Jelajahi Sumber

产品物品管理优化

huang_an 1 tahun lalu
induk
melakukan
e726ba11f4

+ 2 - 0
src/views/material/product/components/index-data.vue

@@ -495,6 +495,7 @@
 
       /* 显示编辑 */
       openEdit(row, status) {
+        console.log(status, this.currentData, 'status');
         this.$router.push({
           path: '/material/product/detail',
           query: {
@@ -503,6 +504,7 @@
             rootId: this.rootId,
             oneProduct: this.oneProduct,
             t: new Date().getTime(),
+            rootTreeId: this.rootTreeId,
             ...this.currentData
           }
         });

+ 39 - 7
src/views/material/product/detail.vue

@@ -416,7 +416,26 @@
         immediate: true
       }
     },
+    async activated() {
+      this.status = this.$route.query.status;
+      this.form.categoryLevelId = this.$route.query.categoryLevelId;
+      this.form.categoryLevelName = this.$route.query.categoryLevelName;
+      this.form.categoryLevelPath = this.$route.query.categoryLevelPath;
+      this.form.categoryLevelPathId = this.$route.query.categoryLevelPathId;
+
+      this.ruleCode = this.$route.query.ruleCode;
+      if (this.ruleCode && this.ruleCode != '自定义' && this.status != 0) {
+        const code = await getCode(this.ruleCode);
+        this.$set(this.form, 'code', code);
+      }
+
+      this.getFieldModel();
+
+      this.getDictList('productionType');
+    },
     async created() {
+      //新增
+
       this.$set(
         this.form,
         'categoryLevelId',
@@ -437,15 +456,14 @@
         'categoryLevelPathId',
         this.$route.query.categoryLevelPathId
       );
-      this.ruleCode = this.$route.query.ruleCode;
 
+      this.ruleCode = this.$route.query.ruleCode;
       if (this.ruleCode && this.ruleCode != '自定义' && this.status != 0) {
         const code = await getCode(this.ruleCode);
         this.$set(this.form, 'code', code);
       }
 
       this.getFieldModel();
-      this.status = this.$route.query.status;
 
       // if (this.$route.query.id) {
       //   this._getDetails();
@@ -471,10 +489,8 @@
           rootCategoryCode(this.categoryLevelPathId).then((res) => {
             this.$set(this.form, 'code', res);
           });
-      
-          this.form.createTime = null
 
-     
+          this.form.createTime = null;
         }
 
         this.$forceUpdate();
@@ -718,12 +734,28 @@
               }
             );
           }
+          console.log('保存', this.$route.query.rootTreeId);
           addMaterial(data)
             .then((msg) => {
               this.loading = false;
               this.$message.success(msg);
-              reloadPageTab({ fullPath: '/material/product' });
-              this.$router.go(-1);
+              // reloadPageTab({ fullPath: '/material/product' });
+              // this.$router.go(-1);
+              if (this.$route.query.rootTreeId == 9) {
+                this.$router.push({
+                  path: '/product/oneProduct',
+                  query: {
+                    categoryLevelId: this.form.categoryLevelId
+                  }
+                });
+              } else {
+                this.$router.push({
+                  path: '/material/product',
+                  query: {
+                    categoryLevelId: this.form.categoryLevelId
+                  }
+                });
+              }
             })
             .catch((e) => {
               this.loading = false;

+ 49 - 12
src/views/material/product/index.vue

@@ -102,6 +102,8 @@
 
   import { getInfoById } from '@/api/classifyManage';
 
+  import { reloadPageTab } from '@/utils/page-tab-util';
+
   export default {
     components: {
       IndexData,
@@ -165,13 +167,28 @@
           if (res?.code === '0') {
             this.treeList = res.data;
 
-            this.$nextTick(() => {
-              // 默认高亮第一级树节点
-              if (this.treeList[0]) {
-                this.rootTreeId = this.treeList[0].id;
-                this.getDetail(this.treeList[0].id);
-              }
-            });
+            if (!this.$route.query.categoryLevelId) {
+              this.$nextTick(() => {
+                //默认高亮第一级树节点;
+                if (this.treeList[0]) {
+                  this.rootTreeId = this.treeList[0].id;
+                  this.getDetail(this.treeList[0].id);
+                }
+              });
+            } else {
+              this.getDetail(this.$route.query.categoryLevelId);
+              this.$nextTick(() => {
+                this.$refs.treeRef.setCurrentKey(
+                  this.$route.query.categoryLevelId
+                );
+              });
+              const objByid = this.findNodeById(
+                this.treeList,
+                this.$route.query.categoryLevelId
+              );
+              console.log(objByid, '当前选择的物品');
+              this.publicfun(objByid);
+            }
             return this.treeList;
           }
         } catch (error) {}
@@ -189,9 +206,32 @@
           });
         }
       },
