YUI.Env.PAY_CENTER={};YUI({combine:true}).use("node-event-simulate","cert","io","until","transition","stat",function(Y){var G_CGI={gen_qrcode:"https://www.tenpay.com/app/wsm/gen_qrcode.cgi?random={random}&code={code}",wsm_qry_paystatus:"https://www.tenpay.com/app/wsm/wsm_qry_paystatus.cgi"};var Qrcode={config:{unLogin:""},timeout:500,second:5,transitionTime:0.5,transitionEffect:"ease-out",queryTimeout:3000,status:1,stopQueryStatus:false,return_url:"",drawQRcode:function(QrImg,Qrstatus,url){QrImg.set("src",url);if(Qrstatus){Qrstatus.addClass("info-loading");QrImg.on("error",function(){Qrstatus.removeClass("info-loading");Qrstatus.addClass("info-offdue");Qrcode.stopQueryStatus=true});QrImg.on("load",function(){Qrstatus.removeClass("info-offdue");Qrstatus.removeClass("info-overdue");Qrstatus.removeClass("info-loading");Qrstatus.addClass("info-tdcode");Qrcode.stopQueryStatus=false})}},watchPayStatus:function(){if(!Qrcode.stopQueryStatus){setTimeout(function(){Qrcode.queryPayStatus()},Qrcode.queryTimeout)}},queryPayStatus:function(){var qr=payPara.transInfoArray[0]["sCode"].match(/\?(.)*/)[0];var code=Y.util.url.getPara("p",qr);var url=G_CGI.wsm_qry_paystatus;var para=["sp_id="+payPara.transInfoArray[0]["sBargainorId"],"code="+code,"status="+Qrcode.status];var config={method:"post",data:para.join("&"),context:this,on:{success:this.queryPayStatusResult,failure:this.failQueryPayStatus}};Y.io(url,config)},failQueryPayStatus:function(){Qrcode.watchPayStatus()},qrOutTimeHander:function(expire_flag){if(expire_flag==1){Y.one("#switch-qr-load").addClass("info-overdue");Qrcode.stopQueryStatus=true}},showSucessPage:function(){var mainQrcode=Y.one("#main-qrcode");mainQrcode.addClass("hide");var paySuccess=Y.one("#pay-success");paySuccess.removeClass("hide");this.initReturnSucess()},showScanOkPage:function(){var qr_status=Y.one("#qr-status");qr_status.addClass("tdcode-success")},queryPayStatusResult:function(id,o){var data=Y.until.parseJson(o.responseText),retcode=parseInt(data.retcode,10);if(retcode===0){Qrcode.status=data.status;if(data.status==1){Qrcode.stopQueryStatus=false}else{if(data.status==2){this.showScanOkPage();Qrcode.stopQueryStatus=false}else{if(data.status==3){Qrcode.stopQueryStatus=true;Qrcode.return_url=data.return_url;Qrcode.showSucessPage()}}}Qrcode.qrOutTimeHander(data.expire_flag)}else{}Qrcode.watchPayStatus()},createQrImg:function(){var url="/app/wsm/plat_qry_event_pc.cgi";var para=["act_type="+2,"pay_channel="+2,"spid="+payPara.transInfoArray[0].sBargainorId,"list_id="+payPara.transInfoArray[0].sTransId];var config={method:"get",data:para.join("&"),context:this,on:{success:function(id,o){var data=Y.until.parseJson(o.responseText),retcode=parseInt(data.retcode,10);var topic_token="";if(retcode==0){if(data.topic_token){topic_token=data.topic_token;var str=data.act_url?'<a href="'+data.act_url+'"  style="color:#FFF" target="_blank">'+data.topic_qp_desc+"</a>":data.topic_qp_desc;Y.all(".js-qr-effect-ad").set("innerHTML",str);Y.all(".spread-tips, .spread-tips-static").removeClass("hide")}}var code=encodeURIComponent(payPara.transInfoArray[0]["sCode"]+"&_wv=7&f=qrcode&q="+topic_token);code=Y.Lang.sub(G_CGI.gen_qrcode,{random:Math.random(),code:code});this.drawQRcode(Y.one("#qr-img"),Y.one("#switch-qr-load"),code)}}};Y.io(url,config)},addAnimation:function(id,pos,opacity){Y.one("#switch-qr-load").addClass("info-hover");Y.one("#"+id).addClass("hover-iphone");Y.one("#"+id).transition({duration:Qrcode.transitionTime,easing:Qrcode.transitionEffect,left:pos+"px",opacity:opacity},function(){if(opacity==0){Y.one("#"+id).removeClass("hover-iphone");Y.one("#switch-qr-load").removeClass("info-hover")}})},initEvent:function(effectId,qrImgId,regetQr){var effectEl=Y.one("#"+effectId);var qrImg=Y.one("#"+qrImgId);qrImg.on("mouseover",function(e){Qrcode.addAnimation("qr-effect",300,1)});qrImg.on("mouseout",function(evt){var relatedTarget=evt.relatedTarget;if(relatedTarget.get("id")===effectId){return}Qrcode.addAnimation(effectId,130,0)});var regetQrEl=Y.one("#"+regetQr);regetQrEl.on("click",function(){if(Qrcode.stopQueryStatus){setTimeout(function(){location.reload()},100)}});Y.one(".btn-wrap").on("click",function(){Y.one("#expand-detail").toggleClass("tdcode-show")});Y.one("#return_url").on("click",function(){Qrcode.goBack()})},goBack:function(){if(!Qrcode.return_url){Y.until.showError("返回商户出错！")}else{window.location.href=Qrcode.return_url}},initReturnSucess:function(){var second=Qrcode.second;var js_count=Y.one("#time_count");var timer=setInterval(function(){if(second==0){clearInterval(timer);timer=null;Qrcode.goBack()}else{js_count.set("innerHTML",--second+"秒")}},1000)},initPage:function(){Y.one("#time_count").set("innerHTML",Qrcode.second+"秒")},initiLize:function(){this.initPage();this.createQrImg();this.initEvent("qr-effect","qr-img","switch-qr-load");this.watchPayStatus()}};Qrcode.initiLize();YUI.Env.PAY_CENTER.PAY_QRCODE=Qrcode});