// pages/statementsDetail/index.js
const config = require('../../config/config.js')
const Http = require('../../utils/HttpBasics.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    billId:'',
    billData:{
      receiveMoneyStr: '',
      payMoneyStr: '',
      balanceStr: ''
    },
    openIf01:false,
    openIf02: false,
    payIf:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      billId:options.id
    })
    this.getData(options.id);
  },
  changeStatus01(){
    this.setData({
      openIf01 : !this.data.openIf01
    })
  },
  changeStatus02() {
    this.setData({
      openIf02: !this.data.openIf02
    })
  },
  getData(id){
    let postData = {
      id
    }
    Http.get({
      url: config.api.findSettleById,
      data: postData
    })
      .then(res => {
        let data = res.data;
        data.receiveMoneyStr = (data.receiveMoney/100).toFixed(2)
        data.payMoneyStr = (data.payMoney / 100).toFixed(2)
        data.balanceStr = (Math.abs(data.balance) / 100).toFixed(2)
        data.receiveBillIds.map((item,index)=>{
          item.receivePayStr = (item.receivePay / 100).toFixed(2)
        })
        data.payBillIds.map((item, index) => {
          item.receivePayStr = (item.receivePay / 100).toFixed(2)
        })
        console.log(data,888888)
        this.setData({
          billData:data,
          payIf:Number(data.balance)>0?true:false
        })
      })
      .catch(err => {
        wx.hideLoading();
        wx.showToast({
          title: err.message,
          icon: 'none',
          duration: 2000,
          mask: false
        });
      });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },
})