seckill.vue 14 KB

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