diff --git a/packages/examination/src/api/examPaper/index.tsx b/packages/examination/src/api/examPaper/index.tsx index 2fba733..1d247e3 100644 --- a/packages/examination/src/api/examPaper/index.tsx +++ b/packages/examination/src/api/examPaper/index.tsx @@ -58,6 +58,17 @@ export function getRandomQuestions(data: any) { }); } +/** + * 获取监管行业下的所有试题 + */ +export function geIndustryQuestions(data: any) { + return axios({ + url: "/ex/examPaper/geIndustryQuestions", + method: 'post', + data: data + }); +} + /** * 添加试卷 */ diff --git a/packages/examination/src/views/examPaper/examPaperAdd.tsx b/packages/examination/src/views/examPaper/examPaperAdd.tsx index 46beb53..5b0c06f 100644 --- a/packages/examination/src/views/examPaper/examPaperAdd.tsx +++ b/packages/examination/src/views/examPaper/examPaperAdd.tsx @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import { Form, Input, Button, Radio, Checkbox, Select, message, Modal, Table } from 'antd'; -import { getRandomQuestions, addExamPaper, editExamPaper, getExamPaperDetail} from 'api/examPaper'; +import { getRandomQuestions, addExamPaper, editExamPaper, getExamPaperDetail, geIndustryQuestions} from 'api/examPaper'; import { getList ,findIndustry} from 'api/question'; import { dictionary } from "../../api/dict"; import TextArea from "antd/es/input/TextArea"; @@ -339,6 +339,22 @@ class ExamPaperAdd extends Component { }); }; + // 题目数量 + compareQuestionCount = async (industryId: string, questionCount: number) => { + if (industryId === null || industryId === undefined || questionCount === null || questionCount === undefined) { + return true; + } + const data = { + industryId: industryId + }; + const res = await geIndustryQuestions(data); + if (res.data) { + const dbCount = res.data; + return questionCount <= dbCount; + } + return true; + }; + render() { const { industryDict, @@ -428,9 +444,22 @@ class ExamPaperAdd extends Component { label="题目数量:" name="questionCount" style={{ width: 240 }} - rules={[{ required: true, message: '请输入题目数量' }]} + rules={[ + { required: true, message: '请输入题目数量' }, + { + message: '输入的题目数量大于该监管行业可获取的题目数量', + validator: async (_, value) => { + const { industryId } = this.formRef.current.getFieldsValue(); + const isValid= await this.compareQuestionCount(industryId, value); + if (!isValid) { + return Promise.reject(new Error('输入的题目数量大于该监管行业可获取的题目数量')); + } + return Promise.resolve(); + } + } + ]} > - +