<template>
  <a-card class="card">
    <a-space size="large">
      <a-statistic title="剩余乐跑次数" :value="userCount?.lepao_count" show-group-separator />
      <a-button type="primary" size="large" @click="$router.push('/store/goodsList')" style="margin-left: 20px;"><icon-gift /> 去购买</a-button>
    </a-space>
  </a-card>
</template>

<script setup>
import { ref } from 'vue'
import { useUserStore } from '@/store/modules/user'
import { getCount } from '@/api/goods'
import { Notification } from '@arco-design/web-vue'

const userCount = ref({})
const loading = ref(false)

const user = ref('')
const getuser = async () => {
  const userStore = useUserStore()
  let userInfo = await userStore.getInfo()
  user.value = userInfo
}

const GetCount = async () => {
  try {
    loading.value = true
    const res = await getCount()
    if (!res || res.code !== 0)
      return Notification.error({
        title: '获取用户数据失败！',
        content: res.msg || '请稍后再试'
      })
    userCount.value = res.data
  } catch (error) {
    Notification.error({
      title: '获取用户数据失败！',
      content: error.message || '请稍后再试'
    })
  } finally {
    loading.value = false
  }
}

GetCount()
getuser()
</script>

<style scoped lang="less"></style>
