registrationRecords.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { enrollRecord } from '../../api/other';
  2. Page({
  3. data: {
  4. cardList: [],
  5. page: 1,
  6. pageSize: 2,
  7. loadingMore: false,
  8. noMore: false,
  9. refreshing: false
  10. },
  11. onLoad() {
  12. this.loadData(true);
  13. },
  14. // 请求数据
  15. async loadData(isRefresh = false) {
  16. if (this.data.loadingMore) return;
  17. let page = isRefresh ? 1 : this.data.page;
  18. this.setData({ loadingMore: true });
  19. try {
  20. const res = await enrollRecord({ page, pageSize: this.data.pageSize });
  21. const statusImgMap = {
  22. 0: '/static/image/register/wks.png',
  23. 1: '/static/image/register/yjs.png',
  24. 2: '/static/image/register/jxz.png'
  25. };
  26. const newList = res.data.list || [];
  27. let allList = isRefresh ? newList : [...this.data.cardList, ...newList];
  28. allList = allList.map(item => ({
  29. ...item,
  30. img: statusImgMap[item.status],
  31. genderText: item.gender == 0 ? '女' : '男'
  32. }));
  33. this.setData({
  34. cardList: allList,
  35. loadingMore: false,
  36. page: page + 1,
  37. noMore: allList.length >= res.data.total, // 有数据时判断是否加载完
  38. refreshing: false
  39. });
  40. } catch (err) {
  41. console.error(err);
  42. wx.showToast({ title: '加载失败', icon: 'none' });
  43. this.setData({
  44. loadingMore: false,
  45. refreshing: false
  46. });
  47. }
  48. },
  49. // 上拉触底
  50. onReachBottom() {
  51. if (this.data.noMore) return;
  52. this.loadData();
  53. },
  54. // 下拉刷新
  55. onPullDownRefresh() {
  56. if (this.data.refreshing) return;
  57. this.setData({ refreshing: true, noMore: false, page: 1 });
  58. this.loadData(true);
  59. }
  60. });