<script setup lang="ts">
import { ref } from 'vue'
import { Button, Input } from 'ant-design-vue'
import { useRouter } from 'vue-router'
import { sendCode } from '@/api/base/login'
import { useUserStore } from '@/store/moules/userStore/index'
import { useMessage } from '@/hooks/useMessage'
import { GrantTypeEnum, TypeEnum, UserTypeEnum } from '@/enums/commonEnum'

const router = useRouter()
const userStore = useUserStore()
const { createMessage } = useMessage()
const phoneCode = ref('')
function handleLogin() {
  userStore.login({
    user_type: UserTypeEnum.C,
    grant_type: GrantTypeEnum.SMS,
    invite_code: '',
    phone: '13864541890',
    phoneCode: phoneCode.value,
    type: TypeEnum.PHONE,
  }).then(() => {
    createMessage.success('登录成功')
    router.push('/')
  }).catch(() => {
    createMessage.error('登录失败')
  })
}

function handleSendCode() {
  sendCode('13864541890')
}

function handleLogout() {
  userStore.logout()
}
</script>

<template>
  <div>
    我是登录页
    <Input v-model:value="phoneCode" placeholder="请输入验证码" />
    <Button type="primary" @click="handleSendCode">
      发送验证码
    </Button>

    <Button type="primary" @click="handleLogin">
      登录
    </Button>

    <Button type="primary" @click="handleLogout">
      退出
    </Button>
  </div>
</template>

<style scoped></style>
