groupon.vue 16 KB

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