Authored by 李奇

添加购物车功能迁移

... ... @@ -42,5 +42,33 @@ export default {
method: 'smallapp.product.intro'
}, params)
});
},
/**
* 加入购物车
* @param params
* @returns {*}
*/
addToShoppingCart(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.add',
}, params)
});
},
/**
* 获取购物车商品数
* @param params
* @returns {*}
*/
getCountInCart(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.count',
}, params)
});
}
};
... ...
... ... @@ -22,6 +22,7 @@ Page(Object.assign({
login: false,
shopId: 0,
productSkn: 0,
countInCart: 0,
productName: '',
marketPrice: '',
salesPrice: '',
... ... @@ -110,6 +111,7 @@ Page(Object.assign({
this.supportService();
this.productIntro();
this.preferList();
this._getCountInCart();
}, 500);
yas = new Yas(app);
... ... @@ -608,7 +610,32 @@ Page(Object.assign({
duration: 1000
});
},
goPayment: function(e) {
goCart: function() {
router.go('shoppingCart');
},
addToCart: function() {
if (this.data.productOnlyProvideByYohoAPP ||
this.data.productOnlyProvideByYohoStore ||
this.data.productNotForSale) {
return wx.showToast({
title: '该商品暂时不支持当前小程序购买,请到Yoho!Buy有货查看',
icon: 'none',
duration: 2000
});
}
if (this.data.storage_sum === 0) {
return;
}
this.setData({buyImmediate: false});
if (app.getUid()) {
Picker.pickerShow(this);
}
},
// 确定选择
confirmChoose: function(e) {
if (!this.data.colorSelected) {
return wx.showToast({
title: '请选择颜色',
... ... @@ -627,10 +654,56 @@ Page(Object.assign({
this._dataReport();
if (this.data.buyImmediate) {
this.payNow(e);
return this._payNow(e);
}
this._addToCart();
},
_addToCart() {
let params = {
product_sku: this.data.selectedSKU > 0 ? this.data.selectedSKU : 0,
buy_number: this.data.pickerData.view.buyNumber,
edit_product_sku: 0,
promotion_id: '',
goods_type: 0,
selected: 'Y'
};
detailModel.addToShoppingCart(params)
.then(res => {
if (res.code === 200) {
this._getCountInCart();
Picker.pickerHide(this);
wx.showToast({
title: res.message,
icon: 'none',
duration: 2000
});
} else {
return Promise.reject();
}
})
.catch(err => {
wx.showToast({
title: err && err.message || '加入购物车失败,请稍后重试',
icon: 'none',
duration: 2000
});
});
},
_getCountInCart: function() {
detailModel.getCountInCart({product_skn: this.data.productSkn})
.then(res => {
if (res.code === 200) {
this.setData({
countInCart: res.data.cart_goods_count,
});
} else {
return Promise.reject();
}
}).catch(() => {});
},
payNow: function() {
_payNow: function() {
router.go('cartEnsure', {
productSku: this.data.selectedSKU,
buyNumber: this.data.pickerData.view.buyNumber
... ...
... ... @@ -122,15 +122,22 @@
<!--<button wx:else class="buy-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfoLogin">立即购买</button>-->
<!--</view>-->
<!--</block>-->
<view class="img-action">
<view class="img-action" bindtap="goCart">
<view class="badge" hidden='{{countInCart===0}}'>{{countInCart}}</view>
<image class="image" src="../../../static/images/cart-btn.png" mode="widthFix"></image>
</view>
<view class="img-action">
<image class="image" src="../../../static/images/store-btn.png" mode="widthFix"></image>
</view>
<view class="txt-action add">加入购物车</view>
<view wx:if="{{login}}" class="txt-action add" bindtap="addToCart">加入购物车</view>
<view wx:else class="txt-action add" bindtap="addToCart">
<button class="add-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfoLogin" plain="true">加入购物车</button>
</view>
<view wx:if="{{login}}" class="txt-action buy" bindtap="buyImmediate">立即购买</view>
<button wx:else class="buy-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfoLogin">立即购买</button>
<view wx:else class="txt-action buy" bindtap="buyImmediate">
<button class="buy-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfoLogin" plain="true">立即购买</button>
</view>
</view>
... ...
... ... @@ -469,12 +469,27 @@
}
.fixed-bottom-actions .img-action {
position: relative;
display: block;
height: 100rpx;
width: 130rpx;
text-align: center;
}
.fixed-bottom-actions .img-action .badge {
position: absolute;
right: 30rpx;
width: 30rpx;
height: 30rpx;
margin-top: 4rpx;
color: #fff;
font-size: 16rpx;
line-height: 30rpx;
text-align: center;
border-radius: 50%;
background-color: #d0021b;
}
.fixed-bottom-actions .img-action .image {
width: 50rpx;
height: 50rpx;
... ... @@ -495,11 +510,27 @@
background-color: #444444;
}
.fixed-bottom-actions .txt-action.add .add-btn {
height: 100rpx;
color: #ffffff;
font-size: 28rpx;
line-height: 100rpx;
border: none;
}
.fixed-bottom-actions .txt-action.buy {
margin-left:3rpx;
background-color: #d0021b;
}
.fixed-bottom-actions .txt-action.buy .buy-btn {
height: 100rpx;
color: #ffffff;
font-size: 28rpx;
line-height: 100rpx;
border: none;
}
.bottom-tip-view{
flex-direction:row;
width: 100%;
... ... @@ -515,17 +546,6 @@
font-size: 28rpx;
}
.bottom{
display: flex;
position: fixed;
flex-direction:row;
width: 100%;
height: 100rpx;
bottom: 0;
background-color: #fff;
border-top: solid 1rpx rgb(242, 242, 242);
}
.shoppint-like-icon{
position: relative;
width: 44rpx;
... ... @@ -536,39 +556,6 @@
padding-right: 28rpx
}
.shoppint-cart-icon{
position: relative;
width: 160rpx;
background-color: #fff;
vertical-align: center;
justify-content: center;
text-align: center;
}
.shoppint-cart-icon-image{
position: absolute;
width: 50rpx;
height: 30rpx;
align-items: center;
z-index: 10;
margin-top: 30rpx;
margin-left: -30rpx;
}
.badge {
position: absolute;
z-index: 9999;
right: 15px;
width: 15px;
height: 15px;
line-height: 15px;
background: #d0021b;
color: #fff;
border-radius: 50%;
text-align: center;
font-size: 8px;
margin-top: 15rpx;
}
.not-for-sale{
flex: 1;
... ...
... ... @@ -69,7 +69,7 @@
</scroll-view>
<view wx:if="{{pickerData.sourceType == 'goodsDetail' && pickerData.view.buyButtonEnable}}"
class="{{pickerData.view.buyButtonEnable?'buyButton':'buyButtonDisable'}}" bindtap="goPayment"
class="{{pickerData.view.buyButtonEnable?'buyButton':'buyButtonDisable'}}" bindtap="confirmChoose"
data-type='{{pickerData}}'>
<text class="title">确定</text>
</view>
... ...
... ... @@ -17,6 +17,7 @@ export default {
orderList: {path: '/pages/home/order/order', auth: true, report: {paramKey: 'type'}},
orderDetail: {path: '/pages/home/order/detail', auth: true, report: {paramKey: 'orderCode'}},
orderExpress: {path: '/pages/home/order/express/express', auth: true, report: {paramKey: 'order_code'}},
shoppingCart: {path: '/pages/cart/cart', type: jump.switchTab, auth: true},
cartEnsure: {path: '/pages/cart/ensure/ensure', auth: true, report: {paramKey: 'productSku'}},
cartInvoice: {path: '/pages/cart/invoice/invoice'},
paySuccess: {path: '/pages/pay/success', type: jump.redirectTo, auth: true},
... ...