mainCtrl.js 166 KB

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