//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
      hasPhone: true,
      imgUrls:[
          {'url': '../../images/banner.jpg'},
          {'url': '../../images/banner.jpg'},
          {'url': '../../images/banner.jpg'},],
      autoplay: true, //是否自动轮播
      interval: 2000, //间隔时间
      duration: 500, //滑动时间
      this_week_test_info: {
          info: [
              {time: '11月01号-11月07号',url: '../../images/test_img.jpg',},
              {time: '11月08号-11月14号',url: '../../images/test_img.jpg'},
          ],
          is_this_week: true,
          ordered: false,
          is_past: false,
      },
      past_test_info: {
          info: [
              {time: '10月01号-10月07号',url: '../../images/test_img.jpg',},
              {time: '10月08号-10月14号',url: '../../images/test_img.jpg'},
              {time: '10月15号-10月21号',url: '../../images/test_img.jpg'},
          ],
          is_this_week: false,
          ordered: false,
          is_past: true,
      },
  },
  swiperChange: function (e) { //切换轮播图
      this.setData({
          currentSwiper: e.detail.current
      })
  },
  goPhoneCode() {
      wx.navigateTo({url: '/pages/index/phone-code/phone-code'})
  },
  //点击购买畅玩卡
  goBuyCard() {
      wx.navigateTo({url: './activity-detail/activity-detail'})
  },
  //点击进入活动详情
  goTestDetail(e) {
      // console.log(e);
      const current = e.currentTarget.dataset.index;
      wx.navigateTo({url: './activity-detail/activity-detail'})
  },
  //前往预约
  goAppointment (e) {
      const current = e.currentTarget.dataset.index;
      wx.navigateTo({url: './go-appointment/go-appointment'})
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})