Geen omschrijving

main.js 14KB

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