From 29271007d0b124f36e0a9db41b7918de2e008b58 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期三, 30 八月 2023 15:01:23 +0800
Subject: [PATCH] 1.计量单位完成100%

---
 src/views/materialManager/unitList.vue |  164 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 106 insertions(+), 58 deletions(-)

diff --git a/src/views/materialManager/unitList.vue b/src/views/materialManager/unitList.vue
index fdb8829..0f7fe94 100644
--- a/src/views/materialManager/unitList.vue
+++ b/src/views/materialManager/unitList.vue
@@ -68,7 +68,7 @@
                 sortable="custom"
               >
                 <template slot-scope="{row}">
-                  {{ row.idunitgroup ? '' : row.code }}
+                  {{ row.isGroup === '0' ? row.code :(!isMainUnitHidden?row.code:'') }}
                 </template>
               </el-table-column>
               <el-table-column
@@ -76,17 +76,28 @@
                 label="璁¢噺鍗曚綅鍚嶇О"
                 sortable="custom"
               />
-              <!--              <el-table-column-->
-              <!--                prop="isGroup"-->
-              <!--                label="鏄惁澶氳閲�"-->
-              <!--                sortable="custom"-->
-              <!--              >-->
-              <!--                <template slot-scope="{row}">-->
-              <!--                  <el-tag v-if="row.isGroup==='1'" size="small" type="success">鏄�</el-tag>-->
-              <!--                  <el-tag v-if="row.isGroup==='0'" size="small" type="info">鍚�</el-tag>-->
-              <!--                </template>-->
-              <!--              </el-table-column>-->
+              <el-table-column
+                v-if="!isMainUnitHidden"
+                prop="isMainUnit"
+                label="涓昏閲�"
+                sortable="custom"
+              >
+                <template slot-scope="{row}">
+                  {{ row.isMainUnit === '1' ? '鏄�' : '鍚�' }}
+                </template>
+              </el-table-column>
+              <el-table-column
+                v-if="!isMainUnitHidden"
+                prop="changeRate"
+                label="鎹㈢畻鐜�"
+                sortable="custom"
+              />
 
+              <el-table-column
+                prop="data_sources"
+                label="鏁版嵁鏉ユ簮"
+                sortable="custom"
+              />
               <el-table-column
                 prop="lm_user"
                 label="鍒涘缓浜哄憳"
@@ -95,7 +106,6 @@
               <el-table-column
                 prop="lm_date"
                 label="鍒涘缓鏃堕棿"
-
                 sortable="custom"
               />
               <el-table-column
@@ -112,6 +122,7 @@
                         @click="edit('edit',row)"
                       />
                     </el-tooltip>
+
                     <el-tooltip v-del-tab-index class="item" effect="dark" content="鍒犻櫎" placement="top">
                       <i
                         class="el-icon-delete"
@@ -312,7 +323,7 @@
 import elDragDialog from '@/directive/el-drag-dialog'
 import waves from '@/directive/waves'
 import { SaveSearchUnit } from '@/api/ErpSyncMes'
-import { AddUpdateTUnit, TUnitData, TUnitGroup, TUnitGroupProject } from '@/api/ProductModel'
+import { AddUpdateTUnit, DeleteTUnit, TUnitData, TUnitGroup, TUnitGroupProject } from '@/api/ProductModel'
 
 export default {
   name: 'Zzjg',
@@ -362,7 +373,9 @@
       checkboxSelectedArr: [
         { code: '0', name: '鍚�' },
         { code: '1', name: '鏄�' }
-      ]
+      ],
+
+      isMainUnitHidden: true
 
     }
   },
@@ -372,16 +385,17 @@
   mounted() {
     window.addEventListener('resize', this.getHeight)
     this.getHeight()
-
-    this.getTUnitGroup('')
-    this.getTUnitData()
+    this.handleGetApi('')
   },
   methods: {
+    async handleGetApi(code) {
+      await this.getTUnitGroup(code)
+      await this.getTUnitData()
+    },
     async getSaveSearchUnit() {
       const res = await SaveSearchUnit()
       if (res.code === '200') {
-        await this.getTUnitGroup('')
-        await this.getTUnitData()
+        await this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey())
         this.$notify.success('璁¢噺鍗曚綅鍚屾鎴愬姛锛�')
       }
     },
