<template>
    <view class="allcourseWrapper">
        <view v-if="onLineList.length">
            <view v-for="course in onLineList" :key="course.courseId">
                <onLineCourseItem :onLineCourse="course" @toLearn="toLearn"></onLineCourseItem>
            </view>
        </view>
    </view>
</template>

<script>
import { dateFormat } from '@/utils/util';
import onLineCourseItem from '@/components/onLineCourseItem/index.vue'

export default {
    components: {
        onLineCourseItem
    },
    data() {
        return {
            onLineList: [],
            total: 10,
            classId: '',
            className: '',
            queryParams: {
                pageSize: 10,
                pageNum: 1,
            },
        }
    },
    onShow() {
        // const classId = options.id
        // const className = options.name
        // this.className = className
        // // console.log(options)
        // this.classId = classId
        // uni.setNavigationBarTitle({ title: className })
        this.getCourseList()
    },
    methods: {
        async toLearn(course) {
            if (!course.signUp && course.isPay == '0') {
                const res = await this.http.quickPost(`/train/online/signUp/${course.courseId}`, {}, true)
                if (res.data.code == 200) {
                    uni.navigateTo({
                        url: `/pages/index/testtraining/onLineCourse?courseId=${course.courseId}`
                    })
                }
                else {
                    return
                }
            } else {
                uni.navigateTo({
                    url: `/pages/index/testtraining/onLineCourse?courseId=${course.courseId}&learnStatus=${course.show ? true : false}`
                })
            }
        },
        pagionChange(e) {
            console.log(e);
            this.queryParams.pageNum = e.current
            this.getCourseList()
        },
        async getCourseList() {
            let accessToken = uni.getStorageSync('accessToken')
            if (accessToken) {
                const wxUserInfo = uni.getStorageSync('wxUserInfo')
                const userId = wxUserInfo.userId
                this.http.quickGet(`/course/online/courses?userId=${userId}`).then((res) => {
                    // console.log(res);
                    this.onLineList = res.data.data
                    console.log(this.onLineList);

                })
            } else {
                this.http.quickGet(`/course/online/courses`, false).then((res) => {
                    // console.log(res);
                    this.onLineList = res.data.data
                    console.log(this.onLineList);

                })
            }
        },
        async onReachBottom() {
            if (this.total <= this.queryParams.pageSize) {
                return
            }
            this.queryParams.pageSize += 10
            this.getCourseList()
            console.log("onReachBottom");
        },
        async onReachBottom() {
            // if (this.total <= this.queryParams.pageSize) {
            //     return
            // }
            // this.queryParams.pageSize += 10
            // this.getCourseList()
            console.log("onReachBottom");
        },

    },
}
</script>

<style lang="scss" scoped>
.allcourseWrapper {
    // text-align: center;
    margin: 20rpx;
}
</style>
