//互联网人力资源
import React from 'react';
import { Table, Popconfirm, Icon, message, Modal, Form, Divider, Select, Row, Col, Button, Input } from 'antd';
import { $http } from '../../containers/config/https';
import store from '../../store';

import CommonPagination from 'components/pagination/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';

const { Option } = Select;
const formItemLayout = {    // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 14, offset: 2 },
};

class OPHBHLWtinsstaff extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false, //加载状态标志
            visible: false, //弹窗显示状态标志
            tableData: [], // 表格数据
            total: 0,  // 表格数据总条数
            page: 1, //当前页数
            pageSize: 10, //每页显示条数
            hospitaData: [], //医院下拉框数据 --- 查询
            hospID: '',
            name: '',
        };
        this.columns = [
            {
                title: '医院',
                dataIndex: 'hosp',
                key: 'hosp',
                width: '100px',
                align: "center",
            },
            {
                title: '机构标识',
                dataIndex: 'JGDM',
                key: 'JGDM',
                width: '100px',
                align: "center",
            },
            {
                title: '工号',
                dataIndex: 'YHRYGH',
                key: 'YHRYGH',
                width: '100px',
                align: "center",
            },
            {
                title: '医护人员姓名',
                dataIndex: 'YHRYXM',
                key: 'YHRYXM',
                width: '100px',
                align: "center",
            },
            {
                title: '性别',
                dataIndex: 'XB',
                key: 'XB',
                width: '100px',
                align: "center",
            },
            {
                title: '出生日期',
                dataIndex: 'CSRQ',
                key: 'CSRQ',
                width: '100px',
                align: "center",
            },
            {
                title: '身份证号',
                dataIndex: 'SFZH',
                key: 'SFZH',
                width: '100px',
                align: "center",
            },
            {
                title: '身份证件类别代码',
                dataIndex: 'ZJLBDM',
                key: 'ZJLBDM',
                width: '100px',
                align: "center",
            },
            {
                title: '科室代码',
                dataIndex: 'KSDM',
                key: 'KSDM',
                width: '100px',
                align: "center",
            },
            {
                title: '专业技术职务代码',
                dataIndex: 'ZYJSZWDM',
                key: 'ZYJSZWDM',
                width: '100px',
                align: "center",
            },
            {
                title: '专业技术职务类别代码',
                dataIndex: 'ZYJSZWLBDM',
                key: 'ZYJSZWLBDM',
                width: '120px',
                align: "center",
            },
            {
                title: '资质类别名称',
                dataIndex: 'ZZLBMC',
                key: 'ZZLBMC',
                width: '100px',
                align: "center",
            },
            {
                title: '资格证书编号',
                dataIndex: 'ZGZSBH',
                key: 'ZGZSBH',
                width: '100px',
                align: "center",
            },
            {
                title: '资格获得时间',
                dataIndex: 'ZGHDSJ',
                key: 'ZGHDSJ',
                width: '100px',
                align: "center",
            },
            {
                title: '执业证书编码',
                dataIndex: 'ZYZSBM',
                key: 'ZYZSBM',
                width: '100px',
                align: "center",
            },
            {
                title: '发证日期',
                dataIndex: 'FZRQ',
                key: 'FZRQ',
                width: '100px',
                align: "center",
            },
            {
                title: '执业地点',
                dataIndex: 'ZYDD',
                key: 'ZYDD',
                width: '100px',
                align: "center",
            },
            {
                title: '执业范围',
                dataIndex: 'ZYFW',
                key: 'ZYFW',
                width: '100px',
                align: "center",
            },
            {
                title: '主要执业医疗机构代码',
                dataIndex: 'ZYZYYLJGDM',
                key: 'ZYZYYLJGDM',
                width: '100px',
                align: "center",
            },
            {
                title: '主要执业医院名称',
                dataIndex: 'ZYZYYYMC',
                key: 'ZYZYYYMC',
                width: '100px',
                align: "center",
            },
            {
                title: '全科医生标志',
                dataIndex: 'QKYSBZ',
                key: 'QKYSBZ',
                width: '100px',
                align: "center",
            },
            {
                title: '手机号码',
                dataIndex: 'SJHM',
                key: 'SJHM',
                width: '100px',
                align: "center",
            },
            {
                title: '专长',
                dataIndex: 'ZC',
                key: 'ZC',
                width: '100px',
                align: "center",
            },
            {
                title: '民族',
                dataIndex: 'MZ',
                key: 'MZ',
                width: '100px',
                align: "center",
            },
            {
                title: '参加工作日期',
                dataIndex: 'CJGZRQ',
                key: 'CJGZRQ',
                width: '100px',
                align: "center",
            },
            {
                title: '注册日期时间',
                dataIndex: 'ZCSJ',
                key: 'ZCSJ',
                width: '100px',
                align: "center",
            },
            {
                title: '学历',
                dataIndex: 'XL',
                key: 'XL',
                width: '100px',
                align: "center",
            },
            {
                title: '个人照片存放地址',
                dataIndex: 'GRZPCFDZ',
                key: 'GRZPCFDZ',
                width: '100px',
                align: "center",
            },
            {
                title: '资格证存放地址',
                dataIndex: 'ZGZCFDZ',
                key: 'ZGZCFDZ',
                width: '100px',
                align: "center",
            },
            {
                title: '执业证存放地址',
                dataIndex: 'ZYZCFDZ',
                key: 'ZYZCFDZ',
                width: '100px',
                align: "center",
            },
            {
                title: '数据生成日期时间',
                dataIndex: 'SJSCSJ',
                key: 'SJSCSJ',
                width: '100px',
                align: "center",
            },
            {
                title: '填报日期',
                dataIndex: 'TBRQSJ',
                key: 'TBRQSJ',
                width: '100px',
                align: "center",
            },
            {
                title: '撤销标志',
                dataIndex: 'CXBZ',
                key: 'CXBZ',
                width: '100px',
                align: "center",
            },
            {
                title: '上传标志',
                dataIndex: 'Uploadflag',
                key: 'Uploadflag',
                width: '100px',
                align: "center",
            },
            {
                title: '操作',
                key: 'op',
                align: "center",
                width: '50px',
                render: (text, record) => (
                    <span>
                        <span style={{ cursor: 'pointer' }} onClick={() => this.uploadHLWtinsstaff(record)} ><Icon type="to-top" />上传</span>
                    </span>
                ),
            },
        ];
    }


    componentDidMount() {
        //初始化列表数据
        this.handleQuery();
        //医院下拉框
        this.getHospitalData();
    }

    //初始化列表数据
    handleQuery = () => {
        let { page, pageSize, hospID, name } = this.state;
        let data = {}
        data = {
            params: [{
                hospID: hospID,
                name: name,
            }],
            pagination: [{
                pageSize: pageSize,
                currentPage: page,
                sortColumn: 'code',
                sortOrder: 'asc'
            }]
        }
        $http.post('urlS', this, {
            code: '05100305',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.result) {
                    this.setState({ tableData: res.result.data, total: res.result.totalCount, loading: false })
                } else {
                    this.setState({ tableData: [], total: 0, loading: false })
                }
            }
        })
    }

    // 页码改变的回调，参数是改变后的页码及每页条数
    appPageChange = (page, pageSize) => {
        this.setState({
            page: page,
            pageSize: pageSize,
        }, () => {
            // 重新调用查询方法
            this.handleQuery();
        });
    }

    // 条数改变的回调
    apponShowSizeChange = (current, size) => {
        this.setState({
            page: current,
            pageSize: size,
        }, () => {
            // 重新调用查询方法
            this.handleQuery();
        });
    }

    //医院下拉框数据
    getHospitalData = () => {
        var data = {
            params: [{
                logonGroupID: JSON.parse(window.sessionStorage.userData).groupID,
                logonHospID: JSON.parse(window.sessionStorage.userData).hospID,
                dataType: "combo",
            }]
        }
        let hospital = []
        $http.post("urlS", this, {
            code: '05100046',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.Hosp) {
                    for (var i = 0; i < res.Hosp.length; i++) {
                        hospital.push(<Option value={String(res.Hosp[i].id)} key={i + "H"} >{res.Hosp[i].descripts}</Option>)
                    }
                    this.setState({ hospitaData: hospital, hospital: hospital, })
                }
            },
            error: function (err) {
                this.setState({ errMsg: "数据加载失败，请重试！" })
            }
        })
    }

    //医院选择 --- 查询条件
    onChangeHosp = (e) => {
        this.setState({ hospID: e });
    }

    onChangeName = (e) => {
        this.setState({ name: e.target.value });
    }

    //互联网人力资源上传
    uploadHLWtinsstaff = (record) => {
        let data = {};
        data = {
            params: [{
                tinsstaffID: record.id,
                userID: JSON.parse(window.sessionStorage.userData).userID,
            }]
        }
        $http.post('urlS', this, {
            code: '05100339',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    message.success(res.errorMessage);
                    this.handleQuery();
                    this.setState({ loading: false, visible: false });
                }
            }
        })
    };

    render() {
        let { hospitaData } = this.state;
        const { getFieldDecorator } = this.props.form;
        return (
            <div>
                <div style={{ width: '100%', height: '100%' }}>
                    <Row style={{ minHeight: '80px', padding: '24px 24px 24px 24px' }}>
                        <Col span={4}>
                            <span>医院：</span>
                            <Select style={{ width: '200px' }} allowClear onChange={this.onChangeHosp} >
                                {hospitaData}
                            </Select>
                        </Col>
                        <Col span={4}>
                            <span>病人姓名：</span>
                            <Input style={{ width: '180px' }} allowClear onChange={this.onChangeName} />
                        </Col>

                        <Col span={3} style={{ textAlign: 'right' }}>
                            <Button type="primary" onClick={() => this.handleQuery()} icon="search" >查询</Button>
                        </Col>
                    </Row>
                </div>
                <div style={{ widht: '100%', height: '10px', background: '#f0f2f5' }}></div>
                <div style={{ padding: 24 }}>
                    <Table
                        style={{ height: store.getState().tableHeight.y + 65 + 'px' }}
                        dataSource={this.state.tableData}
                        columns={this.columns}
                        className='TableA'
                        //rowClassName="editable-row"
                        pagination={false}
                        scroll={{ x: 900, y: store.getState().tableHeight.y }}
                        bordered
                        loading={this.state.loading}
                    />
                    <CommonPagination size="small" current={this.state.page} total={this.state.total} search='search'
                        onShowSizeChange={this.apponShowSizeChange} complete={true} dataSource={this.state.tableData}
                        onChange={this.appPageChange} />
                </div>
            </div>
        )
    }
}

const OPHBHLWtinsstaffForm = Form.create()(OPHBHLWtinsstaff);
export default OPHBHLWtinsstaffForm;