Commit 822cd441 authored by 武广's avatar 武广

fix: 优化可售日期

parent d7d30b15
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Checkbox, Space, message, Modal, notification } from 'antd'; import { Checkbox, Space, message, Modal, notification, Button } from 'antd';
import { weekOptions } from '../staticData/goods'; import { weekOptions } from '../staticData/goods';
import { apiMealInfoUpdate, apiCheckInfo } from '../service'; import { apiMealInfoUpdate, apiCheckInfo } from '../service';
import style from '../style/index.less';
const SaleDateModal = props => { const SaleDateModal = props => {
const [value, setValue] = useState([]); const [value, setValue] = useState([]);
const [loading, setLoading] = useState(false);
const [checkAll, setCheckAll] = useState(false);
// 关闭弹窗 // 关闭弹窗
const handleCancel = () => { const handleCancel = () => {
...@@ -13,6 +16,7 @@ const SaleDateModal = props => { ...@@ -13,6 +16,7 @@ const SaleDateModal = props => {
const onChangeWeek = e => { const onChangeWeek = e => {
setValue(e); setValue(e);
setCheckAll(e?.length === 7);
}; };
// 提交 // 提交
...@@ -35,7 +39,9 @@ const SaleDateModal = props => { ...@@ -35,7 +39,9 @@ const SaleDateModal = props => {
data.push(obj); data.push(obj);
} }
}); });
setLoading(true);
const res = await apiCheckInfo(data); const res = await apiCheckInfo(data);
setLoading(false);
if (!res || !res.success) { if (!res || !res.success) {
return; return;
} }
...@@ -45,7 +51,9 @@ const SaleDateModal = props => { ...@@ -45,7 +51,9 @@ const SaleDateModal = props => {
id: props.id, id: props.id,
saleDateList: value, saleDateList: value,
}; };
setLoading(true);
await apiMealInfoUpdate(params); await apiMealInfoUpdate(params);
setLoading(false);
notification.success({ message: '保存成功' }); notification.success({ message: '保存成功' });
} }
handleCancel(); handleCancel();
...@@ -70,20 +78,45 @@ const SaleDateModal = props => { ...@@ -70,20 +78,45 @@ const SaleDateModal = props => {
return `${item}`; return `${item}`;
}); });
} }
setCheckAll(v.length === 7);
setValue(v); setValue(v);
} }
}, [props.visible]); }, [props.visible]);
// 全选事件
const onCheckAll = e => {
if (e.target.checked) {
setValue(Object.keys(weekOptions).map(w => `${w}`));
} else {
setValue([]);
}
setCheckAll(e.target.checked);
};
// 弹窗底部
const footerComponent = [
<div key="footer" className={style.modalFooters}>
<Checkbox checked={checkAll} onChange={onCheckAll}>
全选
</Checkbox>
<div>
<Button onClick={handleCancel}> 取消 </Button>
<Button type="primary" loading={loading} onClick={handleConfirm}>
{' '}
保存{' '}
</Button>
</div>
</div>,
];
return ( return (
<Modal <Modal
title={props.title || '设置可售日期'} title={props.title || '设置可售日期'}
open={props.visible} open={props.visible}
destroyOnClose destroyOnClose
maskClosable={false} maskClosable={false}
width="200px" width="300px"
okText="保存" footer={footerComponent}
onOk={handleConfirm}
onCancel={handleCancel}
> >
<Checkbox.Group onChange={onChangeWeek} value={value}> <Checkbox.Group onChange={onChangeWeek} value={value}>
<Space direction="vertical"> <Space direction="vertical">
......
...@@ -75,3 +75,8 @@ ...@@ -75,3 +75,8 @@
.columnBtnEdit { .columnBtnEdit {
cursor: pointer; cursor: pointer;
} }
.modalFooters {
display: flex;
align-items: center;
justify-content: space-between;
}
...@@ -35,10 +35,14 @@ const TakeawayGoods = () => { ...@@ -35,10 +35,14 @@ const TakeawayGoods = () => {
const [editItem, setEditItem] = useState({}); // 编辑的记录信息 const [editItem, setEditItem] = useState({}); // 编辑的记录信息
// 刷新列表 // 刷新列表
const onRefresh = () => { const onRefresh = isReset => {
if (pageLoaded) { if (!pageLoaded) {
refTable.current.reloadAndRest(); return;
// refTable.current.reload(); }
if (isReset) {
refTable?.current?.reloadAndRest();
} else {
refTable?.current?.reload();
} }
}; };
...@@ -118,7 +122,7 @@ const TakeawayGoods = () => { ...@@ -118,7 +122,7 @@ const TakeawayGoods = () => {
const pid = `${obj?.pickSelfId || ''}`; const pid = `${obj?.pickSelfId || ''}`;
setActiveKey(`${pid}`); setActiveKey(`${pid}`);
if (pageLoaded) { if (pageLoaded) {
onRefresh(); onRefresh(true);
} }
}; };
...@@ -196,7 +200,7 @@ const TakeawayGoods = () => { ...@@ -196,7 +200,7 @@ const TakeawayGoods = () => {
items: pickSelfList, items: pickSelfList,
onChange: key => { onChange: key => {
setActiveKey(`${key}`); setActiveKey(`${key}`);
onRefresh(); onRefresh(true);
}, },
}, },
actions: [ actions: [
......
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