|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
import React, { Component } from'react'; |
|
|
|
|
import {Form, Input, Button, Table, Select, message, Modal} from 'antd'; |
|
|
|
|
import { TableRowSelection } from 'antd/lib/table/interface'; |
|
|
|
|
import {deleteSingle, deleteMultiple, findIndustry, getList} from 'api/examPaper'; |
|
|
|
|
import {deleteSingle, deleteMultiple, findIndustry, getList, updatePaperStatus, batchUpdatePaperStatus} from 'api/examPaper'; |
|
|
|
|
|
|
|
|
|
const { Option } = Select; |
|
|
|
|
|
|
|
|
@ -56,6 +56,7 @@ class ExamPaperList extends Component<any, States> { |
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
this.findIndustry(); |
|
|
|
|
this.getList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 监管行业
|
|
|
|
@ -180,6 +181,80 @@ class ExamPaperList extends Component<any, States> { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 更新试卷状态
|
|
|
|
|
updatePaperStatus = (id: number, paperStatus: number) => { |
|
|
|
|
const newStatus = paperStatus === 0? '启用' : '停用'; |
|
|
|
|
Modal.confirm({ |
|
|
|
|
title: `确认${newStatus}`, |
|
|
|
|
content: `你确定要${newStatus}这张试卷吗?`, |
|
|
|
|
onOk: () => { |
|
|
|
|
updatePaperStatus(id, paperStatus).then((res) => { |
|
|
|
|
const isSuccess = res.data; |
|
|
|
|
if (isSuccess) { |
|
|
|
|
message.success(`${newStatus}成功`); |
|
|
|
|
const status = paperStatus === 0? 1 : 0; |
|
|
|
|
this.setState((prevState) => ({ |
|
|
|
|
list: prevState.list.map((item) => |
|
|
|
|
item.id === id? { ...item, paperStatus: status } : item |
|
|
|
|
) |
|
|
|
|
})); |
|
|
|
|
} else { |
|
|
|
|
message.error(`${newStatus}失败,请稍后重试`); |
|
|
|
|
} |
|
|
|
|
}).catch(() => { |
|
|
|
|
message.error(`${newStatus}时发生错误,请检查`); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onCancel: () => { |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 批量更新试卷状态
|
|
|
|
|
batchUpdatePaperStatus = (paperStatus: number) => { |
|
|
|
|
const { selectedRowKeys } = this.state; |
|
|
|
|
if (selectedRowKeys.length === 0) { |
|
|
|
|
message.warning('请选择要操作的试卷'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const newStatus = paperStatus === 0? '启用' : '停用'; |
|
|
|
|
const { list } = this.state; |
|
|
|
|
const selectedRecords = list.filter(record => selectedRowKeys.includes(record.id)); |
|
|
|
|
const invalidRecords = selectedRecords.filter(record => record.paperStatus !== paperStatus); |
|
|
|
|
if (invalidRecords.length > 0) { |
|
|
|
|
message.warning(`部分试卷已经处于${newStatus}状态,请重新选择`); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Modal.confirm({ |
|
|
|
|
title: `确认${newStatus}`, |
|
|
|
|
content: `你确定要${newStatus}这些选中的试卷吗?`, |
|
|
|
|
onOk: () => { |
|
|
|
|
batchUpdatePaperStatus(selectedRecords) |
|
|
|
|
.then((res) => { |
|
|
|
|
const isSuccess = res.data; |
|
|
|
|
if (isSuccess) { |
|
|
|
|
message.success(`${newStatus}成功`); |
|
|
|
|
const status = paperStatus === 0? 1 : 0; |
|
|
|
|
this.setState((prevState) => ({ |
|
|
|
|
list: prevState.list.map((item) => |
|
|
|
|
selectedRowKeys.includes(item.id) |
|
|
|
|
? { ...item, paperStatus: status } : item |
|
|
|
|
) |
|
|
|
|
})); |
|
|
|
|
} else { |
|
|
|
|
message.error(`${newStatus}失败,请稍后重试`); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
message.error(`${newStatus}时发生错误,请检查`); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onCancel: () => { |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const onFinish = (values: object) => { |
|
|
|
|
const _listQuery = { ...this.state.listQuery, ...values }; |
|
|
|
@ -225,7 +300,7 @@ class ExamPaperList extends Component<any, States> { |
|
|
|
|
{ title: '状态', dataIndex: 'paperStatus', key: 'paperStatus', align: 'center', width: 60, |
|
|
|
|
render: (paperStatus:any) => { |
|
|
|
|
if (paperStatus === 0) { |
|
|
|
|
return '禁用'; |
|
|
|
|
return '停用'; |
|
|
|
|
} else if (paperStatus === 1) { |
|
|
|
|
return '启用'; |
|
|
|
|
} |
|
|
|
@ -234,7 +309,7 @@ class ExamPaperList extends Component<any, States> { |
|
|
|
|
{ title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 200, |
|
|
|
|
render: (record: any) => [ |
|
|
|
|
<span className='mr10 link' onClick={() => { |
|
|
|
|
this.setState({title: '删除', modalWidth: '85%'}) |
|
|
|
|
this.setState({title: '编辑', modalWidth: '85%'}) |
|
|
|
|
this.props.history.push(`/questionUp/${record.id}`); |
|
|
|
|
}}>编辑</span>, |
|
|
|
|
<span className='mr10 link' onClick={() => { |
|
|
|
@ -242,11 +317,10 @@ class ExamPaperList extends Component<any, States> { |
|
|
|
|
this.deleteSingle(record.id); |
|
|
|
|
}}>预览</span>, |
|
|
|
|
<span className='mr10 link' onClick={() => { |
|
|
|
|
this.setState({title: '停用', modalWidth: '85%'}) |
|
|
|
|
this.deleteSingle(record.id); |
|
|
|
|
}}>停用</span>, |
|
|
|
|
this.updatePaperStatus(record.id, record.paperStatus); // 调用更新状态的方法
|
|
|
|
|
}}>{record.paperStatus === 0? '启用' : '停用'}</span>, // 根
|
|
|
|
|
<span className="mr10 link" onClick={() => { |
|
|
|
|
this.setState({title: '停用', modalWidth: '85%'}) |
|
|
|
|
this.setState({title: '删除', modalWidth: '85%'}) |
|
|
|
|
this.deleteSingle(record.id); |
|
|
|
|
}}>删除</span> |
|
|
|
|
] |
|
|
|
@ -328,10 +402,10 @@ class ExamPaperList extends Component<any, States> { |
|
|
|
|
<Button type="default" onClick={this.deleteMultiple}>删除</Button> |
|
|
|
|
</Form.Item> |
|
|
|
|
<Form.Item> |
|
|
|
|
<Button type="default" onClick={this.deleteMultiple}>停用</Button> |
|
|
|
|
<Button type="default" onClick={() => this.batchUpdatePaperStatus(1)}>停用</Button> |
|
|
|
|
</Form.Item> |
|
|
|
|
<Form.Item> |
|
|
|
|
<Button type="default" onClick={this.deleteMultiple}>启用</Button> |
|
|
|
|
<Button type="default" onClick={() => this.batchUpdatePaperStatus(0)}>启用</Button> |
|
|
|
|
</Form.Item> |
|
|
|
|
<Form.Item> |
|
|
|
|
<Button type="primary" onClick={handleAddQuestion}>新增试卷</Button> |
|
|
|
|