// 医嘱审核
import React from 'react';
import {Card, Row, Col, DatePicker, Button, Select, Tabs, Table, Input, Pagination, message, Icon} from 'antd';
import store from 'store';
import { $http } from 'containers/config/https';
import Moment from 'moment';
import './style/index.less';
import PubilcTablePagination from 'pages/common/PubilcTablePagination.jsx';
import AuditRefusedTo from './component/AuditRefusedTo'
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';

import CommonPagination from 'components/pagination/index';

let {Option} = Select;
const { TabPane } = Tabs;
let timeout;
let timeout2;

export default class HPMedicalAdviceAudit extends React.Component {
    constructor(props) {
        super(props);
        var user = JSON.parse(sessionStorage.getItem('userData'))
        this.state = {
            pharmacy: user&&user.locID ? user.locID : undefined, // 药房
            startDate: undefined, // 开始日期
            endDate: undefined, // 截至日期
            status: undefined, // 状态
            activeTabPaneKey: '1', // 当前激活的面板
            basicHeight: 0,
            selectData: {}, // 下拉框数据集
            wardSelectData: [], // 病区下拉框数据
            inpatientAreaData: [], // 病区病人拉框数据
            wardID: undefined, // 病区
            inpatientArea: undefined, // 病区病人
            wardColumns: [], // 病区列
            wardTableWidth: '', // 病区table宽度
            wardTableData: [], // 病区列表数据
            wardRowId: '', // 病区选中行Id
            wardAndPatientRowId: '', // 病区病人选中行操作
            wardAndPatientData: [], // 病区病人table数据
            wardAndPatientTotal: 0,
            wardAndPatientPage: 1, // 
            wardAndPatientPageSize: 10, 
            wardAndPatientColumns: [], // 病区病人表头
            wardAndPatientTableWidth: '', // 病区病人table宽度
            registrationColumns: [], // 登记号表头数据
            registrationTableData: [], // 登记号列表数据
            registrationTableWidth: '', // 登记号table宽度
            patID: '', // 病人Id
            detailRowId: '', // 医嘱明细选中行Id
            detailColumns: [], // 医嘱明细表头数据
            detailTableData: [], // 医嘱明细列表数据
            detailTableWidth: '', // 医嘱明细table宽度
            selectedRowKeys: [], // 选中的行数
            selectedRows: [], // 选中的行数数据
            detailPage: 1, 
            detailPageSize: 10, 
            detailTotal: 0,
            rowData: {}, // 病区、病区病人、登记号选中行数据
            loading: false,
            detailLoading: false,
        }
    }

    componentDidMount() {
        this.getSelectData();
        this.getParameterSetting();
        this.getWardColumns();
        this.getDetailColumns();
        this.setState({basicHeight: document.getElementById("medical-advice-audit").clientHeight})
    }

    refuseOnRef = ref => { // 审核拒绝组件ref
        this.refuseChild = ref;
    }

    handleWardAndPatientOnRef = ref => {
        this.WardAndPatientChild = ref;
    }