+      findNodeById(tree, targetId) {
+        function traverse(nodes) {
+          for (let node of nodes) {
+            if (node.id === targetId) {
+              return node;
+            } else if (node.children && node.children.length > 0) {
+              const foundNode = traverse(node.children);
+              if (foundNode) {
+                return foundNode;
+              }
+            }
+          }
+          return null;
+        }
+
+        return traverse(tree);
+      },
+
+      async handleNodeClick(data, node) {
+        this.$route.query.categoryLevelId = '';
 
-      handleNodeClick(data, node) {
         this.curNode = node;
+        await this.publicfun(data);
+        await this.getDetail(data.id);
+      },
+      publicfun(data) {
         this.pathList = this.findParent([], data, this.treeList);
         this.rootTreeId = null;
         if (this.pathList.length == 0) {
@@ -232,12 +272,9 @@
         PathInfo.categoryLevelName = data.name;
         PathInfo.ruleCode = ruleCode;
 
-        console.log(PathInfo, '点击品分类');
+        console.log(PathInfo, '点击品分类');
         this.currentData = PathInfo;
-
-        this.getDetail(data.id);
       },
-
       /* 刷新表格 */
       reload(where) {
         this.$refs.listData.reload(where);

+ 51 - 11
src/views/material/product/oneProduct.vue

@@ -102,6 +102,8 @@
 
   import { getInfoById } from '@/api/classifyManage';
 
+  import { deepClone } from '@/utils';
+
   export default {
     components: {
       IndexData,
@@ -161,13 +163,29 @@
           if (res?.code === '0') {
             this.treeList = res.data;
 
-            this.$nextTick(() => {
-              // 默认高亮第一级树节点
-              if (this.treeList[0]) {
-                this.rootTreeId = this.treeList[0].id;
-                this.getDetail(this.treeList[0].id);
-              }
-            });
+            if (!this.$route.query.categoryLevelId) {
+              this.$nextTick(() => {
+                //默认高亮第一级树节点;
+                if (this.treeList[0]) {
+                  this.rootTreeId = this.treeList[0].id;
+                  this.getDetail(this.treeList[0].id);
+                  console.log(this.treeList[0].id, 'rootTreeId');
+                }
+              });
+            } else {
+              this.getDetail(this.$route.query.categoryLevelId);
+              this.$nextTick(() => {
+                this.$refs.treeRef.setCurrentKey(
+                  this.$route.query.categoryLevelId
+                );
+              });
+              const objByid = this.findNodeById(
+                this.treeList,
+                this.$route.query.categoryLevelId
+              );
+              console.log(objByid, '当前选择的产品');
+              this.publicfun(objByid);
+            }
             return this.treeList;
           }
         } catch (error) {}
@@ -186,8 +204,32 @@
         }
       },
 
+      findNodeById(tree, targetId) {
+        function traverse(nodes) {
+          for (let node of nodes) {
+            if (node.id === targetId) {
+              return node;
+            } else if (node.children && node.children.length > 0) {
+              const foundNode = traverse(node.children);
+              if (foundNode) {
+                return foundNode;
+              }
+            }
+          }
+          return null;
+        }
+
+        return traverse(tree);
+      },
       handleNodeClick(data, node) {
+        this.$route.query.categoryLevelId = '';
         this.curNode = node;
+        this.publicfun(data);
+
+        this.getDetail(data.id);
+      },
+
+      publicfun(data) {
         this.pathList = this.findParent([], data, this.treeList);
         this.rootTreeId = null;
         if (this.pathList.length == 0) {
@@ -228,10 +270,8 @@
         PathInfo.categoryLevelName = data.name;
         PathInfo.ruleCode = ruleCode;
 
-        console.log(PathInfo, '点击产品分类');
-        this.currentData = PathInfo;
-
-        this.getDetail(data.id);
+        this.currentData = deepClone(PathInfo);
+        console.log(this.currentData, '选中的产品分类');
       },
 
       /* 刷新表格 */