index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['Forge商城', '商品列表']" />
  4. <a-card>
  5. <a-space size="large">
  6. <a-statistic title="剩余乐跑次数" :value="userCount?.lepao_count" show-group-separator />
  7. </a-space>
  8. </a-card>
  9. <a-card title="商品列表" style="margin-top: 20px;">
  10. <a-list hoverable :loading="loading">
  11. <a-list-item v-for="(item, index) in data" :key="index">
  12. <div class="list">
  13. <div class="icon">
  14. <icon-gift :size="25" />
  15. </div>
  16. <div class="info">
  17. <span class="title">
  18. {{ item.name }}
  19. </span>
  20. <span class="label">
  21. <a-tag size="small">库存:{{ item.num > 99 ? '充足' : item.num }}</a-tag>
  22. ¥ {{ item.price }}
  23. </span>
  24. </div>
  25. <div class="button">
  26. <a-button type="primary" size="small"
  27. @click="$router.push(`/store/goodsDetail/${item.id}`)">查看详情</a-button>
  28. </div>
  29. </div>
  30. </a-list-item>
  31. </a-list>
  32. </a-card>
  33. </div>
  34. </template>
  35. <script setup>
  36. import { ref } from 'vue'
  37. import { getGoodsList, getCount } from '@/api/goods'
  38. import { Notification } from '@arco-design/web-vue'
  39. const data = ref([])
  40. const userCount = ref({})
  41. const loading = ref(false)
  42. const getGoods = async () => {
  43. try {
  44. loading.value = true
  45. const res = await getGoodsList()
  46. if (!res || res.code !== 0)
  47. return Notification.error({
  48. title: '获取商品列表失败!',
  49. content: res?.msg || '请稍后再试'
  50. })
  51. data.value = res.data
  52. } catch (error) {
  53. Notification.error({
  54. title: '获取商品列表失败!',
  55. content: error.message || '请稍后再试'
  56. })
  57. } finally {
  58. loading.value = false
  59. }
  60. }
  61. const GetCount = async () => {
  62. try {
  63. loading.value = true
  64. const res = await getCount()
  65. if (!res || res.code !== 0)
  66. return Notification.error({
  67. title: '获取用户数据失败!',
  68. content: res?.msg || '请稍后再试'
  69. })
  70. userCount.value = res.data
  71. } catch (error) {
  72. Notification.error({
  73. title: '获取用户数据失败!',
  74. content: error.message || '请稍后再试'
  75. })
  76. } finally {
  77. loading.value = false
  78. }
  79. }
  80. getGoods()
  81. GetCount()
  82. </script>
  83. <style lang="less" scoped>
  84. .container {
  85. padding: 0 20px 20px 20px;
  86. }
  87. .list {
  88. display: flex;
  89. min-height: 60px;
  90. align-items: center;
  91. .info {
  92. display: flex;
  93. flex-direction: column;
  94. margin-left: 15px;
  95. margin-right: 15px;
  96. .title {
  97. font-size: 1.3em;
  98. }
  99. }
  100. .button {
  101. margin-left: auto;
  102. }
  103. }
  104. </style>