point.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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/util/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. const getShowPriceText = computed(() => {
  201. let priceText = `¥${fen2yuan(state.goodsInfo.price)}`;
  202. if (!isEmpty(state.selectedSku)) {
  203. const sku = state.selectedSku;
  204. priceText = `${sku.point}${!sku.pointPrice ? '' : `+¥${fen2yuan(sku.pointPrice)}`}`;
  205. }
  206. return priceText;
  207. });
  208. // 查询活动
  209. const getActivity = async (id) => {
  210. const { data } = await PointApi.getPointActivity(id);
  211. activity.value = data;
  212. // 查询产品
  213. await getSpu(data.spuId);
  214. };
  215. // 查询产品
  216. const getSpu = async (id) => {
  217. const { data } = await SpuApi.getSpuDetail(id);
  218. data.activity_type = PromotionActivityTypeEnum.POINT.type;
  219. state.goodsInfo = data;
  220. state.goodsInfo.stock = Math.min(data.stock, activity.value.stock);
  221. // 处理轮播图
  222. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  223. // 价格、库存使用活动的
  224. data.skus.forEach((sku) => {
  225. const product = activity.value.products.find((product) => product.skuId === sku.id);
  226. if (product) {
  227. sku.point = product.point;
  228. sku.pointPrice = product.price;
  229. sku.stock = Math.min(sku.stock, product.stock);
  230. // 设置限购数量
  231. sku.limitCount = product.count;
  232. } else {
  233. // 找不到可能是没配置
  234. sku.stock = 0;
  235. }
  236. });
  237. state.skeletonLoading = false;
  238. };
  239. onLoad((options) => {
  240. // 非法参数
  241. if (!options.id) {
  242. state.goodsInfo = null;
  243. return;
  244. }
  245. // 查询活动
  246. getActivity(options.id);
  247. });
  248. </script>
  249. <style lang="scss" scoped>
  250. .disabled-btn-box[disabled] {
  251. background-color: transparent;
  252. }
  253. .detail-card {
  254. background-color: $white;
  255. margin: 14rpx 20rpx;
  256. border-radius: 10rpx;
  257. overflow: hidden;
  258. }
  259. // 价格标题卡片
  260. .title-card {
  261. width: 710rpx;
  262. box-sizing: border-box;
  263. background-size: 100% 100%;
  264. border-radius: 10rpx;
  265. background-image: v-bind(headerBg);
  266. background-repeat: no-repeat;
  267. .price-box {
  268. .point-img {
  269. width: 36rpx;
  270. height: 36rpx;
  271. margin: 0 4rpx;
  272. }
  273. .point-text {
  274. font-size: 42rpx;
  275. font-weight: 500;
  276. color: #ff3000;
  277. line-height: 36rpx;
  278. font-family: OPPOSANS;
  279. }
  280. .price-text {
  281. font-size: 42rpx;
  282. font-weight: 500;
  283. color: #ff3000;
  284. line-height: 36rpx;
  285. font-family: OPPOSANS;
  286. }
  287. }
  288. .origin-price-text {
  289. font-size: 26rpx;
  290. font-weight: 400;
  291. text-decoration: line-through;
  292. color: $gray-c;
  293. font-family: OPPOSANS;
  294. }
  295. .sales-text {
  296. font-size: 26rpx;
  297. font-weight: 500;
  298. color: $gray-c;
  299. }
  300. .discounts-box {
  301. .discounts-tag {
  302. padding: 4rpx 10rpx;
  303. font-size: 24rpx;
  304. font-weight: 500;
  305. border-radius: 4rpx;
  306. color: var(--ui-BG-Main);
  307. // background: rgba(#2aae67, 0.05);
  308. background: var(--ui-BG-Main-tag);
  309. }
  310. .discounts-title {
  311. font-size: 24rpx;
  312. font-weight: 500;
  313. color: var(--ui-BG-Main);
  314. line-height: normal;
  315. }
  316. .cicon-forward {
  317. color: var(--ui-BG-Main);
  318. font-size: 24rpx;
  319. line-height: normal;
  320. margin-top: 4rpx;
  321. }
  322. }
  323. .title-text {
  324. font-size: 30rpx;
  325. font-weight: bold;
  326. line-height: 42rpx;
  327. }
  328. .subtitle-text {
  329. font-size: 26rpx;
  330. font-weight: 400;
  331. color: $dark-9;
  332. line-height: 42rpx;
  333. }
  334. }
  335. // 购买
  336. .buy-box {
  337. .check-btn-box {
  338. width: 248rpx;
  339. height: 80rpx;
  340. font-size: 24rpx;
  341. font-weight: 600;
  342. margin-left: -36rpx;
  343. background-image: v-bind(btnBg);
  344. background-repeat: no-repeat;
  345. background-size: 100% 100%;
  346. color: #ffffff;
  347. line-height: normal;
  348. border-radius: 0px 40rpx 40rpx 0px;
  349. }
  350. .disabled-btn-box {
  351. width: 248rpx;
  352. height: 80rpx;
  353. font-size: 24rpx;
  354. font-weight: 600;
  355. margin-left: -36rpx;
  356. background-image: v-bind(disabledBtnBg);
  357. background-repeat: no-repeat;
  358. background-size: 100% 100%;
  359. color: #999999;
  360. line-height: normal;
  361. border-radius: 0px 40rpx 40rpx 0px;
  362. }
  363. .btn-price {
  364. font-family: OPPOSANS;
  365. &::before {
  366. content: '¥';
  367. }
  368. }
  369. .origin-price-btn {
  370. width: 236rpx;
  371. height: 80rpx;
  372. background: rgba(#ff5651, 0.1);
  373. color: #ff6000;
  374. border-radius: 40rpx 0px 0px 40rpx;
  375. line-height: normal;
  376. font-size: 24rpx;
  377. font-weight: 500;
  378. .no-original {
  379. font-size: 28rpx;
  380. }
  381. .btn-title {
  382. font-size: 28rpx;
  383. }
  384. }
  385. }
  386. //秒杀卡片
  387. .seckill-box {
  388. background: v-bind(seckillBg) no-repeat;
  389. background-size: 100% 100%;
  390. }
  391. .groupon-box {
  392. background: v-bind(grouponBg) no-repeat;
  393. background-size: 100% 100%;
  394. }
  395. //活动卡片
  396. .activity-box {
  397. width: 100%;
  398. height: 80rpx;
  399. box-sizing: border-box;
  400. margin-bottom: 10rpx;
  401. .activity-title {
  402. font-size: 26rpx;
  403. font-weight: 500;
  404. color: #ffffff;
  405. line-height: 42rpx;
  406. .activity-icon {
  407. width: 38rpx;
  408. height: 38rpx;
  409. }
  410. }
  411. .activity-go {
  412. width: 70rpx;
  413. height: 32rpx;
  414. background: #ffffff;
  415. border-radius: 16rpx;
  416. font-weight: 500;
  417. color: #ff6000;
  418. font-size: 24rpx;
  419. line-height: normal;
  420. }
  421. }
  422. .model-box {
  423. .title {
  424. font-size: 36rpx;
  425. font-weight: bold;
  426. color: #333333;
  427. }
  428. .subtitle {
  429. font-size: 26rpx;
  430. font-weight: 500;
  431. color: #333333;
  432. }
  433. }
  434. </style>