index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. id: '',
  16. cateArray: [
  17. { id: '0', type: '待开始' }, { id: '1', type: '开始' }, { id: '2', type: '结束' }],
  18. cateIndex: 0,
  19. },
  20. //当用户点击确定时,执行的事件
  21. bindCatePickerChange: function (e) {
  22. var cid = this.data.cateArray[e.detail.value].id;
  23. type = cid
  24. //下面重新赋值必须有,页面显示的信息才会改为刚刚选中的值
  25. this.setData({
  26. cateIndex: e.detail.value,
  27. })
  28. },
  29. back: function () {
  30. wx.navigateBack({ url: '/pages/me/index' })
  31. },
  32. //提交
  33. formSubmit: function (e) {
  34. const that = this;
  35. let id = that.data.id;
  36. let status = that.data.cateIndex
  37. wx.request({
  38. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  39. method: "post",
  40. data: { status: status },
  41. header: {},
  42. success: res => {
  43. if (res.data.errcode == 0) {
  44. wx.showToast({
  45. title: '修改成功',
  46. icon: 'success',
  47. duration: 2000//延迟两秒
  48. })
  49. } else {
  50. wx.showToast({
  51. title: '修改失败',
  52. icon: 'success',
  53. duration: 2000
  54. })
  55. }
  56. },
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. this.setData({ id: options.id })
  64. //选择器
  65. var cindex = this.data.cateIndex
  66. type = this.data.cateArray[cindex].id
  67. // 计算高度
  68. this.searchHeight();
  69. // 监听用户是否登录
  70. this.watchLogin();
  71. },
  72. // 监听用户是否登录
  73. watchLogin: function () {
  74. const that = this;
  75. let id = that.data.id;
  76. wx.getStorage({
  77. key: 'token',
  78. success: res => {
  79. wx.request({
  80. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  81. method: 'get',
  82. data: {},
  83. success(res) {
  84. let status = res.data.data.status
  85. that.setData({
  86. form: res.data.data,
  87. cateIndex: status,
  88. })
  89. }
  90. })
  91. },
  92. fail: res => {
  93. return wx.redirectTo({ url: '/pages/login/index', })
  94. }
  95. })
  96. },
  97. // 计算高度
  98. searchHeight: function () {
  99. let frameStyle = this.data.frameStyle;
  100. let client = app.globalData.client;
  101. let infoHeight = client.windowHeight;
  102. // 是否去掉状态栏
  103. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  104. // 是否减去底部菜单
  105. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  106. if (infoHeight) this.setData({ infoHeight: infoHeight })
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload: function () {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh: function () {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function () {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage: function () {
  142. }
  143. })