groupon.vue 15 KB

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