scan-book.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="container">
  3. <!-- 顶部搜索框 -->
  4. <u-sticky>
  5. <view class="search-area">
  6. <u-search v-model="searchValue" placeholder="扫描/输入ISBN或SH码" :show-action="true" actionText="查询"
  7. @search="handleSearch" @custom="handleSearch">
  8. <template #suffixIcon>
  9. <u-icon name="close" size="20" v-if="searchValue" @click="searchValue = ''" />
  10. </template>
  11. </u-search>
  12. </view>
  13. </u-sticky>
  14. <!-- 已扫描ISBN显示 -->
  15. <view class="isbn-display" v-if="scannedISBN">
  16. <text>已查询ISBN:{{ scannedISBN }}</text>
  17. </view>
  18. <!-- 内容区域 -->
  19. <view class="content">
  20. <!-- 空状态 -->
  21. <view class="empty-state" v-if="!bookInfo">
  22. <u-empty mode="data" text="暂无扫描数据" margin-top="100" />
  23. </view>
  24. <!-- 书籍详情 -->
  25. <view class="book-detail" v-else>
  26. <view class="common-card mb-20">
  27. <view class="flex flex-d flex-a-c">
  28. <image class="book-image" :src="bookInfo.cover" mode="heightFix" />
  29. <text class="ml-20 font-15">{{ bookInfo.bookName }}</text>
  30. </view>
  31. <view class="book-status">
  32. <text class="status-text">状态:{{bookInfo.recycleStatus?'已加入回收书单':'未加入回收书单'}}</text>
  33. <text class="time-text" v-if="bookInfo.recycleTime">加入时间:{{ bookInfo.recycleTime }}</text>
  34. </view>
  35. </view>
  36. <!-- 基本信息 -->
  37. <view class="common-card info-section mb-20">
  38. <view class="price-info">
  39. <text class="label">定价:</text>
  40. <text class="price">¥{{ bookInfo.price }}</text>
  41. <text class="recycle-price">回收价:¥{{ bookInfo.expectPrice }}</text>
  42. </view>
  43. <view class="book-info">
  44. <view class="info-item">
  45. <text class="label">ISBN:</text>
  46. <text>{{ bookInfo.isbn }}</text>
  47. </view>
  48. <view class="info-item">
  49. <text class="label">语言:</text>
  50. <text>{{ bookInfo.lang||'-' }}</text>
  51. </view>
  52. <view class="info-item">
  53. <text class="label">作者:</text>
  54. <text>{{ bookInfo.author }}</text>
  55. </view>
  56. <view class="info-item">
  57. <text class="label">出版社:</text>
  58. <text>{{ bookInfo.publish }}</text>
  59. </view>
  60. <view class="info-item">
  61. <text class="label">出版时间:</text>
  62. <text>{{ bookInfo.pubDate }}</text>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- 简介和轨迹 -->
  67. <view class="common-card tabs-section" style="padding:0">
  68. <u-tabs :list="tabsList" v-model="currentTab" lineColor="#19be6b" />
  69. <view class="tab-content">
  70. <view v-if="currentTab === 0" class="intro-content">
  71. <text class="section-title">内容简介:</text>
  72. <text class="content-text">{{ bookInfo.contentBlurb }}</text>
  73. <text class="section-title">作者简介:</text>
  74. <text class="content-text">{{ bookInfo.anthorBlurb }}</text>
  75. <text class="content-text">{{ bookInfo.catalog }}</text>
  76. </view>
  77. <view v-else class="track-content">
  78. <text>{{ bookInfo.track }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. <!-- 底部扫描按钮 -->
  85. <view class="fixed-bottom">
  86. <u-button size="large" type="primary" text="扫码(ISBN或SH码)" @click="handleScan" />
  87. </view>
  88. </view>
  89. </template>
  90. <script setup>
  91. import {
  92. ref
  93. } from 'vue';
  94. const searchValue = ref('');
  95. const scannedISBN = ref('');
  96. const currentTab = ref(0);
  97. const tabsList = [{
  98. name: '简介'
  99. },
  100. {
  101. name: '轨迹'
  102. }
  103. ];
  104. // 模拟书籍信息
  105. const bookInfo = ref(null);
  106. // 处理搜索
  107. const handleSearch = () => {
  108. if (!searchValue.value) return;
  109. loadBookInfo(searchValue.value);
  110. };
  111. // 处理扫描
  112. const handleScan = () => {
  113. uni.scanCode({
  114. success: (res) => {
  115. searchValue.value = res.result;
  116. scannedISBN.value = res.result;
  117. loadBookInfo(res.result);
  118. }
  119. });
  120. };
  121. // 加载书籍信息
  122. const loadBookInfo = (isbn) => {
  123. uni.$u.http.get(`/app/book/getBookByIsbn/${isbn}`).then(res => {
  124. if (res.code == 200) {
  125. bookInfo.value = res.data
  126. }
  127. })
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. .container {
  132. display: flex;
  133. flex-direction: column;
  134. box-sizing: border-box;
  135. padding-bottom: 70px;
  136. }
  137. .search-box {
  138. padding: 12px;
  139. background-color: #fff;
  140. }
  141. .isbn-display {
  142. padding: 8px 12px;
  143. background-color: #e8f5e9;
  144. color: #19be6b;
  145. font-size: 14px;
  146. }
  147. .book-detail {
  148. margin: 12px;
  149. border-radius: 8px;
  150. overflow: hidden;
  151. }
  152. .book-image {
  153. width: 260rpx;
  154. height: 300rpx;
  155. object-fit: cover;
  156. border-radius: 5px;
  157. }
  158. .book-status {
  159. padding: 12px;
  160. .status-text {
  161. font-size: 16px;
  162. color: #19be6b;
  163. margin-bottom: 4px;
  164. display: block;
  165. }
  166. .time-text {
  167. font-size: 14px;
  168. color: #999;
  169. }
  170. }
  171. .info-section {
  172. padding: 16px;
  173. .price-info {
  174. margin-bottom: 16px;
  175. .price {
  176. color: #19be6b;
  177. font-size: 18px;
  178. font-weight: bold;
  179. margin-right: 12px;
  180. }
  181. .recycle-price {
  182. color: #666;
  183. font-size: 14px;
  184. }
  185. }
  186. }
  187. .info-item {
  188. margin-bottom: 8px;
  189. font-size: 14px;
  190. .label {
  191. color: #666;
  192. margin-right: 8px;
  193. }
  194. }
  195. .tab-content {
  196. padding: 16px;
  197. padding-top: 0;
  198. .section-title {
  199. font-weight: bold;
  200. margin-top: 12px;
  201. margin-bottom: 6px;
  202. display: block;
  203. }
  204. .content-text {
  205. font-size: 14px;
  206. color: #666;
  207. line-height: 1.6;
  208. margin-bottom: 16px;
  209. }
  210. }
  211. .footer {
  212. padding: 12px;
  213. background-color: #fff;
  214. }
  215. .empty-state {
  216. flex: 1;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. }
  221. </style>