import { debounce } from '@utils' import req from '@utils/request' import { Input, Modal, Spin, message } from 'antd' import React, { Component, Fragment, createRef } from 'react' import { apiName } from '../../constant' import OptionInputBox from '../option-input-box' import RankLabelBox from '../rank-label-box' import RepeatContentBox from '../repeat-content-box' import './index.less' const defalutLabel = '请使用富文本编辑器输入选项内容' export default class MultipleQuestions extends Component { constructor(props) { super(props) this.state = { subjectName: '', // 题目 isDisabledSubmit: true, //是否禁止输入 isShowModalBox: false, // 是否展示重复率弹框 isSubmit: true // 是否支持提交 } } rankLabelBox = createRef() optionInputBox = OptionInputBox | null currentActive = [] // 选项列表 scoreValue = '' // 分数 subjectAnalysis = '' //试题解析 rankId = 1 //职级 subjectAnswer = '' // 选项内容 firstCategoryValue = '' // 一级分类的值 secondCategoryValue = [] // 二级分类的值 thirdCategoryValue = [] // 三级标签的值 repeatInfo = {} // 重复率 /** * 输入题目 * @param {*} e */ onChangeSubjectName = e => { let str = e.target.value.trim() this.setState( { subjectName: str }, () => { // this.rankLabelBox.getThirdCategoryList(); let isDisabledSubmit = this.checkData() this.setState({ isDisabledSubmit }) } ) } /** * 一次确认录入 */ onSubmit = debounce(() => { const { subjectName, isDisabledSubmit, isSubmit } = this.state if (isDisabledSubmit || !isSubmit) { return } if (!!!subjectName) { message.warning('请输入题目名称') return } if (!this.currentActive.length) { message.warning('请录入答案') return } if (!!!this.firstCategoryValue) { message.warning('请选择一级分类') return } if (this.secondCategoryValue.length <= 0) { message.warning('请选择二级分类') return } if (this.thirdCategoryValue.length <= 0) { message.warning('请选择三级标签') return } this.setState({ isSubmit: false }) let params = { subjectName: subjectName, subjectDifficult: this.rankId, subjectType: 2, subjectScore: this.scoreValue, subjectParse: this.subjectAnalysis, categoryIds: this.secondCategoryValue.filter(item => item.active).map(t => t.id), labelIds: this.thirdCategoryValue.filter(item => item.active).map(t => t.id), optionList: this.currentActive } req({ method: 'post', data: params, url: apiName.add }) .then(res => { // this.repeatInfo = {} // if (res.data && res.data.insertStatus) { // this.setState( // { // isSubmit: true // }, // () => { // this.successModalConfirm() // } // ) // } else if (!res.data.insertStatus) { // this.repeatInfo = { // repeatDocId: res.data.docId, // 重复题目id // repeatRate: res.data.repeatRate, // 重复率 // repeatSubjectName: res.data.subjectName, // 重复题目 // repeatOptionList: res.data.optionList, // 重复列表项 // repeatSetterErp: res.data.subjectSetterErp, // 出题人erp // repeatSetterName: res.data.subjectSetterName // 出题人姓名 // } // this.setState({ // isShowModalBox: true, // isSubmit: true // }) // } this.setState( { isSubmit: true }, () => { this.successModalConfirm() } ) }) .catch(err => { this.setState({ isSubmit: true }) console.log(err) }) }) /** * 校验是否支持点击按钮 * @returns */ /** * 校验是否支持点击按钮 * @returns */ checkData = () => { const { subjectName } = this.state let list = this.currentActive.filter(item => item.optionContent === defalutLabel) let isDisabledSubmit = false if ( !!!subjectName || list.length > 0 || !!!this.firstCategoryValue || this.secondCategoryValue.length <= 0 || this.thirdCategoryValue.length <= 0 || !!!this.scoreValue ) { isDisabledSubmit = true } return isDisabledSubmit } /** * 取消 */ onCancel = () => { this.currentActive = [] // 选项列表 this.scoreValue = '' // 分数 this.subjectAnalysis = '' //试题解析 this.rankId = 1 this.subjectAnswer = '' // 选项内容 this.firstCategoryValue = '' // 一级分类的值 this.secondCategoryValue = [] // 二级分类的值 this.thirdCategoryValue = [] // 三级标签的值 this.repeatInfo = {} this.rankLabelBox.current.initRankLabel() this.optionInputBox.handleClearOption() this.setState({ subjectName: '', isShowModalBox: false, isSubmit: true // 是否支持提交 }) } /** * 重复率弹框-确认录入 */ onSubmitRepeatModal = debounce( () => { let params = { docId: this.repeatInfo.repeatDocId } req({ method: 'post', data: params, url: apiName.addRepeatInterviewSubject }) .then(res => { if (res.data) { this.successModalConfirm() } else { message.info('请再次确认') } }) .catch(err => { console.log(err) message.error('请再次确认') }) }, 300, true ) /** * 重复率弹框-取消录入 */ onCancelRepeatModal = () => { this.repeatInfo = {} this.setState({ isShowModalBox: false }) } /** * 录入成功的弹框 */ successModalConfirm = () => { Modal.confirm({ title: (