mainCtrl.js 127 KB

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