point.vue 13 KB

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