const _Http = getApp().globalData.http; let pageNumber = 1, pageTotal = 1, currency = require("../../utils/currency"), CNY = value => currency(value, { symbol: "¥", precision: 2 }).format(); import { formatTime } from "../../utils/getTime"; Page({ data: { accountList: [], active: 0, ymonth: "", //年月 dateEnd: "", //日期结束时间 }, onLoad(options) { let ymonth = formatTime(new Date(), '年').split(" ")[0].slice(0, 7); this.setData({ ymonth, dateEnd: ymonth }); _Http.basic({ id: 20221008145903, "content": { pageSize: 999, type: 1, "where": { "condition": "" } } }).then(res => { console.log(res) this.setData({ accountList: res.data.map(v => { v.creditquota = CNY(v.creditquota); v.usable = CNY(currency(v.creditquota).add(v.balance)); v.balance = CNY(v.balance) return v }) }); this.getList(true); }) }, /* 切换查看账户 */ changeAccount(e) { this.setData({ active: e.detail.value || e.detail.current }); this.getList(true); }, /* 切换查看时间 */ changeDate(e) { this.setData({ ymonth: e.detail.value.replace('-', '年') }) this.getList(); }, getList(init = false) { if (init) { pageNumber = 1; pageTotal = 1 } if (pageNumber > pageTotal) return; let data = this.data.accountList[this.data.active]; _Http.basic({ "id": "20230111103403", "version": 1, "content": { pageNumber, "sys_enterpriseid": data.sys_enterpriseid, "sa_accountclassid": data.sa_accountclassid, "where": { "year": this.data.ymonth.split("年")[0], "month": this.data.ymonth.split("年")[1] } } }).then(res => { console.log("账户流水", res) if (res.msg == '成功') { let expend = 0, //收入 earning = 0; //支出 if (res.data.length) { let expendObj = res.data[0].total.find(v => v.type == 1); if (expendObj) expend = CNY(expendObj.sumamount); let earningObj = res.data[0].total.find(v => v.type == 0); if (earningObj) earning = CNY(earningObj.sumamount); } res.data = res.data.map(v=>{ v.amount = CNY(v.amount) v.showBalance = CNY(v.balance) return v }) pageNumber += 1; pageTotal = res.pageTotal; this.setData({ recordList: res.pageNumber == 1 ? res.data : this.data.recordList.concat(res.data), expend, earning }); } }) }, onReachBottom() { this.getList(); } })