Commit 184bb8b8 authored by 陈万宝's avatar 陈万宝

feat: 更新回显商品

parent cdf53e53
...@@ -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);
...@@ -43,6 +42,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -43,6 +42,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 {
...@@ -118,13 +118,17 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -118,13 +118,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 === '虚拟商品');
...@@ -132,16 +136,16 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -132,16 +136,16 @@ const FormInformationBasic = forwardRef((props, ref) => {
}, [brandList]); }, [brandList]);
useEffect(() => { useEffect(() => {
console.log('商品类目', newCategoryList[customer.productType]);
if (!editData) return; if (!editData) return;
if (editData.productType === 5 && editData.name) {
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 +156,8 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -152,6 +156,8 @@ const FormInformationBasic = forwardRef((props, ref) => {
name: '', name: '',
categoryId: [], categoryId: [],
description: '', description: '',
productRefShopId: [15],
storageRackIds: [],
}} }}
scrollToFirstError scrollToFirstError
onValuesChange={getFormValues} onValuesChange={getFormValues}
...@@ -165,18 +171,18 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -165,18 +171,18 @@ const FormInformationBasic = forwardRef((props, ref) => {
{ required: true, min: 2, message: '请输入最少两个字符的商品名称', whitespace: true }, { required: true, min: 2, message: '请输入最少两个字符的商品名称', whitespace: true },
]} ]}
> >
<Input placeholder="请输入商品名称" disabled={customer.isDisabled} /> <Input placeholder="请输入商品名称" disabled={customer.isDisabled || isEditTakeaway} />
</Form.Item> </Form.Item>
</Popover> </Popover>
{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 +201,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -195,7 +201,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 +211,6 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -205,7 +211,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: '请输入商品类目' }]}
> >
......
...@@ -47,16 +47,16 @@ const createInitValues = () => ({ ...@@ -47,16 +47,16 @@ 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, takeAway } = 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);
...@@ -69,8 +69,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -69,8 +69,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
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({});
...@@ -115,14 +113,18 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -115,14 +113,18 @@ 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,
categoryId,
skuList,
id,
} = takeawayItem; } = takeawayItem;
console.log('id', id, 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 = []; // 多库存spu、 const multiSpu = []; // 多库存spu、
...@@ -161,7 +163,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -161,7 +163,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice, salePrice,
maxStock, maxStock,
quantity, quantity,
unit: (unit && unit.splice(unit.length - 1)[0]) || '', // unit: (unit && unit?.length && unit?.splice(unit?.length - 1)[0]) || unit,
unit,
productStock, productStock,
specGroupName: '份量', specGroupName: '份量',
}; };
...@@ -169,6 +172,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -169,6 +172,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singularSpu = [{ ...temp, specs: [specs] }]; singularSpu = [{ ...temp, specs: [specs] }];
setSingularSpu(singularSpu); setSingularSpu(singularSpu);
} }
console.log('singularSpu', singularSpu);
// 多规格 // 多规格
if (+repertoryType === 2) { if (+repertoryType === 2) {
if (name) { if (name) {
...@@ -245,7 +249,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -245,7 +249,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
} }
// console.log('multiSpu', multiSpu); // 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) => {
...@@ -255,15 +258,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -255,15 +258,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}); });
}); });
} }
// debugger // debugger
console.log('multiSpu===2222', multiSpu);
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
} }
// debugger
// +repertoryType === 1 单规格 2多规格 // +repertoryType === 1 单规格 2多规格
const intactDataTemp = { const intactDataTemp = {
id,
type: 5, // 外卖类型 type: 5, // 外卖类型
...infoMation, ...infoMation,
label: label && label.toString(), label: label && label.toString(),
...@@ -273,12 +273,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -273,12 +273,15 @@ 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() || categoryId,
}; };
console.log('intactData======>', intactData);
setIntactData(intactDataTemp); setIntactData(intactDataTemp);
console.log('intactData======>', intactDataTemp);
return intactData; return intactData;
}; };
// 过滤对象 // 过滤对象
...@@ -296,14 +299,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -296,14 +299,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}; };
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
console.log('values========', values); props.onValuesChange({ takeawayItem: JSON.parse(JSON.stringify(values)) });
props.onValuesChange({ takeawayItem: values }); const takeawayData = customer.isEdit
const takeawayData = localStorage.get(localAutoSaveKey); ? { takeawayItem: Object.assign({}, editData, values) }
console.log('takeawayData', takeawayData); : localStorage.get(localAutoSaveKey) || {};
console.log('takeawayDatatakeawayData', takeawayData);
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;
...@@ -413,7 +416,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -413,7 +416,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,
}); });
...@@ -452,12 +454,35 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -452,12 +454,35 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
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;
console.log('id', id);
editData.label = +label;
if (editData?.skuList.length) {
editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
}
// 单规格
if (editData?.skuList.length === 1) {
let {
productStock,
specs,
serviceItem: { maxStock },
} = 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];
}
form.setFieldsValue(editData); form.setFieldsValue(editData);
setInitValue({ ...editData }); onCardSuccessImageList(editData?.detailImageList);
getFormValues();
// setInitValue({ ...editData });
} }
}, [customer.isEdit, customer.isUseCache, editData]); }, [customer.isEdit, editData]);
useEffect(() => { useEffect(() => {
setIntactData(intactData); // setIntactData(intactData);
}, [intactData]); }, [intactData]);
useEffect(() => { useEffect(() => {
init(); init();
...@@ -640,7 +665,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -640,7 +665,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',
...@@ -651,7 +677,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -651,7 +677,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>
...@@ -787,7 +813,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -787,7 +813,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>
......
...@@ -68,6 +68,7 @@ const ServiceGoods = options => { ...@@ -68,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([
...@@ -130,7 +131,30 @@ const ServiceGoods = options => { ...@@ -130,7 +131,30 @@ const ServiceGoods = options => {
shopId, shopId,
}; };
const { data } = await apiGetShopDetail(temp); const { data } = await apiGetShopDetail(temp);
console.log(data, '=====外卖结果'); 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);
...@@ -224,12 +248,11 @@ const ServiceGoods = options => { ...@@ -224,12 +248,11 @@ const ServiceGoods = options => {
origin[temp] = other; origin[temp] = other;
return origin; return origin;
}, {}); }, {});
// 外卖商品创建
// if (+productType === 5) {
// console.log('parmas', params);
// const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
// }
const sendData = filterSendData(productType, params); const sendData = filterSendData(productType, params);
if (productType === 5) {
sendMerchantProductHttpRequest(sendData);
return false;
}
if (isEdit) { if (isEdit) {
sendData.id = pageId; sendData.id = pageId;
} }
...@@ -316,12 +339,6 @@ const ServiceGoods = options => { ...@@ -316,12 +339,6 @@ const ServiceGoods = options => {
// 默认生成一条规格数据 // 默认生成一条规格数据
stockRef.current.onFinish(); stockRef.current.onFinish();
} }
console.log('takeAway', takeAway);
if (takeAway && takeAway.spuId) {
productChange({ type: 5 });
querGetShopDetail(takeAway);
setIsEdit(true);
}
setPageLoading(false); setPageLoading(false);
})(); })();
}, [SourceData]); }, [SourceData]);
...@@ -353,6 +370,13 @@ const ServiceGoods = options => { ...@@ -353,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') {
...@@ -558,7 +582,7 @@ const ServiceGoods = options => { ...@@ -558,7 +582,7 @@ const ServiceGoods = options => {
<FormTakeaway <FormTakeaway
ref={takeawayRef} ref={takeawayRef}
takeAway={takeAway} takeAway={takeAway}
editData={editData.takeaway} editData={takeawayEditData}
infoMation={editData.infoMation} infoMation={editData.infoMation}
supplierIdList={supplierIdList} supplierIdList={supplierIdList}
onValuesChange={onValuesChange} onValuesChange={onValuesChange}
......
...@@ -111,6 +111,10 @@ const filterItems = (type, props) => { ...@@ -111,6 +111,10 @@ const filterItems = (type, props) => {
export const filterSendData = (type, params) => { export const filterSendData = (type, params) => {
// takeawayItem 外卖商品 // takeawayItem 外卖商品
const { infoMation, infoImageData, attributeApplyList, takeawayItem } = params; const { infoMation, infoImageData, attributeApplyList, takeawayItem } = params;
// 外卖商品
if (type === 5) {
return takeawayItem?.intactData;
}
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 = {
...@@ -129,10 +133,7 @@ export const filterSendData = (type, params) => { ...@@ -129,10 +133,7 @@ export const filterSendData = (type, params) => {
if (attributeApplyList && attributeApplyList.attributeApplyList) { if (attributeApplyList && attributeApplyList.attributeApplyList) {
obj.attributeApplyList = attributeApplyList.attributeApplyList; obj.attributeApplyList = attributeApplyList.attributeApplyList;
} }
// 外卖商品
if (type === 5) {
return takeawayItem?.intactData;
}
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