list.js 3.8 KB

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