const _Http = getApp().globalData.http,
    currency = require("../../../utils/currency"),
    CNY = (value, symbol = "￥", precision = 2) => currency(value, {
        symbol,
        precision
    }).format();
Page({
    data: {
        searchShow: false,
        searchValue: "",
        typeShow: false,
        tradefieldShow: false
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '营销费用明细')
        this.setData({
            content: Object.assign(options, {
                "where": {
                    "condition": "",
                    "begdate": "",
                    "enddate": ""
                },
                "pageNumber": 1,
                "pageSize": 10
            })
        })
        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": 2024062611202602,
                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,
                })
                this.onCancel()
            })
        })
    },
    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);
    }
})