|
@@ -1,38 +1,220 @@
|
|
|
const app = getApp();
|
|
|
+import WxValidate from '../../../utils/wxValidate';
|
|
|
Page({
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '赛程信息', leftArrow: true, useBar: false },
|
|
|
+ raceuser: {},
|
|
|
+ id: '',
|
|
|
+ form: {},
|
|
|
+ // 赛事列表
|
|
|
+ matchList: [],
|
|
|
+ // 组别列表
|
|
|
+ groupList: [],
|
|
|
+ // 组内项目列表
|
|
|
+ projectList: [],
|
|
|
+ // 小组设置列表
|
|
|
+ teamList: [],
|
|
|
+ // 裁判
|
|
|
+ coachList: [],
|
|
|
+ // 场地
|
|
|
+ addressList: [],
|
|
|
+ // 选手
|
|
|
+ memberList: []
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { match_id: { required: true }, group_id: { required: true }, project_id: { required: true }, team_id: { required: true }, address_id: { required: true }, referee_id: { required: true }, match_time: { required: true }, player_type: { required: true }, player_one: { required: true }, player_two: { required: true } }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { match_id: { required: '比赛赛事' }, group_id: { required: '赛事分组' }, project_id: { required: '组内项目' }, team_id: { required: '小组名称' }, address_id: { required: '场地名称' }, referee_id: { required: '裁判名称' }, match_time: { required: '比赛时间' }, player_type: { required: '选手类型' }, player_one: { required: '选手一' }, player_two: { required: '选手二' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
},
|
|
|
// 返回
|
|
|
back: function () { wx.navigateBack({ delta: 1 }) },
|
|
|
+ // 赛事
|
|
|
+ matchChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.matchList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.match_id': data._id, 'form.match_name': data.name });
|
|
|
+ const arr = await app.$get(`/matchGroup`, { match_id: data._id }, 'race');
|
|
|
+ if (arr.errcode == '0') { that.setData({ groupList: arr.data }) }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 组别
|
|
|
+ groupChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.groupList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.group_id': data._id, 'form.group_name': data.name });
|
|
|
+ const arr = await app.$get(`/matchProject`, { match_id: data.match_id, group_id: data._id }, 'race');
|
|
|
+ if (arr.errcode == '0') { that.setData({ projectList: arr.data }) }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 项目
|
|
|
+ projectChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.projectList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.project_id': data._id, 'form.project_name': data.name });
|
|
|
+ const arr = await app.$get(`/matchTeamGroup`, { match_id: data.match_id, group_id: data.group_id, project_id: data._id }, 'race');
|
|
|
+ if (arr.errcode == '0') { that.setData({ teamList: arr.data }) }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 小组
|
|
|
+ teamChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.teamList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.team_id': data._id, 'form.team_name': data.name });
|
|
|
+ const arr = await app.$get(`/matchTeamGroup/${data._id}`, {}, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ if (arr.data.person_type == 'User') { that.setData({ 'form.player_type': '0', 'form.type_name': '单打' }) }
|
|
|
+ if (arr.data.person_type == 'TeamApply') { that.setData({ 'form.player_type': '1', 'form.type_name': '双打' }) }
|
|
|
+ for (const val of arr.data.person) {
|
|
|
+ let memberList = [];
|
|
|
+ val.map(function (item, index) {
|
|
|
+ var member = {}; member['name'] = item.user_name; member['id'] = item; memberList[index] = member
|
|
|
+ })
|
|
|
+ that.setData({ memberList });
|
|
|
+ console.log(that.data.memberList);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 场地
|
|
|
+ addressChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.addressList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.address_id': data._id, 'form.address_name': data.name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 裁判
|
|
|
+ coachChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.coachList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.coach_id': data._id, 'form.coach_name': data.name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 确认选择
|
|
|
+ datetimeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ [`form.${e.detail.name}`]: e.detail.datetime });
|
|
|
+ },
|
|
|
+ // 选手一
|
|
|
+ oneMemberChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.memberList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.player_one': data._id, 'form.member_one_name': data.name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选手一
|
|
|
+ twoMemberChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.memberList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.player_two': data._id, 'form.member_two_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 {
|
|
|
+ let arr;
|
|
|
+ if (that.data.id) { arr = await app.$post(`/msgs/${that.data.id}`, params, 'race'); }
|
|
|
+ else { arr = await app.$post(`/msgs`, params, 'race'); }
|
|
|
+ if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
|
|
|
+ else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
|
|
|
+ }
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad: function (options) { },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady: function () { },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow: function () {
|
|
|
+ onLoad: async function (options) {
|
|
|
const that = this;
|
|
|
+ that.setData({ id: options.id || '' })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ // 查询其他信息
|
|
|
+ await that.searchOther();
|
|
|
// 监听用户是否登录
|
|
|
- that.watchLogin();
|
|
|
+ await that.watchLogin();
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ searchOther: async function () {
|
|
|
+ const that = this;
|
|
|
+ const raceuser = that.data.raceuser;
|
|
|
+ let arr;
|
|
|
+ // 比赛
|
|
|
+ arr = await app.$get(`/match`, { belong_id: '630ec0480a92b0a015ccfbe1' }, 'race');
|
|
|
+ if (arr.errcode == '0') that.setData({ matchList: arr.data });
|
|
|
+ // 场地
|
|
|
+ arr = await app.$get(`/matchAddress`, { belong_id: '630ec0480a92b0a015ccfbe1' }, 'race');
|
|
|
+ if (arr.errcode == '0') that.setData({ addressList: arr.data });
|
|
|
+ // 裁判
|
|
|
+ arr = await app.$get(`/user`, { type: '2' }, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ for (const val of arr.data) { val.name = val.user_id.name }
|
|
|
+ that.setData({ coachList: arr.data });
|
|
|
+ }
|
|
|
},
|
|
|
// 监听用户是否登录
|
|
|
watchLogin: async function () {
|
|
|
const that = this;
|
|
|
wx.getStorage({
|
|
|
key: 'raceuser',
|
|
|
- success: async res => { },
|
|
|
+ success: async res => {
|
|
|
+ that.setData({ raceuser: res.data })
|
|
|
+ if (that.data.id) {
|
|
|
+ if (that.data.id) {
|
|
|
+ const arr = await app.$get(`/msgs/${that.data.id}`, {}, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ let aee;
|
|
|
+ // 比赛
|
|
|
+ aee = await app.$get(`/match/${arr.data.match_id}`, {}, 'race');
|
|
|
+ if (aee.errcode == '0') arr.data.match_name = aee.data.name;
|
|
|
+ // 组别
|
|
|
+ aee = await app.$get(`/matchGroup/${arr.data.group_id}`, {}, 'race');
|
|
|
+ if (aee.errcode == '0') arr.data.project_name = aee.data.name;
|
|
|
+ // 项目
|
|
|
+ aee = await app.$get(`/matchProject/${arr.data.project_id}`, {}, 'race');
|
|
|
+ if (aee.errcode == '0') arr.data.group_name = aee.data.name
|
|
|
+ // 小组赛设置
|
|
|
+ aee = await app.$get(`/matchTeamGroup/${arr.data.team_id}`, {}, 'race');
|
|
|
+ if (aee.errcode == '0') arr.data.team_name = aee.data.name
|
|
|
+ // 裁判
|
|
|
+ aee = await app.$get(`/user/${arr.data.referee_id}`, {}, 'race');
|
|
|
+ if (aee.errcode == '0') arr.data.referee_name = aee.data.name
|
|
|
+ // 场地
|
|
|
+ aee = await app.$get(`/matchAddress/${arr.data.address_id}`, {}, 'race');
|
|
|
+ if (aee.errcode == '0') arr.data.address_name = aee.data.name
|
|
|
+ that.setData({ info: arr.data })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
fail: async res => {
|
|
|
wx.redirectTo({ url: '/pages/index/index' })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () { },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () { },
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|