<template>
    <div :class="showDatePicker? 'homeMobeilMask': ''">
    </div>
    <div class="homeMobeilPage">
        <van-nav-bar title="年度单位评级" />
        <div class="mobeilVant">
            <div class="mobeilTop">
                <div class="topLeft">
                    <!-- <van-icon name="star" size="20" /> -->
                    <img :src="logoImg" alt="">
                    <span>全业务域考评系统</span>
                </div>
                <div class="topRight">
                    <span>系统导航</span>
                    <img :src="daohangImg" alt="" @click="chooseMenu">
                </div>
            </div>
            <div class="mobeilMain">
                <div class="rankingList">
                    <span>{{showDate}}年度排行榜</span>
                    <img :src="dateImg" @click="changeDate" alt="">
                    <van-date-picker
                        v-model="currentDate"
                        title="选择年份"
                        :columns-type="['year']"
                        @confirm="confirmFn"
                        @cancel="cancelFn"
                        v-if="showDatePicker"
                        />
                </div>
                <div class="mainModel" v-for="(it, index) in cupDataYearArr" :key="index">
                    <div class="mainModelTit">
                        <div class="mainModelTit_left">
                            <img :src="huodianImg" alt="" v-if="it.nameEn === 'HD'">
                            <img :src="shuidianImg" alt="" v-else-if="it.nameEn === 'SD'">
                            <img :src="xinnengyuanImg" alt="" v-else-if="it.nameEn === 'XNYFG'">
                            <img :src="guojiImg" alt="" v-else-if="it.nameEn === 'GJYW'">
                            <img :src="meidianImg" alt="" v-else-if="it.nameEn === 'MDYTH'">
                            <span>{{it.name}}</span>
                        </div>
                        <img :src="moreImg" alt="" class="mainModelTit_right" @click="enterDetail(it.nameEn)">
                    </div>
                    <div class="mainModelMsg">
                        <div class="mainTwo">
                            <!-- <div class="echartsNum" :style="it.echartsData.allNum < 10 ? 'left:56px': 'left: 65px'">{{it.echartsData.allNum}}</div> -->
                            <div :id="'pieChart'+index" style="height: 100px;width: 100%"></div>
                            <el-row>
                                <el-col :span="12">
                                    <span class="mainTwoComColor" style="background: #F65177;"></span>
                                    <span class="mainTwoComTit">A级</span>
                                </el-col>
                                <el-col :span="12">
                                    <span class="mainTwoComColor" style="background: #50C14E;"></span>
                                    <span class="mainTwoComTit">B级</span>
                                </el-col>
                                <el-col :span="12">
                                    <span class="mainTwoComColor" style="background: #5093E1;"></span>
                                    <span class="mainTwoComTit">C级</span>
                                </el-col>
                                <el-col :span="12">
                                    <span class="mainTwoComColor" style="background: #9DA5BE;"></span>
                                    <span class="mainTwoComTit">D级</span>
                                </el-col>
                            </el-row>
                        </div>
                        <div class="mainThree">
                            <div class="headerNameTit">
                                <div class="headerNameTit_left">
                                    <span>单位名称</span>
                                </div>
                                <div class="headerNameTit_right">
                                    <span>级别</span>
                                    <span>得分</span>
                                </div>
                            </div>
                            <div style="display: flex" v-for="(item, index) in it.tableDatas" :key="index">
                                <div class="mainThreeMsg">
                                    <img :src="item.img" alt="">
                                    <div class="msgProgress">
                                        <span>{{item.company}}</span>
                                        <span>{{item.grade}}</span>
                                        <span>{{item.score}}</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import logoImg from '../assets/mobeilImg/logo.png'
import daohangImg from '../assets/mobeilImg/daohang.png'
import dateImg from '../assets/mobeilImg/date.png'
import huodianImg from '../assets/mobeilImg/huodian.png'
import shuidianImg from '../assets/mobeilImg/shuidian.png'
import xinnengyuanImg from '../assets/mobeilImg/xinnengyuan.png'
import meidianImg from '../assets/mobeilImg/meidian.png'
import guojiImg from '../assets/mobeilImg/guoji.png'
import moreImg from '../assets/mobeilImg/more.png'
import cup1 from '../assets/getwayImg/cup1.png'
import cup2 from '../assets/getwayImg/cup2.png'
import cup3 from '../assets/getwayImg/cup3.png'

