|
@@ -1,4 +1,6 @@
|
|
|
import { enroll,smsSend } from '../../api/other';
|
|
|
+import { FETCH_AND_FORMAT_USER_INFO } from '../../utils/util.js'
|
|
|
+import { uploadImage } from '../../utils/upload.js';
|
|
|
const app = getApp();
|
|
|
Page({
|
|
|
data: {
|
|
@@ -25,7 +27,10 @@ Page({
|
|
|
codeText: '获取验证码',
|
|
|
codeDisabled: false,
|
|
|
timer: null,
|
|
|
- countdown: 60
|
|
|
+ countdown: 60,
|
|
|
+ couponInfo:{},
|
|
|
+ filePath: '', // 上传成功的文件路径
|
|
|
+ fileType: '' // image / pdf
|
|
|
},
|
|
|
|
|
|
onShowPicker() {
|
|
@@ -48,26 +53,72 @@ Page({
|
|
|
showPicker: false
|
|
|
}, () => this.checkFormValid());
|
|
|
},
|
|
|
-
|
|
|
- // 上传文件
|
|
|
- afterRead(event) {
|
|
|
- const { file } = event.detail;
|
|
|
- wx.uploadFile({
|
|
|
- url: 'https://example.weixin.qq.com/upload', // 替换成真实接口
|
|
|
- filePath: file.url,
|
|
|
- name: 'file',
|
|
|
- formData: { user: 'test' },
|
|
|
- success: (res) => {
|
|
|
- const { fileList } = this.data;
|
|
|
- const path = res.data; // 假设返回路径
|
|
|
- fileList.push({ ...file, url: path });
|
|
|
- this.setData({
|
|
|
- fileList,
|
|
|
- formData: { ...this.data.formData, competition_image: path }
|
|
|
- });
|
|
|
+ // 点击上传区域
|
|
|
+ chooseFile() {
|
|
|
+ wx.showActionSheet({
|
|
|
+ itemList: ['图片', 'PDF'],
|
|
|
+ success: res => {
|
|
|
+ if (res.tapIndex === 0) {
|
|
|
+ this.chooseImage();
|
|
|
+ } else {
|
|
|
+ this.choosePdf();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 选择图片
|
|
|
+ chooseImage() {
|
|
|
+ wx.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['original', 'compressed'],
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
+ success: res => {
|
|
|
+ const path = res.tempFilePaths[0];
|
|
|
+ this.uploadFile(path, 'image');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ // 选择 PDF
|
|
|
+ choosePdf() {
|
|
|
+ wx.chooseMessageFile({
|
|
|
+ count: 1,
|
|
|
+ type: 'file',
|
|
|
+ success: res => {
|
|
|
+ const file = res.tempFiles[0];
|
|
|
+ if (file.name.endsWith('.pdf')) {
|
|
|
+ this.uploadFile(file.path, 'pdf');
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: '请选择 PDF 文件', icon: 'none' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 上传文件
|
|
|
+ async uploadFile(path, type) {
|
|
|
+ if (!path) {
|
|
|
+ wx.showToast({ title: '文件路径错误', icon: 'none' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const res = await uploadImage(path);
|
|
|
+ console.log('上传成功:', res);
|
|
|
+ this.setData({
|
|
|
+ filePath: res.url,
|
|
|
+ fileType: type,
|
|
|
+ "formData.competition_image": res.path
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ console.error('上传失败:', err);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 删除文件
|
|
|
+ removeFile() {
|
|
|
+ this.setData({
|
|
|
+ filePath: '',
|
|
|
+ fileType: '',
|
|
|
+ "formData.competition_image": ''
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
// 输入框数据绑定
|
|
|
onInput(e) {
|
|
@@ -138,8 +189,12 @@ Page({
|
|
|
};
|
|
|
const res = await enroll(payload);
|
|
|
if (res.code === 200) {
|
|
|
- wx.showToast({ title: res.data, icon: 'none', duration: 2000 });
|
|
|
+ // 优惠券信息
|
|
|
+ this.setData({
|
|
|
+ couponInfo:res.data[0]
|
|
|
+ })
|
|
|
this.setData({ showRegistrationSuccess: true });
|
|
|
+ app.globalData.userInfo = await FETCH_AND_FORMAT_USER_INFO();
|
|
|
} else {
|
|
|
wx.showToast({ title: res.message || '报名失败', icon: 'none', duration: 2000 });
|
|
|
}
|
|
@@ -147,7 +202,7 @@ Page({
|
|
|
// 点击协议文字显示弹窗
|
|
|
showAgreement(e) {
|
|
|
const type = e.currentTarget.dataset.type;
|
|
|
- const dataInfo = app.globalData.programConfig.marathon_event;
|
|
|
+ const dataInfo = app.globalData.programConfig;
|
|
|
this.setData({
|
|
|
showAgreementModal: true,
|
|
|
agreementContent: type == 'rules'?dataInfo.rules : type == 'liability'?dataInfo.disclaimer : dataInfo.privacy_policy,
|