mainCtrl.js 179 KB

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