完善价格计算逻辑
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'use client'
|
||||
import {useContext} from 'react'
|
||||
import {useContext, useMemo} from 'react'
|
||||
import {PurchaseFormContext} from '@/components/composites/purchase/_client/form'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import {FormField} from '@/components/ui/form'
|
||||
@@ -8,7 +8,6 @@ import Image from 'next/image'
|
||||
import alipay from '@/components/composites/purchase/_assets/alipay.svg'
|
||||
import wechat from '@/components/composites/purchase/_assets/wechat.svg'
|
||||
import balance from '@/components/composites/purchase/_assets/balance.svg'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {AuthContext} from '@/components/providers/AuthProvider'
|
||||
import RechargeModal from '@/components/composites/purchase/_client/recharge'
|
||||
import Pay from '@/components/composites/purchase/_client/pay'
|
||||
@@ -33,6 +32,22 @@ export default function Right(props: RightProps) {
|
||||
const watchDailyLimit = form.watch('daily_limit')
|
||||
const payType = form.watch('pay_type')
|
||||
|
||||
const price = useMemo(() => {
|
||||
const count = watchType === '1' ? watchDailyLimit : watchQuota
|
||||
|
||||
let seconds = parseInt(watchLive, 10) * 60
|
||||
if (seconds == 180) {
|
||||
seconds = 150
|
||||
}
|
||||
|
||||
let times = parseInt(watchExpire, 10)
|
||||
if (watchType === '2') {
|
||||
times = 1
|
||||
}
|
||||
|
||||
return count * seconds * times / 30000
|
||||
}, [watchDailyLimit, watchExpire, watchLive, watchQuota, watchType])
|
||||
|
||||
return (
|
||||
<div className={`flex-none basis-80 p-6 flex flex-col gap-6`}>
|
||||
<h3>订单详情</h3>
|
||||
@@ -74,7 +89,7 @@ export default function Right(props: RightProps) {
|
||||
<div className={`border-b border-gray-200`}></div>
|
||||
<p className={`flex justify-between items-center`}>
|
||||
<span>价格</span>
|
||||
<span className={`text-xl text-orange-500`}>¥--</span>
|
||||
<span className={`text-xl text-orange-500`}>¥{price}</span>
|
||||
</p>
|
||||
<FormField name={`pay_type`} label={`支付方式`} className={`flex flex-col gap-6`}>
|
||||
{({id, field}) => (
|
||||
@@ -121,11 +136,11 @@ export default function Right(props: RightProps) {
|
||||
</RadioGroup>
|
||||
)}
|
||||
</FormField>
|
||||
<Pay method={payType} amount={100} resource={{
|
||||
<Pay method={payType} amount={price} resource={{
|
||||
type: Number(watchType),
|
||||
live: Number(watchLive) * 60,
|
||||
quota: watchQuota,
|
||||
expire: Number(watchExpire) * 24 * 3600,
|
||||
expire: Number(watchExpire),
|
||||
daily_limit: watchDailyLimit,
|
||||
}}/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user