const _Http = getApp().globalData.http,
    currency = require("../../utils/currency"),
    CNY = (value, symbol = "￥", precision = 2) => currency(value, {
        symbol,
        precision
    }).format();

Page({
    data: {
        content: {
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": "",
            }
        }
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, "账户流水明细")
        this.setData({
            "content.sa_accountclassid": options.sa_accountclassid,
            "content.sys_enterpriseid": options.sys_enterpriseid,
            "content.where.sys_enterpriseid": options.enddate,
        })
        this.getList(true)
    },
    getList(init = false) {
        _Http.init(this.data.content, init).then(content => {
            _Http.basic({
                "id": 20221022161304,
                content
            }).then(res => {
                console.log("客户账户余额明细", res)
                this.selectComponent('#ListBox').automaticSetHei();
                
                this.selectComponent('#ListBox').RefreshToComplete();
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                res.data = res.data.map(v => {
                    v.amount = CNY(v.amount)
                    return v
                })
                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    "content.pageNumber": res.pageNumber + 1,
                    "content.pageSize": res.pageSize,
                    "content.pageTotal": res.pageTotal,
                    "total": res.total,
                })
            })
        })
    },
    onSearch() {
        this.data.content.where.condition = this.data.searchValue;
        this.getList(true);
    },
    onChange(event) {
        this.setData({
            searchValue: event.detail
        })
    },
    onClear() {
        this.setData({
            searchValue: "",
            "content.where.condition": ""
        })
        this.getList(true);
    }
})