index.js 3.5 KB

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