import { API } from './../../../utils/network/api'

const api = new API()
const app = getApp()
Page({
  data: {
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '收益明细 ', //导航栏 中间的标题
    },
    height: app.globalData.height, 
    list: [],
    date: "",
    current_page: 0,
    total: 0,
    per_page: 0,
    last_page: 0
  },
  onReachBottom() {
    console.log('===触底了！！===');
    if(this.data.current_page < this.data.last_page){//最后一页时停止分页
      this.getDoctorAccountInfo()
    }
  },
  onLoad(option){
    let date = option.date;
    console.log(date);
    this.setData({
      date: date
    })
  },
  onHide(){
    this.setData({
      list: [],
      date: "",
      current_page: 0,
      total: 0,
      per_page: 0,
      last_page: 0
    })
  },
  onShow(){
    this.getDoctorAccountInfo();
  },
  getDoctorAccountInfo(){
    let list = this.data.list
    let params = {};
    params.page = this.data.current_page + 1;
    params.date = this.data.date;
    api.getDoctorAccountInfo(params).then(response => {
      console.log(response);
      this.setData({
        list: list.concat(response.data.data),
        current_page: response.data.current_page,
        total: response.data.total,
        per_page: response.data.per_page,
        last_page: response.data.last_page,
      })
    }).catch(errors => {console.error(errors);})
  }
})