const util = require("../../../utils/util.js");
Page({
  data: {
    array: ['全部','待入账','已入账','审核未通过'],
    index: 0,
    finishedText:'',
    finished: false,
    pageSize:10,
    pageIndex:1,
    list: [],
    moeny: 0,
  },
  onLoad: function (options) {
    this.getList(true)
    this.getMoney()
  },
  onReachBottom: function () {
    var self = this;
    if(self.data.finished) return false;
    setTimeout(function () {
      self.setData({ pageIndex: self.data.pageIndex + 1 });
      self.getList(false);
    }, 1000);
  },
  getList(load) {
    let that = this;
    util.ajax({
      func: "v2/userMoney/list",
      data: {
        pageSize: that.data.pageSize,
        pageIndex: that.data.pageIndex,
        status: that.data.index - 1,
      },
      load: true
    }, function (res) {
      if (res.code == 0) {
        res.data.list = res.data.list.map((item) => {
          if(item.price.toString().indexOf('-') != -1) {
            return {...item, signStatus: false}
          } else {
            return {...item, signStatus: true}
          }
        })
        let list = load ? res.data.list : [...that.data.list, ...res.data.list];
        that.setData({list});
        if (that.data.list.length >= res.data.total || that.data.list.length < that.data.pageSize) {
          that.setData({ finishedText: that.data.list.length < that.data.pageSize ? '' : "~~已经到底了~~", finished:true})
        } else {
          
        }
      } else {
        util.showTips(res.reason);
      }
    });
  },
  getMoney() {
    let that = this;
    util.ajax({
      func: "v2/userMoney/balance",
      data: {},
      load: false
    }, function (res) {
      if (res.code == 0) {
        that.setData({money:util.toMoney(res.data)})
      } else {
        util.showTips(res.reason);
      }
    });
  },
  bindChildChange(e) {
    this.setData({index:e.detail.value,pageIndex: 1})
    this.getList(true)
  }
})