seckill.vue 14 KB

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