<template>
    <div style="width: 100%;">
        <div style="color: #1f2937;font-weight: 600;font-size: 20px;margin-bottom: 16px;">
            热门应用
        </div>


        <div class="hotAppBlo" >
            <div class="BigBlo" v-for="(k,ind) in hotApp" :key="ind+'p'" >
                <div :class="['conBlock',ind % 2 == 0 ? 'conBlock1':'conBlock2']">
                    <div class="conBlockOne" @click="openNewWindow(k[0])" :class="[ind % 2 == 0 ? 'conW1':'conW2']">
                        <div class="conBlockTwo" :style="{bottom : ind % 2 == 0 ? '':'16px'}">
                            <img class="appImg" :src="JSON.parse(k[0].json).icon" alt="">
                            <div class="con">
                                <div class="tit">{{ k[0].name }}</div>
                                <div class="bri">
                                    <el-tooltip class="item" effect="light" :content="k[0].detail" placement="bottom">
                                        <span>
                                            {{ k[0].detail }}
                                        </span>
                                    </el-tooltip>
                                </div>
                            </div>
                        </div>
                       
                        <img class="hg" style="width: 20px;" src="../assets/img/hg1.svg" alt="">
                    </div>

                    <div style="display: flex;" :class="[ind % 2 == 0 ? 'conBlock2':'conBlock1']">
                        <div v-for="(item,index) in list(k)" class="tabCon" @click="openNewWindow(item)"  :key="index">
                                <div style="display: flex;flex-direction: column; gap: 12px;">
                                    <img class="appImg" :src="JSON.parse(item.json).icon" alt="">
                                    <div class="con">
                                        <div class="tit">{{ item.name }}</div>
                                        <div class="bri">
                                            <el-tooltip class="item" effect="light" :content="item.detail" placement="bottom">
                                                <span>
                                                    {{ item.detail }}
                                                </span>
                                            </el-tooltip>
                                        </div>
                                    </div>
                                    <img class="hg" style="width: 20px;" v-if="index == 0" src="../assets/img/hg2.svg" alt="">
                                    <img class="hg" style="width: 20px;" v-if="index == 1" src="../assets/img/hg3.svg" alt="">
                                </div>
                        </div>
                    </div>
                </div>
                <div style="display: flex;justify-content: space-between;">
                    <div class="AppTit">{{ tab[ind].name }}</div>
                    <div class="AppBri" @click="lookMore(ind)">查看全部</div>
                </div>
            </div>
           
        </div>






        <el-dialog
        :title="diaTit"
        :visible.sync="dialogVisible"
        class="moreDia"
        :close-on-click-modal="false"
        :modal="false"
        width="60%"
        :before-close="handleClose">
            <div v-loading="loading" style="display: grid;grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));gap: 16px;">
                <div v-for="(item,index) in moreList" 
                class="tabCon" @click="openNewWindow(item)"  
                :key="index" style="min-width: 308px;border: 1px #e7e7e7 solid;">
                        <div>
                            <img class="appImg" :src="JSON.parse(item.json).icon" alt="">
                            <div class="con">
                                <div class="tit">{{ item.name }}</div>
                                <div class="bri">
                                    <el-tooltip class="item" effect="light" :content="item.detail" placement="bottom">
                                        <span>
                                            {{ item.detail }}
                                        </span>
                                    </el-tooltip>
                                </div>
                            </div>
                            
                    </div>
                    <img class="hg" style="width: 20px;" v-if="index == 0" src="../assets/img/hg1.svg" alt="">
                    <img class="hg" style="width: 20px;" v-if="index == 1" src="../assets/img/hg2.svg" alt="">
                    <img class="hg" style="width: 20px;" v-if="index == 2" src="../assets/img/hg3.svg" alt="">
                </div>
            </div>
        </el-dialog>

    
    </div>
</template>

