mainCtrl.js 169 KB

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