整批提交原子性的方案
This commit is contained in:
+53
-13
@@ -38,7 +38,7 @@
|
||||
<view v-if="activeStage === 'picking'" class="picking-stage">
|
||||
<view class="scan-section">
|
||||
<view class="scan-row">
|
||||
<ScanTargetInput v-model="scanValue" name="boxCode" label="箱码扫码框" placeholder="扫描或输入箱唛标签码" :active="activeScanField === 'boxCode'" @activate="setScanTarget" @submit="handleManualSubmit" />
|
||||
<ScanTargetInput v-model="scanValue" name="boxCode" :label="scanInputLabel" :placeholder="scanPlaceholder" :active="activeScanField === 'boxCode'" @activate="setScanTarget" @submit="handleManualSubmit" />
|
||||
</view>
|
||||
<view v-if="lastScanResult" class="last-scan" :class="lastScanResult.type" role="status">
|
||||
<view class="last-scan-icon">{{ lastScanResult.type === 'success' ? '✓' : '!' }}</view>
|
||||
@@ -78,7 +78,7 @@
|
||||
:class="itemState(item)"
|
||||
>
|
||||
<view class="pick-item-row1">
|
||||
<text class="pick-item-sku">拣货明细</text>
|
||||
<text class="pick-item-sku">{{ isSealedPalletItem(item) ? '整托拣货' : '拣货明细' }}</text>
|
||||
<view class="pick-item-meta">
|
||||
<text v-if="itemState(item) === ITEM_STATUS.PICKED" class="pick-status-tag tag-picked">已拣 ✓</text>
|
||||
<text v-else-if="itemState(item) === ITEM_STATUS.PARTIAL" class="pick-status-tag tag-partial">
|
||||
@@ -98,7 +98,10 @@
|
||||
<text v-if="item.location" class="pick-item-location">{{ item.location }}</text>
|
||||
</view>
|
||||
|
||||
<view v-if="itemState(item) === ITEM_STATUS.PENDING" class="pick-item-actions">
|
||||
<view v-if="itemState(item) === ITEM_STATUS.PENDING && isSealedPalletItem(item)" class="pick-item-actions">
|
||||
<text class="version-hint">扫描托盘码 {{ item.palletNo }} 或托内任一箱码,确认整托装柜</text>
|
||||
</view>
|
||||
<view v-else-if="itemState(item) === ITEM_STATUS.PENDING" class="pick-item-actions">
|
||||
<button class="pick-btn pick-btn-confirm" @tap="pickItem(item.id)">确认拣出</button>
|
||||
<button class="pick-btn pick-btn-partial" @tap="openPartial(item.id)">部分拣货</button>
|
||||
<button class="pick-btn pick-btn-skip" @tap="openSkip(item.id)">跳拣</button>
|
||||
@@ -333,7 +336,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ITEM_STATUS, classifyScan, createItemStates, getPickSummary, submitStates } from '@/utils/picking-state.js'
|
||||
import { ITEM_STATUS, classifyScan, createItemStates, getPickSummary, isSealedPalletItem, submitStates } from '@/utils/picking-state.js'
|
||||
import { SKIP_REASONS, INCOMPLETE_REASONS } from '@/data/demo-data.js'
|
||||
import { session, requireSession } from '@/stores/session.js'
|
||||
import { clearLoadingCompletionAttempt, clearPickingDraft, getPickingSession, restoreLoadingCompletionAttempt, restorePickingSession, saveLoadingCompletionAttempt, savePickingSession } from '@/stores/picking.js'
|
||||
@@ -413,6 +416,12 @@
|
||||
pendingItems() {
|
||||
return this.currentBox.items.filter((item) => this.itemState(item) === ITEM_STATUS.PENDING)
|
||||
},
|
||||
scanInputLabel() {
|
||||
return this.pendingItems.some((item) => isSealedPalletItem(item)) ? '托盘码或托内箱码扫码框' : '箱码扫码框'
|
||||
},
|
||||
scanPlaceholder() {
|
||||
return this.pendingItems.some((item) => isSealedPalletItem(item)) ? '扫描托盘码或托内任一箱码' : '扫描或输入箱唛标签码'
|
||||
},
|
||||
lastScanResult() {
|
||||
return this.scanHistory[0] || null
|
||||
},
|
||||
@@ -808,11 +817,15 @@
|
||||
const restored = restorePickingSession(this.draftIdentity())
|
||||
if (!restored) return false
|
||||
const itemIds = new Set(this.currentBox.items.map((item) => String(item.id)))
|
||||
const restoredScans = restored.scannedBoxCodes || {}
|
||||
const serverStates = { ...this.itemStates }
|
||||
const serverPartialQuantities = { ...this.partialQuantities }
|
||||
Object.entries(restored.itemStates || {}).forEach(([id, status]) => {
|
||||
if (!itemIds.has(String(id)) || serverStates[id] !== ITEM_STATUS.PENDING || status === ITEM_STATUS.PENDING) return
|
||||
const item = this.currentBox.items.find((entry) => String(entry.id) === String(id))
|
||||
const hasPalletScan = isSealedPalletItem(item) && Object.entries(restoredScans).some(([code, itemId]) =>
|
||||
String(itemId) === String(id) && (code === item?.palletNo || (item?.boxCodes || []).includes(code)))
|
||||
if (isSealedPalletItem(item) && (status !== ITEM_STATUS.PICKED || !hasPalletScan)) return
|
||||
const partial = Number(restored.partialQuantities?.[id] || 0)
|
||||
if (status === ITEM_STATUS.PARTIAL && (!partial || partial >= Number(item?.qty || 0))) return
|
||||
serverStates[id] = status
|
||||
@@ -820,7 +833,11 @@
|
||||
})
|
||||
this.itemStates = serverStates
|
||||
this.partialQuantities = serverPartialQuantities
|
||||
this.scannedBoxCodes = Object.fromEntries(Object.entries(restored.scannedBoxCodes || {}).filter(([, id]) => itemIds.has(String(id))))
|
||||
this.scannedBoxCodes = Object.fromEntries(Object.entries(restoredScans).filter(([code, id]) => {
|
||||
if (!itemIds.has(String(id))) return false
|
||||
const item = this.currentBox.items.find((entry) => String(entry.id) === String(id))
|
||||
return !isSealedPalletItem(item) || code === item.palletNo || (item.boxCodes || []).includes(code)
|
||||
}))
|
||||
this.boxDrafts = restored.boxDrafts || {}
|
||||
this.completedBoxes = restored.completedBoxes || {}
|
||||
if (this.remotePick && !isPickingCompleteTask(this.remotePick)) {
|
||||
@@ -944,6 +961,7 @@
|
||||
itemState(item) {
|
||||
return this.itemStates[item.id] || ITEM_STATUS.PENDING
|
||||
},
|
||||
isSealedPalletItem,
|
||||
hasBoxDraft(index) {
|
||||
const draft = this.boxDrafts[index]
|
||||
return Boolean(draft && Object.values(draft.itemStates).some((status) => status !== ITEM_STATUS.PENDING))
|
||||
@@ -952,7 +970,8 @@
|
||||
const reason = this.itemState(item) === ITEM_STATUS.SKIPPED && item.skipReason
|
||||
? ` · ${item.skipReason}`
|
||||
: ''
|
||||
return `${item.desc}${reason}`
|
||||
const pallet = isSealedPalletItem(item) && item.palletNo ? `${item.palletNo} · ` : ''
|
||||
return `${pallet}${item.desc}${reason}`
|
||||
},
|
||||
processScannedValue(scanValue, source = 'broadcast') {
|
||||
if (!this.requirePickingOperation()) return
|
||||
@@ -972,18 +991,19 @@
|
||||
[ITEM_STATUS.PARTIAL]: '已部分拣货',
|
||||
[ITEM_STATUS.SKIPPED]: '已跳拣'
|
||||
}
|
||||
this.recordScanResult('warning', '重复扫描', value, `该箱码已${labels[result.status]},无需重复处理`)
|
||||
this.showToast(`该箱码已处理:${value}`, 'warning')
|
||||
this.recordScanResult('warning', '重复扫描', value, `该条码已${labels[result.status]},无需重复处理`)
|
||||
this.showToast(`该条码已处理:${value}`, 'warning')
|
||||
return
|
||||
}
|
||||
if (result.type === 'unknown') {
|
||||
playErrorSound()
|
||||
this.recordScanResult('error', '当前任务无此箱码', value, '请核对箱唛标签或转入异常处理')
|
||||
this.showToast(`未找到匹配的待拣箱码:${value}`, 'error')
|
||||
this.recordScanResult('error', '当前任务无此条码', value, '请核对托盘码或箱唛标签')
|
||||
this.showToast(`未找到匹配的待拣条码:${value}`, 'error')
|
||||
return
|
||||
}
|
||||
playSuccessSound()
|
||||
this.pickScannedBox(result.item, value)
|
||||
if (result.type === 'pallet') this.pickScannedPallet(result.item, value)
|
||||
else this.pickScannedBox(result.item, value)
|
||||
},
|
||||
evidenceEntries(type) { return Array.isArray(this.evidenceFiles[type]) ? this.evidenceFiles[type].filter((item) => item.status !== 'VOID' && item.status !== 'VOIDED') : (this.evidenceFiles[type] ? [this.evidenceFiles[type]] : []) },
|
||||
evidencePreviewSource(photo) { return photo?.localPath || photo?.fileUrl || photo?.downloadUrl || photo?.url || '' },
|
||||
@@ -1419,9 +1439,19 @@
|
||||
this.showToast(`已拣箱 ${pickedCount}/${plannedCount}`, 'success')
|
||||
this.persistSession()
|
||||
},
|
||||
pickScannedPallet(item, palletNo) {
|
||||
const plannedCount = Number(item.qty || 0)
|
||||
this.scannedBoxCodes = { ...this.scannedBoxCodes, [item.palletNo]: item.id, [palletNo]: item.id }
|
||||
this.partialQuantities = { ...this.partialQuantities, [item.id]: plannedCount }
|
||||
this.itemStates = { ...this.itemStates, [item.id]: ITEM_STATUS.PICKED }
|
||||
this.recordScanResult('success', '整托扫描成功', palletNo, `已定位托盘 ${item.palletNo} · 共 ${plannedCount} 箱`)
|
||||
this.showToast(`托盘 ${item.palletNo} 已确认装柜`, 'success')
|
||||
this.persistSession()
|
||||
},
|
||||
pickItem(id, source = 'manual') {
|
||||
if (!this.requirePickingOperation()) return
|
||||
const item = this.currentBox.items.find((entry) => entry.id === id)
|
||||
if (isSealedPalletItem(item)) { this.showToast(`已封托货物必须扫描托盘码 ${item.palletNo}`, 'warning'); return }
|
||||
const available = this.availablePickQuantity(item)
|
||||
if (available !== null && available < Number(item.qty || 0)) { this.showToast(`库存/库位可用量不足:可拣 ${available}`, 'error'); return }
|
||||
this.itemStates = { ...this.itemStates, [id]: ITEM_STATUS.PICKED }
|
||||
@@ -1448,6 +1478,8 @@
|
||||
},
|
||||
openSkip(id) {
|
||||
if (!this.requirePickingOperation()) return
|
||||
const item = this.currentBox.items.find((entry) => entry.id === id)
|
||||
if (isSealedPalletItem(item)) { this.showToast(`整托货物不能跳拣,请扫描 ${item.palletNo}`, 'warning'); return }
|
||||
this.skipTargetId = id
|
||||
this.selectedSkipReason = ''
|
||||
this.openOverlay('skip')
|
||||
@@ -1468,6 +1500,8 @@
|
||||
},
|
||||
openPartial(id) {
|
||||
if (!this.requirePickingOperation()) return
|
||||
const item = this.currentBox.items.find((entry) => entry.id === id)
|
||||
if (isSealedPalletItem(item)) { this.showToast(`整托货物不能部分拣货,请扫描 ${item.palletNo}`, 'warning'); return }
|
||||
this.partialTargetId = id
|
||||
this.partialInput = ''
|
||||
this.openOverlay('partial')
|
||||
@@ -1548,6 +1582,12 @@
|
||||
const beforeSubmit = this.summary
|
||||
const remoteRequired = Boolean(session.token)
|
||||
this.remoteError = ''
|
||||
const pendingPallet = this.currentBox.items.find((item) => isSealedPalletItem(item) && this.itemState(item) !== ITEM_STATUS.PICKED)
|
||||
if (pendingPallet) {
|
||||
this.remoteError = `请扫描托盘码 ${pendingPallet.palletNo} 或托内任一箱码后再提交`
|
||||
this.showToast(this.remoteError, 'warning')
|
||||
return
|
||||
}
|
||||
this.debugSubmit('submit.start', { incompleteReason, remoteRequired, remoteReady: isRemoteReady(this.currentBox.inboundId || this.currentBox.boxNo) })
|
||||
if (remoteRequired && !isRemoteReady(this.currentBox.inboundId || this.currentBox.boxNo)) {
|
||||
this.remoteError = '缺少服务端任务信息,未提交拣货完成'
|
||||
@@ -1563,6 +1603,7 @@
|
||||
if (item.itemStatus && !['PENDING', 'PICKING'].includes(item.itemStatus)) return null
|
||||
const status = this.itemState(item)
|
||||
const itemId = item.taskItemId ?? item.remoteItemId ?? item.id
|
||||
if (status === ITEM_STATUS.PICKED && isSealedPalletItem(item)) return { type: 'PICK_PALLET', itemId, palletNo: item.palletNo, version: Number(item.version || 0) }
|
||||
if (status === ITEM_STATUS.PICKED) return { type: 'PICK', itemId, pickedPackageCount: Number(item.qty || 0), locationIds: item.locationIds || [], version: Number(item.version || 0) }
|
||||
if (status === ITEM_STATUS.PARTIAL) return { type: 'PARTIAL', itemId, finalPickedPackageCount: Number(this.partialQuantities[item.id] || 0), locationIds: item.locationIds || [], version: Number(item.version || 0) }
|
||||
if (status === ITEM_STATUS.SKIPPED) return { type: 'SKIP', itemId, reason: item.skipReason || incompleteReason || '现场跳拣', version: Number(item.version || 0) }
|
||||
@@ -1601,9 +1642,8 @@
|
||||
} catch (error) {
|
||||
this.debugSubmit('submit.error', { message: error.message || '', code: error.code || '', statusCode: error.statusCode || '', requestIdFromServer: error.requestId || '', traceId: error.traceId || '', network: Boolean(error.network) })
|
||||
const versionConflict = this.isTaskConflict(error)
|
||||
const inventoryConflict = versionConflict && /库存/.test(error.message || '')
|
||||
const conflictMessage = inventoryConflict ? '库存已变化,请刷新后重试' : '任务版本已变化,请刷新后重试'
|
||||
if (versionConflict) {
|
||||
const conflictMessage = sanitizeUserMessage(error.message, '任务状态已变化,请刷新后重试')
|
||||
await this.refreshAfterTaskConflict(conflictMessage)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user