feat(shop): 完善运费模板配送区域功能

- 模板列表操作列新增“配送区域”跳转链接,调整操作列宽度为200
- 配送区域页根据路由参数设置页面标题并过滤对应模板数据
- 合并省市列为配送地区列,显示具体地区名称
- 移除配送区域页模板ID和计费方式列
- 搜索组件去除模板ID搜索框,保留新增与批量删除
- 编辑表单用级联选择组件替代省市输入,移除所属模板与计费方式字段
- 编辑表单支持配送地区回显及动态标签显示,保存时自动赋值模板ID和计费方式
- 加载地区数据建立ID到名称映射以支持地区展示
This commit is contained in:
2026-07-08 19:00:03 +08:00
parent 6118e2be01
commit ae8cb170dd
5 changed files with 146 additions and 128 deletions
@@ -1,5 +1,5 @@
<template>
<a-page-header :title="getPageTitle()" @back="() => $router.go(-1)">
<a-page-header :title="pageTitle" @back="() => $router.go(-1)">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
@@ -13,18 +13,12 @@
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'type'">
<a-tag v-if="record.type === true" color="blue">按件</a-tag>
<a-tag v-else-if="record.type === false" color="cyan">按重量</a-tag>
<span v-else>{{ record.type }}</span>
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">启用</a-tag>
<a-tag v-else color="red">禁用</a-tag>
@@ -49,13 +43,16 @@
<ShopExpressTemplateDetailEdit
v-model:visible="showEdit"
:data="current"
:template-id="templateId"
:template-type="templateType"
@done="reload"
/>
</a-page-header>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { createVNode, ref, computed, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
@@ -76,10 +73,26 @@
ShopExpressTemplateDetail,
ShopExpressTemplateDetailParam
} from '@/api/shop/shopExpressTemplateDetail/model';
import { getRegionsData } from '@/components/RegionsSelect/load-data';
// 表格实例
const route = useRoute();
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 从路由参数获取模板信息
const templateId = Number(route.query.templateId) || undefined;
const templateTitle = (route.query.title as string) || '';
const templateType = route.query.type !== 'false'; // 默认 true(按件)
// 页面标题
const pageTitle = computed(() => {
return templateTitle
? `${templateTitle} - 配送区域`
: (getPageTitle() as string);
});
// 地区ID→名称映射
const regionMap = ref<Record<string, string>>({});
// 表格选中数据
const selection = ref<ShopExpressTemplateDetail[]>([]);
// 当前编辑数据
@@ -87,7 +100,7 @@
// 是否显示编辑弹窗
const showEdit = ref(false);
// 表格数据源
// 表格数据源(自动按 templateId 过滤)
const datasource: DatasourceFunction = ({
page,
limit,
@@ -99,6 +112,7 @@
where.status = filters.status;
}
return pageShopExpressTemplateDetail({
templateId: templateId,
...where,
...orders,
page,
@@ -109,32 +123,20 @@
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: '所属模板ID',
dataIndex: 'templateId',
key: 'templateId',
title: '配送地区',
key: 'region',
align: 'center',
width: 110
},
{
title: '计费方式',
dataIndex: 'type',
key: 'type',
align: 'center',
width: 100
},
{
title: '省份ID',
dataIndex: 'provinceId',
key: 'provinceId',
align: 'center',
width: 90
},
{
title: '城市ID',
dataIndex: 'cityId',
key: 'cityId',
align: 'center',
width: 90
width: 150,
customRender: ({ record }) => {
const province = record.provinceId
? regionMap.value[String(record.provinceId)]
: '';
const city = record.cityId
? regionMap.value[String(record.cityId)]
: '';
if (!province && !city) return '默认全国';
return city ? `${province} / ${city}` : province;
}
},
{
title: '首件数量/重量',
@@ -263,6 +265,22 @@
}
};
};
/* 加载地区数据,建立ID→名称映射 */
onMounted(() => {
getRegionsData().then((data) => {
const map: Record<string, string> = {};
data.forEach((province) => {
map[province.value] = province.label;
if (province.children) {
province.children.forEach((city) => {
map[city.value] = city.label;
});
}
});
regionMap.value = map;
});
});
</script>
<script lang="ts">