Authored by 李奇

购物车引入

import api from '../../common/api';
export default {
/**
* 购物车数据
* @param params
* @returns {*}
*/
getCartData(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.queryCart'
}, params)
});
}
};
... ...
import cartModel from '../../models/cart/cart';
const app = getApp();
const router = global.router;
Page({
data: {
},
onLoad() {
},
onShow() {
this.getCartData();
},
goShopping() {
router.go('home');
},
getCartData() {
cartModel.getCartData({uid: app.getUid()})
.then(res => {
if (res.code === 200 && res.data) {
this._resolveCartData(res.data);
} else {
return Promise.reject();
}
})
.catch(() => {});
},
_resolveCartData() {
}
});
... ...
<view class="container">
<view>hello from the shopping cart!</view>
</view>
<block wx:if="{{curShoppingCartData.has_product_in_shop_cart}}">
我是购物车内容
</block>
<block wx:else>
<view class='empty-cart'>
<image src='../../static/images/empty_cart.png' class='empty-img'></image>
<text class='empty-desc'>购物车空空如也\n去挑选中意的商品</text>
<view class='shopping-btn' bindtap='goShopping'>去逛逛</view>
</view>
</block>
\ No newline at end of file
... ...
.empty-cart .empty-img {
display: block;
width: 204rpx;
height: 200rpx;
margin: 300rpx auto 0 auto;
}
.empty-cart .empty-desc {
display: block;
width: 400rpx;
margin: 60rpx auto 0 auto;
color: #444;
font-size: 26rpx;
line-height: 1.4;
text-align: center;
}
.empty-cart .shopping-btn {
width: 360rpx;
padding: 30rpx;
margin: 60rpx auto 0 auto;
color: #fff;
font-size: 28rpx;
text-align: center;
border-radius: 4rpx;
background-color: #444;
}
... ...