scaned-book.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="scan-history">
  3. <!-- 顶部操作栏 -->
  4. <view class="header" v-if="bookList.length">
  5. <view class="left">
  6. <u-checkbox v-if="isEditMode" class="checkbox-item" v-model="isAllSelected" @change="toggleSelectAll"
  7. shape="circle" active-color="#38C148"></u-checkbox>
  8. <text v-if="isEditMode" class="select-text">全选</text>
  9. </view>
  10. <view class="right">
  11. <text v-if="!isEditMode" @tap="toggleEditMode">管理</text>
  12. <text v-else @tap="handleDelete">移除待售藏书</text>
  13. </view>
  14. </view>
  15. <!-- 书籍列表 -->
  16. <page-scroll :page-size="12" @updateList="handleUpdateList" ref="pageRef" slotEmpty emptyText="您暂未扫过书籍">
  17. <u-checkbox-group v-model="checkedIds">
  18. <view class="book-list">
  19. <BookListItem v-for="book in bookList" :key="book.isbn" :book="book" :isEditMode="isEditMode" />
  20. </view>
  21. </u-checkbox-group>
  22. </page-scroll>
  23. <!-- 删除确认弹窗 -->
  24. <common-dialog ref="deleteDialog" title="温馨提示" @confirm="confirmDelete">
  25. <text>确定删除这本图书吗?</text>
  26. </common-dialog>
  27. </view>
  28. </template>
  29. <script>
  30. import BookListItem from '../components/BookListItem.vue'
  31. import commonDialog from '@/components/common-dialog.vue'
  32. import pageScroll from '@/components/pageScroll/index.vue'
  33. export default {
  34. components: {
  35. BookListItem,
  36. commonDialog,
  37. pageScroll
  38. },
  39. data() {
  40. return {
  41. isEditMode: false,
  42. bookList: [],
  43. checkedIds: [],
  44. isAllSelected: false
  45. }
  46. },
  47. mounted() {
  48. this.$refs.pageRef?.loadData(true)
  49. },
  50. methods: {
  51. handleUpdateList(data) {
  52. this.bookList = data.map(v => {
  53. v.selected = false
  54. return v
  55. })
  56. },
  57. // 切换编辑模式
  58. toggleEditMode() {
  59. this.isEditMode = !this.isEditMode
  60. if (!this.isEditMode) {
  61. this.bookList.forEach(book => book.selected = false)
  62. }
  63. },
  64. // 切换全选
  65. toggleSelectAll() {
  66. const newValue = !this.isAllSelected
  67. console.log(newValue, 'newValue')
  68. this.bookList.forEach(book => book.selected = newValue)
  69. },
  70. // 处理删除
  71. handleDelete() {
  72. let deleteIds = this.bookList.filter(book => book.selected)
  73. if (deleteIds.length === 0) {
  74. uni.showToast({
  75. title: '请选择要删除的记录',
  76. icon: 'none'
  77. })
  78. return
  79. }
  80. this.$refs.deleteDialog.openPopup()
  81. },
  82. // 确认删除
  83. confirmDelete() {
  84. let deleteIds = this.bookList.filter(book => book.selected).map(v => v.isbn)
  85. uni.$u.http.post('/token/order/removeScanLogs', deleteIds).then(res => {
  86. if (res.code === 200) {
  87. uni.showToast({
  88. title: '删除成功',
  89. icon: 'success'
  90. })
  91. this.$refs.pageRef?.loadData(true)
  92. }
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. .scan-history {
  100. min-height: 100vh;
  101. ::v-deep .checkbox-item {
  102. .u-checkbox__label {
  103. margin: 0 !important;
  104. }
  105. }
  106. .header {
  107. position: sticky;
  108. top: 0;
  109. left: 0;
  110. right: 0;
  111. z-index: 100;
  112. height: 88rpx;
  113. background: #FFFFFF;
  114. display: flex;
  115. justify-content: space-between;
  116. align-items: center;
  117. padding: 0 30rpx;
  118. font-size: 28rpx;
  119. border-bottom: 1rpx solid #EEEEEE;
  120. .left {
  121. display: flex;
  122. align-items: center;
  123. .select-text {
  124. margin-left: 12rpx;
  125. color: #333333;
  126. }
  127. }
  128. .right {
  129. text {
  130. color: #333333;
  131. &.delete-btn {
  132. color: #FF5B5B;
  133. }
  134. }
  135. }
  136. }
  137. .scroll-view {
  138. height: calc(100vh - 88rpx);
  139. }
  140. .book-list {
  141. padding: 20rpx;
  142. display: flex;
  143. flex-wrap: wrap;
  144. justify-content: flex-start;
  145. gap: 20rpx;
  146. .load-more {
  147. width: 100%;
  148. display: flex;
  149. color: #999999;
  150. font-size: 24rpx;
  151. padding: 30rpx 0;
  152. justify-content: center;
  153. }
  154. }
  155. }
  156. </style>