new Vue(
            {
            el: "#app",
            data() {
                return {
                    form: {
                        username: '',
                        password: '',
						email:'',
                    },
                    rules: {
                        username: [
                            { required: true, message: '账号不可为空', trigger: 'blur' }
                        ],
                        password: [
                            { required: true, message: '密码不可为空', trigger: 'blur' }
                        ],
						email: [
						    { required: true, message: '邮箱不可为空', 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: "用户名密码不可为空！",
							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: "用户已登录！",
                    				type: "error",
                    				duration: 1500
                    			});
                    		} else if(response.data.r ==2){
								_this.$message({
									message: response.data.err_text,
									type: "error",
									duration: 1500
								});
							}else{
                    			_this.$message({
                    				message: "登录失败，请检查用户名和密码是否正确！",
                    				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","zh");
                    		localStorage.setItem("did",response.data.did);
							localStorage.setItem("userid",response.data.userid);
                    		location.href="main.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: "用户已注册！",
                							type: "error",
                							duration: 1500
                						});
                					}else{
                						_this.$message({
                							message: "注册失败！",
                							type: "error",
                							duration: 1500
                						});
                					}
                					
                				}else{
                					_this.$message({
                						message: "注册成功！",
                						type: "success",
                						duration: 1500
                					});
                				}
                				
                			  })
                			  .catch(function (error) {
                			    console.log(error);
                			  });
                        } 
                		/*else {
                            this.dialogVisible = true;
                            return false;
                        }*/
                    });
                
                },
                handleClose(done) {
                    this.$confirm("确认关闭?")
                        .then(_ => {
                            done();
                        })
                        .catch(_ => { });
                }
            }

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