From 43f4fd08bb99f587c387391aad727fb82b34b7c1 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期五, 11 八月 2023 13:27:47 +0800
Subject: [PATCH] 1.存货类型页面优化

---
 src/views/makeModel/InventoryList.vue |  132 +++++++++++++++++++++++++++++++++----------
 1 files changed, 101 insertions(+), 31 deletions(-)

diff --git a/src/views/makeModel/InventoryList.vue b/src/views/makeModel/InventoryList.vue
index 35f4bc1..cda9131 100644
--- a/src/views/makeModel/InventoryList.vue
+++ b/src/views/makeModel/InventoryList.vue
@@ -48,21 +48,28 @@
               <el-input v-model="form.partspec" placeholder="璇疯緭鍏�" style="width: 200px" />
             </el-form-item>
             <el-form-item label="瀛樿揣绫诲瀷" style=" display: flex;">
-              <el-select
-                v-model="form.stocktypecode"
+              <el-cascader
+                ref="cascader"
+                :options="stocktypeArr"
                 filterable
-                :popper-append-to-body="false"
-                style="width: 200px"
-                placeholder="璇烽�夋嫨"
-              >
-                <!--                @change="val=>stocktypecodeChange(val,'form')"-->
-                <el-option
-                  v-for="item in stocktypeArr"
-                  :key="item.code"
-                  :label="item.name"
-                  :value="item.code"
-                />
-              </el-select>
+                :props="defaultProps"
+                @change="val=>cascaderChange(val,'form')"
+              />
+              <!--              <el-select-->
+              <!--                v-model="form.stocktypecode"-->
+              <!--                filterable-->
+              <!--                :popper-append-to-body="false"-->
+              <!--                style="width: 200px"-->
+              <!--                placeholder="璇烽�夋嫨"-->
+              <!--              >-->
+              <!--                &lt;!&ndash;                @change="val=>stocktypecodeChange(val,'form')"&ndash;&gt;-->
+              <!--                <el-option-->
+              <!--                  v-for="item in stocktypeArr"-->
+              <!--                  :key="item.code"-->
+              <!--                  :label="item.name"-->
+              <!--                  :value="item.code"-->
+              <!--                />-->
+              <!--              </el-select>-->
             </el-form-item>
             <el-form-item v-if="false" label="鐗╂枡绫诲瀷" style=" display: flex;">
               <el-select
@@ -272,22 +279,31 @@
           </el-select>
         </el-form-item>
         <el-form-item label="瀛樿揣绫诲瀷" prop="stocktypecode">
-          <el-select
-            v-model="dialogForm.stocktypecode"
-            filterable
-            :popper-append-to-body="false"
-            style="width: 200px"
-            placeholder="璇烽�夋嫨"
-          >
-            <!--            @change="val=>stocktypecodeChange(val,'dialogForm')"-->
 
-            <el-option
-              v-for="item in stocktypeArr"
-              :key="item.code"
-              :label="item.name"
-              :value="item.code"
-            />
-          </el-select>
+          <el-cascader
+            ref="cascaderDialog"
+            :options="stocktypeArr"
+            filterable
+            :props="defaultPropsDialog"
+            @change="val=>cascaderChange(val,'dialogForm')"
+          />
+
+          <!--          <el-select-->
+          <!--            v-model="dialogForm.stocktypecode"-->
+          <!--            filterable-->
+          <!--            :popper-append-to-body="false"-->
+          <!--            style="width: 200px"-->
+          <!--            placeholder="璇烽�夋嫨"-->
+          <!--          >-->
+          <!--            &lt;!&ndash;            @change="val=>stocktypecodeChange(val,'dialogForm')"&ndash;&gt;-->
+
+          <!--            <el-option-->
+          <!--              v-for="item in stocktypeArr"-->
+          <!--              :key="item.code"-->
+          <!--              :label="item.name"-->
+          <!--              :value="item.code"-->
+          <!--            />-->
+          <!--          </el-select>-->
         </el-form-item>
         <el-form-item label="鎵�灞炰粨搴�" prop="warehousecode">
           <el-select
@@ -720,6 +736,7 @@
 import elDragDialog from '@/directive/el-drag-dialog'
 import waves from '@/directive/waves'
 import TableColumnSettings from '@/components/TableColumnSettings'
