const _Http = getApp().globalData.http;
Page({
    data: {
        sys_phonebookid: 0,
        detail: {}, //联系人画像详情
        tabsList: [{
            label: "跟进记录",
            model: "#FollowUp"
        }, {
            label: "关联客户",
            model: "#Client"
        }, {
            label: "关联项目",
            model: "#Project"
        }, {
            label: "报价单",
            model: "#PriceSheet"
        }, {
            label: "订单",
            model: "#OrderForm"
        }],
        tabsActive: 0,
    },
    onLoad(options) {
        this.setData({
            sys_phonebookid: options.id,
        })
        getApp().globalData.Language.getLanguagePackage(this, '联系人画像');
        this.getDetail();
    },
    getDetail() {
        _Http.basic({
            "id": 20240605102804,
            "content": {
                "sys_phonebookid": this.data.sys_phonebookid
            }
        }).then(res => {
            console.log("联系人画像详情", res)
            if (res.code != 1) return wx.showToast({
                title: res.msg,
                icon: "none"
            });
            this.setData({
                detail: res.data[0]
            })
            this.partialRenewal();
        })
    },
    //tabs 切换
    tabsChange({
        detail
    }) {
        this.setData({
            tabsActive: detail
        });
        this.partialRenewal();
    },
    //局部数据更新 tabs
    partialRenewal(init = false) {
        const model = this.data.tabsList[this.data.tabsActive].model;
        if (model) {
            const Component = this.selectComponent(model),
                {
                    total,
                    pageNumber,
                    pageTotal
                } = Component.data.content,
                id = this.data.sys_phonebookid;
            if (model == "#Files") init = true;
            if (total == null || init) {
                Component.getList(id, init);
            } else if (pageNumber <= pageTotal) {
                Component.getList(id, false);
            }
        }
    },
    onReachBottom() {
        this.partialRenewal();
    },
    showSubdateInfo() {
        getApp().globalData.Language.modeBoxPrompts('未跟进天数=当前查询时间-最近跟进时间-节假日')
    }
})