// pages/integralDetail/integralDetail.js
var http = require("../../../utils/http.js");
var util = require("../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pages: 0,
    current: 1,
    size: 10,
    scoreDetails: [],  //积分明细列表
    isAll: false,
    userInfo: {}, //用户积分等级信息
    scoreExplain: {},  //积分说明
    showPop: false,  //攻略弹框显隐
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //请求积分明细
    this.getScoreDetails()
    //获取用户积分等级信息
    this.getUserScore()
    //积分攻略
    this.getScoreExplain()
  },

  /**
   * 获取用户积分等级信息
   */
  getUserScore: function() {
    var param = {
      url: '/p/user/userInfo',
      method: 'GET',
      data: {
        current: this.data.current,
        size: 10
      },
      callBack: (res) => {
        this.setData({
          userInfo : res
        })
      }
    }
    http.request(param)
  },

  /**
   * 请求积分明细
   */
  getScoreDetails: function() {
    wx.showLoading()
    var param = {
      url: '/p/score/page',
      method: 'GET',
      data: {
        current: this.data.current,
        size: 10
      },
      callBack: (res) => {
        wx.hideLoading()

        let list = []
        if (res.current == 1) {
          list = res.records
        } else {
          list = this.data.scoreDetails
          list = list.concat(res.records)
        }
        this.setData({
          scoreDetails: list,
          pages: res.pages,
          current: res.current
        });
        console.log(this.data.scoreDetails)
      }
    }
    http.request(param);
  },

  /** 
   * 触底加载下一页 
   */
  getNextPage() {
    console.log('触底加载')
    if (this.data.pages > this.data.current) {
      this.setData({
        current: this.data.current + 1
      })
      this.getScoreDetails()
    } else {
      this.setData({
        isAll: true
      })
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('钩子：触底加载')
    this.getNextPage()
  },

  /**
   * 积分攻略
   */
  getScoreExplain: function() {
    var param = {
      url: '/p/score/getScoreQuestion',
      method: 'GET',
      data: {},
      callBack: (res) => {
        res.paramValue = util.formatHtml(res.paramValue);
        this.setData({
          scoreExplain: res
        })
        console.log(this.data.scoreExplain)
      }
    };
    http.request(param)
  },

  /**
   * 积分攻略弹框显隐
   */
  clikcPop: function() {
    var showPop = !this.data.showPop
    this.setData({
      showPop
    })
  },


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

  },

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

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

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

  },

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

  },

  

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

  }
})