<template>
    <My_listbox ref="List" @getlist="getList" :isShowEmpty="false" :bottomHeight="70">
        <view class="box">
            <navigator class="nav-box" v-for="item in list" :key="item.sat_courseware_classid"
                :url="'/packageA/course/index?id=' + item.sat_courseware_classid + '&classname=' + item.classname"
                hover-class="navigator-hover">
                <image v-if="item.cover" class="image" :src="item.cover" mode="aspectFill" lazy-load="false" />
                <text v-else>{{ item.classname }}</text>
            </navigator>
            <navigator class="nav-box" v-for="item in appList" :key="item.name" :url="item.path"
                hover-class="navigator-hover">
                <block v-if="item.cover">
                    <image class="image" :src="item.cover" mode="aspectFill" lazy-load="false" />
                </block>
                <text v-else>{{ item.remark }}</text>
            </navigator>
        </view>
    </My_listbox>
</template>

<script>
export default {
    data() {
        return {
            updatePage: true,
            list: [],
            appList: [],
            "content": {
                "parentid": 0,
                "where": {
                    "isenable": 1
                }
            }
        }
    },
    methods: {
        init(callBack) {
            try {
                this.appList = this.getApps('商学院')
            } catch (error) {
                console.log("未获取到授权信息")
            }
            this.getList().then(res => {
                this.updatePage = false;
                callBack()
            })
        },
        getList(init = false) {
            return new Promise((resolve, reject) => {
                if (this.paging(this.content, init)) return resolve();
                this.$Http.basic({
                    "id": "20221102143302",
                    content: this.content
                }).then(res => {
                    console.log("课程分类", res)
                    this.$refs.List.RefreshToComplete()
                    resolve()
                    if (this.cutoff(res.msg)) return;
                    res.data = res.data.map(v => {
                        v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos.find(s => s.usetype == "avatar")) : uni.getStorageSync("site").logo || '';
                        return v
                    });
                    this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                    this.content = this.$refs.List.paging(this.content, res)
                })
            })
        }
    },
}
</script>

<style lang="scss">
.box {
    padding: 0 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    .nav-box {
        width: 172.5px;
        height: 92px;
        flex-shrink: 0;
        margin-top: 10px;

        .image {
            width: 100%;
            height: 100%;
        }
    }
}
</style>