seckill.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <!-- 秒杀商品详情 -->
  2. <template>
  3. <s-layout :onShareAppMessage="shareInfo" navbar="goods">
  4. <!-- 标题栏 -->
  5. <detailNavbar />
  6. <!-- 骨架屏 -->
  7. <detailSkeleton v-if="state.skeletonLoading" />
  8. <!-- 下架/售罄提醒 -->
  9. <s-empty
  10. v-else-if="
  11. state.goodsInfo === null || state.goodsInfo.activity_type !== 'seckill' || endTime.ms <= 0
  12. "
  13. text="活动不存在或已结束"
  14. icon="/static/soldout-empty.png"
  15. showAction
  16. actionText="再逛逛"
  17. actionUrl="/pages/goods/list"
  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 ss-m-y-14 ss-m-x-20 ss-p-x-20 ss-p-y-34">
  33. <view class="price-box ss-flex ss-row-between ss-m-b-18">
  34. <view class="ss-flex">
  35. <view class="price-text ss-m-r-16">
  36. {{ fen2yuan(state.selectedSku.price || state.goodsInfo.price) }}
  37. </view>
  38. <view class="tig ss-flex ss-col-center">
  39. <view class="tig-icon ss-flex ss-col-center ss-row-center">
  40. <text class="cicon-alarm"></text>
  41. </view>
  42. <view class="tig-title">秒杀价</view>
  43. </view>
  44. </view>
  45. <view class="countdown-box" v-if="endTime.ms > 0">
  46. <view class="countdown-title ss-m-b-20">距结束仅剩</view>
  47. <view class="ss-flex countdown-time">
  48. <view class="ss-flex countdown-h">{{ endTime.h }}</view>
  49. <view class="ss-m-x-4">:</view>
  50. <view class="countdown-num ss-flex ss-row-center">{{ endTime.m }}</view>
  51. <view class="ss-m-x-4">:</view>
  52. <view class="countdown-num ss-flex ss-row-center">{{ endTime.s }}</view>
  53. </view>
  54. </view>
  55. <view class="countdown-title" v-else> 活动已结束 </view>
  56. </view>
  57. <view class="ss-flex ss-row-between ss-m-b-60">
  58. <view class="origin-price ss-flex ss-col-center" v-if="state.goodsInfo.marketPrice">
  59. 原价
  60. <view class="origin-price-text">
  61. {{ fen2yuan(state.selectedSku.marketPrice || state.goodsInfo.marketPrice) }}
  62. </view>
  63. </view>
  64. <detail-progress :percent="state.percent" />
  65. </view>
  66. <view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name || '' }}</view>
  67. <view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
  68. </view>
  69. <!-- 功能卡片 -->
  70. <view class="detail-cell-card detail-card ss-flex-col">
  71. <detail-cell-sku :sku="state.selectedSku" @tap="state.showSelectSku = true" />
  72. </view>
  73. <!-- 规格与数量弹框 -->
  74. <s-select-seckill-sku
  75. v-model="state.goodsInfo"
  76. :show="state.showSelectSku"
  77. :single-limit-count="activity.singleLimitCount"
  78. @buy="onBuy"
  79. @change="onSkuChange"
  80. @close="state.showSelectSku = false"
  81. />
  82. </view>
  83. <!-- 评价 -->
  84. <detail-comment-card class="detail-comment-selector" :goodsId="state.goodsInfo.id" />
  85. <!-- 详情 -->
  86. <detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
  87. <!-- 详情tabbar -->
  88. <detail-tabbar v-model="state.goodsInfo">
  89. <!-- TODO: 缺货中 已售罄 判断 设计-->
  90. <view class="buy-box ss-flex ss-col-center ss-p-r-20">
  91. <button
  92. class="ss-reset-button origin-price-btn ss-flex-col"
  93. v-if="state.goodsInfo.marketPrice"
  94. @tap="sheep.$router.go('/pages/goods/index', { id: state.goodsInfo.id })"
  95. >
  96. <view>
  97. <view class="btn-price">{{ fen2yuan(state.goodsInfo.marketPrice) }}</view>
  98. <view>原价购买</view>
  99. </view>
  100. </button>
  101. <button v-else class="ss-reset-button origin-price-btn ss-flex-col">
  102. <view
  103. class="no-original"
  104. :class="
  105. state.goodsInfo.stock === 0 || timeStatusEnum !== TimeStatusEnum.STARTED ? '' : ''
  106. "
  107. >
  108. 秒杀价
  109. </view>
  110. </button>
  111. <button
  112. class="ss-reset-button btn-box ss-flex-col"
  113. @tap="state.showSelectSku = true"
  114. :class="
  115. timeStatusEnum === TimeStatusEnum.STARTED && state.goodsInfo.stock != 0
  116. ? 'check-btn-box'
  117. : 'disabled-btn-box'
  118. "
  119. :disabled="state.goodsInfo.stock === 0 || timeStatusEnum !== TimeStatusEnum.STARTED"
  120. >
  121. <view class="btn-price">{{ fen2yuan(state.goodsInfo.price) }}</view>
  122. <view v-if="timeStatusEnum === TimeStatusEnum.STARTED">
  123. <view v-if="state.goodsInfo.stock === 0">已售罄</view>
  124. <view v-else>立即秒杀</view>
  125. </view>
  126. <view v-else>{{ timeStatusEnum }}</view>
  127. </button>
  128. </view>
  129. </detail-tabbar>
  130. </block>
  131. </s-layout>
  132. </template>
  133. <script setup>
  134. import { computed, reactive, ref, unref } from 'vue';
  135. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  136. import sheep from '@/sheep';
  137. import { isEmpty, min } from 'lodash-es';
  138. import { fen2yuan, formatGoodsSwiper, useDurationTime } from '@/sheep/hooks/useGoods';
  139. import detailNavbar from './components/detail/detail-navbar.vue';
  140. import detailCellSku from './components/detail/detail-cell-sku.vue';
  141. import detailTabbar from './components/detail/detail-tabbar.vue';
  142. import detailSkeleton from './components/detail/detail-skeleton.vue';
  143. import detailCommentCard from './components/detail/detail-comment-card.vue';
  144. import detailContentCard from './components/detail/detail-content-card.vue';
  145. import detailProgress from './components/detail/detail-progress.vue';
  146. import SeckillApi from '@/sheep/api/promotion/seckill';
  147. import SpuApi from '@/sheep/api/product/spu';
  148. import { getTimeStatusEnum, SharePageEnum, TimeStatusEnum } from '@/sheep/helper/const';
  149. const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
  150. const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
  151. const disabledBtnBg = sheep.$url.css('/static/img/shop/goods/activity-btn-disabled.png');
  152. const seckillBg = sheep.$url.css('/static/img/shop/goods/seckill-tip-bg.png');
  153. const grouponBg = sheep.$url.css('/static/img/shop/goods/groupon-tip-bg.png');
  154. onPageScroll(() => {});
  155. const state = reactive({
  156. skeletonLoading: true,
  157. goodsInfo: {},
  158. showSelectSku: false,
  159. goodsSwiper: [],
  160. selectedSku: {},
  161. showModel: false,
  162. total: 0,
  163. percent: 0,
  164. price: '',
  165. });
  166. const endTime = computed(() => {
  167. return useDurationTime(activity.value.endTime);
  168. });
  169. // 规格变更
  170. function onSkuChange(e) {
  171. state.selectedSku = e;
  172. }
  173. // 立即购买
  174. function onBuy(sku) {
  175. sheep.$router.go('/pages/order/confirm', {
  176. data: JSON.stringify({
  177. order_type: 'goods',
  178. buy_type: 'seckill',
  179. seckillActivityId: activity.value.id,
  180. items: [
  181. {
  182. skuId: sku.id,
  183. count: sku.count,
  184. },
  185. ],
  186. }),
  187. });
  188. }
  189. // 分享信息
  190. const shareInfo = computed(() => {
  191. if (isEmpty(unref(activity))) return {};
  192. return sheep.$platform.share.getShareInfo(
  193. {
  194. title: activity.value.name,
  195. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  196. params: {
  197. page: SharePageEnum.SECKILL.value,
  198. query: activity.value.id,
  199. },
  200. },
  201. {
  202. type: 'goods', // 商品海报
  203. title: activity.value.name, // 商品标题
  204. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
  205. price: fen2yuan(state.goodsInfo.price), // 商品价格
  206. marketPrice: fen2yuan(state.goodsInfo.marketPrice), // 商品原价
  207. },
  208. );
  209. });
  210. const activity = ref();
  211. const timeStatusEnum = ref('');
  212. // 查询活动
  213. const getActivity = async (id) => {
  214. const { data } = await SeckillApi.getSeckillActivity(id);
  215. if (!data) {
  216. state.goodsInfo = null;
  217. state.skeletonLoading = false;
  218. return;
  219. }
  220. activity.value = data;
  221. timeStatusEnum.value = getTimeStatusEnum(activity.value.startTime, activity.value.endTime);
  222. state.percent = 100 - (data.stock / data.totalStock) * 100;
  223. // 查询商品
  224. await getSpu(data.spuId);
  225. };
  226. // 查询商品
  227. const getSpu = async (id) => {
  228. const { data } = await SpuApi.getSpuDetail(id);
  229. if (!data) {
  230. state.goodsInfo = null;
  231. state.skeletonLoading = false;
  232. return;
  233. }
  234. data.activity_type = 'seckill';
  235. state.goodsInfo = data;
  236. // 处理轮播图
  237. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  238. // 默认显示最低价
  239. state.goodsInfo.price = min([
  240. state.goodsInfo.price,
  241. ...activity.value.products.map((spu) => spu.seckillPrice),
  242. ]);
  243. // 价格、库存使用活动的
  244. data.skus.forEach((sku) => {
  245. const product = activity.value.products.find((product) => product.skuId === sku.id);
  246. if (product) {
  247. sku.price = product.seckillPrice;
  248. sku.stock = Math.min(sku.stock, product.stock);
  249. } else {
  250. // 找不到可能是没配置,则不能发起秒杀
  251. sku.stock = 0;
  252. }
  253. // 设置限购数量
  254. if (activity.value.totalLimitCount > 0 && activity.value.singleLimitCount > 0) {
  255. sku.limitCount = Math.min(activity.value.totalLimitCount, activity.value.singleLimitCount);
  256. } else if (activity.value.totalLimitCount > 0) {
  257. sku.limitCount = activity.value.totalLimitCount;
  258. } else if (activity.value.singleLimitCount > 0) {
  259. sku.limitCount = activity.value.singleLimitCount;
  260. }
  261. });
  262. state.skeletonLoading = false;
  263. };
  264. onLoad((options) => {
  265. // 非法参数
  266. if (!options.id) {
  267. state.goodsInfo = null;
  268. state.skeletonLoading = false;
  269. return;
  270. }
  271. // 查询活动
  272. getActivity(options.id);
  273. });
  274. </script>
  275. <style lang="scss" scoped>
  276. .disabled-btn-box[disabled] {
  277. background-color: transparent;
  278. }
  279. .detail-card {
  280. background-color: $white;
  281. margin: 14rpx 20rpx;
  282. border-radius: 10rpx;
  283. overflow: hidden;
  284. }
  285. // 价格标题卡片
  286. .title-card {
  287. width: 710rpx;
  288. box-sizing: border-box;
  289. // height: 320rpx;
  290. background-size: 100% 100%;
  291. border-radius: 10rpx;
  292. background-image: v-bind(headerBg);
  293. background-repeat: no-repeat;
  294. .price-box {
  295. .price-text {
  296. font-size: 30rpx;
  297. font-weight: 500;
  298. color: #fff;
  299. line-height: normal;
  300. font-family: OPPOSANS;
  301. &::before {
  302. content: '¥';
  303. font-size: 30rpx;
  304. }
  305. }
  306. }
  307. .origin-price {
  308. font-size: 24rpx;
  309. font-weight: 400;
  310. color: #fff;
  311. opacity: 0.7;
  312. .origin-price-text {
  313. text-decoration: line-through;
  314. font-family: OPPOSANS;
  315. &::before {
  316. content: '¥';
  317. }
  318. }
  319. }
  320. .tig {
  321. border: 2rpx solid #ffffff;
  322. border-radius: 4rpx;
  323. width: 126rpx;
  324. height: 38rpx;
  325. .tig-icon {
  326. width: 40rpx;
  327. height: 40rpx;
  328. margin-left: -2rpx;
  329. background: #ffffff;
  330. border-radius: 4rpx 0 0 4rpx;
  331. .cicon-alarm {
  332. font-size: 32rpx;
  333. color: #fc6e6f;
  334. }
  335. }
  336. .tig-title {
  337. width: 86rpx;
  338. font-size: 24rpx;
  339. font-weight: 500;
  340. line-height: normal;
  341. color: #ffffff;
  342. display: flex;
  343. justify-content: center;
  344. align-items: center;
  345. }
  346. }
  347. .countdown-title {
  348. font-size: 26rpx;
  349. font-weight: 500;
  350. color: #ffffff;
  351. }
  352. .countdown-time {
  353. font-size: 26rpx;
  354. font-weight: 500;
  355. color: #ffffff;
  356. .countdown-h {
  357. font-size: 24rpx;
  358. font-family: OPPOSANS;
  359. font-weight: 500;
  360. color: #ffffff;
  361. padding: 0 4rpx;
  362. height: 40rpx;
  363. background: rgba(#000000, 0.1);
  364. border-radius: 6rpx;
  365. }
  366. .countdown-num {
  367. font-size: 24rpx;
  368. font-family: OPPOSANS;
  369. font-weight: 500;
  370. color: #ffffff;
  371. width: 40rpx;
  372. height: 40rpx;
  373. background: rgba(#000000, 0.1);
  374. border-radius: 6rpx;
  375. }
  376. }
  377. .discounts-box {
  378. .discounts-tag {
  379. padding: 4rpx 10rpx;
  380. font-size: 24rpx;
  381. font-weight: 500;
  382. border-radius: 4rpx;
  383. color: var(--ui-BG-Main);
  384. // background: rgba(#2aae67, 0.05);
  385. background: var(--ui-BG-Main-tag);
  386. }
  387. .discounts-title {
  388. font-size: 24rpx;
  389. font-weight: 500;
  390. color: var(--ui-BG-Main);
  391. line-height: normal;
  392. }
  393. .cicon-forward {
  394. color: var(--ui-BG-Main);
  395. font-size: 24rpx;
  396. line-height: normal;
  397. margin-top: 4rpx;
  398. }
  399. }
  400. .title-text {
  401. font-size: 30rpx;
  402. font-weight: bold;
  403. line-height: 42rpx;
  404. color: #fff;
  405. }
  406. .subtitle-text {
  407. font-size: 26rpx;
  408. font-weight: 400;
  409. color: #ffffff;
  410. line-height: 42rpx;
  411. opacity: 0.9;
  412. }
  413. }
  414. // 购买
  415. .buy-box {
  416. .check-btn-box {
  417. width: 248rpx;
  418. height: 80rpx;
  419. font-size: 24rpx;
  420. font-weight: 600;
  421. margin-left: -36rpx;
  422. background-image: v-bind(btnBg);
  423. background-repeat: no-repeat;
  424. background-size: 100% 100%;
  425. color: #ffffff;
  426. line-height: normal;
  427. border-radius: 0px 40rpx 40rpx 0px;
  428. }
  429. .disabled-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(disabledBtnBg);
  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. .btn-price {
  443. font-family: OPPOSANS;
  444. &::before {
  445. content: '¥';
  446. }
  447. }
  448. .origin-price-btn {
  449. width: 236rpx;
  450. height: 80rpx;
  451. background: rgba(#ff5651, 0.1);
  452. color: #ff6000;
  453. border-radius: 40rpx 0px 0px 40rpx;
  454. line-height: normal;
  455. font-size: 24rpx;
  456. font-weight: 500;
  457. .no-original {
  458. font-size: 28rpx;
  459. }
  460. .btn-title {
  461. font-size: 28rpx;
  462. }
  463. }
  464. }
  465. //秒杀卡片
  466. .seckill-box {
  467. background: v-bind(seckillBg) no-repeat;
  468. background-size: 100% 100%;
  469. }
  470. .groupon-box {
  471. background: v-bind(grouponBg) no-repeat;
  472. background-size: 100% 100%;
  473. }
  474. //活动卡片
  475. .activity-box {
  476. width: 100%;
  477. height: 80rpx;
  478. box-sizing: border-box;
  479. margin-bottom: 10rpx;
  480. .activity-title {
  481. font-size: 26rpx;
  482. font-weight: 500;
  483. color: #ffffff;
  484. line-height: 42rpx;
  485. .activity-icon {
  486. width: 38rpx;
  487. height: 38rpx;
  488. }
  489. }
  490. .activity-go {
  491. width: 70rpx;
  492. height: 32rpx;
  493. background: #ffffff;
  494. border-radius: 16rpx;
  495. font-weight: 500;
  496. color: #ff6000;
  497. font-size: 24rpx;
  498. line-height: normal;
  499. }
  500. }
  501. .model-box {
  502. .title {
  503. font-size: 36rpx;
  504. font-weight: bold;
  505. color: #333333;
  506. }
  507. .subtitle {
  508. font-size: 26rpx;
  509. font-weight: 500;
  510. color: #333333;
  511. }
  512. }
  513. image {
  514. width: 100%;
  515. height: 100%;
  516. }
  517. </style>