const _Http = getApp().globalData.http,
    currency = require("../../utils/currency"),
    CNY = (value, symbol = "￥", precision = 2) => currency(value, {
        symbol,
        precision
    }).format();

Page({
    data: {
        sa_projectid: 0,
        detail: {},
        tabsList: [{
            label: "项目评估",
            model: "#ProjectAssessment"
        }, {
            label: "跟进记录",
            model: "#FollowUp"
        }, {
            label: "关联客户",
            model: "#Client"
        }, {
            label: "竞争对手",
            model: "#Competitor"
        }, {
            label: "产品配置",
            model: "#Product"
        }, {
            label: "报价单",
            model: "#PriceSheet"
        }, {
            label: "合同",
            model: "#Contract"
        }, {
            label: "订单",
            model: "#OrderForm"
        }, {
            label: "服务",
            model: "#Serve"
        }, {
            label: "联系人"
        }],
        tabsActive: 1,
    },
    onLoad(options) {
        this.setData({
            sa_projectid: options.id,
        })
        getApp().globalData.Language.getLanguagePackage(this, '项目画像');
        this.getDetail();
        this.getGroup();
    },
    getDetail() {
        _Http.basic({
            "id": 20230715111704,
            "content": {
                "sa_projectid": this.data.sa_projectid
            }
        }).then(res => {
            console.log("项目画像详情", res)
            if (res.code != 1) return wx.showToast({
                title: res.msg,
                icon: "none"
            });
            res.data = res.data.map(v => {
                v.signamount_due = CNY(v.signamount_due)
                return v
            })
            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.sa_projectid;
            if (model == "#Files") init = true;
            if (total == null || init) {
                Component.getList(id, init);
            } else if (pageNumber <= pageTotal) {
                Component.getList(id, false);
            }
        }
    },
    onReachBottom() {
        this.partialRenewal();
    },
    //更新团队成员
    getGroup() {
        this.selectComponent("#Group").getList()
    },
    showSubdateInfo() {
        getApp().globalData.Language.modeBoxPrompts('未跟进天数=当前查询时间-最近跟进时间-节假日')
    }
})