const _Http = getApp().globalData.http;
Component({
    options: {
        addGlobalClass: true
    },
    data: {
        content: {
            nocache: true,
            type: 0,
            dataid: 0,
            pageNumber: 1,
            pageSize: 20,
            dataType: "1",
            dateType: '周',
            where: {
                dateType: '周',
                begindate: "",
                enddate: ""
            }
        },
        showFiltrete: false,
        filtratelist: [{
            label: "时间筛选",
            index: 1,
            showName: "name", //显示字段
            valueKey: "dateType", //返回Key
            value: "value", //选中值
            selectKey: "value",
            list: [{
                name: "本日",
                value: "日"
            }, {
                name: "本周",
                value: "周"
            }, {
                name: "本月",
                value: "月"
            }, {
                name: "本年",
                value: "年"
            }]
        }]
    },
    methods: {
        handleFilter({
            detail
        }) {
            this.setData({
                "content.dateType": detail.dateType,
                "content.where.dateType": detail.dateType,
                "content.where.begindate": detail.startdate,
                "content.where.enddate": detail.enddate,
            });
            this.getList(true);
        },
        init(type, dataid) {
            if (this.data.content.dataid != dataid) {
                this.setData({
                    'content.dataid': dataid,
                    'content.type': type
                });
                this.getList(true);
            }
        },
        getList(init = false) {
            if (init.detail != undefined) init = init.detail;
            let content = this.data.content;
            if (init) {
                content.pageNumber = 1;
                content.pageTotal = 1;
            }
            if (content.pageNumber > content.pageTotal) return;
            _Http.basic({
                "id": 20230617143104,
                content
            }).then(res => {
                console.log(content.dataType + "线索", res)
                this.selectComponent("#ListBox").setHeight(".head", this);
                this.selectComponent('#ListBox').RefreshToComplete();
                if (res.msg != '成功') return wx.showToast({
                    title: res.msg,
                    icon: "none"
                });
                content.pageNumber = res.pageNumber + 1;
                content.pageTotal = res.pageTotal;
                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    content
                })
            })
        },
        changeDataType(e) {
            const id = e.target.id;
            if (!id || this.data.content.dataType == id) return;
            this.setData({
                "content.dataType": e.target.id
            });
            this.getList(true)
        },
        openFiltrete() {
            this.setData({
                showFiltrete: true
            })
        },
        callphonenumber(e) {
            const {
                phonenumber
            } = e.currentTarget.dataset;
            if (!phonenumber) return;
            wx.makePhoneCall({
                phoneNumber: phonenumber
            })
        }
    }
})