mainCtrl.js 123 KB

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