product.vue 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <script lang="ts" setup>
  2. import { addBlack } from '@designer-hub/assets/src/assets/svgs'
  3. import { useRouter } from '../../../../core/utils/router'
  4. import { PropType } from 'vue'
  5. import { requestToast } from '../../../../core/utils/common'
  6. import { createProductItemBuy } from '../../../../core/libs/requests'
  7. import { useUserStore } from '../../../../store'
  8. import { storeToRefs } from 'pinia'
  9. import { needLoginPages } from '@/utils'
  10. const props = defineProps({
  11. options: {
  12. type: Object as PropType<any>,
  13. default: () => {},
  14. },
  15. })
  16. const emits = defineEmits<{ change: [] }>()
  17. const userStore = useUserStore()
  18. const { userInfo } = storeToRefs(userStore)
  19. const router = useRouter()
  20. const handleAddToCart = async () => {
  21. await requestToast(
  22. () =>
  23. createProductItemBuy({
  24. doList: [
  25. {
  26. userId: userInfo.value.userId,
  27. productId: props.options?.productId || '',
  28. points: props.options?.points,
  29. nums: 1,
  30. },
  31. ],
  32. }),
  33. { success: true, successTitle: '加入购物车成功' },
  34. )
  35. emits('change')
  36. }
  37. </script>
  38. <template>
  39. <div
  40. class="w-full flex flex-col gap-2.5"
  41. @click="router.push(`/pages/home/mall/detail/index?id=${options.productId}`)"
  42. >
  43. <div class="bg-[#f6f6f6] rounded-2xl w-full aspect-square overflow-hidden">
  44. <wd-img
  45. width="100%"
  46. height="100%"
  47. :src="options.productCoverImgUrl"
  48. mode="aspectFill"
  49. custom-class="aspect-square"
  50. ></wd-img>
  51. </div>
  52. <div class="flex">
  53. <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-normal line-clamp-1 text-ellipsis overflow-hidden">
  54. <!-- 阿芙佳朵 -->
  55. {{ options.prodcutName }}
  56. </div>
  57. <div class="flex-1"></div>
  58. <div
  59. v-if="Number(options.productPrice)"
  60. class="w-[26px] text-black/30 text-xs font-normal font-['PingFang_SC'] line-through leading-normal"
  61. >
  62. <!-- ¥60 -->
  63. ¥{{ options.productPrice }}
  64. </div>
  65. </div>
  66. <div class="flex items-center mb-6">
  67. <template v-if="String(options.needPoints) === '0'">
  68. <div class="flex items-end gap-1">
  69. <div class="text-[#ef4343] text-[22px] font-normal font-['D-DIN_Exp'] leading-5.5">
  70. <!-- 1000 -->
  71. {{ options.showFavourable ? options.favourablePoints : options.points }}
  72. </div>
  73. <div class="text-black/60 text-sm font-normal font-['PingFang_SC']">积分</div>
  74. </div>
  75. <div class="flex-1"></div>
  76. <div class="" @click.stop="handleAddToCart">
  77. <wd-img width="32" height="32" :src="addBlack"></wd-img>
  78. </div>
  79. </template>
  80. <template v-if="String(options.needPoints) === '1'">
  81. <div class="flex items-end gap-1">
  82. <div class="text-[#ef4343] text-[22px] font-normal font-['D-DIN_Exp'] leading-5.5">
  83. <!-- 1000 -->
  84. {{ options.points }}
  85. </div>
  86. <div class="text-black/60 text-sm font-normal font-['PingFang_SC']">折</div>
  87. <div class="text-black/60 text-sm font-normal font-['PingFang_SC']">(积分结算)</div>
  88. </div>
  89. <div class="flex-1"></div>
  90. <!-- <div class="" @click.stop="handleAddToCart">-->
  91. <!-- <wd-img width="32" height="32" :src="addBlack"></wd-img>-->
  92. <!-- </div>-->
  93. </template>
  94. </div>
  95. </div>
  96. </template>