import React, { useEffect, useState } from 'react';
import { Card, Tag, List, Button, Modal, Form, Selector, Input, Popup, DatePicker } from 'antd-mobile';
import { QRCode, Alert } from 'antd';
import Styles from './web.mobile.module.less';
import dayJs from 'dayjs';
import duration from 'dayjs/plugin/duration';
dayJs.extend(duration);
import { CentToString } from 'oak-domain/lib/utils/money';
import { PayCircleOutline, GlobalOutline, InformationCircleOutline, CheckCircleOutline } from 'antd-mobile-icons';
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
export function RenderOffline(props) {
const { pay, t, offline, offlines, updateOfflineId, updateExternalId, mode } = props;
const { meta, iState, phantom3, externalId } = pay;
const { type, channel, name, qrCode, color } = offline || {};
const [show, setShow] = 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(
Modal.show({
content: ,
closeOnMaskClick: true,
})}>
);
}
}
items2.push({t('code.label')}}>
{phantom3}
, {t('externalId.label')}} help={iState === 'paying' && t('externalId.help')}>
{
updateExternalId(value);
}} placeholder={t('externalId.placeholder')} disabled={iState !== 'paying' && mode === 'frontend'}/>
);
return (<>
{
setShow(false);
}} onClose={() => {
setShow(false);
}} position='bottom' bodyStyle={{ padding: 18 }}>
({
label: t(`offlineAccount:v.type.${ele.type}`),
value: ele.id,
}))} value={offline ? [offline.id] : []} onChange={(arr) => {
updateOfflineId(arr[0]);
setShow(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' ? : null}
{['unpaid', 'paying'].includes(iState) && mode === 'backend' ? : null}
>);
}
return null;
}
case 'wpProduct': {
return ;
}
}
return null;
}
export default function Render(props) {
const { pay, iStateColor, notSameApp, type, startPayable, autoSuccessAt, succeedable, goBackable, oakExecutable, onClose, closable, offline, offlines, mode } = props.data;
const { t, update, execute, clean, goBack, startPay, succeed } = props.methods;
const [showSa, setShowSa] = useState(false);
if (pay) {
const { iState, price, entity } = pay;
const BtnPart2 = [];
if (succeedable) {
BtnPart2.push();
}
else if (startPayable) {
BtnPart2.push();
}
else if (oakExecutable === true) {
BtnPart2.push(
,
);
}
if (closable && BtnPart2.length < 2) {
BtnPart2.push();
}
if (goBackable && BtnPart2.length < 2) {
BtnPart2.push();
}
return (
{t(`pay:v.iState.${iState}`)}}>
} extra={t(`type.${type}`)}>
{t('type.label')}
} extra={CentToString(price, 2)}>
{t('pay:attr.price')}
} extra={t(`payChannel::${entity}`)}>
{t('pay:attr.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)} max={new Date()} onConfirm={val => succeed(val.valueOf())}/>
);
}
return null;
}