mainCtrl.js 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  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. // 未读消息数量seimin
  8. $rootScope.getMsgNum=function(id){
  9. api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: id}}).then(function(data) {
  10. if (data.status == 200) {
  11. $rootScope.noReadData=data.totalNum;
  12. }
  13. return $rootScope.noReadData
  14. })
  15. }
  16. // Loading bar transition
  17. // -----------------------------------
  18. // console.log("haha");
  19. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  20. console.log($rootScope.user)
  21. if($rootScope.user){
  22. $rootScope.getMsgNum($rootScope.user.id);
  23. }
  24. var $win = $($window);
  25. $rootScope.isMask = false;
  26. window.onbeforeunload = function() {
  27. $rootScope.statuscall = 0;
  28. $rootScope.statecall = 1;
  29. }
  30. // 所有列表自动刷新
  31. $rootScope.refreshTime=30000;
  32. $interval(function() {
  33. $scope.jry_year = new Date().getFullYear();
  34. $scope.jry_month = new Date().getMonth() + 1;
  35. $scope.jry_data = new Date().getDate();
  36. $scope.jry_hours = new Date().getHours();
  37. $scope.jry_minute = new Date().getMinutes();
  38. $scope.jry_second = new Date().getSeconds();
  39. // console.log($scope.jry_month)
  40. }, 1000)
  41. // $win.on('beforeunload', function() { return $state.go("login.signin"); });
  42. // $auth.deleteData('auth_headers')
  43. // }
  44. $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
  45. if (isEmpty($auth.retrieveData('auth_headers'))) {
  46. // if (toState.name != "login.signin" && toState.name != "echart") {
  47. // event.preventDefault();
  48. // $rootScope.app.isLoginFixed = true;
  49. // // $scope.lodingstyle = 'nodata';
  50. // return $state.go("login.signin");
  51. // }
  52. }
  53. // if (toState.name == "app.system.user.user") {
  54. // var isgoto = false;
  55. // if ($rootScope.user && $rootScope.user.menu) {
  56. // angular.forEach($rootScope.user.menu, function(item) {
  57. // if (item.link == toState.name) {
  58. // isgoto = true;
  59. // } else {}
  60. // })
  61. // }
  62. // if (isgoto) {
  63. // } else {
  64. // $state.go("app.dashboard");
  65. // }
  66. // }
  67. // if (toState.name != "app.incident.editor" && toState.name != "echart") {
  68. // if ($rootScope.status == 2 || $rootScope.status == 4 || $rootScope.status == 9) {
  69. // $rootScope.setidle();
  70. // }
  71. // }
  72. cfpLoadingBar.start();
  73. $auth.validateUser();
  74. });
  75. $rootScope.imUsrMap = {};
  76. $rootScope.onlineUser = [];
  77. $rootScope.offlineUser = [];
  78. $rootScope.me = undefined;
  79. $rootScope.imscope = {
  80. sessions: []
  81. }
  82. // var ws = new WebSocket('ws://192.168.3.51:8088/events');
  83. // var register= {"msgtype":"login","adn":"1001"};
  84. // ws.onopen = function() { ws.send(JSON.stringify(register));}
  85. // ws.onmessage = function(evt) { console.log(evt.data) }
  86. var ddp = new DDP('ws://115.156.150.70:3000/websocket');
  87. $rootScope.getDirectMsgRoomId = function(mdId, toId) {
  88. //me.id,to.id
  89. var rid = [mdId, toId].sort().join('');
  90. return rid;
  91. };
  92. $rootScope.sendMessage = function(rid, msg, callback, error) {
  93. ddp.call('sendMessage', [{ 'rid': rid, 'msg': msg }]).then(callback, error);
  94. };
  95. var pushNotification = function(notification) {
  96. deskNotification.showNotification(notification.title, {
  97. body: notification.body,
  98. icon: notification.icon || '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  99. onClick: notification.callback || function onNotificationClicked() {
  100. // console.log('Notification clicked.');
  101. },
  102. autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
  103. }, function onShow(error, hide) {
  104. if (error) {
  105. window.alert('Unable to show notification: ' + error.message);
  106. } else {
  107. // console.log('Notification Shown.');
  108. setTimeout(function hideNotification() {
  109. // console.log('Hiding notification....');
  110. hide(); //manually close the notification (you can skip this if you use the autoClose option)
  111. }, 5000);
  112. }
  113. });
  114. }
  115. // $rootScope.subscribeRoomMessage = function(rid){
  116. // ddp.subscribe('stream-room-messages',[rid, true]).then(function(){},function(reason){
  117. // console.log('subscribe stream-room-messages:%o', reason);
  118. // });
  119. // }
  120. $rootScope.filternotifyuser = [];
  121. $rootScope.$on('openroom', function(event, data, otheruser) {
  122. ddp.call('createDirectMessage', [otheruser]).then(function() {}, function(reason) {
  123. // console.log('createDirectMessage', reason);
  124. });
  125. ddp.subscribe('stream-room-messages', [data.rid, true]).then(function() {}, function(reason) {
  126. // console.log('subscribe stream-room-messages:%o', reason);
  127. });
  128. if ($rootScope.imUsrMap[data.from]['unread'].msgs) {
  129. $rootScope.imUsrMap[data.from]['unread'].msgs.clear;
  130. }
  131. $rootScope.filternotifyuser.push(data.from);
  132. });
  133. $rootScope.$on("clip-two.toggled", function(e, target, newState, sameGroup) {
  134. if (newState == false && target == 'off-sidebar') {
  135. $rootScope.$broadcast('chatcloseroom');
  136. //$rootScope.toggle("users");
  137. //$rootScope.filternotifyuser = [];
  138. //ddp.unsubscribe('stream-room-messages');
  139. }
  140. });
  141. $rootScope.$on("closeroom", function(event, data) {
  142. $rootScope.filternotifyuser = [];
  143. ddp.unsubscribe('stream-room-messages');
  144. });
  145. var initImUser = function(email, token) {
  146. var ddpconnect = ddp.connect();
  147. ddpconnect.then(function(data) {
  148. //console.log(data);
  149. if (data.session) {
  150. // ddp.call('createDirectMessage', [data.from, data.rid]).then(function() {}, function(reason) {
  151. // console.log('subscribe createDirectMessage');
  152. // });
  153. ddp.call('login', [{ user: { email: email }, password: token }]).then(function(data) {
  154. // console.log('login data: %o', data);
  155. if (data.id) {
  156. $rootScope.me = {
  157. id: data.id,
  158. token: data.token,
  159. expiry: data.tokenExpires
  160. };
  161. //获取在线用户
  162. ddp.subscribe('activeUsers');
  163. ddp.subscribe('stream-notify-user', [$rootScope.me.id + '/notification', true]).then(function(result) {
  164. //console.log(result);
  165. }, function(reason) {
  166. // console.log('stream-notify-user error:%s', reason);
  167. });
  168. // ddp.subscribe('stream-notify-user',[$rootScope.me.id+'/message',false]).then(function(result){
  169. // console.log(result);
  170. // },function(reason){
  171. // console.log('stream-notify-user error:', reason);
  172. // });
  173. ddp.subscribe('messages', [$rootScope.me.id + '/message', true]).then(function() {}, function(reason) {
  174. // console.log('subscribe messages error:%s', reason);
  175. });
  176. //'stream-notify-user',$rootScope.me.id+'/message'
  177. // ddp.call('sendmessage', []).then(function(msg){
  178. // })
  179. //console.log('Logged in!');
  180. // ddp.subscribe('messages', [{rid:data.id,start:new Date()}]).then(function(submsg){
  181. // console.log('subscribe messages-%s', submsg);
  182. // $rootScope.rocketchat_message = ddp.getCollection('rocketchat_message');
  183. // },function(reason){
  184. // console.log(reason);
  185. // })
  186. }
  187. }, function(reason) {
  188. // console.log(reason);
  189. });
  190. } else {
  191. }
  192. ddp.watch('users', function(changedDoc, message) {
  193. //console.log('users:%o',changedDoc);
  194. // if (message == 'method') {
  195. // console.log("1111111111111111111")
  196. // }
  197. if (message == 'added') {
  198. if (changedDoc.status && ($rootScope.me.id != changedDoc._id)) {
  199. if (changedDoc.status == 'away') {
  200. $rootScope.offlineUser.push(changedDoc);
  201. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  202. } else {
  203. $rootScope.onlineUser.push(changedDoc);
  204. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  205. }
  206. } else {
  207. //self
  208. }
  209. } else if (message == 'changed') {
  210. if ($rootScope.me.id != changedDoc._id) {
  211. if (!$rootScope.imUsrMap[changedDoc._id]) {
  212. if (changedDoc.status == 'away') {
  213. $rootScope.offlineUser.push(changedDoc);
  214. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  215. } else {
  216. $rootScope.onlineUser.push(changedDoc);
  217. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  218. }
  219. }
  220. if (changedDoc.status == 'away') {
  221. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  222. } else {
  223. $rootScope.offlineUser.push(changedDoc);
  224. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  225. window._.map(window._.slice($rootScope.onlineUser, $rootScope.imUsrMap[changedDoc._id].index), function(item, n) {
  226. $rootScope.imUsrMap[item._id].index = n;
  227. })
  228. // $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){
  229. // item.index = item.index - 1;
  230. // }))
  231. //.splice($rootScope.imUsrMap[changedDoc.id].index,1);
  232. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.offlineUser.length };
  233. }
  234. } else {
  235. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  236. $rootScope.onlineUser.push(changedDoc);
  237. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  238. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function(item, n) {
  239. $rootScope.imUsrMap[item._id].index = n;
  240. })
  241. // $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){
  242. // item.index = item.index - 1;
  243. // }))
  244. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length };
  245. } else {
  246. }
  247. }
  248. }
  249. } else if (message == 'removed') {
  250. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  251. } else {
  252. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  253. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  254. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function(item, n) {
  255. $rootScope.imUsrMap[item._id].index = n;
  256. });
  257. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length, unread: { total: 0, msgs: [] } };
  258. }
  259. }
  260. });
  261. ddp.watch('stream-notify-user', function(changedDoc, message) {
  262. if (message == 'changed') {
  263. if (changedDoc.eventName) {
  264. if (changedDoc.eventName.indexOf('/') > -1) {
  265. var [mineId, action] = changedDoc.eventName.split('/');
  266. if (action == 'notification') {
  267. angular.forEach(changedDoc.args, function(item) {
  268. if ($rootScope.filternotifyuser.indexOf(item.payload.sender._id) > -1) {
  269. } else {
  270. // console.log("push notify message:%o", item);
  271. var r = angular.extend(item, { 'date': new Date() })
  272. $rootScope.imUsrMap[item.payload.sender._id]['unread'].msgs.push(r);
  273. $rootScope.imUsrMap[item.payload.sender._id]['unread'].total++;
  274. pushNotification({
  275. title: "您有新消息-来自" + item.payload.sender.username,
  276. body: r.text,
  277. callback: function() {
  278. window.focus();
  279. $rootScope.toggle('off-sidebar');
  280. }
  281. })
  282. //toaster.pop('info', "您有新消息-来自"+item.payload.sender.username, r.text);
  283. }
  284. })
  285. }
  286. }
  287. }
  288. } else {
  289. }
  290. //console.log('notify message %o, %o', changedDoc, message);
  291. });
  292. ddp.watch('stream-room-messages', function(changedDoc, message) {
  293. if (message == 'changed') {
  294. //angular.forEach(changedDoc.args,function(item){
  295. $rootScope.$broadcast(changedDoc.eventName + '-msgs', changedDoc.args);
  296. //};
  297. // if(changedDoc.eventName){
  298. // $rootScope.imUsrMap[eventName]=$rootScope.imUsrMap[eventName]||{};
  299. // $rootScope.imUsrMap[eventName]['msgs']=$rootScope.imUsrMap[eventName]['msgs']||[];
  300. // angular.forEach(changedDoc.args,function(item){
  301. // $rootScope.imUsrMap[eventName].msgs.push(item);
  302. // })
  303. // }
  304. } else {
  305. }
  306. // console.log('notify message %o, %o', changedDoc, message);
  307. });
  308. ddp.watch('rocketchat_message', function(changedDoc, message) {
  309. // console.log('recieve rocketchat_message: %o-%o', changedDoc, message);
  310. });
  311. });
  312. }
  313. window.onunload = function() {
  314. }
  315. $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
  316. //$auth.validateUser();
  317. //stop loading bar on stateChangeSuccess
  318. event.targetScope.$watch("$viewContentLoaded", function() {
  319. cfpLoadingBar.complete();
  320. });
  321. // scroll top the page on change state
  322. $document.scrollTo(0, 0);
  323. if (angular.element('.email-reader').length) {
  324. angular.element('.email-reader').animate({
  325. scrollTop: 0
  326. }, 0);
  327. }
  328. // Save the route title
  329. $rootScope.currTitle = $state.current.title;
  330. if (angular.isDefined($state.current.pdKey)) {
  331. $rootScope.pdKey = $state.current.pdKey;
  332. }
  333. // console.log($state.current.title);
  334. });
  335. // State not found
  336. $rootScope.$on('$stateNotFound', function(event, unfoundState, fromState, fromParams) {
  337. //$rootScope.loading = false;
  338. if (angular.isUndefined($rootScope.user.id)) {
  339. $rootScope.loading = false;
  340. }
  341. // console.log(unfoundState.to);
  342. // "lazy.state"
  343. // console.log(unfoundState.toParams);
  344. // {a:1, b:2}
  345. // console.log(unfoundState.options);
  346. // {inherit:false} + default options
  347. });
  348. $rootScope.isMousedown=false;
  349. $rootScope.changeRemoveClass=function(e){
  350. $rootScope.isMousedown=true
  351. }
  352. $rootScope.returnRemoveClass=function(e){
  353. $rootScope.isMousedown=false;
  354. }
  355. $rootScope.$on('auth:login-success', function(ev, data) {
  356. // $state.go('login.signin');
  357. initImUser(data.email, data.msgUuid);
  358. getMenus();
  359. //console.log(data);
  360. //$rootScope.user = data.user;
  361. //$rootScope.menus = data.menu;
  362. });
  363. //$rootScope.$watch('$auth.user')
  364. // $rootScope.$on('auth:validation-success', function(ev, user) {
  365. // // console.log(user);
  366. // initImUser(user.email, user.msgUuid);
  367. // if ($rootScope.userMenus.length == 0) {
  368. // getMenus();
  369. // }
  370. // //alert('Welcome ', user.email);
  371. // });
  372. // $rootScope.$on('auth:invalid', function(ev) {
  373. // $state.go('login.signin');
  374. // });
  375. // $rootScope.$on('auth:validation-error', function(ev) {
  376. // $state.go('login.signin');
  377. // //alert('Welcome ', user.email);
  378. // });
  379. // $rootScope.$on('auth:session-expired', function(ev) {
  380. // //alert('Welcome ', user.email);
  381. // $state.go('login.signin');
  382. // });
  383. // $rootScope.$on('auth:logout-success', function(ev) {
  384. // //alert('goodbye');
  385. // //delete $rootScope.user;
  386. // //delete $rootScope.menus;
  387. // $state.go('login.signin');
  388. // });
  389. // $rootScope.$on('auth:logout-error', function(ev) {
  390. // $state.go('login.signin');
  391. // });
  392. $rootScope.pageTitle = function() {
  393. // if($rootScope.currTitle){
  394. // return $rootScope.app.name + ' - ' + $filter('translate')($rootScope.currTitle) || $rootScope.app.description;
  395. // }else{
  396. // return $rootScope.app.name + ' - ' + $rootScope.app.description
  397. // }
  398. var perfix = "sidebar.nav.";
  399. var toTransKeypageTitle = perfix + $rootScope.currTitle;
  400. return $rootScope.app.name + ' - ' + ($filter('translate')(toTransKeypageTitle) || $rootScope.app.description);
  401. };
  402. // $auth.validateUser();
  403. // $auth.authenticate('local').then(function(resp){
  404. // }).catch(function(resp){
  405. // })
  406. // if(angular.isDefined($rootScope.nickname)){
  407. // api_login.sso($rootScope.nickname).then(function(response){
  408. // var user = Restangular.stripRestangular(response);
  409. // if (user) {
  410. // if(angular.isUndefined(user.id)){
  411. // }else{
  412. // $rootScope.user = user;
  413. // }
  414. // }
  415. // });
  416. // }else{
  417. // var user= $cookieStore.get("userObm");
  418. // if(user){
  419. // $rootScope.user = user;
  420. // $rootScope.menus = $cookieStore.get("menuObm");
  421. // }else{
  422. // if(angular.isDefined($rootScope.nickname)){
  423. // api_login.sso($rootScope.nickname).then(function(response){
  424. // var data = Restangular.stripRestangular(response);
  425. // if (data) {
  426. // if(data.user){
  427. // if(angular.isUndefined(data.user.id)){
  428. // }else{
  429. // $rootScope.user = data.user;
  430. // $rootScope.menus = data.menu;
  431. // $cookieStore.put("userObm", $rootScope.user);
  432. // $cookieStore.put("menuObm", $rootScope.menus);
  433. // $cookieStore.put("session", data.sessionId);
  434. // }
  435. // }
  436. // }
  437. // });
  438. // }else{
  439. // }
  440. // }
  441. //}
  442. $rootScope.getSession = function() {
  443. if ($auth.userIsAuthenticated()) {
  444. return $auth.retrieveData('auth_headers')
  445. /*return {
  446. 'access-token':$auth.retrieveData('auth_headers')['access-token'],
  447. 'expiry':$auth.retrieveData('auth_headers')['expiry']
  448. };*/
  449. } else {
  450. return undefined;
  451. }
  452. }
  453. $scope.includes = [];
  454. $rootScope.includesState = function(state) {
  455. //for test
  456. //return true;
  457. //return includes;
  458. if ($rootScope.user) {
  459. if ($rootScope.user.menu) {
  460. angular.forEach($rootScope.user.menu, function(item) {
  461. $scope.includes[item.link] = true;
  462. });
  463. }
  464. }
  465. return $scope.includes[state];
  466. }
  467. //大屏入口
  468. $rootScope.opendashbord = function() {
  469. $state.go('echart');
  470. }
  471. // $rootScope.authority=false;
  472. // console.log($rootScope.user)
  473. // if($rootScope.user.role){
  474. // for(var i ;i<$rootScope.user.role.length;i++){
  475. // if($rootScope.user.role[i].rolecode=='call center') {
  476. // $rootScope.authority=true;
  477. // }else{$rootScope.authority=false;}
  478. // }
  479. // }
  480. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  481. // if (window.location.href && window.location.href.hash == "#/echart") {
  482. // } else {
  483. // // }
  484. // // 东经呼叫中心开始
  485. // $rootScope.statuscall = 0; //话机状态
  486. // $rootScope.statecall = 1; //示忙示闲
  487. // $scope.login = false; //签入签出
  488. // $rootScope.callout = false; //呼入呼出
  489. // $scope.group = 2000;
  490. // $scope.phone = 1500;
  491. // $rootScope.start = function(phone, group) {
  492. // api_text.start(phone, $rootScope.user.id).then(function(data) {
  493. // var token = data.token;
  494. // $rootScope.takes = token;
  495. // api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  496. // api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  497. // if (data.errno == 0) {
  498. // $rootScope.setidle();
  499. // $scope.login = true;
  500. // $rootScope.statuscall = 1;
  501. // $rootScope.callout = false;
  502. // // function hello() {
  503. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  504. // // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  505. // // };
  506. // // window.setTimeout("hello()", 1000);
  507. // // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  508. // function reconnect() {
  509. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  510. // var ws = new WebSocket('ws://115.156.150.70:28088/events');
  511. // var register = { "msgtype": "login", "adn": phone };
  512. // ws.onopen = function() {
  513. // heartCheck.start();
  514. // ws.send(JSON.stringify(register));
  515. // };
  516. // ws.onmessage = function(evt) {
  517. // heartCheck.reset();
  518. // if (evt.data == "HeartBeat") {
  519. // } else {
  520. // var mydata = JSON.parse(evt.data);
  521. // $scope.filterData = [];
  522. // if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  523. // $rootScope.$apply(function() {
  524. // $rootScope.statuscall = 2;
  525. // });
  526. // $rootScope.callout = false;
  527. // $rootScope.phone = mydata.ano;
  528. // var Notification = window.Notification;
  529. // Notification.requestPermission();
  530. // var n = new Notification("你有来电", {
  531. // body: "来电号码:" + mydata.ano,
  532. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  533. // // onclick: function onNotificationClicked() {
  534. // // console.log('Notification clicked.');
  535. // // }
  536. // });
  537. // } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  538. // $rootScope.callout = true;
  539. // } else if (mydata.evttype == "ringstop") {
  540. // // $rootScope.status=7;
  541. // // $rootScope.$apply(function() {
  542. // $rootScope.statuscall = 1;
  543. // // });
  544. // $rootScope.phone = ""
  545. // } else if (mydata.evttype == 'hookchanged' && $rootScope.callout) {
  546. // if (mydata.status && mydata.status == '1') {
  547. // $rootScope.$apply(function() {
  548. // $rootScope.statuscall = 1;
  549. // });
  550. // $rootScope.phone = "";
  551. // } else if (mydata.status && mydata.status != '1') {
  552. // $rootScope.$apply(function() {
  553. // $rootScope.statuscall = 3;
  554. // });
  555. // }
  556. // } else if (mydata.evttype == 'hookchanged' && !$rootScope.callout) {
  557. // if ($rootScope.phone != "") {
  558. // if (mydata.status && mydata.status == '1') { //挂机
  559. // $rootScope.$apply(function() {
  560. // $rootScope.statuscall = 1;
  561. // });
  562. // console.log("挂机");
  563. // console.log(mydata);
  564. // } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2) { //摘机
  565. // $rootScope.statuscall = 3;
  566. // api_text.setbusy($rootScope.takes).then(function(data) {
  567. // if (data.errno == 0) {
  568. // $rootScope.statecall = 2;
  569. // $scope.busy = true;
  570. // }
  571. // })
  572. // console.log("摘机");
  573. // console.log(mydata);
  574. // api_text.getcdrid($rootScope.takes).then(function(response) {
  575. // if (response.cdrid) {
  576. // var cdrid = response.cdrid;
  577. // // var response={cdrid:'219023836'}
  578. // var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  579. // api_user_data.fetchDataList('requester', filterData).then(function(data) {
  580. // var myData = Restangular.stripRestangular(data);
  581. // // $rootScope.phone="";
  582. // if (myData.list.length == 0) {
  583. // var modalInstance = $modal.open({
  584. // templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  585. // controller: function($scope, $modalInstance, api_user_data) {
  586. // $scope.title = "新增报修人";
  587. // $scope.requester = {};
  588. // $scope.onChangeadd = function(searchData) {
  589. // $scope.searchKey = searchData.account;
  590. // // $scope.searchDataadd = searchData;
  591. // var requesdata = angular.copy(searchData)
  592. // // if (requesdata.mphone) {
  593. // // delete requesdata.mphone;
  594. // // }
  595. // if (requesdata.telephone) {
  596. // delete requesdata.telephone;
  597. // }
  598. // angular.extend($scope.requester, requesdata);
  599. // }
  600. // $scope.refreshUseradd = function(searchKey) { //请求人搜索
  601. // $scope.requester.account = searchKey;
  602. // $scope.searchData = searchKey;
  603. // serchdataadd(searchKey);
  604. // }
  605. // $scope.getMydata = function(x) {
  606. // var reqestdatap = JSON.parse(x[0])
  607. // // if ($scope.requester.mphone) {
  608. // // delete reqestdatap.mphone;
  609. // // }
  610. // if ($scope.requester.telephone) {
  611. // delete reqestdatap.telephone;
  612. // }
  613. // $scope.searchField = JSON.parse(x[0]).account;
  614. // angular.extend($scope.requester, reqestdatap);
  615. // }
  616. // $scope.getMydataone = function(x) {
  617. // $scope.searchField = x;
  618. // $scope.requester.account = x;
  619. // }
  620. // serchdataadd();
  621. // function serchdataadd(searchKey) {
  622. // if (searchKey) {
  623. // var filterData = {
  624. // 'requester': {
  625. // 'searchKey': searchKey,
  626. // },
  627. // idx: 0,
  628. // sum: 10
  629. // };
  630. // } else {
  631. // var filterData = {
  632. // idx: 0,
  633. // sum: 10
  634. // };
  635. // }
  636. // // serchdataadd(searchKey)
  637. // // if ($scope.model.requester && $scope.model.requester.requesterTypeDTO) {
  638. // // angular.extend(filterData.requester, { 'requesterTypeDTO': $scope.model.requester.requesterTypeDTO })
  639. // // }
  640. // api_user_data.fetchDataList('requester', filterData).then(function(response) {
  641. // var myData = response;
  642. // $scope.myData = myData.list;
  643. // });
  644. // }
  645. // // if ((/^1[34578]\d{9}$/.test($rootScope.phone))) {
  646. // // $scope.requester = { 'mphone': $rootScope.phone };
  647. // // } else {
  648. // // $scope.requester = { 'telephone': $rootScope.phone };
  649. // // }
  650. // $scope.requester = { 'telephone': $rootScope.phone };
  651. // $scope.ok = function() {
  652. // $modalInstance.close($scope.requester);
  653. // };
  654. // $scope.cancel = function() {
  655. // $modalInstance.dismiss('cancel');
  656. // };
  657. // },
  658. // });
  659. // modalInstance.result.then(function(selectedItem) {
  660. // if (selectedItem) {
  661. // if (selectedItem.telephone && !selectedItem.mphone) {
  662. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  663. // delete selectedItem.mphone;
  664. // }
  665. // var data = {
  666. // 'requester': selectedItem
  667. // };
  668. // api_user_data.addData('requester', data).then(function(response) {
  669. // if (response.status == 200) {
  670. // var data = { 'model': { 'requestershow': response.data, 'incident': { 'requester': response.data, 'area': response.areaDTO, 'place': response.placeDTO, 'houseNumber': response.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  671. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  672. // }
  673. // })
  674. // }
  675. // });
  676. // } else if (myData.list.length == 1) {
  677. // 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 } } } }
  678. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  679. // } else {
  680. // var modalInstance = $modal.open({
  681. // templateUrl: 'assets/views/createincident.html',
  682. // controller: function($scope, $modalInstance, api_user_data) {
  683. // $scope.title = "请确定报修人";
  684. // $scope.requester = myData.list;
  685. // $scope.choice = function(requester) {
  686. // $modalInstance.dismiss('cancel');
  687. // var data = { 'model': { 'requestershow': requester, 'incident': { 'requester': requester, 'area': requester.areaDTO, 'place': requester.placeDTO, 'houseNumber': requester.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  688. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  689. // };
  690. // $scope.cancel = function() {
  691. // $modalInstance.dismiss('cancel');
  692. // };
  693. // },
  694. // size: "lg"
  695. // });
  696. // }
  697. // });
  698. // }
  699. // })
  700. // }
  701. // }
  702. // }
  703. // }
  704. // };
  705. // var heartCheck = {
  706. // timeout: 12000, //60ms
  707. // timeoutObj: null,
  708. // serverTimeoutObj: null,
  709. // reset: function() {
  710. // clearTimeout(this.timeoutObj);
  711. // clearTimeout(this.serverTimeoutObj);
  712. // this.start();
  713. // },
  714. // start: function() {
  715. // var self = this;
  716. // this.timeoutObj = setTimeout(function() {
  717. // ws.send("HeartBeat");
  718. // self.serverTimeoutObj = setTimeout(function() {
  719. // ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  720. // }, self.timeout)
  721. // }, this.timeout)
  722. // },
  723. // }
  724. // ws.onclose = function(evt) { reconnect(); }
  725. // ws.onerror = function(evt) { reconnect(); };
  726. // }
  727. // reconnect();
  728. // } else {
  729. // var Notification = window.Notification;
  730. // Notification.requestPermission();
  731. // var n = new Notification("签入失败!", {
  732. // body: data.errmsg,
  733. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  734. // // onclick: function onNotificationClicked() {
  735. // // console.log('Notification clicked.');
  736. // // }
  737. // });
  738. // }
  739. // })
  740. // })
  741. // }
  742. // // 东经呼叫中心结束
  743. //话机呼叫中心--开始
  744. $rootScope.getExtnDirect=function(){
  745. var jry_data_dictionary={
  746. key: "hjzx_cornet",
  747. type: "list"
  748. }
  749. api_wechatfile.getDictionary(jry_data_dictionary).then(function(res){
  750. var websocket_url = "ws://192.168.3.122:29003/ola_socket";
  751. var ola_queue = "10009"; //通话配置-队列配置-队列ID
  752. // var ola_extn = "1001"; //个人信息-座席分机号
  753. $rootScope.jry_extnNumberSelect=[];
  754. $rootScope.jry_extnNumberObj={};
  755. $rootScope.jry_extnNumberSelect=res;
  756. $rootScope.jry_extnNumberObj.jry_extnNumber=$rootScope.jry_extnNumberSelect[0];
  757. function log(msg) {
  758. //IE has no console
  759. if ('console' in window) console.log(msg);
  760. }
  761. function websocket_connect()
  762. {
  763. ola.connect(websocket_url);
  764. ola.onConnect = onConnect;
  765. ola.onClose = onClose;
  766. ola.onMessage = onMessage;
  767. }
  768. $(document).ready(function() {
  769. // if(ola_extn!=""){
  770. if($rootScope.jry_extnNumberObj.jry_extnNumber){
  771. websocket_connect();
  772. }
  773. });
  774. /* callbacks */
  775. function onMessage(evt)
  776. {
  777. var phoneData = JSON.parse(evt.data);
  778. if (phoneData.event_type == "agent_state") {
  779. console.log(phoneData);
  780. if (phoneData.state == "busy") {
  781. $('#agent_state').append(" (" + phoneData.private_data + ")");
  782. // 来电
  783. if (phoneData.private_data == "ring") {
  784. console.log(phoneData);
  785. $rootScope.jry_state="laidian";
  786. var Notification = window.Notification;
  787. Notification.requestPermission();
  788. var n = new Notification("你有来电", {
  789. body: "来电号码:" + phoneData.ani,
  790. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  791. });
  792. // 摘机
  793. } else if (phoneData.private_data == "answered") {
  794. $rootScope.jry_state="tonghuazhong";
  795. var jry_findPhone="";
  796. if(phoneData.ani){
  797. jry_findPhone=phoneData.ani
  798. }else if(phoneData.dnis&&phoneData.other_answered){
  799. jry_findPhone=phoneData.dnis
  800. }
  801. var filterData = {
  802. "idx": 0,
  803. "sum": 100,
  804. "requester": {
  805. "mphone": jry_findPhone,
  806. "telephone": jry_findPhone,
  807. "selectType": 1
  808. }
  809. }
  810. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  811. var myData = Restangular.stripRestangular(data);
  812. // $rootScope.phone="";
  813. // 新增报修人
  814. if (myData.list.length == 0) {
  815. var modalInstance = $modal.open({
  816. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  817. controller: function ($scope, $modalInstance, api_user_data,SweetAlert,api_wechatfile) {
  818. $scope.title = "新增报修人";
  819. $scope.requester = {};
  820. $scope.onChangeadd = function (searchData) {
  821. $scope.searchKey = searchData.account;
  822. // $scope.searchDataadd = searchData;
  823. var requesdata = angular.copy(searchData)
  824. // if (requesdata.mphone) {
  825. // delete requesdata.mphone;
  826. // }
  827. if (requesdata.telephone) {
  828. delete requesdata.telephone;
  829. }
  830. angular.extend($scope.requester, requesdata);
  831. }
  832. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  833. $scope.requester.account = searchKey;
  834. $scope.searchData = searchKey;
  835. serchdataadd(searchKey);
  836. }
  837. $scope.getMydata = function (x) {
  838. var reqestdatap = JSON.parse(x[0])
  839. // if ($scope.requester.mphone) {
  840. // delete reqestdatap.mphone;
  841. // }
  842. if ($scope.requester.telephone) {
  843. delete reqestdatap.telephone;
  844. }
  845. $scope.searchField = JSON.parse(x[0]).account;
  846. angular.extend($scope.requester, reqestdatap);
  847. }
  848. $scope.getMydataone = function (x) {
  849. $scope.searchField = x;
  850. $scope.requester.account = x;
  851. }
  852. serchdataadd();
  853. function serchdataadd(searchKey) {
  854. if (searchKey) {
  855. var filterData = {
  856. 'requester': {
  857. 'searchKey': searchKey,
  858. },
  859. idx: 0,
  860. sum: 10
  861. };
  862. } else {
  863. var filterData = {
  864. idx: 0,
  865. sum: 10
  866. };
  867. }
  868. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  869. var myData = response;
  870. $scope.myData = myData.list;
  871. });
  872. }
  873. api_user_data.fetchDataList('area', {
  874. idx: 0,
  875. sum: 100
  876. }).then(function (response) {
  877. if (response.status == 200) {
  878. $scope.areas = response.list;
  879. }
  880. })
  881. api_wechatfile.getDictionary({
  882. "key":"requester_type",
  883. "type":"list"
  884. }).then(function (response) {
  885. // if (response.status == 200) {
  886. $scope.networktypes = response;
  887. // }
  888. })
  889. $scope.requesterAreaid = "";
  890. $scope.onChange = function (item) {
  891. $scope.requesterAreaid = item.id;
  892. $scope.requester.placeDTO = {};
  893. api_user_data.fetchDataList('place', {
  894. place: {
  895. areaId: item.id
  896. },
  897. idx: 0,
  898. sum: 1000
  899. }).then(function (response) {
  900. if (response.status == 200) {
  901. $scope.places = response.list;
  902. }
  903. })
  904. }
  905. //地点搜索
  906. $scope.refresh = function (searchVal) {
  907. var faildata = {};
  908. if ($scope.requesterAreaid) {
  909. faildata = {
  910. 'idx': 0,
  911. 'sum': 1000,
  912. 'place': {
  913. 'areaId': $scope.requesterAreaid,
  914. 'place': searchVal,
  915. 'selectType': 'pinyin_qs'
  916. }
  917. }
  918. } else {
  919. faildata = {
  920. 'idx': 0,
  921. 'sum': 1000,
  922. 'place': {
  923. 'place': searchVal,
  924. 'selectType': 'pinyin_qs'
  925. }
  926. }
  927. }
  928. api_user_data.fetchDataList('place', faildata).then(function (response) {
  929. $scope.places = response.list;
  930. delete $scope.requester.placeDTO;
  931. })
  932. }
  933. $scope.requester = {
  934. 'telephone': jry_findPhone
  935. };
  936. $scope.ok = function () {
  937. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  938. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  939. var flag1 = reg1.test($scope.requester.mphone);
  940. var flag2 = reg2.test($scope.requester.mphone);
  941. console.log($scope.requester)
  942. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  943. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  944. } else if (angular.isUndefined($scope.requester.requesterType)) {
  945. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  946. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  947. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  948. }
  949. else {
  950. $modalInstance.close($scope.requester);
  951. }
  952. };
  953. $scope.cancel = function () {
  954. $modalInstance.dismiss('cancel');
  955. };
  956. },
  957. });
  958. modalInstance.result.then(function (selectedItem) {
  959. if (selectedItem) {
  960. if (selectedItem.telephone && !selectedItem.mphone) {
  961. selectedItem.telephone = angular.copy(selectedItem.mphone);
  962. delete selectedItem.mphone;
  963. }
  964. var data = {
  965. 'requester': selectedItem
  966. };
  967. api_user_data.addData('requester', data).then(function (response) {
  968. if (response.status == 200) {
  969. var data = {
  970. 'model': {
  971. 'requestershow': response.data,
  972. 'incident': {
  973. 'requester': response.data,
  974. 'area': response.data.areaDTO,
  975. 'place': response.data.placeDTO,
  976. 'houseNumber': response.data.houseNumber,
  977. // 'callID': cdrid,
  978. 'source': {
  979. 'id': 1547
  980. }
  981. }
  982. }
  983. }
  984. $state.go('app.incident.title', {
  985. 'model': JSON.stringify(data)
  986. });
  987. }
  988. })
  989. }
  990. });
  991. } else if (myData.list.length == 1) {
  992. var data = {
  993. 'model': {
  994. 'requestershow': myData.list[0],
  995. 'incident': {
  996. 'requester': myData.list[0],
  997. 'area': myData.list[0].areaDTO,
  998. 'place': myData.list[0].placeDTO,
  999. 'houseNumber': myData.list[0].houseNumber,
  1000. // 'callID': cdrid,
  1001. 'source': {
  1002. 'id': 1547
  1003. }
  1004. }
  1005. }
  1006. }
  1007. $state.go('app.incident.title', {
  1008. 'model': JSON.stringify(data)
  1009. });
  1010. } else {
  1011. var modalInstance = $modal.open({
  1012. templateUrl: 'assets/views/createincident.html',
  1013. controller: function ($scope, $modalInstance, api_user_data) {
  1014. $scope.title = "请确定报修人";
  1015. $scope.requester = myData.list;
  1016. $scope.choice = function (requester) {
  1017. $modalInstance.dismiss('cancel');
  1018. var data = {
  1019. 'model': {
  1020. 'requestershow': requester,
  1021. 'incident': {
  1022. 'requester': requester,
  1023. 'area': requester.areaDTO,
  1024. 'place': requester.placeDTO,
  1025. 'houseNumber': requester.houseNumber,
  1026. // 'callID': cdrid,
  1027. 'source': {
  1028. 'id': 1547
  1029. }
  1030. }
  1031. }
  1032. }
  1033. $state.go('app.incident.title', {
  1034. 'model': JSON.stringify(data)
  1035. });
  1036. };
  1037. $scope.cancel = function () {
  1038. $modalInstance.dismiss('cancel');
  1039. };
  1040. },
  1041. size: "lg"
  1042. });
  1043. }
  1044. });
  1045. }
  1046. // 挂机
  1047. } else if(phoneData.state == "login"){
  1048. go_ready()
  1049. }else if(phoneData.state == "logout"){
  1050. $rootScope.jry_state="weiqianru";
  1051. }else if(phoneData.state == "ready"){
  1052. // 来电挂机
  1053. if(phoneData.old_state=="busy"&&phoneData.private_data=="answered"){
  1054. go_break()
  1055. }else{
  1056. $rootScope.jry_state="shixian";
  1057. }
  1058. }
  1059. // else if (data.old_state == "busy") {
  1060. // }
  1061. } else if (phoneData.event_type == "agent_caller_state") {
  1062. // special feature, never mind
  1063. if (phoneData.action == "in") {
  1064. } else {
  1065. }
  1066. } else if (phoneData.event_type == "command/reply") {
  1067. if (phoneData.phoneData && phoneData.phoneData.state) {
  1068. }
  1069. }
  1070. }
  1071. function onConnect() {
  1072. console.log("websocket connected!");
  1073. // ola._extn = ola_extn;
  1074. // ola.subscribe('ola.queue.' + ola_queue + '.' + ola_extn);
  1075. // ola.subscribe('ola.caller.' + ola_extn);
  1076. // ola.get_agent_state(ola_extn);
  1077. ola._extn = $rootScope.jry_extnNumberObj.jry_extnNumber.name;
  1078. ola.subscribe('ola.queue.' + ola_queue + '.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1079. ola.subscribe('ola.caller.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1080. ola.get_agent_state($rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1081. };
  1082. function onClose() {
  1083. }
  1084. function login() {
  1085. // ola.login(ola_queue, ola_extn, {type: "onhook"});
  1086. console.log($rootScope.jry_extnNumberObj.jry_extnNumber);
  1087. ola.login(ola_queue, $rootScope.jry_extnNumberObj.jry_extnNumber.name, {type: "onhook"});
  1088. }
  1089. function logout() {
  1090. ola.logout();
  1091. }
  1092. function go_ready() {
  1093. ola.go_ready();
  1094. }
  1095. function go_break() {
  1096. ola.go_break($('#break_reason').val());
  1097. $rootScope.jry_state="shimang";
  1098. }
  1099. function answer() {
  1100. ola.answer();
  1101. }
  1102. function dial(dst) {
  1103. ola.dial(dst);
  1104. }
  1105. $rootScope.dial=function(dst){
  1106. ola.dial(dst);
  1107. }
  1108. function conference(dst) {
  1109. ola.conference(dst);
  1110. }
  1111. function conference_uuid(channel_uuid) {
  1112. ola.conference_uuid(channel_uuid);
  1113. }
  1114. function hangup() {
  1115. ola.hangup();
  1116. }
  1117. function take_call(uuid) {
  1118. // ola.take_call(ola_extn, uuid);
  1119. ola.take_call($rootScope.jry_extnNumberObj.jry_extnNumber.name, uuid);
  1120. }
  1121. // 签入
  1122. $rootScope.jry_qianru=function(){
  1123. login();
  1124. }
  1125. // 示闲
  1126. $rootScope.jry_shixian=function(){
  1127. go_ready()
  1128. }
  1129. // 示忙
  1130. $rootScope.jry_shimang=function(){
  1131. go_break()
  1132. }
  1133. // 签出
  1134. $rootScope.jry_qianchu=function(){
  1135. logout()
  1136. }
  1137. $rootScope.jry_bohao=function(res){
  1138. if($rootScope.jry_state=="weiqianru"){
  1139. // SweetAlert.swal({
  1140. // title: "拨打失败",
  1141. // text: "请先签入!",
  1142. // type: "error",
  1143. // confirmButtonColor: "#DD6B55"
  1144. // });
  1145. }else if($rootScope.jry_state=="shimang"){
  1146. // SweetAlert.swal({
  1147. // title: "拨打失败",
  1148. // text: "请先示闲!",
  1149. // type: "error",
  1150. // confirmButtonColor: "#DD6B55"
  1151. // });
  1152. }else{
  1153. dial(res);
  1154. }
  1155. }
  1156. })
  1157. }
  1158. $rootScope.jry_state="weiqianru";
  1159. $rootScope.getExtnDirect();
  1160. //话机呼叫中心--结束
  1161. // 未接来电
  1162. $scope.jry_getUnanswered=function(){
  1163. var jry_data={
  1164. idx:0,
  1165. sum:999,
  1166. "callRecord":{
  1167. "todayTime":new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()+" 00:00:00",
  1168. "todayTimeEnd":new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()+" 23:59:59",
  1169. }
  1170. }
  1171. api_bpm_data.fetchDataList("callRecord", jry_data).then(function(data) {
  1172. // fo0h
  1173. for(var i=0;i<data.list.length;i++){
  1174. 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()
  1175. }
  1176. $rootScope.jry_unansweredData=data.list;
  1177. });
  1178. }
  1179. // $scope.jry_getUnanswered();
  1180. // 来电号码回拨
  1181. $scope.jry_callBack=function(data){
  1182. var callBackData={
  1183. "callRecord":{
  1184. "id":data.id,
  1185. "isAnswered":"1"
  1186. }
  1187. };
  1188. api_bpm_data.updData("callRecord",callBackData).then(function(res){
  1189. if(res){
  1190. $scope.jry_getUnanswered();
  1191. dial(data.callerIdNumber)
  1192. }
  1193. });
  1194. if(data.department.id&&data.requester){
  1195. 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} }
  1196. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1197. }else if(data.department.id){
  1198. var toData = { 'model': { 'incident': {'contactsInformation':data.callerIdNumber,'dept':data.department,'faultLocation':data.department.address, 'source': { 'id': 1 }},'openModel':true} }
  1199. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1200. }else{
  1201. var toData = { 'model': { 'incident': {'contactsInformation':data.callerIdNumber, 'source': { 'id': 1 }}} }
  1202. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1203. };
  1204. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  1205. }
  1206. //来电号码生成事件
  1207. $scope.jry_callToIncident=function(data){
  1208. if(data.department.id&&data.requester){
  1209. 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} }
  1210. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1211. }else if(data.department.id){
  1212. var toData = { 'model': { 'incident': {'contactsInformation':data.callerIdNumber,'dept':data.department,'faultLocation':data.department.address, 'source': { 'id': 1 }},'openModel':true} }
  1213. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1214. }else{
  1215. var toData = { 'model': { 'incident': {'contactsInformation':data.callerIdNumber, 'source': { 'id': 1 }}} }
  1216. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1217. }
  1218. }
  1219. $scope.onChangeadd = function(searchData) {
  1220. $scope.searchKey = searchData.account;
  1221. // $scope.searchDataadd = searchData;
  1222. var requesdata = angular.copy(searchData)
  1223. $scope.requester = requesdata;
  1224. }
  1225. $scope.refreshUseradd = function(searchKey) { //主题搜索
  1226. $scope.searchData = searchKey;
  1227. reashdata($scope.searchData);
  1228. }
  1229. $scope.getMydata = function(x) {
  1230. $scope.telephone = JSON.parse(x).phone;
  1231. $scope.searchField = $scope.telephone;
  1232. return $scope.searchField;
  1233. }
  1234. $scope.getMydataone = function(x) {
  1235. $scope.telephone = x;
  1236. $scope.searchField = $scope.telephone;
  1237. }
  1238. $scope.fildata = {
  1239. "idx": 0,
  1240. "sum": 10,
  1241. "flag": -1
  1242. }
  1243. function reashdata(item) {
  1244. if (item && item != "") {
  1245. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  1246. } else {
  1247. delete $scope.fildata.user;
  1248. }
  1249. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function(data) {
  1250. if (data.status == 200) {
  1251. $scope.myData = data.list;
  1252. }
  1253. })
  1254. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  1255. // if (response) {
  1256. // if (response.status = 200) {
  1257. // var myData = response;
  1258. // $scope.myData = myData.list;
  1259. // }
  1260. // }
  1261. // })
  1262. }
  1263. if (window.location && window.location.hash == "#/echart") {
  1264. } else {
  1265. reashdata();
  1266. }
  1267. $rootScope.end = function() {
  1268. api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) {
  1269. if (data.errno == 0) {
  1270. api_text.exit($rootScope.takes).then(function(data) {
  1271. if (data.errno == 0) {
  1272. $rootScope.statuscall = 0;
  1273. $scope.login = false
  1274. // SweetAlert.swal({
  1275. // title: "登出成功",
  1276. // text: "呼叫中心登出成功!",
  1277. // type: "success"
  1278. // });
  1279. // }else{SweetAlert.swal({
  1280. // title: "登出失败",
  1281. // text: "呼叫中心登出失败!",
  1282. // type: "error"
  1283. // });
  1284. }
  1285. })
  1286. }
  1287. })
  1288. }
  1289. $rootScope.dialout = function(gid, teleno) {
  1290. var telephone = "";
  1291. if (teleno && teleno.length > 4) {
  1292. telephone = '9' + teleno;
  1293. } else {
  1294. // telephone = '*01' + teleno + '*';
  1295. telephone = teleno;
  1296. }
  1297. api_text.dialout($rootScope.takes, gid, telephone).then(function(data) {
  1298. if (data.errno == 0) {
  1299. // $rootScope.statuscall = 3;
  1300. $rootScope.callout = true;
  1301. // $rootScope.phone=teleno;
  1302. }
  1303. })
  1304. }
  1305. // $scope.busy=false;
  1306. $rootScope.setbusy = function() {
  1307. api_text.setbusy($rootScope.takes).then(function(data) {
  1308. if (data.errno == 0) {
  1309. $rootScope.statecall = 2;
  1310. $scope.busy = true;
  1311. }
  1312. })
  1313. }
  1314. $rootScope.setidle = function() {
  1315. api_text.setidle($rootScope.takes).then(function(data) {
  1316. if (data.errno == 0) {
  1317. $rootScope.statecall = 1;
  1318. $scope.busy = false;
  1319. }
  1320. })
  1321. }
  1322. $rootScope.inittrans = function(telephone) {
  1323. api_text.inittrans(telephone, $rootScope.takes).then(function(data) {
  1324. if (data.errno == 0) {
  1325. // $scope.status=9
  1326. }
  1327. })
  1328. }
  1329. $rootScope.comptrans = function() {
  1330. api_text.comptrans($rootScope.takes).then(function(data) {
  1331. if (data.errno == 0) {
  1332. $rootScope.statuscall = 1;
  1333. }
  1334. })
  1335. }
  1336. $rootScope.takeup = function() {
  1337. api_text.offhook($rootScope.takes).then(function(data) {
  1338. if (data.errno == 0) {
  1339. $rootScope.statuscall = 3;
  1340. }
  1341. })
  1342. }
  1343. $rootScope.takedown = function() {
  1344. api_text.onhook($rootScope.takes).then(function(data) {
  1345. if (data.errno == 0) {
  1346. $rootScope.statuscall = 1;
  1347. }
  1348. })
  1349. }
  1350. $rootScope.saveData = function(selectdata) {
  1351. var modalInstance = $modal.open({
  1352. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  1353. controller: function($scope, $modalInstance, api_bpm_data) {
  1354. $scope.worktimedata = {};
  1355. $scope.worktimedata = selectdata;
  1356. $scope.cancel = function() {
  1357. $modalInstance.dismiss('cancel');
  1358. };
  1359. $scope.savercode = function(worktimedata) {
  1360. var fildata = {
  1361. "scheduleclass": {
  1362. "id": selectdata.id,
  1363. "code": worktimedata.code,
  1364. "name": worktimedata.title,
  1365. "person": worktimedata.person,
  1366. "description": worktimedata.description,
  1367. "startTime": worktimedata.startTime,
  1368. "endTime": worktimedata.endTime,
  1369. "shiftTime": selectdata.shiftTime,
  1370. "succeedTime": selectdata.succeedTime,
  1371. "isTemplate": worktimedata.isTemplate
  1372. }
  1373. }
  1374. api_bpm_data.updData('scheduleclass', fildata).then(function(response) {
  1375. if (response) {
  1376. if (response.status == 200) {
  1377. SweetAlert.swal({
  1378. title: "修改成功!",
  1379. type: "success"
  1380. }, function() {
  1381. // $scope.refreshData('expand-right', defaultFilterData);
  1382. })
  1383. } else {
  1384. SweetAlert.swal({
  1385. title: "修改失败!",
  1386. type: "error"
  1387. })
  1388. }
  1389. }
  1390. })
  1391. $modalInstance.close();
  1392. }
  1393. }
  1394. });
  1395. }
  1396. $rootScope.changepassword = function(data1, size) {
  1397. var modalInstance = $modal.open({
  1398. templateUrl: 'assets/views/changepassword.html',
  1399. controller: function($scope, $modalInstance, items, Restangular, SweetAlert) {
  1400. $scope.passwordnull = function(originalPwd, pwd, pwd_2) {
  1401. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  1402. }
  1403. $scope.savepassword = function(originalPwd, pwd, pwd_2) {
  1404. $modalInstance.dismiss('cancel');
  1405. // console.log('pwd=' + pwd + '+' + pwd_2);
  1406. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  1407. if (pwd == pwd_2) {
  1408. var data2 = {};
  1409. data2["originalPwd"] = originalPwd;
  1410. data2["userid"] = $rootScope.user.id;
  1411. data2["pwd"] = pwd;
  1412. api_login.uppwd(data2).then(function(response) {
  1413. var myData = Restangular.stripRestangular(response);
  1414. if (myData.status == 200) {
  1415. SweetAlert.swal({
  1416. title: "保存成功!",
  1417. type: "success",
  1418. confirmButtonColor: "#007AFF"
  1419. });
  1420. } else {
  1421. SweetAlert.swal({
  1422. title: "保存失败!",
  1423. text: "输入旧密码错误,请重新输入!",
  1424. type: "error"
  1425. });
  1426. }
  1427. })
  1428. } else {
  1429. SweetAlert.swal({
  1430. title: "两次输入的新密码不相同!",
  1431. text: "输入错误,请重新输入!",
  1432. type: "error"
  1433. });
  1434. }
  1435. // }else{
  1436. // SweetAlert.swal({
  1437. // title: "密码不能为空!",
  1438. // text: "请输入密码!",
  1439. // type: "error"
  1440. // });
  1441. // }
  1442. }
  1443. },
  1444. size: size,
  1445. resolve: {
  1446. items: function() {
  1447. return {
  1448. fetchItems: function(filterData, APIService) {}
  1449. };
  1450. },
  1451. }
  1452. });
  1453. }
  1454. // $rootScope.getnochildpending = function() {
  1455. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1456. // angular.forEach($rootScope.userMenus, function(item) {
  1457. // item.tipnum = 1;
  1458. // })
  1459. // }
  1460. // }
  1461. // $rootScope.getchildpending = function(cantdata) {
  1462. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1463. // angular.forEach($rootScope.userMenus, function(item) {
  1464. // item.tipnum = 1;
  1465. // angular.forEach(item, function(index) {
  1466. // index.tipnum = 18;
  1467. // })
  1468. // })
  1469. // }
  1470. // }
  1471. $rootScope.getpending=function(){
  1472. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  1473. if ($rootScope.user.group) {
  1474. var groupArr=[];
  1475. for(var i=0;i<$rootScope.user.group.length;i++){
  1476. groupArr.push($rootScope.user.group[i].id)
  1477. }
  1478. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function(response) {
  1479. angular.forEach($rootScope.userMenus, function(item, i) {
  1480. item.tipshow = false;
  1481. if (response) {
  1482. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  1483. if (item.id == 58) {
  1484. item.tipshow = true;
  1485. }
  1486. }
  1487. if (response.inspectionCount > 0) {
  1488. if (item.id == 27) {
  1489. item.tipshow = true;
  1490. }
  1491. }
  1492. if (response.incidentCount > 0) {
  1493. if (item.id == 2) {
  1494. item.tipshow = true;
  1495. }
  1496. }
  1497. if (response.releaseCount > 0) {
  1498. if (item.id == 1215) {
  1499. item.tipshow = true;
  1500. }
  1501. }
  1502. if (response.solutionCount > 0) {
  1503. if (item.id == 21) {
  1504. item.tipshow = true;
  1505. }
  1506. }
  1507. if (response.changeCount > 0) {
  1508. if (item.id == 1212) {
  1509. item.tipshow = true;
  1510. }
  1511. }
  1512. if (response.problemCount > 0) {
  1513. if (item.id == 1209) {
  1514. item.tipshow = true;
  1515. }
  1516. }
  1517. if (response.applicationForm > 0) {
  1518. if (item.id == 1221) {
  1519. item.tipshow = true;
  1520. }
  1521. }
  1522. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  1523. if (item.id == 21) {
  1524. item.tipshow = true;
  1525. }
  1526. }
  1527. if (item.children) {
  1528. angular.forEach(item.children, function(index) {
  1529. if (response.hjzxCount && response.hjzxCount > 0) {
  1530. if (index.id == 1208) {
  1531. if (response.hjzxCount < 100) {
  1532. index.tipnum = response.hjzxCount;
  1533. } else {
  1534. index.tipnum = "99+";
  1535. }
  1536. }
  1537. }
  1538. if (response.wechatWarningCount && response.wechatWarningCount > 0) {
  1539. if (index.id == 59) {
  1540. if (response.wechatWarningCount < 100) {
  1541. index.tipnum = response.wechatWarningCount;
  1542. } else {
  1543. index.tipnum = "99+";
  1544. }
  1545. }
  1546. }
  1547. if (response.problemCount && response.problemCount > 0) {
  1548. if (index.id == 1210) {
  1549. if (response.problemCount < 100) {
  1550. index.tipnum = response.problemCount;
  1551. } else {
  1552. index.tipnum = "99+";
  1553. }
  1554. }
  1555. }
  1556. if (response.releaseCount && response.releaseCount > 0) {
  1557. if (index.id == 1216) {
  1558. if (response.releaseCount < 100) {
  1559. index.tipnum = response.releaseCount;
  1560. } else {
  1561. index.tipnum = "99+";
  1562. }
  1563. }
  1564. }
  1565. if (response.inspectionCount && response.inspectionCount > 0) {
  1566. if (index.id == 147) {
  1567. if (response.inspectionCount < 100) {
  1568. index.tipnum = response.inspectionCount;
  1569. } else {
  1570. index.tipnum = "99+";
  1571. }
  1572. }
  1573. }
  1574. if (response.solutionCount && response.solutionCount > 0) {
  1575. if (index.id == 23) {
  1576. if (response.solutionCount < 100) {
  1577. index.tipnum = response.solutionCount;
  1578. } else {
  1579. index.tipnum = "99+";
  1580. }
  1581. }
  1582. }
  1583. if (response.changeCount && response.changeCount > 0) {
  1584. if (index.id == 1213) {
  1585. if (response.changeCount < 100) {
  1586. index.tipnum = response.changeCount;
  1587. } else {
  1588. index.tipnum = "99+";
  1589. }
  1590. }
  1591. }
  1592. if (response.incidentCount && response.incidentCount > 0) {
  1593. if (index.id == 3) {
  1594. if (response.incidentCount < 100) {
  1595. index.tipnum = response.incidentCount;
  1596. } else {
  1597. index.tipnum = "99+";
  1598. }
  1599. }
  1600. }
  1601. if (response.applicationForm && response.applicationForm > 0) {
  1602. if (index.id == 1231) {
  1603. if (response.applicationForm < 100) {
  1604. index.tipnum = response.applicationForm;
  1605. } else {
  1606. index.tipnum = "99+";
  1607. }
  1608. }
  1609. }
  1610. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  1611. if (index.id == 23) {
  1612. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  1613. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  1614. } else {
  1615. index.tipnum = "99+";
  1616. }
  1617. }
  1618. }
  1619. })
  1620. }
  1621. }
  1622. })
  1623. // return $rootScope.userMenus;
  1624. // $scope.recordpending = response.;
  1625. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  1626. })
  1627. } else {
  1628. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  1629. }
  1630. }
  1631. // console.log($rootScope.userMenus);
  1632. }
  1633. $rootScope.userMenus = [];
  1634. var getMenus = function() {
  1635. function convertListToTree(data, treeMap) {
  1636. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  1637. var root = null; //Initially set our loop to null
  1638. var parentNode = null;
  1639. //loop over data
  1640. for (var i = 0; i < data.length; i++) {
  1641. // data[i].id = Number(data[i].id);
  1642. var datum = data[i];
  1643. //each node will have children, so let's give it a "children" poperty
  1644. datum.children = [];
  1645. //add an entry for this node to the map so that any future children can
  1646. //lookup the parent
  1647. idToNodeMap[datum.id] = datum;
  1648. //Does this node have a parent?
  1649. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  1650. //Doesn't look like it, so this node is the root of the tree
  1651. root = datum;
  1652. treeMap[datum.id] = root;
  1653. } else {
  1654. //This node has a parent, so let's look it up using the id
  1655. parentNode = idToNodeMap[datum.parentid];
  1656. //We don't need this property, so let's delete it.
  1657. //delete datum.parentid;
  1658. //Let's add the current node as a child of the parent node.
  1659. parentNode.children.push(datum);
  1660. }
  1661. }
  1662. return root;
  1663. }
  1664. function convertParentToChildList(data) {
  1665. var treeMap = {};
  1666. var list = [];
  1667. convertListToTree(data, treeMap);
  1668. angular.forEach(treeMap, function(item) {
  1669. list.push(item);
  1670. });
  1671. list = window._.sortBy(list, function(o) {
  1672. return o.orders;
  1673. });
  1674. return list;
  1675. }
  1676. //if(userMenus.length==0){
  1677. var userMenus = [];
  1678. var idMapMenu = {};
  1679. if ($rootScope.user) {
  1680. if ($rootScope.user.menu) {
  1681. var allJurisdiction2=$rootScope.user.menu;
  1682. var onlyMenu2=[];
  1683. for(var i=0;i<allJurisdiction2.length;i++){
  1684. if(allJurisdiction2[i].event=="1"){
  1685. onlyMenu2.push(allJurisdiction2[i])
  1686. }
  1687. }
  1688. // userMenus = convertParentToChildList($rootScope.user.menu);
  1689. userMenus = convertParentToChildList(onlyMenu2);
  1690. }
  1691. }
  1692. //}
  1693. $rootScope.userMenus = userMenus;
  1694. if ($rootScope.userMenus.length > 0) {
  1695. $rootScope.getpending();
  1696. // setInterval($rootScope.getpending(), 30000);
  1697. }
  1698. return userMenus;
  1699. }
  1700. setInterval(function(){
  1701. if ($rootScope.userMenus.length > 0){
  1702. $rootScope.getpending()
  1703. $rootScope.getMsgNum($rootScope.user.id)
  1704. }
  1705. }, 5000);
  1706. getMenus();
  1707. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  1708. $rootScope.logout = function() {
  1709. // var userid =data.id;
  1710. // console.log(' userid='+JSON.stringify( userid));
  1711. $auth.signOut()
  1712. .then(function(resp) {
  1713. // $auth.deleteData('auth_headers')
  1714. sessionStorage.clear();
  1715. localStorage.clear();
  1716. $state.go("login.signin");
  1717. })
  1718. .catch(function(resp) {});
  1719. //$cookieStore.remove("userObm");
  1720. //$cookieStore.remove("menuObm");
  1721. //$cookieStore.remove("session");
  1722. //$rootScope.user = undefined;
  1723. //$rootScope.menus = undefined;
  1724. //$rootScope.nickname = undefined;
  1725. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  1726. // //logout: function(noServerLogout){
  1727. // window.sessionStorage.clear();
  1728. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  1729. // //},
  1730. }
  1731. // 快速建单
  1732. $rootScope.newOrder=function(){
  1733. $state.go('app.newOrder');
  1734. }
  1735. // save settings to local storage
  1736. if (angular.isDefined($localStorage.layout)) {
  1737. $scope.app.layout = $localStorage.layout;
  1738. } else {
  1739. $localStorage.layout = $scope.app.layout;
  1740. }
  1741. $scope.$watch('app.layout', function() {
  1742. // save to local storage
  1743. $localStorage.layout = $scope.app.layout;
  1744. }, true);
  1745. //global function to scroll page up
  1746. $scope.toTheTop = function() {
  1747. $document.scrollTopAnimated(0, 600);
  1748. };
  1749. // angular translate
  1750. // ----------------------
  1751. $scope.language = {
  1752. // Handles language dropdown
  1753. listIsOpen: false,
  1754. // list of available languages
  1755. available: {
  1756. 'en': 'English',
  1757. 'it_IT': 'Italiano',
  1758. 'de_DE': 'Deutsch',
  1759. 'zh_cn': 'Chinese'
  1760. },
  1761. // display always the current ui language
  1762. init: function() {
  1763. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  1764. var preferredLanguage = $translate.preferredLanguage();
  1765. // we know we have set a preferred one in app.config
  1766. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  1767. },
  1768. set: function(localeId, ev) {
  1769. $translate.use(localeId);
  1770. $scope.language.selected = $scope.language.available[localeId];
  1771. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  1772. }
  1773. };
  1774. $scope.language.init();
  1775. // Function that find the exact height and width of the viewport in a cross-browser way
  1776. var viewport = function() {
  1777. var e = window,
  1778. a = 'inner';
  1779. if (!('innerWidth' in window)) {
  1780. a = 'client';
  1781. e = document.documentElement || document.body;
  1782. }
  1783. return {
  1784. width: e[a + 'Width'],
  1785. height: e[a + 'Height']
  1786. };
  1787. };
  1788. // function that adds information in a scope of the height and width of the page
  1789. $scope.getWindowDimensions = function() {
  1790. return {
  1791. 'h': viewport().height,
  1792. 'w': viewport().width
  1793. };
  1794. };
  1795. // Detect when window is resized and set some variables
  1796. $scope.$watch($scope.getWindowDimensions, function(newValue, oldValue) {
  1797. $scope.windowHeight = newValue.h;
  1798. $scope.windowWidth = newValue.w;
  1799. if (newValue.w >= 992) {
  1800. $scope.isLargeDevice = true;
  1801. } else {
  1802. $scope.isLargeDevice = false;
  1803. }
  1804. if (newValue.w < 992) {
  1805. $scope.isSmallDevice = true;
  1806. } else {
  1807. $scope.isSmallDevice = false;
  1808. }
  1809. if (newValue.w <= 768) {
  1810. $scope.isMobileDevice = true;
  1811. } else {
  1812. $scope.isMobileDevice = false;
  1813. }
  1814. }, true);
  1815. // Apply on resize
  1816. $win.on('resize', function() {
  1817. $scope.$apply();
  1818. });
  1819. $rootScope.app.layout.isNavbarFixed = false;
  1820. $rootScope.app.layout.isSidebarFixed = false;
  1821. $rootScope.app.layout.isFooterFixed = false;
  1822. $scope.login_signquick = function(Requesteruserinform) {
  1823. $rootScope.statuscall = 1;
  1824. $scope.loginForm = {
  1825. username: Requesteruserinform.username,
  1826. password: Requesteruserinform.password
  1827. }
  1828. $auth.submitLogin($scope.loginForm)
  1829. .then(function(resp) {
  1830. localStorage.setItem("jry_user", JSON.stringify(resp));
  1831. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  1832. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  1833. var allJurisdiction=JSON.parse(localStorage.getItem("jry_user")).menu;
  1834. var onlyMenu=[];
  1835. for(var i=0;i<allJurisdiction.length;i++){
  1836. if(allJurisdiction[i].event=="1"){
  1837. onlyMenu.push(allJurisdiction[i])
  1838. }
  1839. };
  1840. $rootScope.userMenus=onlyMenu;
  1841. getMenus();
  1842. if (resp.error != 500) {
  1843. // $state.go('app.dashboard');
  1844. $rootScope.app.isLoginFixed = false;
  1845. } else {
  1846. resp.error = "";
  1847. $scope.loginForm.password = "";
  1848. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  1849. }
  1850. })
  1851. .catch(function(resp) {
  1852. $scope.loginForm.password = "";
  1853. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  1854. });
  1855. }
  1856. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  1857. var theRequest = {};
  1858. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  1859. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  1860. var str = url.substr(index + 1);
  1861. var strs = str.split("&");
  1862. for (var i = 0; i < strs.length; i++) {
  1863. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  1864. }
  1865. // return theRequest;
  1866. $scope.login_signquick(theRequest)
  1867. }
  1868. // $scope.casUserId = window.location.search;
  1869. // $scope.loginForm = {
  1870. // username: theRequest[0].split("=")[1],
  1871. // password: theRequest[1].split("=")[1]
  1872. // }
  1873. // $scope.lodingstyle = 'nodata';
  1874. var userAgent = window.navigator.userAgent.toLowerCase();
  1875. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  1876. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  1877. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  1878. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  1879. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  1880. if (isOpera) {
  1881. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  1882. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  1883. }
  1884. if (isIE) {
  1885. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  1886. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  1887. }
  1888. if (isFF) {
  1889. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  1890. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  1891. }
  1892. if (isSafari) {
  1893. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  1894. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  1895. }
  1896. if (isChrome) {
  1897. // login_sign();
  1898. $rootScope.app.isChrome = false;
  1899. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  1900. } else {
  1901. $rootScope.app.isChrome = true;
  1902. $scope.checkchrome = '';
  1903. // return alert("访问失败,请用Chrome浏览器访问!");
  1904. }
  1905. // }
  1906. // $scope.handleloginEnter = function(e) {
  1907. // if (e.keyCode == 13) {
  1908. // $scope.handleLoginClick();
  1909. // }
  1910. // };
  1911. // if (document.getElementById("isWatch").value == "true") {
  1912. // $scope.isHanderuser = true;
  1913. // } else {
  1914. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  1915. // $scope.isHanderuser = false;
  1916. // $scope.login_sign();
  1917. // }
  1918. // }
  1919. // $scope.viewType = "password";
  1920. // $scope.isPassword = true;
  1921. // $scope.toggleView = function() {
  1922. // $scope.isPassword = !$scope.isPassword;
  1923. // $scope.viewType = $scope.isPassword ? "password" : "text";
  1924. // }
  1925. // $scope.handleSignOutBtnClick = function() {
  1926. // $auth.signOut()
  1927. // .then(function(resp) {
  1928. // // handle success response
  1929. // })
  1930. // .catch(function(resp) {
  1931. // // handle error response
  1932. // });
  1933. // };
  1934. // }
  1935. // }
  1936. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  1937. // } else {
  1938. // $scope.loginstart();
  1939. // }
  1940. //websocket 信息中心
  1941. console.log(atmosphere)
  1942. var socket = atmosphere;
  1943. var subSocket;
  1944. // We are now ready to cut the request
  1945. var request = {
  1946. url: 'ws://192.168.199.150:8080/messagestation/cache',
  1947. contentType: "application/json",
  1948. shared: true, // 标签共享
  1949. trackMessageLength: true, //校验数据完整性
  1950. transport: 'websocket'
  1951. };
  1952. subSocket = socket.subscribe(request);
  1953. request.onOpen = function(response) {
  1954. console.log(response)
  1955. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  1956. // alert("开始连接")
  1957. };
  1958. request.onMessage = function(response) {
  1959. var message = response.responseBody;
  1960. // alert("连接成功")
  1961. console.log(message)
  1962. try {
  1963. var json = JSON.parse(message);
  1964. console.log(json.noRead)
  1965. $scope.noReadData = json.noRead
  1966. } catch (e) {
  1967. console.log('呵呵哒: ', message);
  1968. return;
  1969. }
  1970. };
  1971. request.onClose = function(response) {
  1972. // alert("连接结束")
  1973. }
  1974. request.onError = function(response) {
  1975. // alert('连接失败')
  1976. };
  1977. //信息中心模态框
  1978. var loginUser = $rootScope.user;
  1979. // if(loginUser){
  1980. // // 未读消息数量
  1981. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  1982. // if (data.status == 200) {
  1983. // $scope.noReadData=data.totalNum
  1984. // // $rootScope.option.all = $rootScope.all;
  1985. // } else {
  1986. // $scope.noReadData=0
  1987. // }
  1988. // })
  1989. // }
  1990. // $scope.noReadData=($rootScope.noReadData||0)
  1991. // // $rootScope.all = 5;
  1992. // setTimeout(function() {
  1993. // console.log($scope.noReadData)
  1994. // }, 500)
  1995. $rootScope.wt_messages = function() {
  1996. var modalInstance = $modal.open({
  1997. templateUrl: '../../../assets/views/wt_messages.html',
  1998. controller: function($scope, $modalInstance) {
  1999. $rootScope.msgData = {
  2000. idx: 0,
  2001. sum: 5,
  2002. messageStation: {
  2003. readStatus: 0,
  2004. userId: $rootScope.user.id
  2005. }
  2006. }
  2007. $scope.getMsgData = function() {
  2008. api_msg.msgDataList($rootScope.msgData).then(function(data) {
  2009. if (data) {
  2010. $rootScope.msg = data.list
  2011. $rootScope.all = data.pageCount;
  2012. $scope.wt_msgData = data
  2013. $rootScope.noReadData=data.totalNum
  2014. }
  2015. })
  2016. }
  2017. $scope.getMsgData()
  2018. $scope.message_type = 2;
  2019. $scope.message_no = function(type) { //未读1
  2020. $scope.wt_msgData = {};
  2021. $scope.message_type = type;
  2022. $rootScope.msgData.messageStation.readStatus = 0,
  2023. // $rootScope.option.curr = 1;
  2024. $rootScope.msgData.idx = 0;
  2025. // console.log($rootScope.option.curr)
  2026. api_msg.msgDataList($rootScope.msgData).then(function(data) {
  2027. $scope.msg_yesType = true;
  2028. if (data.status == 200) {
  2029. $scope.msg_yesType = false
  2030. $scope.wt_msgData = data
  2031. $rootScope.msg = data.list
  2032. $rootScope.all = data.pageCount;
  2033. $rootScope.noReadData=data.totalNum;
  2034. // $rootScope.option.all = $rootScope.all;
  2035. } else {
  2036. $scope.msg_yesType = true;
  2037. }
  2038. })
  2039. }
  2040. $scope.message_yes = function(type) { //已读0
  2041. $scope.wt_msgData = {};
  2042. $scope.message_type = type;
  2043. $rootScope.msgData.messageStation.readStatus = 1,
  2044. $rootScope.msgData.idx = 0;
  2045. // $rootScope.option.curr = 1;
  2046. // console.log($rootScope.option.curr)
  2047. api_msg.msgDataList($rootScope.msgData).then(function(data) {
  2048. $scope.msg_noType = true;
  2049. if (data.status == 200) {
  2050. $scope.msg_noType = false
  2051. $scope.wt_msgData = data
  2052. $rootScope.msg = data.list;
  2053. $rootScope.all = data.pageCount;
  2054. // $rootScope.option.all = $rootScope.all;
  2055. } else {
  2056. $scope.msg_noType = true
  2057. }
  2058. })
  2059. };
  2060. $scope.sBtn = function() {
  2061. // console.log($rootScope.msgData)
  2062. // console.log($scope.wt_msgData)
  2063. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  2064. console.log($rootScope.msgData)
  2065. $scope.getMsgData()
  2066. }
  2067. $scope.xBtn = function() {
  2068. // console.log($rootScope.msgData)
  2069. // console.log($scope.wt_msgData)
  2070. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  2071. console.log($rootScope.msgData)
  2072. $scope.getMsgData()
  2073. }
  2074. $scope.redIn = function(data) {
  2075. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  2076. $scope.messageStation = {
  2077. messageStation: {
  2078. id: data.id,
  2079. readStatus: 1,
  2080. readTime: start
  2081. }
  2082. }
  2083. api_msg.updateDataList($scope.messageStation).then(function(data) {
  2084. console.log(data);
  2085. if (data.status == 200) {
  2086. $rootScope.msgData.messageStation.readStatus = 0,
  2087. api_msg.msgDataList($rootScope.msgData).then(function(data) {
  2088. $rootScope.msg = data.list
  2089. $rootScope.all = data.pageCount;
  2090. $rootScope.noReadData = data.totalNum;
  2091. })
  2092. }
  2093. })
  2094. };
  2095. },
  2096. size: 'lg',
  2097. resolve: {
  2098. }
  2099. })
  2100. }
  2101. }
  2102. ]);
  2103. //消息中心分页组件
  2104. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function($scope, $rootScope, api_msg, Myservice) {
  2105. $rootScope.option = {
  2106. curr: 1, //当前页数
  2107. all: $rootScope.all, //总页数
  2108. count: 5, //最多显示的页数,默认为10
  2109. //点击页数的回调函数,参数page为点击的页数
  2110. click: function(page) {
  2111. $rootScope.msgData.idx = page - 1;
  2112. //这里可以写跳转到某个页面等...
  2113. api_msg.msgDataList($rootScope.msgData).then(function(data) {
  2114. $rootScope.msg = data.list
  2115. $rootScope.all = data.pageCount;
  2116. $rootScope.option.all = $rootScope.all;
  2117. })
  2118. }
  2119. }
  2120. }]);
  2121. app.directive('myPagination', function() {
  2122. return {
  2123. restrict: 'EA',
  2124. replace: true,
  2125. rootScope: {
  2126. option: '=pageOption'
  2127. },
  2128. controller: 'msgCtrl',
  2129. template: '<ul class="pagination">' +
  2130. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  2131. '<a href="javascript:;">{{p}}</a>' +
  2132. '</li>' +
  2133. '</ul>',
  2134. link: function($rootScope) {
  2135. //容错处理
  2136. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  2137. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  2138. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  2139. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  2140. //得到显示页数的数组
  2141. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  2142. //绑定点击事件
  2143. $rootScope.pageClick = function(page) {
  2144. if (page == '«') {
  2145. page = parseInt($rootScope.option.curr) - 1;
  2146. } else if (page == '»') {
  2147. page = parseInt($rootScope.option.curr) + 1;
  2148. }
  2149. if (page < 1) page = 1;
  2150. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  2151. //点击相同的页数 不执行点击事件
  2152. if (page == $rootScope.option.curr) return;
  2153. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  2154. $rootScope.option.click(page);
  2155. $rootScope.option.curr = page;
  2156. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  2157. }
  2158. };
  2159. //返回页数范围(用来遍历)
  2160. function getRange(curr, all, count) {
  2161. //计算显示的页数
  2162. // console.log(curr, all, count)
  2163. curr = parseInt(curr);
  2164. all = parseInt(all);
  2165. count = parseInt(count);
  2166. var from = curr - parseInt(count / 2);
  2167. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  2168. //显示的页数容处理
  2169. if (from <= 0) {
  2170. from = 1;
  2171. to = from + count - 1;
  2172. if (to > all) {
  2173. to = all;
  2174. }
  2175. }
  2176. if (to > all) {
  2177. to = all;
  2178. from = to - count + 1;
  2179. if (from <= 0) {
  2180. from = 1;
  2181. }
  2182. }
  2183. var range = [];
  2184. for (var i = from; i <= to; i++) {
  2185. range.push(i);
  2186. }
  2187. range.push('»');
  2188. range.unshift('«');
  2189. return range;
  2190. }
  2191. }
  2192. }
  2193. });
  2194. app.service('Myservice', function() {
  2195. return {
  2196. };
  2197. });
  2198. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  2199. // console.log(bh)
  2200. // if(bh>=0&&bh<=53){
  2201. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  2202. // }else{
  2203. // $('#sidebar').css('padding-bottom', 0 + 'px')
  2204. // }
  2205. window.onscroll = function () {
  2206. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  2207. $('#sidebar').css('padding-top', (65-window.pageYOffset) + 'px')
  2208. }else{
  2209. $('#sidebar').css('padding-top', '0')
  2210. }
  2211. // console.log(window.pageYOffset)
  2212. // console.log(window.innerHeight)
  2213. // console.log(document.body.scrollHeight)
  2214. // 底部padding
  2215. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  2216. // console.log(bh)
  2217. // if(bh>=0&&bh<=53){
  2218. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  2219. // }else{
  2220. // $('#sidebar').css('padding-bottom', 0 + 'px')
  2221. // }
  2222. }