🚀 feat: update confirm bill type batch

This commit is contained in:
LittleBoy 2024-08-10 18:03:16 +08:00
parent b16d6a237d
commit f4ffe77486
7 changed files with 75 additions and 17 deletions

View File

@ -17,6 +17,7 @@ type BillListProps = {
operationRender?: (record: BillModel) => React.ReactNode;
operationRenderWidth?: number;
onRowSelection?: (selectedRowKeys: (string | number)[]) => void;
rowSelectionDisabled?: (record: BillModel) => boolean;
source?: RecordList<BillModel>;
onPageChange: (pageIndex: number) => void;
tableFooter?: React.ReactNode;
@ -368,6 +369,14 @@ export const BillList: React.FC<BillListProps> = (props) => {
fixed: true,
onChange: (selectedRowKeys) => {
selectedRowKeys && props.onRowSelection?.(selectedRowKeys)
},
getCheckboxProps: (record) => {
if(props.rowSelectionDisabled){
return {
disabled: props.rowSelectionDisabled?.(record)
}
}
return {}
}
} : undefined}
/>

View File

@ -6,6 +6,7 @@
"cancel": "Cancel",
"close": "Close",
"confirm": "Confirm",
"confirm_next_operation": "Please confirm this operation",
"confirm_paid": "Confirm paid",
"operate_fail": "Operation failed",
"operate_success": "Operation success",

View File

@ -6,6 +6,7 @@
"cancel": "取消",
"close": "关闭",
"confirm": "确定",
"confirm_next_operation": "请确认是否进行此操作",
"confirm_paid": "确认已支付",
"operate_fail": "操作失败",
"operate_success": "操作成功",

View File

@ -6,6 +6,7 @@
"cancel": "取消",
"close": "關閉",
"confirm": "確定",
"confirm_next_operation": "請確認是否進行此操作",
"confirm_paid": "確認已支付",
"operate_fail": "操作失敗",
"operate_success": "操作成功",

View File

@ -1,5 +1,5 @@
import {Button, Select, Space, Divider, InputNumber, Modal,} from "@douyinfe/semi-ui";
import React from "react";
import React, {useEffect} from "react";
import {useSetState} from "ahooks";
import MoneyFormat from "@/components/money-format.tsx";
import {useTranslation} from "react-i18next";
@ -21,7 +21,7 @@ export const BillTypeConfirm: React.FC<BillTypeConfirmProps> = (props) => {
const confirmed: ConfirmedBillDetail[] = props.bill.details.map(it=>({
bill_type: it.bill_type,
bill_detail_id: it.id,
amount: it.amount
amount: Number(it.amount)
}))
const [state, setState] = useSetState({
confirm_application_number: '', confirmed
@ -49,6 +49,9 @@ export const BillTypeConfirm: React.FC<BillTypeConfirmProps> = (props) => {
setState({confirmed})
props.onChange?.(confirmed)
}
useEffect(()=>{
props.onChange?.(confirmed)
},[])

View File

@ -0,0 +1,52 @@
import React from "react";
import {Button, Popconfirm} from "@douyinfe/semi-ui";
import {useTranslation} from "react-i18next";
import {confirmBillType} from "@/service/api/bill.ts";
import {useSetState} from "ahooks";
type BillTypeConfirmBatchProps = {
selectKeys: number[];
data?: RecordList<BillModel>;
onConfirm: () => void;
}
export const BillTypeConfirmBatch: React.FC<BillTypeConfirmBatchProps> = (props) => {
const {t} = useTranslation()
const [state, setState] = useSetState({loading: false})
const confirm = (confirmedBills: BillConfirmParams[]) => {
confirmBillType(confirmedBills).then(() => {
props.onConfirm()
}).finally(() => {
setState({loading: false})
})
}
const confirmBillTypeBatch = () => {
const bills: BillConfirmParams[] = [];
props.data?.list.filter(item => props.selectKeys.includes(item.id)).forEach(item => {
bills.push({
id: item.id,
confirm_application_number: String(item.application_number),
confirm_student_number: item.student_number,
detail_confirms: item.details.map(d => {
return {
bill_type: d.bill_type,
bill_detail_id: d.id,
amount: d.amount
}
})
})
})
if (bills.length == 0) return;
confirm(bills)
}
return (<>
{props.selectKeys.length == 0 || !props.data || props.data.list.length == 0 ?
<Button disabled>{t('bill.confirm_bill_type_batch')}</Button> :
<Popconfirm
title={'Warning'}
content={`${t('base.confirm_next_operation')}?`}
onConfirm={() => confirmBillTypeBatch()}
>
<Button loading={state.loading} theme={'solid'}>{t('bill.confirm_bill_type_batch')}</Button>
</Popconfirm>}
</>)
}

View File

@ -13,6 +13,7 @@ import {BillPaidModal} from "@/pages/bill/components/bill_paid_modal.tsx";
import {BillTypeConfirmModal} from "@/pages/bill/components/bill_type_confirm.tsx";
import {saveAs} from "file-saver";
import {AddBillModal} from "@/pages/bill/components/add_bill_modal.tsx";
import {BillTypeConfirmBatch} from "@/pages/bill/components/bill_type_confirm_batch.tsx";
const DownloadButton = ({bill, text}: { bill: BillModel; text: string }) => {
@ -108,10 +109,8 @@ const BillQuery = () => {
const onImportExcel = () => {
Toast.warning({content: 'Not implemented'})
}
const [selectKeys, setSelectedKeys] = useState<(string | number)[]>([])
const confirmBillTypeBatch = () => {
console.log(selectKeys)
}
const [selectKeys, setSelectedKeys] = useState<number[]>([])
const onBillConfirm = (reload?: boolean) => {
setState({confirmBill: undefined})
@ -124,16 +123,7 @@ const BillQuery = () => {
type={'query'} loading={loading} source={data}
operationRender={operation} operationRenderWidth={180}
beforeTotalAmount={<Space>
{
(selectKeys.length == 0) ? <Button disabled>{t('bill.confirm_bill_type_batch')}</Button> :
<Popconfirm
title={'Notice'}
content={`${t('bill.cancel_confirm_bills')}?`}
onConfirm={() => confirmBillTypeBatch()}
>
<Button theme={'solid'}>{t('bill.confirm_bill_type_batch')}</Button>
</Popconfirm>
}
<BillTypeConfirmBatch data={data} selectKeys={selectKeys} onConfirm={refresh}/>
<AddBillModal onConfirm={refresh}/>
<ButtonGroup style={{marginRight: 20}} theme={'solid'}>
<Button onClick={onImportExcel}>{t('bill.import_excel')}</Button>
@ -141,7 +131,8 @@ const BillQuery = () => {
</ButtonGroup>
</Space>}
onRowSelection={setSelectedKeys}
onRowSelection={(keys)=>setSelectedKeys(keys as number[])}
rowSelectionDisabled={(r)=>(r.status != BillStatus.PAID || r.confirm_status == 'CONFIRMED')}
onPageChange={(page_number) => {
setBillQueryParams({
...queryParams,