import React from 'react'
import {
    Row, Col, Button, Input, DatePicker, Checkbox, Select, Tabs, Table, message, Card, Divider,
} from 'antd';
import { $http } from '../../containers/config/https';
import OPPatientList from './OPPatientList';
import store from '../../store';
import AcBarcode from 'ac-barcode';
import PatientInfo from '../nurse/Patient/PatientInfo.jsx'
import './CSS/opNurse.less';
import ReadCard from '../../components/readcard/ReadCard';
import { getLodop } from '../lodop/Common/LodopFuncs.js';
import { $loadTemplate } from '../lodop/Common/Print.js';
import RangeDatePicker from 'components/rangePicker/index';
import { Util, dayFormat } from 'tools/index';
import moment from 'moment';
let user;

// 组件const
const { Option } = Select;
const RangePicker = DatePicker.RangePicker;
const { TabPane } = Tabs;
const dateFormat = 'YYYY-MM-DD';
class NurseExcute extends React.Component {
    constructor(props) {
        super(props);
        var date = new Date()
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        this.state = {
            // admDateFrom: moment(date).format(dayFormat),
            // admDateTo: moment(date).format(dayFormat),
            sheetList: [],
            activeKey: "0",
            ordList: [],
            stDate: "",
            endDate: "",
            patNo: "",
            cardNo: "",
            cardTypeID: "",
            cardTypeList: [],
            execFlag: false,
            ordChecked: {},
            ordCheckedStatus: {},
            admID: "",
            checkAll: "全选",
            admList: [],
            defaultAdmIndex: '',       //默认显示就诊记录
            ordStartDate: '',
            ordStopDate: '',
            defaultValueObj: {
                stDate: moment(date).format(dayFormat),
                endDate: moment(date).format(dayFormat),
            },
            ENObj: {},
            CNObj: {},
            selectRowkeys: [],
            firstCharge: "N",
            execLabNoArr: [],
            crystalsSerialNoArr:[],
        }
    }
    //渲染完成时调用
    componentDidMount() {
        this.getDetailTableColumns()
        this.initDefaultValue();
        this.handleBaseData();
        this.getSheetList();
    }
    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }
    // 调用公共组件的连接事件
    onRef = (ref) => {
        this.child = ref
    }

    initDefaultValue = () => {
        let data = {
            params: [{
                defaultAppObj: {
                    OPNurseExecute: ['stDate', 'endDate'],
                }
            }]
        }
        $http.post('urlS', this, {
            code: "04110023",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        defaultValueObj: res.result,
                        admDateFrom: res.result.stDate ? res.result.stDate : moment(date).format(dayFormat),
                        admDateTo: res.result.endDate ? res.result.endDate : moment(date).format(dayFormat)
                    })
                }
            }
        })
    }
    // 获取明系列表头数据
    getDetailTableColumns = () => {
        let { userInfo } = this.state;
        let data = {
            params: [{
                reactCode: ['AmbulatoryNurseExecute'],
                compontName: 'AmbulatoryNurseExecute',
                type: 'B',
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        ENObj: res.result.language.EN,
                        CNObj: res.result.language.CN
                    })
                }
            }
        })
    };

    //获取单据列表
    getSheetList = () => {
        let data = {
            params: [{
                hospID: user.hospID,
                columnFlag: "0",
            }]
        }
        $http.post('urlDeault', this, {
            code: "04030007",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        sheetList: res.result.sheet,
                        sheet: res.result.default,
                        // stDate: res.result.default.startDate,
                        // endDate: res.result.default.endDate,
                        activeKey: res.result.default.seqNo ? (res.result.default.seqNo + "") : "0",
                    })

                } else {
                    message.error('未获取到单据：' + res.errorMessage);
                }
            }
        })

    }
    //加载基础数据
    handleBaseData = () => {
        let data = {
            params: [{
                hospID: user.hospID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "04080005",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    let defaultCardTypeID = "";
                    res.result.cardTypeList.map((item) => {
                        if (item.defaultFlag === "Y") {
                            defaultCardTypeID = item.id;
                        }
                    })
                    this.setState({
                        cardTypeList: res.result.cardTypeList,
                        cardTypeID: defaultCardTypeID,
                        defaultCardTypeID: defaultCardTypeID,
                        replenishZero: res.result.cardTypeList[0].replenishZero,
                        cardLength: res.result.cardTypeList[0].cardLength,
                        firstCharge: res.result.firstCharge
                    })
                } else {
                    message.error('获取信息失败：' + res.errorMessage);
                }
            }
        })
    }
    //获取患者就诊信息
    handleGetPatInfo = (patNo, cardNo, admID) => {
        if ((patNo == "") && (cardNo == "") && (admID == "")) {
            return;
        }
        if (!admID) {
            admID = this.state.admID;
        }
        let oldadmID = admID;
        let data = {
            params: [{
                hospID: user.hospID,
                locID: user.locID,
                cardTypeID: this.state.cardTypeID === "" ? this.props.defaultCardTypeID : this.state.cardTypeID,
                patNo: patNo,
                cardNo: cardNo,
                startDate: this.state.admDateFrom,
                stopDate: this.state.admDateTo,
            }]
        }
        $http.post('urlDeault', this, {
            code: "04080006",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    if (res.result.admList.length > 0) {
                        if (!admID) {
                            admID = res.result.admList[0].admID;
                        }
                        let index = 0;
                        let findFlag = false;
                        if ((admID != "") && (admID != undefined)) {
                            for (var admi = 0; admi < res.result.admList.length; admi++) {
                                if (res.result.admList[admi].admID == admID) {
                                    index = admi;
                                    findFlag = true;
                                }
                            }
                        }
                        if (!findFlag) {
                            admID = res.result.admList[0].admID;
                        }
                        this.setState({
                            patNo: res.result.baseInfo.patNo,
                            admList: res.result.admList,
                            admID: admID,
                            defaultAdmIndex: index,
                        }, () => {
                            // if (oldadmID != this.state.admID) this.childPatient.getPatientInfo(this.state.admID);
                            this.childPatient.getPatientInfo(this.state.admID);
                            this.handelQueryOrderNew(this.state.patNo, cardNo, admID);
                        })
                    }
                } else {
                    this.childPatient.getPatientInfo("");
                    this.setState({
                        // patInfo: "",
                        admList: [],
                        admID: "",
                        ordList: [],
                    })
                }
            },
            error: () => {
                this.childPatient.getPatientInfo("");
                this.setState({
                    // patInfo: "",
                    admList: [],
                    admID: "",
                    ordList: [],
                })
            }
        })
    }
    handelQueryOrder = (patNo, cardNo, admID) => {
        //查询该段时间内所有就诊记录
        this.handleGetPatInfo(patNo, cardNo, admID);
        // this.handelQueryOrderNew(patNo, cardNo, admID);
    }

    //查询医嘱信息
    handelQueryOrderNew = (patNo, cardNo, admID) => {
        let sheet = this.state.sheetList[this.state.activeKey];
        if ((patNo == "") && (cardNo == "") && (admID == "")) {
            return;
        }
        let data = {
            params: [{
                hospID: user.hospID,
                sheetCode: sheet.code ? sheet.code : "",
                locID: user.locID,
                stDate: this.state.admDateFrom,
                endDate: this.state.admDateTo,                //查询该段时间内所有就诊记录
                execFlag: this.state.execFlag ? "Y" : "N",
                patNo: patNo,
                cardTypeID: this.state.cardTypeID,
                cardNo: cardNo,
                admID: admID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "04030008",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        ordList: (res.result.length > 0)&&(!Util.isEmpty(res.result[0])) ? res.result : [],
                        ordChecked: {},
                        patNo: patNo,
                        cardNo: cardNo,
                        admID: admID,
                        selectRowkeys: [],
                    })
                }
            }
        })

    }
    ///单据切换
    onSheetChange = (key) => {
        this.setState({
            activeKey: key,
            ordList: [],
            ordChecked: {},
            selectRowkeys: [],
        }, () => {
            this.handelQuery();
        })
    }
    //修改日期
    onDateChange = (date, dateString) => {
        this.setState({
            admDateFrom: dateString[0],
            admDateTo: dateString[1],
            defaultAdmIndex: '',
        }, () => {
            this.handleGetPatInfo(this.state.patNo, this.state.cardNo);
            // this.handelQueryOrderNew(this.state.patNo, this.state.cardNo, this.state.admID);
        })
    }
    ///登记号回车事件
    onPatNoEnter = (e) => {
        let patNo = e.target.value
        this.setState({
            patNo: patNo,
            defaultAdmIndex: '',
        }, () => {
            this.handleGetPatInfo(patNo, "");
        })
    }
    ///卡号回车事件
    onCardEnter = (e) => {
        e.stopPropagation();
        this.setState({
            cardNo: e.target.value,
            patNo: '',
            defaultAdmIndex: '',
        }, () => {
            let cardNo = this.handleZero()
            if (cardNo != '') {
                this.handleGetPatInfo("", cardNo);
            } else {
                message.error('请输入卡号');
            }
        })
    }
    //进行卡号检测补0操作
    handleZero = () => {
        //补0 Y 长度不为0
        let cardNoNum = ''
        if (this.state.replenishZero == "Y" && parseInt(this.state.cardLength) && parseInt(this.state.cardLength) > 0 && this.state.cardNo && this.state.cardNo.length > 0) {
            let No = this.state.cardNo ? this.state.cardNo : ''
            // console.log("长度handleLength",this.state.cardLength,parseInt(this.state.cardLength))
            let length = parseInt(this.state.cardLength)
            cardNoNum = (Array(length).join(0) + No).slice(-length)
            // this.props.form.setFieldsValue({ cardNo: num });
            this.setState({
                cardNo: cardNoNum,
            })
        }
        return cardNoNum
    }
    //卡类型修改
    cardTypeChange = (value, option) => {
        this.setState({
            cardLength: option.props.cardlength,
            cardTypeID: value,
        })
    }
    //读卡
    onReadCard = () => {
        const { cardTypeID } = this.state;
        this.readCard.ReadCard(cardTypeID, "R", (json) => {
            if (!Util.isEmpty(json)) {
                this.setState({
                    cardInfo: json,
                    cardNo: json.cardNo,
                    patNo: !Util.isEmpty(json.patInfo) ? json.patInfo.patNo : '',
                }, () => {
                    if (json.hasOwnProperty('patInfo')) {
                        this.handleGetPatInfo(json.patInfo.patNo, '');
                    }
                })
            }
        })
    }
    /** 去重*/
    unique5(arr) {
        var x = new Set(arr);
        return [...x];
    }
    //点击医嘱
    onSelectOrd(index, item, e) {
        let ordChecked = this.state.ordChecked;
        let ordCheckedStatus = this.state.ordCheckedStatus;

        ordChecked[this.state.ordList[index].execID] = !ordChecked[this.state.ordList[index].execID];
        ordCheckedStatus[this.state.ordList[index].execID] = this.state.ordList[index].ordBilledCode
        let execLabNoArr = this.state.execLabNoArr;
        let crystalsSerialNoArr=this.state.crystalsSerialNoArr;
        if (item.execLabNo != '') {
            if ((execLabNoArr.indexOf(item.execLabNo) > -1) && (!ordChecked[this.state.ordList[index].execID])) {
                execLabNoArr.splice(execLabNoArr.findIndex(data => data === item.execLabNo), 1)
            } else {
                execLabNoArr.push(item.execLabNo)
            }
        }
        if (item.crystalsSerialNo !=""){
            if ((crystalsSerialNoArr.indexOf(item.crystalsSerialNo) > -1) && (!ordChecked[this.state.ordList[index].execID])) {
                crystalsSerialNoArr.splice(crystalsSerialNoArr.findIndex(data => data === item.crystalsSerialNo), 1)
            } else {
                crystalsSerialNoArr.push(item.crystalsSerialNo)
            }
        }
        execLabNoArr = this.unique5(execLabNoArr)
        crystalsSerialNoArr = this.unique5(crystalsSerialNoArr)
        this.setState({
            ordChecked: ordChecked,
            ordCheckedStatus: ordCheckedStatus,
            execLabNoArr,
            crystalsSerialNoArr
        })
    }
    //登记号修改
    onPatNoChange = (e) => {
        this.setState({
            patNo: e.target.value
        })
    }
    //卡号修改
    onCardChange = (e) => {
        this.setState({
            cardNo: e.target.value
        })
    }
    ///已执行标记
    onExecFlagChange = (e) => {
        this.setState({ execFlag: e.target.checked }, () => {
            this.handelQueryOrderNew(this.state.patNo, this.state.cardNo, this.state.admID)
        })
    }
    ///查询按钮
    handelQuery = () => {
        this.handleGetPatInfo(this.state.patNo, this.state.cardNo, this.state.admID);
    }

    //配置按钮点击事件
    onButtonClick = (button, e) => {
        let ordIDs = [];
        let crystalsSerialNos=[];
        let {crystalsSerialNoArr}=this.state;
        let ordChecked = this.state.ordChecked;
        let ordCheckedStatus = this.state.ordCheckedStatus;
        var flag = true;
        for (var i in ordChecked) {
            if (ordChecked[i]) {
                if ((ordCheckedStatus[i] != "P") && (this.state.firstCharge == "Y")) {
                    flag = false;
                }
                ordIDs.push(i);
                crystalsSerialNos.push(crystalsSerialNoArr[i])
            }
        }
        if (ordIDs.length === 0) {
            message.warn("请先选择医嘱!");
            return;
        }
        if ((button.code === "skintestBtn") && (ordIDs.length > 1)) {
            message.warning("置皮试请选择一条医嘱！！！");
            return;
        }
        if (button.linkMethod === "skinTestResult") {
            message.warning("开发中");
            return
        }
        if (button.linkMethod === "excuteOrHanlderOrd") {
            if (flag) {
                this.handleExecOrd(button, ordIDs,crystalsSerialNos);
            } else {
                message.warning("请选择已收费医嘱");
                return
            }
        }
        if (button.code === "printBtn") {
            this.printExecSheet(ordIDs);
        }
        if ((button.code === "bottleSign") && (ordIDs.length > 0)) {
            for (let index = 0; index < ordIDs.length; index++) {
                const execID = ordIDs[index].replace(/-/g, '||');
                this.handlePrint(button, execID);
            }
        }
        if ((button.code === "barcodeBtn") && (ordIDs.length > 0)) {
            for (let index = 0; index < this.state.execLabNoArr.length; index++) {
                this.barCodePrint(this.state.execLabNoArr[index])
            }
        }
        this.setState({ checkAll: '全选', execLabNoArr: [] },
            () => {
                this.handelQueryOrderNew(this.state.patNo, this.state.cardNo, this.state.admID);
            });
    }
    // 执行单打印
    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);            //执行打印内容
                }
            }
        })
    }

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

    }
    // 打印条码
    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);
                }
            }
        })

    }
    handleExecOrd = (button, ordIDs,crystalsSerialNos) => {
        let typeCode = "F";
        if (("^" + button.code).indexOf("^Un") > -1) {
            typeCode = "CE"
        }
        let data = {
            params: [{
                ordIDs: ordIDs,
                crystalsSerialNos,
                date: "",
                time: "",
                userID: user.userID,
                code: typeCode,
                locID: user.locID,
            }]
        }
        $http.post('urlDeault', this, {
            code: button.linkService,
            data: data,
            success: (res) => {
                this.setState({ signVisible: false, ordList: [] });
                if (+res.errorCode !== 0) {
                    // message.error(button.descripts + "失败:" + res.errorMessage);
                } else {
                    if (res.errorArr.length !== 0) {
                        message.error(res.errorArr.join(","));
                    } else {
                        message.success(button.descripts + "成功！");
                    }

                }
            }
        })

    }
    //全选
    onCheckAll = (e) => {
        let checkAll = this.state.checkAll === "全选" ? "取消" : "全选";
        let ordChecked = [];
        let execLabNoArr = []
        let crystalsSerialNoArr=[]
        for (var i = 0; i < this.state.ordList.length; i++) {
            ordChecked[this.state.ordList[i].execID] = (this.state.checkAll === "全选");
            ordChecked[this.state.ordList[i].execID] = this.state.ordList[i].ordBilledCode
            if (checkAll === "取消") {
                execLabNoArr.push(this.state.ordList[i].execLabNo)
                crystalsSerialNoArr.push(this.state.ordList[i].execLabNo)
            }
        }
        this.setState({
            checkAll: checkAll,
            ordChecked: ordChecked,
            execLabNoArr: this.unique5(execLabNoArr),
            crystalsSerialNoArr:this.unique5(crystalsSerialNoArr)
        })
    }

    //选择就诊记录
    onAdmChange = (index) => {
        let admID = "", defaultAdmIndex = index;
        if (index != undefined) {
            admID = this.state.admList[index].admID

        } else {
            admID = "";
            defaultAdmIndex = "";
        }
        this.setState({
            admID: admID,
            defaultAdmIndex: index,
            // ordStartDate: this.state.admList[index].admDate,
            // ordStopDate: (this.state.admList.length-1==index)?'':this.state.admList[index + 1].admDate,
        }, () => {
            this.handelQueryOrderNew(this.state.patNo, this.state.cardNo, admID);
        })
    }

    startChange(date) {
        this.setState({
            admDateFrom: date,
        })
    }

    endChange(date) {
        this.setState({
            admDateTo: date,
        })
    }
    cardMode = () => {
        let cardMode = [];
        this.state.ordList.map((item, index) => {
            cardMode.push(
                <Col span={6} style={{ padding: '2px' }} key={index + ""}>
                    <Card style={{ width: '98%', height: '200px' }} className={this.state.ordChecked[item.execID] ? "ant-card-bordered-blue" : ""}>
                        <div style={{ width: '100%', height: '100%' }} onClick={this.onSelectOrd.bind(this, index, item)}>
                            <div style={{ height: '25%' }}>
                                <Row style={{ height: '100%' }}>
                                    <Col span={13}>
                                        <AcBarcode value={item.execID} width={1.2 - ((item.execID.length - 10) / 20)} height={30} fontSize={10} margin={3} />
                                    </Col>
                                    <Col span={11} style={{ paddingLeft: '3px', height: '100%' }}>
                                        <div style={{ width: '100%' }}>
                                            <Col span={20}>
                                                {item.ordUsageDesc + "  " + item.ordFreqCode + "  (" + item.times + "/" + item.total + ")"}
                                            </Col>
                                            <Col span={4}>
                                                <Checkbox checked={this.state.ordChecked[item.execID]} />
                                            </Col>
                                        </div>
                                        <div style={{
                                            width: '100%',
                                            overflow: 'hidden',
                                            textOverflow: 'ellipsis',
                                            whiteSpace: 'nowrap',
                                        }}>
                                            {item.execReqDate + " " + item.execReqTime}
                                        </div>
                                    </Col>
                                </Row>

                            </div>
                            <Divider />
                            <div style={{ height: '63%' }}>
                                <Row>
                                    <Col span={18}>
                                        {item.medDesc}
                                    </Col>
                                    <Col span={6}>{item.ordDoseUnit}</Col>
                                </Row>
                                {
                                    item.child.map((child) => {
                                        return (
                                            <Row key={child.indexID}>
                                                <Col span={18}>
                                                    {child.medDesc}
                                                </Col>
                                                <Col span={6}>{child.ordDoseUnit}</Col>
                                            </Row>)
                                    })
                                }
                            </div>
                            <Divider />
                            <div style={{ height: '10%' }}>
                                <Row>
                                    <Col span={6} style={{ overflow: "hidden", "white-space": "nowrap", "text-overflow": "ellipsis" }}>
                                        {item.ordDocName}
                                    </Col>
                                    <Col span={8}>
                                        第{index + 1}袋/共{this.state.ordList.length}袋
                                    </Col>
                                    <Col span={4}>
                                        {item.ordDuratQty + "  " + item.ordDuratUomDesc}
                                    </Col>
                                    <Col span={2}>
                                        {item.ordInfuseSpeed + "  " + item.ordSpeedUnitDesc}
                                    </Col>
                                    <Col span={4}>
                                        {item.ordBilledDesc == "未账单" ? "未收费" : "已收费"}
                                    </Col>
                                </Row>
                            </div>
                        </div>
                    </Card>
                </Col>
            )
        })
        return cardMode;
    }
    // 晶体医嘱绑定序列号
    bindCrystalsSerialNo = (execID, index, e) => {
        let data = {
            params: [{
                execID,
                crystalsSerialNo: e.target.value,
            }]
        }
        $http.post('urlS', this, {
            code: "04010011",
            data: data,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.handleExecOrdJT(execID);
                    // message.success("绑定晶体成功！");
                    // if (this.state.ordList.length > index) {
                    //     this['crystalsSerialNo' + (index + 1)].input.focus();
                    // }
                }
            }
        })
    }
    // 晶体扫码后执行医嘱
    handleExecOrdJT = (ordID) => {
        let data = {
            params: [{
                ordIDs: [ordID],
                date: "",
                time: "",
                userID: user.userID,
                code: 'F',
                locID: user.locID,
            }]
        }
        $http.post('urlDeault', this, {
            code: '04030003',
            data: data,
            success: (res) => {
                this.setState({ signVisible: false, ordList: [] });
                if (+res.errorCode !== 0) {
                    this.handelQueryOrderNew(this.state.patNo, this.state.cardNo, this.state.admID);
                    // message.error("执行失败:" + res.errorMessage);
                } else {
                    if (res.errorArr.length !== 0) {
                        message.error(res.errorArr.join(","));
                    } else {
                        message.success("执行成功！");
                    }
                    this.handelQueryOrderNew(this.state.patNo, this.state.cardNo, this.state.admID);
                }
            }
        })

    }
    tableMode = (item) => {
        let {ordList} = this.state
        // 晶体序列号列改文本框
        item.columnInfo.column.map(columnObj => {
            if (columnObj.dataIndex == 'crystalsSerialNo' && ordList.length > 0 && (!Util.isEmpty(ordList[0]))) {
                columnObj.render = (text, record, index) => {
                    if (ordList.length > 0) {
                        return (<Input
                            ref={(input) => this['crystalsSerialNo' + index] = input}
                            value={record.crystalsSerialNo}
                            onChange={(e) => {
                                ordList[index].crystalsSerialNo=e.target.value
                                this.setState({ordList})
                            }}
                            onPressEnter={this.bindCrystalsSerialNo.bind(this, record.execID, index)}
                        />)
                    }
                }
            }
        })
        const selection = {
            columnWidth: "30px",
            onChange: (selectedRowKeys, selectedRows) => {
                let ordChecked = [], ordCheckedStatus = [], selectedKeys = [];
                let thisoOdChecked = this.state.ordChecked;
                let curOrdChecked = [];
                let execLabNoArr = []
                let crystalsSerialNoArr=[]
                // console.log('selectedRows',selectedRows)
                for (let i = 0; i < selectedRows.length; i++) {
                    curOrdChecked[selectedRows[i].execID] = true;
                    if (execLabNoArr.indexOf(selectedRows[i].execLabNo) < 0) execLabNoArr.push(selectedRows[i].execLabNo)
                    //同位置索引  undefined及空字符都转换为空字符
                    crystalsSerialNoArr[i]=((selectedRows[i].crystalsSerialNo)&&(selectedRows[i].crystalsSerialNo!==""))?(selectedRows[i].crystalsSerialNo):""
                    //if (crystalsSerialNoArr.indexOf(selectedRows[i].crystalsSerialNo)<0) crystalsSerialNoArr.push(selectedRows[i].crystalsSerialNo) 
                }
                selectedRows.map((item) => {
                    let groupID = item.groupID;
                    if (groupID.length > 1) {
                        let checkedFlag = true;
                        groupID.map((group) => {
                            if ((curOrdChecked[group] == undefined) && (thisoOdChecked[group] == true)) {
                                checkedFlag = false;
                            }
                        })
                        if ((checkedFlag) && (ordChecked[item.execID] == undefined)) {
                            groupID.map((group) => {
                                ordChecked[group] = true;
                                ordCheckedStatus[group] = item.ordBilledCode;
                                selectedKeys.push(group);
                            })
                        }
                    } else {
                        ordChecked[item.execID] = true;
                        ordCheckedStatus[item.execID] = item.ordBilledCode;
                        selectedKeys.push(item.execID);
                    }
                })
                this.setState({ selectRowkeys: selectedKeys, ordChecked: ordChecked, ordCheckedStatus: ordCheckedStatus, execLabNoArr,crystalsSerialNoArr });
            },
            selectedRowKeys: this.state.selectRowkeys,
        }
        return (
            <Table
                pagination={false}
                style={{ width: store.getState().tableHeight.x, height: store.getState().tableHeight.y + 35 + 'px' }}
                scroll={{ x: item.columnInfo.x + 100, y: store.getState().tableHeight.y - 25 }}
                rowSelection={selection}
                bordered={true}
                columns={item.columnInfo.column}
                dataSource={this.state.ordList}
                rowKey={(row) => {
                    return row.execID;
                }}
            >
            </Table>
        )
    }
    onRefPatient = (ref) => {
        this.childPatient = ref;
    }
    render() {
        const cardType = [];
        this.state.cardTypeList.map((item) => {
            cardType.push(
                <Option key={item.id} value={item.id} cardlength={item.cardLength}>
                    {user.language == 'CN' ? item.descripts : item.enDescripts}
                </Option>
            )
        })
        const admList = [];
        this.state.admList.map((adm, index) => {
            admList.push(
                <Option key={index} value={index}>
                    就诊时间:{adm.admDate + " " + adm.admTime}&nbsp;&nbsp;医生:{adm.admDocDesc}
                </Option>
            )
        })
        var language = user.language
        var languageObj = {}
        if (language == "EN") {
            languageObj = this.state.ENObj
        } else {
            languageObj = this.state.CNObj
        }
        return (
            <Row className="NurseExecute">
                {user.locDesc.indexOf('病区')>-1 || user.locDesc.indexOf('手术室')>-1 ? '' :
                <Col span={5} style={{ height: '100%' }}>
                    <OPPatientList
                        onRef={this.onRef}
                        handelThis={this}
                    />
                </Col>}
                <Col span={user.locDesc.indexOf('病区')>-1 || user.locDesc.indexOf('手术室')>-1  ? 24 : 19} style={{ border: '1px solid #cccccc', height: '100%', overflow: 'hidden' }}>
                    <div style={{ width: '100%', minHeight: '31px', fontWeight: 'bold' }}>
                        <PatientInfo onRef={this.onRefPatient} width="96%" />
                    </div>
                    <div style={{ width: '100%', height: '3px', background: '#f0f2f5' }}></div>
                    <div className="table-operations">

                        <Row style={{ padding: "15px 10px 5px 20px" }}>
                            <Col>
                                <RangeDatePicker format='YYYY-MM-DD' label={languageObj.AmbulatoryNurseExecutevisitDate != null ? languageObj.AmbulatoryNurseExecutevisitDate.descripts : ""} labelwidth="70px" totalwidth="350" width="280px" float="left"
                                    startDate={this.state.admDateFrom} endDate={this.state.admDateTo}
                                    // defaultValue={[moment(this.state.defaultValueObj.stDate, dateFormat), moment(this.state.defaultValueObj.endDate, dateFormat)]}
                                    startChange={this.startChange.bind(this)} endChange={this.endChange.bind(this)} />

                                {/* 就诊日期:<RangePicker
                                    value={[(this.state.stDate === "") ? null : Moment(this.state.stDate, 'YYYY-MM-DD'),
                                    (this.state.endDate === "") ? null : Moment(this.state.endDate, 'YYYY-MM-DD')]}
                                    onChange={this.onDateChange}  AmbulatoryNurseExecutecardType ， AmbulatoryNurseExecutepatNo，AmbulatoryNurseExecutecardNo
                                /> */}
                                {languageObj.AmbulatoryNurseExecutepatNo != null ? languageObj.AmbulatoryNurseExecutepatNo.descripts : ""}:<Input value={this.state.patNo} placeholder={languageObj.AmbulatoryNurseExecutepatNo != null ? languageObj.AmbulatoryNurseExecutepatNo.message : ""} onChange={this.onPatNoChange}
                                    allowClear={true}
                                    onPressEnter={this.onPatNoEnter} style={{ marginLeft: '10px', width: '150px' }} />
                                {languageObj.AmbulatoryNurseExecutecardType != null ? languageObj.AmbulatoryNurseExecutecardType.descripts : ""}<Select value={this.state.cardTypeID} onChange={this.cardTypeChange} style={{ marginLeft: '10px', width: '120px' }}>{cardType}</Select>
                                {languageObj.AmbulatoryNurseExecutecardNo != null ? languageObj.AmbulatoryNurseExecutecardNo.descripts : ""}:<Input value={this.state.cardNo} placeholder={languageObj.AmbulatoryNurseExecutecardNo != null ? languageObj.AmbulatoryNurseExecutecardNo.message : "输入卡号"} onChange={this.onCardChange}
                                    allowClear={true}
                                    onPressEnter={this.onCardEnter} style={{ marginLeft: '10px', width: '160px' }} />
                                <Button type="primay" style={{ marginLeft: '10px' }} onClick={this.onReadCard}>{languageObj.AmbulatoryNurseExecutereadCard != null ? languageObj.AmbulatoryNurseExecutereadCard.descripts : ""}</Button>


                                <Select style={{ marginLeft: '10px', width: '200px' }}
                                    allowClear={true}
                                    onChange={this.onAdmChange}  //pleaseSelectAdm
                                    value={this.state.defaultAdmIndex}
                                    placeholder={languageObj.pleaseSelectAdm != null ? languageObj.pleaseSelectAdm.descripts : ""}>
                                    {
                                        admList
                                    }
                                </Select>
                                <Checkbox checked={this.state.execFlag} onChange={this.onExecFlagChange} style={{ marginLeft: '10px' }} >{languageObj.AmbulatoryNurseExecutecarriedOut != null ? languageObj.AmbulatoryNurseExecutecarriedOut.descripts : ""}</Checkbox>
                                <Button type="primary" style={{ marginLeft: '10px' }} onClick={this.handelQuery}>{languageObj.AmbulatoryNurseExecuteQuery != null ? languageObj.AmbulatoryNurseExecuteQuery.descripts : ""}</Button>
                            </Col>
                        </Row>

                    </div>
                    <div style={{ width: '100%', height: '6px', background: '#f0f2f5' }}></div>
                    <Tabs type="card" style={{ paddingTop: '4px' }} activeKey={this.state.activeKey} onChange={this.onSheetChange}>
                        {
                            this.state.sheetList.map((item, index) => {

                                return (
                                    <TabPane tab={item.descripts} key={index + ""} >

                                        {
                                            (this.state.activeKey == (index + "")) ?
                                                <div style={{ height: '100%', width: '100%' }}>
                                                    <div style={{ height: '45px' }}
                                                    >
                                                        {item.cardFlag == "Y" ? <Button type="primary" style={{ margin: '5px 10px 5px 10px' }} onClick={this.onCheckAll}>{this.state.checkAll}</Button> : ""}
                                                        {
                                                            item.buttonInfo.map(
                                                                (button) => {
                                                                    return (
                                                                        <Button
                                                                            type="primary"
                                                                            style={{ margin: '5px 10px 5px 10px' }}
                                                                            disabled={((button.code.indexOf("excute") > -1) && (this.state.execFlag == true)) || ((button.code.indexOf("Excute") > -1) && (this.state.execFlag == false))}
                                                                            id={button.code}
                                                                            key={button.code}
                                                                            onClick={this.onButtonClick.bind(this, button)}
                                                                        >
                                                                            {button.descripts}
                                                                        </Button>
                                                                    )
                                                                })}
                                                    </div>
                                                    <div style={{ width: '100%', height: '2px', background: '#f0f2f5' }}></div>
                                                    <Row style={{ overflow: 'auto', width: store.getState().tableHeight.x, height: store.getState().tableHeight.y + 35 + 'px' }}>
                                                        {item.cardFlag == "Y" ? this.cardMode() : this.tableMode(item)}
                                                    </Row>
                                                </div> : ""
                                        }

                                    </TabPane>
                                )

                            })
                        }
                    </Tabs>
                </Col>
                <ReadCard ref={(r) => { return (this.readCard = r) }} />
            </Row>

        )
    }
}
export default NurseExcute;