<script>
import { API_CONFIG } from "@/common/apiConfig";
import { mapGetters } from 'vuex';

    export default {
        props:['hotApp'],
        computed: {
            ...mapGetters(['userinfo']),
            list(){
                return function(val) {
                    console.log(val);
                    let newArr = val.slice(1)
                    return newArr
                }
            }
        },
        data() {
            return {
                tab:[
                    {name:'项目式学习',type:'63915be8-cefa-11ef-a2d1-005056b86db5'},
                    {name:'教学工具',type:'38111096-cc11-11ef-a2d1-005056b86db5'},
                    {name:'学习工具',type:'917a5a56-abd5-11ef-b887-005056b86db5'},
                    {name:'效率工具',type:'9b257041-abd5-11ef-b887-005056b86db5'},
                ],
                // 控制弹框展开
                dialogVisible:false,
                // 查看更多标题
                diaTit:'',
                // 查看更多弹框list
                moreList:[],
                loading:false
            }
        },
        methods: {
            openNewWindow(val) {
                console.log(val);
                
                // // 基本用法：打开指定 URL
                window.open(val.url, "_blank");
            },
            handleClose(){
                this.dialogVisible = false
            },
            lookMore(index){
                this.dialogVisible = true

                this.diaTit = this.tab[index].name
                this.loading = true
                let params = [
                    {
                        functionName: API_CONFIG.ajax_morHotApp.functionName,
                        uid: this.userinfo.userid, 
                        type: this.tab[index].type,
                        cn: this.userinfo.schoolArea ? this.userinfo.schoolArea : this.userinfo.orgArea, //学校id
                    },
                ];
                this.$ajax
                    .post(API_CONFIG.baseUrl, params)
                    .then((res) => {
                        this.moreList = res.data[0]
                        
                       
                        this.loading = false

                    })
                    .catch((err) => {
                        console.log(err);
                        this.loading = false
                        this.$message.error("获取工具数据失败");
                    });
            }
        },  
    }
</script>

<style scoped>
.hotAppBlo{
    /* display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5%; 网格间距 */
    display: flex;
    justify-content: space-between;
}
.BigBlo{
    background-color: #EFEFEF;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #BDBDBD;
    box-shadow: 0px 0px 40px 0px #0000000D;
}
.conBlock{
    display: flex;
    box-sizing: border-box;
    margin-bottom: 10px;
    border-radius: 10px;
    height: calc(100% - 20px);
    gap: 10px;
}
.conBlock1{
    flex: 1;
    flex-direction: column;
    justify-content: space-around;
    gap: 10px;
}

.AppBri{
    font-family: PingFang SC;
    font-weight: 600;
    font-size: 14px;
    line-height: 100%;
    letter-spacing: 0%;
    text-align: right;
    color: #969BA3;
    cursor: pointer;
}
.AppTit{
    font-family: PingFang SC;
    font-weight: 600;
    font-size: 16px;
    line-height: 100%;
}

.conBlockOne{
    background-color: #fff;
    border-radius: 10px;
    padding: 16px;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    justify-content: flex-start;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease; /* 统一过渡效果 */
}
.conBlockOne:hover{
    transform: translateY(-5px); /* 向上位移 */
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
.conBlockTwo{
    width: 91px;
    height: 90px;
    display: flex;
    flex-direction: column;
    position: absolute;
    gap: 12px;
}

.conBlock2{
    justify-content: space-between;
    gap: 10px;
}
.moreDia >>> .el-dialog{
    border-radius: 10px;
}
.moreDia >>> .el-dialog__body{
    height: 300px;
    overflow: auto;
    border-top: 1px #e7e7e7 solid;
}
.AppList{
    position: relative;
    flex-wrap: wrap;display: flex;
    justify-content: space-between;
    overflow: hidden;
    background: #fff;
    border: 1px rgb(243 244 246 / var(--tw-border-opacity, 1)) solid;
    border-radius: 10px;
    padding: 16px;box-sizing: border-box;
}
.conW1{
    /* height: 100%; */
    width: 100%;
    height: 50%;
    min-width: 100px;
    min-height: 100px;
    justify-content: flex-start;
}
.conW2{
    height: 100%;
    width: 7vw;
    min-width: 100px;
    justify-content: flex-end !important;
}

.tabCon{
    transition: all 0.3s ease; /* 统一过渡效果 */
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    width: 7vw;
    height: 7vw;
    min-width: 100px;
    min-height: 100px;
    background: #fff;
    padding: 26px 14px;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.tabCon:hover{
    transform: translateY(-5px); /* 向上位移 */
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
.hg {
    width: 28px !important;
    height: 28px;
    position: absolute;
    top: 0;
    right: 0;
}
.con{
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: 54px;
    justify-content: flex-end;
}
.appImg{
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}
.tit{
    color: #000000;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: PingFang SC;
    font-weight: 500;
    font-size: 14px;
    line-height: 100%;
}
.bri{
    color: #969BA3;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: PingFang SC;
    font-weight: 300;
    font-size: 10px;
    line-height: 12px;
    letter-spacing: 0%;

}


</style>