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

        <div class="conBlock" v-for="(k,ind) in hotApp" :key="ind+'p'">
            <div style="display: flex;justify-content: space-between;margin-bottom: 16px;">
                <div style="color: #1f2937;font-weight: 600;font-size: 18px;margin-bottom: 16px;">{{ tab[ind].name }}</div>
                <div @click="lookMore(ind)" style="color: #0354d7;font-size: 14px;cursor: pointer;">查看全部</div>
            </div>
            <div style="display: grid;grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));gap: 16px;">
                <div v-for="(item,index) in k" class="tabCon" @click="openNewWindow(item)"  :key="index" style="min-width: 308px;">
                        <div class="AppList">
                            <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 class="hg">
                                <img style="width: 20px;" v-if="index == 0" src="../assets/img/hg1.svg" alt="">
                                <img style="width: 20px;" v-if="index == 1" src="../assets/img/hg2.svg" alt="">
                                <img style="width: 20px;" v-if="index == 2" src="../assets/img/hg3.svg" alt="">
                            </div>
                    </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;">
                        <div class="AppList">
                            <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 class="hg">
                                <img style="width: 20px;" v-if="index == 0" src="../assets/img/hg1.svg" alt="">
                                <img style="width: 20px;" v-if="index == 1" src="../assets/img/hg2.svg" alt="">
                                <img style="width: 20px;" v-if="index == 2" src="../assets/img/hg3.svg" alt="">
                            </div>
                    </div>
                </div>
            </div>
        </el-dialog>

    
    </div>
</template>

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

    export default {
        props:['hotApp'],
        computed: {
            ...mapGetters(['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.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>
.moreDia >>> .el-dialog{
    border-radius: 10px;
}
.moreDia >>> .el-dialog__body{
    height: 300px;
    overflow: auto;
    border-top: 1px #e7e7e7 solid;
}
.conBlock{
    background-color: #fff;
    padding: 24px;
    box-sizing: border-box;
    margin-bottom: 24px;
    border-radius: 10px;
}
.tabCon{
    transition: all 0.3s ease; /* 统一过渡效果 */
    border-radius: 10px;
    cursor: pointer;
}
.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 img{
    width: 23px !important;
    height: 20px;
}
.con{
    flex: 1;
    margin-left: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.tit{
    color: #1f2937;font-size: 16px;height: 24px;line-height: 24px;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bri{
    color: #6b7280;font-size: 12px;height: 16px;line-height: 16px;
    overflow: hidden;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.appImg{
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}
.AppList{
    flex-wrap: wrap;display: flex;
    justify-content: space-between;
    border: 1px rgb(243 244 246 / var(--tw-border-opacity, 1)) solid;
    border-radius: 10px;padding: 16px;box-sizing: border-box;
}
</style>