var appLoginV3 =new Vue({
    el: '#app_mod_login_v3',
    data:{
        title:"Login",
        errorsOrders:[],
        msgInfo:"",
        ListItems:[],
        detailItemLogin:{username:'',password:''} ,
        detailItem:{birthday_day:0,birthday_month:0,birthday_year:0,name:'',password:'',email:'',phone:'',password_confirmation:'',birthday:'',gender:0,captcha:''} ,
        flagLoading:false,
        flagLoadingRegister:false,
        flagTab:true,
        ListDay:[],
        ListYear:[],
        ListMonth:[],
        now:new Date(),
		isMobile:false,
    },
    created() {
       
    },
    
    mounted() {
        this.resetRecaptcha();
        for (let i=1; i<13; i++) {
            this.ListMonth.push(i);
        }
        for (let i=1; i<32; i++) {
            this.ListDay.push(i);
        }
        for (let i=1919; i<=this.now.getFullYear(); i++) {
            this.ListYear.push(i);
        }
        console.log("document:"+document.URL);
    },
    methods: {
		
        myLogin:function () {
            this.flagLoading=true;
            $.request('onMyLoginV3', {  data:{login:this.detailItemLogin.username,password:this.detailItemLogin.password} ,
                complete: result=> {
                    this.flagLoading=false;
                    alert(result.responseJSON.msg);
                    if (result.responseJSON.success===true) {
                        let link = $("#link_after_login").val();
                        if(link==null || link==""){
                            location.reload();
                        }else{
                            window.location.href = link;
                        }
                        
                    }else {							
                        
                    }

                }
            });
        },
        myRegister:function(){
            //this.detailItem.recaptcha = $("#token_recaptcha").val();
            if (this.checkForm()) {
                this.flagLoadingRegister=true;
                    $.request('onMyRegisterV3', {  data:this.detailItem ,
                        complete: result=> {
                            this.flagLoadingRegister=false;
                            alert(result.responseJSON.msg);
                            if (result.responseJSON.success==true) {									
                                let link = $("#link_after_login").val();
                                if(link==null || link==""){
                                    location.reload();
                                }else{
                                    window.location.href = link;
                                }
                            }
                        }
                    });
            }else {
                console.log("fdafds");
            }
        },
        
        ChangeKeyWord(e,ip){
            console.log("login nhé");
            const code = (e.keyCode ? e.keyCode : e.which);
            if (code===13) {
                if (ip==='password') {
                    if (this.detailItemLogin.username!=null && this.detailItemLogin.username!=='' && this.detailItemLogin.password!=null && this.detailItemLogin.password!=='') {
                        this.myLogin();
                    }
                }else if (ip==='username') {
                    this.$refs.password.focus();
                }
            }
        },
        checkForm:function () {
            var flag = true;
            if (this.detailItem.name==null || this.detailItem.name=='') {
                flag = false;
                $("#registerName").addClass('is-error');
            }
            if (this.detailItem.email==null || this.detailItem.email=='') {
                flag = false;
                $("#registerEmail").addClass('is-error');
            }
            if (this.detailItem.phone==null || this.detailItem.phone=='') {
                flag = false;
                $("#registerPhone").addClass('is-error');
            }
            if (this.detailItem.password==null || this.detailItem.password=='') {
                flag = false;
                $("#registerPassword").addClass('is-error');
            }
            if (this.detailItem.password_confirmation==null || this.detailItem.password_confirmation=='') {
                flag = false;
                $("#registerPassword_confirmation").addClass('is-error');
            }


            if (flag==true) {
                if (this.detailItem.password.trim()!=this.detailItem.password_confirmation.trim()) {
                    alert("Mật khẩu nhập lại không đúng");
                    return false;
                }else if (this.validEmail(this.detailItem.email)==false) {
                    alert("Email không đúng định dạng");
                    return false;
                }
                return true;
            }else {
                alert("Bạn chưa điền đầy đủ thông tin");
                return flag;
            }

        },
        validEmail: function (email) {
            var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(email);
        },
        resetRecaptcha:function () {
            //getRecaptcha();

        },
        changeTab(flag){
            if(flag!=this.flagTab){
                this.flagTab=flag;
            }
            
        }
    }

});


