import React , {Component} from 'react'; import {Link} from 'react-router-dom'; import axios from 'axios'; import Nav from './Nav'; import UploadComponent from '../Upload/Index'; import { getImageUrl } from 'educoder'; import {Modal, Col, Form, Input, Tooltip, Popconfirm, Pagination , Spin} from 'antd' import NoneData from '../../modules/courses/coursesPublic/NoneData'; import Attachments from '../Upload/attachment'; import QuillForEditor from '../quillForEditor'; import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html' const TextArea = Input.TextArea; const options = [ ['bold', 'italic', 'underline'], [{header: [1,2,3,false]}], ['blockquote', 'code-block'], ['link', 'image'], ['formula'] ]; class Detail extends Component{ constructor(props){ super(props); this.state={ data:undefined, isShow:false, imgsrc:'', journalsdata:undefined, //图片区域是否显示 none 隐藏 block 显示 display:'none', titledisplay:'none', countvalue:'', //是否需要编辑 isedit:undefined, fileList:undefined, limit:10, page:1, search_count:undefined, isSpin:false, showFiles: true, quillValue:'', quillFlag:false } } componentDidMount=()=>{ this.getDetail(); } getDetail=()=>{ const { projectsId , orderId} = this.props.match.params; const url = `/projects/${projectsId}/issues/${orderId}.json`; axios.get(url).then((result)=>{ if(result){ this.setState({ data:result.data }) this.getjournalslist(); } }).catch((error)=>{ console.log(error); }) } handleok=() => { this.setState({ isShow:false }); }; handleCancel=()=>{ this.setState({ isShow:false }); } imgshow=()=>{ this.setState({ isShow:true }); }; //添加评论 addjournals=()=>{ const { quillValue } = this.state; if(!quillValue){ this.setState({ quillFlag:true }) return; } let _html = ''; try { _html = new QuillDeltaToHtmlConverter(quillValue.ops, {}).convert(); } catch (error) { console.log(error); } this.props.form.validateFieldsAndScroll((err, values) => { if(!err){ const { data, page, limit, fileList } = this.state; const url = `/issues/${data.id}/journals.json`; axios.post(url,{ ...values, content:_html, issue_id:data.id, attachment_ids:fileList }).then(result=>{ if(result){ this.props.form.setFieldsValue({ content: "" }); this.setState({ showFiles: false, quillValue:'' }) this.getjournalslist(page, limit); this.props.showNotification("评论成功!"); // this.UploadFunc(undefined) } }).catch(error=>{ console.log(error); }) } }) } //获取评论信息 getjournalslist=(page, limit)=>{ const { data} = this.state; const url = `/issues/${data.id}/journals.json`; let id=data.id; axios.get(url,{ params:{ id,page,limit } }).then(result=>{ if(result){ this.setState({ journalsdata:result.data, search_count:result.data.journals_count, isSpin:false, fileList:undefined, }) } }).catch(error=>{ console.log(error); }) } //删除工单信息 deletedetail=(id)=>{ const { projectsId , orderId} = this.props.match.params; const url = `/projects/${projectsId}/issues/${orderId}.json`; axios.delete(url,{ data: { project_id: projectsId, id:id } }).then((result)=>{ if(result){ this.props.history.push(`/projects/${projectsId}/orders`); } }).catch((error)=>{ console.log(error); }) } //关闭工单 closedetail=(id)=>{ const {projectsId,orderId} = this.props.match.params; const url = `/projects/${projectsId}/issues/${orderId}/close_issue.json`; axios.post(url,{ project_id:projectsId, id:orderId, status_id:id, }).then(result=>{ if(result){ this.getDetail(); } }).catch(error=>{ console.log(error); }) } //修改评论 updatedetail=(id)=>{ const {page, limit } = this.state; const {orderId} = this.props.match.params; const url = `/issues/${orderId}/journals/${id}.json`; axios.put(url,{ issue_id:orderId, id:id, content:this.state.countvalue }).then(result=>{ if(result){ this.setState({ isedit: undefined }) this.getjournalslist(page, limit); } }).catch(error=>{ console.log(error); }) } // 获取上传后的文件id数组 UploadFunc=(fileList)=>{ this.setState({ fileList }) } //删除评论 deleteorder=(id)=>{ const { orderId} = this.props.match.params; const { page, limit } = this.state; const url = `/issues/${orderId}/journals/${id}.json`; axios.delete(url,{ data: { issue_id: orderId, id:id } }).then((result)=>{ if(result){ this.getjournalslist(page,limit) } }).catch((error)=>{ console.log(error); }) } changmodelname=(e)=>{ this.setState({ countvalue:e.target.value }) } editdetail=(count,status)=>{ this.setState({ countvalue:count, isedit:status }) } renderJournalList=(list)=>{ // console.log(list); if(list && list.length >0){ return( list.map((item,key)=>{ return(
{item.detail}: {item.old_value && item.old_value.length > 0 ? "更新为" : "新增"} {item.value && item.value.length > 0 ? item.detail === "标签" ? {item.value[0].name} : item.value : "无" }
) }) ) }else{ return(
没有评论~
) } } //复制 copydetail=()=>{ const {projectsId,orderId} = this.props.match.params; const url = `/projects/${projectsId}/issues/${orderId}/copy.json`; axios.post(url,{ project_id:projectsId, id:orderId, }).then(result=>{ if(result){ this.props.history.push(`/projects/${projectsId}/orders/${result.data.issue_id}/copyetail`); } }).catch(error=>{ console.log(error); }) } // 翻页 ChangePage=(page)=>{ this.setState({ page, isSpin:true }) const {limit} = this.state; this.getjournalslist(page,limit); } // 判断是否重新上传文件 changeIsComplete=(flag)=>{ this.setState({ showFiles:flag }) } onContentChange=(value)=>{ this.setState({ quillValue:value }) } render(){ const { projectsId,orderId} = this.props.match.params; const { data,journalsdata, page, limit, search_count, isSpin, isedit, showFiles , quillValue , quillFlag } = this.state; const { getFieldDecorator } = this.props.form; const { current_user } = this.props; const Paginations = ( { search_count > limit ?
:"" }
) const renderList =()=>{ if(journalsdata && journalsdata.issue_journals && journalsdata.issue_journals.length>0 ){ return(
{ journalsdata.issue_journals.map((item,key)=>{ return(
  • {item.user_name} 评论于 {item.created_at}

    this.editdetail(item.content,item.id)} className="detail_edit_action">编辑 this.deleteorder(item.id)}> 删除
    { item.content ? :
    {this.renderJournalList(item.journal_details)}
    } { item && item.attachments && item.attachments.length > 0 ? : "" }