index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. back(e) {
  12. wx.navigateBack({ delta: 1 })
  13. },
  14. // 查询
  15. search: function (e) {
  16. const that = this;
  17. that.setData({ 'searchInfo.name': e.detail.value });
  18. that.watchLogin()
  19. },
  20. // 添加
  21. toCommon: function (e) {
  22. const that = this;
  23. const { route } = e.currentTarget.dataset;
  24. wx.navigateTo({ url: `/pages/${route}` })
  25. },
  26. // 信息维护
  27. toEdit: function (e) {
  28. const { item } = e.currentTarget.dataset;
  29. wx.navigateTo({ url: `/pages/race/add?id=${item._id}` })
  30. },
  31. // 删除
  32. toDel: function (e) {
  33. const that = this;
  34. const { item } = 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/race/${item._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. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) {
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow: function () {
  65. const that = this;
  66. that.watchLogin()
  67. },
  68. watchLogin: function () {
  69. const that = this;
  70. const searchInfo = that.data.searchInfo;
  71. wx.getStorage({
  72. key: 'user',
  73. success: async (res) => {
  74. let arr;
  75. let info = { skip: 0, limit: 1000 };
  76. // if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  77. arr = await app.$get(`/newCourt/api/race`, { ...info });
  78. if (arr.errcode == '0') { that.setData({ raceList: arr.data }) }
  79. else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  80. },
  81. fail: async (res) => {
  82. wx.redirectTo({ url: '/pages/index/index' });
  83. },
  84. });
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. }
  111. })