mainCtrl.js 170 KB

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