ProductItem.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div @click.stop="openDetail(props.spuId)" style="cursor: pointer;">
  3. <div>
  4. <slot name="top"></slot>
  5. </div>
  6. <div
  7. :style="[{ borderRadius: radius + 'px', marginBottom: marginBottom + 'px' }]"
  8. class="ss-order-card-warp flex items-stretch justify-between bg-white"
  9. >
  10. <div class="img-box mr-24px">
  11. <el-image
  12. :initial-index="0"
  13. :preview-src-list="[picUrl]"
  14. :src="picUrl"
  15. class="order-img"
  16. fit="contain"
  17. preview-teleported
  18. @click.stop
  19. />
  20. </div>
  21. <div
  22. :style="[{ width: titleWidth ? titleWidth + 'px' : '' }]"
  23. class="box-right flex flex-col justify-between"
  24. >
  25. <div v-if="title" class="title-text ss-line-2">{{ title }}</div>
  26. <div v-if="skuString" class="spec-text mt-8px mb-12px">{{ skuString }}</div>
  27. <div class="groupon-box">
  28. <slot name="groupon"></slot>
  29. </div>
  30. <div class="flex">
  31. <div class="flex items-center">
  32. <div
  33. v-if="price && Number(price) > 0"
  34. :style="[{ color: priceColor }]"
  35. class="price-text flex items-center"
  36. >
  37. ¥{{ fenToYuan(price) }}
  38. </div>
  39. <div v-if="num" class="total-text flex items-center">x {{ num }}</div>
  40. <slot name="priceSuffix"></slot>
  41. </div>
  42. </div>
  43. <div class="tool-box">
  44. <slot name="tool"></slot>
  45. </div>
  46. <div>
  47. <slot name="rightBottom"></slot>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <script lang="ts" setup>
  54. import { fenToYuan } from '@/utils'
  55. const { push } = useRouter()
  56. defineOptions({ name: 'ProductItem' })
  57. const props = defineProps({
  58. spuId: {
  59. type: Number,
  60. default: 0
  61. },
  62. picUrl: {
  63. type: String,
  64. default: 'https://img1.baidu.com/it/u=1601695551,235775011&fm=26&fmt=auto'
  65. },
  66. title: {
  67. type: String,
  68. default: ''
  69. },
  70. titleWidth: {
  71. type: Number,
  72. default: 0
  73. },
  74. skuText: {
  75. type: [String, Array],
  76. default: ''
  77. },
  78. price: {
  79. type: [String, Number],
  80. default: ''
  81. },
  82. priceColor: {
  83. type: [String],
  84. default: ''
  85. },
  86. num: {
  87. type: [String, Number],
  88. default: 0
  89. },
  90. score: {
  91. type: [String, Number],
  92. default: ''
  93. },
  94. radius: {
  95. type: [String],
  96. default: ''
  97. },
  98. marginBottom: {
  99. type: [String],
  100. default: ''
  101. }
  102. })
  103. /** SKU 展示字符串 */
  104. const skuString = computed(() => {
  105. if (!props.skuText) {
  106. return ''
  107. }
  108. if (typeof props.skuText === 'object') {
  109. return props.skuText.join(',')
  110. }
  111. return props.skuText
  112. })
  113. /** 查看商品详情 */
  114. const openDetail = (spuId: number) => {
  115. console.log(props.spuId)
  116. push({ name: 'ProductSpuDetail', params: { id: spuId } })
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .ss-order-card-warp {
  121. padding: 20px;
  122. border-radius: 10px;
  123. border: 1px var(--el-border-color) solid;
  124. background-color: var(--app-content-bg-color);
  125. .img-box {
  126. width: 80px;
  127. height: 80px;
  128. border-radius: 10px;
  129. overflow: hidden;
  130. .order-img {
  131. width: 80px;
  132. height: 80px;
  133. }
  134. }
  135. .box-right {
  136. flex: 1;
  137. position: relative;
  138. .tool-box {
  139. position: absolute;
  140. right: 0;
  141. bottom: -10px;
  142. }
  143. }
  144. .title-text {
  145. font-size: 13px;
  146. font-weight: 500;
  147. line-height: 20px;
  148. }
  149. .spec-text {
  150. font-size: 10px;
  151. font-weight: 400;
  152. color: #999999;
  153. min-width: 0;
  154. overflow: hidden;
  155. text-overflow: ellipsis;
  156. display: -webkit-box;
  157. -webkit-line-clamp: 1;
  158. -webkit-box-orient: vertical;
  159. }
  160. .price-text {
  161. font-size: 11px;
  162. font-weight: 500;
  163. font-family: OPPOSANS;
  164. }
  165. .total-text {
  166. font-size: 10px;
  167. font-weight: 400;
  168. line-height: 16px;
  169. color: #999999;
  170. margin-left: 8px;
  171. }
  172. }
  173. .ss-line {
  174. min-width: 0;
  175. overflow: hidden;
  176. text-overflow: ellipsis;
  177. display: -webkit-box;
  178. -webkit-box-orient: vertical;
  179. &-1 {
  180. -webkit-line-clamp: 1;
  181. }
  182. &-2 {
  183. -webkit-line-clamp: 2;
  184. }
  185. }
  186. </style>