// 润乾报表公共组件
import React from 'react';
import { $http } from 'containers/config/https';
class reports extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            url:'',
        }
    }

    componentDidMount(){
        this.getRaqSoftPath();
    }

    /**
     * @ByYQL: 报表配置走新路径配置，入参增加appCode:'newRaqsoft'，没有则表示走之前的配置数据
     * Create 2023-3-27
     */
    //获取润乾服务器路径
    getRaqSoftPath = () => {
        $http.post('urlS', this, {
            code: "01040114",
            data:  {
                params: [{appCode:'newRaqsoft'}]
            },
            success: function (res) {
                if(res.errorCode==0){
                    let raqName='';
                    if(this.props.location){
                        if(this.props.location.state.raqName){
                            raqName= this.props.location.state.raqName ? this.props.location.state.raqName:"";
                        }
                    }else{
                        raqName = this.props.paras.raqName ? this.props.paras.raqName:"";
                    }
                    if (raqName.indexOf(".rpx") === -1) {
                        raqName=raqName+".rpx";
                    }
                    let session = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
                    let sessionUserID=session.userID;
                    let sessionUserName=session.userName;
                    let sessionLocID=session.locID;
                    let sessionLocDesc=session.locDesc;
                    let sessionGroupID=session.groupID;
                    let sessionGroupDesc=session.groupDesc;
                    let sessionHospID=session.hospDesc;
                    let sessionHospDesc=session.hospDesc;
                    let sessionNowHospID=session.hospID;

                    /**
                     * @ByYQL: 报表链接新增病人入参 admID、patID
                     * Create 2022-3-4
                     */
                    let sessionPatientData = window.sessionStorage.patientData ? JSON.parse(window.sessionStorage.patientData) : {};
                    let _admID = sessionPatientData.admID || '';
                    let _patID = sessionPatientData.patID || '';

                    let sessionStr="&sessionUserID="+sessionUserID+"&sessionUserName="+sessionUserName+"&sessionLocID="+sessionLocID+"&sessionLocDesc="+sessionLocDesc+"&sessionGroupID="+sessionGroupID+"&sessionGroupDesc="+sessionGroupDesc+"&sessionHospID="+sessionHospID+"&sessionHospDesc="+sessionHospDesc+"&sessionNowHospID="+sessionNowHospID+"&sessionAdmID="+_admID+"&sessionPatID="+_patID;
                    let splitUrl='';
                    if(res.result.path.indexOf("//")>-1) {
                        let newUrl=res.result.path.split("//")[1];
                        if(newUrl.indexOf("/")>-1){
                            for(var i=1;i<newUrl.split("/").length;i++){
                                splitUrl=splitUrl+"/"+newUrl.split("/")[i];
                                // if(splitUrl===''){
                                //     splitUrl=newUrl.split("/")[i];
                                // }else{
                                //     splitUrl=splitUrl+"/"+newUrl.split("/")[i];
                                // }
                            }
                        }else{
                            splitUrl="/"+newUrl;
                        }
                    }else {
                        splitUrl=res.result.path;
                    }
                    let path=window.location.protocol+"//"+window.location.host+splitUrl;
                    console.log("path",path)
                    // let path=res.result.path
                    this.setState({
                        url: path+'?rpx='+raqName+sessionStr,
                    })
                }else {
                    message.error("没数据");
                }
            }
        });
    }

    render() {
        return (
            <div style={{height:'99%'}}>
                <iframe
                    style={{width:'100%',border:'0px',height:'100%'}}
                    // sandbox="allow-scripts allow-forms allow-same-origin"
                    scrolling="auto"
                    src={this.state.url}
                />
            </div>
        );
    }
};
export default reports;
