sign.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. const app = getApp()
  2. import { examine_status } from '../../utils/dict';
  3. import WxValidate from '../../utils/wxValidate';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '报名管理', leftArrow: true, useBar: false },
  10. //查询条件
  11. searchName: '',
  12. list: [],
  13. dialog: { title: '详细信息', show: false, type: '1' },
  14. info: {},
  15. statusList: examine_status,
  16. projectList: [],
  17. form: {}
  18. },
  19. initValidate() {
  20. const rules = { grouping_id: { required: true }, project_id: { required: true } }
  21. // 验证字段的提示信息,若不传则调用默认的信息
  22. const messages = { grouping_id: { required: '请选择赛事分组' }, project_id: { required: '请选择组内项目' } };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. // 跳转菜单
  26. back(e) {
  27. wx.navigateBack({ delta: 1 })
  28. },
  29. // 查询信息
  30. onSearch: function (e) {
  31. const that = this;
  32. that.setData({ searchName: e.detail });
  33. that.watchLogin();
  34. },
  35. // 查看
  36. toView: async function (e) {
  37. const that = this;
  38. const { id } = e.currentTarget.dataset;
  39. const arr = await app.$get(`/newCourt/api/enroll/${id}`);
  40. if (arr.errcode == '0') {
  41. const aee = await app.$get(`/newCourt/api/user/${arr.data.openid}`);
  42. if (aee.errcode == '0') arr.data.name = aee.data.name
  43. const ass = await app.$get(`/newCourt/api/match/${arr.data.match_id}`);
  44. if (ass.errcode == '0') arr.data.title = ass.data.name
  45. that.setData({ info: arr.data })
  46. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  47. }
  48. },
  49. // 审核
  50. toCheck: async function (e) {
  51. const that = this;
  52. let { id } = e.currentTarget.dataset;
  53. const arr = await app.$get(`/newCourt/api/enroll/${id}`);
  54. if (arr.errcode == '0') {
  55. const ass = await app.$get(`/newCourt/api/match/${arr.data.match_id}`);
  56. if (ass.errcode == '0') {
  57. that.setData({ info: ass.data })
  58. let data = { openid: ass.data.openid, match_id: ass.data._id, match_name: ass.data.name }
  59. that.setData({ form: data })
  60. }
  61. that.setData({ dialog: { title: '信息审核', show: true, type: '2' } })
  62. }
  63. },
  64. // 赛事分组
  65. groupingChange: async function (e) {
  66. const that = this;
  67. let data = that.data.info.grouping[e.detail.value];
  68. that.setData({ 'form.grouping_id': data._id });
  69. that.setData({ 'form.grouping_name': data.name });
  70. let project = [];
  71. for (const val of data.project) {
  72. const arr = await app.$get(`/newCourt/api/matchProject/${val}`);
  73. if (arr.errcode == '0') {
  74. project.push(arr.data)
  75. }
  76. }
  77. that.setData({ projectList: project });
  78. },
  79. // 选择组内项目
  80. projectChange: function (e) {
  81. const that = this;
  82. let data = that.data.projectList[e.detail.value];
  83. that.setData({ 'form.project_id': data._id });
  84. that.setData({ 'form.project_name': data.name });
  85. },
  86. onSubmit: async function (e) {
  87. const that = this;
  88. const params = e.detail.value;
  89. if (!this.WxValidate.checkForm(params)) {
  90. const error = this.WxValidate.errorList[0];
  91. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  92. return false
  93. } else {
  94. const arr = await app.$post(`/newCourt/api/enroll`, params);
  95. if (arr.errcode == '0') {
  96. wx.showToast({ title: `报名成功`, icon: 'success', duration: 2000 });
  97. that.setData({ dialog: { title: '信息审核', show: false, type: '2' } })
  98. that.watchLogin();
  99. } else {
  100. wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 });
  101. }
  102. }
  103. },
  104. // 关闭弹框
  105. toClose: function () {
  106. const that = this;
  107. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  108. },
  109. /**
  110. * 生命周期函数--监听页面加载
  111. */
  112. onLoad: function (options) {
  113. const that = this;
  114. //验证规则函数
  115. that.initValidate();
  116. that.watchLogin();
  117. },
  118. // 监听用户是否登录
  119. watchLogin: async function () {
  120. const that = this;
  121. wx.getStorage({
  122. key: 'user',
  123. success: async res => {
  124. const arr = await app.$get(`/newCourt/api/enroll/`);
  125. if (arr.errcode == '0') {
  126. for (const val of arr.data) {
  127. const aee = await app.$get(`/newCourt/api/user/${val.openid}`);
  128. if (aee.errcode == '0') val.name = aee.data.name
  129. aee = await app.$get(`/newCourt/api/match/${val.match_id}`);
  130. if (aee.errcode == '0') val.title = aee.data.name
  131. }
  132. if (that.data.searchName) {
  133. let list = arr.data.filter((i) => i.name == that.data.searchName);
  134. if (list) that.setData({ list: list })
  135. else that.setData({ list: [] })
  136. } else {
  137. that.setData({ list: arr.data })
  138. }
  139. }
  140. },
  141. fail: res => {
  142. wx.redirectTo({ url: '/pages/index/index', })
  143. }
  144. })
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面卸载
  163. */
  164. onUnload: function () {
  165. },
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh: function () {
  170. },
  171. /**
  172. * 页面上拉触底事件的处理函数
  173. */
  174. onReachBottom: function () {
  175. },
  176. /**
  177. * 用户点击右上角分享
  178. */
  179. onShareAppMessage: function () {
  180. }
  181. })