groupon.vue 15 KB

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