From 08e52db54ce1e7563f1efe402a3f6c3931188013 Mon Sep 17 00:00:00 2001
From: zhaowei <zhaowei>
Date: 星期五, 14 二月 2025 10:47:53 +0800
Subject: [PATCH] 产品结构树: 1、实现文档批量删除功能 2、实现文档列表的排序以及筛选功能 设备结构树: 1、新增权限配置弹窗,提交后由后端测试

---
 src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue |  221 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 179 insertions(+), 42 deletions(-)

diff --git a/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue b/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
index f00bfda..26a68a1 100644
--- a/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
+++ b/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
@@ -10,13 +10,14 @@
                 <a-row :gutter="24">
                   <a-col :md="7" :sm="7">
                     <a-form-item label="鏂囦欢鍚嶇О">
-                      <a-input placeholder="璇疯緭鍏ユ枃浠跺悕绉�" v-model="queryParam.docName"></a-input>
+                      <a-input placeholder="璇疯緭鍏ユ枃浠跺悕绉�" v-model="queryParam.docName" allow-clear></a-input>
                     </a-form-item>
                   </a-col>
 
                   <a-col :md="11" :sm="11">
                     <a-form-item label="涓婁紶鏃堕棿">
-                      <a-range-picker v-model="queryParam.collectTime"></a-range-picker>
+                      <a-range-picker v-model="date" value-format="YYYY-MM-DD"
+                                      @change="handleDateChange" allow-clear></a-range-picker>
                     </a-form-item>
                   </a-col>
 
@@ -30,6 +31,7 @@
 
             <a-table :columns="columns" :data-source="dataSource" bordered :pagination="false" :loading="loading"
                      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
+                     @change="handleTableChange"
                      :scroll="{y:456}" :size="size" rowKey="docId">
 
             </a-table>
@@ -45,26 +47,20 @@
                 <div style="display: flex">
                   <a-input placeholder="杈撳叆鍏抽敭瀛楄繘琛屾悳绱�" allowClear v-model="searchInput"
                            @change="handleSearchInputChange"/>
-                  <a-dropdown :trigger="['click']" placement="bottomCenter" style="margin: 0 8px">
-                    <a-menu slot="overlay">
-                      <a-menu-item key="1" @click="expandedKeys = allTreeKeys">灞曞紑鎵�鏈�</a-menu-item>
-                      <a-menu-item key="2" @click="expandedKeys = []">鍚堝苟鎵�鏈�</a-menu-item>
-                    </a-menu>
-                    <a-button>
-                      <a-icon type="bars"/>
-                    </a-button>
-                  </a-dropdown>
+                  <a-button type="primary" @click="isExpandAllTreeNode=!isExpandAllTreeNode" style="margin: 0 8px">
+                    灞曞紑/鎶樺彔
+                  </a-button>
                 </div>
 
                 <!--浜у搧缁撴瀯鏍�-->
                 <div style="overflow:auto;margin-top: 10px;height: 400px">
-                  <a-tree ref="tree" checkable :checkedKeys="checkedKeys" :expandedKeys.sync="expandedKeys"
-                          :autoExpandParent="autoExpandParent"
-                          :treeData="treeDataSource" @check="handleTreeNodeCheck" @expand="handleTreeExpand">
-                    <template slot="title" slot-scope="{ label, parentId, entity, key:treeKey,type}">
-                     <span v-if="label.indexOf(searchValue) > -1">{{ label.substr(0, label.indexOf(searchValue)) }}<span
-                       class="replaceSearch">{{ searchValue }}</span>{{ label.substr(label.indexOf(searchValue) + searchValue.length) }}</span>
-                      <span v-else>{{ label }}</span>
+                  <a-tree blockNode checkable :checkedKeys="checkedKeys" :expandedKeys.sync="expandedKeys"
+                          :autoExpandParent="autoExpandParent" @select="handleTreeNodeSelect"
+                          :treeData="treeDataSource" @check="handleTreeNodeCheck" @expand="handleTreeNodeExpand">
+                    <template slot="title" slot-scope="{ title, parentId, entity, key:treeKey,type}">
+                     <span v-if="title.indexOf(searchValue) > -1">{{ title.substr(0, title.indexOf(searchValue)) }}<span
+                       class="replaceSearch">{{ searchValue }}</span>{{ title.substr(title.indexOf(searchValue) + searchValue.length) }}</span>
+                      <span v-else>{{ title }}</span>
                     </template>
                   </a-tree>
                 </div>
@@ -89,11 +85,11 @@
   import { getAction } from '@/api/manage'
   import dncApi from '@/api/dnc'
   import { JeecgListMixin } from '@/mixins/JeecgListMixin'
