import React , {Component} from 'react'; import {Link} from 'react-router-dom'; import axios from 'axios'; import Nav from '../Order/Nav'; import UploadComponent from '../Upload/Index'; import { getImageUrl } from 'educoder'; import {Modal, Col, Form, Input, Tooltip, Popconfirm, Pagination , Spin,Dropdown,Icon,Menu} from 'antd' import NoneData from '../../modules/courses/coursesPublic/NoneData'; import Attachments from '../Upload/attachment' import './merge.css'; const TextArea = Input.TextArea; class MessageCount 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, ismesrge:'none', buttonshow:'none', mergename:'合并请求', mergekey:'merge', title:'', body:'' } } componentDidMount=()=>{ this.getDetail(); } getDetail=()=>{ const { projectsId , mergeId} = this.props.match.params; const url = `/projects/${projectsId}/pull_requests/${mergeId}.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=()=>{ this.props.form.validateFieldsAndScroll((err, values) => { if(!err){ const { data, page, limit, fileList } = this.state; const url = `/issues/${data.issue.id}/journals.json`; axios.post(url,{ ...values, issue_id:data.id, attachment_ids:fileList }).then(result=>{ if(result){ this.props.form.setFieldsValue({ content: "", attachments_ids: undefined }); this.setState({ showFiles: false }) 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.issue.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, showFiles: true }) } }).catch(error=>{ console.log(error); }) } //关闭工单 closedetail=(id)=>{ const {projectsId,orderId} = this.props.match.params; const {data } = this.state; const url = `/projects/${projectsId}/issues/${data.issue.id}/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); }) } //合并请求 prmerge=()=>{ const {projectsId} = this.props.match.params; const {data,title,body,mergekey} = this.state; const url = `/projects/${projectsId}/pull_requests/${data.pull_request.id}/pr_merge.json`; axios.post(url,{ project_id:projectsId, id:data.pull_request.id, do:mergekey, body:body, title:title, }).then(result=>{ if(result){ this.getDetail(); } }).catch(error=>{ console.log(error); }) } //修改评论 updatedetail=(id)=>{ console.log("updtedetail", this.state) const {page, limit,data } = this.state; const {orderId} = this.props.match.params; const url = `/issues/${data.issue.id}/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,data } = this.state; const url = `/issues/${data.issue.id}/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 }) } changtitlepr=(e)=>{ this.setState({ title:e.target.value }) } changbodypr=(e)=>{ this.setState({ body:e.target.value }) } editdetail=(count,status)=>{ this.setState({ countvalue:count, isedit:status }) } submitmerge=()=>{ if(this.state.mergekey==="rebase"){ this.setState({ buttonshow:'block', ismesrge:'none' }) }else{ this.setState({ ismesrge:'block', buttonshow:'block' }) } } nonemerge=()=>{ this.setState({ ismesrge:'none', buttonshow:'none' }) } renderJournalList=(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(
没有评论~
) } } // 翻页 ChangePage=(page)=>{ this.setState({ page, isSpin:true }) const {limit} = this.state; this.getjournalslist(page,limit); } getOption=(e)=>{ this.setState({ mergename:e.item.props.value, mergekey:e.key, title:'', body:'' }) } render(){ const { projectsId,mergeId} = this.props.match.params; const { data,journalsdata, page, limit, search_count, isSpin, isedit, showFiles } = this.state; const { getFieldDecorator } = this.props.form; const { current_user } = this.props; const url = this.props.history.location.pathname; const menu = ( this.getOption(e)}> 合并请求 变基并合并 变基合并 --no-ff 压缩提交并合并 ) 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 ?
    {item.content}
    :
    {this.renderJournalList(item.journal_details)}
    } { item && item.attachments.length > 0 ? : "" }