import React, { useState } from 'react';
import { Descriptions, Tag, Spin, Modal, Space, Flex, Button, Divider, Alert } from 'antd';
import { AlipayOutlined, WechatOutlined, ReloadOutlined } from '@ant-design/icons';
import Styles from './web.pc.module.less';
import { ThousandCont, ToYuan } from "oak-domain/lib/utils/money";
import { OfflineAccount as OADetail } from '../../offlineAccount/config/web.pc';
import { WpAccount as WADetail } from '../../wpAccount/config/web.pc';
import TransferList from '../transferList';
import SysAccountMoveCreate from '../../sysAccountMove/create';
import SysAccountOperList from '../../sysAccountOper/list';
import assert from 'assert';
function OfflineAccount(props) {
const { data, t } = props;
const { type, channel, color, name } = data;
switch (type) {
case 'bank': {
return (
{t('offlineAccount:name')}
{t(`offlineAccount:v.type.${type}`)}
{channel}
);
}
case 'alipay': {
return (
{t('offlineAccount:name')}
{name || t('qrCode')}
);
}
case 'wechat': {
return (
{t('offlineAccount:name')}
{name || t('qrCode')}
);
}
case 'shouqianba':
case 'others': {
return (
{t('offlineAccount:name')}
{t(`offlineAccount:v.type.${type}`)}
{name || t('qrCode')}
);
}
}
}
function WpAccount(props) {
const { data, t } = props;
return (
{t('wpAccount:name')}
);
}
function GeneralAccount(props) {
const { entity, t } = props;
return (
{t(`${entity}:name`)}
);
}
const RenderSysAccountCardTopDict = {
'offlineAccount': OfflineAccount,
'wpAccount': WpAccount,
};
const RenderSysAccountDetailDict = {
'offlineAccount': OADetail,
'wpAccount': WADetail,
};
export function registerSysAccountCardTopComponent(entity, component) {
assert(!RenderSysAccountCardTopDict[entity]);
RenderSysAccountCardTopDict[entity] = component;
}
export function registerSysAccountDetailComponent(entity, component) {
assert(!RenderSysAccountDetailDict[entity]);
RenderSysAccountDetailDict[entity] = component;
}
export default function render(props) {
const { accounts, total, systemId, accountNum, accountTotalSum, accountAvailSum, refundCnt, refundPriceSum, transferCnt, transferPriceSum, orderCnt, orderPaidSum, orderRefundSum, refreshing, } = props.data;
const { t, setMessage, refreshData } = props.methods;
if (accounts && systemId) {
const [showTransferList, setShowTransferList] = useState(false);
const [showMoveCreate, setShowMoveCreate] = useState(false);
const [showHistoryList, setShowHistoryList] = useState(false);
const [showHistoryAcc, setShowHistoryAcc] = useState(undefined);
return (
{t('common::pay.symbol')}
{ThousandCont(ToYuan(total || 0), 2)}
},
{
label: t('count'),
children: accounts.length,
}
]} column={2} extra={<>
} onClick={() => refreshData()}/>
setShowMoveCreate(false)} closeIcon={null} width={800} title={t('move')} footer={null}>
setShowMoveCreate(false)}/>
>}/>
{accounts.map(({ entity, data }, idx) => {
const TopRender = RenderSysAccountCardTopDict[entity];
assert(TopRender);
return (
{TopRender ? : }
{t('common::pay.symbol')}
{ThousandCont(ToYuan(data.price || 0), 2)}
{!!showHistoryAcc && showHistoryList &&
{
setShowHistoryAcc(undefined);
setShowHistoryList(false);
}} width={800} title={showHistoryAcc.entity === 'offlineAccount' ?
(showHistoryAcc.data.type === 'bank' ?
// @oak-ignore
`${t(`${showHistoryAcc.entity}:v.type.${showHistoryAcc.data.type}`)}-${showHistoryAcc.data.channel}-${t('history')}`
// @oak-ignore
: `${t(`${showHistoryAcc.entity}:v.type.${showHistoryAcc.data.type}`)}-${showHistoryAcc.data.name}-${t('history')}`
// @oak-ignore
) : `${t(`${showHistoryAcc.entity}:name`)}-${t('history')}`} footer={null}>
}
);
})}
{accountNum && } items={[
{
label: t('accountTotalSum'),
children:
{t('common::pay.symbol')}
{ThousandCont(ToYuan(accountTotalSum || 0), 2)}
},
{
label: t('accountAvailSum'),
children:
{t('common::pay.symbol')}
{ThousandCont(ToYuan(accountAvailSum || 0), 2)}
},
{
label: t('accountNum'),
children: {accountNum || 0},
},
{
label: t('refundCnt'),
children: {refundCnt || 0}
},
{
label: t('refundPriceSum'),
span: 2,
children: (
{t('common::pay.symbol')}
{ThousandCont(ToYuan(refundPriceSum || 0), 2)}
)
},
{
label: t('transferCnt'),
children: {transferCnt || 0}
},
{
label: t('transferPriceSum'),
span: 2,
children: (
{t('common::pay.symbol')}
{ThousandCont(ToYuan(transferPriceSum || 0), 2)}
setShowTransferList(false)} footer={null} closeIcon={null} width={800}>
)
},
{
label: t('orderCnt'),
children: {orderCnt || 0}
},
{
label: t('orderPriceSum'),
children: (
{t('common::pay.symbol')}
{ThousandCont(ToYuan((orderPaidSum || 0) - (orderRefundSum || 0)), 2)}
)
}
]} column={3}/>}
);
}
return null;
}