// 草药录入
import React from 'react';
import {
	Row, Col, Card, Input, Tree, Form, Icon, Select, Button, Checkbox, Table, message, Modal, DatePicker, List, Pagination, Radio, Divider, Tooltip, Popconfirm,
	InputNumber, Tabs, Empty
} from 'antd';
import store from 'store';
import { $http } from 'containers/config/https';
import '../style/CMOrderSave.less';
import '../style/index.less';
import PublicModalTable from 'pages/common/PublicModalTable';
import Moment from 'moment';
import AddHeabTemplate from './AddHeabTemplate'; // 添加模板
import AddHeabSetMeal from './AddHeabSetMeal'; // 添加套餐
import PublicModalQueryTable from 'pages/common/PublicModalQueryTable';
import { Util } from 'tools/index';
import { base64Encode, SOFE_SignPKCS7Message } from '../../../tools/sccmPlugin';

const { TreeNode } = Tree;
const { Option } = Select;
const { TabPane } = Tabs;
const { RangePicker } = DatePicker;
const doctorOrder = require('../image/img/icon_doctororder.png');

class CMOrderSave extends React.Component {
	constructor(props) {
		super(props);
		var recordData = JSON.parse(sessionStorage.getItem('patientData'));
		var titleData = JSON.parse(sessionStorage.getItem('titleData'))
		var userData = JSON.parse(sessionStorage.getItem('userData'))
		this.state = {
			titleData,
			treeData: [],
			tableData: [], // 表格数据
			selectData: {}, // 下拉框数据集
			departmentInformation: [], // 科室下拉框数据
			comPrincipleID: undefined, // 用药类型
			dose: undefined, // 药品数量
			doseUnitID: undefined, // 单位
			decoctMethod: undefined,
			decoctMethodID: undefined, // 备注ID
			decoctMethodDesc: '', // 备注
			medDesc: undefined, // 名称描述
			medID: '', //名称ID
			page: 1,
			pageSize: 10000,
			total: 0,
			top: '',
			left: '',
			modalData: [], // 名称模态框数据
			quoteTotal: 0,
			quotePage: 1,
			quotePageSize: 10,
			modalRowId: '',
			rowData: {},
			num: 0,
			orderSetDetailData: [],
			visible: false,
			quoteData: [], //引用历史处方
			quoteRowId: '', // 就诊记录列表选中行id
			quoteRowData: {}, // 就诊记录列表选中行数据
			listData: [], // 本次草药处方列表数据
			zoomSpan: false,
			settlementType: [], // 结算类型下拉框
			user: {},
			rangePicker: [],
			modalDetailListData: [], // 模态框草药处方明细
			checkStatus: false, // 记录全选点击状态
			modalCheckStatus: false,
			recipeListRowId: '', // 本次草药处方列表选中行id
			numSelectData: [], // 单位下拉框数据
			mainPerscAmt: '',
			mainPrescPrice: '',
			mainDurQty: '',
			mainTotalAmt: '',
			mainTotalCount: '',
			detailDurQty: '', // 处方付数
			detailPerscAmt: '', // 处方金额
			detailPrescPrice: '', // 单付金额
			detailModalRowData: {}, // 引用历史处方中选中本次处方列表的行数据
			radioValue: '', // 个人科室模板切换
			expandedKeys: [],
			autoExpandParent: false,
			checkedKeys: [],
			radioData: [], // 个人、科室数据
			inputValue: undefined,
			recordData: recordData,
			checkedArr: [],
			detailRowData: {}, // 选中明细回显数据
			visibleCrad: true, // 是否显示医嘱模板
			handleStatus: false, // 当使用剂型为协定处方时，控制操作
			addStatus: false,
			messageError: '',
			columns: [], // 本次草药处方列表
			totalWidth: 0,
			defaultObj: {}, // 初始默认值
			herbalFormID: undefined,
			inoperable: false,
			minQty: undefined,
			maxQty: undefined,
			userData: userData,
			defaultBtn: 1,
			activeKey: '2',
			packageMsg: [],
			packageExpandedKeys: [],
			packageAutoExpandParent: false,
			ordSetID: '', // 医嘱套ID
			diagTabData: [], // 诊断tab数据
			diagActive: '1', // 当前诊断
			isExistRecord: 'Y', // 病历录入标志
		};
		this.columns = [
			{
				title: '状态',
				dataIndex: 'billStatusCode',
				key: '1',
				width: '80px',
				align: 'center',
				render(billStatusCode) {
					let config = {
						'TB': '录入',
						'P': '已结算',
						'R': '已退费'
					}
					return config[billStatusCode];
				},
			},
			{
				title: '处方概要',
				dataIndex: 'title',
				key: '2',
				align: 'center',
			}
		];
		this.modalColumns = [
			{
				title: '编码',
				dataIndex: 'medCode',
				key: '1',
				width: '100px',
				align: 'center'
			},
			{
				title: '名称*规格',
				dataIndex: 'medDesc',
				width: '150px',
				key: '2',
				align: 'center'
			},
			{
				title: '库存',
				dataIndex: 'medStock',
				width: '150px',
				key: '7',
				align: 'center'
			},
			{
				title: '大类',
				dataIndex: 'medCatDesc',
				width: '100px',
				key: '3',
				align: 'center'
			},
			{
				title: '子类',
				dataIndex: 'medSubCatDesc',
				key: '4',
				width: '150px',
				align: 'center'
			}
		];
		this.quoteColumns = [
			{
				title: '日期',
				dataIndex: 'admDate',
				key: '1',
				width: '90px',
				align: 'center'
			},
			{
				title: '医生',
				dataIndex: 'admDocDesc',
				width: '90px',
				key: '2',
				align: 'center'
			},
			{
				title: '科室',
				dataIndex: 'admLocDesc',
				width: '150px',
				key: '3',
				align: 'center'
			}
		];
		this.myRef1 = React.createRef();
		this.myRef2 = React.createRef();
		this.myRef4 = React.createRef();
		this.myRef5 = React.createRef();
	}

	componentDidMount() {
		let user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		this.setState({ user }, () => {
			this.handleAuthorityControl();
			this.getDiagTabData();
			this.getExistRecordFlag();
			this.loadLocPersonMsg(); // 获取套餐的名称
			this.getRadioData(); // 获取个人以及科室readio数据// 
			this.getChineseAndEnglishData(); // 获取中英文数据
			this.loadEndReceiveOfDisableBtn()//结束就诊后，disable按钮
		})
	};

	// 获取病历录入标志
	getExistRecordFlag = () => {
		const data = {
			params: [{
				admID: !Util.isEmpty(this.state.recordData) ? this.state.recordData.admID : '',
			}],
		}
		$http.post('urlDeault', this, {
			code: "03050280",
			data: data,
			success: function (res) {
				if (res.errorCode == '0') {
					let isExistRecord = res?.isExistRecord || 'N'; // 是否写过病历
					if (isExistRecord !== 'Y') {
						Modal.warning({
							title: '病历录入提醒',
							content: '检测到您还未录入病历，请先录入病历！',
							okText: '知道了'
						});
					}
					this.setState({
						isExistRecord
					});
				}
			}
		});
	};

	loadEndReceiveOfDisableBtn() {
		var { user } = this.state;
		var params = {
			params: [{
				admID: this.state.recordData ? this.state.recordData.admID : '',
				hospID: user.hospID,
				userID: user.userID,
				locID: user.locID,
			}]
		}
		$http.post('urlDeault', this, {
			code: "03100124",
			data: params,
			success: (res) => {
				if (res.errorCode == '0') {
					this.setState({
						disBtn: res.result
					})
				}
			}
		})
	}

	componentWillUnmount() {
		// 组件销毁前将静止让setState修改state的状态
		this.setState = (state, callback) => { return; }
	}

