perf: 调用 选择供应商 组件

main
Lei OT 6 months ago
parent a68e32d807
commit 50511adb84

@ -1,10 +1,11 @@
import { useEffect } from "react";
import { Form, Input, Row, Col, Select, DatePicker, Space, Button, Checkbox } from "antd";
import { objectMapper, at } from "@/utils/commons";
import { DATE_FORMAT, SMALL_DATETIME_FORMAT } from "@/config";
import { DATE_FORMAT, SMALL_DATETIME_FORMAT, PERM_AGENCY_ALL } from "@/config";
import useFormStore from "@/stores/Form";
import { useDatePresets } from "@/hooks/useDatePresets";
import { useTranslation } from "react-i18next";
import useAuthStore from '@/stores/Auth'
import SearchInput from "./SearchInput";
import AuditStateSelector from "./AuditStateSelector";
@ -20,15 +21,19 @@ 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 [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 { sort, hides, shows, fieldProps, fieldComProps } = {
sort: "",
// initialValue: '',
fieldProps: "",
fieldComProps: "",
hides: [],
shows: [],
...props.fieldsConfig,
shows: [...defaultShowFields, ...(props.fieldsConfig?.shows || [])],
fieldProps: { ...defaultFieldsProps, ...(props.fieldsConfig?.fieldProps || {}) },
fieldComProps: { ...defaultFieldsComProps, ...(props.fieldsConfig?.fieldComProps || {}) },
};
const readValues = { ...initialValue, ...formValues };
@ -46,12 +51,11 @@ const SearchForm = ({ initialValue, onSubmit, onReset, onMounted, confirmText, f
invoiceStatus: { key: "invoiceStatus", transform: value => value?.value || value?.key || "", default: "" },
invoiceCheckStatus: { key: "invoiceCheckStatus", transform: value => value?.value || value?.key || "", default: "" },
audit_state: { key: "audit_state", transform: value => value?.value || value?.key || "", default: "" },
agency: {
key: "agency",
transform: value => {
return Array.isArray(value) ? value.map(ele => ele.key).join(",") : value ? value.value : "";
},
},
agency: [
{ key: "agency", transform: value => { return Array.isArray(value) ? value.map(ele => ele.key).join(",") : value ? value.value : ""; }, },
{ key: "veisn", transform: value => { return Array.isArray(value) ? value.map(ele => ele.key).join(",") : value ? value.value : ""; }, },
{ key: "VEI_SN", transform: value => { return Array.isArray(value) ? value.map(ele => ele.key).join(",") : value ? value.value : ""; }, },
],
year: [{ key: "year", transform: arrVal => (arrVal ? arrVal.format("YYYY") : "") }],
products_types: {
key: "products_types",
@ -102,9 +106,9 @@ const SearchForm = ({ initialValue, onSubmit, onReset, onMounted, confirmText, f
}, []);
const onFinish = values => {
//console.log("Received values of form, origin form value: \n", values);
console.log("Received values of form, origin form value: \n", values);
const dest = formValuesMapper(values);
//console.log("form value send to onSubmit:\n", dest);
console.log("form value send to onSubmit:\n", dest);
const str = new URLSearchParams(dest).toString();
setFormValues(values);
setFormValuesToSub(dest);
@ -157,7 +161,7 @@ const SearchForm = ({ initialValue, onSubmit, onReset, onMounted, confirmText, f
};
function getFields(props) {
const { fieldProps, fieldComProps, form, presets, t } = props;
const { fieldProps, fieldComProps, form, presets, t, shows } = props;
const bigCol = 4 * 2;
const midCol = 6;
const layoutProps = {
@ -254,7 +258,7 @@ function getFields(props) {
<Form.Item name="username" label={t("account:username")} {...fieldProps.username}>
<Input placeholder={t("account:username")} allowClear />
</Form.Item>,
fieldProps?.username?.col || 4
fieldProps?.username?.col || 6
),
/**
*
@ -269,7 +273,7 @@ function getFields(props) {
),
item(
"agency", //
99,
98, //
<Form.Item name="agency" label={t("products:Vendor")} {...fieldProps.agency} initialValue={at(props, "initialValue.agency")[0]}>
<VendorSelector maxTagCount={1} {...fieldComProps.agency} />
</Form.Item>,

@ -100,14 +100,13 @@ function Index() {
<Space direction='vertical' style={{ width: '100%' }}>
<SearchForm
fieldsConfig={{
shows: ['agency', 'audit_state', 'dates', 'year'],
shows: [ 'audit_state', 'dates', 'year'],
fieldProps: {
agency: { col: 4 },
dates: { label: t('products:CreateDate') },
keyword: { label: t('products:Title'), col: 4 },
year: { col: 4, rules: [{ required: true }] },
},
sort: { agency: 1, audit_state: 2, keyword: 100 },
sort: { aaudit_state: 2, keyword: 100 },
}}
initialValue={{
dates: [dayjs().subtract(2, 'M').startOf('M'), dayjs().endOf('M')],

@ -227,18 +227,14 @@ function Newest() {
</Space>
</Modal>
<Space direction='vertical' className='w-full'>
<Title level={3}></Title>
{/* <Title level={3}></Title> */}
<SearchForm
initialValue={{unconfirmed: true}}
fieldsConfig={{
shows: isPermitted(PERM_AGENCY_ALL) ? ['agency', 'referenceNo', 'dates', 'unconfirmed'] : ['referenceNo', 'dates', 'unconfirmed'],
sort: { agency: 0, },
shows: ['referenceNo', 'dates', 'unconfirmed'],
fieldProps: {
dates: { label: t('group:ArrivalDate') },
},
fieldComProps: {
agency: {mode: null, allowClear: false}
}
}}
onMounted={(initialValue) => {
searchReservation(initialValue)

Loading…
Cancel
Save