mainCtrl.js 127 KB

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