|
@@ -812,21 +812,26 @@ const handleClickPacking = () => {
|
|
|
const contractIds = formData.data.contractIds
|
|
|
? formData.data.contractIds.join(",")
|
|
|
: "";
|
|
|
- formData.data.packDetailList.push({
|
|
|
+ let item = {
|
|
|
customerId: customerId,
|
|
|
contractIds: contractIds,
|
|
|
- packQuantity: undefined,
|
|
|
- netWeight: undefined,
|
|
|
- roughWeight: undefined,
|
|
|
- boxLong: undefined,
|
|
|
- boxWide: undefined,
|
|
|
- boxHigh: undefined,
|
|
|
+ packQuantity: 1,
|
|
|
+ netWeight: null,
|
|
|
+ roughWeight: null,
|
|
|
+ boxLong: null,
|
|
|
+ boxWide: null,
|
|
|
+ boxHigh: null,
|
|
|
bomVolume: "",
|
|
|
remark: "",
|
|
|
packDetailGoodsList: [],
|
|
|
packDetailProductList: packDetailProductList,
|
|
|
isShow: false,
|
|
|
- });
|
|
|
+ };
|
|
|
+ formData.data.packDetailList.push(item);
|
|
|
+ handleChangePackQuantity(
|
|
|
+ item.packQuantity,
|
|
|
+ formData.data.packDetailList.length - 1
|
|
|
+ );
|
|
|
} else {
|
|
|
return ElMessage({
|
|
|
message: "请选择产品 !",
|
|
@@ -836,43 +841,45 @@ const handleClickPacking = () => {
|
|
|
};
|
|
|
|
|
|
const handleChangePackQuantity = (val, index) => {
|
|
|
- console.log(formData.data.contractProductData, "aa");
|
|
|
- console.log(formData.data.packDetailList, "bb");
|
|
|
- if (val && val > 0) {
|
|
|
- // for (let i = 0; i < formData.data.contractProductData.length; i++) {
|
|
|
- // const iele = formData.data.contractProductData[i];
|
|
|
- // iele.waitQuantity =
|
|
|
- // Number(iele.cpQuantity) - Number(iele.sumPackQuantity);
|
|
|
- // let quantity = e.waitQuantity;
|
|
|
- // for (let j = 0; j < formData.data.packDetailList.length; j++) {
|
|
|
- // const jele = formData.data.packDetailList[j];
|
|
|
- // }
|
|
|
- // }
|
|
|
+ // if (val && val > 0) {
|
|
|
+ // 转为map对象
|
|
|
+ const obj = {};
|
|
|
+ for (let i = 0; i < formData.data.contractProductData.length; i++) {
|
|
|
+ const e = formData.data.contractProductData[i];
|
|
|
+ obj[e.contractId + ""] = Number(e.cpQuantity) - Number(e.sumPackQuantity);
|
|
|
+ }
|
|
|
+ // 计算数量 即装箱数量 * 箱数 新增字段放在最外层
|
|
|
+ for (let i = 0; i < formData.data.packDetailList.length; i++) {
|
|
|
+ const ele = formData.data.packDetailList[i];
|
|
|
+ for (let j = 0; j < ele.packDetailProductList.length; j++) {
|
|
|
+ const jele = ele.packDetailProductList[j];
|
|
|
+ ele[jele.contractId + ""] = Number(ele.packQuantity) * jele.quantity;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 计算新的待装箱数量
|
|
|
+ for (let i = 0; i < formData.data.packDetailList.length; i++) {
|
|
|
+ const e = formData.data.packDetailList[i];
|
|
|
+ for (const key in obj) {
|
|
|
+ obj[key] = obj[key] - e[key];
|
|
|
+ if (obj[key] < 0) {
|
|
|
+ e.packQuantity = null;
|
|
|
+ handleChangePackQuantity(null, index);
|
|
|
+ return ElMessage({
|
|
|
+ message: "装箱数量 * 箱数不可大于待装箱数量",
|
|
|
+ type: "info",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 赋值
|
|
|
+ for (let i = 0; i < formData.data.contractProductData.length; i++) {
|
|
|
+ const e = formData.data.contractProductData[i];
|
|
|
+ for (const key in obj) {
|
|
|
+ if (e.contractId === key) {
|
|
|
+ e.waitQuantity = obj[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- // if (formData.data.contractProductData.length > 0 && val && val > 0) {
|
|
|
- // for (let j = 0; j < formData.data.contractProductData.length; j++) {
|
|
|
- // const e = formData.data.contractProductData[j];
|
|
|
- // e.waitQuantity = Number(e.cpQuantity) - Number(e.sumPackQuantity);
|
|
|
- // let quantity = e.waitQuantity;
|
|
|
- // for (let i = 0; i < formData.data.packDetailList.length; i++) {
|
|
|
- // const iele = formData.data.packDetailList[i];
|
|
|
- // quantity -= iele.quantity * Number(e.quantity);
|
|
|
- // if (quantity < 0) {
|
|
|
- // formData.data.packDetailList[i].packQuantity = undefined;
|
|
|
- // return ElMessage({
|
|
|
- // message: "装箱数量 * 箱数不可大于待装箱数量",
|
|
|
- // type: "info",
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // e.waitQuantity = quantity;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // for (let j = 0; j < formData.data.contractProductData.length; j++) {
|
|
|
- // const e = formData.data.contractProductData[j];
|
|
|
- // e.waitQuantity = Number(e.cpQuantity) - Number(e.sumPackQuantity);
|
|
|
- // }
|
|
|
// }
|
|
|
};
|
|
|
|
|
@@ -918,7 +925,7 @@ const handleChangeContract = (val) => {
|
|
|
formData.data.contractProductData = res.data.map((x) => ({
|
|
|
...x,
|
|
|
waitQuantity: Number(x.cpQuantity) - Number(x.sumPackQuantity),
|
|
|
- quantity: undefined,
|
|
|
+ quantity: null,
|
|
|
}));
|
|
|
});
|
|
|
};
|