// 成套医嘱维护 | 医嘱套餐（西药及其它） | 医嘱套餐优惠
import React from 'react';
import { Card, Table, Input, Select, Checkbox, Modal, Spin, Button, Tooltip, Icon, Divider, message, Popconfirm, AutoComplete } from 'antd';
import { Util, dayFormat, timeFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import ShowCompleteMedicalModal from './component/ShowCompleteMedicalModal';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import ShowConfirmModal from './component/ShowConfirmModal';
import ShowCommonTableModal from './component/ShowCommonTableModal';
import PublicDataOrderAdjustment from 'pages/common/PublicDataOrderAdjustment';
import moment from 'moment';
import store from 'store';
import './style/index.less';

const Option = Select.Option;
const confirm = Modal.confirm;
var totalCount = 0;//总数量

class CompleteMedicalPage extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        var recordData = JSON.parse(sessionStorage.getItem('recordData'))
        var titleData = JSON.parse(sessionStorage.getItem('titleData'))
        this.state = {
            categoryData: {}, // 界面参数
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 10,
            subrateData: {},
            userData: userData,
            recordData: recordData,
            titleData: titleData,
            subData: [],
            ids: [],
            selectData: [],
            cannelStatus: false,
            dynColumns: [],
            saveStatus: false,
            eyePartList: [],
            bodyPartList: [],
            stageList: [],
            priorityExtList: [],
            checkData: [],            //多选的数据 createBY: DYK
            totalWidth: 2200, // 总列宽
            coefficientData: [], // 系数类型
        }
        this.selectFocus = React.createRef();
    }

    componentDidMount() {
        let newCategory;
        if ('paras' in this.props && this.props.paras && this.props.paras.params) { // 侧菜单获取类别参数
            newCategory = this.props.paras.params;
        } else {
            if ('location' in this.props && this.props.location.state && this.props.location.state.params) { // 头菜单获取类别参数
                newCategory = this.props.location.state.params;
                React.$setSessionData('CompleteMedicalPage', newCategory, false);
            } else { // 头菜单刷新界面时获取类别
                newCategory = React.$getSessionData('CompleteMedicalPage', false);
            }
        }
        let categoryData = Util.getObjByUrlStr(newCategory);
        console.log("CompleteMedicalPage", categoryData);
        this.setState({ categoryData }, () => {
            categoryData?.interfaceType === 'finance' && this.getSelectData();
            this.loadLeftData();
            this.initData();
            this.loadColumns()
        });
    }

    // 就诊类型
    getSelectData = async () => {
        try {
            let res = await React.$asyncPost(this, '05100222');
            this.setState({
                coefficientData: res.coefficientData || [],    // 系数类型下拉款
            })
        } catch (error) {
            console.log(error);
        }
    }

    initData() {
        // var date = new Date();
        this.leftColumns = [{
            title: '级别',
            dataIndex: 'title',
            width: 100,
            align: 'left',
            render: (text, data) => {
                return data.ordSetID ? null : <span><span>{data.title}</span><span>({data.count})</span></span>
            }
        }, {
            title: '名称',
            dataIndex: 'ordSetDesc',
            width: 200,
            align: 'left',
            render: (text, data) => {
                return <Tooltip title={data.ordSetDesc}><div className="complete-text-ellipsis">{data.ordSetDesc}</div></Tooltip>
            }
        }, {
            title: '别名',
            dataIndex: 'ordSetAlias',
            width: 250,
            align: 'left',
            render: (text, data) => {
                return <Tooltip title={data.ordSetAlias}><div className="complete-text-ellipsis">{data.ordSetAlias}</div></Tooltip>
            }
        }, {
            title: '操作员',
            dataIndex: 'userName',
            width: 80,
            align: 'center',
            render: (text, data) => {
                return <Tooltip title={data.userName}><div className="complete-text-ellipsis">{data.userName}</div></Tooltip>
            }
        }, {
            title: '状态',
            dataIndex: 'status',
            width: 80,
            align: 'center',
        }, {
            title: '操作',
            dataIndex: '6',
            width: 120,
            align: 'center',
            fixed: 'right',
            render: (text, data) => {
                return (
                    data.ordSetID ? (
                        <span>
                            <Icon type="edit" style={{ color: '#108EE9' }}></Icon>
                            <span className="span" onClick={this.editData.bind(this, data)}>编辑</span>
                            <Divider type="vertical" />
                            <Icon type="delete" className="common-record-delete-span"></Icon>
                            <Popconfirm title="删除不可恢复，你确定要删除吗?" onConfirm={this.handleDel.bind(this, data)} >
                                <span className="span common-record-delete-span">删除</span>
                            </Popconfirm>
                        </span>
                    ) : (
                        <span className="span" onClick={(e) => this.handleSort(data, e)}>设置个人排序</span>
                    )
                )
            }
        }];
        this.sunColumns = [{
            title: '编码',
            dataIndex: 'medCode',
            width: 80,
            align: 'center',
        }, {
            title: '名称*规格',
            dataIndex: 'medDesc',
            width: 180,
            align: 'center',
        }, {
            title: '单价(元)',
            dataIndex: 'medPrice',
            width: 80,
            align: 'left',
        }, {
            title: '库存',
            dataIndex: 'medStock',
            width: 80,
            align: 'center',
        }, {
            title: '子类',
            dataIndex: 'medSubCatDesc',
            width: 120,
            align: 'center',
        }, {
            title: '商品名',
            dataIndex: 'tradeName',
            width: 120,
            align: 'center',
        }]
    }

    // 排序
    handleSort = (record, e) => {
        React.$stopPropagation(e);
        let columns = this.leftColumns.slice(1, this.leftColumns.length - 1);
        this.sortRef && this.sortRef.modifyVisible(true, {
            tableData: record?.children || [],
            columns,
            totalWidth: 610,
            saveCode: '03020074',
            recordIdIndex: 'ordSetID',
            modalTitle: (record?.title || '') + '(' + record?.count + ')' + ' 医嘱套餐排序', // 弹窗title
            interfaceParams: {
                authID: record?.authID || '',
                type: 'X', // 医嘱套餐（西药及其他） 【 X-西药及其他 Z-中草药 M-医嘱模板 DM-诊断模板 】
            }
        })
    }

    loadColumns() {
        var params = {
            params: [{
                compontName: 'CompleteMedicalPage',
                type: 'C',
            }]
        }
        $http.post('urlDeault', this, {
            code: '01040073',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var columns = res.result.C;
                    var dynColumns = []
                    if (columns) {
                        for (var i = 0; i < columns.length; i++) {
                            if (columns[i].dataIndex == 'ordSeqNo') {//序号
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        data.tabIndex = index + 1
                                        return {
                                            children: <div className={data.ordMinFlag == 'Y' ? 'rowClass' : ''}>{index + 1}</div>
                                        }
                                    }
                                })
                            }
                            if (columns[i].dataIndex == 'ordLinkSeqNo') {//关联号、组号
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var { copyData, dataSource } = this.state;
                                        if (copyData && dataSource) {
                                            for (var i = 0; i < copyData.length; i++) {
                                                for (var j = 0; j < dataSource.length; j++) {
                                                    if (dataSource[j].indexId == (copyData[i].indexId) && index == (dataSource[j].tabIndex - 1)
                                                        && Util.isEmpty(dataSource[j].ordID) && !Util.isEmpty(dataSource[j].mainIndexId)) {
                                                        data.ordLinkSeqNo = (dataSource[j].tabIndex - 1)
                                                    }
                                                }
                                            }
                                        }
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordLinkSeqNo') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return {
                                            children: editFlag ? undefined : (Util.isEmpty(data.ordID) ? <Input value={data.ordLinkSeqNo} style={{ width: '95%' }}
                                                onChange={this.changeOrdLinkInput.bind(this, 'ordLinkSeqNo', index, data)} /> :
                                                <div className={data.ordOrderDetailID ? 'linkStyle' : ''}>{data.ordLinkSeqNo}</div>)

                                        }
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordMedItemDesc') {//名称规格
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //(this.state.rightIndex == index && this.state.edit) || Util.isEmpty(data.ordSetDetailID)
                                        return Util.isEmpty(data.ordID) ?
                                            <Input style={{ width: '95%' }} id={"name-input" + index} ref={this.selectFocus}
                                                onKeyDown={this.showCommonTableModal.bind(this, index)} allowClear={true}
                                                // onBlur={this.changeMedItemDescFocus.bind(this, index)}
                                                disabled={this.state.titleData && this.state.titleData.depDoctorFlag == 'N' ? true : false}
                                                autoFocus
                                                // value={data.ordMedItemDesc ? data.ordMedItemDesc : this.state.changeValue}
                                                value={data.ordMedItemDesc}
                                                onChange={this.handleSearchInput.bind(this, 'ordMedItemDesc', index)}
                                            /> : <span>{data.ordMedItemDesc}</span>
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordDose') {//剂量
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordDose') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ? <Input style={{ width: '90%' }}
                                            onChange={this.commonInput.bind(this, 'ordDose', index, data)} ref={this.doseFocus}
                                            value={data.ordDose} /> : <span>{data.ordDose}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordDoseUnitID') {//剂量单位
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var doseUnitListOption = []

                                        // var { doseUnitList } = this.state;
                                        var doseUnitList = data.doseUnitList;
                                        doseUnitList && doseUnitList.map((item, index) => {
                                            doseUnitListOption.push(<Option key={index} value={item.doseUnitID} doseMolecule={item.molecule}
                                                doseDenominator={item.denominator}>{item.doseUnitDesc}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordDoseUnitID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ? <Select style={{ width: '90%' }}
                                            onChange={(e, option) => this.changeCommonSelect('ordDoseUnitID', index, data, e, option)} ref={this.ordDescFocus}
                                            value={data.ordDoseUnitID}>{doseUnitListOption}</Select> : <span>{data.ordDoseUnitDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordFreqID') {//频次
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var frequenceListOption = []

                                        // var { frequenceList } = this.state;
                                        var frequenceList = data.frequenceList;
                                        frequenceList && frequenceList.map((item, index) => {
                                            frequenceListOption.push(<Option key={index} value={item.id} code={item.descriptsSPCode} endsp={item.enDescripts}
                                                frequency={item.frequency} cycleDays={item.cycleDays} intervalDays={item.intervalDays}>{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordFreqID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select showSearch onChange={(e, option) => this.changeCommonSelect('ordFreqID', index, data, e, option)}
                                                filterOption={(input, option) =>
                                                    option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                                    || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                                    || option.props.endsp.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                                } ref={this.ordFreqFocus} style={{ width: '90%' }}
                                                onFocus={this.onBlurFreqSelect.bind(this, 'ordFreqID', index, data)}
                                                disabled={data.ordLinkStatus ? true :
                                                    (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                                                value={frequenceList && frequenceList.length > 0 ? data.ordFreqID : data.ordFreqDesc}>{frequenceListOption}</Select> : <span>{data.ordFrequenceDesc}</span>)

                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordUsageID') {//用法
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var usageListOption = []
                                        // var { usageList } = this.state;
                                        var usageList = data.usageList;
                                        usageList && usageList.map((item, index) => {
                                            usageListOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id}>{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordUsageID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select allowClear showSearch onChange={this.changeCommonSelect.bind(this, 'ordUsageID', index, data)} style={{ width: '90%' }}
                                                filterOption={(input, option) =>
                                                    option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                                    || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                                } ref={this.ordUseFocus}
                                                onFocus={this.handleLoadUsage.bind(this, 'ordUsageID', index, data)}
                                                disabled={data.ordLinkStatus ? true :
                                                    (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                                                value={usageList && usageList.length > 0 ? data.ordUsageID : data.ordUsageDesc}>{usageListOption}</Select> : <span>{data.ordUsageDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordDurQty') {//疗程
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordDurQty') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ? <Input value={data.ordDurQty}
                                            ref={this.ordDurFocus} style={{ width: '90%' }}
                                            disabled={data.ordLinkStatus ? true :
                                                (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (this.props.patStatus == '1' ? true : false))}
                                            onChange={this.commonInput.bind(this, 'ordDurQty', index, data)} /> : <span>{data.ordDurQty}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordDurationID') {//疗程单位
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var durationListOption = []

                                        // var { durationList } = this.state;
                                        var durationList = data.durationList;
                                        durationList && durationList.map((item, index) => {
                                            durationListOption.push(<Option key={index} value={item.id} duraFactor={item.factor}>{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordDurationID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select onChange={(e, option) => this.changeCommonSelect('ordDurationID', index, data, e, option)} style={{ width: '90%' }}
                                                disabled={data.ordLinkStatus ? true :
                                                    (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : (this.props.patStatus == '1' ? true : false)))}
                                                value={data.ordDurationID}>{durationListOption}</Select> : <span>{data.ordDurationDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'bodyPartID') {//部位
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var bodyPartListOption = []

                                        // var { recLocList } = this.state;
                                        var bodyPartList = data.bodyPartList;
                                        var newData = []
                                        bodyPartList && bodyPartList.map((item, index) => {
                                            bodyPartListOption.push(<Option key={index} value={item.id} partid={item.id} descripts={item.descripts}
                                                mutexflag={item.mutexFlag} ordprice={Number(item.ordPrice)}
                                            // onClick={this.handleOnSelectColumns.bind(this, 'ordbodyPartID', index, data)}
                                            >{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'bodyPartID') {
                                                    editFlag = true
                                                }
                                            }
                                        }

                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            (data.radioFlag == 'Y' ? <Select style={{ width: '90%' }} onChange={this.changeBodyPartRadio.bind(this, 'ordbodyPartID', index, data)}
                                                disabled={data.ordLinkStatus ? true :
                                                    (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                                                value={data.ordbodyPartID}>{bodyPartListOption}</Select> : <Select style={{ width: '90%' }} onChange={this.changeBodyPartSelect.bind(this, 'ordbodyPartID', index, data)}
                                                    mode='tags'
                                                    disabled={data.ordLinkStatus ? true :
                                                        (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                                                    value={data.ordbodyPartID}>{bodyPartListOption}</Select>) : <span>{data.ordbodyPartDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordQty') {//数量
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //(疗程数*factor*frequency)/cycleDays
                                        if (Util.isEmpty(data.ordSetDetailID)) {
                                            var totalNum = 0;//总次数
                                            var totalDosc = 0;//总剂量
                                            var oneDosc = 0;//剂量
                                            var oneQty = 0;//单次数量
                                            if (data.cycleDays) {//优先使用cycleDays，计算总次数
                                                totalNum = Math.ceil((parseFloat(!Util.isEmpty(data.ordDurQty) ? data.ordDurQty : 1) * parseFloat(data.duraFactor || 1) * parseFloat(data.frequency || 1)) / (data.cycleDays && parseFloat(data.cycleDays) > 0 ? parseFloat(data.cycleDays) : 1))
                                            } else {
                                                totalNum = Math.ceil((parseFloat(!Util.isEmpty(data.ordDurQty) ? data.ordDurQty : 1) * parseFloat(data.duraFactor || 1) * parseFloat(data.frequency || 1)) / (data.intervalDays && parseFloat(data.intervalDays) > 0 ? parseFloat(data.intervalDays) : 1))
                                            }
                                            //门诊
                                            if (data.ordToalCountO == 'Y') {
                                                totalDosc = Math.ceil((parseFloat(data.ordDose ? data.ordDose : 1) * totalNum * parseFloat(!Util.isEmpty(data.doseMolecule) ? data.doseMolecule : 1)).toFixed(2) / (parseFloat(data.doseDenominator) > 0 ? parseFloat(data.doseDenominator) : 1))
                                                //最后算总数量
                                                if (Util.isEmpty(data.duraFactor) || Util.isEmpty(data.ordDurQty) || Util.isEmpty(data.frequency) ||
                                                    Util.isEmpty(data.cycleDays) || Util.isEmpty(data.ordDose) || Util.isEmpty(data.doseMolecule)
                                                    || Util.isEmpty(data.doseDenominator) || Util.isEmpty(data.doseDenominator)) {
                                                    //阿卡波糖片问题，不知为何之前置位1
                                                    totalCount = Math.ceil((totalDosc * parseFloat(data.qtyMolecule ? data.qtyMolecule : 1)) / (parseFloat(data.qtyDenominator) > 0 ? parseFloat(data.qtyDenominator) : 1))
                                                    if (Util.isEmpty(data.ordSetDetailID) /**&& data.qtyStatus == '2'**/) {
                                                        data.newQty = totalCount
                                                        data.totalCount = totalCount
                                                    }
                                                } else {
                                                    totalCount = Math.ceil((totalDosc * parseFloat(data.qtyMolecule ? data.qtyMolecule : 1)) / (parseFloat(data.qtyDenominator) > 0 ? parseFloat(data.qtyDenominator) : 1))
                                                    if (Util.isEmpty(data.ordSetDetailID) /**&& data.qtyStatus == '2'**/) {
                                                        data.newQty = totalCount
                                                        data.totalCount = totalCount
                                                    } else {
                                                        data.totalCount = data.ordQty ? data.ordQty : 1
                                                    }
                                                }
                                            } else {//先取整，再算
                                                oneDosc = Math.ceil((parseFloat(data.ordDose ? data.ordDose : 1) * parseFloat(data.doseMolecule ? data.doseMolecule : 1)) / (parseFloat(data.doseDenominator) > 0 ? parseFloat(data.doseDenominator) : 1))
                                                // totalDosc = oneDosc * totalNum
                                                oneQty = Math.ceil((oneDosc * parseFloat(data.qtyMolecule ? data.qtyMolecule : 1)) / (parseFloat(data.qtyDenominator) > 0 ? parseFloat(data.qtyDenominator) : 1))
                                                data.newQty = oneQty * totalNum
                                            }

                                        }

                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordQty') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ? <Input value={data.medID ? (data.defaultStatus == true ? data.ordQty : data.newQty) : undefined}
                                            style={{ width: '90%' }} onChange={this.commonInput.bind(this, 'ordQty', index, data)} /> : <span>{data.ordQty}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordQtyUomID') {//疗程
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var qtyUnitListOption = []

                                        // var { qtyUnitList } = this.state;
                                        var qtyUnitList = data.qtyUnitList;
                                        qtyUnitList && qtyUnitList.map((item, index) => {
                                            qtyUnitListOption.push(<Option key={index} code={item.price} value={item.unitID} qtyMolecule={item.molecule}
                                                qtyDenominator={item.denominator} price={item.price}>{item.unitDesc}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordQtyUomID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select onChange={(e, option) => this.changeCommonSelect('ordQtyUomID', index, data, e, option)} style={{ width: '90%' }}
                                                value={data.ordQtyUomID}>{qtyUnitListOption}</Select> : <span>{data.ordQtyUomDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordPrice') {//单价
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    className: 'colClassName',
                                    render: (text, data) => {
                                        var price = 0;
                                        var source = data.priceData;
                                        source && source.map((item, index) => {
                                            price += Number(item)
                                        })
                                        if (source) {
                                            data.ordPrice = price
                                        }
                                        //data.nunmber
                                        return <span>{!Util.isEmpty(data.ordID) ? data.ordPrice :
                                            ((data.priceData ? price : data.ordPrice))}</span>
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordSkinTestFlag') {//皮试
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordSkinTestFlag') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Checkbox checked={data.ordSkinTestFlag == 'Y' ? true : (data.ordSkinTestFlagValue == 'Y' ? true : false)}
                                                disabled={editFlag ? true : (data.testFlag == 'N' ? true : false)}
                                                onChange={this.changeCheckBox.bind(this, 'ordSkinTestFlag', index)} /> :
                                            <Checkbox disabled={true} checked={data.ordSkinTestFlag == 'Y' ? true : false} />)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordSkinTestWayID') {//皮试备注
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        // console.log("皮试备注data", data)
                                        var skinTextWayListOption = []

                                        // var { skinTestWayList } = this.state;
                                        var skinTestWayList = data.skinTestWayList;
                                        skinTestWayList && skinTestWayList.map((item, index) => {
                                            skinTextWayListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordSkinTestWayID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select onChange={this.changeCommonSelect.bind(this, 'ordSkinTestWayID', index, data)} style={{ width: '90%' }}
                                                value={data.ordSkinTestWayID}>{skinTextWayListOption}</Select> : <span>{data.ordSkinTestWayDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordPriorityID') {//医嘱优先级
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var priorityListOption = []

                                        // var { priorityList } = this.state;
                                        var priorityList = data.priorityList;
                                        priorityList && priorityList.map((item, index) => {
                                            priorityListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordPriorityID') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select onChange={this.changeCommonSelect.bind(this, 'ordPriorityID', index, data)} style={{ width: '90%' }}

                                                disabled={data.ordLinkStatus ? true :
                                                    (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                                                value={data.ordPriorityID}>{priorityListOption}</Select> : <span>{data.ordPriorityDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordSpecDesc') {//标本
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var specListOption = []

                                        // var { specList } = this.state;
                                        var specList = data.specList;
                                        specList && specList.map((item, index) => {
                                            specListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
                                        })

                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordSpecDesc') {
                                                    editFlag = true
                                                }
                                            }
                                        }

                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select onChange={this.changeCommonSelect.bind(this, 'ordSpecID', index, data)} style={{ width: '90%' }}
                                                value={data.ordSpecID}>{specListOption}</Select> : <span>{data.ordSpecDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordStageID') {//医嘱阶段
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var stageListOption = []

                                        // var { specList } = this.state;
                                        var stageList = data.stageList;
                                        stageList && stageList.map((item, index) => {
                                            stageListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
                                        })

                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordStageID') {
                                                    editFlag = true
                                                }
                                            }
                                        }

                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            //changeBY: DYK
                                            <Select allowClear onChange={this.changeCommonSelect.bind(this, 'ordStageID', index, data)} style={{ width: '90%' }}
                                                value={data.ordStageID}>{stageListOption}</Select> : <span>{data.ordStageDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordPriorityExtID') {//附加说明
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var ordPriorityExtlistOption = []

                                        // var { specList } = this.state;
                                        var priorityExtList = data.priorityExtList;
                                        priorityExtList && priorityExtList.map((item, index) => {
                                            ordPriorityExtlistOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
                                        })

                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordPriorityExtID') {
                                                    editFlag = true
                                                }
                                            }
                                        }

                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            //changeBY: DYK
                                            <Select allowClear onChange={this.changeCommonSelect.bind(this, 'ordPriorityExtID', index, data)} style={{ width: '90%' }}
                                                value={data.ordPriorityExtID}>{ordPriorityExtlistOption}</Select> : <span>{data.ordPriorityExtDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordEMFlag') {//急诊
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordEMFlag') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Checkbox checked={data.ordEMFlag == 'Y' ? true : (data.ordEMFlagValue == 'Y' ? true : false)}
                                                disabled={editFlag ? true : (data.testEMFlag == 'Y' ? false : true)}
                                                onChange={this.changeCheckBox.bind(this, 'ordEMFlag', index)} /> :
                                            <Checkbox disabled={true} checked={data.ordEMFlag == 'Y' ? true : false} />)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordNotea') {//嘱托
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        return Util.isEmpty(data.ordID) ? <Input style={{ width: '90%' }}
                                            onChange={this.commonInput.bind(this, 'ordNotea', index, data)} /> : <span>{data.ordNotea}</span>
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordNote') {//备注
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var ordNoteListtOption = []
                                        var ordNoteList = data.ordNoteList;
                                        var newData = []
                                        ordNoteList && ordNoteList.map((item, index) => {
                                            ordNoteListtOption.push(<Option key={index} value={item.descripts}>{item.descripts}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordNote') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        // return editFlag ? undefined : (Util.isEmpty(data.ordID) ? <Input style={{ width: '90%' }}
                                        //     value={data.ordNote}
                                        //     onChange={this.commonInput.bind(this, 'ordNote', index, data)} /> : <span>{data.ordNote}</span>)
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ? <AutoComplete style={{ width: '90%' }}
                                            value={data.ordNote} dataSource={ordNoteListtOption}
                                            onChange={this.commonInput.bind(this, 'ordNote', index, data)} /> : <span>{data.ordNote}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'ordRecLocID') {//执行科室
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        var recLocListOption = []
                                        // var { recLocList } = this.state;
                                        var recLocList = data.recLocList;

                                        recLocList && recLocList.map((item, index) => {
                                            recLocListOption.push(<Option key={index} value={item.recLocID}>{item.recLocDesc}</Option>)
                                        })
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'ordRecLocID') {
                                                    editFlag = true
                                                }
                                            }
                                        }

                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                                            <Select style={{ width: '90%' }} onChange={this.changeCommonSelect.bind(this, 'ordRecLocID', index, data)}
                                                disabled={data.ordLinkStatus ? true :
                                                    (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                                                value={data.ordRecLocID}>{recLocListOption}</Select> : <span>{data.ordRecLocDesc}</span>)
                                    }
                                })
                            }

                            if (columns[i].dataIndex == 'firstBillFlag') {// 只首次计费标志
                                dynColumns.push({
                                    title: columns[i].title,
                                    dataIndex: columns[i].dataIndex,
                                    width: parseInt(columns[i].width),
                                    align: columns[i].align || 'center',
                                    render: (text, data, index) => {
                                        //置灰编辑框
                                        var unableToEdit = data.unableToEdit;
                                        var editFlag = false;
                                        if (unableToEdit) {
                                            for (var j = 0; j < unableToEdit.length; j++) {
                                                if (unableToEdit[j] == 'firstBillFlag') {
                                                    editFlag = true
                                                }
                                            }
                                        }
                                        return editFlag ? undefined : (Util.isEmpty(data.ordID) ? (
                                            <Checkbox
                                                disabled={editFlag}
                                                checked={data.firstBillFlag == 'Y' ? true : (data.firstBillFlagValue == 'Y' ? true : false)}
                                                onChange={this.changeCheckBox.bind(this, 'firstBillFlag', index)}
                                            />
                                        ) : (
                                            <Checkbox disabled={true} checked={data.firstBillFlag == 'Y' ? true : false} />
                                        ))
                                    }
                                })
                            }

                            // if (columns[i].dataIndex == 'eyePart') {//眼别
                            //     dynColumns.push({
                            //         title: columns[i].title,
                            //         dataIndex: columns[i].dataIndex,
                            //         width: parseInt(columns[i].width),
                            //         align: columns[i].align || 'center',
                            //         render: (text, data, index) => {
                            //             var eyePartListOption = []

                            //             // var { recLocList } = this.state;
                            //             var eyePartList = data.eyePartList;
                            //             var newData = []
                            //             eyePartList && eyePartList.map((item, index) => {
                            //                 eyePartListOption.push(<Option key={index} value={item.id} descripts={item.descripts} name={item.descriptsSPCode}
                            //                 >{item.descripts}</Option>)
                            //             })
                            //             //置灰编辑框
                            //             var unableToEdit = data.unableToEdit;
                            //             var editFlag = false;
                            //             if (unableToEdit) {
                            //                 for (var j = 0; j < unableToEdit.length; j++) {
                            //                     if (unableToEdit[j] == 'eyePartID') {
                            //                         editFlag = true
                            //                     }
                            //                 }
                            //             }

                            //             return editFlag ? undefined : (Util.isEmpty(data.ordID) ?
                            //                 <Select style={{ width: '90%' }} onChange={this.changeCommonSelect.bind(this, 'eyePartID', index, data)}
                            //                     disabled={data.ordLinkStatus ? true :
                            //                         (!Util.isEmpty(data.identity) && this.state.groupStatus && data.checkIdenty == '2' ? true : (!Util.isEmpty(data.mainIndexId) ? true : false))}
                            //                     value={data.eyePartID}>{eyePartListOption}</Select> : <span>{data.eyePartDesc}</span>)
                            //         }
                            //     })
                            // }
                        }
                    }
                    this.setState({
                        dynColumns: dynColumns,
                        totalWidth: res.totalWidth
                    })
                }
            }
        });
    }

    handleLoadUsage(name, index, data, e) {
        var params = {
            params: [{
                medID: data.medID,
                hospID: this.state.userData.hospID
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040065",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.state.dataSource[index]['usageList'] = res.data
                    this.setState({})
                }
            }
        });
    }

    onBlurFreqSelect(name, index, data, e) {
        var params = {
            params: [{
                hospID: this.state.userData.hospID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050143",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.state.dataSource[index]['frequenceList'] = res.result
                    this.setState({})
                }
            }
        });
    }

    changeMedItemDescFocus(index) {
        this.setState({
            edit: false
        })
    }

    showCommonTableModal(index, e) {
        if (e.keyCode == '13') {
            // this.state.dataSource[index] = {}
            this.setState({
                isShowCommonTableModal: true,
                indexTable: index//删除一条空数据，重新添加
            }, () => {
                this.loadSelectData(this.state.changeValue, '', '')
                this.child.showModal();
            })
        }
    }

    //列修改为input框，change事件处理
    handleSearchInput(name, index, e) {
        var { dataSource } = this.state;
        let top = document.getElementById('name-input' + index).getBoundingClientRect().top + 40;
        let left = document.getElementById('name-input' + index).getBoundingClientRect().left + 'px';
        let windowHeight = window.innerHeight;
        if ((top + 360) > windowHeight) {
            top = top - 330 - 80 + 'px';
        }
        var value = e.target.value;
        //change名称规格的时候，讲关联关系去除
        if (Util.isEmpty(value)) {
            for (var i = 0; i < dataSource.length; i++) {
                if (dataSource[i].ordLinkStatus || dataSource[i].identity) {
                    // dataSource[i].identity = ''
                    // dataSource[i].ordLinkStatus = false
                    // dataSource[i].ordLinkSeqNo = undefined
                }
            }
            this.state.dataSource[index] = { tabIndex: index + 1 }
        }
        this.state.dataSource[index][name] = value
        this.setState({
            changeValue: value,
            indexTab: index,
            top: top,
            left: left
        })
        if (value.length >= 2) {
            // this.loadSelectData(value, '', '')
        } else {
            this.setState({
                selectData: [],
                total: 0,
                page: 1,
            })
        }
        document.addEventListener('elementTable', this.loadListener)
    }

    editData(data) {
        this.setState({
            isShowCompleteMedicalModal: true,
            cpmpleteData: data
        })
    }

    handleDel(data) {
        var params = {
            params: [{
                userID: this.state.userData.userID,
                ordSetID: data.ordSetID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050062",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('删除成功！', this.state.userData && this.state.userData.messageTime)
                    this.loadLeftData()
                }
            }
        });
    }

    loadData() {

    }

    loadLeftData = (page, pageSize, e) => {
        var params = {
            params: [{
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                groupID: this.state.userData.groupID,
                activeFlag: this.state.activeFlag,
                selfFlag: this.state.selfFlag,
                searchCode: this.state.searchCode,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050060",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        leftData: res.data.list || [],
                    })
                }
            }
        });
    }

    //分页切换
    onChange(e) {
        this.setState({ page: e }, () => {
            this.loadData(e);
        });
    }

    //分页切换
    changePageSize(current, pageSize) {
        this.setState({ pageSize: pageSize, page: current }, () => {
            this.loadSelectData('', current, pageSize, 'search');
        });
    }

    changeLeftCheckBox(name, e) {
        this.setState({
            [name]: e.target.checked ? 'Y' : 'N'
        }, () => {
            this.loadLeftData()
        })
    }

    changeExpanded(expaded, record) {
        let id = record.id;
        if (Util.isEmpty(this.state.subrateData[id])) {
            this.fetchsubMerchant(id);
        }
    }

    loadListData(e) {
        if (e.keyCode == '13') {
            var params = {
                params: [{
                    userID: this.state.userData.userID,
                    locID: this.state.userData.locID,
                    hospID: this.state.userData.hospID,
                    groupID: this.state.userData.groupID,
                    activeFlag: this.state.activeFlag,
                    selfFlag: this.state.selfFlag,
                    searchCode: this.state.searchCode,
                }]
            }
            $http.post('urlDeault', this, {
                code: "03050060",
                data: params,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setState({
                            leftData: res.data.list,
                        })
                    }
                }
            });
        }
    }

    setRowElement = (record, index) => {
        return {
            onDoubleClick: () => {
                this.rowClick(record, index)
            }
        }
    }

    rowClick = (record, index) => {
        if (!Util.isEmpty(record.ordSetID)) {
            message.error('医嘱套维护中无法添加医嘱套，请重新选择', this.state.userData && this.state.userData.messageTime)
            return
        }
        this.setState({
            visible: false,
            rowData: record.medDesc,
            ordSpecID: record.ordSpecID,
            selectData: [],
            visStatus: false,
            // changeValue: undefined
        }, () => {
            this.child.handleCancel();
            this.loadTableData('', record, index)
        })
    }

    //获取列表行数据
    loadTableData(status, record, data) {
        var that = this;
        var date = new Date();
        var params = {
            params: [{
                orders: [{
                    medID: status == 'temp' ? data.props.nodeId : (status == 'batch' ? record[0].medID : record.medID),
                    ordSetID: status == 'temp' ? data.props.ordSetID : (status == 'batch' ? record[0].ordSetID : record.ordSetID || '')
                }]
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050020",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    if (res.errorData.length > 0) {
                        this.setState({
                            isShowConfirmModal: true,
                            errorData: res.errorData,
                            confirmData: res.confirmData,
                        })
                        return
                    }
                    if (res.confirmData.length > 0) {
                        confirm({
                            title: '确认医嘱',
                            content: res.confirmData[0].errorMessage,
                            onOk() {
                                //双击医嘱项，根据index，渲染对应行的默认数据
                                that.state.dataSource[that.state.indexTable]['ordMedItemDesc'] = res.data[0].defaultData.ordDesc,
                                    that.state.dataSource[that.state.indexTable]['ordDose'] = res.data[0].defaultData.ordDose,
                                    that.state.dataSource[that.state.indexTable]['ordDoseUnitID'] = res.data[0].defaultData.ordDoseUnitID,
                                    // that.state.dataSource[that.state.indexTable]['ordFreqID'] = res.data[0].defaultData.ordFrequenceID,
                                    that.state.dataSource[that.state.indexTable]['ordFreqID'] = res.data[0].defaultData.ordFreqID,
                                    that.state.dataSource[that.state.indexTable]['ordFreqDesc'] = res.data[0].defaultData.ordFreqDesc,
                                    that.state.dataSource[that.state.indexTable]['doseMolecule'] = res.data[0].defaultData.doseMolecule,
                                    that.state.dataSource[that.state.indexTable]['doseDenominator'] = res.data[0].defaultData.doseDenominator,
                                    that.state.dataSource[that.state.indexTable]['ordUsageDesc'] = (res.data[0].defaultData.ordSkinTestFlag == 'Y' || res.data[0].defaultData.ordSkinTestFlagValue == 'Y') ?
                                        res.data[0].defaultData.ordSkinTestUsageDesc : res.data[0].defaultData.ordUsageDesc,
                                    that.state.dataSource[that.state.indexTable]['ordUsageID'] = (res.data[0].defaultData.ordSkinTestFlag == 'Y' || res.data[0].defaultData.ordSkinTestFlagValue == 'Y') ?
                                        res.data[0].defaultData.ordSkinTestUsageID : res.data[0].defaultData.ordUsageID,
                                    that.state.dataSource[that.state.indexTable]['ordSkinTestUsageID'] = res.data[0].defaultData.ordSkinTestUsageID,
                                    that.state.dataSource[that.state.indexTable]['defaultStatus'] = true,
                                    that.state.dataSource[that.state.indexTable]['ordSkinTestUsageDesc'] = res.data[0].defaultData.ordSkinTestUsageDesc,
                                    that.state.dataSource[that.state.indexTable]['ordSetDetailID'] = res.data[0].defaultData.ordSetDetailID,
                                    that.state.dataSource[that.state.indexTable]['ordUsageID'] = res.data[0].defaultData.ordUsageID,
                                    that.state.dataSource[that.state.indexTable]['ordDurQty'] = res.data[0].defaultData.ordDurQty,
                                    that.state.dataSource[that.state.indexTable]['ordDurationID'] = res.data[0].defaultData.ordDurationID,
                                    that.state.dataSource[that.state.indexTable]['ordQty'] = res.data[0].defaultData.ordQty,
                                    that.state.dataSource[that.state.indexTable]['ordQtyUomID'] = res.data[0].defaultData.ordQtyUomID,
                                    that.state.dataSource[that.state.indexTable]['radioFlag'] = res.data[0].defaultData.radioFlag,
                                    that.state.dataSource[that.state.indexTable]['frequency'] = res.data[0].defaultData.frequency,
                                    that.state.dataSource[that.state.indexTable]['cycleDays'] = res.data[0].defaultData.cycleDays,
                                    that.state.dataSource[that.state.indexTable]['ordStageID'] = res.data[0].defaultData.ordStageID,
                                    that.state.dataSource[that.state.indexTable]['ordPriorityExtID'] = res.data[0].defaultData.ordPriorityExtID,
                                    that.state.dataSource[that.state.indexTable]['eyePartDesc'] = res.data[0].defaultData.eyePartDesc,
                                    that.state.dataSource[that.state.indexTable]['eyePartID'] = res.data[0].defaultData.eyePartID,
                                    that.state.dataSource[that.state.indexTable]['ordbodyPartID'] = res.data[0].defaultData.ordbodyPartID,
                                    that.state.dataSource[that.state.indexTable]['ordbodyPartDesc'] = res.data[0].defaultData.ordbodyPartDesc,
                                    that.state.dataSource[that.state.indexTable]['intervalDays'] = res.data[0].defaultData.intervalDays,
                                    that.state.dataSource[that.state.indexTable]['duraFactor'] = res.data[0].defaultData.duraFactor,
                                    that.state.dataSource[that.state.indexTable]['ordPrice'] = res.data[0].defaultData.ordPrice,
                                    that.state.dataSource[that.state.indexTable]['ordSkinTestFlag'] = res.data[0].defaultData.ordSkinTestFlag,
                                    that.state.dataSource[that.state.indexTable]['ordSkinTestFlagValue'] = res.data[0].defaultData.ordSkinTestFlagValue,
                                    that.state.dataSource[that.state.indexTable]['ordEMFlagValue'] = res.data[0].defaultData.ordEMFlagValue,
                                    that.state.dataSource[that.state.indexTable]['ordEMFlag'] = res.data[0].defaultData.ordEMFlag,
                                    that.state.dataSource[that.state.indexTable]['testEMFlag'] = res.data[0].defaultData.ordEMFlag,
                                    that.state.dataSource[that.state.indexTable]['ordToalCountO'] = res.data[0].defaultData.ordToalCountO,
                                    that.state.dataSource[that.state.indexTable]['firstBillFlag'] = res.data[0].defaultData.firstBillFlag,
                                    that.state.dataSource[that.state.indexTable]['testFlag'] = res.data[0].defaultData.ordSkinTestFlag,
                                    that.state.dataSource[that.state.indexTable]['ordSkinTestWayID'] = res.data[0].defaultData.ordSkinTestWayID,
                                    that.state.dataSource[that.state.indexTable]['ordRecLocID'] = res.data[0].defaultData.ordRecLocID,
                                    that.state.dataSource[that.state.indexTable]['ordPriorityID'] = res.data[0].defaultData.ordPriorityID,
                                    that.state.dataSource[that.state.indexTable]['medDesca'] = res.data[0].defaultData.ordDesca,
                                    that.state.dataSource[that.state.indexTable]['duraFactor'] = res.data[0].defaultData.duraFactor,
                                    that.state.dataSource[that.state.indexTable]['ordAdmReasonID'] = res.data[0].defaultData.ordAdmReasonID,
                                    that.state.dataSource[that.state.indexTable]['ordSeqNo'] = parseInt(that.state.indexTable) + 1,
                                    that.state.dataSource[that.state.indexTable]['ordDate'] = moment(date).format(dayFormat),
                                    that.state.dataSource[that.state.indexTable]['ordTime'] = moment(date).format(timeFormat),
                                    that.state.dataSource[that.state.indexTable]['ordStartDate'] = moment(date).format(dayFormat),
                                    that.state.dataSource[that.state.indexTable]['ordStartTime'] = moment(date).format(timeFormat),
                                    that.state.dataSource[that.state.indexTable]['ordNote'] = res.data[0].defaultData.ordNote,
                                    that.state.dataSource[that.state.indexTable]['medID'] = res.data[0].defaultData.medID,
                                    that.state.dataSource[that.state.indexTable]['ordMedItemID'] = status == 'temp' ? data.props.nodeId : (status == 'batch' ? record : record.medID),
                                    that.state.dataSource[that.state.indexTable]['ordTypeCode'] = res.data[0].defaultData.ordTypeCode,
                                    that.state.dataSource[that.state.indexTable]['ordSpecID'] = res.data[0].defaultData.ordSpecID,
                                    that.state.dataSource[that.state.indexTable]['specList'] = res.data[0].dataList.specList,
                                    that.state.dataSource[that.state.indexTable]['doseUnitList'] = res.data[0].dataList.doseUnitList,
                                    that.state.dataSource[that.state.indexTable]['bodyPartList'] = res.data[0].dataList.bodyPartList,
                                    that.state.dataSource[that.state.indexTable]['durationList'] = res.data[0].dataList.durationList,
                                    that.state.dataSource[that.state.indexTable]['qtyUnitList'] = res.data[0].dataList.qtyUnitList,
                                    that.state.dataSource[that.state.indexTable]['recLocList'] = res.data[0].dataList.recLocList,
                                    // that.state.dataSource[that.state.indexTable]['frequenceList'] = res.data[0].dataList.frequenceList,
                                    // that.state.dataSource[that.state.indexTable]['usageList'] = res.data[0].dataList.usageList,
                                    that.state.dataSource[that.state.indexTable]['skinTestWayList'] = res.data[0].dataList.skinTestWayList,
                                    that.state.dataSource[that.state.indexTable]['eyePartList'] = res.data[0].dataList.eyePartList,
                                    that.state.dataSource[that.state.indexTable]['stageList'] = res.data[0].dataList.stageList,
                                    that.state.dataSource[that.state.indexTable]['priorityExtList'] = res.data[0].dataList.priorityExtList,
                                    that.state.dataSource[that.state.indexTable]['priorityList'] = res.data[0].dataList.priorityList,
                                    that.state.dataSource[that.state.indexTable]['admReasonList'] = res.data[0].dataList.admReasonList,
                                    that.state.dataSource[that.state.indexTable]['unableToEdit'] = res.data[0].unableToEdit,
                                    that.state.dataSource[that.state.indexTable]['ordNoteList'] = res.data[0].dataList.ordNoteList,
                                    that.setState({
                                        tableData: res.data[0].defaultData,
                                        doseUnitList: res.data[0].dataList.doseUnitList,//剂量单位
                                        durationList: res.data[0].dataList.durationList,//疗程单位
                                        qtyUnitList: res.data[0].dataList.qtyUnitList,//数量单位
                                        recLocList: res.data[0].dataList.recLocList,//接收科室
                                        frequenceList: res.data[0].dataList.frequenceList,//频次
                                        usageList: res.data[0].dataList.usageList,//用法
                                        ordNoteList: res.data[0].dataList.ordNoteList,//备注
                                        skinTestWayList: res.data[0].dataList.skinTestWayList,//皮试备注
                                        eyePartList: res.data[0].dataList.eyePartList,//皮试备注
                                        priorityList: res.data[0].dataList.priorityList,//优先级
                                        admReasonList: res.data[0].dataList.admReasonList,
                                        bodyPartList: res.data[0].dataList.bodyPartList,
                                        changeValue: undefined
                                        // specList: res.data[0].dataList.specList,//标本
                                    })
                            },
                            onCancel() {
                                console.log('Cancel');
                            },
                        });
                    } else {
                        //双击医嘱项，根据index，渲染对应行的默认数据
                        this.state.dataSource[this.state.indexTable]['ordMedItemDesc'] = res.data[0].defaultData.ordDesc,
                            this.state.dataSource[this.state.indexTable]['ordDose'] = res.data[0].defaultData.ordDose,
                            this.state.dataSource[this.state.indexTable]['ordDoseUnitID'] = res.data[0].defaultData.ordDoseUnitID,
                            // this.state.dataSource[this.state.indexTable]['ordFreqID'] = res.data[0].defaultData.ordFrequenceID,
                            this.state.dataSource[this.state.indexTable]['ordFreqID'] = res.data[0].defaultData.ordFreqID,
                            this.state.dataSource[this.state.indexTable]['ordSetDetailID'] = res.data[0].defaultData.ordSetDetailID,
                            this.state.dataSource[this.state.indexTable]['ordUsageID'] = res.data[0].defaultData.ordUsageID,
                            this.state.dataSource[this.state.indexTable]['ordbodyPartID'] = res.data[0].defaultData.ordbodyPartID,
                            this.state.dataSource[this.state.indexTable]['ordPriorityExtID'] = res.data[0].defaultData.ordPriorityExtID,
                            this.state.dataSource[this.state.indexTable]['ordbodyPartDesc'] = res.data[0].defaultData.ordbodyPartDesc,
                            that.state.dataSource[that.state.indexTable]['ordFreqDesc'] = res.data[0].defaultData.ordFreqDesc,
                            that.state.dataSource[that.state.indexTable]['ordToalCountO'] = res.data[0].defaultData.ordToalCountO,
                            that.state.dataSource[that.state.indexTable]['duraFactor'] = res.data[0].defaultData.duraFactor,
                            that.state.dataSource[that.state.indexTable]['doseDenominator'] = res.data[0].defaultData.doseDenominator,
                            that.state.dataSource[that.state.indexTable]['doseMolecule'] = res.data[0].defaultData.doseMolecule,
                            that.state.dataSource[that.state.indexTable]['frequency'] = res.data[0].defaultData.frequency,
                            that.state.dataSource[that.state.indexTable]['cycleDays'] = res.data[0].defaultData.cycleDays,
                            that.state.dataSource[that.state.indexTable]['defaultStatus'] = true,
                            that.state.dataSource[that.state.indexTable]['ordStageID'] = res.data[0].defaultData.ordStageID,
                            that.state.dataSource[that.state.indexTable]['intervalDays'] = res.data[0].defaultData.intervalDays,
                            that.state.dataSource[that.state.indexTable]['ordUsageDesc'] = (res.data[0].defaultData.ordSkinTestFlag == 'Y' || res.data[0].defaultData.ordSkinTestFlagValue == 'Y') ?
                                res.data[0].defaultData.ordSkinTestUsageDesc : res.data[0].defaultData.ordUsageDesc,
                            that.state.dataSource[that.state.indexTable]['ordUsageID'] = (res.data[0].defaultData.ordSkinTestFlag == 'Y' || res.data[0].defaultData.ordSkinTestFlagValue == 'Y') ?
                                res.data[0].defaultData.ordSkinTestUsageID : res.data[0].defaultData.ordUsageID,
                            that.state.dataSource[that.state.indexTable]['ordSkinTestUsageID'] = res.data[0].defaultData.ordSkinTestUsageID,
                            that.state.dataSource[that.state.indexTable]['ordSkinTestUsageDesc'] = res.data[0].defaultData.ordSkinTestUsageDesc,
                            this.state.dataSource[this.state.indexTable]['ordDurQty'] = res.data[0].defaultData.ordDurQty,
                            this.state.dataSource[this.state.indexTable]['ordDurationID'] = res.data[0].defaultData.ordDurationID,
                            this.state.dataSource[this.state.indexTable]['ordQty'] = res.data[0].defaultData.ordQty,
                            this.state.dataSource[this.state.indexTable]['radioFlag'] = res.data[0].defaultData.radioFlag,
                            this.state.dataSource[this.state.indexTable]['ordQtyUomID'] = res.data[0].defaultData.ordQtyUomID,
                            this.state.dataSource[this.state.indexTable]['ordPrice'] = res.data[0].defaultData.ordPrice,
                            this.state.dataSource[this.state.indexTable]['ordSkinTestFlag'] = res.data[0].defaultData.ordSkinTestFlag,
                            this.state.dataSource[this.state.indexTable]['firstBillFlag'] = res.data[0].defaultData.firstBillFlag,
                            this.state.dataSource[this.state.indexTable]['ordEMFlag'] = res.data[0].defaultData.ordEMFlag,
                            this.state.dataSource[this.state.indexTable]['testEMFlag'] = res.data[0].defaultData.ordEMFlag,
                            this.state.dataSource[this.state.indexTable]['testFlag'] = res.data[0].defaultData.ordSkinTestFlag,
                            this.state.dataSource[this.state.indexTable]['ordSkinTestFlagValue'] = res.data[0].defaultData.ordSkinTestFlagValue,
                            this.state.dataSource[this.state.indexTable]['ordEMFlagValue'] = res.data[0].defaultData.ordEMFlagValue,
                            this.state.dataSource[this.state.indexTable]['eyePartID'] = res.data[0].defaultData.eyePartID,
                            this.state.dataSource[this.state.indexTable]['eyePartDesc'] = res.data[0].defaultData.eyePartDesc,
                            this.state.dataSource[this.state.indexTable]['ordSkinTestWayID'] = res.data[0].defaultData.ordSkinTestWayID,
                            this.state.dataSource[this.state.indexTable]['ordRecLocID'] = res.data[0].defaultData.ordRecLocID,
                            this.state.dataSource[this.state.indexTable]['ordPriorityID'] = res.data[0].defaultData.ordPriorityID,
                            this.state.dataSource[this.state.indexTable]['medDesca'] = res.data[0].defaultData.ordDesca,
                            this.state.dataSource[this.state.indexTable]['ordAdmReasonID'] = res.data[0].defaultData.ordAdmReasonID,
                            this.state.dataSource[this.state.indexTable]['ordSeqNo'] = parseInt(this.state.indexTable) + 1,
                            this.state.dataSource[this.state.indexTable]['ordDate'] = moment(date).format(dayFormat),
                            this.state.dataSource[this.state.indexTable]['ordTime'] = moment(date).format(timeFormat),
                            this.state.dataSource[this.state.indexTable]['ordStartDate'] = moment(date).format(dayFormat),
                            this.state.dataSource[this.state.indexTable]['ordStartTime'] = moment(date).format(timeFormat),
                            this.state.dataSource[this.state.indexTable]['ordNote'] = res.data[0].defaultData.ordNote,
                            that.state.dataSource[that.state.indexTable]['medID'] = res.data[0].defaultData.medID,
                            this.state.dataSource[this.state.indexTable]['ordMedItemID'] = status == 'temp' ? data.props.nodeId : (status == 'batch' ? record : record.medID),
                            this.state.dataSource[this.state.indexTable]['ordTypeCode'] = res.data[0].defaultData.ordTypeCode,
                            this.state.dataSource[this.state.indexTable]['ordSpecID'] = res.data[0].defaultData.ordSpecID,
                            that.state.dataSource[that.state.indexTable]['specList'] = res.data[0].dataList.specList,
                            that.state.dataSource[that.state.indexTable]['doseUnitList'] = res.data[0].dataList.doseUnitList,
                            that.state.dataSource[that.state.indexTable]['durationList'] = res.data[0].dataList.durationList,
                            that.state.dataSource[that.state.indexTable]['qtyUnitList'] = res.data[0].dataList.qtyUnitList,
                            that.state.dataSource[that.state.indexTable]['priorityExtList'] = res.data[0].dataList.priorityExtList,
                            that.state.dataSource[that.state.indexTable]['stageList'] = res.data[0].dataList.stageList,
                            that.state.dataSource[that.state.indexTable]['recLocList'] = res.data[0].dataList.recLocList,
                            // that.state.dataSource[that.state.indexTable]['frequenceList'] = res.data[0].dataList.frequenceList,
                            // that.state.dataSource[that.state.indexTable]['usageList'] = res.data[0].dataList.usageList,
                            that.state.dataSource[that.state.indexTable]['skinTestWayList'] = res.data[0].dataList.skinTestWayList,
                            that.state.dataSource[that.state.indexTable]['priorityList'] = res.data[0].dataList.priorityList,
                            that.state.dataSource[that.state.indexTable]['admReasonList'] = res.data[0].dataList.admReasonList,
                            that.state.dataSource[that.state.indexTable]['eyePartList'] = res.data[0].dataList.eyePartList,
                            that.state.dataSource[that.state.indexTable]['bodyPartList'] = res.data[0].dataList.bodyPartList,
                            this.state.dataSource[this.state.indexTable]['unableToEdit'] = res.data[0].unableToEdit,
                            this.state.dataSource[this.state.indexTable]['ordNoteList'] = res.data[0].dataList.ordNoteList,
                            this.setState({
                                tableData: res.data[0].defaultData,
                                doseUnitList: res.data[0].dataList.doseUnitList,//剂量单位
                                durationList: res.data[0].dataList.durationList,//疗程单位
                                qtyUnitList: res.data[0].dataList.qtyUnitList,//数量单位
                                recLocList: res.data[0].dataList.recLocList,//接收科室
                                frequenceList: res.data[0].dataList.frequenceList,//频次
                                eyePartList: res.data[0].dataList.eyePartList,//频次
                                usageList: res.data[0].dataList.usageList,//用法
                                skinTestWayList: res.data[0].dataList.skinTestWayList,//皮试备注
                                priorityList: res.data[0].dataList.priorityList,//优先级
                                admReasonList: res.data[0].dataList.admReasonList,
                                ordNoteList: res.data[0].dataList.ordNoteList,
                                bodyPartList: res.data[0].dataList.bodyPartList,
                                changeValue: undefined
                                // specList: res.data[0].dataList.specList,//标本
                            })
                    }
                    this.deleteNullData()
                }
            }
        });
    }

    //隐藏弹出框
    hideModal(name) {
        this.setState({
            [name]: false,//将所有参数置为false
            cpmpleteData: {}
        });
    }

    //成套医嘱弹框
    showCompleteMedicalModal() {
        this.setState({
            isShowCompleteMedicalModal: true
        })
    }

    //关联号相关逻辑
    changeOrdLinkInput(name, index, data, e) {
        var { dataSource } = this.state;
        var value = e.target.value;
        //获取子医嘱的下拉数据，校验是否可以分组
        var useageID = ''//用法id
        var array = []//用法数组
        var frequenceID = ''//频次id
        var frequenceList = []//频次数组
        var recLocList = []//执行科室
        var recLocID = ''
        var flag = false
        var freFlag = false
        var recFlag = false
        if (value == data.tabIndex) {
            message.error('关联号不能与自己关联，请重新输入！', this.state.userData && this.state.userData.messageTime)
            return
        }
        if (value > this.state.dataSource.length) {
            message.error('您输入的关联号已超出当前可输入范围，请输入正确的关联号！', this.state.userData && this.state.userData.messageTime)
            return
        }
        /**
         * @ByDYK: 组号关联序号限制
         * Create 2022-2-14
         */
        //  createBY:DYK
        if (value > data.tabIndex) {
            message.error('您输入的关联号不能大于当前序号，否则会导致数据丢失！', this.state.userData && this.state.userData.messageTime)
            return
        }

        for (let i = 0; i < dataSource.length; i++) {
            let nextSeqNo = dataSource[i].ordLinkSeqNo;
            let nextIndex = dataSource[i].tabIndex;
            if (data.tabIndex === +nextSeqNo) {
                message.error('当前项已被其它组号关联，不能多级关联！');
                return
            }
            if (+value === nextIndex) {
                if (nextSeqNo !== '') {
                    message.error('您关联的组号已关联了其它组号，不能多级关联！');
                    return
                }
            }
        }

        if (!Util.isEmpty(value)) {
            useageID = this.state.dataSource[value - 1].ordUsageID
            array = this.state.dataSource[index].usageList
            frequenceID = this.state.dataSource[value - 1].ordFreqID
            frequenceList = this.state.dataSource[index].frequenceList
            recLocID = this.state.dataSource[value - 1].ordRecLocID
            recLocList = this.state.dataSource[index].recLocList
            //用法
            if (!Util.isEmpty(array)) {
                for (var j = 0; j < array.length; j++) {
                    if (useageID == array[j].id) {
                        flag = false
                        break
                    } else {
                        flag = true
                    }
                }
            }
            //频次
            if (!Util.isEmpty(frequenceList)) {
                for (var j = 0; j < frequenceList.length; j++) {
                    if (frequenceID == frequenceList[j].id) {
                        freFlag = false
                        break
                    } else {
                        freFlag = true
                    }
                }
            }
            //科室
            if (!Util.isEmpty(recLocList)) {
                for (var j = 0; j < recLocList.length; j++) {
                    if (recLocID == recLocList[j].recLocID) {
                        recFlag = false
                        break
                    } else {
                        recFlag = true
                    }
                }
            }

            if (flag === true) {
                message.error('关联子项中，无该用法，无法关联！', this.state.userData && this.state.userData.messageTime)
                return
            }
            if (freFlag === true) {
                message.error('关联子项中，无该频次，无法关联！', this.state.userData && this.state.userData.messageTime)
                return
            }
            if (recFlag === true) {
                message.error('关联子项中，无该科室，无法关联！', this.state.userData && this.state.userData.messageTime)
                return
            }
        }
        for (var i = 0; i < dataSource.length; i++) {
            if (dataSource[i].tabIndex - 1 == index && !Util.isEmpty(value)) {
                this.state.dataSource[index][name] = value,
                    this.state.dataSource[index]['ordLinkStatus'] = true
                this.state.dataSource[index]['ordDurQty'] = this.state.dataSource[value - 1].ordDurQty
                this.state.dataSource[index]['ordFreqID'] = this.state.dataSource[value - 1].ordFreqID
                this.state.dataSource[index]['ordFrequenceDesc'] = this.state.dataSource[value - 1].ordFrequenceDesc
                this.state.dataSource[index]['ordUsageDesc'] = this.state.dataSource[value - 1].ordUsageDesc
                this.state.dataSource[index]['ordUsageID'] = this.state.dataSource[value - 1].ordUsageID
                this.state.dataSource[index]['ordDurationDesc'] = this.state.dataSource[value - 1].ordDurationDesc
                this.state.dataSource[index]['ordDurationID'] = this.state.dataSource[value - 1].ordDurationID
                this.state.dataSource[index]['ordPriorityDesc'] = this.state.dataSource[value - 1].ordPriorityDesc
                this.state.dataSource[index]['ordPriorityID'] = this.state.dataSource[value - 1].ordPriorityID
                this.state.dataSource[index]['ordEMFlag'] = this.state.dataSource[value - 1].ordEMFlag
                this.state.dataSource[index]['ordRecLocDesc'] = this.state.dataSource[value - 1].ordRecLocDesc
                this.state.dataSource[index]['ordRecLocID'] = this.state.dataSource[value - 1].ordRecLocID
            }

            if (Util.isEmpty(value)) {
                this.state.dataSource[index][name] = value,
                    this.state.dataSource[index]['ordLinkStatus'] = false,
                    this.state.dataSource[index]['mainIndexId'] = ''
            }
            if (dataSource[i].tabIndex - 1 == value && !Util.isEmpty(value)) {
                this.state.dataSource[value - 1]['moveStatus'] = true,
                    this.state.dataSource[index]['dataCode'] = dataSource[i].tabIndex
            }
        }
        this.setState({ inputIndex: index, linkValue: e.target.value })
    }

    //当前组件内，所有的下拉，针对index进行赋值
    changeCommonSelect(name, index, data, e, option) {
        var { dataSource, ids } = this.state;
        //判断是否是分组并且是否勾选
        if (this.state.groupStatus && data.checkIdenty == '2' && ids.length > 1) {
            for (var i = 0; i < dataSource.length; i++) {
                for (var j = 0; j < ids.length; j++) {
                    if (ids[j] == dataSource[i].ordID) {
                        return
                    } else {
                        if (name == 'ordFreqID' && dataSource[i].checkIdenty == '2' && ids[j] == dataSource[i].tabIndex) {
                            this.state.dataSource[i][name] = e
                            this.state.dataSource[index]['ordNewQty'] = ''
                            this.state.dataSource[index]['defaultStatus'] = ''
                            this.state.dataSource[i]['frequency'] = option.props.frequency ? option.props.frequency : dataSource[i].frequency
                            this.state.dataSource[i]['qtyStatus'] = '2'
                            this.state.dataSource[i]['cycleDays'] = option.props.cycleDays ? option.props.cycleDays : dataSource[i].cycleDays
                            this.state.dataSource[i]['intervalDays'] = option.props.intervalDays ? option.props.intervalDays : dataSource[i].intervalDays
                        } else if (name == 'ordDurationID' && dataSource[i].checkIdenty == '2' && ids[j] == dataSource[i].tabIndex) {
                            this.state.dataSource[i][name] = e
                            this.state.dataSource[index]['ordNewQty'] = ''
                            this.state.dataSource[index]['defaultStatus'] = ''
                            this.state.dataSource[i]['duraFactor'] = option.props.duraFactor ? option.props.duraFactor : dataSource[i].duraFactor
                            this.state.dataSource[i]['qtyStatus'] = '2'
                        } else if ((name == 'ordQtyUomID' || name == 'ordUsageID') && dataSource[i].checkIdenty == '2' && ids[j] == dataSource[i].tabIndex) {
                            this.state.dataSource[i][name] = e
                            this.state.dataSource[index]['ordNewQty'] = ''
                            this.state.dataSource[index]['defaultStatus'] = ''
                            this.state.dataSource[index]['ordPrice'] = option.props.ordPrice ? option.props.ordPrice : dataSource[i].ordPrice
                            this.state.dataSource[i]['qtyStatus'] = '2'
                        } else if (name == 'ordPriorityID' && dataSource[i].checkIdenty == '2' && ids[j] == dataSource[i].tabIndex) {
                            this.state.dataSource[i][name] = e
                            this.state.dataSource[i]['qtyStatus'] = '2'
                            // this.loadDisableColumn(data, index, e)
                            this.state.dataSource[index]['ordNewQty'] = ''
                            this.state.dataSource[index]['defaultStatus'] = ''
                            this.state.ordPriorityID = e
                        } else if (name == 'ordPriorityID') {
                            this.loadDisableColumn(data, index, e)
                            this.state.dataSource[index]['ordNewQty'] = ''
                            this.state.dataSource[index]['defaultStatus'] = ''
                        } else {
                            if (option) {
                                this.state.dataSource[index][name] = e
                                this.state.dataSource[index]['frequency'] = option.props.frequency ? option.props.frequency : dataSource[i].frequency
                                this.state.dataSource[index]['cycleDays'] = option.props.cycleDays ? option.props.cycleDays : dataSource[i].cycleDays
                                this.state.dataSource[index]['intervalDays'] = option.props.intervalDays ? option.props.intervalDays : dataSource[i].intervalDays
                                this.state.dataSource[index]['duraFactor'] = option.props.duraFactor ? option.props.duraFactor : dataSource[i].duraFactor
                                this.state.dataSource[index]['doseDenominator'] = option.props.doseDenominator ? option.props.doseDenominator : dataSource[i].doseDenominator
                                this.state.dataSource[index]['doseMolecule'] = option.props.doseMolecule ? option.props.doseMolecule : dataSource[i].doseMolecule
                                this.state.dataSource[index]['qtyMolecule'] = option.props.qtyMolecule ? option.props.qtyMolecule : dataSource[i].qtyMolecule
                                this.state.dataSource[index]['qtyDenominator'] = option.props.qtyDenominator ? option.props.qtyDenominator : dataSource[i].qtyDenominator
                                this.state.dataSource[i]['qtyStatus'] = '2'
                                this.state.dataSource[index]['defaultStatus'] = ''
                            } else {
                                this.state.dataSource[index][name] = e
                                this.state.dataSource[index]['defaultStatus'] = ''
                                this.state.dataSource[i]['qtyStatus'] = '2'
                            }
                        }
                    }
                }
            }
        } else {
            for (var i = 0; i < dataSource.length; i++) {
                if (name == 'ordFreqID' && dataSource[i].ordLinkSeqNo == data.tabIndex && this.state.cannelStatus === false) {
                    this.state.dataSource[i][name] = e
                    this.state.dataSource[index]['ordNewQty'] = ''
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.dataSource[i]['frequency'] = option.props.frequency
                    this.state.dataSource[i]['cycleDays'] = option.props.cycleDays
                    this.state.dataSource[i]['qtyStatus'] = '2'
                    this.state.dataSource[i]['intervalDays'] = option.props.intervalDays
                } else if (name == 'ordDurationID' && dataSource[i].ordLinkSeqNo == data.tabIndex && this.state.cannelStatus === false) {
                    this.state.dataSource[i][name] = e
                    this.state.dataSource[index]['ordNewQty'] = ''
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.dataSource[i]['duraFactor'] = option.props.duraFactor
                    this.state.dataSource[i]['qtyStatus'] = '2'
                } else if ((name == 'ordQtyUomID' || name == 'ordUsageID') && dataSource[i].ordLinkSeqNo == data.tabIndex && this.state.cannelStatus === false) {
                    this.state.dataSource[i][name] = e
                    this.state.dataSource[index]['ordNewQty'] = ''
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.dataSource[index]['ordPrice'] = option.props.price
                    this.state.dataSource[i]['qtyStatus'] = '2'
                } else if (name == 'ordPriorityID' && dataSource[i].ordLinkSeqNo == data.tabIndex && this.state.cannelStatus === false) {
                    this.state.dataSource[i][name] = e
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.dataSource[index]['ordNewQty'] = ''
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.ordPriorityID = e
                    this.loadDisableColumn(data, index, e)
                } else {
                    if (option) {
                        this.state.dataSource[index][name] = e
                        this.state.dataSource[index]['frequency'] = option.props.frequency ? option.props.frequency : dataSource[index].frequency
                        this.state.dataSource[index]['cycleDays'] = option.props.cycleDays ? option.props.cycleDays : dataSource[index].cycleDays
                        this.state.dataSource[index]['intervalDays'] = option.props.intervalDays ? option.props.intervalDays : dataSource[index].intervalDays
                        this.state.dataSource[index]['duraFactor'] = option.props.duraFactor ? option.props.duraFactor : dataSource[index].duraFactor
                        this.state.dataSource[index]['doseDenominator'] = option.props.doseDenominator ? option.props.doseDenominator : dataSource[index].doseDenominator
                        this.state.dataSource[index]['doseMolecule'] = option.props.doseMolecule ? option.props.doseMolecule : dataSource[index].doseMolecule
                        this.state.dataSource[index]['qtyMolecule'] = option.props.qtyMolecule ? option.props.qtyMolecule : dataSource[index].qtyMolecule
                        this.state.dataSource[index]['qtyDenominator'] = option.props.qtyDenominator ? option.props.qtyDenominator : dataSource[index].qtyDenominator
                        this.state.dataSource[i]['qtyStatus'] = '2'
                        this.state.dataSource[index]['defaultStatus'] = ''
                    } else {
                        this.state.dataSource[index][name] = e
                        this.state.dataSource[i]['qtyStatus'] = '2'
                        this.state.dataSource[index]['defaultStatus'] = ''
                    }
                }
            }
        }
        this.setState({})
    }

    changeBodyPartRadio(name, index, data, e, option) {
        var priceMsg = []
        this.state.dataSource[index][name] = [e]
        priceMsg.push(option.props.ordprice)
        this.state.dataSource[index]['ordPrice'] = option.props.ordprice
        this.setState({})
    }

    //部位
    changeBodyPartSelect(name, index, data, e, option) {
        var priceMsg = []
        var priceData = []
        if (!Util.isEmpty(option)) {
            for (var i = 0; i < option.length; i++) {
                //眼部互斥
                if (option[i].props.mutexflag == 'Y') {
                    this.state.dataSource[index]['ordbodyPartID'] = [option[i].props.value]
                    if (data.ordbodyPartID[0] == option[i].props.value) {
                        this.state.dataSource[index]['ordbodyPartID'] = [option[i].props.partid]
                        priceMsg.push(option[i].props.ordprice)
                        this.state.dataSource[index]['ordPrice'] = option[i].props.ordprice
                        this.state.dataSource[index]['defaultStatus'] = ''
                        this.state.dataSource[index]['ordNewQty'] = ''
                    }
                } else {
                    priceData.push(option[i].props.ordprice)
                    this.state.dataSource[index]['ordbodyPartID'] = e
                    this.state.dataSource[index]['priceData'] = priceData
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.dataSource[index]['ordNewQty'] = ''
                }
            }
        } else {
            this.state.dataSource[index]['ordbodyPartID'] = e
            this.state.dataSource[index]['defaultStatus'] = ''
            this.state.dataSource[index]['ordNewQty'] = ''
        }
        this.setState({})
    }

    loadDisableColumn(data, index, id) {
        var params = {
            params: [{
                medID: data.medID,
                ordPriorityID: id
            }]
        }
        $http.post('urlDeault', this, {
            code: "03010044",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.state.dataSource[index]['unableToEdit'] = res.result.unableToEdit,
                        this.state.dataSource[index]['sequence'] = res.result.sequence,
                        this.setState({})
                }
            }
        });
    }

    commonInput(name, index, data, e) {
        if (name == 'ordDurQty') {
            const { value } = e.target;
            const reg = /^[1-9]\d*$/;
            this.state.dataSource[index]['ordNewQty'] = ''
            this.state.dataSource[index]['defaultStatus'] = ''
            if (!reg.test(value) && value.length > 0) {
                message.error('只允许输入正整数！', this.state.userData && this.state.userData.messageTime)
                return
            }
        }

        if (name == 'ordQty') {
            this.state.dataSource[index]['ordNewQty'] = e.target.value
            this.state.dataSource[index]['defaultStatus'] = ''
            // this.state.dataSource[index]['newQty'] = e.target.value
            this.setState({})
        }

        var { dataSource, ids } = this.state;
        //判断是否是分组并且是否勾选
        if (this.state.groupStatus && data.checkIdenty == '2' && ids.length > 1) {
            for (var i = 0; i < dataSource.length; i++) {
                for (var j = 0; j < ids.length; j++) {
                    if (ids[j] == dataSource[i].ordID) {
                        return
                    } else {
                        if (name == 'ordDurQty' && dataSource[i].checkIdenty == '2') {
                            this.state.dataSource[i][name] = e.target.value
                            this.state.dataSource[index]['defaultStatus'] = ''
                            this.state.dataSource[index]['ordNewQty'] = ''
                        } else {
                            this.state.dataSource[index][name] = e.target.value
                            this.state.dataSource[index]['defaultStatus'] = ''
                            this.state.dataSource[index]['ordNewQty'] = ''
                        }
                    }
                }
            }
        } else {
            for (var i = 0; i < dataSource.length; i++) {
                if (dataSource[i].ordLinkSeqNo == data.tabIndex && (name == 'ordFreqID' || name == 'ordUsageID' ||
                    name == 'ordDurationID' || name == 'ordPriorityID' || name == 'ordRecLocID' || name == 'ordDurQty')) {
                    this.state.dataSource[i][name] = e.target.value
                    this.state.dataSource[index]['defaultStatus'] = ''
                    this.state.dataSource[index]['ordNewQty'] = ''
                } else {
                    if (name == 'ordQty') {
                        this.state.dataSource[index]['qtyStatus'] = '1'
                        this.state.dataSource[index][name] = e.target.value
                        // this.state.dataSource[index]['defaultStatus'] = ''
                        this.state.dataSource[index]['defaultStatus'] = true
                        //修改数量计算材料问题不计算总价之前赋值defaultStatus == true,现在改成空
                        // this.state.dataSource[index]['defaultStatus'] = ''
                    } else if (name == 'ordNote') {
                        this.state.dataSource[index][name] = e
                        this.state.dataSource[index]['defaultStatus'] = ''
                        this.state.dataSource[index]['ordNewQty'] = ''
                    } else {
                        this.state.dataSource[index][name] = e.target.value
                        this.state.dataSource[index]['defaultStatus'] = ''
                        this.state.dataSource[index]['ordNewQty'] = ''
                    }
                }
            }
            // this.state.dataSource[index][name] = e.target.value
        }
        this.setState({})
    }

    loadSelectData(value, page, pageSize, search) {
        var params = {
            params: [{
                // admID: this.state.recordData ? this.state.recordData.patAdmID : '',
                // admID: '11759',
                searchCode: value ? value : this.state.changeValue,
                logonLocID: this.state.userData.locID,
                userID: this.state.userData.userID,
                groupID: this.state.userData.groupID,
                hospID: this.state.userData.hospID,
            }],
            pagination: [{
                pageSize: this.state.pageSize,
                currentPage: page
            }]

        }
        $http.post('urlDeault', this, {
            code: "03050019",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        selectData: res.result.data,
                        total: res.result.totalCount,
                        rowMedID: res.result.data ? res.result.data[0].medID : '',
                        search: search
                    })
                }
            }
        });
    }

    changeCheckBox(name, index, e) {
        this.state.dataSource[index][name] = e.target.checked ? 'Y' : 'N'
        this.setState({})
    }


    //onfocus名称规格展示下拉table
    handleFocusInput(index, e) {
        this.setState({
            indexTable: index,
            visible: e
        })
    }

    handleSearchClear(index, value) {
        this.state.dataSource[index] = {}
        this.setState({
            changeValue: value,
            indexTab: index,
        })
    }

    handleSearch(index, value) {
        this.setState({
            changeValue: value,
            indexTab: index,
        })
        if (value.length >= 2) {
            this.loadSelectData(value, '1', '')
        }
        document.addEventListener('elementTable', this.loadListener)
    }

    changeAdvicePage(current, pageSize) {
        this.setState({ newPage: pageSize, codePage: current }, () => {
            this.loadData('', current, pageSize);
        });
    }

    changeData(e) {
        this.setState({ codePage: e }, () => {
            this.loadData('', e, '');
        });
    }

    //鼠标移动添加样式
    addMouseOverStyle(name, e) {
        this.setState({
            addMouseStyle: true,
            indexStyle: name
        })
    }
    addMouseLeaveStyle() {
        this.setState({
            addMouseStyle: false,
            indexStyle: ''
        })
    }

    //添加处方信息
    addMechansim(data) {
        var { dataSource, completeColData } = this.state;
        if (Util.isEmpty(completeColData)) {
            message.error('请先双击选择您需要维护的医嘱！', this.state.userData && this.state.userData.messageTime)
            return
        }
        //加入添加限制，只有录入了医嘱信息之后才能再次添加
        for (var i = 0; i < dataSource.length; i++) {
            if (Util.isEmpty(dataSource[i].ordMedItemDesc)) {
                message.error('请先录入医嘱信息再添加！', this.state.userData && this.state.userData.messageTime)
                return
            }
        }
        this.state.dataSource.push({ tabIndex: this.state.dataSource.length + 1 });
        this.setState({
            // visStatus:true,
            indexTable: this.state.dataSource.length - 1,
            groupStatus: false,
            batchStatus: false
        }, () => {
            this.selectFocus.current.focus()
        })
    }

    //删除
    delMechansim() {
        // this.loadDeleteTemplate()
        var flag = true;
        var that = this;
        var { dataSource, ids, checkData } = this.state;
        if (ids.length < 1) {
            message.error('请选择你需要删除的数据', this.state.userData && this.state.userData.messageTime)
            return
        }

        confirm({
            title: '删除',
            content: '您确定要删除选中的数据吗？',
            onOk() {
                for (var i = 0; i < checkData.length; i++) {
                    for (var j = 0; j < dataSource.length; j++) {
                        if (!Util.isEmpty(checkData[i].ordSetDetailID) && dataSource[j].tabIndex == checkData[i].tabIndex) {
                            //防止删除时，多次调用
                            if (flag) {
                                flag = false
                                that.loadDeleteTemplate()
                                // that.state.dataSource.splice(j, 1);
                            }
                        } else {
                            if (checkData[i].tabIndex == dataSource[j].tabIndex) {
                                that.state.dataSource.splice(j, 1);
                            }
                        }
                    }
                }
                that.setState({ ids: [] })
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }

    loadDeleteTemplate() {
        var { ids, checkData, dataSource } = this.state;
        var code = []
        for (var i = 0; i < checkData.length; i++) {
            if (!Util.isEmpty(checkData[i].ordSetDetailID)) {
                code.push(checkData[i].ordSetDetailID)
            }
        }
        var params = {
            params: [{
                ordSetDetailID: code,
                userID: this.state.userData.userID
            }],
        }
        $http.post('urlDeault', this, {
            code: "03050065",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('删除成功', this.state.userData && this.state.userData.messageTime)
                    var source = []
                    if (!Util.isEmpty(dataSource)) {
                        for (var i = 0; i < dataSource.length; i++) {
                            for (var j = 0; j < checkData.length; j++) {
                                if (dataSource[i].ordSetDetailID == checkData[j].ordSetDetailID) {
                                    // source.push(dataSource[i])
                                    this.state.dataSource.splice(i, 1);
                                }
                            }
                        }
                    } else {
                        this.state.dataSource = []
                    }
                    this.setState({})
                    // this.loadCompleteDetail('temp')
                }
            }
        });
    }

    //上移
    handleUpSort() {
        var keys = []
        var check = this.state.checkData

        //createBy: DYK
        if (check.length === 0) {
            message.warning('请先选择要移动的医嘱！');
            return;
        }

        if (!Util.isEmpty(check)) {
            for (var i = 0; i < check.length; i++) {
                keys.push(check[i].tabIndex)
            }
        }
        var data = this.state.dataSource

        //记录移动前关联的ID   createBy: DYK
        let beforeGroupID = [];  //移动之前的组号序列ID
        for (let i = 0; i < data.length; i++) {
            if (data[i].ordLinkSeqNo !== '') {
                let currentIndex = data[i].ordLinkSeqNo - 1; //当前组号对应的数组下标
                let currentID = data[currentIndex].ordSetDetailID;  //当前关联的索引ID(唯一)
                beforeGroupID.push(currentID);
            }
        }

        var newKeys = []
        var temp = []
        for (var i = 0; i < data.length; i++) {
            if (!Util.isEmpty(data[i].ordSetDetailID)) {
                temp.push(data[i])
            }
        }
        keys = keys.sort(function (m, n) {
            if (m < n) return -1
            else if (m > n) return 1
            else return 0
        });
        for (var i = 0; i < keys.length; i++) {
            if (keys[i] - 1 === 0) {
                newKeys.push(keys[i])
                // continue
                message.warn('已经到顶了，无法再移动！', this.state.userData && this.state.userData.messageTime)
                return
            }
            // if (keys[i] == data[keys[i]-1].tabIndex) {
            var curRowData = data[keys[i] - 1]
            var curRowKey = curRowData.tabIndex
            var upRowData = data[keys[i] - 2]
            var upRowKey = upRowData.tabIndex
            upRowData.tabIndex = curRowKey
            curRowData.tabIndex = upRowKey

            data[keys[i] - 1] = upRowData
            data[keys[i] - 2] = curRowData
            newKeys.push(keys[i] - 1)
            if (Util.isEmpty(data[keys[i] - 2].tabIndex)) {
                return
            }
        }

        //移动过后组号序列    createBy: DYK
        let afterGroupNo = [];  //移动后变化的组号值
        for (let i = 0; i < beforeGroupID.length; i++) {
            for (let j = 0; j < data.length; j++) {
                let afterID = data[j].ordSetDetailID;
                if (afterID == beforeGroupID[i]) {
                    let currentTableNo = data[j].tabIndex;  // 移动后的坐标序号
                    afterGroupNo.push(currentTableNo);
                }
            }
        }
        //更新数组序列    createBy: DYK
        for (let i = 0; i < data.length; i++) {
            if (data[i].ordLinkSeqNo !== '') {
                data[i].ordLinkSeqNo = afterGroupNo[0];
                afterGroupNo.shift();   //删除数组的第一个元素
            }
        }
        this.setState(
            {
                dataSource: data,
                ids: newKeys
            }
        )
    }

    //下移
    handleDownSort() {
        var keys = []
        var check = this.state.checkData

        //createBy: DYK
        if (check.length === 0) {
            message.warning('请先选择要移动的医嘱！');
            return;
        }

        if (!Util.isEmpty(check)) {
            for (var i = 0; i < check.length; i++) {
                keys.push(check[i].tabIndex)
            }
        }
        var data = this.state.dataSource

        //记录关联ID     createBY: DYK
        let beforeGroupID = [];  //移动之前的组号序列ID
        for (let i = 0; i < data.length; i++) {
            if (data[i].ordLinkSeqNo !== '') {
                let currentIndex = data[i].ordLinkSeqNo - 1; //当前组号对应的数组下标
                let currentID = data[currentIndex].ordSetDetailID;  //当前关联的索引ID(唯一)
                beforeGroupID.push(currentID);
            }
        }

        var newKeys = []
        keys = keys.sort(function (m, n) {
            if (m < n) return -1
            else if (m > n) return 1
            else return 0
        });
        for (var i = keys.length - 1; i >= 0; i--) {
            if (keys[i] === data.length) {
                newKeys.push(keys[i])
                // continue
                message.warn('已经到底了，无法再移动！', this.state.userData && this.state.userData.messageTime)
                return
            }
            // var curRowData = data[keys[i]]
            // var upRowData = data[keys[i] + 1]
            // data[keys[i]] = upRowData
            // data[keys[i] + 1] = curRowData
            // newKeys.push(keys[i] + 1)
            var curRowData = data[keys[i] - 1]
            var upRowData = data[keys[i]]
            var curRowKey = curRowData.tabIndex
            var upRowKey = upRowData.tabIndex
            upRowData.tabIndex = curRowKey
            curRowData.tabIndex = upRowKey
            data[keys[i] - 1] = upRowData
            data[keys[i]] = curRowData
            newKeys.push(keys[i] + 1)
        }

        //移动过后组号序列  createBY: DYK
        let afterGroupNo = [];  //移动后变化的组号值
        for (let i = 0; i < beforeGroupID.length; i++) {
            for (let j = 0; j < data.length; j++) {
                let afterID = data[j].ordSetDetailID;
                if (afterID == beforeGroupID[i]) {
                    let currentTableNo = data[j].tabIndex;  // 移动后的坐标序号
                    afterGroupNo.push(currentTableNo);
                }
            }
        }
        //重新赋值操作  createBY: DYK
        for (let i = 0; i < data.length; i++) {
            if (data[i].ordLinkSeqNo !== '') {
                data[i].ordLinkSeqNo = afterGroupNo[0];
                afterGroupNo.shift();
            }
        }
        this.setState(
            {
                dataSource: data,
                ids: newKeys
            }
        )
    }

    //开始分组
    handleStartGroup() {
        var { dataSource, ids } = this.state;
        //先setState一个标识值，表示分组
        if (Util.isEmpty(ids)) {
            message.error('请选择您需要分组的医嘱项', this.state.userData && this.state.userData.messageTime)
            return
        }
        if (ids.length == 1) {
            message.error('请选择两条及以上数据进行分组', this.state.userData && this.state.userData.messageTime)
            return
        }
        this.setState({
            groupStatus: true
        })
        for (var i = 0; i < dataSource.length; i++) {
            for (var j = 0; j < ids.length; j++) {
                if (ids[j] == dataSource[i].ordID) {
                    message.error('已插入的数据不能用于分组，请重新选择！', this.state.userData && this.state.userData.messageTime)
                    return
                }
            }
        }
        //使用冒泡排序，将选中的id进行排序，取最小的数值作为分组置灰标识
        for (var i = 0; i < ids.length - 1; i++) {
            for (var j = 0; j < ids.length - i - 1; j++) {
                if (ids[j] > ids[j + 1]) {
                    var temp = ids[j];
                    ids[j] = ids[j + 1];
                    ids[j + 1] = temp;
                }
            }
            // this.state.dataSource[ids[0]]['identity'] = '1'
        }
        //获取子医嘱的下拉数据，校验是否可以分组
        var useageID = ''//用法id
        var array = []//用法数组
        var frequenceID = ''//频次id
        var frequenceList = []//频次数组
        var recLocList = []//执行科室
        var recLocID = ''
        var flag = false
        var freFlag = false
        var recFlag = false
        for (var i = 0; i < ids.length; i++) {
            // for(var j=0;j<dataSource.length;j++){
            useageID = this.state.dataSource[ids[0] - 1].ordUsageID
            array = this.state.dataSource[ids[i] - 1].usageList
            frequenceID = this.state.dataSource[ids[0] - 1].ordFreqID
            frequenceList = this.state.dataSource[ids[i] - 1].frequenceList
            recLocID = this.state.dataSource[ids[0] - 1].ordRecLocID
            recLocList = this.state.dataSource[ids[i] - 1].recLocList
            // }
        }
        //用法
        if (!Util.isEmpty(array)) {
            for (var j = 0; j < array.length; j++) {
                if (useageID == array[j].id) {
                    flag = false
                    break
                } else {
                    flag = true
                }
            }
        }
        //频次
        if (!Util.isEmpty(frequenceList)) {
            for (var j = 0; j < frequenceList.length; j++) {
                if (frequenceID == frequenceList[j].id) {
                    freFlag = false
                    break
                } else {
                    freFlag = true
                }
            }
        }
        //科室
        if (!Util.isEmpty(recLocList)) {
            for (var j = 0; j < recLocList.length; j++) {
                if (recLocID == recLocList[j].recLocID) {
                    recFlag = false
                    break
                } else {
                    recFlag = true
                }
            }
        }

        if (flag === true) {
            message.error('关联子项中，无该用法，无法关联！', this.state.userData && this.state.userData.messageTime)
            return
        }
        if (freFlag === true) {
            message.error('关联子项中，无该频次，无法关联！', this.state.userData && this.state.userData.messageTime)
            return
        }
        if (recFlag === true) {
            message.error('关联子项中，无该科室，无法关联！', this.state.userData && this.state.userData.messageTime)
            return
        }
        for (var i = 0; i < ids.length; i++) {
            this.state.dataSource[ids[0] - 1]['identity'] = ''
            if (i > 0) {//开始分组，子医嘱与主医嘱数据一致
                this.state.dataSource[ids[i] - 1]['identity'] = '1';
                this.state.dataSource[ids[i] - 1]['ordDurQty'] = this.state.dataSource[ids[0] - 1].ordDurQty
                this.state.dataSource[ids[i] - 1]['ordFreqID'] = this.state.dataSource[ids[0] - 1].ordFreqID
                this.state.dataSource[ids[i] - 1]['ordFrequenceDesc'] = this.state.dataSource[ids[0] - 1].ordFrequenceDesc
                this.state.dataSource[ids[i] - 1]['ordUsageDesc'] = this.state.dataSource[ids[0] - 1].ordUsageDesc
                this.state.dataSource[ids[i] - 1]['ordUsageID'] = this.state.dataSource[ids[0] - 1].ordUsageID
                this.state.dataSource[ids[i] - 1]['ordDurationDesc'] = this.state.dataSource[ids[0] - 1].ordDurationDesc
                this.state.dataSource[ids[i] - 1]['ordDurationID'] = this.state.dataSource[ids[0] - 1].ordDurationID
                this.state.dataSource[ids[i] - 1]['ordPriorityDesc'] = this.state.dataSource[ids[0] - 1].ordPriorityDesc
                this.state.dataSource[ids[i] - 1]['ordPriorityID'] = this.state.dataSource[ids[0] - 1].ordPriorityID
                this.state.dataSource[ids[i] - 1]['ordEMFlag'] = this.state.dataSource[ids[0] - 1].ordEMFlag
                this.state.dataSource[ids[i] - 1]['ordRecLocDesc'] = this.state.dataSource[ids[0] - 1].ordRecLocDesc
                this.state.dataSource[ids[i] - 1]['ordRecLocID'] = this.state.dataSource[ids[0] - 1].ordRecLocID
                this.state.dataSource[ids[i] - 1]['ordLinkSeqNo'] = this.state.dataSource[ids[0] - 1].tabIndex
            }
            this.setState({})
        }
    }

    //取消分组
    handleCannelGroup() {
        var { dataSource } = this.state;
        for (var i = 0; i < dataSource.length; i++) {
            if (this.state.linkValue) {
                this.state.dataSource[this.state.inputIndex]['ordLinkStatus'] = false
            } else {
                this.state.dataSource[i]['identity'] = ''
                this.state.dataSource[i]['ordLinkSeqNo'] = ''
                this.state.dataSource[i]['checkIdenty'] = ''
                this.state.dataSource[i]['mainIndexId'] = ''
            }
        }
        this.setState({
            groupStatus: false,
            cannelStatus: true,
            ids: []
        })
    }

    //插入医嘱
    insertDoctorAdvice() {
        var { dataSource, ids, completeColData } = this.state;
        this.setState({ saveStatus: true })
        var temp = []
        if (Util.isEmpty(dataSource)) {
            message.error('暂无需要保存的数据！', this.state.userData && this.state.userData.messageTime)
            this.setState({ saveStatus: false })
            return
        }
        //将默认数据过滤掉，只传新添加的数据
        for (var i = 0; i < dataSource.length; i++) {
            if (Util.isEmpty(dataSource[i].ordID) && !Util.isEmpty(dataSource[i].medID)) {
                temp.push(dataSource[i])
            }
            // if (Util.isEmpty(dataSource[i].identity) && this.state.groupStatus) {
            //     this.state.dataSource[i].ordLinkSeqNo = ids[0] + 1
            // }
        }
        for (var i = 0; i < temp.length; i++) {
            if (temp[i].ordTypeCode == 'D') {//医嘱为药品时
                if (Util.isEmpty(temp[i].ordFreqID)) {
                    message.error('频次不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
                if (Util.isEmpty(temp[i].ordDose)) {
                    message.error('剂量不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
                if (Util.isEmpty(temp[i].ordDoseUnitID)) {
                    message.error('剂量单位不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
                // if (Util.isEmpty(temp[i].ordQty)) {
                //     message.error('数量不能为空', this.state.userData && this.state.userData.messageTime);
                //     return
                // }
                if (Util.isEmpty(temp[i].ordQtyUomID)) {
                    message.error('数量单位不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
                if (Util.isEmpty(temp[i].ordDurQty)) {
                    message.error('疗程数量不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
                if (Util.isEmpty(temp[i].ordDurationID)) {
                    message.error('疗程单位不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
                if (!Util.isEmpty(temp[i].ordSkinTestFlag) && temp[i].ordSkinTestFlag == 'Y'
                    && Util.isEmpty(temp[i].ordSkinTestWayID)) {
                    message.error('皮试备注不能为空', this.state.userData && this.state.userData.messageTime);
                    this.setState({ saveStatus: false })
                    return
                }
            }
        }
        //过滤多余的数据
        var tempData = []
        for (var i = 0; i < temp.length; i++) {
            tempData.push({
                ...temp[i],
                ordSkinTestFlag: temp[i].ordSkinTestFlag == 'N' ? temp[i].ordSkinTestFlagValue : temp[i].ordSkinTestFlag,
                ordSkinTestWayID: temp[i].ordSkinTestFlag == 'N' && temp[i].ordSkinTestFlagValue == 'N' ? '' : temp[i].ordSkinTestWayID,
                ordQty: Util.isEmpty(temp[i].ordSetDetailID) ? (temp[i].ordNewQty ? temp[i].ordNewQty : temp[i].newQty) : temp[i].ordQty,
                ordbodyPart: temp[i].ordbodyPartID,
                skinTestWayList: undefined,
                admReasonList: undefined,
                doseUnitList: undefined,
                durationList: undefined,
                frequenceList: undefined,
                priorityExtList: undefined,
                priorityList: undefined,
                qtyUnitList: undefined,
                recLocList: undefined,
                skinTestWayList: undefined,
                specList: undefined,
                usageList: undefined,
                sequence: undefined,
                unableToEdit: undefined,
                stageList: undefined,
                causeList: undefined,
                bodyPartList: undefined,
                dataList: []
            })
        }
        var params = {
            params: [
                {
                    // admID: this.state.recordData ? this.state.recordData.patAdmID : '',
                    // locID: this.state.userData.locID,
                    // docID: this.state.userData.userID,
                    userID: this.state.userData.userID,
                    // hospID: this.state.userData.hospID,
                    orders: tempData,
                    ordSpecID: this.state.ordSpecID,
                    ordSetID: this.state.ordSetID
                }
            ]
        }
        $http.post('urlDeault', this, {
            code: "03050064",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        groupStatus: false,
                        saveStatus: false
                    })
                    message.success('操作成功！', this.state.userData && this.state.userData.messageTime)
                    this.loadLeftData()
                    this.loadCompleteDetail('temp')
                } else {
                    this.setState({
                        saveStatus: false
                    })
                }
            }
        });
    }

    onSelectChange(ids, data) {
        this.setState({
            ids: ids,
            checkData: data
        })
    }

    //根据正选和反选，向对应数据增加一个标识，处理反选下拉依旧置灰问题
    onSelect(data, flag) {
        var selectData = []
        this.state.selectData.push(data)
        if (flag) {
            data['checkIdenty'] = '2'
        } else {
            data['checkIdenty'] = '1'
            //去除缓存的moveStatus标识    changeBY: DYK
            delete data.moveStatus;
        }
        this.setState({})
    }

    onSelectAll(flag, selectedRows, changeRows) {
        this.state.selectData.push(changeRows)
        for (var i = 0; i < changeRows.length; i++) {
            if (flag) {
                changeRows[i]['checkIdenty'] = '2'
            } else {
                changeRows[i]['checkIdenty'] = '1'
            }
        }
        this.setState({})
    }

    //多选模版，确认错误弹框
    confirmAdviceModal(data) {
        var that = this;
        var date = new Date();
        var validData = [], textData = [];
        var { adviceDrData, dataSource, nodeId, confirmData } = this.state;

        var result = [];
        //取两个数组的不同数据
        for (var i = 0; i < adviceDrData.length; i++) {
            var obj = adviceDrData[i];
            var num = obj.indexId;
            var isExist = false;
            for (var j = 0; j < confirmData.length; j++) {
                var aj = confirmData[j];
                var n = aj.indexId;
                if (n == num) {
                    isExist = true;
                    break;
                }
            }
            if (!isExist) {
                result.push(obj);
            }
        }
        var userCode = []
        for (var i = 0; i < adviceDrData.length; i++) {
            var obj = adviceDrData[i];
            var num = obj.indexId;
            var isExist = false;
            for (var j = 0; j < data.length; j++) {
                var aj = data[j];
                var n = aj.indexId;
                if (n == num) {
                    textData.push(obj)
                    isExist = true;
                    break;
                }
            }
            if (!isExist) {
                userCode.push(obj);
            }
        }
        validData = result.concat(textData)
        for (var i = 0; i < validData.length; i++) {
            this.state.dataSource.push({ tabIndex: this.state.dataSource.length + 1 })
            this.state.indexArray.push({ index: this.state.dataSource.length - 1, indexId: validData[i].indexId })
            this.setState({ groupStatus: false })
        }
        //冒泡排序，用来处理关联排序问题
        for (var i = 0; i < validData.length - 1; i++) {
            for (var j = 0; j < validData.length - i - 1; j++) {
                if (validData[j].indexId > validData[j + 1].indexId) {
                    var temp = validData[j].indexId
                    validData[j].indexId = validData[j + 1].indexId
                    validData[j + 1].indexId = temp
                }
            }
        }
        var { indexArray } = this.state;
        for (var i = 0; i < validData.length; i++) {
            for (var j = 0; j < indexArray.length; j++) {
                if (indexArray[j].index && indexArray[j].indexId == validData[i].indexId) {
                    that.state.dataSource[indexArray[j].index]['indexId'] = validData[i].indexId,
                        that.state.dataSource[indexArray[j].index]['mainIndexId'] = validData[i].mainIndexId,
                        that.state.dataSource[indexArray[j].index]['ordLinkSeqNo'] = validData[i].mainIndexId,
                        that.state.dataSource[indexArray[j].index]['ordMedItemDesc'] = validData[i].defaultData.ordDesc,
                        that.state.dataSource[indexArray[j].index]['ordDose'] = validData[i].defaultData.ordDose,
                        that.state.dataSource[indexArray[j].index]['ordDoseUnitID'] = validData[i].defaultData.ordDoseUnitID,
                        // that.state.dataSource[indexArray[j].index]['ordFreqID'] = validData[i].defaultData.ordFrequenceID,

                        that.state.dataSource[indexArray[j].index]['ordSkinTestUsageDesc'] = validData[i].defaultData.ordSkinTestUsageDesc,
                        that.state.dataSource[indexArray[j].index]['ordSkinTestUsageID'] = validData[i].defaultData.ordSkinTestUsageID,

                        that.state.dataSource[indexArray[j].index]['ordUsageDesc'] = (validData[i].defaultData.ordSkinTestFlag == 'Y' || validData[i].defaultData.ordSkinTestFlagValue == 'Y') ?
                            validData[i].defaultData.ordSkinTestUsageDesc : validData[i].defaultData.ordUsageDesc,
                        that.state.dataSource[indexArray[j].index]['ordUsageID'] = (validData[i].defaultData.ordSkinTestFlag == 'Y' || validData[i].defaultData.ordSkinTestFlagValue == 'Y') ?
                            validData[i].defaultData.ordSkinTestUsageID : validData[i].defaultData.ordUsageID,

                        that.state.dataSource[indexArray[j].index]['ordFreqID'] = validData[i].defaultData.ordFreqID,
                        that.state.dataSource[indexArray[j].index]['ordFreqDesc'] = validData[i].defaultData.ordFreqDesc,
                        that.state.dataSource[indexArray[j].index]['ordSetDetailID'] = validData[i].defaultData.ordSetDetailID,
                        that.state.dataSource[indexArray[j].index]['ordUsageID'] = validData[i].defaultData.ordUsageID,
                        that.state.dataSource[indexArray[j].index]['doseMolecule'] = validData[i].defaultData.doseMolecule,
                        that.state.dataSource[indexArray[j].index]['defaultStatus'] = true,
                        that.state.dataSource[indexArray[j].index]['doseDenominator'] = validData[i].defaultData.doseDenominator,
                        that.state.dataSource[indexArray[j].index]['ordbodyPartDesc'] = validData[i].defaultData.ordbodyPartDesc,
                        that.state.dataSource[indexArray[j].index]['ordbodyPartID'] = validData[i].defaultData.ordbodyPartID,
                        that.state.dataSource[indexArray[j].index]['radioFlag'] = validData[i].defaultData.radioFlag,
                        that.state.dataSource[indexArray[j].index]['ordDurQty'] = validData[i].defaultData.ordDurQty,
                        that.state.dataSource[indexArray[j].index]['ordDurationID'] = validData[i].defaultData.ordDurationID,
                        that.state.dataSource[indexArray[j].index]['ordQty'] = validData[i].defaultData.ordQty,
                        that.state.dataSource[indexArray[j].index]['ordQtyUomID'] = validData[i].defaultData.ordQtyUomID,
                        that.state.dataSource[indexArray[j].index]['ordStageID'] = validData[i].defaultData.ordStageID,
                        that.state.dataSource[indexArray[j].index]['ordPriorityExtID'] = validData[i].defaultData.ordPriorityExtID,
                        that.state.dataSource[indexArray[j].index]['ordPrice'] = validData[i].defaultData.ordPrice,
                        that.state.dataSource[indexArray[j].index]['ordSkinTestFlag'] = validData[i].defaultData.ordSkinTestFlag,
                        that.state.dataSource[indexArray[j].index]['firstBillFlag'] = validData[i].defaultData.firstBillFlag,
                        that.state.dataSource[indexArray[j].index]['ordSkinTestWayID'] = validData[i].defaultData.ordSkinTestWayID,
                        that.state.dataSource[indexArray[j].index]['ordEMFlagValue'] = validData[i].defaultData.ordEMFlagValue,
                        that.state.dataSource[indexArray[j].index]['ordSkinTestFlagValue'] = validData[i].defaultData.ordSkinTestFlagValue,
                        that.state.dataSource[indexArray[j].index]['testFlag'] = validData[i].defaultData.ordSkinTestFlag,
                        that.state.dataSource[indexArray[j].index]['ordEMFlag'] = validData[i].defaultData.ordEMFlag,
                        that.state.dataSource[indexArray[j].index]['testEMFlag'] = validData[i].defaultData.ordEMFlag,
                        that.state.dataSource[indexArray[j].index]['ordRecLocID'] = validData[i].defaultData.ordRecLocID,
                        that.state.dataSource[indexArray[j].index]['ordToalCountO'] = validData[i].defaultData.ordToalCountO,
                        that.state.dataSource[indexArray[j].index]['ordPriorityID'] = validData[i].defaultData.ordPriorityID,
                        that.state.dataSource[indexArray[j].index]['medDesca'] = validData[i].defaultData.ordDesca,
                        that.state.dataSource[indexArray[j].index]['ordAdmReasonID'] = validData[i].defaultData.ordAdmReasonID,
                        that.state.dataSource[indexArray[j].index]['ordSeqNo'] = parseInt(indexArray[j].index) + 1,
                        that.state.dataSource[indexArray[j].index]['ordDate'] = moment(date).format(dayFormat),
                        that.state.dataSource[indexArray[j].index]['ordTime'] = moment(date).format(timeFormat),
                        that.state.dataSource[indexArray[j].index]['ordStartDate'] = moment(date).format(dayFormat),
                        that.state.dataSource[indexArray[j].index]['ordStartTime'] = moment(date).format(timeFormat),
                        that.state.dataSource[indexArray[j].index]['ordNote'] = validData[i].defaultData.ordNote,
                        that.state.dataSource[indexArray[j].index]['medID'] = validData[i].defaultData.medID,
                        that.state.dataSource[indexArray[j].index]['ordMedItemID'] = validData[i].defaultData.medID,
                        that.state.dataSource[indexArray[j].index]['ordTypeCode'] = validData[i].defaultData.ordTypeCode,
                        that.state.dataSource[indexArray[j].index]['ordSpecID'] = validData[i].defaultData.ordSpecID,
                        that.state.dataSource[indexArray[j].index]['unableToEdit'] = validData[i].unableToEdit,
                        that.state.dataSource[indexArray[j].index]['ordNoteList'] = validData[i].ordNoteList,
                        that.state.dataSource[indexArray[j].index]['eyePartList'] = validData[i].eyePartList,
                        // that.state.usageList[indexArray[j].index] = validData[i].dataList.usageList,
                        that.state.doseUnitList[indexArray[j].index] = validData[i].dataList.doseUnitList,
                        that.state.durationList[indexArray[j].index] = validData[i].dataList.durationList,
                        that.state.bodyPartList[indexArray[j].index] = validData[i].dataList.bodyPartList,
                        that.state.qtyUnitList[indexArray[j].index] = validData[i].dataList.qtyUnitList,
                        that.state.stageList[indexArray[j].index] = validData[i].dataList.stageList,
                        that.state.recLocList[indexArray[j].index] = validData[i].dataList.recLocList,
                        that.state.eyePartList[indexArray[j].index] = validData[i].dataList.eyePartList,
                        // that.state.frequenceList[indexArray[j].index] = validData[i].dataList.frequenceList,
                        that.state.skinTestWayList[indexArray[j].index] = validData[i].dataList.skinTestWayList,
                        that.state.priorityList[indexArray[j].index] = validData[i].dataList.priorityList,
                        that.state.priorityExtList[indexArray[j].index] = validData[i].dataList.priorityExtList,
                        that.state.admReasonList[indexArray[j].index] = validData[i].dataList.admReasonList,
                        that.state.ordNoteList[indexArray[j].index] = validData[i].dataList.ordNoteList,
                        that.state.specList[indexArray[j].index] = validData[i].dataList.specList,
                        this.setState({ tableData: validData[i].defaultData, batchStatus: true, copyData: validData })
                }
            }
        }
        this.deleteNullData()
        this.hideModal('isShowConfirmModal')
    }

    //添加成套医嘱
    handleComplete(data) {
        var params = {
            params: [{
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                ordSetID: data.ordSetID,
                code: data.descripts,
                descripts: data.descripts,
                alias: data.alias,
                authRangeID: data.authRangeID,
                startDate: data.startDate,
                stopDate: data.stopDate,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050061",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    if (Util.isEmpty(data.ordSetID)) {
                        message.success('添加成套医嘱成功！', this.state.userData && this.state.userData.messageTime)
                    } else {
                        message.success('修改成套医嘱成功！', this.state.userData && this.state.userData.messageTime)
                    }
                    this.hideModal('isShowCompleteMedicalModal')
                    this.loadLeftData()
                }
            }
        });
    }

    //点击行，渲染当前行样式
    onClickRow = (record, index) => {
        return {
            onClick: () => {
                this.setState({
                    completeColData: record,
                    ordSetID: record.ordSetID,
                    indexTable: this.state.dataSource.length - 1,
                    groupStatus: false, batchStatus: false,
                    ids: []
                }, () => {
                    record.ordSetID ? this.loadCompleteDetail() : ''
                    // this.loadCompleteDetail()
                })
            },
        };
    }

    //点击行，渲染当前行样式
    setRowClassName = (record) => {
        return this.state.ordSetID && this.state.ordSetID == record.ordSetID ? 'clickRowStyle' : '';
    }

    onClickRightRow = (record, index) => {
        return {
            onClick: () => {
                this.setState({
                    rightData: record,
                    rightIndex: index,
                    edit: true
                })
            }
        }
    }

    loadCompleteDetail(status) {
        this.setState({
            saveStatus: true
        })
        var that = this;
        var date = new Date()
        var params = {
            params: [{
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                groupID: this.state.userData.groupID,
                ordSetID: this.state.ordSetID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050063",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var data = res.data.data;
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            // if (Util.isEmpty(status)) {
                            //     this.state.dataSource.push({ tabIndex: this.state.dataSource.length + 1 })
                            // }
                            this.state.dataSource = data;
                            this.state.dataSource[i]['ordMedItemDesc'] = data[i].ordDesc,
                                this.state.dataSource[i]['mainIndexId'] = Util.isEmpty(data[i].ordLinkSeqNo) ? '' : data[i].ordLinkSeqNo,
                                this.state.dataSource[i]['ordDose'] = data[i].ordDose,
                                this.state.dataSource[i]['ordDoseUnitID'] = data[i].ordDoseUnitID,
                                this.state.dataSource[i]['ordFreqID'] = data[i].ordFreqID,
                                this.state.dataSource[i]['defaultStatus'] = true,
                                this.state.dataSource[i]['ordUsageID'] = data[i].ordUsageID,
                                this.state.dataSource[i]['ordDurQty'] = data[i].ordDurQty,
                                this.state.dataSource[i]['ordPriorityExtID'] = data[i].ordPriorityExtID,
                                this.state.dataSource[i]['radioFlag'] = data[i].radioFlag,
                                this.state.dataSource[i]['ordDurationID'] = data[i].ordDurationID,
                                this.state.dataSource[i]['ordQty'] = data[i].ordQty,
                                this.state.dataSource[i]['ordQtyUomID'] = data[i].ordQtyUomID,
                                this.state.dataSource[i]['ordSetDetailID'] = data[i].ordSetDetailID,
                                this.state.dataSource[i]['ordPrice'] = data[i].ordPrice,
                                this.state.dataSource[i]['ordSkinTestFlag'] = data[i].ordSkinTestFlag,
                                this.state.dataSource[i]['firstBillFlag'] = data[i].firstBillFlag,
                                this.state.dataSource[i]['ordSkinTestWayID'] = data[i].ordSkinTestWayID,
                                this.state.dataSource[i]['ordRecLocID'] = data[i].ordRecLocID,
                                this.state.dataSource[i]['ordPriorityID'] = data[i].ordPriorityID,
                                this.state.dataSource[i]['ordAdmReasonID'] = data[i].ordAdmReasonID,
                                this.state.dataSource[i]['eyePartID'] = data[i].eyePartID,
                                this.state.dataSource[i]['eyePartDesc'] = data[i].eyePartDesc,
                                this.state.dataSource[i]['ordSeqNo'] = parseInt(i) + 1,
                                this.state.dataSource[i]['ordDate'] = moment(date).format(dayFormat),
                                this.state.dataSource[i]['ordTime'] = moment(date).format(timeFormat),
                                this.state.dataSource[i]['ordStartDate'] = moment(date).format(dayFormat),
                                this.state.dataSource[i]['ordStartTime'] = moment(date).format(timeFormat),
                                this.state.dataSource[i]['ordNote'] = data[i].ordNote,
                                this.state.dataSource[i]['medID'] = data[i].medID,
                                this.state.dataSource[i]['ordMedItemID'] = data[i].medID,
                                this.state.dataSource[i]['ordTypeCode'] = data[i].ordTypeCode,
                                this.state.dataSource[i]['ordSpecID'] = data[i].ordSpecID,
                                this.state.dataSource[i]['doseUnitList'] = data[i].dataList.doseUnitList,
                                this.state.dataSource[i]['durationList'] = data[i].dataList.durationList,
                                this.state.dataSource[i]['qtyUnitList'] = data[i].dataList.qtyUnitList,
                                this.state.dataSource[i]['eyePartList'] = data[i].dataList.eyePartList,
                                this.state.dataSource[i]['stageList'] = data[i].dataList.stageList,
                                this.state.dataSource[i]['priorityExtList'] = data[i].dataList.priorityExtList,
                                this.state.dataSource[i]['recLocList'] = data[i].dataList.recLocList,
                                this.state.dataSource[i]['frequenceList'] = data[i].dataList.frequenceList,
                                this.state.dataSource[i]['usageList'] = data[i].dataList.usageList,
                                this.state.dataSource[i]['priorityList'] = data[i].dataList.priorityList,
                                this.state.dataSource[i]['specList'] = data[i].dataList.specList,
                                this.state.dataSource[i]['bodyPartList'] = data[i].dataList.bodyPartList,
                                this.state.dataSource[i]['skinTestWayList'] = data[i].dataList.skinTestWayList,

                                this.state.tableData = data[i],
                                this.setState({ ids: [], saveStatus: false })
                        }
                    } else {
                        this.setState({
                            dataSource: [],
                            saveStatus: false
                        })
                    }
                    this.deleteNullData()
                } else {
                    this.setState({
                        saveStatus: false
                    })
                }
            }
        });
    }

    deleteNullData() {
        var data = []
        var that = this;
        var { dataSource, ids } = this.state;
        for (var j = 0; j < dataSource.length; j++) {
            if (Util.isEmpty(dataSource[j].ordMedItemID) && Util.isEmpty(dataSource[j].medID)) {
                that.state.dataSource.splice(j, 1);
            }
        }
        that.setState({})
    }

    // 操作弹框
    onClickRowPublic = (record, index) => {
        return {
            onDoubleClick: () => {
                this.rowClick(record, index)
            },
            onClick: () => {
                this.setState({
                    rowMedID: record.medID
                })
            }
        }
    }

    setRowClassNamePublic = (record) => {
        return record.medID === this.state.rowMedID ? 'clickRowStyle' : '';
    }

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

    handleOnKeydown(e) {
        var e = window.event || e;
        let scroll_height = 50;
        let id = '';
        let oneArr = this.state.selectData && this.state.selectData.length > 0 ? this.state.selectData : [];
        switch (e.keyCode) {
            case 13:
                if (this.state.rowMedID) {
                    let obj = {}
                    for (var i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].medID === this.state.rowMedID) {
                            obj = i > 0 ? oneArr[i] : oneArr[0];
                            break;
                        }
                    }
                    this.rowClick(obj);
                } else {
                    message.info("请选择一条需要操作的数据", this.state.userData && this.state.userData.messageTime)
                }
                break;
            case 38: //上
                if (this.state.rowMedID) {
                    for (var i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].medID === this.state.rowMedID) {
                            id = i > 0 ? oneArr[i - 1].medID : oneArr[0].medID;
                            break;
                        }
                    }
                    this.setState({ rowMedID: id }, () => {
                        var gundong = document.getElementById("gundong");
                        gundong.scrollTop = gundong.scrollTop - scroll_height;
                    })
                } else {
                    this.setState({ rowMedID: oneArr[0].medID })
                }
                break;
            case 40: //下
                if (this.state.rowMedID) {
                    for (let i = 0; i < oneArr.length; i++) {
                        if (oneArr[i].medID === this.state.rowMedID) {
                            id = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1].medID : oneArr[i + 1].medID;
                            break;
                        }
                    }
                    this.setState({ rowMedID: id }, () => {
                        var gundong = document.getElementById("gundong");
                        gundong.scrollTop = gundong.scrollTop + scroll_height;
                    })
                } else {
                    this.setState({ rowMedID: oneArr[0].medID })
                }
                break;
        }
    }

    onColumnRef = (ref) => {
        this.columnRef = ref;
    }

    render() {
        let { ids, dataSource, page, total, top, left, selectData, totalWidth, coefficientData, categoryData } = this.state;
        const rowSelection = {
            ids,
            onChange: this.onSelectChange.bind(this),
            onSelect: this.onSelect.bind(this),
            onSelectAll: this.onSelectAll.bind(this),
            selectedRowKeys: ids,
        }
        let param = {
            width: '700px',
            // height: 300,
            top: top,
            left: left,
            columns: this.sunColumns,
            data: selectData,
            isOnRow: true,
            TableClassName: 'tab-placeholder',
            rowClassName: true,
            showPagination: true,
            page,
            total,
        }

        let sum = 0;
        let totalSum = 0;
        if (dataSource) {
            for (let i = 0; i < dataSource.length; i++) {
                if (Util.isEmpty(dataSource[i].ordID) && !Util.isEmpty(dataSource[i].ordQty)) {
                    let totalNum = 0;//总次数
                    let totalDosc = 0;//总剂量
                    let oneDosc = 0;//剂量
                    let totala = 0
                    if (Util.isEmpty(dataSource[i].duraFactor) || Util.isEmpty(dataSource[i].ordDurQty) || Util.isEmpty(dataSource[i].frequency) ||
                        Util.isEmpty(dataSource[i].cycleDays) || Util.isEmpty(dataSource[i].ordDose) || Util.isEmpty(dataSource[i].doseMolecule)
                        || Util.isEmpty(dataSource[i].doseDenominator) || Util.isEmpty(dataSource[i].doseDenominator)) {
                        sum += parseFloat(dataSource[i].ordPrice || 1) * (parseFloat(dataSource[i].qtyStatus == '1' ? dataSource[i].ordQty || 1 : totala))
                    } else {
                        if (dataSource[i].cycleDays) {//优先使用cycleDays，计算总次数
                            totalNum = Math.ceil((parseFloat(dataSource[i].ordDurQty || 1) * parseFloat(dataSource[i].duraFactor || 1) * parseFloat(dataSource[i].frequency || 1)) / parseFloat(dataSource[i].cycleDays || 1))
                        } else {
                            totalNum = Math.ceil((parseFloat(dataSource[i].ordDurQty || 1) * parseFloat(dataSource[i].duraFactor || 1) * parseFloat(dataSource[i].frequency || 1)) / parseFloat(dataSource[i].intervalDays || 1))
                        }
                        //门诊
                        if (dataSource[i].ordToalCountO == 'Y') {
                            totalDosc = Math.ceil((parseFloat(dataSource[i].ordDose || 1) * totalNum * parseFloat(dataSource[i].doseMolecule || 1)) / parseFloat(dataSource[i].doseDenominator || 1))
                        } else {//先取整，再算
                            oneDosc = Math.ceil((parseFloat(dataSource[i].ordDose || 1) * parseFloat(dataSource[i].doseMolecule || 1)) / parseFloat(dataSource[i].doseDenominator || 1))
                            totalDosc = oneDosc * totalNum
                        }
                        if (this.props.patStatus == '1') {
                            if (dataSource[i].ordToalCountI == 'Y') {
                                totalDosc = Math.ceil((parseFloat(dataSource[i].ordDose || 1) * totalNum * parseFloat(dataSource[i].doseMolecule || 1)) / parseFloat(dataSource[i].doseDenominator || 1))
                            } else {
                                oneDosc = Math.ceil((parseFloat(dataSource[i].ordDose || 1) * parseFloat(dataSource[i].doseMolecule || 1)) / parseFloat(dataSource[i].doseDenominator || 1))
                                totalDosc = oneDosc * totalNum
                            }
                        }
                        totala = (totalDosc * parseFloat(dataSource[i].doseMolecule || 1)) / parseFloat(dataSource[i].qtyDenominator || 1)
                        sum += parseFloat(dataSource[i].ordPrice || 1) * (parseFloat(dataSource[i].qtyStatus == '1' ? dataSource[i].ordQty || 1 : totala))
                    }
                }
                if (dataSource[i].ordTotalPrice) {
                    totalSum += parseFloat(dataSource[i].ordTotalPrice)
                }
            }
        }

        return (
            <Spin spinning={this.state.saveStatus} tip="加载中...">
                <div className="complete-body" style={{ height: '100%', width: '100%', background: '#F5F7FE' }}>
                    <div
                        tabIndex={1}
                        onKeyDown={this.handleOnKeydown.bind(this)}
                        style={{ outline: 'none' }}
                    >
                        <ShowCommonTableModal
                            onClickRowPublic={this.onClickRowPublic}
                            setRowClassNamePublic={this.setRowClassNamePublic}
                            param={param}
                            onRef={this.onRef}
                            id="gundong"
                            compilePage={this.changePageSize.bind(this)}>
                        </ShowCommonTableModal>
                    </div>
                    <ShowCompleteMedicalModal
                        categoryData={categoryData}
                        coefficientData={coefficientData}
                        isShow={this.state.isShowCompleteMedicalModal}
                        cpmpleteData={this.state.cpmpleteData}
                        onSubmit={this.handleComplete.bind(this)}
                        onHide={this.hideModal.bind(this, 'isShowCompleteMedicalModal')}>
                    </ShowCompleteMedicalModal>
                    <ColumnAuthoritysModel
                        clientWidth="800px"
                        compontName="CompleteMedicalPage"
                        configType="C"
                        onRef={this.onColumnRef}
                        reloadData={this.loadColumns.bind(this)}
                    />
                    {/**确认医嘱弹框 */}
                    <ShowConfirmModal
                        isShow={this.state.isShowConfirmModal}
                        confirmData={this.state.confirmData}
                        errorData={this.state.errorData}
                        onSubmit={this.confirmAdviceModal.bind(this)}
                        onHide={this.hideModal.bind(this, 'isShowConfirmModal')}>
                    </ShowConfirmModal>
                    <Card className="complete-left-card" hoverable={true} title={<span style={{ marginLeft: 10 }}>成套医嘱列表(西药及其他)</span>}>
                        <div style={{ display: 'flex', marginTop: 10 }}>
                            <Input
                                placeholder='输入名称/别名回车查询'
                                onChange={Util.commonInputChange.bind(this, 'searchCode')}
                                onKeyDown={this.loadListData.bind(this)}
                                style={{ width: '65%' }}
                            />
                            <Button style={{ marginLeft: 5 }} type="primary" onClick={this.showCompleteMedicalModal.bind(this)}>+成套医嘱</Button>
                        </div>

                        <div style={{ marginTop: 10 }}>
                            <Checkbox onChange={this.changeLeftCheckBox.bind(this, 'activeFlag')}>仅显示生效</Checkbox>
                            <Checkbox onChange={this.changeLeftCheckBox.bind(this, 'selfFlag')}>仅显示本人添加的成套医嘱</Checkbox>
                        </div>
                        <div className="table-body-height" style={{ marginTop: 5 }}>
                            <Table
                                bordered
                                expandRowByClick={true}
                                columns={this.leftColumns}
                                dataSource={this.state.leftData}
                                loadData={this.loadLeftData}
                                onRow={this.onClickRow}
                                rowClassName={this.setRowClassName}
                                scroll={{ x: 710, y: store.getState().tableHeight.y + 50 }}
                                rowKey={(data) => {
                                    return data.authID || data.ordSetID
                                }}
                                pagination={false}
                            />
                        </div>
                    </Card>
                    <Card className="complete-right-card" hoverable={true} title={<span style={{ marginLeft: 10 }}>成套医嘱明细项维护</span>}>
                        {this.state.ordSetID ? (
                            <div className="table-body-height">
                                {this.state.completeColData ? (
                                    <div style={{ background: '#d4e9fd' }}>
                                        <span>当前套餐：{this.state.completeColData ? this.state.completeColData.ordSetDesc : ''}</span>
                                        <Divider type="vertical" style={{ background: 'rgba(0, 0, 0, 0.65)' }} />
                                        <span>{this.state.completeColData ? this.state.completeColData.authRangeDesc : ''}套餐</span>
                                    </div>
                                ) : null}
                                <div style={{ height: 40, lineHeight: '40px' }}>
                                    <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '1' ? 'mouse-add-Style' : ''}
                                        onClick={this.addMechansim.bind(this)}
                                        onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                        onMouseOver={this.addMouseOverStyle.bind(this, '1')}>
                                        <Icon className='doctor-add-splice' />
                                        <span>添加</span>
                                    </span>
                                    <span style={{ cursor: 'pointer', marginLeft: 10 }} className={this.state.indexStyle == '2' ? 'mouse-add-Style' : ''}
                                        onClick={this.delMechansim.bind(this)}
                                        onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                        onMouseOver={this.addMouseOverStyle.bind(this, '2')}>
                                        <Icon className='doctor-delete-splice' />
                                        <span>删除</span>
                                    </span>
                                    <span style={{ cursor: 'pointer', marginLeft: 10 }} className={this.state.indexStyle == '3' ? 'mouse-add-Style' : ''}
                                        onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                        onClick={this.handleUpSort.bind(this)}
                                        onMouseOver={this.addMouseOverStyle.bind(this, '3')}>
                                        <Icon className='doctor-up-splice' />
                                        <span>上移</span>
                                    </span>
                                    <span style={{ cursor: 'pointer', marginLeft: 10 }} className={this.state.indexStyle == '4' ? 'mouse-add-Style' : ''}
                                        onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                        onClick={this.handleDownSort.bind(this)}
                                        onMouseOver={this.addMouseOverStyle.bind(this, '4')}>
                                        <Icon className='doctor-down-splice' />
                                        <span>下移</span>
                                    </span>
                                    <span style={{ cursor: 'pointer', marginLeft: 10 }} className={this.state.indexStyle == '5' ? 'mouse-add-Style' : ''}
                                        onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                        onClick={this.handleStartGroup.bind(this)}
                                        onMouseOver={this.addMouseOverStyle.bind(this, '5')}>
                                        <Icon className='doctor-group-splice' />
                                        <span>开始分组</span>
                                    </span>
                                    <span style={{ cursor: 'pointer', marginLeft: 10 }} className={this.state.indexStyle == '6' ? 'mouse-add-Style' : ''}
                                        onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                        onClick={this.handleCannelGroup.bind(this)}
                                        onMouseOver={this.addMouseOverStyle.bind(this, '6')}>
                                        <Icon className='doctor-cannel-group-splice' />
                                        <span>取消分组</span>
                                    </span>
                                    {/* <span style={{ cursor: 'pointer', marginLeft: 10 }} className={this.state.indexStyle == '12' ? 'mouse-add-Style' : ''}
                            onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                            onClick={this.insertDoctorAdvice.bind(this)}
                            onMouseOver={this.addMouseOverStyle.bind(this, '12')}>
                            <Icon className='doctor-save-splice' />
                            <span>保存</span>
                        </span> */}
                                    <Button size='small' type='primary' style={{ marginLeft: 10 }} onClick={this.insertDoctorAdvice.bind(this)}>保存</Button>
                                    <span style={{ marginLeft: '20%' }}>
                                        <span style={{ marginLeft: 10 }}>
                                            <span style={{ color: '#666666' }}>未收费金额（元）：</span>
                                            <span>{totalSum}</span>
                                        </span>
                                        <span style={{ marginLeft: 20 }}>
                                            <span style={{ color: '#666666' }}>当前总金额（元）：</span>
                                            <span>{sum.toFixed(2) || 0}</span>
                                        </span>
                                    </span>
                                </div>
                                <Table
                                    columns={this.state.dynColumns}
                                    dataSource={this.state.dataSource}
                                    loadData={this.loadData.bind(this)}
                                    onRow={this.onClickRightRow}
                                    rowSelection={rowSelection}
                                    rowClassName={(data) => {
                                        return data.ordBilledCode == 'P' ? 'rowClassStyle' : ''
                                    }}
                                    scroll={{ x: totalWidth, y: store.getState().tableHeight.y + 34 }}
                                    bordered
                                    title={() => {
                                        return <span>处方提示信息</span>
                                    }}
                                    onHeaderRow={column => {
                                        return {
                                            onDoubleClick: () => {
                                                this.columnRef.onOpenModel();
                                            },
                                        };
                                    }}
                                    rowKey={(data) => {
                                        return data.tabIndex || data.ordSetDetailID
                                    }}
                                    pagination={false}
                                />
                            </div>
                        ) : '请选择对应的医嘱套进行医嘱添加！'}
                    </Card>

                    {/* 列表顺序调整 */}
                    <PublicDataOrderAdjustment handleQuery={this.loadLeftData} onRef={ref => this.sortRef = ref} />
                </div>
            </Spin>
        )
    }
};

export default CompleteMedicalPage;
