Commit bba27a3c authored by 武广's avatar 武广

feat: 添加门店管理

parent 91f9d3da
import React, { useState } from 'react';
import { Map, Marker, Icon } from 'react-bmapgl';
import { Modal, Input } from 'antd';
export default props => {
const { visible, onSetPoint, onCancel } = props;
const [lnglat, setLnglat] = useState('');
const handleOk = () => {
onSetPoint(lnglat);
onCancel(true);
};
const handleCancle = () => onCancel(true);
const onGetPoint = e => {
setLnglat(`${e.latlng.lng},${e.latlng.lat}`);
};
return (
<Modal
title="门店信息"
visible={visible}
width="800px"
onOk={() => handleOk()}
onCancel={() => handleCancle()}
>
<div style={{ marginBottom: '20px' }}>
<Input value={lnglat} placeholder="点击地图选择经纬度" />
</div>
<div style={{ width: '100%', height: '360px' }}>
<Map
center={{ lng: 116.404449, lat: 39.914889 }}
enableScrollWheelZoom
enableDoubleClickZoom
onClick={e => onGetPoint(e)}
zoom={15}
>
<Marker
position={{ lng: 116.404449, lat: 39.914889 }}
autoViewport
viewportOptions={{
zoomFactor: -12,
}}
/>
</Map>
</div>
</Modal>
);
};
import React, { useRef, useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Form } from '@ant-design/compatible'; import { Form } from '@ant-design/compatible';
import { BaiduMap } from 'react-baidu-map'; import moment from 'moment';
import '@ant-design/compatible/assets/index.css';
import { import {
Modal, Modal,
Input, Input,
DatePicker, DatePicker,
TimePicker,
Checkbox, Checkbox,
Cascader, Cascader,
Radio, Radio,
notification, notification,
InputNumber,
} from 'antd'; } from 'antd';
import { apiAddrArea } from '../services'; import { apiAddrArea, apiCreatStore } from '../services';
import { weekOptions, weekDefault } from '../data'; import { weekOptions, weekDefault } from '../data';
import MapModal from '@/components/BaiduMap';
const FormItem = Form.Item; const FormItem = Form.Item;
const { TextArea } = Input;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const StoreModal = props => { const StoreModal = props => {
const { const {
visible, visible,
onCancel, onCancel,
form: { getFieldDecorator, getFieldValue, validateFields, resetFields }, form: { getFieldDecorator, getFieldValue, validateFields, resetFields },
formData = {}, // formData,
} = props; } = props;
const location = useRef();
const [areaAddr, setAreaAddr] = useState([]); const [areaAddr, setAreaAddr] = useState([]);
const [formData, setFormData] = useState({});
const [visibleMap, setVisibleMap] = useState(false);
const weekD = formData.weekDefault ? formData.weekDefault : weekDefault; const weekD = formData.weekDefault ? formData.weekDefault : weekDefault;
...@@ -36,26 +36,49 @@ const StoreModal = props => { ...@@ -36,26 +36,49 @@ const StoreModal = props => {
onCancel(isSuccess); onCancel(isSuccess);
}; };
const handleOk = () => { const handleOk = () => {
// validateFields(async (error, fieldsValue) => { console.log('111 :>> ', 111);
// if (!error) { validateFields(async (error, fieldsValue) => {
// const { auditResult } = fieldsValue; console.log('222 :>> ', 222);
// const data = await shopStore({ if (!error) {
// ...fieldsValue, const params = Object.assign({}, fieldsValue);
// refuseCode: auditResult?.[1], const areaArr = ['provinceId', 'cityId', 'countyId', 'townId'];
// auditResult: auditResult?.[0], if (params.addr && params.addr.forEach) {
// serviceNo: formData?.serviceNo, params.addr.forEach((item, i) => {
// }); params[areaArr[i]] = item;
// if (data.businessCode === '0000') { });
// notification.success({ message: '审核成功' }); }
// handleCancel(true); if (params.lnglat) {
// } const arr = params.lnglat.split(',');
// } if (arr.length === 2) {
// }); params.longitude = arr[0] || '';
params.latitude = arr[1] || '';
}
}
params.businessHours = {
weeks: params.week,
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);
if (res === '0000') {
notification.success({ message: '创建成功' });
handleCancel(true);
}
}
});
}; };
const openMap = v => setVisibleMap(v);
// 获取地址省 // 获取地址省
(async () => { const getAreaAddr = async () => {
const [res] = await apiAddrArea(); const res = await apiAddrArea();
console.log('res :>> ', res);
if (res) { if (res) {
const arr = res.map(item => ({ const arr = res.map(item => ({
isLeaf: false, isLeaf: false,
...@@ -65,12 +88,20 @@ const StoreModal = props => { ...@@ -65,12 +88,20 @@ const StoreModal = props => {
})); }));
setAreaAddr(arr); setAreaAddr(arr);
} }
})(); };
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,
}); });
...@@ -91,6 +122,13 @@ const StoreModal = props => { ...@@ -91,6 +122,13 @@ const StoreModal = props => {
} }
}; };
const onSetPoint = e => {
console.log('e :>> ', e);
const form = { ...formData };
form.lnglat = e;
setFormData(form);
};
const layout = { const layout = {
labelCol: { span: 6 }, labelCol: { span: 6 },
wrapperCol: { span: 16 }, wrapperCol: { span: 16 },
...@@ -104,13 +142,13 @@ const StoreModal = props => { ...@@ -104,13 +142,13 @@ const StoreModal = props => {
onCancel={() => handleCancel()} onCancel={() => handleCancel()}
> >
<Form {...layout} name="formData"> <Form {...layout} name="formData">
<FormItem label="门店名称"> <FormItem label="门店名称" name="name">
{getFieldDecorator('name', { {getFieldDecorator('name', {
rules: [{ required: true, message: '请输入门店名称!' }], rules: [{ required: true, message: '请输入门店名称!' }],
initialValue: formData.name, initialValue: formData.name,
})(<Input placeholder="请输入门店名称" maxLength={50} />)} })(<Input placeholder="请输入门店名称" maxLength={50} />)}
</FormItem> </FormItem>
<FormItem label="门店电话"> <FormItem label="门店电话" name="phone">
{getFieldDecorator('phone', { {getFieldDecorator('phone', {
rules: [{ required: true, message: '请输入门店电话!' }], rules: [{ required: true, message: '请输入门店电话!' }],
initialValue: formData.phone, initialValue: formData.phone,
...@@ -119,8 +157,12 @@ const StoreModal = props => { ...@@ -119,8 +157,12 @@ const StoreModal = props => {
<FormItem label="营业时间"> <FormItem label="营业时间">
{getFieldDecorator('time', { {getFieldDecorator('time', {
rules: [{ required: true, message: '请选择营业时间!' }], rules: [{ required: true, message: '请选择营业时间!' }],
initialValue: formData.phone, initialValue: formData.time,
})(<RangePicker />)} })(
<div>
<TimePicker.RangePicker format="HH:mm" />,<TimePicker.RangePicker format="HH:mm" />
</div>,
)}
</FormItem> </FormItem>
<FormItem label=" "> <FormItem label=" ">
{getFieldDecorator('week', { {getFieldDecorator('week', {
...@@ -144,21 +186,32 @@ const StoreModal = props => { ...@@ -144,21 +186,32 @@ const StoreModal = props => {
{getFieldDecorator('lnglat', { {getFieldDecorator('lnglat', {
rules: [{ required: true, message: '请选择经纬度!' }], rules: [{ required: true, message: '请选择经纬度!' }],
initialValue: formData.lnglat, initialValue: formData.lnglat,
})(<Input placeholder="请选择经纬度" readOnly maxLength={100} />)} })(
<Input
placeholder="请选择经纬度"
onClick={() => openMap(true)}
readOnly
maxLength={100}
/>,
)}
</FormItem> </FormItem>
<FormItem label="是否启用"> <FormItem label="是否启用">
{getFieldDecorator('enable', { {getFieldDecorator('state', {
rules: [{ required: true, message: '请选择是否启用!' }], rules: [{ required: true, message: '请选择是否启用!' }],
initialValue: formData.enable, initialValue: formData.state,
})( })(
<Radio.Group> <Radio.Group>
<Radio value={1}></Radio> <Radio value={1}></Radio>
<Radio value={2}></Radio> <Radio value={0}></Radio>
</Radio.Group>, </Radio.Group>,
)} )}
</FormItem> </FormItem>
</Form> </Form>
<BaiduMap id="location" ref={location} style={{ height: 300 }} /> <MapModal
visible={visibleMap}
onCancel={() => openMap(false)}
onSetPoint={e => onSetPoint(e)}
></MapModal>
</Modal> </Modal>
); );
}; };
......
...@@ -11,9 +11,12 @@ export default () => { ...@@ -11,9 +11,12 @@ export default () => {
const [storeInfo, setStoreInfo] = useState({}); const [storeInfo, setStoreInfo] = useState({});
const table = useRef(); const table = useRef();
const onEnableState = async ({ id, state }) => { const onEnableState = async ({ id, state }) => {
const res = await apiEnableStore({ id, state }); const enable = +state === 1 ? 0 : 1;
const res = await apiEnableStore({ id, state: enable });
if (res === '0000') { if (res === '0000') {
notification.success({ message: `已${state ? '禁用' : '启用'}` }); notification.success({ message: `已${state ? '禁用' : '启用'}` });
// eslint-disable-next-line no-unused-expressions
table.current?.reload?.();
} }
}; };
const onCreate = () => { const onCreate = () => {
......
...@@ -42,8 +42,23 @@ export async function apiEnableStore({ id, state }) { ...@@ -42,8 +42,23 @@ export async function apiEnableStore({ id, state }) {
// 获取地址 // 获取地址
export async function apiAddrArea(params) { export async function apiAddrArea(params) {
const data = await request.post('/api/kdsp/area/addr/query', { const data = await request.post('/api/kdsp/area/addr/query', {
prefix: kdspApi,
data: stringify(_.omitBy(params, v => !v)),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
return data.data || [];
}
// 创建门店
export async function apiCreatStore(params) {
const data = await request.post('/shop/create', {
prefix: kdspApi, prefix: kdspApi,
data: _.omitBy(params, v => !v), data: _.omitBy(params, v => !v),
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// },
}); });
return data.businessCode; return data.businessCode;
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<title>商户管理后台</title> <title>商户管理后台</title>
<script <script
type="text/javascript" type="text/javascript"
src="https://api.map.baidu.com/getscript?v=3.0&ak=5gZyih0oAhiNdbbdPKTc9ZGYOwel8bYN" src="https://api.map.baidu.com/api?v=3.0&ak=5gZyih0oAhiNdbbdPKTc9ZGYOwel8bYN&type=webgl"
></script> ></script>
<link rel="icon" href="/favicon.png" type="image/x-icon" /> <link rel="icon" href="/favicon.png" type="image/x-icon" />
</head> </head>
......
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