feat(shopExpressTemplateDetail): 支持「不发货黑名单」配送模式
- 新增配送模式三态选择(0全国/1指定配送/2指定不发货) - 编辑表单中增加“配送模式”单选,mode=2时复用多选地区组件选择不发货地区 - 保存时根据模式调整 regionMode 和 regionIds 字段,确保模式与地区同步 - 列表页配送地区列新增不发货黑名单显示,聚合城市码为省份名并支持省名去重 - 加载地区时建立城市ID到省份ID映射,实现城市码聚合显示省名功能 - 适配旧数据兼容性,支持单值旧数据和全国模式显示 - 表单校验强化,指定配送/不发货模式下必须选择有效地区 - 完成端到端链路功能闭环,前端支持黑名单配置,后端按租户生效配送限制
This commit is contained in:
@@ -92,6 +92,8 @@
|
||||
|
||||
// 地区ID→名称映射
|
||||
const regionMap = ref<Record<string, string>>({});
|
||||
// 城市ID→省份ID映射(用于把城市码聚合显示为省名)
|
||||
const cityToProvince = ref<Record<string, string>>({});
|
||||
|
||||
// 表格选中数据
|
||||
const selection = ref<ShopExpressTemplateDetail[]>([]);
|
||||
@@ -128,26 +130,25 @@
|
||||
align: 'center',
|
||||
width: 150,
|
||||
customRender: ({ record }) => {
|
||||
// 多选配送区域(regionIds 逗号分隔的城市编码)
|
||||
const cityIds = (record.regionIds || '')
|
||||
const mode = record.regionMode;
|
||||
const ids = (record.regionIds || '')
|
||||
.split(',')
|
||||
.filter(Boolean);
|
||||
if (cityIds.length) {
|
||||
const names = cityIds.map(
|
||||
(id: string) => regionMap.value[id] || id
|
||||
);
|
||||
const text = names.join('、');
|
||||
// 过长截断并支持 tooltip 悬浮查看全部
|
||||
if (text.length > 22) {
|
||||
return h(
|
||||
'span',
|
||||
{ title: text },
|
||||
text.slice(0, 22) + '…'
|
||||
);
|
||||
if (mode === 2) {
|
||||
// 指定不发货(黑名单)
|
||||
if (!ids.length) {
|
||||
return h('span', { style: { color: '#bbb' } }, '不发货(未配置地区)');
|
||||
}
|
||||
return text;
|
||||
const text = '不发货:' + aggregateProvinces(ids).join('、');
|
||||
return renderRegionText(text, 26);
|
||||
}
|
||||
// 兼容旧单值数据
|
||||
if (mode === 1) {
|
||||
// 指定配送(白名单)
|
||||
if (!ids.length) return '默认全国';
|
||||
const text = aggregateProvinces(ids).join('、');
|
||||
return renderRegionText(text, 22);
|
||||
}
|
||||
// 兼容旧数据 / 全国
|
||||
const province = record.provinceId
|
||||
? regionMap.value[String(record.provinceId)]
|
||||
: '';
|
||||
@@ -286,19 +287,44 @@
|
||||
};
|
||||
};
|
||||
|
||||
/* 把城市编码数组聚合为去重的省份名称数组(兼容直接存省份码的场景) */
|
||||
const aggregateProvinces = (ids: string[]) => {
|
||||
const set = new Set<string>();
|
||||
ids.forEach((id) => {
|
||||
const prov = cityToProvince.value[id];
|
||||
if (prov) {
|
||||
set.add(regionMap.value[prov] || prov);
|
||||
} else {
|
||||
set.add(regionMap.value[id] || id);
|
||||
}
|
||||
});
|
||||
return [...set];
|
||||
};
|
||||
|
||||
/* 过长截断并支持 tooltip 悬浮查看全部 */
|
||||
const renderRegionText = (text: string, max = 22) => {
|
||||
if (text.length > max) {
|
||||
return h('span', { title: text }, text.slice(0, max) + '…');
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
/* 加载地区数据,建立ID→名称映射 */
|
||||
onMounted(() => {
|
||||
getRegionsData().then((data) => {
|
||||
const map: Record<string, string> = {};
|
||||
const c2p: Record<string, string> = {};
|
||||
data.forEach((province) => {
|
||||
map[province.value] = province.label;
|
||||
if (province.children) {
|
||||
province.children.forEach((city) => {
|
||||
map[city.value] = city.label;
|
||||
c2p[city.value] = province.value;
|
||||
});
|
||||
}
|
||||
});
|
||||
regionMap.value = map;
|
||||
cityToProvince.value = c2p;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user