// 门诊发药综合查询
import React from 'react';
import { Row, Col, Card, Button, Form, Select, Input, DatePicker, Table, Icon, Modal, Checkbox, message } from 'antd';
import store from 'store';
import PubilcTablePagination from 'pages/common/PubilcTablePagination.jsx';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import { handleExcel } from 'tools/handleExcel.js';
import { $http } from 'containers/config/https';
import Moment from 'moment';
import './style/outpha.less'
import { $PrintLabel } from './common/Print';

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

class DispensingComprehensiveInquiry extends React.Component {
    constructor() {
        super();
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            userData,
            mainData: [], // 处方列表数据
            total: 0,
            mainPage: 1,
            mainPageSize: 10,
            detailData: [],
            parameterSetting: {}, // 默认参数
            statusSelectData: [], // 状态下拉框数据
            pharmacistSelectData: [], // 配药人/发药人下拉框数据
            searchMedIdData: [], // 医嘱项目下拉框数据
            searchOrdLocData: [], // 开单科室下拉框数据
            cardSlectData: [], // 卡类型下拉框数据
            dispensingWindowSelectData: [], // 发药窗口下拉框数据
            rowId: '', // 选中处方列行id
            visible: false,
            checkMainValue: false,
            checkDetailValue: false,
            defaultValue: '', // 卡类型默认值
            cardHeight: '', // 查询条件的高度
            patID: '', // 根据卡类型卡号查询的病人ID
            columns: [],
            widthTotal: 0,
            detailColumns: [],
            detailWidthTotal: 0,
            columnsVisible: false,
            columnsDetailVisible: false,
            // columnsFlag: 'main',
            cardobj: {}, // 查询病人信息
            loading: false,
            rowData: {},
        };
        this.columns = [
            { title: '当前状态', dataIndex: 'status', key: '1', width: '100px', align: "center" },
            { title: '病人ID', dataIndex: 'patNo', key: '2', width: '100px', align: "center" },
            { title: '病人姓名', dataIndex: 'patName', key: '3', width: '100px', align: "center" },
            { title: '卡号', dataIndex: 'patCardNo', key: '4', width: '100px', align: "center" },
            { title: '联系电话', dataIndex: 'patMobile', key: '5', width: '100px', align: "center" },
            { title: '性别', dataIndex: 'patSexDesc', key: '6', width: '100px', align: "center" },
            { title: '年龄', dataIndex: 'patAge', key: '8', width: '100px', align: "center" },
            { title: '身高', dataIndex: 'patHeight', key: '9', width: '100px', align: "center" },
            { title: '体重', dataIndex: 'patWeight', key: '10', width: '100px', align: "center" },
            { title: '诊断', dataIndex: 'admDiag', key: '11', width: '250px', align: "center" },
            { title: '处方号', dataIndex: 'ordPrescNo', key: '12', width: '150px', align: "center" },
            { title: '处方状态', dataIndex: 'prescStatus', key: '13', width: '100px', align: "center" },
            { title: '草药信息', dataIndex: 'cmInfo', key: '14', width: '150px', align: "center" },
            { title: '配药单号', dataIndex: 'pydNo', key: '15', width: '150px', align: "center" },
            { title: '发药窗口', dataIndex: 'dispWinDesc', key: '16', width: '100px', align: "center" },
            { title: '开单科室', dataIndex: 'ordLocDesc', key: '17', width: '150px', align: "center" },
            { title: '开单日期', dataIndex: 'ordDate', key: '18', width: '100px', align: "center" },
            { title: '开单时间', dataIndex: 'ordTime', key: '19', width: '100px', align: "center" },
            { title: '收费员', dataIndex: 'chargeUserName', key: '20', width: '100px', align: "center" },
            { title: '收费日期', dataIndex: 'chargeDate', key: '21', width: '100px', align: "center" },
            { title: '收费时间', dataIndex: 'chargeTime', key: '22', width: '100px', align: "center" },
            { title: '打印人', dataIndex: 'printUserName', key: '23', width: '100px', align: "center" },
            { title: '打印日期', dataIndex: 'printDate', key: '24', width: '100px', align: "center" },
            { title: '打印时间', dataIndex: 'printTime', key: '25', width: '100px', align: "center" },
            { title: '配药人', dataIndex: 'prepUserName', key: '26', width: '100px', align: "center" },
            { title: '配药日期', dataIndex: 'prepDate', key: '27', width: '100px', align: "center" },
            { title: '配药时间', dataIndex: 'prepTime', key: '28', width: '100px', align: "center" },
            { title: '发药人', dataIndex: 'dispUserName', key: '29', width: '100px', align: "center" },
            { title: '发药日期', dataIndex: 'dispDate', key: '30', width: '100px', align: "center" },
            { title: '发药时间', dataIndex: 'dispTime', key: '31', width: '100px', align: "center" },
            { title: '退药单号', dataIndex: 'retNo', key: '32', width: '100px', align: "center" },
            { title: '退药人', dataIndex: 'retUserName', key: '33', width: '100px', align: "center" },
            { title: '退药日期', dataIndex: 'retDate', key: '34', width: '100px', align: "center" },
            { title: '退药时间', dataIndex: 'retTime', key: '35', width: '100px', align: "center" },
        ];
        this.detailColumns = [
            { title: '药品代码', dataIndex: 'medCode', key: '1', width: '100px', align: "center" },
            { title: '药品名称', dataIndex: 'medDesc', key: '2', width: '250px', align: "center" },
            { title: '规格', dataIndex: 'medSpec', key: '3', width: '100px', align: "center" },
            { title: '医嘱数量', dataIndex: 'ordQty', key: '4', width: '100px', align: "center" },
            { title: '已发药数量', dataIndex: 'dispQty', key: '5', width: '100px', align: "center" },
            { title: '未发药数量', dataIndex: 'lefQty', key: '6', width: '100px', align: "center" },
            { title: '已退药数量', dataIndex: 'retQty', key: '8', width: '100px', align: "center" },
            { title: '剂量', dataIndex: 'ordDoseUnitDesc', key: '7', width: '100px', align: "center" },
            { title: '用法', dataIndex: 'ordUsageDesc', key: '9', width: '100px', align: "center" },
            { title: '频次', dataIndex: 'ordFreqDesc', key: '10', width: '100px', align: "center" },
            { title: '疗程', dataIndex: 'ordDurationDesc', key: '11', width: '100px', align: "center" },
            { title: '医嘱备注', dataIndex: 'ordRemark', key: '12', width: '150px', align: "center" },
            { title: '草药特殊用法', dataIndex: 'ordDecoctMethod', key: '13', width: '200px', align: "center" },
        ];
    }

    componentDidMount() {
        this.initData(); // 初始化数据
        this.handleQuery();
    }

    componentWillUnmount() {
        this.setState = (state, callback) => { return; };
        // window.removeEventListener("keydown", this.handleOnKeydown);
    }

    initData = () => {
        this.getParameterSetting(); // 初始化默认参数
        this.getStatusSelectData();
        this.getPharmacistSelectData();
        this.getCardSelectData();
        this.getDispensingWindowSelectData();
        this.getMainTableColumns();
        this.getDetailTableColumns();
        let height = store.getState().tableHeight.y + 241 - 44 - document.getElementById("card-header").clientHeight + 'px';
        this.setState({ cardHeight: height })
    }

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

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

    // 获取默认参数配置
    getParameterSetting = () => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030056",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({ parameterSetting: res.result[0] })
                }
            }
        })
    }

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

    // 3.2.1.8.2.取状态下拉框数据集
    getStatusSelectData = () => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030053",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({ statusSelectData: res.result })
                }
            }
        })
    }

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

    // 3.2.1.8.8.获取发药窗口信息
    getDispensingWindowSelectData = () => {
        let data = {
            params: []
        }
        $http.post('urlS', this, {
            code: "02030057",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({ dispensingWindowSelectData: res.result })
                }
            }
        })
    }

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

    // 请求列表数据
    getTableData() {
        this.setState({ loading: true });
        let { mainPageSize, mainPage, cardobj } = this.state;
        const { form: { validateFields } } = this.props;
        validateFields((errors, values) => {
            // 验证成功
            if (errors === null) {
                let data = {
                    params: [{ ...values }],
                    pagination: [{
                        pageSize: mainPageSize,
                        currentPage: mainPage,
                        sort: "",
                        dir: "Asc"
                    }]
                }
                data.params[0].startDate = data.params[0].startDate ? Moment(data.params[0].startDate).format('YYYY-MM-DD') : undefined;
                data.params[0].endDate = data.params[0].endDate ? Moment(data.params[0].endDate).format('YYYY-MM-DD') : undefined;
                data.params[0].patID = cardobj && cardobj.patID ? cardobj.patID : '';
                $http.post('urlS', this, {
                    code: "02030054",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            for (var i = 0; i < res.result[0].rows.length; i++) {
                                res.result[0].rows[i].key = i + 1
                            }
                            this.setState({ mainData: res.result[0].rows, total: res.result[0].total, loading: false }, () => {
                                // 数据加载成功关闭loading
                                this.child.handleLoading()
                            })
                        } else {
                            this.setState({ mainData: [], total: 0, loading: false }, () => {
                                // 数据加载成功关闭loading
                                this.child.handleLoading();
                            })
                        }
                    },
                    error: function () {
                        this.setState({ mainData: [], total: 0, loading: false }, () => {
                            // 数据加载成功关闭loading
                            this.child.handleLoading();
                        })
                    }
                })
            }
        })
    }

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

    // 查询处方列表数据
    handleQuery = () => {
        setTimeout(() => {
            this.setState({ mainPage: 1, mainPageSize: 10, rowId: '', detailData: [], rowData: {} }, () => {
                this.getTableData();
            })
        }, 300)
    }

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

    // 选中行操作
    setRowClassNamePublic = (record) => {
        return record.key === this.state.rowId ? 'clickRowStyle' : '';
    }

    // 医嘱项目下拉框数据搜索
    handleMedIDSearch = (value) => {
        if (timeout) {
            clearTimeout(timeout);
            timeout = null;
        }
        timeout = setTimeout(() => {
            if (value) {
                let data = {
                    params: [{
                        alias: value
                    }]
                }
                $http.post('urlS', this, {
                    code: "02020070",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({ searchMedIdData: res.result })
                        }
                    }
                })
            }
        }, 300)
    }

    // 开单科室下拉框数据搜索
    handleOrdLocSearch = (value) => {
        if (timeout2) {
            clearTimeout(timeout2);
            timeout2 = null;
        }
        timeout2 = setTimeout(() => {
            if (value) {
                let data = {
                    params: [{
                        alias: value
                    }]
                }
                $http.post('urlS', this, {
                    code: "02030007",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({ searchOrdLocData: res.result })
                        }
                    }
                })
            }
        }, 300)
    }

    // 获取明细列数据
    getDetailListData = (record) => {
        let data = {
            params: [{
                typeCode: record.typeCode, // 类型Code
                pointerID: record.pointerID, // 业务表ID
                ordPrescNo: record.ordPrescNo, // 处方号
            }]
        }
        $http.post('urlS', this, {
            code: "02030055",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    if (+res.errorCode === 0 && res.result) {
                        for (var i = 0; i < res.result.length; i++) {
                            res.result[i].key = i + 1
                        }
                        this.setState({ detailData: res.result })
                    }
                }
            }
        })
    }

    // 重置
    resetFields = () => {
        this.setState({ detailData: [], rowId: '', rowData: {} }, () => {
            this.props.form.resetFields(); // 重置表单
            this.handleQuery();
        })
    }

    // 确定
    onOk = () => {
        let { checkMainValue, checkDetailValue } = this.state;
        if (checkMainValue && checkDetailValue) {// 同时导出两张表
            this.exportMainTable()
            this.exportDetailTable()
        } else if (checkMainValue) {// 导出库存信息表
            this.exportMainTable()
        } else if (checkDetailValue) {// 导出批次信息表
            this.exportDetailTable()
            this.setState({ visible: false, checkDetailValue: false });
        } else {
            message.info(this.setMessage("DispQueryPrescListSelect_export_table", "descripts", "请选择需要导出的表格"))
        }

    }

    // 关闭弹窗
    onCancel = () => {
        this.setState({ visible: false })
    }

    // 操作库存信息Checkbox
    checkedMain = (e) => {
        this.setState({ checkMainValue: e.target.checked })
    }

    // 操作批次信息Checkbox
    checkedDetails = (e) => {
        this.setState({ checkDetailValue: e.target.checked })
    }

    exportMainTable = () => {
        const { form: { validateFields } } = this.props;
        validateFields((errors, values) => {
            // 验证成功
            if (errors === null) {
                let data = {
                    params: [{ ...values }],
                    pagination: [{
                        pageSize: 1000,
                        currentPage: 1,
                        sort: "",
                        dir: "Asc"
                    }]
                }
                data.params[0].startDate = data.params[0].startDate ? Moment(data.params[0].startDate).format('YYYY-MM-DD') : undefined;
                data.params[0].endDate = data.params[0].endDate ? Moment(data.params[0].endDate).format('YYYY-MM-DD') : undefined;
                $http.post('urlS', this, {
                    code: "02030054",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0 && res.result) {
                            handleExcel.exportExcel(this.columns, res.result[0].rows, '门诊发药综合查询处方表')
                            message.success(res.errorMessage);
                            this.setState({ visible: false, checkMainValue: false, checkDetailValue: false });
                        }
                    }
                })
            }
        })
    }

    exportDetailTable = () => {
        handleExcel.exportExcel(this.detailColumns, this.state.detailData, '门诊发药综合查询明细表')
        message.success(this.setMessage("DispQueryPrescListExport_success", "descripts", "导出明细表成功"));
    }

    handleCardNumCard = (e, type) => {
        if (!e.target.value) {
            this.setState({ cardobj: {} });
            return;
        }
        this.props.form.setFieldsValue({ patID: undefined }, () => {
            this.getPatientInformation('readCard', type)
        })
    }

    // 3.2.1.3.13.根据卡号取病人信息
    getPatientInformation = (flag, type) => {
        let obj = this.props.form.getFieldsValue(['cardNum', 'cardType', 'patID'])
        let data = {
            params: [{
                number: obj.patID, // 病人登记号/证件号
                cardTypeID: flag === 'readCard' ? obj.cardType : undefined, // 卡类型id
                cardNo: obj.cardNum, // 卡号
            }]
        }
        $http.post('urlS', this, {
            code: '03040004',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    flag === "readCard" && res.data && res.data.patCardNo ? this.props.form.setFieldsValue({ cardNum: res.data.patCardNo }) : ''; // 给卡号赋值
                    this.setState({ mainPage: 1, mainPageSize: 10, rowId: '', detailData: [], cardobj: res.data }, () => {
                        if (type === 'enter') {
                            this.getTableData();
                        }
                    })
                } else if (res.errorFlag === 'N') {
                    let obj = {
                        patID: 'aaaaaa'
                    }
                    this.setState({ mainPage: 1, mainPageSize: 10, rowId: '', detailData: [], cardobj: obj, mainData: [], total: 0 })
                    message.error(res.errorMessage)
                }
            }
        })
    }

    // 获取主列表columns
    getMainTableColumns = () => {
        let { userData } = this.state;
        let data = {
            params: [{
                compontName: "DispQueryPrescList",
                reactCode: ['DispQueryPrescList'],
                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.handleCardMain}>{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
                    })
                }
            }
        })
    }

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

    // 获取明系列表头数据
    getDetailTableColumns = () => {
        let { userData } = this.state;
        let data = {
            params: [{
                compontName: "DispQueryPrescDetailList",
                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.handleCardDetail}>{userData.language == 'EN' ? (item && item.enDescripts ? item.enDescripts : item.title) : item.title}</div>
                        }
                    }) : '';
                    let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                    // console.log(filterArr)
                    this.setState({ detailColumns: filterArr, detailWidthTotal: res.totalWidth })
                }
            }
        })
    }

    // 查询病人id
    handlePatient = (e, type) => {
        if (!e.target.value) {
            this.setState({ cardobj: {} });
            return;
        }
        this.props.form.setFieldsValue({ cardNum: undefined, cardType: this.state.defaultValue }, () => {
            this.getPatientInformation('patient', type);
        })
    }

    // 处方列
    handleCardMain = () => {
        this.mainColumnRef.onOpenModel();
    }

    // 明细列
    handleCardDetail = () => {
        this.detailColumnRef.onOpenModel();
    }

    // 开始日期change
    handleStartDataChange = (rule, value, callback) => {
        let endDate = this.props.form.getFieldValue("endDate");
        if (!value) {
            callback(this.setMessage("DispQueryPrescListPlease_ente_start_date", "descripts", "开始日期不能为空"));
        }
        if (Moment(value).format("YYYY-MM-DD") > (Moment(endDate).format("YYYY-MM-DD"))) {
            callback(this.setMessage("DispQueryPrescListNo_greater_than_due_date", "descripts", "不能大于截止日期"));
        }
        // Note: 必须总是返回一个 callback，否则 validateFieldsAndScroll 无法响应
        callback();
    }

    // 结束日期change
    handleEndDataChange = (rule, value, callback) => {
        let startDate = this.props.form.getFieldValue("startDate");
        // console.log(value, startDate)
        if (!value) {
            callback(this.setMessage("DispQueryPrescListDeadline_cannot_be_empty", "descripts", "截止日期不能为空"));
        }
        if (Moment(value).format("YYYY-MM-DD") < (Moment(startDate).format("YYYY-MM-DD"))) {
            callback(this.setMessage("DispQueryPrescListNo_less_than_start_date", "descripts", "不能小于开始日期"));
        }
        // Note: 必须总是返回一个 callback，否则 validateFieldsAndScroll 无法响应
        callback();
    }

    // 卡号onChange
    handleCardNumChange = e => {
        if (!e.target.value) {
            setTimeout(() => {
                this.setState({ cardobj: {} });
            }, 500);
        }
    }

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

    render() {
        let { mainData, total, mainPage, detailData, parameterSetting, statusSelectData, pharmacistSelectData, searchMedIdData, searchOrdLocData,
            visible, checkMainValue, checkDetailValue, defaultValue, cardSlectData, dispensingWindowSelectData, cardHeight, widthTotal, columns,
            detailColumns, detailWidthTotal, loading
        } = this.state;
        const { getFieldDecorator } = this.props.form;
        const formItemInput = {
            labelCol: { span: 8 },
            wrapperCol: { span: 16 }
        };
        // 组件所需参数
        const param = {
            // 表头配置
            columns: columns && columns.length > 0 ? columns : this.columns,
            // 表格数据
            data: mainData,
            // 数据总条数
            total: total,
            // 当前页数
            page: mainPage,
            // 表格的宽度
            x: columns && columns.length > 0 ? widthTotal : 4000,
            y: store.getState().tableHeight.y / 2 - 30,
            height: store.getState().tableHeight.y / 2 + 16 + 'px',
            isOnRow: true,
            rowClassName: true,
            TableClassName: 'th-style',
            loading
        }

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

        // 发药人/配药人
        let pharmacistOption = pharmacistSelectData && pharmacistSelectData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        // 医嘱项目
        let medIDOption = searchMedIdData && searchMedIdData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        // 开单科室
        let ordLocOption = searchOrdLocData && searchOrdLocData.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 dispensingWindowOption = dispensingWindowSelectData && dispensingWindowSelectData.map((item, index) => {
            return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })

        return (
            <div className="didpensing-comprehensiv-inquiry">
                <Row>
                    <Col xs={12} sm={12} md={10} lg={8} xl={6} xxl={4}>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{this.setMessage("DispQueryPrescListOperation_button", "descripts", "操作按钮")}</div>}
                            id="card-header"
                            className="card-footer"
                        >
                            <div style={{ textAlign: 'center' }}>
                                <Button type="primary" onClick={this.handleQuery}>{this.setMessage("DispQueryPrescListQuery", "descripts", "查询")}</Button>
                                <Button onClick={this.resetFields} style={{ margin: '12px 0 0 8px' }}>{this.setMessage("DispQueryPrescListReset", "descripts", "重置")}</Button>
                                <Button onClick={this.handlePrintLabel} style={{ margin: '12px 0 0 8px' }}>{this.setMessage("DispQueryPrescListPrinting", "descripts", "打印")}</Button>
                                <Button onClick={() => this.setState({ visible: true })} type="dashed" style={{ margin: '12px 0 12px 8px' }}>
                                    <Icon type="export" />{this.setMessage("DispQueryPrescListExport", "descripts", "导出")}
                                </Button>
                            </div>
                        </Card>
                        <div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
                        <Card
                            size="small"
                            title={<div className="card-title-left-icon"><div></div>{this.setMessage("DispQueryPrescListQuery_criteria", "descripts", "查询条件")}</div>}
                            style={{ borderBottom: 0 }}
                            className="card-footer"
                        >
                            <div style={{ height: cardHeight, overflow: 'auto', padding: '0 12px' }} className="scroll-bar-style prescription-bar">
                                <Form style={{ paddingTop: '12px' }}>
                                    <Form.Item label={this.setMessage("DispQueryPrescListStart_date", "descripts", "开始日期：")} {...formItemInput}>
                                        {getFieldDecorator('startDate', {
                                            initialValue: parameterSetting && parameterSetting.startDate ? Moment(parameterSetting.startDate) : Moment(),
                                            rules: [{ required: true, validator: this.handleStartDataChange }],
                                        })(
                                            <DatePicker format="YYYY-MM-DD" style={{ width: '100%' }} />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListClosing_date", "descripts", "截止日期：")} {...formItemInput}>
                                        {getFieldDecorator('endDate', {
                                            initialValue: parameterSetting && parameterSetting.endDate ? Moment(parameterSetting.endDate) : Moment(),
                                            rules: [{ required: true, validator: this.handleEndDataChange }],
                                        })(
                                            <DatePicker format="YYYY-MM-DD" style={{ width: '100%' }} />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListOrderItems", "descripts", "医嘱项目：")} {...formItemInput}>
                                        {getFieldDecorator('medID', {
                                            initialValue: undefined
                                        })(
                                            <Select
                                                showSearch
                                                defaultActiveFirstOption={false}
                                                showArrow={false}
                                                filterOption={false}
                                                onSearch={this.handleMedIDSearch}
                                                notFoundContent={null}
                                                placeholder={this.setMessage("DispQueryPrescListOrderItems", "message", "请输入搜索条件")}
                                                allowClear
                                            >
                                                {medIDOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListCard_type", "descripts", "卡类型：")} {...formItemInput}>
                                        {getFieldDecorator('cardType', {
                                            initialValue: defaultValue ? defaultValue : undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {cardTypeOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListCard_number", "descripts", "卡号：")} {...formItemInput}>
                                        {getFieldDecorator('cardNum', {
                                            initialValue: undefined,
                                        })(
                                            <Input placeholder={this.setMessage("DispQueryPrescListCard_number", "message", "请输入卡号(Enter)")} allowClear onChange={this.handleCardNumChange} onPressEnter={(e) => this.handleCardNumCard(e, 'enter')} onBlur={(e) => this.handleCardNumCard(e, 'blur')} />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListPatient_ID", "descripts", "病人ID：")} {...formItemInput}>
                                        {getFieldDecorator('patID', {
                                            initialValue: undefined,
                                        })(
                                            <Input
                                                onChange={this.handleCardNumChange}
                                                allowClear
                                                title={this.setMessage("DispQueryPrescListPatient_ID", "message", "回车触发病人ID查询")}
                                                placeholder={this.setMessage("DispQueryPrescListPICN", "descripts", "病人ID/证件号(Enter)")}
                                                onPressEnter={(e) => this.handlePatient(e, 'enter')}
                                                onBlur={(e) => this.handlePatient(e, 'blur')}
                                            />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListPatient_name", "descripts", "病人姓名：")} {...formItemInput}>
                                        {getFieldDecorator('patName', {
                                            initialValue: undefined,
                                        })(
                                            <Input placeholder={this.setMessage("DispQueryPrescListPlease_input", "descripts", "请输入")} allowClear />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListPrescription_number", "descripts", "处方号：")} {...formItemInput}>
                                        {getFieldDecorator('ordPrescNo', {
                                            initialValue: undefined,
                                        })(
                                            <Input onPressEnter={(e) => this.handleQuery()} placeholder={this.setMessage("DispQueryPrescListPlease_input", "descripts", "请输入(Enter)")} allowClear />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListDispensing_No", "descripts", "配药单号：")} {...formItemInput}>
                                        {getFieldDecorator('pydNo', {
                                            initialValue: undefined,
                                        })(
                                            <Input placeholder={this.setMessage("DispQueryPrescListPlease_input", "descripts", "请输入")} allowClear />
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListStatus", "descripts", "状态：")} {...formItemInput}>
                                        {getFieldDecorator('statusID', {
                                            initialValue: undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {statusOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListDispensing_window", "descripts", "发药窗口：")} {...formItemInput}>
                                        {getFieldDecorator('dispWinID', {
                                            initialValue: undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {dispensingWindowOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListBilling_department", "descripts", "开单科室：")} {...formItemInput}>
                                        {getFieldDecorator('ordLocID', {
                                            initialValue: undefined,
                                        })(
                                            <Select
                                                showSearch
                                                defaultActiveFirstOption={false}
                                                showArrow={false}
                                                filterOption={false}
                                                onSearch={this.handleOrdLocSearch}
                                                notFoundContent={null}
                                                placeholder={this.setMessage("DispQueryPrescListBilling_department", "message", "请输入搜索条件")}
                                                allowClear
                                            >
                                                {ordLocOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListDispenser", "descripts", "配药人：")} {...formItemInput}>
                                        {getFieldDecorator('prepUserID', {
                                            initialValue: undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {pharmacistOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label={this.setMessage("DispQueryPrescListDrug_users", "descripts", "发药人：")} {...formItemInput}>
                                        {getFieldDecorator('dispUserID', {
                                            initialValue: undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {pharmacistOption}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label="管制分类" {...formItemInput}>
                                        {getFieldDecorator('poisonID', {
                                            initialValue: undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {React.$SelectOptions(parameterSetting?.poison || [])}
                                            </Select>
                                        )}
                                    </Form.Item>
                                    <Form.Item label="库存分类" {...formItemInput}>
                                        {getFieldDecorator('stkSubCatID', {
                                            initialValue: undefined,
                                        })(
                                            <Select showSearch optionFilterProp="seatchprop" allowClear placeholder={this.setMessage("DispQueryPrescListPlease_choose", "descripts", "请选择")}>
                                                {React.$SelectOptions(parameterSetting?.stkSubCat || [])}
                                            </Select>
                                        )}
                                    </Form.Item>
                                </Form>
                            </div>
                        </Card>
                    </Col>
                    <Col xs={12} sm={12} md={14} lg={16} xl={18} xxl={20}>
                        <div style={{ paddingLeft: '6px', position: 'relative' }}>
                            <Card
                                size="small"
                                title={<div className="card-title-left-icon"><div></div>{this.setMessage("DispQueryPrescListPrescription_list", "descripts", "处方列表")}</div>}
                                extra={<span style={{ color: '#fff' }} className='span' onClick={this.handleCardMain}><Icon type="setting" title={this.setMessage("DispQueryPrescListColumn_permission_settings", "descripts", "列权限设置")} /></span>}
                            >
                                <PubilcTablePagination
                                    param={param}
                                    handelThis={this}
                                    onRef={this.onRef}
                                    onClickRowPublic={this.onClickRowPublic}
                                    setRowClassNamePublic={this.setRowClassNamePublic}
                                />
                            </Card>
                            <div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)', width: '100%' }}></div>
                            <Card
                                size="small"
                                title={<div className="card-title-left-icon"><div></div>{this.setMessage("DispQueryPrescListList_of_details", "descripts", "明细列表")}</div>}
                                extra={<span style={{ color: '#fff' }} className='span' onClick={this.handleCardDetail}><Icon type="setting" title={this.setMessage("DispQueryPrescListColumn_permission_settings", "descripts", "列权限设置")} /></span>}
                            >
                                <div>
                                    <Table
                                        style={{ height: store.getState().tableHeight.y / 2 + 57 + 'px' }}
                                        columns={detailColumns ? detailColumns : this.detailColumns}
                                        dataSource={detailData}
                                        pagination={false}
                                        bordered
                                        scroll={{ x: detailColumns ? detailWidthTotal : 1600, y: store.getState().tableHeight.y / 2 + 30 }}
                                        className="th-style"
                                    />
                                </div>
                            </Card>
                            <div style={{ width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, left: 0, height: '100%' }}></div>
                        </div>
                    </Col>
                </Row>
                <Modal
                    visible={visible}
                    title={<div><div className="modal-title-top"></div>{this.setMessage("DispQueryPrescListExport_excel_table", "descripts", "导出Excel表格")}</div>}
                    okText={this.setMessage("DispQueryPrescListDetermine", "descripts", "确定")}
                    onCancel={this.onCancel}
                    onOk={this.onOk}
                    className="modal-header-line modal-body-padding"
                >
                    <div style={{ color: '#F5222D', fontSize: '4px', background: '#FFF1F0', height: '32px', lineHeight: '32px', paddingLeft: '24px' }}>
                        <Icon type="exclamation-circle" style={{ marginRight: '4px' }} />{this.setMessage("DispQueryPrescListTEFIOSWTIDITT", "descripts", "当表格存在数据时才支持导出功能。")}
                    </div>
                    <Row style={{ textAlign: 'center', margin: '30px 0' }}>
                        <Col>
                            <Col span={12}>
                                {this.setMessage("DispQueryPrescListTOAPF", "descripts", "导出处方表：")}<Checkbox checked={checkMainValue} onChange={this.checkedMain} disabled={mainData && mainData.length < 1} />
                            </Col>
                            <Col span={12}>
                                {this.setMessage("DispQueryPrescListExport_parts_list", "descripts", "导出明细表：")}<Checkbox checked={checkDetailValue} onChange={this.checkedDetails} disabled={detailData && detailData.length < 1} />
                            </Col>
                        </Col>
                    </Row>
                </Modal>
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName='DispQueryPrescList'
                    configType="C"
                    onRef={this.onMainColumnRef}
                    reloadData={this.getMainTableColumns}
                />
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName='DispQueryPrescDetailList'
                    configType="C"
                    onRef={this.onDetailColumnRef}
                    reloadData={this.getDetailTableColumns}
                />
            </div>
        )
    }
};
const DispensingComprehensiveInquiryForm = Form.create()(DispensingComprehensiveInquiry);
export default DispensingComprehensiveInquiryForm;