feat(address): 增加行政区划校验及地址类型相关字段处理
- 新增行政区划(regionName)必填校验规则 - 增强经度和纬度的空值校验,改为显示错误提示 - 选择来源主数据时,完善表单字段自动赋值及清空逻辑 - 地址类型变更时,动态禁用或启用相关字段(含行政区划和经纬度) - 保存地址时增加行政区划、经纬度非空校验提示 - 统一处理表单中行政区划(regionCode)字段的读写 - 地图点选功能同步更新行政区划字段内容
This commit is contained in:
@@ -101,6 +101,7 @@ export const createOption = ({ validateLongitude, validateLatitude }) => ({
|
|||||||
prop: 'regionName',
|
prop: 'regionName',
|
||||||
search: true,
|
search: true,
|
||||||
minWidth: 150,
|
minWidth: 150,
|
||||||
|
rules: [{ required: true, message: '请输入行政区划', trigger: 'blur' }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '组织',
|
label: '组织',
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
const validateLongitude = (rule, value, callback) => {
|
const validateLongitude = (rule, value, callback) => {
|
||||||
if (value === undefined || value === null || value === '') {
|
if (value === undefined || value === null || value === '') {
|
||||||
callback();
|
callback(new Error('经度不能为空'));
|
||||||
} else if (Number(value) < -180 || Number(value) > 180) {
|
} else if (Number(value) < -180 || Number(value) > 180) {
|
||||||
callback(new Error('经度范围为 -180 到 180'));
|
callback(new Error('经度范围为 -180 到 180'));
|
||||||
} else {
|
} else {
|
||||||
@@ -198,7 +198,7 @@ export default {
|
|||||||
};
|
};
|
||||||
const validateLatitude = (rule, value, callback) => {
|
const validateLatitude = (rule, value, callback) => {
|
||||||
if (value === undefined || value === null || value === '') {
|
if (value === undefined || value === null || value === '') {
|
||||||
callback();
|
callback(new Error('纬度不能为空'));
|
||||||
} else if (Number(value) < -90 || Number(value) > 90) {
|
} else if (Number(value) < -90 || Number(value) > 90) {
|
||||||
callback(new Error('纬度范围为 -90 到 90'));
|
callback(new Error('纬度范围为 -90 到 90'));
|
||||||
} else {
|
} else {
|
||||||
@@ -306,34 +306,45 @@ export default {
|
|||||||
},
|
},
|
||||||
handleSourceChange(value) {
|
handleSourceChange(value) {
|
||||||
const source = this.sourceOptions.find(item => item.sourceId === value);
|
const source = this.sourceOptions.find(item => item.sourceId === value);
|
||||||
if (!source) return;
|
if (!source) {
|
||||||
this.form.addressName = this.form.addressName || source.addressName;
|
this.clearTypeRelatedFields('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.form.addressName = source.addressName;
|
||||||
this.form.siteCode = source.siteCode;
|
this.form.siteCode = source.siteCode;
|
||||||
this.form.siteCodeDisplay = source.siteCode;
|
this.form.siteCodeDisplay = source.siteCode;
|
||||||
this.form.detailAddress = source.detailAddress;
|
this.form.detailAddress = source.detailAddress;
|
||||||
|
this.form.regionCode = source.regionCode;
|
||||||
this.form.regionName = source.regionName;
|
this.form.regionName = source.regionName;
|
||||||
this.form.longitude = source.longitude;
|
this.form.longitude = source.longitude;
|
||||||
this.form.latitude = source.latitude;
|
this.form.latitude = source.latitude;
|
||||||
},
|
},
|
||||||
|
clearTypeRelatedFields(siteCode = '') {
|
||||||
|
this.form.sourceId = undefined;
|
||||||
|
this.form.siteCode = siteCode;
|
||||||
|
this.form.siteCodeDisplay = siteCode;
|
||||||
|
this.form.detailAddress = '';
|
||||||
|
this.form.regionCode = '';
|
||||||
|
this.form.regionName = '';
|
||||||
|
this.form.longitude = '';
|
||||||
|
this.form.latitude = '';
|
||||||
|
},
|
||||||
handleAddressTypeChange(value, reset = true) {
|
handleAddressTypeChange(value, reset = true) {
|
||||||
const sourceColumn = this.findColumn(this.option.column, 'sourceId');
|
const sourceColumn = this.findColumn(this.option.column, 'sourceId');
|
||||||
sourceColumn.rules = value === '常规地址' ? [] : [{ required: true, message: '请选择来源主数据', trigger: 'change' }];
|
sourceColumn.rules = value === '常规地址' ? [] : [{ required: true, message: '请选择来源主数据', trigger: 'change' }];
|
||||||
const sourceDisabled = value === '常规地址';
|
const sourceDisabled = value === '常规地址';
|
||||||
|
this.findColumn(this.option.column, 'regionName').disabled = !sourceDisabled;
|
||||||
this.findColumn(this.option.column, 'longitude').disabled = !sourceDisabled;
|
this.findColumn(this.option.column, 'longitude').disabled = !sourceDisabled;
|
||||||
this.findColumn(this.option.column, 'latitude').disabled = !sourceDisabled;
|
this.findColumn(this.option.column, 'latitude').disabled = !sourceDisabled;
|
||||||
if (value === '常规地址') {
|
if (value === '常规地址') {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.form.sourceId = undefined;
|
this.clearTypeRelatedFields('/');
|
||||||
this.form.siteCode = '/';
|
|
||||||
this.form.siteCodeDisplay = '/';
|
|
||||||
this.sourceOptions = [];
|
this.sourceOptions = [];
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.form.sourceId = undefined;
|
this.clearTypeRelatedFields('');
|
||||||
this.form.siteCode = '';
|
|
||||||
this.form.siteCodeDisplay = '';
|
|
||||||
}
|
}
|
||||||
this.loadSourceOptions();
|
this.loadSourceOptions();
|
||||||
},
|
},
|
||||||
@@ -343,6 +354,7 @@ export default {
|
|||||||
addressName: String(row.addressName || '').trim(),
|
addressName: String(row.addressName || '').trim(),
|
||||||
addressType: String(row.addressType || '').trim(),
|
addressType: String(row.addressType || '').trim(),
|
||||||
detailAddress: String(row.detailAddress || '').trim(),
|
detailAddress: String(row.detailAddress || '').trim(),
|
||||||
|
regionCode: String(row.regionCode || '').trim(),
|
||||||
regionName: String(row.regionName || '').trim(),
|
regionName: String(row.regionName || '').trim(),
|
||||||
contactName: String(row.contactName || '').trim(),
|
contactName: String(row.contactName || '').trim(),
|
||||||
contactPhone: String(row.contactPhone || '').trim(),
|
contactPhone: String(row.contactPhone || '').trim(),
|
||||||
@@ -367,6 +379,18 @@ export default {
|
|||||||
this.$message.warning('请输入详细地址');
|
this.$message.warning('请输入详细地址');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!row.regionName) {
|
||||||
|
this.$message.warning('请输入行政区划');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (row.longitude === undefined || row.longitude === null || row.longitude === '') {
|
||||||
|
this.$message.warning('经度不能为空');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (row.latitude === undefined || row.latitude === null || row.latitude === '') {
|
||||||
|
this.$message.warning('纬度不能为空');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (row.addressType !== '常规地址' && !row.sourceId) {
|
if (row.addressType !== '常规地址' && !row.sourceId) {
|
||||||
this.$message.warning('请选择来源主数据');
|
this.$message.warning('请选择来源主数据');
|
||||||
return false;
|
return false;
|
||||||
@@ -497,6 +521,7 @@ export default {
|
|||||||
addressName: this.form.addressName,
|
addressName: this.form.addressName,
|
||||||
siteCode: this.form.siteCode,
|
siteCode: this.form.siteCode,
|
||||||
detailAddress: this.form.detailAddress,
|
detailAddress: this.form.detailAddress,
|
||||||
|
regionCode: this.form.regionCode,
|
||||||
regionName: this.form.regionName,
|
regionName: this.form.regionName,
|
||||||
longitude: this.form.longitude,
|
longitude: this.form.longitude,
|
||||||
latitude: this.form.latitude,
|
latitude: this.form.latitude,
|
||||||
@@ -583,6 +608,7 @@ export default {
|
|||||||
lat: this.form.latitude,
|
lat: this.form.latitude,
|
||||||
address: this.form.detailAddress,
|
address: this.form.detailAddress,
|
||||||
regionName: this.form.regionName,
|
regionName: this.form.regionName,
|
||||||
|
regionCode: this.form.regionCode,
|
||||||
});
|
});
|
||||||
this.mapStatus = this.mapSelected.longitude ? '已加载当前经纬度,可重新选点' : '可搜索地址或点击地图选点';
|
this.mapStatus = this.mapSelected.longitude ? '已加载当前经纬度,可重新选点' : '可搜索地址或点击地图选点';
|
||||||
this.mapBox = true;
|
this.mapBox = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user