// pages/login/login.js import WxValidate from '../../utils/wxValidate'; const moment = require("../../utils/moment.min"); const app = getApp() Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '解散团队', leftArrow: true, useBar: false }, // 主体高度 infoHeight: '', // 用户列表 user: {}, // 团队列表 teamList: [], list: [], // 弹框 dialog: { title: '添加申请', show: false, type: '1' }, form: {} }, initValidate() { const rules = { team_id: { required: true }, resaon: { required: true } } // 验证字段的提示信息,若不传则调用默认的信息 const messages = { team_id: { required: '请选择团队', }, resaon: { required: '请输入解散原因', } }; this.WxValidate = new WxValidate(rules, messages) }, back: function () { wx.navigateBack({ url: '/pages/me/index' }) }, // 添加 toAdd: function () { const that = this; const user = that.data.user; that.setData({ form: { create_id: user._id, create_user: user.nickname } }) that.setData({ dialog: { title: '添加申请', show: true, type: '1' } }) }, // 选择团队 teamChange: function (e) { const that = this; const { value } = e.detail; let data = that.data.teamList[value]; if (data) that.setData({ 'form.team_id': data._id }); that.setData({ 'form.team_name': data.name }); }, // 提交申请 onSubmit: async function (e) { const that = this; const params = e.detail.value; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 }) return false } else { params.apply_time = moment().format('YYYY-MM-DD HH:mm:ss'); const arr = await app.$post(`/courtAdmin/api/dismissapply`, params) if (arr.errcode == '0') { wx.showToast({ title: `成功,等待审核`, icon: 'success', duration: 2000 }); that.toClose(); that.watchLogin() } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } }, // 关闭弹框 toClose: function () { const that = this; that.setData({ dialog: { title: '添加申请', show: false, type: '1' } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { //验证规则函数 this.initValidate(); // 计算高度 this.searchHeight(); // 监听用户是否登录 this.watchLogin(); }, // 监听用户是否登录 watchLogin: function () { const that = this; wx.getStorage({ key: 'token', success: async res => { that.setData({ user: res.data }); let arr; // 查询团队列表 arr = await app.$get(`/courtAdmin/api/team`, { create_id: res.data._id }); if (arr.errcode == '0') this.setData({ teamList: arr.data }); // 查询申请列表 arr = await app.$get(`/courtAdmin/api/dismissapply`, { create_id: res.data._id }); if (arr.errcode == '0') this.setData({ list: arr.data }); }, fail: res => { wx.redirectTo({ url: '/pages/login/index', }) } }) }, // 计算高度 searchHeight: function () { let frameStyle = this.data.frameStyle; let client = app.globalData.client; let infoHeight = client.windowHeight; // 是否去掉状态栏 if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2); // 是否减去底部菜单 if (frameStyle.useBar) infoHeight = infoHeight - 50; if (infoHeight) this.setData({ infoHeight: infoHeight }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })