define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'swiper', 'layer'], function ($, undefined, Frontend,
    Form, Template, Swiper, Layer) {
    var Controller = {
        index: function () {
            var first_swiper = new Swiper ('#first_swiper', {
                loop: true, // 循环模式选项
                // 如果需要分页器
                autoplay:true,
                pagination: {
                  el: '.swiper-pagination',
                }
              })
            var main = new Vue({
                el: "#main",
                data: function () {
                    return {
                        // 公共数据
                        allData: __data,
                        // 左侧tab栏active
                        leftKey: 'course',
                        // 右侧部分需要的数据
                        nowData: {},
                        star: '3',
                        index: 1,
                        rightkey:'course',
                        course_name:'',
                        thirdkey:'book',
                        detial:'',
                        bookname:'',
                        bookAvator:''
                    }
                },
                // 计算属性
                computed: {
                    videoList: function () {
                        return this.nowData.videoList || []
                    }

                },
                // 钩子函数
                mounted() {
                    this.nowData = __data[this.leftKey]


                    // this.$nextTick(function(){

                    // })

                },
                updated() {
                    if (this.leftKey == 'course') {
                        this.courses = this.nowData.courseList
                        this.courses.map(item => {
                            this.star = item.stars
                            this.index = item.id
                            this.showStars(this.star, this.index)
                        })
                    }
                },
                // 监控属性
                watch: {
                    // 监听导航按钮下标改变,使用导航对应的平台数据
                    leftKey: function (newVal, oldVal) {
                        this.nowData = __data[newVal]
                    },

                },
                methods: {
                    changeTabIndex: function (key) {
                        this.leftKey = key;
                        this.rightkey='course'
                        this.thirdkey='book'
                        console.log(this.leftKey)
                    },
                    play(url,name){
                        // this.leftKey = 'direct_seeding';
                        this.videoUrl = url;
                        this.rightkey='video'
                        this.course_name=name

                    },
                    showStars: function (value, i) {
                        layui.use(['rate'], function () {
                            var rate = layui.rate;
                            rate.render({
                                elem: '.stars_' + i,
                                value: value,
                                readonly: true
                            });
                        })
                    },
                    showDetial(detial,img,name){
                        this.thirdkey='detial'
                        this.detial=detial
                        this.bookname=name
                        this.bookAvator=img
                    }
                },
            })
        },
    }
    return Controller;
});