index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="book-list" style="padding:0">
  3. <!-- 搜索框 -->
  4. <view class="search-header">
  5. <view class="search-box">
  6. <u-icon style="margin-right:16rpx" name="scan" size="30" color="#ffffff" @click="scanCode"></u-icon>
  7. <u-search height="80rpx" v-model="searchText" placeholder="请输入ISBN" :showAction="false"
  8. :clearabled="true" @search="handleSearch" bgColor="#ffffff"></u-search>
  9. </view>
  10. </view>
  11. <!-- 搜索结果列表 -->
  12. <view class="book-list" v-if="bookList.length > 0">
  13. <view class="book-item" v-for="(book, index) in bookList" :key="index">
  14. <view class="book-info">
  15. <image class="book-image" :src="book.cover" mode="aspectFill"></image>
  16. <view class="book-details">
  17. <text class="book-title">{{ book.bookName }}</text>
  18. <text class="book-isbn">ISBN: {{ book.isbn }}</text>
  19. <text class="book-price">定价: {{ book.price }}</text>
  20. <text class="book-set">套装: {{ book.suit == 1 ? '是' : '否' }}</text>
  21. </view>
  22. </view>
  23. <view class="book-action">
  24. <u-icon name="edit-pen" size="30" color="#4cd964" @click="editBook(book)"></u-icon>
  25. </view>
  26. </view>
  27. </view>
  28. <feedback-popup ref="showFeedback" @submit="handleFeedbackSubmit"></feedback-popup>
  29. </view>
  30. </template>
  31. <script setup>
  32. import {
  33. ref,
  34. computed
  35. } from 'vue'
  36. import {
  37. onLoad,
  38. onShow
  39. } from '@dcloudio/uni-app'
  40. import FeedbackPopup from './components/feedbackPopup.vue';
  41. const showFeedback = ref(null)
  42. function handleFeedbackSubmit(data) {
  43. console.log('反馈数据:', data)
  44. }
  45. // 搜索相关
  46. const searchText = ref('')
  47. const bookList = ref([])
  48. // 处理搜索
  49. async function handleSearch() {
  50. if (!searchText.value) {
  51. uni.showToast({
  52. title: '请输入ISBN',
  53. icon: 'none'
  54. })
  55. return
  56. }
  57. await getSimpleBookInfoByIsbn(searchText.value)
  58. }
  59. // 加载数据
  60. async function getSimpleBookInfoByIsbn(isbn) {
  61. uni.$u.http.get(`/app/book/getSimpleBookInfoByIsbn/${isbn}`).then(res => {
  62. if (res.code == 200) {
  63. let bool = bookList.value.some(v => v.isbn == isbn)
  64. if (!bool) {
  65. bookList.value.push(res.data)
  66. }
  67. } else {
  68. uni.$u.toast(res.msg)
  69. }
  70. })
  71. }
  72. // 扫码
  73. function scanCode() {
  74. uni.scanCode({
  75. scanType: ['barCode'],
  76. success: (res) => {
  77. searchText.value = res.result
  78. getSimpleBookInfoByIsbn(res.result)
  79. },
  80. fail: () => {
  81. uni.showToast({
  82. title: '扫码失败',
  83. icon: 'none'
  84. })
  85. }
  86. })
  87. }
  88. // 编辑图书
  89. function editBook(book) {
  90. // 处理编辑逻辑
  91. showFeedback.value?.open(book)
  92. }
  93. onLoad(() => {
  94. // #ifdef APP-PLUS
  95. uni.$u.useGlobalEvent((e) => {
  96. if (!e.barcode) return
  97. getSimpleBookInfoByIsbn(e.barcode)
  98. })
  99. // #endif
  100. })
  101. onShow(() => {
  102. uni.$u.updateActivePageOnShow()
  103. })
  104. </script>
  105. <style lang="scss" scoped>
  106. .search-header {
  107. position: sticky;
  108. top: 0;
  109. z-index: 100;
  110. background-color: rgb(34, 172, 56);
  111. padding: 20rpx;
  112. .search-box {
  113. display: flex;
  114. align-items: center;
  115. border-radius: 8rpx;
  116. padding: 0 20rpx;
  117. }
  118. :deep(.uni-input-placeholder) {
  119. font-size: 32rpx;
  120. }
  121. }
  122. .book-list {
  123. padding: 20rpx;
  124. .book-item {
  125. display: flex;
  126. justify-content: space-between;
  127. align-items: center;
  128. background-color: #ffffff;
  129. border-radius: 12rpx;
  130. padding: 20rpx;
  131. margin-bottom: 20rpx;
  132. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  133. .book-info {
  134. display: flex;
  135. flex: 1;
  136. .book-image {
  137. width: 160rpx;
  138. height: 200rpx;
  139. border-radius: 8rpx;
  140. margin-right: 20rpx;
  141. }
  142. .book-details {
  143. display: flex;
  144. flex-direction: column;
  145. justify-content: space-between;
  146. .book-title {
  147. font-size: 32rpx;
  148. font-weight: bold;
  149. color: #333;
  150. }
  151. .book-isbn,
  152. .book-price,
  153. .book-set {
  154. font-size: 26rpx;
  155. color: #666;
  156. margin-top: 8rpx;
  157. }
  158. }
  159. }
  160. .book-action {
  161. padding: 20rpx;
  162. }
  163. }
  164. }
  165. </style>