// 预住院转门诊退费
// @ByGJG
import React, { Component } from 'react';
import { Card, Row, Col, Input, Button, Table, message, Modal } from 'antd';
import { $http } from 'containers/config/https';
import store from 'store';
import './CSS/inhospital.less';
import iconListvisits from 'assets/images/icon_listvisits.png';
import PatientAccountManagement from '../Cashier/charges/PatientAccountManagement.jsx';


const formItemLayout = { // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 14 },
}
class PreInRefund extends Component {
    constructor(props) {
        super(props);
        this.state = {
            input: undefined,
            basicHeight: 0,
            tableData: [],
            loading: false,
            visible: false,
            userInfo: JSON.parse(window.sessionStorage.userData),
            tableObj: {},
            rowID: "",
            columns: [],
            patientAccountVisile: false,
            inDeposit: 0.00,           // 预交金
        };

        this.columns = [
            {
                title: '患者ID',
                dataIndex: 'patID',
                width: 80,
                align: 'center'
            },
            {
                title: '登记号',
                dataIndex: 'patNo',
                width: 120,
                align: 'center'
            },
            {
                title: '患者姓名',
                dataIndex: 'patName',
                width: 100,
                align: 'center'
            },
            {
                title: '患者性别',
                dataIndex: 'patSexDesc',
                width: 80,
                align: 'center'
            },
            {
                title: '身份证号',
                dataIndex: 'patIDCardNo',
                width: 160,
                align: 'center'
            },
            {
                title: '住院号',
                dataIndex: 'patMedicalNo',
                width: 100,
                align: 'center'
            },
            {
                title: '手机号',
                dataIndex: 'patMobile',
                width: 120,
                align: 'center'
            },
            {
                title: '就诊号',
                dataIndex: 'admNo',
                width: 150,
                align: 'center'
            },
            {
                title: '就诊状态',
                dataIndex: 'admStatusDesc',
                width: 100,
                align: 'center'
            },
            {
                title: '就诊科室',
                dataIndex: 'admLocDesc',
                width: 120,
                align: 'center'
            },
            {
                title: '就诊病区',
                dataIndex: 'admWardDesc',
                width: 120,
                align: 'center'
            },
            {
                title: '就诊类型',
                dataIndex: 'admTypeDesc',
                width: 120,
                align: 'center'
            },
            {
                title: '预交金',
                dataIndex: 'deposit',
                width: 120,
                align: 'center'
            },
            {
                title: '审核状态',
                dataIndex: 'audiFlagDesc',
                width: 120,
                align: 'center'
            },
        ]
    }

    componentDidMount() {
        this.setState({ basicHeight: document.getElementById("diagnostic-query").clientHeight }, () => {
            this.tableList()
            this.getTableData()
        });
    }

    onPatAccManagement = (ref) => {
        this.patAccManagementChild = ref;
    }

    //输入框
    handleInputChange = (e) => {
        this.setState({
            input: e.target.value
        })
    }
    //输入框回车查询
    InputOnPressEnter = (e) => {
        this.setState({
            input: e.target.value
        }, () => {
            this.getTableData();
        })
    }

