From 5ffe205b81d80bff5f64c9799f54d4309b86369d Mon Sep 17 00:00:00 2001
From: zhaowei <zhaowei>
Date: 星期一, 20 一月 2025 15:11:25 +0800
Subject: [PATCH] 产品结构树页面新增NC程序指派到设备功能

---
 src/api/dnc.js                                                                           |    2 
 src/views/dnc/base/modules/ProductStructure/Document/UseNcDocumentEquipmentTableList.vue |   38 +++++++++++-
 src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue           |   92 +++++++++++++++++++++++++-----
 src/views/dnc/base/modules/ProductStructure/ProductStructureMainBottom.vue               |    3 
 4 files changed, 114 insertions(+), 21 deletions(-)

diff --git a/src/api/dnc.js b/src/api/dnc.js
index 2a0862b..08f99d7 100644
--- a/src/api/dnc.js
+++ b/src/api/dnc.js
@@ -23,6 +23,8 @@
   },
   // 鑾峰彇鎸囨淳鍒拌澶囦腑鐨勮澶囨爲
   getDocumentAssignDeviceTreeApi: ({ attributionType, attributionId }) => getAction(`/nc/device/load/depart/tree/${attributionType}/${attributionId}`),
+  // 鎸囨淳鏂囨。鍒拌澶�
+  assignDocumentToDeviceApi: params => postAction('/nc/activit/assign/file/apply', params),
   // 涓嬭浇鏂囨。
   downloadDocumentApi: ({ id, docName }) => downloadFile(`/nc/doc/download/${id}`, docName),
   // 鏂囨。鍑哄簱
diff --git a/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue b/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
index f00bfda..2679fb1 100644
--- a/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
+++ b/src/views/dnc/base/modules/ProductStructure/Document/NcDocumentAssignModal.vue
@@ -45,15 +45,9 @@
                 <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>
 
                 <!--浜у搧缁撴瀯鏍�-->
@@ -89,11 +83,10 @@
   import { getAction } from '@/api/manage'
   import dncApi from '@/api/dnc'
   import { JeecgListMixin } from '@/mixins/JeecgListMixin'
-  import ATextarea from 'ant-design-vue/es/input/TextArea'
 
   export default {
     name: 'NcDocumentAssignModal',
-    components: { ATextarea },
+    components: {},
     mixins: [JeecgListMixin],
     props: {
       currentDocumentInfo: {
@@ -133,6 +126,7 @@
         checkedKeys: [],
         expandedKeys: [],
         autoExpandParent: true,
+        isExpandAllTreeNode: false,
         url: {
           list: '/nc/doc/find/list'
         }
@@ -146,6 +140,12 @@
             this.loadData()
             this.getDocumentAssignDeviceTreeByApi()
           }
+        }
+      },
+      isExpandAllTreeNode: {
+        handler(value) {
+          if (value) this.expandedKeys = this.allTreeKeys
+          else this.expandedKeys = []
         }
       }
     },
@@ -161,7 +161,6 @@
           return false
         }
         const { attributionType, attributionId, param } = this.currentDocumentInfo
-        console.log('currentDocumentInfo', this.currentDocumentInfo)
         params.attributionType = attributionType
         params.attributionId = attributionId
         params.docClassCode = param
@@ -195,15 +194,71 @@
       },
 
       handleAssignDocumentToDevice() {
-        const param = {}
-        console.log('table', this.selectedRowKeys)
+        const { checkedKeys, selectedRowKeys, dataList, $confirm, $notification, currentDocumentInfo, queryParam: { applyReason }, $set } = this
+        const { publishFileId, attributionId } = currentDocumentInfo
+        const paramsArray = []
+        // 杩囨护鍒嗙粍Id浠呮斁鍏ヨ澶嘔d
         const treeCheckedDeviceKeys = []
-        this.checkedKeys.forEach(checkedKey => {
-          const deviceId = this.dataList.find(item => item.key === checkedKey && item.type === 2)
+        checkedKeys.forEach(checkedKey => {
+          const deviceId = dataList.find(item => item.key === checkedKey && item.type === 2)
           if (deviceId) treeCheckedDeviceKeys.push(deviceId.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,
+                  processId: attributionId,
+                  applyReason
+                })
+              })
+            })
+
+            paramsArray.forEach(item => {
+              dncApi.assignDocumentToDeviceApi(item)
+                .then(res => {
+                  if (res.success) {
+                    this.$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
+                  })
+                })
+            })
+            console.log('paramsArray', paramsArray)
+          }
+        })
+        // console.log('table', this.selectedRowKeys)
+        // console.log('treeCheckedDeviceKeys', treeCheckedDeviceKeys)
+        // console.log('currentDocumentInfo', this.currentDocumentInfo)
       },
 
       /* 杈撳叆鏌ヨ鍐呭鍙樺寲鏃惰Е鍙� */
