mainCtrl.js 156 KB

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