import React, { Fragment, useState, useMemo } from 'react' import AttachmentItem from '../attachment-item' import CommentItemReplay from '../commonent-item-replay' import { useParams } from 'react-router-dom' import TPMMDEditor from '../../../../tpm/challengesnew/TPMMDEditor' import axios from 'axios' import { markdownToHTML, WordsBtn, getUrl } from 'educoder' import './index.css' const ACCEPT = 3 const REFUSE = 4 export default ({ confirm, item, showNotification, replySuccess, isStudent, isAdmin, homework_status, is_author, commentIndex, onDelete }) => { const [data, setData] = useState({ value: '', isShow: false, mode: 'reply' }) const { studentWorkId, workId } = useParams() const { value, isShow, mode } = data function onCancelMyAppeal() { confirm({ content:

撤销申诉后,无法再对本评阅记录进行申诉

是否确认撤销申诉

, onOk: () => { const url = `/student_works/${studentWorkId}/cancel_appeal.json` axios.post(url, { score_id: item.id }) .then((response) => { if (response.data.status == 0) { showNotification('撤销成功') replySuccess() } }) .catch(function (error) { console.log(error) }) } }) } function onDeleteReply(source) { confirm({ content: `是否确认删除?`, onOk: () => { const url = `/commons/delete.json` axios.delete(url, { data: { object_id: source.id, object_type: 'journals_for_message' } }) .then((response) => { if (response.data.status == 0) { replySuccess() setData({ ...data, isShow: false }) } }) .catch(function (error) { console.log(error) }) } }) } function onDeleteHandler() { onDelete(item) } function onSubmit() { if (!value || !value.trim()) { showNotification('内容不能为空') return } let url = `/student_works/${studentWorkId}/appeal_anonymous_score.json` if (mode === 'reply') { url = `/student_works/${studentWorkId}/add_score_reply.json` axios.post(url, { score_id: item.id, comment: value }).then((result) => { if (result.data.status == 0) { replySuccess() setData({ ...data, isShow: false }) } }).catch((error) => { console.log(error) }) } } function callback(type, source) { if (type === 'refuse-appeal-score') { onDealAppealScore(REFUSE, source) } if (type === 'accept-appeal-score') { onDealAppealScore(ACCEPT, source) } if (type === 'cancel-my-appeal') { onCancelMyAppeal() } if (type === 'del-replay-item') { onDeleteReply(source) } } function onDealAppealScore(mode, source) { confirm({ content:
{mode == ACCEPT ? '此匿评成绩将被废弃,评阅人的作品将被违规扣分' : '此匿评成绩将被认为合理'}
是否确认{mode == ACCEPT ? '接受申诉' : '拒绝申诉'}
, onOk: () => { const url = `/student_works/${studentWorkId}/deal_appeal_score.json` axios.post(url, { score_id: source.score_id, status: mode }) .then((response) => { if (response.data.status == 0) { showNotification(`${mode == ACCEPT ? '接受申诉' : '拒绝申诉'}成功`) replySuccess() } }) .catch(function (error) { console.log(error); }); } }) } const pre = getUrl() const _origin = '' function onChangeHandler(value) { setData({ ...data, value }) } function onReplayHandler() { setData({ ...data, isShow: true, mode: 'reply' }) } function onAppealHandler() { setData({ ...data, isShow: true, mode: 'appeal' }) } function onCancel() { setData({ ...data, isShow: false }) } const { id, image_url, user_login, username, comment_role, time, score, is_invalid, can_appeal, appeal_status, content, attachments, journals } = item const isAnonymous = homework_status && homework_status.indexOf('匿评中') != -1 const isAppealing = homework_status && homework_status.indexOf('申诉中') != -1 const md = useMemo(() => { return content ? markdownToHTML(content) : '' }, [content, id]) return (
用户头像
{username}({comment_role}) {time} {score !== null && {score}分} {is_invalid ? 失效 : 回复 {(isAppealing || isAnonymous) && can_appeal && appeal_status == 0 && 申诉} } {item.delete && isAdmin() && 删除}
{!!md ?
: {"暂未写评语"}} {attachments && attachments.length > 0 ?
{attachments.map((attaItem, key) => )}
: null} {journals && journals.length > 0 ?
{journals.map(journal => )}
: null }
{isShow && }
) }