const _Http = getApp().globalData.http;

Page({
    data: {
        contactsid: 0,
        tabsActive: 0, //tabs 选中项
        tabsList: [{
            label: "详细信息",
            icon: "icon-tabxiangxixinxi1"
        }, {
            label: "跟进动态",
            icon: "icon-tabgenjinjilu"
        }],
    },
    onLoad(options) {
        if (options.contactsid) {
            this.setData({
                contactsid: options.contactsid
            });
            this.getDetail();
        }
    },
    /* 获取详情信息 */
    getDetail() {
        _Http.basic({
            "id": 20221026110602,
            "content": {
                "contactsid": this.data.contactsid
            }
        }).then(res => {
            console.log("联系人详情", res)
            const item = res.data;
            this.setData({
                detail: item,
                briefs: [{
                    label: "单位",
                    value: item.enterprisename
                }, {
                    label: "手机号码",
                    value: item.phonenumber
                }/* , {
                    label: "最近跟进时间",
                    value: ""
                } */],
                list1: [{
                    label: "手机号码",
                    value: item.phonenumber
                }, {
                    label: "性别",
                    value: item.sex
                }, {
                    label: "生日",
                    value: item.birthday
                }, {
                    label: "邮箱",
                    value: item.email
                }, {
                    label: "部门",
                    value: item.depname
                }, {
                    label: "职位",
                    value: item.position
                }, {
                    label: "备注",
                    value: item.remarks
                }]
            });
        })
    },
    //tabs 切换
    tabsChange({
        detail
    }) {
        this.setData({
            tabsActive: detail
        });
        this.partialRenewal();
    },
    //局部数据更新 tabs
    partialRenewal(init = false) {
        const id = this.data.detail.contactsid;
        let model = '';
        let name = this.data.tabsList[this.data.tabsActive].label;
        switch (name) {
            case "跟进动态":
                model = "#Trace"
                break;
        };
        if (model) {
            // 确定好模块ID total = null 是第一次加载 加载数据
            // init是新增或修改需要清数据
            let Component = this.selectComponent(model);
            const {
                total,
                pageNumber,
                pageTotal
            } = Component.data.content;
            if (total == null || init) {
                Component.getList(id, init);
            } else if (pageNumber <= pageTotal) {
                Component.getList(id, false);
            }
        }
    },
    //更新标签
    getTags() {
        this.selectComponent("#Tags").getTags();
    },
    //更新团队成员
    getGroup() {
        this.selectComponent("#Group").getList();
    },
    onReachBottom() {
        this.partialRenewal();
    },
    onShareAppMessage() {}
})