seckill.vue 15 KB

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