<template>
  <div>
    <headerlogin></headerlogin>
    <div class="loginBox">
      <h2 class="forgotTil">设置登录密码</h2>
      <div class="bzTab">
        <div class="siglist">
          <div class="yuan" :class="(forgotPage==1 || forgotPage==2)?'current':''">1</div>
          <div>设置密码</div>
        </div>
        <div class="siglist les">
          <div class="line" :class="forgotPage==2?'current':''"></div>
        </div>
        <div class="siglist">
          <div class="yuan" :class="forgotPage==2?'current':''">2</div>
          <div>设置结果</div>
        </div>
      </div>
      <div class="gjhqIpt" v-if="forgotPage == 1">
        <el-form :model="ruleFormTwe" status-icon :rules="rulesTwe" ref="ruleFormTwe" class="demo-ruleForm demoRuleForm">
          <el-form-item label="设置新密码" prop="password">
            <el-tooltip class="item" effect="dark" content="密码必须包含字母(区分大小写)、数字、特殊字符！禁止使用0, o, O, i, I, l, L！" placement="right-start">
              <el-input v-model="ruleFormTwe.password" maxlength="12" placeholder="请输入6-12位密码"></el-input>
            </el-tooltip>
          </el-form-item>
          <el-form-item label="再次输入" prop="newpassword">
            <el-input v-model="ruleFormTwe.newpassword" maxlength="12" placeholder="请输入"></el-input>
          </el-form-item>
        </el-form>
        <div class="gjhqbtn " style="text-align:center;"><el-button class="gjhqprimarybtn" @click="nextTweClick('ruleFormTwe')">下一步</el-button></div>
      </div>
      <div class="gjhqIpt" v-if="forgotPage == 2">
        <div class="chenggong" v-if="jhAcitveShow == true">
          <div class="chenggongIcon"></div>
          <div class="cgTile">设置成功</div>
          <div class="gjhqbtn " style="text-align:center;"><el-button class="gjhqprimarybtn" style="padding:0 50px;" @click="goLoginClick">去登录</el-button></div>
        </div>
        <div class="chenggong" v-else>
          <div class="shibaiIcon"></div>
          <div class="cgTiles">设置失败</div>
          <p>网络无连接，请检查网络连接是否通畅。</p>
          <div class="gjhqbtn " style="text-align:center;"><el-button class="gjhqprimarybtn" style="padding:0 50px;" @click="resetClick">重 试</el-button></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { adminLoginPassword } from '../../axios/api'
import headerlogin from './headerlogin.vue'
export default {
  name: 'forgotpage',
  components: { headerlogin },
  data () {
    return {
      newtime: '',
      ruleFormTwe: {
        password: '',
        newpassword: ''
      },
      rulesTwe: {
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        newpassword: [
          { required: true, message: '请再次输入密码', trigger: 'blur' }
        ]
      },
      forgotPage: 1,
      timers: 60,
      yzmShow: true,
      jhAcitveShow: true
    }
  },
  methods: {
    logotabCLick (indx) {
      this.$router.push({name: 'register'})
    },
    nextTweClick  (formName) {
      let that = this
      that.$refs[formName].validate((valid) => {
        if (valid) {
          let obj = that.ruleFormTwe
          if (obj.password != obj.newpassword) {
            that.$messageOne({message: '两个密码必须一直！', type: 'error', duration: 3000})
            return false
          }
          let lent = obj.password.length
          if (lent < 6) {
            that.$messageOne({message: '密码必须大于6位小于12位！', type: 'error', duration: 3000})
            return false
          }
          const regex = /^(?=.*[a-hj-km-np-z])(?=.*[A-HJ-KM-NP-Z])(?=.*[1-9])(?=.*[@~$!%*?&#^])[A-HJ-KM-NP-Za-hj-km-np-z1-9@~$!%*?&#^]{6,12}$/
          if (regex.test(obj.password)) {
          } else {
            that.$messageOne({message: '密码必密码必须包含字母(区分大小写)、数字、特殊字符！禁止使用0, o, O, i, I, l, L须包含字母(区分大小写)、数字、特殊字符！', type: 'error', duration: 3000})
            return false
          }
          let objs = {}
          objs.password = that.ruleFormTwe.password
          objs.password_confirmation = that.ruleFormTwe.newpassword
          adminLoginPassword(objs).then(res => {
            if (res.code == 10000) {
              that.forgotPage = 2
              that.jhAcitveShow = true
            } else {
              that.forgotPage = 2
              that.jhAcitveShow = false
              that.$messageOne({message: res.message, type: 'error', duration: 3000})
            }
          }).catch(error => {
            that.forgotPage = 2
            that.$messageOne({message: error, type: 'error', duration: 3000})
          })
        }
      })
    },
    goLoginClick () {
      localStorage.setItem('UserToken', '')
      this.$router.push({name: 'Login'})
    },
    resetClick () {
      this.forgotPage = 1
    },
    djsTime () {
      let that = this
      const interval = setInterval(() => {
        that.timers--
        if (that.timers == 0) {
          clearInterval(interval) // 清除计时器
          that.yzmShow = true
          that.timers = 60 // 重置倒计时时长，根据需要可以省略此行，如果每次点击都应该重新开始倒计时
        }
      }, 1000) // 每秒更新一次倒计时
    },
    yzmClick () {
      this.yzmShow = false
      this.djsTime()
    }
  }
}
</script>
<style scoped>
.loginBox{margin:200px auto 0;width:700px;}
.bzTab{height:70px;margin-bottom:80px;text-align:center;font-size: 16px;color: #161617;line-height: 22px;text-align: center;}
.bzTab .siglist{width:70px;display:inline-block;}
.bzTab .les{margin:0 28px;}
.bzTab .siglist .yuan{display:inline-block;width: 40px;height: 40px;background: #CCCCCC;line-height:40px;text-align:center;color:#fff;font-weight: bold;font-size: 20px;border-radius:50%;margin-bottom:8px;}
.bzTab .siglist .line{width: 100%;height: 3px;background: #CCCCCC;display:inline-block;position:relative;top:-42px;}
.bzTab .siglist .yuan.current,.bzTab .siglist .line.current{background-color:#0071DB;}
.demoRuleForm >>> .el-form-item__label{font-weight: bold;font-size: 16px;color: #161617;line-height: 24px;margin-bottom:8px;}
.demoRuleForm >>> .el-form-item{margin-bottom:40px;}
.noPassword{text-align:right;color:#5C9AEF;}
.loginTips{text-align:center;margin-bottom:10px;}
.yzmBox{position:absolute;bottom:5px;height:30px;line-height:30px;padding:0 20px;right:0;z-index:999;cursor:pointer;color:#0071DB;}
.forgotTil{height: 50px;font-weight: bold;font-size: 36px;color: #161617;line-height: 50px;text-align: center;font-style: normal;margin-bottom:40px;}
.chenggong{text-align:center;}
.chenggong .cgTile{height:32px;font-size: 24px;color: #161617;line-height: 32px;margin:12px 0 24px;}
.chenggong .cgTiles{height:32px;font-size: 24px;color: #161617;line-height: 32px;margin:12px 0;}
.chenggong p{font-size: 14px;color: #808080;line-height: 22px;text-align: center;margin-bottom:24px;}
.chenggongIcon{background:url('../../assets/icon26.png') no-repeat 0 0/100%;display:inline-block;width:54px;height:54px;}
.shibaiIcon{background:url('../../assets/icon27.png') no-repeat 0 0/100%;display:inline-block;width:54px;height:54px;}
</style>
