修复生产统计与维修记录用户数据
This commit is contained in:
@@ -400,6 +400,33 @@ const matchSpecificRule = (rule: ProduceDataEntrySpecificRule, valueMap: Record<
|
||||
}
|
||||
}
|
||||
|
||||
const hasExistingRecordForRule = (rule: ProduceDataEntrySpecificRule) => {
|
||||
const matchField = rule.match_field || 'process_order_no'
|
||||
const currentValue = String(({
|
||||
process_order_no: processOrderNo.value,
|
||||
order_no: processOrderNo.value,
|
||||
product_code: productCode.value,
|
||||
user_code: userCode.value,
|
||||
} as Record<string, string>)[matchField] || '').trim()
|
||||
if (!currentValue) return false
|
||||
const matched = recentRecords.value.some((record) => {
|
||||
const recordValue = String((record as Record<string, any>)[matchField] || (matchField === 'order_no' ? record.process_order_no : '')).trim()
|
||||
return recordValue === currentValue
|
||||
})
|
||||
return matched
|
||||
}
|
||||
|
||||
const getDuplicateRuleMessage = (rule: ProduceDataEntrySpecificRule) => {
|
||||
const fieldLabels: Record<string, string> = {
|
||||
order_no: '加工单号',
|
||||
process_order_no: '加工单号',
|
||||
product_code: '商品编码',
|
||||
user_code: '用户编码',
|
||||
}
|
||||
const field = rule.match_field || 'process_order_no'
|
||||
return `${fieldLabels[field] || '当前数据'}已录入,当前规则不允许重复扫码`
|
||||
}
|
||||
|
||||
const validateSpecificRules = () => {
|
||||
if (!specificRules.value.length) {
|
||||
return true
|
||||
@@ -415,11 +442,11 @@ const validateSpecificRules = () => {
|
||||
if ((rule.apply_mode || 'order') !== 'machine' && rule.apply_mode !== 'both') {
|
||||
return false
|
||||
}
|
||||
return Number(rule.rule_type) === 2 && matchSpecificRule(rule, context)
|
||||
return Number(rule.rule_type) === 2 && matchSpecificRule(rule, context) && hasExistingRecordForRule(rule)
|
||||
})
|
||||
|
||||
if (blockedRule) {
|
||||
ElMessage.warning(blockedRule.rule_name || '当前整机数据命中特定规则,禁止提交')
|
||||
ElMessage.warning(getDuplicateRuleMessage(blockedRule))
|
||||
const matchField = blockedRule.match_field || 'process_order_no'
|
||||
if (matchField === 'product_code') {
|
||||
focusProductCodeInput()
|
||||
@@ -484,12 +511,13 @@ const resetForm = () => {
|
||||
}
|
||||
|
||||
const submitEntry = async () => {
|
||||
if (submitting.value) return
|
||||
if (!validateBeforeSubmit()) return
|
||||
const passed = await runUserCodeCheck(userCode.value)
|
||||
if (!passed) { emit('play-error'); nextTick(() => focusUserCodeInput()); return }
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await submitProductRecord({
|
||||
const payload = {
|
||||
process_order_no: processOrderNo.value.trim(),
|
||||
product_code: productCode.value.trim(),
|
||||
quantity: Number(quantity.value) || 1,
|
||||
@@ -497,7 +525,8 @@ const submitEntry = async () => {
|
||||
step_id: props.selectedStep,
|
||||
user_code: userCode.value.trim(),
|
||||
scan_result: 1,
|
||||
})
|
||||
}
|
||||
const result = await submitProductRecord(payload)
|
||||
if (Number(result?.code) !== 0) throw new Error(result?.msg || '录入失败')
|
||||
ElMessage.success('录入成功')
|
||||
emit('play-success')
|
||||
|
||||
Reference in New Issue
Block a user