商城后台系统的多规格

文章讲述了如何处理商品的多规格信息,如颜色和尺码。首先获取每个规格的值数据类型,然后通过循环处理生成SKU列表。接着,使用一个公共方法`combineArrays`来组合不同的规格选项,生成所有可能的组合,将这些组合添加到规格列表中,用于后续的商品展示和管理。
摘要由CSDN通过智能技术生成

 需要添加多规格,并且还要根据算法生成对应的规格列表
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;
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值