博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小程序实现sku商品规格
阅读量:2167 次
发布时间:2019-05-01

本文共 2965 字,大约阅读时间需要 9 分钟。

 

实现商品颜色和尺码反选的大致思路:

1.一开始显示的默认价格是后台传递的。

2.调用商品详情接口的时候需要传递SKU数组(存放有颜色和尺码的数组集合),sizeVOList数组(存放商品所有的尺码集合),skcVOList(存放商品所有的颜色集合)。

3.用户点击颜色,将尺码中的status状态首先设置为false,这步操作是为什么后面显示是否有货。尺码一致~

具体代码

/**    * 点击尺寸 颜色改变样式    */  changeSize: function (e) {    var nowSize, chooses = e.currentTarget.dataset.chooses;    if (e.currentTarget.dataset.disc) return    if (this.data.nowSize == chooses) {      nowSize = "";      var skcVOList = this.data.skcVOList;      skcVOList.forEach(item => item.status = false)      this.setData({ skcVOList })    } else {      nowSize = chooses    }    this.setData({      nowSize: nowSize    })    this.distachAttrResult(this.data.nowColor + this.data.nowSize);  },   /**    * 点击尺寸 颜色改变样式    */   changeColor: function (e) {    let productId = e.currentTarget.dataset.productcode;    var nowColor, choosec = e.currentTarget.dataset.choosec;    if (e.currentTarget.dataset.disc) return    if (this.data.nowColor == choosec) {      nowColor = ""      var sizeVOList=this.data.sizeVOList;      sizeVOList.forEach(item => item.status = false);      this.setData({sizeVOList})    } else {      nowColor = choosec      // 颜色选中后图片发生改变      this.changeColorImg(e.currentTarget.dataset.color);    }    this.setData({      nowColor: nowColor,      productCode: productId    })    this.distachAttrResult(this.data.nowColor + this.data.nowSize);  },

组合可选

//组合可选  distachAttrResult: function (res) {    var skuVOList = this.data.skuVOList;    if (this.data.nowColor) {      //通过颜色选尺码      var sizeArry;      sizeArry = skuVOList.filter((i, v) => i.colorKey == this.data.nowColor);      var sizeVOList = this.data.sizeVOList      console.log('sizeVOList',sizeVOList);      for (var j in sizeVOList) {        if (sizeArry.find((value, index, array) => value.sizeKey == sizeVOList[j].sizeKey)) {          sizeVOList[j].status = false        } else {          sizeVOList[j].status = true        }      }      console.log('sizeVOList',sizeVOList);      this.setData({        sizeVOList: sizeVOList,        ischange: true      })    }    if (this.data.nowSize) {      //通过尺码选颜色      var colorArry;      colorArry = skuVOList.filter((i, v) => i.sizeKey == this.data.nowSize);      var skcVOList = this.data.skcVOList;      for (var j in skcVOList) {        if (colorArry.find((value, index, array) => value.colorKey == skcVOList[j].colorKey)) {          skcVOList[j].status = false        } else {          skcVOList[j].status = true        }      }      this.setData({        skcVOList: skcVOList,        ischange: true      })    }    if (this.data.nowColor && this.data.nowSize) {      // 执行颜色、尺码都选中后的事情      var nowGoods = skuVOList.filter((i, v) => i.colorKey == this.data.nowColor && i.sizeKey == this.data.nowSize)[0];      console.log('nowGoods',nowGoods)      var promotionSale = nowGoods.promotionDisplay;      this.setData({        proBarCode: nowGoods.barCode,        salePrice: nowGoods.salePrice,        price: nowGoods.standardPrice      })    }  },

 

转载地址:http://rrpzb.baihongyu.com/

你可能感兴趣的文章
TP5.1模板布局中遇到的坑,配置完不生效解决办法
查看>>
PHPstudy中遇到的坑No input file specified,以及传到linux环境下遇到的坑,模板文件不存在
查看>>
TP5.1事务操作和TP5事务回滚操作多表
查看>>
composer install或composer update 或 composer require phpoffice/phpexcel 失败解决办法
查看>>
TP5.1项目从windows的Apache服务迁移到linux的Nginx服务需要注意几点。
查看>>
win10安装软件 打开时报错 找不到 msvcp120.dll
查看>>
PHPunit+Xdebug代码覆盖率以及遇到的问题汇总
查看>>
PHPUnit安装及使用
查看>>
PHP项目用xhprof性能分析(安装及应用实例)
查看>>
composer安装YII
查看>>
Sublime text3快捷键演示
查看>>
sublime text3 快捷键修改
查看>>
关于PHP几点建议
查看>>
硬盘的接口、协议
查看>>
VLAN与子网划分区别
查看>>
Cisco Packet Tracer教程
查看>>
02. 交换机的基本配置和管理
查看>>
03. 交换机的Telnet远程登陆配置
查看>>
微信小程序-调用-腾讯视频-解决方案
查看>>
phpStudy安装yaf扩展
查看>>