zhengpengju 3 years ago
parent 19ce053d35
commit a230a706e8

@ -1,5 +1,4 @@
/** 模拟考试 | 资质考试选题 */ /** 模拟考试 | 资质考试选题 */
import { InputNumber, Space, Form, Input} from 'antd'; import { InputNumber, Space, Form, Input} from 'antd';
//import styles from '../style.less'; //import styles from '../style.less';
import { forwardRef, useImperativeHandle, useRef, useState } from 'react'; import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
@ -24,18 +23,15 @@ export type TableListItem = {
}; };
// React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。 // React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。
const ScoreSetter = (props: any, ref: any) => { const ScoreSetter = (props: any, ref: any) => {
const [flag, setFlag] = useState([]) // 分数变更标记
const {questionTypeValues, passScore: passScoreValue } = props const {questionTypeValues, passScore: passScoreValue } = props
const [flag, setFlag] = useState<any>([]) // 分数变更标记
const [typeScore, setTypeScore] = useState(questionTypeValues.map((item: { code: number; score: number; score_harf: number; })=>({question_type:item.code, score: item.score, score_harf: item.score_harf}))) ; // 题型分数数组 [{"question_type": "0","score": "3","score_harf": "0"},] const [typeScore, setTypeScore] = useState(questionTypeValues.map((item: { code: number; score: number; score_harf: number; })=>({question_type:item.code, score: item.score, score_harf: item.score_harf}))) ; // 题型分数数组 [{"question_type": "0","score": "3","score_harf": "0"},]
//const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型 //const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型
//const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]);
//const [addType, setAddType] = useState({name: '', value: 0});
//const [sumScore, setSumScore] = useState(); //const [sumScore, setSumScore] = useState();
const [passScore, setPassScore] = useState(passScoreValue); // 设置通过分数线 const [passScore, setPassScore] = useState(passScoreValue); // 设置通过分数线
//let sumScore = 0 // 总分
//console.log('init........', typeScore)
const formRef = useRef<any>(); const formRef = useRef<any>();
/** 列表项定义 */ /** 列表项定义 */
@ -82,24 +78,22 @@ const ScoreSetter = (props: any, ref: any) => {
<span></span> <span></span>
{ (record?.code === 1) && { (record?.code === 1) &&
<> <>
<span>:</span> <span>:</span>
<Form.Item style={{margin:0}} name={`score_harf`} <Form.Item style={{margin:0}} name={`score_harf`}
rules={[ rules={[
/* /*
{ {
required: true, required: true,
message: '请输入分值!', message: '请输入分值!',
},*/ },*/
]} ]}
><InputNumber min={0} max={99} maxLength={2} type="number" defaultValue={questionTypeValues ? questionTypeValues[index]?.score_harf : 0} placeholder="请输入" size="small" name='score_harf' onChange={(value)=>{ ><InputNumber min={0} max={99} maxLength={2} type="number" defaultValue={questionTypeValues ? questionTypeValues[index]?.score_harf : 0} placeholder="请输入" size="small" name='score_harf' onChange={(value)=>{
// const harf = typeScore?.map((item: { score_harf: any; }, key: number)=>{
const _data = []; return {...item, score_harf: ((index === key) ? value : item?.score_harf)}
typeScore?.forEach((item: { score_harf: any; }, key: number)=>{ })
_data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)}) setTypeScore(harf)
}) }} /></Form.Item>
setTypeScore(_data) <span></span>
}} /></Form.Item>
<span></span>
</> </>
} }
</Space>, </Space>,
@ -117,9 +111,6 @@ const ScoreSetter = (props: any, ref: any) => {
width: 80, width: 80,
defaultValue:()=>{ return 123}, defaultValue:()=>{ return 123},
render: (_text: any, _: any, index: number) => { render: (_text: any, _: any, index: number) => {
//console.log('typeScore---', typeScore)
//console.log('questionTypeValues',questionTypeValues)
//console.log('==score==',typeScore)
return <> return <>
{flag?.indexOf(index) === -1 ? {flag?.indexOf(index) === -1 ?
questionTypeValues[index]?.score * questionTypeValues[index].count : questionTypeValues[index]?.score * questionTypeValues[index].count :

Loading…
Cancel
Save