products.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!-- @format -->
  2. <script lang="ts" setup>
  3. import { getCollectionGoodsListApi } from '@/api/model/my'
  4. import { PageSizeEnum } from '~/enums/sizeEnum'
  5. const props = defineProps<{
  6. activeName: string
  7. }>()
  8. const list = ref<any[]>([])
  9. const currentPage = ref(PageSizeEnum.PAGE)
  10. const total = ref()
  11. const page_size = ref(8)
  12. async function getCollectProductsList(pageNo = currentPage.value, pageSize = page_size.value) {
  13. const data: any = await getCollectionGoodsListApi({
  14. pageNo,
  15. pageSize,
  16. })
  17. total.value = data.total
  18. currentPage.value = data.current
  19. list.value = data.records
  20. }
  21. function changePage(current: number, size: number) {
  22. getCollectProductsList(current, size)
  23. }
  24. watch(() => props.activeName, (newVal) => {
  25. if (newVal === 'products')
  26. getCollectProductsList()
  27. }, { immediate: true })
  28. </script>
  29. <template>
  30. <div class="min-h-400px flex items-center">
  31. <div v-if="list.length">
  32. <div class="grid grid-gap-40px grid-cols-4">
  33. <div v-for="item in list" :key="item.id">
  34. <common-goods-item :item />
  35. </div>
  36. </div>
  37. <div class="mt-60px flex justify-center">
  38. <el-pagination
  39. :page-size="page_size"
  40. :pager-count="10"
  41. layout="prev, pager, next"
  42. :total="total" @change="changePage"
  43. />
  44. </div>
  45. </div>
  46. <common-empty v-else />
  47. </div>
  48. </template>
  49. <style lang="less" scoped></style>