+import arrayToTree from 'array-to-tree'
 
 export default {
   name: 'CHDA',
@@ -981,7 +998,20 @@
       isBatchNo: false, // 鏄惁鎵规绠$悊
       isFifo: false, // 鏄惁鍏堣繘鍏堝嚭
       isInCheck: false, // 鏄惁鍏ュ簱妫�楠�
-      isOutCheck: false// 鏄惁鍑哄巶妫�楠�
+      isOutCheck: false, // 鏄惁鍑哄巶妫�楠�
+
+      defaultProps: {
+        checkStrictly: true,
+        expandTrigger: 'hover',
+        value: 'code',
+        label: 'name'
+      },
+      defaultPropsDialog: {
+        // checkStrictly: true,
+        expandTrigger: 'hover',
+        value: 'code',
+        label: 'name'
+      }
     }
   },
   created() {
@@ -1079,6 +1109,34 @@
         }, 10000)
       }
     },
+    cascaderChange(val, type) {
+      if (type === 'form') {
+        this.form.stocktypecode = val[val.length - 1]
+      }
+      if (type === 'dialogForm') {
+        this.dialogForm.stocktypecode = val[val.length - 1]
+      }
+    },
+    // parents:鐢ㄤ簬杩斿洖鐨勬暟缁勶紝childNode:瑕佹煡璇㈢殑鑺傜偣锛宼reeData锛歫son鏍戝舰鏁版嵁
+    findParent(parents, childNode, treeData) {
+      for (let i = 0; i < treeData.length; i++) {
+        // 鐖惰妭鐐规煡璇㈡潯浠�
+        if (treeData[i].code === childNode) {
+          // 濡傛灉鎵惧埌缁撴灉,淇濆瓨褰撳墠鑺傜偣
+          parents.push(treeData[i].code)
+          // 鐢ㄥ綋鍓嶈妭鐐瑰啀鍘诲師鏁版嵁鏌ユ壘褰撳墠鑺傜偣鐨勭埗鑺傜偣
+          this.findParent(parents, treeData[i].iparent_id, this.stocktypeArr)
+          break
+        } else {
+          if (treeData[i].children instanceof Array) {
+            //	娌℃壘鍒帮紝閬嶅巻璇ヨ妭鐐圭殑瀛愯妭鐐�
+            this.findParent(parents, childNode, treeData[i].children)
+          }
+        }
+      }
+      return parents
+    },
+
     async getInventoryFileSelect() {
       const res = await InventoryFileSelect(this.form)
       this.tableData = res.data
@@ -1087,7 +1145,13 @@
     },
     async getStockTypeSelect() {
       const { data: res } = await StockTypeSelect()
-      this.stocktypeArr = res
+      this.stocktypeArr = arrayToTree(res, {
+        parentProperty: 'iparent_id',
+        customID: 'code',
+        childrenProperty: 'children'
+      })
+
+      console.log(this.stocktypeArr, 2)
     },
     async getWareHouseSelect() {
       const { data: res } = await WareHouseSelect()
@@ -1139,6 +1203,7 @@
       this.form.stocktypecode = ''
       this.form.materialtypecode = ''
       this.form.storehousecode = ''
+      this.$refs.cascader.checkedValue = ''
       this.getInventoryFileSelect()
     },
     // 鏂板鎸夐挳
@@ -1149,10 +1214,14 @@
     },
     // 淇敼鎸夐挳
     async edit(operation, row) {
+      const cascaderCheckedValue = this.findParent([], row.stocktypecode, this.stocktypeArr)
+
       this.operation = operation
       this.dialogVisible = true
       // await this.stocktypecodeChange(row.stocktypecode, 'dialogForm')
       this.$nextTick(() => {
+        this.$refs.cascaderDialog.checkedValue = cascaderCheckedValue.reverse()
+
         this.dialogForm.id = row.id
         this.dialogForm.materialcode = row.partcode
         this.dialogForm.materialname = row.partname
@@ -1205,6 +1274,7 @@
       this.isFifo = false
       this.isInCheck = false
       this.isOutCheck = false
+      this.$refs.cascaderDialog.checkedValue = ''
       this.$refs.dialogForm.clearValidate()
     },
     // 瀵硅瘽妗嗗彇娑�

--
Gitblit v1.9.3