item.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script lang='ts' setup>
  2. import { computed, defineAsyncComponent, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
  3. import { setBrandFavoriteApi } from '~/api/model/brand'
  4. defineProps({
  5. item: Object as any,
  6. isFavorite: {
  7. type: Boolean,
  8. default: false,
  9. },
  10. })
  11. const emit = defineEmits(['update:favorite', 'click:detail'])
  12. const { openLoginModal } = useLoginModal()
  13. const hoverStatus = ref<any>()
  14. async function onFavorite(item: any) {
  15. try {
  16. const { status } = await openLoginModal()
  17. if (status) {
  18. const params = { bid: item.id, type: item.isFavorite ? 2 : 1 }
  19. await setBrandFavoriteApi(params)
  20. item.isFavorite = !item.isFavorite
  21. ElMessage({
  22. message: `${item.isFavorite ? 'Add' : 'Remove'} to My Favourites Successfully`,
  23. type: 'success',
  24. plain: true,
  25. })
  26. emit('update:favorite', item)
  27. }
  28. }
  29. catch (error) {
  30. console.log(error)
  31. }
  32. }
  33. </script>
  34. <template>
  35. <div>
  36. <div class="custom-main mx-auto overflow-hidden pos-relative">
  37. <h2 class="!mb-20px text-30px fw-800 text-#333 line-clamp-1">
  38. {{ item.brandName }}
  39. </h2>
  40. <img
  41. :src="item.thumbnail || item.masterImage"
  42. alt=""
  43. srcset=""
  44. class="w-260px h-260px object-cover"
  45. >
  46. </div>
  47. </div>
  48. </template>
  49. <style lang="less" scoped>
  50. .custom-main{
  51. background: url('~/assets/images/swiper_bg.png') no-repeat center center;
  52. background-size: cover;
  53. width: 360px;
  54. height: 360px;
  55. border-radius: 10px;
  56. padding: 20px 50px;
  57. box-shadow: 0px 8px 32px 0px rgba(0, 0, 0, 0.16);
  58. }
  59. </style>