perf: 选择供应商 组件: 默认值

main
Lei OT 6 months ago
parent f6ffed8607
commit 7f0845a111

@ -21,11 +21,14 @@ const SearchForm = ({ initialValue, onSubmit, onReset, onMounted, confirmText, f
const presets = useDatePresets();
const [formValues, setFormValues] = useFormStore(state => [state.formValues, state.setFormValues]);
const [formValuesToSub, setFormValuesToSub] = useFormStore(state => [state.formValuesToSub, state.setFormValuesToSub]);
const isPermitted = useAuthStore((state) => state.isPermitted)
const [isPermitted, {travelAgencyName: myAgencyName, travelAgencyId: myAgencyId}] = useAuthStore((state) => [state.isPermitted, state.currentUser])
const [form] = Form.useForm();
const defaultShowFields = isPermitted(PERM_AGENCY_ALL) ? ['agency'] : [];
const defaultFieldsProps = isPermitted(PERM_AGENCY_ALL) ? { agency: { col: 24 }, } : {};
const defaultFieldsComProps = isPermitted(PERM_AGENCY_ALL) ? { agency: { mode: null }, } : {};
const defaultFieldsComProps = isPermitted(PERM_AGENCY_ALL) ? { agency: { mode: null, allowClear: false }, } : {};
const defaultInitialValue = isPermitted(PERM_AGENCY_ALL) ? { agency: { key: myAgencyId, value: myAgencyId, label: myAgencyName }} : {};
const { sort, hides, shows, fieldProps, fieldComProps } = {
sort: "",
// initialValue: '',
@ -35,7 +38,7 @@ const SearchForm = ({ initialValue, onSubmit, onReset, onMounted, confirmText, f
fieldProps: { ...defaultFieldsProps, ...(props.fieldsConfig?.fieldProps || {}) },
fieldComProps: { ...defaultFieldsComProps, ...(props.fieldsConfig?.fieldComProps || {}) },
};
const readValues = { ...initialValue, ...formValues };
const readValues = { ...defaultInitialValue, ...initialValue, ...formValues };
const formValuesMapper = values => {
const destinationObject = {

@ -5,20 +5,27 @@ import { fetchJSON } from '@/utils/request';
import { HT_HOST } from '@/config';
import { useTranslation } from 'react-i18next';
import useFormStore from "@/stores/Form";
import { usingStorage } from "@/hooks/usingStorage";
import useAuthStore from '@/stores/Auth'
//
export const fetchVendorList = async (q) => {
/**
* 供应商列表
* @deprecated
*/
const fetchVendorList = async (q) => {
const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/VendorList`, { q });
return errcode !== 0 ? [] : result;
};
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]);
return (
<>
<SearchInput initLoad={true}
<SearchInput initLoad={false}
placeholder={t('products:Vendor')}
mode={'multiple'}
maxTagCount={0}
@ -26,7 +33,7 @@ const VendorSelector = ({ ...props }) => {
fetchOptions={fetchVendorList}
map={{ travel_agency_name: 'label', travel_agency_id: 'value' }}
onFetch={(v) => setCache({ vendorList: v })}
defaultOptions={vendorList}
defaultOptions={vendorList?.length ? vendorList : [{ label: myAgencyName, value: myAgencyId, key: myAgencyId }]}
/>
</>
);

@ -80,7 +80,8 @@ const useAuthStore = create(devtools((set, get) => ({
realname: isEmpty(userJson.real_name) ? userJson.LoginName : userJson.real_name,
rolesName: userJson.roles_name,
emailAddress: userJson.LMI_listmail,
travelAgencyName: isEmpty(userJson.VName) ? userJson.LMI_VEI_SN : userJson.VName
travelAgencyName: isEmpty(userJson.VName) ? userJson.LMI_VEI_SN : userJson.VName,
travelAgencyId: userJson.LMI_VEI_SN
}
}))

Loading…
Cancel
Save