groupon.vue 17 KB

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