This commit is contained in:
2026-08-15 09:57:53 +08:00
parent 9b742fd001
commit dd393424c1
2 changed files with 70 additions and 44 deletions
+43 -32
View File
@@ -418,6 +418,8 @@
return this.pickingCompleted
&& this.evidenceIdentity
&& this.evidenceIdentity.inboundId
&& this.loadingVersion !== null
&& this.loadingVersion !== undefined
&& Number.isFinite(Number(this.loadingVersion))
},
partialTargetItem() {
@@ -515,6 +517,7 @@
console.info('[PDA] picking.submit', {
event,
taskId: this.remoteTaskId,
inboundId: this.currentBox.inboundId || this.evidenceIdentity?.inboundId || null,
loadingPlanId: this.currentBox.loadingPlanId,
containerBookingId: this.currentBox.containerBookingId,
warehouseId: this.currentBox.warehouseId || session.currentUser?.warehouseId || session.currentUser?.warehouse,
@@ -682,6 +685,8 @@
this.taskRequestId += 1
this.submitting = false
this.currentBoxIndex = index
this.currentBox.inboundId = null
this.currentBox.inboundVersion = null
this.remoteTaskId = null
this.remotePick = null
this.pickingVersion = null
@@ -825,12 +830,12 @@
}
this.remotePick = normalizePickingTask({ ...task, ...(claimed || {}) })
this.pickingVersion = this.remotePick.pickingVersion ?? this.remotePick.version ?? null
this.loadingVersion = this.currentBox.inboundVersion ?? this.remotePick.inboundVersion ?? null
this.debugSubmit('refresh.ready', { requestId, workflowStatus: this.remotePick.workflowStatus, taskStatus: this.remotePick.taskStatus, assignmentVersion: this.assignmentVersion, loadingVersion: this.loadingVersion })
this.loadingVersion = task.inboundVersion ?? task.loadingVersion ?? this.remotePick.inboundVersion ?? this.remotePick.loadingVersion ?? null
this.evidenceIdentity = this.captureEvidenceIdentity()
this.debugSubmit('refresh.ready', { requestId, workflowStatus: this.remotePick.workflowStatus, taskStatus: this.remotePick.taskStatus, assignmentVersion: this.assignmentVersion, loadingVersion: this.loadingVersion, evidenceIdentity: this.evidenceIdentity })
this.assignmentVersion = this.remotePick.assignmentVersion ?? this.assignmentVersion
if (!this.pickingCompleted) this.restoreRemoteDraft()
this.resetEvidenceState()
if (this.pickingCompleted) await this.loadLoadingEvidence()
if (this.loadingStageReady) await this.loadLoadingEvidence()
} catch (error) {
if (requestId !== this.taskRequestId) return
this.debugSubmit('refresh.error', { requestId, message: error.message || '', code: error.code || '', statusCode: error.statusCode || '', requestIdFromServer: error.requestId || '', traceId: error.traceId || '' })
@@ -838,16 +843,17 @@
} finally { if (requestId === this.taskRequestId) this.remoteLoading = false }
},
async loadLoadingEvidence() {
if (!this.pickingCompleted || !this.currentBox.inboundId || !isRemoteReady(this.currentBox.inboundId)) return
if (!this.loadingStageReady || !this.evidenceIdentity || !isRemoteReady(this.evidenceIdentity.inboundId)) return
const contextId = this.evidenceContextId
const identity = { ...this.evidenceIdentity }
try {
const evidence = await getEvidence(this.currentBox.inboundId, this.currentBox.tenantId)
if (contextId !== this.evidenceContextId) return
const evidence = await getEvidence(identity.inboundId, this.currentBox.tenantId)
if (!this.isEvidenceContextActive(contextId, identity)) return
this.evidenceFiles = (evidence && evidence.evidences ? evidence.evidences : []).reduce((all, item) => { (all[item.evidenceType] ||= []).push(item); return all }, {})
const seal = this.evidenceEntry('SEAL')
this.sealNo = seal?.sealNo || ''
} catch (error) {
if (contextId !== this.evidenceContextId) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.remoteError = error.network ? '网络失败,装柜证据未加载,请刷新重试' : (error.message || '装柜证据加载失败')
}
},
@@ -867,27 +873,28 @@
if (!isOnline()) { this.showToast('当前网络不可用,请联网后再拍照上传', 'warning'); return }
if (typeof uni.chooseImage !== 'function') { this.showToast('当前环境不支持选择照片', 'warning'); return }
const contextId = this.evidenceContextId
const inboundId = this.currentBox.inboundId
const identity = { ...this.evidenceIdentity }
uni.chooseImage({ count: 1, sizeType: ['compressed'], sourceType: ['camera'], success: (result) => {
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
const path = result.tempFilePaths && result.tempFilePaths[0]
if (!path) return
const next = { evidenceType: slot.type, fileName: path.split('/').pop() || path, localPath: path, uploadStatus: 'PENDING' }
this.evidenceFiles = { ...this.evidenceFiles, [slot.type]: [...(this.evidenceFiles[slot.type] || []), next] }
this.queueEvidenceUpload(slot.type, path)
}, fail: () => {
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.showToast('未选择照片,可稍后重试', 'warning')
} })
},
async queueEvidenceUpload(type, path) {
if (!this.requireEvidenceStage()) return
if (!this.currentBox.inboundId || !isRemoteReady(this.currentBox.inboundId)) { this.showToast('当前会话未连接服务端,证据保留本地', 'warning'); return }
if (!this.evidenceIdentity?.inboundId || !isRemoteReady(this.evidenceIdentity.inboundId)) { this.showToast('当前会话未连接服务端,证据保留本地', 'warning'); return }
const contextId = this.evidenceContextId
const identity = { ...this.evidenceIdentity }
const queue = this.evidenceQueue
const entry = queue.add({ inboundId: this.currentBox.inboundId, tenantId: this.currentBox.tenantId, evidenceType: type, localPath: path })
const entry = queue.add({ ...identity, tenantId: this.currentBox.tenantId, evidenceType: type, localPath: path })
await queue.flush()
if (contextId !== this.evidenceContextId || queue !== this.evidenceQueue) return
if (!this.isEvidenceContextActive(contextId, identity) || queue !== this.evidenceQueue) return
const latest = queue.snapshot().find((item) => item.id === entry.id)
if (latest?.status !== 'SUCCEEDED') { this.remoteError = latest?.error || '文件上传失败'; return }
const current = this.evidenceEntry(type) || {}
@@ -898,11 +905,12 @@
if (!this.requireEvidenceStage()) return
const item = this.evidenceQueueEntry(type)
const contextId = this.evidenceContextId
const identity = { ...this.evidenceIdentity }
const queue = this.evidenceQueue
if (!item || !queue.retry(item.id)) return
this.remoteError = ''
await queue.flush()
if (contextId !== this.evidenceContextId || queue !== this.evidenceQueue) return
if (!this.isEvidenceContextActive(contextId, identity) || queue !== this.evidenceQueue) return
const latest = queue.latest(type)
if (latest?.status !== 'SUCCEEDED') { this.remoteError = latest?.error || '文件上传失败'; return }
const current = this.evidenceEntry(type) || {}
@@ -911,21 +919,22 @@
},
async saveEvidence(type, operationId = null) {
if (!this.requireEvidenceStage()) return
if (!this.currentBox.inboundId) { this.showToast('演示任务已记录本地证据', 'success'); return }
if (!isRemoteReady(this.currentBox.inboundId)) { this.showToast('当前会话未连接服务端,证据保留本地', 'warning'); return }
if (!this.evidenceIdentity?.inboundId) { this.showToast('状态尚未同步,请刷新重试', 'warning'); return }
if (!isRemoteReady(this.evidenceIdentity.inboundId)) { this.showToast('当前会话未连接服务端,证据保留本地', 'warning'); return }
const contextId = this.evidenceContextId
const inboundId = this.currentBox.inboundId
const identity = { ...this.evidenceIdentity }
const inboundId = identity.inboundId
const tenantId = this.currentBox.tenantId
const current = this.evidenceEntry(type) || {}
if (!current.fileId) { this.showToast('照片尚未上传完成', 'warning'); return }
const payload = { expectedVersion: current.version || 0, evidenceType: type, fileId: current.fileId || null, fileName: current.fileName || null, sealNo: type === 'SEAL' ? this.sealNo : null, remark: null, operationId: operationId || `evidence-${this.remoteTaskId || this.currentBox.inboundId}-${type}-${current.fileId || 'seal'}` }
const payload = { expectedVersion: current.version || 0, evidenceType: type, fileId: current.fileId || null, fileName: current.fileName || null, sealNo: type === 'SEAL' ? this.sealNo : null, remark: null, operationId: operationId || `evidence-${identity.taskId || identity.inboundId}-${type}-${current.fileId || 'seal'}` }
try {
const result = await upsertEvidence(inboundId, payload, tenantId)
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.evidenceFiles = (result && result.evidences ? result.evidences : []).reduce((all, item) => { const list = (all[item.evidenceType] || []).filter((entry) => entry.id || entry.fileId !== item.fileId); const index = list.findIndex((entry) => entry.id === item.id); all[item.evidenceType] = index >= 0 ? list.map((entry, i) => i === index ? item : entry) : [...list, item]; return all }, this.evidenceFiles)
this.showToast(`${type === 'SEAL' ? '封签' : '照片'}已保存`, 'success')
} catch (error) {
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.remoteError = error.network ? '网络失败,证据未提交,请重试' : (error.message || '证据保存失败')
this.showToast('证据保存失败', 'error')
}
@@ -933,47 +942,49 @@
async saveSealNo() {
if (!this.requireEvidenceStage()) return
if (!String(this.sealNo || '').trim()) { this.showToast('请输入封签号', 'warning'); return }
await this.saveEvidence('SEAL', `seal-no-${this.remoteTaskId || this.currentBox.inboundId}-${Date.now()}`)
await this.saveEvidence('SEAL', `seal-no-${this.evidenceIdentity?.taskId || this.evidenceIdentity?.inboundId}-${Date.now()}`)
},
async voidEvidencePhoto(photo) {
if (!this.requireEvidenceStage()) return
if (!photo?.id || !this.currentBox.inboundId) return
if (!photo?.id || !this.evidenceIdentity?.inboundId) return
const contextId = this.evidenceContextId
const inboundId = this.currentBox.inboundId
const identity = { ...this.evidenceIdentity }
const inboundId = identity.inboundId
const tenantId = this.currentBox.tenantId
const reason = 'PDA现场标记错图'
try {
await voidEvidence(inboundId, photo.id, { expectedVersion: photo.version || 0, reason, operationId: `void-${inboundId}-${photo.id}-${photo.version || 0}` }, tenantId)
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.evidenceFiles = { ...this.evidenceFiles, [photo.evidenceType]: (this.evidenceFiles[photo.evidenceType] || []).map((item) => item.id === photo.id ? { ...item, status: 'VOID', voidReason: reason } : item) }
this.showToast('照片已作废,可重新拍摄', 'success')
} catch (error) {
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.remoteError = error.network ? '网络失败,照片未作废,请重试' : (error.message || '照片作废失败')
this.showToast('照片作废失败', 'error')
}
},
async completeLoadingTask() {
if (!this.requireEvidenceStage()) return
if (!isRemoteReady(this.currentBox.inboundId)) { this.showToast('装柜任务尚未同步,请刷新后重试', 'warning'); return }
if (!this.evidenceIdentity?.inboundId || !isRemoteReady(this.evidenceIdentity.inboundId)) { this.showToast('装柜任务尚未同步,请刷新后重试', 'warning'); return }
if (this.loadingVersion === null) { this.showToast(VERSION_SYNC_MESSAGE, 'warning'); return }
if (!this.evidenceComplete) { this.showToast('五类有效照片和封签号均为必填', 'warning'); return }
const contextId = this.evidenceContextId
const inboundId = this.currentBox.inboundId
const identity = { ...this.evidenceIdentity }
const inboundId = identity.inboundId
const tenantId = this.currentBox.tenantId
const loadingVersion = this.loadingVersion
this.submitting = true
try {
await completeLoading(inboundId, { expectedVersion: loadingVersion, remark: 'PDA确认装柜完成' }, tenantId)
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.showToast('已确认装柜完成', 'success')
} catch (error) {
if (!this.isEvidenceContextActive(contextId, inboundId)) return
if (!this.isEvidenceContextActive(contextId, identity)) return
this.remoteError = error.network ? '网络失败,装柜完成未提交' : (error.message || '装柜完成失败')
this.showToast('装柜完成失败', 'error')
}
finally {
if (this.isEvidenceContextActive(contextId, inboundId)) this.submitting = false
if (this.isEvidenceContextActive(contextId, identity)) this.submitting = false
}
},
pickScannedBox(item, boxCode) {
@@ -1156,7 +1167,7 @@
item.finalPartialQuantity = this.partialQuantities[item.id] || 0
})
this.completedBoxes = { ...this.completedBoxes, [this.currentBoxIndex]: true }
this.loadLoadingEvidence()
if (this.loadingStageReady) this.loadLoadingEvidence()
this.saveCurrentBoxDraft()
if (remoteRequired) clearPickingDraft(this.draftIdentity())
this.submitId = ''