Nenhuma Descrição

main.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. if(typeof console == "undefined") {
  2. this.console = {
  3. log: function(msg) {}
  4. };
  5. }
  6. var callSeatState = echarts.init(document.getElementById("callSeatState"));
  7. // 如果浏览器不支持websocket,会使用这个flash自动模拟websocket协议,此过程对开发者透明
  8. WEB_SOCKET_SWF_LOCATION = "./js/websocket/WebSocketMain.swf";
  9. // 开启flash的websocket debug
  10. WEB_SOCKET_DEBUG = true;
  11. var ws, n = 0,
  12. timer;
  13. var lockReconnect = false; //避免重复连接
  14. var obj = {};
  15. var Statess;
  16. var cls = 0;
  17. var dataLength; //坐席数量
  18. let distributionData = []; //话务数据统计数据
  19. let callDate = []; //话务坐席数据
  20. let hwcount;
  21. let jtcount;
  22. let daySeatName = ['登陆坐席数量', '呼叫排队数量', '话务量', '呼入接通量'];
  23. let callSeatStateName = ['等待', '通话中', '话后处理', '置忙', '空闲']
  24. var lasttime = new Date().getTime();
  25. let callSeatStateData;
  26. let locationNum = 0;
  27. //坐席数量
  28. function agentCount() {
  29. $.ajax({
  30. url: huayi.config.callcenter_url + "SeatMonitoring/getlist",
  31. data: {
  32. token: $.cookie("token"),
  33. },
  34. async: false,
  35. dataType: 'json',
  36. success: function(res) {
  37. dataLength = res.data.length;
  38. }
  39. })
  40. }
  41. //话务量接通量
  42. function getPhoneCount() {
  43. $.ajax({
  44. url: huayi.config.callcenter_url + "/InfoNew/GetTrafficCountByNow",
  45. data: {
  46. token: $.cookie("token"),
  47. },
  48. async: false,
  49. dataType: 'json',
  50. success: function(res) {
  51. hwcount = res.data.hw[0].hwcount;
  52. jtcount = res.data.hw[0].jtcount
  53. }
  54. })
  55. }
  56. //话务数据统计
  57. function GetDistributionCount() {
  58. $.ajax({
  59. url: huayi.config.callcenter_url + "InfoNew/GetDistributionCount",
  60. data: {
  61. token: $.cookie("token"),
  62. },
  63. async: false,
  64. dataType: 'json',
  65. success: function(res) {
  66. distributionData = [];
  67. let hw = res.data.hw[0];
  68. let gd = res.data.gd[0];
  69. Object.keys(hw).forEach((key, n) => {
  70. if(key == 'hrjtcount') {
  71. distributionData.push({
  72. name: '呼入接通数量',
  73. value: hw[key]
  74. })
  75. }
  76. if(key == 'hcjtcount') {
  77. distributionData.push({
  78. name: '呼出接通数量',
  79. value: hw[key]
  80. })
  81. }
  82. if(key == 'hrtime') {
  83. distributionData.push({
  84. name: '呼入通话时长',
  85. value: hw[key]
  86. })
  87. }
  88. if(key == 'hctime') {
  89. distributionData.push({
  90. name: '呼出通话时长',
  91. value: hw[key]
  92. })
  93. }
  94. if(key == 'pjhrtime') {
  95. distributionData.push({
  96. name: '平均呼入通时',
  97. value: hw[key]
  98. })
  99. }
  100. if(key == 'pjhctime') {
  101. distributionData.push({
  102. name: '平均呼出通时',
  103. value: hw[key]
  104. })
  105. }
  106. if(key == 'fqcount') {
  107. distributionData.push({
  108. name: '放弃呼叫量',
  109. value: hw[key]
  110. })
  111. }
  112. if(key == 'hscount') {
  113. distributionData.push({
  114. name: '日呼损量',
  115. value: hw[key]
  116. })
  117. }
  118. if(key == 'sdhscount') {
  119. distributionData.push({
  120. name: '时段呼损量',
  121. value: hw[key]
  122. })
  123. }
  124. })
  125. Object.keys(gd).forEach((key, n) => {
  126. if(key == 'dxcount') {
  127. distributionData.push({
  128. name: '短信受理量',
  129. value: gd[key]
  130. })
  131. }
  132. if(key == 'wxcount') {
  133. distributionData.push({
  134. name: '微信受理量',
  135. value: gd[key]
  136. })
  137. }
  138. if(key == 'wbcount') {
  139. distributionData.push({
  140. name: '微博受理量',
  141. value: gd[key]
  142. })
  143. }
  144. if(key == 'apcount') {
  145. distributionData.push({
  146. name: 'APP受理量',
  147. value: gd[key]
  148. })
  149. }
  150. if(key == 'xxcount') {
  151. distributionData.push({
  152. name: '市长信箱受理量',
  153. value: gd[key]
  154. })
  155. }
  156. })
  157. distributionData.unshift({
  158. name: '登陆坐席数量',
  159. value: 0
  160. })
  161. distributionData.unshift({
  162. name: '呼叫排队数量',
  163. value: 0
  164. })
  165. }
  166. })
  167. }
  168. Connect()
  169. //创建scoket连接
  170. function createWebSocket() {
  171. try {
  172. Connect();
  173. } catch(e) {
  174. reconnect();
  175. }
  176. }
  177. //连接
  178. function Connect() {
  179. // debugger
  180. ws = new WebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  181. ws.onopen = function() {
  182. console.log(new Date() + " " + "建立连接");
  183. //心跳检测重置
  184. heartCheck.reset().start();
  185. cls = 0;
  186. $(".Login").addClass("active");
  187. lasttime = new Date().getTime();
  188. // debugger
  189. //话务坐席情况
  190. obj = {
  191. "Type": 'GetAgentDetail', //话后处理时长设置,0代表一致话后处理,除非发送置闲 (按照历史习惯,字符串形式)
  192. };
  193. Send();
  194. };
  195. //接收到消息的回调方法
  196. ws.onmessage = function(evt) {
  197. //如果获取到消息,心跳检测重置
  198. //拿到任何消息都说明当前连接是正常的
  199. heartCheck.reset().start();
  200. var myDate = new Date();
  201. data = JSON.parse(evt.data)[0];
  202. if(data.Type == "GetAgentDetail") {
  203. if(distributionData[0]){
  204. distributionData[0].value = data.WaiteCallCount;
  205. distributionData[1].value = data.AgentOnlineCount
  206. let disStr = ''
  207. distributionData.forEach(function(v, n) {
  208. disStr += '<li><label>' + v.name + '</label><span class="num_roll" id="">' + parseInt(v.value % 100000 / 10000) +
  209. '</span><span class="num_roll" id="">' + parseInt(v.value % 10000 / 1000) +
  210. '</span><span class="num_roll" id="">' + parseInt(v.value % 1000 / 100) +
  211. '</span><span class="num_roll"id="">' + parseInt((v.value % 100) / 10) +
  212. '</span><span class="num_roll" id="">' + parseInt(v.value % 10) + '</span></li>'
  213. })
  214. $('.callTraffic .data_info').html(disStr)
  215. callDate = [Number(data.AgentOnlineCount), Number(data.WaiteCallCount), Number(hwcount), Number(jtcount)]
  216. const outLine = dataLength - data.AgentOnlineCount;
  217. callSeatStateData = [data.WaiteCallCount, data.AgentSpeakCount, data.AgentProcessingCount, data.AgentReposeCount, data.AgentFreeCount]
  218. hotThingsChartMain('callSeatState', callSeatStateName, callSeatStateData, 500)
  219. }
  220. }
  221. if(data) {
  222. var rlt = data.Result;
  223. if(rlt == true) {
  224. var type = data.Type;
  225. switch(type.toLowerCase()) {
  226. case "subscribe":
  227. SubScribeBack();
  228. break; //监测
  229. case "subscribecancel":
  230. SubScribeCancelBack();
  231. break; //停止监测
  232. case "agentstate":
  233. AgentStateBack(data);
  234. break; //坐席状态
  235. case "linestate":
  236. // LineStateBack(data);
  237. break; //线路状态
  238. }
  239. } else {
  240. if(rlt == false) {
  241. //layer.confirm('操作失败!', {
  242. // btn: ['确定']
  243. //});
  244. $(".hwzt").text('操作失败!');
  245. } else {
  246. $(".hwzt").text(rlt);
  247. //layer.confirm(rlt, {
  248. // btn: ['确定']
  249. //});
  250. switch(data.Type.toLowerCase()) {
  251. case "waitcount":
  252. backstageQueue(data);
  253. break; //后台排队
  254. }
  255. }
  256. }
  257. }
  258. }
  259. };
  260. //连接关闭的回调方法
  261. ws.onclose = function(evt) {
  262. if(cls == 0) {
  263. cls = 1;
  264. //console.log("连接关闭!");
  265. //layer.confirm('连接关闭!', {
  266. // btn: ['确定']
  267. //});
  268. $(".hwzt").text('连接关闭!');
  269. $("#top-search li i").removeClass("active");
  270. reconnect();
  271. }
  272. };
  273. //连接发生错误的回调方法
  274. ws.onerror = function(evt) {
  275. //产生异常
  276. $(".hwzt").text('连接出现异常!');
  277. console.log(ws);
  278. if(ws == null || ws.readyState != ws.OPEN) {
  279. console.log(new Date() + "开始重连");
  280. reconnect();
  281. }
  282. };
  283. //}
  284. //重连
  285. function reconnect() {
  286. if(lockReconnect) return;
  287. lockReconnect = true;
  288. //没连接上会一直重连,设置延迟避免请求过多
  289. setTimeout(function() {
  290. console.log(new Date() + " " + "重连中……");
  291. createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  292. lockReconnect = false;
  293. }, 2000);
  294. }
  295. //发送
  296. function Send() {
  297. if(ws.readyState != ws.OPEN) {
  298. reconnect();
  299. }
  300. if(ws.readyState == ws.OPEN) {
  301. console.log(new Date() + " send " + JSON.stringify(obj));
  302. ws.send(JSON.stringify(obj));
  303. }
  304. }
  305. //心跳检测
  306. var heartCheck = {
  307. timeout: 25000, //25秒
  308. timeoutObj: null,
  309. serverTimeoutObj: null,
  310. reset: function() {
  311. clearTimeout(this.timeoutObj);
  312. clearTimeout(this.serverTimeoutObj);
  313. return this;
  314. },
  315. start: function() {
  316. var self = this;
  317. this.timeoutObj = setTimeout(function() {
  318. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  319. //onmessage拿到返回的心跳就说明连接正常
  320. obj.Type = "Heart";
  321. Send();
  322. self.serverTimeoutObj = setTimeout(function() { //如果超过一定时间还没重置,说明后端主动断开了
  323. ws
  324. .close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  325. }, self.timeout)
  326. }, this.timeout)
  327. }
  328. }
  329. //开始监测
  330. function SubScribeBack() {
  331. $(".star_btn").css("background-color", 'rgb(1,216,235)');
  332. $(".stop_btn").css("background-color", '#064695');
  333. }
  334. //取消监测
  335. function SubScribeCancelBack() {
  336. $(".people_list").show()
  337. $(".people_list i").hide()
  338. $(".stop_btn").css("background-color", 'rgb(1,216,235)');
  339. $(".star_btn").css("background-color", '#064695');
  340. $(".stop_btn").addClass("dis");
  341. $(".star_btn").removeClass("dis");
  342. $(".zx_people i").removeClass().addClass("lx");
  343. $(".zx_people i").removeClass().addClass("lx").attr("zx_item", "0").attr("xl_item", "0");
  344. }
  345. //班长监测返回状态
  346. //坐席状态
  347. function AgentStateBack(data) {
  348. // console.log(data)
  349. var sts = "";
  350. switch(data.State) {
  351. case "0":
  352. sts = "lx";
  353. break; //离线
  354. case "1":
  355. break; //登录中
  356. case "2":
  357. sts = "kx";
  358. break; //空闲
  359. case "3":
  360. sts = "th";
  361. break; //通话中
  362. case "4":
  363. sts = "hh";
  364. break; //话后处理中
  365. case "5":
  366. sts = "ml";
  367. break; //小休
  368. case "6":
  369. sts = "zl";
  370. break; //被请求
  371. case "7":
  372. sts = "lx";
  373. break; //注销
  374. }
  375. if(data.AgentID * 1 < 10) {
  376. data.AgentID = '0' + data.AgentID;
  377. }
  378. var ele = $("." + data.AgentID).find("i");
  379. if(sts) {
  380. ele.removeClass().addClass(sts);
  381. }
  382. ele.attr("zx_item", data.State);
  383. if($(".zxtp .g_nums").text() == data.AgentID) {
  384. if(sts) {
  385. $(".zxtp i").removeClass().addClass(sts);
  386. }
  387. }
  388. if(data.State === "2") {
  389. // console.log(data.AgentID,data.State,data.Group,)
  390. }
  391. $(".people_list dl dt").each(function() {
  392. // console.log($(this).find("i").attr("zxGroup"))
  393. // if($(this).find("i").attr("class")==='lx'){
  394. //// console.log($(this).find("i").attr("zxGroup"))
  395. //// console.log(data.AgentID,$(this).find("i").attr("zxGroup"))
  396. // if ($(this).find("i").attr("zxGroup")==data.Group) {
  397. // $(this).show()
  398. // $(this).find("i").show()
  399. // $(this).find("i").removeClass().addClass("dg");
  400. // console.log($(this).find("i").attr("zxGroup"))
  401. // }
  402. // if($(this).find("i").attr("class")==='lx'){
  403. // $(this).find("i").hide()
  404. // }
  405. // }else{
  406. // $(this).find("i").show()
  407. // }
  408. // $(this).find("i").removeClass().addClass("dg");
  409. $(this).find("i").show()
  410. })
  411. // $(".people_list dl dt").eq(0).before($('.' + data.AgentID))
  412. // $(document.getElementsByClassName('seatList')[locationNum]).before($('.' + data.AgentID))
  413. }
  414. //线路状态
  415. function LineStateBack(data) {
  416. //data.Type,data,
  417. // console.log(data.AgentID,data.State)
  418. if(data.State.indexOf("|") != -1) {
  419. arr = data.State.split("|");
  420. data.State = arr[0];
  421. }
  422. if(data.AgentID * 1 < 10) {
  423. data.AgentID = '0' + data.AgentID;
  424. }
  425. var ele = $("." + data.AgentID).find("i");
  426. var sts = "";
  427. switch(data.State) {
  428. case "0":
  429. sts = "lx";
  430. break; //分机不可用
  431. case "1":
  432. if(!(ele.hasClass("hh") || ele.hasClass("ml"))) {
  433. sts = "kx";
  434. }
  435. break; //空闲
  436. case "2":
  437. sts = "ml";
  438. break; //摘机等待拨号
  439. case "3":
  440. sts = "ml";
  441. break; //正在拨号
  442. case "4":
  443. sts = "zl";
  444. break; //呼出振铃
  445. case "5":
  446. sts = "zl";
  447. break; //来电振铃
  448. case "6":
  449. sts = "th";
  450. break; //通话中
  451. case "7":
  452. sts = "ml";
  453. break; //播放忙音中
  454. case "8":
  455. sts = "th";
  456. break; //通话保持中
  457. case "9":
  458. break; //话机移除
  459. case "10":
  460. break; //保持/空闲
  461. case "11":
  462. break; //保持/摘机等待拨号
  463. case "12":
  464. break; //保持/正在拨号
  465. case "13":
  466. break; //保持/呼出振铃
  467. case "14":
  468. break; //保持/通话中
  469. }
  470. if(sts) {
  471. ele.removeClass().addClass(sts);
  472. }
  473. ele.attr("xl_item", data.State);
  474. if($(".zxtp .g_nums").text() == data.AgentID) {
  475. if(sts) {
  476. $(".zxtp i").removeClass().addClass(sts);
  477. }
  478. }
  479. }
  480. function toDub(i) {
  481. return i < 10 ? "0" + i : "" + i;
  482. }
  483. //默认记忆上次是否签入,是否置忙置闲 0表示已签入 空闲,1表示签入置忙,2表示签出
  484. function SetStateCookie(state) {
  485. $.cookie("socket_state", state);
  486. }
  487. function backstageQueue(data) {
  488. var obj = $("iframe:visible")
  489. // if (obj.attr("data-id") == "index_v1.html") {
  490. window.frames[obj.attr("name")].realTimeMonitorQueue(data.WaitCount);
  491. // }
  492. }
  493. //在线坐席信息
  494. function GetAgentListBack(data) {
  495. $.ajax({
  496. type: "get",
  497. url: huayi.config.callcenter_url + "SeatMonitoring/GetAgentList",
  498. async: true,
  499. dataType: 'json',
  500. data: {
  501. "token": $.cookie("token")
  502. },
  503. success: function(result) {
  504. var user = result.data;
  505. $(user).each(function(j, m) {
  506. $(data.AgentList).each(function(k, g) {
  507. if(g.AgentID == m.UserCode) {
  508. g.userName = m.UserName;
  509. }
  510. })
  511. })
  512. $(data.AgentList).each(function(k, m) {
  513. var strr = '';
  514. switch(m.State) {
  515. case "0":
  516. strr = "离线";
  517. break; //离线
  518. case "1":
  519. break; //登录中
  520. case "2":
  521. strr = "空闲";
  522. break; //空闲
  523. case "3":
  524. strr = "通话中";
  525. break; //通话中
  526. case "4":
  527. strr = "话后处理中";
  528. break; //话后处理中
  529. case "5":
  530. strr = "忙碌";
  531. break; //小休
  532. case "6":
  533. strr = "振铃";
  534. break; //被请求
  535. case "7":
  536. strr = "注销";
  537. break; //注销
  538. }
  539. var html = '<tr fjh="' + m.AgentExten + '">' +
  540. '<td>' + (m.userName ? '' : m.userName) + '</td>' //姓名
  541. +
  542. '<td>' + m.AgentID + '</td>' //工号
  543. +
  544. '<td>' + m.AgentExten + '</td>' //分机号
  545. +
  546. '<td class=" ' + m.UserCode + 'state">' + strr + '</td>' //状态
  547. +
  548. '</tr>';
  549. $(html).appendTo("#zxTable tbody");
  550. })
  551. }
  552. });
  553. }
  554. //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
  555. function getNowFormatDate() {
  556. var date = new Date();
  557. var seperator1 = "-";
  558. var seperator2 = ":";
  559. var month = date.getMonth() + 1;
  560. var strDate = date.getDate();
  561. if(month >= 1 && month <= 9) {
  562. month = "0" + month;
  563. }
  564. if(strDate >= 0 && strDate <= 9) {
  565. strDate = "0" + strDate;
  566. }
  567. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
  568. " " + date.getHours() + seperator2 + date.getMinutes() +
  569. seperator2 + date.getSeconds();
  570. return currentdate;
  571. }
  572. var iswebcloase = 1;
  573. window.onunload = function() {
  574. if(iswebcloase) {
  575. iswebcloase = 0;
  576. if(ws.readyState == ws.OPEN) {
  577. obj.Type = 'Logout';
  578. Send();
  579. ws.onclose();
  580. }
  581. }
  582. }
  583. window.onbeforeunload = function() {
  584. if(iswebcloase) {
  585. iswebcloase = 0;
  586. if(ws.readyState == ws.OPEN) {
  587. obj.Type = 'Logout';
  588. Send();
  589. ws.onclose();
  590. }
  591. }
  592. }