groupon.vue 16 KB

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