sign.js 7.4 KB

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