123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- // 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 () {
- }
- })
|