seckill.vue 15 KB

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