index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate';
  3. const moment = require("../../utils/moment.min");
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. frameStyle: { useTop: true, name: '解散团队', leftArrow: true, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. // 用户列表
  14. user: {},
  15. // 团队列表
  16. teamList: [],
  17. list: [],
  18. // 弹框
  19. dialog: { title: '添加申请', show: false, type: '1' },
  20. form: {}
  21. },
  22. initValidate() {
  23. const rules = { team_id: { required: true }, resaon: { required: true } }
  24. // 验证字段的提示信息,若不传则调用默认的信息
  25. const messages = { team_id: { required: '请选择团队', }, resaon: { required: '请输入解散原因', } };
  26. this.WxValidate = new WxValidate(rules, messages)
  27. },
  28. back: function () {
  29. wx.navigateBack({ url: '/pages/me/index' })
  30. },
  31. // 添加
  32. toAdd: function () {
  33. const that = this;
  34. const user = that.data.user;
  35. that.setData({ form: { create_id: user._id, create_user: user.nickname } })
  36. that.setData({ dialog: { title: '添加申请', show: true, type: '1' } })
  37. },
  38. // 选择团队
  39. teamChange: function (e) {
  40. const that = this;
  41. const { value } = e.detail;
  42. let data = that.data.teamList[value];
  43. if (data) that.setData({ 'form.team_id': data._id });
  44. that.setData({ 'form.team_name': data.name });
  45. },
  46. // 提交申请
  47. onSubmit: async function (e) {
  48. const that = this;
  49. const params = e.detail.value;
  50. if (!this.WxValidate.checkForm(params)) {
  51. const error = this.WxValidate.errorList[0];
  52. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  53. return false
  54. } else {
  55. params.apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
  56. const arr = await app.$post(`/courtAdmin/api/dismissapply`, params)
  57. if (arr.errcode == '0') { wx.showToast({ title: `成功,等待审核`, icon: 'success', duration: 2000 }); that.toClose(); that.watchLogin() }
  58. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  59. }
  60. },
  61. // 关闭弹框
  62. toClose: function () {
  63. const that = this;
  64. that.setData({ dialog: { title: '添加申请', show: false, type: '1' } })
  65. },
  66. /**
  67. * 生命周期函数--监听页面加载
  68. */
  69. onLoad: function (options) {
  70. //验证规则函数
  71. this.initValidate();
  72. // 计算高度
  73. this.searchHeight();
  74. // 监听用户是否登录
  75. this.watchLogin();
  76. },
  77. // 监听用户是否登录
  78. watchLogin: function () {
  79. const that = this;
  80. wx.getStorage({
  81. key: 'token',
  82. success: async res => {
  83. that.setData({ user: res.data });
  84. let arr;
  85. // 查询团队列表
  86. arr = await app.$get(`/courtAdmin/api/team`, { create_id: res.data._id });
  87. if (arr.errcode == '0') this.setData({ teamList: arr.data });
  88. // 查询申请列表
  89. arr = await app.$get(`/courtAdmin/api/dismissapply`, { create_id: res.data._id });
  90. if (arr.errcode == '0') this.setData({ list: arr.data });
  91. },
  92. fail: res => {
  93. 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. })