提交 343ee8bf 作者: 龚洪江

修复:机构缺陷问题

上级 2a7f0c76
...@@ -17,6 +17,7 @@ const EditableCell: React.FC< ...@@ -17,6 +17,7 @@ const EditableCell: React.FC<
EditableCellProps & { EditableCellProps & {
selectOption?: { name: string; id: number }[]; selectOption?: { name: string; id: number }[];
uploadSuccess?: (record: any, result: any) => void; uploadSuccess?: (record: any, result: any) => void;
rules?: any;
} }
> = ({ > = ({
editing, editing,
...@@ -28,6 +29,7 @@ const EditableCell: React.FC< ...@@ -28,6 +29,7 @@ const EditableCell: React.FC<
selectOption, selectOption,
uploadSuccess, uploadSuccess,
children, children,
rules,
...restProps ...restProps
}) => { }) => {
const inputNode = () => { const inputNode = () => {
...@@ -60,32 +62,10 @@ const EditableCell: React.FC< ...@@ -60,32 +62,10 @@ const EditableCell: React.FC<
return <Input placeholder={`请输入${title}`} />; return <Input placeholder={`请输入${title}`} />;
} }
}; };
const getMessage = () => {
switch (inputType) {
case 'number':
case 'text':
return `请输入${title}`;
case 'select':
return `请选择${title}`;
case 'uploader':
return `请上传${title}`;
default:
return `请输入${title}`;
}
};
return ( return (
<td {...restProps}> <td {...restProps}>
{editing ? ( {editing ? (
<Form.Item <Form.Item name={dataIndex + record.id} style={{ margin: 0 }} rules={rules}>
name={dataIndex + record.id}
style={{ margin: 0 }}
rules={[
{
required: true,
message: getMessage(),
},
]}
>
{inputNode()} {inputNode()}
</Form.Item> </Form.Item>
) : ( ) : (
......
...@@ -157,11 +157,7 @@ const BaseInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -157,11 +157,7 @@ const BaseInfo: FC<selfProps> = forwardRef((props, ref) => {
<UploadOutlined /> <UploadOutlined />
</Uploader> </Uploader>
</Form.Item> </Form.Item>
<Form.Item <Form.Item label='机构副图' name='auxiliaryPicture'>
label='机构副图'
name='auxiliaryPicture'
rules={[{ required: true, message: '请上传机构副图' }]}
>
<Uploader <Uploader
fileUpload fileUpload
listType='picture-card' listType='picture-card'
...@@ -206,7 +202,7 @@ const BaseInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -206,7 +202,7 @@ const BaseInfo: FC<selfProps> = forwardRef((props, ref) => {
name='name' name='name'
rules={[{ required: true, message: '请输入机构名称' }]} rules={[{ required: true, message: '请输入机构名称' }]}
> >
<Input placeholder='请输入机构名称' maxLength={30} /> <Input placeholder='请输入机构名称' maxLength={25} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label='机构地区' label='机构地区'
......
...@@ -41,11 +41,25 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -41,11 +41,25 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
//执照类型列表 //执照类型列表
const [typeList, setTypeList] = useState<typeListType>([]); const [typeList, setTypeList] = useState<typeListType>([]);
//价格正则
const priceValidator = (_rule: any, value: any) => {
const reg = /^\d+(\.\d{1,2})?$/;
if (reg.test(value)) {
if (value < 0 || value > 100000) {
return Promise.reject(new Error('价格大于0且小于10万'));
}
} else {
return Promise.reject(new Error('价格为数字且保留小数点后两位'));
}
return Promise.resolve();
};
const defaultColumns: (ColumnTypes[number] & { const defaultColumns: (ColumnTypes[number] & {
editable?: boolean; editable?: boolean;
dataIndex?: string; dataIndex?: string;
selectOption?: { name: string; id: number }[]; selectOption?: { name: string; id: number }[];
inputType?: string; inputType?: string;
rules?: any;
})[] = [ })[] = [
{ {
title: '序号', title: '序号',
...@@ -60,6 +74,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -60,6 +74,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
width: '10%', width: '10%',
inputType: 'uploader', inputType: 'uploader',
editable: true, editable: true,
rules: [{ required: 'true', message: '请上传培训主图' }],
}, },
{ {
title: '培训机型', title: '培训机型',
...@@ -69,6 +84,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -69,6 +84,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
inputType: 'select', inputType: 'select',
width: '15%', width: '15%',
selectOption: modelsList, selectOption: modelsList,
rules: [{ required: 'true', message: '请选择培训机型' }],
}, },
{ {
title: '培训等级', title: '培训等级',
...@@ -78,6 +94,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -78,6 +94,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
inputType: 'select', inputType: 'select',
width: '15%', width: '15%',
selectOption: gradeList, selectOption: gradeList,
rules: [{ required: 'true', message: '请选择培训等级' }],
}, },
{ {
title: '培训类型', title: '培训类型',
...@@ -87,6 +104,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -87,6 +104,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
inputType: 'select', inputType: 'select',
width: '15%', width: '15%',
selectOption: typeList, selectOption: typeList,
rules: [{ required: 'true', message: '请选择培训类型' }],
}, },
{ {
title: '培训价格', title: '培训价格',
...@@ -94,6 +112,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -94,6 +112,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
editable: true, editable: true,
dataIndex: 'price', dataIndex: 'price',
width: '12%', width: '12%',
rules: [{ required: 'true', validator: priceValidator }],
}, },
{ {
title: '操作', title: '操作',
...@@ -142,6 +161,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -142,6 +161,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
selectOption: col.selectOption, selectOption: col.selectOption,
inputType: col.inputType, inputType: col.inputType,
uploadSuccess: col.inputType === 'uploader' ? uploadSuccess : undefined, uploadSuccess: col.inputType === 'uploader' ? uploadSuccess : undefined,
rules: col.rules,
}), }),
}; };
}); });
...@@ -211,6 +231,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => { ...@@ -211,6 +231,7 @@ const SkuInfo: FC<selfProps> = forwardRef((props, ref) => {
setTypeList(result || []); setTypeList(result || []);
}); });
}; };
useEffect(() => { useEffect(() => {
getLicenceModelsList(); getLicenceModelsList();
getLicenceGradeList(); getLicenceGradeList();
......
...@@ -94,7 +94,7 @@ const AddOrEditInstitution = () => { ...@@ -94,7 +94,7 @@ const AddOrEditInstitution = () => {
if (institutionDetail) { if (institutionDetail) {
baseRef.current.getForm().setFieldsValue({ baseRef.current.getForm().setFieldsValue({
mainImage: institutionDetail.mainImage, mainImage: institutionDetail.mainImage,
auxiliaryPicture: institutionDetail.auxiliaryPicture, auxiliaryPicture: institutionDetail.auxiliaryPicture || undefined,
video: institutionDetail.video, video: institutionDetail.video,
name: institutionDetail.name, name: institutionDetail.name,
region: institutionDetail.region, region: institutionDetail.region,
...@@ -117,21 +117,25 @@ const AddOrEditInstitution = () => { ...@@ -117,21 +117,25 @@ const AddOrEditInstitution = () => {
}, },
]); ]);
baseRef.current.getDefaultDataEvent().setSubImgList( baseRef.current.getDefaultDataEvent().setSubImgList(
institutionDetail.auxiliaryPicture.split(',').map((v: string) => ({ institutionDetail.auxiliaryPicture?.split(',').map((v: string) => ({
id: Math.random(), id: Math.random(),
uid: Math.random(), uid: Math.random(),
url: v, url: v,
name: 'auxiliaryPicture', name: 'auxiliaryPicture',
})), })) || [],
); );
baseRef.current.getDefaultDataEvent().setVideoList([ baseRef.current.getDefaultDataEvent().setVideoList(
institutionDetail.video
? [
{ {
id: Math.random(), id: Math.random(),
uid: Math.random(), uid: Math.random(),
url: institutionDetail.video, url: institutionDetail.video,
name: 'video', name: 'video',
}, },
]); ]
: [],
);
const programsList = institutionDetail.programsDOList.map((v) => ({ const programsList = institutionDetail.programsDOList.map((v) => ({
...v, ...v,
fileList: [ fileList: [
......
import SearchBox, { searchColumns } from '~/components/search-box'; import SearchBox, { searchColumns } from '~/components/search-box';
import { Button, message, Modal, Table, Tag } from 'antd'; import { Button, message, Modal, Table } from 'antd';
import { ColumnsType } from 'antd/es/table'; import { ColumnsType } from 'antd/es/table';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { PilotTrainAPI } from '~/api'; import { PilotTrainAPI } from '~/api';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { InterDataType, PaginationProps } from '~/api/interface'; import { InterDataType, InterReqType, PaginationProps } from '~/api/interface';
import { listOrgPageType } from '~/api/interface/pilotTrainType'; import {
licenceGradeListType,
licenceModelsListType,
licenceTypeListType,
listOrgPageType,
} from '~/api/interface/pilotTrainType';
import { filterObjAttr } from '~/utils';
//机构列表返回类型 //机构列表返回类型
type institutionListType = InterDataType<listOrgPageType>['list']; type institutionListType = InterDataType<listOrgPageType>['list'];
//机型下拉返回类型
type modelsListType = InterDataType<licenceModelsListType>;
//等级下拉返回类型
type gradeListType = InterDataType<licenceGradeListType>;
//执照类型返回类型
type typeListType = InterDataType<licenceTypeListType>;
//机构列表请求参数类型
type listOrgPageParametersType = InterReqType<listOrgPageType>;
const InstitutionsList = () => { const InstitutionsList = () => {
const navigate = useNavigate(); const navigate = useNavigate();
//培训类型下拉 //机型下拉列表
const [modelsList, setModelsList] = useState<modelsListType>([]);
//等级下拉列表
const [gradeList, setGradeList] = useState<gradeListType>([]);
//执照类型列表
const [typeList, setTypeList] = useState<typeListType>([]);
const search: searchColumns[] = [ const search: searchColumns[] = [
{ label: '机构名称', name: '', placeholder: '请输入机构名称', type: 'input' }, { label: '机构名称', name: 'name', placeholder: '请输入机构名称', type: 'input' },
{ label: '培训类型', name: '', placeholder: '请选择培训类型', type: 'select', options: [] }, {
{ label: '选择日期', name: '', placeholder: '请选择日期', type: 'rangePicker', options: [] }, label: '培训类型',
name: 'typeId',
placeholder: '请选择培训类型',
type: 'select',
options: gradeList,
},
{
label: '培训等级',
name: 'gradeId',
placeholder: '请选择培训等级',
type: 'select',
options: typeList,
},
{
label: '培训机型',
name: 'modelsId',
placeholder: '请选择培训机型',
type: 'select',
options: modelsList,
},
{
label: '选择日期',
name: 'time',
placeholder: '请选择日期',
type: 'rangePicker',
options: [],
},
]; ];
const tableColumns: ColumnsType<institutionListType[0]> = [ const tableColumns: ColumnsType<institutionListType[0]> = [
{ {
...@@ -36,7 +80,11 @@ const InstitutionsList = () => { ...@@ -36,7 +80,11 @@ const InstitutionsList = () => {
title: '培训类型', title: '培训类型',
align: 'center', align: 'center',
render: (_text: string, record) => render: (_text: string, record) =>
record.programsDOList.map((v) => <Tag key={v.id}>{v.typeName}</Tag>), record.programsDOList[0].gradeName +
'/' +
record.programsDOList[0].modelsName +
'/' +
record.programsDOList[0].typeName,
width: '20%', width: '20%',
}, },
{ {
...@@ -65,25 +113,28 @@ const InstitutionsList = () => { ...@@ -65,25 +113,28 @@ const InstitutionsList = () => {
pageSize: 10, pageSize: 10,
totalCount: 0, totalCount: 0,
}); });
const [query, setQuery] = useState<listOrgPageParametersType>();
const toAddInstitutions = () => { const toAddInstitutions = () => {
navigate('/pilotTraining/institutionsList/add'); navigate('/pilotTraining/institutionsList/add');
}; };
//机构列表 //机构列表
const getListOrgPage = () => { const getListOrgPage = (query?: listOrgPageParametersType) => {
PilotTrainAPI.getListOrgPage({ pageNo: pagination.pageNo, pageSize: pagination.pageSize }).then( PilotTrainAPI.getListOrgPage({
({ result }) => { pageNo: pagination.pageNo,
pageSize: pagination.pageSize,
...query,
}).then(({ result }) => {
setTableData(result.list || []); setTableData(result.list || []);
pagination.totalCount = result.totalCount; pagination.totalCount = result.totalCount;
setPagination(pagination); setPagination(pagination);
}, });
);
}; };
//分页-监听 //分页-监听
const paginationChange = (pageNo: number, pageSize: number) => { const paginationChange = (pageNo: number, pageSize: number) => {
pagination.pageNo = pageNo; pagination.pageNo = pageNo;
pagination.pageSize = pageSize; pagination.pageSize = pageSize;
getListOrgPage(); getListOrgPage(query);
}; };
//机构删除 //机构删除
const deleteInstitutionsClick = (record: institutionListType[0]) => { const deleteInstitutionsClick = (record: institutionListType[0]) => {
...@@ -107,8 +158,37 @@ const InstitutionsList = () => { ...@@ -107,8 +158,37 @@ const InstitutionsList = () => {
const editInstitutionsClick = (record: institutionListType[0]) => { const editInstitutionsClick = (record: institutionListType[0]) => {
navigate({ pathname: '/pilotTraining/institutionsList/edit', search: `id=${record.id}` }); navigate({ pathname: '/pilotTraining/institutionsList/edit', search: `id=${record.id}` });
}; };
//培训机型下拉
const getLicenceModelsList = () => {
PilotTrainAPI.getLicenceModelsList().then(({ result }) => {
setModelsList(result || []);
});
};
//培训等级下拉
const getLicenceGradeList = () => {
PilotTrainAPI.getLicenceGradeList().then(({ result }) => {
setGradeList(result || []);
});
};
//培训类型下拉
const getLicenceTypeList = () => {
PilotTrainAPI.getLicenceTypeList().then(({ result }) => {
setTypeList(result || []);
});
};
//筛选
const searchSuccess = (value: any) => {
setQuery(filterObjAttr(value, ['time']));
pagination.pageNo = 1;
pagination.pageSize = 10;
getListOrgPage(filterObjAttr(value, ['time']));
};
useEffect(() => { useEffect(() => {
getListOrgPage(); getListOrgPage();
getLicenceModelsList();
getLicenceGradeList();
getLicenceTypeList();
}, []); }, []);
return ( return (
<div className='institutions-list'> <div className='institutions-list'>
...@@ -119,11 +199,13 @@ const InstitutionsList = () => { ...@@ -119,11 +199,13 @@ const InstitutionsList = () => {
新增 新增
</Button> </Button>
} }
searchData={searchSuccess}
/> />
<Table <Table
bordered bordered
columns={tableColumns} columns={tableColumns}
dataSource={tableData} dataSource={tableData}
rowKey='id'
pagination={{ pagination={{
total: pagination.totalCount, total: pagination.totalCount,
pageSize: pagination.pageSize, pageSize: pagination.pageSize,
......
// 不能输入数字,其他可输入 // 不能输入数字,其他可输入
export const exceptNumber = (val: any) => { export const exceptNumber = (val: any) => {
val.target.value = val.target.value.replace(/1?(\d|([1-9]\d+))(.\d+)?$/g, '').replace(/\s/g, ''); val.target.value = val.target.value.replace(/1?(\d|([1-9]\d+))(.\d+)?$/g, '').replace(/\s/g, '');
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论