安图前端代码

main.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. var ws, n = 0,
  2. timer,hidTel,hidCallID,hidActionID;
  3. var lockReconnect = false; //避免重复连接
  4. var obj = {};
  5. var directType;
  6. var sendType;
  7. var mesCont;
  8. var eorrorConnect;
  9. var cls = 0;
  10. var lasttime = new Date().getTime();
  11. var errorState=false;
  12. var reconnecTion;
  13. var recon;
  14. var loginOr=false;
  15. //创建scoket连接
  16. function createWebSocket() {
  17. try {
  18. $("#top-search li i").removeClass("active");
  19. Connect();
  20. } catch(e) {
  21. //打印日志
  22. directType="lianjie";
  23. sendType="异常错误"; //JSON.stringify(data)
  24. mesCont=e.message;
  25. debuggerLog();
  26. reconnect();
  27. }
  28. }
  29. //连接
  30. function Connect() {
  31. ws = new WebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  32. ws.onopen = function() {
  33. console.log(new Date() + " " + "建立连接");
  34. heartCheck.reset().start();
  35. cls = 0;
  36. $(".Login").addClass("active");
  37. console.log(errorState);
  38. console.log(loginOr);
  39. if (errorState&&loginOr) {
  40. //自动签入
  41. errorState=false;
  42. obj.Type = "Login";
  43. obj.AgentType = "0";
  44. Send();
  45. directType="recive";
  46. sendType="自动签入 "; //JSON.stringify(data)
  47. debuggerLog();
  48. clearInterval(timer);
  49. }else{
  50. //签入
  51. Send();
  52. }
  53. //自动签入
  54. //lasttime = new Date().getTime();
  55. //obj.Type = "Login";
  56. //obj.AgentType = "0";
  57. //Send(); /*2018-05-19zhangshaungnan注释*/
  58. };
  59. //接收到消息的回调方法
  60. ws.onmessage = function(evt) {
  61. //如果获取到消息,心跳检测重置
  62. //拿到任何消息都说明当前连接是正常的
  63. heartCheck.reset().start();
  64. var myDate = new Date();
  65. console.log(myDate + " receive " + evt.data);
  66. var data = JSON.parse(evt.data)[0];
  67. //打印日志
  68. directType="recive";
  69. sendType=data.Type; //JSON.stringify(data)
  70. mesCont=JSON.stringify(data);
  71. debuggerLog()
  72. if(data) {
  73. var rlt = data.Result;
  74. if(rlt == true) {
  75. clearInterval(timer);
  76. //$('title').text('安图生物呼叫中心管理系统');
  77. var type = data.Type;
  78. if (eorrorConnect) {
  79. LoginBack();
  80. obj.Type = "Login";
  81. Send();
  82. eorrorConnect=false;
  83. }
  84. switch(type.toLowerCase()) {
  85. //case "heart": HeartBack(); break;//心跳
  86. case "login":
  87. LoginBack();
  88. break; //签入
  89. case "logout":
  90. LogoutBack();
  91. break; //签出
  92. case "dropcall":
  93. DropCallBack();
  94. break; //挂断
  95. case "makecall":
  96. MakeCallBack();
  97. break; //外呼
  98. case "setstate":
  99. SetState(data);
  100. break; //置忙置闲
  101. //case "saybusy": SayBusyBack(data); break;
  102. //case "sayfree": SayFreeBack(data); break;
  103. case "meeting":
  104. MeetingBack();
  105. break; //多方通话
  106. case "transfer":
  107. TransferBack();
  108. break; //转移
  109. case "hold":
  110. HoldBack();
  111. break; //保持
  112. case "retrieve":
  113. RetrieveBack();
  114. break; //接回
  115. case "incoming":
  116. IncomingBack(data);
  117. break; //来电
  118. case "subscribe":
  119. SubScribeBack();
  120. break; //监测
  121. case "subscribecancel":
  122. SubScribeCancelBack();
  123. break; //停止监测
  124. case "agentstate":
  125. AgentStateBack(data);
  126. break; //坐席状态
  127. case "linestate":
  128. LineStateBack(data);
  129. break; //线路状态
  130. case "motorsetstate":
  131. SayFreeBack();
  132. break; //班长置闲
  133. case "linestateagent":
  134. LineStateAgentBack(data);
  135. break; //线路状态通知
  136. // case "agentstateagent":
  137. // AgentStateAgentBack(data);
  138. // break; //坐席状态通知
  139. case "callid":
  140. CallIDBack(data);
  141. break; //获取callid
  142. case "recordpath":
  143. RecordPathBack(data);
  144. break; //录音返回
  145. }
  146. } else {
  147. if(rlt == false) {
  148. //$(".hwzt").text('操作失败!');
  149. //外呼失败的文字展示
  150. if (data.Type.toLowerCase() == "makecall") {
  151. switch (data.ErrorCode) {
  152. case 1: $(".hwzt").text(' 挂机,请重试!'); break;
  153. case 2: $(".hwzt").text(' FS外呼命令失败,请重试!'); break;
  154. case 3: $(".hwzt").text(' 外呼获取座席失败,请重试!'); break;
  155. case 4: $(".hwzt").text(' 座席置忙禁止座席外呼,请重试!'); break;
  156. case 5: $(".hwzt").text(' 主叫座席分机非空闲或摘机拨号,请重试!'); break;
  157. case 6: $(".hwzt").text(' 为外呼设置座席状态失败,请重试!'); break;
  158. case 7: $(".hwzt").text(' 被叫座席非空闲,请重试!'); break;
  159. case 8: $(".hwzt").text(' 执行分机呼叫失败, 未找到分机通道,请重试!'); break;
  160. case 9: $(".hwzt").text(' 执行分机呼叫失败, 无法绑定分机通道,请重试!'); break;
  161. case 10: $(".hwzt").text(' 禁止分机自呼,请重试!'); break;
  162. case 11: $(".hwzt").text(' 发送分机呼叫Esl命令失败,请重试!'); break;
  163. case 12: $(".hwzt").text(' 目标分机非空闲,请重试!'); break;
  164. case 13: $(".hwzt").text(' 主控通道非空闲,请重试!'); break;
  165. case 14: $(".hwzt").text(''); break;
  166. //case 14: $(".hwzt").text(' 校验不通过绑定本端逻辑线路失败,请重试!'); break;
  167. case 15: $(".hwzt").text(' 校验不通过本端当前线路忙,请重试!'); break;
  168. case 16: $(".hwzt").text(' 校验不通过对端线路状态忙,请重试!'); break;
  169. case 17: $(".hwzt").text(' 被叫关机,请重试!'); break;
  170. case 18: $(".hwzt").text(' 无效号码,请重试!'); break;
  171. case 19: $(".hwzt").text(' 无人接听,请重试!'); break;
  172. case 20: $(".hwzt").text(' 交换机错误(用户无法接通),请重试!'); break;
  173. case 21: $(".hwzt").text(' 话机外呼执行数据交换操作失败未找到分机通道,请重试!'); break;
  174. case 22: $(".hwzt").text(' 话机外呼执行数据交换操作失败分机通道未绑定任务,请重试!'); break;
  175. case 23: $(".hwzt").text(' 执行设备外呼任务失败无法获取对应线路,请重试!'); break;
  176. }
  177. }
  178. if(data.Type=='AcdConnectNotify'){
  179. $("#top-search li i").removeClass("active");
  180. $(".hwzt").text('Acd未连接');
  181. }
  182. } else {
  183. $(".hwzt").text(rlt);
  184. //layer.confirm(rlt, {
  185. // btn: ['确定']
  186. //});
  187. }
  188. }
  189. }
  190. };
  191. //连接关闭的回调方法
  192. ws.onclose = function(evt) {
  193. directType="recive";
  194. sendType="close"; //JSON.stringify(data)
  195. mesCont=JSON.stringify(evt);
  196. debuggerLog();
  197. if(cls == 0) {
  198. cls = 1;
  199. //console.log("连接关闭!");
  200. $(".hwzt").text('连接关闭!');
  201. $("#top-search li i").removeClass("active");
  202. showMsgNotification('呼叫系统提示', '话务连接关闭'); //暂时关闭
  203. reconnect();
  204. }
  205. };
  206. //连接发生错误的回调方法
  207. ws.onerror = function(evt) {
  208. directType="recive";
  209. sendType="连接错误 "; //JSON.stringify(data)
  210. mesCont=JSON.stringify(evt);
  211. debuggerLog();
  212. //产生异常
  213. $(".hwzt").text('连接出现异常!');
  214. showMsgNotification('呼叫系统提示', '连接出现异常'); //暂时关闭
  215. console.log(ws);
  216. if(ws == null || ws.readyState != ws.OPEN) {
  217. console.log(new Date() + "开始重连");
  218. reconnect();
  219. }
  220. };
  221. }
  222. //重连
  223. function reconnect() {
  224. if(lockReconnect) return;
  225. lockReconnect = true;
  226. //没连接上会一直重连,设置延迟避免请求过多
  227. setTimeout(function() {
  228. directType="send";
  229. sendType="重连中 "; //JSON.stringify(data)
  230. mesCont="重连中";
  231. debuggerLog();
  232. console.log(new Date() + " " + "重连中……");
  233. createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  234. lockReconnect = false;
  235. }, 2000);
  236. }
  237. function debuggerLog(){
  238. $.post(huayi.config.callcenter_url + 'Log/CallOpt', {
  239. direct: directType,
  240. type: sendType,
  241. cont: mesCont,
  242. "token": $.cookie("token")
  243. }, function(result) {
  244. result = $.parseJSON(result);
  245. if(result.state.toLowerCase() == "warning") {
  246. //layer.msg("创建工单成功");
  247. }
  248. })
  249. }
  250. //异常重连
  251. function errorFun(){
  252. clearInterval(timer);
  253. var errorNum=0
  254. timer = setInterval(function() {
  255. errorNum++;
  256. if (errorNum>2) {
  257. $(".hwzt").text('连接异常!');
  258. }else{
  259. $("#top-search li i").removeClass("active");
  260. $(".Login").addClass("active");
  261. $(".zxzt").removeClass("bl").addClass("br");
  262. $(".fwzt").removeClass("bl").addClass("br");
  263. $(".hwzt").text('');
  264. }
  265. reconnect();
  266. $(".hwzt").text('连接异常!');
  267. }, 15000);
  268. }
  269. noLine();
  270. clearInterval(recon);
  271. recon = setInterval(function () {
  272. if(loginOr){
  273. noLine();
  274. setTimeout(function () {
  275. lineState();
  276. }, 2000);
  277. }
  278. }, 1000*10);
  279. function lineState(){
  280. if (reconnecTion) {
  281. reconnecTion=false;
  282. }else{
  283. directType="send";
  284. sendType="断网 "; //JSON.stringify(data)
  285. mesCont="断网";
  286. debuggerLog();
  287. //errorState=true;
  288. //errorFun();
  289. // var numEorr=0;
  290. // numEorr++;
  291. // if (numEorr>2) {
  292. // $("#top-search li i").removeClass("active");
  293. // }
  294. // $("#top-search li i").removeClass("active");
  295. // $(".Login").addClass("active");
  296. // $(".zxzt").removeClass("bl").addClass("br");
  297. // $(".fwzt").removeClass("bl").addClass("br");
  298. // $(".hwzt").text('');
  299. // $(".hwzt").text('网络异常!');
  300. }
  301. }
  302. function noLine(){
  303. $.ajax({
  304. type: "get",
  305. url: huayi.config.callcenter_url + 'UserAccount/GetNowUser',
  306. async: true,
  307. dataType: 'json',
  308. data: {
  309. "token": $.cookie("token")
  310. },
  311. success: function(data) {
  312. reconnecTion = data.data.user.F_UserCode;
  313. }
  314. });
  315. }
  316. //发送
  317. function Send() {
  318. if(ws.readyState != ws.OPEN) {
  319. if(loginOr){
  320. errorState=true;
  321. $("#top-search li i").removeClass("active");
  322. $(".Login").addClass("active");
  323. $(".zxzt").removeClass("bl").addClass("br");
  324. $(".fwzt").removeClass("bl").addClass("br");
  325. $(".hwzt").text('');
  326. directType="send";
  327. sendType=ws.readyState; //JSON.stringify(data)
  328. mesCont="签入时异常了";
  329. debuggerLog();
  330. $(".hwzt").text('连接异常!');
  331. reconnect();
  332. }else{
  333. errorState=false;
  334. $("#top-search li i").removeClass("active");
  335. $(".Login").addClass("active");
  336. $(".zxzt").removeClass("bl").addClass("br");
  337. $(".fwzt").removeClass("bl").addClass("br");
  338. $(".hwzt").text('');
  339. directType="send";
  340. sendType=ws.readyState; //JSON.stringify(data)
  341. mesCont="异常了";
  342. debuggerLog();
  343. $(".hwzt").text('连接异常!');
  344. reconnect();
  345. }
  346. }
  347. if(ws.readyState == ws.OPEN) {
  348. if (obj.Type) {
  349. directType="send";
  350. sendType=obj.Type;
  351. mesCont=JSON.stringify(obj);
  352. debuggerLog()
  353. }else{
  354. directType="send";
  355. sendType="建立连接";
  356. mesCont=JSON.stringify(obj);
  357. debuggerLog()
  358. }
  359. console.log(new Date() + " send " + JSON.stringify(obj));
  360. ws.send(JSON.stringify(obj));
  361. }
  362. }
  363. //心跳检测
  364. var heartCheck = {
  365. timeout: 25000, //25秒
  366. timeoutObj: null,
  367. serverTimeoutObj: null,
  368. reset: function() {
  369. clearTimeout(this.timeoutObj);
  370. clearTimeout(this.serverTimeoutObj);
  371. return this;
  372. },
  373. start: function() {
  374. var self = this;
  375. this.timeoutObj = setTimeout(function() {
  376. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  377. //onmessage拿到返回的心跳就说明连接正常
  378. obj.Type = "Heart";
  379. Send();
  380. self.serverTimeoutObj = setTimeout(function() { //如果超过一定时间还没重置,说明后端主动断开了
  381. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  382. //同步签出状态
  383. $("#top-search li i").removeClass("active");
  384. $(".Login").addClass("active");
  385. $(".zxzt").removeClass("bl").addClass("br");
  386. $(".fwzt").removeClass("bl").addClass("br");
  387. $(".hwzt").text('');
  388. //打印日志
  389. directType="heart";
  390. sendType="心跳"; //JSON.stringify(data)
  391. mesCont="未收到";
  392. debuggerLog();
  393. if(cls == 0) {
  394. cls = 1;
  395. reconnect();
  396. }
  397. }, self.timeout)
  398. }, this.timeout)
  399. }
  400. }
  401. //签入
  402. function LoginBack() {
  403. loginOr=true;
  404. //心跳检测重置
  405. $("#top-search li i").removeClass("active");
  406. $(".Logout").addClass("active");
  407. $(".SayBusy").addClass("active");
  408. $(".MakeCall").addClass("active");
  409. $(".zxzt").removeClass("br").addClass("bl");
  410. $(".fwzt").removeClass("br").addClass("bl");
  411. $(".hwzt").text('空闲');
  412. }
  413. //签出
  414. function LogoutBack() {
  415. loginOr=false;
  416. $("#top-search li i").removeClass("active");
  417. $(".Login").addClass("active");
  418. $(".zxzt").removeClass("bl").addClass("br");
  419. $(".fwzt").removeClass("bl").addClass("br");
  420. $(".hwzt").text('');
  421. }
  422. //来电
  423. function IncomingBack(data) {
  424. if(data.CallID!=0){
  425. $(".hwzt").text('来电振铃'); //左下角状态显示
  426. var p = '<a href="javascript:;" class="active J_menuTab" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID=' + data.CallID + '">来电弹屏' + data.Number + ' <i class="fa fa-times-circle"></i></a>';
  427. $(".J_menuTab").removeClass("active");
  428. var nif = '<iframe class="J_iframe J_iframeNew" name="iframe'+ data.CallID +'" width="100%" height="100%" src="./callScreen/callScreen.html?Number=' + data.Number + '&CallID=' + data.CallID + '&ActionID=' + data.ActionID + '" frameborder="0" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID=' + data.CallID + '" seamless></iframe>';
  429. $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(nif);
  430. $(".J_menuTabs .page-tabs-content").append(p);
  431. hidTel=data.Number;
  432. hidCallID=data.CallID;
  433. hidActionID=data.ActionID;
  434. }else{
  435. $(".hwzt").text('来电振铃'); //左下角状态显示
  436. var timestamp = Date.parse(new Date());
  437. var p = '<a href="javascript:;" class="active J_menuTab" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID='+timestamp+'">来电弹屏' + data.Number + ' <i class="fa fa-times-circle"></i></a>';
  438. $(".J_menuTab").removeClass("active");
  439. var nif = '<iframe class="J_iframe J_iframeNew" name="iframe'+timestamp+'" width="100%" height="100%" src="./callScreen/callScreen.html?Number=' + data.Number + '&CallID='+timestamp+'" frameborder="0" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID='+timestamp+'" seamless></iframe>';
  440. $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(nif);
  441. $(".J_menuTabs .page-tabs-content").append(p);
  442. hidTel=data.Number;
  443. hidCallID=timestamp;
  444. }
  445. }
  446. //***************************************************
  447. function CallIDBack(data) {
  448. //$(".hidCallID").val(data.CurrID);
  449. }
  450. //挂断
  451. function DropCallBack() {
  452. $("#top-search li i").removeClass("active");
  453. $(".Logout").addClass("active");
  454. $(".SayBusy").addClass("active");
  455. $(".MakeCall").addClass("active");
  456. var obj = $("iframe:visible")
  457. // if (obj.attr("data-id") == './callScreen/callScreen.html?tel=' + hidTel + '&CallID=' + hidCallID + '') {
  458. // window.frames[obj.attr("name")].$(".td-call").hide();
  459. // window.frames['iframe'+ hidCallID +''].$(".td-call").hide();
  460. // }
  461. if(window.frames['iframe'+ hidCallID +'']){
  462. window.frames['iframe'+ hidCallID +''].$(".td-call").hide();
  463. }
  464. }
  465. //线路状态通知
  466. function LineStateAgentBack(data) {
  467. var objiframe = $("iframe:visible")
  468. //0分机不可用,1空闲,2摘机等待拨号,3正在拨号,4呼出振铃,5来电振铃,6通话中,7播放忙音中,8移除IP分机,9通话保持中
  469. if(data.State == '0') {
  470. $(".hwzt").text('分机不可用'); //左下角状态显示
  471. //$(".fwzt").removeClass("br").removeClass("bl");
  472. $(".fwzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加话机状态灯
  473. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  474. }
  475. if(data.State == '1') {
  476. // var isml=0;
  477. if($("#isml").val()==1){
  478. // isml=1;
  479. $(".hwzt").text('置忙'); //左下角状态显示
  480. $(".zxzt").removeClass("bl").addClass("br");
  481. }
  482. else{
  483. $(".hwzt").text('空闲'); //左下角状态显示
  484. $(".zxzt").removeClass("br").addClass("bl");
  485. }
  486. $(".fwzt").removeClass("br").addClass("bl");
  487. // $(".zxzt").removeClass("br").addClass("bl");//20180509 by fanlongfei 增加坐席状态灯
  488. if(window.frames['iframe'+ hidCallID +'']){
  489. window.frames['iframe'+ hidCallID +''].clearInter();
  490. }
  491. //2019-03-26 clq 作废挂机
  492. //if (hidTel && hidCallID) {
  493. // $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateGJ', {
  494. // callid: hidTel,
  495. // "token": $.cookie("token")
  496. // }, function (result) {
  497. // result = JSON.parse(result);
  498. // if (result.state.toLowerCase() == "success") { }
  499. // })
  500. // }
  501. $("#top-search li i").removeClass("active");
  502. $(".Logout").addClass("active");
  503. if($("#isml").val()==0){
  504. $(".SayBusy").addClass("active");
  505. }
  506. else{
  507. $(".SayFree").addClass("active");
  508. }
  509. $(".MakeCall").addClass("active");
  510. if(window.frames['iframe'+ hidCallID +'']){
  511. window.frames['iframe'+ hidCallID +''].$(".td-call").hide();
  512. }
  513. }
  514. if(data.State == '2') {
  515. $(".hwzt").text('摘机等待拨号'); //左下角状态显示
  516. }
  517. if(data.State == '3') {
  518. $(".hwzt").text('正在拨号'); //左下角状态显示
  519. }
  520. if(data.State == '4') {
  521. $(".hwzt").text('呼出振铃'); //左下角状态显示
  522. }
  523. if(data.State == '5') {
  524. $(".hwzt").text('来电振铃'); //左下角状态显示
  525. //$(".fwzt").removeClass("bl").addClass("br");
  526. $(".fwzt").removeClass("br").addClass("bl");//20180509 by fanlongfei 增加话机状态灯
  527. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  528. if (hidTel && hidCallID) {
  529. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZL', {
  530. callid: hidCallID,
  531. "token": $.cookie("token")
  532. }, function (result) {
  533. result = JSON.parse(result);
  534. if (result.state.toLowerCase() == "success") { }
  535. })
  536. }
  537. }
  538. if(data.State == '6') {
  539. $(".hwzt").text('通话中'); //左下角状态显示
  540. $(".fwzt").removeClass("bl").addClass("br");
  541. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  542. if(hidTel && hidCallID) {
  543. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZJ', {
  544. callid: hidCallID,
  545. "token": $.cookie("token")
  546. }, function(result) {
  547. result = JSON.parse(result);
  548. if(result.state.toLowerCase() == "success") {}
  549. })
  550. }
  551. $("#top-search li i").removeClass("active");
  552. $(".DropCall").addClass("active");
  553. $(".Hold").addClass("active");
  554. $(".Transfer").addClass("active");
  555. $(".Meeting").addClass("active");
  556. var aaa=data.CallDirection;
  557. if(data.CallDirection=="in"){
  558. // if (objiframe.attr("data-id") == './callScreen/callScreen.html?tel=' + hidTel + '&CallID=' + hidCallID + '') {
  559. setTimeout(window.frames['iframe'+ hidCallID +''].calling(),500);/*2018-05-19 zhangshuangnan 修改 ps: 因软电话设置为 自动应答 通话时间不计时问题*/
  560. // }
  561. }
  562. }
  563. if(data.State == '7') {
  564. $(".hwzt").text('播放忙音中'); //左下角状态显示
  565. }
  566. if(data.State == '8') {
  567. $(".hwzt").text('移除IP分机'); //左下角状态显示
  568. }
  569. if(data.State == '9') {
  570. $(".hwzt").text('通话保持中'); //左下角状态显示
  571. }
  572. }
  573. function toDub(i) {
  574. return i < 10 ? "0" + i : "" + i;
  575. }
  576. //外呼
  577. function MakeCallBack() {
  578. $("#top-search li i").removeClass("active");
  579. $(".DropCall").addClass("active");
  580. // window.frames[obj.attr("name")].calling();
  581. }
  582. //置忙置闲
  583. function SetState(obj) {
  584. if(obj.State == '5') {
  585. $(".SayBusy").removeClass("active");
  586. $(".SayFree").addClass("active");
  587. $(".zxzt").removeClass("bl").addClass("br");
  588. $(".hwzt").text('置忙');
  589. $("#isml").val(1)
  590. }
  591. if(obj.State == '2') {
  592. $(".SayBusy").addClass("active");
  593. $(".SayFree").removeClass("active");
  594. $(".zxzt").removeClass("br").addClass("bl");
  595. $(".hwzt").text('空闲');
  596. $("#isml").val(0)
  597. }
  598. }
  599. //置忙
  600. function SayBusyBack() {
  601. $(".SayBusy").removeClass("active");
  602. $(".SayFree").addClass("active");
  603. $("#isml").val(1)
  604. }
  605. //坐席班长置闲
  606. function SayFreeBack() {
  607. $(".SayBusy").addClass("active");
  608. $(".SayFree").removeClass("active");
  609. $(".zxzt").removeClass("br").addClass("bl"); // 2018/05/09 by fanlongfei 增加坐席状态指示
  610. $(".hwzt").text('空闲');// 2018/05/09 by fanlongfei 增加坐席状态指示
  611. $("#isml").val(0)
  612. }
  613. //多方通话
  614. function MeetingBack() {
  615. }
  616. //转移
  617. function TransferBack() {
  618. $("#top-search li i").removeClass("active");
  619. $(".Logout").addClass("active");
  620. $(".SayBusy").addClass("active");
  621. $(".MakeCall").addClass("active");
  622. }
  623. //保持
  624. function HoldBack() {
  625. $(".Hold").removeClass("active");
  626. $(".Retrieve").addClass("active");
  627. }
  628. //接回
  629. function RetrieveBack() {
  630. $(".Hold").addClass("active");
  631. $(".Retrieve").removeClass("active");
  632. }
  633. //监测
  634. function SubScribeBack() {
  635. $('#content-main .J_iframeNew').each(function(i,n){
  636. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  637. window.frames[$(this).attr("name")].Start();
  638. }
  639. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  640. }
  641. //取消监测
  642. function SubScribeCancelBack() {
  643. // var obj = $("iframe:visible")
  644. // if(obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  645. // window.frames[obj.attr("name")].();
  646. // }
  647. $('#content-main .J_iframeNew').each(function(i,n){
  648. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  649. window.frames[$(this).attr("name")].Stop();
  650. }
  651. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  652. }
  653. //班长监测返回状态
  654. //坐席状态
  655. function AgentStateBack(data) {
  656. $('#content-main .J_iframeNew').each(function(i,n){
  657. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  658. window.frames[$(this).attr("name")].UpdateAgentState(data.AgentID, data.State);
  659. }
  660. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  661. }
  662. //线路状态
  663. function LineStateBack(data) {
  664. $('#content-main .J_iframeNew').each(function(i,n){
  665. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  666. window.frames[$(this).attr("name")].UpdateLineState(data.AgentID, data.State);
  667. }
  668. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  669. }
  670. //录音返回
  671. function RecordPathBack(data) {
  672. $(".hidCallID").val(data.CallID);
  673. //if ($(".hidTel").val() && $(".hidCallID").val()) {
  674. // $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', { callid: $(".hidCallID").val(),path:data.RecPath, "token": $.cookie("token") }, function (result) {
  675. // result = JSON.parse(result);
  676. // if (result.state.toLowerCase() == "success") {
  677. // }
  678. // })
  679. //}
  680. if(hidTel) {
  681. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', {
  682. callid: data.CallID,
  683. path: data.RecPath,
  684. "token": $.cookie("token")
  685. }, function(result) {
  686. result = JSON.parse(result);
  687. if(result.state.toLowerCase() == "success") {}
  688. })
  689. }
  690. }
  691. //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
  692. function getNowFormatDate() {
  693. var date = new Date();
  694. var seperator1 = "-";
  695. var seperator2 = ":";
  696. var month = date.getMonth() + 1;
  697. var strDate = date.getDate();
  698. if(month >= 1 && month <= 9) {
  699. month = "0" + month;
  700. }
  701. if(strDate >= 0 && strDate <= 9) {
  702. strDate = "0" + strDate;
  703. }
  704. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
  705. " " + date.getHours() + seperator2 + date.getMinutes() +
  706. seperator2 + date.getSeconds();
  707. return currentdate;
  708. }
  709. //桌面弹出提示
  710. function showMsgNotification(title, msg) {
  711. // var Notification = window.Notification || window.mozNotification || window.webkitNotification;
  712. //
  713. // if(Notification) {//支持桌面通知
  714. // if(Notification.permission == "granted") {//已经允许通知
  715. // var instance = new Notification(title, {
  716. // body: msg,
  717. // tag:msg,
  718. // icon: "img/tips.png",
  719. // requireInteraction:true,
  720. // renotify:true
  721. //
  722. // });
  723. //
  724. // instance.onclick = function() {
  725. //// $('body').css({'background': 'red'});
  726. //// console.log('onclick');
  727. //// instance.close();
  728. // };
  729. // instance.onerror = function() {
  730. // console.log('onerror');
  731. // };
  732. // instance.onshow = function() {
  733. // console.log('onshow');
  734. // };
  735. // instance.onclose = function() {
  736. // console.log('onclose');
  737. // };
  738. // }else {//第一次询问或已经禁止通知(如果用户之前已经禁止显示通知,那么浏览器不会再次询问用户的意见,Notification.requestPermission()方法无效)
  739. // Notification.requestPermission(function(status) {
  740. // if (status === "granted") {//用户允许
  741. // var instance = new Notification(title, {
  742. // body: msg,
  743. // tag:msg,
  744. // icon: "img/tips.png",
  745. // requireInteraction:true,
  746. // renotify:true
  747. // });
  748. //
  749. // instance.onclick = function() {
  750. // // Something to do
  751. // };
  752. // instance.onerror = function() {
  753. // // Something to do
  754. // };
  755. // instance.onshow = function() {
  756. // // Something to do
  757. // };
  758. // instance.onclose = function() {
  759. // // Something to do
  760. // };
  761. // }else {//用户禁止
  762. // return false
  763. // }
  764. // });
  765. // }
  766. // }else {//不支持(IE等)
  767. var index = 0;
  768. clearInterval(timer);
  769. timer = setInterval(function() {
  770. if(index%2) {
  771. $('title').text('【 】'+ title);//这里是中文全角空格,其他不行
  772. }else {
  773. $('title').text('【'+ msg+'】'+ title);
  774. }
  775. index++;
  776. // if(index > 20) {
  777. // clearInterval(timer);
  778. // }
  779. }, 500);
  780. // }
  781. }