groupon.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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.defaultGrouponNum"
  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. defaultGrouponNum: 0, // 默认团购人数
  200. grouponNum: 0, // 团购人数
  201. grouponAction: 'create', // 团购操作
  202. });
  203. // 商品主价格
  204. const goodsPrice = computed(() => {
  205. if (isEmpty(state.selectedSkuPrice)) {
  206. return formatPrice(state.goodsInfo.price);
  207. }
  208. if(state.grouponNum === 0 && state.grouponType === 'groupon_ladder') {
  209. return formatPrice(state.goodsInfo.price)
  210. }
  211. if (state.grouponType === 'groupon') {
  212. return state.selectedSkuPrice.groupon_price;
  213. }
  214. if (state.grouponType === 'groupon_ladder') {
  215. return state.selectedSkuPrice.ladder_price;
  216. }
  217. return '';
  218. });
  219. // 倒计时
  220. const endTime = computed(() => {
  221. return useDurationTime(state.goodsInfo.activity.end_time);
  222. });
  223. // 规格变更
  224. function onSkuChange(e) {
  225. state.selectedSkuPrice = e;
  226. }
  227. // 阶梯变更
  228. function onLadder(e) {
  229. state.grouponNum = e
  230. }
  231. function onSkuClose() {
  232. state.showSelectSku = false;
  233. }
  234. // 发起拼团
  235. function onCreateGroupon() {
  236. state.grouponAction = 'create';
  237. state.grouponId = 0;
  238. state.showSelectSku = true;
  239. }
  240. // 点击参团
  241. function onJoinGroupon(groupon) {
  242. state.grouponAction = 'join';
  243. state.grouponId = groupon.id;
  244. state.defaultGrouponNum = groupon.num;
  245. state.grouponNum = groupon.num;
  246. state.showSelectSku = true;
  247. }
  248. // 立即购买
  249. function onBuy(e) {
  250. sheep.$router.go('/pages/order/confirm', {
  251. data: JSON.stringify({
  252. order_type: 'goods',
  253. buy_type: 'groupon',
  254. activity_id: state.goodsInfo.activity.id,
  255. groupon_id: state.grouponId,
  256. groupon_num: state.grouponNum,
  257. goods_list: [
  258. {
  259. goods_id: e.goods_id,
  260. goods_num: e.goods_num,
  261. goods_sku_price_id: e.id,
  262. },
  263. ],
  264. }),
  265. });
  266. }
  267. const shareInfo = computed(() => {
  268. if (isEmpty(state.goodsInfo?.activity)) return {};
  269. return sheep.$platform.share.getShareInfo(
  270. {
  271. title: state.goodsInfo.title,
  272. image: sheep.$url.cdn(state.goodsInfo.image),
  273. params: {
  274. page: '3',
  275. query: state.goodsInfo.id + ',' + state.goodsInfo.activity.id,
  276. },
  277. },
  278. {
  279. type: 'goods', // 商品海报
  280. title: state.goodsInfo.title, // 商品标题
  281. image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
  282. price: state.goodsInfo.price[0], // 商品价格
  283. original_price: state.goodsInfo.original_price, // 商品原价
  284. },
  285. );
  286. });
  287. onLoad(async (options) => {
  288. // 非法参数
  289. if (!options.id) {
  290. state.goodsInfo = null;
  291. return;
  292. }
  293. state.goodsId = options.id;
  294. // 加载商品信息
  295. const { error, data } = await sheep.$api.goods.detail(options.id, {
  296. activity_id: options.activity_id,
  297. });
  298. // 关闭骨架屏
  299. state.skeletonLoading = false;
  300. if (error === 0) {
  301. state.goodsInfo = data;
  302. state.grouponType = state.goodsInfo.activity_type;
  303. if (state.grouponType === 'groupon') {
  304. state.defaultGrouponNum = state.goodsInfo.activity.rules.team_num;
  305. state.grouponNum = state.goodsInfo.activity.rules.team_num;
  306. }
  307. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.images);
  308. } else {
  309. // 未找到商品
  310. state.goodsInfo = null;
  311. }
  312. });
  313. </script>
  314. <style lang="scss" scoped>
  315. .detail-card {
  316. background-color: $white;
  317. margin: 14rpx 20rpx;
  318. border-radius: 10rpx;
  319. overflow: hidden;
  320. }
  321. // 价格标题卡片
  322. .title-card {
  323. width: 710rpx;
  324. box-sizing: border-box;
  325. // height: 320rpx;
  326. background-size: 100% 100%;
  327. border-radius: 10rpx;
  328. background-image: v-bind(headerBg);
  329. background-repeat: no-repeat;
  330. .price-box {
  331. .price-text {
  332. font-size: 30rpx;
  333. font-weight: 500;
  334. color: #fff;
  335. line-height: normal;
  336. font-family: OPPOSANS;
  337. &::before {
  338. content: '¥';
  339. font-size: 30rpx;
  340. }
  341. }
  342. }
  343. .origin-price {
  344. font-size: 24rpx;
  345. font-weight: 400;
  346. color: #fff;
  347. opacity: 0.7;
  348. .origin-price-text {
  349. text-decoration: line-through;
  350. font-family: OPPOSANS;
  351. &::before {
  352. content: '¥';
  353. }
  354. }
  355. }
  356. .tig {
  357. border: 2rpx solid #ffffff;
  358. border-radius: 4rpx;
  359. width: 126rpx;
  360. height: 38rpx;
  361. .tig-icon {
  362. margin-left: -2rpx;
  363. width: 40rpx;
  364. height: 40rpx;
  365. background: #ffffff;
  366. border-radius: 4rpx 0 0 4rpx;
  367. .groupon-tag {
  368. width: 32rpx;
  369. height: 32rpx;
  370. }
  371. }
  372. .tig-title {
  373. font-size: 24rpx;
  374. font-weight: 500;
  375. line-height: normal;
  376. color: #ffffff;
  377. width: 86rpx;
  378. display: flex;
  379. justify-content: center;
  380. align-items: center;
  381. }
  382. }
  383. .countdown-title {
  384. font-size: 26rpx;
  385. font-weight: 500;
  386. color: #ffffff;
  387. }
  388. .countdown-time {
  389. font-size: 26rpx;
  390. font-weight: 500;
  391. color: #ffffff;
  392. .countdown-h {
  393. font-size: 24rpx;
  394. font-family: OPPOSANS;
  395. font-weight: 500;
  396. color: #ffffff;
  397. padding: 0 4rpx;
  398. height: 40rpx;
  399. background: rgba(#000000, 0.1);
  400. border-radius: 6rpx;
  401. }
  402. .countdown-num {
  403. font-size: 24rpx;
  404. font-family: OPPOSANS;
  405. font-weight: 500;
  406. color: #ffffff;
  407. width: 40rpx;
  408. height: 40rpx;
  409. background: rgba(#000000, 0.1);
  410. border-radius: 6rpx;
  411. }
  412. }
  413. .title-text {
  414. font-size: 30rpx;
  415. font-weight: bold;
  416. line-height: 42rpx;
  417. color: #fff;
  418. }
  419. .subtitle-text {
  420. font-size: 26rpx;
  421. font-weight: 400;
  422. color: #ffffff;
  423. line-height: 42rpx;
  424. opacity: 0.9;
  425. }
  426. }
  427. // 购买
  428. .buy-box {
  429. .disabled-btn-box[disabled] {
  430. background-color: transparent;
  431. }
  432. .check-btn-box {
  433. width: 248rpx;
  434. height: 80rpx;
  435. font-size: 24rpx;
  436. font-weight: 600;
  437. margin-left: -36rpx;
  438. background-image: v-bind(btnBg);
  439. background-repeat: no-repeat;
  440. background-size: 100% 100%;
  441. color: #ffffff;
  442. line-height: normal;
  443. border-radius: 0px 40rpx 40rpx 0px;
  444. }
  445. .disabled-btn-box {
  446. width: 248rpx;
  447. height: 80rpx;
  448. font-size: 24rpx;
  449. font-weight: 600;
  450. margin-left: -36rpx;
  451. background-image: v-bind(disabledBtnBg);
  452. background-repeat: no-repeat;
  453. background-size: 100% 100%;
  454. color: #999999;
  455. line-height: normal;
  456. border-radius: 0px 40rpx 40rpx 0px;
  457. }
  458. .origin-price-btn {
  459. width: 236rpx;
  460. height: 80rpx;
  461. background: rgba(#ff5651, 0.1);
  462. color: #ff6000;
  463. border-radius: 40rpx 0px 0px 40rpx;
  464. line-height: normal;
  465. font-size: 24rpx;
  466. font-weight: 500;
  467. .btn-title {
  468. font-size: 28rpx;
  469. }
  470. }
  471. .btn-price {
  472. font-family: OPPOSANS;
  473. &::before {
  474. content: '¥';
  475. }
  476. }
  477. .more-item-box {
  478. .more-item {
  479. width: 156rpx;
  480. height: 58rpx;
  481. font-size: 26rpx;
  482. font-weight: 500;
  483. color: #999999;
  484. border-radius: 10rpx;
  485. }
  486. .more-item-hover {
  487. background: rgba(#ffefe5, 0.32);
  488. color: #ff6000;
  489. }
  490. }
  491. }
  492. //秒杀卡片
  493. .seckill-box {
  494. background: v-bind(seckillBg)
  495. no-repeat;
  496. background-size: 100% 100%;
  497. }
  498. .groupon-box {
  499. background: v-bind(grouponBg)
  500. no-repeat;
  501. background-size: 100% 100%;
  502. }
  503. //活动卡片
  504. .activity-box {
  505. width: 100%;
  506. height: 80rpx;
  507. box-sizing: border-box;
  508. margin-bottom: 10rpx;
  509. .activity-title {
  510. font-size: 26rpx;
  511. font-weight: 500;
  512. color: #ffffff;
  513. line-height: 42rpx;
  514. .activity-icon {
  515. width: 38rpx;
  516. height: 38rpx;
  517. }
  518. }
  519. .activity-go {
  520. width: 70rpx;
  521. height: 32rpx;
  522. background: #ffffff;
  523. border-radius: 16rpx;
  524. font-weight: 500;
  525. color: #ff6000;
  526. font-size: 24rpx;
  527. line-height: normal;
  528. }
  529. }
  530. .model-box {
  531. .title {
  532. font-size: 36rpx;
  533. font-weight: bold;
  534. color: #333333;
  535. }
  536. .subtitle {
  537. font-size: 26rpx;
  538. font-weight: 500;
  539. color: #333333;
  540. }
  541. }
  542. image {
  543. width: 100%;
  544. height: 100%;
  545. }
  546. </style>