groupon.vue 17 KB

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