<template>
<div class="wrap">
  <el-form :model="loginForm" :rules="fieldRules" ref="loginForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <span class="tool-bar">
      <!-- 主题切换 -->
     
      <!-- 语言切换 -->
      <!-- <lang-selector class="lang-selector"></lang-selector>    -->
    </span>
    <h1 class="title" style="padding-left:22px;" ><img src="../assets/selogo.png" alt=""> 中国社会保险</h1>
    <p style="color:black;text-align:right;font-size:40px">西充居保全网经办平台</p>
    
      <input type="text" v-model="loginForm.account" class="acc" auto-complete="off" placeholder="账号">
     
    
   
      <input type="password"  v-model="loginForm.password" class="pass" auto-complete="off" placeholder="密码">
     
   
    <el-form-item  style="margin-top:20px">
      <el-col :span="12">
        <el-form-item prop="captcha">
          <el-input @keyup.enter.native="login" type="test" v-model="loginForm.captcha" auto-complete="off" placeholder="验证码, 单击图片刷新"
            style="width: 100%;">
          </el-input>
        </el-form-item>
      </el-col>
      <el-col class="line" :span="1">&nbsp;</el-col>
      <el-col :span="11">
        <el-form-item>
            <img style="width: 100%;" class="pointer" :src="loginForm.src" @click="refreshCaptcha">
        </el-form-item>
      </el-col>
    </el-form-item>
    <!-- <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox> -->
    <el-form-item style="width:100%;">
      <el-button class="cz" type="primary" style="width:48%;" @click.native.prevent="reset">重 置</el-button>
      <el-button class="dl" type="primary" style="width:48%;" @click.native.prevent="login" :loading="loading">登 录</el-button>
    </el-form-item>
  </el-form>
 
  </div>
</template>

<script>
import { mapState } from 'vuex'
import Cookies from "js-cookie"
import ThemePicker from "@/components/ThemePicker"
import LangSelector from "@/components/LangSelector"
export default {
  name: 'Login',
  components:{
    ThemePicker,
    LangSelector
  },
  data() {
    return {
      loading: false,
      loginForm: {
        account: '',
        password:'',
        captcha:'',
        src: ''
      },
      fieldRules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
        // ,
        // captcha: [
        //   { required: true, message: '请输入验证码', trigger: 'blur' }
        // ]
      },
      checked: true
    }
  },
  methods: {
    login() {
    
      this.loading = true
      let userInfo = {account:this.loginForm.account, password:this.loginForm.password, captcha:this.loginForm.captcha}
      this.$api.login.login(userInfo).then((res) => {
          if(res.code != 200) {
            this.$message({
              message: res.message,
              type: 'error'
            })
          } else {
            Cookies.set('token', res.data.token) // 放置token到Cookie
            sessionStorage.setItem('user', userInfo.account) // 保存用户到本地会话
            this.$store.commit('menuRouteLoaded', false) // 要求重新加载导航菜单
            this.$router.push('/')  // 登录成功，跳转到主页
          }
          this.loading = false
        }).catch((res) => {
          this.$message({
          message: res.message,
          type: 'error'
          })
        });
    },
    refreshCaptcha: function(){
      this.loginForm.src = this.global.baseUrl + "/captcha.jpg?t=" + new Date().getTime();
    },
    reset() {
      this.$refs.loginForm.resetFields()
    },
    // 切换主题
    onThemeChange: function(themeColor) {
      this.$store.commit('setThemeColor', themeColor)
    }
  },
  mounted() {
    this.refreshCaptcha()
  },
  computed:{
    ...mapState({
      themeColor: state=>state.app.themeColor
    })
  }
}
</script>

<style lang="scss" scoped>
.wrap{
 background: url(../assets/bg.jpg) no-repeat;
  background-size: auto 100%;
  height: 100%;
}
.iggf{
  height: 100%;
  position: relative;
}
.igg{
  height: 100%
}
h1{
  text-align: right;
  font-size: 30px
}
  .login-container {
    z-index: 200;
    left: 60vw;
    position: absolute;
    top:100px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    width: 450px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    // border: 1px solid #eaeaea;
    // box-shadow: 0 0 25px #cac6c6;
    .title {
      height: 60px;
      display: flex;
     justify-content: flex-end;
     
      align-items: center;
      color: #505458;
    }
    .title img{
      height: 100%;
      margin-right: 40px;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
  input{
    outline: none;
     background: none
  }
  .acc{
    width: 450px;
    border: none ;
    height: 50px;
    border-bottom: 1px solid lightgray
  }
  .pass{
     width: 450px;
    border: none;
     height: 50px;
     border-bottom: 1px solid lightgray
  }
  .cz,.dl{
    border-radius: 20px;
    border: none;
    height: 45px;
    background: lightgray;
   
  }
</style>