import React from 'react';
import ReactDOM from 'react-dom';
import { Select, Input, Row, Col, Button, Spin, Divider, Popconfirm, message, Icon, Form, DatePicker, Table, Tabs, Modal, Card } from 'antd';
import { $http } from 'containers/config/https.js';
import { Keup, ArraySome } from 'tools/index';
import ReadCard from '../../../../../components/readcard/ReadCard';
//import '../../style/style.less'
//import '../../../../opadmReg/style/index.less';
let user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
let configData = {}
let IfChargeFlag = 'N';
let readPower = 'N'
const styles = {
    mask: {
        position: 'fixed',
        top: 0,
        right: 0,
        left: 0,
        bottom: 0,
        backgroundColor: 'rgba(0, 0, 0, 0.65)',
        height: '100%',
        zIndex: 1000,
        display: 'none',
    },
    modalWrap: {
        position: 'fixed',
        top: 0,
        right: 0,
        left: 0,
        bottom: 0,
        zIndex: 1000,
        display: 'none',
    },
    modal: {
        fontSize: 14,
        padding: 20,
        width: 520,
        height: 200,
        margin: '100px auto 0',
        backgroundColor: '#fff',
        borderRadius: 4,
        overflow: 'hidden',
        textAlign: 'center',
        display: 'none',
    },
    btnGroup: {
        padding: 10,
        textAlign: 'right',
        display: 'none',
    }
};
export default class OtherCashRegister extends React.Component {

    constructor(props) {
        super(props)
        this.dom = null //被append的元素
    }

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

    }

    //诊间收费接口
    OPPaycashier() {
        this.close();
        this.dom = document.createElement('div');

        // JSX代码
        const render = this.render();
        ReactDOM.render(render, this.dom);
        document.body.appendChild(this.dom);
    }

    //确定
    onCancel(onCancel) {
        (onCancel instanceof Function) && onCancel();
        this.close();
    }
    //取消
    onOk(onOk) {
        (onOk instanceof Function) && onOk();
        this.close();
    }
    //关闭
    close() {
        this.dom && this.dom.remove();
    }
    // 权限
    initJuris() {

    }


    //院内支付收费校验
    CheckCPPAmt(Checkjason,callback) {

        var data = {
            params: [{
                logonHospID: JSON.parse(window.sessionStorage.userData).hospID, //医院id 
                logonGroupID: JSON.parse(window.sessionStorage.userData).groupID,  //角色id
                logonUserID: JSON.parse(window.sessionStorage.userData).userID, //人员id
                invTypeCode: 'O'  // 类型
            }]
        }
        $http.post('urlS', this, {
            code: "05210001",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    configData = res
                    let patID = Checkjason.patID
                    let cppAmt = Checkjason.cppAmt
                    let errorMessage = "校验成功"
                    let AccPayVerification = configData.sysConfig.AccPayVerification
                    //let accmID="123"
                    if (AccPayVerification === "R") {
        
                        this.readCard.ReadCard('1', "R", (json) => {
                    
                            let patIDRead = json && json.patInfo ? json.patInfo.patID : '';
                            let accountBalanceRead = json && json.patInfo ? json.patInfo.accountBalance : '';
                            let accTSubID = json && json.patInfo ? json.patInfo.accTSubID : '';
                            let accmID = accTSubID && accTSubID !== '' ? accTSubID.split("||")[0] : '';
              
                            if ((patIDRead === patID) & (cppAmt <= accountBalanceRead)) {
                                let rtn = {
                                    CheckCPPFlag: true, //true 校验成功 ，false 校验失败
                                    errorMessage: errorMessage,
                                    accmID: accmID,
                                }
                             
                                callback(rtn) 
                            } else {
                                if (patIDRead !== patID) { errorMessage = "病人信息校验失败" } else { errorMessage = "账户余额不足" }
                                let rtn = {
                                    CheckCPPFlag: false, //true 校验成功 ，false 校验失败
                                    errorMessage: errorMessage,
                                    accmID: accmID,
                                }
                         
                                callback(rtn) 
                            }

                        })
                    } else {
                        let rtn = {
                            CheckCPPFlag: true, //true 校验成功 ，false 校验失败
                            errorMessage: errorMessage,
                            accmID: "",
                        }
                        callback(rtn) 
                    }
                }
            }
        });


    }

    //诊间收费弹框界面
    render() {
        return (
            <div>
                <ReadCard ref={r => this.readCard = r} />
                <div style={styles.mask} />
                <div style={styles.modalWrap}>
                    <div style={styles.modal}>
                        <Row className='mT10'>
                            <Col span={24} style={{ fontSize: '16px' }} >
                                <div>
                                    <div style={{ display: 'flex' }}><div className='border-radius-fee'></div>
                                        <div style={{ marginLeft: 10, fontWeight: 'bold' }}>收费信息</div></div>
                                    <div style={{ float: 'left', marginLeft: 30 }}>
                                        <span><span style={{ background: '#F5F4F4' }}>实际金额(元)：</span>
                                            <span style={{ color: '#FA8C16' }}></span>
                                        </span><br />

                                        <span><span style={{ background: '#F5F4F4' }}>统筹金额(元)：</span>
                                            <span style={{ color: '#FA8C16' }}></span>
                                        </span><br />
                                        <span><span style={{ background: '#F5F4F4' }}>院内账户(元)：</span>
                                            <span style={{ color: '#FA8C16' }}></span>
                                        </span>
                                        <span style={{ marginLeft: 10 }}>账户余额(元):<span style={{ color: '#FA8C16' }}> </span>
                                            <span style={{ marginLeft: '10px', width: '50px', color: 'rgb(66, 185, 131)' }}></span>
                                            {/* <label ><Checkbox style={{ marginLeft: 10 }} /><span>不使用账户</span></label>  */}

                                        </span>
                                        <br />
                                        <span><span style={{ background: '#F5F4F4' }}>社保账户(元)：</span>
                                            <span style={{ color: '#FA8C16' }}></span>
                                            <span style={{ marginLeft: 10 }}>账户余额(元)：<span style={{ color: '#FA8C16' }}></span></span>
                                        </span>
                                    </div>
                                    <div style={{ float: 'right', marginRight: '18%' }}>
                                        <span><span style={{ background: '#F5F4F4' }}>减免金额(元)：</span>
                                            <span style={{ color: '#FA8C16' }}></span>
                                        </span>
                                    </div>
                                </div>
                            </Col>
                        </Row>
                        <div style={styles.btnGroup}>
                            <Button onClick={() => this.onCancel()}>取消</Button>
                            <Button type="primary" onClick={() => this.onOk()}>确定</Button>
                        </div>
                    </div>
                </div >
            </div>
        )
    }

}


