|
|
@ -1,6 +1,6 @@
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
import { Form, Input, Row, Col, Select, DatePicker, Space, Button, InputNumber, Radio, Checkbox, Divider } from 'antd';
|
|
|
|
import { Form, Input, Row, Col, Select, DatePicker, Space, Button, InputNumber, Radio, Checkbox, Divider } from 'antd';
|
|
|
|
import { objectMapper, at } from '@/utils/commons';
|
|
|
|
import { objectMapper, at, isEmpty } from '@/utils/commons';
|
|
|
|
import { DATE_FORMAT, SMALL_DATETIME_FORMAT } from '@/config';
|
|
|
|
import { DATE_FORMAT, SMALL_DATETIME_FORMAT } from '@/config';
|
|
|
|
// import useFormStore from '@/stores/Form';
|
|
|
|
// import useFormStore from '@/stores/Form';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
@ -74,8 +74,8 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Form form={form} disabled={!(editable || false)} name={formName || 'product_info'} onFinish={onFinish} onValuesChange={onIValuesChange} initialValues={editingProduct?.info}>
|
|
|
|
<Form form={form} disabled={!(editable || false)} name={formName || 'product_info'} onFinish={onFinish} onValuesChange={onIValuesChange} initialValues={editingProduct?.info}>
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Row>
|
|
|
|
{getFields({ sort, initialValue: editingProduct?.info, hides, shows, fieldProps, fieldComProps, form, t, dataSets: { weekdays } })}
|
|
|
|
{getFields({ sort, initialValue: editingProduct?.info, hides, shows, fieldProps, fieldComProps, form, t, dataSets: { weekdays }, editable })}
|
|
|
|
{/* {showSubmit && (
|
|
|
|
{/* {showSubmit && (
|
|
|
|
<Col flex='1 0 90px' className='flex justify-end items-start'>
|
|
|
|
<Col flex='1 0 90px' className='flex justify-end items-start'>
|
|
|
|
<Space align='center'>
|
|
|
|
<Space align='center'>
|
|
|
@ -88,13 +88,13 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
</Row>
|
|
|
|
</Row>
|
|
|
|
{/* <Divider className='my-1' /> */}
|
|
|
|
{/* <Divider className='my-1' /> */}
|
|
|
|
|
|
|
|
|
|
|
|
<ProductInfoLgc formInstance={form} />
|
|
|
|
<ProductInfoLgc editable={editable} formInstance={form} />
|
|
|
|
<ProductInfoQuotation formInstance={form} />
|
|
|
|
<ProductInfoQuotation editable={editable} formInstance={form} />
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item hidden name={'id'} label={'ID'}>
|
|
|
|
<Form.Item hidden name={'id'} label={'ID'}>
|
|
|
|
<Input />
|
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
</Form.Item>
|
|
|
|
{showSubmit && (
|
|
|
|
{editable && (
|
|
|
|
<Form.Item>
|
|
|
|
<Form.Item>
|
|
|
|
<div className='flex justify-around'>
|
|
|
|
<div className='flex justify-around'>
|
|
|
|
<Button type='primary' htmlType='submit'>
|
|
|
|
<Button type='primary' htmlType='submit'>
|
|
|
@ -110,18 +110,23 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
|
|
|
|
|
|
|
|
function getFields(props) {
|
|
|
|
function getFields(props) {
|
|
|
|
const { fieldProps, fieldComProps, form, t, dataSets } = props;
|
|
|
|
const { fieldProps, fieldComProps, form, t, dataSets } = props;
|
|
|
|
console.log('getFields', props.initialValue);
|
|
|
|
// console.log('getFields', props.initialValue);
|
|
|
|
|
|
|
|
const styleProps = {};
|
|
|
|
|
|
|
|
// !props.editable ? {
|
|
|
|
|
|
|
|
// variant: 'borderless',
|
|
|
|
|
|
|
|
// className: '!text-slate-500',
|
|
|
|
|
|
|
|
// } : {};
|
|
|
|
const bigCol = 4 * 2;
|
|
|
|
const bigCol = 4 * 2;
|
|
|
|
const midCol = 6;
|
|
|
|
const midCol = 8;
|
|
|
|
const layoutProps = {
|
|
|
|
const layoutProps = {
|
|
|
|
// gutter: { xs: 8, sm: 8, lg: 16 },
|
|
|
|
// gutter: { xs: 8, sm: 8, lg: 16 },
|
|
|
|
lg: { span: 4 },
|
|
|
|
lg: { span: 6 },
|
|
|
|
md: { span: 8 },
|
|
|
|
md: { span: 8 },
|
|
|
|
sm: { span: 12 },
|
|
|
|
sm: { span: 12 },
|
|
|
|
xs: { span: 24 },
|
|
|
|
xs: { span: 24 },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const item = (name, sort = 0, render, col) => {
|
|
|
|
const item = (name, sort = 0, render, col) => {
|
|
|
|
const customCol = col || 4;
|
|
|
|
const customCol = col || midCol;
|
|
|
|
const mdCol = customCol * 2;
|
|
|
|
const mdCol = customCol * 2;
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'key': '',
|
|
|
|
'key': '',
|
|
|
@ -129,7 +134,7 @@ function getFields(props) {
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
render,
|
|
|
|
render,
|
|
|
|
'hide': false,
|
|
|
|
'hide': false,
|
|
|
|
'col': { lg: { span: customCol }, md: { span: mdCol < 8 ? 10 : mdCol }, flex: mdCol < 8 ? '1 0' : '' },
|
|
|
|
'col': { lg: { span: customCol }, md: { span: mdCol < 8 ? 10 : (mdCol > 24 ? 24 : mdCol) }, flex: mdCol < 8 ? '1 0' : '' },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let baseChildren = [];
|
|
|
|
let baseChildren = [];
|
|
|
@ -138,49 +143,49 @@ function getFields(props) {
|
|
|
|
'code',
|
|
|
|
'code',
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='code' label={t('Code')} {...fieldProps.code} _initialValue={at(props, 'initialValue.code')[0]}>
|
|
|
|
<Form.Item name='code' label={t('Code')} {...fieldProps.code} _initialValue={at(props, 'initialValue.code')[0]}>
|
|
|
|
<Input allowClear {...fieldComProps.code} />
|
|
|
|
<Input allowClear {...fieldComProps.code} {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.code?.col || 8
|
|
|
|
fieldProps?.code?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'city', // todo:
|
|
|
|
'city', // todo:
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='city' label={t('City')} {...fieldProps.city} _initialValue={at(props, 'initialValue.city')[0]}>
|
|
|
|
<Form.Item name='city' label={t('City')} {...fieldProps.city} _initialValue={at(props, 'initialValue.city')[0]}>
|
|
|
|
<CitySelector />
|
|
|
|
<CitySelector {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.city?.col || 8
|
|
|
|
fieldProps?.city?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'dept', // todo:
|
|
|
|
'dept', // todo:
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='dept' label={t('Dept')} {...fieldProps.dept}>
|
|
|
|
<Form.Item name='dept' label={t('Dept')} {...fieldProps.dept}>
|
|
|
|
<DeptSelector labelInValue={false} />
|
|
|
|
<DeptSelector labelInValue={false} isLeaf {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.dept?.col || 8
|
|
|
|
fieldProps?.dept?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'duration',
|
|
|
|
'duration',
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='duration' label={t('Duration')} {...fieldProps.duration}>
|
|
|
|
<Form.Item name='duration' label={t('Duration')} {...fieldProps.duration}>
|
|
|
|
<InputNumber suffix={'H'} max={24} />
|
|
|
|
<InputNumber suffix={'H'} max={24} {...styleProps} />
|
|
|
|
{/* <Input allowClear {...fieldComProps.duration} suffix={'H'} /> */}
|
|
|
|
{/* <Input allowClear {...fieldComProps.duration} suffix={'H'} /> */}
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.duration?.col || 8
|
|
|
|
fieldProps?.duration?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'km',
|
|
|
|
'km',
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='km' label={t('KM')} {...fieldProps.km}>
|
|
|
|
<Form.Item name='km' label={t('KM')} {...fieldProps.km}>
|
|
|
|
<InputNumber suffix={'KM'} min={1} />
|
|
|
|
<InputNumber suffix={'KM'} min={0.1} {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.km?.col || 8
|
|
|
|
fieldProps?.km?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'recommends_rate', // todo:
|
|
|
|
'recommends_rate', // todo:
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='recommends_rate' label={t('RecommendsRate')} {...fieldProps.recommends_rate}>
|
|
|
|
<Form.Item name='recommends_rate' label={t('RecommendsRate')} {...fieldProps.recommends_rate}>
|
|
|
|
{/* <Input placeholder={t('RecommendsRate')} allowClear /> */}
|
|
|
|
{/* <Input placeholder={t('RecommendsRate')} allowClear /> */}
|
|
|
|
<Select
|
|
|
|
<Select {...styleProps}
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
labelInValue
|
|
|
|
labelInValue
|
|
|
|
options={[
|
|
|
|
options={[
|
|
|
@ -192,7 +197,7 @@ function getFields(props) {
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.recommends_rate?.col || 8
|
|
|
|
fieldProps?.recommends_rate?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'display_to_c',
|
|
|
|
'display_to_c',
|
|
|
@ -222,16 +227,16 @@ function getFields(props) {
|
|
|
|
{ value: '153001', label: '在计划显示,不在报价信显示' },
|
|
|
|
{ value: '153001', label: '在计划显示,不在报价信显示' },
|
|
|
|
{ value: 0, label: '计划和报价信都要显示' },
|
|
|
|
{ value: 0, label: '计划和报价信都要显示' },
|
|
|
|
{ value: '153001, 153002', label: '计划和报价信都不用显示' },
|
|
|
|
{ value: '153001, 153002', label: '计划和报价信都不用显示' },
|
|
|
|
]} />
|
|
|
|
]} {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.display_to_c?.col || 8
|
|
|
|
fieldProps?.display_to_c?.col || midCol
|
|
|
|
),
|
|
|
|
),
|
|
|
|
item(
|
|
|
|
item(
|
|
|
|
'open_weekdays',
|
|
|
|
'open_weekdays',
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='open_weekdays' label={t('OpenWeekdays')} initialValue={['1', '2', '3', '4', '5', '6', '7']} {...fieldProps.open_weekdays}>
|
|
|
|
<Form.Item name='open_weekdays' label={t('OpenWeekdays')} initialValue={['1', '2', '3', '4', '5', '6', '7']} {...fieldProps.open_weekdays}>
|
|
|
|
{/* 默认全部 */}
|
|
|
|
{/* 默认全部 */}
|
|
|
|
<Checkbox.Group options={dataSets.weekdays} />
|
|
|
|
<Checkbox.Group options={dataSets.weekdays} {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.open_weekdays?.col || 24
|
|
|
|
fieldProps?.open_weekdays?.col || 24
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -239,7 +244,7 @@ function getFields(props) {
|
|
|
|
'remarks',
|
|
|
|
'remarks',
|
|
|
|
99,
|
|
|
|
99,
|
|
|
|
<Form.Item name='remarks' label={t('Remarks')} {...fieldProps.remarks}>
|
|
|
|
<Form.Item name='remarks' label={t('Remarks')} {...fieldProps.remarks}>
|
|
|
|
<Input.TextArea allowClear rows={2} maxLength={2000} {...fieldComProps.remarks} />
|
|
|
|
<Input.TextArea allowClear rows={2} maxLength={2000} {...fieldComProps.remarks} {...styleProps} />
|
|
|
|
</Form.Item>,
|
|
|
|
</Form.Item>,
|
|
|
|
fieldProps?.remarks?.col || 24
|
|
|
|
fieldProps?.remarks?.col || 24
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -282,7 +287,7 @@ function getFields(props) {
|
|
|
|
style = i % 2 === 0 && baseChildren[i].col === 12 ? { ...style, ...leftStyle } : style;
|
|
|
|
style = i % 2 === 0 && baseChildren[i].col === 12 ? { ...style, ...leftStyle } : style;
|
|
|
|
style = !baseChildren[i].hide ? { ...style, display: 'block' } : { ...style, display: 'none' };
|
|
|
|
style = !baseChildren[i].hide ? { ...style, display: 'block' } : { ...style, display: 'none' };
|
|
|
|
const Item = (
|
|
|
|
const Item = (
|
|
|
|
<Col key={String(i)} style={style} {...layoutProps} {...baseChildren[i].col}>
|
|
|
|
<Col key={String(i)} style={style} {...baseChildren[i].col} className='px-1 shrink-0 grow'>
|
|
|
|
{baseChildren[i].render}
|
|
|
|
{baseChildren[i].render}
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -290,28 +295,32 @@ function getFields(props) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return children;
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const formValuesMapper = (values) => {
|
|
|
|
const formValuesMapper = (values) => {
|
|
|
|
const destinationObject = {
|
|
|
|
const destinationObject = {
|
|
|
|
'keyword': { key: 'keyword', transform: (value) => value || '' },
|
|
|
|
'city': [{ key: 'city_id', transform: (value) => value?.value || value?.key || '' }, { key: 'city_name', transform: (value) => value?.label || '' }],
|
|
|
|
'referenceNo': { key: 'referenceNo', transform: (value) => value || '' },
|
|
|
|
'dept': { key: 'dept', transform: (value) => typeof value === 'string' ? value : (value?.value || value?.key || '') },
|
|
|
|
'dates': [
|
|
|
|
'open_weekdays': { key: 'open_weekdays', transform: (value) => (Array.isArray(value) ? value.join(',') : value) },
|
|
|
|
{ key: 'startdate', transform: (arrVal) => (arrVal ? arrVal[0].format(DATE_FORMAT) : '') },
|
|
|
|
'recommends_rate': { key: 'recommends_rate', transform: (value) => typeof value === 'string' ? value : (value?.value || value?.key || '') },
|
|
|
|
{ key: 'enddate', transform: (arrVal) => (arrVal ? arrVal[1].format(DATE_FORMAT) : '') },
|
|
|
|
'lgc_details': [
|
|
|
|
{ key: 'starttime', transform: (arrVal) => (arrVal ? arrVal[0].format(DATE_FORMAT) : '') },
|
|
|
|
{
|
|
|
|
{ key: 'endtime', transform: (arrVal) => (arrVal ? arrVal[1].format(SMALL_DATETIME_FORMAT) : '') },
|
|
|
|
key: 'lgc_details',
|
|
|
|
],
|
|
|
|
transform: (value) => {
|
|
|
|
'invoiceStatus': { key: 'invoiceStatus', transform: (value) => value?.value || value?.key || '', default: '' },
|
|
|
|
const _val = value.filter((s) => !isEmpty(s));
|
|
|
|
'audit_state': { key: 'audit_state', transform: (value) => value?.value || value?.key || '', default: '' },
|
|
|
|
return _val || '';
|
|
|
|
'agency': {
|
|
|
|
},
|
|
|
|
key: 'agency',
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
key: 'lgc_details_mapped',
|
|
|
|
transform: (value) => {
|
|
|
|
transform: (value) => {
|
|
|
|
return Array.isArray(value) ? value.map((ele) => ele.key).join(',') : value ? value.value : '';
|
|
|
|
const _val = value.filter((s) => !isEmpty(s));
|
|
|
|
|
|
|
|
return _val.reduce((r, c) => ({ ...r, [c.lgc]: c }), {});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'year': [{ key: 'year', transform: (arrVal) => (arrVal ? arrVal.format('YYYY') : '') }],
|
|
|
|
],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let dest = {};
|
|
|
|
let dest = {};
|
|
|
|
const { dates, ...omittedValue } = values;
|
|
|
|
const { city, ...omittedValue } = values;
|
|
|
|
dest = { ...omittedValue, ...objectMapper(values, destinationObject) };
|
|
|
|
dest = { ...omittedValue, ...objectMapper(values, destinationObject) };
|
|
|
|
for (const key in dest) {
|
|
|
|
for (const key in dest) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(dest, key)) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(dest, key)) {
|
|
|
@ -320,7 +329,8 @@ const formValuesMapper = (values) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// omit empty
|
|
|
|
// omit empty
|
|
|
|
// Object.keys(dest).forEach((key) => (dest[key] == null || dest[key] === '' || dest[key].length === 0) && delete dest[key]);
|
|
|
|
// Object.keys(dest).forEach((key) => (dest[key] == null || dest[key] === '' || dest[key].length === 0) && delete dest[key]);
|
|
|
|
return dest;
|
|
|
|
const { lgc_details, lgc_details_mapped, ...info } = dest;
|
|
|
|
|
|
|
|
return { info, lgc_details, lgc_details_mapped };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|