const app = getApp();
Page({
    data: {
        noMoney : "****",
        hiddenMoney: false,
        sumBalance: 0,
        cashBalance: 0,
        oweBalance: 0,
        cashAccountList : [],
        oweAccountList : []
    },
    onLoad: function (options) {

    },
    onShow: function () {
        if (wx.canIUse('hideHomeButton')) {
            wx.hideHomeButton()
        }
        app.$api.getSettings().then(setting => {
            if (setting.data){
                let cashAccountList = setting.data.CASH_SETTING
                let sumBalance = 0;
                let cashBalance = 0;
                cashAccountList.forEach(item => {
                    if (item.balance){
                        cashBalance = cashBalance + item.balance
                        sumBalance = sumBalance + item.balance
                    }
                })
                let oweAccountList = setting.data.OWE_SETTING
                let oweBalance = 0;
                oweAccountList.forEach(item => {
                    if (item.balance){
                        oweBalance = oweBalance + item.balance
                        sumBalance = sumBalance + item.balance
                    }
                })
                this.setData({cashAccountList,oweAccountList,cashBalance,oweBalance,sumBalance})
            }
        })
    },
    changeHidden () {
        let isHidden = this.data.hiddenMoney;
        this.setData({
            hiddenMoney : !isHidden
        });
    }

});
