123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- // pages/login/login.js
- import WxValidate from '../../utils/wxValidate'
- import { notice_type } from '../../utils/dict';
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '维护公告信息', leftArrow: true, useBar: false },
- // 主体高度
- infoHeight: '',
- form: {},
- // 文件
- file: [],
- typeList: notice_type,
- //用户列表
- userList: [],
- // 接收人
- receive_user: [],
- // 弹框
- dialog: { title: '选择接收人', show: false, type: '1' }
- },
- initValidate() {
- const rules = { content: { required: true } }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = { nickname: { content: '请输入发送内容', } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- back: function () {
- wx.navigateBack({ url: '/pages/user/index' })
- },
- // 上传图片
- imgUpload: function (e) {
- const that = this;
- let data = that.data.file;
- data.push(e.detail)
- that.setData({ file: data })
- },
- // 删除图片
- imgDel: function (e) {
- const that = this;
- let list = that.data.file;
- let arr = list.filter((i, index) => index != e.detail.index)
- that.setData({ file: arr })
- },
- // 选择发送时间
- dateChange: function (e) {
- const that = this;
- const { value } = e.detail;
- that.setData({ 'form.send_time': value })
- },
- // 选择用户类别
- typeChange: function (e) {
- const that = this;
- let index = e.detail.value;
- let data = that.data.typeList[index];
- if (data) that.setData({ 'form.type': data.label });
- },
- // 选择接收人
- userAdd() {
- const that = this;
- that.setData({ dialog: { title: '选择接收人', show: true, type: '1' } })
- },
- // 选择接收人
- userChange: function (e) {
- const that = this;
- let data = e.detail.value;
- let user = that.data.userList;
- let receive_user = [];
- for (const val of data) {
- let arr = user.find((i) => i._id == val);
- if (arr) receive_user.push({ user_id: arr._id, name: arr.nickname, status: '0' })
- }
- that.setData({ receive_user: receive_user })
- },
- // 关闭弹框
- toClose() {
- const that = this;
- that.setData({ dialog: { title: '选择接收人', show: false, type: '1' } })
- },
- // 提交登录
- onSubmit: async function (e) {
- const that = this;
- const params = e.detail.value;
- const receive_user = that.data.receive_user;
- params.receive_user = receive_user;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- let arr;
- params.file = that.data.file;
- arr = await app.$post(`/courtAdmin/api/notice`, params);
- if (arr.errcode == '0') { wx.showToast({ title: `添加信息完成`, icon: 'success', duration: 2000 }); that.back(); }
- else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- //验证规则函数
- this.initValidate();
- // 计算高度
- this.searchHeight();
- // 监听用户是否登录
- this.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'token',
- success: async res => {
- that.setData({ 'form': { send_id: res.data.id, send_name: res.data.nickname, file: [] } });
- const arr = await app.$get(`/courtAdmin/api/user`, { status: '1' });
- if (arr.errcode == '0') {
- let p1 = arr.data.filter((i) => i.type != '0')
- that.setData({ userList: p1 })
- }
- },
- fail: res => {
- wx.redirectTo({ url: '/pages/index/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 () {
- }
- })
|