index.js 2.5 KB
import {
  getQueryByUrl
} from '../../utils/util';

let app = getApp();
Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    tipsRuleVisible: false,
    authorizeVisible: false,
    indexInfo: {}
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {
    // console.log("index q:", decodeURIComponent(options.q));
    let q = decodeURIComponent(options.q);
    if (q) {
      let m = getQueryByUrl("m", q);
      console.log("m:", m);
    }
    let sessionId = app.store.getItem('sessionId');
    if (sessionId) {
      app.queryIndex({
        auth: false
      }).then((result) => {
        this.setData({
          indexInfo: app.globalData.indexInfo
        })
        let {
          wishBillCode
        } = app.globalData.indexInfo;
        if (wishBillCode) {
          app.router.push({
            openType: "redirectTo",
            path: "wish"
          })
        }
      })
    }
  },
  initData() {},
  // 开始互动游戏 判断是否会员
  onStartHandler() {
    console.log("onStartHandler");
    app.queryIndex({
      auth: false
    }).then((result) => {
      this.setData({
        indexInfo: app.globalData.indexInfo
      })
      let {
        wishBillCode
      } = app.globalData.indexInfo;
      // 判断页面跳转
      let path = "createWish";
      if (wishBillCode) {
        path = "wish"
      }
      console.log("path:", path);
      app.router.push({
        path: path
      })
    })


  },
  // 显示规则页面
  onShowRuleHandler() {
    this.setData({
      tipsRuleVisible: true
    })
  },
  hideMask() {
    this.setData({
      tipsRuleVisible: false,
      authorizeVisible: false,
    })
  },

  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      case "_evt_hide_mask":
        this.hideMask();
        break;

        // 拒绝授权
      case "_evt_do_not_auth":
        this.hideMask();
        break;

      default:
        break;
    }
  },

  bindGetUserInfo(e) {
    console.log("222");
    wx.showLoading();
    this.getUserInfo(e.detail);
  },
  getUserInfo(e) {
    let _this = this;
    app.post({
      url: app.api.register,
      sid: false,
      data: {
        encryptedData: e.encryptedData,
        iv: e.iv,
        code: app.globalData.wxcode,
        tlMemberCode: app.globalData.tlMemberCode
      }
    }).then((res2) => {
      wx.hideLoading();
      _this.onStartHandler();
    }).catch((err) => {})
  },

})