seckill.vue 15 KB

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