const _Http = getApp().globalData.http,
    getHeight = require("../../utils/getRheRemainingHeight");

Page({
    data: {
        content: {
            "type": 0,
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": "",
                "status": "",
                "startdate": "",
                "enddate": ""
            },
            "sort": [{
                sortname: "默认",
                sorted: 1,
                sortid: 68,
                reversed: 0
            }]
        },
    },
    onLoad(options) {
        this.getList();
    },
    startSearch({
        detail
    }) {
        this.setData({
            "content.where.condition": detail
        })
        this.getList(true);
    },
    onClear() {
        this.setData({
            "content.where.condition": ""
        })
        this.getList(true);
    },
    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": 20221020143502,
            content
        }).then(res => {
            console.log("客户商机列表", res)
            this.selectComponent('#ListBox').RefreshToComplete();
            if (res.msg != '成功') return wx.showToast({
                title: res.data,
                icon: "none"
            })
            res.data = res.data.map(v => {
                v.winrate = parseFloat(v.winrate.substring(0, v.winrate.length - 1));
                return v
            })
            this.setData({
                'content.pageNumber': res.pageNumber + 1,
                'content.pageTotal': res.pageTotal,
                'content.total': res.total,
                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
            })
        })
    },
    onReady() {
        getHeight.getHeight('.total', this).then(res => this.setData({
            listHeight: res
        }));
    },
})