修改购买套餐调用接口后端计算价格 & 重置包时/包量初始化数量

This commit is contained in:
Eamon-meng
2025-12-17 10:13:38 +08:00
parent 4bb8d35b2a
commit 32a1b2a8b7
4 changed files with 87 additions and 32 deletions

View File

@@ -10,11 +10,19 @@ import check from '../_assets/check.svg'
import {useFormContext, useWatch} from 'react-hook-form'
import {Schema} from '@/components/composites/purchase/short/form'
import {Card} from '@/components/ui/card'
import {useEffect} from 'react'
export default function Center() {
const form = useFormContext<Schema>()
const type = useWatch({name: 'type'})
useEffect(() => {
if (type === '1') {
form.setValue('quota', 2000)
}
else {
form.setValue('quota', 10000)
}
}, [type, form])
return (
<Card className="flex-auto p-6 flex flex-col gap-6 relative">
@@ -130,7 +138,7 @@ export default function Center() {
{/* 包时:每日提取上限 */}
<FormField
className="space-y-4"
name="daily_limit"
name="quota"
label="每日提取上限">
{({id, field}) => (
<div className="flex gap-2 items-center">
@@ -138,7 +146,7 @@ export default function Center() {
theme="outline"
type="button"
className="h-10 w-10 border border-gray-200 rounded-sm flex items-center justify-center text-lg"
onClick={() => form.setValue('daily_limit', Math.max(2_000, Number(field.value) - 1_000))}
onClick={() => form.setValue('quota', Math.max(2_000, Number(field.value) - 1_000))}
disabled={Number(field.value) === 2_000}>
<Minus/>
</Button>
@@ -154,7 +162,7 @@ export default function Center() {
theme="outline"
type="button"
className="h-10 w-10 border border-gray-200 rounded-sm flex items-center justify-center text-lg"
onClick={() => form.setValue('daily_limit', Number(field.value) + 1_000)}>
onClick={() => form.setValue('quota', Number(field.value) + 1_000)}>
<Plus/>
</Button>
</div>