mainCtrl.js 166 KB

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