<template>
    <div class="help">
        <m-header v-if="headerStatus" />
        <van-collapse v-if="dataStatus" v-model="activeNames" accordion>
            <van-collapse-item v-for="(item, index) in dataList" :key="index" title-class="van-ellipsis" :title="item.title" :name="index"><div v-html="item.content"></div></van-collapse-item>
        </van-collapse>
        <m-empty class="empty" v-else key="data" />
    </div>
</template>
<script>
/* eslint-disable */
import MHeader from '@/components/MHeader'
import MEmpty from '@/components/MEmpty'
import { browser, calcMinute }  from '@/common/common'
import { helpCenterCatalogList, helpCenterContentList } from '@/api/app'
export default {
    name: 'courseApply',
    components: { MHeader, MEmpty },
    data() {
        return {
            headerStatus: true,
            activeNames: [0],
            dataStatus: true,
            dataList: []
        }
    },
    mounted() {
        let params = this.$route.query
        if(params.Authorization) {
            localStorage.setItem('Authorization', decodeURI(params.Authorization))
            localStorage.setItem('userInfo', decodeURI(params.Authorization))
        }
        
        document.title = '帮助中心'
        if(browser().android || browser().iPhone) {
            this.headerStatus = false
        }

        this.__init()
    },
    methods: {
        async __init() {
            let loadingStatus = true
            this.$toast.loading({
                duration: 0,
                message: '加载中...',
                forbidClick: true,
                loadingType: 'spinner'
            })
            let catalogResult = []
            await helpCenterCatalogList().then(res => {
                let result = res.data
                if(result.code == 200) {
                    catalogResult = result.data
                } else {
                    this.$toast(result.msg)
                    loadingStatus = false
                }
            })
            if(catalogResult.length > 0) {
                await helpCenterContentList({
                    catalogIds: catalogResult[0].id,
                    page: 1,
                    rows: 100
                }).then(res => {
                    let result = res.data
                    loadingStatus = false
                    if(result.code == 200) {
                        this.dataList = result.data.rows ? result.data.rows : []
                        if(this.dataList.length > 0) {
                            this.dataStatus = true
                        } else {
                            this.dataStatus = false
                        }
                    } else {
                        this.$toast(result.msg)
                    }
                })
            } else {
                loadingStatus = false
            }
            
            if(!loadingStatus) {
                this.$toast.clear()
            }
        }
    },
    destroyed() {
        this.$toast.clear()
    }
}
</script>
<style lang='less' scoped>
@import url("../../assets/commonLess/variable.less");
.help {
    min-height: 100vh;
}
/deep/.van-collapse {
    margin: .15rem 0;
    /deep/.van-cell {
        color: #1A1A1A;
        font-size: .17rem;
        padding: .15rem .16rem;
    }
    /deep/.van-collapse-item__content {
        font-size: .14rem;
        color: #808080;
    }
}
</style>