商城后台系统的多规格

 需要添加多规格,并且还要根据算法生成对应的规格列表
1、获取此规格值数据类型

specsList:[{
        title: "颜色",
        specsTag:['蓝色','绿色'],
      },{
        title: "尺码",
        specsTag:['165*130','L','XL'],
}]

2、处理数据

let skuList = []

for(const { specsTag } of this.specsList) {

    skuList.push(specsTag)

}
// this.muitiSpecsList 规格列表
const combinations = this.combineArrays(skuList);
      combinations.forEach(item=>{
        this.muitiSpecsList.push({
          ID:0,
          AttrDetail:item,
          Image : '',
          Price : 0,
          FakePrice : 0,
          StoreNum : 0,
          Sku: '',//商品编号
        })
      })

3、处理多规格的公共方法

combineArrays(arrays) {
      if (arrays.length === 0) {
        return [[]];
      }
      const result = [];
      const currentArray = arrays[0];
      const remainingArrays = arrays.slice(1);
      const combinations = this.combineArrays(remainingArrays);
      for (let i = 0; i < currentArray.length; i++) {
        for (let j = 0; j < combinations.length; j++) {
          result.push([currentArray[i], ...combinations[j]]);
        }
      }
      return result;
 }

猜你喜欢

转载自blog.csdn.net/a_grain_of_wheat/article/details/131919198