s-goods-column.vue 29 KB

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