123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 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();
- }
- })
- },
- })
|