mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
feat: 快递报价改为独立编辑页并优化分区双栏布局
This commit is contained in:
@@ -15,6 +15,28 @@ import { $t } from '#/locales';
|
||||
|
||||
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
||||
|
||||
/** 编辑类 embedded 路由:侧栏高亮回列表菜单 */
|
||||
const ACTIVE_PATH_BY_ROUTE_NAME: Record<string, string> = {
|
||||
ExpressQuoteEdit: '/ec/warehouse/express-quote',
|
||||
};
|
||||
|
||||
/** 就地写入 activePath,避免 mapTree 展开 meta 后 title 被推断成 string | undefined */
|
||||
function enrichRouteMeta(
|
||||
routes: RouteRecordStringComponent[],
|
||||
): RouteRecordStringComponent[] {
|
||||
for (const node of routes) {
|
||||
const name = String(node.name ?? '');
|
||||
const activePath = ACTIVE_PATH_BY_ROUTE_NAME[name];
|
||||
if (activePath && node.meta) {
|
||||
node.meta.activePath = activePath;
|
||||
}
|
||||
if (node.children?.length) {
|
||||
enrichRouteMeta(node.children as RouteRecordStringComponent[]);
|
||||
}
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
|
||||
/** 将 glob key 规范成与后端 component 一致的 /xxx/index.vue */
|
||||
function normalizePageKey(path: string): string {
|
||||
const normalized = path.replace(/^(\.\/|\.\.\/)+/, '');
|
||||
@@ -83,7 +105,9 @@ async function generateAccess(
|
||||
}
|
||||
try {
|
||||
const routes = await getUserMenuApi();
|
||||
return filterMissingPageRoutes(routes || [], pageMap, layoutMap);
|
||||
return enrichRouteMeta(
|
||||
filterMissingPageRoutes(routes || [], pageMap, layoutMap),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('❌ 获取用户菜单路由失败:', error);
|
||||
throw error;
|
||||
|
||||
-486
@@ -1,486 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ExpressQuoteDTO, ExpressQuoteVO } from '#/api/ec/express-quote';
|
||||
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
FormItem,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
Switch,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createExpressQuoteApi,
|
||||
getExpressCarriersApi,
|
||||
getExpressProvincesApi,
|
||||
getExpressQuoteDetailApi,
|
||||
updateExpressQuoteApi,
|
||||
upsertExpressQuoteVersionApi,
|
||||
} from '#/api/ec/express-quote';
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
interface BandRow {
|
||||
weightFromG: number;
|
||||
weightToG: number | null;
|
||||
priceMode: string;
|
||||
flatAmount: number;
|
||||
firstWeightG: number;
|
||||
firstAmount: number;
|
||||
continuePerKg: number;
|
||||
}
|
||||
|
||||
interface RegionRow {
|
||||
regionName: string;
|
||||
zoneLabel: string;
|
||||
provinces: string[];
|
||||
isDefault: boolean;
|
||||
bands: BandRow[];
|
||||
}
|
||||
|
||||
function emptyBand(fromG = 0): BandRow {
|
||||
return {
|
||||
weightFromG: fromG,
|
||||
weightToG: null,
|
||||
priceMode: 'FLAT_TICKET',
|
||||
flatAmount: 0,
|
||||
firstWeightG: 0,
|
||||
firstAmount: 0,
|
||||
continuePerKg: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function emptyRegion(): RegionRow {
|
||||
return {
|
||||
regionName: '默认区',
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
isDefault: true,
|
||||
bands: [emptyBand(0)],
|
||||
};
|
||||
}
|
||||
|
||||
const isEdit = ref(false);
|
||||
const editingId = ref<number>();
|
||||
const carriers = ref<ExpressQuoteVO.CarrierOption[]>([]);
|
||||
const provinces = ref<ExpressQuoteVO.ProvinceOption[]>([]);
|
||||
|
||||
const form = reactive({
|
||||
code: '',
|
||||
name: '',
|
||||
carrierCode: 'ZTO',
|
||||
billingMode: 'FLAT',
|
||||
status: 1,
|
||||
remark: '',
|
||||
effectiveFrom: new Date().toISOString().slice(0, 10),
|
||||
flatAmount: 0,
|
||||
unitScope: 'ORDER',
|
||||
pricePerKg: 0,
|
||||
minAmount: undefined as number | undefined,
|
||||
volumeDivisor: 6000,
|
||||
useVolumetric: false,
|
||||
weightRound: 'NONE',
|
||||
regions: [emptyRegion()] as RegionRow[],
|
||||
});
|
||||
|
||||
const isRegion = computed(() => form.billingMode === 'REGION_WEIGHT');
|
||||
const isFlat = computed(() => form.billingMode === 'FLAT');
|
||||
const isPerKg = computed(() => form.billingMode === 'PER_KG');
|
||||
|
||||
const provinceOptions = computed(() =>
|
||||
provinces.value.map((p) => ({ value: p.code, label: p.name })),
|
||||
);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
onConfirm: handleSubmit,
|
||||
onOpenChange: (open) => {
|
||||
if (!open) reset();
|
||||
},
|
||||
});
|
||||
|
||||
function reset() {
|
||||
Object.assign(form, {
|
||||
code: '',
|
||||
name: '',
|
||||
carrierCode: 'ZTO',
|
||||
billingMode: 'FLAT',
|
||||
status: 1,
|
||||
remark: '',
|
||||
effectiveFrom: new Date().toISOString().slice(0, 10),
|
||||
flatAmount: 0,
|
||||
unitScope: 'ORDER',
|
||||
pricePerKg: 0,
|
||||
minAmount: undefined,
|
||||
volumeDivisor: 6000,
|
||||
useVolumetric: false,
|
||||
weightRound: 'NONE',
|
||||
});
|
||||
form.regions = [emptyRegion()];
|
||||
isEdit.value = false;
|
||||
editingId.value = undefined;
|
||||
}
|
||||
|
||||
async function ensureMeta() {
|
||||
if (!carriers.value.length) {
|
||||
carriers.value = await getExpressCarriersApi();
|
||||
}
|
||||
if (!provinces.value.length) {
|
||||
provinces.value = await getExpressProvincesApi();
|
||||
}
|
||||
}
|
||||
|
||||
function fillFromVersion(v?: ExpressQuoteVO.Version) {
|
||||
if (!v) return;
|
||||
form.effectiveFrom = v.effectiveFrom;
|
||||
form.flatAmount = v.flatAmount ?? 0;
|
||||
form.unitScope = v.unitScope || 'ORDER';
|
||||
form.pricePerKg = v.pricePerKg ?? 0;
|
||||
form.minAmount = v.minAmount;
|
||||
form.volumeDivisor = v.volumeDivisor ?? 6000;
|
||||
form.useVolumetric = v.useVolumetric === 1;
|
||||
form.weightRound = v.weightRound || 'NONE';
|
||||
if (v.regions?.length) {
|
||||
form.regions = v.regions.map((r) => ({
|
||||
regionName: r.regionName,
|
||||
zoneLabel: r.zoneLabel || '',
|
||||
provinces: r.provinces ? [...r.provinces] : [],
|
||||
isDefault: r.isDefault === 1,
|
||||
bands:
|
||||
r.bands?.length ?
|
||||
r.bands.map((b) => ({
|
||||
weightFromG: b.weightFromG ?? 0,
|
||||
weightToG: b.weightToG ?? null,
|
||||
priceMode: b.priceMode || 'FLAT_TICKET',
|
||||
flatAmount: b.flatAmount ?? 0,
|
||||
firstWeightG: b.firstWeightG ?? 0,
|
||||
firstAmount: b.firstAmount ?? 0,
|
||||
continuePerKg: b.continuePerKg ?? 0,
|
||||
}))
|
||||
: [emptyBand(0)],
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
async function open(edit: boolean, row?: ExpressQuoteVO.Info) {
|
||||
await ensureMeta();
|
||||
isEdit.value = edit;
|
||||
if (edit && row) {
|
||||
editingId.value = row.id;
|
||||
const detail = await getExpressQuoteDetailApi(row.id);
|
||||
form.code = detail.code;
|
||||
form.name = detail.name;
|
||||
form.carrierCode = detail.carrierCode;
|
||||
form.billingMode = detail.billingMode;
|
||||
form.status = detail.status;
|
||||
form.remark = detail.remark || '';
|
||||
fillFromVersion(detail.currentVersion);
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
modalApi.setState({
|
||||
title: edit ? '编辑报价单' : '新建报价单',
|
||||
class: form.billingMode === 'REGION_WEIGHT' ? 'w-[920px]' : 'w-[640px]',
|
||||
});
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
function addRegion() {
|
||||
form.regions.push({
|
||||
regionName: `分区${form.regions.length + 1}`,
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
isDefault: false,
|
||||
bands: [emptyBand(0)],
|
||||
});
|
||||
}
|
||||
|
||||
function removeRegion(idx: number) {
|
||||
if (form.regions.length <= 1) {
|
||||
message.warning('至少保留一个分区');
|
||||
return;
|
||||
}
|
||||
form.regions.splice(idx, 1);
|
||||
}
|
||||
|
||||
function addBand(region: RegionRow) {
|
||||
const last = region.bands[region.bands.length - 1];
|
||||
const nextFrom =
|
||||
last?.weightToG != null ? last.weightToG + 1 : (last?.weightFromG ?? 0) + 1000;
|
||||
region.bands.push(emptyBand(nextFrom));
|
||||
}
|
||||
|
||||
function removeBand(region: RegionRow, idx: number) {
|
||||
if (region.bands.length <= 1) {
|
||||
message.warning('每分区至少一条重量带');
|
||||
return;
|
||||
}
|
||||
region.bands.splice(idx, 1);
|
||||
}
|
||||
|
||||
function buildVersion(): ExpressQuoteDTO.VersionUpsert {
|
||||
const version: ExpressQuoteDTO.VersionUpsert = {
|
||||
effectiveFrom: form.effectiveFrom,
|
||||
volumeDivisor: form.volumeDivisor,
|
||||
useVolumetric: form.useVolumetric ? 1 : 0,
|
||||
weightRound: form.weightRound,
|
||||
};
|
||||
if (form.billingMode === 'FLAT') {
|
||||
version.flatAmount = form.flatAmount;
|
||||
version.unitScope = form.unitScope;
|
||||
} else if (form.billingMode === 'PER_KG') {
|
||||
version.pricePerKg = form.pricePerKg;
|
||||
version.minAmount = form.minAmount;
|
||||
} else {
|
||||
version.regions = form.regions.map((r, i) => ({
|
||||
regionName: r.regionName.trim() || `分区${i + 1}`,
|
||||
zoneLabel: r.zoneLabel.trim() || undefined,
|
||||
provinces: r.provinces,
|
||||
isDefault: r.isDefault ? 1 : 0,
|
||||
sortOrder: i,
|
||||
bands: r.bands.map((b, bi) => ({
|
||||
weightFromG: b.weightFromG ?? 0,
|
||||
weightToG: b.weightToG,
|
||||
priceMode: b.priceMode,
|
||||
flatAmount: b.priceMode === 'FLAT_TICKET' ? b.flatAmount : undefined,
|
||||
firstWeightG: b.priceMode === 'FIRST_PLUS_KG' ? b.firstWeightG : undefined,
|
||||
firstAmount: b.priceMode === 'FIRST_PLUS_KG' ? b.firstAmount : undefined,
|
||||
continuePerKg: b.priceMode === 'FIRST_PLUS_KG' ? b.continuePerKg : undefined,
|
||||
sortOrder: bi,
|
||||
})),
|
||||
}));
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!form.name.trim() || (!isEdit.value && !form.code.trim())) {
|
||||
message.warning('请填写编码与名称');
|
||||
return;
|
||||
}
|
||||
if (isRegion.value) {
|
||||
for (const r of form.regions) {
|
||||
if (!r.bands.length) {
|
||||
message.warning(`分区「${r.regionName}」至少一条重量带`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
modalApi.setState({ confirming: true });
|
||||
try {
|
||||
if (isEdit.value && editingId.value) {
|
||||
await updateExpressQuoteApi(editingId.value, {
|
||||
name: form.name.trim(),
|
||||
carrierCode: form.carrierCode,
|
||||
status: form.status,
|
||||
remark: form.remark || undefined,
|
||||
});
|
||||
if (form.effectiveFrom) {
|
||||
await upsertExpressQuoteVersionApi(editingId.value, buildVersion());
|
||||
}
|
||||
message.success('已更新');
|
||||
} else {
|
||||
await createExpressQuoteApi({
|
||||
code: form.code.trim(),
|
||||
name: form.name.trim(),
|
||||
carrierCode: form.carrierCode,
|
||||
billingMode: form.billingMode,
|
||||
status: form.status,
|
||||
remark: form.remark || undefined,
|
||||
initialVersion: buildVersion(),
|
||||
});
|
||||
message.success('创建成功');
|
||||
}
|
||||
modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.setState({ confirming: false });
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form layout="vertical" class="max-h-[75vh] overflow-y-auto px-1">
|
||||
<FormItem v-if="!isEdit" label="报价编码" required>
|
||||
<Input v-model:value="form.code" />
|
||||
</FormItem>
|
||||
<FormItem label="名称" required>
|
||||
<Input v-model:value="form.name" />
|
||||
</FormItem>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<FormItem label="承运商" required>
|
||||
<Select
|
||||
v-model:value="form.carrierCode"
|
||||
:options="carriers.map((c) => ({ value: c.code, label: c.name }))"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label="计费模式" required>
|
||||
<Select
|
||||
v-model:value="form.billingMode"
|
||||
:disabled="isEdit"
|
||||
:options="[
|
||||
{ value: 'FLAT', label: '一口价 FLAT' },
|
||||
{ value: 'PER_KG', label: '按千克 PER_KG' },
|
||||
{ value: 'REGION_WEIGHT', label: '分区×重量带' },
|
||||
]"
|
||||
/>
|
||||
</FormItem>
|
||||
</div>
|
||||
<FormItem label="状态">
|
||||
<Select
|
||||
v-model:value="form.status"
|
||||
:options="[
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '停用', value: 0 },
|
||||
]"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label="生效日(版本)" required>
|
||||
<Input v-model:value="form.effectiveFrom" placeholder="yyyy-MM-dd" />
|
||||
</FormItem>
|
||||
<template v-if="isFlat">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<FormItem label="一口价(元)">
|
||||
<InputNumber v-model:value="form.flatAmount" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
<FormItem label="计费单位">
|
||||
<Select
|
||||
v-model:value="form.unitScope"
|
||||
:options="[
|
||||
{ value: 'ORDER', label: '每单' },
|
||||
{ value: 'PIECE', label: '每件' },
|
||||
]"
|
||||
/>
|
||||
</FormItem>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="isPerKg">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<FormItem label="元/kg">
|
||||
<InputNumber v-model:value="form.pricePerKg" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
<FormItem label="最低消费">
|
||||
<InputNumber v-model:value="form.minAmount" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="isRegion">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm text-muted-foreground">目的分区 × 重量带(对齐承运商报价矩阵)</span>
|
||||
<Button size="small" type="dashed" @click="addRegion">添加分区</Button>
|
||||
</div>
|
||||
<div
|
||||
v-for="(region, ri) in form.regions"
|
||||
:key="ri"
|
||||
class="mb-3 rounded border border-border p-3"
|
||||
>
|
||||
<div class="mb-2 flex items-start justify-between gap-2">
|
||||
<div class="grid flex-1 grid-cols-3 gap-2">
|
||||
<FormItem label="分区名" class="mb-0">
|
||||
<Input v-model:value="region.regionName" />
|
||||
</FormItem>
|
||||
<FormItem label="价区标签" class="mb-0">
|
||||
<Input v-model:value="region.zoneLabel" placeholder="一类/二类…" />
|
||||
</FormItem>
|
||||
<FormItem label="默认分区" class="mb-0">
|
||||
<Switch v-model:checked="region.isDefault" />
|
||||
</FormItem>
|
||||
</div>
|
||||
<Button size="small" danger type="link" @click="removeRegion(ri)">删除</Button>
|
||||
</div>
|
||||
<FormItem label="目的地(省或市)" class="mb-2">
|
||||
<Select
|
||||
v-model:value="region.provinces"
|
||||
mode="tags"
|
||||
allow-clear
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:options="provinceOptions"
|
||||
placeholder="选省或输入市名如深圳市"
|
||||
/>
|
||||
</FormItem>
|
||||
<div class="mb-1 flex items-center justify-between">
|
||||
<span class="text-xs text-muted-foreground">重量带</span>
|
||||
<Button size="small" type="link" @click="addBand(region)">加带</Button>
|
||||
</div>
|
||||
<div
|
||||
v-for="(band, bi) in region.bands"
|
||||
:key="bi"
|
||||
class="mb-2 grid grid-cols-12 items-end gap-2 rounded bg-muted/40 p-2"
|
||||
>
|
||||
<FormItem label="从(克)" class="col-span-2 mb-0">
|
||||
<InputNumber v-model:value="band.weightFromG" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
<FormItem label="到(克)" class="col-span-2 mb-0">
|
||||
<InputNumber
|
||||
v-model:value="band.weightToG"
|
||||
:min="0"
|
||||
class="w-full"
|
||||
placeholder="空=无上限"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label="方式" class="col-span-3 mb-0">
|
||||
<Select
|
||||
v-model:value="band.priceMode"
|
||||
:options="[
|
||||
{ value: 'FLAT_TICKET', label: '元/票' },
|
||||
{ value: 'FIRST_PLUS_KG', label: '首重+续重/kg' },
|
||||
]"
|
||||
/>
|
||||
</FormItem>
|
||||
<template v-if="band.priceMode === 'FLAT_TICKET'">
|
||||
<FormItem label="元/票" class="col-span-3 mb-0">
|
||||
<InputNumber v-model:value="band.flatAmount" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
</template>
|
||||
<template v-else>
|
||||
<FormItem label="首重克" class="col-span-1 mb-0">
|
||||
<InputNumber v-model:value="band.firstWeightG" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
<FormItem label="首重价" class="col-span-2 mb-0">
|
||||
<InputNumber v-model:value="band.firstAmount" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
<FormItem label="续重元/kg" class="col-span-2 mb-0">
|
||||
<InputNumber v-model:value="band.continuePerKg" :min="0" class="w-full" />
|
||||
</FormItem>
|
||||
</template>
|
||||
<div class="col-span-2 flex justify-end pb-1">
|
||||
<Button size="small" type="link" danger @click="removeBand(region, bi)">
|
||||
删带
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="grid grid-cols-3 gap-3">
|
||||
<FormItem label="启用体积重">
|
||||
<Switch v-model:checked="form.useVolumetric" />
|
||||
</FormItem>
|
||||
<FormItem label="体积重除数">
|
||||
<InputNumber v-model:value="form.volumeDivisor" :min="1" class="w-full" />
|
||||
</FormItem>
|
||||
<FormItem label="计费重取整">
|
||||
<Select
|
||||
v-model:value="form.weightRound"
|
||||
:options="[
|
||||
{ value: 'NONE', label: '不取整' },
|
||||
{ value: 'CEIL_KG', label: '向上整千克' },
|
||||
]"
|
||||
/>
|
||||
</FormItem>
|
||||
</div>
|
||||
<FormItem label="备注">
|
||||
<Input.TextArea v-model:value="form.remark" :rows="2" />
|
||||
</FormItem>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 分区×重量带编辑:动态嵌套用 antd Card/Table;左侧 Anchor 快速跳转分区。
|
||||
*/
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import {
|
||||
Anchor,
|
||||
Button,
|
||||
Card,
|
||||
Input,
|
||||
InputNumber,
|
||||
Select,
|
||||
Space,
|
||||
Switch,
|
||||
Table,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
export interface BandRow {
|
||||
weightFromG: number;
|
||||
weightToG: number | null;
|
||||
priceMode: string;
|
||||
flatAmount: number;
|
||||
firstWeightG: number;
|
||||
firstAmount: number;
|
||||
continuePerKg: number;
|
||||
}
|
||||
|
||||
export interface RegionRow {
|
||||
regionName: string;
|
||||
zoneLabel: string;
|
||||
provinces: string[];
|
||||
isDefault: boolean;
|
||||
bands: BandRow[];
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: RegionRow[];
|
||||
provinceOptions: { label: string; value: string }[];
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: RegionRow[]];
|
||||
}>();
|
||||
|
||||
defineOptions({ name: 'RegionBandEditor' });
|
||||
|
||||
const scrollRef = ref<HTMLElement | null>(null);
|
||||
|
||||
const regions = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v),
|
||||
});
|
||||
|
||||
const anchorItems = computed(() =>
|
||||
regions.value.map((r, i) => ({
|
||||
key: `region-${i}`,
|
||||
href: `#quote-region-${i}`,
|
||||
title: r.zoneLabel || r.regionName || `分区${i + 1}`,
|
||||
})),
|
||||
);
|
||||
|
||||
function getScrollContainer() {
|
||||
return scrollRef.value || window;
|
||||
}
|
||||
|
||||
const bandColumnDefs = [
|
||||
{ title: '从(克)', key: 'from', width: 110 },
|
||||
{ title: '到(克)', key: 'to', width: 110 },
|
||||
{ title: '方式', key: 'mode', width: 150 },
|
||||
{ title: '价格', key: 'price' },
|
||||
{ title: '操作', key: 'action', width: 72 },
|
||||
];
|
||||
|
||||
function emptyBand(fromG = 0): BandRow {
|
||||
return {
|
||||
weightFromG: fromG,
|
||||
weightToG: null,
|
||||
priceMode: 'FLAT_TICKET',
|
||||
flatAmount: 0,
|
||||
firstWeightG: 0,
|
||||
firstAmount: 0,
|
||||
continuePerKg: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function addRegion() {
|
||||
const nextIndex = regions.value.length;
|
||||
regions.value = [
|
||||
...regions.value,
|
||||
{
|
||||
regionName: `分区${nextIndex + 1}`,
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
isDefault: false,
|
||||
bands: [emptyBand(0)],
|
||||
},
|
||||
];
|
||||
void nextTick(() => {
|
||||
document
|
||||
.getElementById(`quote-region-${nextIndex}`)
|
||||
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
});
|
||||
}
|
||||
|
||||
function removeRegion(idx: number) {
|
||||
if (regions.value.length <= 1) {
|
||||
message.warning('至少保留一个分区');
|
||||
return;
|
||||
}
|
||||
const next = [...regions.value];
|
||||
next.splice(idx, 1);
|
||||
regions.value = next;
|
||||
}
|
||||
|
||||
function patchRegion(idx: number, patch: Partial<RegionRow>) {
|
||||
const next = [...regions.value];
|
||||
const cur = next[idx];
|
||||
if (!cur) return;
|
||||
next[idx] = { ...cur, ...patch };
|
||||
regions.value = next;
|
||||
}
|
||||
|
||||
function addBand(ri: number) {
|
||||
const region = regions.value[ri];
|
||||
if (!region) return;
|
||||
const last = region.bands[region.bands.length - 1];
|
||||
const nextFrom =
|
||||
last?.weightToG != null ? last.weightToG + 1 : (last?.weightFromG ?? 0) + 1000;
|
||||
patchRegion(ri, { bands: [...region.bands, emptyBand(nextFrom)] });
|
||||
}
|
||||
|
||||
function removeBand(ri: number, bi: number) {
|
||||
const region = regions.value[ri];
|
||||
if (!region) return;
|
||||
if (region.bands.length <= 1) {
|
||||
message.warning('每分区至少一条重量带');
|
||||
return;
|
||||
}
|
||||
const bands = [...region.bands];
|
||||
bands.splice(bi, 1);
|
||||
patchRegion(ri, { bands });
|
||||
}
|
||||
|
||||
function patchBand(ri: number, bi: number, patch: Partial<BandRow>) {
|
||||
const region = regions.value[ri];
|
||||
if (!region) return;
|
||||
const bands = region.bands.map((b, i) => (i === bi ? { ...b, ...patch } : b));
|
||||
patchRegion(ri, { bands });
|
||||
}
|
||||
|
||||
function onAnchorClick(e: Event) {
|
||||
e.preventDefault();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
size="small"
|
||||
title="目的分区 × 重量带"
|
||||
class="flex h-full min-h-0 flex-col overflow-hidden"
|
||||
:body-style="{
|
||||
flex: '1 1 0%',
|
||||
minHeight: 0,
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
padding: '12px',
|
||||
}"
|
||||
>
|
||||
<template #extra>
|
||||
<Button size="small" type="dashed" @click="addRegion">添加分区</Button>
|
||||
</template>
|
||||
<div class="flex min-h-0 flex-1 gap-3">
|
||||
<aside
|
||||
class="w-36 shrink-0 overflow-y-auto border-r border-border pr-2 pt-1"
|
||||
>
|
||||
<div class="mb-2 text-xs text-muted-foreground">分区导航</div>
|
||||
<Anchor
|
||||
:affix="false"
|
||||
:items="anchorItems"
|
||||
:get-container="getScrollContainer"
|
||||
@click="onAnchorClick"
|
||||
/>
|
||||
</aside>
|
||||
<div ref="scrollRef" class="min-h-0 min-w-0 flex-1 overflow-y-auto">
|
||||
<Card
|
||||
v-for="(region, ri) in regions"
|
||||
:id="`quote-region-${ri}`"
|
||||
:key="ri"
|
||||
size="small"
|
||||
class="mb-3 shrink-0 scroll-mt-2"
|
||||
:title="region.regionName || `分区${ri + 1}`"
|
||||
>
|
||||
<template #extra>
|
||||
<Button type="link" danger size="small" @click="removeRegion(ri)">
|
||||
删除分区
|
||||
</Button>
|
||||
</template>
|
||||
<div class="mb-3 grid grid-cols-1 gap-3 md:grid-cols-4">
|
||||
<div>
|
||||
<div class="mb-1 text-xs text-muted-foreground">分区名</div>
|
||||
<Input
|
||||
:value="region.regionName"
|
||||
@update:value="(v) => patchRegion(ri, { regionName: String(v) })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-xs text-muted-foreground">价区标签</div>
|
||||
<Input
|
||||
:value="region.zoneLabel"
|
||||
placeholder="一类/二类…"
|
||||
@update:value="(v) => patchRegion(ri, { zoneLabel: String(v) })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-xs text-muted-foreground">默认分区</div>
|
||||
<Switch
|
||||
:checked="region.isDefault"
|
||||
@update:checked="(v) => patchRegion(ri, { isDefault: !!v })"
|
||||
/>
|
||||
</div>
|
||||
<div class="md:col-span-4">
|
||||
<div class="mb-1 text-xs text-muted-foreground">
|
||||
目的地(省或市)
|
||||
</div>
|
||||
<Select
|
||||
class="w-full"
|
||||
mode="tags"
|
||||
allow-clear
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:options="provinceOptions"
|
||||
:value="region.provinces"
|
||||
placeholder="选省或输入市名如深圳市"
|
||||
@update:value="
|
||||
(v) => patchRegion(ri, { provinces: (v as string[]) || [] })
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-2 flex justify-end">
|
||||
<Button size="small" type="link" @click="addBand(ri)">
|
||||
加重量带
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
size="small"
|
||||
:pagination="false"
|
||||
:columns="bandColumnDefs"
|
||||
:data-source="region.bands"
|
||||
:row-key="(_r: BandRow, i: number) => `${ri}-${i}`"
|
||||
>
|
||||
<template #bodyCell="{ column, index }">
|
||||
<template v-if="column.key === 'from'">
|
||||
<InputNumber
|
||||
class="w-full"
|
||||
:min="0"
|
||||
:value="region.bands[index]?.weightFromG"
|
||||
@update:value="
|
||||
(v) => patchBand(ri, index, { weightFromG: Number(v ?? 0) })
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'to'">
|
||||
<InputNumber
|
||||
class="w-full"
|
||||
:min="0"
|
||||
placeholder="空=无上限"
|
||||
:value="region.bands[index]?.weightToG ?? undefined"
|
||||
@update:value="
|
||||
(v) =>
|
||||
patchBand(ri, index, {
|
||||
weightToG: v == null ? null : Number(v),
|
||||
})
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'mode'">
|
||||
<Select
|
||||
class="w-full"
|
||||
:value="region.bands[index]?.priceMode"
|
||||
:options="[
|
||||
{ value: 'FLAT_TICKET', label: '元/票' },
|
||||
{ value: 'FIRST_PLUS_KG', label: '首重+续重/kg' },
|
||||
]"
|
||||
@update:value="
|
||||
(v) => patchBand(ri, index, { priceMode: String(v) })
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'price'">
|
||||
<InputNumber
|
||||
v-if="region.bands[index]?.priceMode === 'FLAT_TICKET'"
|
||||
class="w-full"
|
||||
:min="0"
|
||||
addon-after="元/票"
|
||||
:value="region.bands[index]?.flatAmount"
|
||||
@update:value="
|
||||
(v) => patchBand(ri, index, { flatAmount: Number(v ?? 0) })
|
||||
"
|
||||
/>
|
||||
<Space v-else wrap>
|
||||
<InputNumber
|
||||
class="w-28"
|
||||
:min="0"
|
||||
addon-after="首重克"
|
||||
:value="region.bands[index]?.firstWeightG"
|
||||
@update:value="
|
||||
(v) =>
|
||||
patchBand(ri, index, { firstWeightG: Number(v ?? 0) })
|
||||
"
|
||||
/>
|
||||
<InputNumber
|
||||
class="w-28"
|
||||
:min="0"
|
||||
addon-after="首重价"
|
||||
:value="region.bands[index]?.firstAmount"
|
||||
@update:value="
|
||||
(v) =>
|
||||
patchBand(ri, index, { firstAmount: Number(v ?? 0) })
|
||||
"
|
||||
/>
|
||||
<InputNumber
|
||||
class="w-28"
|
||||
:min="0"
|
||||
addon-after="续/kg"
|
||||
:value="region.bands[index]?.continuePerKg"
|
||||
@update:value="
|
||||
(v) =>
|
||||
patchBand(ri, index, { continuePerKg: Number(v ?? 0) })
|
||||
"
|
||||
/>
|
||||
</Space>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<Button
|
||||
type="link"
|
||||
danger
|
||||
size="small"
|
||||
@click="removeBand(ri, index)"
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -0,0 +1,557 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ExpressQuoteDTO, ExpressQuoteVO } from '#/api/ec/express-quote';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import { ColPage } from '@vben/common-ui';
|
||||
import { useTabs } from '@vben/hooks';
|
||||
|
||||
import { Button, Card, Empty, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createExpressQuoteApi,
|
||||
getExpressCarriersApi,
|
||||
getExpressProvincesApi,
|
||||
getExpressQuoteDetailApi,
|
||||
updateExpressQuoteApi,
|
||||
upsertExpressQuoteVersionApi,
|
||||
} from '#/api/ec/express-quote';
|
||||
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
|
||||
|
||||
import RegionBandEditor, {
|
||||
type RegionRow,
|
||||
} from './components/RegionBandEditor.vue';
|
||||
|
||||
defineOptions({ name: 'ExpressQuoteEdit' });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { setTabTitle, closeCurrentTab } = useTabs();
|
||||
|
||||
const quoteId = computed(() => {
|
||||
const raw = route.params.id;
|
||||
const id = raw ? Number(raw) : 0;
|
||||
return Number.isFinite(id) && id > 0 ? id : undefined;
|
||||
});
|
||||
const isEdit = computed(() => quoteId.value != null);
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const pageTitle = ref('快递报价单编辑「新建」');
|
||||
const provinces = ref<ExpressQuoteVO.ProvinceOption[]>([]);
|
||||
const regions = ref<RegionRow[]>([
|
||||
{
|
||||
regionName: '默认区',
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
isDefault: true,
|
||||
bands: [
|
||||
{
|
||||
weightFromG: 0,
|
||||
weightToG: null,
|
||||
priceMode: 'FLAT_TICKET',
|
||||
flatAmount: 0,
|
||||
firstWeightG: 0,
|
||||
firstAmount: 0,
|
||||
continuePerKg: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
const provinceOptions = computed(() =>
|
||||
provinces.value.map((p) => ({ value: p.code, label: p.name })),
|
||||
);
|
||||
|
||||
/** 编辑页乐观按分区模式,避免首屏按 FLAT 分栏约束被拉成对半 */
|
||||
const billingMode = ref(isEdit.value ? 'REGION_WEIGHT' : 'FLAT');
|
||||
const isRegion = computed(() => billingMode.value === 'REGION_WEIGHT');
|
||||
|
||||
async function syncTabTitle(name?: string) {
|
||||
let rawName = name;
|
||||
if (rawName == null) {
|
||||
try {
|
||||
const values = await formApi.getValues();
|
||||
rawName = values.name ? String(values.name) : undefined;
|
||||
} catch {
|
||||
rawName = undefined;
|
||||
}
|
||||
}
|
||||
const title = formatOverviewTabTitle(
|
||||
'快递报价单编辑',
|
||||
rawName,
|
||||
isEdit.value ? `#${quoteId.value}` : '新建',
|
||||
);
|
||||
pageTitle.value = title;
|
||||
await setTabTitle(title);
|
||||
}
|
||||
|
||||
/** 分区模式左栏贴最小宽;与 billingMode 乐观初始值对齐 */
|
||||
const leftWidth = ref(isEdit.value ? 22 : 50);
|
||||
|
||||
function syncLeftWidthByMode() {
|
||||
leftWidth.value = isRegion.value ? 22 : 50;
|
||||
}
|
||||
|
||||
/** 外层 Card 撑满列高,body 内滚动 */
|
||||
const cardBodyScrollStyle = {
|
||||
flex: '1 1 0%',
|
||||
minHeight: 0,
|
||||
overflowY: 'auto' as const,
|
||||
display: 'flex',
|
||||
flexDirection: 'column' as const,
|
||||
};
|
||||
|
||||
watch(isRegion, () => {
|
||||
syncLeftWidthByMode();
|
||||
});
|
||||
|
||||
const [BaseForm, formApi] = useVbenForm({
|
||||
layout: 'vertical',
|
||||
compact: true,
|
||||
commonConfig: {
|
||||
componentProps: { class: 'w-full' },
|
||||
labelClass: 'w-full',
|
||||
},
|
||||
wrapperClass: 'grid-cols-1',
|
||||
showDefaultActions: false,
|
||||
handleValuesChange(values, fieldsChanged) {
|
||||
if (fieldsChanged.includes('billingMode') && values.billingMode) {
|
||||
billingMode.value = String(values.billingMode);
|
||||
}
|
||||
if (fieldsChanged.includes('name')) {
|
||||
void syncTabTitle(String(values.name ?? ''));
|
||||
}
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'code',
|
||||
label: '报价编码',
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
show: () => !isEdit.value,
|
||||
triggerFields: ['name'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '名称',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
fieldName: 'carrierCode',
|
||||
label: '承运商',
|
||||
rules: 'selectRequired',
|
||||
defaultValue: 'ZTO',
|
||||
componentProps: {
|
||||
api: getExpressCarriersApi,
|
||||
afterFetch: (data: ExpressQuoteVO.CarrierOption[]) =>
|
||||
(data || []).map((c) => ({ label: c.name, value: c.code })),
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'billingMode',
|
||||
label: '计费模式',
|
||||
rules: 'selectRequired',
|
||||
defaultValue: 'FLAT',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ value: 'FLAT', label: '一口价 FLAT' },
|
||||
{ value: 'PER_KG', label: '按千克 PER_KG' },
|
||||
{ value: 'REGION_WEIGHT', label: '分区×重量带' },
|
||||
],
|
||||
},
|
||||
dependencies: {
|
||||
disabled: () => isEdit.value,
|
||||
triggerFields: ['name'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
defaultValue: 1,
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '停用', value: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
fieldName: 'effectiveFrom',
|
||||
label: '生效日(版本)',
|
||||
rules: 'required',
|
||||
defaultValue: new Date().toISOString().slice(0, 10),
|
||||
componentProps: {
|
||||
valueFormat: 'YYYY-MM-DD',
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'flatAmount',
|
||||
label: '一口价(元)',
|
||||
defaultValue: 0,
|
||||
dependencies: {
|
||||
if: (values) => values.billingMode === 'FLAT',
|
||||
triggerFields: ['billingMode'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'unitScope',
|
||||
label: '计费单位',
|
||||
defaultValue: 'ORDER',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ value: 'ORDER', label: '每单' },
|
||||
{ value: 'PIECE', label: '每件' },
|
||||
],
|
||||
},
|
||||
dependencies: {
|
||||
if: (values) => values.billingMode === 'FLAT',
|
||||
triggerFields: ['billingMode'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'pricePerKg',
|
||||
label: '元/kg',
|
||||
defaultValue: 0,
|
||||
dependencies: {
|
||||
if: (values) => values.billingMode === 'PER_KG',
|
||||
triggerFields: ['billingMode'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'minAmount',
|
||||
label: '最低消费',
|
||||
dependencies: {
|
||||
if: (values) => values.billingMode === 'PER_KG',
|
||||
triggerFields: ['billingMode'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Switch',
|
||||
fieldName: 'useVolumetric',
|
||||
label: '启用体积重',
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'volumeDivisor',
|
||||
label: '体积重除数',
|
||||
defaultValue: 6000,
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'weightRound',
|
||||
label: '计费重取整',
|
||||
defaultValue: 'NONE',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ value: 'NONE', label: '不取整' },
|
||||
{ value: 'CEIL_KG', label: '向上整千克' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
componentProps: { rows: 2 },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
function fillRegionsFromVersion(v?: ExpressQuoteVO.Version) {
|
||||
if (!v?.regions?.length) {
|
||||
regions.value = [
|
||||
{
|
||||
regionName: '默认区',
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
isDefault: true,
|
||||
bands: [
|
||||
{
|
||||
weightFromG: 0,
|
||||
weightToG: null,
|
||||
priceMode: 'FLAT_TICKET',
|
||||
flatAmount: 0,
|
||||
firstWeightG: 0,
|
||||
firstAmount: 0,
|
||||
continuePerKg: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
return;
|
||||
}
|
||||
regions.value = v.regions.map((r) => ({
|
||||
regionName: r.regionName,
|
||||
zoneLabel: r.zoneLabel || '',
|
||||
provinces: r.provinces ? [...r.provinces] : [],
|
||||
isDefault: r.isDefault === 1,
|
||||
bands:
|
||||
r.bands?.length ?
|
||||
r.bands.map((b) => ({
|
||||
weightFromG: b.weightFromG ?? 0,
|
||||
weightToG: b.weightToG ?? null,
|
||||
priceMode: b.priceMode || 'FLAT_TICKET',
|
||||
flatAmount: b.flatAmount ?? 0,
|
||||
firstWeightG: b.firstWeightG ?? 0,
|
||||
firstAmount: b.firstAmount ?? 0,
|
||||
continuePerKg: b.continuePerKg ?? 0,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
weightFromG: 0,
|
||||
weightToG: null,
|
||||
priceMode: 'FLAT_TICKET',
|
||||
flatAmount: 0,
|
||||
firstWeightG: 0,
|
||||
firstAmount: 0,
|
||||
continuePerKg: 0,
|
||||
},
|
||||
],
|
||||
}));
|
||||
}
|
||||
|
||||
async function loadDetail() {
|
||||
loading.value = true;
|
||||
try {
|
||||
if (!provinces.value.length) {
|
||||
provinces.value = await getExpressProvincesApi();
|
||||
}
|
||||
if (!quoteId.value) {
|
||||
await formApi.resetForm();
|
||||
await formApi.setValues({
|
||||
carrierCode: 'ZTO',
|
||||
billingMode: 'FLAT',
|
||||
status: 1,
|
||||
effectiveFrom: new Date().toISOString().slice(0, 10),
|
||||
flatAmount: 0,
|
||||
unitScope: 'ORDER',
|
||||
volumeDivisor: 6000,
|
||||
useVolumetric: false,
|
||||
weightRound: 'NONE',
|
||||
});
|
||||
billingMode.value = 'FLAT';
|
||||
fillRegionsFromVersion();
|
||||
await syncTabTitle('新建');
|
||||
return;
|
||||
}
|
||||
const detail = await getExpressQuoteDetailApi(quoteId.value);
|
||||
billingMode.value = detail.billingMode;
|
||||
const v = detail.currentVersion;
|
||||
await formApi.setValues({
|
||||
code: detail.code,
|
||||
name: detail.name,
|
||||
carrierCode: detail.carrierCode,
|
||||
billingMode: detail.billingMode,
|
||||
status: detail.status,
|
||||
remark: detail.remark || '',
|
||||
effectiveFrom: v?.effectiveFrom || new Date().toISOString().slice(0, 10),
|
||||
flatAmount: v?.flatAmount ?? 0,
|
||||
unitScope: v?.unitScope || 'ORDER',
|
||||
pricePerKg: v?.pricePerKg ?? 0,
|
||||
minAmount: v?.minAmount,
|
||||
volumeDivisor: v?.volumeDivisor ?? 6000,
|
||||
useVolumetric: v?.useVolumetric === 1,
|
||||
weightRound: v?.weightRound || 'NONE',
|
||||
});
|
||||
fillRegionsFromVersion(v);
|
||||
await syncTabTitle(detail.name);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('加载报价单失败');
|
||||
} finally {
|
||||
syncLeftWidthByMode();
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function buildVersion(
|
||||
values: Record<string, unknown>,
|
||||
): ExpressQuoteDTO.VersionUpsert {
|
||||
const mode = String(values.billingMode);
|
||||
const version: ExpressQuoteDTO.VersionUpsert = {
|
||||
effectiveFrom: String(values.effectiveFrom),
|
||||
volumeDivisor: Number(values.volumeDivisor ?? 6000),
|
||||
useVolumetric: values.useVolumetric ? 1 : 0,
|
||||
weightRound: String(values.weightRound || 'NONE'),
|
||||
remark: values.remark ? String(values.remark) : undefined,
|
||||
};
|
||||
if (mode === 'FLAT') {
|
||||
version.flatAmount = Number(values.flatAmount ?? 0);
|
||||
version.unitScope = String(values.unitScope || 'ORDER');
|
||||
} else if (mode === 'PER_KG') {
|
||||
version.pricePerKg = Number(values.pricePerKg ?? 0);
|
||||
version.minAmount =
|
||||
values.minAmount == null ? undefined : Number(values.minAmount);
|
||||
} else {
|
||||
version.regions = regions.value.map((r, i) => ({
|
||||
regionName: r.regionName.trim() || `分区${i + 1}`,
|
||||
zoneLabel: r.zoneLabel.trim() || undefined,
|
||||
provinces: r.provinces,
|
||||
isDefault: r.isDefault ? 1 : 0,
|
||||
sortOrder: i,
|
||||
bands: r.bands.map((b, bi) => ({
|
||||
weightFromG: b.weightFromG ?? 0,
|
||||
weightToG: b.weightToG,
|
||||
priceMode: b.priceMode,
|
||||
flatAmount: b.priceMode === 'FLAT_TICKET' ? b.flatAmount : undefined,
|
||||
firstWeightG:
|
||||
b.priceMode === 'FIRST_PLUS_KG' ? b.firstWeightG : undefined,
|
||||
firstAmount:
|
||||
b.priceMode === 'FIRST_PLUS_KG' ? b.firstAmount : undefined,
|
||||
continuePerKg:
|
||||
b.priceMode === 'FIRST_PLUS_KG' ? b.continuePerKg : undefined,
|
||||
sortOrder: bi,
|
||||
})),
|
||||
}));
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) return;
|
||||
const values = await formApi.getValues();
|
||||
if (isRegion.value) {
|
||||
for (const r of regions.value) {
|
||||
if (!r.bands.length) {
|
||||
message.warning(`分区「${r.regionName}」至少一条重量带`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
if (isEdit.value && quoteId.value) {
|
||||
await updateExpressQuoteApi(quoteId.value, {
|
||||
name: String(values.name).trim(),
|
||||
carrierCode: String(values.carrierCode),
|
||||
status: Number(values.status),
|
||||
remark: values.remark ? String(values.remark) : undefined,
|
||||
});
|
||||
await upsertExpressQuoteVersionApi(quoteId.value, buildVersion(values));
|
||||
message.success('已更新');
|
||||
await syncTabTitle(String(values.name));
|
||||
} else {
|
||||
const created = await createExpressQuoteApi({
|
||||
code: String(values.code).trim(),
|
||||
name: String(values.name).trim(),
|
||||
carrierCode: String(values.carrierCode),
|
||||
billingMode: String(values.billingMode),
|
||||
status: Number(values.status),
|
||||
remark: values.remark ? String(values.remark) : undefined,
|
||||
initialVersion: buildVersion(values),
|
||||
});
|
||||
message.success('创建成功');
|
||||
await router.replace(`/ec/warehouse/express-quote/edit/${created.id}`);
|
||||
}
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleBack() {
|
||||
await closeCurrentTab();
|
||||
await router.push('/ec/warehouse/express-quote');
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadDetail();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
() => {
|
||||
void loadDetail();
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="express-quote-edit-page min-h-0">
|
||||
<ColPage
|
||||
v-model:left-width="leftWidth"
|
||||
auto-content-height
|
||||
:loading="loading"
|
||||
:left-min-width="isRegion ? 22 : 40"
|
||||
:left-max-width="isRegion ? 40 : 72"
|
||||
:right-width="100 - leftWidth"
|
||||
:left-collapsible="false"
|
||||
resizable
|
||||
split-line
|
||||
content-class="!flex !min-h-0 !flex-col !overflow-hidden !p-3"
|
||||
>
|
||||
<template #left>
|
||||
<Card
|
||||
size="small"
|
||||
title="基本信息"
|
||||
class="flex h-full min-h-0 flex-col overflow-hidden"
|
||||
:body-style="cardBodyScrollStyle"
|
||||
>
|
||||
<BaseForm />
|
||||
</Card>
|
||||
</template>
|
||||
<div class="h-full min-h-0 min-w-0">
|
||||
<RegionBandEditor
|
||||
v-if="isRegion"
|
||||
v-model="regions"
|
||||
:province-options="provinceOptions"
|
||||
/>
|
||||
<Card
|
||||
v-else
|
||||
size="small"
|
||||
title="分区报价"
|
||||
class="flex h-full min-h-0 flex-col overflow-hidden"
|
||||
:body-style="cardBodyScrollStyle"
|
||||
>
|
||||
<Empty
|
||||
class="py-16"
|
||||
description="当前为一口价 / 按千克模式,无需配置目的分区。切换为「分区×重量带」后在此编辑。"
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="flex w-full justify-end gap-2 px-1 py-1">
|
||||
<Button @click="handleBack">返回列表</Button>
|
||||
<Button type="primary" :loading="saving" @click="handleSubmit">
|
||||
保存
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</ColPage>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/**
|
||||
* 内容区高度由 Page autoContentHeight 按「视口 − footer」算出;
|
||||
* 分栏只填满该剩余高度,勿再用 !h-full 盖掉 calc。
|
||||
*/
|
||||
.express-quote-edit-page :deep([data-panel-group]) {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
flex: 1 1 0%;
|
||||
}
|
||||
.express-quote-edit-page :deep(.ant-card) {
|
||||
max-height: 100%;
|
||||
}
|
||||
.express-quote-edit-page :deep(.ant-card-head) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -4,6 +4,7 @@ import type { ExpressQuoteDTO, ExpressQuoteVO } from '#/api/ec/express-quote';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
@@ -23,22 +24,27 @@ import {
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
|
||||
import ExpressQuoteDetailDrawer from './components/ExpressQuoteDetailDrawer.vue';
|
||||
import ExpressQuoteFormModal from './components/ExpressQuoteFormModal.vue';
|
||||
import ExpressQuoteImportModal from './components/ExpressQuoteImportModal.vue';
|
||||
|
||||
defineOptions({ name: 'ExpressQuoteManagement' });
|
||||
|
||||
const router = useRouter();
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const loading = ref(false);
|
||||
const formModalRef = ref<InstanceType<typeof ExpressQuoteFormModal> | null>(
|
||||
null,
|
||||
);
|
||||
const importModalRef = ref<InstanceType<typeof ExpressQuoteImportModal> | null>(
|
||||
null,
|
||||
);
|
||||
const detailDrawerRef = ref<InstanceType<
|
||||
typeof ExpressQuoteDetailDrawer
|
||||
> | null>(null);
|
||||
|
||||
function goCreate() {
|
||||
void router.push('/ec/warehouse/express-quote/edit');
|
||||
}
|
||||
|
||||
function goEdit(row: ExpressQuoteVO.Info) {
|
||||
void router.push(`/ec/warehouse/express-quote/edit/${row.id}`);
|
||||
}
|
||||
const searchForm = ref({
|
||||
keywords: '',
|
||||
billingMode: undefined as string | undefined,
|
||||
@@ -194,7 +200,7 @@ async function handleDelete(row: ExpressQuoteVO.Info) {
|
||||
<Button @click="importModalRef?.open()">导入</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="ec:express-quote:create">
|
||||
<Button type="primary" @click="formModalRef?.open(false)">
|
||||
<Button type="primary" @click="goCreate">
|
||||
<PlusIcon />
|
||||
新建报价
|
||||
</Button>
|
||||
@@ -220,9 +226,7 @@ async function handleDelete(row: ExpressQuoteVO.Info) {
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="ec:express-quote:update">
|
||||
<Button size="small" @click="formModalRef?.open(true, row)">
|
||||
编辑/调价
|
||||
</Button>
|
||||
<Button size="small" @click="goEdit(row)">编辑/调价</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="ec:express-quote:delete">
|
||||
<Popconfirm title="确定删除?" @confirm="handleDelete(row)">
|
||||
@@ -232,7 +236,6 @@ async function handleDelete(row: ExpressQuoteVO.Info) {
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
<ExpressQuoteFormModal ref="formModalRef" @success="gridApi.reload()" />
|
||||
<ExpressQuoteImportModal
|
||||
ref="importModalRef"
|
||||
@success="gridApi.reload()"
|
||||
|
||||
Reference in New Issue
Block a user