<template>
<div class="bg-container">
  <el-card class="box-card">
    <el-form ref="setAccountform" :model="setAccount" :rules="accountRules">
      <div class="title">清华大学企业工作台</div>
      <el-form-item label="账号" prop="user">
        <el-input class="self-input" v-model="setAccount.user" type="text" placeholder="请输入账号" @keyup.enter.native="onSubmitSetAccount"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="pwd">
        <el-input v-model="setAccount.pwd" type="password" placeholder="请输入密码" @keyup.enter.native="onSubmitSetAccount"></el-input>
      </el-form-item>
      <el-button type="primary" @click="onSubmitSetAccount">保存</el-button>
      <div class="forgin-pwd"><span>忘记密码</span></div>
    </el-form>
  </el-card>
  <div class="test-text"><span>测试账号：admin 测试密码：123456</span></div>
</div>
</template>

<script>
  export default {
    data () {
      return {
        setAccount: {},
        accountRules: {
          'user': [
            { required: true, message: '请输入账号', trigger: 'blur' }
          ],
          'pwd': [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      }
    },
    beforeMount () {
    },
    methods: {
      onSubmitSetAccount () {
        this.$refs['setAccountform'].validate((valid) => {
          if (valid) {
            if (this.setAccount.user === 'admin' && this.setAccount.pwd === '123456') {
              /* 跳转 */
              this.$router.push({ path: '/app/news/news-list' })
            } else {
              this.$message.error('用户名或密码错误')
            }
            /* 重置密码 */
            this.$refs['setAccountform'].resetFields()
          } else {
            this.$message.error('请检查输入项，确认无误后，重新提交')
            return false
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  /* 由于压缩后 样式覆盖不上，直接采用 css方式 */
  @import './dialogLogin.css';
</style>
