item.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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-360px h-360px 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"
  48. >
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <style lang="less" scoped>
  54. </style>