From 9866a439ce32c744af0c1c11fe457bc0778faeaa Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 11 Jan 2024 15:07:50 +0800 Subject: [PATCH] gen xml with selected ids --- src/pages/DemandNote/Create/SearchForm.js | 7 +- src/pages/DemandNote/Search/DataGrid.js | 81 ++++++++++++++++++++++- src/pages/DemandNote/Search/index.js | 33 +-------- src/utils/HttpUtils.js | 67 ++++++++++++------- 4 files changed, 130 insertions(+), 58 deletions(-) diff --git a/src/pages/DemandNote/Create/SearchForm.js b/src/pages/DemandNote/Create/SearchForm.js index 6b46abd..339e8c9 100644 --- a/src/pages/DemandNote/Create/SearchForm.js +++ b/src/pages/DemandNote/Create/SearchForm.js @@ -27,6 +27,7 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p const [isSuccessPopUp, setIsSuccessPopUp] = React.useState(false); const [resultCount, setResultCount] = React.useState(0); + const [dnIdList, setDnIdList] = React.useState([]); const [issueSelected, setIssueSelected] = React.useState({}); const [paymentCount, setPaymentCount] = React.useState(0); @@ -86,6 +87,7 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p url: UrlUtils.DEMAND_NOTE_CREATE + "/" + issueSelected.id, onSuccess: function (responseData) { setResultCount(responseData.count); + setDnIdList(responseData.idList); setIsSuccessPopUp(true); } }); @@ -95,9 +97,10 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p const fileDownload = () => { HttpUtils.fileDownload({ + method:'post', url: UrlUtils.DEMAND_NOTE_EXPORT, params: { - "issueId": issueSelected.id + "dnIdList": dnIdList }, onSuccess: function () { notifyDownloadSuccess(); @@ -219,7 +222,7 @@ const SearchPublicNoticeForm = ({ applySearch, issueComboData, _paymentCount, _p + + + +
+ setSelectonWarning(false)} > + Warning + + Please Select DN. + + + + + +
setConfirmPopUp(false)} > Confirm @@ -292,6 +362,13 @@ export default function SearchDemandNote({ recordList, reloadFun, exportXmlFun }
+
+ setWait(false)} > + + Calculating, please wait ... + + +
); } diff --git a/src/pages/DemandNote/Search/index.js b/src/pages/DemandNote/Search/index.js index cbe9141..c8f15f6 100644 --- a/src/pages/DemandNote/Search/index.js +++ b/src/pages/DemandNote/Search/index.js @@ -3,8 +3,6 @@ import { Grid, Typography, Stack, - Button, - Dialog, DialogTitle, DialogContent, DialogActions, } from '@mui/material'; import MainCard from "components/MainCard"; @@ -18,7 +16,7 @@ const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/Loa const SearchForm = Loadable(React.lazy(() => import('./SearchForm'))); const EventTable = Loadable(React.lazy(() => import('./DataGrid'))); import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' -import { notifyDownloadSuccess } from 'utils/CommonFunction'; + const BackgroundHead = { backgroundImage: `url(${titleBackgroundImg})`, @@ -34,8 +32,6 @@ const BackgroundHead = { const UserSearchPage_Individual = () => { - const [isErrorPopUp, setIsErrorPopUp] = React.useState(false); - const [record, setRecord] = React.useState([]); const [orgCombo, setOrgCombo] = React.useState([]); const [issueCombo, setIssueCombo] = React.useState([]); @@ -69,20 +65,6 @@ const UserSearchPage_Individual = () => { }); } - function exportXml() { - if (record.length >= 100) { - setIsErrorPopUp(true); - return; - } - HttpUtils.fileDownload({ - url: UrlUtils.DEMAND_NOTE_EXPORT, - params: searchCriteria, - onSuccess: function () { - notifyDownloadSuccess(); - } - }); - } - function getOrgCombo() { HttpUtils.get({ url: UrlUtils.GET_ORG_COMBO, @@ -140,21 +122,10 @@ const UserSearchPage_Individual = () => {
-
- setIsErrorPopUp(false)} > - Action Fail - - Number of DN record must less than 100.
Please edit search form.
-
- - - -
-
+ ); } diff --git a/src/utils/HttpUtils.js b/src/utils/HttpUtils.js index 1ab55ba..4c87c38 100644 --- a/src/utils/HttpUtils.js +++ b/src/utils/HttpUtils.js @@ -58,35 +58,56 @@ export const postWithFiles = ({url, params, files, onSuccess, onFail, onError}) }); }; -export const fileDownload = ({url, fileId, skey, filename, onResponse, onError}) =>{ +export const fileDownload = ({url, fileId, skey, filename, params, method, onResponse, onError}) =>{ if(!url){ url = FILE_DOWN_GET+"/"+fileId+"/"+skey+"/"+filename } - axios.get( url, - { - responseType: 'blob', - } - ).then( - (response)=>{ - const fn = response.headers.get("content-disposition")?.split("filename=")[1]?.split('"')[1]?.trim()??filename; - const url = URL.createObjectURL(response.data); - const a = document.createElement('a'); - a.href = url; - a.setAttribute("download", fn); - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); - if(onResponse){ - onResponse(); + if(method == 'post'){ + axios.post( url, params, + { + responseType: 'blob', + headers:{ + "Content-Type":"application/json" + } } - } - ).catch(error => { - return handleError(error,onError); - }); -}; + ).then( + (response)=>{ + fileDownloadResponse(response, onResponse) + } + ).catch(error => { + return handleError(error,onError); + }); + }else{ + axios.get( url, + { + responseType: 'blob', + params:params + } + ).then( + (response)=>{ + fileDownloadResponse(response, onResponse) + } + ).catch(error => { + return handleError(error,onError); + }); + } +}; +const fileDownloadResponse=(response, onResponse)=>{ + const fn = response.headers.get("content-disposition")?.split("filename=")[1]?.split('"')[1]?.trim()??filename; + const url = URL.createObjectURL(response.data); + const a = document.createElement('a'); + a.href = url; + a.setAttribute("download", fn); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + if(onResponse){ + onResponse(); + } +} export const fileUpload = ({refType, refId, files, refCode, onSuccess, onFail, onError}) =>{ postWithFiles({