Commit 4ff4d225 authored by 陈万宝's avatar 陈万宝

feat: 更新商品库

parent 1a4aa07b
...@@ -16,7 +16,6 @@ const AddRepertoryModal = (props, ref) => { ...@@ -16,7 +16,6 @@ const AddRepertoryModal = (props, ref) => {
}); });
const { modifiedInventory, intactData, repertoryModel } = props; const { modifiedInventory, intactData, repertoryModel } = props;
console.log('repertoryModel', repertoryModel);
const { type, idx, item } = repertoryModel; const { type, idx, item } = repertoryModel;
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
// changeVal 就是暴露给父组件的方法 // changeVal 就是暴露给父组件的方法
...@@ -26,14 +25,12 @@ const AddRepertoryModal = (props, ref) => { ...@@ -26,14 +25,12 @@ const AddRepertoryModal = (props, ref) => {
})); }));
// 自动补全 // 自动补全
const onChangeAutoStock = e => { const onChangeAutoStock = e => {
console.log('onChangeAutoStock');
form.setFieldsValue({ form.setFieldsValue({
autoStock: e ? 1 : 0, autoStock: e ? 1 : 0,
}); });
}; };
// 勾选库存设置 // 勾选库存设置
const onChangeSetRepertory = e => { const onChangeSetRepertory = e => {
console.log('form', form);
setRepertoryState(`${e.target.value}`); setRepertoryState(`${e.target.value}`);
if (+e.target.value === 0) { if (+e.target.value === 0) {
form.setFieldsValue({ form.setFieldsValue({
...@@ -57,25 +54,23 @@ const AddRepertoryModal = (props, ref) => { ...@@ -57,25 +54,23 @@ const AddRepertoryModal = (props, ref) => {
}; };
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
console.log('values========', values);
}, 400); }, 400);
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
values.autoStock = values.autoStock ? 1 : 0; values.autoStock = values.autoStock ? 1 : 0;
// 回调库存 // 回调库存
modifiedInventory(type, idx, values); modifiedInventory(type, idx, values);
// setConfirmLoading(true); setConfirmLoading(true);
// setTimeout(() => { setTimeout(() => {
// setOpenRepertory(false); setOpenRepertory(false);
// setConfirmLoading(false); setConfirmLoading(false);
// }, 2000); }, 1000);
}; };
const handleCancel = () => { const handleCancel = () => {
setOpenRepertory(false); setOpenRepertory(false);
}; };
useEffect(() => { useEffect(() => {
console.log('333', repertoryModel);
if (item?.serviceItem) { if (item?.serviceItem) {
const { productStock = 1, autoStock = 0, maxStock = 2 } = item?.serviceItem; const { productStock = 1, autoStock = 0, maxStock = 2 } = item?.serviceItem;
const params = { const params = {
...@@ -83,11 +78,8 @@ const AddRepertoryModal = (props, ref) => { ...@@ -83,11 +78,8 @@ const AddRepertoryModal = (props, ref) => {
autoStock: +autoStock === 1, autoStock: +autoStock === 1,
maxStock, maxStock,
}; };
console.log('params=====', params);
switch (type) { switch (type) {
case 'all': // 统一设置 case 'all': // 统一设置
console.log('params', params);
form.setFieldsValue(params); form.setFieldsValue(params);
break; break;
case 'multi': // 多规格设置 case 'multi': // 多规格设置
......
...@@ -128,6 +128,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -128,6 +128,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const multiSpu = []; // 单库存spu const multiSpu = []; // 单库存spu
let singularSpu = []; // 多库存spu let singularSpu = []; // 多库存spu
const saleTimesTemp = []; const saleTimesTemp = [];
let initIndex = 0;
if (saleTimes.length) { if (saleTimes.length) {
saleTimes.forEach(item => { saleTimes.forEach(item => {
const startTime = item ? moment(item[0]).format(format) : ''; const startTime = item ? moment(item[0]).format(format) : '';
...@@ -166,12 +167,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -166,12 +167,10 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}; };
singularSpecList[0].specs = [specs]; singularSpecList[0].specs = [specs];
singularSpu = [{ ...temp, specs: [specs] }]; singularSpu = [{ ...temp, specs: [specs] }];
console.log('2222', singularSpu);
setSingularSpu(singularSpu); setSingularSpu(singularSpu);
} }
// 多规格 // 多规格
if (+repertoryType === 2) { if (+repertoryType === 2) {
console.log('222');
if (name) { if (name) {
if (weight.length) { if (weight.length) {
weight.forEach((item, weightIndex) => { weight.forEach((item, weightIndex) => {
...@@ -194,32 +193,42 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -194,32 +193,42 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (specsItem.specs.length > 1) { if (specsItem.specs.length > 1) {
specsItem.specs.forEach((itm, idx) => { specsItem.specs.forEach((itm, idx) => {
const params = { const params = {
...temp, initIndex,
...JSON.parse(JSON.stringify(temp)),
...intactData?.items[initIndex],
specs: [ specs: [
{ ...item }, { ...item },
{ ...specsItem.specs[idx], specGroupName: specsItem.specGroupName }, { ...specsItem.specs[idx], specGroupName: specsItem.specGroupName },
], ],
}; };
multiSpu.push(params); // 处理spu multiSpu.push(params); // 处理spu
initIndex++;
}); });
} else { } else {
const params = { const params = {
...temp, initIndex,
...JSON.parse(JSON.stringify(temp)),
...intactData?.items[initIndex],
specs: [ specs: [
{ ...item }, { ...item },
{ ...specsItem.specs[0], specGroupName: specsItem.specGroupName }, { ...specsItem.specs[0], specGroupName: specsItem.specGroupName },
], ],
}; };
multiSpu.push(params); // 处理spu multiSpu.push(params); // 处理spu
initIndex++;
} }
}); });
isFirstLoops = false; isFirstLoops = false;
} else { } else {
const params = { const params = {
...temp, initIndex,
...JSON.parse(JSON.stringify(temp)),
...intactData?.items[initIndex],
specs: [{ ...item }], specs: [{ ...item }],
}; };
multiSpu.push(params); // 处理spu multiSpu.push(params); // 处理spu
initIndex++;
} }
}); });
} }
...@@ -228,7 +237,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -228,7 +237,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
} }
// +repertoryType === 1 单规格 2多规格 // +repertoryType === 1 单规格 2多规格
const intactData = { const intactDataTemp = {
type: 5, // 外卖类型 type: 5, // 外卖类型
...infoMation, ...infoMation,
label: label && label.toString(), label: label && label.toString(),
...@@ -237,15 +246,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -237,15 +246,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
detailImageList, detailImageList,
singleDelivery, singleDelivery,
specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList
items: +repertoryType === 1 ? singularSpu : multiSpu, items: +repertoryType === 1 ? singularSpu : JSON.parse(JSON.stringify(multiSpu)),
categoryId: ( categoryId: (
infoMation?.categoryId && infoMation?.categoryId.slice(infoMation.categoryId.length - 1) infoMation?.categoryId && infoMation?.categoryId.slice(infoMation.categoryId.length - 1)
).toString(), ).toString(),
storageRackIds: [1633015955205664770], storageRackIds: [1633015955205664770],
}; };
console.log('intactData======>', intactData); console.log('intactData======>', intactData);
setIntactData(intactData); setIntactData(intactDataTemp);
return intactData; return false;
}; };
const onChange = () => {}; const onChange = () => {};
...@@ -259,26 +268,30 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -259,26 +268,30 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const takeawayData = localStorage.get(localAutoSaveKey); const takeawayData = localStorage.get(localAutoSaveKey);
console.log('takeawayData', takeawayData); console.log('takeawayData', takeawayData);
setTakeawayData(takeawayData); setTakeawayData(takeawayData);
console.log("3333",isCalcTakeaway); takeawayCalc(takeawayData);
takeawayCalc(takeawayData);
}, 400); }, 400);
// 设置库存 // 设置库存
const modifiedInventory = (type, idx, values) => { const modifiedInventory = (type, idx, values) => {
console.log("isCalcTakeaway",isCalcTakeaway);
const { productStock, maxStock, autoStock } = values; const { productStock, maxStock, autoStock } = values;
if (type === 'multi') { if (type === 'multi') {
if (intactData?.items.length) { if (intactData?.items.length) {
// intactData.items[index].serviceItem.productStock = productStock
// intactData.items[index].serviceItem.autoStock = autoStock
// intactData.items[index].serviceItem.maxStock = maxStock
intactData.items[+idx].serviceItem.productStock = productStock; intactData.items[+idx].serviceItem.productStock = productStock;
intactData.items[+idx].serviceItem.autoStock = autoStock; intactData.items[+idx].serviceItem.autoStock = autoStock;
intactData.items[+idx].serviceItem.maxStock = maxStock; intactData.items[+idx].serviceItem.maxStock = maxStock;
// intactData.items[1].serviceItem.productStock = 2 console.log('index===2222', +idx, intactData);
// intactData.items[1].serviceItem.autoStock = 0 const temp = { ...intactData };
// intactData.items[1].serviceItem.maxStock = 2 setIntactData(temp);
console.log('index===', +idx, intactData); }
}
if (type === 'all') {
if (intactData?.items.length) {
intactData?.items.forEach(item => {
item.serviceItem.productStock = productStock;
item.serviceItem.autoStock = autoStock;
item.serviceItem.maxStock = maxStock;
return item;
});
const temp = { ...intactData }; const temp = { ...intactData };
setIntactData(temp); setIntactData(temp);
} }
......
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