<template>
    <view>
        <view class="cover">
            <image class="image" :src="detail.cover || ''" mode="aspectFill" />
        </view>
        <view class="head">
            <view class="title">{{ detail.title || '--' }}</view>
            <view class="text">
                <view class="teacher">讲师：{{ detail.teacher || ' --' }}</view>
                <view class="count">共{{ total || 0 }}个课件 | {{ detail.study_count || 1 }}人已学习</view>
            </view>
        </view>
        <view style="height: 10px;" />
        <view class="tabs">
            <view class="tab-item" :class="tabsActive == '目录' ? 'active' : ''" @click="tabsActive = '目录'">
                目录
            </view>
            <view class="tab-item" :class="tabsActive == '介绍' ? 'active' : ''" @click="tabsActive = '介绍'">
                介绍
            </view>
        </view>
        <My_listbox v-show="tabsActive == '目录'" ref="List" @getlist="getList" boxBackground="#fff">
            <list ref="courseware" :list="list" />
        </My_listbox>

        <My_listbox v-if="tabsActive == '介绍'" :pullDown="false" boxBackground="#fff">
            <view class="introduce">
                <view class="title">
                    课程介绍
                </view>
                <view class="description">
                    {{ detail.description || '--' }}
                </view>
            </view>
        </My_listbox>
    </view>
</template>

<script>
import list from "../../components/collectLists/courseware"
export default {
    components: { list },
    data() {
        return {
            tabsActive: "目录",
            list: [],
            detail: {},
            total: 0,
            "content": {
                "sat_coursewareid": 0,
                "where": {
                    "condition": "",
                    "status": "上架"
                }
            }
        }
    },
    onLoad(options) {
        this.content.sat_coursewareid = options.id;
        this.getList(true)
        this.$Http.basic({
            "id": 20240314134002,
            "content": {
                "sat_coursewareid": options.id
            }
        }).then(res => {
            console.log("获取课程详情", res)
            if (this.cutoff(res.msg)) return;
            res.data.cover = this.getSpecifiedImage(res.data.attinfos[0] || {}, 'compressed') || uni.getStorageSync("site").logo || ''
            this.detail = res.data;
            uni.setNavigationBarTitle({
                title: res.data.title,
            })
        })
    },
    methods: {
        getList(init = false) {
            if (this.paging(this.content, init)) return;
            this.$Http.basic({
                "id": 20240315131602,
                content: this.content
            }).then(res => {
                this.$refs.List.RefreshToComplete()
                console.log("获取课件列表", res)
                if (this.cutoff(res.msg)) return;
                res.data = this.$refs.courseware.handleList(res.data)
                this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                this.total = res.total;
                this.content = this.$refs.List.paging(this.content, res)
            })
        }
    }
}
</script>

<style lang="scss">
.cover {
    width: 375px;
    height: 229px;
    background: #FFFFFF;
    box-sizing: border-box;
    overflow: hidden;

    .image {
        width: 375px;
        height: 229px;
    }
}

.head {
    padding: 10px;
    box-sizing: border-box;
    background: #fff;

    .title {
        line-height: 24px;
        font-family: Source Han Sans SC, Source Han Sans SC;
        font-weight: bold;
        font-size: 16px;
        color: #000000;
    }

    .text {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        font-family: Source Han Sans SC, Source Han Sans SC;
        margin-top: 10px;

        .teacher {
            font-size: 14px;
            color: #999999;
        }

        .count {
            font-size: 12px;
            color: #666666;
        }
    }
}

.tabs {
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-sizing: border-box;
    padding: 0 20px;
    width: 375px;
    height: 50px;
    background: #FFFFFF;

    .tab-item {
        line-height: 20px;
        font-family: Source Han Sans SC, Source Han Sans SC;
        font-size: 14px;
        color: #333333;
        padding: 10px;
        border-radius: 8px;
    }

    .active {
        position: relative;
        font-weight: bold;
        color: #C30D23;
    }

    .active::after {
        position: absolute;
        content: "";
        width: 14px;
        height: 3px;
        background: #C30D23;
        border-radius: 5px;
        bottom: 0;
        left: 50%;
        margin-left: -7px;
    }


}


.introduce {
    padding: 10px;

    .title {
        line-height: 20px;
        font-family: Source Han Sans SC, Source Han Sans SC;
        font-weight: bold;
        font-size: 14px;
        color: #333333;
    }

    .description {
        font-size: 14px;
        color: #333333;
        line-height: 24px;
    }
}
</style>