address.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/dictionary/addressAdd' })
  23. },
  24. // 修改
  25. toEdit: function (e) {
  26. const that = this;
  27. let { id } = e.currentTarget.dataset;
  28. wx.navigateTo({ url: `/pages/dictionary/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. watchLogin: function () {
  57. const that = this;
  58. let searchInfo = that.data.searchInfo;
  59. wx.getStorage({
  60. key: 'user',
  61. success: async (res) => {
  62. let info = { skip: 0, limit: 1000 };
  63. if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  64. const user = await app.$get(`/newCourt/api/user`);
  65. if (user.errcode == '0') {
  66. const arr = await app.$get(`/newCourt/api/ground`, { ...info });
  67. if (arr.errcode == '0') {
  68. for (const val of arr.data) {
  69. let userInfo = user.data.find((i) => i.openid == val.referee_id);
  70. if (userInfo) { val.referee_name = userInfo.name; }
  71. }
  72. that.setData({ list: arr.data })
  73. }
  74. } else {
  75. wx.showToast({ title: `${res.errmsg}`, icon: 'fail', duration: 2000 });
  76. }
  77. },
  78. fail: async (res) => {
  79. wx.redirectTo({ url: '/pages/index/index' });
  80. },
  81. });
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow: function () {
  92. this.watchLogin();
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })