优化
This commit is contained in:
@@ -3,6 +3,7 @@ import type { PageResult } from './businessOrders'
|
||||
|
||||
export type Amount = number | string
|
||||
export interface ProcurementSummary {
|
||||
procurementDirection?: import('../procurementPresentation').ProcurementDirection
|
||||
orderNo: string
|
||||
purchaseCategory: string
|
||||
productName: string
|
||||
@@ -73,6 +74,7 @@ export interface ProcurementDetail {
|
||||
exceptionSummaries: string[]
|
||||
}
|
||||
export interface ProcurementCreate {
|
||||
procurementDirection?: import('../procurementPresentation').ProcurementDirection
|
||||
customerName: string
|
||||
purchaseCategory: string
|
||||
productName: string
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { ProcurementDetail, ProcurementFee } from '../api/procurement'
|
||||
import { dateTime, feePurposes, feeStatus, feeTone, feeTotals, measurement, money, productHref, text } from '../procurementPresentation'
|
||||
import { directionLabel, regionText, dateTime, feePurposes, feeStatus, feeTone, feeTotals, measurement, money, productHref, text } from '../procurementPresentation'
|
||||
|
||||
const props = defineProps<{ detail: ProcurementDetail }>()
|
||||
const t = (text: string) => regionText(text, props.detail.order.procurementDirection)
|
||||
const totals = computed(() => feeTotals(props.detail.fees))
|
||||
const progress = computed(() => props.detail.progress.filter(step => step.key !== 'closed_at' || step.completedAt))
|
||||
const ended = computed(() => ['REJECTED', 'CANCELLED', 'EXCEPTION_CLOSED', 'SHIPPED_TO_CUSTOMER'].includes(props.detail.order.status))
|
||||
@@ -22,7 +23,7 @@ const hasPending = computed(() => props.detail.fees.some(f => f.walletStatus?.en
|
||||
</section>
|
||||
<section class="procurement-section" aria-label="商品与收件信息">
|
||||
<h3>商品与收件信息</h3>
|
||||
<dl class="procurement-grid">
|
||||
<dl class="procurement-grid"><div><dt>采购方向</dt><dd>{{ directionLabel(detail.order.procurementDirection) }}</dd></div>
|
||||
<div><dt>采购品类</dt><dd>{{ detail.order.purchaseCategory }}</dd></div>
|
||||
<div><dt>商品名称</dt><dd>{{ detail.order.productName }}</dd></div>
|
||||
<div><dt>商品规格</dt><dd>{{ text(detail.order.productSpecification) }}</dd></div>
|
||||
@@ -30,16 +31,16 @@ const hasPending = computed(() => props.detail.fees.some(f => f.walletStatus?.en
|
||||
<div><dt>下单预算单价</dt><dd>{{ money(detail.order.budgetUnitPrice, detail.order.currency) }}</dd></div>
|
||||
<div><dt>货款预算总上限</dt><dd>{{ money(detail.budget.totalAmount, detail.budget.currency) }}</dd></div>
|
||||
<div><dt>预算核验时间</dt><dd>{{ dateTime(detail.budget.authorizedAt) }}</dd></div>
|
||||
<div><dt>预计到海外仓</dt><dd>{{ dateTime(detail.order.estimatedArrivalAt) }}</dd></div>
|
||||
<div><dt>{{ t('预计到海外仓') }}</dt><dd>{{ dateTime(detail.order.estimatedArrivalAt) }}</dd></div>
|
||||
<div><dt>收件人</dt><dd>{{ detail.order.contactName }}</dd></div>
|
||||
<div><dt>联系电话</dt><dd>{{ detail.order.contactPhone }}</dd></div>
|
||||
<div class="wide"><dt>下单收货地址</dt><dd>{{ detail.order.receivingAddress }}</dd></div>
|
||||
<div class="wide"><dt>实际海外仓</dt><dd>{{ text(detail.order.actualWarehouseName) }}<span v-if="detail.order.actualWarehouseCode">({{ detail.order.actualWarehouseCode }})</span></dd></div>
|
||||
<div class="wide"><dt>{{ t('实际海外仓') }}</dt><dd>{{ text(detail.order.actualWarehouseName) }}<span v-if="detail.order.actualWarehouseCode">({{ detail.order.actualWarehouseCode }})</span></dd></div>
|
||||
<div class="wide"><dt>商品链接</dt><dd><a v-if="productHref(detail.order.productUrl)" :href="productHref(detail.order.productUrl)" target="_blank" rel="noopener noreferrer">{{ detail.order.productUrl }}</a><span v-else>{{ text(detail.order.productUrl) }}</span></dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
<section class="procurement-section" aria-label="已确认海外装箱清单">
|
||||
<h3>已确认海外装箱清单</h3>
|
||||
<section class="procurement-section" :aria-label="t('已确认海外装箱清单')">
|
||||
<h3>{{ t('已确认海外装箱清单') }}</h3>
|
||||
<el-table :data="detail.boxes" border stripe empty-text="尚无已确认的装箱清单" row-key="cartonNo">
|
||||
<el-table-column prop="cartonNo" label="箱号" min-width="170" />
|
||||
<el-table-column label="箱内商品" min-width="200"><template #default>{{ detail.order.productName }}</template></el-table-column>
|
||||
@@ -52,7 +53,7 @@ const hasPending = computed(() => props.detail.fees.some(f => f.walletStatus?.en
|
||||
<section class="procurement-section" aria-label="两段实际运输">
|
||||
<h3>两段实际运输</h3>
|
||||
<el-table :data="detail.shipments" border stripe empty-text="尚无实际交寄记录">
|
||||
<el-table-column label="运输段" width="150"><template #default="{ row }">{{ row.leg === 'OVERSEAS' ? '国际段 · 海外交寄' : '国内段 · 寄客户' }}</template></el-table-column>
|
||||
<el-table-column label="运输段" width="150"><template #default="{ row }">{{ t(row.leg === 'OVERSEAS' ? '国际段 · 海外交寄' : '国内段 · 寄客户') }}</template></el-table-column>
|
||||
<el-table-column prop="shipmentNo" label="交寄编号" min-width="270" />
|
||||
<el-table-column prop="cartonNo" label="原箱号" min-width="150" />
|
||||
<el-table-column prop="quantity" label="实际件数" width="110" />
|
||||
@@ -73,7 +74,7 @@ const hasPending = computed(() => props.detail.fees.some(f => f.walletStatus?.en
|
||||
<p class="procurement-note">预算上限仅包含样品货款。预估国际运费只冻结、不直接扣款,最终以实际费用结算;表内保留原费用、追加及退款记录。</p>
|
||||
<el-table :data="detail.fees" border stripe empty-text="尚无已核定费用" row-key="feeNo">
|
||||
<el-table-column prop="feeNo" label="费用编号" min-width="270" />
|
||||
<el-table-column label="费用用途" min-width="145"><template #default="{ row }">{{ feePurposes[row.purpose] || '待核定' }}</template></el-table-column>
|
||||
<el-table-column label="费用用途" min-width="145"><template #default="{ row }">{{ t(feePurposes[row.purpose] || '待核定') }}</template></el-table-column>
|
||||
<el-table-column prop="name" label="费用名称" min-width="145" />
|
||||
<el-table-column label="原币金额" min-width="130"><template #default="{ row }">{{ money(row.originalAmount, row.originalCurrency) }}</template></el-table-column>
|
||||
<el-table-column label="汇率 / 月份" min-width="150"><template #default="{ row }">{{ measurement(row.exchangeRate, 6) }}<br /><small>{{ text(row.exchangeRateMonth) }}</small></template></el-table-column>
|
||||
|
||||
@@ -154,3 +154,18 @@ test('purchase category is optional while its length remains bounded', () => {
|
||||
assert.equal(payload.purchaseCategory, '')
|
||||
assert.throws(() => presentation.buildProcurementCreate({ ...draft(), purchaseCategory: 'x'.repeat(129) }, 'Company', 'key'), /品类/)
|
||||
})
|
||||
|
||||
|
||||
test('domestic purchase creates an export order and displays the actual origin and destination regions', () => {
|
||||
const payload = presentation.buildProcurementCreate({ ...draft(), procurementDirection: 'DOMESTIC_TO_OVERSEAS', receivingAddress: 'US, CA, Los Angeles, test destination' }, 'Authenticated Company', 'export-key')
|
||||
assert.equal(payload.procurementDirection, 'DOMESTIC_TO_OVERSEAS')
|
||||
assert.equal(payload.receivingAddress, 'US, CA, Los Angeles, test destination')
|
||||
assert.equal(presentation.statusLabel('WAIT_OVERSEAS_RECEIPT', payload.procurementDirection), '待国内到仓')
|
||||
assert.equal(presentation.statusLabel('DOMESTIC_RECEIVING', payload.procurementDirection), '海外收货中')
|
||||
assert.equal(presentation.statusLabel('WAIT_CHARGES', payload.procurementDirection), '待海外核费')
|
||||
assert.equal(presentation.statusLabel('WAIT_OVERSEAS_RECEIPT'), '待海外到仓')
|
||||
assert.throws(() => presentation.buildProcurementCreate({ ...draft(), procurementDirection: 'INVALID' }, 'Company', 'key'), /采购方向/)
|
||||
const source = readFileSync(new URL('./views/ProcurementView.vue', import.meta.url), 'utf8')
|
||||
assert.match(source, /v-model="form.procurementDirection"/)
|
||||
assert.match(source, /regionText\('最终国内收件资料', form.procurementDirection\)/)
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@ export const feePurposes: Record<string, string> = {
|
||||
SAMPLE_PAYMENT: '样品货款', INTERNATIONAL_ESTIMATE: '预估国际运费', INTERNATIONAL_FREIGHT: '实际国际运费',
|
||||
DUTY: '关税', DOMESTIC_FREIGHT: '国内运费', OTHER: '其他费用', ADJUSTMENT: '追加费用', REFUND: '退款',
|
||||
}
|
||||
export function statusLabel(status: string | null | undefined) { return status ? procurementStatuses[status] || '待核对进度' : '—' }
|
||||
export function statusLabel(status: string | null | undefined, direction?: string | null) { return regionText(status ? procurementStatuses[status] || '待核对进度' : '—', direction) }
|
||||
export function statusTone(status: string | null | undefined): 'success' | 'warning' | 'danger' | 'info' | 'primary' {
|
||||
if (status === 'SHIPPED_TO_CUSTOMER') return 'success'
|
||||
if (status === 'REJECTED' || status === 'EXCEPTION_CLOSED') return 'danger'
|
||||
@@ -79,6 +79,7 @@ export function feeTotals(fees: ProcurementFee[]) {
|
||||
return { paid: decimal(paid), refunded: decimal(refunded), net: decimal(paid - refunded), estimatedHold: decimal(estimatedHold) }
|
||||
}
|
||||
export interface ProcurementDraft {
|
||||
procurementDirection?: ProcurementDirection
|
||||
purchaseCategory: string
|
||||
productName: string
|
||||
productSpecification: string
|
||||
@@ -92,7 +93,7 @@ export interface ProcurementDraft {
|
||||
remark: string
|
||||
}
|
||||
export function emptyProcurementDraft(): ProcurementDraft {
|
||||
return { purchaseCategory: '', productName: '', productSpecification: '', productUrl: '', purchaseQuantity: '1', budgetUnitPrice: '', currency: 'USD', receivingAddress: '', contactName: '', contactPhone: '', remark: '' }
|
||||
return { procurementDirection: 'OVERSEAS_TO_DOMESTIC', purchaseCategory: '', productName: '', productSpecification: '', productUrl: '', purchaseQuantity: '1', budgetUnitPrice: '', currency: 'USD', receivingAddress: '', contactName: '', contactPhone: '', remark: '' }
|
||||
}
|
||||
export function draftBudgetTotal(draft: ProcurementDraft) {
|
||||
const price = cents(draft.budgetUnitPrice)
|
||||
@@ -101,7 +102,7 @@ export function draftBudgetTotal(draft: ProcurementDraft) {
|
||||
}
|
||||
export function buildProcurementCreate(draft: ProcurementDraft, customerName: string, key: string): ProcurementCreate {
|
||||
for (const [field, label, max] of [
|
||||
['productName', '商品名称', 255], ['receivingAddress', '完整国内收货地址', 1000],
|
||||
['productName', '商品名称', 255], ['receivingAddress', '完整目的地收货地址', 1000],
|
||||
['contactName', '最终收件人', 128], ['contactPhone', '联系电话', 64],
|
||||
] as const) {
|
||||
if (!draft[field].trim() || draft[field].trim().length > max) throw new Error(`请填写有效的${label}`)
|
||||
@@ -116,9 +117,20 @@ export function buildProcurementCreate(draft: ProcurementDraft, customerName: st
|
||||
if (!/^[+0-9][0-9 ()-]{5,63}$/.test(draft.contactPhone.trim())) throw new Error('请填写快递可联系的电话号码,微信或邮箱不能代替电话')
|
||||
if (draft.productUrl && (!productHref(draft.productUrl.trim()) || draft.productUrl.trim().length > 2000)) throw new Error('商品链接须为有效的 http 或 https 地址')
|
||||
if (draft.productSpecification.length > 500 || draft.remark.length > 1000) throw new Error('商品规格或备注超过长度限制')
|
||||
return { customerName: customerName.trim(), purchaseCategory: draft.purchaseCategory.trim(), productName: draft.productName.trim(),
|
||||
if (draft.procurementDirection && !['OVERSEAS_TO_DOMESTIC', 'DOMESTIC_TO_OVERSEAS'].includes(draft.procurementDirection)) throw new Error('请选择有效采购方向')
|
||||
return { procurementDirection: draft.procurementDirection || 'OVERSEAS_TO_DOMESTIC', customerName: customerName.trim(), purchaseCategory: draft.purchaseCategory.trim(), productName: draft.productName.trim(),
|
||||
productSpecification: draft.productSpecification.trim() || undefined, productUrl: draft.productUrl.trim() || undefined,
|
||||
purchaseQuantity: Number(draft.purchaseQuantity), budgetUnitPrice: Number(decimal(price)), currency: draft.currency,
|
||||
receivingAddress: draft.receivingAddress.trim(), contactName: draft.contactName.trim(), contactPhone: draft.contactPhone.trim(),
|
||||
remark: draft.remark.trim() || undefined, idempotencyKey: key }
|
||||
}
|
||||
|
||||
export type ProcurementDirection = 'OVERSEAS_TO_DOMESTIC' | 'DOMESTIC_TO_OVERSEAS'
|
||||
export const procurementDirections: Record<ProcurementDirection, string> = {
|
||||
OVERSEAS_TO_DOMESTIC: '海外采购,发往国内', DOMESTIC_TO_OVERSEAS: '国内采购,发往海外',
|
||||
}
|
||||
export function directionLabel(direction?: string | null) { return direction === 'DOMESTIC_TO_OVERSEAS' ? procurementDirections.DOMESTIC_TO_OVERSEAS : procurementDirections.OVERSEAS_TO_DOMESTIC }
|
||||
// 两个历史段编码表示起运段和目的地段,展示区域按订单方向转换。
|
||||
export function regionText(text: string, direction?: string | null) {
|
||||
return direction === 'DOMESTIC_TO_OVERSEAS' ? text.replaceAll('海外', '__ORIGIN__').replaceAll('国内', '海外').replaceAll('__ORIGIN__', '国内') : text
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import QueryToolbar, { type QueryField, type QueryModel } from '@/components/com
|
||||
import type { TableAction } from '@/components/common/tableActions'
|
||||
import ProcurementDetailPanel from '../components/ProcurementDetailPanel.vue'
|
||||
import { createProcurement, getProcurement, listProcurements, type ProcurementDetail, type ProcurementSummary } from '../api/procurement'
|
||||
import { buildProcurementCreate, dateTime, draftBudgetTotal, emptyProcurementDraft, money, procurementStatuses, statusLabel, statusTone } from '../procurementPresentation'
|
||||
import { procurementDirections, directionLabel, regionText, buildProcurementCreate, dateTime, draftBudgetTotal, emptyProcurementDraft, money, procurementStatuses, statusLabel, statusTone } from '../procurementPresentation'
|
||||
import { procurementRequestKey } from '../procurementSubmission'
|
||||
|
||||
const props = withDefaults(defineProps<{ createPage?: boolean; detailPage?: boolean }>(), { createPage: false, detailPage: false })
|
||||
@@ -35,10 +35,11 @@ const queryModel = computed<QueryModel>({
|
||||
const queryFields: QueryField[] = [
|
||||
{ key: 'orderNo', label: '采购单号', type: 'input' }, { key: 'purchaseCategory', label: '采购品类', type: 'input' },
|
||||
{ key: 'productName', label: '商品名称', type: 'input' },
|
||||
{ key: 'status', label: '履约进度', type: 'select', options: Object.entries(procurementStatuses).map(([value, label]) => ({ value, label })) },
|
||||
{ key: 'status', label: '履约进度', type: 'select', options: Object.entries(procurementStatuses).map(([value, label]) => ({ value, label: ({ WAIT_OVERSEAS_RECEIPT: '待起运仓收货', OVERSEAS_RECEIVING: '起运地收货中', WAIT_OVERSEAS_SHIPMENT: '待国际交寄', DOMESTIC_RECEIVING: '目的地收货中', WAIT_CHARGES: '待目的地核费' } as Record<string, string>)[value] || label })) },
|
||||
]
|
||||
const columns: DataTableColumn[] = [
|
||||
{ key: 'actions', label: '操作', width: 90, fixed: 'left', slotName: 'actions' },
|
||||
{ prop: 'procurementDirection', label: '采购方向', minWidth: 170, slotName: 'direction' },
|
||||
{ prop: 'orderNo', label: '采购单号', minWidth: 250, slotName: 'orderNo' },
|
||||
{ prop: 'purchaseCategory', label: '采购品类', width: 120 }, { prop: 'productName', label: '商品名称', minWidth: 200 },
|
||||
{ prop: 'productSpecification', label: '商品规格', minWidth: 160 }, { prop: 'purchaseQuantity', label: '采购数量(件)', width: 135 },
|
||||
@@ -104,23 +105,25 @@ onBeforeUnmount(() => { active = false; ++requestSequence })
|
||||
<template v-if="error" #error><div class="procurement-error" role="alert"><span>{{ error }}</span><el-button :disabled="loading" @click="loadList">重新加载</el-button></div></template>
|
||||
<template #orderNo="{ row }"><button class="procurement-link" type="button" @click="openDetail(row as ProcurementSummary)">{{ (row as ProcurementSummary).orderNo || '—' }}</button></template>
|
||||
<template #budget="{ row }">{{ money((row as ProcurementSummary).budgetUnitPrice, (row as ProcurementSummary).currency) }}</template>
|
||||
<template #status="{ row }"><el-tag :type="statusTone((row as ProcurementSummary).status)" size="small">{{ statusLabel((row as ProcurementSummary).status) }}</el-tag></template>
|
||||
<template #direction="{ row }">{{ directionLabel((row as ProcurementSummary).procurementDirection) }}</template>
|
||||
<template #status="{ row }"><el-tag :type="statusTone((row as ProcurementSummary).status)" size="small">{{ statusLabel((row as ProcurementSummary).status, (row as ProcurementSummary).procurementDirection) }}</el-tag></template>
|
||||
<template #createdAt="{ row }">{{ dateTime((row as ProcurementSummary).createdAt) }}</template>
|
||||
</DataTable>
|
||||
</div>
|
||||
</template>
|
||||
<section v-else-if="mode === 'detail'" v-loading="loading" class="procurement-detail" aria-label="采购订单详情">
|
||||
<header class="procurement-heading"><div><el-button link type="primary" @click="returnToList">← 返回列表</el-button><h2>{{ detail?.order.orderNo || '采购订单详情' }}</h2></div><div><el-tag v-if="detail" :type="statusTone(detail.order.status)">{{ statusLabel(detail.order.status) }}</el-tag><el-button :disabled="loading" @click="loadDetail">刷新</el-button></div></header>
|
||||
<header class="procurement-heading"><div><el-button link type="primary" @click="returnToList">← 返回列表</el-button><h2>{{ detail?.order.orderNo || '采购订单详情' }}</h2></div><div><el-tag v-if="detail" :type="statusTone(detail.order.status)">{{ statusLabel(detail.order.status, detail.order.procurementDirection) }}</el-tag><el-button :disabled="loading" @click="loadDetail">刷新</el-button></div></header>
|
||||
<div v-if="error" class="procurement-error" role="alert"><span>{{ error }}</span><el-button :disabled="loading" @click="loadDetail">重新加载</el-button></div>
|
||||
<ProcurementDetailPanel v-else-if="detail" :detail="detail" /><el-skeleton v-else :rows="8" animated />
|
||||
</section>
|
||||
<section v-else class="procurement-create" aria-label="采购下单">
|
||||
<header class="procurement-heading"><div><h2>海外采购下单</h2><p>一单一个商品及规格;预算仅授权样品货款,运费及关税另行核定。</p></div><el-button v-if="canList" @click="returnToList">返回列表</el-button></header>
|
||||
<header class="procurement-heading"><div><h2>采购下单</h2><p>一单一个商品及规格;预算仅授权样品货款,运费及关税另行核定。</p></div><el-button v-if="canList" @click="returnToList">返回列表</el-button></header>
|
||||
<el-result v-if="!canCreate" icon="warning" title="没有采购下单权限" sub-title="请联系企业管理员配置权限" />
|
||||
<el-result v-else-if="submittedOrder" icon="success" title="采购订单已提交" :sub-title="submittedOrder"><template #extra><el-button @click="resetForm">新建另一单</el-button></template></el-result>
|
||||
<template v-else>
|
||||
<el-alert v-if="submitError" class="submit-error" :title="submitError" type="error" :closable="false" />
|
||||
<el-form :model="form" label-position="top" :disabled="submitting" @submit.prevent="submit">
|
||||
<el-form-item label="采购方向" required><el-select v-model="form.procurementDirection"><el-option v-for="(label, value) in procurementDirections" :key="value" :label="label" :value="value" /></el-select></el-form-item>
|
||||
<h3>商品与预算</h3><div class="procurement-form-grid">
|
||||
<el-form-item label="采购品类"><el-input v-model.trim="form.purchaseCategory" maxlength="128" placeholder="" /></el-form-item>
|
||||
<el-form-item label="商品名称" required><el-input v-model.trim="form.productName" maxlength="255" placeholder="" /></el-form-item>
|
||||
@@ -130,10 +133,10 @@ onBeforeUnmount(() => { active = false; ++requestSequence })
|
||||
<el-form-item label="预算币种" required><el-select v-model="form.currency"><el-option label="美元 USD" value="USD" /><el-option label="人民币 CNY" value="CNY" /></el-select></el-form-item>
|
||||
<el-form-item class="full" label="商品链接"><el-input v-model.trim="form.productUrl" maxlength="2000" placeholder="https://…" /></el-form-item>
|
||||
</div><p class="procurement-hint">货款预算总上限:<strong>{{ money(draftBudgetTotal(form), form.currency) }}</strong>。零预算仅授权免费样品;实际货款按供应商实付核定。</p>
|
||||
<h3>最终国内收件资料</h3><div class="procurement-form-grid">
|
||||
<h3>{{ regionText('最终国内收件资料', form.procurementDirection) }}</h3><div class="procurement-form-grid">
|
||||
<el-form-item label="收件人" required><el-input v-model.trim="form.contactName" maxlength="128" placeholder="实际收件人姓名" /></el-form-item>
|
||||
<el-form-item label="联系电话" required><el-input v-model.trim="form.contactPhone" maxlength="64" type="tel" placeholder="快递可联系的电话" /></el-form-item>
|
||||
<el-form-item class="full" label="完整国内地址" required><el-input v-model.trim="form.receivingAddress" maxlength="1000" placeholder="省、市、区县、街道及详细门牌" /></el-form-item>
|
||||
<el-form-item class="full" :label="regionText('完整国内地址', form.procurementDirection)" required><el-input v-model.trim="form.receivingAddress" maxlength="1000" :placeholder="form.procurementDirection === 'DOMESTIC_TO_OVERSEAS' ? '国家、州/省、市、邮编及详细地址' : '省、市、区县、街道及详细门牌'" /></el-form-item>
|
||||
<el-form-item class="full" label="采购要求"><el-input v-model="form.remark" type="textarea" :rows="3" maxlength="1000" show-word-limit placeholder="" /></el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
Reference in New Issue
Block a user