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