| /** | 
|  * 通用的与后台交互的请求操作 | 
|  * | 
|  */ | 
| 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, | 
|   | 
| } |