import React from 'react'
import {
    message, Modal, Row, Col, Tag, Table, Input, Button
} from 'antd';
const { TextArea } = Input;
import '../style/index.less';
import {$http} from "../../../containers/config/https";
/**
 * @ByYQL:模态框 事前审核信息
 * Create 2022-1-11
 */
let userData = {}
class ShowExamineModal extends React.Component {
    constructor(props) {
        super(props);
        userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {};
        this.state = {
            visible: false,//弹框显示状
            admID:"",
            patID:"",
            tableRowId:'',
            tableRowCenterResult:'',
            tableRowDetail:'',
            textAreaInput:'',
            resultDataList:[]
        }
    }

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

    showModal = (admID) => {
        let that=this;
        this.setState({
            visible: true,
            admID:admID
        },()=>{
            var params = {
                params: [{
                    admID : that.state.admID,
                }],
                pagination:[{
                    pageSize: 100,
                    currentPage: 1,
                    sortColumn: '',
                    sortOrder:''
                }]
            }
            $http.post('urlDeault', this, {
                code: "pr02901",
                data: params,
                success: function (res) {
                    if (res.errorCode == '0') {
                        that.setState({
                            resultDataList:res.result.Data
                        },function () {
                            if(res.result.Data.length < 1){
                                message.warning('未查询到医保审核信息')
                                that.close()
                            }
                        })
                    }
                }
            });
        });
    };

    close = (e) => {
        this.setState({
            visible: false,
        });
    };


    // 操作行 --- 信息列表
    onClickRowPublic = (record) => {
        let that = this
        return {
            // 单击行选中
            onClick: () => {
                that.setState({
                    tableRowId: record.id,
                    tableRowCenterResult: record.centerResult
                },function () {
                    var params = {
                        params: [{
                            insuMessageId: that.state.tableRowId,
                        }]
                    }
                    $http.post('urlDeault', that, {
                        code: "pr02902",
                        data: params,
                        success: function (res) {
                            if (res.errorCode == '0') {
                                that.setState({
                                    tableRowDetail:res.result
                                })
                            }else{
                                message.warning(res.errorMessage)
                            }
                        }
                    });
                })
            }
        }
    }
    setRowClassNamePublic = (record) => {
        return  record.id === this.state.tableRowId ? 'clickRowStyle' : "";;
    }

    //事中审核模态框输入框内容监听
    textAreaInfo(e){
        this.setState({
            textAreaInput: e.target.value
        })
    }

    //处理事前或事中审核-遵从、不遵从
    followVerifyFun(onPress){
        var params = {
            params: [{
                insuMessageId : this.state.tableRowId,
                confirmType : onPress,
                confirmReason : this.state.textAreaInput
            }]
        }
        $http.post('urlDeault', this, {
            code: "pr02903",
            data: params,
            success: function (res) {
                this.showModal(this.state.admID)
            }
        });
    }

    render() {
        const orderColumns = [
            {
                title: '医保信息ID',
                dataIndex: 'id',
                width: 70,
                align: 'center',
            },
            {
                title: '类型',
                dataIndex: 'type',
                width: 100,
                align: 'center',
            },
            {
                title: '发起人',
                dataIndex: 'requestUser',
                width: 50,
                align: 'center',
            },
            {
                title: '审核结果',
                dataIndex: 'centerResult',
                width: 60,
                align: 'center',
                render: (text, record,index) => {
                    return (
                        <div>
                            {text == 'Y' ?  <Tag color="green">审核通过</Tag> : text == 'N' ? <Tag color="orange">审核异常</Tag> : ''}
                        </div>
                    );}
            },{
                title: '发起时间',
                dataIndex: 'requestDateTime',
                width: 100,
                align: 'center',
            }
        ]

        const _tableRowDetail = this.state.tableRowDetail;
        return (
            <Modal
                title="审查信息"
                className="PatientCourse"
                visible={this.state.visible}
                onCancel={this.close}
                footer={null}
            >
            <Row>
                <Col span={12}>
                    <Table
                        style={{ height: '75vh'}}
                        columns={orderColumns}
                        pagination={false}
                        dataSource={this.state.resultDataList}
                        scroll={{ y:'70vh'}}
                        onRow={(record)=>this.onClickRowPublic(record)}
                        rowClassName={this.setRowClassNamePublic}
                    />
                </Col>
                <Col span={12}>
                    <Row style={{height: '73vh',background:'#FFFFFF',margin:'0 10px',padding:'15px'}}>
                        {
                            _tableRowDetail == '' ? '' :
                                <Row>
                                    <Row><Col span={12}>类型：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.type}</Col></Row>
                                    <Row><Col span={12}>发起人：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.requestUser}</Col></Row>
                                    <Row><Col span={12}>发起时间：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.requestDateTime}</Col></Row>
                                    <Row><Col span={12}>发起内容：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.requestContent}</Col></Row>
                                    <Row><Col span={12}>中心反馈：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.centerResult}</Col></Row>
                                    <Row><Col span={12}>反馈明细：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.centerResultDetail}</Col></Row>
                                    <Row><Col span={12}>结果类型：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.confirmType}</Col></Row>
                                    <Row><Col span={12}>确认人员：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.confirmUser}</Col></Row>
                                    <Row><Col span={12}>确认时间：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.confirmDateTime}</Col></Row>
                                    <Row><Col span={12}>确认原因：</Col><Col span={12} style={{textAlign:'right'}}>{_tableRowDetail.confirmReason}</Col></Row>

                                    {this.state.tableRowCenterResult == '' || this.state.tableRowCenterResult == undefined ?
                                        <Row style={{marginTop:'30px'}}>
                                            <Row><span>若不遵从请输入反馈原因</span><TextArea placeholder='请输入不遵从的原因，若选择遵从无需输入内容' onChange={(e)=>this.textAreaInfo(e)} rows={3}/></Row>
                                            <Row style={{marginTop:'20px',textAlign:'center'}}>
                                                <Button onClick={() =>this.followVerifyFun('N')}>不遵从</Button>
                                                <Button style={{marginLeft:'60px'}} type="primary" onClick={() =>this.followVerifyFun('Y')}>遵从</Button>
                                            </Row>
                                        </Row>
                                        : ''
                                    }
                                </Row>
                        }
                    </Row>
                </Col>
            </Row>
            </Modal>
        )
    }
}
export default ShowExamineModal
