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;
            const {
                dataid,
                type,
                username,
                isleave
            } = getCurrentPages()[getCurrentPages().length - 1].data;
            content.dataid = dataid;
            content.type = type;
            content.username = username;
            content.where.isleave = isleave;
            _Http.basic({
                "id": 20231014114204,
                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.total,
                        tips: getMapText('线索总数：包含待分配、已分配线索数。'),
                        link: true
                    },
                    {
                        title: '待分配未过期线索数',
                        value: res.data.dfp,
                        tips: getMapText('待分配未过期线索数：所有线索中，待分配未过期的线索数量。'),
                        link: true
                    },
                    {
                        title: '待跟进线索数',
                        value: res.data.dgj,
                        tips: getMapText('待跟进线索数：销售线索应用中，已分配给业务员，待跟进状态的线索数量。'),
                        link: true
                    },
                    {
                        title: '跟进中线索数',
                        value: res.data.gjz,
                        tips: getMapText('跟进中线索数：销售线索应用中，已分配给业务员，跟进中状态的线索数量。'),
                        link: true
                    },
                    {
                        title: '已转化线索数',
                        value: res.data.yzh,
                        tips: getMapText("①已转化线索数：销售线索应用中，已分配给业务员，已转化状态的线索数量。") + '\n\n' + getMapText('②一条线索可进行两次转化：转化客户、转化项目，因此，已转化线索数≠转化客户线索数+转化项目线索数。'),
                        link: true
                    },
                    {
                        title: '已无效线索数',
                        value: res.data.ywx,
                        tips: getMapText("已无效线索数：销售线索应用中，已分配给业务员，已无效状态的线索数量。"),
                        link: true
                    },
                    {
                        title: '待分配已过期线索数',
                        value: res.data.ygq,
                        tips: getMapText('待分配已过期线索数：所有线索中，待分配已过期的线索数量。'),
                        link: true
                    },
                    {
                        title: '过期比例',
                        value: Math.round(((res.data.gqbl * 100) * 100) / 100) + '%',
                        tips: getMapText('过期比例=已过期线索数÷待分配线索数×100%'),
                        link: false
                    },
                    {
                        title: '转化客户线索数',
                        value: res.data.covercusomers,
                        tips: getMapText('转化客户线索数：统计有转化客户操作的线索数'),
                        link: true
                    },
                    {
                        title: '转化项目线索数',
                        value: res.data.coverproject,
                        tips: getMapText('转化项目线索数：统计有转化项目操作的线索数'),
                        link: true
                    },
                    {
                        title: '线索转化率',
                        value: Math.round(((res.data.zhl * 100) * 100) / 100) + '%',
                        tips: getMapText('线索转化率=已转化线索数÷线索总数×100%'),
                        link: false
                    },
                    {
                        title: '线索成交数',
                        value: res.data.dealqty,
                        tips: getMapText('线索成交数：转化后有下订单的线索数量'),
                        link: true
                    },
                    {
                        title: '线索成交率',
                        value: Math.round(((res.data.cjl * 100) * 100) / 100) + '%',
                        tips: getMapText('线索成交率=转化后有下订单的线索数÷线索总数×100%'),
                        link: false
                    },
                    {
                        title: '参与线索数',
                        value: res.data.joinordercluesize,
                        tips: getMapText('参与线索数：参与的并且至少有一次跟进的线索数量'),
                        link: true
                    },
                    {
                        title: '参与线索转化数',
                        value: res.data.joincoverorderclue,
                        tips: getMapText('参与线索转化数：参与的并且至少有一次跟进的有发生转化的线索数量'),
                        link: true
                    },
                    {
                        title: '参与线索转化率',
                        value: Math.round(((res.data.joinordercluezhl * 100) * 100) / 100) + '%',
                        tips: getMapText('参与线索转化率=参与线索转化数 ÷ 参与线索数 ×100%'),
                        link: false
                    },
                    {
                        title: '参与线索成交数',
                        value: res.data.joindealorderclue,
                        tips: getMapText('参与线索成交数：参与的并且至少有一次跟进的转化后有下订单的线索数量'),
                        link: true
                    },
                    {
                        title: '参与线索成交率',
                        value: Math.round(((res.data.joinordercluecjl * 100) * 100) / 100) + '%',
                        tips: getMapText('参与线索成交率=参与线索成交率 ÷ 参与线索数 ×100%'),
                        link: false
                    },
                ]
                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/Clue?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
                })
            })
        },
    }
})