Browse Source

feat: 销售退货入库修改

liujt 1 month ago
parent
commit
c4aa90411f
1 changed files with 92 additions and 54 deletions
  1. 92 54
      src/views/bpm/stockManagement/storage.vue

+ 92 - 54
src/views/bpm/stockManagement/storage.vue

@@ -1851,6 +1851,22 @@
             this.$message.warning('未获取到物品类型!');
           }
 
+          const mergedList = [];
+          this.detailList.forEach((item) => {
+            const key = `${item.productCode}_${item.batchNo}_${item.colorKey}_${item.warehouseId}_${item.modelType}`;
+            const existIndex = mergedList.findIndex(
+              (m) => `${m.productCode}_${m.batchNo}_${m.colorKey}_${m.warehouseId}_${m.modelType}` === key
+            );
+            if (existIndex > -1) {
+              mergedList[existIndex].quantity += item.quantity;
+              mergedList[existIndex].packingWeight += item.packingWeight;
+              mergedList[existIndex].packingQuantity += item.packingQuantity;
+
+            } else {
+              mergedList.push({ ...item });
+            }
+          });
+
           // 包装列表 this.detailList
           // 获取主数据物品详情
           // let { category } = await getDetails(this.form.categoryId);
@@ -1859,8 +1875,7 @@
           });
           storageApi
             .getListByNameOrModeType({
-              codeList,
-              queryConditions: this.detailList
+              codeList
             })
             .then(async (res) => {
               console.log(res, 'detailList-res');
@@ -1878,11 +1893,20 @@
                 await storageApi.getCategoryPackageDisposition({
                   categoryIds: res.map((item) => item.id)
                 });
-              this.packingSpecificationOption = res.map((item) => {
-                return packingSpecification
-                  .filter((ite) => item.id == ite.categoryId)
-                  .sort((a, b) => a.sort - b.sort);
+              let packingSpecificationOption = res.map((item) => {
+                return {
+                  id: item.id,
+                  packingSpecification: packingSpecification
+                    .filter((ite) => item.id == ite.categoryId)
+                    .sort((a, b) => a.sort - b.sort)
+                }
               });
+              console.log(packingSpecificationOption,'packingSpecificationOption')
+              // this.packingSpecificationOption = res.map((item) => {
+              //   return packingSpecification
+              //     .filter((ite) => item.id == ite.categoryId)
+              //     .sort((a, b) => a.sort - b.sort);
+              // });
               // 获取相同仓库
               let warehouseIds = [];
               let warehouseNames = [];
@@ -1907,22 +1931,41 @@
                 );
               }
 
-              const newSpecificationOption = this.getNewSpecificationOption(
-                this.packingSpecificationOption
-              );
+              // const newSpecificationOption = this.getNewSpecificationOption(
+              //   this.packingSpecificationOption
+              // );
 
               // 生成产品列表
-              this.productList = res.map((item, index) => {
+              this.productList = mergedList.map((filtersItem, index) => {
+                let item = res.find(
+                  (detailItem) =>
+                    detailItem.code == filtersItem.productCode ||
+                    detailItem.code == filtersItem.categoryCode
+                );
+
                 // 显示规格
-                let packingSpecificationLabel = this.packingSpecificationOption[
-                  index
-                ]
-                  .map((item) => {
-                    if (item.sort > 0) {
-                      return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`;
-                    }
-                  })
-                  .filter((item) => !!item);
+                // let packingSpecificationLabel = this.packingSpecificationOption[
+                //   index
+                // ]
+                //   .map((item) => {
+                //     if (item.sort > 0) {
+                //       return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`;
+                //     }
+                //   })
+                //   .filter((item) => !!item);
+                const packingSpecificationItem = packingSpecificationOption.find(packingSpecificationItem=>packingSpecificationItem.id==filtersItem.productId)?.packingSpecification
+
+                // 显示规格
+                let packingSpecificationLabel = packingSpecificationItem
+                .map((item) => {
+                  if (item.sort > 0) {
+                    return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`;
+                  }
+                })
+                .filter((item) => !!item);
+
+                const newSpecificationOption = packingSpecificationItem;
+
                 // 换算重量
                 let weight = 0;
                 if (
@@ -1931,7 +1974,7 @@
                 ) {
                   weight = this.form.totalWeight;
                 } else {
-                  switch (item.weightUnit.toUpperCase()) {
+                  switch (filtersItem.weightUnit.toUpperCase()) {
                     case 'KG':
                       if (this.form.totalWeight > -1) {
                         weight = this.$math.format(
@@ -1994,8 +2037,8 @@
                       break;
                   }
                 }
-                let packingUnit = item.packingUnit;
-                let singleWeight = item.singleWeight || 0; // 单重重量
+                let packingUnit = filtersItem.packingUnit;
+                let singleWeight = filtersItem.singleWeight || 0; // 单重重量
 
                 return {
                   index: this.productList.length + index,
@@ -2011,72 +2054,67 @@
                       ? this.form.colorKey
                         ? this.form.colorKey
                         : ''
-                      : item.colorKey
-                      ? item.colorKey
+                      : filtersItem.colorKey
+                      ? filtersItem.colorKey
                       : '', // 颜色
                   modelKey:
                     this.bizType == 1
                       ? this.form.modelKey
                         ? this.form.modelKey
                         : ''
-                      : item.modelKey
-                      ? item.modelKey
+                      : filtersItem.modelKey
+                      ? filtersItem.modelKey
                       : '', // 机型
                   batchNo: [1, 3, 6].includes(this.bizType)
                     ? this.detailList[0]?.batchNo || batchNo
                     : batchNo, // 批次号
                   supplierListOptions: supplierList[item.id], // 供应商列表
                   supplierId:
-                    this.detailList.find((val) => val.categoryCode == item.code)
-                      ?.supplierId || item.supplierId, // 供应商id
+                    filtersItem?.supplierId || item.supplierId, // 供应商id
                   supplierCode:
-                    this.detailList.find((val) => val.categoryCode == item.code)
-                      ?.supplierCode || item.supplierCode,
+                    filtersItem?.supplierCode || item.supplierCode,
                   supplierName:
-                    this.detailList.find((val) => val.categoryCode == item.code)
-                      ?.supplierName || item.supplierName, // 供应商名称
+                    filtersItem?.supplierName || item.supplierName, // 供应商名称
                   approvalNumber: item.approvalNumber, // 批准文号
-                  productionRequirements: this.form.productionRequirements,
+                  productionRequirements: filtersItem.productionRequirements,
                   packingSpecification: item.packingSpecification, // 包装规格
-                  packingSpecificationOption: newSpecificationOption[index], // 包装规格选项
+                  packingSpecificationOption: newSpecificationOption, // 包装规格选项
                   packingSpecificationLabel: packingSpecificationLabel, // 包装规格显示
                   // minPackingQuantity: 1, // 最小包装单元数量
-                  packingQuantity: this.isMoreProduct
-                    ? this.detailList.filter(
-                        (val) => val.productCode == item.code
-                      ).length
-                    : this.detailList.length || this.form.detailList.length, // 包装数量
+                  // packingQuantity: this.isMoreProduct
+                  //   ? this.detailList.filter(
+                  //       (val) => val.productCode == item.code
+                  //     ).length
+                  //   : this.detailList.length || this.form.detailList.length, // 包装数量
+
+                  packingQuantity: this.isMoreProduct ? filtersItem.packingQuantity : this.detailList.length || this.detailList.length, 
                   packingUnit: packingUnit, // 单位
                   measureQuantity: this.isMoreProduct
-                    ? this.getMeasureQuantity(item.code)
+                    ? filtersItem.quantity
                     : this.form.totalCount, // 计量数量
-                  measureUnit: item.measuringUnit, // 计量单位
+                  measureUnit: filtersItem.measuringUnit, // 计量单位
                   measureType: item.measureType, // 计量方式
                   netWeight: item.netWeight > -1 ? item.netWeight : 0, // 净重
                   weight: weight || 0, // 重量
                   singleWeight: singleWeight || 0,
                   weightUnit: item.weightUnit, // 重量单位
-                  totalMoney: item.totalPrice, // 总价
-                  unitPrice: item.unitPrice, // 单价
+                  totalMoney: filtersItem.totalPrice, // 总价
+                  unitPrice: filtersItem.unitPrice, // 单价
                   purpose: '', // 用途
                   isUnpack: item.isUnpack, // 是否允许拆包
                   warehouseId: this.isMoreProduct
-                    ? this.detailList.find(
-                        (val) => val.productCode == item.code
-                      )?.warehouseId
+                    ? filtersItem?.warehouseId
                     : this.form.warehouseId, // 仓库id
                   warehouseName: this.isMoreProduct
-                    ? this.detailList.find(
-                        (val) => val.productCode == item.code
-                      )?.warehouseName
+                    ? filtersItem?.warehouseName
                     : this.form.warehouseName, // 仓库名称
                   warehouseIds: this.isMoreProduct
-                    ? this.detailList
+                    ? mergedList
                         .filter((val) => val.productCode == item.code)
                         .map((item) => item.warehouseId)
                     : warehouseIds,
                   warehouseNames: this.isMoreProduct
-                    ? this.detailList
+                    ? mergedList
                         .filter((val) => val.productCode == item.code)
                         .map((item) => item.warehouseName)
                     : warehouseNames
@@ -2228,7 +2266,7 @@
                         (val) => val.categoryCode == item.productCode
                       ).index
                     : this.productList[0].index, // 产品索引
-                  batchNo: this.productList[0].batchNo, // 批次号
+                  batchNo: item.batchNo || this.productList[0].batchNo, // 批次号
                   packageNo:
                     item.packageNo ||
                     item.packingCode ||
@@ -2250,13 +2288,13 @@
                       )?.packingSpecificationOption
                     : this.productList[0].packingSpecificationOption, // 包装规格
 
-                  netWeight: this.productList[0].netWeight, // 净重
+                  netWeight: item.netWeight || this.productList[0].netWeight, // 净重
                   barcodes: item.barcodes || item.sendCode, // 发货条码
                   clientCode: clientCode, // 客户代号
                   materielDesignation:
                     item.materielDesignation || item.extInfo?.materielCode, // 物料代号
                   engrave: item.engrave || item.extInfo?.engrave, // 刻码
-                  isUnpack: this.productList[0].isUnpack, // 是否允许拆包
+                  isUnpack: item.isUnpack || this.productList[0].isUnpack, // 是否允许拆包
                   productionDate: productionDate, // 生产日期
                   purchaseDate: purchaseDate, // 采购时间
                   result: 1, // 结果(1合格 2不合格)