1
935090232@qq.com
2020-12-01 611146e69aaa62296cf84f2ccb5aca5ebba17677
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * 通用的与后台交互的请求操作
 *
 */
const app=getApp();
var api = require('service-api.js');
var util = require('util.js');
 
 
 
 
/**
 * 领取优惠券
 */
function receiveCoupon(e) {
    var couponId = e.currentTarget.dataset.couponId;
    //获取用户信息
    util.request({
        method: "GET",
        api: api.coupon.receiveCoupon + couponId,
        callback: function (data) {
            wx.showToast({
                title: data.info,
                icon: 'success',
                duration: 2000
            })
        }
    });
}
 
 
/**在购物车中加入产品 */
function addShoppingCar(id, num, callBack) {
 
    //查询产品,判断sku数量,加入购物车,动画,跳转产品页并打开sku选择页
    let param = {
        "cartSkuId": id,
        "cartNumber": num,
        "shopId":app.shopInfo.id,
    };
    //直接加入购物车
    util.request({
        method: "POST",
        api: api.goods.saveShoppingCart, data: param,
        callback: function (data) {
            console.log("添加购物成功")
            wx.setTabBarBadge({
                index: 3,
                text: data.mapInfo.userCartCount + "",
            })
            if (callBack) {
              callBack(data.mapInfo.userCartCount);
            }
        }
    });
 
}
 
//刷新购物车数量
function refreshUserCartCount() {
 
    util.request({
        method: "POST",
        data:{shopId:app.shopInfo.id},
        api: api.goods.getUserCartCount+app.shopInfo.id,
        callback: function (data) {
            if (data.mapInfo.userCartCount != 0) {
                wx.setTabBarBadge({
                    index: 3,
                    text: data.mapInfo.userCartCount + "",
                })
            } else {
                wx.removeTabBarBadge({index: 3});
            }
 
        }
    });
}
 
 
module.exports = {
 
    receiveCoupon: receiveCoupon,
    addShoppingCar: addShoppingCar,
    refreshUserCartCount: refreshUserCartCount,
 
}