const _Http = getApp().globalData.http;
Page({
    data: {},
    onLoad(options) {
        getApp().globalData.Language.getLanguagePackage(this, '数据总览')
        this.setData({
            content: JSON.parse(options.content)
        })
        this.getList()

        let page = getCurrentPages()[getCurrentPages().length - 2],
            model = page.selectComponent("#organization"),
            organization = this.selectComponent("#organization"),
            {
                username,
                isleave
            } = page.data;
        organization.setData({
            ...model.data
        })
        this.setData({
            username,
            isleave
        })
    },
    getList(init = false) {
        _Http.init(this.data.content, init).then(content => {
            console.log("content", content)
            _Http.basic({
                "id": 20241008144104,
                content
            }).then(res => {
                console.log("res", res)
                this.selectComponent('#ListBox').automaticSetHei();
                this.selectComponent('#ListBox').RefreshToComplete();
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                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,
                })
            })
        })
    },
    handleFilter({
        detail
    }) {
        if (detail.name == "close") return;
        if (detail.name == 'reset') {
            this.selectComponent("#organization").setData({
                isleave: 1
            })
            this.selectComponent("#organization").initDepAndUser()
            this.setData({
                "content.dataid": wx.getStorageSync('userMsg').userid,
                "content.type": 0,
                "content.where.isleave": 1,
                username: wx.getStorageSync('userMsg').name,
                isleave: 1
            })
        } else {
            let active = this.selectComponent("#organization").data.result,
                isleave = this.selectComponent("#organization").data.isleave;
            let type = active.userid ? 0 : 1,
                dataid = type == 0 ? active.userid : active.sa_saleareaid
            this.setData({
                "content.dataid": dataid,
                "content.type": type,
                "content.where.isleave": isleave,
                "content.username": active.name
            })
        }
        this.getList(true);
    },
    openFiltrate() {
        this.setData({
            showFiltrate: true
        })
    },
})