list.js 3.6 KB

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