ScanBookList.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="wrapper">
  3. <scroll-view
  4. scroll-y
  5. @scroll="onScroll"
  6. :refresher-enabled="isAtTop"
  7. :refresher-triggered="isRefreshing"
  8. @refresherrefresh="onRefresh"
  9. @scrolltoupper="scrollToUpper"
  10. upper-threshold="5"
  11. class="book-scroll"
  12. >
  13. <view class="scan-book-list">
  14. <!-- 顶部提示 -->
  15. <view class="tip-text">
  16. 套装书(相同ISBN相同的系列书籍)只需扫描其中一本,扫描价即套装价;需用户将整个套装全部寄出,缺册不予回收。
  17. </view>
  18. <!-- 书籍列表 -->
  19. <view class="book-list">
  20. <BookItem
  21. v-for="book in bookList"
  22. :key="book.isbn"
  23. :book="book"
  24. @delete="handleDeleteBook"
  25. @quantity-change="handleQuantityChange"
  26. @upsell="handleUpsell"
  27. />
  28. </view>
  29. <view class="link-wrap flex-a">
  30. <text class="link-btn flex-1" @click="goToScannedBooks"
  31. >扫过的书 ></text
  32. >
  33. <text class="link-btn flex-1" @click="goToRules">卖书规则 ></text>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. </template>
  39. <script>
  40. import BookItem from "./BookItem.vue";
  41. export default {
  42. components: {
  43. BookItem,
  44. },
  45. props: {
  46. bookList: {
  47. type: Array,
  48. default: () => [],
  49. },
  50. },
  51. data() {
  52. return {
  53. books: [],
  54. isRefreshing: false,
  55. isAtTop: true, // 是否在顶部,默认为true
  56. scrollTop: 0,
  57. };
  58. },
  59. watch: {
  60. bookList: {
  61. handler(newVal) {
  62. this.books = newVal;
  63. },
  64. deep: true,
  65. immediate: true,
  66. },
  67. },
  68. methods: {
  69. // 滚动事件
  70. onScroll(e) {
  71. // 记录滚动位置
  72. this.scrollTop = e.detail.scrollTop;
  73. // 只有在最顶部时才能触发下拉刷新
  74. this.isAtTop = this.scrollTop < 5;
  75. },
  76. // 滚动到顶部事件
  77. scrollToUpper() {
  78. this.isAtTop = true;
  79. },
  80. // 下拉刷新
  81. onRefresh() {
  82. this.isRefreshing = true;
  83. // 触发父组件的刷新事件
  84. this.$emit("refresh");
  85. // 模拟刷新完成
  86. setTimeout(() => {
  87. this.isRefreshing = false;
  88. }, 600);
  89. },
  90. // 加价
  91. handleUpsell(book) {
  92. this.$emit("upsell", book);
  93. },
  94. handleDeleteBook(book) {
  95. this.$emit("deleted", book);
  96. },
  97. handleQuantityChange(data) {
  98. const book = this.books.find((book) => book.isbn === data.isbn);
  99. if (book) {
  100. book.num = data.num;
  101. }
  102. this.$emit("updateBooks", this.books, book);
  103. },
  104. onNext() {
  105. this.$emit("next");
  106. },
  107. goToScannedBooks() {
  108. uni.navigateTo({
  109. url: "/pages-home/pages/scaned-book",
  110. });
  111. },
  112. goToRules() {
  113. uni.navigateTo({
  114. url: "/pages-mine/pages/rules-for-sellbooks",
  115. });
  116. },
  117. },
  118. };
  119. </script>
  120. <style lang="scss">
  121. .wrapper {
  122. height: 100%;
  123. width: 100%;
  124. position: relative;
  125. }
  126. .book-scroll {
  127. height: calc(100vh - 240px);
  128. }
  129. .scan-book-list {
  130. padding: 20rpx;
  131. display: flex;
  132. flex-direction: column;
  133. .tip-text {
  134. font-family: Source Han Sans CN;
  135. font-weight: 400;
  136. font-size: 24rpx;
  137. color: #ff8a4b;
  138. line-height: 36rpx;
  139. }
  140. .link-wrap {
  141. gap: 20rpx;
  142. box-sizing: border-box;
  143. margin-top: 20rpx;
  144. .link-btn {
  145. height: 80rpx;
  146. background: #ffffff;
  147. border-radius: 10rpx;
  148. display: flex;
  149. align-items: center;
  150. justify-content: center;
  151. font-family: PingFang SC;
  152. font-weight: 500;
  153. font-size: 32rpx;
  154. color: #666666;
  155. }
  156. }
  157. }
  158. </style>