|
@@ -0,0 +1,171 @@
|
|
|
+const app = getApp();
|
|
|
+import WxValidate from '../../utils/wxValidate';
|
|
|
+const moment = require("../../utils/moment.min");
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '报名', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
+ user: {},
|
|
|
+ form: {},
|
|
|
+ // 赛事分组
|
|
|
+ groupList: [],
|
|
|
+ //项目名称
|
|
|
+ projectList: [],
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { group_id: { required: true }, project_id: { required: true }, card: { required: true, idcard: true } }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { group_id: { required: '赛事分组' }, project_id: { required: '项目名称' }, card: { required: '身份证' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back: function () { wx.navigateBack({ delta: 1 }) },
|
|
|
+ // 赛事分组
|
|
|
+ groupChange: 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, 'form.group_age': data.age })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 项目名称
|
|
|
+ projectChange: 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, 'form.project_age': data.age })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //提交
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ const form = that.data.form;
|
|
|
+ params.match_id = that.data.id;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ let checkFit = await app.$post(`/matchSign/checkFit`, params, 'race')
|
|
|
+ if (checkFit.errcode == '0') {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '您确定是否报名缴费?',
|
|
|
+ async success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'raceuser',
|
|
|
+ success: async (res) => {
|
|
|
+ let obj = { openid: res.data.openid, money: form.money, match_id: params.match_id, group_id: params.group_id, project_id: params.project_id, payer_id: params.user_id, time: moment().format('YYYY-MM-DD HH:mm:ss'), desc: '报名' }
|
|
|
+ const arr = await app.$post(`/payOrder`, obj, 'race')
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ wx.requestPayment({
|
|
|
+ "timeStamp": arr.data.wxSign.timestamp,
|
|
|
+ "nonceStr": arr.data.wxSign.nonceStr,
|
|
|
+ "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
|
|
|
+ "signType": arr.data.wxSign.signType,
|
|
|
+ "paySign": arr.data.wxSign.paySign,
|
|
|
+ "success": async function (res) {
|
|
|
+ const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { status: '1' }, 'race');
|
|
|
+ if (pay.errcode == '0') { wx.showToast({ title: `报名成功`, icon: 'success', duration: 5000 }); that.back(); }
|
|
|
+ else wx.showToast({ title: `${sign.errmsg}`, icon: 'error', duration: 2000 })
|
|
|
+ },
|
|
|
+ "fail": async function (res) {
|
|
|
+ const pay = await app.$delete(`/payOrder/${arr.data.data._id}`, {}, 'race');
|
|
|
+ if (pay.errcode == '0') wx.showToast({ title: `报名未成功`, icon: 'error', duration: 2000 })
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: async (res) => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else if (res.cancel) { }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else wx.showToast({ title: `${checkFit.errmsg}`, icon: 'none', duration: 2000 })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: async function (options) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ id: options.id || '' });
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ // 查询其他信息
|
|
|
+ await that.searchOther();
|
|
|
+ // 监听用户是否登录
|
|
|
+ await that.watchLogin();
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'raceuser',
|
|
|
+ success: async res => {
|
|
|
+ that.setData({ user: res.data })
|
|
|
+ const arr = await app.$get(`/match/${that.data.id}`, {}, 'race');
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.setData({ form: arr.data });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ searchOther: async function () {
|
|
|
+ const that = this;
|
|
|
+ let arr;
|
|
|
+ // 项目
|
|
|
+ arr = await app.$get(`/matchProject`, {}, 'race');
|
|
|
+ if (arr.errcode == '0' && arr.total > 0) that.setData({ projectList: arr.data });
|
|
|
+ // 组别
|
|
|
+ arr = await app.$get(`/matchGroup`, {}, 'race');
|
|
|
+ if (arr.errcode == '0') that.setData({ groupList: arr.data })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () { },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|