import React, { useEffect, useState } from 'react';
import { Input, Space, Tag, Card, QRCode, Form, Descriptions, Typography, Alert, Button, Modal, Radio, Flex, DatePicker } from 'antd';
import { CheckCircleOutlined } from '@ant-design/icons';
import { CentToString } from 'oak-domain/lib/utils/money';
import Styles from './web.pc.module.less';
import dayJs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
dayJs.extend(duration);
export function RenderOffline(props) {
const { pay, t, offline, offlines, updateOfflineId, updateExternalId, mode } = props;
const { iState, phantom3, externalId } = pay;
const { type, channel, name, qrCode, color } = offline;
const [show, setShow] = useState(false);
const [showQrCode, setShowQrCode] = useState(false);
const items2 = [
{`${t('channel.prefix')}`}}>
{iState === 'paying' && offlines.length > 1 ?
:
{t(`offlineAccount:v.type.${type}`)}}
];
if (type === 'bank') {
items2.push(
{channel}
,
{name}
,
{qrCode}
);
}
else {
if (type === 'others') {
items2.push(
{channel}
);
}
if (name) {
items2.push(
{name}
);
}
if (qrCode) {
items2.push(
setShowQrCode(true)}>
);
}
}
items2.push({t('code.label')}}>
{phantom3}
, {t('externalId.label')}} help={mode === 'frontend' && iState === 'paying' && t('externalId.help')}>
{
const { value } = currentTarget;
updateExternalId(value);
}} placeholder={t('externalId.placeholder')} disabled={iState !== 'paying' && mode === 'frontend'}/>
);
return (<>
setShow(false)} closeIcon={null} footer={null}>
{
updateOfflineId(target.value);
setShow(false);
}} value={offline.id}>
{offlines.map((ele, idx) => (
{t(`offlineAccount:v.type.${ele.type}`)}
))}
setShowQrCode(false)}>
>);
}
function Counter(props) {
const { deadline } = props;
const [counter, setCounter] = useState('');
const timerFn = () => {
const now = Date.now();
if (now < deadline) {
const duration = dayJs.duration(deadline - now);
setCounter(duration.format('HH:mm:ss'));
setTimeout(timerFn, 1000);
}
};
useEffect(() => {
timerFn();
}, []);
return ({counter});
}
function RenderWechatPay(props) {
const { pay, t } = props;
const { externalId, wpProduct, timeoutAt, iState } = pay;
if (iState === 'paid') {
return ();
}
switch (wpProduct.type) {
case 'native': {
if (iState === 'paying') {
return (
{process.env.NODE_ENV === 'production' ?
:
}
);
}
break;
}
}
return null;
}
function RenderPayMeta(props) {
const { pay, notSameApp, t, offlines, offline, updateOfflineId, updateExternalId, mode } = props;
const { iState, entity } = pay;
if (entity !== 'offlineAccount' && notSameApp) {
return ;
}
switch (entity) {
case 'offlineAccount': {
if (offline && offlines) {
return (<>
{iState === 'paying' && (mode === 'frontend'
?
: )}
>);
}
return null;
}
case 'wpProduct': {
return ;
}
}
// todo 要支持注入第三方支付的渲染组件
return null;
}
export default function Render(props) {
const { pay, iStateColor, notSameApp, type, startPayable, goBackable, succeedable, oakExecutable, onClose, closable, offline, offlines, autoSuccessAt, mode } = props.data;
const { t, update, execute, clean, goBack, startPay, succeed } = props.methods;
const [showSa, setShowSa] = useState(false);
const [sa, setSa] = useState(Date.now());
if (pay) {
const { iState, price, entity } = pay;
const BtnPart2 = [];
if (startPayable) {
BtnPart2.push();
}
else if (oakExecutable === true) {
BtnPart2.push(, );
}
else {
if (closable) {
BtnPart2.push();
}
if (goBackable) {
BtnPart2.push();
}
}
return (<>
{succeedable ? :
{t(`pay:v.iState.${iState}`)}
}
}>
{t(`type.${type}`)},
},
{
key: '1',
label: t('pay:attr.price'),
children: {`${t('common::pay.symbol')} ${CentToString(price, 2)}`},
},
{
key: '2',
label: t('pay:attr.entity'),
children: {t(`payChannel::${entity}`)},
}
]}/>
{
execute(undefined, undefined, undefined, [
{
entity: 'pay',
operation: {
id: await generateNewIdAsync(),
action: 'update',
data: {
entity: 'offlineAccount',
entityId,
},
filter: {
id: props.data.oakId,
},
}
}
]);
}} updateExternalId={(externalId) => {
update({
externalId,
});
}}/>
{BtnPart2}
setShowSa(false)} onOk={() => succeed(sa)} width={580}>
{
setSa(date.valueOf());
}} value={dayJs(sa)}/>
>);
}
return null;
}