浏览代码

物料档案-列表-控制必须选择数据才能进行导出,数据选择需要保存翻页前的选择状态

002390 2 年之前
父节点
当前提交
f6362cadfd
共有 1 个文件被更改,包括 40 次插入28 次删除
  1. 40 28
      src/views/material/basicFile/index.vue

+ 40 - 28
src/views/material/basicFile/index.vue

@@ -27,7 +27,7 @@
               <el-dropdown-item :command="filterCondition('stop')">显示停用</el-dropdown-item>
               <el-dropdown-item :command="filterCondition('allot')">显示已分配</el-dropdown-item>
             </el-dropdown-menu>
-                                                                                          </el-dropdown> -->
+                                                                                                                                                                                            </el-dropdown> -->
 
             <!-- <el-button size="small" @click="handleQuery">查询</el-button> -->
             <el-button size="small" @click="handleRefresh">刷新</el-button>
@@ -95,9 +95,9 @@
     <!-- 主体列表 -->
     <el-card class="material-list" v-loading="loading">
       <el-table :data="taskList" ref="materialTable" @cell-dblclick="handledbClick" :row-key="getRowKey"
-        @selection-change="handleSelectionChange">
-        <!-- :reserve-selection="true" -->
-        <el-table-column type="selection" width="30"  />
+        @selection-change="handleSelectionChange" @select="handleSelect" @select-all="handleSelectAll">
+        <!--  -->
+        <el-table-column type="selection" width="30" :reserve-selection="true" />
         <el-table-column type="index" label="序号" width="55" align="center" />
         <el-table-column width="150" v-for="h in  tableHeader" v-if="h.show" :label="h.name" align="center"
           show-overflow-tooltip>
@@ -225,14 +225,9 @@ export default {
             isEdit: true
           }
         });
-      } else if (this.checkedList.length > 1) {
-        this.$message({
-          message: '修改只能选择单个数据!',
-          type: 'warning'
-        });
       } else {
         this.$message({
-          message: '请选择需要修改的信息!',
+          message: `${this.checkedList.length > 1 ? '修改只能选择单个数据!' : '请选择需要修改的信息!'}`,
           type: 'warning'
         });
       }
@@ -366,11 +361,20 @@ export default {
 
       let ids = this.checkedList.length ? this.checkedList.map(i => i.id) : [];
 
-      let params = {
-        // orgId: '1',
-        ids,
+      if (ids.length) {
+
+        let params = {
+          // orgId: '1',
+          ids,
+        }
+        this.download('/system/material/export', params, `物料基本信息${new Date().getTime()}.xlsx`);
+      } else {
+        this.$message({
+          message: '请选择需要导出的数据!',
+          type: 'warning'
+        });
       }
-      this.download('/system/material/export', params, `物料基本信息${new Date().getTime()}.xlsx`)
+
     },
     // 下载模板
     handleDownTemplate() {
@@ -409,12 +413,29 @@ export default {
     getRowKey(row) {
       return row.id;
     },
+    // 对象数组去重
+    handleUnique(arr, key) {
+      // arr  需要去重的数组   type:作为去重依据的key
+      const res = new Map();
+      return arr.filter((arr) => !res.has(arr[key]) && res.set(arr[key], 1))
+    },
     // 选中数据改变
     handleSelectionChange(list) {
-      this.checkedList = list;
-      // this.checkedList = Array.from(new Set([...this.checkedList, ...list]));
-      console.log(this.checkedList, '选中数据改变');
-      this.$emit('headerOption', JSON.stringify({ checkedList: [...list] }))
+      // this.checkedList = this.handleUnique([...this.checkedList, ...list], 'id');
+      // console.log(this.checkedList, '选中数据改变');
+      // this.$emit('headerOption', JSON.stringify({ checkedList: [... this.checkedList] }))
+    },
+    // 行数据勾选操作 
+    handleSelect(selection, row) {
+      this.checkedList = selection;
+      // // true就是选中,0或者false是取消选中
+      // let selected = selection.length && selection.indexOf(row) !== -1
+
+    },
+    //手动勾选全选 
+    handleSelectAll(selection) {
+      // console.log(selection, '手动勾选全选--------------');
+      this.checkedList = selection;
     },
     // 获取物料列表信息
     getMaterialList(templateCode, query) {
@@ -429,22 +450,13 @@ export default {
         templateCode,
         ...this.queryForm
       }
-      console.log(param, 'param');
+      // console.log(param, 'param');
       materialApi.materialList(param, page).then((res) => {
         _this.loading = false;
         console.log(res, '获取物料列表信息以及表头字段');
         let { code, data } = res;
         if (code == 200) {
           _this.taskList = data.tableBody.rows;
-          // console.log(_this.$refs.materialTable, ' _this.$refs.materialTable');
-          // _this.checkedList.forEach(c => {
-          //   _this.taskList.forEach(row => {
-          //     if (row.id == c.id) {
-          //       _this.$refs.materialTable.toggleRowSelection(row, true);
-          //     }
-          //   })
-          // })
-
           _this.total = data.tableBody.total;
 
         }