Merge remote-tracking branch 'origin/release/test' into dev

# Conflicts:
#	src/modules/first-leg/views/QuickOrderView.vue
This commit is contained in:
2026-09-04 12:36:56 +08:00
7 changed files with 160 additions and 73 deletions
@@ -33,7 +33,7 @@ test('exposes real list, draft, submit, and detail workflow entries without canc
assert.match(source, /function openCreate\(\)/)
assert.match(source, /async function saveDraft\(\)/)
assert.match(source, /function submitOrder\(\)/)
assert.match(source, /async function openDetail\(order: FirstLegOrder, showFeeDialog = false\)/)
assert.match(source, /async function openDetail\(order: FirstLegOrder\)/)
assert.match(source, /Promise\.allSettled\(\[/)
assert.match(source, /const orderPageRequest = isCreatePage\.value\s*\? store\.loadWarehouseType\('DOMESTIC', true\)\s*:\s*store\.load\(\{ includeDrafts: true \}\)/)
assert.match(source, /Promise\.allSettled\(\[\s*orderPageRequest,\s*companyRequest/)
@@ -491,8 +491,9 @@ test('loads merchant inbound billing as an isolated read-only detail section', (
assert.match(source, /<InboundBillingPanel/)
assert.match(source, /@retry="retryInboundBilling"/)
assert.match(source, /error instanceof ApiError && error\.code === 'A0404'/)
assert.match(source, /inboundBillingUnavailableMessage\.value = error\.message \|\| '还未测量推送'/)
assert.match(source, /error\.message \|\| unavailableMessage/)
assert.match(source, /order\.status === 'DRAFT'/)
assert.match(source, /feeConfirmationOpen\.value[\s\S]*\? '未推送计费重'[\s\S]*: '订单提交后可查看入库结果'/)
assert.match(source, /订单提交后可查看入库结果/)
assert.doesNotMatch(source, /confirmMerchantInbound|adjustMerchantInbound|sendMerchantInbound/)
})
@@ -502,11 +503,28 @@ test('keeps platform enterprise scope and tenant terminology out of the customer
assert.doesNotMatch(templateSource, /租户|tenantId|所属企业|企业筛选/)
})
test('discards stale inbound billing responses when the drawer closes or the user changes orders', () => {
test('opens billing-weight confirmation independently from order details', () => {
const handler = source.slice(source.indexOf('function openFeeConfirmation'), source.indexOf('async function retryDetail'))
assert.match(handler, /feeConfirmationOpen\.value = true/)
assert.match(handler, /loadInboundBilling\(order, '未推送计费重'\)/)
assert.doesNotMatch(handler, /openDetail\(/)
assert.match(source, /v-if="feeConfirmationOpen"[\s\S]*dialog-only[\s\S]*auto-open/)
assert.match(source, /unavailable-message="未推送计费重"/)
})
test('shows the standalone billing-weight entry at every order node', () => {
const templateSource = source.slice(source.indexOf('<template>'), source.lastIndexOf('</template>'))
const entries = templateSource.match(/<el-button link type="primary" @click="openFeeConfirmation\([^)]*\)">确认计费重<\/el-button>/g) ?? []
assert.equal(entries.length, 2)
assert.doesNotMatch(templateSource, /v-if="[^"]*status === 'WAIT_SPLIT'[^"]*"[^>]*>确认计费重/)
})
test('discards stale inbound billing responses when billing views close or the user changes orders', () => {
assert.match(source, /let inboundBillingRequestSequence = 0/)
assert.match(source, /const sequence = \+\+inboundBillingRequestSequence/)
assert.match(source, /sequence === inboundBillingRequestSequence[\s\S]*detailOpen\.value[\s\S]*detailId\.value === orderId/)
assert.match(source, /sequence === inboundBillingRequestSequence[\s\S]*inboundBillingOrderId\.value === orderId[\s\S]*detailOpen\.value \|\| feeConfirmationOpen\.value/)
assert.match(source, /watch\(detailOpen,[\s\S]*resetInboundBillingState\(\)/)
assert.match(source, /watch\(feeConfirmationOpen,[\s\S]*resetInboundBillingState\(\)/)
})
test('protects unsaved drafts and exposes recoverable load failures', () => {
@@ -200,8 +200,9 @@ const inboundBilling = ref<MerchantInboundBilling | null>(null)
const inboundBillingLoading = ref(false)
const inboundBillingUnavailable = ref(false)
const inboundBillingUnavailableMessage = ref('还未测量推送')
const openFeeDialogWithDetail = ref(false)
const inboundBillingError = ref('')
const inboundBillingOrderId = ref('')
const feeConfirmationOpen = ref(false)
const customsByOrder = reactive<Record<string, MerchantCustomsContainer | null | undefined>>({})
const customsEligibilityPending = new Set<string>()
const customsDialogOpen = ref(false)
@@ -650,12 +651,16 @@ watch(isCreatePage, (isCreate, wasCreate) => {
}, { immediate: true })
watch(detailOpen, (open) => {
if (!open) {
if (!open && !feeConfirmationOpen.value) {
resetInboundBillingState()
if (detailOrder.value) releaseProductImagePreviews(detailOrder.value.items)
}
})
watch(feeConfirmationOpen, (open) => {
if (!open && !detailOpen.value) resetInboundBillingState()
})
onBeforeUnmount(() => {
resetInboundBillingState()
channelRequestSequence += 1
@@ -1195,8 +1200,8 @@ async function openEdit(order: FirstLegOrder) {
}
}
async function openDetail(order: FirstLegOrder, showFeeDialog = false) {
openFeeDialogWithDetail.value = showFeeDialog
async function openDetail(order: FirstLegOrder) {
feeConfirmationOpen.value = false
detailId.value = order.id
detailCargoPage.value = 1
detailOpen.value = true
@@ -1216,7 +1221,11 @@ async function openDetail(order: FirstLegOrder, showFeeDialog = false) {
}
function openFeeConfirmation(order: FirstLegOrder) {
void openDetail(order, true)
detailOpen.value = false
resetInboundBillingState()
inboundBillingUnavailableMessage.value = '未推送计费重'
feeConfirmationOpen.value = true
void loadInboundBilling(order, '未推送计费重')
}
async function retryDetail() {
@@ -1226,6 +1235,7 @@ async function retryDetail() {
function resetInboundBillingState() {
inboundBillingRequestSequence += 1
inboundBillingOrderId.value = ''
inboundBilling.value = null
inboundBillingLoading.value = false
inboundBillingUnavailable.value = false
@@ -1235,21 +1245,24 @@ function resetInboundBillingState() {
function isCurrentInboundBillingRequest(sequence: number, orderId: string) {
return sequence === inboundBillingRequestSequence
&& detailOpen.value
&& detailId.value === orderId
&& inboundBillingOrderId.value === orderId
&& (detailOpen.value || feeConfirmationOpen.value)
}
async function loadInboundBilling(order: FirstLegOrder) {
async function loadInboundBilling(order: FirstLegOrder, unavailableMessage = '还未测量推送') {
const sequence = ++inboundBillingRequestSequence
inboundBillingOrderId.value = order.id
inboundBilling.value = null
inboundBillingLoading.value = false
inboundBillingUnavailable.value = false
inboundBillingUnavailableMessage.value = '还未测量推送'
inboundBillingUnavailableMessage.value = unavailableMessage
inboundBillingError.value = ''
if (order.status === 'DRAFT') {
inboundBillingUnavailable.value = true
inboundBillingUnavailableMessage.value = '订单提交后可查看入库结果'
inboundBillingUnavailableMessage.value = feeConfirmationOpen.value
? '未推送计费重'
: '订单提交后可查看入库结果'
return
}
@@ -1262,7 +1275,9 @@ async function loadInboundBilling(order: FirstLegOrder) {
if (!isCurrentInboundBillingRequest(sequence, order.id)) return
if (error instanceof ApiError && error.code === 'A0404') {
inboundBillingUnavailable.value = true
inboundBillingUnavailableMessage.value = error.message || '还未测量推送'
inboundBillingUnavailableMessage.value = feeConfirmationOpen.value
? '未推送计费重'
: error.message || unavailableMessage
} else {
inboundBillingError.value = error instanceof Error ? error.message : '入库与费用加载失败'
}
@@ -1272,8 +1287,12 @@ async function loadInboundBilling(order: FirstLegOrder) {
}
async function retryInboundBilling() {
const order = detailId.value ? store.getById(detailId.value) : undefined
if (order) await loadInboundBilling(order)
const order = inboundBillingOrderId.value ? store.getById(inboundBillingOrderId.value) : undefined
if (order) await loadInboundBilling(order, feeConfirmationOpen.value ? '未推送计费重' : '还未测量推送')
}
function handleInboundFeeConfirmed() {
if (!feeConfirmationOpen.value) void retryInboundBilling()
}
async function confirmDiscardChanges() {
@@ -1782,7 +1801,7 @@ async function searchOrders(model: QueryModel) {
<template #actions="{ row }">
<div class="order-row-actions">
<el-button link type="primary" @click="openDetail(row as FirstLegOrder)"><Eye :size="15" />详情</el-button>
<el-button v-if="(row as FirstLegOrder).status === 'WAIT_SPLIT'" link type="primary" @click="openFeeConfirmation(row as FirstLegOrder)">确认计费重</el-button>
<el-button link type="primary" @click="openFeeConfirmation(row as FirstLegOrder)">确认计费重</el-button>
<el-button v-if="canEditOrder && canClientEditFirstLegOrder((row as FirstLegOrder).status)" link type="primary" :loading="openingEditor" @click="openEdit(row as FirstLegOrder)"><Pencil :size="15" />编辑</el-button>
<el-button v-if="eligibleCustomsDetail(row as FirstLegOrder)" link type="primary" @click="openCustomsDocuments(row as FirstLegOrder)"><FileText :size="15" />报关资料</el-button>
</div>
@@ -1848,7 +1867,7 @@ async function searchOrders(model: QueryModel) {
<span>更新于 {{ formatDateTime(order.updatedAt) }}</span>
<div>
<el-button link type="primary" @click="openDetail(order)"><Eye :size="15" />详情</el-button>
<el-button v-if="order.status === 'WAIT_SPLIT'" link type="primary" @click="openFeeConfirmation(order)">确认计费重</el-button>
<el-button link type="primary" @click="openFeeConfirmation(order)">确认计费重</el-button>
<el-button v-if="canEditOrder && canClientEditFirstLegOrder(order.status)" link type="primary" :loading="openingEditor" @click="openEdit(order)"><Pencil :size="15" />编辑</el-button>
<el-button v-if="eligibleCustomsDetail(order)" link type="primary" @click="openCustomsDocuments(order)"><FileText :size="15" />报关资料</el-button>
</div>
@@ -2156,19 +2175,32 @@ async function searchOrders(model: QueryModel) {
<OrderProgressPanel :order="detailOrder" />
<InboundBillingPanel
:data="inboundBilling"
:auto-open="openFeeDialogWithDetail"
:loading="inboundBillingLoading"
:unavailable="inboundBillingUnavailable"
:unavailable-message="inboundBillingUnavailableMessage"
:error="inboundBillingError"
:can-confirm="canConfirmInboundFee"
@retry="retryInboundBilling"
@confirmed="retryInboundBilling"
@confirmed="handleInboundFeeConfirmed"
/>
</template>
</div>
<template #footer><div v-if="detailOrder" class="editor-actions"><el-button @click="detailOpen = false">关闭</el-button><el-button v-if="canEditOrder && canClientEditFirstLegOrder(detailOrder.status)" :loading="openingEditor" @click="openEdit(detailOrder)"><Pencil :size="16" />编辑草稿</el-button></div></template>
</el-dialog>
<InboundBillingPanel
v-if="feeConfirmationOpen"
dialog-only
auto-open
:data="inboundBilling"
:loading="inboundBillingLoading"
:unavailable="inboundBillingUnavailable"
unavailable-message="未推送计费重"
:error="inboundBillingError"
:can-confirm="canConfirmInboundFee"
@retry="retryInboundBilling"
@confirmed="handleInboundFeeConfirmed"
@closed="feeConfirmationOpen = false"
/>
<CustomsDocumentsDialog
v-model="customsDialogOpen"
:order-id="customsDialogOrderId"
@@ -102,7 +102,11 @@ test('binds exactly one destination warehouse through a destination dialog', ()
assert.match(source, /availableDestinationWarehouses\.value\.find/)
assert.match(source, /destinationWarehouseId: warehouse\.id/)
assert.match(source, /destinationWarehouseId: ''/)
assert.match(source, /const required = \[destinationForm\.privateName, destinationForm\.countryCode\]/)
assert.match(source, /getMerchantOrderAddresses\('PRIVATE_DESTINATION'\)/)
assert.match(source, /v-model="destinationForm\.privateAddressId"/)
assert.match(source, /privateDestinationAddressId: String\(address\.id\)/)
assert.match(source, /privateDestinationAddressId: row\.destinationType === 'PRIVATE' \? row\.privateDestinationAddressId : ''/)
assert.match(source, /hasCompletePrivateContact\(row\)/)
assert.doesNotMatch(source, /v-model="destinationForm\.privateName"/)
assert.match(source, /确认绑定/)
})
+45 -41
View File
@@ -6,7 +6,9 @@ import { MapPin, Plus, Send, Trash2 } from '@lucide/vue'
import { useAuthStore } from '@/modules/auth/store/auth'
import {
getMerchantInboundCodePolicy,
getMerchantOrderAddresses,
getMerchantPricingChannels,
type CustomerOrderAddress,
type InboundCodePolicy,
type MerchantPricingChannel,
} from '@/modules/first-leg/api/firstLeg'
@@ -32,6 +34,7 @@ interface QuickOrderRow {
destinationWarehouseName: string
destinationCountryCode: string
amazonWarehouseCode: string
privateDestinationAddressId: string
consigneeContactName: string
consigneePhone: string
consigneeCity: string
@@ -64,6 +67,8 @@ const inboundCodePolicy = ref<InboundCodePolicy | null>(null)
const channelOptions = ref<QuickChannelOption[]>([])
const destinationDialogOpen = ref(false)
const destinationLoading = ref(false)
const privateAddresses = ref<CustomerOrderAddress[]>([])
const privateAddressesError = ref('')
const editingDestinationRow = ref<QuickOrderRow>()
const draftResults = reactive<QuickDraftResult[]>([])
const resultDialogOpen = ref(false)
@@ -71,13 +76,7 @@ const activeBatchKey = ref('')
const destinationForm = reactive({
type: 'FBA' as DestinationType,
warehouseId: '',
privateName: '',
countryCode: 'US',
contactName: '',
phone: '',
city: '',
address: '',
postalCode: '',
privateAddressId: '',
})
let rowSequence = 0
let productSequence = 0
@@ -101,6 +100,7 @@ function createRow(): QuickOrderRow {
destinationWarehouseName: '',
destinationCountryCode: '',
amazonWarehouseCode: '',
privateDestinationAddressId: '',
consigneeContactName: '',
consigneePhone: '',
consigneeCity: '',
@@ -149,6 +149,10 @@ function selectedChannel(row: QuickOrderRow) {
return channelOptions.value.find((channel) => channelKey(channel.warehouseId, channel.channelCode) === row.channelKey)
}
function addressLabel(address: CustomerOrderAddress) {
return `${address.addressName} · ${address.contactName} · ${address.countryCode} ${address.city} ${address.addressLine}`
}
function createConsigneeSnapshot(row: QuickOrderRow) {
return {
id: '',
@@ -187,7 +191,7 @@ function buildOrderDraft(row: QuickOrderRow, channel: QuickChannelOption): First
shipperPartySnapshot: null,
shipper: '',
consigneePartyId: '',
privateDestinationAddressId: '',
privateDestinationAddressId: row.destinationType === 'PRIVATE' ? row.privateDestinationAddressId : '',
consigneePartySnapshot: row.destinationType === 'PRIVATE' && hasCompletePrivateContact(row)
? createConsigneeSnapshot(row) : null,
consignee: row.destinationType === 'PRIVATE' && hasCompletePrivateContact(row)
@@ -231,21 +235,24 @@ async function openDestinationDialog(row: QuickOrderRow, typeValue: string | num
Object.assign(destinationForm, {
type,
warehouseId: row.destinationType === type ? row.destinationWarehouseId : '',
privateName: row.destinationType === type ? row.destinationWarehouseName : '',
countryCode: row.destinationType === type ? row.destinationCountryCode || 'US' : 'US',
contactName: row.destinationType === type ? row.consigneeContactName : '',
phone: row.destinationType === type ? row.consigneePhone : '',
city: row.destinationType === type ? row.consigneeCity : '',
address: row.destinationType === type ? row.consigneeAddress : '',
postalCode: row.destinationType === type ? row.consigneePostalCode : '',
privateAddressId: row.destinationType === type ? row.privateDestinationAddressId : '',
})
destinationDialogOpen.value = true
if (type === 'PRIVATE') return
destinationLoading.value = true
try {
await store.loadWarehouseType(type)
if (type === 'PRIVATE') {
privateAddressesError.value = ''
privateAddresses.value = await getMerchantOrderAddresses('PRIVATE_DESTINATION')
} else {
await store.loadWarehouseType(type)
}
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '目的仓加载失败,请稍后重试')
const message = error instanceof Error ? error.message : '目的仓加载失败,请稍后重试'
if (type === 'PRIVATE') {
privateAddresses.value = []
privateAddressesError.value = message
}
ElMessage.error(message)
} finally {
destinationLoading.value = false
}
@@ -266,6 +273,7 @@ function bindDestination() {
destinationWarehouseName: warehouse.name,
destinationCountryCode: warehouse.countryCode,
amazonWarehouseCode: destinationForm.type === 'FBA' ? warehouse.code : '',
privateDestinationAddressId: '',
consigneeContactName: '',
consigneePhone: '',
consigneeCity: '',
@@ -273,26 +281,23 @@ function bindDestination() {
consigneePostalCode: '',
})
} else {
const required = [destinationForm.privateName, destinationForm.countryCode]
if (required.some((value) => !value.trim())) {
ElMessage.warning('请填写私人仓名称和目的国家')
return
}
if (!/^[A-Za-z]{2}$/.test(destinationForm.countryCode.trim())) {
ElMessage.warning('目的国家请输入两位英文代码,例如 US')
const address = privateAddresses.value.find((item) => String(item.id) === destinationForm.privateAddressId)
if (!address) {
ElMessage.warning('请选择企业已保存的私人仓地址')
return
}
Object.assign(row, {
destinationType: 'PRIVATE',
destinationWarehouseId: '',
destinationWarehouseName: destinationForm.privateName.trim(),
destinationCountryCode: destinationForm.countryCode.trim().toUpperCase(),
destinationWarehouseName: address.addressName,
destinationCountryCode: address.countryCode,
amazonWarehouseCode: '',
consigneeContactName: destinationForm.contactName.trim(),
consigneePhone: destinationForm.phone.trim(),
consigneeCity: destinationForm.city.trim(),
consigneeAddress: destinationForm.address.trim(),
consigneePostalCode: destinationForm.postalCode.trim(),
privateDestinationAddressId: String(address.id),
consigneeContactName: address.contactName,
consigneePhone: address.phone,
consigneeCity: address.city,
consigneeAddress: address.addressLine,
consigneePostalCode: address.postalCode ?? '',
})
}
destinationDialogOpen.value = false
@@ -347,6 +352,7 @@ async function submitQuickOrder() {
return
}
const incompleteIndex = rows.findIndex((row) => !row.channelKey || !row.destinationWarehouseName
|| (row.destinationType === 'PRIVATE' && !row.privateDestinationAddressId)
|| row.products.some((product) => !product.sku.trim() || product.packageCount < 1))
if (incompleteIndex >= 0) {
ElMessage.warning(`请完善第 ${incompleteIndex + 1} 行的渠道、目的仓、产品 SKU 和箱数`)
@@ -513,15 +519,13 @@ onMounted(loadChannels)
<small v-if="!destinationLoading && availableDestinationWarehouses.length === 0">平台暂未维护可用目的仓,请联系平台管理员。</small>
</el-form-item>
<template v-else>
<el-form-item label="私人地址名称" required><el-input v-model="destinationForm.privateName" maxlength="128" placeholder="例如:洛杉矶客户自有仓" /></el-form-item>
<div class="destination-private-grid">
<el-form-item label="目的国家" required><el-input v-model="destinationForm.countryCode" maxlength="2" placeholder="US" /></el-form-item>
<el-form-item label="联系人" required><el-input v-model="destinationForm.contactName" maxlength="64" placeholder="请输入收件人姓名" /></el-form-item>
<el-form-item label="联系电话" required><el-input v-model="destinationForm.phone" maxlength="32" placeholder="请输入收件人联系电话" /></el-form-item>
<el-form-item label="城市" required><el-input v-model="destinationForm.city" maxlength="64" placeholder="请输入收件城市" /></el-form-item>
</div>
<el-form-item label="详细地址" required><el-input v-model="destinationForm.address" maxlength="256" placeholder="请输入收件详细地址" /></el-form-item>
<el-form-item label="邮编"><el-input v-model="destinationForm.postalCode" maxlength="20" placeholder="请输入邮编(选填)" /></el-form-item>
<el-form-item label="私人仓地址" required>
<el-select v-model="destinationForm.privateAddressId" filterable :loading="destinationLoading" placeholder="请选择企业已保存的私人仓地址">
<el-option v-for="address in privateAddresses" :key="String(address.id)" :label="addressLabel(address)" :value="String(address.id)" />
</el-select>
<small v-if="privateAddressesError">私人仓地址加载失败,请关闭后重试。</small>
<small v-else-if="!destinationLoading && privateAddresses.length === 0">暂无已保存的私人仓地址,请先在普通下单页面维护。</small>
</el-form-item>
</template>
</el-form>
<template #footer>