// 电子病历模板维护
import React from 'react';
import {Radio, Tabs, message, Input, Tree, Icon, Button, Table, Modal, Popconfirm
} from 'antd';
import { $http } from 'containers/config/https';
import './style/index.less';
import AddTemplateDirectory from './component/AddTemplateDirectory.jsx';
import AddTemplate from './component/AddTemplate.jsx';
import AddKnowledgeBaseTree from './component/AddKnowledgeBaseTree.jsx';
import AddAddKnowledgeBase from './component/AddAddKnowledgeBase.jsx';
import OtherCustomData from './component/OtherCustomData.jsx';
import RangeMaintenance from './component/RangeMaintenance.jsx';
import SettingsDocumentSize from './component/SettingsDocumentSize';
import ElectronicCaseTemplate from 'pages/common/ElectronicCaseTemplate.jsx';
import EMRToolLibrary from './component/EMRToolLibrary.jsx';
import Moment from "moment";
import '../../assets/css/common.css';
const { TabPane } = Tabs;
const { TreeNode } = Tree;
const { confirm } = Modal;

export default class EMR extends React.Component {
	constructor() {
		super();
		var userData = JSON.parse(sessionStorage.getItem('userData'));
		this.state = {
			userData,
			treeData: [], // 病历模板资源管理器数据
			selectedKeys: [], // 设置选中的树节点
			treeSelectData: {}, // 选中树节点包含的所有数据
			knowledgeBaseTreeData: [], // 知识库资源管理器数据
			knowledgeBaseSelectedKeys: [], // 知识库选中的树节点
			knowledgeBaseTreeSelectData: {}, // 知识库树选中节点包含的所有数据
			counterObj: {},
			insertTemplateArr: [],
			dataSetKey: '1',
			customDataSet: [], // 自定义数据集
			dataSetSelectedKeys: [], // 自定义数据集选中操作
			dataSource: [], // 元素数据源信息
			basicsDataSetColumns: [], // 基础数据集表头数据
			basicsDataSetDataSource: [],
			visible: false,
			rowId: '',
			modalTreeSelectData: {},
			inputId: '', // 双击模板中的输入域ID
			customDataColumns: [], // 自定义数据表头
			customDataTableData: [],
			insertTypeVisible: false,
			frameType: undefined,
			customRowData: {}, // 自定义选中行数据
			trangeListData: [], // 值域数据
			isShowSearch: false,
			citingResourcesKeys: "1",
			patientTestingHeight: "34px",
			isShowPatientTesting: false,
			templateName: "",
			autoExpandParent: true,
			expandedKeys: [],
			searchHeight: "68px",
			knowledgeAutoExpandParent: true,
			knowledgeExpandedKeys: [],
			knowledgeValue: "",
			dataSetAutoExpandParent: true,
			dataSetExpandedKeys: [],
			dataSetValue: "",
			customDataRowId: "",
			customDataRowData: {},
			fontTyle: undefined,
			colorTemplateFlag: '',
			isShowCustomPopUps: false,
			selectionXml: "",
			drawerVisible: false,
			nodeDirectoryTreeData: [],
			popoverVisible: false, // 插入表格
			dbTreeSelectData: {},
			chapterDataSource: [], // 章节列表数据 
			chapterSetColumns: [], // 章节表头数据
			chapterRowId: "", // 章节行id
		}
	}

	componentDidMount() {
		this.getKnowledgeBaseTreeData(); // 获取知识库资源数据
		this.getTreeData();
	}
	
	componentWillUnmount() {
		if (this.state.dbTreeSelectData&&this.state.dbTreeSelectData.releaseFlag&&this.state.dbTreeSelectData.releaseFlag === "N") {
			this.handleSave();
		} 
		// 组件销毁前将静止让setState修改state的状态
		this.setState = (state,callback)=>{ return; }
	}

	// 保存
	handleSave = (flag) => {
		let xmlStrAndDataSource = this.caseTemplateChild.getTemplateXml(flag);
		let {dbTreeSelectData} = this.state;
		// console.log(dbTreeSelectData);
		if (!(dbTreeSelectData&&dbTreeSelectData.ID)) {
			message.info("请选择需要保存的模板版本")
			return;
		}
		setTimeout(() => {
			let data = {
				params: [{
					ID: dbTreeSelectData.ID,
					templateContent: xmlStrAndDataSource&&xmlStrAndDataSource.xmlStr ? xmlStrAndDataSource.xmlStr : "",
					dataSource:  xmlStrAndDataSource&&xmlStrAndDataSource.dataSource ? xmlStrAndDataSource.dataSource : "", // 
					power: flag === "noMes" ? "newVersion" : undefined
				}]
			}
			$http.post('urlADS', this, {
				code: '06020001',
				data: data,
				success: function (res) {
					if (+res.errorCode === 0) {
						// let _dbTreeSelectData = JSON.parse(JSON.stringify(dbTreeSelectData));
						// _dbTreeSelectData.releaseFlag = "Y";
						// 成功提示
						if (!(flag === "release" || flag === "noMes")) {
							message.success("保存成功");
							let obj = JSON.parse(JSON.stringify(dbTreeSelectData));
							obj.releaseFlag = "Y";
							this.setState({dbTreeSelectData: obj})
						}
						flag === "release" ? this.handleRelease() : ''; // 发布
						// this.resetInterfaceData();
						// 重新查询病历目录导航数据
					}
				}
			})
		}, 300)
	}

	onChange = e => {
		this.setState({
			value: e.target.value,
		});
	}

	// 病历模板树选中操作
	onSelect = (keys, event) => {
		let treeRowData = event.node.props.dataRef;
		// console.log(treeRowData);
		this.setState({selectedKeys: keys}, () => {
			if (this.state.selectedKeys&&this.state.selectedKeys.length > 0) {
				this.setState({treeSelectData: treeRowData})
			} else {
				this.setState({treeSelectData: {}})
			}
		})
	};

	// 处理tree数据
	filterTreeData = treeData => {
		let data = treeData&&JSON.parse(JSON.stringify(treeData)).map(item => {
			return {
				title: item.descripts,
				key: item.treeType + item.ID,
				...item,
				children: this.filterTreeData(item.subCatalogue)
			}
		});
		return data;
	}

