|
@@ -26,7 +26,7 @@ Page({
|
|
|
},
|
|
|
getGoodsInfo: function () {
|
|
|
let that = this;
|
|
|
- util.request(api.GoodsDetail + '/' + that.data.id ).then(function (res) {
|
|
|
+ util.request(api.GoodsDetail + '/' + that.data.id).then(function (res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setData({
|
|
|
goods: res.data.info,
|
|
@@ -68,130 +68,131 @@ Page({
|
|
|
});
|
|
|
|
|
|
},
|
|
|
- clickSkuValue: function (event) {
|
|
|
- let that = this;
|
|
|
- let specNameId = event.currentTarget.dataset.nameId;
|
|
|
- let specValueId = event.currentTarget.dataset.valueId;
|
|
|
+ // clickSkuValue: function (event) {
|
|
|
+ // let that = this;
|
|
|
+ // let specNameId = event.currentTarget.dataset.nameId;
|
|
|
+ // let specValueId = event.currentTarget.dataset.valueId;
|
|
|
|
|
|
- //判断是否可以点击
|
|
|
+ // //判断是否可以点击
|
|
|
|
|
|
- //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
|
|
|
- let _specificationList = this.data.specificationList;
|
|
|
- for (let i = 0; i < _specificationList.length; i++) {
|
|
|
- if (_specificationList[i].specification_id == specNameId) {
|
|
|
- for (let j = 0; j < _specificationList[i].valueList.length; j++) {
|
|
|
- if (_specificationList[i].valueList[j].id == specValueId) {
|
|
|
- //如果已经选中,则反选
|
|
|
- if (_specificationList[i].valueList[j].checked) {
|
|
|
- _specificationList[i].valueList[j].checked = false;
|
|
|
- } else {
|
|
|
- _specificationList[i].valueList[j].checked = true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- _specificationList[i].valueList[j].checked = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- 'specificationList': _specificationList
|
|
|
- });
|
|
|
- //重新计算spec改变后的信息
|
|
|
- this.changeSpecInfo();
|
|
|
+ // //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
|
|
|
+ // let _specificationList = this.data.specificationList;
|
|
|
+ // for (let i = 0; i < _specificationList.length; i++) {
|
|
|
+ // if (_specificationList[i].specification_id == specNameId) {
|
|
|
+ // for (let j = 0; j < _specificationList[i].valueList.length; j++) {
|
|
|
+ // if (_specificationList[i].valueList[j].id == specValueId) {
|
|
|
+ // //如果已经选中,则反选
|
|
|
+ // if (_specificationList[i].valueList[j].checked) {
|
|
|
+ // _specificationList[i].valueList[j].checked = false;
|
|
|
+ // } else {
|
|
|
+ // _specificationList[i].valueList[j].checked = true;
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // _specificationList[i].valueList[j].checked = false;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // this.setData({
|
|
|
+ // 'specificationList': _specificationList
|
|
|
+ // });
|
|
|
+ // //重新计算spec改变后的信息
|
|
|
+ // this.changeSpecInfo();
|
|
|
|
|
|
- //重新计算哪些值不可以点击
|
|
|
- },
|
|
|
+ // //重新计算哪些值不可以点击
|
|
|
+ // },
|
|
|
|
|
|
//获取选中的规格信息
|
|
|
- getCheckedSpecValue: function () {
|
|
|
- let checkedValues = [];
|
|
|
- let _specificationList = this.data.specificationList;
|
|
|
- for (let i = 0; i < _specificationList.length; i++) {
|
|
|
- let _checkedObj = {
|
|
|
- nameId: _specificationList[i].specification_id,
|
|
|
- valueId: 0,
|
|
|
- valueText: ''
|
|
|
- };
|
|
|
- for (let j = 0; j < _specificationList[i].valueList.length; j++) {
|
|
|
- if (_specificationList[i].valueList[j].checked) {
|
|
|
- _checkedObj.valueId = _specificationList[i].valueList[j].id;
|
|
|
- _checkedObj.valueText = _specificationList[i].valueList[j].value;
|
|
|
- }
|
|
|
- }
|
|
|
- checkedValues.push(_checkedObj);
|
|
|
- }
|
|
|
+ // getCheckedSpecValue: function () {
|
|
|
+ // let checkedValues = [];
|
|
|
+ // let _specificationList = this.data.specificationList;
|
|
|
+ // for (let i = 0; i < _specificationList.length; i++) {
|
|
|
+ // let _checkedObj = {
|
|
|
+ // nameId: _specificationList[i].specification_id,
|
|
|
+ // valueId: 0,
|
|
|
+ // valueText: ''
|
|
|
+ // };
|
|
|
+ // for (let j = 0; j < _specificationList[i].valueList.length; j++) {
|
|
|
+ // if (_specificationList[i].valueList[j].checked) {
|
|
|
+ // _checkedObj.valueId = _specificationList[i].valueList[j].id;
|
|
|
+ // _checkedObj.valueText = _specificationList[i].valueList[j].value;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // checkedValues.push(_checkedObj);
|
|
|
+ // }
|
|
|
|
|
|
- return checkedValues;
|
|
|
+ // return checkedValues;
|
|
|
|
|
|
- },
|
|
|
- //根据已选的值,计算其它值的状态
|
|
|
- setSpecValueStatus: function () {
|
|
|
+ // },
|
|
|
+ // //根据已选的值,计算其它值的状态
|
|
|
+ // setSpecValueStatus: function () {
|
|
|
|
|
|
- },
|
|
|
- //判断规格是否选择完整
|
|
|
- isCheckedAllSpec: function () {
|
|
|
- return !this.getCheckedSpecValue().some(function (v) {
|
|
|
- if (v.valueId == 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- getCheckedSpecKey: function () {
|
|
|
- let checkedValue = this.getCheckedSpecValue().map(function (v) {
|
|
|
- return v.valueId;
|
|
|
- });
|
|
|
+ // },
|
|
|
+ // //判断规格是否选择完整
|
|
|
+ // isCheckedAllSpec: function () {
|
|
|
+ // return !this.getCheckedSpecValue().some(function (v) {
|
|
|
+ // if (v.valueId == 0) {
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // getCheckedSpecKey: function () {
|
|
|
+ // let checkedValue = this.getCheckedSpecValue().map(function (v) {
|
|
|
+ // return v.valueId;
|
|
|
+ // });
|
|
|
|
|
|
- return checkedValue.join('_');
|
|
|
- },
|
|
|
- changeSpecInfo: function () {
|
|
|
- let checkedNameValue = this.getCheckedSpecValue();
|
|
|
+ // return checkedValue.join('_');
|
|
|
+ // },
|
|
|
+ // changeSpecInfo: function () {
|
|
|
+ // let checkedNameValue = this.getCheckedSpecValue();
|
|
|
|
|
|
- //设置选择的信息
|
|
|
- let checkedValue = checkedNameValue.filter(function (v) {
|
|
|
- if (v.valueId != 0) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }).map(function (v) {
|
|
|
- return v.valueText;
|
|
|
- });
|
|
|
- if (checkedValue.length > 0) {
|
|
|
- this.setData({
|
|
|
- 'checkedSpecText': checkedValue.join(' ')
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.setData({
|
|
|
- 'checkedSpecText': '请选择规格数量'
|
|
|
- });
|
|
|
- }
|
|
|
+ // //设置选择的信息
|
|
|
+ // let checkedValue = checkedNameValue.filter(function (v) {
|
|
|
+ // if (v.valueId != 0) {
|
|
|
+ // return true;
|
|
|
+ // } else {
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // }).map(function (v) {
|
|
|
+ // return v.valueText;
|
|
|
+ // });
|
|
|
+ // if (checkedValue.length > 0) {
|
|
|
+ // this.setData({
|
|
|
+ // 'checkedSpecText': checkedValue.join(' ')
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // this.setData({
|
|
|
+ // 'checkedSpecText': '请选择规格数量'
|
|
|
+ // });
|
|
|
+ // }
|
|
|
|
|
|
- },
|
|
|
- getCheckedProductItem: function (key) {
|
|
|
- return this.data.productList.filter(function (v) {
|
|
|
- if (v.goods_specification_ids == key) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
+ // },
|
|
|
+ // getCheckedProductItem: function (key) {
|
|
|
+ // return this.data.productList.filter(function (v) {
|
|
|
+ // if (v.goods_specification_ids == key) {
|
|
|
+ // return true;
|
|
|
+ // } else {
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
onLoad: function (options) {
|
|
|
// 页面初始化 options为页面跳转所带来的参数
|
|
|
this.setData({
|
|
|
id: parseInt(options.id)
|
|
|
// id: 1181000
|
|
|
});
|
|
|
+
|
|
|
var that = this;
|
|
|
this.getGoodsInfo();
|
|
|
- util.request(api.CartGoodsCount).then(function (res) {
|
|
|
- if (res.errno === 0) {
|
|
|
- that.setData({
|
|
|
- cartGoodsCount: res.data.cartTotal.goodsCount
|
|
|
- });
|
|
|
+ // util.request(api.CartGoodsCount).then(function (res) {
|
|
|
+ // if (res.errno === 0) {
|
|
|
+ // that.setData({
|
|
|
+ // cartGoodsCount: res.data.cartTotal.goodsCount
|
|
|
+ // });
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
},
|
|
|
onReady: function () {
|
|
|
// 页面渲染完成
|
|
@@ -209,18 +210,18 @@ Page({
|
|
|
// 页面关闭
|
|
|
|
|
|
},
|
|
|
- switchAttrPop: function () {
|
|
|
- if (this.data.openAttr == false) {
|
|
|
- this.setData({
|
|
|
- openAttr: !this.data.openAttr
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- closeAttr: function () {
|
|
|
- this.setData({
|
|
|
- openAttr: false,
|
|
|
- });
|
|
|
- },
|
|
|
+ // switchAttrPop: function () {
|
|
|
+ // if (this.data.openAttr == false) {
|
|
|
+ // this.setData({
|
|
|
+ // openAttr: !this.data.openAttr
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // closeAttr: function () {
|
|
|
+ // this.setData({
|
|
|
+ // openAttr: false,
|
|
|
+ // });
|
|
|
+ // },
|
|
|
addCannelCollect: function () {
|
|
|
let that = this;
|
|
|
//添加或是取消收藏
|
|
@@ -247,85 +248,85 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- openCartPage: function () {
|
|
|
- wx.switchTab({
|
|
|
- url: '/pages/cart/cart',
|
|
|
- });
|
|
|
- },
|
|
|
- addToCart: function () {
|
|
|
- var that = this;
|
|
|
- if (this.data.openAttr === false) {
|
|
|
- //打开规格选择窗口
|
|
|
- this.setData({
|
|
|
- openAttr: !this.data.openAttr
|
|
|
- });
|
|
|
- } else {
|
|
|
+ // openCartPage: function () {
|
|
|
+ // wx.switchTab({
|
|
|
+ // url: '/pages/cart/cart',
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // addToCart: function () {
|
|
|
+ // var that = this;
|
|
|
+ // if (this.data.openAttr === false) {
|
|
|
+ // //打开规格选择窗口
|
|
|
+ // this.setData({
|
|
|
+ // openAttr: !this.data.openAttr
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
|
|
|
- //提示选择完整规格
|
|
|
- if (!this.isCheckedAllSpec()) {
|
|
|
- wx.showToast({
|
|
|
- image: '/static/images/icon_error.png',
|
|
|
- title: '请选择规格',
|
|
|
- mask: true
|
|
|
- });
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // //提示选择完整规格
|
|
|
+ // if (!this.isCheckedAllSpec()) {
|
|
|
+ // wx.showToast({
|
|
|
+ // image: '/static/images/icon_error.png',
|
|
|
+ // title: '请选择规格',
|
|
|
+ // mask: true
|
|
|
+ // });
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
|
|
|
- //根据选中的规格,判断是否有对应的sku信息
|
|
|
- let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey());
|
|
|
- if (!checkedProduct || checkedProduct.length <= 0) {
|
|
|
- //找不到对应的product信息,提示没有库存
|
|
|
- wx.showToast({
|
|
|
- image: '/static/images/icon_error.png',
|
|
|
- title: '库存不足',
|
|
|
- mask: true
|
|
|
- });
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // //根据选中的规格,判断是否有对应的sku信息
|
|
|
+ // let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey());
|
|
|
+ // if (!checkedProduct || checkedProduct.length <= 0) {
|
|
|
+ // //找不到对应的product信息,提示没有库存
|
|
|
+ // wx.showToast({
|
|
|
+ // image: '/static/images/icon_error.png',
|
|
|
+ // title: '库存不足',
|
|
|
+ // mask: true
|
|
|
+ // });
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
|
|
|
- //验证库存
|
|
|
- if (checkedProduct.goods_number < this.data.number) {
|
|
|
- //找不到对应的product信息,提示没有库存
|
|
|
- wx.showToast({
|
|
|
- image: '/static/images/icon_error.png',
|
|
|
- title: '库存不足',
|
|
|
- mask: true
|
|
|
- });
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // //验证库存
|
|
|
+ // if (checkedProduct.goods_number < this.data.number) {
|
|
|
+ // //找不到对应的product信息,提示没有库存
|
|
|
+ // wx.showToast({
|
|
|
+ // image: '/static/images/icon_error.png',
|
|
|
+ // title: '库存不足',
|
|
|
+ // mask: true
|
|
|
+ // });
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
|
|
|
- //添加到购物车
|
|
|
- util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST")
|
|
|
- .then(function (res) {
|
|
|
- let _res = res;
|
|
|
- if (_res.errno == 0) {
|
|
|
- wx.showToast({
|
|
|
- title: '添加成功'
|
|
|
- });
|
|
|
- that.setData({
|
|
|
- openAttr: !that.data.openAttr,
|
|
|
- cartGoodsCount: _res.data.cartTotal.goodsCount
|
|
|
- });
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- image: '/static/images/icon_error.png',
|
|
|
- title: _res.errmsg,
|
|
|
- mask: true
|
|
|
- });
|
|
|
- }
|
|
|
+ // //添加到购物车
|
|
|
+ // util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST")
|
|
|
+ // .then(function (res) {
|
|
|
+ // let _res = res;
|
|
|
+ // if (_res.errno == 0) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '添加成功'
|
|
|
+ // });
|
|
|
+ // that.setData({
|
|
|
+ // openAttr: !that.data.openAttr,
|
|
|
+ // cartGoodsCount: _res.data.cartTotal.goodsCount
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // wx.showToast({
|
|
|
+ // image: '/static/images/icon_error.png',
|
|
|
+ // title: _res.errmsg,
|
|
|
+ // mask: true
|
|
|
+ // });
|
|
|
+ // }
|
|
|
|
|
|
- });
|
|
|
- }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
|
|
|
- },
|
|
|
- cutNumber: function () {
|
|
|
- this.setData({
|
|
|
- number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
|
|
|
- });
|
|
|
- },
|
|
|
- addNumber: function () {
|
|
|
- this.setData({
|
|
|
- number: this.data.number + 1
|
|
|
- });
|
|
|
- }
|
|
|
+ // },
|
|
|
+ // cutNumber: function () {
|
|
|
+ // this.setData({
|
|
|
+ // number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // addNumber: function () {
|
|
|
+ // this.setData({
|
|
|
+ // number: this.data.number + 1
|
|
|
+ // });
|
|
|
+ // }
|
|
|
})
|