No Description

main.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. if (typeof console == "undefined") {
  2. this.console = { log: function (msg) { } };
  3. }
  4. // 如果浏览器不支持websocket,会使用这个flash自动模拟websocket协议,此过程对开发者透明
  5. WEB_SOCKET_SWF_LOCATION = "./js/websocket/WebSocketMain.swf";
  6. // 开启flash的websocket debug
  7. WEB_SOCKET_DEBUG = true;
  8. var ws, n = 0,
  9. timer;
  10. var lockReconnect = false; //避免重复连接
  11. var obj = {};
  12. var Statess;
  13. var cls = 0;
  14. var lasttime = new Date().getTime();
  15. //创建scoket连接
  16. function createWebSocket() {
  17. try {
  18. $("#top-search li i").removeClass("active");
  19. Connect();
  20. } catch (e) {
  21. reconnect();
  22. }
  23. }
  24. //连接
  25. function Connect() {
  26. ws = new WebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  27. ws.onopen = function () {
  28. console.log(new Date() + " " + "建立连接");
  29. //心跳检测重置
  30. heartCheck.reset().start();
  31. cls = 0;
  32. $(".Login").addClass("active");
  33. lasttime = new Date().getTime();
  34. //自动签入
  35. // if ($.cookie("socket_state") != null) {
  36. // SetLogin($.cookie("socket_state"));
  37. // }
  38. //$(".hwzt").text('连接成功!');
  39. };
  40. //接收到消息的回调方法
  41. ws.onmessage = function (evt) {
  42. //如果获取到消息,心跳检测重置
  43. //拿到任何消息都说明当前连接是正常的
  44. heartCheck.reset().start();
  45. var myDate = new Date();
  46. console.log(myDate + " receive " + evt.data);
  47. var data = JSON.parse(evt.data)[0];
  48. if (data) {
  49. var rlt = data.Result;
  50. if (rlt == true) {
  51. var type = data.Type;
  52. switch (type.toLowerCase()) {
  53. //case "heart": HeartBack(); break;//心跳
  54. case "login":
  55. LoginBack();
  56. break; //签入
  57. case "logout":
  58. LogoutBack();
  59. break; //签出
  60. case "dropcall":
  61. DropCallBack();
  62. break; //挂断
  63. case "makecall":
  64. MakeCallBack();
  65. break; //外呼
  66. case "setstate":
  67. SetState(data);
  68. break; //置忙置闲
  69. //case "saybusy": SayBusyBack(data); break;
  70. //case "sayfree": SayFreeBack(data); break;
  71. case "meeting":
  72. MeetingBack();
  73. break; //多方通话
  74. case "meetingtakeback":
  75. MeetingTakeBackFun();
  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. case "getagentlist":
  117. GetAgentListBack(data);
  118. break;//在线坐席信息
  119. case "confirmtransfer":
  120. ConfirmTransfer(data);
  121. break;//确认转移 取消转移
  122. case "consult":
  123. ConsultationCall();
  124. break;//协商呼叫
  125. }
  126. } else {
  127. if (rlt == false) {
  128. //layer.confirm('操作失败!', {
  129. // btn: ['确定']
  130. //});
  131. $(".hwzt").text('操作失败!');
  132. } else {
  133. $(".hwzt").text(rlt);
  134. //layer.confirm(rlt, {
  135. // btn: ['确定']
  136. //});
  137. switch (data.Type.toLowerCase()) {
  138. case "waitcount":
  139. backstageQueue(data);
  140. break;//后台排队
  141. }
  142. }
  143. }
  144. }
  145. };
  146. //连接关闭的回调方法
  147. ws.onclose = function (evt) {
  148. if (cls == 0) {
  149. cls = 1;
  150. //console.log("连接关闭!");
  151. //layer.confirm('连接关闭!', {
  152. // btn: ['确定']
  153. //});
  154. $(".hwzt").text('连接关闭!');
  155. $("#top-search li i").removeClass("active");
  156. reconnect();
  157. }
  158. };
  159. //连接发生错误的回调方法
  160. ws.onerror = function (evt) {
  161. //产生异常
  162. $(".hwzt").text('连接出现异常!');
  163. console.log(ws);
  164. if (ws == null || ws.readyState != ws.OPEN) {
  165. console.log(new Date() + "开始重连");
  166. reconnect();
  167. }
  168. };
  169. }
  170. //重连
  171. function reconnect() {
  172. if (lockReconnect) return;
  173. lockReconnect = true;
  174. //没连接上会一直重连,设置延迟避免请求过多
  175. setTimeout(function () {
  176. console.log(new Date() + " " + "重连中……");
  177. createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  178. lockReconnect = false;
  179. }, 2000);
  180. }
  181. //发送
  182. function Send() {
  183. if (ws.readyState != ws.OPEN) {
  184. reconnect();
  185. }
  186. if (ws.readyState == ws.OPEN) {
  187. console.log(new Date() + " send " + JSON.stringify(obj));
  188. ws.send(JSON.stringify(obj));
  189. }
  190. }
  191. //心跳检测
  192. var heartCheck = {
  193. timeout: 25000, //25秒
  194. timeoutObj: null,
  195. serverTimeoutObj: null,
  196. reset: function () {
  197. clearTimeout(this.timeoutObj);
  198. clearTimeout(this.serverTimeoutObj);
  199. return this;
  200. },
  201. start: function () {
  202. var self = this;
  203. this.timeoutObj = setTimeout(function () {
  204. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  205. //onmessage拿到返回的心跳就说明连接正常
  206. obj.Type = "Heart";
  207. Send();
  208. self.serverTimeoutObj = setTimeout(function () { //如果超过一定时间还没重置,说明后端主动断开了
  209. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  210. }, self.timeout)
  211. }, this.timeout)
  212. }
  213. }
  214. //签入
  215. function LoginBack() {
  216. $("#top-search li i").removeClass("active");
  217. $(".Logout").addClass("active");
  218. $(".SayBusy").addClass("active");
  219. $(".MakeCall").addClass("active");
  220. $(".zxzt").removeClass("br").addClass("bl");
  221. $(".fwzt").removeClass("br").addClass("bl");
  222. $(".hwzt").text('');
  223. $('.Consult').addClass("active");
  224. // if($.cookie("socket_state") == null){
  225. // SetStateCookie(0);
  226. // }
  227. $("#isml").val(1);
  228. // SetStateCookie(1);
  229. obj.Type = "SayBusy";
  230. Send();
  231. }
  232. //签出
  233. function LogoutBack() {
  234. $("#top-search li i").removeClass("active");
  235. $(".Login").addClass("active");
  236. $(".zxzt").removeClass("bl").addClass("br");
  237. $(".fwzt").removeClass("bl").addClass("br");
  238. $(".hwzt").text('');
  239. // SetStateCookie(2);
  240. }
  241. //来电
  242. function IncomingBack(data) {
  243. $(".ldhm").val(data.Number);
  244. $(".hidTel").val(data.Number);
  245. $(".tel").text(data.Number);
  246. $(".ldtime").text(getNowFormatDate());
  247. $(".thsc").text("00:00");
  248. $(".hidCallID").val(data.CallID);
  249. //获取电话所属地
  250. $.getJSON(huayi.config.callcenter_url + 'CallInScreen/GetPhoneLocation', {
  251. "tel": $(".hidTel").val(),
  252. "token": $.cookie("token")
  253. }, function (result) {
  254. if (result.state.toLowerCase() == "success") {
  255. $(".ldlocation").text(result.data[0].F_Name);
  256. $(".khgsd").text(result.data[0].F_Name);
  257. }
  258. })
  259. //获取客户信息
  260. $(".ttsdh").text($(".hidTel").val());
  261. $(".tsdh").val($(".hidTel").val());
  262. $.getJSON(huayi.config.callcenter_url + 'CallInScreen/GetCustomerByTel', {
  263. "tel": $(".hidTel").val(),
  264. "token": $.cookie("token")
  265. }, function (result) {
  266. if (result.state.toLowerCase() == "success") {
  267. if (result.data.length > 0) {
  268. $(".khmc").val(result.data[0].F_CustomerName);
  269. $(".tkhmc").text(result.data[0].F_CustomerName);
  270. $("#khid").val(result.data[0].F_CustomerId);
  271. $(".lxdh").val(result.data[0].F_Telephone);
  272. //$(".tsdh").val(result.data[0].F_Mobile);
  273. //$(".ttsdh").text(result.data[0].F_Mobile);
  274. $(".lxr").val(result.data[0].F_CustomerEName);
  275. $(".postcode").val(result.data[0].F_PostCode);
  276. $(".email").val(result.data[0].F_Email);
  277. }
  278. else {
  279. $(".khmc").val("");
  280. $(".tkhmc").text("");
  281. $("#khid").val("");
  282. $(".lxr").val("");
  283. $(".postcode").val("");
  284. $(".email").val("");
  285. }
  286. }
  287. })
  288. $('.maxOpen').trigger("click");
  289. $('.head-pic .lahei .la-before').show();
  290. //触发来电类型第一个 点击;
  291. $("#dicValueList li:first-child").find("label").trigger('click');
  292. $('.head-pic .lahei .la-after').hide();
  293. $(".Bacha").hide();
  294. }
  295. //挂断
  296. function DropCallBack() {
  297. debugger
  298. $("#top-search li i").removeClass("active");
  299. $(".Logout").addClass("active");
  300. $(".SayBusy").removeClass("active");
  301. $(".SayFree").addClass("active");
  302. $(".MakeCall").addClass("active");
  303. $(".td-call").hide();
  304. $(".zxzt").removeClass("bl").removeClass("br").addClass("by");
  305. $(".hwzt").text('忙碌');
  306. $("#isml").val(1);
  307. // SetStateCookie(1);
  308. obj.Type = "SayBusy";
  309. Send();
  310. //$('.ldtp-con').css("display", 'none');
  311. }
  312. //线路状态通知
  313. function LineStateAgentBack(data) {
  314. //0分机不可用,1空闲,2摘机等待拨号,3正在拨号,4呼出振铃,5来电振铃,6通话中,7播放忙音中,8移除IP分机,9通话保持中
  315. if (data.State == '0') {
  316. $(".hwzt").text('分机不可用'); //左下角状态显示
  317. $(".fwzt").removeClass("br").removeClass("bl");
  318. }
  319. if (data.State == '1') {
  320. if($("#isml").val()==1){
  321. // isml=1;
  322. $(".hwzt").text('置忙'); //左下角状态显示
  323. $(".fwzt").removeClass("bl").addClass("br");
  324. }
  325. else{
  326. if ($("#RoleCode").val()=='ZJZY') {
  327. $(".hwzt").text('置忙'); //左下角状态显示
  328. $(".fwzt").removeClass("bl").addClass("br");
  329. }else{
  330. $(".hwzt").text('空闲'); //左下角状态显示
  331. $(".fwzt").removeClass("br").addClass("bl");
  332. }
  333. }
  334. // $(".hwzt").text('空闲'); //左下角状态显示
  335. // $(".fwzt").removeClass("br").addClass("bl");
  336. clearInterval(timer);
  337. //2018-10-13 clq 作废挂机
  338. //if ($(".hidTel").val() && $(".hidCallID").val()) {
  339. // $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateGJ', {
  340. // callid: $(".hidCallID").val(),
  341. // "token": $.cookie("token")
  342. // }, function (result) {
  343. // result = JSON.parse(result);
  344. // if (result.state.toLowerCase() == "success") { }
  345. // })
  346. //}
  347. $("#top-search li i").removeClass("active");
  348. $(".Logout").addClass("active");
  349. if($("#isml").val()==0){
  350. $(".SayBusy").addClass("active");
  351. }
  352. else{
  353. $(".SayFree").addClass("active");
  354. }
  355. // $(".SayBusy").addClass("active");
  356. $(".MakeCall").addClass("active");
  357. $(".td-call").hide();
  358. $(".Bacha").show();
  359. //$(".hidTel").val("");
  360. //$(".hidCallID").val("");
  361. }
  362. if (data.State == '2') {
  363. $(".hwzt").text('摘机等待拨号'); //左下角状态显示
  364. }
  365. if (data.State == '3') {
  366. $(".hwzt").text('正在拨号'); //左下角状态显示
  367. }
  368. if (data.State == '4') {
  369. $(".hwzt").text('呼出振铃'); //左下角状态显示
  370. }
  371. if (data.State == '5') {
  372. $(".hwzt").text('来电振铃'); //左下角状态显示
  373. $(".fwzt").removeClass("bl").addClass("br");
  374. if ($(".hidTel").val() && $(".hidCallID").val()) {
  375. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZL', {
  376. callid: $(".hidCallID").val(),
  377. "token": $.cookie("token")
  378. }, function (result) {
  379. result = JSON.parse(result);
  380. if (result.state.toLowerCase() == "success") { }
  381. })
  382. }
  383. }
  384. if (data.State == '6') {
  385. $(".hwzt").text('通话中'); //左下角状态显示
  386. $(".fwzt").removeClass("bl").addClass("br");
  387. $(".zxzt").removeClass("bl").addClass("br");
  388. if ($(".hidTel").val() && $(".hidCallID").val()) {
  389. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZJ', {
  390. callid: $(".hidCallID").val(),
  391. "token": $.cookie("token")
  392. }, function (result) {
  393. result = JSON.parse(result);
  394. if (result.state.toLowerCase() == "success") { }
  395. })
  396. }
  397. $(".td-call").show();
  398. n = 0;
  399. $("#top-search li i").removeClass("active");
  400. $(".DropCall").addClass("active");
  401. $(".Hold").addClass("active");
  402. $(".Transfer").addClass("active");
  403. $(".Meeting").addClass("active");
  404. $('.TurnIvr').addClass("active");
  405. $('.Consult').addClass("active");
  406. clearInterval(timer);
  407. timer = setInterval(function () {
  408. n++;
  409. var m = parseInt(n / 60 % 60);
  410. var s = parseInt(n % 60);
  411. $(".thsc").text(toDub(m) + ":" + toDub(s));
  412. }, 1000);
  413. }
  414. if (data.State == '7') {
  415. $(".hwzt").text('播放忙音中'); //左下角状态显示
  416. }
  417. if (data.State == '8') {
  418. $(".hwzt").text('移除IP分机'); //左下角状态显示
  419. }
  420. if (data.State == '9') {
  421. $(".hwzt").text('通话保持中'); //左下角状态显示
  422. }
  423. }
  424. //坐席状态通知
  425. function AgentStateAgentBack(data) {
  426. var strr = '';
  427. console.log('坐席状态'+ data.State );
  428. switch (data.State+"") {
  429. case "0":
  430. strr = "离线";
  431. $(".zxzt").removeClass("br").removeClass("bl").removeClass("by");
  432. break; //离线
  433. case "1":
  434. break; //登录中
  435. case "2":
  436. strr = "空闲";
  437. $(".zxzt").removeClass("br").removeClass("by").addClass("bl");
  438. break; //空闲
  439. case "3":
  440. strr = "通话中";
  441. $(".zxzt").removeClass("bl").removeClass("by").addClass("br");
  442. break; //通话中
  443. case "4":
  444. strr = "话后处理中";
  445. $(".zxzt").removeClass("bl").removeClass("br").addClass("by");
  446. break; //话后处理中
  447. case "5":
  448. strr = "忙碌";
  449. $(".zxzt").removeClass("bl").removeClass("br").addClass("by");
  450. break; //小休
  451. case "6":
  452. strr = "振铃";
  453. break; //被请求
  454. case "7":
  455. strr = "注销";
  456. $(".zxzt").removeClass("br").removeClass("bl").removeClass("by");
  457. break; //注销
  458. }
  459. $(".hxzt").text(strr);
  460. }
  461. function toDub(i) {
  462. return i < 10 ? "0" + i : "" + i;
  463. }
  464. //外呼
  465. function MakeCallBack() {
  466. $("#top-search li i").removeClass("active");
  467. $(".DropCall").addClass("active");
  468. $(".Meeting").addClass("active");
  469. }
  470. //默认记忆上次是否签入,是否置忙置闲 0表示已签入 空闲,1表示签入置忙,2表示签出
  471. function SetStateCookie(state) {
  472. $.cookie("socket_state", state);
  473. }
  474. //置忙 置闲
  475. function SetState(obj) {
  476. if (obj.State == '5') {
  477. $(".SayBusy").removeClass("active");
  478. $(".SayFree").addClass("active");
  479. $(".zxzt").removeClass("bl").removeClass("br").addClass("by");
  480. $(".hwzt").text('忙碌');
  481. $("#isml").val(1);
  482. // SetStateCookie(1);
  483. }
  484. if (obj.State == '2') {
  485. $(".SayBusy").addClass("active");
  486. $(".SayFree").removeClass("active");
  487. $(".zxzt").removeClass("br").removeClass("by").addClass("bl");
  488. $(".hwzt").text('空闲');
  489. $("#isml").val(0);
  490. // SetStateCookie(0);
  491. }
  492. }
  493. // 自动签入
  494. // function SetLogin(state) {
  495. // if (state == 2) { return; }
  496. // if (obj.AgentID) {
  497. // obj.Type = "Login";
  498. // if( $("#RoleCode").val()=='DBHWY'){
  499. // obj.AgentGroup = "1";
  500. // }
  501. // else if($("#RoleCode").val()=='ZJZY'){
  502. // obj.AgentGroup = "2";
  503. // }
  504. // else{
  505. // obj.AgentGroup = "364";
  506. // }
  507. // obj.AgentType = "0";
  508. // Send();
  509. // }
  510. // if (state == 1) {
  511. // setTimeout('SayBusy()', 500);
  512. // }
  513. // }
  514. //置忙
  515. function SayBusy() {
  516. if (obj.AgentID) {
  517. obj.Type = "SayBusy";
  518. Send();
  519. }
  520. }
  521. //置忙
  522. function SayBusyBack() {
  523. $(".SayBusy").removeClass("active");
  524. $(".SayFree").addClass("active");
  525. $("#isml").val(1)
  526. }
  527. //置闲
  528. function SayFreeBack() {
  529. $(".SayBusy").addClass("active");
  530. $(".SayFree").removeClass("active");
  531. $(".zxzt").removeClass("br").addClass("bl"); //坐席状态指示
  532. $(".hwzt").text('空闲');// 增加坐席状态指示
  533. $("#isml").val(0)
  534. }
  535. //多方通话
  536. function MeetingBack() {
  537. $(".MeetingTakeBack").addClass("active");
  538. }
  539. //多方通话回签
  540. function MeetingTakeBackFun() {
  541. $(".MeetingTakeBack").removeClass("active");
  542. }
  543. //转移
  544. function TransferBack() {
  545. $("#top-search li i").removeClass("active");
  546. $(".Logout").addClass("active");
  547. $(".SayBusy").addClass("active");
  548. $(".MakeCall").addClass("active");
  549. }
  550. //保持
  551. function HoldBack() {
  552. $(".Hold").removeClass("active");
  553. $(".Retrieve").addClass("active");
  554. }
  555. //接回
  556. function RetrieveBack() {
  557. $(".Hold").addClass("active");
  558. $(".Retrieve").removeClass("active");
  559. }
  560. //协商呼叫
  561. function ConsultationCall() {
  562. $('.Consult').removeClass("active");
  563. $('.ConfirmTransfer').addClass("active");//确认转移
  564. $('.CancelTransfer').addClass("active");//取消转移
  565. }
  566. //确认转移&取消转移
  567. function ConfirmTransfer(data) {
  568. if (data.State == 3) {//取消转移
  569. $('.Consult').addClass("active");
  570. $(".CancelTransfer").removeClass("active");
  571. $(".ConfirmTransfer").removeClass("active");
  572. } else {
  573. //确认转移
  574. $('.Consult').removeClass("active");
  575. $(".CancelTransfer").removeClass("active");
  576. $(".ConfirmTransfer").removeClass("active");
  577. }
  578. }
  579. //监测
  580. function SubScribeBack() {
  581. var obj = $("iframe:visible")
  582. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  583. window.frames[obj.attr("name")].Start();
  584. }
  585. if (obj.attr("data-id") == "./TelCall/zxKong.html") {
  586. window.frames[obj.attr("name")].Start();
  587. }
  588. }
  589. //取消监测
  590. function SubScribeCancelBack() {
  591. var obj = $("iframe:visible")
  592. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  593. window.frames[obj.attr("name")].Stop();
  594. }
  595. if (obj.attr("data-id") == "./TelCall/zxKong.html") {
  596. window.frames[obj.attr("name")].Stop();
  597. }
  598. }
  599. //班长监测返回状态
  600. //坐席状态
  601. function AgentStateBack(data) {
  602. var obj = $("iframe:visible")
  603. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  604. window.frames[obj.attr("name")].UpdateAgentState(data.AgentID, data.State);
  605. }
  606. if (obj.attr("data-id") == "./TelCall/zxKong.html") {
  607. window.frames[obj.attr("name")].UpdateAgentState(data.AgentID, data.State);
  608. }
  609. }
  610. //线路状态
  611. function LineStateBack(data) {
  612. var obj = $("iframe:visible")
  613. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  614. window.frames[obj.attr("name")].UpdateLineState(data.AgentID, data.State);
  615. }
  616. if (obj.attr("data-id") == "./TelCall/zxKong.html") {
  617. window.frames[obj.attr("name")].UpdateLineState(data.AgentID, data.State);
  618. }
  619. }
  620. //后台排队
  621. function backstageQueue(data) {
  622. var obj = $("iframe:visible")
  623. if (obj.attr("data-id") == "index_v1.html") {
  624. window.frames[obj.attr("name")].realTimeMonitorQueue(data.WaitCount);
  625. }
  626. }
  627. //录音返回
  628. function RecordPathBack(data) {
  629. //if ($(".hidTel").val() && $(".hidCallID").val()) {
  630. // $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', { callid: $(".hidCallID").val(),path:data.RecPath, "token": $.cookie("token") }, function (result) {
  631. // result = JSON.parse(result);
  632. // if (result.state.toLowerCase() == "success") {
  633. // }
  634. // })
  635. //}
  636. if ($(".hidTel").val()) {
  637. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', {
  638. callid: data.CallID,
  639. path: data.RecPath,
  640. "token": $.cookie("token")
  641. }, function (result) {
  642. result = JSON.parse(result);
  643. if (result.state.toLowerCase() == "success") { }
  644. })
  645. }
  646. }
  647. //在线坐席信息
  648. function GetAgentListBack(data) {
  649. console.log(data)
  650. $.ajax({
  651. type: "get",
  652. url: huayi.config.callcenter_url + "SeatMonitoring/GetAgentList",
  653. async: true,
  654. dataType: 'json',
  655. data: {
  656. "token": $.cookie("token")
  657. },
  658. success: function (result) {
  659. var user = result.data;
  660. $(user).each(function (j, m) {
  661. $(data.AgentList).each(function (k, g) {
  662. if (g.AgentID == m.UserCode) {
  663. g.userName = m.UserName;
  664. }
  665. })
  666. })
  667. $(data.AgentList).each(function (k, m) {
  668. var strr = '';
  669. switch (m.State) {
  670. case "0":
  671. strr = "离线";
  672. break; //离线
  673. case "1":
  674. break; //登录中
  675. case "2":
  676. strr = "空闲";
  677. break; //空闲
  678. case "3":
  679. strr = "通话中";
  680. break; //通话中
  681. case "4":
  682. strr = "话后处理中";
  683. break; //话后处理中
  684. case "5":
  685. strr = "忙碌";
  686. break; //小休
  687. case "6":
  688. strr = "振铃";
  689. break; //被请求
  690. case "7":
  691. strr = "注销";
  692. break; //注销
  693. }
  694. var html = '<tr fjh="' + m.AgentExten + '">' +
  695. '<td>' + (m.userName ? '' : m.userName) + '</td>' //姓名
  696. +
  697. '<td>' + m.AgentID + '</td>' //工号
  698. +
  699. '<td>' + m.AgentExten + '</td>'//分机号
  700. +
  701. '<td class=" ' + m.UserCode + 'state">' + strr + '</td>' //状态
  702. +
  703. '</tr>';
  704. $(html).appendTo("#zxTable tbody");
  705. })
  706. }
  707. });
  708. }
  709. //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
  710. function getNowFormatDate() {
  711. var date = new Date();
  712. var seperator1 = "-";
  713. var seperator2 = ":";
  714. var month = date.getMonth() + 1;
  715. var strDate = date.getDate();
  716. if (month >= 1 && month <= 9) {
  717. month = "0" + month;
  718. }
  719. if (strDate >= 0 && strDate <= 9) {
  720. strDate = "0" + strDate;
  721. }
  722. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
  723. " " + date.getHours() + seperator2 + date.getMinutes() +
  724. seperator2 + date.getSeconds();
  725. return currentdate;
  726. }
  727. var iswebcloase = 1;
  728. window.onunload = function () {
  729. if (iswebcloase) {
  730. iswebcloase = 0;
  731. if (ws.readyState == ws.OPEN) {
  732. obj.Type = 'Logout';
  733. Send();
  734. ws.onclose();
  735. }
  736. }
  737. }
  738. window.onbeforeunload = function () {
  739. if (iswebcloase) {
  740. iswebcloase = 0;
  741. if (ws.readyState == ws.OPEN) {
  742. obj.Type = 'Logout';
  743. Send();
  744. ws.onclose();
  745. }
  746. }
  747. }