groupon.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. <!-- 轮播 -->
  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/img/shop/goods/groupon-bg.png');
  147. const btnBg = sheep.$url.css('/static/img/shop/goods/groupon-btn.png');
  148. const disabledBtnBg = sheep.$url.css(
  149. '/static/img/shop/goods/activity-btn-disabled.png',
  150. );
  151. const grouponBg = sheep.$url.css('/static/img/shop/goods/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. const shareInfo = computed(() => {
  212. if (isEmpty(state.activity)) return {};
  213. return sheep.$platform.share.getShareInfo(
  214. {
  215. title: state.activity.name,
  216. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  217. params: {
  218. page: '3',
  219. query: state.activity.id,
  220. },
  221. },
  222. {
  223. type: 'goods', // 商品海报
  224. title: state.activity.name, // 商品标题
  225. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
  226. price: fen2yuan(state.goodsInfo.price), // 商品价格
  227. marketPrice: fen2yuan(state.goodsInfo.marketPrice), // 商品原价
  228. },
  229. );
  230. });
  231. onLoad(async (options) => {
  232. // 非法参数
  233. if (!options.id) {
  234. state.goodsInfo = null;
  235. return;
  236. }
  237. state.grouponId = options.id;
  238. // 加载活动信息
  239. const { code, data: activity } = await CombinationApi.getCombinationActivity(state.grouponId);
  240. state.activity = activity;
  241. // 加载商品信息
  242. const { data: spu } = await SpuApi.getSpuDetail(activity.spuId);
  243. state.goodsId = spu.id;
  244. activity.products.forEach(product => {
  245. spu.price = Math.min(spu.price, product.combinationPrice); // 设置 SPU 的最低价格
  246. });
  247. // 关闭骨架屏
  248. state.skeletonLoading = false;
  249. if (code === 0) {
  250. state.goodsInfo = spu;
  251. state.grouponNum = activity.userSize;
  252. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  253. } else {
  254. // 未找到商品
  255. state.goodsInfo = null;
  256. }
  257. });
  258. </script>
  259. <style lang="scss" scoped>
  260. .detail-card {
  261. background-color: $white;
  262. margin: 14rpx 20rpx;
  263. border-radius: 10rpx;
  264. overflow: hidden;
  265. }
  266. // 价格标题卡片
  267. .title-card {
  268. width: 710rpx;
  269. box-sizing: border-box;
  270. // height: 320rpx;
  271. background-size: 100% 100%;
  272. border-radius: 10rpx;
  273. background-image: v-bind(headerBg);
  274. background-repeat: no-repeat;
  275. .price-box {
  276. .price-text {
  277. font-size: 30rpx;
  278. font-weight: 500;
  279. color: #fff;
  280. line-height: normal;
  281. font-family: OPPOSANS;
  282. &::before {
  283. content: '¥';
  284. font-size: 30rpx;
  285. }
  286. }
  287. }
  288. .origin-price {
  289. font-size: 24rpx;
  290. font-weight: 400;
  291. color: #fff;
  292. opacity: 0.7;
  293. .origin-price-text {
  294. text-decoration: line-through;
  295. font-family: OPPOSANS;
  296. &::before {
  297. content: '¥';
  298. }
  299. }
  300. }
  301. .tig {
  302. border: 2rpx solid #ffffff;
  303. border-radius: 4rpx;
  304. width: 126rpx;
  305. height: 38rpx;
  306. .tig-icon {
  307. margin-left: -2rpx;
  308. width: 40rpx;
  309. height: 40rpx;
  310. background: #ffffff;
  311. border-radius: 4rpx 0 0 4rpx;
  312. .groupon-tag {
  313. width: 32rpx;
  314. height: 32rpx;
  315. }
  316. }
  317. .tig-title {
  318. font-size: 24rpx;
  319. font-weight: 500;
  320. line-height: normal;
  321. color: #ffffff;
  322. width: 86rpx;
  323. display: flex;
  324. justify-content: center;
  325. align-items: center;
  326. }
  327. }
  328. .countdown-title {
  329. font-size: 26rpx;
  330. font-weight: 500;
  331. color: #ffffff;
  332. }
  333. .countdown-time {
  334. font-size: 26rpx;
  335. font-weight: 500;
  336. color: #ffffff;
  337. .countdown-h {
  338. font-size: 24rpx;
  339. font-family: OPPOSANS;
  340. font-weight: 500;
  341. color: #ffffff;
  342. padding: 0 4rpx;
  343. height: 40rpx;
  344. background: rgba(#000000, 0.1);
  345. border-radius: 6rpx;
  346. }
  347. .countdown-num {
  348. font-size: 24rpx;
  349. font-family: OPPOSANS;
  350. font-weight: 500;
  351. color: #ffffff;
  352. width: 40rpx;
  353. height: 40rpx;
  354. background: rgba(#000000, 0.1);
  355. border-radius: 6rpx;
  356. }
  357. }
  358. .title-text {
  359. font-size: 30rpx;
  360. font-weight: bold;
  361. line-height: 42rpx;
  362. color: #fff;
  363. }
  364. .subtitle-text {
  365. font-size: 26rpx;
  366. font-weight: 400;
  367. color: #ffffff;
  368. line-height: 42rpx;
  369. opacity: 0.9;
  370. }
  371. }
  372. // 购买
  373. .buy-box {
  374. .disabled-btn-box[disabled] {
  375. background-color: transparent;
  376. }
  377. .check-btn-box {
  378. width: 248rpx;
  379. height: 80rpx;
  380. font-size: 24rpx;
  381. font-weight: 600;
  382. margin-left: -36rpx;
  383. background-image: v-bind(btnBg);
  384. background-repeat: no-repeat;
  385. background-size: 100% 100%;
  386. color: #ffffff;
  387. line-height: normal;
  388. border-radius: 0px 40rpx 40rpx 0px;
  389. }
  390. .disabled-btn-box {
  391. width: 248rpx;
  392. height: 80rpx;
  393. font-size: 24rpx;
  394. font-weight: 600;
  395. margin-left: -36rpx;
  396. background-image: v-bind(disabledBtnBg);
  397. background-repeat: no-repeat;
  398. background-size: 100% 100%;
  399. color: #999999;
  400. line-height: normal;
  401. border-radius: 0px 40rpx 40rpx 0px;
  402. }
  403. .origin-price-btn {
  404. width: 236rpx;
  405. height: 80rpx;
  406. background: rgba(#ff5651, 0.1);
  407. color: #ff6000;
  408. border-radius: 40rpx 0px 0px 40rpx;
  409. line-height: normal;
  410. font-size: 24rpx;
  411. font-weight: 500;
  412. .btn-title {
  413. font-size: 28rpx;
  414. }
  415. }
  416. .btn-price {
  417. font-family: OPPOSANS;
  418. &::before {
  419. content: '¥';
  420. }
  421. }
  422. .more-item-box {
  423. .more-item {
  424. width: 156rpx;
  425. height: 58rpx;
  426. font-size: 26rpx;
  427. font-weight: 500;
  428. color: #999999;
  429. border-radius: 10rpx;
  430. }
  431. .more-item-hover {
  432. background: rgba(#ffefe5, 0.32);
  433. color: #ff6000;
  434. }
  435. }
  436. }
  437. .groupon-box {
  438. background: v-bind(grouponBg)
  439. no-repeat;
  440. background-size: 100% 100%;
  441. }
  442. //活动卡片
  443. .activity-box {
  444. width: 100%;
  445. height: 80rpx;
  446. box-sizing: border-box;
  447. margin-bottom: 10rpx;
  448. .activity-title {
  449. font-size: 26rpx;
  450. font-weight: 500;
  451. color: #ffffff;
  452. line-height: 42rpx;
  453. .activity-icon {
  454. width: 38rpx;
  455. height: 38rpx;
  456. }
  457. }
  458. .activity-go {
  459. width: 70rpx;
  460. height: 32rpx;
  461. background: #ffffff;
  462. border-radius: 16rpx;
  463. font-weight: 500;
  464. color: #ff6000;
  465. font-size: 24rpx;
  466. line-height: normal;
  467. }
  468. }
  469. .model-box {
  470. .title {
  471. font-size: 36rpx;
  472. font-weight: bold;
  473. color: #333333;
  474. }
  475. .subtitle {
  476. font-size: 26rpx;
  477. font-weight: 500;
  478. color: #333333;
  479. }
  480. }
  481. image {
  482. width: 100%;
  483. height: 100%;
  484. }
  485. </style>