<template>
  <el-form ref="loginForm" label-position="left" label-width="100px" style="width: 400px; margin-left:50px;">
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="email"/>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input type="password" v-model="password"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login()">
        登录
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import Http from '@/js/http'
import Api from '@/js/api'
import {notify} from '@/constants'
import router from '@/router'

export default {
  name: 'login',
  data: function () {
    return {
      email: '',
      password: ''
    }
  },
  methods: {
    login () {
      const loginData = {
        email: this.email,
        password: this.password
      }
      Http.post(Api.LOGIN, loginData).then((res) => {
        if (res.code === 20000) {
          router.back()
        } else {
          notify('error', '登陆失败：' + res.msg)
        }
      }).catch((error) => {
        notify('error', '登陆失败：' + error.data)
      })
    }
  }
}
</script>

<style scoped>

</style>
