const _Http = getApp().globalData.http;
Page({
    data: {
        sa_customersid: 0,
        businessInfo: {}, //工商信息
        showBusInfo: false, //是否显示工商信息
        detail: {}, //客户画像详情
        tabsList: [{
            label: "跟进记录",
            model: "#FollowUp"
        }, {
            label: "项目",
            model: "#Project"
        }, {
            label: "报价单",
            model: "#PriceSheet"
        }, {
            label: "合同",
            model: "#Contract"
        }, {
            label: "订单",
            model: "#OrderForm"
        }, {
            label: "服务",
            model: "#Serve"
        }, {
            label: "联系人"
        }],
        tabsActive: 0,
    },
    onLoad(options) {
        this.setData({
            sa_customersid: options.id,
        })
        getApp().globalData.Language.getLanguagePackage(this, '客户画像');
        this.getDetail();
        this.getGroup();
    },
    getDetail() {
        _Http.basic({
            "id": 20230713103804,
            "content": {
                "sa_customersid": this.data.sa_customersid
            }
        }).then(res => {
            console.log("客户画像详情", res)
            if (res.code != 1) return wx.showToast({
                title: res.msg,
                icon: "none"
            });
            this.setData({
                detail: res.data
            })
            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.sa_customersid;
            if (model == "#Files") init = true;
            if (total == null || init) {
                Component.getList(id, init);
            } else if (pageNumber <= pageTotal) {
                Component.getList(id, false);
            }
        }
    },
    onReachBottom() {
        this.partialRenewal();
    },
    getBusinessInfo() {
        if (this.data.businessInfo.enterprisename) return this.setData({
            showBusInfo: true
        })
        _Http.basic({
            "id": 2024060715002601,
            "content": {
                "companyName": this.data.detail.enterprisename
            }
        }).then(res => {
            console.log("工商信息", res)
            if (res.code != 1) return wx.showToast({
                title: res.msg,
                icon: "none"
            });
            if (!res.data.companyName) return getApp().globalData.Language.showToast('暂无工商信息')
            this.setData({
                businessInfo: res.data,
                showBusInfo: true
            })
        })
    },
    closeBusInfo() {
        this.setData({
            showBusInfo: false
        })
    },
    //更新团队成员
    getGroup() {
        this.selectComponent("#Group").getList()
    },
})