Blame view

src/pages/scan-result/scan-result.js 3.1 KB
simon committed
1 2 3 4 5
import {
  getBindtapData,
  getQueryByUrl
} from '../../utils/util';

simon committed
6 7
let app = getApp();
Page({
simon committed
8 9
  data: {
    authorizeVisible: false,
simon committed
10 11 12
    qrCodeCode: "",
    prizeInfo: null, //扫码结果
    userInfo: {}, //用户信息
simon committed
13 14 15 16 17 18 19
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
simon committed
20 21 22 23 24 25
  onLoad(options) {

    // 手输码
    let code = options.code || "";
    if (code) {
      this.setData({
simon committed
26
        code: code
simon committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
      })
    }

    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 {
simon committed
63
        code
simon committed
64
      } = this.data;
simon committed
65
      if (code) {
simon committed
66 67 68
        app.post({
          url: app.api.scanIntegralQrcode,
          data: {
simon committed
69
            qrCodeCode: code
simon committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
          }
        }).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: '积分获取失败'
        })
      }
    });
  },

simon committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

  /**
   * 点击扫码按钮
   */
  onScanHandler() {
    let _this = this;
    wx.scanCode({
      onlyFromCamera: true,
      success(res) {
        // 扫码结果
        let q = res.result;

        // 获取积分码
        let c = getQueryByUrl("c", q);
        if (c) {
          // app.router.push({
          //   path: "scanResult",
          //   query: {
          //     code: c
          //   }
          // })
          _this.queryScanIntegralQrcode();
        } else {
          wx.showModal({
            content: '未发现积分码,换一个二维码试试',
            showCancel: false,
            success(res) {}
          })
        }
      },
      fail(err) {
        console.log("err:", err);
      }
    })
  },

simon committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  /**
   * 查看我的积分
   */
  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;
    }
  },
simon committed
169
})