shopDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <view class="shop-detail-container">
  3. <!-- 顶部透明导航栏悬浮在轮播图上,滚动时变为有背景的固定导航栏 -->
  4. <view class="nav-float-header" :style="{ backgroundColor: `rgba(255, 255, 255, ${navOpacity})` }">
  5. <view class="nav-btn-group">
  6. <view class="nav-btn" @click="goBack">
  7. <u-icon name="arrow-left" size="20" color="#333"></u-icon>
  8. </view>
  9. <view class="nav-btn" @click="goHome">
  10. <u-icon name="home" size="20" color="#333"></u-icon>
  11. </view>
  12. </view>
  13. <!-- <view class="nav-btn single-btn" @click="handleShare">
  14. <u-icon name="share" size="20" color="#333"></u-icon>
  15. </view> -->
  16. </view>
  17. <!-- 顶部轮播图 -->
  18. <view class="banner-wrap">
  19. <swiper class="banner-swiper" @change="onSwiperChange" :circular="true">
  20. <swiper-item v-for="(item, index) in bannerList" :key="index" @click="previewImage(index)">
  21. <image class="banner-img" :src="item" mode="aspectFill"></image>
  22. </swiper-item>
  23. </swiper>
  24. <!-- 自定义指示器 -->
  25. <view class="custom-indicator" v-if="bannerList.length > 0">
  26. {{ currentSwiper + 1 }}/{{ bannerList.length }}
  27. </view>
  28. </view>
  29. <!-- 商品信息卡片 -->
  30. <view class="product-info-card">
  31. <view class="price-row">
  32. <view class="price-left">
  33. <text class="price-label">到手价</text>
  34. <text class="price-symbol">¥</text>
  35. <text class="price-main">{{ formatPrice(productInfo.couponPrice).intPart }}</text>
  36. <text class="price-decimal">{{ formatPrice(productInfo.couponPrice).decPart }}</text>
  37. <text class="price-original" v-if="productInfo.price">¥{{ productInfo.price }}</text>
  38. </view>
  39. <view class="sales-vol">已售{{ productInfo.monthlySales || 0 }}件</view>
  40. </view>
  41. <view class="subsidy-tag" v-if="productInfo.commissionAmount">
  42. <text>已补贴 ¥{{ productInfo.commissionAmount }}</text>
  43. </view>
  44. <view class="product-title-wrap">
  45. <image v-if="getPlatformImage(productInfo.platform)" class="platform-icon"
  46. :src="getPlatformImage(productInfo.platform)" mode="aspectFit"></image>
  47. <text class="product-title">{{ productInfo.title }}</text>
  48. </view>
  49. </view>
  50. <!-- 店铺信息卡片 -->
  51. <view class="shop-info-card" v-if="productInfo.shopName">
  52. <view class="shop-icon-wrap">
  53. <image src="/static/image/points/avatar_shop.png" class="w88 h88"></image>
  54. </view>
  55. <text class="shop-name">{{ productInfo.shopName }}</text>
  56. </view>
  57. <!-- 图文详情区域 -->
  58. <view class="detail-section" v-if="productInfo.detailUrl">
  59. <view class="section-title">图文详情</view>
  60. <view class="detail-content">
  61. <image class="detail-img" v-for="(item, index) in handleDetailURL(productInfo.detailUrl)" :key="index"
  62. :src="item" mode="widthFix"></image>
  63. </view>
  64. </view>
  65. <!-- 底部安全留白 -->
  66. <view class="bottom-spacer"></view>
  67. <!-- 底部固定操作栏 -->
  68. <view class="bottom-action-bar">
  69. <view class="action-icons">
  70. <view class="icon-item" @click="toggleFavorite">
  71. <u-icon :name="isFavorite ? 'star-fill' : 'star'" size="24" :color="isFavorite ? '#FF5A1F' : '#333'"></u-icon>
  72. <text class="icon-text">收藏</text>
  73. </view>
  74. <view class="icon-item" @click="getShareLink('shortUrl')">
  75. <u-icon name="file-text" size="24" color="#333"></u-icon>
  76. <text class="icon-text">复制口令</text>
  77. </view>
  78. </view>
  79. <view class="action-btns">
  80. <button class="btn-share" @click="getShareLink('promotionUrl')">分享赚 ¥{{ productInfo.commissionAmount || 0
  81. }}</button>
  82. <button class="btn-buy" @tap="handleOpenUrl">下单省 ¥{{ productInfo.commissionAmount || 0 }}</button>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. import { getProductDetail, getIsCollection, getShareLink, checkAuthStatus, getAuthLink } from '@/api/makeMoney.js'
  89. export default {
  90. data() {
  91. return {
  92. currentSwiper: 0,
  93. isFavorite: false,
  94. navOpacity: 0, // 导航栏背景透明度
  95. id: '',//346 337
  96. bannerList: [],
  97. productInfo: {}, // 存放商品详情数据
  98. };
  99. },
  100. onPageScroll(e) {
  101. // 监听页面滚动,实现导航栏背景渐变效果
  102. // 假设滚动 150px 时背景完全不透明
  103. let opacity = e.scrollTop / 150;
  104. if (opacity > 1) {
  105. opacity = 1;
  106. } else if (opacity < 0) {
  107. opacity = 0;
  108. }
  109. this.navOpacity = opacity;
  110. },
  111. onLoad(option) {
  112. this.id = option.id
  113. // this.openApp('https://mos.m.taobao.com/inviter/register?inviterCode=7MHVXE&src=pub&app=common&rtag=4055653333')
  114. this.getProductDetails()
  115. },
  116. computed: {
  117. formatPrice() {
  118. return (price) => {
  119. if (!price) return { intPart: '0', decPart: '.00' };
  120. const priceStr = Number(price).toFixed(2);
  121. const parts = priceStr.split('.');
  122. return {
  123. intPart: parts[0],
  124. decPart: '.' + parts[1]
  125. };
  126. };
  127. }
  128. },
  129. methods: {
  130. handleDetailURL(url) {
  131. if (!url) return []
  132. return url.split(',')
  133. },
  134. openApp(schemeUrl) {
  135. const packagekey = {
  136. 'taobao': 'com.taobao.taobao',
  137. 'jd': 'com.jingdong.app.mall',
  138. 'pdd': 'com.xunmeng.pinduoduo',
  139. 'douyin': 'com.ss.android.ugc.aweme',
  140. 'cps_douyin': 'com.ss.android.ugc.aweme',
  141. 'cps_taobao': 'com.taobao.taobao',
  142. }
  143. // #ifdef APP-PLUS
  144. plus.runtime.openURL(
  145. schemeUrl,
  146. () => {
  147. uni.showModal({
  148. title: '提示',
  149. content: `App打开失败,是否用浏览器打开?`,
  150. success: (res) => {
  151. if (res.confirm) plus.runtime.openURL(schemeUrl);
  152. }
  153. });
  154. },
  155. packagekey[this.productInfo.platform]
  156. );
  157. // #endif
  158. // #ifdef H5
  159. // H5环境下直接使用浏览器打开链接
  160. window.open(schemeUrl, '_blank');
  161. // #endif
  162. },
  163. handleOpenUrl() {
  164. const platform = this.productInfo.platform
  165. if (platform.includes('taobao')) {
  166. return this.checkAuthStatus()
  167. }
  168. this.getToLink()
  169. },
  170. async getToLink() {
  171. uni.showLoading()
  172. const { code, message, data } = await getShareLink(this.id)
  173. uni.hideLoading()
  174. if (code == 200) {
  175. if (!data.promotionUrl) {
  176. uni.showToast({
  177. icon: 'none',
  178. title: '未获取到链接',
  179. });
  180. }
  181. this.openApp(data.promotionUrl)
  182. } else {
  183. uni.showToast({
  184. icon: 'none',
  185. title: message,
  186. });
  187. }
  188. },
  189. async checkAuthStatus() {
  190. uni.showLoading()
  191. const { code, message, data } = await checkAuthStatus(this.productInfo.platform)
  192. console.log("--checkAuthStatus--", data)
  193. uni.hideLoading()
  194. if (code == 200) {
  195. if (!data.isAuth) {
  196. this.getAuthLink()
  197. } else {
  198. this.getToLink()
  199. }
  200. } else {
  201. uni.showToast({
  202. icon: 'none',
  203. title: message,
  204. });
  205. }
  206. },
  207. async getAuthLink() {
  208. uni.showLoading()
  209. const { code, message, data } = await getAuthLink(this.productInfo.platform)
  210. uni.hideLoading()
  211. if (code == 200) {
  212. if (!data.url) {
  213. uni.showToast({
  214. icon: 'none',
  215. title: '未获取到授权链接',
  216. });
  217. return
  218. }
  219. return this.openApp(data.url)
  220. } else {
  221. uni.showToast({
  222. icon: 'none',
  223. title: message,
  224. });
  225. }
  226. },
  227. getPlatformImage(platform) {
  228. if (!platform) return '';
  229. const platformMap = {
  230. 'douyin': '/static/image/points/douyin.png',
  231. 'taobao': '/static/image/points/taobao.png',
  232. 'pdd': '/static/image/points/pinduoduo.png',
  233. 'cps_douyin': '/static/image/points/douyin.png',
  234. 'cps_taobao': '/static/image/points/taobao.png',
  235. };
  236. return platformMap[platform] || '';
  237. },
  238. getProductDetails() {
  239. getProductDetail(this.id).then(res => {
  240. console.log(res)
  241. if (res.code == 200) {
  242. this.productInfo = res.data || {};
  243. this.isFavorite = this.productInfo.isCollection == 1
  244. // 处理轮播图数据,以逗号分隔的字符串转为数组
  245. if (this.productInfo.imageUrls) {
  246. this.bannerList = this.productInfo.imageUrls.split(',').filter(url => url.trim());
  247. } else if (this.productInfo.imageUrl) {
  248. this.bannerList = [this.productInfo.imageUrl];
  249. }
  250. } else {
  251. uni.showToast({
  252. icon: 'none',
  253. title: res.msg,
  254. });
  255. }
  256. })
  257. },
  258. goBack() {
  259. uni.navigateBack();
  260. },
  261. goHome() {
  262. uni.switchTab({
  263. url: '/pages_im/pages/conversation/conversationList/index' // 假设主页路径,根据实际项目调整
  264. });
  265. },
  266. onSwiperChange(e) {
  267. this.currentSwiper = e.detail.current;
  268. },
  269. previewImage(index) {
  270. if (this.bannerList.length > 0) {
  271. uni.previewImage({
  272. urls: this.bannerList,
  273. current: index
  274. });
  275. }
  276. },
  277. handleShare() {
  278. console.log('点击分享');
  279. },
  280. toggleFavorite() {
  281. getIsCollection(this.id).then(res => {
  282. console.log(res)
  283. if (res.code == 200) {
  284. this.isFavorite = !this.isFavorite;
  285. } else {
  286. uni.showToast({
  287. title: res.msg,
  288. icon: 'none'
  289. });
  290. }
  291. })
  292. },
  293. async getShareLink(type) {
  294. const { code, message, data } = await getShareLink(this.id)
  295. if (code != 200) {
  296. uni.showToast({
  297. title: message,
  298. icon: 'none'
  299. });
  300. return
  301. }
  302. if (!data[type]) {
  303. uni.showToast({
  304. title: '未获取到链接',
  305. icon: 'none'
  306. });
  307. return
  308. }
  309. uni.setClipboardData({
  310. data: data[type] || '',
  311. success: () => {
  312. uni.showToast({
  313. title: '复制成功',
  314. icon: 'none'
  315. });
  316. }
  317. });
  318. }
  319. }
  320. };
  321. </script>
  322. <style lang="scss" scoped>
  323. .shop-detail-container {
  324. min-height: 100vh;
  325. background-color: #F5F7FA;
  326. padding-bottom: env(safe-area-inset-bottom);
  327. }
  328. /* 悬浮导航栏 */
  329. .nav-float-header {
  330. position: fixed;
  331. top: 0;
  332. left: 0;
  333. width: 100%;
  334. padding: 80rpx 30rpx 20rpx;
  335. /* 适配状态栏高度 */
  336. display: flex;
  337. justify-content: space-between;
  338. align-items: center;
  339. z-index: 100;
  340. box-sizing: border-box;
  341. }
  342. .nav-btn-group {
  343. display: flex;
  344. background-color: rgba(255, 255, 255, 0.8);
  345. border-radius: 30rpx;
  346. overflow: hidden;
  347. border: 1px solid rgba(0, 0, 0, 0.05);
  348. }
  349. .nav-btn {
  350. width: 60rpx;
  351. height: 60rpx;
  352. display: flex;
  353. justify-content: center;
  354. align-items: center;
  355. }
  356. .nav-btn-group .nav-btn:first-child {
  357. border-right: 1px solid rgba(0, 0, 0, 0.1);
  358. }
  359. .nav-float-header>.nav-btn {
  360. background-color: rgba(255, 255, 255, 0.8);
  361. border-radius: 50%;
  362. border: 1px solid rgba(0, 0, 0, 0.05);
  363. }
  364. /* 轮播图区域 */
  365. .banner-wrap {
  366. position: relative;
  367. width: 100%;
  368. height: 750rpx;
  369. /* 1:1 比例 */
  370. }
  371. .banner-swiper {
  372. width: 100%;
  373. height: 100%;
  374. }
  375. .banner-img {
  376. width: 100%;
  377. height: 100%;
  378. background-image: linear-gradient(45deg, rgba(0, 0, 0, 0.05) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.05) 75%, rgba(0, 0, 0, 0.05)), linear-gradient(45deg, rgba(0, 0, 0, 0.05) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.05) 75%, rgba(0, 0, 0, 0.05));
  379. background-size: 20px 20px;
  380. background-position: 0 0, 10px 10px;
  381. }
  382. .custom-indicator {
  383. position: absolute;
  384. right: 30rpx;
  385. bottom: 30rpx;
  386. background-color: rgba(0, 0, 0, 0.4);
  387. color: #fff;
  388. font-size: 24rpx;
  389. padding: 4rpx 16rpx;
  390. border-radius: 20rpx;
  391. }
  392. /* 商品信息卡片 */
  393. .product-info-card {
  394. background-color: #fff;
  395. padding: 30rpx;
  396. margin-bottom: 20rpx;
  397. }
  398. .price-row {
  399. display: flex;
  400. justify-content: space-between;
  401. align-items: baseline;
  402. margin-bottom: 16rpx;
  403. }
  404. .price-left {
  405. display: flex;
  406. align-items: baseline;
  407. }
  408. .price-label {
  409. font-size: 24rpx;
  410. color: #FF5A1F;
  411. margin-right: 8rpx;
  412. }
  413. .price-symbol {
  414. font-size: 28rpx;
  415. color: #FF5A1F;
  416. font-weight: bold;
  417. }
  418. .price-main {
  419. font-size: 48rpx;
  420. color: #FF5A1F;
  421. font-weight: bold;
  422. }
  423. .price-decimal {
  424. font-size: 28rpx;
  425. color: #FF5A1F;
  426. font-weight: bold;
  427. }
  428. .price-original {
  429. font-size: 24rpx;
  430. color: #999;
  431. text-decoration: line-through;
  432. margin-left: 16rpx;
  433. }
  434. .sales-vol {
  435. font-size: 24rpx;
  436. color: #999;
  437. }
  438. .subsidy-tag {
  439. display: inline-block;
  440. font-size: 22rpx;
  441. color: #FF5A1F;
  442. border: 2rpx solid #FF5A1F;
  443. padding: 2rpx 12rpx;
  444. border-radius: 6rpx;
  445. margin-bottom: 20rpx;
  446. background-color: #FFF2ED;
  447. }
  448. .product-title-wrap {
  449. display: flex;
  450. align-items: flex-start;
  451. }
  452. .platform-icon {
  453. width: 36rpx;
  454. height: 36rpx;
  455. margin-right: 8rpx;
  456. margin-top: 6rpx;
  457. flex-shrink: 0;
  458. }
  459. .product-title {
  460. font-size: 32rpx;
  461. font-weight: bold;
  462. color: #333;
  463. line-height: 1.5;
  464. flex: 1;
  465. }
  466. /* 店铺信息卡片 */
  467. .shop-info-card {
  468. background-color: #fff;
  469. padding: 30rpx;
  470. margin-bottom: 20rpx;
  471. display: flex;
  472. align-items: center;
  473. }
  474. .shop-icon-wrap {
  475. width: 88rpx;
  476. height: 88rpx;
  477. background-color: #F5F6F8;
  478. border-radius: 8rpx;
  479. display: flex;
  480. justify-content: center;
  481. align-items: center;
  482. margin-right: 20rpx;
  483. }
  484. .shop-name {
  485. font-size: 28rpx;
  486. color: #333;
  487. }
  488. /* 图文详情区域 */
  489. .detail-section {
  490. background-color: #fff;
  491. padding: 30rpx 0;
  492. }
  493. .section-title {
  494. font-size: 30rpx;
  495. font-weight: bold;
  496. color: #333;
  497. padding: 0 30rpx 20rpx;
  498. }
  499. .detail-content {
  500. width: 100%;
  501. }
  502. .detail-img {
  503. width: 100%;
  504. display: block;
  505. }
  506. /* 底部安全留白 */
  507. .bottom-spacer {
  508. height: 120rpx;
  509. }
  510. /* 底部固定操作栏 */
  511. .bottom-action-bar {
  512. position: fixed;
  513. bottom: 0;
  514. left: 0;
  515. width: calc(100% - 40rpx);
  516. height: 110rpx;
  517. background-color: #fff;
  518. display: flex;
  519. align-items: center;
  520. padding: 0 20rpx;
  521. padding-bottom: env(safe-area-inset-bottom);
  522. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
  523. box-sizing: content-box;
  524. z-index: 99;
  525. }
  526. .action-icons {
  527. display: flex;
  528. width: 240rpx;
  529. justify-content: space-around;
  530. }
  531. .icon-item {
  532. display: flex;
  533. flex-direction: column;
  534. align-items: center;
  535. justify-content: center;
  536. }
  537. .icon-text {
  538. font-size: 20rpx;
  539. color: #666;
  540. margin-top: 6rpx;
  541. }
  542. .action-btns {
  543. flex: 1;
  544. display: flex;
  545. justify-content: flex-end;
  546. align-items: center;
  547. }
  548. .btn-share,
  549. .btn-buy {
  550. height: 80rpx;
  551. line-height: 80rpx;
  552. font-size: 28rpx;
  553. font-weight: bold;
  554. padding: 0 20rpx;
  555. margin: 0;
  556. border-radius: 0;
  557. }
  558. .btn-share {
  559. background-color: #fff;
  560. color: #FF5A1F;
  561. border: 2rpx solid #FF5A1F;
  562. border-radius: 40rpx 0 0 40rpx;
  563. border-right: none;
  564. flex: 1;
  565. text-align: center;
  566. }
  567. .btn-buy {
  568. background: linear-gradient(90deg, #FF7E53 0%, #FF5A1F 100%);
  569. color: #fff;
  570. border-radius: 0 40rpx 40rpx 0;
  571. flex: 1;
  572. text-align: center;
  573. }
  574. button::after {
  575. border: none;
  576. }
  577. </style>