Commit 5d4359f5 authored by 陈万宝's avatar 陈万宝

feat: 修改新增商品无法同步sku

parent ad22d13b
...@@ -49,6 +49,7 @@ const createInitValues = () => ({ ...@@ -49,6 +49,7 @@ const createInitValues = () => ({
singleDelivery: 0, // 单点不送 singleDelivery: 0, // 单点不送
list: 1, // 列出商品 list: 1, // 列出商品
label: [], label: [],
minPurchaseNum: 1,
}); });
const format = 'HH:mm'; const format = 'HH:mm';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
...@@ -99,6 +100,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -99,6 +100,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
return null; return null;
} }
}; };
// 过滤对象
const objectComparison = (item, itm) => {
const {
serviceItem: { maxStock, autoStock, productStock },
} = itm;
const params = { maxStock, autoStock, productStock: productStock || itm.productStock };
const temp = { ...item, ...params };
return temp;
};
const takeawayCalc = takeawayData => { const takeawayCalc = takeawayData => {
// 商品基本信息编辑商品名称 // 商品基本信息编辑商品名称
const { infoMation: name, infoMation, takeawayItem } = takeawayData; const { infoMation: name, infoMation, takeawayItem } = takeawayData;
...@@ -109,7 +119,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -109,7 +119,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
description, description,
detailImageList, detailImageList,
list, list,
minPurchaseNum = 1, minPurchaseNum,
saleDates, saleDates,
maxStock = 0, maxStock = 0,
saleTimes = [], saleTimes = [],
...@@ -124,7 +134,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -124,7 +134,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
id, id,
categoryId, categoryId,
} = takeawayItem; } = takeawayItem;
let unit = takeawayItem.unit; let { unit } = takeawayItem;
unit = (unit && (Array.isArray(unit) && unit?.length && unit?.slice(1).toString())) || unit; unit = (unit && (Array.isArray(unit) && unit?.length && unit?.slice(1).toString())) || unit;
console.log(takeawayItem, 'takeawayItem'); console.log(takeawayItem, 'takeawayItem');
...@@ -180,9 +190,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -180,9 +190,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
setSingularSpu(singularSpu); setSingularSpu(singularSpu);
console.log('singularSpu', singularSpu); console.log('singularSpu', singularSpu);
} }
console.log('name || editData.name', name, editData.name, weight);
// 多规格 // 多规格
if (+repertoryType === 2) { if (+repertoryType === 2) {
if (name || editData.name) { // if (name || editData.name) {
if (weight.length) { if (weight.length) {
let tempSku = []; let tempSku = [];
multiSpecList[0].specs = weight; // 处理specList multiSpecList[0].specs = weight; // 处理specList
...@@ -202,11 +214,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -202,11 +214,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const sepcx = specs.map(item => item.specs); const sepcx = specs.map(item => item.specs);
sepcx.map(item => { sepcx.map(item => {
item.unit = ''; item.unit = '';
return item
}); });
// 生成 specs 规格sku // 生成 specs 规格sku
tempSku = [[...weight], ...sepcx].reduce( tempSku = [[...weight], ...sepcx].reduce(
(x, y) => { (x, y) => {
let arr = []; const arr = [];
x.forEach(x => y.forEach(y => arr.push(x.concat([y])))); x.forEach(x => y.forEach(y => arr.push(x.concat([y]))));
return arr; return arr;
}, },
...@@ -214,10 +227,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -214,10 +227,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
); );
console.log('multiSpu1111', multiSpu); console.log('multiSpu1111', multiSpu);
multiSpu = tempSku.map((item, index) => { multiSpu = tempSku.map((item, index) => {
let obj = {}; const obj = {};
obj.salePrice = salePrice; obj.salePrice = salePrice;
obj.productStock = productStock; obj.productStock = productStock;
obj.list = list; obj.list = list;
obj.id = multiSpu?.[index]?.id || ''
obj.serviceItem = { obj.serviceItem = {
...temp.serviceItem, ...temp.serviceItem,
productStock: multiSpu?.[index]?.serviceItem?.productStock || productStock, productStock: multiSpu?.[index]?.serviceItem?.productStock || productStock,
...@@ -269,7 +283,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -269,7 +283,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
console.log(multiSpu, 'multiSpumultiSpu'); console.log(multiSpu, 'multiSpumultiSpu');
setMultiSpu(JSON.parse(JSON.stringify(multiSpu))); setMultiSpu(JSON.parse(JSON.stringify(multiSpu)));
} // }
} }
// +repertoryType === 1 单规格 2多规格 // +repertoryType === 1 单规格 2多规格
const intactDataTemp = { const intactDataTemp = {
...@@ -296,15 +310,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -296,15 +310,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
setIntactData(intactDataTemp); setIntactData(intactDataTemp);
return intactData; return intactData;
}; };
// 过滤对象
const objectComparison = (item, itm) => {
let {
serviceItem: { maxStock, autoStock, productStock },
} = itm;
let params = { maxStock, autoStock, productStock: productStock || itm.productStock };
let temp = { ...item, ...params };
return temp;
};
const onChange = () => {}; const onChange = () => {};
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
...@@ -340,7 +346,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -340,7 +346,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
return item; return item;
}); });
} }
let temp = JSON.parse(JSON.stringify(multiSpu)); const temp = JSON.parse(JSON.stringify(multiSpu));
tempMultiSpu.push(...temp); tempMultiSpu.push(...temp);
setTempMultiSpu(tempMultiSpu); setTempMultiSpu(tempMultiSpu);
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
...@@ -392,7 +398,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -392,7 +398,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
); );
// 切换库存 // 切换库存
const onChangeRepertory = e => { const onChangeRepertory = e => {
const value = e.target.value; const { value } = e.target;
setRepertoryType(`${value}`); setRepertoryType(`${value}`);
if (+value === 1) { if (+value === 1) {
form.setFieldsValue({ weight: [] }); form.setFieldsValue({ weight: [] });
...@@ -475,8 +481,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -475,8 +481,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (!unitsList.length) { if (!unitsList.length) {
const res = await apiUnits(); const res = await apiUnits();
setUnitsList(res.data || []); setUnitsList(res.data || []);
let tempWeight = res.data.filter(item => item.name === '准确重量单位'); const tempWeight = res.data.filter(item => item.name === '准确重量单位');
let tempPeople = res.data.filter(item => item.name === '适用人数'); const tempPeople = res.data.filter(item => item.name === '适用人数');
if (tempWeight.length && tempWeight[0]?.children) { if (tempWeight.length && tempWeight[0]?.children) {
const tempWeightName = tempWeight[0]?.children.map(item => item.name); const tempWeightName = tempWeight[0]?.children.map(item => item.name);
...@@ -495,7 +501,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -495,7 +501,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
useEffect(() => { useEffect(() => {
if (customer.isEdit || customer.isUseCache) { if (customer.isEdit || customer.isUseCache) {
if (!editData) return; if (!editData) return;
let { const {
label, label,
firstCategoryId, firstCategoryId,
secondCategoryId, secondCategoryId,
...@@ -505,9 +511,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -505,9 +511,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
saleTimeType, saleTimeType,
} = editData; } = editData;
editData.label = label && label.split(',')?.map(item => +item); editData.label = label && label.split(',')?.map(item => +item);
let specList = editData?.specList; const specList = editData?.specList;
let weight = specList?.filter(item => item.specGroupName === '份量'); const weight = specList?.filter(item => item.specGroupName === '份量');
let specs = specList?.filter(item => item.specGroupName !== '份量'); const specs = specList?.filter(item => item.specGroupName !== '份量');
const tempWeightName = JSON.parse(sessionStorage.getItem('weightUnits')); const tempWeightName = JSON.parse(sessionStorage.getItem('weightUnits'));
weight?.forEach(item => { weight?.forEach(item => {
if (item?.specs?.length) { if (item?.specs?.length) {
...@@ -520,40 +526,38 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -520,40 +526,38 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
} }
}); });
editData.saleTimes = saleTimes?.length editData.saleTimes = saleTimes?.length
? saleTimes.map(item => { ? saleTimes.map(item => [moment(item?.startTime, format), moment(item?.endTime, format)])
return [moment(item?.startTime, format), moment(item?.endTime, format)];
})
: []; : [];
if (editData?.skuList?.length) { if (editData?.skuList?.length) {
// editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum; // editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
// 单规格 // 单规格
if (editData?.skuList?.length === 1) { if (editData?.skuList?.length === 1) {
let { const {
productStock, productStock,
shopId, shopId,
specs, specs,
serviceItem: { maxStock, id, autoStock }, serviceItem: { maxStock, id, autoStock },
} = editData?.skuList[0]; } = editData?.skuList[0];
let { quantity, unit, salePrice } = specs[0]; const { quantity, unit, salePrice } = specs[0];
editData.productStock = productStock; editData.productStock = productStock;
editData.quantity = `${quantity}`.indexOf('约') > -1 ? quantity.slice(1) : quantity || ''; editData.quantity = `${quantity}`.indexOf('约') > -1 ? quantity.slice(1) : quantity || '';
editData.unit = unit; editData.unit = unit;
editData.salePrice = salePrice; editData.salePrice = salePrice;
editData.maxStock = maxStock; editData.maxStock = maxStock;
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId]; editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
editData.autoStock = +autoStock === 1 ? true : false; editData.autoStock = +autoStock === 1;
editData.productRefShopId = editData.shopId; editData.productRefShopId = editData.shopId;
editData.skuId = id; editData.skuId = id;
// setSingularSpu(JSON.parse(JSON.stringify(tempMultiSpu)) || []); // setSingularSpu(JSON.parse(JSON.stringify(tempMultiSpu)) || []);
form.setFieldsValue(editData); form.setFieldsValue(editData);
} else { } else {
// 多规格 // 多规格
setRepertoryType(`2`); setRepertoryType('2');
let { const {
serviceItem: { saleTimeType, saleDates, saleTimes }, serviceItem: { saleTimeType, saleDates, saleTimes },
} = editData?.skuList[0]; } = editData?.skuList[0];
let specList = editData?.specList; const specList = editData?.specList;
let weight = specList.filter(item => item.specGroupName === '份量'); const weight = specList.filter(item => item.specGroupName === '份量');
const tempWeightName = JSON.parse(sessionStorage.getItem('weightUnits')); const tempWeightName = JSON.parse(sessionStorage.getItem('weightUnits'));
weight?.forEach(item => { weight?.forEach(item => {
if (item?.specs?.length) { if (item?.specs?.length) {
...@@ -579,11 +583,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -579,11 +583,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
if (item) { if (item) {
console.log('item===', item); console.log('item===', item);
item.serviceItem.productStock = item.productStock; item.serviceItem.productStock = item.productStock;
let weightIndex = item.specs.findIndex(itm => itm.specGroupName === '份量'); const weightIndex = item.specs.findIndex(itm => itm.specGroupName === '份量');
let tempQuantity = item.specs[weightIndex].quantity; const tempQuantity = item.specs[weightIndex].quantity;
let tempUnit = item.specs[weightIndex].unit; const tempUnit = item.specs[weightIndex].unit;
let specsNameList = item.specs.map(itm => itm.specName); const specsNameList = item.specs.map(itm => itm.specName);
let lastName = specsNameList.slice(1)?.join(' '); const lastName = specsNameList.slice(1)?.join(' ');
item.unique = item?.specs.map(itm => itm.specName).toString(); item.unique = item?.specs.map(itm => itm.specName).toString();
} }
return item; return item;
...@@ -644,12 +648,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -644,12 +648,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<Form.Item <Form.Item
name="minPurchaseNum" name="minPurchaseNum"
label="最少购买" label="最少购买"
rules={[{ required: true, message: '请输入最少购买数' }, rules={[
{ { required: true, message: '请输入最少购买数' },
validator: isIntegerNotZero, {
type: 'number', validator: isIntegerNotZero,
message: '请输入大于0的整数', type: 'number',
},]} message: '请输入大于0的整数',
},
]}
> >
<InputNumber min={1} max={999999999} style={{ width: 200 }} placeholder="请输入购买量" /> <InputNumber min={1} max={999999999} style={{ width: 200 }} placeholder="请输入购买量" />
</Form.Item> </Form.Item>
...@@ -833,7 +839,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -833,7 +839,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
showSearch={{ filter: filterCategoryOptions }} showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ label: 'name', value: 'name', children: 'children' }} fieldNames={{ label: 'name', value: 'name', children: 'children' }}
onChange={() => { onChange={() => {
let unit = form.getFieldValue('unit') || []; const unit = form.getFieldValue('unit') || [];
if (unit && peopleUnits.includes(unit[1])) { if (unit && peopleUnits.includes(unit[1])) {
form.setFieldsValue({ quantity: '' }); form.setFieldsValue({ quantity: '' });
} }
...@@ -889,13 +895,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -889,13 +895,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<Form.Item <Form.Item
name="maxStock" name="maxStock"
label="最大库存" label="最大库存"
rules={[{ required: isRequired, message: '请填写最大库存' }, rules={[
{ { required: isRequired, message: '请填写最大库存' },
validator: isIntegerNotZero, {
type: 'number', validator: isIntegerNotZero,
message: '请输入大于0的整数', type: 'number',
}, message: '请输入大于0的整数',
]} },
]}
> >
<InputNumber <InputNumber
max={999999999} max={999999999}
...@@ -988,11 +995,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -988,11 +995,9 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
name={[weightField.name, 'quantity']} name={[weightField.name, 'quantity']}
rules={[ rules={[
{ {
required: peopleUnits.includes( required: !peopleUnits.includes(
form.getFieldValue(['weight'])?.[index]?.unit, form.getFieldValue(['weight'])?.[index]?.unit,
) ),
? false
: true,
message: '份量', message: '份量',
}, },
{ {
......
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