mainCtrl.js 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106
  1. 'use strict';
  2. /**
  3. * Clip-Two Main Controller
  4. */
  5. app.controller('AppCtrl', ['$rootScope', '$scope', '$state', '$translate', '$localStorage', '$cookieStore', '$window', '$modal', '$document', '$timeout', '$filter', '$auth', 'cfpLoadingBar', 'DDP', 'deskNotification', 'Restangular', 'api_login', 'api_text', 'api_user_data', 'api_wechatfile', 'api_bpm_data', 'api_msg', 'Myservice', '$interval', 'jry_api_bpm',
  6. function ($rootScope, $scope, $state, $translate, $localStorage, $cookieStore, $window, $modal, $document, $timeout, $filter, $auth, cfpLoadingBar, DDP, deskNotification, Restangular, api_login, api_text, api_user_data, api_wechatfile, api_bpm_data, api_msg, Myservice, $interval, jry_api_bpm) {
  7. // 未读消息数量seimin
  8. $rootScope.getMsgNum = function (id) {
  9. api_msg.msgDataList({ idx: 0, sum: 1, messageStation: { readStatus: 0, userId: id } }).then(function (data) {
  10. if (data.status == 200) {
  11. $rootScope.noReadData = data.totalNum;
  12. }
  13. return $rootScope.noReadData
  14. })
  15. }
  16. // Loading bar transition
  17. // -----------------------------------
  18. // console.log("haha");
  19. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  20. $rootScope.isFuwutai = JSON.parse(localStorage.getItem("isFuwutai")) ? true : false;
  21. console.log($rootScope.user)
  22. if ($rootScope.user) {
  23. $rootScope.getMsgNum($rootScope.user.id);
  24. }
  25. var $win = $($window);
  26. $rootScope.isMask = false;
  27. window.onbeforeunload = function () {
  28. $rootScope.statuscall = 0;
  29. $rootScope.statecall = 1;
  30. }
  31. // 所有列表自动刷新
  32. $rootScope.refreshTime = 30000;
  33. $interval(function () {
  34. $scope.jry_year = new Date().getFullYear();
  35. $scope.jry_month = new Date().getMonth() + 1;
  36. $scope.jry_data = new Date().getDate();
  37. $scope.jry_hours = new Date().getHours();
  38. $scope.jry_minute = new Date().getMinutes();
  39. $scope.jry_second = new Date().getSeconds();
  40. // console.log($scope.jry_month)
  41. }, 1000)
  42. // $win.on('beforeunload', function() { return $state.go("login.signin"); });
  43. // $auth.deleteData('auth_headers')
  44. // }
  45. // 监听路由
  46. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  47. console.log(event, toState, toParams, fromState, fromParams)
  48. if ((toState.name == 'app.incident.chart' || toState.name == 'app.incident.editor') &&
  49. fromState.name) {
  50. console.log($rootScope.jry_state);
  51. $scope.isShixian = false;
  52. if($rootScope.jry_state == 'shixian'){
  53. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  54. //进入页面强制示忙
  55. if (tlwsa) {
  56. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  57. setTimeout(()=>{
  58. tlwsa.tlaAcw();
  59. },0)
  60. }
  61. }
  62. }
  63. if ((fromState.name == 'app.incident.chart' || fromState.name == 'app.incident.editor') &&
  64. toState.name != 'app.incident.chart' && toState.name != 'app.incident.editor'
  65. ) {
  66. console.log($rootScope.jry_state);
  67. // $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  68. //进入页面强制示闲
  69. $scope.isShixian = true;
  70. // if (tlwsa) {
  71. // // tlwsa.tlaForcewca($rootScope.phoneNumber);
  72. // tlwsa.tlaWca();
  73. // }
  74. }
  75. if (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. console.log('最近一次话机状态',$rootScope.preState);
  1586. $scope.qShimang($rootScope.preState);
  1587. $.toaster({
  1588. priority: 'info',
  1589. title: '操作',
  1590. message: '挂断成功'
  1591. });
  1592. } else {
  1593. console.log('挂断失败-----seimin');
  1594. $.toaster({
  1595. priority: 'info',
  1596. title: '操作',
  1597. message: '挂断失败'
  1598. });
  1599. }
  1600. }
  1601. //呼入回调函数
  1602. TLWSA.onCallin = oncallin;
  1603. function oncallin(jso) {
  1604. console.log(jso);//lmm
  1605. $rootScope.callInPhoneNumber = jso.caller;//来电的电话
  1606. $rootScope.sockid = jso.crs;//来电的话机id
  1607. if (jso) {
  1608. console.log('呼入坐席成功,请摘机-----seimin');
  1609. $scope.getState(3);
  1610. $.toaster({
  1611. priority: 'info',
  1612. title: '操作',
  1613. message: '呼入坐席成功,请摘机'
  1614. });
  1615. console.log('来电了!电话号码是【' + $rootScope.callInPhoneNumber + '】');
  1616. } else {
  1617. console.log('呼入坐席失败-----seimin');
  1618. $.toaster({
  1619. priority: 'info',
  1620. title: '操作',
  1621. message: '呼入坐席失败'
  1622. });
  1623. }
  1624. }
  1625. //呼入摘机应答回调函数
  1626. TLWSA.onAnswer = onanswer;
  1627. function onanswer(err) {
  1628. err = Number(err);
  1629. if (!err) {
  1630. console.log('呼入摘机应答成功-----seimin');
  1631. $scope.getState(5);
  1632. $.toaster({
  1633. priority: 'info',
  1634. title: '操作',
  1635. message: '呼入摘机应答成功'
  1636. });
  1637. //根据电话号码反查报修人,如果是坐席号码,则不用
  1638. // console.log(sessionStorage.getItem('phones'));
  1639. // var phones = JSON.parse(sessionStorage.getItem('phones'));
  1640. // var isHuajihao = phones.length?phones.some(v=>v == teleno):false;
  1641. // if(isHuajihao){
  1642. // return;
  1643. // }
  1644. var postData = { "idx": 0, "sum": 10, "requester": { hjzxPhone: $rootScope.callInPhoneNumber } };
  1645. api_user_data.fetchDataList('requester', postData).then(function (result) {
  1646. if (result.status == 200) {
  1647. console.log(result.list);
  1648. var requesters = result.list;
  1649. if (requesters.length === 0) {
  1650. //未匹配到报修人,则弹窗添加报修人yeye
  1651. $state.go('app.incident.chart', {
  1652. model: JSON.stringify({
  1653. model: {
  1654. incident: {
  1655. requester: {
  1656. hjzxPhone: $rootScope.callInPhoneNumber
  1657. },
  1658. sockid: $rootScope.sockid
  1659. }
  1660. }
  1661. })
  1662. });
  1663. } else if (requesters.length === 1) {
  1664. //匹配到一个报修人
  1665. $state.go('app.incident.chart', {
  1666. model: JSON.stringify({
  1667. model: {
  1668. incident: {
  1669. requester: requesters[0],
  1670. contactsInformation: requesters[0].mphone,
  1671. sockid: $rootScope.sockid
  1672. },
  1673. }
  1674. })
  1675. });
  1676. } else {
  1677. //匹配到多个报修人
  1678. $modal.open({
  1679. templateUrl: 'assets/views/incident/tpl/tel.html',
  1680. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  1681. $scope.list = requesters;
  1682. $scope.selectedItem = 0;
  1683. $scope.cancel = function () {
  1684. $modalInstance.dismiss('cancel');
  1685. };
  1686. $scope.changeBxr = function (id) {
  1687. $scope.selectedItem = id;
  1688. }
  1689. $scope.save = function () {
  1690. var item = $scope.list.find(v => v.id == $scope.selectedItem);
  1691. if (item) {
  1692. $scope.cancel();
  1693. $state.go('app.incident.chart', {
  1694. model: JSON.stringify({
  1695. model: {
  1696. incident: {
  1697. requester: item,
  1698. contactsInformation: item.mphone,
  1699. sockid: $rootScope.sockid
  1700. },
  1701. }
  1702. })
  1703. });
  1704. } else {
  1705. SweetAlert.swal({
  1706. title: "请选择报修人!",
  1707. type: "error"
  1708. })
  1709. }
  1710. }
  1711. }
  1712. });
  1713. }
  1714. }
  1715. })
  1716. } else {
  1717. console.log('呼入摘机应答失败-----seimin');
  1718. $.toaster({
  1719. priority: 'info',
  1720. title: '操作',
  1721. message: '呼入摘机应答失败'
  1722. });
  1723. }
  1724. }
  1725. //呼入未摘机应答回调函数
  1726. TLWSA.onMisscall = onmisscall;
  1727. function onmisscall(err) {
  1728. err = Number(err);
  1729. if (!err) {
  1730. console.log('呼入未摘机应答成功-----seimin');
  1731. $scope.getState(1);
  1732. $.toaster({
  1733. priority: 'info',
  1734. title: '操作',
  1735. message: '呼入未摘机应答成功'
  1736. });
  1737. } else {
  1738. console.log('呼入未摘机应答失败-----seimin');
  1739. $.toaster({
  1740. priority: 'info',
  1741. title: '操作',
  1742. message: '呼入未摘机应答失败'
  1743. });
  1744. }
  1745. }
  1746. //转接开始回调函数
  1747. TLWSA.onTransferreturn = ontransferreturn;//调用转移方法之后,返回该事件 如果错误码为0,仅仅表示开始转移,不代表转移目标已经接听或已经拒绝
  1748. function ontransferreturn(err) {
  1749. err = Number(err);
  1750. if (!err) {
  1751. console.log('转接坐席开始成功-----seimin');
  1752. $scope.getState(7);
  1753. $.toaster({
  1754. priority: 'info',
  1755. title: '操作',
  1756. message: '转接坐席开始成功'
  1757. });
  1758. } else {
  1759. console.log('转接坐席开始失败-----seimin');
  1760. $.toaster({
  1761. priority: 'info',
  1762. title: '操作',
  1763. message: '转接坐席开始失败'
  1764. });
  1765. }
  1766. }
  1767. //转接结果回调函数
  1768. TLWSA.onTransferresult = ontransferresult;
  1769. function ontransferresult(err) {
  1770. err = Number(err);
  1771. if (!err) {
  1772. console.log('转接坐席结果成功-----seimin');
  1773. $scope.getState(1);
  1774. $.toaster({
  1775. priority: 'info',
  1776. title: '操作',
  1777. message: '转接坐席结果成功'
  1778. });
  1779. } else {
  1780. console.log('转接坐席结果失败-----seimin');
  1781. $.toaster({
  1782. priority: 'info',
  1783. title: '操作',
  1784. message: '转接坐席结果失败'
  1785. });
  1786. }
  1787. }
  1788. // 签入
  1789. $rootScope.jry_qianru = function () {
  1790. console.log($rootScope.jry_extnNumberObj.jry_extnNumber)
  1791. if(Object.keys($rootScope.jry_extnNumberObj.jry_extnNumber).length === 0){
  1792. $.toaster({
  1793. priority: 'info',
  1794. title: '警告',
  1795. message: '绑定分机不能为空'
  1796. });
  1797. return;
  1798. }
  1799. // 签入并绑定分机
  1800. // $rootScope.jry_extnNumberObj.jry_extnNumber.name 分机号
  1801. // $rootScope.user.id 坐席号(用户id)
  1802. tlwsa.tlaLogin($rootScope.user.id, 1, -1);
  1803. $rootScope.phoneNumber = $rootScope.user.id;
  1804. }
  1805. // 示闲
  1806. $rootScope.jry_shixian = function () {
  1807. tlwsa.tlaWca();
  1808. }
  1809. // 示忙
  1810. $rootScope.jry_shimang = function () {
  1811. tlwsa.tlaAcw();
  1812. }
  1813. // 签出
  1814. $rootScope.jry_qianchu = function () {
  1815. tlwsa.tlaLogoff();
  1816. }
  1817. // 呼叫坐席
  1818. // $scope.tlaCallagc = function () {
  1819. // tlwsa.tlaCallagc($rootScope.jry_extnNumberObj.tel1)
  1820. // }
  1821. // 呼叫外线
  1822. $scope.tlaCallout = function () {
  1823. // 选择目的号码
  1824. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  1825. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  1826. if(!reg1.test($rootScope.jry_extnNumberObj.tel1)&&!reg2.test($rootScope.jry_extnNumberObj.tel1)){
  1827. $.toaster({
  1828. priority: 'info',
  1829. title: '警告',
  1830. message: '请输入正确的手机号或座机号'
  1831. });
  1832. return;
  1833. }
  1834. tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  1835. }
  1836. // // 转移坐席
  1837. // $scope.tlaTransfertoagc = function () {
  1838. // tlwsa.tlaTransfertoagc($rootScope.jry_extnNumberObj.tel2)
  1839. // }
  1840. // 转移外线
  1841. $scope.tlaTransferout = function () {
  1842. // 选择转接号码
  1843. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  1844. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  1845. if(!reg1.test($rootScope.jry_extnNumberObj.tel2)&&!reg2.test($rootScope.jry_extnNumberObj.tel2)){
  1846. $.toaster({
  1847. priority: 'info',
  1848. title: '警告',
  1849. message: '请输入正确的手机号或座机号'
  1850. });
  1851. return;
  1852. }
  1853. tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  1854. }
  1855. })
  1856. }
  1857. $rootScope.jry_state = 'weiqianru';
  1858. window.addEventListener('load', function () {
  1859. if ($rootScope.isFuwutai) {
  1860. $rootScope.getExtnDirect();//seiminHj----1
  1861. }
  1862. })
  1863. //话机呼叫中心--结束
  1864. // 未接来电
  1865. $scope.jry_getUnanswered = function () {
  1866. var jry_data = {
  1867. idx: 0,
  1868. sum: 999,
  1869. "callRecord": {
  1870. "todayTime": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 00:00:00",
  1871. "todayTimeEnd": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 23:59:59",
  1872. }
  1873. }
  1874. api_bpm_data.fetchDataList("callRecord", jry_data).then(function (data) {
  1875. // fo0h
  1876. for (var i = 0; i < data.list.length; i++) {
  1877. 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()
  1878. }
  1879. $rootScope.jry_unansweredData = data.list;
  1880. });
  1881. }
  1882. // $scope.jry_getUnanswered();
  1883. // 来电号码回拨
  1884. $scope.jry_callBack = function (data) {
  1885. var callBackData = {
  1886. "callRecord": {
  1887. "id": data.id,
  1888. "isAnswered": "1"
  1889. }
  1890. };
  1891. api_bpm_data.updData("callRecord", callBackData).then(function (res) {
  1892. if (res) {
  1893. $scope.jry_getUnanswered();
  1894. dial(data.callerIdNumber)
  1895. }
  1896. });
  1897. if (data.department.id && data.requester) {
  1898. 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 } }
  1899. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1900. } else if (data.department.id) {
  1901. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  1902. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1903. } else {
  1904. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  1905. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1906. };
  1907. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  1908. }
  1909. //来电号码生成事件
  1910. $scope.jry_callToIncident = function (data) {
  1911. if (data.department.id && data.requester) {
  1912. 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 } }
  1913. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1914. } else if (data.department.id) {
  1915. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  1916. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1917. } else {
  1918. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  1919. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1920. }
  1921. }
  1922. $scope.onChangeadd = function (searchData) {
  1923. $scope.searchKey = searchData.account;
  1924. // $scope.searchDataadd = searchData;
  1925. var requesdata = angular.copy(searchData)
  1926. $scope.requester = requesdata;
  1927. }
  1928. $scope.refreshUseradd = function (searchKey) { //主题搜索
  1929. $scope.searchData = searchKey;
  1930. reashdata($scope.searchData);
  1931. }
  1932. $scope.getMydata = function (x) {
  1933. $scope.telephone = JSON.parse(x).phone;
  1934. $scope.searchField = $scope.telephone;
  1935. return $scope.searchField;
  1936. }
  1937. $scope.getMydataone = function (x) {
  1938. $scope.telephone = x;
  1939. $scope.searchField = $scope.telephone;
  1940. }
  1941. $scope.fildata = {
  1942. "idx": 0,
  1943. "sum": 10,
  1944. "flag": -1
  1945. }
  1946. function reashdata(item) {
  1947. if (item && item != "") {
  1948. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  1949. } else {
  1950. delete $scope.fildata.user;
  1951. }
  1952. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  1953. if (data.status == 200) {
  1954. $scope.myData = data.list;
  1955. }
  1956. })
  1957. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  1958. // if (response) {
  1959. // if (response.status = 200) {
  1960. // var myData = response;
  1961. // $scope.myData = myData.list;
  1962. // }
  1963. // }
  1964. // })
  1965. }
  1966. if (window.location && window.location.hash == "#/echart") {
  1967. } else {
  1968. reashdata();
  1969. }
  1970. $rootScope.end = function () {
  1971. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  1972. if (data.errno == 0) {
  1973. api_text.exit($rootScope.takes).then(function (data) {
  1974. if (data.errno == 0) {
  1975. $rootScope.statuscall = 0;
  1976. $scope.login = false
  1977. // SweetAlert.swal({
  1978. // title: "登出成功",
  1979. // text: "呼叫中心登出成功!",
  1980. // type: "success"
  1981. // });
  1982. // }else{SweetAlert.swal({
  1983. // title: "登出失败",
  1984. // text: "呼叫中心登出失败!",
  1985. // type: "error"
  1986. // });
  1987. }
  1988. })
  1989. }
  1990. })
  1991. }
  1992. $rootScope.dialout = function (gid, teleno) {
  1993. var telephone = "";
  1994. if (teleno && teleno.length > 4) {
  1995. telephone = '9' + teleno;
  1996. } else {
  1997. // telephone = '*01' + teleno + '*';
  1998. telephone = teleno;
  1999. }
  2000. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  2001. if (data.errno == 0) {
  2002. // $rootScope.statuscall = 3;
  2003. $rootScope.callout = true;
  2004. // $rootScope.phone=teleno;
  2005. }
  2006. })
  2007. }
  2008. // $scope.busy=false;
  2009. $rootScope.setbusy = function () {
  2010. api_text.setbusy($rootScope.takes).then(function (data) {
  2011. if (data.errno == 0) {
  2012. $rootScope.statecall = 2;
  2013. $scope.busy = true;
  2014. }
  2015. })
  2016. }
  2017. $rootScope.setidle = function () {
  2018. api_text.setidle($rootScope.takes).then(function (data) {
  2019. if (data.errno == 0) {
  2020. $rootScope.statecall = 1;
  2021. $scope.busy = false;
  2022. }
  2023. })
  2024. }
  2025. $rootScope.inittrans = function (telephone) {
  2026. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  2027. if (data.errno == 0) {
  2028. // $scope.status=9
  2029. }
  2030. })
  2031. }
  2032. $rootScope.comptrans = function () {
  2033. api_text.comptrans($rootScope.takes).then(function (data) {
  2034. if (data.errno == 0) {
  2035. $rootScope.statuscall = 1;
  2036. }
  2037. })
  2038. }
  2039. $rootScope.takeup = function () {
  2040. api_text.offhook($rootScope.takes).then(function (data) {
  2041. if (data.errno == 0) {
  2042. $rootScope.statuscall = 3;
  2043. }
  2044. })
  2045. }
  2046. $rootScope.takedown = function () {
  2047. api_text.onhook($rootScope.takes).then(function (data) {
  2048. if (data.errno == 0) {
  2049. $rootScope.statuscall = 1;
  2050. }
  2051. })
  2052. }
  2053. $rootScope.saveData = function (selectdata) {
  2054. var modalInstance = $modal.open({
  2055. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  2056. controller: function ($scope, $modalInstance, api_bpm_data) {
  2057. $scope.worktimedata = {};
  2058. $scope.worktimedata = selectdata;
  2059. $scope.cancel = function () {
  2060. $modalInstance.dismiss('cancel');
  2061. };
  2062. $scope.savercode = function (worktimedata) {
  2063. var fildata = {
  2064. "scheduleclass": {
  2065. "id": selectdata.id,
  2066. "code": worktimedata.code,
  2067. "name": worktimedata.title,
  2068. "person": worktimedata.person,
  2069. "description": worktimedata.description,
  2070. "startTime": worktimedata.startTime,
  2071. "endTime": worktimedata.endTime,
  2072. "shiftTime": selectdata.shiftTime,
  2073. "succeedTime": selectdata.succeedTime,
  2074. "isTemplate": worktimedata.isTemplate
  2075. }
  2076. }
  2077. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  2078. if (response) {
  2079. if (response.status == 200) {
  2080. SweetAlert.swal({
  2081. title: "修改成功!",
  2082. type: "success"
  2083. }, function () {
  2084. // $scope.refreshData('expand-right', defaultFilterData);
  2085. })
  2086. } else {
  2087. SweetAlert.swal({
  2088. title: "修改失败!",
  2089. type: "error"
  2090. })
  2091. }
  2092. }
  2093. })
  2094. $modalInstance.close();
  2095. }
  2096. }
  2097. });
  2098. }
  2099. $rootScope.changepassword = function (data1, size) {
  2100. var modalInstance = $modal.open({
  2101. templateUrl: 'assets/views/changepassword.html',
  2102. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  2103. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  2104. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  2105. }
  2106. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  2107. $modalInstance.dismiss('cancel');
  2108. // console.log('pwd=' + pwd + '+' + pwd_2);
  2109. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  2110. if (pwd == pwd_2) {
  2111. var data2 = {};
  2112. data2["originalPwd"] = originalPwd;
  2113. data2["userid"] = $rootScope.user.id;
  2114. data2["pwd"] = pwd;
  2115. api_login.uppwd(data2).then(function (response) {
  2116. var myData = Restangular.stripRestangular(response);
  2117. if (myData.status == 200) {
  2118. SweetAlert.swal({
  2119. title: "保存成功!",
  2120. type: "success",
  2121. confirmButtonColor: "#007AFF"
  2122. });
  2123. } else {
  2124. SweetAlert.swal({
  2125. title: "保存失败!",
  2126. text: "输入旧密码错误,请重新输入!",
  2127. type: "error"
  2128. });
  2129. }
  2130. })
  2131. } else {
  2132. SweetAlert.swal({
  2133. title: "两次输入的新密码不相同!",
  2134. text: "输入错误,请重新输入!",
  2135. type: "error"
  2136. });
  2137. }
  2138. // }else{
  2139. // SweetAlert.swal({
  2140. // title: "密码不能为空!",
  2141. // text: "请输入密码!",
  2142. // type: "error"
  2143. // });
  2144. // }
  2145. }
  2146. },
  2147. size: size,
  2148. resolve: {
  2149. items: function () {
  2150. return {
  2151. fetchItems: function (filterData, APIService) { }
  2152. };
  2153. },
  2154. }
  2155. });
  2156. }
  2157. // $rootScope.getnochildpending = function() {
  2158. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2159. // angular.forEach($rootScope.userMenus, function(item) {
  2160. // item.tipnum = 1;
  2161. // })
  2162. // }
  2163. // }
  2164. // $rootScope.getchildpending = function(cantdata) {
  2165. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2166. // angular.forEach($rootScope.userMenus, function(item) {
  2167. // item.tipnum = 1;
  2168. // angular.forEach(item, function(index) {
  2169. // index.tipnum = 18;
  2170. // })
  2171. // })
  2172. // }
  2173. // }
  2174. $rootScope.getpending = function () {
  2175. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2176. if ($rootScope.user.group) {
  2177. var groupArr = [];
  2178. for (var i = 0; i < $rootScope.user.group.length; i++) {
  2179. groupArr.push($rootScope.user.group[i].id)
  2180. }
  2181. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  2182. angular.forEach($rootScope.userMenus, function (item, i) {
  2183. item.tipshow = false;
  2184. if (response) {
  2185. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  2186. if (item.id == 58) {
  2187. item.tipshow = true;
  2188. }
  2189. }
  2190. if (response.inspectionCount > 0) {
  2191. if (item.id == 27) {
  2192. item.tipshow = true;
  2193. }
  2194. }
  2195. if (response.incidentCount > 0) {
  2196. if (item.id == 2) {
  2197. item.tipshow = true;
  2198. }
  2199. }
  2200. if (response.releaseCount > 0) {
  2201. if (item.id == 1215) {
  2202. item.tipshow = true;
  2203. }
  2204. }
  2205. if (response.solutionCount > 0) {
  2206. if (item.id == 21) {
  2207. item.tipshow = true;
  2208. }
  2209. }
  2210. if (response.changeCount > 0) {
  2211. if (item.id == 1212) {
  2212. item.tipshow = true;
  2213. }
  2214. }
  2215. if (response.problemCount > 0) {
  2216. if (item.id == 1209) {
  2217. item.tipshow = true;
  2218. }
  2219. }
  2220. if (response.applicationForm > 0) {
  2221. if (item.id == 1221) {
  2222. item.tipshow = true;
  2223. }
  2224. }
  2225. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2226. if (item.id == 21) {
  2227. item.tipshow = true;
  2228. }
  2229. }
  2230. if (item.children) {
  2231. angular.forEach(item.children, function (index) {
  2232. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  2233. if (index.id == 1208) {
  2234. if (response.hjzxCount < 100) {
  2235. index.tipnum = response.hjzxCount;
  2236. } else {
  2237. index.tipnum = "99+";
  2238. }
  2239. }
  2240. }
  2241. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  2242. if (index.id == 59) {
  2243. if (response.wechatWarningCount < 100) {
  2244. index.tipnum = response.wechatWarningCount;
  2245. } else {
  2246. index.tipnum = "99+";
  2247. }
  2248. }
  2249. }
  2250. if (response.problemCount !== null && response.problemCount !== undefined) {
  2251. if (index.id == 1210) {
  2252. if (response.problemCount < 100) {
  2253. index.tipnum = response.problemCount;
  2254. } else {
  2255. index.tipnum = "99+";
  2256. }
  2257. }
  2258. }
  2259. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  2260. if (index.id == 1216) {
  2261. if (response.releaseCount < 100) {
  2262. index.tipnum = response.releaseCount;
  2263. } else {
  2264. index.tipnum = "99+";
  2265. }
  2266. }
  2267. }
  2268. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  2269. if (index.id == 147) {
  2270. if (response.inspectionCount < 100) {
  2271. index.tipnum = response.inspectionCount;
  2272. } else {
  2273. index.tipnum = "99+";
  2274. }
  2275. }
  2276. }
  2277. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  2278. if (index.id == 23) {
  2279. if (response.solutionCount < 100) {
  2280. index.tipnum = response.solutionCount;
  2281. } else {
  2282. index.tipnum = "99+";
  2283. }
  2284. }
  2285. }
  2286. if (response.changeCount !== null && response.changeCount !== undefined) {
  2287. if (index.id == 1213) {
  2288. if (response.changeCount < 100) {
  2289. index.tipnum = response.changeCount;
  2290. } else {
  2291. index.tipnum = "99+";
  2292. }
  2293. }
  2294. }
  2295. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  2296. if (index.id == 3) {
  2297. if (response.incidentCount < 100) {
  2298. index.tipnum = response.incidentCount;
  2299. } else {
  2300. index.tipnum = "99+";
  2301. }
  2302. }
  2303. }
  2304. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  2305. if (index.id == 1231) {
  2306. if (response.applicationForm < 100) {
  2307. index.tipnum = response.applicationForm;
  2308. } else {
  2309. index.tipnum = "99+";
  2310. }
  2311. }
  2312. }
  2313. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2314. if (index.id == 23) {
  2315. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  2316. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2317. } else {
  2318. index.tipnum = "99+";
  2319. }
  2320. }
  2321. }
  2322. })
  2323. }
  2324. }
  2325. })
  2326. // return $rootScope.userMenus;
  2327. // $scope.recordpending = response.;
  2328. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2329. })
  2330. } else {
  2331. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  2332. }
  2333. }
  2334. // console.log($rootScope.userMenus);
  2335. }
  2336. $rootScope.userMenus = [];
  2337. var getMenus = function () {
  2338. function convertListToTree(data, treeMap) {
  2339. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  2340. var root = null; //Initially set our loop to null
  2341. var parentNode = null;
  2342. //loop over data
  2343. for (var i = 0; i < data.length; i++) {
  2344. // data[i].id = Number(data[i].id);
  2345. var datum = data[i];
  2346. //each node will have children, so let's give it a "children" poperty
  2347. datum.children = [];
  2348. //add an entry for this node to the map so that any future children can
  2349. //lookup the parent
  2350. idToNodeMap[datum.id] = datum;
  2351. //Does this node have a parent?
  2352. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  2353. //Doesn't look like it, so this node is the root of the tree
  2354. root = datum;
  2355. treeMap[datum.id] = root;
  2356. } else {
  2357. //This node has a parent, so let's look it up using the id
  2358. parentNode = idToNodeMap[datum.parentid];
  2359. //We don't need this property, so let's delete it.
  2360. //delete datum.parentid;
  2361. //Let's add the current node as a child of the parent node.
  2362. parentNode.children.push(datum);
  2363. }
  2364. }
  2365. return root;
  2366. }
  2367. function convertParentToChildList(data) {
  2368. var treeMap = {};
  2369. var list = [];
  2370. convertListToTree(data, treeMap);
  2371. angular.forEach(treeMap, function (item) {
  2372. list.push(item);
  2373. });
  2374. list = window._.sortBy(list, function (o) {
  2375. return o.orders;
  2376. });
  2377. return list;
  2378. }
  2379. //if(userMenus.length==0){
  2380. var userMenus = [];
  2381. var idMapMenu = {};
  2382. if ($rootScope.user) {
  2383. if ($rootScope.user.menu) {
  2384. var allJurisdiction2 = $rootScope.user.menu;
  2385. var onlyMenu2 = [];
  2386. for (var i = 0; i < allJurisdiction2.length; i++) {
  2387. if (allJurisdiction2[i].event == "1") {
  2388. onlyMenu2.push(allJurisdiction2[i])
  2389. }
  2390. }
  2391. // userMenus = convertParentToChildList($rootScope.user.menu);
  2392. userMenus = convertParentToChildList(onlyMenu2);
  2393. }
  2394. }
  2395. //}
  2396. $rootScope.userMenus = userMenus;
  2397. if ($rootScope.userMenus.length > 0) {
  2398. $rootScope.getpending();
  2399. // setInterval($rootScope.getpending(), 30000);
  2400. }
  2401. return userMenus;
  2402. }
  2403. setInterval(function () {
  2404. if ($rootScope.userMenus.length > 0) {
  2405. $rootScope.getpending()
  2406. $rootScope.getMsgNum($rootScope.user.id)
  2407. }
  2408. }, 5000);
  2409. getMenus();
  2410. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  2411. $rootScope.logout = function () {
  2412. // var userid =data.id;
  2413. // console.log(' userid='+JSON.stringify( userid));
  2414. //单点登录
  2415. if (localStorage.getItem('isSSo') === '1') {
  2416. sessionStorage.clear();
  2417. localStorage.clear();
  2418. location.href = 'http://' + location.hostname + ':8080/pc_logout.jsp'
  2419. } else {
  2420. $auth.signOut()
  2421. .then(function (resp) {
  2422. // $auth.deleteData('auth_headers')
  2423. sessionStorage.clear();
  2424. localStorage.clear();
  2425. if ($rootScope.isFuwutai) {
  2426. tlwsa.tlaClose();
  2427. $.toaster({
  2428. priority: 'info',
  2429. title: '操作',
  2430. message: '呼叫中心断开连接'
  2431. });
  2432. }
  2433. $state.go("login.signin");
  2434. })
  2435. .catch(function (resp) { });
  2436. }
  2437. //$cookieStore.remove("userObm");
  2438. //$cookieStore.remove("menuObm");
  2439. //$cookieStore.remove("session");
  2440. //$rootScope.user = undefined;
  2441. //$rootScope.menus = undefined;
  2442. //$rootScope.nickname = undefined;
  2443. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  2444. // //logout: function(noServerLogout){
  2445. // window.sessionStorage.clear();
  2446. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  2447. // //},
  2448. }
  2449. // 快速建单
  2450. $rootScope.newOrder = function () {
  2451. $state.go('app.newOrder');
  2452. }
  2453. // save settings to local storage
  2454. if (angular.isDefined($localStorage.layout)) {
  2455. $scope.app.layout = $localStorage.layout;
  2456. } else {
  2457. $localStorage.layout = $scope.app.layout;
  2458. }
  2459. $scope.$watch('app.layout', function () {
  2460. // save to local storage
  2461. $localStorage.layout = $scope.app.layout;
  2462. }, true);
  2463. //global function to scroll page up
  2464. $scope.toTheTop = function () {
  2465. $document.scrollTopAnimated(0, 600);
  2466. };
  2467. // angular translate
  2468. // ----------------------
  2469. $scope.language = {
  2470. // Handles language dropdown
  2471. listIsOpen: false,
  2472. // list of available languages
  2473. available: {
  2474. 'en': 'English',
  2475. 'it_IT': 'Italiano',
  2476. 'de_DE': 'Deutsch',
  2477. 'zh_cn': 'Chinese'
  2478. },
  2479. // display always the current ui language
  2480. init: function () {
  2481. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  2482. var preferredLanguage = $translate.preferredLanguage();
  2483. // we know we have set a preferred one in app.config
  2484. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  2485. },
  2486. set: function (localeId, ev) {
  2487. $translate.use(localeId);
  2488. $scope.language.selected = $scope.language.available[localeId];
  2489. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  2490. }
  2491. };
  2492. $scope.language.init();
  2493. // Function that find the exact height and width of the viewport in a cross-browser way
  2494. var viewport = function () {
  2495. var e = window,
  2496. a = 'inner';
  2497. if (!('innerWidth' in window)) {
  2498. a = 'client';
  2499. e = document.documentElement || document.body;
  2500. }
  2501. return {
  2502. width: e[a + 'Width'],
  2503. height: e[a + 'Height']
  2504. };
  2505. };
  2506. // function that adds information in a scope of the height and width of the page
  2507. $scope.getWindowDimensions = function () {
  2508. return {
  2509. 'h': viewport().height,
  2510. 'w': viewport().width
  2511. };
  2512. };
  2513. // Detect when window is resized and set some variables
  2514. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  2515. $scope.windowHeight = newValue.h;
  2516. $scope.windowWidth = newValue.w;
  2517. if (newValue.w >= 992) {
  2518. $scope.isLargeDevice = true;
  2519. } else {
  2520. $scope.isLargeDevice = false;
  2521. }
  2522. if (newValue.w < 992) {
  2523. $scope.isSmallDevice = true;
  2524. } else {
  2525. $scope.isSmallDevice = false;
  2526. }
  2527. if (newValue.w <= 768) {
  2528. $scope.isMobileDevice = true;
  2529. } else {
  2530. $scope.isMobileDevice = false;
  2531. }
  2532. }, true);
  2533. // Apply on resize
  2534. $win.on('resize', function () {
  2535. $scope.$apply();
  2536. });
  2537. $rootScope.app.layout.isNavbarFixed = false;
  2538. $rootScope.app.layout.isSidebarFixed = false;
  2539. $rootScope.app.layout.isFooterFixed = false;
  2540. $scope.login_signquick = function (Requesteruserinform) {
  2541. $rootScope.statuscall = 1;
  2542. $scope.loginForm = {
  2543. username: Requesteruserinform.username,
  2544. password: Requesteruserinform.password
  2545. }
  2546. $auth.submitLogin($scope.loginForm)
  2547. .then(function (resp) {
  2548. localStorage.setItem("jry_user", JSON.stringify(resp));
  2549. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  2550. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  2551. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  2552. var onlyMenu = [];
  2553. for (var i = 0; i < allJurisdiction.length; i++) {
  2554. if (allJurisdiction[i].event == "1") {
  2555. onlyMenu.push(allJurisdiction[i])
  2556. }
  2557. };
  2558. $rootScope.userMenus = onlyMenu;
  2559. getMenus();
  2560. if (resp.error != 500) {
  2561. // $state.go('app.dashboard');
  2562. $rootScope.app.isLoginFixed = false;
  2563. } else {
  2564. resp.error = "";
  2565. $scope.loginForm.password = "";
  2566. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  2567. }
  2568. })
  2569. .catch(function (resp) {
  2570. $scope.loginForm.password = "";
  2571. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  2572. });
  2573. }
  2574. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  2575. var theRequest = {};
  2576. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  2577. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  2578. var str = url.substr(index + 1);
  2579. var strs = str.split("&");
  2580. for (var i = 0; i < strs.length; i++) {
  2581. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  2582. }
  2583. // return theRequest;
  2584. $scope.login_signquick(theRequest)
  2585. }
  2586. // $scope.casUserId = window.location.search;
  2587. // $scope.loginForm = {
  2588. // username: theRequest[0].split("=")[1],
  2589. // password: theRequest[1].split("=")[1]
  2590. // }
  2591. // $scope.lodingstyle = 'nodata';
  2592. var userAgent = window.navigator.userAgent.toLowerCase();
  2593. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  2594. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  2595. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  2596. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  2597. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  2598. if (isOpera) {
  2599. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  2600. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  2601. }
  2602. if (isIE) {
  2603. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  2604. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  2605. }
  2606. if (isFF) {
  2607. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  2608. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  2609. }
  2610. if (isSafari) {
  2611. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  2612. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  2613. }
  2614. if (isChrome) {
  2615. // login_sign();
  2616. $rootScope.app.isChrome = false;
  2617. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  2618. } else {
  2619. $rootScope.app.isChrome = true;
  2620. $scope.checkchrome = '';
  2621. // return alert("访问失败,请用Chrome浏览器访问!");
  2622. }
  2623. // }
  2624. // $scope.handleloginEnter = function(e) {
  2625. // if (e.keyCode == 13) {
  2626. // $scope.handleLoginClick();
  2627. // }
  2628. // };
  2629. // if (document.getElementById("isWatch").value == "true") {
  2630. // $scope.isHanderuser = true;
  2631. // } else {
  2632. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  2633. // $scope.isHanderuser = false;
  2634. // $scope.login_sign();
  2635. // }
  2636. // }
  2637. // $scope.viewType = "password";
  2638. // $scope.isPassword = true;
  2639. // $scope.toggleView = function() {
  2640. // $scope.isPassword = !$scope.isPassword;
  2641. // $scope.viewType = $scope.isPassword ? "password" : "text";
  2642. // }
  2643. // $scope.handleSignOutBtnClick = function() {
  2644. // $auth.signOut()
  2645. // .then(function(resp) {
  2646. // // handle success response
  2647. // })
  2648. // .catch(function(resp) {
  2649. // // handle error response
  2650. // });
  2651. // };
  2652. // }
  2653. // }
  2654. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  2655. // } else {
  2656. // $scope.loginstart();
  2657. // }
  2658. //websocket 信息中心
  2659. console.log(atmosphere)
  2660. var socket = atmosphere;
  2661. var subSocket;
  2662. // We are now ready to cut the request
  2663. var request = {
  2664. url: 'ws://192.168.199.150:8080/messagestation/cache',
  2665. contentType: "application/json",
  2666. shared: true, // 标签共享
  2667. trackMessageLength: true, //校验数据完整性
  2668. transport: 'websocket'
  2669. };
  2670. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  2671. request.onOpen = function (response) {
  2672. console.log(response)
  2673. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  2674. // alert("开始连接")
  2675. };
  2676. request.onMessage = function (response) {
  2677. var message = response.responseBody;
  2678. // alert("连接成功")
  2679. console.log(message)
  2680. try {
  2681. var json = JSON.parse(message);
  2682. console.log(json.noRead)
  2683. $scope.noReadData = json.noRead
  2684. } catch (e) {
  2685. console.log('呵呵哒: ', message);
  2686. return;
  2687. }
  2688. };
  2689. request.onClose = function (response) {
  2690. // alert("连接结束")
  2691. }
  2692. request.onError = function (response) {
  2693. // alert('连接失败')
  2694. };
  2695. //信息中心模态框
  2696. var loginUser = $rootScope.user;
  2697. // if(loginUser){
  2698. // // 未读消息数量
  2699. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  2700. // if (data.status == 200) {
  2701. // $scope.noReadData=data.totalNum
  2702. // // $rootScope.option.all = $rootScope.all;
  2703. // } else {
  2704. // $scope.noReadData=0
  2705. // }
  2706. // })
  2707. // }
  2708. // $scope.noReadData=($rootScope.noReadData||0)
  2709. // // $rootScope.all = 5;
  2710. // setTimeout(function() {
  2711. // console.log($scope.noReadData)
  2712. // }, 500)
  2713. $rootScope.wt_messages = function () {
  2714. var modalInstance = $modal.open({
  2715. templateUrl: '../../../assets/views/wt_messages.html',
  2716. controller: function ($scope, $modalInstance) {
  2717. $rootScope.msgData = {
  2718. idx: 0,
  2719. sum: 5,
  2720. messageStation: {
  2721. readStatus: 0,
  2722. userId: $rootScope.user.id
  2723. }
  2724. }
  2725. // 关闭
  2726. $scope.closeModel = function () {
  2727. modalInstance.close();
  2728. }
  2729. $scope.getMsgData = function () {
  2730. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2731. if (data) {
  2732. $rootScope.msg = data.list
  2733. $rootScope.all = data.pageCount;
  2734. $scope.wt_msgData = data
  2735. $rootScope.noReadData = data.totalNum
  2736. }
  2737. })
  2738. }
  2739. $scope.getMsgData()
  2740. $scope.message_type = 2;
  2741. $scope.message_no = function (type) { //未读1
  2742. $scope.wt_msgData = {};
  2743. $scope.message_type = type;
  2744. $rootScope.msgData.messageStation.readStatus = 0,
  2745. // $rootScope.option.curr = 1;
  2746. $rootScope.msgData.idx = 0;
  2747. // console.log($rootScope.option.curr)
  2748. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2749. $scope.msg_yesType = true;
  2750. if (data.status == 200) {
  2751. $scope.msg_yesType = false
  2752. $scope.wt_msgData = data
  2753. $rootScope.msg = data.list
  2754. $rootScope.all = data.pageCount;
  2755. $rootScope.noReadData = data.totalNum;
  2756. // $rootScope.option.all = $rootScope.all;
  2757. } else {
  2758. $scope.msg_yesType = true;
  2759. }
  2760. })
  2761. }
  2762. $scope.message_yes = function (type) { //已读0
  2763. $scope.wt_msgData = {};
  2764. $scope.message_type = type;
  2765. $rootScope.msgData.messageStation.readStatus = 1,
  2766. $rootScope.msgData.idx = 0;
  2767. // $rootScope.option.curr = 1;
  2768. // console.log($rootScope.option.curr)
  2769. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2770. $scope.msg_noType = true;
  2771. if (data.status == 200) {
  2772. $scope.msg_noType = false
  2773. $scope.wt_msgData = data
  2774. $rootScope.msg = data.list;
  2775. $rootScope.all = data.pageCount;
  2776. // $rootScope.option.all = $rootScope.all;
  2777. } else {
  2778. $scope.msg_noType = true
  2779. }
  2780. })
  2781. };
  2782. $scope.sBtn = function () {
  2783. // console.log($rootScope.msgData)
  2784. // console.log($scope.wt_msgData)
  2785. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  2786. console.log($rootScope.msgData)
  2787. $scope.getMsgData()
  2788. }
  2789. $scope.xBtn = function () {
  2790. // console.log($rootScope.msgData)
  2791. // console.log($scope.wt_msgData)
  2792. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  2793. console.log($rootScope.msgData)
  2794. $scope.getMsgData()
  2795. }
  2796. $scope.redIn = function (data) {
  2797. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  2798. $scope.messageStation = {
  2799. messageStation: {
  2800. id: data.id,
  2801. readStatus: 1,
  2802. readTime: start
  2803. }
  2804. }
  2805. api_msg.updateDataList($scope.messageStation).then(function (data) {
  2806. console.log(data);
  2807. if (data.status == 200) {
  2808. $rootScope.msgData.messageStation.readStatus = 0,
  2809. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2810. $rootScope.msg = data.list
  2811. $rootScope.all = data.pageCount;
  2812. $rootScope.noReadData = data.totalNum;
  2813. })
  2814. }
  2815. })
  2816. };
  2817. },
  2818. size: 'lg',
  2819. resolve: {
  2820. }
  2821. })
  2822. }
  2823. }
  2824. ]);
  2825. //消息中心分页组件
  2826. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  2827. $rootScope.option = {
  2828. curr: 1, //当前页数
  2829. all: $rootScope.all, //总页数
  2830. count: 5, //最多显示的页数,默认为10
  2831. //点击页数的回调函数,参数page为点击的页数
  2832. click: function (page) {
  2833. $rootScope.msgData.idx = page - 1;
  2834. //这里可以写跳转到某个页面等...
  2835. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2836. $rootScope.msg = data.list
  2837. $rootScope.all = data.pageCount;
  2838. $rootScope.option.all = $rootScope.all;
  2839. })
  2840. }
  2841. }
  2842. }]);
  2843. app.directive('myPagination', function () {
  2844. return {
  2845. restrict: 'EA',
  2846. replace: true,
  2847. rootScope: {
  2848. option: '=pageOption'
  2849. },
  2850. controller: 'msgCtrl',
  2851. template: '<ul class="pagination">' +
  2852. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  2853. '<a href="javascript:;">{{p}}</a>' +
  2854. '</li>' +
  2855. '</ul>',
  2856. link: function ($rootScope) {
  2857. //容错处理
  2858. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  2859. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  2860. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  2861. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  2862. //得到显示页数的数组
  2863. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  2864. //绑定点击事件
  2865. $rootScope.pageClick = function (page) {
  2866. if (page == '«') {
  2867. page = parseInt($rootScope.option.curr) - 1;
  2868. } else if (page == '»') {
  2869. page = parseInt($rootScope.option.curr) + 1;
  2870. }
  2871. if (page < 1) page = 1;
  2872. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  2873. //点击相同的页数 不执行点击事件
  2874. if (page == $rootScope.option.curr) return;
  2875. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  2876. $rootScope.option.click(page);
  2877. $rootScope.option.curr = page;
  2878. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  2879. }
  2880. };
  2881. //返回页数范围(用来遍历)
  2882. function getRange(curr, all, count) {
  2883. //计算显示的页数
  2884. // console.log(curr, all, count)
  2885. curr = parseInt(curr);
  2886. all = parseInt(all);
  2887. count = parseInt(count);
  2888. var from = curr - parseInt(count / 2);
  2889. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  2890. //显示的页数容处理
  2891. if (from <= 0) {
  2892. from = 1;
  2893. to = from + count - 1;
  2894. if (to > all) {
  2895. to = all;
  2896. }
  2897. }
  2898. if (to > all) {
  2899. to = all;
  2900. from = to - count + 1;
  2901. if (from <= 0) {
  2902. from = 1;
  2903. }
  2904. }
  2905. var range = [];
  2906. for (var i = from; i <= to; i++) {
  2907. range.push(i);
  2908. }
  2909. range.push('»');
  2910. range.unshift('«');
  2911. return range;
  2912. }
  2913. }
  2914. }
  2915. });
  2916. app.service('Myservice', function () {
  2917. return {
  2918. };
  2919. });
  2920. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  2921. // console.log(bh)
  2922. // if(bh>=0&&bh<=53){
  2923. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  2924. // }else{
  2925. // $('#sidebar').css('padding-bottom', 0 + 'px')
  2926. // }
  2927. window.onscroll = function () {
  2928. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  2929. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  2930. } else {
  2931. $('#sidebar').css('padding-top', '0')
  2932. }
  2933. // console.log(window.pageYOffset)
  2934. // console.log(window.innerHeight)
  2935. // console.log(document.body.scrollHeight)
  2936. // 底部padding
  2937. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  2938. // console.log(bh)
  2939. // if(bh>=0&&bh<=53){
  2940. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  2941. // }else{
  2942. // $('#sidebar').css('padding-bottom', 0 + 'px')
  2943. // }
  2944. }