mainCtrl.js 128 KB

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