	// 获取tree数据
	getTreeData = (ID, flag) => {
		let data = {
			params: [{}]
		}
		$http.post('urlS', this, {
			code: "06020002",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let arr = this.filterTreeData(res.result);
					this.setState({treeData: arr, selectedKeys: [], treeSelectData: {}, dbTreeSelectData: {}}, () => {
						this.generateList(this.state.treeData)
						if (ID) {
							let key = [];
							let obj = {
								ID,
								treeType: 'VERSION', 
								deleteOrNot: "Y",
								addOrNot: "N",
								releaseFlag: flag === "release" ? "Y" : "N",
								descripts: Moment().format("YYYY-MM-DD HH:mm"), // 版本号
							};
							key.push('VERSION' + ID);
							this.setState({selectedKeys: key, treeSelectData: obj, dbTreeSelectData: obj});
							if (flag === "release") {
								this.caseTemplateChild.operableShow("no");
								return;
							}
						}
					})
				}
			}
		})
	}

	//以下是Tree展开搜索
	dataList = [];
	generateList = (data) => {
		for (let i = 0; i < data.length; i++) {
			const node = data[i];
			const key = node.key;
			this.dataList.push({ key, title: node.title });
			if (node.children) {
				this.generateList(node.children);
			}
		}
	};

	renderTreeNodes = (data, value) => data.map(item => {
		let type = item.treeType === 'CATALOG' ? 'folder-open' : (item.treeType === 'TEMPLATE' ? 'folder' : 'file');
		let releaseFlag = item.releaseFlag ? item.releaseFlag : "N";
		const index = item.title.indexOf(value);
		const beforeStr = item.title.substr(0, index);
		const afterStr = item.title.substr(index + value&&value.length);
		const title = index > -1 ? (
			<span style={{color: releaseFlag === "Y" ? "#40a9ff" : "rgba(0, 0, 0, 0.65)"}}>
			{beforeStr}
			<span style={{ color: '#FF7F00' }}>{value}</span>
			{afterStr}
			</span>
		) : <span>{item.title}</span>;
		if (item.children) {
			return (
				<TreeNode icon={<Icon style={{color: releaseFlag === "Y" ? "#40a9ff" : "rgba(0, 0, 0, 0.65)"}} type={type} />} title={title} key={item.key} dataRef={item}>
					{this.renderTreeNodes(item.children, value)}
				</TreeNode>
			);
		}
		return <TreeNode icon={<Icon style={{color: releaseFlag === "Y" ? "#40a9ff" : "rgba(0, 0, 0, 0.65)"}} type={type} />} title={title} key={item.key} dataRef={item} />;
	});

	onDirectoryRef = ref => {
		this.directorChild = ref;
	}

	onTemplateRef = ref => {
		this.templateChild = ref;
	}

	// 添加模板
	handleAddCatalog = (flag) => {
		let {treeSelectData} = this.state;
		let obj = {
			treeSelectData,
			flag: 'add'
		}
		if (flag === 'catalog') {
			if (treeSelectData.catalogFlag === "N") {
				return;
			}
			this.directorChild.showModal(obj); // 目录
		} else {
			if (!(treeSelectData&&treeSelectData.ID) || treeSelectData.templateFlag === 'N') {
				return;
			}
			this.templateChild.showModal(obj); // 模板
		}
	}

	// 新建模板版本
	handleAddTemplateVersion = () => {
		let {treeSelectData} = this.state;
		let arr = treeSelectData.children&&treeSelectData.children.length > 0 ? treeSelectData.children : [];
		let id = treeSelectData&&treeSelectData.ID ? treeSelectData.ID : ""; // 最新版本号ID
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let releaseArr = [];

		for(var i = 0; i < arr.length; i++) {
			if (arr[i].releaseFlag === "N") {
				releaseArr.push(arr[i].releaseFlag);
			}
		}
		if (releaseArr&&releaseArr.length > 0) { // 一个模板不能存在多个未发布的版本
			message.error("一个模板不能同时存在多个未发布的版本，请先将未发布的版本号进行发布。");
			return;
		}
		if (!(treeSelectData&&treeSelectData.ID) || treeSelectData.versionFlag === 'N') {
			return;
		}
		let data = {
			params: [{
				templateID: treeSelectData.ID,
			}]
		}
		$http.post('urlADS', this, {
			code: '06020010',
			data: data,
			success: function (res) { 
				if (+res.errorCode === 0) {
					// 成功提示
					message.success('新增成功');
					// 刷新列表数据
					this.getTreeData(res.ID);
					id ? this.handleLoadingDocuments(id, "N", "noSave") : caseTemplateThis.NewFile();
				}
			}
		})
	}

	// 编辑模板
	handleCompileCatalog = () => {
		let {treeSelectData} = this.state;
		if (!(treeSelectData&&treeSelectData.updateOrNot === 'Y')) {
			return;
		}
		let obj = {
			treeSelectData,
			flag: 'compile'
		}
		if(treeSelectData&&treeSelectData.ID) {
			if (treeSelectData.treeType === 'CATALOG') {
				this.directorChild.showModal(obj);
			} else if (treeSelectData.treeType === 'TEMPLATE') {
				this.templateChild.showModal(obj);
			} else {
				return;
			}
		} else {
			return;
		}
	}

	// 删除模板
	handleDeleteCatalog = () => {
		let {treeSelectData, selectedKeys} = this.state;
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let code = '';
		if(treeSelectData&&treeSelectData.ID) {
			if (treeSelectData.treeType === 'CATALOG') {
				code = '06020006';
			} else if (treeSelectData.treeType === 'TEMPLATE') {
				code = '06020009';
			} else {
				code = '06020012';
			}
		} else {
			return;
		}
		let data = {
			params: [{
				ID: treeSelectData.ID
			}]
		}
		$http.post('urlADS', this, {
			code: code,
			data: data,
			success: function (res) { 
				if (+res.errorCode === 0) {
					message.success('删除成功');
					// 刷新列表数据
					this.getTreeData();
					if (selectedKeys&&selectedKeys.length > 0) {
						let key = "VERSION" + treeSelectData.ID;
						// console.log(key, selectedKeys[0])
						(code === '06020012')&&(key === selectedKeys[0]) ? caseTemplateThis.operableShow() : '';
					}
				}
			}
		})
	}

	// 获取知识库树数据
	getKnowledgeBaseTreeData = () => {
		let data = {
			params: [{}]
		}
		$http.post('urlS', this, {
			code: "06020013",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let arr = this.filterTreeData(res.result);
					this.setState({knowledgeBaseTreeData: arr, knowledgeBaseSelectedKeys: []})
				}
			}
		})
	}

	// 知识库树选中操作
	knowledgeBaseOnSelect = (keys, event) => {
		this.setState({knowledgeBaseSelectedKeys: keys}, () => {
			if (this.state.knowledgeBaseSelectedKeys&&this.state.knowledgeBaseSelectedKeys.length > 0) {
				this.setState({knowledgeBaseTreeSelectData: event.node.props.dataRef})
			}
		})
	}

	onKnowledgeBaseTreeRef = ref => {
		this.knowledgeBaseTreeChild = ref;
	}

	onKnowledgeBaseRef = ref => {
		this.knowledgeBaseChild = ref;
	}

	// 添加目录、知识库
	handleAddknowledgeBase = (flag) => {
		let {knowledgeBaseTreeSelectData} = this.state;
		let obj = {
			knowledgeBaseTreeSelectData,
			flag: 'add'
		}
		if (flag === 'catalog') {
			this.knowledgeBaseTreeChild.showModal(obj); // 目录
		} else {
			this.knowledgeBaseChild.showModal(obj); // 知识库
		}
	}

	// 新建知识库版本
	handleAddknowledgeBaseVersion = () => {
		let {knowledgeBaseTreeSelectData} = this.state;
		let data = {
			params: [{
				knowledgeID: knowledgeBaseTreeSelectData.ID
			}]
		}
		$http.post('urlADS', this, {
			code: '06020020',
			data: data,
			success: function (res) { 
				if (+res.errorCode === 0) {
					// 成功提示
					message.success('新增成功');
					// 刷新列表数据
					this.getKnowledgeBaseTreeData();
				}
			}
		})
	}

	// 编辑模板
	handleCompileCatalog2 = () => {
		let {knowledgeBaseTreeSelectData} = this.state;
		let obj = {
			knowledgeBaseTreeSelectData,
			flag: 'compile'
		}
		if(knowledgeBaseTreeSelectData&&knowledgeBaseTreeSelectData.ID) {
			if (knowledgeBaseTreeSelectData.treeType === 'CATALOG') {
				this.knowledgeBaseTreeChild.showModal(obj);
			} else if (knowledgeBaseTreeSelectData.treeType === 'TEMPLATE') {
				this.knowledgeBaseChild.showModal(obj);
			} else {
				return;
			}
		} else {
			return;
		}
	}

	// 删除模板
	handleDeleteCatalog2 = () => {
		let {knowledgeBaseTreeSelectData} = this.state;
		let code = '';
		if(knowledgeBaseTreeSelectData&&knowledgeBaseTreeSelectData.ID) {
			if (knowledgeBaseTreeSelectData.treeType === 'CATALOG') {
				code = '06020016';
			} else if (knowledgeBaseTreeSelectData.treeType === 'TEMPLATE') {
				code = '06020019';
			} else {
				code = '06020022';
			}
		} else {
			return;
		}
		let data = {
			params: [{
				ID: knowledgeBaseTreeSelectData.ID
			}]
		}
		$http.post('urlADS', this, {
			code: code,
			data: data,
			success: function (res) { 
				if (+res.errorCode === 0) {
					message.success('删除成功');
					// 刷新列表数据
					this.getKnowledgeBaseTreeData();
				}
			}
		})
	}

	// 根据ID加载电子病历模板
	handleLoadingDocuments = (ID, releaseFlag, isSave) => {
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let data = {
			params: [{
				ID, // 模板版本ID
			}]
		}
		$http.post('urlS', this, {
			code: "06020023",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					// this.setState({templatePath:	res.result&&res.result.templatePath}, () => {
					caseTemplateThis.setInsertTemplateArr(res.result&&res.result.dataSource, releaseFlag);
					res.result.templatePath? caseTemplateThis.AjaxLoad(res.result.templatePath, true, isSave, "template") : caseTemplateThis.NewFile();
					// })
				}
			}
		})
	}

	// 双击模板资源管理器
	dblclickTreeNodes = (status, record) => {
		let releaseFlag = record.props.dataRef.releaseFlag;
		let treeType = record.props.dataRef.treeType;
		let ID = record.props.dataRef.ID;
		let key = [];
		key.push(treeType + ID);
		if (treeType !== 'VERSION') {
			return;
		} else {
			if (this.state.dbTreeSelectData&&this.state.dbTreeSelectData.ID === ID) {
				return;
			}
			// 如果是未发布版本双击切换前需要提示保存模板
			if (this.state.dbTreeSelectData&&this.state.dbTreeSelectData.releaseFlag&&this.state.dbTreeSelectData.releaseFlag === "N") {
				let _this = this;
				confirm({
					title: '请确认当前病历模板是否保存，如未保存是否需要保存？',
					content: "当前版本号为：" + _this.state.dbTreeSelectData.descripts,
					onOk() {
						_this.handleSave();
					},
					onCancel() {
						_this.setState({selectedKeys: key, treeSelectData: record.props.dataRef, dbTreeSelectData: record.props.dataRef}, () => {
							// 加载电子病历
							_this.handleLoadingDocuments(ID, releaseFlag)
						})
					},
				});
			} else {
				this.setState({selectedKeys: key, treeSelectData: record.props.dataRef, dbTreeSelectData: record.props.dataRef}, () => {
					// 加载电子病历
					this.handleLoadingDocuments(ID, releaseFlag)
				})
			}
		}
	}
	
	// 数据集
	dataSetKeyTabsCut = key => {
		this.setState({dataSetKey: key}, () => {
			if (this.state.dataSetKey === '2') {
				if (!(this.state.basicsDataSetColumns&&this.state.basicsDataSetColumns.length > 0)) {
					this.getBasicsDataSetColumns(); // 初始化基本数据集表头数据
				}
				this.getBasicsDataSetDataSource();
			} else if (this.state.dataSetKey === '3') {
				if (!(this.state.customDataColumns&&this.state.customDataColumns.length > 0)) {
					this.getCustomDataColumns(); // 初始化其他自定义表头数据
				}
				this.getCustomDataTableData();
			}
		})
	}

	// 获取自定义数据集
	getCustomDataSet = () => {
		let data = {
			params: [{
				ID: '', // 表ID
				code: '', // 数据集代码
				descripts: '', // 数据集描述
				serviceCode: '', // 服务代码
			}],
			pagination: [{
				pageSize: 10000,
				currentPage: 1
			}]
		}
		$http.post('urlS', this, {
			code: "06010017",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.result) {
					for(var i = 0; i < res.result.length; i++) {
						res.result[i].key = 'main' + res.result[i].ID;
					}
					this.setState({ customDataSet: res.result })
				}
			}
		})
	}

	// 异步加载数据集的子数据数据
	onLoadData = treeNode =>
		new Promise(resolve => {
			console.log(treeNode)
			if (!treeNode.props.serviceCode || treeNode.props.children) {
				resolve();
				return;
			}
			let ID = treeNode.props.dataRef.ID;
			let data = {
				params: [{
					code: "", // 数据集代码
					descripts: "", // 数据集描述
					CBEMRDSRParRef: ID,
				}],
				pagination: [{
					pageSize: 1000,
					currentPage: 1
				}]
			}
			$http.post('urlS', this, {
				code: "06010025",
				data: data,
				success: function (res) {
					if (+res.errorCode === 0 && res.result) {
						for(var i = 0; i < res.result.length; i++) {
							res.result[i].key = res.result[i].ID;
							res.result[i].isLeaf = true;
							res.result[i].serviceCode = treeNode.props.serviceCode;
							res.result[i].type = 'C',
							res.result[i].customID = res.result[i].ID; 
						}
						treeNode.props.dataRef.children = res.result;
						// console.log(this.state.customDataSet)
						this.setState({
							customDataSet: [...this.state.customDataSet],
						});
						resolve();
					} else {
						resolve();
					}
				}
			})
		}
	)

	renderCustomDataSetTreeNodes = data => data.map(item => {
			const index = item.descripts.indexOf(this.state.dataSetValue);
			const beforeStr = item.descripts.substr(0, index);
			const afterStr = item.descripts.substr(index + this.state.dataSetValue&&this.state.dataSetValue.length);
			const title = index > -1 ? (
					<span>
					{beforeStr}
					<span style={{ color: '#FF7F00' }}>{this.state.dataSetValue}</span>
					{afterStr}
					</span>
			) : <span>{item.descripts}</span>;
			if (item.children&&item.children.length > 0) {
				return (
					<TreeNode title={title} key={item.key} dataRef={item}>
						{this.renderCustomDataSetTreeNodes(item.children)}
					</TreeNode>
				);
			}
			return <TreeNode title={title} key={item.key} {...item} dataRef={item} />;
		}
	);

	// 双击自定义数据集树
	dataSetDBClickTreeNodes = (status, record) => {
		if (!record.props.isLeaf) { // 如果不是子集数据择不将这条数据插入到模板中
			return;
		}
		let key = [];
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let obj = JSON.parse(JSON.stringify(record.props.dataRef))
		key.push(record.props.dataRef.ID);
		this.setState({dataSetSelectedKeys: key}, () => {
			caseTemplateThis.InsertDynamicList(obj)
		})
	}

	// 获取基础数据集表头数据
	getBasicsDataSetColumns = () => {
		let columns = [
			{
                title: '数据集代码',
                dataIndex: 'code',
                align: "center",
                width: '100px'
            },
            {
                title: '数据集名称',
                dataIndex: 'descripts',
                align: "center",
                width: '100px'
            },
		];
		this.setState({basicsDataSetColumns: columns})
	}

	// 获取基础数据集列表数据
	getBasicsDataSetDataSource = () => {
		let data = {
			params: [{
				ID: '', // 表ID
				code: '', // 数据集代码
				descripts: '', // 数据集描述
				dataSetType: '', // 数据集类型
			}],
			pagination: [{
				pageSize: 10000,
				currentPage: 1
			}]
		}
		$http.post('urlS', this, {
			code: "06010013",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.result) {
					for(var i = 0; i < res.result.length; i++) {
						res.result[i].key = i;
						res.result[i].type = 'B';
					}
					this.setState({ basicsDataSetDataSource: res.result})
				}
			}
		})
	}

	// 基础字典操作行
	onClickOnRow = (record) => {
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		return {
			// 单击行选中
			onClick: () => {
				if (this.state.rowId === '') {
					// 保存行数据以及ID
					this.setState({rowId: record.key})
				} else {
					if (this.state.rowId !== record.key) {
						this.setState({rowId: record.key})
					}
				}
			},
			onDoubleClick: () => {
				this.setState({rowId: record.key}, () => {
					caseTemplateThis.dynamicDropDownList(record);
				})
			}
		}
	}

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

	// 重置界面操作数据
	resetInterfaceData = () => {
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		this.setState({dataSetSelectedKeys: [], rowId: '', selectedKeys: [], treeSelectData: {}, dbTreeSelectData: {}}, () => {
			caseTemplateThis.NewFile();
		})
	}

	// 获取自定义数据表头数据
	getCustomDataColumns = () => {
		let columns = [
			{
                title: '代码',
                dataIndex: 'code',
                align: "center",
                width: '80px'
            },
            {
                title: '描述',
                dataIndex: 'descripts',
                align: "center",
                width: '120px'
            },
            {
                title: '是否下拉框标志',
                dataIndex: 'listBoxOrNot',
                align: "center",
				width: '100px',
				render(listBoxOrNot){
					let config = {
						'Y': '是',
						'N': '否'
					}
					return config[listBoxOrNot];
				}
			},
			{
                title: '是否单选框标志',
                dataIndex: 'radioOrNot',
                align: "center",
				width: '100px',
				render(radioOrNot){
					let config = {
						'Y': '是',
						'N': '否'
					}
					return config[radioOrNot];
				}
            },
            {
                title: '是否复选框标志',
                dataIndex: 'checkBoxOrNot',
                align: "center",
				width: '100px',
				render(checkBoxOrNot){
					let config = {
						'Y': '是',
						'N': '否'
					}
					return config[checkBoxOrNot];
				}
			},
			{
				title: '操作',
				align: "center",
				width: 80,
				// fixed: 'right',
				render: (text, record) => (
					<span>
						<span onClick={() => this.rangeMaintenanceChild.showModal(record)} className='span' style={{color: 'rgb(77, 193, 130)'}}>维护值域</span>
						
						{/* <Divider type="vertical" />
					  <Icon type="edit" style={{color: '#108EE9'}}></Icon>
						<span className='span' onClick={() => this.handleCustomDataCompile(record)}>编辑</span>
						
						<Divider type="vertical" />
							<Icon type="delete" style={{color: 'rgba(240,65,52,1)'}}></Icon>
						<Popconfirm title="删除不可恢复，你确定要删除吗?" onConfirm={() => this.handleCustomDataDelete(record)} >
							<span className='span' style={{color: 'rgba(240,65,52,1)'}}>删除</span>
						</Popconfirm> */}
				  </span>
				),
			}
		];
		this.setState({customDataColumns: columns});
	}

	// 获取自定义列表数据
	getCustomDataTableData = () => {
		let data = {
			params: [{}],
			pagination: [{
				pageSize: 10000,
				currentPage: 1
			}]
		}
		$http.post('urlS', this, {
			code: "06010043",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.result) {
					for(var i = 0; i < res.result.length; i++) {
						res.result[i].key = i;
					}
					this.setState({ customDataTableData: res.result})
				}
			}
		})
	}

	// 编辑自定义数据
	handleCustomDataCompile = () => {
		this.otherCustomDataChild.showModal(this.state.customDataRowData, 'compile')
	}

	// 删除自定义数据
	handleCustomDataDelete = () => {
		let data = {
			params: [{
				ID: this.state.customDataRowData.ID
			}]
		}
		$http.post('urlADS', this, {
			code: "06010039",
			data: data,
			success: function (res) { 
				if (+res.errorCode === 0) {
					message.success('删除成功');
					// 刷新列表数据
					this.getCustomDataTableData();
				}
			}
		})
	}

	otherCustomDataOnRef = ref => {
		this.otherCustomDataChild = ref;
	}

	rangeMaintenanceOnRef = ref => {
		this.rangeMaintenanceChild = ref;
	}

	// 自定义数据操作行
	customDataOnRow = record => {
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		return {
			onClick: () => {
				if (this.state.customDataRowId === '') {
					// 保存行数据以及ID
					this.setState({customDataRowId: record.ID, customDataRowData: record});
				} else {
					if (this.state.customDataRowId !== record.ID) {
						this.setState({customDataRowId: record.ID, customDataRowData: record});
					}
				}
			},
			onDoubleClick: () => {
				let {checkBoxOrNot, listBoxOrNot, radioOrNot} = record;
				if (checkBoxOrNot === 'Y' && listBoxOrNot === 'N' && radioOrNot === 'N') {
					// 直接插入checkbox
					this.geTrangeListData(record, 'checkbox');
				} else if (checkBoxOrNot === 'N' && listBoxOrNot === 'Y' && radioOrNot === 'N') {
					// 直接插入下拉列表
					caseTemplateThis.dynamicDropDownList(record, 'no');
				} else if (checkBoxOrNot === 'N' && listBoxOrNot === 'N' && radioOrNot === 'Y') {
					// 直接插入radio
					this.geTrangeListData(record, 'radio');
				} else if (checkBoxOrNot === 'N' && listBoxOrNot === 'N' && radioOrNot === 'N') {
					// 直接插入radio
					return;
				} else {
					this.handleInsertTypeShowModal(record)
				}
			}
		}
	}

	customDataRowClassName = record => {
		return record.ID === this.state.customDataRowId ? 'clickRowStyle' : '';
	}

	// 请求自定义数据所在行的维护值域
	geTrangeListData = (record, flag) => {
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let data = {
			params: [{
				othCode: record.code
			}]
		}
		$http.post('urlADS', this, {
			code: "06010036",
			data: data,
			success: function (res) { 
				if (+res.errorCode === 0) {
					let arr = res.result;
					for (var i = 0; i < arr.length; i++) {
						arr[i].ToolTip = arr[i].descripts;
						arr[i].Text = arr[i].descripts;
						arr[i].Value = arr[i].ID;
					}
					this.setState({trangeListData: arr}, () => {
						if (flag === 'checkbox' || flag === 'radio') {
							caseTemplateThis.insertCheckboxRadio(this.state.trangeListData, flag, record);
						}
					})
				}
			}
		})
	}

	// 打开选择插入类型弹窗
	handleInsertTypeShowModal = (record) => {
		this.setState({insertTypeVisible: true, customRowData: record});
	}

	// 关闭选择插入类型弹窗
	handleInsertTypeCancel = () => {
		this.setState({insertTypeVisible: false});
	}

	// 确认
	handleInsertTypeOk = () => {
		let {customRowData, frameType} = this.state;
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		if (frameType === 'radio') {
			this.geTrangeListData(customRowData, frameType);
			this.handleInsertTypeCancel();
		} else if (frameType === 'checkbox') {
			this.geTrangeListData(customRowData, frameType);
			this.handleInsertTypeCancel();
		} else if (frameType === 'select') {
			caseTemplateThis.dynamicDropDownList(customRowData, "no");
			this.handleInsertTypeCancel();
		}
	}

	handleFrameTypeOnChange = e => {
		this.setState({
			frameType: e.target.value,
		});
	}

	documentSetRef = ref => {
		this.documentSetChild = ref;
	}

	// 引用资源tabs切换
	citingResourcesOnChange = key => {
		if (key === '11') {
			if (!(this.state.knowledgeBaseTreeSelectData&&this.state.knowledgeBaseTreeSelectData.treeType === "TEMPLATE")) {
				this.setState({citingResourcesKeys: this.state.citingResourcesKeys}, () => {
					message.error("请双击或者选择知识库当中的模板进行切换");
				});
				return;
			}
		}
		this.setState({citingResourcesKeys: key}, () => {
			if (this.state.citingResourcesKeys === '11') {
				this.getNodeDirectoryTreeData()
			} else if (this.state.citingResourcesKeys === '2') {
				if (!(this.state.basicsDataSetColumns&&this.state.basicsDataSetColumns.length > 0)) {
					this.getBasicsDataSetColumns(); // 初始化基本数据集表头数据
				}
				this.getBasicsDataSetDataSource();
			} else if (this.state.citingResourcesKeys === '3') {
				if (!(this.state.customDataSet&&this.state.customDataSet.length > 0)) {
					this.getCustomDataSet(); // 获取自定义数据集
				}
			} else if (this.state.citingResourcesKeys === '4') {
				if (!(this.state.customDataColumns&&this.state.customDataColumns.length > 0)) {
					this.getCustomDataColumns(); // 初始化其他自定义表头数据
				}
				this.getCustomDataTableData();
			} else if (this.state.citingResourcesKeys === '22') {
				if (!(this.state.chapterSetColumns&&this.state.chapterSetColumns.length > 0)) {
					this.getChapterSetColumns(); // 初始化章节
				}
				this.getChapterDataSource()
			}
		})
	}

	// 
	handlePatientTesting = () => {
		this.setState({isShowPatientTesting: !this.state.isShowPatientTesting}, () => {
			if (this.state.isShowPatientTesting) {
				this.setState({patientTestingHeight: "280px"});
			} else {
				this.setState({patientTestingHeight: "34px"});
			}
		})
	}

	handleTemplateNameChange = e => {
		const templateName=e.target.value;
		const expandedKeys = this.dataList.map((item) => {
				if (templateName.length===0) return null;
				if (item.title.indexOf(templateName) > -1) {
						return this.getParentKey(item.key, this.state.treeData);
				}
				return null;
		}).filter((item, i, self) => item && self.indexOf(item) === i);
		this.setState({
				expandedKeys,
				templateName,
				autoExpandParent: true,
		});
	}

	getParentKey = (key, tree) => {
		let parentKey;
		for (let i = 0; i < tree.length; i++) {
				const node = tree[i];
				if (node.children) {
						if (node.children.some(item => item.key === key)) {
								parentKey = node.key;
						} else if (this.getParentKey(key, node.children)) {
								parentKey = this.getParentKey(key, node.children);
						}
				}
		}
		return parentKey;
	};

	onExpand = (expandedKeys) => {
		this.setState({
				expandedKeys,
				autoExpandParent: false,
		});
	}

	handleIsShowSearch = () => {
		this.setState({isShowSearch: !this.state.isShowSearch}, () => {
			if (this.state.isShowSearch) {
				this.setState({searchHeight: "100px"})
			} else {
				this.setState({searchHeight: "68px"})
			}
		})
	}

	knowledgeOnExpand = (knowledgeExpandedKeys) => {
		this.setState({
				knowledgeExpandedKeys,
				knowledgeAutoExpandParent: false,
		});
	}

	handleKnowledgeValueChange = e => {
		const knowledgeValue=e.target.value;
		const knowledgeExpandedKeys = this.dataList.map((item) => {
			if (knowledgeValue.length===0) return null;
			if (item.title.indexOf(knowledgeValue) > -1) {
				return this.getParentKey(item.key, this.state.treeData);
			}
			return null;
		}).filter((item, i, self) => item && self.indexOf(item) === i);
		this.setState({
			knowledgeExpandedKeys,
			knowledgeValue,
			knowledgeAutoExpandParent: true,
		});
	}

	dataSetOnExpand = (dataSetExpandedKeys) => {
		this.setState({
			dataSetExpandedKeys,
			dataSetAutoExpandParent: false,
		});
	}

	handleDataSetValueChange = e => {
		const dataSetValue=e.target.value;
		const dataSetExpandedKeys = this.dataList.map((item) => {
			if (dataSetValue.length===0) return null;
			if (item.title.indexOf(dataSetValue) > -1) {
				return this.getParentKey(item.key, this.state.customDataSet);
			}
			return null;
		}).filter((item, i, self) => item && self.indexOf(item) === i);
		this.setState({
			dataSetExpandedKeys,
			dataSetValue,
			dataSetAutoExpandParent: true,
		});
	}

	handleCustomPopUpsCancel = () => {
		this.setState({isShowCustomPopUps: false});
	}

	// 
	handleCustomPopUpsOk = () => {
		var ctl = document.getElementById("myWriterControl");
		var result = ctl.SetElementTextByID(this.state.initID, "柿子");//赋值
		if (result) {
			this.handleCustomPopUpsCancel();
		}
	}

	selectDivDom = (element) => {
		var ctl = document.getElementById("myWriterControl");
		var rangeNode = ctl.GetContentDocument().getElementById(element);
		// console.log(ctl, rangeNode)
		var s = window.getSelection();

		if(s.rangeCount > 0) s.removeAllRanges();
		var range = document.createRange();
		range.selectNode(rangeNode);
		s.addRange(range);
	}

	// 解锁模板
	unlockingTemplate = () => {
		let ID = this.state.treeSelectData&&this.state.treeSelectData.ID ? this.state.treeSelectData.ID : "";
		let data = {
			params: [{
				ID, // 模板版本ID
			}]
		}
		$http.post('urlS', this, {
			code: "06020032",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success("解锁知识库成功")
				}
			}
		})
	}
	
	knowledgeBaseDoubleClick = (status, record) => {
		let key = [];
		let obj = JSON.parse(JSON.stringify(record.props.dataRef));
		if (obj.treeType !== 'TEMPLATE') {
			return;
		} else {
			key.push(obj.treeType + obj.ID);
			this.setState({knowledgeBaseSelectedKeys: key, knowledgeBaseTreeSelectData: obj}, () => {
				this.getNodeDirectoryTreeData()
			})
		}
	}

	// 获取知识库节点目录树
	getNodeDirectoryTreeData = (obj) => {
		let {knowledgeBaseTreeSelectData} = this.state;
		let data = {
			params: [{
				knowledgeID: knowledgeBaseTreeSelectData.ID
			}]
		}
		$http.post('urlS', this, {
			code: "06020030",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let arr = this.filterTreeData(res.result);
					this.setState({nodeDirectoryTreeData: arr, nodeDirectorySelectedKeys: [], nodeDirectoryTreeSelectData: {}, citingResourcesKeys: "11"})
				} else {
					this.setState({nodeDirectoryTreeData: [], nodeDirectorySelectedKeys: [], nodeDirectoryTreeSelectData: {}, citingResourcesKeys: "11"})
				}
			}
		})
	}

	// 知识库节点目录选中操作
	nodeDirectoryOnSelect = (keys, event) => {
		this.setState({nodeDirectorySelectedKeys: keys}, () => {
			
			if (this.state.nodeDirectorySelectedKeys&&this.state.nodeDirectorySelectedKeys.length > 0) {
				this.setState({nodeDirectoryTreeSelectData: event.node.props.dataRef})
			} else {
				this.setState({nodeDirectoryTreeSelectData: {}})
			}
		})
  }

	handleCaseTemplateRef = ref => {
		this.caseTemplateChild = ref;
	}

	// 发布
	handleRelease = () => {
		let {treeSelectData, userData} = this.state;
		if (!(treeSelectData&&treeSelectData.ID)) {
			message.info("请选择需要发布的模板版本")
			return;
		}
		let data = {
			params: [{
				ID: treeSelectData.ID,
				releaseUserID: userData.userID,
			}]
		}
		$http.post('urlADS', this, {
			code: '06020001',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					// 成功提示
					message.success("发布成功");
					// 重新查询病历目录导航数据
					this.getTreeData(treeSelectData.ID, "release");
					// this.resetInterfaceData();
				}
			}
		})
	}
	
	// 双击知识库节点数据 --- 根据
	nodeDirectoryDoubleClick = (status, record) => {
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let treeData = record.props.dataRef;
		let key = "TEMPLATE" + treeData.ID;
		this.setState({nodeDirectorySelectedKeys: key});
		let data = {
			params: [{
				knowledgeNodeID: treeData.ID
			}]
		}
		$http.post('urlADS', this, {
			code: '06010082',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let str = res.result&&res.result.knowledgeNodeContent ? res.result.knowledgeNodeContent : "";
					caseTemplateThis.InsertXmlString(str);
				}
			}
		})
	}

	// 获取章节表头数据
	getChapterSetColumns = () => {
		const columns = [
			{
				title: '代码',
				dataIndex: 'eMRChapterCode',
				align: "center",
				key: '1',
			},
			{
				title: '描述',
				dataIndex: 'eMRChapterDesc',
				align: "center",
				key: '2',
			},
			{
				title: '所属医院',
				dataIndex: 'eMRChapterHospDesc',
				align: "center",
				key: '3',
			},
		];
		this.setState({chapterSetColumns: columns});
	}

	// 获取章节列表数据
	getChapterDataSource = () => {
		let data = {
			params: [{}]
		}
		$http.post('urlDeault', this, {
			code: "06010085",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
				for(var i = 0; i < res.result.length; i++) {
					res.result[i].key = i;
				}
					this.setState({chapterDataSource: res.result})
				}
			}
		})
	}

	// 章节行操作
	handleChapterClickOnRow = (record) => {
		return {
			// 单击行选中
			onClick: () => {
				if (this.state.chapterRowId === '') {
					// 保存行数据以及ID
					this.setState({chapterRowId: record.eMRChapterID, chapterRowData: record})
				} else {
					if (this.state.chapterRowId !== record.eMRChapterID) {
						this.setState({chapterRowId: record.eMRChapterID, chapterRowData: record})
					}
				}
			},
			onDoubleClick: () => {
				this.setState({chapterRowId: record.eMRChapterID, chapterRowData: record}, () => {
					this.getChapterXml()
				})
			}
		}
	}

	setRowClassNameChapter = (record) => {
		return record.record === this.state.chapterRowId ? 'clickRowStyle' : '';
	}

	// 获取章节xml
	getChapterXml = () => {
		let {chapterRowData} = this.state;
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this
		let data = {
			params: [{
				eMRChapterID: chapterRowData.eMRChapterID
			}]
		}
		$http.post('urlDeault', this, {
			code: "06010087",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					caseTemplateThis.insertTheCourseOfDisease(res.result.knowledgeNodeContent, chapterRowData);
				}
			}
		})
	}

	render() {
		let {treeData, selectedKeys, treeSelectData, knowledgeBaseSelectedKeys, knowledgeBaseTreeSelectData, 
			knowledgeBaseTreeData, customDataSet, dataSetSelectedKeys, basicsDataSetDataSource, basicsDataSetColumns, customDataTableData,
			customDataColumns, insertTypeVisible, frameType, customRowData, isShowSearch, citingResourcesKeys, patientTestingHeight, isShowPatientTesting,
			templateName, autoExpandParent, expandedKeys, searchHeight, knowledgeAutoExpandParent, knowledgeValue, knowledgeExpandedKeys, dataSetAutoExpandParent,
			dataSetExpandedKeys, dataSetValue, isShowCustomPopUps, nodeDirectoryTreeData, nodeDirectorySelectedKeys, chapterDataSource, chapterSetColumns, 
			
		} = this.state;
		let caseTemplateThis = this.caseTemplateChild ? this.caseTemplateChild : {}; // 公共病历组件this

		let param = {
			setChapter: "show"
		}

		return (
			<div className="emr-style">
				<div style={{width: "260px", height: '100%', display: 'inline-block', overflow: 'hidden'}}>
					<div style={{textAlign: "center", height: '34px', lineHeight: '34px', fontWeight: 900, fontSize: "14px", background: "#fafafa", borderBottom: "1px solid #e8e8e8"}}>病历目录导航</div>
					<div className="navigation-operation-icon" style={{background: "#fafafa"}}>
						{treeSelectData&&treeSelectData.deleteOrNot === 'Y' ? (<Popconfirm title="删除不可恢复，你确定要删除吗?" onConfirm={this.handleDeleteCatalog} >
							<Icon type="delete" 
								style={{
									cursor: "pointer", 
									color: "rgb(240, 65, 52)" 
								}}
								title={treeSelectData.treeType === 'CATALOG' ? '删除目录' : (treeSelectData.treeType === 'TEMPLATE' ? '删除模板' : (treeSelectData.treeType === 'VERSION' ? '删除模板版本': ''))}
							/>
						</Popconfirm>) : (
							<Icon type="delete" 
								style={{
									cursor: "no-drop", 
									color: "#666"
								}}
								title={treeSelectData.treeType === 'CATALOG' ? '删除目录' : (treeSelectData.treeType === 'TEMPLATE' ? '删除模板' : (treeSelectData.treeType === 'VERSION' ? '删除模板版本': ''))}
							/>
						)}
						<Icon type="edit" 
							style={{
								cursor: treeSelectData&&treeSelectData.updateOrNot === 'Y' ? "pointer" : "no-drop", 
								color: treeSelectData&&treeSelectData.updateOrNot === 'Y' ? "#1890ff" : "#666"
							}}
							onClick={this.handleCompileCatalog} 
							title={treeSelectData.treeType === 'CATALOG' ? '编辑目录' : (treeSelectData.treeType === 'TEMPLATE' ? '编辑模板' : "")}
						/>
						<Icon type="folder-open" 
							style={{
								color: treeSelectData&&treeSelectData.addOrNot === 'N' ? "#666" : (treeSelectData&&treeSelectData.catalogFlag === 'N' ? "#666" : "#1999db"), 
								cursor: treeSelectData&&treeSelectData.addOrNot === 'N' ? "no-drop" : (treeSelectData&&treeSelectData.catalogFlag === 'N' ? "no-drop" : 'pointer')
							}} 
							onClick={() => this.handleAddCatalog('catalog')} title="新建目录"  />
						<Icon type="folder-add" 
							style={{
								color: treeSelectData&&treeSelectData.addOrNot === "N" ? "#666" : (treeSelectData.templateFlag === 'Y' ? "#1999db" : '#666'), 
								cursor: treeSelectData&&treeSelectData.addOrNot === "N" ? "no-drop" : (treeSelectData.templateFlag === 'Y' ? 'pointer' : 'no-drop')
							}} 
							title="新建模板" onClick={() => this.handleAddCatalog('template')} />
						<Icon type="file-add" 
							style={{
								color: treeSelectData&&treeSelectData.addOrNot === "N" ? "#666" : (treeSelectData.versionFlag === 'Y' ? "#1999db" : "#666"), 
								cursor: treeSelectData&&treeSelectData.addOrNot === "N" ? "no-drop" : (treeSelectData.versionFlag === 'Y' ? "pointer" : "no-drop")
							}}  
							title="新建模板版本" onClick={this.handleAddTemplateVersion} />
						<Icon type={isShowSearch ? "caret-down" : "caret-right"} onClick={this.handleIsShowSearch} title="搜索病历" />
					</div>
					<Input style={{width: '100%', display: isShowSearch ? "block" : "none"}} value={templateName} onChange={this.handleTemplateNameChange} placeholder="请输入模板名称查询" />
					<div style={{height: `calc(100% - ${searchHeight})`, overflow: 'auto'}}>
						<Tree showIcon 
							autoExpandParent={autoExpandParent}
							onExpand={this.onExpand}
							expandedKeys={expandedKeys}
							onSelect={this.onSelect} 
							selectedKeys={selectedKeys} 
							onDoubleClick={this.dblclickTreeNodes}>
							{this.renderTreeNodes(treeData, templateName)}
						</Tree>
					</div>
					<AddTemplateDirectory onRef={this.onDirectoryRef} handleQuery={this.getTreeData} />
					<AddTemplate onRef={this.onTemplateRef} handleQuery={this.getTreeData} />
				</div>
				<div style={{width: "calc(100% - 620px)", height: '100%', display: 'inline-block', overflow: 'auto'}}>
					<div style={{padding: '0 6px', position: 'relative', height: '100%' }}>
						<ElectronicCaseTemplate 
							param={param}
							editorID={this.props.editorID ? this.props.editorID : "EMRWriterControl"}
							onRef={this.handleCaseTemplateRef}
							handleSave={this.handleSave} // 保存
							unlockingTemplate={this.unlockingTemplate} // 解锁模板
							handleRelease={() => this.handleSave("release")} // 发布
							// handleDelete={this.handleDelete} // 删除
						/>
						<div style={{width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, left: 0, height: '100%'}}></div>
						<div style={{width: '6px', background: 'rgba(240, 242, 245, 1)', position: 'absolute', top: 0, right: 0, height: '100%'}}></div>
					</div>
				</div>
				<div style={{width: "360px", height: '100%', display: 'inline-block', overflow: 'hidden'}}>
					<Tabs defaultActiveKey="1" className="right-tabs" style={{height: `calc(100% - ${patientTestingHeight})`, overflow: 'auto'}}>
						<TabPane tab="引用资源" key="1">
							<div>
								<Tabs activeKey={citingResourcesKeys} onChange={this.citingResourcesOnChange} tabPosition="left" type="card" className="word-wrap">
									<TabPane tab="知识库" key="1">
										<Input value={knowledgeValue} onChange={this.handleKnowledgeValueChange} placeholder="请输入名称搜索" />
										<Tree showIcon 
											autoExpandParent={knowledgeAutoExpandParent}
											onExpand={this.knowledgeOnExpand}
											expandedKeys={knowledgeExpandedKeys}
											onSelect={this.knowledgeBaseOnSelect} 
											selectedKeys={knowledgeBaseSelectedKeys}
											onDoubleClick={this.knowledgeBaseDoubleClick}>
											{this.renderTreeNodes(knowledgeBaseTreeData, knowledgeValue)}
										</Tree>
									</TabPane>
									<TabPane tab="知识库节点数据" key="11">
										<Tree showIcon 
												onSelect={this.nodeDirectoryOnSelect} 
												selectedKeys={nodeDirectorySelectedKeys}
												onDoubleClick={this.nodeDirectoryDoubleClick}
											>
											{this.renderTreeNodes(nodeDirectoryTreeData)}
										</Tree>
									</TabPane>
									<TabPane tab="基础字典" key="2">
										<Table
											pagination={false}
											dataSource={basicsDataSetDataSource}
											columns={basicsDataSetColumns} 
											onRow={this.onClickOnRow}
											rowClassName={this.setRowClassNameLeftTable}
										/>
									</TabPane>
									<TabPane tab="章节" key="22">
										<Table
											pagination={false}
											dataSource={chapterDataSource}
											columns={chapterSetColumns} 
											onRow={this.handleChapterClickOnRow}
											rowClassName={this.setRowClassNameChapter}
										/>
									</TabPane>
									<TabPane tab="自定义数据集" key="3">
										<Input value={dataSetValue} onChange={this.handleDataSetValueChange} placeholder="请输入名称搜索" />
										<Tree 
											loadData={this.onLoadData} 
											autoExpandParent={dataSetAutoExpandParent}
											onExpand={this.dataSetOnExpand}
											expandedKeys={dataSetExpandedKeys}
											selectedKeys={dataSetSelectedKeys} 
											onDoubleClick={this.dataSetDBClickTreeNodes}>
											{this.renderCustomDataSetTreeNodes(customDataSet)}
										</Tree>
									</TabPane>
									<TabPane tab="自定义组件" key="4">
										<div style={{textAlign: "right"}}>
											<Button style={{background: "#1999db", color: "#fff"}} onClick={() => this.otherCustomDataChild.showModal({}, 'add')} >新增</Button>
											<Button style={{margin: '0 12px', background: '#3399ff', color: "#fff"}} onClick={this.handleCustomDataCompile}>编辑</Button>
											<Button style={{background: "#ff0000", color: "#fff"}} onClick={this.handleCustomDataDelete}>删除</Button>
										</div>
										<Table
											pagination={false}
											dataSource={customDataTableData}
											columns={customDataColumns} 
											onRow={this.customDataOnRow}
											rowClassName={this.customDataRowClassName}
											scroll={{x: 760}}
										/>
									</TabPane>
									<TabPane tab="关联历史病历模块" key="5">

									</TabPane>
								</Tabs>
							</div>
						</TabPane>
						<TabPane tab="工具库" key="2">
							<EMRToolLibrary caseTemplateThis={caseTemplateThis} />
						</TabPane>
					</Tabs>
					<div>
						<div style={{textAlign: "center", background: '#fafafa', height: '34px', lineHeight: '34px', position: "relative", color: "#000"}}>
							<Icon onClick={() => this.setState(this.handlePatientTesting)} type={isShowPatientTesting ? "down" : "right"} style={{position: "absolute", left: "12px", top: "10px",  fontSize: '16px', cursor: "pointer"}} />
							绑定患者数据测试
						</div>
						<div style={{padding: "12px", display: isShowPatientTesting ? "block" : "none"}}>
							<Input placeholder="病人ID" />
						</div>
					</div>
				</div>
				<OtherCustomData onRef={this.otherCustomDataOnRef} handleQuery={this.getCustomDataTableData} />
				<RangeMaintenance onRef={this.rangeMaintenanceOnRef} />
				<Modal
					title="选择插入类型"
					visible={insertTypeVisible}
					onOk={this.handleInsertTypeOk}
					onCancel={this.handleInsertTypeCancel}
				>
					<div style={{textAlign: 'center'}}>
						<Radio.Group onChange={this.handleFrameTypeOnChange} value={frameType}>
							{customRowData&&customRowData.listBoxOrNot === 'Y' ? <Radio value="select">下拉框</Radio> : ''}
							{customRowData&&customRowData.radioOrNot === 'Y' ? <Radio value="radio">单选框</Radio> : ''}
							{customRowData&&customRowData.checkBoxOrNot === 'Y' ? <Radio value="checkbox">复选框</Radio> : ''}
						</Radio.Group>
					</div>
				</Modal>
				{/* 页面设置 */}
				<SettingsDocumentSize onRef={this.documentSetRef} ctlDom={document.getElementById("myWriterControl")}  />
				<Modal
					title="自定义弹窗"
					visible={isShowCustomPopUps}
					onOk={this.handleCustomPopUpsOk}
					onCancel={this.handleCustomPopUpsCancel}
				>
					功能完善中请耐心等待
				</Modal>
			</div>
		)
	}
}
