Bläddra i källkod

新增委外生产入库

huang_an 2 år sedan
förälder
incheckning
31ff9108cf

+ 381 - 78
src/views/bpm/handleTask/components/purchaseOrder/invoice/procurementStorage.vue

@@ -121,7 +121,10 @@
 
       <div class="material">
         <header-title title="产品信息">
-          <el-button type="primary" @click="addStock" v-if="!isTask"
+          <el-button
+            type="primary"
+            @click="addStock"
+            v-if="!isTask || isOutsourcing"
             >添加</el-button
           >
         </header-title>
@@ -429,10 +432,7 @@
                     @click="listEdit(row, $index)"
                     >编辑</el-button
                   >
-                  <el-button
-                    type="text"
-                    @click="listDel(row, $index)"
-                    v-if="!isTask"
+                  <el-button type="text" @click="listDel(row, $index)"
                     >删除</el-button
                   >
                 </template>
@@ -475,6 +475,7 @@
             >批量保存</el-button
           >
           <el-table
+            v-if="isWrapTable"
             ref="materialCodeReqListTable"
             :data="materialCodeReqList"
             tooltip-effect="dark"
@@ -644,11 +645,14 @@
                 width="200"
               ></el-table-column>
             </template>
-            <el-table-column label="操作" width="80" fixed="right">
-              <template slot-scope="{ row }">
+            <el-table-column label="操作" width="120" fixed="right">
+              <template slot-scope="{ row, $index }">
                 <el-button type="text" @click="packCout(row)">
                   {{ !row.isPack ? '保存' : '编辑' }}
                 </el-button>
+                <el-button type="text" @click="wrapDelete(row, $index)">
+                  删除
+                </el-button>
               </template>
             </el-table-column>
           </el-table>
@@ -667,6 +671,7 @@
             >批量保存</el-button
           >
           <el-table
+            v-if="isMaterialTable"
             ref="resultArrayTable"
             :data="resultArray"
             tooltip-effect="dark"
@@ -768,11 +773,14 @@
                 <span>{{ qualityStatus[row.status] }}</span>
               </template>
             </el-table-column>
-            <el-table-column label="操作" width="80" fixed="right">
-              <template slot-scope="{ row }">
+            <el-table-column label="操作" width="120" fixed="right">
+              <template slot-scope="{ row, $index }">
                 <el-button type="text" @click="materialBtn(row)">
                   {{ !row.isPack ? '保存' : '编辑' }}
                 </el-button>
+                <el-button type="text" @click="materialDelete(row, $index)">
+                  删除
+                </el-button>
               </template>
             </el-table-column>
           </el-table>
@@ -816,6 +824,7 @@
 </template>
 
 <script>
+  import { getOutInBySourceBizNoOrError } from '@/api/classifyManage/index';
   import { getProductList } from '@/api/bpm/components/saleManage/contact';
   import { getLoginUser } from '@/api/login';
   import picker from '@/views/bpm/stockManagement/components/picker.vue';
@@ -832,6 +841,7 @@
   import { tableHeader } from '@/views/bpm/handleTask/components/inoutBound/common';
   import { getCode } from '@/api/codeManagement/index.js';
   import { getReceiveSaleOrderrecordDetail } from '@/api/bpm/components/purchasingManage/purchaseorderreceive';
