Commit 12a621f0 authored by 武广's avatar 武广

Merge branch 'feature/group-meal' of git.quantgroup.cn:ui/merchant-manage-ui into feature/meal-3.0

parents 45b05eb4 63fda8bf
......@@ -5,7 +5,7 @@ const environment = 'sc';
// 从tob进入的判断接口前缀
const getUrlParams = name => {
const regArg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
const r = window.location.search.substr(1).match(regArg);
const r = window.location.search.substring(1).match(regArg);
if (r != null) return decodeURIComponent(r[2]);
return null;
};
......
......@@ -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')) {
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);
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([]);
......@@ -76,6 +76,7 @@ const SaleDateModal = props => {
shopId: v,
});
setSelectedRowKeys([]);
setSelectedRows([]);
};
// 关闭弹窗
......@@ -89,11 +90,21 @@ 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);
props.onChangeShop(shopId);
handleCancel();
};
......@@ -122,9 +133,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);
}
......@@ -180,13 +193,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']}>
......@@ -204,7 +221,7 @@ const SaleDateModal = props => {
useEffect(() => {
getShopList();
setGoodsType(props.productType);
// setGoodsType(props.productType);
}, []);
return (
......
......@@ -25,23 +25,21 @@ export const getEnterpriseList = async () => {
};
// 获取店铺列表
export const getShopList = debounce(async e => {
const { name } = e;
const res = await apiShopList({ name });
const res = await apiShopList({ name: e });
if (res && res.data && res.data.records) {
const data = res.data.records;
const json = {};
data.forEach(item => {
json[item.id] = { text: item.name };
});
return {
id: res[res.length - 1].id,
list: json,
};
// const json = {};
// data.forEach(item => {
// json[item.id] = { text: item.name };
// });
// return json;
return data.map(item => ({
value: item.id,
text: item.name,
}));
}
return {
id: '',
list: {},
};
// return {};
return [];
}, 300);
// 获取店铺列表通过自提点ID
export const getShopListByPickSelf = async e => {
......
......@@ -26,6 +26,13 @@ export const productType = {
5: '外卖商品',
};
// 餐品类型:(1外卖 2 自助餐 4到店)
export const mealType = {
1: '外卖',
2: '自助餐',
4: '到店',
};
export const weekOptions = {
1: '周一',
2: '周二',
......@@ -39,7 +46,6 @@ export const weekOptions = {
export const takeawayGoodsColumn = options => {
const {
onDel,
companyEnum,
shopEnum,
onChangeFlag,
setVisibleSaleDate,
......@@ -68,39 +74,44 @@ export const takeawayGoodsColumn = options => {
hideInTable: true,
fieldProps: {
showSearch: true,
filterOption: false,
onSearch: getShopList,
},
// request: getShopList,
// valueEnum: {}, // shopEnum,
valueEnum: {}, // shopEnum,
},
{
title: 'SKU编码',
dataIndex: 'skuId',
width: 120,
width: 160,
align: 'center',
},
{
title: '商品名称',
dataIndex: 'skuName',
width: 120,
align: 'center',
},
{
title: '商品图片',
dataIndex: 'primaryImage',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
valueType: 'image',
},
{
title: '可售日期',
dataIndex: 'saleTimeType',
dataIndex: 'saleDateList',
width: 120,
align: 'center',
hideInSearch: true,
render: (_, record) => (
<Space>
<span>{_}</span>
{_ && _.length && (
<div>
{_.length === 7 ? '不限制' : <span>{_.map(item => item.name).join('/')}</span>}
</div>
)}
<span
onClick={() => {
setRecordID(record.id);
......@@ -114,13 +125,13 @@ export const takeawayGoodsColumn = options => {
},
{
title: '可售餐段',
dataIndex: 'saleDate',
dataIndex: 'tabCateList',
width: 120,
align: 'center',
hideInSearch: true,
render: (_, record) => (
<Space>
<span>{_}</span>
{_ && _.length && <span>{_.map(item => item.tabName).join('/')}</span>}
<span
onClick={() => {
setRecordID(record.id);
......@@ -135,7 +146,7 @@ export const takeawayGoodsColumn = options => {
{
title: '企业价格',
dataIndex: 'activityPrice',
width: 120,
width: 100,
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -155,14 +166,14 @@ export const takeawayGoodsColumn = options => {
{
title: '商品销售价',
dataIndex: 'price',
width: 120,
width: 100,
align: 'center',
hideInSearch: true,
},
{
title: '状态',
dataIndex: 'status',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
valueEnum: {
......@@ -174,7 +185,7 @@ export const takeawayGoodsColumn = options => {
{
title: '排序',
dataIndex: 'sort',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -194,7 +205,7 @@ export const takeawayGoodsColumn = options => {
{
title: '列出商品',
dataIndex: 'showFlag',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -208,7 +219,7 @@ export const takeawayGoodsColumn = options => {
{
title: '餐品类型',
dataIndex: 'mealType',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
},
......@@ -218,6 +229,9 @@ export const takeawayGoodsColumn = options => {
width: 120,
valueType: 'dateRange',
align: 'center',
render(v, record) {
return record.createDate;
},
},
{
title: '当日餐段',
......@@ -244,11 +258,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 +277,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 +329,7 @@ export const GoodsInfoColumn = options => {
},
{
title: '可售餐段',
dataIndex: 'mealType',
dataIndex: 'tabCate',
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -321,10 +348,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 => item.name).join('/');
}
return '-';
},
},
{
title: '操作',
......@@ -386,3 +419,139 @@ export const SelectGoodsColumn = [
hideInSearch: true,
},
];
// 企业虚拟商品列表字段
export const virtualGoodsColumn = options => {
const { onDel, enterprises, onChangeEnterprise } = options;
return [
{
title: '企业名称',
dataIndex: 'enterpriseId',
hideInTable: true,
fieldProps: {
showSearch: true,
filterOption: (v, option) => (option?.label ?? '').toLowerCase().includes(v.toLowerCase()),
onChange: onChangeEnterprise,
},
valueEnum: enterprises, // companyEnum,
},
{
title: '微店名称',
dataIndex: 'shopId',
hideInTable: true,
fieldProps: {
showSearch: true,
filterOption: false,
onSearch: getShopList,
},
// request: getShopList,
valueEnum: {}, // shopEnum,
},
{
title: 'SKU编码',
dataIndex: 'skuId',
width: 160,
align: 'center',
},
{
title: '商品名称',
dataIndex: 'skuName',
align: 'center',
},
{
title: '商品图片',
dataIndex: 'primaryImage',
width: 80,
align: 'center',
hideInSearch: true,
valueType: 'image',
},
{
title: '可售日期',
dataIndex: 'saleDateList',
width: 120,
align: 'center',
hideInSearch: true,
render: (_, record) => (
<Space>
{_ && _.length && (
<div>
{_.length === 7 ? '不限制' : <span>{_.map(item => item.name).join('/')}</span>}
</div>
)}
</Space>
),
},
{
title: '可售餐段',
dataIndex: 'tabCateList',
width: 120,
align: 'center',
hideInSearch: true,
render: (_, record) => (
<Space>{_ && _.length && <span>{_.map(item => item.tabName).join('/')}</span>}</Space>
),
},
{
title: '企业价格',
dataIndex: 'activityPrice',
width: 100,
align: 'center',
hideInSearch: true,
render: (_, record) => (
<Space>
<span>{_}</span>
</Space>
),
},
{
title: '商品销售价',
dataIndex: 'price',
width: 100,
align: 'center',
hideInSearch: true,
},
{
title: '状态',
dataIndex: 'status',
width: 80,
align: 'center',
hideInSearch: true,
valueEnum: {
1: '生效中',
2: '已下架',
3: '已售罄',
},
},
{
title: '餐品类型',
dataIndex: 'mealType',
width: 80,
align: 'center',
hideInSearch: true,
},
{
title: '添加时间',
dataIndex: 'createDate',
width: 120,
valueType: 'dateRange',
align: 'center',
render(v, record) {
return record.createDate;
},
},
{
title: '操作',
hideInSearch: true,
dataIndex: 'action',
width: '100px',
align: 'center',
fixed: 'right',
render: (val, r) => (
<Button key="del" onClick={() => onDel(r.id)}>
删除
</Button>
),
},
];
};
......@@ -17,48 +17,60 @@ import { getToUrlQuery } from '@/utils/utils';
const TakeawayGoods = () => {
const history = useHistory();
const refTable = useRef();
const [pageLoading, setPageLoading] = useState(true); // 可售日期弹窗
const [pageLoaded, setPageLoaded] = useState(false); // 可售日期弹窗
const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗
const [visibleSaleSection, setVisibleSaleSection] = useState(false); // 可售餐段弹窗
const [visiblePrice, setVisiblePrice] = useState(false); // 修改企业商品价格弹窗
const [visibleSort, setVisibleSort] = useState(false); // 商品排序弹窗
const [enterprises, setEnterprises] = useState({ 1: { text: '领红包' } }); // 企业列表
const [enterprises, setEnterprises] = useState({}); // 企业列表
const [shopEnum, setShopEnum] = useState({}); // 店铺列表
const [activeKey, setActiveKey] = useState('');
const [enterpriseId, setEnterpriseId] = useState('1');
const [enterpriseId, setEnterpriseId] = useState();
const [pickSelfList, setPickSelfList] = useState([]); // 取餐点列表
const [recordID, setRecordID] = useState(''); // 编辑的记录ID
// 刷新列表
const onRefresh = () => {
if (pageLoaded) {
refTable.current.reloadAndRest();
// refTable.current.reload();
}
};
// 搜索商品列表
const searchList = async params => {
if (params.enterpriseId && params.enterpriseId !== enterpriseId) {
setEnterpriseId(params.enterpriseId);
}
const data = {
page: params.current,
size: params.pageSize,
data: Object.assign(
{
page: params.current || 1,
size: params.pageSize || 10,
data: Object.assign({}, params, {
enterpriseId,
},
params,
),
pickSelfId: activeKey,
}),
};
const res = await apiTakeawayList(data);
if (res && res.records) {
return {
data: res.records,
total: res.total,
data: res.records || [],
total: res.total || 0,
};
}
return {
data: [],
total: 0,
};
};
// 删除商品
const onDel = async id => {
await apiMealInfoDel({
id,
});
refTable.current.reload();
notification.success({
message: '删除成功',
});
};
const onAdd = async () => {
// 跳转添加商品
const toAdd = async () => {
const params = getToUrlQuery();
const query = Object.assign(
{
......@@ -72,7 +84,7 @@ const TakeawayGoods = () => {
query,
});
};
// 修改商品是否列出
const onChangeFlag = async (id, checked) => {
const params = {
id,
......@@ -80,28 +92,33 @@ const TakeawayGoods = () => {
};
await apiMealInfoUpdate(params);
notification.success({ message: '保存成功' });
onRefresh();
};
// 根据企业ID获取取餐点
const getPickSelf = async id => {
const res = await apiSelPickSelfList({ enterpriseId: id });
if (res) {
if (res && res.data && res.data.length) {
setPickSelfList(
res.map(item => ({
key: item.pickSelfId,
res.data.map(item => ({
key: `${item.pickSelfId}`,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res[0].pickSelfId);
const pid = res.data[0].pickSelfId;
setActiveKey(`${pid}`);
if (pageLoaded) {
onRefresh();
}
} else {
setPickSelfList([]);
setActiveKey('');
if (pageLoaded) {
onRefresh();
}
}
};
// 根据企业ID获取取餐点
// const getShops = async () => {
// const res = await getShopList({});
// setShopEnum(res.list);
// };
// 改变企业
const onChangeEnterprise = v => {
setEnterpriseId(v);
......@@ -113,18 +130,14 @@ const TakeawayGoods = () => {
const obj = await getEnterpriseList();
if (obj.list && Object.keys(obj.list).length) {
setEnterprises(obj.list);
setEnterpriseId(obj.id);
getPickSelf(obj.id);
setPageLoading(true);
setEnterpriseId(`${obj.id}`);
await getPickSelf(obj.id);
setPageLoaded(true);
}
};
useEffect(() => {
getList();
// getShops();
// setTimeout(() => {
// // refTable.current.reload();
// }, 1000);
}, []);
const options = {
......@@ -137,12 +150,13 @@ const TakeawayGoods = () => {
enterprises,
onChangeEnterprise,
onChangeFlag,
onRefresh,
shopEnum,
};
return (
<div>
{pageLoading && (
<div className={utilStyle.formPageBox}>
{pageLoaded && (
<ProTable
search={{
span: 6,
......@@ -165,11 +179,12 @@ const TakeawayGoods = () => {
activeKey,
items: pickSelfList,
onChange: key => {
setActiveKey(key);
setActiveKey(`${key}`);
onRefresh();
},
},
actions: [
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={onAdd}>
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={toAdd}>
添加外卖商品
</Button>,
],
......@@ -182,7 +197,7 @@ const TakeawayGoods = () => {
<SaleDateModal
visible={visibleSaleDate}
id={recordID}
handleRefresh={() => searchList({})}
handleRefresh={() => onRefresh()}
handleClose={() => setVisibleSaleDate(false)}
/>
)}
......@@ -191,7 +206,7 @@ const TakeawayGoods = () => {
<SaleSectionModal
visible={visibleSaleSection}
id={recordID}
handleRefresh={() => searchList({})}
handleRefresh={() => onRefresh()}
handleClose={() => setVisibleSaleSection(false)}
/>
)}
......@@ -200,7 +215,7 @@ const TakeawayGoods = () => {
<GoodPriceModal
visible={visiblePrice}
id={recordID}
handleRefresh={() => searchList({})}
handleRefresh={() => onRefresh()}
handleClose={() => setVisiblePrice(false)}
/>
)}
......@@ -209,7 +224,7 @@ const TakeawayGoods = () => {
<GoodSortModal
visible={visibleSort}
id={recordID}
handleRefresh={() => searchList({})}
handleRefresh={() => onRefresh()}
handleClose={() => setVisibleSort(false)}
/>
)}
......
......@@ -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,10 +18,12 @@ 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([]); // 选中的取餐点列表
const [editID, setEditID] = useState(''); // 编辑ID
const [shopId, setShopId] = useState(''); // 店铺ID
// 取消
const onCancel = () => {
......@@ -35,18 +38,21 @@ const TakeawayGoodsInfo = props => {
const skuInfoList = dataSource.map(item => ({
skuId: item.skuId,
enterprisePrice: item.enterprisePrice,
mealTypeList: item.mealType,
mealTypeList: item.mealTypeList.map(m => m.code),
saleDateList: item.saleDate,
tabCateList: item.tabCate.map(t => ({ tabId: t })),
}));
const params = {
shopId: id,
shopId,
enterpriseId: id,
pickSelfIdList: slePickSelf,
skuInfoList,
};
await apiSaveGoodsList(params);
const res = await apiSaveGoodsList(params);
if (res && res.success) {
notification.success({ message: '添加成功' });
onCancel();
}
};
// 删除
......@@ -74,7 +80,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 +121,7 @@ const TakeawayGoodsInfo = props => {
setVisibleSaleSection,
setEditID,
onDel,
setVisiblePrice,
};
return (
......@@ -176,7 +183,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 +216,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
......@@ -216,6 +235,8 @@ const TakeawayGoodsInfo = props => {
enterpriseId={id}
productType={5}
pickSelfIdList={slePickSelf}
shopID={shopId}
onChangeShop={setShopId}
onSelectChange={setDataSource}
handleClose={() => setVisibleSelectGoods(false)}
/>
......
......@@ -3,110 +3,105 @@ import { useHistory } from 'react-router-dom';
import { ProTable } from '@ant-design/pro-components';
import { Button, notification } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { takeawayGoodsColumn } from './staticData/goods';
import { virtualGoodsColumn } from './staticData/goods';
import utilStyle from '@/utils/utils.less';
import { apiVirtualList, apiSelPickSelfList, apiMealInfoDel, apiMealInfoUpdate } from './service';
import { getEnterpriseList } from './service/bll';
import SaleDateModal from './components/SaleDateModal';
import SaleSectionModal from './components/SaleSectionModal';
import GoodPriceModal from './components/GoodPriceModal';
import GoodSortModal from './components/GoodSortModal';
import { apiVirtualList, apiSelPickSelfList, apiMealInfoDel } from './service';
import { getEnterpriseList, getShopList } from './service/bll';
import { getToUrlQuery } from '@/utils/utils';
// 企业虚拟商品
const VirtualGoods = () => {
const history = useHistory();
const refTable = useRef();
const [pageLoading, setPageLoading] = useState(true); // 可售日期弹窗
const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗
const [visibleSaleSection, setVisibleSaleSection] = useState(false); // 可售餐段弹窗
const [visiblePrice, setVisiblePrice] = useState(false); // 修改企业商品价格弹窗
const [visibleSort, setVisibleSort] = useState(false); // 商品排序弹窗
const [enterprises, setEnterprises] = useState([]); // 企业列表
const [pageLoaded, setPageLoaded] = useState(false);
const [enterprises, setEnterprises] = useState({}); // 企业列表
const [activeKey, setActiveKey] = useState('');
const [enterpriseId, setEnterpriseId] = useState('');
const [pickSelfList, setPickSelfList] = useState([]); // 取餐点列表
const [recordID, setRecordID] = useState(''); // 编辑的记录ID
const [enterpriseId, setEnterpriseId] = useState();
// 刷新列表
// const onRefresh = () => {
// if (pageLoaded) {
// refTable.current.reloadAndRest();
// // refTable.current.reload();
// }
// };
// 搜索商品列表
const searchList = async params => {
if (params.enterpriseId && params.enterpriseId !== enterpriseId) {
setEnterpriseId(params.enterpriseId);
const data = {
page: params.current || 1,
size: params.pageSize || 10,
data: Object.assign({}, params, {
enterpriseId,
pickSelfId: activeKey,
}),
};
const res = await apiVirtualList(data);
if (res && res.records) {
return {
data: res.records || [],
total: res.total || 0,
};
}
// const data = {
// page: params.current,
// size: params.pageSize,
// data: params,
// };
// return apiVirtualList(data);
return {
data: [],
total: 0,
};
};
// 删除商品
const onDel = async id => {
await apiMealInfoDel({
id,
});
refTable.current.reload();
notification.success({
message: '删除成功',
});
};
const onAdd = async () => {
const query = getToUrlQuery();
// 跳转添加商品
const toAdd = async () => {
const params = getToUrlQuery();
const query = Object.assign(
{
id: enterpriseId,
name: enterprises[enterpriseId].text,
},
params,
);
history.push({
pathname: '/takeawayGoodsInfo',
query,
});
};
const onChangeFlag = async (id, checked) => {
const params = {
id,
showFlag: checked ? 1 : 0,
};
await apiMealInfoUpdate(params);
notification.success({ message: '保存成功' });
};
const options = {
setVisibleSaleDate,
setVisibleSaleSection,
setVisiblePrice,
setVisibleSort,
onDel,
setRecordID,
enterprises,
onChangeFlag,
};
// 根据企业ID获取取餐点
const getPickSelf = async () => {
const res = await apiSelPickSelfList({});
setPickSelfList(
res.map(item => ({
key: item.pickSelfId,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res[0].pickSelfId);
// 改变企业
const onChangeEnterprise = v => {
setEnterpriseId(v);
};
// 获取企业列表
const getList = async name => {
const obj = await getEnterpriseList(name);
const getList = async () => {
const obj = await getEnterpriseList();
if (obj.list && Object.keys(obj.list).length) {
setEnterprises(obj.list);
setEnterpriseId(obj.id);
getPickSelf(obj.id);
setPageLoading(true);
setEnterpriseId(`${obj.id}`);
setPageLoaded(true);
}
};
useEffect(() => {
getList('');
// setTimeout(() => {
// // refTable.current.reload();
// }, 1000);
getList();
}, []);
const options = {
onDel,
enterprises,
onChangeEnterprise,
};
return (
<div>
{pageLoading && (
<div className={utilStyle.formPageBox}>
{pageLoaded && (
<ProTable
search={{
span: 6,
......@@ -116,7 +111,7 @@ const VirtualGoods = () => {
}}
actionRef={refTable}
tableClassName={utilStyle.formTable}
columns={takeawayGoodsColumn(options)}
columns={virtualGoodsColumn(options)}
request={params => searchList({ ...params })}
rowKey={r => r.id}
expandIconColumnIndex={10}
......@@ -124,59 +119,15 @@ const VirtualGoods = () => {
options={false}
form={{ initialValues: { enterpriseId } }}
toolbar={{
menu: {
type: 'tab',
activeKey,
items: pickSelfList,
onChange: key => {
setActiveKey(key);
},
},
actions: [
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={onAdd}>
添加外卖商品
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={toAdd}>
添加虚拟商品
</Button>,
],
}}
scroll={{ x: '100%', y: 400 }}
/>
)}
{/* 可售日期弹窗 */}
{visibleSaleDate && (
<SaleDateModal
visible={visibleSaleDate}
id={recordID}
handleRefresh={() => searchList({})}
handleClose={() => setVisibleSaleDate(false)}
/>
)}
{/* 可售餐段弹窗 */}
{visibleSaleSection && (
<SaleSectionModal
visible={visibleSaleSection}
id={recordID}
handleRefresh={() => searchList({})}
handleClose={() => setVisibleSaleSection(false)}
/>
)}
{/* 修改企业商品价格弹窗 */}
{visiblePrice && (
<GoodPriceModal
visible={visiblePrice}
id={recordID}
handleRefresh={() => searchList({})}
handleClose={() => setVisiblePrice(false)}
/>
)}
{/* 商品排序弹窗 */}
{visibleSort && (
<GoodSortModal
visible={visibleSort}
id={recordID}
handleRefresh={() => searchList({})}
handleClose={() => setVisibleSort(false)}
/>
)}
</div>
);
};
......
......@@ -11,7 +11,7 @@ import { apiSaveVirtualGoodsList, apiShopListByEnterpriseID } from './service';
import style from './style/index.less';
const VirtualGoodsInfo = props => {
const { id } = props.location.query;
const { id, name } = props.location.query;
const history = useHistory();
const [loading, setLoading] = useState(false);
const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗
......@@ -35,22 +35,25 @@ const VirtualGoodsInfo = props => {
const skuInfoList = dataSource.map(item => ({
skuId: item.skuId,
enterprisePrice: item.enterprisePrice,
mealTypeList: item.mealType,
mealTypeList: item.mealTypeList.map(m => m.code),
saleDateList: item.saleDate,
tabCateList: item.tabCate.map(t => ({ tabId: t })),
}));
const params = {
shopId: sleShopID,
enterpriseId: id,
skuInfoList,
};
await apiSaveVirtualGoodsList(params);
const res = await apiSaveVirtualGoodsList(params);
if (res && res.success) {
notification.success({ message: '添加成功' });
onCancel();
}
};
// 删除
const onDel = i => {
const arr = dataSource.splice(i, 1);
const arr = [...dataSource];
arr.splice(i, 1);
setDataSource(arr);
};
......@@ -59,12 +62,14 @@ const VirtualGoodsInfo = props => {
const res = await apiShopListByEnterpriseID({
enterpriseId: id,
});
if (res && res.data) {
setShopList(
res.map(item => ({
key: item.id,
label: <span>{item.name}</span>,
res.data.map(item => ({
value: item.id,
label: item.name,
})),
);
}
};
// 刷新列表数据
......@@ -104,7 +109,7 @@ const VirtualGoodsInfo = props => {
<Col span={3} className={style['info-box--label']}>
企业名称:
</Col>
<Col span={20}>企业名称111</Col>
<Col span={20}>{name}</Col>
</Row>
<Row className={style['info-box--line']}>
<Col span={3} className={style['info-box--label']}>
......@@ -116,6 +121,7 @@ const VirtualGoodsInfo = props => {
options={shopList}
className={style['info-box--select']}
placeholder="清选择"
value={sleShopID}
onChange={setSelShopID}
filterOption={(input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
......@@ -135,24 +141,6 @@ const VirtualGoodsInfo = props => {
</Row>
<Row className={style['info-box--line']}>
<Col span={24}>
<div className={style['info-box--batch-btn']}>
<Button
onClick={() => {
setEditID('');
setVisibleSaleDate(true);
}}
>
批量配置日期
</Button>
<Button
onClick={() => {
setEditID('');
setVisibleSaleSection(true);
}}
>
批量配置餐段
</Button>
</div>
<Table columns={GoodsInfoColumn(options)} dataSource={dataSource} />
</Col>
</Row>
......@@ -191,6 +179,9 @@ const VirtualGoodsInfo = props => {
<SelectGoodsModal
visible={visibleSelectGoods}
type="virtual"
enterpriseId={id}
productType={2}
shopID={sleShopID}
onSelectChange={setDataSource}
handleClose={() => setVisibleSelectGoods(false)}
/>
......
......@@ -183,7 +183,7 @@ export const getErrorMessage = err => {
// 获取地址栏参数,name:参数名称
export const getUrlParams = name => {
const regArg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
const r = window.location.search.substr(1).match(regArg);
const r = window.location.search.substring(1).match(regArg);
if (r != null) return decodeURIComponent(r[2]);
return null;
};
......
......@@ -59,3 +59,7 @@
.formTable {
padding: 0;
}
.formPageBox {
box-sizing: border-box;
padding: 20px;
}
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