list.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. typeList: []
  14. },
  15. // 返回
  16. back: function () { wx.navigateBack({ delta: 1 }) },
  17. //添加信息,信息维护
  18. toCommon: function (e) {
  19. const that = this;
  20. const { item, route } = e.currentTarget.dataset;
  21. that.setData({ skip: 0, page: 0, list: [] });
  22. wx.navigateTo({ url: `/pagesMatch/${route}?id=${item && item._id ? item._id : ''}` })
  23. },
  24. // 删除
  25. toDel: function (e) {
  26. const that = this;
  27. const { item } = e.currentTarget.dataset;
  28. wx.showModal({
  29. title: '提示',
  30. content: '是否确认删除该条数据?',
  31. async success(res) {
  32. if (res.confirm) {
  33. const arr = await app.$delete(`/matchProject/${item._id}`);
  34. if (arr.errcode == '0') {
  35. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  36. that.watchLogin()
  37. } else {
  38. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  39. }
  40. }
  41. }
  42. })
  43. },
  44. // 分页
  45. toPage: function () {
  46. const that = this;
  47. let list = that.data.list;
  48. let limit = that.data.limit;
  49. if (that.data.total > list.length) {
  50. wx.showLoading({ title: '加载中', mask: true })
  51. let page = that.data.page + 1;
  52. that.setData({ page: page })
  53. let skip = page * limit;
  54. that.setData({ skip: skip })
  55. that.watchLogin();
  56. wx.hideLoading()
  57. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) { },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () { },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. const that = this;
  72. // 查询其他信息
  73. that.searchOther();
  74. // 监听用户是否登录
  75. that.watchLogin();
  76. },
  77. searchOther: async function () {
  78. const that = this;
  79. let arr;
  80. // 性别
  81. arr = await app.$get(`/dict`, { code: 'gender' });
  82. if (arr.errcode == '0' && arr.total > 0) that.setData({ genderList: arr.data[0].list });
  83. // 项目类别
  84. arr = await app.$get(`/dict`, { code: 'match_project_type' });
  85. if (arr.errcode == '0' && arr.total > 0) that.setData({ typeList: arr.data[0].list });
  86. },
  87. // 监听用户是否登录
  88. watchLogin: async function () {
  89. const that = this;
  90. let genderList = that.data.genderList;
  91. let typeList = that.data.typeList;
  92. wx.getStorage({
  93. key: 'user',
  94. success: async res => {
  95. let info = { skip: that.data.skip, limit: that.data.limit };
  96. let arr = await app.$get(`/matchProject`, { ...info });
  97. if (arr.errcode == '0') {
  98. for (const val of arr.data) {
  99. let type = typeList.find(i => i.value == val.type); if (type) val.zhType = type.label;
  100. let gender = genderList.find(i => i.value == val.gender); if (gender) val.zhGender = gender.label;
  101. }
  102. that.setData({ list: [...that.data.list, ...arr.data] })
  103. that.setData({ total: arr.total })
  104. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  105. },
  106. fail: async res => {
  107. wx.redirectTo({ url: '/pages/index/index' })
  108. }
  109. })
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. /**
  115. * 生命周期函数--监听页面隐藏
  116. */
  117. onHide: function () {
  118. const that = this;
  119. that.setData({ skip: 0, page: 0, list: [] })
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload: function () {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh: function () {
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. }
  136. })