123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- Page({
- data: {
- list:[]
- },
- onLoad: function (options) {
- var that = this;
- wx.request({
- url: 'https://yutang.web.ximengnaikang.com/api/coupons',
- method: 'GET',
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization':wx.getStorageSync('token')
- },
- success: function (res) {
- console.log(res)
- if (res.statusCode == 200) {
- that.setData({list:res.data.data})
- }
- }
- })
- },
- buy:function(e){
- console.log(e)
- var data = {
- 'coupon_id':e.currentTarget.dataset.id
- }
- wx.request({
- url: 'https://yutang.web.ximengnaikang.com/api/coupon/pay',
- method: 'POST',
- data:data,
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization':wx.getStorageSync('token')
- },
- success: function (res) {
- console.log(res)
- if (res.statusCode == 200) {
- wx.requestPayment({ //调用微信支付
- timeStamp: res.data.data.timeStamp.toString(),
- nonceStr: res.data.data.nonceStr,
- package: res.data.data.package,
- signType: res.data.data.signType,
- paySign: res.data.data.paySign,
- success(resp) {
- console.log(resp)
- wx.showToast({
- title: '购买成功',
- icon: 'none'
- })
- },
- fail(err) {
- console.log(err)
- wx.showToast({
- title: '支付失败',
- icon: 'none'
- })
- }
- })
- }
- }
- })
- },
- onReady: function () {
- },
- onShow: function () {
- },
- onHide: function () {
- },
- onUnload: function () {
- },
- onPullDownRefresh: function () {
- var that = this;
- wx.showNavigationBarLoading();
- wx.request({
- url: 'https://yutang.web.ximengnaikang.com/api/coupons',
- method: 'GET',
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization':wx.getStorageSync('token')
- },
- success: function (res) {
- console.log(res)
- if (res.statusCode == 200) {
- that.setData({list:res.data.data})
- wx.hideNavigationBarLoading();
- wx.stopPullDownRefresh();
- }
- }
- })
- },
- onReachBottom: function () {
- },
- onShareAppMessage: function () {
- }
- })
|