point.vue 13 KB

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