add.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. const app = getApp()
  2. import WxValidate from '../../utils/wxValidate'
  3. const moment = require("../../utils/moment.min")
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '组队申请', leftArrow: true, useBar: false },
  10. searchInfo: {},
  11. form: {},
  12. teammateList: [],
  13. id: '',
  14. // 用户信息
  15. userinfo: {}
  16. },
  17. initValidate() {
  18. const rules = { teammate_id: { required: true }, teammate_name: { required: true } }
  19. // 验证字段的提示信息,若不传则调用默认的信息
  20. const messages = { teammate_id: { required: '请输入组队用户', }, teammate_name: { required: '请输入组队用户姓名', } };
  21. this.WxValidate = new WxValidate(rules, messages)
  22. },
  23. // 跳转菜单
  24. back(e) {
  25. wx.navigateBack({ delta: 1 })
  26. },
  27. // 查询
  28. toSearch: function (e) {
  29. const that = this;
  30. that.setData({ 'searchInfo.name': e.detail.value });
  31. that.watchLogin()
  32. },
  33. // 选择组队用户
  34. toChoose: function (e) {
  35. const that = this;
  36. const { item } = e.currentTarget.dataset;
  37. let form = { teammate_id: item.openid, teammate_name: item.name }
  38. wx.showModal({
  39. title: '提示',
  40. content: '是否确认选择该名队员?可先与对方电话联系!',
  41. success(res) {
  42. if (res.confirm) {
  43. that.onSubmit(form)
  44. } else if (res.cancel) {
  45. that.setData({ form: {} });
  46. }
  47. }
  48. });
  49. },
  50. // 提交登录
  51. onSubmit: async function (e) {
  52. const that = this;
  53. const params = e;
  54. const data = that.data.form;
  55. params.match_id = data.match_id;
  56. params.grouping_id = data.grouping_id;
  57. params.project_id = data.project_id;
  58. params.applyuser_id = that.data.userinfo.openid;
  59. params.applyuser_name = that.data.userinfo.name;
  60. params.apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
  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 arr;
  67. arr = await app.$post(`/newCourt/api/teamApply`, params);
  68. if (arr.errcode == '0') { wx.showToast({ title: `添加信息完成`, icon: 'success', duration: 2000 }); that.back(); }
  69. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  70. }
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {
  76. const that = this;
  77. if (options && options.id) that.setData({ id: options.id })
  78. //验证规则函数
  79. that.initValidate();
  80. // 监听用户是否登录
  81. that.watchLogin();
  82. },
  83. // 监听用户是否登录
  84. watchLogin: async function () {
  85. const that = this;
  86. let searchInfo = that.data.searchInfo;
  87. wx.getStorage({
  88. key: 'user',
  89. success: async res => {
  90. const arr = await app.$get(`/newCourt/api/enroll/${that.data.id}`);
  91. if (arr.errcode == '0') {
  92. that.setData({ form: arr.data });
  93. that.setData({ userinfo: res.data });
  94. }
  95. let info = {};
  96. if (searchInfo && searchInfo.name) {
  97. info.name = searchInfo.name;
  98. info.match_id = that.data.form.match_id;
  99. info.grouping_id = that.data.form.grouping_id;
  100. info.project_id = that.data.form.project_id;
  101. const team = await app.$get(`/newCourt/api/enroll/findTeammate`, { ...info });
  102. if (team.errcode == '0') {
  103. that.setData({ teammateList: team.data })
  104. } else {
  105. wx.showToast({ title: `${team.errMsg}`, icon: 'fail', duration: 2000 });
  106. }
  107. } else {
  108. let info = {};
  109. info.match_id = that.data.form.match_id;
  110. info.grouping_id = that.data.form.grouping_id;
  111. info.project_id = that.data.form.project_id;
  112. info.openid = that.data.userinfo.openid;
  113. const team = await app.$get(`/newCourt/api/enroll/findTeammate`, { ...info });
  114. if (team.errcode == '0') {
  115. for (const val of team.data) {
  116. val.card = val.card.substr(0, 4) + "*".repeat(val.card.length - 8) + val.card.substr(-4);
  117. }
  118. that.setData({ teammateList: team.data })
  119. }
  120. }
  121. },
  122. fail: res => {
  123. wx.redirectTo({ url: '/pages/index/index', })
  124. }
  125. })
  126. },
  127. /**
  128. * 生命周期函数--监听页面初次渲染完成
  129. */
  130. onReady: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面显示
  134. */
  135. onShow: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面隐藏
  139. */
  140. onHide: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面卸载
  144. */
  145. onUnload: function () {
  146. },
  147. /**
  148. * 页面相关事件处理函数--监听用户下拉动作
  149. */
  150. onPullDownRefresh: function () {
  151. },
  152. /**
  153. * 页面上拉触底事件的处理函数
  154. */
  155. onReachBottom: function () {
  156. },
  157. /**
  158. * 用户点击右上角分享
  159. */
  160. onShareAppMessage: function () {
  161. }
  162. })