point.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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 !== PromotionActivityTypeEnum.POINT.type"
  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. {{ getShowPriceText }}
  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>
  44. <view class="ss-flex ss-row-between ss-m-b-60">
  45. <view class="origin-price ss-flex ss-col-center" v-if="state.goodsInfo.marketPrice">
  46. 原价
  47. <view class="origin-price-text">
  48. {{ fen2yuan(state.selectedSku.marketPrice || state.goodsInfo.marketPrice) }}
  49. </view>
  50. </view>
  51. </view>
  52. <view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name || '' }}</view>
  53. <view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
  54. </view>
  55. <!-- 功能卡片 -->
  56. <view class="detail-cell-card detail-card ss-flex-col">
  57. <detail-cell-sku :sku="state.selectedSku" @tap="state.showSelectSku = true" />
  58. </view>
  59. <!-- 规格与数量弹框 -->
  60. <s-select-seckill-sku
  61. v-model="state.goodsInfo"
  62. :show="state.showSelectSku"
  63. :single-limit-count="activity.singleLimitCount"
  64. @buy="onBuy"
  65. @change="onSkuChange"
  66. @close="state.showSelectSku = false"
  67. />
  68. </view>
  69. <!-- 评价 -->
  70. <detail-comment-card class="detail-comment-selector" :goodsId="state.goodsInfo.id" />
  71. <!-- 详情 -->
  72. <detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
  73. <!-- 详情tabbar -->
  74. <detail-tabbar v-model="state.goodsInfo">
  75. <view class="buy-box ss-flex ss-col-center ss-p-r-20">
  76. <button
  77. class="ss-reset-button origin-price-btn ss-flex-col"
  78. v-if="state.goodsInfo.marketPrice"
  79. @tap="sheep.$router.go('/pages/goods/index', { id: state.goodsInfo.id })"
  80. >
  81. <view>
  82. <view class="btn-price">{{ fen2yuan(state.goodsInfo.marketPrice) }}</view>
  83. <view>原价购买</view>
  84. </view>
  85. </button>
  86. <button
  87. class="ss-reset-button btn-box ss-flex-col"
  88. @tap="state.showSelectSku = true"
  89. :class="
  90. state.goodsInfo.stock != 0
  91. ? 'check-btn-box'
  92. : 'disabled-btn-box'
  93. "
  94. :disabled="state.goodsInfo.stock === 0"
  95. >
  96. <view class="price-text">
  97. {{getShowPriceText}}
  98. </view>
  99. <view v-if="state.goodsInfo.stock === 0">已售罄</view>
  100. <view v-else>立即兑换</view>
  101. </button>
  102. </view>
  103. </detail-tabbar>
  104. </block>
  105. </s-layout>
  106. </template>
  107. <script setup>
  108. import { computed, reactive, ref, unref } from 'vue';
  109. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  110. import sheep from '@/sheep';
  111. import { isEmpty } from 'lodash-es';
  112. import { fen2yuan, formatGoodsSwiper } from '@/sheep/hooks/useGoods';
  113. import detailNavbar from './components/detail/detail-navbar.vue';
  114. import detailCellSku from './components/detail/detail-cell-sku.vue';
  115. import detailTabbar from './components/detail/detail-tabbar.vue';
  116. import detailSkeleton from './components/detail/detail-skeleton.vue';
  117. import detailCommentCard from './components/detail/detail-comment-card.vue';
  118. import detailContentCard from './components/detail/detail-content-card.vue';
  119. import SpuApi from '@/sheep/api/product/spu';
  120. import { PromotionActivityTypeEnum } from '@/sheep/util/const';
  121. import PointApi from '@/sheep/api/promotion/point';
  122. const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
  123. const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
  124. const disabledBtnBg = sheep.$url.css('/static/img/shop/goods/activity-btn-disabled.png');
  125. const seckillBg = sheep.$url.css('/static/img/shop/goods/seckill-tip-bg.png');
  126. const grouponBg = sheep.$url.css('/static/img/shop/goods/groupon-tip-bg.png');
  127. onPageScroll(() => {
  128. });
  129. const state = reactive({
  130. skeletonLoading: true,
  131. goodsInfo: {},
  132. showSelectSku: false,
  133. goodsSwiper: [],
  134. selectedSku: {},
  135. showModel: false,
  136. total: 0,
  137. price: '',
  138. });
  139. // 规格变更
  140. function onSkuChange(e) {
  141. state.selectedSku = e;
  142. }
  143. // 立即购买
  144. function onBuy(sku) {
  145. sheep.$router.go('/pages/order/confirm', {
  146. data: JSON.stringify({
  147. order_type: 'goods',
  148. buy_type: 'point',
  149. pointActivityId: activity.value.id,
  150. items: [
  151. {
  152. skuId: sku.id,
  153. count: sku.count,
  154. },
  155. ],
  156. }),
  157. });
  158. }
  159. // 分享信息
  160. // TODO puhui999: 下次 fix
  161. const shareInfo = computed(() => {
  162. if (isEmpty(unref(activity))) return {};
  163. return sheep.$platform.share.getShareInfo(
  164. {
  165. title: activity.value.name,
  166. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  167. params: {
  168. page: '4',
  169. query: activity.value.id,
  170. },
  171. },
  172. {
  173. type: 'goods', // 商品海报
  174. title: activity.value.name, // 商品标题
  175. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
  176. price: state.goodsInfo.price, // 商品价格
  177. marketPrice: state.goodsInfo.marketPrice, // 商品原价
  178. },
  179. );
  180. });
  181. const activity = ref();
  182. const getShowPriceText = computed(() => {
  183. let priceText = `${activity.value.point}积分${!activity.value.price ? '' : `+¥${fen2yuan(activity.value.price)}`}`;
  184. if (!isEmpty(state.selectedSku)) {
  185. const sku = state.selectedSku;
  186. priceText = `${sku.point}积分${!sku.pointPrice ? '' : `+¥${fen2yuan(sku.pointPrice)}`}`;
  187. }
  188. return priceText;
  189. });
  190. // 查询活动
  191. const getActivity = async (id) => {
  192. const { data } = await PointApi.getPointActivity(id);
  193. activity.value = data;
  194. // 查询商品
  195. await getSpu(data.spuId);
  196. };
  197. // 查询商品
  198. const getSpu = async (id) => {
  199. const { data } = await SpuApi.getSpuDetail(id);
  200. data.activity_type = PromotionActivityTypeEnum.POINT.type;
  201. state.goodsInfo = data;
  202. state.goodsInfo.stock = Math.min(data.stock, activity.value.stock);
  203. // 处理轮播图
  204. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  205. // 价格、库存使用活动的
  206. data.skus.forEach((sku) => {
  207. const product = activity.value.products.find((product) => product.skuId === sku.id);
  208. if (product) {
  209. sku.point = product.point;
  210. sku.pointPrice = product.price;
  211. sku.stock = Math.min(sku.stock, product.stock);
  212. // 设置限购数量
  213. sku.limitCount = product.count;
  214. } else {
  215. // 找不到可能是没配置
  216. sku.stock = 0;
  217. }
  218. });
  219. state.skeletonLoading = false;
  220. };
  221. onLoad((options) => {
  222. // 非法参数
  223. if (!options.id) {
  224. state.goodsInfo = null;
  225. return;
  226. }
  227. // 查询活动
  228. getActivity(options.id);
  229. });
  230. </script>
  231. <style lang="scss" scoped>
  232. .disabled-btn-box[disabled] {
  233. background-color: transparent;
  234. }
  235. .detail-card {
  236. background-color: $white;
  237. margin: 14rpx 20rpx;
  238. border-radius: 10rpx;
  239. overflow: hidden;
  240. }
  241. // 价格标题卡片
  242. .title-card {
  243. width: 710rpx;
  244. box-sizing: border-box;
  245. // height: 320rpx;
  246. background-size: 100% 100%;
  247. border-radius: 10rpx;
  248. background-image: v-bind(headerBg);
  249. background-repeat: no-repeat;
  250. .price-box {
  251. .price-text {
  252. font-size: 30rpx;
  253. font-weight: 500;
  254. color: #fff;
  255. line-height: normal;
  256. font-family: OPPOSANS;
  257. }
  258. }
  259. .origin-price {
  260. font-size: 24rpx;
  261. font-weight: 400;
  262. color: #fff;
  263. opacity: 0.7;
  264. .origin-price-text {
  265. text-decoration: line-through;
  266. font-family: OPPOSANS;
  267. &::before {
  268. content: '¥';
  269. }
  270. }
  271. }
  272. .tig {
  273. border: 2rpx solid #ffffff;
  274. border-radius: 4rpx;
  275. width: 126rpx;
  276. height: 38rpx;
  277. .tig-icon {
  278. width: 40rpx;
  279. height: 40rpx;
  280. margin-left: -2rpx;
  281. background: #ffffff;
  282. border-radius: 4rpx 0 0 4rpx;
  283. .cicon-alarm {
  284. font-size: 32rpx;
  285. color: #fc6e6f;
  286. }
  287. }
  288. .tig-title {
  289. width: 86rpx;
  290. font-size: 24rpx;
  291. font-weight: 500;
  292. line-height: normal;
  293. color: #ffffff;
  294. display: flex;
  295. justify-content: center;
  296. align-items: center;
  297. }
  298. }
  299. .countdown-title {
  300. font-size: 26rpx;
  301. font-weight: 500;
  302. color: #ffffff;
  303. }
  304. .countdown-time {
  305. font-size: 26rpx;
  306. font-weight: 500;
  307. color: #ffffff;
  308. .countdown-h {
  309. font-size: 24rpx;
  310. font-family: OPPOSANS;
  311. font-weight: 500;
  312. color: #ffffff;
  313. padding: 0 4rpx;
  314. height: 40rpx;
  315. background: rgba(#000000, 0.1);
  316. border-radius: 6rpx;
  317. }
  318. .countdown-num {
  319. font-size: 24rpx;
  320. font-family: OPPOSANS;
  321. font-weight: 500;
  322. color: #ffffff;
  323. width: 40rpx;
  324. height: 40rpx;
  325. background: rgba(#000000, 0.1);
  326. border-radius: 6rpx;
  327. }
  328. }
  329. .discounts-box {
  330. .discounts-tag {
  331. padding: 4rpx 10rpx;
  332. font-size: 24rpx;
  333. font-weight: 500;
  334. border-radius: 4rpx;
  335. color: var(--ui-BG-Main);
  336. // background: rgba(#2aae67, 0.05);
  337. background: var(--ui-BG-Main-tag);
  338. }
  339. .discounts-title {
  340. font-size: 24rpx;
  341. font-weight: 500;
  342. color: var(--ui-BG-Main);
  343. line-height: normal;
  344. }
  345. .cicon-forward {
  346. color: var(--ui-BG-Main);
  347. font-size: 24rpx;
  348. line-height: normal;
  349. margin-top: 4rpx;
  350. }
  351. }
  352. .title-text {
  353. font-size: 30rpx;
  354. font-weight: bold;
  355. line-height: 42rpx;
  356. color: #fff;
  357. }
  358. .subtitle-text {
  359. font-size: 26rpx;
  360. font-weight: 400;
  361. color: #ffffff;
  362. line-height: 42rpx;
  363. opacity: 0.9;
  364. }
  365. }
  366. // 购买
  367. .buy-box {
  368. .check-btn-box {
  369. width: 248rpx;
  370. height: 80rpx;
  371. font-size: 24rpx;
  372. font-weight: 600;
  373. margin-left: -36rpx;
  374. background-image: v-bind(btnBg);
  375. background-repeat: no-repeat;
  376. background-size: 100% 100%;
  377. color: #ffffff;
  378. line-height: normal;
  379. border-radius: 0px 40rpx 40rpx 0px;
  380. }
  381. .disabled-btn-box {
  382. width: 248rpx;
  383. height: 80rpx;
  384. font-size: 24rpx;
  385. font-weight: 600;
  386. margin-left: -36rpx;
  387. background-image: v-bind(disabledBtnBg);
  388. background-repeat: no-repeat;
  389. background-size: 100% 100%;
  390. color: #999999;
  391. line-height: normal;
  392. border-radius: 0px 40rpx 40rpx 0px;
  393. }
  394. .btn-price {
  395. font-family: OPPOSANS;
  396. &::before {
  397. content: '¥';
  398. }
  399. }
  400. .origin-price-btn {
  401. width: 236rpx;
  402. height: 80rpx;
  403. background: rgba(#ff5651, 0.1);
  404. color: #ff6000;
  405. border-radius: 40rpx 0px 0px 40rpx;
  406. line-height: normal;
  407. font-size: 24rpx;
  408. font-weight: 500;
  409. .no-original {
  410. font-size: 28rpx;
  411. }
  412. .btn-title {
  413. font-size: 28rpx;
  414. }
  415. }
  416. }
  417. //秒杀卡片
  418. .seckill-box {
  419. background: v-bind(seckillBg) no-repeat;
  420. background-size: 100% 100%;
  421. }
  422. .groupon-box {
  423. background: v-bind(grouponBg) no-repeat;
  424. background-size: 100% 100%;
  425. }
  426. //活动卡片
  427. .activity-box {
  428. width: 100%;
  429. height: 80rpx;
  430. box-sizing: border-box;
  431. margin-bottom: 10rpx;
  432. .activity-title {
  433. font-size: 26rpx;
  434. font-weight: 500;
  435. color: #ffffff;
  436. line-height: 42rpx;
  437. .activity-icon {
  438. width: 38rpx;
  439. height: 38rpx;
  440. }
  441. }
  442. .activity-go {
  443. width: 70rpx;
  444. height: 32rpx;
  445. background: #ffffff;
  446. border-radius: 16rpx;
  447. font-weight: 500;
  448. color: #ff6000;
  449. font-size: 24rpx;
  450. line-height: normal;
  451. }
  452. }
  453. .model-box {
  454. .title {
  455. font-size: 36rpx;
  456. font-weight: bold;
  457. color: #333333;
  458. }
  459. .subtitle {
  460. font-size: 26rpx;
  461. font-weight: 500;
  462. color: #333333;
  463. }
  464. }
  465. image {
  466. width: 100%;
  467. height: 100%;
  468. }
  469. </style>