import React, { Component } from "react";
import { Form, Input, Button, message, Modal, Spin, Table } from "antd";
import { ShowModal, splitUrl, getAccountName, getVehicleName, getTypeName, commonAdd, dealBigMoney } from "../../../tools"
import ImgList from "../../../common/imgList";
import ReactToPrint from "react-to-print";
import moment from "moment";
import $ from "jquery/src/ajax";
import './accountReview.less';
const FormItem = Form.Item;
class AccountDetails extends Component {
constructor(props) {
super(props);
this.state = {
isTable: true,
loading: false,
visible: "",
data: {},
logvisible: false,
logdataSour: [],
logcolumns: [
{
title: "审核人",
dataIndex: "auditorName",
key: "auditorName"
},
{
title: "操作",
dataIndex: "status",
key: "status",
width: 120,
render: (text, record) => {
return (
{["【发起】", "【通过】", "【完成】", "【驳回】", "【重新发起】"][text]}
{this.state.processStatus == record.processStatus && !record.id &&
审核中...}
);
},
},
{
title: "操作时间",
dataIndex: "createTimeStr",
key: "createTimeStr",
width: 88,
},
{
title: "备注",
dataIndex: "remarks",
key: "remarks",
render: (text, record) => {
return (
{text}
)
}
}
],
};
}
componentDidMount() {
const { id } = this.props
!!id && this.getDetails(id)
}
// 报销信息详情
getDetails(id) {
this.setState({
loading: true,
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/expenseAccount/selectById",
data: { id, },
success: function (data) {
ShowModal(this);
this.setState({
loading: false,
});
if (data.error.length === 0) {
this.setState({
data: data.data,
imgs: data.data.attachmentUrl
? splitUrl(data.data.attachmentUrl, ",", globalConfig.avatarHost + "/upload")
: [],
})
this.getAccountList(id)
this.getLogData(id)
} else {
message.warning(data.error[0].message)
}
}.bind(this),
}).always(
function () {
this.setState({
loading: false,
});
}.bind(this)
);
}
// 报销费用详情
getAccountList(eaid) {
const { data } = this.state
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/expenseAccount/details/list",
data: { eaid, },
success: function (datas) {
if (datas.error.length === 0) {
let sum = 0
for (var i = 0; i < datas.data.length; i++) {
sum = commonAdd(sum, datas.data[i].amount)
}
let leftList = JSON.parse(JSON.stringify(datas.data)) || []
let jsonArray = []
if (data.type != 4 && data.type != 5 && data.debitTotalAmount) {
leftList.push({ "other": "预借支", "amount": data.debitTotalAmount },)
}
if (data.type != 4 && data.type != 5) {
leftList.push(
{ "other": "总金额", "amount": sum },
{ "other": "实报金额", "amount": (sum > data.debitTotalAmount) ? commonAdd(sum, -data.debitTotalAmount) : 0 })
}
if (data.type == 1) {
// 差旅费
jsonArray = [
{ "head": `支付公司:${data.payDepName}` },
{ "head": `事由:${data.remarks}` },
{ "head": `公出企业:${data.userNames}` },
{ "head": `公出地点:${data.districtName}` },
{ "head": `时间:${moment(data.releaseStartStr).format('YYYY-MM-DD HH:mm') + " 至 " + moment(data.releaseEndStr).format('YYYY-MM-DD HH:mm')}` },
{ "head": `公出时长:${data.duration}` },
]
} else if (data.type == 3) {
// 第三方付款
jsonArray = [
{ "head": `支付公司:${data.payDepName}` },
{ "head": `事由:${data.remarks}` },
]
} else {
// 通用
jsonArray = [
{ "head": `事由:${data.remarks}` },
]
}
let newArray = []
if (jsonArray.length >= leftList.length) {
for (var i = 0; i < leftList.length; i++) {
jsonArray[i] = Object.assign(jsonArray[i], leftList[i])
}
newArray = jsonArray
} else {
for (var i = 0; i < jsonArray.length; i++) {
leftList[i] = Object.assign(jsonArray[i], leftList[i])
}
newArray = leftList
}
newArray.push({}, {})
this.setState({
list: datas.data || [],
newList: newArray,
total: sum,
})
} else {
message.warning(datas.error[0].message);
}
}.bind(this),
}).always(
function () {
this.setState({
loading: false,
});
}.bind(this)
);
}
isHere(list = []) {
for (var i = 0; i < list.length; i++) {
if (!list[i].id) {
this.setState({
processStatus: list[i].processStatus
})
return
}
}
}
// 日志
getLogData(eaid) {
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/expenseAccount/log/list",
data: { eaid },
success: function (data) {
if (data.error.length === 0) {
this.setState({
logdataSour: data.data || []
});
this.isHere(data.data || [])
} else {
message.warning(data.error[0].message);
}
}.bind(this)
}).always(
function () {
}.bind(this)
);
}
// 审核
toExamine(num) {
const { checkData, reason } = this.state
if (!reason) {
message.warning("请填写审核说明~");
return;
}
this.setState({
loading: true,
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/expenseAccount/examine",
data: {
id: checkData.id,
reason,
status: num,//1同意 3驳回
},
}).done(
function (data) {
if (!data.error.length) {
message.success("审核成功!");
this.setState({
visible: "",
reason: "",
showDetails: false,
checkData: {},
});
this.loadData()
} else {
message.warning(data.error[0].message);
}
}.bind(this)
);
}
distinct(arr, key) {
let hash = {};
let result = [];
for (let i = arr.length - 1; i >= 0; i--) {
let value = arr[i][key];
if (!hash[value]) {
hash[value] = true;
result.unshift(arr[i]);
}
}
return result;
}
render() {
const { TextArea } = Input
const { data, visible, list = [], newList, total, logdataSour, } = this.state
const { onCancel } = this.props
const formItemLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
};
const logArray = this.distinct(logdataSour, "auditorName")
// const logArray = logdataSour.filter((item, index, arr) => {
// return arr.findLastIndex((t) => t.auditorName === item.auditorName) === index;
// });
const reimbursement = [
{
title: !!data.contractNo ? `报销至订单:${data.contractNo}` : `报销至部门`,
dataIndex: "head",
key: "head",
width: 275,
render: (text, row, index) => {
if (index < newList.length - 2) {
return {text};
} else if (index == newList.length - 2) {
return {
children:
金额合计(大写):{data.type == 5 ? dealBigMoney(total) : (dealBigMoney((total > data.debitTotalAmount) ? commonAdd(total, -data.debitTotalAmount) : 0))}
¥ {data.type == 5 ? total : (total > data.debitTotalAmount) ? commonAdd(total, -data.debitTotalAmount) : 0}
,
props: {
colSpan: 3,
},
};
} else if (index == newList.length - 1) {
return {
children:
{data.type == 3 && newList.map((item, index) => !!item.invoiceNo &&
付款方式:{"公对公转账"} 发票类型:{["普票", "专票"][item.invoiceType]} 发票号:{item.invoiceNo}
)}
{data.type == 3
? newList.map((item, index) => !!item.payerName &&
收款方式:{item.payerName} {item.openBank} {item.bankAccounts} {item.openBankAddress}
)
: data.type != 5 &&
收款方式:{data.bank} {data.accounts} {data.name}
}
,
props: {
colSpan: 3,
},
};
}
},
},
{
title: '报销数',
children: [
{
title: '付款项目',
dataIndex: "type",
key: "type",
width: 120,
render: (value, row, index) => {
if (index == newList.length - 2) {
return {
props: {
rowSpan: 0,
},
};
} else if (index == newList.length - 1) {
return {
props: {
rowSpan: 0,
},
};
} else {
return
{data.type == 1 &&
// 差旅费显示
{!!row.other
? row.other
: value == 1
? {`交通费(${getVehicleName(row.vehicle, row.vehicleOther)})`}
: {getTypeName(row.type)}}
}
{(data.type == 0 || data.type == 2 || data.type == 4 || data.type == 5) &&
{value == 4 ? "预借支金额" : value == 5 ? "抵扣金额" : !!row.other ? row.other : "申请金额"}
}
{data.type == 3 &&
{!!row.other ? row.other : "申请金额"}
}
;
}
},
},
{
title: '金额(元)',
dataIndex: "amount",
key: "amount",
width: 80,
render: (value, row, index) => {
if (index == newList.length - 2) {
return {
props: {
rowSpan: 0,
},
};
} else if (index == newList.length - 1) {
return {
props: {
rowSpan: 0,
},
};
} else {
return {value};
}
},
}
],
},
{
title: '审核意见',
dataIndex: "shyj",
key: "shyj",
width: 270,
render: (value, row, index) => {
if (index == 0) {
return {
children:
{logArray.map((item, index) => {
return (
// 要求只显示通过的审核
(item.status == 1 || item.status == 2) &&
-
{item.auditorName}:
{["【发起】,", "【通过】,", "【完成】,", "【驳回】,", "【重新发起】,"][item.status]}
{this.state.processStatus == item.processStatus && !item.id && data.status != 0 &&
审核中...}
{item.remarks}
{/* {item.createTimeStr} */}
)
})}
,
props: {
rowSpan: newList.length - 2,
},
};
} else if (index == newList.length - 2) {
return data.type != 0 && 要求付款时间:{data.type == 1 ? moment(data.agreeTimeStr).format('YYYY-MM-DD') : moment(newList[0].agreeTimeStr).format('YYYY-MM-DD')};
} else if (index < newList.length - 1) {
return {
props: {
rowSpan: 0,
},
};
}
},
},
]
return (
{"报销详情-" + getAccountName(data.type, data.typeOther)}
}
footer=""
>
{
this.refs.all = e;
}}
>
{this.state.isTable
?
{getAccountName(data.type, data.typeOther)}
{getAccountName(data.type, data.typeOther).indexOf("报销") == -1 ? "报销清单" : "清单"}
申请部门:{data.appDepName}
报销日期:{moment(data.createTimeStr).format('YYYY年MM月DD日')}
报销公司:{data.appDepName}
报销人:{data.aname}
:
}
(
)}
content={() => this.refs.all}
bodyClass="print-body"
/>
{
//审核弹窗
this.state.visible != "" &&
{ this.toExamine(visible == "adopt" ? 1 : visible == "reject" && 3) }}
okText={this.state.visible == "adopt" ? "通过" : this.state.visible == "reject" && "驳回"}
onCancel={() => {
this.setState({
visible: '',
reason: "",
checkData: {},
})
}}
>
}
{
// 审核日志
this.state.logvisible &&
{
this.setState({
logvisible: false,
})
}}
>
}
);
}
}
export default AccountDetails;