From ecd24de1515a144200967a50518165978377fa4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Sat, 9 May 2026 13:29:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E5=90=8D=E5=92=8C=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8A=A5=E5=90=8D=E6=B5=81=E7=A8=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/apply/apply.js | 26 +++++++-- pages/detail/detail.js | 40 ++++++++++---- .../cancel-registration.js | 53 +++++++++++++++++-- 3 files changed, 103 insertions(+), 16 deletions(-) diff --git a/pages/apply/apply.js b/pages/apply/apply.js index ca5a513..12c8142 100644 --- a/pages/apply/apply.js +++ b/pages/apply/apply.js @@ -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 { // 支付成功,同步支付状态 diff --git a/pages/detail/detail.js b/pages/detail/detail.js index b69471c..a2fb4f2 100644 --- a/pages/detail/detail.js +++ b/pages/detail/detail.js @@ -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); diff --git a/subpackages/mine/cancel-registration/cancel-registration.js b/subpackages/mine/cancel-registration/cancel-registration.js index b4036c4..25493ec 100644 --- a/subpackages/mine/cancel-registration/cancel-registration.js +++ b/subpackages/mine/cancel-registration/cancel-registration.js @@ -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' }); }); }