2 Commits 721419d9ec ... deff76eccb

Autor SHA1 Mensaje Fecha
  reloaded deff76eccb Merge branch 'master' of http://git.cc-lotus.info/live-platform/live-cms hace 4 años
  reloaded fe865471e2 111 hace 4 años
Se han modificado 1 ficheros con 23 adiciones y 18 borrados
  1. 23 18
      src/views/question/part/wenjuan.vue

+ 23 - 18
src/views/question/part/wenjuan.vue

@@ -53,14 +53,7 @@
               </el-select>
               <el-button size="mini" type="primary" @click="searchQuestion" style="margin-left:10px;">查询</el-button>
             </el-col>
-            <el-table
-              :row-key="getRowKey"
-              ref="multipleTable"
-              :data="questions"
-              tooltip-effect="dark"
-              style="width: 100%"
-              @selection-change="handleSelectionChange"
-            >
+            <el-table :row-key="getRowKey" ref="multipleTable" :data="questions" tooltip-effect="dark" style="width: 100%" @select="handleSelect">
               <el-table-column prop="_id" type="selection" width="55" :reserve-selection="true"> </el-table-column>
               <el-table-column prop="type" label="类型">
                 <template slot-scope="scope">
@@ -109,7 +102,6 @@ export default {
     form: {},
     questions: [], //问题数组
     questiontotal: 0, //问题总数
-    multipleSelection: [], //选择的问题数组
     qtype: null, //选择的问题类型
     qtypeoptions: [
       { value: '0', label: '单选' },
@@ -151,20 +143,29 @@ export default {
         this.$set(this, `questions`, list.data);
         this.$set(this, `questiontotal`, list.total);
       }
+      if (this.form.question) {
+        this.matchQuestion(this.form.question);
+      } else {
+        this.$refs.multipleTable.clearSelection();
+      }
     },
     // 查看详情
     async detailBtn(item) {
       this.dialogFormVisible = true;
       this.form = item;
-      this.searchQuestion();
+      await this.searchQuestion();
+      this.matchQuestion(this.form.question);
+    },
+    // 匹配选中的问题
+    matchQuestion(rows) {
       this.$nextTick(function() {
-        item.question.forEach(row => {
+        this.$refs.multipleTable.clearSelection();
+        rows.forEach(row => {
           let r = this.questions.find(f => f._id == row._id);
-          //this.multipleSelection.push(row);
-          this.$refs.multipleTable.toggleRowSelection(r);
+          if (r) this.$refs.multipleTable.toggleRowSelection(r);
         });
+        this.$forceUpdate();
       });
-      console.log(this.multipleSelection);
     },
     //删除
     async deleteBtn() {
@@ -177,7 +178,6 @@ export default {
     },
     //提交问卷
     async submitFrom() {
-      this.form.question = this.multipleSelection;
       let res;
       if (this.form.id) res = await this.update(this.form);
       else res = await this.create(this.form);
@@ -193,11 +193,16 @@ export default {
       this.qtype = null;
       this.form = {};
       this.searchQuestion();
-      this.multipleSelection = [];
     },
     //选中问题时触发
-    handleSelectionChange(val) {
-      this.multipleSelection = val;
+    handleSelect(selection, row) {
+      let index = this.form.question.findIndex(item => item._id == row._id);
+      if (index >= 0) {
+        this.form.question.splice(index, 1);
+      } else {
+        this.form.question.push(row);
+      }
+      console.log(this.form.question);
     },
     //题库分页
     questionChange(val) {