/*
* 拒绝接诊理由
* */

import React, { Component } from 'react';
import {
    Input, Form, Select, Modal, Button, Progress, Upload, message, Divider, Table,
    Card, Row, Col, DatePicker, Popconfirm, Checkbox, Radio
} from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import FaceRecognitionAuto from 'pages/common/FaceRecognitionAuto';
import store from 'store';
import '../style/index.less';
import moment from 'moment';

const Option = Select.Option;
const Search = Input.Search;
const FormItem = Form.Item;
const { TextArea } = Input;

class ShowFaceRecognitionModal extends Component {

    constructor(props) {
        super(props);
        var date = new Date();
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            leftData: [],
            rightData: [],
            userData: userData,
            visible: false,
            patientMsg: []
        }
    }

    componentDidMount() {
        this.props.onRef(this)
        this.initData()
    }

    initData() {
        this.columns = [
            {
                title: '病人ID',
                dataIndex: 'patNo',
                width: 100,
                align: 'left',
            },
            {
                title: '病人姓名',
                dataIndex: 'patName',
                width: 100,
                align: 'left',
            },
            {
                title: '病人性别',
                dataIndex: 'patSexDesc',
                width: 80,
                align: 'left',
            },
            {
                title: '身份证号码',
                dataIndex: 'patIDCardNo',
                width: 150,
                align: 'left',
            },
        ]
    }

    closeModal(name) {
        let { onHide } = this.props;
        onHide && onHide();
        this.cleanInput();
        if (this.onFace) {
            this.onFace.clearVideo()
        }
    }

    //清空输入框
    cleanInput() {
        this.setState({})
    }
    //提交
    onSubmit(data) {
        let { onHide, onSubmit } = this.props;
        onHide && onHide();
        if (!Util.isEmpty(data) && data.length > 1) {
            this.showPatientList(data);
        } else {
            onSubmit && onSubmit(!Util.isEmpty(data) ? data[0].patNo : '');
        }
    }

    showPatientList(data) {
        this.setState({
            patientMsg: !Util.isEmpty(data) ? data : [],
            isShowModal: true
        })
    }

    confirmModal() {
        let { onSubmit } = this.props;
        this.closeComfirmModal()
        onSubmit && onSubmit(this.state.patNo);
    }

    //点击行，渲染当前行样式
    onClickRow = (record) => {
        return {
            onClick: () => {
                this.setState({
                    patNo: record.patNo,
                })
            },
        };
    }

    //点击行，渲染当前行样式 
    setRowClassName = (record) => {
        return record.patNo === this.state.patNo ? 'clickRowStyle' : '';
    }

    closeComfirmModal() {
        this.setState({
            isShowModal: false
        })
    }

    onRefs = ref => {
        this.onFace = ref
    }

    render() {
        return <div>
            <Modal className='face-recognition-modal'
                title={'人脸识别'}
                maskClosable={false}
                footer={null}
                visible={this.props.isShow}
                onCancel={this.closeModal.bind(this)}
                onOk={this.onSubmit.bind(this)}>
                <div>
                    {this.props.isShow ? <FaceRecognitionAuto businessCode={this.props.businessCode} faceType='patient'
                        loadDara={this.onSubmit.bind(this)}
                        hospID={this.state.userData.hospID}
                        locID={this.state.userData.locID}
                        doctorID={this.state.userData.userID}
                        ref={this.onRefs} /> : null}
                </div>
            </Modal>
            <Modal className='face-recognition-modal'
                title={'选择病人'}
                maskClosable={false}
                visible={this.state.isShowModal}
                onCancel={this.closeComfirmModal.bind(this)}
                onOk={this.confirmModal.bind(this)}>
                <Table columns={this.columns}
                    dataSource={this.state.patientMsg}
                    onRow={this.onClickRow} bordered
                    rowClassName={this.setRowClassName}
                    scroll={{ y: store.getState().tableHeight.y }}
                    pagination={false}>
                </Table>
            </Modal>
        </div>
    }
}

export default ShowFaceRecognitionModal;