+  import { deepClone } from 'ele-admin/lib/utils/core';
 
   export default {
     components: {
@@ -845,6 +855,9 @@
     },
     data() {
       return {
+        isWrapTable: true, // 包装表格显隐
+        isMaterialTable: true, // 物料表格显隐
+        isOutsourcing: false, // 是否委外
         isSplit: false, // 是否拆分到物料明细
         qualityStatus: {
           0: '未检',
@@ -1060,6 +1073,12 @@
         } else {
           row.isPack = false;
         }
+        this.$nextTick(() => {
+          this.isWrapTable = false;
+          this.$nextTick(() => {
+            this.isWrapTable = true;
+          });
+        });
       },
       // 批量修改包装明细
       bulkEditingWrap() {
@@ -1119,11 +1138,10 @@
       },
       // 物料明细保存
       materialBtn(row) {
-        console.log(row);
-        console.log(this.resultArray);
-        console.log(this.materialCodeReqList);
+        console.log(row.isPack);
         // true保存 false编辑
         if (!row.isPack) {
+          this.$set(row, 'isPack', true);
           row.isPack = true;
           // 物料维度修改质检改变包装维度质检(结果和状态)
           this.materialCodeReqList.forEach((outItem) => {
@@ -1213,6 +1231,14 @@
         } else {
           row.isPack = false;
         }
+        this.$nextTick(() => {
+          this.isWrapTable = false;
+          this.isMaterialTable = false;
+          this.$nextTick(() => {
+            this.isWrapTable = true;
+            this.isMaterialTable = true;
+          });
+        });
       },
       // 重量计算
       packNum(row, value) {
@@ -1244,11 +1270,13 @@
       },
       // 根据单据信息初始化产品信息(外部调用)
       async pickerSuccess(row) {
-        this.formData.bizType = '2';
-        this.codeListValue(row.categoryLevelTopId);
         this.isTask = true;
         this.pickerRow = row;
+        // this.codeListValue(row.categoryLevelTopId);
+        this.formData.bizType = '2';
         this.formData.extInfo.documentSource = row.orderNo;
+        this.formData.extInfo.assetType = row.categoryLevelTopId;
+        this.selectEquiType = row.categoryLevelTopId;
         this.formData.sourceBizNo = row.receiveNo;
         this.formData.fromId = row.id;
         this.formData.clientName = row.partaName;
@@ -1266,7 +1294,268 @@
               minPackUnit: item.packingUnit
             };
           });
-          this.onSelectTableData(await this.serachMainCode(list));
+          await this.onSelectTableData(await this.serachMainCode(list));
+        }
+        // 委外发货入库(出库再入库)
+        if (row.outsourceSendCode) {
+          this.isOutsourcing = true;
+          this.formData.bizType = '8';
+          this.title = '半成品入库';
+          getOutInBySourceBizNoOrError(row.outsourceSendCode).then(
+            async (res) => {
+              if (res.outInDetailVOList && res.outInDetailVOList.length > 0) {
+                const batchNo = await getCode('lot_number_code');
+                this.warehousingMaterialList = [];
+                let arr = res.outInDetailVOList.map(async (goodsiItem) => {
+                  return new Promise(async (outResolve) => {
+                    goodsiItem.isSave = true;
+                    goodsiItem.houseList = [];
+                    goodsiItem.batchNo = batchNo;
+                    goodsiItem.assetName = goodsiItem.name;
+                    goodsiItem.assetCode = goodsiItem.categoryCode;
+                    goodsiItem.outInNum =
+                      goodsiItem.packingCount < 1 ? 1 : goodsiItem.packingCount;
+                    goodsiItem.minPackingCount = goodsiItem.count;
+                    goodsiItem.minPackUnit = goodsiItem.packingUnit;
+                    this.warehousingMaterialList.push(goodsiItem);
+                    let arr = goodsiItem.outInDetailRecordVOList.map(
+                      (wrapItem, index) => {
+                        return new Promise(async (resolve) => {
+                          let res = await outin.getAssetNum({
+                            assetCode: goodsiItem.assetCode,
+                            batchNum: goodsiItem.batchNo,
+                            num:
+                              goodsiItem.outInNum < 1 ? 1 : goodsiItem.outInNum
+                          });
+                          wrapItem.onlyCode = res.shift().onlyCode;
+                          wrapItem.packingCount =
+                            wrapItem.packingCount < 1
+                              ? 1
+                              : wrapItem.packingCount;
+                          wrapItem.isPack = true;
+                          wrapItem.minPackingCount = wrapItem.totalCount;
+                          wrapItem.assetName = goodsiItem.name;
+                          wrapItem.assetCode = goodsiItem.categoryCode;
+                          wrapItem.batchNo = batchNo;
+                          wrapItem.result =
+                            wrapItem.result === null
+                              ? ''
+                              : String(wrapItem.result);
+                          // wrapItem.count =
+                          //   wrapItem.outInDetailRecordMaterialDetailVOList.length; // 增加包装计量数量
+                          // 增加内部重量(解决重量未保存同时参与计算问题)
+                          wrapItem.initWeight = wrapItem.weight;
+                          if (
+                            wrapItem.outInDetailRecordMaterialDetailVOList
+                              ?.length > 0
+                          ) {
+                            wrapItem.outInDetailRecordMaterialDetailVOList.forEach(
+                              (materialItem, index) => {
+                                materialItem.id = '';
+                                materialItem.onlyCode = wrapItem.onlyCode;
+                                materialItem.no =
+                                  materialItem.onlyCode +
+                                  index.toString().padStart(4, '0');
+                                materialItem.result =
+                                  materialItem.result === null
+                                    ? ''
+                                    : String(materialItem.result);
+                                materialItem.batchNo = batchNo;
+                                materialItem.minPackingCount = 1;
+                                materialItem.isPack = true;
+                                // 增加内部重量(解决重量未保存同时参与计算问题)
+                                materialItem.initWeight = materialItem.weight;
+                                this.resultArray.push(materialItem);
+                              }
+                            );
+                          }
+                          resolve(wrapItem);
+                        });
+                      }
+                    );
+                    Promise.all(arr).then((data) => {
+                      console.log(goodsiItem);
+                      goodsiItem.warehouseLedgerDetails = data;
+                      outResolve(goodsiItem);
+                      // console.log(this.resultArray);
+                      // goodsiItem.warehouseLedgerDetails =
+                      //   goodsiItem.outInDetailRecordVOList;
+                      // if (this.resultArray.length > 0) {
+                      //   this.isSplit = true;
+                      // }
+                    });
+                  });
+                });
+                Promise.all(arr).then((data) => {
+                  console.log(this.warehousingMaterialList);
+                  console.log(this.resultArray);
+                  this.warehousingMaterialList = data;
+                  if (this.resultArray.length > 0) {
+                    this.isSplit = true;
+                  }
+                });
+
+                // this.warehousingMaterialList.forEach((item, index) => {
+                //   item.manualBatchNo =
+                //     warehousingMaterialList[index].manualBatchNo;
+                //   item.minPackingCount = warehousingMaterialList[index].count;
+                //   item.outInNum = warehousingMaterialList[index].outInNum;
+                //   item.weight = warehousingMaterialList[index].weight;
+                // });
+                // this.listSaveArrs().then(() => {
+                //   this.materialCodeReqList.forEach((item, index) => {
+                //     item.materielCode = materialCodeReqList[index].materielCode;
+                //     item.clientCode = materialCodeReqList[index].clientCode;
+                //     item.engrave = materialCodeReqList[index].engrave;
+                //   });
+                //   if (resultArray.length > 0) {
+                //     this.handleIsDetail(true);
+                //     this.resultArray.forEach((item, index) => {
+                //       item.materielCode = resultArray[index].materielCode;
+                //       item.clientCode = resultArray[index].clientCode;
+                //       item.engrave = resultArray[index].engrave;
+                //     });
+                //   }
+                // });
+                // console.log(warehousingMaterialList);
+                // console.log(materialCodeReqListOrStorage);
+                // console.log(resultArray);
+              }
+            }
+          );
+        } else {
+          this.formData.bizType = '2';
+          this.title = '采购入库';
+        }
+      },
+      // 包装删除
+      wrapDelete(row, index) {
+        // 删除包装
+        this.materialCodeReqList.splice(index, 1);
+        let outIndex = 0;
+        let arr = this.warehousingMaterialList.filter((item, index) => {
+          if (item.assetCode == row.assetCode && item.batchNo == row.batchNo) {
+            outIndex = index;
+            return true;
+          }
+        });
+        // 修改产品
+        if (arr[0].minPackingCount * arr[0].outInNum === row.minPackingCount) {
+          this.warehousingMaterialList.splice(outIndex, 1);
+        } else {
+          this.$set(
+            this.warehousingMaterialList[outIndex],
+            'outInNum',
+            this.warehousingMaterialList[outIndex].outInNum - 1
+          );
+        }
+        // 删除物料
+        if (this.resultArray.length > 0) {
+          let indexs = [];
+          let arr = this.resultArray.filter((item, index) => {
+            if (
+              item.assetCode == row.assetCode &&
+              item.batchNo == row.batchNo
+            ) {
+              indexs.push(index);
+              return true;
+            }
+          });
+          console.log(indexs);
+          console.log(arr);
+          this.resultArray = this.resultArray.filter((item, index) => {
+            return !indexs.includes(index);
+          });
+        }
+      },
+      // 物料删除
+      materialDelete(row, index) {
+        let isBoolen = false;
+        // 删除物料
+        this.resultArray.splice(index, 1);
+        // 修改包装
+        let wrapOutIndex = 0;
+        let wrapArr = this.materialCodeReqList.filter((item, index) => {
+          if (item.assetCode == row.assetCode && item.batchNo == row.batchNo) {
+            wrapOutIndex = index;
+            return true;
+          }
+        });
+        if (wrapArr[0].minPackingCount === row.minPackingCount) {
+          isBoolen = true;
+          // 修改产品
+          let materialOutIndex = 0;
+          let materialArr = this.warehousingMaterialList.filter(
+            (item, index) => {
+              console.log(wrapOutIndex);
+              console.log(this.materialCodeReqList);
+              console.log(item.assetCode);
+              console.log(this.materialCodeReqList[wrapOutIndex]);
+              console.log(this.materialCodeReqList[wrapOutIndex].assetCode);
+              console.log('----------------');
+              if (
+                item.assetCode ==
+                  this.materialCodeReqList[wrapOutIndex].assetCode &&
+                item.batchNo == this.materialCodeReqList[wrapOutIndex].batchNo
+              ) {
+                materialOutIndex = index;
+                return true;
+              }
+            }
+          );
+          if (
+            materialArr[0].minPackingCount * materialArr[0].outInNum ===
+            this.materialCodeReqList[wrapOutIndex].minPackingCount
+          ) {
+            this.materialCodeReqList.splice(wrapOutIndex, 1);
+            this.warehousingMaterialList.splice(materialOutIndex, 1);
+          } else {
+            this.$set(
+              this.warehousingMaterialList[materialOutIndex],
+              'minPackingCount',
+              this.warehousingMaterialList[materialOutIndex].minPackingCount - 1
+            );
+          }
+        } else {
+          this.$set(
+            this.materialCodeReqList[wrapOutIndex],
+            'minPackingCount',
+            this.materialCodeReqList[wrapOutIndex].minPackingCount - 1
+          );
+        }
+        if (!isBoolen) {
+          // 修改产品
+          let materialOutIndex = 0;
+          let materialArr = this.warehousingMaterialList.filter(
+            (item, index) => {
+              console.log(wrapOutIndex);
+              console.log(this.materialCodeReqList);
+              console.log(item.assetCode);
+              console.log(this.materialCodeReqList[wrapOutIndex]);
+              console.log(this.materialCodeReqList[wrapOutIndex].assetCode);
+              console.log('----------------');
+              if (
+                item.assetCode ==
+                  this.materialCodeReqList[wrapOutIndex].assetCode &&
+                item.batchNo == this.materialCodeReqList[wrapOutIndex].batchNo
+              ) {
+                materialOutIndex = index;
+                return true;
+              }
+            }
+          );
+          if (
+            materialArr[0].minPackingCount * materialArr[0].outInNum ===
+            this.materialCodeReqList[wrapOutIndex].minPackingCount
+          ) {
+            this.warehousingMaterialList.splice(materialOutIndex, 1);
+          } else {
+            this.$set(
+              this.warehousingMaterialList[materialOutIndex],
+              'minPackingCount',
+              this.warehousingMaterialList[materialOutIndex].minPackingCount - 1
+            );
+          }
         }
       },
       async serachMainCode(arr) {
@@ -1419,70 +1708,73 @@
       },
       // 产品批量保存
       listSaveArrs() {
-        // 已经拆分(还原到未拆封编辑状态)
-        if (this.isSplit && this.resultArray.length > 0) {
-          this.handleIsDetail(false);
-        }
-        const rows = this.warehousingMaterialList;
-        const indexes = Array.from(
-          { length: this.warehousingMaterialList.length },
-          (_, index) => index
-        );
-        let showMessage = true;
-        rows.forEach((row, i) => {
-          const index = indexes[i];
-          const fileds = [
-            // `warehousingMaterialList.${index}.cargoSpaceCode`,
-            `warehousingMaterialList.${index}.batchNo`,
-            `warehousingMaterialList.${index}.houseList`
-          ];
-          if (this.formData.bizType == 1) {
-            // fileds.push(...[`warehousingMaterialList.${index}.customCode`]);
-          } else if (this.formData.bizType == 2) {
-            // fileds.push(...[`warehousingMaterialList.${index}.supplierCode`]);
-          }
-          if (this.formData.bizType != 5) {
-            fileds.push(
-              ...[
-                `warehousingMaterialList.${index}.outInNum`,
-                `warehousingMaterialList.${index}.minPackingCount`
-              ]
-            );
-          } else if (
-            this.warehousingMaterialList.some(
-              (i) => !i.selfWarehouseLedgerDetails?.length
-            )
-          ) {
-            this.$message.error('请选择资产编号!');
-            return;
+        return new Promise((allResolve) => {
+          // 已经拆分(还原到未拆封编辑状态)
+          if (this.isSplit && this.resultArray.length > 0) {
+            this.handleIsDetail(false);
           }
-          Promise.all(
-            fileds.map(
-              (item) =>
-                new Promise(async (resolve, rej) => {
-                  this.$refs.warehousingMaterialListRef.validateField(
-                    item,
-                    (err) => {
-                      if (err) {
-                        rej(err);
-                      } else {
-                        resolve();
+          const rows = this.warehousingMaterialList;
+          const indexes = Array.from(
+            { length: this.warehousingMaterialList.length },
+            (_, index) => index
+          );
+          let showMessage = true;
+          rows.forEach((row, i) => {
+            const index = indexes[i];
+            let fileds = [
+              // `warehousingMaterialList.${index}.cargoSpaceCode`,
+              `warehousingMaterialList.${index}.batchNo`,
+              `warehousingMaterialList.${index}.houseList`
+            ];
+            if (this.formData.bizType == 1) {
+              // fileds.push(...[`warehousingMaterialList.${index}.customCode`]);
+            } else if (this.formData.bizType == 2) {
+              // fileds.push(...[`warehousingMaterialList.${index}.supplierCode`]);
+            }
+            if (this.formData.bizType != 5) {
+              fileds.push(
+                ...[
+                  `warehousingMaterialList.${index}.outInNum`,
+                  `warehousingMaterialList.${index}.minPackingCount`
+                ]
+              );
+            } else if (
+              this.warehousingMaterialList.some(
+                (i) => !i.selfWarehouseLedgerDetails?.length
+              )
+            ) {
+              this.$message.error('请选择资产编号!');
+              return;
+            }
+            Promise.all(
+              fileds.map(
+                (item) =>
+                  new Promise(async (resolve, rej) => {
+                    this.$refs.warehousingMaterialListRef.validateField(
+                      item,
+                      (err) => {
+                        if (err) {
+                          rej(err);
+                        } else {
+                          resolve();
+                        }
                       }
-                    }
-                  );
-                })
+                    );
+                  })
+              )
             )
-          )
-            .then((res) => {
-              this.$set(row, 'isSave', true);
-              this.createMaterialCode(row);
-            })
-            .catch((err) => {
-              if (showMessage) {
-                showMessage = false;
-                this.$message.error('请填入必填项!');
-              }
-            });
+              .then(async (res) => {
+                this.$set(row, 'isSave', true);
+                await this.createMaterialCode(row);
+                allResolve();
+              })
+              .catch((err) => {
+                if (showMessage) {
+                  showMessage = false;
+                  this.$message.error('请填入必填项!');
+                }
+              });
+          });
         });
       },
       // 批量设置生产日期
@@ -1673,6 +1965,16 @@
       // 外部调用获取入库数据
       getReturnStorage() {
         return new Promise((resolve) => {
+          console.log(this.warehousingMaterialList);
+          if (this.isOutsourcing) {
+            let boolen = this.warehousingMaterialList.every(
+              (item) => item.houseList.length > 0
+            );
+            if (!boolen) {
+              this.$message.error('请选择产品仓库!');
+              return false;
+            }
+          }
           this.$refs.formName.validate(async (valid) => {
             if (valid) {
               if (!this.warehousingMaterialList?.length) {
@@ -1700,7 +2002,7 @@
                   manualBatchNo: item.manualBatchNo,
                   batchNo: item.batchNo,
                   categoryId:
-                    this.formData.bizType == 2
+                    this.formData.bizType == 2 || this.formData.bizType == 8
                       ? item.categoryId
                         ? item.categoryId
                         : item.id
@@ -1789,7 +2091,7 @@
           name: it.assetName,
           pathIds: item.pathIds,
           unit: it.unit,
-          packageNo: it.num,
+          packageNo: it.num > 0 ? it.num : '',
           clientCode: it.clientCode,
           materielCode: it.materielCode,
           weight: it.weight,
@@ -1873,6 +2175,7 @@
         this.$refs.formName.validateField('contentImage');
       },
       houseData(argum, idx) {
+        console.log(argum);
         this.$set(this.warehousingMaterialList[idx], 'houseList', argum);
       }
     },