seckill.vue 14 KB

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