重构租户管理城市数据处理逻辑,支持直辖市特殊处理

This commit is contained in:
WUSIJIAN
2025-12-09 15:02:57 +08:00
parent 1138655123
commit 112994ac5b
6 changed files with 124 additions and 30 deletions

View File

@@ -55,13 +55,13 @@
<el-tag v-else type="info">未知</el-tag>
</template>
</el-table-column>
<el-table-column prop="city" label="所属城市" show-overflow-tooltip>
<el-table-column prop="cityName" label="所属城市" show-overflow-tooltip>
<template #default="scope">
{{ getCityName(scope.row.city) }}
{{ getCityName(scope.row.cityName) }}
</template>
</el-table-column>
<el-table-column prop="contactPerson" label="联系人" show-overflow-tooltip></el-table-column>
<el-table-column prop="phone" label="电话" show-overflow-tooltip></el-table-column>
<el-table-column prop="userNickname" label="联系人" show-overflow-tooltip></el-table-column>
<el-table-column prop="mobile" label="电话" show-overflow-tooltip></el-table-column>
<el-table-column prop="businessLicense" label="营业执照" align="center">
<template #default="scope">
<el-image
@@ -106,7 +106,7 @@ import { toRefs, reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
import EditTenant from './component/editTenant.vue';
import { getTenantList, deleteTenant } from '/@/api/system/tenant';
import { pcTextArr } from 'element-china-area-data';
import { pcTextArr,provinceAndCityData } from 'element-china-area-data';
const editTenantRef = ref();
const queryRef = ref();
@@ -120,7 +120,7 @@ const state = reactive({
pageSize: 10,
tenantName: '',
tenantType: '',
city: [],
city: '',
},
},
});
@@ -128,12 +128,49 @@ const state = reactive({
const { tableData } = toRefs(state);
// 省市数据
const cityOptions = pcTextArr;
const cityOptions = ref<any[]>([]);
// 初始化城市数据
const initCityData = () => {
const data = JSON.parse(JSON.stringify(provinceAndCityData));
cityOptions.value = data.map((item: any) => {
// 处理直辖市:北京(110000), 天津(120000), 上海(310000), 重庆(500000)
if (['110000', '120000', '310000', '500000'].includes(item.value) || ['北京市', '天津市', '上海市', '重庆市'].includes(item.label)) {
// 移除 children 属性,使其成为叶子节点
delete item.children;
}
return item;
});
};
initCityData();
// 初始化表格数据
const tenantList = () => {
state.tableData.loading = true;
getTenantList(state.tableData.param)
const params = { ...state.tableData.param };
// 处理城市数据:如果是数组(级联选择器返回),取最后一个值
if (Array.isArray(params.city) && params.city.length > 0) {
let lastCode = String(params.city[params.city.length - 1]);
// 特殊处理直辖市:如果选中的是省级代码,转换为市级代码 (市辖区)
const municipalityMap: Record<string, string> = {
'11': '110100', '110000': '110100', // 北京
'12': '120100', '120000': '120100', // 天津
'31': '310100', '310000': '310100', // 上海
'50': '500100', '500000': '500100', // 重庆
};
if (municipalityMap[lastCode]) {
lastCode = municipalityMap[lastCode];
} else if (lastCode.length === 4) {
// 普通省市如果是4位代码补齐为6位
lastCode = lastCode + '00';
}
params.city = lastCode;
} else {
params.city = '';
}
getTenantList(params)
.then((res: any) => {
state.tableData.data = res.data.list ?? [];
state.tableData.total = res.data.total;