detail.vue 14 KB

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