<template>

  <div class="loginContent">

    <div class="left-panel">

    </div>
    <div class="right-panel">
      <div class="sys-title-wrapper" style="letter-spacing:5px;">
        <!-- {{appinfo.appinfo.appName}} -->
        <!-- {{appName}} -->
        费县城管后台管理
      </div>

      <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm"
               label-position="left">
        <div class="header-logo">
            
            <!-- <div class="sys-title">
                用户登录
            </div> -->
        </div>
        <div style="top: 15%;left: 8%;position:absolute;">
          <div class="input-wrapper login-container">
            <label class="label">
              <img src="~@/assets/login/yonghu1.png" style="width:20px">
            </label>
            <div>
              <el-input class="u-input" name="username" type="text" v-model="loginForm.username" autoComplete="on"
                        placeholder="请输入登录账号"/>
            </div>
          </div>
        </div>
        <div style="top: 40%;left: 8%;position:absolute;">
          <div class="input-wrapper login-container">
            <label class="label">
              <img src="~@/assets/login/mima.png" style="width:20px">
            </label>
            <div>
              <el-input class="u-input" name="password" :type="pwdType" @keyup.enter.native="handleLogin"
                        v-model="loginForm.password"
                        autoComplete="on" placeholder="请输入密码"></el-input>
            </div>
          </div>
        </div>

        <div style="top: 65%;left: 8%;position:absolute;">
          <el-button class="login-btn" v-waves type="primary"
                     style="width:448px;background:#0084FF ;border-radius: 10px;font-size: 24px;height: 50px;"
                     :loading="loading" @click.native.prevent="handleLogin">
            登 录
          </el-button>
        </div>

        <div style="top: 86%;left: 10%;position:absolute;">
          <div class="left-txt">
            <span>忘记密码？</span>
          </div>
          <div class="right-txt">
            <span class="s1">还没有账号？</span>
            <router-link :to="{path:'/register'}">
              <span class="s2">去注册</span>
            </router-link>
          </div>
        </div>

        <div class="tips" v-if="isIdentityAuth">
          <router-link to="/oidcRedirect">
            <el-badge is-dot>接口服务器启用了Oauth认证，请点击这里登录</el-badge>
          </router-link>
        </div>

      </el-form>
    </div>
    <div class="comtxt">
     技术支持：山东慧创信息科技有限公司
    </div>
  </div>

</template>

<script>
import waves from '@/directive/waves' // 水波纹指令
import appInfo from '../../../public/config.json';
import {
  mapGetters,
  mapActions
} from 'vuex'

export default {
  name: 'login',
  directives: {
    waves
  },
  data() {
   
    const validateUsername = (rule, value, callback) => {
      if (value.length <= 0) {
        callback(new Error('用户名不能为空'))
      } else {
        callback()
      }
    }
    const validatePass = (rule, value, callback) => {
      if (value.length <= 0) {
        callback(new Error('密码不能为空'))
      } else {
        callback()
      }
    }
    return {
       appName:"",
      tenant: this.tenantid || 'OpenAuthDBContext',  //当前选择的租户
      tenants: [{
        value: 'OpenAuthDBContext',
        label: '默认租户'
      }, {
        value: 'ErrorId404',
        label: '模拟一个不存在的租户'
      }],
      loginForm: {
        username: "",
        password: ""
      },
      loginRules: {
        username: [{
          required: true,
          trigger: 'blur',
          validator: validateUsername
        }],
        password: [{
          required: true,
          trigger: 'blur',
          validator: validatePass
        }]
      },
      loading: false,
      pwdType: 'password'
    }
  },
  mounted(){
    this.appName = appInfo.appInfo.appName
  },
  computed: {
    ...mapGetters([
      'isIdentityAuth',
      'tenantid'
    ])
  },
  methods: {
    ...mapActions([
      'setTenantId', //
    ]),

    tenantChange(e) {
      this.setTenantId(e)
    },
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        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: '/shopsmanage/index'
            })
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}

</script>

<style rel="stylesheet/scss" lang="scss">

$bg: #2d3a4b;
$light_gray: #eee;
$color_balck: #333;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 40px;
    width: 300px;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 5px 0;
      color: $color_balck;
      height: 40px;

      &:-webkit-autofill {
        transition: background-color 5000s ease-in-out 0s;
      }
    }
  }

  .el-form-item {
    margin-bottom: 35px;
    border-radius: 5px;
    color: #454545;

    .el-form-item__content {
      background: #fff;
      border: 1px solid rgba(223, 223, 223, 1);
    }

    &:last-child {
      padding-top: 20px;

      .el-form-item__content {
        border: none;
      }
    }
  }
}

</style>

<style rel="stylesheet/scss" lang="scss" scoped>

@media screen and (max-width: 1150px) {
  .leftImg {
    width: 450px !important;
  }
}

@media screen and (max-width: 1010px) {
  .leftImg {
    width: 380px !important;
  }
}

@media screen and (max-width: 940px) {
  .leftImg {
    display: block;
    width: 260px !important;
    margin: 0 auto !important;
  }
}

$dark_gray: #D1DFE8;

