import React,{ Component } from 'react';
import {Select} from "antd";
import { provinceList} from '@/NewDicProvinceList';
import './index.less';
import TabelContent from '../../../../common/tabelContent'

import DetailedList from './detailedList';

class SignatureStatistics extends Component{
    constructor(props) {
        super(props);
        this.state={
            columns: [
                {
                    title: "序号",
                    dataIndex: "key",
                    key: "key",
                    width: 120,
                },
                {
                    title: "省份",
                    dataIndex: "province",
                    key: "province",
                    width: 120,
                },
                {
                    title: "签单人数(人)",
                    dataIndex: "counts",
                    key: "counts",
                    width: 120,
                    className: 'projectTable',
                    onCellClick :(record, event)=>{
                        event.stopPropagation();
                        this.setState({
                            visible:true,
                            recordInfor:record
                        })
                    }
                },
                {
                    title: "总单量(个)",
                    dataIndex: "quantity",
                    key: "quantity",
                    className: 'projectTable',
                    width: 120,
                    onCellClick :(record, event)=>{
                        event.stopPropagation();
                        this.setState({
                            visible:true,
                            recordInfor:record
                        })
                    }
                },
                {
                    title: "总签单额(万元)",
                    dataIndex: "total",
                    key: "total",
                    className: 'projectTable',
                    width: 120,
                    onCellClick :(record, event)=>{
                        event.stopPropagation();
                        this.setState({
                            visible:true,
                            recordInfor:record
                        })
                    }
                },
            ],
            searchConfig:{}
        }
    }

    searchList(){
        let arr = [
            // {
            //     type:'autoComplete',
            //     dataKey:'orderNo',
            //     dataTitle:'orderNoTitle',
            //     api:'/api/admin/customer/listAdminByName',
            //     search:'adminName',
            //     placeholder:'请输入客户名称'
            // },
            {
                type:'departmentSelect',
                dataKey:'depId',
                placeholder:'请选择部门'
            },
            {
                type:'times',
                title:'下单时间',
                dataKey:['startCreate','endCreate'],
            },
            {
                type:'times',
                title:'合同时间',
                dataKey:['startSign','endSign'],
            },
            //0签单额 1签单数 2签单人数
            {
                type:'select',
                dataKey:'sort',
                placeholder:'请选择排序',
                selectList:[
                    {
                        value:'0',
                        label:'按签单额排序'
                    },
                    {
                        value:'1',
                        label:'按签单数排序'
                    },
                    {
                        value:'2',
                        label:'按签单人数排序'
                    },
                ]
            },
            {
                type:'select',
                dataKey:'province',
                placeholder:'请选择省份',
                selectOptionList:()=>{
                    let Province = [];
                    provinceList.map(function(item) {
                        let id = String(item.id)
                        Province.push(
                            <Select.Option value={id} key={item.name}>{item.name}</Select.Option>
                        )
                    });
                    return Province
                },
            }
        ]
        return arr;
    }

    render() {
        return (
            <div className="user-content signatureStatistics">
                <div className="content-title">
                    <span>
                        签单统计表
                    </span>
                </div>
                <TabelContent
                    scroll={{ x: 0, y: 200 }}
                    searchList={this.searchList()}
                    columns={this.state.columns}
                    searchOperation={(value)=>{
                        for(let i of Object.keys(value)){
                            if(i === 'sort' || i === 'pageNo' || i === 'pageSize'){
                                delete value[i]
                            }

                        }
                        this.setState({searchConfig:value})}
                    }
                    tabelApi={'/api/admin/newOrder/statisticsList'}
                    exportApi={'/api/admin/newOrder/statisticsListExprot'}
                    exportExecProcessing={(data)=>{
                        if(data.province){
                            let arr = provinceList.filter(v=>String(v.id) === String(data.province))
                            data.provinceName = arr[0].name
                        }
                        return data;
                    }}
                    dataProcessing={(data)=>{
                        let theArr = [];
                        for (let i = 0; i < data.data.length; i++) {
                            let thisdata = data.data[i];
                            thisdata.key=i + 1;
                            theArr.push(thisdata);
                        }
                        return theArr;
                    }}
                />
                {this.state.visible ? <DetailedList
                    searchConfig={this.state.searchConfig}
                    visible={this.state.visible}
                    recordInfor={this.state.recordInfor}
                    onCancel={()=>{
                        this.setState({
                            visible:false,
                            recordInfor:{}
                        })
                    }}/> : null}
            </div>
        )
    }
}

export default SignatureStatistics;
