s-goods-column.vue 26 KB

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