Commit 81e54fd6 authored by 武广's avatar 武广

fix: 修改外卖商品列表

parent f1e3c41b
......@@ -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;
};
......
......@@ -104,6 +104,7 @@ const SaleDateModal = props => {
shopName,
}));
props.onSelectChange(arr);
props.onChangeShop(shopId);
handleCancel();
};
......
......@@ -46,7 +46,6 @@ export const weekOptions = {
export const takeawayGoodsColumn = options => {
const {
onDel,
companyEnum,
shopEnum,
onChangeFlag,
setVisibleSaleDate,
......@@ -73,28 +72,27 @@ export const takeawayGoodsColumn = options => {
title: '微店名称',
dataIndex: 'shopId',
hideInTable: true,
fieldProps: {
showSearch: true,
},
// fieldProps: {
// showSearch: true,
// },
// request: getShopList,
// 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',
......@@ -121,13 +119,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);
......@@ -142,7 +140,7 @@ export const takeawayGoodsColumn = options => {
{
title: '企业价格',
dataIndex: 'activityPrice',
width: 120,
width: 100,
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -162,14 +160,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: {
......@@ -181,7 +179,7 @@ export const takeawayGoodsColumn = options => {
{
title: '排序',
dataIndex: 'sort',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -201,7 +199,7 @@ export const takeawayGoodsColumn = options => {
{
title: '列出商品',
dataIndex: 'showFlag',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
render: (_, record) => (
......@@ -215,7 +213,7 @@ export const takeawayGoodsColumn = options => {
{
title: '餐品类型',
dataIndex: 'mealType',
width: 120,
width: 80,
align: 'center',
hideInSearch: true,
},
......@@ -225,6 +223,9 @@ export const takeawayGoodsColumn = options => {
width: 120,
valueType: 'dateRange',
align: 'center',
render(v, record) {
return record.createDate;
},
},
{
title: '当日餐段',
......@@ -347,7 +348,7 @@ export const GoodsInfoColumn = options => {
hideInSearch: true,
render(arr) {
if (arr && arr.length) {
return arr.map(item => mealType[item]).join('/');
return arr.map(item => item.name).join('/');
}
return '-';
},
......
......@@ -17,47 +17,59 @@ 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(
{
enterpriseId,
},
params,
),
page: params.current || 1,
size: params.pageSize || 10,
data: Object.assign({}, params, {
enterpriseId,
pickSelfId: activeKey,
}),
};
const res = await apiTakeawayList(data);
if (res && res.records) {
return {
data: res.records || [],
total: res.total || 0,
};
}
return {
data: res.records,
total: res.total,
data: [],
total: 0,
};
};
// 删除商品
const onDel = async id => {
await apiMealInfoDel({
id,
});
refTable.current.reload();
notification.success({
message: '删除成功',
});
};
// 跳转添加商品
const onAdd = 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 && res.data) {
if (res && res.data && res.data.length) {
setPickSelfList(
res.data.map(item => ({
key: item.pickSelfId,
key: `${item.pickSelfId}`,
label: <span>{item.pickSelfName}</span>,
})),
);
setActiveKey(res.data[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,7 +179,8 @@ const TakeawayGoods = () => {
activeKey,
items: pickSelfList,
onChange: key => {
setActiveKey(key);
setActiveKey(`${key}`);
onRefresh();
},
},
actions: [
......@@ -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)}
/>
)}
......
......@@ -23,6 +23,7 @@ const TakeawayGoodsInfo = props => {
const [pickSelfList, setPickSelfList] = useState([]); // 取餐点列表
const [slePickSelf, setSelPickSelf] = useState([]); // 选中的取餐点列表
const [editID, setEditID] = useState(''); // 编辑ID
const [shopId, setShopId] = useState(''); // 店铺ID
// 取消
const onCancel = () => {
......@@ -37,12 +38,12 @@ 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: { tabId: item.tabCate },
tabCateList: item.tabCate.map(t => ({ tabId: t })),
}));
const params = {
shopId: id,
shopId,
enterpriseId: id,
pickSelfIdList: slePickSelf,
skuInfoList,
......@@ -234,6 +235,7 @@ const TakeawayGoodsInfo = props => {
enterpriseId={id}
productType={5}
pickSelfIdList={slePickSelf}
onChangeShop={setShopId}
onSelectChange={setDataSource}
handleClose={() => setVisibleSelectGoods(false)}
/>
......
......@@ -107,7 +107,7 @@ const VirtualGoods = () => {
}, []);
return (
<div>
<div className={utilStyle.formPageBox}>
{pageLoading && (
<ProTable
search={{
......
......@@ -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