(this["webpackJsonpmr-julyedu"]=this["webpackJsonpmr-julyedu"]||[]).push([[41],{1628:function(e,t,a){"use strict";a.r(t);a(25);var s=a(4),r=a.n(s),i=a(0),n=a.n(i),c=(a(924),a(18)),l=a(1),o=a(465),d=a.n(o);class m extends i.Component{constructor(e){super(e),this.initCanvas=(e,t)=>{let a=this,s=e[t].poster,r=450*e[t].header_position_x,i=800*e[t].header_position_y-18,n=450*e[t].qr_code_x,c=800*e[t].qr_code_y+7;var l=document.getElementById("canvas"),o=l.getContext("2d");a.getBase64(s).then(s=>{let l=new Image;l.src=s;let d=document.getElementById("qrcode");(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)||/(Android)/i.test(navigator.userAgent))&&(d=document.getElementById("qrcode")),l.setAttribute("crossOrigin","anonymous"),l.onload=function(){o.drawImage(l,0,0,450,800),o.drawImage(d,n,c,100,100),o.fillStyle=e[t].username_color,o.font="16px serif",o.fillText("@"+a.state.name,r+50+20,i+25),o.font="14px serif",o.fillText("\u6b63\u5728\u5b66\u4e60\u8be5\u8bfe\u7a0b",r+50+20,i+25+20),o.restore()}}).then(()=>{a.getBase64(a.state.imgUrl).then(e=>{let t=new Image;t.src=e,t.setAttribute("crossOrigin","anonymous"),t.setAttribute("border-Radius","50%"),t.onload=function(){a.imgPosition(o,t,r,i,24),o.drawImage(t,r,i,48,48),o.restore(),a.setState({billSrc:a.convertCanvasToImage(l)})}})})},this.children=(e,t)=>{var a=e.childNodes,s=[];if(/MSIE(6|7|8)/.test(navigator.userAgent))for(var r=0;r<a.length;r++){var i=a[r];1===i.nodeType&&(s[s.length]=i)}else s=Array.prototype.slice.call(e.children);if("string"===typeof t)for(var n=0;n<s.length;n++)(e=s[n]).nodeName.toLowerCase()!==t.toLowerCase()&&(s.splice(n,1),n--);return s},this.imgPosition=(e,t,a,s,r)=>{e.save();var i=a+r,n=s+r;e.beginPath(),e.arc(i,n,r,0,2*Math.PI),e.clip()},this.getBase64Image=e=>{let t=document.createElement("canvas");t.width=e.width,t.height=e.height,t.getContext("2d").drawImage(e,0,0,e.width,e.height);let a=e.src.substring(e.src.lastIndexOf(".")+1).toLowerCase();return t.toDataURL("image/"+a)},this.convertCanvasToImage=e=>{let t=new Image;return t.src=e.toDataURL("image/png"),t},this.squareClick=e=>{this.setState({smallactive:e}),this.initCanvas(this.state.bgImage,e)},this.state={codeSrc:"",billSrc:"",imgUrl:"",smallListImg:[],smallactive:0,distPrice:"",name:"",bgImage:[]}}componentDidMount(){this.getCodeWe(),l.f.get(`${API.home}/m/dist/posters/${Object(l.c)("courseId")}/${Object(l.c)("uid")}`).then(e=>{200===e.data.code?(this.setState({imgUrl:e.data.data.avatar,smallListImg:e.data.data.list,distPrice:e.data.data.dist_course,bgImage:e.data.data.list,name:e.data.data.username}),this.initCanvas(this.state.bgImage,0)):r.a.info(e.data.msg,2)})}getCodeWe(){let e=this,t=`https://m.julyedu.com/detail?id=${Object(l.c)("courseId")}&dist_code=${Object(l.c)("dist_code")}`;return new Promise(a=>{d.a.toDataURL(t,{},(function(t,a){e.setState({codeSrc:a})})),a()})}getBase64(e){let t=this;return new Promise(a=>{let s=null,r=new Image,i=+new Date;r.setAttribute("crossOrigin","anonymous"),r.src=e+"?"+i,r.onload=()=>{s=t.getBase64Image(r),a(s)},r.onerror=function(){let a=+new Date;t.getBase64(e+"?"+a)}})}render(){const{distPrice:e={},smallListImg:t=[],smallactive:a}=this.state;return n.a.createElement("div",{className:"share-poster"},n.a.createElement(c.e,{title:"\u751f\u6210\u4e13\u5c5e\u6d77\u62a5",arrow:!0,cart:!1}),n.a.createElement("div",{className:"total-container"},n.a.createElement("div",{className:"placard-img-container",id:"imgWrapper"},n.a.createElement("img",{src:this.state.billSrc.src,alt:""})),n.a.createElement("img",{src:this.state.codeSrc,alt:"",id:"qrcode",className:"placard-code"}),n.a.createElement("canvas",{id:"canvas",width:"450",height:"800",className:""===this.state.billSrc?"":"hide"})),n.a.createElement("div",{className:"placard-desc"},n.a.createElement("span",{className:"placard-sharetxt"},"\u957f\u6309\u4fdd\u5b58\u6d77\u62a5\u5206\u4eab\u7ed9\u597d\u53cb\uff0c\u6bcf\u6709\u4e00\u4eba\u901a\u8fc7\u60a8\u7684\u5206\u4eab\u8d2d\u4e70\u8be5\u8bfe\u7a0b\uff0c\u60a8\u53ef\u4ee5",0===e.count_type&&n.a.createElement("span",{className:"placard-price"},"\u83b7\u5f97",e.first_level_tip,"\u5143\u7684\u4f63\u91d1\u5956\u52b1\u3002"),1===e.count_type&&n.a.createElement("span",{className:"placard-price"},"\u83b7\u5f97\u6210\u4ea4\u91d1\u989d\u7684",e.first_level_scale,"%\u4f5c\u4e3a\u4f63\u91d1\u5956\u52b1\u3002"))),n.a.createElement("div",{className:"placard-swiper"},n.a.createElement("ul",{className:"placard-list"},t.length>0&&t.map((e,t)=>n.a.createElement("li",{onClick:this.squareClick.bind(this,t),key:t,className:a===t?"active":""},n.a.createElement("img",{src:e.square,alt:""}))))))}}t.default=m},924:function(e,t,a){}}]);
//# sourceMappingURL=shareposter.ac1347c2.chunk.js.map