Commit 6dc8ec9b authored by 武广's avatar 武广

fix: 修改虚拟商品列表逻辑

parent 81e54fd6
...@@ -25,23 +25,21 @@ export const getEnterpriseList = async () => { ...@@ -25,23 +25,21 @@ export const getEnterpriseList = async () => {
}; };
// 获取店铺列表 // 获取店铺列表
export const getShopList = debounce(async e => { export const getShopList = debounce(async e => {
const { name } = e; const res = await apiShopList({ name: e });
const res = await apiShopList({ name });
if (res && res.data && res.data.records) { if (res && res.data && res.data.records) {
const data = res.data.records; const data = res.data.records;
const json = {}; // const json = {};
data.forEach(item => { // data.forEach(item => {
json[item.id] = { text: item.name }; // json[item.id] = { text: item.name };
}); // });
return { // return json;
id: res[res.length - 1].id, return data.map(item => ({
list: json, value: item.id,
}; text: item.name,
}));
} }
return { // return {};
id: '', return [];
list: {},
};
}, 300); }, 300);
// 获取店铺列表通过自提点ID // 获取店铺列表通过自提点ID
export const getShopListByPickSelf = async e => { export const getShopListByPickSelf = async e => {
......
...@@ -72,11 +72,13 @@ export const takeawayGoodsColumn = options => { ...@@ -72,11 +72,13 @@ export const takeawayGoodsColumn = options => {
title: '微店名称', title: '微店名称',
dataIndex: 'shopId', dataIndex: 'shopId',
hideInTable: true, hideInTable: true,
// fieldProps: { fieldProps: {
// showSearch: true, showSearch: true,
// }, filterOption: false,
onSearch: getShopList,
},
// request: getShopList, // request: getShopList,
// valueEnum: {}, // shopEnum, valueEnum: {}, // shopEnum,
}, },
{ {
title: 'SKU编码', title: 'SKU编码',
...@@ -413,3 +415,131 @@ export const SelectGoodsColumn = [ ...@@ -413,3 +415,131 @@ export const SelectGoodsColumn = [
hideInSearch: true, 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: 'saleTimeType',
width: 120,
align: 'center',
hideInSearch: true,
render: (_, record) => <span>{_}</span>,
},
{
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>
),
},
];
};
...@@ -70,7 +70,7 @@ const TakeawayGoods = () => { ...@@ -70,7 +70,7 @@ const TakeawayGoods = () => {
}); });
}; };
// 跳转添加商品 // 跳转添加商品
const onAdd = async () => { const toAdd = async () => {
const params = getToUrlQuery(); const params = getToUrlQuery();
const query = Object.assign( const query = Object.assign(
{ {
...@@ -184,7 +184,7 @@ const TakeawayGoods = () => { ...@@ -184,7 +184,7 @@ const TakeawayGoods = () => {
}, },
}, },
actions: [ actions: [
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={onAdd}> <Button key="1" icon={<PlusOutlined />} type="primary" onClick={toAdd}>
添加外卖商品 添加外卖商品
</Button>, </Button>,
], ],
......
...@@ -235,6 +235,7 @@ const TakeawayGoodsInfo = props => { ...@@ -235,6 +235,7 @@ const TakeawayGoodsInfo = props => {
enterpriseId={id} enterpriseId={id}
productType={5} productType={5}
pickSelfIdList={slePickSelf} pickSelfIdList={slePickSelf}
shopID={shopId}
onChangeShop={setShopId} onChangeShop={setShopId}
onSelectChange={setDataSource} onSelectChange={setDataSource}
handleClose={() => setVisibleSelectGoods(false)} handleClose={() => setVisibleSelectGoods(false)}
......
...@@ -3,112 +3,105 @@ import { useHistory } from 'react-router-dom'; ...@@ -3,112 +3,105 @@ import { useHistory } from 'react-router-dom';
import { ProTable } from '@ant-design/pro-components'; import { ProTable } from '@ant-design/pro-components';
import { Button, notification } from 'antd'; import { Button, notification } from 'antd';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import { takeawayGoodsColumn } from './staticData/goods'; import { virtualGoodsColumn } from './staticData/goods';
import utilStyle from '@/utils/utils.less'; import utilStyle from '@/utils/utils.less';
import { apiVirtualList, apiSelPickSelfList, apiMealInfoDel, apiMealInfoUpdate } from './service'; import { apiVirtualList, apiSelPickSelfList, apiMealInfoDel } from './service';
import { getEnterpriseList } from './service/bll'; import { getEnterpriseList, getShopList } from './service/bll';
import SaleDateModal from './components/SaleDateModal';
import SaleSectionModal from './components/SaleSectionModal';
import GoodPriceModal from './components/GoodPriceModal';
import GoodSortModal from './components/GoodSortModal';
import { getToUrlQuery } from '@/utils/utils'; import { getToUrlQuery } from '@/utils/utils';
// 企业虚拟商品 // 企业虚拟商品
const VirtualGoods = () => { const VirtualGoods = () => {
const history = useHistory(); const history = useHistory();
const refTable = useRef(); const refTable = useRef();
const [pageLoading, setPageLoading] = useState(true); // 可售日期弹窗 const [pageLoaded, setPageLoaded] = useState(false);
const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗 const [enterprises, setEnterprises] = useState({}); // 企业列表
const [visibleSaleSection, setVisibleSaleSection] = useState(false); // 可售餐段弹窗
const [visiblePrice, setVisiblePrice] = useState(false); // 修改企业商品价格弹窗
const [visibleSort, setVisibleSort] = useState(false); // 商品排序弹窗
const [enterprises, setEnterprises] = useState([]); // 企业列表
const [activeKey, setActiveKey] = useState(''); const [activeKey, setActiveKey] = useState('');
const [enterpriseId, setEnterpriseId] = useState(''); 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 => { const searchList = async params => {
if (params.enterpriseId && params.enterpriseId !== enterpriseId) { const data = {
setEnterpriseId(params.enterpriseId); 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 = { return {
// page: params.current, data: [],
// size: params.pageSize, total: 0,
// data: params, };
// };
// return apiVirtualList(data);
}; };
// 删除商品
const onDel = async id => { const onDel = async id => {
await apiMealInfoDel({ await apiMealInfoDel({
id, id,
}); });
refTable.current.reload();
notification.success({ notification.success({
message: '删除成功', 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({ history.push({
pathname: '/takeawayGoodsInfo', pathname: '/takeawayGoodsInfo',
query, query,
}); });
}; };
const onChangeFlag = async (id, checked) => { // 改变企业
const params = { const onChangeEnterprise = v => {
id, setEnterpriseId(v);
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({});
if (res && res.data) {
setPickSelfList(
res.data.map(item => ({
key: item.pickSelfId,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res.data[0].pickSelfId);
}
}; };
// 获取企业列表 // 获取企业列表
const getList = async name => { const getList = async () => {
const obj = await getEnterpriseList(name); const obj = await getEnterpriseList();
setEnterprises(obj.list); if (obj.list && Object.keys(obj.list).length) {
setEnterpriseId(obj.id); setEnterprises(obj.list);
getPickSelf(obj.id); setEnterpriseId(`${obj.id}`);
setPageLoading(true); setPageLoaded(true);
}
}; };
useEffect(() => { useEffect(() => {
getList(''); getList();
// setTimeout(() => {
// // refTable.current.reload();
// }, 1000);
}, []); }, []);
const options = {
onDel,
enterprises,
onChangeEnterprise,
};
return ( return (
<div className={utilStyle.formPageBox}> <div className={utilStyle.formPageBox}>
{pageLoading && ( {pageLoaded && (
<ProTable <ProTable
search={{ search={{
span: 6, span: 6,
...@@ -118,7 +111,7 @@ const VirtualGoods = () => { ...@@ -118,7 +111,7 @@ const VirtualGoods = () => {
}} }}
actionRef={refTable} actionRef={refTable}
tableClassName={utilStyle.formTable} tableClassName={utilStyle.formTable}
columns={takeawayGoodsColumn(options)} columns={virtualGoodsColumn(options)}
request={params => searchList({ ...params })} request={params => searchList({ ...params })}
rowKey={r => r.id} rowKey={r => r.id}
expandIconColumnIndex={10} expandIconColumnIndex={10}
...@@ -126,59 +119,15 @@ const VirtualGoods = () => { ...@@ -126,59 +119,15 @@ const VirtualGoods = () => {
options={false} options={false}
form={{ initialValues: { enterpriseId } }} form={{ initialValues: { enterpriseId } }}
toolbar={{ toolbar={{
menu: {
type: 'tab',
activeKey,
items: pickSelfList,
onChange: key => {
setActiveKey(key);
},
},
actions: [ actions: [
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={onAdd}> <Button key="1" icon={<PlusOutlined />} type="primary" onClick={toAdd}>
添加外卖商品 添加虚拟商品
</Button>, </Button>,
], ],
}} }}
scroll={{ x: '100%', y: 400 }} 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> </div>
); );
}; };
......
...@@ -11,7 +11,7 @@ import { apiSaveVirtualGoodsList, apiShopListByEnterpriseID } from './service'; ...@@ -11,7 +11,7 @@ import { apiSaveVirtualGoodsList, apiShopListByEnterpriseID } from './service';
import style from './style/index.less'; import style from './style/index.less';
const VirtualGoodsInfo = props => { const VirtualGoodsInfo = props => {
const { id } = props.location.query; const { id, name } = props.location.query;
const history = useHistory(); const history = useHistory();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗 const [visibleSaleDate, setVisibleSaleDate] = useState(false); // 可售日期弹窗
...@@ -35,22 +35,25 @@ const VirtualGoodsInfo = props => { ...@@ -35,22 +35,25 @@ const VirtualGoodsInfo = props => {
const skuInfoList = dataSource.map(item => ({ const skuInfoList = dataSource.map(item => ({
skuId: item.skuId, skuId: item.skuId,
enterprisePrice: item.enterprisePrice, enterprisePrice: item.enterprisePrice,
mealTypeList: item.mealType, mealTypeList: item.mealTypeList.map(m => m.code),
saleDateList: item.saleDate, saleDateList: item.saleDate,
tabCateList: item.tabCate.map(t => ({ tabId: t })),
})); }));
const params = { const params = {
shopId: sleShopID,
enterpriseId: id, enterpriseId: id,
skuInfoList, skuInfoList,
}; };
await apiSaveVirtualGoodsList(params); const res = await apiSaveVirtualGoodsList(params);
notification.success({ message: '添加成功' }); if (res && res.success) {
onCancel(); notification.success({ message: '添加成功' });
onCancel();
}
}; };
// 删除 // 删除
const onDel = i => { const onDel = i => {
const arr = dataSource.splice(i, 1); const arr = [...dataSource];
arr.splice(i, 1);
setDataSource(arr); setDataSource(arr);
}; };
...@@ -62,7 +65,7 @@ const VirtualGoodsInfo = props => { ...@@ -62,7 +65,7 @@ const VirtualGoodsInfo = props => {
if (res && res.data) { if (res && res.data) {
setShopList( setShopList(
res.data.map(item => ({ res.data.map(item => ({
key: item.id, value: item.id,
label: item.name, label: item.name,
})), })),
); );
...@@ -106,7 +109,7 @@ const VirtualGoodsInfo = props => { ...@@ -106,7 +109,7 @@ const VirtualGoodsInfo = props => {
<Col span={3} className={style['info-box--label']}> <Col span={3} className={style['info-box--label']}>
企业名称: 企业名称:
</Col> </Col>
<Col span={20}>企业名称111</Col> <Col span={20}>{name}</Col>
</Row> </Row>
<Row className={style['info-box--line']}> <Row className={style['info-box--line']}>
<Col span={3} className={style['info-box--label']}> <Col span={3} className={style['info-box--label']}>
...@@ -118,6 +121,7 @@ const VirtualGoodsInfo = props => { ...@@ -118,6 +121,7 @@ const VirtualGoodsInfo = props => {
options={shopList} options={shopList}
className={style['info-box--select']} className={style['info-box--select']}
placeholder="清选择" placeholder="清选择"
value={sleShopID}
onChange={setSelShopID} onChange={setSelShopID}
filterOption={(input, option) => filterOption={(input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()) (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
...@@ -137,24 +141,6 @@ const VirtualGoodsInfo = props => { ...@@ -137,24 +141,6 @@ const VirtualGoodsInfo = props => {
</Row> </Row>
<Row className={style['info-box--line']}> <Row className={style['info-box--line']}>
<Col span={24}> <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} /> <Table columns={GoodsInfoColumn(options)} dataSource={dataSource} />
</Col> </Col>
</Row> </Row>
...@@ -193,6 +179,9 @@ const VirtualGoodsInfo = props => { ...@@ -193,6 +179,9 @@ const VirtualGoodsInfo = props => {
<SelectGoodsModal <SelectGoodsModal
visible={visibleSelectGoods} visible={visibleSelectGoods}
type="virtual" type="virtual"
enterpriseId={id}
productType={2}
shopID={sleShopID}
onSelectChange={setDataSource} onSelectChange={setDataSource}
handleClose={() => setVisibleSelectGoods(false)} handleClose={() => setVisibleSelectGoods(false)}
/> />
......
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