scaned-book.vue 5.7 KB

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