return {
    data: function () {
        return {
            list: [],
            show: false,
            childList: [],
            urls: []
        }
    },
    methods: {
        allDownload: function () {
            var that = this
            if(this.urls.length==0){
                this.$message.warning('请选择要下载的文件')
                return
            }
            this.urls.map(function (item) {
                that.childList.map(function(site){
                    if(item == site.ZLAdd){
                        that.download(item,site.ZLName)
                    }
                })
            })
        },
        filePreview:function(url,name){
            this.$router.push({name:'UserCourseDetailFilePreview',query:{
                costype:this.$route.query.costype,
                url:url,
                name:name
            }})
        },
        download: function (item) {
            if(item.downloaded){
                return false
            }
            var zlurl = item.ZLAdd;
            var name = item.ZLName;
            if(!zlurl){
                return this.$message.warning('无效文件地址！');
            }
            
            var x = new XMLHttpRequest();
            x.open("GET", zlurl, true);
            x.responseType = 'blob';
            x.onload = function (e) {
                var url = window.URL.createObjectURL(x.response);
                var a = document.createElement('a');
                a.href = url;
                a.download = name;
                a.click();
                item.downloaded = true;
                if(!localStorage.COURSE_DATA_DOWNLOADED){
                    localStorage.COURSE_DATA_DOWNLOADED = item.zlid;
                }else{
                    var downloadIds = localStorage.COURSE_DATA_DOWNLOADED.split(',');
                    if(downloadIds.indexOf(item.zlid) == -1){
                        localStorage.COURSE_DATA_DOWNLOADED += ','+item.zlid;
                    }
                    
                }
            }
            x.send();
        },
        allSelect: function () {
            if (this.urls.length > 0) {
                this.urls = []
                this.list.map(function (item,i) {
                    item.select = false
                    if(item.childs && item.childs.length){
                        item.childs.map(function (site, i) {
                            site.select = false
                        })
                    }
                })
            } else {
                this.urls = this.list.map(function (item,i) {
                    item.select = true
                    if(item.childs && item.childs.length){
                        item.childs.map(function (site, i) {
                            site.select = true
                            return site.ZLAdd
                        })
                    }
                })
                // this.urls = this.childList.map(function (site) {
                //     site.select = true
                //     return site.ZLAdd
                // })
            }
        },
        select: function (item) {
            var that = this
            item.select = !item.select
            if(item.childs && item.childs.length){
                item.childs.map(function (site, i) {
                    site.select = item.select
                })
            }
            that.getFileData()

        },
        getFileData(){
            var that = this
            var urlsArr = []
            that.list.map(function (item,i) {
                if(item.childs && item.childs.length){
                    item.childs.map(function (child,c) {
                        if(child.select){
                            urlsArr.push(child.ZLAdd)
                        }
                    })
                }else{
                    urlsArr.push(item.ZLAdd)
                }
            })
            that.urls = urlsArr
        },
        openList(item) {
            item.show = !item.show
        },
        getList: function () {
            var that = this;
            GetCosZLCourseID({
                Courseid:that.$route.params.id
            }).then(function (res) {
                if (res.result) {
                    res.CosZLlist.map(function(item){
                        if(localStorage.COURSE_DATA_DOWNLOADED){
                            var downloadIds = localStorage.COURSE_DATA_DOWNLOADED.split(',');
                            item.downloaded = downloadIds.indexOf(item.zlid) > -1;
                        }else{
                            item.downloaded = false;
                        }
                    });
                    var list
                    /**类型为0的数组 */
                    list = res.CosZLlist.filter(function (item) {
                        if (item.zltypid == 0) {
                            return item
                        }
                    })
                    /**类型不为0的数组 */
                    var otherList = []
                    var ids = []
                    res.CosZLlist.map(function (item) {
                        if (item.zltypid !== 0 && ids.indexOf(item.zltypid) === -1) {
                            ids.push(item.zltypid)
                            otherList.push({ zltypid: item.zltypid, zltypename: item.zltypename,show:false })
                        }
                    })
                    otherList.map(function (item) {
                        var list = res.CosZLlist.filter(function (site) {
                            if (site.zltypid == item.zltypid) {
                                site.select = false
                                return site
                            }
                        })
                        return item.childs = list
                    })
                    list = otherList.concat(list);
                    
                    /*重构后的数组 */
                    that.list = list
                }else{
                    that.list = []
                }


            });
        },
        open:function(name) {
            this.$router.push({
                name:name,
                query:{
                    costype:this.$route.query.costype
                }
            })
        }
    },
    created: function () {
        var that = this;
        that.getList()
    }
}