product.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script setup>
  2. import { formatNumber } from '@/utils/index'
  3. defineOptions({
  4. name: 'Product', // 商品组件
  5. })
  6. const props = defineProps({
  7. item: {
  8. type: Object,
  9. required: true,
  10. },
  11. titleFontSize: {
  12. type: [Number, String],
  13. default: 22,
  14. },
  15. width: {
  16. type: [Number, String],
  17. default: 260,
  18. },
  19. height: {
  20. type: [Number, String],
  21. default: 260,
  22. },
  23. borderRadius: {
  24. type: [Number, String],
  25. default: 6,
  26. },
  27. })
  28. const emit = defineEmits(['itemClick'])
  29. function handleClick() {
  30. emit('itemClick', props.item)
  31. }
  32. </script>
  33. <template>
  34. <view
  35. class="flex flex-col items-center overflow-hidden"
  36. :style="{
  37. maxWidth: Number.isFinite(width) ? `${width}rpx` : width,
  38. width: Number.isFinite(width) ? `${width}rpx` : width,
  39. borderRadius: Number.isFinite(borderRadius) ? `${borderRadius}rpx` : borderRadius,
  40. }"
  41. @click="handleClick"
  42. >
  43. <view
  44. class="overflow-hidden"
  45. :style="{
  46. maxWidth: Number.isFinite(width) ? `${width}rpx` : width,
  47. width: Number.isFinite(width) ? `${width}rpx` : width,
  48. height: Number.isFinite(height) ? `${height}rpx` : height,
  49. borderTopLeftRadius: Number.isFinite(borderRadius) ? `${borderRadius}rpx` : borderRadius,
  50. borderTopRightRadius: Number.isFinite(borderRadius) ? `${borderRadius}rpx` : borderRadius,
  51. }"
  52. >
  53. <image
  54. :src="item.image"
  55. class="h-full w-full"
  56. mode="aspectFit"
  57. />
  58. </view>
  59. <view
  60. class="box-border w-full bg-white px-14rpx pb-8rpx pt-10rpx"
  61. :style="{
  62. fontSize: Number.isFinite(titleFontSize) ? `${titleFontSize}rpx` : titleFontSize,
  63. borderBottomLeftRadius: Number.isFinite(borderRadius) ? `${borderRadius}rpx` : borderRadius,
  64. borderBottomRightRadius: Number.isFinite(borderRadius) ? `${borderRadius}rpx` : borderRadius,
  65. }"
  66. >
  67. <view class="mb-3px truncate">
  68. {{ item.productName || item.storeName }}
  69. </view>
  70. <view class="flex items-center justify-between">
  71. <view class="text-#FF334A font-bold" :style="{ fontSize: Number.isFinite(titleFontSize) ? `${titleFontSize}rpx` : titleFontSize }">
  72. ৳ {{ formatNumber(item.price) }}
  73. </view>
  74. <view class="text-16rpx text-#898989">
  75. {{ item.sales }} Sold
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <style lang="scss" scoped>
  82. //
  83. </style>