natasha 4 天之前
父节点
当前提交
ff1fd78b87
共有 1 个文件被更改,包括 29 次插入6 次删除
  1. 29 6
      src/views/personalCenter/components/OrderList.vue

+ 29 - 6
src/views/personalCenter/components/OrderList.vue

@@ -15,8 +15,16 @@
       v-loading="tableLoading"
       :max-height="tableHeight"
       @selection-change="handleSelectionChange"
+      row-key="id"
+      ref="table"
     >
-      <el-table-column type="selection" width="40" fixed> </el-table-column>
+      <el-table-column
+        type="selection"
+        width="40"
+        fixed
+        :reserve-selection="true"
+      >
+      </el-table-column>
       <el-table-column
         type="index"
         label="#"
@@ -532,6 +540,15 @@ export default {
           if (res.status === 1) {
             this.orderList = res.order_list;
             this.total_count = res.total_count;
+            // this.$refs.table.clearSelection(); // 清空当前选中行,然后重新设置选中状态。
+            this.multipleSelection.forEach((row) => {
+              // row 需要有唯一的标识符,如 id 或其他唯一属性。
+              this.orderList.forEach((items) => {
+                if (row.id === items.id) {
+                  this.$refs.table.toggleRowSelection(items, true); // 根据需要设置选中状态。
+                }
+              });
+            });
           }
         })
         .catch(() => {
@@ -591,11 +608,12 @@ export default {
     },
     // 复选框
     handleSelectionChange(val) {
-      // this.multipleSelection = [];
-      val.forEach((item) => {
-        this.multipleSelection.push(item.id);
+      this.multipleSelection = val.filter((item, index, array) => {
+        return array.map((i) => i.id).indexOf(item.id) === index; // 基于id去重
       });
-      console.log(this.multipleSelection);
+      // val.forEach((item) => {
+      //   this.multipleSelection.push(item.id);
+      // });
     },
     // 去掉前后空格
     handleTrim(form, fild) {
@@ -633,10 +651,14 @@ export default {
           }
         }
       }
+      let multipleSelection = [];
+      this.multipleSelection.forEach((item) => {
+        multipleSelection.push(item.id);
+      });
       let MethodName = "/ShopServer/Client/OrderManager/SubmitInvoiceApply";
 
       let data = {
-        order_id_list: this.multipleSelection,
+        order_id_list: multipleSelection,
         create_model: this.invoiceForm.create_model,
         invoice_type: this.invoiceForm.invoice_type,
         invoice_object: this.invoiceForm.invoice_object,
@@ -670,6 +692,7 @@ export default {
             this.$message.success("申请成功,稍后请到发票管理查看");
             this.dialogVisible = false;
             this.multipleSelection = [];
+            this.$refs.table.clearSelection();
             this.invoiceForm = {
               create_model: 0,
               invoice_type: 0,