groupon.vue 16 KB

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