<template>
  <div class="login-index">
    <div class="ConDivContent_bg">
      <router-view />
    </div>
  </div>
</template>
<script>
/* eslint-disable */
import { login } from 'r/index/login.js'
// import DialogBox from "c/index/register/DialogBox";

export default {
  name: 'loginIndex',
  data () {
    return {
      isShowPwd: true, // 控制密码显示隐藏
      loginForm: {
        username: '',
        password: ''
      },
      // 表单验证规则对象
      loginFormRules: {
        // 对用户名进行校验
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 4, max: 20, message: '请输入正确的用户名', trigger: 'blur' }
        ],
        // 对密码进行校验
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 20, message: '请输入正确的密码', trigger: 'blur' }
        ]
      },
      dialogFormFu: {
        title: '',
        message: ''
      },
      dialogVisibleFu: false
    }
  },
  created () {
    this.$emit('getStatus', false)
  },
  methods: {
    // 忘记账号/密码
    forgetPwd () {
      window.localStorage.setItem('f_forgetpwd', 0)
      this.$router.replace({ name: 'foundback' })
    },
    // 子组件触发，关闭弹框
    closeDialog (value, type) {
      this.dialogVisibleFu = value
      if (type) {
        this.$router.replace({ name: 'StepOne' })
      }
    },
    // 去注册
    register () {
      this.dialogFormFu = {
        title: '提示',
        message: 1
      }
      this.dialogVisibleFu = true
      // this.$router.replace({ name: "StepOne" });
    },
    // 改变密码显示状态
    changePwdStatus () {
      this.isShowPwd = !this.isShowPwd
    },
    // 表单验证
    submitForm () {
      this.$refs.loginFormRef.validate(async (valid) => {
        // 验证用户名和密码是否符合规定
        if (!valid) return

        // 发送请求的操作
        const { data: res } = await login(this.loginForm)
        console.log(res, '返回用户注册数据')
        // 根据返回的状态码做想关的判断
        if (res.code !== 200) {
          return this.$message.error(res.message)
        }

        // 判断用户注册是否填写信息完整
        const applicationstatus = parseInt(res.applicationstatus)
        const can_skip = parseInt(res.can_skip)
        window.localStorage.setItem('applicationstatus', res.applicationstatus)
        window.localStorage.setItem('can_skip', res.can_skip)
        window.localStorage.setItem('is_check_id_card', res.is_check_id_card)
        console.log(!can_skip)
        if (!can_skip) {
          if (applicationstatus == 0) {
            window.localStorage.setItem('sfzNum', res.sfzNum)
            this.$router.replace({
              name: 'StepOne',
              query: { applicationstatus: '0', data: res }
            })
            return
          } else if (
            applicationstatus == 3 ||
            applicationstatus == 4 ||
            applicationstatus == 5 ||
            applicationstatus == 6
          ) {
            window.localStorage.setItem('index-token', res.token)
            this.$store.state.token = res.token
            window.localStorage.setItem('student_id', res.student_id)
            window.localStorage.setItem('sfzNum', res.sfzNum)
            window.localStorage.setItem('username', res.username)
            if (res.is_check_id_card != 1) {
              this.$router.replace({ name: 'StepTwo' })
            } else {
              this.$router.replace({ name: 'StepThree' })
            }
            return
          }
        }
        this.$store.state.token = res.token
        window.localStorage.setItem('index-token', res.token)
        window.localStorage.setItem('student_id', res.student_id)
        window.localStorage.setItem('sfzNum', res.sfzNum)
        window.localStorage.setItem('username', res.username)
        this.$router.replace({ name: 'examlist' })
      })
    }
  }
  // components: {
  //   DialogBox,
  // },
}
</script>

<style scoped lang="scss">
.login-index {

  // height: 1080px;
  background: #F8F8F8;
  .ConDivContent_bg {
   height: 1080px;
    background: url("../../../assets/img/login/left@2x.png") no-repeat center
      center;
    background-size: 100% 100%;
    // position: relative;
    width: 30%;
  }
  // @media screen and (min-width: 1601px) {
  //   .ConDivContent_bg {
  //     height: 650px;
  //     max-height: 650px;
  //   }
  // }
}
</style>
