mainCtrl.js 128 KB

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