edit.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. const app = getApp();
  2. import WxValidate from '../../../utils/wxValidate';
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '赛程信息', leftArrow: true, useBar: false },
  6. raceuser: {},
  7. id: '',
  8. form: {},
  9. // 赛事列表
  10. matchList: [],
  11. // 组别列表
  12. groupList: [],
  13. // 组内项目列表
  14. projectList: [],
  15. // 小组设置列表
  16. teamList: [],
  17. // 裁判
  18. refereeList: [],
  19. // 场地
  20. addressList: [],
  21. // 选手
  22. memberList: [],
  23. // 赛程状态
  24. statusList: []
  25. },
  26. initValidate() {
  27. const rules = { match_id: { required: true }, group_id: { required: true }, project_id: { required: true }, team_id: { required: true }, address_id: { required: false }, referee_id: { required: false }, match_time: { required: true }, player_type: { required: true }, player_one: { required: true }, player_two: { required: true } }
  28. // 验证字段的提示信息,若不传则调用默认的信息
  29. const messages = { match_id: { required: '比赛赛事' }, group_id: { required: '赛事分组' }, project_id: { required: '组内项目' }, team_id: { required: '小组名称' }, address_id: { required: '场地名称' }, referee_id: { required: '裁判名称' }, match_time: { required: '比赛时间' }, player_type: { required: '选手类型' }, player_one: { required: '选手一' }, player_two: { required: '选手二' } };
  30. this.WxValidate = new WxValidate(rules, messages)
  31. },
  32. // 返回
  33. back: function () { wx.navigateBack({ delta: 1 }) },
  34. // 赛事
  35. matchChange: async function (e) {
  36. const that = this;
  37. let data = that.data.matchList[e.detail.value];
  38. if (data) {
  39. that.setData({ 'form.match_id': data._id, 'form.match_id_name': data.name });
  40. const arr = await app.$get(`/matchGroup`, { match_id: data._id }, 'race');
  41. if (arr.errcode == '0') { that.setData({ groupList: arr.data }) }
  42. }
  43. },
  44. // 组别
  45. groupChange: async function (e) {
  46. const that = this;
  47. let data = that.data.groupList[e.detail.value];
  48. if (data) {
  49. that.setData({ 'form.group_id': data._id, 'form.group_id_name': data.name });
  50. const arr = await app.$get(`/matchProject`, { match_id: data.match_id, group_id: data._id }, 'race');
  51. if (arr.errcode == '0') { that.setData({ projectList: arr.data }) }
  52. }
  53. },
  54. // 项目
  55. projectChange: async function (e) {
  56. const that = this;
  57. let data = that.data.projectList[e.detail.value];
  58. if (data) {
  59. that.setData({ 'form.project_id': data._id, 'form.project_id_name': data.name });
  60. const arr = await app.$get(`/matchTeamGroup`, { match_id: data.match_id, group_id: data.group_id, project_id: data._id }, 'race');
  61. if (arr.errcode == '0') { that.setData({ teamList: arr.data }) }
  62. }
  63. },
  64. // 小组
  65. teamChange: async function (e) {
  66. const that = this;
  67. let data = that.data.teamList[e.detail.value];
  68. if (data) {
  69. that.setData({ 'form.team_id': data._id, 'form.team_id_name': data.name });
  70. const arr = await app.$get(`/matchTeamGroup/${data._id}`, {}, 'race');
  71. console.log(arr);
  72. if (arr.errcode == '0') {
  73. if (arr.data.person_type == 'Race.User') { that.setData({ 'form.player_type': 'Race.User', 'form.type_name': '单打' }) }
  74. if (arr.data.person_type == 'Race.TeamApply') { that.setData({ 'form.player_type': 'Race.TeamApply', 'form.type_name': '双打' }) }
  75. that.setData({ memberList: arr.data.person });
  76. }
  77. }
  78. },
  79. // 场地
  80. addressChange: async function (e) {
  81. const that = this;
  82. let data = that.data.addressList[e.detail.value];
  83. if (data) {
  84. that.setData({ 'form.address_id': data._id, 'form.address_id_name': data.name });
  85. }
  86. },
  87. // 裁判
  88. refereeChange: async function (e) {
  89. const that = this;
  90. let data = that.data.refereeList[e.detail.value];
  91. if (data) {
  92. that.setData({ 'form.referee_id': data._id, 'form.referee_id_name': data.name });
  93. }
  94. },
  95. // 确认选择
  96. datetimeChange: function (e) {
  97. const that = this;
  98. that.setData({ [`form.${e.detail.name}`]: e.detail.datetime });
  99. },
  100. // 选手一
  101. oneMemberChange: async function (e) {
  102. const that = this;
  103. let data = that.data.memberList[e.detail.value];
  104. if (data) {
  105. that.setData({ 'form.player_one': data.id, 'form.player_one_name': data.name });
  106. }
  107. },
  108. // 选手二
  109. twoMemberChange: async function (e) {
  110. const that = this;
  111. let data = that.data.memberList[e.detail.value];
  112. if (data) {
  113. that.setData({ 'form.player_two': data.id, 'form.player_two_name': data.name });
  114. }
  115. },
  116. // 选择状态
  117. statusChange: function (e) {
  118. const that = this;
  119. let data = that.data.statusList[e.detail.value];
  120. if (data) {
  121. that.setData({ 'form.status': data.value, 'form.zhStatus': data.label });
  122. }
  123. },
  124. // 提交保存
  125. onSubmit: async function (e) {
  126. const that = this;
  127. const params = e.detail.value;
  128. const form = that.data.form;
  129. params.match_time = form.match_time;
  130. if (!this.WxValidate.checkForm(params)) {
  131. const error = this.WxValidate.errorList[0];
  132. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  133. return false
  134. } else {
  135. let arr;
  136. if (that.data.id) { arr = await app.$post(`/msgs/${that.data.id}`, params, 'race'); }
  137. else { arr = await app.$post(`/msgs`, params, 'race'); }
  138. if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
  139. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  140. }
  141. },
  142. /**
  143. * 生命周期函数--监听页面加载
  144. */
  145. onLoad: async function (options) {
  146. const that = this;
  147. that.setData({ id: options && options.id || '' })
  148. //验证规则函数
  149. that.initValidate();
  150. // 监听用户是否登录
  151. await that.watchLogin();
  152. },
  153. // 查询其他信息
  154. searchOther: async function () {
  155. const that = this;
  156. const raceuser = that.data.raceuser;
  157. let arr;
  158. // 状态
  159. arr = await app.$get(`/dict`, { code: 'schedule_status' });
  160. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  161. // 比赛
  162. arr = await app.$get(`/match`, { belong_id: raceuser._id, status: '2' }, 'race');
  163. if (arr.errcode == '0') that.setData({ matchList: arr.data });
  164. // 场地
  165. arr = await app.$get(`/matchAddress`, { belong_id: raceuser._id, is_use: '0' }, 'race');
  166. if (arr.errcode == '0') that.setData({ addressList: arr.data });
  167. // 裁判
  168. arr = await app.$get(`/user`, { type: '2' }, 'race');
  169. if (arr.errcode == '0') {
  170. for (const val of arr.data) { val.name = val.user_id.name }
  171. that.setData({ refereeList: arr.data });
  172. }
  173. },
  174. // 监听用户是否登录
  175. watchLogin: async function () {
  176. const that = this;
  177. wx.getStorage({
  178. key: 'raceuser',
  179. success: async res => {
  180. that.setData({ raceuser: res.data });
  181. // 查询其他信息
  182. await that.searchOther();
  183. if (that.data.id) {
  184. const arr = await app.$get(`/msgs/${that.data.id}`, {}, 'race');
  185. if (arr.errcode == '0') {
  186. // 状态
  187. let status = that.data.statusList.find(i => i.value == arr.data.status)
  188. if (status) arr.data.zhStatus = status.label;
  189. if (arr.data.player_type == 'Race.User') { arr.data.type_name = '单打' }
  190. if (arr.data.player_type == 'Race.TeamApply') { arr.data.type_name = '双打' }
  191. that.setData({ form: arr.data })
  192. } else {
  193. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  194. }
  195. }
  196. },
  197. fail: async res => {
  198. wx.redirectTo({ url: '/pages/index/index' })
  199. }
  200. })
  201. },
  202. /**
  203. * 生命周期函数--监听页面初次渲染完成
  204. */
  205. onReady: function () { },
  206. /**
  207. * 生命周期函数--监听页面显示
  208. */
  209. onShow: function () { },
  210. /**
  211. * 页面上拉触底事件的处理函数
  212. */
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide: function () {
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload: function () {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. },
  228. /**
  229. * 用户点击右上角分享
  230. */
  231. onShareAppMessage: function () {
  232. }
  233. })