
(function(){
    var apiUrl = '/webapi/';
    var apikey = 'bff16cf2c8275d99c008e318500a623c';
    var rely = [templateDir+'/static/vue/js/vue2.5.17.js','/ks_inc/static/js/vue.main.js?'+hash,templateDir+'/static/vue-router/js/vue-router.js'];

    loadFile()
    /**
     * 加载文件
     */
  
    function loadFile(index){
        index = index || 0;
        var script = document.createElement('script');
        script.src = rely[index];
        document.getElementsByTagName('body')[0].appendChild(script);
        script.onload = function(){
            this.outerHTML = null;
            index++;
            if(index >= rely.length){
                loadFileSuccess()
            }else{
                loadFile(index)
            }
        }
    }
    
    function loadFileSuccess(){
       
        /**
         * 加载组件
         */
        new KS_Main();
        /**
         * 过滤html标签
         */
        Vue.prototype.msg= function (msg) {  
            return msg.replace("\n", "<br>")
        };
        /**
         * 创建路由
         */
        var routes = [
            {
                path:'/',
                component:{
                    template:"#index",
                    data:function(){
                        return{
                            sign:null,
                            message:''
                        }
                    },
                    methods:{
                        SignIn:function(){
                            if(this.sign === null){
                                return false
                            }
                            var that = this;
                            if(this.sign === '签到'){
                                request('/plus/SignIn.aspx?action=SignIn&rnd=' + Math.random(),null,function(res){
                                    alert(res)
                                    that.sign = '签到记录'
                                })    
                            }else{
                                
                                location.href = URL_signinlist.value;
                            }
    
                        }   
    
                    },
                    mounted:function(){
                        var that = this;
                        getUserInfo(function(res){                       
                           that.message = res.message;
                        })
                        request('/plus/SignIn.aspx?action=SignInUser&rnd='+Math.random(),null,function(res){
                            if (res == "no") {
                                that.sign = '签到'     
                            
                            } else {
                                that.sign = '签到记录'  
                               
                            }

                        })    
                    }
                },
               
                
            },
           
            
            /**
             * 教师管理
             */
            
            {
                path:"/teacherManage",
                component:{
                    
                    data:function(){
                        return {
                            verify:0,//不限0   审核2   未审核1
                            loading:true,
                            pagesize:3,
                            page:1,
                            pageCount:null,
                            list:[],
                            addStyle:0,
                            itmeObj:{
                                url:'',
                                TcId:null,
                                index:null
                            }

                        }
                    },
                  
                    watch:{
                        '$route.query.verify':function(v){
                            console.log(v)
                            this.pageCount = null;
                            this.page = 1;
                            this.verify = v;
                            this.list = [];
                            this.getList();
                            
                        },
                        

                    },
                    mounted:function(){
                        var that = this;
                        this.verify = this.$route.query.verify || 0;
                        this.getList()
                        window.addEventListener('scroll',function(){
                            that.scroll()
                        })
                    },
                    methods:{
                        go:function(key,v){
                            var queryData = JSON.parse(JSON.stringify(this.$route.query));
                            queryData[key] = v;
                            this.$router.push({
                                path: '/teacherManage',
                                query: queryData
                            });
                            
                        },
                        getList:function(){
                            this.loading = true;
                            var that = this;
                            request('/?c=user&a=ajax_teacher&pagesize='+this.pagesize+'&page='+this.page+'&verify='+this.verify,null,function(res){

                                console.log(res)
                                that.pageCount = Number(res.data.pageCount);
                                that.list = that.list.concat(res.data.data);
                                
                                that.$nextTick(function(){
                                    that.loading = false
                                })
                            },'json')
                        },
                        scroll:function(){
                            var scrollFlag = getIsScrolltolower(body);
                            if (scrollFlag &&  this.page < this.pageCount){
                                this.page++;
                                this.getList()
                            }
                        },
                        changeState:function(item,i){
                            console.log(item)
                            this.itmeObj.url= item.getViewUrl;  
                            this.itmeObj.TcID = item.TcID                     
                            this.addStyle = 1,
                            this.itmeObj.index = i;
                        },
                        del:function(){
                            var that = this;
                            if(confirm('您确定要删除吗？')){
                                request('?c=user&a=ajax_teacher&action=delete&ids='+this.itmeObj.TcID,null,function(res){
                                    console.log(res)
                                    if(res.data.result === true){
                                        that.list.splice(that.itmeObj.index,1)
                                        that.addStyle = 0
                                    }
                                    
                                },'json')
                            }
                            
                        },

                        lcokerDown:function(){
                            this.addStyle = 0
                        }

                    },
                    template:"#teacherManage"
                },
                
            },
             /**
             * 学员管理
             */
            {
                path:"/studentManage",
                component:{
                    data:function(){
                        return {
                            key:null,
                            loading:true,
                            pagesize:6,
                            page:1,
                            pageCount:null,
                            list:[],
                            scorllHeight:null    
                        }
                    },
                    watch:{
                        '$route.query.key':function(v){
                            console.log(v)
                            this.pageCount = null;
                            this.page = 1;
                            this.key = v;
                            this.list = [];
                            this.getList();
                        },                   
                    },
                    mounted:function(){
                        var that =this;
                        this.getList()
                        window.addEventListener('scroll',function(){
                            that.scroll()
                        })
                    },
                    methods:{
                        go:function(key,v){
                            var queryData = JSON.parse(JSON.stringify(this.$route.query));
                            queryData[key] = v;
                            this.$router.push({
                                path: '/studentManage',
                                query: queryData
                            });
                            
                        },
                        getList:function(){
                            this.loading = true;
                            var that = this;
                            var __key = this.key ? '&key='+this.key : '';
                            request('/?c=user&a=ajax_student&pagesize='+this.pagesize+'&page='+this.page+__key,null,function(res){
                                console.log(res)
                                that.pageCount = Number(res.data.pageCount);
                                that.list = that.list.concat(res.data.data);

                                that.$nextTick(function(){
                                    that.loading = false
                                })
                            },'json')
                        },
                        scroll:function(){
                        
                            var scrollFlag = getIsScrolltolower(body);
                            if (scrollFlag &&  this.page < this.pageCount){
                                this.page++;
                                this.getList()
                            }

                        },
                        onKeyDown:function(e){
                           if(e.keyCode===13){
                                this.go('key',this.key)
                           }
                        }
                    },
                    template:"#studentManage"
                }
            },

            /**
             * 订单管理
             */

            {
                path:"/orderList",
                component:{
                    data:function(){
                        return {
                            key:null,
                            loading:true,
                            pagesize:6,
                            page:1,
                            pageCount:null,
                            list:[],
                            
                            showtype:0,//0全部订单，1今日,2点播已付款,3点播未付款,4面授已付款,5面授未付款,6直播已付款,7直播未付款,
                            showFlag:false
                        }
                    },
                    watch:{
                        '$route.query.showtype':function(v){ //监听路由地址
                            console.log(v)
                            this.pageCount = null;
                            this.page = 1;
                            this.showtype = v;
                            this.showFlag=false
                            this.list = [];
                            this.getList();

                        },
                        

                    },
                    mounted:function(){
                        this.showtype = this.$route.query.showtype || 0;
                        this.getList()
                        window.addEventListener('scroll',function(){                          
                            that.scroll()
                        }) 
                    },
                    methods:{
                        go:function(key,v){
                            var queryData = JSON.parse(JSON.stringify(this.$route.query));
                          
                           
                            queryData[key] = v;
                            this.$router.push({
                                path: '/orderList',
                                query: queryData
                            });
                            
                        },
                        getList:function(){
                            this.loading = true;
                            var that = this;
                          
                            request('/?c=user&a=ajax_order&page='+this.page+'&pagesize='+this.pagesize+'&showtype='+this.showtype,null,function(res){
                                console.log(res)
                                that.pageCount = Number(res.data.pageCount);
                                that.list = that.list.concat(res.data.data);

                                that.$nextTick(function(){
                                    that.loading = false
                                })
                            },'json')
                        },
                        scroll:function(){
                      
                        
                            var scrollFlag = getIsScrolltolower(body);
                            if (scrollFlag &&  this.page < this.pageCount){
                                this.page++;
                                this.getList()
                            }

                        },
                        maskTrigger:function(){
                            this.showFlag=false
                        },
                        maskTrue:function(){
                            this.showFlag=true
                        }
                       
                    },
                    template:"#orderList"
                }
            },


            /**
             * 课程管理
             */
            {
                path:'/courseManage',
                component:{
                   
                    data:function(){
                        return {
                            key:null,
                            loading:true,
                            pagesize:5,
                            page:1,
                            pageCount:null,
                            list:[],                          
                            filter:0,
                            costype:0,//0点播 1面授 5直播
                            free:0, //0全部 1免费 2收费
                            isoff:0,  //0全部 1未上架 2已上架
                            verify:0, //0全部 1未审核 2已审核
                            itmeObj:{},
                            addStyle:0
                           
                        }
                    },
                    watch:{
                        '$route.query':function(){
                            this.reset()
                        }
                        
                        
                    },
                    mounted:function(){
                        var that = this;
                        this.costype = this.$route.query.costype || 0;
                        this.verify = this.$route.query.verify || 0;
                        this.free = this.$route.query.free || 0;
                        this.isoff = this.$route.query.isoff || 0;
                        this.getList()
                        window.addEventListener('scroll',function(){              
                            that.scroll()
                        })   
                    },
                    methods:{
                        reset:function(){
                            this.pageCount = null;
                            this.page = 1;
                            this.filter = 0;
                            this.list = [];
                            this.getList();
                        },
                        go:function(key,v){
                            var queryData = JSON.parse(JSON.stringify(this.$route.query));            
                            queryData[key] = v;
                            this.$router.push({
                                path: '/courseManage',
                                query: queryData
                            });
                            this.showFlag = false;
                        },
                        getList:function(){
                            this.loading = true;
                            var that = this;
                            this.costype = this.$route.query.costype || 0;
                            this.verify = this.$route.query.verify || 0;
                            this.free = this.$route.query.free || 0;
                            this.isoff = this.$route.query.isoff || 0;
                            request('/?c=user&a=ajax_course&page='+this.page+'&pagesize='+this.pagesize+'&costype='+this.costype+'&verify='+this.verify+'&free='+this.free+'&isoff='+this.isoff,null,function(res){
                                    console.log(res)
                                    that.pageCount = Number(res.data.pageCount);
                                 
                                    that.list = that.list.concat(res.data.data);

                                    that.$nextTick(function(){
                                        that.loading = false
                                    })
                                },'json')
                            },
                            scroll:function(e){
                                var scrollFlag = getIsScrolltolower(body);
                                if (scrollFlag && this.pageCount && this.page < this.pageCount){
                                    this.page++;
                                    this.getList()
                                }
                            },
                            changeState:function(item,i){
                                console.log(item)
                                
                                this.itmeObj = item                    
                                this.addStyle = 1

                            },
                            shelves:function(sttus){
                                var that = this;
                                request('/?c=user&a=ajax_course&action=sell&courseid='+this.itmeObj.CourseID,null,function(res){
                                    if(res.data.result === true) {
                                        that.itmeObj.IsOff = that.itmeObj.IsOff == 0 ? 1 : 0;
                                        var tips = that.itmeObj.IsOff == 1 ? '上架成功' : '下架成功';
                                        alert(tips);
                                        
                                        that.addStyle = 0;
                                    }
                                    
                                },'json')
                               
                                
                            },
                            confirm:function(order){
                                if(order === 'reset'){
                                    this.verify = 0;
                                    this.isoff = 0;
                                    this.free = 0;
                                   
                                }
                                this.go('verify',this.verify);
                                this.go('isoff',this.isoff);
                                this.go('free',this.free);
                            },   
                            lcokerDown:function(){
                                this.addStyle = 0
                            }
                           
                           
                        },
                    template:"#courseManage"
                },
                
                
            },
           /**
             * 订单结算
             */

            {
                path:"/settlement",
                component:{
                    data:function(){
                        return {
                            key:null,
                            loading:true,
                            pagesize:6,
                            page:1,
                            pageCount:null,
                            list:[],
                           
                            balance:0,//余额
                            kCash:0,//可提现
                            YCash:0,//已提现
                            CCash:0//总提现
                               
                        }
                    },
              
                    mounted:function(){
                        var that = this
                        this.getList()
                        window.addEventListener('scroll',function(){                               
                            that.scroll()
                        }) 
                    },
                    methods:{
                        go:function(key,v){
                            var queryData = JSON.parse(JSON.stringify(this.$route.query));
                          
                           
                            queryData[key] = v;
                            this.$router.push({
                                path:"/settlement",        
                                query: queryData
                            });
                            
                        },
                        getList:function(){
                            this.loading = true;
                            var that = this;
                          
                            request('?c=user&a=ajax_account&page='+this.page+'&pagesize='+this.pagesize,null,function(res){
                              
                                that.pageCount = Number(res.data.pageCount);
                                that.list = that.list.concat(res.data.data);
                               console.log(res)
                                that.kCash = res.data.kTxAmount;
                                that.YCash = res.data.yTxAmount;
                                that.CCash = res.data.totalCurrent
                                that.$nextTick(function(){
                                    that.loading = false
                                })
                            },'json')
                        },
                        scroll:function(){
                      
                         
                            var scrollFlag = getIsScrolltolower(body);
                            if (scrollFlag &&  this.page < this.pageCount){
                                this.page++;
                                this.getList()
                            }

                        },
                      
                       
                    },
                    template:"#settlement"
                }
            },


              /**
             * 申请提现
             */
            
            {
                path:"/AFCW",
                component:{
                    data:function(){
                        return {
                            key:null,
                            loading:true,                      
                            list:[],
                            scorllHeight:null,                               
                            title:null,//结算标题
                            money:0,//结算金额
                            applytype:1,//结算方式
                            applicant:null,//开户人
                            phone:'',//联系电话
                            bankaccount:'',//开户银行
                            accountnumber:'',//银行账户
                            remarks:'',//备注  
                            countMoney:'',//实际到账金额
                            poundage:'', //手续费;
                            kTxAmount:''//可提现金额

                        }
                    },
                   
                    mounted:function(){

                     
                        var that = this;
                        request('?c=user&a=ajax_account',null,function(res){
                            
                           that.poundage = res.data.poundage;
                            that.kTxAmount = res.data.kTxAmount
                        
                        },'json')
                    
                    },
                    methods:{
                       


                        submit:function(){
                            this.loading = true;
                            var that = this;
                         
                            if(that.money > that.kTxAmount ){
                                alert('您的余额不足')
                                return false;
                            }
                            if(this.phone===''){
                                alert('请输入联系电话');
                                return false; 
                            }
                            if(this.applicant===0){
                                if(this.bankaccount===''){
                                    alert('请输入开户银行');
                                    return false; 
                                } else if(this.accountnumber===''){
                                    alert('请输入银行账户');
                                    return false; 
                                }else if(this.accountnumber===''){
                                    alert(' 请输入开户人');
                                    return false; 
                                }
                            }
                           
                            
                            request('?c=user&a=ajax_account&action=apply&title='+that.title+'&money='+that.money+'&applytype='+that.applytype+'&applicant='+that.applytype+'&phone='+that.phone+'&bankaccount='+that.bankaccount+'&accountnumber='+that.accountnumber+'&remarks='+that.remarks,null,function(res){
                            
                                that.list = that.list.concat(res.data);
                                    if( res.data.result == true) {
                                            alert('提现成功');
                                            window.history.go(-1);
                                    
                                    }else{
                                        alert(res.data.msg);
                                        return false   
                                    }
                                    that.$nextTick(function(){
                                        that.loading = false

                                    })
                            },'json')
                            
                        },
                        
                        actualmoney:function(){
                            var reg = this.money.match(/\d+\.?\d{0,2}/);
                            var txt = '';
                            if (reg != null) { txt = reg[0]; }
                            var poundage = this.poundage;


                          
                            this.countMoney = this.toMoney(txt - txt * poundage * 0.01);
                            console.log(txt,poundage)
                            return false
                           
                        },
                        toMoney:function(num){
                            num = num.toFixed(2);
                            num = parseFloat(num)
                            num = num.toLocaleString();
                            if (num == 0) num = '0.00';
                            return num;//返回的是字符串23,245.12保留2位小数
              
                        }
                      
                    
                    },
                    template:"#AFCW"
                }
            }

        ];
        
        var router = new VueRouter({
            routes
        });

        new Vue({
            el:"#app",
            data:{
            
            },
            router
        });

    }

})();