const app = getApp(); var WxParse = require('../../wxParse/wxParse.js'); Page({ data: { arr: [], arrIndex: 0, tabSwiper: [], content: [], show: false, num: 1, info: '', yuName: '', color: '#ccc', jiaColor: 'blue', maxnum: '', coupon_id:'', coupon:'' }, onLoad: function () { }, tabbar: function (e) { this.setData({ arrIndex: e.currentTarget.dataset.index, num: 1, color: '#ccc', jiaColor: 'blue', }) }, swiper: function (e) { console.log(e) this.setData({ arrIndex: e.detail.current }) }, onShow:function(){ var that = this; wx.request({ url: 'https://yutang.web.ximengnaikang.com/api/company', method: 'GET', header:{ 'Authorization':wx.getStorageSync('token') }, success: function (res) { console.log(res) var article = res.data.data.company.body; WxParse.wxParse('article', 'html', article, that, 5); that.setData({ arr: res.data.data.company.tabs, tabSwiper: res.data.data.seats, content: res.data.data.company }) wx.setStorageSync('items', res.data.data.seats) } }) wx.request({ url: 'https://yutang.web.ximengnaikang.com/api/user/coupons', method: 'GET', header: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization':wx.getStorageSync('token') }, success: function (res) { console.log(res.data.data.length) if (res.statusCode == 200 && res.data.data.length>=1) { that.setData({coupon:res.data.data[0],coupon_id:res.data.data[0].id}) } } }) }, yuyue: function (e) { console.log(e) var item = e.currentTarget.dataset.item; var yuName = e.currentTarget.dataset.yuname; var maxnum = e.currentTarget.dataset.num; var userInfo = wx.getStorageSync('userInfo'); console.log(userInfo) if (userInfo == undefined || userInfo == '' || userInfo.nickname==null) { wx.showModal({ title: '用户授权', content: '此功能需要获取您的昵称等公开信息,请到小程序的设置中打开用户权限!', cancelText: '下次再说', confirmText: '去授权', success: function (res) { if (res.confirm) { wx.navigateTo({ url: '../login/login', }) } } }) return; }else if(userInfo.mobile==null){ wx.showModal({ title: '手机号授权', content: '此功能需要获取您的手机号,请到小程序的设置中打开用户权限!', cancelText: '下次再说', confirmText: '去授权', success: function (res) { if (res.confirm) { wx.navigateTo({ url: '../login/login?mobile=true', }) } } }) return; } else { console.log(yuName) this.setData({ show: true, info: item, yuName, maxnum }) } }, quxiao: function () { this.setData({ show: false, num: 1, color: '#ccc', jiaColor: 'blue', }) }, queren: function () { var that = this; var data = { 'number': this.data.num, 'day': this.data.info.date, 'seat_id': this.data.info.site_id, 'coupon_id':this.data.coupon_id } wx.request({ url: 'https://yutang.web.ximengnaikang.com/api/storeOrder', 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) { that.setData({ show: false, num: 1, color: '#ccc', jiaColor: 'blue', }) 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' }) wx.request({ url: 'https://yutang.web.ximengnaikang.com/api/company', method: 'GET', header:{ 'Authorization':wx.getStorageSync('token') }, success: function (res) { console.log(res) that.setData({ tabSwiper: res.data.data.seats, }) } }) }, fail(err) { console.log(err) wx.showToast({ title: '支付失败', icon: 'none' }) } }) } } }) }, jian: function () { this.setData({ num: this.data.num - 1 }) if (this.data.num <= 1) { this.setData({ color: '#ccc', num: 1 }) return; } else { this.setData({ color: 'blue', jiaColor: 'blue' }) } }, jia: function () { this.setData({ num: this.data.num + 1 }) if (this.data.num == this.data.maxnum) { this.setData({ jiaColor: '#ccc', num: this.data.maxnum }) return; } else { this.setData({ jiaColor: 'blue', color: 'blue' }) } }, onPullDownRefresh: function () { wx.showNavigationBarLoading(); var that = this; wx.request({ url: 'https://yutang.web.ximengnaikang.com/api/user/coupons', method: 'GET', header: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization':wx.getStorageSync('token') }, success: function (res) { console.log(res.data.data.length) if (res.statusCode == 200 && res.data.data.length>=1) { that.setData({coupon:res.data.data[0],coupon_id:res.data.data[0].id}) } } }) wx.request({ url: 'https://yutang.web.ximengnaikang.com/api/company', method: 'GET', header:{ 'Authorization':wx.getStorageSync('token') }, success: function (res) { console.log(res) that.setData({ tabSwiper: res.data.data.seats, }) wx.showToast({ title: '刷新成功', icon:'none' }) wx.hideNavigationBarLoading(); wx.stopPullDownRefresh(); } }) }, })