yuanyuan 3 лет назад
Родитель
Сommit
70fdd59602
1 измененных файлов с 74 добавлено и 41 удалено
  1. 74 41
      src/views/account/ChangeText.vue

+ 74 - 41
src/views/account/ChangeText.vue

@@ -2,7 +2,7 @@
     <div class="change" v-if="type === 'nickname'">
         <div class="title">昵称</div>
         <van-field
-            v-model="info.nickname"
+            v-model="message"
             :rows="1"
             type="textarea"
             :maxlength="10"
@@ -151,6 +151,7 @@ export default {
         return {
             type: 'nickname',
             message: '',
+            messages: '',
             // briefIntroduction: '',
             // school: '',
             // occupation: "",
@@ -160,62 +161,94 @@ export default {
         };
     },
     mounted() {
-        this.getInformation().then(res => {
-            this.type = this.$route.query.type;
-            this.message = this.userInfo.nickname;
-        });
+        // this.getInformation().then(res => {
+        //     this.type = this.$route.query.type;
+        //     this.message = this.userInfo.nickname;
+        // });
+        this.type = this.$route.query.type;
+        this.message = this.userInfo.nickname;
+        this.getInformation();
     },
     methods: {
+        // getInformation() {
+        //     return this.$http.get('/userDetail/get/' + this.userInfo.id).then(res => {
+        //         this.info = {
+        //             autograph: '',
+        //             school: '',
+        //             occupation: '',
+        //             company: '',
+        //             mail: '',
+        //             nickname: this.userInfo.nickname,
+        //             ...res
+        //         };
+        //     });
+        // },
         getInformation() {
-            return this.$http.get('/userDetail/get/' + this.userInfo.id).then(res => {
-                this.info = {
-                    autograph: '', //没默认值更新不成功
-                    school: '',
-                    occupation: '',
-                    company: '',
-                    mail: '',
-                    nickname: this.userInfo.nickname,
-                    ...res
-                };
+            this.$http.get('/userDetail/get/' + this.userInfo.id).then(res => {
+                this.info = res;
             });
         },
         save() {
-            const message = this.info[this.type];
-            if (!message) {
+            if (this.type === 'nickname') {
+                this.messages = this.message;
+            } else {
+                this.messages = this.info[this.type];
+            }
+            if (!this.messages) {
                 this.$toast('内容不能为空');
                 return;
             }
-            if (message.indexOf('习近平') !== -1) {
+            if (this.messages.indexOf('习近平') !== -1) {
                 this.$dialog.alert({
                     title: '提示',
                     message: '不能含有敏感词汇'
                 });
-                this.info[this.type] = '';
+                if (this.type === 'nickname') {
+                    this.message = '';
+                } else {
+                    this.info[this.type] = '';
+                }
                 return;
             }
-            if (this.type == 'nickname') {
-                let data = {
-                    userId: this.userInfo.id,
-                    ...this.info,
-                    nickname: message
-                };
-                Promise.all([
-                    this.$http.post('/userDetail/save', data, { body: 'json' }),
-                    this.updateUser({ [this.type]: message })
-                ]).then(res => {
-                    this.$toast.success('更新成功');
-                    setTimeout(() => {
-                        this.$router.back();
-                    }, 1500);
-                });
-            } else {
-                this.updateUser({ [this.type]: message }).then(() => {
-                    this.$toast.success('更新成功');
-                    setTimeout(() => {
-                        this.$router.back();
-                    }, 1500);
-                });
+            let data = {
+                userId: this.userInfo.id,
+                ...this.info,
+                nickname: this.message
+            };
+            this.$http.post('/userDetail/save', data, { body: 'json' }).then(() => {
+                this.$toast.success('更新成功');
+                setTimeout(() => {
+                    this.$router.back();
+                }, 1500);
+            });
+            if (this.type === 'nickname') {
+                this.updateUser({ [this.type]: this.message }).then(() => {});
+            } else if (this.type === 'intro') {
+                this.updateUser({ [this.type]: this.info.autograph }).then(() => {});
             }
+            // if (this.type == 'nickname') {
+            //     let data = {
+            //         userId: this.userInfo.id,
+            //         ...this.info,
+            //         nickname: message
+            //     };
+            //     Promise.all([
+            //         this.$http.post('/userDetail/save', data, { body: 'json' }),
+            //         this.updateUser({ [this.type]: message })
+            //     ]).then(res => {
+            //         this.$toast.success('更新成功');
+            //         setTimeout(() => {
+            //             this.$router.back();
+            //         }, 1500);
+            //     });
+            // } else {
+            //     this.updateUser({ [this.type]: message }).then(() => {
+            //         this.$toast.success('更新成功');
+            //         setTimeout(() => {
+            //             this.$router.back();
+            //         }, 1500);
+            //     });
+            // }
 
             // /userDetail/save
             // if (this.message) {