
ELEMENT.locale(ELEMENT.lang.en);
new Vue(
            {
            el: "#app",
            data() {
                return {
                    form: {
                        username: '',
                        password: '',
						email:'',
                    },
                    rules: {
                        username: [
                            { required: true, message: 'Account cannot be empty!', trigger: 'blur' }
                        ],
                        password: [
                            { required: true, message: 'Password cannot be empty!', trigger: 'blur' }
                        ],
						email: [
						    { required: true, message: 'Email cannot be empty!', trigger: 'blur' }
						]
                    },
                    dialogVisible: false,
					
					checked:false,
					
					dialogVisible1:false,
                }
            },
            methods: {
				re_password(){
					
				},
				show_password(){
					this.$data.dialogVisible1=true;
				},
				show_reg(){
					this.$data.form.username= '';
					this.$data.form.password='';
					this.$data.dialogVisible=true;
				},
				
				handleCommand(command) {
					if (command === 'zh') {
						var url = 'login.html';
						url = encodeURI(url);
						window.open(url, "_self");
					}else if (command === 'en'){
						var url = 'login-en.html';
						url = encodeURI(url);
						window.open(url, "_self");
					}
				},
                onSubmit(formName) {
					if(this.form.username =="" || this.form.password == ""){
						this.$message({
							message: "Account or Password cannot be empty!",
							type: "error",
							duration: 1500
						});
						return;
					}
					
                    var _this = this;
                    axios.post('/deescloud/login', {
                        username: _this.$data.form.username,
                        password: _this.$data.form.password
                      })
                      .then(function (response) {
                        
                    	if (response.status != 200 || response.data.r !=0) {
                    		
                    		if (response.data.r ==1) {
                    			_this.$message({
                    				message: "The user has logged in!",
                    				type: "error",
                    				duration: 1500
                    			});
                    		}else{
                    			_this.$message({
                    				message: "logged in Failure, please check your user name and password!",
                    				type: "error",
                    				duration: 1500
                    			});
                    		}
                    		
                    	}else{
                    		localStorage.setItem("online_user",_this.$data.form.username);
                    		localStorage.setItem("uuid",response.data.uuid);
                    		localStorage.setItem("level",response.data.level);
                    		localStorage.setItem("lang","en");
                    		localStorage.setItem("did",response.data.did);
                    		location.href="main-en.html";
                    	}
                    	
                      })
                      .catch(function (error) {
                        console.log(error);
                      });

                },
                register(formName) {
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                			//window.open("main.html","_self","baidu.com");
                			
                			var _this = this;
                			axios.post('/deescloud/registerUser', {
                			    username: _this.$data.form.username,
                			    password: _this.$data.form.password
                			  })
                			  .then(function (response) {
                			    
                				if (response.status != 200 || response.data.r !=0) {
                					
                					if (response.data.r ==1) {
                						_this.$message({
                							message: "The user has registered!",
                							type: "error",
                							duration: 1500
                						});
                					}else{
                						_this.$message({
                							message: "Registration is failed!",
                							type: "error",
                							duration: 1500
                						});
                					}
                					
                				}else{
                					_this.$message({
                						message: "Registration is successful!",
                						type: "success",
                						duration: 1500
                					});
                				}
                				
                			  })
                			  .catch(function (error) {
                			    console.log(error);
                			  });
                        } 
                		/*else {
                            this.dialogVisible = true;
                            return false;
                        }*/
                    });
                
                },
                handleClose(done) {
                    this.$confirm("Are you sure to exit?")
                        .then(_ => {
                            done();
                        })
                        .catch(_ => { });
                }
            }

            })
			
			
			//setInterval(function(){ alert("Hello"); }, 3000);