报名和取消报名流程优化
This commit is contained in:
parent
1d63531bb3
commit
ecd24de151
@ -711,9 +711,17 @@ Page({
|
||||
|
||||
// 4. 获取支付信息
|
||||
const paymentInfo = await this._getPaymentInfo(registrationId, openid);
|
||||
console.log('获取的支付信息:', paymentInfo);
|
||||
|
||||
// 5. 调起微信支付
|
||||
await this._invokeWeChatPay(paymentInfo.wechatPayParams, registrationId);
|
||||
// 5. 检查支付参数是否存在
|
||||
const wechatPayParams = paymentInfo.wechatPayParams || paymentInfo.WechatPayParams;
|
||||
if (!wechatPayParams || !wechatPayParams.paySign) {
|
||||
console.error('支付参数异常:', wechatPayParams);
|
||||
throw new Error('获取支付参数失败,请稍后重试');
|
||||
}
|
||||
|
||||
// 6. 调起微信支付
|
||||
await this._invokeWeChatPay(wechatPayParams, registrationId);
|
||||
|
||||
} catch (error) {
|
||||
console.error('支付流程异常:', error);
|
||||
@ -817,8 +825,20 @@ Page({
|
||||
/** 调起微信支付 */
|
||||
_invokeWeChatPay(wechatPayParams, registrationId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 确保所有支付参数都是字符串类型
|
||||
const params = {
|
||||
appId: String(wechatPayParams.appId || wechatPayParams.AppId || ''),
|
||||
timeStamp: String(wechatPayParams.timeStamp || wechatPayParams.TimeStamp || ''),
|
||||
nonceStr: String(wechatPayParams.nonceStr || wechatPayParams.NonceStr || ''),
|
||||
package: String(wechatPayParams.package || ''),
|
||||
signType: String(wechatPayParams.signType || wechatPayParams.SignType || 'MD5'),
|
||||
paySign: String(wechatPayParams.paySign || wechatPayParams.PaySign || '')
|
||||
};
|
||||
|
||||
console.log('准备调用微信支付,参数:', params);
|
||||
|
||||
wx.requestPayment({
|
||||
...wechatPayParams,
|
||||
...params,
|
||||
success: async () => {
|
||||
try {
|
||||
// 支付成功,同步支付状态
|
||||
|
||||
@ -544,26 +544,46 @@ Page({
|
||||
);
|
||||
var hasRegistrationLimit = registrationLimitLines.length > 0;
|
||||
|
||||
// 解析 units 数组,按 unitType 分组
|
||||
// unitType: 0=主办单位 1=承办单位 2=协办单位 3=赞助单位
|
||||
// 解析 units 数组,保持后端原始顺序并分组
|
||||
const UNIT_TYPE_LABELS = ['主办单位', '承办单位', '协办单位', '赞助单位'];
|
||||
const rawUnits = Array.isArray(detail.units)
|
||||
? detail.units
|
||||
: Array.isArray(detail.Units)
|
||||
? detail.Units
|
||||
: [];
|
||||
const unitMap = {};
|
||||
|
||||
const unitGroups = [];
|
||||
const labelMap = new Map(); // 用于记录标签在 unitGroups 中的索引位置
|
||||
|
||||
rawUnits.forEach((u) => {
|
||||
const customType = u.customUnitType || u.CustomUnitType;
|
||||
const type = u.unitType != null ? u.unitType : u.UnitType != null ? u.UnitType : null;
|
||||
const name = u.unitName || u.UnitName || u.name || u.Name || '';
|
||||
if (type == null || !name.trim()) return;
|
||||
const t = Number(type);
|
||||
if (!unitMap[t]) unitMap[t] = [];
|
||||
unitMap[t].push(name.trim());
|
||||
|
||||
if (!name.trim()) return;
|
||||
|
||||
// 确定分组标签
|
||||
let label;
|
||||
if (customType && customType.trim()) {
|
||||
label = customType.trim();
|
||||
} else if (type != null) {
|
||||
const t = Number(type);
|
||||
label = UNIT_TYPE_LABELS[t];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// 查找或创建分组
|
||||
if (labelMap.has(label)) {
|
||||
// 分组已存在,添加到该分组
|
||||
const index = labelMap.get(label);
|
||||
unitGroups[index].names.push(name.trim());
|
||||
} else {
|
||||
// 新分组,添加到数组并记录索引
|
||||
labelMap.set(label, unitGroups.length);
|
||||
unitGroups.push({ label, names: [name.trim()] });
|
||||
}
|
||||
});
|
||||
const unitGroups = [0, 1, 2, 3]
|
||||
.filter((t) => unitMap[t] && unitMap[t].length)
|
||||
.map((t) => ({ label: UNIT_TYPE_LABELS[t], names: unitMap[t] }));
|
||||
|
||||
const eventStatus = parseEventStatus(detail);
|
||||
const { canApply, applyButtonText } = applyUiFromEventStatus(eventStatus);
|
||||
|
||||
@ -53,6 +53,23 @@ Page({
|
||||
})
|
||||
.then((detail) => {
|
||||
const d = detail && typeof detail === 'object' ? detail : {};
|
||||
|
||||
// 检查报名状态,如果已取消(PaymentStatus=3),则提示用户
|
||||
const paymentStatus = d.paymentStatus != null ? Number(d.paymentStatus) : null;
|
||||
if (paymentStatus === 3) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '该报名已取消,无法继续操作',
|
||||
showCancel: false,
|
||||
confirmText: '确定',
|
||||
success: () => {
|
||||
wx.navigateBack();
|
||||
}
|
||||
});
|
||||
this.setData({ loading: false });
|
||||
return;
|
||||
}
|
||||
|
||||
const rawItems = Array.isArray(d.items) ? d.items : [];
|
||||
|
||||
const items = rawItems.map((it, idx) => {
|
||||
@ -89,13 +106,32 @@ Page({
|
||||
};
|
||||
});
|
||||
|
||||
// 使用后端返回的退款金额和规则
|
||||
const refundRulesText = d.refundRulesText || d.RefundRulesText || '退款规则以赛事说明为准';
|
||||
const refundAmountFromBackend = d.refundAmount != null ? toNumber(d.refundAmount) : (d.RefundAmount != null ? toNumber(d.RefundAmount) : null);
|
||||
|
||||
// 默认全选
|
||||
this.setData({
|
||||
items,
|
||||
selectAll: items.length > 0,
|
||||
refundRulesText,
|
||||
loading: false
|
||||
});
|
||||
this.recalc();
|
||||
|
||||
// 优先使用后端计算的退款金额,否则使用前端计算
|
||||
if (refundAmountFromBackend != null) {
|
||||
const all = [];
|
||||
this.data.items.forEach((it) => it.pills.forEach((p) => all.push(p)));
|
||||
const selected = all.filter((p) => p.selected);
|
||||
const selectAll = all.length > 0 && selected.length === all.length;
|
||||
this.setData({
|
||||
selectedCount: selected.length,
|
||||
selectAll,
|
||||
refundAmount: formatMoney(refundAmountFromBackend)
|
||||
});
|
||||
} else {
|
||||
this.recalc();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
this.setData({ loading: false, items: [] });
|
||||
@ -163,14 +199,25 @@ Page({
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// wx.hideLoading();
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: '退款申请已提交', icon: 'success' });
|
||||
setTimeout(() => {
|
||||
// 返回上一页并刷新数据
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
const prevPage = pages[pages.length - 2];
|
||||
// 如果上一页是 records 页面,通知它刷新
|
||||
if (prevPage && prevPage.route && prevPage.route.includes('records')) {
|
||||
if (prevPage.initData) {
|
||||
prevPage.initData(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
})
|
||||
.catch((err) => {
|
||||
// wx.hideLoading();
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: (err && err.message) || '提交失败,请稍后重试', icon: 'none' });
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user