<template>
  <div class="login">
    <avue-login :option="option" @submit="submit">
    </avue-login>
  </div>
</template>

<script>
import { settoken } from "../servuces/token";
import { userloginInfo } from "../servuces/prove";
import { stringify } from "qs";
export default {
  data () {
    return {
      codesrc: '',
      form: {},
      option: {
        width: 400,
        time: 60,
        codeType: 'phone', //phone为手机验证码/img为图片验证码
        column: {
          username: {
            // hide: true,
            label: '用户名',
            // prop: 'user',
            // placeholder:'',
            autocomplete: 'off',
            rules: { required: true, message: '请输入用户名', trigger: 'blur' }
          },
          password: {
            label: '密码',
            // prop: 'pass',
            // placeholder:'',
            autocomplete: 'off',
            rules: { required: true, message: '请输入密码', trigger: 'blur' }
          },
          code: {
            hide: true
          }
        }
      },
    }
  },
  methods: {
    async submit (form) {
      // if (form.username == 123 || form.password == 123) {

      //   settoken(123654)
      //   this.$router.replace('/')
      //   this.$message.success('登陆成功')
      // } else {
      //   this.$message.error('密码错误')
      // }

      await userloginInfo(stringify({ username: form.username, password: form.password })).then(res => {
        console.log(res);
        if (res.success) {
          settoken(123654)
          this.$router.replace('/')
        } else {
          alert('res.errors')
        }

      })
    }
  }
}
</script>

<style scoped>
.login {
  width: 500px;
  margin: 200px auto;
}
</style>