address.js 3.6 KB

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