const _Http = getApp().globalData.http;
Page({
    data: {
        hrid: 0,
        detail: {}, //业务员画像详情
        tabsList: [{
            label: "业绩",
            model: "#Performance"
        }, {
            label: "订单",
            model: "#OrderForm"
        }, {
            label: "销售线索",
            model: "#Clue"
        }, {
            label: "销售线索跟进明细",
            model: "#SalesFollow"
        }, {
            label: "客户",
            model: "#Client"
        }, {
            label: "客户跟进明细",
            model: "#ClientFollow"
        }, {
            label: "项目",
            model: "#Project"
        }, {
            label: "项目跟进明细",
            model: "#ProjectFollow"
        }, {
            label: "报价单",
            model: "#PriceSheet"
        }, {
            label: "合同",
            model: "#Contract"
        }],
        tabsActive: 0,
    },
    onLoad(options) {
        this.setData({
            hrid: options.id,
        })
        getApp().globalData.Language.getLanguagePackage(this, '业务员画像');
        this.getDetail();
    },
    getDetail() {
        _Http.basic({
            "id": 20230717100304,
            "content": {
                "hrid": this.data.hrid
            }
        }).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.hrid;
            if (model == "#Files") init = true;
            if (total == null || init) {
                Component.getList(id, init);
            } else if (pageNumber <= pageTotal) {
                Component.getList(id, false);
            }
        }
    },
    onReachBottom() {
        this.partialRenewal();
    }
})