<template>
    <div class="redList">
        <MapTitle text='红榜' />
        <div class="redListCont">
            <el-radio-group v-model="tabPosition" @change="radioChange">
                <el-radio-button v-for="(tit, index) in radioList" :key="index" :label="tit">
                    <div class="bg"></div>
                    <div class="text">{{ tit }}</div>
                </el-radio-button>
            </el-radio-group>
            <!-- 内容 -->
            <div class="radioGroupCont">
                <div class="rankingBox" ref="rankingDiv">
                    <!-- left  市级-->
                    <!-- :indicator-position="municipalList.length > 3 ? '':'none'" -->
                    <div class="leftMunicipal" v-if="carouselShow">
                        <el-carousel :height="domHeight" trigger="click" v-if="municipalList.length" :loop="true" :interval="2500"
                            direction="vertical" indicator-position="none"
                            :autoplay="municipalList.length > 3 ? true : false">
                            <!-- this.getNum(municipalList.length) -->
                            <el-carousel-item v-for="num in this.getNum(municipalList.length)" :key="num">
                                <div class="carouselBox">
                                    <el-col v-for="(item, index) in getColData(municipalList, num)" :key="index">
                                        <div class="colBg"></div>
                                        <div class="colCont">
                                            <div class="rankingIcon">
                                                <div v-if="item.ranking > 3">{{ item.ranking }}</div>
                                                <div v-else class="tab-index"
                                                    :style="{ background: colors[item.ranking] }">{{ item.ranking }}
                                                </div>
                                            </div>
                                            <div class="regionName">{{ item.name }}</div>
                                            <div class="scoreBox">
                                                <div class="score">{{ item.score }}</div>
                                                <div class="txt">分</div>
                                            </div>
                                        </div>
                                    </el-col>
                                </div>
                            </el-carousel-item>
                        </el-carousel>
                        <div v-else style="color:#ffffff">
                            暂无数据
                        </div>
                    </div>
                    <!-- center 分割线 -->
                    <div class="line"></div>
                    <!-- right  县级-->
                    <div class="rightCounty" v-if="carouselShow">
                        <el-carousel :height="domHeight" trigger="click" v-if="countyList.length" :loop="true" :interval="2500"
                            direction="vertical" indicator-position="none"
                            :autoplay="countyList.length > 3 ? true : false">
                            <el-carousel-item v-for="num in this.getNum(countyList.length)" :key="num">
                                <div class="carouselBox">
                                    <el-col v-for="(item, index) in getColData(countyList, num)" :key="index">
                                        <div class="colBg"></div>
                                        <div class="colCont">
                                            <div class="rankingIcon">
                                                <div class="tab-index" v-if="item.ranking > 3">{{ item.ranking }}</div>
                                                <div v-else class="tab-index"
                                                    :style="{ background: colors[item.ranking] }">{{ item.ranking }}
                                                </div>
                                            </div>
                                            <div class="regionName">{{ item.name }}</div>
                                            <div class="scoreBox">
                                                <div class="score">{{ item.score }}</div>
                                                <div class="txt">分</div>
                                            </div>
                                        </div>
                                    </el-col>
                                </div>
                            </el-carousel-item>
                        </el-carousel>
                        <div v-else style="color:#ffffff">
                            暂无数据
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</template>

