// 门诊配药(备用)
import React from 'react';
import { Card, Row, Col, Select, Button, Input, DatePicker, Switch, Modal, Table, Checkbox, Icon, Form, message } from 'antd';
import store from 'store';
import { $http } from 'containers/config/https';
import CommonPagination from 'components/pagination/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import Moment from 'moment';
import './style/outpha.less';
import {$PrintLabel, $PrintPresc, $PrintPYD} from "./common/Print";

const { Option } = Select;
let autoamticTimer = null;
let timer = null;

class Dispensing extends React.Component {

    constructor(props) {
        super(props);
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            userInfo: JSON.parse(window.sessionStorage.userData),
            windowDomData: [],
            windowVisible: true, //显示窗口
            cardSlectData:[], //下拉
            detailData: [],
            radioWindowData: {},
            pageSize: 10,
            page: 1,
            total:0,
            loading:false,
            patID: '', // 病人Id
            pat: '', // 回车保存的病人id
            patNo: undefined, // 病人
            cardType: undefined, // 卡类型
            cardNo: undefined, // 卡号
            defaultValue: '', // 默认卡类型
            dispRecFlag: false,
            prescNo: '',//行处方号
            detailsListData: [], //药品详情列表
            outpatientID: '', //配药id
            whether: false,
            buttonStatus: 'end',//自动配药识别
            initData: {}, //自动配药秒数
            selectpharmacy: false,
            determineSelect: false,
            modalColumns: [], //表头数据
            listLength: '', //长度
            topLength: '',
            Columns: [],
            parameterCode: '',
            selectAllData: [],//选中的配药列表数据
            selectedRowKeys:[],
            DispensingFlag:null,//根据查询状态显示配药按钮
            dispID: '',//配药列表id
        };
        this.columns = [
            { title: '配药状态', dataIndex: 'prepFlag', key: '1', width: '100px', align: "center"},
            { title: '收费日期', dataIndex: 'payDate', key: '2', width: '100px', align: "center"},
            { title: '登记号', dataIndex: 'patNo', key: '3', width: '100px', align: "center"},
            { title: '处方', dataIndex: 'prescNo', key: '4', width: '100px', align: "center"},
            { title: '姓名', dataIndex: 'patName', key: '5', width: '100px', align: "center"},
            { title: '性别', dataIndex: 'patSex', key: '6', width: '100px', align: "center"},
            { title: '年龄', dataIndex: 'age', key: '7', width: '100px', align: "center"},
            { title: '收据号', dataIndex: 'dateTime', key: '8', width: '100px', align: "center"},
            { title: '处方金额', dataIndex: 'preAmt', key: '9', width: '100px', align: "center"},
            { title: '费别', dataIndex: 'admReason', key: '10', width: '100px', align: "center"},
            { title: '发药窗口', dataIndex: 'dispWin', key: '11', width: '100px', align: "center"},
            { title: '科室', dataIndex: 'loc', key: '12', width: '100px', align: "center"},
            { title: '取号', dataIndex: 'dateTime', key: '13', width: '100px', align: "center"},
            { title: '发药机', dataIndex: 'dateTime', key: '14', width: '100px', align: "center"},
            { title: '剂数', dataIndex: 'dateTime', key: '15', width: '100px', align: "center"},
            { title: '煎药类型', dataIndex: 'dateTime', key: '16', width: '100px', align: "center"},
            { title: '电话', dataIndex: 'mobile', key: '17', width: '100px', align: "center"},
            { title: '诊断', dataIndex: 'admDiag', key: '18', width: '100px', align: "center"},
        ];
        this.detailColumns = [
            { title: '药品名称', dataIndex: 'ordMedDesc', key: '1', width: '100px', align: "center"},
            { title: '数量', dataIndex: 'qty', key: '2', width: '100px', align: "center"},
            { title: '单位', dataIndex: 'baseUnitDesc', key: '3', width: '100px', align: "center"},
            { title: '用法', dataIndex: 'ordUsageDesc', key: '4', width: '100px', align: "center"},
            { title: '剂量', dataIndex: 'ordDoseUnitDesc', key: '5', width: '100px', align: "center"},
            { title: '频次', dataIndex: 'ordFreqDesc', key: '6', width: '100px', align: "center"},
            { title: '疗程', dataIndex: 'ordDurationDesc', key: '7', width: '100px', align: "center"},
            { title: '单价', dataIndex: 'sp', key: '8', width: '100px', align: "center"},
            { title: '金额', dataIndex: 'spAmt', key: '9', width: '100px', align: "center"},
            { title: '状态', dataIndex: 'ordStatus', key: '10', width: '100px', align: "center"},
            { title: '医师', dataIndex: 'ordDoctor', key: '11', width: '100px', align: "center"},
            { title: '产地', dataIndex: 'manfDesc', key: '12', width: '100px', align: "center"},
            { title: '货位', dataIndex: 'stockBin', key: '15', width: '100px', align: "center"},
        ];
    }

    componentDidMount() {
        let topList = document.querySelectorAll('.table-scroll-height  .ant-table-body');
        if(topList.length>0){
            topList[0].style.height = (store.getState().tableHeight.y)/2 + 'px';
        }
        let bottomList = document.querySelectorAll('.table-detail-height  .ant-table-body');
        if(bottomList.length>0){
            bottomList[0].style.height = (store.getState().tableHeight.y)/2 + 'px';
        }
        this.getPharmacyWindowData();
        this.getCardSelectData();
        window.addEventListener('beforeunload', this.beforeunload);
        this.getDetailListTableColumns();
        this.getListTableColumns();
    }

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

    // 获取主列表头数据
    getListTableColumns = () => {
        let {userInfo} = this.state;
        let data = {
            params: [{
                compontName: 'OutpatientDispensing',
                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.setState({parameterCode: 'OutpatientDispensing'},()=>{
                                this.columnRef.onOpenModel();
                            })}}>{userInfo.language== 'EN' ? item.enDescripts : item.title}</div>
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({Columns: filterArr, topLength: res.totalWidth})
                }
            }
        })
    };

    // 获取明系列表头数据
    getDetailListTableColumns = () => {
        let {userInfo} = this.state;
        let data = {
            params: [{
                compontName: 'OutpatientDispensingDetail',
                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.setState({parameterCode: 'OutpatientDispensingDetail'},()=>{
                                this.columnRef.onOpenModel();
                            })}}>{userInfo.language== 'EN' ? item.enDescripts : item.title}</div>
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({modalColumns: filterArr, listLength: res.totalWidth})
                }
            }
        })
    };

    beforeunload = (event) => {
        if(this.state.buttonStatus == 'start') {
            //用户点击浏览器右上角关闭按钮或是按alt+F4关闭
            if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
            {
                let confirmationMessage = '离开本页面自动配药将会停止! 是否要离开?';
                (event || window.event).returnValue = confirmationMessage;
                return confirmationMessage;
            }
            //用户点击任务栏，右键关闭。s或是按alt+F4关闭
            else if(event.clientY > document.body.clientHeight || event.altKey)
            {
                let confirmationMessage = '离开本页面自动配药将会停止! 是否要离开?';
                (event || window.event).returnValue = confirmationMessage;
                return confirmationMessage;
            }
            //其他情况为刷新
            else
            {
                let confirmationMessage = '刷新本页面自动配药将会停止! 是否要离开?';
                (event || window.event).returnValue = confirmationMessage;
                return confirmationMessage;
            }
        }
    }
    // 获取卡类型下拉框数据
    getCardSelectData = () => {
        let data = {
            params: [{}]
        }
        $http.post('urlS', this, {
            code: '02030052',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let defaultValue = '';
                    for(var i = 0; i < res.result.length; i++) {
                        if (res.result[i].defaultFlag === 'Y') {
                            defaultValue = res.result[i].id;
                        }
                    }
                    this.setState({cardSlectData: res.result, cardType: defaultValue, defaultValue: defaultValue})
                }
            }
        });
        $http.post('urlS', this, {
            code: '02030073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({parameterSetting: res, startDate: res.startDate, endDate: res.endDate})
                }
            }
        })
    }

    // 获取取药窗口信息
    getPharmacyWindowData = (flag) => {
        let data = {
            params: [],
        }
        $http.post('urlS', this, {
            code: "02030029",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({windowDomData: res.result[0].rows});
                }else {
                    this.setState({windowDomData: []});
                }
            }
        })
    }