-  import ATextarea from 'ant-design-vue/es/input/TextArea'
+  import { mapActions } from 'vuex'
 
   export default {
     name: 'NcDocumentAssignModal',
-    components: { ATextarea },
+    components: {},
     mixins: [JeecgListMixin],
     props: {
       currentDocumentInfo: {
@@ -119,11 +115,43 @@
               return parseInt(index) + 1
             }
           },
-          { title: '鏂囦欢鍚嶇О', dataIndex: 'docName', align: 'center', width: 300 },
+          {
+            title: '鏂囦欢鍚嶇О',
+            dataIndex: 'docName',
+            key: 'docName',
+            align: 'center',
+            width: 300,
+            sorter: true
+          },
           { title: '璁惧缂栧彿', dataIndex: 'docCode', align: 'center' },
-          { title: '鍑哄簱鐘舵��', dataIndex: 'pullStatus_dictText', align: 'center' },
-          { title: '鐘�  鎬�', dataIndex: 'docStatus_dictText', align: 'center' },
-          { title: '涓婁紶鏃堕棿', dataIndex: 'createTime', align: 'center', width: 200 }
+          {
+            title: '鍑哄簱鐘舵��',
+            dataIndex: 'pullStatus_dictText',
+            key: 'pullStatus',
+            align: 'center',
+            filters: [
+              { text: '鏈嚭搴�', value: 1 },
+              { text: '宸插嚭搴�', value: 2 }
+            ]
+          },
+          {
+            title: '鐘�  鎬�',
+            dataIndex: 'docStatus_dictText',
+            key: 'docStatus',
+            align: 'center',
+            filters: [
+              { text: '璁捐', value: 1 },
+              { text: '鍙戝竷', value: 2 },
+              { text: '褰掓。', value: 3 }
+            ]
+          },
+          {
+            title: '鍒涘缓鏃堕棿',
+            dataIndex: 'createTime',
+            align: 'center',
+            width: 200,
+            sorter: true
+          }
         ],
         searchValue: '',
         searchInput: '',
@@ -133,6 +161,8 @@
         checkedKeys: [],
         expandedKeys: [],
         autoExpandParent: true,
+        isExpandAllTreeNode: false,
+        date: [],
         url: {
           list: '/nc/doc/find/list'
         }
@@ -147,9 +177,18 @@
             this.getDocumentAssignDeviceTreeByApi()
           }
         }
