From 7993729a2ecc0c7117b2325daf1b811cca28e7f4 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期五, 27 十月 2023 13:11:42 +0800
Subject: [PATCH] 1.库位设置   优化

---
 src/views/basicSettings/storageList.vue |  152 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 113 insertions(+), 39 deletions(-)

diff --git a/src/views/basicSettings/storageList.vue b/src/views/basicSettings/storageList.vue
index 7b68a54..eaa777a 100644
--- a/src/views/basicSettings/storageList.vue
+++ b/src/views/basicSettings/storageList.vue
@@ -63,13 +63,13 @@
         >
           <div class="bodyTopButtonGroup" style="justify-content: space-between">
             <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">鏂板</el-button>
-            <el-button
-              v-waves
-              type="success"
-              icon="el-icon-download"
-              @click="$router.push('./../systemSetting/dataImport?fileCode=7')"
-            >瀵煎叆
-            </el-button>
+            <!--            <el-button-->
+            <!--              v-waves-->
+            <!--              type="success"-->
+            <!--              icon="el-icon-download"-->
+            <!--              @click="$router.push('./../systemSetting/dataImport?fileCode=7')"-->
+            <!--            >瀵煎叆-->
+            <!--            </el-button>-->
           </div>
 
           <div class="bodyTopFormGroup">
@@ -81,10 +81,10 @@
               style="display: flex;"
             >
               <div class="elForm">
-                <el-form-item label="浠撳簱缂栫爜" style=" display: flex;">
+                <el-form-item label="璐т綅缂栫爜" style=" display: flex;">
                   <el-input v-model="form.locacode" placeholder="璇疯緭鍏�" style="width: 200px" />
                 </el-form-item>
-                <el-form-item label="浠撳簱鍚嶇О" style=" display: flex;">
+                <el-form-item label="璐т綅鍚嶇О" style=" display: flex;">
                   <el-input v-model="form.locaname" placeholder="璇疯緭鍏�" style="width: 200px" />
                 </el-form-item>
                 <!--                <el-form-item label="瀛樿揣瑙勬牸" style=" display: flex;">-->
@@ -166,12 +166,12 @@
               />
               <el-table-column
                 prop="code"
-                label="浠撳簱缂栫爜"
+                label="璐т綅缂栫爜"
                 sortable="custom"
               />
               <el-table-column
                 prop="name"
-                label="浠撳簱鍚嶇О"
+                label="璐т綅鍚嶇О"
                 show-overflow-tooltip
                 sortable="custom"
               />
@@ -328,10 +328,10 @@
 
       <el-form ref="dialogForm" class="" inline :rules="dialogFormRules" :model="dialogForm" label-width="110px">
         <!--        <el-divider content-position="left">鍩烘湰淇℃伅</el-divider>-->
-        <el-form-item label="浠撳簱缂栫爜" prop="locacode">
+        <el-form-item label="璐т綅缂栫爜" prop="locacode">
           <el-input v-model="dialogForm.locacode" :disabled="operation!=='add'" style="width: 200px" />
         </el-form-item>
-        <el-form-item label="浠撳簱鍚嶇О" prop="locaname">
+        <el-form-item label="璐т綅鍚嶇О" prop="locaname">
           <el-input v-model="dialogForm.locaname" style="width: 200px" />
         </el-form-item>
 
@@ -342,6 +342,7 @@
             placeholder="璇烽�夋嫨"
             filterable
             :popper-append-to-body="false"
+            :disabled="!isEdit&&operation==='edit'"
             @change="stckcodeChange"
           >
             <el-option
@@ -420,6 +421,9 @@
   TCunstomerClassTreeDelete,
   TCunstomerData, TCunstomerDelete, TSecLocaAddUpdate, TSecLocaData, TSecLocaDelete, TSecLocaTree
 } from '@/api/basicSettings'
