import React, { useState } from 'react';
import { Button, Modal, Alert, Descriptions, QRCode } from 'antd';
import { PlusCircleOutlined } from '@ant-design/icons';
import Styles from './web.pc.module.less';
import Upsert from '../upsert';
import { OakAttrNotNullException, OakException } from 'oak-domain/lib/types';
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { ToYuan } from 'oak-domain/lib/utils/money';
export function OfflineAccount(props) {
const { data: account, t, onUpdate, onRemove, onQrCodeClick } = props;
const { type, channel, name, qrCode, allowDeposit, allowPay, color, enabled, price, taxLossRatio, refundCompensateRatio, refundGapDays, allowWithdrawTransfer, withdrawTransferLossRatio } = account;
return (
{onUpdate && }
{onRemove && }
>} column={1} bordered size="small" labelStyle={{ width: 198 }}>
{t(`offlineAccount:v.type.${type}`)}
{channel && {channel}}
{name && {name}}
{qrCode &&
{type === 'bank' ? qrCode : }
}
{ToYuan(price)}{t('common::pay.scale')}
{t(`common::${allowPay}`)}
{t(`common::${enabled}`)}
{taxLossRatio}%
{refundCompensateRatio}%
{refundGapDays}
{taxLossRatio}%
{t(`common::${allowWithdrawTransfer}`)}
{withdrawTransferLossRatio}%
);
}
export default function render(props) {
const { accounts, oakFullpath, oakExecutable, systemId, canCreate } = props.data;
const { t, addItem, execute, clean } = props.methods;
const [upsertId, setUpsertId] = useState('');
const getNotNullMessage = (attr) => {
if (['channel', 'name', 'qrCode'].includes(attr)) {
const upsertRow = accounts?.find(ele => ele.id === upsertId);
// @oak-ignore
return t('notnull', { value: t(`offlineAccount::label.${attr}.${upsertRow.type}`) });
}
// @oak-ignore
return t('notnull', { value: t(`offlineAccount:attr.${attr}`) });
};
const errMsg = oakExecutable instanceof OakException && (
// @oak-ignore
oakExecutable instanceof OakAttrNotNullException ? getNotNullMessage(oakExecutable.getAttributes()[0]) : t(oakExecutable.message));
const U = ( {
clean();
setUpsertId('');
}} closeIcon={null} onOk={async () => {
await execute();
setUpsertId('');
}} okButtonProps={{
disabled: oakExecutable !== true,
}} okText={t('common::confirm')} cancelText={(t('common::action.cancel'))}>
);
const [showQrCodeId, setShowQrCodeId] = useState('');
const showQrCodeRow = showQrCodeId ? accounts.find(ele => ele.id === showQrCodeId) : undefined;
if (accounts && accounts.length > 0) {
return (
{U}
{accounts.filter(ele => ele.$$createAt$$ > 1).map((ele, idx) =>
{
Modal.confirm({
title: t('confirmDelete'),
content: t('areYouSure'),
onOk: async () => execute(undefined, undefined, undefined, [
{
entity: 'offlineAccount',
operation: {
id: await generateNewIdAsync(),
action: 'remove',
data: {},
filter: {
id: ele.id,
},
}
}
]),
});
} : undefined} onUpdate={ele['#oakLegalActions']?.includes('update') ? () => setUpsertId(ele.id) : undefined} onQrCodeClick={() => setShowQrCodeId(ele.id)}/>
)}
{canCreate && }
{showQrCodeRow && setShowQrCodeId('')}>
}
);
}
return (
{U}
{canCreate ?
{
const id = addItem({ systemId });
setUpsertId(id);
}}/> : t('noData')}
);
}