|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { Form, Input, Row, Col, Select, DatePicker, Space, Button, InputNumber, Radio, Checkbox, Divider } from 'antd';
|
|
|
|
|
import { objectMapper, at, isEmpty } from '@/utils/commons';
|
|
|
|
|
import { DATE_FORMAT, SMALL_DATETIME_FORMAT } from '@/config';
|
|
|
|
@ -17,11 +17,14 @@ import { useProductsTypesMapVal, useProductsTypesFieldsets } from '@/hooks/usePr
|
|
|
|
|
import useProductsStore from '@/stores/Products/Index';
|
|
|
|
|
import ProductInfoLgc from './ProductInfoLgc';
|
|
|
|
|
import ProductInfoQuotation from './ProductInfoQuotation';
|
|
|
|
|
import useAuthStore from '@/stores/Auth';
|
|
|
|
|
import { PERM_PRODUCTS_MANAGEMENT, PERM_PRODUCTS_OFFER_AUDIT, PERM_PRODUCTS_OFFER_PUT } from '@/config';
|
|
|
|
|
|
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
|
|
|
|
const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, showSubmit, confirmText, formName, loading, ...props }) => {
|
|
|
|
|
const { t } = useTranslation('products');
|
|
|
|
|
const isPermitted = useAuthStore((state) => state.isPermitted);
|
|
|
|
|
const [agencyProducts, editingProduct, setEditingProduct] = useProductsStore((state) => [state.agencyProducts, state.editingProduct, state.setEditingProduct]);
|
|
|
|
|
const weekdays = useWeekdays();
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
@ -46,6 +49,8 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [editingProduct?.info?.id]);
|
|
|
|
|
|
|
|
|
|
const ignoreEditable = isPermitted(PERM_PRODUCTS_OFFER_AUDIT);
|
|
|
|
|
|
|
|
|
|
const onFinish = (values) => {
|
|
|
|
|
console.log('Received values of form, origin form value: \n', values);
|
|
|
|
|
const dest = formValuesMapper(values);
|
|
|
|
@ -75,7 +80,7 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
|
<>
|
|
|
|
|
<Form form={form} disabled={!(editable || false)} name={formName || 'product_info'} onFinish={onFinish} onValuesChange={onIValuesChange} initialValues={editingProduct?.info}>
|
|
|
|
|
<Row>
|
|
|
|
|
{getFields({ sort, initialValue: editingProduct?.info, hides, shows, fieldProps, fieldComProps, form, t, dataSets: { weekdays }, editable })}
|
|
|
|
|
{getFields({ sort, initialValue: editingProduct?.info, hides, shows, fieldProps, fieldComProps, form, t, dataSets: { weekdays }, editable, ignoreEditable })}
|
|
|
|
|
{/* {showSubmit && (
|
|
|
|
|
<Col flex='1 0 90px' className='flex justify-end items-start'>
|
|
|
|
|
<Space align='center'>
|
|
|
|
@ -88,7 +93,7 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
|
</Row>
|
|
|
|
|
{/* <Divider className='my-1' /> */}
|
|
|
|
|
|
|
|
|
|
<ProductInfoLgc editable={editable} formInstance={form} />
|
|
|
|
|
<ProductInfoLgc editable={editable} ignoreEditable={ignoreEditable} formInstance={form} />
|
|
|
|
|
<ProductInfoQuotation editable={editable} formInstance={form} />
|
|
|
|
|
|
|
|
|
|
<Form.Item hidden name={'id'} label={'ID'}>
|
|
|
|
@ -97,7 +102,7 @@ const InfoForm = ({ formInstance, onSubmit, onReset, onValuesChange, editable, s
|
|
|
|
|
{editable && (
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<div className='flex justify-around'>
|
|
|
|
|
<Button type='primary' htmlType='submit'>
|
|
|
|
|
<Button type='primary' htmlType='submit' loading={loading}>
|
|
|
|
|
{t('common:Save')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
@ -112,10 +117,10 @@ function getFields(props) {
|
|
|
|
|
const { fieldProps, fieldComProps, form, t, dataSets } = props;
|
|
|
|
|
// console.log('getFields', props.initialValue);
|
|
|
|
|
const styleProps = {};
|
|
|
|
|
// !props.editable ? {
|
|
|
|
|
// variant: 'borderless',
|
|
|
|
|
// className: '!text-slate-500',
|
|
|
|
|
// } : {};
|
|
|
|
|
const editableProps = (name) => {
|
|
|
|
|
const disabled = props.ignoreEditable ? false : (isEmpty(props.initialValue?.[name]) && props.editable ? false : true)
|
|
|
|
|
return { disabled, className: disabled ? '!text-slate-500' : '' };
|
|
|
|
|
}
|
|
|
|
|
const bigCol = 4 * 2;
|
|
|
|
|
const midCol = 8;
|
|
|
|
|
const layoutProps = {
|
|
|
|
@ -143,15 +148,15 @@ function getFields(props) {
|
|
|
|
|
'code',
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='code' label={t('Code')} {...fieldProps.code} _initialValue={at(props, 'initialValue.code')[0]}>
|
|
|
|
|
<Input allowClear {...fieldComProps.code} {...styleProps} />
|
|
|
|
|
<Input allowClear {...fieldComProps.code} {...styleProps} {...editableProps('code')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.code?.col || midCol
|
|
|
|
|
),
|
|
|
|
|
item(
|
|
|
|
|
'city', // todo:
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='city' label={t('City')} {...fieldProps.city} _initialValue={at(props, 'initialValue.city')[0]}>
|
|
|
|
|
<CitySelector {...styleProps} />
|
|
|
|
|
<Form.Item name='city' label={t('City')} {...fieldProps.city} _initialValue={at(props, 'initialValue.city_id')[0]}>
|
|
|
|
|
<CitySelector {...styleProps} {...editableProps('city_id')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.city?.col || midCol
|
|
|
|
|
),
|
|
|
|
@ -159,7 +164,7 @@ function getFields(props) {
|
|
|
|
|
'dept', // todo:
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='dept' label={t('Dept')} {...fieldProps.dept}>
|
|
|
|
|
<DeptSelector labelInValue={false} isLeaf {...styleProps} />
|
|
|
|
|
<DeptSelector labelInValue={false} isLeaf {...styleProps} {...editableProps('dept')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.dept?.col || midCol
|
|
|
|
|
),
|
|
|
|
@ -167,7 +172,7 @@ function getFields(props) {
|
|
|
|
|
'duration',
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='duration' label={t('Duration')} {...fieldProps.duration}>
|
|
|
|
|
<InputNumber suffix={'H'} max={24} {...styleProps} />
|
|
|
|
|
<InputNumber suffix={'H'} max={24} {...styleProps} {...editableProps('duration')} />
|
|
|
|
|
{/* <Input allowClear {...fieldComProps.duration} suffix={'H'} /> */}
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.duration?.col || midCol
|
|
|
|
@ -176,7 +181,7 @@ function getFields(props) {
|
|
|
|
|
'km',
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='km' label={t('KM')} {...fieldProps.km}>
|
|
|
|
|
<InputNumber suffix={'KM'} min={0.1} {...styleProps} />
|
|
|
|
|
<InputNumber suffix={'KM'} min={0.1} {...styleProps} {...editableProps('km')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.km?.col || midCol
|
|
|
|
|
),
|
|
|
|
@ -185,7 +190,7 @@ function getFields(props) {
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='recommends_rate' label={t('RecommendsRate')} {...fieldProps.recommends_rate}>
|
|
|
|
|
{/* <Input placeholder={t('RecommendsRate')} allowClear /> */}
|
|
|
|
|
<Select {...styleProps}
|
|
|
|
|
<Select {...styleProps} {...editableProps('recommends_rate')}
|
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
|
labelInValue
|
|
|
|
|
options={[
|
|
|
|
@ -227,7 +232,7 @@ function getFields(props) {
|
|
|
|
|
{ value: '153001', label: '在计划显示,不在报价信显示' },
|
|
|
|
|
{ value: 0, label: '计划和报价信都要显示' },
|
|
|
|
|
{ value: '153001, 153002', label: '计划和报价信都不用显示' },
|
|
|
|
|
]} {...styleProps} />
|
|
|
|
|
]} {...styleProps} {...editableProps('display_to_c')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.display_to_c?.col || midCol
|
|
|
|
|
),
|
|
|
|
@ -236,7 +241,7 @@ function getFields(props) {
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='open_weekdays' label={t('OpenWeekdays')} initialValue={['1', '2', '3', '4', '5', '6', '7']} {...fieldProps.open_weekdays}>
|
|
|
|
|
{/* 默认全部 */}
|
|
|
|
|
<Checkbox.Group options={dataSets.weekdays} {...styleProps} />
|
|
|
|
|
<Checkbox.Group options={dataSets.weekdays} {...styleProps} {...editableProps('open_weekdays')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.open_weekdays?.col || 24
|
|
|
|
|
),
|
|
|
|
@ -244,7 +249,7 @@ function getFields(props) {
|
|
|
|
|
'remarks',
|
|
|
|
|
99,
|
|
|
|
|
<Form.Item name='remarks' label={t('Remarks')} {...fieldProps.remarks}>
|
|
|
|
|
<Input.TextArea allowClear rows={2} maxLength={2000} {...fieldComProps.remarks} {...styleProps} />
|
|
|
|
|
<Input.TextArea allowClear rows={2} maxLength={2000} {...fieldComProps.remarks} {...styleProps} {...editableProps('remarks')} />
|
|
|
|
|
</Form.Item>,
|
|
|
|
|
fieldProps?.remarks?.col || 24
|
|
|
|
|
),
|
|
|
|
|