const _Http = getApp().globalData.http;
Component({
    options: {
        addGlobalClass: true
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    properties: {

    },
    data: {
        dateType: "本年",
        showList: false,
        list: [],
        "isAll": 1,
        "content": {
            "nocache": true,
            "pageNumber": 1,
            "pageTotal": 1,
            "total": null,
            "where": {
                begdate: "",
                enddate: "",
            }
        },
        followSize: 0,
    },
    methods: {
        getList(id, init) {
            let content = this.data.content;
            content.hrid = id;
            content.type = this.data.isAll;
            if (init) {
                content.pageNumber = 1;
                content.total = null;
            }
            if (!this.data.showList && content.total != null) return;
            if (content.pageNumber > content.pageTotal) return;
            _Http.basic({
                "id": 20230717100704,
                content
            }).then(res => {
                console.log("业务员销售线索跟进记录", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                content.pageNumber = res.pageNumber + 1;
                content.pageSize = res.pageSize;
                content.pageTotal = res.pageTotal;
                content.total = res.total;
                try {
                    res.data = res.data.map(item => {
                        item.names = item.contacts.map((v) => v.name)
                        return item
                    })
                } catch (error) {

                }

                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    content,
                    id: id,
                });
                this.selectComponent("#TimeRange").onCancel()
            })
        },
        changeDate({
            detail
        }) {
            let isAll = 99;
            switch (detail.dateType) {
                case '全部':
                    isAll = 0
                    break;
                case '本年':
                    isAll = 1
                    break;
                case '本季':
                    isAll = 2
                    break;
                case '本月':
                    isAll = 3
                    break;
            }
            this.setData({
                dateType: detail.dateType,
                isAll,
                "content.where.begdate": detail.begdate || "",
                "content.where.enddate": detail.enddate || ""
            })
            this.getList(this.data.id, true)
        }
    }
})