<template>
  <div class="login-container">
    <el-form
      class="login-form"
      autocomplete="on"
      :model="loginForm"
      :rules="loginRules"
      ref="loginForm"
      label-position="left"
    >
      <div class="form-box-login">
        <div class="title-container" style="padding-bottom:20px;">
          <img src="static/images/login-logo.png" width style="margin:0 auto; display: block;">
        </div>

        <el-form-item prop="password">
          <span class="svg-container svg-container_login">
            <svg-icon icon-class="user"/>
          </span>
          <el-input
            name="password"loginbytoken
            type="password"
            v-model.trim="loginForm.password"
            autocomplete="off"
            :placeholder="$t('login.set_new_password')"
          />
        </el-form-item>

        <el-form-item prop="passwordConfirm">
          <span class="svg-container">
            <svg-icon icon-class="password"/>
          </span>
          <el-input
            name="password"
            :type="passwordType"
            @keyup.enter.native="handleLogin"
            v-model.trim="loginForm.passwordConfirm"
            autocomplete="off"
            :placeholder="$t('login.set_new_password_d')"
          />
        </el-form-item>

        <el-button
          type="primary"
          style="width:100%; font-size: 16px; padding:15px 20px; margin-bottom:20px;"
          :loading="loading"
          @click.native.prevent="forgetPwdNextStep"
        >{{$t('login.over')}}</el-button>

        <div style="overflow:hidden;">
          <el-button type="text" @click="$router.push({name:'login'})" style="float:left">{{$t('login.password_login')}}</el-button>
          <!-- <el-button type="text" @click="$router.push({name:'reg'})" style="float:right">{{$t('login.toregister')}}</el-button> -->
        </div>

        <div style="padding:8px;"></div>
      </div>
    </el-form>

    <el-dialog :title="$t('login.dialogVisible')" :visible.sync="dialogVisible" append-to-body width="400">
      <el-button
        style="margin:5px 0; width:100%;"
        @click="loginBySite(item.id)"
        v-for="(item,index) in site_list"
        :key="index"
        size="medium"
      >{{item.name}}</el-button>
    </el-dialog>
  </div>
</template>

<script>
import { isvalidUsername } from '@/utils/validate'
import { getToken, setToken } from '@/utils/auth' // getToken from cookie
export default {
  data() {
    const validateConfirmPwd = (rule, value, callback) => {
      if (value === '') {
        callback(new Error(this.$t('login.password_check')))
      } else if (value.length < 5) {
        callback(new Error(this.$t('login.validatePassword')))
      } else if (this.loginForm.password !== value) {
        callback(new Error(this.$t('login.validatePasswordCheck')))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 5) {
        callback(new Error(this.$t('login.validatePassword')))
      } else {
        callback()
      }
    }
    return {
      // password: "",
      // passwordConfirm: "",
      dialogVisible: false,
      username5: '',
      site_list: [],
      loginForm: {
        password: '',
        passwordConfirm: '',
        site_id: 0
      },
      loginRules: {
        password: [
          { required: true, trigger: 'blur', validator: validatePassword }
        ],
        passwordConfirm: [
          { required: true, trigger: 'blur', validator: validateConfirmPwd }
        ]
      },
      passwordType: 'password',
      loading: false,
      showDialog: false,
      sended: false,
      sendInt: 60
    }
  },
  methods: {
    // loginBySite(sid) {
    //   this.loginForm.site_id = sid;
    //   self.dialogVisible = false;
    //   this.handleLogin();
    // },
    forgetPwdNextStep() {
      if (this.loginForm.password === '') {
        this.$message.error(this.$t('login.set_new_password'))
        return false
      } else if (this.loginForm.passwordConfirm === '') {
        this.$message.error(this.$t('login.set_new_password_d'))
        return false
      } else if (this.loginForm.password !== this.loginForm.passwordConfirm) {
        this.$message.error(this.$t('login.validatePasswordCheck'))
        return false
      }
      this.$http('post','/api/account/forget', {
          tel: this.$route.query.mobile,
          verify: this.$route.query.verifyCode,
          password: this.loginForm.password,
          password_confirmation: this.loginForm.passwordConfirm
        })
        .then(res => {
          if (res.data.code == 1) {
            this.$message.success(res.data.msg)
            this.$router.push({ name: 'login' })
          } else {
            this.$message.error(res.data.msg)
          }
        })
    }
  },
  created() {
    document.title = this.$t('login.title_gongdaoyun')
    this.$store.dispatch('setLanguage', 'zh')
  },
  destroyed() {}
}
</script>

<style rel="stylesheet/scss" scoped lang="scss">
.form-box-login {
  background-color: #fff;
  padding: 30px;
  border-radius: 4px;
}

$bg: #283443;
$light_gray: #eee;
$cursor: #fff;

/* reset element-ui css */
.login-container {
  background-image: url(/images/login-bg.jpg);
  background-repeat: no-repeat;
  background-size: 100% 100%;

  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;

      height: 47px;

      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px #e5e5e5 inset !important;
        -webkit-text-fill-color: $cursor !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;
  }
}

$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.login-container .el-input input::first-line {
  color: #889aa4;
}
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: $bg;
  .login-form {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 400px;
    margin-top: -210px;
    margin-left: -200px;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
    &_login {
      font-size: 20px;
    }
  }
  /deep/ .el-input{
    .el-input__inner{
      background: transparent !important;
      border: 0px !important;
      -webkit-appearance: none !important;
      border-radius: 0px !important;
      padding: 12px 5px 12px 15px !important;
      height: 47px !important;
    }
  }
  .title-container {
    position: relative;
    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
    .set-language {
      color: #fff;
      position: absolute;
      top: 5px;
      right: 0px;
    }
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .thirdparty-button {
    position: absolute;
    right: 35px;
    bottom: 28px;
  }
  .verify_code,
  .verify_code_click {
    position: absolute;
    right: 10px;
    top: 10px;
    line-height: 30px;
    padding: 0 5px;
    color: #409eff;
  }
  .verify_code {
    background-color: #fff;
  }
  .form-box-login .verify_code_click {
    color: #333;
    background-color: none;
  }
}
</style>
