//InsuBaseConfiguresNew 医保基础配置
import React from 'react';
import { Card, Input, Row, Col, Button, Table, Select, message, Popconfirm, Modal } from 'antd';
import { $http } from '../../containers/config/https';
import store from '../../store';
import CommonPagination from 'components/pagination/index';
import ColumnAuthoritysModel from '../../pages/columnAuthority/ColumnAuthoritysModel';
import iconListvisits from 'assets/images/icon_listvisits.png';
const Option = Select.Option;

class InsuBaseConfiguresNew extends React.Component {
	constructor(props) {
		super(props);
		const userData = React.$getSessionData();
		this.state = {
			userData,
			moduleSelect: [],
			areaSelect: [],
			handleHospSelect: [],
			// 主菜单列表数据
			data: [],
			tableList: [],
			//主表数据
			proCID: '',
			proCCode: '',
			proCDescripts: '',
			proCYBAreaID: undefined,
			//子表数据
			data1: [],
			tableList1: [],
			columnsA: [],
			//子表数据
			proDID: '',
			proDCode: '',
			proDDescripts: '',
			proDValue: '',
			proDRemark: '',
			proDType: undefined,
			//孙子表数据
			data2: [],
			tableList2: [],
			//孙子表数据
			proKID: '',
			proKHospID: userData?.hospID || undefined,
			proKCode: '',
			proKDescripts: '',
			proKLinkValue: undefined,
			proKLinkCode: '',
			proKRemark: '',
			//父表
			total: 0,
			page: 1,
			pageSize: 20,
			showLoading: true,
			//子表
			total1: 0,
			page1: 1,
			pageSize1: 20,
			showLoading1: true,
			//暂时不使用
			total2: 0,
			page2: 1,
			pageSize2: 20,
			showLoading2: true,
			showFlagInput: 'none',
			showFlagSelect: '',
			languageTable1: {}, // 国际化Table1
			languageTable2: {}, // 国际化Table2
			languageData: {}, // 国际化语言包
			language: {},   // 国际化语言
			languageCode: userData?.language || '', // 国际化语言标识
			columnsB: [],
			columnsBTotalWidth: 0,
			columnsC: [],
			columnsCTotalWidth: 0,
			modalSetVisible: false,	//配置复制弹框显示/隐藏
			currentSettingCode: undefined,	//配置复制功能：当前选中的配置项code
			copySettingCode: undefined,		//配置复制弹框内选中的要复制的配置项的code
			hospCode: undefined,				//配置复制弹框内选中的医院属性
		}
	}

	componentDidMount() {
		this.tableList("InsuBaseConfiguresNewMInsu", "InsuBaseConfiguresNewMInsu");
		this.tableList("InsuBaseConfiguresNewMInsu", "InsuBaseConfiguresNewDetail");
		this.tableList("InsuBaseConfiguresNewMInsu", "InsuBaseConfiguresNewLinkValue");
		document.querySelector('.ant-table-body').style.height = '590px';
		// 初始化列表数据
		this.getProconfigureData();
		this.handleModuleSelect();
		this.handleYBAreaSelect();
		this.handleHospSelect();
	}