import {apiGetappAnnualRankingData} from '../api/api'
export default {
    data() {
        return {
            forecastDatas: [],
            expendData: ['0'],
            openeds: [],
            routeTags: [],
            userName: '',
            logoImg: logoImg,
            daohangImg: daohangImg,
            dateImg: dateImg,
            huodianImg: huodianImg,
            shuidianImg: shuidianImg,
            xinnengyuanImg: xinnengyuanImg,
            meidianImg: meidianImg,
            guojiImg: guojiImg,
            moreImg: moreImg,
            showDatePicker: false,
            currentDate: [],
            showDate: '',
            cupDataYearArr: []
        }
    },
    created() {
        this.showDate = new Date().getFullYear()
        this.getyearCompanyList()
    },
    methods: {
        //获取年度单位考评数据
        getyearCompanyList() {
            let that = this
            that.cupDataYearArr = []
            let params = {
                binSection: '',
                year: that.showDate
            }
            apiGetappAnnualRankingData(params).then(datas =>{
                if (datas && datas.data) {
                    let secArr = ['HD', 'SD', 'XNYFG', 'GJYW', 'MDYTH']
                    secArr.forEach(item =>{
                        for(let i in datas.data.year) {
                            let it = datas.data.year[i]
                            if (item === i) {
                                let gradeA = 0
                                let gradeB = 0
                                let gradeC = 0
                                let gradeD = 0
                                let tableData = []
                                it.forEach((iv, index) =>{
                                    if (index < 3) {
                                        let obj = iv
                                        if (index === 0) {
                                            obj.img = cup1
                                        } else if (index === 1) {
                                            obj.img = cup2
                                        } else if (index === 2) {
                                            obj.img = cup3
                                        }
                                        tableData.push(iv)
                                    }
                                    if (iv.grade === 'A') {
                                        gradeA ++
                                    } else if (iv.grade === 'B') {
                                        gradeB ++
                                    } else if (iv.grade === 'C') {
                                        gradeC ++
                                    } else if (iv.grade === 'D') {
                                        gradeD ++
                                    }
                                })
                                let obj = {
                                    name: item === 'HD' ? '火电板块' : item === 'SD' ? '水电板块' :item === 'XNYFG' ? '新能源' : item === 'GJYW' ? '海外业务':'煤电一体化',
                                    nameEn: item,
                                    echartsData: {
                                        allNum: it.length,
                                        echarts: [
                                            { value: gradeA, name: 'A类' },
                                            { value: gradeB, name: 'B类' },
                                            { value: gradeC, name: 'C类' },
                                            { value: gradeD, name: 'D类' }
                                        ]
                                    },
                                    tableDatas: tableData,
                                    allTableData: it,
                                    section: [],
                                    sectionAll: []
                                }
                                that.cupDataYearArr.push(obj)
                            }
                        }
                    })
                    that.cupDataYearArr.forEach(item =>{
                        for(let i in datas.data.season) {
                            let it = datas.data.season[i]
                            if (item.nameEn === i) {
                                it.forEach((iv, index) =>{
                                    if (index<3) {
                                        item.section.push(iv)
                                    }
                                })
                                item.sectionAll = it
                            }
                        }
                    })
                    this.$nextTick(() =>{
                        that.getEcharts(that.cupDataYearArr)
                    })
                }
            })
        },
        getEcharts(datas) {
            datas.forEach((item, index) =>{
                this.getEchartsData(item.echartsData.echarts, 'pieChart'+index)
            })
        },
        chooseMenu() {
            this.$router.push({ path: "/menu"})
        },
        enterDetail(type) {
            this.$router.push({ path: "/yearConpanyDetail", query: {binSection: type, year: this.showDate}})
        },
        getEchartsData(data, name) {
            let total = 0
            data.forEach(it =>{
                total += it.value
            })
            let option = {
                color: ['#F65177', '#50C14E', '#5093E1', '#9DA5BE'],
                tooltip: {
                    trigger: 'item'
                },
                series: [
                    {
                    name: '年度榜',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        show: true,
                        position: 'center',
                        formatter: () =>{
                            return total
                        },
                        fontSize: 16,
                        fontWeight: 600
                    },
                    labelLine: {
                        show: false
                    },
                    data: data
                    }
                ]
            };
            // 基于准备好的dom，初始化echarts实例
            let dom = document.getElementById(name);
            dom.removeAttribute("_echarts_instance_")
            let myChart = this.$echarts.init(dom);
            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize()
            })
        },
        changeDate() {
            this.showDatePicker = true
        },
        confirmFn(val) {
            this.showDate = val.selectedValues[0]
            console.log('riqi', val)
            this.getyearCompanyList()
            this.cancelFn()
        },
        cancelFn() {
            this.showDatePicker = false
        }
    }
}
</script>