	// 权限控制
	handleAuthorityControl = () => {
		let { user, recordData } = this.state;
		let data = {
			params: [
				{
					hospID: user.hospID, // 登录医院id
					userID: user.userID, // 登录用户id
					locID: user.locID, // 登录科室id
					admID: recordData.admID, // 就诊id
					cmFlag: "Y"
				}
			]
		}
		$http.post('urlDeault', this, {
			code: "03050229",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					this.setState({ inoperable: false })
				} else {
					this.setState({ inoperable: true }, () => {
						message.info(res.errorMessage, this.state.userData && this.state.userData.messageTime);
					})
				}
			}
		})
	}

	// 获取中英文数据
	getChineseAndEnglishData = () => {
		let { user } = this.state;
		let data = {
			params: [{
				compontName: "CMOrderSave",
				type: "C",
				reactCode: ['CMOrderSave']
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					let columnsData = res.result.C && res.result.C.map((item, index) => {
						return {
							...item,
							key: index,
							title: user.language == 'EN' ? (item && item.enDescripts ? item.enDescripts : item.title) : item.title,
							render: (states, rowData) => {
								if (item.dataIndex === "billStatusCode") {
									let config = {
										'TB': this.setMessage("CMOrderSaveenter", "descripts"),
										'P': this.setMessage("CMOrderSavesettled", "descripts"),
										'R': this.setMessage("CMOrderSaverefunded", "descripts")
									}
									return config[states];
								} else {
									return states;
								}
							},
						}
					});
					this.setState({
						columns: columnsData,
						totalWidth: res?.totalWidth || 0,
						localeProvider: user.language == 'EN' ? res.result.language.EN : res.result.language.CN
					})
				}
			}
		})
	}

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

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

	// 获取诊断数据
	getDiagTabData = async () => {
		try {
			const { recordData } = this.state;
			const data = {
				params: [{
					admID: recordData?.admID || '',
					patID: recordData?.patID || '',
					historyFlag: 'Y',
					historyType: '',
					syFlag: 'Y',
				}]
			}
			let res = await React.$asyncPost(this, '03050033', data);
			let diagTabData = res.result?.diagList || [];
			this.setState({
				diagTabData,
			}, () => {
				diagTabData && Array.isArray(diagTabData) && diagTabData.length > 0 && this.getSelectData();
			});
		} catch (error) {
			console.log(error);
			this.getSelectData();
		}
	}

	// 获取下拉框数据
	getSelectData = () => {
		let { user, herbalFormID } = this.state;
		let formData = this.props.form.getFieldsValue();
		let data = {
			params: [
				{
					comPrincipleFlag: '1',
					herbalFormFlag: '1',
					frequenceFlag: '1',
					usageFlag: '1',
					durationFlag: '1',
					authRangeFlag: '1',
					usageExplainFlag: '1',
					decoctMethodFlag: '1',
					cookTypeFlag: '1',
					hospID: user.hospID ? user.hospID : '',
					admType: 'O', // 就诊类型
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050018",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let defaultObj = {
						durQty: formData.durQty ? formData.durQty : (res && res.defaultDurQty ? res.defaultDurQty : undefined),
						// herbalFormID: formData.herbalFormID ? formData.herbalFormID : (res && res.defaultHerbalFormID ? res.defaultHerbalFormID : undefined),
						freqID: formData.freqID ? formData.freqID : (res && res.defaultFreqID ? res.defaultFreqID : undefined),
						usageID: formData.usageID ? formData.usageID : (res && res.defaultUsageID ? res.defaultUsageID : undefined),
						doseQty: formData.doseQty ? formData.doseQty : (res && res.defaultDoseQty ? res.defaultDoseQty : undefined),
						recLocID: formData.recLocID ? formData.recLocID : (res && res.defaultRecLocID ? res.defaultRecLocID : undefined),
						usageExplainID: formData.usageExplainID ? formData.usageExplainID : (res && res.defaultUsageExplainID ? res.defaultUsageExplainID : undefined), // 服用要求
						// admReasonID: undefined, // 结算类型
						cookTypeID: formData.cookTypeID ? formData.cookTypeID : (res && res.defaultCookTypeID ? res.defaultCookTypeID : undefined), // 煎药方式
					}
					this.props.form.setFieldsValue({
						...defaultObj
					})
					this.setState({ selectData: res, defaultObj, herbalFormID: herbalFormID ? herbalFormID : (res && res.defaultHerbalFormID ? res.defaultHerbalFormID : undefined) }, () => {
						this.getDepartmentInformation(this.state.selectData && this.state.selectData.defaultHerbalFormID ? this.state.selectData.defaultHerbalFormID : '', 'yes', 'settlementType');
						this.getTableData();
					})
				} else {
					this.getTableData();
				}
			}
		})
	}

	// 3.13.23.获取科室信息
	getDepartmentInformation = (herbalFormID, status, type) => {
		let { selectData } = this.state;
		let data = {
			params: [
				{
					herbalFormID: herbalFormID ? herbalFormID : '', // 剂型ID
					admType: 'O', // 就诊类型
					tisaneFlag: 'N', // 代煎标识
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050083",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let { defaultObj } = this.state;
					let newDefaultObj = {};
					if (status === 'yes') {
						newDefaultObj = {
							durQty: res.data && res.data.defaultDurQty ? res.data.defaultDurQty : undefined,
							freqID: res.data && res.data.defaultFreqID ? res.data.defaultFreqID : undefined,
							usageID: res.data && res.data.defaultUsageID ? res.data.defaultUsageID : undefined,
							doseQty: res.data && res.data.defaultDoseQty ? res.data.defaultDoseQty : undefined,
							recLocID: res.data && res.data.defaultCMRecLocID ? res.data.defaultCMRecLocID : undefined,
							// usageExplainID: undefined, // 服用要求
							// admReasonID: undefined, // 结算类型
							cookTypeID: res.data && res.data.defaultCookTypeID ? res.data.defaultCookTypeID : undefined, // 煎药方式
						}
						this.props.form.setFieldsValue({
							...newDefaultObj
						})
					}
					this.setState({ departmentInformation: res.data && res.data.CMRecLocList.length > 0 ? res.data.CMRecLocList : [], defaultObj: { ...defaultObj, ...newDefaultObj }, selectData: { ...selectData, cookType: res.data.cookTypeList } }, () => {
						// console.log(this.state.selectData)
						if (type === 'settlementType') {
							this.getSettlementTypeSelectData();
						}
					})
				} else {
					this.setState({ departmentInformation: [] })
				}
			}
		})
	}

	// 获取结算类型下拉框数据
	getSettlementTypeSelectData = () => {
		let { user, recordData, defaultObj } = this.state;
		let data = {
			params: [
				{
					hospID: user.hospID ? user.hospID : '',
					admID: recordData.admID,
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050057",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let defaultValue = "";
					for (var i = 0; i < res.admReason.length; i++) {
						if (res.admReason[i].defaultFlag === "Y") {
							defaultValue = res.admReason[i].id;
							break;
						}
					}
					defaultObj.admReasonID = defaultValue;
					this.setState({ settlementType: res.admReason, defaultObj }, () => {
						// this.props.form.setFieldsValue({ admReasonID: defaultValue }); // 不需要结算类型了
					})
				}
			}
		})
	}

	// 获取描述列表数据
	getModalListData = (isShow) => {
		let { medDesc, pageSize, page, user, recordData, herbalFormID } = this.state;
		let data = {
			params: [
				{
					searchCode: medDesc,
					admID: recordData.admID,
					// admLocID: user.groupID,
					logonLocID: user.locID ? user.locID : '',
					userID: user.userID ? user.userID : '',
					groupID: user.groupID ? user.groupID : '',
					medSubCatID: this.state.selectData && this.state.selectData.defaultMedSubCatID ? this.state.selectData.defaultMedSubCatID : '',
					hospID: user.hospID ? user.hospID : '',
					cmFlag: 'Y',
					herbalFormID, // 草药剂型
				}
			],
			pagination: [{
				pageSize: pageSize,
				currentPage: page
			}]
		}
		setTimeout(() => {
			var gundong = document.getElementById("gundong");
			gundong.scrollTop = 0;
		}, 100)
		$http.post('urlS', this, {
			code: "03050019",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let arr = res.result.data ? res.result.data : [];
					for (var i = 0; i < arr.length; i++) {
						arr[i].key = i + 1
					}
					this.setState({ modalData: arr, total: res.result.totalCount, modalRowId: arr && arr.length > 0 ? arr[0].key : '' }, () => {
						isShow === 'show' ? this.child.showModal() : '';
					})
				} else {
					this.setState({ modalData: [], total: 0 });
					isShow === 'show' ? this.child.showModal() : '';
				}
			},
			error: function () {
				this.setState({ modalData: [], total: 0 });
				isShow === 'show' ? this.child.showModal() : '';
			}
		})
	}

	// 名称回车事件
	nameOnPressEnter = (e) => {
		let recLocID = this.props.form.getFieldValue('recLocID');
		if (!recLocID) {
			message.info("接收科室不能为空", this.state.userData && this.state.userData.messageTime);
			return;
		}
		if (!e.target.value) {
			message.info("请输入名称回车搜索", this.state.userData && this.state.userData.messageTime)
			return;
		}
		let top = document.getElementById('name-input').getBoundingClientRect().top + 40 + 'px';
		let left = document.getElementById('name-input').getBoundingClientRect().left + 'px';
		this.setState({
			top: top,
			left: left,
			medDesc: e.target.value
		}, () => {
			this.getModalListData("show");
		});
	}

	// 用药类型
	handleComPrincipleID = (e) => {
		this.setState({ comPrincipleID: e })
		setTimeout(() => {
			this.myRef4.current.focus();
		}, 100)
	}

	// 药品数量
	handleDose = (e) => {
		this.setState({ dose: e.target.value })
	}

	// 药品单位
	handledoseUnitID = (e) => {
		this.setState({ doseUnitID: e });

	}

	// 名称
	handleMedDesc = (e) => {
		if (!e.target.value) {
			this.setState({ messageError: "" })
		}
		this.setState({ medDesc: e.target.value })
	}

	// 备注
	handleCmOrderSetDetailDecoctMethodID = (e) => {
		this.setState({ decoctMethodID: e }, () => {
			this.doseQtyOnPressEnter()
		});
	}

	// 名称失焦操作
	handleOnBlur = (e) => {
		if (this.state.medID) {
			let arr = this.state.modalData ? JSON.parse(JSON.stringify(this.state.modalData)) : '';
			let status = false;
			for (var i = 0; i < arr.length; i++) {
				if (arr[i].medDesc === e.target.value) {
					status = true;
					break;
				}
			}
			if (!status) {
				this.setState({ medID: '', medDesc: undefined, numSelectData: [], doseUnitID: undefined, decoctMethod: undefined, })
			}
		} else {
			this.setState({ medID: '', medDesc: undefined, numSelectData: [], doseUnitID: undefined, decoctMethod: undefined })
		}
	}

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

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

	// 双击选中行数据的回调
	confirmSelection = (record) => {
		//  console.log(record)
		this.setState({ medDesc: record.medDesc, medID: record.medID ? record.medID : record.ordSetID }, () => {
			this.child.handleCancel();
			this.getNumSelectData(record);
		})
		setTimeout(() => {
			this.myRef2.current.focus();
		}, 100)
	}

	// 获取单位的下拉框以及下拉数据
	getNumSelectData = (record) => {
		let { user, recordData, medID } = this.state;
		let ordDoseUnitIDState = this.state.ordDoseUnitID;
		// let comPrincipleIDState = this.state.comPrincipleID;
		let doseState = this.state.dose;
		let recLocID = this.props.form.getFieldValue('recLocID');
		let obj = {};
		record.medID ? (obj.medID = record.medID) : (obj.ordSetID = record.ordSetID);
		let arr = [];
		arr.push(obj);
		let data = {
			params: [
				{
					recLocID: recLocID, // 执行科室id
					hospID: user.hospID, // 登录医院id
					groupID: user.groupID, //	登录角色id
					userID: user.userID, // 登录用户id
					locID: user.locID, // 登录科室id
					admID: recordData.admID, // 就诊id
					orders: arr
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050076",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					if (record && record.medID) {
						let obj = res.data[0] ? res.data[0] : {};
						let numSelectData = obj && obj.qtyUnitList ? obj.qtyUnitList : [];
						let ordDoseUnitID = ordDoseUnitIDState ? ordDoseUnitIDState : (obj && obj.ordDoseUnitID ? obj.ordDoseUnitID : undefined);
						// let comPrincipleID = comPrincipleIDState ? comPrincipleIDState : (obj && obj.comPrincipleID ? obj.comPrincipleID : undefined);
						let comPrincipleID = undefined;
						let dose = doseState ? doseState : (obj && obj.ordDose ? obj.ordDose : undefined);
						let treatyFlag = obj && obj.treatyFlag ? obj.treatyFlag : '';
						let str = res.errorList && res.errorList.length > 0 ? res.errorList[0].ordDesc + res.errorList[0].errorMessage : '';
						if (res.errorList && res.errorList.length > 1) {
							for (var i = 1; i < res.errorList.length; i++) {
								str += ", " + res.errorList[i].ordDesc + res.errorList[i].errorMessage
							}
						}
						this.setState({ numSelectData, doseUnitID: ordDoseUnitID, comPrincipleID, dose, treatyFlag, messageError: str }, () => {
							if (this.state.treatyFlag === 'Y') {
								this.props.form.setFieldsValue({
									durQty: obj && obj.durQty ? obj.durQty : undefined,
									freqID: obj && obj.freqID ? obj.freqID : undefined,
									usageID: obj && obj.usageID ? obj.usageID : undefined,
									doseQty: obj && obj.doseQty ? obj.doseQty : undefined,
									recLocID: obj && obj.recLocID ? obj.recLocID : undefined,
									usageExplainID: obj && obj.usageExplainID ? obj.usageExplainID : undefined, // 服用要求
									// admReasonID: obj&&obj.recLocID ? obj.recLocID : undefined, // 结算类型
									cookTypeID: obj && obj.cookTypeID ? obj.cookTypeID : undefined, // 煎药方式
								})
							}
						})
					} else { // 医嘱套
						// let {orderSetDetailData} = this.state;
						var concatArr = res.data
						if (!Util.isEmpty(concatArr)) {
							for (var i = 0; i < concatArr.length; i++) {
								concatArr[i].key = i;
								concatArr[i].checkBox = false;
								concatArr[i].medDesc = concatArr[i].ordDesc;
							}
						}
						let obj = res.ordSetData;
						let data = res.data && res.data.map((item) => {
							return {
								dose: item.ordDose,
								medDesc: item.ordDesc,
								doseUnitID: item.ordDoseUnitID,
								numSelectData: item.qtyUnitList, // 单位下拉框
								...item
							}
						})
						this.getDepartmentInformation(obj.herbalFormID, 'no');
						let str = res.errorList && res.errorList.length > 0 ? res.errorList[0].ordDesc + res.errorList[0].errorMessage : '';
						if (res.errorList && res.errorList.length > 1) {
							for (var i = 1; i < res.errorList.length; i++) {
								str += ", " + res.errorList[i].ordDesc + res.errorList[i].errorMessage
							}
						}
						this.setState({ orderSetDetailData: data, messageError: str, herbalFormID: obj && obj.herbalFormID ? obj.herbalFormID : undefined }, () => {
							this.props.form.setFieldsValue({
								durQty: obj && obj.durQty ? obj.durQty : undefined,
								freqID: obj && obj.freqID ? obj.freqID : undefined,
								usageID: obj && obj.usageID ? obj.usageID : undefined,
								doseQty: obj && obj.doseQty ? obj.doseQty : undefined,
								recLocID: obj && obj.recLocID ? obj.recLocID : undefined,
								usageExplainID: obj && obj.usageExplainID ? obj.usageExplainID : undefined, // 服用要求
								// cookTypeID: obj&&obj.cookTypeID ? obj.cookTypeID : undefined, // 煎药方式
							})
							// this.clearDetailInput(); // 清空数据
							setTimeout(() => {
								this.myRef1.current.focus();
							}, 100)
						})
					}
				}
			}
		})
	}

	// 修改名称列表条数以及列数
	compilePage = (page, pageSize) => {
		this.setState({ page, pageSize }, () => {
			this.getModalListData()
		})
	}

	// 保存
	handleSaveDetailList = () => {
		let { user, recordData, recipeListRowId, inoperable, herbalFormID, titleData } = this.state;
		if (recipeListRowId || inoperable || this.state.disBtn == 'N') {
			return;
		}
		if (!herbalFormID) {
			message.info("使用剂型不能为空", this.state.userData && this.state.userData.messageTime);
			return;
		}
		// 当前诊断数据
		this.props.form.validateFields((err, values) => {
			if (!err) {
				let { orderSetDetailData, diagActive, diagTabData } = this.state;
				let arr = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
				let currentDiagRecord = diagActive && diagTabData && Array.isArray(diagTabData) && diagTabData.length > 0 ? diagTabData[diagActive - 1] : {};
				for (var i = 0; i < arr.length; i++) {
					arr[i].cmOrderSetID = this.state.rowId;
					arr[i].diagID = currentDiagRecord?.id || '';
					arr[i].diagCode = currentDiagRecord?.diagCode || currentDiagRecord?.ICDCode || '';
				}
				let obj = {
					admID: recordData.admID, // 患者就诊id
					hospID: user.hospID ? user.hospID : '', // 登录医院id
					userID: user.userID ? user.userID : '', // 登录用户id
					locID: user.locID ? user.locID : '', // 登录科室id
					docID: user.userID ? user.userID : '', // 登录医生id
					...values,
					herbalFormID,
					admReasonID: titleData?.patAdmReasonID || '', // 结算类型 - 绵阳骨科界面不展示，直接取titleData中的patAdmReasonID
					orders: arr && arr.length > 0 ? arr : undefined,
				}
				let data = {
					params: []
				}
				data.params.push(obj);
				let that = this;
				const saveHerbalOrder = () => {
					$http.post('urlADS', that, {
						code: '03050054',
						data: data,
						success: function (res) {
							if (+res.errorCode === 0) {
								// 成功提示
								message.success("保存成功", this.state.userData && this.state.userData.messageTime);
								this.getTableData();
								this.handleResetFields();
								this.handleRationalUse(); // 合理用药
							}
						}
					})
				};

				let containerNames = sessionStorage.getItem('CAcontainerName');
				// CA 登录为可选项：未登录或签名失败时按无 CA 签名保存，避免阻断中草药处方录入。
				if (!containerNames) {
					saveHerbalOrder();
					return;
				}

				Promise.resolve(SOFE_SignPKCS7Message(0, containerNames, base64Encode(JSON.stringify(data)))).then(function (res) {
					if (res && res !== 'null') {
						data.params[0].PKCSData = {
							"toSign": JSON.stringify(data),
							"signedData": res
						};
					} else {
						console.warn('CA签名失败，按无CA签名保存中草药处方');
					}
					saveHerbalOrder();
				}).catch(function (error) {
					console.error('CA签名失败，按无CA签名保存中草药处方', error);
					saveHerbalOrder();
				});
			}
		})
	}

	// 根据ID取出描述
	handleTransition = (arr, id) => {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id === id) {
				return arr[i].descripts
			}
		}
	}

	// 根据单位id取出单位描述
	handleOrdDoseUnitDesc = (id) => {
		let arr = this.state.numSelectData;
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].unitID === id) {
				return arr[i].unitDesc
			}
		}
	}

	// 清空明细输入框
	clearDetailInput = () => {
		let { orderSetDetailData } = this.state;
		for (var i = 0; i < orderSetDetailData.length; i++) {
			orderSetDetailData[i].isboxShadow = false;
		}
		this.setState({
			messageError: '',
			orderSetDetailData,
			comPrincipleID: undefined,
			dose: undefined,
			decoctMethodID: undefined,
			decoctMethodDesc: '',
			medDesc: undefined,
			medID: '',
			doseUnitID: undefined,
			decoctMethod: undefined,
			detailRowData: {}
		})
	}

	// 新增明细
	handleDetailSave = () => {
		let { comPrincipleID, dose, decoctMethodID, medDesc, doseUnitID, decoctMethod,
			medID, selectData, num, orderSetDetailData, detailRowData } = this.state;
		let nums = orderSetDetailData && orderSetDetailData.length > 0 ? num + 1 : 0;
		if (!medID) {
			message.info("请根据名称回车查询名称ID", this.state.userData && this.state.userData.messageTime);
			setTimeout(() => {
				this.myRef1.current.focus();
			}, 100)
			return;
		}
		if (!dose) {
			message.info("单次剂量不能为空", this.state.userData && this.state.userData.messageTime);
			setTimeout(() => {
				this.myRef2.current.focus();
			}, 100)
			return;
		} else {
			var reg = /^[1-9]\d*$/;
			var pattern = new RegExp(reg);
			if (!pattern.test(dose)) {
				message.error("单次剂量只允许为正整数，如1、2、3、……", this.state.userData && this.state.userData.messageTime);
				return;
			}
		}
		let obj = {
			comPrincipleID,
			dose: dose,
			decoctMethodID,
			decoctMethodDesc: this.handleTransition(selectData.decoctMethod, decoctMethodID),
			medDesc,
			medID,
			checkBox: false,
			cmOrderSetDetailSeqNo: detailRowData && detailRowData.medID ? detailRowData.key : nums,
			key: detailRowData && detailRowData.medID ? detailRowData.key : nums,
			decoctMethod,
			doseUnitID,
			ordDoseUnitDesc: this.handleOrdDoseUnitDesc(doseUnitID),
			qtyUnitList: this.state.numSelectData ? JSON.parse(JSON.stringify(this.state.numSelectData)) : [],
			treatyFlag: this.state.treatyFlag ? this.state.treatyFlag : ''
		}
		let arr = JSON.parse(JSON.stringify(this.state.orderSetDetailData));
		if (detailRowData && detailRowData.medID) {
			for (var i = 0; i < arr.length; i++) {
				if (JSON.stringify(arr[i]) === JSON.stringify(detailRowData)) {
					arr[i] = obj
				}
			}
		} else {
			for (var i = 0; i < orderSetDetailData.length; i++) { // 编辑或者新增时名称不能重复
				if (orderSetDetailData[i].medID == medID) {
					message.error("已经存在该名称，请添加别的名称", this.state.userData && this.state.userData.messageTime);
					return;
				}
			}
			arr.push(obj);
		}
		// console.log(arr)
		this.setState({ orderSetDetailData: arr, num: arr.length - 1, addStatus: this.state.treatyFlag && this.state.treatyFlag === 'Y' ? true : false, messageError: '' }, () => {
			this.clearDetailInput();
			setTimeout(() => {
				this.myRef1.current.focus();
			}, 100)
		})
	}

	// 改变checkBox操作
	handleCheckOnChange = (item, e) => {
		e.stopPropagation();
		let { orderSetDetailData } = this.state;
		let arr = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].key === item.key) {
				arr[i].checkBox = !arr[i].checkBox;
				break;
			}
		}
		this.setState({ orderSetDetailData: arr });
	}

	// 全选
	handleCheckAll = () => {
		let { checkStatus, orderSetDetailData } = this.state;
		let checkStatusFlag = checkStatus; // 记录全选点击状态
		this.setState({ checkStatus: !checkStatus });
		let arr = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
		for (var i = 0; i < arr.length; i++) {
			if (!checkStatusFlag) {
				arr[i].checkBox = true;
			} else {
				arr[i].checkBox = false;
			}

		}
		this.setState({ orderSetDetailData: arr })
	}

	// 弹窗确认操作
	handleOk = () => {
		let { detailModalRowData, user, modalDetailListData } = this.state;
		if (!(detailModalRowData && detailModalRowData.ordPrescNo)) {
			message.info(this.setMessage("CMOrderSavePSAPODTBO", "descripts"), this.state.userData && this.state.userData.messageTime);
			return;
		}
		let filterListData = []
		let arr = modalDetailListData ? JSON.parse(JSON.stringify(modalDetailListData)) : [];
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].checkBox) {
				filterListData.push(arr[i].ordID)
			}
		}
		let data = {
			params: [{
				ordPrescNo: detailModalRowData.ordPrescNo,
				hospID: user.hospID ? user.hospID : '', // 登录医院id,
				ordID: filterListData
			}]
		}
		$http.post('urlADS', this, {
			code: '03050075',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.props.form.resetFields();
					this.getDepartmentInformation(res.data.herbalFormID, 'no');
					let arr = res.data.orders && res.data.orders.length > 0 ? JSON.parse(JSON.stringify(res.data.orders)) : [];
					for (var i = 0; i < arr.length; i++) {
						arr[i].key = i;
						arr[i].checkBox = false;
						arr[i].medDesc = arr[i].ordDesc;
					}
					// 成功提示
					// console.log(arr)
					this.setState({ rowData: res.data, orderSetDetailData: arr, num: arr.length - 1 }, () => {
						this.clearDetailInput();
						this.handleCancel();
					})
				}
			}
		})
	}

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

	// 引用
	handleQuote = () => {
		if (this.state.recipeListRowId) {
			return;
		}
		this.setState({ visible: true }, () => {
			this.handleQueryQuoteData();
		})
	}

	// 缩放
	handleZoom = () => {
		this.setState({
			zoomSpan: !this.state.zoomSpan
		});
	}

	// 查询就诊记录列表
	handleQueryQuoteData = () => {
		let { user, recordData, quotePageSize, quotePage, rangePicker } = this.state;
		let data = {
			params: [{
				admID: recordData.admID, // 病人id
				hospID: user.hospID ? user.hospID : '', // 登录医院id
				admDateFrom: rangePicker && rangePicker.length > 0 ? Moment(rangePicker[0]).format("YYYY-MM-DD") : '', // 开始日期
				admDateTo: rangePicker && rangePicker.length > 0 ? Moment(rangePicker[1]).format("YYYY-MM-DD") : '', // 结束日期
			}],
			pagination: [{
				pageSize: quotePageSize,
				currentPage: quotePage
			}]
		}
		$http.post('urlS', this, {
			code: '03050052',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					// 成功提示
					let data = res.result.data ? res.result.data : []
					for (var i = 0; i < data.length; i++) {
						data[i].key = i + 1;
					}
					this.setState({
						quoteData: data,
						quoteTotal: res.result.totalCount,
						detailDurQty: '', // 处方付数
						detailPerscAmt: '', // 处方金额
						detailPrescPrice: '', // 单付金额
						detailModalRowData: {}, // 引用历史处方中选中本次处方列表的行数据
						modalDetailListData: [],
						quoteRowId: '',
						quoteRowData: {},
						listData: [],
					})
				}
			}
		})
	}

	// 选择日期查询医嘱模板
	handleRangePicker = (date, dateString) => {
		this.setState({ rangePicker: dateString }, () => {
			this.handleQueryQuoteData()
		})
	}

	// 回车查询医嘱模板
	queryMedicalAdviceList = () => {
		let { inputValue, radioValue } = this.state;
		let data = {
			params: [
				{
					templetCatCode: '02', // 西药及其他01, 草药02
					templetTypeID: radioValue,
					input: inputValue
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050023",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let expandedKeys = [];
					let arr = res.result && res.result.map(item => {
						// expandedKeys.push(item.id + ''); // 自动展开	模板
						return {
							title: item.title,
							key: item.id,
							children: item.data && item.data.map(childItem => {
								return {
									...childItem,
									key: childItem.ordTempletDetailID,
								}
							})
						}
					})
					this.setState({ treeData: arr, expandedKeys })
				}
			}
		})
	}

	// 新处方
	handleResetFields = () => {
		let { defaultObj } = this.state;
		this.clearDetailInput();
		this.props.form.setFieldsValue({
			...defaultObj
		})
		this.setState({
			orderSetDetailData: [],
			rowData: {},
			num: 1,
			recipeListRowId: '',
			mainPerscAmt: '',
			mainPrescPrice: '',
			mainDurQty: '',
			detailRowData: {}, // 选中的明细回显数据
			handleStatus: false,
			addStatus: false,
		})
	}

	// 显示分页总条数
	showTotal(total) {
		return `共 ${total} 条`;
	}

	handlePaginationOnChange = (page, pageSize) => {
		this.setState({ quotePage: page, quotePageSize: pageSize }, () => {
			this.handleQueryQuoteData()
		})
	}

	handlePaginationOnShowSizeChange = (page, pageSize) => {
		this.setState({ quotePage: 1, quotePageSize: pageSize }, () => {
			this.handleQueryQuoteData()
		})
	}

	// 获取弹窗本次草药处方列表
	getQuotePrescriptionListData = () => {
		let { user, quoteRowId } = this.state;
		let data = {
			params: [{
				admID: quoteRowId, // 病人id '11694'
				hospID: user.hospID ? user.hospID : '',
			}],
			pagination: [{
				pageSize: 10000,
				currentPage: 1
			}]
		}
		$http.post('urlS', this, {
			code: '03050058',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let data = res.result.data ? res.result.data : [];
					for (var i = 0; i < data.length; i++) {
						data[i].key = i + 1;
						data[i].isShow = false;
					}
					this.setState({ listData: data });
				}
			}
		})
	}

	// 就诊记录列表行操作
	onClickQuoteRow = (record) => {
		return {
			// 单击行选中
			onClick: () => {
				if (this.state.quoteRowId === '') {
					// 保存行数据以及ID
					this.setState({
						quoteRowId: record.admID,
						quoteRowData: record,
						detailDurQty: '', // 处方付数
						detailPerscAmt: '', // 处方金额
						detailPrescPrice: '', // 单付金额
						detailModalRowData: {}, // 引用历史处方中选中本次处方列表的行数据
						modalDetailListData: [],
					}, () => {
						this.getQuotePrescriptionListData()
					})
				} else {
					if (this.state.quoteRowId !== record.admID) {
						this.setState({
							quoteRowId: record.admID,
							quoteRowData: record,
							detailDurQty: '', // 处方付数
							detailPerscAmt: '', // 处方金额
							detailPrescPrice: '', // 单付金额
							detailModalRowData: {}, // 引用历史处方中选中本次处方列表的行数据
							modalDetailListData: []
						}, () => {
							this.getQuotePrescriptionListData()
						})
					}
				}
			}
		}
	}

	onClickQuoteRowClassName = (record) => {
		return record.admID === this.state.quoteRowId ? 'clickRowStyle' : '';
	}

	// 本次草药处方列表行操作
	handleClickListItem = (record, flag) => {
		let { user, listData } = this.state;
		let data = {
			params: [{
				ordPrescNo: record.ordPrescNo, // 病人id
				hospID: user.hospID ? user.hospID : '',
			}]
		}
		$http.post('urlS', this, {
			code: '03050059',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					if (flag === 'detail') {
						let data = res.data && res.data.map((item, index) => {
							return {
								...item,
								key: index + 1,
								checkBox: true
							}
						});
						for (var i = 0; i < listData.length; i++) {
							listData[i].isShow = false
							if (JSON.stringify(listData[i]) === JSON.stringify(record)) {
								listData[i].isShow = true;
							}
						}
						this.setState({
							listData,
							modalDetailListData: data,
							detailPerscAmt: res.prescAmt,
							detailPrescPrice: res.prescPrice,
							detailDurQty: res.durQty,
							detailModalRowData: record
						})
					} else if (flag === 'main') {
						let mainData = res.data && res.data.map((item, index) => {
							return {
								...item,
								medDesc: item.ordDesc,
								key: index + 1,
								checkBox: false
							}
						})
						this.setState({ orderSetDetailData: mainData, mainPerscAmt: res.prescAmt, mainPrescPrice: res.prescPrice, mainDurQty: res.durQty })
					}
				}
			}
		})
	}

	// 全选/反选
	handleCheckAndAgainstAll = () => {
		let { modalCheckStatus, modalDetailListData } = this.state;
		let modalCheckStatusFlag = modalCheckStatus; // 记录全选点击状态
		this.setState({ modalCheckStatus: !modalCheckStatus });
		let arr = modalDetailListData ? JSON.parse(JSON.stringify(modalDetailListData)) : [];
		for (var i = 0; i < arr.length; i++) {
			if (!modalCheckStatusFlag) {
				arr[i].checkBox = true;
			} else {
				arr[i].checkBox = false;
			}

		}
		this.setState({ modalDetailListData: arr })
	}

	handleModalCheckOnChange = (item) => {
		let { modalDetailListData } = this.state;
		let arr = modalDetailListData ? JSON.parse(JSON.stringify(modalDetailListData)) : [];
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].key === item.key) {
				arr[i].checkBox = !arr[i].checkBox;
				break;
			}
		}
		this.setState({ modalDetailListData: arr });
	}

	// 获取本次草药处方列表
	getTableData = () => {
		let { user, recordData, selectData, diagActive, diagTabData } = this.state;
		// 当前诊断数据
		let currentDiagRecord = diagActive && diagTabData && Array.isArray(diagTabData) && diagTabData.length > 0 ? diagTabData[diagActive - 1] : {};
		let data = {
			params: [{
				diagID: currentDiagRecord?.id || '',
				diagCode: currentDiagRecord?.diagCode || currentDiagRecord?.ICDCode || '',
				admID: recordData.admID, // 病人id 11694
				flag: 'Y',
				hospID: user.hospID ? user.hospID : '',
			}],
			pagination: [{
				pageSize: 10000,
				currentPage: 1
			}]
		}
		$http.post('urlS', this, {
			code: '03050058',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let data = res.result.data ? res.result.data : [];
					for (var i = 0; i < data.length; i++) {
						let freqID = data[i]?.freqID || '';
						data[i].key = i + 1;
						if (freqID) { // 频次
							data[i].freqDesc = Util.returnDataCccordingToAttributes(selectData?.frequence || [], freqID)?.descripts || '';
						}
					}
					this.setState({ tableData: data, mainTotalAmt: res.result.totalAmt, mainTotalCount: res.result.totalCount });
				}
			}
		})
	}

	onClickRecipeListRow = (record) => {
		return {
			// 单击行选中
			onClick: () => {
				this.props.form.resetFields();
				this.getDepartmentInformation(record.herbalFormID, 'no');
				if (this.state.recipeListRowId === '') {
					// 保存行数据以及ID
					this.setState({ recipeListRowId: record.key, rowData: record, handleStatus: false }, () => {
						this.handleClickListItem(record, 'main');
					})
				} else {
					if (this.state.recipeListRowId !== record.key) {
						this.setState({ recipeListRowId: record.key, rowData: record, handleStatus: false }, () => {
							this.handleClickListItem(record, 'main');
						})
					}
				}
			}
		}
	}

	onClickRecipeListRowClassName = (record) => {
		return record.key === this.state.recipeListRowId ? 'clickRowStyle' : '';
	}

	handleTemplate = (ref) => {
		this.templateRef = ref;
	}

	handleShowTemplate = () => {
		this.templateRef.showModal(this.state.orderSetDetailData);
	}

	handleSetMeal = (ref) => {
		this.setMealRef = ref;
	}

	handleShowSetMeal = () => {
		this.setMealRef.showModal(this.state.orderSetDetailData);
	}

	// 获取以及勾选的数据
	getCheckBoxData = () => {
		let arr = this.state.orderSetDetailData ? JSON.parse(JSON.stringify(this.state.orderSetDetailData)) : [];
		let filterData = [];
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].checkBox) {
				filterData.push(arr[i]);
			}
		}
		return filterData;
	}

	// 左移
	handleLeft = () => {
		if (this.state.recipeListRowId) {
			return;
		}
		let data = this.state.orderSetDetailData ? JSON.parse(JSON.stringify(this.state.orderSetDetailData)) : [];
		let checkData = this.getCheckBoxData();
		if (checkData && checkData.length > 0) {
			for (var i = 0; i < checkData.length; i++) {
				if (+checkData[i].key === 0) {
					break;
				}
				var curRowData = data[Number(checkData[i].key)];
				var curRowKey = curRowData.key;
				var leftRowData = data[Number(checkData[i].key) - 1];
				var leftRowKey = leftRowData.key;
				leftRowData.key = curRowKey;
				curRowData.key = leftRowKey;

				data[Number(checkData[i].key)] = leftRowData;
				data[Number(checkData[i].key) - 1] = curRowData;
			}
			this.setState({ orderSetDetailData: data }, () => {
				this.clearDetailInput();
			});
		} else {
			message.info("请勾选需要操作的草药", this.state.userData && this.state.userData.messageTime)
		}
	}

	// 右移
	handleRight = () => {
		if (this.state.recipeListRowId) {
			return;
		}
		let data = this.state.orderSetDetailData ? JSON.parse(JSON.stringify(this.state.orderSetDetailData)) : [];
		let checkData = this.getCheckBoxData();
		if (checkData && checkData.length > 0) {
			for (var i = checkData.length - 1; i >= 0; i--) {
				if (+checkData[i].key >= data.length - 1) {
					break;
				}
				var curRowData = data[Number(checkData[i].key)];
				var curRowKey = curRowData.key;
				var rightRowData = data[Number(checkData[i].key) + 1];
				var rightRowKey = rightRowData.key;
				rightRowData.key = curRowKey;
				curRowData.key = rightRowKey;

				data[Number(checkData[i].key)] = rightRowData;
				data[Number(checkData[i].key) + 1] = curRowData;
			}
			this.setState({ orderSetDetailData: data }, () => {
				this.clearDetailInput();
			});
		} else {
			message.info("请勾选需要操作的草药", this.state.userData && this.state.userData.messageTime)
		}
	}

	// 获取dom宽度
	getDetailListWidth = (domId) => {
		var o = document.getElementById(domId);
		var w = o.clientWidth || o.clientWidth;
		let num = Number(Math.floor(w / 158));
		// console.log(num)
		return num;
	}

	// 上移
	handleUp = () => {
		let nums = this.getDetailListWidth("round-detail-list");
		let data = this.state.orderSetDetailData ? JSON.parse(JSON.stringify(this.state.orderSetDetailData)) : [];
		let checkData = this.getCheckBoxData();
		if (checkData && checkData.length > 0) {
			for (var i = 0; i < checkData.length; i++) {
				if (+checkData[i].key - nums < 0) {
					break;
				}
				var curRowData = data[Number(checkData[i].key)];
				var curRowKey = curRowData.key;
				var leftRowData = data[Number(checkData[i].key) - nums];
				var leftRowKey = leftRowData.key;
				leftRowData.key = curRowKey;
				curRowData.key = leftRowKey;

				data[Number(checkData[i].key)] = leftRowData;
				data[Number(checkData[i].key) - nums] = curRowData;
			}
			this.setState({ orderSetDetailData: data }, () => {
				this.clearDetailInput();
			});
		} else {
			message.info("请勾选需要操作的草药", this.state.userData && this.state.userData.messageTime)
		}
	}

	// 下移
	handleDown = () => {
		let nums = this.getDetailListWidth("round-detail-list");
		let data = this.state.orderSetDetailData ? JSON.parse(JSON.stringify(this.state.orderSetDetailData)) : [];
		let checkData = this.getCheckBoxData();
		if (checkData && checkData.length > 0) {
			for (var i = checkData.length - 1; i >= 0; i--) {
				if (+checkData[i].key + nums > data.length - 1) {
					break;
				}
				var curRowData = data[Number(checkData[i].key)];
				var curRowKey = curRowData.key;
				var rightRowData = data[Number(checkData[i].key) + nums];
				var rightRowKey = rightRowData.key;
				rightRowData.key = curRowKey;
				curRowData.key = rightRowKey;

				data[Number(checkData[i].key)] = rightRowData;
				data[Number(checkData[i].key) + nums] = curRowData;
			}
			this.setState({ orderSetDetailData: data }, () => {
				this.clearDetailInput();
			});
		} else {
			message.info("请勾选需要操作的草药", this.state.userData && this.state.userData.messageTime)
		}
	}

	handleOnKeydown = (e) => {
		var e = window.event || e;
		switch (e.keyCode) {
			case 38: //上
				this.handleUp()
				break;
			case 40: //下
				this.handleDown();
				break;
			case 37: //左
				this.handleLeft()
				break;
			case 39: //右
				this.handleRight();
				break;
		}
	}

	// 删除明细
	handleDeleteDetail = () => {
		if (this.state.recipeListRowId) {
			return;
		}
		let { orderSetDetailData } = this.state;
		let arr = JSON.parse(JSON.stringify(orderSetDetailData));
		let filterLocalData = JSON.parse(JSON.stringify(orderSetDetailData));
		let statusArr = [];
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].checkBox) {
				statusArr.push(arr[i])
				filterLocalData = filterLocalData.filter(function (item) { return arr[i].key != item.key });
				continue;
			}
		}
		if (statusArr && statusArr.length > 0) {
			if (filterLocalData && filterLocalData.length > 0) {
				for (var i = 0; i < filterLocalData.length; i++) {
					if (JSON.stringify(filterLocalData[i]) === JSON.stringify(this.state.detailRowData)) {
						break;
					} else {
						this.clearDetailInput();
					}
				}
				this.setState({ orderSetDetailData: filterLocalData }, () => {
					let forKey = this.state.orderSetDetailData;
					let addStatus = false;
					for (var i = 0; i < forKey.length; i++) {
						forKey[i].key = i;
						if (forKey[i].treatyFlag === 'Y') {
							addStatus = true;
							break;
						} else {
							addStatus = false
						}
					}
					this.setState({ orderSetDetailData: forKey, addStatus })
				})
			} else {
				this.setState({ orderSetDetailData: [], addStatus: false }, () => {
					this.clearDetailInput();
				})
			}
		} else {
			message.info(this.setMessage("CMOrderSavePSAPODTBO", "descripts"), this.state.userData && this.state.userData.messageTime)
		}
	}

	// 个人/科室模板切换
	radioOnChange = e => {
		this.setState({
			radioValue: e.target.value,
		}, () => {
			this.queryMedicalAdviceList()
		});
	}

	// 获取下拉框数据
	getRadioData = () => {
		let data = {
			params: [
				{
					orderTemplTypeFlag: '1',
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050017",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({ radioData: res.orderTemplType, radioValue: res.defaultTemplTypeID }, () => {
						this.queryMedicalAdviceList(); // 医嘱模板
					})
				}
			}
		})
	}

	// 名称/别名输入框value
	getInputValue = e => {
		this.setState({
			inputValue: e.target.value,
		});
	}

	// 展开/收起节点时触发
	onExpand = expandedKeys => {
		this.setState({
			expandedKeys,
			autoExpandParent: false,
		});
	};

	// 点击复选框触发
	onCheck = (checkedKeys, e) => {
		this.setState({ checkedKeys: checkedKeys, checkedArr: e.checkedNodes });
	};

	renderTreeNodes = (data, idIndex, descIndex) => {
		return data.map(item => {
			if (item.children) {
				return (
					<TreeNode title={item[descIndex || 'title']} key={item[idIndex || 'key']} dataRef={item}>
						{this.renderTreeNodes(item.children, idIndex, descIndex)}
					</TreeNode>
				);
			}
			return <TreeNode {...item} title={item[descIndex || 'title']} key={item[idIndex || 'key']} dataRef={item} />;
		})
	};

	dblclickTreeNodes = (status, record) => {
		// console.log(record)
		let arr = [];
		arr.push(record);
		this.setState({ checkedArr: arr }, () => {
			this.handleBatchAdd()
		})

	}

	//跳转到西药及其他
	goDoctorAdviceStepPage = (num) => {
		var { hashROuter } = this.props;
		hashROuter && hashROuter(num);
	}

	// 批量添加
	handleBatchAdd = () => {
		let { herbalFormID } = this.state;
		// let herbalFormID = this.props.form.getFieldValue('herbalFormID');
		if (!herbalFormID) {
			message.error(this.setMessage("CMOrderSavePSTDFTUF", "descripts"), this.state.userData && this.state.userData.messageTime);
			return;
		}
		if (this.state.recipeListRowId) {// 本次草药处方列表如果选中行择不能进行添加
			return;
		}
		let { checkedArr } = this.state;
		if (!(checkedArr && checkedArr.length > 0)) {
			message.info(this.setMessage("CMOrderSavePSTDYWTA", "descripts"), this.state.userData && this.state.userData.messageTime);
			return;
		}
		let arr = checkedArr && checkedArr.length > 0 ? checkedArr.map(item => {
			return {
				ordTempletDetailID: item.props.ordTempletDetailID ? item.props.ordTempletDetailID : ''
			}
		}) : [];
		this.getOrders(arr);
	}

	// 修改明细
	compileOrderDetailDom = item => {
		if (this.state.recipeListRowId) {
			return;
		}
		let { orderSetDetailData } = this.state;
		for (var i = 0; i < orderSetDetailData.length; i++) {
			orderSetDetailData[i].isboxShadow = false;
			if (orderSetDetailData[i].key === item.key) {
				orderSetDetailData[i].isboxShadow = true;
			}
		}
		this.setState({
			orderSetDetailData,
			detailRowData: item,
			numSelectData: item.qtyUnitList, // 单位下拉框
			medID: item.medID,
			medDesc: item.medDesc,
			comPrincipleID: item.comPrincipleID, // 用药类型
			dose: item.dose,
			decoctMethodID: item.decoctMethodID, // 备注
			checkBox: item.checkBox,
			doseUnitID: item.doseUnitID,  // 剂量单位
			decoctMethod: item?.decoctMethod || undefined
		}, () => {
			this.getModalListData()
		})
	}

	// 隐藏左侧card
	handleHideLeftCard = () => {
		this.setState({ visibleCrad: false })
	}

	// 显示左侧card
	handleShowLeftCard = () => {
		this.setState({ visibleCrad: true })
	}

	// 使用剂型
	// handleHerbalFormID = e => {
	// 	// Modal.confirm({
	// 	// 	title: '',
	// 	// 	content: '切换剂型应先保存，不然数据将重置，确认切换吗???',
	// 	// 	okText: '确认',
	// 	// 	cancelText: '取消',
	// 	// 	onOk() {
	// 	// 		if (e === '17') {
	// 	// 			this.setState({ handleStatus: true })
	// 	// 		} else {
	// 	// 			this.setState({ handleStatus: false, addStatus: false })
	// 	// 		}
	// 	// 		this.setState({ orderSetDetailData: [] });
	// 	// 		this.clearDetailInput();
	// 	// 		this.getDepartmentInformation(e);
	// 	// 	},
	// 	// 	onCancel() {

	// 	// 	},
	// 	// });
	// 	if (e === '17') {
	// 		this.setState({ handleStatus: true })
	// 	} else {
	// 		this.setState({ handleStatus: false, addStatus: false })
	// 	}
	// 	this.setState({ orderSetDetailData: [] });
	// 	this.clearDetailInput();
	// 	this.getDepartmentInformation(e, 'yes');
	// }

	handleHerbalFormChange = (e) => {
		let _this = this;
		Modal.confirm({
			title: '',
			content: '切换剂型应先保存，不然数据将重置，确认切换吗???',
			okText: '确认',
			cancelText: '取消',
			onOk() {
				if (e === '17') {
					_this.setState({ handleStatus: true, orderSetDetailData: [], herbalFormID: e }, () => {
						_this.clearDetailInput();
						_this.getDepartmentInformation(e, 'yes');
					})
				} else {
					_this.setState({ handleStatus: false, addStatus: false, orderSetDetailData: [], herbalFormID: e }, () => {
						_this.clearDetailInput();
						_this.getDepartmentInformation(e, 'yes');
					})
				}
			},
			onCancel() {
				console.log("取消了")
			},
		});
	}

	// 撤销
	handleCancelButton = () => {
		let { user, rowData } = this.state;
		if (!(rowData && rowData.ordPrescNo)) {
			return;
		}
		let data = {
			params: [
				{
					ordPrescNo: rowData.ordPrescNo, // 执行科室id
					hospID: user.hospID, // 登录医院id
					userID: user.userID, // 登录用户id
					locID: user.locID, // 登录科室id
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050084",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success(res.errorMessage, this.state.userData && this.state.userData.messageTime);
					this.getTableData();
					this.handleResetFields();
				}
			}
		})
	}

	// 药品数量回车操作
	doseQtyOnPressEnter = () => {
		setTimeout(() => {
			this.myRef5.current.buttonNode.focus();
		}, 100)
	}

	// 键盘操作名称模态框数据
	handlePublicModalTableOnKeydown = (e) => {
		var e = window.event || e;
		let scroll_height = 26;
		let id = '';
		let oneArr = this.state.modalData && this.state.modalData.length > 0 ? this.state.modalData : [];
		switch (e.keyCode) {
			case 13:
				if (this.state.modalRowId) {
					let obj = {}
					for (var i = 0; i < oneArr.length; i++) {
						if (oneArr[i].key === this.state.modalRowId) {
							obj = i > 0 ? oneArr[i] : oneArr[0];
							break;
						}
					}
					this.confirmSelection(obj);
				} else {
					message.info(this.setMessage("CMOrderSavePSAPODTBO", "descripts"), this.state.userData && this.state.userData.messageTime)
				}
				break;
			case 38: //上
				if (this.state.modalRowId) {
					for (var i = 0; i < oneArr.length; i++) {
						if (oneArr[i].key === this.state.modalRowId) {
							id = i > 0 ? oneArr[i - 1].key : oneArr[0].key;
							break;
						}
					}
					this.setState({ modalRowId: id })
					setTimeout(() => {
						var gundong = document.getElementById("gundong");
						gundong.scrollTop = gundong.scrollTop - scroll_height;
					}, 100)
				} else {
					this.setState({ modalRowId: oneArr[0].key })
				}
				break;
			case 40: //下
				if (this.state.modalRowId) {
					for (let i = 0; i < oneArr.length; i++) {
						if (oneArr[i].key === this.state.modalRowId) {
							id = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1].key : oneArr[i + 1].key;
							break;
						}
					}
					this.setState({ modalRowId: id })
					setTimeout(() => {
						var gundong = document.getElementById("gundong");
						gundong.scrollTop = gundong.scrollTop + scroll_height;
					}, 100)
				} else {
					this.setState({ modalRowId: oneArr[0].key })
				}
				break;
		}
	};

	// 根据煎药方式获取科室
	getTheDepartmentAccordingToTheDecoctingMethod = (e) => {
		let { user, herbalFormID } = this.state;
		let data = {
			params: [
				{
					hospID: user.hospID, // 登录医院id
					cookTypeID: e, // 煎药方式
					herbalFormID
				}
			]
		}
		$http.post('urlS', this, {
			code: "02030115",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({ minQty: res.result[0].minQty ? res.result[0].minQty : undefined, maxQty: res.result[0].maxQty ? res.result[0].maxQty : undefined })
					if (res.result[0].defaultFlag === "Y") {
						this.props.form.setFieldsValue({
							recLocID: res.result.length && res.result[0].id ? res.result[0].id : undefined, // 执行科室
						})
					}
				}
			}
		})
	}

	handleChangeBtn(name, e) {
		this.setState({
			[name]: e.target.value
		}, () => {
			if (this.state.defaultBtn == 2) {
				this.goDoctorAdviceStepPage(2)
			} else if (this.state.defaultBtn == 3) {
				this.goDoctorAdviceStepPage(3)
			}
		})
	};

	// 获取医嘱套餐相关数据
	loadLocPersonMsg = async () => {
		try {
			const { userData } = this.state;
			const data = {
				params: [{
					hospID: userData?.hospID || '',
					userID: userData?.userID || '',
					locID: userData?.locID || '',
				}]
			}
			let res = await React.$asyncPost(this, '03050272', data);
			var resData = res.result
			var authRangeID = ''
			if (!Util.isEmpty(resData)) {
				for (var i = 0; i < resData.length; i++) {
					if (resData[i].default == 'Y') {
						authRangeID = resData[i].id
					}
				}
			}
			this.setState({
				packageData: resData,
				authRangeID: !Util.isEmpty(authRangeID) ? authRangeID : (!Util.isEmpty(resData) ? resData[0].id : '')
			}, () => {
				this.getMedicalAdvicePackage();
			})
		} catch (error) {
			console.log(error);
		}
	};

	// 模板套餐切换
	handleActiveKeyChange = e => {
		this.setState({
			activeKey: e
		});
	};

	handleAuthRangeChange = e => {
		this.setState({
			authRangeID: e.target.value
		}, () => {
			this.getMedicalAdvicePackage()
		});
	};

	// 获取草药医嘱套数据
	getMedicalAdvicePackage = async () => {
		try {
			const { userData, authRangeID } = this.state;
			const data = {
				params: [{
					userID: userData?.userID,
					locID: userData?.locID,
					hospID: userData?.hospID,
					groupID: userData?.groupID,
					authRangeID,
					activeFlag: 'Y',
				}]
			};
			let res = await React.$asyncPost(this, '03050289', data);
			this.setState({
				packageMsg: res.data.otherList || [],
			});
		} catch (error) {
			console.log(error);
		};
	};

	// 展开/收起节点时触发
	handlePackageExpand = expandedKeys => {
		this.setState({
			packageExpandedKeys: expandedKeys,
			packageAutoExpandParent: false,
		});
	};

	// 选择医嘱套餐
	handlePackageDoubleClick = async (status, record) => {
		let { ordSetID, dataRef } = record?.props;
		let currentOrdSetID = ordSetID || dataRef?.ordSetID || '';
		let orders = [{ ordSetID: currentOrdSetID }];
		this.getOrders(orders, currentOrdSetID);
	}

	// 获取草药明细
	getOrders = async (orders, ordSetID = '') => {
		try {
			const { user, recordData, orderSetDetailData, herbalFormID, selectData } = this.state;
			let recLocID = this.props.form.getFieldValue('recLocID');
			const data = {
				params: [{
					recLocID, // 执行科室id
					hospID: user.hospID, // 登录医院id
					groupID: user.groupID, //	登录角色id
					userID: user.userID, // 登录用户id
					locID: user.locID, // 登录科室id
					admID: recordData.admID, // 就诊id
					orders
				}]
			};
			let res = await React.$asyncPost(this, '03050076', data);
			let adviceDrData = res?.data || [];
			let confirmList = [];
			if (selectData?.callInterfaceConfirmFlag === 'Y') { // 是否取接口确认信息
				confirmList = res?.confirmList || [];
			} else { // 默认取现有并且重复的数据
				confirmList = this.getRepeatList(adviceDrData);
			}
			let selectedRows = [];
			let selectedRowKeys = [];
			for (let i = 0; i < confirmList.length; i++) {
				confirmList[i].key = confirmList[i].medID;
				if (selectData?.medRepeatFlag !== 'Y') {
					confirmList[i].errorMessage = '已存在相同医嘱';
				} else {
					selectedRowKeys.push(confirmList[i]?.medID || '');
					selectedRows.push(confirmList[i]);
				}
			}
			let errorList = (res?.errorList || []);
			errorList = errorList && errorList.map(item => {
				return {
					...item,
					disabledFlag: 'Y', // 错误数据不能选择
				}
			});
			let tipTableData = [...confirmList, ...errorList];
			let str = errorList && errorList.length > 0 ? errorList[0].ordDesc + errorList[0].errorMessage : '';
			if (errorList && errorList.length > 1) {
				for (var i = 1; i < errorList.length; i++) {
					str += ", " + errorList[i].ordDesc + errorList[i].errorMessage
				}
			}
			console.log('tipTableData', tipTableData)
			if (tipTableData && tipTableData.length > 0) {
				this.ordConfirmRef && this.ordConfirmRef.modifyVisible(true, { tableData: tipTableData, selectedRowKeys, selectedRows });
				this.setState({ // 确认医嘱弹框
					tipTableData,
					adviceDrData,
					ordSetID,
					messageError: str,
				}, () => {
					setTimeout(() => {
						selectData?.medRepeatFlag !== 'Y' && this.handleOrdConfirmSave({ selectedRowKeys: [], selectedRows: [] }); // 不允许开重复草药的情况直接添加过滤掉的数据
					}, 100)
				});
			} else {
				let listData = orderSetDetailData && orderSetDetailData.length > 0 ? JSON.parse(JSON.stringify(orderSetDetailData)) : []; // 数据源
				let newArr = res?.data || [];
				let num = listData.length + newArr.length;
				let concatArr = this.setOrderSetDetailData(newArr, ordSetID)
				if (num > concatArr.length) {
					message.info(this.setMessage("CMOrderSaveTDWAI", "descripts"), this.state.userData && this.state.userData.messageTime);
				}
				this.setState({
					orderSetDetailData: concatArr,
					num: concatArr && concatArr.length - 1,
					ordSetID: '', // 医嘱套ID
					checkedKeys: [],
					checkedArr: [],
					messageError: str,
					herbalFormID: res.ordSetData && res.ordSetData.herbalFormID ? res.ordSetData.herbalFormID : (herbalFormID ? herbalFormID : undefined)
				}, () => {
					let formData = this.props.form.getFieldsValue();
					this.props.form.setFieldsValue({
						durQty: res.ordSetData && res.ordSetData.durQty ? res.ordSetData.durQty : (formData.durQty ? formData.durQty : undefined), // 用药副数
						usageExplainID: res.ordSetData && res.ordSetData.usageExplainID ? res.ordSetData.usageExplainID : (formData.usageExplainID ? formData.usageExplainID : undefined), // 服用要求
						freqID: res.ordSetData && res.ordSetData.freqID ? res.ordSetData.freqID : (formData.freqID ? formData.freqID : undefined), // 使用频次
						usageID: res.ordSetData && res.ordSetData.usageID ? res.ordSetData.usageID : (formData.usageID ? formData.usageID : undefined), // 用药方法
						doseQty: res.ordSetData && res.ordSetData.doseQty ? res.ordSetData.doseQty : (formData.doseQty ? formData.doseQty : undefined), // 每次用量
						recLocID: res.ordSetData && res.ordSetData.recLocID ? res.ordSetData.recLocID : (formData.recLocID ? formData.recLocID : undefined), // 执行科室
					})
				});
			}
		} catch (error) {
			console.log(error);
		};
	}

	// 获取重复数据
	getRepeatList = (newData) => {
		const { orderSetDetailData } = this.state;
		let medIDArr = orderSetDetailData && orderSetDetailData.map(item => item.medID);
		let repeatList = [];
		for (let i = 0; i < newData.length; i++) {
			if (medIDArr && medIDArr.indexOf(newData[i].medID) > -1) {
				repeatList.push(newData[i]);
			}
		}
		return repeatList;
	}

	// 确认开立
	handleOrdConfirmSave = ({ selectedRowKeys }) => {
		const { adviceDrData, tipTableData, ordSetID } = this.state;
		let errorMedIDArr = tipTableData.map(item => item.medID);
		let insertData = [];
		for (let i = 0; i < adviceDrData.length; i++) {
			if ((errorMedIDArr && errorMedIDArr.indexOf(adviceDrData[i].medID) < 0) || (selectedRowKeys && selectedRowKeys.indexOf(adviceDrData[i].medID) > -1)) {
				insertData.push(adviceDrData[i]);
			}
		}
		let concatArr = this.setOrderSetDetailData(insertData, ordSetID);
		this.setState({
			orderSetDetailData: concatArr,
			num: concatArr && concatArr.length - 1,
		});
	};

	setOrderSetDetailData = (data, ordSetID) => {
		const { orderSetDetailData } = this.state;
		let timeStamp = new Date()?.getTime();
		let listData = orderSetDetailData && orderSetDetailData.length > 0 ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
		let newArr = data && data.map((item, index) => {
			return {
				medID: item.medID ? item.medID : '',
				dose: item.ordDose,
				comPrincipleID: item.comPrincipleID, // 用药类型
				medDesc: item.ordDesc,
				decoctMethodID: '', // 备注
				decoctMethodDesc: '', // 备注描述
				decoctMethod: undefined, // 备注
				checkBox: false,
				key: listData && listData.length > 0 ? (listData.length + index) : index,
				doseUnitID: item.ordDoseUnitID, // 剂量单位
				ordDoseUnitDesc: item.ordDoseUnitDesc, // 剂量单位描述
				qtyUnitList: item.qtyUnitList, // 单位下拉框数据
				ordSetID: ordSetID ? (ordSetID + ',' + timeStamp) : undefined, // 医嘱套ID
			}
		});
		let hash = {};
		let concatArr = listData.concat(newArr).reduce(function (item, next) {
			hash[next.medID] ? '' : hash[next.medID] = true && item.push(next);
			return item
		}, []);
		return concatArr;
	};

	// 诊断切换
	handleDiagTabChange = (key) => {
		this.setState({ diagActive: key }, () => {
			this.getTableData();
		});
	};

	// 合理用药
	handleRationalUse = async () => {
		try {
			const { recordData } = this.state;
			let data = {
				params: [{
					admID: recordData?.admID || ''
				}]
			}
			let res = await React.$asyncPost(this, '03050292', data);
			let result = res?.result || {};
			if (Object.prototype.toString.call(result) === '[object Object]' && JSON.stringify(result) !== '{}') {
				if (typeof (CefSharp) != 'undefined') { // 定制浏览器
					let dllParams = JSON.stringify(result);
					CefSharp.BindObjectAsync('xysCefToJavaScripts');
					return new Promise((resolve, reject) => {
						if (xysCefToJavaScripts && 'pass4Invoke' in xysCefToJavaScripts && xysCefToJavaScripts.pass4Invoke) {
							xysCefToJavaScripts.pass4Invoke(dllParams).then((returnVale) => {
								let res = JSON.parse(returnVale);
								if (res.errorCode != '0') {
									message.error(res.errorMessage)
								}
							})
						} else {
							xysCefToJavaScripts.driveLocalHardware(dllParams).then((returnVale) => {
								let res = JSON.parse(returnVale);
								if (res.errorCode != '0') {
									message.error(res.errorMessage)
								}
							})
						}
					})
				}
			}
		} catch (error) {
			console.log(error);
		}
	};

	render() {
		const { tableData, selectData, departmentInformation, comPrincipleID, dose, orderSetDetailData, visible, listData, zoomSpan, quotePage, quoteTotal, minQty, maxQty, activeKey, authRangeID, packageData, packageMsg,
			decoctMethodID, medDesc, rowData, doseUnitID, quoteData, top, left, modalData, settlementType, modalDetailListData, recipeListRowId, packageExpandedKeys, packageAutoExpandParent,
			numSelectData, radioValue, treeData, radioData, detailRowData, visibleCrad, handleStatus, addStatus, messageError, totalWidth, columns, user, titleData, herbalFormID,
			inoperable, decoctMethod, diagTabData, diagActive, isExistRecord
		} = this.state;
		const { getFieldDecorator } = this.props.form;
		let param = {
			width: '700px',
			height: 300,
			top: top,
			left: left,
			columns: this.modalColumns,
			data: modalData,
			isOnRow: true,
			TableClassName: 'tab-placeholder',
			rowClassName: true,
		}

		// 剂型
		let herbalFormOption = selectData.herbalForm && selectData.herbalForm.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 频次
		let frequenceOption = selectData.frequence && selectData.frequence.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 用药方法
		let usageOption = selectData.usage && selectData.usage.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 煎药方式
		let cookTypeOption = selectData.cookType && selectData.cookType.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 服用要求
		let usageExplainOption = selectData.usageExplain && selectData.usageExplain.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 结算类型
		// let settlementTypeOption = settlementType && settlementType.map((item, index) => {
		// 	return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		// })

		// 执行科室
		let departmentOption = departmentInformation && departmentInformation.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 用药类型
		let comPrincipleOption = selectData.comPrinciple && selectData.comPrinciple.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		let numOption = numSelectData && numSelectData.map((item, index) => {
			return (<Option key={index} value={item.unitID} title={item.unitDesc} seatchprop={item.unitDesc}>{item.unitDesc}</Option>)
		})

		// 备注
		let decoctMethodOption = selectData.decoctMethod && selectData.decoctMethod.map((item, index) => {
			return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
		})

		// 医嘱模板个人、科室数据
		let radioOption = radioData && radioData.map((item, index) => {
			return (<Radio value={item.id} key={index}>{user.language === 'EN' ? (item && item.enDescripts ? item.enDescripts : item.descripts) : item.descripts}</Radio>)
		})

		//套餐
		let packageDataOption = [];
		packageData && packageData.map((item, index) => {
			packageDataOption.push(
				<Radio value={item.id} key={item.id}>{item.descripts}</Radio>
			)
		})

		let orderSetDetailDom = orderSetDetailData && orderSetDetailData.map((item, index) => {
			return (
				<li key={index} onClick={() => this.compileOrderDetailDom(item)} style={{ cursor: 'pointer', boxShadow: item.isboxShadow ? '4px 4px 8px' : '0 0 0' }}>
					<h3 className="ellipsis" style={{
						background: item.comPrincipleID === '1' ? '#ffa23e' : (item.comPrincipleID === '2' ? '#39d1d1' : (item.comPrincipleID === '3' ? '#fa5ab2' : (item.comPrincipleID === '4' ? '#aa71f9' : '#d7d7d7'))),
						textAlign: 'center',
						position: 'relative',
						color: item.comPrincipleID ? '#fff' : '#000',
						height: '24px',
						lineHeight: '24px',
						padding: '0 20px',
					}}>
						<Checkbox style={{ position: 'absolute', left: '4px' }} checked={item.checkBox} onClick={e => e.stopPropagation()} onChange={(e) => this.handleCheckOnChange(item, e)} disabled={recipeListRowId ? true : false} />
						{item.medDesc}
					</h3>
					<div>
						<div className="ellipsis" style={{ display: 'inline-block', height: '18px', lineHeight: '18px', marginBottom: '8px' }}>{this.setMessage("CMOrderSavenumber_of_drugs", "descripts")}: {(item.dose ? item.dose : '') + (item.ordDoseUnitDesc ? item.ordDoseUnitDesc : '')}</div>
						<div className="ellipsis">{this.setMessage("CMOrderSaveremark", "descripts")}: {item.decoctMethod ? item.decoctMethod : '无'}</div>
					</div>
				</li>
			)
		})

		let modalDetailListDom = modalDetailListData && modalDetailListData.map((item, index) => {
			return (
				<li key={index}>
					<h3 className="ellipsis" style={{
						background: item.comPrincipleID === '1' ? '#ffa23e' : (item.comPrincipleID === '2' ? '#39d1d1' : (item.comPrincipleID === '3' ? '#fa5ab2' : (item.comPrincipleID === '4' ? '#aa71f9' : '#d7d7d7'))),
						textAlign: 'center',
						position: 'relative',
						color: item.comPrincipleID ? '#fff' : '#000',
						height: '24px',
						lineHeight: '24px',
						padding: '0 20px',
					}}>
						<Checkbox style={{ position: 'absolute', left: '4px' }} checked={item.checkBox} onChange={() => this.handleModalCheckOnChange(item)} />
						{item.ordDesc}
					</h3>
					<div>
						<div className="ellipsis" style={{ display: 'inline-block', height: '18px', lineHeight: '18px', marginBottom: '8px' }}>{this.setMessage("CMOrderSavenumber_of_drugs", "descripts")}: {item.dose ? item.dose : '' + item.ordDoseUnitDesc ? item.ordDoseUnitDesc : ''}</div>
						<div className="ellipsis">{this.setMessage("CMOrderSaveremark", "descripts")}: {item.decoctMethod ? item.decoctMethod : '无'}</div>
					</div>
				</li>
			)
		})
		return (
			<div className="cm-order-save" style={{ background: '#fff' }}>
				<div style={{ height: '6px', background: 'rgba(240, 242, 245, 1)' }}></div>
				{!visibleCrad ? (
					<Card
						className="show-card"
						style={{
							width: '20px', background: '#f5f4f4',
							float: "left",
							height: store.getState().tableHeight.y + 157 + 'px'
							, cursor: 'pointer', paddingTop: 200, textAlign: 'center'
						}} hoverable={true} onClick={this.handleShowLeftCard}>
						<div className='change-card-icon-show'><Tooltip title={this.setMessage("CMOrderSavemedical_template", "descripts")}>
							<Icon type='double-right' style={{ fontSize: '18px' }} /></Tooltip></div>{this.setMessage("CMOrderSavePODOT", "descripts")}
					</Card>
				) : (
					<Card
						size="small"
						title={<span><img src={doctorOrder} style={{ marginRight: 5 }} />{activeKey === '2' ? this.setMessage("CMOrderSavemedical_template", "descripts") : '医嘱套'}</span>}
						hoverable={true}
						style={{ width: '18%', float: 'left' }}
						headStyle={{ background: '#fff', color: '#1999db' }}
						className="medical-advice-list"
						extra={activeKey === '2' && (
							<span onClick={this.handleBatchAdd} style={{ color: '#1999db', cursor: recipeListRowId ? 'not-allowed' : 'pointer' }}>
								<Icon type="plus" />
								{this.setMessage("CMOrderSaveadd_in_batches", "descripts")}
							</span>
						)}
					>
						<div className="cm-order-save-tabs">
							<Tabs
								activeKey={activeKey}
								onChange={this.handleActiveKeyChange}
								tabBarExtraContent={(
									<Tooltip title={this.setMessage("CMOrderSavehide_doctor_order_template", "descripts")}>
										<Icon type="double-left" className="common-card-hide-icon common-card-show-icon" style={{ fontSize: '15px' }} onClick={this.handleHideLeftCard} />
									</Tooltip>
								)}
							>
								<TabPane tab="医嘱套" key="1">
									<div style={{ width: '100%', padding: '0 8px' }}>
										<div style={{ background: '#F6FCF9', height: '34px', lineHeight: '34px', paddingLeft: '8px', position: 'relative' }}>
											<Radio.Group value={authRangeID} onChange={this.handleAuthRangeChange}>
												{packageDataOption}
											</Radio.Group>
										</div>
										<div style={{ height: store.getState().tableHeight.y + 36 + 'px', overflow: 'auto' }}>
											<Tree
												// 是否自动展开父节点
												expandedKeys={packageExpandedKeys}
												autoExpandParent={packageAutoExpandParent}
												onExpand={this.handlePackageExpand}
												onDoubleClick={this.handlePackageDoubleClick}
											>
												{this.renderTreeNodes(packageMsg, 'ordSetID', 'ordSetDesc')}
											</Tree>
										</div>
									</div>
								</TabPane>
								<TabPane tab="医嘱模板" key="2">
									<div style={{ width: '100%', padding: '0 8px' }}>
										<Input
											style={{ width: '100%', margin: '6px 0' }}
											placeholder={this.setMessage("CMOrderSaveTNOPNOA", "descripts")}
											value={this.state.inputValue}
											onChange={this.getInputValue}
											onPressEnter={this.queryMedicalAdviceList}
											prefix={<Icon type="search" style={{ color: 'rgba(0,0,0,.25)' }} />}
										/>
									</div>
									<div style={{ background: '#F6FCF9', height: '34px', lineHeight: '34px', paddingLeft: '8px', position: 'relative' }}>
										<Radio.Group onChange={this.radioOnChange} value={radioValue}>
											{radioOption}
										</Radio.Group>
									</div>
									<div style={{ height: store.getState().tableHeight.y + 'px', overflow: 'auto' }}>
										<Tree
											// 节点前添加 Checkbox 复选框
											checkable
											// 展开/收起节点时触发
											onExpand={this.onExpand}
											//（受控）展开指定的树节点
											expandedKeys={this.state.expandedKeys}
											// 是否自动展开父节点
											autoExpandParent={this.state.autoExpandParent}
											// 点击复选框触发
											onCheck={this.onCheck}
											checkedKeys={this.state.checkedKeys}
											onDoubleClick={this.dblclickTreeNodes}
										>
											{this.renderTreeNodes(treeData)}
										</Tree>
									</div>
								</TabPane>
							</Tabs>
						</div>
					</Card>
				)}
				<div tabIndex={1}
					onKeyDown={this.handleOnKeydown}
					style={{ outline: 'none', borderTop: '1px solid #e8e8e8', paddingLeft: '6px', position: 'relative', width: !visibleCrad ? "calc(100% - 20px)" : '82%', float: 'right' }}
				>
					<div style={{ position: 'absolute', left: '0', top: '0', width: '6px', background: 'rgba(240, 242, 245, 1)', height: '100%' }}></div>
					<div>
						<div style={{ height: '36px', lineHeight: '36px', padding: '0 12px', borderBottom: '1px solid #e8e8e8' }}>
							<span className="ellipsis" title={this.setMessage("CMOrderSavetotal_prescriptions", "descripts")}>{this.setMessage("CMOrderSavetotal_prescriptions", "descripts")}</span>：
							<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900' }}>{this.state.mainTotalCount ? this.state.mainTotalCount : 0}</span>，{this.setMessage("CMOrderSavetotal_prescription_amount", "descripts")}：
							<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900', marginRight: '24px' }}>{this.state.mainTotalAmt ? this.state.mainTotalAmt : 0}</span>
							<span className="ellipsis" title={this.setMessage("CMOrderSaveAOCPS", "descripts")}>{this.setMessage("CMOrderSaveAOCPS", "descripts")}</span>：
							<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900', marginRight: '24px' }}>{this.state.mainPrescPrice ? this.state.mainPrescPrice : 0}</span>
							<span className="ellipsis" title={this.setMessage("CMOrderSavetotal_current_prescriptions", "descripts")}>{this.setMessage("CMOrderSavetotal_current_prescriptions", "descripts")}</span>：
							<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900' }}>{this.state.mainDurQty ? this.state.mainDurQty : 0}</span>，{this.setMessage("CMOrderSavetotal_amount", "descripts")}：
							<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900' }}>{this.state.mainPerscAmt ? this.state.mainPerscAmt : 0}</span>
							{titleData && titleData.admTypeCode === 'W' ? null : <span
								className={recipeListRowId ? 'span-card disp-card' : 'span-card pointer-span'}
							>
								{this.setMessage("CMOrderSavecard_consumption", "descripts")}
							</span>}
							<div style={{ float: 'right' }}>
								{/* <span className="span" onClick={() => this.goDoctorAdviceStepPage(2)}>
									{this.setMessage("CMOrderSaveWMAO", "descripts")}
								</span>
								<span className="span" style={{ margin: '0 12px' }} onClick={() => this.goDoctorAdviceStepPage(3)}>
									{this.setMessage("CMOrderSaverequisition", "descripts")}
								</span> */}
								<Radio.Group value={this.state.defaultBtn} buttonStyle="solid" onChange={this.handleChangeBtn.bind(this, 'defaultBtn')}>
									<Radio.Button value={2}>{this.setMessage("CMOrderSaveWMAO", "descripts")}</Radio.Button>
									<Radio.Button value={1}>草药录入</Radio.Button>
									<Radio.Button value={3}>{this.setMessage("CMOrderSaverequisition", "descripts")}</Radio.Button>
								</Radio.Group>
							</div>
						</div>
						{diagTabData && diagTabData.length > 0 && isExistRecord === 'Y' ? (
							<div className="cm-order-save-tabs">
								<Tabs activeKey={diagActive} onChange={this.handleDiagTabChange}>
									{diagTabData && diagTabData.map((item, index) => {
										return (
											<TabPane tab={item?.diagDesc || ''} key={String(index + 1)}></TabPane>
										)
									})}
								</Tabs>
								<div style={{ height: '36px', lineHeight: '36px', borderBottom: '1px solid #ccc' }}>
									<ul className="handle-btn">
										{recipeListRowId ? (
											<li className='color333' onClick={this.handleResetFields}>
												<Icon className='doctor-add-splice' />
												<span>{this.setMessage("CMOrderSavenew_prescription", "descripts")}</span>
											</li>
										) : (
											<Popconfirm title="当前页面有处方未保存，是否需要保存处方？" onConfirm={this.handleSaveDetailList} onCancel={this.handleResetFields} >
												<li className='color333'>
													<Icon className='doctor-add-splice' />
													<span>{this.setMessage("CMOrderSavenew_prescription", "descripts")}</span>
												</li>
											</Popconfirm>
										)}
										<Divider type="vertical" />
										<li onClick={this.handleCheckAll} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className="doctor-hourglass-splice" />
											<span>{this.setMessage("CMOrderSaveselect_all", "descripts")}</span>
										</li>
										<Divider type="vertical" />
										<li onClick={this.handleDeleteDetail} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className='doctor-delete-splice' />
											<span>{this.setMessage("CMOrderSavedelete", "descripts")}</span>
										</li>
										{titleData && titleData.admTypeCode === 'W' ? null : <Divider type="vertical" />}
										{titleData && titleData.admTypeCode === 'W' ? null : <li onClick={this.handleUp} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className='doctor-up-splice' />
											<span>{this.setMessage("CMOrderSavemove_up", "descripts")}</span>
										</li>}
										{titleData && titleData.admTypeCode === 'W' ? null : <Divider type="vertical" />}
										{titleData && titleData.admTypeCode === 'W' ? null : <li onClick={this.handleDown} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className='doctor-down-splice' />
											<span>{this.setMessage("CMOrderSavemove_down", "descripts")}</span>
										</li>}
										{titleData && titleData.admTypeCode === 'W' ? null : <Divider type="vertical" />}
										{titleData && titleData.admTypeCode === 'W' ? null : <li onClick={this.handleLeft} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className="doctor-left-splice" />
											<span>{this.setMessage("CMOrderSaveshift_left", "descripts")}</span>
										</li>}
										{titleData && titleData.admTypeCode === 'W' ? null : <Divider type="vertical" />}
										{titleData && titleData.admTypeCode === 'W' ? null : <li onClick={this.handleRight} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className="doctor-right-splice" />
											<span>{this.setMessage("CMOrderSaveshift_right", "descripts")}</span>
										</li>}
										<Divider type="vertical" />
										<li onClick={this.handleQuote} className={recipeListRowId ? 'color999' : 'color333'}>
											<Icon className='doctor-copy-splice' />
											<span>{this.setMessage("CMOrderSavequote", "descripts")}</span>
										</li>
										<Divider type="vertical" />
										<li onClick={this.handleShowTemplate} className='color333'>
											<Icon className='doctor-plus-square-splice' />
											<span>{this.setMessage("CMOrderSaveadd_template", "descripts")}</span>
										</li>
										<Divider type="vertical" />
										<li onClick={this.handleShowSetMeal} className='color333'>
											<Icon className='doctor-menu-unfold-splice' />
											<span>{this.setMessage("CMOrderSaveadd_package", "descripts")}</span>
										</li>
										<Divider type="vertical" />
										<li onClick={this.handleCancelButton} className={recipeListRowId ? 'color333' : 'color999'}>
											<Icon className='doctor-cannel-splice' />
											<span>{this.setMessage("CMOrderSaverevoke", "descripts")}</span>
										</li>
										<Divider type="vertical" />
										<li onClick={this.handleSaveDetailList} className={recipeListRowId || inoperable || this.state.disBtn == 'N' ? 'color999' : 'color333'}>
											<Icon className='doctor-save-splice' />
											<span>{this.setMessage("CMOrderSavesave", "descripts")}</span>
										</li>
									</ul>
								</div>
								<Form className="form-flex">
									<Form.Item className="rules-position rules-position-star">
										{/* {getFieldDecorator('herbalFormID', { // 使用剂型
									initialValue: rowData.herbalFormID ? rowData.herbalFormID : undefined,
									rules: [{ required: true, message: this.setMessage("CMOrderSaveuse_dosage_form", "message") }]
								})( */}
										<span className="star">{this.setMessage("CMOrderSaveuse_dosage_form", "descripts")}：</span>
										<Select value={herbalFormID} onChange={this.handleHerbalFormChange} showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId ? true : false}>
											{herbalFormOption}
										</Select>
										{/* )} */}
									</Form.Item>
									<Form.Item label={this.setMessage("CMOrderSavenumber_of_medications", "descripts")} className="rules-position">
										{getFieldDecorator('durQty', { // 用药副数
											initialValue: rowData.durQty ? rowData.durQty : undefined,
											// rules: [{ required: true, message: '用药副数不能为空' }]
											rules: [{ required: true, message: this.setMessage("CMOrderSavenumber_of_medications", "message") }, { pattern: /^[1-9]\d*$/, message: this.setMessage("CMOrderSavethe_input_format_is", "descripts") }]
										})(
											<InputNumber type="number" min={minQty} max={maxQty} className="input-number" style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_enter", "descripts")} disabled={recipeListRowId ? true : false} />
										)}
									</Form.Item>
									<Form.Item label={this.setMessage("CMOrderSavefrequency_of_use", "descripts")} className="rules-position">
										{getFieldDecorator('freqID', { // 使用频次
											initialValue: rowData.freqID ? rowData.freqID : undefined,
											rules: [{ required: true, message: this.setMessage("CMOrderSavefrequency_of_use", "message") }]
										})(
											<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId || handleStatus}>
												{frequenceOption}
											</Select>
										)}
									</Form.Item>
									<Form.Item label={this.setMessage("CMOrderSaveper_dose", "descripts")} className="rules-position">
										{getFieldDecorator('doseQty', { // 每次用量
											initialValue: rowData.doseQty ? rowData.doseQty : undefined,
											rules: [{ required: true, message: this.setMessage("CMOrderSaveper_dose", "message") }]
										})(
											<Input style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_enter", "descripts")} disabled={recipeListRowId || handleStatus} />
										)}
									</Form.Item>
									<Form.Item label={this.setMessage("CMOrderSavemedication", "descripts")} className="rules-position">
										{getFieldDecorator('usageID', { // 用药方法
											initialValue: rowData.usageID ? rowData.usageID : undefined,
											rules: [{ required: true, message: this.setMessage("CMOrderSavemedication", "message") }]
										})(
											<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId || handleStatus}>
												{usageOption}
											</Select>
										)}
									</Form.Item>
									<Form.Item label={this.setMessage("CMOrderSavetaking_requirements", "descripts")} className="rules-position">
										{getFieldDecorator('usageExplainID', { // 服用要求
											initialValue: rowData.usageExplainID ? rowData.usageExplainID : undefined,
											rules: [{ required: true, message: this.setMessage("CMOrderSavetaking_requirements", "message") }]
										})(
											<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId || handleStatus}>
												{usageExplainOption}
											</Select>
										)}
									</Form.Item>
									{/* <Form.Item label={this.setMessage("CMOrderSavesettlement_type", "descripts")} className="rules-position">
								{getFieldDecorator('admReasonID', { // 结算类型
									initialValue: rowData.admReasonID ? rowData.admReasonID : undefined,
									rules: [{ required: true, message: this.setMessage("CMOrderSavesettlement_type", "message") }]
								})(
									<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId ? true : false}>
										{settlementTypeOption}
									</Select>
								)}
							</Form.Item> */}
									<Form.Item label={this.setMessage("CMOrderSaveexecutive_section", "descripts")} className="rules-position">
										{getFieldDecorator('recLocID', { // 执行科室
											initialValue: rowData.recLocID ? rowData.recLocID : undefined,
											rules: [{ required: true, message: this.setMessage("CMOrderSaveexecutive_section", "message") }]
										})(
											<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId ? true : false}>
												{departmentOption}
											</Select>
										)}
									</Form.Item>
									<Form.Item label={this.setMessage("CMOrderSavedecoction_way", "descripts")} className="rules-position">
										{getFieldDecorator('cookTypeID', { // 煎药方式
											initialValue: rowData.cookTypeID ? rowData.cookTypeID : undefined,
											// rules: [{ required: true, message: this.setMessage("CMOrderSavedecoction_way", "message") }]
										})(
											<Select showSearch onChange={this.getTheDepartmentAccordingToTheDecoctingMethod} optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")} disabled={recipeListRowId || handleStatus}>
												{cookTypeOption}
											</Select>
										)}
									</Form.Item>
								</Form>
								<div>
									<div style={{ background: 'rgba(240, 242, 245, 1)', height: '32px', lineHeight: '32px' }}><Icon className='doctor-table-title-splice' style={{ marginLeft: 0 }} />
										{this.setMessage("CMOrderSaveprescribing_information", "descripts")}
										{messageError ? <span style={{ color: 'red', marginLeft: '50px', fontSize: '16px' }}>{messageError}</span> : ''}
									</div>
									<div style={{ height: '40px', lineHeight: '40px' }}>
										<div style={{ display: 'inline-block', padding: '0 18px' }}>
											<span className="star">{this.setMessage("CMOrderSavename", "descripts")}：</span>
											<Input
												id="name-input"
												style={{ width: '150px', marginRight: '20px' }}
												onPressEnter={this.nameOnPressEnter}
												value={medDesc}
												onChange={this.handleMedDesc}
												placeholder={this.setMessage("CMOrderSavename", "message")}
												onBlur={this.handleOnBlur}
												autoComplete="off"
												allowClear
												disabled={recipeListRowId || (detailRowData && detailRowData.medID ? true : false) || inoperable || this.state.disBtn == 'N'}
												ref={this.myRef1}
											/>
											<span className="star">{this.setMessage("CMOrderSavesingle_dose", "descripts")}：</span>
											<Input
												style={{ width: '80px', marginRight: '5px' }}
												value={dose}
												onChange={this.handleDose}
												placeholder="剂量"
												// placeholder={this.setMessage("CMOrderSaveplease_enter", "descripts")}
												allowClear
												disabled={recipeListRowId ? true : false}
												ref={this.myRef2}
												onPressEnter={this.doseQtyOnPressEnter}
											/>
											<Select
												showSearch optionFilterProp="seatchprop" allowClear
												style={{ width: '80px', marginRight: '20px' }}
												value={doseUnitID}
												onChange={this.handledoseUnitID}
												placeholder="单位"
												// placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")}
												disabled={recipeListRowId ? true : false}
											>
												{numOption}
											</Select>
											{/* {this.setMessage("CMOrderSavemedication_type", "descripts")}：<Select
									style={{
										width: '80px', marginRight: '10px'
									}}
									value={comPrincipleID}
									onChange={this.handleComPrincipleID}
									showSearch optionFilterProp="seatchprop" allowClear
									placeholder="类型"
									// placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")}
									disabled={recipeListRowId ? true : false}
								>
									{comPrincipleOption}
								</Select> */}
											{this.setMessage("CMOrderSaveremark", "descripts")}：
											<Input
												allowClear
												value={decoctMethod}
												style={{ width: '120px', marginRight: '12px' }}
												placeholder={this.setMessage("CMOrderSaveplease_enter", "descripts")}
												disabled={recipeListRowId ? true : false}
												ref={this.myRef4}
												onChange={Util.commonInputChange.bind(this, 'decoctMethod')}
											/>
											{/* <Select
									showSearch optionFilterProp="seatchprop" allowClear
									style={{ width: '150px', marginRight: '20px' }}
									value={decoctMethodID}
									onChange={this.handleCmOrderSetDetailDecoctMethodID}
									placeholder={this.setMessage("CMOrderSaveplease_choose", "descripts")}
									disabled={recipeListRowId ? true : false}
									ref={this.myRef4}
								>
									{decoctMethodOption}
								</Select> */}
											<Button className="button-hover" ref={this.myRef5} onClick={this.handleDetailSave} title="新增后请点击保存按钮保存新增的数据" disabled={recipeListRowId || addStatus || this.state.disBtn == 'N' || inoperable || messageError}>{detailRowData && detailRowData.medID ? this.setMessage("CMOrderSavesave", "descripts") : this.setMessage("CMOrderSaveadd", "descripts")}</Button>
											<Button type="danger" ghost onClick={this.clearDetailInput} style={{ display: detailRowData && detailRowData.medID ? 'inline-block' : 'none', marginLeft: '8px' }}>{this.setMessage("CMOrderSaveCancel_editing", "descripts")}</Button>
										</div>
										{/* <div style={{ display: 'inline-block', float: 'right' }}>
								<ul className="round-ul">
									<li>
										<span className="round-span" style={{ background: '#ffa23e' }}></span>{this.setMessage("CMOrderSaveking_medicine", "descripts")}
									</li>
									<li>
										<span className="round-span" style={{ background: '#39d1d1' }}></span>{this.setMessage("CMOrderSavemedicine", "descripts")}
									</li>
									<li>
										<span className="round-span" style={{ background: '#fa5ab2' }}></span>{this.setMessage("CMOrderSaveadjuvant", "descripts")}
									</li>
									<li>
										<span className="round-span" style={{ background: '#aa71f9' }}></span>{this.setMessage("CMOrderSavemake_medicine", "descripts")}
									</li>
								</ul>
							</div> */}
									</div>
									<Row>
										<Col span={15} style={{ height: store.getState().tableHeight.y - 123 + 'px', border: '1px solid #ccc' }}>
											<ul className="round-list" id="round-detail-list">
												{orderSetDetailDom}
											</ul>
										</Col>
										<Col span={9}>
											<Card
												size="small"
												title={this.setMessage("CMOrderSaveLOTHP", "descripts")}
												headStyle={{ background: 'rgb(66, 185, 131)', color: '#fff' }}
												bodyStyle={{ padding: '0px' }}
											>
												<div style={{ height: store.getState().tableHeight.y - 162 + 'px', overflow: 'auto' }}>
													<Table
														columns={columns && columns.length > 0 ? columns : this.columns}
														dataSource={tableData}
														bordered
														pagination={false}
														scroll={{ x: totalWidth, }}
														onRow={this.onClickRecipeListRow}
														rowClassName={this.onClickRecipeListRowClassName}
													/>
												</div>
											</Card>
										</Col>
									</Row>
								</div>
							</div>
						) : (
							<Empty
								style={{ marginTop: '100px' }}
								description={(
									<div>
										{isExistRecord !== 'Y' ? '没有录入病历的话是不能录草药的哦！' : '没下诊断的话是不能录草药的哦！'}
									</div>
								)}
								image={Empty.PRESENTED_IMAGE_SIMPLE}
							/>
						)}
					</div>
				</div>
				<div
					tabIndex={1}
					onKeyDown={this.handlePublicModalTableOnKeydown}
					style={{ outline: 'none' }}
				>
					<PublicModalTable
						onClickRowPublic={this.onClickRowPublic}
						setRowClassNamePublic={this.setRowClassNamePublic}
						param={param}
						onRef={this.onRef}
						compilePage={this.compilePage}
						id="gundong"
					/>
				</div>
				<Modal
					title={this.setMessage("CMOrderSaveCHP", "descripts")}
					visible={visible}
					onOk={this.handleOk}
					onCancel={this.handleCancel}
					width={1200}
					className="quote-modal cm-order-save"
				>
					<div style={{ width: '100%', height: '600px' }}>
						<Row>
							<Col span={7}>
								<Card
									size="small"
									title={<div className="card-title-left-icon"><div></div>{this.setMessage("CMOrderSavefind_a_list_of_visits", "descripts")}</div>}
									className="medical-advice-list"
								>
									<div style={{ margin: '8px' }}>
										{this.setMessage("CMOrderSaveselect_date", "descripts")}：<RangePicker style={{ display: 'inline-block', width: '70%' }} onChange={this.handleRangePicker} />
									</div>
									<Table
										columns={this.quoteColumns}
										dataSource={quoteData}
										bordered
										pagination={false}
										scroll={{ y: 450 }}
										onRow={this.onClickQuoteRow}
										rowClassName={this.onClickQuoteRowClassName}
									/>
									<Pagination
										showTotal={() => this.showTotal(quoteTotal)}
										size="small"
										showQuickJumper
										showSizeChanger
										current={quotePage}
										total={quoteTotal}
										onChange={this.handlePaginationOnChange}
										onShowSizeChange={this.handlePaginationOnShowSizeChange}
										style={{ textAlign: "right", marginTop: '13px' }}
									/>
								</Card>
							</Col>
							<Col span={12} style={{ display: !zoomSpan ? 'block' : 'none' }}>
								<Card
									size="small"
									title={<div className="card-title-left-icon"><div></div>
										{this.setMessage("CMOrderSaveLOTHP", "descripts")}
										<div style={{ float: 'right' }}>
											{this.setMessage("CMOrderSavenumber_of_prescriptions", "descripts")}：<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900' }}>{this.state.detailDurQty ? this.state.detailDurQty : 0}</span>,
											{this.setMessage("CMOrderSaveprescription_amount", "descripts")}：<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900', marginRight: '24px' }}>{this.state.detailPrescPrice ? this.state.detailPrescPrice : 0}</span>
											{this.setMessage("CMOrderSavecurrent_prescription_amount", "descripts")}：<span style={{ color: '#1999db', fontSize: '14px', fontWeight: '900' }}>{this.state.detailPerscAmt ? this.state.detailPerscAmt : 0}</span>
										</div>
									</div>}
									className="medical-advice-list"
								>
									<div style={{ padding: '0 12px' }}>
										<Row style={{ height: '42px', lineHeight: '42px' }}>
											<Col span={18}>{modalDetailListData[0] ? modalDetailListData[0].note : ''}</Col>
											<Col span={6} style={{ textAlign: 'right' }}><span className="span" onClick={this.handleCheckAndAgainstAll}>{this.setMessage("CMOrderSaveis_select", "descripts")}</span></Col>
										</Row>
										<ul className="round-list" style={{ height: '520px', overflow: 'auto' }}>
											{modalDetailListDom}
										</ul>
									</div>
								</Card>
							</Col>
							<Col span={zoomSpan ? 17 : 5}>
								<Card
									size="small"
									// title={<div><Icon type={zoomSpan ? 'menu-unfold' : 'menu-fold'} onClick={this.handleZoom} style={{marginRight: '6px'}} />本次草药处方列表</div>}
									// headStyle={{background: 'rgb(66, 185, 131)'}}
									title={<div className="card-title-left-icon"><div></div>{this.setMessage("CMOrderSaveLOTHP", "descripts")}</div>}
									className="medical-advice-list"
								>
									<div style={{ height: '564px', overflow: 'auto' }}>
										<List
											className="modal-right-list"
											size="large"
											dataSource={listData}
											renderItem={item => <List.Item style={{ color: item.isShow ? 'rgb(77, 193, 130)' : 'rgba(0, 0, 0, 0.65)' }} onClick={() => this.handleClickListItem(item, 'detail')}>{item.title}</List.Item>}
										/>
									</div>
								</Card>
							</Col>
						</Row>
					</div>
				</Modal>
				<AddHeabTemplate onRef={this.handleTemplate} />
				<AddHeabSetMeal onRef={this.handleSetMeal} />

				{/* 处方确认 */}
				<PublicModalQueryTable
					cancelText={selectData?.medRepeatFlag === 'Y' ? "取消" : '知道了'}
					okText="确定"
					title={selectData?.medRepeatFlag === 'Y' ? '确认医嘱' : '处方提示信息'}
					autoQueryFlag="N"
					width="50vw"
					doubleRecordFlag="N"
					idIndex="medID"
					multipleFlag={selectData?.medRepeatFlag}
					okBtnFlag={selectData?.medRepeatFlag === 'Y' ? 'Y' : 'N'}
					tableHeight={store.getState().tableHeight.y - 148}
					componentName="CMOrderSaveFormOrdConfirm"
					onRef={ref => this.ordConfirmRef = ref}
					handleOk={this.handleOrdConfirmSave}
				/>
			</div>
		)
	}
};
const CMOrderSaveForm = Form.create()(CMOrderSave);
export default CMOrderSaveForm;
