From 895c0325326cc6aa54f18d7d97c1fb30f783bc15 Mon Sep 17 00:00:00 2001 From: callmeyan Date: Sun, 28 Jul 2024 18:50:47 +0800 Subject: [PATCH] feat:sort is now available --- src/components/bill/search-form.tsx | 13 +++++++--- src/pages/bill/query.tsx | 38 ++++++++++++++--------------- src/types/bill.d.ts | 3 +++ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/components/bill/search-form.tsx b/src/components/bill/search-form.tsx index 60b0b09..498950f 100644 --- a/src/components/bill/search-form.tsx +++ b/src/components/bill/search-form.tsx @@ -21,6 +21,7 @@ type SearchFormFields = { payment_channel?: string; bill_status?: string; apply_status?: string; + sort_by?: string; } const SearchForm: React.FC = (props) => { const formSubmit = (value: SearchFormFields) => { @@ -54,6 +55,12 @@ const SearchForm: React.FC = (props) => { if (value.payment_channel) { params.payment_channel = value.payment_channel; } + // 排序 + if(value.sort_by){ + const [field, order] = value.sort_by.split(' ') + params.sort_field = field + params.sort_order = order?.toUpperCase() || 'DESC' + } props.onSearch?.(params); } const {t, i18n} = useTranslation(); @@ -102,14 +109,14 @@ const SearchForm: React.FC = (props) => { - ID {t('bill.sort_desc')} ID {t('bill.sort_asc')} {t('base.student_number')} {t('bill.sort_desc')} {t('base.student_number')} {t('bill.sort_asc')} - {t('base.bill_number')} {t('bill.sort_desc')} - {t('base.bill_number')} {t('bill.sort_asc')} + {t('base.bill_number')} {t('bill.sort_desc')} + {t('base.bill_number')} {t('bill.sort_asc')} {t('bill.title_paid_at')} {t('bill.sort_desc')} {t('bill.title_paid_at')} {t('bill.sort_asc')} diff --git a/src/pages/bill/query.tsx b/src/pages/bill/query.tsx index aca0554..3b5401e 100644 --- a/src/pages/bill/query.tsx +++ b/src/pages/bill/query.tsx @@ -25,18 +25,16 @@ const DownloadButton = ({bill, text}: { bill: BillModel; text: string }) => { // } const BillQuery = () => { - const {user} = useAuth(); const [state, setState] = useSetState<{ updateBill?: BillModel updateLoading?: boolean confirmBill?: BillModel }>({}) const [showBill, setShowBill] = useState() - const [queryParams, setBillQueryParams] = useState({}); - const {data, loading, refresh} = useRequest(() => billList({ - ...queryParams, - department: user?.department == 'RO' ? 'RO' : 'FO', - }), { + const [queryParams, setBillQueryParams] = useState({ + sort_field: 'id', sort_order: 'DESC' + }); + const {data, loading, refresh} = useRequest(() => billList(queryParams), { refreshDeps: [queryParams], onError: (e) => { Notification.error({title: 'Error', content: e.message}) @@ -156,21 +154,23 @@ const BillQuery = () => { > {state.confirmBill && <>
-
+
{ - state.confirmBill.details.map((it, idx) => (
- - {it.id}. - {it.bill_type} -
- -
-
-
- {!!it.confirm_status ? CONFIRMED:} + state.confirmBill.details.map((it, idx) => ( +
+ + {it.id}. + {it.bill_type} +
+ +
+
+
+ {!!it.confirm_status ? CONFIRMED : + } -
-
)) +
+
)) }
} diff --git a/src/types/bill.d.ts b/src/types/bill.d.ts index b119cc5..e709818 100644 --- a/src/types/bill.d.ts +++ b/src/types/bill.d.ts @@ -15,6 +15,7 @@ declare type BillDetail = { confirm_status?: number; amount: decimal; } +declare type SortOrderType = 'ASC'|'DESC' | string; /** * 账单查询参数 */ @@ -30,6 +31,8 @@ declare type BillQueryParam = { start_date:string; end_date:string; department:string; + sort_field:string; + sort_order:SortOrderType; } /** * 账单模型