<template>
  <div class="container">
    <div class="topHeader">
      <span>登录</span>
    </div>
    <div class="main">
      <div class="logo">
        <img src="@/assets/images/logo.png" alt="" />
      </div>
      <van-form @submit="onSubmit">
        <div class="border">
          <van-field
            v-model="username"
            left-icon="friends"
            placeholder="请输入用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
        </div>
        <div class="border">
          <van-field
            v-model="password"
            :rules="[{ required: true, message: '请填写密码' }]"
            color="#ee0a24"
            type="password"
            left-icon="lock"
            placeholder="请输入密码"
            clearable
          />
        </div>
        <div style="margin: 26px;">
          <van-button round block type="primary" native-type="submit"
            >登录</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { login } from '@/api/emergencies'
export default {
  name: 'VueSkIndex',

  data () {
    return {
      username: 'admin',
      password: 'admin123'
    }
  },

  mounted () {},

  methods: {
    onSubmit (values) {
      if (this.username && this.password) {
        login({ userName: this.username, password: this.password }).then(({ data }) => {
          if (data.code === 200) {
            console.log(data)
            this.$notify({
              type: 'success',
              message: data.msg,
              duration: 1000
            })
            window.sessionStorage.setItem('token', data.data.token)
            this.$router.push('/home')
            Android.setToken(data.data.token)
          }
        })
        // this.$router.push('/home')
      } else {
        this.$notify({
          type: 'warning',
          message: '用户名或密码不能为空！',
          duration: 2000
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
img {
  width: 50%;
  height: 100%;
}
.logo {
  width: 100%;
  height: 150px;
  display: flex;
  justify-content: center;
  margin: 50px 0;
}
.border {
  border: 1px solid #eee;
  border-radius: 5px;
  margin-top: 15px;
}
</style>
