scan-book.vue 7.4 KB

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