Commit c7caca16 authored by 武广's avatar 武广

fix: 修改门店列表不刷新的问题

parent 1a04ac87
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { Map, Marker, ZoomControl, CityListControl } from 'react-bmapgl';
import { Modal, Input } from 'antd';
export default props => {
const { visible, onSetPoint, onCancel, lngLat } = props;
const { visible, onSetPoint, onCancel, lngLat, addrInfo } = props;
let defaultLnglat = { lng: 116.404449, lat: 39.914889 };
if (lngLat) {
defaultLnglat = lngLat;
......@@ -27,6 +27,31 @@ export default props => {
setLnglatText(`${e.latlng.lng},${e.latlng.lat}`);
};
// const translateCallback = obj => {
// console.log('obj :>> ', obj);
// setLnglat(obj.points[0]);
// };
const getPoint = () => {
// const convertor = new window.BMapGL.Convertor();
const myGeo = new window.BMapGL.Geocoder();
// 将地址解析结果显示在地图上,并调整地图视野
myGeo.getPoint(
addrInfo.address || '',
point => {
if (point) {
// convertor.translate([point], 1, 5, translateCallback);
setLnglat(point);
}
},
addrInfo.provice || '北京市',
);
};
useEffect(() => {
if (visible) getPoint();
}, [visible]);
return (
<Modal
title="门店信息"
......
......@@ -24,13 +24,17 @@ const StoreModal = props => {
const {
visible,
onCancel,
form: { getFieldDecorator, setFieldsValue, validateFields, resetFields },
form: { getFieldDecorator, setFieldsValue, getFieldsValue, validateFields, resetFields },
formInfo,
} = props;
const [areaAddr, setAreaAddr] = useState([]);
const [visibleMap, setVisibleMap] = useState(false);
const [times, setTimes] = useState([{ name: 'time0' }]);
const [formData, setFormData] = useState({});
const [mapInfo, setMapInfo] = useState({
provice: '',
address: '',
});
const divDom = useRef();
......@@ -82,7 +86,22 @@ const StoreModal = props => {
};
// 显示地图
const openMap = v => setVisibleMap(v);
const openMap = v => {
const values = getFieldsValue();
let provice = '北京市';
if (values.addr.length > 0) {
areaAddr.forEach(item => {
if (item.value === values.addr[0]) {
provice = item.label;
}
});
}
setMapInfo({
provice,
address: values.address,
});
setVisibleMap(v);
};
// 获取地址省
const getAreaAddr = async id => {
......@@ -162,7 +181,7 @@ const StoreModal = props => {
};
useEffect(() => {
if (props.visible) {
if (visible) {
resetFields();
const info = Object.assign({}, formInfo);
if (info && info.id) {
......@@ -186,7 +205,9 @@ const StoreModal = props => {
setFormData(info);
getLazyAddr(info);
} else {
getAreaAddr(0);
if (areaAddr.length < 1) {
getAreaAddr();
}
setFormData({});
}
}
......@@ -197,6 +218,7 @@ const StoreModal = props => {
title="门店信息"
visible={visible}
width="800px"
maskClosable={false}
onOk={() => onSubmit()}
onCancel={() => handleCancel()}
>
......@@ -293,6 +315,7 @@ const StoreModal = props => {
</Form>
<MapModal
visible={visibleMap}
addrInfo={mapInfo}
onCancel={() => openMap(false)}
onSetPoint={e => onSetPoint(e)}
></MapModal>
......
......@@ -34,13 +34,6 @@ export default () => {
setStoreInfo(info);
setVisible(true);
};
const closeModal = isReload => {
if (isReload === true) {
// eslint-disable-next-line no-unused-expressions
table.current?.reload?.();
}
setVisible(false);
};
// 获取市区街道
const loadData = async selectedOptions => {
......@@ -111,6 +104,14 @@ export default () => {
}
getList(params);
};
const closeModal = isReload => {
if (isReload) {
// eslint-disable-next-line no-unused-expressions
onSearch(refSearch.current?.getFieldValue?.() || {});
}
setStoreInfo({});
setVisible(false);
};
const onReset = () => {
if (refSearch.current && refSearch.current.resetFields) {
......@@ -280,6 +281,7 @@ export default () => {
</div>
<Table
dataSource={dataList}
ref={table}
bordered
columns={columns}
rowKey={record => record.id}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment