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

fix: 优化可售日期

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