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 InterviewStatistics extends Component{
    constructor(props) {
        super(props);
        this.state={
            columns: [
                {
                    title: "序号",
                    dataIndex: "key",
                    key: "key",
                },
                {
                    title: "面谈部门",
                    dataIndex: "province",
                    key: "province",
                },
                {
                    title: "老客户面谈数",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "老客户签单数/金额",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "老客户面谈率",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "新客户面谈数",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "新客户签单数/金额",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "新客户面谈率",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "总面数",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "总签单数/金额",
                    dataIndex: "counts",
                    key: "counts",
                },
                {
                    title: "总面谈率",
                    dataIndex: "counts",
                    key: "counts",
                },
            ],
        }
    }

    searchList(){
        let arr = [
            {
                type:'departmentSelect',
                dataKey:'depId',
                placeholder:'请选择部门'
            },
            {
                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
                },
            },
            //0 总数量 1总金额 2总面谈
            {
                type:'select',
                dataKey:'sort',
                placeholder:'请选择排序',
                selectList:[
                    {
                        value:'0',
                        label:'按总数量排序'
                    },
                    {
                        value:'1',
                        label:'按总金额排序'
                    },
                    {
                        value:'2',
                        label:'按总面谈排序'
                    },
                ]
            },
            {
                type:'times',
                title:'公出时间',
                dataKey:'date',
                format: 'YYYY/MM'
            },
        ]
        return arr;
    }

    render() {
        return (
            <div className="user-content interviewStatistics">
                <div className="content-title">
                    <span>
                        公出面谈表<span style={{fontSize:'10px',color:'#0f2be5',marginLeft:'10px'}}>注：通过公出打卡，同一家公司，多次面谈数只计算1次</span>
                    </span>
                </div>
                <TabelContent
                    searchList={this.searchList()}
                    columns={this.state.columns}
                    tabelApi={'/api/admin/followStatisticsList'}
                    exportApi={'/api/admin/followStatisticsListExport'}
                    onRowClick={(row)=>{
                        this.setState({
                            visible: true,
                            recordInfor: row,
                        })
                    }}
                    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
                    visible={this.state.visible}
                    recordInfor={this.state.recordInfor}
                    onCancel={()=>{
                        this.setState({
                            visible:false,
                            recordInfor:{}
                        })
                    }}/> : null}
            </div>
        )
    }
}

export default InterviewStatistics;
