Browse Source

Merge branch 'dev' of http://110.41.163.243:9980/kd-aiot/kd-aiot-frontend into dev

lijiang007 2 years ago
parent
commit
fd8d95a9e6

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

@@ -25,6 +25,19 @@ export async function getTreeByPid (parentId) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+
+// 根据type查分类树组
+export async function getTreeByGroup (data) {
+  const res = await request.get(`/main/categoryLevel/getProduceTreeByPid`, {  params: data});
+  if (res.data.code == 0) {
+    return res.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+
+
 // 根据类型查分类树
 export async function getTreeByType (type) {
   const res = await request.get(`/main/categoryLevel/getTreeByType/${type}`);

+ 159 - 0
src/components/AssetTree/group.vue

@@ -0,0 +1,159 @@
+<template>
+  <div class="tree-wrapper">
+    <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"
+    >
+    </el-tree>
+  </div>
+</template>
+
+<script>
+  import { getTreeByGroup } from '@/api/classifyManage';
+  // let originId = '';
+  // let originType = '';
+  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
+      },
+      type: {
+        type: String,
+        default: true
+      },
+      nodeKey: {
+        type: String,
+        default: 'id'
+      }
+      // appendRoot: {
+      //   type: Boolean,
+      //   default: false
+      // },
+    },
+    data() {
+      return {
+        treeList: [],
+        treeLoading: false,
+        parentName: '',
+        parentId: '',
+        currentKey: ''
+      };
+    },
+    mounted() {
+      if (this.init) {
+        this.getTreeData();
+      }
+    },
+    methods: {
+      getInstance() {
+        return this.$refs.tree;
+      },
+      // 获取树结构数据
+      async getTreeData() {
+        try {
+          this.treeLoading = true;
+
+          const res = await getTreeByGroup({type: this.type});
+          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) {}
+        this.treeLoading = false;
+      },
+      // 递归 - 往树children里面添加parentName
+      // _setParentName (tree) {
+      //   let data = tree;
+      //   for (let i = 0; i < data.length; i++) {
+      //     if (data[i].parentId === '0') {
+      //       this.parentName = data[i].name;
+      //       originId = data[i].id;
+      //       originType = data[i].type;
+      //     }
+
+      //     data[i]['originId'] = originId;
+      //     data[i]['originType'] = originType;
+      //     data[i]['parentId'] = data[i]['parentId'];
+      //     if (data[i].children && data[i].children.length > 0) {
+      //       this._setParentName(data[i].children);
+      //     }
+      //   }
+      //   return data;
+      // },
+
+      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>

+ 29 - 16
src/views/classifyManage/treeClassify/components/list-edit.vue

@@ -27,24 +27,23 @@
             placeholder="请输入"
           />
         </el-form-item>
-        <el-form-item label="类型用途:" prop="type" :key="data && data.id + 1">
-          <DictSelection dictName="类型用途" clearable v-model="formData.type">
-          </DictSelection>
-          <!-- <el-select
+        <el-form-item label="分类组:" prop="type" >
+          <el-select
             clearable
+            multiple 
             class="w100"
             :maxlength="20"
-            v-model="formData.type"
+            v-model="type"
             placeholder="请选择"
           >
             <el-option
               v-for="item in typeList"
-              :key="item.code"
+              :key="item.value"
               :label="item.label"
-              :value="item.code"
+              :value="item.value"
             >
             </el-option>
-          </el-select> -->
+          </el-select> 
         </el-form-item>
         <el-form-item label="描述:" prop="remark">
           <el-input
@@ -128,7 +127,6 @@
         code: '',
         separate: '',
         sort: '',
-        type: '',
         remark: '',
         parentId: 0
       };
@@ -137,6 +135,22 @@
         defaultForm,
         // 表单数据
         formData: { ...defaultForm },
+        type: null,
+        typeList: [
+          { 
+            value: '1',
+            label: '产品组'
+          },
+          {
+            value: '2',
+            label: '设备组',
+          },
+          {
+            value: '3',
+            label: '物料组'
+          }
+        ],
+
         // 表单验证规则
         rules: {
           name: [
@@ -153,13 +167,7 @@
               trigger: 'blur'
             }
           ],
-          type: [
-            {
-              required: true,
-              message: '请选择类型用途',
-              trigger: 'change'
-            }
-          ]
+     
         },
         // 提交状态
         loading: false,
@@ -213,6 +221,9 @@
            
           }
           if(!this.rootId || ( this.data &&  this.data.id ==  this.rootId)) {
+             if(this.type) {
+              params.type = this.type.join(',')
+             }
             params.parentId = 0
           }
 
@@ -239,6 +250,8 @@
         if (visible) {
           if (this.data) {
             this.$util.assignObject(this.formData, this.data);
+            console.log(this.data)
+            this.type = this.data.type.split(',')
             this.isUpdate = true;
           } else {
             this.isUpdate = false;

+ 2 - 2
src/views/material/product/index.vue

@@ -10,7 +10,7 @@
         <div class="ele-border-lighter split-layout-right-content">
           <AssetTree
             ref="assetTreeRef"
-            id="9"
+            type="1"
             @handleNodeClick="handleNodeClick"
           />
         </div>
@@ -42,7 +42,7 @@
 </template>
 
 <script>
-  import AssetTree from '@/components/AssetTree';
+  import AssetTree from '@/components/AssetTree/group.vue';
   import ProductSearch from './components/product-search.vue';
   import { getList } from '@/api/classifyManage/itemInformation';