From 5f87a71ab23ff41acfaeac9704e9264805584b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Thu, 20 Nov 2025 23:14:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E6=9C=AA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E6=B5=8B=E8=AF=95=E7=BB=93=E6=9E=9C=E9=A1=B5?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/NTRPTestEntryCard/index.tsx | 14 ++- src/components/refundPopup/index.tsx | 115 +++++++++++------- .../ntrp-evaluate/index.module.scss | 2 +- src/other_pages/ntrp-evaluate/index.tsx | 54 +++++--- 4 files changed, 120 insertions(+), 65 deletions(-) diff --git a/src/components/NTRPTestEntryCard/index.tsx b/src/components/NTRPTestEntryCard/index.tsx index cce9100..d9db6f6 100644 --- a/src/components/NTRPTestEntryCard/index.tsx +++ b/src/components/NTRPTestEntryCard/index.tsx @@ -39,7 +39,7 @@ function NTRPTestEntryCard(props: { // 获取测试结果 const res = await evaluateService.getLastResult(); if (res.code === 0) { - setTestFlag(res.data.has_ntrp_level); + setTestFlag(res.data.has_test_record); setHasTestInLastMonth(res.data.has_test_in_last_month); } }; @@ -117,13 +117,21 @@ function NTRPTestEntryCard(props: { }, }); } + if (!testFlag && !userInfo.phone) { + Taro.navigateTo({ + url: `/login_pages/index/index?redirect=${encodeURIComponent( + `/other_pages/ntrp-evaluate/index?stage=${StageType.INTRO}` + )}`, + }); + return false; + } Taro.navigateTo({ url: `/other_pages/ntrp-evaluate/index?stage=${ - testFlag ? StageType.INTRO : StageType.INTRO + testFlag ? StageType.INTRO : StageType.TEST }`, }); }, - [setCallback, testFlag, type, evaluateCallback] + [setCallback, testFlag, type, evaluateCallback, userInfo.phone] ); // 如果最近一个月有测试记录,则不展示 diff --git a/src/components/refundPopup/index.tsx b/src/components/refundPopup/index.tsx index b7354d9..5106799 100644 --- a/src/components/refundPopup/index.tsx +++ b/src/components/refundPopup/index.tsx @@ -1,31 +1,48 @@ -import React, { useState, useRef, forwardRef, useImperativeHandle } from 'react'; -import { View, Text, Button, Image } from '@tarojs/components' -import Taro from '@tarojs/taro'; -import dayjs from 'dayjs' -import { CommonPopup } from '@/components'; -import orderService from '@/services/orderService'; -import styles from './index.module.scss' -import closeIcon from '@/static/order/orderListClose.svg' +import React, { + useState, + useRef, + forwardRef, + useImperativeHandle, +} from "react"; +import { View, Text, Button, Image } from "@tarojs/components"; +import Taro from "@tarojs/taro"; +import dayjs from "dayjs"; +import { CommonPopup } from "@/components"; +import orderService from "@/services/orderService"; +import styles from "./index.module.scss"; +import closeIcon from "@/static/order/orderListClose.svg"; -function genRefundNotice (refund_policy) { +function genRefundNotice(refund_policy) { if (refund_policy.length === 0) { - return {} + return {}; } - const now = dayjs() - const deadlines = refund_policy.map(item => dayjs(item.deadline_formatted)) - let matchPolicyIndex = deadlines.findIndex(d => d.isAfter(now)) + const now = dayjs(); + const deadlines = refund_policy.map((item) => dayjs(item.deadline_formatted)); + let matchPolicyIndex = deadlines.findIndex((d) => d.isAfter(now)); if (matchPolicyIndex === -1) { - matchPolicyIndex = refund_policy.length - 1 + matchPolicyIndex = refund_policy.length - 1; } - const { deadline_formatted, price, refund_rate } = refund_policy[matchPolicyIndex] + const { deadline_formatted, price, refund_rate } = + refund_policy[matchPolicyIndex]; if (refund_rate === 1) { - return { refundPrice: price, notice: `本次可全额退款, ¥${price} 将原路退回,请查收` } + return { + refundPrice: price, + notice: `本次可全额退款, ¥${price} 将原路退回,请查收`, + }; } else if (refund_rate === 0) { - return { refundPrice: 0, notice: `当前退出不可退款,后续流程未明确,@麻真瑜` } + return { + refundPrice: 0, + notice: `当前退出不可退款,后续流程未明确,@麻真瑜`, + }; } - const refundPrice = price * refund_rate - const leftHours = dayjs(deadline_formatted).diff(dayjs(), 'hour') - return { refundPrice, notice: `距活动开始已不足${leftHours}h,当前退出您需扣除${price - refundPrice}元` } + const refundPrice = Number(Math.ceil(price * refund_rate * 100) / 100); + const leftHours = dayjs(deadline_formatted).diff(dayjs(), "hour"); + return { + refundPrice, + notice: `距活动开始已不足${leftHours}h,当前退出您需扣除${ + Math.floor((price - refundPrice) * 100) / 100 + }元`, + }; } function renderCancelContent(checkOrderInfo) { @@ -42,7 +59,7 @@ function renderCancelContent(checkOrderInfo) { }; }), ]; - const { notice } = genRefundNotice(refund_policy) + const { notice } = genRefundNotice(refund_policy); return ( {/* @@ -63,37 +80,35 @@ function renderCancelContent(checkOrderInfo) { } export type RefundRef = { - show: (item: any, callback: (result: boolean) => void) => void -} + show: (item: any, callback: (result: boolean) => void) => void; +}; export default forwardRef(function RefundPopup(_props, ref) { - const [visible, setVisible] = useState(false) - const [checkOrderInfo, setCheckOrderInfo] = useState({}) - const [orderData, setOrderData] = useState({}) - const onDown = useRef<((result: boolean) => void) | null>(null) + const [visible, setVisible] = useState(false); + const [checkOrderInfo, setCheckOrderInfo] = useState({}); + const [orderData, setOrderData] = useState({}); + const onDown = useRef<((result: boolean) => void) | null>(null); useImperativeHandle(ref, () => ({ show: onShow, - })) + })); - async function onShow (orderItem, onFinish: (result: boolean) => void) { - const { - game_info, - } = orderItem - onDown.current = onFinish - setOrderData(orderItem) + async function onShow(orderItem, onFinish: (result: boolean) => void) { + const { game_info } = orderItem; + onDown.current = onFinish; + setOrderData(orderItem); const res = await orderService.getCheckOrderInfo(game_info.id); setCheckOrderInfo(res.data); - setVisible(true) + setVisible(true); } - function onClose () { - setVisible(false) - onDown.current?.(false) + function onClose() { + setVisible(false); + onDown.current?.(false); } - async function handleConfirmQuit () { - const { order_no, amount } = orderData + async function handleConfirmQuit() { + const { order_no, amount } = orderData; try { const refundRes = await orderService.applicateRefund({ order_no, @@ -106,15 +121,15 @@ export default forwardRef(function RefundPopup(_props, ref) { Taro.showToast({ title: "退出成功", icon: "none", - }) - onDown.current?.(true) + }); + onDown.current?.(true); } catch (e) { Taro.showToast({ title: e.message, icon: "error", }); } finally { - onClose() + onClose(); } } return ( @@ -129,11 +144,17 @@ export default forwardRef(function RefundPopup(_props, ref) { 退出活动 - + {renderCancelContent(checkOrderInfo)} - + - ) -}) \ No newline at end of file + ); +}); diff --git a/src/other_pages/ntrp-evaluate/index.module.scss b/src/other_pages/ntrp-evaluate/index.module.scss index a354819..161972f 100644 --- a/src/other_pages/ntrp-evaluate/index.module.scss +++ b/src/other_pages/ntrp-evaluate/index.module.scss @@ -295,7 +295,7 @@ } .actions { - margin: 74px 22px 0; + margin: 52px 22px 0; display: flex; flex-direction: column; gap: 10px; diff --git a/src/other_pages/ntrp-evaluate/index.tsx b/src/other_pages/ntrp-evaluate/index.tsx index b0d2d0f..beea3ea 100644 --- a/src/other_pages/ntrp-evaluate/index.tsx +++ b/src/other_pages/ntrp-evaluate/index.tsx @@ -150,7 +150,9 @@ function Intro() { const { last_test_result = null } = ntrpData || {}; const { ntrp_level, create_time, id } = last_test_result || {}; - const lastTestTime = create_time ? dayjs(create_time).format("YYYY年M月D日") : ""; + const lastTestTime = create_time + ? dayjs(create_time).format("YYYY年M月D日") + : ""; useEffect(() => { const init = async () => { @@ -192,15 +194,16 @@ function Intro() { }); } Taro.redirectTo({ - url: `/other_pages/ntrp-evaluate/index?stage=${type}${type === StageType.RESULT ? `&id=${id}` : "" - }`, + url: `/other_pages/ntrp-evaluate/index?stage=${type}${ + type === StageType.RESULT ? `&id=${id}` : "" + }`, }); } return ( - {ntrpData?.has_ntrp_level ? ( + {ntrpData?.has_test_record ? ( @@ -234,7 +237,9 @@ function Intro() { NTRP - {formatNtrpDisplay(ntrp_level || "")} + + {formatNtrpDisplay(ntrp_level || "")} + 变线+网前,下一步就是赢比赛! @@ -495,6 +500,10 @@ function Result() { } function handleReTest() { + if (!userInfo.phone) { + handleAuth(); + return false; + } Taro.redirectTo({ url: `/other_pages/ntrp-evaluate/index?stage=${StageType.TEST}`, }); @@ -507,6 +516,15 @@ function Result() { } async function handleGoon() { + if (!userInfo?.phone) { + Taro.redirectTo({ + url: `/login_pages/index/index?redirect=${encodeURIComponent( + `/main_pages/index` + )}`, + }); + clear(); + return; + } if (type) { next({ flag: false, score: result?.ntrp_level as string }); await delay(1500); @@ -566,7 +584,8 @@ function Result() { async function handleSaveImage() { console.log(userInfo); - if (!userInfo?.id) { + if (!userInfo?.phone) { + handleAuth(); return; } Taro.getSetting().then(async (res) => { @@ -615,16 +634,19 @@ function Result() { }); function handleAuth() { - if (userInfo?.id) { + if (userInfo?.phone) { return true; } const currentPage = getCurrentFullPath(); Taro.redirectTo({ - url: `/login_pages/index/index${currentPage ? `?redirect=${encodeURIComponent(currentPage)}` : "" - }`, + url: `/login_pages/index/index${ + currentPage ? `?redirect=${encodeURIComponent(currentPage)}` : "" + }`, }); } + function handleGo() {} + return ( @@ -652,7 +674,9 @@ function Result() { NTRP - {formatNtrpDisplay(result?.ntrp_level)} + + {formatNtrpDisplay(result?.ntrp_level)} + 变线+网前,下一步就是赢比赛! @@ -666,9 +690,11 @@ function Result() { 重新测试 - {userInfo?.id ? ( + {userInfo?.phone ? ( - 你的 NTRP 水平已更新为 {formatNtrpDisplay(result?.ntrp_level || "")} + + 你的 NTRP 水平已更新为 {formatNtrpDisplay(result?.ntrp_level || "")}{" "} + (可在个人信息中修改) ) : ( @@ -679,14 +705,14 @@ function Result() {