feat: SearchForm 增加时间 onMounted,解决 View 获取初始值加载数据

perf/export-docx
Jimmy Liow 11 months ago
parent 83275f2d25
commit 3544419d11

@ -15,7 +15,7 @@ import VendorSelector from '@/components/VendorSelector';
const { RangePicker } = DatePicker; 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 { t } = useTranslation();
const presets = useDatePresets(); const presets = useDatePresets();
const [formValues, setFormValues] = useFormStore((state) => [state.formValues, state.setFormValues]); const [formValues, setFormValues] = useFormStore((state) => [state.formValues, state.setFormValues]);
@ -89,8 +89,14 @@ const SearchForm = ({ initialValue, onSubmit, onReset, confirmText, formName, fo
}; };
useEffect(() => { useEffect(() => {
const dest = formValuesMapper(formValues); setFormValues(readValues);
const dest = formValuesMapper(readValues);
setFormValuesToSub(dest); setFormValuesToSub(dest);
if (typeof onMounted === 'function') {
onMounted(dest)
}
return () => {}; return () => {};
}, []); }, []);

@ -96,7 +96,6 @@ function Newest() {
const [guideSelectOptions, setGuideSelectOptions] = useState([]) const [guideSelectOptions, setGuideSelectOptions] = useState([])
const formValuesToSub = useFormStore((state) => state.formValuesToSub) const formValuesToSub = useFormStore((state) => state.formValuesToSub)
const [fetchAllGuideList, fetchReservationList, reservationList, reservationPage, cityList, selectReservation, getCityListByReservationId, setupCityGuide, updateReservationGuide] = const [fetchAllGuideList, fetchReservationList, reservationList, reservationPage, cityList, selectReservation, getCityListByReservationId, setupCityGuide, updateReservationGuide] =
useReservationStore((state) => useReservationStore((state) =>
[state.fetchAllGuideList, state.fetchReservationList, state.reservationList, state.reservationPage, state.cityList, state.selectReservation, state.getCityListByReservationId, state.setupCityGuide, state.updateReservationGuide]) [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() const { notification } = App.useApp()
useEffect (() => { useEffect (() => {
if (location.search !== '?back') {
//
onSearchClick(1, 1)
}
fetchAllGuideList() fetchAllGuideList()
.then((guideList) => { .then((guideList) => {
const selectOptions = guideList.map((data, index) => { const selectOptions = guideList.map((data) => {
return { return {
value: data.guideId, value: data.guideId,
label: data.guideName label: data.guideName
@ -137,6 +132,7 @@ function Newest() {
setDataLoading(false); setDataLoading(false);
}) })
} }
const handleOk = () => { const handleOk = () => {
updateReservationGuide() updateReservationGuide()
.finally(() => { .finally(() => {
@ -144,15 +140,18 @@ function Newest() {
setDataLoading(false); setDataLoading(false);
}) })
} }
const handleCancel = () => { const handleCancel = () => {
setIsModalOpen(false); setIsModalOpen(false);
setDataLoading(false); setDataLoading(false);
} }
// //
const onSearchClick = (current=1, status=null) => { const searchReservation = (submitValues, current=1) => {
setDataLoading(true) setDataLoading(true)
fetchReservationList(formValuesToSub, current) console.info('onSearchClick')
console.info(submitValues)
fetchReservationList(submitValues, current)
.catch(ex => { .catch(ex => {
notification.error({ notification.error({
message: `Notification`, message: `Notification`,
@ -208,20 +207,11 @@ function Newest() {
dates: { label: t('group:ArrivalDate') }, dates: { label: t('group:ArrivalDate') },
}, },
}} }}
onSubmit={(err, formVal, filedsVal) => { onMounted={(initialValue) => {
setDataLoading(true) searchReservation(initialValue)
fetchReservationList(formVal) }}
.catch(ex => { onSubmit={() => {
notification.error({ searchReservation(formValuesToSub)
message: 'Notification',
description: ex.message,
placement: 'top',
duration: 4,
})
})
.finally(() => {
setDataLoading(false)
})
}} }}
/> />
<Title level={3}></Title> <Title level={3}></Title>
@ -238,7 +228,9 @@ function Newest() {
total: reservationPage.total, total: reservationPage.total,
simple: true simple: true
}} }}
onChange={(pagination) => {onSearchClick(pagination.current)}} onChange={(pagination) => {
searchReservation(formValuesToSub, pagination.current)
}}
columns={reservationListColumns} dataSource={reservationList} columns={reservationListColumns} dataSource={reservationList}
/> />
</Col> </Col>

Loading…
Cancel
Save