// 关闭弹窗
    handleCancel = () => {
        this.setState({windowVisible:false})
    };
    // Checkbox的onChange事件
    compileChecked = (item, index) => {
        let windowDomData = [...this.state.windowDomData];
        for(var i = 0; i < windowDomData.length; i++) {
            let indexChecked = windowDomData[index].checked;
            windowDomData[i].checked = false;
            windowDomData[index].checked = indexChecked;
            if (windowDomData[i] === item) {
                windowDomData[i].checked = !windowDomData[i].checked;
            }
        }
        this.setState({windowDomData: windowDomData,radioWindowData:item,selectpharmacy:!this.state.selectpharmacy},()=>{
            if(!this.state.selectpharmacy){
                this.setState({determineSelect: false})
            }
        })
    };

    // 修改弹窗中的有人无人
    // handleSwitch = (item, e) => {
    //     let windowDomData = [...this.state.windowDomData];
    //     let status = e ? 'O' : 'C';
    //     for(var i = 0; i < windowDomData.length; i++) {
    //         if (windowDomData[i] === item) {
    //             windowDomData[i].statusID = status;
    //         }
    //     }
    //     this.setState({windowDomData: windowDomData}, () => {
    //         this.compileWindowStatus(item, status)
    //     });
    // };

    // 修改发药窗口状态
    compileWindowStatus = (item, status) => {
        let data = {
            params: [
                {
                    dispWinID: item.prepWinID,
                    statusID: status,
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030036",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    message.success(res.errorMessage)
                } else {
                    message.error(res.errorMessage)
                }
            }
        })
    };
    // 切换窗口 --- 确定
    windowHandleOk = () => {
        if(this.state.selectpharmacy){
            this.setState({windowVisible: false,determineSelect: true});
        }else {
            message.error('请选择配药窗口')
        }

        // this.getOutpatientList();
    };
    // 查询配药列表
    getOutpatientList = () => {
        if(!this.state.radioWindowData.prepWinID){
            message.error('请选择配药窗口');
            return
        }
        let { startDate, endDate, radioWindowData} = this.state;
        let data = {
            params: [
                {
                    prepWinID: radioWindowData&&radioWindowData.prepWinID ? radioWindowData.prepWinID : undefined, // 发药窗口ID
                    startDate: startDate ? Moment(startDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 开始日期
                    endDate: endDate ? Moment(endDate).format('YYYY-MM-DD') : Moment().format('YYYY-MM-DD'), // 截止日期
                    // patNo: this.state.patNo,
                    // credNo: this.state.cardNo,
                    // cardTypeID:this.state.cardType,
                    patID: this.state.patID,
                    dispRecFlag:this.state.dispRecFlag,
                }
            ],
            pagination: [
                {
                    pageSize:this.state.pageSize,
                    currentPage:this.state.page,
                    sort:"ID",
                    dir:"asc",
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030070",
            data: data,
            success: function (res) {
                let arr = [];
                // if (+res.errorCode === 0 ) {
                //     this.setState({});
                // }else {
                //     this.setState({});
                // };

                if (+res.errorCode === 0 && res.rows && res.rows.length>0) {
                    for (var i = 0; i < res.rows.length; i++) {
                        res.rows[i].key = i+1;
                        arr[i] = i+1;
                    }
                 this.setState({detailData: res.rows,total: res.total, selectedRowKeys: arr, selectAllData: res.rows,DispensingFlag: res.dispRecFlag});
                }else {
                    this.setState({detailData:[],total: 0, detailsListData:[],selectedRowKeys: [],selectAllData:[],DispensingFlag:null});
                    message.error('没数据');
                }
            }
        })
    };
// 查询配药列表
    getOutpatientDetailList = () => {
        let data = {
            params: [
                {
                    ordPrescNo:this.state.prescNo,
                    dispID: this.state.dispID,
                }
            ],
        }
        $http.post('urlS', this, {
            code: "02030072",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.result.rows) {
                    for (var i = 0; i < res.result.rows.length; i++) {
                        res.result.rows[i].key = i;
                    }
                    this.setState({detailsListData: res.result.rows})
                }else {
                    this.setState({detailsListData: []})
                    // message.error('没数据')
                }
            }
        })
    };
    // 配药
    getOutpatient = () => {
        if(this.state.selectAllData.length>0 ){
            let arr = this.state.selectAllData.map((item)=>{
                return {
                    prescNo:item.prescNo,
                    patNo: item.patNo
                }
            });
            let data = {
                params: arr.length>0 ? arr : ''
            }
            $http.post('urlS', this, {
                code: "02030071",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(res.errorMessage)
                        this.getOutpatientList();
                    }
                }
            })
        }else {
            message.error('请选择配药信息')
        }

    };

    // 3.2.1.3.13.根据卡号取病人信息
    getPatientInformation = (flag) => {
        let data = {
            params: [{
                number: this.state.patNo, // 病人登记号/证件号
                cardTypeID: flag === 'readCard' ? this.state.cardType : undefined, // 卡类型id
                cardNo: this.state.cardNo, // 卡号
            }]
        }
        $http.post('urlS', this, {
            code: '03040004',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let cardNo = flag === "readCard"&&res.data&&res.data.patCardNo ? res.data.patCardNo : undefined; // 给卡号赋值
                    this.setState({patID: res.data&&res.data.patID ? res.data.patID : '', cardNo: res.data.patCardNo, patNo: res.data.patNo},()=>{
                        this.getOutpatientList();
                    })
                }else if (res.errorFlag === 'N') {
                    this.setState({tableData: [], total: 0, patID: 'aaaaa'})
                    message.error(res.errorMessage)
                }
            }
        })
    };
    // 病人id
    handlePatientOnChange = (e) => {
        if (!e.target.value) {
            this.setState({patID: ''})
        }
        this.setState({patNo: e.target.value})
    };
    // 查询病人id
    handlePatient = (e, name) => {
        if (!e.target.value) {
            this.setState({patID: ''})
            return;
        }
        this.setState({cardNo: undefined, cardType: this.state.defaultValue}, () => {
            this.getPatientInformation('patient');
        })
    }

    handleReadCardOnBlur = (e) => {
        if (!e.target.value) {
            this.setState({patID: ''})
            return;
        }
        this.setState({patNo: undefined}, () => {
            this.getPatientInformation('readCard');
        })
    }
    // 获取表格数据
    handleQuery = () => {
        this.setState({ page: 1, pageSize: 10, rowId: '', prescNo: '', detailsListData: [], detailData: [],cardNo: '', patNo: '', dispRecFlag: false})
    };
    // 关闭弹窗
    handleCancel = () => {
        if(this.state.determineSelect){
            this.setState({
                windowVisible: false,
            });
        }

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

    onShowSizeChange = (current, size) => {
        this.setState({page: current, pageSize: size}, () => {
            // 重新调用查询方法
            this.onChange(current,size);
        })
    };
    switchingWindow=()=>{
        this.setState({windowVisible:true})
    };

    // 查询条件 --- 开始日期
    handleStartDate = (e) => {
        this.setState({ startDate: e });
    };

    // 查询条件 --- 截止日期
    handleEndDate = (e) => {
        this.setState({ endDate: e });
    };

    //是否配药
    onChangeDispRecFlag = (e) => {
        this.setState({ dispRecFlag: e.target.checked });
    };
    // 卡号
    handleCardNoChange = (e) => {
        if (!e.target.value) {
            this.setState({patID: ''})
        }
        this.setState({cardNo: e.target.value})
    };
    // 卡类型
    handleCardTypeOnChange = (e) => {
        this.setState({cardType: e})
    };
    // 操作行 --- 左侧列表待发药
    onClickRowLeftTable = (record) => {
        return {
            // 单击行选中
            onClick: () => {
                if (this.state.outpatientID === '') {
                    // 保存行数据以及ID
                    this.setState({prescNo: record.prescNo, outpatientID: record.key, dispID: record.id}, () => {
                        this.getOutpatientDetailList();
                    })
                } else {
                    if (this.state.outpatientID !== record.key) {
                        this.setState({prescNo: record.prescNo, outpatientID: record.key,dispID: record.id}, () => {
                            this.getOutpatientDetailList();
                        })
                    }else {
                        this.setState({prescNo: '', detailsListData: [], outpatientID: '',dispID: ''})
                    }
                }
            }
        }
    }

    // 选中行操作 --- 左侧列表
    setRowClassNameLeftTable = (record) => {
        return record.key === this.state.outpatientID ? 'clickRowStyle' : '';
    };

    //自动配药
    automaticOutpatient=()=>{
        if(this.state.whether){
            let secondTime = this.state.initData.RefreshTime ? (this.state.initData.RefreshTime)*1000 : 5000;
            this.automaticDispensingPort('outpatient');
            this.setState({buttonStatus:'start'})
            autoamticTimer =  setInterval(() => {
                this.automaticDispensingPort('outpatient');
            }, secondTime);
        }else {
            //结束自动配药
            clearInterval(autoamticTimer);
            this.setState({buttonStatus:'end'})
        }

    };
    automaticDispensingPort=(v)=>{
        if(this.state.radioWindowData.prepWinID){
            let data = {
                params: [
                    {
                        prepWinID: this.state.radioWindowData.prepWinID,
                    }
                ]
            }
            $http.post('urlS', this, {
                code: "02030031",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0 && res.result &&res.result[0]&& res.result[0].rows&&res.result[0].rows.length>0) {
                        this.handlePrintPresc(res.result[0]&&res.result[0].rows);
                    }else {
                        if(v == 'Manual'){
                            message.error('没有打印数据')
                        }
                    }
                }
            })
        }else {
            message.error('请选择配药窗口')
        }

    };

    // 打印已配药单
    handleReprint = () => {
        if(this.state.DispensingFlag !==1 ){
            message.error('只能打印已配药单据');
            return
        }
        let {parameterSetting} = this.state;
        this.state.selectAllData&&JSON.parse(JSON.stringify(this.state.selectAllData)).map(item => {
            let params = {
                dispID:item.id,
                prescno:item.prescNo,
                phFlag:1,
            }
            if (parameterSetting.PrintLabel === '1') {
                $PrintLabel(params);
            }
            if (parameterSetting.PrintPYD === '1') {
                $PrintPYD(params);
            }
            if (parameterSetting.PrintPresc === '1') {
                $PrintPresc(params);
            }
        })
    }

    //打印处方
    handlePrintPresc = (notPrintData) => {
        let {parameterSetting} = this.state;
        if (!(notPrintData&&notPrintData.length > 0)) {
            return;
        }
        for (let i = 0; i < notPrintData.length; i++) {
            let params = {
                dispID:notPrintData[i].dispID,
                prescno:notPrintData[i].ordPrescNo,
                phFlag:1,
            }
            if (parameterSetting.PrintLabel === '1') {
                $PrintLabel(params);
            }
            if (parameterSetting.PrintPYD === '1') {
                $PrintPYD(params);
            }
            if (parameterSetting.PrintPresc === '1') {
                $PrintPresc(params);
            }
        }
    };
    //组件权限编辑器
    onColumnRef = (ref) => {
        this.columnRef = ref;
    };
    render() {
        const { getFieldDecorator } = this.props.form;
        let {windowDomData , windowVisible, cardSlectData, detailData, radioWindowData, patNo, detailsListData, modalColumns, listLength, topLength, Columns} = this.state;
        // 审核状态
        // let auditStatus = cardSlectData.a && cardSlectData.a.map((item, index) => {
        //     return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        // })
        // 卡类型
        let cardTypeOption = cardSlectData && cardSlectData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        let windowDom = (
            windowDomData&&windowDomData.map((item, index) => {
                return (
                    <div key={index} style={{margin: (index + 1) % 5 == 0 ? '0 0 20px 0' : '0 20px 20px 0'}}>
                        <div className="check-box">
                            <div className="prep-win-desc" style={{background: item.checked ? '#1890FF' : '#69C0FF'}}>{item.prepWinDesc}</div>
                            <div className="presc-num" style={{color: item.checked ? '#1890FF' : '#69C0FF'}}>{item.prescNum}</div>
                            <span>
                                <Checkbox checked={item.checked} onChange={() => this.compileChecked(item, index)} />
                            </span>
                        </div>
                        {/*<Row className="check-row">*/}
                            {/*<Switch checkedChildren="有人" unCheckedChildren="无人" checked={item.statusID === 'O' ? true : false} onChange={(e) => this.handleSwitch(item, e)} />*/}
                        {/*</Row>*/}
                    </div>
                )
            })
        );
        const rowSelection = {
            selectedRowKeys: this.state.selectedRowKeys,
            onChange: (selectedRowKeys, selectedRows) => {
                this.setState({selectAllData:selectedRows,selectedRowKeys});
            },
        };

        return (
            <div className="Odispensing">
                <Row id="outpha-dispensing-basic" style={{padding: '0 24px'}}>
                    <Col span={15} className="input-padding-right">
                        <Row style={{marginBottom: '8px'}}>
                            <Select value={this.state.cardType} onChange={this.handleCardTypeOnChange} showSearch optionFilterProp="seatchprop" allowClear placeholder="居民健康卡" style={{width: '150px', margin: '8px 8px 0 0'}}>
                                {cardTypeOption}
                            </Select>
                            <Input value={this.state.cardNo} allowClear onChange={this.handleCardNoChange} onBlur={(e) => this.handleReadCardOnBlur(e)} onPressEnter={(e) => this.handleReadCardOnBlur(e)} placeholder="请输入卡号(Enter)" style={{width: '150px', marginTop: '8px', borderRight: '0'}} />
                            <Button style={{marginRight: '12px', background: 'rgba(77,193,130,1)', color: '#fff'}} onClick={this.handleReadCard}>读卡</Button>
                            <Input
                                title="回车触发病人ID查询"
                                allowClear
                                placeholder="病人ID/证件号(Enter)"
                                ref={this.myRef1}
                                style={{width: '160px', margin: '8px 20px 0 0'}}
                                value={patNo}
                                onBlur={(e) => this.handlePatient(e, 'blur')}
                                onChange={this.handlePatientOnChange}
                                onPressEnter={(e) => this.handlePatient(e, 'enter')}
                            />
                            <div style={{display: 'inline-block'}}>
                                收费日期：<DatePicker onChange={this.handleStartDate} value={Moment(this.state.startDate)} style={{width: '150px', marginTop: '8px'}} placeholder="开始日期" />
                                <span style={{display: 'inline-block', margin: '0 5px'}}>到</span>
                                <DatePicker onChange={this.handleEndDate} value={Moment(this.state.endDate)} style={{width: '150px', marginRight: '8px'}} placeholder="结束日期" />
                                <span>
                                    <Checkbox value={this.state.dispRecFlag} onChange={this.onChangeDispRecFlag}>已配药</Checkbox>
                                </span>
                                <Button style={{marginTop: '8px', marginLeft: '15px'}} onClick={this.getOutpatientList}>查询</Button>
                            </div>
                        </Row>
                    </Col>
                    <Col span={5} style={{paddingTop: '8px'}}>
                        <Button
                            type="danger"
                            ghost
                            onClick={()=>{this.handleReprint()}}
                            style={{color: '#1890FF', borderColor: '#1890FF'}}
                            disabled={this.state.DispensingFlag == 1 ? false : true}
                        >打印</Button>
                        <Button
                            type="danger"
                            onClick={this.getOutpatient}
                            style={{margin: '0 15px'}}
                            disabled={this.state.DispensingFlag == 0 ? false : true}
                        >配药</Button>
                        <Button
                            type="primary"
                            onClick={()=>{
                                this.setState({whether: !this.state.whether},()=>{
                                    this.automaticOutpatient();
                                })
                            }}
                        >{this.state.whether ? '取消自动配药' : '自动配药'}</Button>
                        <Button
                            type="danger"
                            ghost
                            onClick={this.handleQuery}
                            style={{marginLeft: '15px', color: '#1890FF', borderColor: '#1890FF'}}
                        >清屏</Button>
                    </Col>
                    <Col span={4} style={{paddingTop: '8px', textAlign: 'right'}}>
                        <span style={{ fontSize: '15px', fontWeight:'700'}}>
                            当前窗口：{radioWindowData&&radioWindowData.prepWinDesc ? radioWindowData.prepWinDesc :
                            "未选择窗口"}
                            <Button type="dashed" style={{marginLeft: '20px', fontSize:'15px'}} onClick={this.switchingWindow}>切换窗口</Button>
                        </span>
                    </Col>
                </Row>
                <Row>
                    <Col>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>配药列表</div>}
                            extra={<span style={{color: '#666'}} className='span' onClick={() => {this.setState({parameterCode: 'OutpatientDispensing'},()=>{
                                this.columnRef.onOpenModel();
                            })}}><Icon type="setting" title='列权限设置' /></span>}
                        >
                            <div>
                                <Table
                                    rowSelection={rowSelection}
                                    selectedRowKeys={this.state.selectedRowKeys}
                                    columns={Columns.length>0 ? Columns : this.columns}
                                    dataSource={detailData}
                                    bordered
                                    pagination={false}
                                    scroll={{x: topLength? topLength : 1800, y: (store.getState().tableHeight.y)/2 -14 + 'px'}}
                                    onRow={this.onClickRowLeftTable}
                                    rowClassName={this.setRowClassNameLeftTable}
                                    className="table-scroll-height"
                                />
                                <CommonPagination size='small' current={this.state.page} total={this.state.total} search= 'search'
                                                  onShowSizeChange={this.onShowSizeChange.bind(this)} complete={true} dataSource={detailData}
                                                  loading={this.state.loading} onChange={this.onChange.bind(this)} />
                            </div>
                        </Card>
                    </Col>
                    <Col>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>药品详情列表</div>}
                            className="dispensing-list"
                            extra={<span style={{color: '#666'}} className='span' onClick={() => {this.setState({parameterCode: 'OutpatientDispensingDetail'},()=>{
                                this.columnRef.onOpenModel();
                            })}}><Icon type="setting" title='列权限设置' /></span>}
                        >
                            <Table
                                columns={modalColumns.length>0 ? modalColumns : this.detailColumns}
                                dataSource={detailsListData}
                                bordered
                                pagination={false}
                                scroll={{x: listLength? listLength:1500, y: (store.getState().tableHeight.y)/2 -50 + 'px'}}
                                // onRow={this.onClickRowLeftTable}
                                // rowClassName={this.setRowClassNameLeftTable}
                                className="table-detail-height"
                            />
                        </Card>
                    </Col>
                </Row>
                <Modal
                    title={<div><div className="modal-title-top"></div>选择窗口</div>}
                    visible={windowVisible}
                    style={{minWidth: '680px'}}
                    className="modal-header-line modal-body-padding"
                    onCancel={() => this.handleCancel()}
                    footer={
                        <div>
                            <Button style={{marginRight: '8px'}} onClick={() => this.handleCancel()}>取消</Button>
                            <Button onClick={this.windowHandleOk} style={{backgroundColor: '#1890ff', borderColor: '#1890ff', color: '#fff'}}>确认</Button>
                        </div>
                    }
                >
                    <div style={{color: '#F5222D', fontSize: '4px', background: '#FFF1F0', height: '32px', lineHeight: '32px', paddingLeft: '24px'}}>
                        <Icon type="exclamation-circle" style={{marginRight: '4px'}} />切换窗口时请选择需要切换的窗口并点击确定按钮。
                    </div>
                    <Form style={{padding: '0 24px'}}>
                        <Form.Item label="请选择窗口：">
                            {getFieldDecorator('window', {
                                rules: [{ required: true }],
                            })(
                                <Row className="ad-window li-window" style={{padding: '0 20px'}}>
                                    {windowDom}
                                </Row>
                            )}
                        </Form.Item>
                    </Form>
                </Modal>
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName={ this.state.parameterCode}
                    configType="C"
                    onRef={this.onColumnRef}
                    reloadData={() => {
                        if (this.state.parameterCode == 'OutpatientDispensing') {
                            this.getListTableColumns()
                        }else if(this.state.parameterCode == 'OutpatientDispensingDetail'){
                            this.getDetailListTableColumns()
                        }
                    }
                    }
                />
            </div>
        )
    }
};
const DispensingForm = Form.create()(Dispensing);
export default DispensingForm;
