<template>
  <div class="container">
    <div class="search-ctn">
        <searchs></searchs>
    </div>
    <folder-list
        v-for="(folderListItem, folderListIndex) of currentList"
        :key="folderListIndex"
        :list="folderListItem.list"
        @folderClick="intoFolder">
    </folder-list>
  </div>
</template>

<script>

export default {
    name: 'SchoolFolderLevel',
    components: {
        Searchs: () => import('./../myResources/components/Searchs'),
        FolderList: () => import('./../myResources/components/FolderList')
    },
    data () {
        return {
            currentList: {},
            listData: {
                secondLevel: [
                    {
                        list: [
                            {
                                title: '第二级文件夹1',
                                descript: '我上传了10个文档',
                                isFolder: true,
                                nextIsFolder: true,
                                folderData: 'thirdLevel'
                            },
                            {
                                title: '第二级文件夹2',
                                descript: '我上传了10个文档',
                                isFolder: true,
                                nextIsFolder: true,
                                folderData: 'thirdLevel'
                            },
                            {
                                title: '第二级文件夹3',
                                descript: '我上传了10个文档',
                                isFolder: true,
                                nextIsFolder: true,
                                folderData: 'thirdLevel'
                            }
                        ]
                    }
                ],
                thirdLevel: [
                    {
                        list: [
                            {
                                title: '第三级文件夹1',
                                descript: '我上传了10个文档',
                                isFolder: true,
                                nextIsFolder: false,
                                folderData: 'fileLevel'
                            }
                        ]
                    }
                ]
            }

        }
    },
    methods: {
        intoFolder (item) {
            /* 点击文件夹进入下一级 */
            if (item.isFolder) {
                let routerName
                let routerPath
                if (item.nextIsFolder) {
                    routerPath = '/education/schoolResources/folderLevel'
                    routerName = 'schoolFolderLevel'
                } else {
                    routerPath = '/education/schoolResources/fileLevel'
                    routerName = 'schoolFileLevel'
                }
                this.$router.push({
                    name: routerName,
                    path: routerPath,
                    query: {
                        folder: item.folderData,
                        title: item.title
                    }
                })
            }
        }
    },
    mounted () {
        if (this.$route.query) {
            this.currentList = this.listData[this.$route.query.folder]
        }
    },
    watch: {
        $route (val) {
            if (val.query) {
                this.currentList = this.listData[val.query.folder]
            }
        }
    }
}
</script>

<style lang="less" scoped>
.container {
    .search-ctn {
        padding: 20px 15px 10px 15px;
    }
}
</style>
