mainCtrl.js 169 KB

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