QL.SoftPhone-cticaas.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. (function($){
  2. var $this;// this对象
  3. var phoneArray = new Array();
  4. var othendn = "";
  5. var interval;
  6. //软电话核心对象
  7. qlSoftPhone = {
  8. init: function(options) {
  9. var o = $.extend({
  10. host: "http://localhost",
  11. contentPath:"",
  12. agentId:"",
  13. agentName:"",
  14. extension:"",
  15. password:"null",
  16. url:"",
  17. autoLogin:false,
  18. isDefaultSkill:true,//是否默认一个技能组
  19. isDisableAcw:false,//是否禁用后处理操作
  20. hangupTransferSatis:false,//是否挂机转满意度
  21. autoEndWrapUpTime:-1,//自动结束后处理时间(单位:毫秒),-1时则不自动结束后处理
  22. softPhoneType:"",
  23. marginBottom:0,//底部间距
  24. marginTop:0,//顶部间距
  25. marginLeft:0,//顶部间距
  26. tenant:"tenant1",// 租户
  27. platformFlag:"aspect", //平台名称,华为:huawei,Aspect:aspect,Awaya:awaya,思科:cisco, 中兴:zte
  28. platformVersion:"",// 平台版本号
  29. agentType:"common",// 座席类型 (common:普通座席, manager:管理员)
  30. skillGroupCode:"-1",// 技能组编号
  31. skillGroupName:"默认技能组", // 技能组名称
  32. consultativeGroup :"{\"-1\":\"默认技能组\"}", // 可咨询组
  33. transferGroup :"{\"-1\":\"默认技能组\"}", // 可咨询组
  34. manageGroup:"{\"-1\":\"默认技能组\"}",//可管理组
  35. isGetEvent:"false",//是否开始轮询
  36. ejectScreen: function(data) {},//连接服务器成功回调事件
  37. onDial: function(extension,phone,bussiness) {}, //外呼成功回调事件
  38. onCall: function(data) {}, //接通成功回调事件
  39. onWrapUp: function(data){},//后处理事件
  40. wrapUp: function(data) {},
  41. hangUp: function(data) {},
  42. addRecord: function(data) {},//挂断成功回调事件
  43. logout:function(data){},
  44. logOff:function(data){},//登出事件回调
  45. login:function(data){},// 登录事件回调
  46. notReady:function(data){},// 未就绪事件回调
  47. ready:function(data){},// 就绪事件回调
  48. hold:function(data){},// 保持事件回调
  49. consultDial:function(data){},// 咨询外呼事件回调
  50. consult:function(data){},// 咨询接通事件回调
  51. conference:function(data){}, // 会议事件回调
  52. error:function(data){}// 错误事件回调
  53. }, options );
  54. //组装软电话中间件URL
  55. if(o.url === "") o.url = o.host+o.contentPath;
  56. $this = this;
  57. $this.data('softphones', o).addClass("softPhoneTopBox").html(softTopObj.initSoftPage());
  58. if(o.extension != ""){
  59. $("input[name='softExtensionIpt']").val(o.extension);
  60. }
  61. if(o.agentId != ""){
  62. $("input[name='softAgentIpt']").val(o.agentId);
  63. //开始登录
  64. if(o.autoLogin){
  65. $("input[name='softAgentIpt']").attr("disabled",true);
  66. $("input[name='softExtensionIpt']").attr("disabled",true);
  67. $(".loginInf .loginBtn").addClass("dis");
  68. $(".status-text").text("登录中");
  69. $(".timing").text("00:00:00");
  70. qlSoftPhone.login();
  71. }
  72. }
  73. //登录绑定事件
  74. $(".loginInf .loginBtn").bind("click",function(){
  75. if($(this).hasClass("dis")) return false;
  76. o.agentId = $("input[name='softAgentIpt']").val().trim();
  77. o.agentName = $("input[name='softAgentIpt']").val().trim();
  78. o.extension = $("input[name='softExtensionIpt']").val().trim();
  79. //如果默认密码,则密码和工号一样
  80. if(o.password == 'null') o.password=o.agentId;
  81. $this.data('softphones', o)
  82. if(o.agentId==""){
  83. alert("请输入工号!");
  84. return false;
  85. }
  86. if(o.extension==""){
  87. alert("请输入分机!");
  88. return false;
  89. }
  90. //开始登录
  91. $(".loginInf .loginBtn").addClass("dis");
  92. $(".status-text").text("登录中");
  93. $(".timing").text("00:00:00");
  94. qlSoftPhone.login();
  95. });
  96. //绑定登出事件
  97. $(".loginInf .logOffBtn").bind("click",function(){
  98. if($(this).hasClass("dis")) return false;
  99. qlSoftPhone.logOff();
  100. });
  101. //电话历史委派事件
  102. $(".telRecordBox").delegate(".make-call-history", "click", function(e) {
  103. $("input[name='phoneNumIpt']").val($(this).attr("phone"));
  104. }).delegate(".make-call-history", "dblclick",function(){
  105. $(".callInfo").find(".activeCall").text("主叫:" + $("input[name='softExtensionIpt']").val());
  106. $(".callInfo").find(".passiveCall").text("被叫:" + $(this).attr("phone"));
  107. $(".callInfo").find(".phone-text").show();
  108. $(".consultatio-div,soft-agent-search").hide();//隐藏咨询框
  109. $("input[name='phoneNumIpt']").val($(this).attr("phone"));
  110. //初始化拨号键点击事件
  111. qlSoftPhone.makeCall($(this).attr("phone"),"");
  112. });
  113. $(".organUser").find("label").bind("dblclick", function(){
  114. qlSoftPhone.makeCall($(this).attr("extension"),"");
  115. });
  116. //事件冒泡。父元素上绑定事件在子元素上不执行
  117. $(this).dblclick(function(e){
  118. e.stopPropagation();
  119. });
  120. //顶部间距
  121. if(o.marginTop>0){
  122. $this.css("top",o.marginTop);
  123. }
  124. //左面间距
  125. if(o.marginLeft>0){
  126. $this.css("left",o.marginLeft);
  127. }
  128. //开始计时
  129. commonObj.startCountTime();
  130. return qlSoftPhone;
  131. },
  132. //软电话状态
  133. statusFlag:"",
  134. //未就绪原因
  135. noReadyReason:"",
  136. //是否登录成功
  137. loginFlag:false,
  138. //装满意度随路数据
  139. transferSatisBusiness:"",
  140. //是否正在获取事件
  141. getEventing:false,
  142. //获取时间异常次数
  143. anomalyCount:0,
  144. lastEventTime:0,
  145. /**
  146. * <p>登录方法<p>
  147. * @param tenant 租户
  148. * @param platform 平台名称,华为:huawei,Aspect:aspect
  149. * @param version 版本号
  150. * @param agentType 坐席类型(common:普通座席, manager:管理员)
  151. * @param skillGroupCode 技能组编号
  152. * @param skillGroupName 技能组名称
  153. * @param consultativeGroup 可咨询组
  154. * @param transferGroup 可转接组
  155. * @param manageGroup 可管理组
  156. */
  157. login:function(){
  158. var o = $this.data('softphones');
  159. var data = {
  160. agentId:o.agentId,
  161. agentName:o.agentName,
  162. password:o.password,
  163. extension:o.extension,
  164. tenant:o.tenant,
  165. platform:o.platformFlag,
  166. version:o.platformVersion,
  167. agentType:o.agentType,
  168. skillGroupCode:o.skillGroupCode,
  169. skillGroupName:o.skillGroupName,
  170. consultativeGroup:o.consultativeGroup,
  171. transferGroup:o.transferGroup,
  172. manageGroup:o.manageGroup
  173. };
  174. this.agentType = o.agentType;
  175. qlSoftPhone.sendAjax("login",data,"qlSoftPhone.loginSuccess");
  176. },
  177. //改变座席状态为示忙
  178. setNotReady:function(notreadyreason){
  179. var o = $this.data("softphones");
  180. qlSoftPhone.sendAjax("notReady",{token:o.token,reason:notreadyreason},"qlSoftPhone.functionCallBack");
  181. },
  182. //改变座席状态为示闲
  183. setReady:function(){
  184. var o = $this.data("softphones");
  185. qlSoftPhone.sendAjax("ready",{token:o.token},"qlSoftPhone.functionCallBack");
  186. },
  187. //拨打号码
  188. makeCall:function(phone,businessParam){
  189. var o = $this.data("softphones");
  190. if(phone==undefined || phone==null || phone=="" ){
  191. alert("请输入电话号码!");
  192. return false;
  193. }
  194. var reg = /^[0-9]*$/;
  195. if(!reg.test(phone)){
  196. alert("电话号码格式不正确!");
  197. return false;
  198. }
  199. if(qlSoftPhone.statusFlag != "AS_IDLE" && qlSoftPhone.statusFlag != "AS_NOT_READY"){
  200. alert("当前状态下不允许外呼!");
  201. return false;
  202. }
  203. var serviceId = $("#soft_skills").val();
  204. if(serviceId == '0' || serviceId == 0){
  205. serviceId = $(".selectGroup").find(".skill_sed").attr("value");
  206. if(serviceId == '0' || serviceId == 0){
  207. alert("请先选择技能组再外呼!");
  208. return false;
  209. }
  210. }
  211. $(".status-text").text("拨号中");
  212. $(".timing").text("00:00:00");
  213. qlSoftPhone.statusFlag = "AS_IDLEING";
  214. qlSoftPhone.sendAjax("dial",{token:o.token,phoneNumber:phone,serviceId:serviceId,type:"external",business:businessParam},"qlSoftPhone.functionCallBack");
  215. // 回调外呼方法
  216. o.onDial(o.extension,phone,businessParam);
  217. },
  218. //接听方法
  219. answerCall:function(){
  220. var o = $this.data('softphones');
  221. this.sendAjax("answer",{token:o.token},"qlSoftPhone.functionCallBack");
  222. },
  223. //设置技能组
  224. setSkill:function(skillCode){
  225. var o = $this.data('softphones');
  226. qlSoftPhone.sendAjax("setSkill", {agentId:o.agentId, token:o.token, skillId:skillCode}, "qlSoftPhone.functionCallBack");
  227. },
  228. //挂断电话
  229. releaseCall:function(){
  230. var o = $this.data('softphones');
  231. if(o.hangupTransferSatis && qlSoftPhone.statusFlag == "AS_ACTIVE"){
  232. qlSoftPhone.sendAjax("transferSatis",{token:o.token,business:qlSoftPhone.transferSatisBusiness},"qlSoftPhone.functionCallBack");
  233. qlSoftPhone.transferSatisBusiness = "";
  234. }else{
  235. qlSoftPhone.sendAjax("hangUp",{token:o.token},"qlSoftPhone.functionCallBack");
  236. }
  237. },
  238. //数字按键
  239. sendDigit:function(number){
  240. var o = $this.data('softphones');
  241. this.sendAjax("pressDigit",{token:o.token,number:number},"qlSoftPhone.functionCallBack");
  242. },
  243. //保持
  244. holdCall:function(){
  245. var o = $this.data('softphones');
  246. qlSoftPhone.sendAjax("hold",{token:o.token},"qlSoftPhone.functionCallBack");
  247. },
  248. //结束后处理
  249. completeCall:function(completeCode){
  250. var o = $this.data('softphones');
  251. qlSoftPhone.sendAjax("completeCall",{token:o.token,completeCode:completeCode},"qlSoftPhone.functionCallBack");
  252. },
  253. //转接
  254. transfer:function(phoneOrAgentId,type,business){
  255. var o = $this.data('softphones');
  256. qlSoftPhone.sendAjax("transfer",{token:o.token,phoneNumber:phoneOrAgentId,type:type,applicant:phoneOrAgentId,callNumber:"",business:business},"qlSoftPhone.functionCallBack");
  257. },
  258. //恢复
  259. retrieveCall:function(){
  260. var o = $this.data('softphones');
  261. qlSoftPhone.sendAjax("retrieve",{token:o.token},"qlSoftPhone.functionCallBack");
  262. },
  263. //咨询
  264. consult:function(phoneOrAgentId,type,otherdn,business){
  265. var o = $this.data('softphones');
  266. //技能组
  267. var serviceId = $("#soft_skills").val();
  268. if(serviceId == '0' || serviceId == 0){
  269. serviceId = $(".selectGroup").find(".skill_sed").attr("value");
  270. if(serviceId == '0' || serviceId == 0){
  271. alert("请先选择技能组再咨询!");
  272. return false;
  273. }
  274. }
  275. qlSoftPhone.sendAjax("consult",{token:o.token,consultNumber:phoneOrAgentId,type:type,applicant:o.agentId,callNumber:otherdn,serviceId:serviceId,business:business},"qlSoftPhone.functionCallBack");
  276. },
  277. //咨询转接
  278. consultTransfer:function(){
  279. var o = $this.data('softphones');
  280. qlSoftPhone.sendAjax("consultTransfer",{token:o.token},"qlSoftPhone.functionCallBack");
  281. },
  282. //会议
  283. conferenceCall:function(){
  284. var o = $this.data('softphones');
  285. qlSoftPhone.sendAjax("conference",{token:o.token},"qlSoftPhone.functionCallBack");
  286. },
  287. //退出会议
  288. exitConference:function(){
  289. var o = $this.data('softphones');
  290. qlSoftPhone.sendAjax("exitConference",{token:o.token},"qlSoftPhone.functionCallBack");
  291. },
  292. //转满意度
  293. transferSatis:function(){
  294. var o = $this.data('softphones');
  295. qlSoftPhone.sendAjax("transferSatis",{token:o.token},"qlSoftPhone.functionCallBack");
  296. },
  297. //获取可转接,咨询技能组
  298. getSkills:function(type){
  299. var o = $this.data('softphones');
  300. qlSoftPhone.sendAjax("getSkill",{type:type,token:o.token},"qlSoftPhone.transferSkillsCallBack");
  301. },
  302. //根据技能组code获取就绪坐席
  303. getReadyAgentBySkill:function(skillCode){
  304. var o = $this.data('softphones');
  305. qlSoftPhone.sendAjax("getReadyAgentBySkill",{skillCode:skillCode,token:o.token},"qlSoftPhone.getReadyAgentCallBack");
  306. },
  307. //登录成功回调事件
  308. loginSuccess:function(data){
  309. var o = $this.data('softphones');
  310. var token = data.success;
  311. if(token){
  312. o.isGetEvent = true;
  313. o.token = token;
  314. $this.data('softphones', o);
  315. qlSoftPhone.getEvent();
  316. //时隔30秒轮询
  317. interval = setInterval(function(){
  318. var time = new Date().getTime();
  319. if(time - qlSoftPhone.lastEventTime >30000 ){
  320. qlSoftPhone.getEvent();
  321. }
  322. },30000);
  323. //切换成就绪状态
  324. qlSoftPhone.setReady();
  325. o.login();//登录成功回调
  326. }else{
  327. alert(data.fail);
  328. $(".loginInf .loginBtn").removeClass("dis");
  329. $(".status-text").text("登录失败");
  330. }
  331. },
  332. //除登录,外呼,登出以外的请求回调函数
  333. functionCallBack:function(data){
  334. if(data.fail){
  335. alert(data.fail);
  336. softTopObj.onError();
  337. }
  338. },
  339. //登出方法
  340. logOff : function(){
  341. var o = $this.data('softphones');
  342. if(qlSoftPhone.statusFlag != "AS_IDLE" && qlSoftPhone.statusFlag != "AS_NOT_READY"){
  343. alert("当前状态下不允许退出!");
  344. return false;
  345. }
  346. qlSoftPhone.sendAjax("logout",{token:o.token},"qlSoftPhone.logOutSuccess");
  347. },
  348. //登出回调成功事件
  349. logOutSuccess:function(data){
  350. if(data.fail) alert(data.fail);
  351. },
  352. //获取可转接咨询的技能组
  353. transferSkillsCallBack:function(data){
  354. var html = "";
  355. var flag = true;
  356. for(var i in data){
  357. if(flag){
  358. html+="<a class='sed' href='javascript:void(0);' organCode='"+i+"'>"+data[i]+"</a>";
  359. //加载第一个技能组的所有坐席
  360. qlSoftPhone.getReadyAgentBySkill(i);
  361. flag = false;
  362. }else{
  363. html+="<a href='javascript:void(0);' organCode='"+i+"'>"+data[i]+"</a>";
  364. }
  365. }
  366. $(".organGroup").html(html);
  367. $(".organGroup").find("a").bind("click", function(){
  368. $(this).addClass("sed").siblings().removeClass("sed");
  369. qlSoftPhone.getReadyAgentBySkill($(this).attr("organCode"));
  370. });
  371. },
  372. //获取所有示闲的坐席
  373. getReadyAgentCallBack:function(data){
  374. var o = $this.data('softphones');
  375. if (data != null && data != undefined) {
  376. var consuleHtml = "";
  377. for (var i in data) {
  378. consuleHtml += "<label extension='"+o.extension+"'><input type='radio' class='radio' name='agentRedio' agentId='"+i+"'><span class='radio'>"+data[i]+"</span></label>";
  379. }
  380. $(".organUser").html(consuleHtml);
  381. }else{
  382. $(".organUser").html("");
  383. }
  384. $(".organUser").find("label").bind("dblclick", function(){
  385. qlSoftPhone.transfer($(this).find("input").attr("agentid"),"internal");
  386. });
  387. },
  388. //通知后台拿到事件了
  389. eventNotice:function(eventName){
  390. var o = $this.data('softphones');
  391. qlSoftPhone.sendAjax("eventNotice",{name:eventName,token:o.token},"qlSoftPhone.noticeCallBack");
  392. },
  393. //拿到事件回调函数
  394. noticeCallBack:function(data){
  395. if(data.fail) alert(data.fail);
  396. qlSoftPhone.getEvent();
  397. },
  398. //发送ajax请求的方法
  399. sendAjax:function(methodName,data,callBackName){
  400. var o = $this.data('softphones');
  401. $.ajax({
  402. type: "post",
  403. async:true,
  404. timeout:15000,
  405. url: o.url + "/" + methodName,
  406. data: data,
  407. dataType: "jsonp",
  408. jsonpCallback : callBackName,
  409. complete : function(XMLHttpRequest, status) {
  410. if(XMLHttpRequest.status==200){
  411. return false;
  412. }
  413. if(XMLHttpRequest.status==0 || status=="timeout") {
  414. alert("请求超时,请检查网路连接!");
  415. } else {
  416. alert("网络异常["+ XMLHttpRequest.status +", "+ status +"]");
  417. console.log("网络异常["+ XMLHttpRequest.status +", "+ status +"]");
  418. }
  419. }
  420. });
  421. },
  422. //获取事件
  423. getEvent : function(){
  424. var o = $this.data('softphones');
  425. qlSoftPhone.lastEventTime = new Date().getTime();
  426. //判断是否停止轮询
  427. if(o.isGetEvent){
  428. //判断是否轮询中
  429. if(!qlSoftPhone.getEventing){
  430. qlSoftPhone.getEventing = true;
  431. var date = new Date();
  432. var yrd = "" + date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + "_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "." + date.getMilliseconds() + "_" + Math.round(Math.random()*1000);
  433. $.ajax({
  434. type: "post",
  435. async:true,
  436. timeout:25000,
  437. url: o.url + "/getEventACK?yrd=" + yrd,
  438. data: {token:o.token},
  439. dataType: "jsonp",
  440. jsonpCallback : "qlSoftPhone.qlEventCallBack",
  441. complete : function(XMLHttpRequest, status) {
  442. if(XMLHttpRequest.status==200){
  443. return false;
  444. }
  445. qlSoftPhone.getEventing = false;
  446. qlSoftPhone.anomalyCount = qlSoftPhone.anomalyCount + 1;
  447. setTimeout(function(){qlSoftPhone.getEvent();}, 1000);
  448. var statusText = $(".status-text").text();
  449. if(XMLHttpRequest.status==0 || status=="timeout") {
  450. console.log("获取事件请求超时,请检查网路连接!");
  451. $(".status-text").text(statusText + ".");
  452. } else {
  453. $(".status-text").text(statusText + "["+ XMLHttpRequest.status +"]");
  454. //连续异常超过5次,提醒坐席
  455. if(qlSoftPhone.anomalyCount>=5){
  456. // 获取事件成功,清0
  457. qlSoftPhone.anomalyCount = 0;
  458. alert("获取事件网络异常["+ XMLHttpRequest.status +", "+ status +"]");
  459. }
  460. console.log("获取事件网络异常["+ XMLHttpRequest.status +", "+ status +"]");
  461. }
  462. }
  463. });
  464. }
  465. }
  466. },
  467. qlEventCallBack:function(data){
  468. qlSoftPhone.getEventing = false;
  469. qlSoftPhone.anomalyCount = 0; // 获取事件成功,清0
  470. if(data != undefined && data != null && !jQuery.isEmptyObject(data)) console.log(data);
  471. var o = $this.data("softphones");
  472. var eventName = data.name;
  473. var data = data.data;
  474. //通知收到事件
  475. if(eventName) qlSoftPhone.eventNotice(eventName);
  476. switch (eventName){
  477. case "qlEvent_Login"://登录
  478. softTopObj.logonSuccess(o,data);
  479. qlSoftPhone.loginFlag=true;
  480. o.login(data);
  481. break;
  482. case "qlEvent_notReady"://未就绪,示忙
  483. softTopObj.notReadySuccess(data);
  484. o.notReady(data);
  485. break;
  486. case "qlEvent_Ready"://就绪,示闲
  487. softTopObj.readySuccess(data);
  488. o.ready(data);
  489. break;
  490. case "qlEvent_Dial"://外呼
  491. softTopObj.dailSuccess(data);
  492. o.ejectScreen(data);
  493. break;
  494. case "qlEvent_Active":
  495. softTopObj.activeSuccess(data);
  496. o.onCall(data);
  497. break;
  498. case "qlEvent_Alerting":
  499. softTopObj.alertingSuccess(data);
  500. if(data.callType != "cons") o.ejectScreen(data);
  501. break;
  502. case "qlEvent_HangUp":
  503. o.hangUp(data);
  504. break;
  505. case "qlEvent_WrapUp":
  506. softTopObj.wrapUpSuccess(o,data);
  507. o.wrapUp(data);
  508. break;
  509. case "qlEvent_Hold":
  510. softTopObj.hodeSuccess(data);
  511. o.hold(data);
  512. break;
  513. case "qlEvent_Record":
  514. o.addRecord(data);
  515. break;
  516. case "qlEvent_ConsultDial":
  517. softTopObj.consultDialSuccess(data);
  518. o.consultDial(data);
  519. break;
  520. case "qlEvent_Consult":
  521. softTopObj.consultSuccess(data);
  522. o.consult(data);
  523. break;
  524. case "qlEvent_Consult_Tran":
  525. break;
  526. case "qlEvent_Conference":
  527. softTopObj.conferenceSuccess(data);
  528. o.conference(data);
  529. break;
  530. case "Session Timeout":
  531. alert("Session Timeout");
  532. softTopObj.logOutSuccess({success:"Session Timeout"});
  533. break;
  534. case "qlEvent_Logout":
  535. o.isGetEvent = false;
  536. window.clearInterval(interval);//删除30秒轮询对象
  537. $this.data('softphones', o);
  538. qlSoftPhone.loginFlag=false;
  539. softTopObj.logOutSuccess(data);
  540. o.logout(data);
  541. break;
  542. case "qlEvent_Error":
  543. alert(data);
  544. softTopObj.onError();
  545. o.error(data);
  546. break;
  547. default:
  548. qlSoftPhone.getEvent();
  549. }
  550. }
  551. };
  552. //顶部软电话对象
  553. var softTopObj = {
  554. //登录成功回调事件
  555. logonSuccess:function(o,data){
  556. //关闭所有的按钮
  557. softTopObj.closeAllBtn()
  558. //显示状态
  559. $(".status-text").text("登录成功");
  560. qlSoftPhone.statusFlag="AS_LOGIN";
  561. $(".loginInf").find("input[name='softAgentIpt']").attr("disabled",true);
  562. $(".loginInf").find("input[name='softExtensionIpt']").attr("disabled",true);
  563. $(".loginInf .logOffBtn").removeClass("dis");
  564. //显示技能组
  565. var currentSkills = data.serviceList;
  566. if(currentSkills != null && currentSkills != undefined && currentSkills.length > 0) {
  567. if(o.isDefaultSkill) $(".selectGroup").find("#soft_skills").html('');
  568. else $(".selectGroup").find("#soft_skills").html('<label value="0">请选择技能组</label>');
  569. for(var i=0;i<currentSkills.length;i++){
  570. $(".selectGroup").find("#soft_skills").append('<label value="'+currentSkills[i].key+'">'+currentSkills[i].value+'</label>');
  571. }
  572. //是否默认一个技能组
  573. if(o.isDefaultSkill){
  574. $(".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"));
  575. }else{
  576. $(".selectGroup").removeClass("selectGroup_dis").find("#soft_skills").find("label").unbind().bind("click",function(){
  577. $(".selectGroup").find(".skill_sed").text($(this).text()).attr("value",$(this).attr("value"));
  578. });
  579. }
  580. }else alert("没有获取到该工号的技能组");
  581. //组装示忙原因
  582. var html="<span>未就绪原因</span>";
  583. for(var i=0;i<data.notReadyReasonList.length;i++){
  584. html+="<label key='"+data.notReadyReasonList[i].key+"'>"+data.notReadyReasonList[i].value+"</label>";
  585. }
  586. $(".state").find(".readyKey").html(html);
  587. },
  588. //示闲成功回调事件
  589. readySuccess:function(data){
  590. //关闭所有的按钮
  591. softTopObj.closeAllBtn();
  592. //显示状态
  593. $(".status-text").text("就绪");
  594. qlSoftPhone.statusFlag="AS_IDLE";
  595. //绑定示闲可以点击
  596. $(".ready").bind("click", function(){
  597. var $readyKey = $(".ready").find(".readyKey");
  598. if($readyKey.is(":hidden")) {
  599. $readyKey.show();
  600. } else {
  601. $readyKey.hide();
  602. }
  603. });
  604. $(".ready").removeClass("sm_dis").addClass("sm").show().find("label").bind("click", function(){
  605. qlSoftPhone.noReadyReason=$(this).text();
  606. qlSoftPhone.setNotReady($(this).attr("key"));
  607. });
  608. $(".idle").hide();
  609. //外呼拨号
  610. $(".softPhoneTopBox").find(".dial-num").addClass("on").find(".bh").unbind().bind("click",function(){
  611. if($(".pt-input-num-box").attr("isShow") == undefined || $(".pt-input-num-box").attr("isShow") == "0" ){
  612. $(".pt-input-num-box").attr("isShow","1");
  613. //初始化拨号键
  614. softTopObj.openPhoneNum();
  615. $(".pt-input-num-box").show().find(".make-call-box").unbind().bind("click",function(){
  616. var phone = $("input[name='phoneNumIpt']").val();
  617. phone = phone.replace(/\s/g, "");
  618. if(phone!=undefined && phone!=null && phone!=""){
  619. $(".callInfo").show().find(".activeCall").text("主叫:"+$("input[name='softExtensionIpt']").val());
  620. $(".callInfo").find(".passiveCall").text("被叫:"+phone);
  621. $(".callInfo").removeClass("hide");
  622. $(".softPhoneBox").find("input[name='phoneNumIpt']").val(phone);
  623. //拨号
  624. var userdata = $(".inputNumBox").find(".addCode").attr("userdata");
  625. //设置电话历史
  626. var phoneObj = {};
  627. phoneObj.phone=phone;
  628. softTopObj.setPhoneHistory(phoneObj);
  629. }
  630. qlSoftPhone.makeCall(phone,userdata);
  631. });
  632. }else{
  633. $(".pt-input-num-box").removeAttr("isShow").hide();
  634. }
  635. });
  636. },
  637. //示忙成功回调事件
  638. notReadySuccess:function (data){
  639. //关闭所有的按钮
  640. softTopObj.closeAllBtn()
  641. //打开拨号键盘盘
  642. $(".pt-input-num-box").hide();//隐藏拨号键
  643. $(".consu-input-div").hide();//隐藏咨询框
  644. $(".callInfo").find(".phone-text").hide();
  645. if(qlSoftPhone.noReadyReason == "") $(".status-text").text("未就绪");//显示状态
  646. else $(".status-text").text(qlSoftPhone.noReadyReason);//显示状态
  647. //设置软电话状态
  648. qlSoftPhone.statusFlag="AS_NOT_READY";
  649. //绑定示闲可以点击
  650. $(".idle").removeClass("sx_dis").addClass("sx").show().bind("click",function(){
  651. qlSoftPhone.setReady();
  652. }).siblings().hide();
  653. //外呼拨号
  654. $(".softPhoneTopBox").find(".dial-num").addClass("on").find(".bh").unbind().bind("click",function(){
  655. if($(".pt-input-num-box").attr("isShow") == undefined || $(".pt-input-num-box").attr("isShow") == "0" ){
  656. $(".pt-input-num-box").attr("isShow","1");
  657. //初始化拨号键
  658. softTopObj.openPhoneNum();
  659. $(".pt-input-num-box").show().find(".make-call-box").unbind().bind("click",function(){
  660. var phone = $("input[name='phoneNumIpt']").val();
  661. phone = phone.replace(/\s/g, "");
  662. if(phone!=undefined && phone!=null && phone!=""){
  663. $(".callInfo").show().find(".activeCall").text("主叫:"+$("input[name='softExtensionIpt']").val());
  664. $(".callInfo").find(".passiveCall").text("被叫:"+phone);
  665. $(".callInfo").removeClass("hide");
  666. $(".softPhoneBox").find("input[name='phoneNumIpt']").val(phone);
  667. //拨号
  668. var userdata = $(".inputNumBox").find(".addCode").attr("userdata");
  669. //设置电话历史
  670. var phoneObj = {};
  671. phoneObj.phone=phone;
  672. softTopObj.setPhoneHistory(phoneObj);
  673. }
  674. qlSoftPhone.makeCall(phone,userdata);
  675. });
  676. }else{
  677. $(".pt-input-num-box").removeAttr("isShow").hide();
  678. }
  679. $("input[name='phoneNumIpt']").focus(); //号码输入框获取焦点
  680. });
  681. },
  682. //外呼振铃操作
  683. dailSuccess:function(data){
  684. //关闭所有的按钮
  685. softTopObj.closeAllBtn()
  686. $(".callInfo").css("display","");
  687. othendn = data.dnis;
  688. //显示状态
  689. $(".status-text").text("外呼中");
  690. qlSoftPhone.statusFlag="AS_DAIL";
  691. //外呼拨号
  692. $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){
  693. qlSoftPhone.releaseCall();
  694. }).removeClass("jt").addClass("gd").text("挂断");
  695. },
  696. //呼入振铃操作
  697. alertingSuccess:function(data){
  698. //关闭所有的按钮
  699. softTopObj.closeAllBtn()
  700. //显示状态
  701. $(".status-text").text("呼入中");
  702. if(data.callType == "cons") qlSoftPhone.statusFlag="AS_CONSULTDIAL";
  703. else qlSoftPhone.statusFlag="AS_ALERTING";
  704. $(".callInfo").find(".activeCall").text("主叫:"+data.ani);
  705. $(".callInfo").find(".passiveCall").text("被叫:"+data.dnis);
  706. $(".callInfo").css("display","");
  707. if(data.callType == "in") $(".softPhoneBox").find("input[name='phoneNumIpt']").val(data.ani);
  708. else $(".softPhoneBox").find("input[name='phoneNumIpt']").val(data.dnis);
  709. //外呼拨号
  710. $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){
  711. qlSoftPhone.answerCall();
  712. });
  713. },
  714. //接通操作
  715. activeSuccess:function(data){
  716. //关闭所有的按钮
  717. softTopObj.closeAllBtn();
  718. $(".callInfo").css("display","");
  719. //打开拨号键盘盘
  720. //挂断
  721. $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){
  722. qlSoftPhone.releaseCall();
  723. }).removeClass("jt").addClass("gd").text("挂断");
  724. $(".status-text").text("通话中");//显示状态
  725. qlSoftPhone.statusFlag = "AS_ACTIVE";
  726. // 显示示忙按钮
  727. // 通话之前是示闲状态时才显示
  728. if($(".idle").is(":hidden")){
  729. $(".ready").bind("click", function(){
  730. var $readyKey = $(".ready").find(".readyKey");
  731. $readyKey.show();
  732. });
  733. $(".ready").removeClass("sm_dis").addClass("sm").show().find("label").bind("click", function(){
  734. $(".idle").removeClass("sx_dis").addClass("sx").show();
  735. $(".ready").hide();
  736. qlSoftPhone.noReadyReason=$(this).text();
  737. qlSoftPhone.setNotReady($(this).attr("key"));
  738. //将示闲按钮禁用
  739. $(".state .sr").find(".idle").removeClass("sx").addClass("sx_dis").unbind();
  740. });
  741. }
  742. //保持
  743. $(".softPhoneTopBox").find(".hode").addClass("on").find("a").unbind().bind("click",function(){
  744. qlSoftPhone.holdCall();
  745. }).addClass("bc").removeClass("hf").text("保持");
  746. //转接
  747. $(".softPhoneTopBox").find(".transfer").addClass("on").find("a").unbind().bind("click",function(){
  748. softTopObj.openTransferBtn(data);
  749. });
  750. //外呼拨号
  751. $(".softPhoneTopBox").find(".dial-num").addClass("on").find("a").unbind().bind("click",function(){
  752. if($(".pt-input-num-box").attr("isShow") == undefined || $(".pt-input-num-box").attr("isShow") == "0" ){
  753. $(".pt-input-num-box").attr("isShow","1").show();
  754. //数字按键
  755. $(".inputKey").find(".num").unbind().bind("click",function(){
  756. $("input[name='phoneNumIpt']").val($("input[name='phoneNumIpt']").val()+$(this).text());
  757. qlSoftPhone.sendDigit($(this).text());
  758. });
  759. }else{
  760. $(".pt-input-num-box").removeAttr("isShow").hide();
  761. }
  762. });
  763. },
  764. //后处理
  765. wrapUpSuccess:function(o,data){
  766. //关闭所有的按钮
  767. softTopObj.closeAllBtn();
  768. $(".status-text").text("通话结束");
  769. //更新软电话状态
  770. qlSoftPhone.statusFlag="AS_ACW";
  771. //是否禁用结束后处理操作
  772. if(!o.isDisableAcw){
  773. var html = "<div class='why'>";
  774. for(var i=0;i<data.wrapUpReasons.length;i++){
  775. html+="<label key='"+data.wrapUpReasons[i].key+"'>"+data.wrapUpReasons[i].value+"</label>";
  776. }
  777. $(".softPhoneTopBox").find(".hcl").append(html+"</div>");
  778. //结束后处理操作
  779. $(".softPhoneTopBox").find(".back-handle").addClass("on").find("label").bind("click", function(){
  780. $(".softPhoneTopBox").find(".hcl").find("div").remove();
  781. qlSoftPhone.completeCall($(this).attr("key"));
  782. });
  783. // 自动结束后处理
  784. if(o.autoEndWrapUpTime > 0){
  785. // 定时结束后处理
  786. var key = $(".softPhoneTopBox").find(".hcl").find("div").children().first().attr("key");
  787. setTimeout(function () {
  788. if(qlSoftPhone.statusFlag == 'AS_ACW'){
  789. qlSoftPhone.completeCall(key);
  790. }
  791. }, o.autoEndWrapUpTime);
  792. }
  793. }
  794. // 回调
  795. o.onWrapUp();//后处理事件
  796. },
  797. //保持操作
  798. hodeSuccess:function(data){
  799. //关闭所有的按钮
  800. softTopObj.closeAllBtn();
  801. //显示状态
  802. $(".status-text").text("保持中");
  803. //更新软电话状态
  804. qlSoftPhone.statusFlag="AS_HOLD";
  805. //咨询
  806. $(".softPhoneTopBox").find(".consultation").addClass("on").find("a").unbind().bind("click",function(){
  807. softTopObj.openConsultationBtn(data);
  808. });
  809. //恢复
  810. $(".softPhoneTopBox").find(".hode").addClass("on").find("a").unbind().bind("click",function(){
  811. qlSoftPhone.retrieveCall();
  812. }).addClass("hf").removeClass("bc").text("恢复");
  813. },
  814. //咨询外呼振铃事件
  815. consultDialSuccess:function(data){
  816. //关闭所有的按钮
  817. softTopObj.closeAllBtn();
  818. //显示状态
  819. $(".status-text").text("咨询外呼中");
  820. //绑定咨询按钮显示隐藏咨询框
  821. $(".softPhoneTopBox").find(".consultation").addClass("on").find("a").unbind().bind("click",function(){
  822. if($(".consultationBox").attr("isShow") == undefined || $(".consultationBox").attr("isShow") == 0){
  823. $(".consultationBox").show().attr("isShow",1);
  824. }else{
  825. $(".consultationBox").hide().removeAttr("isShow");
  826. return false;
  827. }
  828. });
  829. qlSoftPhone.statusFlag="AS_CONSULTDIAL";
  830. $(".consultationBox .zxBtn").html("<a href='javascript:void(0);' class='release-btn'>挂断</a>");
  831. //挂断咨询按钮
  832. $(".consultationBox .zxBtn").find(".release-btn").unbind().bind("click", function(){
  833. qlSoftPhone.releaseCall();
  834. });
  835. },
  836. //咨询成功回调事件
  837. consultSuccess:function(data){
  838. //显示状态
  839. $(".status-text").text("咨询中");
  840. qlSoftPhone.statusFlag="AS_CONSULT";
  841. //咨询转接
  842. $(".consultationBox .zxBtn").html("<a href='javascript:void(0);' class='transfer-btn'>转接</a><a href='javascript:void(0);' class='release-btn'>挂断</a>")
  843. //咨询转接按钮点击事件
  844. $(".consultationBox .zxBtn").find(".transfer-btn").bind("click", function(){
  845. qlSoftPhone.consultTransfer();
  846. $(".consultationBox").hide().find("input[name='consultation-ipt']").val("");
  847. });
  848. //挂断咨询按钮
  849. $(".consultationBox .zxBtn").find(".release-btn").bind("click", function(){
  850. qlSoftPhone.releaseCall();
  851. });
  852. //绑定会议点击事件
  853. $(".softPhoneTopBox").find(".meeting").addClass("on").find("a").unbind().bind("click",function(){
  854. qlSoftPhone.conferenceCall();
  855. $(".consultationBox").hide().find("input[name='consultation-ipt']").val("");
  856. });
  857. },
  858. //会议成功回调事件
  859. conferenceSuccess:function(data){
  860. //关闭所有的按钮
  861. softTopObj.closeAllBtn();
  862. //显示状态
  863. $(".status-text").text("会议中");
  864. qlSoftPhone.statusFlag="AS_CONFERENCE";
  865. //咨询转接
  866. $(".call-btn").html("<a href='javascript:void(0);' class='release-btn'>结束会议</a>")
  867. //挂断
  868. $(".softPhoneTopBox").find(".answer-call").addClass("on").find("a").unbind().bind("click",function(){
  869. qlSoftPhone.exitConference();
  870. }).removeClass("jt").addClass("gd").text("挂断");
  871. },
  872. //点亮转接按钮
  873. openTransferBtn:function(data){
  874. if($(".transferBox").attr("isShow") == undefined || $(".transferBox").attr("isShow") == 0){
  875. $(".transferBox").show().attr("isShow",1);
  876. }else{
  877. $(".transferBox").hide().removeAttr("isShow");
  878. return false;
  879. }
  880. //获取所有空闲坐席
  881. qlSoftPhone.getSkills("transferGroup");
  882. //内外线切换
  883. $(".transferBox .adSearch").find("i").unbind().bind("click",function(){
  884. if($(this).hasClass("you")){
  885. $(".transferOutLine").hide();
  886. $(".transferInLine").show();
  887. $(this).removeClass("you").addClass("zuo");
  888. }else{
  889. $(".transferOutLine").show();
  890. $(".transferInLine").hide();
  891. softTopObj.transferPhoneNum();
  892. $(this).removeClass("zuo").addClass("you");
  893. }
  894. });
  895. //刷新按钮
  896. $(".transferBox .zxBtn").find(".reflush-btn").unbind().bind("click", function(){
  897. qlSoftPhone.getSkills("transferGroup");
  898. });
  899. //转接按钮
  900. $(".transferBox .zxBtn").find(".transfer-btn").unbind().bind("click", function(){
  901. var phone = "",targetType = "";
  902. if($(".transferBox .adSearch").find("i").hasClass("zuo")){
  903. phone = $(".transferBox").find("input[name='agentRedio']:checked").attr("agentid");
  904. targetType="internal";
  905. }else{
  906. targetType="external";
  907. phone = $("input[name='transfer-ipt']").val()
  908. }
  909. if(phone==undefined || phone==null || phone==""){
  910. alert("请选择一个坐席");
  911. return false;
  912. }
  913. $(".status-text").text("转接中");
  914. qlSoftPhone.transfer(phone,targetType,null);
  915. $(".transferBox").hide().find("input[name='transfer-ipt']").val();
  916. });
  917. },
  918. //打开咨询框
  919. openConsultationBtn:function(data){
  920. if($(".consultationBox").attr("isShow") == undefined || $(".consultationBox").attr("isShow") == 0){
  921. $(".consultationBox").show().attr("isShow",1);
  922. }else{
  923. $(".consultationBox").hide().removeAttr("isShow");
  924. return false;
  925. }
  926. //获取所有空闲坐席
  927. qlSoftPhone.getSkills("consultativeGroup");
  928. //内外线切换
  929. $(".consultationBox .adSearch").find("i").unbind().bind("click",function(){
  930. if($(this).hasClass("you")){
  931. $(".consultationOutLine").hide();
  932. $(".consultationInLine").show();
  933. $(this).removeClass("you").addClass("zuo");
  934. }else{
  935. $(".consultationOutLine").show();
  936. $(".consultationInLine").hide();
  937. softTopObj.consultationPhoneNum();
  938. $(this).removeClass("zuo").addClass("you");
  939. }
  940. });
  941. //添加刷新,监听,强插按钮
  942. var str = "<a href='javascript:void(0)'; class='reflush-btn'>刷新</a>"
  943. + "<a href='javascript:void(0)'; class='consultation-btn'>咨询</a>"
  944. $(".consultationBox .zxBtn").html(str);
  945. //刷新按钮
  946. $(".consultationBox .zxBtn").find(".reflush-btn").unbind().bind("click", function(){
  947. //获取所有空闲坐席
  948. qlSoftPhone.getSkills("consultativeGroup");
  949. });
  950. //咨询按钮
  951. $(".consultationBox .zxBtn").find(".consultation-btn").unbind().bind("click", function(){
  952. var phone = "";
  953. var targetType="internal";
  954. if($(".consultationBox .adSearch").find("i").hasClass("zuo")){
  955. targetType="internal";
  956. phone = $(".consultationBox").find("input[name='agentRedio']:checked").attr("agentid");
  957. }else{
  958. targetType="external";
  959. phone = $("input[name='consultation-ipt']").val()
  960. }
  961. if(phone==undefined || phone==null || phone==""){
  962. alert("请选择一个坐席");
  963. return false;
  964. }
  965. $(".status-text").text("咨询拨号中");
  966. $(".timing").text("00:00:00");
  967. qlSoftPhone.consult(phone,targetType,othendn,null);
  968. });
  969. },
  970. //退出成功
  971. logOutSuccess:function(){
  972. //关闭所有的按钮
  973. softTopObj.closeAllBtn()
  974. //显示状态
  975. $(".status-text").text("签出成功");
  976. qlSoftPhone.statusFlag = "AS_LOGOFF";
  977. //绑定登录按钮可以
  978. $(".loginInf").find("input[name='softAgentIpt']").removeAttr("disabled");
  979. $(".loginInf").find("input[name='softExtensionIpt']").removeAttr("disabled")
  980. $(".selectGroup").addClass("selectGroup_dis").find(".skill_sed").text("技能组").attr("value","0");
  981. $(".loginInf .loginBtn").removeClass("dis");
  982. $(".loginInf .logOffBtn").addClass("dis")
  983. },
  984. //初始化咨询区
  985. initConsultArea:function(){
  986. //打开拨号键盘盘
  987. $(".pt-input-num-box").hide();//打开拨号键
  988. $(".adSearch .nw-line").show();//隐藏咨询框
  989. $(".telRecordBox").hide();//隐藏电话历史
  990. $(".outLine").hide();//隐藏电话历史
  991. $(".consultatio-div").show();//隐藏电话历史
  992. $(".soft-agent-search").find("i").removeClass("right").addClass("left");
  993. },
  994. //转接外线键盘
  995. transferPhoneNum:function(){
  996. //拨号键盘点击事件
  997. $(".transferOutLine .inputKey").find(".num").unbind().bind("click",function(){
  998. $("input[name='transfer-ipt']").val($("input[name='transfer-ipt']").val()+$(this).text());
  999. });
  1000. //拨号删除键实现长按删除电话号码
  1001. var time;
  1002. $(".transferOutLine .inputKey").find(".del").unbind().bind("mouseup",function(){
  1003. clearTimeout(time);
  1004. }).bind("mousedown",function(){
  1005. time = setTimeout(function() {
  1006. $("input[name='transfer-ipt']").val("");
  1007. }, 700);
  1008. }).bind("click",function(){
  1009. var phone = $("input[name='transfer-ipt").val();
  1010. $("input[name='transfer-ipt']").val(phone.substring(0,phone.length-1));
  1011. });
  1012. },
  1013. //咨询外线键盘
  1014. consultationPhoneNum:function(){
  1015. //拨号键盘点击事件
  1016. $(".consultationOutLine .inputKey").find(".num").unbind().bind("click",function(){
  1017. $("input[name='consultation-ipt']").val($("input[name='consultation-ipt']").val()+$(this).text());
  1018. });
  1019. //拨号删除键实现长按删除电话号码
  1020. var time;
  1021. $(".consultationOutLine .inputKey").find(".del").unbind().bind("mouseup",function(){
  1022. clearTimeout(time);
  1023. }).bind("mousedown",function(){
  1024. time = setTimeout(function() {
  1025. $("input[name='consultation-ipt']").val("");
  1026. }, 700);
  1027. }).bind("click",function(){
  1028. var phone = $("input[name='consultation-ipt").val();
  1029. $("input[name='consultation-ipt']").val(phone.substring(0,phone.length-1));
  1030. });
  1031. },
  1032. //打开拨号键
  1033. openPhoneNum:function(){
  1034. $("input[name='phoneNumIpt']").val("");
  1035. //拨号键盘点击事件
  1036. $(".pt-input-num-box .inputKey").find(".num").unbind().bind("click",function(){
  1037. $("input[name='phoneNumIpt']").val($("input[name='phoneNumIpt']").val()+$(this).text());
  1038. });
  1039. //键盘收缩隐藏
  1040. $(".pt-input-num-box .inputNumBox").find(".key-set-xy").unbind().bind("click",function(){
  1041. if($(this).hasClass("jpss")){
  1042. $(".pt-input-num-box .inputKey").show();
  1043. $(this).removeClass("jpss").addClass("jpzk");
  1044. $(".telRecordBox").hide();
  1045. }else{
  1046. $(this).removeClass("jpzk").addClass("jpss");
  1047. $(".pt-input-num-box .inputKey").hide();
  1048. $(".telRecordBox").show();
  1049. }
  1050. });
  1051. //拨号删除键实现长按删除电话号码
  1052. var time;
  1053. $(".pt-input-num-box .inputKey").find(".del").unbind().bind("mouseup",function(){
  1054. clearTimeout(time);
  1055. }).bind("mousedown",function(){
  1056. time = setTimeout(function() {
  1057. $("input[name='phoneNumIpt']").val("");
  1058. }, 700);
  1059. }).bind("click",function(){
  1060. var phone = $("input[name='phoneNumIpt']").val();
  1061. $("input[name='phoneNumIpt']").val(phone.substring(0,phone.length-1));
  1062. });
  1063. },
  1064. //关闭所有的按钮
  1065. closeAllBtn:function(){
  1066. $(".state .sr").find(".idle").removeClass("sx").addClass("sx_dis").unbind();//解除示闲示忙操作
  1067. $(".state .sr").find(".ready").removeClass("sm").addClass("sm_dis").unbind().find("label").unbind();//解除示闲示忙操作
  1068. $(".timing").text("00:00:00");
  1069. $(".pt-input-num-box").hide().removeAttr("isShow");
  1070. $(".softPhoneTopBox").find("em").removeClass("on").find(".softBtn").unbind();
  1071. $(".inputKeyBox").find(".make-call-box").unbind()
  1072. $(".softPhoneTopBox").find(".answer-call").find("a").removeClass("gd").addClass("jt").text("接听");
  1073. $(".transferBox").hide().removeAttr("isShow");
  1074. $(".consultationBox").hide().removeAttr("isShow");
  1075. },
  1076. //咨询外线键盘
  1077. consultPhoneNum:function(){
  1078. //拨号键盘点击事件
  1079. $(".outLine .inputKey").find(".num").unbind().bind("click",function(){
  1080. if($("input[name='cons-tran-ipt']").val().length<12)
  1081. $("input[name='cons-tran-ipt']").val($("input[name='cons-tran-ipt']").val()+$(this).text());
  1082. });
  1083. //键盘收缩隐藏
  1084. $(".outLine .inputNumBox").find(".key-set-xy").unbind().bind("click",function(){
  1085. if($(this).hasClass("jpss")){
  1086. $(".inputKey").show();
  1087. $(this).removeClass("jpss").addClass("jpzk");
  1088. }else{
  1089. $(this).removeClass("jpzk").addClass("jpss");
  1090. $(".inputKey").hide();
  1091. }
  1092. });
  1093. //拨号删除键实现长按删除电话号码
  1094. var time;
  1095. $(".outLine .inputKey").find(".del").unbind().bind("mouseup",function(){
  1096. clearTimeout(time);
  1097. }).bind("mousedown",function(){
  1098. time = setTimeout(function() {
  1099. $("input[name='cons-tran-ipt']").val("");
  1100. }, 700);
  1101. }).bind("click",function(){
  1102. var phone = $("input[name='cons-tran-ipt']").val();
  1103. $("input[name='cons-tran-ipt']").val(phone.substring(0,phone.length-1));
  1104. });
  1105. },
  1106. //设置拨打电话历史
  1107. setPhoneHistory:function(phoneObj){
  1108. var myDate = new Date();
  1109. phoneObj.time=myDate.getHours()+":"+(myDate.getMinutes()<10?'0'+myDate.getMinutes():myDate.getMinutes());
  1110. //电话数组最多存放5个历史电话
  1111. if(phoneArray.length>=5){
  1112. for(var i=1;i<=phoneArray.length;i++){
  1113. phoneArray[i-1]=phoneArray[i];
  1114. }
  1115. }
  1116. phoneArray[phoneArray.length]=phoneObj;
  1117. softTopObj.getPhoneHistory();
  1118. },
  1119. //设置拨打电话历史
  1120. getPhoneHistory:function(){
  1121. var html = "<div class='tit'>电话记录</div>";
  1122. for(var i=phoneArray.length-1;i>=0;i--){
  1123. if(phoneArray[i]==undefined) continue;
  1124. html+="<dl class='ls'><dd class='make-call-history' phone='"+phoneArray[i].phone+"'>"+phoneArray[i].phone+"</dd><dt>"+phoneArray[i].time+"</dt></dl>";
  1125. }
  1126. $(".telRecordBox").html(html);
  1127. },
  1128. initSoftPage:function(){
  1129. var html = '<div class="qlSoftPhoneBox"><div class="loginBox_phone loginInf"><input readonly class="gh" type="text" name="softAgentIpt" placeholder="工号..." />';
  1130. html += '<input readonly class="fjh" type="text" name="softExtensionIpt" placeholder="分机号..." value=""/><div>';
  1131. html += '<button type="button" class="qr loginBtn">登入</button><button type="button" class="qc dis logOffBtn">登出</button></div></div>';
  1132. html += '<div class="state"><div class="sr"><b class="sx_dis idle"><i></i>未就绪</b><b class="sm_dis ready" style="display:none;"><i></i>就绪<div class="why readyKey"></div></b></div></div> ';
  1133. html += '<em class="answer-call"><a class="jt softBtn" href="javascript:void(0);">接听</a></em>';
  1134. html += '<em class="dial-num"><a class="bh softBtn" href="javascript:void(0);">拨号</a><div class="inputKeyBox pt-input-num-box" style="display:none;">';
  1135. html += '<div class="outLine"><div class="inputNumBox"><i class="jpzk key-set-xy"></i><input type="text" name="phoneNumIpt" placeholder="请输入号码"/><i class="bd make-call-box"></i></div>';
  1136. html += '<div class="telRecordBox" style="display:none;"><div class="tit">电话记录</div><dl class="ls">暂时还没有拨打记录!</dl></div>';
  1137. html += '<div class="inputKey clear"><ul><li class="border1 num">1</li><li class="border1 num">2</li><li class="border2 num">3</li></ul>';
  1138. html += '<ul><li class="border1 num">4</li><li class="border1 num">5</li><li class="border2 num">6</li></ul>';
  1139. html += '<ul><li class="border1 num">7</li><li class="border1 num">8</li><li class="border2 num">9</li></ul>';
  1140. html += '<ul><li class="border3 num">#</li><li class="border3 num">0</li><li class="del"></li></ul></div></div></div></em>';
  1141. html += '<em class="hode"><a class="bc softBtn" id="qlSoftPhoneHoldBtn" href="javascript:void(0);">保持</a></em>';
  1142. html += '<em class="back-handle"><a class="hcl softBtn" href="javascript:void(0);">后处理 </a></em>';
  1143. html += '<div class="state"><div class="sl"><b class="blue status-text">未登录</b>';
  1144. html += '<i class="timing" >00:00:00</i><div class="why callInfo hide"><label class="activeCall"></label><label class="passiveCall"></label></div></div></div></div>';
  1145. return html;
  1146. },
  1147. //错误处理
  1148. onError:function(){
  1149. if(!qlSoftPhone.loginFlag) $(".loginInf .loginBtn").removeClass("dis");
  1150. if(qlSoftPhone.statusFlag == "AS_IDLEING") {
  1151. if($(".ready").hasClass("sm")){
  1152. $(".status-text").text("就绪");
  1153. qlSoftPhone.statusFlag = "AS_IDLE";
  1154. } else {
  1155. $(".status-text").text("未就绪");
  1156. qlSoftPhone.statusFlag = "AS_NOT_READY";
  1157. }
  1158. $(".timing").text("00:00:00");
  1159. }
  1160. }
  1161. };
  1162. //公共对象
  1163. var commonObj = {
  1164. //开始计时
  1165. startCountTime:function(){
  1166. timeFlag = true;
  1167. setInterval(function(){
  1168. commonObj._countTime()//开始时间计时
  1169. },1000);
  1170. },
  1171. //计时器
  1172. _countTime:function(){
  1173. if(timeFlag){
  1174. var times = $(".timing").text().split(":");
  1175. var HH=parseInt(times[0]),MM=parseInt(times[1]),SS=parseInt(times[2]),str = "";
  1176. if(++SS==60){
  1177. if(++MM==60){
  1178. HH++;
  1179. MM=0;
  1180. }
  1181. SS=0;
  1182. }
  1183. str+=HH<10?"0"+HH:HH;
  1184. str+=":";
  1185. str+=MM<10?"0"+MM:MM;
  1186. str+=":";
  1187. str+=SS<10?"0"+SS:SS;
  1188. $(".timing").text(str);
  1189. }
  1190. },
  1191. //重写startsWith方法
  1192. startsWith:function(str,subStr){
  1193. if(subStr==null||subStr==""||str.length==0||subStr.length>str.length)
  1194. return false;
  1195. if(str.substr(0,subStr.length)==subStr)
  1196. return true;
  1197. else
  1198. return false;
  1199. return true;
  1200. }
  1201. };
  1202. $.fn.softphones = function(method) {
  1203. if (qlSoftPhone[method]) {
  1204. return qlSoftPhone[method].apply(this, Array.prototype.slice.call(arguments, 1));
  1205. } else if (typeof method === 'object' || !method) {
  1206. return qlSoftPhone.init.apply(this, arguments);
  1207. } else {
  1208. $.error('Method ' + method + ' does not exist on softphones');
  1209. }
  1210. };
  1211. })(jQuery);