seckill.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. v-model="state.selectedSku.goods_sku_text"
  71. :sku="state.selectedSku"
  72. @tap="state.showSelectSku = true"
  73. />
  74. </view>
  75. <!-- 规格与数量弹框 -->
  76. <s-select-seckill-sku
  77. v-model="state.goodsInfo"
  78. :show="state.showSelectSku"
  79. :single-limit-count="activity.singleLimitCount"
  80. @buy="onBuy"
  81. @change="onSkuChange"
  82. @close="state.showSelectSku = false"
  83. />
  84. </view>
  85. <!-- 评价 -->
  86. <detail-comment-card class="detail-comment-selector" :goodsId="state.goodsInfo.id" />
  87. <!-- 详情 -->
  88. <detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
  89. <!-- 详情tabbar -->
  90. <detail-tabbar v-model="state.goodsInfo">
  91. <!-- TODO: 缺货中 已售罄 判断 设计-->
  92. <view class="buy-box ss-flex ss-col-center ss-p-r-20">
  93. <button
  94. class="ss-reset-button origin-price-btn ss-flex-col"
  95. v-if="state.goodsInfo.marketPrice"
  96. @tap="sheep.$router.go('/pages/goods/index', { id: state.goodsInfo.id })"
  97. >
  98. <view>
  99. <view class="btn-price">{{ fen2yuan(state.goodsInfo.marketPrice) }}</view>
  100. <view>原价购买</view>
  101. </view>
  102. </button>
  103. <button v-else class="ss-reset-button origin-price-btn ss-flex-col">
  104. <view
  105. class="no-original"
  106. :class="
  107. state.goodsInfo.stock === 0 || activity.status != 'ing' ? '' : ''
  108. "
  109. >
  110. 秒杀价
  111. </view>
  112. </button>
  113. <!-- TODO @疯狂:status 判断不太对 -->
  114. <button
  115. class="ss-reset-button btn-box ss-flex-col"
  116. @tap="state.showSelectSku = true"
  117. :class="
  118. activity.status === 'ing' && state.goodsInfo.stock != 0
  119. ? 'check-btn-box'
  120. : 'disabled-btn-box'
  121. "
  122. :disabled="state.goodsInfo.stock === 0 || activity.status != 'ing'"
  123. >
  124. <view class="btn-price">{{ fen2yuan(state.goodsInfo.price) }}</view>
  125. <view v-if="activity.status === 'ing'">
  126. <view v-if="state.goodsInfo.stock === 0">已售罄</view>
  127. <view v-else>立即秒杀</view>
  128. </view>
  129. <view v-else>{{ activity.status_text }}</view>
  130. </button>
  131. </view>
  132. </detail-tabbar>
  133. </block>
  134. </s-layout>
  135. </template>
  136. <script setup>
  137. import {reactive, computed, ref} from 'vue';
  138. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  139. import sheep from '@/sheep';
  140. import {isEmpty, min} from 'lodash';
  141. import {useDurationTime, formatGoodsSwiper, fen2yuan} from '@/sheep/hooks/useGoods';
  142. import detailNavbar from './components/detail/detail-navbar.vue';
  143. import detailCellSku from './components/detail/detail-cell-sku.vue';
  144. import detailTabbar from './components/detail/detail-tabbar.vue';
  145. import detailSkeleton from './components/detail/detail-skeleton.vue';
  146. import detailCommentCard from './components/detail/detail-comment-card.vue';
  147. import detailContentCard from './components/detail/detail-content-card.vue';
  148. import detailProgress from './components/detail/detail-progress.vue';
  149. import SeckillApi from "@/sheep/api/promotion/seckill";
  150. import SpuApi from "@/sheep/api/product/spu";
  151. const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
  152. const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
  153. const disabledBtnBg = sheep.$url.css(
  154. '/static/img/shop/goods/activity-btn-disabled.png',
  155. );
  156. const seckillBg = sheep.$url.css('/static/img/shop/goods/seckill-tip-bg.png');
  157. const grouponBg = sheep.$url.css('/static/img/shop/goods/groupon-tip-bg.png');
  158. onPageScroll(() => {});
  159. const state = reactive({
  160. skeletonLoading: true,
  161. goodsInfo: {},
  162. showSelectSku: false,
  163. goodsSwiper: [],
  164. selectedSku: {},
  165. showModel: false,
  166. total: 0,
  167. percent: 0,
  168. price: '',
  169. });
  170. const endTime = computed(() => {
  171. return useDurationTime(activity.value.endTime);
  172. });
  173. // 规格变更
  174. function onSkuChange(e) {
  175. state.selectedSku = e;
  176. }
  177. // 立即购买
  178. function onBuy(e) {
  179. sheep.$router.go('/pages/order/confirm', {
  180. data: JSON.stringify({
  181. order_type: 'goods',
  182. buy_type: 'seckill',
  183. activityId: activity.value.id,
  184. goods_list: [
  185. {
  186. goods_id: e.goods_id,
  187. goods_num: e.goods_num,
  188. goods_sku_price_id: e.id,
  189. },
  190. ],
  191. }),
  192. });
  193. }
  194. const shareInfo = computed(() => {
  195. if (isEmpty(state.goodsInfo?.activity)) return {};
  196. return sheep.$platform.share.getShareInfo(
  197. {
  198. title: state.goodsInfo.name,
  199. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  200. params: {
  201. page: '4',
  202. query: state.goodsInfo.id + ',' + activity.value.id,
  203. },
  204. },
  205. {
  206. type: 'goods', // 商品海报
  207. title: state.goodsInfo.name, // 商品标题
  208. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
  209. price: state.goodsInfo.price[0], // 商品价格
  210. marketPrice: state.goodsInfo.marketPrice, // 商品原价
  211. },
  212. );
  213. });
  214. const activity = ref()
  215. // 查询活动
  216. const getActivity = async (id) => {
  217. const { data } = await SeckillApi.getSeckillActivity(id)
  218. activity.value = data
  219. // 查询商品
  220. await getSpu(data.spuId)
  221. }
  222. const getSpu = async (id) => {
  223. const { data } = await SpuApi.getSpuDetail(id)
  224. // 模拟
  225. data.activity_type = 'seckill'
  226. state.goodsInfo = data
  227. // 处理轮播图
  228. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  229. // 默认显示最低价
  230. state.goodsInfo.price = min([state.goodsInfo.price, ...activity.value.products.map(spu => spu.seckillPrice)])
  231. // 价格、库存使用活动的
  232. data.skus.forEach(sku => {
  233. debugger
  234. const product = activity.value.products.find(product => product.skuId === sku.id);
  235. if (product) {
  236. sku.price = product.seckillPrice;
  237. sku.stock = Math.min(sku.stock, product.stock);
  238. } else { // 找不到可能是没配置,则不能发起秒杀
  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>