/** 
 * Creator:     JYW
 * CreatDate:   2019-04-17
 * descripts：  医嘱详情
*/
import React from 'react'
import { Radio, Checkbox, Col, Button, message, Spin, Table, Input, Select, Tag } from 'antd'
import { $http } from '../../../containers/config/https';
import Sign from './Sign';
import SkinTest from './SkinTest';
import { $loopPrint } from '../../lodop/Common/Print';
import ColumnAuthoritysModel from '../../columnAuthority/ColumnAuthoritysModel';
import { $loadTemplate } from '../../lodop/Common/Print.js';
import { getLodop } from '../../lodop/Common/LodopFuncs.js';

import './CSS/nurseexecute.less';//引入样式

const Option = Select.Option;
class OrderItem extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            allChecked: false,
            ordCheck: [],
            ordCheckTemp: [],
            title: "",
            signVisible: false,
            skinTestVisible: false,
            button: "",
            execCode: "F",
            date: "",
            time: "",
            serviceCode: "",
            okTitle: "计时",
            type: "U",
            oldType: "U",
            startDate: "",
            startTime: "",
            setDate: "",
            setTime: "",
            auditDate: "",
            auditTime: "",
            timeimg: "",
            typeCode: "A",
            timingFlag: false,
            result: false,
            oldResult: false,
            okDisabled: false,
            oldDisabled: false,
            batchNumber: "",
            remainderTime: "",
            execCheck: [],
            ordIDs: [],
            loading: false,
            filterColumn: 'medDesc',    // 默认医嘱名称检索
            filterData: '',
            visible: false,
            clickFlag: false,
            mouseIndex: '-1',
            execLabNoArr: [],
            refuseReason: '',
            iconLoading: false,
            handleOrderBtnStatus: false,
            nurseArr: [],
            execUserID: ''
        }
    }
    componentWillReceiveProps(nextprops) {
        if (nextprops.loading != this.props.loading) {
            this.setState({
                execCheck: [],
                allChecked: false,
                ordCheck: [],
                ordCheckTemp: [],
            })
        }
    }
    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }
    componentDidMount() {
        if (this.props.onOrderItemChild) {
            this.props.onOrderItemChild(this)
        }
        this.getLocUserList()
    }
    getLocUserList = () => {
        let data = {
            params: [{}]
        }
        $http.post('urlDeault', this, {
            code: "02030045",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({nurseArr: res.result})
                } 
            }
        })
    }
    setHandleOrderBtnStatus = (isDisabled) => {
        this.setState({ handleOrderBtnStatus: isDisabled })
    }
    onButtonClick = (button, e) => {
        this.setState({ iconLoading: true })
        setTimeout(() => {
            this.setState({ iconLoading: false });
        }, 2000);
        let ordIDs = [];
        let execCheck = this.state.execCheck;
        let ordCheck = this.state.ordCheck;
        let ordCheckTemp = this.state.ordCheckTemp;
        if ((button.code).indexOf("HandlerOrder") > -1 || (button.code).indexOf("yysPrint") > -1) {
            ordIDs = ordCheck;
            if (ordIDs.length === 0) {
                message.warning("请选择医嘱！");
                return;
            }
        } else {
            ordCheck = ordCheck.concat(ordCheckTemp);
            ordCheck = this.unique5(ordCheck);
            for (var i = 0; i < ordCheck.length; i++) {
                ordIDs = ordIDs.concat(execCheck[ordCheck[i]]);
            }
            if (ordIDs.length === 0) {
                message.warning("请选择执行记录！");
                return;
            }
            if ((button.code).indexOf('printBtn') > -1 || (button.linkMethod).indexOf('printBtn') > -1) {
                this.printSheet(ordIDs);
            }
            if ((button.code).indexOf('InfusionPrint') > -1) {
                this.printPatrolSheet(ordIDs);
            }
        }


        if ((button.code === "skintestBtn") && (this.state.execCheck.length > 1)) {
            message.warning("置皮试请选择一条医嘱！！！");
            return;
        }
        if (button.linkMethod === "skinTestResult") {
            this.skinTestResult(ordIDs, button);
        }
        if (button.linkMethod === "excuteOrHanlderOrd") {
            this.excuteOrHanlderOrd(ordIDs, button);
        }
        if (button.linkMethod === "yysPrint") {
            // ordCheck = ordCheck.concat(ordCheckTemp);
            // ordCheck = this.unique5(ordCheck);
            this.yysPrint(ordIDs);
        }
        if (button.linkMethod === "yysPrintRQ") {
            // ordCheck = ordCheck.concat(ordCheckTemp);
            // ordCheck = this.unique5(ordCheck);
            this.yysPrintRQ(ordIDs);
        }
        if ((button.code === "bottleSign") && (ordIDs.length > 0)) {
            var sortOrdIDs = this.sortOrderIDs(ordIDs);
            this.handlePrintNew(button, sortOrdIDs, 0, this.handlePrintNew);
            // for (let index = 0; index < ordIDs.length; index++) {
            //     this.handlePrint(button, ordIDs[index]);
            // }
        }
        // handlePrintLittleLabel
        if ((button.code === "littleLabel") && (ordCheck.length > 0)) {
            for (let index = 0; index < ordCheck.length; index++) {
                this.handlePrintLittleLabel(button, ordCheck[index])
            }
        }
        if ((button.code === "barcodeBtn") && (ordIDs.length > 0)) {
            for (let index = 0; index < this.state.execLabNoArr.length; index++) {
                if (this.state.execLabNoArr[index] != '') {
                    this.barCodePrint(this.state.execLabNoArr[index])
                } else {
                    error.message('标本号不能为空!')
                }
            }
        }
    }
    sortOrderIDs = (ordIDs) => {
        var sortOrdIDs = [];
        let _this = this;
        this.props.ordData.map((item) => {
            if (_this.findOrdID(ordIDs, item.ordID)) {
                sortOrdIDs.push(item.ordID)
            }
            item.execInfos.map((execItem) => {
                if (_this.findOrdID(ordIDs, execItem.execID)) {
                    sortOrdIDs.push(execItem.execID)
                }
            })
        })
        return sortOrdIDs;
    }
    findOrdID = (ordIDs, orderID) => {
        var find = false;
        ordIDs.map((ordID) => {
            if (orderID == ordID) {
                find = true;
            }
        })
        return find;
    }
    handlePrintNew = (button, ordIDs, i, callback) => {
        let data = {};
        data = {
            params: [{
                printCode: button.code,
                execID: ordIDs[i],
            }]
        }
        // let code = (type === 'BedCard') ? "04140012" : "04140013"
        let templateCode = (button.code === 'bottleSign') ? "BottleSignOP" : 'BarCode';
        if (templateCode == '') { message.error('模板代码为空'); return }
        $http.post('urlS', this, {
            code: '04080010',
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    //加载模板
                    // $loadTemplate(templateCode, res.result);
                    LODOP = getLodop();
                    LODOP.PRINT_INIT(templateCode);     //打印初始化
                    eval(res.templateData);       //执行模板内容
                    eval(res.result);            //执行打印内容
                    i = i + 1;
                    if (i < ordIDs.length) {
                        callback(button, ordIDs, i, callback);
                    }
                }
            }
        })

    }

    // 打印小标签
    handlePrintLittleLabel = (button, execID) => {
        let data = {};
        data = {
            params: [{
                printCode: button.code,
                execID: execID,
            }]
        }
        $http.post('urlS', this, {
            code: '04080015',
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    //加载模板
                    $loadTemplate('LittleLabel', res.result);
                }
            }
        })
    }

    // 打印条码
    barCodePrint = (execLabNo) => {
        let data = {};
        data = {
            params: [{
                execLabNo: execLabNo,
            }]
        }
        $http.post('urlS', this, {
            code: '04080014',
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    //加载模板
                    $loadTemplate('BarCode', res.result);
                }
            }
        })

    }

    //检验条码打印
    handlePrint = (button, execID) => {
        let data = {};
        data = {
            params: [{
                printCode: button.code,
                execID: execID,
            }]
        }
        // let code = (type === 'BedCard') ? "04140012" : "04140013"
        let templateCode = (button.code === 'bottleSign') ? "BottleSignOP" : 'BarCode';
        if (templateCode == '') { message.error('模板代码为空'); return }
        $http.post('urlS', this, {
            code: '04080010',
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    //加载模板
                    $loadTemplate(templateCode, res.result);
                }
            }
        })

    }
    /*
    // 执行单打印
    printExecSheet = (ordIDs) => {
        let sheet = this.state.sheetList[this.state.activeKey];
        let data = {
            params: [{
                ordExeIDs: ordIDs,
                sheetCode: sheet.code,
            }]
        }
        $http.post('urlS', this, {
            code: "04030011",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    const data = res.result
                    LODOP = getLodop();
                    LODOP.PRINT_INIT('门诊执行单');     //打印初始化
                    eval(data);            //执行打印内容
                }
            }
        })
    }
    // 打印
    printBottle = (ordIDs) => {
        let data = {
            params: [{
                ordExeIDs: ordIDs
            }]
        }
        $http.post('urlS', this, {
            code: "04030009",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    const data = res.result
                    if (data.length > 0) {
                        for (let i = 0; i < data.length; i++) {
                            //加载模板
                            $loadTemplate("BottlesignTest", data[i]);
                        }
                    }

                }
            }
        })
    }
    */
    // 打印执行单
    printSheet = (ordIDs) => {
        let data = {
            params: [{
                ordExeIDs: ordIDs,
                sheetCode: this.props.sheet.code
            }]
        }
        $http.post('urlS', this, {
            code: "04030009",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    const data = res.result
                    LODOP = getLodop();
                    LODOP.PRINT_INIT('执行单');     //打印初始化
                    eval(data);            //执行打印内容 
                }
            }
        })
    }
    // 打印巡视单
    printPatrolSheet = (ordIDs) => {
        let data = {
            params: [{
                ordExeIDs: ordIDs,
            }]
        }
        $http.post('urlS', this, {
            code: "04030018",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    const data = res.result
                    LODOP = getLodop();
                    LODOP.PRINT_INIT('巡视单');     //打印初始化
                    eval(data);            //执行打印内容 
                }
            }
        })
    }
    // 打印输液卡
    print = (ordIDs) => {
        let data = {
            params: [{
                ordExeIDs: ordIDs
            }]
        }
        $http.post('urlS', this, {
            code: "04030009",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    const data = res.result
                    if (data.length > 0) {
                        for (let i = 0; i < data.length; i++) {
                            //加载模板
                            $loadTemplate("InfusionCard", data[i]);
                        }
                    }
                }
            }
        })
    }
    skinTestResult = (ordIDs, button) => {
        let data = {
            params: [{
                ordID: ordIDs[0],
            }]
        }
        $http.post('urlDeault', this, {
            code: "04030006",
            data: data,
            success: (res) => {
                let type = "S", okTitle = "计时开始";
                if (button.code === "skinTiming") {
                    type = "S";
                    if (res.data && res.data.result) {
                        message.error("已置皮试结果,不能重新计时!");
                        return;
                    }
                } else {
                    if (res.data === undefined) {
                        message.error("皮试未开始,请先开始");
                        return;
                    }
                    if (res.data.setUserName !== "") {
                        type = "A", okTitle = "复核";
                    } else {
                        type = "U", okTitle = "皮试";
                    }
                }
                let okDisabled = false;
                if ((type === "S") && (res.data !== undefined)) {
                    okDisabled = true;
                }

                this.setState({
                    skinTestVisible: true,
                    button: button,
                    startDate: res.data === undefined ? res.startDate : res.data.startDate,
                    startTime: res.data === undefined ? res.startTime : res.data.startTime,
                    timeimg: res.data === undefined ? "" : res.data.time,
                    setDate: res.data === undefined ? "" : res.data.setDate,
                    setTime: res.data === undefined ? "" : res.data.setTime,
                    batchNumber: res.data === undefined ? "" : res.data.batchNumber,
                    auditDate: res.data === undefined ? "" : res.data.auditDate,
                    auditTime: res.data === undefined ? "" : res.data.auditTime,
                    okDisabled: okDisabled,
                    oldDisabled: okDisabled,
                    result: res.data === undefined ? false : res.data.result === "N" ? false : true,
                    oldResult: res.data === undefined ? false : res.data.result === "N" ? false : true,
                    remainderTime: res.data === undefined ? "" : res.data.remainderTime,
                    title: button.descripts,
                    okTitle: okTitle,
                    ordIDs: ordIDs,
                    serviceCode: button.linkService,
                    type: type,
                    oldType: type,
                })

            }
        })
    }

    // 支持选择日期时间
    excuteOrHanlderOrd = (ordIDs, button) => {
        if (("^" + button.code).indexOf("^Un") > -1) {
            this.setState({
                ordIDs: ordIDs,
                button: button,
                execCode: "CE",
                typeCode: "",
            }, () => {
                this.handleSignOk();
            })
        } else {
            let date = "", time = "";
            let data = {}
            $http.post('urlDeault', this, {
                code: "04030004",
                data: data,
                success: (res) => {
                    if (+res.errorCode === 0) {
                        date = res.date;
                        time = res.time;
                        this.setState({
                            signVisible: true,
                            button: button,
                            ordIDs: ordIDs,
                            date: date,
                            time: time,
                            execCode: "F",
                            typeCode: "A",
                        })
                    }
                }
            })
        }
    }

    yysPrintRQ = (ordIDs) => {
        let data = []
        data = {
            params: [{
                ordExeIDs: ordIDs
            }]
        }
        $http.post('urls', this, {
            code: '04010013',
            data: data,
            success: function (res) {
                window.open(res.result);
            }
        })
    }

    yysPrint = (ordIDs) => {
        let data = []
        data = {
            params: [{
                ordExeIDs: ordIDs
            }]
        }
        $http.post('urls', this, {
            code: '04160030',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    $loopPrint('', res.result);
                } else {
                    message.error(res.errorMessage);
                }
            }
        })

    }
    //隐藏弹出框
    onModalClose(name) {
        this.setState({
            [name]: false
        });
    }
    handleSignOk = () => {
        let user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        let userID=this.state.execUserID ? this.state.execUserID : user.userID
        let data = {
            params: [{
                ordIDs: this.state.ordIDs,
                date: this.state.date,
                time: this.state.time,
                userID: userID,
                type: this.state.typeCode,
                code: this.state.execCode,
                locID: user.locID,
                refuseReason: this.state.refuseReason
            }]
        }
        $http.post('urlDeault', this, {
            code: this.state.button.linkService,
            data: data,
            success: (res) => {
                this.setState({ signVisible: false });
                if (+res.errorCode !== 0) {
                    // message.error(this.state.button.descripts + "失败:" + res.errorMessage);
                } else {
                    if (res.errorArr.length !== 0) {
                        message.success(res.errorArr.join(","));
                    } else {
                        message.success(this.state.button.descripts + "成功！");
                    }
                    if (this.props.patListRef) {
                        this.props.patListRef.getPatients()
                    }
                    this.props.getPatientOrd("", "");
                }
            }
        })

    }
    handleSkinTestOk = () => {
        let user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        let data = {
            params: [{
                type: this.state.type,
                userID: user.userID,
                ordID: this.state.ordIDs[0],
                startDate: this.state.startDate,
                startTime: this.state.startTime,
                setDate: this.state.setDate,
                setTime: this.state.setTime,
                auditDate: this.state.auditDate,
                auditTime: this.state.auditTime,
                timeimg: this.state.timeimg,
                result: this.state.result ? "Y" : "N",
                batchNumber: this.state.batchNumber,
            }]
        }
        $http.post('urlDeault', this, {
            code: this.state.serviceCode,
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        skinTestVisible: false,
                    })
                    message.success(this.state.okTitle + "成功！");
                    this.props.getPatientOrd("", "");
                }
            }
        })

    }

    handleDateTimeChange = (flag, time, datetimeString) => {
        this.setState({ [flag]: datetimeString });
    }
    onSelectChange = (flag, value) => {
        this.setState({ [flag]: value });
    }
    onInputChange = (flag, e) => {
        this.setState({ [flag]: e.target.value, });
    }
    onSwitchChange = (flag, checked, e) => {
        let okDisabled = false;
        if (flag === "timingFlag") {

            if (checked) {
                // if (this.state.setDate !== "") {
                //     message.error("已置皮试结果,不能重新计时!");
                //     return;
                // }
                okDisabled = false;
            } else {
                if (this.state.oldDisabled) {
                    okDisabled = true;
                }
            }
        }
        let type = this.state.type;
        if (flag === "result") {
            if (this.state.oldResult !== checked) {
                type = "U";
            } else {
                type = this.state.oldType;
            }
        }
        let okTitle = this.state.okTitle;
        if (type === "A") {
            okTitle = "复核";
        } else {
            okTitle = "皮试";
        }
        this.setState({ [flag]: checked, okDisabled: okDisabled, type: type, okTitle: okTitle })
    }

    onCheckDetailChange = (orderItem, execID, e) => {
        const checked = e.target.checked
        let ordCheck = this.state.ordCheck;
        let execCheck = this.state.execCheck;
        let ordCheckTemp = this.state.ordCheckTemp;
        const ordID = orderItem.ordID;
        ordCheckTemp.push(ordID);
        ordCheckTemp = this.unique5(ordCheckTemp);
        if (execCheck[ordID] === undefined) {
            execCheck[ordID] = [];
        }
        if (checked) {
            execCheck[ordID].push(execID);
            execCheck[ordID] = this.unique5(execCheck[ordID]);
            if (execCheck[ordID].length === orderItem.execInfos.length) {
                ordCheck.push(ordID)
                ordCheck = this.unique5(ordCheck);
                if (ordCheck.length == this.props.ordData.length) {
                    this.setState({ allChecked: true, ordCheck: ordCheck, execCheck: execCheck, ordCheckTemp: ordCheckTemp })
                } else {
                    this.setState({ ordCheck: ordCheck, execCheck: execCheck, ordCheckTemp: ordCheckTemp })
                }

            } else {

                this.setState({ execCheck: execCheck, ordCheckTemp: ordCheckTemp })
            }

        } else {
            let findFlag = false;
            let start = 0;
            execCheck[ordID].find(function (value, key) {
                if (value === execID) {
                    //遍历找到选中的数据，并记录下选中数据在数组中的key
                    findFlag = true;
                    start = key;
                }
            })
            execCheck[ordID].splice(start, 1);
            if (ordCheck.join("^").indexOf(ordID) > -1) {

                findFlag = false, start = 0;
                ordCheck.find(function (value, key) {
                    if (value === ordID) {
                        //遍历找到选中的数据，并记录下选中数据在数组中的key
                        findFlag = true;
                        start = key;
                    }
                })
                ordCheck.splice(start, 1);
                this.setState({ allChecked: false, ordCheck: ordCheck, execCheck: execCheck, ordCheckTemp: ordCheckTemp })
            } else {
                this.setState({ execCheck: execCheck, ordCheckTemp: ordCheckTemp })
            }


        }
    }
    //点击医嘱时触发
    onClickOrderChange = (ordItem, e) => {
        e.stopPropagation();
        let orderLength = 0;
        let orderID = e.target.id;
        if ((orderID != undefined) && (orderID != "")) {
            orderLength = orderID.split("||").length;
        }
        if (orderLength != 3) {

            let execCheck = this.state.execCheck;
            let orderCheck = this.state.ordCheck;
            let execLabNoArr = this.state.execLabNoArr;
            let start = "-1";
            orderCheck.find(function (value, key) {
                if (value === ordItem.ordID) {
                    start = key;
                }
            })
            if (start != "-1") {
                execCheck[ordItem.ordID] = [];
                orderCheck.splice(start, 1);
                execLabNoArr.splice(start, 1);
            } else {
                let arr = [];
                if (ordItem.execInfos != undefined) {
                    arr = ordItem.execInfos.map(item => item.execID)
                }
                execCheck[ordItem.ordID] = arr;
                orderCheck.push(ordItem.ordID);
                execLabNoArr.push(ordItem.execLabNo);
            }
            this.setState({ execCheck: execCheck, ordCheck: orderCheck, clickFlag: true, execLabNoArr });
        }
    }
    //勾选医嘱时触发
    onCheckOrderChange = (ordItem, e) => {
        // if (this.state.clickFlag) {
        //     this.setState({ clickFlag: false })
        //     return
        // }
        // e.stopPropagation();
        // let execCheck = this.state.execCheck;
        // let orderCheck = this.state.ordCheck;
        // if (e.target.checked) {
        //     let arr = [];
        //     if (ordItem.execInfos != undefined) {
        //         arr = ordItem.execInfos.map(item => item.execID)
        //     }
        //     execCheck[ordItem.ordID] = arr;
        //     orderCheck.push(ordItem.ordID);
        // } else {
        //     execCheck[ordItem.ordID] = [];
        //     let start = -1;
        //     orderCheck.find(function (value, key) {
        //         if (value === ordItem.ordID) {
        //             start = key;
        //         }
        //     })
        //     orderCheck.splice(start, 1);
        // }

        // this.setState({ execCheck: execCheck, ordCheck: orderCheck });
    }
    /** 去重*/
    unique5(arr) {
        var x = new Set(arr);
        return [...x];
    }
    onChange = (ordCheck) => {
        this.setState({ ordCheck, allChecked: ordCheck.length == this.props.ordData.length })
    }
    handleCheckAll = (checked) => {
        console.log("handleCheckAll", checked)
        // const checked = checked
        let execCheck = this.getDetailArr(this.props.ordData);
        let ordData = this.props.ordData;
        var ordChecker = [];
        let execLabNoArr = [];
        if (checked) {
            for (var i = 0; i < ordData.length; i++) {
                ordChecker.push(ordData[i].ordID);
                execLabNoArr.push(ordData[i].execLabNo);
            }
            this.setState({ allChecked: checked, ordCheck: ordChecker, execCheck: execCheck, execLabNoArr })
        } else {
            this.setState({ allChecked: checked, ordCheck: [], execCheck: [], execLabNoArr })
        }

    }
    getDetailArr = (mapData) => {
        let detail = [];
        for (var i = 0; i < mapData.length; i++) {
            let item = mapData[i]
            if (item.execInfos !== undefined) {
                let arr = [];
                for (var j = 0; j < item.execInfos.length; j++) {
                    arr.push(item.execInfos[j].execID)
                }
                detail[item.ordID] = arr
            }
        }
        // mapData.map((item) => {
        //     if (item.execInfos !== undefined) {
        //         let arr = [];
        //         item.execInfos.map((detail) => {
        //             arr.push(detail.ordID)
        //         });
        //         detail[item.ordID] = arr
        //     }

        // });
        return detail
    }
    onScroll = (e) => {
        //当医嘱数据左右滚动时标题跟随滚动
        const scrollLeft = document.getElementById('OrderTable').scrollLeft;
        document.getElementById('title').scrollLeft = scrollLeft;
    }
    onMouseEnter = (code, order, e) => {
        if (code === "medDesc") {
            // message.success("医嘱详情");
        } else {
            return;
        }
    }
    ///选择筛选条件
    onFilterChange = (value) => {
        this.setState({ filterColumn: value });
    }
    //填写筛选数据回车
    onFilterEnter = (e) => {
        if (this.state.filterColumn === '') {
            message.warn("请先选择筛选列");
            return;
        }
        this.setState({ filterData: e.target.value });
    }
    onFilterInputChage = (e) => {
        if (e.target.value === "") {
            this.setState({ filterData: e.target.value });
        }
    }
    onCheckGroupChange = () => {

    }
    //鼠标移入
    onMouseEnterTr = (mouseIndex) => {
        this.setState({
            mouseIndex: mouseIndex,
        })
    }
    //鼠标移出
    onMouseOverTr = () => {
        this.setState({
            mouseIndex: '-1',
        })
    }

    // 返回执行记录区域数据
    renderExecInfo = (columns, orderItem, text) => {
        if (columns.dataIndex == "dayNum") {
            return (
                orderItem.execInfos === undefined ? "" : (orderItem.execInfos.map(
                    (execInfo, ordExecIndex) => {

                        return (
                            <Checkbox.Group
                                value={this.state.execCheck[orderItem.ordID]}
                                key={ordExecIndex}
                            >
                                <Checkbox
                                    value={execInfo.execID}
                                    key={ordExecIndex}
                                    id={execInfo.execID}
                                    onChange={this.onCheckDetailChange.bind(this, orderItem, execInfo.execID)}
                                >
                                    <span id={execInfo.execID} title={execInfo.title} style={{ padding: '0' }}>
                                        {
                                            execInfo.execSttTime
                                        }
                                    </span>
                                </Checkbox>
                            </Checkbox.Group>
                        )
                    }))
            )
        }
        if (columns.dataIndex == "part" && orderItem.part == '') {
            return (
                orderItem.execInfos === undefined ? "" : (orderItem.execInfos.map(
                    (execInfo, ordExecIndex) => {
                        return (
                            <div>{execInfo.part}</div>
                        )
                    }))
            )
        }
        return text;
    }
    render() {
        let table = [];
        const filterColumn = [];
        table.push(
            <div
                key="title"
                id="title" style={{ overflowX: 'hidden', overflowY: 'scroll' }}>
                <div
                    style={{ width: (this.props.sheet.columnInfo.x + 120) + "px" }}
                >
                    <table key="titleT" border='1' style={{ border: '1px solid #cccccc' }} className="orderTitle">
                        <thead>
                            <tr className="orderTitletr" >
                                <th
                                    key="check"
                                    className="ant-table-align-center ant-table-row-cell-break-word"
                                    style={{ width: "26px" }}>
                                    <Checkbox
                                        indeterminate={(this.state.ordCheck.length !== this.props.ordData.length) && (this.state.ordCheck.length > 0)
                                        }
                                        onChange={(e) => this.handleCheckAll(e.target.checked)}
                                        checked={(this.state.ordCheck.length == this.props.ordData.length) && (this.state.ordCheck.length > 0)}
                                    ></Checkbox>

                                </th>
                                {
                                    this.props.sheet.columnInfo.column.map(
                                        (columns) => {
                                            filterColumn.push(
                                                <Option key={columns.dataIndex} value={columns.dataIndex} >
                                                    {columns.title}
                                                </Option>
                                            );
                                            return (
                                                <th key={columns.dataIndex} style={{ width: columns.width, textAlign: columns.align }}>
                                                    {columns.title}
                                                </th>
                                            )
                                        })
                                }
                                <th key="ordID" style={{ width: "100px", textAlign: "center" }} className="ant-table-align-center ant-table-row-cell-break-word">
                                    ordID
                                </th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div >
        );
        const filterData = this.state.filterData;
        const filterC = this.state.filterColumn;
        let tableItem = [];
        this.props.ordData.map(
            (orderItem, patIndex) => {
                let flag = 1;
                if (filterData !== '') {
                    if ((orderItem[filterC]) && (orderItem[filterC].indexOf(filterData) < 0)) {
                        flag = 0;
                        if (filterC === 'medDesc' && orderItem.medAlias && orderItem.medAlias.indexOf(filterData.toUpperCase()) > -1) {
                            flag = 1;
                        }
                    }
                }
                if (flag === 0) return;
                tableItem.push(

                    <tr
                        key={orderItem.ordID}
                        className="orderItemtr"
                        onClick={this.onClickOrderChange.bind(this, orderItem)}
                        onMouseEnter={this.onMouseEnterTr.bind(this, patIndex)}
                    >
                        {
                            <td
                                rowSpan={orderItem.children.length + 1}
                                style={{ width: "26px" }}
                                className="ant-table-row-cell-break-word"
                            >
                                <Checkbox
                                    value={orderItem.ordID}
                                    indeterminate={(this.state.execCheck[orderItem.ordID] !== undefined)
                                        && (this.state.execCheck[orderItem.ordID].length !== orderItem.execInfos.length)
                                        && (orderItem.execInfos.length !== 0) && (this.state.execCheck[orderItem.ordID].length !== 0)
                                    }
                                    onChange={this.onCheckOrderChange.bind(this, orderItem)}
                                ></Checkbox>
                            </td>
                        }
                        {
                            this.props.sheet.columnInfo.column.map(
                                (columns) => {
                                    let group = "";
                                    if (orderItem.children.length != 0) {
                                        group = "┎"
                                    }
                                    let text = orderItem[columns.dataIndex] || '';
                                    if (columns.dataIndex == "group") {
                                        text = group;
                                    }
                                    return (
                                        <td
                                            rowSpan={columns.childrenVisible === "N" ? orderItem.children.length + 1 : 1}
                                            key={columns.dataIndex}
                                            className={[this.state.mouseIndex == patIndex ? 'orderItemtrMouseIn' : columns.dataIndex === 'medDesc' ? orderItem['disposeCode'] : '', 'ant-table-row-cell-break-word'].join(' ')}
                                            style={{
                                                width: columns.width, textAlign: columns.align,
                                                fontSize: columns.dataIndex == "group" ? '20px' : '',
                                                color: columns.dataIndex == "group" ? '#0000ff' : (columns.dataIndex == "ordPriorityDesc" && orderItem["ordPriorityCode"] == 'NORM') ? '#722ed1' : '',
                                            }}
                                            onMouseEnter={this.onMouseEnter.bind(this, columns.dataIndex, orderItem)}
                                        >

                                            {
                                                this.renderExecInfo(columns, orderItem, text)
                                                // columns.dataIndex !== "dayNum" ? text : (
                                                //     orderItem.execInfos === undefined ? "" : (orderItem.execInfos.map(
                                                //         (execInfo, ordExecIndex) => {

                                                //             return (
                                                //                 <Checkbox.Group
                                                //                     value={this.state.execCheck[orderItem.ordID]}
                                                //                     key={ordExecIndex}
                                                //                 >
                                                //                     <Checkbox
                                                //                         value={execInfo.execID}
                                                //                         key={ordExecIndex}
                                                //                         id={execInfo.execID}
                                                //                         onChange={this.onCheckDetailChange.bind(this, orderItem, execInfo.execID)}
                                                //                     >
                                                //                         <span id={execInfo.execID} title={execInfo.title} style={{ padding: '0' }}>
                                                //                             {
                                                //                                 execInfo.execSttTime
                                                //                             }
                                                //                         </span>
                                                //                     </Checkbox>
                                                //                 </Checkbox.Group>
                                                //             )
                                                //         })))
                                            }

                                        </td>
                                    )

                                }
                            )
                        }
                        <td
                            rowSpan={1}
                            key="ordID"
                            style={{ width: "100px", textAlign: "center" }}
                            className="ant-table-row-cell-break-word"
                            onMouseEnter={this.onMouseEnter.bind(this, "ordID", orderItem)}
                        >
                            {orderItem.ordID}
                        </td>
                    </tr>

                )
                {
                    orderItem.children.map(
                        (children, childIndex) => {
                            tableItem.push(
                                <tr
                                    key={children.execID}
                                    className="orderItemtr"
                                    onClick={this.onClickOrderChange.bind(this, orderItem)}
                                    onMouseEnter={this.onMouseEnterTr.bind(this, patIndex)}
                                >
                                    {
                                        this.props.sheet.columnInfo.column.map(
                                            (columns) => {
                                                let group = "┃";
                                                if (childIndex == (orderItem.children.length - 1)) {
                                                    group = "┖"
                                                }
                                                let text = children[columns.dataIndex] || '';
                                                if (columns.dataIndex == "group") {
                                                    text = group;
                                                }
                                                if (columns.childrenVisible === "Y") {
                                                    return (
                                                        <td key={columns.dataIndex}
                                                            className={[columns.dataIndex === 'medDesc' ? orderItem['disposeCode'] : this.state.mouseIndex == patIndex ? 'orderItemtrMouseIn' : '', 'ant-table-row-cell-break-word'].join(' ')}
                                                            style={{
                                                                width: columns.width, textAlign: columns.align,
                                                                fontSize: columns.dataIndex == "group" ? '20px' : '',
                                                                color: columns.dataIndex == "group" ? '#0000ff' : '',
                                                            }}
                                                            onMouseEnter={this.onMouseEnter.bind(this, columns.dataIndex, children)}
                                                        >
                                                            {text}
                                                        </td>
                                                    )
                                                }
                                            }
                                        )
                                    }
                                    <td
                                        rowSpan={1}
                                        key="ordID"
                                        style={{ width: "100px", textAlign: "center" }}
                                        className="ant-table-row-cell-break-word"
                                        onMouseEnter={this.onMouseEnter.bind(this, "ordID", children)}
                                    >
                                        {children.ordID}
                                    </td>
                                </tr>)
                        }

                    )
                }

            }
        )
        table.push(
            <div
                key="OrderTable"
                style={{ width: '100%', height: 'calc(100% - 36px)', overflow: 'auto' }}
                onScroll={this.onScroll}
                id="OrderTable"
            >
                <div style={{ width: (this.props.sheet.columnInfo.x + 120) + "px" }} onMouseOut={this.onMouseOverTr}>
                    <table border='1' style={{ border: '1px solid #cccccc' }}  >
                        <tbody>
                            <Checkbox.Group
                                value={this.state.ordCheck}
                            >
                                {tableItem}
                            </Checkbox.Group>
                        </tbody>
                    </table>
                </div>
            </div>
        );

        return (
            <div className="nurseExecute orderItem">
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName="NurseExcuteConfigPanel"
                    configType="C"
                    visible={this.state.visible}
                    onCancel={
                        () => {
                            this.setState({
                                visible: false,
                            })
                        }
                    }
                />
                <Col className='tabsHeight'>
                    <Col xxl={{ span: 7 }} xl={{ span: 12 }} lg={{ span: 14 }}>
                        模糊检索:<Select style={{ width: "35%", margin: '0 10px 0 10px', height: '28px' }} value={this.state.filterColumn} onChange={this.onFilterChange}>
                            {filterColumn}
                        </Select>
                        <Input allowClear={true} onChange={this.onFilterInputChage} placeholder="(Enter后自动查询)" style={{ width: '40%', margin: '0 10px 0 0', height: '28px' }} onPressEnter={this.onFilterEnter} />
                    </Col>
                    <Col xxl={{ span: 17 }} xl={{ span: 12 }} lg={{ span: 14 }}>
                        {
                            this.props.sheet.buttonInfo.map(
                                (button) => {
                                    return (
                                        <Button
                                            type={button.code == "HandlerOrder" && this.state.handleOrderBtnStatus ? "text" : "primary"}
                                            className="btnStyle"
                                            id={button.code}
                                            key={button.code}
                                            onClick={this.onButtonClick.bind(this, button)}
                                            loading={this.state.iconLoading}
                                            disabled={button.code == "HandlerOrder" ? this.state.handleOrderBtnStatus : false}
                                        >
                                            {
                                                button.descripts
                                            }
                                        </Button>
                                    )
                                }
                            )
                        }
                    </Col>
                </Col>
                <Col span={24} className="btnCol">
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', background: '#36CFC9', color: '#fff' }}>未处理医嘱</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', color: '#36CFC9' }}>已处理医嘱</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', background: '#ff0000', color: '#fff' }}>需处理停止</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', color: '#75D048' }}>已处理停止</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', background: '#EF59AB', color: '#fff' }}>皮试医嘱 </Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', background: '#F74E57', color: '#fff' }}>皮试阳性</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px' }}>皮试阴性/已执行</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', color: '#2F54EB' }}>长期医嘱</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', background: '#FF7A45', color: '#fff' }}>新开长期</Tag>
                    <Tag style={{ border: 0, textAlign: 'center', marginTop: '4px', color: '#722ED1' }}>临时医嘱</Tag>
                </Col>

                <div class="orderdivStyle">
                    {table}
                </div>

                <SkinTest
                    key="SkinTest"
                    onClose={this.onModalClose.bind(this, "skinTestVisible")}
                    visible={this.state.skinTestVisible}
                    button={this.state.button}
                    getPatientOrd={this.props.getPatientOrd}
                    onOk={this.handleSkinTestOk}
                    onSwitchChange={this.onSwitchChange}
                    onInputChange={this.onInputChange}
                    type={this.state.type}
                    result={this.state.result}
                    batchNumber={this.state.batchNumber}
                    setDate={this.state.setDate}
                    setTime={this.state.setTime}
                    auditDate={this.state.auditDate}
                    auditTime={this.state.auditTime}
                    startDate={this.state.startDate}
                    startTime={this.state.startTime}
                    timeimg={this.state.timeimg}
                    timingFlag={this.state.timingFlag}
                    remainderTime={this.state.remainderTime}
                    okTitle={this.state.okTitle}
                    handleDateTimeChange={this.handleDateTimeChange}
                />
                <Sign
                    key="Sign"
                    onClose={this.onModalClose.bind(this, "signVisible")}
                    visible={this.state.signVisible}
                    button={this.state.button}
                    getPatientOrd={this.props.getPatientOrd}
                    title={this.state.title}
                    onOk={this.handleSignOk}
                    handleDateTimeChange={this.handleDateTimeChange}
                    onSelectChange={this.onSelectChange}                    
                    typeCode={this.state.typeCode}
                    refuseReason={this.state.refuseReason}
                    nurseArr={this.state.nurseArr}
                    execUserID={this.state.execUserID}
                    date={this.state.date}
                    time={this.state.time}
                    preExecFlag={this.props.preExecFlag}
                />

            </div >
        )

    }

}
export default OrderItem;