Sfoglia il codice sorgente

修复不良品bug

695593266@qq.com 11 mesi fa
parent
commit
f9d4aca887

+ 34 - 0
src/api/classifyManage/index.js

@@ -1,5 +1,16 @@
 import request from '@/utils/request';
 
+// 物品信息列表
+export async function getList(params) {
+  const res = await request.get('/main/category/getList', {
+    params
+  });
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
 export async function getSubPage(data) {
   const res = await request.get('/main/categoryLevel/getSubPage', {
     params: data
@@ -59,3 +70,26 @@ export async function getInfoById(id) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+export async function getProduceTreeByPid(parentId) {
+  console.log(parentId, '55555');
+  const res = await request.get(
+    `/main/categoryLevel/getProduceTreeByPid?type=${parentId}`
+  );
+  if (res.data.code == 0) {
+    return res.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+// ?type=5
+
+// 根据ids查询物品分类
+export async function getTreeByIds(data) {
+  const res = await request.get(`/pda/main/categoryLevel/pdaTreeByPid`, {
+    params: data
+  });
+  if (res.data.code == 0) {
+    return res.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 10 - 8
src/components/AssetTree/index2.vue

@@ -61,7 +61,7 @@
       //   default: false
       // },
     },
-    data () {
+    data() {
       return {
         treeList: [],
         treeLoading: false,
@@ -70,17 +70,17 @@
         currentKey: ''
       };
     },
-    mounted () {
+    mounted() {
       if (this.init) {
         this.getTreeData();
       }
     },
     methods: {
-      getInstance () {
+      getInstance() {
         return this.$refs.tree;
       },
       // 获取树结构数据
-      async getTreeData () {
+      async getTreeData() {
         try {
           this.treeLoading = true;
 
@@ -104,7 +104,9 @@
             });
             return this.treeList;
           }
-        } catch (error) {}
+        } catch (error) {
+          console.log(error);
+        }
         this.treeLoading = false;
       },
       // 递归 - 往树children里面添加parentName
@@ -127,17 +129,17 @@
       //   return data;
       // },
 
-      handleNodeClick (data, node) {
+      handleNodeClick(data, node) {
         this.$emit('handleNodeClick', data, node);
       },
       // 设置默认高亮行
-      setCurrentKey (id) {
+      setCurrentKey(id) {
         this.currentKey = id;
         this.$refs.tree.setCurrentKey(this.currentKey);
       },
 
       // 获取树的选中状态
-      getSelectList () {
+      getSelectList() {
         const selectList = this.$refs.tree.getCurrentNode();
         return selectList;
       }

+ 158 - 0
src/components/AssetTree/newIndex.vue

@@ -0,0 +1,158 @@
+<template>
+  <div class="tree-wrapper">
+    <!-- <el-input placeholder="输入关键字进行过滤" v-model="filterText">
+    </el-input> -->
+    <el-tree
+      :data="treeList"
+      :props="defaultProps"
+      v-loading="treeLoading"
+      :node-key="nodeKey"
+      ref="tree"
+      :highlight-current="true"
+      :expand-on-click-node="false"
+      @node-click="handleNodeClick"
+      v-bind="$attrs"
+      :default-expand-all="defaultExpandAll"
+      :filter-node-method="filterNode"
+    >
+    </el-tree>
+  </div>
+</template>
+
+<script>
+  import { getTreeByIds, getProduceTreeByPid } from '@/api/classifyManage';
+
+  export default {
+    props: {
+      // treeList私有化处理
+      treeFormate: {
+        type: Function,
+        default: null
+      },
+      defaultProps: {
+        type: Object,
+        default: function () {
+          return {
+            children: 'children',
+            value: 'id',
+            label: 'name'
+          };
+        }
+      },
+      defaultExpandAll: {
+        type: Boolean,
+        default: function () {
+          return true;
+        }
+      },
+      // 初始请求treeList
+      init: {
+        type: Boolean,
+        default: true
+      },
+      treeIds: {
+        type: Array,
+        default: () => []
+      },
+      typeS: {
+        type: Array,
+        default: () => []
+      },
+      nodeKey: {
+        type: String,
+        default: 'id'
+      }
+    },
+    watch: {
+      // filterText(val) {
+      //   this.$refs.tree.filter(val);
+      // }
+    },
+    data() {
+      return {
+        // filterText: '',
+        treeList: [],
+        treeLoading: false,
+        parentName: '',
+        parentId: '',
+        currentKey: ''
+      };
+    },
+    mounted() {
+      if (this.init) {
+        this.getTreeData();
+      }
+    },
+    methods: {
+      filterNode(value, data) {
+        if (!value) return true;
+        return data.name.indexOf(value) !== -1;
+      },
+      getInstance() {
+        return this.$refs.tree;
+      },
+      // 获取树结构数据
+      async getTreeData() {
+        try {
+          this.treeLoading = true;
+
+          const res =
+            this.typeS.length > 0
+              ? await getProduceTreeByPid(this.typeS.toString())
+              : await getTreeByIds({ ids: this.treeIds.join(',') });
+
+          this.treeLoading = false;
+          if (res?.code === '0') {
+            this.treeList = res.data;
+            this.$emit('setRootId', res.data[0].id);
+            if (this.treeFormate) {
+              this.treeList = this.treeFormate(this.treeList);
+            }
+            this.$nextTick(() => {
+              // 默认高亮第一级树节点
+              if (this.treeList[0]) {
+                this.setCurrentKey(this.treeList[0].id);
+                this.handleNodeClick(
+                  this.treeList[0],
+                  this.$refs.tree.getCurrentNode()
+                );
+              }
+            });
+            return this.treeList;
+          }
+        } catch (error) {
+          console.log(error);
+        }
+        this.treeLoading = false;
+      },
+
+      handleNodeClick(data, node) {
+        this.$emit('handleNodeClick', data, node);
+      },
+      // 设置默认高亮行
+      setCurrentKey(id) {
+        this.currentKey = id;
+        this.$refs.tree.setCurrentKey(this.currentKey);
+      },
+
+      // 获取树的选中状态
+      getSelectList() {
+        const selectList = this.$refs.tree.getCurrentNode();
+        return selectList;
+      }
+    }
+  };
+</script>
+
+<style lang="scss" scoped>
+  .tree-wrapper {
+    width: 100%;
+    height: 100%;
+    overflow: auto;
+
+    :deep(.el-tree) {
+      display: inline-block;
+      min-width: 100%;
+    }
+  }
+</style>

+ 1 - 1
src/views/unacceptedProduct/components/EquipmentDialog.vue

@@ -69,7 +69,7 @@
 </template>
 
 <script>
-  import AssetTree from '@/components/AssetTree/index.vue';
+  import AssetTree from '@/components/AssetTree/newIndex.vue';
   import { getList } from '@/api/classifyManage/index';
   export default {
     components: {