Commit e64c6bba authored by 陈万宝's avatar 陈万宝

Merge branch 'feature/20230315_take_out_goods' into feature/20230327_public_takeaway

parents 6fec3ca3 5470e60a
...@@ -78,7 +78,7 @@ class goodsManage extends Component { ...@@ -78,7 +78,7 @@ class goodsManage extends Component {
componentDidMount() { componentDidMount() {
this.props.goodsManage.tableData = {}; this.props.goodsManage.tableData = {};
this.categoryList(); this.categoryList(this.state.productType);
this.categoryListByType(this.state.productType); this.categoryListByType(this.state.productType);
this.getVirtualCategory(); this.getVirtualCategory();
this.specList(); this.specList();
......
...@@ -245,6 +245,15 @@ ...@@ -245,6 +245,15 @@
.specsBetween { .specsBetween {
display: flex; display: flex;
flex-flow: row nowrap; flex-flow: row nowrap;
:global {
.ant-form-item-label{
overflow:inherit;
}
.ant-col-sm-3{
max-width: fit-content;
}
}
} }
.specRepertory { .specRepertory {
background-color: #319bfe; background-color: #319bfe;
......
...@@ -12,7 +12,7 @@ import { ServiceContext } from '../context'; ...@@ -12,7 +12,7 @@ import { ServiceContext } from '../context';
import { debounce } from '@/utils/utils'; import { debounce } from '@/utils/utils';
import AddMenusModal from './AddMenusModal'; import AddMenusModal from './AddMenusModal';
import UploadImage from './UploadImage'; import UploadImage from './UploadImage';
import { apiShopIds, apiQueryShopList } from '../service'; import { apiShopIds, apiQueryShopList, getByProductType } from '../service';
const CreateSelectOption = optionList => const CreateSelectOption = optionList =>
optionList.map(brandItem => ( optionList.map(brandItem => (
...@@ -22,7 +22,6 @@ const CreateSelectOption = optionList => ...@@ -22,7 +22,6 @@ const CreateSelectOption = optionList =>
)); ));
const fileterBrandOptions = (input, options) => options.children.includes(input); const fileterBrandOptions = (input, options) => options.children.includes(input);
const filterCategoryOptions = (inputValue, path) => const filterCategoryOptions = (inputValue, path) =>
path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1); path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
...@@ -35,6 +34,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -35,6 +34,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
brandList, brandList,
afterAddressList, afterAddressList,
specListData, specListData,
shopGetByProductType,
} = props; } = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [noreBrandList, setNoreBrandList] = useState([]); const [noreBrandList, setNoreBrandList] = useState([]);
...@@ -43,6 +43,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -43,6 +43,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
const [takeawayImageList, setTakeawayImageList] = useState([]); const [takeawayImageList, setTakeawayImageList] = useState([]);
const [shopIds, setShopIds] = useState([]); const [shopIds, setShopIds] = useState([]);
const [shopList, setShopList] = useState([]); const [shopList, setShopList] = useState([]);
const [isEditTakeaway, setIsEditTakeaway] = useState(false);
const onCheck = async () => { const onCheck = async () => {
try { try {
...@@ -66,6 +67,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -66,6 +67,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
return null; return null;
} }
}; };
// 自定义加入菜单 // 自定义加入菜单
const showModal = () => { const showModal = () => {
childAddMenusModalRef.current.setOpen(true); childAddMenusModalRef.current.setOpen(true);
...@@ -100,6 +102,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -100,6 +102,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
}; };
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
console.log('infoMation', values);
props.onValuesChange({ infoMation: values }); props.onValuesChange({ infoMation: values });
}, 400); }, 400);
// 查询shopIds // 查询shopIds
...@@ -118,13 +121,17 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -118,13 +121,17 @@ const FormInformationBasic = forwardRef((props, ref) => {
}; };
const onChangeShopId = async e => { const onChangeShopId = async e => {
if (e) { if (e) {
queryShopList({ shopId: e }); // 分组列表 setShopList([]);
queryShopList({ shopId: e });
} }
}; };
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
onCheck, onCheck,
reset: form.resetFields, reset: form.resetFields,
})); }));
useEffect(() => {
queryShopIds();
}, [customer.productType]);
useEffect(() => { useEffect(() => {
const noreList = (brandList || []).filter(item => item.name === '虚拟商品'); const noreList = (brandList || []).filter(item => item.name === '虚拟商品');
...@@ -133,15 +140,15 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -133,15 +140,15 @@ const FormInformationBasic = forwardRef((props, ref) => {
useEffect(() => { useEffect(() => {
if (!editData) return; if (!editData) return;
if (editData.productType === 5 && editData.name) {
shopGetByProductType(5);
queryShopList({ shopId: editData.productRefShopId });
setIsEditTakeaway(true);
}
form.setFieldsValue(editData); form.setFieldsValue(editData);
onTakeawayImageList(editData.commonImageList);
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
useEffect(() => {
console.log('!customer.isTakeawayService', customer);
console.log('newCategoryList[customer.productType]', newCategoryList[customer.productType]);
console.log('newCategoryList[customer.productType]', shopList);
queryShopIds()
}, [customer.productType]);
return ( return (
<Form <Form
{...formItemLayout} {...formItemLayout}
...@@ -152,6 +159,8 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -152,6 +159,8 @@ const FormInformationBasic = forwardRef((props, ref) => {
name: '', name: '',
categoryId: [], categoryId: [],
description: '', description: '',
productRefShopId: [],
storageRackIds: [],
}} }}
scrollToFirstError scrollToFirstError
onValuesChange={getFormValues} onValuesChange={getFormValues}
...@@ -171,12 +180,12 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -171,12 +180,12 @@ const FormInformationBasic = forwardRef((props, ref) => {
{customer.isTakeawayService && ( {customer.isTakeawayService && (
<Form.Item <Form.Item
name="productRefShopId" name="productRefShopId"
key="productRefShopId"
label="所属门店" label="所属门店"
rules={[{ required: true, message: '请选择所属门店' }]} rules={[{ required: true, message: '请选择所属门店' }]}
> >
<Select <Select
fieldNames={{ label: 'name', value: 'id' }} fieldNames={{ label: 'name', value: 'id' }}
filterOption={fileterBrandOptions}
placeholder="请选择所属门店" placeholder="请选择所属门店"
options={shopIds} options={shopIds}
onChange={onChangeShopId} onChange={onChangeShopId}
...@@ -195,7 +204,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -195,7 +204,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
disabled={customer.isEdit && customer.isNormal} disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }} showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ label: 'name', value: 'id', children: 'children' }} fieldNames={{ label: 'name', value: 'id', children: 'children' }}
onChange={props.onCategoryChange} // onChange={props.onCategoryChange}
options={shopList} options={shopList}
dropdownRender={dropdownRender} dropdownRender={dropdownRender}
/> />
...@@ -205,7 +214,6 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -205,7 +214,6 @@ const FormInformationBasic = forwardRef((props, ref) => {
<AddMenusModal ref={childAddMenusModalRef} queryShopList={queryShopList} /> <AddMenusModal ref={childAddMenusModalRef} queryShopList={queryShopList} />
<Form.Item <Form.Item
name="categoryId" name="categoryId"
key="categoryId"
label="商品类目" label="商品类目"
rules={[{ type: 'array', required: true, message: '请输入商品类目' }]} rules={[{ type: 'array', required: true, message: '请输入商品类目' }]}
> >
......
...@@ -36,7 +36,7 @@ import AddSellTimeModal from './AddSellTimeModal'; ...@@ -36,7 +36,7 @@ import AddSellTimeModal from './AddSellTimeModal';
import styles from '../common.less'; import styles from '../common.less';
import AddRepertoryModal from './AddRepertoryModal'; import AddRepertoryModal from './AddRepertoryModal';
import AddMultiSpecModal from './AddMultiSpecModal'; import AddMultiSpecModal from './AddMultiSpecModal';
import { apiTagList, apiUnits, apiGetShopDetail } from '../service'; import { apiTagList, apiUnits } from '../service';
import { localAutoSaveKey } from '../utils'; import { localAutoSaveKey } from '../utils';
import localStorage from '@/utils/localStorage'; import localStorage from '@/utils/localStorage';
...@@ -47,37 +47,37 @@ const createInitValues = () => ({ ...@@ -47,37 +47,37 @@ const createInitValues = () => ({
saleTimeType: 0, // 售卖时间 saleTimeType: 0, // 售卖时间
singleDelivery: 0, // 单点不送 singleDelivery: 0, // 单点不送
list: 1, // 列出商品 list: 1, // 列出商品
label: '',
}); });
const format = 'HH:mm'; const format = 'HH:mm';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const TakeawayGoodsInfo = forwardRef((props, ref) => { const TakeawayGoodsInfo = forwardRef((props, ref) => {
const { editData, infoMation } = props; const { editData } = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [initValue, setInitValue] = useState(createInitValues()); const [initValue, setInitValue] = useState(createInitValues());
const customer = useContext(ServiceContext); const customer = useContext(ServiceContext);
const [detailImageList, setDetailImageList] = useState([]); const [detailImageList, setDetailImageList] = useState([]);
const [newCategoryList, setNewCategoryList] = useState({});
const addSellTimeRef = useRef(null); const addSellTimeRef = useRef(null);
const AddRepertoryRef = useRef(null); const AddRepertoryRef = useRef(null);
const AddMultiSpecRef = useRef(null); const AddMultiSpecRef = useRef(null);
const [saleDates, setSaleDates] = useState({ const [saleDates, setSaleDates] = useState({
saleDates: [], saleDates: [],
saleTimes: [], saleTimes: [],
// saleTimes: [[moment('22-02', 'HH:mm'), moment('23-02', 'HH:mm')]],
}); // 可售日期 }); // 可售日期
const [timeType, setTimeType] = useState(0); const [timeType, setTimeType] = useState(0);
const [repertoryType, setRepertoryType] = useState('1'); const [repertoryType, setRepertoryType] = useState('1');
const [tagList, setTagList] = useState([]); const [tagList, setTagList] = useState([]);
const [unitsList, setUnitsList] = useState([]); const [unitsList, setUnitsList] = useState([]);
const [takeawayData, setTakeawayData] = useState({}); const [takeawayData, setTakeawayData] = useState({});
// const [multiSpecList, setMultiSpecList] = useState([]);
// const [singularSpecList, setSingularSpecList] = useState([]);
const [multiSpu, setMultiSpu] = useState([]); const [multiSpu, setMultiSpu] = useState([]);
const [singularSpu, setSingularSpu] = useState([]); const [singularSpu, setSingularSpu] = useState([]);
const [intactData, setIntactData] = useState({}); const [intactData, setIntactData] = useState({});
const [repertoryState, setRepertoryState] = useState(''); const [repertoryState, setRepertoryState] = useState('');
const [repertoryModel, setRepertoryModel] = useState({}); const [repertoryModel, setRepertoryModel] = useState({});
const [tempMultiSpu, setTempMultiSpu] = useState([]); const [tempMultiSpu, setTempMultiSpu] = useState([]);
const [tempWeight, setTempWeight] = useState([]);
const [tempSpecs, setTempSpecs] = useState([]);
const initialDealValue = [ const initialDealValue = [
{ {
specGroupName: '', specGroupName: '',
...@@ -104,10 +104,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -104,10 +104,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const takeawayCalc = takeawayData => { const takeawayCalc = takeawayData => {
// 商品基本信息编辑商品名称 // 商品基本信息编辑商品名称
const { infoMation: name, infoMation, takeawayItem } = takeawayData; const { infoMation: name, infoMation, takeawayItem } = takeawayData;
console.log('i========', infoMation, takeawayItem, repertoryType);
// weight 份量 specs规格 生成sku规则 weight * specs // weight 份量 specs规格 生成sku规则 weight * specs
const { const {
specs = [], specs = tempSpecs,
weight = [], weight = tempWeight,
description, description,
detailImageList, detailImageList,
list, list,
...@@ -116,17 +117,23 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -116,17 +117,23 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
maxStock = 0, maxStock = 0,
saleTimes = [], saleTimes = [],
label, label,
unit = [], unit,
quantity, quantity,
productStock = 0, productStock = 0,
salePrice, salePrice,
singleDelivery, singleDelivery,
saleTimeType, saleTimeType,
autoStock = 0, autoStock = 0,
skuList,
id,
categoryId,
} = takeawayItem; } = takeawayItem;
console.log('skuList====', infoMation, takeawayItem, skuList);
const singularSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 单规格 const singularSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 单规格
const multiSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 多规格 const multiSpecList = [{ specGroupName: '份量', generateSku: 1, specs: [] }]; // 多规格
// const multiSpu = customer.isEdit ? skuList:[]; // 多库存spu、
const multiSpu = []; // 多库存spu、 const multiSpu = []; // 多库存spu、
let singularSpu = []; // 单库存spu let singularSpu = []; // 单库存spu
const saleTimesTemp = []; const saleTimesTemp = [];
let initIndex = 0; let initIndex = 0;
...@@ -141,6 +148,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -141,6 +148,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice: salePrice || 0, salePrice: salePrice || 0,
productStock, productStock,
list: 1, list: 1,
id: skuList?.length === 1 ? skuList[0].id : '', // 单规格默认取第一个
serviceItem: { serviceItem: {
description, // 商品描述 description, // 商品描述
maxStock, // 最大库存 maxStock, // 最大库存
...@@ -162,7 +170,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -162,7 +170,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice, salePrice,
maxStock, maxStock,
quantity, quantity,
unit: (unit && unit.splice(unit.length - 1)[0]) || '', unit: (Array.isArray(unit) && unit?.length && unit?.splice(unit?.length - 1)[0]) || unit,
productStock, productStock,
specGroupName: '份量', specGroupName: '份量',
}; };
...@@ -172,13 +180,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -172,13 +180,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
} }
// 多规格 // 多规格
if (+repertoryType === 2) { if (+repertoryType === 2) {
if (name) { if (name || editData.name) {
console.log('weight', weight);
if (weight.length) { if (weight.length) {
weight.forEach((item, weightIndex) => { weight.forEach((item, weightIndex) => {
console.log('eee====', item); if (item?.unit && item?.unit.length) {
if (item?.unit && item.unit.length) { item.unit =
item.unit = item.unit.slice(item.unit.length - 1).toString(); item?.unit &&
(Array.isArray(item?.unit) ? item.unit.slice(item.unit.length - 1)[0] : item.unit);
} }
if (item && !item.specGroupName) { if (item && !item.specGroupName) {
item.specGroupName = '份量'; item.specGroupName = '份量';
...@@ -244,27 +252,24 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -244,27 +252,24 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}); });
} }
} }
// console.log('multiSpu', multiSpu);
console.log('multiSpu===1111', multiSpu);
if (tempMultiSpu.length) { if (tempMultiSpu.length) {
multiSpu.forEach((item, index) => { multiSpu.forEach((item, index) => {
tempMultiSpu.forEach((itm, idx) => { tempMultiSpu.forEach((itm, idx) => {
if (item.unique === itm.unique) { if (item.unique === itm.unique) {
item.serviceItem = objectComparison(item.serviceItem, itm); item.serviceItem = objectComparison(item.serviceItem, itm);
item.id = itm.id;
} }
}); });
}); });
} }
console.log(multiSpu, tempMultiSpu, 'multiSpumultiSpu');
// debugger
console.log('multiSpu===2222', multiSpu);
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
} }
// debugger
// +repertoryType === 1 单规格 2多规格 // +repertoryType === 1 单规格 2多规格
const intactDataTemp = { const intactDataTemp = {
...takeawayItem,
id,
type: 5, // 外卖类型 type: 5, // 外卖类型
...infoMation, ...infoMation,
label: label && label.toString(), label: label && label.toString(),
...@@ -274,12 +279,16 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -274,12 +279,16 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singleDelivery, singleDelivery,
specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList
items: +repertoryType === 1 ? singularSpu : JSON.parse(JSON.stringify(multiSpu)), items: +repertoryType === 1 ? singularSpu : JSON.parse(JSON.stringify(multiSpu)),
categoryId: ( // categoryId:
infoMation?.categoryId && infoMation?.categoryId.slice(infoMation.categoryId.length - 1) // (
).toString(), // infoMation?.categoryId &&
// infoMation?.categoryId?.slice(infoMation?.categoryId?.length - 1)
// )?.toString() ||
// (Array.isArray(categoryId) && categoryId?.slice(categoryId?.length - 1)?.toString()),
}; };
console.log('intactData======>', intactData);
setIntactData(intactDataTemp); setIntactData(intactDataTemp);
console.log('intactData======>', form.getFieldsValue(), intactDataTemp);
return intactData; return intactData;
}; };
// 过滤对象 // 过滤对象
...@@ -287,24 +296,21 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -287,24 +296,21 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
let { let {
serviceItem: { maxStock, autoStock, productStock }, serviceItem: { maxStock, autoStock, productStock },
} = itm; } = itm;
let params = { maxStock, autoStock, productStock }; let params = { maxStock, autoStock, productStock: productStock || itm.productStock };
let temp = { ...item, ...params }; let temp = { ...item, ...params };
return temp; return temp;
}; };
const onChange = () => {}; const onChange = () => {};
const onDealFinish = values => {
console.log('Received values of form:', values);
};
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
console.log('values========', values); console.log('values', values);
props.onValuesChange({ takeawayItem: values }); props.onValuesChange({ takeawayItem: JSON.parse(JSON.stringify(values)) });
const takeawayData = localStorage.get(localAutoSaveKey); const takeawayData = customer.isEdit
console.log('takeawayData', takeawayData); ? { takeawayItem: Object.assign({}, editData, values) }
: localStorage.get(localAutoSaveKey) || {};
setTakeawayData(takeawayData); setTakeawayData(takeawayData);
takeawayCalc(takeawayData); takeawayCalc(takeawayData);
}, 400); }, 400);
// 设置库存 // 设置库存
const modifiedInventory = (type, idx, values) => { const modifiedInventory = (type, idx, values) => {
const { productStock, maxStock, autoStock } = values; const { productStock, maxStock, autoStock } = values;
...@@ -321,41 +327,23 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -321,41 +327,23 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
tempMultiSpu.push(...temp); tempMultiSpu.push(...temp);
setTempMultiSpu(tempMultiSpu); setTempMultiSpu(tempMultiSpu);
setMultiSpu(temp); setMultiSpu(temp);
console.log('33333========>', multiSpu, tempMultiSpu);
// if (intactData?.items.length) {
// intactData.items[+idx].serviceItem.productStock = productStock;
// intactData.items[+idx].serviceItem.autoStock = autoStock;
// intactData.items[+idx].serviceItem.maxStock = maxStock;
// console.log('index===2222', +idx, intactData);
// const temp = { ...intactData };
// setIntactData(temp);
// }
} }
if (type === 'all') { if (type === 'all') {
if (intactData?.items.length) { multiSpu.map(item => {
intactData?.items.forEach(item => {
item.serviceItem.productStock = productStock; item.serviceItem.productStock = productStock;
item.serviceItem.autoStock = autoStock; item.serviceItem.autoStock = autoStock;
item.serviceItem.maxStock = maxStock; item.serviceItem.maxStock = maxStock;
return item; return item;
}); });
const temp = { ...intactData }; let temp = JSON.parse(JSON.stringify(multiSpu));
setIntactData(temp); tempMultiSpu.push(...temp);
} setTempMultiSpu(tempMultiSpu);
setMultiSpu(multiSpu);
} }
console.log('=========', multiSpu, tempMultiSpu);
getFormValues();
return false; return false;
}; };
const querGetShopDetail = async () => {
let params = {
id: '638899799727110',
shopId: 15,
};
const result = await apiGetShopDetail(params);
console.log('result', result);
};
const fileterBrandOptions = (input, options) => options.children.includes(input);
const filterCategoryOptions = (inputValue, path) => const filterCategoryOptions = (inputValue, path) =>
path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1); path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
...@@ -377,13 +365,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -377,13 +365,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
detailImageList: imgList, detailImageList: imgList,
}); });
}; };
const radioChangeEvent = key => {
const value = form.getFieldValue(key);
setInitValue({
...initValue,
[key]: value,
});
};
// 自定义菜单下拉 // 自定义菜单下拉
const dropdownRender = menus => ( const dropdownRender = menus => (
<div> <div>
...@@ -440,7 +421,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -440,7 +421,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}; };
// 自动补全 // 自动补全
const onChangeAutoStock = e => { const onChangeAutoStock = e => {
console.log('e=======', e);
form.setFieldsValue({ form.setFieldsValue({
autoStock: e ? 1 : 0, autoStock: e ? 1 : 0,
}); });
...@@ -472,17 +452,91 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -472,17 +452,91 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const res = await apiUnits(); const res = await apiUnits();
setUnitsList(res.data || []); setUnitsList(res.data || []);
} }
querGetShopDetail();
setTempMultiSpu([]) setTempMultiSpu([]);
return false; return false;
}; };
useEffect(() => { useEffect(() => {
if (customer.isEdit || customer.isUseCache) { if (customer.isEdit || customer.isUseCache) {
if (!editData) return; if (!editData) return;
let { label, firstCategoryId, secondCategoryId, thirdCategoryId, id } = editData;
editData.label = label.split(',');
if (editData?.skuList.length) {
editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
// 单规格
if (editData?.skuList.length === 1) {
let {
productStock,
shopId,
specs,
serviceItem: { maxStock, saleTimeType, saleDates, saleTimes, id },
} = editData?.skuList[0];
let { quantity, unit, salePrice } = specs[0];
editData.productStock = productStock;
editData.quantity = quantity;
editData.unit = unit;
editData.salePrice = salePrice;
editData.maxStock = maxStock;
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
editData.saleTimeType = saleTimeType;
editData.saleDates = saleDates;
editData.saleTimes = saleTimes.length
? saleTimes.map(item => {
return [moment(item?.startTime, format), moment(item?.endTime, format)];
})
: [];
editData.productRefShopId = editData.shopId;
editData.skuId = id;
form.setFieldsValue(editData); form.setFieldsValue(editData);
setInitValue({ ...editData });
setTimeType(saleTimeType);
} else {
// 多规格
setRepertoryType(`2`);
let {
serviceItem: { saleTimeType, saleDates, saleTimes },
} = editData?.skuList[0];
let specList = editData?.specList;
let weight = specList.filter(item => item.specGroupName === '份量');
let specs = specList.filter(item => item.specGroupName !== '份量');
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
editData.saleTimeType = saleTimeType;
editData.saleDates = saleDates;
editData.saleTimes = saleTimes.length
? saleTimes.map(item => {
return [moment(item?.startTime, format), moment(item?.endTime, format)];
})
: [];
editData.productRefShopId = editData.shopId;
// setTempWeight(weight)
// setTempSpecs(specs)
setTimeType(saleTimeType);
form.setFieldsValue({ weight: weight[0].specs });
form.setFieldsValue(editData);
form.setFieldsValue({ specs });
console.log('editData?.skuList', editData?.skuList);
const tempMultiSpu = editData?.skuList.map(item => {
if (item) {
let weightIdx = item.specs.findIndex(itm => itm.specGroupName === '份量');
console.log('weightIdx', weightIdx);
let specsIdx = item.specs.findIndex(itm => itm.specGroupName !== '份量');
console.log('specsIdx', specsIdx);
item.unique = `${item.specs[weightIdx]?.specName}-${item.specs[specsIdx]?.specGroupName}-${item.specs[specsIdx]?.specName}`;
}
return item;
});
setTempMultiSpu(tempMultiSpu || []);
}
form.setFieldsValue({ productRefShopId: editData.shopId });
onCardSuccessImageList(editData?.detailImageList);
getFormValues();
// setInitValue({ ...editData });
} }
}, [customer.isEdit, customer.isUseCache, editData]); }
}, [customer.isEdit, editData]);
useEffect(() => { useEffect(() => {
setIntactData(intactData); setIntactData(intactData);
}, [intactData]); }, [intactData]);
...@@ -555,32 +609,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -555,32 +609,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
<Form.Item label="售卖时段"> <Form.Item label="售卖时段">
<Form.List <Form.List name="saleTimes" initialValue={[[]]}>
name="saleTimes"
initialValue={[[]]}
// rules={[
// {
// validator: async (_, times) => {
// if (!times || times.length < 2) {
// return Promise.reject(new Error('At least 2 passengers'));
// }
// },
// },
// ]}
>
{(fields, { add, remove }) => ( {(fields, { add, remove }) => (
<> <>
{fields.map((field, index) => ( {fields.map((field, index) => (
<Form.Item <Form.Item required={false} key={field.key} className={styles.deal}>
// {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
required={false}
key={field.key}
className={styles.deal}
>
<Form.Item <Form.Item
className={styles.deal} className={styles.deal}
{...field} {...field}
// validateTrigger={['onChange', 'onBlur']}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -635,11 +671,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -635,11 +671,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
</> </>
)} )}
<Form.Item <Form.Item name="label" label="商品标签">
name="label"
label="商品标签"
// rules={[{ type: 'array', required: true, message: '请输入售卖时间!' }]}
>
<Select <Select
mode="multiple" mode="multiple"
allowClear allowClear
...@@ -665,16 +697,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -665,16 +697,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Title title="规格信息" /> <Title title="规格信息" />
{!customer.isEdit && (
{/* <Form.Item label="限购" name="limitPurchase" valuePropName="checked">
<Checkbox onChange={() => radioChangeEvent('limitPurchase')}>
<b style={{ marginLeft: 10 }}>启用限购</b>
<span style={{ marginLeft: 10 }} className="ant-form-text">
限制每人可购买数量
</span>
</Checkbox>
</Form.Item> */}
<Form.Item label="库存" name="stock"> <Form.Item label="库存" name="stock">
<Radio.Group <Radio.Group
options={ENUM_REPERTORY} options={ENUM_REPERTORY}
...@@ -684,7 +707,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -684,7 +707,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
optionType="button" optionType="button"
/> />
</Form.Item> </Form.Item>
)}
{/* 单规格 */}
{repertoryType === '1' && ( {repertoryType === '1' && (
<> <>
<Form.Item label="份量" className={styles.required}> <Form.Item label="份量" className={styles.required}>
...@@ -699,7 +723,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -699,7 +723,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="unit" name="unit"
rules={[{ type: 'array', required: true, message: '请选择单位' }]} rules={[{ required: true, message: '请选择单位' }]}
// rules={[{ type: 'array', required: true, message: '请选择单位' }]}
style={{ style={{
display: 'inline-block', display: 'inline-block',
margin: '0 8px', margin: '0 8px',
...@@ -710,7 +735,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -710,7 +735,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
disabled={customer.isEdit && customer.isNormal} disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }} showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ label: 'name', value: 'name', children: 'children' }} fieldNames={{ label: 'name', value: 'name', children: 'children' }}
onChange={props.onCategoryChange} // onChange={props.onCategoryChange}
options={unitsList} options={unitsList}
/> />
</Form.Item> </Form.Item>
...@@ -767,7 +792,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -767,7 +792,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item> </Form.Item>
<div className={styles.rowWarp}> <div className={styles.rowWarp}>
{singularSpu.length > 0 && {singularSpu.length > 0 &&
takeawayData?.infoMation?.name && (takeawayData?.infoMation?.name || takeawayData.takeawayItem.name) &&
singularSpu.map((item, index) => ( singularSpu.map((item, index) => (
<div className={styles.specsBetween}> <div className={styles.specsBetween}>
<Form.Item label={calcLabelName(intactData, item, 'singular')}> <Form.Item label={calcLabelName(intactData, item, 'singular')}>
...@@ -790,41 +815,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -790,41 +815,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div> </div>
</> </>
)} )}
{/* 多规格 */}
{repertoryType === '2' && ( {repertoryType === '2' && (
<> <>
<Form.Item> <Form.Item>
<div>份量(如大小/小份、微辣/特辣等)</div> <div>份量(如大小/小份、微辣/特辣等)</div>
{/* <Form.List name="deal">
{(dealFields, { add, remove }) => (
<>
{dealFields.map((field, index) => (
<Form.Item key={field.key} className={styles.conBg}>
<Form.Item
{...field}
validateTrigger={['onChange', 'onBlur']}
name={[field.name, 'specGroupName']}
rules={[
{
required: true,
whitespace: true,
message: '请输入名称例如(份量)',
},
]}
noStyle
>
<Input
placeholder="请输入名称"
style={{
width: '60%',
}}
/>
</Form.Item>
{dealFields.length > 1 ? (
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(field.name)}
/>
) : null} */}
<Form.List name="weight" initialValue={[{}]}> <Form.List name="weight" initialValue={[{}]}>
{(weightFields, { add: weightAdd, remove: weightRemove }) => ( {(weightFields, { add: weightAdd, remove: weightRemove }) => (
<> <>
...@@ -861,7 +856,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -861,7 +856,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
name={[weightField.name, 'unit']} name={[weightField.name, 'unit']}
rules={[ rules={[
{ {
type: 'array', // type: 'array',
required: true, required: true,
message: '请选择单位', message: '请选择单位',
}, },
...@@ -876,7 +871,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -876,7 +871,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
value: 'name', value: 'name',
children: 'children', children: 'children',
}} }}
onChange={props.onCategoryChange} // onChange={props.onCategoryChange}
options={unitsList} options={unitsList}
/> />
</Form.Item> </Form.Item>
...@@ -922,38 +917,31 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -922,38 +917,31 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</> </>
)} )}
</Form.List> </Form.List>
{/* </Form.Item>
))} */}
{/* <Form.Item>
<Button
type="primary"
onClick={() => add()}
style={{
width: '400px',
}}
icon={<PlusOutlined />}
>
添加份量
</Button>
</Form.Item> */}
{/* </>
)}
</Form.List> */}
</Form.Item> </Form.Item>
{takeawayData?.takeawayItem?.weight?.length > 0 && ( {/* takeawayData?.takeawayItem?.weight?.length > 0 && */}
{
<> <>
<Form.Item> <Form.Item>
<div>添加规格(如加料、甜度、辣度等)</div> <div>添加规格(如加料、甜度、辣度等)</div>
<Form.List name="specs"> <Form.List
name="specs"
initialValue={
[
// {
// specGroupName: '',
// specs: [],
// },
]
}
>
{(specsFields, { add, remove }) => ( {(specsFields, { add, remove }) => (
<> <>
{specsFields.map((field, index) => ( {specsFields.map((specsField, index) => (
<Form.Item key={field.key} className={styles.conBg}> <Form.Item key={specsField.key} className={styles.conBg}>
<Form.Item <Form.Item
{...field} {...specsField}
validateTrigger={['onChange', 'onBlur']} validateTrigger={['onChange', 'onBlur']}
name={[field.name, 'specGroupName']} name={[specsField.name, 'specGroupName']}
rules={[ rules={[
{ {
required: true, required: true,
...@@ -965,15 +953,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -965,15 +953,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
> >
<Input placeholder="规格名称" className={styles.nameWidth} /> <Input placeholder="规格名称" className={styles.nameWidth} />
</Form.Item> </Form.Item>
{specsFields.length > 1 ? ( {/* {specsFields.length > 1 ? ( */}
<MinusCircleOutlined <MinusCircleOutlined
className="dynamic-delete-button" className="dynamic-delete-button"
onClick={() => remove(field.name)} onClick={() => remove(specsField.name)}
/> />
) : null} {/* ) : null} */}
<Form.List <Form.List
{...field} {...specsField}
name={[field.name, 'specs']} name={[specsField.name, 'specs']}
initialValue={[ initialValue={[
{ {
specName: '', specName: '',
...@@ -1097,7 +1085,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -1097,7 +1085,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div> </div>
</Form.Item> </Form.Item>
</> </>
)} }
</> </>
)} )}
</Form> </Form>
......
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
getByProductType, getByProductType,
apiCreateDraft, apiCreateDraft,
apiEditDraft, apiEditDraft,
apiAddTakeawayProducts, apiGetShopDetail,
} from './service'; } from './service';
import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils'; import { isUrl, filterSendData, clearCurrent, onAutoSaveValue, localAutoSaveKey } from './utils';
import { ServiceContext } from './context'; import { ServiceContext } from './context';
...@@ -35,12 +35,18 @@ import styles from './common.less'; ...@@ -35,12 +35,18 @@ import styles from './common.less';
* @returns ReactDOM * @returns ReactDOM
*/ */
const ServiceGoods = options => { const ServiceGoods = options => {
const { SourceData, categoryList, virtualCategoryList, specListData, permissions } = options; const {
SourceData,
categoryList,
virtualCategoryList,
specListData,
permissions,
takeAway,
} = options;
const canAddService = permissions[GOOD_MANAGE.ADD_SERVICE_GOODS]; const canAddService = permissions[GOOD_MANAGE.ADD_SERVICE_GOODS];
const canAddNormal = permissions[GOOD_MANAGE.ADD_NORMAL_GOODS]; const canAddNormal = permissions[GOOD_MANAGE.ADD_NORMAL_GOODS];
// const canTakeawayService = permissions[GOOD_MANAGE.ADD_TAKEAWAY_GOODS]; // const canTakeawayService = permissions[GOOD_MANAGE.ADD_TAKEAWAY_GOODS];
// const canTakeawayService = true // const canTakeawayService = true
const basicRef = useRef(null); const basicRef = useRef(null);
const stockRef = useRef(null); const stockRef = useRef(null);
const settingRef = useRef(null); const settingRef = useRef(null);
...@@ -62,6 +68,7 @@ const ServiceGoods = options => { ...@@ -62,6 +68,7 @@ const ServiceGoods = options => {
const [specList, setSpecList] = useState([]); // 规格列表 const [specList, setSpecList] = useState([]); // 规格列表
const [editData, setEditData] = useState({}); // 编辑保存数据 const [editData, setEditData] = useState({}); // 编辑保存数据
const [newCategoryList, setNewCategoryList] = useState({}); const [newCategoryList, setNewCategoryList] = useState({});
const [takeawayEditData, setTakeawayEditData] = useState({}); // 外卖编辑保存数据
const [visibleCacheEdit, setVisibleCacheEdit] = useState(false); // 显示有缓存未保存提示 const [visibleCacheEdit, setVisibleCacheEdit] = useState(false); // 显示有缓存未保存提示
const [checkFormList] = useState([ const [checkFormList] = useState([
...@@ -111,10 +118,44 @@ const ServiceGoods = options => { ...@@ -111,10 +118,44 @@ const ServiceGoods = options => {
}, },
!0, !0,
); );
if (stockRef.current) {
stockRef.current.onFinish(); stockRef.current.onFinish();
}
}, 1000); }, 1000);
}; };
// 查询外卖商品详情
const querGetShopDetail = async params => {
const { spuId, shopId } = params;
const temp = {
id: spuId,
shopId,
};
const { data } = await apiGetShopDetail(temp);
const {
name,
storageRackIds,
firstCategoryId,
secondCategoryId,
thirdCategoryId,
commonImageList,
id,
} = data;
const categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
const editInfoMation = {
infoMation: {
name,
productRefShopId: `${shopId}`,
commonImageList,
categoryId,
storageRackIds,
productType: 5,
},
};
setEditData(editInfoMation);
setTakeawayEditData(data);
setIsEdit(true);
setPageLoading(false);
};
const onResetData = refresh => { const onResetData = refresh => {
setPageId(null); setPageId(null);
setIsEdit(false); setIsEdit(false);
...@@ -195,7 +236,6 @@ const ServiceGoods = options => { ...@@ -195,7 +236,6 @@ const ServiceGoods = options => {
}); });
} }
}; };
// 保存商品 // 保存商品
const submitEvent = async () => { const submitEvent = async () => {
const checkPromiseList = clearCurrent(checkFormList).map(({ current }) => current.onCheck()); const checkPromiseList = clearCurrent(checkFormList).map(({ current }) => current.onCheck());
...@@ -208,14 +248,11 @@ const ServiceGoods = options => { ...@@ -208,14 +248,11 @@ const ServiceGoods = options => {
origin[temp] = other; origin[temp] = other;
return origin; return origin;
}, {}); }, {});
// 外卖商品创建 const sendData = filterSendData(productType, params);
if (+productType === 5) { if (productType === 5) {
console.log('parmas', params); sendMerchantProductHttpRequest(sendData);
const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
return false; return false;
} }
const sendData = filterSendData(productType, params);
if (isEdit) { if (isEdit) {
sendData.id = pageId; sendData.id = pageId;
} }
...@@ -333,6 +370,13 @@ const ServiceGoods = options => { ...@@ -333,6 +370,13 @@ const ServiceGoods = options => {
}, },
[specKeyList], [specKeyList],
); );
useEffect(() => {
// 外卖类型
if (takeAway && takeAway.spuId) {
setProductType(5);
querGetShopDetail(takeAway);
}
}, []);
const onEventBus = (event, params) => { const onEventBus = (event, params) => {
if (event === 'cloneImg') { if (event === 'cloneImg') {
...@@ -411,7 +455,6 @@ const ServiceGoods = options => { ...@@ -411,7 +455,6 @@ const ServiceGoods = options => {
}, },
}); });
}; };
console.log('productType', productType);
const providerValue = { const providerValue = {
pageId, pageId,
isEdit, isEdit,
...@@ -470,6 +513,7 @@ const ServiceGoods = options => { ...@@ -470,6 +513,7 @@ const ServiceGoods = options => {
ref={basicRef} ref={basicRef}
editData={editData.infoMation} editData={editData.infoMation}
newCategoryList={newCategoryList} newCategoryList={newCategoryList}
shopGetByProductType={shopGetByProductType}
categoryList={categoryList} categoryList={categoryList}
virtualCategoryList={virtualCategoryList} virtualCategoryList={virtualCategoryList}
brandList={brandList} brandList={brandList}
...@@ -538,7 +582,8 @@ const ServiceGoods = options => { ...@@ -538,7 +582,8 @@ const ServiceGoods = options => {
<> <>
<FormTakeaway <FormTakeaway
ref={takeawayRef} ref={takeawayRef}
editData={editData.takeawayItem} takeAway={takeAway}
editData={takeawayEditData}
infoMation={editData.infoMation} infoMation={editData.infoMation}
supplierIdList={supplierIdList} supplierIdList={supplierIdList}
onValuesChange={onValuesChange} onValuesChange={onValuesChange}
......
...@@ -109,7 +109,15 @@ const filterItems = (type, props) => { ...@@ -109,7 +109,15 @@ const filterItems = (type, props) => {
}; };
export const filterSendData = (type, params) => { export const filterSendData = (type, params) => {
const { infoMation, infoImageData, attributeApplyList } = params; // takeawayItem 外卖商品
const { infoMation, infoImageData, attributeApplyList, takeawayItem } = params;
console.log('infoMation', infoMation, takeawayItem);
const temp = Object.assign({}, takeawayItem?.intactData, infoMation)
temp.categoryId = (Array.isArray(temp.categoryId) && temp.categoryId?.slice(temp.categoryId?.length - 1)?.toString())
// 外卖商品
if (type === 5) {
return temp;
}
const items = filterItems(type, params); const items = filterItems(type, params);
const commonImageList = type === 4 ? [] : infoImageData.commonImageList; const commonImageList = type === 4 ? [] : infoImageData.commonImageList;
const obj = { const obj = {
...@@ -128,6 +136,7 @@ export const filterSendData = (type, params) => { ...@@ -128,6 +136,7 @@ export const filterSendData = (type, params) => {
if (attributeApplyList && attributeApplyList.attributeApplyList) { if (attributeApplyList && attributeApplyList.attributeApplyList) {
obj.attributeApplyList = attributeApplyList.attributeApplyList; obj.attributeApplyList = attributeApplyList.attributeApplyList;
} }
return obj; return obj;
}; };
......
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