<template>
    <div style="width: 100%;margin-top: 30px;">
        <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">
                    <div class="conBlockOne conW1" @click="openNewWindow(k[0])" >
                        <div class="conBlockTwo">
                            <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="conBlock2">
                        <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="tabConDia" @click="openNewWindow(item)"  
                :key="index" >
                        <div style="display: flex;align-items: center;">
                            <img class="appImg"  :src="JSON.parse(item.json).icon" alt="">
                            <div class="con" style="height: auto;">
                                <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','userinfo2']),
            list(){
                return function(val) {
                    // console.log(val);
                    let newArr = val.slice(1)
                    return newArr
                }
            },
            roleUser(){
                return Object.keys(this.userinfo2).length != 0 ? this.userinfo2 : this.userinfo
            }
        },
        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.roleUser.userid, 
                        type: this.tab[index].type,
                        cn: this.roleUser.schoolArea ? this.roleUser.schoolArea : this.roleUser.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: 20px;
    
}
.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;
    flex-direction: column;
    justify-content: space-around;
}


.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: 26px 14px;
    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: 100%;
    height: 90px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    margin-top: auto; /* 将子元素推到底部 */
    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-height: 100px;
}

.tabCon{
    transition: all 0.3s ease; /* 统一过渡效果 */
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    width: 50%;
    height: 100%;
    min-height: 115px;
    background: #fff;
    padding: 26px 14px;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}
.tabConDia{
    border-radius: 10px;
    cursor: pointer;
    display: grid;grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    min-height: 80px;
    background: #fff;
    padding: 15px;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    min-width: 308px;border: 1px #e7e7e7 solid;
}

.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;
    margin-right: 10px;
}
.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;
}


</style>