Browse Source

文章提交

LiuJ 3 months ago
parent
commit
1ed1120e1a
1 changed files with 17 additions and 13 deletions
  1. 17 13
      src/views/news/creatNews.vue

+ 17 - 13
src/views/news/creatNews.vue

@@ -580,12 +580,7 @@ export default {
         //如果是普通用户 推荐等级设置为0 
         this.form.level = "[0]";
       }
-      if (this.form.commend_id != undefined && this.form.commend_id.length >= 0) {
-        this.form.commend_id = JSON.stringify(this.form.commend_id); // 提取推荐ID
-      }
-      if (this.form.commend_id.length == 0) {
-        this.form.commend_id = '[]';
-      }
+
       //先进行验证
       console.log(this.form);
 
@@ -598,6 +593,13 @@ export default {
             this.form.level = JSON.stringify(this.form.level);
           }
           //console.log(this.form)
+          const formData = { ...this.form };
+          if (formData.commend_id != undefined && formData.commend_id.length > 0) {
+            formData.commend_id = JSON.stringify(formData.commend_id); // 提取推荐ID
+          }
+          if (formData.commend_id.length == 0) {
+            formData.commend_id = '[]';
+          }
           this.$store.dispatch('news/addArticle', this.form).then(res => {
             if (res.code == 200) {
               //汇报结果
@@ -855,12 +857,7 @@ export default {
         this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
       }
 
-      if (this.form.commend_id != undefined && this.form.commend_id.length > 0) {
-        this.form.commend_id = JSON.stringify(this.form.commend_id); // 提取推荐ID
-      }
-      if (this.form.commend_id.length == 0) {
-        this.form.commend_id = '[]';
-      }
+
       //将department_id和city_id转换为字符串  
       // this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
       // this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
@@ -891,8 +888,15 @@ export default {
           } else {
             this.form.level = JSON.stringify(this.form.level);
           }
+          const formData = { ...this.form };
+          if (formData.commend_id != undefined && formData.commend_id.length > 0) {
+            formData.commend_id = JSON.stringify(formData.commend_id); // 提取推荐ID
+          }
+          if (formData.commend_id.length == 0) {
+            formData.commend_id = '[]';
+          }
           //console.log(this.form)
-          this.$store.dispatch('news/updateArticle', this.form).then(res => {
+          this.$store.dispatch('news/updateArticle', formData).then(res => {
             if (res.code != 200) {
               this.$message.error("修改失败,请稍后再试!");
             } else {