sign.js 7.9 KB

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