商丘12345 前端

main.js 24KB

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