mainCtrl.js 177 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782
  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 = false;
  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 = true;
  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 = false;
  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 = true;
  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. api_text.start(phone, $rootScope.user.id).then(function(data) {
  864. var token = data.token;
  865. $rootScope.takes = token;
  866. api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  867. api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  868. if (data.errno == 0) {
  869. localStorage.setItem('hk_phone',phone);
  870. $rootScope.setidle();
  871. $scope.login = true;
  872. $rootScope.statuscall = 1;
  873. $rootScope.callout = 0;
  874. // function hello() {
  875. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  876. // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  877. // };
  878. // window.setTimeout("hello()", 1000);
  879. // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  880. function reconnect() {
  881. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  882. var ws = new WebSocket('ws://192.168.77.57:8088/IXServer/messagestation/hjzx');
  883. var register = { "msgtype": "login", "adn": phone };
  884. ws.onopen = function() {
  885. heartCheck.start();
  886. ws.send(JSON.stringify(register));
  887. };
  888. ws.onmessage = function(evt) {
  889. heartCheck.reset();
  890. if (evt.data == "HeartBeat") {
  891. } else {
  892. var mydata = JSON.parse(evt.data);
  893. $scope.filterData = [];
  894. if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  895. $rootScope.$apply(function() {
  896. $rootScope.statuscall = 2;
  897. $rootScope.callout = 1;
  898. });
  899. $rootScope.phone = mydata.ano;
  900. var Notification = window.Notification;
  901. Notification.requestPermission();
  902. var n = new Notification("你有来电", {
  903. body: "来电号码:" + mydata.ano,
  904. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  905. // onclick: function onNotificationClicked() {
  906. // console.log('Notification clicked.');
  907. // }
  908. });
  909. } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  910. $rootScope.callout = 2;
  911. } else if (mydata.evttype == "ringstop") {
  912. // $rootScope.status=7;
  913. // $rootScope.$apply(function() {
  914. $rootScope.statuscall = 1;
  915. // });
  916. $rootScope.phone = ""
  917. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout == 2) {
  918. if (mydata.status && mydata.status == '1') {
  919. $rootScope.$apply(function() {
  920. $rootScope.statuscall = 1;
  921. });
  922. $rootScope.phone = "";
  923. } else if (mydata.status && mydata.status != '1') {
  924. $rootScope.$apply(function() {
  925. $rootScope.statuscall = 3;
  926. });
  927. }
  928. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout == 1) {
  929. if ($rootScope.phone != "") {
  930. if (mydata.status && mydata.status == '1') { //挂机
  931. $rootScope.$apply(function() {
  932. $rootScope.statuscall = 1;
  933. $rootScope.callout = 0;
  934. });
  935. // console.log("挂机");
  936. // if ($rootScope.statecall == 1 && !$rootScope.isSetidle) {
  937. // $rootScope.setbusy();
  938. // }
  939. } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2 && $rootScope.callout == 1) { //摘机
  940. $rootScope.status = 6
  941. $rootScope.statuscall = 3;
  942. $rootScope.isSetidle = false;
  943. $rootScope.app.layout.isSidebarClosed = true;
  944. // console.log("摘机");
  945. // console.log(mydata);
  946. api_text.getcdrid($rootScope.takes).then(function(response) {
  947. if (response.cdrid) {
  948. var cdrid = response.cdrid;
  949. // var response={cdrid:'219023836'}
  950. var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  951. api_user_data.fetchDataList('requester', filterData).then(function(data) {
  952. var myData = Restangular.stripRestangular(data);
  953. // $rootScope.phone="";
  954. if (myData.list.length == 0) {
  955. var modalInstance = $modal.open({
  956. backdrop: "static",
  957. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  958. controller: function($scope, $modalInstance, api_user_data, api_wechatfile, SweetAlert) {
  959. $modalInstance.SweetAlert = SweetAlert;
  960. $scope.title = "新增报修人";
  961. $scope.requester = {};
  962. $scope.onChangeadd = function(searchData) {
  963. $scope.searchKey = searchData.account;
  964. // $scope.searchDataadd = searchData;
  965. var requesdata = angular.copy(searchData)
  966. // if (requesdata.mphone) {
  967. // delete requesdata.mphone;
  968. // }
  969. if (requesdata.telephone) {
  970. delete requesdata.telephone;
  971. }
  972. angular.extend($scope.requester, requesdata);
  973. }
  974. $scope.refreshUseradd = function(searchKey) { //请求人搜索
  975. $scope.requester.account = searchKey;
  976. $scope.searchData = searchKey;
  977. serchdataadd(searchKey);
  978. }
  979. $scope.getMydata = function(x) {
  980. var reqestdatap = JSON.parse(x[0])
  981. if ($scope.requester.telephone) {
  982. delete reqestdatap.telephone;
  983. }
  984. $scope.searchField = JSON.parse(x[0]).account;
  985. angular.extend($scope.requester, reqestdatap);
  986. // if ($scope.requester.areaDTO && $scope.requester.areaDTO.id && $scope.requester.areaDTO.id != "") {
  987. // api_user_data.fetchDataList('place', { place: { areaId: $scope.requester.areaDTO.id }, idx: 0, sum: 1000 }).then(function(response) {
  988. // if (response.status == 200) {
  989. // $scope.places = response.list;
  990. // }
  991. // })
  992. // }
  993. // $scope.searchField = JSON.parse(x[0]).account;
  994. // $scope.requester = JSON.parse(x[0]);
  995. console.log($scope.requester);
  996. $scope.refreshArea('');
  997. $scope.refresh('');
  998. }
  999. $scope.getMydataone = function(x) {
  1000. $scope.searchField = x;
  1001. $scope.requester.account = x;
  1002. }
  1003. serchdataadd();
  1004. function serchdataadd(searchKey) {
  1005. if (searchKey) {
  1006. var filterData = {
  1007. 'requester': {
  1008. 'searchKey': searchKey,
  1009. },
  1010. idx: 0,
  1011. sum: 10
  1012. };
  1013. } else {
  1014. var filterData = {
  1015. idx: 0,
  1016. sum: 10
  1017. };
  1018. }
  1019. api_user_data.fetchDataList('requester', filterData).then(function(response) {
  1020. var myData = response;
  1021. $scope.myData = myData.list;
  1022. });
  1023. }
  1024. api_user_data.fetchDataList('branch', { idx: 0, sum: 100 }).then(function(response) {
  1025. if (response.status == 200) {
  1026. $scope.branchs = response.list;
  1027. }
  1028. })
  1029. // api_user_data.fetchDataList('place', { idx: 0, sum: 1000 }).then(function(response) {
  1030. // if (response.status == 200) {
  1031. // $scope.places = response.list;
  1032. // }
  1033. // }) //地点
  1034. // api_user_data.fetchDataList('requesterType', { idx: 0, sum: 100 }).then(function(response) {
  1035. // if (response.status == 200) {
  1036. // $scope.networktypes = response.list;
  1037. // }
  1038. // })
  1039. api_wechatfile.getDictionary({
  1040. "key": "requester_type",
  1041. "type": "list"
  1042. }).then(function (response) {
  1043. // if (response.status == 200) {
  1044. $scope.networktypes = response;
  1045. // }
  1046. })
  1047. $scope.onChangeBranch = function (item) {
  1048. delete $scope.requester.place;
  1049. console.log($scope.requester, 'changeArea');
  1050. api_user_data
  1051. .fetchDataList("area", {
  1052. area: {
  1053. branch: item.id,
  1054. },
  1055. idx: 0,
  1056. sum: 1000,
  1057. })
  1058. .then(function (response) {
  1059. if (response.status == 200) {
  1060. $scope.areas = response.list;
  1061. }
  1062. });
  1063. };
  1064. $scope.onChange = function(item) {
  1065. $scope.requester.place = {area: $scope.requester.place.area};
  1066. console.log($scope.requester, 'changeArea');
  1067. api_user_data.fetchDataList('place', { place: { areaId: item.id }, idx: 0, sum: 1000 }).then(function(response) {
  1068. if (response.status == 200) {
  1069. $scope.places = response.list;
  1070. }
  1071. })
  1072. }
  1073. // 修改地点
  1074. $scope.requesterPlaceid = "";
  1075. $scope.onChangePlace = function (item) {
  1076. $scope.requesterPlaceid = item.id;
  1077. console.log($scope.requester, 'changePlace');
  1078. api_user_data
  1079. .fetchDataList("room", {
  1080. room: {
  1081. place: {
  1082. id: item.id,
  1083. },
  1084. },
  1085. idx: 0,
  1086. sum: 1000,
  1087. })
  1088. .then(function (response) {
  1089. if (response.status == 200) {
  1090. $scope.rooms = response.list;
  1091. }
  1092. });
  1093. };
  1094. $scope.refreshArea = function (searchVal) {
  1095. console.log($scope.requester, 'area');
  1096. var faildata = {};
  1097. if ($scope.requester.branch) {
  1098. faildata = {
  1099. idx: 0,
  1100. sum: 1000,
  1101. area: {
  1102. branch: $scope.requester.branch.id,
  1103. area: searchVal,
  1104. selectType: "pinyin_qs",
  1105. },
  1106. };
  1107. } else {
  1108. return;
  1109. }
  1110. api_user_data
  1111. .fetchDataList("area", faildata)
  1112. .then(function (response) {
  1113. $scope.areas = response.list;
  1114. delete $scope.requester.areaDTO;
  1115. });
  1116. };
  1117. //地点搜索
  1118. $scope.refresh = function (searchVal) {
  1119. console.log($scope.requester, 'place');
  1120. var faildata = {};
  1121. if ($scope.requester.place && $scope.requester.place.area) {
  1122. faildata = {
  1123. idx: 0,
  1124. sum: 1000,
  1125. place: {
  1126. areaId: $scope.requester.place.area.id,
  1127. place: searchVal,
  1128. selectType: "pinyin_qs",
  1129. },
  1130. };
  1131. } else {
  1132. return;
  1133. }
  1134. api_user_data
  1135. .fetchDataList("place", faildata)
  1136. .then(function (response) {
  1137. $scope.places = response.list;
  1138. delete $scope.requester.placeDTO;
  1139. });
  1140. };
  1141. $scope.requester = { 'telephone': $rootScope.phone };
  1142. $scope.ok = function() {
  1143. // $modalInstance.close($scope.requester);
  1144. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1145. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1146. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1147. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1148. } else {
  1149. // $modalInstance.close($scope.requester);
  1150. $scope.selectedItemTodo($scope.requester)
  1151. }
  1152. };
  1153. $scope.selectedItemTodo = function(selectedItem){
  1154. if (selectedItem) {
  1155. // if (selectedItem.telephone && !selectedItem.mphone) {
  1156. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  1157. // delete selectedItem.mphone;
  1158. // }
  1159. var data = {
  1160. 'requester': selectedItem
  1161. };
  1162. api_user_data.addData('requester', data).then(function(response) {
  1163. if (response.status == 200) {
  1164. $modalInstance.dismiss("ok");
  1165. var data = {
  1166. model: {
  1167. requestershow: response.data,
  1168. incident: {
  1169. requester: response.data,
  1170. branch: response.data.branch,
  1171. area: response.data.place?response.data.place.area:undefined,
  1172. place: response.data.place,
  1173. houseNumber: response.data.houseNumber,
  1174. contactsInformation: response.data.telephone,
  1175. contacts:response.data.name,
  1176. callID: cdrid,
  1177. source: { id: 1547 },
  1178. },
  1179. },
  1180. };
  1181. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1182. }else{
  1183. modalInstance.SweetAlert.swal({
  1184. title: "系统错误",
  1185. text: "账号重复!",
  1186. type: "error",
  1187. });
  1188. }
  1189. })
  1190. }
  1191. }
  1192. $scope.cancel = function() {
  1193. $modalInstance.dismiss('cancel');
  1194. $rootScope.setidle();
  1195. };
  1196. },
  1197. });
  1198. //#region list1
  1199. // modalInstance.result.then(function(selectedItem) {
  1200. // if (selectedItem) {
  1201. // // if (selectedItem.telephone && !selectedItem.mphone) {
  1202. // // selectedItem.telephone = angular.copy(selectedItem.mphone);
  1203. // // delete selectedItem.mphone;
  1204. // // }
  1205. // var data = {
  1206. // 'requester': selectedItem
  1207. // };
  1208. // api_user_data.addData('requester', data).then(function(response) {
  1209. // if (response.status == 200) {
  1210. // var data = {
  1211. // model: {
  1212. // requestershow: response.data,
  1213. // incident: {
  1214. // requester: response.data,
  1215. // branch: response.data.branch,
  1216. // area: response.data.place?response.data.place.area:undefined,
  1217. // place: response.data.place,
  1218. // houseNumber: response.data.houseNumber,
  1219. // contactsInformation: response.data.telephone,
  1220. // contacts:response.data.name,
  1221. // callID: cdrid,
  1222. // source: { id: 1547 },
  1223. // },
  1224. // },
  1225. // };
  1226. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1227. // }else{
  1228. // modalInstance.SweetAlert.swal({
  1229. // title: "系统错误",
  1230. // text: "账号重复!",
  1231. // type: "error",
  1232. // });
  1233. // }
  1234. // })
  1235. // }
  1236. // });
  1237. //#endregion list1
  1238. } else if (myData.list.length == 1) {
  1239. angular.extend(myData.list[0], { 'telephone': $rootScope.phone });
  1240. var data = {
  1241. model: {
  1242. requestershow: myData.list[0],
  1243. incident: {
  1244. requester: myData.list[0],
  1245. branch: myData.list[0].branch,
  1246. area: myData.list[0].place?myData.list[0].place.area:undefined,
  1247. place: myData.list[0].place,
  1248. contactsInformation: myData.list[0].telephone,
  1249. houseNumber: myData.list[0].houseNumber,
  1250. contacts:myData.list[0].name,
  1251. callID: cdrid,
  1252. source: { id: 1547 },
  1253. },
  1254. },
  1255. };
  1256. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1257. } else {
  1258. var modalInstance = $modal.open({
  1259. templateUrl: 'assets/views/createincident.html',
  1260. backdrop: "static",
  1261. controller: function($scope, $modalInstance, api_user_data) {
  1262. $scope.title = "请确定报修人";
  1263. $scope.requester = myData.list;
  1264. $scope.choice = function(requester) {
  1265. $modalInstance.dismiss('cancel');
  1266. angular.extend(requester, { 'telephone': $rootScope.phone });
  1267. var data = {
  1268. model: {
  1269. requestershow: requester,
  1270. incident: {
  1271. requester: requester,
  1272. branch: requester.branch,
  1273. area: requester.place?requester.place.area:undefined,
  1274. place: requester.place,
  1275. houseNumber: requester.houseNumber,
  1276. contactsInformation: requester.telephone,
  1277. contacts:requester.name,
  1278. callID: cdrid,
  1279. source: { id: 1547 },
  1280. },
  1281. },
  1282. };
  1283. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1284. };
  1285. $scope.cancel = function() {
  1286. $modalInstance.dismiss('cancel');
  1287. $rootScope.setidle();
  1288. };
  1289. },
  1290. size: "lg"
  1291. });
  1292. }
  1293. });
  1294. }
  1295. })
  1296. }
  1297. }
  1298. }
  1299. // else if(mydata.evttype == 'allbusy' && mydata.status == 'false'){
  1300. // if(location.href.includes('app/incident/list') || location.href.includes('app/incident/editor') || location.href.includes('app/incident/title')){
  1301. // $scope.setbusy();
  1302. // }else{
  1303. // $scope.setidle();
  1304. // }
  1305. // }
  1306. }
  1307. };
  1308. var heartCheck = {
  1309. timeout: 12000, //60ms
  1310. timeoutObj: null,
  1311. serverTimeoutObj: null,
  1312. reset: function() {
  1313. clearTimeout(this.timeoutObj);
  1314. clearTimeout(this.serverTimeoutObj);    
  1315. this.start();
  1316. },
  1317. start: function() {
  1318. var self = this;
  1319. this.timeoutObj = setTimeout(function() {
  1320. if ($scope.login) {
  1321. ws.send("HeartBeat");
  1322. self.serverTimeoutObj = setTimeout(function() {
  1323. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  1324. }, self.timeout)
  1325. }
  1326. }, this.timeout)
  1327. },
  1328. }
  1329. ws.onclose = function(evt) { reconnect(); }
  1330. ws.onerror = function(evt) { reconnect(); };
  1331. }
  1332. reconnect();
  1333. } else {
  1334. var Notification = window.Notification;
  1335. Notification.requestPermission();
  1336. var n = new Notification("签入失败!", {
  1337. body: data.errmsg,
  1338. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  1339. // onclick: function onNotificationClicked() {
  1340. // console.log('Notification clicked.');
  1341. // }
  1342. });
  1343. }
  1344. })
  1345. })
  1346. }
  1347. // 牛逼
  1348. // setInterval(function() {
  1349. // if ($scope.login && $rootScope.statuscall == 1 && $rootScope.statecall == 1) {
  1350. // $rootScope.setidle();
  1351. // } else if ($scope.login && $rootScope.statuscall != 3 && $rootScope.statecall == 2 && $rootScope.statuscall != 0) {
  1352. // $rootScope.setbusy();
  1353. // }
  1354. // }, 3000);
  1355. // 华科呼叫中心 end
  1356. //话机呼叫中心--开始
  1357. // 1是老的呼叫中心
  1358. // 2是财大2021年12月29日新增的呼叫中心
  1359. // 3是华科新增的呼叫中心
  1360. console.log($rootScope.isHk,'hk')
  1361. console.log($rootScope.isZncd,'zncd')
  1362. if($rootScope.isZncd){
  1363. $rootScope.seiminHj = 2;
  1364. }else if($rootScope.isHk){
  1365. $rootScope.seiminHj = 3;
  1366. }else{
  1367. $rootScope.seiminHj = 1;
  1368. }
  1369. $rootScope.getExtnDirect = function () {
  1370. $rootScope['getExtnDirect' + $rootScope.seiminHj]();
  1371. }
  1372. // --------------------------1------------------------------
  1373. $rootScope.getExtnDirect1 = function () {
  1374. var jry_data_dictionary = {
  1375. key: "hjzx_cornet",
  1376. type: "list"
  1377. }
  1378. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1379. var websocket_url = "ws://192.168.3.122:29003/ola_socket";
  1380. var ola_queue = "10009"; //通话配置-队列配置-队列ID
  1381. // var ola_extn = "1001"; //个人信息-座席分机号
  1382. $rootScope.jry_extnNumberSelect = [];
  1383. $rootScope.jry_extnNumberObj = {};
  1384. $rootScope.jry_extnNumberSelect = res;
  1385. $rootScope.jry_extnNumberObj.jry_extnNumber = $rootScope.jry_extnNumberSelect[0];
  1386. function log(msg) {
  1387. //IE has no console
  1388. if ('console' in window) console.log(msg);
  1389. }
  1390. function websocket_connect() {
  1391. ola.connect(websocket_url);
  1392. ola.onConnect = onConnect;
  1393. ola.onClose = onClose;
  1394. ola.onMessage = onMessage;
  1395. }
  1396. $(document).ready(function () {
  1397. // if(ola_extn!=""){
  1398. if ($rootScope.jry_extnNumberObj.jry_extnNumber) {
  1399. websocket_connect();
  1400. }
  1401. });
  1402. /* callbacks */
  1403. function onMessage(evt) {
  1404. var phoneData = JSON.parse(evt.data);
  1405. if (phoneData.event_type == "agent_state") {
  1406. console.log(phoneData);
  1407. if (phoneData.state == "busy") {
  1408. $('#agent_state').append(" (" + phoneData.private_data + ")");
  1409. // 来电
  1410. if (phoneData.private_data == "ring") {
  1411. console.log(phoneData);
  1412. $rootScope.jry_state = "laidian";
  1413. var Notification = window.Notification;
  1414. Notification.requestPermission();
  1415. var n = new Notification("你有来电", {
  1416. body: "来电号码:" + phoneData.ani,
  1417. icon: './bower_components/HTML5-Desktop-Notifications/alert.ico',
  1418. });
  1419. // 摘机
  1420. } else if (phoneData.private_data == "answered") {
  1421. $rootScope.jry_state = "tonghuazhong";
  1422. var jry_findPhone = "";
  1423. if (phoneData.ani) {
  1424. jry_findPhone = phoneData.ani
  1425. } else if (phoneData.dnis && phoneData.other_answered) {
  1426. jry_findPhone = phoneData.dnis
  1427. }
  1428. var filterData = {
  1429. "idx": 0,
  1430. "sum": 100,
  1431. "requester": {
  1432. "mphone": jry_findPhone,
  1433. "telephone": jry_findPhone,
  1434. "selectType": 1
  1435. }
  1436. }
  1437. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  1438. var myData = Restangular.stripRestangular(data);
  1439. // $rootScope.phone="";
  1440. // 新增报修人
  1441. if (myData.list.length == 0) {
  1442. var modalInstance = $modal.open({
  1443. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  1444. controller: function ($scope, $modalInstance, api_user_data, SweetAlert, api_wechatfile) {
  1445. $modalInstance.SweetAlert = SweetAlert;
  1446. $scope.title = "新增报修人";
  1447. $scope.requester = {};
  1448. $scope.onChangeadd = function (searchData) {
  1449. $scope.searchKey = searchData.account;
  1450. // $scope.searchDataadd = searchData;
  1451. var requesdata = angular.copy(searchData)
  1452. // if (requesdata.mphone) {
  1453. // delete requesdata.mphone;
  1454. // }
  1455. if (requesdata.telephone) {
  1456. delete requesdata.telephone;
  1457. }
  1458. angular.extend($scope.requester, requesdata);
  1459. }
  1460. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  1461. $scope.requester.account = searchKey;
  1462. $scope.searchData = searchKey;
  1463. serchdataadd(searchKey);
  1464. }
  1465. $scope.getMydata = function (x) {
  1466. var reqestdatap = JSON.parse(x[0])
  1467. // if ($scope.requester.mphone) {
  1468. // delete reqestdatap.mphone;
  1469. // }
  1470. if ($scope.requester.telephone) {
  1471. delete reqestdatap.telephone;
  1472. }
  1473. $scope.searchField = JSON.parse(x[0]).account;
  1474. angular.extend($scope.requester, reqestdatap);
  1475. }
  1476. $scope.getMydataone = function (x) {
  1477. $scope.searchField = x;
  1478. $scope.requester.account = x;
  1479. }
  1480. serchdataadd();
  1481. function serchdataadd(searchKey) {
  1482. if (searchKey) {
  1483. var filterData = {
  1484. 'requester': {
  1485. 'searchKey': searchKey,
  1486. },
  1487. idx: 0,
  1488. sum: 10
  1489. };
  1490. } else {
  1491. var filterData = {
  1492. idx: 0,
  1493. sum: 10
  1494. };
  1495. }
  1496. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  1497. var myData = response;
  1498. $scope.myData = myData.list;
  1499. });
  1500. }
  1501. api_user_data.fetchDataList('area', {
  1502. idx: 0,
  1503. sum: 100
  1504. }).then(function (response) {
  1505. if (response.status == 200) {
  1506. $scope.areas = response.list;
  1507. }
  1508. })
  1509. api_wechatfile.getDictionary({
  1510. "key": "requester_type",
  1511. "type": "list"
  1512. }).then(function (response) {
  1513. // if (response.status == 200) {
  1514. $scope.networktypes = response;
  1515. // }
  1516. })
  1517. $scope.requesterAreaid = "";
  1518. $scope.onChange = function (item) {
  1519. $scope.requesterAreaid = item.id;
  1520. $scope.requester.place = {};
  1521. api_user_data.fetchDataList('place', {
  1522. place: {
  1523. areaId: item.id
  1524. },
  1525. idx: 0,
  1526. sum: 1000
  1527. }).then(function (response) {
  1528. if (response.status == 200) {
  1529. $scope.places = response.list;
  1530. }
  1531. })
  1532. }
  1533. //地点搜索
  1534. $scope.refresh = function (searchVal) {
  1535. var faildata = {};
  1536. if ($scope.requesterAreaid) {
  1537. faildata = {
  1538. 'idx': 0,
  1539. 'sum': 1000,
  1540. 'place': {
  1541. 'areaId': $scope.requesterAreaid,
  1542. 'place': searchVal,
  1543. 'selectType': 'pinyin_qs'
  1544. }
  1545. }
  1546. } else {
  1547. faildata = {
  1548. 'idx': 0,
  1549. 'sum': 1000,
  1550. 'place': {
  1551. 'place': searchVal,
  1552. 'selectType': 'pinyin_qs'
  1553. }
  1554. }
  1555. }
  1556. api_user_data.fetchDataList('place', faildata).then(function (response) {
  1557. $scope.places = response.list;
  1558. delete $scope.requester.place;
  1559. })
  1560. }
  1561. $scope.requester = {
  1562. 'telephone': jry_findPhone
  1563. };
  1564. $scope.ok = function () {
  1565. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  1566. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  1567. var flag1 = reg1.test($scope.requester.mphone);
  1568. var flag2 = reg2.test($scope.requester.mphone);
  1569. console.log($scope.requester)
  1570. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1571. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1572. } else if (angular.isUndefined($scope.requester.requesterType)) {
  1573. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  1574. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1575. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1576. }
  1577. else {
  1578. // $modalInstance.close($scope.requester);
  1579. $scope.selectedItemTodo($scope.requester);
  1580. }
  1581. };
  1582. $scope.selectedItemTodo = function(selectedItem){
  1583. if (selectedItem) {
  1584. if (selectedItem.telephone && !selectedItem.mphone) {
  1585. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1586. delete selectedItem.mphone;
  1587. }
  1588. var data = {
  1589. 'requester': selectedItem
  1590. };
  1591. api_user_data.addData('requester', data).then(function (response) {
  1592. if (response.status == 200) {
  1593. $modalInstance.dismiss("ok");
  1594. var data = {
  1595. 'model': {
  1596. 'requestershow': response.data,
  1597. 'incident': {
  1598. 'requester': response.data,
  1599. 'area': response.data.place?response.data.place.area:undefined,
  1600. 'place': response.data.place,
  1601. 'houseNumber': response.data.houseNumber,
  1602. 'callID': cdrid,
  1603. 'contacts':response.data.name,
  1604. 'contactsInformation': response.data.telephone,
  1605. 'source': {
  1606. 'id': 1547
  1607. }
  1608. }
  1609. }
  1610. }
  1611. $state.go('app.incident.title', {
  1612. 'model': JSON.stringify(data)
  1613. });
  1614. }else{
  1615. modalInstance.SweetAlert.swal({
  1616. title: "系统错误",
  1617. text: "账号重复!",
  1618. type: "error",
  1619. });
  1620. }
  1621. })
  1622. }
  1623. }
  1624. $scope.cancel = function () {
  1625. $modalInstance.dismiss('cancel');
  1626. };
  1627. },
  1628. });
  1629. // modalInstance.result.then(function (selectedItem) {
  1630. // if (selectedItem) {
  1631. // if (selectedItem.telephone && !selectedItem.mphone) {
  1632. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  1633. // delete selectedItem.mphone;
  1634. // }
  1635. // var data = {
  1636. // 'requester': selectedItem
  1637. // };
  1638. // api_user_data.addData('requester', data).then(function (response) {
  1639. // if (response.status == 200) {
  1640. // var data = {
  1641. // 'model': {
  1642. // 'requestershow': response.data,
  1643. // 'incident': {
  1644. // 'requester': response.data,
  1645. // 'area': response.data.place?response.data.place.area:undefined,
  1646. // 'place': response.data.place,
  1647. // 'houseNumber': response.data.houseNumber,
  1648. // 'callID': cdrid,
  1649. // 'contacts':response.data.name,
  1650. // 'contactsInformation': response.data.telephone,
  1651. // 'source': {
  1652. // 'id': 1547
  1653. // }
  1654. // }
  1655. // }
  1656. // }
  1657. // $state.go('app.incident.title', {
  1658. // 'model': JSON.stringify(data)
  1659. // });
  1660. // }else{
  1661. // modalInstance.SweetAlert.swal({
  1662. // title: "系统错误",
  1663. // text: "账号重复!",
  1664. // type: "error",
  1665. // });
  1666. // }
  1667. // })
  1668. // }
  1669. // });
  1670. } else if (myData.list.length == 1) {
  1671. var data = {
  1672. 'model': {
  1673. 'requestershow': myData.list[0],
  1674. 'incident': {
  1675. 'requester': myData.list[0],
  1676. 'area': myData.list[0].place?myData.list[0].place.area:undefined,
  1677. 'place': myData.list[0].place,
  1678. 'houseNumber': myData.list[0].houseNumber,
  1679. 'callID': cdrid,
  1680. 'contacts':myData.list[0].name,
  1681. 'contactsInformation': myData.list[0].telephone,
  1682. 'source': {
  1683. 'id': 1547
  1684. }
  1685. }
  1686. }
  1687. }
  1688. $state.go('app.incident.title', {
  1689. 'model': JSON.stringify(data)
  1690. });
  1691. } else {
  1692. var modalInstance = $modal.open({
  1693. templateUrl: 'assets/views/createincident.html',
  1694. controller: function ($scope, $modalInstance, api_user_data) {
  1695. $scope.title = "请确定报修人";
  1696. $scope.requester = myData.list;
  1697. $scope.choice = function (requester) {
  1698. $modalInstance.dismiss('cancel');
  1699. var data = {
  1700. 'model': {
  1701. 'requestershow': requester,
  1702. 'incident': {
  1703. 'requester': requester,
  1704. 'area': requester.place?requester.place.area:undefined,
  1705. 'place': requester.place,
  1706. 'houseNumber': requester.houseNumber,
  1707. 'callID': cdrid,
  1708. 'contacts':requester.name,
  1709. 'contactsInformation': requester.telephone,
  1710. 'source': {
  1711. 'id': 1547
  1712. }
  1713. }
  1714. }
  1715. }
  1716. $state.go('app.incident.title', {
  1717. 'model': JSON.stringify(data)
  1718. });
  1719. };
  1720. $scope.cancel = function () {
  1721. $modalInstance.dismiss('cancel');
  1722. };
  1723. },
  1724. size: "lg"
  1725. });
  1726. }
  1727. });
  1728. }
  1729. // 挂机
  1730. } else if (phoneData.state == "login") {
  1731. go_ready()
  1732. } else if (phoneData.state == "logout") {
  1733. $rootScope.jry_state = "weiqianru";
  1734. } else if (phoneData.state == "ready") {
  1735. // 来电挂机
  1736. if (phoneData.old_state == "busy" && phoneData.private_data == "answered") {
  1737. go_break()
  1738. } else {
  1739. $rootScope.jry_state = "shixian";
  1740. }
  1741. }
  1742. // else if (data.old_state == "busy") {
  1743. // }
  1744. } else if (phoneData.event_type == "agent_caller_state") {
  1745. // special feature, never mind
  1746. if (phoneData.action == "in") {
  1747. } else {
  1748. }
  1749. } else if (phoneData.event_type == "command/reply") {
  1750. if (phoneData.phoneData && phoneData.phoneData.state) {
  1751. }
  1752. }
  1753. }
  1754. function onConnect() {
  1755. console.log("websocket connected!");
  1756. // ola._extn = ola_extn;
  1757. // ola.subscribe('ola.queue.' + ola_queue + '.' + ola_extn);
  1758. // ola.subscribe('ola.caller.' + ola_extn);
  1759. // ola.get_agent_state(ola_extn);
  1760. ola._extn = $rootScope.jry_extnNumberObj.jry_extnNumber.name;
  1761. ola.subscribe('ola.queue.' + ola_queue + '.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1762. ola.subscribe('ola.caller.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1763. ola.get_agent_state($rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1764. };
  1765. function onClose() {
  1766. }
  1767. function login() {
  1768. // ola.login(ola_queue, ola_extn, {type: "onhook"});
  1769. console.log($rootScope.jry_extnNumberObj.jry_extnNumber);
  1770. ola.login(ola_queue, $rootScope.jry_extnNumberObj.jry_extnNumber.name, { type: "onhook" });
  1771. }
  1772. function logout() {
  1773. ola.logout();
  1774. }
  1775. function go_ready() {
  1776. ola.go_ready();
  1777. }
  1778. function go_break() {
  1779. ola.go_break($('#break_reason').val());
  1780. $rootScope.jry_state = "shimang";
  1781. }
  1782. function answer() {
  1783. ola.answer();
  1784. }
  1785. function dial(dst) {
  1786. ola.dial(dst);
  1787. }
  1788. $rootScope.dial = function (dst) {
  1789. ola.dial(dst);
  1790. }
  1791. function conference(dst) {
  1792. ola.conference(dst);
  1793. }
  1794. function conference_uuid(channel_uuid) {
  1795. ola.conference_uuid(channel_uuid);
  1796. }
  1797. function hangup() {
  1798. ola.hangup();
  1799. }
  1800. function take_call(uuid) {
  1801. // ola.take_call(ola_extn, uuid);
  1802. ola.take_call($rootScope.jry_extnNumberObj.jry_extnNumber.name, uuid);
  1803. }
  1804. // 签入
  1805. $rootScope.jry_qianru = function () {
  1806. login();
  1807. }
  1808. // 示闲
  1809. $rootScope.jry_shixian = function () {
  1810. go_ready()
  1811. }
  1812. // 示忙
  1813. $rootScope.jry_shimang = function () {
  1814. go_break()
  1815. }
  1816. // 签出
  1817. $rootScope.jry_qianchu = function () {
  1818. logout()
  1819. }
  1820. $rootScope.jry_bohao = function (res) {
  1821. if ($rootScope.jry_state == "weiqianru") {
  1822. // SweetAlert.swal({
  1823. // title: "拨打失败",
  1824. // text: "请先签入!",
  1825. // type: "error",
  1826. // confirmButtonColor: "#DD6B55"
  1827. // });
  1828. } else if ($rootScope.jry_state == "shimang") {
  1829. // SweetAlert.swal({
  1830. // title: "拨打失败",
  1831. // text: "请先示闲!",
  1832. // type: "error",
  1833. // confirmButtonColor: "#DD6B55"
  1834. // });
  1835. } else {
  1836. dial(res);
  1837. }
  1838. }
  1839. })
  1840. }
  1841. // ------------------------------2--------------------------
  1842. $rootScope.getExtnDirect2 = function () {
  1843. var jry_data_dictionary = {
  1844. key: "hjzx_cornet",
  1845. type: "list"
  1846. }
  1847. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1848. sessionStorage.setItem('phones',JSON.stringify(res.map(v=>v.name)));
  1849. var websocket_url = $rootScope.seiminCallIp;
  1850. $rootScope.jry_extnNumberSelect = [];
  1851. $rootScope.jry_extnNumberObj = {};
  1852. $rootScope.jry_extnNumberSelect = angular.copy(res);
  1853. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1854. var fenjiNumber = localStorage.getItem('fenjiNumber');
  1855. if(fenjiNumber){
  1856. $rootScope.jry_extnNumberSelect.forEach(ress=>{
  1857. if(ress.name == fenjiNumber){
  1858. $rootScope.jry_extnNumberObj.jry_extnNumber = ress;
  1859. }
  1860. })
  1861. }
  1862. // $rootScope.jry_extnNumberObj.jry_extnNumber = angular.copy(res[0]);//绑定分机对象
  1863. // $rootScope.jry_extnNumberObj.tel1 = angular.copy(res[0]);//目的号码对象
  1864. // $rootScope.jry_extnNumberObj.tel2 = angular.copy(res[0]);//转接坐席对象
  1865. $rootScope.preState = '';//最近一次示忙还是示闲的状态
  1866. //连接
  1867. tlwsa.tlaOpen(websocket_url);
  1868. // 强制示忙
  1869. $scope.qShimang = function(state){
  1870. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1871. //进入页面,强制示忙
  1872. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1873. setTimeout(()=>{
  1874. tlwsa.tlaAcw();
  1875. },0)
  1876. }else{
  1877. $scope.getState(state);
  1878. }
  1879. }
  1880. // 获取状态
  1881. $scope.getState = function (state) {
  1882. // if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1883. // if(state != 2&&state != 0){
  1884. // //进入页面,强制示忙
  1885. // // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1886. // setTimeout(()=>{
  1887. // tlwsa.tlaAcw();
  1888. // },3000)
  1889. // }
  1890. // }
  1891. // var agcount = tlwsa.tlaGetagentcount();
  1892. // var flag = true;
  1893. // for (var i = 0; i < agcount; i++) {
  1894. // if (tlwsa.tlaGetagentwid(i) == $rootScope.phoneNumber) {
  1895. // flag = false;
  1896. // var state = Number(tlwsa.tlaGetagentstate(i));
  1897. // console.log(state);
  1898. switch (state) {
  1899. case 0:
  1900. $rootScope.jry_state = 'weiqianru';
  1901. break;
  1902. case 1:
  1903. $rootScope.jry_state = 'shixian';
  1904. break;
  1905. case 2:
  1906. $rootScope.jry_state = 'shimang';
  1907. break;
  1908. case 3:
  1909. $rootScope.jry_state = 'laidian';
  1910. break;
  1911. case 5:
  1912. $rootScope.jry_state = 'tonghuazhong';
  1913. break;
  1914. case 6:
  1915. $rootScope.jry_state = 'zhengzaiwaihu';
  1916. break;
  1917. case 7:
  1918. $rootScope.jry_state = 'zhengzaizhuanyi';
  1919. break;
  1920. }
  1921. // }
  1922. // console.log('agnet No. ' + i + ' workid is ' + tlwsa.tlaGetagentwid(i) + ' state is ' + tlwsa.tlaGetagentstate(i) + ' ' + getStateInfo(tlwsa.tlaGetagentstate(i)))
  1923. // }
  1924. // if (flag) {
  1925. // $rootScope.jry_state = 'weiqianru';
  1926. // }
  1927. }
  1928. // 状态回调函数
  1929. // TLWSA.onStatechange = onstatechange;
  1930. // function onstatechange() {
  1931. // console.log('事件:状态变化----------------------------------------------------');
  1932. // $scope.getState();
  1933. // }
  1934. //连接呼叫中心回调函数
  1935. TLWSA.onOpenreturn = onopenreturn;
  1936. function onopenreturn(err) {
  1937. err = Number(err);
  1938. if (!err) {
  1939. console.log('呼叫中心连接成功-----seimin');
  1940. $scope.getState(0);
  1941. $.toaster({
  1942. priority: 'info',
  1943. title: '操作',
  1944. message: '呼叫中心连接成功'
  1945. });
  1946. //如果设置过话机
  1947. if (localStorage.getItem('phoneNumber')) {
  1948. //强制签出,然后签入
  1949. tlwsa.tlaKillworkid(localStorage.getItem('phoneNumber'));
  1950. }
  1951. } else {
  1952. console.log('呼叫中心连接失败-----seimin');
  1953. $scope.getState(0);
  1954. $.toaster({
  1955. priority: 'info',
  1956. title: '操作',
  1957. message: '呼叫中心连接失败'
  1958. });
  1959. }
  1960. }
  1961. //绑定分机回调函数
  1962. TLWSA.onSetphonenumberreturn = onsetphonenumberreturn;
  1963. function onsetphonenumberreturn(err) {
  1964. err = Number(err);
  1965. if (!err) {
  1966. console.log('绑定分机成功-----seimin');
  1967. $.toaster({
  1968. priority: 'info',
  1969. title: '操作',
  1970. message: '绑定分机成功'
  1971. });
  1972. localStorage.setItem('phoneNumber', $rootScope.phoneNumber);
  1973. localStorage.setItem('fenjiNumber', $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1974. $scope.qShimang(1);
  1975. } else {
  1976. console.log('绑定分机失败-----seimin');
  1977. $scope.getState(0);
  1978. $.toaster({
  1979. priority: 'info',
  1980. title: '操作',
  1981. message: '绑定分机失败'
  1982. });
  1983. }
  1984. }
  1985. //强制示忙回调函数
  1986. // TLWSA.onAcw = onacw;
  1987. // function onacw(err) {
  1988. // err = Number(err);
  1989. // if (!err) {
  1990. // console.log('强制示忙成功-----seimin');
  1991. // $scope.getState(2);
  1992. // $.toaster({
  1993. // priority: 'info',
  1994. // title: '操作',
  1995. // message: '示忙成功'
  1996. // });
  1997. // } else {
  1998. // console.log('强制示忙失败-----seimin');
  1999. // $.toaster({
  2000. // priority: 'info',
  2001. // title: '操作',
  2002. // message: '示忙失败'
  2003. // });
  2004. // }
  2005. // }
  2006. // //强制示闲回调函数
  2007. // TLWSA.onWca = onwca;
  2008. // function onwca(err) {
  2009. // console.log(err)
  2010. // err = Number(err);
  2011. // if (!err) {
  2012. // console.log('强制示闲成功-----seimin');
  2013. // $scope.getState(1);
  2014. // $.toaster({
  2015. // priority: 'info',
  2016. // title: '操作',
  2017. // message: '示闲成功'
  2018. // });
  2019. // } else {
  2020. // console.log('强制示闲失败-----seimin');
  2021. // $.toaster({
  2022. // priority: 'info',
  2023. // title: '操作',
  2024. // message: '示闲失败'
  2025. // });
  2026. // }
  2027. // }
  2028. //与服务器网络连接中断回调函数
  2029. TLWSA.onClosed = onclosed;
  2030. function onclosed() {
  2031. $scope.getState(0);
  2032. console.log('与服务器网络连接中断-----seimin');
  2033. $.toaster({
  2034. priority: 'info',
  2035. title: '操作',
  2036. message: '与服务器网络连接中断,2分钟后重连'
  2037. });
  2038. console.log('2分钟后自动重连-----seimin')
  2039. $timeout(function () {
  2040. //连接
  2041. tlwsa.tlaOpen(websocket_url);
  2042. }, 120000)
  2043. }
  2044. //签入回调函数
  2045. TLWSA.onLoginreturn = onloginreturn;
  2046. function onloginreturn(err) {
  2047. err = Number(err);
  2048. if (!err) {
  2049. console.log('签入成功-----seimin');
  2050. $.toaster({
  2051. priority: 'info',
  2052. title: '操作',
  2053. message: '签入成功'
  2054. });
  2055. setTimeout(function () {
  2056. console.log($rootScope.jry_extnNumberObj.jry_extnNumber.name,1111)
  2057. var fenjiNumber = $rootScope.jry_extnNumberObj.jry_extnNumber.name || localStorage.getItem('fenjiNumber');
  2058. console.log('开始绑定分机【' + fenjiNumber + '】-----seimin');
  2059. tlwsa.tlaSetphonenumber(fenjiNumber);
  2060. }, 0)
  2061. } else if (err == 9011) {
  2062. console.log('签入失败,该分机已登录-----seimin');
  2063. $.toaster({
  2064. priority: 'info',
  2065. title: '操作',
  2066. message: '签入失败,该分机已登录'
  2067. });
  2068. } else {
  2069. console.log('签入失败-----seimin');
  2070. $.toaster({
  2071. priority: 'info',
  2072. title: '操作',
  2073. message: '签入失败'
  2074. });
  2075. }
  2076. // tlwsa.tlaSubscribestateinfo(2);
  2077. }
  2078. // 强制签出回调函数
  2079. TLWSA.onKillreturn = onkillreturn;
  2080. function onkillreturn(err) {
  2081. err = Number(err);
  2082. if (!err) {
  2083. console.log('强制签出成功-----seimin');
  2084. $scope.getState(0);
  2085. // $.toaster({
  2086. // priority: 'info',
  2087. // title: '操作',
  2088. // message: '强制签出成功'
  2089. // });
  2090. } else {
  2091. console.log('强制签出失败,该分机不是签入状态-----seimin');
  2092. // $.toaster({
  2093. // priority: 'info',
  2094. // title: '操作',
  2095. // message: '强制签出失败'
  2096. // });
  2097. }
  2098. //如果设置过话机
  2099. if (localStorage.getItem('phoneNumber')) {
  2100. // 签入并绑定分机
  2101. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  2102. tlwsa.tlaLogin($rootScope.phoneNumber, 1, -1);
  2103. }
  2104. }
  2105. // 签出回调函数
  2106. TLWSA.onLogoffreturn = onlogoffreturn;
  2107. function onlogoffreturn(err) {
  2108. err = Number(err);
  2109. if (!err) {
  2110. console.log('签出成功-----seimin');
  2111. $scope.getState(0);
  2112. $.toaster({
  2113. priority: 'info',
  2114. title: '操作',
  2115. message: '签出成功'
  2116. });
  2117. localStorage.removeItem('phoneNumber');
  2118. localStorage.removeItem('fenjiNumber');
  2119. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  2120. } else {
  2121. console.log('签出失败-----seimin');
  2122. $.toaster({
  2123. priority: 'info',
  2124. title: '操作',
  2125. message: '签出失败'
  2126. });
  2127. }
  2128. }
  2129. //示忙回调函数
  2130. TLWSA.onAcwreturn = onacwreturn;
  2131. function onacwreturn(err) {
  2132. err = Number(err);
  2133. if (!err) {
  2134. console.log('示忙成功-----seimin');
  2135. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  2136. $scope.isShixian = false;
  2137. }else{
  2138. $scope.isShixian = true;
  2139. }
  2140. $scope.getState(2);
  2141. $rootScope.preState = 2;
  2142. $.toaster({
  2143. priority: 'info',
  2144. title: '操作',
  2145. message: '示忙成功'
  2146. });
  2147. } else {
  2148. console.log('示忙失败-----seimin');
  2149. // $.toaster({
  2150. // priority: 'info',
  2151. // title: '操作',
  2152. // message: '示忙失败'
  2153. // });
  2154. }
  2155. }
  2156. //示闲回调函数
  2157. TLWSA.onWcareturn = onwcareturn;
  2158. function onwcareturn(err) {
  2159. err = Number(err);
  2160. if (!err) {
  2161. console.log('示闲成功-----seimin');
  2162. $scope.getState(1);
  2163. $rootScope.preState = 1;
  2164. $.toaster({
  2165. priority: 'info',
  2166. title: '操作',
  2167. message: '示闲成功'
  2168. });
  2169. } else {
  2170. console.log('示闲失败-----seimin');
  2171. $.toaster({
  2172. priority: 'info',
  2173. title: '操作',
  2174. message: '示闲失败'
  2175. });
  2176. }
  2177. }
  2178. //呼叫坐席回调函数
  2179. TLWSA.onCallreturn = oncallreturn;
  2180. function oncallreturn(err) {
  2181. err = Number(err);
  2182. if (!err) {
  2183. console.log('呼叫成功,请摘机-----seimin');
  2184. $scope.getState(6);
  2185. $.toaster({
  2186. priority: 'info',
  2187. title: '操作',
  2188. message: '呼叫成功,请摘机'
  2189. });
  2190. } else {
  2191. console.log('呼叫失败-----seimin');
  2192. $.toaster({
  2193. priority: 'info',
  2194. title: '操作',
  2195. message: '呼叫失败'
  2196. });
  2197. }
  2198. }
  2199. //呼叫坐席被接听回调函数
  2200. TLWSA.onCallresult = oncallresult;
  2201. function oncallresult(jso) {
  2202. console.log(jso);
  2203. var err = Number(jso.err);
  2204. if (!err) {
  2205. console.log('呼叫被接听成功-----seimin');
  2206. $scope.getState(5);
  2207. $.toaster({
  2208. priority: 'info',
  2209. title: '操作',
  2210. message: '呼叫被接听成功'
  2211. });
  2212. } else {
  2213. console.log('呼叫被接听失败-----seimin');
  2214. $scope.qShimang(1);
  2215. $.toaster({
  2216. priority: 'info',
  2217. title: '操作',
  2218. message: '呼叫被接听失败'
  2219. });
  2220. }
  2221. }
  2222. //挂断回调函数
  2223. TLWSA.onCallend = oncallend;
  2224. function oncallend(jso) {
  2225. console.log(jso);//lmm
  2226. if (jso) {
  2227. console.log('挂断成功-----seimin');
  2228. console.log('最近一次话机状态',$rootScope.preState);
  2229. $scope.qShimang($rootScope.preState);
  2230. $.toaster({
  2231. priority: 'info',
  2232. title: '操作',
  2233. message: '挂断成功'
  2234. });
  2235. } else {
  2236. console.log('挂断失败-----seimin');
  2237. $.toaster({
  2238. priority: 'info',
  2239. title: '操作',
  2240. message: '挂断失败'
  2241. });
  2242. }
  2243. }
  2244. //呼入回调函数
  2245. TLWSA.onCallin = oncallin;
  2246. function oncallin(jso) {
  2247. console.log(jso);//lmm
  2248. $rootScope.callInPhoneNumber = jso.caller;//来电的电话
  2249. $rootScope.sockid = jso.crs;//来电的话机id
  2250. if (jso) {
  2251. console.log('呼入坐席成功,请摘机-----seimin');
  2252. $scope.getState(3);
  2253. $.toaster({
  2254. priority: 'info',
  2255. title: '操作',
  2256. message: '呼入坐席成功,请摘机'
  2257. });
  2258. console.log('来电了!电话号码是【' + $rootScope.callInPhoneNumber + '】');
  2259. } else {
  2260. console.log('呼入坐席失败-----seimin');
  2261. $.toaster({
  2262. priority: 'info',
  2263. title: '操作',
  2264. message: '呼入坐席失败'
  2265. });
  2266. }
  2267. }
  2268. //呼入摘机应答回调函数
  2269. TLWSA.onAnswer = onanswer;
  2270. function onanswer(err) {
  2271. err = Number(err);
  2272. if (!err) {
  2273. console.log('呼入摘机应答成功-----seimin');
  2274. $scope.getState(5);
  2275. $.toaster({
  2276. priority: 'info',
  2277. title: '操作',
  2278. message: '呼入摘机应答成功'
  2279. });
  2280. //根据电话号码反查报修人,如果是坐席号码,则不用
  2281. // console.log(sessionStorage.getItem('phones'));
  2282. // var phones = JSON.parse(sessionStorage.getItem('phones'));
  2283. // var isHuajihao = phones.length?phones.some(v=>v == teleno):false;
  2284. // if(isHuajihao){
  2285. // return;
  2286. // }
  2287. var postData = { "idx": 0, "sum": 10, "requester": { hjzxPhone: $rootScope.callInPhoneNumber } };
  2288. api_user_data.fetchDataList('requester', postData).then(function (result) {
  2289. if (result.status == 200) {
  2290. console.log(result.list);
  2291. var requesters = result.list;
  2292. if (requesters.length === 0) {
  2293. //未匹配到报修人,则弹窗添加报修人yeye
  2294. $state.go('app.incident.chart', {
  2295. model: JSON.stringify({
  2296. model: {
  2297. incident: {
  2298. requester: {
  2299. hjzxPhone: $rootScope.callInPhoneNumber
  2300. },
  2301. sockid: $rootScope.sockid
  2302. }
  2303. }
  2304. })
  2305. });
  2306. } else if (requesters.length === 1) {
  2307. //匹配到一个报修人
  2308. $state.go('app.incident.chart', {
  2309. model: JSON.stringify({
  2310. model: {
  2311. incident: {
  2312. requester: requesters[0],
  2313. contactsInformation: requesters[0].mphone,
  2314. sockid: $rootScope.sockid
  2315. },
  2316. }
  2317. })
  2318. });
  2319. } else {
  2320. //匹配到多个报修人
  2321. $modal.open({
  2322. templateUrl: 'assets/views/incident/tpl/tel.html',
  2323. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  2324. $scope.list = requesters;
  2325. $scope.selectedItem = 0;
  2326. $scope.cancel = function () {
  2327. $modalInstance.dismiss('cancel');
  2328. };
  2329. $scope.changeBxr = function (id) {
  2330. $scope.selectedItem = id;
  2331. }
  2332. $scope.save = function () {
  2333. var item = $scope.list.find(v => v.id == $scope.selectedItem);
  2334. if (item) {
  2335. $scope.cancel();
  2336. $state.go('app.incident.chart', {
  2337. model: JSON.stringify({
  2338. model: {
  2339. incident: {
  2340. requester: item,
  2341. contactsInformation: item.mphone,
  2342. sockid: $rootScope.sockid
  2343. },
  2344. }
  2345. })
  2346. });
  2347. } else {
  2348. SweetAlert.swal({
  2349. title: "请选择报修人!",
  2350. type: "error"
  2351. })
  2352. }
  2353. }
  2354. }
  2355. });
  2356. }
  2357. }
  2358. })
  2359. } else {
  2360. console.log('呼入摘机应答失败-----seimin');
  2361. $.toaster({
  2362. priority: 'info',
  2363. title: '操作',
  2364. message: '呼入摘机应答失败'
  2365. });
  2366. }
  2367. }
  2368. //呼入未摘机应答回调函数
  2369. TLWSA.onMisscall = onmisscall;
  2370. function onmisscall(err) {
  2371. err = Number(err);
  2372. if (!err) {
  2373. console.log('呼入未摘机应答成功-----seimin');
  2374. $scope.getState(1);
  2375. $.toaster({
  2376. priority: 'info',
  2377. title: '操作',
  2378. message: '呼入未摘机应答成功'
  2379. });
  2380. } else {
  2381. console.log('呼入未摘机应答失败-----seimin');
  2382. $.toaster({
  2383. priority: 'info',
  2384. title: '操作',
  2385. message: '呼入未摘机应答失败'
  2386. });
  2387. }
  2388. }
  2389. //转接开始回调函数
  2390. TLWSA.onTransferreturn = ontransferreturn;//调用转移方法之后,返回该事件 如果错误码为0,仅仅表示开始转移,不代表转移目标已经接听或已经拒绝
  2391. function ontransferreturn(err) {
  2392. err = Number(err);
  2393. if (!err) {
  2394. console.log('转接坐席开始成功-----seimin');
  2395. $scope.getState(7);
  2396. $.toaster({
  2397. priority: 'info',
  2398. title: '操作',
  2399. message: '转接坐席开始成功'
  2400. });
  2401. } else {
  2402. console.log('转接坐席开始失败-----seimin');
  2403. $.toaster({
  2404. priority: 'info',
  2405. title: '操作',
  2406. message: '转接坐席开始失败'
  2407. });
  2408. }
  2409. }
  2410. //转接结果回调函数
  2411. TLWSA.onTransferresult = ontransferresult;
  2412. function ontransferresult(err) {
  2413. err = Number(err);
  2414. if (!err) {
  2415. console.log('转接坐席结果成功-----seimin');
  2416. $scope.getState(1);
  2417. $.toaster({
  2418. priority: 'info',
  2419. title: '操作',
  2420. message: '转接坐席结果成功'
  2421. });
  2422. } else {
  2423. console.log('转接坐席结果失败-----seimin');
  2424. $.toaster({
  2425. priority: 'info',
  2426. title: '操作',
  2427. message: '转接坐席结果失败'
  2428. });
  2429. }
  2430. }
  2431. // 签入
  2432. $rootScope.jry_qianru = function () {
  2433. console.log($rootScope.jry_extnNumberObj.jry_extnNumber)
  2434. if(Object.keys($rootScope.jry_extnNumberObj.jry_extnNumber).length === 0){
  2435. $.toaster({
  2436. priority: 'info',
  2437. title: '警告',
  2438. message: '绑定分机不能为空'
  2439. });
  2440. return;
  2441. }
  2442. // 签入并绑定分机
  2443. // $rootScope.jry_extnNumberObj.jry_extnNumber.name 分机号
  2444. // $rootScope.user.id 坐席号(用户id)
  2445. tlwsa.tlaLogin($rootScope.user.id, 1, -1);
  2446. $rootScope.phoneNumber = $rootScope.user.id;
  2447. }
  2448. // 示闲
  2449. $rootScope.jry_shixian = function () {
  2450. tlwsa.tlaWca();
  2451. }
  2452. // 示忙
  2453. $rootScope.jry_shimang = function () {
  2454. tlwsa.tlaAcw();
  2455. }
  2456. // 签出
  2457. $rootScope.jry_qianchu = function () {
  2458. tlwsa.tlaLogoff();
  2459. }
  2460. // 呼叫坐席
  2461. // $scope.tlaCallagc = function () {
  2462. // tlwsa.tlaCallagc($rootScope.jry_extnNumberObj.tel1)
  2463. // }
  2464. // 呼叫外线
  2465. $scope.tlaCallout = function () {
  2466. // 选择目的号码
  2467. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2468. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2469. if(!reg1.test($rootScope.jry_extnNumberObj.tel1)&&!reg2.test($rootScope.jry_extnNumberObj.tel1)){
  2470. $.toaster({
  2471. priority: 'info',
  2472. title: '警告',
  2473. message: '请输入正确的手机号或座机号'
  2474. });
  2475. return;
  2476. }
  2477. tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2478. }
  2479. // // 转移坐席
  2480. // $scope.tlaTransfertoagc = function () {
  2481. // tlwsa.tlaTransfertoagc($rootScope.jry_extnNumberObj.tel2)
  2482. // }
  2483. // 转移外线
  2484. $scope.tlaTransferout = function () {
  2485. // 选择转接号码
  2486. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2487. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2488. if(!reg1.test($rootScope.jry_extnNumberObj.tel2)&&!reg2.test($rootScope.jry_extnNumberObj.tel2)){
  2489. $.toaster({
  2490. priority: 'info',
  2491. title: '警告',
  2492. message: '请输入正确的手机号或座机号'
  2493. });
  2494. return;
  2495. }
  2496. tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2497. }
  2498. })
  2499. }
  2500. $rootScope.getExtnDirect3 = function(){
  2501. console.log($rootScope.user)
  2502. var user = $rootScope.user;
  2503. initImUser(user.email, user.msgUuid);
  2504. // $rootScope.start(JSON.parse(localStorage.userdata).commonExtension.name);
  2505. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function(data) {
  2506. $scope.runNumber = data;
  2507. $scope.phone = $scope.runNumber[0].name;
  2508. $rootScope.phoneChange($scope.phone);
  2509. })
  2510. if ($rootScope.userMenus.length == 0) {
  2511. getMenus();
  2512. }
  2513. if(localStorage.getItem('hk_phone')){
  2514. $rootScope.start(localStorage.getItem('hk_phone'));
  2515. }
  2516. }
  2517. $rootScope.jry_state = 'weiqianru';
  2518. window.addEventListener('load', function () {
  2519. if ($rootScope.isFuwutai) {
  2520. $rootScope.getExtnDirect();//seiminHj----1
  2521. }
  2522. })
  2523. //话机呼叫中心--结束
  2524. // 未接来电
  2525. $scope.jry_getUnanswered = function () {
  2526. var jry_data = {
  2527. idx: 0,
  2528. sum: 999,
  2529. "callRecord": {
  2530. "todayTime": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 00:00:00",
  2531. "todayTimeEnd": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 23:59:59",
  2532. }
  2533. }
  2534. api_bpm_data.fetchDataList("callRecord", jry_data).then(function (data) {
  2535. // fo0h
  2536. for (var i = 0; i < data.list.length; i++) {
  2537. 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()
  2538. }
  2539. $rootScope.jry_unansweredData = data.list;
  2540. });
  2541. }
  2542. // $scope.jry_getUnanswered();
  2543. // 来电号码回拨
  2544. $scope.jry_callBack = function (data) {
  2545. var callBackData = {
  2546. "callRecord": {
  2547. "id": data.id,
  2548. "isAnswered": "1"
  2549. }
  2550. };
  2551. api_bpm_data.updData("callRecord", callBackData).then(function (res) {
  2552. if (res) {
  2553. $scope.jry_getUnanswered();
  2554. dial(data.callerIdNumber)
  2555. }
  2556. });
  2557. if (data.department.id && data.requester) {
  2558. 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 } }
  2559. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2560. } else if (data.department.id) {
  2561. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2562. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2563. } else {
  2564. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2565. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2566. };
  2567. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  2568. }
  2569. //来电号码生成事件
  2570. $scope.jry_callToIncident = function (data) {
  2571. if (data.department.id && data.requester) {
  2572. 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 } }
  2573. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2574. } else if (data.department.id) {
  2575. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2576. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2577. } else {
  2578. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2579. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2580. }
  2581. }
  2582. $scope.onChangeadd = function (searchData) {
  2583. $scope.searchKey = searchData.account;
  2584. // $scope.searchDataadd = searchData;
  2585. var requesdata = angular.copy(searchData)
  2586. $scope.requester = requesdata;
  2587. }
  2588. $scope.refreshUseradd = function (searchKey) { //主题搜索
  2589. $scope.searchData = searchKey;
  2590. reashdata($scope.searchData);
  2591. }
  2592. $scope.getMydata = function (x) {
  2593. $scope.telephone = JSON.parse(x).phone;
  2594. $scope.searchField = $scope.telephone;
  2595. return $scope.searchField;
  2596. }
  2597. $scope.getMydataone = function (x) {
  2598. $scope.telephone = x;
  2599. $scope.searchField = $scope.telephone;
  2600. }
  2601. $scope.fildata = {
  2602. "idx": 0,
  2603. "sum": 10,
  2604. "flag": -1
  2605. }
  2606. function reashdata(item) {
  2607. if (item && item != "") {
  2608. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  2609. } else {
  2610. delete $scope.fildata.user;
  2611. }
  2612. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  2613. if (data.status == 200) {
  2614. $scope.myData = data.list;
  2615. }
  2616. })
  2617. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  2618. // if (response) {
  2619. // if (response.status = 200) {
  2620. // var myData = response;
  2621. // $scope.myData = myData.list;
  2622. // }
  2623. // }
  2624. // })
  2625. }
  2626. if (window.location && window.location.hash == "#/echart") {
  2627. } else {
  2628. reashdata();
  2629. }
  2630. $rootScope.end = function () {
  2631. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  2632. if (data.errno == 0) {
  2633. localStorage.removeItem('hk_phone');
  2634. api_text.exit($rootScope.takes).then(function (data) {
  2635. if (data.errno == 0) {
  2636. $rootScope.statuscall = 0;
  2637. $scope.login = false;
  2638. // SweetAlert.swal({
  2639. // title: "登出成功",
  2640. // text: "呼叫中心登出成功!",
  2641. // type: "success"
  2642. // });
  2643. // }else{SweetAlert.swal({
  2644. // title: "登出失败",
  2645. // text: "呼叫中心登出失败!",
  2646. // type: "error"
  2647. // });
  2648. }
  2649. })
  2650. }
  2651. })
  2652. }
  2653. $rootScope.dialout = function (gid, teleno) {
  2654. var telephone = "";
  2655. if (teleno && teleno.length > 4) {
  2656. telephone = '9' + teleno;
  2657. } else {
  2658. // telephone = '*01' + teleno + '*';
  2659. telephone = teleno;
  2660. }
  2661. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  2662. if (data.errno == 0) {
  2663. // $rootScope.statuscall = 3;
  2664. $rootScope.callout = true;
  2665. // $rootScope.phone=teleno;
  2666. }
  2667. })
  2668. }
  2669. // $scope.busy=false;
  2670. $rootScope.setbusy = function () {
  2671. api_text.setbusy($rootScope.takes).then(function (data) {
  2672. if (data.errno == 0) {
  2673. $rootScope.statecall = 2;
  2674. $scope.busy = true;
  2675. }
  2676. })
  2677. }
  2678. $rootScope.setidle = function () {
  2679. api_text.setidle($rootScope.takes).then(function (data) {
  2680. if (data.errno == 0) {
  2681. $rootScope.statecall = 1;
  2682. $scope.busy = false;
  2683. }
  2684. })
  2685. }
  2686. $rootScope.inittrans = function (telephone) {
  2687. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  2688. if (data.errno == 0) {
  2689. // $scope.status=9
  2690. }
  2691. })
  2692. }
  2693. $rootScope.comptrans = function () {
  2694. api_text.comptrans($rootScope.takes).then(function (data) {
  2695. if (data.errno == 0) {
  2696. $rootScope.statuscall = 1;
  2697. }
  2698. })
  2699. }
  2700. $rootScope.takeup = function () {
  2701. api_text.offhook($rootScope.takes).then(function (data) {
  2702. if (data.errno == 0) {
  2703. $rootScope.statuscall = 3;
  2704. }
  2705. })
  2706. }
  2707. $rootScope.takedown = function () {
  2708. api_text.onhook($rootScope.takes).then(function (data) {
  2709. if (data.errno == 0) {
  2710. $rootScope.statuscall = 1;
  2711. }
  2712. })
  2713. }
  2714. $rootScope.saveData = function (selectdata) {
  2715. var modalInstance = $modal.open({
  2716. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  2717. controller: function ($scope, $modalInstance, api_bpm_data) {
  2718. $scope.worktimedata = {};
  2719. $scope.worktimedata = selectdata;
  2720. $scope.cancel = function () {
  2721. $modalInstance.dismiss('cancel');
  2722. };
  2723. $scope.savercode = function (worktimedata) {
  2724. var fildata = {
  2725. "scheduleclass": {
  2726. "id": selectdata.id,
  2727. "code": worktimedata.code,
  2728. "name": worktimedata.title,
  2729. "person": worktimedata.person,
  2730. "description": worktimedata.description,
  2731. "startTime": worktimedata.startTime,
  2732. "endTime": worktimedata.endTime,
  2733. "shiftTime": selectdata.shiftTime,
  2734. "succeedTime": selectdata.succeedTime,
  2735. "isTemplate": worktimedata.isTemplate
  2736. }
  2737. }
  2738. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  2739. if (response) {
  2740. if (response.status == 200) {
  2741. SweetAlert.swal({
  2742. title: "修改成功!",
  2743. type: "success"
  2744. }, function () {
  2745. // $scope.refreshData('expand-right', defaultFilterData);
  2746. })
  2747. } else {
  2748. SweetAlert.swal({
  2749. title: "修改失败!",
  2750. type: "error"
  2751. })
  2752. }
  2753. }
  2754. })
  2755. $modalInstance.close();
  2756. }
  2757. }
  2758. });
  2759. }
  2760. $rootScope.changepassword = function (data1, size) {
  2761. var modalInstance = $modal.open({
  2762. templateUrl: 'assets/views/changepassword.html',
  2763. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  2764. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  2765. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  2766. }
  2767. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  2768. $modalInstance.dismiss('cancel');
  2769. // console.log('pwd=' + pwd + '+' + pwd_2);
  2770. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  2771. if (pwd == pwd_2) {
  2772. var data2 = {};
  2773. data2["originalPwd"] = originalPwd;
  2774. data2["userid"] = $rootScope.user.id;
  2775. data2["pwd"] = pwd;
  2776. api_login.uppwd(data2).then(function (response) {
  2777. var myData = Restangular.stripRestangular(response);
  2778. if (myData.status == 200) {
  2779. SweetAlert.swal({
  2780. title: "保存成功!",
  2781. type: "success",
  2782. confirmButtonColor: "#007AFF"
  2783. });
  2784. } else {
  2785. SweetAlert.swal({
  2786. title: "保存失败!",
  2787. text: "输入旧密码错误,请重新输入!",
  2788. type: "error"
  2789. });
  2790. }
  2791. })
  2792. } else {
  2793. SweetAlert.swal({
  2794. title: "两次输入的新密码不相同!",
  2795. text: "输入错误,请重新输入!",
  2796. type: "error"
  2797. });
  2798. }
  2799. // }else{
  2800. // SweetAlert.swal({
  2801. // title: "密码不能为空!",
  2802. // text: "请输入密码!",
  2803. // type: "error"
  2804. // });
  2805. // }
  2806. }
  2807. },
  2808. size: size,
  2809. resolve: {
  2810. items: function () {
  2811. return {
  2812. fetchItems: function (filterData, APIService) { }
  2813. };
  2814. },
  2815. }
  2816. });
  2817. }
  2818. // $rootScope.getnochildpending = function() {
  2819. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2820. // angular.forEach($rootScope.userMenus, function(item) {
  2821. // item.tipnum = 1;
  2822. // })
  2823. // }
  2824. // }
  2825. // $rootScope.getchildpending = function(cantdata) {
  2826. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2827. // angular.forEach($rootScope.userMenus, function(item) {
  2828. // item.tipnum = 1;
  2829. // angular.forEach(item, function(index) {
  2830. // index.tipnum = 18;
  2831. // })
  2832. // })
  2833. // }
  2834. // }
  2835. $rootScope.getpending = function () {
  2836. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2837. if ($rootScope.user.group) {
  2838. var groupArr = [];
  2839. for (var i = 0; i < $rootScope.user.group.length; i++) {
  2840. groupArr.push($rootScope.user.group[i].id)
  2841. }
  2842. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  2843. angular.forEach($rootScope.userMenus, function (item, i) {
  2844. item.tipshow = false;
  2845. if (response) {
  2846. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  2847. if (item.id == 58) {
  2848. item.tipshow = true;
  2849. }
  2850. }
  2851. if (response.inspectionCount > 0) {
  2852. if (item.id == 27) {
  2853. item.tipshow = true;
  2854. }
  2855. }
  2856. if (response.incidentCount > 0) {
  2857. if (item.id == 2) {
  2858. item.tipshow = true;
  2859. }
  2860. }
  2861. if (response.releaseCount > 0) {
  2862. if (item.id == 1215) {
  2863. item.tipshow = true;
  2864. }
  2865. }
  2866. if (response.solutionCount > 0) {
  2867. if (item.id == 21) {
  2868. item.tipshow = true;
  2869. }
  2870. }
  2871. if (response.changeCount > 0) {
  2872. if (item.id == 1212) {
  2873. item.tipshow = true;
  2874. }
  2875. }
  2876. if (response.problemCount > 0) {
  2877. if (item.id == 1209) {
  2878. item.tipshow = true;
  2879. }
  2880. }
  2881. if (response.applicationForm > 0) {
  2882. if (item.id == 1221) {
  2883. item.tipshow = true;
  2884. }
  2885. }
  2886. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2887. if (item.id == 21) {
  2888. item.tipshow = true;
  2889. }
  2890. }
  2891. if (item.children) {
  2892. angular.forEach(item.children, function (index) {
  2893. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  2894. if (index.id == 1208) {
  2895. if (response.hjzxCount < 100) {
  2896. index.tipnum = response.hjzxCount;
  2897. } else {
  2898. index.tipnum = "99+";
  2899. }
  2900. }
  2901. }
  2902. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  2903. if (index.id == 59) {
  2904. if (response.wechatWarningCount < 100) {
  2905. index.tipnum = response.wechatWarningCount;
  2906. } else {
  2907. index.tipnum = "99+";
  2908. }
  2909. }
  2910. }
  2911. if (response.problemCount !== null && response.problemCount !== undefined) {
  2912. if (index.id == 1210) {
  2913. if (response.problemCount < 100) {
  2914. index.tipnum = response.problemCount;
  2915. } else {
  2916. index.tipnum = "99+";
  2917. }
  2918. }
  2919. }
  2920. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  2921. if (index.id == 1216) {
  2922. if (response.releaseCount < 100) {
  2923. index.tipnum = response.releaseCount;
  2924. } else {
  2925. index.tipnum = "99+";
  2926. }
  2927. }
  2928. }
  2929. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  2930. if (index.id == 147) {
  2931. if (response.inspectionCount < 100) {
  2932. index.tipnum = response.inspectionCount;
  2933. } else {
  2934. index.tipnum = "99+";
  2935. }
  2936. }
  2937. }
  2938. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  2939. if (index.id == 23) {
  2940. if (response.solutionCount < 100) {
  2941. index.tipnum = response.solutionCount;
  2942. } else {
  2943. index.tipnum = "99+";
  2944. }
  2945. }
  2946. }
  2947. if (response.changeCount !== null && response.changeCount !== undefined) {
  2948. if (index.id == 1213) {
  2949. if (response.changeCount < 100) {
  2950. index.tipnum = response.changeCount;
  2951. } else {
  2952. index.tipnum = "99+";
  2953. }
  2954. }
  2955. }
  2956. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  2957. if (index.id == 3) {
  2958. if (response.incidentCount < 100) {
  2959. index.tipnum = response.incidentCount;
  2960. } else {
  2961. index.tipnum = "99+";
  2962. }
  2963. }
  2964. }
  2965. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  2966. if (index.id == 1231) {
  2967. if (response.applicationForm < 100) {
  2968. index.tipnum = response.applicationForm;
  2969. } else {
  2970. index.tipnum = "99+";
  2971. }
  2972. }
  2973. }
  2974. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2975. if (index.id == 23) {
  2976. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  2977. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2978. } else {
  2979. index.tipnum = "99+";
  2980. }
  2981. }
  2982. }
  2983. })
  2984. }
  2985. }
  2986. })
  2987. // return $rootScope.userMenus;
  2988. // $scope.recordpending = response.;
  2989. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2990. })
  2991. } else {
  2992. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  2993. }
  2994. }
  2995. // console.log($rootScope.userMenus);
  2996. }
  2997. $rootScope.userMenus = [];
  2998. var getMenus = function () {
  2999. function convertListToTree(data, treeMap) {
  3000. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  3001. var root = null; //Initially set our loop to null
  3002. var parentNode = null;
  3003. //loop over data
  3004. for (var i = 0; i < data.length; i++) {
  3005. // data[i].id = Number(data[i].id);
  3006. var datum = data[i];
  3007. //each node will have children, so let's give it a "children" poperty
  3008. datum.children = [];
  3009. //add an entry for this node to the map so that any future children can
  3010. //lookup the parent
  3011. idToNodeMap[datum.id] = datum;
  3012. //Does this node have a parent?
  3013. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  3014. //Doesn't look like it, so this node is the root of the tree
  3015. root = datum;
  3016. treeMap[datum.id] = root;
  3017. } else {
  3018. //This node has a parent, so let's look it up using the id
  3019. parentNode = idToNodeMap[datum.parentid];
  3020. //We don't need this property, so let's delete it.
  3021. //delete datum.parentid;
  3022. //Let's add the current node as a child of the parent node.
  3023. parentNode.children.push(datum);
  3024. }
  3025. }
  3026. return root;
  3027. }
  3028. function convertParentToChildList(data) {
  3029. var treeMap = {};
  3030. var list = [];
  3031. convertListToTree(data, treeMap);
  3032. angular.forEach(treeMap, function (item) {
  3033. list.push(item);
  3034. });
  3035. list = window._.sortBy(list, function (o) {
  3036. return o.orders;
  3037. });
  3038. return list;
  3039. }
  3040. //if(userMenus.length==0){
  3041. var userMenus = [];
  3042. var idMapMenu = {};
  3043. if ($rootScope.user) {
  3044. if ($rootScope.user.menu) {
  3045. var allJurisdiction2 = $rootScope.user.menu;
  3046. var onlyMenu2 = [];
  3047. for (var i = 0; i < allJurisdiction2.length; i++) {
  3048. if (allJurisdiction2[i].event == "1") {
  3049. onlyMenu2.push(allJurisdiction2[i])
  3050. }
  3051. }
  3052. // userMenus = convertParentToChildList($rootScope.user.menu);
  3053. userMenus = convertParentToChildList(onlyMenu2);
  3054. }
  3055. }
  3056. //}
  3057. $rootScope.userMenus = userMenus;
  3058. if ($rootScope.userMenus.length > 0) {
  3059. $rootScope.getpending();
  3060. // setInterval($rootScope.getpending(), 30000);
  3061. }
  3062. return userMenus;
  3063. }
  3064. setInterval(function () {
  3065. if ($rootScope.userMenus.length > 0) {
  3066. $rootScope.getpending()
  3067. $rootScope.getMsgNum($rootScope.user.id)
  3068. }
  3069. }, 5000);
  3070. getMenus();
  3071. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  3072. $rootScope.logout = function () {
  3073. // var userid =data.id;
  3074. // console.log(' userid='+JSON.stringify( userid));
  3075. //单点登录
  3076. if (localStorage.getItem('isSSo') === '1') {
  3077. $scope.runNumber = [];
  3078. sessionStorage.clear();
  3079. localStorage.clear();
  3080. location.href = 'http://' + location.hostname + '/pc_logout.jsp'
  3081. } else {
  3082. $auth.signOut()
  3083. .then(function (resp) {
  3084. // $auth.deleteData('auth_headers')
  3085. $scope.runNumber = [];
  3086. sessionStorage.clear();
  3087. localStorage.clear();
  3088. console.log($rootScope.isHk,'hk');
  3089. console.log($rootScope.isZncd,'zncd');
  3090. if($rootScope.isZncd){
  3091. if ($rootScope.isFuwutai) {
  3092. tlwsa.tlaClose();
  3093. $.toaster({
  3094. priority: 'info',
  3095. title: '操作',
  3096. message: '呼叫中心断开连接'
  3097. });
  3098. }
  3099. }
  3100. $state.go("login.signin");
  3101. })
  3102. .catch(function (resp) { });
  3103. }
  3104. //$cookieStore.remove("userObm");
  3105. //$cookieStore.remove("menuObm");
  3106. //$cookieStore.remove("session");
  3107. //$rootScope.user = undefined;
  3108. //$rootScope.menus = undefined;
  3109. //$rootScope.nickname = undefined;
  3110. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  3111. // //logout: function(noServerLogout){
  3112. // window.sessionStorage.clear();
  3113. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  3114. // //},
  3115. }
  3116. // 快速建单
  3117. $rootScope.newOrder = function () {
  3118. $state.go('app.newOrder');
  3119. }
  3120. // save settings to local storage
  3121. if (angular.isDefined($localStorage.layout)) {
  3122. $scope.app.layout = $localStorage.layout;
  3123. } else {
  3124. $localStorage.layout = $scope.app.layout;
  3125. }
  3126. $scope.$watch('app.layout', function () {
  3127. // save to local storage
  3128. $localStorage.layout = $scope.app.layout;
  3129. }, true);
  3130. //global function to scroll page up
  3131. $scope.toTheTop = function () {
  3132. $document.scrollTopAnimated(0, 600);
  3133. };
  3134. // angular translate
  3135. // ----------------------
  3136. $scope.language = {
  3137. // Handles language dropdown
  3138. listIsOpen: false,
  3139. // list of available languages
  3140. available: {
  3141. 'en': 'English',
  3142. 'it_IT': 'Italiano',
  3143. 'de_DE': 'Deutsch',
  3144. 'zh_cn': 'Chinese'
  3145. },
  3146. // display always the current ui language
  3147. init: function () {
  3148. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  3149. var preferredLanguage = $translate.preferredLanguage();
  3150. // we know we have set a preferred one in app.config
  3151. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  3152. },
  3153. set: function (localeId, ev) {
  3154. $translate.use(localeId);
  3155. $scope.language.selected = $scope.language.available[localeId];
  3156. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  3157. }
  3158. };
  3159. $scope.language.init();
  3160. // Function that find the exact height and width of the viewport in a cross-browser way
  3161. var viewport = function () {
  3162. var e = window,
  3163. a = 'inner';
  3164. if (!('innerWidth' in window)) {
  3165. a = 'client';
  3166. e = document.documentElement || document.body;
  3167. }
  3168. return {
  3169. width: e[a + 'Width'],
  3170. height: e[a + 'Height']
  3171. };
  3172. };
  3173. // function that adds information in a scope of the height and width of the page
  3174. $scope.getWindowDimensions = function () {
  3175. return {
  3176. 'h': viewport().height,
  3177. 'w': viewport().width
  3178. };
  3179. };
  3180. // Detect when window is resized and set some variables
  3181. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  3182. $scope.windowHeight = newValue.h;
  3183. $scope.windowWidth = newValue.w;
  3184. if (newValue.w >= 992) {
  3185. $scope.isLargeDevice = true;
  3186. } else {
  3187. $scope.isLargeDevice = false;
  3188. }
  3189. if (newValue.w < 992) {
  3190. $scope.isSmallDevice = true;
  3191. } else {
  3192. $scope.isSmallDevice = false;
  3193. }
  3194. if (newValue.w <= 768) {
  3195. $scope.isMobileDevice = true;
  3196. } else {
  3197. $scope.isMobileDevice = false;
  3198. }
  3199. }, true);
  3200. // Apply on resize
  3201. $win.on('resize', function () {
  3202. $scope.$apply();
  3203. });
  3204. $rootScope.app.layout.isNavbarFixed = false;
  3205. $rootScope.app.layout.isSidebarFixed = false;
  3206. $rootScope.app.layout.isFooterFixed = false;
  3207. $scope.login_signquick = function (Requesteruserinform) {
  3208. $rootScope.statuscall = 1;
  3209. $scope.loginForm = {
  3210. username: Requesteruserinform.username,
  3211. password: Requesteruserinform.password
  3212. }
  3213. $auth.submitLogin($scope.loginForm)
  3214. .then(function (resp) {
  3215. localStorage.setItem("jry_user", JSON.stringify(resp));
  3216. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  3217. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  3218. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  3219. var onlyMenu = [];
  3220. for (var i = 0; i < allJurisdiction.length; i++) {
  3221. if (allJurisdiction[i].event == "1") {
  3222. onlyMenu.push(allJurisdiction[i])
  3223. }
  3224. };
  3225. $rootScope.userMenus = onlyMenu;
  3226. getMenus();
  3227. if (resp.error != 500) {
  3228. // $state.go('app.dashboard');
  3229. $rootScope.app.isLoginFixed = false;
  3230. } else {
  3231. resp.error = "";
  3232. $scope.loginForm.password = "";
  3233. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  3234. }
  3235. })
  3236. .catch(function (resp) {
  3237. $scope.loginForm.password = "";
  3238. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  3239. });
  3240. }
  3241. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  3242. var theRequest = {};
  3243. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  3244. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  3245. var str = url.substr(index + 1);
  3246. var strs = str.split("&");
  3247. for (var i = 0; i < strs.length; i++) {
  3248. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  3249. }
  3250. // return theRequest;
  3251. $scope.login_signquick(theRequest)
  3252. }
  3253. // $scope.casUserId = window.location.search;
  3254. // $scope.loginForm = {
  3255. // username: theRequest[0].split("=")[1],
  3256. // password: theRequest[1].split("=")[1]
  3257. // }
  3258. // $scope.lodingstyle = 'nodata';
  3259. var userAgent = window.navigator.userAgent.toLowerCase();
  3260. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  3261. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  3262. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  3263. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  3264. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  3265. if (isOpera) {
  3266. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  3267. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  3268. }
  3269. if (isIE) {
  3270. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  3271. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  3272. }
  3273. if (isFF) {
  3274. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  3275. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  3276. }
  3277. if (isSafari) {
  3278. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  3279. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  3280. }
  3281. if (isChrome) {
  3282. // login_sign();
  3283. $rootScope.app.isChrome = false;
  3284. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  3285. } else {
  3286. $rootScope.app.isChrome = true;
  3287. $scope.checkchrome = '';
  3288. // return alert("访问失败,请用Chrome浏览器访问!");
  3289. }
  3290. // }
  3291. // $scope.handleloginEnter = function(e) {
  3292. // if (e.keyCode == 13) {
  3293. // $scope.handleLoginClick();
  3294. // }
  3295. // };
  3296. // if (document.getElementById("isWatch").value == "true") {
  3297. // $scope.isHanderuser = true;
  3298. // } else {
  3299. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  3300. // $scope.isHanderuser = false;
  3301. // $scope.login_sign();
  3302. // }
  3303. // }
  3304. // $scope.viewType = "password";
  3305. // $scope.isPassword = true;
  3306. // $scope.toggleView = function() {
  3307. // $scope.isPassword = !$scope.isPassword;
  3308. // $scope.viewType = $scope.isPassword ? "password" : "text";
  3309. // }
  3310. // $scope.handleSignOutBtnClick = function() {
  3311. // $auth.signOut()
  3312. // .then(function(resp) {
  3313. // // handle success response
  3314. // })
  3315. // .catch(function(resp) {
  3316. // // handle error response
  3317. // });
  3318. // };
  3319. // }
  3320. // }
  3321. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  3322. // } else {
  3323. // $scope.loginstart();
  3324. // }
  3325. //websocket 信息中心
  3326. console.log(atmosphere)
  3327. var socket = atmosphere;
  3328. var subSocket;
  3329. // We are now ready to cut the request
  3330. var request = {
  3331. url: 'ws://192.168.199.150:8080/messagestation/cache',
  3332. contentType: "application/json",
  3333. shared: true, // 标签共享
  3334. trackMessageLength: true, //校验数据完整性
  3335. transport: 'websocket'
  3336. };
  3337. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  3338. request.onOpen = function (response) {
  3339. console.log(response)
  3340. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  3341. // alert("开始连接")
  3342. };
  3343. request.onMessage = function (response) {
  3344. var message = response.responseBody;
  3345. // alert("连接成功")
  3346. console.log(message)
  3347. try {
  3348. var json = JSON.parse(message);
  3349. console.log(json.noRead)
  3350. $scope.noReadData = json.noRead
  3351. } catch (e) {
  3352. console.log('呵呵哒: ', message);
  3353. return;
  3354. }
  3355. };
  3356. request.onClose = function (response) {
  3357. // alert("连接结束")
  3358. }
  3359. request.onError = function (response) {
  3360. // alert('连接失败')
  3361. };
  3362. //信息中心模态框
  3363. var loginUser = $rootScope.user;
  3364. // if(loginUser){
  3365. // // 未读消息数量
  3366. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  3367. // if (data.status == 200) {
  3368. // $scope.noReadData=data.totalNum
  3369. // // $rootScope.option.all = $rootScope.all;
  3370. // } else {
  3371. // $scope.noReadData=0
  3372. // }
  3373. // })
  3374. // }
  3375. // $scope.noReadData=($rootScope.noReadData||0)
  3376. // // $rootScope.all = 5;
  3377. // setTimeout(function() {
  3378. // console.log($scope.noReadData)
  3379. // }, 500)
  3380. $rootScope.wt_messages = function () {
  3381. var modalInstance = $modal.open({
  3382. templateUrl: './assets/views/wt_messages.html',
  3383. controller: function ($scope, $modalInstance) {
  3384. $rootScope.msgData = {
  3385. idx: 0,
  3386. sum: 5,
  3387. messageStation: {
  3388. readStatus: 0,
  3389. userId: $rootScope.user.id
  3390. }
  3391. }
  3392. // 关闭
  3393. $scope.closeModel = function () {
  3394. modalInstance.close();
  3395. }
  3396. $scope.getMsgData = function () {
  3397. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3398. if (data) {
  3399. $rootScope.msg = data.list
  3400. $rootScope.all = data.pageCount;
  3401. $scope.wt_msgData = data
  3402. $rootScope.noReadData = data.totalNum
  3403. }
  3404. })
  3405. }
  3406. $scope.getMsgData()
  3407. $scope.message_type = 2;
  3408. $scope.message_no = function (type) { //未读1
  3409. $scope.wt_msgData = {};
  3410. $scope.message_type = type;
  3411. $rootScope.msgData.messageStation.readStatus = 0,
  3412. // $rootScope.option.curr = 1;
  3413. $rootScope.msgData.idx = 0;
  3414. // console.log($rootScope.option.curr)
  3415. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3416. $scope.msg_yesType = true;
  3417. if (data.status == 200) {
  3418. $scope.msg_yesType = false
  3419. $scope.wt_msgData = data
  3420. $rootScope.msg = data.list
  3421. $rootScope.all = data.pageCount;
  3422. $rootScope.noReadData = data.totalNum;
  3423. // $rootScope.option.all = $rootScope.all;
  3424. } else {
  3425. $scope.msg_yesType = true;
  3426. }
  3427. })
  3428. }
  3429. $scope.message_yes = function (type) { //已读0
  3430. $scope.wt_msgData = {};
  3431. $scope.message_type = type;
  3432. $rootScope.msgData.messageStation.readStatus = 1,
  3433. $rootScope.msgData.idx = 0;
  3434. // $rootScope.option.curr = 1;
  3435. // console.log($rootScope.option.curr)
  3436. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3437. $scope.msg_noType = true;
  3438. if (data.status == 200) {
  3439. $scope.msg_noType = false
  3440. $scope.wt_msgData = data
  3441. $rootScope.msg = data.list;
  3442. $rootScope.all = data.pageCount;
  3443. // $rootScope.option.all = $rootScope.all;
  3444. } else {
  3445. $scope.msg_noType = true
  3446. }
  3447. })
  3448. };
  3449. $scope.sBtn = function () {
  3450. // console.log($rootScope.msgData)
  3451. // console.log($scope.wt_msgData)
  3452. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  3453. console.log($rootScope.msgData)
  3454. $scope.getMsgData()
  3455. }
  3456. $scope.xBtn = function () {
  3457. // console.log($rootScope.msgData)
  3458. // console.log($scope.wt_msgData)
  3459. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  3460. console.log($rootScope.msgData)
  3461. $scope.getMsgData()
  3462. }
  3463. $scope.redIn = function (data) {
  3464. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  3465. $scope.messageStation = {
  3466. messageStation: {
  3467. id: data.id,
  3468. readStatus: 1,
  3469. readTime: start
  3470. }
  3471. }
  3472. api_msg.updateDataList($scope.messageStation).then(function (data) {
  3473. console.log(data);
  3474. if (data.status == 200) {
  3475. $rootScope.msgData.messageStation.readStatus = 0,
  3476. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3477. $rootScope.msg = data.list
  3478. $rootScope.all = data.pageCount;
  3479. $rootScope.noReadData = data.totalNum;
  3480. })
  3481. }
  3482. })
  3483. };
  3484. },
  3485. size: 'lg',
  3486. resolve: {
  3487. }
  3488. })
  3489. }
  3490. }
  3491. ]);
  3492. //消息中心分页组件
  3493. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  3494. $rootScope.option = {
  3495. curr: 1, //当前页数
  3496. all: $rootScope.all, //总页数
  3497. count: 5, //最多显示的页数,默认为10
  3498. //点击页数的回调函数,参数page为点击的页数
  3499. click: function (page) {
  3500. $rootScope.msgData.idx = page - 1;
  3501. //这里可以写跳转到某个页面等...
  3502. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  3503. $rootScope.msg = data.list
  3504. $rootScope.all = data.pageCount;
  3505. $rootScope.option.all = $rootScope.all;
  3506. })
  3507. }
  3508. }
  3509. }]);
  3510. app.directive('myPagination', function () {
  3511. return {
  3512. restrict: 'EA',
  3513. replace: true,
  3514. rootScope: {
  3515. option: '=pageOption'
  3516. },
  3517. controller: 'msgCtrl',
  3518. template: '<ul class="pagination">' +
  3519. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  3520. '<a href="javascript:;">{{p}}</a>' +
  3521. '</li>' +
  3522. '</ul>',
  3523. link: function ($rootScope) {
  3524. //容错处理
  3525. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  3526. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  3527. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  3528. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  3529. //得到显示页数的数组
  3530. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  3531. //绑定点击事件
  3532. $rootScope.pageClick = function (page) {
  3533. if (page == '«') {
  3534. page = parseInt($rootScope.option.curr) - 1;
  3535. } else if (page == '»') {
  3536. page = parseInt($rootScope.option.curr) + 1;
  3537. }
  3538. if (page < 1) page = 1;
  3539. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  3540. //点击相同的页数 不执行点击事件
  3541. if (page == $rootScope.option.curr) return;
  3542. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  3543. $rootScope.option.click(page);
  3544. $rootScope.option.curr = page;
  3545. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  3546. }
  3547. };
  3548. //返回页数范围(用来遍历)
  3549. function getRange(curr, all, count) {
  3550. //计算显示的页数
  3551. // console.log(curr, all, count)
  3552. curr = parseInt(curr);
  3553. all = parseInt(all);
  3554. count = parseInt(count);
  3555. var from = curr - parseInt(count / 2);
  3556. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  3557. //显示的页数容处理
  3558. if (from <= 0) {
  3559. from = 1;
  3560. to = from + count - 1;
  3561. if (to > all) {
  3562. to = all;
  3563. }
  3564. }
  3565. if (to > all) {
  3566. to = all;
  3567. from = to - count + 1;
  3568. if (from <= 0) {
  3569. from = 1;
  3570. }
  3571. }
  3572. var range = [];
  3573. for (var i = from; i <= to; i++) {
  3574. range.push(i);
  3575. }
  3576. range.push('»');
  3577. range.unshift('«');
  3578. return range;
  3579. }
  3580. }
  3581. }
  3582. });
  3583. app.service('Myservice', function () {
  3584. return {
  3585. };
  3586. });
  3587. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3588. // console.log(bh)
  3589. // if(bh>=0&&bh<=53){
  3590. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3591. // }else{
  3592. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3593. // }
  3594. window.onscroll = function () {
  3595. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  3596. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  3597. } else {
  3598. $('#sidebar').css('padding-top', '0')
  3599. }
  3600. // console.log(window.pageYOffset)
  3601. // console.log(window.innerHeight)
  3602. // console.log(document.body.scrollHeight)
  3603. // 底部padding
  3604. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3605. // console.log(bh)
  3606. // if(bh>=0&&bh<=53){
  3607. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3608. // }else{
  3609. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3610. // }
  3611. }