item.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. function toDetail(item: any) {
  34. const router = useRouter()
  35. router.push({ path: `/brand/${item.id}` })
  36. // emit('click:detail', item)
  37. }
  38. </script>
  39. <template>
  40. <div>
  41. <div class="text-left " @click="toDetail(item)">
  42. <div class="b-rd-10px custom-main mx-auto !w-300px h-300px mb-20px overflow-hidden pos-relative">
  43. <img
  44. :src="item.thumbnail || item.masterImage"
  45. alt=""
  46. srcset=""
  47. class="w-100% h-100% object-contain hover-effect"
  48. >
  49. <div
  50. v-if="isFavorite"
  51. class="b-rd-50% custom-like b-1px b-solid w-32px h-32px flex cursor-pointer justify-center items-center bg-#CC9879/10% pos-absolute bottom-20px hover:bg-#CC9879"
  52. :class="item.isFavorite && '!bg-#CC9879'"
  53. @mouseover="hoverStatus = '!fill-#fff'"
  54. @mouseleave="hoverStatus = '!fill-#CC9879'"
  55. @click.stop="onFavorite(item)"
  56. >
  57. <svgo-like
  58. :class="(item.isFavorite && '!fill-#fff') || hoverStatus"
  59. class="!fill-#CC9879 text-16px"
  60. :filled="true"
  61. />
  62. </div>
  63. </div>
  64. <div class="fw-400 text-14px text-#666">
  65. {{ item?.categoryNames ? (item?.categoryNames.join(','))[0] : '' }}
  66. </div>
  67. <h3
  68. class="fw-600 text-24px !my-10px text-#363C40 custom-title-font line-clamp-1"
  69. >
  70. {{ item.brandName }}
  71. </h3>
  72. <div class="text-#999 text-18px mb-20px h-48px lh-24px line-clamp-2">
  73. {{ item.brandStory }}
  74. </div>
  75. <div class="underline text-#C58C64 cursor-pointer">
  76. Shop Now
  77. </div>
  78. </div>
  79. </div>
  80. </template>
  81. <style lang="less" scoped>
  82. .custom-main {
  83. .custom-like {
  84. right: -50px;
  85. opacity: 0;
  86. transition: all 0.3s ease-out;
  87. }
  88. &:hover {
  89. .custom-like {
  90. right: 12px;
  91. opacity: 1;
  92. }
  93. }
  94. }
  95. </style>