detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view class="detail-page">
  3. <!-- Top Background -->
  4. <view class="header-bg"></view>
  5. <!-- Custom Navbar -->
  6. <Navbar :title="product.bookName || '详情'" :titleSize="32" :title-color="navbarTitleColor"
  7. :back-icon-color="navbarIconColor" :background="navbarBackground">
  8. </Navbar>
  9. <!-- Notification Bar -->
  10. <!-- <view class="notification-bar">
  11. <u-avatar size="40" src="https://img.yzcdn.cn/vant/cat.jpeg"></u-avatar>
  12. <text class="notif-text">微 ** 用户 购买了 《苏菲的世界》</text>
  13. </view> -->
  14. <view class="content-scroll">
  15. <!-- Book Cover Area -->
  16. <view class="cover-area">
  17. <image class="book-cover" :src="product.cover" mode="heightFix"></image>
  18. <view class="share-btn" @click="openSharePopup">
  19. <image src="/pages-sell/static/goods/icon-share.png" class="share-icon"></image>
  20. <text>分享</text>
  21. </view>
  22. </view>
  23. <!-- Product Info Card -->
  24. <InfoCard :product="product"></InfoCard>
  25. <!-- Banner -->
  26. <view class="banner-area">
  27. <image src="/pages-sell/static/top-banner.png" class="banner-img" mode="widthFix"></image>
  28. </view>
  29. <!-- Service Info -->
  30. <ServiceCard @click="showReduceRulePopup" :bookInfo="product"></ServiceCard>
  31. <!-- Customer Service Float -->
  32. <FloatingDrag :width="126" :height="140" :initial-position="servicePosition"
  33. @position-change="handlePositionChange"
  34. @drag-start="handleDragStart"
  35. @drag-end="handleDragEnd">
  36. <!-- #ifdef MP-ALIPAY -->
  37. <button class="service-btn" @click="navigateToCustomerService">
  38. <image src="/static/img/kf.png" class="cs-icon" mode="aspectFit"></image>
  39. </button>
  40. <!-- #endif -->
  41. <!-- #ifndef MP-ALIPAY -->
  42. <button class="service-btn" open-type="contact">
  43. <image src="/static/img/kf.png" class="cs-icon" mode="aspectFit"></image>
  44. </button>
  45. <!-- #endif -->
  46. </FloatingDrag>
  47. <!-- Tabs -->
  48. <view class="tabs-header">
  49. <view class="tab-item" :class="{ active: currentTab === 0 }" @click="switchTab(0)">
  50. <text>商品详情</text>
  51. <view class="indicator" v-if="currentTab === 0"></view>
  52. </view>
  53. <view class="tab-item" :class="{ active: currentTab === 1 }" @click="switchTab(1)">
  54. <text>相关推荐</text>
  55. <view class="indicator" v-if="currentTab === 1"></view>
  56. </view>
  57. </view>
  58. <!-- Product Detail Content -->
  59. <ProductContent :currentTab="currentTab" :product="product" :tipsContent="tipsContent"
  60. :relatedBooksList="relatedBooksList" @bookClick="onBookClick">
  61. </ProductContent>
  62. <u-gap height="220"></u-gap>
  63. </view>
  64. <!-- Footer -->
  65. <FooterBar :hasStock="hasStock" :isCollect="product.isCollect" :hasArrivalNotice="product.hasArrivalNotice"
  66. @addCart="openSelectPopup" @notify="handleNotify" @collect="handleCollect"></FooterBar>
  67. <!-- Select Popup -->
  68. <SelectGoodPopup ref="selectPopup" @confirm="onPopupConfirm" @notice-change="onNoticeChange"></SelectGoodPopup>
  69. <!-- Share Popup -->
  70. <SharePopup ref="sharePopup" :product="product"></SharePopup>
  71. <!-- Reduce Rule Popup -->
  72. <ReduceRulePopup ref="reduceRulePopup"></ReduceRulePopup>
  73. </view>
  74. </template>
  75. <script>
  76. import Navbar from '@/components/navbar/navbar.vue'
  77. import SelectGoodPopup from '../components/select-good-popup/index.vue'
  78. import InfoCard from '../components/detail/info-card.vue'
  79. import ServiceCard from '../components/detail/service-card.vue'
  80. import ProductContent from '../components/detail/product-content.vue'
  81. import FooterBar from '../components/detail/footer-bar.vue'
  82. import FloatingDrag from "@/components/floating-drag.vue";
  83. import SharePopup from '../components/detail/share-popup.vue';
  84. import ReduceRulePopup from '../components/reduce-rule-popup/index.vue';
  85. export default {
  86. components: {
  87. Navbar,
  88. SelectGoodPopup,
  89. InfoCard,
  90. ServiceCard,
  91. ProductContent,
  92. FooterBar,
  93. FloatingDrag,
  94. SharePopup,
  95. ReduceRulePopup
  96. },
  97. data() {
  98. return {
  99. currentTab: 0,
  100. hasStock: false, // Toggle this to test stock status
  101. navbarBackground: 'transparent',
  102. navbarTitleColor: '#ffffff',
  103. navbarIconColor: '#ffffff',
  104. isDragging: false, // 是否正在拖动悬浮按钮
  105. tipsContent: [
  106. '印刷版次较多,二手图书封面、版次、原价等信息可能与商品介绍有差异,具体以收到实物为准;',
  107. '二手图书性质特殊,不保证随新书赠送的光盘、海报、卡片等内容,仅支持图书质量问题退款,否则将扣除运费成本;',
  108. '收到的图书如有质量问题,请于七天内联系客服处理,超出售后时效,不予处理。'
  109. ],
  110. relatedBooksList: [],
  111. product: {},
  112. servicePosition: {
  113. left: "auto",
  114. right: 0,
  115. bottom: "300rpx",
  116. },
  117. }
  118. },
  119. onLoad(options) {
  120. const isbn = options.isbn || options.id; // Support both just in case
  121. if (isbn) {
  122. this.getBookDetail(isbn);
  123. } else {
  124. uni.showToast({
  125. title: '参数错误',
  126. icon: 'none'
  127. });
  128. setTimeout(() => {
  129. uni.navigateBack();
  130. }, 1500);
  131. }
  132. },
  133. onPageScroll(e) {
  134. if (this.isDragging) return; // 拖动悬浮按钮时禁止滚动
  135. if (e.scrollTop > 0) {
  136. this.navbarBackground = '#ffffff';
  137. this.navbarTitleColor = '#000000';
  138. this.navbarIconColor = '#000000';
  139. } else {
  140. this.navbarBackground = 'transparent';
  141. this.navbarTitleColor = '#ffffff';
  142. this.navbarIconColor = '#ffffff';
  143. }
  144. },
  145. methods: {
  146. getBookDetail(isbn) {
  147. uni.showLoading({ title: '加载中' });
  148. this.$u.api.getBookDetailAjax({ isbn }).then(res => {
  149. uni.hideLoading();
  150. if (res.code === 200) {
  151. this.product = res.data;
  152. this.hasStock = res.data.skuList.some(sku => sku.stockNum > 0);
  153. if (res.data.recommendList) {
  154. this.relatedBooksList = res.data.recommendList;
  155. }
  156. } else {
  157. uni.showToast({
  158. title: res.msg || '获取详情失败',
  159. icon: 'none'
  160. });
  161. }
  162. }).catch(() => {
  163. uni.hideLoading();
  164. });
  165. },
  166. switchTab(index) {
  167. this.currentTab = index;
  168. },
  169. openSelectPopup(sourceFrom) {
  170. this.$refs.selectPopup.open(this.product, sourceFrom);
  171. },
  172. onNoticeChange(val) {
  173. this.$set(this.product, 'hasArrivalNotice', val);
  174. },
  175. handleNotify() {
  176. const isCancel = this.product.hasArrivalNotice === 1;
  177. const apiUrl = isCancel ? '/token/shop/user/noticeArrivalCancel' : '/token/shop/user/noticeArrival';
  178. uni.showLoading({ mask: true });
  179. uni.$u.http.post(apiUrl, { isbn: this.product.isbn }).then(res => {
  180. uni.hideLoading();
  181. if (res.code === 200) {
  182. this.$set(this.product, 'hasArrivalNotice', isCancel ? 0 : 1);
  183. uni.showToast({
  184. title: isCancel ? '已取消到货通知' : '已订阅到货通知',
  185. icon: 'success'
  186. });
  187. } else {
  188. uni.showToast({
  189. title: res.msg || '操作失败',
  190. icon: 'none'
  191. });
  192. }
  193. }).catch(() => {
  194. uni.hideLoading();
  195. });
  196. },
  197. async onPopupConfirm(data) {
  198. console.log('Added to cart:', data);
  199. await this.$updateCartBadge();
  200. uni.showToast({
  201. title: '已加入购物车',
  202. icon: 'success',
  203. duration: 3000
  204. });
  205. },
  206. handleCollect() {
  207. if (!this.product || !this.product.isbn) {
  208. return this.$u.toast('商品信息不完整');
  209. }
  210. const isCollect = this.product.isCollect;
  211. const api = isCollect ? this.$u.api.removeCollectAjax : this.$u.api.addCollectAjax;
  212. const params = isCollect ? [this.product.isbn] : this.product.isbn;
  213. uni.showLoading({ mask: true });
  214. api(params).then(res => {
  215. uni.hideLoading();
  216. if (res.code === 200) {
  217. this.$set(this.product, 'isCollect', !isCollect);
  218. this.$u.toast(isCollect ? '已取消收藏' : '收藏成功');
  219. } else {
  220. this.$u.toast(res.msg);
  221. }
  222. }).catch(() => {
  223. uni.hideLoading();
  224. });
  225. },
  226. showReduceRulePopup() {
  227. this.$refs.reduceRulePopup.open();
  228. },
  229. onBookClick(book) {
  230. console.log('Book clicked:', book);
  231. uni.navigateTo({
  232. url: '/pages-sell/pages/detail?id=' + encodeURIComponent(book.title)
  233. });
  234. },
  235. openSharePopup() {
  236. this.$refs.sharePopup.open();
  237. },
  238. // 处理位置变更
  239. handlePositionChange(position) {
  240. this.servicePosition = position;
  241. },
  242. // 拖动开始
  243. handleDragStart() {
  244. this.isDragging = true;
  245. },
  246. // 拖动结束
  247. handleDragEnd() {
  248. this.isDragging = false;
  249. },
  250. //支付宝小程序的客服
  251. navigateToCustomerService() {
  252. uni.navigateTo({
  253. url: "/pages-mine/pages/customer-service",
  254. });
  255. },
  256. },
  257. onShareAppMessage(res) {
  258. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  259. let reduceCode = uni.getStorageSync("reduceCodeShare");
  260. // 调用分享接口
  261. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  262. this.$u.api.goToReduceShareAjax({
  263. reduceCode: reduceCode
  264. });
  265. } else {
  266. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  267. }
  268. return {
  269. title: "快来帮我减钱买书吧!",
  270. path: "/pages/home/index?reduceCode=" + reduceCode,
  271. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  272. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  273. };
  274. }
  275. return {
  276. title: `${this.product.bookName}`,
  277. path: `/pages-sell/pages/detail?isbn=${this.product.isbn}`,
  278. imageUrl: this.product.cover
  279. };
  280. }
  281. }
  282. </script>
  283. <style lang="scss" scoped>
  284. .detail-page {
  285. min-height: 100vh;
  286. background-color: #f5f5f5;
  287. position: relative;
  288. padding-bottom: 100rpx;
  289. }
  290. .header-bg {
  291. position: absolute;
  292. top: 0;
  293. left: 0;
  294. width: 100%;
  295. height: 664rpx;
  296. background: linear-gradient(0deg, #4ED868 0%, #D1FFE5 100%);
  297. z-index: 0;
  298. }
  299. .notification-bar {
  300. position: fixed;
  301. top: 180rpx;
  302. /* Adjust based on navbar height */
  303. left: 30rpx;
  304. z-index: 10;
  305. background: rgba(0, 0, 0, 0.3);
  306. border-radius: 30rpx;
  307. padding: 6rpx 20rpx 6rpx 6rpx;
  308. display: flex;
  309. align-items: center;
  310. .notif-text {
  311. font-size: 24rpx;
  312. color: #fff;
  313. margin-left: 10rpx;
  314. }
  315. }
  316. .content-scroll {
  317. position: relative;
  318. z-index: 1;
  319. height: 100vh;
  320. }
  321. .cover-area {
  322. position: relative;
  323. display: flex;
  324. justify-content: center;
  325. padding-top: 60rpx;
  326. padding-bottom: 40rpx;
  327. .book-cover {
  328. width: 360rpx;
  329. height: 360rpx;
  330. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  331. }
  332. .share-btn {
  333. position: absolute;
  334. right: 50rpx;
  335. top: 50rpx;
  336. display: flex;
  337. flex-direction: column;
  338. align-items: center;
  339. z-index: 10; // Ensure it's clickable
  340. .share-icon {
  341. width: 40rpx;
  342. height: 40rpx;
  343. margin-bottom: 4rpx;
  344. }
  345. text {
  346. font-size: 20rpx;
  347. color: #333;
  348. }
  349. }
  350. }
  351. .banner-area {
  352. background: #f5f5f5;
  353. padding: 20rpx;
  354. .banner-img {
  355. width: 100%;
  356. border-radius: 20rpx;
  357. }
  358. }
  359. .service-btn {
  360. width: 100%;
  361. height: 100%;
  362. display: flex;
  363. justify-content: center;
  364. align-items: center;
  365. padding: 0;
  366. margin: 0;
  367. background-color: transparent;
  368. line-height: 1;
  369. border-radius: 0;
  370. &::after {
  371. border: none;
  372. }
  373. .cs-icon {
  374. width: 100rpx;
  375. height: 100rpx;
  376. }
  377. }
  378. .tabs-header {
  379. display: flex;
  380. justify-content: center;
  381. /* Center the tabs */
  382. background: #F8F8F8;
  383. padding: 20rpx 0;
  384. /* Remove horizontal padding as we center items */
  385. .tab-item {
  386. padding: 0 30rpx;
  387. /* Add internal padding for hit area */
  388. position: relative;
  389. text {
  390. font-family: 'Source Han Sans SC';
  391. font-size: 30rpx;
  392. /* Assuming 30px from design tool = 30rpx */
  393. color: #666666;
  394. transition: all 0.3s;
  395. }
  396. &.active {
  397. text {
  398. font-size: 30rpx;
  399. /* Keep consistent size or adjust if 'big' effect needed, user said 30px */
  400. font-weight: bold;
  401. color: #333333;
  402. }
  403. .indicator {
  404. position: absolute;
  405. bottom: 2rpx;
  406. /* Adjust vertical position */
  407. left: 50%;
  408. transform: translateX(-50%);
  409. width: 120rpx;
  410. /* Make it wider or relative to text? Usually fixed or text width. Let's try matching text width visually or a fixed width */
  411. height: 8rpx;
  412. /* Slightly thicker for gradient visibility */
  413. background: linear-gradient(90deg, rgba(78, 217, 100, 0.1) 0%, #4ED964 100%);
  414. border-radius: 4rpx;
  415. }
  416. }
  417. }
  418. }
  419. </style>