Commit 74b477ce authored by 武广's avatar 武广

feat: 修改门店信息

parent 5ec86b4f
...@@ -12,10 +12,11 @@ import { ...@@ -12,10 +12,11 @@ import {
Radio, Radio,
notification, notification,
} from 'antd'; } from 'antd';
import { apiAddrArea, apiCreatStore } from '../services'; import { apiAddrArea, apiCreatStore, apiEditStore } from '../services';
import { weekOptions, weekDefault, layout } from '../data'; import { weekOptions, weekDefault, layout } from '../data';
import MapModal from '@/components/BaiduMap'; import MapModal from '@/components/BaiduMap';
import style from './style.less'; import style from './style.less';
// import { await } from '@umijs/deps/compiled/signale';
const FormItem = Form.Item; const FormItem = Form.Item;
...@@ -23,12 +24,13 @@ const StoreModal = props => { ...@@ -23,12 +24,13 @@ const StoreModal = props => {
const { const {
visible, visible,
onCancel, onCancel,
form: { getFieldDecorator, getFieldValue, setFieldsValue, validateFields, resetFields }, form: { getFieldDecorator, setFieldsValue, validateFields, resetFields },
formData, formInfo,
} = props; } = props;
const [areaAddr, setAreaAddr] = useState([]); const [areaAddr, setAreaAddr] = useState([]);
const [visibleMap, setVisibleMap] = useState(false); const [visibleMap, setVisibleMap] = useState(false);
const [times, setTimes] = useState([{ name: 'time0' }]); const [times, setTimes] = useState([{ name: 'time0' }]);
const [formData, setFormData] = useState({});
const divDom = useRef(); const divDom = useRef();
...@@ -39,7 +41,7 @@ const StoreModal = props => { ...@@ -39,7 +41,7 @@ const StoreModal = props => {
const onSubmit = () => { const onSubmit = () => {
validateFields(async (error, fieldsValue) => { validateFields(async (error, fieldsValue) => {
if (!error) { if (!error) {
const params = Object.assign({}, fieldsValue); const params = Object.assign({}, formInfo, fieldsValue);
const areaArr = ['provinceId', 'cityId', 'countyId', 'townId']; const areaArr = ['provinceId', 'cityId', 'countyId', 'townId'];
if (params.addr && params.addr.forEach) { if (params.addr && params.addr.forEach) {
params.addr.forEach((item, i) => { params.addr.forEach((item, i) => {
...@@ -66,7 +68,11 @@ const StoreModal = props => { ...@@ -66,7 +68,11 @@ const StoreModal = props => {
weeks: params.week, weeks: params.week,
hoursItems, hoursItems,
}; };
const res = await apiCreatStore(params); let api = apiCreatStore;
if (params.id) {
api = apiEditStore;
}
const res = await api(params);
if (res === '0000') { if (res === '0000') {
notification.success({ message: '保存成功' }); notification.success({ message: '保存成功' });
handleCancel(true); handleCancel(true);
...@@ -79,9 +85,12 @@ const StoreModal = props => { ...@@ -79,9 +85,12 @@ const StoreModal = props => {
const openMap = v => setVisibleMap(v); const openMap = v => setVisibleMap(v);
// 获取地址省 // 获取地址省
const getAreaAddr = async () => { const getAreaAddr = async id => {
const res = await apiAddrArea(); const params = {};
console.log('res :>> ', res); if (id) {
params.parentId = id;
}
const res = await apiAddrArea(params);
if (res) { if (res) {
const arr = res.map(item => ({ const arr = res.map(item => ({
isLeaf: false, isLeaf: false,
...@@ -90,7 +99,9 @@ const StoreModal = props => { ...@@ -90,7 +99,9 @@ const StoreModal = props => {
value: item.addrId, value: item.addrId,
})); }));
setAreaAddr(arr); setAreaAddr(arr);
return arr;
} }
return [];
}; };
// 获取市区街道 // 获取市区街道
...@@ -137,10 +148,46 @@ const StoreModal = props => { ...@@ -137,10 +148,46 @@ const StoreModal = props => {
}); });
}; };
const getLazyAddr = async info => {
const arr = await getAreaAddr();
const parr = arr.filter(item => +item.value === +info.provinceId);
parr[0].children = await getAreaAddr(parr[0].value);
const carr = parr[0].children.filter(item => +item.value === +info.cityId);
carr[0].children = await getAreaAddr(carr[0].value);
if (info.townId) {
const aarr = carr[0].children.filter(item => +item.value === +info.countyId);
aarr[0].children = await getAreaAddr(aarr[0].value);
}
setAreaAddr([...arr]);
};
useEffect(() => { useEffect(() => {
if (props.visible) { if (props.visible) {
resetFields(); resetFields();
getAreaAddr(); const info = Object.assign({}, formInfo);
if (info && info.id) {
info.week = info.businessHours.weeks;
const hours = info.businessHours.hoursItems;
const harr = [];
if (hours && hours.length) {
hours.forEach((item, i) => {
info[`time${i}`] = [moment(item.begin, 'HH:mm'), moment(item.end, 'HH:mm')];
harr.push({
name: `time${i}`,
});
});
}
info.lnglat = `${info.longitude},${info.latitude}`;
info.addr = [info.provinceId, info.cityId, info.countyId];
if (info.townId) {
info.addr.push(info.townId);
}
setTimes(harr);
setFormData(info);
getLazyAddr(info);
} else {
getAreaAddr(0);
}
} }
}, [visible]); }, [visible]);
...@@ -157,13 +204,13 @@ const StoreModal = props => { ...@@ -157,13 +204,13 @@ const StoreModal = props => {
{getFieldDecorator('name', { {getFieldDecorator('name', {
rules: [{ required: true, message: '请输入门店名称!' }], rules: [{ required: true, message: '请输入门店名称!' }],
initialValue: formData.name, initialValue: formData.name,
})(<Input placeholder="请输入门店名称" maxLength={50} />)} })(<Input placeholder="请输入门店名称" allowClear maxLength={50} />)}
</FormItem> </FormItem>
<FormItem label="门店电话" name="phone"> <FormItem label="门店电话" name="phone">
{getFieldDecorator('phone', { {getFieldDecorator('phone', {
rules: [{ required: true, message: '请输入门店电话!' }], rules: [{ required: true, message: '请输入门店电话!' }],
initialValue: formData.phone, initialValue: formData.phone,
})(<Input placeholder="请输入门店电话" maxLength={20} />)} })(<Input placeholder="请输入门店电话" allowClear maxLength={20} />)}
</FormItem> </FormItem>
<FormItem label="营业时间" required> <FormItem label="营业时间" required>
{times && {times &&
...@@ -173,6 +220,7 @@ const StoreModal = props => { ...@@ -173,6 +220,7 @@ const StoreModal = props => {
<FormItem name={item.name}> <FormItem name={item.name}>
{getFieldDecorator(item.name, { {getFieldDecorator(item.name, {
rules: [{ required: true, message: '请选择营业时间!' }], rules: [{ required: true, message: '请选择营业时间!' }],
initialValue: formData[item.name],
})(<TimePicker.RangePicker format="HH:mm" />)} })(<TimePicker.RangePicker format="HH:mm" />)}
</FormItem> </FormItem>
</div> </div>
...@@ -206,13 +254,20 @@ const StoreModal = props => { ...@@ -206,13 +254,20 @@ const StoreModal = props => {
{getFieldDecorator('address', { {getFieldDecorator('address', {
rules: [{ required: true, message: '请输入详细地址!' }], rules: [{ required: true, message: '请输入详细地址!' }],
initialValue: formData.address, initialValue: formData.address,
})(<Input placeholder="请输入详细地址" maxLength={100} />)} })(<Input placeholder="请输入详细地址" allowClear maxLength={100} />)}
</FormItem> </FormItem>
<FormItem label="经纬度"> <FormItem label="经纬度">
{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="请选择经纬度"
readOnly
onClick={() => openMap(true)}
maxLength={100}
/>,
)}
</FormItem> </FormItem>
<FormItem label="是否启用"> <FormItem label="是否启用">
{getFieldDecorator('state', { {getFieldDecorator('state', {
......
...@@ -20,6 +20,11 @@ export default () => { ...@@ -20,6 +20,11 @@ export default () => {
} }
}; };
const onCreate = () => { const onCreate = () => {
setStoreInfo({});
setVisible(true);
};
const onShowInfo = info => {
setStoreInfo(info);
setVisible(true); setVisible(true);
}; };
const closeModal = isReload => { const closeModal = isReload => {
...@@ -96,7 +101,6 @@ export default () => { ...@@ -96,7 +101,6 @@ export default () => {
valueEnum: stateDesc, valueEnum: stateDesc,
hideInSearch: true, hideInSearch: true,
width: 120, width: 120,
// render: state => <span>{`${stateDesc[state]}`}</span>,
}, },
{ {
title: '创建时间', title: '创建时间',
...@@ -108,12 +112,15 @@ export default () => { ...@@ -108,12 +112,15 @@ export default () => {
title: '操作', title: '操作',
hideInSearch: true, hideInSearch: true,
dataIndex: 'action', dataIndex: 'action',
width: 100, width: 170,
fixed: 'right', fixed: 'right',
render: (val, r) => [ render: (val, r) => [
<Button onClick={() => onEnableState(r)} type="primary"> <Button onClick={() => onEnableState(r)} type="primary">
{+r.state ? '禁用' : '启用'} {+r.state ? '禁用' : '启用'}
</Button>, </Button>,
<Button style={{ marginLeft: '10px' }} onClick={() => onShowInfo(r)}>
查看
</Button>,
], ],
}, },
]; ];
...@@ -140,7 +147,7 @@ export default () => { ...@@ -140,7 +147,7 @@ export default () => {
</Button>, </Button>,
]} ]}
/> />
<StoreModal visible={visible} onCancel={closeModal} formData={storeInfo} /> <StoreModal visible={visible} onCancel={closeModal} formInfo={storeInfo} />
</div> </div>
); );
}; };
...@@ -62,3 +62,15 @@ export async function apiCreatStore(params) { ...@@ -62,3 +62,15 @@ export async function apiCreatStore(params) {
}); });
return data.businessCode; return data.businessCode;
} }
// 更新门店
export async function apiEditStore(params) {
const data = await request.post('/shop/update', {
prefix: kdspApi,
data: params,
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// },
});
return data.businessCode;
}
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