|
@@ -0,0 +1,225 @@
|
|
|
+
|
|
|
+import WxValidate from '../../utils/wxValidate';
|
|
|
+const moment = require("../../utils/moment.min")
|
|
|
+const app = getApp()
|
|
|
+Page({
|
|
|
+
|
|
|
+
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '申请报名', leftArrow: true, useBar: false },
|
|
|
+
|
|
|
+ infoHeight: '',
|
|
|
+
|
|
|
+ user: {},
|
|
|
+
|
|
|
+ match_id: '629eb5f211f83364713232a1',
|
|
|
+ matchInfo: {},
|
|
|
+
|
|
|
+ teamInfo: {},
|
|
|
+
|
|
|
+ dialog: { title: '选择赛制', show: false, type: '1' },
|
|
|
+
|
|
|
+ userList: [],
|
|
|
+
|
|
|
+ members: [],
|
|
|
+
|
|
|
+ formatList: [],
|
|
|
+ format: [],
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { match_name: { required: true } }
|
|
|
+
|
|
|
+ const messages = { match_name: { required: '请输入比赛名称' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+ back: function () {
|
|
|
+ wx.navigateBack({ url: '/pages/matchteam/index' })
|
|
|
+ },
|
|
|
+
|
|
|
+ changeMem: function () {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ dialog: { title: '成员列表', show: true, type: '2' } })
|
|
|
+ },
|
|
|
+
|
|
|
+ onMemchange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = e.detail.value;
|
|
|
+ let user = that.data.userList;
|
|
|
+ let members = [];
|
|
|
+ for (const val of data) {
|
|
|
+ let arr = user.find((i) => i.user_id == val);
|
|
|
+ if (arr) members.push(arr)
|
|
|
+ }
|
|
|
+ that.setData({ 'form.match_num': members.length })
|
|
|
+ that.setData({ members: members })
|
|
|
+ },
|
|
|
+
|
|
|
+ memDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ const { user_id } = e.currentTarget.dataset;
|
|
|
+ var members = that.data.members;
|
|
|
+ for (var i = 0; i < members.length; i++) {
|
|
|
+ if (members[i].user_id == user_id) members.splice(i, 1)
|
|
|
+ }
|
|
|
+ that.setData({ 'form.match_num': members.length })
|
|
|
+ this.setData({ members: members })
|
|
|
+ },
|
|
|
+
|
|
|
+ formatChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ const { value } = e.detail;
|
|
|
+ let format = that.data.format;
|
|
|
+ let data = that.data.formatList[value];
|
|
|
+ let list = [];
|
|
|
+ if (data) list = [...format, data]
|
|
|
+ that.setData({ format: list })
|
|
|
+ },
|
|
|
+
|
|
|
+ formatDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.format;
|
|
|
+ const { index } = e.currentTarget.dataset;
|
|
|
+ list.splice(index, 1);
|
|
|
+ that.setData({ format: list });
|
|
|
+ },
|
|
|
+
|
|
|
+ toClose: function () {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ dialog: { title: '选择赛制', show: false } })
|
|
|
+ },
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ const format = that.data.format;
|
|
|
+ const members = that.data.members;
|
|
|
+ const data = that.data.form;
|
|
|
+ params.format = format;
|
|
|
+ params.members = members;
|
|
|
+ params.apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ params.logo = data.logo;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ if (params.format.length > 0 && params.members.length > 0) {
|
|
|
+ const arr = await app.$post(`/courtAdmin/api/matchteam`, params);
|
|
|
+ if (arr.errcode == 0) { wx.showToast({ title: `报名成功`, icon: 'success', duration: 2000 }); that.back(); }
|
|
|
+ else wx.showToast({ title: arr.errmsg, icon: 'none', duration: 2000 })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `缺少必要信息`, icon: 'error', duration: 2000 })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: function (options) {
|
|
|
+ const that = this;
|
|
|
+ if (options && options.id) that.setData({ match_id: options.id })
|
|
|
+
|
|
|
+ this.initValidate();
|
|
|
+
|
|
|
+ this.searchHeight();
|
|
|
+
|
|
|
+ this.watchLogin();
|
|
|
+ },
|
|
|
+
|
|
|
+ watchLogin: function () {
|
|
|
+ const that = this;
|
|
|
+ let match_id = that.data.match_id;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ success: async res => {
|
|
|
+ that.setData({ user: res.data })
|
|
|
+
|
|
|
+ let arr = await app.$get(`/courtAdmin/api/match/${match_id}`);
|
|
|
+ if (arr.errcode == '0') that.setData({ matchInfo: arr.data });
|
|
|
+ that.setData({ formatList: arr.data.format })
|
|
|
+
|
|
|
+ let aee = await app.$get(`/courtAdmin/api/team`, { create_id: res.data._id })
|
|
|
+ if (aee.errcode == '0') that.setData({ teamInfo: aee.data[0] });
|
|
|
+
|
|
|
+ let att = {
|
|
|
+
|
|
|
+ match_id: arr.data._id,
|
|
|
+ match_name: arr.data.name,
|
|
|
+
|
|
|
+ team_id: aee.data[0]._id,
|
|
|
+ team_name: aee.data[0].name,
|
|
|
+ logo: aee.data[0].logo,
|
|
|
+ create_id: aee.data[0].create_id,
|
|
|
+ create_user: aee.data[0].create_user,
|
|
|
+ create_time: aee.data[0].create_time,
|
|
|
+ }
|
|
|
+ that.setData({ userList: aee.data[0].members });
|
|
|
+ that.setData({ form: att })
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ searchHeight: function () {
|
|
|
+ let frameStyle = this.data.frameStyle;
|
|
|
+ let client = app.globalData.client;
|
|
|
+ let infoHeight = client.windowHeight;
|
|
|
+
|
|
|
+ if (frameStyle.useTop) infoHeight = infoHeight - (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 () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|