scan-book.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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>已成功添加:{{ 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-a-e">
  28. <image class="book-image" :src="bookInfo.image" mode="heightFix" />
  29. <text class="ml-20 font-15">{{bookInfo.name}}</text>
  30. </view>
  31. <view class="book-status">
  32. <text class="status-text">状态:已加入回收书单</text>
  33. <text class="time-text">加入时间:{{ bookInfo.addTime }}</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.recyclePrice }}</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.language }}</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.publisher }}</text>
  59. </view>
  60. <view class="info-item">
  61. <text class="label">出版时间:</text>
  62. <text>{{ bookInfo.publishDate }}</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.introduction }}</text>
  73. <text class="section-title">作者简介:</text>
  74. <text class="content-text">{{ bookInfo.authorIntro }}</text>
  75. </view>
  76. <view v-else class="track-content">
  77. <text>{{ bookInfo.track }}</text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 底部扫描按钮 -->
  84. <view class="fixed-bottom">
  85. <u-button size="large" type="primary" text="扫码(ISBN或SH码)" @click="handleScan" />
  86. </view>
  87. </view>
  88. </template>
  89. <script setup>
  90. import {
  91. ref
  92. } from 'vue';
  93. const searchValue = ref('');
  94. const scannedISBN = ref('');
  95. const currentTab = ref(0);
  96. const tabsList = [{
  97. name: '简介'
  98. },
  99. {
  100. name: '轨迹'
  101. }
  102. ];
  103. // 模拟书籍信息
  104. const bookInfo = ref(null);
  105. // 处理搜索
  106. const handleSearch = () => {
  107. if (!searchValue.value) return;
  108. loadBookInfo(searchValue.value);
  109. };
  110. // 处理扫描
  111. const handleScan = () => {
  112. uni.scanCode({
  113. success: (res) => {
  114. searchValue.value = res.result;
  115. scannedISBN.value = res.result;
  116. loadBookInfo(res.result);
  117. }
  118. });
  119. };
  120. // 加载书籍信息
  121. const loadBookInfo = (isbn) => {
  122. // 模拟数据
  123. bookInfo.value = {
  124. name: '圆圈正义',
  125. image: 'https://img20.360buyimg.com/da/jfs/t1/141592/25/8861/261559/5f68d8c1E33ed78ab/698ad655bfcfbaed.png',
  126. addTime: '2023-05-15 12:15:12',
  127. price: '46',
  128. recyclePrice: '4.6[1折]',
  129. isbn: '9787015454545',
  130. language: '中文',
  131. author: '罗翔',
  132. publisher: '中国法治出版社',
  133. publishDate: '2019-08-12',
  134. introduction: '《圆圈正义》一书共收录作者的40篇微信文章...',
  135. authorIntro: '罗翔,男,中国政法大学教授...',
  136. track: '轨迹信息...'
  137. };
  138. };
  139. </script>
  140. <style lang="scss" scoped>
  141. .container {
  142. display: flex;
  143. flex-direction: column;
  144. box-sizing: border-box;
  145. padding-bottom: 50px;
  146. }
  147. .search-box {
  148. padding: 12px;
  149. background-color: #fff;
  150. }
  151. .isbn-display {
  152. padding: 8px 12px;
  153. background-color: #e8f5e9;
  154. color: #19be6b;
  155. font-size: 14px;
  156. }
  157. .book-detail {
  158. margin: 12px;
  159. border-radius: 8px;
  160. overflow: hidden;
  161. }
  162. .book-image {
  163. width: 100%;
  164. height: 300rpx;
  165. object-fit: cover;
  166. border-radius: 5px;
  167. }
  168. .book-status {
  169. padding: 12px;
  170. .status-text {
  171. font-size: 16px;
  172. color: #19be6b;
  173. margin-bottom: 4px;
  174. display: block;
  175. }
  176. .time-text {
  177. font-size: 14px;
  178. color: #999;
  179. }
  180. }
  181. .info-section {
  182. padding: 16px;
  183. .price-info {
  184. margin-bottom: 16px;
  185. .price {
  186. color: #19be6b;
  187. font-size: 18px;
  188. font-weight: bold;
  189. margin-right: 12px;
  190. }
  191. .recycle-price {
  192. color: #666;
  193. font-size: 14px;
  194. }
  195. }
  196. }
  197. .info-item {
  198. margin-bottom: 8px;
  199. font-size: 14px;
  200. .label {
  201. color: #666;
  202. margin-right: 8px;
  203. }
  204. }
  205. .tab-content {
  206. padding: 16px;
  207. padding-top: 0;
  208. .section-title {
  209. font-weight: bold;
  210. margin-top: 12px;
  211. margin-bottom: 6px;
  212. display: block;
  213. }
  214. .content-text {
  215. font-size: 14px;
  216. color: #666;
  217. line-height: 1.6;
  218. margin-bottom: 16px;
  219. }
  220. }
  221. .footer {
  222. padding: 12px;
  223. background-color: #fff;
  224. }
  225. .empty-state {
  226. flex: 1;
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. }
  231. </style>