mainCtrl.js 179 KB

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