import React from 'react'; import PropTypes from "prop-types"; import { Link } from 'react-router-dom'; import { Spin, Button, Input, Divider, Icon, Tooltip, Form, message, Modal } from 'antd'; import axios from 'axios'; import _ from 'lodash' import './index.scss'; const { confirm } = Modal; class GraduationRequirement extends React.Component { constructor (props) { super(props); this.state = { loading: true, editIndex: null, addState: false, submitState: false, validateState: false, currentEditReq: {}, newRequirement: {}, graduationRequirements: [] } } componentDidMount() { this.getData(); } getData = () => { let { yearId } = this.props; this.setState({ loading: true }); axios.get(`/ec_years/${yearId}/ec_graduation_requirements.json`).then(res => { if(res.status === 200){ this.setState({ graduationRequirements: res.data.graduation_requirements, loading: false }) } }).catch(e => console.log(e)) } showDeleteConfirm = (id) => { if(this.state.editIndex !== null || this.state.addState){ message.error('请先保存其它内容'); return } confirm({ title: '确认删除该毕业要求?', okText: '确认', cancelText: '取消', onOk: () => { this.deleteRequirement(id); }, onCancel() {}, }); } deleteRequirement = (id) => { let { yearId } = this.props; let url = `/ec_years/${yearId}/ec_graduation_requirements/${id}.json`; axios.delete(url).then(res => { if(res){ message.success('操作成功'); this.getData(); } }).catch(e => console.log(e)) } showEditContent = (index) => { let { editIndex, graduationRequirements } = this.state; if(editIndex !== null){ message.error('请先保存其它内容'); return } this.setState({ editIndex: index, currentEditReq: _.cloneDeep(graduationRequirements[index])}) } onEditContentChange = (e) => { let { currentEditReq } = this.state; currentEditReq.content = e.target.value; this.setState({ currentEditReq }); } onEditItemContentChange = (e, index) => { let { currentEditReq } = this.state; currentEditReq.ec_graduation_subitems[index].content = e.target.value; this.setState({ currentEditReq }); } addEditItem = () => { let { currentEditReq } = this.state; currentEditReq.ec_graduation_subitems.push({id: null, content: ''}) this.setState({ currentEditReq }); } removeEditItem = (index) => { let { currentEditReq } = this.state; currentEditReq.ec_graduation_subitems.splice(index, 1); this.setState({ currentEditReq }); } saveContentEdit = () => { let { currentEditReq } = this.state; let contentExist = currentEditReq.content && currentEditReq.content.length !== 0; let errorItem = currentEditReq.ec_graduation_subitems.find(item => !item.content || item.content.length === 0); this.setState({ validateState: !!errorItem || !contentExist }); if(errorItem || !contentExist){ return } this.setState({ submitState: true }, this.updateRequirement); } cancelContentEdit = () => { this.setState({ currentEditReq: {}, editIndex: null, validateState: false }); } updateRequirement = () => { let { yearId } = this.props; let { currentEditReq } = this.state; let url = `/ec_years/${yearId}/ec_graduation_requirements/${currentEditReq.id}.json`; axios.put(url, { content: currentEditReq.content, position: currentEditReq.position, graduation_subitems: currentEditReq.ec_graduation_subitems }).then(res => { if(res){ message.success('操作成功'); this.setState({ submitState: false, editIndex: null }); this.getData(); } }).catch(e => { console.log(e); this.setState({ submitState: false }); }) } showNewReqContent = () => { let { editIndex, graduationRequirements } = this.state; if(editIndex !== null){ message.error('请先保存其它内容'); return } this.setState({ editIndex: -1, addState: true, newRequirement: { content: '', position: graduationRequirements.length + 1, graduation_subitems: [ { id: null, content: '' }, { id: null, content: '' }, { id: null, content: '' }, ] } }) } onNewReqContentChange = (e) => { let { newRequirement } = this.state; newRequirement.content = e.target.value; this.setState({ newRequirement }); } onNewReqItemContentChange = (e, index) => { let { newRequirement } = this.state; newRequirement.graduation_subitems[index].content = e.target.value; this.setState({ newRequirement }); } addNewReqItem = () => { let { newRequirement } = this.state; newRequirement.graduation_subitems.push({id: null, content: ''}) this.setState({ newRequirement }); } removeNewReqItem = (index) => { let { newRequirement } = this.state; newRequirement.graduation_subitems.splice(index, 1); this.setState({ newRequirement }); } saveNewReq = () => { let { newRequirement } = this.state; let contentExist = newRequirement.content && newRequirement.content.length !== 0; let errorItem = newRequirement.graduation_subitems.find(item => !item.content || item.content.length === 0); this.setState({ validateState: !!errorItem || !contentExist }); if(errorItem || !contentExist){ return } this.setState({ submitState: true }, this.createRequirement); } cancelNewReq = () => { this.setState({ newRequirement: {}, addState: false, editIndex: null, validateState: false }); } createRequirement = () => { let { yearId } = this.props; let { newRequirement } = this.state; let url = `/ec_years/${yearId}/ec_graduation_requirements.json`; axios.post(url, newRequirement).then(res => { if(res){ message.success('操作成功'); this.setState({ submitState: false, editIndex: null, addState: false }); this.getData(); } }).catch(e => { console.log(e); this.setState({ submitState: false }); }) } render() { let { can_manager } = this.props.year; let { loading, editIndex, addState, submitState, validateState, currentEditReq, graduationRequirements, newRequirement } = this.state; return (
毕业要求(及其指标点)
请结合本专业特色修改毕业要求文字描述及指标点,需完全覆盖12项通用标准 查看详情
导出毕业要求
指标点
内容
{ can_manager && !addState && ( ) }
{ graduationRequirements && graduationRequirements.map((item, index) => { return can_manager && index === editIndex ? (
{ index + 1 }
{ currentEditReq.ec_graduation_subitems.map((subitem, i) => { return (
{ index + 1 }-{ i + 1 }
this.onEditItemContentChange(e, i)} />
this.removeEditItem(i)}/>
) }) }
) : (
{ index + 1 }
{ item.content }
{ can_manager && (
this.showDeleteConfirm(item.id)} /> this.showEditContent(index)}/> { index === graduationRequirements.length - 1 && !addState && ( ) }
) }
{ item.ec_graduation_subitems.map((subitem, i) => { return (
{ index + 1 }-{ i + 1 }
{ subitem.content }
) }) }
) }) } { can_manager && addState && (
{ graduationRequirements.length + 1 }
{ newRequirement.graduation_subitems.map((subitem, i) => { return (
{ graduationRequirements.length + 1 }-{ i + 1 }
this.onNewReqItemContentChange(e, i)} />
this.removeNewReqItem(i)}/>
) }) }
) }
) } } GraduationRequirement.propTypes = { schoolId: PropTypes.string, majorId: PropTypes.string, yearId: PropTypes.string, } export default GraduationRequirement