groupon.vue 15 KB

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