ProductItem.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="product-warp" style="cursor: pointer" @click.stop="openDetail(spuId)">
  3. <!-- 左侧商品图片-->
  4. <div class="product-warp-left mr-24px">
  5. <el-image
  6. :initial-index="0"
  7. :preview-src-list="[picUrl]"
  8. :src="picUrl"
  9. class="product-warp-left-img"
  10. fit="contain"
  11. preview-teleported
  12. @click.stop
  13. />
  14. </div>
  15. <!-- 右侧商品信息 -->
  16. <div class="product-warp-right">
  17. <div class="description">{{ title }}</div>
  18. <div class="my-5px">
  19. <span class="mr-20px">库存: {{ stock || 0 }}</span>
  20. <span>销量: {{ salesCount || 0 }}</span>
  21. </div>
  22. <div class="flex justify-between items-center">
  23. <span class="price">¥{{ fenToYuan(price) }}</span>
  24. <el-button size="small" text type="primary">详情</el-button>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import { fenToYuan } from '@/utils'
  31. const { push } = useRouter()
  32. defineOptions({ name: 'ProductItem' })
  33. defineProps({
  34. spuId: {
  35. type: Number,
  36. default: 0
  37. },
  38. picUrl: {
  39. type: String,
  40. default: 'https://img1.baidu.com/it/u=1601695551,235775011&fm=26&fmt=auto'
  41. },
  42. title: {
  43. type: String,
  44. default: ''
  45. },
  46. price: {
  47. type: [String, Number],
  48. default: ''
  49. },
  50. salesCount: {
  51. type: [String, Number],
  52. default: ''
  53. },
  54. stock: {
  55. type: [String, Number],
  56. default: ''
  57. }
  58. })
  59. /** 查看商品详情 */
  60. const openDetail = (spuId: number) => {
  61. push({ name: 'ProductSpuDetail', params: { id: spuId } })
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .button {
  66. background-color: #007bff;
  67. color: white;
  68. border: none;
  69. padding: 5px 10px;
  70. cursor: pointer;
  71. }
  72. .product-warp {
  73. width: 100%;
  74. background-color: #fff;
  75. border-radius: 8px;
  76. display: flex;
  77. align-items: center;
  78. padding: 10px;
  79. &-left {
  80. width: 70px;
  81. &-img {
  82. width: 100%;
  83. height: 100%;
  84. border-radius: 8px;
  85. }
  86. }
  87. &-right {
  88. flex: 1;
  89. .description {
  90. width: 100%;
  91. font-size: 16px;
  92. font-weight: bold;
  93. display: -webkit-box;
  94. -webkit-line-clamp: 1; /* 显示一行 */
  95. -webkit-box-orient: vertical;
  96. overflow: hidden;
  97. text-overflow: ellipsis;
  98. }
  99. .price {
  100. color: #ff3000;
  101. }
  102. }
  103. }
  104. </style>