<style lang="less">
.homeMobeilMask{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 111;
}
.homeMobeilPage {
    background-color: #184FB4;
    .van-nav-bar{
        width: 100%;
        background-color: #184FB4;
        color: #fff;
        position: fixed;
        top: 0;
    }
    .mobeilVant{
        height: 100%;
        margin-top: 45px;
        border-radius: 10px 10px 0 0;
        background-color: #fff;
        .mobeilTop{
            height: 60px;
            display: flex;
            justify-content: space-around;
            .topLeft{
                display: flex;
                img{
                    width: 24px;
                    height: 28px;
                    position: relative;
                    top: 18px;
                    left: -10px;
                }
                span{
                    font-family: MicrosoftYaHei;
                    font-weight: 600;
                    font-size: 16px;
                    color: #444950;
                    line-height: 60px;
                }
            }
            .topRight{
                display: flex;
                img{
                    width: 22px;
                    height: 18px;
                    position: relative;
                    top: 21px;
                    left: 5px;
                }
                span{
                    font-family: MicrosoftYaHei;
                    font-weight: 400;
                    font-size: 14px;
                    color: #545960;
                    line-height: 60px;
                    margin-right: 5px;
                }
            }
        }
        .mobeilMain{
            // height: 50px;
            background-color: #ededf5;
            padding: 17px 20px;
            .rankingList{
                width: 100%;
                height: 45px;
                background: #184FB4;
                border-radius: 5px;
                margin-bottom: 15px;
                span{
                    display: inline-block;
                    width: 85%;
                    text-align: center;
                    font-family: MicrosoftYaHei;
                    font-weight: 400;
                    font-size: 16px;
                    color: #fff;
                    margin-right: 5px;
                    position: relative;
                    top: 12px;
                    left: 8vw;
                }
                img{
                    width: 22px;
                    height: 18px;
                    position: relative;
                    top: 15px;
                    right: 5px;
                }
                .van-picker{
                    z-index: 222;
                }
            }
            .mainModel{
                background: #fff;
                border-radius: 5px;
                .mainModelTit{
                    height: 40px;
                    padding: 0 15px;
                    display: flex;
                    justify-content: space-between;
                    border-bottom: 1px solid #96A1B4;
                    .mainModelTit_left{
                        img{
                            width: 20px;
                            height: 20px;
                            position: relative;
                            top: 10px;
                            right: 5px;
                        }
                        span{
                            display: inline-block;
                            font-family: MicrosoftYaHei;
                            font-weight: 500;
                            font-size: 16px;
                            color: #545960;
                            margin-right: 5px;
                            position: relative;
                            top: 7px;
                        }
                    }
                    .mainModelTit_right{
                        width: 14px;
                        height: 14px;
                        position: relative;
                        top: 14px;
                        right: 5px;
                    }
                }
                .mainModelMsg{
                    width: 100%;
                    display: flex;
                    margin-bottom: 10px;
                    .mainTwo{
                        width: 35%;
                        border-right: 1px solid #E1E3EA;
                        position: relative;
                        .echartsNum{
                            font-size: 16px;
                            font-weight: 600;
                            position: absolute;
                            top: 40px;
                            left: 60px;
                        }
                        .mainTwoComColor{
                            display: inline-block;
                            width: 6px;
                            height: 6px;
                            border-radius: 20px;
                            margin-left: 15px;
                            position: relative;
                            top: -1px;
                        }
                        .mainTwoComTit{
                            font-size: 14px;
                            display: inline-block;
                            margin-left: 5px;
                        }
                    }
                    .mainThree{
                        width: 65%;
                        padding-top: 5px;
                        border-right: 1px solid #E1E3EA;
                        position: relative;
                        .headerNameTit{
                            display: flex;
                            // justify-content: space-between;
                            padding: 0px 15px;
                            margin-bottom: 5px;
                            font-size: 14px;
                            color: #414141;
                            .headerNameTit_left{
                                width: 65%;
                            }
                            .headerNameTit_right{
                                width: 40%;
                                span:nth-child(1){
                                    display: inline-block;
                                    width: 60%;
                                }
                                span:nth-child(2){
                                    display: inline-block;
                                    width: 40%;
                                }
                            }
                        }
                        .mainThreeMsg{
                            display: flex;
                            margin: 0 10px;
                            width: calc(100% - 36px);
                            height: 33px;
                            background: #F6F7FA;
                            margin-bottom: 8px;
                            padding-left: 8px;
                            padding-right: 8px;
                            padding-top: 2px;
                            border-radius: 5px;
                            img{
                                width: 20px;
                                height: 20px;
                                position: relative;
                                top: 5px;
                                margin-right: 10px;
                            }
                            .msgProgress{
                                margin-top: 5px;
                                display: flex;
                                width: 100%;
                                span{
                                    font-size: 14px;
                                    font-family: Microsoft YaHei;
                                }
                                span:nth-child(1){
                                    display: inline-block;
                                    width: 60%;
                                    font-weight: 400;
                                    color: #666;
                                    // margin-right: 10px;
                                    overflow: hidden;
                                    text-overflow: ellipsis;
                                    white-space: nowrap;
                                }
                                span:nth-child(2){
                                    display: inline-block;
                                    width: 25%;
                                    font-weight: 600;
                                    color: #F65177;
                                }
                                span:nth-child(3){
                                    display: inline-block;
                                    width: 10%;
                                    font-weight: 600;
                                    color: #666;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>