<template>
    <div class="main bg-white-grey rounded-10px mt-4 p-8" style="font-size: 18px">
        <el-select v-model="fi_db_table_name" @change="initData">
            <el-option label="全部" value=""></el-option>
            <el-option v-for="t in typeList" :key="t.v" :label="t.n" :value="t.v"></el-option>
        </el-select>
        <div class="mt-25px search-box">
            <input type="text" placeholder="搜索关键字" v-model="keyword">
            <button type="button" class="search-btn" @click="initData"></button>
        </div>
        <ul v-if="listData.length > 0" class="mt-25px course-list">
            <li v-for="(item, i) in listData" :key="i" @click="toDetail(item)">
                <div class="course-img relative">
                    <img v-if="item.fi_ex" :src="getFullUrl(item.fi_ex.img)" alt="">
                    <div class="info-bottom pl-7px items-center">
                        <span class="icon-view"></span>
                        <span class="ml-5px text-14px text-white">{{ item.fi_ex.lll }}</span>
                        <span class="ml-15px icon-thumb"></span>
                        <span class="ml-5px text-14px text-white">{{ item.fi_ex.dzl }}</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.fi_ex.name }}
                    </div>
                    <p class="text-14px my-5px text-gray-500">{{ item.fi_ex.create_dateline }}</p>
                    <el-divider style="margin: 0;"></el-divider>
                    <div class="mt-2px flex justify-between items-center text-14px leading-30px">
                        <span class="text-dark-500 font-medium">责任老师：{{ item.fi_ex.teacher_name }}</span>
                        <div class="w-102px text-gray-500 text-sm">
                            <p class="truncate">{{ item.fi_ex.school_name }}</p>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
        <nodata v-else></nodata>
        <div class="mt-20px flex justify-center">
            <el-pagination v-model:current-page="page" v-model:page-size="limit" layout="total, prev, pager, next"
                :total="total" :background="true" @current-change="handleSelectionChange"></el-pagination>
        </div>
    </div>
</template>
<script setup>
import { useRouter, useRoute } from "vue-router";
import nodata from '@/pages/xsd/component/noData.vue'
import { zj_list } from "../api";
import { user } from '@/store/index'
const router = useRouter();
const route = useRoute();
let fi_db_table_name = $ref('')
let keyword = $ref('');
let typeList = $ref([
    {
        "v": "txwx_mszy_kc",
        "n": "名师资源"
    },
    {
        "v": "txwx_tskc_kc",
        "n": "特色课程"
    },
    {
        "v": "txwx_zbkc",
        "n": "直播课程"
    },
    {
        "v": "txwx_jtjy_kc",
        "n": "家庭教育"
    },
]
)
let listData = $ref([])
let limit = $ref(8);
let total = $ref(0);
let page = $ref(1);
let form_query = $ref({
    limit: 8,
    page: 1,
})
function handleSelectionChange(val) {
    form_query.page = val;
    initData();
}
function initData() {
    let data = {
        ...form_query,
        td_user_name: user.value.user_name,
        fi_db_table_name,
        keyword,
        user_space: '1'
    }
    zj_list(data).then(res => {
        if (res.code == '1') {
            const { page_data, total_rows, page_now } = res.data;
            total = Number(total_rows);
            page = Number(page_now);
            listData = page_data;
            page_data.forEach(item => {
                item.fi_ex = JSON.parse(item.fi_ex);
            })
        }
    })
}
initData();

function toDetail(item) {
     if (item.fi_db_table_name == 'txwx_mszy_kc') {
        router.push({ name: 'home_mszx_chapter', params: { tmk_id: item.fi_ex.tmk_id} })
    } else if (item.fi_db_table_name == 'txwx_tskc_kc') {
        router.push({ name: 'home_tskc_chapter', params: { ttk_id: item.fi_ex.ttk_id } });
    } else if (item.fi_db_table_name == 'txwx_zbkc') {
        router.push({ name: 'home_zbkc_chapter', params: { tz_id: item.fi_ex.tz_id} });
    } else if (item.fi_db_table_name == 'txwx_jtjy_kc') {
        router.push({ name: 'home_jtjy_chapter', params: { tjk_id: item.fi_ex.tjk_id } });
    } else if (item.fi_db_table_name == 'txwx_xkzy') {
        // router.push({ name: 'home_jtjy_chapter', params: { tjk_id: item.fi_ex.tjk_id } });
    }
}
</script>
<style lang="scss" scoped>
$color: #1259a1;

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

.bg_blue {
    background: $color;
}

.shadow-default {
    box-shadow: 0 10px 24px rgba(161, 153, 168, 0.18);
}

.color-grey {
    color: #999;
}

.border-bottom-1 {
    border-bottom: 1px solid #eee;
}

.nav-title {
    font-size: 16px;
    color: #949494;

    span {
        font-size: 18px;
        color: #050026;
    }
}

.btnDiv {
    .el-button {
        background: $color;
        border-color: $color;
        color: #fff;
    }
}

.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: 152px;
                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;
                }
            }
        }
    }
}
</style>