const _Http = getApp().globalData.http;
Page({
    data: {
        total: 0,
        isShowType: false
    },
    onLoad(options) {
        let content = {
            nocache: true,
            pageNumber: 1,
            pageTotal: 1,
            ...JSON.parse(options.data)
        }
        this.setData({
            content,
            isShowType: ["sys_task", "sat_orderclue", "sa_customers", "sa_project"].includes(content.ownertable)
        });
        this.getList()
        getApp().globalData.Language.getLanguagePackage(this, '同步跟进内容');
    },
    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;

        this.selectComponent("#ListBox").setHeight(".total", this);
        _Http.basic({
            "id": 20231207130504,
            content
        }).then(res => {
            this.selectComponent('#ListBox').RefreshToComplete();
            console.log("跟进列表", res)
            this.setData({
                total: res.total
            })
            if (res.code != '1') return wx.showToast({
                title: res.data,
                icon: "none"
            })
            if (content.ownertable != 'sat_orderclue' && this.data.isShowType) res.data = res.data.map(v => {
                v.contentList = v.content.split("\n").map(v => {
                    let obj = v.split("：")
                    return {
                        label: obj[0],
                        value: obj[1] || ""
                    }
                })
                return v
            })
            this.setData({
                'content.pageNumber': res.pageNumber + 1,
                'content.pageTotal': res.pageTotal,
                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
            })

        })
    },
    onClick(e) {
        _Http.selectSync(e.currentTarget.dataset.item, this.data.content.ownertable)
    }
})