ysy 2 năm trước cách đây
mục cha
commit
9aae3ffe20

+ 7 - 1
src/components/Dict/DictSelection.vue

@@ -1,4 +1,5 @@
 <template>
+
   <el-select
     v-model="selectVal"
     style="width: 100%"
@@ -10,7 +11,7 @@
       v-for="item in dictList"
       :key="item[valueName]"
       :value="item[valueName]"
-      :label="item[labelName]"
+      :label="ChinEng ? item[labelName] + '-' + item[valueName] : item[labelName]"
     ></el-option>
   </el-select>
 </template>
@@ -39,7 +40,12 @@
       valueName: {
         type: String,
         default: 'dictCode'
+      },
+      ChinEng: {
+        Boolean,
+        default: false
       }
+      
     },
     data () {
       return {};

+ 2 - 0
src/enum/dict.js

@@ -33,6 +33,8 @@ export default {
   证件类型: 'id_type',
   台账状态: 'ledger',
   工种: 'workType',
+  二级编码规则: 'Secondary',
+  三级编码规则: 'Third'
 
 };
 

+ 95 - 74
src/views/material/product/components/CategoryDialog.vue

@@ -1,24 +1,10 @@
 <template>
-  <ele-modal
-    :title="title"
-    :visible.sync="treeVisible"
-    :before-close="handleClose"
-    :close-on-click-modal="false"
-    :close-on-press-escape="false"
-    append-to-body
-    width="40%"
-  >
+  <ele-modal :title="title" :visible.sync="treeVisible" :before-close="handleClose" :close-on-click-modal="false"
+    :close-on-press-escape="false" append-to-body width="40%">
     <div class="ele-border-lighter sys-organization-list">
-      <el-tree
-        ref="tree"
-        :data="treeData"
-        highlight-current
-        node-key="id"
-        :props="{ label: 'name' }"
-        :expand-on-click-node="false"
-        :default-expand-all="true"
-        @node-click="onNodeClick"
-      />
+      <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">
+      </el-tree>
     </div>
     <template v-slot:footer>
       <el-button @click="handleClose">关闭</el-button>
@@ -28,15 +14,23 @@
 </template>
 
 <script>
- import { getTreeByPid } from '@/api/material/manage.js'
+import { getTreeByGroup } from '@/api/classifyManage';
 export default {
-  data () {
+  data() {
     return {
       treeVisible: false,
-      treeData: [],
-      current:null,
-      title:'选择分类',
-      pathList:[]
+      treeList: [],
+      current: null,
+      title: '选择分类',
+      pathList: [],
+
+      treeLoading: false,
+      nodeKey: 'id',
+      defaultProps: {
+        children: 'children',
+        value: 'id',
+        label: 'name'
+      }
     }
   },
 
@@ -44,58 +38,85 @@ export default {
 
   },
   methods: {
-    open(pid,title){
+    open() {
       this.treeVisible = true
-      this.title = title
-      this.getTree(pid)
+      this.getTreeData()
     },
-    handleClose () {
+    handleClose() {
       this.treeVisible = false
       this.current = null
     },
-    getTree(pid){
-      getTreeByPid(pid).then(res=>{
-         this.treeData = res
-      })
+    // 获取树结构数据
+    async getTreeData() {
+      try {
+        this.treeLoading = true;
+
+        const res = await getTreeByGroup({ type: 1 });
+        this.treeLoading = false;
+        if (res?.code === '0') {
+          this.treeList = res.data;
+
+
+          return this.treeList;
+        }
+      } catch (error) { }
+      this.treeLoading = false;
     },
-    onNodeClick(node){
-       this.current = node
+
+
+    handleNodeClick(data, node) {
+      this.$emit('handleNodeClick', data, node);
+      this.current = data
     },
-    selected(){
-       if(!this.current){
-         return this.$message.warning(`请${this.title}`)
-       }
-       this.pathList = this.findParent([],this.current,this.treeData)
-       this.pathList.unshift(this.current)
-       const PathInfo = {
-         categoryLevelPath:'',
-         categoryLevelPathId:[]
-       }
-       const pathName = []
-       this.pathList.map(item=>{
-          pathName.unshift(item.name)
-          PathInfo.categoryLevelPathId.unshift(item.id)
-       })
-       PathInfo.categoryLevelPath = pathName.join('-')
-       PathInfo.categoryLevelPathId = PathInfo.categoryLevelPathId.join(',')
-       this.$emit('chooseCategory',this.current,this.title,PathInfo)
-       this.handleClose()
+
+    selected() {
+      if (!this.current) {
+        return this.$message.warning(`请${this.title}`)
+      }
+      this.pathList = this.findParent([], this.current, this.treeList)
+
+
+
+      let ruleCode = null
+      if (this.pathList.length == 0) {
+        ruleCode = this.current.ruleCode
+
+      } else {
+        ruleCode = this.pathList[this.pathList.length - 1] && this.pathList[this.pathList.length - 1].ruleCode
+      }
+
+
+      this.pathList.unshift(this.current)
+      const PathInfo = {
+        categoryLevelPath: '',
+        categoryLevelPathId: []
+      }
+      const pathName = []
+      this.pathList.map(item => {
+        pathName.unshift(item.name)
+        PathInfo.categoryLevelPathId.unshift(item.id)
+      })
+      PathInfo.categoryLevelPath = pathName.join('-')
+      PathInfo.categoryLevelPathId = PathInfo.categoryLevelPathId.join(',')
+      console.log(PathInfo)
+      this.$emit('chooseCategory', this.current, this.title, PathInfo, ruleCode)
+      this.handleClose()
     },
 
-    // parents:用于返回的数组,childNode:要查询的节点,treeData:json树形数据
-    findParent (parents, childNode, treeData) {
-      for (let i = 0; i < treeData.length; i++) {
+    // parents:用于返回的数组,childNode:要查询的节点,treeList:json树形数据
+    findParent(parents, childNode, treeList) {
+      for (let i = 0; i < treeList.length; i++) {
         // 父节点查询条件
-        if (treeData[i].id === childNode.parentId) {
+        if (treeList[i].id === childNode.parentId) {
           // 如果找到结果,保存当前节点
-          parents.push(treeData[i])
+          parents.push(treeList[i])
           // 用当前节点再去原数据查找当前节点的父节点
-          this.findParent(parents, treeData[i],this.treeData)
+          this.findParent(parents, treeList[i], this.treeList)
           break
         } else {
-          if (treeData[i].children instanceof Array) {
+          if (treeList[i].children instanceof Array) {
             //	没找到,遍历该节点的子节点
-            this.findParent(parents, childNode, treeData[i].children)
+            this.findParent(parents, childNode, treeList[i].children)
           }
         }
       }
@@ -107,19 +128,19 @@ export default {
 </script>
 
 <style lang="scss" scoped>
-  .sys-organization-list {
-    height: calc(100vh - 264px);
-    box-sizing: border-box;
-    border-width: 1px;
-    border-style: solid;
-    overflow: auto;
-  }
+.sys-organization-list {
+  height: calc(100vh - 264px);
+  box-sizing: border-box;
+  border-width: 1px;
+  border-style: solid;
+  overflow: auto;
+}
 
-  .sys-organization-list :deep(.el-tree-node__content) {
-    height: 40px;
+.sys-organization-list :deep(.el-tree-node__content) {
+  height: 40px;
 
-    & > .el-tree-node__expand-icon {
-      margin-left: 10px;
-    }
+  &>.el-tree-node__expand-icon {
+    margin-left: 10px;
   }
+}
 </style>

+ 130 - 0
src/views/material/product/components/codeDialog.vue

@@ -0,0 +1,130 @@
+<template>
+    <ele-modal title="自定义编码" :visible.sync="visible" v-if="visible" :before-close="handleClose" :close-on-click-modal="false"
+        :close-on-press-escape="false" append-to-body width="40%">
+        <el-form label-width="120px" ref="formRef" :model="formData" :rules="rules">
+
+            <div class="row_flex">
+
+
+               <el-form-item label="" prop="leave">
+                    <el-input v-model="formData.leave" readonly style="width: 120px;margin-left: 8px;"></el-input>
+                </el-form-item>
+
+
+                 <span>-</span>
+                <el-form-item label="" prop="leave2">
+                    <DictSelection :ChinEng="true" dictName="二级编码规则" clearable v-model="formData.leave2">
+                    </DictSelection>
+                </el-form-item>
+                <span>-</span>
+
+                <el-form-item label="" prop="leave3">
+                    <DictSelection :ChinEng="true" dictName="二级编码规则" clearable v-model="formData.leave3">
+                    </DictSelection>
+                </el-form-item>
+                <span>-</span> 
+
+                <el-form-item label="" prop="code">
+                    <el-input v-model.number="formData.code" maxlength="4" placeholder="流水号"
+                        style="width: 120px;margin-left: 8px;"></el-input>
+                </el-form-item> 
+
+
+
+            </div>
+            <div class="des">设备\模具\周转车\舟皿三级编码规则,例如:CX-JY-SB(本级)-0001 </div>
+
+
+        </el-form>
+
+
+        <template v-slot:footer>
+            <el-button @click="handleClose">取消</el-button>
+            <el-button type="primary" @click="save" :loading="loading">
+                保存
+            </el-button>
+        </template>
+
+    </ele-modal>
+</template>
+  
+<script>
+
+export default {
+    data() {
+        return {
+            visible: false,
+            loading: false,
+
+            formData: {
+                leave: 'CX',
+                leave2: null,
+                leave3: null,
+                code: null
+            },
+
+            rules: {
+                leave2: { required: true, message: '请选择', trigger: 'change' },
+                leave3: { required: true, message: '请选择', trigger: 'change' },
+                code: { required: true, message: '请输入流水号', trigger: 'blur' }
+            }
+        }
+    },
+
+    watch: {
+
+    },
+    methods: {
+        open() {
+            this.visible = true
+        },
+        handleClose() {
+            this.visible = false
+            this.formData = null
+        },
+
+
+        save() {
+
+            this.$refs.formRef.validate((valid) => {
+                if (!valid) {
+                    return false;
+                }
+                let code = this.formData.leave   + '-' +  this.formData.leave2 + '-' +  this.formData.leave3 + '-' +  this.formData.code
+                this.$emit('chooseCode', code)
+                this.handleClose()
+
+
+            })
+        },
+
+
+    }
+}
+</script>
+  
+<style lang="scss" scoped>
+.row_flex {
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+}
+
+::v-deep .el-form-item__content {
+    margin: 0 8px !important;
+}
+
+::v-deep .el-form-item {
+    margin-bottom: 0px;
+}
+
+::v-deep .el-form-item:last-child {
+    margin-bottom: 0px !important;
+
+}
+
+.des {
+    margin-top: 20px;
+}
+</style>
+  

+ 324 - 299
src/views/material/product/detail.vue

@@ -1,74 +1,77 @@
 <template>
   <div class="ele-body">
     <el-card shadow="never">
-      <el-form
-        label-width="120px"
-        ref="manageForm"
-        :model="form"
-        :rules="rules"
-      >
+      <el-form label-width="120px" ref="manageForm" :model="form" :rules="rules">
         <headerTitle title="基本信息">
           <el-button @click="cancel">返回</el-button>
-          <el-button type="primary" @click="submit" :loading="loading"
-            >保存</el-button
-          ></headerTitle
-        >
+          <el-button type="primary" @click="submit" :loading="loading">保存</el-button>
+        </headerTitle>
 
         <el-row :gutter="24">
-
           <el-col :span="8">
             <el-form-item label="分类" prop="categoryLevelName">
-              <el-input
-                v-model="form.categoryLevelName"
-                @click.native="openCategory"
-              />
+              <el-input v-model="form.categoryLevelName" @click.native="openCategory" />
             </el-form-item>
           </el-col>
 
-          
-          <el-col :span="8">
+         
+        <el-col :span="8" v-if="ruleCode == '自定义'"  >
             <el-form-item label="编码" prop="code">
-              <el-input v-model="form.code" />
+              <el-input v-model="form.code" readonly @click.native="openCode" />
             </el-form-item>
           </el-col>
+
+          <el-col :span="8" v-else>
+            <el-form-item label="编码" prop="code">
+              <el-input v-model="form.code"  />
+            </el-form-item>
+          </el-col> 
+
+         
+
+
+ 
+
           <el-col :span="8">
             <el-form-item label="名称" prop="name">
               <el-input v-model="form.name" />
             </el-form-item>
           </el-col>
-    
+
           <el-col :span="8">
             <el-form-item label="牌号" prop="brandNum">
               <el-input v-model="form.brandNum" />
             </el-form-item>
           </el-col>
+          <el-col :span="8">
+            <el-form-item label="型号" prop="modelType">
+              <el-input v-model="form.modelType" />
+            </el-form-item>
+          </el-col>
+
           <el-col :span="8">
             <el-form-item label="规格" prop="specification">
               <el-input v-model="form.specification" />
             </el-form-item>
           </el-col>
+
           <el-col :span="8">
-            <el-form-item label="型号" prop="modelType">
-              <el-input v-model="form.modelType" />
+            <el-form-item label="计量单位" prop="measuringUnit">
+              <DictSelection dictName="计量单位" clearable v-model="form.measuringUnit">
+              </DictSelection>
             </el-form-item>
           </el-col>
+
           <el-col :span="8">
-            <el-form-item label="计量单位" prop="measuringUnit">
-              <DictSelection
-                dictName="计量单位"
-                clearable
-                v-model="form.measuringUnit"
-              >
+            <el-form-item label="重量单位" prop="roughWeight">
+              <DictSelection dictName="重量单位" clearable v-model="form.roughWeight">
               </DictSelection>
             </el-form-item>
           </el-col>
+
           <el-col :span="8">
             <el-form-item label="包装单位" prop="packingUnit">
-              <DictSelection
-                dictName="包装单位"
-                clearable
-                v-model="form.packingUnit"
-              >
+              <DictSelection dictName="包装单位" clearable v-model="form.packingUnit">
               </DictSelection>
             </el-form-item>
           </el-col>
@@ -76,12 +79,7 @@
             <el-form-item label="体积">
               <div class="form-line">
                 <el-input v-model="form.volume" />
-                <DictSelection
-                  class="line-select"
-                  dictName="体积单位"
-                  clearable
-                  v-model="form.volumeUnit"
-                >
+                <DictSelection class="line-select" dictName="体积单位" clearable v-model="form.volumeUnit">
                 </DictSelection>
               </div>
             </el-form-item>
@@ -90,12 +88,7 @@
             <el-form-item label="毛重">
               <div class="form-line">
                 <el-input v-model="form.roughWeight" />
-                <DictSelection
-                  class="line-select"
-                  dictName="重量单位"
-                  clearable
-                  v-model="form.weightUnit"
-                >
+                <DictSelection class="line-select" dictName="重量单位" clearable v-model="form.weightUnit">
                 </DictSelection>
               </div>
             </el-form-item>
@@ -104,38 +97,28 @@
             <el-form-item label="净重">
               <div class="form-line">
                 <el-input v-model="form.netWeight" />
-                <DictSelection
-                  class="line-select"
-                  dictName="重量单位"
-                  clearable
-                  v-model="form.weightUnit"
-                >
+                <DictSelection class="line-select" dictName="重量单位" clearable v-model="form.weightUnit">
                 </DictSelection>
               </div>
             </el-form-item>
           </el-col>
           <el-col :span="8">
             <el-form-item label="所属部门">
-              <deptSelect
-                v-model="form.deptLeaderId"
-                @changeGroup="searchDeptNodeClick"
-              />
+              <deptSelect v-model="form.deptLeaderId" @changeGroup="searchDeptNodeClick" />
             </el-form-item>
           </el-col>
           <el-col :span="8">
             <el-form-item label="负责人">
-              <personSelect
-                ref="directorRef"
-                v-model="form.deptId"
-                @selfChange="handleDirectorChange"
-                :init="false"
-              />
+              <personSelect ref="directorRef" v-model="form.deptId" @selfChange="handleDirectorChange" :init="false" />
             </el-form-item>
           </el-col>
         </el-row>
       </el-form>
     </el-card>
 
+
+    <!--  自定义编码 -->
+    <CodeDialog ref="codeRefs"  @chooseCode="chooseCode"></CodeDialog>
     <!-- 分类选择弹窗 -->
     <CategoryDialog ref="categoryRefs" @chooseCategory="confirmCategory" />
     <!-- 仓储配置 -->
@@ -155,265 +138,307 @@
     <!-- 备注信息 -->
     <RemarkInfo ref="remarkRefs" :form="remarkform" />
     <!-- 关联信息 -->
-    <linkMsg
-      ref="linkMsgRef"
-      :id="$route.query.id"
-      :categoryLevelId="form.categoryLevelId"
-      :categoryLevelGroupId = "form.categoryLevelGroupId"
-    />
+    <linkMsg ref="linkMsgRef" :id="$route.query.id" :categoryLevelId="form.categoryLevelId"
+      :categoryLevelGroupId="form.categoryLevelGroupId" />
   </div>
 </template>
 
 <script>
-  import GroupDialog from './components/GroupDialog.vue';
-  import CategoryDialog from './components/CategoryDialog.vue';
-  import WarehouseInfo from './components/WarehouseInfo.vue';
-  import ProcureInfo from './components/ProcureInfo.vue';
-  import ProductionInfo from './components/ProductionInfo.vue';
-  import PlanInfo from './components/PlanInfo.vue';
-  import SalesInfo from './components/SalesInfo.vue';
-  import QualityInfo from './components/QualityInfo.vue';
-  import BoatInfo from './components/BoatInfo.vue';
-  import TurnoverInfo from './components/TurnoverInfo.vue';
-  import MoldInfo from './components/MoldInfo.vue';
-  import RemarkInfo from './components/RemarkInfo.vue';
-  import deptSelect from '@/components/CommomSelect/dept-select.vue';
-  import personSelect from '@/components/CommomSelect/person-select.vue';
-  import linkMsg from './components/link-msg.vue';
-  import { getDetails } from '@/api/classifyManage/itemInformation';
-  import { addMaterial } from '@/api/material/manage.js';
-  import { deepClone } from '@/utils/index';
-  import { finishPageTab, reloadPageTab } from '@/utils/page-tab-util';
-  export default {
-    name: 'ManageMaterial',
-    components: {
-      linkMsg,
-      GroupDialog,
-      deptSelect,
-      personSelect,
-      WarehouseInfo,
-      ProcureInfo,
-      ProductionInfo,
-      PlanInfo,
-      SalesInfo,
-      QualityInfo,
-      BoatInfo,
-      TurnoverInfo,
-      MoldInfo,
-      RemarkInfo,
-      CategoryDialog
-    },
-    data () {
-      return {
-        loading: false,
-        form: {
-          categoryLevelGroupName: '',
-          categoryLevelName: ''
-        },
-        remarkform: {
-          remarkAttach: []
-        },
-        categoryAps: {},
-        categoryMes: {},
-        categoryMold: {},
-        categoryPallet: {},
-        categoryQms: {},
-        categoryVehicle: {},
-        categoryWms: {},
-        // 表单验证规则
-        rules: {
-          categoryLevelGroupName: [
-            { required: true, message: '请选择所属物料组', trigger: 'change' }
-          ],
-          code: [{ required: true, message: '请输入编码', trigger: 'blur' }],
-          name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
-          categoryLevelName: [
-            { required: true, message: '请选择所属分类', trigger: 'change' }
-          ],
-          measuringUnit: [
-            { required: true, message: '请选择计量单位', trigger: 'change' }
-          ]
-        },
-        PathInfo: {},
-        id: null
-      };
-    },
-    created () {
-      this._getDetails();
-    },
-    methods: {
-      async _getDetails () {
-        const data = await getDetails(this.$route.query.id);
-        const info = deepClone(data);
-        this.form = {
-          ...info.category
-        };
-        this.judgeSet(info);
-        this.searchDeptNodeClick(this.form.deptLeaderId);
-      },
-      // 判断字段类型并赋值
-      judgeSet (info) {
-        if (typeof info.categoryAps == 'string') {
-          this.categoryAps = {};
-        } else {
-          this.categoryAps = info.categoryAps;
-        }
-        if (typeof info.categoryMes == 'string') {
-          this.categoryMes = {};
-        } else {
-          this.categoryMes = info.categoryMes;
-        }
-        if (typeof info.categoryMold == 'string') {
-          this.categoryMold = {};
-        } else {
-          this.categoryMold = info.categoryMold;
-        }
-        if (typeof info.categoryPallet == 'string') {
-          this.categoryPallet = {};
-        } else {
-          this.categoryPallet = info.categoryPallet;
-        }
-        if (typeof info.categoryQms == 'string') {
-          this.categoryQms = {};
-        } else {
-          this.categoryQms = info.categoryQms;
-        }
-        if (typeof info.categoryVehicle == 'string') {
-          this.categoryVehicle = {};
-        } else {
-          this.categoryVehicle = info.categoryVehicle;
-        }
-        if (typeof info.categoryWms == 'string') {
-          this.categoryWms = {};
-        } else {
-          this.categoryWms = info.categoryWms;
-        }
-      },
-      // 选择所属部门
-      searchDeptNodeClick (id, info) {
-        // 根据部门获取人员
-        const params = { executeGroupId: id };
-        this.$nextTick(() => {
-          this.$refs.directorRef.getList(params);
-        });
+import GroupDialog from './components/GroupDialog.vue';
+import CodeDialog from './components/codeDialog.vue'
+import CategoryDialog from './components/CategoryDialog.vue';
+import WarehouseInfo from './components/WarehouseInfo.vue';
+import ProcureInfo from './components/ProcureInfo.vue';
+import ProductionInfo from './components/ProductionInfo.vue';
+import PlanInfo from './components/PlanInfo.vue';
+import SalesInfo from './components/SalesInfo.vue';
+import QualityInfo from './components/QualityInfo.vue';
+import BoatInfo from './components/BoatInfo.vue';
+import TurnoverInfo from './components/TurnoverInfo.vue';
+import MoldInfo from './components/MoldInfo.vue';
+import RemarkInfo from './components/RemarkInfo.vue';
+import deptSelect from '@/components/CommomSelect/dept-select.vue';
+import personSelect from '@/components/CommomSelect/person-select.vue';
+import linkMsg from './components/link-msg.vue';
+import { getDetails } from '@/api/classifyManage/itemInformation';
+
+import { getCode } from '@/api/codeManagement';
+
+import { addMaterial } from '@/api/material/manage.js';
+import { deepClone } from '@/utils/index';
+import { finishPageTab, reloadPageTab } from '@/utils/page-tab-util';
+export default {
+  name: 'ManageMaterial',
+  components: {
+    linkMsg,
+    GroupDialog,
+    deptSelect,
+    personSelect,
+    WarehouseInfo,
+    ProcureInfo,
+    ProductionInfo,
+    PlanInfo,
+    SalesInfo,
+    QualityInfo,
+    BoatInfo,
+    TurnoverInfo,
+    MoldInfo,
+    RemarkInfo,
+    CategoryDialog,
+    CodeDialog
+  },
+  data() {
+    return {
+      loading: false,
+      form: {
+        categoryLevelGroupName: '',
+        categoryLevelName: ''
       },
-      //选择负责人
-      handleDirectorChange (id, info) {},
-      // 确定分类
-      confirmCategory (node, title, PathInfo) {
-        if (title == '选择产品分类') {
-          this.$set(this.form, 'productCategoryLevelName', node.name);
-          this.$set(this.form, 'productCategoryLevelId', node.id);
-        } else {
-          this.$set(this.form, 'categoryLevelName', node.name);
-          this.$set(this.form, 'categoryLevelId', node.id);
-          this.$set(this.form, 'categoryLevelPath', node.name);
-          this.$set(this.form, 'categoryLevelPathId', node.id);
-          this.PathInfo = PathInfo;
-        }
+      remarkform: {
+        remarkAttach: []
       },
-      openCategory () {
-        this.$refs.categoryRefs.open(this.form.categoryLevelId);
+      categoryAps: {},
+      categoryMes: {},
+      categoryMold: {},
+      categoryPallet: {},
+      categoryQms: {},
+      categoryVehicle: {},
+      categoryWms: {
+        isUnpack: 1
       },
-      cancel () {
-        finishPageTab();
-        this.$router.go(-1);
+      // 表单验证规则
+      rules: {
+        categoryLevelGroupName: [
+          { required: true, message: '请选择所属物料组', trigger: 'change' }
+        ],
+        code: [{ required: true, message: '请输入编码', trigger: 'blur' }],
+        name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
+        categoryLevelName: [
+          { required: true, message: '请选择所属分类', trigger: 'change' }
+        ],
+        measuringUnit: [
+          { required: true, message: '请选择计量单位', trigger: 'change' }
+        ]
       },
+      PathInfo: {},
+      id: null,
+
+      ruleCode: null
+    };
+  },
+  async created() {
+    if (this.$route.query.id) {
+      this._getDetails();
+    }
+
+
+  },
+  methods: {
+    async _getDetails() {
+      const data = await getDetails(this.$route.query.id);
+      const info = deepClone(data);
+      this.form = {
+        ...info.category
+      };
+      this.judgeSet(info);
+      this.searchDeptNodeClick(this.form.deptLeaderId);
+    },
+    // 判断字段类型并赋值
+    judgeSet(info) {
+      if (typeof info.categoryAps == 'string') {
+        this.categoryAps = {};
+      } else {
+        this.categoryAps = info.categoryAps;
+      }
+      if (typeof info.categoryMes == 'string') {
+        this.categoryMes = {};
+      } else {
+        this.categoryMes = info.categoryMes;
+      }
+      if (typeof info.categoryMold == 'string') {
+        this.categoryMold = {};
+      } else {
+        this.categoryMold = info.categoryMold;
+      }
+      if (typeof info.categoryPallet == 'string') {
+        this.categoryPallet = {};
+      } else {
+        this.categoryPallet = info.categoryPallet;
+      }
+      if (typeof info.categoryQms == 'string') {
+        this.categoryQms = {};
+      } else {
+        this.categoryQms = info.categoryQms;
+      }
+      if (typeof info.categoryVehicle == 'string') {
+        this.categoryVehicle = {};
+      } else {
+        this.categoryVehicle = info.categoryVehicle;
+      }
+      if (typeof info.categoryWms == 'string') {
+        this.categoryWms = {};
+      } else {
+        this.categoryWms = info.categoryWms;
+      }
+    },
+    // 选择所属部门
+    searchDeptNodeClick(id, info) {
+      // 根据部门获取人员
+      const params = { executeGroupId: id };
+      this.$nextTick(() => {
+        this.$refs.directorRef.getList(params);
+      });
+    },
+    //选择负责人
+    handleDirectorChange(id, info) { },
+    // 确定分类
+    async confirmCategory(node, title, PathInfo, ruleCode) {
+      this.form.code = null
+      console.log(ruleCode)
+      if (title == '选择产品分类') {
+        this.$set(this.form, 'productCategoryLevelName', node.name);
+        this.$set(this.form, 'productCategoryLevelId', node.id);
+      } else {
+        this.$set(this.form, 'categoryLevelName', node.name);
+        this.$set(this.form, 'categoryLevelId', node.id);
+        this.$set(this.form, 'categoryLevelPath', node.name);
+        this.$set(this.form, 'categoryLevelPathId', node.id);
+        this.PathInfo = PathInfo;
+
+        this.ruleCode = ruleCode
+
+        if(ruleCode &&  ruleCode != '自定义') {
+          const code = await getCode(ruleCode);
+          this.$set(this.form, 'code', code);
+          this.$forceUpdate()
+      
+        }
+
 
-      // 保存
-      submit () {
-        this.$refs.manageForm.validate((valid) => {
-          if (!valid) {
-            return false;
-          }
-          this.loading = true;
-          // const imgList = this.remarkform.imgList;
-          // const arr = [];
-          // if (imgList.length) {
-          //   imgList.map((item) => {
-          //     arr.push(item.storePath);
-          //   });
-          //   this.form.remarkAttach = arr.join(',');
-          // }
-          // this.form.remark = this.remarkform.remark
-          //   ? this.remarkform.remark
-          //   : '';
-          const data = {
-            categoryWms: this.categoryWms,
-            categoryAps: this.categoryAps,
-            categoryMes: this.categoryMes,
-            categoryMold: this.categoryMold,
-            categoryPallet: this.categoryPallet,
-            categoryQms: this.categoryQms,
-            categoryVehicle: this.categoryVehicle,
-            category: {
-              ...this.form,
-              ...this.remarkform,
-              ...this.PathInfo
-            }
-          };
-          addMaterial(data)
-            .then((msg) => {
-              this.loading = false;
-              this.$message.success(msg);
-              finishPageTab();
-              reloadPageTab({ fullPath: '/material/product' });
-              this.$router.go(-1);
-            })
-            .catch((e) => {
-              this.loading = false;
-            });
-        });
       }
+    },
+    openCategory() {
+      this.$refs.categoryRefs.open();
+    },
+
+    openCode() {
+      this.$refs.codeRefs.open()
+    },
+
+    chooseCode(code) {
+      this.$set(this.form, 'code', code);
+      this.$forceUpdate()
+    },
+
+    cancel() {
+      finishPageTab();
+      this.$router.go(-1);
+    },
+
+    // 保存
+    submit() {
+      this.$refs.manageForm.validate((valid) => {
+        if (!valid) {
+          return false;
+        }
+        this.loading = true;
+        // const imgList = this.remarkform.imgList;
+        // const arr = [];
+        // if (imgList.length) {
+        //   imgList.map((item) => {
+        //     arr.push(item.storePath);
+        //   });
+        //   this.form.remarkAttach = arr.join(',');
+        // }
+        // this.form.remark = this.remarkform.remark
+        //   ? this.remarkform.remark
+        //   : '';
+        const data = {
+          categoryWms: this.categoryWms,
+          categoryAps: this.categoryAps,
+          categoryMes: this.categoryMes,
+          categoryMold: this.categoryMold,
+          categoryPallet: this.categoryPallet,
+          categoryQms: this.categoryQms,
+          categoryVehicle: this.categoryVehicle,
+          category: {
+            ...this.form,
+            ...this.remarkform,
+            ...this.PathInfo
+          }
+        };
+        addMaterial(data)
+          .then((msg) => {
+            this.loading = false;
+            this.$message.success(msg);
+            finishPageTab();
+            reloadPageTab({ fullPath: '/material/product' });
+            this.$router.go(-1);
+          })
+          .catch((e) => {
+            this.loading = false;
+          });
+      });
     }
-  };
+  }
+};
 </script>
 
 <style lang="scss" scoped>
-  .ele-page-header {
-    border: none;
-  }
-  .body-top {
+.ele-page-header {
+  border: none;
+}
+
+.body-top {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  background: #fff;
+
+  .top-left {
     display: flex;
     align-items: center;
-    justify-content: space-between;
-    background: #fff;
-    .top-left {
-      display: flex;
-      align-items: center;
-      justify-content: flex-start;
-      margin-left: -25px;
-      .el-form-item {
-        margin-bottom: 0;
-      }
-    }
-  }
-  .divider {
-    margin: 20px 0;
-    .title {
-      display: flex;
-      align-items: center;
-      margin-bottom: 10px;
-      div {
-        width: 8px;
-        height: 20px;
-        margin-right: 10px;
-      }
-      span {
-        font-size: 20px;
-      }
-    }
-    .ele-width {
-      width: 100%;
-      height: 2px;
+    justify-content: flex-start;
+    margin-left: -25px;
+
+    .el-form-item {
+      margin-bottom: 0;
     }
   }
-  .form-line {
+}
+
+.divider {
+  margin: 20px 0;
+
+  .title {
     display: flex;
     align-items: center;
-    justify-content: space-between;
-    .line-select {
-      margin-left: 15px;
+    margin-bottom: 10px;
+
+    div {
+      width: 8px;
+      height: 20px;
+      margin-right: 10px;
+    }
+
+    span {
+      font-size: 20px;
     }
   }
+
+  .ele-width {
+    width: 100%;
+    height: 2px;
+  }
+}
+
+.form-line {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+
+  .line-select {
+    margin-left: 15px;
+  }
+}
 </style>

+ 0 - 1
src/views/material/product/index.vue

@@ -162,7 +162,6 @@ export default {
           this.$nextTick(() => {
             // 默认高亮第一级树节点
             if (this.treeList[0]) {
-              this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
               this.getDetail(this.treeList[0].id);
             }
           });