matchgroup.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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({ form: {} })
  78. that.setData({ dialog: { title: '赛事组别', show: false, type: '1' } })
  79. },
  80. /**
  81. * 生命周期函数--监听页面加载
  82. */
  83. onLoad: function (options) {
  84. const that = this;
  85. that.setData({ id: options.id || '62e23cd3bb22e03d0b49d73b' });
  86. //验证规则函数
  87. that.initValidate();
  88. that.watchLogin()
  89. },
  90. watchLogin: function () {
  91. const that = this;
  92. wx.getStorage({
  93. key: 'user',
  94. success: async (res) => {
  95. if (that.data.id) {
  96. let arr;
  97. arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
  98. if (arr.errcode == '0') {
  99. that.setData({ info: arr.data })
  100. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  101. arr = await app.$get(`/newCourt/api/matchProject`, { skip: 0, limit: 1000 });
  102. if (arr.errcode == '0') that.setData({ projectList: arr.data })
  103. }
  104. },
  105. fail: async (res) => {
  106. wx.redirectTo({ url: '/pages/index/index' });
  107. },
  108. });
  109. },
  110. /**
  111. * 生命周期函数--监听页面初次渲染完成
  112. */
  113. onReady: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面显示
  117. */
  118. onShow: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面隐藏
  122. */
  123. onHide: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面卸载
  127. */
  128. onUnload: function () {
  129. },
  130. /**
  131. * 页面相关事件处理函数--监听用户下拉动作
  132. */
  133. onPullDownRefresh: function () {
  134. },
  135. /**
  136. * 页面上拉触底事件的处理函数
  137. */
  138. onReachBottom: function () {
  139. },
  140. /**
  141. * 用户点击右上角分享
  142. */
  143. onShareAppMessage: function () {
  144. }
  145. })