<template>
  <el-form ref="loginForm"
           :model="loginForm"
           class="login-form"
           autocomplete="on"
           label-position="left">
    <el-form-item prop="username" key="username">
      <el-input
        suffix-icon="el-icon-user-solid"
        ref="username"
        v-model="loginForm.username"
        :placeholder="'账号'"
        name="username"
        type="text"
        tabindex="1"
        autocomplete="on"
        @keyup.enter.native="handleLogin"
      />
    </el-form-item>

    <el-form-item prop="password" key="password">
      <el-input
        ref="password"
        v-model="loginForm.password"
        :placeholder="'密码'"
        name="password"
        tabindex="2"
        autocomplete="on"
        @keyup.enter.native="handleLogin"
      />
    </el-form-item>
  </el-form>
</template>

<script>
import create from '../utils/create-basic'
import { getRsaCode } from '../utils/auth'
import { login } from '../api'

export default create(
  {
    name: 'login',
    data () {
      return {
        loginForm: {
          username: '111',
          password: '222'
        }
      }
    },
    methods: {
      handleLogin () {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            const data = {}
            data.loginKey = getRsaCode(this.loginForm.username)
            data.password = getRsaCode(this.loginForm.password)
            console.log(login, 'login')
            login(data, { aa: 1 }).then(res => {
              console.log('res', res)
            })
          }
        })
      }
    }
  }
)
</script>

<style scoped>

</style>
