// subPackage/page/pages/valueCard/valueCard.js
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    cardList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu();
    this.getValueCardList();
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  //跳转卡详情
  onTapToCardInfo(e){
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/subPackage/page/pages/valueCardInfo/valueCardInfo?id=' + item.id,
    });
  },
  //获取有效活动列表
  getValueCardList(refresh){
    wx.showLoading({
      title: '加载中..',
    });

    wxService.post(`/merchant/superValueCardActivity/miniProgram/getPageList`).then(res => {
      if(res){
        let list = res.data.data ? res.data.data : [];
        this.data.cardList = list;
        this.setData({
          cardList: this.data.cardList
        });
      }
      wx.hideLoading();
      if(refresh){
        setTimeout(() => {
          wx.showToast({
            title: '刷新成功',
          });
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }, 300);
      }
    });
  },

  
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.getValueCardList(true);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})