mainCtrl.js 179 KB

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