.login-container {
  height: 100%;
  background: url('~@/assets/login/bg2.png') no-repeat;
  background-color: #EBEBEA;
  background-position: 0 0;
  background-size: 62% 100%;
  text-align: center;

  &:before {
    // content: '';
    display: inline-block;
    // height: 100%;  //or the input will be in new line
    vertical-align: middle;
  }

  // .content {
  //   display: inline-block;
  //   vertical-align: middle;

  //   > img {
  //     width: 568px;
  //     margin-right: 150px;
  //     vertical-align: middle;
  //   }

  //   .login-form {
  //     display: inline-block;
  //     width: 400px;
  //     vertical-align: middle;
  //   }
  // }

  .svg-container {
    color: $dark_gray;
    vertical-align: middle;
    width: 33px;
    display: inline-block;
    font-size: 22px;

    &_login {
      font-size: 31px;
    }
  }

  .title {
    font-size: 26px;
    font-weight: 400;
    color: #4452D5;
    margin: 0;
    text-align: left;
  }

  .tips {
    color: #959595;
    font-size: 14px;
    margin-top: 0;
    margin-bottom: 40px;
    text-align: left;
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
    font-size: 24px;
  }
}

</style>

<style scoped>
.left-panel {
  
  width:600px;
  height:430px;
  overflow: hidden;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  /* background:#0b96e5; */
  top:37vh;
  left:50%;
  margin-left:-710px;
  position:relative;
  /* background-image: url('~@/assets/login/bg4.png'); */

}
.loginContent{
  width:100%;
  height:100%;
  left:0px;
  top:0px;
  background: url('~@/assets/login/login-bg.jpg');
  background-size:100% 100%;
  background-repeat: no-repeat;

}
.right-panel {
  width:522px;
  height:360px;
  background-image: url('~@/assets/login/矩形.png');
  background-repeat: no-repeat;
  background-size: 100%;
  
  position: absolute;
  /* right:130px; */
  left:56%;
  /* margin-left:-260px; */
  top: 39vh;
  border-radius: 16px;
}

.header-logo {
  position: absolute;
  top: 12%;
  left: 8%;
}

.header-logo .image {
  width: 41px;
  height: 41px;
  float: left;
}

.header-logo .image img {
  width: 41px;
  height: 41px;
}

.header-logo .sys-title {
  float: right;
  text-align: center;
  margin-left: 15px;
  width: 400px;
  height: 23px;
  font-size: 18px;
  font-family: Adobe Heiti Std;
  font-weight: normal;
  color: #101F2C ;
}

.sys-title-wrapper{
  position: absolute;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  top: -120px;
  line-height: 45px;
  width: 540px;
  left:-10px;
  letter-space:24px;
  font-size:40px;
  font-family: Adobe Heiti Std;
  font-weight: normal;
  color: white;
}

.input-wrapper {
  float: left;
  width: 448px;
  height: 50px;
  background: #FFFFFF;
  box-shadow: 0px 1px 1px 0px rgba(158, 168, 184, 0.5);
  border-radius: 5px;
}

.label {
  float: left;
  width: 56px;
  height: 56px;
  line-height: 56px;
  text-align: center;
  overflow: hidden;
    position:relative;
  top:-6px;
}

.u-input {
  background: transparent;
  border: none;
  padding: 5px 0;
  color: #555;
  height: 40px;
  line-height: 40px;
  width: 390px;
}

.login-btn {
  width: 448px;
  height: 56px;
  background: #0088FF;
  border-radius: 10px;
  cursor: pointer;
}

.login-btn::after {
  box-sizing: border-box;
  position: absolute;
  width: 100%;
  height: 100%;
  content: "";
  border: 2px solid rgb(255, 255, 255);
  z-index: 2;
  margin: 0px;
  left: 0px;
  bottom: 0px;
  border-top-width: 2px;
  transition: border-top-width 0.1s ease 0.2s, height 0.2s ease 0.1s, width 0.2s ease 0s, margin 0.2s ease 0s;
}

.login-btn:hover {
  opacity: 0.8;
}

.login-btn:hover::after {
  width: 60%;
  height: 0px;
  border-width: 0px 2px 2px;
  margin: 0px 20%;
  transition: border-top-width 0.1s ease 0s, height 0.2s ease 0.1s, width 0.2s ease 0.2s, margin 0.2s ease 0.2s;
}

.login-btn .btn-txt {
  font-family: Source Han Sans CN;
  margin-left: 42%;
  color: #FFFFFF;
  width: 56px;
  height: 56px;
  line-height: 56px;
  text-align: center;
  display: inline-block;
  border-radius: 50%;
  text-decoration: none;
}

.login-btn .btn-txt:hover {
  opacity: 0.8;
}

.left-txt {
  float: left;
}

.left-txt span {
  width: 81px;
  height: 17px;
  font-size: 12px;
  font-family: Source Han Sans CN;
  color: #999999;
  line-height: 42px;
}

.right-txt {
  float: right;
  margin-left: 250px;
}

.right-txt .s1 {
  width: 81px;
  height: 17px;
  font-size: 12px;
  font-family: Source Han Sans CN;
  color: #999999;
  line-height: 42px;
}

.right-txt .s2 {
  width: 81px;
  height: 17px;
  font-size: 12px;
  font-family: Source Han Sans CN;
  color: #2882FE;
  line-height: 42px;
  cursor: pointer;
}

.right-txt .s2:hover {
  color: #0F31AF;
}

.comtxt {
  width: 220px;
  height: 16px;
  font-size: 12px;
  font-family: Source Han Sans CN;
  color:#fff;
  line-height: 63px;
  position: absolute;
  bottom: 50px;
  right:50px;
 text-align:right;
 margin-left:-110px;
}
</style>
