mainCtrl.js 128 KB

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