<template>
    <div>
        <div class="w-full flex items-center w-full relative min-h-134px">
            <img :src="title" alt="" class="w-full">
            <div class="absolute title">
                名师工作室
            </div>
        </div>
        <div class="main bg-white-grey rounded-10px mt-4 py-8 px-8 relative">
            <check-row v-model="queryForm.tjzx_id" label="学科" :items="subjectData" @click="initData"></check-row>
            <check-row v-model="queryForm.tm_xd" label="学段" :items="xdData" @click="initData"></check-row>
            <div class="mt-25px search-box">
                <input type="text" placeholder="搜索关键字" v-model="queryForm.keyword">
                <button type="button" class="search-btn" @click="initData"></button>
            </div>
            <ul v-loading="loading" v-if="listData.length > 0" class="my-25px course-list">
                <li @click="routerLink(item)" v-for="(item, i) in listData" :key="i">
                    <div class="course-img relative">
                        <img :src="getFullUrl(item.tm_img)" alt="">
                        <div class="info-bottom pl-7px items-center">
                            <span class="icon-view"></span>
                            <span class="ml-5px text-14px text-white">{{ item.tm_fws }}</span>
                        </div>
                    </div>
                    <div class="pt-10px pb-20px px-15px border-bottom-1">
                        <div class="text-16px text-dark-400 h-40px leading-20px overflow-hidden">{{
                            item.tm_gzsmc }}
                        </div>
                    </div>
                </li>
            </ul>
            <nodata v-else class="my-25px "></nodata>
            <div class="flex justify-center items-end absolute bottom-10px left-0 right-0">
                <el-pagination
                  v-model:current-page="queryForm.page"
                  v-model:page-size="queryForm.limit"
                  layout="total,sizes, prev, pager, next, jumper"
                  :total="total"
                  :background="true"
                  @current-change="initData"
                  :hide-on-single-page="false"
                />
              </div>
        </div>
    </div>
</template>
<script setup>
import title from '~/assets/home/icon-6.png'
import nodata from '@/pages/xsd/component/noData.vue'
import { msgzs_list, option_list, subject_list } from './api'
import { useRouter } from 'vue-router'
const router = useRouter();
let queryForm = $ref({
    page: '1',
    limit: 8,
    tjzx_id: null,
    tm_xd: null,
    keyword: ''
})
let subjectData = $ref([]);
let xdData = $ref([]);
subject_list({ limit: 9999, page: 1 }).then(res => {
    if (res.code == '1') {
        subjectData = [{ n: "全部", v: null }].concat(
            res.data.page_data.map(({ tjzx_id, tjzx_xkmc }) => ({
                v: tjzx_id,
                n: tjzx_xkmc
            }))
        )
    }
})
option_list({ cs_code: "XD" }).then(res => {
    if (res.code == '1') {
        xdData = [{ n: "全部", v: null }].concat(
            res.data.option.map(({ v, n }) => ({
                v: v,
                n: n
            }))
        )
    }
})
// 初始化
let loading = $ref(false);
let total = $ref(0);
let listData = $ref([]);
function initData() {
    loading = true;
    let data = {
        ...queryForm
    }
    msgzs_list(data).then(res => {
        if (res.code == '1') {
            const { page_data, page_now, total_rows, total_page } = res.data;
            listData = page_data;
            total = total_rows * 1;
            queryForm.page = page_now;
            loading = false;
        }
    })
}
initData();
function routerLink(item) {
    router.push({
        name: 'home_msgzs_detail',
        params: {
            id: item.tm_id
        }
    })
}
</script>
<style lang="scss" scoped>
$color: #1259A1;

.title {
    font-size: 30px;
    font-weight: 400;
    text-align: left;
    color: #ffffff;
    padding-left: 100px;
    line-height: 30px;
    letter-spacing: 0.23px;
    text-shadow: 0px 2px 3px 0px rgba(0, 14, 51, 0.31);
}

.bg-white-grey {
    background: #fcfeff;
}

.search-box {
    width: 300px;
    height: 48px;
    background: #f6f8fa;
    border-radius: 8px;
    padding: 0 10px 0 14px;
    display: flex;
    align-items: center;

    input {
        flex: 1;
        height: 48px;
        border: 0;
        font-size: 16px;
        color: #333;
        outline: none;
        background: #f6f8fa;
    }

    .search-btn {
        width: 26px;
        height: 26px;
        border-radius: 6px;
        background: $color url("/images/icon-search.png") center no-repeat;
        background-size: 13px 13px;
    }
}

.course-list {
    display: flex;
    flex-wrap: wrap;

    li {
        min-width: 0;
        width: 268px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 1px 6px rgba(0, 0, 0, 0.11);
        margin-right: 19px;
        margin-bottom: 15px;
        cursor: pointer;

        &:nth-child(4n) {
            margin-right: 0;
        }

        .course-img {
            width: 100%;
            height: 151px;
            border-radius: 10px 10px 0 0;
            overflow: hidden;

            img {
                width: 100%;
            }

            .info-bottom {
                position: absolute;
                left: 0;
                bottom: 0;
                z-index: 30;
                width: 80px;
                height: 27px;
                background: rgba(0, 0, 0, .5);
                border-radius: 0 10px 0 0;
                display: flex;

                .icon-view {
                    width: 24px;
                    height: 16px;
                    background: url("/images/icon/view.png") center no-repeat;
                    background-size: 24px 16px;
                }

                .icon-thumb {
                    width: 17px;
                    height: 16px;
                    background: url("/images/icon/thumb.png") center no-repeat;
                    background-size: 17px 16px;
                }
            }
        }
    }
}
::v-deep .el-pagination.is-background .el-pager li.is-active {
  background: $color;
}
</style>