// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo

wxService.page({
  /**
   * 页面的初始数据
   */
  data: {
    integralNum: 0,
    pageNo: 1,
    pageSize: 30,
    integralList: [],
    noMore: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 积分流水
    this.getIntegralList()
    // 查询会员积分信息
    this.getMemberPointInfo()
  },
  // 查询会员积分信息
  getMemberPointInfo(){
    wx.showLoading({
      title: '加载中'
    })
    wxService.get(`/member/memberPoint/getMyPointInfo`).then(res => {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading()
          this.setData({
            integralNum: data.point
          })
        }

      })
  },
  getIntegralList() {
    wx.showLoading({
      title: '加载中'
    })
    const params = {
      pageNo: this.data.pageNo,
      pageSize: this.data.pageSize
    }
    wxService.post(`/member/memberPointLog/findPage?pageNo=${this.data.pageNo}&pageSize=${this.data.pageSize}`, params).then(res=> {
      const {result,data} = res.data
      if(result == 0){
         wx.hideLoading()
         this.setData({
           integralList: data.content.slice(0,30)
         })
      }
    })
  },
  // 点击跳转至会员规则页
  handleGoMemberRulesRules() {
    wxService.router(`/pages/memberRules/memberRules?type=1`)
  },
    // 去积分商城
  handleGoIntegralMall() {
    // wxService.router(`/pages/IntegralMall/IntegralMall`)
    wxService.router(`/subPackage/page/pages/IntegralMallGoods/IntegralMallGoods`);
  },
  // 消费详情
  handleGoDetail(e) {
    const {memberId,
      expandInfo} = e.currentTarget.dataset
    // orderNo 存在 跳转订单详情
    if(expandInfo && expandInfo.orderNo){
      let orderNo = expandInfo.orderNo
      wxService.router(`/pages/consumptionDetails/consumptionDetails`).search({orderNo})
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      noMore: true
    })
  },

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

  }
})