import React, { Component } from "react";
import { Button, Col, DatePicker, Form, Input, message, Modal, Select, Spin, Table, Tag, Tooltip } from "antd";
import { getApprovedState, getLiquidationStatus, getProcessStatus, getProjectName, splitUrl } from "../../../../tools";
import moment from "moment";
import EnterpriseNameChange from "../../../../common/enterpriseNameChange";
import PicturesWall from "../../../order/orderNew/changeComponent/picturesWall";
import ImgList from "../../../../common/imgList";
import OrderCoor from "../../../order/orderNew/changeComponent/orderCoor";
import ContentUrl from "../../../order/orderNew/contentUrl";
import $ from "jquery";
const FormItem = Form.Item;
const formItemLayout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 14 },
};
class OrderInfor extends Component {
    constructor(props) {
        super(props);
        this.state = {
            contactList: [],
            columns: [
                {
                    title: "业务项目名称",
                    dataIndex: "commodityName",
                    key: "commodityName",
                    render: (text, record) => {
                        return {text}{record.patentTypeName}{"-" + record.id}
                    }
                },
                {
                    title: "项目类别",
                    dataIndex: "cname",
                    key: "cname",
                },
                {
                    title: "项目数量",
                    dataIndex: "commodityQuantity",
                    key: "commodityQuantity",
                    render: (text, record) => {
                        if (record.splitStatus == 1) {
                            return (
                                
                                    {text}{" "}
                                     {
                                            e.stopPropagation();
                                            this.showRes(record);
                                        }}
                                    >
                                        已拆
                                    
                                
                            );
                        } else {
                            return text;
                        }
                    },
                },
                {
                    title: "金额(万元)",
                    dataIndex: "commodityPrice",
                    key: "commodityPrice",
                },
                {
                    title: "负责人",
                    dataIndex: "contacts",
                    key: "contacts",
                },
                {
                    title: "负责人电话",
                    dataIndex: "contactsMobile",
                    key: "contactsMobile",
                },
                {
                    title: "项目状态",
                    dataIndex: "projectStatus",
                    key: "projectStatus",
                    render: (text) => {
                        return getProjectName(text);
                    },
                },
                {
                    title: "主要项目",
                    dataIndex: "main",
                    key: "main",
                    render: (text) => {
                        return text ? "是" : "否";
                    },
                },
                {
                    title: "总年限",
                    dataIndex: "yearSum",
                    key: "yearSum",
                    render: (text, record) => {
                        return (
                            
{["", "一年", "二年", "三年", "四年", "五年"][text]}
                        );
                    }
                },
                {
                    title: "年限",
                    dataIndex: "serviceLife",
                    key: "serviceLife",
                    render: (text, record) => {
                        return (
{!!text && JSON.parse(text).toString()}
                        );
                    }
                },
                {
                    title: "本次派单",
                    dataIndex: "serviceYear",
                    key: "serviceYear",
                    render: (text, record) => {
                        return (
                            {!text ? "" : text}
                        );
                    }
                },
                {
                    title: "项目说明",
                    dataIndex: "taskComment",
                    key: "taskComment",
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        );
                    },
                },
            ]
        }
        this.loaduser = this.loaduser.bind(this);
        this.jiedian = this.jiedian.bind(this);
        this.loadData = this.loadData.bind(this);
    }
    componentDidMount() {
        this.loaduser();
        this.jiedian();
        this.loadData();
    }
    //查看项目列表
    loadData(record) {
        this.setState({
            loading: true,
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/newOrder/getOrderTask",
            data: {
                orderNo: this.props.orderNo
            },
            success: function (data) {
                let theArr = [];
                if (!data.data) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    for (let i = 0; i < data.data.length; i++) {
                        let thisdata = data.data[i];
                        thisdata.key = i;
                        thisdata.sort = thisdata.cSort;
                        thisdata.declarationBatch = thisdata.declarationBatch || undefined;//申报批次
                        thisdata.ifCertificationFee = isNaN(parseInt(thisdata.ifCertificationFee)) ? undefined : thisdata.ifCertificationFee;//是否包含申报批次
                        theArr.push(thisdata);
                    }
                }
                this.setState({
                    dataSource: theArr,
                });
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );
    }
    loaduser() {
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/newOrder/getOrderNewDetail",
            data: {
                orderNo: this.props.orderNo,
            },
            success: function (data) {
                let thisData = data.data;
                if (!thisData) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                    thisData = {};
                }
                if (thisData.approval == 2) {
                    thisData.approval = "特批通过";
                } else if (thisData.approval == 3) {
                    thisData.approval = "特批驳回";
                }
                this.setState({
                    id: thisData.id,
                    kehuId: thisData.buyerId,
                    orderNo: thisData.orderNo, //订单编号
                    orderType: thisData.orderType, //订单类型
                    firstAmount: thisData.firstAmount, //首付金额
                    totalAmount: thisData.totalAmount, //总金额
                    settlementAmount: thisData.settlementAmount, //结算金额
                    liquidationStatus: thisData.liquidationStatus, //清算状态
                    processStatus: thisData.processStatus, //流程状态
                    orderRemarks: thisData.orderRemarks, //订单备注
                    contractNo: thisData.contractNo, //合同编号
                    contacts: thisData.contacts, //联系人
                    contactMobile: thisData.contactMobile, //联系人电话
                    legalPerson: thisData.legalPerson, //法人
                    legalPersonTel: thisData.legalPersonTel, //法人电话
                    orgCodeUrl: thisData.contractPictureUrl
                        ? splitUrl(
                            thisData.contractPictureUrl,
                            ",",
                            globalConfig.avatarHost + "/upload"
                        )
                        : [], //图片地址
                    replenishUrl: thisData.agreementUrl
                        ? splitUrl(
                            thisData.agreementUrl,
                            ",",
                            globalConfig.avatarHost + "/upload"
                        )
                        : [], //图片地址
                    contentUrl: thisData.serviceContent
                        ? splitUrl(
                            thisData.serviceContent,
                            ",",
                            globalConfig.avatarHost + "/upload"
                        )
                        : [], //图片地址
                    signDate: thisData.signDate, //签单时间
                    userName: thisData.userName, //客户名称
                    salesmanName: thisData.salesmanName, //营销员名称
                    salesmanMobile: thisData.salesmanMobile, //营销员电话
                    oldSalesmanName: thisData.oldSalesmanName, //营销员名称
                    oldSalesmanMobile: thisData.oldSalesmanMobile, //营销员电话
                    financeName: thisData.financeName, //财务名称
                    financeMobile: thisData.financeMobile, //财务电话
                    nowFinanceMobile: thisData.nowFinanceMobile,
                    nowFinance: thisData.nowFinance,
                    approval:
                        thisData.approval == 0
                            ? thisData.approval.toString()
                            : thisData.approval,
                    organizationSearch: thisData.orderDep,
                    depName: thisData.depName,
                    status: thisData.status,
                    outsource: thisData.outsource,
                    deleteSign: thisData.deleteSign,
                    orderUid: thisData.uid,
                });
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );
    }
    jiedian() {
        this.setState({
            loadData: true,
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/newOrder/selectOrderDun",
            data: {
                orderNo: this.props.orderNo,
            },
            success: function (data) {
                let theArr = [];
                let thisData = [];
                if (data.error.length || data.data.list == "") {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    for (let i = 0; i < data.data.length; i++) {
                        thisData = data.data[i];
                        theArr.push({
                            key: i,
                            dunSubject: thisData.dunSubject
                                ? thisData.dunSubject.toString()
                                : "", //催款科目
                            id: thisData.id, //节点Id
                            money: thisData.money, //催款金额
                            dunStatus: thisData.dunStatus, //催款状态
                            orderNo: thisData.orderNo,
                        });
                    }
                    this.setState({
                        contactList: theArr,
                    });
                }
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );
    }
    render() {
        const formItemList = [
            {
                label: "企业联系人",
                content: {this.state.contacts},
            },
            {
                label: "客户名称",
                content: 
                    {this.state.userName}
                    
                ,
            },
            {
                label: "联系人电话",
                content: {this.state.contactMobile},
            },
            {
                label: "企业法人",
                content: {this.state.legalPerson},
            },
            {
                label: "法人电话",
                content: {this.state.legalPersonTel},
            },
        ];
        return (
            
                
                    
                        
                            {{this.state.contractNo}}
                        
                        
                            {this.state.orderNo}
                        
                        
                            
                                {getProcessStatus(this.state.processStatus)}
                            
                        
                        
                            
                                {getLiquidationStatus(
                                    this.state.liquidationStatus
                                )}
                            
                        
                        
                            
                                
                                    {getApprovedState(this.state.approval)}
                                
                            
                            
                                {this.state.signDate}
                            
                            
                                {this.state.depName}
                            
                            
                                
                                    {this.state.outsource == 0 ? "否" : "是"}
                                
                            
                        
                     
                    
                        收款项目
                    
                    {this.state.processStatus === 0 ? (
                        
                            
                                 {
                                        this.setState({
                                            totalAmount: e.target.value,
                                        });
                                    }}
                                    style={{ width: "240px" }}
                                />
                            
                            
                                 {
                                        this.setState({
                                            firstAmount: e.target.value,
                                        });
                                    }}
                                    style={{ width: "240px" }}
                                />
                            
                            
                                
                                    {this.state.settlementAmount + "万元"}
                                
                            
                        
                    ) : (
                        
                            
                                {this.state.totalAmount}
                            
                            
                                {this.state.firstAmount}
                            
                            
                                
                                    {this.state.settlementAmount + "万元"}
                                
                            
                        
                    )}
                    
                        联系信息
                    
                    
                        {formItemList.map((data, index) => {
                            return (
                                
                                    {data.content}
                                
                            );
                        })}
                    
                    
                        
                            
                                
                                    {this.state.orgCodeUrl && this.state.visible && this.state.activeKey === '1' ? 
 : 
}
                                
 {/* {*/}
                                {/*    this.setState({*/}
                                {/*      previewImage: file.url || file.thumbUrl,*/}
                                {/*      previewVisibles: true,*/}
                                {/*    });*/}
                                {/*  }}*/}
                                {/*/>*/}
                                    
                                    
                                    
                                
                                
                            
                            
                                {/* {*/}
                                {/*    this.setState({*/}
                                {/*      previewImage: file.url || file.thumbUrl,*/}
                                {/*      previewVisibles: true,*/}
                                {/*    });*/}
                                {/*  }}*/}
                                {/*/>*/}
                                
                                    {
                                        this.state.visible && this.state.activeKey === '1' && this.state.replenishUrl ?
                                            
 :
                                            
                                    }
                                
 
                                    
                                    
                                    
                                
                            
                         
                     
                    
                    
                        
                            
                                {this.state.orderRemarks}
                            
                        
                     
                    
                        
                            {this.state.salesmanName}
                        
                        
                            {this.state.salesmanMobile}
                        
                    
                    
                        
                            {this.state.nowFinance}
                        
                        
                            {this.state.nowFinanceMobile}
                        
                    
                    
                        
                            {this.state.oldSalesmanName}
                        
                        
                            {this.state.oldSalesmanMobile}
                        
                    
                    
                        
                            {this.state.financeName}
                        
                        
                            {this.state.financeMobile}
                        
                    
                    {/* 协单人员 */}
                    
                    
                        
                            项目业务
                        
                    
                    
                 
            
        )
    }
}
export default OrderInfor;