2026-04-18 14:30:30 +08:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import {useFormContext} from 'react-hook-form'
|
|
|
|
|
import {FormField} from '@/components/ui/form'
|
|
|
|
|
import {RadioGroup} from '@/components/ui/radio-group'
|
|
|
|
|
import FormOption from '../option'
|
2026-04-18 15:47:20 +08:00
|
|
|
import {PurchaseMode} from './resource'
|
2026-04-18 14:30:30 +08:00
|
|
|
import {PurchaseFormValues} from './form-values'
|
|
|
|
|
|
|
|
|
|
export function BillingMethodField(props: {
|
2026-04-18 15:47:20 +08:00
|
|
|
modeList: PurchaseMode[]
|
2026-04-18 14:30:30 +08:00
|
|
|
timeDailyLimit: number
|
|
|
|
|
}) {
|
2026-04-22 10:27:19 +08:00
|
|
|
const {setValue, getValues} = useFormContext<PurchaseFormValues>()
|
2026-04-18 14:30:30 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FormField<PurchaseFormValues, 'type'>
|
|
|
|
|
className="flex flex-col gap-4"
|
|
|
|
|
name="type"
|
|
|
|
|
label="计费方式"
|
|
|
|
|
>
|
|
|
|
|
{({id, field}) => (
|
|
|
|
|
<RadioGroup
|
|
|
|
|
id={id}
|
|
|
|
|
value={field.value}
|
|
|
|
|
onValueChange={(value) => {
|
|
|
|
|
field.onChange(value)
|
|
|
|
|
|
|
|
|
|
if (value === '2') {
|
|
|
|
|
setValue('expire', '0')
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-22 10:27:19 +08:00
|
|
|
setValue('expire', getValues('expire') || '0')
|
2026-04-18 14:30:30 +08:00
|
|
|
}}
|
|
|
|
|
className="flex gap-4 max-md:flex-col"
|
|
|
|
|
>
|
|
|
|
|
|
2026-04-18 15:47:20 +08:00
|
|
|
{props.modeList.includes('1') && (
|
|
|
|
|
<FormOption
|
|
|
|
|
id={`${id}-1`}
|
|
|
|
|
value="1"
|
|
|
|
|
label="包时套餐"
|
|
|
|
|
description="适用于每日提取量稳定的业务场景"
|
|
|
|
|
compare={field.value}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-04-27 17:08:41 +08:00
|
|
|
{props.modeList.includes('2') && (
|
|
|
|
|
<FormOption
|
|
|
|
|
id={`${id}-2`}
|
|
|
|
|
value="2"
|
|
|
|
|
label="包量套餐"
|
|
|
|
|
description="适用于短期或不定期高提取业务场景"
|
|
|
|
|
compare={field.value}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-04-18 14:30:30 +08:00
|
|
|
</RadioGroup>
|
|
|
|
|
)}
|
|
|
|
|
</FormField>
|
|
|
|
|
)
|
|
|
|
|
}
|