<template>
  <div class="login-container" :style="loginBackImgPath">
    <div class="login-form">
      <img class="login-title-img" :src="loginTitleImg" alt>
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" auto-complete="on" label-position="left">
        <el-row>
          <el-col :span="24">
            <img :src="loginRecodeImg" alt @click="showQrcode">
            <img :src="loginTipImg" alt @click="showQrcode">
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <img :src="loginLeftImg" alt>
            </div>
          </el-col>
          <el-col :span="12">
            <div style="font-size: 22px; color: white;margin-bottom: 20px">
              欢迎使用
            </div>
            <div class="grid-content bg-purple-light">
              <el-form-item prop="username">
                <span class="svg-container svg-container_login">
                  <svg-icon icon-class="user" />
                </span>
                <el-input ref="login" v-model="loginForm.username" name="username" type="text" auto-complete="on" placeholder="请输入登录账号" />
              </el-form-item>
              <el-form-item prop="password">
                <span class="svg-container">
                  <svg-icon icon-class="password" />
                </span>
                <el-input
                  v-model="loginForm.password"
                  :type="pwdType"
                  name="password"
                  auto-complete="on"
                  placeholder="请输入密码"
                  @keyup.enter.native="handleLogin"
                />
                <span class="show-pwd" @click="showPwd"><svg-icon :icon-class="svg_icon" /></span>
              </el-form-item>
              <el-form-item>
                <el-button :loading="loading" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
                  登  录
                </el-button>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div
      style="color:#fcfaff;
      position:relative;
      width:100%;
      height:10%;
      top:90%;
      text-align: center"
    >
      山东明安信息技术有限公司 客户服务电话：0531-67881719    手机：18615601819  QQ：3363106855
    </div>
  </div>
</template>
<script>
import path from 'path'
import { mapGetters } from 'vuex'
export default {
  name: 'Login',
  data() {
    return {
      svg_icon: 'hide_password',
      loginBackImgPath: '',
      loginTitleImg: '',
      loginLeftImg: '',
      loginTipImg: '',
      loginRecodeImg: '',
      loginForm: {
        username: '',
        password: '',
        rememberMe: false
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      },
      loading: false,
      pwdType: 'password'
    }
  },
  computed: {
    ...mapGetters([
      'prodName'
    ])
  },
  mounted() {
    this.loginTitleImg = path.join(__dirname, this.$store.getters.prodName + '/static/login/login_title_new.png')
    this.loginBackImgPath = 'background: url("' + path.join(__dirname, this.$store.getters.prodName + '/static/login/bg-img.jpg') + '")'
    this.loginLeftImg = path.join(__dirname, this.$store.getters.prodName + '/static/login/illustratio.png')
    this.loginRecodeImg = path.join(__dirname, this.$store.getters.prodName + '/static/login/QRcode.png')
    this.loginTipImg = path.join(__dirname, this.$store.getters.prodName + '/static/login/prompts.png')
    this.$refs.login.focus()
  },
  methods: {
    showQrcode() {
      this.loginLeftImg = path.join(__dirname, this.$store.getters.prodName + '/static/web/images/app.png')
    },
    showPwd() {
      if (this.pwdType === 'password') {
        this.svg_icon = 'show_password'
        this.pwdType = ''
      } else {
        this.svg_icon = 'hide_password'
        this.pwdType = 'password'
      }
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('Login', this.loginForm).then(_ => {
            this.loading = false
            this.$router.push({ path: '/' })
          }).catch(e => {
            console.log(e)
            if (e && Object.prototype.toString.call(e) === '[object String]') {
              this.$message.warning(e)
            }
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
  $bg:#2d3a4b;
  $light_gray:#eee;

  /* reset element-ui css */
  .login-container{
    /*background: url("http://ww1.sinaimg.cn/large/67d647e5ly1fxdid1ljymj23vc2kwgvm.jpg?tdsourcetag=s_pctim_aiomsg");*/
    background-size: 100% 100%;
  }
  .login-container {
    .el-input {
      display: inline-block;
      height: 47px;
      width: 55%;
      input {
        background: transparent;
        border: 0;
        -webkit-appearance: none;
        border-radius: 0;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        &:-webkit-autofill {
          -webkit-box-shadow: 0 0 0 1000px $bg inset !important;
          -webkit-text-fill-color: #fff !important;
        }
      }
    }
    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
  }

</style>

<style rel="stylesheet/scss" lang="scss" scoped>
  $bg:#2d3a4b;
  $dark_gray:#889aa4;
  $light_gray:#eee;
  .login-container {
    position: fixed;
    height: 100%;
    width: 100%;
    background-color: $bg;
    .login-form {
      position: absolute;
      left: 0;
      right: 0;
      width: 700px;
      height: 400px;
      padding: 35px 35px 15px 35px;
      margin: 140px auto;
      .login-title-img {
        margin-left: 80px;
        margin-bottom: 20px;
      }
    }
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0 auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
  }
</style>
