// pages/handle/liist.js
import * as UTIL from '../../utils/util.js';
import * as API from '../../utils/API.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    pageNums:1,
    scrollHeight:"",
    financeList:[],
    index:0,
    array:["收支明细公开"],
    userInfoObj:[],
    date: UTIL.formatDates(new Date),
    data:{}
  },
  onConfirmReviewTime(e){
    let data = e.detail.value;
    this.setData({
      'date':data,
      'pageNums':1});
    this.getList();
  },
  paging(){
    this.setData({
      pageNums:this.data.pageNums+1,
    })
    this.getList();
  },
  getList:function(){
    let params = {
      pageNum:this.data.pageNums,
      pageSize:10,
      startNY:this.data.date,
      all:false
    }
    UTIL.httpRequest(API.URL_GET_FINANCIALLIST,params,{
      success: (res) => {
        if(res.code == 200){
          res.summary.syjc=Number(res.summary.syjc ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
            return $1 + ","; }).replace(/\.$/, "") 
          res.summary.dai=Number(res.summary.dai ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
            return $1 + ","; }).replace(/\.$/, "") 
          res.summary.jie=Number(res.summary.jie ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
            return $1 + ","; }).replace(/\.$/, "") 
          res.summary.byjc=Number(res.summary.byjc ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
            return $1 + ","; }).replace(/\.$/, "") 
          this.setData({'data':res.summary})
          if(this.data.pageNums!=1&&this.data.financeList.length<res.total){
            res.rows.map(rr => {
              rr.jieAmount =   Number(rr.jieAmount ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
                return $1 + ","; }).replace(/\.$/, "") 
              rr.daiAmount =   Number(rr.daiAmount ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
                return $1 + ","; }).replace(/\.$/, "") 
            })
            let lists = this.data.financeList.concat(res.rows)
            this.setData({financeList:lists})
          }else if(this.data.pageNums==1){
            res.rows.map(rr => {
              rr.jieAmount =   Number(rr.jieAmount ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
                return $1 + ","; }).replace(/\.$/, "") 
              rr.daiAmount =   Number(rr.daiAmount ).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
                return $1 + ","; }).replace(/\.$/, "") 
            })
            this.setData({financeList:res.rows})
          }
        }else{
          UTIL.showToastNoneIcon(res.msg);
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    let qu = wx.createSelectorQuery()
    qu.select("#top_view1").boundingClientRect()
    qu.select("#top_view2").boundingClientRect()
    qu.exec(res => {
      that.setData({
        scrollHeight:wx.getSystemInfoSync().windowHeight-res[0].height-res[0].top-res[1].height-res[1].left*2
      })
    })
    this.getList()
  },

  bindPickerChange:function(e){
    this.setData({index:e.detail.value});
  },
  switchTab:function(e){
    this.setData({
      active:e.currentTarget.dataset.gid
    })
  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

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

  }
})