|
|
@@ -200,7 +200,7 @@
|
|
|
<el-table-column label="计量数量">
|
|
|
<template slot-scope="{ row }">
|
|
|
<el-input
|
|
|
- v-if="!hasPacking && !isAutoMeasureTarget(row.target)"
|
|
|
+ v-if="!hasPacking"
|
|
|
v-model="row.target.measureQuantity"
|
|
|
maxlength="19"
|
|
|
:disabled="Boolean(pendingApproveId)"
|
|
|
@@ -595,6 +595,14 @@
|
|
|
return decimal(value).decimalPlaces(6).toFixed(6);
|
|
|
}
|
|
|
|
|
|
+ function formatDecimal(value) {
|
|
|
+ return decimal(value)
|
|
|
+ .decimalPlaces(6)
|
|
|
+ .toFixed(6)
|
|
|
+ .replace(/\.0+$/, '')
|
|
|
+ .replace(/(\.\d*?)0+$/, '$1');
|
|
|
+ }
|
|
|
+
|
|
|
function isEmptyDecimal(value) {
|
|
|
return value == null || String(value).trim() === '';
|
|
|
}
|
|
|
@@ -680,8 +688,8 @@
|
|
|
return this.packingRows.length > 0;
|
|
|
},
|
|
|
mergeMeasureQuantity() {
|
|
|
- return this.sources
|
|
|
- .reduce(
|
|
|
+ return formatDecimal(
|
|
|
+ this.sources.reduce(
|
|
|
(sum, source) =>
|
|
|
sum.plus(
|
|
|
decimal(source.stockCountBase).minus(
|
|
|
@@ -690,7 +698,7 @@
|
|
|
),
|
|
|
new BigNumber(0)
|
|
|
)
|
|
|
- .toFixed(6);
|
|
|
+ );
|
|
|
},
|
|
|
targetRows() {
|
|
|
return this.targets.map((target) => {
|
|
|
@@ -921,7 +929,19 @@
|
|
|
(max, target) => Math.max(max, target.targetDetailId),
|
|
|
0
|
|
|
);
|
|
|
- this.targets.push(this.createTarget(maxId + 1));
|
|
|
+ const target = this.createTarget(maxId + 1);
|
|
|
+ this.targets.push(target);
|
|
|
+ if (this.hasPacking) {
|
|
|
+ this.syncTargetPackingMinimums();
|
|
|
+ } else {
|
|
|
+ this.handleMeasureQuantityInput(this.targets[0]);
|
|
|
+ const weightRemainder = decimal(this.sources[0].weight).minus(
|
|
|
+ this.sum(this.targets.slice(0, -1), 'weight')
|
|
|
+ );
|
|
|
+ target.weight = formatDecimal(
|
|
|
+ weightRemainder.isNegative() ? 0 : weightRemainder
|
|
|
+ );
|
|
|
+ }
|
|
|
},
|
|
|
removeTarget(targetDetailId) {
|
|
|
if (this.targets.length <= 2)
|
|
|
@@ -937,6 +957,11 @@
|
|
|
this.targets = this.targets.filter(
|
|
|
(target) => target.targetDetailId !== targetDetailId
|
|
|
);
|
|
|
+ if (this.hasPacking) {
|
|
|
+ this.syncTargetPackingMinimums();
|
|
|
+ } else {
|
|
|
+ this.handleMeasureQuantityInput(this.targets[0]);
|
|
|
+ }
|
|
|
if (this.batchPackingTargetId === targetDetailId) {
|
|
|
this.batchPackingTargetId = null;
|
|
|
}
|
|
|
@@ -954,8 +979,8 @@
|
|
|
row.targetDetailId = null;
|
|
|
});
|
|
|
const target = this.targets[0];
|
|
|
- target.measureQuantity = this.sources
|
|
|
- .reduce(
|
|
|
+ target.measureQuantity = formatDecimal(
|
|
|
+ this.sources.reduce(
|
|
|
(sum, source) =>
|
|
|
sum.plus(
|
|
|
decimal(source.stockCountBase).minus(
|
|
|
@@ -964,7 +989,7 @@
|
|
|
),
|
|
|
new BigNumber(0)
|
|
|
)
|
|
|
- .toFixed(6);
|
|
|
+ );
|
|
|
target.packageQuantity = this.sum(this.sources, 'packingQuantity');
|
|
|
target.weight = this.sum(this.sources, 'weight');
|
|
|
this.syncTargetPackingMinimums();
|
|
|
@@ -982,8 +1007,9 @@
|
|
|
isAutoMeasureTarget(target) {
|
|
|
return (
|
|
|
this.mode === 'split' &&
|
|
|
- this.targets.length === 2 &&
|
|
|
- target.targetDetailId === this.targets[1].targetDetailId
|
|
|
+ this.targets.length > 1 &&
|
|
|
+ target.targetDetailId ===
|
|
|
+ this.targets[this.targets.length - 1].targetDetailId
|
|
|
);
|
|
|
},
|
|
|
/** 将勾选的整包装一次分配到同一目标子批次。 */
|
|
|
@@ -1087,35 +1113,42 @@
|
|
|
);
|
|
|
const measureMinimum = decimal(this.sum(packages, 'measureQuantity'));
|
|
|
const weightMinimum = decimal(this.sum(packages, 'weight'));
|
|
|
- target.measureQuantity = measureMinimum.toFixed(6);
|
|
|
- target.weight = weightMinimum.toFixed(6);
|
|
|
+ target.measureQuantity = formatDecimal(measureMinimum);
|
|
|
+ target.weight = formatDecimal(weightMinimum);
|
|
|
});
|
|
|
if (this.mode === 'split') {
|
|
|
const lastTarget = this.targets[this.targets.length - 1];
|
|
|
const assigned = this.targets.slice(0, -1);
|
|
|
- lastTarget.measureQuantity = decimal(source.stockCountBase)
|
|
|
- .minus(this.sum(assigned, 'measureQuantity'))
|
|
|
- .max(0)
|
|
|
- .toFixed(6);
|
|
|
- lastTarget.weight = decimal(source.weight)
|
|
|
- .minus(this.sum(assigned, 'weight'))
|
|
|
- .max(0)
|
|
|
- .toFixed(6);
|
|
|
+ const measureRemainder = decimal(source.stockCountBase).minus(
|
|
|
+ this.sum(assigned, 'measureQuantity')
|
|
|
+ );
|
|
|
+ const weightRemainder = decimal(source.weight).minus(
|
|
|
+ this.sum(assigned, 'weight')
|
|
|
+ );
|
|
|
+ lastTarget.measureQuantity = formatDecimal(
|
|
|
+ measureRemainder.isNegative() ? 0 : measureRemainder
|
|
|
+ );
|
|
|
+ lastTarget.weight = formatDecimal(
|
|
|
+ weightRemainder.isNegative() ? 0 : weightRemainder
|
|
|
+ );
|
|
|
}
|
|
|
},
|
|
|
handleMeasureQuantityInput(target) {
|
|
|
if (
|
|
|
this.mode !== 'split' ||
|
|
|
- this.targets.length !== 2 ||
|
|
|
this.isAutoMeasureTarget(target) ||
|
|
|
!this.sources.length
|
|
|
) {
|
|
|
return;
|
|
|
}
|
|
|
+ const lastTarget = this.targets[this.targets.length - 1];
|
|
|
+ const assigned = this.targets.filter((item) => item !== lastTarget);
|
|
|
const remainder = decimal(this.sources[0].stockCountBase).minus(
|
|
|
- decimal(target.measureQuantity)
|
|
|
+ this.sum(assigned, 'measureQuantity')
|
|
|
+ );
|
|
|
+ lastTarget.measureQuantity = formatDecimal(
|
|
|
+ remainder.isNegative() ? 0 : remainder
|
|
|
);
|
|
|
- this.targets[1].measureQuantity = remainder.max(0).toFixed(6);
|
|
|
},
|
|
|
validateTargetLimit(target, field) {
|
|
|
if (this.mode !== 'split' || !this.sources.length) return;
|
|
|
@@ -1133,7 +1166,7 @@
|
|
|
const label = field === 'measureQuantity' ? '计量数量' : '重量';
|
|
|
target[field] = '';
|
|
|
this.$message.warning(
|
|
|
- `目标子批次${label}累计不能超过来源库存${label} ${limit.toFixed(6)}`
|
|
|
+ `目标子批次${label}累计不能超过来源库存${label} ${formatDecimal(limit)}`
|
|
|
);
|
|
|
},
|
|
|
targetLabel(id) {
|
|
|
@@ -1151,9 +1184,9 @@
|
|
|
.join('、');
|
|
|
},
|
|
|
sum(rows, key) {
|
|
|
- return rows
|
|
|
- .reduce((sum, row) => sum.plus(decimal(row[key])), new BigNumber(0))
|
|
|
- .toFixed(6);
|
|
|
+ return formatDecimal(
|
|
|
+ rows.reduce((sum, row) => sum.plus(decimal(row[key])), new BigNumber(0))
|
|
|
+ );
|
|
|
},
|
|
|
total(key) {
|
|
|
return this.sum(this.sources, key);
|