import React,{Component} from 'react';
import $ from "jquery/src/ajax";
import {
    Spin,
    Table,
    message,
    Tooltip, Tabs, Button,Modal
} from "antd";
import {ShowModal,getProjectStatus} from "@/tools";
import FilterColumn from './filterColumn';
import DetailsModal from './detailsModal/index';
import OrderPaymentModal from './component/orderPaymentModal';
import './index.less';
import CheckProject from "../../../components/checkProject";
import PayRecord from "../../../components/checkProject/payRecord";
const { TabPane } = Tabs;
class PayApplyReject extends Component{
    constructor(props) {
        super(props);
        this.state={
            loading: true,
            columns: [
                {
                    title: "支付编号",
                    dataIndex: "key",
                    key: "key",
                },
                {
                    title: "项目编号",
                    dataIndex: "tid",
                    key: "tid",
                },
                {
                    title: "项目名称",
                    dataIndex: "pname",
                    key: "pname",
                },
                {
                    title: "项目状态",
                    dataIndex: "projectStatus",
                    key: "projectStatus",
                    render: (text) => {
                        return getProjectStatus(text);
                    },
                },
                {
                    title: "分类名称",
                    dataIndex: "cname",
                    key: "cname",
                },
                {
                    title: "合同编号",
                    dataIndex: "contractNo",
                    key: "contractNo",
                },
                {
                    title: "订单编号",
                    dataIndex: "orderNo",
                    key: "orderNo",
                },
                {
                    title: "客户名称",
                    dataIndex: "userName",
                    key: "userName",
                    render: (text) => {
                        return (
                             9 ? text : ''}>
                                {text && text.length > 9 ? text.substr(0, 9) + "..." : text}
                            
                        )
                    },
                },
                {
                    title: "部门名称",
                    dataIndex: "depName",
                    key: "depName",
                    render: (text) => {
                        return (
                             9 ? text : ''}>
                                {text && text.length > 9 ? text.substr(0, 9) + "..." : text}
                            
                        )
                    },
                },
                // {
                //     title: "实际总付款",
                //     dataIndex: "costAmount",
                //     key: "costAmount",
                // },
                {
                    title: "付款类型",
                    dataIndex: "chooseType",
                    key: "chooseType",
                    render: (text) => {
                        return text == 0 ? '第三方成本' :
                            text == 1 ? '催款节点' :'官费';
                    },
                },
                {
                    title: "本次申请金额",
                    dataIndex: "applicationAmount",
                    key: "applicationAmount",
                    render: (text) => {
                        return isNaN(parseFloat(text)) ? text : parseFloat(text);
                    }
                },
                {
                    title: "已支付",
                    dataIndex: "paymentAmount",
                    key: "paymentAmount",
                    render: (text) => {
                        return isNaN(parseFloat(text)) ? text : parseFloat(text);
                    },
                },
                {
                    title: "供应商",
                    dataIndex: "companyName",
                    key: "companyName",
                },
                {
                    title: "申请人",
                    dataIndex: "aname",
                    key: "aname",
                },
                {
                    title: "财务名称",
                    dataIndex: "financeName",
                    key: "financeName",
                },
                {
                    title: "状态",
                    dataIndex: "status",
                    key: "status",
                    render: (text) => {
                        return text === 0 ? '审核' :
                            text === 1 ? '待支付' :
                                text === 2 ? '驳回' :
                                    text === 3 ? '已支付' :
                                        text === 4 ? '已取消' : '';
                    },
                },
                {
                    title: "创建时间",
                    dataIndex: "createTime",
                    key: "createTime",
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    key: 'action',
                    render: (text, record) => {
                        return (
                            
                                
                                
                            
                        )
                    }
                }
            ],
            dataSource: [],
            selectedRowKeys: [],
            pagination: {
                defaultCurrent: 1,
                defaultPageSize: 10,
                showQuickJumper: true,
                pageSize: 10,
                onChange: function (page) {
                    this.loadData(page,this.state.searchInfor);
                }.bind(this),
                showTotal: function (total) {
                    return "共" + total + "条数据";
                },
            },
            page: 1,
            selectInfor: {},
            visible: false,
            paymentVisible: false,
            tid: 0,
            projectType: 0,
            payRecordVisible: false,
            orderPaymentsId: 0,
        }
    }
    componentDidMount() {
        this.loadData()
    }
    loadData(pageNo,data={}) {
        this.setState({
            loading: true,
        });
        data.pageNo = pageNo || 1;
        data.pageSize = this.state.pagination.pageSize;
        data.status = 2;   //驳回状态
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/company/selectPaymentList",
            data: data,
            success: function (data) {
                ShowModal(this);
                let theArr = [];
                if (data.error.length || data.data.list == "") {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    this.setState({
                        page: data.data.pageNo
                    });
                    for (let i = 0; i < data.data.list.length; i++) {
                        let thisdata = data.data.list[i];
                        let obj = thisdata;
                        obj.key = thisdata.id;
                        theArr.push(obj);
                    }
                    this.state.pagination.total = data.data.totalCount;
                }
                if (data.data && data.data.list && !data.data.list.length) {
                    this.state.pagination.total = 0;
                }
                this.setState({
                    dataSource: theArr,
                    pageNo: pageNo,
                    pagination: this.state.pagination,
                });
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );
    }
    tableRowClick(record){
        this.setState({
            visible: true,
            selectInfor: record,
        })
    }
    render() {
        return (
            
                
                    付款驳回列表
                
                
                    {
                            this.setState({
                                searchInfor: data
                            });
                            this.loadData(1,data);
                        }}
                        onResetSearch={()=>{
                            this.setState({
                                searchInfor: {}
                            });
                            this.loadData();
                        }}
                    />
                
                
                    
                        {
                                this.tableRowClick(record)
                            }}
                            scroll={{ x: "max-content", y: 0 }}
                            bordered
                            size="small"
                        />
                    
                
                {
                    this.state.visible ?
                        {
                                this.loadData(this.state.page,this.state.searchInfor);
                            }}
                            visitCancel={()=>{
                                this.setState({
                                    visible: false
                                })
                                this.loadData(this.state.page,this.state.searchInfor);
                            }}/> : 
                }
                {this.state.paymentVisible ?
                    {
                            this.setState({
                                paymentVisible: false,
                                tid: 0,
                                projectType: 0,
                            });
                            this.loadData(this.state.page,this.state.searchInfor);
                        }}
                        onSuccess={()=>{
                            this.setState({
                                paymentVisible: false,
                                tid: 0,
                                projectType: 0,
                            });
                            this.loadData(this.state.page,this.state.searchInfor);
                        }}/> :
                    
                }
                {this.state.payRecordVisible ? {
                        this.loadData(this.state.page,this.state.searchInfor);
                        this.setState({
                            payRecordVisible: false,
                            orderPaymentsId: 0,
                            tid: 0,
                            projectType: 0,
                        })
                    }}
                /> : }
            
        );
    }
}
export default PayApplyReject