Browse Source

物料管理提交

LAPTOP-16IUEB3P\Lenovo 2 năm trước cách đây
mục cha
commit
37d042bef6

+ 27 - 4
src/api/material/manage.js

@@ -11,7 +11,7 @@ export async function getTreeByPid (pid) {
 }
 
 
-// 新增物料 
+// 新增物料
 export async function addMaterial (data) {
   const res = await request.post(`/main/category/add`,data);
   if (res.data.code == 0) {
@@ -20,11 +20,34 @@ export async function addMaterial (data) {
   return Promise.reject(new Error(res.data.message));
 }
 
-// 获取列表  
+// 编辑物料
+export async function editMaterial (data) {
+  const res = await request.post(`/main/category/edit`,data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// 获取列表
 export async function getMaterialList (data) {
-  const res = await request.post(`/main/category/getList`,data);
+  const res = await request.get(`/main/category/getList`,{
+    params: data
+  });
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
-}
+}
+
+// 获取详情
+export async function getDetailInfo (id) {
+  const res = await request.get(`/main/category/info/${id}`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+
+// /main/category/remove/{id}

+ 41 - 2
src/views/material/manage/components/CategoryDialog.vue

@@ -35,7 +35,8 @@ export default {
       treeVisible: false,
       treeData: [],
       current:null,
-      title:'选择分类'
+      title:'选择分类',
+      pathList:[]
     }
   },
 
@@ -46,6 +47,11 @@ export default {
     open(pid,title){
       this.treeVisible = true
       this.title = title
+      // if(title=='选择产品分类'){
+      //   if(this.remarkform.productCategoryLevelId) this.$refs.tree.setCurrentKey(this.remarkform.productCategoryLevelId)
+      // }else{
+      //   if(this.remarkform.categoryLevelId) this.$refs.tree.setCurrentKey(this.remarkform.categoryLevelId)
+      // }
       this.getTree(pid)
     },
     handleClose () {
@@ -64,10 +70,43 @@ export default {
        if(!this.current){
          return this.$message.warning(`请${this.title}`)
        }
-       this.$emit('chooseCategory',this.current,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()
     },
 
+    // parents:用于返回的数组,childNode:要查询的节点,treeData:json树形数据
+    findParent (parents, childNode, treeData) {
+      for (let i = 0; i < treeData.length; i++) {
+        // 父节点查询条件
+        if (treeData[i].id === childNode.parentId) {
+          // 如果找到结果,保存当前节点
+          parents.push(treeData[i])
+          // 用当前节点再去原数据查找当前节点的父节点
+          this.findParent(parents, treeData[i],this.treeData)
+          break
+        } else {
+          if (treeData[i].children instanceof Array) {
+            //	没找到,遍历该节点的子节点
+            this.findParent(parents, childNode, treeData[i].children)
+          }
+        }
+      }
+      return parents
+    }
+
   }
 }
 </script>

+ 37 - 34
src/views/material/manage/components/index-data.vue

@@ -20,21 +20,25 @@
             type="primary"
             icon="el-icon-plus"
             class="ele-btn-icon"
-            @click="openEdit()"
+            @click="openEdit({},2)"
           >
             添加
           </el-button>
       </template>
-      <!-- 操作列 -->
-      <template v-slot:appType="{ row }">
-        {{ types[row.appType] }}
-      </template>
       <template v-slot:action="{ row }">
+        <el-link
+          type="primary"
+          :underline="false"
+          icon="el-icon-copy-document"
+          @click="openEdit(row,1)"
+        >
+          复制
+        </el-link>
         <el-link
           type="primary"
           :underline="false"
           icon="el-icon-edit"
-          @click="openEdit(row)"
+          @click="openEdit(row,0)"
         >
           修改
         </el-link>
@@ -60,6 +64,11 @@
   import { getMaterialList } from '@/api/material/manage.js';
   export default {
     components: { },
+    props: {
+      // 物料组id
+      currentId: [Number, String],
+      data:Object
+    },
     data() {
       return {
         // 表格列配置
@@ -85,45 +94,43 @@
             showOverflowTooltip: true
           },
           {
-            prop: 'group',
+            prop: 'categoryLevelGroupName',
             label: '物料组',
             showOverflowTooltip: true,
             minWidth: 110
           },
           {
-            prop: 'brand',
+            prop: 'brandNum',
             align: 'center',
             label: '牌号',
-            showOverflowTooltip: true,
-            slot: 'appType'
+            showOverflowTooltip: true
           },
           {
-            prop: 'model',
+            prop: 'modelType',
             label: '型号',
             align: 'center',
             showOverflowTooltip: true
           },
           {
-            prop: 'specifications',
+            prop: 'specification',
             label: '规格',
             align: 'center',
             showOverflowTooltip: true
           },
           {
-            prop: 'measurement',
+            prop: 'measuringUnit',
             label: '计量单位',
             showOverflowTooltip: true,
             minWidth: 110
           },
           {
-            prop: 'unit',
+            prop: 'packingUnit',
             align: 'center',
             label: '包装单位',
-            showOverflowTooltip: true,
-            slot: 'appType'
+            showOverflowTooltip: true
           },
           {
-            prop: 'category',
+            prop: 'categoryLevelPath',
             label: '分类',
             align: 'center',
             showOverflowTooltip: true
@@ -131,11 +138,12 @@
           {
             columnKey: 'action',
             label: '操作',
-            width: 130,
+            width: 200,
             align: 'center',
             resizable: false,
             slot: 'action',
-            showOverflowTooltip: true
+            showOverflowTooltip: true,
+            fixed:'right'
           }
         ],
         types: {
@@ -144,35 +152,30 @@
         },
         // 表格选中数据
         selection: [],
-        // 当前编辑数据
-        current: null,
         // 是否显示编辑弹窗
         showEdit: false,
-        id: ''
+        id: null
       };
     },
 
     methods: {
       /* 表格数据源 */
       datasource({ page, limit, where, order }) {
-        return getMaterialList({ pageNum: page, size: limit, ...where });
+        return getMaterialList({ pageNum: page, size: limit, ...where , categoryLevelGroupId:this.currentId });
       },
       /* 刷新表格 */
       reload(where) {
-        this.$refs.table.reload({ page: 1, where: where });
+        this.$refs.table.reload({ page: 1, where: where ,  categoryLevelGroupId:this.currentId  });
       },
       /* 显示编辑 */
-      openEdit(row) {
-        if(row){
-          this.id = row.id;
-          this.current = row;
-        }
+      openEdit(row,status) {
         this.$router.push({
           path: '/material/manage/manageMaterial',
-          // query: {
-          //   pageTitle: '编辑物品',
-          //   id: row.id
-          // }
+          query: {
+            chooseTab: JSON.stringify(this.data),
+            id: row.id?row.id:null,
+            status:status
+          }
         });
       },
       /* 删除 */
@@ -191,7 +194,7 @@
       }
     },
     watch: {
-      // 监听字典id变化
+      // 监听物料组id变化
       currentId() {
         this.reload();
       }

+ 3 - 2
src/views/material/manage/index.vue

@@ -38,7 +38,7 @@
 
         <template v-slot:content>
           <!-- 物料列表 -->
-          <IndexData ref="listData" v-if="current" :current-id="current.id" />
+          <IndexData ref="listData" v-if="current" :current-id="current.id" :data="current"/>
         </template>
       </ele-split-layout>
     </el-card>
@@ -94,7 +94,8 @@
       reload(where) {
         this.$refs.table.reload();
         this.$refs.listData.reload(where);
-      }
+      },
+
     }
   };
 </script>

+ 57 - 13
src/views/material/manage/manageMaterial.vue

@@ -5,7 +5,7 @@
          <div class="body-top">
             <div class="top-left">
                <div class="ele-page-header ele-cell">
-                 <div class="ele-page-title">管理物料</div>
+                 <div class="ele-page-title">{{titileStatus==0?'修改':titileStatus==1?'复制':'添加'}}物料</div>
                </div>
                <el-row :gutter="24">
                  <el-col :span="24">
@@ -30,7 +30,7 @@
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="编码" prop="code">
-                <el-input  v-model="form.code"/>
+                <el-input  v-model="form.code" :disabled="titileStatus==0?true:false"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
@@ -171,7 +171,9 @@
   import RemarkInfo from './components/RemarkInfo.vue';
   import deptSelect from '@/components/CommomSelect/dept-select.vue';
   import personSelect from '@/components/CommomSelect/person-select.vue';
-  import { addMaterial } from '@/api/material/manage.js';
+  import { addMaterial , editMaterial , getDetailInfo } from '@/api/material/manage.js';
+  import { finishPageTab } from '@/utils/page-tab-util';
+  import { deepClone } from '@/utils/index'
   export default {
     name: 'ManageMaterial',
     components: {
@@ -179,32 +181,69 @@
       PlanInfo , SalesInfo , QualityInfo , BoatInfo , TurnoverInfo , MoldInfo , RemarkInfo , CategoryDialog
     },
     data() {
+      const defaultForm = {
+        categoryLevelGroupName:'',
+        categoryLevelName:'',
+      };
       return {
          loading:false,
-         form:{
-           categoryLevelGroupName:'',
-           categoryLevelName:'',
+         form:{...defaultForm},
+         remarkform:{
+           remarkAttach:[]
          },
-         remarkform:{},
          chooseItem:null,
+         PathInfo:{},
+         titileStatus:1
       };
     },
     computed:{
       rules(){
          const rules ={
-        	  categoryLevelGroupName:[{ required: true, message: '请选择所属物料组', trigger: 'change' }],
+        	 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' }],
+           packingUnit:[{ required: true, message: '请选择包装单位', trigger: 'change' }],
            isProduct:[{ required: true, message: '请选择是否产品', trigger: 'change' }],
          }
          return rules
       }
     },
 
+    created() {
+        this.chooseItem = JSON.parse(this.$route.query.chooseTab)
+        this.$set(this.form,'categoryLevelGroupName',this.chooseItem.name)
+        this.$set(this.form,'categoryLevelGroupId',this.chooseItem.id)
+        this.titileStatus = this.$route.query.status
+        this.$nextTick(() => {
+          this.$refs.directorRef.getList();
+        });
+       if(this.$route.query.id){
+          this.getDetail(this.$route.query.id)
+       }
+    },
 
     methods: {
+      // 获取详情
+      getDetail(id){
+        getDetailInfo(id).then(res=>{
+           const info = deepClone(res)
+           this.form = {
+             ...info,
+             ...JSON.parse(this.$route.query.chooseTab)
+           }
+           delete this.form.remarkAttach
+           delete this.form.remark
+           // this.$set(this.remarkform,'remarkAttach',info.remarkAttach)
+           this.$set(this.remarkform,'remark',info.remark)
+           this.$set(this.form,'categoryLevelGroupName',this.chooseItem.name)
+           if(this.titileStatus == 1){
+              delete this.form.code
+              delete this.form.id
+           }
+        })
+      },
       // 选择所属部门
       searchDeptNodeClick (id, info) {
         // 根据部门获取人员
@@ -236,19 +275,21 @@
         this.$set(this.form,'categoryLevelGroupId',row.id)
       },
       cancel(){
+        finishPageTab()
         this.$router.go(-1)
       },
 
       // 确定分类
-      confirmCategory(node,title){
+      confirmCategory(node,title,PathInfo){
          if(title=='选择产品分类'){
             this.$set(this.form,'productCategoryLevelName',node.name)
             this.$set(this.form,'productCategoryLevelId',node.id)
+            this.remarkform.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.remarkform.categoryLevelId = node.id
+            this.PathInfo = PathInfo
          }
       },
 
@@ -267,12 +308,15 @@
           this.loading = true;
           const data = {
             ...this.form,
-            ...this.remarkform
+            ...this.remarkform,
+            ...this.PathInfo
           };
-          addMaterial(data)
+          const saveOrUpdate = this.form.id ? editMaterial : addMaterial;
+          saveOrUpdate(data)
             .then((msg) => {
               this.loading = false;
               this.$message.success(msg);
+              finishPageTab()
               this.$router.go(-1)
             })
             .catch((e) => {