    getSelectData = () => { // 获取下拉框数据
        let data = {
			params: []
		}
		$http.post('urlS', this, {
			code: "02040001",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
                    let obj = res.result&&res.result.length > 0 ? res.result[0] : {}
					this.setState({selectData: obj, status: obj.status&&obj.status.length > 0 ? obj.status[0].id : undefined}, () => {
                        this.handleQuery();
                    })
				}
			}
		})
    }

    // 3.3.1.1.2.获取医嘱审核界面参数
    getParameterSetting = () => {
        let data = {
			params: []
		}
		$http.post('urlS', this, {
			code: "02040002",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
                    this.setState({
                        startDate: res.result[0]&&res.result[0].startDate ? Moment(res.result[0].startDate) : Moment(),
                        endDate: res.result[0]&&res.result[0].endDate ? Moment(res.result[0].endDate) : undefined
                    })
				}
			}
		})
    }

    // 药房查询条件
    handlePharmacyOnChange = e => {
        this.setState({pharmacy: e})
    }

    // 切换医嘱查询页签
    toggleTabPane = key => {
        this.setState({activeTabPaneKey: key, rowData: {}, selectedRowKeys: [], selectedRows: [], detailTableData: [], detailTotal: 0}, () => {
            if (this.state.activeTabPaneKey === '1') {
                this.setState({
                    wardAndPatientRowId: '',
                    registrationRowId: '',
                }, () => {
                    this.getWardTableData();
                })
            } else if (this.state.activeTabPaneKey === '2') { // 当切换为病区病人页签时加载相关数据
                this.setState({
                    wardRowId: '',
                    registrationRowId: '',
                }, () => {
                    this.getWardAndPatientTableData();
                })
                if (!(this.state.wardAndPatientColumns&&this.state.wardAndPatientColumns.length > 0)) {
                    this.getWardAndPatientColumns();
                }
            } else if (this.state.activeTabPaneKey === '3') {
                if (!(this.state.registrationColumns&&this.state.registrationColumns.length > 0)) {
                    this.getRegistrationColumns();
                }
                this.setState({wardRowId: '', wardAndPatientRowId: ''})
            }
        })
    }

    // 审核拒绝
    handleRefuse = () => {
        let {selectedRows} = this.state;
        let status = selectedRows.every( item => item.patID === selectedRows[0].patID);
        if (status) {
            this.refuseChild.handleShowModal(selectedRows);
        } else {
            message.error("请选择同一病人的医嘱进行操作。")
        }
    }

    // 请求病区下拉框数据(病区病人)
    handleInpatientAreaSelectData = (value) => {
        if (timeout) {
            clearTimeout(timeout);
            timeout = null;
        }
        timeout = setTimeout(() => {
            if (value) {
                let data = {
                    params: [{
                        alias: value
                    }]
                }
                $http.post('urlS', this, {
                    code: "02040003",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({inpatientAreaData: res.result})
                        }
                    }
                })
            }
        }, 300)
    }

    // 请求病区下拉框数据(病区)
    handleWardSelectData = (value) => {
        if (timeout2) {
            clearTimeout(timeout2);
            timeout2 = null;
        }
        timeout2 = setTimeout(() => {
            if (value) {
                let data = {
                    params: [{
                        alias: value
                    }]
                }
                $http.post('urlS', this, {
                    code: "02040003",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({wardSelectData: res.result})
                        }
                    }
                })
            }
        }, 300)
    }

    // 病区value
    handleWardOnChange = e => {
        this.setState({wardID: e}, () => {
            this.getWardTableData()
        })
    }

    // 状态
    handleStatusOnChange = e => {
        this.setState({status: e}) 
    }

    // 开始日期
    handleStartDate = e => {
        this.setState({startDate: e})
    }

    // 结束日期
    handleEndDate = e => {
        this.setState({endDate: e})
    }

    // 获取病区columns
    getWardColumns = () => {
        let data = {
			params: [{
                compontName: "OrderAuditWardList",
                type: 'C',
            }]
		}
		$http.post('urlS', this, {
			code: '01040073',
			data: data,
			success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result.C&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
                        return  {
                            ...item,
                            key: index + 1
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({wardColumns: filterArr, wardTableWidth: res.totalWidth})
                }
			}
		})
    }

    // 获取病区病人columns
    getWardAndPatientColumns = () => {
        let data = {
			params: [{
                compontName: "OrderAuditWardAdmList",
                type: 'C',
            }]
		}
		$http.post('urlS', this, {
			code: '01040073',
			data: data,
			success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result.C&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
                        return  {
                            ...item,
                            key: index + 1
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({wardAndPatientColumns: filterArr, wardAndPatientTableWidth: res.totalWidth})
                }
			}
		})
    }

    // 获取登记号columns
    getRegistrationColumns = () => {
        let data = {
			params: [{
                compontName: "OrderAuditAdmList",
                type: 'C',
            }]
		}
		$http.post('urlS', this, {
			code: '01040073',
			data: data,
			success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result.C&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
                        return  {
                            ...item,
                            key: index + 1
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({registrationColumns: filterArr, registrationTableWidth: res.totalWidth})
                }
			}
		})
    }

    // 获取明细列表表头
    getDetailColumns = () => {
        let data = {
			params: [{
                compontName: "OrderAuditOrdDetail",
                type: 'C',
            }]
		}
		$http.post('urlS', this, {
			code: '01040073',
			data: data,
			success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result.C&&res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
                        return  {
                            ...item,
                            key: index + 1,
                            title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{item.title}</div>,
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({detailColumns: filterArr, detailTableWidth: res.totalWidth})
                }
			}
		})
    }

    // 获取病区列表数据
    getWardTableData = () => {
        let {pharmacy, startDate, endDate, status, wardID} = this.state;
        let data = {
			params: [
                {
                    recLocID: pharmacy, // 药房科室ID
                    startDate: startDate ? Moment(startDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 发药窗口ID
                    endDate: endDate ? Moment(endDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 开始日期
                    statusID: status, // 类型ID
                    wardID, // 病区ID
                }
            ]
		}
		$http.post('urlS', this, {
			code: "02040004",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
                    for (var i = 0; i < res.result.length; i++) {
                        res.result[i].key = i + 1
                    }
                    this.setState({wardTableData: res.result, detailTotal: 0, })
				}
			}
		})
    }

    // 病区操作行
    handleWardOnRow = (record) => {
        return {
			// 单击行选中
			onClick: () => {
				if (this.state.wardRowId === '') {
					// 保存行数据以及ID
					this.setState({wardRowId: record.admWardID, rowData: record, wardAndPatientRowId: '', registrationRowId: '', selectedRowKeys: [], selectedRows: []}, () => {
                        this.handleQueryDetailList()
                    });
				} else {
					if (this.state.wardRowId !== record.admWardID) {
						this.setState({wardRowId: record.admWardID, rowData: record, wardAndPatientRowId: '', registrationRowId: '', selectedRowKeys: [], selectedRows: []}, () => {
                            this.handleQueryDetailList()
                        });
					}
				}
			}
		}
    }

    // 病区选中行背景
    handleWardRowClassName = (record) => {
        return record.admWardID === this.state.wardRowId ? 'clickRowStyle' : '';
    }
    
    // 提供修改page和pageSize的回调函数
	compilePage(page, pageSize) {
		// 修改page，或者pageSize
		this.setState({ wardAndPatientPage: page, wardAndPatientPageSize: pageSize }, () => {
			// 重新调用查询方法
			this.getWardAndPatientTableData()
		})
	}

    // 重置页数与每页的条数查询病区病人列表数据
    handleQueryWardAndPatient = () => {
        this.setState({wardAndPatientPage: 1, wardAndPatientRowId: "", rowData: {}, selectedRowKeys: [], selectedRows: [], detailTableData: []}, () => {
            this.getWardAndPatientTableData()
        })
    }

    // 获取病区病人列表数据
    getWardAndPatientTableData = () => {
        this.setState({loading: true});
        let {pharmacy, startDate, endDate, status, inpatientArea, wardAndPatientPage, wardAndPatientPageSize} = this.state;
        let data = {
			params: [
                {
                    recLocID: pharmacy, // 药房科室ID
                    startDate: startDate ? Moment(startDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 发药窗口ID
                    endDate: endDate ? Moment(endDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 开始日期
                    statusID: status, // 类型ID
                    wardID: inpatientArea, // 病区ID
                }
            ],
            pagination:[{
                pageSize: wardAndPatientPageSize,
                currentPage: wardAndPatientPage,
                sort: "",
                dir: "Asc"
            }]
		}
		$http.post('urlS', this, {
			code: "02040005",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    for(var i = 0; i < res.result[0].rows.length; i++) {
                        res.result[0].rows[i].key = res.result[0].rows[i].admID
                    }
                    this.setState({
                        wardAndPatientData: res.result[0].rows, 
                        wardAndPatientTotal: res.result[0].total, 
                        loading: false
                    }, () => {
                        // 数据加载成功关闭loading
                        this.WardAndPatientChild.handleLoading();
                    })
                } else {
                    this.setState({wardAndPatientData: [], wardAndPatientTotal: 0, loading: false}, () => {
                        // 数据加载成功关闭loading
                        this.WardAndPatientChild.handleLoading();
                    })
                }
            },
            error: function () {
                this.setState({wardAndPatientData: [], wardAndPatientTotal: 0, loading: false}, () => {
                    // 数据加载成功关闭loading
                    this.WardAndPatientChild.handleLoading();
                })
            }
		})
    }

    // 病区、病人行操作
    handleWardAndPatientOnRow = (record) => {
        return {
			// 单击行选中
			onClick: () => {
				if (this.state.wardAndPatientRowId === '') {
					// 保存行数据以及ID
					this.setState({wardAndPatientRowId: record.key, rowData: record, wardRowId: '', registrationRowId: '', selectedRowKeys: [], selectedRows: []}, () => {
                        this.handleQueryDetailList()
                    });
				} else {
					if (this.state.wardAndPatientRowId !== record.key) {
						this.setState({wardAndPatientRowId: record.key, rowData: record, wardRowId: '', registrationRowId: '', selectedRowKeys: [], selectedRows: []}, () => {
                            this.handleQueryDetailList()
                        });
					}
				}
			}
		}
    }

    handleWardAndPatientRowClassName = (record) => {
        return record.key === this.state.wardAndPatientRowId ? 'clickRowStyle' : '';
    }

    // 获取登记号列表数据
    getRegistrationTableData = () => {
        let {pharmacy, status, patID} = this.state;
        let data = {
			params: [
                {
                    recLocID: pharmacy, // 药房科室ID
                    statusID: status, // 类型ID
                    patID, // 病人ID
                }
            ]
		}
		$http.post('urlS', this, {
			code: "02040006",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
                    for (var i = 0; i < res.result.length; i++) {
                        res.result[0].key = i + 1
                    }
                    this.setState({registrationTableData: res.result, registrationRowId: '', rowData: {}, selectedRowKeys: [], selectedRows: [], detailTableData: [], detailTotal: 0})
				} else {
                    this.setState({registrationTableData: []})
                }
			}
		})
    }

    // 登记号选中行操作
    handleRegistrationOnRow = (record) => {
        return {
			// 单击行选中
			onClick: () => {
				if (this.state.registrationRowId === '') {
					// 保存行数据以及ID
					this.setState({registrationRowId: record.key, rowData: record, wardAndPatientRowId: '', wardRowId: '', selectedRowKeys: [], selectedRows: []}, () => {
                        this.handleQueryDetailList()
                    });
				} else {
					if (this.state.registrationRowId !== record.key) {
						this.setState({registrationRowId: record.key, rowData: record, wardAndPatientRowId: '', wardRowId: '', selectedRowKeys: [], selectedRows: []}, () => {
                            this.handleQueryDetailList()
                        });
					}
				}
			}
		}
    }

    handleRegistrationRowClassName = (record) => {
        return record.key === this.state.registrationRowId ? 'clickRowStyle' : '';
    }

    // 病人登记号
    handlePatNoOnChange = e => {
        this.setState({patNo: e.target.value})
    }

    // 病人登记号失焦操作
    handleRegistrationInput = (e, flag) => {
        if (!e.target.value) {
            this.setState({patID: ''})
            return;
        }
        let data = {
			params: [
                {
                    patNo: e.target.value, // 病人ID
                }
            ]
		}
		$http.post('urlS', this, {
			code: "02030028",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
                    this.setState({patID: res.result&&res.result[0] ? res.result[0].patID : ''}, () => {
                        if (flag === 'enter') {
                            this.getRegistrationTableData();
                        }
                    })
				} else {
                    this.setState({patID: 'aaaaaaaaaaaa'})
                    // 清空医嘱明细数据以及
                }
			}
		})
    }

    // 医嘱明细行操作
    handleDetailOnRow = (record) => {
        return {
            onClick: () => {
                let { selectedRowKeys, selectedRows } = this.state;
                let findFlag = false;
                let start = 0;
                if (selectedRowKeys) {
                    selectedRowKeys.find(function (value, key) {
                        if (value === record.key) {
                            //遍历找到选中的数据，并记录下选中数据在数组中的key
                            findFlag = true;
                            start = key;
                        }
                    })
                }
                if (findFlag) {
                    //再次点击移除选中
                    selectedRowKeys.splice(start, 1);
                    selectedRows.splice(start, 1);
                } else {
                    //将点击的行添加到选中
                    selectedRowKeys.push(record.key);
                    selectedRows.push(record);
                }
                if (this.state.detailRowId === "") {
                    this.setState({
                        detailRowId: record.key,
                        selectedRowKeys,
                        selectedRows
                    });
                } else {
                    if (this.state.detailRowId !== record.key) {
                        this.setState({
                            detailRowId: record.key,
                            selectedRowKeys,
                            selectedRows
                        });
                    } else {
                        this.setState({
                            detailRowId: "",
                            selectedRowKeys,
                            selectedRows
                        });
                    }
                }
            }
		}
    }

    handleDetailRowClassName = (record) => {
        return (("^" + this.state.selectedRowKeys.join("^") + "^").indexOf("^" + record.ordMainOrdID + "^") > -1) ? 'clickRowStyle' : '';
    }

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

    // 修改医嘱明细页数
    handleCompileDetailPage = (page, pageSize) => {
        this.setState({detailPage: page, detailPageSize: pageSize}, () => {
            this.getDetailListData();
        })
    }

    // 修改医嘱明细条数
    handleCompileDetailPageSize = (page, pageSize) => {
        this.setState({detailPage: 1, detailPageSize: pageSize}, () => {
            this.getDetailListData();
        })
    }

    // 获取明细列表数据
    getDetailListData = () => {
        this.setState({detailLoading: true, detailTableData: [], selectedRowKeys: [], selectedRows: []});
        let {pharmacy, startDate, endDate, status, detailPage, detailPageSize, rowData} = this.state;
        let data = {
			params: [
                {
                    recLocID: pharmacy, // 药房科室ID
                    startDate: startDate ? Moment(startDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 发药窗口ID
                    endDate: endDate ? Moment(endDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 开始日期
                    statusID: status, // 类型ID
                    wardID: rowData.admWardID ? rowData.admWardID : '', // 选中行病区ID
                    admID: rowData.admID ? rowData.admID : '', // 就诊ID
                    patID: rowData.patID ? rowData.patID : '', // 病人ID
                }
            ],
            pagination:[{
                pageSize: detailPageSize,
                currentPage: detailPage,
                sort: "",
                dir: "Asc"
            }]
		}
		$http.post('urlS', this, {
			code: "02040007",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result&&res.result[0].rows ? JSON.parse(JSON.stringify(res.result[0].rows)) : [];
                    for(var i = 0; i < arr.length; i++) {
                        arr[i].key = arr[i].ordMainOrdID;
                    }
                    this.setState({
                        detailTableData: arr, 
                        detailTotal: res.result[0].total, 
                        detailLoading: false,
                    })
                } else {
                    this.setState({detailTableData: [], detailLoading: false, detailTotal: 0})
                }
            }
		})
    }

    // 查询明细列表
    handleQueryDetailList = () => {
        this.setState({detailPage: 1, detailPageSize: 10}, () => {
            this.getDetailListData();
        })
    }

    // 病区病人选择病区
    handleInpatientAreaOnChange = e => {
        this.setState({inpatientArea: e}, () => {
            this.handleQueryWardAndPatient();
        })
    }

    // 审核
    handleAudit = () => {
        // console.log(this.state.selectedRows)
        let ordIDInfo = this.state.selectedRows&&this.state.selectedRows.map(item => {
            return {
                ordID: item.ordID
            }
        });
        let data = {
			params: [
                {
                    auditType: 0, // 审核类型
                    ordIDInfo, // 医嘱信息
                }
            ]
		}
		$http.post('urlS', this, {
			code: "02040008",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
                    message.success("审核成功");
                    this.getDetailListData();
				}
			}
		})
    }

    // 查询
    handleQuery = () => {
        let {activeTabPaneKey, patNo} = this.state;
        if (activeTabPaneKey === '1') {
            this.setState({wardRowId: "", rowData: {}, selectedRowKeys: [], selectedRows: [], detailTableData: []}, () => {
                this.getWardTableData();
            })
        } else if (activeTabPaneKey === '2') {
            this.handleQueryWardAndPatient();
        } else if (activeTabPaneKey === '3') {
            if (!patNo) {
                message.info("请先根据登记号查询病人ID");
                return;
            }
            this.setState({registrationRowId: "", rowData: {}, selectedRowKeys: [], selectedRows: [], detailTableData: []}, () => {
                this.getRegistrationTableData();
            })
        }
    };

    onColumnRef = (ref) => {
        this.columnRef = ref;
    }

    render() {
        let {pharmacy, startDate, endDate, activeTabPaneKey, basicHeight, selectData, inpatientAreaData, wardID, wardColumns, wardTableData, status,
            wardAndPatientData, wardAndPatientTotal, wardAndPatientPage, wardAndPatientColumns, wardAndPatientTableWidth, registrationColumns, registrationTableData,
            patNo, registrationTableWidth, detailColumns, detailTableData, detailTableWidth, detailPage, detailTotal, inpatientArea, wardSelectData,
            selectedRowKeys, selectedRows, loading, detailLoading
        } = this.state;

        const rowSelection = {
            selectedRowKeys: selectedRowKeys,
            selectedRows: selectedRows,
            onChange: (selectedRowKeys, selectedRows) => {
                this.setState({selectedRowKeys: selectedRowKeys, selectedRows: selectedRows}, () => {
                    // 清除拒绝数据
                    this.refuseChild.emptyData();
                })
            }
        };

        // 组件所需参数
		const param = {
			// 表头配置
			columns: wardAndPatientColumns,
			// 表格数据
			data: wardAndPatientData,
			// 数据总条数
			total: wardAndPatientTotal,
			// 当前页数
			page: wardAndPatientPage,
			// 表格的宽度
			x: wardAndPatientTableWidth,
			y:  store.getState().tableHeight.y + 47 - basicHeight,
			height: store.getState().tableHeight.y + 91 - basicHeight + 'px',
			isOnRow: true,
            rowClassName: true,
            loading
        }

        // 药房
		let pharmacyOption = selectData.loc && selectData.loc.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })
        // 状态
        let statusOption = selectData.status && selectData.status.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })
        // 病区
        let wardAreaOption = wardSelectData&&wardSelectData.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })
        // 病区病人
        let inpatientAreaOption = inpatientAreaData&&inpatientAreaData.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        let flag = selectedRows&&selectedRows.length > 0 ? selectedRows[0].statusID : "";
        return (
            <div className="hospital-pharmacies">
                <Row id="medical-advice-audit" style={{padding: '0 24px'}}> 
                    <Col span={20}>
                        <Row style={{marginBottom: '8px'}}>
                            药房：<Select value={pharmacy} onChange={this.handlePharmacyOnChange} showSearch optionFilterProp="seatchprop" placeholder="请选择" style={{width: '150px', margin: '8px 12px 0 0'}}>
                                {pharmacyOption}
                            </Select>
                            <DatePicker
                                value={startDate}
                                onChange={this.handleStartDate}
                                style={{width: '150px', marginTop: '8px'}}
                                placeholder="开始日期"
                                allowClear={false}
                            />
                            <span style={{display: 'inline-block', margin: '0 5px'}}>到</span>
                            <DatePicker 
                                value={endDate}
                                onChange={this.handleEndDate}
                                style={{width: '150px', marginRight: '12px'}} 
                                placeholder="结束日期"
                                allowClear={false}
                            />
                            状态：<Select value={status} onChange={this.handleStatusOnChange} showSearch optionFilterProp="seatchprop" placeholder="请选择" style={{width: '150px', margin: '8px 12px 0 0'}}>
                                {statusOption}
                            </Select>
                            <Button style={{marginTop: '8px'}} onClick={this.handleQuery}>查询</Button>
                        </Row>
                    </Col>
                    <Col span={4} style={{textAlign: 'right'}}>
                        <Button
                            type="danger"
                            style={{margin: '8px 12px 0 0', width: '100px', display: (flag === 'V' || flag === '' || flag === 'Yes') ? 'inline-block' : 'none'}}
                            onClick={this.handleRefuse}
                            disabled={!flag}
                            ghost
                        >
                            审核拒绝
                        </Button>
                        <Button
                            type="primary"
                            style={{marginTop: '8px', width: '100px', display: (flag === 'V' || flag === '') ? 'inline-block' : 'none'}}
                            onClick={this.handleAudit}
                            disabled={!flag}
                        >
                            通过审核
                        </Button>
                        <Button
                            style={{marginTop: '8px', width: '100px', display: (flag === 'No' || flag === 'Rec') ? 'inline-block' : 'none'}}
                            onClick={this.handleRefuse}
                        >查看</Button>
                    </Col>
                </Row>
                <div style={{height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%'}}></div>
                <Row>
                    <Col span={8} className="card-container">
                        <Tabs activeKey={activeTabPaneKey} onChange={this.toggleTabPane} type="card">
                            <TabPane tab="病区" key="1">
                                <div style={{padding: '12px', height: store.getState().tableHeight.y + 198 - basicHeight + 'px', overflow: 'auto'}}>
                                    <div style={{marginBottom: '12px'}}>
                                        <Select
                                            showSearch
                                            defaultActiveFirstOption={false}
                                            showArrow={false}
                                            filterOption={false}
                                            onSearch={this.handleWardSelectData}
                                            notFoundContent={null}
                                            placeholder="搜索病区"
                                            allowClear
                                            style={{width: '100%'}}
                                            value={wardID}
                                            onChange={this.handleWardOnChange}
                                        >
                                            {wardAreaOption}
                                        </Select>
                                    </div>
                                    <Table
                                        columns={wardColumns}
                                        dataSource={wardTableData}
                                        bordered
                                        pagination={false}
                                        // scroll={{y: store.getState().tableHeight.y + 169 - 75 - basicHeight}}
                                        onRow={this.handleWardOnRow}
                                        rowClassName={this.handleWardRowClassName}
                                    />
                                </div>
                            </TabPane>
                            <TabPane tab="病区/病人" key="2">
                                <div style={{padding: '12px', height: store.getState().tableHeight.y + 198 - basicHeight + 'px', overflow: 'auto'}} className="inpatient-area">
                                    <div style={{marginBottom: '12px'}}>
                                        <Select
                                            showSearch
                                            defaultActiveFirstOption={false}
                                            showArrow={false}
                                            filterOption={false}
                                            onSearch={this.handleInpatientAreaSelectData}
                                            notFoundContent={null}
                                            placeholder="搜索病区"
                                            allowClear
                                            style={{width: '100%'}}
                                            value={inpatientArea}
                                            onChange={this.handleInpatientAreaOnChange}
                                        >
                                            {inpatientAreaOption}
                                        </Select>
                                    </div>
                                    <div>
                                        <PubilcTablePagination
                                            param={param}
                                            handelThis={this}
                                            onRef={this.handleWardAndPatientOnRef}
                                            onClickRowPublic={this.handleWardAndPatientOnRow}
                                            setRowClassNamePublic={this.handleWardAndPatientRowClassName}
                                        />
                                    </div>
                                </div>
                            </TabPane>
                            <TabPane tab="登记号" key="3">
                                <div style={{padding: '12px', height: store.getState().tableHeight.y + 198 - basicHeight + 'px', overflow: 'auto'}}>
                                    <div style={{marginBottom: '12px'}}>
                                        <Input
                                            style={{width: '100%'}}
                                            value={patNo}
                                            onChange={this.handlePatNoOnChange}
                                            onBlur={(e) => this.handleRegistrationInput(e, 'blur')}
                                            onPressEnter={(e) => this.handleRegistrationInput(e, 'enter')}
                                            placeholder="根据登记号查询病人Id"
                                        />
                                    </div>
                                    <Table
                                        columns={registrationColumns}
                                        dataSource={registrationTableData}
                                        bordered
                                        pagination={false}
                                        // scroll={{x: registrationTableWidth, y: store.getState().tableHeight.y + 160 - 64 - basicHeight}}
                                        onRow={this.handleRegistrationOnRow}
                                        rowClassName={this.handleRegistrationRowClassName}
                                    />
                                </div>
                            </TabPane>
                        </Tabs>
                    </Col>
                    <Col span={16}>
                        <div style={{paddingLeft: '6px', position: 'relative'}}>
                            <Card
                                size="small"
                                title={<div className="card-title-left-icon"><div></div>医嘱明细</div>}
                                extra={<span style={{color: '#666'}} className='span' onClick={() => this.columnRef.onOpenModel()}><Icon type="setting" title="列权限设置" /></span>}
                            >
                                <div style={{height: store.getState().tableHeight.y + 174 - basicHeight + 'px', overflow: 'auto'}}>
                                    <Table
                                        style={{height: store.getState().tableHeight.y + 134 - basicHeight + 'px'}}
                                        className="inpatient-area"
                                        rowSelection={rowSelection}
                                        columns={detailColumns}
                                        dataSource={detailTableData}
                                        bordered
                                        pagination={false}
                                        scroll={{x: detailTableWidth, y: store.getState().tableHeight.y + 85 - basicHeight}}
                                        // onRow={this.handleDetailOnRow}
                                        // rowClassName={this.handleDetailRowClassName}
                                    />
                                    {/* <Pagination
                                        showTotal={() => this.showTotal(detailTotal)}
                                        size="small"
                                        showQuickJumper
                                        showSizeChanger
                                        defaultCurrent={1}
                                        defaultPageSize={10}
                                        current={detailPage}
                                        total={detailTotal}
                                        onChange={this.handleCompileDetailPage}
                                        onShowSizeChange={this.handleCompileDetailPageSize}
                                        style={{ textAlign: "right", marginTop: '13px' }}
                                    /> */}
                                    <CommonPagination size='small' current={detailPage} total={detailTotal} search= 'search'
                                        onShowSizeChange={this.handleCompileDetailPageSize} complete={true} dataSource={detailTableData}
                                        loading={detailLoading} onChange={this.handleCompileDetailPage} company="组" />
                                </div>
                            </Card>
                            <div style={{width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, left: 0, height: '100%'}}></div>
                        </div>
                    </Col>
                </Row>
                <AuditRefusedTo onRef={this.refuseOnRef} handleQuery={this.getDetailListData} />
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName='OrderAuditOrdDetail'
                    configType="C"
                    onRef={this.onColumnRef}
                    reloadData={this.getDetailColumns}
                />
            </div>
        )
    }
}