// 协定处方
import React from 'react';
import { Row, Col, Card, Input, Button, Checkbox, Icon, Form, Select, message, Divider } from 'antd';
import store from 'store';
import { $http } from 'containers/config/https';
import '../workstation/style/index.less';
import '../workstation/style/CMOrderSave.less';
// import './css/index.less';
import PubilcTablePagination from '../common/PubilcTablePagination.jsx';
import PublicModalTable from 'pages/common/PublicModalTable';

const { Option } = Select;

class CipherPrescription extends React.Component {
	constructor(props) {
		super(props);
		var userData = JSON.parse(sessionStorage.getItem('userData'));
		this.state = {
			tableData: [], // 左侧表格数据
			userInfo: {}, // 协定处方数据
			rowId: '', // 选中行ID
			rowData: {}, // 选中行数据
			name: undefined, // 名称、别名
			page: 1,
			pageSize: 10,
			total: 0,
			user: userData,
			selectData: {}, // 下拉框数据
			departmentInformation: [], // 科室下拉数据
			checkStatus: false, // 记录全选点击状态
			top: 0,
			left: 0,
			medID: '', // 名称ID
			comPrincipleID: undefined, // 用药类型
			medDesc: undefined, // 名称
			doseQty: undefined, // 数量
			decoctMethodID: undefined, // 备注
			modalData: [], // 名称模态框数据
			modalTotal: 0,
			modalPage: 1,
			modalPageSize: 10,
			seqNo: 0,
			orderSetDetailData: [],
			detailRowData: {}, // 编辑明细
			unitID: undefined,
			numSelectData: [], // 单位下拉框数据
		};
		this.columns = [
			{
				title: '代码',
				dataIndex: 'code',
				key: '1',
				align: 'center',
				width: '50px',
			},
			{
				title: '描述',
				dataIndex: 'descripts',
				key: '2',
				align: 'center',
				width: '100px',
			},
			{
				title: '简称',
				dataIndex: 'shortDesc',
				width: '100px',
				align: 'center',
				key: '3',
			},
			{
				title: '英文描述',
				dataIndex: 'enDescripts',
				width: '100px',
				align: 'center',
				key: '4',
			}
		];
		this.modalColumns = [
			{
				title: '编码',
				dataIndex: 'medCode',
				key: '1',
				width: '50px',
			},
			{
				title: '名称*规格',
				dataIndex: 'medDesc',
				width: '100px',
				key: '2',
			},
			{
				title: '大类',
				dataIndex: 'medCatDesc',
				width: '100px',
				key: '3',
			},
			{
				title: '子类',
				dataIndex: 'medSubCatDesc',
				key: '4',
				width: '100px',
			}
		]
	}

	componentDidMount() {
		this.handleQuery(); // 初始化列表数据
		this.getSelectData();
	}

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

	modalOnRef = (ref) => {
		this.modalChild = ref;
	}