/*
var appLoginSuggest =new Vue({
    el: '#app_mod_login_suggest',     
    data:{
        title:"Nhập thông tin mua hàng",
        errorsOrders:[],
        msgInfo:"",
        ListItems:[],
        detailItemLogin:{username:'',password:''} ,
        detailItem:{birthday_day:0,birthday_month:0,birthday_year:0,name:null,password:'',email:'',phone:'',password_confirmation:''
        ,birthday:'',gender:0,captcha:'',province:0,district:0,ward:0,address:''} ,
        flagLoading:false,
        flagLoadingRegister:false,
        flagTab:true,
        ListDay:[],
        ListYear:[],
        ListMonth:[],
        now:new Date(),
        flagLoadingDistrict:false,
        flagLoadingProvince:false,
        flagLoadingWard:false,
        ListProvince:[], 
        ListDistrict:[],                
        ListWard:[], 
		isMobile:false,
    },
    created() {
       
    },
    
    mounted() {
        this.resetRecaptcha();
        for (let i=1; i<13; i++) {
            this.ListMonth.push(i);
        }
        for (let i=1; i<32; i++) {
            this.ListDay.push(i);
        }
        for (let i=1919; i<=this.now.getFullYear(); i++) {
            this.ListYear.push(i);
        }
        this.getListProvince();
        
    },
    methods: {
        showLogin:function(){
			$('#SuggestV3Modal').modal('hide');
			$('#GuestConfirmRegisterModal').modal('hide');
			$('#LoginV3Modal').modal('show');
		},
        myRegisterSuggest:function(){
            //this.detailItem.recaptcha = $("#token_recaptcha").val();
            if (this.checkForm()) {
                this.flagLoadingRegister=true;
                    $.request('onRegisterSuggest', {  data:this.detailItem ,
                        complete: result=> {
                            this.flagLoadingRegister=false;
                            $("#guestconfirmregistermsg").html(result.responseJSON.msg);
							$('#SuggestV3Modal').modal('hide');
							$('#GuestConfirmRegisterModal').modal('show');
                            if (result.responseJSON.success==true) {						
                                let link = $("#link_after_login").val();
                                if(link==null || link==""){
                                    location.reload();
                                }else{
                                    window.location.href = link;
                                }
                            }
                        }
                    });
            }else {
                console.log("fdafds");
            }
        },
        
        ChangeKeyWord(e,ip){
            console.log("login nhé");
            const code = (e.keyCode ? e.keyCode : e.which);
            if (code===13) {
                if (ip==='password') {
                    if (this.detailItemLogin.username!=null && this.detailItemLogin.username!=='' && this.detailItemLogin.password!=null && this.detailItemLogin.password!=='') {
                        this.myLogin();
                    }
                }else if (ip==='username') {
                    this.$refs.password.focus();
                }
            }
        },
        checkForm:function () {
            var flag = true;
            $("#app_mod_login_suggest").addClass('was-validated');
            
            if (this.detailItem.name==null || this.detailItem.name=='') {
                flag = false;
                $("#registerName").addClass('is-error');
            }
            if (this.detailItem.email==null || this.detailItem.email=='') {
                flag = false;
                $("#registerEmail").addClass('is-error');
            }
            if (this.detailItem.phone==null || this.detailItem.phone=='') {
                flag = false;
                $("#registerPhone").addClass('is-error');
            }
            if (this.detailItem.province==null || this.detailItem.province==0) {
				flag = false;
				$("#add_province").addClass('is-error');
			}
			if (this.detailItem.district==null || this.detailItem.district==0) {
				flag = false;
				$("#add_district").addClass('is-error');
			}
			if (this.detailItem.ward==null || this.detailItem.ward==0) {
				flag = false;
				$("#add_ward").addClass('is-error');
			}


            if (flag==true) {
                if (this.detailItem.password.trim()!=this.detailItem.password_confirmation.trim()) {
                    alert("Mật khẩu nhập lại không đúng");
                    return false;
                }else if (this.validEmail(this.detailItem.email)==false) {
                    alert("Email không đúng định dạng");
                    return false;
                }
                return true;
            }else {
                alert("Bạn chưa điền đầy đủ thông tin");
                return flag;
            }

        },
        validEmail: function (email) {
            var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(email);
        },
        resetRecaptcha:function () {
            //getRecaptcha();

        },
        changeTab(flag){
            if(flag!=this.flagTab){
                this.flagTab=flag;
            }
            
        },
        getListProvince:function(flagEdit = false){
            this.ListProvince = [];
            this.flagLoadingProvince = true;
            this.detailItem.district = 0;
            this.detailItem.ward = 0;
            
            $.request('onGetListProvince', {  data:{} ,      
                complete: result=> {
                    if(result.responseJSON.success==true){                                 
                        this.ListProvince = result.responseJSON.ListItems;                      
                    }  
                    this.flagLoadingProvince = false;            
                }
            });
        },
        getListDistrict:function(flagEdit = false){
            this.ListDistrict = [];
            this.flagLoadingDistrict = true;
            if(!flagEdit)
            {                    
                this.detailItem.ward = 0;
            }
            $.request('onGetListDistrict', {  data:{"province":this.detailItem.province} ,      
                complete: result=> {
                    if(result.responseJSON.success==true){                                 
                        this.ListDistrict = result.responseJSON.ListItems;                      
                    }  
                    this.flagLoadingDistrict = false;                     
                }
            });
        },
        getListWard:function(district_id){
            
            this.ListWard = [];
            this.flagLoadingWard = true;
            $.request('onGetListWard', {  data:{"district":this.detailItem.district} ,      
                complete: result=>{
                    if(result.responseJSON.success==true){                                 
                        this.ListWard = result.responseJSON.ListItems;                      
                    }    
                    this.flagLoadingWard = false;                 
                }
            });
        },

    }
});*/