index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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 userInfo = computed(() => sheep.$store('user').userInfo);
  200. const customerService = () => {
  201. CouponApi.getKefuConversationByRelID({
  202. relID: state.goodsInfo.kefuId
  203. }).then((res) => {
  204. console.log(res, 44444)
  205. if (state.goodsInfo.proType == 0) {
  206. sheep.$router.go('/pages/chat/index', { conversationId: res.data.id, relUserId: userInfo.value.id === res.data.relUserId ? res.data.userId : res.data.relUserId })
  207. } else {
  208. sheep.$router.go('/pages/customerService/index', {
  209. data: JSON.stringify({
  210. url: state.goodsInfo.qrCodePath,
  211. })
  212. })
  213. }
  214. })
  215. }
  216. // 规格变更
  217. function onSkuChange(e) {
  218. state.selectedSku = e;
  219. state.settlementSku = e;
  220. }
  221. // 添加购物车
  222. function onAddCart(e) {
  223. if (!e.id) {
  224. sheep.$helper.toast('请选择产品规格');
  225. return;
  226. }
  227. sheep.$store('cart').add(e);
  228. }
  229. // 立即购买
  230. function onBuy(e) {
  231. if (!e.id) {
  232. sheep.$helper.toast('请选择产品规格');
  233. return;
  234. }
  235. sheep.$router.go('/pages/order/confirm', {
  236. data: JSON.stringify({
  237. items: [
  238. {
  239. skuId: e.id,
  240. count: e.goods_num,
  241. categoryId: state.goodsInfo.categoryId,
  242. },
  243. ],
  244. }),
  245. });
  246. }
  247. // 打开营销弹窗
  248. function onOpenActivity() {
  249. state.showActivityModel = true;
  250. }
  251. // 立即领取优惠劵
  252. async function onTakeCoupon(id) {
  253. const { code } = await CouponApi.takeCoupon(id);
  254. if (code !== 0) {
  255. return;
  256. }
  257. uni.showToast({
  258. title: '领取成功',
  259. });
  260. setTimeout(() => {
  261. getCoupon();
  262. }, 1000);
  263. }
  264. const shareInfo = computed(() => {
  265. if (isEmpty(state.goodsInfo)) return {};
  266. return sheep.$platform.share.getShareInfo(
  267. {
  268. title: state.goodsInfo.name,
  269. image: sheep.$url.cdn(state.goodsInfo.picUrl),
  270. desc: state.goodsInfo.introduction,
  271. params: {
  272. page: SharePageEnum.GOODS.value,
  273. query: state.goodsInfo.id,
  274. },
  275. },
  276. {
  277. type: 'goods', // 产品海报
  278. title: state.goodsInfo.name, // 产品名称
  279. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 产品主图
  280. price: fen2yuan(state.goodsInfo.price), // 产品价格
  281. original_price: fen2yuan(state.goodsInfo.marketPrice), // 产品原价
  282. },
  283. );
  284. });
  285. async function getCoupon() {
  286. const { code, data } = await CouponApi.getCouponTemplateList(state.goodsId, 2, 10);
  287. if (code === 0) {
  288. state.couponInfo = data;
  289. }
  290. }
  291. async function getSettlementByIds(ids) {
  292. let { data, code } = await OrderApi.getSettlementProduct(ids);
  293. if (code !== 0 || data.length !== 1) {
  294. return;
  295. }
  296. data = data[0];
  297. // 补充 SKU 的价格信息
  298. state.goodsInfo.skus.forEach((sku) => {
  299. data.skus.forEach((item) => {
  300. if (sku.id === item.id) {
  301. sku.promotionType = item.promotionType;
  302. sku.promotionPrice = item.promotionPrice;
  303. sku.promotionId = item.promotionId;
  304. sku.promotionEndTime = item.promotionEndTime;
  305. }
  306. });
  307. });
  308. // 选择有 promotionPrice 且最小的
  309. state.settlementSku = state.goodsInfo.skus
  310. .filter((sku) => sku.stock > 0 && sku.promotionPrice > 0)
  311. .reduce((prev, curr) => (prev.promotionPrice < curr.promotionPrice ? prev : curr), []);
  312. // 设置满减送活动
  313. if (data.rewardActivity) {
  314. state.rewardActivity = data.rewardActivity;
  315. //获取活动时间
  316. getActivityTime(state.rewardActivity.id);
  317. }
  318. }
  319. //获取活动时间
  320. async function getActivityTime(id) {
  321. const { code, data } = await RewardActivityApi.getRewardActivity(id);
  322. if (code === 0) {
  323. // console.log('获取到的活动 数据', data)
  324. state.rewardActivity.startTime = data.startTime;
  325. state.rewardActivity.endTime = data.endTime;
  326. }
  327. }
  328. onLoad((options) => {
  329. // 非法参数
  330. if (!options.id) {
  331. state.goodsInfo = null;
  332. return;
  333. }
  334. state.goodsId = options.id;
  335. // 1. 加载产品信息
  336. SpuApi.getSpuDetail(state.goodsId).then((res) => {
  337. // 未找到产品
  338. if (res.code !== 0 || !res.data) {
  339. state.goodsInfo = null;
  340. return;
  341. }
  342. // 加载到产品
  343. state.skeletonLoading = false;
  344. state.goodsInfo = res.data;
  345. // 加载是否收藏
  346. if (isLogin.value) {
  347. FavoriteApi.isFavoriteExists(state.goodsId, 'goods').then((res) => {
  348. if (res.code !== 0) {
  349. return;
  350. }
  351. state.goodsInfo.favorite = res.data;
  352. });
  353. }
  354. });
  355. // 2. 加载优惠劵信息
  356. getCoupon();
  357. // 3. 加载营销活动信息
  358. ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
  359. if (res.code !== 0) {
  360. return;
  361. }
  362. state.activityList = res.data;
  363. });
  364. //获取结算信息
  365. getSettlementByIds(state.goodsId);
  366. });
  367. </script>
  368. <style lang="scss" scoped>
  369. .detail-card {
  370. background-color: #ffff;
  371. margin: 14rpx 20rpx;
  372. border-radius: 10rpx;
  373. overflow: hidden;
  374. }
  375. // 价格标题卡片
  376. .title-card {
  377. .price-box {
  378. .price-text {
  379. font-size: 42rpx;
  380. font-weight: 500;
  381. color: #ff3000;
  382. line-height: 30rpx;
  383. font-family: OPPOSANS;
  384. &::before {
  385. content: '¥';
  386. font-size: 30rpx;
  387. }
  388. }
  389. .origin-price-text {
  390. font-size: 26rpx;
  391. font-weight: 400;
  392. text-decoration: line-through;
  393. color: $gray-c;
  394. font-family: OPPOSANS;
  395. &::before {
  396. content: '¥';
  397. }
  398. }
  399. }
  400. .sales-text {
  401. font-size: 26rpx;
  402. font-weight: 500;
  403. color: $gray-c;
  404. }
  405. .discounts-box {
  406. .tag-content {
  407. flex: 1;
  408. min-width: 0;
  409. white-space: nowrap;
  410. }
  411. .tag-box {
  412. overflow: hidden;
  413. text-overflow: ellipsis;
  414. }
  415. .tag {
  416. flex-shrink: 0;
  417. padding: 4rpx 10rpx;
  418. font-size: 24rpx;
  419. font-weight: 500;
  420. border-radius: 4rpx;
  421. color: var(--ui-BG-Main);
  422. background: var(--ui-BG-Main-tag);
  423. }
  424. .discounts-title {
  425. font-size: 24rpx;
  426. font-weight: 500;
  427. color: var(--ui-BG-Main);
  428. line-height: normal;
  429. }
  430. .cicon-forward {
  431. color: var(--ui-BG-Main);
  432. font-size: 24rpx;
  433. line-height: normal;
  434. margin-top: 4rpx;
  435. }
  436. }
  437. .title-text {
  438. font-size: 30rpx;
  439. font-weight: bold;
  440. line-height: 42rpx;
  441. }
  442. .subtitle-text {
  443. font-size: 26rpx;
  444. font-weight: 400;
  445. color: $dark-9;
  446. line-height: 42rpx;
  447. }
  448. }
  449. // 购买
  450. .buy-box {
  451. .add-btn {
  452. width: 254rpx;
  453. height: 72rpx;
  454. font-weight: 500;
  455. font-size: 28rpx;
  456. border-radius: 40rpx 0 0 40rpx;
  457. background-color: var(--ui-BG-Main-light);
  458. color: var(--ui-BG-Main);
  459. }
  460. .buy-btn {
  461. width: 254rpx;
  462. height: 72rpx;
  463. font-weight: 500;
  464. font-size: 28rpx;
  465. border-radius: 0 40rpx 40rpx 0;
  466. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  467. color: $white;
  468. }
  469. .disabled-btn {
  470. width: 428rpx;
  471. height: 72rpx;
  472. border-radius: 40rpx;
  473. background: #999999;
  474. color: $white;
  475. }
  476. }
  477. .model-box {
  478. height: 60vh;
  479. .model-content {
  480. height: 56vh;
  481. }
  482. .title {
  483. font-size: 36rpx;
  484. font-weight: bold;
  485. color: #333333;
  486. }
  487. .subtitle {
  488. font-size: 26rpx;
  489. font-weight: 500;
  490. color: #333333;
  491. }
  492. }
  493. // 限时折扣
  494. .discount {
  495. width: 750rpx;
  496. height: 100rpx;
  497. // background-color: red;
  498. overflow: hidden;
  499. position: relative;
  500. }
  501. .disImg {
  502. width: 750rpx;
  503. height: 100rpx;
  504. position: absolute;
  505. top: 0;
  506. z-index: -1;
  507. }
  508. .discountCont {
  509. width: 680rpx;
  510. height: 90rpx;
  511. margin: 10rpx auto 0 auto;
  512. // background-color: gold;
  513. }
  514. .disContT {
  515. width: 680rpx;
  516. height: 50rpx;
  517. display: flex;
  518. justify-content: space-between;
  519. }
  520. .disContT1 {
  521. width: 400rpx;
  522. height: 50rpx;
  523. // background-color: green;
  524. display: flex;
  525. justify-content: flex-start;
  526. align-items: center;
  527. }
  528. .disContT2 {
  529. width: 200rpx;
  530. height: 50rpx;
  531. line-height: 50rpx;
  532. // background-color: gold;
  533. font-size: 30rpx;
  534. text-align: end;
  535. color: white;
  536. font-weight: bolder;
  537. font-style: oblique 20deg;
  538. letter-spacing: 0.1rem;
  539. }
  540. .disContT1P {
  541. color: white;
  542. font-weight: bold;
  543. font-size: 28rpx;
  544. }
  545. .disContT1End {
  546. // width: 180rpx;
  547. padding: 0 10rpx;
  548. height: 30rpx;
  549. line-height: 28rpx;
  550. text-align: center;
  551. font-weight: bold;
  552. background-color: white;
  553. color: #ff3000;
  554. font-size: 23rpx;
  555. border-radius: 20rpx;
  556. margin-left: 10rpx;
  557. }
  558. .disContB {
  559. width: 680rpx;
  560. height: 40rpx;
  561. display: flex;
  562. justify-content: space-between;
  563. font-size: 20rpx;
  564. color: white;
  565. align-items: center;
  566. }
  567. .disContB1 {
  568. width: 300rpx;
  569. height: 40rpx;
  570. line-height: 40rpx;
  571. }
  572. .disContB2 {
  573. width: 300rpx;
  574. height: 40rpx;
  575. line-height: 40rpx;
  576. display: flex;
  577. justify-content: flex-end;
  578. }
  579. </style>