seckill.vue 15 KB

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