import {
  get,
} from '../../utils/http';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    total: 0,
    page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCaseList()
  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.page * 10 < this.data.total) {
      this.getCaseList(++this.data.page)
    }
  },

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

  },

  // /api/case
  /**
   * 获取案例列表
  */
  getCaseList() {
    let { list,page } = this.data;
    get('api/case',{
      page,
      limit: 10
    },(res) => {
      list.push(...res.data.list)
      this.setData({ list,total:res.data.total })
    })
  }
})