seckill.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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 { reactive, computed, 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 { useDurationTime, formatGoodsSwiper, fen2yuan } 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, TimeStatusEnum } from '@/sheep/util/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: '4',
  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: state.goodsInfo.price, // 商品价格
  206. marketPrice: 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. activity.value = data;
  216. timeStatusEnum.value = getTimeStatusEnum(activity.value.startTime, activity.value.endTime);
  217. state.percent = 100 - (data.stock / data.totalStock) * 100;
  218. // 查询商品
  219. await getSpu(data.spuId);
  220. };
  221. // 查询商品
  222. const getSpu = async (id) => {
  223. const { data } = await SpuApi.getSpuDetail(id);
  224. data.activity_type = 'seckill';
  225. state.goodsInfo = data;
  226. // 处理轮播图
  227. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  228. // 默认显示最低价
  229. state.goodsInfo.price = min([
  230. state.goodsInfo.price,
  231. ...activity.value.products.map((spu) => spu.seckillPrice),
  232. ]);
  233. // 价格、库存使用活动的
  234. data.skus.forEach((sku) => {
  235. const product = activity.value.products.find((product) => product.skuId === sku.id);
  236. if (product) {
  237. sku.price = product.seckillPrice;
  238. sku.stock = Math.min(sku.stock, product.stock);
  239. } else {
  240. // 找不到可能是没配置,则不能发起秒杀
  241. sku.stock = 0;
  242. }
  243. // 设置限购数量
  244. if (activity.value.totalLimitCount > 0 && activity.value.singleLimitCount > 0) {
  245. sku.limitCount = Math.min(activity.value.totalLimitCount, activity.value.singleLimitCount);
  246. } else if (activity.value.totalLimitCount > 0) {
  247. sku.limitCount = activity.value.totalLimitCount;
  248. } else if (activity.value.singleLimitCount > 0) {
  249. sku.limitCount = activity.value.singleLimitCount;
  250. }
  251. });
  252. state.skeletonLoading = false;
  253. };
  254. onLoad((options) => {
  255. // 非法参数
  256. if (!options.id) {
  257. state.goodsInfo = null;
  258. return;
  259. }
  260. // 查询活动
  261. getActivity(options.id);
  262. });
  263. </script>
  264. <style lang="scss" scoped>
  265. .disabled-btn-box[disabled] {
  266. background-color: transparent;
  267. }
  268. .detail-card {
  269. background-color: $white;
  270. margin: 14rpx 20rpx;
  271. border-radius: 10rpx;
  272. overflow: hidden;
  273. }
  274. // 价格标题卡片
  275. .title-card {
  276. width: 710rpx;
  277. box-sizing: border-box;
  278. // height: 320rpx;
  279. background-size: 100% 100%;
  280. border-radius: 10rpx;
  281. background-image: v-bind(headerBg);
  282. background-repeat: no-repeat;
  283. .price-box {
  284. .price-text {
  285. font-size: 30rpx;
  286. font-weight: 500;
  287. color: #fff;
  288. line-height: normal;
  289. font-family: OPPOSANS;
  290. &::before {
  291. content: '¥';
  292. font-size: 30rpx;
  293. }
  294. }
  295. }
  296. .origin-price {
  297. font-size: 24rpx;
  298. font-weight: 400;
  299. color: #fff;
  300. opacity: 0.7;
  301. .origin-price-text {
  302. text-decoration: line-through;
  303. font-family: OPPOSANS;
  304. &::before {
  305. content: '¥';
  306. }
  307. }
  308. }
  309. .tig {
  310. border: 2rpx solid #ffffff;
  311. border-radius: 4rpx;
  312. width: 126rpx;
  313. height: 38rpx;
  314. .tig-icon {
  315. width: 40rpx;
  316. height: 40rpx;
  317. margin-left: -2rpx;
  318. background: #ffffff;
  319. border-radius: 4rpx 0 0 4rpx;
  320. .cicon-alarm {
  321. font-size: 32rpx;
  322. color: #fc6e6f;
  323. }
  324. }
  325. .tig-title {
  326. width: 86rpx;
  327. font-size: 24rpx;
  328. font-weight: 500;
  329. line-height: normal;
  330. color: #ffffff;
  331. display: flex;
  332. justify-content: center;
  333. align-items: center;
  334. }
  335. }
  336. .countdown-title {
  337. font-size: 26rpx;
  338. font-weight: 500;
  339. color: #ffffff;
  340. }
  341. .countdown-time {
  342. font-size: 26rpx;
  343. font-weight: 500;
  344. color: #ffffff;
  345. .countdown-h {
  346. font-size: 24rpx;
  347. font-family: OPPOSANS;
  348. font-weight: 500;
  349. color: #ffffff;
  350. padding: 0 4rpx;
  351. height: 40rpx;
  352. background: rgba(#000000, 0.1);
  353. border-radius: 6rpx;
  354. }
  355. .countdown-num {
  356. font-size: 24rpx;
  357. font-family: OPPOSANS;
  358. font-weight: 500;
  359. color: #ffffff;
  360. width: 40rpx;
  361. height: 40rpx;
  362. background: rgba(#000000, 0.1);
  363. border-radius: 6rpx;
  364. }
  365. }
  366. .discounts-box {
  367. .discounts-tag {
  368. padding: 4rpx 10rpx;
  369. font-size: 24rpx;
  370. font-weight: 500;
  371. border-radius: 4rpx;
  372. color: var(--ui-BG-Main);
  373. // background: rgba(#2aae67, 0.05);
  374. background: var(--ui-BG-Main-tag);
  375. }
  376. .discounts-title {
  377. font-size: 24rpx;
  378. font-weight: 500;
  379. color: var(--ui-BG-Main);
  380. line-height: normal;
  381. }
  382. .cicon-forward {
  383. color: var(--ui-BG-Main);
  384. font-size: 24rpx;
  385. line-height: normal;
  386. margin-top: 4rpx;
  387. }
  388. }
  389. .title-text {
  390. font-size: 30rpx;
  391. font-weight: bold;
  392. line-height: 42rpx;
  393. color: #fff;
  394. }
  395. .subtitle-text {
  396. font-size: 26rpx;
  397. font-weight: 400;
  398. color: #ffffff;
  399. line-height: 42rpx;
  400. opacity: 0.9;
  401. }
  402. }
  403. // 购买
  404. .buy-box {
  405. .check-btn-box {
  406. width: 248rpx;
  407. height: 80rpx;
  408. font-size: 24rpx;
  409. font-weight: 600;
  410. margin-left: -36rpx;
  411. background-image: v-bind(btnBg);
  412. background-repeat: no-repeat;
  413. background-size: 100% 100%;
  414. color: #ffffff;
  415. line-height: normal;
  416. border-radius: 0px 40rpx 40rpx 0px;
  417. }
  418. .disabled-btn-box {
  419. width: 248rpx;
  420. height: 80rpx;
  421. font-size: 24rpx;
  422. font-weight: 600;
  423. margin-left: -36rpx;
  424. background-image: v-bind(disabledBtnBg);
  425. background-repeat: no-repeat;
  426. background-size: 100% 100%;
  427. color: #999999;
  428. line-height: normal;
  429. border-radius: 0px 40rpx 40rpx 0px;
  430. }
  431. .btn-price {
  432. font-family: OPPOSANS;
  433. &::before {
  434. content: '¥';
  435. }
  436. }
  437. .origin-price-btn {
  438. width: 236rpx;
  439. height: 80rpx;
  440. background: rgba(#ff5651, 0.1);
  441. color: #ff6000;
  442. border-radius: 40rpx 0px 0px 40rpx;
  443. line-height: normal;
  444. font-size: 24rpx;
  445. font-weight: 500;
  446. .no-original {
  447. font-size: 28rpx;
  448. }
  449. .btn-title {
  450. font-size: 28rpx;
  451. }
  452. }
  453. }
  454. //秒杀卡片
  455. .seckill-box {
  456. background: v-bind(seckillBg) no-repeat;
  457. background-size: 100% 100%;
  458. }
  459. .groupon-box {
  460. background: v-bind(grouponBg) no-repeat;
  461. background-size: 100% 100%;
  462. }
  463. //活动卡片
  464. .activity-box {
  465. width: 100%;
  466. height: 80rpx;
  467. box-sizing: border-box;
  468. margin-bottom: 10rpx;
  469. .activity-title {
  470. font-size: 26rpx;
  471. font-weight: 500;
  472. color: #ffffff;
  473. line-height: 42rpx;
  474. .activity-icon {
  475. width: 38rpx;
  476. height: 38rpx;
  477. }
  478. }
  479. .activity-go {
  480. width: 70rpx;
  481. height: 32rpx;
  482. background: #ffffff;
  483. border-radius: 16rpx;
  484. font-weight: 500;
  485. color: #ff6000;
  486. font-size: 24rpx;
  487. line-height: normal;
  488. }
  489. }
  490. .model-box {
  491. .title {
  492. font-size: 36rpx;
  493. font-weight: bold;
  494. color: #333333;
  495. }
  496. .subtitle {
  497. font-size: 26rpx;
  498. font-weight: 500;
  499. color: #333333;
  500. }
  501. }
  502. image {
  503. width: 100%;
  504. height: 100%;
  505. }
  506. </style>