index.js 5.0 KB

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