const _Http = getApp().globalData.http,
    currency = require("../../utils/currency"),
    CNY = (value, symbol = "￥", precision = 2) => currency(value, {
        symbol,
        precision
    }).format();
Page({
    data: {
        id: "20231017110204",
        searchShow: false,
        searchValue: "",
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '订单未回款明细')
        this.setData({
            content: JSON.parse(options.content),
            siteid: wx.getStorageSync('userMsg').siteid
        })
        this.getList()
    },
    changeSearchShow() {
        this.setData({
            searchShow: !this.data.searchShow
        })
        this.selectComponent('#ListBox').automaticSetHei();
    },
    getList(init = false) {
        _Http.init(this.data.content, init).then(content => {
            _Http.basic({
                "id": this.data.id,
                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.price = CNY(v.price)
                    v.amount = CNY(v.amount)
                    v.outOrderamount = CNY(v.outOrderamount)
                    v.invoiceamount = CNY(v.invoiceamount)
                    v.unwriteoffamount = CNY(v.unwriteoffamount)
                    v.expanded = false;
                    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,
                })
            })
        })
    },
    changeExpanded(e) {
        const {
            index
        } = e.currentTarget.dataset;
        this.setData({
            [`list[${index}].expanded`]: !this.data.list[index].expanded
        })
    },
    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);
    }
})