+import { WareHouseSelectLocation } from '@/api/GeneralBasicData'
+
+const _ = require('lodash')
 
 export default {
   name: 'RoleList',
@@ -453,6 +457,7 @@
         locacode: '',
         locaname: '',
         partspec: '',
+        flag: '',
         page: 1,
         rows: 20,
         prop: 'lm_date', // 鎺掑簭瀛楁
@@ -486,6 +491,8 @@
         parentlocacode: '', // 涓婄骇璐т綅缂栫爜
         status: '0', // 浣跨敤鐘舵��: 姝e父(0)鍋滅敤(1)
         description: '',
+        depth: '', // 灞傜骇
+
         OperType: '' // 鎿嶄綔绫诲瀷
       },
       dialogFormRules: {
@@ -500,7 +507,9 @@
         ]
       },
       stckcodeArr: [],
-      parentlocacodeArr: []
+      parentlocacodeArr: [],
+
+      isEdit: true
 
     }
   },
@@ -516,28 +525,56 @@
   },
   methods: {
     async getTSecLocaTree() {
-      const res = await TSecLocaTree()
-      this.treeLeftArr = res.data
-      this.treeLeftArr.forEach(e => {
+      const { data: res } = await TSecLocaTree()
+      res.forEach(e => {
         e.name = e.code + ' ' + e.name
       })
-      this.stckcodeArr = res.data.filter(i => i.idparent === '-1')
-      this.treeLeft = [
-        {
-          code: '-1',
-          name: '鍏ㄩ儴'
-        }
-      ]// 宸︿晶鏍�
-      this.treeLeft = arrayToTree(this.treeLeft.concat(res.data), {
+      //  鑾峰彇浠撳簱
+      const ck = res.filter(i => i.depth === 0)// 灞傜骇涓�0鐨�  鏄粨搴�
+      const kw = res.filter(i => i.depth !== 0)// 鍙嶄箣 涓轰粨浣�
+      this.stckcodeArr = ck
+      const tree = arrayToTree(kw, {
         parentProperty: 'idparent',
         customID: 'code',
         childrenProperty: 'children'
       })
+      const group = _.groupBy(tree, i => i.warhouse)
+      const newArr = []
+      ck.forEach(j => {
+        if (Object.keys(group).includes(j.code)) {
+          newArr.push({
+            code: j.code,
+            name: j.name,
+            depth: 0,
+            idparent: '-1',
+            children: group[j.code]
+          })
+        } else {
+          newArr.push({
+            code: j.code,
+            name: j.name,
+            depth: 0,
+            idparent: '-1',
+            children: []
+          })
+        }
+      })
+      this.treeLeft = [
+        {
+          code: '-1',
+          name: '鍏ㄩ儴',
+          idparent: '',
+          children: newArr
+        }
+      ]// 宸︿晶鏍�
       this.$nextTick(() => {
         this.$refs.treeLeftRef.setCurrentKey('-1')
         this.getTSecLocaData(this.$refs.treeLeftRef.getCurrentNode())
       })
+
+      console.log(JSON.parse(JSON.stringify(this.treeLeft)))
     },
+
     async getTSecLocaData(node) {
       let result = ''
       if (node.code === '-1') {
@@ -550,6 +587,13 @@
       //   result.shift()
       // }
       this.form.stckcode = result.join(',')
+
+      if (this.$refs.treeLeftRef.getCurrentNode().idparent === '') {
+        this.form.flag = -1
+      } else {
+        this.form.flag = this.$refs.treeLeftRef.getCurrentNode().depth
+      }
+
       const res = await TSecLocaData(this.form)
 
       this.tableData = res.data
@@ -588,18 +632,29 @@
       this.dialogVisible = true
       this.dialogForm.OperType = 'Update'
 
-      this.$nextTick(() => {
-        this.dialogForm.data_sources = row.data_sources
-        this.dialogForm.locacode = row.code
-        this.dialogForm.locaname = row.name
-        this.dialogForm.stckcode = row.stckcode
+      const temp = this.$refs.treeLeftRef.getCurrentNode()
 
-        this.parentlocacodeArr = this.treeLeftArr.filter(i => i.idparent === this.dialogForm.stckcode)
+      if (temp.idparent === '-1' || temp.idparent === '') {
+        this.isEdit = temp.depth !== 1
+      } else {
+        this.isEdit = false
+      }
 
-        this.dialogForm.parentlocacode = row.parentname ? row.parentcode : null
-        this.dialogForm.status = row.status
-        this.dialogForm.description = row.description
-      })
+      // this.$nextTick(() => {
+      this.dialogForm.data_sources = row.data_sources
+      this.dialogForm.locacode = row.code
+      this.dialogForm.locaname = row.name
+      this.dialogForm.stckcode = row.stckcode
+
+      const { data: res } = await WareHouseSelectLocation({ warhousecode: row.stckcode })
+
+      this.parentlocacodeArr = res
+      // this.parentlocacodeArr = this.treeLeftArr.filter(i => i.idparent === this.dialogForm.stckcode)
+
+      this.dialogForm.parentlocacode = row.parentname ? row.parentcode : null
+      this.dialogForm.status = row.status
+      this.dialogForm.description = row.description
+      // })
     },
     del(row) {
       this.$confirm('鏄惁纭鍒犻櫎?', '鎻愮ず', {
@@ -634,6 +689,12 @@
       this.dialogForm.parentlocacode = ''
       this.dialogForm.description = ''
       this.dialogForm.status = '0'
+
+      if (this.$refs.treeLeftRef.getCurrentNode().idparent === '') {
+        this.form.flag = ''
+      } else {
+        this.form.flag = this.$refs.treeLeftRef.getCurrentNode().depth
+      }
       this.$refs.dialogForm.clearValidate()
     },
     // 瀵硅瘽妗嗗彇娑�
@@ -645,6 +706,17 @@
       this.$refs.dialogForm.validate(valid => {
         if (valid) {
           // console.log(JSON.parse(JSON.stringify(this.dialogForm)), 2)
+
+          if (this.dialogForm.locacode === this.dialogForm.parentlocacode) {
+            return this.$message.error('涓婄骇璐т綅涓嶈兘鏄揣浣嶆湰韬紒')
+          }
+
+          if (this.dialogForm.parentlocacode === '') {
+            this.dialogForm.depth = 1
+          } else {
+            this.dialogForm.depth = parseFloat(this.parentlocacodeArr.find(i => i.code === this.dialogForm.parentlocacode).depth) + 1
+          }
+
           this.$store.state.app.buttonIsDisabled = true
           TSecLocaAddUpdate(this.dialogForm).then(res => {
             if (res.code === '200') {
@@ -652,7 +724,6 @@
               this.dialogVisible = false
               this.$store.state.app.buttonIsDisabled = false
               this.getTSecLocaTree()
-              this.getTSecLocaData(this.$refs.treeLeftRef.getCurrentNode())
             } else {
               this.$store.state.app.buttonIsDisabled = false
               this.$notify.error(this.operation === 'add' ? '娣诲姞澶辫触锛�' : '淇敼澶辫触锛�')
@@ -662,10 +733,13 @@
       })
     },
 
-    stckcodeChange(val) {
-      this.dialogForm.parentlocacode = ''
-      const res = this.recursiveLookupArray([], val)// 閫掑綊鏌ユ壘鏁扮粍
+    async stckcodeChange(val) {
+      const { data: res } = await WareHouseSelectLocation({ warhousecode: val })
       this.parentlocacodeArr = res
+
+      this.dialogForm.parentlocacode = ''
+      // const res = this.recursiveLookupArray([], val)// 閫掑綊鏌ユ壘鏁扮粍
+      // this.parentlocacodeArr = res
     },
     recursiveLookupArray(newArr, val) {
       const temp = this.treeLeftArr.filter(i => i.idparent === val)

--
Gitblit v1.9.3