+      },
+      isExpandAllTreeNode: {
+        handler(value) {
+          if (value) this.expandedKeys = this.allTreeKeys
+          else this.expandedKeys = []
+        }
       }
     },
     methods: {
+      ...mapActions(['QueryProduction']),
+
+      // 鑾峰彇褰撳墠宸ュ簭鎴栧伐姝ュ搴旀枃妗e垪琛�
       loadData() {
         this.dataSource = []
         if (!this.url.list) {
@@ -157,15 +196,11 @@
           return
         }
         var params = this.getQueryParams()//鏌ヨ鏉′欢
-        if (!params) {
-          return false
-        }
+        if (!params) return false
         const { attributionType, attributionId, param } = this.currentDocumentInfo
-        console.log('currentDocumentInfo', this.currentDocumentInfo)
         params.attributionType = attributionType
         params.attributionId = attributionId
         params.docClassCode = param
-        console.log('params', params)
         this.loading = true
         getAction(this.url.list, params).then((res) => {
           if (res.success) this.dataSource = res.result
@@ -175,16 +210,18 @@
         })
       },
 
+      // 鑾峰彇DNC璁惧鏍�
       getDocumentAssignDeviceTreeByApi() {
         this.spinning = true
         this.treeDataSource = []
-        dncApi.getDocumentAssignDeviceTreeApi(this.currentDocumentInfo)
+        this.QueryProduction('DNC')
           .then(res => {
             if (res.success) {
               this.dataList = []
               this.allTreeKeys = []
-              this.treeDataSource = res.list
+              this.treeDataSource = res.result
               this.generateList(this.treeDataSource)
+              this.expandedKeys = this.allTreeKeys
             } else {
               this.$message.warn(res.message)
             }
@@ -194,16 +231,103 @@
           })
       },
 
+      // 鏃堕棿閫夋嫨鍣ㄩ�夋嫨瀹屾垚鍚庤Е鍙�
+      handleDateChange(value) {
+        this.queryParam.startTime = value[0]
+        this.queryParam.endTime = value[1]
+      },
+
+      /**
+       * 琛ㄦ牸鍒嗛〉銆佹帓搴忔敼鍙樸�佺瓫閫夋椂瑙﹀彂
+       * @param pagination 鍒嗛〉鍣ㄩ�夐」
+       * @param filters 绛涢�夐�夐」
+       * @param sorter 鎺掑簭閫夐」
+       */
+      handleTableChange(pagination, filters, sorter) {
+        if (sorter.order) {
+          this.isorter.column = sorter.field
+          this.isorter.order = sorter.order === 'ascend' ? 'asc' : 'desc'
+        } else {
+          this.isorter.column = 'createTime'
+          this.isorter.order = 'desc'
+        }
+        for (let key in filters) {
+          this.filters[key] = filters[key].join(',')
+        }
+        this.loadData()
+      },
+
+      // 鎸囨淳鍒拌澶囩獥鍙g偣鍑荤‘瀹氭寚娲捐澶囧悗瑙﹀彂
       handleAssignDocumentToDevice() {
-        const param = {}
-        console.log('table', this.selectedRowKeys)
+        const { checkedKeys, selectedRowKeys, dataList, $confirm, $notification, currentDocumentInfo, queryParam: { applyReason }, $destroyAll, $bus } = this
+        const { publishFileId, attributionId, attributionType } = currentDocumentInfo
+        const paramsArray = []
+        // 杩囨护杞﹂棿key浠呮斁鍏ヨ澶噆ey
         const treeCheckedDeviceKeys = []
-        this.checkedKeys.forEach(checkedKey => {
-          const deviceId = this.dataList.find(item => item.key === checkedKey && item.type === 2)
-          if (deviceId) treeCheckedDeviceKeys.push(deviceId.key)
+        checkedKeys.forEach(checkedKey => {
+          const device = dataList.find(item => item.key === checkedKey && item.type === 2)
+          if (device) treeCheckedDeviceKeys.push(device.key)
         })
 
-        console.log('treeCheckedDeviceKeys', treeCheckedDeviceKeys)
+        if (treeCheckedDeviceKeys.length === 0 || selectedRowKeys.length === 0) {
+          $notification.warning({
+            message: '娑堟伅',
+            description: '璇烽�夋嫨璁惧鎴栨枃妗�'
+          })
+          return
+        }
+
+        $confirm({
+          title: '鎻愮ず',
+          content: `纭鎻愪氦鍚楋紵`,
+          okText: '纭',
+          cancelText: '鍙栨秷',
+          onOk: () => {
+            // 鍙岄噸寰幆纭畾姣忎竴缁勮澶囦笌鏂囨。鐨勫弬鏁�
+            treeCheckedDeviceKeys.forEach(deviceId => {
+              selectedRowKeys.forEach(docId => {
+                paramsArray.push({
+                  docId,
+                  deviceId,
+                  fileId: publishFileId,
+                  attributionId,
+                  attributionType,
+                  applyReason
+                })
+              })
+            })
+
+            paramsArray.forEach(item => {
+              dncApi.assignDocumentToDeviceApi(item)
+                .then(res => {
+                  if (res.success) {
+                    $bus.$emit('reloadMainBottomTableData', 'useDocumentEquipment')
+                    $notification.success({
+                      message: '娑堟伅',
+                      description: res.message
+                    })
+                  } else {
+                    $notification.error({
+                      message: '娑堟伅',
+                      description: res.message
+                    })
+                  }
+                })
+                .catch(err => {
+                  $notification.error({
+                    message: '娑堟伅',
+                    description: err.message
+                  })
+                })
+                .finally(() => {
+                  $destroyAll()
+                })
+            })
+          },
+          onCancel: () => {
+            $destroyAll()
+          }
+        })
       },
 
       /* 杈撳叆鏌ヨ鍐呭鍙樺寲鏃惰Е鍙� */
@@ -232,7 +356,7 @@
        * 鏍戣妭鐐瑰睍寮�鍚堝苟鏃惰Е鍙�
        * @param expandedKeys 灞曞紑椤筴ey
        */
-      handleTreeExpand(expandedKeys) {
+      handleTreeNodeExpand(expandedKeys) {
         this.expandedKeys = expandedKeys
         this.autoExpandParent = false
       },
@@ -245,6 +369,15 @@
       handleTreeNodeCheck(checkedKeys, { node }) {
         let record = node.dataRef
         this.checkedKeys = checkedKeys
+      },
+
+      /**
+       * 鏍戣妭鐐归�変腑鏃惰Е鍙戯紙妯℃嫙鏍戣妭鐐瑰閫夋閫変腑鏃剁殑鏁堟灉锛�
+       * @param selectedKeys 閫変腑鑺傜偣key
+       * @param {node} node 鑺傜偣瀵硅薄
+       */
+      handleTreeNodeSelect(selectedKeys, { node }) {
+        node.$el.childNodes[1].click()
       },
 
       /**
@@ -271,14 +404,13 @@
 
       /**
        * 閫掑綊鑾峰緱鎵�鏈夋爲鑺傜偣key
-       * @param data
+       * @param data 璁惧鏍戞暟鎹�
        */
       generateList(data) {
         for (let i = 0; i < data.length; i++) {
-          data[i].key = data[i].id
           const node = data[i]
-          const key = node.id
-          const title = node.label
+          const key = node.key
+          const title = node.title
           const type = node.type
           this.dataList.push({ key, title, type })
           this.allTreeKeys.push(key)
@@ -291,6 +423,8 @@
         this.expandedKeys = []
         this.selectedRowKeys = []
         this.checkedKeys = []
+        this.filters = {}
+        this.isorter = Object.assign({}, this.defaultSorter)
       }
     }
   }
@@ -311,4 +445,7 @@
 
   }
 
+  ::-webkit-scrollbar {
+    width: 8px;
+  }
 </style>
\ No newline at end of file

--
Gitblit v1.9.3