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

Page({
    data: {
        admin: true,
        showFiltrate: false,
        content: {
            baseonproject: 1, //1项目预测，0出货开票预测
            pageNumber: 1,
            pageTotal: 1,
            pagesize: 20,
            sort: [],
            where: {
                condition: "",
                begindate: "",
                enddate: ""
            }
        },
        navList: [{
            label: "排序",
            icon: "icon-jiangxu1",
            color: "",
            width: "",
            id: "sort"
        }, {
            label: "筛选",
            icon: "icon-shaixuan",
            color: "",
            width: "",
            id: "2"
        }]
    },
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '项目成交预测管理');
        this.getList();
    },
    /* 获取列表 */
    getList(init = false) {
        if (init.detail != undefined) init = init.detail;
        let content = this.data.content;
        if (init) content.pageNumber = 1;
        if (content.pageNumber > content.pageTotal) return;

        _Http.basic({
            "id": 20230705144604,
            content
        }).then(res => {
            console.log("项目成交预测", res)
            this.selectComponent('#ListBox').RefreshToComplete();
            if (res.code != '1') return wx.showToast({
                title: res.data,
                icon: "none"
            })
            res.data = res.data.map(v => {
                v.showAmount = CNY(v.projectamount)
                return v
            })
            this.setData({
                'content.pageNumber': res.pageNumber + 1,
                'content.pageTotal': res.pageTotal,
                'content.total': res.total,
                'content.sort': res.sort,
                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
            });
        })
    },
    /* 处理搜索 */
    onSearch({
        detail
    }) {
        this.setData({
            "content.where.condition": detail
        });
        this.getList(true);
    },
    /* 顶部条件导航回调 */
    navClick({
        detail
    }) {
        this.setData({
            showFiltrate: true
        })
    },
    handleFilter({
        detail
    }) {
        if (detail.startdate) {
            this.setData({
                'content.where.begindate': detail.startdate || "",
                'content.where.enddate': detail.enddate || "",
            });
        } else {
            this.setData({
                'content.where.begindate': "",
                'content.where.enddate': "",
            });
        }
        this.getList(true)
    }
})