This commit is contained in:
2026-08-27 11:08:03 +08:00
parent 506d310211
commit 82f0479928
7 changed files with 136 additions and 24 deletions
@@ -59,6 +59,8 @@ const previewResultId = ref('')
const previewSnapshot = ref<WeightResultResource | null>(null)
const weightDrafts = ref<Record<string, { value: number | null; unit: 'KG' | 'LB'; reason: string }>>({})
let loadSequence = 0
let palletLoadSequence = 0
let palletAbortController: AbortController | null = null
const editableStatuses = new Set(['WAIT_MEASURE', 'MEASURING', 'MEASURE_REJECTED'])
const minimumWeight = { KG: 0.001, LB: 0.002 } as const
@@ -68,6 +70,18 @@ const canEdit = computed(() => access.can('platform:firstleg:inbound:weight:edit
const canConfirm = computed(() => access.can('platform:firstleg:inbound:weight:confirm'))
const canView = computed(() => access.can('platform:firstleg:inbound:measure:view'))
const editable = computed(() => Boolean(workspace.value && editableStatuses.has(workspace.value.processStatus)))
const canLoadPalletOptions = computed(() => Boolean(
!props.reviewMode
&& customerId.value
&& props.inboundId
&& canView.value
&& canEdit.value
&& editable.value,
))
const virtualPalletOptions = computed(() => palletOptions.value.map((option) => ({
label: palletOptionLabel(option),
value: option.palletId,
})))
const reviewCorrectionEnabled = computed(() => Boolean(
props.reviewMode
&& props.correctionMode
@@ -212,32 +226,44 @@ async function loadWorkspace() {
}
async function loadPalletOptions() {
if (props.reviewMode) {
if (!canLoadPalletOptions.value) {
cancelPalletOptionsLoad()
palletOptions.value = []
selectedPalletId.value = ''
palletError.value = null
return
}
if (!customerId.value || !props.inboundId || !canView.value) {
palletOptions.value = []
selectedPalletId.value = ''
return
}
cancelPalletOptionsLoad()
const sequence = ++palletLoadSequence
const controller = new AbortController()
palletAbortController = controller
palletLoading.value = true
palletError.value = null
try {
const result = await getWeightPalletOptions(customerId.value, props.inboundId)
const result = await getWeightPalletOptions(customerId.value, props.inboundId, controller.signal)
if (sequence !== palletLoadSequence || controller.signal.aborted) return
palletOptions.value = result
if (!result.some((option) => option.palletId === selectedPalletId.value)) selectedPalletId.value = ''
} catch (error) {
if (sequence !== palletLoadSequence || controller.signal.aborted) return
palletOptions.value = []
selectedPalletId.value = ''
palletError.value = getApiErrorDetails(error, '可选托盘加载失败,请稍后重试')
} finally {
palletLoading.value = false
if (sequence === palletLoadSequence) {
palletLoading.value = false
if (palletAbortController === controller) palletAbortController = null
}
}
}
function cancelPalletOptionsLoad() {
++palletLoadSequence
palletAbortController?.abort()
palletAbortController = null
palletLoading.value = false
}
function chooseFile() {
if (!editable.value) {
ElMessage.warning('当前入库状态不允许上传称重图片')
@@ -397,17 +423,32 @@ watch(
previewOpen.value = false
releasePreview()
void loadWorkspace()
void loadPalletOptions()
},
{ immediate: true },
)
watch(
() => [customerId.value, props.inboundId, canLoadPalletOptions.value] as const,
() => {
cancelPalletOptionsLoad()
palletOptions.value = []
selectedPalletId.value = ''
palletError.value = null
if (canLoadPalletOptions.value) void loadPalletOptions()
},
)
watch(previewOpen, (open) => {
if (!open) {
releasePreview()
}
})
onBeforeUnmount(releasePreview)
onBeforeUnmount(() => {
cancelPalletOptionsLoad()
palletOptions.value = []
selectedPalletId.value = ''
releasePreview()
})
defineExpose({ reload: loadWorkspace })
</script>
@@ -424,22 +465,16 @@ defineExpose({ reload: loadWorkspace })
<div class="weight-summary"><span>货物重量</span><strong>{{ formatWeight(workspace.actualNetWeightKg) }}</strong></div>
</div>
<div class="pallet-picker">
<el-select
v-if="!reviewMode"
<el-select-v2
v-if="canEdit && !reviewMode"
v-model="selectedPalletId"
:options="virtualPalletOptions"
aria-label="选择称重托盘"
placeholder="选择称重托盘"
filterable
:loading="palletLoading"
:disabled="loading || uploading || !editable || !canEdit || Boolean(palletError)"
>
<el-option
v-for="option in palletOptions"
:key="option.palletId"
:label="palletOptionLabel(option)"
:value="option.palletId"
/>
</el-select>
/>
</div>
<input
v-if="!reviewMode"