seckill.vue 15 KB

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