groupon.vue 16 KB

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