const _Http = getApp().globalData.http;
Component({
    options: {
        addGlobalClass: true,
    },
    properties: {
        update: {
            type: Function
        }
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
            this.setData({
                dates: this.data.dates.map(v => {
                    v.name = getApp().globalData.Language.getMapText(v.value);
                    v.color = v.value == this.data.content.dateType ? "#3874F6" : "";
                    return v
                }),
                "content.dataid": wx.getStorageSync('userMsg').userid,
                "content.username": wx.getStorageSync('userMsg').name,
            })
        }
    },
    data: {
        "content": {
            dateType: "本年",
            type: 0,
            "where": {
                isleave: "1"
            }
        },
        detaShow: false,
        dates: [{
            value: "全部"
        }, {
            value: "本年"
        }, {
            value: "本季"
        }, {
            value: "本月"
        }, {
            value: "上月"
        }, {
            value: "去年"
        }, ],
    },
    methods: {
        getList() {
            let content = this.data.content;
            _Http.basic({
                "id": 20231018110404,
                content
            }).then(res => {
                console.log("项目数据概况", res)
                if (res.code != '1') return wx.showToast({
                    title: res.msg,
                    icon: "none"
                })
                const getMapText = getApp().globalData.Language.getMapText;
                let list = [{
                        title: '项目总数',
                        value: res.data.totalqty,
                        tips: getMapText('项目总数：统计所有项目的数量'),
                        link: true
                    },
                    {
                        title: '报备项目数',
                        value: res.data.reportProject,
                        tips: getMapText('报备项目数：统计已报备的项目数量'),
                        link: true
                    },
                    {
                        title: '进行中项目数',
                        value: res.data.dealProject,
                        tips: getMapText('进行中项目数：进行中状态的项目数量'),
                        link: true
                    },
                    {
                        title: '项目成交数',
                        value: res.data.dealProject,
                        tips: getMapText('项目成交数：统计有关联审核过的订单的项目数量'),
                        link: true
                    },
                    {
                        title: '项目成交率',
                        value: res.data.cjl + '%',
                        tips: getMapText('项目成交率=有关联审核订单的项目数÷项目总数×100%'),
                        link: false
                    },
                    {
                        title: '项目失败数',
                        value: res.data.failedproject,
                        tips: getMapText('项目失败数：已失败状态的项目数量'),
                        link: true
                    },
                    {
                        title: '项目失败率',
                        value: Math.round(((res.data.sbl) * 100) / 100) + '%',
                        tips: getMapText('项目失败率=已失败项目数÷项目总数×100%'),
                        link: false
                    },
                    {
                        title: '参与项目数',
                        value: res.data.joinProject,
                        tips: getMapText('参与项目数：参与的并且至少有一次跟进的项目数量'),
                        link: true
                    },
                    {
                        title: '参与项目成交数',
                        value: res.data.joinDealProject,
                        tips: getMapText('参与项目成交数：参与的并且至少有一次跟进的项目的成交数量'),
                        link: true
                    },
                    {
                        title: '参与项目成交率',
                        value: Math.round(((res.data.joinDealProjectcjl) * 100) / 100) + '%',
                        tips: getMapText('参与项目成交率=参与项目成交数 ÷ 参与项目数 ×100%'),
                        link: false
                    },
                ];

                try {
                    list = list.concat(res.data.projecttype.map(v => {
                        return {
                            title: v.value,
                            value: v.qty,
                            tips: "",
                            link: true
                        }
                    }))
                } catch (error) {

                }
                this.setData({
                    list,
                    content
                })
                this.onCancel()
            })
        },
        showTips(e) {
            const {
                tips
            } = e.currentTarget.dataset;
            wx.showModal({
                content: tips,
                showCancel: false,
                confirmText: getApp().globalData.Language.getMapText('确定'),
            })
        },
        toDetail(e) {
            const {
                item
            } = e.currentTarget.dataset,
                content = this.data.content;
            content.typemx = item.title;
            wx.navigateTo({
                url: '/salesPanel/dataOverview/OverviewAndDetails/project?content=' + JSON.stringify(content),
            })
        },
        openDateType() {
            this.setData({
                detaShow: true
            })
        },
        dateOnSelect(event) {
            const {
                value
            } = event.detail;
            if (this.data.content.dateType == value) return this.onCancel();
            this.setData({
                "content.dateType": value,
                dates: this.data.dates.map(item => {
                    item.color = item.value == value ? "#3874F6" : "";
                    item.loading = item.value == value ? true : false;
                    return item
                }),
            })
            this.getList(true)
        },
        onCancel() {
            this.setData({
                actionShow: false,
                detaShow: false,
                list: this.data.list.map(item => {
                    item.loading = false;
                    return item
                }),
                dates: this.data.dates.map(item => {
                    item.loading = false;
                    return item
                })
            })
        },
    }
})