import { BasicColumn, DescItem, formatCell, FormSchema, UseFormReturnType } from '@eciol/ant-ui'; import { useGo } from '@eciol/hooks'; import { dateFn, formatDateTime, formatUtcDateTime, resolveOptions, useGlobSetting, } from '@eciol/shared'; import { getFileListApi, getInvoiceInfo, uploadApi } from '@/api'; import { useUserStore } from '@/store'; import { Attachment } from '../../components'; export const useInvoice = () => { const { getDict, getDictMap } = useUserStore(); const { uploadUrl } = useGlobSetting(); const go = useGo(); const invoiceList = ref([]); const noInvoice = ref(false); const schemas: FormSchema[] = [ { field: 'buyerName', component: 'Input', label: '购买方名称', componentProps: { disabled: true, }, }, { field: 'buyerNsrsbh', component: 'Input', label: '购买方纳税人识别号', componentProps: { disabled: true, }, }, { field: 'buyerAddr', component: 'Input', label: '购买方地址', componentProps: { disabled: true, }, }, { field: 'buyerPhone', component: 'Input', label: '购买方电话', componentProps: { disabled: true, }, }, { field: 'buyerBank', component: 'Input', label: '购买方开户行', componentProps: { disabled: true, }, }, { field: 'buyerAct', component: 'Input', label: '购买方账号', componentProps: { disabled: true, }, }, { field: 'sellerName', component: 'Input', label: '销售方名称', componentProps: { disabled: true, }, }, { field: 'sellerNsrsbh', component: 'Input', label: '销售方纳税人识别号', required: true, componentProps: {}, }, { field: 'sellerAddr', component: 'Input', label: '销售方地址', required: true, componentProps: {}, }, { field: 'sellerPhone', component: 'Input', label: '销售方电话', required: true, componentProps: {}, }, { field: 'sellerBank', component: 'Input', label: '销售方开户行', componentProps: {}, }, { field: 'sellerAct', component: 'Input', label: '销售方账号', componentProps: {}, }, ]; const invoiceSchemas: FormSchema[] = [ { field: 'totalAmount', component: 'InputNumber', label: '发票金额', required: true, componentProps: { allowClear: true, controls: false, precision: 4, }, }, { field: 'vatType', component: 'Select', label: '发票类别', required: true, componentProps: { options: getDict.InvoiceType, }, }, { field: 'fpdm', component: 'Input', label: '发票代码', componentProps: {}, }, { field: 'fphm', component: 'Input', label: '发票号码', required: true, componentProps: {}, }, { field: 'billingOn', component: 'DatePicker', label: '开票日期', required: true, componentProps: { allowClear: true, format: 'YYYY-MM-DD', valueFormat: 'YYYY-MM-DD HH:mm:ss', }, format: 'toUtcDate', }, { field: 'invoiceFileId', component: 'FileUpload', valueField: 'fileId', label: '收款凭证附件', helpMessage: '上传发票后其他发票信息会自动识别并填写', required: true, componentProps({ formModel, values }) { return { async onChange(fileId = '') { const { vatType, code, number, date, details } = await getInvoiceInfo({ fileId, ids: values.ids, }); if (!number) { return; } formModel.vatType = vatType || undefined; formModel.totalAmount = 0; formModel.fpdm = code; formModel.fphm = number; formModel.billingOn = formatUtcDateTime({ date: date ? dateFn(date, 'YYYY年MM月DD日') : '', isSubmit: true, }); invoiceList.value[values.index].service = (details ?? []).map((item) => ({ serviceName: item.name, quantity: item.count, unit: item.unit, taxRate: item.taxRate, taxAmount: item.taxAmount, amount: item.amount, unitPrice: item.price, editable: true, })); }, // onDelete() { // formModel.vatType = undefined; // formModel.totalAmount = 0; // formModel.fpdm = undefined; // formModel.fphm = undefined; // formModel.billingOn = ''; // invoiceList.value[values.index].service = []; // }, }; }, }, ]; const invoiceDetailDescSchemas: DescItem[] = [ { field: 'buyerName', label: '购买方名称', }, { field: 'buyerNsrsbh', label: '购买方纳税人识别号', }, { field: 'buyerAddr', label: '购买方地址', }, { field: 'buyerPhone', label: '购买方电话', }, { field: 'buyerBank', label: '购买方开户行', }, { field: 'buyerAct', label: '购买方账号', }, { field: 'sellerName', label: '销售方名称', }, { field: 'sellerNsrsbh', label: '销售方纳税人识别号', }, { field: 'sellerAddr', label: '销售方地址', }, { field: 'sellerPhone', label: '销售方电话', }, { field: 'sellerBank', label: '销售方开户行', }, { field: 'sellerAct', label: '销售方账号', }, ]; const invoiceDetailItemDesc: DescItem[] = [ { field: 'totalAmount', label: '发票金额', render: 'amount|digits=4&separator=,&spaceNumber=3', }, { field: 'offsetAmount', label: '关联金额', render: 'amount|digits=4&separator=,&spaceNumber=3', }, { field: 'fpdm', label: '发票代码', }, { field: 'fphm', label: '发票号码', }, { field: 'vatType', label: '发票类别', render(val) { return getDictMap.InvoiceType[val] ?? ''; }, }, { field: 'billingOn', label: '开票日期', render: 'utcDate|YYYY-MM-DD', }, { field: 'invoiceFileId', label: '收款凭证附件', render: (_val, record) => { return h( , ); }, }, ]; const invoiceDetailColumns: BasicColumn[] = [ { title: '服务名称', dataIndex: 'serviceName', }, { title: '单位', dataIndex: 'unit', format(text) { return getDictMap.InvoiceUnit[text]; }, }, { title: '数量', dataIndex: 'quantity', format: 'amount|digits=4&separator=,&spaceNumber=3', }, { title: '单价', dataIndex: 'unitPrice', format: 'amount|digits=4&separator=,&spaceNumber=3', }, { title: '金额', dataIndex: 'taxAmount', format: 'amount|digits=4&separator=,&spaceNumber=3', }, { title: '税率', dataIndex: 'taxRate', format(text) { return Number(text) * 100 + '%'; }, }, { title: '税额', dataIndex: 'taxAmount', format: 'amount|digits=4&separator=,&spaceNumber=3', }, ]; const payApplyColumns: BasicColumn[] = [ { title: '付款申请单编号', dataIndex: 'billNo', }, { title: '付款申请单类型', dataIndex: 'billTypeName', }, { title: '单据状态', dataIndex: 'billStatusName', }, { title: '供应商编号', dataIndex: 'supplierNo', }, { title: '供应商', dataIndex: 'supplierName', }, { title: '供应商开票名头', dataIndex: 'supplierBillingName', }, { title: '供应商支付渠道', dataIndex: 'supplierBillingTypeName', }, { title: '付款方式', dataIndex: 'paymentMethodName', }, { title: '支付周期', dataIndex: 'paymentCycleName', }, { title: '币别', dataIndex: 'currencyName', }, { title: '价税合计', dataIndex: 'totalAmount', format: 'amount|digits=4&separator=,&spaceNumber=3', }, ]; const invoiceColumns: BasicColumn[] = [ { title: '服务名称', dataIndex: 'serviceName', editable: true, editRow: true, editRule: true, editComponent: 'Input', editComponentProps: {}, }, { title: '单位', dataIndex: 'unit', editable: true, editRow: true, editRule: true, editComponent: 'Select', editComponentProps: { options: getDict.InvoiceUnit, }, }, { title: '数量', dataIndex: 'quantity', editRow: true, editRule: true, editComponent: 'InputNumber', editComponentProps: { controls: false, precision: 4, }, editRender: ({ text, record, index, column }) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return formatCell(text as string, column.format!, record, index); }, format: 'amount|digits=4&separator=,&spaceNumber=3', }, { title: '单价', dataIndex: 'unitPrice', editable: true, editRow: true, editRule: true, editComponent: 'InputNumber', editComponentProps: { controls: false, precision: 10, }, editRender: ({ text, record, index, column }) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return formatCell(text as string, column.format!, record, index); }, format: 'amount|digits=10&separator=,&spaceNumber=3', }, { title: '金额', dataIndex: 'amount', editable: true, editRow: true, editRule: true, editComponent: 'InputNumber', editComponentProps: { controls: false, precision: 2, }, editRender: ({ text, record, index, column }) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return formatCell(text as string, column.format!, record, index); }, format: 'amount|digits=2&separator=,&spaceNumber=3', }, { title: '税率', dataIndex: 'taxRate', editable: true, editRow: true, editRule: true, editComponent: 'Select', editComponentProps: { options: resolveOptions(getDict.InvoiceTax, { labelField: 'label', valueField: 'value', }), }, }, { title: '税额', dataIndex: 'taxAmount', editable: true, editRow: true, editRule: true, editComponent: 'InputNumber', editComponentProps: { controls: false, precision: 2, }, editRender: ({ text, record, index, column }) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return formatCell(text as string, column.format!, record, index); }, format: 'amount|digits=2&separator=,&spaceNumber=3', }, ]; const invoiceActionColumns: BasicColumn = { title: '操作', dataIndex: 'operation', width: 50, align: 'left', }; function goDetail(id) { go({ path: '/payment-manage/application/detail', query: { id }, }); } interface TabsFormType { index: number; Form: UseFormReturnType; } const tabsFormSchema = ref([]); return { invoiceList, schemas, noInvoice, payApplyColumns, invoiceDetailDescSchemas, invoiceSchemas, invoiceDetailItemDesc, invoiceDetailColumns, goDetail, tabsFormSchema, invoiceColumns, invoiceActionColumns, }; };