zhengpengju 3 years ago
parent e1602ecd03
commit 950507e376

@ -3,7 +3,7 @@
*/ */
//import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; //import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Col, InputNumber, message, Row } from 'antd'; import { Button, Col, Input, InputNumber, message, Row } from 'antd';
//import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; //import { FooterToolbar, PageContainer } from '@ant-design/pro-layout';
//import { useRequest } from 'umi'; //import { useRequest } from 'umi';
//import { queryFakeList } from './service'; //import { queryFakeList } from './service';
@ -16,11 +16,13 @@ import { forwardRef, ReactText, useEffect, useImperativeHandle, useRef, useState
//import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons'; //import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons';
import { useParams, useRequest, history, useRouteMatch } from 'umi'; import { useParams, useRequest, history, useRouteMatch } from 'umi';
import { queryCourseView } from '@/pages/course/option/service'; import { queryCourseView } from '@/pages/course/option/service';
import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; //import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service';
//import ProForm, { ProFormSelect } from '@ant-design/pro-form'; //import ProForm, { ProFormSelect } from '@ant-design/pro-form';
import type { ActionType, ProColumns } from '@ant-design/pro-table'; import type { ActionType, ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import { manualPaper } from '../service'; import { manualPaper } from '../service';
import { queryQuestionWithoutList } from '../../service';
export type TableListItem = { export type TableListItem = {
id: string; id: string;
@ -58,7 +60,7 @@ const AutoSelector = (props: any, ref: any) => {
/** 获取常规题库试题数量 */ /** 获取常规题库试题数量 */
const { data: normalSum } = useRequest(()=>{ const { data: normalSum } = useRequest(()=>{
return queryQuestionList({subject_id: params?.id, page_number: 1, page_size: 1, type: 0}) return queryQuestionWithoutList({subject_id: params?.id, page_number: 1, page_size: 1, type: 0})
},{ },{
formatResult: (result) => { formatResult: (result) => {
return result.totalRow; return result.totalRow;
@ -67,7 +69,7 @@ const AutoSelector = (props: any, ref: any) => {
/** 获取资质考试题库试题数量 */ /** 获取资质考试题库试题数量 */
const { data: attestationSum } = useRequest(()=>{ const { data: attestationSum } = useRequest(()=>{
return queryQuestionList({subject_id: params?.id, page_number: 1, page_size: 1, type: 1}) return queryQuestionWithoutList({subject_id: params?.id, page_number: 1, page_size: 1, type: 1})
},{ },{
formatResult: (result) => { formatResult: (result) => {
return result.totalRow; return result.totalRow;
@ -89,6 +91,7 @@ const AutoSelector = (props: any, ref: any) => {
return ( return (
<> <>
<Row><Col style={{padding: '10px 0 10px 10px', lineHeight:'32px'}}></Col><Col style={{padding:10}}><Input name='paper_count' /></Col><Col style={{color:'#cccccc'}}><span style={{display: 'block', margin: '15px 0 0 10px'}}></span></Col></Row>
<Row><Col style={{padding:10}}></Col></Row> <Row><Col style={{padding:10}}></Col></Row>
<Row style={{padding:5}}> <Row style={{padding:5}}>
<Col offset={1} span={5}><span style={{lineHeight:'32px'}}>{`常规题库 ( ${normalQuestionSum} 道题)`}</span></Col> <Col offset={1} span={5}><span style={{lineHeight:'32px'}}>{`常规题库 ( ${normalQuestionSum} 道题)`}</span></Col>

@ -3,7 +3,7 @@
*/ */
//import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; //import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Form, InputNumber, message } from 'antd'; import { Button, Form, Input, InputNumber, message } from 'antd';
//import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; //import { FooterToolbar, PageContainer } from '@ant-design/pro-layout';
//import { useRequest } from 'umi'; //import { useRequest } from 'umi';
//import { queryFakeList } from './service'; //import { queryFakeList } from './service';
@ -50,12 +50,13 @@ type DataSourceType = {
// 需要处理 // 需要处理
// React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。 // React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。
const AutoSelector = (props: any, ref: any) => { const AutoSelector = (props: any, ref: any) => {
const formRef = useRef()
/** 获取章节数据 */ /** 获取章节数据 */
// 获取主题id // 获取主题id
console.log('props subject_id', props) console.log('props subject_id', props)
const { subjectId, questionType } = props; const { subjectId, questionType } = props;
console.log('questionType', questionType) console.log('questionType', questionType)
const [typeScore, setTypeScore] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}] const [typeChapterCount, setTypeChapterCount] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}]
//const [dataSource, setDataSource] = useState<DataSourceType[]>(() => defaultData); //const [dataSource, setDataSource] = useState<DataSourceType[]>(() => defaultData);
@ -72,22 +73,41 @@ const AutoSelector = (props: any, ref: any) => {
]; ];
/* 动态设置题型列 */ /* 动态设置题型列 */
questionType?.forEach((item)=>{ questionType?.forEach((item, idx)=>{
columns.push({ columns.push({
title: <>{item?.name} <Form.Item style={{margin:0}} name={`type${item?.code}`}><InputNumber defaultValue={0} style={{marginLeft:5}} /></Form.Item></>, title: <>{item?.name} <Form.Item style={{margin:0}} name={['type',idx,'sum']}><Input type='text' defaultValue={0} onInput={(e)=>{
}}
onChange={(e)=>{
const val = e.currentTarget.value;
console.log('onchange==', val)
const values = formRef?.current.getFieldsValue()
console.log('values', values)
const {questionType} = values;
const avg = val / questionType[idx].length // 平均数
const rem = val % questionType[idx].length // 余数
const _questionType = questionType[idx].map((item, key)=>{return key < rem ? Math.ceil(avg) : Math.floor(avg)})
console.log('questionTypeData', _questionType)
questionType[idx] = _questionType;
//[[10]]
formRef?.current.setFieldsValue({questionType: questionType})
}}
/></Form.Item></>,
//key: 'code', //key: 'code',
dataIndex: `type${item?.code}`, dataIndex: `type${item?.code}`,
render: ( item, { defaultRender, ...rest }, form) => { render: ( _dom, record, index) => {
return <Form.Item style={{margin:0}} ><InputNumber min={0} max={3} defaultValue={1} type='number' return <Form.Item style={{margin:0}} name={['questionType', idx, index]}><Input min={0} max={3} defaultValue={0} type='text'
onChange={(value)=>{ onChange={(value)=>{
// console.log('record', record)
const _data = []; //{chapter_id: record?.chapter_id, count:0}
console.log('typeScore',typeScore) /*
typeScore?.forEach((item, key)=>{ console.log('typeChapterCount',typeChapterCount)
_data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)}) const data = typeChapterCount?.map((item, key)=>{
data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)})
}) })
setTypeScore(_data) setTypeChapterCount(data)
console.log('setTypeScore',typeScore) console.log('setTypeChapterCount---',typeChapterCount)
*/
}} }}
/></Form.Item>; /></Form.Item>;
}, },
@ -105,13 +125,18 @@ const AutoSelector = (props: any, ref: any) => {
return ( return (
<> <>
<EditableProTable <Button onClick={()=>{ console.log('formRef',formRef.current.getFieldsValue()); formRef.current.setFieldsValue({questionType:[['10']]})}}>show</Button>
<Form ref={formRef}>
<ProTable
bordered bordered
recordCreatorProps={false} pagination={false}
//recordCreatorProps={false}
//formRef={formRef}
headerTitle={false} headerTitle={false}
columns={columns} columns={columns}
rowKey="id" rowKey="id"
key="id" key="id"
search={false}
// value={dataSource} // value={dataSource}
request={async (value) => { request={async (value) => {
const { data } = await queryListChapterBySubject({ const { data } = await queryListChapterBySubject({
@ -120,13 +145,14 @@ const AutoSelector = (props: any, ref: any) => {
page_size: 1000, page_size: 1000,
}); });
console.log('data--',data) console.log('data--',data)
/*
const _data = []; const _data = [];
data?.list.forEach((item)=>{ data?.list.forEach((item)=>{
_data.push({ _data.push({
id: item?.chapter_id, id: item?.chapter_id,
chapter_name: item?.chapter_name, chapter_name: item?.chapter_name,
}) })
}) })*/
//chapter_name //chapter_name
return {data: data?.list}; return {data: data?.list};
/* /*
@ -143,6 +169,7 @@ const AutoSelector = (props: any, ref: any) => {
}} }}
toolBarRender={false} toolBarRender={false}
/> />
</Form>
</> </>
); );
}; };

Loading…
Cancel
Save