|
@@ -0,0 +1,199 @@
|
|
|
+const app = getApp();
|
|
|
+import WxValidate from '../../../utils/wxValidate'
|
|
|
+
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
+ form: { logo: [] },
|
|
|
+ // 状态列表
|
|
|
+ statusList: [],
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = {
|
|
|
+ logo: { required: true },
|
|
|
+ name: { required: true },
|
|
|
+ startDate: { required: true },
|
|
|
+ startTime: { required: true },
|
|
|
+ endDate: { required: true },
|
|
|
+ endTime: { required: true },
|
|
|
+ address: { required: true },
|
|
|
+ sign_end_time: { required: true }, money_remark: { required: true }, money_mode: { required: true }, contact: { required: true }, explain: { required: true }, regular: { required: true }, status: { required: true }
|
|
|
+ }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = {
|
|
|
+ logo: { required: '请上传logo' }, name: { required: '请输入比赛名称' },
|
|
|
+ startDate: { required: '比赛开始日期' },
|
|
|
+ startTime: { required: '比赛开始时间' },
|
|
|
+ endDate: { required: '比赛结束日期' },
|
|
|
+ endTime: { required: '比赛结束时间' },
|
|
|
+ address: { required: '请输入比赛地点' }, sign_end_time: { required: '报名截止时间' }, money_remark: { required: '请输入报名费用说明' }, money_mode: { required: '请输入付款方式' }, contact: { required: '请输入联系方式' }, explain: { required: '请输入报名说明' }, regular: { required: '请输入赛事规程' }, status: { required: '请选择比赛状态' },
|
|
|
+ };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back: function () { wx.navigateBack({ delta: 1 }) },
|
|
|
+ // 上传照片
|
|
|
+ imgUpl: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.form.logo;
|
|
|
+ data.push(e.detail)
|
|
|
+ that.setData({ 'form.logo': data })
|
|
|
+ },
|
|
|
+ // 删除图片
|
|
|
+ imgDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.form.logo;
|
|
|
+ let arr = list.filter((i, index) => index != e.detail.index)
|
|
|
+ that.setData({ 'form.logo': arr })
|
|
|
+ },
|
|
|
+ // 选择比赛开始日期
|
|
|
+ startChangedate: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.startDate': e.detail.value });
|
|
|
+ },
|
|
|
+ // 选择比赛开始时间
|
|
|
+ startChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.startTime': e.detail.value });
|
|
|
+ },
|
|
|
+ // 选择比赛结束日期
|
|
|
+ endChangedate: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.endDate': e.detail.value });
|
|
|
+ },
|
|
|
+ // 选择比赛结束时间
|
|
|
+ endChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.endTime': e.detail.value });
|
|
|
+ },
|
|
|
+ // 选择报名截止日期
|
|
|
+ dateChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.sign_date': e.detail.value });
|
|
|
+ },
|
|
|
+ // 选择报名截止时间
|
|
|
+ timeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.sign_time': e.detail.value });
|
|
|
+ },
|
|
|
+ // 选择状态
|
|
|
+ statusChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.statusList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.status': data.value });
|
|
|
+ that.setData({ 'form.zhstatus': data.label });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //赛事规程
|
|
|
+ inputChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let html = e.detail.html;
|
|
|
+ that.setData({ "form.regular": html });
|
|
|
+ },
|
|
|
+ toSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const form = that.data.form;
|
|
|
+ const params = e.detail.value;
|
|
|
+ params.start_time = params.startDate + ' ' + params.startTime;
|
|
|
+ params.end_time = params.endDate + ' ' + params.endTime;
|
|
|
+ params.sign_end_time = params.sign_date + ' ' + params.sign_time;
|
|
|
+ params.logo = form.logo;
|
|
|
+ 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 (form._id) arr = await app.$post(`/match/${form._id}`, params);
|
|
|
+ else arr = await app.$post(`/match`, params);
|
|
|
+ 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) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ id: options.id || '' })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ // 监听用户是否登录
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'user',
|
|
|
+ success: async res => {
|
|
|
+ const aee = await app.$get(`/dict`, { code: "match_status" });
|
|
|
+ if (aee.errcode == '0' && aee.total > 0) that.setData({ statusList: aee.data[0].list });
|
|
|
+ if (that.data.id) {
|
|
|
+ const arr = await app.$get(`/match/${that.data.id}`);
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ // 比赛状态
|
|
|
+ let status = statusList.find(i => i.value == arr.data.status)
|
|
|
+ if (status) arr.data.zhStatus = status.label;
|
|
|
+ // 开始时间
|
|
|
+ arr.data.startDate = arr.data.start_time.slice(0, 10);
|
|
|
+ arr.data.startTime = arr.data.start_time.slice(11, arr.data.time_start.length);
|
|
|
+ // 结束时间
|
|
|
+ arr.data.endDate = arr.data.end_time.slice(0, 10);
|
|
|
+ arr.data.endTime = arr.data.end_time.slice(11, arr.data.time_end.length);
|
|
|
+ // 截止时间
|
|
|
+ arr.data.sign_date = arr.data.sign_end_time.slice(0, 10);
|
|
|
+ arr.data.sign_time = arr.data.sign_end_time.slice(11, arr.data.sign_end_time.length);
|
|
|
+ that.setData({ form: arr.data });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () { },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|