mainCtrl.js 129 KB

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