//住院收费结算数据统一配置
import React from 'react'
import { Form, Row, Col, Select, Input, Button, Switch, message } from 'antd'
import { $http } from 'containers/config/https';
const { Option } = Select;


class HospitalChargesConfiguration extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            id: '',
            hospID: JSON.parse(window.sessionStorage.userData).hospID,   //医院名称
            userID: JSON.parse(window.sessionStorage.userData).userID,   //医院名称
            hospdesc: '',     //打印在单据上的医院名称
            defBillConditionID: '', //默认计费点
            defAdmReasonID: '', //默认病人类别
            ifMotherAddBaby: false,//是否母婴账单合并
            ifPrintNeDeposit: false,//退押金是否打印负票
            ifModifyPaymode: false,//退押金是否允许修改支付方式
            ifAbortByUnFoot: false,//收费员未交账退押金是否按作废方式处理
            ifPrintDepByAbort: false,//作废押金是否自动打印新押金收据
            ifPrintInvByArrear: false,//欠费结算是否打印发票
            ifAbortByUnFootDelBill: false,//收费员未交账取消结算是否按作废方式处理
            ifModifyAdmdate: false,//住院登记页面是否可以修改入院日期
            ifOMByBillCondition: false,//出院带药是否按计费点计费
            ifInsuHalfwayCharge: false,//医保病人是否允许中途结算
            ifPrintInvByAbort: false,// 作废发票是否自动打印新发票
            ifChooseDepByCharge: false,// 结算患者费用是是否可以选择押金
            frontIPCertificateDate: 0,// 住院证办理入院登记有效天数(前)
            afterIPCertificateDate: 0,//住院证办理入院登记有效天数(后)
            payAccIPAmtFlag: false,// 住院收费账户金额是否可以修改
        }
    }

    //初始化数据
    componentDidMount() {
        this.handleHospQuery()      //医院
        this.loadAdmReaSonType()    //类别
        this.loadBillConType()      //计费点
        this.loadBillConTypeQuery() //根据医院查询
    }

    //选择医院onChange事件
    BillConTypeonChange = (hospID) => {
        this.setState({
            hospID: hospID,
        }, () => {
            this.loadBillConTypeQuery();
        })
    }

    //根据医院查询
    loadBillConTypeQuery = () => {
        let data = {}
        data = {
            params: [{
                hospID: this.state.hospID
            }]
        };
        $http.post('urlDeanlt', this, {
            code: "05100398",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {

                    let ifMotherAddBaby = false
                    if (res.data.ifMotherAddBaby == "Y") { ifMotherAddBaby = true }

                    let ifPrintNeDeposit = false
                    if (res.data.ifPrintNeDeposit == "Y") { ifPrintNeDeposit = true }

                    let ifModifyPaymode = false
                    if (res.data.ifModifyPaymode == "Y") { ifModifyPaymode = true }

                    let ifAbortByUnFoot = false
                    if (res.data.ifAbortByUnFoot == "Y") { ifAbortByUnFoot = true }

                    let ifPrintDepByAbort = false
                    if (res.data.ifPrintDepByAbort == "Y") { ifPrintDepByAbort = true }

                    let ifPrintInvByArrear = false
                    if (res.data.ifPrintInvByArrear == "Y") { ifPrintInvByArrear = true }

                    let ifAbortByUnFootDelBill = false
                    if (res.data.ifAbortByUnFootDelBill == "Y") { ifAbortByUnFootDelBill = true }

                    let ifModifyAdmdate = false
                    if (res.data.ifModifyAdmdate == "Y") { ifModifyAdmdate = true }

                    let ifOMByBillCondition = false
                    if (res.data.ifOMByBillCondition == "Y") { ifOMByBillCondition = true }

                    let ifInsuHalfwayCharge = false
                    if (res.data.ifInsuHalfwayCharge == "Y") { ifInsuHalfwayCharge = true }

                    let ifPrintInvByAbort = false
                    if (res.data.ifPrintInvByAbort == "Y") { ifPrintInvByAbort = true }

                    let ifChooseDepByCharge = false
                    if (res.data.ifChooseDepByCharge == "Y") { ifChooseDepByCharge = true }

                    let payAccIPAmtFlag = false
                    if (res.data.payAccIPAmtFlag == "Y") { payAccIPAmtFlag = true }
                    this.setState({
                        id: res.data.id,
                        hospdesc: res.data.hospdesc,     //打印在单据上的医院名称
                        defBillConditionID: res.data.defBillConditionID, //默认计费点
                        defAdmReasonID: res.data.defAdmReasonID, //默认病人类别
                        ifMotherAddBaby: ifMotherAddBaby,//是否母婴账单合并
                        ifPrintNeDeposit: ifPrintNeDeposit,//退押金是否打印负票
                        ifModifyPaymode: ifModifyPaymode,//退押金是否允许修改支付方式
                        ifAbortByUnFoot: ifAbortByUnFoot,//收费员未交账退押金是否按作废方式处理
                        ifPrintDepByAbort: ifPrintDepByAbort,//作废押金是否自动打印新押金收据
                        ifPrintInvByArrear: ifPrintInvByArrear,//欠费结算是否打印发票
                        ifAbortByUnFootDelBill: ifAbortByUnFootDelBill,//收费员未交账取消结算是否按作废方式处理
                        ifModifyAdmdate: ifModifyAdmdate,//住院登记页面是否可以修改入院日期
                        ifOMByBillCondition: ifOMByBillCondition,//出院带药是否按计费点计费
                        ifInsuHalfwayCharge: ifInsuHalfwayCharge,//医保病人是否允许中途结算
                        ifPrintInvByAbort: ifPrintInvByAbort,// 作废发票是否自动打印新发票
                        ifChooseDepByCharge: ifChooseDepByCharge,// 结算患者费用是是否可以选择押金
                        frontIPCertificateDate: res.data.frontIPCertificateDate,// 住院证办理入院登记有效天数(前)
                        afterIPCertificateDate: res.data.afterIPCertificateDate,//住院证办理入院登记有效天数(后)
                        payAccIPAmtFlag
                    })
                }
            }
        })
    }

    //保存
    handleSubmit = () => {
        let { validateFields } = this.props.form;
        validateFields({ force: true }, (err, params) => {
            if (err) {
                return;
            }
            let data = {}
            let obj = params;
            obj.id = this.state.id
            obj.userID = this.state.userID
            data = {
                params: [params]
            };
            $http.post('urlDeanlt', this, {
                code: "05100399",
                data: data,
                success: function (res) {
                    if (res.errorCode === '0') {
                        message.success('保存成功！')
                        //重置表单
                        this.props.form.resetFields();
                        //刷新列表数据
                        this.loadBillConTypeQuery()
                    }
                }
            })
        })
    }

    //医院下拉框
    handleHospQuery = () => {
        let data = {}
        data = {
            params: [{
                hospitalId: "",
                logonGroupID: JSON.parse(window.sessionStorage.userData).groupID,
                logonHospID: JSON.parse(window.sessionStorage.userData).hospID,
                hospRequired: "1",
            }]
        }
        $http.post('urlS', this, {
            code: '01040001',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.depDoctor) {
                    let tempList = [];
                    for (var i = 0; i < res.depDoctor.length; i++) {
                        tempList.push(<Option key={res.depDoctor[i].id}>{res.depDoctor[i].descripts}</Option>)
                    }
                    this.setState({
                        hospList: tempList
                    })
                }
            }
        })
    }

    //病人类别下拉框
    loadAdmReaSonType() {
        var params = {
            params: [{
                hospID: JSON.parse(window.sessionStorage.userData).hospID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "05100247",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        AdmReaSonTypeData: res.AdmReaSonArr
                    })
                }
            }
        });
    }

    //计费点下拉框
    loadBillConType() {
        var params = {
            params: [{
            }]
        }
        $http.post('urlDeault', this, {
            code: "05100289",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        BillConTypeData: res.result
                    })
                }
            }
        });
    }

    onChange = (code,checked) => {
        this.setState({[code]:checked})
    }

    render() {
        let { getFieldDecorator } = this.props.form;
        //获取病人类别
        let AdmReaSonTypeOption = []
        this.state.AdmReaSonTypeData && this.state.AdmReaSonTypeData.map((item, index) => {
            AdmReaSonTypeOption.push(<Option key={index} value={item.ID}>{item.AdmReaSon}</Option>)
        })

        //获取计费点
        let BillConTypeOption = []
        this.state.BillConTypeData && this.state.BillConTypeData.map((item, index) => {
            BillConTypeOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })
        return (
            <div>
                <Form>
                    <Row>
                        <Col span={4}>
                            <Form.Item label="医院名称">
                                {getFieldDecorator("hospID", {
                                    initialValue: this.state.hospID,
                                    rules: [{ required: true }]
                                })(
                                    <Select style={{ width: '250px' }} onChange={this.BillConTypeonChange.bind(this)}>{this.state.hospList}</Select>
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="医院打印描述">
                                {getFieldDecorator("hospdesc", {
                                    initialValue: this.state.hospdesc,
                                    rules: [{ required: true }]
                                })(
                                    <Input style={{ width: '250px' }} placeholder="打印在单据上的医院名称" />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="默认计费点">
                                {getFieldDecorator("defBillConditionID", {
                                    initialValue: this.state.defBillConditionID,
                                    rules: [{ required: true }]
                                })(
                                    <Select style={{ width: '250px' }}>{BillConTypeOption}</Select>
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="默认病人类别">
                                {getFieldDecorator("defAdmReasonID", {
                                    initialValue: this.state.defAdmReasonID,
                                    rules: [{ required: true }]
                                })(
                                    <Select style={{ width: '250px' }}>{AdmReaSonTypeOption}</Select>
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="是否母婴账单合并">
                                {getFieldDecorator("ifMotherAddBaby", {
                                    initialValue: this.state.ifMotherAddBaby,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifMotherAddBaby} onChange={this.onChange.bind(this,"ifMotherAddBaby")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="退押金是否打印负票">
                                {getFieldDecorator("ifPrintNeDeposit", {
                                    initialValue: this.state.ifPrintNeDeposit,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifPrintNeDeposit} onChange={this.onChange.bind(this,"ifPrintNeDeposit")}/>
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="退押金是否允许修改支付方式">
                                {getFieldDecorator("ifModifyPaymode", {
                                    initialValue: this.state.ifModifyPaymode,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifModifyPaymode} onChange={this.onChange.bind(this,"ifModifyPaymode")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="收费员未交账退押金是否按作废方式处理">
                                {getFieldDecorator("ifAbortByUnFoot", {
                                    initialValue: this.state.ifAbortByUnFoot,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifAbortByUnFoot} onChange={this.onChange.bind(this,"ifAbortByUnFoot")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="作废押金是否自动打印新押金收据">
                                {getFieldDecorator("ifPrintDepByAbort", {
                                    initialValue: this.state.ifPrintDepByAbort,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifPrintDepByAbort} onChange={this.onChange.bind(this,"ifPrintDepByAbort")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="欠费结算是否打印发票">
                                {getFieldDecorator("ifPrintInvByArrear", {
                                    initialValue: this.state.ifPrintInvByArrear,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifPrintInvByArrear} onChange={this.onChange.bind(this,"ifPrintInvByArrear")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="收费员未交账取消结算是否按作废方式处理">
                                {getFieldDecorator("ifAbortByUnFootDelBill", {
                                    initialValue: this.state.ifAbortByUnFootDelBill,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifAbortByUnFootDelBill} onChange={this.onChange.bind(this,"ifAbortByUnFootDelBill")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="住院登记页面是否可以修改入院日期">
                                {getFieldDecorator("ifModifyAdmdate", {
                                    initialValue: this.state.ifModifyAdmdate,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifModifyAdmdate} onChange={this.onChange.bind(this,"ifModifyAdmdate")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="出院带药是否按计费点计费">
                                {getFieldDecorator("ifOMByBillCondition", {
                                    initialValue: this.state.ifOMByBillCondition,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifOMByBillCondition} onChange={this.onChange.bind(this,"ifOMByBillCondition")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="医保病人是否允许中途结算">
                                {getFieldDecorator("ifInsuHalfwayCharge", {
                                    initialValue: this.state.ifInsuHalfwayCharge,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifInsuHalfwayCharge} onChange={this.onChange.bind(this,"ifInsuHalfwayCharge")} />)}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="作废发票是否自动打印新发票">
                                {getFieldDecorator("ifPrintInvByAbort", {
                                    initialValue: this.state.ifPrintInvByAbort,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifPrintInvByAbort} onChange={this.onChange.bind(this,"ifPrintInvByAbort")} />
                                )}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="结算患者费用是是否可以选择押金">
                                {getFieldDecorator("ifChooseDepByCharge", {
                                    initialValue: this.state.ifChooseDepByCharge,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.ifChooseDepByCharge} onChange={this.onChange.bind(this,"ifChooseDepByCharge")} />)}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="住院证办理入院登记有效天数(前)">
                                {getFieldDecorator("frontIPCertificateDate", {
                                    initialValue: this.state.frontIPCertificateDate,
                                    rules: [{ required: false }]
                                })(
                                    <Input style={{ width: '200px' }} />)}
                            </Form.Item>
                        </Col>
                        <Col span={4}>
                            <Form.Item label="住院证办理入院登记有效天数(后)">
                                {getFieldDecorator("afterIPCertificateDate", {
                                    initialValue: this.state.afterIPCertificateDate,
                                    rules: [{ required: false }]
                                })(
                                    <Input style={{ width: '200px' }} />)}
                            </Form.Item>
                        </Col>                        
                        <Col span={4}>
                            <Form.Item label="住院收费账户金额是否可以修改">
                                {getFieldDecorator("payAccIPAmtFlag", {
                                    initialValue: this.state.payAccIPAmtFlag,
                                    rules: [{ required: true }]
                                })(
                                    <Switch checkedChildren="是" unCheckedChildren="否" checked={this.state.payAccIPAmtFlag} onChange={this.onChange.bind(this,"payAccIPAmtFlag")} />)}
                            </Form.Item>
                        </Col>
                    </Row>
                </Form>
                <Row style={{ marginTop: '20px', marginLeft: '680px' }}><Button type="primary" onClick={this.handleSubmit}>保存</Button></Row>
            </div>
        )
    }
}
export default Form.create()(HospitalChargesConfiguration)