index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. } from '@dcloudio/uni-app'
  39. import FeedbackPopup from './components/feedbackPopup.vue';
  40. const showFeedback = ref(null)
  41. function handleFeedbackSubmit(data) {
  42. console.log('反馈数据:', data)
  43. }
  44. // 搜索相关
  45. const searchText = ref('')
  46. const bookList = ref([])
  47. // 处理搜索
  48. async function handleSearch() {
  49. if (!searchText.value) {
  50. uni.showToast({
  51. title: '请输入ISBN',
  52. icon: 'none'
  53. })
  54. return
  55. }
  56. await getSimpleBookInfoByIsbn(searchText.value)
  57. }
  58. // 加载数据
  59. async function getSimpleBookInfoByIsbn(isbn) {
  60. uni.$u.http.get(`/app/book/getSimpleBookInfoByIsbn/${isbn}`).then(res => {
  61. if (res.code == 200) {
  62. let bool = bookList.value.some(v => v.isbn == isbn)
  63. if (!bool) {
  64. bookList.value.push(res.data)
  65. }
  66. } else {
  67. uni.$u.toast(res.msg)
  68. }
  69. })
  70. }
  71. // 扫码
  72. function scanCode() {
  73. uni.scanCode({
  74. scanType: ['barCode'],
  75. success: (res) => {
  76. searchText.value = res.result
  77. getSimpleBookInfoByIsbn(res.result)
  78. },
  79. fail: () => {
  80. uni.showToast({
  81. title: '扫码失败',
  82. icon: 'none'
  83. })
  84. }
  85. })
  86. }
  87. // 编辑图书
  88. function editBook(book) {
  89. // 处理编辑逻辑
  90. showFeedback.value?.open(book)
  91. }
  92. onLoad(() => {
  93. // #ifdef APP-PLUS
  94. uni.$u.useGlobalEvent((e) => {
  95. if (!e.barcode) return
  96. getSimpleBookInfoByIsbn(e.barcode)
  97. })
  98. // #endif
  99. })
  100. </script>
  101. <style lang="scss" scoped>
  102. .search-header {
  103. position: sticky;
  104. top: 0;
  105. z-index: 100;
  106. background-color: rgb(34, 172, 56);
  107. padding: 20rpx;
  108. .search-box {
  109. display: flex;
  110. align-items: center;
  111. border-radius: 8rpx;
  112. padding: 0 20rpx;
  113. }
  114. :deep(.uni-input-placeholder) {
  115. font-size: 32rpx;
  116. }
  117. }
  118. .book-list {
  119. padding: 20rpx;
  120. .book-item {
  121. display: flex;
  122. justify-content: space-between;
  123. align-items: center;
  124. background-color: #ffffff;
  125. border-radius: 12rpx;
  126. padding: 20rpx;
  127. margin-bottom: 20rpx;
  128. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  129. .book-info {
  130. display: flex;
  131. flex: 1;
  132. .book-image {
  133. width: 160rpx;
  134. height: 200rpx;
  135. border-radius: 8rpx;
  136. margin-right: 20rpx;
  137. }
  138. .book-details {
  139. display: flex;
  140. flex-direction: column;
  141. justify-content: space-between;
  142. .book-title {
  143. font-size: 32rpx;
  144. font-weight: bold;
  145. color: #333;
  146. }
  147. .book-isbn,
  148. .book-price,
  149. .book-set {
  150. font-size: 26rpx;
  151. color: #666;
  152. margin-top: 8rpx;
  153. }
  154. }
  155. }
  156. .book-action {
  157. padding: 20rpx;
  158. }
  159. }
  160. }
  161. </style>