From 998367f80e252276a4976b05aa628eddf6a906a9 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Wed, 4 Apr 2018 16:28:35 +0800 Subject: [PATCH] =?UTF-8?q?fix[litemall-wx]:=20=E5=95=86=E5=93=81=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=B4=A7=E5=93=81=EF=BC=8C=E5=88=99=E6=98=BE=E7=A4=BA=E8=B4=A7?= =?UTF-8?q?=E5=93=81=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=B7=E6=A0=BC=EF=BC=9B?= =?UTF-8?q?=E5=90=A6=E5=88=99=E6=98=BE=E7=A4=BA=E5=95=86=E5=93=81=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- litemall-wx/pages/goods/goods.js | 65 +++++++++++++++++++++++------- litemall-wx/pages/goods/goods.wxml | 4 +- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/litemall-wx/pages/goods/goods.js b/litemall-wx/pages/goods/goods.js index 3bfb5c4b..c35ad27e 100644 --- a/litemall-wx/pages/goods/goods.js +++ b/litemall-wx/pages/goods/goods.js @@ -18,8 +18,9 @@ Page({ cartGoodsCount: 0, userHasCollect: 0, number: 1, - checkedSpecText: '规格数量', + checkedSpecText: '规格数量选择', tmpSpecText: '请选择规格数量', + checkedSpecPrice: 0, openAttr: false, noCollectImage: '/static/images/icon_collect.png', hasCollectImage: '/static/images/icon_collect_checked.png', @@ -31,13 +32,24 @@ Page({ if (res.errno === 0) { let _specificationList = res.data.specificationList - // 如果仅仅只存在一个规格,那么商品页面初始化时默认checked + // 如果仅仅存在一种货品,那么商品页面初始化时默认checked if (_specificationList.length == 1) { if (_specificationList[0].valueList.length == 1) { _specificationList[0].valueList[0].checked = true + + // 如果仅仅存在一种货品,那么商品价格应该和货品价格一致,商品数量应该和货品数量一致 + // 这里检测一下 + let _producePrice = _specificationList[0].valueList[0].retailPrice; + let _goodsPrice = res.data.info.retailPrice; + let _produceNumber = _specificationList[0].valueList[0].goodsNumber; + let _goodsNumber = res.data.info.number; + if (_producePrice != _goodsPrice || _produceNumber != _goodsNumber){ + console.error('商品数量价格和货品不一致'); + } + that.setData({ checkedSpecText: _specificationList[0].valueList[0].value, - tmpSpecText: '已选择:' + _specificationList[0].valueList[0].value + tmpSpecText: '已选择:' + _specificationList[0].valueList[0].value, }); } } @@ -50,7 +62,8 @@ Page({ brand: res.data.brand, specificationList: res.data.specificationList, productList: res.data.productList, - userHasCollect: res.data.userHasCollect + userHasCollect: res.data.userHasCollect, + checkedSpecPrice: res.data.info.retailPrice }); if (res.data.userHasCollect == 1) { @@ -182,10 +195,32 @@ Page({ this.setData({ checkedSpecText: this.data.tmpSpecText }); + + // 规格所对应的货品选择以后 + let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); + if (!checkedProductArray || checkedProductArray.length <= 0) { + console.error('规格所对应货品不存在'); + return; + } + + let checkedProduct = checkedProductArray[0]; + if (checkedProduct.goodsNumber > 0){ + this.setData({ + checkedSpecPrice: checkedProduct.retailPrice + }); + } + else{ + this.setData({ + checkedSpecPrice: this.data.goods.retailPrice + }); + } + + } else{ this.setData({ - checkedSpecText: '规格数量' + checkedSpecText: '规格数量选择', + checkedSpecPrice: this.data.goods.retailPrice }); } @@ -303,8 +338,8 @@ Page({ } //根据选中的规格,判断是否有对应的sku信息 - let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey()); - if (!checkedProduct || checkedProduct.length <= 0) { + let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); + if (!checkedProductArray || checkedProductArray.length <= 0) { //找不到对应的product信息,提示没有库存 wx.showToast({ image: '/static/images/icon_error.png', @@ -313,9 +348,9 @@ Page({ return false; } + let checkedProduct = checkedProductArray[0]; //验证库存 - if (checkedProduct.goods_number < this.data.number) { - //找不到对应的product信息,提示没有库存 + if (checkedProduct.goodsNumber <= 0) { wx.showToast({ image: '/static/images/icon_error.png', title: '没有库存' @@ -324,7 +359,7 @@ Page({ } //立即购买 - util.request(api.CartFastAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST") + util.request(api.CartFastAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct.id }, "POST") .then(function (res) { if (res.errno == 0) { @@ -369,8 +404,8 @@ Page({ } //根据选中的规格,判断是否有对应的sku信息 - let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey()); - if (!checkedProduct || checkedProduct.length <= 0) { + let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); + if (!checkedProductArray || checkedProductArray.length <= 0) { //找不到对应的product信息,提示没有库存 wx.showToast({ image: '/static/images/icon_error.png', @@ -379,9 +414,9 @@ Page({ return false; } + let checkedProduct = checkedProductArray[0]; //验证库存 - if (checkedProduct.goods_number < this.data.number) { - //找不到对应的product信息,提示没有库存 + if (checkedProduct.goodsNumber <= 0) { wx.showToast({ image: '/static/images/icon_error.png', title: '没有库存' @@ -390,7 +425,7 @@ Page({ } //添加到购物车 - util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST") + util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct.id }, "POST") .then(function (res) { let _res = res; if (_res.errno == 0) { diff --git a/litemall-wx/pages/goods/goods.wxml b/litemall-wx/pages/goods/goods.wxml index 67944730..1a41a00b 100644 --- a/litemall-wx/pages/goods/goods.wxml +++ b/litemall-wx/pages/goods/goods.wxml @@ -14,7 +14,7 @@ {{goods.name}} {{goods.goodsBrief}} - ¥{{goods.retailPrice}} + ¥{{checkedSpecPrice}} {{brand.name}} @@ -105,7 +105,7 @@ - 价格:¥{{goods.retailPrice}} + 价格:¥{{checkedSpecPrice}} {{tmpSpecText}}