front/src/views/operation/fulfillPack/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

717 lines
20 KiB
Vue

<script setup lang="ts">
import { ref, computed, onMounted, nextTick } from 'vue'
import { useI18n } from 'vue-i18n'
import { Message, Modal } from '@arco-design/web-vue'
import { extractOmsRequestError } from '@/api/oms/common'
import { IconQuestionCircleFill } from '@arco-design/web-vue/es/icon'
import PaginationPro from '@/components/PaginationPro/index.vue'
import HandsontablePro from '@/components/HandsontablePro/index.vue'
import FulfillBindLookupPanel from '../components/FulfillBindLookupPanel.vue'
import { useTableContainerHeight } from '@/composables/useTableContainerHeight'
import { postOrderList, postOrderStockBindConfirmDeduct } from '@/api/order'
import type { PrintLabelLookupCandidate } from '@/api/operation'
import { getWarehouseList } from '@/api/system/warehouse'
import { buildStatusTagHtml } from '@/utils/statusTag'
import { useCurrentWarehouseStore } from '@/store'
import { useOperationLabelPrint } from '@/composables/useOperationLabelPrint'
import { hasPermission } from '@/utils/rbac-permission'
defineOptions({ name: 'FulfillPack' })
const { t } = useI18n()
const currentWarehouseStore = useCurrentWarehouseStore()
const lookupPanelRef = ref<InstanceType<typeof FulfillBindLookupPanel>>()
const { tableContainerRef, tableHeight } = useTableContainerHeight()
const {
printing,
labelTemplateId,
labelTemplateOptions,
loadLabelTemplates,
printWaybill,
batchPrintWaybills,
} = useOperationLabelPrint('fulfillPack')
const listLoading = ref(false)
const confirmLoading = ref(false)
const queueList = ref<any[]>([])
const currentPage = ref(1)
const pageSize = ref(50)
const totalCount = ref(0)
const selectedOrderId = ref<number | null>(null)
const selectedQueueRows = ref<any[]>([])
const autoBatchRows = ref<any[]>([])
const handsontableRef = ref<InstanceType<typeof HandsontablePro>>()
const warehouseOptions = ref<Array<{ label: string; value: number }>>([])
const selectedWarehouseId = ref<number>()
const skuFilter = ref('')
const filterOrderIds = ref<number[]>([])
const canConfirmOutbound = hasPermission('Operation.FulfillPack.ConfirmOutbound')
const canBatchPrint = hasPermission('Operation.FulfillPack.BatchPrint')
const isQueueFiltered = computed(
() => Boolean(skuFilter.value.trim() || filterOrderIds.value.length),
)
const filteredStats = computed(() => ({
orders: filteredQueueList.value.length,
qty: filteredQueueList.value.reduce(
(sum, row) => sum + Number(row.stockBindQtyTotal || 0),
0,
),
}))
const activeWarehouseId = computed(() =>
currentWarehouseStore.resolveDefaultWarehouseId(selectedWarehouseId.value),
)
const pageQtyTotal = computed(() =>
queueList.value.reduce((sum, row) => sum + Number(row.stockBindQtyTotal || 0), 0),
)
const hasBatchPrintTarget = computed(
() =>
selectedQueueRows.value.length > 0 ||
autoBatchRows.value.length > 0 ||
selectedOrderId.value != null,
)
const filteredQueueList = computed(() => {
let rows = queueList.value
if (filterOrderIds.value.length) {
const idSet = new Set(filterOrderIds.value.map(Number))
rows = rows.filter((r) => idSet.has(Number(r.id)))
}
const sku = skuFilter.value.trim().toLowerCase()
if (sku) {
rows = rows.filter((r) =>
String(r.primarySkuCodes || '')
.toLowerCase()
.split(',')
.some((code) => code.trim() === sku || code.trim().includes(sku)),
)
}
return rows
})
const hotColumns = computed(() => [
{ key: 'primaryBinCode', label: t('order.myOrders.table.primaryBinCode'), width: 90 },
{ key: 'primarySkuCodes', label: t('order.myOrders.table.sku'), width: 120 },
{ key: 'waybillNo', label: t('order.myOrders.table.waybillNo'), width: 150 },
{
key: 'domesticTrackingNos',
label: t('order.myOrders.table.domesticTrackingNos'),
width: 140,
},
{ key: 'stockBindQtyTotal', label: t('order.myOrders.table.stockBindQtyTotal'), width: 72 },
{ key: 'fulfillProgress', label: t('order.myOrders.table.fulfillProgress'), width: 100 },
])
function pickRow(raw: any, ...keys: string[]) {
for (const k of keys) {
const v = raw?.[k]
if (v !== undefined && v !== null && v !== '') return v
}
return undefined
}
function normalizeRow(raw: any) {
return {
...raw,
id: pickRow(raw, 'id', 'Id'),
waybillNo: pickRow(raw, 'serviceNo', 'ServiceNo') ?? '',
customerOrderNo: pickRow(raw, 'clientNo', 'ClientNo') ?? '',
trackingNo: pickRow(raw, 'trackNo', 'TrackNo') ?? '',
warehouse: pickRow(raw, 'warehouse', 'Warehouse') ?? '',
stockBindStatus: pickRow(raw, 'stockBindStatus', 'StockBindStatus') ?? 'none',
fulfillProgress: pickRow(raw, 'fulfillProgress', 'FulfillProgress') ?? '',
domesticTrackingNos: pickRow(raw, 'domesticTrackingNos', 'DomesticTrackingNos') ?? '',
primaryBinCode: pickRow(raw, 'primaryBinCode', 'PrimaryBinCode') ?? '',
primarySkuCodes: pickRow(raw, 'primarySkuCodes', 'PrimarySkuCodes') ?? '',
stockBindQtyTotal: pickRow(raw, 'stockBindQtyTotal', 'StockBindQtyTotal') ?? 0,
orderStatus: pickRow(raw, 'orderStatus', 'OrderStatus') ?? pickRow(raw, 'status', 'Status'),
}
}
function fulfillProgressLabel(code: string) {
const key = `order.fulfillOrders.progress.${code || 'arrivedPendingPick'}`
const text = t(key)
return text === key ? code : text
}
function fulfillProgressTone(code: string) {
if (code === 'outboundDone') return 'ok'
if (code === 'arrivedPendingPick') return 'wait'
if (code === 'domesticInTransit') return 'neutral'
return 'mute'
}
function formatDomesticTrackingSummary(nosText: string) {
const nos = String(nosText || '')
.split(',')
.map((s) => s.trim())
.filter(Boolean)
if (!nos.length) return '--'
if (nos.length === 1) return nos[0]
return `${nos[0]} ${t('operation.fulfillPack.domesticMore', { count: nos.length })}`
}
function clearQueueFilters() {
skuFilter.value = ''
filterOrderIds.value = []
autoBatchRows.value = []
handsontableRef.value?.clearSelection()
selectedQueueRows.value = []
}
function queueContainsOrder(orderId: number) {
return queueList.value.some((r) => Number(r.id) === orderId)
}
function customCellRenderer(_row: number, col: number, _value: any, rowData: any) {
const dataColIndex = col - 1
if (dataColIndex < 0 || dataColIndex >= hotColumns.value.length) return null
const colKey = hotColumns.value[dataColIndex].key
if (colKey === 'domesticTrackingNos') {
return formatDomesticTrackingSummary(String(rowData?.domesticTrackingNos || ''))
}
if (colKey === 'fulfillProgress') {
const code = String(rowData?.fulfillProgress || '').trim()
if (!code) return '--'
return buildStatusTagHtml(fulfillProgressLabel(code), fulfillProgressTone(code))
}
return null
}
function onQueueCellClick(payload: { row: any }) {
if (payload?.row) onRowClick(payload.row)
}
function handleSelectionChange(rows: any[]) {
selectedQueueRows.value = rows ?? []
autoBatchRows.value = []
}
async function loadWarehouses() {
try {
const { items } = await getWarehouseList({ page: 1, pageSize: 200 })
const opts = (items || [])
.map((row: any) => ({
label: String(row.warehouseName || row.WarehouseName || row.id || row.Id || ''),
value: Number(row.id ?? row.Id),
}))
.filter((o: { value: number }) => o.value > 0)
warehouseOptions.value = opts
currentWarehouseStore.setOptions(opts)
if (!selectedWarehouseId.value && activeWarehouseId.value) {
selectedWarehouseId.value = activeWarehouseId.value
}
} catch {
warehouseOptions.value = []
}
}
async function loadQueue() {
listLoading.value = true
try {
const { items, total } = await postOrderList({
page: currentPage.value,
pageSize: pageSize.value,
status: 'all',
fulfillmentType: 'warehouse',
stockBindStatus: 'bound',
warehouseId: activeWarehouseId.value,
sortField: 'primaryBinCode',
sortOrder: 'asc',
})
queueList.value = (items || []).map(normalizeRow)
totalCount.value = total
} catch (e: any) {
queueList.value = []
totalCount.value = 0
Message.error(extractOmsRequestError(e) || t('operation.fulfillPack.message.loadFailed'))
} finally {
listLoading.value = false
}
}
function onWarehouseChange(id: number | undefined) {
selectedWarehouseId.value = id
if (id) currentWarehouseStore.setWarehouseId(id)
currentPage.value = 1
clearQueueFilters()
void loadQueue()
}
function onRowClick(record: any) {
selectedOrderId.value = Number(record.id)
const domestic = String(record.domesticTrackingNos || '').split(',')[0]?.trim()
if (domestic) {
void lookupPanelRef.value?.lookupByDomesticTracking(domestic)
return
}
void lookupPanelRef.value?.lookupByWaybill(record.waybillNo)
}
function resolveRowsForBatchPrint() {
if (selectedQueueRows.value.length) return selectedQueueRows.value
if (autoBatchRows.value.length) return autoBatchRows.value
if (selectedOrderId.value) {
const row = filteredQueueList.value.find((r) => Number(r.id) === selectedOrderId.value)
return row ? [row] : []
}
return []
}
async function handlePrintCurrent(lookup: any) {
const ok = await printWaybill(lookup?.serviceNo || lookup?.clientNo)
if (!ok) {
Message.warning(t('operation.fulfillPack.message.printNoWaybill'))
}
}
async function handleBatchPrint() {
const rows = resolveRowsForBatchPrint()
const waybills = rows.map((r) => r.waybillNo).filter(Boolean)
if (!waybills.length) {
Message.warning(t('operation.fulfillPack.message.batchPrintEmpty'))
return
}
await batchPrintWaybills(waybills)
}
function applySkuQueueFilter(skuCode: string, candidateOrderIds?: number[]) {
skuFilter.value = skuCode.trim()
filterOrderIds.value = candidateOrderIds?.length ? candidateOrderIds : []
nextTick(() => {
if (skuFilter.value || filterOrderIds.value.length) {
autoBatchRows.value = [...filteredQueueList.value]
}
})
}
function onLookupComplete(payload: { lookup: any; candidates: any[] }) {
const lookup = payload?.lookup
const candidates = (payload?.candidates || []) as PrintLabelLookupCandidate[]
const scanNo = String(lookupPanelRef.value?.getScanNumber?.() || '').trim()
const matchedType = String(lookup?.matchedNumberType || '').toLowerCase()
if (candidates.length > 0) {
const queueIdSet = new Set(queueList.value.map((r) => Number(r.id)))
const ids = candidates
.map((c) => Number(c.orderId))
.filter((id) => id > 0 && queueIdSet.has(id))
if (!ids.length) {
Message.warning(t('operation.fulfillPack.message.notInQueue'))
return
}
const skuHint =
matchedType === 'sku'
? scanNo
: String(candidates[0]?.matchedHint || scanNo || '').trim()
applySkuQueueFilter(skuHint || scanNo, ids)
Message.info(t('operation.fulfillPack.message.skuMultiMatch', { count: ids.length }))
return
}
if (!lookup?.matched || !lookup.orderId) return
const orderId = Number(lookup.orderId)
selectedOrderId.value = orderId
if (matchedType === 'sku') {
const sku = String(lookup.bindItems?.[0]?.skuCode || scanNo).trim()
if (sku) {
applySkuQueueFilter(sku)
return
}
}
skuFilter.value = ''
filterOrderIds.value = []
if (queueContainsOrder(orderId)) {
autoBatchRows.value = filteredQueueList.value.filter((r) => Number(r.id) === orderId)
} else {
autoBatchRows.value = []
Message.info(t('operation.fulfillPack.message.orderNotInQueue'))
}
}
function isPickReady(record: { fulfillProgress?: string }) {
return String(record?.fulfillProgress || '').trim() === 'arrivedPendingPick'
}
async function handleConfirmOutbound() {
const lookup = lookupPanelRef.value?.getLookup?.()
const orderId = Number(lookup?.orderId)
if (!orderId) {
Message.warning(t('operation.fulfillPack.message.lookupFirst'))
return
}
if (lookup?.bindStatus !== 'bound') {
Message.warning(t('operation.fulfillPack.message.notBound'))
return
}
const queueRow = queueList.value.find((r) => Number(r.id) === orderId)
if (queueRow && !isPickReady(queueRow)) {
Message.warning(t('operation.fulfillPack.message.domesticInTransit'))
return
}
Modal.confirm({
title: t('operation.fulfillPack.confirm.title'),
content: t('operation.fulfillPack.confirm.content', {
waybill: lookup.serviceNo || orderId,
qty: lookup.bindQtyTotal || 0,
}),
onOk: async () => {
confirmLoading.value = true
try {
await postOrderStockBindConfirmDeduct(orderId)
Message.success(t('operation.fulfillPack.message.confirmSuccess'))
lookupPanelRef.value?.handleReset()
selectedOrderId.value = null
clearQueueFilters()
await loadQueue()
} catch (e: any) {
Message.error(extractOmsRequestError(e) || t('operation.fulfillPack.message.confirmFailed'))
} finally {
confirmLoading.value = false
}
},
})
}
onMounted(async () => {
await Promise.all([loadWarehouses(), loadLabelTemplates()])
await loadQueue()
})
</script>
<template>
<div class="fulfill-pack-page">
<header class="fp-toolbar">
<div class="fp-toolbar__left">
<h1 class="fp-toolbar__title">{{ t('menu.operation.fulfillPack') }}</h1>
<span class="fp-toolbar__stats">
{{ t('operation.fulfillPack.stats.summary', { orders: totalCount, qty: pageQtyTotal }) }}
</span>
<span v-if="isQueueFiltered" class="fp-toolbar__stats fp-toolbar__stats--filter">
{{
t('operation.fulfillPack.stats.filtered', {
orders: filteredStats.orders,
qty: filteredStats.qty,
})
}}
</span>
<a-tag v-if="skuFilter" closable color="arcoblue" @close="clearQueueFilters">
SKU: {{ skuFilter }}
</a-tag>
</div>
<div class="fp-toolbar__actions">
<a-select
v-if="warehouseOptions.length"
:model-value="activeWarehouseId"
:options="warehouseOptions"
allow-search
:placeholder="t('operation.fulfillPack.filter.warehouse')"
style="width: 180px"
@change="onWarehouseChange"
/>
<a-select
v-if="labelTemplateOptions.length"
v-model="labelTemplateId"
:options="labelTemplateOptions"
allow-search
:placeholder="t('operation.fulfillPack.filter.labelTemplate')"
style="width: 160px"
/>
<a-button
v-if="canBatchPrint"
:loading="printing"
:disabled="!hasBatchPrintTarget"
@click="handleBatchPrint"
>
{{ t('operation.fulfillPack.actions.batchPrint') }}
</a-button>
<a-button :loading="listLoading" @click="loadQueue">
{{ t('operation.fulfillPack.actions.refresh') }}
</a-button>
</div>
</header>
<div class="fulfill-pack-page__body">
<aside class="fulfill-pack-page__lookup">
<FulfillBindLookupPanel
ref="lookupPanelRef"
page-key="fulfillPack"
default-number-type="auto"
compact
@matched="selectedOrderId = $event"
@lookup-complete="onLookupComplete"
>
<template #actions="{ lookup }">
<div v-if="lookup?.matched" class="fp-actions">
<a-button
v-if="canBatchPrint"
:loading="printing"
@click="handlePrintCurrent(lookup)"
>
{{ t('operation.fulfillPack.actions.printOne') }}
</a-button>
<a-button
v-if="canConfirmOutbound"
type="primary"
:loading="confirmLoading"
:disabled="lookup.bindStatus !== 'bound' || !isPickReady(
queueList.find((r) => Number(r.id) === Number(lookup.orderId)) || {},
)"
@click="handleConfirmOutbound"
>
{{ t('operation.fulfillPack.actions.confirmOutbound') }}
</a-button>
</div>
</template>
</FulfillBindLookupPanel>
</aside>
<main class="fulfill-pack-page__queue">
<div class="fp-queue-head">
<div class="fp-queue-head__left">
<span class="fp-queue-head__title">{{ t('operation.fulfillPack.queue.title') }}</span>
<a-tooltip :content="t('operation.fulfillPack.queue.desc')" position="top">
<IconQuestionCircleFill class="fp-queue-head__help" />
</a-tooltip>
</div>
<PaginationPro
:total-count="totalCount"
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:page-sizes="[10, 30, 50, 100]"
@page-change="loadQueue"
@page-size-change="() => { currentPage = 1; loadQueue() }"
/>
</div>
<div ref="tableContainerRef" class="fp-queue-table-wrap list-wrap">
<a-spin :loading="listLoading" class="table-spin">
<HandsontablePro
ref="handsontableRef"
:key="`${currentPage}-${filteredQueueList.length}`"
:columns="hotColumns"
:data="filteredQueueList"
:height="tableHeight"
:read-only="true"
:stretch-columns="true"
:custom-cell-renderer="customCellRenderer"
@cell-click="onQueueCellClick"
@selection-change="handleSelectionChange"
/>
</a-spin>
</div>
<div
v-if="!listLoading && queueList.length && !filteredQueueList.length"
class="fp-queue-empty"
>
{{ t('operation.fulfillPack.queue.emptyFiltered') }}
<a-button type="text" size="mini" @click="clearQueueFilters">
{{ t('operation.fulfillPack.actions.clearFilter') }}
</a-button>
</div>
</main>
</div>
</div>
</template>
<style lang="less" scoped>
.fulfill-pack-page {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
padding: 16px;
gap: 12px;
background: var(--app-page-bg);
}
.fp-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px 16px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.fp-toolbar__left {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
min-width: 0;
}
.fp-toolbar__title {
margin: 0;
font-size: 16px;
font-weight: 600;
}
.fp-toolbar__stats {
font-size: 13px;
color: var(--color-text-2);
}
.fp-toolbar__actions {
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.fulfill-pack-page__body {
display: flex;
gap: 12px;
flex: 1;
min-height: 0;
}
.fulfill-pack-page__lookup {
flex: 1 1 50%;
min-width: 0;
min-height: 0;
overflow: hidden;
display: flex;
flex-direction: column;
:deep(.fbl-panel) {
flex: 1;
min-height: 0;
height: 100%;
}
}
.fulfill-pack-page__queue {
flex: 1 1 50%;
min-width: 0;
min-height: 0;
display: flex;
flex-direction: column;
gap: 12px;
background: #fff;
border-radius: 8px;
padding: 12px 16px 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.fp-queue-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
flex-shrink: 0;
}
.fp-queue-head__left {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.fp-queue-head__title {
font-size: 15px;
font-weight: 600;
color: var(--color-text-1);
}
.fp-queue-head__help {
font-size: 14px;
color: var(--color-text-3);
cursor: help;
flex-shrink: 0;
&:hover {
color: var(--app-primary-color);
}
}
.fp-queue-table-wrap {
flex: 1;
min-height: 0;
padding: 0;
}
.table-spin {
width: 100%;
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
:deep(.arco-spin) {
width: 100%;
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
:deep(.arco-spin-children) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
}
.list-wrap {
width: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
overscroll-behavior: contain;
:deep(.handsontable-pro-container) {
width: 100%;
flex: 1;
min-height: 0;
}
}
@media (max-width: 1100px) {
.fulfill-pack-page__body {
flex-direction: column;
}
.fulfill-pack-page__lookup,
.fulfill-pack-page__queue {
flex: 0 0 auto;
width: 100%;
max-height: 50vh;
}
}
.fp-toolbar__stats--filter {
color: rgb(var(--primary-6));
}
.fp-queue-empty {
padding: 24px 0;
text-align: center;
font-size: 13px;
color: var(--color-text-3);
}
.fp-actions {
display: flex;
gap: 8px;
padding-top: 4px;
flex-wrap: wrap;
}
</style>