groupon.vue 16 KB

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