Commit 5ec86b4f authored by 武广's avatar 武广

fix: 优化添加门店

优化地图选择
parent bba27a3c
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Map, Marker, Icon } from 'react-bmapgl'; import { Map, Marker, ZoomControl, CityListControl } from 'react-bmapgl';
import { Modal, Input } from 'antd'; import { Modal, Input } from 'antd';
export default props => { export default props => {
const { visible, onSetPoint, onCancel } = props; const { visible, onSetPoint, onCancel, lngLat } = props;
let defaultLnglat = { lng: 116.404449, lat: 39.914889 };
if (lngLat) {
defaultLnglat = lngLat;
}
const [lnglat, setLnglat] = useState(''); const [lnglat, setLnglat] = useState(defaultLnglat);
const [lnglatText, setLnglatText] = useState(`${defaultLnglat.lng},${defaultLnglat.lat}`);
const handleOk = () => { const handleOk = () => {
onSetPoint(lnglat); onSetPoint(lnglatText);
onCancel(true); onCancel(true);
}; };
const handleCancle = () => onCancel(true); const handleCancle = () => onCancel(true);
const onGetPoint = e => { const onGetPoint = e => {
setLnglat(`${e.latlng.lng},${e.latlng.lat}`); setLnglat({
lng: e.latlng.lng,
lat: e.latlng.lat,
});
setLnglatText(`${e.latlng.lng},${e.latlng.lat}`);
}; };
return ( return (
...@@ -27,23 +36,28 @@ export default props => { ...@@ -27,23 +36,28 @@ export default props => {
onCancel={() => handleCancle()} onCancel={() => handleCancle()}
> >
<div style={{ marginBottom: '20px' }}> <div style={{ marginBottom: '20px' }}>
<Input value={lnglat} placeholder="点击地图选择经纬度" /> <Input value={lnglatText} placeholder="点击地图选择经纬度" />
</div> </div>
<div style={{ width: '100%', height: '360px' }}> <div style={{ width: '100%', height: '360px' }}>
<Map <Map
center={{ lng: 116.404449, lat: 39.914889 }} center={lnglat}
enableScrollWheelZoom enableScrollWheelZoom
enableDoubleClickZoom enableDoubleClickZoom
coordType="gcj02"
onClick={e => onGetPoint(e)} onClick={e => onGetPoint(e)}
zoom={15} zoom={15}
> >
<Marker <Marker
position={{ lng: 116.404449, lat: 39.914889 }} position={lnglat}
Icon
coordType="gcj02"
autoViewport autoViewport
viewportOptions={{ viewportOptions={{
zoomFactor: -12, zoomFactor: -12,
}} }}
/> />
<CityListControl />
<ZoomControl />
</Map> </Map>
</div> </div>
</Modal> </Modal>
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Form } from '@ant-design/compatible'; import { Form } from '@ant-design/compatible';
import moment from 'moment'; import moment from 'moment';
import { PlusSquareFilled, MinusSquareFilled } from '@ant-design/icons';
import { import {
Modal, Modal,
Input, Input,
...@@ -12,33 +13,31 @@ import { ...@@ -12,33 +13,31 @@ import {
notification, notification,
} from 'antd'; } from 'antd';
import { apiAddrArea, apiCreatStore } from '../services'; import { apiAddrArea, apiCreatStore } from '../services';
import { weekOptions, weekDefault } from '../data'; import { weekOptions, weekDefault, layout } from '../data';
import MapModal from '@/components/BaiduMap'; import MapModal from '@/components/BaiduMap';
import style from './style.less';
const FormItem = Form.Item; const FormItem = Form.Item;
const { RangePicker } = DatePicker;
const StoreModal = props => { const StoreModal = props => {
const { const {
visible, visible,
onCancel, onCancel,
form: { getFieldDecorator, getFieldValue, validateFields, resetFields }, form: { getFieldDecorator, getFieldValue, setFieldsValue, validateFields, resetFields },
// formData, formData,
} = props; } = props;
const [areaAddr, setAreaAddr] = useState([]); const [areaAddr, setAreaAddr] = useState([]);
const [formData, setFormData] = useState({});
const [visibleMap, setVisibleMap] = useState(false); const [visibleMap, setVisibleMap] = useState(false);
const [times, setTimes] = useState([{ name: 'time0' }]);
const weekD = formData.weekDefault ? formData.weekDefault : weekDefault; const divDom = useRef();
const handleCancel = isSuccess => { const handleCancel = isSuccess => {
resetFields(); resetFields();
onCancel(isSuccess); onCancel(isSuccess);
}; };
const handleOk = () => { const onSubmit = () => {
console.log('111 :>> ', 111);
validateFields(async (error, fieldsValue) => { validateFields(async (error, fieldsValue) => {
console.log('222 :>> ', 222);
if (!error) { if (!error) {
const params = Object.assign({}, fieldsValue); const params = Object.assign({}, fieldsValue);
const areaArr = ['provinceId', 'cityId', 'countyId', 'townId']; const areaArr = ['provinceId', 'cityId', 'countyId', 'townId'];
...@@ -54,25 +53,29 @@ const StoreModal = props => { ...@@ -54,25 +53,29 @@ const StoreModal = props => {
params.latitude = arr[1] || ''; params.latitude = arr[1] || '';
} }
} }
const hoursItems = [];
if (times && times.length && times.forEach) {
times.forEach(item => {
hoursItems.push({
begin: moment(params[item.name][0]).format('HH:mm'),
end: moment(params[item.name][1]).format('HH:mm'),
});
});
}
params.businessHours = { params.businessHours = {
weeks: params.week, weeks: params.week,
hoursItems: [ hoursItems,
{
begin: moment(params.time[0]).format('HH:mm'),
end: moment(params.time[1]).format('HH:mm'),
},
],
}; };
console.log('params :>> ', params);
const res = await apiCreatStore(params); const res = await apiCreatStore(params);
if (res === '0000') { if (res === '0000') {
notification.success({ message: '创建成功' }); notification.success({ message: '保存成功' });
handleCancel(true); handleCancel(true);
} }
} }
}); });
}; };
// 显示地图
const openMap = v => setVisibleMap(v); const openMap = v => setVisibleMap(v);
// 获取地址省 // 获取地址省
...@@ -90,18 +93,10 @@ const StoreModal = props => { ...@@ -90,18 +93,10 @@ const StoreModal = props => {
} }
}; };
useEffect(() => {
if (props.visible) {
getAreaAddr();
}
}, [visible]);
// 获取市区街道 // 获取市区街道
const loadData = async selectedOptions => { const loadData = async selectedOptions => {
console.log('2222 :>> ', 2222);
const targetOption = selectedOptions[selectedOptions.length - 1]; const targetOption = selectedOptions[selectedOptions.length - 1];
targetOption.loading = true; targetOption.loading = true;
console.log('targetOption.value :>> ', targetOption.value);
const res = await apiAddrArea({ const res = await apiAddrArea({
parentId: targetOption.value, parentId: targetOption.value,
}); });
...@@ -117,28 +112,44 @@ const StoreModal = props => { ...@@ -117,28 +112,44 @@ const StoreModal = props => {
targetOption.children = children; targetOption.children = children;
} else { } else {
targetOption.isLeaf = true; targetOption.isLeaf = true;
if (selectedOptions.length === 3) {
divDom.current.blur();
}
} }
setAreaAddr([...areaAddr]); setAreaAddr([...areaAddr]);
} }
}; };
const onSetPoint = e => { const onTimePlus = () => {
console.log('e :>> ', e); times.push({
const form = { ...formData }; name: `time${times.length}`,
form.lnglat = e; });
setFormData(form); setTimes([...times]);
};
const onTimeMinus = i => {
times.splice(i, 1);
setTimes([...times]);
}; };
const layout = { const onSetPoint = e => {
labelCol: { span: 6 }, setFieldsValue({
wrapperCol: { span: 16 }, lnglat: e,
});
}; };
useEffect(() => {
if (props.visible) {
resetFields();
getAreaAddr();
}
}, [visible]);
return ( return (
<Modal <Modal
title="门店信息" title="门店信息"
visible={visible} visible={visible}
width="800px" width="800px"
onOk={() => handleOk()} onOk={() => onSubmit()}
onCancel={() => handleCancel()} onCancel={() => handleCancel()}
> >
<Form {...layout} name="formData"> <Form {...layout} name="formData">
...@@ -154,27 +165,42 @@ const StoreModal = props => { ...@@ -154,27 +165,42 @@ const StoreModal = props => {
initialValue: formData.phone, initialValue: formData.phone,
})(<Input placeholder="请输入门店电话" maxLength={20} />)} })(<Input placeholder="请输入门店电话" maxLength={20} />)}
</FormItem> </FormItem>
<FormItem label="营业时间"> <FormItem label="营业时间" required>
{getFieldDecorator('time', { {times &&
rules: [{ required: true, message: '请选择营业时间!' }], times.map((item, i) => (
initialValue: formData.time, <div className={style.timerWrapper}>
})( <div>
<div> <FormItem name={item.name}>
<TimePicker.RangePicker format="HH:mm" />,<TimePicker.RangePicker format="HH:mm" /> {getFieldDecorator(item.name, {
</div>, rules: [{ required: true, message: '请选择营业时间!' }],
)} })(<TimePicker.RangePicker format="HH:mm" />)}
</FormItem>
</div>
{i > 0 ? (
<div className={style.timerWrapperRight} onClick={() => onTimeMinus(i)}>
<MinusSquareFilled style={{ color: '#ff4d4f', fontSize: '30px' }} />
</div>
) : (
<div className={style.timerWrapperRight} onClick={() => onTimePlus()}>
<PlusSquareFilled style={{ color: '#1890ff', fontSize: '30px' }} />
</div>
)}
</div>
))}
</FormItem> </FormItem>
<FormItem label=" "> <FormItem label="营业日">
{getFieldDecorator('week', { {getFieldDecorator('week', {
rules: [{ required: true, message: '请选择营业日!' }], rules: [{ required: true, message: '请选择营业日!' }],
initialValue: formData.week, initialValue: formData.week || weekDefault,
})(<Checkbox.Group options={weekOptions} defaultValue={weekD} />)} })(<Checkbox.Group options={weekOptions} />)}
</FormItem> </FormItem>
<FormItem label="店铺区域"> <FormItem label="店铺区域">
{getFieldDecorator('addr', { {getFieldDecorator('addr', {
rules: [{ required: true, type: 'array', message: '请选择店铺区域!' }], rules: [{ required: true, type: 'array', message: '请选择店铺区域!' }],
initialValue: formData.addr, initialValue: formData.addr,
})(<Cascader options={areaAddr} loadData={e => loadData(e)} changeOnSelect />)} })(
<Cascader ref={divDom} options={areaAddr} loadData={e => loadData(e)} changeOnSelect />,
)}
</FormItem> </FormItem>
<FormItem label="详细地址"> <FormItem label="详细地址">
{getFieldDecorator('address', { {getFieldDecorator('address', {
...@@ -186,14 +212,7 @@ const StoreModal = props => { ...@@ -186,14 +212,7 @@ const StoreModal = props => {
{getFieldDecorator('lnglat', { {getFieldDecorator('lnglat', {
rules: [{ required: true, message: '请选择经纬度!' }], rules: [{ required: true, message: '请选择经纬度!' }],
initialValue: formData.lnglat, initialValue: formData.lnglat,
})( })(<Input placeholder="请选择经纬度" onClick={() => openMap(true)} maxLength={100} />)}
<Input
placeholder="请选择经纬度"
onClick={() => openMap(true)}
readOnly
maxLength={100}
/>,
)}
</FormItem> </FormItem>
<FormItem label="是否启用"> <FormItem label="是否启用">
{getFieldDecorator('state', { {getFieldDecorator('state', {
......
.timerWrapper {
display: flex;
}
.timerWrapperRight {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
padding-left: 10px;
cursor: pointer;
}
...@@ -15,3 +15,8 @@ export const weekOptions = [ ...@@ -15,3 +15,8 @@ export const weekOptions = [
]; ];
export const weekDefault = [1, 2, 3, 4, 5, 6, 7]; export const weekDefault = [1, 2, 3, 4, 5, 6, 7];
export const layout = {
labelCol: { span: 6 },
wrapperCol: { span: 16 },
};
...@@ -128,7 +128,7 @@ export default () => { ...@@ -128,7 +128,7 @@ export default () => {
}} }}
bordered bordered
actionRef={table} actionRef={table}
scroll={{ x: '100%', y: 400 }} scroll={{ x: '100%' }}
search={{ search={{
collapsed: false, collapsed: false,
collapseRender: () => null, collapseRender: () => null,
......
...@@ -55,7 +55,7 @@ export async function apiAddrArea(params) { ...@@ -55,7 +55,7 @@ export async function apiAddrArea(params) {
export async function apiCreatStore(params) { export async function apiCreatStore(params) {
const data = await request.post('/shop/create', { const data = await request.post('/shop/create', {
prefix: kdspApi, prefix: kdspApi,
data: _.omitBy(params, v => !v), data: params,
// headers: { // headers: {
// 'Content-Type': 'application/x-www-form-urlencoded', // 'Content-Type': 'application/x-www-form-urlencoded',
// }, // },
......
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