index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <view>
  3. <s-layout :onShareAppMessage="shareInfo" navbar="goods">
  4. <!-- 标题栏 -->
  5. <detailNavbar />
  6. <!-- 骨架屏 -->
  7. <detailSkeleton v-if="state.skeletonLoading" />
  8. <!-- 下架/售罄提醒 -->
  9. <s-empty v-else-if="state.goodsInfo === null" text="产品不存在或已下架" icon="/static/soldout-empty.png" showAction
  10. actionText="再逛逛" actionUrl="/pages/goods/list" />
  11. <block v-else>
  12. <view class="detail-swiper-selector">
  13. <!-- 产品轮播图 -->
  14. <su-swiper class="ss-m-b-14" isPreview :list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)" otStyle="tag"
  15. imageMode="widthFix" dotCur="bg-mask-40" :seizeHeight="750" />
  16. <!-- 限时折扣/会员价的优惠信息 -->
  17. <view class="discount" v-if="
  18. state.settlementSku && state.settlementSku.id && state.settlementSku.promotionPrice
  19. ">
  20. <image class="disImg" :src="sheep.$url.static('/static/img/shop/goods/dis.png')" />
  21. <view class="discountCont">
  22. <view class="disContT">
  23. <view class="disContT1">
  24. <view class="disContT1P">
  25. ¥{{ fen2yuan(state.settlementSku.promotionPrice) }}
  26. </view>
  27. <view class="disContT1End">
  28. 直降¥
  29. {{ fen2yuan(state.settlementSku.price - state.settlementSku.promotionPrice) }}
  30. </view>
  31. </view>
  32. <view class="disContT2" v-if="state.settlementSku.promotionType === 4">
  33. 限时折扣
  34. </view>
  35. <view class="disContT2" v-else-if="state.settlementSku.promotionType === 6">
  36. 会员折扣
  37. </view>
  38. </view>
  39. <view class="disContB">
  40. <view class="disContB1">
  41. 价格:¥{{ fen2yuan(state.settlementSku.price) }} 丨 剩余:
  42. {{ state.settlementSku.stock }}
  43. </view>
  44. <view class="disContB2" v-if="state.settlementSku.promotionEndTime > 0">
  45. 距结束仅剩
  46. <countDown :tipText="' '" :bgColor="bgColor" :dayText="':'" :hourText="':'" :minuteText="':'"
  47. :secondText="' '" :datatime="state.settlementSku.promotionEndTime / 1000" :isDay="false" />
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 价格+标题 -->
  53. <view class="title-card detail-card ss-p-y-30 ss-p-x-20">
  54. <!-- 没有限时折扣/会员价的优惠信息时,展示的价格信息 -->
  55. <!-- <view class="ss-flex ss-row-between ss-col-center ss-m-b-26" v-if="!state.settlementSku.promotionPrice">
  56. <view class="price-box ss-flex ss-col-bottom">
  57. <view class="price-text ss-m-r-16">
  58. {{ fen2yuan(state.selectedSku.price || state.goodsInfo.price) }}
  59. </view>
  60. <view class="origin-price-text" v-if="state.goodsInfo.marketPrice > state.goodsInfo.price">
  61. {{ fen2yuan(state.selectedSku.marketPrice || state.goodsInfo.marketPrice) }}
  62. </view>
  63. </view>
  64. <view class="sales-text">
  65. {{ formatSales('exact', state.goodsInfo.salesCount) }}
  66. </view>
  67. </view> -->
  68. <view class="discounts-box ss-flex ss-row-between ss-m-b-28">
  69. <!-- 查看优惠劵的描述 -->
  70. <!-- <view class="tag ss-m-r-10" v-for="coupon in state.couponInfo.slice(0, 1)" :key="coupon.id"
  71. @tap="onOpenActivity">
  72. [劵]满{{ fen2yuanSimple(coupon.usePrice) }}元{{
  73. coupon.discountType === 1
  74. ? '减' + fen2yuanSimple(coupon.discountPrice) + '元'
  75. : '打' + formatDiscountPercent(coupon.discountPercent) + '折'
  76. }}
  77. </view> -->
  78. <!-- 查看满减送的描述 -->
  79. <!--<div class="tag-content">
  80. <view class="tag-box ss-flex">
  81. <view v-for="item in getRewardActivityRuleItemDescriptions(
  82. state.rewardActivity,
  83. ).slice(0, 3 - state.couponInfo.slice(0, 1).length)" :key="item" class="tag ss-m-r-10"
  84. @tap="onOpenActivity">
  85. <text>{{ item }}</text>
  86. </view>
  87. </view>
  88. </div>-->
  89. <!-- 领取优惠劵的按钮 -->
  90. <!-- <view class="get-coupon-box ss-flex ss-col-center ss-m-l-20" @tap="onOpenActivity"
  91. v-if="state.couponInfo.length">
  92. <view class="discounts-title ss-m-r-8">领券</view>
  93. <text class="cicon-forward"></text>
  94. </view> -->
  95. </view>
  96. <view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name }}</view>
  97. <view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
  98. </view>
  99. <!-- 功能卡片 -->
  100. <!--<view class="detail-cell-card detail-card ss-flex-col">
  101. <detail-cell-sku v-model="state.selectedSku.goods_sku_text" :sku="state.selectedSku"
  102. @tap="state.showSelectSku = true" />
  103. </view>-->
  104. <!-- 规格与数量弹框 -->
  105. <s-select-sku :goodsInfo="state.goodsInfo" :show="state.showSelectSku" @addCart="onAddCart" @buy="onBuy"
  106. @change="onSkuChange" @close="state.showSelectSku = false" />
  107. </view>
  108. <!-- 评价 -->
  109. <!--<detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />-->
  110. <!-- 详情 -->
  111. <detail-content-card class="detail-content-selector" :goodsInfo="state.goodsInfo"
  112. :content="state.goodsInfo.description" />
  113. <!-- 活动跳转:拼团/秒杀/砍价活动 -->
  114. <!--<detail-activity-tip v-if="state.activityList.length > 0" :activity-list="state.activityList" />-->
  115. <!-- 详情 tabbar -->
  116. <detail-tabbar v-model="state.goodsInfo">
  117. <view class="buy-box ss-flex ss-col-center ss-p-r-20" v-if="state.goodsInfo.stock > 0">
  118. <button class="ss-reset-button add-btn ui-Shadow-Main" @tap="phoneClick">
  119. 打电话
  120. </button>
  121. <!-- state.showSelectSku = true -->
  122. <button class="ss-reset-button buy-btn ui-Shadow-Main" @tap="customerService">
  123. 联系客服
  124. </button>
  125. </view>
  126. <view class="buy-box ss-flex ss-col-center ss-p-r-20" v-else>
  127. <button class="ss-reset-button disabled-btn" disabled> 已售罄 </button>
  128. </view>
  129. </detail-tabbar>
  130. <!-- 满减送/限时折扣活动弹窗 -->
  131. <s-activity-pop v-model="state" :show="state.showActivityModel" @close="state.showActivityModel = false"
  132. @get="onTakeCoupon" />
  133. </block>
  134. </s-layout>
  135. </view>
  136. </template>
  137. <script setup>
  138. import { reactive, computed, ref, toRaw } from 'vue';
  139. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  140. import sheep from '@/sheep';
  141. import CouponApi from '@/sheep/api/promotion/coupon';
  142. import ActivityApi from '@/sheep/api/promotion/activity';
  143. import FavoriteApi from '@/sheep/api/product/favorite';
  144. import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
  145. import {
  146. formatSales,
  147. formatGoodsSwiper,
  148. fen2yuan,
  149. fen2yuanSimple,
  150. formatDiscountPercent,
  151. getRewardActivityRuleItemDescriptions,
  152. } from '@/sheep/hooks/useGoods';
  153. import detailNavbar from './components/detail/detail-navbar.vue';
  154. import detailCellSku from './components/detail/detail-cell-sku.vue';
  155. import detailTabbar from './components/detail/detail-tabbar.vue';
  156. import detailSkeleton from './components/detail/detail-skeleton.vue';
  157. import detailCommentCard from './components/detail/detail-comment-card.vue';
  158. import detailContentCard from './components/detail/detail-content-card.vue';
  159. import detailActivityTip from './components/detail/detail-activity-tip.vue';
  160. import { isEmpty } from 'lodash-es';
  161. import SpuApi from '@/sheep/api/product/spu';
  162. onPageScroll(() => { });
  163. import countDown from '@/sheep/components/countDown/index.vue';
  164. import OrderApi from '@/sheep/api/trade/order';
  165. import activity from '@/sheep/api/promotion/activity';
  166. import { SharePageEnum } from '@/sheep/util/const';
  167. const bgColor = {
  168. bgColor: '#E93323',
  169. Color: '#fff',
  170. width: '44rpx',
  171. timeTxtwidth: '16rpx',
  172. isDay: true,
  173. };
  174. const isLogin = computed(() => sheep.$store('user').isLogin);
  175. const state = reactive({
  176. goodsId: 0,
  177. skeletonLoading: true, // SPU 加载中
  178. goodsInfo: {}, // SPU 信息
  179. showSelectSku: false, // 是否展示 SKU 选择弹窗
  180. selectedSku: {}, // 选中的 SKU
  181. settlementSku: {}, // 结算的 SKU:由于 selectedSku 不进行默认选中,所以初始使用结算价格最低的 SKU 作为基础展示
  182. showModel: false, // 是否展示 Coupon 优惠劵的弹窗
  183. couponInfo: [], // 可领取的 Coupon 优惠劵的列表
  184. showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
  185. rewardActivity: {}, // 【满减送】活动
  186. activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
  187. });
  188. // 打电话
  189. const phoneClick = () => {
  190. if (uni.getSystemInfoSync().platform === 'h5') {
  191. window.location.href = `tel:${state.goodsInfo.phoneNumber}`; // 替换为实际电话号码
  192. } else {
  193. uni.makePhoneCall({
  194. phoneNumber: state.goodsInfo.phoneNumber // 替换为实际电话号码
  195. });
  196. }
  197. }
  198. // 客服
  199. const customerService = () => {
  200. if (state.goodsInfo.proType == 0) {
  201. sheep.$router.go('/pages/chat/index')
  202. } else {
  203. sheep.$router.go('/pages/customerService/index', {
  204. data: JSON.stringify({
  205. url: state.goodsInfo.qrCodePath,
  206. })
  207. })
  208. }
  209. }
  210. // 规格变更
  211. function onSkuChange(e) {
  212. state.selectedSku = e;
  213. state.settlementSku = e;
  214. }
  215. // 添加购物车
  216. function onAddCart(e) {
  217. if (!e.id) {
  218. sheep.$helper.toast('请选择产品规格');
  219. return;
  220. }
  221. sheep.$store('cart').add(e);
  222. }
  223. // 立即购买
  224. function onBuy(e) {
  225. if (!e.id) {
  226. sheep.$helper.toast('请选择产品规格');
  227. return;
  228. }
  229. sheep.$router.go('/pages/order/confirm', {
  230. data: JSON.stringify({
  231. items: [
  232. {
  233. skuId: e.id,
  234. count: e.goods_num,
  235. categoryId: state.goodsInfo.categoryId,
  236. },
  237. ],
  238. }),
  239. });
  240. }
  241. // 打开营销弹窗
  242. function onOpenActivity() {
  243. state.showActivityModel = true;
  244. }
  245. // 立即领取优惠劵
  246. async function onTakeCoupon(id) {
  247. const { code } = await CouponApi.takeCoupon(id);
  248. if (code !== 0) {
  249. return;
  250. }
  251. uni.showToast({
  252. title: '领取成功',
  253. });
  254. setTimeout(() => {
  255. getCoupon();
  256. }, 1000);
  257. }
  258. const shareInfo = computed(() => {
  259. if (isEmpty(state.goodsInfo)) return {};
  260. return sheep.$platform.share.getShareInfo(
  261. {
  262. title: state.goodsInfo.name,
  263. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  264. desc: state.goodsInfo.introduction,
  265. params: {
  266. page: SharePageEnum.GOODS.value,
  267. query: state.goodsInfo.id,
  268. },
  269. },
  270. {
  271. type: 'goods', // 产品海报
  272. title: state.goodsInfo.name, // 产品名称
  273. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 产品主图
  274. price: fen2yuan(state.goodsInfo.price), // 产品价格
  275. original_price: fen2yuan(state.goodsInfo.marketPrice), // 产品原价
  276. },
  277. );
  278. });
  279. async function getCoupon() {
  280. const { code, data } = await CouponApi.getCouponTemplateList(state.goodsId, 2, 10);
  281. if (code === 0) {
  282. state.couponInfo = data;
  283. }
  284. }
  285. async function getSettlementByIds(ids) {
  286. let { data, code } = await OrderApi.getSettlementProduct(ids);
  287. if (code !== 0 || data.length !== 1) {
  288. return;
  289. }
  290. data = data[0];
  291. // 补充 SKU 的价格信息
  292. state.goodsInfo.skus.forEach((sku) => {
  293. data.skus.forEach((item) => {
  294. if (sku.id === item.id) {
  295. sku.promotionType = item.promotionType;
  296. sku.promotionPrice = item.promotionPrice;
  297. sku.promotionId = item.promotionId;
  298. sku.promotionEndTime = item.promotionEndTime;
  299. }
  300. });
  301. });
  302. // 选择有 promotionPrice 且最小的
  303. state.settlementSku = state.goodsInfo.skus
  304. .filter((sku) => sku.stock > 0 && sku.promotionPrice > 0)
  305. .reduce((prev, curr) => (prev.promotionPrice < curr.promotionPrice ? prev : curr), []);
  306. // 设置满减送活动
  307. if (data.rewardActivity) {
  308. state.rewardActivity = data.rewardActivity;
  309. //获取活动时间
  310. getActivityTime(state.rewardActivity.id);
  311. }
  312. }
  313. //获取活动时间
  314. async function getActivityTime(id) {
  315. const { code, data } = await RewardActivityApi.getRewardActivity(id);
  316. if (code === 0) {
  317. // console.log('获取到的活动 数据', data)
  318. state.rewardActivity.startTime = data.startTime;
  319. state.rewardActivity.endTime = data.endTime;
  320. }
  321. }
  322. onLoad((options) => {
  323. // 非法参数
  324. if (!options.id) {
  325. state.goodsInfo = null;
  326. return;
  327. }
  328. state.goodsId = options.id;
  329. // 1. 加载产品信息
  330. SpuApi.getSpuDetail(state.goodsId).then((res) => {
  331. // 未找到产品
  332. if (res.code !== 0 || !res.data) {
  333. state.goodsInfo = null;
  334. return;
  335. }
  336. // 加载到产品
  337. state.skeletonLoading = false;
  338. state.goodsInfo = res.data;
  339. // 加载是否收藏
  340. if (isLogin.value) {
  341. FavoriteApi.isFavoriteExists(state.goodsId, 'goods').then((res) => {
  342. if (res.code !== 0) {
  343. return;
  344. }
  345. state.goodsInfo.favorite = res.data;
  346. });
  347. }
  348. });
  349. // 2. 加载优惠劵信息
  350. getCoupon();
  351. // 3. 加载营销活动信息
  352. ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
  353. if (res.code !== 0) {
  354. return;
  355. }
  356. state.activityList = res.data;
  357. });
  358. //获取结算信息
  359. getSettlementByIds(state.goodsId);
  360. });
  361. </script>
  362. <style lang="scss" scoped>
  363. .detail-card {
  364. background-color: #ffff;
  365. margin: 14rpx 20rpx;
  366. border-radius: 10rpx;
  367. overflow: hidden;
  368. }
  369. // 价格标题卡片
  370. .title-card {
  371. .price-box {
  372. .price-text {
  373. font-size: 42rpx;
  374. font-weight: 500;
  375. color: #ff3000;
  376. line-height: 30rpx;
  377. font-family: OPPOSANS;
  378. &::before {
  379. content: '¥';
  380. font-size: 30rpx;
  381. }
  382. }
  383. .origin-price-text {
  384. font-size: 26rpx;
  385. font-weight: 400;
  386. text-decoration: line-through;
  387. color: $gray-c;
  388. font-family: OPPOSANS;
  389. &::before {
  390. content: '¥';
  391. }
  392. }
  393. }
  394. .sales-text {
  395. font-size: 26rpx;
  396. font-weight: 500;
  397. color: $gray-c;
  398. }
  399. .discounts-box {
  400. .tag-content {
  401. flex: 1;
  402. min-width: 0;
  403. white-space: nowrap;
  404. }
  405. .tag-box {
  406. overflow: hidden;
  407. text-overflow: ellipsis;
  408. }
  409. .tag {
  410. flex-shrink: 0;
  411. padding: 4rpx 10rpx;
  412. font-size: 24rpx;
  413. font-weight: 500;
  414. border-radius: 4rpx;
  415. color: var(--ui-BG-Main);
  416. background: var(--ui-BG-Main-tag);
  417. }
  418. .discounts-title {
  419. font-size: 24rpx;
  420. font-weight: 500;
  421. color: var(--ui-BG-Main);
  422. line-height: normal;
  423. }
  424. .cicon-forward {
  425. color: var(--ui-BG-Main);
  426. font-size: 24rpx;
  427. line-height: normal;
  428. margin-top: 4rpx;
  429. }
  430. }
  431. .title-text {
  432. font-size: 30rpx;
  433. font-weight: bold;
  434. line-height: 42rpx;
  435. }
  436. .subtitle-text {
  437. font-size: 26rpx;
  438. font-weight: 400;
  439. color: $dark-9;
  440. line-height: 42rpx;
  441. }
  442. }
  443. // 购买
  444. .buy-box {
  445. .add-btn {
  446. width: 254rpx;
  447. height: 72rpx;
  448. font-weight: 500;
  449. font-size: 28rpx;
  450. border-radius: 40rpx 0 0 40rpx;
  451. background-color: var(--ui-BG-Main-light);
  452. color: var(--ui-BG-Main);
  453. }
  454. .buy-btn {
  455. width: 254rpx;
  456. height: 72rpx;
  457. font-weight: 500;
  458. font-size: 28rpx;
  459. border-radius: 0 40rpx 40rpx 0;
  460. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  461. color: $white;
  462. }
  463. .disabled-btn {
  464. width: 428rpx;
  465. height: 72rpx;
  466. border-radius: 40rpx;
  467. background: #999999;
  468. color: $white;
  469. }
  470. }
  471. .model-box {
  472. height: 60vh;
  473. .model-content {
  474. height: 56vh;
  475. }
  476. .title {
  477. font-size: 36rpx;
  478. font-weight: bold;
  479. color: #333333;
  480. }
  481. .subtitle {
  482. font-size: 26rpx;
  483. font-weight: 500;
  484. color: #333333;
  485. }
  486. }
  487. // 限时折扣
  488. .discount {
  489. width: 750rpx;
  490. height: 100rpx;
  491. // background-color: red;
  492. overflow: hidden;
  493. position: relative;
  494. }
  495. .disImg {
  496. width: 750rpx;
  497. height: 100rpx;
  498. position: absolute;
  499. top: 0;
  500. z-index: -1;
  501. }
  502. .discountCont {
  503. width: 680rpx;
  504. height: 90rpx;
  505. margin: 10rpx auto 0 auto;
  506. // background-color: gold;
  507. }
  508. .disContT {
  509. width: 680rpx;
  510. height: 50rpx;
  511. display: flex;
  512. justify-content: space-between;
  513. }
  514. .disContT1 {
  515. width: 400rpx;
  516. height: 50rpx;
  517. // background-color: green;
  518. display: flex;
  519. justify-content: flex-start;
  520. align-items: center;
  521. }
  522. .disContT2 {
  523. width: 200rpx;
  524. height: 50rpx;
  525. line-height: 50rpx;
  526. // background-color: gold;
  527. font-size: 30rpx;
  528. text-align: end;
  529. color: white;
  530. font-weight: bolder;
  531. font-style: oblique 20deg;
  532. letter-spacing: 0.1rem;
  533. }
  534. .disContT1P {
  535. color: white;
  536. font-weight: bold;
  537. font-size: 28rpx;
  538. }
  539. .disContT1End {
  540. // width: 180rpx;
  541. padding: 0 10rpx;
  542. height: 30rpx;
  543. line-height: 28rpx;
  544. text-align: center;
  545. font-weight: bold;
  546. background-color: white;
  547. color: #ff3000;
  548. font-size: 23rpx;
  549. border-radius: 20rpx;
  550. margin-left: 10rpx;
  551. }
  552. .disContB {
  553. width: 680rpx;
  554. height: 40rpx;
  555. display: flex;
  556. justify-content: space-between;
  557. font-size: 20rpx;
  558. color: white;
  559. align-items: center;
  560. }
  561. .disContB1 {
  562. width: 300rpx;
  563. height: 40rpx;
  564. line-height: 40rpx;
  565. }
  566. .disContB2 {
  567. width: 300rpx;
  568. height: 40rpx;
  569. line-height: 40rpx;
  570. display: flex;
  571. justify-content: flex-end;
  572. }
  573. </style>