matchgroup.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. id: '',
  10. info: {},
  11. projectList: [],
  12. dialog: { title: '赛事组别', show: false, type: '1' },
  13. form: { project: [] }
  14. },
  15. initValidate() {
  16. const rules = { name: { required: true }, age: { required: true }, gender: { required: true } }
  17. // 验证字段的提示信息,若不传则调用默认的信息
  18. const messages = { name: { required: '请输入名称' }, age: { required: '请输入年龄限制' }, gender: { required: '请输入性别限制' } };
  19. this.WxValidate = new WxValidate(rules, messages)
  20. },
  21. // 跳转菜单
  22. back(e) {
  23. wx.navigateBack({ delta: 1 })
  24. },
  25. // 添加
  26. toAdd: function () {
  27. const that = this;
  28. that.setData({ dialog: { title: '赛事组别', show: true, type: '1' } });
  29. },
  30. // 信息删除
  31. toDel: async function (e) {
  32. const that = this;
  33. const info = that.data.info;
  34. const { item } = e.currentTarget.dataset;
  35. wx.showModal({
  36. title: '提示',
  37. content: '您确定要删除该条数据吗?',
  38. async success(res) {
  39. if (res.confirm) {
  40. let grouping = info.grouping.filter((i) => i._id != item._id);
  41. const arr = await app.$post(`/newCourt/api/match/${info.id}`, { grouping: grouping })
  42. if (arr.errcode == '0') {
  43. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 });
  44. that.watchLogin()
  45. } else {
  46. wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 });
  47. }
  48. }
  49. }
  50. })
  51. },
  52. checkboxChange: function (e) {
  53. const that = this;
  54. that.setData({ 'form.project': e.detail.value });
  55. },
  56. // 提交
  57. onSubmit: async function (e) {
  58. const that = this;
  59. const params = e.detail.value;
  60. const info = that.data.info;
  61. if (!this.WxValidate.checkForm(params)) {
  62. const error = this.WxValidate.errorList[0];
  63. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  64. return false
  65. } else {
  66. let grouping = [...info.grouping, params];
  67. const arr = await app.$post(`/newCourt/api/match/${that.data.id}`, { grouping: grouping })
  68. if (arr.errcode == '0') {
  69. that.watchLogin();
  70. that.toClose();
  71. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  72. }
  73. },
  74. // 关闭弹框
  75. toClose: function () {
  76. const that = this;
  77. that.setData({ dialog: { title: '赛事组别', show: false, type: '1' } })
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. const that = this;
  84. that.setData({ id: options.id || '62e23cd3bb22e03d0b49d73b' });
  85. //验证规则函数
  86. that.initValidate();
  87. that.watchLogin()
  88. },
  89. watchLogin: function () {
  90. const that = this;
  91. wx.getStorage({
  92. key: 'user',
  93. success: async (res) => {
  94. if (that.data.id) {
  95. let arr;
  96. arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
  97. if (arr.errcode == '0') {
  98. that.setData({ info: arr.data })
  99. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  100. arr = await app.$get(`/newCourt/api/matchProject`);
  101. if (arr.errcode == '0') that.setData({ projectList: arr.data })
  102. }
  103. },
  104. fail: async (res) => {
  105. wx.redirectTo({ url: '/pages/index/index' });
  106. },
  107. });
  108. },
  109. /**
  110. * 生命周期函数--监听页面初次渲染完成
  111. */
  112. onReady: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面显示
  116. */
  117. onShow: function () {
  118. },
  119. /**
  120. * 生命周期函数--监听页面隐藏
  121. */
  122. onHide: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面卸载
  126. */
  127. onUnload: function () {
  128. },
  129. /**
  130. * 页面相关事件处理函数--监听用户下拉动作
  131. */
  132. onPullDownRefresh: function () {
  133. },
  134. /**
  135. * 页面上拉触底事件的处理函数
  136. */
  137. onReachBottom: function () {
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. }
  144. })