mainCtrl.js 167 KB

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