index.js 5.9 KB

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