// 首页
import React from 'react';
// import store from 'store';
import moment from 'moment';

export default class Header extends React.Component {
	constructor(props) {
		super(props);
		this.state = {

		}
	}
	// componentDidMount() {
	// 	window.addEventListener('message', this.handleIframePostMessage)
	// }

	// handleIframePostMessage(event) {
	// 	console.log(event)
	// 	// if (event.origin !== "http://192.168.5.120:3001") return;
	// }

	handleAdd() {
		// var ret = window.showModalDialog("child.htm", null, "dialogWidth:350px;dialogHeight:350px;help:no;status:no");
		// if (ret) {
		//   console.log(ret)
		// } else {
		//     alert('子窗口返回假!');
		// }
		// let url = "http://192.168.5.120:3001";
		// window.open(url, " ", "height=800,width=800,left=190,top=10,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no ");
	}

	// 触发下载任务列表查询
	handleClick = () => {
		// store.dispatch({
		// 	type: 'downloadTask',
		// 	value: new Date().getTime()
		// })

		// 事前调阅
		// const data = {
		// 	apiName: 'ims-svc-beforeAccess',
		// 	apiVersion: '1.0.0',
		// 	timeStamp: '1628478580227',
		// 	accessKey: '65ce75d08e8744fd8a9978daa3d5dc86',
		// 	secretKey: '09kEgZIHYDuwn@Ay/eFCESykZB0=',
		// 	formParamMap: null,
		// 	body: ''
		// };

		// fetch('http://172.18.1.130/CSB', {
		// 	method: 'POST',
		// 	headers: {
		// 		'Content-Type': 'application/json',
		// 		'_api_name': 'ims-svc',
		// 		'_api_version': '1.0.0'
		// 	},
		// 	body: JSON.stringify(data)
		// })
		// 	.then(response => response.json())
		// 	.then(result => {
		// 		console.log('Response:', result);
		// 	})
		// 	.catch(error => {
		// 		console.error('Error:', error);
		// 	});
	}

	/**
	 *  生成唯一的uuid
	 * @returns {string} uuid
	 */
	uuid = () => {
		const res = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
			const r = Math.random() * 16 | 0;
			const v = c == 'x' ? r : (r & 0x3 | 0x8);
			return v.toString(16);
		});
		return `uuid${res}`;
	};

	// 360视图
	handle360View = () => {
		// 安装 sm-crypto
		let titleData = React.$getSessionData('titleData');
		let appid = '4d4596b8e3fc4691aa2545aeb847566e';
		let guid = this.uuid();
		let path = 'Patient360View';
		let timestamp = moment().valueOf();
		let secret = 'IqnSH2an84V6Dde9ErI23OKbY4f5dvKg'; // 授权秘钥
		let patientId = titleData?.patID || '';
		let data = {
			patientId: patientId,
			admNo: titleData?.admID || '',
			admTypeCode: titleData?.admTypeCode || '',
			outPatientNo: titleData?.patNo || '',
			inPatientNo: titleData?.patNo || '',
		}

		const digest = 'appid=' + appid + '&guid=' + guid + '&timestamp=' + timestamp + '&data=' + JSON.stringify(data) + '&secret=' + secret;
		const digestSM3 = sm3(digest);
		console.log('sm3', sm3);
		let urlPath = 'http://ip:port/adapter?appid=' + appid + '&path=' + path + '&operator=admin&timestamp=' + timestamp + '&patientId=' + patientId + '&digest=' + digestSM3;
		window.open(urlPath);
	};

	render() {
		return (
			<div onClick={this.handleClick}>
				首页
				{/* <Input id="my-iframe-id" />
				<button onClick={this.handleAdd}>按钮1</button>

				<iframe
					allowFullScreen={true}
					scrolling={'no'}
					src="http://192.168.5.120:3001"
				/> */}
			</div>
		)
	}
}