郑州颐和随访系统UI

main.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. var ws, n = 0,
  2. timer,hidTel,hidCallID,hidActionID;
  3. var lockReconnect = false; //避免重复连接
  4. var obj = {};
  5. var cls = 0;
  6. var lasttime = new Date().getTime();
  7. //创建scoket连接
  8. function createWebSocket() {
  9. try {
  10. $("#top-search li i").removeClass("active");
  11. Connect();
  12. } catch(e) {
  13. reconnect();
  14. }
  15. }
  16. //连接
  17. function Connect() {
  18. ws = new WebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  19. ws.onopen = function() {
  20. console.log(new Date() + " " + "建立连接");
  21. //心跳检测重置
  22. heartCheck.reset().start();
  23. cls = 0;
  24. $(".Login").addClass("active");
  25. //自动签入
  26. //lasttime = new Date().getTime();
  27. //obj.Type = "Login";
  28. //obj.AgentType = "0";
  29. //Send(); /*2018-05-19zhangshaungnan注释*/
  30. };
  31. //接收到消息的回调方法
  32. ws.onmessage = function(evt) {
  33. //如果获取到消息,心跳检测重置
  34. //拿到任何消息都说明当前连接是正常的
  35. heartCheck.reset().start();
  36. var myDate = new Date();
  37. console.log(myDate + " receive " + evt.data);
  38. var data = JSON.parse(evt.data)[0];
  39. if(data) {
  40. var rlt = data.Result;
  41. if(rlt == true) {
  42. var type = data.Type;
  43. switch(type.toLowerCase()) {
  44. //case "heart": HeartBack(); break;//心跳
  45. case "login":
  46. LoginBack();
  47. break; //签入
  48. case "logout":
  49. LogoutBack();
  50. break; //签出
  51. case "dropcall":
  52. DropCallBack();
  53. break; //挂断
  54. case "makecall":
  55. MakeCallBack();
  56. break; //外呼
  57. case "setstate":
  58. SetState(data);
  59. break; //置忙置闲
  60. //case "saybusy": SayBusyBack(data); break;
  61. //case "sayfree": SayFreeBack(data); break;
  62. case "meeting":
  63. MeetingBack();
  64. break; //多方通话
  65. case "transfer":
  66. TransferBack();
  67. break; //转移
  68. case "hold":
  69. HoldBack();
  70. break; //保持
  71. case "retrieve":
  72. RetrieveBack();
  73. break; //接回
  74. case "incoming":
  75. IncomingBack(data);
  76. break; //来电
  77. case "subscribe":
  78. SubScribeBack();
  79. break; //监测
  80. case "subscribecancel":
  81. SubScribeCancelBack();
  82. break; //停止监测
  83. case "agentstate":
  84. AgentStateBack(data);
  85. break; //坐席状态
  86. case "linestate":
  87. LineStateBack(data);
  88. break; //线路状态
  89. case "motorsetstate":
  90. SayFreeBack();
  91. break; //班长置闲
  92. case "linestateagent":
  93. LineStateAgentBack(data);
  94. break; //线路状态通知
  95. case "agentstateagent":
  96. AgentStateAgentBack(data);
  97. break; //坐席状态通知
  98. case "callid":
  99. CallIDBack(data);
  100. break; //获取callid
  101. case "recordpath":
  102. RecordPathBack(data);
  103. break; //录音返回
  104. }
  105. } else {
  106. if(rlt == false) {
  107. //layer.confirm('操作失败!', {
  108. // btn: ['确定']
  109. //});
  110. $(".hwzt").text('操作失败!');
  111. } else {
  112. $(".hwzt").text(rlt);
  113. //layer.confirm(rlt, {
  114. // btn: ['确定']
  115. //});
  116. }
  117. }
  118. }
  119. };
  120. //连接关闭的回调方法
  121. ws.onclose = function(evt) {
  122. if(cls == 0) {
  123. cls = 1;
  124. //console.log("连接关闭!");
  125. //layer.confirm('连接关闭!', {
  126. // btn: ['确定']
  127. //});
  128. $(".hwzt").text('连接关闭!');
  129. $("#top-search li i").removeClass("active");
  130. reconnect();
  131. }
  132. };
  133. //连接发生错误的回调方法
  134. ws.onerror = function(evt) {
  135. //产生异常
  136. $(".hwzt").text('连接出现异常!');
  137. console.log(ws);
  138. if(ws == null || ws.readyState != ws.OPEN) {
  139. console.log(new Date() + "开始重连");
  140. reconnect();
  141. }
  142. };
  143. }
  144. //重连
  145. function reconnect() {
  146. if(lockReconnect) return;
  147. lockReconnect = true;
  148. //没连接上会一直重连,设置延迟避免请求过多
  149. setTimeout(function() {
  150. console.log(new Date() + " " + "重连中……");
  151. createWebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  152. lockReconnect = false;
  153. }, 2000);
  154. }
  155. //发送
  156. function Send() {
  157. if(ws.readyState != ws.OPEN) {
  158. reconnect();
  159. }
  160. if(ws.readyState == ws.OPEN) {
  161. console.log(new Date() + " send " + JSON.stringify(obj));
  162. ws.send(JSON.stringify(obj));
  163. }
  164. }
  165. //心跳检测
  166. var heartCheck = {
  167. timeout: 25000, //25秒
  168. timeoutObj: null,
  169. serverTimeoutObj: null,
  170. reset: function() {
  171. clearTimeout(this.timeoutObj);
  172. clearTimeout(this.serverTimeoutObj);
  173. return this;
  174. },
  175. start: function() {
  176. var self = this;
  177. this.timeoutObj = setTimeout(function() {
  178. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  179. //onmessage拿到返回的心跳就说明连接正常
  180. obj.Type = "Heart";
  181. Send();
  182. self.serverTimeoutObj = setTimeout(function() { //如果超过一定时间还没重置,说明后端主动断开了
  183. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  184. }, self.timeout)
  185. }, this.timeout)
  186. }
  187. }
  188. //签入
  189. function LoginBack() {
  190. $("#top-search li i").removeClass("active");
  191. $(".Logout").addClass("active");
  192. $(".SayBusy").addClass("active");
  193. $(".MakeCall").addClass("active");
  194. $(".zxzt").removeClass("br").addClass("bl");
  195. $(".fwzt").removeClass("br").addClass("bl");
  196. $(".hwzt").text('');
  197. }
  198. //签出
  199. function LogoutBack() {
  200. $("#top-search li i").removeClass("active");
  201. $(".Login").addClass("active");
  202. $(".zxzt").removeClass("bl").addClass("br");
  203. $(".fwzt").removeClass("bl").addClass("br");
  204. $(".hwzt").text('');
  205. }
  206. //来电
  207. function IncomingBack(data) {
  208. if(data.CallID!=0){
  209. var p = '<a href="javascript:;" class="active J_menuTab" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID=' + data.CallID + '">来电弹屏' + helper.filter.cutTel(data.Number) + ' <i class="fa fa-times-circle"></i></a>';
  210. $(".J_menuTab").removeClass("active");
  211. var nif = '<iframe class="J_iframe J_iframeNew" name="iframe'+ data.CallID +'" width="100%" height="100%" src="./callScreen/callScreen.html?Number=' + data.Number + '&CallID=' + data.CallID + '&ActionID=' + data.ActionID + '" frameborder="0" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID=' + data.CallID + '" seamless></iframe>';
  212. $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(nif);
  213. $(".J_menuTabs .page-tabs-content").append(p);
  214. hidTel=data.Number;
  215. hidCallID=data.CallID;
  216. hidActionID=data.ActionID;
  217. }else{
  218. var timestamp = Date.parse(new Date());
  219. var p = '<a href="javascript:;" class="active J_menuTab" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID='+timestamp+'">来电弹屏' + helper.filter.cutTel(data.Number) + ' <i class="fa fa-times-circle"></i></a>';
  220. $(".J_menuTab").removeClass("active");
  221. var nif = '<iframe class="J_iframe J_iframeNew" name="iframe'+timestamp+'" width="100%" height="100%" src="./callScreen/callScreen.html?Number=' + data.Number + '&CallID='+timestamp+'" frameborder="0" data-id="./callScreen/callScreen.html?tel=' + data.Number + '&CallID='+timestamp+'" seamless></iframe>';
  222. $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(nif);
  223. $(".J_menuTabs .page-tabs-content").append(p);
  224. hidTel=data.Number;
  225. hidCallID=timestamp;
  226. }
  227. }
  228. //***************************************************
  229. function CallIDBack(data) {
  230. //$(".hidCallID").val(data.CurrID);
  231. }
  232. //挂断
  233. function DropCallBack() {
  234. $("#top-search li i").removeClass("active");
  235. $(".Logout").addClass("active");
  236. $(".SayBusy").addClass("active");
  237. $(".MakeCall").addClass("active");
  238. var obj = $("iframe:visible")
  239. // if (obj.attr("data-id") == './callScreen/callScreen.html?tel=' + hidTel + '&CallID=' + hidCallID + '') {
  240. // window.frames[obj.attr("name")].$(".td-call").hide();
  241. // window.frames['iframe'+ hidCallID +''].$(".td-call").hide();
  242. // }
  243. if(window.frames['iframe'+ hidCallID +'']){
  244. window.frames['iframe'+ hidCallID +''].$(".td-call").hide();
  245. }
  246. }
  247. //线路状态通知
  248. function LineStateAgentBack(data) {
  249. var objiframe = $("iframe:visible")
  250. //0分机不可用,1空闲,2摘机等待拨号,3正在拨号,4呼出振铃,5来电振铃,6通话中,7播放忙音中,8移除IP分机,9通话保持中
  251. if(data.State == '0') {
  252. $(".hwzt").text('分机不可用'); //左下角状态显示
  253. //$(".fwzt").removeClass("br").removeClass("bl");
  254. $(".fwzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加话机状态灯
  255. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  256. }
  257. if(data.State == '1') {
  258. $(".hwzt").text('空闲'); //左下角状态显示
  259. $(".fwzt").removeClass("br").addClass("bl");
  260. $(".zxzt").removeClass("br").addClass("bl");//20180509 by fanlongfei 增加坐席状态灯
  261. if(window.frames['iframe'+ hidCallID +'']){
  262. window.frames['iframe'+ hidCallID +''].clearInter();
  263. }
  264. if (hidTel && hidCallID) {
  265. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateGJ', {
  266. callid: hidTel,
  267. "token": $.cookie("token")
  268. }, function (result) {
  269. result = JSON.parse(result);
  270. if (result.state.toLowerCase() == "success") { }
  271. })
  272. }
  273. $("#top-search li i").removeClass("active");
  274. $(".Logout").addClass("active");
  275. $(".SayBusy").addClass("active");
  276. $(".MakeCall").addClass("active");
  277. if(window.frames['iframe'+ hidCallID +'']){
  278. window.frames['iframe'+ hidCallID +''].$(".td-call").hide();
  279. }
  280. }
  281. if(data.State == '2') {
  282. $(".hwzt").text('摘机等待拨号'); //左下角状态显示
  283. }
  284. if(data.State == '3') {
  285. $(".hwzt").text('正在拨号'); //左下角状态显示
  286. }
  287. if(data.State == '4') {
  288. $(".hwzt").text('呼出振铃'); //左下角状态显示
  289. }
  290. if(data.State == '5') {
  291. $(".hwzt").text('来电振铃'); //左下角状态显示
  292. //$(".fwzt").removeClass("bl").addClass("br");
  293. $(".fwzt").removeClass("br").addClass("bl");//20180509 by fanlongfei 增加话机状态灯
  294. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  295. if (hidTel && hidCallID) {
  296. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZL', {
  297. callid: hidCallID,
  298. "token": $.cookie("token")
  299. }, function (result) {
  300. result = JSON.parse(result);
  301. if (result.state.toLowerCase() == "success") { }
  302. })
  303. }
  304. }
  305. if(data.State == '6') {
  306. $(".hwzt").text('通话中'); //左下角状态显示
  307. $(".fwzt").removeClass("bl").addClass("br");
  308. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  309. if(hidTel && hidCallID) {
  310. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZJ', {
  311. callid: hidCallID,
  312. "token": $.cookie("token")
  313. }, function(result) {
  314. result = JSON.parse(result);
  315. if(result.state.toLowerCase() == "success") {}
  316. })
  317. }
  318. $("#top-search li i").removeClass("active");
  319. $(".DropCall").addClass("active");
  320. $(".Hold").addClass("active");
  321. $(".Transfer").addClass("active");
  322. $(".Meeting").addClass("active");
  323. var aaa=data.CallDirection;
  324. if(data.CallDirection=="in"){
  325. // if (objiframe.attr("data-id") == './callScreen/callScreen.html?tel=' + hidTel + '&CallID=' + hidCallID + '') {
  326. setTimeout(window.frames['iframe'+ hidCallID +''].calling(),500);/*2018-05-19 zhangshuangnan 修改 ps: 因软电话设置为 自动应答 通话时间不计时问题*/
  327. // }
  328. }
  329. }
  330. if(data.State == '7') {
  331. $(".hwzt").text('播放忙音中'); //左下角状态显示
  332. }
  333. if(data.State == '8') {
  334. $(".hwzt").text('移除IP分机'); //左下角状态显示
  335. }
  336. if(data.State == '9') {
  337. $(".hwzt").text('通话保持中'); //左下角状态显示
  338. }
  339. }
  340. //线路状态通知
  341. function AgentStateAgentBack(data){
  342. var objiframe = $("iframe:visible")
  343. if(data.State == '6') {
  344. $(".hwzt").text('通话中'); //左下角状态显示
  345. $(".fwzt").removeClass("bl").addClass("br");
  346. $(".zxzt").removeClass("bl").addClass("br");//20180509 by fanlongfei 增加坐席状态灯
  347. if(hidTel && hidCallID) {
  348. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZJ', {
  349. callid: hidCallID,
  350. "token": $.cookie("token")
  351. }, function(result) {
  352. result = JSON.parse(result);
  353. if(result.state.toLowerCase() == "success") {}
  354. })
  355. }
  356. $("#top-search li i").removeClass("active");
  357. $(".DropCall").addClass("active");
  358. $(".Hold").addClass("active");
  359. $(".Transfer").addClass("active");
  360. $(".Meeting").addClass("active");
  361. var aaa=data.CallDirection;
  362. if(data.CallDirection=="in"){
  363. // if (objiframe.attr("data-id") == './callScreen/callScreen.html?tel=' + hidTel + '&CallID=' + hidCallID + '') {
  364. setTimeout(window.frames['iframe'+ hidCallID +''].calling(),500);/*2018-05-19 zhangshuangnan 修改 ps: 因软电话设置为 自动应答 通话时间不计时问题*/
  365. // }
  366. }
  367. }else{
  368. console.log('出错了!')
  369. }
  370. }
  371. function toDub(i) {
  372. return i < 10 ? "0" + i : "" + i;
  373. }
  374. //外呼
  375. function MakeCallBack() {
  376. $("#top-search li i").removeClass("active");
  377. $(".DropCall").addClass("active");
  378. // alert('1');
  379. // window.frames[obj.attr("name")].calling();
  380. }
  381. //置忙置闲
  382. function SetState(obj) {
  383. if(obj.State == '5') {
  384. $(".SayBusy").removeClass("active");
  385. $(".SayFree").addClass("active");
  386. $(".zxzt").removeClass("bl").addClass("br");
  387. $(".hwzt").text('置忙');
  388. }
  389. if(obj.State == '2') {
  390. $(".SayBusy").addClass("active");
  391. $(".SayFree").removeClass("active");
  392. $(".zxzt").removeClass("br").addClass("bl");
  393. $(".hwzt").text('空闲');
  394. }
  395. }
  396. //置忙
  397. function SayBusyBack() {
  398. $(".SayBusy").removeClass("active");
  399. $(".SayFree").addClass("active");
  400. }
  401. //坐席班长置闲
  402. function SayFreeBack() {
  403. $(".SayBusy").addClass("active");
  404. $(".SayFree").removeClass("active");
  405. $(".zxzt").removeClass("br").addClass("bl"); // 2018/05/09 by fanlongfei 增加坐席状态指示
  406. $(".hwzt").text('空闲');// 2018/05/09 by fanlongfei 增加坐席状态指示
  407. }
  408. //多方通话
  409. function MeetingBack() {
  410. }
  411. //转移
  412. function TransferBack() {
  413. $("#top-search li i").removeClass("active");
  414. $(".Logout").addClass("active");
  415. $(".SayBusy").addClass("active");
  416. $(".MakeCall").addClass("active");
  417. }
  418. //保持
  419. function HoldBack() {
  420. $(".Hold").removeClass("active");
  421. $(".Retrieve").addClass("active");
  422. }
  423. //接回
  424. function RetrieveBack() {
  425. $(".Hold").addClass("active");
  426. $(".Retrieve").removeClass("active");
  427. }
  428. //监测
  429. function SubScribeBack() {
  430. $('#content-main .J_iframeNew').each(function(i,n){
  431. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  432. window.frames[$(this).attr("name")].Start();
  433. }
  434. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  435. }
  436. //取消监测
  437. function SubScribeCancelBack() {
  438. // var obj = $("iframe:visible")
  439. // if(obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  440. // window.frames[obj.attr("name")].();
  441. // }
  442. $('#content-main .J_iframeNew').each(function(i,n){
  443. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  444. window.frames[$(this).attr("name")].Stop();
  445. }
  446. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  447. }
  448. //班长监测返回状态
  449. //坐席状态
  450. function AgentStateBack(data) {
  451. $('#content-main .J_iframeNew').each(function(i,n){
  452. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  453. window.frames[$(this).attr("name")].UpdateAgentState(data.AgentID, data.State);
  454. }
  455. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  456. }
  457. //线路状态
  458. function LineStateBack(data) {
  459. $('#content-main .J_iframeNew').each(function(i,n){
  460. if($(this).attr('data-id') == "./TelCall/SeatMonitor.html"){
  461. window.frames[$(this).attr("name")].UpdateLineState(data.AgentID, data.State);
  462. }
  463. })/*2018-05-24 zhangshuangnan 修改 解决通话中时 坐席监控状态不改变的问题*/
  464. }
  465. //录音返回
  466. function RecordPathBack(data) {
  467. $(".hidCallID").val(data.CallID);
  468. //if ($(".hidTel").val() && $(".hidCallID").val()) {
  469. // $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', { callid: $(".hidCallID").val(),path:data.RecPath, "token": $.cookie("token") }, function (result) {
  470. // result = JSON.parse(result);
  471. // if (result.state.toLowerCase() == "success") {
  472. // }
  473. // })
  474. //}
  475. if(hidTel) {
  476. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', {
  477. callid: data.CallID,
  478. path: data.RecPath,
  479. "token": $.cookie("token")
  480. }, function(result) {
  481. result = JSON.parse(result);
  482. if(result.state.toLowerCase() == "success") {}
  483. })
  484. }
  485. }
  486. //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
  487. function getNowFormatDate() {
  488. var date = new Date();
  489. var seperator1 = "-";
  490. var seperator2 = ":";
  491. var month = date.getMonth() + 1;
  492. var strDate = date.getDate();
  493. if(month >= 1 && month <= 9) {
  494. month = "0" + month;
  495. }
  496. if(strDate >= 0 && strDate <= 9) {
  497. strDate = "0" + strDate;
  498. }
  499. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
  500. " " + date.getHours() + seperator2 + date.getMinutes() +
  501. seperator2 + date.getSeconds();
  502. return currentdate;
  503. }