|
@@ -0,0 +1,201 @@
|
|
|
+const app = getApp()
|
|
|
+import { pay_status } from '../../../utils/dict';
|
|
|
+import WxValidate from '../../../utils/wxValidate';
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '信息维护', leftArrow: true, useBar: false },
|
|
|
+ form: {},
|
|
|
+ //比赛列表
|
|
|
+ matchList: [],
|
|
|
+ // 赛事组别
|
|
|
+ groupList: [],
|
|
|
+ // 组内项目
|
|
|
+ projectList: [],
|
|
|
+ // 用户列表
|
|
|
+ userList: [],
|
|
|
+ statusList: pay_status
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { match_id: { required: true } }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { match_id: { 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 });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 用户
|
|
|
+ userChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.userList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.user_id': data._id, 'form.user_name': data.user_id.name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选择状态
|
|
|
+ statusChange: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.statusList[e.detail.value];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.pay_status': data.value, 'form.zhpay_status': data.label });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //提交
|
|
|
+ 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 (params._id) { arr = await app.$post(`/matchSign/${params._id}`, params, 'race') }
|
|
|
+ else { arr = await app.$post(`/matchSign`, 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.id || '' })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ // 监听用户是否登录
|
|
|
+ await that.watchLogin();
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'raceuser',
|
|
|
+ success: async res => {
|
|
|
+ let arr;
|
|
|
+ arr = await app.$get(`/match`, { belong_id: '630ec0480a92b0a015ccfbe1' }, 'race');
|
|
|
+ if (arr.errcode == '0') that.setData({ matchList: arr.data });
|
|
|
+ // 用户列表
|
|
|
+ arr = await app.$get(`/user`, { type: '0' }, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ for (const val of arr.data) { val.user_id_name = val.user_id.name; };
|
|
|
+ that.setData({ userList: arr.data })
|
|
|
+ }
|
|
|
+ if (that.data.id) {
|
|
|
+ const arr = await app.$get(`/matchSign/${that.data.id}`, {}, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ let form = arr.data;
|
|
|
+ let aee;
|
|
|
+ // 查询赛事
|
|
|
+ aee = await app.$get(`/match/${form.match_id}`, {}, 'race')
|
|
|
+ if (aee.errcode == '0') { form.match_name = aee.data.name; }
|
|
|
+ // 查询组别
|
|
|
+ aee = await app.$get(`/matchGroup/${form.group_id}`, {}, 'race')
|
|
|
+ if (aee.errcode == '0') { form.group_name = aee.data.name; }
|
|
|
+ // 查询项目
|
|
|
+ aee = await app.$get(`/matchProject/${form.project_id}`, {}, 'race')
|
|
|
+ if (aee.errcode == '0') { form.project_name = aee.data.name; }
|
|
|
+ // 报名用户
|
|
|
+ aee = await app.$get(`/user/${form.user_id}`, {}, 'race')
|
|
|
+ if (aee.errcode == '0') {
|
|
|
+ form.user_id = aee.data;
|
|
|
+ // 查询用户信息
|
|
|
+ const user = await app.$get(`/user/${aee.data.user_id}`);
|
|
|
+ if (user.errcode == '0') { form.user_name = user.data.name }
|
|
|
+ }
|
|
|
+ // 查询支付状态
|
|
|
+ form.zhpay_status = that.searchStatus(form.pay_status);
|
|
|
+ that.setData({ form })
|
|
|
+ }
|
|
|
+ };
|
|
|
+ },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 查询状态
|
|
|
+ searchStatus: function (e) {
|
|
|
+ let data = pay_status.find(i => i.value == e);
|
|
|
+ if (data) return data.label;
|
|
|
+ else return '暂无';
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|