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

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 {Schema} from '@/components/composites/purchase/long/form'
import {useFormContext, useWatch} from 'react-hook-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', 100)
}
else {
form.setValue('quota', 500)
}
}, [type, form])
return (
<Card className="flex-auto p-6 flex flex-col gap-6 relative">
@@ -136,7 +144,7 @@ export default function Center() {
{/* 包时:每日提取上限 */}
<FormField
className="space-y-4"
name="daily_limit"
name="quota"
label="每日提取上限">
{({id, field}) => {
const value = Number(field.value) || 100
@@ -151,7 +159,7 @@ export default function Center() {
className={`h-10 w-10 border border-gray-200 rounded-sm flex items-center justify-center text-lg ${
value === minValue ? 'opacity-50 cursor-not-allowed' : ''
}`}
onClick={() => form.setValue('daily_limit', Math.max(minValue, value - step))}
onClick={() => form.setValue('quota', Math.max(minValue, value - step))}
disabled={value === minValue}>
<Minus/>
</Button>
@@ -164,7 +172,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', value + step)}>
onClick={() => form.setValue('quota', value + step)}>
<Plus/>
</Button>
</div>