	// 获取主列表columns1
	tableList = (reactCode, compontName) => {
		var data = {
			params: [{
				"reactCode": reactCode,
				"compontName": compontName,
				"type": "C"
			}]
		}
		$http.post('urlS', this, {
			code: '01040073',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let resC = res.result.C
					let { languageCode } = this.state
					for (var i = 0; i < resC.length; i++) {
						resC[i].key = i;
					}
					if (languageCode === "EN") {
						resC.map((item, i) => {
							item.title = item.enDescripts
						})
					}

					if (languageCode === "CN") {
						resC.map((item, i) => {
							item.title = item.descripts
						})
					}
					let arr = res.result && resC.length > 0 ? JSON.parse(JSON.stringify(resC)).map(item => {
						if (compontName === "InsuBaseConfiguresNewMInsu" && item.code === "action") {
							return {
								align: item.align,
								widthNum: parseInt(item.width),
								width: item.width,
								dataIndex: item.dataIndex,
								title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{item.title}</div>,
								display: item.display,
								key: item.proCCode,
								render: (text, record) => {
									return (
										<Popconfirm placement="left" title='复制其他配置项会覆盖原数据，确认是否继续' okText=" 是 " cancelText=" 否 "
											onConfirm={(e) => this.copySettingFun(e, record)}>
											<Button type="link">复制配置</Button>
										</Popconfirm>
									)
								}
							}
						} else {
							return {
								align: item.align,
								widthNum: parseInt(item.width),
								width: item.width,
								dataIndex: item.dataIndex,
								title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{item.title}</div>,
								display: item.display,
								key: item.proCCode,
							}
						}
					}) : '';

					let filterArr = arr.filter(function (item) { return item.display === 'Y' });
					if (compontName === "InsuBaseConfiguresNewMInsu") {
						this.setState({
							columnsA: filterArr,
							languageTable1: res.result.B || {},  // 国际化Table1
							languageTable2: res.result.C || {},  // 国际化Table2
							languageData: res.result.language || {},  // 国际化语言包
						}, () => {
							this.LanCNEN(this.state.languageCode)
							//   this.listAdd(filterArr.length+1, 0,languageCode);
						})
					} else if (compontName === "InsuBaseConfiguresNewDetail") {
						this.setState({
							columnsB: filterArr,
							columnsBTotalWidth: res.totalWidth
						})

					} else if (compontName === "InsuBaseConfiguresNewLinkValue") {
						this.setState({
							columnsC: filterArr,
							columnsCTotalWidth: res.totalWidth
						})
					}

				}
			}
		})
	}

	LanCNEN = (code) => {
		let { languageData } = this.state
		this.setState({
			language: languageData[code]
		})
	}

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

	// 调用公共组件的连接事件
	onRef = (ref) => {
		this.child = ref
	}

	// 页码改变的回调，参数是改变后的页码及每页条数
	appPageChange = (page, pageSize) => {
		this.setState({
			page: page,
			pageSize: pageSize,
		}, () => {
			// 重新调用查询方法
			this.getProconfigureData();
		});
	}

	// 条数改变的回调
	apponShowSizeChange = (current, size) => {
		this.setState({
			page: current,
			pageSize: size,
		}, () => {
			// 重新调用查询方法
			this.getProconfigureData();
		});
	}

	// 页码改变的回调，参数是改变后的页码及每页条数
	propPageChange = (page, pageSize) => {
		this.setState({
			page1: page,
			pageSize1: pageSize,
		}, () => {
			// 重新调用查询方法
			this.getProconfigureDetailData();
		});
	}

	// 条数改变的回调
	proponShowSizeChange = (current, size) => {
		this.setState({
			page1: current,
			pageSize1: size,
		}, () => {
			// 重新调用查询方法
			this.getProconfigureDetailData();
		});
	}

	//父表3个字段
	//代码
	onChangeProconfigureCode = (e) => {
		this.setState({
			proCCode: e.target.value,
		});
	}

	//描述
	onChangeProconfigureDescripts = (e) => {
		this.setState({
			proCDescripts: e.target.value,
		});
	}

	//医保地域
	onChangeProconfigureYBArea = (value) => {
		this.setState({
			proCYBAreaID: value
		});
	}

	//模块
	onChangeProCYBAreaID = (value) => {
		this.setState({
			proCYBAreaID: value,
		});
	}

	//子表6个字段
	// 代码
	onChangeProconfigureDetailCode = (e) => {
		this.setState({
			proDCode: e.target.value,
		});
	}

	// 描述
	onChangeProconfigureDetailDescripts = (e) => {
		this.setState({
			proDDescripts: e.target.value,
		});
	}

	//值
	onChangeProconfigureDetailValue = (e) => {
		this.setState({
			proDValue: e.target.value,
		});
	}

	// 类型
	onChangeProconfigureDetailType = (value) => {
		this.setState({
			proDType: value,
		});
	}

	// 备注
	onChangeProconfigureDetailRemark = (e) => {
		this.setState({
			proDRemark: e.target.value,
		});
	}

	//孙子表输入6个字段
	// 医院
	onChangeProconfigureLinkHospID = (value) => {
		this.setState({
			proKHospID: value,
			proKLinkValue: undefined
		}, () => {
			this.handleLinkSelect();
		});
	}

	// 代码
	onChangeProconfigureLinkCode = (e) => {
		this.setState({
			proKCode: e.target.value,
		});
	}

	//描述
	onChangeProconfigureLinkDescripts = (e) => {
		this.setState({
			proKDescripts: e.target.value,
		});
	}

	// 关联值
	onChangeProconfigureLinkLinkValue = (e) => {
		this.setState({
			proKLinkValue: e.target.value,
		});
	}

	// 关联值
	onChangeProconfigureLinkLinkValues = (value) => {
		this.setState({
			proKLinkValue: value,
		});
	}

	// 关联代码
	onChangeProconfigureLinkLinkCode = (e) => {
		this.setState({
			proKLinkCode: e.target.value,
		});
	}

	//备注
	onChangeProconfigureLinkRemark = (value) => {
		this.setState({
			proKRemark: value
		});
	}

	handleProconfigureQuery = () => {
		this.setState({ page: 1 }, () => {
			this.getProconfigureData();
		})
	}

	//复制配置
	copySettingFun = (e, record) => {
		this.setState({ modalSetVisible: true, currentSettingCode: record.proCCode, copySettingCode: undefined })
	};

	//配置复制弹框处理函数
	modalHandleCancel = (tag) => {
		let { currentSettingCode, copySettingCode, hospCode } = this.state;
		let _this = this;
		if (tag === 'Y') {
			if (copySettingCode) {
				let data = {
					params: [{
						currentSettingCode,
						copySettingCode,
						hospCode
					}],
				}
				$http.post('urlS', this, {
					code: '05100127',
					data: data,
					success: function (res) {
						if (+res.errorCode === 0) {
							message.success('操作成功');
							_this.setState({ modalSetVisible: false });
							_this.getProconfigureDetailData();
						}
					}
				});
			} else {
				message.warning('请选择需要复制的配置源')
			}
		} else {
			this.setState({ modalSetVisible: false })
		}
	};

	//配置复制框内选择器选择事件
	onCopySelectChange = (e) => {
		this.setState({ copySettingCode: e })
	};

	//配置复选框内医院选择事件
	onhospSelectChange = (e) => {
		this.setState({ hospCode: e })
	};

	//对父表操作
	//医保基础配置查询
	getProconfigureData = () => {
		let { proCCode, proCDescripts, proCYBAreaID, page, pageSize, userData } = this.state;
		let data = {
			params: [{
				code: proCCode,
				descripts: proCDescripts,
				ybAreaID: proCYBAreaID,
			}],
			pagination: [{
				pageSize: pageSize,
				currentPage: page,
				sort: "ID",
				dir: "desc"
			}]
		}
		$http.post('urlS', this, {
			code: '05100103',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.proCArr) {
					for (var i = 0; i < res.proCArr.length; i++) {
						res.proCArr[i].key = i
					}
					this.setState({
						data: res.proCArr,
						total: res.total,
						proCID: '',
						data1: [],
						proDID: '',
						proDCode: '',
						proDDescripts: '',
						proDValue: '',
						proDRemark: '',
						proDType: undefined,
						data2: [],
						//孙子表数据
						proKID: '',
						proKHospID: userData?.hospID || undefined,
						proKCode: '',
						proKDescripts: '',
						proKLinkValue: undefined,
						proKLinkCode: '',
						proKRemark: '',
						//子表
						total1: 0,
						page1: 1,
						showLoading1: true,
						//暂时不使用
						total2: 0,
						page2: 1,
						showLoading2: true,
					})
				}
			}
		})
	}

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

	onClickProconfigureRow = (record) => {
		//给右边的编辑form传值
		return {
			onClick: () => {
				this.setState({
					data1: [],
					total1: 0,
					page1: 1,
					proDID: '',
					proDCode: '',
					proDDescripts: '',
					proDValue: '',
					proDRemark: '',
					proDType: undefined,
				})
				if (this.state.proCID === "") {
					this.setState({
						proCID: record.proCID,
						proCCode: record.proCCode,
						proCDescripts: record.proCDescripts,
						proCYBAreaID: record.proCYBAreaID,
					}, () => { this.getProconfigureDetailData(); });
				} else {
					if (this.state.proCID !== record.proCID) {
						this.setState({
							proCID: record.proCID,
							proCCode: record.proCCode,
							proCDescripts: record.proCDescripts,
							proCYBAreaID: record.proCYBAreaID,
						}, () => { this.getProconfigureDetailData(); });
					} else {
						this.setState({
							proCID: '',
							proCCode: '',
							proCDescripts: '',
							proCYBAreaID: '',
							//子表数据
							data1: [],
							//子表数据
							proDID: '',
							proDCode: '',
							proDDescripts: '',
							proDValue: '',
							proDRemark: '',
							proDType: undefined,
							//孙子表数据
							data2: [],
							//孙子表数据
							proKID: '',
							proKHospID: this.state.userData?.hospID || undefined,
							proKCode: '',
							proKDescripts: '',
							proKLinkValue: undefined,
							proKLinkCode: '',
							proKRemark: '',
							//信息
							total1: 0,
							page1: 1,
							showLoading1: true,
							//信息
							total2: 0,
							page2: 1,
							showLoading2: true,

						});
					}
				}
			},
		};
	}

	handleProconfigureSave = () => {
		let sessionInfo = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		let {
			proCID,
			proCCode,
			proCDescripts,
			proCYBAreaID,
		} = this.state;
		let data = {}
		data = {
			params: [{
				proCID: proCID,
				proCCode: proCCode,
				proCDescripts: proCDescripts,
				proCYBAreaID: proCYBAreaID,
				updateUserID: sessionInfo.userID
			}],
		}
		$http.post('urlADS', this, {
			code: '05100116',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success('保存成功');
					this.getProconfigureData();
				}
			}
		})
	}

	handleProconfigureClear = () => {
		const { userData } = this.state;
		this.setState({
			proCID: '',
			proCCode: '',
			proCDescripts: '',
			proCYBAreaID: '',
			//子表数据
			data1: [],
			//子表数据
			proDID: '',
			proDCode: '',
			proDDescripts: '',
			proDValue: '',
			proDRemark: '',
			proDType: undefined,
			//孙子表数据
			data2: [],
			//孙子表数据
			proKID: '',
			proKHospID: userData?.hospID || undefined,
			proKCode: '',
			proKDescripts: '',
			proKLinkValue: undefined,
			proKLinkCode: '',
			proKRemark: '',
			//信息
			total1: 0,
			page1: 1,
			showLoading1: true,
			//信息
			total2: 0,
			page2: 1,
			showLoading2: true,
		});
	}

	//对子表的操作
	handleProconfigureDetailQuery = () => {
		this.setState({ page1: 1 }, () => {
			this.getProconfigureDetailData();
		})
	}

	getProconfigureDetailData = () => {
		if (this.state.proCID === "") {
			return;
		}
		let { page1, pageSize1, userData } = this.state;
		let data = {}
		data = {
			params: [{
				proCID: this.state.proCID,
				proDCode: this.state.proDCode,
				proDDescripts: this.state.proDDescripts,
			}],
			pagination: [{
				pageSize1: pageSize1,
				currentPage1: page1,
				sort: "ID",
				dir: "desc"
			}]
		}
		$http.post('urlS', this, {
			code: '05100107',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					for (var i = 0; i < res.proDArr.length; i++) {
						res.proDArr[i].key = i
					}
					this.setState({
						data1: res.proDArr,
						total1: res.total,
						data2: [],
						//孙子表数据
						proKID: '',
						proKHospID: userData?.hospID || undefined,
						proKCode: '',
						proKDescripts: '',
						proKLinkValue: undefined,
						proKLinkCode: '',
						proKRemark: '',
						//信息
						total2: 0,
						page2: 1,
						showLoading2: true
					})
				}
			}
		})
	}

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

	onClickProconfigureDetailRow = (record) => {
		//给右边的编辑form传值
		return {
			onClick: () => {
				if (this.state.proDID === "") {
					this.setState({
						proDID: record.proDID,
						proDCode: record.proDCode,
						proDDescripts: record.proDDescripts,
						proDValue: record.proDValue,
						proDRemark: record.proDRemark,
						proDType: record.proDType,
						proKID: '',
						proKHospID: this.state.userData?.hospID || undefined,
						proKCode: '',
						proKDescripts: '',
						proKLinkValue: undefined,
						proKLinkCode: '',
						proKRemark: '',
						page2: 1,
					}, () => {
						this.handleProconfigureLinkQuery();
						this.handleLinkSelect();
					});

				} else {
					if (this.state.proDID !== record.proDID) {
						this.setState({
							proDID: record.proDID,
							proDCode: record.proDCode,
							proDDescripts: record.proDDescripts,
							proDValue: record.proDValue,
							proDRemark: record.proDRemark,
							proDType: record.proDType,
							proKID: '',
							proKHospID: this.state.userData?.hospID || undefined,
							proKCode: '',
							proKDescripts: '',
							proKLinkValue: undefined,
							proKLinkCode: '',
							proKRemark: '',
							page2: 1,
						}, () => {
							this.handleProconfigureLinkQuery();
							this.handleLinkSelect();
						});
					} else {
						this.setState({
							proDID: '',
							proDCode: '',
							proDDescripts: '',
							proDValue: '',
							proDRemark: '',
							proDType: undefined,
							data2: [],
							//孙子表数据
							proKID: '',
							proKHospID: this.state.userData?.hospID || undefined,
							proKCode: '',
							proKDescripts: '',
							proKLinkValue: undefined,
							proKLinkCode: '',
							proKRemark: '',
							//信息
							total2: 0,
							page2: 1,
							showLoading2: true,
							linkSelect: [],
						});
					}
				}
			},
		};
	}

	handleProconfigureDetailSave = () => {
		if (this.state.proCID === "") {
			message.error("请选择左边的功能模块再做保存操作!!!");
			return;
		}
		let sessionInfo = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		let {
			proDID,
			proDCode,
			proDDescripts,
			proDValue,
			proDRemark,
			proDType,
		} = this.state;
		let data = {}
		data = {
			params: [{
				proCID: this.state.proCID,
				proDID: proDID,
				proDCode: proDCode,
				proDDescripts: proDDescripts,
				proDValue: proDValue,
				proDRemark: proDRemark,
				proDType: proDType,
				updateUserID: sessionInfo.userID
			}],
		}
		$http.post('urlADS', this, {
			code: '05100117',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success('保存成功');
					this.getProconfigureDetailData();
				}
			}
		})
	}

	handleProconfigureDetailClear = () => {
		const { userData } = this.state;
		this.setState({
			proDID: '',
			proDCode: '',
			proDDescripts: '',
			proDValue: '',
			proDRemark: '',
			proDType: undefined,
			//孙子表数据
			data2: [],
			//孙子表数据
			proKID: '',
			proKHospID: userData?.hospID || undefined,
			proKCode: '',
			proKDescripts: '',
			proKLinkValue: undefined,
			proKLinkCode: '',
			proKRemark: '',
			//信息
			total2: 0,
			page2: 1,
			showLoading2: true,
		});
	}

	///对孙子表的操作
	handleProconfigureLinkSave = () => {
		if (this.state.proDID === "") {
			message.error("请选择上面的参数再做保存操作!!!");
			return;
		}
		let sessionInfo = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		let {
			proDID,
			proKID,
			proKHospID,
			proKCode,
			proKDescripts,
			proKLinkValue,
			proKLinkCode,
			proKRemark
		} = this.state;
		let data = {}
		data = {
			params: [{
				proDID: proDID,
				proKID: proKID,
				proKHospID: proKHospID,
				proKCode: proKCode,
				proKDescripts: proKDescripts,
				proKLinkValue: proKLinkValue,
				proKLinkCode: proKLinkCode,
				proKRemark: proKRemark,
				updateUserID: sessionInfo.userID
			}],
		}
		$http.post('urlADS', this, {
			code: '05100118',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success('保存成功');
					this.handleProconfigureLinkQuery();
				}
			}
		})
	}

	// 查询
	handleProconfigureLinkQuery = () => {
		if (this.state.proDID === "") {
			return;
		}
		let {
			proDID,
			proKCode,
			proKDescripts,
			proKHospID,
			pageSize2,
			page2
		} = this.state;
		let data = {}
		data = {
			params: [{
				proDID: proDID,
				proKCode: proKCode,
				proKDescripts: proKDescripts,
				proKHospID
			}],
			pagination: [{
				pageSize: pageSize2,
				currentPage: page2
			}]
		}
		$http.post('urlS', this, {
			code: '05100111',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					let data2 = res?.proKArr || [];
					for (var i = 0; i < data2.length; i++) {
						data2[i].key = i
					}
					this.setState({
						data2,
						total2: res?.total || data2.length
					})
				} else {
					this.setState({
						data2: [],
						total2: 0
					})
				}
			},
			error: function (error) {
				console.log(error);
				this.setState({
					data2: [],
					total2: 0
				})
			}
		})
	}

	onClickProconfigureLinkRow = (record) => {
		//给右边的编辑form传值
		return {
			onClick: () => {
				if (this.state.proKID === "") {
					this.setState({
						proKID: record.proKID,
						proKHospID: record.proKHospID,
						proKCode: record.proKCode,
						proKDescripts: record.proKDescripts,
						proKLinkValue: record.proKLinkValue,
						proKLinkCode: record.proKLinkCode,
						proKRemark: record.proKRemark,
					});
				} else {
					if (this.state.proKID !== record.proKID) {
						this.setState({
							proKID: record.proKID,
							proKHospID: record.proKHospID,
							proKCode: record.proKCode,
							proKDescripts: record.proKDescripts,
							proKLinkValue: record.proKLinkValue,
							proKLinkCode: record.proKLinkCode,
							proKRemark: record.proKRemark,
						});
					} else {
						this.setState({
							proKID: '',
							proKHospID: this.state.userData?.hospID || undefined,
							proKCode: '',
							proKDescripts: '',
							proKLinkValue: undefined,
							proKLinkCode: '',
							proKRemark: '',
						});
					}
				}
			},
		};
	}

	handleProconfigureLinkClear = () => {
		const { userData } = this.state;
		this.setState({
			proKID: '',
			proKHospID: userData?.hospID || undefined,
			proKCode: '',
			proKDescripts: '',
			proKLinkValue: undefined,
			proKLinkCode: '',
			proKRemark: '',
		});
	}

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

	//删除
	handleProconfigureLinkDel = () => {
		if (this.state.proKID === "") {
			return;
		}
		let sessionInfo = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		let data = {}
		data = {
			params: [{
				proKID: this.state.proKID,
				updateUserID: sessionInfo.userID
			}],
		}
		$http.post('urlADS', this, {
			code: '05100114',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					message.success('删除成功');
					this.handleProconfigureLinkQuery();
				} else {
					return;
				}
			}
		})
	}

	// 医保地域
	handleYBAreaSelect = () => {
		let data = {}
		data = {
			params: [{
				proCCode: "CONTRAST",
			}]
		}
		$http.post('urlS', this, {
			code: '05100119',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.data) {
					this.setState({
						areaSelect: res?.data || []
					})
				}
			}
		})
	}

	// 模块
	handleModuleSelect = () => {
		let data = {}
		data = {
			params: [{
			}]
		}
		$http.post('urlS', this, {
			code: '05100120',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.data) {
					let moduleSelect = []
					for (var i = 0; i < res.data.length; i++) {
						moduleSelect.push(<Option key={res.data[i].id} alias={res.data[i].descriptsSPCode}>{res.data[i].descripts}</Option>)
					}
					this.setState({
						moduleSelect: moduleSelect
					})
				}
			}
		})
	}

	// 医院
	handleHospSelect = () => {
		let data = {}
		data = {
			params: [{
			}]
		}
		$http.post('urlS', this, {
			code: '01040078',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0 && res.data) {
					this.setState({
						hospSelect: res?.data || []
					})
				}
			}
		})
	}

	//关联值
	handleLinkSelect = () => {
		let { proKHospID } = this.state;
		let data = {
			params: [{
				proDID: this.state.proDID,
				hospID: proKHospID
			}]
		}
		$http.post('urlS', this, {
			code: '05100121',
			data: data,

			success: function (res) {
				if (res.flag === 1) {
					this.setState({
						showFlagInput: 'none',
						showFlagSelect: ''
					})
				} else {
					this.setState({
						showFlagInput: '',
						showFlagSelect: 'none'
					})
				}
				if (+res.errorCode === 0) {
					this.setState({
						linkSelect: res?.data || []
					})
				}
			}
		})
	}

	handlePageSize2Change = (page, pageSize) => {
		this.setState({
			page2: page,
			pageSize2: pageSize,
		}, () => {
			this.handleProconfigureLinkQuery();
		});
	}

	handleSize2Change = (current, size) => {
		this.setState({
			page2: 1,
			pageSize2: size,
		}, () => {
			this.handleProconfigureLinkQuery();
		});
	}

	render() {
		let { columnsBTotalWidth, columnsCTotalWidth, proKHospID } = this.state;
		console.log('proKHospID', proKHospID)
		return (
			<Row className="table-body-height">
				<Col span={10}>
					<div style={{ paddingRight: '6px', position: 'relative', height: '100%' }}>
						<Card
							size="small"
							bordered={false}
							title={(
								<div className="card-title-left-img">
									<img src={iconListvisits} alt="" />
									医保基础配置设置界面
								</div>
							)}
						>
							<div style={{ marginBottom: 12 }}>
								<Input
									placeholder="代码"
									value={this.state.proCCode}
									className="common-query-input"
									style={{ marginRight: '6px' }}
									onChange={this.onChangeProconfigureCode}
								/>
								<Input
									placeholder="描述"
									value={this.state.proCDescripts}
									className="common-query-input"
									style={{ marginRight: '6px' }}
									onChange={this.onChangeProconfigureDescripts}
								/>
								<Select
									showSearch
									allowClear={true}
									placeholder="医保地域"
									optionFilterProp="seachprop"
									onChange={this.onChangeProconfigureYBArea}
									value={this.state.proCYBAreaID}
									style={{ width: '120px', marginRight: '8px' }}
								>
									{React.$SelectOptions(this.state.areaSelect)}
								</Select>
								<Button style={{ background: 'rgba(100,169,130,1)', color: '#ffffff' }} onClick={this.handleProconfigureQuery}>查询</Button>
								<Button style={{ margin: '0 8px', background: 'rgba(100,169,130,1)', color: '#ffffff' }} onClick={this.handleProconfigureSave}>保存</Button>
								<Button onClick={this.handleProconfigureClear}>清空</Button>
							</div>
							<Table
								dataSource={this.state.data}
								columns={this.state.columnsA}
								rowClassName={this.setProconfigureRowClassName}
								pagination={false}
								bordered
								onRow={this.onClickProconfigureRow}
								rowKey="ID"
								style={{ height: store.getState().tableHeight.y + 99 + 'px' }}
								scroll={{ x: true, y: store.getState().tableHeight.y + 49 }}
							/>
							<CommonPagination size="small" pageSize="20" current={this.state.page} total={this.state.total} search='search'
								onShowSizeChange={this.apponShowSizeChange} complete={true} dataSource={this.state.data}
								onChange={this.appPageChange} />
							<ColumnAuthoritysModel
								clientWidth='900px'
								compontName='InsuBaseConfiguresNewMInsu'
								configType="C"
								onRef={this.onColumnRef}
								reloadData={this.tableList}
							/>
						</Card>
						<div className="common-card-right-split-line" style={{ width: 8 }}></div>
					</div>
				</Col>
				<Col span={14}>
					<Card bordered={false} bodyStyle={{ padding: '12px' }}>
						<div style={{ marginBottom: '12px' }}>
							<Input
								placeholder="代码"
								value={this.state.proDCode}
								className="common-query-input"
								style={{ marginRight: '6px' }}
								onChange={this.onChangeProconfigureDetailCode}
							/>
							<Input
								placeholder="描述"
								value={this.state.proDDescripts}
								className="common-query-input"
								style={{ marginRight: '6px' }}
								onChange={this.onChangeProconfigureDetailDescripts}
							/>
							{/*<Input placeholder="值" value={this.state.proDValue} style={{width: '10%', marginLeft: '2px'}} onChange={this.onChangeProconfigureDetailValue} />*/}
							<Select
								showSearch
								allowClear={true}
								placeholder="请输入"
								optionFilterProp="children"
								className="common-query-input"
								style={{ marginRight: '6px' }}
								value={this.state.proDType}
								onChange={this.onChangeProconfigureDetailType}
							>
								<Option value="String" title='inputType'>String</Option>
								<Option value="User" title='inputType'>User</Option>
							</Select>
							<Input placeholder="备注" value={this.state.proDRemark} className="common-query-input" onChange={this.onChangeProconfigureDetailRemark} />
							{/*<Select
                                    showSearch
                                    allowClear={true}
                                    placeholder="医保地域"
                                    optionFilterProp="children"
                                    onChange={this.onChangeProconfigureDetailYBArea}
                                    value={this.state.proDYBArea}
                                    style={{width: '20%', marginLeft: '2px'}}
                                    filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                   >{this.state.areaSelect}</Select>*/}
							{/*<Input placeholder="医保地域" value={this.state.proDYBArea} style={{width: '15%', marginLeft: '2px'}} onChange={this.onChangeProconfigureDetailYBArea} />*/}
							<Button style={{ background: 'rgba(100,169,130,1)', color: '#ffffff' }} onClick={this.handleProconfigureDetailQuery}>查询</Button>
							<Button style={{ margin: '0 12px', background: 'rgba(100,169,130,1)', color: '#ffffff' }} onClick={this.handleProconfigureDetailSave}>保存</Button>
							<Button onClick={this.handleProconfigureDetailClear}>清空</Button>
						</div>
						<Table
							dataSource={this.state.data1}
							columns={this.state.columnsB}
							rowClassName={this.setProconfigureDetailRowClassName}
							pagination={false}
							bordered
							onRow={this.onClickProconfigureDetailRow}
							rowKey="ID"
							scroll={{ x: columnsBTotalWidth, y: store.getState().tableHeight.y / 2 - 40 }}
							style={{ height: store.getState().tableHeight.y / 2 + 10 + 'px' }}
						/>
						{/* 分页: total1--总条数  defaultCurrent1--默认的当前页 hideOnSinglePage1--只有一页时隐藏分页器 */}
						<CommonPagination
							size="small"
							pageSize="20"
							search="search"
							complete={true}
							current={this.state.page1}
							total={this.state.total1}
							dataSource={this.state.data1}
							onShowSizeChange={this.proponShowSizeChange}
							onChange={this.propPageChange}
						/>
						<ColumnAuthoritysModel
							clientWidth='900px'
							compontName='InsuBaseConfiguresNewDetail'
							configType="C"
							onRef={this.onColumnRef}
							reloadData={this.tableList}
						/>
					</Card>
					<div className="common-query-split-line" style={{ height: 8 }}></div>
					<Card bordered={false} bodyStyle={{ padding: '12px' }}>
						<div style={{ marginBottom: '12px' }}>
							<Input
								placeholder="代码"
								value={this.state.proKCode}
								className="common-query-input"
								style={{ marginRight: '6px' }}
								onChange={this.onChangeProconfigureLinkCode}
							/>
							<Input
								placeholder="描述"
								value={this.state.proKDescripts}
								className="common-query-input"
								style={{ marginRight: '6px' }}
								onChange={this.onChangeProconfigureLinkDescripts}
							/>
							<Select
								showSearch
								allowClear={true}
								placeholder="关联值"
								optionFilterProp="seachprop"
								onChange={this.onChangeProconfigureLinkLinkValues}
								value={this.state.proKLinkValue}
								className="common-query-input"
								style={{ display: this.state.showFlagSelect }}
							>
								{React.$SelectOptions(this.state.linkSelect)}
							</Select>
							<Input
								placeholder="关联值"
								className="common-query-input"
								type="text"
								value={this.state.proKLinkValue}
								style={{ display: this.state.showFlagInput, marginRight: '6px' }}
								onChange={this.onChangeProconfigureLinkLinkValue}
							/>
							{/*<Input placeholder="关联代码" value={this.state.proKLinkCode} style={{width: '10%', marginLeft: '2px'}} onChange={this.onChangeProconfigureLinkLinkCode} />
                                        <Input placeholder="备注" value={this.state.proKRemark} style={{width: '15%', marginLeft: '2px'}} onChange={this.onChangeProconfigureLinkRemark} />*/}
							<Select
								showSearch
								allowClear={true}
								placeholder="医院"
								optionFilterProp="seachprop"
								onChange={this.onChangeProconfigureLinkHospID}
								value={this.state.proKHospID}
								className="common-query-input"
							>
								{React.$SelectOptions(this.state.hospSelect)}
							</Select>
							{/*<Input placeholder="医院" value={this.state.proKHospID} style={{width: '20%', marginLeft: '2px'}} onChange={this.onChangeProconfigureLinkHospID} />*/}
							<Button style={{ background: 'rgba(100,169,130,1)', color: '#ffffff' }} onClick={this.handleProconfigureLinkQuery}>查询</Button>
							<Button style={{ margin: '0 12px', background: 'rgba(100,169,130,1)', color: '#ffffff' }} onClick={this.handleProconfigureLinkSave}>保存</Button>
							<Button ghost type="danger" onClick={this.handleProconfigureLinkDel}>删除</Button>
							<Button style={{ marginLeft: '12px' }} onClick={this.handleProconfigureLinkClear}>清空</Button>
						</div>
						<Table
							dataSource={this.state.data2}
							columns={this.state.columnsC}
							rowClassName={this.setProconfigureLinkRowClassName}
							pagination={false}
							bordered
							onRow={this.onClickProconfigureLinkRow}
							rowKey="ID"
							style={{ height: store.getState().tableHeight.y / 2 + 10 + 'px' }}
							scroll={{ x: columnsCTotalWidth, y: store.getState().tableHeight.y / 2 - 40 }}
						/>
						<CommonPagination
							size="small"
							search="search"
							pageSize="20"
							complete={true}
							dataSource={this.state.data2}
							current={this.state.page2}
							total={this.state.total2}
							onShowSizeChange={this.handleSize2Change}
							onChange={this.handlePageSize2Change}
						/>
						<ColumnAuthoritysModel
							clientWidth='900px'
							compontName='InsuBaseConfiguresNewLinkValue'
							configType="C"
							onRef={this.onColumnRef}
							reloadData={this.tableList}
						/>
					</Card>
				</Col>

				<Modal title="配置复制"
					visible={this.state.modalSetVisible}
					onCancel={() => this.modalHandleCancel('N')}
					onOk={() => this.modalHandleCancel('Y')}
					width='900px'>
					<Row style={{ paddingLeft: '150px' }}>
						<p>请选择要从哪个配置项进行数据复制，将覆盖当前配置项内容，请谨慎操作！！！</p>
						<Select
							showSearch
							style={{ width: 600, marginTop: '6px' }}
							allowClear={true}
							placeholder="选择复制源"
							optionFilterProp="children"
							value={this.state.copySettingCode}
							onChange={(e) => this.onCopySelectChange(e)}>
							{this.state.data && this.state.data.map((item, index) => {
								return <Option value={item.proCCode}>{item.proCDescripts}</Option>
							})}
						</Select>
					</Row>
					<Row style={{ paddingLeft: '150px', marginTop: '30px' }}>
						<p>请选择配置项数据希望归属的医院，如不选则复制的数据医院属性不变。</p>
						<Select
							showSearch
							style={{ width: 600, marginTop: '6px' }}
							allowClear={true}
							placeholder="添加医院属性"
							optionFilterProp="seachprop"
							value={this.state.hospCode}
							onChange={(e) => this.onhospSelectChange(e)}>
							{this.state.hospSelect && this.state.hospSelect.map((item, index) => {
								return <Option value={item.code}>{item.descripts}</Option>
							})}
						</Select>
					</Row>
				</Modal>
			</Row>
		)
	}
};

export default InsuBaseConfiguresNew;
