/*
* 加入購物車
*/
goCat: function (isPay) {
var that = this;
var productSelect = this.data.productValue[this.data.attrValue];
//打開屬性
if (this.data.attrValue) {
//默認選中了屬性,但是沒有打開過屬性彈窗還是自動打開讓用戶查看默認選中的屬性
this.setData({ 'attribute.cartAttr': !this.data.isOpen ? true : false })
} else {
if (this.data.isOpen)
this.setData({ 'attribute.cartAttr': true })
else
this.setData({ 'attribute.cartAttr': !this.data.attribute.cartAttr });
}
//只有關閉屬性彈窗時進行加入購物車
if (this.data.attribute.cartAttr === true && this.data.isOpen == false) return this.setData({ isOpen: true });
//如果有屬性,沒有選擇,提示用戶選擇
if (this.data.productAttr.length && productSelect === undefined && this.data.isOpen == true) return app.Tips({ title: '請選擇屬性' });
if (!that.data.cart_num || parseInt(that.data.cart_num) <= 0) return app.Tips({ title: '請輸入購買數量' });
postCartAdd({
productId: that.data.id,
cartNum: that.data.cart_num,
uniqueId: productSelect !== undefined ? productSelect.unique : '',
'new': isPay === undefined ? 0 : 1,
}).then(res => {
that.setData({ isOpen: false, 'attribute.cartAttr': false });
if (isPay)
wx.navigateTo({ url: '/pages/order_confirm/index?cartId=' + res.data.cartId });
else
app.Tips({ title: '添加購物車成功', icon: 'success' }, function () {
that.getCartCount(true);
});
}).catch(err => {
return app.Tips({ title: err });
});
},
點擊之后一點反應都沒有