@@ -311,4 +366,7 @@
 
   }
 
+  ::-webkit-scrollbar {
+    width: 8px;
+  }
 </style>
\ No newline at end of file
diff --git a/src/views/dnc/base/modules/ProductStructure/Document/UseNcDocumentEquipmentTableList.vue b/src/views/dnc/base/modules/ProductStructure/Document/UseNcDocumentEquipmentTableList.vue
index 085b567..e5f323b 100644
--- a/src/views/dnc/base/modules/ProductStructure/Document/UseNcDocumentEquipmentTableList.vue
+++ b/src/views/dnc/base/modules/ProductStructure/Document/UseNcDocumentEquipmentTableList.vue
@@ -1,18 +1,28 @@
 <template>
-  <a-table :columns="columns" :data-source="dataSource" bordered :pagination="false">
+  <a-table :columns="columns" :data-source="dataSource" bordered :pagination="false" :size="size" rowKey="deviceId">
 
   </a-table>
 </template>
 
 <script>
+  import { getAction } from '@/api/manage'
   import { JeecgListMixin } from '@/mixins/JeecgListMixin'
 
   export default {
     name: 'UseNcDocumentEquipmentTableList',
     components: {},
     mixins: [JeecgListMixin],
+    props: {
+      currentDocumentInfo: {
+        type: Object
+      },
+      size: {
+        type: String
+      }
+    },
     data() {
       return {
+        disableMixinCreated: true,
         columns: [
           {
             title: '搴忓彿',
@@ -32,11 +42,33 @@
           { title: '鎺у埗绯荤粺', dataIndex: 'controlSystem', align: 'center' }
         ],
         url: {
-          list: ''
+          list: '/doc/relative/get/device'
         }
       }
     },
-    methods: {}
+    methods: {
+      loadData() {
+        this.dataSource = []
+        if (!this.url.list) {
+          this.$message.error('璇疯缃畊rl.list灞炴��!')
+          return
+        }
+        var params = this.getQueryParams()//鏌ヨ鏉′欢
+        if (!params) {
+          return false
+        }
+        this.loading = true
+        getAction(this.url.list + `/${this.currentDocumentInfo.docId}`, params).then((res) => {
+          if (res.success) {
+            this.dataSource = res.list
+          } else {
+            this.$message.warning(res.message)
+          }
+        }).finally(() => {
+          this.loading = false
+        })
+      }
+    }
   }
 </script>
 
diff --git a/src/views/dnc/base/modules/ProductStructure/ProductStructureMainBottom.vue b/src/views/dnc/base/modules/ProductStructure/ProductStructureMainBottom.vue
index c3a67b5..e5a321e 100644
--- a/src/views/dnc/base/modules/ProductStructure/ProductStructureMainBottom.vue
+++ b/src/views/dnc/base/modules/ProductStructure/ProductStructureMainBottom.vue
@@ -36,7 +36,8 @@
       </a-tab-pane>
 
       <a-tab-pane :key="4" tab="浣跨敤璁惧" v-if="currentLevelInfo.attributionType===5">
-        <UseDocumentEquipmentTableList ref="useDocumentEquipmentTableRef"/>
+        <UseDocumentEquipmentTableList ref="useDocumentEquipmentTableRef" :currentDocumentInfo="currentLevelInfo"
+                                       :size="containerSize"/>
       </a-tab-pane>
     </template>
   </a-tabs>

--
Gitblit v1.9.3