point.vue 13 KB

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