mainCtrl.js 178 KB

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