    // 获取列表数据
    getTableData = () => {
        let { input } = this.state
        var params = {
            params: [{
                input: input || '',
                status: 'A'
            }],
        }
        $http.post('urlDeault', this, {
            code: "05100402",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        tableData: res.result.rows,
                        total: res.result.total,
                        tableObj: {},
                        loading: false,
                        rowID: ''
                    })
                } else {
                    message.warning(res.errorMessage)
                    this.setState({
                        loading: false
                    })
                }
            }
        });
    }
    //获取表头
    tableList = () => {
        var data = {
            params: [{
                "reactCode": ["PreHospitalizationQuery"],
                "compontName": "PreHospitalizationQuery",
                "type": "C"
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let resC = res.result.C
                    for (var i = 0; i < resC.length; i++) {
                        resC[i].key = i;
                    }
                    resC.map((item, i) => {
                        item.title = item.descripts
                    })
                    let filterArr = resC.filter(function (item) { return item.display === 'Y' });
                    this.setState({
                        columns: filterArr,
                    })
                }
            }
        })
    }

    //转门诊
    turnInAdm = () => {
        let { rowID, tableObj } = this.state
        if (rowID == "") {
            message.info("请选中一条记录再进行操作！")
            return
        }
        var params = {
            params: [{
                admType: "O",
                admID: rowID
            }],
        }
        $http.post('urlDeault', this, {
            code: "05100403",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success(res.errorMessage)
                    this.getTableData()
                }
            }
        });
    }
    handleCancel = () => {
        this.getTableData()
        this.setState({
            patientAccountVisile: false,
        })
    }
    //选中行
    onClickRowPublic = (record) => {
        return {
            // 单击行选中
            onClick: () => {
                this.setState({ rowID: record.admID, tableObj: record });
            }
        }
    }
    setRowClassNamePublic = (record) => {
        return (record.admID || record.admID) === this.state.rowID ? 'clickRowStyle' : '';
    }
    render() {
        let { input, basicHeight, tableData, loading, columns } = this.state;
        return (
            <div className="diagnostic-query">
                <Row id="diagnostic-query" style={{ padding: '0 24px' }}>
                    <Col span={16} >
                        <Row style={{ marginBottom: '20px' }}>
                            病人标识：
                            <Input
                                style={{ width: "250px", margin: '22px 10px 0 0' }}
                                placeholder="登记号/病人ID/病人姓名"
                                allowClear
                                onChange={this.handleInputChange} value={input}
                                onPressEnter={this.InputOnPressEnter}
                            />
                            <Button style={{ marginTop: '8px' }} onClick={this.getTableData}>查询</Button>
                        </Row>
                    </Col>
                    <Col span={8}  >
                        <Row style={{ marginBottom: '20px' }}>
                            <div style={{ padding: '22px 10px 0 0' }} >
                                <Button type="primary" style={{ marginLeft: '8px' }} onClick={() => this.turnInAdm()}>转门诊</Button>
                                <Button style={{ margin: '0 5px', display: this.state.poorFlag === true ? 'none' : '' }} className="searchPatBtn" onClick={() => {
                                    if (!(this.state.tableObj && this.state.tableObj.patNo)) {
                                        message.info("请先选中一条记录！")
                                        return
                                    }
                                    this.setState({
                                        patientAccountVisile: true,
                                    }, () => {
                                        if (this.patAccManagementChild) {
                                            this.patAccManagementChild.setState({
                                                patNo: this.state.tableObj.patNo
                                            }, () => {
                                                this.patAccManagementChild.searchUser()
                                            })
                                        }
                                    })
                                }}>
                                    退预交金
                                </Button>
                            </div>
                        </Row>
                    </Col>
                </Row>
                <div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
                <Card
                    size="small"
                    title={<div className="card-title-left-img"><img src={iconListvisits} alt="" />预住院列表</div>}
                >
                    <div>
                        <Table
                            columns={columns ? columns : this.columns}
                            dataSource={tableData}
                            style={{ height: store.getState().tableHeight.y + 136 - basicHeight + 'px', }}
                            scroll={{ x: 480, y: store.getState().tableHeight.y + 80 - basicHeight }}
                            onRow={this.onClickRowPublic}
                            rowClassName={this.setRowClassNamePublic}
                            bordered
                            rowKey={record => record.key}
                            loading={loading}
                            pagination={false}
                            className="table-body-height"
                        />
                    </div>
                </Card>
                <Modal
                    className='patientAccountModal'
                    style={{
                        top: '8vh',
                        height: '90vh',
                        width: '150vh',
                    }}
                    maskClosable={false}
                    visible={this.state.patientAccountVisile}
                    title='充值'
                    onCancel={this.handleCancel}
                    footer={null}
                    width="150vh"
                >
                    <PatientAccountManagement inDeposit={this.state.inDeposit} typeCinFlage="I"
                        onRef={this.onPatAccManagement}
                        key={this.state.tableObj.patNo}
                        number={this.state.tableObj.patNo}
                    ></PatientAccountManagement>
                </Modal>
            </div>
        );
    }
}

export default PreInRefund;
