刘洋 2 年之前
父節點
當前提交
269da03eaf
共有 1 個文件被更改,包括 46 次插入30 次删除
  1. 46 30
      src/modules/questions/views/AddPaperSelect.vue

+ 46 - 30
src/modules/questions/views/AddPaperSelect.vue

@@ -94,7 +94,7 @@
                   <el-option label="卷库来源" value="GENERATE"></el-option>
                 </el-select>
                 <span
-                  v-if="checked && !multipleSelection.length"
+                  v-if="checked && !tempPapers.length"
                   class="red"
                   style="font-size: 12px; font-weight: bold; margin-left: 10px"
                   >请选择数据</span
@@ -281,6 +281,7 @@ export default {
       tableLoading2: false,
       checked: false,
       initSelectedRows: [],
+      isEditInitPage: false,
     };
   },
   computed: {
@@ -324,7 +325,7 @@ export default {
     let res = await this.getTplData();
     if (res) {
       this.getStruct();
-      this.getTable2(true);
+      // this.getTable2(true);
     }
   },
   methods: {
@@ -353,10 +354,14 @@ export default {
             }
           );
           const tplData = data.data;
-          this.paperIdsArr = tplData.paperIds || [];
+          this.tempPaperIds = tplData.paperIds || [];
+          this.tempPapers = tplData.papers || [];
+          this.isEditInitPage = true;
           Object.assign(this.form, tplData || {}, {
             paperIds: (tplData.paperIds || []).join(","),
           });
+          this.getTable2();
+          this.getTable3();
           return true;
         } catch (e) {
           return false;
@@ -374,13 +379,15 @@ export default {
     },
     save() {
       this.checked = true;
+      let paperIds = this.tempPaperIds.join(",");
       this.$refs.form.validate((valid) => {
         if (valid) {
-          if (this.multipleSelection.length && !this.hasError) {
+          if (this.tempPaperIds.length && !this.hasError) {
             let params = {
               courseId: this.$route.query.courseId,
               ...this.form,
               rootOrgId: this.user.rootOrgId,
+              paperIds,
             };
             if (this.$route.params.id) {
               params.id = this.$route.params.id;
@@ -441,7 +448,7 @@ export default {
         this.loading = false;
       });
     },
-    getTable2(bool) {
+    getTable2() {
       this.tableLoading2 = true;
       let apiUrl =
         this.form.paperType === "IMPORT"
@@ -462,18 +469,18 @@ export default {
           this.tableData2 = res.data.content || [];
           this.totalSelect = res.data.totalElements;
           // this.curSelect = res.data.number + 1;
-          if (bool) {
-            this.tableData2.forEach((item) => {
-              if (this.paperIdsArr.includes(item.id)) {
-                this.initSelectedRows.push(item);
-              }
-            });
-            setTimeout(() => {
-              this.initSelectedRows.forEach((item) => {
-                this.$refs.table2.toggleRowSelection(item, true);
-              });
-            }, 0);
-          }
+          // if (bool) {
+          //   this.tableData2.forEach((item) => {
+          //     if (this.paperIdsArr.includes(item.id)) {
+          //       this.initSelectedRows.push(item);
+          //     }
+          //   });
+          //   setTimeout(() => {
+          //     this.initSelectedRows.forEach((item) => {
+          //       this.$refs.table2.toggleRowSelection(item, true);
+          //     });
+          //   }, 0);
+          // }
           this.tableLoading2 = false;
         });
     },
@@ -492,15 +499,22 @@ export default {
         }
       }
       this.getTable2();
+      this.getTable3();
     },
     changePaperType() {
-      this.tempPapers = [];
-      this.tempPaperIds = [];
-      this.tableData2 = [];
-      this.tableData3 = [];
-      this.multipleSelection = [];
-      this.curSelect = 1;
-      this.getTable2();
+      console.log("changePaperType");
+      if (!this.isEditInitPage) {
+        this.tempPapers = [];
+        this.tempPaperIds = [];
+        this.tableData2 = [];
+        this.tableData3 = [];
+        this.multipleSelection = [];
+        this.curSelect = 1;
+        this.getTable2();
+      } else {
+        this.isEditInitPage = false;
+      }
+
       // if (bool === true) {
       //   // this.handleSelectionChange([]);
       //   this.tempPapers = [];
@@ -548,12 +562,14 @@ export default {
     },
     handleSelectionChange(val) {
       // this.multipleSelection = val;
-      val.forEach((element) => {
-        this.tempPapers.push(cloneDeep(element));
-        this.tempPaperIds.push(element.id);
-      });
-      this.getTable2();
-      this.getTable3();
+      if (val.length) {
+        val.forEach((element) => {
+          this.tempPapers.push(cloneDeep(element));
+          this.tempPaperIds.push(element.id);
+        });
+        this.getTable2();
+        this.getTable3();
+      }
     },
     hasNumError(row) {
       return (