import React, { Component } from "react";
import { Button, Cascader, Input, message, Select, Spin, Table, Tabs, Tooltip } from "antd";
import $ from "jquery/src/ajax";
import { ChooseList } from "../../../order/orderNew/chooseList";
import { projectStatusCascader } from '@/dataDic.js';
import CheckInfor from './checkInfor';
import OrderInfor from "./orderInfor";
const TabPane = Tabs.TabPane;
class BusinessManagement extends Component {
    constructor(props) {
        super(props);
        this.state = {
            changeList: [],
            pageNo: 1,
            columns: [
                {
                    title: '项目编号',
                    dataIndex: 'id',
                    key: 'id',
                    fixed: 'left',
                    width: 50,
                    render: (text, record) => {
                        if (record.splitStatus == 2) {
                            return {record.splitSuper + '-' + record.splitId}
                        } else {
                            return text
                        }
                    },
                },
                {
                    title: '项目名称',
                    dataIndex: 'commodityName',
                    key: 'commodityName',
                    fixed: 'left',
                    width: 100,
                    render: text => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: '项目数量',
                    dataIndex: 'commodityQuantity',
                    key: 'commodityQuantity',
                },
                {
                    title: '订单编号',
                    dataIndex: 'orderNo',
                    key: 'orderNo',
                },
                {
                    title: '合同编号',
                    dataIndex: 'contractNo',
                    key: 'contractNo',
                },
                {
                    title: '客户名称',
                    dataIndex: 'userName',
                    key: 'userName',
                    className: 'userName',
                    render: text => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: '业务类别',
                    dataIndex: 'cname',
                    key: 'cname',
                },
                {
                    title: '分配时间',
                    dataIndex: 'taskDistributionTime',
                    key: 'taskDistributionTime',
                },
                {
                    title: '订单部门',
                    dataIndex: 'depName',
                    key: 'depName',
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    key: 'operation',
                    render: (text, record) => {
                        return (
                            
                        )
                    }
                },
            ],
            dataSource: [],
            infor: {},
            nameSearch: '',
            orderNoSearch: '',
            contractNoSearch: undefined,
            taskNoSearch: '',
            departmenttSearch: undefined,
            projectStatusSearch: [], //项目状态
            approvalSearch: undefined,
            outsourceStatusSearch: [],
            pagination: {
                defaultCurrent: 1,
                defaultPageSize: 10,
                showQuickJumper: true,
                pageSize: 10,
                onChange: function (page) {
                    this.loadData(page)
                }.bind(this),
                showTotal: function (total) {
                    return '共' + total + '条数据'
                },
            },
            departmentArr: []
        }
        this.loadData = this.loadData.bind(this);
        this.changeList = this.changeList.bind(this);
        this.departmentList = this.departmentList.bind(this);
        this.reset = this.reset.bind(this);
    }
    componentDidMount() {
        this.loadData();
        this.departmentList();
    }
    loadData(pageNo) {
        this.setState({
            loading: true,
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/orderProject/selectProjectCheck",
            data: {
                pageNo: pageNo || 1,
                pageSize: this.state.pagination.pageSize,
                name: this.state.nameSearch || undefined, //客户名称
                depId: this.state.departmenttSearch, //订单部门
                orderNo: this.state.orderNoSearch || undefined, //订单编号
                contractNo: this.state.contractNoSearch, //合同编号
                taskId: this.state.taskNoSearch || undefined, //项目编号
                taskStatus: this.state.taskStatuSearch, //项目状态
                projectStatus: this.state.projectStatusSearch && this.state.projectStatusSearch.length > 0 ?
                    (typeof this.state.projectStatusSearch[0] === 'string' ? this.state.projectStatusSearch[1] : this.state.projectStatusSearch[0]) : undefined,  //项目状态
                adminName: this.state.adminName, //项目受理人
                approval: this.state.approvalSearch, //特批状态搜索
                outsourceStatus:
                    this.state.outsourceStatusSearch >= 999
                        ? undefined
                        : this.state.outsourceStatusSearch, //外包状态搜索
            },
            success: function (data) {
                let theArr = []
                if (data.error.length === 0) {
                    for (let i = 0; i < data.data.list.length; i++) {
                        let thisdata = data.data.list[i];
                        thisdata.key = i;
                        theArr.push(thisdata)
                    }
                    this.state.pagination.current = data.data.pageNo
                    this.state.pagination.total = data.data.totalCount
                    if (data.data && data.data.list && !data.data.list.length) {
                        this.state.pagination.current = 0
                        this.state.pagination.total = 0
                    }
                    this.setState({
                        dataSource: theArr,
                        pagination: this.state.pagination,
                        pageNo: data.data.pageNo
                    })
                } else {
                    message.warning(data.error[0].message)
                }
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );
    }
    changeList(arr) {
        const newArr = [];
        this.state.columns.forEach(item => {
            arr.forEach(val => {
                if (val === item.title) {
                    newArr.push(item);
                }
            });
        });
        this.setState({
            changeList: newArr
        });
    }
    //部门
    departmentList() {
        this.setState({
            loading: true,
        })
        $.ajax({
            method: 'get',
            dataType: 'json',
            crossDomain: false,
            url: globalConfig.context + '/api/admin/organization/selectSuperId',
            data: {},
            success: function (data) {
                let thedata = data.data
                let theArr = []
                if (!thedata) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message)
                    }
                    thedata = {}
                } else {
                    thedata.map(function (item, index) {
                        theArr.push({
                            key: index,
                            name: item.name,
                            id: item.id,
                        })
                    })
                }
                this.setState({
                    departmentArr: theArr,
                })
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                })
            }.bind(this)
        )
    }
    reset() {
        this.setState({
            nameSearch: '',
            orderNoSearch: '',
            contractNoSearch: undefined,
            taskNoSearch: '',
            departmenttSearch: undefined,
            projectStatusSearch: [], //项目状态
            approvalSearch: undefined,
            outsourceStatusSearch: [],
        }, () => {
            this.loadData();
        })
    }
    render() {
        return (
            
                
                    核对专利
                
                
                
                    
                         {
                                this.setState({
                                    orderVisible: true,
                                    orderNo: record.orderNo
                                })
                            }}
                        />
                    
                
                {this.state.visible ?  {
                        this.setState({
                            visible: false,
                            infor: {}
                        })
                        this.loadData(this.state.pageNo);
                    }}
                /> : null}
                {this.state.orderVisible ?  {
                        this.setState({
                            orderVisible: false,
                            orderNo: ''
                        })
                    }}
                /> : null}
            
        )
    }
}
export default BusinessManagement;