@@ -412,7 +426,15 @@
         unitcode, isgroup: '1'
       }
       const res = await TUnitGroupProject(data)
-      this.tableData = res.data
+      res.data.forEach((i, index) => {
+        i.unitname = i.name
+        i.unitcode = i.code
+        i.uuid = new Date().getTime() + index
+        i.isVisible = 0
+        // i.idunitgroup = unitcode
+        i.checkboxSelected = i.isMainUnit === '1' ? '1' : '0'
+      })
+      this.tableDataDialog = res.data
     },
 
     // 鎺掑簭鏀瑰彉鏃�
@@ -426,17 +448,25 @@
       }
       this.form.order = order
       this.form.prop = prop
-      this.getTUnitGroup()
+      this.getTUnitData()
     },
-    nodeClick(obj, Node, VueComponent) {
+    async nodeClick(obj, Node, VueComponent) {
       if (obj.code === 'S' || obj.code === 'M' || obj.code === '') {
         this.form.tunittype = obj.code
         this.form.tunitgroupcode = ''
-        this.getTUnitData(obj.code)
+        await this.getTUnitData(obj.code)
+        this.isMainUnitHidden = true
+        this.$nextTick(() => {
+          this.$refs.tableDataRef.doLayout()
+        })
       } else {
         this.form.tunittype = 'M'
         this.form.tunitgroupcode = obj.code
-        this.getTUnitData(obj.code)
+        await this.getTUnitData(obj.code)
+        this.isMainUnitHidden = false
+        this.$nextTick(() => {
+          this.$refs.tableDataRef.doLayout()
+        })
       }
     },
     add(operation) {
@@ -456,11 +486,23 @@
       this.dialogForm.OperType = 'Update'
 
       this.$nextTick(() => {
-        this.dialogForm.tunittype = row.isGroup === '0' ? 'S' : 'M'
-        this.dialogForm.tunitgroupcode = row.isGroup === '0' ? '' : row.code
-        this.dialogForm.unitcode = row.code
-        this.dialogForm.unitname = row.name
-        this.dialogForm.data_sources = row.data_sources
+        if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M' || this.$refs.treeLeftRef.getCurrentKey() === '') {
+          this.dialogForm.tunittype = row.isGroup === '0' ? 'S' : 'M'
+          this.dialogForm.tunitgroupcode = row.isGroup === '0' ? row.code : row.idunitgroup
+          this.dialogForm.unitcode = row.code
+          this.dialogForm.unitname = row.name
+          this.dialogForm.data_sources = row.data_sources
+        } else {
+          this.dialogForm.tunittype = 'M'
+          this.dialogForm.tunitgroupcode = row.idunitgroup
+          this.dialogForm.unitcode = row.idunitgroup
+          this.dialogForm.unitname = this.treeLeft[0].children[1].children.find(i => i.code === this.$refs.treeLeftRef.getCurrentKey()).name
+          this.dialogForm.data_sources = row.data_sources
+        }
+
+        if (this.dialogForm.tunittype === 'M') {
+          this.getTUnitGroupProject(row.idunitgroup)
+        }
       })
     },
 
