|
@@ -10,16 +10,129 @@ Page({
|
|
|
frameStyle: { useTop: true, name: '维护赛程信息', leftArrow: true, useBar: false },
|
|
|
// 主体高度
|
|
|
infoHeight: '',
|
|
|
+ user: {},
|
|
|
+ form: {},
|
|
|
+ // 红方团队
|
|
|
+ redTeam: {},
|
|
|
+ // 蓝方团队
|
|
|
+ blueTeam: {},
|
|
|
+ id: '',
|
|
|
+ // 参赛团队成员列表
|
|
|
+ membersList: [],
|
|
|
+ // 弹框
|
|
|
+ dialog: { title: '成员列表', show: false, type: '1' },
|
|
|
+ teamType: ''
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { match_name: { required: true } }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { match_name: { required: '请输入比赛名称' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
},
|
|
|
back: function () {
|
|
|
- wx.navigateBack({ url: '/pages/matchadmin/layout' })
|
|
|
+ wx.navigateBack({ url: '/pages/matchteam/layout' })
|
|
|
+ },
|
|
|
+ // 添加成员
|
|
|
+ memAdd: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const { type } = e.currentTarget.dataset;
|
|
|
+ const data = that.data.form;
|
|
|
+ const red = that.data.redTeam;
|
|
|
+ const blue = that.data.blueTeam;
|
|
|
+ let arr;
|
|
|
+ arr = await app.$get(`/courtAdmin/api/matchteam`, { match_id: data.match_id, team_id: type == 'red' ? red._id : blue._id });
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.setData({ teamType: type });
|
|
|
+ that.setData({ membersList: arr.data[0].members });
|
|
|
+ that.setData({ dialog: { title: '成员列表', show: true, type: '1' } })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选择成员
|
|
|
+ onMemchange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = e.detail.value;
|
|
|
+ let user = that.data.membersList;
|
|
|
+ const type = that.data.teamType;
|
|
|
+ let members = [];
|
|
|
+ for (const val of data) {
|
|
|
+ let arr = user.find((i) => i.user_id == val);
|
|
|
+ if (arr) members.push(arr)
|
|
|
+ }
|
|
|
+ if (type == 'red') that.setData({ 'form.red_members': members })
|
|
|
+ else if (type == 'blue') that.setData({ 'form.blue_members': members })
|
|
|
+ },
|
|
|
+ // 删除成员
|
|
|
+ memDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ const { type, user_id } = e.currentTarget.dataset;
|
|
|
+ const data = that.data.form;
|
|
|
+ if (type == 'red') {
|
|
|
+ let red_members = data.red_members.filter((i) => i.user_id != user_id)
|
|
|
+ that.setData({ 'form.red_members': red_members })
|
|
|
+ } else if (type == 'blue') {
|
|
|
+ let blue_members = data.blue_members.filter((i) => i.user_id != user_id)
|
|
|
+ that.setData({ 'form.blue_members': blue_members })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ const data = that.data.form;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ params.red_members = data.red_members;
|
|
|
+ params.blue_members = data.blue_members;
|
|
|
+ const arr = await app.$post(`/courtAdmin/api/schedule/${data._id}`, params);
|
|
|
+ if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
|
|
|
+ else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 关闭弹框
|
|
|
+ toClose: function () {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ dialog: { title: '成员列表', show: false } })
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ id: options.id || '62a04833b3fcf97310b3e9c3' })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
// 计算高度
|
|
|
- this.searchHeight()
|
|
|
+ that.searchHeight();
|
|
|
+ // 监听用户是否登录
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ success: async res => {
|
|
|
+ that.setData({ user: res.data })
|
|
|
+ let arr;
|
|
|
+ let schedule;
|
|
|
+ // 查询赛程信息
|
|
|
+ arr = await app.$get(`/courtAdmin/api/schedule/${that.data.id}`);
|
|
|
+ if (arr.errcode == '0') { schedule = arr.data; that.setData({ form: schedule }); }
|
|
|
+ // 红方
|
|
|
+ arr = await app.$get(`/courtAdmin/api/team/${schedule.red_id}`);
|
|
|
+ if (arr.errcode == '0') that.setData({ redTeam: arr.data });
|
|
|
+ // 蓝方
|
|
|
+ arr = await app.$get(`/courtAdmin/api/team/${schedule.blue_id}`);
|
|
|
+ if (arr.errcode == '0') that.setData({ blueTeam: arr.data });
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
// 计算高度
|
|
|
searchHeight: function () {
|