address.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '比赛场地管理', leftArrow: true, useBar: false },
  8. searchInfo: {},
  9. list: [],
  10. },
  11. // 跳转菜单
  12. back(e) {
  13. wx.navigateBack({ delta: 1 });
  14. },
  15. search: function (e) {
  16. const that = this;
  17. that.setData({ 'searchInfo.name': e.detail.value });
  18. that.watchLogin()
  19. },
  20. // 添加
  21. toAdd() {
  22. wx.navigateTo({ url: '/pages/match/addressAdd' })
  23. },
  24. // 修改
  25. toEdit: function (e) {
  26. const that = this;
  27. let { id } = e.currentTarget.dataset;
  28. wx.navigateTo({ url: `/pages/match/addressAdd?id=${id}` })
  29. },
  30. // 删除
  31. toDel: async function (e) {
  32. const that = this;
  33. const { id } = e.currentTarget.dataset;
  34. wx.showModal({
  35. title: '提示',
  36. content: '是否确认删除该条数据?',
  37. async success(res) {
  38. if (res.confirm) {
  39. const arr = await app.$delete(`/newCourt/api/ground/${id}`);
  40. if (arr.errcode == '0') {
  41. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  42. that.watchLogin()
  43. } else {
  44. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  45. }
  46. }
  47. }
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. const that = this;
  55. // 监听用户是否登录
  56. // that.watchLogin();
  57. },
  58. watchLogin: function () {
  59. const that = this;
  60. let searchInfo = that.data.searchInfo;
  61. wx.getStorage({
  62. key: 'user',
  63. success: async (res) => {
  64. let info = { skip: 0, limit: 1000 };
  65. if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  66. const arr = await app.$get(`/newCourt/api/ground`, { ...info });
  67. if (arr.errcode == '0') {
  68. for (const val of arr.data) {
  69. const aee = await app.$get(`/newCourt/api/user/${val.referee_id}`);
  70. if (aee.errcode == '0') val.referee_name = aee.data.name;
  71. }
  72. that.setData({ list: arr.data })
  73. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  74. },
  75. fail: async (res) => {
  76. wx.redirectTo({ url: '/pages/index/index' });
  77. },
  78. });
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: function () {
  89. this.watchLogin();
  90. },
  91. /**
  92. * 生命周期函数--监听页面隐藏
  93. */
  94. onHide: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面卸载
  98. */
  99. onUnload: function () {
  100. },
  101. /**
  102. * 页面相关事件处理函数--监听用户下拉动作
  103. */
  104. onPullDownRefresh: function () {
  105. },
  106. /**
  107. * 页面上拉触底事件的处理函数
  108. */
  109. onReachBottom: function () {
  110. },
  111. /**
  112. * 用户点击右上角分享
  113. */
  114. onShareAppMessage: function () {
  115. }
  116. })