//医院信息维护
import React from 'react';
import { Select, Input, Row, Col, Button, Spin, Divider, Popconfirm, message, Icon, Form, Modal, Card, Switch, DatePicker, Popover, List } from 'antd';
import { $http } from '../../containers/config/https';
import '../../assets/css/system.css';
import PubilcTablePagination from '../common/PubilcTablePagination.jsx';
import store from './../../store/index';
import moment from 'moment';

const { Option } = Select;
const FormItem = Form.Item;

const formItemLayout = {
    labelCol: { span: 10 },
    wrapperCol: { span: 14 },
}

const HospitalMaintenance = Form.create()(
    class HospitalMaintenance extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                data: [],
                columns: [],
                total: 0,
                page: 1,
                pageSize: 10,
                baseParms: [],
                values: {},
                hospID: "",
                higherHospID: "",
                healthBureauArr: [],//卫生局
                superiorHospitalArr: [],//上级医院
                cityArr: [],
                areasArr: [],
                VillagesArr: [],
                hamletsArr: [],
                heightTable: "",
            }
        }

        componentDidMount() {
            // 初始化设置table的高度以及表体的高度 内容高度 height
            if (document.querySelector('.ant-table-body')) {
                document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y - 40 + 'px'
            }
            this.getHealthBureauArr();
            this.getBaseParams();
        }

        //获取对应的医院基础信息数据
        getBaseParams = () => {
            let data = {
                params: [{

                }],
            }
            $http.post("urlS", this, {
                code: "05100224",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            baseParms: res.result
                        })
                    } else {
                        message.error('失败：' + res.errorMessage);
                    }
                },
                error: function (error) {
                    message.error('失败：' + error);
                }
            })
        }

        //获取卫生局下拉框数据
        getHealthBureauArr = () => {
            let data = {
                params: [{
                }],
            }
            $http.post("urlS", this, {
                code: "05100220",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            healthBureauArr: res.result.Data
                        })
                    } else {
                        message.error('失败：' + res.errorMessage);
                    }
                },
                error: function (error) {
                    message.error('失败：' + error);
                }
            })
        }

        setRowClassName = (record) => {
            return record.hospID === this.state.rowId ? 'clickRowStyle' : '';
        }

        FindData = () => {
            const { propMethod: { findData } } = this.props;
            this.showModal(false);
            findData();
            this.reset();
        }

        // 页码改变的回调，参数是改变后的页码及每页条数
        PageChange = (page, pageSize) => {
            this.setState({ page: page, pageSize: pageSize }, () => {
                // 重新调用查询方法
                this.FindData()
            });
        }

        // 条数改变的回调
        onShowSizeChange = (current, size) => {
            this.setState({ page: current, pageSize: size }, () => {
                // 重新调用查询方法
                this.FindData()
            });
        }

        onClickRow = (record) => {
            //给右边的编辑form传值
            return {
                onClick: () => {
                    // console.log("record",record)
                    this.reset()
                    this.setState({
                        params: record,
                        hospID: record.hospID,
                        higherHospID: record.higherHospID,
                        cityArr: [],
                        areasArr: [],
                        VillagesArr: [],
                    })
                    if (this.state.rowId === "") {
                        this.setState({
                            rowId: record.hospID,
                        });
                    } else {
                        if (this.state.rowId !== record.hospID) {
                            this.setState({
                                rowId: record.hospID,
                            });
                        } else {
                            this.setState({
                                rowId: "",
                            });
                            this.reset()
                            this.setState({
                                params: {},
                                hospID: "",
                                higherHospID: "",
                                cityArr: [],
                                areasArr: [],
                                VillagesArr: [],
                            })
                        }
                    }
                },
            };
        }

        ImportData = () => {
            this.DataImport.DrawerShow()
        }

        handleSwithChange = (val) => {
        }

        handleStatus = (v) => {
        }

        save = () => {
            this.props.form.validateFields((err, values) => {
                const { page, pageSize } = this.state;
                const { data: params } = this.props;
                if (!err) {
                    let data = {
                        params: [{
                            hospID: params && params.hospID ? params.hospID : "",
                            hospSeqNo: values.hospSeqNo || "",
                            hospCode: values.hospCode || "",
                            hospDesc: values.hospDesc || "",
                            healBureauID: values.healBureauID || "",
                            higherHospID: this.state.higherHospID || "",
                            hospGradeID: values.hospGradeID || "",
                            hospTypeID: values.hospTypeID || "",
                            hospNatureID: values.hospNatureID || "",
                            address: values.address || "",
                            deanName: values.deanName || "",
                            officePhone: values.officePhone || "",
                            email: values.email || "",
                            provID: values.provID || "",
                            cityID: values.cityID || "",
                            areaID: values.areaID || "",
                            villageID: values.villageID || "",
                            clinicFlag: values.clinicFlag == true ? "Y" : "N",
                            organizationCode: values.organizationCode || "",
                            businesslicense: values.businesslicense || "",
                            ZIPCode: values.ZIPCode || "",
                            website: values.website || "",
                            startDate: values.startDate ? moment(values.startDate).format('YYYY-MM-DD') : undefined,
                            stopDate: values.stopDate ? moment(values.stopDate).format('YYYY-MM-DD') : '',
                            updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                            authorizeCode: values.authorizeCode || "",
                            introduce: values.introduce || "",
                            logo: values.logo || "",
                            oneRowNumber: values.oneRowNumber || "",
                            height: values.height || "",
                            width: values.width || "",
                            bedInterval: values.bedInterval || "",
                            businesslicenseDesc: values.businesslicenseDesc || "",
                        }],
                        pagination: [{
                            pageSize: pageSize,
                            currentPage: page,
                        }]
                    }
                    $http.post("urlS", this, {
                        code: "05100209",
                        data: data,
                        success: function (res) {
                            if (+res.errorCode === 0) {
                                if (params && params.hospID) {
                                    message.success("修改成功")
                                    this.FindData();
                                } else {
                                    message.success("新增成功")
                                    this.FindData();
                                }
                            } else {
                                message.error('失败：' + res.errorMessage);
                            }
                        },
                        error: function (error) {
                            message.error('失败：' + error);
                        }
                    })
                } else {
                }
            })
        }

        reset = () => {
            this.props.form.resetFields();
        }

        //省拼检索上级医院
        handleSearch = (val) => {
            let data = {
                params: [{
                    higherHospDesc: val,
                }]
            };
            //上级医院下拉
            if (val) {
                $http.post('urlS', this, {
                    code: "05100223",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({ superiorHospitalArr: res.result.Data })
                        }
                    }
                })
            }
        }

        //上级医院点击获取id
        handleSuperior = (v) => {
            this.setState({
                higherHospID: v.key
            })
        }

        //清空上级医院
        handleClear = (v) => {
            if (!v) {
                this.setState({
                    higherHospID: ""
                })
            }
        }

        //选择清除省
        handleProvince = (flag, value, option) => {
            if (value) {
                let city = []
                city = this.state.baseParms.provDataList.filter((item) => item.id == value);
                this.setState({
                    cityArr: city[0].cityDataList,
                    areasArr: [],
                    VillagesArr: []
                })
                this.props.form.setFieldsValue({ cityID: undefined, areaID: undefined, villageID: undefined })
            } else {
                this.props.form.setFieldsValue({ cityID: undefined, areaID: undefined, villageID: undefined })
                this.setState({
                    cityArr: [],
                    areasArr: [],
                    VillagesArr: []
                })
            }
        }

        //选择市
        handleCity = (flag, value) => {
            if (value) {
                this.getAreas(value)
            } else {
                this.props.form.setFieldsValue({ areaID: undefined, villageID: undefined })
                this.setState({
                    areasArr: [],
                    VillagesArr: []
                })
            }
        }

        //市获取焦点
        onCityFocus = () => {
            let city = this.state.cityArr;
            let provinceID = this.props.form.getFieldValue("provID");
            if ((city.length === 0) && (provinceID)) {
                let newCity = []
                newCity = this.state.baseParms.provDataList.filter((item) => item.id == provinceID);
                this.setState({
                    cityArr: newCity[0].cityDataList,
                })
            }
        }

        //县获取焦点
        onAreasFocus = () => {
            let area = this.state.areasArr
            let cityID = this.props.form.getFieldValue("cityID");
            if ((area.length === 0) && (cityID)) {
                this.getAreas(cityID);
            }
        }

        //乡获取焦点
        onVillagesFocus = () => {
            let village = this.state.VillagesArr
            let areaID = this.props.form.getFieldValue("areaID");
            if ((village.length === 0) && (areaID)) {
                this.getVillages(areaID);
            }
        }

        //选择县
        handleAreas = (flag, value) => {
            if (value) {
                this.getVillages(value)
            } else {
                this.props.form.setFieldsValue({ villageID: undefined })
                this.setState({
                    VillagesArr: []
                })
            }
        }

        //选择市 加载县
        getAreas = (cityID) => {
            let data = {
                params: [{
                    cityId: cityID
                }],
            }
            $http.post('urlS', this, {
                code: '03030006',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            areasArr: res.result,
                        })
                    } else {
                        this.setState({
                            areasArr: [],
                            VillagesArr: [],
                            hamletsArr: [],
                        })
                    }
                }
            })
        }

        //选择县时加载乡数据
        getVillages = (countyID) => {
            let data = {
                params: [{
                    areaId: countyID,
                }],
            }
            $http.post('urlS', this, {
                code: '03030007',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            VillagesArr: res.result,
                        })
                    } else {
                        this.setState({
                            VillagesArr: [],
                            hamletsArr: [],
                        })
                    }
                }
            })
        }

        // 显示分页总条数
        showTotal(total) {
            return `共 ${total} 条`;
        }

        showModal = (bool) => {
            const { propMethod: { showModal } } = this.props;
            showModal(bool);
            this.reset();
        }

        render() {
            const { modalVisible, data: params, propMethod } = this.props;
            const { getFieldDecorator } = this.props.form;
            const { baseParms, healthBureauArr, superiorHospitalArr, cityArr, areasArr,
                VillagesArr, hamletsArr, } = this.state;

            //卫生局
            let healthBureauoP = []
            healthBureauArr && healthBureauArr.map(item => {
                healthBureauoP.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            //上级医院
            let superiorHospitalOp = []
            superiorHospitalArr && superiorHospitalArr.map(item => {
                superiorHospitalOp.push(<Option key={item.hospID} onClick={this.handleSuperior} role={item.hospDesc} title={item.hospDesc} value={String(item.hospID)}>{item.hospDesc}</Option>)
            })
            //医院级别
            let hospitalLevelOp = []
            baseParms.hospGradeList && baseParms.hospGradeList.map(item => {
                hospitalLevelOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            //医院类型
            let hospitalTypeOp = []
            baseParms.hospTypeList && baseParms.hospTypeList.map(item => {
                hospitalTypeOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            //医院性质
            let hospitaNatureOp = []
            baseParms.hospNatureList && baseParms.hospNatureList.map(item => {
                hospitaNatureOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            //省
            let provinceOp = []
            baseParms.provDataList && baseParms.provDataList.map(item => {
                provinceOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            //市
            let cityOp = []
            cityArr && cityArr.map(item => {
                cityOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            if ((cityArr) && (cityArr.length === 0) && params && (params.cityID)) {
                cityOp.push(<Option key={params.cityID} role={params.cityDesc} title={params.cityDesc} value={String(params.cityID)}>{params.cityDesc}</Option>)
            }
            //县
            let areaOp = []
            areasArr && areasArr.map(item => {
                areaOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            if ((areasArr) && (areasArr.length === 0) && params && (params.areaID)) {
                areaOp.push(<Option key={params.areaID} role={params.areaDesc} title={params.areaDesc} value={String(params.areaID)}>{params.areaDesc}</Option>)
            }
            //乡
            let villagesOp = []
            VillagesArr && VillagesArr.map(item => {
                villagesOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
            })
            if ((VillagesArr) && (VillagesArr.length === 0) && params && (params.villageID)) {
                villagesOp.push(<Option key={params.villageID} role={params.villageDesc} title={params.villageDesc} value={String(params.villageID)}>{params.villageDesc}</Option>)
            }
            return (
                <Modal onCancel={() => this.showModal(false)} title={<span>{params ? params.hospDesc : ''}</span>} visible={modalVisible} width={1200} footer={<div style={{ display: "flex", justifyContent: "flex-end" }}>
                    <Button style={{ marginRight: '30px' }} onClick={() => this.showModal(false)}>取消</Button>
                    <Button style={{ marginRight: '30px' }} type="primary" onClick={this.save}>{params && params ? "更新" : "新增"}</Button>

                    <Button type="primary" onClick={this.reset}>重置</Button>
                </div>} >
                    <Row style={{ margin: "0" }}>
                        <Col span={24} style={{ paddingLeft: "0px" }}>
                            <Card>
                                <Form style={{ height: "100%", overflow: "hidden auto" }}>
                                    <Row>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='序号'>
                                                {getFieldDecorator('hospSeqNo', {
                                                    initialValue: params && params.hospSeqNo ? params && params.hospSeqNo : undefined,
                                                    rules: [{ required: false, message: '请输入', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='代码'>
                                                {getFieldDecorator('hospCode', {
                                                    initialValue: params && params.hospCode ? params.hospCode : undefined,
                                                    rules: [{ required: true, message: '请输入代码' }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='描述'>
                                                {getFieldDecorator('hospDesc', {
                                                    initialValue: params && params.hospDesc ? params && params.hospDesc : undefined,
                                                    rules: [{ required: true, message: '请输入描述' }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='卫生局'>
                                                {getFieldDecorator('healBureauID', {
                                                    initialValue: params && params.healBureauID ? String(params.healBureauID) : undefined,
                                                    rules: [{ required: true, message: '请选择卫生局' }],
                                                })(
                                                    <Select showSearch allowClear optionFilterProp="role" >
                                                        {healthBureauoP}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='上级医院'>
                                                {getFieldDecorator('higherHospID', {
                                                    initialValue: params && params.higherHospDesc ? String(params.higherHospDesc) : undefined,
                                                    rules: [{ required: false, message: '请选择上级医院', },
                                                    ],
                                                })(
                                                    <Select placeholder="请输入首拼/汉字进行检索" onChange={this.handleClear} showSearch allowClear onSearch={this.handleSearch} showArrow={false} filterOption={false} defaultActiveFirstOption={false} notFoundContent={null} optionFilterProp="role" >
                                                        {superiorHospitalOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='医院级别'>
                                                {getFieldDecorator('hospGradeID', {
                                                    initialValue: params && params.hospGradeID ? String(params.hospGradeID) : undefined,
                                                    rules: [{ required: true, message: '请选择医院级别' }],
                                                })(
                                                    <Select showSearch allowClear optionFilterProp="role" >
                                                        {hospitalLevelOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='医院类型'>
                                                {getFieldDecorator('hospTypeID', {
                                                    initialValue: params && params.hospTypeID ? String(params.hospTypeID) : undefined,
                                                    rules: [{ required: true, message: '请选择医院类型' }],
                                                })(
                                                    <Select showSearch allowClear optionFilterProp="role" >
                                                        {hospitalTypeOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='医院性质'>
                                                {getFieldDecorator('hospNatureID', {
                                                    initialValue: params && params.hospNatureID ? String(params.hospNatureID) : undefined,
                                                    rules: [{ required: true, message: '请选择医院性质' }],
                                                })(
                                                    <Select showSearch allowClear optionFilterProp="role" >
                                                        {hospitaNatureOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='物理位置'>
                                                {getFieldDecorator('address', {
                                                    initialValue: params && params.address ? params.address : undefined,
                                                    rules: [{ required: true, message: '', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='院长'>
                                                {getFieldDecorator('deanName', {
                                                    initialValue: params && params.deanName ? params && params.deanName : undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='院长电话'>
                                                {getFieldDecorator('deanPhone', {
                                                    initialValue: params && params.deanPhone ? params && params.deanPhone : undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='院办电话'>
                                                {getFieldDecorator('officePhone', {
                                                    initialValue: params && params.officePhone ? params && params.officePhone : undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='医院邮箱'>
                                                {getFieldDecorator('email', {
                                                    initialValue: params && params.email ? params && params.email : undefined,
                                                    rules: [{ required: false, message: '请输入', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='省'>
                                                {getFieldDecorator('provID', {
                                                    initialValue: params && params.provID ? String(params.provID) : undefined,
                                                    rules: [{ required: true, message: '请选择省' }],
                                                })(
                                                    <Select onChange={this.handleProvince.bind(this, "prov")} showSearch allowClear optionFilterProp="role" >
                                                        {provinceOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='市'>
                                                {getFieldDecorator('cityID', {
                                                    initialValue: params && params.cityID ? String(params.cityID) : undefined,
                                                    rules: [{ required: true, message: '请选择市' }],
                                                })(
                                                    <Select onFocus={this.onCityFocus.bind(this)} onChange={this.handleCity.bind(this, "city")} showSearch allowClear optionFilterProp="role" >
                                                        {cityOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='县'>
                                                {getFieldDecorator('areaID', {
                                                    initialValue: params && params.areaID ? String(params.areaID) : undefined,
                                                    rules: [{ required: true, message: '请选择县' }],
                                                })(
                                                    <Select onFocus={this.onAreasFocus.bind(this)} onChange={this.handleAreas.bind(this, "area")} showSearch allowClear optionFilterProp="role" >
                                                        {areaOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='乡'>
                                                {getFieldDecorator('villageID', {
                                                    initialValue: params && params.villageID ? String(params.villageID) : undefined,
                                                    rules: [{ required: false, message: '请选择乡' }],
                                                })(
                                                    <Select onFocus={this.onVillagesFocus.bind(this)} showSearch allowClear optionFilterProp="role" >
                                                        {villagesOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem {...formItemLayout} label='诊所'>
                                                {getFieldDecorator('clinicFlag', {
                                                    initialValue: params && params.clinicFlag ? params && params.clinicFlag : undefined,
                                                    rules: [{ required: false, message: '请选择' }],
                                                })(
                                                    // checked={record.logLocIsDefault&&record.logLocIsDefault=="Y"?true:false}
                                                    <Switch checkedChildren="是" unCheckedChildren="否" onChange={(val) => this.handleSwithChange(val)} />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='机构代码'>
                                                {getFieldDecorator('organizationCode', {
                                                    initialValue: params && params.organizationCode ? params && params.organizationCode : undefined,
                                                    rules: [{ required: true, message: '请输入机构代码', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='营业执照'>
                                                {getFieldDecorator('businesslicense', {
                                                    initialValue: params && params.businesslicense ? params && params.businesslicense : undefined,
                                                    rules: [{ required: true, message: '请输入', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='营业执照名称'>
                                                {getFieldDecorator('businesslicenseDesc', {
                                                    initialValue: params && params.businesslicenseDesc ? params && params.businesslicenseDesc : undefined,
                                                    rules: [{ required: false, message: '', }]
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='邮编'>
                                                {getFieldDecorator('ZIPCode', {
                                                    validateTrigger: ["onPressEnter", "onBlur"],
                                                    initialValue: params && params.ZIPCode ? params && params.ZIPCode : undefined,
                                                    rules: [{ required: true, message: '请输入邮编', },
                                                    { pattern: new RegExp(/^[0-9][0-9]{5}$/), message: '请输入正确的邮编' }],
                                                    getValueFromEvent: (event) => {
                                                        return event.target.value.replace(/\D/g, '')
                                                    }
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} className="starDataDom">
                                            <FormItem label='生效日期' {...formItemLayout}>
                                                {getFieldDecorator('startDate', {
                                                    initialValue: params && params.startDate ? moment(params.startDate, "YYYY-MM-DD") : undefined,
                                                    rules: [{ required: false, message: '请选择开始日期' }],
                                                })(
                                                    <DatePicker style={{ width: '100%' }} placeholder={'开始日期'} disabledDate={(curDate) => {
                                                        return curDate && curDate > moment().endOf('day');
                                                    }} />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} >
                                            <FormItem label='失效日期' {...formItemLayout}>
                                                {getFieldDecorator('stopDate', {
                                                    initialValue: params && params.stopDate ? moment(params.stopDate, "YYYY-MM-DD") : undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <DatePicker style={{ width: '100%' }} placeholder={'请选择失效日期'} disabledDate={(curDate) => {
                                                        return curDate && curDate > moment().endOf('day');
                                                    }} />
                                                )}
                                            </FormItem>
                                        </Col >
                                    </Row>
                                    <Row>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='网站'>
                                                {getFieldDecorator('website', {
                                                    initialValue: params && params.website ? params && params.website : undefined,
                                                    rules: [{ required: true, message: '请输入网站', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6} className="patNameDom">
                                            <FormItem {...formItemLayout} label='授权码'>
                                                {getFieldDecorator('authorizeCode', {
                                                    initialValue: params && params.authorizeCode ? params && params.authorizeCode : undefined,
                                                    rules: [{ required: false, message: '', },
                                                    ],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='医院介绍'>
                                                {getFieldDecorator('introduce', {
                                                    initialValue: params && params.introduce ? params && params.introduce : undefined,
                                                    rules: [{ required: false, message: '', }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='医院LOGO'>
                                                {getFieldDecorator('logo', {
                                                    initialValue: params && params.logo ? params && params.logo : undefined,
                                                    rules: [{ required: false, message: '', },]
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={6}>
                                            <FormItem {...{
                                                labelCol: { span: 10 },
                                                wrapperCol: { span: 14 },
                                            }} label='每行显示床数'>
                                                {getFieldDecorator('oneRowNumber', {
                                                    initialValue: params && params.oneRowNumber ? params && params.oneRowNumber : undefined,
                                                    rules: [{ required: false, message: '', }]
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='床位图高'>
                                                {getFieldDecorator('height', {
                                                    initialValue: params && params.height ? params && params.height : undefined,
                                                    rules: [{ required: false, message: '', }],
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='床位图宽'>
                                                {getFieldDecorator('width', {
                                                    initialValue: params && params.hospSeqNo ? params && params.hospSeqNo : undefined,
                                                    rules: [{ required: false, message: '', },]
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={6}>
                                            <FormItem {...formItemLayout} label='床位间隔'>
                                                {getFieldDecorator('bedInterval', {
                                                    initialValue: params && params.bedInterval ? params && params.bedInterval : undefined,
                                                    rules: [{ required: false, message: '', }]
                                                })(
                                                    <Input />
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                </Form>
                            </Card>
                        </Col>
                    </Row>
                </Modal>
            );
        }
    });

class RoleMaintenance extends React.Component {
    constructor() {
        super();
        this.state = {
            // 角色名称
            name: undefined,
            // 关联岗位
            quarters: undefined,
            // 记录状态
            status: undefined,
            // 表格数据
            tableData: [],
            // 表格数据总条数
            total: 0,
            showLoading: true,
            page: 1,
            pageSize: 10,
            selectData: {}, // 下拉框数据
            headerHeight: 0,

            modalVisible: false,
            editData: {}
        };

        this.columns = [
            {
                key: 1,
                title: '代码',
                dataIndex: 'hospCode',
                align: "center",
                width: '10%'
            },
            {
                key: 2,
                title: '描述',
                dataIndex: 'hospDesc',
                align: "center",
                width: '15%'
            },
            {
                key: 3,
                title: '级别',
                dataIndex: 'hospGradeDesc',
                align: "center",
                width: '10%',
                render: (text, record) => {
                    const gradeChange = record.gradeChange;
                    const list = <List
                        size="small"
                        bordered
                        dataSource={gradeChange}
                        renderItem={item => <List.Item>{item.grade + ':' + item.startDate + ' - ' + (item.stopDate ? item.stopDate : '今天')}</List.Item>}
                        locale={{ emptyText: '无医院等级历史数据' }}
                    />;
                    return (
                        <Popover placement="topLeft" content={list} trigger="hover">
                            <span>{text}</span>
                        </Popover>
                    );
                }
            },
            {
                key: 5,
                title: '类型',
                dataIndex: 'hospTypeDesc',
                align: "center",
                width: '10%'
            },
            {
                key: 6,
                title: '性质',
                dataIndex: 'hospNatureDesc',
                align: "center",
                width: '10%'
            },
            {
                key: 7,
                title: '机构代码',
                dataIndex: 'organizationCode',
                align: "center",
                width: '10%'
            },
            {
                key: 8,
                title: '营业执照',
                dataIndex: 'businesslicense',
                align: "center",
                width: '10%'
            },
            {
                key: 9,
                title: '地址',
                dataIndex: 'provDesc',
                align: "center",
                width: '20%',
                render: (text, record) => {
                    let add = record.provDesc + '，' + record.cityDesc + '，' + record.areaDesc;
                    add = record.villageDesc ? add + '，' + record.villageDesc : add;
                    return <span>{add}</span>
                }
            },
            {
                title: '操作',
                key: 10,
                align: "center",
                width: 100,
                fixed: 'right',
                render: (text, record) => (
                    <span>
                        <Icon type="edit" style={{ color: '#108EE9' }}></Icon>
                        <span className='span' onClick={() => this.handleCompile(record)}>编辑</span>
                        <Divider type="vertical"></Divider>
                        <Popconfirm title="删除不可恢复，你确定要删除吗?" onConfirm={() => this.handleCompile(record, "2")} >
                            <span className='span' style={{ color: "red" }}>删除</span>
                        </Popconfirm>
                    </span>
                ),
            }
        ]
    }

    componentDidMount() {
        // 初始化列表数据
        this.handleQuery();
        this.getSelectData();
        // 组件加载完毕关闭loading
        this.setState({ showLoading: false });
    }

    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    // 角色管理下拉框数据
    getSelectData() {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "01040013",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({ selectData: res })
                } else {
                    this.setState({ selectData: {} })
                }
            }
        })
    }

    // 调用子组件的连接事件
    onRef = (ref) => {
        this.child = ref
    }

    // 提供修改page和pageSize的回调函数
    compilePage(page, pageSize) {
        // 修改page，或者pageSize
        this.setState({ page: page, pageSize: pageSize }, () => {
            // 重新调用查询方法
            let { status, name, quarters } = this.state;
            this.getTableData(name, status, quarters);
        })
    }

    // 请求列表数据
    getTableData() {
        let { page, pageSize } = this.state;
        let data = {};
        this.props.form.validateFields((error, values) => {
            if (error) {
                return;
            }
            data = {
                params: [{
                    hospCode: values.hospCode ? values.hospCode : '',
                    hospDesc: values.hospDesc ? values.hospDesc : '',
                    hospStatus: values.hospStatus ? values.hospStatus : '',
                }],
                pagination: [{
                    pageSize: pageSize,
                    currentPage: page,
                    sortColumn: "",
                    sortOrder: ""
                }]
            };
            $http.post('urlS', this, {
                code: "05100219",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0 && res.result) {
                        // console.log(res)
                        // for(var i = 0; i < res.result.Data.length; i++) {
                        // 	res.result.Data[i].key = i;
                        // 	if (res.result.Data[i].StopDate === "") {
                        // 		res.result.Data[i].states = "生效";
                        // 	} else {
                        // 		let start = new Date();
                        // 		let end = new Date(res.result.Data[i].StopDate);
                        // 		if (start > end) {
                        // 			res.result.Data[i].states = "失效";
                        // 		} else {
                        // 			res.result.Data[i].states = "生效";
                        // 		}
                        // 	}

                        // }
                        this.setState({ tableData: res.result.Data, total: res.result.TotalCount }, () => {
                            // 数据加载成功关闭loading
                            this.child.handleLoading()
                        })
                    } else {
                        this.setState({ tableData: [], total: 0 }, () => {
                            // 数据加载成功关闭loading
                            this.child.handleLoading();
                        })
                    }
                },
                error: function () {
                    this.setState({ tableData: [], total: 0 }, () => {
                        // 数据加载成功关闭loading
                        this.child.handleLoading();
                    })
                }
            });
        });

    }

    // 查询
    handleQuery = () => {
        this.setState({ page: 1, pageSize: 10 }, () => {
            this.getTableData();
        })
    }

    // 新增跳转到新增界面
    handleAdd = () => {
        this.setState({ editData: undefined });
        this.showModal(true);
    }

    // 编辑
    handleCompile = (record, num) => {
        if (num == "2") {
            let data = {
                params: [{
                    hospID: record.hospID,
                    updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                }],
            }
            $http.post("urlS", this, {
                code: "05100210",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success("删除成功")
                        this.handleQuery()
                    } else {
                        message.error('失败：' + res.errorMessage);
                    }
                },
                error: function (error) {
                    message.error('失败：' + error);
                }
            })
        }
        else {
            this.setState({ editData: record });
            this.showModal(true);
        }
    }

    //控制模态框显示
    showModal = (bool) => {
        this.setState({ modalVisible: bool });
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        // 组件所需参数
        const param = {
            // 表头配置
            columns: this.columns,
            // 表格数据
            data: this.state.tableData,
            // 数据总条数
            total: this.state.total,
            // 当前页数
            page: this.state.page,
            // 表格的宽度
            x: '115%',
            y: store.getState().tableHeight.y - this.state.headerHeight,
            height: store.getState().tableHeight.y + 50 - this.state.headerHeight + 'px',
        }
        const statusArr = [
            {
                id: '',
                descripts: '全部',
                descriptsSPCode: 'QB',
            }, {
                id: '1',
                descripts: '可用',
                descriptsSPCode: 'KY',
            }, {
                id: '0',
                descripts: '不可用',
                descriptsSPCode: 'BKY',
            },];
        let statusoP = []
        statusArr && statusArr.map(item => {
            statusoP.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
        });
        return (
            <Spin tip="加载中..." spinning={this.state.showLoading}>
                <div>
                    <Form>
                        <Row style={{ margin: '23px 0 0 0' }}>
                            <Col span={5} >
                                <FormItem {...formItemLayout} label='医院代码'>
                                    {getFieldDecorator('hospCode', {
                                        //initialValue: params && params.healBureauID ? String(params.healBureauID) : undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input title="输入内容后可回车检索" placeholder="请输入( Enter )" onPressEnter={this.handleQuery} />
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={4} >
                                <FormItem {...formItemLayout} label='医院描述'>
                                    {getFieldDecorator('hospDesc', {
                                        //initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input title="输入内容后可回车检索" placeholder="请输入( Enter )" onPressEnter={this.handleQuery} />
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={4} >
                                <FormItem {...formItemLayout} label='医院状态'>
                                    {getFieldDecorator('hospStatus', {
                                        //initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Select
                                            style={{ width: '70%' }}
                                            onSelect={this.handleStatus}
                                        >
                                            {statusoP}
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={2}>
                                <Button onClick={this.handleQuery} style={{ margin: '4px 15px 20px 0', background: 'rgba(255,255,255,1)' }}>查询</Button>
                            </Col>
                            <Col span={7}>
                            </Col>
                            <Col span={2}>
                                <Button icon="plus" onClick={this.handleAdd} style={{ background: 'rgba(247,128,93,1)', color: '#fff', margin: '4px 0 0 0' }}>新增医院</Button>
                            </Col>
                        </Row>
                    </Form>
                </div>
                <div style={{ width: '100%', height: '10px', background: '#f0f2f5' }}></div>
                <div style={{ padding: '24px' }} className="table-body-height">
                    <PubilcTablePagination param={param} handelThis={this} onRef={this.onRef} />
                </div>
                <HospitalMaintenance data={this.state.editData} modalVisible={this.state.modalVisible} propMethod={{ showModal: this.showModal, findData: this.handleQuery }} />
            </Spin>
        )
    }
}
export default Form.create()(RoleMaintenance);
