user_spsy.js 3.23 KB
// pages/user/usersy/usersy.js
var e = getApp(),
  os = e.globalData.setting;
var ut = require('../../../utils/util');
var regeneratorRuntime = require('../../../utils/runtime.js');

Page({
  /**
   * 页面的初始数据
   */
  data: {
    qr_code_object: {},
    xp_list: null,
    iurl: os.imghost,
    page: 1,
    isLoading: 0,
    no_more: 0,
    is_use:0 //领取状态
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var h_pic = options.img;
    if (h_pic.indexOf("http") == -1) {
      h_pic = os.imghost + h_pic;
    }
    var FormId = options.FormId;
    var GradeId = options.gradeId;
    var now = ut.gettimestamp();
    this.setData({
      h_pic,
      GradeId,
      FormId,
      now,
    });
    this.requestData()
    this.getQrCode(FormId)
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {


  },
 async getQrCode(id) {
    const res = await getApp().request.promiseGet("/api/weshop/users/grade/wares/code/get", {
      data: {
        privilegeId: id,
        storeId: os.stoid,
        userId: getApp().globalData.user_id,
      },
    });
    if (res.data.code == 0 && res.data.data) {
      if(res.data.data.VerifyDate || res.data.data.VerifyNo){
        this.setData({
          is_use:1
        })
      }else{
        this.setData({
          qr_code_object: res.data.data,
        })
      }
    }
  },
  async requestData() {
    if (this.data.no_more) return false;
    if (this.data.isLoading) return false;
    this.data.isLoading = 1;
    let {
      GradeId,
      FormId,
      page,
      xp_list
    } = this.data;
    let req_data = {
      page,
      GradeId,
      FormId,
      storeId: os.stoid,
      userId: getApp().globalData.user_id,
    }
    const res = await getApp().request.promiseGet("/api/weshop/users/grade/wechat/wares/page", {
      data: req_data
    });

    if (ut.ajax_ok(res)) {
      if (res.data.data.page > 1) {
        xp_list = xp_list.concat(res.data.data.pageData);
      } else {
        xp_list = res.data.data.pageData;
      }
      this.setData({
        xp_list,
        isLoading: 0,
        no_more: 0,
      })
    } else {
      this.setData({
        xp_list: [],
        isLoading: 0,
        no_more: 0,
      })
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  /*-- 打开服务项目 --*/
  open_xp: function (e) {
    var th = this;
    var qc_com = this.selectComponent("#qc_com"); //组件的id
    qc_com.open(th.data.qr_code_object)
  },

  //--领取商品--
  async show_hxm(e) {
    let qr_code_object = this.data.qr_code_object;
    if (qr_code_object !== {}) {
      let { Number: val, BeginDate, EndDate} = qr_code_object;
      let qr_code = this.selectComponent("#qc_com");
      let obj = {
        val,
        content: "请将二维码展示给核销员,抵券更快捷",
        now: BeginDate,
        validay: EndDate,
        is_quan: 1,
      };
      qr_code.open(obj)
    }else{
      wx.showToast({
        title: "获取失败",
        icon: 'none',
        duration: 1000
      })
    }
  },

  close:function (){
    this.getQrCode(this.data.FormId)
  }
})