index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. const app = getApp()
  2. import { race_status } from '../../utils/dict';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '小组赛管理', leftArrow: true, useBar: false },
  9. searchInfo: {},
  10. list: [],
  11. dialog: { title: '赛事管理', show: false, type: '1' },
  12. form: {},
  13. statusList: race_status,
  14. },
  15. back(e) {
  16. wx.navigateBack({ delta: 1 })
  17. },
  18. // 查询
  19. search: function (e) {
  20. const that = this;
  21. that.setData({ 'searchInfo.name': e.detail.value });
  22. that.watchLogin()
  23. },
  24. // 添加
  25. toCommon: function (e) {
  26. const that = this;
  27. const { route } = e.currentTarget.dataset;
  28. wx.navigateTo({ url: `/pages/${route}` })
  29. },
  30. // 赛事管理
  31. toScore: async function (e) {
  32. const that = this;
  33. const { item } = e.currentTarget.dataset;
  34. const arr = await app.$get(`/newCourt/api/race/${item._id}`);
  35. if (arr.errcode == '0') { that.setData({ form: arr.data }) }
  36. that.setData({ dialog: { title: '赛事管理', show: true, type: '1' } });
  37. },
  38. // 选择比赛状态
  39. statusChange: function (e) {
  40. const that = this;
  41. let data = that.data.statusList[e.detail.value];
  42. if (data) { that.setData({ 'form.status': data.value }) }
  43. },
  44. // 提交保存
  45. onSubmit: function (e) {
  46. console.log(e);
  47. },
  48. // 关闭弹框
  49. toClose: function () {
  50. const that = this;
  51. that.setData({ form: {} })
  52. that.setData({ dialog: { title: '赛事管理', show: false, type: '1' } })
  53. that.watchLogin();
  54. },
  55. // 信息维护
  56. toEdit: function (e) {
  57. const { item } = e.currentTarget.dataset;
  58. wx.navigateTo({ url: `/pages/race/add?id=${item._id}` })
  59. },
  60. // 删除
  61. toDel: function (e) {
  62. const that = this;
  63. const { item } = e.currentTarget.dataset;
  64. wx.showModal({
  65. title: '提示',
  66. content: '是否确认删除该条数据?',
  67. async success(res) {
  68. if (res.confirm) {
  69. const arr = await app.$delete(`/newCourt/api/race/${item._id}`);
  70. if (arr.errcode == '0') {
  71. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  72. that.watchLogin()
  73. } else {
  74. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  75. }
  76. }
  77. }
  78. })
  79. },
  80. /**
  81. * 生命周期函数--监听页面加载
  82. */
  83. onLoad: function (options) {
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. const that = this;
  95. that.watchLogin()
  96. },
  97. watchLogin: function () {
  98. const that = this;
  99. const searchInfo = that.data.searchInfo;
  100. wx.getStorage({
  101. key: 'user',
  102. success: async (res) => {
  103. let arr;
  104. let info = { skip: 0, limit: 5 };
  105. // if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  106. arr = await app.$get(`/newCourt/api/race`, { ...info });
  107. if (arr.errcode == '0') { that.setData({ raceList: arr.data }) }
  108. else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  109. },
  110. fail: async (res) => {
  111. wx.redirectTo({ url: '/pages/index/index' });
  112. },
  113. });
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })