LiuJ 1 vecka sedan
förälder
incheckning
fc5d97aea6
1 ändrade filer med 38 tillägg och 4 borttagningar
  1. 38 4
      src/views/news/creatNews.vue

+ 38 - 4
src/views/news/creatNews.vue

@@ -139,7 +139,7 @@
               </div>
               <el-form-item label="资讯内容:" prop="content" class="custom-align-right">
                 <myEditor ref="myEditor" v-model="form.content"></myEditor>
-              </el-form-item> 
+              </el-form-item>
               <el-form-item label="是否开启投票:" prop="is_survey" class="custom-align-right">
                 <el-radio-group v-model="form.is_survey">
                   <el-radio :label="1">是</el-radio>
@@ -177,8 +177,10 @@
                 </el-form-item>
               </div>
               <el-form-item label="手动推荐:" prop="commend_id" class="custom-align-right">
-                <el-select v-model="form.commend_id" placeholder="请选择手动推荐名称" multiple filterable clearable remote :remote-method="remoteMethod" :loading="loading">
-                  <el-option v-for="item in commend_article" :key="item.id" :label="item.title" :value="item.id"></el-option>
+                <el-select v-model="form.commend_id" placeholder="请选择手动推荐名称" multiple filterable clearable remote
+                  :remote-method="remoteMethod" :loading="loading">
+                  <el-option v-for="item in commend_article" :key="item.id" :label="item.title"
+                    :value="item.id"></el-option>
                 </el-select>
               </el-form-item>
               <el-form-item label="" prop="commend_id" class="custom-align-right">
@@ -453,6 +455,31 @@ export default {
       //表单项 end ------------------------------------------------------------>
     };
 
+  }, watch: {
+    '$route'(to, from) {
+      console.log(from, '---------------------------------------');
+      // 监听路由参数中的 id 变化,若变化则更新页面状态并获取数据
+      if (to.query.id) {
+        this.getMainData();
+      }
+    },
+
+
+    // 监听路由参数中的 id 变化,若变化则更新页面状态并获取数据
+    // '$route.query.id': function (newVal, oldVal) {
+    //   console.log('当前 id:', newVal, '旧的 id:', oldVal);
+    //   if (newVal) {
+    //     this.editStatus = true;
+    //     this.tableDivTitle = "编辑资讯";
+    //     //     // 调用方法名保持大小写一致
+    //     this.getMainData();
+    //   } else {
+    //     this.editStatus = false;
+    //     this.tableDivTitle = "添加资讯";
+    //   }
+    // }
+
+
   },
   methods: {
     //1.提交表单 start ------------------------------------------------------------>
@@ -553,9 +580,12 @@ export default {
         //如果是普通用户 推荐等级设置为0 
         this.form.level = "[0]";
       }
-      if (this.form.commend_id != undefined && this.form.commend_id.length > 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);
 
@@ -824,9 +854,13 @@ 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);