From 3544419d115c41a474cd4f7c7708d6eb035dba73 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Mon, 22 Jul 2024 10:44:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SearchForm=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=97=B6=E9=97=B4=20onMounted=EF=BC=8C=E8=A7=A3=E5=86=B3=20Vie?= =?UTF-8?q?w=20=E8=8E=B7=E5=8F=96=E5=88=9D=E5=A7=8B=E5=80=BC=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SearchForm.jsx | 10 +++++++-- src/views/reservation/Newest.jsx | 38 +++++++++++++------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx index 89b79b9..54174ff 100644 --- a/src/components/SearchForm.jsx +++ b/src/components/SearchForm.jsx @@ -15,7 +15,7 @@ import VendorSelector from '@/components/VendorSelector'; const { RangePicker } = DatePicker; -const SearchForm = ({ initialValue, onSubmit, onReset, confirmText, formName, formLayout, loading, ...props }) => { +const SearchForm = ({ initialValue, onSubmit, onReset, onMounted, confirmText, formName, formLayout, loading, ...props }) => { const { t } = useTranslation(); const presets = useDatePresets(); const [formValues, setFormValues] = useFormStore((state) => [state.formValues, state.setFormValues]); @@ -89,8 +89,14 @@ const SearchForm = ({ initialValue, onSubmit, onReset, confirmText, formName, fo }; useEffect(() => { - const dest = formValuesMapper(formValues); + setFormValues(readValues); + const dest = formValuesMapper(readValues); setFormValuesToSub(dest); + + if (typeof onMounted === 'function') { + onMounted(dest) + } + return () => {}; }, []); diff --git a/src/views/reservation/Newest.jsx b/src/views/reservation/Newest.jsx index 9a02816..c6e4279 100644 --- a/src/views/reservation/Newest.jsx +++ b/src/views/reservation/Newest.jsx @@ -96,7 +96,6 @@ function Newest() { const [guideSelectOptions, setGuideSelectOptions] = useState([]) const formValuesToSub = useFormStore((state) => state.formValuesToSub) - const [fetchAllGuideList, fetchReservationList, reservationList, reservationPage, cityList, selectReservation, getCityListByReservationId, setupCityGuide, updateReservationGuide] = useReservationStore((state) => [state.fetchAllGuideList, state.fetchReservationList, state.reservationList, state.reservationPage, state.cityList, state.selectReservation, state.getCityListByReservationId, state.setupCityGuide, state.updateReservationGuide]) @@ -104,13 +103,9 @@ function Newest() { const { notification } = App.useApp() useEffect (() => { - if (location.search !== '?back') { - // 第一页,未确认计划 - onSearchClick(1, 1) - } fetchAllGuideList() .then((guideList) => { - const selectOptions = guideList.map((data, index) => { + const selectOptions = guideList.map((data) => { return { value: data.guideId, label: data.guideName @@ -137,6 +132,7 @@ function Newest() { setDataLoading(false); }) } + const handleOk = () => { updateReservationGuide() .finally(() => { @@ -144,15 +140,18 @@ function Newest() { setDataLoading(false); }) } + const handleCancel = () => { setIsModalOpen(false); setDataLoading(false); } // 默认重新搜索第一页,所有状态的计划 - const onSearchClick = (current=1, status=null) => { + const searchReservation = (submitValues, current=1) => { setDataLoading(true) - fetchReservationList(formValuesToSub, current) + console.info('onSearchClick') + console.info(submitValues) + fetchReservationList(submitValues, current) .catch(ex => { notification.error({ message: `Notification`, @@ -208,20 +207,11 @@ function Newest() { dates: { label: t('group:ArrivalDate') }, }, }} - onSubmit={(err, formVal, filedsVal) => { - setDataLoading(true) - fetchReservationList(formVal) - .catch(ex => { - notification.error({ - message: 'Notification', - description: ex.message, - placement: 'top', - duration: 4, - }) - }) - .finally(() => { - setDataLoading(false) - }) + onMounted={(initialValue) => { + searchReservation(initialValue) + }} + onSubmit={() => { + searchReservation(formValuesToSub) }} /> @@ -238,7 +228,9 @@ function Newest() { total: reservationPage.total, simple: true }} - onChange={(pagination) => {onSearchClick(pagination.current)}} + onChange={(pagination) => { + searchReservation(formValuesToSub, pagination.current) + }} columns={reservationListColumns} dataSource={reservationList} />