|
|
|
|
@ -7,20 +7,33 @@ import { useTranslation } from 'react-i18next';
|
|
|
|
|
import useFormStore from "@/stores/Form";
|
|
|
|
|
import { usingStorage } from "@/hooks/usingStorage";
|
|
|
|
|
import useAuthStore from '@/stores/Auth'
|
|
|
|
|
import { isEmpty, objectMapper } from '@/utils/commons';
|
|
|
|
|
|
|
|
|
|
const mapper = { travel_agency_name: 'label', travel_agency_id: 'value' };
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 供应商列表
|
|
|
|
|
*/
|
|
|
|
|
const fetchVendorList = async (q) => {
|
|
|
|
|
const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/VendorList`, { q });
|
|
|
|
|
const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/VendorList`, { q, useweb: -1 });
|
|
|
|
|
return errcode !== 0 ? [] : result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fetchVendorListDefault = async (q = '') => {
|
|
|
|
|
const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/VendorList`, { q, useweb: 1 });
|
|
|
|
|
return errcode !== 0 ? [] : result.map(ele => objectMapper(ele, mapper));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const VendorSelector = ({ ...props }) => {
|
|
|
|
|
const { travelAgencyId: myAgencyId } = usingStorage();
|
|
|
|
|
const [{ travelAgencyName: myAgencyName }] = useAuthStore((state) => [state.currentUser]);
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const [{ vendorList }, setCache] = useFormStore(state => [state.cache, state.setCache]);
|
|
|
|
|
const [vendorList0, setVendorList0] = useFormStore(state => [state.vendorList0, state.setVendorList0]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isEmpty(vendorList0)) {
|
|
|
|
|
fetchVendorListDefault().then(res => setVendorList0(res));
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
@ -31,9 +44,9 @@ const VendorSelector = ({ ...props }) => {
|
|
|
|
|
maxTagCount={0}
|
|
|
|
|
{...props}
|
|
|
|
|
fetchOptions={fetchVendorList}
|
|
|
|
|
map={{ travel_agency_name: 'label', travel_agency_id: 'value' }}
|
|
|
|
|
map={mapper}
|
|
|
|
|
onFetch={(v) => setCache({ vendorList: v })}
|
|
|
|
|
defaultOptions={vendorList?.length ? vendorList : [{ label: myAgencyName, value: myAgencyId, key: myAgencyId }]}
|
|
|
|
|
defaultOptions={vendorList0}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|