修复生产统计与维修记录用户数据
This commit is contained in:
@@ -183,7 +183,7 @@ export default {
|
||||
methods: {
|
||||
getCurrentUserCode() {
|
||||
const user = uni.getStorageSync('scanapp_user') || {}
|
||||
return user.username || user.nickname || 'U001'
|
||||
return String(user.username || user.user_code || '').trim()
|
||||
},
|
||||
loadPdaMode() {
|
||||
const userCode = this.getCurrentUserCode()
|
||||
@@ -307,6 +307,31 @@ export default {
|
||||
return false
|
||||
}
|
||||
},
|
||||
hasExistingRecordForRule(rule) {
|
||||
const matchField = rule.match_field || 'process_order_no'
|
||||
const valueMap = {
|
||||
process_order_no: this.form.processOrderNo,
|
||||
order_no: this.form.processOrderNo,
|
||||
product_code: this.form.productCode,
|
||||
user_code: this.currentUser.userCode
|
||||
}
|
||||
const currentValue = String(valueMap[matchField] || '').trim()
|
||||
if (!currentValue) return false
|
||||
return this.recentRecords.some((record) => {
|
||||
const recordValue = String(record[matchField] || (matchField === 'order_no' ? record.process_order_no : '')).trim()
|
||||
return recordValue === currentValue
|
||||
})
|
||||
},
|
||||
getDuplicateRuleMessage(rule) {
|
||||
const fieldLabels = {
|
||||
order_no: '加工单号',
|
||||
process_order_no: '加工单号',
|
||||
product_code: '商品编码',
|
||||
user_code: '用户编码'
|
||||
}
|
||||
const field = rule.match_field || 'process_order_no'
|
||||
return `${fieldLabels[field] || '当前数据'}已录入,当前规则不允许重复扫码`
|
||||
},
|
||||
validateSpecificRules() {
|
||||
const context = {
|
||||
order_no: this.form.processOrderNo.trim(),
|
||||
@@ -316,10 +341,10 @@ export default {
|
||||
}
|
||||
const blockedRule = this.specificRules.find((rule) => {
|
||||
if (rule.apply_mode && rule.apply_mode !== 'machine' && rule.apply_mode !== 'both') return false
|
||||
return Number(rule.rule_type) === 2 && this.matchSpecificRule(rule, context)
|
||||
return Number(rule.rule_type) === 2 && this.matchSpecificRule(rule, context) && this.hasExistingRecordForRule(rule)
|
||||
})
|
||||
if (blockedRule) {
|
||||
uni.showToast({ title: blockedRule.rule_name || '当前整机数据命中特定规则,禁止提交', icon: 'none' })
|
||||
uni.showToast({ title: this.getDuplicateRuleMessage(blockedRule), icon: 'none' })
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -394,6 +419,10 @@ export default {
|
||||
this.form.quantity = Math.max(1, Number(this.form.quantity || 1) - 1)
|
||||
},
|
||||
validateForm() {
|
||||
if (!this.currentUser.userCode) {
|
||||
uni.showToast({ title: '登录信息已失效,请重新登录', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!this.form.processOrderNo.trim()) {
|
||||
uni.showToast({ title: '请输入加工单号', icon: 'none' })
|
||||
return false
|
||||
@@ -430,26 +459,32 @@ export default {
|
||||
return true
|
||||
},
|
||||
async submitEntry() {
|
||||
if (this.submitting) return
|
||||
await this.loadDataEntryConfig()
|
||||
if (!this.validateForm()) return
|
||||
this.submitting = true
|
||||
try {
|
||||
const processItem = this.processOptions[this.selectedProcessIndex]
|
||||
const stepItem = this.stepOptions[this.selectedStepIndex]
|
||||
await submitProductRecord({
|
||||
const payload = {
|
||||
process_order_no: this.form.processOrderNo.trim(),
|
||||
product_code: this.form.productCode.trim(),
|
||||
quantity: Number(this.form.quantity) || 1,
|
||||
user_code: this.currentUser.userCode,
|
||||
user_code: this.currentUser.userCode.trim(),
|
||||
process_id: processItem?.value,
|
||||
step_id: stepItem?.value,
|
||||
scan_result: 1
|
||||
})
|
||||
}
|
||||
await submitProductRecord(payload)
|
||||
uni.showToast({ title: '整机录入成功', icon: 'success' })
|
||||
this.resetForm()
|
||||
await this.loadPageData()
|
||||
} catch (error) {
|
||||
console.error('[scanapp] 整机录入失败', error)
|
||||
uni.showToast({
|
||||
title: error?.message || '整机录入失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user