提交 343ee8bf 作者: 龚洪江

修复:机构缺陷问题

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