/**
 * 只包含一站式流程的申请页面 会带部分字段参数到申请表单
 * 返回也是返回到上一个路由
 * */

import { message } from 'antd';
import React  from 'react';
import { getToken } from '@/utils/authority';

import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import Shell from '@/baseComponent/Shell';
import router from 'umi/router';
import ApplyForZyd from '@/webPublic/one_stop_public/ForZydApply/index';


export default class AffairPage extends React.Component {
	constructor(props) {
		super(props);
		let state = this.props.location.state;
		if (!state || !state.id) {
			console.error('无法获取流程id', 'JustApply.js');
		}
		this.state = {
			workId: state.id,
			init: { ...state },
		};
	}

	componentDidMount() {
		if (!getToken()) {
			message.error('您的数据未同步,请联系管理员!');
			return false;
		}
		// window.addEventListener(
		// 	'message',
		// 	(event) => {
		// 		// 和Iframe页进行通迅
		// 		if (event.data === 'returnList') {
		// 			this.returnList(true);
		// 		}
		// 		if (event && event.data && event.data.indexOf && event.data.indexOf('iframeHeight') > -1) {
		// 			let height = Number(event.data.split('-')[1]);
		// 			const iframe = document.getElementById('applyIframeId');
		// 			if (iframe) {
		// 				iframe.height = height;
		// 			}
		// 		}
		// 	},
		// 	false,
		// );

		return true;
	}

	returnList = () => {
		router.goBack();
	};

	render() {
		const { workId, init } = this.state;
		if (!workId) {
			return null;
		}
		return (
			<PageHeaderWrapper title="">
				<div
					style={{
						visibility: 'visible',
						backgroundColor: '#fff',
						paddingLeft: '24px',
					}}>
					<Shell>
						<div
							style={{
								height: '54px',
								padding: '12px 0 12px 12px',
								display: 'block',
							}}>
							<ButtonDiy
								name="返回"
								className="defaultBlue"
								handleClick={this.returnList}
								icon="arrow-left"
							/>
						</div>
					</Shell>
         <ApplyForZyd
           {...this.props}
           id={workId}
           returnList={this.returnList}
           init={encodeURIComponent(JSON.stringify(init))}
         />
				{/*	<iframe
						src={iframeUrl}
						frameBorder={0}
						id="applyIframeId"
						name="applyIframe"
						marginWidth="0"
						marginHeight="0"
						allowtransparency="yes"
						seamless
						scrolling={'auto'}
						style={{
							width: '100%',
							minHeight: '800px',
							overflowY: 'hidden',
							backgroundColor: '#fff',
						}}
					/>*/}
					: null
				</div>
			</PageHeaderWrapper>
		);
	}
}
