scaned-book.vue 5.1 KB

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