SealTemplateWrap.js 13.1 KB
import React,{PropTypes} from 'react';  
import cx from 'classnames'; 
import { 
    message,
} from 'antd';


class SealTemplateWrap extends React.Component {
	constructor(props) {
        super(props) 
        this.setSeal = this.setSeal.bind(this);
        this.js_getDPI = this.js_getDPI.bind(this);
        this.px2pt = this.px2pt.bind(this);
        this.changePXY = this.changePXY.bind(this);
        this.state = { 
        }
    }
    static propTypes = {  
        template: PropTypes.string, 
        onChange:PropTypes.func,
        sealImg:PropTypes.string
    }
    static defaultProps = {   
        template:'<p class="f14 t2 lh26 s-c666 mt10" style="font-family: tahoma, 微软雅黑; margin-top: 10px !important; font-size: 14px !important; text-indent: 2em !important; color: rgb(102, 102, 102) !important;">离职证明</p><p class="f14 t2 lh26 s-c666 mt10" style="font-family: tahoma, 微软雅黑; margin-top: 10px !important; font-size: 14px !important; text-indent: 2em !important; color: rgb(102, 102, 102) !important;">某某先生/女士/小姐自XX年01月01日入职我公司担任人力资源部人力资源助理职务,至2011年07月31日因个人原因申请离职,在此间无不良表现,经公司研究决定,同意其离职,已办理离职手续。</p><p class="f14 t2 lh26 s-c666 mt10" style="font-family: tahoma, 微软雅黑; margin-top: 10px !important; font-size: 14px !important; text-indent: 2em !important; color: rgb(102, 102, 102) !important;">因未签订相关保密协议,遵从择业自由。</p><p class="f14 t2 lh26 s-c666 mt10" style="font-family: tahoma, 微软雅黑; margin-top: 10px !important; font-size: 14px !important; text-indent: 2em !important; color: rgb(102, 102, 102) !important;">特此证明</p><p class="f14 t2 lh26 s-c666 mt10" style="font-family: tahoma, 微软雅黑; margin-top: 10px !important; font-size: 14px !important; text-indent: 2em !important; color: rgb(102, 102, 102) !important;">公司名称(加盖<a class="custom_field_seal" data-field="签章位置" data-field-type="seal" data-field-system="1" data-field-owner="1" style="background-color: rgb(255, 255, 255); font-family: BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 12px;"> </a><span style="text-indent: 2em;">公章)</span></p><p class="f14 t2 lh26 s-c666 mt10" style="font-family: tahoma, 微软雅黑; margin-top: 10px !important; font-size: 14px !important; text-indent: 2em !important; color: rgb(102, 102, 102) !important;">2011年07月31日</p>',
        sealImg:'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfAAAAHwCAMAAABucs3UAAAADFBMVEX/////AAAAAP8AAABvxgj3AAAAAXRSTlMAQObYZgAAFh9JREFUeNrtndmi5CgORB2k//+XY3pu3cW7WQQIJD/0VNVkpoWOQhIY28vih6kDxkdMB25+eHSPmBwY3S8WR0R3j8mx0J1kcBR0V9kbAd1d9qynu8ye6XSv2TOb7jl7JtO9Z85cugfN2Up3ojlL6W5UbCarjJ0OXIONVHsuBy5rIIc7qwPPNI+TnN4acChxNWZijlkMozKD6MDrmUWVZtGB1zCKio2jA5c1ifqdRgcuZBBHcRwdeLE5HMt5dOAlxtAjdBLgGI72iGEKx23LeAxjhvJF6lFGAPeVrWFgABPG2U8C/chhCjdoPnyh+/SUPh1v/jLumIYCjsauwfY3Uc/30IschnB/n5ENiL+MjRaB91ABloPEK7peKXLoPHG96sqHv1tAvtrB3fzg4zBBOwpHJ9pXCq8cXdAW2B9lvLm04723BO1HC1hQOLqF/CVw9p2kNRf5agb3u121qupTLUfrUUPN6ZrsM2avblFNoAczvGNOUy/8SSWigx3c0LuMzSmB9x4vNF+pambZxxLv/ge6WwcjuN8EDvZ2BKdSeO9hvkW2gsrWaBUGRng/L6OivSkdW1cLuH+MYEY0zOUQ9DtF05Z5y1uBQf2Qf2zw3lsBBRdg0UmAMIH7xwxNF9o7eQYmeGsE3sk5oceQaO7lUUlgMSrwu5kle2iJGqankYGPMYFrSecxJ4WulytgROCK0jliPqCLeDVr1ta8+5dLXU85udsOU2txPxjgfZh2d+mV1KT1T0veXXdiK37IKBoSD9PzXvTf2HDT12AU4NcdB513qokYA7gyeY9x41Iz4mF63nEm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xxnB8WmrGAPcXbZCFu6zNj7kSMa64+axGuM5TxPz4QxWd79PpD0jtT8c0cEaLeIQbuOo7tVpE532BMATrVK76ZPDu1avXdRnE6dwrGbTaMaYSYHnGccJbTADvMC+fu/h5ZwOHcREDnFCB17HStb2As240u2c6Jq9mzoP7WW0Z2fBcdsCrtFguv/sGE33nR3D6X6zYzvdaXbspzvMzhjozrIzELqfjAyH7iEro6K7xsjY6E6Zf5z+OjU/Zjz+B7Ye3G8dHA0KAAAAAElFTkSuQmCC',
        onChange:(top,bottom,left,page)=>{
            console.log(top,bottom,left,page);
        }
    } 
    componentDidUpdate(){
        $('.custom_field_seal', $('#seal_template_wrap')).addClass("hidden_template_seal");
    }
    js_getDPI(){
        const arrDPI = new Array();
        if (window.screen.deviceXDPI != undefined) {
            arrDPI[0] = window.screen.deviceXDPI;
            arrDPI[1] = window.screen.deviceYDPI;
        }
        else {
            const tmpNode = document.createElement("DIV");
            tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
            document.body.appendChild(tmpNode);
            arrDPI[0] = parseInt(tmpNode.offsetWidth);
            arrDPI[1] = parseInt(tmpNode.offsetHeight);
            tmpNode.parentNode.removeChild(tmpNode);
        }
        return arrDPI[0];
    }
    px2pt(px){
        const  pt = px*72/this.js_getDPI();
        return pt;
    }
    changePXY(top,left){
        const arrA4 = new Array();
        const tmpNode = document.createElement("DIV");
        tmpNode.style.cssText = "width:210mm;height:297mm;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
        document.body.appendChild(tmpNode);
        arrA4[0] = parseInt(tmpNode.offsetWidth);
        arrA4[1] = parseInt(tmpNode.offsetHeight);
        tmpNode.parentNode.removeChild(tmpNode);
        const page = parseInt(top/arrA4[1]);
        const pageTop = page==0?top:top-arrA4[1]*page;
        const pageBottom = arrA4[1]-pageTop;
        return {
            pageBottom:this.px2pt(pageBottom),
            pageTop:this.px2pt(pageTop),
            pageLeft:this.px2pt(left),
            page:page+1
        }
    }
    setSeal(){
        const { sealImg,onChange } = this.props;
        let templateOffset='';
        if($('.custom_field_seal',$('#seal_template_wrap'))){
            templateOffset = $('.custom_field_seal',$('#seal_template_wrap')).offset();
        }else{
            return 	message.error('该证明模板未设置签章位置');
        }

        const sealOffset = $('#seal_template_wrap').offset();
        const top = templateOffset.top-sealOffset.top;
        const left = templateOffset.left-sealOffset.left;
        const {pageBottom,page,pageTop,pageLeft} = this.changePXY(top,left);
        const sealTemplate = `<img id="seal-one" style="width: 4.3cm;position: absolute;transform: translate(-50%, -50%);top:${top}px;left:${left}px;" src="${sealImg}">`;
        $('#seal-one',$('#seal_template_wrap')).remove(); 
        $('#seal_template_wrap').append(sealTemplate);
        // console.log($('.custom_field_seal',$('#seal_template_wrap')).offset());
        // console.log($('#seal_template_wrap').offset());
        onChange(pageTop,pageBottom,pageLeft,page);
    }
    render() {
        const { template } = this.props;
        return (
            <div id={'seal_template_wrap'}  dangerouslySetInnerHTML={{__html: `${template}`}} >

            </div>
        )
    }
}
 


export default SealTemplateWrap;