@@ -471,15 +513,31 @@
         cancelButtonText: '鍙栨秷',
         type: 'warning'
       }).then(() => {
-        // DeleteUserSave({ usercode: row.usercode }).then(res => {
-        //   if (res.code === '200') {
-        //     this.$notify.success('鍒犻櫎鎴愬姛!')
-        //     if (this.form.page > 1 && this.tableData.length === 1) {
-        //       this.form.page--
-        //     }
-        //     this.getTUnitGroup()
-        //   }
-        // })
+        if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M' || this.$refs.treeLeftRef.getCurrentKey() === '') {
+          // this.dialogForm.tunittype = this.$refs.treeLeftRef.getCurrentKey()
+        } else {
+          if (row.isMainUnit === '1' || this.tableData.length === 2) {
+            return this.$message.info('璁¢噺鍗曚綅缁勪笅锛屽繀椤绘湁涓�涓富璁¢噺鍜岃嚦灏戜竴涓緟璁¢噺锛�')
+          }
+        }
+
+        const data = {
+          data_sources: row.data_sources,
+          tunittype: row.isGroup === '0' ? 'S' : 'M',
+
+          tunitgroupcode: row.isGroup === '0' ? '' : row.idunitgroup,
+          tunitcode: row.isGroup === '0' ? row.code : (this.$refs.treeLeftRef.getCurrentKey() === 'M' ? '' : row.code)
+        }
+        DeleteTUnit(data).then(res => {
+          if (res.code === '200') {
+            this.$notify.success('鍒犻櫎鎴愬姛!')
+            if (this.form.page > 1 && this.tableData.length === 1) {
+              this.form.page--
+            }
+
+            this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey())
+          }
+        })
       }).catch(() => {
         this.$notify.info('宸插彇娑堝垹闄�')
       })
@@ -502,6 +560,10 @@
     dialogVisibleConfirm() {
       this.$refs.dialogForm.validate(valid => {
         if (valid) {
+          if (this.tableDataDialog.find(i => i.isVisible === 1)) {
+            return this.$message.info('璇峰厛淇濆瓨褰撳墠琛岋紒')
+          }
+
           let data
           if (this.dialogForm.tunittype === 'S') { // 鍗曡閲忔柊澧烇紝淇敼
             data = [{
@@ -531,8 +593,8 @@
             }
 
             this.tableDataDialog.forEach((i, index) => {
-              i.unitcode = index + 1
-              i.isMainUnit = '1'
+              i.unitcode = i.unitcode ? i.unitcode : 'U' + index.toString()
+              i.isMainUnit = i.checkboxSelected === '1' ? '1' : '0'
               i.isSingleUnit = '0'
               i.disabled = '0'
               i.isGroup = '1'
@@ -544,19 +606,14 @@
               children: this.tableDataDialog
             }]
           }
-
-          // console.log(JSON.parse(JSON.stringify(data)))
-
+          console.log(data)
           this.$store.state.app.buttonIsDisabled = true
           AddUpdateTUnit(data, this.dialogForm.data_sources, this.dialogForm.tunittype, this.dialogForm.tunitgroupcode, this.dialogForm.OperType).then(res => {
             if (res.code === '200') {
               this.$notify.success(this.operation === 'add' ? '娣诲姞鎴愬姛锛�' : '淇敼鎴愬姛锛�')
               this.dialogVisible = false
               this.$store.state.app.buttonIsDisabled = false
-              this.getTUnitData()
-              if (this.dialogForm.tunittype === 'M') {
-                this.getTUnitGroup('M')
-              }
+              this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey())
             } else {
               this.$store.state.app.buttonIsDisabled = false
               this.$notify.error(this.operation === 'add' ? '娣诲姞澶辫触锛�' : '淇敼澶辫触锛�')
@@ -567,16 +624,6 @@
     },
 
     tableDataDialogAdd() {
-      // 'unitcode': this.dialogForm.unitcode,
-      //   'unitname': this.dialogForm.unitname,
-      //   'isMainUnit': '0',
-      //   'changeRate': '1',
-      //   'isSingleUnit': '1',
-      //   'disabled': '0',
-      //   'isGroup': '0',
-      //   'rateDescription': '',
-      //   'idunitgroup': ''
-
       if (this.tableDataDialog.find(i => i.isVisible === 1)) {
         return this.$message.info('璇峰厛淇濆瓨涓婁竴鏉℃暟鎹紒')
       }
@@ -586,7 +633,8 @@
         changeRate: 1,
         uuid: new Date().getTime(),
         checkboxSelected: this.tableDataDialog.length === 0 ? '1' : '0',
-        isVisible: 1
+        isVisible: 1,
+        data_sources: 'MES'
       })
       console.log(this.tableDataDialog)
     },

--
Gitblit v1.9.3