2025-05-22 14:59:22 +08:00
|
|
|
'use client'
|
2026-03-13 14:13:06 +08:00
|
|
|
import {useForm} from 'react-hook-form'
|
2025-05-22 14:59:22 +08:00
|
|
|
import Center from '@/components/composites/purchase/long/center'
|
|
|
|
|
import {Form} from '@/components/ui/form'
|
|
|
|
|
import * as z from 'zod'
|
|
|
|
|
import {zodResolver} from '@hookform/resolvers/zod'
|
2026-04-16 14:41:42 +08:00
|
|
|
import {ProductItem} from '@/actions/product'
|
2026-04-18 14:30:30 +08:00
|
|
|
import {parsePurchaseSkuList} from '../shared/sku'
|
|
|
|
|
import {PurchaseSidePanel} from '../shared/side-panel'
|
2025-05-22 14:59:22 +08:00
|
|
|
|
|
|
|
|
const schema = z.object({
|
|
|
|
|
type: z.enum(['1', '2']).default('2'),
|
2026-04-16 14:41:42 +08:00
|
|
|
live: z.string(),
|
2025-05-22 14:59:22 +08:00
|
|
|
quota: z.number().min(500, '购买数量不能少于 500 个'),
|
2026-04-16 14:41:42 +08:00
|
|
|
expire: z.string(),
|
2025-05-22 14:59:22 +08:00
|
|
|
daily_limit: z.number().min(100, '每日限额不能少于 100 个'),
|
|
|
|
|
pay_type: z.enum(['wechat', 'alipay', 'balance']),
|
|
|
|
|
})
|
|
|
|
|
export type Schema = z.infer<typeof schema>
|
|
|
|
|
|
2026-04-16 14:41:42 +08:00
|
|
|
export default function LongForm({skuList}: {skuList: ProductItem['skus']}) {
|
2026-04-18 14:30:30 +08:00
|
|
|
const {priceMap, liveList, expireList} = parsePurchaseSkuList('long', skuList)
|
2026-04-16 14:41:42 +08:00
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
const form = useForm<Schema>({
|
|
|
|
|
resolver: zodResolver(schema),
|
|
|
|
|
defaultValues: {
|
|
|
|
|
type: '2', // 默认为包量套餐
|
2026-04-16 14:41:42 +08:00
|
|
|
live: liveList[0], // 分钟
|
|
|
|
|
expire: '0', // 天
|
2025-05-22 14:59:22 +08:00
|
|
|
quota: 500,
|
|
|
|
|
daily_limit: 100,
|
2026-03-31 16:11:36 +08:00
|
|
|
pay_type: 'balance', // 余额支付
|
2025-05-22 14:59:22 +08:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return (
|
2025-06-09 19:04:25 +08:00
|
|
|
<Form form={form} className="flex flex-col lg:flex-row gap-4">
|
2026-04-18 14:30:30 +08:00
|
|
|
<Center {...{liveList, priceMap, expireList}}/>
|
|
|
|
|
<PurchaseSidePanel kind="long"/>
|
2025-05-22 14:59:22 +08:00
|
|
|
</Form>
|
|
|
|
|
)
|
|
|
|
|
}
|