reward.js 4.42 KB
import {
  getBindtapData
} from '../../utils/util';

let app = getApp();
Page({
  data: {
    authorizeVisible: false,
    total: 0,
    page: 1,
    size: 10,
    productList: [], // 产品列表
    indexInfo: {},
    userInfo: {},
    rewardList: [{
        price: 1,
        packet: "price1"
      },
      {
        price: 2,
        packet: "price2"
      },
      {
        price: 3,
        packet: "price3"
      },
      {
        price: 4,
        packet: "price4"
      },
      {
        price: 5,
        packet: "price5"
      },
      {
        price: 6,
        packet: "price6"
      },
    ]
  },
  onShareAppMessage(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
    } else {
      // 打点

    }
  },
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {
    app.stat({
      classify: "page",
      action: "reword_page",
      primaryCode: "",
    });
  },
  onShow() {
    // this.checkAuth();
  },

  /**
   * 基础方法
   * 授权完毕重拉数据用
   */
  initData() {

  },
  /**
   * 到达底部
   * 做加载更多操作
   */
  // onReachBottom() {
  //   if (this.data.dataList.length < this.data.total) {
  //     this.setData({
  //       page: this.data.page + 1
  //     });
  //     this.queryDataList();
  //   }
  // },

  // 重置页面列表 点击搜索条件时需要
  resetPage() {
    this.setData({
      page: 1,
      dataList: []
    })
  },

  /**
   * 打赏
   */
  onRewardHandler(evt) {
    let curItem = getBindtapData(evt);
    console.log("curItem:", curItem);
    curItem.packet = "ONE_CENT";
    app.post({
      url: app.api.wxPay,
      data: curItem
    }).then((res2) => {
      console.log("wxPay result:", res2);
      wx.requestPayment({
        timeStamp: res2.timeStamp + "",
        nonceStr: res2.nonceStr,
        paySign: res2.paySign,
        package: res2.package,
        signType: 'MD5',
        success(res) {
          // console.log("success:", res);
          // 支付成功
          // app.router.push({
          //   path: "rewardCompleted",
          //   query: {
          //     c: res2.orderCode // orderCode
          //   }
          // })
          wx.showModal({
            content: '赞赏成功',
            showCancel: false,
            success(res) {
              app.router.push({
                openType: "back",
              })
            }
          })
        },
        fail(res) {
          console.log("fail:", res);
          wx.showModal({
            content: '赞赏失败',
            showCancel: false,
            success(res) {
              // if (res.confirm) {
              //   console.log('用户点击确定')
              // } else if (res.cancel) {
              //   console.log('用户点击取消')
              // }
            }
          })
        }
      })
    }).catch((err) => {
      console.log("catch:", err);
    });
  },

  /**
   * 请求DataList
   */
  queryDataList() {
    return;
    return new Promise((resolve, reject) => {
      app.post({
        sid: false,
        url: app.api.dataList,
        data: {
          page: this.data.page,
          size: this.data.size,
        },
      }).then((result) => {
        let dataList = result.list;
        dataList = this.data.dataList.concat(dataList);
        this.setData({
          dataList: dataList,
          total: result.total
        })
        resolve();
      })
    });
  },

  /**
   * 检查是否授权
   */
  checkAuth() {
    let _this = this;
    wx.getSetting({
      success(res) {
        console.log("scope:", res);
        if (res.authSetting['scope.userInfo']) {
          // 已经授权
        } else {
          //用户没有授权
          wx.login({
            success(res) {
              app.store.setItem('wxcode', res.code);
              _this.showAuth();
            }
          });
        }
      }
    });
  },

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

      // 隐藏蒙层
      case "_evt_hide_mask":
        this.hideMask();
        break;

        /**
         * 重拉数据已在
         */
      case "_evt_auth_complete":
        // this.initData();
        this.hideMask();
        break;

      default:
        break;
    }
  },
})