// pages/login/login.js import WxValidate from '../../utils/wxValidate' const app = getApp() Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false }, // 主体高度 infoHeight: '', // 数据id id: '', //详情数据 info: {}, // 现场图片 match_file: [], showModal: false, //修改比分 form: [], //判断用户类别 type: '', //用户信息 userdata: {}, //团队id blue_id: '', red_id: '', }, //验证是否输入 initValidate() { const rules = { blue_branch: { required: true }, red_branch: { required: true, }, blue_integral: { required: true }, red_integral: { required: true, } } // 验证字段的提示信息,若不传则调用默认的信息 const messages = { blue_branch: { required: '请输入蓝方比分', }, red_branch: { required: '请输入红方比分', }, blue_integral: { required: '请输入蓝方积分', }, red_integral: { required: '请输入红方积分', } }; this.WxValidate = new WxValidate(rules, messages) }, back: function () { wx.navigateBack({ url: '/pages/home/index' }) }, //显示对话框 clickme: function () { this.setData({ showModal: true }) }, //关闭弹窗 go: function () { this.setData({ showModal: false }) }, //上传图片 imgUpload: async function (e) { const that = this; if (that.data.type == '0') { return wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', }) } else if (that.data.type == '1') { let red_id = that.data.red_id let blue_id = that.data.blue_id let user_id = that.data.userdata.id let create_id_one = '' let create_id_two = '' const res = await app.$get('/courtAdmin/api/team', { id: red_id }); if (res.errcode === 0) create_id_one = res.data[0].create_id; const arr = await app.$get('/courtAdmin/api/team', { id: blue_id }); if (arr.errcode === 0) create_id_two = arr.data[0].create_id; if (create_id_one == user_id || create_id_two == user_id) { let data = that.data.match_file; let id = that.data.id; data.push(e.detail) wx.request({ url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址 method: 'post', data: { match_file: data }, success(res) { if (res.data.errcode == 0) { wx.showToast({ title: '添加成功', duration: 2000, icon: 'success', }) that.setData({ match_file: data }) } else { wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 }) } } }) } else { return wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', }) } } else if (that.data.type == '2') { let userid = that.data.userdata.id let red_members = that.data.info.red_members; let blue_members = that.data.info.blue_members; var item = red_members.find(item => item.id == userid) var items = blue_members.find(item => item.id == userid) if (item || items) { let data = that.data.match_file; let id = that.data.id; data.push(e.detail) wx.request({ url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址 method: 'post', data: { match_file: data }, success(res) { if (res.data.errcode == 0) { wx.showToast({ title: '添加成功', duration: 2000, icon: 'success', }) that.setData({ match_file: data }) } else { wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 }) } } }) } else { return wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', }) } } }, //删除图片 imgDel: async function (e) { const that = this; if (that.data.type == '0') { return wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', }) } else if (that.data.type == '1') { let red_id = that.data.red_id let blue_id = that.data.blue_id let user_id = that.data.userdata.id let create_id_one = '' let create_id_two = '' const res = await app.$get('/courtAdmin/api/team', { id: red_id }); if (res.errcode === 0) create_id_one = res.data[0].create_id; const arr = await app.$get('/courtAdmin/api/team', { id: blue_id }); if (arr.errcode === 0) create_id_two = arr.data[0].create_id; if (create_id_one == user_id || create_id_two == user_id) { let data = that.data.match_file; let id = that.data.id; let arr = data.filter((i, index) => index != e.detail.index) wx.request({ url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址 method: 'post', data: { match_file: arr }, success(res) { if (res.data.errcode == 0) { wx.showToast({ title: '删除成功', duration: 2000, icon: 'success', }) that.setData({ match_file: arr }) } else { wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 }) } } }) } else { return wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', }) } } else if (that.data.type == '2') { let userid = that.data.userdata.id let red_members = that.data.info.red_members; let blue_members = that.data.info.blue_members; var item = red_members.find(item => item.id == userid) var items = blue_members.find(item => item.id == userid) if (item || items) { let data = that.data.match_file; let id = that.data.id; let arr = data.filter((i, index) => index != e.detail.index) wx.request({ url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址 method: 'post', data: { match_file: arr }, success(res) { if (res.data.errcode == 0) { wx.showToast({ title: '删除成功', duration: 2000, icon: 'success', }) that.setData({ match_file: arr }) } else { wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 }) } } }) } else { return wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', }) } } }, // 提交登录 formSubmit: function (e) { const that = this; let id = that.data.id; const params = e.detail.value; params.match_file = that.data.match_file; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 }) return false } else { wx.request({ url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址 method: 'post', data: params, success(res) { if (res.data.errcode == 0) { wx.showToast({ title: '保存成功', duration: 2000, icon: 'success', success: (res) => { that.back() } }) } else { wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 }) } } }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const that = this; that.setData({ id: options.id }) //验证规则函数 this.initValidate(); // 计算高度 this.searchHeight(); // 监听用户是否登录 this.watchLogin(); }, // 监听用户是否登录 watchLogin: async function () { const that = this; let id = that.data.id; wx.getStorage({ key: 'token', success: async res => { that.setData({ type: res.data.type, userdata: res.data }) const arr = await app.$get(`/courtAdmin/api/schedule/${id}`); if (arr.errcode === 0) { that.setData({ info: arr.data, blue_id: arr.data.blue_id, red_id: arr.data.red_id }) that.setData({ match_file: arr.data.match_file }) } }, fail: res => { return wx.redirectTo({ url: '/pages/login/index', }) } }) }, // 计算高度 searchHeight: function () { let frameStyle = this.data.frameStyle; let client = app.globalData.client; // 减去状态栏 let infoHeight = client.windowHeight - (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 () { } })