生产模块完成任务接口加幂等:重复点击“完成”不应重复生成回执

优化页面体验
任务允许重复但要合并
This commit is contained in:
朱昊天
2026-06-01 13:56:39 +08:00
parent 303092e637
commit 9f4e1c39ad
5 changed files with 117 additions and 26 deletions

View File

@@ -98,6 +98,11 @@
<span style="margin-left: 10px;">已完 {{ formatQty(t.finishedQty) }}</span>
<span style="margin-left: 10px;">未完 {{ formatQty(t.unfinishedQty) }}</span>
</div>
<div class="task-item__meta">
<span v-if="t.planStartTime || t.planEndTime">计划 {{ formatTimeRange(t.planStartTime, t.planEndTime) }}</span>
<span v-if="t.createBy" style="margin-left: 10px;">创建 {{ t.createBy }}</span>
<span v-if="t.updateTime" style="margin-left: 10px;">更新 {{ formatTime(t.updateTime) }}</span>
</div>
<el-progress :percentage="taskProgressPercent(t)" :stroke-width="8" :show-text="false" />
</div>
</el-scrollbar>
@@ -339,6 +344,22 @@ function normalizeRole(v) {
return String(v || '').toLowerCase()
}
function formatTime(v) {
if (!v) return '-'
if (v instanceof Date) {
return formatDateTime(v).slice(0, 16)
}
const s = String(v)
if (s.length >= 16) return s.slice(0, 16)
return s
}
function formatTimeRange(start, end) {
const a = start ? formatTime(start) : '-'
const b = end ? formatTime(end) : '-'
return `${a} ~ ${b}`
}
function pad2(n) {
return String(n).padStart(2, '0')
}
@@ -560,21 +581,43 @@ function onProductPicked(row) {
}
}
function mergeProductLines(lines) {
const list = Array.isArray(lines) ? lines : []
const map = new Map()
list.forEach((p) => {
if (!p || p.productId == null) return
const key = String(p.productId)
const planQty = toNumber(p.planQty)
if (!map.has(key)) {
map.set(key, {
productId: p.productId,
planQty,
unit: p.unit || '',
remark: p.remark || ''
})
return
}
const hit = map.get(key)
hit.planQty = toNumber(hit.planQty) + planQty
if (!hit.unit && p.unit) hit.unit = p.unit
if (!hit.remark && p.remark) hit.remark = p.remark
})
return Array.from(map.values())
}
function submitAdd() {
if (!addFormRef.value) return
addFormRef.value.validate((valid) => {
if (!valid) return
const task = Object.assign({}, addForm.value)
const products = (addProducts.value || [])
.filter((p) => p && p.productId != null)
.map((p) => ({
productId: p.productId,
planQty: p.planQty || 0,
finishedQty: 0,
badQty: 0,
unit: p.unit || '',
remark: p.remark || ''
}))
const products = mergeProductLines(addProducts.value).map((p) => ({
productId: p.productId,
planQty: p.planQty || 0,
finishedQty: 0,
badQty: 0,
unit: p.unit || '',
remark: p.remark || ''
}))
addSaving.value = true
addProductionTask({ task, products })
@@ -775,6 +818,13 @@ onMounted(() => {
margin-bottom: 8px;
}
.task-item__meta {
margin-top: -2px;
margin-bottom: 8px;
font-size: 12px;
color: #c0c4cc;
}
.mb12 {
margin-bottom: 12px;
}