167 lines
4.9 KiB
JavaScript
167 lines
4.9 KiB
JavaScript
import React from 'react';
|
|
import { Button, message } from 'antd';
|
|
import { getImageUrl } from 'educoder';
|
|
import MDEditor from "../../../../modules/tpm/challengesnew/tpm-md-editor";
|
|
import Upload from "../../../../forge/Upload/Index";
|
|
import Attachments from "../../../../forge/Upload/attachment";
|
|
import UploadImg from "../../../../forge/Images/upload.png";
|
|
import './list.scss';
|
|
import '../../../../forge/Order/order.scss';
|
|
import { useState } from 'react';
|
|
import { Link } from 'react-router-dom';
|
|
import axios from 'axios';
|
|
import { addComment, editComment } from '../../api'
|
|
|
|
function EditComment(props){
|
|
const {owner, projectsId, index} = props.match.params;
|
|
const {current_user, current_user:{login}, docId, showNotification, reloadComment, cancelMd, parentId, replyId, updateId, showUserImg=true} = props;
|
|
const [content, setContent] = useState(props.content);
|
|
const [quillFlag, setQuillFlag] = useState(false);
|
|
// 确认评论按钮loading效果
|
|
const [journalSpin, setJournalSpin] = useState(false);
|
|
const [atWhoLoginList, setAtWhoLoginList] = useState(undefined);
|
|
const [fileList, setFileList] = useState(undefined);
|
|
const [attachmentClean, setAttachmentClean] = useState(true);
|
|
const [ save , setSave ] = useState(undefined);
|
|
|
|
useState(()=>{
|
|
setSave(props.defaultFileList);
|
|
},[props.defaultFileList])
|
|
|
|
// 评论点击函数
|
|
function addJournals(){
|
|
if(!content){
|
|
setQuillFlag(true);
|
|
return
|
|
}
|
|
setJournalSpin(true);
|
|
console.log(updateId)
|
|
if(updateId){
|
|
// 修改评论
|
|
const params = {
|
|
id: updateId,
|
|
notes: content,
|
|
attachmentIds: fileList,
|
|
receivers_login:atWhoLoginList
|
|
}
|
|
editComment(docId, params).then(res=>{
|
|
if(res && res.data && res.data.data){
|
|
// 刷新评论列表
|
|
reloadComment();
|
|
message.success('评论成功');
|
|
cancelMd();
|
|
setContent(undefined);
|
|
}
|
|
setJournalSpin(false);
|
|
})
|
|
}else{
|
|
// 新建评论
|
|
const params = {
|
|
parentId: parentId,
|
|
replyId: replyId,
|
|
notes: content,
|
|
attachmentIds: fileList,
|
|
}
|
|
|
|
addComment(docId, params).then(res=>{
|
|
if(res && res.data && res.data.data){
|
|
// 刷新评论列表
|
|
reloadComment();
|
|
message.success('评论成功');
|
|
cancelMd();
|
|
setContent(undefined);
|
|
}
|
|
setJournalSpin(false);
|
|
})
|
|
}
|
|
};
|
|
function deleteLoad(id){
|
|
let arr = [];
|
|
let list = save;
|
|
if(list && list.length>0 ){
|
|
arr = list.filter(i=>i.id !== id);
|
|
}
|
|
setFileList(arr.map(i=>{return i.id}));
|
|
setSave(arr);
|
|
}
|
|
function UploadFunc(f){
|
|
let list = [];
|
|
let arr = [];
|
|
if(save && save.length>0 ){
|
|
arr = save.map(i=>{return i.id});
|
|
}
|
|
list = arr && arr.length>0 ? f.concat(arr) : f ;
|
|
setFileList(list);
|
|
};
|
|
|
|
return(
|
|
<div className="grid-item-top pb10">
|
|
<Link
|
|
to={`/${current_user && current_user.login}`}
|
|
className="show-user-link mr10"
|
|
>
|
|
<img
|
|
className="radius"
|
|
src={getImageUrl(
|
|
`/${current_user && current_user.image_url}`
|
|
)}
|
|
alt=""
|
|
width="30"
|
|
height="30"
|
|
style={{display: showUserImg ? '' : 'none'}}
|
|
/>
|
|
</Link>
|
|
<div style={{position:"relative"}}>
|
|
<MDEditor
|
|
placeholder={"添加评论..."}
|
|
height={300}
|
|
mdID={"orderdetail-add-descriptions" + replyId}
|
|
initValue={content}
|
|
onChange={(value)=>{setQuillFlag(false);setContent(value);}}
|
|
changeAtWhoLoginList = {(loginList)=>{setAtWhoLoginList(loginList); setAttachmentClean(true)}}
|
|
owner = {owner}
|
|
projectsId = {projectsId}
|
|
></MDEditor>
|
|
<p className="quillFlagBox">
|
|
{quillFlag && <span>请输入评论内容</span>}
|
|
</p>
|
|
<Upload
|
|
className="commentStyle"
|
|
isComplete={attachmentClean}
|
|
load={UploadFunc}
|
|
icon={
|
|
<img
|
|
src={UploadImg}
|
|
width="58"
|
|
alt=""
|
|
style={{ marginBottom: 15 }}
|
|
/>
|
|
}
|
|
size={100}
|
|
showNotification={showNotification}
|
|
// defaultFileList={props.defaultFileList}
|
|
/>
|
|
{props.defaultFileList && props.defaultFileList.length > 0 &&
|
|
<Attachments
|
|
attachments={props.defaultFileList}
|
|
showNotification={props.showNotification}
|
|
canDelete={true}
|
|
deleteLoad={deleteLoad}
|
|
></Attachments>
|
|
}
|
|
<p className="clearfix mt20">
|
|
<Button
|
|
type="primary"
|
|
onClick={addJournals}
|
|
loading={journalSpin}
|
|
className="mr15 colorButton"
|
|
>
|
|
评论
|
|
</Button>
|
|
<Button className="colorButton2" onClick={()=>{cancelMd()}}>取消</Button>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
export default EditComment; |