groupon.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <!-- 拼团商品详情 -->
  2. <template>
  3. <s-layout :onShareAppMessage="shareInfo" navbar="goods">
  4. <!-- 标题栏 -->
  5. <detailNavbar />
  6. <!-- 骨架屏 -->
  7. <detailSkeleton v-if="state.skeletonLoading" />
  8. <!-- 下架/售罄提醒 -->
  9. <s-empty
  10. v-else-if="
  11. state.goodsInfo === null ||
  12. state.activity.status !== 0 ||
  13. state.activity.endTime < new Date().getTime()
  14. "
  15. text="活动不存在或已结束"
  16. icon="/static/soldout-empty.png"
  17. showAction
  18. actionText="返回上一页"
  19. @clickAction="sheep.$router.back()"
  20. />
  21. <block v-else>
  22. <view class="detail-swiper-selector">
  23. <!-- 商品图轮播 -->
  24. <su-swiper
  25. class="ss-m-b-14"
  26. isPreview
  27. :list="state.goodsSwiper"
  28. dotStyle="tag"
  29. imageMode="widthFix"
  30. dotCur="bg-mask-40"
  31. :seizeHeight="750"
  32. />
  33. <!-- 价格+标题 -->
  34. <view class="title-card detail-card ss-m-y-14 ss-m-x-20 ss-p-x-20 ss-p-y-34">
  35. <view class="ss-flex ss-row-between ss-m-b-60">
  36. <view>
  37. <view class="price-box ss-flex ss-col-bottom ss-m-b-18">
  38. <view class="price-text ss-m-r-16">
  39. {{ fen2yuan(state.activity.price || state.goodsInfo.price) }}
  40. </view>
  41. <view class="tig ss-flex ss-col-center">
  42. <view class="tig-icon ss-flex ss-col-center ss-row-center">
  43. <view class="groupon-tag">
  44. <image
  45. :src="sheep.$url.static('/static/img/shop/goods/groupon-tag.png')"
  46. ></image>
  47. </view>
  48. </view>
  49. <view class="tig-title">拼团价</view>
  50. </view>
  51. </view>
  52. <view class="ss-flex ss-row-between">
  53. <view class="origin-price ss-flex ss-col-center" v-if="state.goodsInfo.price">
  54. 单买价:
  55. <view class="origin-price-text">
  56. {{ fen2yuan(state.goodsInfo.marketPrice) }}
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="countdown-box" v-if="endTime.ms > 0">
  62. <view class="countdown-title ss-m-b-20">距结束仅剩</view>
  63. <view class="ss-flex countdown-time">
  64. <view class="ss-flex countdown-h">{{ endTime.h }}</view>
  65. <view class="ss-m-x-4">:</view>
  66. <view class="countdown-num ss-flex ss-row-center">{{ endTime.m }}</view>
  67. <view class="ss-m-x-4">:</view>
  68. <view class="countdown-num ss-flex ss-row-center">{{ endTime.s }}</view>
  69. </view>
  70. </view>
  71. <view class="countdown-title" v-else> 活动已结束 </view>
  72. </view>
  73. <view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name }}</view>
  74. <view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
  75. </view>
  76. <!-- 功能卡片 -->
  77. <view class="detail-cell-card detail-card ss-flex-col">
  78. <!-- 规格 -->
  79. <detail-cell-sku :sku="state.selectedSku" @tap="state.showSelectSku = true" />
  80. </view>
  81. <!-- 参团列表 -->
  82. <groupon-card-list v-model="state.activity" @join="onJoinGroupon" />
  83. <!-- 规格与数量弹框 -->
  84. <s-select-groupon-sku
  85. :show="state.showSelectSku"
  86. :goodsInfo="state.goodsInfo"
  87. :grouponAction="state.grouponAction"
  88. :grouponNum="state.grouponNum"
  89. @buy="onBuy"
  90. @change="onSkuChange"
  91. @close="onSkuClose"
  92. />
  93. </view>
  94. <!-- 评价 -->
  95. <detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />
  96. <!-- 详情 -->
  97. <detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
  98. <!-- 商品tabbar -->
  99. <detail-tabbar v-model="state.goodsInfo">
  100. <view class="buy-box ss-flex ss-col-center ss-p-r-20">
  101. <button
  102. class="ss-reset-button origin-price-btn ss-flex-col"
  103. @tap="sheep.$router.go('/pages/goods/index', { id: state.goodsInfo.id })"
  104. >
  105. <view class="btn-price">{{ fen2yuan(state.goodsInfo.marketPrice) }}</view>
  106. <view>原价购买</view>
  107. </button>
  108. <button
  109. class="ss-reset-button btn-tox ss-flex-col"
  110. @tap="onCreateGroupon"
  111. :class="
  112. state.activity.status === 0 && state.goodsInfo.stock !== 0
  113. ? 'check-btn-box'
  114. : 'disabled-btn-box'
  115. "
  116. :disabled="state.goodsInfo.stock === 0 || state.activity.status !== 0"
  117. >
  118. <view class="btn-price">{{
  119. fen2yuan(
  120. state.selectedSku.price * state.selectedSku.count ||
  121. state.activity.price * state.selectedSku.count ||
  122. state.goodsInfo.price * state.selectedSku.count ||
  123. state.goodsInfo.price,
  124. )
  125. }}</view>
  126. <view v-if="state.activity.startTime > new Date().getTime()">未开始</view>
  127. <view v-else-if="state.activity.endTime <= new Date().getTime()">已结束</view>
  128. <view v-else>
  129. <view v-if="state.goodsInfo.stock === 0">已售罄</view>
  130. <view v-else>立即开团</view>
  131. </view>
  132. </button>
  133. </view>
  134. </detail-tabbar>
  135. </block>
  136. </s-layout>
  137. </template>
  138. <script setup>
  139. import { reactive, computed } from 'vue';
  140. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  141. import sheep from '@/sheep';
  142. import { isEmpty } from 'lodash-es';
  143. import detailNavbar from './components/detail/detail-navbar.vue';
  144. import detailCellSku from './components/detail/detail-cell-sku.vue';
  145. import detailTabbar from './components/detail/detail-tabbar.vue';
  146. import detailSkeleton from './components/detail/detail-skeleton.vue';
  147. import detailCommentCard from './components/detail/detail-comment-card.vue';
  148. import detailContentCard from './components/detail/detail-content-card.vue';
  149. import grouponCardList from './components/groupon/groupon-card-list.vue';
  150. import { useDurationTime, formatGoodsSwiper, fen2yuan } from '@/sheep/hooks/useGoods';
  151. import CombinationApi from '@/sheep/api/promotion/combination';
  152. import SpuApi from '@/sheep/api/product/spu';
  153. const headerBg = sheep.$url.css('/static/img/shop/goods/groupon-bg.png');
  154. const btnBg = sheep.$url.css('/static/img/shop/goods/groupon-btn.png');
  155. const disabledBtnBg = sheep.$url.css('/static/img/shop/goods/activity-btn-disabled.png');
  156. const grouponBg = sheep.$url.css('/static/img/shop/goods/groupon-tip-bg.png');
  157. onPageScroll(() => {});
  158. const state = reactive({
  159. skeletonLoading: true, // 骨架屏
  160. goodsId: 0, // 商品ID
  161. goodsInfo: {}, // 商品信息
  162. goodsSwiper: [], // 商品轮播图
  163. showSelectSku: false, // 显示规格弹框
  164. selectedSku: {}, // 选中的规格属性
  165. activity: {}, // 团购活动
  166. grouponId: 0, // 团购ID
  167. grouponNum: 0, // 团购人数
  168. grouponAction: 'create', // 团购操作
  169. combinationHeadId: null, // 拼团团长编号
  170. });
  171. // 倒计时
  172. const endTime = computed(() => {
  173. return useDurationTime(state.activity.endTime);
  174. });
  175. // 规格变更
  176. function onSkuChange(e) {
  177. state.selectedSku = e;
  178. }
  179. function onSkuClose() {
  180. state.showSelectSku = false;
  181. }
  182. // 发起拼团
  183. function onCreateGroupon() {
  184. state.grouponAction = 'create';
  185. state.grouponId = 0;
  186. state.showSelectSku = true;
  187. }
  188. /**
  189. * 去参团
  190. *
  191. * @param record 团长的团购记录
  192. */
  193. function onJoinGroupon(record) {
  194. state.grouponAction = 'join';
  195. state.grouponId = record.activityId;
  196. state.combinationHeadId = record.id;
  197. state.grouponNum = record.userSize;
  198. state.showSelectSku = true;
  199. }
  200. // 立即购买
  201. function onBuy(sku) {
  202. sheep.$router.go('/pages/order/confirm', {
  203. data: JSON.stringify({
  204. order_type: 'goods',
  205. combinationActivityId: state.activity.id,
  206. combinationHeadId: state.combinationHeadId,
  207. items: [
  208. {
  209. skuId: sku.id,
  210. count: sku.count,
  211. },
  212. ],
  213. }),
  214. });
  215. }
  216. // 分享信息
  217. const shareInfo = computed(() => {
  218. if (isEmpty(state.activity)) return {};
  219. return sheep.$platform.share.getShareInfo(
  220. {
  221. title: state.activity.name,
  222. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  223. params: {
  224. page: '3',
  225. query: state.activity.id,
  226. },
  227. },
  228. {
  229. type: 'goods', // 商品海报
  230. title: state.activity.name, // 商品标题
  231. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
  232. price: fen2yuan(state.goodsInfo.price), // 商品价格
  233. marketPrice: fen2yuan(state.goodsInfo.marketPrice), // 商品原价
  234. },
  235. );
  236. });
  237. onLoad(async (options) => {
  238. // 非法参数
  239. if (!options.id) {
  240. state.goodsInfo = null;
  241. return;
  242. }
  243. state.grouponId = options.id;
  244. // 加载活动信息
  245. const { code, data: activity } = await CombinationApi.getCombinationActivity(state.grouponId);
  246. state.activity = activity;
  247. // 加载商品信息
  248. const { data: spu } = await SpuApi.getSpuDetail(activity.spuId);
  249. state.goodsId = spu.id;
  250. // 默认显示最低价
  251. spu.price = activity.products.reduce((min, product) => {
  252. return Math.min(min, product.combinationPrice || Infinity);
  253. }, Infinity);
  254. // 价格、库存使用活动的
  255. spu.skus.forEach((sku) => {
  256. const product = activity.products.find((product) => product.skuId === sku.id);
  257. if (product) {
  258. sku.price = product.combinationPrice;
  259. } else {
  260. // 找不到可能是没配置,则不能发起秒杀
  261. sku.stock = 0;
  262. }
  263. });
  264. // 关闭骨架屏
  265. state.skeletonLoading = false;
  266. if (code === 0) {
  267. state.goodsInfo = spu;
  268. state.grouponNum = activity.userSize;
  269. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  270. } else {
  271. // 未找到商品
  272. state.goodsInfo = null;
  273. }
  274. });
  275. </script>
  276. <style lang="scss" scoped>
  277. .detail-card {
  278. background-color: $white;
  279. margin: 14rpx 20rpx;
  280. border-radius: 10rpx;
  281. overflow: hidden;
  282. }
  283. // 价格标题卡片
  284. .title-card {
  285. width: 710rpx;
  286. box-sizing: border-box;
  287. // height: 320rpx;
  288. background-size: 100% 100%;
  289. border-radius: 10rpx;
  290. background-image: v-bind(headerBg);
  291. background-repeat: no-repeat;
  292. .price-box {
  293. .price-text {
  294. font-size: 30rpx;
  295. font-weight: 500;
  296. color: #fff;
  297. line-height: normal;
  298. font-family: OPPOSANS;
  299. &::before {
  300. content: '¥';
  301. font-size: 30rpx;
  302. }
  303. }
  304. }
  305. .origin-price {
  306. font-size: 24rpx;
  307. font-weight: 400;
  308. color: #fff;
  309. opacity: 0.7;
  310. .origin-price-text {
  311. text-decoration: line-through;
  312. font-family: OPPOSANS;
  313. &::before {
  314. content: '¥';
  315. }
  316. }
  317. }
  318. .tig {
  319. border: 2rpx solid #ffffff;
  320. border-radius: 4rpx;
  321. width: 126rpx;
  322. height: 38rpx;
  323. .tig-icon {
  324. margin-left: -2rpx;
  325. width: 40rpx;
  326. height: 40rpx;
  327. background: #ffffff;
  328. border-radius: 4rpx 0 0 4rpx;
  329. .groupon-tag {
  330. width: 32rpx;
  331. height: 32rpx;
  332. }
  333. }
  334. .tig-title {
  335. font-size: 24rpx;
  336. font-weight: 500;
  337. line-height: normal;
  338. color: #ffffff;
  339. width: 86rpx;
  340. display: flex;
  341. justify-content: center;
  342. align-items: center;
  343. }
  344. }
  345. .countdown-title {
  346. font-size: 26rpx;
  347. font-weight: 500;
  348. color: #ffffff;
  349. }
  350. .countdown-time {
  351. font-size: 26rpx;
  352. font-weight: 500;
  353. color: #ffffff;
  354. .countdown-h {
  355. font-size: 24rpx;
  356. font-family: OPPOSANS;
  357. font-weight: 500;
  358. color: #ffffff;
  359. padding: 0 4rpx;
  360. height: 40rpx;
  361. background: rgba(#000000, 0.1);
  362. border-radius: 6rpx;
  363. }
  364. .countdown-num {
  365. font-size: 24rpx;
  366. font-family: OPPOSANS;
  367. font-weight: 500;
  368. color: #ffffff;
  369. width: 40rpx;
  370. height: 40rpx;
  371. background: rgba(#000000, 0.1);
  372. border-radius: 6rpx;
  373. }
  374. }
  375. .title-text {
  376. font-size: 30rpx;
  377. font-weight: bold;
  378. line-height: 42rpx;
  379. color: #fff;
  380. }
  381. .subtitle-text {
  382. font-size: 26rpx;
  383. font-weight: 400;
  384. color: #ffffff;
  385. line-height: 42rpx;
  386. opacity: 0.9;
  387. }
  388. }
  389. // 购买
  390. .buy-box {
  391. .disabled-btn-box[disabled] {
  392. background-color: transparent;
  393. }
  394. .check-btn-box {
  395. width: 248rpx;
  396. height: 80rpx;
  397. font-size: 24rpx;
  398. font-weight: 600;
  399. margin-left: -36rpx;
  400. background-image: v-bind(btnBg);
  401. background-repeat: no-repeat;
  402. background-size: 100% 100%;
  403. color: #ffffff;
  404. line-height: normal;
  405. border-radius: 0px 40rpx 40rpx 0px;
  406. }
  407. .disabled-btn-box {
  408. width: 248rpx;
  409. height: 80rpx;
  410. font-size: 24rpx;
  411. font-weight: 600;
  412. margin-left: -36rpx;
  413. background-image: v-bind(disabledBtnBg);
  414. background-repeat: no-repeat;
  415. background-size: 100% 100%;
  416. color: #999999;
  417. line-height: normal;
  418. border-radius: 0px 40rpx 40rpx 0px;
  419. }
  420. .origin-price-btn {
  421. width: 236rpx;
  422. height: 80rpx;
  423. background: rgba(#ff5651, 0.1);
  424. color: #ff6000;
  425. border-radius: 40rpx 0px 0px 40rpx;
  426. line-height: normal;
  427. font-size: 24rpx;
  428. font-weight: 500;
  429. .btn-title {
  430. font-size: 28rpx;
  431. }
  432. }
  433. .btn-price {
  434. font-family: OPPOSANS;
  435. &::before {
  436. content: '¥';
  437. }
  438. }
  439. .more-item-box {
  440. .more-item {
  441. width: 156rpx;
  442. height: 58rpx;
  443. font-size: 26rpx;
  444. font-weight: 500;
  445. color: #999999;
  446. border-radius: 10rpx;
  447. }
  448. .more-item-hover {
  449. background: rgba(#ffefe5, 0.32);
  450. color: #ff6000;
  451. }
  452. }
  453. }
  454. .groupon-box {
  455. background: v-bind(grouponBg) no-repeat;
  456. background-size: 100% 100%;
  457. }
  458. //活动卡片
  459. .activity-box {
  460. width: 100%;
  461. height: 80rpx;
  462. box-sizing: border-box;
  463. margin-bottom: 10rpx;
  464. .activity-title {
  465. font-size: 26rpx;
  466. font-weight: 500;
  467. color: #ffffff;
  468. line-height: 42rpx;
  469. .activity-icon {
  470. width: 38rpx;
  471. height: 38rpx;
  472. }
  473. }
  474. .activity-go {
  475. width: 70rpx;
  476. height: 32rpx;
  477. background: #ffffff;
  478. border-radius: 16rpx;
  479. font-weight: 500;
  480. color: #ff6000;
  481. font-size: 24rpx;
  482. line-height: normal;
  483. }
  484. }
  485. .model-box {
  486. .title {
  487. font-size: 36rpx;
  488. font-weight: bold;
  489. color: #333333;
  490. }
  491. .subtitle {
  492. font-size: 26rpx;
  493. font-weight: 500;
  494. color: #333333;
  495. }
  496. }
  497. image {
  498. width: 100%;
  499. height: 100%;
  500. }
  501. </style>