my-footprint.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="my-footprint">
  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" url="/token/shop/user/lookLogList" @updateList="handleUpdateList" ref="pageRef" slotEmpty emptyText="您暂无浏览记录">
  17. <view class="list-container">
  18. <view class="date-group" v-for="group in groupedList" :key="group.date">
  19. <view class="date-header">{{ group.date }}</view>
  20. <view class="book-list">
  21. <BookListItem v-for="book in group.books" :key="book.id" :book="book" :isEditMode="isEditMode"
  22. @click="handleBookClick" @checked="handleChecked" />
  23. </view>
  24. </view>
  25. </view>
  26. </page-scroll>
  27. <!-- 删除确认弹窗 -->
  28. <common-dialog ref="deleteDialog" title="温馨提示" @confirm="confirmDelete">
  29. <text>确定清除选中的浏览记录吗?</text>
  30. </common-dialog>
  31. </view>
  32. </template>
  33. <script>
  34. import BookListItem from '../components/book-list-item.vue'
  35. import commonDialog from '@/components/common-dialog.vue'
  36. import pageScroll from '@/components/pageScroll/index.vue'
  37. export default {
  38. components: {
  39. BookListItem,
  40. commonDialog,
  41. pageScroll
  42. },
  43. data() {
  44. return {
  45. isEditMode: false,
  46. bookList: [],
  47. isAllSelected: false
  48. }
  49. },
  50. computed: {
  51. groupedList() {
  52. const groups = {};
  53. this.bookList.forEach(book => {
  54. // "2026-04-19T15:16:42.827Z" -> "2026-04-19" 或者直接使用截取
  55. let date = '未知日期';
  56. if (book.createTime) {
  57. if (book.createTime.includes('T')) {
  58. date = book.createTime.split('T')[0];
  59. } else {
  60. date = book.createTime.split(' ')[0];
  61. }
  62. }
  63. if (!groups[date]) {
  64. groups[date] = [];
  65. }
  66. groups[date].push(book);
  67. });
  68. // 按日期倒序排列
  69. const sortedDates = Object.keys(groups).sort((a, b) => new Date(b) - new Date(a));
  70. return sortedDates.map(date => {
  71. return {
  72. date,
  73. books: groups[date]
  74. };
  75. });
  76. }
  77. },
  78. // #ifdef MP-ALIPAY
  79. onPullDownRefresh() {
  80. this.$refs.pageRef?.loadData(true)
  81. },
  82. // #endif
  83. onShow() {
  84. this.$refs.pageRef?.loadData(true)
  85. },
  86. methods: {
  87. handleChecked({ book, checked }) {
  88. this.$nextTick(() => {
  89. let item = this.bookList.find(item => item.id === book.id)
  90. let index = this.bookList.findIndex(item => item.id === book.id)
  91. if (item) {
  92. item.selected = checked
  93. this.$set(this.bookList, index, item)
  94. this.isAllSelected = this.bookList.every(item => item.selected)
  95. }
  96. })
  97. },
  98. handleBookClick(book) {
  99. uni.navigateTo({
  100. url: '/pages-sell/pages/detail?isbn=' + book.isbn
  101. });
  102. },
  103. handleUpdateList(data) {
  104. const oldSelectedIds = new Set(this.bookList.filter(v => v.selected).map(v => v.id));
  105. this.bookList = data.map(v => {
  106. return {
  107. ...v,
  108. selected: oldSelectedIds.has(v.id),
  109. // BookListItem 显示组件使用 price 作为售价,producePrice 作为原价
  110. // 足迹接口返回的是 sellPrice (售价) 和 price (原价)
  111. price: v.sellPrice,
  112. producePrice: v.price
  113. }
  114. })
  115. // 更新全选状态
  116. if (this.bookList.length > 0) {
  117. this.isAllSelected = this.bookList.every(item => item.selected);
  118. } else {
  119. this.isAllSelected = false;
  120. }
  121. },
  122. // 切换编辑模式
  123. toggleEditMode() {
  124. this.isEditMode = !this.isEditMode
  125. if (!this.isEditMode) {
  126. this.bookList.forEach(book => book.selected = false)
  127. } else {
  128. // 进入编辑模式不默认全选
  129. this.isAllSelected = false
  130. this.bookList.forEach(book => book.selected = false)
  131. }
  132. },
  133. // 切换全选
  134. toggleSelectAll() {
  135. const newValue = !this.isAllSelected
  136. this.bookList.forEach(book => book.selected = newValue)
  137. },
  138. // 处理删除
  139. handleDelete() {
  140. let deleteIds = this.bookList.filter(book => book.selected)
  141. if (deleteIds.length === 0) {
  142. uni.showToast({
  143. title: '请选择要清除的记录',
  144. icon: 'none'
  145. })
  146. return
  147. }
  148. this.$refs.deleteDialog.openPopup()
  149. },
  150. // 确认删除
  151. confirmDelete() {
  152. let deleteIds = this.bookList.filter(book => book.selected).map(v => v.id)
  153. this.$u.api.clearLookLogAjax(deleteIds).then(res => {
  154. if (res.code === 200) {
  155. uni.showToast({
  156. title: '清除成功',
  157. icon: 'success'
  158. })
  159. this.$refs.pageRef?.loadData(true)
  160. this.isEditMode = false;
  161. }
  162. })
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .my-footprint {
  169. min-height: 100vh;
  170. background: #F5F5F5;
  171. ::v-deep .checkbox-item {
  172. .u-checkbox__label {
  173. margin: 0 !important;
  174. }
  175. }
  176. .header {
  177. position: sticky;
  178. top: 0;
  179. left: 0;
  180. right: 0;
  181. z-index: 100;
  182. height: 88rpx;
  183. background: #FFFFFF;
  184. display: flex;
  185. justify-content: space-between;
  186. align-items: center;
  187. padding: 0 30rpx;
  188. font-size: 28rpx;
  189. border-bottom: 1rpx solid #EEEEEE;
  190. .left {
  191. display: flex;
  192. align-items: center;
  193. .select-text {
  194. margin-left: 12rpx;
  195. color: #333333;
  196. }
  197. }
  198. .right {
  199. text {
  200. color: #333333;
  201. &.delete-btn {
  202. color: #FF5B5B;
  203. }
  204. }
  205. }
  206. }
  207. .scroll-view {
  208. height: calc(100vh - 88rpx);
  209. }
  210. .list-container {
  211. padding: 20rpx;
  212. .date-group {
  213. margin-bottom: 30rpx;
  214. .date-header {
  215. font-size: 32rpx;
  216. color: #333333;
  217. font-weight: bold;
  218. margin-bottom: 20rpx;
  219. padding-left: 10rpx;
  220. }
  221. .book-list {
  222. display: flex;
  223. flex-wrap: wrap;
  224. justify-content: flex-start;
  225. gap: 20rpx;
  226. }
  227. }
  228. }
  229. }
  230. </style>