ysy 2 years ago
parent
commit
b3f8f4feba

+ 11 - 0
src/api/materialPlan/index.js

@@ -117,3 +117,14 @@ export async function listBomByWorkOrderIds(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+
+// 根据工艺路线返回工序
+
+export async function getTaskListById(id) {
+  const res = await request.get(`/main/produceversion/getTaskListById/${id}`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 274 - 0
src/views/materialPlan/components/ProductModal2.vue

@@ -0,0 +1,274 @@
+<template>
+  <el-dialog :title="title" :visible.sync="visible" :before-close="handleClose" :close-on-click-modal="false"
+    :close-on-press-escape="false" append-to-body width="70%">
+
+    <el-card shadow="never">
+      <ProductSearch @search="reload" ref="searchRef" />
+
+      <ele-split-layout width="244px" allow-collapse :right-style="{ overflow: 'hidden' }">
+        <div class="ele-border-lighter split-layout-right-content">
+          <el-tree :data="treeList" :props="defaultProps" ref="treeRef"
+            :default-expanded-keys="categoryId ? [categoryId] : []" :highlight-current="true" node-key="id"
+            @node-click="handleNodeClick"></el-tree>
+        </div>
+
+
+        <!-- 数据表格 -->
+        <template v-slot:content>
+          <ele-pro-table style="min-height: 400px;" ref="table" :columns="columns" :datasource="datasource"
+            :selection.sync="selection" row-key="id">
+          </ele-pro-table>
+        </template>
+      </ele-split-layout>
+
+    </el-card>
+
+
+
+
+
+    <div class="rx-sc">
+
+      <el-button type="primary" size="small" @click="selected">选择</el-button>
+      <el-button size="small" @click="handleClose">关闭</el-button>
+
+    </div>
+  </el-dialog>
+</template>
+
+<script>
+
+
+import { getMaterialList, getTaskListById } from '@/api/materialPlan/index';
+import ProductSearch from './product-search.vue'
+import { getTreeByPid } from '@/api/classifyManage';
+export default {
+  components: {
+    ProductSearch
+  },
+  data() {
+    return {
+      visible: false,
+      title: '选择物料',
+
+      categoryLevelId: null,
+      categoryId: 1,
+      treeList: [],
+      treeLoading: false,
+
+      defaultProps: {
+        children: 'children',
+        label: 'name'
+      },
+      type: null,
+
+      // 表格列配置
+      columns: [
+        {
+          columnKey: 'selection',
+          type: 'selection',
+          width: 45,
+          align: 'center',
+          selectable: (row, index) => {
+            return !this.processData.some((it) => false);
+          },
+          reserveSelection: true,
+          fixed: 'left'
+        },
+
+        {
+          label: '物料名称',
+          prop: 'name',
+        },
+
+        {
+          label: '物料编码',
+          prop: 'code'
+        },
+        {
+          label: '牌号',
+          prop: 'brandNum'
+        },
+        {
+          label: '型号',
+          prop: 'modelType'
+        },
+
+        {
+          prop: 'availableCountBase',
+          label: '包装库存',
+          sortable: 'custom',
+        },
+        {
+          label: '单位',
+          prop: 'weightUnit'
+        },
+
+        {
+          prop: 'packingCountBase',
+          label: '计量库存',
+          sortable: 'custom',
+        },
+
+        {
+          label: '计量单位',
+          prop: 'unit'
+        },
+
+
+
+        {
+          label: '数量',
+          prop: 'count'
+        },
+
+
+
+
+
+      ],
+
+      // 表格选中数据
+      selection: [],
+
+      processData: [],
+      current: null,
+
+      form: {
+        produceRoutingId: null,
+        taskName: null,
+      },
+
+      produceList: []
+
+    }
+  },
+
+  watch: {
+
+  },
+  methods: {
+
+
+    /* 表格数据源 */
+    async datasource({ page, limit, where }) {
+      const res = await getMaterialList({
+        ...where,
+
+        pageNum: page,
+        size: limit,
+        categoryLevelId: 1,
+        dimension: 1
+      });
+      return res;
+    },
+
+    open(item, row, type) {
+      this.type = type
+      this.processData = item || []
+      this.current = row;
+      this.visible = true
+
+      this.getTreeData();
+      this.getTaskList()
+    },
+
+
+
+    async getTreeData() {
+      try {
+        this.treeLoading = true;
+
+        const res = await getTreeByPid(1);
+        this.treeLoading = false;
+        if (res?.code === '0') {
+          this.treeList = res.data;
+
+          this.$nextTick(() => {
+            // 默认高亮第一级树节点
+            if (this.treeList[0]) {
+              this.rootTreeId = this.treeList[0].id
+              this.$nextTick(() => {
+                this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
+              });
+
+            }
+          });
+          return this.treeList;
+        }
+      } catch (error) { }
+      this.treeLoading = false;
+    },
+
+    getTaskList() {
+
+      getTaskListById(this.current.produceRoutingId).then(res => {
+        this.produceList = res
+      })
+    },
+
+
+    handleNodeClick(data) {
+      this.categoryLevelId = data.id;
+      this.$refs.table.reload({ pageNum: 1, where: {} });
+
+
+
+    },
+
+
+    /* 刷新表格 */
+    reload(where) {
+      this.$refs.table.reload({ page: 1, where: where });
+    },
+
+
+
+    handleClose() {
+      this.visible = false
+      this.$refs.table.setSelectedRows([]);
+      this.selection = []
+
+    },
+    selected() {
+      let _arr = []
+      if (!this.selection.length) {
+        this.$message.error('请至少选择一条数据');
+        return;
+      }
+
+
+      if (this.type == 'add') {
+        _arr = this.selection.map(m => {
+          m.produceRoutingList = this.produceList
+          m.categoryId = m.id + '-' + new Date().getTime()
+          m.produceSelect = true
+          m.taskId = ''
+          delete m.id
+          return {
+            ...m
+          }
+        })
+      }
+
+
+
+      this.$emit('chooseModal', _arr, this.current)
+      this.handleClose()
+    },
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.rx-sc {
+
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+
+.ml60 {
+  margin-left: 60px;
+}
+</style>

+ 7 - 0
src/views/materialPlan/components/plan-edit-dialog.vue

@@ -447,6 +447,10 @@ export default {
         this.formData['id'] = res.id
         this.$refs.table.setData([...res.salesOrderList]);
 
+        this.$nextTick(() => {
+          this.$refs.table.toggleRowExpansionAll()
+        })
+
       })
     },
 
@@ -536,8 +540,11 @@ export default {
 
           this.$refs.table.setData([...this.tableData, ...res]);
 
+          this.$nextTick(() => {
           this.$refs.table.toggleRowExpansionAll()
         })
+
+        })
       }
     },
 

+ 122 - 70
src/views/materialPlan/components/produce-edit-dialog.vue

@@ -16,7 +16,7 @@
         </el-col>
 
 
-       
+
 
 
 
@@ -43,12 +43,7 @@
           <el-input placeholder="请输入" readonly :value="row.code || row.salesOrderCode"></el-input>
         </template>
 
-     
 
-        <template v-slot:productionPlanId="{ row }">
-          <el-link type="primary" v-if="!row.productionPlanId" :underline="false"
-            @click.native="openVersion(row)">获取物料</el-link>
-        </template>
 
 
 
@@ -70,11 +65,27 @@
 
         <!-- 展开内容 -->
         <template v-slot:expand="{ row }">
-          <div style="width:100%; min-height: 60px" v-if="row.materialList.length > 0">
+          <div style="width:calc(100% - 95px); min-height: 60px; margin-left: 95px;" v-if="row.materialList.length > 0">
             <ele-pro-table :toolbar="false" toolsTheme="none" ref="table2" :need-page="false"
               :datasource="row.materialList" :columns="columns2" row-key="id">
 
 
+              <template v-slot:sort="{ $index }">
+                {{ $index }}
+              </template>
+
+              <template v-slot:taskName="{ row }">
+                <div v-if="row.produceSelect">
+                  <el-select v-model="row.taskId" placeholder="请选择工序">
+                    <el-option v-for="item in row.produceRoutingList" :key="item.id" :label="item.name" :value="item.id"
+                      @click.native="row.taskName = item.name">
+                    </el-option>
+                  </el-select>
+                </div>
+                <div v-if="!row.produceSelect">
+                  {{ row.taskName }}
+                </div>
+              </template>
 
 
               <template v-slot:demandQuantity="{ row }">
@@ -87,6 +98,11 @@
               </template>
 
 
+
+
+
+
+
               <template v-slot:purchaseQuantity="{ row }">
                 <el-input v-model="row.purchaseQuantity" placeholder="请输入" @input="(value) =>
                 (row.purchaseQuantity = value.replace(
@@ -125,10 +141,8 @@
     <workOrderPop ref="workOrderRef" @chooseOrder="chooseOrder"></workOrderPop>
 
 
-
     <ProductModal ref="productRefs" @chooseModal="chooseModal" />
 
-    <ProductionVersion ref="versionRefs" @changeProduct="changeProduct"></ProductionVersion>
 
   </ele-modal>
 </template>
@@ -136,14 +150,13 @@
 <script>
 
 import workOrderPop from './workOrderPop.vue'
-import ProductModal from './ProductModal.vue'
-import {listBomByWorkOrderIds, save, getById } from '@/api/materialPlan/index';
-import ProductionVersion from '@/components/CreatePlan/ProductionVersion2.vue';
+import ProductModal from './ProductModal2.vue'
+import { listBomByWorkOrderIds, save, getById } from '@/api/materialPlan/index';
+
 export default {
   components: {
     workOrderPop,
     ProductModal,
-    ProductionVersion
 
 
   },
@@ -168,6 +181,14 @@ export default {
           slot: 'expand'
         },
 
+        {
+          width: 50,
+          label: '序号',
+          type: 'index',
+          align: 'center',
+          slot: 'index'
+        },
+
         {
           prop: 'code',
           label: '生产订单号',
@@ -238,13 +259,11 @@ export default {
           label: '欠交数量',
           align: 'center'
         },
-   
+
 
         {
-          prop: 'productionPlanId',
+          prop: 'produceRoutingName',
           label: '工序',
-          slot: 'productionPlanId',
-
           align: 'center',
           minWidth: 110
         },
@@ -264,6 +283,22 @@ export default {
 
       columns2: [
 
+        {
+          width: 50,
+          label: '序号',
+          prop: 'sort',
+          slot: 'sort',
+          align: 'center',
+        },
+
+        {
+          label: '工序',
+          slot: 'taskName',
+          prop: 'taskName',
+          width: 150,
+        },
+
+
         {
           label: '物料名称',
           prop: 'name',
@@ -364,10 +399,21 @@ export default {
         this.$set(this.formData, 'remark', res.remark)
         this.formData['id'] = res.id
         this.$refs.table.setData([...res.salesOrderList]);
+        this.$nextTick(() => {
+          this.$refs.table.toggleRowExpansionAll()
+        })
 
       })
     },
 
+    isEverySubArrayRequiredFieldPresent(nestedArray, requiredFields) {
+      return nestedArray.every(subArray =>
+        requiredFields.every(field =>
+          subArray.materialList.some(item => item[field] !== '')
+        )
+      );
+    },
+
     confirm() {
       this.$refs.formRef.validate(async (value) => {
         if (value) {
@@ -378,24 +424,55 @@ export default {
             this.$message.info('请添加生产订单');
             return false
           }
+
+
+
+
+
+
+          const requiredFields = ['taskId']; // 必填字段
+
+          const result = await this.isEverySubArrayRequiredFieldPresent(_arr, requiredFields);
+
+
+
+          if (!result) {
+            this.$message.info('请选择工序!');
+            return false
+          }
+
           let _arr2 = []
 
+
           _arr2 = _arr.map(m => {
-            if (Object.prototype.hasOwnProperty.call(m, "salesOrderId") && m.salesOrderId) {
+            if (Object.prototype.hasOwnProperty.call(m, "workOrderId") && m.workOrderId) {
             } else {
-              m.salesOrderId = m.id
-              m.salesOrderCode = m.code
+
+              m.workOrderId = m.id
+              m.workOrderCode = m.code
               delete m.id
               delete m.code
+
+
             }
 
+            m.materialList.forEach(f => {
+              if (f.categoryId.includes('-')) {
+                f.categoryId = f.categoryId.split('-')[0]
+              }
+
+            })
+
             return {
               ...m,
             }
           })
 
-          this.formData['type'] = 1
-          this.formData['salesOrderList'] = _arr2
+          console.log(_arr2)
+
+
+          this.formData['type'] = 2
+          this.formData['workOrderList'] = _arr2
           await save(this.formData);
           this.$message.success('保存成功!');
           this.$emit('success');
@@ -427,22 +504,33 @@ export default {
     },
 
     chooseOrder(list) {
-      let workOrderList = []
+      let workOrderIds = []
       list.map((m => {
-        workOrderList.push(m.id)
+        workOrderIds.push(m.id)
         return {
           ...m,
         }
       }))
-      // this.$refs.table.setData([...this.tableData, ...list]);
-    
 
 
-      if (workOrderList.length > 0) {
-        listBomByWorkOrderIds({ workOrderList: workOrderList }).then((res) => {
+
+      if (workOrderIds.length > 0) {
+        listBomByWorkOrderIds({ workOrderIds: workOrderIds }).then((res) => {
+          res.forEach(m => {
+            if (m.materialList.length > 0) {
+              m.materialList.forEach(p => {
+                p.detailId = m.id
+              })
+            }
+          })
+
+
           this.$refs.table.setData([...this.tableData, ...res]);
 
-          this.$refs.table.toggleRowExpansionAll()
+
+          this.$nextTick(() => {
+            this.$refs.table.toggleRowExpansionAll()
+          })
         })
       }
     },
@@ -455,7 +543,7 @@ export default {
     },
 
     categorySelect(row) {
-      this.$refs.productRefs.open(row.materialList, row)
+      this.$refs.productRefs.open(row.materialList, row, this.type)
     },
 
     chooseModal(data, current) {
@@ -494,7 +582,7 @@ export default {
       this.formData.materialRemoveIds.push(row.id)
       data.forEach((e) => {
         if (row.detailId == e.id) {
-          e.materialList = e.materialList.filter((d) => d.id !== row.id);
+          e.materialList = e.materialList.filter((d) => d.categoryId !== row.categoryId);
         }
       })
 
@@ -508,44 +596,6 @@ export default {
 
 
 
-    openVersion(row) {
-      this.xsId = row.id
-      this.$refs.versionRefs.open();
-    },
-    changeProduct(data) {
-      let param = {
-        salesOrderIds: [this.xsId],
-        produceRoutingId: data.id
-      }
-
-      listBomBySalesOrderId(param).then((res) => {
-
-
-        let tableList = []
-        tableList = this.$refs.table.getData()
-
-        tableList.forEach(e => {
-          if (e.id == this.xsId) {
-
-            res.map(m => {
-              m.detailId = this.xsId
-              return {
-                ...m,
-              }
-            })
-
-            e.materialList = res
-
-            this.$nextTick(() => {
-              this.$refs.table.setData([...tableList]);
-              this.$refs.table.toggleRowExpansionAll()
-            })
-          }
-        })
-
-      })
-
-    },
   }
 };
 </script>
@@ -553,6 +603,8 @@ export default {
 <style lang="scss" scoped>
 :deep(.el-table__expanded-cell) {
 
-  padding-bottom: 120px !important;
+  padding-bottom: 30px !important;
+  border-bottom: 12px solid #CCFFCC !important;
 }
 </style>
+