raceautoAdd.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const app = getApp()
  2. import WxValidate from '../../utils/wxValidate'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '组项信息', leftArrow: true, useBar: false },
  9. form: {},
  10. // 赛事信息
  11. matchList: [],
  12. // 组别
  13. groupingList: [],
  14. //组内项目
  15. projectList: [],
  16. // 组内人员
  17. personList: []
  18. },
  19. initValidate() {
  20. const rules = { match_id: { required: true }, grouping_id: { required: true }, project_id: { required: true }, team_number: { required: true } }
  21. // 验证字段的提示信息,若不传则调用默认的信息
  22. const messages = { match_id: { required: '请选择赛事名称', }, grouping_id: { required: '请选择赛事组别', }, project_id: { required: '请选择组内项目', }, team_number: { required: '请输入分组数' } };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. back(e) { wx.navigateBack({ delta: 1 }) },
  26. // 选择赛事
  27. matchChange: function (e) {
  28. const that = this;
  29. let data = that.data.matchList[e.detail.value];
  30. if (data) {
  31. that.setData({ 'form.match_id': data._id });
  32. that.setData({ 'form.match_name': data.name });
  33. if (data.grouping && data.grouping.length > 0) {
  34. that.setData({ groupingList: data.grouping })
  35. }
  36. }
  37. },
  38. // 选择赛事组别
  39. grpupChange: async function (e) {
  40. const that = this;
  41. let data = that.data.groupingList[e.detail.value];
  42. if (data) {
  43. that.setData({ 'form.grouping_id': data._id });
  44. that.setData({ 'form.grouping_name': data.name });
  45. if (data.project && data.project.length > 0) {
  46. let projectList = [];
  47. for (const val of data.project) {
  48. const arr = await app.$get(`/newCourt/api/matchProject/${val}`)
  49. if (arr.errcode == '') projectList.push(arr.data);
  50. that.setData({ projectList: projectList })
  51. }
  52. }
  53. }
  54. },
  55. // 选择组内项目
  56. projectChange: function (e) {
  57. const that = this;
  58. let data = that.data.projectList[e.detail.value];
  59. if (data) {
  60. that.setData({ 'form.project_id': data._id });
  61. that.setData({ 'form.project_name': data.name });
  62. }
  63. },
  64. // 提交保存
  65. onSubmit: async function (e) {
  66. const that = this;
  67. const params = e.detail.value;
  68. if (!this.WxValidate.checkForm(params)) {
  69. const error = this.WxValidate.errorList[0];
  70. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  71. return false
  72. } else {
  73. console.log(params);
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad: function (options) {
  80. const that = this;
  81. that.setData({ id: options.id || '' });
  82. //验证规则函数
  83. that.initValidate();
  84. that.watchLogin()
  85. },
  86. // 监听用户是否登录
  87. watchLogin: async function () {
  88. const that = this;
  89. wx.getStorage({
  90. key: 'user',
  91. success: async res => {
  92. const arr = await app.$get(`/newCourt/api/match`, { status: '0' });//2
  93. if (arr.errcode == '0') {
  94. that.setData({ matchList: arr.data });
  95. }
  96. },
  97. fail: res => {
  98. wx.redirectTo({ url: '/pages/index/index', })
  99. }
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload: function () {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh: function () {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage: function () {
  136. }
  137. })