sign.js 7.3 KB

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