mainCtrl.js 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562
  1. 'use strict';
  2. /**
  3. * Clip-Two Main Controller
  4. */
  5. app.controller('AppCtrl', ['$rootScope', '$scope', '$state', '$translate', '$localStorage', '$cookieStore', '$window', '$modal', '$document', '$timeout', '$filter', '$auth', 'cfpLoadingBar', 'DDP', 'deskNotification', 'Restangular', 'api_login', 'api_text', 'api_user_data', 'api_wechatfile', 'api_bpm_data', 'api_msg', 'Myservice', '$interval', 'jry_api_bpm',
  6. function ($rootScope, $scope, $state, $translate, $localStorage, $cookieStore, $window, $modal, $document, $timeout, $filter, $auth, cfpLoadingBar, DDP, deskNotification, Restangular, api_login, api_text, api_user_data, api_wechatfile, api_bpm_data, api_msg, Myservice, $interval, jry_api_bpm) {
  7. if(localStorage.getItem('version_qd')){
  8. $rootScope[localStorage.getItem('version_qd')] = true;
  9. }
  10. // 未读消息数量seimin
  11. $rootScope.getMsgNum = function (id) {
  12. api_msg.msgDataList({ idx: 0, sum: 1, messageStation: { readStatus: 0, userId: id } }).then(function (data) {
  13. if (data.status == 200) {
  14. $rootScope.noReadData = data.totalNum;
  15. }
  16. return $rootScope.noReadData
  17. })
  18. }
  19. // Loading bar transition
  20. // -----------------------------------
  21. // console.log("haha");
  22. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  23. $rootScope.isFuwutai = JSON.parse(localStorage.getItem("isFuwutai")) ? true : false;
  24. console.log($rootScope.user)
  25. if ($rootScope.user) {
  26. $rootScope.getMsgNum($rootScope.user.id);
  27. }
  28. var $win = $($window);
  29. $rootScope.isMask = false;
  30. window.onbeforeunload = function () {
  31. $rootScope.statuscall = 0;
  32. $rootScope.statecall = 1;
  33. }
  34. // 所有列表自动刷新
  35. $rootScope.refreshTime = 30000;
  36. $interval(function () {
  37. $scope.jry_year = new Date().getFullYear();
  38. $scope.jry_month = new Date().getMonth() + 1;
  39. $scope.jry_data = new Date().getDate();
  40. $scope.jry_hours = new Date().getHours();
  41. $scope.jry_minute = new Date().getMinutes();
  42. $scope.jry_second = new Date().getSeconds();
  43. // console.log($scope.jry_month)
  44. }, 1000)
  45. // $win.on('beforeunload', function() { return $state.go("login.signin"); });
  46. // $auth.deleteData('auth_headers')
  47. // }
  48. // 监听路由
  49. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  50. console.log(event, toState, toParams, fromState, fromParams)
  51. if(localStorage.getItem('version_qd')){
  52. $rootScope[localStorage.getItem('version_qd')] = true;
  53. }
  54. if($rootScope.isZncd){
  55. // 中南财大
  56. if ((toState.name == 'app.incident.chart' || toState.name == 'app.incident.editor') &&
  57. fromState.name) {
  58. console.log($rootScope.jry_state);
  59. $scope.isShixian = false;
  60. if($rootScope.jry_state == 'shixian'){
  61. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  62. //进入页面强制示忙
  63. if (tlwsa) {
  64. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  65. setTimeout(()=>{
  66. tlwsa.tlaAcw();
  67. },0)
  68. }
  69. }
  70. }
  71. if ((fromState.name == 'app.incident.chart' || fromState.name == 'app.incident.editor') &&
  72. toState.name != 'app.incident.chart' && toState.name != 'app.incident.editor'
  73. ) {
  74. console.log($rootScope.jry_state);
  75. // $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  76. //进入页面强制示闲
  77. $scope.isShixian = true;
  78. // if (tlwsa) {
  79. // // tlwsa.tlaForcewca($rootScope.phoneNumber);
  80. // tlwsa.tlaWca();
  81. // }
  82. }
  83. }else if($rootScope.isHk){
  84. if (toState.name != "app.incident.editor" && toState.name != "echart") {
  85. if ($rootScope.status == 2 || $rootScope.status == 4 || $rootScope.status == 9) {
  86. $rootScope.setidle();
  87. }
  88. }
  89. if (toState.name != "app.incident.editor" && toState.name != "app.incident.title") {
  90. if ($scope.login && $rootScope.statecall == 2 && !$rootScope.busy) {
  91. $rootScope.setidle();
  92. }
  93. } else {
  94. if ($scope.login && !$rootScope.busy) {
  95. $rootScope.setbusy();
  96. }
  97. // $rootScope.isMask = true;
  98. }
  99. }
  100. if (isEmpty($auth.retrieveData('auth_headers'))) {
  101. // if (toState.name != "login.signin" && toState.name != "echart") {
  102. // event.preventDefault();
  103. // $rootScope.app.isLoginFixed = true;
  104. // // $scope.lodingstyle = 'nodata';
  105. // return $state.go("login.signin");
  106. // }
  107. }
  108. // if (toState.name == "app.system.user.user") {
  109. // var isgoto = false;
  110. // if ($rootScope.user && $rootScope.user.menu) {
  111. // angular.forEach($rootScope.user.menu, function(item) {
  112. // if (item.link == toState.name) {
  113. // isgoto = true;
  114. // } else {}
  115. // })
  116. // }
  117. // if (isgoto) {
  118. // } else {
  119. // $state.go("app.dashboard");
  120. // }
  121. // }
  122. // if (toState.name != "app.incident.editor" && toState.name != "echart") {
  123. // if ($rootScope.status == 2 || $rootScope.status == 4 || $rootScope.status == 9) {
  124. // $rootScope.setidle();
  125. // }
  126. // }
  127. cfpLoadingBar.start();
  128. $auth.validateUser();
  129. });
  130. $rootScope.imUsrMap = {};
  131. $rootScope.onlineUser = [];
  132. $rootScope.offlineUser = [];
  133. $rootScope.me = undefined;
  134. $rootScope.imscope = {
  135. sessions: []
  136. }
  137. // var ws = new WebSocket('ws://192.168.3.51:8088/events');
  138. // var register= {"msgtype":"login","adn":"1001"};
  139. // ws.onopen = function() { ws.send(JSON.stringify(register));}
  140. // ws.onmessage = function(evt) { console.log(evt.data) }
  141. var ddp = new DDP('ws://115.156.150.70:3000/websocket');
  142. $rootScope.getDirectMsgRoomId = function (mdId, toId) {
  143. //me.id,to.id
  144. var rid = [mdId, toId].sort().join('');
  145. return rid;
  146. };
  147. $rootScope.sendMessage = function (rid, msg, callback, error) {
  148. ddp.call('sendMessage', [{ 'rid': rid, 'msg': msg }]).then(callback, error);
  149. };
  150. var pushNotification = function (notification) {
  151. deskNotification.showNotification(notification.title, {
  152. body: notification.body,
  153. icon: notification.icon || '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  154. onClick: notification.callback || function onNotificationClicked() {
  155. // console.log('Notification clicked.');
  156. },
  157. autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
  158. }, function onShow(error, hide) {
  159. if (error) {
  160. window.alert('Unable to show notification: ' + error.message);
  161. } else {
  162. // console.log('Notification Shown.');
  163. setTimeout(function hideNotification() {
  164. // console.log('Hiding notification....');
  165. hide(); //manually close the notification (you can skip this if you use the autoClose option)
  166. }, 5000);
  167. }
  168. });
  169. }
  170. // $rootScope.subscribeRoomMessage = function(rid){
  171. // ddp.subscribe('stream-room-messages',[rid, true]).then(function(){},function(reason){
  172. // console.log('subscribe stream-room-messages:%o', reason);
  173. // });
  174. // }
  175. $rootScope.filternotifyuser = [];
  176. $rootScope.$on('openroom', function (event, data, otheruser) {
  177. ddp.call('createDirectMessage', [otheruser]).then(function () { }, function (reason) {
  178. // console.log('createDirectMessage', reason);
  179. });
  180. ddp.subscribe('stream-room-messages', [data.rid, true]).then(function () { }, function (reason) {
  181. // console.log('subscribe stream-room-messages:%o', reason);
  182. });
  183. if ($rootScope.imUsrMap[data.from]['unread'].msgs) {
  184. $rootScope.imUsrMap[data.from]['unread'].msgs.clear;
  185. }
  186. $rootScope.filternotifyuser.push(data.from);
  187. });
  188. $rootScope.$on("clip-two.toggled", function (e, target, newState, sameGroup) {
  189. console.log(newState)
  190. if (newState == false && target == 'off-sidebar') {
  191. $rootScope.$broadcast('chatcloseroom');
  192. //$rootScope.toggle("users");
  193. //$rootScope.filternotifyuser = [];
  194. //ddp.unsubscribe('stream-room-messages');
  195. }
  196. });
  197. $rootScope.$on("closeroom", function (event, data) {
  198. $rootScope.filternotifyuser = [];
  199. ddp.unsubscribe('stream-room-messages');
  200. });
  201. var initImUser = function (email, token) {
  202. var ddpconnect = ddp.connect();
  203. ddpconnect.then(function (data) {
  204. //console.log(data);
  205. if (data.session) {
  206. // ddp.call('createDirectMessage', [data.from, data.rid]).then(function() {}, function(reason) {
  207. // console.log('subscribe createDirectMessage');
  208. // });
  209. ddp.call('login', [{ user: { email: email }, password: token }]).then(function (data) {
  210. // console.log('login data: %o', data);
  211. if (data.id) {
  212. $rootScope.me = {
  213. id: data.id,
  214. token: data.token,
  215. expiry: data.tokenExpires
  216. };
  217. //获取在线用户
  218. ddp.subscribe('activeUsers');
  219. ddp.subscribe('stream-notify-user', [$rootScope.me.id + '/notification', true]).then(function (result) {
  220. //console.log(result);
  221. }, function (reason) {
  222. // console.log('stream-notify-user error:%s', reason);
  223. });
  224. // ddp.subscribe('stream-notify-user',[$rootScope.me.id+'/message',false]).then(function(result){
  225. // console.log(result);
  226. // },function(reason){
  227. // console.log('stream-notify-user error:', reason);
  228. // });
  229. ddp.subscribe('messages', [$rootScope.me.id + '/message', true]).then(function () { }, function (reason) {
  230. // console.log('subscribe messages error:%s', reason);
  231. });
  232. //'stream-notify-user',$rootScope.me.id+'/message'
  233. // ddp.call('sendmessage', []).then(function(msg){
  234. // })
  235. //console.log('Logged in!');
  236. // ddp.subscribe('messages', [{rid:data.id,start:new Date()}]).then(function(submsg){
  237. // console.log('subscribe messages-%s', submsg);
  238. // $rootScope.rocketchat_message = ddp.getCollection('rocketchat_message');
  239. // },function(reason){
  240. // console.log(reason);
  241. // })
  242. }
  243. }, function (reason) {
  244. // console.log(reason);
  245. });
  246. } else {
  247. }
  248. ddp.watch('users', function (changedDoc, message) {
  249. //console.log('users:%o',changedDoc);
  250. // if (message == 'method') {
  251. // console.log("1111111111111111111")
  252. // }
  253. if (message == 'added') {
  254. if (changedDoc.status && ($rootScope.me.id != changedDoc._id)) {
  255. if (changedDoc.status == 'away') {
  256. $rootScope.offlineUser.push(changedDoc);
  257. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  258. } else {
  259. $rootScope.onlineUser.push(changedDoc);
  260. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  261. }
  262. } else {
  263. //self
  264. }
  265. } else if (message == 'changed') {
  266. if ($rootScope.me.id != changedDoc._id) {
  267. if (!$rootScope.imUsrMap[changedDoc._id]) {
  268. if (changedDoc.status == 'away') {
  269. $rootScope.offlineUser.push(changedDoc);
  270. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  271. } else {
  272. $rootScope.onlineUser.push(changedDoc);
  273. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  274. }
  275. }
  276. if (changedDoc.status == 'away') {
  277. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  278. } else {
  279. $rootScope.offlineUser.push(changedDoc);
  280. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  281. window._.map(window._.slice($rootScope.onlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  282. $rootScope.imUsrMap[item._id].index = n;
  283. })
  284. // $rootScope.onlineUser = window._.take($rootScope.onlineUser,$rootScope.imUsrMap[changedDoc._id].index).concat(window._.map(window._.slice($rootScope.onlineUser,$rootScope.imUsrMap[changedDoc._id].index+1),function(item){
  285. // item.index = item.index - 1;
  286. // }))
  287. //.splice($rootScope.imUsrMap[changedDoc.id].index,1);
  288. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.offlineUser.length };
  289. }
  290. } else {
  291. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  292. $rootScope.onlineUser.push(changedDoc);
  293. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  294. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  295. $rootScope.imUsrMap[item._id].index = n;
  296. })
  297. // $rootScope.offlineUser = window._.take($rootScope.offlineUser,$rootScope.imUsrMap[changedDoc._id].index).concat(window._.map(window._.slice($rootScope.offlineUser,$rootScope.imUsrMap[changedDoc._id].index+1),function(item){
  298. // item.index = item.index - 1;
  299. // }))
  300. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length };
  301. } else {
  302. }
  303. }
  304. }
  305. } else if (message == 'removed') {
  306. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  307. } else {
  308. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  309. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  310. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  311. $rootScope.imUsrMap[item._id].index = n;
  312. });
  313. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length, unread: { total: 0, msgs: [] } };
  314. }
  315. }
  316. });
  317. ddp.watch('stream-notify-user', function (changedDoc, message) {
  318. if (message == 'changed') {
  319. if (changedDoc.eventName) {
  320. if (changedDoc.eventName.indexOf('/') > -1) {
  321. // var [mineId, action] = changedDoc.eventName.split('/');
  322. var mineId = changedDoc.eventName.split('/');
  323. var action = mineId;
  324. if (action == 'notification') {
  325. angular.forEach(changedDoc.args, function (item) {
  326. if ($rootScope.filternotifyuser.indexOf(item.payload.sender._id) > -1) {
  327. } else {
  328. // console.log("push notify message:%o", item);
  329. var r = angular.extend(item, { 'date': new Date() })
  330. $rootScope.imUsrMap[item.payload.sender._id]['unread'].msgs.push(r);
  331. $rootScope.imUsrMap[item.payload.sender._id]['unread'].total++;
  332. pushNotification({
  333. title: "您有新消息-来自" + item.payload.sender.username,
  334. body: r.text,
  335. callback: function () {
  336. window.focus();
  337. $rootScope.toggle('off-sidebar');
  338. }
  339. })
  340. //toaster.pop('info', "您有新消息-来自"+item.payload.sender.username, r.text);
  341. }
  342. })
  343. }
  344. }
  345. }
  346. } else {
  347. }
  348. //console.log('notify message %o, %o', changedDoc, message);
  349. });
  350. ddp.watch('stream-room-messages', function (changedDoc, message) {
  351. if (message == 'changed') {
  352. //angular.forEach(changedDoc.args,function(item){
  353. $rootScope.$broadcast(changedDoc.eventName + '-msgs', changedDoc.args);
  354. //};
  355. // if(changedDoc.eventName){
  356. // $rootScope.imUsrMap[eventName]=$rootScope.imUsrMap[eventName]||{};
  357. // $rootScope.imUsrMap[eventName]['msgs']=$rootScope.imUsrMap[eventName]['msgs']||[];
  358. // angular.forEach(changedDoc.args,function(item){
  359. // $rootScope.imUsrMap[eventName].msgs.push(item);
  360. // })
  361. // }
  362. } else {
  363. }
  364. // console.log('notify message %o, %o', changedDoc, message);
  365. });
  366. ddp.watch('rocketchat_message', function (changedDoc, message) {
  367. // console.log('recieve rocketchat_message: %o-%o', changedDoc, message);
  368. });
  369. });
  370. }
  371. window.onunload = function () {
  372. }
  373. $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
  374. //$auth.validateUser();
  375. //stop loading bar on stateChangeSuccess
  376. event.targetScope.$watch("$viewContentLoaded", function () {
  377. cfpLoadingBar.complete();
  378. });
  379. // scroll top the page on change state
  380. $document.scrollTo(0, 0);
  381. if (angular.element('.email-reader').length) {
  382. angular.element('.email-reader').animate({
  383. scrollTop: 0
  384. }, 0);
  385. }
  386. // Save the route title
  387. $rootScope.currTitle = $state.current.title;
  388. if (angular.isDefined($state.current.pdKey)) {
  389. $rootScope.pdKey = $state.current.pdKey;
  390. }
  391. // console.log($state.current.title);
  392. });
  393. // State not found
  394. $rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) {
  395. //$rootScope.loading = false;
  396. if (angular.isUndefined($rootScope.user.id)) {
  397. $rootScope.loading = false;
  398. }
  399. // console.log(unfoundState.to);
  400. // "lazy.state"
  401. // console.log(unfoundState.toParams);
  402. // {a:1, b:2}
  403. // console.log(unfoundState.options);
  404. // {inherit:false} + default options
  405. });
  406. $rootScope.isMousedown = false;
  407. $rootScope.changeRemoveClass = function (e) {
  408. $rootScope.isMousedown = true
  409. }
  410. $rootScope.returnRemoveClass = function (e) {
  411. $rootScope.isMousedown = false;
  412. }
  413. $rootScope.$on('auth:login-success', function (ev, data) {
  414. // $state.go('login.signin');
  415. initImUser(data.email, data.msgUuid);
  416. getMenus();
  417. //console.log(data);
  418. //$rootScope.user = data.user;
  419. //$rootScope.menus = data.menu;
  420. });
  421. //$rootScope.$watch('$auth.user')
  422. // $rootScope.$on('auth:validation-success', function(ev, user) {
  423. // // console.log(user);
  424. // initImUser(user.email, user.msgUuid);
  425. // if ($rootScope.userMenus.length == 0) {
  426. // getMenus();
  427. // }
  428. // //alert('Welcome ', user.email);
  429. // });
  430. // $rootScope.$on('auth:invalid', function(ev) {
  431. // $state.go('login.signin');
  432. // });
  433. // $rootScope.$on('auth:validation-error', function(ev) {
  434. // $state.go('login.signin');
  435. // //alert('Welcome ', user.email);
  436. // });
  437. // $rootScope.$on('auth:session-expired', function(ev) {
  438. // //alert('Welcome ', user.email);
  439. // $state.go('login.signin');
  440. // });
  441. // $rootScope.$on('auth:logout-success', function(ev) {
  442. // //alert('goodbye');
  443. // //delete $rootScope.user;
  444. // //delete $rootScope.menus;
  445. // $state.go('login.signin');
  446. // });
  447. // $rootScope.$on('auth:logout-error', function(ev) {
  448. // $state.go('login.signin');
  449. // });
  450. $rootScope.pageTitle = function () {
  451. // if($rootScope.currTitle){
  452. // return $rootScope.app.name + ' - ' + $filter('translate')($rootScope.currTitle) || $rootScope.app.description;
  453. // }else{
  454. // return $rootScope.app.name + ' - ' + $rootScope.app.description
  455. // }
  456. var perfix = "sidebar.nav.";
  457. var toTransKeypageTitle = perfix + $rootScope.currTitle;
  458. return $rootScope.app.name + ' - ' + ($filter('translate')(toTransKeypageTitle) || $rootScope.app.description);
  459. };
  460. // $auth.validateUser();
  461. // $auth.authenticate('local').then(function(resp){
  462. // }).catch(function(resp){
  463. // })
  464. // if(angular.isDefined($rootScope.nickname)){
  465. // api_login.sso($rootScope.nickname).then(function(response){
  466. // var user = Restangular.stripRestangular(response);
  467. // if (user) {
  468. // if(angular.isUndefined(user.id)){
  469. // }else{
  470. // $rootScope.user = user;
  471. // }
  472. // }
  473. // });
  474. // }else{
  475. // var user= $cookieStore.get("userObm");
  476. // if(user){
  477. // $rootScope.user = user;
  478. // $rootScope.menus = $cookieStore.get("menuObm");
  479. // }else{
  480. // if(angular.isDefined($rootScope.nickname)){
  481. // api_login.sso($rootScope.nickname).then(function(response){
  482. // var data = Restangular.stripRestangular(response);
  483. // if (data) {
  484. // if(data.user){
  485. // if(angular.isUndefined(data.user.id)){
  486. // }else{
  487. // $rootScope.user = data.user;
  488. // $rootScope.menus = data.menu;
  489. // $cookieStore.put("userObm", $rootScope.user);
  490. // $cookieStore.put("menuObm", $rootScope.menus);
  491. // $cookieStore.put("session", data.sessionId);
  492. // }
  493. // }
  494. // }
  495. // });
  496. // }else{
  497. // }
  498. // }
  499. //}
  500. //选择坐席号
  501. $scope.changeWorkId = function () {
  502. event.stopPropagation();
  503. }
  504. $rootScope.getSession = function () {
  505. if ($auth.userIsAuthenticated()) {
  506. return $auth.retrieveData('auth_headers')
  507. /*return {
  508. 'access-token':$auth.retrieveData('auth_headers')['access-token'],
  509. 'expiry':$auth.retrieveData('auth_headers')['expiry']
  510. };*/
  511. } else {
  512. return undefined;
  513. }
  514. }
  515. $scope.includes = [];
  516. $rootScope.includesState = function (state) {
  517. //for test
  518. //return true;
  519. //return includes;
  520. if ($rootScope.user) {
  521. if ($rootScope.user.menu) {
  522. angular.forEach($rootScope.user.menu, function (item) {
  523. $scope.includes[item.link] = true;
  524. });
  525. }
  526. }
  527. return $scope.includes[state];
  528. }
  529. //大屏入口
  530. $rootScope.opendashbord = function () {
  531. $state.go('echart');
  532. }
  533. // $rootScope.authority=false;
  534. // console.log($rootScope.user)
  535. // if($rootScope.user.role){
  536. // for(var i ;i<$rootScope.user.role.length;i++){
  537. // if($rootScope.user.role[i].rolecode=='call center') {
  538. // $rootScope.authority=true;
  539. // }else{$rootScope.authority=false;}
  540. // }
  541. // }
  542. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  543. // if (window.location.href && window.location.href.hash == "#/echart") {
  544. // } else {
  545. // // }
  546. // // 东经呼叫中心开始
  547. // $rootScope.statuscall = 0; //话机状态
  548. // $rootScope.statecall = 1; //示忙示闲
  549. // $scope.login = false; //签入签出
  550. // $rootScope.callout = false; //呼入呼出
  551. // $scope.group = 2000;
  552. // $scope.phone = 1500;
  553. // $rootScope.start = function(phone, group) {
  554. // api_text.start(phone, $rootScope.user.id).then(function(data) {
  555. // var token = data.token;
  556. // $rootScope.takes = token;
  557. // api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  558. // api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  559. // if (data.errno == 0) {
  560. // $rootScope.setidle();
  561. // $scope.login = true;
  562. // $rootScope.statuscall = 1;
  563. // $rootScope.callout = false;
  564. // // function hello() {
  565. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  566. // // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  567. // // };
  568. // // window.setTimeout("hello()", 1000);
  569. // // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  570. // function reconnect() {
  571. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  572. // var ws = new WebSocket('ws://115.156.150.70:28088/events');
  573. // var register = { "msgtype": "login", "adn": phone };
  574. // ws.onopen = function() {
  575. // heartCheck.start();
  576. // ws.send(JSON.stringify(register));
  577. // };
  578. // ws.onmessage = function(evt) {
  579. // heartCheck.reset();
  580. // if (evt.data == "HeartBeat") {
  581. // } else {
  582. // var mydata = JSON.parse(evt.data);
  583. // $scope.filterData = [];
  584. // if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  585. // $rootScope.$apply(function() {
  586. // $rootScope.statuscall = 2;
  587. // });
  588. // $rootScope.callout = false;
  589. // $rootScope.phone = mydata.ano;
  590. // var Notification = window.Notification;
  591. // Notification.requestPermission();
  592. // var n = new Notification("你有来电", {
  593. // body: "来电号码:" + mydata.ano,
  594. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  595. // // onclick: function onNotificationClicked() {
  596. // // console.log('Notification clicked.');
  597. // // }
  598. // });
  599. // } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  600. // $rootScope.callout = true;
  601. // } else if (mydata.evttype == "ringstop") {
  602. // // $rootScope.status=7;
  603. // // $rootScope.$apply(function() {
  604. // $rootScope.statuscall = 1;
  605. // // });
  606. // $rootScope.phone = ""
  607. // } else if (mydata.evttype == 'hookchanged' && $rootScope.callout) {
  608. // if (mydata.status && mydata.status == '1') {
  609. // $rootScope.$apply(function() {
  610. // $rootScope.statuscall = 1;
  611. // });
  612. // $rootScope.phone = "";
  613. // } else if (mydata.status && mydata.status != '1') {
  614. // $rootScope.$apply(function() {
  615. // $rootScope.statuscall = 3;
  616. // });
  617. // }
  618. // } else if (mydata.evttype == 'hookchanged' && !$rootScope.callout) {
  619. // if ($rootScope.phone != "") {
  620. // if (mydata.status && mydata.status == '1') { //挂机
  621. // $rootScope.$apply(function() {
  622. // $rootScope.statuscall = 1;
  623. // });
  624. // console.log("挂机");
  625. // console.log(mydata);
  626. // } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2) { //摘机
  627. // $rootScope.statuscall = 3;
  628. // api_text.setbusy($rootScope.takes).then(function(data) {
  629. // if (data.errno == 0) {
  630. // $rootScope.statecall = 2;
  631. // $scope.busy = true;
  632. // }
  633. // })
  634. // console.log("摘机");
  635. // console.log(mydata);
  636. // api_text.getcdrid($rootScope.takes).then(function(response) {
  637. // if (response.cdrid) {
  638. // var cdrid = response.cdrid;
  639. // // var response={cdrid:'219023836'}
  640. // var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  641. // api_user_data.fetchDataList('requester', filterData).then(function(data) {
  642. // var myData = Restangular.stripRestangular(data);
  643. // // $rootScope.phone="";
  644. // if (myData.list.length == 0) {
  645. // var modalInstance = $modal.open({
  646. // templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  647. // controller: function($scope, $modalInstance, api_user_data) {
  648. // $scope.title = "新增报修人";
  649. // $scope.requester = {};
  650. // $scope.onChangeadd = function(searchData) {
  651. // $scope.searchKey = searchData.account;
  652. // // $scope.searchDataadd = searchData;
  653. // var requesdata = angular.copy(searchData)
  654. // // if (requesdata.mphone) {
  655. // // delete requesdata.mphone;
  656. // // }
  657. // if (requesdata.telephone) {
  658. // delete requesdata.telephone;
  659. // }
  660. // angular.extend($scope.requester, requesdata);
  661. // }
  662. // $scope.refreshUseradd = function(searchKey) { //请求人搜索
  663. // $scope.requester.account = searchKey;
  664. // $scope.searchData = searchKey;
  665. // serchdataadd(searchKey);
  666. // }
  667. // $scope.getMydata = function(x) {
  668. // var reqestdatap = JSON.parse(x[0])
  669. // // if ($scope.requester.mphone) {
  670. // // delete reqestdatap.mphone;
  671. // // }
  672. // if ($scope.requester.telephone) {
  673. // delete reqestdatap.telephone;
  674. // }
  675. // $scope.searchField = JSON.parse(x[0]).account;
  676. // angular.extend($scope.requester, reqestdatap);
  677. // }
  678. // $scope.getMydataone = function(x) {
  679. // $scope.searchField = x;
  680. // $scope.requester.account = x;
  681. // }
  682. // serchdataadd();
  683. // function serchdataadd(searchKey) {
  684. // if (searchKey) {
  685. // var filterData = {
  686. // 'requester': {
  687. // 'searchKey': searchKey,
  688. // },
  689. // idx: 0,
  690. // sum: 10
  691. // };
  692. // } else {
  693. // var filterData = {
  694. // idx: 0,
  695. // sum: 10
  696. // };
  697. // }
  698. // // serchdataadd(searchKey)
  699. // // if ($scope.model.requester && $scope.model.requester.requesterTypeDTO) {
  700. // // angular.extend(filterData.requester, { 'requesterTypeDTO': $scope.model.requester.requesterTypeDTO })
  701. // // }
  702. // api_user_data.fetchDataList('requester', filterData).then(function(response) {
  703. // var myData = response;
  704. // $scope.myData = myData.list;
  705. // });
  706. // }
  707. // // if ((/^1[34578]\d{9}$/.test($rootScope.phone))) {
  708. // // $scope.requester = { 'mphone': $rootScope.phone };
  709. // // } else {
  710. // // $scope.requester = { 'telephone': $rootScope.phone };
  711. // // }
  712. // $scope.requester = { 'telephone': $rootScope.phone };
  713. // $scope.ok = function() {
  714. // $modalInstance.close($scope.requester);
  715. // };
  716. // $scope.cancel = function() {
  717. // $modalInstance.dismiss('cancel');
  718. // };
  719. // },
  720. // });
  721. // modalInstance.result.then(function(selectedItem) {
  722. // if (selectedItem) {
  723. // if (selectedItem.telephone && !selectedItem.mphone) {
  724. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  725. // delete selectedItem.mphone;
  726. // }
  727. // var data = {
  728. // 'requester': selectedItem
  729. // };
  730. // api_user_data.addData('requester', data).then(function(response) {
  731. // if (response.status == 200) {
  732. // var data = { 'model': { 'requestershow': response.data, 'incident': { 'requester': response.data, 'area': response.areaDTO, 'place': response.placeDTO, 'houseNumber': response.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  733. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  734. // }
  735. // })
  736. // }
  737. // });
  738. // } else if (myData.list.length == 1) {
  739. // var data = { 'model': { 'requestershow': myData.list[0], 'incident': { 'requester': myData.list[0], 'area': myData.list[0].areaDTO, 'place': myData.list[0].placeDTO, 'houseNumber': myData.list[0].houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  740. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  741. // } else {
  742. // var modalInstance = $modal.open({
  743. // templateUrl: 'assets/views/createincident.html',
  744. // controller: function($scope, $modalInstance, api_user_data) {
  745. // $scope.title = "请确定报修人";
  746. // $scope.requester = myData.list;
  747. // $scope.choice = function(requester) {
  748. // $modalInstance.dismiss('cancel');
  749. // var data = { 'model': { 'requestershow': requester, 'incident': { 'requester': requester, 'area': requester.areaDTO, 'place': requester.placeDTO, 'houseNumber': requester.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  750. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  751. // };
  752. // $scope.cancel = function() {
  753. // $modalInstance.dismiss('cancel');
  754. // };
  755. // },
  756. // size: "lg"
  757. // });
  758. // }
  759. // });
  760. // }
  761. // })
  762. // }
  763. // }
  764. // }
  765. // }
  766. // };
  767. // var heartCheck = {
  768. // timeout: 12000, //60ms
  769. // timeoutObj: null,
  770. // serverTimeoutObj: null,
  771. // reset: function() {
  772. // clearTimeout(this.timeoutObj);
  773. // clearTimeout(this.serverTimeoutObj);
  774. // this.start();
  775. // },
  776. // start: function() {
  777. // var self = this;
  778. // this.timeoutObj = setTimeout(function() {
  779. // ws.send("HeartBeat");
  780. // self.serverTimeoutObj = setTimeout(function() {
  781. // ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  782. // }, self.timeout)
  783. // }, this.timeout)
  784. // },
  785. // }
  786. // ws.onclose = function(evt) { reconnect(); }
  787. // ws.onerror = function(evt) { reconnect(); };
  788. // }
  789. // reconnect();
  790. // } else {
  791. // var Notification = window.Notification;
  792. // Notification.requestPermission();
  793. // var n = new Notification("签入失败!", {
  794. // body: data.errmsg,
  795. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  796. // // onclick: function onNotificationClicked() {
  797. // // console.log('Notification clicked.');
  798. // // }
  799. // });
  800. // }
  801. // })
  802. // })
  803. // }
  804. // // 东经呼叫中心结束
  805. // 华科呼叫中心 start
  806. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  807. $rootScope.statuscall = 0; //话机状态
  808. $rootScope.statecall = 1; //示忙示闲
  809. $scope.login = false; //签入签出
  810. $rootScope.callout = 0; //呼入:1,呼出:2
  811. $scope.group = 2000;
  812. $scope.phone = 1500;
  813. $rootScope.phoneChange = function(phone) {
  814. if (phone == 1500||phone == 1501||phone == 1502) {
  815. $scope.group = 2000;
  816. } else if(phone == 1511) {
  817. $scope.group = 2001;
  818. }else if(phone == 1507) {
  819. $scope.group = 2002;
  820. }
  821. }
  822. $rootScope.start = function(phone) {
  823. if (phone == 1500||phone == 1501||phone == 1502) {
  824. $scope.group = 2000;
  825. } else if(phone == 1511) {
  826. $scope.group = 2001;
  827. }else if(phone == 1507) {
  828. $scope.group = 2002;
  829. }
  830. api_text.start(phone, $rootScope.user.id).then(function(data) {
  831. var token = data.token;
  832. $rootScope.takes = token;
  833. api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  834. api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  835. if (data.errno == 0) {
  836. localStorage.setItem('hk_phone',phone);
  837. $rootScope.setidle();
  838. $scope.login = true;
  839. $rootScope.statuscall = 1;
  840. $rootScope.callout = 0;
  841. // function hello() {
  842. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  843. // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  844. // };
  845. // window.setTimeout("hello()", 1000);
  846. // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  847. function reconnect() {
  848. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  849. var ws = new WebSocket('ws://192.168.77.57:8088/IXServer/messagestation/hjzx');
  850. var register = { "msgtype": "login", "adn": phone };
  851. ws.onopen = function() {
  852. heartCheck.start();
  853. ws.send(JSON.stringify(register));
  854. };
  855. ws.onmessage = function(evt) {
  856. heartCheck.reset();
  857. if (evt.data == "HeartBeat") {
  858. } else {
  859. var mydata = JSON.parse(evt.data);
  860. $scope.filterData = [];
  861. if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  862. $rootScope.$apply(function() {
  863. $rootScope.statuscall = 2;
  864. $rootScope.callout = 1;
  865. });
  866. $rootScope.phone = mydata.ano;
  867. var Notification = window.Notification;
  868. Notification.requestPermission();
  869. var n = new Notification("你有来电", {
  870. body: "来电号码:" + mydata.ano,
  871. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  872. // onclick: function onNotificationClicked() {
  873. // console.log('Notification clicked.');
  874. // }
  875. });
  876. } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  877. $rootScope.callout = 2;
  878. } else if (mydata.evttype == "ringstop") {
  879. // $rootScope.status=7;
  880. // $rootScope.$apply(function() {
  881. $rootScope.statuscall = 1;
  882. // });
  883. $rootScope.phone = ""
  884. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout == 2) {
  885. if (mydata.status && mydata.status == '1') {
  886. $rootScope.$apply(function() {
  887. $rootScope.statuscall = 1;
  888. });
  889. $rootScope.phone = "";
  890. } else if (mydata.status && mydata.status != '1') {
  891. $rootScope.$apply(function() {
  892. $rootScope.statuscall = 3;
  893. });
  894. }
  895. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout == 1) {
  896. if ($rootScope.phone != "") {
  897. if (mydata.status && mydata.status == '1') { //挂机
  898. $rootScope.$apply(function() {
  899. $rootScope.statuscall = 1;
  900. $rootScope.callout = 0;
  901. });
  902. // console.log("挂机");
  903. if ($rootScope.statecall == 1 && !$rootScope.isSetidle) {
  904. $rootScope.setbusy();
  905. }
  906. } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2 && $rootScope.callout == 1) { //摘机
  907. $rootScope.status = 6
  908. $rootScope.statuscall = 3;
  909. $rootScope.isSetidle = false;
  910. $rootScope.app.layout.isSidebarClosed = true;
  911. // console.log("摘机");
  912. // console.log(mydata);
  913. api_text.getcdrid($rootScope.takes).then(function(response) {
  914. if (response.cdrid) {
  915. var cdrid = response.cdrid;
  916. // var response={cdrid:'219023836'}
  917. var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  918. api_user_data.fetchDataList('requester', filterData).then(function(data) {
  919. var myData = Restangular.stripRestangular(data);
  920. // $rootScope.phone="";
  921. if (myData.list.length == 0) {
  922. var modalInstance = $modal.open({
  923. backdrop: "static",
  924. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  925. controller: function($scope, $modalInstance, api_user_data, SweetAlert) {
  926. $scope.title = "新增报修人";
  927. $scope.requester = {};
  928. $scope.onChangeadd = function(searchData) {
  929. $scope.searchKey = searchData.account;
  930. // $scope.searchDataadd = searchData;
  931. var requesdata = angular.copy(searchData)
  932. // if (requesdata.mphone) {
  933. // delete requesdata.mphone;
  934. // }
  935. if (requesdata.telephone) {
  936. delete requesdata.telephone;
  937. }
  938. angular.extend($scope.requester, requesdata);
  939. }
  940. $scope.refreshUseradd = function(searchKey) { //请求人搜索
  941. $scope.requester.account = searchKey;
  942. $scope.searchData = searchKey;
  943. serchdataadd(searchKey);
  944. }
  945. $scope.getMydata = function(x) {
  946. var reqestdatap = JSON.parse(x[0])
  947. // if ($scope.requester.mphone) {
  948. // delete reqestdatap.mphone;
  949. // }
  950. if ($scope.requester.telephone) {
  951. delete reqestdatap.telephone;
  952. }
  953. $scope.searchField = JSON.parse(x[0]).account;
  954. angular.extend($scope.requester, reqestdatap);
  955. if ($scope.requester.areaDTO && $scope.requester.areaDTO.id && $scope.requester.areaDTO.id != "") {
  956. api_user_data.fetchDataList('place', { place: { areaId: $scope.requester.areaDTO.id }, idx: 0, sum: 1000 }).then(function(response) {
  957. if (response.status == 200) {
  958. $scope.places = response.list;
  959. }
  960. })
  961. }
  962. }
  963. $scope.getMydataone = function(x) {
  964. $scope.searchField = x;
  965. $scope.requester.account = x;
  966. }
  967. serchdataadd();
  968. function serchdataadd(searchKey) {
  969. if (searchKey) {
  970. var filterData = {
  971. 'requester': {
  972. 'searchKey': searchKey,
  973. },
  974. idx: 0,
  975. sum: 10
  976. };
  977. } else {
  978. var filterData = {
  979. idx: 0,
  980. sum: 10
  981. };
  982. }
  983. api_user_data.fetchDataList('requester', filterData).then(function(response) {
  984. var myData = response;
  985. $scope.myData = myData.list;
  986. });
  987. }
  988. api_user_data.fetchDataList('area', { idx: 0, sum: 100 }).then(function(response) {
  989. if (response.status == 200) {
  990. $scope.areas = response.list;
  991. }
  992. })
  993. // api_user_data.fetchDataList('place', { idx: 0, sum: 1000 }).then(function(response) {
  994. // if (response.status == 200) {
  995. // $scope.places = response.list;
  996. // }
  997. // }) //地点
  998. api_user_data.fetchDataList('requesterType', { idx: 0, sum: 100 }).then(function(response) {
  999. if (response.status == 200) {
  1000. $scope.networktypes = response.list;
  1001. }
  1002. })
  1003. $scope.requesterAreaid = "";
  1004. $scope.onChange = function(item) {
  1005. $scope.requesterAreaid = item.id;
  1006. $scope.requester.place = {};
  1007. api_user_data.fetchDataList('place', { place: { areaId: item.id }, idx: 0, sum: 1000 }).then(function(response) {
  1008. if (response.status == 200) {
  1009. $scope.places = response.list;
  1010. }
  1011. })
  1012. }
  1013. //地点搜索
  1014. $scope.refresh = function(searchVal) {
  1015. var faildata = {};
  1016. if ($scope.requesterAreaid) {
  1017. faildata = {
  1018. 'idx': 0,
  1019. 'sum': 1000,
  1020. 'place': { 'areaId': $scope.requesterAreaid, 'place': searchVal, 'selectType': 'pinyin_qs' }
  1021. }
  1022. } else {
  1023. faildata = {
  1024. 'idx': 0,
  1025. 'sum': 1000,
  1026. 'place': { 'place': searchVal, 'selectType': 'pinyin_qs' }
  1027. }
  1028. }
  1029. api_user_data.fetchDataList('place', faildata).then(function(response) {
  1030. $scope.places = response.list;
  1031. delete $scope.requester.place;
  1032. })
  1033. }
  1034. $scope.requester = { 'telephone': $rootScope.phone };
  1035. $scope.ok = function() {
  1036. // $modalInstance.close($scope.requester);
  1037. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1038. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1039. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1040. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1041. } else {
  1042. $modalInstance.close($scope.requester);
  1043. }
  1044. };
  1045. $scope.cancel = function() {
  1046. $modalInstance.dismiss('cancel');
  1047. $rootScope.setidle();
  1048. };
  1049. },
  1050. });
  1051. modalInstance.result.then(function(selectedItem) {
  1052. if (selectedItem) {
  1053. if (selectedItem.telephone && !selectedItem.mphone) {
  1054. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1055. delete selectedItem.mphone;
  1056. }
  1057. var data = {
  1058. 'requester': selectedItem
  1059. };
  1060. api_user_data.addData('requester', data).then(function(response) {
  1061. if (response.status == 200) {
  1062. var data = {
  1063. model: {
  1064. requestershow: response.data,
  1065. incident: {
  1066. requester: response.data,
  1067. area: response.data.place?response.data.place.area:undefined,
  1068. place: response.data.place,
  1069. houseNumber: response.data.houseNumber,
  1070. contactsInformation: response.data.telephone,
  1071. contacts:response.data.name,
  1072. callID: cdrid,
  1073. source: { id: 1 },
  1074. },
  1075. },
  1076. };
  1077. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1078. }
  1079. })
  1080. }
  1081. });
  1082. } else if (myData.list.length == 1) {
  1083. angular.extend(myData.list[0], { 'telephone': $rootScope.phone });
  1084. var data = {
  1085. model: {
  1086. requestershow: myData.list[0],
  1087. incident: {
  1088. requester: myData.list[0],
  1089. area: myData.list[0].place?myData.list[0].place.area:undefined,
  1090. place: myData.list[0].place,
  1091. contactsInformation: myData.list[0].telephone,
  1092. houseNumber: myData.list[0].houseNumber,
  1093. contacts:myData.list[0].name,
  1094. callID: cdrid,
  1095. source: { id: 1 },
  1096. },
  1097. },
  1098. };
  1099. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1100. } else {
  1101. var modalInstance = $modal.open({
  1102. templateUrl: 'assets/views/createincident.html',
  1103. backdrop: "static",
  1104. controller: function($scope, $modalInstance, api_user_data) {
  1105. $scope.title = "请确定报修人";
  1106. $scope.requester = myData.list;
  1107. $scope.choice = function(requester) {
  1108. $modalInstance.dismiss('cancel');
  1109. angular.extend(requester, { 'telephone': $rootScope.phone });
  1110. var data = {
  1111. model: {
  1112. requestershow: requester,
  1113. incident: {
  1114. requester: requester,
  1115. area: requester.place?requester.place.area:undefined,
  1116. place: requester.place,
  1117. houseNumber: requester.houseNumber,
  1118. contactsInformation: requester.telephone,
  1119. contacts:requester.name,
  1120. callID: cdrid,
  1121. source: { id: 1 },
  1122. },
  1123. },
  1124. };
  1125. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1126. };
  1127. $scope.cancel = function() {
  1128. $modalInstance.dismiss('cancel');
  1129. $rootScope.setidle();
  1130. };
  1131. },
  1132. size: "lg"
  1133. });
  1134. }
  1135. });
  1136. }
  1137. })
  1138. }
  1139. }
  1140. }
  1141. }
  1142. };
  1143. var heartCheck = {
  1144. timeout: 12000, //60ms
  1145. timeoutObj: null,
  1146. serverTimeoutObj: null,
  1147. reset: function() {
  1148. clearTimeout(this.timeoutObj);
  1149. clearTimeout(this.serverTimeoutObj);    
  1150. this.start();
  1151. },
  1152. start: function() {
  1153. var self = this;
  1154. this.timeoutObj = setTimeout(function() {
  1155. if ($scope.login) {
  1156. ws.send("HeartBeat");
  1157. self.serverTimeoutObj = setTimeout(function() {
  1158. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  1159. }, self.timeout)
  1160. }
  1161. }, this.timeout)
  1162. },
  1163. }
  1164. ws.onclose = function(evt) { reconnect(); }
  1165. ws.onerror = function(evt) { reconnect(); };
  1166. }
  1167. reconnect();
  1168. } else {
  1169. var Notification = window.Notification;
  1170. Notification.requestPermission();
  1171. var n = new Notification("签入失败!", {
  1172. body: data.errmsg,
  1173. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1174. // onclick: function onNotificationClicked() {
  1175. // console.log('Notification clicked.');
  1176. // }
  1177. });
  1178. }
  1179. })
  1180. })
  1181. }
  1182. setInterval(function() {
  1183. if ($scope.login && $rootScope.statuscall == 1 && $rootScope.statecall == 1) {
  1184. $rootScope.setidle();
  1185. } else if ($scope.login && $rootScope.statuscall != 3 && $rootScope.statecall == 2 && statuscall != 0) {
  1186. $rootScope.setbusy
  1187. }
  1188. }, 3000);
  1189. // 华科呼叫中心 end
  1190. //话机呼叫中心--开始
  1191. // 1是老的呼叫中心
  1192. // 2是财大2021年12月29日新增的呼叫中心
  1193. // 3是华科新增的呼叫中心
  1194. console.log($rootScope.isHk,'hk')
  1195. console.log($rootScope.isZncd,'zncd')
  1196. if($rootScope.isZncd){
  1197. $rootScope.seiminHj = 2;
  1198. }else if($rootScope.isHk){
  1199. $rootScope.seiminHj = 3;
  1200. }else{
  1201. $rootScope.seiminHj = 1;
  1202. }
  1203. $rootScope.getExtnDirect = function () {
  1204. $rootScope['getExtnDirect' + $rootScope.seiminHj]();
  1205. }
  1206. // --------------------------1------------------------------
  1207. $rootScope.getExtnDirect1 = function () {
  1208. var jry_data_dictionary = {
  1209. key: "hjzx_cornet",
  1210. type: "list"
  1211. }
  1212. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1213. var websocket_url = "ws://192.168.3.122:29003/ola_socket";
  1214. var ola_queue = "10009"; //通话配置-队列配置-队列ID
  1215. // var ola_extn = "1001"; //个人信息-座席分机号
  1216. $rootScope.jry_extnNumberSelect = [];
  1217. $rootScope.jry_extnNumberObj = {};
  1218. $rootScope.jry_extnNumberSelect = res;
  1219. $rootScope.jry_extnNumberObj.jry_extnNumber = $rootScope.jry_extnNumberSelect[0];
  1220. function log(msg) {
  1221. //IE has no console
  1222. if ('console' in window) console.log(msg);
  1223. }
  1224. function websocket_connect() {
  1225. ola.connect(websocket_url);
  1226. ola.onConnect = onConnect;
  1227. ola.onClose = onClose;
  1228. ola.onMessage = onMessage;
  1229. }
  1230. $(document).ready(function () {
  1231. // if(ola_extn!=""){
  1232. if ($rootScope.jry_extnNumberObj.jry_extnNumber) {
  1233. websocket_connect();
  1234. }
  1235. });
  1236. /* callbacks */
  1237. function onMessage(evt) {
  1238. var phoneData = JSON.parse(evt.data);
  1239. if (phoneData.event_type == "agent_state") {
  1240. console.log(phoneData);
  1241. if (phoneData.state == "busy") {
  1242. $('#agent_state').append(" (" + phoneData.private_data + ")");
  1243. // 来电
  1244. if (phoneData.private_data == "ring") {
  1245. console.log(phoneData);
  1246. $rootScope.jry_state = "laidian";
  1247. var Notification = window.Notification;
  1248. Notification.requestPermission();
  1249. var n = new Notification("你有来电", {
  1250. body: "来电号码:" + phoneData.ani,
  1251. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1252. });
  1253. // 摘机
  1254. } else if (phoneData.private_data == "answered") {
  1255. $rootScope.jry_state = "tonghuazhong";
  1256. var jry_findPhone = "";
  1257. if (phoneData.ani) {
  1258. jry_findPhone = phoneData.ani
  1259. } else if (phoneData.dnis && phoneData.other_answered) {
  1260. jry_findPhone = phoneData.dnis
  1261. }
  1262. var filterData = {
  1263. "idx": 0,
  1264. "sum": 100,
  1265. "requester": {
  1266. "mphone": jry_findPhone,
  1267. "telephone": jry_findPhone,
  1268. "selectType": 1
  1269. }
  1270. }
  1271. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  1272. var myData = Restangular.stripRestangular(data);
  1273. // $rootScope.phone="";
  1274. // 新增报修人
  1275. if (myData.list.length == 0) {
  1276. var modalInstance = $modal.open({
  1277. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  1278. controller: function ($scope, $modalInstance, api_user_data, SweetAlert, api_wechatfile) {
  1279. $scope.title = "新增报修人";
  1280. $scope.requester = {};
  1281. $scope.onChangeadd = function (searchData) {
  1282. $scope.searchKey = searchData.account;
  1283. // $scope.searchDataadd = searchData;
  1284. var requesdata = angular.copy(searchData)
  1285. // if (requesdata.mphone) {
  1286. // delete requesdata.mphone;
  1287. // }
  1288. if (requesdata.telephone) {
  1289. delete requesdata.telephone;
  1290. }
  1291. angular.extend($scope.requester, requesdata);
  1292. }
  1293. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  1294. $scope.requester.account = searchKey;
  1295. $scope.searchData = searchKey;
  1296. serchdataadd(searchKey);
  1297. }
  1298. $scope.getMydata = function (x) {
  1299. var reqestdatap = JSON.parse(x[0])
  1300. // if ($scope.requester.mphone) {
  1301. // delete reqestdatap.mphone;
  1302. // }
  1303. if ($scope.requester.telephone) {
  1304. delete reqestdatap.telephone;
  1305. }
  1306. $scope.searchField = JSON.parse(x[0]).account;
  1307. angular.extend($scope.requester, reqestdatap);
  1308. }
  1309. $scope.getMydataone = function (x) {
  1310. $scope.searchField = x;
  1311. $scope.requester.account = x;
  1312. }
  1313. serchdataadd();
  1314. function serchdataadd(searchKey) {
  1315. if (searchKey) {
  1316. var filterData = {
  1317. 'requester': {
  1318. 'searchKey': searchKey,
  1319. },
  1320. idx: 0,
  1321. sum: 10
  1322. };
  1323. } else {
  1324. var filterData = {
  1325. idx: 0,
  1326. sum: 10
  1327. };
  1328. }
  1329. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  1330. var myData = response;
  1331. $scope.myData = myData.list;
  1332. });
  1333. }
  1334. api_user_data.fetchDataList('area', {
  1335. idx: 0,
  1336. sum: 100
  1337. }).then(function (response) {
  1338. if (response.status == 200) {
  1339. $scope.areas = response.list;
  1340. }
  1341. })
  1342. api_wechatfile.getDictionary({
  1343. "key": "requester_type",
  1344. "type": "list"
  1345. }).then(function (response) {
  1346. // if (response.status == 200) {
  1347. $scope.networktypes = response;
  1348. // }
  1349. })
  1350. $scope.requesterAreaid = "";
  1351. $scope.onChange = function (item) {
  1352. $scope.requesterAreaid = item.id;
  1353. $scope.requester.place = {};
  1354. api_user_data.fetchDataList('place', {
  1355. place: {
  1356. areaId: item.id
  1357. },
  1358. idx: 0,
  1359. sum: 1000
  1360. }).then(function (response) {
  1361. if (response.status == 200) {
  1362. $scope.places = response.list;
  1363. }
  1364. })
  1365. }
  1366. //地点搜索
  1367. $scope.refresh = function (searchVal) {
  1368. var faildata = {};
  1369. if ($scope.requesterAreaid) {
  1370. faildata = {
  1371. 'idx': 0,
  1372. 'sum': 1000,
  1373. 'place': {
  1374. 'areaId': $scope.requesterAreaid,
  1375. 'place': searchVal,
  1376. 'selectType': 'pinyin_qs'
  1377. }
  1378. }
  1379. } else {
  1380. faildata = {
  1381. 'idx': 0,
  1382. 'sum': 1000,
  1383. 'place': {
  1384. 'place': searchVal,
  1385. 'selectType': 'pinyin_qs'
  1386. }
  1387. }
  1388. }
  1389. api_user_data.fetchDataList('place', faildata).then(function (response) {
  1390. $scope.places = response.list;
  1391. delete $scope.requester.place;
  1392. })
  1393. }
  1394. $scope.requester = {
  1395. 'telephone': jry_findPhone
  1396. };
  1397. $scope.ok = function () {
  1398. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  1399. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  1400. var flag1 = reg1.test($scope.requester.mphone);
  1401. var flag2 = reg2.test($scope.requester.mphone);
  1402. console.log($scope.requester)
  1403. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1404. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1405. } else if (angular.isUndefined($scope.requester.requesterType)) {
  1406. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  1407. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1408. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1409. }
  1410. else {
  1411. $modalInstance.close($scope.requester);
  1412. }
  1413. };
  1414. $scope.cancel = function () {
  1415. $modalInstance.dismiss('cancel');
  1416. };
  1417. },
  1418. });
  1419. modalInstance.result.then(function (selectedItem) {
  1420. if (selectedItem) {
  1421. if (selectedItem.telephone && !selectedItem.mphone) {
  1422. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1423. delete selectedItem.mphone;
  1424. }
  1425. var data = {
  1426. 'requester': selectedItem
  1427. };
  1428. api_user_data.addData('requester', data).then(function (response) {
  1429. if (response.status == 200) {
  1430. var data = {
  1431. 'model': {
  1432. 'requestershow': response.data,
  1433. 'incident': {
  1434. 'requester': response.data,
  1435. 'area': response.data.place?response.data.place.area:undefined,
  1436. 'place': response.data.place,
  1437. 'houseNumber': response.data.houseNumber,
  1438. 'callID': cdrid,
  1439. 'contacts':response.data.name,
  1440. 'contactsInformation': response.data.telephone,
  1441. 'source': {
  1442. 'id': 1547
  1443. }
  1444. }
  1445. }
  1446. }
  1447. $state.go('app.incident.title', {
  1448. 'model': JSON.stringify(data)
  1449. });
  1450. }
  1451. })
  1452. }
  1453. });
  1454. } else if (myData.list.length == 1) {
  1455. var data = {
  1456. 'model': {
  1457. 'requestershow': myData.list[0],
  1458. 'incident': {
  1459. 'requester': myData.list[0],
  1460. 'area': myData.list[0].place?myData.list[0].place.area:undefined,
  1461. 'place': myData.list[0].place,
  1462. 'houseNumber': myData.list[0].houseNumber,
  1463. 'callID': cdrid,
  1464. 'contacts':myData.list[0].name,
  1465. 'contactsInformation': myData.list[0].telephone,
  1466. 'source': {
  1467. 'id': 1547
  1468. }
  1469. }
  1470. }
  1471. }
  1472. $state.go('app.incident.title', {
  1473. 'model': JSON.stringify(data)
  1474. });
  1475. } else {
  1476. var modalInstance = $modal.open({
  1477. templateUrl: 'assets/views/createincident.html',
  1478. controller: function ($scope, $modalInstance, api_user_data) {
  1479. $scope.title = "请确定报修人";
  1480. $scope.requester = myData.list;
  1481. $scope.choice = function (requester) {
  1482. $modalInstance.dismiss('cancel');
  1483. var data = {
  1484. 'model': {
  1485. 'requestershow': requester,
  1486. 'incident': {
  1487. 'requester': requester,
  1488. 'area': requester.place?requester.place.area:undefined,
  1489. 'place': requester.place,
  1490. 'houseNumber': requester.houseNumber,
  1491. 'callID': cdrid,
  1492. 'contacts':requester.name,
  1493. 'contactsInformation': requester.telephone,
  1494. 'source': {
  1495. 'id': 1547
  1496. }
  1497. }
  1498. }
  1499. }
  1500. $state.go('app.incident.title', {
  1501. 'model': JSON.stringify(data)
  1502. });
  1503. };
  1504. $scope.cancel = function () {
  1505. $modalInstance.dismiss('cancel');
  1506. };
  1507. },
  1508. size: "lg"
  1509. });
  1510. }
  1511. });
  1512. }
  1513. // 挂机
  1514. } else if (phoneData.state == "login") {
  1515. go_ready()
  1516. } else if (phoneData.state == "logout") {
  1517. $rootScope.jry_state = "weiqianru";
  1518. } else if (phoneData.state == "ready") {
  1519. // 来电挂机
  1520. if (phoneData.old_state == "busy" && phoneData.private_data == "answered") {
  1521. go_break()
  1522. } else {
  1523. $rootScope.jry_state = "shixian";
  1524. }
  1525. }
  1526. // else if (data.old_state == "busy") {
  1527. // }
  1528. } else if (phoneData.event_type == "agent_caller_state") {
  1529. // special feature, never mind
  1530. if (phoneData.action == "in") {
  1531. } else {
  1532. }
  1533. } else if (phoneData.event_type == "command/reply") {
  1534. if (phoneData.phoneData && phoneData.phoneData.state) {
  1535. }
  1536. }
  1537. }
  1538. function onConnect() {
  1539. console.log("websocket connected!");
  1540. // ola._extn = ola_extn;
  1541. // ola.subscribe('ola.queue.' + ola_queue + '.' + ola_extn);
  1542. // ola.subscribe('ola.caller.' + ola_extn);
  1543. // ola.get_agent_state(ola_extn);
  1544. ola._extn = $rootScope.jry_extnNumberObj.jry_extnNumber.name;
  1545. ola.subscribe('ola.queue.' + ola_queue + '.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1546. ola.subscribe('ola.caller.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1547. ola.get_agent_state($rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1548. };
  1549. function onClose() {
  1550. }
  1551. function login() {
  1552. // ola.login(ola_queue, ola_extn, {type: "onhook"});
  1553. console.log($rootScope.jry_extnNumberObj.jry_extnNumber);
  1554. ola.login(ola_queue, $rootScope.jry_extnNumberObj.jry_extnNumber.name, { type: "onhook" });
  1555. }
  1556. function logout() {
  1557. ola.logout();
  1558. }
  1559. function go_ready() {
  1560. ola.go_ready();
  1561. }
  1562. function go_break() {
  1563. ola.go_break($('#break_reason').val());
  1564. $rootScope.jry_state = "shimang";
  1565. }
  1566. function answer() {
  1567. ola.answer();
  1568. }
  1569. function dial(dst) {
  1570. ola.dial(dst);
  1571. }
  1572. $rootScope.dial = function (dst) {
  1573. ola.dial(dst);
  1574. }
  1575. function conference(dst) {
  1576. ola.conference(dst);
  1577. }
  1578. function conference_uuid(channel_uuid) {
  1579. ola.conference_uuid(channel_uuid);
  1580. }
  1581. function hangup() {
  1582. ola.hangup();
  1583. }
  1584. function take_call(uuid) {
  1585. // ola.take_call(ola_extn, uuid);
  1586. ola.take_call($rootScope.jry_extnNumberObj.jry_extnNumber.name, uuid);
  1587. }
  1588. // 签入
  1589. $rootScope.jry_qianru = function () {
  1590. login();
  1591. }
  1592. // 示闲
  1593. $rootScope.jry_shixian = function () {
  1594. go_ready()
  1595. }
  1596. // 示忙
  1597. $rootScope.jry_shimang = function () {
  1598. go_break()
  1599. }
  1600. // 签出
  1601. $rootScope.jry_qianchu = function () {
  1602. logout()
  1603. }
  1604. $rootScope.jry_bohao = function (res) {
  1605. if ($rootScope.jry_state == "weiqianru") {
  1606. // SweetAlert.swal({
  1607. // title: "拨打失败",
  1608. // text: "请先签入!",
  1609. // type: "error",
  1610. // confirmButtonColor: "#DD6B55"
  1611. // });
  1612. } else if ($rootScope.jry_state == "shimang") {
  1613. // SweetAlert.swal({
  1614. // title: "拨打失败",
  1615. // text: "请先示闲!",
  1616. // type: "error",
  1617. // confirmButtonColor: "#DD6B55"
  1618. // });
  1619. } else {
  1620. dial(res);
  1621. }
  1622. }
  1623. })
  1624. }
  1625. // ------------------------------2--------------------------
  1626. $rootScope.getExtnDirect2 = function () {
  1627. var jry_data_dictionary = {
  1628. key: "hjzx_cornet",
  1629. type: "list"
  1630. }
  1631. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1632. sessionStorage.setItem('phones',JSON.stringify(res.map(v=>v.name)));
  1633. var websocket_url = $rootScope.seiminCallIp;
  1634. $rootScope.jry_extnNumberSelect = [];
  1635. $rootScope.jry_extnNumberObj = {};
  1636. $rootScope.jry_extnNumberSelect = angular.copy(res);
  1637. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1638. var fenjiNumber = localStorage.getItem('fenjiNumber');
  1639. if(fenjiNumber){
  1640. $rootScope.jry_extnNumberSelect.forEach(ress=>{
  1641. if(ress.name == fenjiNumber){
  1642. $rootScope.jry_extnNumberObj.jry_extnNumber = ress;
  1643. }
  1644. })
  1645. }
  1646. // $rootScope.jry_extnNumberObj.jry_extnNumber = angular.copy(res[0]);//绑定分机对象
  1647. // $rootScope.jry_extnNumberObj.tel1 = angular.copy(res[0]);//目的号码对象
  1648. // $rootScope.jry_extnNumberObj.tel2 = angular.copy(res[0]);//转接坐席对象
  1649. $rootScope.preState = '';//最近一次示忙还是示闲的状态
  1650. //连接
  1651. tlwsa.tlaOpen(websocket_url);
  1652. // 强制示忙
  1653. $scope.qShimang = function(state){
  1654. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1655. //进入页面,强制示忙
  1656. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1657. setTimeout(()=>{
  1658. tlwsa.tlaAcw();
  1659. },0)
  1660. }else{
  1661. $scope.getState(state);
  1662. }
  1663. }
  1664. // 获取状态
  1665. $scope.getState = function (state) {
  1666. // if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1667. // if(state != 2&&state != 0){
  1668. // //进入页面,强制示忙
  1669. // // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1670. // setTimeout(()=>{
  1671. // tlwsa.tlaAcw();
  1672. // },3000)
  1673. // }
  1674. // }
  1675. // var agcount = tlwsa.tlaGetagentcount();
  1676. // var flag = true;
  1677. // for (var i = 0; i < agcount; i++) {
  1678. // if (tlwsa.tlaGetagentwid(i) == $rootScope.phoneNumber) {
  1679. // flag = false;
  1680. // var state = Number(tlwsa.tlaGetagentstate(i));
  1681. // console.log(state);
  1682. switch (state) {
  1683. case 0:
  1684. $rootScope.jry_state = 'weiqianru';
  1685. break;
  1686. case 1:
  1687. $rootScope.jry_state = 'shixian';
  1688. break;
  1689. case 2:
  1690. $rootScope.jry_state = 'shimang';
  1691. break;
  1692. case 3:
  1693. $rootScope.jry_state = 'laidian';
  1694. break;
  1695. case 5:
  1696. $rootScope.jry_state = 'tonghuazhong';
  1697. break;
  1698. case 6:
  1699. $rootScope.jry_state = 'zhengzaiwaihu';
  1700. break;
  1701. case 7:
  1702. $rootScope.jry_state = 'zhengzaizhuanyi';
  1703. break;
  1704. }
  1705. // }
  1706. // console.log('agnet No. ' + i + ' workid is ' + tlwsa.tlaGetagentwid(i) + ' state is ' + tlwsa.tlaGetagentstate(i) + ' ' + getStateInfo(tlwsa.tlaGetagentstate(i)))
  1707. // }
  1708. // if (flag) {
  1709. // $rootScope.jry_state = 'weiqianru';
  1710. // }
  1711. }
  1712. // 状态回调函数
  1713. // TLWSA.onStatechange = onstatechange;
  1714. // function onstatechange() {
  1715. // console.log('事件:状态变化----------------------------------------------------');
  1716. // $scope.getState();
  1717. // }
  1718. //连接呼叫中心回调函数
  1719. TLWSA.onOpenreturn = onopenreturn;
  1720. function onopenreturn(err) {
  1721. err = Number(err);
  1722. if (!err) {
  1723. console.log('呼叫中心连接成功-----seimin');
  1724. $scope.getState(0);
  1725. $.toaster({
  1726. priority: 'info',
  1727. title: '操作',
  1728. message: '呼叫中心连接成功'
  1729. });
  1730. //如果设置过话机
  1731. if (localStorage.getItem('phoneNumber')) {
  1732. //强制签出,然后签入
  1733. tlwsa.tlaKillworkid(localStorage.getItem('phoneNumber'));
  1734. }
  1735. } else {
  1736. console.log('呼叫中心连接失败-----seimin');
  1737. $scope.getState(0);
  1738. $.toaster({
  1739. priority: 'info',
  1740. title: '操作',
  1741. message: '呼叫中心连接失败'
  1742. });
  1743. }
  1744. }
  1745. //绑定分机回调函数
  1746. TLWSA.onSetphonenumberreturn = onsetphonenumberreturn;
  1747. function onsetphonenumberreturn(err) {
  1748. err = Number(err);
  1749. if (!err) {
  1750. console.log('绑定分机成功-----seimin');
  1751. $.toaster({
  1752. priority: 'info',
  1753. title: '操作',
  1754. message: '绑定分机成功'
  1755. });
  1756. localStorage.setItem('phoneNumber', $rootScope.phoneNumber);
  1757. localStorage.setItem('fenjiNumber', $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1758. $scope.qShimang(1);
  1759. } else {
  1760. console.log('绑定分机失败-----seimin');
  1761. $scope.getState(0);
  1762. $.toaster({
  1763. priority: 'info',
  1764. title: '操作',
  1765. message: '绑定分机失败'
  1766. });
  1767. }
  1768. }
  1769. //强制示忙回调函数
  1770. // TLWSA.onAcw = onacw;
  1771. // function onacw(err) {
  1772. // err = Number(err);
  1773. // if (!err) {
  1774. // console.log('强制示忙成功-----seimin');
  1775. // $scope.getState(2);
  1776. // $.toaster({
  1777. // priority: 'info',
  1778. // title: '操作',
  1779. // message: '示忙成功'
  1780. // });
  1781. // } else {
  1782. // console.log('强制示忙失败-----seimin');
  1783. // $.toaster({
  1784. // priority: 'info',
  1785. // title: '操作',
  1786. // message: '示忙失败'
  1787. // });
  1788. // }
  1789. // }
  1790. // //强制示闲回调函数
  1791. // TLWSA.onWca = onwca;
  1792. // function onwca(err) {
  1793. // console.log(err)
  1794. // err = Number(err);
  1795. // if (!err) {
  1796. // console.log('强制示闲成功-----seimin');
  1797. // $scope.getState(1);
  1798. // $.toaster({
  1799. // priority: 'info',
  1800. // title: '操作',
  1801. // message: '示闲成功'
  1802. // });
  1803. // } else {
  1804. // console.log('强制示闲失败-----seimin');
  1805. // $.toaster({
  1806. // priority: 'info',
  1807. // title: '操作',
  1808. // message: '示闲失败'
  1809. // });
  1810. // }
  1811. // }
  1812. //与服务器网络连接中断回调函数
  1813. TLWSA.onClosed = onclosed;
  1814. function onclosed() {
  1815. $scope.getState(0);
  1816. console.log('与服务器网络连接中断-----seimin');
  1817. $.toaster({
  1818. priority: 'info',
  1819. title: '操作',
  1820. message: '与服务器网络连接中断,2分钟后重连'
  1821. });
  1822. console.log('2分钟后自动重连-----seimin')
  1823. $timeout(function () {
  1824. //连接
  1825. tlwsa.tlaOpen(websocket_url);
  1826. }, 120000)
  1827. }
  1828. //签入回调函数
  1829. TLWSA.onLoginreturn = onloginreturn;
  1830. function onloginreturn(err) {
  1831. err = Number(err);
  1832. if (!err) {
  1833. console.log('签入成功-----seimin');
  1834. $.toaster({
  1835. priority: 'info',
  1836. title: '操作',
  1837. message: '签入成功'
  1838. });
  1839. setTimeout(function () {
  1840. console.log($rootScope.jry_extnNumberObj.jry_extnNumber.name,1111)
  1841. var fenjiNumber = $rootScope.jry_extnNumberObj.jry_extnNumber.name || localStorage.getItem('fenjiNumber');
  1842. console.log('开始绑定分机【' + fenjiNumber + '】-----seimin');
  1843. tlwsa.tlaSetphonenumber(fenjiNumber);
  1844. }, 0)
  1845. } else if (err == 9011) {
  1846. console.log('签入失败,该分机已登录-----seimin');
  1847. $.toaster({
  1848. priority: 'info',
  1849. title: '操作',
  1850. message: '签入失败,该分机已登录'
  1851. });
  1852. } else {
  1853. console.log('签入失败-----seimin');
  1854. $.toaster({
  1855. priority: 'info',
  1856. title: '操作',
  1857. message: '签入失败'
  1858. });
  1859. }
  1860. // tlwsa.tlaSubscribestateinfo(2);
  1861. }
  1862. // 强制签出回调函数
  1863. TLWSA.onKillreturn = onkillreturn;
  1864. function onkillreturn(err) {
  1865. err = Number(err);
  1866. if (!err) {
  1867. console.log('强制签出成功-----seimin');
  1868. $scope.getState(0);
  1869. // $.toaster({
  1870. // priority: 'info',
  1871. // title: '操作',
  1872. // message: '强制签出成功'
  1873. // });
  1874. } else {
  1875. console.log('强制签出失败,该分机不是签入状态-----seimin');
  1876. // $.toaster({
  1877. // priority: 'info',
  1878. // title: '操作',
  1879. // message: '强制签出失败'
  1880. // });
  1881. }
  1882. //如果设置过话机
  1883. if (localStorage.getItem('phoneNumber')) {
  1884. // 签入并绑定分机
  1885. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  1886. tlwsa.tlaLogin($rootScope.phoneNumber, 1, -1);
  1887. }
  1888. }
  1889. // 签出回调函数
  1890. TLWSA.onLogoffreturn = onlogoffreturn;
  1891. function onlogoffreturn(err) {
  1892. err = Number(err);
  1893. if (!err) {
  1894. console.log('签出成功-----seimin');
  1895. $scope.getState(0);
  1896. $.toaster({
  1897. priority: 'info',
  1898. title: '操作',
  1899. message: '签出成功'
  1900. });
  1901. localStorage.removeItem('phoneNumber');
  1902. localStorage.removeItem('fenjiNumber');
  1903. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1904. } else {
  1905. console.log('签出失败-----seimin');
  1906. $.toaster({
  1907. priority: 'info',
  1908. title: '操作',
  1909. message: '签出失败'
  1910. });
  1911. }
  1912. }
  1913. //示忙回调函数
  1914. TLWSA.onAcwreturn = onacwreturn;
  1915. function onacwreturn(err) {
  1916. err = Number(err);
  1917. if (!err) {
  1918. console.log('示忙成功-----seimin');
  1919. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1920. $scope.isShixian = false;
  1921. }else{
  1922. $scope.isShixian = true;
  1923. }
  1924. $scope.getState(2);
  1925. $rootScope.preState = 2;
  1926. $.toaster({
  1927. priority: 'info',
  1928. title: '操作',
  1929. message: '示忙成功'
  1930. });
  1931. } else {
  1932. console.log('示忙失败-----seimin');
  1933. // $.toaster({
  1934. // priority: 'info',
  1935. // title: '操作',
  1936. // message: '示忙失败'
  1937. // });
  1938. }
  1939. }
  1940. //示闲回调函数
  1941. TLWSA.onWcareturn = onwcareturn;
  1942. function onwcareturn(err) {
  1943. err = Number(err);
  1944. if (!err) {
  1945. console.log('示闲成功-----seimin');
  1946. $scope.getState(1);
  1947. $rootScope.preState = 1;
  1948. $.toaster({
  1949. priority: 'info',
  1950. title: '操作',
  1951. message: '示闲成功'
  1952. });
  1953. } else {
  1954. console.log('示闲失败-----seimin');
  1955. $.toaster({
  1956. priority: 'info',
  1957. title: '操作',
  1958. message: '示闲失败'
  1959. });
  1960. }
  1961. }
  1962. //呼叫坐席回调函数
  1963. TLWSA.onCallreturn = oncallreturn;
  1964. function oncallreturn(err) {
  1965. err = Number(err);
  1966. if (!err) {
  1967. console.log('呼叫成功,请摘机-----seimin');
  1968. $scope.getState(6);
  1969. $.toaster({
  1970. priority: 'info',
  1971. title: '操作',
  1972. message: '呼叫成功,请摘机'
  1973. });
  1974. } else {
  1975. console.log('呼叫失败-----seimin');
  1976. $.toaster({
  1977. priority: 'info',
  1978. title: '操作',
  1979. message: '呼叫失败'
  1980. });
  1981. }
  1982. }
  1983. //呼叫坐席被接听回调函数
  1984. TLWSA.onCallresult = oncallresult;
  1985. function oncallresult(jso) {
  1986. console.log(jso);
  1987. var err = Number(jso.err);
  1988. if (!err) {
  1989. console.log('呼叫被接听成功-----seimin');
  1990. $scope.getState(5);
  1991. $.toaster({
  1992. priority: 'info',
  1993. title: '操作',
  1994. message: '呼叫被接听成功'
  1995. });
  1996. } else {
  1997. console.log('呼叫被接听失败-----seimin');
  1998. $scope.qShimang(1);
  1999. $.toaster({
  2000. priority: 'info',
  2001. title: '操作',
  2002. message: '呼叫被接听失败'
  2003. });
  2004. }
  2005. }
  2006. //挂断回调函数
  2007. TLWSA.onCallend = oncallend;
  2008. function oncallend(jso) {
  2009. console.log(jso);//lmm
  2010. if (jso) {
  2011. console.log('挂断成功-----seimin');
  2012. console.log('最近一次话机状态',$rootScope.preState);
  2013. $scope.qShimang($rootScope.preState);
  2014. $.toaster({
  2015. priority: 'info',
  2016. title: '操作',
  2017. message: '挂断成功'
  2018. });
  2019. } else {
  2020. console.log('挂断失败-----seimin');
  2021. $.toaster({
  2022. priority: 'info',
  2023. title: '操作',
  2024. message: '挂断失败'
  2025. });
  2026. }
  2027. }
  2028. //呼入回调函数
  2029. TLWSA.onCallin = oncallin;
  2030. function oncallin(jso) {
  2031. console.log(jso);//lmm
  2032. $rootScope.callInPhoneNumber = jso.caller;//来电的电话
  2033. $rootScope.sockid = jso.crs;//来电的话机id
  2034. if (jso) {
  2035. console.log('呼入坐席成功,请摘机-----seimin');
  2036. $scope.getState(3);
  2037. $.toaster({
  2038. priority: 'info',
  2039. title: '操作',
  2040. message: '呼入坐席成功,请摘机'
  2041. });
  2042. console.log('来电了!电话号码是【' + $rootScope.callInPhoneNumber + '】');
  2043. } else {
  2044. console.log('呼入坐席失败-----seimin');
  2045. $.toaster({
  2046. priority: 'info',
  2047. title: '操作',
  2048. message: '呼入坐席失败'
  2049. });
  2050. }
  2051. }
  2052. //呼入摘机应答回调函数
  2053. TLWSA.onAnswer = onanswer;
  2054. function onanswer(err) {
  2055. err = Number(err);
  2056. if (!err) {
  2057. console.log('呼入摘机应答成功-----seimin');
  2058. $scope.getState(5);
  2059. $.toaster({
  2060. priority: 'info',
  2061. title: '操作',
  2062. message: '呼入摘机应答成功'
  2063. });
  2064. //根据电话号码反查报修人,如果是坐席号码,则不用
  2065. // console.log(sessionStorage.getItem('phones'));
  2066. // var phones = JSON.parse(sessionStorage.getItem('phones'));
  2067. // var isHuajihao = phones.length?phones.some(v=>v == teleno):false;
  2068. // if(isHuajihao){
  2069. // return;
  2070. // }
  2071. var postData = { "idx": 0, "sum": 10, "requester": { hjzxPhone: $rootScope.callInPhoneNumber } };
  2072. api_user_data.fetchDataList('requester', postData).then(function (result) {
  2073. if (result.status == 200) {
  2074. console.log(result.list);
  2075. var requesters = result.list;
  2076. if (requesters.length === 0) {
  2077. //未匹配到报修人,则弹窗添加报修人yeye
  2078. $state.go('app.incident.chart', {
  2079. model: JSON.stringify({
  2080. model: {
  2081. incident: {
  2082. requester: {
  2083. hjzxPhone: $rootScope.callInPhoneNumber
  2084. },
  2085. sockid: $rootScope.sockid
  2086. }
  2087. }
  2088. })
  2089. });
  2090. } else if (requesters.length === 1) {
  2091. //匹配到一个报修人
  2092. $state.go('app.incident.chart', {
  2093. model: JSON.stringify({
  2094. model: {
  2095. incident: {
  2096. requester: requesters[0],
  2097. contactsInformation: requesters[0].mphone,
  2098. sockid: $rootScope.sockid
  2099. },
  2100. }
  2101. })
  2102. });
  2103. } else {
  2104. //匹配到多个报修人
  2105. $modal.open({
  2106. templateUrl: 'assets/views/incident/tpl/tel.html',
  2107. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  2108. $scope.list = requesters;
  2109. $scope.selectedItem = 0;
  2110. $scope.cancel = function () {
  2111. $modalInstance.dismiss('cancel');
  2112. };
  2113. $scope.changeBxr = function (id) {
  2114. $scope.selectedItem = id;
  2115. }
  2116. $scope.save = function () {
  2117. var item = $scope.list.find(v => v.id == $scope.selectedItem);
  2118. if (item) {
  2119. $scope.cancel();
  2120. $state.go('app.incident.chart', {
  2121. model: JSON.stringify({
  2122. model: {
  2123. incident: {
  2124. requester: item,
  2125. contactsInformation: item.mphone,
  2126. sockid: $rootScope.sockid
  2127. },
  2128. }
  2129. })
  2130. });
  2131. } else {
  2132. SweetAlert.swal({
  2133. title: "请选择报修人!",
  2134. type: "error"
  2135. })
  2136. }
  2137. }
  2138. }
  2139. });
  2140. }
  2141. }
  2142. })
  2143. } else {
  2144. console.log('呼入摘机应答失败-----seimin');
  2145. $.toaster({
  2146. priority: 'info',
  2147. title: '操作',
  2148. message: '呼入摘机应答失败'
  2149. });
  2150. }
  2151. }
  2152. //呼入未摘机应答回调函数
  2153. TLWSA.onMisscall = onmisscall;
  2154. function onmisscall(err) {
  2155. err = Number(err);
  2156. if (!err) {
  2157. console.log('呼入未摘机应答成功-----seimin');
  2158. $scope.getState(1);
  2159. $.toaster({
  2160. priority: 'info',
  2161. title: '操作',
  2162. message: '呼入未摘机应答成功'
  2163. });
  2164. } else {
  2165. console.log('呼入未摘机应答失败-----seimin');
  2166. $.toaster({
  2167. priority: 'info',
  2168. title: '操作',
  2169. message: '呼入未摘机应答失败'
  2170. });
  2171. }
  2172. }
  2173. //转接开始回调函数
  2174. TLWSA.onTransferreturn = ontransferreturn;//调用转移方法之后,返回该事件 如果错误码为0,仅仅表示开始转移,不代表转移目标已经接听或已经拒绝
  2175. function ontransferreturn(err) {
  2176. err = Number(err);
  2177. if (!err) {
  2178. console.log('转接坐席开始成功-----seimin');
  2179. $scope.getState(7);
  2180. $.toaster({
  2181. priority: 'info',
  2182. title: '操作',
  2183. message: '转接坐席开始成功'
  2184. });
  2185. } else {
  2186. console.log('转接坐席开始失败-----seimin');
  2187. $.toaster({
  2188. priority: 'info',
  2189. title: '操作',
  2190. message: '转接坐席开始失败'
  2191. });
  2192. }
  2193. }
  2194. //转接结果回调函数
  2195. TLWSA.onTransferresult = ontransferresult;
  2196. function ontransferresult(err) {
  2197. err = Number(err);
  2198. if (!err) {
  2199. console.log('转接坐席结果成功-----seimin');
  2200. $scope.getState(1);
  2201. $.toaster({
  2202. priority: 'info',
  2203. title: '操作',
  2204. message: '转接坐席结果成功'
  2205. });
  2206. } else {
  2207. console.log('转接坐席结果失败-----seimin');
  2208. $.toaster({
  2209. priority: 'info',
  2210. title: '操作',
  2211. message: '转接坐席结果失败'
  2212. });
  2213. }
  2214. }
  2215. // 签入
  2216. $rootScope.jry_qianru = function () {
  2217. console.log($rootScope.jry_extnNumberObj.jry_extnNumber)
  2218. if(Object.keys($rootScope.jry_extnNumberObj.jry_extnNumber).length === 0){
  2219. $.toaster({
  2220. priority: 'info',
  2221. title: '警告',
  2222. message: '绑定分机不能为空'
  2223. });
  2224. return;
  2225. }
  2226. // 签入并绑定分机
  2227. // $rootScope.jry_extnNumberObj.jry_extnNumber.name 分机号
  2228. // $rootScope.user.id 坐席号(用户id)
  2229. tlwsa.tlaLogin($rootScope.user.id, 1, -1);
  2230. $rootScope.phoneNumber = $rootScope.user.id;
  2231. }
  2232. // 示闲
  2233. $rootScope.jry_shixian = function () {
  2234. tlwsa.tlaWca();
  2235. }
  2236. // 示忙
  2237. $rootScope.jry_shimang = function () {
  2238. tlwsa.tlaAcw();
  2239. }
  2240. // 签出
  2241. $rootScope.jry_qianchu = function () {
  2242. tlwsa.tlaLogoff();
  2243. }
  2244. // 呼叫坐席
  2245. // $scope.tlaCallagc = function () {
  2246. // tlwsa.tlaCallagc($rootScope.jry_extnNumberObj.tel1)
  2247. // }
  2248. // 呼叫外线
  2249. $scope.tlaCallout = function () {
  2250. // 选择目的号码
  2251. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2252. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2253. if(!reg1.test($rootScope.jry_extnNumberObj.tel1)&&!reg2.test($rootScope.jry_extnNumberObj.tel1)){
  2254. $.toaster({
  2255. priority: 'info',
  2256. title: '警告',
  2257. message: '请输入正确的手机号或座机号'
  2258. });
  2259. return;
  2260. }
  2261. tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2262. }
  2263. // // 转移坐席
  2264. // $scope.tlaTransfertoagc = function () {
  2265. // tlwsa.tlaTransfertoagc($rootScope.jry_extnNumberObj.tel2)
  2266. // }
  2267. // 转移外线
  2268. $scope.tlaTransferout = function () {
  2269. // 选择转接号码
  2270. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2271. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2272. if(!reg1.test($rootScope.jry_extnNumberObj.tel2)&&!reg2.test($rootScope.jry_extnNumberObj.tel2)){
  2273. $.toaster({
  2274. priority: 'info',
  2275. title: '警告',
  2276. message: '请输入正确的手机号或座机号'
  2277. });
  2278. return;
  2279. }
  2280. tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2281. }
  2282. })
  2283. }
  2284. $rootScope.getExtnDirect3 = function(){
  2285. console.log($rootScope.user)
  2286. var user = $rootScope.user;
  2287. initImUser(user.email, user.msgUuid);
  2288. // $rootScope.start(JSON.parse(localStorage.userdata).commonExtension.name);
  2289. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function(data) {
  2290. $scope.runNumber = data;
  2291. $scope.phone = $scope.runNumber[0].name;
  2292. $rootScope.phoneChange($scope.phone);
  2293. })
  2294. if ($rootScope.userMenus.length == 0) {
  2295. getMenus();
  2296. }
  2297. if(localStorage.getItem('hk_phone')){
  2298. $rootScope.start(localStorage.getItem('hk_phone'));
  2299. }
  2300. }
  2301. $rootScope.jry_state = 'weiqianru';
  2302. window.addEventListener('load', function () {
  2303. if ($rootScope.isFuwutai) {
  2304. $rootScope.getExtnDirect();//seiminHj----1
  2305. }
  2306. })
  2307. //话机呼叫中心--结束
  2308. // 未接来电
  2309. $scope.jry_getUnanswered = function () {
  2310. var jry_data = {
  2311. idx: 0,
  2312. sum: 999,
  2313. "callRecord": {
  2314. "todayTime": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 00:00:00",
  2315. "todayTimeEnd": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 23:59:59",
  2316. }
  2317. }
  2318. api_bpm_data.fetchDataList("callRecord", jry_data).then(function (data) {
  2319. // fo0h
  2320. for (var i = 0; i < data.list.length; i++) {
  2321. data.list[i].createdTime = new Date(data.list[i].createdTime).getFullYear() + "-" + (new Date(data.list[i].createdTime).getMonth() + 1) + "-" + new Date(data.list[i].createdTime).getDate() + " " + new Date(data.list[i].createdTime).getHours() + ":" + new Date(data.list[i].createdTime).getMinutes() + ":" + new Date(data.list[i].createdTime).getSeconds()
  2322. }
  2323. $rootScope.jry_unansweredData = data.list;
  2324. });
  2325. }
  2326. // $scope.jry_getUnanswered();
  2327. // 来电号码回拨
  2328. $scope.jry_callBack = function (data) {
  2329. var callBackData = {
  2330. "callRecord": {
  2331. "id": data.id,
  2332. "isAnswered": "1"
  2333. }
  2334. };
  2335. api_bpm_data.updData("callRecord", callBackData).then(function (res) {
  2336. if (res) {
  2337. $scope.jry_getUnanswered();
  2338. dial(data.callerIdNumber)
  2339. }
  2340. });
  2341. if (data.department.id && data.requester) {
  2342. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'requester': data.requester, 'contacts': data.requester.name, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2343. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2344. } else if (data.department.id) {
  2345. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2346. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2347. } else {
  2348. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2349. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2350. };
  2351. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  2352. }
  2353. //来电号码生成事件
  2354. $scope.jry_callToIncident = function (data) {
  2355. if (data.department.id && data.requester) {
  2356. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'requester': data.requester, 'contacts': data.requester.name, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2357. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2358. } else if (data.department.id) {
  2359. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2360. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2361. } else {
  2362. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2363. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2364. }
  2365. }
  2366. $scope.onChangeadd = function (searchData) {
  2367. $scope.searchKey = searchData.account;
  2368. // $scope.searchDataadd = searchData;
  2369. var requesdata = angular.copy(searchData)
  2370. $scope.requester = requesdata;
  2371. }
  2372. $scope.refreshUseradd = function (searchKey) { //主题搜索
  2373. $scope.searchData = searchKey;
  2374. reashdata($scope.searchData);
  2375. }
  2376. $scope.getMydata = function (x) {
  2377. $scope.telephone = JSON.parse(x).phone;
  2378. $scope.searchField = $scope.telephone;
  2379. return $scope.searchField;
  2380. }
  2381. $scope.getMydataone = function (x) {
  2382. $scope.telephone = x;
  2383. $scope.searchField = $scope.telephone;
  2384. }
  2385. $scope.fildata = {
  2386. "idx": 0,
  2387. "sum": 10,
  2388. "flag": -1
  2389. }
  2390. function reashdata(item) {
  2391. if (item && item != "") {
  2392. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  2393. } else {
  2394. delete $scope.fildata.user;
  2395. }
  2396. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  2397. if (data.status == 200) {
  2398. $scope.myData = data.list;
  2399. }
  2400. })
  2401. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  2402. // if (response) {
  2403. // if (response.status = 200) {
  2404. // var myData = response;
  2405. // $scope.myData = myData.list;
  2406. // }
  2407. // }
  2408. // })
  2409. }
  2410. if (window.location && window.location.hash == "#/echart") {
  2411. } else {
  2412. reashdata();
  2413. }
  2414. $rootScope.end = function () {
  2415. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  2416. if (data.errno == 0) {
  2417. localStorage.removeItem('hk_phone');
  2418. api_text.exit($rootScope.takes).then(function (data) {
  2419. if (data.errno == 0) {
  2420. $rootScope.statuscall = 0;
  2421. $scope.login = false;
  2422. // SweetAlert.swal({
  2423. // title: "登出成功",
  2424. // text: "呼叫中心登出成功!",
  2425. // type: "success"
  2426. // });
  2427. // }else{SweetAlert.swal({
  2428. // title: "登出失败",
  2429. // text: "呼叫中心登出失败!",
  2430. // type: "error"
  2431. // });
  2432. }
  2433. })
  2434. }
  2435. })
  2436. }
  2437. $rootScope.dialout = function (gid, teleno) {
  2438. var telephone = "";
  2439. if (teleno && teleno.length > 4) {
  2440. telephone = '9' + teleno;
  2441. } else {
  2442. // telephone = '*01' + teleno + '*';
  2443. telephone = teleno;
  2444. }
  2445. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  2446. if (data.errno == 0) {
  2447. // $rootScope.statuscall = 3;
  2448. $rootScope.callout = true;
  2449. // $rootScope.phone=teleno;
  2450. }
  2451. })
  2452. }
  2453. // $scope.busy=false;
  2454. $rootScope.setbusy = function () {
  2455. api_text.setbusy($rootScope.takes).then(function (data) {
  2456. if (data.errno == 0) {
  2457. $rootScope.statecall = 2;
  2458. $scope.busy = true;
  2459. }
  2460. })
  2461. }
  2462. $rootScope.setidle = function () {
  2463. api_text.setidle($rootScope.takes).then(function (data) {
  2464. if (data.errno == 0) {
  2465. $rootScope.statecall = 1;
  2466. $scope.busy = false;
  2467. }
  2468. })
  2469. }
  2470. $rootScope.inittrans = function (telephone) {
  2471. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  2472. if (data.errno == 0) {
  2473. // $scope.status=9
  2474. }
  2475. })
  2476. }
  2477. $rootScope.comptrans = function () {
  2478. api_text.comptrans($rootScope.takes).then(function (data) {
  2479. if (data.errno == 0) {
  2480. $rootScope.statuscall = 1;
  2481. }
  2482. })
  2483. }
  2484. $rootScope.takeup = function () {
  2485. api_text.offhook($rootScope.takes).then(function (data) {
  2486. if (data.errno == 0) {
  2487. $rootScope.statuscall = 3;
  2488. }
  2489. })
  2490. }
  2491. $rootScope.takedown = function () {
  2492. api_text.onhook($rootScope.takes).then(function (data) {
  2493. if (data.errno == 0) {
  2494. $rootScope.statuscall = 1;
  2495. }
  2496. })
  2497. }
  2498. $rootScope.saveData = function (selectdata) {
  2499. var modalInstance = $modal.open({
  2500. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  2501. controller: function ($scope, $modalInstance, api_bpm_data) {
  2502. $scope.worktimedata = {};
  2503. $scope.worktimedata = selectdata;
  2504. $scope.cancel = function () {
  2505. $modalInstance.dismiss('cancel');
  2506. };
  2507. $scope.savercode = function (worktimedata) {
  2508. var fildata = {
  2509. "scheduleclass": {
  2510. "id": selectdata.id,
  2511. "code": worktimedata.code,
  2512. "name": worktimedata.title,
  2513. "person": worktimedata.person,
  2514. "description": worktimedata.description,
  2515. "startTime": worktimedata.startTime,
  2516. "endTime": worktimedata.endTime,
  2517. "shiftTime": selectdata.shiftTime,
  2518. "succeedTime": selectdata.succeedTime,
  2519. "isTemplate": worktimedata.isTemplate
  2520. }
  2521. }
  2522. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  2523. if (response) {
  2524. if (response.status == 200) {
  2525. SweetAlert.swal({
  2526. title: "修改成功!",
  2527. type: "success"
  2528. }, function () {
  2529. // $scope.refreshData('expand-right', defaultFilterData);
  2530. })
  2531. } else {
  2532. SweetAlert.swal({
  2533. title: "修改失败!",
  2534. type: "error"
  2535. })
  2536. }
  2537. }
  2538. })
  2539. $modalInstance.close();
  2540. }
  2541. }
  2542. });
  2543. }
  2544. $rootScope.changepassword = function (data1, size) {
  2545. var modalInstance = $modal.open({
  2546. templateUrl: 'assets/views/changepassword.html',
  2547. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  2548. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  2549. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  2550. }
  2551. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  2552. $modalInstance.dismiss('cancel');
  2553. // console.log('pwd=' + pwd + '+' + pwd_2);
  2554. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  2555. if (pwd == pwd_2) {
  2556. var data2 = {};
  2557. data2["originalPwd"] = originalPwd;
  2558. data2["userid"] = $rootScope.user.id;
  2559. data2["pwd"] = pwd;
  2560. api_login.uppwd(data2).then(function (response) {
  2561. var myData = Restangular.stripRestangular(response);
  2562. if (myData.status == 200) {
  2563. SweetAlert.swal({
  2564. title: "保存成功!",
  2565. type: "success",
  2566. confirmButtonColor: "#007AFF"
  2567. });
  2568. } else {
  2569. SweetAlert.swal({
  2570. title: "保存失败!",
  2571. text: "输入旧密码错误,请重新输入!",
  2572. type: "error"
  2573. });
  2574. }
  2575. })
  2576. } else {
  2577. SweetAlert.swal({
  2578. title: "两次输入的新密码不相同!",
  2579. text: "输入错误,请重新输入!",
  2580. type: "error"
  2581. });
  2582. }
  2583. // }else{
  2584. // SweetAlert.swal({
  2585. // title: "密码不能为空!",
  2586. // text: "请输入密码!",
  2587. // type: "error"
  2588. // });
  2589. // }
  2590. }
  2591. },
  2592. size: size,
  2593. resolve: {
  2594. items: function () {
  2595. return {
  2596. fetchItems: function (filterData, APIService) { }
  2597. };
  2598. },
  2599. }
  2600. });
  2601. }
  2602. // $rootScope.getnochildpending = function() {
  2603. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2604. // angular.forEach($rootScope.userMenus, function(item) {
  2605. // item.tipnum = 1;
  2606. // })
  2607. // }
  2608. // }
  2609. // $rootScope.getchildpending = function(cantdata) {
  2610. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2611. // angular.forEach($rootScope.userMenus, function(item) {
  2612. // item.tipnum = 1;
  2613. // angular.forEach(item, function(index) {
  2614. // index.tipnum = 18;
  2615. // })
  2616. // })
  2617. // }
  2618. // }
  2619. $rootScope.getpending = function () {
  2620. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2621. if ($rootScope.user.group) {
  2622. var groupArr = [];
  2623. for (var i = 0; i < $rootScope.user.group.length; i++) {
  2624. groupArr.push($rootScope.user.group[i].id)
  2625. }
  2626. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  2627. angular.forEach($rootScope.userMenus, function (item, i) {
  2628. item.tipshow = false;
  2629. if (response) {
  2630. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  2631. if (item.id == 58) {
  2632. item.tipshow = true;
  2633. }
  2634. }
  2635. if (response.inspectionCount > 0) {
  2636. if (item.id == 27) {
  2637. item.tipshow = true;
  2638. }
  2639. }
  2640. if (response.incidentCount > 0) {
  2641. if (item.id == 2) {
  2642. item.tipshow = true;
  2643. }
  2644. }
  2645. if (response.releaseCount > 0) {
  2646. if (item.id == 1215) {
  2647. item.tipshow = true;
  2648. }
  2649. }
  2650. if (response.solutionCount > 0) {
  2651. if (item.id == 21) {
  2652. item.tipshow = true;
  2653. }
  2654. }
  2655. if (response.changeCount > 0) {
  2656. if (item.id == 1212) {
  2657. item.tipshow = true;
  2658. }
  2659. }
  2660. if (response.problemCount > 0) {
  2661. if (item.id == 1209) {
  2662. item.tipshow = true;
  2663. }
  2664. }
  2665. if (response.applicationForm > 0) {
  2666. if (item.id == 1221) {
  2667. item.tipshow = true;
  2668. }
  2669. }
  2670. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2671. if (item.id == 21) {
  2672. item.tipshow = true;
  2673. }
  2674. }
  2675. if (item.children) {
  2676. angular.forEach(item.children, function (index) {
  2677. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  2678. if (index.id == 1208) {
  2679. if (response.hjzxCount < 100) {
  2680. index.tipnum = response.hjzxCount;
  2681. } else {
  2682. index.tipnum = "99+";
  2683. }
  2684. }
  2685. }
  2686. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  2687. if (index.id == 59) {
  2688. if (response.wechatWarningCount < 100) {
  2689. index.tipnum = response.wechatWarningCount;
  2690. } else {
  2691. index.tipnum = "99+";
  2692. }
  2693. }
  2694. }
  2695. if (response.problemCount !== null && response.problemCount !== undefined) {
  2696. if (index.id == 1210) {
  2697. if (response.problemCount < 100) {
  2698. index.tipnum = response.problemCount;
  2699. } else {
  2700. index.tipnum = "99+";
  2701. }
  2702. }
  2703. }
  2704. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  2705. if (index.id == 1216) {
  2706. if (response.releaseCount < 100) {
  2707. index.tipnum = response.releaseCount;
  2708. } else {
  2709. index.tipnum = "99+";
  2710. }
  2711. }
  2712. }
  2713. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  2714. if (index.id == 147) {
  2715. if (response.inspectionCount < 100) {
  2716. index.tipnum = response.inspectionCount;
  2717. } else {
  2718. index.tipnum = "99+";
  2719. }
  2720. }
  2721. }
  2722. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  2723. if (index.id == 23) {
  2724. if (response.solutionCount < 100) {
  2725. index.tipnum = response.solutionCount;
  2726. } else {
  2727. index.tipnum = "99+";
  2728. }
  2729. }
  2730. }
  2731. if (response.changeCount !== null && response.changeCount !== undefined) {
  2732. if (index.id == 1213) {
  2733. if (response.changeCount < 100) {
  2734. index.tipnum = response.changeCount;
  2735. } else {
  2736. index.tipnum = "99+";
  2737. }
  2738. }
  2739. }
  2740. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  2741. if (index.id == 3) {
  2742. if (response.incidentCount < 100) {
  2743. index.tipnum = response.incidentCount;
  2744. } else {
  2745. index.tipnum = "99+";
  2746. }
  2747. }
  2748. }
  2749. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  2750. if (index.id == 1231) {
  2751. if (response.applicationForm < 100) {
  2752. index.tipnum = response.applicationForm;
  2753. } else {
  2754. index.tipnum = "99+";
  2755. }
  2756. }
  2757. }
  2758. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2759. if (index.id == 23) {
  2760. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  2761. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2762. } else {
  2763. index.tipnum = "99+";
  2764. }
  2765. }
  2766. }
  2767. })
  2768. }
  2769. }
  2770. })
  2771. // return $rootScope.userMenus;
  2772. // $scope.recordpending = response.;
  2773. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2774. })
  2775. } else {
  2776. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  2777. }
  2778. }
  2779. // console.log($rootScope.userMenus);
  2780. }
  2781. $rootScope.userMenus = [];
  2782. var getMenus = function () {
  2783. function convertListToTree(data, treeMap) {
  2784. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  2785. var root = null; //Initially set our loop to null
  2786. var parentNode = null;
  2787. //loop over data
  2788. for (var i = 0; i < data.length; i++) {
  2789. // data[i].id = Number(data[i].id);
  2790. var datum = data[i];
  2791. //each node will have children, so let's give it a "children" poperty
  2792. datum.children = [];
  2793. //add an entry for this node to the map so that any future children can
  2794. //lookup the parent
  2795. idToNodeMap[datum.id] = datum;
  2796. //Does this node have a parent?
  2797. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  2798. //Doesn't look like it, so this node is the root of the tree
  2799. root = datum;
  2800. treeMap[datum.id] = root;
  2801. } else {
  2802. //This node has a parent, so let's look it up using the id
  2803. parentNode = idToNodeMap[datum.parentid];
  2804. //We don't need this property, so let's delete it.
  2805. //delete datum.parentid;
  2806. //Let's add the current node as a child of the parent node.
  2807. parentNode.children.push(datum);
  2808. }
  2809. }
  2810. return root;
  2811. }
  2812. function convertParentToChildList(data) {
  2813. var treeMap = {};
  2814. var list = [];
  2815. convertListToTree(data, treeMap);
  2816. angular.forEach(treeMap, function (item) {
  2817. list.push(item);
  2818. });
  2819. list = window._.sortBy(list, function (o) {
  2820. return o.orders;
  2821. });
  2822. return list;
  2823. }
  2824. //if(userMenus.length==0){
  2825. var userMenus = [];
  2826. var idMapMenu = {};
  2827. if ($rootScope.user) {
  2828. if ($rootScope.user.menu) {
  2829. var allJurisdiction2 = $rootScope.user.menu;
  2830. var onlyMenu2 = [];
  2831. for (var i = 0; i < allJurisdiction2.length; i++) {
  2832. if (allJurisdiction2[i].event == "1") {
  2833. onlyMenu2.push(allJurisdiction2[i])
  2834. }
  2835. }
  2836. // userMenus = convertParentToChildList($rootScope.user.menu);
  2837. userMenus = convertParentToChildList(onlyMenu2);
  2838. }
  2839. }
  2840. //}
  2841. $rootScope.userMenus = userMenus;
  2842. if ($rootScope.userMenus.length > 0) {
  2843. $rootScope.getpending();
  2844. // setInterval($rootScope.getpending(), 30000);
  2845. }
  2846. return userMenus;
  2847. }
  2848. setInterval(function () {
  2849. if ($rootScope.userMenus.length > 0) {
  2850. $rootScope.getpending()
  2851. $rootScope.getMsgNum($rootScope.user.id)
  2852. }
  2853. }, 5000);
  2854. getMenus();
  2855. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  2856. $rootScope.logout = function () {
  2857. // var userid =data.id;
  2858. // console.log(' userid='+JSON.stringify( userid));
  2859. //单点登录
  2860. if (localStorage.getItem('isSSo') === '1') {
  2861. sessionStorage.clear();
  2862. localStorage.clear();
  2863. location.href = 'http://' + location.hostname + ':8080/pc_logout.jsp'
  2864. } else {
  2865. $auth.signOut()
  2866. .then(function (resp) {
  2867. // $auth.deleteData('auth_headers')
  2868. sessionStorage.clear();
  2869. localStorage.clear();
  2870. console.log($rootScope.isHk,'hk');
  2871. console.log($rootScope.isZncd,'zncd');
  2872. if($rootScope.isZncd){
  2873. if ($rootScope.isFuwutai) {
  2874. tlwsa.tlaClose();
  2875. $.toaster({
  2876. priority: 'info',
  2877. title: '操作',
  2878. message: '呼叫中心断开连接'
  2879. });
  2880. }
  2881. }
  2882. $state.go("login.signin");
  2883. })
  2884. .catch(function (resp) { });
  2885. }
  2886. //$cookieStore.remove("userObm");
  2887. //$cookieStore.remove("menuObm");
  2888. //$cookieStore.remove("session");
  2889. //$rootScope.user = undefined;
  2890. //$rootScope.menus = undefined;
  2891. //$rootScope.nickname = undefined;
  2892. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  2893. // //logout: function(noServerLogout){
  2894. // window.sessionStorage.clear();
  2895. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  2896. // //},
  2897. }
  2898. // 快速建单
  2899. $rootScope.newOrder = function () {
  2900. $state.go('app.newOrder');
  2901. }
  2902. // save settings to local storage
  2903. if (angular.isDefined($localStorage.layout)) {
  2904. $scope.app.layout = $localStorage.layout;
  2905. } else {
  2906. $localStorage.layout = $scope.app.layout;
  2907. }
  2908. $scope.$watch('app.layout', function () {
  2909. // save to local storage
  2910. $localStorage.layout = $scope.app.layout;
  2911. }, true);
  2912. //global function to scroll page up
  2913. $scope.toTheTop = function () {
  2914. $document.scrollTopAnimated(0, 600);
  2915. };
  2916. // angular translate
  2917. // ----------------------
  2918. $scope.language = {
  2919. // Handles language dropdown
  2920. listIsOpen: false,
  2921. // list of available languages
  2922. available: {
  2923. 'en': 'English',
  2924. 'it_IT': 'Italiano',
  2925. 'de_DE': 'Deutsch',
  2926. 'zh_cn': 'Chinese'
  2927. },
  2928. // display always the current ui language
  2929. init: function () {
  2930. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  2931. var preferredLanguage = $translate.preferredLanguage();
  2932. // we know we have set a preferred one in app.config
  2933. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  2934. },
  2935. set: function (localeId, ev) {
  2936. $translate.use(localeId);
  2937. $scope.language.selected = $scope.language.available[localeId];
  2938. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  2939. }
  2940. };
  2941. $scope.language.init();
  2942. // Function that find the exact height and width of the viewport in a cross-browser way
  2943. var viewport = function () {
  2944. var e = window,
  2945. a = 'inner';
  2946. if (!('innerWidth' in window)) {
  2947. a = 'client';
  2948. e = document.documentElement || document.body;
  2949. }
  2950. return {
  2951. width: e[a + 'Width'],
  2952. height: e[a + 'Height']
  2953. };
  2954. };
  2955. // function that adds information in a scope of the height and width of the page
  2956. $scope.getWindowDimensions = function () {
  2957. return {
  2958. 'h': viewport().height,
  2959. 'w': viewport().width
  2960. };
  2961. };
  2962. // Detect when window is resized and set some variables
  2963. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  2964. $scope.windowHeight = newValue.h;
  2965. $scope.windowWidth = newValue.w;
  2966. if (newValue.w >= 992) {
  2967. $scope.isLargeDevice = true;
  2968. } else {
  2969. $scope.isLargeDevice = false;
  2970. }
  2971. if (newValue.w < 992) {
  2972. $scope.isSmallDevice = true;
  2973. } else {
  2974. $scope.isSmallDevice = false;
  2975. }
  2976. if (newValue.w <= 768) {
  2977. $scope.isMobileDevice = true;
  2978. } else {
  2979. $scope.isMobileDevice = false;
  2980. }
  2981. }, true);
  2982. // Apply on resize
  2983. $win.on('resize', function () {
  2984. $scope.$apply();
  2985. });
  2986. $rootScope.app.layout.isNavbarFixed = false;
  2987. $rootScope.app.layout.isSidebarFixed = false;
  2988. $rootScope.app.layout.isFooterFixed = false;
  2989. $scope.login_signquick = function (Requesteruserinform) {
  2990. $rootScope.statuscall = 1;
  2991. $scope.loginForm = {
  2992. username: Requesteruserinform.username,
  2993. password: Requesteruserinform.password
  2994. }
  2995. $auth.submitLogin($scope.loginForm)
  2996. .then(function (resp) {
  2997. localStorage.setItem("jry_user", JSON.stringify(resp));
  2998. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  2999. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  3000. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  3001. var onlyMenu = [];
  3002. for (var i = 0; i < allJurisdiction.length; i++) {
  3003. if (allJurisdiction[i].event == "1") {
  3004. onlyMenu.push(allJurisdiction[i])
  3005. }
  3006. };
  3007. $rootScope.userMenus = onlyMenu;
  3008. getMenus();
  3009. if (resp.error != 500) {
  3010. // $state.go('app.dashboard');
  3011. $rootScope.app.isLoginFixed = false;
  3012. } else {
  3013. resp.error = "";
  3014. $scope.loginForm.password = "";
  3015. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  3016. }
  3017. })
  3018. .catch(function (resp) {
  3019. $scope.loginForm.password = "";
  3020. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  3021. });
  3022. }
  3023. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  3024. var theRequest = {};
  3025. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  3026. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  3027. var str = url.substr(index + 1);
  3028. var strs = str.split("&");
  3029. for (var i = 0; i < strs.length; i++) {
  3030. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  3031. }
  3032. // return theRequest;
  3033. $scope.login_signquick(theRequest)
  3034. }
  3035. // $scope.casUserId = window.location.search;
  3036. // $scope.loginForm = {
  3037. // username: theRequest[0].split("=")[1],
  3038. // password: theRequest[1].split("=")[1]
  3039. // }
  3040. // $scope.lodingstyle = 'nodata';
  3041. var userAgent = window.navigator.userAgent.toLowerCase();
  3042. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  3043. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  3044. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  3045. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  3046. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  3047. if (isOpera) {
  3048. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  3049. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  3050. }
  3051. if (isIE) {
  3052. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  3053. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  3054. }
  3055. if (isFF) {
  3056. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  3057. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  3058. }
  3059. if (isSafari) {
  3060. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  3061. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  3062. }
  3063. if (isChrome) {
  3064. // login_sign();
  3065. $rootScope.app.isChrome = false;
  3066. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  3067. } else {
  3068. $rootScope.app.isChrome = true;
  3069. $scope.checkchrome = '';
  3070. // return alert("访问失败,请用Chrome浏览器访问!");
  3071. }
  3072. // }
  3073. // $scope.handleloginEnter = function(e) {
  3074. // if (e.keyCode == 13) {
  3075. // $scope.handleLoginClick();
  3076. // }
  3077. // };
  3078. // if (document.getElementById("isWatch").value == "true") {
  3079. // $scope.isHanderuser = true;
  3080. // } else {
  3081. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  3082. // $scope.isHanderuser = false;
  3083. // $scope.login_sign();
  3084. // }
  3085. // }
  3086. // $scope.viewType = "password";
  3087. // $scope.isPassword = true;
  3088. // $scope.toggleView = function() {
  3089. // $scope.isPassword = !$scope.isPassword;
  3090. // $scope.viewType = $scope.isPassword ? "password" : "text";
  3091. // }
  3092. // $scope.handleSignOutBtnClick = function() {
  3093. // $auth.signOut()
  3094. // .then(function(resp) {
  3095. // // handle success response
  3096. // })
  3097. // .catch(function(resp) {
  3098. // // handle error response
  3099. // });
  3100. // };
  3101. // }
  3102. // }
  3103. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  3104. // } else {
  3105. // $scope.loginstart();
  3106. // }
  3107. //websocket 信息中心
  3108. console.log(atmosphere)
  3109. var socket = atmosphere;
  3110. var subSocket;
  3111. // We are now ready to cut the request
  3112. var request = {
  3113. url: 'ws://192.168.199.150:8080/messagestation/cache',
  3114. contentType: "application/json",
  3115. shared: true, // 标签共享
  3116. trackMessageLength: true, //校验数据完整性
  3117. transport: 'websocket'
  3118. };
  3119. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  3120. request.onOpen = function (response) {
  3121. console.log(response)
  3122. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  3123. // alert("开始连接")
  3124. };
  3125. request.onMessage = function (response) {
  3126. var message = response.responseBody;
  3127. // alert("连接成功")
  3128. console.log(message)
  3129. try {
  3130. var json = JSON.parse(message);
  3131. console.log(json.noRead)
  3132. $scope.noReadData = json.noRead
  3133. } catch (e) {
  3134. console.log('呵呵哒: ', message);
  3135. return;
  3136. }
  3137. };
  3138. request.onClose = function (response) {
  3139. // alert("连接结束")
  3140. }
  3141. request.onError = function (response) {
  3142. // alert('连接失败')
  3143. };
  3144. //信息中心模态框
  3145. var loginUser = $rootScope.user;
  3146. // if(loginUser){
  3147. // // 未读消息数量
  3148. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  3149. // if (data.status == 200) {
  3150. // $scope.noReadData=data.totalNum
  3151. // // $rootScope.option.all = $rootScope.all;
  3152. // } else {
  3153. // $scope.noReadData=0
  3154. // }
  3155. // })
  3156. // }
  3157. // $scope.noReadData=($rootScope.noReadData||0)
  3158. // // $rootScope.all = 5;
  3159. // setTimeout(function() {
  3160. // console.log($scope.noReadData)
  3161. // }, 500)
  3162. $rootScope.wt_messages = function () {
  3163. var modalInstance = $modal.open({
  3164. templateUrl: '../../../assets/views/wt_messages.html',
  3165. controller: function ($scope, $modalInstance) {
  3166. $rootScope.msgData = {
  3167. idx: 0,
  3168. sum: 5,
  3169. messageStation: {
  3170. readStatus: 0,
  3171. userId: $rootScope.user.id
  3172. }
  3173. }
  3174. // 关闭
  3175. $scope.closeModel = function () {
  3176. modalInstance.close();
  3177. }
  3178. $scope.getMsgData = function () {
  3179. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3180. if (data) {
  3181. $rootScope.msg = data.list
  3182. $rootScope.all = data.pageCount;
  3183. $scope.wt_msgData = data
  3184. $rootScope.noReadData = data.totalNum
  3185. }
  3186. })
  3187. }
  3188. $scope.getMsgData()
  3189. $scope.message_type = 2;
  3190. $scope.message_no = function (type) { //未读1
  3191. $scope.wt_msgData = {};
  3192. $scope.message_type = type;
  3193. $rootScope.msgData.messageStation.readStatus = 0,
  3194. // $rootScope.option.curr = 1;
  3195. $rootScope.msgData.idx = 0;
  3196. // console.log($rootScope.option.curr)
  3197. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3198. $scope.msg_yesType = true;
  3199. if (data.status == 200) {
  3200. $scope.msg_yesType = false
  3201. $scope.wt_msgData = data
  3202. $rootScope.msg = data.list
  3203. $rootScope.all = data.pageCount;
  3204. $rootScope.noReadData = data.totalNum;
  3205. // $rootScope.option.all = $rootScope.all;
  3206. } else {
  3207. $scope.msg_yesType = true;
  3208. }
  3209. })
  3210. }
  3211. $scope.message_yes = function (type) { //已读0
  3212. $scope.wt_msgData = {};
  3213. $scope.message_type = type;
  3214. $rootScope.msgData.messageStation.readStatus = 1,
  3215. $rootScope.msgData.idx = 0;
  3216. // $rootScope.option.curr = 1;
  3217. // console.log($rootScope.option.curr)
  3218. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3219. $scope.msg_noType = true;
  3220. if (data.status == 200) {
  3221. $scope.msg_noType = false
  3222. $scope.wt_msgData = data
  3223. $rootScope.msg = data.list;
  3224. $rootScope.all = data.pageCount;
  3225. // $rootScope.option.all = $rootScope.all;
  3226. } else {
  3227. $scope.msg_noType = true
  3228. }
  3229. })
  3230. };
  3231. $scope.sBtn = function () {
  3232. // console.log($rootScope.msgData)
  3233. // console.log($scope.wt_msgData)
  3234. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  3235. console.log($rootScope.msgData)
  3236. $scope.getMsgData()
  3237. }
  3238. $scope.xBtn = function () {
  3239. // console.log($rootScope.msgData)
  3240. // console.log($scope.wt_msgData)
  3241. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  3242. console.log($rootScope.msgData)
  3243. $scope.getMsgData()
  3244. }
  3245. $scope.redIn = function (data) {
  3246. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  3247. $scope.messageStation = {
  3248. messageStation: {
  3249. id: data.id,
  3250. readStatus: 1,
  3251. readTime: start
  3252. }
  3253. }
  3254. api_msg.updateDataList($scope.messageStation).then(function (data) {
  3255. console.log(data);
  3256. if (data.status == 200) {
  3257. $rootScope.msgData.messageStation.readStatus = 0,
  3258. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3259. $rootScope.msg = data.list
  3260. $rootScope.all = data.pageCount;
  3261. $rootScope.noReadData = data.totalNum;
  3262. })
  3263. }
  3264. })
  3265. };
  3266. },
  3267. size: 'lg',
  3268. resolve: {
  3269. }
  3270. })
  3271. }
  3272. }
  3273. ]);
  3274. //消息中心分页组件
  3275. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  3276. $rootScope.option = {
  3277. curr: 1, //当前页数
  3278. all: $rootScope.all, //总页数
  3279. count: 5, //最多显示的页数,默认为10
  3280. //点击页数的回调函数,参数page为点击的页数
  3281. click: function (page) {
  3282. $rootScope.msgData.idx = page - 1;
  3283. //这里可以写跳转到某个页面等...
  3284. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3285. $rootScope.msg = data.list
  3286. $rootScope.all = data.pageCount;
  3287. $rootScope.option.all = $rootScope.all;
  3288. })
  3289. }
  3290. }
  3291. }]);
  3292. app.directive('myPagination', function () {
  3293. return {
  3294. restrict: 'EA',
  3295. replace: true,
  3296. rootScope: {
  3297. option: '=pageOption'
  3298. },
  3299. controller: 'msgCtrl',
  3300. template: '<ul class="pagination">' +
  3301. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  3302. '<a href="javascript:;">{{p}}</a>' +
  3303. '</li>' +
  3304. '</ul>',
  3305. link: function ($rootScope) {
  3306. //容错处理
  3307. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  3308. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  3309. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  3310. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  3311. //得到显示页数的数组
  3312. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  3313. //绑定点击事件
  3314. $rootScope.pageClick = function (page) {
  3315. if (page == '«') {
  3316. page = parseInt($rootScope.option.curr) - 1;
  3317. } else if (page == '»') {
  3318. page = parseInt($rootScope.option.curr) + 1;
  3319. }
  3320. if (page < 1) page = 1;
  3321. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  3322. //点击相同的页数 不执行点击事件
  3323. if (page == $rootScope.option.curr) return;
  3324. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  3325. $rootScope.option.click(page);
  3326. $rootScope.option.curr = page;
  3327. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  3328. }
  3329. };
  3330. //返回页数范围(用来遍历)
  3331. function getRange(curr, all, count) {
  3332. //计算显示的页数
  3333. // console.log(curr, all, count)
  3334. curr = parseInt(curr);
  3335. all = parseInt(all);
  3336. count = parseInt(count);
  3337. var from = curr - parseInt(count / 2);
  3338. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  3339. //显示的页数容处理
  3340. if (from <= 0) {
  3341. from = 1;
  3342. to = from + count - 1;
  3343. if (to > all) {
  3344. to = all;
  3345. }
  3346. }
  3347. if (to > all) {
  3348. to = all;
  3349. from = to - count + 1;
  3350. if (from <= 0) {
  3351. from = 1;
  3352. }
  3353. }
  3354. var range = [];
  3355. for (var i = from; i <= to; i++) {
  3356. range.push(i);
  3357. }
  3358. range.push('»');
  3359. range.unshift('«');
  3360. return range;
  3361. }
  3362. }
  3363. }
  3364. });
  3365. app.service('Myservice', function () {
  3366. return {
  3367. };
  3368. });
  3369. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3370. // console.log(bh)
  3371. // if(bh>=0&&bh<=53){
  3372. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3373. // }else{
  3374. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3375. // }
  3376. window.onscroll = function () {
  3377. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  3378. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  3379. } else {
  3380. $('#sidebar').css('padding-top', '0')
  3381. }
  3382. // console.log(window.pageYOffset)
  3383. // console.log(window.innerHeight)
  3384. // console.log(document.body.scrollHeight)
  3385. // 底部padding
  3386. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3387. // console.log(bh)
  3388. // if(bh>=0&&bh<=53){
  3389. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3390. // }else{
  3391. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3392. // }
  3393. }