scaned-book.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. }else{
  90. this.isAllSelected = true
  91. this.bookList.forEach(book => book.selected = true)
  92. }
  93. },
  94. // 切换全选
  95. toggleSelectAll() {
  96. const newValue = !this.isAllSelected
  97. this.bookList.forEach(book => book.selected = newValue)
  98. },
  99. // 处理删除
  100. handleDelete() {
  101. let deleteIds = this.bookList.filter(book => book.selected)
  102. if (deleteIds.length === 0) {
  103. uni.showToast({
  104. title: '请选择要删除的记录',
  105. icon: 'none'
  106. })
  107. return
  108. }
  109. this.$refs.deleteDialog.openPopup()
  110. },
  111. // 确认删除
  112. confirmDelete() {
  113. let deleteIds = this.bookList.filter(book => book.selected).map(v => v.isbn)
  114. uni.$u.http.post('/token/order/removeScanLogs', deleteIds).then(res => {
  115. if (res.code === 200) {
  116. uni.showToast({
  117. title: '删除成功',
  118. icon: 'success'
  119. })
  120. this.$refs.pageRef?.loadData(true)
  121. }
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .scan-history {
  129. min-height: 100vh;
  130. ::v-deep .checkbox-item {
  131. .u-checkbox__label {
  132. margin: 0 !important;
  133. }
  134. }
  135. .header {
  136. position: sticky;
  137. top: 0;
  138. left: 0;
  139. right: 0;
  140. z-index: 100;
  141. height: 88rpx;
  142. background: #FFFFFF;
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. padding: 0 30rpx;
  147. font-size: 28rpx;
  148. border-bottom: 1rpx solid #EEEEEE;
  149. .left {
  150. display: flex;
  151. align-items: center;
  152. .select-text {
  153. margin-left: 12rpx;
  154. color: #333333;
  155. }
  156. }
  157. .right {
  158. text {
  159. color: #333333;
  160. &.delete-btn {
  161. color: #FF5B5B;
  162. }
  163. }
  164. }
  165. }
  166. .scroll-view {
  167. height: calc(100vh - 88rpx);
  168. }
  169. .book-list {
  170. padding: 20rpx;
  171. display: flex;
  172. flex-wrap: wrap;
  173. justify-content: flex-start;
  174. gap: 20rpx;
  175. .load-more {
  176. width: 100%;
  177. display: flex;
  178. color: #999999;
  179. font-size: 24rpx;
  180. padding: 30rpx 0;
  181. justify-content: center;
  182. }
  183. }
  184. }
  185. </style>