<template>
  <div class="login">
    <div class="main">
      <div class="main-left"><img class="logo" src="../assets/logo.png" alt="" /></div>
      <div class="main-right">
        <div class="title">武汉耀火科技flame框架</div>
        <el-input class="input" v-model="user_name" placeholder="请输入账号"></el-input>
        <el-input class="input" v-model="password" show-password placeholder="请输入密码"></el-input>
        <el-button class="btn" type="primary" @click="login_click">登录</el-button>

        <div class="register" @click="register_click">注册</div>
      </div>
    </div>
    <div class="bottom">技术支持(武汉耀火科技)20201112.4</div>
  </div>
</template>

<script>
import Vue from 'vue';
import { mapActions } from 'vuex';
export default {
  name: 'login',
  data() {
    return {
      user_name: '',
      password: ''
    };
  },
  mounted() {
    let that = this;
    that.$store.dispatch('global/loginOut').then(res => {
      console.log('loginOut', res);
      sessionStorage.clear();
    });
    console.log('$router===', that.$router.options.routes);
  },
  methods: {
    ...mapActions(['loginIn']),
    login_click() {
      let that = this;
      let commit_data = {
        user_name: that.user_name,
        pass_word: that.password
      };
      console.log('userName', that.user_name, 'password', that.password);
      that.$store.dispatch('global/loginIn', commit_data).then(res => {
        console.log('用户登陆返回的数据:', res);
        that.$router.push('/Home');
      });
    },
    register_click() {
      let that = this;
      console.log('Register');
      that.$router.push('/Register');
    }
  }
};
</script>

<style scoped>
.login {
  /* position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0; */
  width: 100vw;
  height: 100vh;
  background: url(../assets/loginbg7.jpeg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  -moz-background-size: 100% 100%;
  display: flex;
  justify-content: center;
}
.register {
  margin-top: 20px;
  margin-right: 10px;
  text-align: right;
  color: darkblue;
  width: 100%;
}
.register:hover {
  cursor: pointer;
}
.login .main {
  /* position: absolute; */
  margin-top: calc((100vh - 380px) / 3);
  padding: 50px;
  height: 280px;
  border-radius: 5px;
  background-color: #eee;
  box-shadow: #333 0 0 20px 2px;
  display: flex;
  flex-direction: row;
  align-items: center;
}
.login .main .main-left {
  padding-right: 30px;
  padding-top: 30px;
  align-items: center;
}

.login .main .main-right {
  /* position: absolute; */

  display: flex;
  flex-direction: column;
  align-items: center;
}
.login .main .logo {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}
.login .main .title {
  padding: 20px 0;
  color: #666;
  font-size: 26px;
  font-weight: bold;
}
.login .main .input {
  width: 300px;
  margin-top: 20px;
}
.login .main .btn {
  width: 300px;
  margin-top: 20px;
}
.login .bottom {
  position: fixed;
  margin-bottom: 20px;
  bottom: 0;
  left: 0px;
  right: 0px;
  text-align: center;
  color: grey;
}
</style>
