import React, { Component } from 'react'; import {Link} from 'react-router-dom'; import axios from "axios"; import {Popconfirm} from "antd"; class Attachment extends Component{ constructor(props){ super(props); this.state={ attachments:undefined, canDelete: false, Deleted:[] } } componentDidMount=()=>{ this.getDetail(); } getDetail=()=>{ this.setState({ attachments: this.props.attachments, canDelete: this.props.canDelete }) } deleteAttachment = (id) => { const url = `/attachments/${id}.json` axios.delete(url, { }).then((response) => { if (response.data) { if (response.data.status === 0) { this.setState({ Deleted: this.state.Deleted.concat(id) }); this.props.showNotification("附件删除成功") }else{ this.props.showNotification(response.data.message) } } }).catch(function (error) { console.log(error); }); } render(){ const { Deleted, attachments, canDelete } = this.state; return(
{ attachments ?
{ attachments.map((item,key)=>{ return(
0 && Deleted.indexOf(item.id) !== -1) ? "none" : "block"}} className="mt10 attachment-list-div" > {item.title} {item.filesize} { canDelete ? this.deleteAttachment(item.id)}> : "" }
) }) }
: "" }
) } } export default Attachment;