<style lang="less">
  @import './register.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <div class="login-title">PhalApi Pro 管理后台</div>
      <Card icon="log-in" title="欢迎注册" :bordered="false">
        <div class="form-con">
          <register-form @on-success-valid="handleSubmit"></register-form>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import registerForm from '_c/register-form'
import { mapActions } from 'vuex'
import md5 from 'js-md5'
export default {
  components: {
    registerForm
  },
  methods: {
    ...mapActions([
      'handleRegister',
      'getUserInfo'
    ]),
    handleSubmit ({ username, password }) {
      password = md5(password)
      this.handleRegister({ username, password }).then((res) => {
        if (res.ret === 200) {
          this.$Message.success('注册成功，为您跳转至登录页面')
          setTimeout(() => {
            this.$router.push({
              name: 'login'
            })
          }, 1000)
        } else this.$Message.warning(res.data.data.err_msg)
      })
    }
  }
}
</script>

<style>

</style>
