Aucune description

main.js 15KB

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