中鑫之宝5.0前端

main.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. 
  2. var ws, heartbeat, n = 0, timer;
  3. var obj = {};
  4. var cls = 0;
  5. var lasttime = new Date().getTime();
  6. heartbeat = setInterval(function () { Heart() }, 60000);
  7. //连接
  8. function Connect() {
  9. try {
  10. ws = new WebSocket("ws://" + huayi.config.socket_ip + ":" + huayi.config.socket_port);
  11. ws.onopen = function () {
  12. console.log("建立连接");
  13. cls = 0;
  14. $(".Login").addClass("active");
  15. lasttime = new Date().getTime();
  16. obj.Type = "Login";
  17. obj.AgentType = "0";
  18. Send();
  19. };
  20. //接收到消息的回调方法
  21. ws.onmessage = function (evt) {
  22. console.log(evt.data);
  23. var data = JSON.parse(evt.data)[0];
  24. if (data) {
  25. var rlt = data.Result;
  26. if (rlt == true) {
  27. var type = data.Type;
  28. switch (type.toLowerCase()) {
  29. case "heart": HeartBack(); break;//心跳
  30. case "login": LoginBack(); break;//签入
  31. case "logout": LogoutBack(); break;//签出
  32. case "dropcall": DropCallBack(); break;//挂断
  33. case "makecall": MakeCallBack(); break;//外呼
  34. case "setstate": SetState(data); break;//置忙置闲
  35. //case "saybusy": SayBusyBack(data); break;
  36. //case "sayfree": SayFreeBack(data); break;
  37. case "meeting": MeetingBack(); break;//多方通话
  38. case "transfer": TransferBack(); break;//转移
  39. case "hold": HoldBack(); break;//保持
  40. case "retrieve": RetrieveBack(); break;//接回
  41. case "incoming": IncomingBack(data); break;//来电
  42. case "subscribe": SubScribeBack(); break;//监测
  43. case "subscribecancel": SubScribeCancelBack(); break;//停止监测
  44. case "agentstate": AgentStateBack(data); break;//坐席状态
  45. case "linestate": LineStateBack(data); break;//线路状态
  46. case "motorsetstate": SayFreeBack(); break;//班长置闲
  47. case "linestateagent": LineStateAgentBack(data); break;//线路状态通知
  48. case "callid": CallIDBack(data); break;//获取callid
  49. case "recordpath": RecordPathBack(data); break;//录音返回
  50. }
  51. }
  52. else {
  53. if (rlt == false) {
  54. layer.confirm('操作失败!', {
  55. btn: ['确定']
  56. });
  57. }
  58. else {
  59. layer.confirm(rlt, {
  60. btn: ['确定']
  61. });
  62. }
  63. }
  64. }
  65. };
  66. //连接关闭的回调方法
  67. ws.onclose = function (evt) {
  68. if (cls == 0) {
  69. cls = 1;
  70. console.log("连接关闭!");
  71. layer.confirm('连接关闭!', {
  72. btn: ['确定']
  73. });
  74. $("#top-search li i").removeClass("active");
  75. }
  76. };
  77. //连接发生错误的回调方法
  78. ws.onerror = function (evt) {
  79. //产生异常
  80. console.log("WebSocketError!");
  81. };
  82. }
  83. catch (ex) {
  84. layer.confirm('连接失败!', {
  85. btn: ['确定']
  86. });
  87. }
  88. }
  89. //发送
  90. function Send() {
  91. if (ws.readyState != ws.OPEN) {
  92. Connect();
  93. }
  94. if (ws.readyState == ws.OPEN) {
  95. ws.send(JSON.stringify(obj));
  96. }
  97. }
  98. //心跳
  99. function Heart() {
  100. if (new Date().getTime() - lasttime > 70000) {
  101. Connect();
  102. }
  103. else {
  104. if (ws.bufferedAmount == 0) {
  105. obj.Type = "Heart";
  106. Send();
  107. }
  108. }
  109. }
  110. function HeartBack() {
  111. lasttime = new Date().getTime();
  112. }
  113. //签入
  114. function LoginBack() {
  115. $("#top-search li i").removeClass("active");
  116. $(".Logout").addClass("active");
  117. $(".SayBusy").addClass("active");
  118. $(".MakeCall").addClass("active");
  119. $(".zxzt").removeClass("lx").removeClass("br");
  120. $(".zxzt").addClass("bl");
  121. }
  122. //签出
  123. function LogoutBack() {
  124. $("#top-search li i").removeClass("active");
  125. $(".Login").addClass("active");
  126. $(".zxzt").removeClass("bl").removeClass("br");
  127. $(".zxzt").addClass("lx");
  128. $(".fwzt").removeClass("bl").removeClass("br");
  129. $(".fwzt").addClass("lx");
  130. }
  131. //来电
  132. function IncomingBack(data) {
  133. $(".hidTel").val(data.Number);
  134. $(".tel").text(data.Number);
  135. $(".ldtime").text(getNowFormatDate());
  136. $(".thsc").text("00:00");
  137. //获取callid
  138. $.ajaxSettings.async = false;
  139. $.getJSON(huayi.config.callcenter_url + 'CallInScreen/GetCallIdByPhone', { "tel": $(".hidTel").val(), "token": $.cookie("token") }, function (result) {
  140. $.ajaxSettings.async = true;
  141. if (result.state.toLowerCase() == "success") {
  142. $(".hidCallID").val(result.data.CallId);
  143. }
  144. })
  145. //获取电话所属地
  146. $.getJSON(huayi.config.callcenter_url + 'CallInScreen/GetPhoneLocation', { "tel": $(".hidTel").val(), "token": $.cookie("token") }, function (result) {
  147. if (result.state.toLowerCase() == "success") {
  148. $(".khgsd").text(result.data);
  149. }
  150. })
  151. //获取客户信息
  152. $(".ldtel").text($(".hidTel").val());
  153. $("#tsdh").val($(".hidTel").val());
  154. $(".ldtel1").val($(".hidTel").val());
  155. $.getJSON(huayi.config.callcenter_url + 'CallInScreen/GetCustomerByTel', { "tel": $(".hidTel").val(), "token": $.cookie("token") }, function (result) {
  156. if (result.state.toLowerCase() == "success") {
  157. if (result.data.length > 0) {
  158. $("#tskh").val(result.data[0].F_CustomerName);
  159. $("#khid").val(result.data[0].F_CustomerId);
  160. $(".khbh").val(result.data[0].F_CustomerCode);
  161. $(".ldtel1").val(result.data[0].F_Telephone);
  162. $(".ldtel2").val(result.data[0].F_Mobile);
  163. $(".ldtel3").val(result.data[0].F_ChargeTelephone);
  164. }
  165. }
  166. })
  167. loadOld();
  168. $('.maxOpen').trigger("click");
  169. $('.head-pic .lahei .la-before').show();
  170. $('.head-pic .lahei .la-after').hide();
  171. $(".Bacha").hide();
  172. }
  173. function CallIDBack(data) {
  174. //$(".hidCallID").val(data.CurrID);
  175. }
  176. //挂断
  177. function DropCallBack() {
  178. $("#top-search li i").removeClass("active");
  179. $(".Logout").addClass("active");
  180. $(".SayBusy").addClass("active");
  181. $(".MakeCall").addClass("active");
  182. $(".td-call").hide();
  183. //$('.ldtp-con').css("display", 'none');
  184. }
  185. function LineStateAgentBack(data) {
  186. if (data.State == '1') {
  187. clearInterval(timer);
  188. if ($(".hidTel").val() && $(".hidCallID").val()) {
  189. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateGJ', { callid: $(".hidCallID").val(), "token": $.cookie("token") }, function (result) {
  190. result = JSON.parse(result);
  191. if (result.state.toLowerCase() == "success") {
  192. }
  193. })
  194. }
  195. $("#top-search li i").removeClass("active");
  196. $(".Logout").addClass("active");
  197. $(".SayBusy").addClass("active");
  198. $(".MakeCall").addClass("active");
  199. $(".td-call").hide();
  200. $(".Bacha").show();
  201. //$(".hidTel").val("");
  202. //$(".hidCallID").val("");
  203. $(".fwzt").removeClass("lx").removeClass("br");
  204. $(".fwzt").addClass("bl");
  205. }
  206. if (data.State == '5') {
  207. if ($(".hidTel").val() && $(".hidCallID").val()) {
  208. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZL', { callid: $(".hidCallID").val(), "token": $.cookie("token") }, function (result) {
  209. result = JSON.parse(result);
  210. if (result.state.toLowerCase() == "success") {
  211. }
  212. })
  213. }
  214. }
  215. if (data.State == '6') {
  216. if ($(".hidTel").val() && $(".hidCallID").val()) {
  217. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateZJ', { callid: $(".hidCallID").val(), "token": $.cookie("token") }, function (result) {
  218. result = JSON.parse(result);
  219. if (result.state.toLowerCase() == "success") {
  220. }
  221. })
  222. }
  223. $(".fwzt").removeClass("lx").removeClass("bl");
  224. $(".fwzt").addClass("br");
  225. $(".td-call").show();
  226. n = 0;
  227. $("#top-search li i").removeClass("active");
  228. $(".DropCall").addClass("active");
  229. $(".Hold").addClass("active");
  230. $(".Transfer").addClass("active");
  231. $(".Meeting").addClass("active");
  232. clearInterval(timer);
  233. timer = setInterval(function () {
  234. n++;
  235. var m = parseInt(n / 60 % 60);
  236. var s = parseInt(n % 60);
  237. $(".thsc").text(toDub(m) + ":" + toDub(s));
  238. }, 1000);
  239. }
  240. }
  241. function toDub(i) {
  242. return i < 10 ? "0" + i : "" + i;
  243. }
  244. //外呼
  245. function MakeCallBack() {
  246. $("#top-search li i").removeClass("active");
  247. $(".DropCall").addClass("active");
  248. }
  249. //置忙置闲
  250. function SetState(obj) {
  251. if (obj.State == '5') {
  252. $(".SayBusy").removeClass("active");
  253. $(".SayFree").addClass("active");
  254. $(".zxzt").removeClass("bl").removeClass("lx");
  255. $(".zxzt").addClass("br");
  256. }
  257. if (obj.State == '2') {
  258. $(".SayBusy").addClass("active");
  259. $(".SayFree").removeClass("active");
  260. $(".zxzt").removeClass("lx").removeClass("br");
  261. $(".zxzt").addClass("bl");
  262. }
  263. }
  264. //置忙
  265. function SayBusyBack() {
  266. $(".SayBusy").removeClass("active");
  267. $(".SayFree").addClass("active");
  268. }
  269. //置闲
  270. function SayFreeBack() {
  271. $(".SayBusy").addClass("active");
  272. $(".SayFree").removeClass("active");
  273. }
  274. //多方通话
  275. function MeetingBack() {
  276. }
  277. //转移
  278. function TransferBack() {
  279. $("#top-search li i").removeClass("active");
  280. $(".Logout").addClass("active");
  281. $(".SayBusy").addClass("active");
  282. $(".MakeCall").addClass("active");
  283. }
  284. //保持
  285. function HoldBack() {
  286. $(".Hold").removeClass("active");
  287. $(".Retrieve").addClass("active");
  288. }
  289. //接回
  290. function RetrieveBack() {
  291. $(".Hold").addClass("active");
  292. $(".Retrieve").removeClass("active");
  293. }
  294. //监测
  295. function SubScribeBack() {
  296. var obj = $("iframe:visible")
  297. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  298. window.frames[obj.attr("name")].Start();
  299. }
  300. }
  301. //取消监测
  302. function SubScribeCancelBack() {
  303. var obj = $("iframe:visible")
  304. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  305. window.frames[obj.attr("name")].Stop();
  306. }
  307. }
  308. //班长监测返回状态
  309. //坐席状态
  310. function AgentStateBack(data) {
  311. var obj = $("iframe:visible")
  312. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  313. window.frames[obj.attr("name")].UpdateAgentState(data.AgentID, data.State);
  314. }
  315. }
  316. //线路状态
  317. function LineStateBack(data) {
  318. var obj = $("iframe:visible")
  319. if (obj.attr("data-id") == "./TelCall/SeatMonitor.html") {
  320. window.frames[obj.attr("name")].UpdateLineState(data.AgentID, data.State);
  321. }
  322. }
  323. //录音返回
  324. function RecordPathBack(data) {
  325. if ($(".hidTel").val() && $(".hidCallID").val()) {
  326. $.post(huayi.config.callcenter_url + 'CallInScreen/UpdateLY', { callid: $(".hidCallID").val(),path:data.RecPath, "token": $.cookie("token") }, function (result) {
  327. result = JSON.parse(result);
  328. if (result.state.toLowerCase() == "success") {
  329. }
  330. })
  331. }
  332. }
  333. //获取当前的日期时间 格式“yyyy-MM-dd HH:mm:ss”
  334. function getNowFormatDate() {
  335. var date = new Date();
  336. var seperator1 = "-";
  337. var seperator2 = ":";
  338. var month = date.getMonth() + 1;
  339. var strDate = date.getDate();
  340. if (month >= 1 && month <= 9) {
  341. month = "0" + month;
  342. }
  343. if (strDate >= 0 && strDate <= 9) {
  344. strDate = "0" + strDate;
  345. }
  346. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  347. + " " + date.getHours() + seperator2 + date.getMinutes()
  348. + seperator2 + date.getSeconds();
  349. return currentdate;
  350. }
  351. //来电弹屏
  352. laydate.skin('molv');
  353. //laydate({
  354. // elem: '#startTime',
  355. // event: 'focus'
  356. //});
  357. //laydate({
  358. // elem: '#endTime',
  359. // event: 'focus'
  360. //});
  361. //laydate({
  362. // elem: '#bx_startTime',
  363. // event: 'focus'
  364. //});
  365. //laydate({
  366. // elem: '#bx_endTime',
  367. // event: 'focus'
  368. //});
  369. laydate({
  370. elem: '#old_startTime',
  371. event: 'focus'
  372. });
  373. laydate({
  374. elem: '#old_endTime',
  375. event: 'focus'
  376. });
  377. laydate({
  378. elem: '#con_startTime',
  379. event: 'focus'
  380. });
  381. laydate({
  382. elem: '#con_endTime',
  383. event: 'focus'
  384. });
  385. //弹屏右侧切换效果
  386. $(".ldtp-cr ul.ld-service li").click(function() {
  387. $(this).addClass("cr-click").siblings().removeClass("cr-click");
  388. //var inedx = $(this).index();
  389. //console.log(inedx);
  390. //var indexCon = $('.ld-sercon>div').eq(inedx);
  391. //indexCon.show();
  392. //indexCon.siblings().hide();
  393. //indexCon.find('.ld-sercon-con').show();
  394. //indexCon.find('.second-con').hide();
  395. //indexCon.find('.addjl').click(function() {
  396. // var par = $(this).parent().parent();
  397. // par.hide().siblings().show();
  398. //})
  399. loadOld();
  400. });
  401. $('.pre-add').click(function() {
  402. var par = $(this).parent().parent();
  403. par.hide().siblings().show();
  404. })
  405. //最大化 最小化效果
  406. //最小化
  407. $('.minClosed').click(function () {
  408. $('.ldtp-con').removeClass('fadeInDown');
  409. $('.ldtp-con').addClass('fadeOutUp');
  410. $('.ldtp-con').css("display", "none");
  411. $('.maxOpen').show();
  412. $('.maxOpen').addClass('fadeInDown');
  413. });
  414. //最大化
  415. $('.maxOpen').click(function() {
  416. $('.ldtp-con').removeClass('fadeOutUp');
  417. $('.ldtp-con').addClass('fadeInDown');
  418. $('.ldtp-con').css("display","block");
  419. $('.maxOpen').hide();
  420. $('.maxOpen').removeClass('fadeInDown');
  421. $('.maxOpen').addClass('fadeInDown');
  422. $('.first').removeClass('first');
  423. $('.ldtp-con').addClass('first');
  424. })
  425. //关闭弹框
  426. $(".Bacha").click(function () {
  427. $('.ldtp-con').removeClass('fadeInDown');
  428. $('.ldtp-con').addClass('fadeOutUp');
  429. $('.ldtp-con').css("display", "none");
  430. obj.Type = "SayFree";
  431. Send();
  432. })
  433. //顶部小头像
  434. var little_pic = $('.head-pic .hp-box img').attr("src");
  435. //console.log(little_pic);
  436. $('.maxOpen li .photo img').attr("src", little_pic);
  437. //$('.ldtp-cr').scroll(function() {
  438. // var scheit = $('.ldtp-cr').scrollTop();
  439. // //console.log(scheit);
  440. // if (scheit > 10) {
  441. // $('.minClosed').css({
  442. // 'background': '#000',
  443. // 'top': '13px',
  444. // 'right': '15px'
  445. // });
  446. // $('.minClosed a').css('background', '#fff');
  447. // } else {
  448. // $('.minClosed').css({
  449. // 'background': '',
  450. // 'top': '0',
  451. // 'right': '80px'
  452. // }) ;
  453. // $('.minClosed a').css('background', '#000');
  454. // }
  455. //})
  456. //点击左侧菜单来电弹屏显示
  457. $('.tantan').click(function () {
  458. $('.maxOpen').trigger("click");
  459. $('.head-pic .lahei .la-before').show();
  460. $('.head-pic .lahei .la-after').hide();
  461. loadOld();
  462. })
  463. //点击挂断
  464. $('.head-pic .td-call .take').click(function() {
  465. //$('.ldtp-con').css("display", 'none');
  466. obj.Type = "DropCall";
  467. Send();
  468. }) ;
  469. //点击拉黑事件
  470. $('.head-pic .lahei .la-before').click(function () {
  471. if (!$(".hidTel").val()) {
  472. layer.confirm('来电号码为空!', {
  473. btn: ['确定']
  474. });
  475. return;
  476. }
  477. $("#time-word").val('');
  478. $('.ldtp-con .hei-list').show();
  479. //$('.ldtp-con .hei-list').removeClass('bounceOutUp');
  480. //$('.ldtp-con .hei-list').addClass('bounceIn');
  481. })
  482. //拉黑输入框事件
  483. $('.hei-list .bacha').click(function(){
  484. //$('.ldtp-con .hei-list').removeClass('bounceIn');
  485. //$('.ldtp-con .hei-list').addClass('bounceOutUp');
  486. $('.ldtp-con .hei-list').hide();
  487. $("#time-word").val('');
  488. })
  489. var reg = /^\+?[1-9][0-9]*$/;
  490. $('#bc').click(function () {
  491. var n = $("#time-word").val();
  492. var val = $("input[name='time']:checked").val();
  493. if (n) {
  494. if (!(reg.test(n))) {
  495. layer.confirm('请输入整数时间!', {
  496. btn: ['确定']
  497. });
  498. return;
  499. }
  500. }
  501. else {
  502. if (val == '4') {
  503. n = 0;
  504. }
  505. else {
  506. layer.confirm('请输入整数时间!', {
  507. btn: ['确定']
  508. });
  509. return;
  510. }
  511. }
  512. $.post(huayi.config.callcenter_url+'CallInScreen/AddBlack',{tel: $(".hidTel").val(), num: n, type: val,"token": $.cookie("token")}, function (result) {
  513. result = $.parseJSON(result);
  514. if (result.state.toLowerCase() == "success") {
  515. layer.msg("拉入黑名单成功");
  516. $('.la-shichang .blackTime').html(result.data);
  517. //$('.ldtp-con .hei-list').removeClass('bounceIn');
  518. //$('.ldtp-con .hei-list').addClass('bounceOutUp');
  519. $('.ldtp-con .hei-list').hide();
  520. $('.head-pic .lahei .la-before').hide();
  521. $('.head-pic .lahei .la-after').show();
  522. $('.head-pic .lahei .retur').show();
  523. }
  524. })
  525. })
  526. $('.la-after').click(function () {
  527. if (!$(".hidTel").val()) {
  528. layer.confirm('来电号码为空!', {
  529. btn: ['确定']
  530. });
  531. return;
  532. }
  533. $("#time-word").val('');
  534. $('.ldtp-con .hei-list').show();
  535. $('.ldtp-con .hei-list').removeClass('bounceOutUp');
  536. $('.ldtp-con .hei-list').addClass('bounceIn');
  537. })
  538. $('.head-pic .lahei .retur').click(function () {
  539. $.getJSON(huayi.config.callcenter_url+'CallInScreen/DelBlack', { tel: $(".hidTel").val(), "token": $.cookie("token") }, function (result) {
  540. if (result.state.toLowerCase() == "success") {
  541. layer.msg("取消黑名单成功");
  542. $('.head-pic .lahei .retur').hide();
  543. $('.head-pic .lahei .la-after').hide();
  544. $('.head-pic .lahei .la-before').show();
  545. }
  546. })
  547. })