(function($){ var $this;// this对象 var phoneArray = new Array(); var othendn = ""; var interval; //软电话核心对象 qlSoftPhone = { init: function(options) { var o = $.extend({ host: "http://localhost", contentPath:"", agentId:"", agentName:"", extension:"", password:"null", url:"", autoLogin:false, isDefaultSkill:true,//是否默认一个技能组 isDisableAcw:false,//是否禁用后处理操作 hangupTransferSatis:false,//是否挂机转满意度 autoEndWrapUpTime:-1,//自动结束后处理时间(单位:毫秒),-1时则不自动结束后处理 softPhoneType:"", marginBottom:0,//底部间距 marginTop:0,//顶部间距 marginLeft:0,//顶部间距 tenant:"tenant1",// 租户 platformFlag:"aspect", //平台名称,华为:huawei,Aspect:aspect,Awaya:awaya,思科:cisco, 中兴:zte platformVersion:"",// 平台版本号 agentType:"common",// 座席类型 (common:普通座席, manager:管理员) skillGroupCode:"-1",// 技能组编号 skillGroupName:"默认技能组", // 技能组名称 consultativeGroup :"{\"-1\":\"默认技能组\"}", // 可咨询组 transferGroup :"{\"-1\":\"默认技能组\"}", // 可咨询组 manageGroup:"{\"-1\":\"默认技能组\"}",//可管理组 isGetEvent:"false",//是否开始轮询 ejectScreen: function(data) {},//连接服务器成功回调事件 onDial: function(extension,phone,bussiness) {}, //外呼成功回调事件 onCall: function(data) {}, //接通成功回调事件 onWrapUp: function(data){},//后处理事件 wrapUp: function(data) {}, hangUp: function(data) {}, addRecord: function(data) {},//挂断成功回调事件 logout:function(data){}, logOff:function(data){},//登出事件回调 login:function(data){},// 登录事件回调 notReady:function(data){},// 未就绪事件回调 ready:function(data){},// 就绪事件回调 hold:function(data){},// 保持事件回调 consultDial:function(data){},// 咨询外呼事件回调 consult:function(data){},// 咨询接通事件回调 conference:function(data){}, // 会议事件回调 error:function(data){}// 错误事件回调 }, options ); //组装软电话中间件URL if(o.url === "") o.url = o.host+o.contentPath; $this = this; $this.data('softphones', o).addClass("softPhoneTopBox").html(softTopObj.initSoftPage()); if(o.extension != ""){ $("input[name='softExtensionIpt']").val(o.extension); } if(o.agentId != ""){ $("input[name='softAgentIpt']").val(o.agentId); //开始登录 if(o.autoLogin){ $("input[name='softAgentIpt']").attr("disabled",true); $("input[name='softExtensionIpt']").attr("disabled",true); $(".loginInf .loginBtn").addClass("dis"); $(".status-text").text("登录中"); $(".timing").text("00:00:00"); qlSoftPhone.login(); } } //登录绑定事件 $(".loginInf .loginBtn").bind("click",function(){ if($(this).hasClass("dis")) return false; o.agentId = $("input[name='softAgentIpt']").val().trim(); o.agentName = $("input[name='softAgentIpt']").val().trim(); o.extension = $("input[name='softExtensionIpt']").val().trim(); //如果默认密码,则密码和工号一样 if(o.password == 'null') o.password=o.agentId; $this.data('softphones', o) if(o.agentId==""){ alert("请输入工号!"); return false; } if(o.extension==""){ alert("请输入分机!"); return false; } //开始登录 $(".loginInf .loginBtn").addClass("dis"); $(".status-text").text("登录中"); $(".timing").text("00:00:00"); qlSoftPhone.login(); }); //绑定登出事件 $(".loginInf .logOffBtn").bind("click",function(){ if($(this).hasClass("dis")) return false; qlSoftPhone.logOff(); }); //电话历史委派事件 $(".telRecordBox").delegate(".make-call-history", "click", function(e) { $("input[name='phoneNumIpt']").val($(this).attr("phone")); }).delegate(".make-call-history", "dblclick",function(){ $(".callInfo").find(".activeCall").text("主叫:" + $("input[name='softExtensionIpt']").val()); $(".callInfo").find(".passiveCall").text("被叫:" + $(this).attr("phone")); $(".callInfo").find(".phone-text").show(); $(".consultatio-div,soft-agent-search").hide();//隐藏咨询框 $("input[name='phoneNumIpt']").val($(this).attr("phone")); //初始化拨号键点击事件 qlSoftPhone.makeCall($(this).attr("phone"),""); }); $(".organUser").find("label").bind("dblclick", function(){ qlSoftPhone.makeCall($(this).attr("extension"),""); }); //事件冒泡。父元素上绑定事件在子元素上不执行 $(this).dblclick(function(e){ e.stopPropagation(); }); //顶部间距 if(o.marginTop>0){ $this.css("top",o.marginTop); } //左面间距 if(o.marginLeft>0){ $this.css("left",o.marginLeft); } //开始计时 commonObj.startCountTime(); return qlSoftPhone; }, //软电话状态 statusFlag:"", //未就绪原因 noReadyReason:"", //是否登录成功 loginFlag:false, //装满意度随路数据 transferSatisBusiness:"", //是否正在获取事件 getEventing:false, //获取时间异常次数 anomalyCount:0, lastEventTime:0, /** *

登录方法

* @param tenant 租户 * @param platform 平台名称,华为:huawei,Aspect:aspect * @param version 版本号 * @param agentType 坐席类型(common:普通座席, manager:管理员) * @param skillGroupCode 技能组编号 * @param skillGroupName 技能组名称 * @param consultativeGroup 可咨询组 * @param transferGroup 可转接组 * @param manageGroup 可管理组 */ login:function(){ var o = $this.data('softphones'); var data = { agentId:o.agentId, agentName:o.agentName, password:o.password, extension:o.extension, tenant:o.tenant, platform:o.platformFlag, version:o.platformVersion, agentType:o.agentType, skillGroupCode:o.skillGroupCode, skillGroupName:o.skillGroupName, consultativeGroup:o.consultativeGroup, transferGroup:o.transferGroup, manageGroup:o.manageGroup }; this.agentType = o.agentType; qlSoftPhone.sendAjax("login",data,"qlSoftPhone.loginSuccess"); }, //改变座席状态为示忙 setNotReady:function(notreadyreason){ var o = $this.data("softphones"); qlSoftPhone.sendAjax("notReady",{token:o.token,reason:notreadyreason},"qlSoftPhone.functionCallBack"); }, //改变座席状态为示闲 setReady:function(){ var o = $this.data("softphones"); qlSoftPhone.sendAjax("ready",{token:o.token},"qlSoftPhone.functionCallBack"); }, //拨打号码 makeCall:function(phone,businessParam){ var o = $this.data("softphones"); if(phone==undefined || phone==null || phone=="" ){ alert("请输入电话号码!"); return false; } var reg = /^[0-9]*$/; if(!reg.test(phone)){ alert("电话号码格式不正确!"); return false; } if(qlSoftPhone.statusFlag != "AS_IDLE" && qlSoftPhone.statusFlag != "AS_NOT_READY"){ alert("当前状态下不允许外呼!"); return false; } var serviceId = $("#soft_skills").val(); if(serviceId == '0' || serviceId == 0){ serviceId = $(".selectGroup").find(".skill_sed").attr("value"); if(serviceId == '0' || serviceId == 0){ alert("请先选择技能组再外呼!"); return false; } } $(".status-text").text("拨号中"); $(".timing").text("00:00:00"); qlSoftPhone.statusFlag = "AS_IDLEING"; qlSoftPhone.sendAjax("dial",{token:o.token,phoneNumber:phone,serviceId:serviceId,type:"external",business:businessParam},"qlSoftPhone.functionCallBack"); // 回调外呼方法 o.onDial(o.extension,phone,businessParam); }, //接听方法 answerCall:function(){ var o = $this.data('softphones'); this.sendAjax("answer",{token:o.token},"qlSoftPhone.functionCallBack"); }, //设置技能组 setSkill:function(skillCode){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("setSkill", {agentId:o.agentId, token:o.token, skillId:skillCode}, "qlSoftPhone.functionCallBack"); }, //挂断电话 releaseCall:function(){ var o = $this.data('softphones'); if(o.hangupTransferSatis && qlSoftPhone.statusFlag == "AS_ACTIVE"){ qlSoftPhone.sendAjax("transferSatis",{token:o.token,business:qlSoftPhone.transferSatisBusiness},"qlSoftPhone.functionCallBack"); qlSoftPhone.transferSatisBusiness = ""; }else{ qlSoftPhone.sendAjax("hangUp",{token:o.token},"qlSoftPhone.functionCallBack"); } }, //数字按键 sendDigit:function(number){ var o = $this.data('softphones'); this.sendAjax("pressDigit",{token:o.token,number:number},"qlSoftPhone.functionCallBack"); }, //保持 holdCall:function(){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("hold",{token:o.token},"qlSoftPhone.functionCallBack"); }, //结束后处理 completeCall:function(completeCode){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("completeCall",{token:o.token,completeCode:completeCode},"qlSoftPhone.functionCallBack"); }, //转接 transfer:function(phoneOrAgentId,type,business){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("transfer",{token:o.token,phoneNumber:phoneOrAgentId,type:type,applicant:phoneOrAgentId,callNumber:"",business:business},"qlSoftPhone.functionCallBack"); }, //恢复 retrieveCall:function(){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("retrieve",{token:o.token},"qlSoftPhone.functionCallBack"); }, //咨询 consult:function(phoneOrAgentId,type,otherdn,business){ var o = $this.data('softphones'); //技能组 var serviceId = $("#soft_skills").val(); if(serviceId == '0' || serviceId == 0){ serviceId = $(".selectGroup").find(".skill_sed").attr("value"); if(serviceId == '0' || serviceId == 0){ alert("请先选择技能组再咨询!"); return false; } } qlSoftPhone.sendAjax("consult",{token:o.token,consultNumber:phoneOrAgentId,type:type,applicant:o.agentId,callNumber:otherdn,serviceId:serviceId,business:business},"qlSoftPhone.functionCallBack"); }, //咨询转接 consultTransfer:function(){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("consultTransfer",{token:o.token},"qlSoftPhone.functionCallBack"); }, //会议 conferenceCall:function(){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("conference",{token:o.token},"qlSoftPhone.functionCallBack"); }, //退出会议 exitConference:function(){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("exitConference",{token:o.token},"qlSoftPhone.functionCallBack"); }, //转满意度 transferSatis:function(){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("transferSatis",{token:o.token},"qlSoftPhone.functionCallBack"); }, //获取可转接,咨询技能组 getSkills:function(type){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("getSkill",{type:type,token:o.token},"qlSoftPhone.transferSkillsCallBack"); }, //根据技能组code获取就绪坐席 getReadyAgentBySkill:function(skillCode){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("getReadyAgentBySkill",{skillCode:skillCode,token:o.token},"qlSoftPhone.getReadyAgentCallBack"); }, //登录成功回调事件 loginSuccess:function(data){ var o = $this.data('softphones'); var token = data.success; if(token){ o.isGetEvent = true; o.token = token; $this.data('softphones', o); qlSoftPhone.getEvent(); //时隔30秒轮询 interval = setInterval(function(){ var time = new Date().getTime(); if(time - qlSoftPhone.lastEventTime >30000 ){ qlSoftPhone.getEvent(); } },30000); //切换成就绪状态 qlSoftPhone.setReady(); o.login();//登录成功回调 }else{ alert(data.fail); $(".loginInf .loginBtn").removeClass("dis"); $(".status-text").text("登录失败"); } }, //除登录,外呼,登出以外的请求回调函数 functionCallBack:function(data){ if(data.fail){ alert(data.fail); softTopObj.onError(); } }, //登出方法 logOff : function(){ var o = $this.data('softphones'); if(qlSoftPhone.statusFlag != "AS_IDLE" && qlSoftPhone.statusFlag != "AS_NOT_READY"){ alert("当前状态下不允许退出!"); return false; } qlSoftPhone.sendAjax("logout",{token:o.token},"qlSoftPhone.logOutSuccess"); }, //登出回调成功事件 logOutSuccess:function(data){ if(data.fail) alert(data.fail); }, //获取可转接咨询的技能组 transferSkillsCallBack:function(data){ var html = ""; var flag = true; for(var i in data){ if(flag){ html+=""+data[i]+""; //加载第一个技能组的所有坐席 qlSoftPhone.getReadyAgentBySkill(i); flag = false; }else{ html+=""+data[i]+""; } } $(".organGroup").html(html); $(".organGroup").find("a").bind("click", function(){ $(this).addClass("sed").siblings().removeClass("sed"); qlSoftPhone.getReadyAgentBySkill($(this).attr("organCode")); }); }, //获取所有示闲的坐席 getReadyAgentCallBack:function(data){ var o = $this.data('softphones'); if (data != null && data != undefined) { var consuleHtml = ""; for (var i in data) { consuleHtml += ""; } $(".organUser").html(consuleHtml); }else{ $(".organUser").html(""); } $(".organUser").find("label").bind("dblclick", function(){ qlSoftPhone.transfer($(this).find("input").attr("agentid"),"internal"); }); }, //通知后台拿到事件了 eventNotice:function(eventName){ var o = $this.data('softphones'); qlSoftPhone.sendAjax("eventNotice",{name:eventName,token:o.token},"qlSoftPhone.noticeCallBack"); }, //拿到事件回调函数 noticeCallBack:function(data){ if(data.fail) alert(data.fail); qlSoftPhone.getEvent(); }, //发送ajax请求的方法 sendAjax:function(methodName,data,callBackName){ var o = $this.data('softphones'); $.ajax({ type: "post", async:true, timeout:15000, url: o.url + "/" + methodName, data: data, dataType: "jsonp", jsonpCallback : callBackName, complete : function(XMLHttpRequest, status) { if(XMLHttpRequest.status==200){ return false; } if(XMLHttpRequest.status==0 || status=="timeout") { alert("请求超时,请检查网路连接!"); } else { alert("网络异常["+ XMLHttpRequest.status +", "+ status +"]"); console.log("网络异常["+ XMLHttpRequest.status +", "+ status +"]"); } } }); }, //获取事件 getEvent : function(){ var o = $this.data('softphones'); qlSoftPhone.lastEventTime = new Date().getTime(); //判断是否停止轮询 if(o.isGetEvent){ //判断是否轮询中 if(!qlSoftPhone.getEventing){ qlSoftPhone.getEventing = true; var date = new Date(); var yrd = "" + date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + "_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "." + date.getMilliseconds() + "_" + Math.round(Math.random()*1000); $.ajax({ type: "post", async:true, timeout:25000, url: o.url + "/getEventACK?yrd=" + yrd, data: {token:o.token}, dataType: "jsonp", jsonpCallback : "qlSoftPhone.qlEventCallBack", complete : function(XMLHttpRequest, status) { if(XMLHttpRequest.status==200){ return false; } qlSoftPhone.getEventing = false; qlSoftPhone.anomalyCount = qlSoftPhone.anomalyCount + 1; setTimeout(function(){qlSoftPhone.getEvent();}, 1000); var statusText = $(".status-text").text(); if(XMLHttpRequest.status==0 || status=="timeout") { console.log("获取事件请求超时,请检查网路连接!"); $(".status-text").text(statusText + "."); } else { $(".status-text").text(statusText + "["+ XMLHttpRequest.status +"]"); //连续异常超过5次,提醒坐席 if(qlSoftPhone.anomalyCount>=5){ // 获取事件成功,清0 qlSoftPhone.anomalyCount = 0; alert("获取事件网络异常["+ XMLHttpRequest.status +", "+ status +"]"); } console.log("获取事件网络异常["+ XMLHttpRequest.status +", "+ status +"]"); } } }); } } }, qlEventCallBack:function(data){ qlSoftPhone.getEventing = false; qlSoftPhone.anomalyCount = 0; // 获取事件成功,清0 if(data != undefined && data != null && !jQuery.isEmptyObject(data)) console.log(data); var o = $this.data("softphones"); var eventName = data.name; var data = data.data; //通知收到事件 if(eventName) qlSoftPhone.eventNotice(eventName); switch (eventName){ case "qlEvent_Login"://登录 softTopObj.logonSuccess(o,data); qlSoftPhone.loginFlag=true; o.login(data); break; case "qlEvent_notReady"://未就绪,示忙 softTopObj.notReadySuccess(data); o.notReady(data); break; case "qlEvent_Ready"://就绪,示闲 softTopObj.readySuccess(data); o.ready(data); break; case "qlEvent_Dial"://外呼 softTopObj.dailSuccess(data); o.ejectScreen(data); break; case "qlEvent_Active": softTopObj.activeSuccess(data); o.onCall(data); break; case "qlEvent_Alerting": softTopObj.alertingSuccess(data); if(data.callType != "cons") o.ejectScreen(data); break; case "qlEvent_HangUp": o.hangUp(data); break; case "qlEvent_WrapUp": softTopObj.wrapUpSuccess(o,data); o.wrapUp(data); break; case "qlEvent_Hold": softTopObj.hodeSuccess(data); o.hold(data); break; case "qlEvent_Record": o.addRecord(data); break; case "qlEvent_ConsultDial": softTopObj.consultDialSuccess(data); o.consultDial(data); break; case "qlEvent_Consult": softTopObj.consultSuccess(data); o.consult(data); break; case "qlEvent_Consult_Tran": break; case "qlEvent_Conference": softTopObj.conferenceSuccess(data); o.conference(data); break; case "Session Timeout": alert("Session Timeout"); softTopObj.logOutSuccess({success:"Session Timeout"}); break; case "qlEvent_Logout": o.isGetEvent = false; window.clearInterval(interval);//删除30秒轮询对象 $this.data('softphones', o); qlSoftPhone.loginFlag=false; softTopObj.logOutSuccess(data); o.logout(data); break; case "qlEvent_Error": alert(data); softTopObj.onError(); o.error(data); break; default: qlSoftPhone.getEvent(); } } }; //顶部软电话对象 var softTopObj = { //登录成功回调事件 logonSuccess:function(o,data){ //关闭所有的按钮 softTopObj.closeAllBtn() //显示状态 $(".status-text").text("登录成功"); qlSoftPhone.statusFlag="AS_LOGIN"; $(".loginInf").find("input[name='softAgentIpt']").attr("disabled",true); $(".loginInf").find("input[name='softExtensionIpt']").attr("disabled",true); $(".loginInf .logOffBtn").removeClass("dis"); //显示技能组 var currentSkills = data.serviceList; if(currentSkills != null && currentSkills != undefined && currentSkills.length > 0) { if(o.isDefaultSkill) $(".selectGroup").find("#soft_skills").html(''); else $(".selectGroup").find("#soft_skills").html(''); for(var i=0;i'+currentSkills[i].value+''); } //是否默认一个技能组 if(o.isDefaultSkill){ $(".selectGroup").removeClass("selectGroup_dis").find(".skill_sed").text($(".selectGroup").find("#soft_skills").find("label:first").text()).attr("value",$(".selectGroup").find("#soft_skills").find("label:first").attr("value")); }else{ $(".selectGroup").removeClass("selectGroup_dis").find("#soft_skills").find("label").unbind().bind("click",function(){ $(".selectGroup").find(".skill_sed").text($(this).text()).attr("value",$(this).attr("value")); }); } }else alert("没有获取到该工号的技能组"); //组装示忙原因 var html="未就绪原因"; for(var i=0;i"+data.notReadyReasonList[i].value+""; } $(".state").find(".readyKey").html(html); }, //示闲成功回调事件 readySuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn(); //显示状态 $(".status-text").text("就绪"); qlSoftPhone.statusFlag="AS_IDLE"; //绑定示闲可以点击 $(".ready").bind("click", function(){ var $readyKey = $(".ready").find(".readyKey"); if($readyKey.is(":hidden")) { $readyKey.show(); } else { $readyKey.hide(); } }); $(".ready").removeClass("sm_dis").addClass("sm").show().find("label").bind("click", function(){ qlSoftPhone.noReadyReason=$(this).text(); qlSoftPhone.setNotReady($(this).attr("key")); }); $(".idle").hide(); //外呼拨号 $(".softPhoneTopBox").find(".dial-num").addClass("on").find(".bh").unbind().bind("click",function(){ if($(".pt-input-num-box").attr("isShow") == undefined || $(".pt-input-num-box").attr("isShow") == "0" ){ $(".pt-input-num-box").attr("isShow","1"); //初始化拨号键 softTopObj.openPhoneNum(); $(".pt-input-num-box").show().find(".make-call-box").unbind().bind("click",function(){ var phone = $("input[name='phoneNumIpt']").val(); phone = phone.replace(/\s/g, ""); if(phone!=undefined && phone!=null && phone!=""){ $(".callInfo").show().find(".activeCall").text("主叫:"+$("input[name='softExtensionIpt']").val()); $(".callInfo").find(".passiveCall").text("被叫:"+phone); $(".callInfo").removeClass("hide"); $(".softPhoneBox").find("input[name='phoneNumIpt']").val(phone); //拨号 var userdata = $(".inputNumBox").find(".addCode").attr("userdata"); //设置电话历史 var phoneObj = {}; phoneObj.phone=phone; softTopObj.setPhoneHistory(phoneObj); } qlSoftPhone.makeCall(phone,userdata); }); }else{ $(".pt-input-num-box").removeAttr("isShow").hide(); } }); }, //示忙成功回调事件 notReadySuccess:function (data){ //关闭所有的按钮 softTopObj.closeAllBtn() //打开拨号键盘盘 $(".pt-input-num-box").hide();//隐藏拨号键 $(".consu-input-div").hide();//隐藏咨询框 $(".callInfo").find(".phone-text").hide(); if(qlSoftPhone.noReadyReason == "") $(".status-text").text("未就绪");//显示状态 else $(".status-text").text(qlSoftPhone.noReadyReason);//显示状态 //设置软电话状态 qlSoftPhone.statusFlag="AS_NOT_READY"; //绑定示闲可以点击 $(".idle").removeClass("sx_dis").addClass("sx").show().bind("click",function(){ qlSoftPhone.setReady(); }).siblings().hide(); //外呼拨号 $(".softPhoneTopBox").find(".dial-num").addClass("on").find(".bh").unbind().bind("click",function(){ if($(".pt-input-num-box").attr("isShow") == undefined || $(".pt-input-num-box").attr("isShow") == "0" ){ $(".pt-input-num-box").attr("isShow","1"); //初始化拨号键 softTopObj.openPhoneNum(); $(".pt-input-num-box").show().find(".make-call-box").unbind().bind("click",function(){ var phone = $("input[name='phoneNumIpt']").val(); phone = phone.replace(/\s/g, ""); if(phone!=undefined && phone!=null && phone!=""){ $(".callInfo").show().find(".activeCall").text("主叫:"+$("input[name='softExtensionIpt']").val()); $(".callInfo").find(".passiveCall").text("被叫:"+phone); $(".callInfo").removeClass("hide"); $(".softPhoneBox").find("input[name='phoneNumIpt']").val(phone); //拨号 var userdata = $(".inputNumBox").find(".addCode").attr("userdata"); //设置电话历史 var phoneObj = {}; phoneObj.phone=phone; softTopObj.setPhoneHistory(phoneObj); } qlSoftPhone.makeCall(phone,userdata); }); }else{ $(".pt-input-num-box").removeAttr("isShow").hide(); } $("input[name='phoneNumIpt']").focus(); //号码输入框获取焦点 }); }, //外呼振铃操作 dailSuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn() $(".callInfo").css("display",""); othendn = data.dnis; //显示状态 $(".status-text").text("外呼中"); qlSoftPhone.statusFlag="AS_DAIL"; //外呼拨号 $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.releaseCall(); }).removeClass("jt").addClass("gd").text("挂断"); }, //呼入振铃操作 alertingSuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn() //显示状态 $(".status-text").text("呼入中"); if(data.callType == "cons") qlSoftPhone.statusFlag="AS_CONSULTDIAL"; else qlSoftPhone.statusFlag="AS_ALERTING"; $(".callInfo").find(".activeCall").text("主叫:"+data.ani); $(".callInfo").find(".passiveCall").text("被叫:"+data.dnis); $(".callInfo").css("display",""); if(data.callType == "in") $(".softPhoneBox").find("input[name='phoneNumIpt']").val(data.ani); else $(".softPhoneBox").find("input[name='phoneNumIpt']").val(data.dnis); //外呼拨号 $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.answerCall(); }); }, //接通操作 activeSuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn(); $(".callInfo").css("display",""); //打开拨号键盘盘 //挂断 $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.releaseCall(); }).removeClass("jt").addClass("gd").text("挂断"); $(".status-text").text("通话中");//显示状态 qlSoftPhone.statusFlag = "AS_ACTIVE"; // 显示示忙按钮 // 通话之前是示闲状态时才显示 if($(".idle").is(":hidden")){ $(".ready").bind("click", function(){ var $readyKey = $(".ready").find(".readyKey"); $readyKey.show(); }); $(".ready").removeClass("sm_dis").addClass("sm").show().find("label").bind("click", function(){ $(".idle").removeClass("sx_dis").addClass("sx").show(); $(".ready").hide(); qlSoftPhone.noReadyReason=$(this).text(); qlSoftPhone.setNotReady($(this).attr("key")); //将示闲按钮禁用 $(".state .sr").find(".idle").removeClass("sx").addClass("sx_dis").unbind(); }); } //保持 $(".softPhoneTopBox").find(".hode").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.holdCall(); }).addClass("bc").removeClass("hf").text("保持"); //转接 $(".softPhoneTopBox").find(".transfer").addClass("on").find("a").unbind().bind("click",function(){ softTopObj.openTransferBtn(data); }); //外呼拨号 $(".softPhoneTopBox").find(".dial-num").addClass("on").find("a").unbind().bind("click",function(){ if($(".pt-input-num-box").attr("isShow") == undefined || $(".pt-input-num-box").attr("isShow") == "0" ){ $(".pt-input-num-box").attr("isShow","1").show(); //数字按键 $(".inputKey").find(".num").unbind().bind("click",function(){ $("input[name='phoneNumIpt']").val($("input[name='phoneNumIpt']").val()+$(this).text()); qlSoftPhone.sendDigit($(this).text()); }); }else{ $(".pt-input-num-box").removeAttr("isShow").hide(); } }); }, //后处理 wrapUpSuccess:function(o,data){ //关闭所有的按钮 softTopObj.closeAllBtn(); $(".status-text").text("通话结束"); //更新软电话状态 qlSoftPhone.statusFlag="AS_ACW"; //是否禁用结束后处理操作 if(!o.isDisableAcw){ var html = "

"; for(var i=0;i"+data.wrapUpReasons[i].value+""; } $(".softPhoneTopBox").find(".hcl").append(html+"
"); //结束后处理操作 $(".softPhoneTopBox").find(".back-handle").addClass("on").find("label").bind("click", function(){ $(".softPhoneTopBox").find(".hcl").find("div").remove(); qlSoftPhone.completeCall($(this).attr("key")); }); // 自动结束后处理 if(o.autoEndWrapUpTime > 0){ // 定时结束后处理 var key = $(".softPhoneTopBox").find(".hcl").find("div").children().first().attr("key"); setTimeout(function () { if(qlSoftPhone.statusFlag == 'AS_ACW'){ qlSoftPhone.completeCall(key); } }, o.autoEndWrapUpTime); } } // 回调 o.onWrapUp();//后处理事件 }, //保持操作 hodeSuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn(); //显示状态 $(".status-text").text("保持中"); //更新软电话状态 qlSoftPhone.statusFlag="AS_HOLD"; //咨询 $(".softPhoneTopBox").find(".consultation").addClass("on").find("a").unbind().bind("click",function(){ softTopObj.openConsultationBtn(data); }); //恢复 $(".softPhoneTopBox").find(".hode").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.retrieveCall(); }).addClass("hf").removeClass("bc").text("恢复"); }, //咨询外呼振铃事件 consultDialSuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn(); //显示状态 $(".status-text").text("咨询外呼中"); //绑定咨询按钮显示隐藏咨询框 $(".softPhoneTopBox").find(".consultation").addClass("on").find("a").unbind().bind("click",function(){ if($(".consultationBox").attr("isShow") == undefined || $(".consultationBox").attr("isShow") == 0){ $(".consultationBox").show().attr("isShow",1); }else{ $(".consultationBox").hide().removeAttr("isShow"); return false; } }); qlSoftPhone.statusFlag="AS_CONSULTDIAL"; $(".consultationBox .zxBtn").html("挂断"); //挂断咨询按钮 $(".consultationBox .zxBtn").find(".release-btn").unbind().bind("click", function(){ qlSoftPhone.releaseCall(); }); }, //咨询成功回调事件 consultSuccess:function(data){ //显示状态 $(".status-text").text("咨询中"); qlSoftPhone.statusFlag="AS_CONSULT"; //咨询转接 $(".consultationBox .zxBtn").html("转接挂断") //咨询转接按钮点击事件 $(".consultationBox .zxBtn").find(".transfer-btn").bind("click", function(){ qlSoftPhone.consultTransfer(); $(".consultationBox").hide().find("input[name='consultation-ipt']").val(""); }); //挂断咨询按钮 $(".consultationBox .zxBtn").find(".release-btn").bind("click", function(){ qlSoftPhone.releaseCall(); }); //绑定会议点击事件 $(".softPhoneTopBox").find(".meeting").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.conferenceCall(); $(".consultationBox").hide().find("input[name='consultation-ipt']").val(""); }); }, //会议成功回调事件 conferenceSuccess:function(data){ //关闭所有的按钮 softTopObj.closeAllBtn(); //显示状态 $(".status-text").text("会议中"); qlSoftPhone.statusFlag="AS_CONFERENCE"; //咨询转接 $(".call-btn").html("结束会议") //挂断 $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){ qlSoftPhone.exitConference(); }).removeClass("jt").addClass("gd").text("挂断"); }, //点亮转接按钮 openTransferBtn:function(data){ if($(".transferBox").attr("isShow") == undefined || $(".transferBox").attr("isShow") == 0){ $(".transferBox").show().attr("isShow",1); }else{ $(".transferBox").hide().removeAttr("isShow"); return false; } //获取所有空闲坐席 qlSoftPhone.getSkills("transferGroup"); //内外线切换 $(".transferBox .adSearch").find("i").unbind().bind("click",function(){ if($(this).hasClass("you")){ $(".transferOutLine").hide(); $(".transferInLine").show(); $(this).removeClass("you").addClass("zuo"); }else{ $(".transferOutLine").show(); $(".transferInLine").hide(); softTopObj.transferPhoneNum(); $(this).removeClass("zuo").addClass("you"); } }); //刷新按钮 $(".transferBox .zxBtn").find(".reflush-btn").unbind().bind("click", function(){ qlSoftPhone.getSkills("transferGroup"); }); //转接按钮 $(".transferBox .zxBtn").find(".transfer-btn").unbind().bind("click", function(){ var phone = "",targetType = ""; if($(".transferBox .adSearch").find("i").hasClass("zuo")){ phone = $(".transferBox").find("input[name='agentRedio']:checked").attr("agentid"); targetType="internal"; }else{ targetType="external"; phone = $("input[name='transfer-ipt']").val() } if(phone==undefined || phone==null || phone==""){ alert("请选择一个坐席"); return false; } $(".status-text").text("转接中"); qlSoftPhone.transfer(phone,targetType,null); $(".transferBox").hide().find("input[name='transfer-ipt']").val(); }); }, //打开咨询框 openConsultationBtn:function(data){ if($(".consultationBox").attr("isShow") == undefined || $(".consultationBox").attr("isShow") == 0){ $(".consultationBox").show().attr("isShow",1); }else{ $(".consultationBox").hide().removeAttr("isShow"); return false; } //获取所有空闲坐席 qlSoftPhone.getSkills("consultativeGroup"); //内外线切换 $(".consultationBox .adSearch").find("i").unbind().bind("click",function(){ if($(this).hasClass("you")){ $(".consultationOutLine").hide(); $(".consultationInLine").show(); $(this).removeClass("you").addClass("zuo"); }else{ $(".consultationOutLine").show(); $(".consultationInLine").hide(); softTopObj.consultationPhoneNum(); $(this).removeClass("zuo").addClass("you"); } }); //添加刷新,监听,强插按钮 var str = "刷新" + "咨询" $(".consultationBox .zxBtn").html(str); //刷新按钮 $(".consultationBox .zxBtn").find(".reflush-btn").unbind().bind("click", function(){ //获取所有空闲坐席 qlSoftPhone.getSkills("consultativeGroup"); }); //咨询按钮 $(".consultationBox .zxBtn").find(".consultation-btn").unbind().bind("click", function(){ var phone = ""; var targetType="internal"; if($(".consultationBox .adSearch").find("i").hasClass("zuo")){ targetType="internal"; phone = $(".consultationBox").find("input[name='agentRedio']:checked").attr("agentid"); }else{ targetType="external"; phone = $("input[name='consultation-ipt']").val() } if(phone==undefined || phone==null || phone==""){ alert("请选择一个坐席"); return false; } $(".status-text").text("咨询拨号中"); $(".timing").text("00:00:00"); qlSoftPhone.consult(phone,targetType,othendn,null); }); }, //退出成功 logOutSuccess:function(){ //关闭所有的按钮 softTopObj.closeAllBtn() //显示状态 $(".status-text").text("签出成功"); qlSoftPhone.statusFlag = "AS_LOGOFF"; //绑定登录按钮可以 $(".loginInf").find("input[name='softAgentIpt']").removeAttr("disabled"); $(".loginInf").find("input[name='softExtensionIpt']").removeAttr("disabled") $(".selectGroup").addClass("selectGroup_dis").find(".skill_sed").text("技能组").attr("value","0"); $(".loginInf .loginBtn").removeClass("dis"); $(".loginInf .logOffBtn").addClass("dis") }, //初始化咨询区 initConsultArea:function(){ //打开拨号键盘盘 $(".pt-input-num-box").hide();//打开拨号键 $(".adSearch .nw-line").show();//隐藏咨询框 $(".telRecordBox").hide();//隐藏电话历史 $(".outLine").hide();//隐藏电话历史 $(".consultatio-div").show();//隐藏电话历史 $(".soft-agent-search").find("i").removeClass("right").addClass("left"); }, //转接外线键盘 transferPhoneNum:function(){ //拨号键盘点击事件 $(".transferOutLine .inputKey").find(".num").unbind().bind("click",function(){ $("input[name='transfer-ipt']").val($("input[name='transfer-ipt']").val()+$(this).text()); }); //拨号删除键实现长按删除电话号码 var time; $(".transferOutLine .inputKey").find(".del").unbind().bind("mouseup",function(){ clearTimeout(time); }).bind("mousedown",function(){ time = setTimeout(function() { $("input[name='transfer-ipt']").val(""); }, 700); }).bind("click",function(){ var phone = $("input[name='transfer-ipt").val(); $("input[name='transfer-ipt']").val(phone.substring(0,phone.length-1)); }); }, //咨询外线键盘 consultationPhoneNum:function(){ //拨号键盘点击事件 $(".consultationOutLine .inputKey").find(".num").unbind().bind("click",function(){ $("input[name='consultation-ipt']").val($("input[name='consultation-ipt']").val()+$(this).text()); }); //拨号删除键实现长按删除电话号码 var time; $(".consultationOutLine .inputKey").find(".del").unbind().bind("mouseup",function(){ clearTimeout(time); }).bind("mousedown",function(){ time = setTimeout(function() { $("input[name='consultation-ipt']").val(""); }, 700); }).bind("click",function(){ var phone = $("input[name='consultation-ipt").val(); $("input[name='consultation-ipt']").val(phone.substring(0,phone.length-1)); }); }, //打开拨号键 openPhoneNum:function(){ $("input[name='phoneNumIpt']").val(""); //拨号键盘点击事件 $(".pt-input-num-box .inputKey").find(".num").unbind().bind("click",function(){ $("input[name='phoneNumIpt']").val($("input[name='phoneNumIpt']").val()+$(this).text()); }); //键盘收缩隐藏 $(".pt-input-num-box .inputNumBox").find(".key-set-xy").unbind().bind("click",function(){ if($(this).hasClass("jpss")){ $(".pt-input-num-box .inputKey").show(); $(this).removeClass("jpss").addClass("jpzk"); $(".telRecordBox").hide(); }else{ $(this).removeClass("jpzk").addClass("jpss"); $(".pt-input-num-box .inputKey").hide(); $(".telRecordBox").show(); } }); //拨号删除键实现长按删除电话号码 var time; $(".pt-input-num-box .inputKey").find(".del").unbind().bind("mouseup",function(){ clearTimeout(time); }).bind("mousedown",function(){ time = setTimeout(function() { $("input[name='phoneNumIpt']").val(""); }, 700); }).bind("click",function(){ var phone = $("input[name='phoneNumIpt']").val(); $("input[name='phoneNumIpt']").val(phone.substring(0,phone.length-1)); }); }, //关闭所有的按钮 closeAllBtn:function(){ $(".state .sr").find(".idle").removeClass("sx").addClass("sx_dis").unbind();//解除示闲示忙操作 $(".state .sr").find(".ready").removeClass("sm").addClass("sm_dis").unbind().find("label").unbind();//解除示闲示忙操作 $(".timing").text("00:00:00"); $(".pt-input-num-box").hide().removeAttr("isShow"); $(".softPhoneTopBox").find("em").removeClass("on").find(".softBtn").unbind(); $(".inputKeyBox").find(".make-call-box").unbind() $(".softPhoneTopBox").find(".answer-call").find("a").removeClass("gd").addClass("jt").text("接听"); $(".transferBox").hide().removeAttr("isShow"); $(".consultationBox").hide().removeAttr("isShow"); }, //咨询外线键盘 consultPhoneNum:function(){ //拨号键盘点击事件 $(".outLine .inputKey").find(".num").unbind().bind("click",function(){ if($("input[name='cons-tran-ipt']").val().length<12) $("input[name='cons-tran-ipt']").val($("input[name='cons-tran-ipt']").val()+$(this).text()); }); //键盘收缩隐藏 $(".outLine .inputNumBox").find(".key-set-xy").unbind().bind("click",function(){ if($(this).hasClass("jpss")){ $(".inputKey").show(); $(this).removeClass("jpss").addClass("jpzk"); }else{ $(this).removeClass("jpzk").addClass("jpss"); $(".inputKey").hide(); } }); //拨号删除键实现长按删除电话号码 var time; $(".outLine .inputKey").find(".del").unbind().bind("mouseup",function(){ clearTimeout(time); }).bind("mousedown",function(){ time = setTimeout(function() { $("input[name='cons-tran-ipt']").val(""); }, 700); }).bind("click",function(){ var phone = $("input[name='cons-tran-ipt']").val(); $("input[name='cons-tran-ipt']").val(phone.substring(0,phone.length-1)); }); }, //设置拨打电话历史 setPhoneHistory:function(phoneObj){ var myDate = new Date(); phoneObj.time=myDate.getHours()+":"+(myDate.getMinutes()<10?'0'+myDate.getMinutes():myDate.getMinutes()); //电话数组最多存放5个历史电话 if(phoneArray.length>=5){ for(var i=1;i<=phoneArray.length;i++){ phoneArray[i-1]=phoneArray[i]; } } phoneArray[phoneArray.length]=phoneObj; softTopObj.getPhoneHistory(); }, //设置拨打电话历史 getPhoneHistory:function(){ var html = "
电话记录
"; for(var i=phoneArray.length-1;i>=0;i--){ if(phoneArray[i]==undefined) continue; html+="
"+phoneArray[i].phone+"
"+phoneArray[i].time+"
"; } $(".telRecordBox").html(html); }, initSoftPage:function(){ var html = '
'; html += '
'; html += '
'; html += '
未就绪
'; html += '接听'; html += '拨号'; html += '保持'; html += '后处理 '; html += '
未登录'; html += '00:00:00
'; return html; }, //错误处理 onError:function(){ if(!qlSoftPhone.loginFlag) $(".loginInf .loginBtn").removeClass("dis"); if(qlSoftPhone.statusFlag == "AS_IDLEING") { if($(".ready").hasClass("sm")){ $(".status-text").text("就绪"); qlSoftPhone.statusFlag = "AS_IDLE"; } else { $(".status-text").text("未就绪"); qlSoftPhone.statusFlag = "AS_NOT_READY"; } $(".timing").text("00:00:00"); } } }; //公共对象 var commonObj = { //开始计时 startCountTime:function(){ timeFlag = true; setInterval(function(){ commonObj._countTime()//开始时间计时 },1000); }, //计时器 _countTime:function(){ if(timeFlag){ var times = $(".timing").text().split(":"); var HH=parseInt(times[0]),MM=parseInt(times[1]),SS=parseInt(times[2]),str = ""; if(++SS==60){ if(++MM==60){ HH++; MM=0; } SS=0; } str+=HH<10?"0"+HH:HH; str+=":"; str+=MM<10?"0"+MM:MM; str+=":"; str+=SS<10?"0"+SS:SS; $(".timing").text(str); } }, //重写startsWith方法 startsWith:function(str,subStr){ if(subStr==null||subStr==""||str.length==0||subStr.length>str.length) return false; if(str.substr(0,subStr.length)==subStr) return true; else return false; return true; } }; $.fn.softphones = function(method) { if (qlSoftPhone[method]) { return qlSoftPhone[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method) { return qlSoftPhone.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist on softphones'); } }; })(jQuery);