mainCtrl.js 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837
  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 filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  953. api_user_data.fetchDataList('requester', filterData).then(function(data) {
  954. var myData = Restangular.stripRestangular(data);
  955. // $rootScope.phone="";
  956. if (myData.list.length == 0) {
  957. var modalInstance = $modal.open({
  958. backdrop: "static",
  959. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  960. controller: function($scope, $modalInstance, api_user_data, api_wechatfile, SweetAlert) {
  961. $modalInstance.SweetAlert = SweetAlert;
  962. $scope.title = "新增报修人";
  963. $scope.requester = {};
  964. $scope.onChangeadd = function(searchData) {
  965. $scope.searchKey = searchData.account;
  966. // $scope.searchDataadd = searchData;
  967. var requesdata = angular.copy(searchData)
  968. // if (requesdata.mphone) {
  969. // delete requesdata.mphone;
  970. // }
  971. if (requesdata.telephone) {
  972. delete requesdata.telephone;
  973. }
  974. angular.extend($scope.requester, requesdata);
  975. }
  976. $scope.refreshUseradd = function(searchKey) { //请求人搜索
  977. $scope.requester.account = searchKey;
  978. $scope.searchData = searchKey;
  979. serchdataadd(searchKey);
  980. }
  981. $scope.getMydata = function(x) {
  982. var reqestdatap = JSON.parse(x[0])
  983. if ($scope.requester.telephone) {
  984. delete reqestdatap.telephone;
  985. }
  986. $scope.searchField = JSON.parse(x[0]).account;
  987. angular.extend($scope.requester, reqestdatap);
  988. // if ($scope.requester.areaDTO && $scope.requester.areaDTO.id && $scope.requester.areaDTO.id != "") {
  989. // api_user_data.fetchDataList('place', { place: { areaId: $scope.requester.areaDTO.id }, idx: 0, sum: 1000 }).then(function(response) {
  990. // if (response.status == 200) {
  991. // $scope.places = response.list;
  992. // }
  993. // })
  994. // }
  995. // $scope.searchField = JSON.parse(x[0]).account;
  996. // $scope.requester = JSON.parse(x[0]);
  997. console.log($scope.requester);
  998. $scope.refreshArea('');
  999. $scope.refresh('');
  1000. }
  1001. $scope.getMydataone = function(x) {
  1002. $scope.searchField = x;
  1003. $scope.requester.account = x;
  1004. }
  1005. serchdataadd();
  1006. function serchdataadd(searchKey) {
  1007. if (searchKey) {
  1008. var filterData = {
  1009. 'requester': {
  1010. 'searchKey': searchKey,
  1011. },
  1012. idx: 0,
  1013. sum: 10
  1014. };
  1015. } else {
  1016. var filterData = {
  1017. idx: 0,
  1018. sum: 10
  1019. };
  1020. }
  1021. api_user_data.fetchDataList('requester', filterData).then(function(response) {
  1022. var myData = response;
  1023. $scope.myData = myData.list;
  1024. });
  1025. }
  1026. api_user_data.fetchDataList('branch', { idx: 0, sum: 100 }).then(function(response) {
  1027. if (response.status == 200) {
  1028. $scope.branchs = response.list;
  1029. }
  1030. })
  1031. // api_user_data.fetchDataList('place', { idx: 0, sum: 1000 }).then(function(response) {
  1032. // if (response.status == 200) {
  1033. // $scope.places = response.list;
  1034. // }
  1035. // }) //地点
  1036. // api_user_data.fetchDataList('requesterType', { idx: 0, sum: 100 }).then(function(response) {
  1037. // if (response.status == 200) {
  1038. // $scope.networktypes = response.list;
  1039. // }
  1040. // })
  1041. api_wechatfile.getDictionary({
  1042. "key": "requester_type",
  1043. "type": "list"
  1044. }).then(function (response) {
  1045. // if (response.status == 200) {
  1046. $scope.networktypes = response;
  1047. // }
  1048. })
  1049. $scope.onChangeBranch = function (item) {
  1050. delete $scope.requester.place;
  1051. console.log($scope.requester, 'changeArea');
  1052. api_user_data
  1053. .fetchDataList("area", {
  1054. area: {
  1055. branch: item.id,
  1056. },
  1057. idx: 0,
  1058. sum: 1000,
  1059. })
  1060. .then(function (response) {
  1061. if (response.status == 200) {
  1062. $scope.areas = response.list;
  1063. }
  1064. });
  1065. };
  1066. $scope.onChange = function(item) {
  1067. $scope.requester.place = {area: $scope.requester.place.area};
  1068. console.log($scope.requester, 'changeArea');
  1069. api_user_data.fetchDataList('place', { place: { areaId: item.id }, idx: 0, sum: 1000 }).then(function(response) {
  1070. if (response.status == 200) {
  1071. $scope.places = response.list;
  1072. }
  1073. })
  1074. }
  1075. // 修改地点
  1076. $scope.requesterPlaceid = "";
  1077. $scope.onChangePlace = function (item) {
  1078. $scope.requesterPlaceid = item.id;
  1079. console.log($scope.requester, 'changePlace');
  1080. api_user_data
  1081. .fetchDataList("room", {
  1082. room: {
  1083. place: {
  1084. id: item.id,
  1085. },
  1086. },
  1087. idx: 0,
  1088. sum: 1000,
  1089. })
  1090. .then(function (response) {
  1091. if (response.status == 200) {
  1092. $scope.rooms = response.list;
  1093. }
  1094. });
  1095. };
  1096. $scope.refreshArea = function (searchVal) {
  1097. console.log($scope.requester, 'area');
  1098. var faildata = {};
  1099. if ($scope.requester.branch) {
  1100. faildata = {
  1101. idx: 0,
  1102. sum: 1000,
  1103. area: {
  1104. branch: $scope.requester.branch.id,
  1105. area: searchVal,
  1106. selectType: "pinyin_qs",
  1107. },
  1108. };
  1109. } else {
  1110. return;
  1111. }
  1112. api_user_data
  1113. .fetchDataList("area", faildata)
  1114. .then(function (response) {
  1115. $scope.areas = response.list;
  1116. delete $scope.requester.areaDTO;
  1117. });
  1118. };
  1119. //地点搜索
  1120. $scope.refresh = function (searchVal) {
  1121. console.log($scope.requester, 'place');
  1122. var faildata = {};
  1123. if ($scope.requester.place && $scope.requester.place.area) {
  1124. faildata = {
  1125. idx: 0,
  1126. sum: 1000,
  1127. place: {
  1128. areaId: $scope.requester.place.area.id,
  1129. place: searchVal,
  1130. selectType: "pinyin_qs",
  1131. },
  1132. };
  1133. } else {
  1134. return;
  1135. }
  1136. api_user_data
  1137. .fetchDataList("place", faildata)
  1138. .then(function (response) {
  1139. $scope.places = response.list;
  1140. delete $scope.requester.placeDTO;
  1141. });
  1142. };
  1143. $scope.requester = { 'telephone': $rootScope.phone };
  1144. $scope.ok = function() {
  1145. // $modalInstance.close($scope.requester);
  1146. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1147. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1148. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1149. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1150. } else {
  1151. // $modalInstance.close($scope.requester);
  1152. $scope.selectedItemTodo($scope.requester)
  1153. }
  1154. };
  1155. $scope.selectedItemTodo = function(selectedItem){
  1156. if (selectedItem) {
  1157. // if (selectedItem.telephone && !selectedItem.mphone) {
  1158. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  1159. // delete selectedItem.mphone;
  1160. // }
  1161. var data = {
  1162. 'requester': selectedItem
  1163. };
  1164. api_user_data.addData('requester', data).then(function(response) {
  1165. if (response.status == 200) {
  1166. $modalInstance.dismiss("ok");
  1167. var data = {
  1168. model: {
  1169. requestershow: response.data,
  1170. incident: {
  1171. requester: response.data,
  1172. branch: response.data.branch,
  1173. area: response.data.place?response.data.place.area:undefined,
  1174. place: response.data.place,
  1175. houseNumber: response.data.houseNumber,
  1176. contactsInformation: response.data.telephone,
  1177. contacts:response.data.name,
  1178. callID: cdrid,
  1179. source: { id: 1547 },
  1180. incomingPhone: $rootScope.phone
  1181. },
  1182. },
  1183. };
  1184. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1185. }else{
  1186. modalInstance.SweetAlert.swal({
  1187. title: "系统错误",
  1188. text: "账号重复!",
  1189. type: "error",
  1190. });
  1191. }
  1192. })
  1193. }
  1194. }
  1195. $scope.cancel = function() {
  1196. $modalInstance.dismiss('cancel');
  1197. $rootScope.setidle();
  1198. };
  1199. },
  1200. });
  1201. //#region list1
  1202. // modalInstance.result.then(function(selectedItem) {
  1203. // if (selectedItem) {
  1204. // // if (selectedItem.telephone && !selectedItem.mphone) {
  1205. // // selectedItem.telephone = angular.copy(selectedItem.mphone);
  1206. // // delete selectedItem.mphone;
  1207. // // }
  1208. // var data = {
  1209. // 'requester': selectedItem
  1210. // };
  1211. // api_user_data.addData('requester', data).then(function(response) {
  1212. // if (response.status == 200) {
  1213. // var data = {
  1214. // model: {
  1215. // requestershow: response.data,
  1216. // incident: {
  1217. // requester: response.data,
  1218. // branch: response.data.branch,
  1219. // area: response.data.place?response.data.place.area:undefined,
  1220. // place: response.data.place,
  1221. // houseNumber: response.data.houseNumber,
  1222. // contactsInformation: response.data.telephone,
  1223. // contacts:response.data.name,
  1224. // callID: cdrid,
  1225. // source: { id: 1547 },
  1226. // },
  1227. // },
  1228. // };
  1229. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1230. // }else{
  1231. // modalInstance.SweetAlert.swal({
  1232. // title: "系统错误",
  1233. // text: "账号重复!",
  1234. // type: "error",
  1235. // });
  1236. // }
  1237. // })
  1238. // }
  1239. // });
  1240. //#endregion list1
  1241. } else if (myData.list.length == 1) {
  1242. angular.extend(myData.list[0], { 'telephone': $rootScope.phone });
  1243. var data = {
  1244. model: {
  1245. requestershow: myData.list[0],
  1246. incident: {
  1247. requester: myData.list[0],
  1248. branch: myData.list[0].branch,
  1249. area: myData.list[0].place?myData.list[0].place.area:undefined,
  1250. place: myData.list[0].place,
  1251. contactsInformation: myData.list[0].telephone,
  1252. houseNumber: myData.list[0].houseNumber,
  1253. contacts:myData.list[0].name,
  1254. callID: cdrid,
  1255. source: { id: 1547 },
  1256. incomingPhone: $rootScope.phone
  1257. },
  1258. },
  1259. };
  1260. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1261. } else {
  1262. var modalInstance = $modal.open({
  1263. templateUrl: 'assets/views/createincident.html',
  1264. backdrop: "static",
  1265. controller: function($scope, $modalInstance, api_user_data) {
  1266. $scope.title = "请确定报修人";
  1267. $scope.requester = myData.list;
  1268. $scope.choice = function(requester) {
  1269. $modalInstance.dismiss('cancel');
  1270. angular.extend(requester, { 'telephone': $rootScope.phone });
  1271. var data = {
  1272. model: {
  1273. requestershow: requester,
  1274. incident: {
  1275. requester: requester,
  1276. branch: requester.branch,
  1277. area: requester.place?requester.place.area:undefined,
  1278. place: requester.place,
  1279. houseNumber: requester.houseNumber,
  1280. contactsInformation: requester.telephone,
  1281. contacts:requester.name,
  1282. callID: cdrid,
  1283. source: { id: 1547 },
  1284. incomingPhone: $rootScope.phone
  1285. },
  1286. },
  1287. };
  1288. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1289. };
  1290. $scope.cancel = function() {
  1291. $modalInstance.dismiss('cancel');
  1292. $rootScope.setidle();
  1293. };
  1294. },
  1295. size: "lg"
  1296. });
  1297. }
  1298. });
  1299. }
  1300. })
  1301. }
  1302. }
  1303. }
  1304. // else if(mydata.evttype == 'allbusy' && mydata.status == 'false'){
  1305. // if(location.href.includes('app/incident/list') || location.href.includes('app/incident/editor') || location.href.includes('app/incident/title')){
  1306. // $scope.setbusy();
  1307. // }else{
  1308. // $scope.setidle();
  1309. // }
  1310. // }
  1311. }
  1312. };
  1313. var heartCheck = {
  1314. timeout: 12000, //60ms
  1315. timeoutObj: null,
  1316. serverTimeoutObj: null,
  1317. reset: function() {
  1318. clearTimeout(this.timeoutObj);
  1319. clearTimeout(this.serverTimeoutObj);    
  1320. this.start();
  1321. },
  1322. start: function() {
  1323. var self = this;
  1324. this.timeoutObj = setTimeout(function() {
  1325. if ($scope.login) {
  1326. ws.send("HeartBeat");
  1327. self.serverTimeoutObj = setTimeout(function() {
  1328. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  1329. }, self.timeout)
  1330. }
  1331. }, this.timeout)
  1332. },
  1333. }
  1334. ws.onclose = function(evt) { reconnect(); }
  1335. ws.onerror = function(evt) { reconnect(); };
  1336. }
  1337. reconnect();
  1338. } else {
  1339. alert('签入失败,'+ data.errmsg +',请到相应的话机输入*91#');
  1340. var Notification = window.Notification;
  1341. Notification.requestPermission();
  1342. var n = new Notification("签入失败!", {
  1343. body: data.errmsg,
  1344. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  1345. // onclick: function onNotificationClicked() {
  1346. // console.log('Notification clicked.');
  1347. // }
  1348. });
  1349. }
  1350. })
  1351. });
  1352. })
  1353. }
  1354. // 牛逼
  1355. // setInterval(function() {
  1356. // if ($scope.login && $rootScope.statuscall == 1 && $rootScope.statecall == 1) {
  1357. // $rootScope.setidle(true);
  1358. // } else if ($scope.login && $rootScope.statuscall != 3 && $rootScope.statecall == 2 && $rootScope.statuscall != 0) {
  1359. // $rootScope.setbusy(true);
  1360. // }
  1361. // }, 5000);
  1362. // 华科呼叫中心 end
  1363. //话机呼叫中心--开始
  1364. // 1是老的呼叫中心
  1365. // 2是财大2021年12月29日新增的呼叫中心
  1366. // 3是华科新增的呼叫中心
  1367. console.log($rootScope.isHk,'hk')
  1368. console.log($rootScope.isZncd,'zncd')
  1369. if($rootScope.isZncd){
  1370. $rootScope.seiminHj = 2;
  1371. }else if($rootScope.isHk){
  1372. $rootScope.seiminHj = 3;
  1373. }else{
  1374. $rootScope.seiminHj = 1;
  1375. }
  1376. $rootScope.getExtnDirect = function () {
  1377. $rootScope['getExtnDirect' + $rootScope.seiminHj]();
  1378. }
  1379. // --------------------------1------------------------------
  1380. $rootScope.getExtnDirect1 = function () {
  1381. var jry_data_dictionary = {
  1382. key: "hjzx_cornet",
  1383. type: "list"
  1384. }
  1385. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1386. var websocket_url = "ws://192.168.3.122:29003/ola_socket";
  1387. var ola_queue = "10009"; //通话配置-队列配置-队列ID
  1388. // var ola_extn = "1001"; //个人信息-座席分机号
  1389. $rootScope.jry_extnNumberSelect = [];
  1390. $rootScope.jry_extnNumberObj = {};
  1391. $rootScope.jry_extnNumberSelect = res;
  1392. $rootScope.jry_extnNumberObj.jry_extnNumber = $rootScope.jry_extnNumberSelect[0];
  1393. function log(msg) {
  1394. //IE has no console
  1395. if ('console' in window) console.log(msg);
  1396. }
  1397. function websocket_connect() {
  1398. ola.connect(websocket_url);
  1399. ola.onConnect = onConnect;
  1400. ola.onClose = onClose;
  1401. ola.onMessage = onMessage;
  1402. }
  1403. $(document).ready(function () {
  1404. // if(ola_extn!=""){
  1405. if ($rootScope.jry_extnNumberObj.jry_extnNumber) {
  1406. websocket_connect();
  1407. }
  1408. });
  1409. /* callbacks */
  1410. function onMessage(evt) {
  1411. var phoneData = JSON.parse(evt.data);
  1412. if (phoneData.event_type == "agent_state") {
  1413. console.log(phoneData);
  1414. if (phoneData.state == "busy") {
  1415. $('#agent_state').append(" (" + phoneData.private_data + ")");
  1416. // 来电
  1417. if (phoneData.private_data == "ring") {
  1418. console.log(phoneData);
  1419. $rootScope.jry_state = "laidian";
  1420. var Notification = window.Notification;
  1421. Notification.requestPermission();
  1422. var n = new Notification("你有来电", {
  1423. body: "来电号码:" + phoneData.ani,
  1424. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  1425. });
  1426. // 摘机
  1427. } else if (phoneData.private_data == "answered") {
  1428. $rootScope.jry_state = "tonghuazhong";
  1429. var jry_findPhone = "";
  1430. if (phoneData.ani) {
  1431. jry_findPhone = phoneData.ani
  1432. } else if (phoneData.dnis && phoneData.other_answered) {
  1433. jry_findPhone = phoneData.dnis
  1434. }
  1435. var filterData = {
  1436. "idx": 0,
  1437. "sum": 100,
  1438. "requester": {
  1439. "mphone": jry_findPhone,
  1440. "telephone": jry_findPhone,
  1441. "selectType": 1
  1442. }
  1443. }
  1444. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  1445. var myData = Restangular.stripRestangular(data);
  1446. // $rootScope.phone="";
  1447. // 新增报修人
  1448. if (myData.list.length == 0) {
  1449. var modalInstance = $modal.open({
  1450. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  1451. controller: function ($scope, $modalInstance, api_user_data, SweetAlert, api_wechatfile) {
  1452. $modalInstance.SweetAlert = SweetAlert;
  1453. $scope.title = "新增报修人";
  1454. $scope.requester = {};
  1455. $scope.onChangeadd = function (searchData) {
  1456. $scope.searchKey = searchData.account;
  1457. // $scope.searchDataadd = searchData;
  1458. var requesdata = angular.copy(searchData)
  1459. // if (requesdata.mphone) {
  1460. // delete requesdata.mphone;
  1461. // }
  1462. if (requesdata.telephone) {
  1463. delete requesdata.telephone;
  1464. }
  1465. angular.extend($scope.requester, requesdata);
  1466. }
  1467. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  1468. $scope.requester.account = searchKey;
  1469. $scope.searchData = searchKey;
  1470. serchdataadd(searchKey);
  1471. }
  1472. $scope.getMydata = function (x) {
  1473. var reqestdatap = JSON.parse(x[0])
  1474. // if ($scope.requester.mphone) {
  1475. // delete reqestdatap.mphone;
  1476. // }
  1477. if ($scope.requester.telephone) {
  1478. delete reqestdatap.telephone;
  1479. }
  1480. $scope.searchField = JSON.parse(x[0]).account;
  1481. angular.extend($scope.requester, reqestdatap);
  1482. }
  1483. $scope.getMydataone = function (x) {
  1484. $scope.searchField = x;
  1485. $scope.requester.account = x;
  1486. }
  1487. serchdataadd();
  1488. function serchdataadd(searchKey) {
  1489. if (searchKey) {
  1490. var filterData = {
  1491. 'requester': {
  1492. 'searchKey': searchKey,
  1493. },
  1494. idx: 0,
  1495. sum: 10
  1496. };
  1497. } else {
  1498. var filterData = {
  1499. idx: 0,
  1500. sum: 10
  1501. };
  1502. }
  1503. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  1504. var myData = response;
  1505. $scope.myData = myData.list;
  1506. });
  1507. }
  1508. api_user_data.fetchDataList('area', {
  1509. idx: 0,
  1510. sum: 100
  1511. }).then(function (response) {
  1512. if (response.status == 200) {
  1513. $scope.areas = response.list;
  1514. }
  1515. })
  1516. api_wechatfile.getDictionary({
  1517. "key": "requester_type",
  1518. "type": "list"
  1519. }).then(function (response) {
  1520. // if (response.status == 200) {
  1521. $scope.networktypes = response;
  1522. // }
  1523. })
  1524. $scope.requesterAreaid = "";
  1525. $scope.onChange = function (item) {
  1526. $scope.requesterAreaid = item.id;
  1527. $scope.requester.place = {};
  1528. api_user_data.fetchDataList('place', {
  1529. place: {
  1530. areaId: item.id
  1531. },
  1532. idx: 0,
  1533. sum: 1000
  1534. }).then(function (response) {
  1535. if (response.status == 200) {
  1536. $scope.places = response.list;
  1537. }
  1538. })
  1539. }
  1540. //地点搜索
  1541. $scope.refresh = function (searchVal) {
  1542. var faildata = {};
  1543. if ($scope.requesterAreaid) {
  1544. faildata = {
  1545. 'idx': 0,
  1546. 'sum': 1000,
  1547. 'place': {
  1548. 'areaId': $scope.requesterAreaid,
  1549. 'place': searchVal,
  1550. 'selectType': 'pinyin_qs'
  1551. }
  1552. }
  1553. } else {
  1554. faildata = {
  1555. 'idx': 0,
  1556. 'sum': 1000,
  1557. 'place': {
  1558. 'place': searchVal,
  1559. 'selectType': 'pinyin_qs'
  1560. }
  1561. }
  1562. }
  1563. api_user_data.fetchDataList('place', faildata).then(function (response) {
  1564. $scope.places = response.list;
  1565. delete $scope.requester.place;
  1566. })
  1567. }
  1568. $scope.requester = {
  1569. 'telephone': jry_findPhone
  1570. };
  1571. $scope.ok = function () {
  1572. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  1573. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  1574. var flag1 = reg1.test($scope.requester.mphone);
  1575. var flag2 = reg2.test($scope.requester.mphone);
  1576. console.log($scope.requester)
  1577. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1578. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1579. } else if (angular.isUndefined($scope.requester.requesterType)) {
  1580. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  1581. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1582. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1583. }
  1584. else {
  1585. // $modalInstance.close($scope.requester);
  1586. $scope.selectedItemTodo($scope.requester);
  1587. }
  1588. };
  1589. $scope.selectedItemTodo = function(selectedItem){
  1590. if (selectedItem) {
  1591. if (selectedItem.telephone && !selectedItem.mphone) {
  1592. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1593. delete selectedItem.mphone;
  1594. }
  1595. var data = {
  1596. 'requester': selectedItem
  1597. };
  1598. api_user_data.addData('requester', data).then(function (response) {
  1599. if (response.status == 200) {
  1600. $modalInstance.dismiss("ok");
  1601. var data = {
  1602. 'model': {
  1603. 'requestershow': response.data,
  1604. 'incident': {
  1605. 'requester': response.data,
  1606. 'area': response.data.place?response.data.place.area:undefined,
  1607. 'place': response.data.place,
  1608. 'houseNumber': response.data.houseNumber,
  1609. 'callID': cdrid,
  1610. 'contacts':response.data.name,
  1611. 'contactsInformation': response.data.telephone,
  1612. 'source': {
  1613. 'id': 1547
  1614. }
  1615. }
  1616. }
  1617. }
  1618. $state.go('app.incident.title', {
  1619. 'model': JSON.stringify(data)
  1620. });
  1621. }else{
  1622. modalInstance.SweetAlert.swal({
  1623. title: "系统错误",
  1624. text: "账号重复!",
  1625. type: "error",
  1626. });
  1627. }
  1628. })
  1629. }
  1630. }
  1631. $scope.cancel = function () {
  1632. $modalInstance.dismiss('cancel');
  1633. };
  1634. },
  1635. });
  1636. // modalInstance.result.then(function (selectedItem) {
  1637. // if (selectedItem) {
  1638. // if (selectedItem.telephone && !selectedItem.mphone) {
  1639. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  1640. // delete selectedItem.mphone;
  1641. // }
  1642. // var data = {
  1643. // 'requester': selectedItem
  1644. // };
  1645. // api_user_data.addData('requester', data).then(function (response) {
  1646. // if (response.status == 200) {
  1647. // var data = {
  1648. // 'model': {
  1649. // 'requestershow': response.data,
  1650. // 'incident': {
  1651. // 'requester': response.data,
  1652. // 'area': response.data.place?response.data.place.area:undefined,
  1653. // 'place': response.data.place,
  1654. // 'houseNumber': response.data.houseNumber,
  1655. // 'callID': cdrid,
  1656. // 'contacts':response.data.name,
  1657. // 'contactsInformation': response.data.telephone,
  1658. // 'source': {
  1659. // 'id': 1547
  1660. // }
  1661. // }
  1662. // }
  1663. // }
  1664. // $state.go('app.incident.title', {
  1665. // 'model': JSON.stringify(data)
  1666. // });
  1667. // }else{
  1668. // modalInstance.SweetAlert.swal({
  1669. // title: "系统错误",
  1670. // text: "账号重复!",
  1671. // type: "error",
  1672. // });
  1673. // }
  1674. // })
  1675. // }
  1676. // });
  1677. } else if (myData.list.length == 1) {
  1678. var data = {
  1679. 'model': {
  1680. 'requestershow': myData.list[0],
  1681. 'incident': {
  1682. 'requester': myData.list[0],
  1683. 'area': myData.list[0].place?myData.list[0].place.area:undefined,
  1684. 'place': myData.list[0].place,
  1685. 'houseNumber': myData.list[0].houseNumber,
  1686. 'callID': cdrid,
  1687. 'contacts':myData.list[0].name,
  1688. 'contactsInformation': myData.list[0].telephone,
  1689. 'source': {
  1690. 'id': 1547
  1691. }
  1692. }
  1693. }
  1694. }
  1695. $state.go('app.incident.title', {
  1696. 'model': JSON.stringify(data)
  1697. });
  1698. } else {
  1699. var modalInstance = $modal.open({
  1700. templateUrl: 'assets/views/createincident.html',
  1701. controller: function ($scope, $modalInstance, api_user_data) {
  1702. $scope.title = "请确定报修人";
  1703. $scope.requester = myData.list;
  1704. $scope.choice = function (requester) {
  1705. $modalInstance.dismiss('cancel');
  1706. var data = {
  1707. 'model': {
  1708. 'requestershow': requester,
  1709. 'incident': {
  1710. 'requester': requester,
  1711. 'area': requester.place?requester.place.area:undefined,
  1712. 'place': requester.place,
  1713. 'houseNumber': requester.houseNumber,
  1714. 'callID': cdrid,
  1715. 'contacts':requester.name,
  1716. 'contactsInformation': requester.telephone,
  1717. 'source': {
  1718. 'id': 1547
  1719. }
  1720. }
  1721. }
  1722. }
  1723. $state.go('app.incident.title', {
  1724. 'model': JSON.stringify(data)
  1725. });
  1726. };
  1727. $scope.cancel = function () {
  1728. $modalInstance.dismiss('cancel');
  1729. };
  1730. },
  1731. size: "lg"
  1732. });
  1733. }
  1734. });
  1735. }
  1736. // 挂机
  1737. } else if (phoneData.state == "login") {
  1738. go_ready()
  1739. } else if (phoneData.state == "logout") {
  1740. $rootScope.jry_state = "weiqianru";
  1741. } else if (phoneData.state == "ready") {
  1742. // 来电挂机
  1743. if (phoneData.old_state == "busy" && phoneData.private_data == "answered") {
  1744. go_break()
  1745. } else {
  1746. $rootScope.jry_state = "shixian";
  1747. }
  1748. }
  1749. // else if (data.old_state == "busy") {
  1750. // }
  1751. } else if (phoneData.event_type == "agent_caller_state") {
  1752. // special feature, never mind
  1753. if (phoneData.action == "in") {
  1754. } else {
  1755. }
  1756. } else if (phoneData.event_type == "command/reply") {
  1757. if (phoneData.phoneData && phoneData.phoneData.state) {
  1758. }
  1759. }
  1760. }
  1761. function onConnect() {
  1762. console.log("websocket connected!");
  1763. // ola._extn = ola_extn;
  1764. // ola.subscribe('ola.queue.' + ola_queue + '.' + ola_extn);
  1765. // ola.subscribe('ola.caller.' + ola_extn);
  1766. // ola.get_agent_state(ola_extn);
  1767. ola._extn = $rootScope.jry_extnNumberObj.jry_extnNumber.name;
  1768. ola.subscribe('ola.queue.' + ola_queue + '.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1769. ola.subscribe('ola.caller.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1770. ola.get_agent_state($rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1771. };
  1772. function onClose() {
  1773. }
  1774. function login() {
  1775. // ola.login(ola_queue, ola_extn, {type: "onhook"});
  1776. console.log($rootScope.jry_extnNumberObj.jry_extnNumber);
  1777. ola.login(ola_queue, $rootScope.jry_extnNumberObj.jry_extnNumber.name, { type: "onhook" });
  1778. }
  1779. function logout() {
  1780. ola.logout();
  1781. }
  1782. function go_ready() {
  1783. ola.go_ready();
  1784. }
  1785. function go_break() {
  1786. ola.go_break($('#break_reason').val());
  1787. $rootScope.jry_state = "shimang";
  1788. }
  1789. function answer() {
  1790. ola.answer();
  1791. }
  1792. function dial(dst) {
  1793. ola.dial(dst);
  1794. }
  1795. $rootScope.dial = function (dst) {
  1796. ola.dial(dst);
  1797. }
  1798. function conference(dst) {
  1799. ola.conference(dst);
  1800. }
  1801. function conference_uuid(channel_uuid) {
  1802. ola.conference_uuid(channel_uuid);
  1803. }
  1804. function hangup() {
  1805. ola.hangup();
  1806. }
  1807. function take_call(uuid) {
  1808. // ola.take_call(ola_extn, uuid);
  1809. ola.take_call($rootScope.jry_extnNumberObj.jry_extnNumber.name, uuid);
  1810. }
  1811. // 签入
  1812. $rootScope.jry_qianru = function () {
  1813. login();
  1814. }
  1815. // 示闲
  1816. $rootScope.jry_shixian = function () {
  1817. go_ready()
  1818. }
  1819. // 示忙
  1820. $rootScope.jry_shimang = function () {
  1821. go_break()
  1822. }
  1823. // 签出
  1824. $rootScope.jry_qianchu = function () {
  1825. logout()
  1826. }
  1827. $rootScope.jry_bohao = function (res) {
  1828. if ($rootScope.jry_state == "weiqianru") {
  1829. // SweetAlert.swal({
  1830. // title: "拨打失败",
  1831. // text: "请先签入!",
  1832. // type: "error",
  1833. // confirmButtonColor: "#DD6B55"
  1834. // });
  1835. } else if ($rootScope.jry_state == "shimang") {
  1836. // SweetAlert.swal({
  1837. // title: "拨打失败",
  1838. // text: "请先示闲!",
  1839. // type: "error",
  1840. // confirmButtonColor: "#DD6B55"
  1841. // });
  1842. } else {
  1843. dial(res);
  1844. }
  1845. }
  1846. })
  1847. }
  1848. // ------------------------------2--------------------------
  1849. $rootScope.getExtnDirect2 = function () {
  1850. var jry_data_dictionary = {
  1851. key: "hjzx_cornet",
  1852. type: "list"
  1853. }
  1854. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1855. sessionStorage.setItem('phones',JSON.stringify(res.map(v=>v.name)));
  1856. var websocket_url = $rootScope.seiminCallIp;
  1857. $rootScope.jry_extnNumberSelect = [];
  1858. $rootScope.jry_extnNumberObj = {};
  1859. $rootScope.jry_extnNumberSelect = angular.copy(res);
  1860. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1861. var fenjiNumber = localStorage.getItem('fenjiNumber');
  1862. if(fenjiNumber){
  1863. $rootScope.jry_extnNumberSelect.forEach(ress=>{
  1864. if(ress.name == fenjiNumber){
  1865. $rootScope.jry_extnNumberObj.jry_extnNumber = ress;
  1866. }
  1867. })
  1868. }
  1869. // $rootScope.jry_extnNumberObj.jry_extnNumber = angular.copy(res[0]);//绑定分机对象
  1870. // $rootScope.jry_extnNumberObj.tel1 = angular.copy(res[0]);//目的号码对象
  1871. // $rootScope.jry_extnNumberObj.tel2 = angular.copy(res[0]);//转接坐席对象
  1872. $rootScope.preState = '';//最近一次示忙还是示闲的状态
  1873. //连接
  1874. tlwsa.tlaOpen(websocket_url);
  1875. // 强制示忙
  1876. $scope.qShimang = function(state){
  1877. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1878. //进入页面,强制示忙
  1879. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1880. setTimeout(()=>{
  1881. tlwsa.tlaAcw();
  1882. },0)
  1883. }else{
  1884. $scope.getState(state);
  1885. }
  1886. }
  1887. // 获取状态
  1888. $scope.getState = function (state) {
  1889. // if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1890. // if(state != 2&&state != 0){
  1891. // //进入页面,强制示忙
  1892. // // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1893. // setTimeout(()=>{
  1894. // tlwsa.tlaAcw();
  1895. // },3000)
  1896. // }
  1897. // }
  1898. // var agcount = tlwsa.tlaGetagentcount();
  1899. // var flag = true;
  1900. // for (var i = 0; i < agcount; i++) {
  1901. // if (tlwsa.tlaGetagentwid(i) == $rootScope.phoneNumber) {
  1902. // flag = false;
  1903. // var state = Number(tlwsa.tlaGetagentstate(i));
  1904. // console.log(state);
  1905. switch (state) {
  1906. case 0:
  1907. $rootScope.jry_state = 'weiqianru';
  1908. break;
  1909. case 1:
  1910. $rootScope.jry_state = 'shixian';
  1911. break;
  1912. case 2:
  1913. $rootScope.jry_state = 'shimang';
  1914. break;
  1915. case 3:
  1916. $rootScope.jry_state = 'laidian';
  1917. break;
  1918. case 5:
  1919. $rootScope.jry_state = 'tonghuazhong';
  1920. break;
  1921. case 6:
  1922. $rootScope.jry_state = 'zhengzaiwaihu';
  1923. break;
  1924. case 7:
  1925. $rootScope.jry_state = 'zhengzaizhuanyi';
  1926. break;
  1927. }
  1928. // }
  1929. // console.log('agnet No. ' + i + ' workid is ' + tlwsa.tlaGetagentwid(i) + ' state is ' + tlwsa.tlaGetagentstate(i) + ' ' + getStateInfo(tlwsa.tlaGetagentstate(i)))
  1930. // }
  1931. // if (flag) {
  1932. // $rootScope.jry_state = 'weiqianru';
  1933. // }
  1934. }
  1935. // 状态回调函数
  1936. // TLWSA.onStatechange = onstatechange;
  1937. // function onstatechange() {
  1938. // console.log('事件:状态变化----------------------------------------------------');
  1939. // $scope.getState();
  1940. // }
  1941. //连接呼叫中心回调函数
  1942. TLWSA.onOpenreturn = onopenreturn;
  1943. function onopenreturn(err) {
  1944. err = Number(err);
  1945. if (!err) {
  1946. console.log('呼叫中心连接成功-----seimin');
  1947. $scope.getState(0);
  1948. $.toaster({
  1949. priority: 'info',
  1950. title: '操作',
  1951. message: '呼叫中心连接成功'
  1952. });
  1953. //如果设置过话机
  1954. if (localStorage.getItem('phoneNumber')) {
  1955. //强制签出,然后签入
  1956. tlwsa.tlaKillworkid(localStorage.getItem('phoneNumber'));
  1957. }
  1958. } else {
  1959. console.log('呼叫中心连接失败-----seimin');
  1960. $scope.getState(0);
  1961. $.toaster({
  1962. priority: 'info',
  1963. title: '操作',
  1964. message: '呼叫中心连接失败'
  1965. });
  1966. }
  1967. }
  1968. //绑定分机回调函数
  1969. TLWSA.onSetphonenumberreturn = onsetphonenumberreturn;
  1970. function onsetphonenumberreturn(err) {
  1971. err = Number(err);
  1972. if (!err) {
  1973. console.log('绑定分机成功-----seimin');
  1974. $.toaster({
  1975. priority: 'info',
  1976. title: '操作',
  1977. message: '绑定分机成功'
  1978. });
  1979. localStorage.setItem('phoneNumber', $rootScope.phoneNumber);
  1980. localStorage.setItem('fenjiNumber', $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1981. $scope.qShimang(1);
  1982. } else {
  1983. console.log('绑定分机失败-----seimin');
  1984. $scope.getState(0);
  1985. $.toaster({
  1986. priority: 'info',
  1987. title: '操作',
  1988. message: '绑定分机失败'
  1989. });
  1990. }
  1991. }
  1992. //强制示忙回调函数
  1993. // TLWSA.onAcw = onacw;
  1994. // function onacw(err) {
  1995. // err = Number(err);
  1996. // if (!err) {
  1997. // console.log('强制示忙成功-----seimin');
  1998. // $scope.getState(2);
  1999. // $.toaster({
  2000. // priority: 'info',
  2001. // title: '操作',
  2002. // message: '示忙成功'
  2003. // });
  2004. // } else {
  2005. // console.log('强制示忙失败-----seimin');
  2006. // $.toaster({
  2007. // priority: 'info',
  2008. // title: '操作',
  2009. // message: '示忙失败'
  2010. // });
  2011. // }
  2012. // }
  2013. // //强制示闲回调函数
  2014. // TLWSA.onWca = onwca;
  2015. // function onwca(err) {
  2016. // console.log(err)
  2017. // err = Number(err);
  2018. // if (!err) {
  2019. // console.log('强制示闲成功-----seimin');
  2020. // $scope.getState(1);
  2021. // $.toaster({
  2022. // priority: 'info',
  2023. // title: '操作',
  2024. // message: '示闲成功'
  2025. // });
  2026. // } else {
  2027. // console.log('强制示闲失败-----seimin');
  2028. // $.toaster({
  2029. // priority: 'info',
  2030. // title: '操作',
  2031. // message: '示闲失败'
  2032. // });
  2033. // }
  2034. // }
  2035. //与服务器网络连接中断回调函数
  2036. TLWSA.onClosed = onclosed;
  2037. function onclosed() {
  2038. $scope.getState(0);
  2039. console.log('与服务器网络连接中断-----seimin');
  2040. $.toaster({
  2041. priority: 'info',
  2042. title: '操作',
  2043. message: '与服务器网络连接中断,2分钟后重连'
  2044. });
  2045. console.log('2分钟后自动重连-----seimin')
  2046. $timeout(function () {
  2047. //连接
  2048. tlwsa.tlaOpen(websocket_url);
  2049. }, 120000)
  2050. }
  2051. //签入回调函数
  2052. TLWSA.onLoginreturn = onloginreturn;
  2053. function onloginreturn(err) {
  2054. err = Number(err);
  2055. if (!err) {
  2056. console.log('签入成功-----seimin');
  2057. $.toaster({
  2058. priority: 'info',
  2059. title: '操作',
  2060. message: '签入成功'
  2061. });
  2062. setTimeout(function () {
  2063. console.log($rootScope.jry_extnNumberObj.jry_extnNumber.name,1111)
  2064. var fenjiNumber = $rootScope.jry_extnNumberObj.jry_extnNumber.name || localStorage.getItem('fenjiNumber');
  2065. console.log('开始绑定分机【' + fenjiNumber + '】-----seimin');
  2066. tlwsa.tlaSetphonenumber(fenjiNumber);
  2067. }, 0)
  2068. } else if (err == 9011) {
  2069. console.log('签入失败,该分机已登录-----seimin');
  2070. $.toaster({
  2071. priority: 'info',
  2072. title: '操作',
  2073. message: '签入失败,该分机已登录'
  2074. });
  2075. } else {
  2076. console.log('签入失败-----seimin');
  2077. $.toaster({
  2078. priority: 'info',
  2079. title: '操作',
  2080. message: '签入失败'
  2081. });
  2082. }
  2083. // tlwsa.tlaSubscribestateinfo(2);
  2084. }
  2085. // 强制签出回调函数
  2086. TLWSA.onKillreturn = onkillreturn;
  2087. function onkillreturn(err) {
  2088. err = Number(err);
  2089. if (!err) {
  2090. console.log('强制签出成功-----seimin');
  2091. $scope.getState(0);
  2092. // $.toaster({
  2093. // priority: 'info',
  2094. // title: '操作',
  2095. // message: '强制签出成功'
  2096. // });
  2097. } else {
  2098. console.log('强制签出失败,该分机不是签入状态-----seimin');
  2099. // $.toaster({
  2100. // priority: 'info',
  2101. // title: '操作',
  2102. // message: '强制签出失败'
  2103. // });
  2104. }
  2105. //如果设置过话机
  2106. if (localStorage.getItem('phoneNumber')) {
  2107. // 签入并绑定分机
  2108. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  2109. tlwsa.tlaLogin($rootScope.phoneNumber, 1, -1);
  2110. }
  2111. }
  2112. // 签出回调函数
  2113. TLWSA.onLogoffreturn = onlogoffreturn;
  2114. function onlogoffreturn(err) {
  2115. err = Number(err);
  2116. if (!err) {
  2117. console.log('签出成功-----seimin');
  2118. $scope.getState(0);
  2119. $.toaster({
  2120. priority: 'info',
  2121. title: '操作',
  2122. message: '签出成功'
  2123. });
  2124. localStorage.removeItem('phoneNumber');
  2125. localStorage.removeItem('fenjiNumber');
  2126. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  2127. } else {
  2128. console.log('签出失败-----seimin');
  2129. $.toaster({
  2130. priority: 'info',
  2131. title: '操作',
  2132. message: '签出失败'
  2133. });
  2134. }
  2135. }
  2136. //示忙回调函数
  2137. TLWSA.onAcwreturn = onacwreturn;
  2138. function onacwreturn(err) {
  2139. err = Number(err);
  2140. if (!err) {
  2141. console.log('示忙成功-----seimin');
  2142. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  2143. $scope.isShixian = false;
  2144. }else{
  2145. $scope.isShixian = true;
  2146. }
  2147. $scope.getState(2);
  2148. $rootScope.preState = 2;
  2149. $.toaster({
  2150. priority: 'info',
  2151. title: '操作',
  2152. message: '示忙成功'
  2153. });
  2154. } else {
  2155. console.log('示忙失败-----seimin');
  2156. // $.toaster({
  2157. // priority: 'info',
  2158. // title: '操作',
  2159. // message: '示忙失败'
  2160. // });
  2161. }
  2162. }
  2163. //示闲回调函数
  2164. TLWSA.onWcareturn = onwcareturn;
  2165. function onwcareturn(err) {
  2166. err = Number(err);
  2167. if (!err) {
  2168. console.log('示闲成功-----seimin');
  2169. $scope.getState(1);
  2170. $rootScope.preState = 1;
  2171. $.toaster({
  2172. priority: 'info',
  2173. title: '操作',
  2174. message: '示闲成功'
  2175. });
  2176. } else {
  2177. console.log('示闲失败-----seimin');
  2178. $.toaster({
  2179. priority: 'info',
  2180. title: '操作',
  2181. message: '示闲失败'
  2182. });
  2183. }
  2184. }
  2185. //呼叫坐席回调函数
  2186. TLWSA.onCallreturn = oncallreturn;
  2187. function oncallreturn(err) {
  2188. err = Number(err);
  2189. if (!err) {
  2190. console.log('呼叫成功,请摘机-----seimin');
  2191. $scope.getState(6);
  2192. $.toaster({
  2193. priority: 'info',
  2194. title: '操作',
  2195. message: '呼叫成功,请摘机'
  2196. });
  2197. } else {
  2198. console.log('呼叫失败-----seimin');
  2199. $.toaster({
  2200. priority: 'info',
  2201. title: '操作',
  2202. message: '呼叫失败'
  2203. });
  2204. }
  2205. }
  2206. //呼叫坐席被接听回调函数
  2207. TLWSA.onCallresult = oncallresult;
  2208. function oncallresult(jso) {
  2209. console.log(jso);
  2210. var err = Number(jso.err);
  2211. if (!err) {
  2212. console.log('呼叫被接听成功-----seimin');
  2213. $scope.getState(5);
  2214. $.toaster({
  2215. priority: 'info',
  2216. title: '操作',
  2217. message: '呼叫被接听成功'
  2218. });
  2219. } else {
  2220. console.log('呼叫被接听失败-----seimin');
  2221. $scope.qShimang(1);
  2222. $.toaster({
  2223. priority: 'info',
  2224. title: '操作',
  2225. message: '呼叫被接听失败'
  2226. });
  2227. }
  2228. }
  2229. //挂断回调函数
  2230. TLWSA.onCallend = oncallend;
  2231. function oncallend(jso) {
  2232. console.log(jso);//lmm
  2233. if (jso) {
  2234. console.log('挂断成功-----seimin');
  2235. console.log('最近一次话机状态',$rootScope.preState);
  2236. $scope.qShimang($rootScope.preState);
  2237. $.toaster({
  2238. priority: 'info',
  2239. title: '操作',
  2240. message: '挂断成功'
  2241. });
  2242. } else {
  2243. console.log('挂断失败-----seimin');
  2244. $.toaster({
  2245. priority: 'info',
  2246. title: '操作',
  2247. message: '挂断失败'
  2248. });
  2249. }
  2250. }
  2251. //呼入回调函数
  2252. TLWSA.onCallin = oncallin;
  2253. function oncallin(jso) {
  2254. console.log(jso);//lmm
  2255. $rootScope.callInPhoneNumber = jso.caller;//来电的电话
  2256. $rootScope.sockid = jso.crs;//来电的话机id
  2257. if (jso) {
  2258. console.log('呼入坐席成功,请摘机-----seimin');
  2259. $scope.getState(3);
  2260. $.toaster({
  2261. priority: 'info',
  2262. title: '操作',
  2263. message: '呼入坐席成功,请摘机'
  2264. });
  2265. console.log('来电了!电话号码是【' + $rootScope.callInPhoneNumber + '】');
  2266. } else {
  2267. console.log('呼入坐席失败-----seimin');
  2268. $.toaster({
  2269. priority: 'info',
  2270. title: '操作',
  2271. message: '呼入坐席失败'
  2272. });
  2273. }
  2274. }
  2275. //呼入摘机应答回调函数
  2276. TLWSA.onAnswer = onanswer;
  2277. function onanswer(err) {
  2278. err = Number(err);
  2279. if (!err) {
  2280. console.log('呼入摘机应答成功-----seimin');
  2281. $scope.getState(5);
  2282. $.toaster({
  2283. priority: 'info',
  2284. title: '操作',
  2285. message: '呼入摘机应答成功'
  2286. });
  2287. //根据电话号码反查报修人,如果是坐席号码,则不用
  2288. // console.log(sessionStorage.getItem('phones'));
  2289. // var phones = JSON.parse(sessionStorage.getItem('phones'));
  2290. // var isHuajihao = phones.length?phones.some(v=>v == teleno):false;
  2291. // if(isHuajihao){
  2292. // return;
  2293. // }
  2294. var postData = { "idx": 0, "sum": 10, "requester": { hjzxPhone: $rootScope.callInPhoneNumber } };
  2295. api_user_data.fetchDataList('requester', postData).then(function (result) {
  2296. if (result.status == 200) {
  2297. console.log(result.list);
  2298. var requesters = result.list;
  2299. if (requesters.length === 0) {
  2300. //未匹配到报修人,则弹窗添加报修人yeye
  2301. $state.go('app.incident.chart', {
  2302. model: JSON.stringify({
  2303. model: {
  2304. incident: {
  2305. requester: {
  2306. hjzxPhone: $rootScope.callInPhoneNumber
  2307. },
  2308. sockid: $rootScope.sockid
  2309. }
  2310. }
  2311. })
  2312. });
  2313. } else if (requesters.length === 1) {
  2314. //匹配到一个报修人
  2315. $state.go('app.incident.chart', {
  2316. model: JSON.stringify({
  2317. model: {
  2318. incident: {
  2319. requester: requesters[0],
  2320. contactsInformation: requesters[0].mphone,
  2321. sockid: $rootScope.sockid
  2322. },
  2323. }
  2324. })
  2325. });
  2326. } else {
  2327. //匹配到多个报修人
  2328. $modal.open({
  2329. templateUrl: 'assets/views/incident/tpl/tel.html',
  2330. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  2331. $scope.list = requesters;
  2332. $scope.selectedItem = 0;
  2333. $scope.cancel = function () {
  2334. $modalInstance.dismiss('cancel');
  2335. };
  2336. $scope.changeBxr = function (id) {
  2337. $scope.selectedItem = id;
  2338. }
  2339. $scope.save = function () {
  2340. var item = $scope.list.find(v => v.id == $scope.selectedItem);
  2341. if (item) {
  2342. $scope.cancel();
  2343. $state.go('app.incident.chart', {
  2344. model: JSON.stringify({
  2345. model: {
  2346. incident: {
  2347. requester: item,
  2348. contactsInformation: item.mphone,
  2349. sockid: $rootScope.sockid
  2350. },
  2351. }
  2352. })
  2353. });
  2354. } else {
  2355. SweetAlert.swal({
  2356. title: "请选择报修人!",
  2357. type: "error"
  2358. })
  2359. }
  2360. }
  2361. }
  2362. });
  2363. }
  2364. }
  2365. })
  2366. } else {
  2367. console.log('呼入摘机应答失败-----seimin');
  2368. $.toaster({
  2369. priority: 'info',
  2370. title: '操作',
  2371. message: '呼入摘机应答失败'
  2372. });
  2373. }
  2374. }
  2375. //呼入未摘机应答回调函数
  2376. TLWSA.onMisscall = onmisscall;
  2377. function onmisscall(err) {
  2378. err = Number(err);
  2379. if (!err) {
  2380. console.log('呼入未摘机应答成功-----seimin');
  2381. $scope.getState(1);
  2382. $.toaster({
  2383. priority: 'info',
  2384. title: '操作',
  2385. message: '呼入未摘机应答成功'
  2386. });
  2387. } else {
  2388. console.log('呼入未摘机应答失败-----seimin');
  2389. $.toaster({
  2390. priority: 'info',
  2391. title: '操作',
  2392. message: '呼入未摘机应答失败'
  2393. });
  2394. }
  2395. }
  2396. //转接开始回调函数
  2397. TLWSA.onTransferreturn = ontransferreturn;//调用转移方法之后,返回该事件 如果错误码为0,仅仅表示开始转移,不代表转移目标已经接听或已经拒绝
  2398. function ontransferreturn(err) {
  2399. err = Number(err);
  2400. if (!err) {
  2401. console.log('转接坐席开始成功-----seimin');
  2402. $scope.getState(7);
  2403. $.toaster({
  2404. priority: 'info',
  2405. title: '操作',
  2406. message: '转接坐席开始成功'
  2407. });
  2408. } else {
  2409. console.log('转接坐席开始失败-----seimin');
  2410. $.toaster({
  2411. priority: 'info',
  2412. title: '操作',
  2413. message: '转接坐席开始失败'
  2414. });
  2415. }
  2416. }
  2417. //转接结果回调函数
  2418. TLWSA.onTransferresult = ontransferresult;
  2419. function ontransferresult(err) {
  2420. err = Number(err);
  2421. if (!err) {
  2422. console.log('转接坐席结果成功-----seimin');
  2423. $scope.getState(1);
  2424. $.toaster({
  2425. priority: 'info',
  2426. title: '操作',
  2427. message: '转接坐席结果成功'
  2428. });
  2429. } else {
  2430. console.log('转接坐席结果失败-----seimin');
  2431. $.toaster({
  2432. priority: 'info',
  2433. title: '操作',
  2434. message: '转接坐席结果失败'
  2435. });
  2436. }
  2437. }
  2438. // 签入
  2439. $rootScope.jry_qianru = function () {
  2440. console.log($rootScope.jry_extnNumberObj.jry_extnNumber)
  2441. if(Object.keys($rootScope.jry_extnNumberObj.jry_extnNumber).length === 0){
  2442. $.toaster({
  2443. priority: 'info',
  2444. title: '警告',
  2445. message: '绑定分机不能为空'
  2446. });
  2447. return;
  2448. }
  2449. // 签入并绑定分机
  2450. // $rootScope.jry_extnNumberObj.jry_extnNumber.name 分机号
  2451. // $rootScope.user.id 坐席号(用户id)
  2452. tlwsa.tlaLogin($rootScope.user.id, 1, -1);
  2453. $rootScope.phoneNumber = $rootScope.user.id;
  2454. }
  2455. // 示闲
  2456. $rootScope.jry_shixian = function () {
  2457. tlwsa.tlaWca();
  2458. }
  2459. // 示忙
  2460. $rootScope.jry_shimang = function () {
  2461. tlwsa.tlaAcw();
  2462. }
  2463. // 签出
  2464. $rootScope.jry_qianchu = function () {
  2465. tlwsa.tlaLogoff();
  2466. }
  2467. // 呼叫坐席
  2468. // $scope.tlaCallagc = function () {
  2469. // tlwsa.tlaCallagc($rootScope.jry_extnNumberObj.tel1)
  2470. // }
  2471. // 呼叫外线
  2472. $scope.tlaCallout = function () {
  2473. // 选择目的号码
  2474. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2475. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2476. if(!reg1.test($rootScope.jry_extnNumberObj.tel1)&&!reg2.test($rootScope.jry_extnNumberObj.tel1)){
  2477. $.toaster({
  2478. priority: 'info',
  2479. title: '警告',
  2480. message: '请输入正确的手机号或座机号'
  2481. });
  2482. return;
  2483. }
  2484. tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2485. }
  2486. // // 转移坐席
  2487. // $scope.tlaTransfertoagc = function () {
  2488. // tlwsa.tlaTransfertoagc($rootScope.jry_extnNumberObj.tel2)
  2489. // }
  2490. // 转移外线
  2491. $scope.tlaTransferout = function () {
  2492. // 选择转接号码
  2493. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2494. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2495. if(!reg1.test($rootScope.jry_extnNumberObj.tel2)&&!reg2.test($rootScope.jry_extnNumberObj.tel2)){
  2496. $.toaster({
  2497. priority: 'info',
  2498. title: '警告',
  2499. message: '请输入正确的手机号或座机号'
  2500. });
  2501. return;
  2502. }
  2503. tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2504. }
  2505. })
  2506. }
  2507. $rootScope.getExtnDirect3 = function(){
  2508. console.log($rootScope.user)
  2509. var user = $rootScope.user;
  2510. initImUser(user.email, user.msgUuid);
  2511. // $rootScope.start(JSON.parse(localStorage.userdata).commonExtension.name);
  2512. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function(data) {
  2513. $scope.runNumber = data;
  2514. $scope.phone = $scope.runNumber[0].name;
  2515. $rootScope.phoneChange($scope.phone);
  2516. })
  2517. if ($rootScope.userMenus.length == 0) {
  2518. getMenus();
  2519. }
  2520. if(localStorage.getItem('hk_phone')){
  2521. $rootScope.start(localStorage.getItem('hk_phone'));
  2522. }
  2523. }
  2524. $rootScope.jry_state = 'weiqianru';
  2525. window.addEventListener('load', function () {
  2526. if ($rootScope.isFuwutai) {
  2527. $rootScope.getExtnDirect();//seiminHj----1
  2528. }
  2529. })
  2530. //话机呼叫中心--结束
  2531. // 未接来电
  2532. $scope.jry_getUnanswered = function () {
  2533. var jry_data = {
  2534. idx: 0,
  2535. sum: 999,
  2536. "callRecord": {
  2537. "todayTime": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 00:00:00",
  2538. "todayTimeEnd": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 23:59:59",
  2539. }
  2540. }
  2541. api_bpm_data.fetchDataList("callRecord", jry_data).then(function (data) {
  2542. // fo0h
  2543. for (var i = 0; i < data.list.length; i++) {
  2544. 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()
  2545. }
  2546. $rootScope.jry_unansweredData = data.list;
  2547. });
  2548. }
  2549. // $scope.jry_getUnanswered();
  2550. // 来电号码回拨
  2551. $scope.jry_callBack = function (data) {
  2552. var callBackData = {
  2553. "callRecord": {
  2554. "id": data.id,
  2555. "isAnswered": "1"
  2556. }
  2557. };
  2558. api_bpm_data.updData("callRecord", callBackData).then(function (res) {
  2559. if (res) {
  2560. $scope.jry_getUnanswered();
  2561. dial(data.callerIdNumber)
  2562. }
  2563. });
  2564. if (data.department.id && data.requester) {
  2565. 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 } }
  2566. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2567. } else if (data.department.id) {
  2568. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2569. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2570. } else {
  2571. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2572. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2573. };
  2574. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  2575. }
  2576. //来电号码生成事件
  2577. $scope.jry_callToIncident = function (data) {
  2578. if (data.department.id && data.requester) {
  2579. 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 } }
  2580. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2581. } else if (data.department.id) {
  2582. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2583. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2584. } else {
  2585. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2586. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2587. }
  2588. }
  2589. $scope.onChangeadd = function (searchData) {
  2590. $scope.searchKey = searchData.account;
  2591. // $scope.searchDataadd = searchData;
  2592. var requesdata = angular.copy(searchData)
  2593. $scope.requester = requesdata;
  2594. }
  2595. $scope.refreshUseradd = function (searchKey) { //主题搜索
  2596. $scope.searchData = searchKey;
  2597. reashdata($scope.searchData);
  2598. }
  2599. $scope.getMydata = function (x) {
  2600. $scope.telephone = JSON.parse(x).phone;
  2601. $scope.searchField = $scope.telephone;
  2602. return $scope.searchField;
  2603. }
  2604. $scope.getMydataone = function (x) {
  2605. $scope.telephone = x;
  2606. $scope.searchField = $scope.telephone;
  2607. }
  2608. $scope.fildata = {
  2609. "idx": 0,
  2610. "sum": 10,
  2611. "flag": -1
  2612. }
  2613. function reashdata(item) {
  2614. if (item && item != "") {
  2615. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  2616. } else {
  2617. delete $scope.fildata.user;
  2618. }
  2619. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  2620. if (data.status == 200) {
  2621. $scope.myData = data.list;
  2622. }
  2623. })
  2624. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  2625. // if (response) {
  2626. // if (response.status = 200) {
  2627. // var myData = response;
  2628. // $scope.myData = myData.list;
  2629. // }
  2630. // }
  2631. // })
  2632. }
  2633. if (window.location && window.location.hash == "#/echart") {
  2634. } else {
  2635. reashdata();
  2636. }
  2637. $rootScope.end = function (callback) {
  2638. $rootScope.isMask = true;
  2639. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  2640. $rootScope.isMask = false;
  2641. if (data.errno == 0) {
  2642. localStorage.removeItem('hk_phone');
  2643. api_text.exit($rootScope.takes).then(function (data) {
  2644. if (data.errno == 0) {
  2645. $rootScope.statuscall = 0;
  2646. $scope.login = false;
  2647. callback();
  2648. // SweetAlert.swal({
  2649. // title: "登出成功",
  2650. // text: "呼叫中心登出成功!",
  2651. // type: "success"
  2652. // });
  2653. // }else{SweetAlert.swal({
  2654. // title: "登出失败",
  2655. // text: "呼叫中心登出失败!",
  2656. // type: "error"
  2657. // });
  2658. }
  2659. })
  2660. }
  2661. })
  2662. }
  2663. $rootScope.dialout = function (gid, teleno) {
  2664. var telephone = "";
  2665. if (teleno && teleno.length > 4) {
  2666. telephone = '9' + teleno;
  2667. } else {
  2668. // telephone = '*01' + teleno + '*';
  2669. telephone = teleno;
  2670. }
  2671. $rootScope.isMask = true;
  2672. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  2673. $rootScope.isMask = false;
  2674. if (data.errno == 0) {
  2675. // $rootScope.statuscall = 3;
  2676. $rootScope.callout = true;
  2677. // $rootScope.phone=teleno;
  2678. }
  2679. })
  2680. }
  2681. // $scope.busy=false;
  2682. $rootScope.setbusy = function (flag) {
  2683. if(!flag){
  2684. $rootScope.isMask = true;
  2685. }
  2686. api_text.setbusy($rootScope.takes).then(function (data) {
  2687. if(!flag){
  2688. $rootScope.isMask = false;
  2689. }
  2690. if (data.errno == 0) {
  2691. $rootScope.statecall = 2;
  2692. $scope.busy = true;
  2693. }else{
  2694. // alert('示忙失败,请在群里反馈!');
  2695. }
  2696. })
  2697. }
  2698. $rootScope.setidle = function (flag) {
  2699. if(!flag){
  2700. $rootScope.isMask = true;
  2701. }
  2702. api_text.setidle($rootScope.takes).then(function (data) {
  2703. if(!flag){
  2704. $rootScope.isMask = false;
  2705. }
  2706. if (data.errno == 0) {
  2707. $rootScope.statecall = 1;
  2708. $scope.busy = false;
  2709. }else{
  2710. // alert('示闲失败,请在群里反馈!');
  2711. }
  2712. })
  2713. }
  2714. $rootScope.inittrans = function (telephone) {
  2715. $rootScope.isMask = true;
  2716. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  2717. $rootScope.isMask = false;
  2718. if (data.errno == 0) {
  2719. // $scope.status=9
  2720. }
  2721. })
  2722. }
  2723. $rootScope.comptrans = function () {
  2724. api_text.comptrans($rootScope.takes).then(function (data) {
  2725. if (data.errno == 0) {
  2726. $rootScope.statuscall = 1;
  2727. }
  2728. })
  2729. }
  2730. $rootScope.takeup = function () {
  2731. api_text.offhook($rootScope.takes).then(function (data) {
  2732. if (data.errno == 0) {
  2733. $rootScope.statuscall = 3;
  2734. }
  2735. })
  2736. }
  2737. $rootScope.takedown = function () {
  2738. api_text.onhook($rootScope.takes).then(function (data) {
  2739. if (data.errno == 0) {
  2740. $rootScope.statuscall = 1;
  2741. }
  2742. })
  2743. }
  2744. $rootScope.saveData = function (selectdata) {
  2745. var modalInstance = $modal.open({
  2746. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  2747. controller: function ($scope, $modalInstance, api_bpm_data) {
  2748. $scope.worktimedata = {};
  2749. $scope.worktimedata = selectdata;
  2750. $scope.cancel = function () {
  2751. $modalInstance.dismiss('cancel');
  2752. };
  2753. $scope.savercode = function (worktimedata) {
  2754. var fildata = {
  2755. "scheduleclass": {
  2756. "id": selectdata.id,
  2757. "code": worktimedata.code,
  2758. "name": worktimedata.title,
  2759. "person": worktimedata.person,
  2760. "description": worktimedata.description,
  2761. "startTime": worktimedata.startTime,
  2762. "endTime": worktimedata.endTime,
  2763. "shiftTime": selectdata.shiftTime,
  2764. "succeedTime": selectdata.succeedTime,
  2765. "isTemplate": worktimedata.isTemplate
  2766. }
  2767. }
  2768. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  2769. if (response) {
  2770. if (response.status == 200) {
  2771. SweetAlert.swal({
  2772. title: "修改成功!",
  2773. type: "success"
  2774. }, function () {
  2775. // $scope.refreshData('expand-right', defaultFilterData);
  2776. })
  2777. } else {
  2778. SweetAlert.swal({
  2779. title: "修改失败!",
  2780. type: "error"
  2781. })
  2782. }
  2783. }
  2784. })
  2785. $modalInstance.close();
  2786. }
  2787. }
  2788. });
  2789. }
  2790. $rootScope.changepassword = function (data1, size) {
  2791. var modalInstance = $modal.open({
  2792. templateUrl: 'assets/views/changepassword.html',
  2793. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  2794. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  2795. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  2796. }
  2797. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  2798. $modalInstance.dismiss('cancel');
  2799. // console.log('pwd=' + pwd + '+' + pwd_2);
  2800. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  2801. if (pwd == pwd_2) {
  2802. var data2 = {};
  2803. data2["originalPwd"] = originalPwd;
  2804. data2["userid"] = $rootScope.user.id;
  2805. data2["pwd"] = pwd;
  2806. api_login.uppwd(data2).then(function (response) {
  2807. var myData = Restangular.stripRestangular(response);
  2808. if (myData.status == 200) {
  2809. SweetAlert.swal({
  2810. title: "保存成功!",
  2811. type: "success",
  2812. confirmButtonColor: "#007AFF"
  2813. });
  2814. } else {
  2815. SweetAlert.swal({
  2816. title: "保存失败!",
  2817. text: "输入旧密码错误,请重新输入!",
  2818. type: "error"
  2819. });
  2820. }
  2821. })
  2822. } else {
  2823. SweetAlert.swal({
  2824. title: "两次输入的新密码不相同!",
  2825. text: "输入错误,请重新输入!",
  2826. type: "error"
  2827. });
  2828. }
  2829. // }else{
  2830. // SweetAlert.swal({
  2831. // title: "密码不能为空!",
  2832. // text: "请输入密码!",
  2833. // type: "error"
  2834. // });
  2835. // }
  2836. }
  2837. },
  2838. size: size,
  2839. resolve: {
  2840. items: function () {
  2841. return {
  2842. fetchItems: function (filterData, APIService) { }
  2843. };
  2844. },
  2845. }
  2846. });
  2847. }
  2848. // $rootScope.getnochildpending = function() {
  2849. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2850. // angular.forEach($rootScope.userMenus, function(item) {
  2851. // item.tipnum = 1;
  2852. // })
  2853. // }
  2854. // }
  2855. // $rootScope.getchildpending = function(cantdata) {
  2856. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2857. // angular.forEach($rootScope.userMenus, function(item) {
  2858. // item.tipnum = 1;
  2859. // angular.forEach(item, function(index) {
  2860. // index.tipnum = 18;
  2861. // })
  2862. // })
  2863. // }
  2864. // }
  2865. $rootScope.getpending = function () {
  2866. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2867. if ($rootScope.user.group) {
  2868. var groupArr = [];
  2869. for (var i = 0; i < $rootScope.user.group.length; i++) {
  2870. groupArr.push($rootScope.user.group[i].id)
  2871. }
  2872. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  2873. angular.forEach($rootScope.userMenus, function (item, i) {
  2874. item.tipshow = false;
  2875. if (response) {
  2876. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  2877. if (item.id == 58) {
  2878. item.tipshow = true;
  2879. }
  2880. }
  2881. if (response.inspectionCount > 0) {
  2882. if (item.id == 27) {
  2883. item.tipshow = true;
  2884. }
  2885. }
  2886. if (response.incidentCount > 0) {
  2887. if (item.id == 2) {
  2888. item.tipshow = true;
  2889. }
  2890. }
  2891. if (response.releaseCount > 0) {
  2892. if (item.id == 1215) {
  2893. item.tipshow = true;
  2894. }
  2895. }
  2896. if (response.solutionCount > 0) {
  2897. if (item.id == 21) {
  2898. item.tipshow = true;
  2899. }
  2900. }
  2901. if (response.changeCount > 0) {
  2902. if (item.id == 1212) {
  2903. item.tipshow = true;
  2904. }
  2905. }
  2906. if (response.problemCount > 0) {
  2907. if (item.id == 1209) {
  2908. item.tipshow = true;
  2909. }
  2910. }
  2911. if (response.applicationForm > 0) {
  2912. if (item.id == 1221) {
  2913. item.tipshow = true;
  2914. }
  2915. }
  2916. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2917. if (item.id == 21) {
  2918. item.tipshow = true;
  2919. }
  2920. }
  2921. if (item.children) {
  2922. angular.forEach(item.children, function (index) {
  2923. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  2924. if (index.id == 1208) {
  2925. if (response.hjzxCount < 100) {
  2926. index.tipnum = response.hjzxCount;
  2927. } else {
  2928. index.tipnum = "99+";
  2929. }
  2930. }
  2931. }
  2932. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  2933. if (index.id == 59) {
  2934. if (response.wechatWarningCount < 100) {
  2935. index.tipnum = response.wechatWarningCount;
  2936. } else {
  2937. index.tipnum = "99+";
  2938. }
  2939. }
  2940. }
  2941. if (response.problemCount !== null && response.problemCount !== undefined) {
  2942. if (index.id == 1210) {
  2943. if (response.problemCount < 100) {
  2944. index.tipnum = response.problemCount;
  2945. } else {
  2946. index.tipnum = "99+";
  2947. }
  2948. }
  2949. }
  2950. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  2951. if (index.id == 1216) {
  2952. if (response.releaseCount < 100) {
  2953. index.tipnum = response.releaseCount;
  2954. } else {
  2955. index.tipnum = "99+";
  2956. }
  2957. }
  2958. }
  2959. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  2960. if (index.id == 147) {
  2961. if (response.inspectionCount < 100) {
  2962. index.tipnum = response.inspectionCount;
  2963. } else {
  2964. index.tipnum = "99+";
  2965. }
  2966. }
  2967. }
  2968. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  2969. if (index.id == 23) {
  2970. if (response.solutionCount < 100) {
  2971. index.tipnum = response.solutionCount;
  2972. } else {
  2973. index.tipnum = "99+";
  2974. }
  2975. }
  2976. }
  2977. if (response.changeCount !== null && response.changeCount !== undefined) {
  2978. if (index.id == 1213) {
  2979. if (response.changeCount < 100) {
  2980. index.tipnum = response.changeCount;
  2981. } else {
  2982. index.tipnum = "99+";
  2983. }
  2984. }
  2985. }
  2986. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  2987. if (index.id == 3) {
  2988. if (response.incidentCount < 100) {
  2989. index.tipnum = response.incidentCount;
  2990. } else {
  2991. index.tipnum = "99+";
  2992. }
  2993. }
  2994. }
  2995. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  2996. if (index.id == 1231) {
  2997. if (response.applicationForm < 100) {
  2998. index.tipnum = response.applicationForm;
  2999. } else {
  3000. index.tipnum = "99+";
  3001. }
  3002. }
  3003. }
  3004. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  3005. if (index.id == 23) {
  3006. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  3007. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  3008. } else {
  3009. index.tipnum = "99+";
  3010. }
  3011. }
  3012. }
  3013. })
  3014. }
  3015. }
  3016. })
  3017. // return $rootScope.userMenus;
  3018. // $scope.recordpending = response.;
  3019. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  3020. })
  3021. } else {
  3022. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  3023. }
  3024. }
  3025. // console.log($rootScope.userMenus);
  3026. }
  3027. $rootScope.userMenus = [];
  3028. var getMenus = function () {
  3029. function convertListToTree(data, treeMap) {
  3030. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  3031. var root = null; //Initially set our loop to null
  3032. var parentNode = null;
  3033. //loop over data
  3034. for (var i = 0; i < data.length; i++) {
  3035. // data[i].id = Number(data[i].id);
  3036. var datum = data[i];
  3037. //each node will have children, so let's give it a "children" poperty
  3038. datum.children = [];
  3039. //add an entry for this node to the map so that any future children can
  3040. //lookup the parent
  3041. idToNodeMap[datum.id] = datum;
  3042. //Does this node have a parent?
  3043. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  3044. //Doesn't look like it, so this node is the root of the tree
  3045. root = datum;
  3046. treeMap[datum.id] = root;
  3047. } else {
  3048. //This node has a parent, so let's look it up using the id
  3049. parentNode = idToNodeMap[datum.parentid];
  3050. //We don't need this property, so let's delete it.
  3051. //delete datum.parentid;
  3052. //Let's add the current node as a child of the parent node.
  3053. parentNode.children.push(datum);
  3054. }
  3055. }
  3056. return root;
  3057. }
  3058. function convertParentToChildList(data) {
  3059. var treeMap = {};
  3060. var list = [];
  3061. convertListToTree(data, treeMap);
  3062. angular.forEach(treeMap, function (item) {
  3063. list.push(item);
  3064. });
  3065. list = window._.sortBy(list, function (o) {
  3066. return o.orders;
  3067. });
  3068. return list;
  3069. }
  3070. //if(userMenus.length==0){
  3071. var userMenus = [];
  3072. var idMapMenu = {};
  3073. if ($rootScope.user) {
  3074. if ($rootScope.user.menu) {
  3075. var allJurisdiction2 = $rootScope.user.menu;
  3076. var onlyMenu2 = [];
  3077. for (var i = 0; i < allJurisdiction2.length; i++) {
  3078. if (allJurisdiction2[i].event == "1") {
  3079. onlyMenu2.push(allJurisdiction2[i])
  3080. }
  3081. }
  3082. // userMenus = convertParentToChildList($rootScope.user.menu);
  3083. userMenus = convertParentToChildList(onlyMenu2);
  3084. }
  3085. }
  3086. //}
  3087. $rootScope.userMenus = userMenus;
  3088. if ($rootScope.userMenus.length > 0) {
  3089. $rootScope.getpending();
  3090. // setInterval($rootScope.getpending(), 30000);
  3091. }
  3092. return userMenus;
  3093. }
  3094. setInterval(function () {
  3095. if ($rootScope.userMenus.length > 0) {
  3096. $rootScope.getpending()
  3097. $rootScope.getMsgNum($rootScope.user.id)
  3098. }
  3099. }, 5000);
  3100. getMenus();
  3101. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  3102. $rootScope.logout = function () {
  3103. // var userid =data.id;
  3104. // console.log(' userid='+JSON.stringify( userid));
  3105. //单点登录
  3106. if (localStorage.getItem('isSSo') === '1') {
  3107. console.log($rootScope.isHk,'hk');
  3108. console.log($rootScope.isZncd,'zncd');
  3109. if($rootScope.isHk){
  3110. if ($rootScope.isFuwutai && $scope.login){
  3111. $rootScope.end(function(){
  3112. $scope.runNumber = [];
  3113. sessionStorage.clear();
  3114. localStorage.clear();
  3115. location.href = 'http://' + location.hostname + '/pc_logout.jsp';
  3116. })
  3117. }else{
  3118. $scope.runNumber = [];
  3119. sessionStorage.clear();
  3120. localStorage.clear();
  3121. location.href = 'http://' + location.hostname + '/pc_logout.jsp';
  3122. }
  3123. }else{
  3124. $scope.runNumber = [];
  3125. sessionStorage.clear();
  3126. localStorage.clear();
  3127. location.href = 'http://' + location.hostname + '/pc_logout.jsp';
  3128. }
  3129. } else {
  3130. $auth.signOut()
  3131. .then(function (resp) {
  3132. // $auth.deleteData('auth_headers')
  3133. $scope.runNumber = [];
  3134. sessionStorage.clear();
  3135. localStorage.clear();
  3136. console.log($rootScope.isHk,'hk');
  3137. console.log($rootScope.isZncd,'zncd');
  3138. if($rootScope.isZncd){
  3139. if ($rootScope.isFuwutai) {
  3140. tlwsa.tlaClose();
  3141. $.toaster({
  3142. priority: 'info',
  3143. title: '操作',
  3144. message: '呼叫中心断开连接'
  3145. });
  3146. }
  3147. $state.go("login.signin");
  3148. }else if($rootScope.isHk){
  3149. if ($rootScope.isFuwutai && $scope.login) {
  3150. $rootScope.end(function(){
  3151. $state.go("login.signin");
  3152. })
  3153. }else{
  3154. $state.go("login.signin");
  3155. }
  3156. }
  3157. })
  3158. .catch(function (resp) { });
  3159. }
  3160. //$cookieStore.remove("userObm");
  3161. //$cookieStore.remove("menuObm");
  3162. //$cookieStore.remove("session");
  3163. //$rootScope.user = undefined;
  3164. //$rootScope.menus = undefined;
  3165. //$rootScope.nickname = undefined;
  3166. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  3167. // //logout: function(noServerLogout){
  3168. // window.sessionStorage.clear();
  3169. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  3170. // //},
  3171. }
  3172. // 快速建单
  3173. $rootScope.newOrder = function () {
  3174. $state.go('app.newOrder');
  3175. }
  3176. // save settings to local storage
  3177. if (angular.isDefined($localStorage.layout)) {
  3178. $scope.app.layout = $localStorage.layout;
  3179. } else {
  3180. $localStorage.layout = $scope.app.layout;
  3181. }
  3182. $scope.$watch('app.layout', function () {
  3183. // save to local storage
  3184. $localStorage.layout = $scope.app.layout;
  3185. }, true);
  3186. //global function to scroll page up
  3187. $scope.toTheTop = function () {
  3188. $document.scrollTopAnimated(0, 600);
  3189. };
  3190. // angular translate
  3191. // ----------------------
  3192. $scope.language = {
  3193. // Handles language dropdown
  3194. listIsOpen: false,
  3195. // list of available languages
  3196. available: {
  3197. 'en': 'English',
  3198. 'it_IT': 'Italiano',
  3199. 'de_DE': 'Deutsch',
  3200. 'zh_cn': 'Chinese'
  3201. },
  3202. // display always the current ui language
  3203. init: function () {
  3204. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  3205. var preferredLanguage = $translate.preferredLanguage();
  3206. // we know we have set a preferred one in app.config
  3207. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  3208. },
  3209. set: function (localeId, ev) {
  3210. $translate.use(localeId);
  3211. $scope.language.selected = $scope.language.available[localeId];
  3212. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  3213. }
  3214. };
  3215. $scope.language.init();
  3216. // Function that find the exact height and width of the viewport in a cross-browser way
  3217. var viewport = function () {
  3218. var e = window,
  3219. a = 'inner';
  3220. if (!('innerWidth' in window)) {
  3221. a = 'client';
  3222. e = document.documentElement || document.body;
  3223. }
  3224. return {
  3225. width: e[a + 'Width'],
  3226. height: e[a + 'Height']
  3227. };
  3228. };
  3229. // function that adds information in a scope of the height and width of the page
  3230. $scope.getWindowDimensions = function () {
  3231. return {
  3232. 'h': viewport().height,
  3233. 'w': viewport().width
  3234. };
  3235. };
  3236. // Detect when window is resized and set some variables
  3237. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  3238. $scope.windowHeight = newValue.h;
  3239. $scope.windowWidth = newValue.w;
  3240. if (newValue.w >= 992) {
  3241. $scope.isLargeDevice = true;
  3242. } else {
  3243. $scope.isLargeDevice = false;
  3244. }
  3245. if (newValue.w < 992) {
  3246. $scope.isSmallDevice = true;
  3247. } else {
  3248. $scope.isSmallDevice = false;
  3249. }
  3250. if (newValue.w <= 768) {
  3251. $scope.isMobileDevice = true;
  3252. } else {
  3253. $scope.isMobileDevice = false;
  3254. }
  3255. }, true);
  3256. // Apply on resize
  3257. $win.on('resize', function () {
  3258. $scope.$apply();
  3259. });
  3260. $rootScope.app.layout.isNavbarFixed = false;
  3261. $rootScope.app.layout.isSidebarFixed = false;
  3262. $rootScope.app.layout.isFooterFixed = false;
  3263. $scope.login_signquick = function (Requesteruserinform) {
  3264. $rootScope.statuscall = 1;
  3265. $scope.loginForm = {
  3266. username: Requesteruserinform.username,
  3267. password: Requesteruserinform.password
  3268. }
  3269. $auth.submitLogin($scope.loginForm)
  3270. .then(function (resp) {
  3271. localStorage.setItem("jry_user", JSON.stringify(resp));
  3272. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  3273. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  3274. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  3275. var onlyMenu = [];
  3276. for (var i = 0; i < allJurisdiction.length; i++) {
  3277. if (allJurisdiction[i].event == "1") {
  3278. onlyMenu.push(allJurisdiction[i])
  3279. }
  3280. };
  3281. $rootScope.userMenus = onlyMenu;
  3282. getMenus();
  3283. if (resp.error != 500) {
  3284. // $state.go('app.dashboard');
  3285. $rootScope.app.isLoginFixed = false;
  3286. } else {
  3287. resp.error = "";
  3288. $scope.loginForm.password = "";
  3289. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  3290. }
  3291. })
  3292. .catch(function (resp) {
  3293. $scope.loginForm.password = "";
  3294. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  3295. });
  3296. }
  3297. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  3298. var theRequest = {};
  3299. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  3300. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  3301. var str = url.substr(index + 1);
  3302. var strs = str.split("&");
  3303. for (var i = 0; i < strs.length; i++) {
  3304. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  3305. }
  3306. // return theRequest;
  3307. $scope.login_signquick(theRequest)
  3308. }
  3309. // $scope.casUserId = window.location.search;
  3310. // $scope.loginForm = {
  3311. // username: theRequest[0].split("=")[1],
  3312. // password: theRequest[1].split("=")[1]
  3313. // }
  3314. // $scope.lodingstyle = 'nodata';
  3315. var userAgent = window.navigator.userAgent.toLowerCase();
  3316. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  3317. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  3318. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  3319. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  3320. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  3321. if (isOpera) {
  3322. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  3323. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  3324. }
  3325. if (isIE) {
  3326. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  3327. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  3328. }
  3329. if (isFF) {
  3330. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  3331. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  3332. }
  3333. if (isSafari) {
  3334. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  3335. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  3336. }
  3337. if (isChrome) {
  3338. // login_sign();
  3339. $rootScope.app.isChrome = false;
  3340. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  3341. } else {
  3342. $rootScope.app.isChrome = true;
  3343. $scope.checkchrome = '';
  3344. // return alert("访问失败,请用Chrome浏览器访问!");
  3345. }
  3346. // }
  3347. // $scope.handleloginEnter = function(e) {
  3348. // if (e.keyCode == 13) {
  3349. // $scope.handleLoginClick();
  3350. // }
  3351. // };
  3352. // if (document.getElementById("isWatch").value == "true") {
  3353. // $scope.isHanderuser = true;
  3354. // } else {
  3355. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  3356. // $scope.isHanderuser = false;
  3357. // $scope.login_sign();
  3358. // }
  3359. // }
  3360. // $scope.viewType = "password";
  3361. // $scope.isPassword = true;
  3362. // $scope.toggleView = function() {
  3363. // $scope.isPassword = !$scope.isPassword;
  3364. // $scope.viewType = $scope.isPassword ? "password" : "text";
  3365. // }
  3366. // $scope.handleSignOutBtnClick = function() {
  3367. // $auth.signOut()
  3368. // .then(function(resp) {
  3369. // // handle success response
  3370. // })
  3371. // .catch(function(resp) {
  3372. // // handle error response
  3373. // });
  3374. // };
  3375. // }
  3376. // }
  3377. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  3378. // } else {
  3379. // $scope.loginstart();
  3380. // }
  3381. //websocket 信息中心
  3382. console.log(atmosphere)
  3383. var socket = atmosphere;
  3384. var subSocket;
  3385. // We are now ready to cut the request
  3386. var request = {
  3387. url: 'ws://192.168.199.150:8080/messagestation/cache',
  3388. contentType: "application/json",
  3389. shared: true, // 标签共享
  3390. trackMessageLength: true, //校验数据完整性
  3391. transport: 'websocket'
  3392. };
  3393. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  3394. request.onOpen = function (response) {
  3395. console.log(response)
  3396. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  3397. // alert("开始连接")
  3398. };
  3399. request.onMessage = function (response) {
  3400. var message = response.responseBody;
  3401. // alert("连接成功")
  3402. console.log(message)
  3403. try {
  3404. var json = JSON.parse(message);
  3405. console.log(json.noRead)
  3406. $scope.noReadData = json.noRead
  3407. } catch (e) {
  3408. console.log('呵呵哒: ', message);
  3409. return;
  3410. }
  3411. };
  3412. request.onClose = function (response) {
  3413. // alert("连接结束")
  3414. }
  3415. request.onError = function (response) {
  3416. // alert('连接失败')
  3417. };
  3418. //信息中心模态框
  3419. var loginUser = $rootScope.user;
  3420. // if(loginUser){
  3421. // // 未读消息数量
  3422. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  3423. // if (data.status == 200) {
  3424. // $scope.noReadData=data.totalNum
  3425. // // $rootScope.option.all = $rootScope.all;
  3426. // } else {
  3427. // $scope.noReadData=0
  3428. // }
  3429. // })
  3430. // }
  3431. // $scope.noReadData=($rootScope.noReadData||0)
  3432. // // $rootScope.all = 5;
  3433. // setTimeout(function() {
  3434. // console.log($scope.noReadData)
  3435. // }, 500)
  3436. $rootScope.wt_messages = function () {
  3437. var modalInstance = $modal.open({
  3438. templateUrl: './assets/views/wt_messages.html',
  3439. controller: function ($scope, $modalInstance) {
  3440. $rootScope.msgData = {
  3441. idx: 0,
  3442. sum: 5,
  3443. messageStation: {
  3444. readStatus: 0,
  3445. userId: $rootScope.user.id
  3446. }
  3447. }
  3448. // 关闭
  3449. $scope.closeModel = function () {
  3450. modalInstance.close();
  3451. }
  3452. $scope.getMsgData = function () {
  3453. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3454. if (data) {
  3455. $rootScope.msg = data.list
  3456. $rootScope.all = data.pageCount;
  3457. $scope.wt_msgData = data
  3458. $rootScope.noReadData = data.totalNum
  3459. }
  3460. })
  3461. }
  3462. $scope.getMsgData()
  3463. $scope.message_type = 2;
  3464. $scope.message_no = function (type) { //未读1
  3465. $scope.wt_msgData = {};
  3466. $scope.message_type = type;
  3467. $rootScope.msgData.messageStation.readStatus = 0,
  3468. // $rootScope.option.curr = 1;
  3469. $rootScope.msgData.idx = 0;
  3470. // console.log($rootScope.option.curr)
  3471. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3472. $scope.msg_yesType = true;
  3473. if (data.status == 200) {
  3474. $scope.msg_yesType = false
  3475. $scope.wt_msgData = data
  3476. $rootScope.msg = data.list
  3477. $rootScope.all = data.pageCount;
  3478. $rootScope.noReadData = data.totalNum;
  3479. // $rootScope.option.all = $rootScope.all;
  3480. } else {
  3481. $scope.msg_yesType = true;
  3482. }
  3483. })
  3484. }
  3485. $scope.message_yes = function (type) { //已读0
  3486. $scope.wt_msgData = {};
  3487. $scope.message_type = type;
  3488. $rootScope.msgData.messageStation.readStatus = 1,
  3489. $rootScope.msgData.idx = 0;
  3490. // $rootScope.option.curr = 1;
  3491. // console.log($rootScope.option.curr)
  3492. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3493. $scope.msg_noType = true;
  3494. if (data.status == 200) {
  3495. $scope.msg_noType = false
  3496. $scope.wt_msgData = data
  3497. $rootScope.msg = data.list;
  3498. $rootScope.all = data.pageCount;
  3499. // $rootScope.option.all = $rootScope.all;
  3500. } else {
  3501. $scope.msg_noType = true
  3502. }
  3503. })
  3504. };
  3505. $scope.sBtn = function () {
  3506. // console.log($rootScope.msgData)
  3507. // console.log($scope.wt_msgData)
  3508. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  3509. console.log($rootScope.msgData)
  3510. $scope.getMsgData()
  3511. }
  3512. $scope.xBtn = function () {
  3513. // console.log($rootScope.msgData)
  3514. // console.log($scope.wt_msgData)
  3515. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  3516. console.log($rootScope.msgData)
  3517. $scope.getMsgData()
  3518. }
  3519. $scope.redIn = function (data) {
  3520. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  3521. $scope.messageStation = {
  3522. messageStation: {
  3523. id: data.id,
  3524. readStatus: 1,
  3525. readTime: start
  3526. }
  3527. }
  3528. api_msg.updateDataList($scope.messageStation).then(function (data) {
  3529. console.log(data);
  3530. if (data.status == 200) {
  3531. $rootScope.msgData.messageStation.readStatus = 0,
  3532. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3533. $rootScope.msg = data.list
  3534. $rootScope.all = data.pageCount;
  3535. $rootScope.noReadData = data.totalNum;
  3536. })
  3537. }
  3538. })
  3539. };
  3540. },
  3541. size: 'lg',
  3542. resolve: {
  3543. }
  3544. })
  3545. }
  3546. }
  3547. ]);
  3548. //消息中心分页组件
  3549. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  3550. $rootScope.option = {
  3551. curr: 1, //当前页数
  3552. all: $rootScope.all, //总页数
  3553. count: 5, //最多显示的页数,默认为10
  3554. //点击页数的回调函数,参数page为点击的页数
  3555. click: function (page) {
  3556. $rootScope.msgData.idx = page - 1;
  3557. //这里可以写跳转到某个页面等...
  3558. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3559. $rootScope.msg = data.list
  3560. $rootScope.all = data.pageCount;
  3561. $rootScope.option.all = $rootScope.all;
  3562. })
  3563. }
  3564. }
  3565. }]);
  3566. app.directive('myPagination', function () {
  3567. return {
  3568. restrict: 'EA',
  3569. replace: true,
  3570. rootScope: {
  3571. option: '=pageOption'
  3572. },
  3573. controller: 'msgCtrl',
  3574. template: '<ul class="pagination">' +
  3575. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  3576. '<a href="javascript:;">{{p}}</a>' +
  3577. '</li>' +
  3578. '</ul>',
  3579. link: function ($rootScope) {
  3580. //容错处理
  3581. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  3582. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  3583. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  3584. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  3585. //得到显示页数的数组
  3586. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  3587. //绑定点击事件
  3588. $rootScope.pageClick = function (page) {
  3589. if (page == '«') {
  3590. page = parseInt($rootScope.option.curr) - 1;
  3591. } else if (page == '»') {
  3592. page = parseInt($rootScope.option.curr) + 1;
  3593. }
  3594. if (page < 1) page = 1;
  3595. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  3596. //点击相同的页数 不执行点击事件
  3597. if (page == $rootScope.option.curr) return;
  3598. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  3599. $rootScope.option.click(page);
  3600. $rootScope.option.curr = page;
  3601. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  3602. }
  3603. };
  3604. //返回页数范围(用来遍历)
  3605. function getRange(curr, all, count) {
  3606. //计算显示的页数
  3607. // console.log(curr, all, count)
  3608. curr = parseInt(curr);
  3609. all = parseInt(all);
  3610. count = parseInt(count);
  3611. var from = curr - parseInt(count / 2);
  3612. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  3613. //显示的页数容处理
  3614. if (from <= 0) {
  3615. from = 1;
  3616. to = from + count - 1;
  3617. if (to > all) {
  3618. to = all;
  3619. }
  3620. }
  3621. if (to > all) {
  3622. to = all;
  3623. from = to - count + 1;
  3624. if (from <= 0) {
  3625. from = 1;
  3626. }
  3627. }
  3628. var range = [];
  3629. for (var i = from; i <= to; i++) {
  3630. range.push(i);
  3631. }
  3632. range.push('»');
  3633. range.unshift('«');
  3634. return range;
  3635. }
  3636. }
  3637. }
  3638. });
  3639. app.service('Myservice', function () {
  3640. return {
  3641. };
  3642. });
  3643. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3644. // console.log(bh)
  3645. // if(bh>=0&&bh<=53){
  3646. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3647. // }else{
  3648. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3649. // }
  3650. window.onscroll = function () {
  3651. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  3652. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  3653. } else {
  3654. $('#sidebar').css('padding-top', '0')
  3655. }
  3656. // console.log(window.pageYOffset)
  3657. // console.log(window.innerHeight)
  3658. // console.log(document.body.scrollHeight)
  3659. // 底部padding
  3660. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3661. // console.log(bh)
  3662. // if(bh>=0&&bh<=53){
  3663. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3664. // }else{
  3665. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3666. // }
  3667. }