	// 获取下拉框数据
	getSelectData = () => {
		let { user } = 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) {
					this.setState({ selectData: res }, () => {
						this.props.form.setFieldsValue({
							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.getDepartmentInformation(this.state.selectData && this.state.selectData.defaultHerbalFormID ? this.state.selectData.defaultHerbalFormID : '');
					})
				}
			}
		})
	}

	// 3.13.23.获取科室信息
	getDepartmentInformation = (herbalFormID) => {
		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) {
					this.setState({ departmentInformation: res.data && res.data.CMRecLocList.length > 0 ? res.data.CMRecLocList : [] }, () => {
						this.props.form.setFieldsValue({
							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, // 煎药方式
						})
					})
				}
			}
		})
	}

	// 获取列表数据
	getTableData = () => {
		let { page, pageSize, user, name } = this.state;
		let data = {
			params: [
				{
					findCode: name, // 名称
					hospID: user.hospID, // 医院id
				}
			],
			pagination: [{
				pageSize: pageSize,
				currentPage: page,
				sortColumn: 'code',
				sortOrder: 'asc'
			}]
		}
		this.child.handleLoading()
		$http.post('urlS', this, {
			code: "03010023",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let data = res.result && res.result.Data ? res.result.Data : [];
					for (var i = 0; i < data.length; i++) {
						data[i].key = data[i].id
					}
					this.setState({
						tableData: data,
						total: res.result && res.result.TotalCount ? res.result.TotalCount : 0
					})
				}
			}
		})
	}

	// 获取协定处方类医嘱
	handleQuery = () => {
		this.setState({ page: 1, pageSize: 10, rowId: '', rowData: {}, userInfo: {}, orderSetDetailData: [] }, () => {
			this.getTableData()
		})
	}

	// 获取名称、别名
	handleNameOnChange = e => {
		this.setState({ name: e.target.value })
	}

	// 查询协定处方数据
	handleQueryCipherPre = () => {
		this.resetFields();
		let { user, rowId } = this.state;
		let data = {
			params: [
				{
					medID: rowId, // 医嘱项id
					hospID: user.hospID, // 医院id
				}
			]
		}
		$http.post('urlS', this, {
			code: "03010025",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let orderSetDetailData = res.data && res.data.length > 0 ? JSON.parse(JSON.stringify(res.data[0].orders)).map((item, index) => {
						return {
							key: index,
							checkBox: false,
							...item
						}
					}) : [];
					this.setState({
						userInfo: res.data && res.data.length > 0 ? res.data[0] : {},
						orderSetDetailData,
						seqNo: orderSetDetailData.length - 1
					}, () => {
						// console.log(this.state.orderSetDetailData)
					})
				} else {
					this.setState({
						userInfo: {},
						orderSetDetailData: []
					})
				}
			}
		})
	}

	// 行操作
	onClickRowPublic = (record) => {
		return {
			// 单击行选中
			onClick: () => {
				if (record.id) {
					if (this.state.rowId === '') {
						// 保存行数据以及ID
						this.setState({ rowId: record.id, rowData: record }, () => {
							this.resetDetailData();
							this.handleQueryCipherPre();
						})
					} else {
						if (this.state.rowId !== record.id) {
							this.setState({ rowId: record.id, rowData: record }, () => {
								this.handleQueryCipherPre();
								this.resetDetailData();
							})
						}
					}
				}
			}
		}
	}

	// 选中行class
	setRowClassNamePublic = (record) => {
		return record.id === this.state.rowId ? 'clickRowStyle' : '';
	}

	// 提供修改page和pageSize的回调函数
	compilePage(page, pageSize) {
		// 修改page，或者pageSize
		this.setState({ page: page, pageSize: pageSize }, () => {
			this.getTableData();
		})
	}

	// 使用剂型
	handleHerbalFormID = e => {
		this.getDepartmentInformation(e)
	}

	// 全选
	handleCheckAll = () => {
		let { checkStatus, orderSetDetailData } = this.state;
		let checkStatusFlag = checkStatus; // 记录全选点击状态
		this.setState({ checkStatus: !checkStatus });
		let arr = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
		if (!(arr && arr.length > 0)) {
			message.info("暂无可操作的数据");
			return;
		}
		for (var i = 0; i < arr.length; i++) {
			if (!checkStatusFlag) {
				arr[i].checkBox = true;
			} else {
				arr[i].checkBox = false;
			}

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

	// 改变checkBox操作
	handleCheckOnChange = (item) => {
		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 });
	}

	// 删除明细
	handleDeleteDetail = () => {
		let { orderSetDetailData } = this.state;
		let arr = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
		let filterData = [];
		let filterLocalData = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].checkBox) {
				filterData.push(arr[i]);;
				filterLocalData = filterLocalData.filter(function (item) { return arr[i].key !== item.key });
			}
		}
		if (filterData && filterData.length > 0) {
			this.setState({ orderSetDetailData: filterLocalData }, () => {
				for (var i = 0; i < this.state.orderSetDetailData.length; i++) {
					if (JSON.stringify(this.state.orderSetDetailData[i]) === JSON.stringify(this.state.detailRowData)) {
						break;
					} else {
						this.resetDetailData();
					}
				}
			})
		} else {
			message.info("请选择需要删除的数据")
		}
	}

	// 获取以及勾选的数据
	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 = () => {
		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 });
		} else {
			message.info("请选择需要操作的数据")
		}
	}

	// 右移
	handleRight = () => {
		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 });
		} else {
			message.info("请选择需要操作的数据")
		}
	}

	// 获取dom宽度
	getDetailListWidth = (domId) => {
		var o = document.getElementById(domId);
		var w = o.clientWidth || o.clientWidth;
		let num = Number(Math.floor(w / 158));
		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 });
		} else {
			message.info("请选择需要操作的数据")
		}
	}

	// 下移
	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 });
		} else {
			message.info("请选择需要操作的数据")
		}
	}

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

	// 重置表单
	resetFields() {
		this.props.form.resetFields();
	}

	// 用药类型
	handleComPrincipleID = e => {
		this.setState({ comPrincipleID: e })
	}

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

	// 数量
	handleNum = e => {
		this.setState({ doseQty: e.target.value })
	}

	// 备注
	handleMethod = e => {
		this.setState({ decoctMethodID: e })
	}

	// 名称回车事件
	handleOnPressEnter = (e) => {
		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,
		});
		this.getModalListData();
		this.modalChild.showModal();
	}

	// 获取描述列表数据
	getModalListData() {
		let { medDesc, modalPageSize, modalPage } = this.state;
		let user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		let data = {
			params: [
				{
					hospID: user.hospID, // 医院ID
					detailFlag: '1',
					findCode: medDesc, // 库存项描述别名
					medSubCatID: this.state.selectData && this.state.selectData.defaultMedSubCatID ? this.state.selectData.defaultMedSubCatID : '',
				}
			],
			pagination: [{
				pageSize: modalPageSize,
				currentPage: modalPage
			}]
		}
		$http.post('urlS', this, {
			code: "01010002",
			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, modalTotal: res.result.TotalCount })
				}
			}
		})
	}

	// 操作弹框
	handleRowPublic = (record) => {
		return {
			onDoubleClick: () => {
				this.setState({ medDesc: record.medDesc, medID: record.medID }, () => {
					this.modalChild.handleCancel();
					this.getNumSelectData();
				})
			}
		}
	}

	// 获取单位的下拉框以及下拉数据
	getNumSelectData = () => {
		let { user, medID } = this.state;
		let recLocID = this.props.form.getFieldValue('recLocID');
		let arr = [
			{ medID }
		]
		let data = {
			params: [
				{
					recLocID: recLocID, // 执行科室id
					hospID: user.hospID, // 登录医院id
					groupID: user.groupID, //	登录角色id
					userID: user.userID, // 登录用户id
					locID: user.locID, // 登录科室id
					admID: "", // 就诊id
					orders: arr
				}
			]
		}
		$http.post('urlS', this, {
			code: "03050076",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let obj = res.data[0].data ? res.data[0].data : {};
					let numSelectData = obj.qtyUnitList ? obj.qtyUnitList : [];
					let unitID = obj.ordDoseUnitID ? obj.ordDoseUnitID : undefined;
					let comPrincipleID = obj.comPrincipleID ? obj.comPrincipleID : undefined;
					let doseQty = obj.ordDose ? obj.ordDose : undefined;
					this.setState({ numSelectData, unitID, comPrincipleID, doseQty })
				}
			}
		})
	}

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

	// 名称失焦操作
	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 })
			}
		} else {
			this.setState({ medID: '', medDesc: undefined })
		}
	}

	handleTransition = (arr, id) => {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id === id) {
				return arr[i].descripts
			}
		}
	}

	// 新增明细
	handleDetailSave = () => {
		let { comPrincipleID, doseQty, decoctMethodID, medDesc,
			medID, selectData, seqNo, orderSetDetailData, detailRowData, unitID, numSelectData } = this.state;
		let nums = orderSetDetailData && orderSetDetailData.length > 0 ? seqNo + 1 : 0;
		if (!comPrincipleID) {
			message.info("请选择用药类型");
			return;
		} else if (!medID) {
			message.info("请根据名称回车查询名称ID");
			return;
		}
		let obj = {
			comPrincipleID,
			doseQty: doseQty,
			decoctMethodID,
			decoctMethodDesc: decoctMethodID ? this.handleTransition(selectData.decoctMethod, decoctMethodID) : '无',
			medDesc,
			medID,
			unitID,
			checkBox: false,
			seqNo: detailRowData && detailRowData.key ? detailRowData.key : nums,
			key: detailRowData && detailRowData.key ? detailRowData.key : nums,
			qtyUnitList: numSelectData ? JSON.parse(JSON.stringify(numSelectData)) : [],
		}
		let arr = JSON.parse(JSON.stringify(orderSetDetailData));
		if (detailRowData && detailRowData.comPrincipleID) {
			for (var i = 0; i < arr.length; i++) {
				if (JSON.stringify(arr[i]) === JSON.stringify(detailRowData)) {
					arr[i] = obj
				}
			}
		} else {
			arr.push(obj);
		}
		// console.log(arr)
		this.setState({ orderSetDetailData: arr, seqNo: nums }, () => {
			this.resetDetailData()
		})
	}

	// 重置处方提示新增下的信息
	resetDetailData = () => {
		this.setState({
			detailRowData: {},
			numSelectData: [],
			comPrincipleID: undefined,
			doseQty: undefined,
			decoctMethodID: undefined,
			decoctMethodDesc: '',
			medDesc: undefined,
			medID: '',
			unitID: undefined
		})
	}

	// 保存
	handleSaveDetailList = () => {
		if (this.state.recipeListRowId) {
			return;
		}
		let { user, rowId } = this.state;
		this.props.form.validateFields((err, values) => {
			if (!err) {
				let { orderSetDetailData } = this.state;
				let arr = orderSetDetailData ? JSON.parse(JSON.stringify(orderSetDetailData)) : [];
				let obj = {
					medID: rowId, // 医嘱项id
					hospID: user.hospID ? user.hospID : '', // 登录医院id
					userID: user.userID ? user.userID : '', // 登录用户id
					...values,
					orders: arr && arr.length > 0 ? arr : undefined,
				}
				let data = {
					params: []
				}
				data.params.push(obj);
				$http.post('urlADS', this, {
					code: '03010024',
					data: data,
					success: function (res) {
						if (+res.errorCode === 0) {
							// 成功提示
							message.success("保存成功: 请审核");
						}
					}
				})
			}
		})
	}

	// 审核
	handleAudit = () => {
		let { user, rowId } = this.state;
		let obj = {
			medID: rowId, // 医嘱项id
			hospID: user.hospID ? user.hospID : '', // 登录医院id
			userID: user.userID ? user.userID : '', // 登录用户id
		}
		let data = {
			params: []
		}
		data.params.push(obj);
		$http.post('urlADS', this, {
			code: '03010026',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					// 成功提示
					message.success("审核成功");
					this.handleQuery();
					this.resetDetailData();
					this.resetFields();
				}
			}
		})
	}

	// 修改明细
	compileOrderDetailDom = item => {
		// console.log(item)
		this.setState({
			numSelectData: item.qtyUnitList, // 单位下拉框
			detailRowData: item,
			medID: item.medID,
			medDesc: item.medDesc,
			comPrincipleID: item.comPrincipleID, // 用药类型
			doseQty: item.doseQty,
			unitID: item.unitID,
			decoctMethodID: item.decoctMethodID, // 备注
		}, () => {
			this.getModalListData()
		})
	}

	// 阻止事件冒泡
	handlePopconfirm = (e) => {
		e.stopPropagation();
	}

	// 单位
	handleUnitID = e => {
		this.setState({ unitID: e })
	}

	render() {
		let { name, tableData, userInfo, rowId, total, page, selectData, departmentInformation, orderSetDetailData, comPrincipleID, medDesc, doseQty, decoctMethodID,
			top, left, modalData, modalPage, modalTotal, rowData, unitID, detailRowData, numSelectData
		} = this.state;
		const { getFieldDecorator } = this.props.form;
		let param = {
			// 表头配置
			columns: this.columns,
			// 表格数据
			data: tableData,
			// 数据总条数
			total: total,
			// 当前页数
			page: page,
			// 表格的宽度
			x: 400,
			isOnRow: true,
			rowClassName: true,
			y: store.getState().tableHeight.y,
			height: store.getState().tableHeight.y + 45 + 'px',
		}
		let modalParam = {
			width: '500px',
			height: 250,
			top: top,
			left: left,
			columns: this.modalColumns,
			data: modalData,
			isOnRow: true,
			TableClassName: 'tab-placeholder',
			rowClassName: true,
			showPagination: true,
			page: modalPage,
			total: modalTotal,
		}

		// 剂型
		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 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 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 numOption = numSelectData && numSelectData.map((item, index) => {
			return (<Option key={index} value={item.unitID} title={item.unitDesc} seatchprop={item.unitDesc}>{item.unitDesc}</Option>)
		})

		let orderSetDetailDom = orderSetDetailData && orderSetDetailData.map((item, index) => {
			return (
				<li key={index} onClick={() => this.compileOrderDetailDom(item)} style={{ cursor: 'pointer' }}>
					<h3 style={{
						background: item.comPrincipleID === '1' ? '#ffa23e' : (item.comPrincipleID === '2' ? '#39d1d1' : (item.comPrincipleID === '3' ? '#fa5ab2' : (item.comPrincipleID === '4' ? '#aa71f9' : '#fff'))),
						textAlign: 'center',
						position: 'relative',
						color: item.comPrincipleID ? '#fff' : '#000',
						height: '24px',
						lineHeight: '24px'
					}}>
						<Checkbox style={{ position: 'absolute', left: '4px' }} checked={item.checkBox} onChange={() => this.handleCheckOnChange(item)} onClick={this.handlePopconfirm} />
						{item.medDesc}
					</h3>
					<div>
						<div className="ellipsis" style={{ marginBottom: '8px' }}>药品数量: {item.doseQty}</div>
						<div className="ellipsis">备注: {item.decoctMethodDesc}</div>
					</div>
				</li>
			)
		})

		return (
			<div className="cm-order-group cm-order-save">
				<Row>
					<Col span={7}>
						<Card
							size="small"
							title="协定处方列表"
							headStyle={{ background: 'rgb(66, 185, 131)' }}
							className="medical-advice-list"
						>
							<div style={{ height: store.getState().tableHeight.y + 204 + 'px', overflow: 'auto' }}>
								<div style={{ padding: '12px' }}>
									<Row style={{ margin: '12px 0' }}>
										<Col span={16} style={{ marginRight: '20px' }}>
											<Input
												placeholder="输入代码/描述回车查询"
												value={name}
												onChange={this.handleNameOnChange}
												onPressEnter={this.handleQuery}
											/>
										</Col>
										<Button onClick={this.handleQuery}>查询</Button>
									</Row>
								</div>
								<div>
									<PubilcTablePagination
										param={param}
										handelThis={this}
										onRef={this.onRef}
										onClickRowPublic={this.onClickRowPublic}
										setRowClassNamePublic={this.setRowClassNamePublic}
									/>
								</div>
							</div>
						</Card>
					</Col>
					<Col
						span={17}
						tabIndex={1}
						onKeyDown={this.handleOnKeydown}
						style={{ outline: 'none' }}
					>
						<Card
							size="small"
							title="协定处方维护"
							headStyle={{ background: 'rgb(66, 185, 131)' }}
							className="medical-advice-list"
						>
							<div style={{ height: store.getState().tableHeight.y + 204 + 'px', overflow: 'auto' }}>
								<Row style={{ height: '38px', lineHeight: '38px', background: 'rgba(208, 233, 255, 1)', paddingLeft: '15px' }}>
									当前处方：{rowData.code ? rowData.code : '---'}<span style={{ display: 'inline-block', margin: '0 6px' }}>|</span>
									{rowData.descripts ? rowData.descripts : '---'}
								</Row>
								<div>
									<div style={{ height: '36px', lineHeight: '36px', borderBottom: '1px solid #ccc' }}>
										<ul className="handle-btn">
											<li onClick={this.handleCheckAll} className={rowId ? 'color333' : 'color999'}>
												<Icon className="doctor-hourglass-splice" style={{ marginLeft: "10px" }} />
												<span>全选</span>
											</li>
											<Divider type="vertical" />
											<li onClick={this.handleDeleteDetail} className={rowId ? 'color333' : 'color999'}>
												<Icon className='doctor-delete-splice' />
												<span>删除</span>
											</li>
											<Divider type="vertical" />
											<li onClick={this.handleUp} className={rowId ? 'color333' : 'color999'}>
												<Icon className='doctor-up-splice' />
												<span>上移</span>
											</li>
											<Divider type="vertical" />
											<li onClick={this.handleDown} className={rowId ? 'color333' : 'color999'}>
												<Icon className='doctor-down-splice' />
												<span>下移</span>
											</li>
											<Divider type="vertical" />
											<li onClick={this.handleLeft} className={rowId ? 'color333' : 'color999'}>
												<Icon className="doctor-left-splice" />
												<span>左移</span>
											</li>
											<Divider type="vertical" />
											<li onClick={this.handleRight} className={rowId ? 'color333' : 'color999'}>
												<Icon className="doctor-right-splice" />
												<span>右移</span>
											</li>
											<Divider type="vertical" />
											<li onClick={this.handleSaveDetailList} className={rowId ? 'color333' : 'color999'}>
												<Icon className='doctor-save-splice' />
												<span>保存</span>
											</li>
											<li style={{ marginLeft: "24px" }}>
												<span
													onClick={this.handleAudit}
													style={{ padding: '2px 12px' }}
													className={!rowId ? 'span-card disp-card' : 'span-card pointer-span'}
												>
													审核
												</span>
											</li>
										</ul>
									</div>
									<Form className="form-flex">
										<Form.Item label="使用剂型" className="rules-position">
											{getFieldDecorator('herbalFormID', {
												initialValue: userInfo.herbalFormID ? userInfo.herbalFormID : undefined,
												rules: [{ required: true, message: '使用剂型不能为空' }]
											})(
												<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder="请选择" onSelect={this.handleHerbalFormID}>
													{herbalFormOption}
												</Select>
											)}
										</Form.Item>
										<Form.Item label="用药副数" className="rules-position">
											{getFieldDecorator('durQty', {
												initialValue: userInfo.durQty ? userInfo.durQty : undefined,
												// rules: [{ required: true, message: '用药副数不能为空' }]
												rules: [{ required: true, message: '用药副数不能为空' }, { pattern: /^[1-9]\d*$/, message: '用药副数只能为正整数, 如1、2、3、4' }]
											})(
												<Input type="number" className="input-number" style={{ width: '150px' }} placeholder="请输入" />
											)}
										</Form.Item>
										
										<Form.Item label="使用频次" className="rules-position">
											{getFieldDecorator('freqID', {
												initialValue: userInfo.freqID ? userInfo.freqID : undefined,
												rules: [{ required: true, message: '使用频次不能为空' }]
											})(
												<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder="请选择">
													{frequenceOption}
												</Select>
											)}
										</Form.Item>
										<Form.Item label="每次用量" className="rules-position">
											{getFieldDecorator('doseQty', {
												initialValue: userInfo.doseQty ? userInfo.doseQty : undefined,
												rules: [{ required: true, message: '每次用量不能为空' }]
											})(
												<Input style={{ width: '150px' }} placeholder="请输入" />
											)}
										</Form.Item>
										<Form.Item label="用药方法" className="rules-position">
											{getFieldDecorator('usageID', {
												initialValue: userInfo.usageID ? userInfo.usageID : undefined,
												rules: [{ required: true, message: '用药方法不能为空' }]
											})(
												<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder="请选择">
													{usageOption}
												</Select>
											)}
										</Form.Item>
										<Form.Item label="煎药方式" className="rules-position">
											{getFieldDecorator('cookTypeID', {
												initialValue: userInfo.cookTypeID ? userInfo.cookTypeID : undefined,
												rules: [{ required: true, message: '煎药方式不能为空' }]
											})(
												<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder="请选择">
													{cookTypeOption}
												</Select>
											)}
										</Form.Item>
										<Form.Item label="服用要求" className="rules-position">
											{getFieldDecorator('usageExplainID', {
												initialValue: userInfo.usageExplainID ? userInfo.usageExplainID : undefined,
												rules: [{ required: true, message: '服用要求不能为空' }]
											})(
												<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder="请选择">
													{usageExplainOption}
												</Select>
											)}
										</Form.Item>
										<Form.Item label="执行科室" className="rules-position">
											{getFieldDecorator('recLocID', {
												initialValue: userInfo.recLocID ? userInfo.recLocID : undefined,
												rules: [{ required: true, message: '执行科室不能为空' }]
											})(
												<Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '150px' }} placeholder="请选择">
													{departmentOption}
												</Select>
											)}
										</Form.Item>
									</Form>
								</div>
								<div>
									<div style={{ background: 'rgba(228, 228, 228, 1)', height: '32px', lineHeight: '32px' }}>
										<Icon className='doctor-table-title-splice' style={{ marginLeft: 0 }} />
										处方提示信息
									</div>
									<div style={{ height: '40px', lineHeight: '40px' }}>
										<div style={{ display: 'inline-block', padding: '0 12px' }}>
											用药类型：<Select
												style={{
													width: '100px', marginRight: '10px'
												}}
												showSearch optionFilterProp="seatchprop" allowClear
												placeholder="请选择"
												value={comPrincipleID}
												onChange={this.handleComPrincipleID}
											>
												{comPrincipleOption}
											</Select>
                                            名称：<Input
												id="name-input"
												style={{ width: '150px', marginRight: '10px' }}
												placeholder="(Enter)回车检索"
												value={medDesc}
												onChange={this.handleMedDesc}
												onPressEnter={this.handleOnPressEnter}
												onBlur={this.handleOnBlur}
												autoComplete="off"
												disabled={detailRowData && detailRowData.comPrincipleID ? true : false}
											/>
                                            药品数量：<Input
												style={{ width: '100px', marginRight: '5px' }}
												placeholder="请输入"
												value={doseQty}
												onChange={this.handleNum}
											/><Select style={{ width: '80px', marginRight: '20px' }} value={unitID ? +unitID : undefined} onChange={this.handleUnitID}>{numOption}</Select>
                                            备注：<Select
												showSearch optionFilterProp="seatchprop" allowClear
												style={{ width: '150px', marginRight: '10px' }}
												placeholder="请选择"
												value={decoctMethodID}
												onChange={this.handleMethod}
											>
												{decoctMethodOption}
											</Select>
											<Button onClick={this.handleDetailSave} disabled={!rowId} title="新增后请点击保存按钮保存新增的数据">{detailRowData && detailRowData.comPrincipleID ? '编辑' : '新增'}</Button>
										</div>
										<div style={{ display: 'inline-block', float: 'right' }}>
											<ul className="round-ul">
												<li>
													<span className="round-span" style={{ background: '#ffa23e' }}></span>君药
                                                </li>
												<li>
													<span className="round-span" style={{ background: '#39d1d1' }}></span>臣药
                                                </li>
												<li>
													<span className="round-span" style={{ background: '#fa5ab2' }}></span>佐药
                                                </li>
												<li>
													<span className="round-span" style={{ background: '#aa71f9' }}></span>使药
                                                </li>
											</ul>
										</div>
									</div>
									<Row >
										<Col span={20} style={{ height: store.getState().tableHeight.y + 204 - 258 + 'px', border: '1px solid #ccc', marginLeft: '8px' }}>
											<ul className="round-list" id="round-detail-list">
												{orderSetDetailDom}
											</ul>
										</Col>
										<Col span={4}></Col>
									</Row>
								</div>
							</div>
						</Card>
					</Col>
				</Row>
				<PublicModalTable
					onClickRowPublic={this.handleRowPublic}
					setRowClassNamePublic={this.handleRowClassNamePublic}
					param={modalParam}
					onRef={this.modalOnRef}
				/>
			</div>
		)
	}
};
const CipherPrescriptionForm = Form.create()(CipherPrescription);
export default CipherPrescriptionForm;
