s-goods-column.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. <!-- 页面 -->
  2. <template>
  3. <view class="ss-goods-wrap">
  4. <!-- xs卡片:横向紧凑型,一行放两个,图片左内容右边 -->
  5. <view v-if="size === 'xs'" class="xs-goods-card ss-flex ss-col-stretch" :style="[elStyles]" @tap="onClick">
  6. <view v-if="tagStyle.show" class="tag-icon-box">
  7. <image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
  8. </view>
  9. <image class="xs-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="aspectFit" />
  10. <view v-if="goodsFields.title?.show || goodsFields.name?.show || goodsFields.price?.show"
  11. class="xs-goods-content ss-flex-col ss-row-around">
  12. <view v-if="goodsFields.title?.show || goodsFields.name?.show" class="xs-goods-title ss-line-1"
  13. :style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]">
  14. {{ data.title || data.name }}
  15. </view>
  16. <!-- 活动信息 -->
  17. <view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
  18. <view class="card" v-if="discountText">{{ discountText }}</view>
  19. <view class="card2" v-for="item in getRewardActivityRuleItemDescriptions(data.rewardActivity).slice(0, 1)"
  20. :key="item">
  21. {{ item }}
  22. </view>
  23. </view>
  24. <view v-if="goodsFields.price?.show" class="xs-goods-price font-OPPOSANS"
  25. :style="[{ color: goodsFields.price.color }]">
  26. <!-- 活动价格 -->
  27. <view class="ss-flex" v-if="data.activityType && data.activityType === PromotionActivityTypeEnum.POINT.type">
  28. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="point-img"></image>
  29. <text class="point-text ss-m-r-16">
  30. {{ data.point }}
  31. {{ !data.pointPrice || data.pointPrice === 0 ? '' : `+${priceUnit}${fen2yuan(data.pointPrice)}` }}
  32. </text>
  33. </view>
  34. <template v-else>
  35. <text class="price-unit ss-font-24">{{ priceUnit }}</text>
  36. <text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
  37. <text v-else>
  38. {{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
  39. </text>
  40. </template>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- sm卡片:竖向紧凑,一行放三个,图上内容下 -->
  45. <view v-if="size === 'sm'" class="sm-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
  46. <view v-if="tagStyle.show" class="tag-icon-box">
  47. <image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
  48. </view>
  49. <image class="sm-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="aspectFill"></image>
  50. <view v-if="goodsFields.title?.show || goodsFields.name?.show || goodsFields.price?.show" class="sm-goods-content"
  51. :style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]">
  52. <view v-if="goodsFields.title?.show || goodsFields.name?.show" class="sm-goods-title ss-line-1 ss-m-b-16">
  53. {{ data.title || data.name }}
  54. </view>
  55. <!-- 活动信息 -->
  56. <view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
  57. <view class="card" v-if="discountText">{{ discountText }}</view>
  58. <view class="card2" v-for="item in getRewardActivityRuleItemDescriptions(data.rewardActivity).slice(0, 1)"
  59. :key="item">
  60. {{ item }}
  61. </view>
  62. </view>
  63. <view v-if="goodsFields.price?.show" class="sm-goods-price font-OPPOSANS"
  64. :style="[{ color: goodsFields.price.color }]">
  65. <!-- 活动价格 -->
  66. <view class="ss-flex" v-if="data.activityType && data.activityType === PromotionActivityTypeEnum.POINT.type">
  67. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="point-img"></image>
  68. <text class="point-text ss-m-r-16">
  69. {{ data.point }}
  70. {{ !data.pointPrice || data.pointPrice === 0 ? '' : `+${priceUnit}${fen2yuan(data.pointPrice)}` }}
  71. </text>
  72. </view>
  73. <template v-else>
  74. <text class="price-unit ss-font-24">{{ priceUnit }}</text>
  75. <text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
  76. <text v-else>
  77. {{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
  78. </text>
  79. </template>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- md卡片:竖向,一行放两个,图上内容下 -->
  84. <view v-if="size === 'md'" class="md-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
  85. <view v-if="tagStyle.show" class="tag-icon-box">
  86. <image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)" />
  87. </view>
  88. <image class="md-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="widthFix" />
  89. <view class="md-goods-content ss-flex-col ss-row-around ss-p-b-20 ss-p-t-20 ss-p-x-16" :id="elId">
  90. <view v-if="goodsFields.title?.show || goodsFields.name?.show" class="md-goods-title ss-line-1"
  91. :style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]">
  92. {{ data.title || data.name }}
  93. </view>
  94. <view v-if="goodsFields.subtitle?.show || goodsFields.introduction?.show"
  95. class="md-goods-subtitle ss-m-t-16 ss-line-1"
  96. :style="[{ color: subTitleColor, background: subTitleBackground }]">
  97. {{ data.subtitle || data.introduction }}
  98. </view>
  99. <slot name="activity">
  100. <view v-if="data.promos?.length" class="tag-box ss-flex-wrap ss-flex ss-col-center">
  101. <view class="activity-tag ss-m-r-10 ss-m-t-16" v-for="item in data.promos" :key="item.id">
  102. {{ item.title }}
  103. </view>
  104. </view>
  105. </slot>
  106. <!-- 活动信息 -->
  107. <view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
  108. <view class="card" v-if="discountText">{{ discountText }}</view>
  109. <view class="card2" v-for="item in getRewardActivityRuleItemDescriptions(data.rewardActivity).slice(0, 1)"
  110. :key="item">
  111. {{ item }}
  112. </view>
  113. </view>
  114. <view class="ss-flex ss-col-bottom">
  115. <view v-if="goodsFields.price?.show" class="md-goods-price ss-m-t-16 font-OPPOSANS ss-m-r-10"
  116. :style="[{ color: goodsFields.price.color }]">
  117. <!-- 活动价格 -->
  118. <view class="ss-flex"
  119. v-if="data.activityType && data.activityType === PromotionActivityTypeEnum.POINT.type">
  120. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="point-img"></image>
  121. <text class="point-text ss-m-r-16">
  122. {{ data.point }}
  123. {{ !data.pointPrice || data.pointPrice === 0 ? '' : `+${priceUnit}${fen2yuan(data.pointPrice)}` }}
  124. </text>
  125. </view>
  126. <template v-else>
  127. <text class="price-unit ss-font-24">{{ priceUnit }}</text>
  128. <text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
  129. <text v-else>
  130. {{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
  131. </text>
  132. </template>
  133. </view>
  134. <view v-if="
  135. (goodsFields.original_price?.show || goodsFields.marketPrice?.show) &&
  136. (data.original_price > 0 || data.marketPrice > 0)
  137. " class="goods-origin-price ss-m-t-16 font-OPPOSANS ss-flex" :style="[{ color: originPriceColor }]">
  138. <text class="price-unit ss-font-20">{{ priceUnit }}</text>
  139. <view class="ss-m-l-8">{{ fen2yuan(data.marketPrice) }}</view>
  140. </view>
  141. </view>
  142. <view class="ss-m-t-16 ss-flex ss-col-center ss-flex-wrap">
  143. <view class="sales-text">{{ salesAndStock }}</view>
  144. </view>
  145. </view>
  146. <slot name="cart">
  147. <view class="cart-box ss-flex ss-col-center ss-row-center">
  148. <image class="cart-icon" src="/static/img/shop/tabbar/category2.png" mode="" />
  149. </view>
  150. </slot>
  151. </view>
  152. <!-- lg卡片:横向型,一行放一个,图片左内容右边 -->
  153. <view v-if="size === 'lg'" class="lg-goods-card ss-flex ss-col-stretch" :style="[elStyles]" @tap="onClick">
  154. <view v-if="tagStyle.show" class="tag-icon-box">
  155. <image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
  156. </view>
  157. <view v-if="seckillTag" class="seckill-tag ss-flex ss-row-center">秒杀</view>
  158. <view v-if="grouponTag" class="groupon-tag ss-flex ss-row-center">
  159. <view class="tag-icon">拼团</view>
  160. </view>
  161. <image class="lg-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="aspectFill" />
  162. <view class="lg-goods-content ss-flex-1 ss-flex-col ss-row-between ss-p-b-10 ss-p-t-20">
  163. <view>
  164. <view v-if="goodsFields.title?.show || goodsFields.name?.show" class="lg-goods-title ss-line-2"
  165. :style="[{ color: titleColor }]">
  166. {{ data.title || data.name }}
  167. </view>
  168. <view v-if="goodsFields.subtitle?.show || goodsFields.introduction?.show"
  169. class="lg-goods-subtitle ss-m-t-10 ss-line-1"
  170. :style="[{ color: subTitleColor, background: subTitleBackground }]">
  171. {{ data.subtitle || data.introduction }}
  172. </view>
  173. </view>
  174. <view>
  175. <slot name="activity">
  176. <view v-if="data.promos?.length" class="tag-box ss-flex ss-col-center">
  177. <view class="activity-tag ss-m-r-10" v-for="item in data.promos" :key="item.id">
  178. {{ item.title }}
  179. </view>
  180. </view>
  181. </slot>
  182. <!-- 活动信息 -->
  183. <view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
  184. <view class="card" v-if="discountText">{{ discountText }}</view>
  185. <view class="card2" v-for="item in getRewardActivityRuleItemDescriptions(data.rewardActivity).slice(0, 1)"
  186. :key="item">
  187. {{ item }}
  188. </view>
  189. </view>
  190. <view v-if="goodsFields.price?.show" class="ss-flex ss-col-bottom font-OPPOSANS">
  191. <view class="sl-goods-price ss-m-r-12" :style="[{ color: goodsFields.price.color }]">
  192. <!-- 活动价格 -->
  193. <view class="ss-flex"
  194. v-if="data.activityType && data.activityType === PromotionActivityTypeEnum.POINT.type">
  195. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="point-img"></image>
  196. <text class="point-text ss-m-r-16">
  197. {{ data.point }}
  198. {{ !data.pointPrice || data.pointPrice === 0 ? '' : `+${priceUnit}${fen2yuan(data.pointPrice)}` }}
  199. </text>
  200. </view>
  201. <template v-else>
  202. <text class="price-unit ss-font-24">{{ priceUnit }}</text>
  203. <text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
  204. <text v-else>
  205. {{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
  206. </text>
  207. </template>
  208. </view>
  209. <view v-if="
  210. (goodsFields.original_price?.show || goodsFields.marketPrice?.show) &&
  211. (data.original_price > 0 || data.marketPrice > 0)
  212. " class="goods-origin-price ss-m-t-16 font-OPPOSANS ss-flex" :style="[{ color: originPriceColor }]">
  213. <text class="price-unit ss-font-20">{{ priceUnit }}</text>
  214. <view class="ss-m-l-8">{{ fen2yuan(data.marketPrice) }}</view>
  215. </view>
  216. </view>
  217. <view class="ss-m-t-8 ss-flex ss-col-center ss-flex-wrap">
  218. <view class="sales-text">{{ salesAndStock }}</view>
  219. </view>
  220. </view>
  221. </view>
  222. <slot name="cart">
  223. <view class="buy-box ss-flex ss-col-center ss-row-center" v-if="buttonShow"> 去购买</view>
  224. </slot>
  225. </view>
  226. <!-- sl卡片:竖向型,一行放一个,图片上内容下边 -->
  227. <view v-if="size === 'sl'" class="sl-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
  228. <view v-if="tagStyle.show" class="tag-icon-box">
  229. <image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)" />
  230. </view>
  231. <image class="sl-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="aspectFill" />
  232. <view class="sl-goods-content">
  233. <view>
  234. <view v-if="goodsFields.title?.show || goodsFields.name?.show" class="sl-goods-title ss-line-1"
  235. :style="[{ color: titleColor }]">
  236. {{ data.title || data.name }}
  237. </view>
  238. <view v-if="goodsFields.subtitle?.show || goodsFields.introduction?.show" class="sl-goods-subtitle ss-m-t-16"
  239. :style="[{ color: subTitleColor, background: subTitleBackground }]">
  240. {{ data.subtitle || data.introduction }}
  241. </view>
  242. </view>
  243. <view>
  244. <slot name="activity">
  245. <view v-if="data.promos?.length" class="tag-box ss-flex ss-col-center ss-flex-wrap">
  246. <view class="activity-tag ss-m-r-10 ss-m-t-16" v-for="item in data.promos" :key="item.id">
  247. {{ item.title }}
  248. </view>
  249. </view>
  250. </slot>
  251. <!-- 活动信息 -->
  252. <view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
  253. <view class="card" v-if="discountText">{{ discountText }}</view>
  254. <view class="card2" v-for="item in getRewardActivityRuleItemDescriptions(data.rewardActivity).slice(0, 1)"
  255. :key="item">
  256. {{ item }}
  257. </view>
  258. </view>
  259. <view v-if="goodsFields.price?.show" class="ss-flex ss-col-bottom font-OPPOSANS">
  260. <view class="sl-goods-price ss-m-r-12" :style="[{ color: goodsFields.price.color }]">
  261. <!-- 活动价格 -->
  262. <view class="ss-flex"
  263. v-if="data.activityType && data.activityType === PromotionActivityTypeEnum.POINT.type">
  264. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="point-img"></image>
  265. <text class="ss-m-r-16">
  266. {{ data.point }}
  267. {{ !data.pointPrice || data.pointPrice === 0 ? '' : `+${priceUnit}${fen2yuan(data.pointPrice)}` }}
  268. </text>
  269. </view>
  270. <template v-else>
  271. <text class="price-unit ss-font-24">{{ priceUnit }}</text>
  272. <text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
  273. <text v-else>
  274. {{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
  275. </text>
  276. </template>
  277. </view>
  278. <view v-if="
  279. (goodsFields.original_price?.show || goodsFields.marketPrice?.show) &&
  280. (data.original_price > 0 || data.marketPrice > 0)
  281. " class="goods-origin-price ss-m-t-16 font-OPPOSANS ss-flex" :style="[{ color: originPriceColor }]">
  282. <text class="price-unit ss-font-20">{{ priceUnit }}</text>
  283. <view class="ss-m-l-8">{{ fen2yuan(data.marketPrice) }}</view>
  284. </view>
  285. </view>
  286. <view class="ss-m-t-16 ss-flex ss-flex-wrap">
  287. <view class="sales-text">{{ salesAndStock }}</view>
  288. </view>
  289. </view>
  290. </view>
  291. <slot name="cart">
  292. <view class="buy-box ss-flex ss-col-center ss-row-center">去购买</view>
  293. </slot>
  294. </view>
  295. </view>
  296. </template>
  297. <script setup>
  298. /**
  299. * 商品卡片
  300. *
  301. * @property {Array} size = [xs | sm | md | lg | sl ] - 列表数据
  302. * @property {String} tag - md及以上才有
  303. * @property {String} img - 图片
  304. * @property {String} background - 背景色
  305. * @property {String} topRadius - 上圆角
  306. * @property {String} bottomRadius - 下圆角
  307. * @property {String} title - 标题
  308. * @property {String} titleColor - 标题颜色
  309. * @property {Number} titleWidth = 0 - 标题宽度,默认0,单位rpx
  310. * @property {String} subTitle - 副标题
  311. * @property {String} subTitleColor - 副标题颜色
  312. * @property {String} subTitleBackground - 副标题背景
  313. * @property {String | Number} price - 价格
  314. * @property {String} priceColor - 价格颜色
  315. * @property {String | Number} originPrice - 原价/划线价
  316. * @property {String} originPriceColor - 原价颜色
  317. * @property {String | Number} sales - 销售数量
  318. * @property {String} salesColor - 销售数量颜色
  319. *
  320. * @slots activity - 活动插槽
  321. * @slots cart - 购物车插槽,默认包含文字,背景色,文字颜色 || 图片 || 行为
  322. *
  323. * @event {Function()} click - 点击卡片
  324. *
  325. */
  326. import { computed, getCurrentInstance, nextTick, onMounted } from 'vue';
  327. import sheep from '@/sheep';
  328. import {
  329. fen2yuan,
  330. formatExchange,
  331. formatSales,
  332. formatStock,
  333. getRewardActivityRuleItemDescriptions,
  334. } from '@/sheep/hooks/useGoods';
  335. import { isArray } from 'lodash-es';
  336. import { PromotionActivityTypeEnum } from '@/sheep/util/const';
  337. // 接收参数
  338. const props = defineProps({
  339. goodsFields: {
  340. type: [Array, Object],
  341. default() {
  342. return {
  343. // 商品价格
  344. price: {
  345. show: true,
  346. },
  347. // 库存
  348. stock: {
  349. show: true,
  350. },
  351. // 商品名称
  352. name: {
  353. show: true,
  354. },
  355. // 商品介绍
  356. introduction: {
  357. show: true,
  358. },
  359. // 市场价
  360. marketPrice: {
  361. show: true,
  362. },
  363. // 销量
  364. salesCount: {
  365. show: true,
  366. },
  367. };
  368. },
  369. },
  370. tagStyle: {
  371. type: Object,
  372. default: () => ({}),
  373. },
  374. data: {
  375. type: Object,
  376. default: () => ({}),
  377. },
  378. size: {
  379. type: String,
  380. default: 'sl',
  381. },
  382. background: {
  383. type: String,
  384. default: '',
  385. },
  386. topRadius: {
  387. type: Number,
  388. default: 0,
  389. },
  390. bottomRadius: {
  391. type: Number,
  392. default: 0,
  393. },
  394. titleWidth: {
  395. type: Number,
  396. default: 0,
  397. },
  398. titleColor: {
  399. type: String,
  400. default: '#333',
  401. },
  402. priceColor: {
  403. type: String,
  404. default: '',
  405. },
  406. originPriceColor: {
  407. type: String,
  408. default: '#C4C4C4',
  409. },
  410. priceUnit: {
  411. type: String,
  412. default: '¥',
  413. },
  414. subTitleColor: {
  415. type: String,
  416. default: '#999999',
  417. },
  418. subTitleBackground: {
  419. type: String,
  420. default: '',
  421. },
  422. buttonShow: {
  423. type: Boolean,
  424. default: true,
  425. },
  426. seckillTag: {
  427. type: Boolean,
  428. default: false,
  429. },
  430. grouponTag: {
  431. type: Boolean,
  432. default: false,
  433. },
  434. });
  435. // 优惠文案
  436. const discountText = computed(() => {
  437. const promotionType = props.data.promotionType;
  438. if (promotionType === 4) {
  439. return '限时优惠';
  440. } else if (promotionType === 6) {
  441. return '会员价';
  442. }
  443. return undefined;
  444. });
  445. // 组件样式
  446. const elStyles = computed(() => {
  447. return {
  448. background: props.background,
  449. 'border-top-left-radius': props.topRadius + 'px',
  450. 'border-top-right-radius': props.topRadius + 'px',
  451. 'border-bottom-left-radius': props.bottomRadius + 'px',
  452. 'border-bottom-right-radius': props.bottomRadius + 'px',
  453. };
  454. });
  455. // 格式化销量、库存信息
  456. const salesAndStock = computed(() => {
  457. let text = [];
  458. if (props.goodsFields.salesCount?.show) {
  459. if (props.data.activityType && props.data.activityType === PromotionActivityTypeEnum.POINT.type) {
  460. text.push(formatExchange(props.data.sales_show_type, (props.data.pointTotalStock || 0) - (props.data.pointStock || 0)));
  461. } else {
  462. text.push(formatSales(props.data.sales_show_type, props.data.salesCount));
  463. }
  464. }
  465. if (props.goodsFields.stock?.show) {
  466. if (props.data.activityType && props.data.activityType === PromotionActivityTypeEnum.POINT.type) {
  467. text.push(formatStock(props.data.stock_show_type, props.data.pointTotalStock));
  468. } else {
  469. text.push(formatStock(props.data.stock_show_type, props.data.stock));
  470. }
  471. }
  472. return text.join(' | ');
  473. });
  474. // 返回事件
  475. const emits = defineEmits(['click', 'getHeight']);
  476. const onClick = () => {
  477. emits('click');
  478. };
  479. // 获取卡片实时高度
  480. const { proxy } = getCurrentInstance();
  481. const elId = `sheep_${Math.ceil(Math.random() * 10e5).toString(36)}`;
  482. function getGoodsPriceCardWH() {
  483. if (props.size === 'md') {
  484. const view = uni.createSelectorQuery().in(proxy);
  485. view.select(`#${elId}`).fields({
  486. size: true,
  487. scrollOffset: true,
  488. });
  489. view.exec((data) => {
  490. let totalHeight = 0;
  491. const goodsPriceCard = data[0];
  492. if (props.data.image_wh) {
  493. totalHeight =
  494. (goodsPriceCard.width / props.data.image_wh.w) * props.data.image_wh.h +
  495. goodsPriceCard.height;
  496. } else {
  497. totalHeight = goodsPriceCard.width;
  498. }
  499. emits('getHeight', totalHeight);
  500. });
  501. }
  502. }
  503. onMounted(() => {
  504. nextTick(() => {
  505. getGoodsPriceCardWH();
  506. });
  507. });
  508. </script>
  509. <style lang="scss" scoped>
  510. .tag-icon-box {
  511. position: absolute;
  512. left: 0;
  513. top: 0;
  514. z-index: 2;
  515. .tag-icon {
  516. width: 72rpx;
  517. height: 44rpx;
  518. }
  519. }
  520. .seckill-tag {
  521. position: absolute;
  522. left: 0;
  523. top: 0;
  524. z-index: 2;
  525. width: 68rpx;
  526. height: 38rpx;
  527. background: linear-gradient(90deg, #ff5854 0%, #ff2621 100%);
  528. border-radius: 10rpx 0px 10rpx 0px;
  529. font-size: 24rpx;
  530. font-weight: 500;
  531. color: #ffffff;
  532. line-height: 32rpx;
  533. }
  534. .point-img {
  535. width: 30rpx;
  536. height: 30rpx;
  537. margin: 0 4rpx;
  538. }
  539. .groupon-tag {
  540. position: absolute;
  541. left: 0;
  542. top: 0;
  543. z-index: 2;
  544. width: 68rpx;
  545. height: 38rpx;
  546. background: linear-gradient(90deg, #fe832a 0%, #ff6600 100%);
  547. border-radius: 10rpx 0px 10rpx 0px;
  548. font-size: 24rpx;
  549. font-weight: 500;
  550. color: #ffffff;
  551. line-height: 32rpx;
  552. }
  553. .goods-img {
  554. width: 100%;
  555. height: 100%;
  556. background-color: #f5f5f5;
  557. }
  558. .price-unit {
  559. margin-right: -4px;
  560. }
  561. .sales-text {
  562. display: table;
  563. font-size: 24rpx;
  564. transform: scale(0.8);
  565. margin-left: 0rpx;
  566. color: #c4c4c4;
  567. }
  568. .activity-tag {
  569. font-size: 20rpx;
  570. color: #ff0000;
  571. line-height: 30rpx;
  572. padding: 0 10rpx;
  573. border: 1px solid rgba(#ff0000, 0.25);
  574. border-radius: 4px;
  575. flex-shrink: 0;
  576. }
  577. .goods-origin-price {
  578. font-size: 20rpx;
  579. color: #c4c4c4;
  580. line-height: 36rpx;
  581. text-decoration: line-through;
  582. }
  583. // xs
  584. .xs-goods-card {
  585. overflow: hidden;
  586. // max-width: 375rpx;
  587. background-color: $white;
  588. position: relative;
  589. .xs-img-box {
  590. width: 128rpx;
  591. height: 128rpx;
  592. margin-right: 20rpx;
  593. }
  594. .xs-goods-title {
  595. font-size: 26rpx;
  596. color: #333;
  597. font-weight: 500;
  598. }
  599. .xs-goods-price {
  600. font-size: 30rpx;
  601. color: $red;
  602. }
  603. }
  604. // sm
  605. .sm-goods-card {
  606. overflow: hidden;
  607. // width: 223rpx;
  608. // width: 100%;
  609. background-color: $white;
  610. position: relative;
  611. .sm-img-box {
  612. // width: 228rpx;
  613. width: 100%;
  614. height: 208rpx;
  615. }
  616. .sm-goods-content {
  617. padding: 20rpx 16rpx;
  618. box-sizing: border-box;
  619. }
  620. .sm-goods-title {
  621. font-size: 26rpx;
  622. color: #333;
  623. }
  624. .sm-goods-price {
  625. font-size: 30rpx;
  626. color: $red;
  627. }
  628. }
  629. // md
  630. .md-goods-card {
  631. overflow: hidden;
  632. width: 100%;
  633. position: relative;
  634. z-index: 1;
  635. background-color: $white;
  636. position: relative;
  637. .md-img-box {
  638. width: 100%;
  639. }
  640. .md-goods-title {
  641. font-size: 26rpx;
  642. color: #333;
  643. width: 100%;
  644. }
  645. .md-goods-subtitle {
  646. font-size: 24rpx;
  647. font-weight: 400;
  648. color: #999999;
  649. }
  650. .md-goods-price {
  651. font-size: 30rpx;
  652. color: $red;
  653. line-height: 36rpx;
  654. }
  655. .cart-box {
  656. width: 54rpx;
  657. height: 54rpx;
  658. background: linear-gradient(90deg, #fe8900, #ff5e00);
  659. border-radius: 50%;
  660. position: absolute;
  661. bottom: 50rpx;
  662. right: 20rpx;
  663. z-index: 2;
  664. .cart-icon {
  665. width: 30rpx;
  666. height: 30rpx;
  667. }
  668. }
  669. }
  670. // lg
  671. .lg-goods-card {
  672. overflow: hidden;
  673. position: relative;
  674. z-index: 1;
  675. background-color: $white;
  676. height: 280rpx;
  677. .lg-img-box {
  678. width: 280rpx;
  679. height: 280rpx;
  680. margin-right: 20rpx;
  681. }
  682. .lg-goods-title {
  683. font-size: 28rpx;
  684. font-weight: 500;
  685. color: #333333;
  686. // line-height: 36rpx;
  687. // width: 410rpx;
  688. }
  689. .lg-goods-subtitle {
  690. font-size: 24rpx;
  691. font-weight: 400;
  692. color: #999999;
  693. // line-height: 30rpx;
  694. // width: 410rpx;
  695. }
  696. .lg-goods-price {
  697. font-size: 30rpx;
  698. color: $red;
  699. line-height: 36rpx;
  700. }
  701. .buy-box {
  702. position: absolute;
  703. bottom: 20rpx;
  704. right: 20rpx;
  705. z-index: 2;
  706. width: 120rpx;
  707. height: 50rpx;
  708. background: linear-gradient(90deg, #fe8900, #ff5e00);
  709. border-radius: 25rpx;
  710. font-size: 24rpx;
  711. color: #ffffff;
  712. }
  713. .tag-box {
  714. width: 100%;
  715. }
  716. }
  717. // sl
  718. .sl-goods-card {
  719. overflow: hidden;
  720. position: relative;
  721. z-index: 1;
  722. width: 100%;
  723. background-color: $white;
  724. .sl-goods-content {
  725. padding: 20rpx 20rpx;
  726. box-sizing: border-box;
  727. }
  728. .sl-img-box {
  729. width: 100%;
  730. height: 360rpx;
  731. }
  732. .sl-goods-title {
  733. font-size: 26rpx;
  734. color: #333;
  735. font-weight: 500;
  736. }
  737. .sl-goods-subtitle {
  738. font-size: 24rpx;
  739. font-weight: 400;
  740. color: #999999;
  741. line-height: 30rpx;
  742. }
  743. .sl-goods-price {
  744. font-size: 30rpx;
  745. color: $red;
  746. line-height: 36rpx;
  747. }
  748. .buy-box {
  749. position: absolute;
  750. bottom: 20rpx;
  751. right: 20rpx;
  752. z-index: 2;
  753. width: 148rpx;
  754. height: 50rpx;
  755. background: linear-gradient(90deg, #fe8900, #ff5e00);
  756. border-radius: 25rpx;
  757. font-size: 24rpx;
  758. color: #ffffff;
  759. }
  760. }
  761. .card {
  762. width: fit-content;
  763. height: fit-content;
  764. padding: 2rpx 10rpx;
  765. background-color: red;
  766. color: #ffffff;
  767. font-size: 24rpx;
  768. margin-top: 5rpx;
  769. }
  770. .card2 {
  771. width: fit-content;
  772. height: fit-content;
  773. padding: 2rpx 10rpx;
  774. background-color: rgb(255, 242, 241);
  775. color: #ff2621;
  776. font-size: 24rpx;
  777. margin: 5rpx 0 5rpx 5rpx;
  778. }
  779. .iconBox {
  780. width: 100%;
  781. height: fit-content;
  782. margin-top: 10rpx;
  783. display: flex;
  784. justify-content: flex-start;
  785. flex-wrap: wrap;
  786. }
  787. </style>