index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 主体高度
  10. infoHeight: '',
  11. frameStyle: { useTop: true, name: '新增赛程编排', leftArrow: true, useBar: false },
  12. form: {
  13. },
  14. // 上传图片
  15. fileList: [],
  16. //比赛id
  17. id: '',
  18. //团队
  19. cateArray: [],
  20. cateIndex: 0,
  21. objectArray: [],
  22. cateIndex1: 0,
  23. objectArray1: [],
  24. index: 0,
  25. date: '2022-05-01',
  26. time: '08:00',
  27. red: {},
  28. blue: {},
  29. },
  30. //验证必填项
  31. initValidate() {
  32. const rules = { match_name: { required: true }, }
  33. // 验证字段的提示信息,若不传则调用默认的信息
  34. const messages = { match_name: { required: '请输入比赛名称' }, };
  35. this.WxValidate = new WxValidate(rules, messages)
  36. },
  37. back: function () {
  38. wx.navigateBack({ url: '/pages/me/index' })
  39. },
  40. //蓝方
  41. bindCatePickerChangeblue: function (e) {
  42. this.setData({ cateIndex: e.detail.value, blue: e.currentTarget.dataset.item, })
  43. },
  44. //红方
  45. bindCatePickerChangered: function (e) {
  46. this.setData({ cateIndex1: e.detail.value, red: e.currentTarget.dataset.item, })
  47. },
  48. //选择时间
  49. bindDateChange: function (e) {
  50. this.setData({date: e.detail.value})
  51. },
  52. bindTimeChange: function (e) {
  53. this.setData({time: e.detail.value})
  54. },
  55. //提交
  56. formSubmit: function (e) {
  57. const value = e.detail.value;
  58. value.match_id = this.data.id;
  59. value.red_id = this.data.red.team_id;
  60. value.red_name = this.data.red.team_name;
  61. value.red_logo = this.data.red.logo;
  62. value.red_members = this.data.red.members;
  63. value.blue_id = this.data.blue.team_id;
  64. value.blue_name = this.data.blue.team_name;
  65. value.blue_logo = this.data.blue.logo;
  66. value.blue_members = this.data.blue.members;
  67. value.match_time = this.data.date + ' ' + this.data.time;
  68. if (!this.WxValidate.checkForm(value)) {
  69. const error = this.WxValidate.errorList[0];
  70. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  71. return false
  72. } else {
  73. wx.request({
  74. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule`, 
  75. method: "post",
  76. data: value,
  77. header: {},
  78. success: res => {
  79. if (res.data.errcode == 0) {
  80. wx.showToast({
  81. title: '保存成功',
  82. icon: 'success',
  83. duration: 2000
  84. })
  85. } else {
  86. wx.showToast({
  87. title: '保存失败',
  88. icon: 'success',
  89. duration: 2000
  90. })
  91. }
  92. },
  93. })
  94. }
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. onLoad: function (options) {
  100. this.setData({ id: options.id })
  101. //验证规则函数
  102. this.initValidate();
  103. // 计算高度
  104. this.searchHeight();
  105. // 监听用户是否登录
  106. this.watchLogin();
  107. },
  108. // 监听用户是否登录
  109. watchLogin: function () {
  110. const that = this;
  111. let id = that.data.id;
  112. wx.getStorage({
  113. key: 'token',
  114. success: res => {
  115. wx.request({
  116. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`,
  117. method: 'get',
  118. data: {},
  119. success(res) {
  120. that.setData({ form: res.data.data })
  121. }
  122. })
  123. wx.request({
  124. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`,
  125. method: 'get',
  126. data: { match_id: id, status: 1 },
  127. success(res) {
  128. that.setData({ cateArray: res.data.data })
  129. }
  130. })
  131. },
  132. fail: res => {
  133. return wx.redirectTo({ url: '/pages/login/index', })
  134. }
  135. })
  136. },
  137. // 计算高度
  138. searchHeight: function () {
  139. let frameStyle = this.data.frameStyle;
  140. let client = app.globalData.client;
  141. let infoHeight = client.windowHeight;
  142. // 是否去掉状态栏
  143. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  144. // 是否减去底部菜单
  145. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  146. if (infoHeight) this.setData({ infoHeight: infoHeight })
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. },
  158. /**
  159. * 生命周期函数--监听页面隐藏
  160. */
  161. onHide: function () {
  162. },
  163. /**
  164. * 生命周期函数--监听页面卸载
  165. */
  166. onUnload: function () {
  167. },
  168. /**
  169. * 页面相关事件处理函数--监听用户下拉动作
  170. */
  171. onPullDownRefresh: function () {
  172. },
  173. /**
  174. * 页面上拉触底事件的处理函数
  175. */
  176. onReachBottom: function () {
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage: function () {
  182. }
  183. })