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

feat: 更新商品

parent 7953b2af
...@@ -62,7 +62,7 @@ class goodsManage extends Component { ...@@ -62,7 +62,7 @@ class goodsManage extends Component {
auditRow: {}, // 查看审核信息使用 auditRow: {}, // 查看审核信息使用
isVisibleDraft: false, // 显示隐藏草稿箱 isVisibleDraft: false, // 显示隐藏草稿箱
isEditDraft: false, // 是否编辑草稿 isEditDraft: false, // 是否编辑草稿
productType: 1, // 商品类型 productType: 5, // 商品类型
takeAway: {}, // 弹窗外卖商品参数 takeAway: {}, // 弹窗外卖商品参数
searchValue: {}, // 搜索条件 searchValue: {}, // 搜索条件
refresh: '', // 外卖刷新 refresh: '', // 外卖刷新
......
...@@ -37,7 +37,7 @@ import styles from '../common.less'; ...@@ -37,7 +37,7 @@ import styles from '../common.less';
import AddRepertoryModal from './AddRepertoryModal'; import AddRepertoryModal from './AddRepertoryModal';
import AddMultiSpecModal from './AddMultiSpecModal'; import AddMultiSpecModal from './AddMultiSpecModal';
import { apiTagList, apiUnits } from '../service'; import { apiTagList, apiUnits } from '../service';
import { localAutoSaveKey } from '../utils'; import { localAutoSaveKey ,calcDescartes} from '../utils';
import localStorage from '@/utils/localStorage'; import localStorage from '@/utils/localStorage';
const createInitValues = () => ({ const createInitValues = () => ({
...@@ -101,8 +101,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -101,8 +101,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const { infoMation: name, infoMation, takeawayItem } = takeawayData; const { infoMation: name, infoMation, takeawayItem } = takeawayData;
// weight 份量 specs规格 生成sku规则 weight * specs // weight 份量 specs规格 生成sku规则 weight * specs
const { const {
specs = tempSpecs, specs = [],
weight = tempWeight, weight = [],
description, description,
detailImageList, detailImageList,
list, list,
...@@ -122,6 +122,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -122,6 +122,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
id, id,
categoryId, categoryId,
} = takeawayItem; } = takeawayItem;
console.log("weight",weight);
console.log("sepcx",specs)
// const sepcx = specs.map(item => item.specs)
// let sku = [[...weight],...sepcx].reduce((x,y) =>{
// let arr = [];
// x.forEach(x => y.forEach(y => arr.push(x.concat([y]))))
// return arr;
// },[[]])
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 = customer.isEdit ? skuList:[]; // 多库存spu、
...@@ -172,81 +186,114 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -172,81 +186,114 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singularSpu = [{ ...temp, specs: [specs] }]; singularSpu = [{ ...temp, specs: [specs] }];
setSingularSpu(singularSpu); setSingularSpu(singularSpu);
} }
console.log("weight",weight,repertoryType,weight.length);
// 多规格 // 多规格
if (+repertoryType === 2) { if (+repertoryType === 2) {
if (name || editData.name) { // if (name || editData.name) {
if (weight.length) { if (weight.length) {
weight.forEach((item, weightIndex) => {
if (item?.unit && item?.unit.length) {
item.unit =
item?.unit &&
(Array.isArray(item?.unit) ? item.unit.slice(item.unit.length - 1)[0] : item.unit);
}
if (item && !item.specGroupName) {
item.specGroupName = '份量';
}
if (item && !item.generateSku) {
item.generateSku = 1;
}
multiSpecList[0].specs = weight; // 处理specList multiSpecList[0].specs = weight; // 处理specList
// 循环一次 插入规则列表 if(specs.length){
let isFirstLoops = true; specs.forEach((specsItem, specsIndex)=>{
if (specs.length) {
specs.forEach((specsItem, specsIndex) => {
if (specsItem && !specsItem.generateSku) { if (specsItem && !specsItem.generateSku) {
specsItem.generateSku = 1; specsItem.generateSku = 1;
} }
if (isFirstLoops && multiSpecList.length < specs.length + 1) { multiSpecList.push(specsItem)
multiSpecList.push(specsItem); // 处理specList })
} }
if (specsItem.specs.length > 1) { console.log("multiSpecList",multiSpecList);
specsItem.specs.forEach((itm, idx) => {
const params = {
initIndex,
unique: `${item.specName}-${specsItem.specGroupName}-${specsItem.specs[idx].specName}`,
...JSON.parse(JSON.stringify(temp)),
// ...intactData?.items[initIndex],
specs: [
{ ...item },
{ ...specsItem.specs[idx], specGroupName: specsItem.specGroupName },
],
};
multiSpu.push(params); // 处理spu
initIndex++; // const sepcx = specs.map(item => item.specs)
}); // let sku = [[...weight],...sepcx].reduce((x,y) =>{
} else { // let arr = [];
const params = { // x.forEach(x => y.forEach(y => arr.push(x.concat([y]))))
initIndex, // return arr;
unique: `${item.specName}-${specsItem.specGroupName}-${specsItem.specs[0].specName}`, // },[[]])
...JSON.parse(JSON.stringify(temp)), let result = []
// ...intactData?.items[initIndex], weight.forEach(item =>{
specs: [ console.log("item",item);
{ ...item }, specs.forEach((itm,idx) =>{
{ ...specsItem.specs[0], specGroupName: specsItem.specGroupName }, console.log("itm",itm);
], itm.specs.forEach((it,idx) =>{
}; result.push({...temp,specs:[item,specs[idx],it]})
multiSpu.push(params); // 处理spu })
initIndex++; })
} })
});
isFirstLoops = false;
} else { console.log(result,"result")
const params = { // weight.forEach((item, weightIndex) => {
initIndex, // if (item?.unit && item?.unit.length) {
unique: `${item?.specName}`, // item.unit =
...JSON.parse(JSON.stringify(temp)), // item?.unit &&
// ...intactData?.items[initIndex], // (Array.isArray(item?.unit) ? item.unit.slice(item.unit.length - 1)[0] : item.unit);
specs: [{ ...item }], // }
}; // if (item && !item.specGroupName) {
multiSpu.push(params); // 处理spu // item.specGroupName = '份量';
initIndex++; // }
} // if (item && !item.generateSku) {
}); // item.generateSku = 1;
} // }
// multiSpecList[0].specs = weight; // 处理specList
// // 循环一次 插入规则列表
// let isFirstLoops = true;
// if (specs.length) {
// specs.forEach((specsItem, specsIndex) => {
// if (specsItem && !specsItem.generateSku) {
// specsItem.generateSku = 1;
// }
// if (isFirstLoops && multiSpecList.length < specs.length + 1) {
// multiSpecList.push(specsItem); // 处理specList
// }
// if (specsItem.specs.length > 1) {
// specsItem.specs.forEach((itm, idx) => {
// const params = {
// initIndex,
// unique: `${item.specName}-${specsItem.specGroupName}-${specsItem.specs[idx].specName}`,
// ...JSON.parse(JSON.stringify(temp)),
// // ...intactData?.items[initIndex],
// specs: [
// { ...item },
// { ...specsItem.specs[idx], specGroupName: specsItem.specGroupName },
// ],
// };
// multiSpu.push(params); // 处理spu
// initIndex++;
// });
// } else {
// const params = {
// initIndex,
// unique: `${item.specName}-${specsItem.specGroupName}-${specsItem.specs[0].specName}`,
// ...JSON.parse(JSON.stringify(temp)),
// // ...intactData?.items[initIndex],
// specs: [
// { ...item },
// { ...specsItem.specs[0], specGroupName: specsItem.specGroupName },
// ],
// };
// multiSpu.push(params); // 处理spu
// initIndex++;
// }
// });
// isFirstLoops = false;
// } else {
// const params = {
// initIndex,
// unique: `${item?.specName}`,
// ...JSON.parse(JSON.stringify(temp)),
// // ...intactData?.items[initIndex],
// specs: [{ ...item }],
// };
// multiSpu.push(params); // 处理spu
// initIndex++;
// }
// });
} }
// }
console.log("multiSpu",multiSpu);
if (tempMultiSpu.length) { if (tempMultiSpu.length) {
multiSpu.forEach((item, index) => { multiSpu.forEach((item, index) => {
tempMultiSpu.forEach((itm, idx) => { tempMultiSpu.forEach((itm, idx) => {
...@@ -257,6 +304,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => { ...@@ -257,6 +304,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}); });
}); });
} }
// let weight= form.getFieldValue('weight')
console.log("weight",weight);
console.log(multiSpu, tempMultiSpu, 'multiSpumultiSpu'); console.log(multiSpu, tempMultiSpu, 'multiSpumultiSpu');
setMultiSpu(multiSpu); setMultiSpu(multiSpu);
} }
......
...@@ -317,3 +317,22 @@ export const onAutoSaveValue = (e, isClear) => { ...@@ -317,3 +317,22 @@ export const onAutoSaveValue = (e, isClear) => {
localStorage.set(localAutoSaveKey, Object.assign({ type: 1 }, info, e)); localStorage.set(localAutoSaveKey, Object.assign({ type: 1 }, info, e));
} }
}; };
export const calcDescartes = (array) => {
console.log(array,"array");
if (array.length < 2) return array[0] || [];
return [].reduce.call(array, function (col, set) {
var res = [];
col.forEach(function (c) {
set.forEach(function (s) {
var t = [].concat(Array.isArray(c) ? c : [c]);
t.push(s);
res.push(t);
})
});
return res;
});
}
\ No newline at end of file
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