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

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

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