index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. frameStyle: { useTop: true, name: '比赛修改', leftArrow: true, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. ids: '',
  14. form: {},
  15. cateArray: [
  16. { id: '0', type: '未开始' }, { id: '1', type: '报名中' }, { id: '2', type: '待比赛' }, { id: '3', type: '进行中' }, { id: '4', type: '已结束' }],
  17. cateIndex: 0,
  18. },
  19. //当用户点击确定时,执行的事件
  20. bindCatePickerChange: function (e) {
  21. var cid = this.data.cateArray[e.detail.value].id;
  22. type = cid
  23. //下面重新赋值必须有,页面显示的信息才会改为刚刚选中的值
  24. this.setData({
  25. cateIndex: e.detail.value,
  26. })
  27. },
  28. //提交
  29. formSubmit: function (e) {
  30. const value = e.detail.value;
  31. var form = this.data.form
  32. var id = this.ids;
  33. var name = value.name;
  34. var match_time = value.match_time;
  35. var single_time = value.single_time;
  36. var address = value.address;
  37. var format = form.format;
  38. // var match_team = this.form.match_team;
  39. const params = {
  40. "id": id,
  41. "name": name,
  42. "match_time": match_time,
  43. "single_time": single_time,
  44. "address": address,
  45. "format": format,
  46. "match_team": [],
  47. "status": type
  48. };
  49. if (!this.WxValidate.checkForm(params)) {
  50. const error = this.WxValidate.errorList[0];
  51. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  52. return false
  53. } else {
  54. wx.getStorage({
  55. key: 'token',
  56. success: function (res) {
  57. wx.request({
  58. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  59. method: 'post',
  60. data: params,
  61. success(res) {
  62. console.log(res.data);
  63. if (res.data.errcode == 0) {
  64. wx.showToast({ title: `修改比赛成功`, icon: 'success', duration: 2000 }) //创建成功提示
  65. // wx.navigateTo({ url: '/pages/administration/index' })// 跳转页面
  66. } else {
  67. wx.showToast({
  68. title: res.data.errmsg,
  69. icon: 'none',
  70. duration: 2000
  71. })
  72. }
  73. }
  74. })
  75. }
  76. })
  77. }
  78. },
  79. back: function () {
  80. wx.navigateBack({ url: '/pages/home/index' })
  81. },
  82. /**
  83. * 生命周期函数--监听页面加载
  84. */
  85. onLoad: function (options) {
  86. this.ids = options.id;
  87. //选择器
  88. var cindex = this.data.cateIndex
  89. type = this.data.cateArray[cindex].id
  90. // 监听用户是否登录
  91. this.watchLogin();
  92. //验证规则函数
  93. this.initValidate()
  94. // 计算高度
  95. this.searchHeight()
  96. },
  97. //验证是否输入
  98. initValidate() {
  99. const rules = { name: { required: true }, match_time: { required: true, }, single_time: { required: true }, address: { required: true, }, format: { required: true } }
  100. // 验证字段的提示信息,若不传则调用默认的信息
  101. const messages = { name: { required: '请输入比赛名称', }, match_time: { required: '请输入时间', }, single_time: { required: '请输入单场时间', }, address: { required: '请输入地点', }, format: { required: '请选择赛制', } };
  102. this.WxValidate = new WxValidate(rules, messages)
  103. },
  104. // 监听用户是否登录
  105. watchLogin: function () {
  106. wx.getStorage({
  107. key: 'token',
  108. success: res => {
  109. var that = this;
  110. var id = that.ids;
  111. wx.request({
  112. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  113. method: 'get',
  114. // data: {},
  115. success(res) {
  116. console.log('res', res.data);
  117. if (res.data.errcode == 0) {
  118. let datas = res.data.data
  119. that.setData({
  120. form: datas,
  121. });
  122. } else {
  123. wx.showToast({
  124. title: res.data.errmsg,
  125. icon: 'none',
  126. duration: 2000
  127. })
  128. }
  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. // 减去状态栏
  142. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  143. // 是否减去底部菜单
  144. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  145. if (infoHeight) this.setData({ infoHeight: infoHeight })
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面显示
  154. */
  155. onShow: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload: function () {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh: function () {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom: function () {
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage: function () {
  181. }
  182. })