Bez popisu

main.js 25KB

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