Commit f1e3c41b authored by 武广's avatar 武广

fix: 修改餐品类型

parent ee7dfdf8
......@@ -152,24 +152,26 @@ const CustomerInfo = props => {
});
};
// 改变餐品类型
// 改变餐品类型 (1和2要选都选 要不都不选)
const onChangeMealType = async ms => {
try {
if (props.info && props.info.id && ms.length < mealTypes.length) {
await checkConfirm();
}
if (mealTypes.includes('1') && mealTypes.includes('2')) {
if (!(ms.includes('1') && ms.includes('2'))) {
if (ms.includes('4')) {
ms = ['4'];
} else {
ms = [];
}
console.log('ms :>> ', ms);
if (mealTypes.length > ms.length) {
if (ms.includes('1') && ms.includes('2')) {
ms = ['1', '2'];
} else if (ms.includes('4')) {
ms = ['4'];
} else {
ms = [];
}
} else if (ms.length < 3 && ms.length) {
ms = ['1', '2'];
} else if (ms.includes('1') || ms.includes('2')) {
if (ms.includes('4')) {
ms.push('4');
ms = ['1', '2', '4'];
} else {
ms = ['1', '2'];
}
}
form.setFieldsValue({
......
import React, { useEffect } from 'react';
import { Form, InputNumber, Modal, notification } from 'antd';
import { layout } from '../staticData/goods';
import { isCheckPriceTwoDecimal } from '@/utils/validator';
import { apiMealInfoUpdate } from '../service';
const SaleDateModal = props => {
const [form] = Form.useForm();
const layout = {
labelCol: { span: 8 },
wrapperCol: { span: 14 },
};
// 关闭弹窗
const handleCancel = () => {
props.handleClose(false);
......@@ -16,14 +20,16 @@ const SaleDateModal = props => {
const handleConfirm = async () => {
const res = await form.validateFields();
console.log('res :>> ', res);
const params = {
id: props.id,
enterprisePrice: res.price,
};
await apiMealInfoUpdate(params);
notification.success({ message: '保存成功' });
if (props.id) {
const params = {
id: props.id,
enterprisePrice: res.price,
};
await apiMealInfoUpdate(params);
notification.success({ message: '保存成功' });
}
handleCancel();
props.handleRefresh();
props.handleRefresh(res.price);
};
useEffect(() => {
......@@ -38,7 +44,7 @@ const SaleDateModal = props => {
open={props.visible}
destroyOnClose
maskClosable={false}
width="300px"
width="400px"
okText="保存"
onOk={handleConfirm}
onCancel={handleCancel}
......
......@@ -11,7 +11,7 @@ const { Option } = Select;
const SaleDateModal = props => {
const [searchType, setSearchType] = useState('1');
const [searchKeyword, setSearchKeyword] = useState('');
const [goodsType, setGoodsType] = useState('1');
// const [goodsType, setGoodsType] = useState('1');
const [shopId, setShopId] = useState();
const [searchName, setSearchName] = useState('');
const [loading, setLoading] = useState(false);
......@@ -19,7 +19,7 @@ const SaleDateModal = props => {
const [pageSize, setPageSize] = useState(10);
const [total, setTotal] = useState(0);
const [dataSource, setDataSource] = useState([]);
const [shopList, setShopList] = useState(jsonToArray(productType));
const [shopList, setShopList] = useState([]);
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const [selectedRows, setSelectedRows] = useState([]);
......@@ -90,9 +90,18 @@ const SaleDateModal = props => {
notification.error({ message: '请选择要添加的商品' });
return;
}
let shopName = '';
if (shopList) {
shopList.forEach(item => {
if (+item.value === +shopId) {
shopName = item.label;
}
});
}
const arr = deepClone(selectedRows).map(item => ({
...item,
shopId,
shopName,
}));
props.onSelectChange(arr);
handleCancel();
......@@ -123,9 +132,11 @@ const SaleDateModal = props => {
const onSelectAllChange = (selected, rows) => {
const keys = [...selectedRowKeys];
const arr = [...selectedRows];
console.log('selected :>> ', selected);
console.log('rows :>> ', rows);
if (selected) {
rows.forEach(item => {
if (!keys.includes(item.skuId)) {
if (item && !keys.includes(item.skuId)) {
keys.push(item.skuId);
arr.push(item);
}
......@@ -181,13 +192,17 @@ const SaleDateModal = props => {
};
const selectBefore = (
<Select defaultValue="1" onChange={setSearchType}>
<Option value="1">名称</Option>
<Option value="2">SKU</Option>
<Option value="1" key={1}>
名称
</Option>
<Option value="2" key={2}>
SKU
</Option>
</Select>
);
const selectAfter = <SearchOutlined onClick={onSearch} />;
const footers = () => [
<div className={style.footers}>
<div className={style.footers} key="footer">
<Pagination defaultCurrent={1} total={total} showQuickJumper onChange={onPageChange} />
<div className={style['footers-btn']}>
<div className={style['footers-desc']}>
......@@ -205,7 +220,7 @@ const SaleDateModal = props => {
useEffect(() => {
getShopList();
setGoodsType(props.productType);
// setGoodsType(props.productType);
}, []);
return (
......
......@@ -26,6 +26,13 @@ export const productType = {
5: '外卖商品',
};
// 餐品类型:(1外卖 2 自助餐 4到店)
export const mealType = {
1: '外卖',
2: '自助餐',
4: '到店',
};
export const weekOptions = {
1: '周一',
2: '周二',
......@@ -244,11 +251,11 @@ export const takeawayGoodsColumn = options => {
};
export const GoodsInfoColumn = options => {
const { onDel, setVisibleSaleDate, setVisibleSaleSection, setEditID } = options;
const { onDel, setVisibleSaleDate, setVisibleSaleSection, setEditID, setVisiblePrice } = options;
return [
{
title: '微店名称',
dataIndex: 'shopId',
dataIndex: 'shopName',
},
{
title: '商品名称',
......@@ -263,9 +270,22 @@ export const GoodsInfoColumn = options => {
},
{
title: '企业价格',
dataIndex: 'activityPrice',
dataIndex: 'enterprisePrice',
width: 120,
align: 'center',
render: (_, record) => (
<Space>
<span>{_}</span>
<span
onClick={() => {
setEditID(record.skuId);
setVisiblePrice(true);
}}
>
<FormOutlined />
</span>
</Space>
),
},
{
title: '库存',
......@@ -302,7 +322,7 @@ export const GoodsInfoColumn = options => {
},
{
title: '可售餐段',
dataIndex: 'mealType',
dataIndex: 'tabCate',
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -321,10 +341,16 @@ export const GoodsInfoColumn = options => {
},
{
title: '餐品类型',
dataIndex: 'mealType',
dataIndex: 'mealTypeList',
width: 120,
align: 'center',
hideInSearch: true,
render(arr) {
if (arr && arr.length) {
return arr.map(item => mealType[item]).join('/');
}
return '-';
},
},
{
title: '操作',
......
......@@ -85,14 +85,14 @@ const TakeawayGoods = () => {
// 根据企业ID获取取餐点
const getPickSelf = async id => {
const res = await apiSelPickSelfList({ enterpriseId: id });
if (res) {
if (res && res.data) {
setPickSelfList(
res.map(item => ({
res.data.map(item => ({
key: item.pickSelfId,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res[0].pickSelfId);
setActiveKey(res.data[0].pickSelfId);
}
};
......
......@@ -4,6 +4,7 @@ import { useHistory } from 'react-router-dom';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { GoodsInfoColumn } from './staticData/goods';
import SaleDateModal from './components/SaleDateModal';
import GoodPriceModal from './components/GoodPriceModal';
import SaleSectionModal from './components/SaleSectionModal';
import SelectGoodsModal from './components/SelectGoodsModal';
import { apiSelPickSelfList, apiPickSelfList, apiSaveGoodsList } from './service';
......@@ -17,6 +18,7 @@ const TakeawayGoodsInfo = props => {
const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗
const [visibleSaleSection, setVisibleSaleSection] = useState(false); // 可售餐段弹窗
const [visibleSelectGoods, setVisibleSelectGoods] = useState(false); // 选择商品弹窗
const [visiblePrice, setVisiblePrice] = useState(false); // 修改企业商品价格弹窗
const [dataSource, setDataSource] = useState([]);
const [pickSelfList, setPickSelfList] = useState([]); // 取餐点列表
const [slePickSelf, setSelPickSelf] = useState([]); // 选中的取餐点列表
......@@ -37,6 +39,7 @@ const TakeawayGoodsInfo = props => {
enterprisePrice: item.enterprisePrice,
mealTypeList: item.mealType,
saleDateList: item.saleDate,
tabCateList: { tabId: item.tabCate },
}));
const params = {
shopId: id,
......@@ -44,9 +47,11 @@ const TakeawayGoodsInfo = props => {
pickSelfIdList: slePickSelf,
skuInfoList,
};
await apiSaveGoodsList(params);
notification.success({ message: '添加成功' });
onCancel();
const res = await apiSaveGoodsList(params);
if (res && res.success) {
notification.success({ message: '添加成功' });
onCancel();
}
};
// 删除
......@@ -74,7 +79,7 @@ const TakeawayGoodsInfo = props => {
enterpriseId: id,
});
if (res && res.data) {
setSelPickSelf(res.map(item => item.pickSelfId));
setSelPickSelf(res.data.map(item => item.pickSelfId));
}
};
......@@ -115,6 +120,7 @@ const TakeawayGoodsInfo = props => {
setVisibleSaleSection,
setEditID,
onDel,
setVisiblePrice,
};
return (
......@@ -176,7 +182,11 @@ const TakeawayGoodsInfo = props => {
批量配置餐段
</Button>
</div>
<Table columns={GoodsInfoColumn(options)} dataSource={dataSource} />
<Table
columns={GoodsInfoColumn(options)}
pagination={false}
dataSource={dataSource}
/>
</Col>
</Row>
<Row className={style['info-box--btns']}>
......@@ -205,10 +215,18 @@ const TakeawayGoodsInfo = props => {
{visibleSaleSection && (
<SaleSectionModal
visible={visibleSaleSection}
handleRefresh={v => refreshList('mealType', v)}
handleRefresh={v => refreshList('tabCate', v)}
handleClose={() => setVisibleSaleSection(false)}
/>
)}
{/* 修改企业商品价格弹窗 */}
{visiblePrice && (
<GoodPriceModal
visible={visiblePrice}
handleRefresh={v => refreshList('enterprisePrice', v)}
handleClose={() => setVisiblePrice(false)}
/>
)}
{/* 选择商品弹窗 */}
{visibleSelectGoods && (
<SelectGoodsModal
......
......@@ -79,13 +79,15 @@ const VirtualGoods = () => {
// 根据企业ID获取取餐点
const getPickSelf = async () => {
const res = await apiSelPickSelfList({});
setPickSelfList(
res.map(item => ({
key: item.pickSelfId,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res[0].pickSelfId);
if (res && res.data) {
setPickSelfList(
res.data.map(item => ({
key: item.pickSelfId,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res.data[0].pickSelfId);
}
};
// 获取企业列表
......
......@@ -59,12 +59,14 @@ const VirtualGoodsInfo = props => {
const res = await apiShopListByEnterpriseID({
enterpriseId: id,
});
setShopList(
res.map(item => ({
key: item.id,
label: <span>{item.name}</span>,
})),
);
if (res && res.data) {
setShopList(
res.data.map(item => ({
key: item.id,
label: item.name,
})),
);
}
};
// 刷新列表数据
......
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