fix bug
This commit is contained in:
@@ -109,6 +109,8 @@ import { getToken } from '@/utils/auth';
|
||||
import NProgress from 'nprogress';
|
||||
import 'nprogress/nprogress.css';
|
||||
|
||||
const DEFAULT_COUNTRY_CODE = '+86';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
const validateTmisCode = (rule, value, callback) => {
|
||||
@@ -152,6 +154,7 @@ export default {
|
||||
excelForm: {},
|
||||
provinceOptions: [],
|
||||
cityOptions: [],
|
||||
regionInitializing: false,
|
||||
page: {
|
||||
pageSize: 10,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
@@ -180,6 +183,8 @@ export default {
|
||||
{
|
||||
label: '编码',
|
||||
prop: 'code',
|
||||
minWidth: 120,
|
||||
overHidden: false,
|
||||
search: true,
|
||||
addDisabled: true,
|
||||
editDisabled: true,
|
||||
@@ -216,11 +221,11 @@ export default {
|
||||
search: true,
|
||||
rules: [{ required: true, message: '请输入车站名称', trigger: 'blur' }],
|
||||
},
|
||||
{
|
||||
label: '所属铁路线路',
|
||||
prop: 'railwayLine',
|
||||
minWidth: 130,
|
||||
},
|
||||
// {
|
||||
// label: '所属铁路线路',
|
||||
// prop: 'railwayLine',
|
||||
// minWidth: 130,
|
||||
// },
|
||||
{
|
||||
label: '所属省份',
|
||||
prop: 'provinceCode',
|
||||
@@ -265,11 +270,35 @@ export default {
|
||||
addDisplay: false,
|
||||
editDisplay: false,
|
||||
},
|
||||
{
|
||||
label: '行政区划',
|
||||
prop: 'regionName',
|
||||
search: true,
|
||||
minWidth: 160,
|
||||
overHidden: false,
|
||||
maxlength: 128,
|
||||
showWordLimit: true,
|
||||
rules: [{ max: 128, message: '行政区划不能超过128字', trigger: 'blur' }],
|
||||
},
|
||||
{
|
||||
label: '详细地址',
|
||||
prop: 'detailAddress',
|
||||
type: 'textarea',
|
||||
minRows: 3,
|
||||
span: 24,
|
||||
minWidth: 220,
|
||||
overHidden: false,
|
||||
maxlength: 255,
|
||||
showWordLimit: true,
|
||||
rules: [{ max: 255, message: '详细地址不能超过255字', trigger: 'blur' }],
|
||||
},
|
||||
{
|
||||
label: '经度',
|
||||
prop: 'longitude',
|
||||
type: 'number',
|
||||
precision: 6,
|
||||
minWidth: 130,
|
||||
overHidden: false,
|
||||
rules: [{ validator: validateLongitude, trigger: 'blur' }],
|
||||
},
|
||||
{
|
||||
@@ -277,6 +306,8 @@ export default {
|
||||
prop: 'latitude',
|
||||
type: 'number',
|
||||
precision: 6,
|
||||
minWidth: 130,
|
||||
overHidden: false,
|
||||
rules: [{ validator: validateLatitude, trigger: 'blur' }],
|
||||
},
|
||||
{
|
||||
@@ -284,6 +315,8 @@ export default {
|
||||
prop: 'dataSource',
|
||||
type: 'select',
|
||||
search: true,
|
||||
minWidth: 120,
|
||||
overHidden: false,
|
||||
dicData: [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: '初始化导入', value: '初始化导入' },
|
||||
@@ -298,6 +331,8 @@ export default {
|
||||
search: true,
|
||||
slot: true,
|
||||
dataType: 'number',
|
||||
minWidth: 110,
|
||||
overHidden: false,
|
||||
dicData: [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: '启用', value: 1 },
|
||||
@@ -405,8 +440,8 @@ export default {
|
||||
return this.option.column.find(item => item.prop === prop);
|
||||
},
|
||||
loadProvinceOptions() {
|
||||
getLazyTree('00').then(res => {
|
||||
this.provinceOptions = res.data.data;
|
||||
getLazyTree(DEFAULT_COUNTRY_CODE).then(res => {
|
||||
this.provinceOptions = (res.data.data || []).map(this.normalizeRegionOption);
|
||||
this.findColumn('provinceCode').dicData = this.provinceOptions;
|
||||
});
|
||||
},
|
||||
@@ -417,10 +452,40 @@ export default {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return getLazyTree(provinceCode).then(res => {
|
||||
this.cityOptions = res.data.data;
|
||||
this.cityOptions = (res.data.data || []).map(this.normalizeRegionOption);
|
||||
this.findColumn('cityCode').dicData = this.cityOptions;
|
||||
});
|
||||
},
|
||||
normalizeRegionOption(region) {
|
||||
return {
|
||||
...region,
|
||||
id: region.id === undefined || region.id === null ? region.id : String(region.id),
|
||||
};
|
||||
},
|
||||
normalizeRegionForm(row) {
|
||||
return {
|
||||
...row,
|
||||
provinceCode:
|
||||
row.provinceCode === undefined || row.provinceCode === null
|
||||
? row.provinceCode
|
||||
: String(row.provinceCode),
|
||||
cityCode:
|
||||
row.cityCode === undefined || row.cityCode === null ? row.cityCode : String(row.cityCode),
|
||||
};
|
||||
},
|
||||
ensureCityOption(row) {
|
||||
if (!row.cityCode || !row.cityName) return;
|
||||
const exists = this.cityOptions.some(item => item.id === row.cityCode);
|
||||
if (exists) return;
|
||||
this.cityOptions = [
|
||||
...this.cityOptions,
|
||||
{
|
||||
id: row.cityCode,
|
||||
title: row.cityName,
|
||||
},
|
||||
];
|
||||
this.findColumn('cityCode').dicData = this.cityOptions;
|
||||
},
|
||||
handleTmisChange(value) {
|
||||
this.form.tmisCode = String(value || '')
|
||||
.replace(/\D/g, '')
|
||||
@@ -436,6 +501,10 @@ export default {
|
||||
handleProvinceChange(value) {
|
||||
const province = this.provinceOptions.find(item => item.id === value);
|
||||
this.form.provinceName = province ? province.title : '';
|
||||
if (this.regionInitializing) {
|
||||
this.loadCityOptions(value).then(() => this.ensureCityOption(this.form));
|
||||
return;
|
||||
}
|
||||
this.form.cityCode = undefined;
|
||||
this.form.cityName = '';
|
||||
this.loadCityOptions(value);
|
||||
@@ -446,6 +515,8 @@ export default {
|
||||
},
|
||||
normalizeRow(row) {
|
||||
row.code = row.tmisCode ? `TL${row.tmisCode}` : row.code;
|
||||
row.regionName = String(row.regionName || '').trim();
|
||||
row.detailAddress = String(row.detailAddress || '').trim();
|
||||
if (!row.dataSource) row.dataSource = '手动';
|
||||
if (!row.status) row.status = 1;
|
||||
return row;
|
||||
@@ -546,9 +617,19 @@ export default {
|
||||
},
|
||||
beforeOpen(done, type) {
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
this.regionInitializing = true;
|
||||
getDetail(this.form.id).then(res => {
|
||||
this.form = res.data.data;
|
||||
this.loadCityOptions(this.form.provinceCode).then(() => done());
|
||||
const detail = this.normalizeRegionForm(res.data.data || {});
|
||||
this.loadCityOptions(detail.provinceCode).then(() => {
|
||||
this.ensureCityOption(detail);
|
||||
this.form = detail;
|
||||
done();
|
||||
this.$nextTick(() => {
|
||||
window.setTimeout(() => {
|
||||
this.regionInitializing = false;
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user