<template>
    <LeftNav />
    <div class="main-container wrap main-fullScreen main-div" style="height: unset;">
        <el-row :gutter="20">
            <!--  左侧 院校列表-->
            <el-col :xs="12" :sm="12">
                <el-card class="box-card">
                    <div class="filterTable">
                        <div class="filterTitle flexWrap">
                            <div class="flex-item-75">
                                <div class="searchSchool">
                                    <el-input v-model="state.selectForm.schoolName" maxlength="24" show-word-limit
                                        style="max-width: 230px;height: 40px;line-height: 40px;"
                                        placeholder="请输入院校或专业名称" class="input-with-select" />
                                    <el-button :icon="Search" @click="reloadSchoolList"
                                        style="border-left: none;height: 40px;line-height: 40px;" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <el-divider />
                    <!--clearable-->
                    <div class="schoolList">
                        <div class="schoolItem" v-for="item in state.schoolList"
                            @click="showSchoolInfo(item.schoolCode)">
                            <div class="schoolLogo">
                                <img :src="item.schoolIcon"
                                    v-if="item.schoolIcon != null && item.schoolIcon != undefined" />
                                <img v-else src="@/assets/images/school/school_default.png">
                            </div>
                            <div class="schoolInfo">
                                <div class="schoolTitle">
                                    <h3 class="schoolName">
                                        {{ item.schoolName }}
                                        <span class="province" v-if="item.province">{{ item.province }}{{ item.city }}{{
                                            item.area }}</span>
                                    </h3>
                                </div>
                                <div class="schoolTags">
                                    <span v-for="tag in item.tagsList">{{ tag }}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <el-skeleton :loading="state.loading" style="padding-top: 25px;"></el-skeleton>
                    <div class="page">
                        <el-pagination background @current-change="handlePage" :current-page="state.current"
                            :page-size="state.size" :total="state.total" layout="total, prev, pager, next,jumper" />
                    </div>
                </el-card>
            </el-col>
            <!--  右侧 功能广告-->
            <el-col :xs="12" :sm="12">
                <div class="page-right" style="width: 300px">
                    选择左侧院校
                </div>
            </el-col>
        </el-row>

    </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import apiConstant from "@/utils/ApiConstant";
import axiosInstance from '@/utils/http';
import { SchoolEntity } from "@/types";
import { Search } from '@element-plus/icons-vue';
import LeftNav from "@/components/LeftNav.vue";
import StaticConstant from '@/utils/StaticConstant';
document.title = '找大学|' + import.meta.env.VITE_PROGRAM_TYPE;
//激活的tabs页
const state = reactive({
    selectForm: {
        schoolName: '',
        current: 1,
        pageSize: 10,
    } as any,
    schoolList: [] as Array<SchoolEntity>,
    size: 10,
    total: 0,
    current: 1,
    loading: false,//加载中? true 加载/false 关闭
})


getSchoolList()

//获取学校列表
function getSchoolList() {
    state.loading = true;
    state.schoolList = []
    axiosInstance({
        url: apiConstant.School.searchSchoolList,
        method: 'get',
        params: {
            schoolName: state.selectForm.schoolName,
            pageNum: state.selectForm.current,
            pageSize: state.selectForm.pageSize,
            addressList: state.selectForm.addressList,
            tagsList: state.selectForm.tagsList,
            schoolNatureList: state.selectForm.schoolNatureList
        },
        showLoading: false,//是否显示加载图标
    }).then((response) => {
        return response?.data
    }).then((data) => {
        state.loading = false;
        if (data.success) {

            let dataResult = data.result
            console.log(dataResult)
            let tags = []
            if (dataResult.records != null && dataResult.records != undefined) {
                for (let i = 0; i < dataResult.records.length; i++) {
                    tags = []
                    let dre = dataResult.records[i]
                    if (dataResult.records[i].tagsList != null && dataResult.records[i].tagsList != undefined) {
                        tags.push(...dre.tagsList)
                    }
                    dataResult.records[i].tagsList = tags
                }
            }
            state.schoolList = dataResult.records
            state.selectForm.current = data.result.current
            state.selectForm.pageSize = data.result.size
            state.total = data.result.total
        }
    }).catch((error: any) => {
        console.log(error);
    }).finally(() => {
    });
}

function reloadSchoolList() {
    state.selectForm.current = 1
    state.schoolList = []
    getSchoolList()
}

const handlePage = (page: number) => {
    if (page) {
        state.selectForm.current = page
        getSchoolList()
    }
}

const showSchoolInfo = (schoolCode: string) => {
    window.open(schoolCode, '_self')
}

</script>

<style scoped lang="scss">
//标签页样式
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}

//自定义输入框 样式
/** 默认样式 */
.input-border-style {
    border: 1px solid #eee !important;
    border-radius: 6px !important;
}

:deep(.el-input__wrapper) {
    background: none !important;
}
</style>

<!--学校列表-->
<style scoped lang="scss">
.schoolList {
    .schoolItem:hover {
        color: #3491FA
    }

    .schoolItem:last-child {
        border-bottom: none;
    }

    .schoolItem {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding: 20px;
        cursor: pointer;
        border-bottom: 1px solid #eee;
        position: relative;

        .schoolLogo {
            margin-right: 20px;

            img {
                width: 60px;
                height: 60px;
            }
        }

        .schoolInfo {
            .schoolTitle {
                margin-bottom: 18px;

                .schoolName {
                    color: #333;
                    font-size: 18px;
                    height: 25px;
                    line-height: 25px;
                    margin: 0 20px 0 0;
                    transition: all .3s;
                    display: flex;
                    align-items: center;

                    .province {
                        height: 26px;
                        line-height: 24px;
                        font-size: 12px;
                        border: 1px solid #eee;
                        color: #555;
                        display: inline-block;
                        padding: 0 10px;
                        margin: 0 20px 0 15px;
                    }
                }

                .schoolName:hover {
                    color: #3491FA
                }
            }

            .schoolTags {
                span {
                    display: inline-block;
                    color: #555;
                    padding-right: 10px;
                    margin-right: 10px;
                    border-right: 1px solid #c5c5c5;
                    line-height: 15px;
                }

                span:last-child {
                    border: none;
                }
            }
        }
    }
}

.page-right {
    .box-card {
        border-radius: 12px;
    }

    .card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: red;
    }

    :deep(.el-card__header) {
        padding: 6px 12px 12px 12px;
        background-color: #4cc8ff;
        height: 30px;

        span {
            width: 100px;
            height: 16px;
            background-size: cover;
            background-image: url(data:image/png;base64, );
        }
    }

    .item {
        border-radius: 12px;

    }

    :deep(.el-card__body) {
        padding: 0;
    }
}
</style>