perf: 产品管理: 导出按钮
parent
45aa339fc6
commit
4ba8751a77
@ -0,0 +1,59 @@
|
||||
import { Button } from 'antd';
|
||||
import { useProductsAuditStatesMapVal } from '@/hooks/useProductsSets';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import useProductsStore, { getAgencyAllExtrasAction } from '@/stores/Products/Index';
|
||||
import RequireAuth from '@/components/RequireAuth';
|
||||
import { PERM_PRODUCTS_OFFER_AUDIT } from '@/config';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import AgencyContract from '../Print/AgencyContract';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { Packer } from 'docx';
|
||||
import { isEmpty } from '@/utils/commons';
|
||||
|
||||
const ExportDocxBtn = ({ params = { travel_agency_id: '', use_year: '', audit_state: '' }, ...props }) => {
|
||||
const { t } = useTranslation();
|
||||
const [agencyProducts] = useProductsStore((state) => [state.agencyProducts]);
|
||||
const [activeAgency] = useProductsStore((state) => [state.activeAgency]);
|
||||
const { travel_agency_id, use_year, audit_state } = params;
|
||||
|
||||
const auditStatesMap = useProductsAuditStatesMapVal();
|
||||
|
||||
const { getRemarkList } = useProductsStore((selector) => ({
|
||||
getRemarkList: selector.getRemarkList,
|
||||
}));
|
||||
const handleDownload = async () => {
|
||||
// await refresh();
|
||||
const agencyExtras = await getAgencyAllExtrasAction(params);
|
||||
const remarks = await getRemarkList();
|
||||
const remarksMappedByType = remarks.reduce((r, v) => ({ ...r, [v.product_type_id]: v }), {});
|
||||
const documentCreator = new AgencyContract();
|
||||
const doc = documentCreator.create([
|
||||
params,
|
||||
activeAgency,
|
||||
agencyProducts,
|
||||
agencyExtras,
|
||||
// remarks,
|
||||
remarksMappedByType,
|
||||
]);
|
||||
|
||||
const _d = dayjs().format('YYYYMMDD_HH.mm.ss.SSS'); // Date.now().toString(32)
|
||||
// console.log(params);
|
||||
const _state = isEmpty(audit_state) ? '' : auditStatesMap[audit_state].label;
|
||||
Packer.toBlob(doc).then((blob) => {
|
||||
saveAs(blob, `${activeAgency.travel_agency_name}${use_year}年地接合同-${_state}-${_d}.docx`);
|
||||
});
|
||||
};
|
||||
return (
|
||||
<>
|
||||
{/* todo: export, 审核完成之后才能导出 */}
|
||||
<RequireAuth subject={PERM_PRODUCTS_OFFER_AUDIT}>
|
||||
<Button size='small' onClick={handleDownload}>
|
||||
{t('Export')} .docx
|
||||
</Button>
|
||||
{/* <PrintContractPDF /> */}
|
||||
</RequireAuth>
|
||||
</>
|
||||
);
|
||||
};
|
||||
export default ExportDocxBtn;
|
Loading…
Reference in New Issue