Commit f8c96d7c authored by 武广's avatar 武广

fix: 修改虚拟商品回显的问题

parent a7bdf2f4
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Form, Checkbox, Space, Modal, notification, message } from 'antd'; import { Checkbox, Space, Modal, notification, message } from 'antd';
import { mealColumn } from '../staticData/goods'; import { mealColumn } from '../staticData/goods';
import { apiMealInfoUpdate } from '../service'; import { apiMealInfoUpdate } from '../service';
const SaleDateModal = props => { const SaleDateModal = props => {
const [form] = Form.useForm();
const [value, setValue] = useState([]); const [value, setValue] = useState([]);
// 关闭弹窗 // 关闭弹窗
...@@ -54,7 +53,9 @@ const SaleDateModal = props => { ...@@ -54,7 +53,9 @@ const SaleDateModal = props => {
<Checkbox.Group onChange={onChangeMeal} value={value}> <Checkbox.Group onChange={onChangeMeal} value={value}>
<Space direction="vertical"> <Space direction="vertical">
{Object.keys(mealColumn).map(key => ( {Object.keys(mealColumn).map(key => (
<Checkbox value={key}>{mealColumn[key]}</Checkbox> <Checkbox key={key} value={key}>
{mealColumn[key]}
</Checkbox>
))} ))}
</Space> </Space>
</Checkbox.Group> </Checkbox.Group>
......
...@@ -11,7 +11,6 @@ const { Option } = Select; ...@@ -11,7 +11,6 @@ const { Option } = Select;
const SaleDateModal = props => { const SaleDateModal = props => {
const [searchType, setSearchType] = useState('1'); const [searchType, setSearchType] = useState('1');
const [searchKeyword, setSearchKeyword] = useState(''); const [searchKeyword, setSearchKeyword] = useState('');
// const [goodsType, setGoodsType] = useState('1');
const [shopId, setShopId] = useState(props.shopID); const [shopId, setShopId] = useState(props.shopID);
const [shopName, setShopName] = useState(''); const [shopName, setShopName] = useState('');
const [searchName, setSearchName] = useState(''); const [searchName, setSearchName] = useState('');
...@@ -21,8 +20,8 @@ const SaleDateModal = props => { ...@@ -21,8 +20,8 @@ const SaleDateModal = props => {
const [total, setTotal] = useState(0); const [total, setTotal] = useState(0);
const [dataSource, setDataSource] = useState([]); const [dataSource, setDataSource] = useState([]);
const [shopList, setShopList] = useState([]); const [shopList, setShopList] = useState([]);
const [selectedRowKeys, setSelectedRowKeys] = useState([]); const [selectedRowKeys, setSelectedRowKeys] = useState(props.selectedRowKeys || []);
const [selectedRows, setSelectedRows] = useState([]); const [selectedRows, setSelectedRows] = useState(props.selectedRows || []);
const searchList = async params => { const searchList = async params => {
console.log('params :>> ', params); console.log('params :>> ', params);
...@@ -58,6 +57,9 @@ const SaleDateModal = props => { ...@@ -58,6 +57,9 @@ const SaleDateModal = props => {
const res = await api(data); const res = await api(data);
console.log('res :>> ', res); console.log('res :>> ', res);
if (res && res.data && res.data.records) { if (res && res.data && res.data.records) {
res.data.records.forEach(item => {
item.enterprisePrice = item.salePrice;
});
setDataSource(res.data.records); setDataSource(res.data.records);
setTotal(res.data.total); setTotal(res.data.total);
} }
...@@ -110,6 +112,9 @@ const SaleDateModal = props => { ...@@ -110,6 +112,9 @@ const SaleDateModal = props => {
if (!props.shopID) { if (!props.shopID) {
props.onChangeShop(shopId); props.onChangeShop(shopId);
} }
if (props.onSelectedRowKeys) {
props.onSelectedRowKeys(selectedRowKeys);
}
handleCancel(); handleCancel();
}; };
...@@ -212,7 +217,7 @@ const SaleDateModal = props => { ...@@ -212,7 +217,7 @@ const SaleDateModal = props => {
<Pagination defaultCurrent={1} total={total} showQuickJumper onChange={onPageChange} /> <Pagination defaultCurrent={1} total={total} showQuickJumper onChange={onPageChange} />
<div className={style['footers-btn']}> <div className={style['footers-btn']}>
<div className={style['footers-desc']}> <div className={style['footers-desc']}>
已选商品(<span className={style['footers-num']}>{selectedRows.length}</span>) 已选商品(<span className={style['footers-num']}>{selectedRowKeys.length}</span>)
</div> </div>
<Button key="back" onClick={handleCancel}> <Button key="back" onClick={handleCancel}>
取消 取消
......
...@@ -304,6 +304,9 @@ export const GoodsInfoColumn = options => { ...@@ -304,6 +304,9 @@ export const GoodsInfoColumn = options => {
if (arr && arr.length) { if (arr && arr.length) {
return arr[0].stock; return arr[0].stock;
} }
if (![null, undefined].includes(v)) {
return v;
}
return '-'; return '-';
}, },
}, },
......
...@@ -41,7 +41,7 @@ const TakeawayGoodsInfo = props => { ...@@ -41,7 +41,7 @@ const TakeawayGoodsInfo = props => {
if (!item.mealTypeList || item.mealTypeList.length < 1) { if (!item.mealTypeList || item.mealTypeList.length < 1) {
throw Error('请添加餐品类型!'); throw Error('请添加餐品类型!');
} }
if (!item.enterprisePrice || item.enterprisePrice.length < 1) { if (!item.enterprisePrice || `${item.enterprisePrice}`.length < 1) {
throw Error('请添加企业价格!'); throw Error('请添加企业价格!');
} }
if (!item.saleDate || item.saleDate.length < 1) { if (!item.saleDate || item.saleDate.length < 1) {
......
...@@ -8,7 +8,7 @@ import SaleDateModal from './components/SaleDateModal'; ...@@ -8,7 +8,7 @@ import SaleDateModal from './components/SaleDateModal';
import GoodPriceModal from './components/GoodPriceModal'; import GoodPriceModal from './components/GoodPriceModal';
import SaleSectionModal from './components/SaleSectionModal'; import SaleSectionModal from './components/SaleSectionModal';
import SelectGoodsModal from './components/SelectGoodsModal'; import SelectGoodsModal from './components/SelectGoodsModal';
import { apiSaveVirtualGoodsList, apiShopListByEnterpriseID } from './service'; import { apiSaveVirtualGoodsList, apiShopListByEnterpriseID, apiVirtualList } from './service';
import style from './style/index.less'; import style from './style/index.less';
...@@ -24,6 +24,7 @@ const VirtualGoodsInfo = props => { ...@@ -24,6 +24,7 @@ const VirtualGoodsInfo = props => {
const [shopList, setShopList] = useState({}); // 店铺列表 const [shopList, setShopList] = useState({}); // 店铺列表
const [sleShopID, setSelShopID] = useState(''); // 选中的店铺ID const [sleShopID, setSelShopID] = useState(''); // 选中的店铺ID
const [sleShopName, setSelShopName] = useState(''); // 选中的店铺名称 const [sleShopName, setSelShopName] = useState(''); // 选中的店铺名称
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const [editID, setEditID] = useState(''); // 编辑ID const [editID, setEditID] = useState(''); // 编辑ID
// 取消 // 取消
...@@ -52,7 +53,7 @@ const VirtualGoodsInfo = props => { ...@@ -52,7 +53,7 @@ const VirtualGoodsInfo = props => {
if (!item.mealTypeList || item.mealTypeList.length < 1) { if (!item.mealTypeList || item.mealTypeList.length < 1) {
throw Error('请添加餐品类型!'); throw Error('请添加餐品类型!');
} }
if (!item.enterprisePrice || item.enterprisePrice.length < 1) { if (!item.enterprisePrice || `${item.enterprisePrice}`.length < 1) {
throw Error('请添加企业价格!'); throw Error('请添加企业价格!');
} }
if (!item.saleDate || item.saleDate.length < 1) { if (!item.saleDate || item.saleDate.length < 1) {
...@@ -107,10 +108,38 @@ const VirtualGoodsInfo = props => { ...@@ -107,10 +108,38 @@ const VirtualGoodsInfo = props => {
} }
}; };
// 查询已选商品列表
const getGoodsList = async shopId => {
const data = {
page: 1,
size: 1000,
data: {
enterpriseId: id,
shopId,
},
};
const res = await apiVirtualList(data);
if (res && res.data && res.data.records && res.data.records.length) {
const keys = [];
setDataSource(
res.data.records.map(item => {
item.saleDate = item.saleDateList.map(d => d.code);
item.tabCate = item.tabCateList.map(c => c.tabId);
item.enterprisePrice = item.activityPrice;
item.salePrice = item.price;
keys.push(item.skuId);
return item;
}),
);
setSelectedRowKeys(keys);
}
};
// 选中店铺 // 选中店铺
const onSelectShop = sid => { const onSelectShop = sid => {
setSelShopID(sid); setSelShopID(sid);
setSelShopName(shopList[sid]); setSelShopName(shopList[sid]);
getGoodsList(sid);
}; };
// 刷新列表数据 // 刷新列表数据
...@@ -128,9 +157,6 @@ const VirtualGoodsInfo = props => { ...@@ -128,9 +157,6 @@ const VirtualGoodsInfo = props => {
setDataSource(arr); setDataSource(arr);
}; };
// const initData = async () => {
// setLoading(true);
// };
useEffect(() => { useEffect(() => {
getShopList(); getShopList();
}, []); }, []);
...@@ -233,7 +259,10 @@ const VirtualGoodsInfo = props => { ...@@ -233,7 +259,10 @@ const VirtualGoodsInfo = props => {
productType={4} productType={4}
shopID={sleShopID} shopID={sleShopID}
shopName={sleShopName} shopName={sleShopName}
selectedRowKeys={selectedRowKeys}
selectedRows={dataSource}
onSelectChange={setDataSource} onSelectChange={setDataSource}
onSelectedRowKeys={setSelectedRowKeys}
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