<script>
// <!-- 红榜 -->
import MapTitle from "@/components/mapTitle/index.vue";
import Mock from "./redList";
import { mapState } from "vuex";
export default {
    components: {
        MapTitle,
    },
    data() {
        return {
            colors: {
                1: "#e45c5c",
                2: "#ea8234",
                3: "#fac858",
            },
            // radioNums: ['1', '2', '3', '4', '5'],
            radioList: ['服务强军兴军', '军民协同创新', '产业融合发展', '资源开放共享', '五大体系建设'],
            radioItem: { '服务强军兴军': '1', '军民协同创新': '2', '产业融合发展': '3', '资源开放共享': '4', '五大体系建设': '5' },
            tabPosition: '服务强军兴军',
            carouselShow: true,
            domHeight: 100,

        }
    },
    computed: {
        ...mapState({
            curDataType: (state) => state.curDataType,
        }),
        list() {
            return this.getListFormat()
            // return Mock[this.curDataType] || [];
        },
        activeNum() {
            return this.radioItem[this.tabPosition];
        },
        municipalList() {
            // console.log(this.list.municipal ? this.list.municipal[this.tabPosition] : [], 'municipalList');
            return this.list.municipal ? this.list.municipal[this.activeNum] : [];
        },
        countyList() {
            // console.log(this.list.county ? this.list.county[this.activeNum] : [], 'countyList');
            return this.list.county ? this.list.county[this.activeNum] : [];
        },
    },
    mounted() {
        this.domHeight = this.$refs.rankingDiv.clientHeight - 18 + 'px'
    },
    watch: {
        curDataType(val) {
            if (val == "2022One" || val == "2022Two ") {
                this.$nextTick(() => {
                    this.radioChange();
                })
            }
        }
    },
    created() {
        // let indexs = [1, 2, 3, 4, 5];
        // let newData = {};
        // indexs.map(num => {
        //     let lData = [];
        //     this.sjdata.map(item => {
        //         if (item[num][0] != 0) {
        //             let liName = this.radioList[num - 1];
        //             lData.push({
        //                 name: item.name,
        //                 ranking: item[num][1],
        //                 score: item[num][0]
        //             })
        //         }
        //     })
        //     // 排序
        //     let keyArr = lData.sort((a, b) => {
        //         return a.ranking - b.ranking;   
        //     });
        //     newData[num] = keyArr;

        //     // if (item.)
        // })
        // console.log(JSON.stringify(newData), '00');
        // excel 数据格式
        // let data = []
        // let newData = {};
        // indexs.map(num => {
        //     let newCod = [];
        //     data.map(item => {
        //         if (item['大类'] == num) {
        //             newCod.push({
        //                 name: item['地区'],
        //                 ranking: item['排名'],
        //                 score: item['分数'],
        //                 category: item['大类'],
        //             })
        //         }
        //     })
        //     let keyArr = newCod.sort((a, b) => {
        //         return a.ranking - b.ranking;
        //     });
        //     newData[num] = keyArr;
        // })
        // console.log(JSON.stringify(newData));
    },
    methods: {
        getListFormat() {
            let listData = {};
            const format = ["2022Three"];
            if (format.indexOf(this.curDataType) != -1) {
                const data = Mock[this.curDataType];
                listData = {
                    "municipal": {
                        "1": data.municipal.filter(item => item.class == "1"),
                        "2": data.municipal.filter(item => item.class == "2"),
                        "3": data.municipal.filter(item => item.class == "3"),
                        "4": data.municipal.filter(item => item.class == "4"),
                        "5": data.municipal.filter(item => item.class == "5"),
                    },
                    "county": {
                        "1": data.county.filter(item => item.class == "1"),
                        "2": data.county.filter(item => item.class == "2"),
                        "3": data.county.filter(item => item.class == "3"),
                        "4": data.county.filter(item => item.class == "4"),
                        "5": data.county.filter(item => item.class == "5"),
                    },
                }
            } else {
                listData = Mock[this.curDataType] || {};
            }
            return listData
        },
        radioChange(val) {
            this.carouselShow = false;
            setTimeout(() => {
                this.carouselShow = true;
            }, 30)
        },
        getColData(list, num) {
            let data = [];
            if (list.length > 3) {
                data = list.filter((item, index) => {
                    if (index > num - 2 && index < num + 2) {
                        return item;
                    }
                })
            } else {
                data = list
            }
            return data;
        },
        getNum(val) {
            return val % 3 == 0 ? (val / 3) : (Math.floor(val / 3) + 1);
        }
    }


}
</script>

