front/src/views/operation/inboundScan/index.vue
zzh 3ce8955472
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m11s
feat: 经营地图放大下钻与中美口岸标注,并完善扫码/品牌/培训
地图支持全屏漫游、美国邮编港口与中国城市口岸图层;同步入出库扫码与培训手册等改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 13:55:47 +08:00

577 lines
19 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="ops-page">
<div class="ops-col ops-col--main">
<section class="ops-card ops-card--scan">
<div class="ops-card__body ops-scan">
<div class="ops-scan__row">
<a-input
ref="scanInputRef"
v-model="formData.waybillNumber"
:placeholder="$t('operation.inbound.form.placeholder.scanOrInput')"
class="ops-scan-input"
allow-clear
@press-enter="withImeEnterGuard(onScanEnter, $event)"
@clear="clearLookup"
/>
</div>
<div class="ops-scan__row ops-scan__row--tools">
<div class="ops-scan__opts">
<a-select
v-model="numberType"
class="ops-type-select"
:placeholder="$t('operation.printLabel.form.placeholder.numberType')"
>
<a-option v-for="item in numberTypeOptions" :key="item.value" :value="item.value">
{{ item.label }}
</a-option>
</a-select>
<a-checkbox v-model="keepScanFocus" class="ops-opt">
{{ $t('operation.common.keepScanFocus') }}
</a-checkbox>
<a-checkbox v-model="voiceEnabled" class="ops-opt">
{{ $t('operation.common.voiceBroadcast') }}
</a-checkbox>
</div>
<div class="ops-scan__actions">
<a-button class="ops-btn ops-btn--ghost" @click="handleReset()">
{{ $t('operation.inbound.actions.reset') }}
</a-button>
<a-button
type="primary"
class="ops-btn ops-btn--primary"
:loading="submitting || lookingUp"
@click="handleSubmit()"
>
{{ $t('operation.inbound.actions.inbound') }}
</a-button>
</div>
</div>
<p class="ops-scan-hint">{{ $t('operation.inbound.form.hint.supportedTypes') }}</p>
</div>
</section>
<section class="ops-card ops-card--verify">
<div class="ops-card__body ops-verify">
<p
v-if="feedbackMessage"
class="ops-feedback"
:class="`is-${feedbackType}`"
>
{{ feedbackMessage }}
</p>
<a-spin :loading="lookingUp" class="ops-verify-spin">
<div v-if="candidates.length" class="ops-candidates">
<a-alert type="warning" show-icon>
{{ $t('operation.printLabel.preview.multiMatch') }}
</a-alert>
<button
v-for="c in candidates"
:key="c.orderId"
type="button"
class="ops-candidate"
@click="selectCandidate(c)"
>
<div>
<strong>{{ c.serviceNo || c.clientNo || `#${c.orderId}` }}</strong>
<p>{{ c.clientNo || '-' }} · {{ c.trackNo || '-' }} · {{ c.orderStatusName || '-' }}</p>
</div>
</button>
</div>
<div v-else-if="formData.orderId" class="ops-panel">
<div class="ops-hero">
<div class="ops-hero__nos">
<div class="ops-hero__waybill">{{ lookedUpServiceNo || formData.waybillNumber || '-' }}</div>
<div class="ops-hero__meta">
<span>{{ $t('operation.inbound.form.salesProduct') }} {{ formData.salesProductName || '-' }}</span>
<span>{{ $t('operation.inbound.form.destinationCountry') }} {{ formData.destinationCountryName || '-' }}</span>
</div>
</div>
</div>
<div class="ops-metrics">
<div class="ops-metric">
<label class="ops-metric__label">{{ $t('operation.inbound.form.receivedWeight') }}</label>
<div class="ops-metric__weight">
<a-input
v-model="formData.weight"
:placeholder="$t('operation.inbound.form.placeholder.input')"
class="ops-field"
@press-enter="handleSubmit"
/>
<span class="ops-unit">KG</span>
</div>
</div>
<div class="ops-metric ops-metric--dims">
<label class="ops-metric__label">{{ $t('operation.inbound.form.dimensions') }}</label>
<div class="ops-dims">
<a-input
v-model="formData.length"
:placeholder="$t('operation.inbound.form.placeholder.length')"
class="ops-field ops-field--dim"
@press-enter="handleSubmit"
/>
<span class="ops-dims__x">×</span>
<a-input
v-model="formData.width"
:placeholder="$t('operation.inbound.form.placeholder.width')"
class="ops-field ops-field--dim"
@press-enter="handleSubmit"
/>
<span class="ops-dims__x">×</span>
<a-input
v-model="formData.height"
:placeholder="$t('operation.inbound.form.placeholder.height')"
class="ops-field ops-field--dim"
@press-enter="handleSubmit"
/>
</div>
</div>
</div>
</div>
<div v-else class="ops-empty">
<p class="ops-empty__title">{{ $t('operation.inbound.preview.empty') }}</p>
<p class="ops-empty__tip">{{ $t('operation.inbound.tip') }}</p>
</div>
</a-spin>
</div>
</section>
</div>
<aside class="ops-card ops-card--recent-wide">
<div class="ops-list-toolbar">
<div />
<PaginationPro
:total-count="totalCount"
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:page-sizes="[10, 30, 50, 100]"
@page-change="handlePageChange"
@page-size-change="handlePageSizeChange"
/>
</div>
<div ref="tableContainerRef" class="ops-list-wrap">
<HandsontablePro
:columns="hotColumns"
:data="pagedOrders"
:total="totalCount"
:current-page="currentPage"
:page-size="pageSize"
:height="tableHeight"
:loading="listLoading"
:read-only="true"
:stretch-columns="true"
:search-params="headerSearchParams"
@search="handleHeaderSearch"
/>
</div>
</aside>
</div>
</template>
<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
import { ref, reactive, computed, watch, onMounted, onBeforeUnmount } from 'vue'
import HandsontablePro from '@/components/HandsontablePro/index.vue'
import PaginationPro from '@/components/PaginationPro/index.vue'
import { useTableContainerHeight } from '@/composables/useTableContainerHeight'
import { useOperationScanFocus } from '@/composables/useOperationScanFocus'
import { useOperationScanFeedback } from '@/composables/useOperationScanFeedback'
import { useOpsScanNumberType } from '@/composables/useOpsScanNumberType'
import { withImeEnterGuard } from '@/utils/keyboard'
import {
inboundCreate,
inboundRecentList,
inboundOrderLookup,
type OpsScanCandidate,
} from '@/api/operation'
import { buildStatusTagHtml } from '@/utils/statusTag'
import { withServerFilterColumns } from '@/utils/headerFilterAdapter'
import { applyScanExtract, ensureScanExtractBundle } from '@/utils/scanExtract'
const { t } = useI18n()
const { tableContainerRef, tableHeight } = useTableContainerHeight()
const scanInputRef = ref<{ focus?: () => void } | null>(null)
const { keepScanFocus, maybeRefocusScan } = useOperationScanFocus('inboundScan', scanInputRef)
const {
voiceEnabled,
feedbackType,
feedbackMessage,
clearFeedback,
showRequestError,
showSuccess,
showWarning,
} = useOperationScanFeedback('inboundScan')
const { numberType, numberTypeOptions } = useOpsScanNumberType('inboundScan')
defineOptions({ name: 'InboundScan' })
type RecentRow = {
key: string
waybillNumber: string
weight: string
dimensions: string
product: string
country: string
warehouse: string
operateTime: string
operator: string
orderId?: number
orderStatus?: string
orderStatusName?: string
allocationPendingReason?: string
}
const submitting = ref(false)
const lookingUp = ref(false)
const listLoading = ref(false)
const currentPage = ref(1)
const pageSize = ref(50)
const headerSearchParams = reactive<Record<string, string>>({})
const NUMBER_FILTER_KEYS = ['waybillNumber'] as const
let softPollTimer: ReturnType<typeof setInterval> | null = null
let softPollUntil = 0
const formData = reactive({
waybillNumber: '',
weight: '',
length: '',
width: '',
height: '',
salesProductName: '',
destinationCountryName: '',
orderId: undefined as number | undefined,
})
const recentOrders = ref<RecentRow[]>([])
const filteredOrders = computed(() => {
const waybill = String(headerSearchParams.waybillNumber || '')
.trim()
.toLowerCase()
if (!waybill) return recentOrders.value
return recentOrders.value.filter((row) =>
String(row.waybillNumber || '')
.toLowerCase()
.includes(waybill),
)
})
const totalCount = computed(() => filteredOrders.value.length)
const pagedOrders = computed(() => {
const start = (currentPage.value - 1) * pageSize.value
return filteredOrders.value.slice(start, start + pageSize.value)
})
const hotColumns = computed(() =>
withServerFilterColumns(
[
{ key: 'waybillNumber', label: t('operation.inbound.table.waybillNumber'), width: 160 },
{ key: 'weight', label: t('operation.inbound.table.weight'), width: 80 },
{ key: 'dimensions', label: t('operation.inbound.table.dimensions'), width: 120 },
{ key: 'product', label: t('operation.inbound.table.product'), width: 140 },
{ key: 'country', label: t('operation.inbound.table.destCountry'), width: 100 },
{
key: 'orderStatusName',
label: t('operation.inbound.table.orderStatus'),
width: 110,
renderer: (row: RecentRow) => {
const text = row.orderStatusName || row.orderStatus || '-'
return buildStatusTagHtml(text, statusTone(row.orderStatus))
},
},
{ key: 'allocationPendingReason', label: t('operation.inbound.table.reason'), width: 160 },
{ key: 'operateTime', label: t('operation.inbound.table.operateTime'), width: 160 },
],
NUMBER_FILTER_KEYS,
),
)
function statusTone(status?: string) {
switch (status) {
case 'pendingAllocation':
return 'wait'
case 'pendingPayment':
return 'alert'
default:
return 'neutral'
}
}
function mapRecentRow(row: any, idx: number): RecentRow {
const orderId = row.orderId ?? row.OrderId
const orderStatus = row.orderStatus ?? row.OrderStatus ?? ''
const reason = row.allocationPendingReason ?? row.AllocationPendingReason ?? ''
return {
key: String(row.id ?? row.Id ?? `${row.waybillNo ?? ''}-${idx}`),
waybillNumber: row.waybillNo ?? row.waybillNumber ?? '',
weight: row.weight != null ? String(row.weight) : '-',
dimensions:
row.length != null && row.width != null && row.height != null
? `${row.length}×${row.width}×${row.height}`
: '-',
product: row.salesProductName ?? '-',
country: row.destinationCountry ?? '-',
warehouse: row.warehouseName ?? '-',
operateTime: row.operateTime ?? row.createTime ?? '',
operator: row.operatorName ?? row.operator ?? '-',
orderId: orderId != null ? Number(orderId) : undefined,
orderStatus,
orderStatusName: row.orderStatusName ?? row.OrderStatusName ?? '',
allocationPendingReason: typeof reason === 'string' ? reason.trim() : '',
}
}
function stopSoftPoll() {
if (softPollTimer) {
clearInterval(softPollTimer)
softPollTimer = null
}
softPollUntil = 0
}
function startSoftPoll() {
softPollUntil = Date.now() + 20_000
if (softPollTimer) return
softPollTimer = setInterval(async () => {
if (Date.now() > softPollUntil) {
stopSoftPoll()
return
}
await loadRecent(false)
const stillPending = recentOrders.value.some((r) => r.orderStatus === 'pendingAllocation')
if (!stillPending) stopSoftPoll()
}, 3000)
}
async function loadRecent(showLoadError = true) {
listLoading.value = true
try {
const { items } = await inboundRecentList({ limit: 100 })
recentOrders.value = (items || []).map((row: any, idx: number) => mapRecentRow(row, idx))
const maxPage = Math.max(1, Math.ceil(filteredOrders.value.length / pageSize.value) || 1)
if (currentPage.value > maxPage) currentPage.value = maxPage
} catch (e: any) {
if (showLoadError) {
showRequestError(e, t('operation.inbound.message.loadRecentFailed'))
recentOrders.value = []
}
} finally {
listLoading.value = false
}
}
function handleHeaderSearch() {
currentPage.value = 1
}
function handlePageChange(page: number) {
currentPage.value = page
}
function handlePageSizeChange(size: number) {
pageSize.value = size
currentPage.value = 1
}
const lookedUpWaybillNo = ref('')
const lookedUpServiceNo = ref('')
const lookedUpNumberType = ref('auto')
const candidates = ref<OpsScanCandidate[]>([])
function clearLookupFields() {
formData.salesProductName = ''
formData.destinationCountryName = ''
formData.orderId = undefined
formData.weight = ''
formData.length = ''
formData.width = ''
formData.height = ''
lookedUpWaybillNo.value = ''
lookedUpServiceNo.value = ''
lookedUpNumberType.value = numberType.value
candidates.value = []
}
function clearLookup() {
clearLookupFields()
clearFeedback()
}
function hasMetrics() {
return !!(formData.weight && formData.length && formData.width && formData.height)
}
function applyLookupHit(info: Awaited<ReturnType<typeof inboundOrderLookup>>, scanNo: string) {
formData.orderId = info.orderId
formData.salesProductName = info.salesProductName || info.productCode || ''
formData.destinationCountryName =
info.destinationCountryName || info.destinationCountry || ''
lookedUpWaybillNo.value = scanNo
lookedUpServiceNo.value = info.serviceNo || scanNo
lookedUpNumberType.value = numberType.value
candidates.value = []
}
/** 扫码后静默查单;不弹「匹配成功」,失败才提示 */
async function ensureOrderLookup(): Promise<boolean> {
const no = formData.waybillNumber?.trim()
if (!no) {
clearLookup()
return false
}
if (
formData.orderId &&
lookedUpWaybillNo.value === no &&
lookedUpNumberType.value === numberType.value
) {
return true
}
lookingUp.value = true
try {
const info = await inboundOrderLookup(no, numberType.value)
if (info?.candidates?.length && info.matched === false) {
formData.orderId = undefined
formData.salesProductName = ''
formData.destinationCountryName = ''
lookedUpWaybillNo.value = no
lookedUpServiceNo.value = ''
lookedUpNumberType.value = numberType.value
candidates.value = info.candidates
showWarning(t('operation.printLabel.preview.multiMatch'))
return false
}
if (!info?.orderId) {
throw new Error(t('operation.common.message.orderNotFound'))
}
applyLookupHit(info, no)
return true
} catch (e: any) {
formData.salesProductName = ''
formData.destinationCountryName = ''
formData.orderId = undefined
lookedUpWaybillNo.value = ''
lookedUpServiceNo.value = ''
candidates.value = []
showRequestError(e, t('operation.common.message.orderNotFound'))
maybeRefocusScan()
return false
} finally {
lookingUp.value = false
}
}
async function selectCandidate(c: OpsScanCandidate) {
const serviceNo = String(c.serviceNo || '').trim()
if (!serviceNo) {
showWarning(t('operation.common.message.orderNotFound'))
return
}
formData.waybillNumber = serviceNo
numberType.value = 'waybill'
candidates.value = []
await ensureOrderLookup()
}
async function onScanEnter() {
formData.waybillNumber = applyScanExtract(formData.waybillNumber)
const ok = await ensureOrderLookup()
if (!ok) return
if (hasMetrics()) {
await handleSubmit()
return
}
clearFeedback()
}
function buildSuccessMessage(result: any) {
const status = result?.orderStatus ?? result?.OrderStatus
const statusName = result?.orderStatusName ?? result?.OrderStatusName
if (status === 'pendingAllocation') {
return t('operation.inbound.message.inboundProcessing')
}
if (statusName) {
return t('operation.inbound.message.inboundSuccessWithStatus', { status: statusName })
}
return t('operation.inbound.message.inboundProcessing')
}
async function handleSubmit() {
if (!formData.waybillNumber?.trim()) {
showWarning(t('operation.inbound.message.waybillNumberRequired'))
maybeRefocusScan()
return
}
const ok = await ensureOrderLookup()
if (!ok) return
if (!hasMetrics()) {
showWarning(t('operation.inbound.message.metricsRequired'))
return
}
submitting.value = true
try {
const result = await inboundCreate({
waybillNo: lookedUpServiceNo.value || formData.waybillNumber.trim(),
numberType: lookedUpServiceNo.value ? 'waybill' : numberType.value,
weight: Number(formData.weight),
length: Number(formData.length),
width: Number(formData.width),
height: Number(formData.height),
})
showSuccess(buildSuccessMessage(result))
handleReset(false)
await loadRecent()
const status = result?.orderStatus ?? result?.OrderStatus
if (status === 'pendingAllocation') {
startSoftPoll()
}
maybeRefocusScan()
} catch (e: any) {
showRequestError(e, t('operation.inbound.message.inboundFailed'))
maybeRefocusScan()
} finally {
submitting.value = false
}
}
watch(
() => formData.waybillNumber,
(value) => {
const no = String(value || '').trim()
if (!no || no !== lookedUpWaybillNo.value) {
formData.orderId = undefined
formData.salesProductName = ''
formData.destinationCountryName = ''
lookedUpWaybillNo.value = ''
lookedUpServiceNo.value = ''
candidates.value = []
}
},
)
watch(numberType, () => {
formData.orderId = undefined
lookedUpWaybillNo.value = ''
lookedUpServiceNo.value = ''
candidates.value = []
})
function handleReset(clearStatus = true) {
formData.waybillNumber = ''
clearLookupFields()
if (clearStatus) clearFeedback()
maybeRefocusScan()
}
onMounted(() => {
void ensureScanExtractBundle()
loadRecent()
})
onBeforeUnmount(() => {
stopSoftPoll()
})
</script>
<style lang="less" scoped>
@import '@/views/operation/styles/ops-scan-page.less';
</style>