1、基础数据修复bug
2、客商模块修复bug
This commit is contained in:
@@ -24,10 +24,25 @@
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-plus"
|
||||
plain
|
||||
v-if="hasPermission('common_route_add')"
|
||||
@click="$refs.crud.rowAdd()"
|
||||
>新增
|
||||
>新建路线
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-upload"
|
||||
plain
|
||||
v-if="config.importUrl && hasPermission('common_route_import')"
|
||||
@click="handleImport"
|
||||
>批量导入
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-download"
|
||||
plain
|
||||
v-if="config.templateUrl && hasPermission('common_route_template')"
|
||||
@click="handleTemplate"
|
||||
>下载模板
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
@@ -57,10 +72,10 @@
|
||||
/>
|
||||
<el-input
|
||||
v-model="form.departureAddress"
|
||||
readonly
|
||||
placeholder="请输入并选择地址"
|
||||
suffix-icon="el-icon-location"
|
||||
:disabled="dialogReadonly"
|
||||
@click="openRouteMapDialog('departure')"
|
||||
/>
|
||||
<el-tooltip content="选择常用地址" placement="top">
|
||||
<el-button
|
||||
@@ -84,10 +99,10 @@
|
||||
/>
|
||||
<el-input
|
||||
v-model="form.arrivalAddress"
|
||||
readonly
|
||||
placeholder="请输入并选择地址"
|
||||
suffix-icon="el-icon-location"
|
||||
:disabled="dialogReadonly"
|
||||
@click="openRouteMapDialog('arrival')"
|
||||
/>
|
||||
<el-tooltip content="选择常用地址" placement="top">
|
||||
<el-button
|
||||
@@ -133,6 +148,16 @@
|
||||
@load="onLoad(page, query)"
|
||||
/>
|
||||
|
||||
<el-dialog :title="`${config.title}导入`" append-to-body v-model="excelBox" width="555px">
|
||||
<avue-form :option="excelOptionConfig" v-model="excelForm">
|
||||
<template #excelTemplate>
|
||||
<el-button type="primary" @click="handleTemplate">
|
||||
点击下载<i class="el-icon-download el-icon--right"></i>
|
||||
</el-button>
|
||||
</template>
|
||||
</avue-form>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
title="选择常用地址"
|
||||
append-to-body
|
||||
@@ -238,6 +263,48 @@
|
||||
<el-button @click="addressDialogVisible = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
title="地图选择地址"
|
||||
append-to-body
|
||||
v-model="routeMapVisible"
|
||||
width="920px"
|
||||
@opened="initRouteAmap"
|
||||
>
|
||||
<div class="common-route-page__map-toolbar">
|
||||
<el-input
|
||||
v-model="routeMapKeyword"
|
||||
clearable
|
||||
placeholder="输入地址关键词"
|
||||
@keyup.enter="searchRouteMapKeyword"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
:icon="Search"
|
||||
:loading="routeMapLoading"
|
||||
@click="searchRouteMapKeyword"
|
||||
>
|
||||
搜索
|
||||
</el-button>
|
||||
</div>
|
||||
<div ref="routeAmap" class="common-route-page__map"></div>
|
||||
<div class="common-route-page__map-info">
|
||||
<span>{{ routeMapStatus }}</span>
|
||||
<span v-if="routeMapSelected.regionName"
|
||||
>发货/收货地:{{ routeMapSelected.regionName }}</span
|
||||
>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="routeMapVisible = false">取消</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="!routeMapSelected.longitude"
|
||||
@click="confirmRouteMapPick"
|
||||
>
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
@@ -247,18 +314,24 @@ import { getList as getCommonAddressList } from '@/api/base/common-address';
|
||||
import { exportBlob } from '@/api/common';
|
||||
import { getDeptTree } from '@/api/system/dept';
|
||||
import { addressTypeOptions } from '@/option/base/common-address';
|
||||
import { config, option } from '@/option/business/common-route';
|
||||
import { config, excelOption, option } from '@/option/business/common-route';
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { openImportDialog } from '@/utils/import-excel';
|
||||
import { downloadXls } from '@/utils/util';
|
||||
import { List } from '@element-plus/icons-vue';
|
||||
import { List, Search } from '@element-plus/icons-vue';
|
||||
import { mapGetters } from 'vuex';
|
||||
import NProgress from 'nprogress';
|
||||
import 'nprogress/nprogress.css';
|
||||
|
||||
const AMAP_KEY = '653b7cf105ad7fb8ec9b2f5198ade315';
|
||||
const AMAP_SECURITY_CODE = '5aab65c632e48ebae0d0e28f5b28e21a';
|
||||
let amapLoader;
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
List,
|
||||
Search,
|
||||
config,
|
||||
option,
|
||||
form: {},
|
||||
@@ -266,12 +339,24 @@ export default {
|
||||
loading: true,
|
||||
data: [],
|
||||
dialogReadonly: false,
|
||||
excelBox: false,
|
||||
excelForm: {},
|
||||
excelOptionConfig: excelOption,
|
||||
addressTypeOptions,
|
||||
addressDialogVisible: false,
|
||||
addressTarget: '',
|
||||
addressQuery: {},
|
||||
addressData: [],
|
||||
addressLoading: false,
|
||||
routeMapVisible: false,
|
||||
routeMapTarget: '',
|
||||
routeMapLoading: false,
|
||||
routeMapKeyword: '',
|
||||
routeMapStatus: '可搜索地址或点击地图选点',
|
||||
routeMapSelected: {},
|
||||
routeAmap: null,
|
||||
routeAmapMarker: null,
|
||||
routeAmapGeocoder: null,
|
||||
deptOptions: [],
|
||||
page: {
|
||||
pageSize: 10,
|
||||
@@ -313,9 +398,22 @@ export default {
|
||||
},
|
||||
initDeptTree() {
|
||||
getDeptTree(this.userInfo.tenantId).then(res => {
|
||||
this.deptOptions = this.flattenDept(res.data.data || []);
|
||||
const deptTree = res.data.data || [];
|
||||
this.deptOptions = this.flattenDept(deptTree);
|
||||
const deptColumn = this.findColumn(this.option.column, 'searchDeptId');
|
||||
if (deptColumn) {
|
||||
deptColumn.dicData = this.buildDeptTree(deptTree);
|
||||
}
|
||||
});
|
||||
},
|
||||
buildDeptTree(tree) {
|
||||
return tree.map(item => ({
|
||||
label: item.title || item.deptName || item.name,
|
||||
value: item.id,
|
||||
children:
|
||||
item.children && item.children.length ? this.buildDeptTree(item.children) : undefined,
|
||||
}));
|
||||
},
|
||||
flattenDept(tree, level = 0) {
|
||||
const result = [];
|
||||
tree.forEach(item => {
|
||||
@@ -400,6 +498,246 @@ export default {
|
||||
this.form[`${prefix}Contact`] = address.contactName || this.form[`${prefix}Contact`] || '';
|
||||
this.form[`${prefix}Phone`] = address.contactPhone || this.form[`${prefix}Phone`] || '';
|
||||
},
|
||||
openRouteMapDialog(target) {
|
||||
if (this.dialogReadonly) return;
|
||||
const prefix = target === 'departure' ? 'departure' : 'arrival';
|
||||
this.routeMapTarget = prefix;
|
||||
this.routeMapKeyword = this.form[`${prefix}Address`] || this.form[`${prefix}Name`] || '';
|
||||
this.routeMapSelected = this.buildRouteMapSelection({
|
||||
lng: this.form[`${prefix}Longitude`],
|
||||
lat: this.form[`${prefix}Latitude`],
|
||||
address: this.form[`${prefix}Address`],
|
||||
regionName: this.form[`${prefix}Name`],
|
||||
});
|
||||
this.routeMapStatus = this.routeMapSelected.longitude
|
||||
? '已加载当前选点,可重新选点'
|
||||
: '可搜索地址或点击地图选点';
|
||||
this.routeMapVisible = true;
|
||||
},
|
||||
loadAmap() {
|
||||
if (window.AMap && window.AMap.Map) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (!amapLoader) {
|
||||
amapLoader = new Promise((resolve, reject) => {
|
||||
window._AMapSecurityConfig = {
|
||||
securityJsCode: AMAP_SECURITY_CODE,
|
||||
};
|
||||
const script = document.createElement('script');
|
||||
script.src = `https://webapi.amap.com/maps?v=2.0&key=${AMAP_KEY}`;
|
||||
script.async = true;
|
||||
script.onload = resolve;
|
||||
script.onerror = () => reject(new Error('高德地图组件加载失败'));
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
}
|
||||
return amapLoader;
|
||||
},
|
||||
initRouteAmap() {
|
||||
this.loadAmap()
|
||||
.then(() => {
|
||||
this.$nextTick(() => {
|
||||
if (!this.routeAmap) {
|
||||
const center = this.toLngLat(
|
||||
this.routeMapSelected.longitude || 116.40769,
|
||||
this.routeMapSelected.latitude || 39.89945
|
||||
);
|
||||
this.routeAmap = new window.AMap.Map(this.$refs.routeAmap, {
|
||||
center,
|
||||
zoom: this.routeMapSelected.longitude ? 14 : 11,
|
||||
});
|
||||
window.AMap.plugin(['AMap.ToolBar', 'AMap.Geocoder'], () => {
|
||||
this.routeAmap.addControl(new window.AMap.ToolBar());
|
||||
if (!this.routeAmapGeocoder) {
|
||||
this.routeAmapGeocoder = new window.AMap.Geocoder();
|
||||
}
|
||||
});
|
||||
this.routeAmap.on('click', event => this.pickRouteMapPoint(event.lnglat));
|
||||
} else if (typeof this.routeAmap.resize === 'function') {
|
||||
this.routeAmap.resize();
|
||||
}
|
||||
if (this.routeMapSelected.longitude) {
|
||||
this.renderRouteMapMarker(
|
||||
this.toLngLat(this.routeMapSelected.longitude, this.routeMapSelected.latitude)
|
||||
);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message.error('高德地图组件加载失败,请稍后重试或重新打开弹窗');
|
||||
this.routeMapVisible = false;
|
||||
});
|
||||
},
|
||||
searchRouteMapKeyword() {
|
||||
const keyword = String(this.routeMapKeyword || '').trim();
|
||||
if (!keyword) {
|
||||
this.$message.warning('请输入地址关键词');
|
||||
return;
|
||||
}
|
||||
this.loadAmap()
|
||||
.then(() => {
|
||||
this.routeMapLoading = true;
|
||||
return this.ensureRouteAmapGeocoder();
|
||||
})
|
||||
.then(() => this.runAmapGeocode('location', keyword))
|
||||
.then(result => {
|
||||
const point = this.resolveMapPoint(result);
|
||||
if (!point) {
|
||||
this.routeMapStatus = '未找到匹配地址';
|
||||
this.$message.warning('地图搜索无匹配地址');
|
||||
return;
|
||||
}
|
||||
this.pickRouteMapPoint(point, keyword);
|
||||
})
|
||||
.catch(() => {
|
||||
this.routeMapStatus = '地图搜索失败';
|
||||
this.$message.error('地图搜索失败,请稍后重试');
|
||||
})
|
||||
.finally(() => {
|
||||
this.routeMapLoading = false;
|
||||
});
|
||||
},
|
||||
pickRouteMapPoint(lnglat, keyword) {
|
||||
const longitude = this.getPointLng(lnglat);
|
||||
const latitude = this.getPointLat(lnglat);
|
||||
if (longitude === undefined || latitude === undefined) {
|
||||
this.$message.warning('选点坐标无效');
|
||||
return;
|
||||
}
|
||||
const point = this.toLngLat(longitude, latitude);
|
||||
this.renderRouteMapMarker(point);
|
||||
this.routeMapSelected = this.buildRouteMapSelection({
|
||||
lng: longitude,
|
||||
lat: latitude,
|
||||
address: keyword,
|
||||
});
|
||||
this.routeMapStatus = '正在反查地址...';
|
||||
this.ensureRouteAmapGeocoder()
|
||||
.then(() => this.runAmapGeocode('address', point))
|
||||
.then(result => {
|
||||
const address = this.resolveMapAddress(result);
|
||||
this.routeMapSelected = {
|
||||
...this.routeMapSelected,
|
||||
detailAddress: address.detailAddress || this.routeMapSelected.detailAddress,
|
||||
regionName: address.regionName || this.routeMapSelected.regionName,
|
||||
};
|
||||
this.routeMapKeyword = this.routeMapSelected.detailAddress || this.routeMapKeyword;
|
||||
this.routeMapStatus = this.routeMapSelected.detailAddress || '已选点,可确认回填';
|
||||
})
|
||||
.catch(() => {
|
||||
this.routeMapStatus = '反查地址失败';
|
||||
this.$message.error('反查地址失败,请重新选点');
|
||||
});
|
||||
},
|
||||
renderRouteMapMarker(point) {
|
||||
if (!this.routeAmap || !window.AMap) return;
|
||||
if (this.routeAmapMarker) {
|
||||
this.routeAmapMarker.setMap(null);
|
||||
}
|
||||
this.routeAmapMarker = new window.AMap.Marker({ position: point });
|
||||
this.routeAmapMarker.setMap(this.routeAmap);
|
||||
this.routeAmap.setCenter(point);
|
||||
},
|
||||
confirmRouteMapPick() {
|
||||
if (!this.routeMapSelected.longitude) {
|
||||
this.$message.warning('请先搜索或点击地图完成选点');
|
||||
return;
|
||||
}
|
||||
const prefix = this.routeMapTarget;
|
||||
this.form[`${prefix}Address`] =
|
||||
this.routeMapSelected.detailAddress || this.form[`${prefix}Address`];
|
||||
this.form[`${prefix}Name`] = this.routeMapSelected.regionName || this.form[`${prefix}Name`];
|
||||
this.form[`${prefix}Longitude`] = this.routeMapSelected.longitude;
|
||||
this.form[`${prefix}Latitude`] = this.routeMapSelected.latitude;
|
||||
this.routeMapVisible = false;
|
||||
this.$refs.crud?.validateField?.(`${prefix}Address`);
|
||||
},
|
||||
buildRouteMapSelection({ lng, lat, address, regionName }) {
|
||||
return {
|
||||
longitude: this.formatCoordinate(lng),
|
||||
latitude: this.formatCoordinate(lat),
|
||||
detailAddress: address || '',
|
||||
regionName: regionName || '',
|
||||
};
|
||||
},
|
||||
formatCoordinate(value) {
|
||||
if (value === undefined || value === null || value === '') return '';
|
||||
const numberValue = Number(value);
|
||||
return Number.isFinite(numberValue) ? numberValue.toFixed(6) : '';
|
||||
},
|
||||
toLngLat(lng, lat) {
|
||||
return new window.AMap.LngLat(Number(lng), Number(lat));
|
||||
},
|
||||
getPointLng(point) {
|
||||
if (!point) return undefined;
|
||||
if (typeof point.getLng === 'function') return point.getLng();
|
||||
return point.lng ?? point.lon;
|
||||
},
|
||||
getPointLat(point) {
|
||||
if (!point) return undefined;
|
||||
if (typeof point.getLat === 'function') return point.getLat();
|
||||
return point.lat;
|
||||
},
|
||||
ensureRouteAmapGeocoder() {
|
||||
if (this.routeAmapGeocoder) return Promise.resolve(this.routeAmapGeocoder);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!window.AMap || !window.AMap.plugin) {
|
||||
reject(new Error('高德地图组件未就绪'));
|
||||
return;
|
||||
}
|
||||
window.AMap.plugin(['AMap.Geocoder'], () => {
|
||||
try {
|
||||
this.routeAmapGeocoder = new window.AMap.Geocoder();
|
||||
resolve(this.routeAmapGeocoder);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
runAmapGeocode(action, input) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timer = window.setTimeout(() => {
|
||||
reject(new Error('高德地图请求超时'));
|
||||
}, 10000);
|
||||
const done = (status, result) => {
|
||||
window.clearTimeout(timer);
|
||||
if (status === 'complete' && result) {
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
reject(new Error('高德地图请求失败'));
|
||||
};
|
||||
try {
|
||||
if (action === 'location') {
|
||||
this.routeAmapGeocoder.getLocation(input, done);
|
||||
} else {
|
||||
this.routeAmapGeocoder.getAddress(input, done);
|
||||
}
|
||||
} catch (error) {
|
||||
window.clearTimeout(timer);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
resolveMapPoint(result) {
|
||||
if (!result) return null;
|
||||
const geocode = Array.isArray(result.geocodes) ? result.geocodes[0] : null;
|
||||
if (geocode && geocode.location) return geocode.location;
|
||||
if (result.location) return result.location;
|
||||
if (result.lnglat) return result.lnglat;
|
||||
if (result.getLng || result.lng || result.lon) return result;
|
||||
return null;
|
||||
},
|
||||
resolveMapAddress(result = {}) {
|
||||
const regeocode = result.regeocode || {};
|
||||
const component = regeocode.addressComponent || {};
|
||||
const city = Array.isArray(component.city) ? '' : component.city;
|
||||
return {
|
||||
detailAddress: regeocode.formattedAddress || '',
|
||||
regionName: [component.province, city, component.district].filter(Boolean).join(''),
|
||||
};
|
||||
},
|
||||
normalizeRow(row) {
|
||||
const submitRow = { ...row };
|
||||
Object.keys(submitRow).forEach(key => {
|
||||
@@ -609,6 +947,27 @@ export default {
|
||||
});
|
||||
});
|
||||
},
|
||||
handleTemplate() {
|
||||
NProgress.start();
|
||||
exportBlob(
|
||||
config.templateUrl,
|
||||
{
|
||||
[this.website.tokenHeader]: getToken(),
|
||||
},
|
||||
{ feedback: true }
|
||||
)
|
||||
.then(res => {
|
||||
downloadXls(res.data, `${config.title}模板.xlsx`);
|
||||
})
|
||||
.finally(() => {
|
||||
NProgress.done();
|
||||
});
|
||||
},
|
||||
handleImport() {
|
||||
const column = this.excelOptionConfig.column.find(item => item.prop === 'excelFile');
|
||||
column.action = config.importUrl;
|
||||
openImportDialog(this, config.title, () => this.onLoad(this.page, this.query));
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -650,5 +1009,31 @@ export default {
|
||||
justify-content: flex-end;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
&__map-toolbar {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.el-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&__map {
|
||||
width: 100%;
|
||||
height: 420px;
|
||||
border: 1px solid #eff1f7;
|
||||
}
|
||||
|
||||
&__map-info {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-top: 10px;
|
||||
color: #606266;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user