index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. const moment = require("../../utils/moment.min")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. ids: '',
  11. apply_time: '',
  12. // 主体高度
  13. infoHeight: '',
  14. frameStyle: { useTop: true, name: '解散申请', leftArrow: true, useBar: false },
  15. form: {
  16. // team_id: '234', // 团队id
  17. // team_name: '我是第一队', // 团队名称
  18. // create_user: '李铁蛋', // 团队创建人
  19. // create_id: '23455', // 团队创建人id
  20. // apply_time: '', // 申请时间
  21. // resaon: '', // 解散团队原因
  22. },
  23. },
  24. // 监听用户是否登录
  25. watchLogin: function () {
  26. wx.getStorage({
  27. key: 'token',
  28. success: res => {
  29. var that = this;
  30. wx.request({
  31. url: `${app.globalData.publicUrl}/courtAdmin/api/team/` + that.data.ids, //接口地址
  32. method: 'get',
  33. data: '',
  34. success(res) {
  35. console.log('解散团队', res.data);
  36. if (res.data.errcode == 0) {
  37. let datas = res.data.data
  38. that.setData({
  39. form: datas,
  40. });
  41. } else {
  42. wx.showToast({
  43. title: res.data.errmsg,
  44. icon: 'none',
  45. duration: 2000
  46. })
  47. }
  48. }
  49. })
  50. },
  51. fail: res => {
  52. return wx.redirectTo({ url: '/pages/login/index', })
  53. }
  54. })
  55. },
  56. back: function () {
  57. wx.navigateBack({ url: '/pages/me/index' })
  58. },
  59. initValidate() {
  60. const rules = { team_id: { required: true }, team_name: { required: true, }, create_user: { required: true }, create_id: { required: true, }, resaon: { required: true, } }
  61. // 验证字段的提示信息,若不传则调用默认的信息
  62. const messages = { team_id: { required: '请输入团队id', }, team_name: { required: '请输入团队名称', }, create_user: { required: '请输入团队创建人', }, create_id: { required: '请输入团队创建人id', }, resaon: { required: '请输入解散团队原因', } };
  63. this.WxValidate = new WxValidate(rules, messages)
  64. },
  65. //提交
  66. formSubmit: function (e) {
  67. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  68. const params = e.detail.value;
  69. var apply_time = this.data.apply_time;
  70. var form = {
  71. "team_id": params.team_id,
  72. "team_name": params.team_name,
  73. "create_user": params.create_user,
  74. "create_id": params.create_id,
  75. "apply_time": apply_time,
  76. "resaon": params.resaon
  77. }
  78. if (!this.WxValidate.checkForm(params)) {
  79. const error = this.WxValidate.errorList[0];
  80. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  81. return false
  82. } else {
  83. wx.request({
  84. url: `${app.globalData.publicUrl}/courtAdmin/api/dismissapply`, //接口地址
  85. method: 'post',
  86. data: form,
  87. success(res) {
  88. if (res.data.errcode == 0) {
  89. wx.showToast({ title: `解散审核提交成功`, icon: 'success', duration: 2000 }) //登录成功提示
  90. wx.navigateTo({ url: '/pages/me/index' })// 跳转页面
  91. } else {
  92. wx.showToast({
  93. title: res.data.errmsg,
  94. icon: 'none',
  95. duration: 2000
  96. })
  97. }
  98. }
  99. })
  100. }
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. onLoad: function (options) {
  106. this.setData({
  107. ids: options.id,
  108. });
  109. let apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
  110. this.setData({
  111. apply_time: apply_time,
  112. });
  113. // 计算高度
  114. this.searchHeight();
  115. // 监听用户是否登录
  116. this.watchLogin();
  117. //验证规则函数
  118. this.initValidate()
  119. },
  120. // 计算高度
  121. searchHeight: function () {
  122. let frameStyle = this.data.frameStyle;
  123. let client = app.globalData.client;
  124. // 减去状态栏
  125. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  126. // 是否减去底部菜单
  127. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  128. if (infoHeight) this.setData({ infoHeight: infoHeight })
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })