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

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

parent 81e54fd6
......@@ -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 => {
......
......@@ -72,11 +72,13 @@ export const takeawayGoodsColumn = options => {
title: '微店名称',
dataIndex: 'shopId',
hideInTable: true,
// fieldProps: {
// showSearch: true,
// },
fieldProps: {
showSearch: true,
filterOption: false,
onSearch: getShopList,
},
// request: getShopList,
// valueEnum: {}, // shopEnum,
valueEnum: {}, // shopEnum,
},
{
title: 'SKU编码',
......@@ -413,3 +415,131 @@ 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: '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 = () => {
});
};
// 跳转添加商品
const onAdd = async () => {
const toAdd = async () => {
const params = getToUrlQuery();
const query = Object.assign(
{
......@@ -184,7 +184,7 @@ const TakeawayGoods = () => {
},
},
actions: [
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={onAdd}>
<Button key="1" icon={<PlusOutlined />} type="primary" onClick={toAdd}>
添加外卖商品
</Button>,
],
......
......@@ -235,6 +235,7 @@ const TakeawayGoodsInfo = props => {
enterpriseId={id}
productType={5}
pickSelfIdList={slePickSelf}
shopID={shopId}
onChangeShop={setShopId}
onSelectChange={setDataSource}
handleClose={() => setVisibleSelectGoods(false)}
......
......@@ -3,112 +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({});
if (res && res.data) {
setPickSelfList(
res.data.map(item => ({
key: item.pickSelfId,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res.data[0].pickSelfId);
}
// 改变企业
const onChangeEnterprise = v => {
setEnterpriseId(v);
};
// 获取企业列表
const getList = async name => {
const obj = await getEnterpriseList(name);
setEnterprises(obj.list);
setEnterpriseId(obj.id);
getPickSelf(obj.id);
setPageLoading(true);
const getList = async () => {
const obj = await getEnterpriseList();
if (obj.list && Object.keys(obj.list).length) {
setEnterprises(obj.list);
setEnterpriseId(`${obj.id}`);
setPageLoaded(true);
}
};
useEffect(() => {
getList('');
// setTimeout(() => {
// // refTable.current.reload();
// }, 1000);
getList();
}, []);
const options = {
onDel,
enterprises,
onChangeEnterprise,
};
return (
<div className={utilStyle.formPageBox}>
{pageLoading && (
{pageLoaded && (
<ProTable
search={{
span: 6,
......@@ -118,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}
......@@ -126,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);
notification.success({ message: '添加成功' });
onCancel();
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);
};
......@@ -62,7 +65,7 @@ const VirtualGoodsInfo = props => {
if (res && res.data) {
setShopList(
res.data.map(item => ({
key: item.id,
value: item.id,
label: item.name,
})),
);
......@@ -106,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']}>
......@@ -118,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())
......@@ -137,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>
......@@ -193,6 +179,9 @@ const VirtualGoodsInfo = props => {
<SelectGoodsModal
visible={visibleSelectGoods}
type="virtual"
enterpriseId={id}
productType={2}
shopID={sleShopID}
onSelectChange={setDataSource}
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