|
|
@@ -54,7 +54,8 @@
|
|
|
<el-input
|
|
|
v-model="row.reportQuantity"
|
|
|
placeholder="请输入"
|
|
|
- type="number"
|
|
|
+ inputmode="decimal"
|
|
|
+ type="text"
|
|
|
@input="(e) => handleQuantityInput(e, 'reportQuantity', row)"
|
|
|
></el-input>
|
|
|
</template>
|
|
|
@@ -69,7 +70,8 @@
|
|
|
<el-input
|
|
|
v-model="row.lossQuantity"
|
|
|
placeholder="请输入"
|
|
|
- type="number"
|
|
|
+ inputmode="decimal"
|
|
|
+ type="text"
|
|
|
@input="(e) => handleQuantityInput(e, 'lossQuantity', row)"
|
|
|
></el-input>
|
|
|
</template>
|
|
|
@@ -305,7 +307,9 @@
|
|
|
pageAssigneeByTask(this.params)
|
|
|
.then((res) => {
|
|
|
this.loading = false;
|
|
|
- this.workList = res.list;
|
|
|
+ this.workList = (res.list || []).map((item) =>
|
|
|
+ this.buildReportRow(item)
|
|
|
+ );
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
this.loading = false;
|
|
|
@@ -313,6 +317,121 @@
|
|
|
this.$message.error(err.message);
|
|
|
});
|
|
|
},
|
|
|
+ buildReportRow(row) {
|
|
|
+ const reportQuantityReported = Number(row.reportQuantity) || 0;
|
|
|
+ const lossQuantityReported = Number(row.lossQuantity) || 0;
|
|
|
+ const remainingReportQuantity = this.getRemainingReportQuantity({
|
|
|
+ ...row,
|
|
|
+ reportQuantityReported,
|
|
|
+ lossQuantityReported
|
|
|
+ });
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...row,
|
|
|
+ reportQuantityReported,
|
|
|
+ lossQuantityReported,
|
|
|
+ remainingReportQuantity,
|
|
|
+ reportQuantity: remainingReportQuantity,
|
|
|
+ lossQuantity: 0
|
|
|
+ };
|
|
|
+ },
|
|
|
+ getRemainingReportQuantity(row) {
|
|
|
+ const taskQuantity = Number(row.quantity) || 0;
|
|
|
+ const reportQuantityReported =
|
|
|
+ Number(
|
|
|
+ row.reportQuantityReported !== undefined &&
|
|
|
+ row.reportQuantityReported !== null
|
|
|
+ ? row.reportQuantityReported
|
|
|
+ : row.reportQuantity
|
|
|
+ ) || 0;
|
|
|
+ const lossQuantityReported =
|
|
|
+ Number(
|
|
|
+ row.lossQuantityReported !== undefined &&
|
|
|
+ row.lossQuantityReported !== null
|
|
|
+ ? row.lossQuantityReported
|
|
|
+ : row.lossQuantity
|
|
|
+ ) || 0;
|
|
|
+
|
|
|
+ return Math.max(
|
|
|
+ taskQuantity - reportQuantityReported - lossQuantityReported,
|
|
|
+ 0
|
|
|
+ );
|
|
|
+ },
|
|
|
+ validateReportQuantity(row) {
|
|
|
+ this.normalizeQuantityBeforeSubmit(row);
|
|
|
+ const quantityFormatValid = this.validateQuantityFormat(row);
|
|
|
+ if (!quantityFormatValid) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const reportQuantity = Number(row.reportQuantity) || 0;
|
|
|
+ const lossQuantity = Number(row.lossQuantity) || 0;
|
|
|
+ const totalQuantity = reportQuantity + lossQuantity;
|
|
|
+ const remainingReportQuantity = this.getRemainingReportQuantity(row);
|
|
|
+
|
|
|
+ if (reportQuantity === 0 && lossQuantity === 0) {
|
|
|
+ this.$message.warning('该任务数已经报工完成,无法再报工');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (totalQuantity > remainingReportQuantity) {
|
|
|
+ this.$message.warning(
|
|
|
+ `本次报工数加损耗数不能大于剩余可报工数(剩余 ${remainingReportQuantity})`
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ normalizeQuantityBeforeSubmit(row) {
|
|
|
+ ['reportQuantity', 'lossQuantity'].forEach((key) => {
|
|
|
+ if (typeof row[key] === 'string' && row[key].endsWith('.')) {
|
|
|
+ row[key] = row[key].slice(0, -1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ validateQuantityFormat(row) {
|
|
|
+ const quantityList = [
|
|
|
+ { label: '报工数', value: row.reportQuantity },
|
|
|
+ { label: '损耗数', value: row.lossQuantity }
|
|
|
+ ];
|
|
|
+
|
|
|
+ for (const item of quantityList) {
|
|
|
+ const value = item.value;
|
|
|
+ if (value === '' || value === null || value === undefined) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!this.isCompleteQuantity(value)) {
|
|
|
+ this.$message.warning(
|
|
|
+ `${item.label}格式不正确,请输入正整数或小数`
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ isCompleteQuantity(value) {
|
|
|
+ return /^\d+(\.\d+)?$/.test(String(value));
|
|
|
+ },
|
|
|
+ formatQuantityInput(e) {
|
|
|
+ let value = String(e === null || e === undefined ? '' : e).replace(
|
|
|
+ /[^\d.]/g,
|
|
|
+ ''
|
|
|
+ );
|
|
|
+ const dotIndex = value.indexOf('.');
|
|
|
+
|
|
|
+ if (dotIndex !== -1) {
|
|
|
+ value =
|
|
|
+ value.slice(0, dotIndex + 1) +
|
|
|
+ value.slice(dotIndex + 1).replace(/\./g, '');
|
|
|
+ }
|
|
|
+ if (value.startsWith('.')) {
|
|
|
+ value = `0${value}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ const parts = value.split('.');
|
|
|
+ parts[0] = parts[0].replace(/^0+(?=\d)/, '');
|
|
|
+
|
|
|
+ return parts.length > 1 ? `${parts[0]}.${parts[1]}` : parts[0];
|
|
|
+ },
|
|
|
// 保存
|
|
|
saveData(row) {
|
|
|
if (!row.realStartTime) {
|
|
|
@@ -350,6 +469,10 @@
|
|
|
// );
|
|
|
// }
|
|
|
|
|
|
+ if (!this.validateReportQuantity(row)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
let params = {
|
|
|
realStartTime: row.realStartTime,
|
|
|
realEndTime: row.realEndTime,
|
|
|
@@ -393,14 +516,7 @@
|
|
|
},
|
|
|
// 数量正则 quantity
|
|
|
handleQuantityInput(e, type, row) {
|
|
|
- // 过滤非数字字符(包括负号)
|
|
|
- let value = e.replace(/[^\d]/g, '');
|
|
|
- // 限制不能以 0 开头(除非是 0 本身)
|
|
|
- if (value.startsWith('0') && value.length > 1) {
|
|
|
- value = value.slice(1);
|
|
|
- }
|
|
|
- // 更新绑定值
|
|
|
- row[type] = value;
|
|
|
+ row[type] = this.formatQuantityInput(e);
|
|
|
this.calculateQuantity(row, type);
|
|
|
},
|
|
|
//计算重量
|
|
|
@@ -418,10 +534,22 @@
|
|
|
// row[type] = 0;
|
|
|
// this.$message.warning('合格数量加不合格数量不能大于任务数量');
|
|
|
// }
|
|
|
- let total = row.reportQuantity - 0 + (row.lossQuantity - 0);
|
|
|
- if (total > row.formingNum) {
|
|
|
- this.form[type] = 0;
|
|
|
- this.$message.warning('报工数量加损耗数量不能大于要求完成数量');
|
|
|
+ const reportQuantity = Number(row.reportQuantity) || 0;
|
|
|
+ const lossQuantity = Number(row.lossQuantity) || 0;
|
|
|
+ const totalQuantity = reportQuantity + lossQuantity;
|
|
|
+ const remainingReportQuantity = this.getRemainingReportQuantity(row);
|
|
|
+ if (
|
|
|
+ (row.reportQuantity &&
|
|
|
+ !this.isCompleteQuantity(row.reportQuantity)) ||
|
|
|
+ (row.lossQuantity && !this.isCompleteQuantity(row.lossQuantity))
|
|
|
+ ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (totalQuantity > remainingReportQuantity) {
|
|
|
+ row[type] = '';
|
|
|
+ this.$message.warning(
|
|
|
+ `本次报工数加损耗数不能大于剩余可报工数(剩余 ${remainingReportQuantity})`
|
|
|
+ );
|
|
|
}
|
|
|
},
|
|
|
// 查看修改记录
|