<style scoped lang="scss">
.redList {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.redListCont {
    flex: 1;
    display: flex;
    max-height: calc(100% - 26px);
    flex-direction: column;

    >div {
        flex: 1;
    }
}

// 上部分
::v-deep .el-radio-group {
    margin-top: 7px;
    padding-bottom: 2px;
    max-height: 30px;
    display: flex;
    position: relative;



    .el-radio-button {
        flex: 1;
        margin-right: 8px;

        .el-radio-button__inner {
            padding: 5px 10px;
            width: 100%;
            height: 30px;
            position: relative;
            background-color: rgba(25, 125, 237, 0.15);
            border: none;
            border-radius: 4px 4px 0px 0px;

            // background-image: linear-gradient(90deg, #32a6ff 0%, #227feb 25.89%, #1055d6 58.79%, #063bc8 84.63%, #0232c4 100%);
            .bg {
                content: "";
                // background-image: linear-gradient(90deg, rgba(50, 166, 255, 100%) 0%,
                //         rgba(34, 127, 235, 100%) 25.89%,
                //         rgba(16, 85, 214, 100%) 58.79%,
                //         rgba(6, 59, 200, 100%) 84.63%,
                //         rgba(2, 50, 196, 100%) 100%);
                opacity: 30%;
                background-image: linear-gradient(90deg, #32a6ff 0%, #227feb 25.89%, #1055d6 58.79%, #063bc8 84.63%, #0232c4 100%);
                width: 100%;
                height: 100%;
                border-radius: 4px 4px 0px 0px;
                position: absolute;
                top: 0;
                left: 0;
            }

            .text {
                font-family: AlibabaPuHuiTiR-GBpc-EUC-H;
                color: #ffffff;
                font-size: 14px;
                z-index: 999;
                width: 100%;
                height: 100%;
                position: absolute;
                top: 0;
                left: 0;
                display: flex;
                align-items: center;
                justify-content: center;
            }
        }
    }

    .el-radio-button:last-child {
        margin-right: 0px;
    }

    .is-active {
        .el-radio-button__inner {
            .bg {
                opacity: 99%;
                background-image: linear-gradient(90deg, #4aacf7 0%, #3c8ee7 21.25%, #2864d1 56.22%, #1b4ac4 83.66%, #1741bf 100%);
            }
        }
    }

}

.el-radio-group::before {
    content: "";
    width: 100%;
    height: 2px;
    background-image: linear-gradient(60.53deg, #49a9f4 0%, #1844c0 100%);
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 99;
}

// 下部分
.radioGroupCont {
    max-height: calc(100% - 39px);

    .rankingBox {
        width: 100%;
        height: 100%;
        display: flex;
        padding: 18px 0px 0 0px;
        box-sizing: border-box;

        >div {
            flex: 1;
        }

        .leftMunicipal {}

        .line {
            max-width: 1px;
            height: 100%;
            border-left: 1px dashed #197ded;
            margin: 0 18px;
        }

        .rightCounty {}

        .carouselBox {
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;

            .el-col,
            .scoreBox {
                flex: 1;
                width: 100%;
                display: flex;
            }

            .el-col {
                position: relative;
                width: 100%;
                height: 100%;
                border-radius: 4px;
                overflow: hidden;

            }

            .el-col:nth-child(2n) {
                margin: 15px 0;
            }

            .colBg {
                position: absolute;
                left: 0;
                top: 0;
                opacity: 40%;
                width: 100%;
                height: 100%;
                // height: 38px;
                background-image: linear-gradient(270deg, rgba(0, 162, 255, 0.2) 0%, rgba(0, 156, 255, 0.4) 19.95%, rgba(0, 149, 255, 0.65) 48.04%, rgba(0, 144, 255, 0.84) 71.72%, rgba(0, 141, 255, 0.96) 89.75%, #008cff 100%);
            }

            .colCont {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
                height: 100%;
                display: flex;
                padding: 0 11px;
                align-items: center;
                box-sizing: border-box;

                .rankingIcon {
                    color: #ffffff;

                    .tab-index {
                        border-radius: 50%;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        width: 22px;
                        height: 22px;
                        color: #fff;
                        font-size: 16px;
                        font-family: tabTypeFace;
                        margin: 0 auto;
                    }
                }

                .regionName {
                    color: #ffffff;
                    font-size: 20px;
                    letter-spacing: 14px;
                    font-weight: bold;
                    margin-left: 15px;
                }

                .scoreBox {
                    display: flex;
                    width: auto;
                    margin-right: 10px;
                    // justify-content: flex-end;
                    position: absolute;
                    bottom: 0;
                    right: 0;
                    height: 100%;
                    align-items: center;

                    .score {
                        color: #54f2ff;
                        font-size: 18px;
                        font-weight: bold;
                    }

                    .txt {
                        margin-left: 4px;
                        color: #ffffff;
                        font-size: 12px;
                        margin-top: 6px;
                    }
                }
            }


        }
    }
}
</style>