// subPackage/page/pages/orderBenefit/orderBenefit.js
const app = getApp()
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')
const { memberId } = wx.getStorageSync('_baseUserInfo')

wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    pageSize: 10,
    totalPages: 0,
    orderBenefitList:[],
    id:'',
    type:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu()
    if(options){
      if(options.id){
        this.setData({
          id: options.id
        })
      }
      if (options.type){
        this.setData({
          type: options.type
        })
      }
     
    }

    this.getOrderBenefit(1, 10)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  getOrderBenefit(pageNum, pageSize){
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    let params = {
      userId: memberId,
      type: this.data.type,
      sourceId: this.data.id
    }
    wxService.post(`/marketing/awardRecord/queryAward?pageNum=${pageNum}&pageSize=${pageSize}`, params).then(res => {
      if (res) {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading()
          this.setData({
            orderBenefitList: this.data.pageNo == 1 ? [...data.content] : [...this.data.orderBenefitList, ...data.content],
            totalPages: data.totalPages
          }, () => {
          })
        }
      }
    })
  },

  /**
    * 页面上拉触底事件的处理函数
    */
  onReachBottom: function () {
    if (this.data.pageNum < this.data.totalPages) {
      this.setData({
        pageNum: this.data.pageNum + 1,
      }, () => {
        this.getOrderBenefit(this.data.pageNum, 10)
      })
    }
  },

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