This commit is contained in:
2026-10-20 11:34:58 +08:00
parent 53cb68a8bc
commit 8cce909c78
3 changed files with 67 additions and 5 deletions
@@ -116,7 +116,7 @@
assignableCurrentPallet() { return this.currentPallet?.status === 'OPEN' ? this.currentPallet : null }
},
onLoad(options) { this.taskId = String(options.taskId || ''); this.warehouseId = String(options.warehouseId || ''); this.initialPalletNo = String(options.palletNo || '') },
onShow() { if (!requireSession()) return; this.user = session.currentUser; const draft = restoreDropshipPalletizingDraft(this.draftIdentity()); this.selectedPalletNo = this.initialPalletNo || draft?.activePalletNo || ''; this.initialPalletNo = ''; this.startScanner(); this.loadTask() },
onShow() { if (!requireSession()) return; this.user = session.currentUser; const draft = restoreDropshipPalletizingDraft(this.draftIdentity()); this.selectedPalletNo = this.initialPalletNo || draft?.activePalletNo || ''; this.initialPalletNo = ''; this.startScanner(); this.loadTask({ restorePallet: true }) },
onHide() { this.stopScanner() }, onUnload() { this.stopScanner() }, beforeUnmount() { this.stopScanner() },
onBackPress() { if (!this.unsealOpen) return false; this.closeUnseal(); return true },
methods: {
@@ -124,10 +124,10 @@
stopScanner() { if (this._stopScanner) this._stopScanner(); this._stopScanner = null },
handleScan(value) { if (this.loading || this.submitting) return; if (!this.palletSetupReady) { this.error = this.palletSetupMessage; return } const plan = planDropshipScan(createDropshipScanState({ online: isOnline() }), value, { unboundCartons: this.task?.unboundCartons }); if ([DROPSHIP_SCAN_INTENT.BLOCKED, DROPSHIP_SCAN_INTENT.INVALID].includes(plan.intent)) { this.error = plan.message; return } const code = plan.palletNo || plan.boxCode; if (plan.palletNo) { this.palletCode = code; this.selectPallet(code) } else { this.boxCode = code; this.resolveCarton() } },
resetMessages() { this.error = ''; this.notice = '' },
async loadTask() {
async loadTask({ restorePallet = false } = {}) {
if (!this.taskId || !this.warehouseId) { this.error = '缺少合托任务或仓库信息,请返回任务列表'; return }
this.loading = true; this.resetMessages()
try { this.task = await getDropshipPalletizationTask(this.taskId, this.warehouseId); await this.refreshPallet(); if (this.task.taskStatus === 'COMPLETED') clearDropshipPalletizingDraft(this.draftIdentity()) }
try { this.task = await getDropshipPalletizationTask(this.taskId, this.warehouseId); await this.refreshPallet({ restorePallet }); if (this.task.taskStatus === 'COMPLETED') clearDropshipPalletizingDraft(this.draftIdentity()) }
catch (error) { this.error = formatApiError(error, '一件代发入库任务加载失败') }
finally { this.loading = false }
},
@@ -175,7 +175,18 @@
if (Number(this.task?.unboundCartons || 0) > 0) await this.runMutation(() => bindDropshipPendingCartons(this.taskId, this.warehouseId, code, this.task.version), `待归托箱已绑定至 ${code}`)
else this.notice = `已选择仓库开放托盘 ${code},可连续扫描不同客户的箱码`
},
async refreshPallet() { if (!this.selectedPalletNo) { this.workspace = null; return }; this.workspace = null; this.workspace = await resolveDropshipWorkspacePallet(this.warehouseId, this.selectedPalletNo) },
// 页面恢复只延续开放托盘;主动扫码和刚封托后的回查仍保留真实封托结果。
async refreshPallet({ restorePallet = false } = {}) {
this.workspace = null
if (!this.selectedPalletNo) return
const workspace = await resolveDropshipWorkspacePallet(this.warehouseId, this.selectedPalletNo)
if (restorePallet && workspace.pallet.status !== 'OPEN') {
this.selectedPalletNo = ''; this.selectedPalletId = ''; this.palletCode = ''
clearDropshipPalletizingDraft(this.draftIdentity())
return
}
this.workspace = workspace
},
memberForCarton(carton) { return this.palletMembers.find((member) => String(member.inboundId) === String(carton.inboundId)) },
async activateScanTask() {
const targetId = String(this.scanTask?.taskId || this.taskId)
+6 -1
View File
@@ -33,7 +33,7 @@
<script>
import PortalHeader from '@/components/PortalHeader.vue'
import ScanTargetInput from '@/components/ScanTargetInput.vue'
import { listDropshipPalletizationTasks } from '@/api/pda-dropship.js'
import { listDropshipPalletizationTasks, resolveDropshipWorkspacePallet } from '@/api/pda-dropship.js'
import { session, requireSession } from '@/stores/session.js'
import { formatApiError } from '@/utils/user-facing.js'
@@ -50,6 +50,11 @@
if (!this.user?.warehouseId) { this.error = '请返回首页选择作业仓库'; return }
this.loading = true; this.error = ''
try {
// 返回列表时重查跨票续装目标,已封托盘不再传入其他任务。
if (this.palletNo) {
const workspace = await resolveDropshipWorkspacePallet(this.user.warehouseId, this.palletNo)
if (workspace.pallet.status !== 'OPEN') this.palletNo = ''
}
const records = await listDropshipPalletizationTasks(this.keyword, this.user.warehouseId)
this.tasks = Array.isArray(records) ? records : []
}
+46
View File
@@ -70,3 +70,49 @@ test('switching tickets carries only validated open pallet and scanner cannot ra
await state.selectPallet('DP-261019-0002')
assert.equal(state.currentPallet.palletNo, pallet.palletNo)
})
test('reopening a task drops a pallet sealed since the draft was saved without mutating business facts', async () => {
const cleared = []
const { state, pallet, calls } = harness({ clearDropshipPalletizingDraft: (identity) => cleared.push(identity) })
pallet.status = 'SEALED'
state.selectedPalletNo = pallet.palletNo; state.palletCode = pallet.palletNo; state.selectedPalletId = pallet.palletId
await state.loadTask({ restorePallet: true })
assert.equal(state.currentPallet, null)
assert.equal(state.selectedPalletNo, '')
assert.equal(state.selectedPalletId, '')
assert.equal(state.palletCode, '')
assert.equal(cleared.length, 1)
assert.equal(cleared[0].taskId, '10')
assert.deepEqual(calls.map(call => call[0]), ['get'])
})
test('restoring open cross customer pallet still works and explicit sealed scan remains inspectable', async () => {
const { state, pallet } = harness()
state.selectedPalletNo = pallet.palletNo
await state.loadTask({ restorePallet: true })
assert.equal(state.currentPallet.palletNo, pallet.palletNo)
pallet.status = 'SEALED'
await state.selectPallet(pallet.palletNo)
assert.equal(state.currentPallet.status, 'SEALED')
assert.equal(state.canSubmitCarton, false)
})
test('task list stops carrying a pallet sealed while another ticket was being worked', async () => {
const taskSource = await readFile(new URL('../pages/dropship-tasks/dropship-tasks.vue', import.meta.url), 'utf8')
const taskScript = taskSource.match(/<script>([\s\S]*?)<\/script>/)[1].replace(/^\s*import .*$/gm, '').replace('export default', 'globalThis.page =')
let status = 'OPEN'
const navigations = []
const context = { PortalHeader: {}, ScanTargetInput: {}, session: { currentUser: { warehouseId: '100' } },
resolveDropshipWorkspacePallet: async () => ({ pallet: { status } }),
listDropshipPalletizationTasks: async () => [], formatApiError: error => error.message,
uni: { navigateTo: value => navigations.push(value.url) } }
vm.runInNewContext(taskScript, context)
const state = Object.assign(context.page.data(), context.page.methods, { palletNo: 'DP-261019-0014' })
const task = { taskId: '20', warehouseId: '100' }
await state.loadTasks(); state.openTask(task)
assert.match(navigations[0], /palletNo=DP-261019-0014/)
status = 'SEALED'
await state.loadTasks(); state.openTask(task)
assert.equal(state.palletNo, '')
assert.ok(!navigations[1].includes('DP-261019-0014'))
})