mainCtrl.js 168 KB

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