// 煎药房发药
import React from 'react';
import { Card, Row, Col, Select, Button, Input, DatePicker, Switch, Modal, Table, Checkbox, Icon, Form, message } from 'antd';
import PubilcTablePagination from '../common/PubilcTablePagination';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import RejectPrescription from '../pharmacy/outpha/RejectPrescription.jsx'; // 审核拒绝
import store from 'store';
import { $http } from 'containers/config/https';
import Moment from 'moment';
import './style/outpha.less';
import { $PrintPresc,$PrintLabel,$PrintPYD } from './common/Print';
import ReadCard from 'components/readcard/ReadCard';

const { Option } = Select;
let buttonStatus = true;
let timer = null;

class Dispensing extends React.Component {

    constructor(props) {
        super(props);
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            userData,
            statusSelectData: [], // 审核状态下拉框数据
            startDate: Moment(), // 开始日期
            endDate: Moment(), // 截止日期
            fyFlag: undefined, // 发药标志
            patID: '', // 病人Id
            pat: '', // 回车保存的病人id
            patNo: undefined, // 病人
            tableData: [],
            total: 0,
            page: 1,
            pageSize: 20,
            rowId: '', // 选中行标识 --- 发药列表
            rowData: {}, // 选中行对象 --- 发药列表
            basicHeight: 0,
            detailData: [],
            pharmacistVisible: false, // 选中配药师弹窗
            dispensingChecked: false, // 直接发药
            windowVisible: false, // 选中窗口
            windowDomData: [],
            LTrowId: '', // 左侧列表选中标识 --- 待发药
            LTrowData: {}, // 选中行对象 --- 待发药
            usageData: [], // Rp数据
            usageTableData: [], // 选药列表数据
            selectedRowKeys: [],
            selectedRows: [],
            unfoldTableData: {}, // 点击显示table的行数据
            radioWindowData: {}, // 选中一条发药窗口数据
            parameterSetting: {}, // 3.2.1.6.10.取发药参数设置
            mainInfo: [], // 发药主信息
            detailInfo: [], // 发药明细信息
            PharmacistSelectData: [], // 配药师下拉框数据
            pharmacistValue: undefined, // 配药师
            defaultValue: '', // 默认卡类型
            cardSlectData: [], // 卡类型下拉框数据
            cardType: undefined, // 卡类型
            cardNo: undefined, // 卡号
            LTpatID: '', // 选中行病人id
            // checkedObj: {}, // 选中窗口
            loading: false,
            columns: [],
            widthTotal: 0,
            detailColumns: [], // 待发药
            detailWidthTotal: 0,
            authorityStatus: false,
        };
        this.columns = [
            { title: '病人ID', dataIndex: 'patNo', key: '1', width: '100px', align: "center"},
            { title: '患者', dataIndex: 'patName', key: '2', width: '100px', align: "center"},
            { title: '处方号', dataIndex: 'ordPrescNo', key: '3', width: '150px', align: "center"},
            { title: '收费日期', dataIndex: 'dateTime', key: '4', width: '150px', align: "center"},
        ];
        this.detailColumns = [
            { title: '序号', dataIndex: 'key', key: '1', width: '80px', align: "center"},
            { title: '性名', dataIndex: 'patName', key: '2', align: "center"},
        ];
        this.usageColumns = [
            { title: '执行时间', dataIndex: 'time', key: '1', width: '50%', align: "center"},
            { title: '数量', dataIndex: 'num', key: '2', align: "center"},
        ];
        this.myRef1 = React.createRef();
    }

    componentDidMount() {
        // this.getPharmacyWindowData("start");
        this.authorityManagement();
        this.getSelectData();
        this.getCardSelectData();
        this.getParameterSetting();
        this.getOutpatientWaitingList(); // 获取待发药表头数据
        this.getMainTableColumns(); // 获取发药列表表头数据
        // loading
        this.child.handleLoading();
        this.getPharmacistSelectData();
        this.setState({basicHeight: document.getElementById("outpha-dispensing-basic").clientHeight});
    }

    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        clearInterval(timer);
        this.setState = (state,callback)=>{ return; }
    }
    //判断医生有没有审核权限
    authorityManagement=()=>{
        let data = {
            params: [{
                userID:this.state.userData.userID,
                locID:this.state.userData.locID,
                authDesc:'DispAuth'
            }]
        }
        $http.post('urlS', this, {
            code: "02030082",
            data: data,
            success: function (res) {
                if (+res.errorCode == '02010015' ) {
                    // message.error(res.errorMessage);
                    this.setState({authorityStatus: true})
                } else {
                    this.setState({authorityStatus: false})
                }
            }
        })
    };
    // 获取数据列表columns
    getMainTableColumns = () => {
        let {userData} = this.state;
        let data = {
            params: [{
                compontName: "DrugDistribution",
                reactCode: ['DrugDistribution'],
                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.mainColumnRef.onOpenModel()}>{userData.language == 'EN' ? (item&&item.enDescripts ? item.enDescripts : item.title) : item.title}</div>
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({
                        columns: filterArr, widthTotal: res.totalWidth,
                        localeProvider: userData.language == 'EN' ? res.result.language.EN : res.result.language.CN
                    })
                }
            }
        })
    }

    onMainColumnRef = (ref) => {
        this.mainColumnRef = ref;
    }

    //国际化
    setMessage = (name, message, defaultTitle) => {
        return this.state.localeProvider&&this.state.localeProvider[name] ? this.state.localeProvider[name][message] : defaultTitle
    }

    // 获取门诊发药待发药列头
    getOutpatientWaitingList = () => {
        let {userData} = this.state;
        let data = {
            params: [{
                compontName: "OutpatientWaitingList",
                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.detailColumnRef.onOpenModel()}>{userData.language == 'EN' ? (item&&item.enDescripts ? item.enDescripts : item.title) : item.title}</div>
                        }
                    }) : '';
                    let filterArr = arr.filter(function(item){ return item.display === 'Y'});
                    this.setState({detailColumns: filterArr, detailWidthTotal: res.totalWidth})
                }
            }
        })
    }

    onDetailColumnRef = (ref) => {
        this.detailColumnRef = ref;
    }

    // 3.2.1.6.10.取发药 参数设置
    getParameterSetting = () => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030044",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({parameterSetting: res.result[0]})
                }
            }
        })
    }

    // 获取取药窗口信息
    getPharmacyWindowData = (flag) => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030035",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result[0] && res.result[0].rows && JSON.parse(JSON.stringify(res.result[0].rows)).map((item, index) => {
                        return {
                            key: index + 1,
                            checked: false,
                            disabled: false,
                            dispWinDesc: item.dispWinDesc, // 发药窗口描述
                            dispWinID: item.dispWinID, // 发药窗口ID
                            statusID: item.statusID, // 状态ID
                            statusDesc: item.statusDesc, // 状态描述
                            prescNum: item.prescNum, // 窗口数量
                        }
                    })
                    if(this.state.radioWindowData&&this.state.radioWindowData.dispWinID) {
                        for (let i = 0; i < arr.length; i++) {
                            if (arr[i].dispWinID === this.state.radioWindowData.dispWinID) {
                                arr[i].checked = this.state.radioWindowData.checked;
                            }
                        }
                    }
                    this.setState({windowDomData: arr}, () => {
                        if (flag === "start") {
                            this.showModal("window")
                        }
                    })
                }
            }
        })
    }

    filterDspInfo = (data) => {
        let rowsData = data[0].rows;
        let obj = {};
        let batInfo = [];
        let filterBatInfo = [];
        for(var i = 0; i < rowsData.length; i++) {
            batInfo = batInfo.concat(rowsData[i].batInfo)
        }
        for(var i = 0; i < batInfo.length; i++) {
            if (!obj[batInfo[i].batNo]) {
                obj[batInfo[i].batNo] = batInfo[i].batNo;
                filterBatInfo.push(batInfo[i]);
            } else {
                for(var j = 0; j < filterBatInfo.length; j++) {
                    if (filterBatInfo[j].batNo === batInfo[i].batNo) {
                        filterBatInfo[j].qty += batInfo[i].qty;
                    }
                }
            }
        }
        let dspInfo = [];
        rowsData[0].batInfo = filterBatInfo
        let batInfoObj = {
            rows: rowsData
        }
        dspInfo.push(batInfoObj);
        return dspInfo
    }

    // 3.2.1.6.6.获取发药明细信息
    getDetailInformation = (record) => {
        let data = {
            params: [
                {
                    dispID: record.dispID ? record.dispID : '', // 发药表ID
                    ordPrescNo: record.ordPrescNo ? record.ordPrescNo : '', // 处方号
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030113",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let detailInfo = res.result[0] ? JSON.parse(JSON.stringify(res.result[0].detailInfo)) : [];
                    let usageData = detailInfo&&detailInfo.length > 0 ? JSON.parse(JSON.stringify(detailInfo[0].rows)) : [];

                    for (var i = 0; i < usageData.length; i++) {
                        usageData[i].visible = false;
                        usageData[i].filterDd = usageData[i].ordQty;
                        // usageData[i].dspInfo = this.filterDspInfo(usageData[i].dspInfo)
                    }
                    // console.log(usageData)
                    this.setState({
                        mainInfo: res.result[0] ? res.result[0].mainInfo : [],
                        usageData: usageData,
                    })
                } else {
                    this.setState({mainInfo: [], usageData: [], selectedRowKeys: [], selectedRows: []})
                }
            }
        })
    }

    // 3.2.1.6.4.获取发药 等候队列
    getMedicationWaitingQueue = () => {
        let {mode, startDate, endDate, radioWindowData} = this.state;
        let data = {
            params: [
                {
                    // mode: mode ? mode : 1, // 发药模式
                    // dispWinID: radioWindowData&&radioWindowData.dispWinID ? radioWindowData.dispWinID : 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'), // 截止日期
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030088",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.rows) {
                    for (var i = 0; i < res.rows.length; i++) {
                        res.rows[i].key = res.rows[i].patID
                    }
                    let arr = res.rows;
                    if (JSON.stringify(arr) !== JSON.stringify(this.state.detailData)) {
                        this.setState({detailData: arr}, () => {
                            this.handleFYClick("dfy-list");
                        })
                    }
                }
            }
        })
    }

    getTableData(mode, startDate, endDate, fyFlag, patID) {
        let {pageSize, page, radioWindowData, LTpatID, patNo} = this.state;
        let data = {
            params: [{
                // mode: mode ? mode : 1, // 发药模式
                // dispWinID: radioWindowData&&radioWindowData.dispWinID ? radioWindowData.dispWinID : undefined, // 发药窗口ID
                // dispWinID: '1', // 发药窗口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'), // 截止日期
                dispRecFlag: fyFlag, // 发药标志
                patID: LTpatID ? LTpatID : (this.isNumber(patNo) ? patID : ""), // 病人ID
                patName: LTpatID ? "" : (this.isNumber(patNo) ? "" : patNo),
            }],
            pagination: [{
                pageSize: pageSize,
                currentPage: page
            }]
        }
        setTimeout(() => {
            var gundong = document.querySelector("#fy-list .ant-table-body");
            gundong.scrollTop = 0;
        }, 100)
        $http.post('urlS', this, {
            code: "02030089",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.rows) {
                    let arr =  res.rows ?  res.rows : []
                    for (var i = 0; i <arr.length; i++) {
                        arr[i].key = i+1;
                    }
                    let rowData = arr&&arr.length > 0 ? arr[0] : {};
                    this.setState({ tableData: arr, total: res.total, rowId: rowData&&rowData.key ? rowData.key : "", rowData }, () => {
                        if (this.state.rowId) {
                            this.getDetailInformation(this.state.rowData);
                            // this.handleFYClick("fy-list");
                        }
                    })
                    // 数据加载成功关闭loading
                    this.child.handleLoading();
                } else {
                    this.setState({ tableData: [], total: 0, rowId: "", rowData: {}})
                    // 数据加载失败关闭loading
                    this.child.handleLoading();
                }
            },
            error: function (error) {
                this.setState({ tableData: [], total: 0 , rowId: "", rowData: {}}, () => {
                    // 数据加载成功关闭loading
                    this.child.handleLoading();
                })
            }
        })
    }

    // 重置操作数据
    resetData = () => {
        this.setState({rowId: '', rowData: {}, mainInfo: [], usageData: []});
        this.getMedicationWaitingQueue(); // 重新查询待发药列表
    }

    // 获取表格数据
    handleQuery = () => {
        setTimeout(() => {
            this.setState({ page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: [], LTrowId: '', LTpatID: '' }, () => {
                this.refreshTableData();
                this.getMedicationWaitingQueue();
            })
        }, 300)
    }

    // 按照输入条件重新查询数据
    refreshTableData() {
        let {mode, startDate, endDate, fyFlag, patID} = this.state;
        this.getTableData(mode, startDate, endDate, fyFlag, patID)
    }


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

    onRef = (ref) => {
        this.child = ref;
    }

    onModalRef = (ref) => {
        this.modalChild = ref;
    }

    // 操作行 --- 左侧列表待发药
    onClickRowLeftTable = (record) => {
        return {
            // 单击行选中
            onClick: () => {
                if (this.state.LTrowId === '') {
                    // 保存行数据以及ID
                    this.setState({LTrowId: record.key, LTpatID: record.patID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: []}, () => {
                        this.refreshTableData();
                    })
                } else {
                    if (this.state.LTrowId !== record.key) {
                        this.setState({LTrowId: record.key, LTpatID: record.patID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: []}, () => {
                            this.refreshTableData();
                        })
                    }
                }
            }
        }
    }

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

    // 操作行 --- 发药列表
    onClickRowPublic = (record) => {
        return {
            // 单击行选中
            onClick: () => {
                if (this.state.rowId === '') {
                    // 保存行数据以及ID
                    this.setState({rowId: record.key, rowData: record}, () => {
                        this.getDetailInformation(this.state.rowData)
                    })
                } else {
                    if (this.state.rowId !== record.key) {
                        this.setState({rowId: record.key, rowData: record}, () => {
                            this.getDetailInformation(this.state.rowData)
                        })
                    }
                }
            }
        }
    }

    // 选中行操作 --- 发药列表
    setRowClassNamePublic = (record) => {
        return (record.dispStatus === "Y")&&(record.key === this.state.rowId) ? "select-and-row" : (record.dispStatus === "Y" ? "select-color": (record.key === this.state.rowId ? 'clickRowStyle' : ""));
    }

    // 直接发药模式
    onClickSwitch = () => {
        if (!this.state.dispensingChecked) {
            this.showModal('pharmacist')
        } else {
            this.setState({dispensingChecked: false, pharmacistValue: undefined, mode: 1}, () => {
                this.refreshTableData(); // 发药列表
                this.resetData(); // 重置操作数据以及刷新待发药列表
            })
        }
    }

    // 切换窗口
    switchingWindow = () => {
        this.setState({
            windowVisible: true,
        }, () => {
            this.getPharmacyWindowData();
        });
    }

    // 打开弹窗
    showModal = (flag) => {
        if (flag === 'pharmacist') {
            this.setState({
                pharmacistVisible: true,
            });
        } else if (flag === 'window') {
            let {windowDomData} = this.state;
            if (windowDomData&&windowDomData.length === 1) { // 如果窗口数等于1的话直接默认为当前窗口
                let arr = JSON.parse(JSON.stringify(windowDomData));
                arr[0].checked = true;
                this.setState({windowDomData: arr}, () => {
                    this.windowHandleOk();
                })
            } else {
                this.setState({
                    windowVisible: true,
                });
            }
        }

    };

    // 选择配药师弹窗 --- 确定
    pharmacistHandleOk = () => {
        // 当选择配药师之后直接发药模式变成是并且关闭选择模态框
        if (this.state.pharmacistValue) {
            // 点击确定并且成功之后将开关切换为是并且关闭弹窗
            this.setState({dispensingChecked: true, mode: 2}, () => {
                this.handleCancel('pharmacist');
                this.handleQuery();
            })
        } else {
            message.info(this.setMessage("DrugDistributionpleaseSelectPharmacist", "descripts", "请选择配药师"))
        }
    };

    // 切换窗口 --- 确定
    windowHandleOk = () => {
        let messageTrue = true;
        let obj = {};
        let windowDomData = JSON.parse(JSON.stringify(this.state.windowDomData));
        if (windowDomData&&windowDomData.length > 0) {
            for (let i = 0; i < windowDomData.length; i++) {
                if (windowDomData[i].checked == true) {
                    messageTrue = true
                    obj = windowDomData[i];
                    break;
                } else {
                    messageTrue = false
                }
            }
        }
        // console.log(arr)
        if (messageTrue === false) {
            message.error(this.setMessage("DrugDistributionpleaseSelectDrugDispensingWin", "descripts", "请选择发药窗口"))
        } else {

            this.setState({radioWindowData: obj}, () => {
                let date  = this.state.parameterSetting.refreshTime ? this.state.parameterSetting.refreshTime * 1000 : 10*1000; // 将秒转为毫秒
                // console.log(date)
                timer = setInterval(() => {
                    this.getMedicationWaitingQueue();
                }, date);
                this.handleQuery();
                this.handleCancel('window');
            })
        }
    }

    // 关闭弹窗
    handleCancel = (flag) => {
        if (flag === 'pharmacist') {// 关闭直接发药模式刷新待发药、发药列表、处方笺三栏的数据
            this.setState({
                pharmacistVisible: false,
            });
        } else if (flag === 'window') {
            if (this.state.radioWindowData&&this.state.radioWindowData.dispWinID) {
                let windowDomData = JSON.parse(JSON.stringify(this.state.windowDomData));
                let index;
                for (var i = 0; i < windowDomData.length; i++) {
                    windowDomData[i].checked = false;
                    if (windowDomData[i].dispWinID === this.state.radioWindowData.dispWinID) {
                        index = i;
                    }
                }
                windowDomData[index].checked = this.state.radioWindowData.checked;
                this.setState({
                    windowVisible: false,
                    windowDomData
                }, () => {
                    setTimeout(() => {
                        this.myRef1.current.focus();
                    }, 300)
                });
            } else {
                message.error(this.setMessage("DrugDistributionpleaseSelectDrugDispensingWin", "descripts", "请选择发药窗口"))
            }
        }
    };

    // 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})
    }

    // 点击切换Icon并且显示弹窗
    handleISModal = (item) => {
        this.getExecutionRecord(item); // 切换Icon请求执行记录
        let arr = [...this.state.usageData];

        for(var i = 0; i < arr.length; i++) {
            if (arr[i].ordID === item.ordID) {
                arr[i].visible = !arr[i].visible
            } else {
                arr[i].visible = false;
            }
        }
        this.setState({usageData: arr, unfoldTableData: item})
    }

    // 修改发药窗口状态
    compileWindowStatus = (item, status) => {
        let data = {
            params: [
                {
                    dispWinID: item.dispWinID,
                    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)
                }
            }
        })
    }

    // 修改弹窗中的有人无人
    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)
        });
    }

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

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

    // 查询条件 --- 审核状态
    handlestatusID = (e) => {
        this.setState({ fyFlag: e });
    }

    // 选择配药师
    handlePharmacistValue = (e) => {
        this.setState({ pharmacistValue: e });
    }

    // 3.2.1.6.3.取发药状态下拉框数据集
    getSelectData = () => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030037",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.result) {
                    this.setState({statusSelectData: res.result, fyFlag: res.result[0].id},()=>{
                        this.handleQuery()
                    })
                } else {
                    this.setState({statusSelectData: []})
                }
            }
        })
    }

    // 病人id
    handlePatientOnChange = (e) => {
        if (!e.target.value) {
            setTimeout(() => {
                this.setState({patID: ''})
            }, 500);
        }
        this.setState({patNo: e.target.value})
    }

    // 病人id失去焦点事件
    handlePatientOnBlur = (e) => {
        if (e.target.value !== this.state.pat) {
            this.setState({patNo: undefined, patID: '', pat: ''})
        }
    }

    isNumber = (val) => {
        var regPos = /^\d+(\.\d+)?$/; //非负浮点数
        var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
        if(regPos.test(val) || regNeg.test(val)) {
            return true;
        } else {
            return false;
        }
    }

    // 查询病人id
    handlePatient = (e, name) => {
        if (!e.target.value) {
            this.setState({patID: ''})
            return;
        }
        if (this.isNumber(e.target.value)) {
            this.setState({cardNo: undefined, cardType: this.state.defaultValue}, () => {
                this.getPatientInformation('patient', name);
            })
        } else {
            this.setState({LTrowId: '', LTpatID: '', page: 1, mainInfo: [], usageData: [], rowData: {}, rowId: '', patID: ""}, () => {
                this.refreshTableData();
            })
        }
    }

    // 3.2.1.6.7.根据医嘱ID获取执行记录
    getExecutionRecord = (item) => {
        let dspInfo = item.dspInfo&&item.dspInfo[0].rows ? item.dspInfo[0].rows : [];
        let data = {
            params: [
                {
                    dispID: item.dispID, // 发药表ID
                    ordID: item.ordID, // 医嘱ID
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030041",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0&&res.result) {
                    let arr = res.result[0]&&res.result[0].rows.length > 0 ? res.result[0].rows.map((itemChild, index) => {
                        return {
                            ...itemChild,
                            num: itemChild.qty + itemChild.unitDesc,
                            time: itemChild.reqExeDate + ' ' + itemChild.reqExeTime,
                            key: itemChild.dspID
                        }
                    }) : [];
                    let selectedRowKeys = [];
                    for(var i = 0; i < dspInfo.length; i++) {
                        selectedRowKeys.push(dspInfo[i].dspID)
                    }
                    this.setState({usageTableData: arr, selectedRows: dspInfo, selectedRowKeys})
                }
            }
        })
    }


    // 修改该条已发药数据的状态
    modifyDispStatus = (rowData) => {
        console.log('rowData',rowData)
        let tableData = JSON.parse(JSON.stringify(this.state.tableData));
        console.log('tableData',tableData)
        for (var i = 0; i < tableData.length; i++) {
            if (tableData[i].key === rowData.key) {
                tableData[i].dispStatus = "Y";
                break;
            }
        }
        this.setState({tableData, rowData: {}, rowId: ""})
    }

    // 获取配药师下拉框数据
    getPharmacistSelectData = () => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030045",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({PharmacistSelectData: res.result})
                } else {
                    this.setState({PharmacistSelectData: []})
                }
            }
        })
    }

    // 卡号
    handleCardNoChange = (e) => {
        if (!e.target.value) {
            setTimeout(() => {
                this.setState({patID: ''})
            }, 500);
        }
        this.setState({cardNo: e.target.value})
    }

    // 卡类型
    handleCardTypeOnChange = (e) => {
        this.setState({cardType: e})
    }

    // 读卡 --- 根据卡号取病人信息
    handleReadCard = () => {
        if (!buttonStatus) {
            return;
        }
        let {cardType} = this.state;
        this.readCard.ReadCard(cardType,"R",(json) => {
            this.setState({patID: json&&json.patInfo ? json.patInfo.patID : 'aaaaa', cardNo: json.cardNo}, () => {
                this.refreshTableData(); // 调取查询接口
            })
        })
    }

    handleReadCardOnBlur = (e, name) => {
        if (!e.target.value) {
            this.setState({patID: ''})
            return;
        }
        if (name === 'blur') {
            buttonStatus = false
        }
        this.setState({patNo: undefined}, () => {
            this.getPatientInformation('readCard', name);
        })
    }

    // 获取卡类型下拉框数据
    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})
                }
            }
        })
    }

    // 3.2.1.3.13.根据卡号取病人信息
    getPatientInformation = (flag, name) => {
        this.setState({loading: true});
        this.setState({LTrowId: '', LTpatID: '', page: 1, mainInfo: [], usageData: [], rowData: {}, rowId: ''})
        let data = {
            params: [{
                number: this.state.patNo, // 病人登记号/证件号
                cardTypeID: flag === 'readCard' ? this.state.cardType : undefined, // 卡类型id
                cardNo: this.state.cardNo, // 卡号
            }]
        }
        setTimeout(() => {
            buttonStatus = true;
        }, 500)
        $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 : '', loading: false, cardNo, patNo: res.data&&res.data.patNo ? res.data.patNo : ''}, () => {
                        if (name === 'enter') {
                            this.refreshTableData()
                        }
                    })
                } else if (res.errorFlag === 'N') {
                    this.setState({tableData: [], total: 0, patID: 'aaaaa', loading: false})
                    message.error(res.errorMessage)
                } else {
                    this.setState({loading: false});
                }
            },
            error: function() {
                this.setState({loading: false});
            }
        })
    }

    //打印处方
    handlePrintPresc = () => {
        let {rowData} = this.state;
        let params;
        params={
            // dispID:rowData.dispID,
            prescno:rowData.ordPrescNo,
            phFlag:1,
        }
        $PrintPresc(params);
    }

    //打印标签
    handlePrintLabel = () => {
        let {rowData} = this.state;
        let params;
        params={
            // dispID:rowData.dispID,
            prescno:rowData.ordPrescNo,
            phFlag:1,
        }
        $PrintLabel(params);
    }

    //打印配药单
    handlePrintPYD = () => {
        let {rowData} = this.state;
        let params;
        params={
            // dispID:rowData.dispID,
            prescno:rowData.ordPrescNo,
            phFlag:1,
        }
        $PrintPYD(params);
    }

    inciseData = () => {
        var {usageData} = this.state
        var result = [];
        for(var i = 0, len=usageData.length; i < len; i+=4){
            result.push(usageData.slice(i,i+4));
        }
        return result
    }

    // 西药时需要处理关联医嘱
    processAssociatedData = (data) => {
        let tempArr = [];
        let afterData = [];
        if (!(data&&data.length > 0)) {
            return afterData;
        }
        for (let i = 0; i < data.length; i++) {
            if (tempArr.indexOf(data[i].ordMainID) === -1) {
                afterData.push({
                    ordMainID: data[i].ordMainID,
                    children: [data[i]]
                });
                tempArr.push(data[i].ordMainID);
            } else {
                for (let j = 0; j < afterData.length; j++) {
                    if (afterData[j].ordMainID == data[i].ordMainID) {
                        afterData[j].children.push(data[i]);
                        break;
                    }
                }
            }
        }
        // console.log(afterData);
        return afterData;
    }

    // 发药公共方法
    dispensingCommon = (rowData, usageData, selectedRows, type, index) => {

        let {pharmacistValue, fyFlag, tableData,mode, startDate, endDate, patID} = this.state;
        let arr = JSON.parse(JSON.stringify(selectedRows)).map(item => {
            return {
                dspID: item.dspID
            }
        })
        let ordInfo = usageData&&usageData.length > 0&&usageData.map(item => {
            return {
                ordID: item.ordID,
                dspInfo: arr
            }
        });

        let data = {
            params: [
                {
                    id: rowData.id, // 发药表ID
                    ordPrescNo: rowData.ordPrescNo, // 处方号
                    PDFlag: fyFlag, // 部分发药标志
                    prepUserID: pharmacistValue, // 配药师
                    ordInfo: ordInfo, // 医嘱记录
                    orderID: rowData.ordID,
                    resFlag: false,
                    detail: [{
                        recLocID: this.state.userData.locID, // 科室ID
                        ward: [{
                            wardID:this.state.rowData.wardID ? this.state.rowData.wardID :'',
                            dispCat:this.state.rowData.medArr? this.state.rowData.medArr: []
                        }], // 病区
                    }],
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030090",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    if (type === "all") {
                        if (tableData.length-1 === index) {
                            message.success('一键发药成功');
                        }
                    } else {
                        message.success('发药成功');
                        this.handleFYClick("fy-list");
                    }
                    this.modifyDispStatus(rowData);
                    this.getMedicationWaitingQueue();
                    this.getTableData(mode, startDate, endDate, fyFlag, patID)
                }
            },
            error: function (error) {
                message.error(error);
            }
        })
    }

    // 发药
    handleDispensing = () => {
        let {rowData, usageData, selectedRows} = this.state;
        this.dispensingCommon(rowData, usageData, selectedRows, "noneAll")
    }

    getDetailInformationAll = (record, i) => {
        let {selectedRows} = this.state;
        let data = {
            params: [
                {
                    dispID: record.dispID ? record.dispID : '', // 发药表ID
                    ordPrescNo: record.ordPrescNo ? record.ordPrescNo : '', // 处方号
                }
            ]
        }
        $http.post('urlS', this, {
            code: "02030113",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let detailInfo = res.result[0] ? JSON.parse(JSON.stringify(res.result[0].detailInfo)) : [];
                    let usageData = detailInfo&&detailInfo.length > 0 ? JSON.parse(JSON.stringify(detailInfo[0].rows)) : [];
                    for (var i = 0; i < usageData.length; i++) {
                        usageData[i].visible = false;
                        usageData[i].filterDd = usageData[i].ordQty;
                        // usageData[i].dspInfo = this.filterDspInfo(usageData[i].dspInfo)
                    }
                    this.dispensingCommon(record, usageData, selectedRows, "all", i)
                }
            }
        })
    }

    // 全发
    handleFullDose = () => {
        let {tableData} = this.state;
        for(var i = 0; i < tableData.length; i++) {
            if (tableData[i].ordPrescNo) {
                this.getDetailInformationAll(tableData[i], i)
            }
        }
    }

    handleDFYOnKeydown = (e) => {
        var e = window.event || e;
        let id = '';
        let obj = {};
        let scroll_height = 32;
        let oneArr = this.state.detailData && this.state.detailData.length > 0 ? this.state.detailData : [];
        switch (e.keyCode) {
            case 38: //上
                if (this.state.LTrowId) {
                    for (var i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].key === this.state.LTrowId) {
                            id = i > 0 ? oneArr[i - 1].key : oneArr[0].key;
                            obj = i > 0 ? oneArr[i - 1] : oneArr[0];
                            break;
                        }
                    }
                    this.setState({ LTrowId: id, LTpatID: obj.patID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: [] }, () => {
                        this.refreshTableData();
                    })
                    setTimeout(() => {
                        var gundong = document.querySelector("#dfy-list .ant-table-body");
                        gundong.scrollTop = gundong.scrollTop - scroll_height;
                    }, 100)
                } else {
                    this.setState({ LTrowId: oneArr[0].key, LTpatID: oneArr[0].patID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: [] }, () => {
                        this.refreshTableData();
                    })
                }
                break;
            case 39: //  右
                if (this.state.tableData&&this.state.tableData.length > 0) {
                    this.handleFYClick("fy-list")
                    this.setState({rowId: this.state.tableData[0].key, rowData: this.state.tableData[0]}, () => {
                        this.getDetailInformation(this.state.rowData)
                    })
                }
                break;
            case 40: //下
                if (this.state.LTrowId) {
                    for (let i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].key === this.state.LTrowId) {
                            id = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1].key : oneArr[i + 1].key;
                            obj = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1] : oneArr[i + 1];
                            break;
                        }
                    }
                    this.setState({ LTrowId: id, LTpatID: obj.patID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: [] }, () => {
                        this.refreshTableData();
                    })
                    setTimeout(() => {
                        var gundong = document.querySelector("#dfy-list .ant-table-body");
                        gundong.scrollTop = gundong.scrollTop + scroll_height;
                    }, 100)
                } else {
                    this.setState({ LTrowId: oneArr[0].key, LTpatID: oneArr[0].patID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: [] }, () => {
                        this.refreshTableData();
                    })
                }
                break;
        }
    }

    handleFYLBOnKeydown = (e) => {
        var e = window.event || e;
        let id = '';
        let obj = {};
        let scroll_height = 32;
        let oneArr = this.state.tableData && this.state.tableData.length > 0 ? this.state.tableData : [];
        switch (e.keyCode) {
            case 13: //  回车发药
                this.handleDispensing();
                break;
            case 37: //  左
                if (this.state.detailData&&this.state.detailData.length > 0) {
                    this.handleFYClick("dfy-list")
                    this.setState({ LTrowId: this.state.LTrowId, LTpatID: this.state.LTpatID, page: 1, rowId: '', rowData: {}, mainInfo: [], usageData: [] })
                }
                break;
            case 38: //上
                if (this.state.rowId) {
                    for (var i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].key === this.state.rowId) {
                            id = i > 0 ? oneArr[i - 1].key : oneArr[0].key;
                            obj = i > 0 ? oneArr[i - 1] : oneArr[0];
                            break;
                        }
                    }
                    this.setState({rowId: id, rowData: obj}, () => {
                        this.getDetailInformation(this.state.rowData)
                    })
                    setTimeout(() => {
                        var gundong = document.querySelector("#fy-list .ant-table-body");
                        gundong.scrollTop = gundong.scrollTop - scroll_height;
                    }, 100)
                } else {
                    this.setState({rowId: oneArr[0].key, rowData: oneArr[0]}, () => {
                        this.getDetailInformation(this.state.rowData)
                    })
                }
                break;
            case 40: //下
                if (this.state.rowId) {
                    for (let i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].key === this.state.rowId) {
                            id = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1].key : oneArr[i + 1].key;
                            obj = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1] : oneArr[i + 1];
                            break;
                        }
                    }
                    this.setState({rowId: id, rowData: obj}, () => {
                        this.getDetailInformation(this.state.rowData)
                    })
                    setTimeout(() => {
                        var gundong = document.querySelector("#fy-list .ant-table-body");
                        // console.log(gundong)
                        gundong.scrollTop = gundong.scrollTop + scroll_height;
                    }, 100)
                } else {
                    this.setState({rowId: oneArr[0].key, rowData: oneArr[0]}, () => {
                        this.getDetailInformation(this.state.rowData)
                    })
                }
                break;
        }
    }

    handleFYClick = (id) => {
        let dom = document.getElementById(id);
        dom.focus();
    }

    render() {
        let {
            tableData, total, page, basicHeight, windowDomData, fyFlag, startDate, endDate, patNo, mainInfo, usageData, PharmacistSelectData,
            rowId, rowData, windowVisible, pharmacistVisible, dispensingChecked, usageTableData, statusSelectData, selectedRowKeys, selectedRows, detailData,
            pharmacistValue, radioWindowData, loading, detailWidthTotal, detailColumns, columns, widthTotal, userData
        } = this.state;
        let mainInfoObj = mainInfo&&mainInfo.length > 0 ? mainInfo[0] : {};
        const { getFieldDecorator } = this.props.form;
        const rowSelection = {
            selectedRowKeys,
            selectedRows,
            onChange: (selectedRowKeys, selectedRows) => {
                this.setState({selectedRowKeys, selectedRows})
            },
        };
        // 组件所需参数
        const param = {
            // 表头配置
            columns: columns&&columns.length > 0 ? columns : this.columns,
            // 表格数据
            data: tableData,
            // 数据总条数
            total: total,
            // 当前页数
            page: page,
            pageSize: "20",
            // 表格的宽度
            x: columns&&columns.length > 0 ? widthTotal : 500,
            y: store.getState().tableHeight.y + 51 - basicHeight,
            height: store.getState().tableHeight.y + 96 - basicHeight + 'px',
            isOnRow: true,
            rowClassName: true,
            loading,

        };
        let colTop = {
            xs: {span: 12},
            sm: {span: 12},
            md: {span: 10},
            lg: {span: 10},
            xl: {span: 10},
            xxl: {span: 10}
        };
        let colBottom = {
            xs: {span: 12},
            sm: {span: 12},
            md: {span: 14},
            lg: {span: 14},
            xl: {span: 14},
            xxl: {span: 14}
        }
        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.dispWinDesc}</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={this.setMessage("DrugDistributionsomeone", "descripts", "有人")} unCheckedChildren={this.setMessage("DrugDistributionnobody", "descripts", "无人")} checked={item.statusID === 'O' ? true : false} onChange={(e) => this.handleSwitch(item, e)} />
                        </Row>
                    </div>
                )
            })
        )
        let medicalAdviceDom = (
            <div>
                <div style={{borderBottom: '1px solid #ccc'}}>
                    <h1 style={{textAlign: 'center', position: 'relative', fontSize: '24px', marginBottom: '24px'}}>
                        {mainInfoObj.hospName ? mainInfoObj.hospName : userData&&userData.hospDesc ? userData.hospDesc : ""}{this.setMessage("DrugDistributionprescriptionNotes", "descripts", "处方笺")}
                        <span style={{position: 'absolute', right: '10px', top: '10px', fontSize: '14px', fontWeight: 100, textAlign: 'right', color:'rgba(153,153,153,1)'}}>
                            <Row>{mainInfoObj.prescType}</Row>
                            <Row>{this.setMessage("DrugDistributionordPrescNo", "descripts", "处方号：")}{mainInfoObj.ordPrescNo}</Row>
                        </span>
                    </h1>
                    <div style={{padding: '0 48px 12px', fontSize: '14px'}}>
                        <Row>
                            <Col span={6}>
                                {this.setMessage("DrugDistributionloc", "descripts", "科室：")}{mainInfoObj.ordLocDesc}
                            </Col>
                            <Col span={6}>
                                {this.setMessage("DrugDistributionpatID", "descripts", "病人ID：")}{mainInfoObj.patNo}
                            </Col>
                            <Col span={6}>
                                {this.setMessage("DrugDistributiondate", "descripts", "日期：")}{mainInfoObj.ordDate}
                            </Col>
                            <Col span={6}>
                                {this.setMessage("DrugDistributioncostCategory", "descripts", "费别：")}{mainInfoObj.admReasonDesc}
                            </Col>
                        </Row>
                        <Row style={{margin: '4px 0'}}>
                            <Col span={6}>
                                {this.setMessage("DrugDistributionpatName", "descripts", "患者：")}{mainInfoObj.patName}
                            </Col>
                            <Col span={6}>
                                {this.setMessage("DrugDistributionpatSexDesc", "descripts", "性别：")}{mainInfoObj.patSexDesc}
                            </Col>
                            <Col span={6}>
                                {this.setMessage("DrugDistributionpatAge", "descripts", "年龄：")}{mainInfoObj.patAge}
                            </Col>
                            <Col span={6}>
                                {this.setMessage("DrugDistributionpatWeight", "descripts", "体重：")}{mainInfoObj.patWeight}
                            </Col>
                        </Row>
                        <Row>
                            {this.setMessage("DrugDistributionadmDiag", "descripts", "诊断：")}{mainInfoObj.admDiag}
                        </Row>
                    </div>
                </div>
                <div
                    style={{
                        borderBottom: '1px solid #ccc', padding: '0 24px',
                        height: store.getState().tableHeight.y - 88 - this.state.basicHeight + 'px', overflow: 'auto'
                    }}
                    className="pr-style prescription-bar"
                >
                    <h1 style={{fontSize: '20px'}}>Rp:</h1>

                        <div className="marginRight">
                        <div>
                            {this.inciseData().map((data, key) => {
                                return (
                                    <Row key={key}>
                                        {data&&data.map((item, index) => {
                                            return (
                                                <Col span={6} key={index} style={{marginBottom: '20px', paddingRight: "8px"}}>
                                                    <span style={{fontWeight: 900}}>
                                                        {item.medDesc}
                                                    </span>
                                                    <span style={{marginLeft: '8px', position: 'relative', display: 'inline-block', fontWeight: 900}}>
                                                        {item.ordQty + item.ordUnitDesc}
                                                        {item.ordCMNote ? <b style={{position: 'absolute', top: '-8px', right: '-30px', fontWeight: 900, fontSize: '12px', color: 'blue'}}>{'(' + item.ordCMNote + ')'}</b> : ''}
                                                    </span>
                                                    <div style={{marginLeft: '10px', fontSize: '12px'}}>
                                                        {item.stkInfo&&item.stkInfo[0]&&item.stkInfo[0].rows.length > 1 ? item.stkInfo[0].rows.map((child, childIndex) => {
                                                            return (
                                                                <div key={childIndex}>
                                                                    {child.stockDesc}
                                                                    <span style={{marginLeft: '8px'}}>{child.qty + child.baseUnitDesc}</span>
                                                                </div>
                                                            )
                                                        }) : ''}
                                                    </div>
                                                </Col>
                                            )
                                        })}
                                    </Row>
                                )
                            })}
                        </div>
                        <div style={{textAlign: 'center', paddingRight: '150px'}}>
                            --------------------------------------------------
                            <span style={{fontWeight: '900'}}>{this.setMessage("DrugDistributionblank", "descripts", "(以下空白)")}</span>
                            --------------------------------------------------
                        </div>
                        <Row style={{fontWeight: '900', }}>
                            {this.setMessage("DrugDistributionusage", "descripts", "用法：")}{mainInfoObj.cmFreqDesc + '，' + mainInfoObj.cmExplainDesc + '，' + mainInfoObj.cmUsageDesc}
                            <span style={{margin: '0 15px'}}>{this.setMessage("DrugDistributiontotal", "descripts", "共：") + mainInfoObj.cmFac + this.setMessage("DrugDistributiondoses", "descripts", "剂")}</span>
                            {mainInfoObj.cmCookTypeDesc}
                        </Row>
                    </div>
                </div>
                <div style={{padding: '12px'}}>
                    <Row style={{marginBottom: '4px'}}>
                        <Col span={8}>
                            <Row>
                                <Col {...colTop} className="alignRight">{this.setMessage("DrugDistributiondoctorSignName", "descripts", "医生签名：")}</Col>
                                <Col {...colBottom}>{mainInfoObj.ordDocDesc}</Col>
                            </Row>
                        </Col>
                        <Col span={8}>
                            <Row>
                                <Col {...colTop} className="alignRight">{this.setMessage("DrugDistributioncheck", "descripts", "审核：")}</Col>
                                <Col {...colBottom}>{mainInfoObj.auditUserName}</Col>
                            </Row>
                        </Col>
                        <Col span={8}>
                            <Row>
                                <Col {...colTop} className="alignRight">{this.setMessage("DrugDistributionamount", "descripts", "金额：")}</Col>
                                <Col {...colBottom}>{mainInfoObj.prescAmt}</Col>
                            </Row>
                        </Col>
                    </Row>
                    <Row>
                        <Col span={8}>
                            <Row>
                                <Col {...colTop} className="alignRight">{this.setMessage("DrugDistributionprovisioning", "descripts", "调配：")}</Col>
                                <Col {...colBottom}>{mainInfoObj.prepUserName}</Col>
                            </Row>
                        </Col>
                        <Col span={8}>
                            <Row>
                                <Col {...colTop} className="alignRight">{this.setMessage("DrugDistributionverify", "descripts", "核对：")}</Col>
                                <Col {...colBottom}>{mainInfoObj.printUserName}</Col>
                            </Row>
                        </Col>
                        <Col span={8}>
                            <Row>
                                <Col {...colTop} className="alignRight">{this.setMessage("DrugDistributiondrugDistribution", "descripts", "发药：")}</Col>
                                <Col {...colBottom}>{mainInfoObj.dispUserName}</Col>
                            </Row>
                        </Col>
                    </Row>
                    {/* <p style={{textAlign: 'center', marginTop: '12px', marginBottom: 0}}>本处方当前有效</p> */}
                </div>
            </div>
        )

        // 审核状态
        let auditStatus = statusSelectData && statusSelectData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })
        // 卡类型
        let cardTypeOption = this.state.cardSlectData && this.state.cardSlectData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        let pharmacistSelect = PharmacistSelectData&&PharmacistSelectData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        // 提供给拒绝窗口的行数据
        let modalRowData = {
            statusID: 'Before',
            ...rowData
        }
        // console.log(modalRowData)

        return (
            <div className="dispensing">
                <Row id="outpha-dispensing-basic" style={{padding: '0 24px'}}>
                    <Col span={16} className="input-padding-right">
                        <Row style={{marginBottom: '8px'}}>
                            <Select value={this.state.cardType} onChange={this.handleCardTypeOnChange} showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DrugDistributionperHealthCard", "descripts", "居民健康卡")} style={{width: '150px', margin: '8px 8px 0 0'}}>
                                {cardTypeOption}
                            </Select>
                            <Input value={this.state.cardNo} allowClear onChange={this.handleCardNoChange} onBlur={(e) => this.handleReadCardOnBlur(e, 'blur')} onPressEnter={(e) => this.handleReadCardOnBlur(e, 'enter')} placeholder={this.setMessage("DrugDistributioncardNumTips", "descripts", "请输入卡号(Enter)")} style={{width: '150px', marginTop: '8px', borderRight: '0'}} />
                            <Button style={{marginRight: '12px', background: 'rgba(77,193,130,1)', color: '#fff'}} onClick={this.handleReadCard}>{this.setMessage("DrugDistributionCardReading", "descripts", "读卡")}</Button>
                            <Input
                                title={this.setMessage("DrugDistributionenterToSeachPatID", "descripts", "回车触发病人ID查询")}
                                allowClear
                                placeholder={this.setMessage("DrugDistributionpatId/CardNum", "descripts", "病人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'}}>
                                {this.setMessage("DrugDistributionchargeDate", "descripts", "收费日期：")}<DatePicker value={startDate} onChange={this.handleStartDate} style={{width: '150px', marginTop: '8px'}} placeholder={this.setMessage("DrugDistributionstartDate", "descripts", "开始日期")} />
                                <span style={{display: 'inline-block', margin: '0 5px'}}>{this.setMessage("DrugDistributionto", "descripts", "到")}</span>
                                <DatePicker value={endDate} onChange={this.handleEndDate} style={{width: '150px', marginRight: '8px'}} placeholder={this.setMessage("DrugDistributiondeadline", "descripts", "结束日期")} />
                                <Select value={fyFlag} onChange={this.handlestatusID} showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DrugDistributionstate", "descripts", "状态")} style={{width: '150px', margin: '8px 8px 0 0'}}>
                                    {auditStatus}
                                </Select>
                                <Button style={{marginTop: '8px'}} onClick={this.handleQuery}>{this.setMessage("DrugDistributionsearch", "descripts", "查询")}</Button>
                            </div>
                        </Row>
                    </Col>
                    <Col span={8} style={{textAlign: 'right'}}>
                        <Button
                            type="danger"
                            onClick={this.handlePrintLabel}
                            style={{margin: '8px 8px 0 0', color: !rowId ? '#d9d9d9' : '#1890FF', borderColor: !rowId ? '#d9d9d9' : '#1890FF'}}
                            disabled={!rowId}
                            ghost
                        >{this.setMessage("DrugDistributionprintLabel", "descripts", "打印标签")}</Button>
                        <Button
                            type="danger"
                            onClick={this.handlePrintPresc}
                            style={{margin: '8px 8px 0 0', color: !rowId ? '#d9d9d9' : '#1890FF', borderColor: !rowId ? '#d9d9d9' : '#1890FF'}}
                            disabled={!rowId}
                            ghost
                        >{this.setMessage("DrugDistributionprintPre", "descripts", "打印处方")}</Button>
                        <Button
                            type="danger"
                            onClick={this.handlePrintPYD}
                            style={{margin: '8px 8px 0 0', color: !rowId ? '#d9d9d9' : '#1890FF', borderColor: !rowId ? '#d9d9d9' : '#1890FF'}}
                            disabled={!rowId}
                            ghost
                        >{this.setMessage("DrugDistributionprintPYD", "descripts", "打印配药单")}</Button>
                        <Button
                            type="danger"
                            onClick={() => this.modalChild.showModal(modalRowData, usageData)}
                            style={{margin: '8px 8px 0 0'}}
                            disabled={!rowId || rowData.dispStatus === 'Y' || this.state.authorityStatus}
                            ghost
                        >{this.setMessage("DrugDistributionrefusingToDistribute", "descripts", "拒绝发药")}</Button>
                        <Button
                            type="primary"
                            onClick={this.handleDispensing}
                            style={{margin: '8px 8px 0 0'}}
                            disabled={!rowId || rowData.dispStatus === 'Y'|| this.state.authorityStatus}
                        >{this.setMessage("DrugDistributiondrugDelibery", "descripts", "发药")}</Button>
                        <Button
                            type="primary"
                            onClick={this.handleFullDose}
                            style={{marginTop: '8px'}}
                            disabled={tableData&&tableData.length > 0 ? this.state.authorityStatus ? true : false : true}
                        >一键发药</Button>
                    </Col>
                </Row>
                <div style={{height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%'}}></div>
                <Row>
                    <Col
                        span={4}
                        tabIndex={1}
                        onKeyDown={this.handleDFYOnKeydown}
                        style={{ outline: 'none' }}
                        id="dfy-list"
                    >
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>待发药</div>}
                        >
                            <div style={{height: store.getState().tableHeight.y + 134 - basicHeight + 'px'}}>
                                <Table
                                    columns={this.detailColumns}
                                    dataSource={detailData}
                                    bordered
                                    pagination={false}
                                    scroll={{x: detailColumns&&detailColumns.length > 0 ? detailWidthTotal : '200', y: store.getState().tableHeight.y + 51 - basicHeight}}
                                    onRow={this.onClickRowLeftTable}
                                    rowClassName={this.setRowClassNameLeftTable}
                                    className="table-scroll-height"
                                />
                            </div>
                        </Card>
                    </Col>
                    <Col
                        span={8}
                        tabIndex={1}
                        onKeyDown={this.handleFYLBOnKeydown}
                        style={{ outline: 'none' }}
                        id="fy-list"
                    >
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{this.setMessage("DrugDistributiondistributingDrugList", "descripts", "发药列表")}</div>}
                            className="dispensing-list"
                        >
                            <PubilcTablePagination param={param} handelThis={this} onRef={this.onRef} onClickRowPublic={this.onClickRowPublic} setRowClassNamePublic={this.setRowClassNamePublic} />
                        </Card>
                    </Col>
                    <Col span={12}>
                        <div style={{paddingLeft: '6px', position: 'relative'}}>
                            <Card
                                size="small"
                                title={this.setMessage("DrugDistributionprescriptionNotes", "descripts", "处方笺")}
                                // extra={<a href="#">More</a>}
                                className="catd-head-bg-img prescription"
                            >
                                <div className="prescription-bar" style={{
                                    height: store.getState().tableHeight.y + 158 - basicHeight + 'px',
                                    overflow: 'auto',
                                    background: mainInfoObj&&mainInfoObj.backGroupColor ? mainInfoObj.backGroupColor : '#fff'
                                }}>
                                    <p style={{textAlign: 'center', display: !(mainInfo&&mainInfo.length > 0) ? 'block' : 'none', textDecoration: 'underline'}}>{this.setMessage("DrugDistributionviewPrescriptionFormTips", "descripts", "选择左侧处方来查看处方单")}</p>
                                    <div style={{
                                        width: '100%',
                                        height: '100%',
                                        display: mainInfo&&mainInfo.length > 0 ? 'block' : 'none',
                                    }}>
                                        {medicalAdviceDom}
                                    </div>
                                </div>
                            </Card>
                            <div style={{width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, left: 0, height: '100%'}}></div>
                        </div>
                    </Col>
                </Row>
                <Row style={{height: '40px', lineHeight: '40px'}}>
                    <Col span={6}></Col>
                    <Col span={14}>
                        <span>
                            {this.setMessage("DrugDistributiondirectModel", "descripts", "直接发药模式：")}<Switch checkedChildren="是" unCheckedChildren="否" checked={dispensingChecked} onClick={this.onClickSwitch} />
                        </span>
                    </Col>
                    <Col span={4}></Col>
                </Row>
                <Modal
                    title={<div><div className="modal-title-top"></div>{this.setMessage("DrugDistributionselectPharmacist", "descripts", "选择配药师")}</div>}
                    visible={pharmacistVisible}
                    onOk={this.pharmacistHandleOk}
                    onCancel={() => this.handleCancel("pharmacist")}
                    className="modal-header-line"
                >
                    <div style={{minHeight: '100px'}}>
                        {this.setMessage("DrugDistributionpharmacist", "descripts", "配药师：")}<Select style={{width: '200px'}} showSearch optionFilterProp="seatchprop" allowClear value={pharmacistValue} onChange={this.handlePharmacistValue}>
                        {pharmacistSelect}
                    </Select>
                    </div>
                </Modal>
                <RejectPrescription onRef={this.onModalRef} handleThis={this} modalTitle="拒绝发药" />
                <ReadCard  ref={r => this.readCard = r}/>
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName='DrugDistribution'
                    configType="C"
                    onRef={this.onMainColumnRef}
                    reloadData={this.getMainTableColumns}
                />
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName='OutpatientWaitingList'
                    configType="C"
                    onRef={this.onDetailColumnRef}
                    reloadData={this.getOutpatientWaitingList}
                />
            </div>
        )
    }
};
const DispensingForm = Form.create()(Dispensing);
export default DispensingForm;
