list.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '教练信息', leftArrow: true, useBar: false },
  5. list: [],
  6. total: 0,
  7. page: 0,
  8. skip: 0,
  9. limit: 5,
  10. // 性别
  11. genderList: [],
  12. //教练等级
  13. levelList: [],
  14. },
  15. // 返回
  16. back(e) {
  17. wx.navigateBack({ delta: 1 })
  18. },
  19. // 查看
  20. toView: async function (e) {
  21. const that = this;
  22. that.setData({ skip: 0, page: 0, list: [] })
  23. const { item } = e.currentTarget.dataset;
  24. wx.navigateTo({ url: `/pages/stuAdmin/coach/info?id=${item.coach_id}` })
  25. },
  26. // 分页
  27. toPage: function () {
  28. const that = this;
  29. let list = that.data.list;
  30. let limit = that.data.limit;
  31. if (that.data.total > list.length) {
  32. wx.showLoading({ title: '加载中', mask: true })
  33. let page = that.data.page + 1;
  34. that.setData({ page: page })
  35. let skip = page * limit;
  36. that.setData({ skip: skip })
  37. that.watchLogin();
  38. wx.hideLoading()
  39. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () { },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: async function () {
  54. const that = this;
  55. // 查询其他信息
  56. await that.searchOther();
  57. // 监听用户是否登录
  58. await that.watchLogin();
  59. },
  60. searchOther: async function () {
  61. const that = this;
  62. let arr;
  63. // 性别
  64. arr = await app.$get(`/dict`, { code: 'gender' });
  65. if (arr.errcode == '0' && arr.total > 0) that.setData({ genderList: arr.data[0].list });
  66. // 教练等级
  67. arr = await app.$get(`/dict`, { code: 'coach_grade' });
  68. if (arr.errcode == '0' && arr.total > 0) that.setData({ levelList: arr.data[0].list });
  69. },
  70. // 监听用户是否登录
  71. watchLogin: async function () {
  72. const that = this;
  73. let genderList = that.data.genderList;
  74. let levelList = that.data.levelList;
  75. wx.getStorage({
  76. key: 'user',
  77. success: async res => {
  78. let info = { skip: that.data.skip, limit: that.data.limit, student_id: res.data.info.id };
  79. let arr = await app.$get(`/rsc`, { ...info });
  80. if (arr.errcode == '0') {
  81. for (const val of arr.data) {
  82. let level = levelList.find(i => i.value == val.coach_id_level); if (level) val.zhLevel = level.label;
  83. let gender = genderList.find(i => i.value == val.coach_id_gender); if (gender) val.zhGender = level.label;
  84. }
  85. that.setData({ list: [...that.data.list, ...arr.data] })
  86. that.setData({ total: arr.total })
  87. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  88. },
  89. fail: async res => {
  90. wx.redirectTo({ url: '/pages/index/index' })
  91. }
  92. })
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. /**
  98. * 生命周期函数--监听页面隐藏
  99. */
  100. onHide: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面卸载
  104. */
  105. onUnload: function () {
  106. },
  107. /**
  108. * 页面相关事件处理函数--监听用户下拉动作
  109. */
  110. onPullDownRefresh: function () {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. }
  117. })