scan-result.js 2.52 KB
let app = getApp();
Page({
  data: {
    authorizeVisible: false,
    qrCodeCode: "",
    prizeInfo: null, //扫码结果
    userInfo: {}, //用户信息
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {

    // 扫小程序码进入
    let scene = decodeURIComponent(options.scene) || "";
    // scene = "02llmPvYl1CFN2bc"
    if (scene) {
      this.setData({
        scene
      })
    }

    // 手输码
    let code = options.code || "";
    console.log("code:", code);
    if (code) {
      this.setData({
        scene: code
      })
    }

    this.initData();
  },

  initData() {
    // 可能要拉授权
    this.queryMember().then((result) => {
      this.queryScanIntegralQrcode().then((result) => {}).catch((err) => {});
    });
  },

  /**
   * 获取会员信息
   */
  queryMember() {
    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.member,
        data: {}
      }).then((result) => {
        this.setData({
          userInfo: result
        })
        resolve();
      })
    });
  },

  /**
   * 扫积分码功能 扫积分码
   */
  queryScanIntegralQrcode() {
    return new Promise((resolve, reject) => {
      let {
        scene
      } = this.data;
      if (scene) {
        app.post({
          url: app.api.scanIntegralQrcode,
          data: {
            qrCodeCode: scene
          }
        }).then((result) => {
          this.setData({
            prizeInfo: result
          })
          if (result.qrCodeStatus != 1) {
            wx.setNavigationBarTitle({
              title: '积分获取失败'
            })
          }
        }).catch((err) => {
          this.setData({
            prizeInfo: {}
          })
          wx.setNavigationBarTitle({
            title: '积分获取失败'
          })
        });
      } else {
        this.setData({
          prizeInfo: {}
        })
        wx.setNavigationBarTitle({
          title: '积分获取失败'
        })
      }
    });
  },

  /**
   * 查看我的积分
   */
  onMyIntegralHandler(evt) {
    app.router.push({
      openType: "reLaunch",
      path: "userCenter"
    })
  },

  // 隐藏蒙层
  hideMask() {
    this.setData({
      authorizeVisible: false,
    })
  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      // 授权完毕
      case "_evt_auth_complete":
        this.initData();
        this.hideMask();
        break;

      default:
        break;
    }
  },
})