|
@@ -0,0 +1,241 @@
|
|
|
+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: [],
|
|
|
+ // 裁判
|
|
|
+ refereeList: [],
|
|
|
+ // 场地
|
|
|
+ addressList: [],
|
|
|
+ // 选手
|
|
|
+ memberList: [],
|
|
|
+ // 赛程状态
|
|
|
+ statusList: []
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { match_id: { required: true }, group_id: { required: true }, project_id: { required: true }, team_id: { required: true }, address_id: { required: false }, referee_id: { required: false }, 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_id_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_id_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_id_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_id_name': data.name });
|
|
|
+ const arr = await app.$get(`/matchTeamGroup/${data._id}`, {}, 'race');
|
|
|
+ console.log(arr);
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ if (arr.data.person_type == 'Race.User') { that.setData({ 'form.player_type': 'Race.User', 'form.type_name': '单打' }) }
|
|
|
+ if (arr.data.person_type == 'Race.TeamApply') { that.setData({ 'form.player_type': 'Race.TeamApply', 'form.type_name': '双打' }) }
|
|
|
+ that.setData({ memberList: arr.data.person });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 场地
|
|
|
+ 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_id_name': data.name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 裁判
|
|
|
+ refereeChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.refereeList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.referee_id': data._id, 'form.referee_id_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.player_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.player_two_name': data.name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选择状态
|
|
|
+ statusChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.statusList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.status': data.value, 'form.zhStatus': data.label });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ const form = that.data.form;
|
|
|
+ params.match_time = form.match_time;
|
|
|
+ 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: async function (options) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ id: options && options.id || '' })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ // 监听用户是否登录
|
|
|
+ await that.watchLogin();
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ searchOther: async function () {
|
|
|
+ const that = this;
|
|
|
+ const raceuser = that.data.raceuser;
|
|
|
+ let arr;
|
|
|
+ // 状态
|
|
|
+ arr = await app.$get(`/dict`, { code: 'schedule_status' });
|
|
|
+ if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
|
|
|
+ // 比赛
|
|
|
+ arr = await app.$get(`/match`, { belong_id: raceuser._id, status: '2' }, 'race');
|
|
|
+ if (arr.errcode == '0') that.setData({ matchList: arr.data });
|
|
|
+ // 场地
|
|
|
+ arr = await app.$get(`/matchAddress`, { belong_id: raceuser._id, is_use: '0' }, '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({ refereeList: arr.data });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'raceuser',
|
|
|
+ success: async res => {
|
|
|
+ that.setData({ raceuser: res.data });
|
|
|
+ // 查询其他信息
|
|
|
+ await that.searchOther();
|
|
|
+ if (that.data.id) {
|
|
|
+ const arr = await app.$get(`/msgs/${that.data.id}`, {}, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ // 状态
|
|
|
+ let status = that.data.statusList.find(i => i.value == arr.data.status)
|
|
|
+ if (status) arr.data.zhStatus = status.label;
|
|
|
+ if (arr.data.player_type == 'Race.User') { arr.data.type_name = '单打' }
|
|
|
+ if (arr.data.player_type == 'Race.TeamApply') { arr.data.type_name = '双打' }
|
|
|
+ that.setData({ form: 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 () { },
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|