feat: 支持快递报价 Excel 导入与标准模板下载

This commit is contained in:
2026-10-22 14:21:11 +08:00
parent 49bbaa7362
commit 3f8f066a7c
7 changed files with 246 additions and 21 deletions
@@ -0,0 +1,198 @@
<script lang="ts" setup>
import type { ExpressQuoteVO } from '#/api/ec/express-quote';
import { computed, ref } from 'vue';
import {
Collapse,
CollapsePanel,
Descriptions,
DescriptionsItem,
Drawer,
Empty,
Spin,
Table,
Tag,
message,
} from 'ant-design-vue';
import { getExpressQuoteDetailApi } from '#/api/ec/express-quote';
defineOptions({ name: 'ExpressQuoteDetailDrawer' });
const MODE_LABEL: Record<string, string> = {
FLAT: '一口价',
PER_KG: '按千克',
REGION_WEIGHT: '分区×重量带',
};
const openFlag = ref(false);
const loading = ref(false);
const detail = ref<ExpressQuoteVO.Info | null>(null);
const versions = computed(() => detail.value?.versions ?? []);
const bandColumns = [
{
title: '重量(克)',
key: 'weight',
customRender: ({ record }: { record: ExpressQuoteVO.Band }) =>
formatWeightRange(record.weightFromG, record.weightToG),
},
{
title: '方式',
key: 'priceMode',
customRender: ({ record }: { record: ExpressQuoteVO.Band }) =>
record.priceMode === 'FIRST_PLUS_KG' ? '首重+续重/kg' : '元/票',
},
{
title: '价格',
key: 'price',
customRender: ({ record }: { record: ExpressQuoteVO.Band }) =>
formatBandPrice(record),
},
];
function formatWeightRange(from?: number, to?: number | null) {
const f = from ?? 0;
if (to == null) return `${f}g+`;
return `${f}–${to}g`;
}
function formatBandPrice(b: ExpressQuoteVO.Band) {
if (b.priceMode === 'FIRST_PLUS_KG') {
return `${b.firstAmount ?? 0} + ${b.continuePerKg ?? 0}元/kg(首重${b.firstWeightG ?? 0}g)`;
}
return `${b.flatAmount ?? 0} 元/票`;
}
function money(v?: number | null) {
if (v == null || Number.isNaN(Number(v))) return '—';
return `¥${Number(v).toFixed(2)}`;
}
async function open(id: number) {
openFlag.value = true;
loading.value = true;
detail.value = null;
try {
detail.value = await getExpressQuoteDetailApi(id);
} catch (error) {
console.error(error);
message.error('加载报价详情失败');
openFlag.value = false;
} finally {
loading.value = false;
}
}
function close() {
openFlag.value = false;
}
defineExpose({ open, close });
</script>
<template>
<Drawer
v-model:open="openFlag"
:title="detail ? `报价详情 · ${detail.name}` : '报价详情'"
width="820"
destroy-on-close
>
<Spin :spinning="loading">
<template v-if="detail">
<Descriptions bordered :column="2" size="small" class="mb-4">
<DescriptionsItem label="编码">{{ detail.code }}</DescriptionsItem>
<DescriptionsItem label="承运商">
{{ detail.carrierCode }}
</DescriptionsItem>
<DescriptionsItem label="计费模式">
{{ MODE_LABEL[detail.billingMode] || detail.billingMode }}
</DescriptionsItem>
<DescriptionsItem label="状态">
<Tag :color="detail.status === 1 ? 'green' : 'red'">
{{ detail.status === 1 ? '启用' : '停用' }}
</Tag>
</DescriptionsItem>
<DescriptionsItem label="创建时间">
{{ detail.createTime || '—' }}
</DescriptionsItem>
<DescriptionsItem label="备注" :span="2">
{{ detail.remark || '—' }}
</DescriptionsItem>
</Descriptions>
<div class="mb-2 text-sm font-medium">版本历史(按生效日)</div>
<Empty v-if="!versions.length" description="暂无版本" />
<Collapse v-else accordion :default-active-key="[String(versions[0]?.id)]">
<CollapsePanel
v-for="v in versions"
:key="String(v.id)"
:header="`生效 ${v.effectiveFrom}${v.id === detail.currentVersion?.id ? '(当前)' : ''}`"
>
<Descriptions bordered :column="2" size="small" class="mb-3">
<DescriptionsItem
v-if="detail.billingMode === 'FLAT'"
label="一口价"
>
{{ money(v.flatAmount) }}
({{ v.unitScope === 'PIECE' ? '每件' : '每单' }})
</DescriptionsItem>
<template v-else-if="detail.billingMode === 'PER_KG'">
<DescriptionsItem label="元/kg">
{{ v.pricePerKg ?? '—' }}
</DescriptionsItem>
<DescriptionsItem label="最低消费">
{{ money(v.minAmount) }}
</DescriptionsItem>
</template>
<DescriptionsItem label="体积重">
{{ v.useVolumetric === 1 ? '启用' : '关闭' }}
(除数 {{ v.volumeDivisor ?? 6000 }})
</DescriptionsItem>
<DescriptionsItem label="计费重取整">
{{ v.weightRound === 'CEIL_KG' ? '向上整千克' : '不取整' }}
</DescriptionsItem>
<DescriptionsItem v-if="v.remark" label="版本备注" :span="2">
{{ v.remark }}
</DescriptionsItem>
</Descriptions>
<template v-if="detail.billingMode === 'REGION_WEIGHT'">
<div
v-for="(region, ri) in v.regions || []"
:key="region.id ?? ri"
class="mb-3 rounded border border-border p-3"
>
<div class="mb-2 flex flex-wrap items-center gap-2 text-sm">
<span class="font-medium">{{ region.regionName }}</span>
<Tag v-if="region.zoneLabel" color="blue">
{{ region.zoneLabel }}
</Tag>
<Tag v-if="region.isDefault === 1">默认分区</Tag>
</div>
<div class="mb-2 text-xs text-muted-foreground">
目的地:{{ (region.provinces || []).join('、') || '—' }}
</div>
<Table
size="small"
:pagination="false"
:columns="bandColumns"
:data-source="region.bands || []"
:row-key="
(r: ExpressQuoteVO.Band, i: number) => String(r.id ?? i)
"
/>
</div>
<Empty
v-if="!(v.regions && v.regions.length)"
description="该版本无分区"
/>
</template>
</CollapsePanel>
</Collapse>
</template>
</Spin>
</Drawer>
</template>
@@ -163,7 +163,7 @@ defineExpose({ open });
<Button>选择文件</Button>
</Upload>
<div class="mt-1 text-xs text-muted-foreground">
支持标准模板或承运商矩阵报价单;不可解析单元格将整单失败
支持标准模板或承运商矩阵;「发/转单」文案与无价格行会跳过并警告
</div>
</FormItem>
@@ -181,7 +181,14 @@ defineExpose({ open });
show-icon
class="mb-3"
:message="`可导入:${preview.regionCount} 分区,${preview.destinationCount} 目的地,共 ${preview.bandCount} 条重量带`"
:description="(preview.warnings || []).join('\n') || undefined"
/>
<Alert
v-if="preview?.warnings?.length"
type="warning"
show-icon
class="mb-3 whitespace-pre-wrap"
:message="`已跳过 ${preview.warnings.length} 处,请核对`"
:description="preview.warnings.join('\n')"
/>
<div
@@ -22,6 +22,7 @@ import {
useActionColumnVisible,
} from '#/composables/use-vxe-action-column';
import ExpressQuoteDetailDrawer from './components/ExpressQuoteDetailDrawer.vue';
import ExpressQuoteFormModal from './components/ExpressQuoteFormModal.vue';
import ExpressQuoteImportModal from './components/ExpressQuoteImportModal.vue';
@@ -35,6 +36,9 @@ const formModalRef = ref<InstanceType<typeof ExpressQuoteFormModal> | null>(
const importModalRef = ref<InstanceType<typeof ExpressQuoteImportModal> | null>(
null,
);
const detailDrawerRef = ref<InstanceType<
typeof ExpressQuoteDetailDrawer
> | null>(null);
const searchForm = ref({
keywords: '',
billingMode: undefined as string | undefined,
@@ -43,6 +47,7 @@ const searchForm = ref({
const gridReloadRef = ref<(() => void) | null>(null);
const actionCodes = [
'ec:express-quote:read',
'ec:express-quote:create',
'ec:express-quote:update',
'ec:express-quote:delete',
@@ -67,7 +72,7 @@ const actionColumn: NonNullable<
VxeGridProps<ExpressQuoteVO.Info>['columns']
>[number] = {
title: '操作',
minWidth: 160,
minWidth: 220,
fixed: 'right' as const,
slots: { default: 'action' },
};
@@ -209,6 +214,11 @@ async function handleDelete(row: ExpressQuoteVO.Info) {
#action="{ row }: { row: ExpressQuoteVO.Info }"
>
<Space>
<PermissionGate code="ec:express-quote:read">
<Button size="small" @click="detailDrawerRef?.open(row.id)">
详情
</Button>
</PermissionGate>
<PermissionGate code="ec:express-quote:update">
<Button size="small" @click="formModalRef?.open(true, row)">
编辑/调价
@@ -227,5 +237,6 @@ async function handleDelete(row: ExpressQuoteVO.Info) {
ref="importModalRef"
@success="gridApi.reload()"
/>
<ExpressQuoteDetailDrawer ref="detailDrawerRef" />
</Page>
</template>