groupon.vue 15 KB

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