mainCtrl.js 263 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978
  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','fileReader','api_custom','api_category','api_simple','WebsocketPhoneService','api_newreport', 'api_flow',
  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,fileReader,api_custom,api_category,api_simple,WebsocketPhoneService,api_newreport,api_flow) {
  7. // 未读消息数量seimin
  8. $rootScope.getMsgNum = function (id) {
  9. api_msg.msgDataList({ idx: 0, sum: 1, messageStation: { readStatus: 0, userId: id } }).then(function (data) {
  10. if (data.status == 200) {
  11. $rootScope.noReadData = data.totalNum;
  12. }
  13. return $rootScope.noReadData
  14. })
  15. }
  16. // Loading bar transition
  17. // -----------------------------------
  18. // console.log("haha");
  19. // 附件地址拼接-全局
  20. $rootScope.attachmentAddressSplicing = function(relativeFilePath){
  21. return location.origin + '/file' + relativeFilePath;
  22. }
  23. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  24. $rootScope.isRealtimeBroadcast = ($rootScope.user && $rootScope.user.menu)?$rootScope.user.menu.some(v => v.link == 'realtimeBroadcast'):false;
  25. $rootScope.isFuwutai = JSON.parse(localStorage.getItem("isFuwutai")) ? true : false;
  26. console.log($rootScope.user)
  27. //判断项目归属 start
  28. //因项目众多,前端为了加以区分,所以用域名加以判断,后期有更好的方式可以自行修改
  29. $rootScope.judgeHjzx = function(isMask = false, isStart = false){
  30. if(!$rootScope.user){
  31. return;
  32. }
  33. $rootScope.isZncd = false;
  34. $rootScope.isHk = false;
  35. $rootScope.isXy = false;
  36. $rootScope.isXyBox = false;
  37. var branchId;
  38. // 当前所属院区或责任科室
  39. if($rootScope.user.duty){
  40. branchId = $rootScope.user.duty.branch;
  41. }else if($rootScope.user.branch){
  42. branchId = $rootScope.user.branch.id;
  43. }
  44. if(isMask){
  45. $rootScope.isMask = true;
  46. }
  47. api_simple.fetchDataList("hospitalConfig", {"idx":0,"sum":100,"hospitalConfig":{"hosId":branchId}}).then(function(result){
  48. if(isMask){
  49. $rootScope.isMask = false;
  50. }
  51. if(result.status = 200){
  52. var hospitalConfig = result.list || [];
  53. var ccTypeDTO = hospitalConfig.find(function(v){return v.key == 'ccType'});
  54. // 暂无 1
  55. // 东进呼叫中心 2
  56. // 申欧录音盒子 3
  57. $rootScope.isXy = ccTypeDTO && ccTypeDTO.value == 2;
  58. $rootScope.isXyBox = ccTypeDTO && ccTypeDTO.value == 3;
  59. if($rootScope.isZncd){
  60. localStorage.setItem('version_qd','isZncd');
  61. }else if($rootScope.isHk){
  62. localStorage.setItem('version_qd','isHk');
  63. }else if($rootScope.isXy){
  64. localStorage.setItem('version_qd','isXy');
  65. }else if($rootScope.isXyBox){
  66. $rootScope.phoneNumList = hospitalConfig.filter(function(v){return v.key.includes('phone_num_port') && v.value}).map(function(v){return {value: v.value, checked: false}});
  67. $rootScope.phoneNumListBind.forEach((item) => {
  68. let obj = $rootScope.phoneNumList.find((item1) => item1.value === item);
  69. if (obj) {
  70. obj.checked = true;
  71. }
  72. });
  73. $rootScope.phoneNumListSelected = $rootScope.phoneNumList.filter(v => v.checked).map(v => v.value);
  74. $rootScope.phoneNumListSelectedStr = $rootScope.phoneNumListSelected.length ? '您选择了'+ $rootScope.phoneNumListSelected.map(v => '‘'+ v +'’').join('') +'号码,可在下方选择后确认更新。' : '请选择分机';
  75. console.log($rootScope.phoneNumList, 'phoneNumList');
  76. console.log($rootScope.phoneNumListBind, 'phoneNumListBind');
  77. localStorage.setItem('version_qd','isXyBox');
  78. }else{
  79. localStorage.removeItem('version_qd');
  80. }
  81. // 1是老的呼叫中心
  82. // 2是财大2021年12月29日新增的呼叫中心
  83. // 3是华科新增的呼叫中心
  84. // 4是支助紫铜录音盒子
  85. console.log($rootScope.isHk,'hk')
  86. console.log($rootScope.isZncd,'zncd')
  87. console.log($rootScope.isXy,'xy')
  88. console.log($rootScope.isXyBox,'xyBox')
  89. if($rootScope.isZncd || $rootScope.isXy){
  90. $rootScope.seiminHj = 2;
  91. }else if($rootScope.isXyBox){
  92. $rootScope.seiminHj = 4;
  93. }else if($rootScope.isHk){
  94. $rootScope.seiminHj = 3;
  95. }else{
  96. // $rootScope.seiminHj = 1;
  97. }
  98. if (isStart && $rootScope.isFuwutai && ($rootScope.isXy || $rootScope.isXyBox)) {
  99. console.log($rootScope.seiminHj, 'seiminHj');
  100. $rootScope.getExtnDirect();//seiminHj----1
  101. }
  102. }
  103. })
  104. }
  105. // $rootScope.judgeHjzx();
  106. //判断项目归属 end
  107. var loginUser = $rootScope.user;
  108. if(loginUser){
  109. $scope.allFlag = false;//全部事件
  110. for (var i = 0; i < loginUser.menu.length; i++) {
  111. if (loginUser.menu[i].link == "shijianliebiao_all") {
  112. $scope.allFlag = true
  113. }
  114. }
  115. }
  116. if ($rootScope.user) {
  117. $rootScope.getMsgNum($rootScope.user.id);
  118. }
  119. var $win = $($window);
  120. $rootScope.isMask = false;
  121. window.onbeforeunload = function () {
  122. $rootScope.statuscall = 0;
  123. $rootScope.statecall = 1;
  124. }
  125. // 所有列表自动刷新
  126. $rootScope.refreshTime = 60000;
  127. $interval(function () {
  128. $scope.jry_year = new Date().getFullYear();
  129. $scope.jry_month = new Date().getMonth() + 1;
  130. $scope.jry_data = new Date().getDate();
  131. $scope.jry_hours = new Date().getHours();
  132. $scope.jry_minute = new Date().getMinutes();
  133. $scope.jry_second = new Date().getSeconds();
  134. // console.log($scope.jry_month)
  135. }, 1000)
  136. // $win.on('beforeunload', function() { return $state.go("login.signin"); });
  137. // $auth.deleteData('auth_headers')
  138. // }
  139. // 监听路由
  140. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  141. var loginUser = $rootScope.user;
  142. if(loginUser){
  143. $scope.allFlag = false;//全部事件
  144. for (var i = 0; i < loginUser.menu.length; i++) {
  145. if (loginUser.menu[i].link == "shijianliebiao_all") {
  146. $scope.allFlag = true
  147. }
  148. }
  149. }
  150. console.log(event, toState, toParams, fromState, fromParams)
  151. // 请求首页统计
  152. if(toState.name != 'login.signin'){
  153. $rootScope.getOrderCount();
  154. // 判断首页统计页面是否显示
  155. // if($rootScope.user.role.length){
  156. // $scope.isShowTj = $rootScope.user.role.some(function(v){
  157. // return v.rolecode === "incident-category-manager" || v.rolecode === "incident manager";
  158. // })
  159. // }else{
  160. // $scope.isShowTj = false;
  161. // }
  162. }
  163. if($rootScope.isZncd || $rootScope.isXy){
  164. // 中南财大
  165. if ((toState.name == 'app.incident.chart' || toState.name == 'app.incident.editor') &&
  166. fromState.name) {
  167. console.log($rootScope.jry_state);
  168. $scope.isShixian = false;
  169. if($rootScope.jry_state == 'shixian'){
  170. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  171. //进入页面强制示忙
  172. if (tlwsa) {
  173. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  174. setTimeout(()=>{
  175. tlwsa.tlaAcw();
  176. },0)
  177. }
  178. }
  179. }
  180. if ((fromState.name == 'app.incident.chart' || fromState.name == 'app.incident.editor') &&
  181. toState.name != 'app.incident.chart' && toState.name != 'app.incident.editor'
  182. ) {
  183. console.log($rootScope.jry_state);
  184. // $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  185. //进入页面强制示闲
  186. $scope.isShixian = true;
  187. // if (tlwsa) {
  188. // // tlwsa.tlaForcewca($rootScope.phoneNumber);
  189. // tlwsa.tlaWca();
  190. // }
  191. }
  192. }else if($rootScope.isHk){
  193. if (toState.name != "app.incident.editor" && toState.name != "echart") {
  194. if ($rootScope.status == 2 || $rootScope.status == 4 || $rootScope.status == 9) {
  195. $rootScope.setidle();
  196. }
  197. }
  198. if (toState.name != "app.incident.editor" && toState.name != "app.incident.title") {
  199. if ($scope.login && $rootScope.statecall == 2 && !$rootScope.busy) {
  200. $rootScope.setidle();
  201. }
  202. } else {
  203. if ($scope.login && !$rootScope.busy) {
  204. $rootScope.setbusy();
  205. }
  206. // $rootScope.isMask = true;
  207. }
  208. }
  209. if (isEmpty($auth.retrieveData('auth_headers'))) {
  210. // if (toState.name != "login.signin" && toState.name != "echart") {
  211. // event.preventDefault();
  212. // $rootScope.app.isLoginFixed = true;
  213. // // $scope.lodingstyle = 'nodata';
  214. // return $state.go("login.signin");
  215. // }
  216. }
  217. // if (toState.name == "app.system.user.user") {
  218. // var isgoto = false;
  219. // if ($rootScope.user && $rootScope.user.menu) {
  220. // angular.forEach($rootScope.user.menu, function(item) {
  221. // if (item.link == toState.name) {
  222. // isgoto = true;
  223. // } else {}
  224. // })
  225. // }
  226. // if (isgoto) {
  227. // } else {
  228. // $state.go("app.dashboard");
  229. // }
  230. // }
  231. // if (toState.name != "app.incident.editor" && toState.name != "echart") {
  232. // if ($rootScope.status == 2 || $rootScope.status == 4 || $rootScope.status == 9) {
  233. // $rootScope.setidle();
  234. // }
  235. // }
  236. cfpLoadingBar.start();
  237. $auth.validateUser();
  238. });
  239. $rootScope.imUsrMap = {};
  240. $rootScope.onlineUser = [];
  241. $rootScope.offlineUser = [];
  242. $rootScope.me = undefined;
  243. $rootScope.imscope = {
  244. sessions: []
  245. }
  246. // var ws = new WebSocket('ws://192.168.3.51:8088/events');
  247. // var register= {"msgtype":"login","adn":"1001"};
  248. // ws.onopen = function() { ws.send(JSON.stringify(register));}
  249. // ws.onmessage = function(evt) { console.log(evt.data) }
  250. var ddp = new DDP('ws://115.156.150.70:3000/websocket');
  251. $rootScope.getDirectMsgRoomId = function (mdId, toId) {
  252. //me.id,to.id
  253. var rid = [mdId, toId].sort().join('');
  254. return rid;
  255. };
  256. $rootScope.sendMessage = function (rid, msg, callback, error) {
  257. ddp.call('sendMessage', [{ 'rid': rid, 'msg': msg }]).then(callback, error);
  258. };
  259. var pushNotification = function (notification) {
  260. deskNotification.showNotification(notification.title, {
  261. body: notification.body,
  262. icon: notification.icon || '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  263. onClick: notification.callback || function onNotificationClicked() {
  264. // console.log('Notification clicked.');
  265. },
  266. autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
  267. }, function onShow(error, hide) {
  268. if (error) {
  269. window.alert('Unable to show notification: ' + error.message);
  270. } else {
  271. // console.log('Notification Shown.');
  272. setTimeout(function hideNotification() {
  273. // console.log('Hiding notification....');
  274. hide(); //manually close the notification (you can skip this if you use the autoClose option)
  275. }, 5000);
  276. }
  277. });
  278. }
  279. // $rootScope.subscribeRoomMessage = function(rid){
  280. // ddp.subscribe('stream-room-messages',[rid, true]).then(function(){},function(reason){
  281. // console.log('subscribe stream-room-messages:%o', reason);
  282. // });
  283. // }
  284. $rootScope.filternotifyuser = [];
  285. $rootScope.$on('openroom', function (event, data, otheruser) {
  286. ddp.call('createDirectMessage', [otheruser]).then(function () { }, function (reason) {
  287. // console.log('createDirectMessage', reason);
  288. });
  289. ddp.subscribe('stream-room-messages', [data.rid, true]).then(function () { }, function (reason) {
  290. // console.log('subscribe stream-room-messages:%o', reason);
  291. });
  292. if ($rootScope.imUsrMap[data.from]['unread'].msgs) {
  293. $rootScope.imUsrMap[data.from]['unread'].msgs.clear;
  294. }
  295. $rootScope.filternotifyuser.push(data.from);
  296. });
  297. $rootScope.$on("clip-two.toggled", function (e, target, newState, sameGroup) {
  298. console.log(newState)
  299. if (newState == false && target == 'off-sidebar') {
  300. $rootScope.$broadcast('chatcloseroom');
  301. $rootScope.judgeHjzx();
  302. //$rootScope.toggle("users");
  303. //$rootScope.filternotifyuser = [];
  304. //ddp.unsubscribe('stream-room-messages');
  305. }
  306. });
  307. $rootScope.$on("closeroom", function (event, data) {
  308. $rootScope.filternotifyuser = [];
  309. ddp.unsubscribe('stream-room-messages');
  310. });
  311. var initImUser = function (email, token) {
  312. var ddpconnect = ddp.connect();
  313. ddpconnect.then(function (data) {
  314. //console.log(data);
  315. if (data.session) {
  316. // ddp.call('createDirectMessage', [data.from, data.rid]).then(function() {}, function(reason) {
  317. // console.log('subscribe createDirectMessage');
  318. // });
  319. ddp.call('login', [{ user: { email: email }, password: token }]).then(function (data) {
  320. // console.log('login data: %o', data);
  321. if (data.id) {
  322. $rootScope.me = {
  323. id: data.id,
  324. token: data.token,
  325. expiry: data.tokenExpires
  326. };
  327. //获取在线用户
  328. ddp.subscribe('activeUsers');
  329. ddp.subscribe('stream-notify-user', [$rootScope.me.id + '/notification', true]).then(function (result) {
  330. //console.log(result);
  331. }, function (reason) {
  332. // console.log('stream-notify-user error:%s', reason);
  333. });
  334. // ddp.subscribe('stream-notify-user',[$rootScope.me.id+'/message',false]).then(function(result){
  335. // console.log(result);
  336. // },function(reason){
  337. // console.log('stream-notify-user error:', reason);
  338. // });
  339. ddp.subscribe('messages', [$rootScope.me.id + '/message', true]).then(function () { }, function (reason) {
  340. // console.log('subscribe messages error:%s', reason);
  341. });
  342. //'stream-notify-user',$rootScope.me.id+'/message'
  343. // ddp.call('sendmessage', []).then(function(msg){
  344. // })
  345. //console.log('Logged in!');
  346. // ddp.subscribe('messages', [{rid:data.id,start:new Date()}]).then(function(submsg){
  347. // console.log('subscribe messages-%s', submsg);
  348. // $rootScope.rocketchat_message = ddp.getCollection('rocketchat_message');
  349. // },function(reason){
  350. // console.log(reason);
  351. // })
  352. }
  353. }, function (reason) {
  354. // console.log(reason);
  355. });
  356. } else {
  357. }
  358. ddp.watch('users', function (changedDoc, message) {
  359. //console.log('users:%o',changedDoc);
  360. // if (message == 'method') {
  361. // console.log("1111111111111111111")
  362. // }
  363. if (message == 'added') {
  364. if (changedDoc.status && ($rootScope.me.id != changedDoc._id)) {
  365. if (changedDoc.status == 'away') {
  366. $rootScope.offlineUser.push(changedDoc);
  367. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  368. } else {
  369. $rootScope.onlineUser.push(changedDoc);
  370. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  371. }
  372. } else {
  373. //self
  374. }
  375. } else if (message == 'changed') {
  376. if ($rootScope.me.id != changedDoc._id) {
  377. if (!$rootScope.imUsrMap[changedDoc._id]) {
  378. if (changedDoc.status == 'away') {
  379. $rootScope.offlineUser.push(changedDoc);
  380. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  381. } else {
  382. $rootScope.onlineUser.push(changedDoc);
  383. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  384. }
  385. }
  386. if (changedDoc.status == 'away') {
  387. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  388. } else {
  389. $rootScope.offlineUser.push(changedDoc);
  390. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  391. window._.map(window._.slice($rootScope.onlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  392. $rootScope.imUsrMap[item._id].index = n;
  393. })
  394. // $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){
  395. // item.index = item.index - 1;
  396. // }))
  397. //.splice($rootScope.imUsrMap[changedDoc.id].index,1);
  398. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.offlineUser.length };
  399. }
  400. } else {
  401. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  402. $rootScope.onlineUser.push(changedDoc);
  403. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  404. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  405. $rootScope.imUsrMap[item._id].index = n;
  406. })
  407. // $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){
  408. // item.index = item.index - 1;
  409. // }))
  410. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length };
  411. } else {
  412. }
  413. }
  414. }
  415. } else if (message == 'removed') {
  416. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  417. } else {
  418. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  419. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  420. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  421. $rootScope.imUsrMap[item._id].index = n;
  422. });
  423. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length, unread: { total: 0, msgs: [] } };
  424. }
  425. }
  426. });
  427. ddp.watch('stream-notify-user', function (changedDoc, message) {
  428. if (message == 'changed') {
  429. if (changedDoc.eventName) {
  430. if (changedDoc.eventName.indexOf('/') > -1) {
  431. // var [mineId, action] = changedDoc.eventName.split('/');
  432. var mineId = changedDoc.eventName.split('/');
  433. var action = mineId;
  434. if (action == 'notification') {
  435. angular.forEach(changedDoc.args, function (item) {
  436. if ($rootScope.filternotifyuser.indexOf(item.payload.sender._id) > -1) {
  437. } else {
  438. // console.log("push notify message:%o", item);
  439. var r = angular.extend(item, { 'date': new Date() })
  440. $rootScope.imUsrMap[item.payload.sender._id]['unread'].msgs.push(r);
  441. $rootScope.imUsrMap[item.payload.sender._id]['unread'].total++;
  442. pushNotification({
  443. title: "您有新消息-来自" + item.payload.sender.username,
  444. body: r.text,
  445. callback: function () {
  446. window.focus();
  447. $rootScope.toggle('off-sidebar');
  448. }
  449. })
  450. //toaster.pop('info', "您有新消息-来自"+item.payload.sender.username, r.text);
  451. }
  452. })
  453. }
  454. }
  455. }
  456. } else {
  457. }
  458. //console.log('notify message %o, %o', changedDoc, message);
  459. });
  460. ddp.watch('stream-room-messages', function (changedDoc, message) {
  461. if (message == 'changed') {
  462. //angular.forEach(changedDoc.args,function(item){
  463. $rootScope.$broadcast(changedDoc.eventName + '-msgs', changedDoc.args);
  464. //};
  465. // if(changedDoc.eventName){
  466. // $rootScope.imUsrMap[eventName]=$rootScope.imUsrMap[eventName]||{};
  467. // $rootScope.imUsrMap[eventName]['msgs']=$rootScope.imUsrMap[eventName]['msgs']||[];
  468. // angular.forEach(changedDoc.args,function(item){
  469. // $rootScope.imUsrMap[eventName].msgs.push(item);
  470. // })
  471. // }
  472. } else {
  473. }
  474. // console.log('notify message %o, %o', changedDoc, message);
  475. });
  476. ddp.watch('rocketchat_message', function (changedDoc, message) {
  477. // console.log('recieve rocketchat_message: %o-%o', changedDoc, message);
  478. });
  479. });
  480. }
  481. window.onunload = function () {
  482. }
  483. $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
  484. //$auth.validateUser();
  485. //stop loading bar on stateChangeSuccess
  486. event.targetScope.$watch("$viewContentLoaded", function () {
  487. cfpLoadingBar.complete();
  488. });
  489. // scroll top the page on change state
  490. $document.scrollTo(0, 0);
  491. if (angular.element('.email-reader').length) {
  492. angular.element('.email-reader').animate({
  493. scrollTop: 0
  494. }, 0);
  495. }
  496. // Save the route title
  497. $rootScope.currTitle = $state.current.title;
  498. if (angular.isDefined($state.current.pdKey)) {
  499. $rootScope.pdKey = $state.current.pdKey;
  500. }
  501. // console.log($state.current.title);
  502. });
  503. // State not found
  504. $rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) {
  505. //$rootScope.loading = false;
  506. if (angular.isUndefined($rootScope.user.id)) {
  507. $rootScope.loading = false;
  508. }
  509. // console.log(unfoundState.to);
  510. // "lazy.state"
  511. // console.log(unfoundState.toParams);
  512. // {a:1, b:2}
  513. // console.log(unfoundState.options);
  514. // {inherit:false} + default options
  515. });
  516. $rootScope.isMousedown = false;
  517. $rootScope.changeRemoveClass = function (e) {
  518. $rootScope.isMousedown = true
  519. }
  520. $rootScope.returnRemoveClass = function (e) {
  521. $rootScope.isMousedown = false;
  522. }
  523. $rootScope.$on('auth:login-success', function (ev, data) {
  524. // $state.go('login.signin');
  525. initImUser(data.email, data.msgUuid);
  526. getMenus();
  527. //console.log(data);
  528. //$rootScope.user = data.user;
  529. //$rootScope.menus = data.menu;
  530. });
  531. //$rootScope.$watch('$auth.user')
  532. // $rootScope.$on('auth:validation-success', function(ev, user) {
  533. // // console.log(user);
  534. // initImUser(user.email, user.msgUuid);
  535. // if ($rootScope.userMenus.length == 0) {
  536. // getMenus();
  537. // }
  538. // //alert('Welcome ', user.email);
  539. // });
  540. // $rootScope.$on('auth:invalid', function(ev) {
  541. // $state.go('login.signin');
  542. // });
  543. // $rootScope.$on('auth:validation-error', function(ev) {
  544. // $state.go('login.signin');
  545. // //alert('Welcome ', user.email);
  546. // });
  547. // $rootScope.$on('auth:session-expired', function(ev) {
  548. // //alert('Welcome ', user.email);
  549. // $state.go('login.signin');
  550. // });
  551. // $rootScope.$on('auth:logout-success', function(ev) {
  552. // //alert('goodbye');
  553. // //delete $rootScope.user;
  554. // //delete $rootScope.menus;
  555. // $state.go('login.signin');
  556. // });
  557. // $rootScope.$on('auth:logout-error', function(ev) {
  558. // $state.go('login.signin');
  559. // });
  560. $rootScope.pageTitle = function () {
  561. // if($rootScope.currTitle){
  562. // return $rootScope.app.name + ' - ' + $filter('translate')($rootScope.currTitle) || $rootScope.app.description;
  563. // }else{
  564. // return $rootScope.app.name + ' - ' + $rootScope.app.description
  565. // }
  566. var perfix = "sidebar.nav.";
  567. var toTransKeypageTitle = perfix + $rootScope.currTitle;
  568. // return $rootScope.app.name + ' - ' + ($filter('translate')(toTransKeypageTitle) || $rootScope.app.description);
  569. return $rootScope.app.name;
  570. };
  571. // $auth.validateUser();
  572. // $auth.authenticate('local').then(function(resp){
  573. // }).catch(function(resp){
  574. // })
  575. // if(angular.isDefined($rootScope.nickname)){
  576. // api_login.sso($rootScope.nickname).then(function(response){
  577. // var user = Restangular.stripRestangular(response);
  578. // if (user) {
  579. // if(angular.isUndefined(user.id)){
  580. // }else{
  581. // $rootScope.user = user;
  582. // }
  583. // }
  584. // });
  585. // }else{
  586. // var user= $cookieStore.get("userObm");
  587. // if(user){
  588. // $rootScope.user = user;
  589. // $rootScope.menus = $cookieStore.get("menuObm");
  590. // }else{
  591. // if(angular.isDefined($rootScope.nickname)){
  592. // api_login.sso($rootScope.nickname).then(function(response){
  593. // var data = Restangular.stripRestangular(response);
  594. // if (data) {
  595. // if(data.user){
  596. // if(angular.isUndefined(data.user.id)){
  597. // }else{
  598. // $rootScope.user = data.user;
  599. // $rootScope.menus = data.menu;
  600. // $cookieStore.put("userObm", $rootScope.user);
  601. // $cookieStore.put("menuObm", $rootScope.menus);
  602. // $cookieStore.put("session", data.sessionId);
  603. // }
  604. // }
  605. // }
  606. // });
  607. // }else{
  608. // }
  609. // }
  610. //}
  611. //选择坐席号
  612. $scope.changeWorkId = function () {
  613. event.stopPropagation();
  614. }
  615. $rootScope.getSession = function () {
  616. if ($auth.userIsAuthenticated()) {
  617. return $auth.retrieveData('auth_headers')
  618. /*return {
  619. 'access-token':$auth.retrieveData('auth_headers')['access-token'],
  620. 'expiry':$auth.retrieveData('auth_headers')['expiry']
  621. };*/
  622. } else {
  623. return undefined;
  624. }
  625. }
  626. $scope.includes = [];
  627. $rootScope.includesState = function (state) {
  628. //for test
  629. //return true;
  630. //return includes;
  631. if ($rootScope.user) {
  632. if ($rootScope.user.menu) {
  633. angular.forEach($rootScope.user.menu, function (item) {
  634. $scope.includes[item.link] = true;
  635. });
  636. }
  637. }
  638. return $scope.includes[state];
  639. }
  640. //大屏入口
  641. $rootScope.opendashbord = function () {
  642. $state.go('echart');
  643. }
  644. // $rootScope.authority=false;
  645. // console.log($rootScope.user)
  646. // if($rootScope.user.role){
  647. // for(var i ;i<$rootScope.user.role.length;i++){
  648. // if($rootScope.user.role[i].rolecode=='call center') {
  649. // $rootScope.authority=true;
  650. // }else{$rootScope.authority=false;}
  651. // }
  652. // }
  653. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  654. // if (window.location.href && window.location.href.hash == "#/echart") {
  655. // } else {
  656. // // }
  657. // // 东经呼叫中心开始
  658. // $rootScope.statuscall = 0; //话机状态
  659. // $rootScope.statecall = 1; //示忙示闲
  660. // $scope.login = false; //签入签出
  661. // $rootScope.callout = false; //呼入呼出
  662. // $scope.group = 2000;
  663. // $scope.phone = 1500;
  664. // $rootScope.start = function(phone, group) {
  665. // api_text.start(phone, $rootScope.user.id).then(function(data) {
  666. // var token = data.token;
  667. // $rootScope.takes = token;
  668. // api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  669. // api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  670. // if (data.errno == 0) {
  671. // $rootScope.setidle();
  672. // $scope.login = true;
  673. // $rootScope.statuscall = 1;
  674. // $rootScope.callout = false;
  675. // // function hello() {
  676. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  677. // // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  678. // // };
  679. // // window.setTimeout("hello()", 1000);
  680. // // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  681. // function reconnect() {
  682. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  683. // var ws = new WebSocket('ws://115.156.150.70:28088/events');
  684. // var register = { "msgtype": "login", "adn": phone };
  685. // ws.onopen = function() {
  686. // heartCheck.start();
  687. // ws.send(JSON.stringify(register));
  688. // };
  689. // ws.onmessage = function(evt) {
  690. // heartCheck.reset();
  691. // if (evt.data == "HeartBeat") {
  692. // } else {
  693. // var mydata = JSON.parse(evt.data);
  694. // $scope.filterData = [];
  695. // if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  696. // $rootScope.$apply(function() {
  697. // $rootScope.statuscall = 2;
  698. // });
  699. // $rootScope.callout = false;
  700. // $rootScope.phone = mydata.ano;
  701. // var Notification = window.Notification;
  702. // Notification.requestPermission();
  703. // var n = new Notification("你有来电", {
  704. // body: "来电号码:" + mydata.ano,
  705. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  706. // // onclick: function onNotificationClicked() {
  707. // // console.log('Notification clicked.');
  708. // // }
  709. // });
  710. // } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  711. // $rootScope.callout = true;
  712. // } else if (mydata.evttype == "ringstop") {
  713. // // $rootScope.status=7;
  714. // // $rootScope.$apply(function() {
  715. // $rootScope.statuscall = 1;
  716. // // });
  717. // $rootScope.phone = ""
  718. // } else if (mydata.evttype == 'hookchanged' && $rootScope.callout) {
  719. // if (mydata.status && mydata.status == '1') {
  720. // $rootScope.$apply(function() {
  721. // $rootScope.statuscall = 1;
  722. // });
  723. // $rootScope.phone = "";
  724. // } else if (mydata.status && mydata.status != '1') {
  725. // $rootScope.$apply(function() {
  726. // $rootScope.statuscall = 3;
  727. // });
  728. // }
  729. // } else if (mydata.evttype == 'hookchanged' && !$rootScope.callout) {
  730. // if ($rootScope.phone != "") {
  731. // if (mydata.status && mydata.status == '1') { //挂机
  732. // $rootScope.$apply(function() {
  733. // $rootScope.statuscall = 1;
  734. // });
  735. // console.log("挂机");
  736. // console.log(mydata);
  737. // } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2) { //摘机
  738. // $rootScope.statuscall = 3;
  739. // api_text.setbusy($rootScope.takes).then(function(data) {
  740. // if (data.errno == 0) {
  741. // $rootScope.statecall = 2;
  742. // $scope.busy = true;
  743. // }
  744. // })
  745. // console.log("摘机");
  746. // console.log(mydata);
  747. // api_text.getcdrid($rootScope.takes).then(function(response) {
  748. // if (response.cdrid) {
  749. // var cdrid = response.cdrid;
  750. // // var response={cdrid:'219023836'}
  751. // var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  752. // api_user_data.fetchDataList('requester', filterData).then(function(data) {
  753. // var myData = Restangular.stripRestangular(data);
  754. // // $rootScope.phone="";
  755. // if (myData.list.length == 0) {
  756. // var modalInstance = $modal.open({
  757. // templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  758. // controller: function($scope, $modalInstance, api_user_data) {
  759. // $scope.title = "新增报修人";
  760. // $scope.requester = {};
  761. // $scope.onChangeadd = function(searchData) {
  762. // $scope.searchKey = searchData.account;
  763. // // $scope.searchDataadd = searchData;
  764. // var requesdata = angular.copy(searchData)
  765. // // if (requesdata.mphone) {
  766. // // delete requesdata.mphone;
  767. // // }
  768. // if (requesdata.telephone) {
  769. // delete requesdata.telephone;
  770. // }
  771. // angular.extend($scope.requester, requesdata);
  772. // }
  773. // $scope.refreshUseradd = function(searchKey) { //请求人搜索
  774. // $scope.requester.account = searchKey;
  775. // $scope.searchData = searchKey;
  776. // serchdataadd(searchKey);
  777. // }
  778. // $scope.getMydata = function(x) {
  779. // var reqestdatap = JSON.parse(x[0])
  780. // // if ($scope.requester.mphone) {
  781. // // delete reqestdatap.mphone;
  782. // // }
  783. // if ($scope.requester.telephone) {
  784. // delete reqestdatap.telephone;
  785. // }
  786. // $scope.searchField = JSON.parse(x[0]).account;
  787. // angular.extend($scope.requester, reqestdatap);
  788. // }
  789. // $scope.getMydataone = function(x) {
  790. // $scope.searchField = x;
  791. // $scope.requester.account = x;
  792. // }
  793. // serchdataadd();
  794. // function serchdataadd(searchKey) {
  795. // if (searchKey) {
  796. // var filterData = {
  797. // 'requester': {
  798. // 'searchKey': searchKey,
  799. // },
  800. // idx: 0,
  801. // sum: 10
  802. // };
  803. // } else {
  804. // var filterData = {
  805. // idx: 0,
  806. // sum: 10
  807. // };
  808. // }
  809. // // serchdataadd(searchKey)
  810. // // if ($scope.model.requester && $scope.model.requester.requesterTypeDTO) {
  811. // // angular.extend(filterData.requester, { 'requesterTypeDTO': $scope.model.requester.requesterTypeDTO })
  812. // // }
  813. // api_user_data.fetchDataList('requester', filterData).then(function(response) {
  814. // var myData = response;
  815. // $scope.myData = myData.list;
  816. // });
  817. // }
  818. // // if ((/^1[34578]\d{9}$/.test($rootScope.phone))) {
  819. // // $scope.requester = { 'mphone': $rootScope.phone };
  820. // // } else {
  821. // // $scope.requester = { 'telephone': $rootScope.phone };
  822. // // }
  823. // $scope.requester = { 'telephone': $rootScope.phone };
  824. // $scope.ok = function() {
  825. // $modalInstance.close($scope.requester);
  826. // };
  827. // $scope.cancel = function() {
  828. // $modalInstance.dismiss('cancel');
  829. // };
  830. // },
  831. // });
  832. // modalInstance.result.then(function(selectedItem) {
  833. // if (selectedItem) {
  834. // if (selectedItem.telephone && !selectedItem.mphone) {
  835. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  836. // delete selectedItem.mphone;
  837. // }
  838. // var data = {
  839. // 'requester': selectedItem
  840. // };
  841. // api_user_data.addData('requester', data).then(function(response) {
  842. // if (response.status == 200) {
  843. // var data = { 'model': { 'requestershow': response.data, 'incident': { 'requester': response.data, 'area': response.areaDTO, 'place': response.placeDTO, 'houseNumber': response.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  844. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  845. // }
  846. // })
  847. // }
  848. // });
  849. // } else if (myData.list.length == 1) {
  850. // 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 } } } }
  851. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  852. // } else {
  853. // var modalInstance = $modal.open({
  854. // templateUrl: 'assets/views/createincident.html',
  855. // controller: function($scope, $modalInstance, api_user_data) {
  856. // $scope.title = "请确定报修人";
  857. // $scope.requester = myData.list;
  858. // $scope.choice = function(requester) {
  859. // $modalInstance.dismiss('cancel');
  860. // var data = { 'model': { 'requestershow': requester, 'incident': { 'requester': requester, 'area': requester.areaDTO, 'place': requester.placeDTO, 'houseNumber': requester.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  861. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  862. // };
  863. // $scope.cancel = function() {
  864. // $modalInstance.dismiss('cancel');
  865. // };
  866. // },
  867. // size: "lg"
  868. // });
  869. // }
  870. // });
  871. // }
  872. // })
  873. // }
  874. // }
  875. // }
  876. // }
  877. // };
  878. // var heartCheck = {
  879. // timeout: 12000, //60ms
  880. // timeoutObj: null,
  881. // serverTimeoutObj: null,
  882. // reset: function() {
  883. // clearTimeout(this.timeoutObj);
  884. // clearTimeout(this.serverTimeoutObj);
  885. // this.start();
  886. // },
  887. // start: function() {
  888. // var self = this;
  889. // this.timeoutObj = setTimeout(function() {
  890. // ws.send("HeartBeat");
  891. // self.serverTimeoutObj = setTimeout(function() {
  892. // ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  893. // }, self.timeout)
  894. // }, this.timeout)
  895. // },
  896. // }
  897. // ws.onclose = function(evt) { reconnect(); }
  898. // ws.onerror = function(evt) { reconnect(); };
  899. // }
  900. // reconnect();
  901. // } else {
  902. // var Notification = window.Notification;
  903. // Notification.requestPermission();
  904. // var n = new Notification("签入失败!", {
  905. // body: data.errmsg,
  906. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  907. // // onclick: function onNotificationClicked() {
  908. // // console.log('Notification clicked.');
  909. // // }
  910. // });
  911. // }
  912. // })
  913. // })
  914. // }
  915. // // 东经呼叫中心结束
  916. // 华科呼叫中心 start
  917. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  918. $rootScope.statuscall = 0; //话机状态
  919. $rootScope.statecall = 1; //示忙示闲
  920. $scope.login = false; //签入签出
  921. $rootScope.callout = 0; //呼入:1,呼出:2
  922. $scope.group = 2000;
  923. $scope.phone = 1500;
  924. $rootScope.phoneChange = function(phone) {
  925. if (phone == 1500||phone == 1501||phone == 1502) {
  926. $scope.group = 2000;
  927. } else if(phone == 1511) {
  928. $scope.group = 2001;
  929. }else if(phone == 1507) {
  930. $scope.group = 2002;
  931. }
  932. }
  933. $rootScope.start = function(phone) {
  934. if (phone == 1500||phone == 1501||phone == 1502) {
  935. $scope.group = 2000;
  936. } else if(phone == 1511) {
  937. $scope.group = 2001;
  938. }else if(phone == 1507) {
  939. $scope.group = 2002;
  940. }
  941. api_text.start(phone, $rootScope.user.id).then(function(data) {
  942. var token = data.token;
  943. $rootScope.takes = token;
  944. api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  945. api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  946. if (data.errno == 0) {
  947. localStorage.setItem('hk_phone',phone);
  948. $rootScope.setidle();
  949. $scope.login = true;
  950. $rootScope.statuscall = 1;
  951. $rootScope.callout = 0;
  952. // function hello() {
  953. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  954. // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  955. // };
  956. // window.setTimeout("hello()", 1000);
  957. // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  958. function reconnect() {
  959. // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  960. var ws = new WebSocket('ws://192.168.77.57:8088/IXServer/messagestation/hjzx');
  961. var register = { "msgtype": "login", "adn": phone };
  962. ws.onopen = function() {
  963. heartCheck.start();
  964. ws.send(JSON.stringify(register));
  965. };
  966. ws.onmessage = function(evt) {
  967. heartCheck.reset();
  968. if (evt.data == "HeartBeat") {
  969. } else {
  970. var mydata = JSON.parse(evt.data);
  971. $scope.filterData = [];
  972. if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  973. $rootScope.$apply(function() {
  974. $rootScope.statuscall = 2;
  975. $rootScope.callout = 1;
  976. });
  977. $rootScope.phone = mydata.ano;
  978. var Notification = window.Notification;
  979. Notification.requestPermission();
  980. var n = new Notification("你有来电", {
  981. body: "来电号码:" + mydata.ano,
  982. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  983. // onclick: function onNotificationClicked() {
  984. // console.log('Notification clicked.');
  985. // }
  986. });
  987. } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  988. $rootScope.callout = 2;
  989. } else if (mydata.evttype == "ringstop") {
  990. // $rootScope.status=7;
  991. // $rootScope.$apply(function() {
  992. $rootScope.statuscall = 1;
  993. // });
  994. $rootScope.phone = ""
  995. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout == 2) {
  996. if (mydata.status && mydata.status == '1') {
  997. $rootScope.$apply(function() {
  998. $rootScope.statuscall = 1;
  999. });
  1000. $rootScope.phone = "";
  1001. } else if (mydata.status && mydata.status != '1') {
  1002. $rootScope.$apply(function() {
  1003. $rootScope.statuscall = 3;
  1004. });
  1005. }
  1006. } else if (mydata.evttype == 'hookchanged' && $rootScope.callout == 1) {
  1007. if ($rootScope.phone != "") {
  1008. if (mydata.status && mydata.status == '1') { //挂机
  1009. $rootScope.$apply(function() {
  1010. $rootScope.statuscall = 1;
  1011. $rootScope.callout = 0;
  1012. });
  1013. // console.log("挂机");
  1014. if ($rootScope.statecall == 1 && !$rootScope.isSetidle) {
  1015. $rootScope.setbusy();
  1016. }
  1017. } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2 && $rootScope.callout == 1) { //摘机
  1018. $rootScope.status = 6
  1019. $rootScope.statuscall = 3;
  1020. $rootScope.isSetidle = false;
  1021. $rootScope.app.layout.isSidebarClosed = true;
  1022. // console.log("摘机");
  1023. // console.log(mydata);
  1024. api_text.getcdrid($rootScope.takes).then(function(response) {
  1025. if (response.cdrid) {
  1026. var cdrid = response.cdrid;
  1027. // var response={cdrid:'219023836'}
  1028. var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  1029. api_user_data.fetchDataList('requester', filterData).then(function(data) {
  1030. var myData = Restangular.stripRestangular(data);
  1031. // $rootScope.phone="";
  1032. if (myData.list.length == 0) {
  1033. var modalInstance = $modal.open({
  1034. backdrop: "static",
  1035. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  1036. controller: function($scope, $modalInstance, api_user_data, SweetAlert) {
  1037. $scope.title = "新增报修人";
  1038. $scope.requester = {};
  1039. $scope.onChangeadd = function(searchData) {
  1040. $scope.searchKey = searchData.account;
  1041. // $scope.searchDataadd = searchData;
  1042. var requesdata = angular.copy(searchData)
  1043. // if (requesdata.mphone) {
  1044. // delete requesdata.mphone;
  1045. // }
  1046. if (requesdata.telephone) {
  1047. delete requesdata.telephone;
  1048. }
  1049. angular.extend($scope.requester, requesdata);
  1050. }
  1051. $scope.refreshUseradd = function(searchKey) { //请求人搜索
  1052. $scope.requester.account = searchKey;
  1053. $scope.searchData = searchKey;
  1054. serchdataadd(searchKey);
  1055. }
  1056. $scope.getMydata = function(x) {
  1057. var reqestdatap = JSON.parse(x[0])
  1058. // if ($scope.requester.mphone) {
  1059. // delete reqestdatap.mphone;
  1060. // }
  1061. if ($scope.requester.telephone) {
  1062. delete reqestdatap.telephone;
  1063. }
  1064. $scope.searchField = JSON.parse(x[0]).account;
  1065. angular.extend($scope.requester, reqestdatap);
  1066. if ($scope.requester.areaDTO && $scope.requester.areaDTO.id && $scope.requester.areaDTO.id != "") {
  1067. api_user_data.fetchDataList('place', { place: { areaId: $scope.requester.areaDTO.id }, idx: 0, sum: 1000 }).then(function(response) {
  1068. if (response.status == 200) {
  1069. $scope.places = response.list;
  1070. }
  1071. })
  1072. }
  1073. }
  1074. $scope.getMydataone = function(x) {
  1075. $scope.searchField = x;
  1076. $scope.requester.account = x;
  1077. }
  1078. serchdataadd();
  1079. function serchdataadd(searchKey) {
  1080. if (searchKey) {
  1081. var filterData = {
  1082. 'requester': {
  1083. 'searchKey': searchKey,
  1084. },
  1085. idx: 0,
  1086. sum: 10
  1087. };
  1088. } else {
  1089. var filterData = {
  1090. idx: 0,
  1091. sum: 10
  1092. };
  1093. }
  1094. api_user_data.fetchDataList('requester', filterData).then(function(response) {
  1095. var myData = response;
  1096. $scope.myData = myData.list;
  1097. });
  1098. }
  1099. api_user_data.fetchDataList('area', { idx: 0, sum: 100 }).then(function(response) {
  1100. if (response.status == 200) {
  1101. $scope.areas = response.list;
  1102. }
  1103. })
  1104. // api_user_data.fetchDataList('place', { idx: 0, sum: 1000 }).then(function(response) {
  1105. // if (response.status == 200) {
  1106. // $scope.places = response.list;
  1107. // }
  1108. // }) //地点
  1109. api_user_data.fetchDataList('requesterType', { idx: 0, sum: 100 }).then(function(response) {
  1110. if (response.status == 200) {
  1111. $scope.networktypes = response.list;
  1112. }
  1113. })
  1114. $scope.requesterAreaid = "";
  1115. $scope.onChange = function(item) {
  1116. $scope.requesterAreaid = item.id;
  1117. $scope.requester.place = {};
  1118. api_user_data.fetchDataList('place', { place: { areaId: item.id }, idx: 0, sum: 1000 }).then(function(response) {
  1119. if (response.status == 200) {
  1120. $scope.places = response.list;
  1121. }
  1122. })
  1123. }
  1124. //地点搜索
  1125. $scope.refresh = function(searchVal) {
  1126. var faildata = {};
  1127. if ($scope.requesterAreaid) {
  1128. faildata = {
  1129. 'idx': 0,
  1130. 'sum': 1000,
  1131. 'place': { 'areaId': $scope.requesterAreaid, 'place': searchVal, 'selectType': 'pinyin_qs' }
  1132. }
  1133. } else {
  1134. faildata = {
  1135. 'idx': 0,
  1136. 'sum': 1000,
  1137. 'place': { 'place': searchVal, 'selectType': 'pinyin_qs' }
  1138. }
  1139. }
  1140. api_user_data.fetchDataList('place', faildata).then(function(response) {
  1141. $scope.places = response.list;
  1142. delete $scope.requester.place;
  1143. })
  1144. }
  1145. $scope.requester = { 'telephone': $rootScope.phone };
  1146. $scope.ok = function() {
  1147. // $modalInstance.close($scope.requester);
  1148. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1149. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1150. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1151. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1152. } else {
  1153. $modalInstance.close($scope.requester);
  1154. }
  1155. };
  1156. $scope.cancel = function() {
  1157. $modalInstance.dismiss('cancel');
  1158. $rootScope.setidle();
  1159. };
  1160. },
  1161. });
  1162. modalInstance.result.then(function(selectedItem) {
  1163. if (selectedItem) {
  1164. if (selectedItem.telephone && !selectedItem.mphone) {
  1165. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1166. delete selectedItem.mphone;
  1167. }
  1168. var data = {
  1169. 'requester': selectedItem
  1170. };
  1171. api_user_data.addData('requester', data).then(function(response) {
  1172. if (response.status == 200) {
  1173. var data = {
  1174. model: {
  1175. requestershow: response.data,
  1176. incident: {
  1177. requester: response.data,
  1178. area: response.data.place?response.data.place.area:undefined,
  1179. place: response.data.place,
  1180. houseNumber: response.data.houseNumber,
  1181. contactsInformation: response.data.telephone,
  1182. contacts:response.data.name,
  1183. callID: cdrid,
  1184. source: { id: 1 },
  1185. },
  1186. },
  1187. };
  1188. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1189. }
  1190. })
  1191. }
  1192. });
  1193. } else if (myData.list.length == 1) {
  1194. angular.extend(myData.list[0], { 'telephone': $rootScope.phone });
  1195. var data = {
  1196. model: {
  1197. requestershow: myData.list[0],
  1198. incident: {
  1199. requester: myData.list[0],
  1200. area: myData.list[0].place?myData.list[0].place.area:undefined,
  1201. place: myData.list[0].place,
  1202. contactsInformation: myData.list[0].telephone,
  1203. houseNumber: myData.list[0].houseNumber,
  1204. contacts:myData.list[0].name,
  1205. callID: cdrid,
  1206. source: { id: 1 },
  1207. },
  1208. },
  1209. };
  1210. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1211. } else {
  1212. var modalInstance = $modal.open({
  1213. templateUrl: 'assets/views/createincident.html',
  1214. backdrop: "static",
  1215. controller: function($scope, $modalInstance, api_user_data) {
  1216. $scope.title = "请确定报修人";
  1217. $scope.requester = myData.list;
  1218. $scope.choice = function(requester) {
  1219. $modalInstance.dismiss('cancel');
  1220. angular.extend(requester, { 'telephone': $rootScope.phone });
  1221. var data = {
  1222. model: {
  1223. requestershow: requester,
  1224. incident: {
  1225. requester: requester,
  1226. area: requester.place?requester.place.area:undefined,
  1227. place: requester.place,
  1228. houseNumber: requester.houseNumber,
  1229. contactsInformation: requester.telephone,
  1230. contacts:requester.name,
  1231. callID: cdrid,
  1232. source: { id: 1 },
  1233. },
  1234. },
  1235. };
  1236. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  1237. };
  1238. $scope.cancel = function() {
  1239. $modalInstance.dismiss('cancel');
  1240. $rootScope.setidle();
  1241. };
  1242. },
  1243. size: "lg"
  1244. });
  1245. }
  1246. });
  1247. }
  1248. })
  1249. }
  1250. }
  1251. }
  1252. }
  1253. };
  1254. var heartCheck = {
  1255. timeout: 12000, //60ms
  1256. timeoutObj: null,
  1257. serverTimeoutObj: null,
  1258. reset: function() {
  1259. clearTimeout(this.timeoutObj);
  1260. clearTimeout(this.serverTimeoutObj);    
  1261. this.start();
  1262. },
  1263. start: function() {
  1264. var self = this;
  1265. this.timeoutObj = setTimeout(function() {
  1266. if ($scope.login) {
  1267. ws.send("HeartBeat");
  1268. self.serverTimeoutObj = setTimeout(function() {
  1269. ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  1270. }, self.timeout)
  1271. }
  1272. }, this.timeout)
  1273. },
  1274. }
  1275. ws.onclose = function(evt) { reconnect(); }
  1276. ws.onerror = function(evt) { reconnect(); };
  1277. }
  1278. reconnect();
  1279. } else {
  1280. var Notification = window.Notification;
  1281. Notification.requestPermission();
  1282. var n = new Notification("签入失败!", {
  1283. body: data.errmsg,
  1284. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1285. // onclick: function onNotificationClicked() {
  1286. // console.log('Notification clicked.');
  1287. // }
  1288. });
  1289. }
  1290. })
  1291. })
  1292. }
  1293. setInterval(function() {
  1294. if ($scope.login && $rootScope.statuscall == 1 && $rootScope.statecall == 1) {
  1295. $rootScope.setidle();
  1296. } else if ($scope.login && $rootScope.statuscall != 3 && $rootScope.statecall == 2 && statuscall != 0) {
  1297. $rootScope.setbusy
  1298. }
  1299. }, 3000);
  1300. // 华科呼叫中心 end
  1301. //话机呼叫中心--开始
  1302. $rootScope.getExtnDirect = function () {
  1303. $rootScope['getExtnDirect' + $rootScope.seiminHj]();
  1304. }
  1305. // --------------------------1------------------------------
  1306. $rootScope.getExtnDirect1 = function () {
  1307. var jry_data_dictionary = {
  1308. key: "hjzx_cornet",
  1309. type: "list"
  1310. }
  1311. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1312. var websocket_url = "ws://192.168.3.122:29003/ola_socket";
  1313. var ola_queue = "10009"; //通话配置-队列配置-队列ID
  1314. // var ola_extn = "1001"; //个人信息-座席分机号
  1315. $rootScope.jry_extnNumberSelect = [];
  1316. $rootScope.jry_extnNumberObj = {};
  1317. $rootScope.jry_extnNumberSelect = res;
  1318. $rootScope.jry_extnNumberObj.jry_extnNumber = $rootScope.jry_extnNumberSelect[0];
  1319. function log(msg) {
  1320. //IE has no console
  1321. if ('console' in window) console.log(msg);
  1322. }
  1323. function websocket_connect() {
  1324. ola.connect(websocket_url);
  1325. ola.onConnect = onConnect;
  1326. ola.onClose = onClose;
  1327. ola.onMessage = onMessage;
  1328. }
  1329. $(document).ready(function () {
  1330. // if(ola_extn!=""){
  1331. if ($rootScope.jry_extnNumberObj.jry_extnNumber) {
  1332. websocket_connect();
  1333. }
  1334. });
  1335. /* callbacks */
  1336. function onMessage(evt) {
  1337. var phoneData = JSON.parse(evt.data);
  1338. if (phoneData.event_type == "agent_state") {
  1339. console.log(phoneData);
  1340. if (phoneData.state == "busy") {
  1341. $('#agent_state').append(" (" + phoneData.private_data + ")");
  1342. // 来电
  1343. if (phoneData.private_data == "ring") {
  1344. console.log(phoneData);
  1345. $rootScope.jry_state = "laidian";
  1346. var Notification = window.Notification;
  1347. Notification.requestPermission();
  1348. var n = new Notification("你有来电", {
  1349. body: "来电号码:" + phoneData.ani,
  1350. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  1351. });
  1352. // 摘机
  1353. } else if (phoneData.private_data == "answered") {
  1354. $rootScope.jry_state = "tonghuazhong";
  1355. var jry_findPhone = "";
  1356. if (phoneData.ani) {
  1357. jry_findPhone = phoneData.ani
  1358. } else if (phoneData.dnis && phoneData.other_answered) {
  1359. jry_findPhone = phoneData.dnis
  1360. }
  1361. var filterData = {
  1362. "idx": 0,
  1363. "sum": 100,
  1364. "requester": {
  1365. "mphone": jry_findPhone,
  1366. "telephone": jry_findPhone,
  1367. "selectType": 1
  1368. }
  1369. }
  1370. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  1371. var myData = Restangular.stripRestangular(data);
  1372. // $rootScope.phone="";
  1373. // 新增报修人
  1374. if (myData.list.length == 0) {
  1375. var modalInstance = $modal.open({
  1376. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  1377. controller: function ($scope, $modalInstance, api_user_data, SweetAlert, api_wechatfile) {
  1378. $scope.title = "新增报修人";
  1379. $scope.requester = {};
  1380. $scope.onChangeadd = function (searchData) {
  1381. $scope.searchKey = searchData.account;
  1382. // $scope.searchDataadd = searchData;
  1383. var requesdata = angular.copy(searchData)
  1384. // if (requesdata.mphone) {
  1385. // delete requesdata.mphone;
  1386. // }
  1387. if (requesdata.telephone) {
  1388. delete requesdata.telephone;
  1389. }
  1390. angular.extend($scope.requester, requesdata);
  1391. }
  1392. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  1393. $scope.requester.account = searchKey;
  1394. $scope.searchData = searchKey;
  1395. serchdataadd(searchKey);
  1396. }
  1397. $scope.getMydata = function (x) {
  1398. var reqestdatap = JSON.parse(x[0])
  1399. // if ($scope.requester.mphone) {
  1400. // delete reqestdatap.mphone;
  1401. // }
  1402. if ($scope.requester.telephone) {
  1403. delete reqestdatap.telephone;
  1404. }
  1405. $scope.searchField = JSON.parse(x[0]).account;
  1406. angular.extend($scope.requester, reqestdatap);
  1407. }
  1408. $scope.getMydataone = function (x) {
  1409. $scope.searchField = x;
  1410. $scope.requester.account = x;
  1411. }
  1412. serchdataadd();
  1413. function serchdataadd(searchKey) {
  1414. if (searchKey) {
  1415. var filterData = {
  1416. 'requester': {
  1417. 'searchKey': searchKey,
  1418. },
  1419. idx: 0,
  1420. sum: 10
  1421. };
  1422. } else {
  1423. var filterData = {
  1424. idx: 0,
  1425. sum: 10
  1426. };
  1427. }
  1428. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  1429. var myData = response;
  1430. $scope.myData = myData.list;
  1431. });
  1432. }
  1433. api_user_data.fetchDataList('area', {
  1434. idx: 0,
  1435. sum: 100
  1436. }).then(function (response) {
  1437. if (response.status == 200) {
  1438. $scope.areas = response.list;
  1439. }
  1440. })
  1441. api_wechatfile.getDictionary({
  1442. "key": "requester_type",
  1443. "type": "list"
  1444. }).then(function (response) {
  1445. // if (response.status == 200) {
  1446. $scope.networktypes = response;
  1447. // }
  1448. })
  1449. $scope.requesterAreaid = "";
  1450. $scope.onChange = function (item) {
  1451. $scope.requesterAreaid = item.id;
  1452. $scope.requester.place = {};
  1453. api_user_data.fetchDataList('place', {
  1454. place: {
  1455. areaId: item.id
  1456. },
  1457. idx: 0,
  1458. sum: 1000
  1459. }).then(function (response) {
  1460. if (response.status == 200) {
  1461. $scope.places = response.list;
  1462. }
  1463. })
  1464. }
  1465. //地点搜索
  1466. $scope.refresh = function (searchVal) {
  1467. var faildata = {};
  1468. if ($scope.requesterAreaid) {
  1469. faildata = {
  1470. 'idx': 0,
  1471. 'sum': 1000,
  1472. 'place': {
  1473. 'areaId': $scope.requesterAreaid,
  1474. 'place': searchVal,
  1475. 'selectType': 'pinyin_qs'
  1476. }
  1477. }
  1478. } else {
  1479. faildata = {
  1480. 'idx': 0,
  1481. 'sum': 1000,
  1482. 'place': {
  1483. 'place': searchVal,
  1484. 'selectType': 'pinyin_qs'
  1485. }
  1486. }
  1487. }
  1488. api_user_data.fetchDataList('place', faildata).then(function (response) {
  1489. $scope.places = response.list;
  1490. delete $scope.requester.place;
  1491. })
  1492. }
  1493. $scope.requester = {
  1494. 'telephone': jry_findPhone
  1495. };
  1496. $scope.ok = function () {
  1497. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  1498. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  1499. var flag1 = reg1.test($scope.requester.mphone);
  1500. var flag2 = reg2.test($scope.requester.mphone);
  1501. console.log($scope.requester)
  1502. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  1503. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  1504. } else if (angular.isUndefined($scope.requester.requesterType)) {
  1505. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  1506. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  1507. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  1508. }
  1509. else {
  1510. $modalInstance.close($scope.requester);
  1511. }
  1512. };
  1513. $scope.cancel = function () {
  1514. $modalInstance.dismiss('cancel');
  1515. };
  1516. },
  1517. });
  1518. modalInstance.result.then(function (selectedItem) {
  1519. if (selectedItem) {
  1520. if (selectedItem.telephone && !selectedItem.mphone) {
  1521. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1522. delete selectedItem.mphone;
  1523. }
  1524. var data = {
  1525. 'requester': selectedItem
  1526. };
  1527. api_user_data.addData('requester', data).then(function (response) {
  1528. if (response.status == 200) {
  1529. var data = {
  1530. 'model': {
  1531. 'requestershow': response.data,
  1532. 'incident': {
  1533. 'requester': response.data,
  1534. 'area': response.data.place?response.data.place.area:undefined,
  1535. 'place': response.data.place,
  1536. 'houseNumber': response.data.houseNumber,
  1537. 'callID': cdrid,
  1538. 'contacts':response.data.name,
  1539. 'contactsInformation': response.data.telephone,
  1540. 'source': {
  1541. 'id': 1547
  1542. }
  1543. }
  1544. }
  1545. }
  1546. $state.go('app.incident.title', {
  1547. 'model': JSON.stringify(data)
  1548. });
  1549. }
  1550. })
  1551. }
  1552. });
  1553. } else if (myData.list.length == 1) {
  1554. var data = {
  1555. 'model': {
  1556. 'requestershow': myData.list[0],
  1557. 'incident': {
  1558. 'requester': myData.list[0],
  1559. 'area': myData.list[0].place?myData.list[0].place.area:undefined,
  1560. 'place': myData.list[0].place,
  1561. 'houseNumber': myData.list[0].houseNumber,
  1562. 'callID': cdrid,
  1563. 'contacts':myData.list[0].name,
  1564. 'contactsInformation': myData.list[0].telephone,
  1565. 'source': {
  1566. 'id': 1547
  1567. }
  1568. }
  1569. }
  1570. }
  1571. $state.go('app.incident.title', {
  1572. 'model': JSON.stringify(data)
  1573. });
  1574. } else {
  1575. var modalInstance = $modal.open({
  1576. templateUrl: 'assets/views/createincident.html',
  1577. controller: function ($scope, $modalInstance, api_user_data) {
  1578. $scope.title = "请确定报修人";
  1579. $scope.requester = myData.list;
  1580. $scope.choice = function (requester) {
  1581. $modalInstance.dismiss('cancel');
  1582. var data = {
  1583. 'model': {
  1584. 'requestershow': requester,
  1585. 'incident': {
  1586. 'requester': requester,
  1587. 'area': requester.place?requester.place.area:undefined,
  1588. 'place': requester.place,
  1589. 'houseNumber': requester.houseNumber,
  1590. 'callID': cdrid,
  1591. 'contacts':requester.name,
  1592. 'contactsInformation': requester.telephone,
  1593. 'source': {
  1594. 'id': 1547
  1595. }
  1596. }
  1597. }
  1598. }
  1599. $state.go('app.incident.title', {
  1600. 'model': JSON.stringify(data)
  1601. });
  1602. };
  1603. $scope.cancel = function () {
  1604. $modalInstance.dismiss('cancel');
  1605. };
  1606. },
  1607. size: "lg"
  1608. });
  1609. }
  1610. });
  1611. }
  1612. // 挂机
  1613. } else if (phoneData.state == "login") {
  1614. go_ready()
  1615. } else if (phoneData.state == "logout") {
  1616. $rootScope.jry_state = "weiqianru";
  1617. } else if (phoneData.state == "ready") {
  1618. // 来电挂机
  1619. if (phoneData.old_state == "busy" && phoneData.private_data == "answered") {
  1620. go_break()
  1621. } else {
  1622. $rootScope.jry_state = "shixian";
  1623. }
  1624. }
  1625. // else if (data.old_state == "busy") {
  1626. // }
  1627. } else if (phoneData.event_type == "agent_caller_state") {
  1628. // special feature, never mind
  1629. if (phoneData.action == "in") {
  1630. } else {
  1631. }
  1632. } else if (phoneData.event_type == "command/reply") {
  1633. if (phoneData.phoneData && phoneData.phoneData.state) {
  1634. }
  1635. }
  1636. }
  1637. function onConnect() {
  1638. console.log("websocket connected!");
  1639. // ola._extn = ola_extn;
  1640. // ola.subscribe('ola.queue.' + ola_queue + '.' + ola_extn);
  1641. // ola.subscribe('ola.caller.' + ola_extn);
  1642. // ola.get_agent_state(ola_extn);
  1643. ola._extn = $rootScope.jry_extnNumberObj.jry_extnNumber.name;
  1644. ola.subscribe('ola.queue.' + ola_queue + '.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1645. ola.subscribe('ola.caller.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1646. ola.get_agent_state($rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1647. };
  1648. function onClose() {
  1649. }
  1650. function login() {
  1651. // ola.login(ola_queue, ola_extn, {type: "onhook"});
  1652. console.log($rootScope.jry_extnNumberObj.jry_extnNumber);
  1653. ola.login(ola_queue, $rootScope.jry_extnNumberObj.jry_extnNumber.name, { type: "onhook" });
  1654. }
  1655. function logout() {
  1656. ola.logout();
  1657. }
  1658. function go_ready() {
  1659. ola.go_ready();
  1660. }
  1661. function go_break() {
  1662. ola.go_break($('#break_reason').val());
  1663. $rootScope.jry_state = "shimang";
  1664. }
  1665. function answer() {
  1666. ola.answer();
  1667. }
  1668. function dial(dst) {
  1669. ola.dial(dst);
  1670. }
  1671. $rootScope.dial = function (dst) {
  1672. ola.dial(dst);
  1673. }
  1674. function conference(dst) {
  1675. ola.conference(dst);
  1676. }
  1677. function conference_uuid(channel_uuid) {
  1678. ola.conference_uuid(channel_uuid);
  1679. }
  1680. function hangup() {
  1681. ola.hangup();
  1682. }
  1683. function take_call(uuid) {
  1684. // ola.take_call(ola_extn, uuid);
  1685. ola.take_call($rootScope.jry_extnNumberObj.jry_extnNumber.name, uuid);
  1686. }
  1687. // 签入
  1688. $rootScope.jry_qianru = function () {
  1689. login();
  1690. }
  1691. // 示闲
  1692. $rootScope.jry_shixian = function () {
  1693. go_ready()
  1694. }
  1695. // 示忙
  1696. $rootScope.jry_shimang = function () {
  1697. go_break()
  1698. }
  1699. // 签出
  1700. $rootScope.jry_qianchu = function () {
  1701. logout()
  1702. }
  1703. $rootScope.jry_bohao = function (res) {
  1704. if ($rootScope.jry_state == "weiqianru") {
  1705. // SweetAlert.swal({
  1706. // title: "拨打失败",
  1707. // text: "请先签入!",
  1708. // type: "error",
  1709. // confirmButtonColor: "#DD6B55"
  1710. // });
  1711. } else if ($rootScope.jry_state == "shimang") {
  1712. // SweetAlert.swal({
  1713. // title: "拨打失败",
  1714. // text: "请先示闲!",
  1715. // type: "error",
  1716. // confirmButtonColor: "#DD6B55"
  1717. // });
  1718. } else {
  1719. dial(res);
  1720. }
  1721. }
  1722. })
  1723. }
  1724. // ------------------------------2--------------------------
  1725. $rootScope.getExtnDirect2 = function () {
  1726. var jry_data_dictionary = {
  1727. key: "hjzx_cornet",
  1728. type: "list"
  1729. }
  1730. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1731. sessionStorage.setItem('phones',JSON.stringify(res.map(v=>v.name)));
  1732. var websocket_url = $rootScope.seiminCallIp;
  1733. $rootScope.jry_extnNumberSelect = [];
  1734. $rootScope.jry_extnNumberObj = {};
  1735. $rootScope.jry_extnNumberSelect = angular.copy(res);
  1736. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1737. var fenjiNumber = localStorage.getItem('fenjiNumber');
  1738. if(fenjiNumber){
  1739. $rootScope.jry_extnNumberSelect.forEach(ress=>{
  1740. if(ress.name == fenjiNumber){
  1741. $rootScope.jry_extnNumberObj.jry_extnNumber = ress;
  1742. }
  1743. })
  1744. }
  1745. // $rootScope.jry_extnNumberObj.jry_extnNumber = angular.copy(res[0]);//绑定分机对象
  1746. // $rootScope.jry_extnNumberObj.tel1 = angular.copy(res[0]);//目的号码对象
  1747. // $rootScope.jry_extnNumberObj.tel2 = angular.copy(res[0]);//转接坐席对象
  1748. $rootScope.preState = '';//最近一次示忙还是示闲的状态
  1749. //连接
  1750. tlwsa.tlaOpen(websocket_url);
  1751. // 强制示忙
  1752. $scope.qShimang = function(state){
  1753. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1754. //进入页面,强制示忙
  1755. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1756. setTimeout(()=>{
  1757. tlwsa.tlaAcw();
  1758. },0)
  1759. }else{
  1760. $scope.getState(state);
  1761. }
  1762. }
  1763. // 获取状态
  1764. $scope.getState = function (state) {
  1765. // if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1766. // if(state != 2&&state != 0){
  1767. // //进入页面,强制示忙
  1768. // // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1769. // setTimeout(()=>{
  1770. // tlwsa.tlaAcw();
  1771. // },3000)
  1772. // }
  1773. // }
  1774. // var agcount = tlwsa.tlaGetagentcount();
  1775. // var flag = true;
  1776. // for (var i = 0; i < agcount; i++) {
  1777. // if (tlwsa.tlaGetagentwid(i) == $rootScope.phoneNumber) {
  1778. // flag = false;
  1779. // var state = Number(tlwsa.tlaGetagentstate(i));
  1780. // console.log(state);
  1781. switch (state) {
  1782. case 0:
  1783. $rootScope.jry_state = 'weiqianru';
  1784. break;
  1785. case 1:
  1786. $rootScope.jry_state = 'shixian';
  1787. break;
  1788. case 2:
  1789. $rootScope.jry_state = 'shimang';
  1790. break;
  1791. case 3:
  1792. $rootScope.jry_state = 'laidian';
  1793. break;
  1794. case 5:
  1795. $rootScope.jry_state = 'tonghuazhong';
  1796. break;
  1797. case 6:
  1798. $rootScope.jry_state = 'zhengzaiwaihu';
  1799. break;
  1800. case 7:
  1801. $rootScope.jry_state = 'zhengzaizhuanyi';
  1802. break;
  1803. }
  1804. // }
  1805. // console.log('agnet No. ' + i + ' workid is ' + tlwsa.tlaGetagentwid(i) + ' state is ' + tlwsa.tlaGetagentstate(i) + ' ' + getStateInfo(tlwsa.tlaGetagentstate(i)))
  1806. // }
  1807. // if (flag) {
  1808. // $rootScope.jry_state = 'weiqianru';
  1809. // }
  1810. }
  1811. // 状态回调函数
  1812. // TLWSA.onStatechange = onstatechange;
  1813. // function onstatechange() {
  1814. // console.log('事件:状态变化----------------------------------------------------');
  1815. // $scope.getState();
  1816. // }
  1817. //连接呼叫中心回调函数
  1818. TLWSA.onOpenreturn = onopenreturn;
  1819. function onopenreturn(err) {
  1820. err = Number(err);
  1821. if (!err) {
  1822. console.log('呼叫中心连接成功-----seimin');
  1823. $scope.getState(0);
  1824. $.toaster({
  1825. priority: 'info',
  1826. title: '操作',
  1827. message: '呼叫中心连接成功'
  1828. });
  1829. //如果设置过话机
  1830. if (localStorage.getItem('phoneNumber')) {
  1831. //强制签出,然后签入
  1832. tlwsa.tlaKillworkid(localStorage.getItem('phoneNumber'));
  1833. }
  1834. } else {
  1835. console.log('呼叫中心连接失败-----seimin');
  1836. $scope.getState(0);
  1837. $.toaster({
  1838. priority: 'info',
  1839. title: '操作',
  1840. message: '呼叫中心连接失败'
  1841. });
  1842. }
  1843. }
  1844. //绑定分机回调函数
  1845. TLWSA.onSetphonenumberreturn = onsetphonenumberreturn;
  1846. function onsetphonenumberreturn(err) {
  1847. err = Number(err);
  1848. if (!err) {
  1849. console.log('绑定分机成功-----seimin');
  1850. $.toaster({
  1851. priority: 'info',
  1852. title: '操作',
  1853. message: '绑定分机成功'
  1854. });
  1855. localStorage.setItem('phoneNumber', $rootScope.phoneNumber);
  1856. localStorage.setItem('fenjiNumber', $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1857. $scope.qShimang(1);
  1858. } else {
  1859. console.log('绑定分机失败-----seimin');
  1860. $scope.getState(0);
  1861. $.toaster({
  1862. priority: 'info',
  1863. title: '操作',
  1864. message: '绑定分机失败'
  1865. });
  1866. }
  1867. }
  1868. //强制示忙回调函数
  1869. // TLWSA.onAcw = onacw;
  1870. // function onacw(err) {
  1871. // err = Number(err);
  1872. // if (!err) {
  1873. // console.log('强制示忙成功-----seimin');
  1874. // $scope.getState(2);
  1875. // $.toaster({
  1876. // priority: 'info',
  1877. // title: '操作',
  1878. // message: '示忙成功'
  1879. // });
  1880. // } else {
  1881. // console.log('强制示忙失败-----seimin');
  1882. // $.toaster({
  1883. // priority: 'info',
  1884. // title: '操作',
  1885. // message: '示忙失败'
  1886. // });
  1887. // }
  1888. // }
  1889. // //强制示闲回调函数
  1890. // TLWSA.onWca = onwca;
  1891. // function onwca(err) {
  1892. // console.log(err)
  1893. // err = Number(err);
  1894. // if (!err) {
  1895. // console.log('强制示闲成功-----seimin');
  1896. // $scope.getState(1);
  1897. // $.toaster({
  1898. // priority: 'info',
  1899. // title: '操作',
  1900. // message: '示闲成功'
  1901. // });
  1902. // } else {
  1903. // console.log('强制示闲失败-----seimin');
  1904. // $.toaster({
  1905. // priority: 'info',
  1906. // title: '操作',
  1907. // message: '示闲失败'
  1908. // });
  1909. // }
  1910. // }
  1911. //与服务器网络连接中断回调函数
  1912. TLWSA.onClosed = onclosed;
  1913. function onclosed() {
  1914. $scope.getState(0);
  1915. console.log('与服务器网络连接中断-----seimin');
  1916. $.toaster({
  1917. priority: 'info',
  1918. title: '操作',
  1919. message: '与服务器网络连接中断,2分钟后重连'
  1920. });
  1921. console.log('2分钟后自动重连-----seimin')
  1922. $timeout(function () {
  1923. //连接
  1924. tlwsa.tlaOpen(websocket_url);
  1925. }, 120000)
  1926. }
  1927. //签入回调函数
  1928. TLWSA.onLoginreturn = onloginreturn;
  1929. function onloginreturn(err) {
  1930. err = Number(err);
  1931. if (!err) {
  1932. console.log('签入成功-----seimin');
  1933. $.toaster({
  1934. priority: 'info',
  1935. title: '操作',
  1936. message: '签入成功'
  1937. });
  1938. setTimeout(function () {
  1939. console.log($rootScope.jry_extnNumberObj.jry_extnNumber.name,1111)
  1940. var fenjiNumber = $rootScope.jry_extnNumberObj.jry_extnNumber.name || localStorage.getItem('fenjiNumber');
  1941. console.log('开始绑定分机【' + fenjiNumber + '】-----seimin');
  1942. tlwsa.tlaSetphonenumber(fenjiNumber);
  1943. }, 0)
  1944. } else if (err == 9011) {
  1945. console.log('签入失败,该分机已登录-----seimin');
  1946. $.toaster({
  1947. priority: 'info',
  1948. title: '操作',
  1949. message: '签入失败,该分机已登录'
  1950. });
  1951. } else {
  1952. console.log('签入失败-----seimin');
  1953. $.toaster({
  1954. priority: 'info',
  1955. title: '操作',
  1956. message: '签入失败'
  1957. });
  1958. }
  1959. // tlwsa.tlaSubscribestateinfo(2);
  1960. }
  1961. // 强制签出回调函数
  1962. TLWSA.onKillreturn = onkillreturn;
  1963. function onkillreturn(err) {
  1964. err = Number(err);
  1965. if (!err) {
  1966. console.log('强制签出成功-----seimin');
  1967. $scope.getState(0);
  1968. // $.toaster({
  1969. // priority: 'info',
  1970. // title: '操作',
  1971. // message: '强制签出成功'
  1972. // });
  1973. } else {
  1974. console.log('强制签出失败,该分机不是签入状态-----seimin');
  1975. // $.toaster({
  1976. // priority: 'info',
  1977. // title: '操作',
  1978. // message: '强制签出失败'
  1979. // });
  1980. }
  1981. //如果设置过话机
  1982. if (localStorage.getItem('phoneNumber')) {
  1983. // 签入并绑定分机
  1984. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  1985. tlwsa.tlaLogin($rootScope.phoneNumber, 1, -1);
  1986. }
  1987. }
  1988. // 签出回调函数
  1989. TLWSA.onLogoffreturn = onlogoffreturn;
  1990. function onlogoffreturn(err) {
  1991. err = Number(err);
  1992. if (!err) {
  1993. console.log('签出成功-----seimin');
  1994. $scope.getState(0);
  1995. $.toaster({
  1996. priority: 'info',
  1997. title: '操作',
  1998. message: '签出成功'
  1999. });
  2000. localStorage.removeItem('phoneNumber');
  2001. localStorage.removeItem('fenjiNumber');
  2002. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  2003. } else {
  2004. console.log('签出失败-----seimin');
  2005. $.toaster({
  2006. priority: 'info',
  2007. title: '操作',
  2008. message: '签出失败'
  2009. });
  2010. }
  2011. }
  2012. //示忙回调函数
  2013. TLWSA.onAcwreturn = onacwreturn;
  2014. function onacwreturn(err) {
  2015. err = Number(err);
  2016. if (!err) {
  2017. console.log('示忙成功-----seimin');
  2018. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  2019. $scope.isShixian = false;
  2020. }else{
  2021. $scope.isShixian = true;
  2022. }
  2023. $scope.getState(2);
  2024. $rootScope.preState = 2;
  2025. $.toaster({
  2026. priority: 'info',
  2027. title: '操作',
  2028. message: '示忙成功'
  2029. });
  2030. } else {
  2031. console.log('示忙失败-----seimin');
  2032. // $.toaster({
  2033. // priority: 'info',
  2034. // title: '操作',
  2035. // message: '示忙失败'
  2036. // });
  2037. }
  2038. }
  2039. //示闲回调函数
  2040. TLWSA.onWcareturn = onwcareturn;
  2041. function onwcareturn(err) {
  2042. err = Number(err);
  2043. if (!err) {
  2044. console.log('示闲成功-----seimin');
  2045. $scope.getState(1);
  2046. $rootScope.preState = 1;
  2047. $.toaster({
  2048. priority: 'info',
  2049. title: '操作',
  2050. message: '示闲成功'
  2051. });
  2052. } else {
  2053. console.log('示闲失败-----seimin');
  2054. $.toaster({
  2055. priority: 'info',
  2056. title: '操作',
  2057. message: '示闲失败'
  2058. });
  2059. }
  2060. }
  2061. //呼叫坐席回调函数
  2062. TLWSA.onCallreturn = oncallreturn;
  2063. function oncallreturn(err) {
  2064. err = Number(err);
  2065. if (!err) {
  2066. console.log('呼叫成功,请摘机-----seimin');
  2067. $scope.getState(6);
  2068. $.toaster({
  2069. priority: 'info',
  2070. title: '操作',
  2071. message: '呼叫成功,请摘机'
  2072. });
  2073. } else {
  2074. console.log('呼叫失败-----seimin');
  2075. $.toaster({
  2076. priority: 'info',
  2077. title: '操作',
  2078. message: '呼叫失败'
  2079. });
  2080. }
  2081. }
  2082. //呼叫坐席被接听回调函数
  2083. TLWSA.onCallresult = oncallresult;
  2084. function oncallresult(jso) {
  2085. console.log(jso);
  2086. var err = Number(jso.err);
  2087. if (!err) {
  2088. console.log('呼叫被接听成功-----seimin');
  2089. $scope.getState(5);
  2090. $.toaster({
  2091. priority: 'info',
  2092. title: '操作',
  2093. message: '呼叫被接听成功'
  2094. });
  2095. } else {
  2096. console.log('呼叫被接听失败-----seimin');
  2097. $scope.qShimang(1);
  2098. $.toaster({
  2099. priority: 'info',
  2100. title: '操作',
  2101. message: '呼叫被接听失败'
  2102. });
  2103. }
  2104. }
  2105. //挂断回调函数
  2106. TLWSA.onCallend = oncallend;
  2107. function oncallend(jso) {
  2108. console.log(jso);//lmm
  2109. if (jso) {
  2110. console.log('挂断成功-----seimin');
  2111. console.log('最近一次话机状态',$rootScope.preState);
  2112. $scope.qShimang($rootScope.preState);
  2113. $.toaster({
  2114. priority: 'info',
  2115. title: '操作',
  2116. message: '挂断成功'
  2117. });
  2118. } else {
  2119. console.log('挂断失败-----seimin');
  2120. $.toaster({
  2121. priority: 'info',
  2122. title: '操作',
  2123. message: '挂断失败'
  2124. });
  2125. }
  2126. }
  2127. //呼入回调函数
  2128. TLWSA.onCallin = oncallin;
  2129. function oncallin(jso) {
  2130. console.log(jso);//lmm
  2131. $rootScope.callInPhoneNumber = jso.caller;//来电的电话
  2132. $rootScope.sockid = jso.crs;//来电的话机id
  2133. if (jso) {
  2134. console.log('呼入坐席成功,请摘机-----seimin');
  2135. $scope.getState(3);
  2136. $.toaster({
  2137. priority: 'info',
  2138. title: '操作',
  2139. message: '呼入坐席成功,请摘机'
  2140. });
  2141. console.log('来电了!电话号码是【' + $rootScope.callInPhoneNumber + '】');
  2142. } else {
  2143. console.log('呼入坐席失败-----seimin');
  2144. $.toaster({
  2145. priority: 'info',
  2146. title: '操作',
  2147. message: '呼入坐席失败'
  2148. });
  2149. }
  2150. }
  2151. // 测试代码start
  2152. // seachBxDept();
  2153. // 测试代码end
  2154. // 查报修科室
  2155. function seachBxDept(){
  2156. var postData = { "idx": 0, "sum": 10, "department": { phone: $rootScope.callInPhoneNumber } };//hjzxPhone
  2157. api_user_data.fetchDataList('department', postData).then(function (result) {
  2158. if (result.status == 200) {
  2159. console.log(result.list);
  2160. var requesters = result.list;
  2161. if (requesters.length === 0) {
  2162. //未匹配到报修科室
  2163. $rootScope.newOrder({
  2164. incident: {
  2165. sockid: $rootScope.sockid,
  2166. incomingPhone: $rootScope.callInPhoneNumber,
  2167. source: {id:1547,name:'电话'}
  2168. },
  2169. },'incomingCall')
  2170. // $state.go('app.incident.chart', {
  2171. // model: JSON.stringify({
  2172. // model: {
  2173. // incident: {
  2174. // requester: {
  2175. // phone: $rootScope.callInPhoneNumber,//hjzxPhone
  2176. // },
  2177. // sockid: $rootScope.sockid
  2178. // }
  2179. // }
  2180. // })
  2181. // });
  2182. } else if (requesters.length === 1) {
  2183. //匹配到一个报修科室
  2184. $rootScope.newOrder({
  2185. incident: {
  2186. department: requesters[0],
  2187. phone: requesters[0].phone,
  2188. sockid: $rootScope.sockid,
  2189. incomingPhone: $rootScope.callInPhoneNumber,
  2190. source: {id:1547,name:'电话'}
  2191. },
  2192. },'incomingCall')
  2193. // $state.go('app.incident.chart', {
  2194. // model: JSON.stringify({
  2195. // model: {
  2196. // incident: {
  2197. // requester: requesters[0],
  2198. // contactsInformation: requesters[0].mphone,
  2199. // sockid: $rootScope.sockid
  2200. // },
  2201. // }
  2202. // })
  2203. // });
  2204. } else {
  2205. //匹配到多个报修科室
  2206. $modal.open({
  2207. templateUrl: 'assets/views/incident/tpl/tel.html',
  2208. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  2209. $scope.list = requesters;
  2210. $scope.selected = {
  2211. selectedItem: 0
  2212. };
  2213. $scope.cancel = function () {
  2214. $modalInstance.dismiss('cancel');
  2215. };
  2216. $scope.changeBxr = function (id) {
  2217. $scope.selected.selectedItem = id;
  2218. }
  2219. $scope.save = function () {
  2220. var item = $scope.list.find(v => v.id == $scope.selected.selectedItem);
  2221. if (item) {
  2222. $scope.cancel();
  2223. $rootScope.newOrder({
  2224. incident: {
  2225. department: item,
  2226. phone: item.phone,
  2227. sockid: $rootScope.sockid,
  2228. incomingPhone: $rootScope.callInPhoneNumber,
  2229. source: {id:1547,name:'电话'}
  2230. },
  2231. },'incomingCall')
  2232. // $state.go('app.incident.chart', {
  2233. // model: JSON.stringify({
  2234. // model: {
  2235. // incident: {
  2236. // requester: item,
  2237. // contactsInformation: item.mphone,
  2238. // sockid: $rootScope.sockid
  2239. // },
  2240. // }
  2241. // })
  2242. // });
  2243. } else {
  2244. SweetAlert.swal({
  2245. title: "请选择报修科室!",
  2246. type: "error"
  2247. })
  2248. }
  2249. }
  2250. }
  2251. });
  2252. }
  2253. }
  2254. })
  2255. }
  2256. //呼入摘机应答回调函数
  2257. TLWSA.onAnswer = onanswer;
  2258. function onanswer(err) {
  2259. err = Number(err);
  2260. if (!err) {
  2261. console.log('呼入摘机应答成功-----seimin');
  2262. $scope.getState(5);
  2263. $.toaster({
  2264. priority: 'info',
  2265. title: '操作',
  2266. message: '呼入摘机应答成功'
  2267. });
  2268. //根据电话号码反查报修人,如果是坐席号码,则不用
  2269. // console.log(sessionStorage.getItem('phones'));
  2270. // var phones = JSON.parse(sessionStorage.getItem('phones'));
  2271. // var isHuajihao = phones.length?phones.some(v=>v == teleno):false;
  2272. // if(isHuajihao){
  2273. // return;
  2274. // }
  2275. // 查报修科室
  2276. seachBxDept();
  2277. // var postData = { "idx": 0, "sum": 10, "requester": { hjzxPhone: $rootScope.callInPhoneNumber } };
  2278. // api_user_data.fetchDataList('requester', postData).then(function (result) {
  2279. // if (result.status == 200) {
  2280. // console.log(result.list);
  2281. // var requesters = result.list;
  2282. // if (requesters.length === 0) {
  2283. // //未匹配到报修人,则弹窗添加报修人yeye
  2284. // $state.go('app.incident.chart', {
  2285. // model: JSON.stringify({
  2286. // model: {
  2287. // incident: {
  2288. // requester: {
  2289. // hjzxPhone: $rootScope.callInPhoneNumber
  2290. // },
  2291. // sockid: $rootScope.sockid
  2292. // }
  2293. // }
  2294. // })
  2295. // });
  2296. // } else if (requesters.length === 1) {
  2297. // //匹配到一个报修人
  2298. // $state.go('app.incident.chart', {
  2299. // model: JSON.stringify({
  2300. // model: {
  2301. // incident: {
  2302. // requester: requesters[0],
  2303. // contactsInformation: requesters[0].mphone,
  2304. // sockid: $rootScope.sockid
  2305. // },
  2306. // }
  2307. // })
  2308. // });
  2309. // } else {
  2310. // //匹配到多个报修人
  2311. // $modal.open({
  2312. // templateUrl: 'assets/views/incident/tpl/tel.html',
  2313. // controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  2314. // $scope.list = requesters;
  2315. // $scope.selectedItem = 0;
  2316. // $scope.cancel = function () {
  2317. // $modalInstance.dismiss('cancel');
  2318. // };
  2319. // $scope.changeBxr = function (id) {
  2320. // $scope.selectedItem = id;
  2321. // }
  2322. // $scope.save = function () {
  2323. // var item = $scope.list.find(v => v.id == $scope.selectedItem);
  2324. // if (item) {
  2325. // $scope.cancel();
  2326. // $state.go('app.incident.chart', {
  2327. // model: JSON.stringify({
  2328. // model: {
  2329. // incident: {
  2330. // requester: item,
  2331. // contactsInformation: item.mphone,
  2332. // sockid: $rootScope.sockid
  2333. // },
  2334. // }
  2335. // })
  2336. // });
  2337. // } else {
  2338. // SweetAlert.swal({
  2339. // title: "请选择报修人!",
  2340. // type: "error"
  2341. // })
  2342. // }
  2343. // }
  2344. // }
  2345. // });
  2346. // }
  2347. // }
  2348. // })
  2349. } else {
  2350. console.log('呼入摘机应答失败-----seimin');
  2351. $.toaster({
  2352. priority: 'info',
  2353. title: '操作',
  2354. message: '呼入摘机应答失败'
  2355. });
  2356. }
  2357. }
  2358. //呼入未摘机应答回调函数
  2359. TLWSA.onMisscall = onmisscall;
  2360. function onmisscall(err) {
  2361. err = Number(err);
  2362. if (!err) {
  2363. console.log('呼入未摘机应答成功-----seimin');
  2364. $scope.getState(1);
  2365. $.toaster({
  2366. priority: 'info',
  2367. title: '操作',
  2368. message: '呼入未摘机应答成功'
  2369. });
  2370. } else {
  2371. console.log('呼入未摘机应答失败-----seimin');
  2372. $.toaster({
  2373. priority: 'info',
  2374. title: '操作',
  2375. message: '呼入未摘机应答失败'
  2376. });
  2377. }
  2378. }
  2379. //转接开始回调函数
  2380. TLWSA.onTransferreturn = ontransferreturn;//调用转移方法之后,返回该事件 如果错误码为0,仅仅表示开始转移,不代表转移目标已经接听或已经拒绝
  2381. function ontransferreturn(err) {
  2382. err = Number(err);
  2383. if (!err) {
  2384. console.log('转接坐席开始成功-----seimin');
  2385. $scope.getState(7);
  2386. $.toaster({
  2387. priority: 'info',
  2388. title: '操作',
  2389. message: '转接坐席开始成功'
  2390. });
  2391. } else {
  2392. console.log('转接坐席开始失败-----seimin');
  2393. $.toaster({
  2394. priority: 'info',
  2395. title: '操作',
  2396. message: '转接坐席开始失败'
  2397. });
  2398. }
  2399. }
  2400. //转接结果回调函数
  2401. TLWSA.onTransferresult = ontransferresult;
  2402. function ontransferresult(err) {
  2403. err = Number(err);
  2404. if (!err) {
  2405. console.log('转接坐席结果成功-----seimin');
  2406. $scope.getState(1);
  2407. $.toaster({
  2408. priority: 'info',
  2409. title: '操作',
  2410. message: '转接坐席结果成功'
  2411. });
  2412. } else {
  2413. console.log('转接坐席结果失败-----seimin');
  2414. $.toaster({
  2415. priority: 'info',
  2416. title: '操作',
  2417. message: '转接坐席结果失败'
  2418. });
  2419. }
  2420. }
  2421. // 签入
  2422. $rootScope.jry_qianru = function () {
  2423. console.log($rootScope.jry_extnNumberObj.jry_extnNumber)
  2424. if(Object.keys($rootScope.jry_extnNumberObj.jry_extnNumber).length === 0){
  2425. $.toaster({
  2426. priority: 'info',
  2427. title: '警告',
  2428. message: '绑定分机不能为空'
  2429. });
  2430. return;
  2431. }
  2432. // 签入并绑定分机
  2433. // $rootScope.jry_extnNumberObj.jry_extnNumber.name 分机号
  2434. // $rootScope.user.id 坐席号(用户id)
  2435. tlwsa.tlaLogin($rootScope.user.id, 1, -1);
  2436. $rootScope.phoneNumber = $rootScope.user.id;
  2437. }
  2438. // 示闲
  2439. $rootScope.jry_shixian = function () {
  2440. tlwsa.tlaWca();
  2441. }
  2442. // 示忙
  2443. $rootScope.jry_shimang = function () {
  2444. tlwsa.tlaAcw();
  2445. }
  2446. // 签出
  2447. $rootScope.jry_qianchu = function () {
  2448. tlwsa.tlaLogoff();
  2449. }
  2450. // 呼叫坐席
  2451. // $scope.tlaCallagc = function () {
  2452. // tlwsa.tlaCallagc($rootScope.jry_extnNumberObj.tel1)
  2453. // }
  2454. // 呼叫外线
  2455. $scope.tlaCallout = function () {
  2456. // 选择目的号码
  2457. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2458. var reg2 = /^(0|9|90|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2459. if(!reg1.test($rootScope.jry_extnNumberObj.tel1)&&!reg2.test($rootScope.jry_extnNumberObj.tel1)){
  2460. $.toaster({
  2461. priority: 'info',
  2462. title: '警告',
  2463. message: '请输入正确的手机号或座机号'
  2464. });
  2465. return;
  2466. }
  2467. // tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2468. tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1, '3558177',1);//襄阳主叫号码写死
  2469. }
  2470. // // 转移坐席
  2471. // $scope.tlaTransfertoagc = function () {
  2472. // tlwsa.tlaTransfertoagc($rootScope.jry_extnNumberObj.tel2)
  2473. // }
  2474. // 转移外线
  2475. $scope.tlaTransferout = function () {
  2476. // 选择转接号码
  2477. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  2478. var reg2 = /^(0|9|90|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  2479. if(!reg1.test($rootScope.jry_extnNumberObj.tel2)&&!reg2.test($rootScope.jry_extnNumberObj.tel2)){
  2480. $.toaster({
  2481. priority: 'info',
  2482. title: '警告',
  2483. message: '请输入正确的手机号或座机号'
  2484. });
  2485. return;
  2486. }
  2487. // tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  2488. tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2, '3558177',1);//襄阳主叫号码写死
  2489. }
  2490. })
  2491. }
  2492. // ------------------------------3--------------------------
  2493. $rootScope.getExtnDirect3 = function(){
  2494. console.log($rootScope.user)
  2495. var user = $rootScope.user;
  2496. initImUser(user.email, user.msgUuid);
  2497. // $rootScope.start(JSON.parse(localStorage.userdata).commonExtension.name);
  2498. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function(data) {
  2499. $scope.runNumber = data;
  2500. $scope.phone = $scope.runNumber[0].name;
  2501. $rootScope.phoneChange($scope.phone);
  2502. })
  2503. if ($rootScope.userMenus.length == 0) {
  2504. getMenus();
  2505. }
  2506. if(localStorage.getItem('hk_phone')){
  2507. $rootScope.start(localStorage.getItem('hk_phone'));
  2508. }
  2509. }
  2510. // ------------------------------4盒子--------------------------start
  2511. $rootScope.phoneNumListBind = []; //已绑定分机列表
  2512. $rootScope.phoneNumListSelected = []; //选中的分机列表
  2513. $rootScope.phoneNumList = []; //所有分机列表
  2514. $rootScope.newOrderShow = false; //展示/隐藏新建工单弹框
  2515. $rootScope.newOrderShowOpen = false; //展示/隐藏新建工单弹框(辅助项)
  2516. $rootScope.applyDept; //申请科室
  2517. $rootScope.applyDeptMiddle; //申请科室(中间传递)
  2518. $rootScope.getExtnDirect4 = function () {
  2519. console.log(WebsocketPhoneService);
  2520. $rootScope.getPhoneNum();
  2521. }
  2522. $rootScope.getPhoneNum = function(flag = true) {
  2523. if (!flag) {
  2524. //切换院区的时候清除掉缓存中的号码
  2525. localStorage.removeItem("box_phones");
  2526. }
  2527. $rootScope.phoneNumListBind = localStorage.getItem("box_phones")
  2528. ? localStorage.getItem("box_phones").split("_")
  2529. : [];
  2530. $rootScope.phoneNumListSelected = localStorage.getItem("box_phones")
  2531. ? localStorage.getItem("box_phones").split("_")
  2532. : [];
  2533. if ($rootScope.phoneNumListBind.length) {
  2534. $rootScope.getWebsocketPhone();
  2535. }
  2536. }
  2537. // 查报修科室
  2538. function seachBoxBxDept(callInPhoneNumber, callID){
  2539. var postData = { "idx": 0, "sum": 10, "department": { phone: callInPhoneNumber } };//hjzxPhone
  2540. api_user_data.fetchDataList('department', postData).then(function (result) {
  2541. if (result.status == 200) {
  2542. console.log(result.list);
  2543. var requesters = result.list;
  2544. if (requesters.length === 0) {
  2545. //未匹配到报修科室
  2546. $rootScope.newOrder({
  2547. incident: {
  2548. sockid: callID,
  2549. incomingPhone: callInPhoneNumber,
  2550. source: {id:1547,name:'电话'}
  2551. },
  2552. },'incomingCall')
  2553. } else if (requesters.length === 1) {
  2554. //匹配到一个报修科室
  2555. $rootScope.newOrder({
  2556. incident: {
  2557. department: requesters[0],
  2558. phone: requesters[0].phone,
  2559. sockid: callID,
  2560. incomingPhone: callInPhoneNumber,
  2561. source: {id:1547,name:'电话'}
  2562. },
  2563. },'incomingCall')
  2564. } else {
  2565. //匹配到多个报修科室
  2566. $modal.open({
  2567. templateUrl: 'assets/views/incident/tpl/tel.html',
  2568. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  2569. $scope.list = requesters;
  2570. $scope.selected = {
  2571. selectedItem: 0
  2572. };
  2573. $scope.cancel = function () {
  2574. $rootScope.newOrderShowOpen = false;
  2575. $modalInstance.dismiss('cancel');
  2576. };
  2577. $scope.changeBxr = function (id) {
  2578. $scope.selected.selectedItem = id;
  2579. }
  2580. $scope.save = function () {
  2581. var item = $scope.list.find(v => v.id == $scope.selected.selectedItem);
  2582. if (item) {
  2583. $scope.cancel();
  2584. $rootScope.newOrder({
  2585. incident: {
  2586. department: item,
  2587. phone: item.phone,
  2588. sockid: callID,
  2589. incomingPhone: callInPhoneNumber,
  2590. source: {id:1547,name:'电话'}
  2591. },
  2592. },'incomingCall')
  2593. } else {
  2594. SweetAlert.swal({
  2595. title: "请选择报修科室!",
  2596. type: "error"
  2597. })
  2598. }
  2599. }
  2600. }
  2601. });
  2602. }
  2603. }
  2604. })
  2605. }
  2606. // 连接websocket---phone
  2607. // 待完成
  2608. $rootScope.getWebsocketPhone = function() {
  2609. $rootScope.isMask = true;
  2610. // {"userCount":"LiaoMingMing|3369_3366"}
  2611. let userCount = $rootScope.user.account + "|" + $rootScope.phoneNumListSelected.join("_");
  2612. WebsocketPhoneService.connectWs($rootScope.seiminCallBoxIp, { userCount }).subscribe((data) => {
  2613. // data = { status: 201, phone: '013581394341' };//ceshi
  2614. var callID = data.callId;
  2615. console.log(data);
  2616. $rootScope.isMask = false;
  2617. if (data.status == 200 && data.phone) {
  2618. $.toaster({
  2619. priority: 'info',
  2620. title: '操作',
  2621. message: '连接成功'
  2622. });
  2623. localStorage.setItem("box_phones", data.phone);
  2624. $rootScope.phoneNumListBind = data.phone.split("_");
  2625. $rootScope.phoneNumListBind.forEach((item) => {
  2626. let obj = $rootScope.phoneNumList.find((item1) => item1.value === item);
  2627. if (obj) {
  2628. obj.checked = true;
  2629. }
  2630. });
  2631. } else if (data.status == 201 && data.phone) {
  2632. if (!$rootScope.newOrderShow && !$rootScope.newOrderShowOpen) {
  2633. seachBoxBxDept(data.phone, callID);
  2634. }
  2635. } else if (data.status == 201 && data.phone === "") {
  2636. //没绑定科室
  2637. if (!$rootScope.newOrderShow && !$rootScope.newOrderShowOpen) {
  2638. $rootScope.newOrder({
  2639. incident: {
  2640. sockid: callID,
  2641. incomingPhone: data.phone,
  2642. source: {id:1547,name:'电话'}
  2643. },
  2644. },'incomingCall')
  2645. }
  2646. }
  2647. });
  2648. }
  2649. // 选择分机
  2650. $rootScope.changePhones = function(value) {
  2651. $rootScope.phoneNumListSelected = $rootScope.phoneNumList.filter(v => v.checked).map(v => v.value);
  2652. $rootScope.phoneNumListSelectedStr = $rootScope.phoneNumListSelected.length ? '您选择了'+ $rootScope.phoneNumListSelected.map(v => '‘'+ v +'’').join('') +'号码,可在下方选择后确认更新。' : '请选择分机';
  2653. console.log($rootScope.phoneNumListSelected);
  2654. }
  2655. //获取所有分机号码列表
  2656. $rootScope.getPhoneNumList = function() {
  2657. this.phoneNumLoading = true;
  2658. let postData = {
  2659. idx: 0,
  2660. sum: 100,
  2661. hospitalConfig: { hosId: this.checkedHos },
  2662. };
  2663. this.mainService
  2664. .getFetchDataList("simple/data", "hospitalConfig", postData)
  2665. .subscribe((result) => {
  2666. this.phoneNumLoading = false;
  2667. this.phoneNumList = result.list.filter(
  2668. (item) => item.key.includes("phone_num_port") && item.value
  2669. );
  2670. this.phoneNumList.map((item) => {
  2671. return { ...item, checked: false };
  2672. });
  2673. this.phoneNumListBind.forEach((item) => {
  2674. let obj = this.phoneNumList.find((item1) => item1.value === item);
  2675. if (obj) {
  2676. obj.checked = true;
  2677. }
  2678. });
  2679. });
  2680. }
  2681. //确定绑定
  2682. $rootScope.bindingOk = function() {
  2683. if ($rootScope.phoneNumListSelected.length > 0) {
  2684. WebsocketPhoneService.closeWs(true);
  2685. $rootScope.getWebsocketPhone();
  2686. } else {
  2687. localStorage.removeItem("box_phones");
  2688. $rootScope.phoneNumListBind = [];
  2689. $rootScope.phoneNumList.forEach((item) => {
  2690. item.checked = false;
  2691. });
  2692. WebsocketPhoneService.closeWs(true);
  2693. }
  2694. }
  2695. // ------------------------------4盒子--------------------------end
  2696. $rootScope.jry_state = 'weiqianru';
  2697. window.addEventListener('load', function () {
  2698. $rootScope.judgeHjzx(false, true);
  2699. })
  2700. //话机呼叫中心--结束
  2701. // 未接来电
  2702. $scope.jry_getUnanswered = function () {
  2703. var jry_data = {
  2704. idx: 0,
  2705. sum: 999,
  2706. "callRecord": {
  2707. "todayTime": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 00:00:00",
  2708. "todayTimeEnd": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 23:59:59",
  2709. }
  2710. }
  2711. api_bpm_data.fetchDataList("callRecord", jry_data).then(function (data) {
  2712. // fo0h
  2713. for (var i = 0; i < data.list.length; i++) {
  2714. 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()
  2715. }
  2716. $rootScope.jry_unansweredData = data.list;
  2717. });
  2718. }
  2719. // $scope.jry_getUnanswered();
  2720. // 来电号码回拨
  2721. $scope.jry_callBack = function (data) {
  2722. var callBackData = {
  2723. "callRecord": {
  2724. "id": data.id,
  2725. "isAnswered": "1"
  2726. }
  2727. };
  2728. api_bpm_data.updData("callRecord", callBackData).then(function (res) {
  2729. if (res) {
  2730. $scope.jry_getUnanswered();
  2731. dial(data.callerIdNumber)
  2732. }
  2733. });
  2734. if (data.department.id && data.requester) {
  2735. 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 } }
  2736. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2737. } else if (data.department.id) {
  2738. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2739. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2740. } else {
  2741. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2742. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2743. };
  2744. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  2745. }
  2746. //来电号码生成事件
  2747. $scope.jry_callToIncident = function (data) {
  2748. if (data.department.id && data.requester) {
  2749. 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 } }
  2750. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2751. } else if (data.department.id) {
  2752. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  2753. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2754. } else {
  2755. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  2756. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  2757. }
  2758. }
  2759. $scope.onChangeadd = function (searchData) {
  2760. $scope.searchKey = searchData.account;
  2761. // $scope.searchDataadd = searchData;
  2762. var requesdata = angular.copy(searchData)
  2763. $scope.requester = requesdata;
  2764. }
  2765. $scope.refreshUseradd = function (searchKey) { //主题搜索
  2766. $scope.searchData = searchKey;
  2767. reashdata($scope.searchData);
  2768. }
  2769. $scope.getMydata = function (x) {
  2770. $scope.telephone = JSON.parse(x).phone;
  2771. $scope.searchField = $scope.telephone;
  2772. return $scope.searchField;
  2773. }
  2774. $scope.getMydataone = function (x) {
  2775. $scope.telephone = x;
  2776. $scope.searchField = $scope.telephone;
  2777. }
  2778. $scope.fildata = {
  2779. "idx": 0,
  2780. "sum": 10,
  2781. "flag": -1
  2782. }
  2783. function reashdata(item) {
  2784. if (item && item != "") {
  2785. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  2786. } else {
  2787. delete $scope.fildata.user;
  2788. }
  2789. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  2790. if (data.status == 200) {
  2791. $scope.myData = data.list;
  2792. }
  2793. })
  2794. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  2795. // if (response) {
  2796. // if (response.status = 200) {
  2797. // var myData = response;
  2798. // $scope.myData = myData.list;
  2799. // }
  2800. // }
  2801. // })
  2802. }
  2803. if (window.location && window.location.hash == "#/echart") {
  2804. } else {
  2805. $rootScope.user && reashdata();
  2806. }
  2807. $rootScope.end = function () {
  2808. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  2809. if (data.errno == 0) {
  2810. localStorage.removeItem('hk_phone');
  2811. api_text.exit($rootScope.takes).then(function (data) {
  2812. if (data.errno == 0) {
  2813. $rootScope.statuscall = 0;
  2814. $scope.login = false;
  2815. // SweetAlert.swal({
  2816. // title: "登出成功",
  2817. // text: "呼叫中心登出成功!",
  2818. // type: "success"
  2819. // });
  2820. // }else{SweetAlert.swal({
  2821. // title: "登出失败",
  2822. // text: "呼叫中心登出失败!",
  2823. // type: "error"
  2824. // });
  2825. }
  2826. })
  2827. }
  2828. })
  2829. }
  2830. $rootScope.dialout = function (gid, teleno) {
  2831. var telephone = "";
  2832. if (teleno && teleno.length > 4) {
  2833. telephone = '9' + teleno;
  2834. } else {
  2835. // telephone = '*01' + teleno + '*';
  2836. telephone = teleno;
  2837. }
  2838. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  2839. if (data.errno == 0) {
  2840. // $rootScope.statuscall = 3;
  2841. $rootScope.callout = true;
  2842. // $rootScope.phone=teleno;
  2843. }
  2844. })
  2845. }
  2846. // $scope.busy=false;
  2847. $rootScope.setbusy = function () {
  2848. api_text.setbusy($rootScope.takes).then(function (data) {
  2849. if (data.errno == 0) {
  2850. $rootScope.statecall = 2;
  2851. $scope.busy = true;
  2852. }
  2853. })
  2854. }
  2855. $rootScope.setidle = function () {
  2856. api_text.setidle($rootScope.takes).then(function (data) {
  2857. if (data.errno == 0) {
  2858. $rootScope.statecall = 1;
  2859. $scope.busy = false;
  2860. }
  2861. })
  2862. }
  2863. $rootScope.inittrans = function (telephone) {
  2864. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  2865. if (data.errno == 0) {
  2866. // $scope.status=9
  2867. }
  2868. })
  2869. }
  2870. $rootScope.comptrans = function () {
  2871. api_text.comptrans($rootScope.takes).then(function (data) {
  2872. if (data.errno == 0) {
  2873. $rootScope.statuscall = 1;
  2874. }
  2875. })
  2876. }
  2877. $rootScope.takeup = function () {
  2878. api_text.offhook($rootScope.takes).then(function (data) {
  2879. if (data.errno == 0) {
  2880. $rootScope.statuscall = 3;
  2881. }
  2882. })
  2883. }
  2884. $rootScope.takedown = function () {
  2885. api_text.onhook($rootScope.takes).then(function (data) {
  2886. if (data.errno == 0) {
  2887. $rootScope.statuscall = 1;
  2888. }
  2889. })
  2890. }
  2891. $rootScope.saveData = function (selectdata) {
  2892. var modalInstance = $modal.open({
  2893. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  2894. controller: function ($scope, $modalInstance, api_bpm_data) {
  2895. $scope.worktimedata = {};
  2896. $scope.worktimedata = selectdata;
  2897. $scope.cancel = function () {
  2898. $modalInstance.dismiss('cancel');
  2899. };
  2900. $scope.savercode = function (worktimedata) {
  2901. var fildata = {
  2902. "scheduleclass": {
  2903. "id": selectdata.id,
  2904. "code": worktimedata.code,
  2905. "name": worktimedata.title,
  2906. "person": worktimedata.person,
  2907. "description": worktimedata.description,
  2908. "startTime": worktimedata.startTime,
  2909. "endTime": worktimedata.endTime,
  2910. "shiftTime": selectdata.shiftTime,
  2911. "succeedTime": selectdata.succeedTime,
  2912. "isTemplate": worktimedata.isTemplate
  2913. }
  2914. }
  2915. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  2916. if (response) {
  2917. if (response.status == 200) {
  2918. SweetAlert.swal({
  2919. title: "修改成功!",
  2920. type: "success"
  2921. }, function () {
  2922. // $scope.refreshData('expand-right', defaultFilterData);
  2923. })
  2924. } else {
  2925. SweetAlert.swal({
  2926. title: "修改失败!",
  2927. type: "error"
  2928. })
  2929. }
  2930. }
  2931. })
  2932. $modalInstance.close();
  2933. }
  2934. }
  2935. });
  2936. }
  2937. $rootScope.changepassword = function (data1, size) {
  2938. var modalInstance = $modal.open({
  2939. templateUrl: 'assets/views/changepassword.html',
  2940. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  2941. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  2942. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  2943. }
  2944. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  2945. $modalInstance.dismiss('cancel');
  2946. // console.log('pwd=' + pwd + '+' + pwd_2);
  2947. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  2948. if (pwd == pwd_2) {
  2949. var data2 = {};
  2950. data2["originalPwd"] = originalPwd;
  2951. data2["userid"] = $rootScope.user.id;
  2952. data2["pwd"] = pwd;
  2953. api_login.uppwd(data2).then(function (response) {
  2954. var myData = Restangular.stripRestangular(response);
  2955. if (myData.status == 200) {
  2956. SweetAlert.swal({
  2957. title: "保存成功!",
  2958. type: "success",
  2959. confirmButtonColor: "#007AFF"
  2960. });
  2961. } else {
  2962. SweetAlert.swal({
  2963. title: "保存失败!",
  2964. text: "输入旧密码错误,请重新输入!",
  2965. type: "error"
  2966. });
  2967. }
  2968. })
  2969. } else {
  2970. SweetAlert.swal({
  2971. title: "两次输入的新密码不相同!",
  2972. text: "输入错误,请重新输入!",
  2973. type: "error"
  2974. });
  2975. }
  2976. // }else{
  2977. // SweetAlert.swal({
  2978. // title: "密码不能为空!",
  2979. // text: "请输入密码!",
  2980. // type: "error"
  2981. // });
  2982. // }
  2983. }
  2984. },
  2985. size: size,
  2986. resolve: {
  2987. items: function () {
  2988. return {
  2989. fetchItems: function (filterData, APIService) { }
  2990. };
  2991. },
  2992. }
  2993. });
  2994. }
  2995. // 修改院区科室
  2996. $rootScope.intervalTime = sessionStorage.getItem('intervalTime')?JSON.parse(sessionStorage.getItem('intervalTime')):{
  2997. flag: false,
  2998. rotationInterval: 10,
  2999. rotationIntervals: [3, 5, 10, 15, 20, 25, 30, 35, 40, 45],
  3000. logTimeConst: 60,
  3001. logTimeConsts: [30, 60, 90, 120, 150, 180, 210, 240, 270, 300],
  3002. }
  3003. $rootScope.changeHospitalDept = function (flag = false) {
  3004. $rootScope.intervalTime.flag = flag;
  3005. var modalInstance = $modal.open({
  3006. templateUrl: 'assets/views/changeHospitalDept.html',
  3007. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  3008. console.log($rootScope.user.duty)
  3009. $scope.f = {
  3010. uuid:''
  3011. };
  3012. $scope.dataList = {};
  3013. // $scope.dataList = [];
  3014. // $scope.hospitalAndDutyDept = {};
  3015. // $scope.dutyDeptList = [];
  3016. // $scope.branchObj = {};
  3017. // $scope.f = {
  3018. // hospitalDepartment:$rootScope.user.duty?$rootScope.user.duty:''
  3019. // };
  3020. // // 获取所属的院区科室
  3021. // var dutyDepts = [];//责任科室
  3022. // var branchs = [];//院区
  3023. // $rootScope.user.role.forEach(v=>{
  3024. // dutyDepts = dutyDepts.concat(v.dutyDepts);
  3025. // branchs = branchs.concat(v.branchs);
  3026. // })
  3027. // // 责任科室除重
  3028. // var obj = {};
  3029. // dutyDepts = dutyDepts.reduce(function(item, next) {
  3030. // obj[next.id] ? '' : obj[next.id] = true && item.push(next);
  3031. // return item;
  3032. // }, []);
  3033. // $scope.dutyDeptList = dutyDepts;
  3034. // // 院区除重
  3035. // var obj1 = {};
  3036. // branchs = branchs.reduce(function(item, next) {
  3037. // obj1[next.id] ? '' : obj1[next.id] = true && item.push(next);
  3038. // return item;
  3039. // }, []);
  3040. // // $scope.branchs = branchs;
  3041. // // 院区数据处理
  3042. // $scope.branchObj = angular.copy(branchs).find(v=>v.children.length>0);
  3043. // $scope.branchObj.children.sort((a,b)=>a.id-b.id);
  3044. // // 处理责任科室数据
  3045. // $scope.hospitalAndDutyDept = {};
  3046. // $scope.dutyDeptList.forEach(v=>{
  3047. // if($scope.hospitalAndDutyDept[v.branch]){
  3048. // $scope.hospitalAndDutyDept[v.branch].push(v);
  3049. // }else{
  3050. // $scope.hospitalAndDutyDept[v.branch] = [v];
  3051. // }
  3052. // })
  3053. // console.log(dutyDepts,branchs)
  3054. // ----------------------------------------------
  3055. // api_category.branchDutyList({ "userId": $rootScope.user.id }).then(function(response) {
  3056. // if(response.status == 200){
  3057. // $scope.dataList = response.data;
  3058. // $scope.branchObj = response.data.find(v=>!v.parent);
  3059. // $scope.otherBranchs = response.data.filter(v=>v.parent);
  3060. // if($rootScope.user.duty){
  3061. // $scope.f.uuid = $rootScope.user.duty.uuid;
  3062. // }else if($rootScope.user.branch){
  3063. // $scope.f.uuid = $rootScope.user.branch.uuid;
  3064. // }
  3065. // }else{
  3066. // SweetAlert.swal({
  3067. // title: "系统错误!",
  3068. // text: "请刷新重试!",
  3069. // type: "error"
  3070. // });
  3071. // }
  3072. // })
  3073. // ------------------------------------------------------------------------------
  3074. $scope.hospitalAndDutyDept = {};
  3075. $scope.dutyDeptList = [];
  3076. $scope.branchObj = {};
  3077. api_category.branchDutyList({ "userId": $rootScope.user.id }).then(function(response1) {
  3078. if(response1.status == 200){
  3079. $scope.dataList = angular.copy(response1.data);
  3080. if(!$scope.dataList.branchs){
  3081. $scope.dataList.branchs = [];
  3082. }
  3083. if(!$scope.dataList.dutys){
  3084. $scope.dataList.dutys = [];
  3085. }
  3086. var roleObj = response1.data;
  3087. api_user_data.fetchDataList('branch', { "idx": 0, "sum": 1000 }).then(function(res) {
  3088. if (res.status == 200) {
  3089. api_user_data.fetchDataList('dutyDepartment', { "idx": 0, "sum": 1000 }).then(function(response) {
  3090. if (response.status == 200) {
  3091. // 院区数据处理
  3092. $scope.branchObj = angular.copy(res.list).find(v=>v.children.length>0);
  3093. $scope.branchObj.children.sort((a,b)=>a.id-b.id);
  3094. // 清空
  3095. response.list.forEach(v=>{
  3096. v.flag = false
  3097. });
  3098. $scope.dutyDeptList = response.list;
  3099. $scope.branchObj.flag = false;
  3100. $scope.branchObj.children.forEach(v=>{
  3101. v.flag = false;
  3102. })
  3103. // 回显数据接口数据
  3104. if(roleObj){
  3105. roleObj.dutys.forEach(v=>{
  3106. $scope.dutyDeptList.forEach(vv=>{
  3107. if(v.id == vv.id){
  3108. vv.flag = true;
  3109. }
  3110. })
  3111. })
  3112. roleObj.branchs.forEach(v=>{
  3113. if(v.id == $scope.branchObj.id){
  3114. $scope.branchObj.flag = true;
  3115. }
  3116. $scope.branchObj.children.forEach(vv=>{
  3117. if(v.id == vv.id){
  3118. vv.flag = true;
  3119. }
  3120. })
  3121. })
  3122. }
  3123. // 回显当前所属院区或责任科室
  3124. if($rootScope.user.duty){
  3125. $scope.f.uuid = $rootScope.user.duty.uuid;
  3126. }else if($rootScope.user.branch){
  3127. $scope.f.uuid = $rootScope.user.branch.uuid;
  3128. }
  3129. // 处理责任科室数据
  3130. $scope.hospitalAndDutyDept = {};
  3131. $scope.dutyDeptList.forEach(v=>{
  3132. if($scope.hospitalAndDutyDept[v.branch]){
  3133. $scope.hospitalAndDutyDept[v.branch].push(v);
  3134. }else{
  3135. $scope.hospitalAndDutyDept[v.branch] = [v];
  3136. }
  3137. })
  3138. console.log($scope.branchObj,$scope.hospitalAndDutyDept)
  3139. } else {
  3140. SweetAlert.swal({
  3141. title: "系统错误!",
  3142. text: "请刷新重试!",
  3143. type: "error"
  3144. });
  3145. }
  3146. });
  3147. } else {
  3148. SweetAlert.swal({
  3149. title: "系统错误!",
  3150. text: "请刷新重试!",
  3151. type: "error"
  3152. });
  3153. }
  3154. });
  3155. }else{
  3156. SweetAlert.swal({
  3157. title: "系统错误!",
  3158. text: "请刷新重试!",
  3159. type: "error"
  3160. });
  3161. }
  3162. })
  3163. // -----------------------------------
  3164. $scope.saveDept = function () {
  3165. if(! $scope.f.uuid){
  3166. SweetAlert.swal({
  3167. title: "保存失败!",
  3168. text: "请选择院区科室!",
  3169. type: "error"
  3170. });
  3171. return;
  3172. }
  3173. $modalInstance.dismiss('cancel');
  3174. var data2 = {};
  3175. var branchObj = $scope.dataList.branchs.find(v=>v.uuid == $scope.f.uuid);//查找院区的uuid
  3176. if(branchObj){
  3177. data2.branchId = branchObj.id;
  3178. }else{
  3179. var dutyObj = $scope.dataList.dutys.find(v=>v.uuid == $scope.f.uuid);//查询责任科室的uuid
  3180. if(dutyObj){
  3181. data2.dutyId = dutyObj.id;
  3182. }
  3183. }
  3184. // 当前所属院区或责任科室
  3185. if($rootScope.user.duty){
  3186. if(data2.dutyId && data2.dutyId == $rootScope.user.duty.id){
  3187. sessionStorage.setItem('intervalTime', JSON.stringify($rootScope.intervalTime))
  3188. return;
  3189. }
  3190. }else if($rootScope.user.branch){
  3191. if(data2.branchId && data2.branchId == $rootScope.user.branch.id){
  3192. sessionStorage.setItem('intervalTime', JSON.stringify($rootScope.intervalTime))
  3193. return;
  3194. }
  3195. }
  3196. $rootScope.isMask = true;
  3197. api_login.changeBranch(data2).then(function (response) {
  3198. $rootScope.isMask = false;
  3199. var myData = Restangular.stripRestangular(response);
  3200. if (myData.status == 200) {
  3201. var jry_user = JSON.parse(localStorage.getItem('jry_user'));
  3202. myData.user.user.menu = jry_user.menu;
  3203. // jry_user.user = myData.user;
  3204. // console.log(jry_user,myData.user)
  3205. localStorage.setItem('jry_user',JSON.stringify(myData.user.user));
  3206. sessionStorage.setItem('intervalTime', JSON.stringify($rootScope.intervalTime));
  3207. localStorage.removeItem('phones');
  3208. localStorage.removeItem('box_phones');
  3209. SweetAlert.swal({
  3210. title: "切换成功!",
  3211. type: "success",
  3212. confirmButtonColor: "#007AFF"
  3213. },function(){
  3214. location.reload(true);
  3215. });
  3216. } else {
  3217. SweetAlert.swal({
  3218. title: "切换失败!",
  3219. type: "error"
  3220. });
  3221. }
  3222. }).catch(function(err){
  3223. $rootScope.isMask = false;
  3224. SweetAlert.swal({
  3225. title: "切换失败!",
  3226. type: "error"
  3227. });
  3228. })
  3229. }
  3230. $scope.cancel = function() {
  3231. $modalInstance.dismiss('cancel');
  3232. };
  3233. },
  3234. resolve: {
  3235. items: function () {
  3236. return {
  3237. fetchItems: function (filterData, APIService) { }
  3238. };
  3239. },
  3240. }
  3241. });
  3242. }
  3243. // $rootScope.getnochildpending = function() {
  3244. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  3245. // angular.forEach($rootScope.userMenus, function(item) {
  3246. // item.tipnum = 1;
  3247. // })
  3248. // }
  3249. // }
  3250. // $rootScope.getchildpending = function(cantdata) {
  3251. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  3252. // angular.forEach($rootScope.userMenus, function(item) {
  3253. // item.tipnum = 1;
  3254. // angular.forEach(item, function(index) {
  3255. // index.tipnum = 18;
  3256. // })
  3257. // })
  3258. // }
  3259. // }
  3260. $rootScope.getpending = function () {
  3261. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  3262. if ($rootScope.user.group) {
  3263. var groupArr = [];
  3264. for (var i = 0; i < $rootScope.user.group.length; i++) {
  3265. groupArr.push($rootScope.user.group[i].id)
  3266. }
  3267. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  3268. angular.forEach($rootScope.userMenus, function (item, i) {
  3269. item.tipshow = false;
  3270. if (response) {
  3271. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  3272. if (item.id == 58) {
  3273. item.tipshow = true;
  3274. }
  3275. }
  3276. if (response.inspectionCount > 0) {
  3277. if (item.id == 27) {
  3278. item.tipshow = true;
  3279. }
  3280. }
  3281. if (response.incidentCount > 0) {
  3282. if (item.id == 2) {
  3283. item.tipshow = true;
  3284. }
  3285. }
  3286. if (response.releaseCount > 0) {
  3287. if (item.id == 1215) {
  3288. item.tipshow = true;
  3289. }
  3290. }
  3291. if (response.solutionCount > 0) {
  3292. if (item.id == 21) {
  3293. item.tipshow = true;
  3294. }
  3295. }
  3296. if (response.changeCount > 0) {
  3297. if (item.id == 1212) {
  3298. item.tipshow = true;
  3299. }
  3300. }
  3301. if (response.problemCount > 0) {
  3302. if (item.id == 1209) {
  3303. item.tipshow = true;
  3304. }
  3305. }
  3306. if (response.applicationForm > 0) {
  3307. if (item.id == 1221) {
  3308. item.tipshow = true;
  3309. }
  3310. }
  3311. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  3312. if (item.id == 21) {
  3313. item.tipshow = true;
  3314. }
  3315. }
  3316. if (item.children) {
  3317. angular.forEach(item.children, function (index) {
  3318. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  3319. if (index.id == 1208) {
  3320. if (response.hjzxCount < 100) {
  3321. index.tipnum = response.hjzxCount;
  3322. } else {
  3323. index.tipnum = "99+";
  3324. }
  3325. }
  3326. }
  3327. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  3328. if (index.id == 59) {
  3329. if (response.wechatWarningCount < 100) {
  3330. index.tipnum = response.wechatWarningCount;
  3331. } else {
  3332. index.tipnum = "99+";
  3333. }
  3334. }
  3335. }
  3336. if (response.problemCount !== null && response.problemCount !== undefined) {
  3337. if (index.id == 1210) {
  3338. if (response.problemCount < 100) {
  3339. index.tipnum = response.problemCount;
  3340. } else {
  3341. index.tipnum = "99+";
  3342. }
  3343. }
  3344. }
  3345. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  3346. if (index.id == 1216) {
  3347. if (response.releaseCount < 100) {
  3348. index.tipnum = response.releaseCount;
  3349. } else {
  3350. index.tipnum = "99+";
  3351. }
  3352. }
  3353. }
  3354. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  3355. if (index.id == 147) {
  3356. if (response.inspectionCount < 100) {
  3357. index.tipnum = response.inspectionCount;
  3358. } else {
  3359. index.tipnum = "99+";
  3360. }
  3361. }
  3362. }
  3363. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  3364. if (index.id == 23) {
  3365. if (response.solutionCount < 100) {
  3366. index.tipnum = response.solutionCount;
  3367. } else {
  3368. index.tipnum = "99+";
  3369. }
  3370. }
  3371. }
  3372. if (response.changeCount !== null && response.changeCount !== undefined) {
  3373. if (index.id == 1213) {
  3374. if (response.changeCount < 100) {
  3375. index.tipnum = response.changeCount;
  3376. } else {
  3377. index.tipnum = "99+";
  3378. }
  3379. }
  3380. }
  3381. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  3382. if (index.id == 3) {
  3383. if (response.incidentCount < 100) {
  3384. index.tipnum = response.incidentCount;
  3385. } else {
  3386. index.tipnum = "99+";
  3387. }
  3388. }
  3389. }
  3390. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  3391. if (index.id == 1231) {
  3392. if (response.applicationForm < 100) {
  3393. index.tipnum = response.applicationForm;
  3394. } else {
  3395. index.tipnum = "99+";
  3396. }
  3397. }
  3398. }
  3399. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  3400. if (index.id == 23) {
  3401. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  3402. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  3403. } else {
  3404. index.tipnum = "99+";
  3405. }
  3406. }
  3407. }
  3408. })
  3409. }
  3410. }
  3411. })
  3412. // return $rootScope.userMenus;
  3413. // $scope.recordpending = response.;
  3414. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  3415. })
  3416. } else {
  3417. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  3418. }
  3419. }
  3420. // console.log($rootScope.userMenus);
  3421. }
  3422. $rootScope.userMenus = [];
  3423. var getMenus = function () {
  3424. function convertListToTree(data, treeMap) {
  3425. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  3426. var root = null; //Initially set our loop to null
  3427. var parentNode = null;
  3428. //loop over data
  3429. for (var i = 0; i < data.length; i++) {
  3430. // data[i].id = Number(data[i].id);
  3431. var datum = data[i];
  3432. //each node will have children, so let's give it a "children" poperty
  3433. datum.children = [];
  3434. //add an entry for this node to the map so that any future children can
  3435. //lookup the parent
  3436. idToNodeMap[datum.id] = datum;
  3437. //Does this node have a parent?
  3438. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  3439. //Doesn't look like it, so this node is the root of the tree
  3440. root = datum;
  3441. treeMap[datum.id] = root;
  3442. } else {
  3443. //This node has a parent, so let's look it up using the id
  3444. parentNode = idToNodeMap[datum.parentid];
  3445. //We don't need this property, so let's delete it.
  3446. //delete datum.parentid;
  3447. //Let's add the current node as a child of the parent node.
  3448. parentNode.children.push(datum);
  3449. }
  3450. }
  3451. return root;
  3452. }
  3453. function convertParentToChildList(data) {
  3454. var treeMap = {};
  3455. var list = [];
  3456. convertListToTree(data, treeMap);
  3457. angular.forEach(treeMap, function (item) {
  3458. list.push(item);
  3459. });
  3460. list = window._.sortBy(list, function (o) {
  3461. return o.orders;
  3462. });
  3463. return list;
  3464. }
  3465. //if(userMenus.length==0){
  3466. var userMenus = [];
  3467. var idMapMenu = {};
  3468. if ($rootScope.user) {
  3469. if ($rootScope.user.menu) {
  3470. var allJurisdiction2 = $rootScope.user.menu;
  3471. var onlyMenu2 = [];
  3472. for (var i = 0; i < allJurisdiction2.length; i++) {
  3473. if (allJurisdiction2[i].event == "1") {
  3474. onlyMenu2.push(allJurisdiction2[i])
  3475. }
  3476. }
  3477. // userMenus = convertParentToChildList($rootScope.user.menu);
  3478. userMenus = convertParentToChildList(onlyMenu2);
  3479. }
  3480. }
  3481. //}
  3482. $rootScope.userMenus = userMenus;
  3483. if ($rootScope.userMenus.length > 0) {
  3484. $rootScope.getpending();
  3485. // setInterval($rootScope.getpending(), 30000);
  3486. }
  3487. return userMenus;
  3488. }
  3489. setInterval(function () {
  3490. if ($rootScope.userMenus.length > 0) {
  3491. $rootScope.getpending()
  3492. $rootScope.getMsgNum($rootScope.user.id)
  3493. }
  3494. }, 10000);
  3495. getMenus();
  3496. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  3497. $rootScope.logout = function () {
  3498. // var userid =data.id;
  3499. // console.log(' userid='+JSON.stringify( userid));
  3500. //单点登录
  3501. if (localStorage.getItem('isSSo') === '1') {
  3502. sessionStorage.clear();
  3503. localStorage.clear();
  3504. location.href = 'http://' + location.hostname + ':8080/pc_logout.jsp'
  3505. } else {
  3506. $auth.signOut()
  3507. .then(function (resp) {
  3508. // $auth.deleteData('auth_headers')
  3509. sessionStorage.clear();
  3510. localStorage.clear();
  3511. console.log($rootScope.isHk,'hk');
  3512. console.log($rootScope.isZncd,'zncd');
  3513. console.log($rootScope.isXy,'xy');
  3514. console.log($rootScope.isXyBox,'isXyBox');
  3515. if($rootScope.isZncd || $rootScope.isXy){
  3516. if ($rootScope.isFuwutai) {
  3517. tlwsa.tlaClose();
  3518. $.toaster({
  3519. priority: 'info',
  3520. title: '操作',
  3521. message: '呼叫中心断开连接'
  3522. });
  3523. }
  3524. }else if($rootScope.isXyBox){
  3525. if ($rootScope.isFuwutai) {
  3526. WebsocketPhoneService.closeWs(true);
  3527. }
  3528. }
  3529. $state.go("login.signin");
  3530. })
  3531. .catch(function (resp) { });
  3532. }
  3533. //$cookieStore.remove("userObm");
  3534. //$cookieStore.remove("menuObm");
  3535. //$cookieStore.remove("session");
  3536. //$rootScope.user = undefined;
  3537. //$rootScope.menus = undefined;
  3538. //$rootScope.nickname = undefined;
  3539. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  3540. // //logout: function(noServerLogout){
  3541. // window.sessionStorage.clear();
  3542. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  3543. // //},
  3544. }
  3545. // 首页统计跳转
  3546. $scope.goTo = function(url,data){
  3547. $state.go(url,data);
  3548. }
  3549. //获取首页建单统计信息
  3550. $rootScope.getOrderCount = function(){
  3551. // api_bpm_data.getManagerIndexInfo({}).then(function(result) {
  3552. // $scope.managerIndexInfo = result.data;
  3553. // });
  3554. var postData = {}
  3555. // 根据权限查询
  3556. if($rootScope.user.duty){
  3557. // 当前的所属责任科室
  3558. postData.dutyId = $rootScope.user.duty.id;
  3559. }else if($rootScope.user.branch){
  3560. // 当前的所属院区
  3561. postData.branchId = $rootScope.user.branch.id;
  3562. }
  3563. api_newreport.fetchDataListIndex('dutyOrderCount', postData).then(function(data) {
  3564. if (data.status == 200) {
  3565. $scope.managerIndexInfo = {
  3566. createOrders: data.today,
  3567. waitOrders: data.receiving,
  3568. doingOrders: data.doing,
  3569. doneOrders: data.complete,
  3570. }
  3571. }
  3572. })
  3573. }
  3574. // $rootScope.getOrderCount();
  3575. // 快速建单
  3576. $rootScope.newOrder = function (model1, type = '') {
  3577. $rootScope.newOrderShowOpen = true;
  3578. //进入弹窗,强制示忙
  3579. if (localStorage.getItem('fenjiNumber')) {
  3580. setTimeout(()=>{
  3581. tlwsa.tlaAcw();
  3582. },0)
  3583. }
  3584. $modal.open({
  3585. backdrop: false,
  3586. templateUrl:
  3587. "assets/views/newOrderSeimin.html",
  3588. controller: function (
  3589. $scope,
  3590. $parse,
  3591. fileReader,
  3592. FileUploader,
  3593. $modalInstance,
  3594. SweetAlert,
  3595. api_user_data,
  3596. api_bpm_domain,
  3597. up_down_file,
  3598. $rootScope,
  3599. modelData
  3600. ) {
  3601. // -------------------start----------------------
  3602. $scope.modelData = modelData;
  3603. // 当前所属院区处理
  3604. console.log(modelData);
  3605. // if(modelData){
  3606. // var curentHospital = undefined;
  3607. // api_bpm_data.fetchData('department', modelData.incident.department.id).then(res=>{
  3608. // if(res.status == 200){
  3609. // console.log(res.data);
  3610. // curentHospital = {id:1,hosName:'同济医院-主院区'}
  3611. // }
  3612. // })
  3613. // }else{
  3614. // var curentHospital = $rootScope.user.duty?{id:$rootScope.user.duty.branch,hosName:$rootScope.user.duty.branchName}:$rootScope.user.branch;
  3615. // }
  3616. if(modelData){
  3617. var curentHospital = {};
  3618. }else{
  3619. var curentHospital = $rootScope.user.duty?{id:$rootScope.user.duty.branch,hosName:$rootScope.user.duty.branchName}:$rootScope.user.branch;
  3620. }
  3621. // 是否连续建单
  3622. $scope.isBuildOrderAgagin = false;
  3623. //事件列表数据存储
  3624. $scope.incidentModel = {
  3625. department: "", //报修科室
  3626. requester: "", //报修人
  3627. contacts: "", //联系人
  3628. contactsInformation: "", //联系电话
  3629. branch: curentHospital, //院区
  3630. area: "", //区域
  3631. place: "", //地点
  3632. address: "", //详细地址
  3633. priority: "", //优先级
  3634. description: "", //故障描述
  3635. source: {id:1547,name:'电话'}, //事件来源
  3636. yyTime: null, //预约报修时间
  3637. assign: 1, //派单人或组
  3638. user: "", //处理人
  3639. group: "", //处理组
  3640. };
  3641. console.log(modelData)
  3642. if(modelData){
  3643. //报修生成事件,数据回显
  3644. //来电生成事件,数据回显
  3645. $scope.categorySelect = modelData.incident.category;
  3646. $scope.jry_modelLeft = modelData.incident.category?modelData.incident.category.mutiCategory:'';
  3647. console.log($scope.jry_deptData)
  3648. $scope.incidentModel = {
  3649. department: modelData.incident.department, //报修科室
  3650. requester: "", //报修人
  3651. contacts: modelData.incident.contacts, //联系人
  3652. contactsInformation: modelData.incident.contactsInformation, //联系电话
  3653. branch: curentHospital, //院区
  3654. area: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.area : "") : modelData.incident.area, //区域
  3655. place: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.place : "") : modelData.incident.place, //地点
  3656. address: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.address : "") : modelData.incident.houseNumber, //详细地址
  3657. priority: modelData.incident.priority, //优先级
  3658. description: modelData.incident.description, //故障描述
  3659. source: modelData.incident.source, //事件来源
  3660. yyTime: null, //预约报修时间
  3661. assign: 1, //派单人或组
  3662. user: "", //处理人
  3663. group: "", //处理组
  3664. callID: modelData.incident.sockid || undefined, //callID
  3665. incomingPhone: modelData.incident.incomingPhone || undefined, //来电电话
  3666. };
  3667. }
  3668. $scope.minYYtime = new Date();
  3669. // 建单并派单
  3670. $scope.buildAndAssign = function(){
  3671. if(!$scope.categorySelectId){
  3672. SweetAlert.swal({
  3673. title: "提示",
  3674. text: "请选择故障现象!",
  3675. type: "error",
  3676. confirmButtonColor: "#DD6B55"
  3677. });
  3678. return;
  3679. }
  3680. if(!$scope.selectedDuty){
  3681. SweetAlert.swal({
  3682. title: "提示",
  3683. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  3684. type: "error",
  3685. confirmButtonColor: "#DD6B55"
  3686. });
  3687. return;
  3688. }
  3689. if(!$scope.incidentModel.department){
  3690. SweetAlert.swal({
  3691. title: "提示",
  3692. text: "请选择报修科室!",
  3693. type: "error",
  3694. confirmButtonColor: "#DD6B55"
  3695. });
  3696. return;
  3697. }
  3698. if(!$scope.incidentModel.contactsInformation){
  3699. SweetAlert.swal({
  3700. title: "提示",
  3701. text: "请填写联系电话!",
  3702. type: "error",
  3703. confirmButtonColor: "#DD6B55"
  3704. });
  3705. return;
  3706. }
  3707. if(!$scope.incidentModel.priority){
  3708. SweetAlert.swal({
  3709. title: "提示",
  3710. text: "请选择优先级!",
  3711. type: "error",
  3712. confirmButtonColor: "#DD6B55"
  3713. });
  3714. return;
  3715. }
  3716. if(!$scope.incidentModel.description){
  3717. SweetAlert.swal({
  3718. title: "提示",
  3719. text: "请选择故障描述!",
  3720. type: "error",
  3721. confirmButtonColor: "#DD6B55"
  3722. });
  3723. return;
  3724. }
  3725. if($scope.incidentModel.assign == 0){
  3726. SweetAlert.swal({
  3727. title: "提示",
  3728. text: "请选择派单给人或组!",
  3729. type: "error",
  3730. confirmButtonColor: "#DD6B55"
  3731. });
  3732. return;
  3733. }
  3734. if($scope.incidentModel.assign == 1 && !$scope.incidentModel.user){
  3735. SweetAlert.swal({
  3736. title: "提示",
  3737. text: "请选择处理人!",
  3738. type: "error",
  3739. confirmButtonColor: "#DD6B55"
  3740. });
  3741. return;
  3742. }
  3743. if($scope.incidentModel.assign == 2 && !$scope.incidentModel.group){
  3744. SweetAlert.swal({
  3745. title: "提示",
  3746. text: "请选择处理组!",
  3747. type: "error",
  3748. confirmButtonColor: "#DD6B55"
  3749. });
  3750. return;
  3751. }
  3752. $rootScope.isMask = true;
  3753. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  3754. // var postData = {
  3755. // "loginUser": $rootScope.user,
  3756. // "incident": {
  3757. // "deleteFlag": 0,
  3758. // "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3759. // "department": $scope.incidentModel.department||undefined,
  3760. // "contactsInformation": $scope.incidentModel.contactsInformation,
  3761. // "contacts": $scope.incidentModel.contacts,
  3762. // "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3763. // "area": $scope.incidentModel.area||undefined,
  3764. // "place": $scope.incidentModel.place||undefined,
  3765. // "houseNumber": $scope.incidentModel.address,
  3766. // "category": $scope.categorySelect||undefined,
  3767. // "priority": $scope.incidentModel.priority||undefined,
  3768. // "source": $scope.incidentModel.source||undefined,
  3769. // "title": $scope.categorySelect.category,
  3770. // "description": $scope.incidentModel.description,
  3771. // "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3772. // "repairType": repair_main?repair_main.valueconfig:undefined,
  3773. // "requester":$scope.incidentModel.requester||undefined,
  3774. // "acceptUser": $rootScope.user||undefined,
  3775. // "callID": $scope.incidentModel.callID||undefined,
  3776. // "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3777. // },
  3778. // "start_code": "assignment",
  3779. // "initUser": $rootScope.user.id
  3780. // };
  3781. var postData = {
  3782. "incident": {
  3783. "deleteFlag": 0,
  3784. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3785. "department": $scope.incidentModel.department||undefined,
  3786. "contactsInformation": $scope.incidentModel.contactsInformation,
  3787. "contacts": $scope.incidentModel.contacts,
  3788. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3789. "area": $scope.incidentModel.area||undefined,
  3790. "place": $scope.incidentModel.place||undefined,
  3791. "houseNumber": $scope.incidentModel.address,
  3792. "category": $scope.categorySelect||undefined,
  3793. "priority": $scope.incidentModel.priority||undefined,
  3794. "source": $scope.incidentModel.source||undefined,
  3795. "title": $scope.categorySelect.category,
  3796. "description": $scope.incidentModel.description,
  3797. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3798. "repairType": repair_main?repair_main.valueconfig:undefined,
  3799. "requester":$scope.incidentModel.requester||undefined,
  3800. "acceptUser": $rootScope.user||undefined,
  3801. "callID": $scope.incidentModel.callID||undefined,
  3802. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3803. }
  3804. };
  3805. // if(modelData){
  3806. // // 微信报修转事件
  3807. // postData.flow = modelData.flow;
  3808. // }
  3809. if($scope.incidentModel.assign == 1){
  3810. postData.incident.assignee = $scope.incidentModel.user.id;
  3811. }else if($scope.incidentModel.assign == 2){
  3812. postData.incident.candidateGroups = $scope.incidentModel.group.id;
  3813. }
  3814. api_bpm_domain.workernumber('sj').then(res1=>{
  3815. postData.incident.incidentsign = res1.data;
  3816. api_flow.accept("accept", postData).then(function (response) {
  3817. if ($scope.uploader != null) {
  3818. // 有图片
  3819. $scope.uploader.onBeforeUploadItem = function(item) {
  3820. angular.extend(item.headers, $rootScope.getSession());
  3821. item.url = api_bpm_domain.uploadAttachment(response.id).getRequestedUrl();
  3822. item.formData.push({ 'fileName': item.file.name });
  3823. };
  3824. $scope.uploader.uploadAll();
  3825. }
  3826. $rootScope.isMask = false;
  3827. SweetAlert.swal(
  3828. {
  3829. title: "保存成功!",
  3830. type: "success",
  3831. confirmButtonColor: "#007AFF",
  3832. },
  3833. function (isConfirm) {
  3834. if(isConfirm){
  3835. // 是否连续建单
  3836. if($scope.isBuildOrderAgagin){
  3837. $scope.categorySelect = "";
  3838. $scope.categorySelectId = 0;
  3839. $scope.incidentModel.assign = 1;
  3840. $scope.incidentModel.user = "";
  3841. $scope.incidentModel.group = "";
  3842. }else{
  3843. if (localStorage.getItem('fenjiNumber')) {
  3844. $rootScope.jry_shixian();
  3845. }
  3846. $modalInstance.dismiss("cancel");
  3847. }
  3848. $rootScope.newOrderShowOpen = false;
  3849. if($state.current.name === 'app.incident.list'){
  3850. $state.reload();
  3851. }else{
  3852. $state.go("app.incident.list");
  3853. }
  3854. }
  3855. }
  3856. );
  3857. });
  3858. })
  3859. }
  3860. // 暂存
  3861. $scope.temporaryStorage = function(){
  3862. $rootScope.isMask = true;
  3863. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  3864. var postData = {
  3865. "incident": {
  3866. "deleteFlag": 0,
  3867. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3868. "department": $scope.incidentModel.department||undefined,
  3869. "contactsInformation": $scope.incidentModel.contactsInformation,
  3870. "contacts": $scope.incidentModel.contacts,
  3871. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3872. "area": $scope.incidentModel.area||undefined,
  3873. "place": $scope.incidentModel.place||undefined,
  3874. "houseNumber": $scope.incidentModel.address,
  3875. "category": $scope.categorySelect||undefined,
  3876. "priority": $scope.incidentModel.priority||undefined,
  3877. "source": $scope.incidentModel.source||undefined,
  3878. "title": $scope.categorySelect.category,
  3879. "description": $scope.incidentModel.description,
  3880. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3881. "repairType": repair_main?repair_main.valueconfig:undefined,
  3882. "requester":$scope.incidentModel.requester||undefined,
  3883. "acceptUser": $rootScope.user||undefined,
  3884. "callID": $scope.incidentModel.callID||undefined,
  3885. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3886. }
  3887. };
  3888. // if(modelData){
  3889. // // 微信报修转事件
  3890. // postData.flow = modelData.flow;
  3891. // }
  3892. if($scope.incidentModel.assign == 1){
  3893. postData.incident.assignee = $scope.incidentModel ? $scope.incidentModel.user.id : undefined;
  3894. }else if($scope.incidentModel.assign == 2){
  3895. postData.incident.candidateGroups = $scope.incidentModel ? $scope.incidentModel.group.id : undefined;
  3896. }
  3897. api_bpm_domain.workernumber('sj').then(res1=>{
  3898. postData.incident.incidentsign = res1.data;
  3899. api_flow.accept("storage", postData).then(function (response) {
  3900. if ($scope.uploader != null) {
  3901. // 有图片
  3902. $scope.uploader.onBeforeUploadItem = function(item) {
  3903. angular.extend(item.headers, $rootScope.getSession());
  3904. item.url = api_bpm_domain.uploadAttachment(response.id).getRequestedUrl();
  3905. item.formData.push({ 'fileName': item.file.name });
  3906. };
  3907. $scope.uploader.uploadAll();
  3908. }
  3909. $rootScope.isMask = false;
  3910. SweetAlert.swal(
  3911. {
  3912. title: "保存成功!",
  3913. type: "success",
  3914. confirmButtonColor: "#007AFF",
  3915. },
  3916. function (isConfirm) {
  3917. if(isConfirm){
  3918. // 是否连续建单
  3919. if($scope.isBuildOrderAgagin){
  3920. $scope.categorySelect = "";
  3921. $scope.categorySelectId = 0;
  3922. $scope.incidentModel.assign = 1;
  3923. $scope.incidentModel.user = "";
  3924. $scope.incidentModel.group = "";
  3925. }else{
  3926. if (localStorage.getItem('fenjiNumber')) {
  3927. $rootScope.jry_shixian();
  3928. }
  3929. $modalInstance.dismiss("cancel");
  3930. }
  3931. $rootScope.newOrderShowOpen = false;
  3932. if($state.current.name === 'app.incident.list'){
  3933. $state.reload();
  3934. }else{
  3935. $state.go("app.incident.list");
  3936. }
  3937. }
  3938. }
  3939. );
  3940. });
  3941. })
  3942. }
  3943. // 展开/收起
  3944. $scope.showId = "";
  3945. $scope.ifshow = false;
  3946. $scope.showAll = function (id) {
  3947. $scope.attachments = [];
  3948. if ($scope.showId == id) {
  3949. $scope.ifshow = !$scope.ifshow;
  3950. } else {
  3951. $scope.ifshow = true;
  3952. }
  3953. $scope.showId = id;
  3954. // 获取附件
  3955. api_wechatfile
  3956. .listAttachments("knowledge", $scope.showId)
  3957. .then(function (data) {
  3958. $scope.attachments = data.data;
  3959. $scope.download = function (token, filename) {
  3960. var downUrl = up_down_file
  3961. .downloadAttachment("common/common/downloadAttachment", token)
  3962. .getRequestedUrl();
  3963. var a = document.createElement("a");
  3964. a.href = downUrl;
  3965. a.target = "_blank";
  3966. a.download = filename;
  3967. document.body.appendChild(a);
  3968. a.click();
  3969. };
  3970. });
  3971. };
  3972. // 回显处理人或组
  3973. $scope.showUserOrGroup = function(){
  3974. if($scope.incidentModel.department && $scope.categorySelect && $scope.selectedDuty && $scope.incidentModel.branch){
  3975. var postData = {
  3976. idx: 0,
  3977. sum: 10,
  3978. incidentAssignManager: {
  3979. deptId:$scope.incidentModel.department.id,
  3980. categoryId:$scope.categorySelect.id,
  3981. branch:$scope.incidentModel.branch.id,
  3982. dutyId: $scope.selectedDuty.id
  3983. },
  3984. };
  3985. api_user_data.fetchDataList("incidentAssignManager", postData).then(function(result){
  3986. if(result.status == 200){
  3987. var deptBinduserConfig = result.list?result.list[0]:null;//获取第一条配置
  3988. if(deptBinduserConfig){
  3989. // 如果有科室绑定人员的配置
  3990. if(deptBinduserConfig.userOrGroupType == 1){
  3991. // 派单给人
  3992. $scope.incidentModel.assign = 1;
  3993. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == deptBinduserConfig.handleUser);
  3994. }else if(deptBinduserConfig.userOrGroupType == 2){
  3995. // 派单给组
  3996. $scope.incidentModel.assign = 2;
  3997. $scope.incidentModel.group = $scope.jry_groupData.find(v=>v.id == deptBinduserConfig.group);
  3998. }
  3999. }else{
  4000. // 没有查询到科室绑定人员的配置,则根据院区,普通科室,责任科室查询
  4001. var postData = {
  4002. idx: 0,
  4003. sum: 10,
  4004. incidentAssignManager: {
  4005. deptId:$scope.incidentModel.department.id,
  4006. branch:$scope.incidentModel.branch.id,
  4007. dutyId: $scope.selectedDuty.id
  4008. },
  4009. };
  4010. api_user_data.fetchDataList("incidentAssignManager", postData).then(function(result){
  4011. if(result.status == 200){
  4012. //获取配置
  4013. var deptBinduserConfig = result.list || [];
  4014. // 过滤掉有故障现象的配置
  4015. deptBinduserConfig = deptBinduserConfig.filter(v => !v.categoryId);
  4016. // 获取第一条配置
  4017. deptBinduserConfig = deptBinduserConfig[0] || null;
  4018. if(deptBinduserConfig){
  4019. // 如果有科室绑定人员的配置
  4020. if(deptBinduserConfig.userOrGroupType == 1){
  4021. // 派单给人
  4022. $scope.incidentModel.assign = 1;
  4023. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == deptBinduserConfig.handleUser);
  4024. }else if(deptBinduserConfig.userOrGroupType == 2){
  4025. // 派单给组
  4026. $scope.incidentModel.assign = 2;
  4027. $scope.incidentModel.group = $scope.jry_groupData.find(v=>v.id == deptBinduserConfig.group);
  4028. }
  4029. }else{
  4030. if($scope.categorySelect){
  4031. // 选择了故障现象
  4032. assignCommon($scope.categorySelect);
  4033. }
  4034. }
  4035. }
  4036. })
  4037. }
  4038. }
  4039. })
  4040. }else if($scope.categorySelect){
  4041. // 选择了故障现象
  4042. assignCommon($scope.categorySelect);
  4043. }
  4044. }
  4045. // 直接解决
  4046. $scope.build = function(){
  4047. if(!$scope.categorySelectId){
  4048. SweetAlert.swal({
  4049. title: "提示",
  4050. text: "请选择故障现象!",
  4051. type: "error",
  4052. confirmButtonColor: "#DD6B55"
  4053. });
  4054. return;
  4055. }
  4056. if(!$scope.selectedDuty){
  4057. SweetAlert.swal({
  4058. title: "提示",
  4059. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  4060. type: "error",
  4061. confirmButtonColor: "#DD6B55"
  4062. });
  4063. return;
  4064. }
  4065. if(!$scope.incidentModel.department){
  4066. SweetAlert.swal({
  4067. title: "提示",
  4068. text: "请选择报修科室!",
  4069. type: "error",
  4070. confirmButtonColor: "#DD6B55"
  4071. });
  4072. return;
  4073. }
  4074. if(!$scope.incidentModel.contactsInformation){
  4075. SweetAlert.swal({
  4076. title: "提示",
  4077. text: "请填写联系电话!",
  4078. type: "error",
  4079. confirmButtonColor: "#DD6B55"
  4080. });
  4081. return;
  4082. }
  4083. if(!$scope.incidentModel.priority){
  4084. SweetAlert.swal({
  4085. title: "提示",
  4086. text: "请选择优先级!",
  4087. type: "error",
  4088. confirmButtonColor: "#DD6B55"
  4089. });
  4090. return;
  4091. }
  4092. if(!$scope.incidentModel.description){
  4093. SweetAlert.swal({
  4094. title: "提示",
  4095. text: "请选择故障描述!",
  4096. type: "error",
  4097. confirmButtonColor: "#DD6B55"
  4098. });
  4099. return;
  4100. }
  4101. $modal.open({
  4102. templateUrl: "assets/views/newOrderDirectly.html",
  4103. controller: function ($scope,scope,$state, $modalInstance, SweetAlert,api_bpm) {
  4104. $scope.categorySelect = scope.categorySelect;
  4105. console.log($scope.categorySelect)
  4106. $scope.incidentModel = {
  4107. handlerMsg:'',//处理方案
  4108. closecode:'',//关闭代码
  4109. };
  4110. // 关闭代码
  4111. $scope.closecodeArray = [];
  4112. $scope.jry_closecodeSearch = function () {
  4113. api_wechatfile
  4114. .getDictionary({ type: "list", key: "incident_closecode" })
  4115. .then(function (data) {
  4116. $scope.closecodeArray = data;
  4117. });
  4118. };
  4119. $scope.jry_closecodeSearch();
  4120. // 确定
  4121. $scope.ok = function () {
  4122. if($scope.categorySelect.hasSimple != 1 && !$scope.incidentModel.handlerMsg){
  4123. SweetAlert.swal({
  4124. title: "提示",
  4125. text: "请填写处理方案!",
  4126. type: "error",
  4127. confirmButtonColor: "#DD6B55"
  4128. });
  4129. return;
  4130. }
  4131. if(!$scope.incidentModel.closecode.id){
  4132. SweetAlert.swal({
  4133. title: "提示",
  4134. text: "请选择关闭代码!",
  4135. type: "error",
  4136. confirmButtonColor: "#DD6B55"
  4137. });
  4138. return;
  4139. }
  4140. // -------新建事件,积分机制,直接处理--------
  4141. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4142. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4143. $modal.open({
  4144. templateUrl: 'assets/views/incident/tpl/toIntegralMechanism.tpl.html',
  4145. controller: function ($scope, $modalInstance, incidentData,categorySelect, currentUserId, Alert, api_wechatfile,scope,api_bpm_data) {
  4146. console.log(incidentData,currentUserId,categorySelect);
  4147. $scope.complexityConfirm = {complexity:null,updateReason:''};
  4148. $scope.complexityFn = function(category){
  4149. if(category.complexity){
  4150. return category.complexity.value;
  4151. }else if(category.parent){
  4152. return $scope.complexityFn(category.parent);
  4153. }else{
  4154. return $scope.list[0]?$scope.list[0].value:1;
  4155. }
  4156. }
  4157. $scope.list = [];
  4158. api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){
  4159. $scope.list = res;
  4160. if(categorySelect && categorySelect.id){
  4161. api_bpm_data.fetchData("incidentCategory",categorySelect.id).then(function(result){
  4162. if(result.status == 200){
  4163. $scope.complexity = $scope.complexityFn(result.data);
  4164. $scope.complexityConfirm.complexity = $scope.list.find(v=>v.value == $scope.complexity);
  4165. }
  4166. })
  4167. }
  4168. })
  4169. $scope.onChangeComplexity = function(item){
  4170. }
  4171. $scope.ok = function () {
  4172. if (!$scope.complexityConfirm.complexity){
  4173. Alert.swal({
  4174. title: "操作失败",
  4175. text: "请选择工时!",
  4176. type: "error"
  4177. });
  4178. return;
  4179. }
  4180. if ($scope.complexityConfirm.complexity.value != $scope.complexity&&!$scope.complexityConfirm.updateReason.trim()){
  4181. Alert.swal({
  4182. title: "操作失败",
  4183. text: "请填写升级原因!",
  4184. type: "error"
  4185. });
  4186. return;
  4187. }
  4188. $modalInstance.close('success');
  4189. handlerStart();
  4190. scope.complexity = $scope.complexity;
  4191. scope.complexityConfirm = $scope.complexityConfirm;
  4192. // 暂存--后面直接处理后调用积分接口
  4193. }
  4194. $scope.cancel = function () {
  4195. if (localStorage.getItem('fenjiNumber')) {
  4196. $rootScope.jry_shixian();
  4197. }
  4198. $modalInstance.dismiss('cancel');
  4199. }
  4200. },
  4201. size: 'sm',
  4202. resolve: {
  4203. scope: function () {
  4204. return $scope;
  4205. },
  4206. api_bpm: function () {
  4207. return api_bpm;
  4208. },
  4209. incidentData: function () {
  4210. return scope.incidentModel;
  4211. },
  4212. categorySelect: function () {
  4213. return scope.categorySelect;
  4214. },
  4215. currentUserId: function () {
  4216. return $rootScope.user.id;
  4217. },
  4218. Alert: function () {
  4219. return SweetAlert;
  4220. },
  4221. api_user_data: function () {
  4222. return api_user_data;
  4223. },
  4224. api_wechatfile: function () {
  4225. return api_wechatfile;
  4226. }
  4227. }
  4228. });
  4229. }else{
  4230. handlerStart();
  4231. }
  4232. // -------新建事件,积分机制,直接处理--------
  4233. };
  4234. // 直接处理,新建事件
  4235. function handlerStart(){
  4236. $rootScope.isMask = true;
  4237. console.log(scope.incidentModel,$scope.incidentModel);
  4238. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  4239. // var postData = {
  4240. // "loginUser": $rootScope.user||undefined,
  4241. // "incident": {
  4242. // "deleteFlag": 0,
  4243. // "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4244. // "requester":$scope.incidentModel.requester||undefined,
  4245. // "alarmType": false,
  4246. // "department": scope.incidentModel.department||undefined,
  4247. // "contactsInformation": scope.incidentModel.contactsInformation,
  4248. // "contacts": scope.incidentModel.contacts,
  4249. // "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4250. // "area": scope.incidentModel.area||undefined,
  4251. // "place": scope.incidentModel.place||undefined,
  4252. // "houseNumber": scope.incidentModel.address,
  4253. // "category": scope.categorySelect||undefined,
  4254. // "priority": scope.incidentModel.priority||undefined,
  4255. // "source": scope.incidentModel.source||undefined,
  4256. // "title": scope.categorySelect.category,
  4257. // "description": scope.incidentModel.description,
  4258. // "directProcess": 1,
  4259. // "handleDescription": $scope.incidentModel.handlerMsg,
  4260. // "handlingPersonnelUser":{id:$rootScope.user.id},
  4261. // "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4262. // "closecode": $scope.incidentModel.closecode||undefined,
  4263. // "repairType": repair_main?repair_main.valueconfig:undefined,
  4264. // "acceptUser": $rootScope.user||undefined,
  4265. // "callID": scope.incidentModel.callID||undefined,
  4266. // "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  4267. // },
  4268. // "start_code": "close",
  4269. // "handler_code": "resolve",
  4270. // "initUser": $rootScope.user.id,
  4271. // "isSolution": false
  4272. // };
  4273. var postData = {
  4274. "incident": {
  4275. "deleteFlag": 0,
  4276. "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4277. "requester":$scope.incidentModel.requester||undefined,
  4278. "alarmType": false,
  4279. "department": scope.incidentModel.department||undefined,
  4280. "contactsInformation": scope.incidentModel.contactsInformation,
  4281. "contacts": scope.incidentModel.contacts,
  4282. "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4283. "area": scope.incidentModel.area||undefined,
  4284. "place": scope.incidentModel.place||undefined,
  4285. "houseNumber": scope.incidentModel.address,
  4286. "category": scope.categorySelect||undefined,
  4287. "priority": scope.incidentModel.priority||undefined,
  4288. "source": scope.incidentModel.source||undefined,
  4289. "title": scope.categorySelect.category,
  4290. "description": scope.incidentModel.description,
  4291. "directProcess": 1,
  4292. "handleDescription": $scope.incidentModel.handlerMsg,
  4293. "handlingPersonnelUser":{id:$rootScope.user.id},
  4294. "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4295. "closecode": $scope.incidentModel.closecode||undefined,
  4296. "repairType": repair_main?repair_main.valueconfig:undefined,
  4297. "acceptUser": $rootScope.user||undefined,
  4298. "callID": scope.incidentModel.callID||undefined,
  4299. "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  4300. },
  4301. };
  4302. // if(scope.modelData){
  4303. // // 微信报修转事件
  4304. // postData.flow = scope.modelData.flow;
  4305. // }
  4306. api_bpm_domain.workernumber('sj').then(res1=>{
  4307. postData.incident.incidentsign = res1.data;
  4308. api_flow.accept("accept", postData).then(function (resData) {
  4309. if (scope.uploader != null) {
  4310. // 有图片
  4311. scope.uploader.onBeforeUploadItem = function(item) {
  4312. angular.extend(item.headers, $rootScope.getSession());
  4313. item.url = api_bpm_domain.uploadAttachment(resData.id).getRequestedUrl();
  4314. item.formData.push({ 'fileName': item.file.name });
  4315. };
  4316. scope.uploader.uploadAll();
  4317. }
  4318. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4319. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4320. api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
  4321. var auditState = res.find(v=>v.value == 0);
  4322. var postData = {
  4323. incidentIntegral: {
  4324. incidentId:resData.bussId,
  4325. auditState:auditState,
  4326. handlerUser:$rootScope.user.id,
  4327. handlerUserName:$rootScope.user.name,
  4328. sourceScore:$scope.complexity,
  4329. currentScore:$scope.complexityConfirm.complexity.value,
  4330. updateReason:$scope.complexityConfirm.updateReason.trim() || undefined,
  4331. }
  4332. }
  4333. console.log(postData)
  4334. api_bpm_data.addData('incidentIntegral', postData).then(function (response) {
  4335. console.log(response)
  4336. $rootScope.isMask = false;
  4337. if (response.status == 200) {
  4338. SweetAlert.swal(
  4339. {
  4340. title: "保存成功!",
  4341. type: "success",
  4342. confirmButtonColor: "#007AFF",
  4343. },
  4344. function (isConfirm) {
  4345. if(isConfirm){
  4346. $modalInstance.dismiss("cancel");
  4347. // 是否连续建单
  4348. if(scope.isBuildOrderAgagin){
  4349. scope.categorySelect = "";
  4350. scope.categorySelectId = 0;
  4351. scope.incidentModel.assign = 1;
  4352. scope.incidentModel.user = "";
  4353. scope.incidentModel.group = "";
  4354. }else{
  4355. if (localStorage.getItem('fenjiNumber')) {
  4356. $rootScope.jry_shixian();
  4357. }
  4358. scope.cancel();
  4359. }
  4360. $rootScope.newOrderShowOpen = false;
  4361. if($state.current.name === 'app.incident.list'){
  4362. $state.reload();
  4363. }else{
  4364. $state.go("app.incident.list");
  4365. }
  4366. }
  4367. }
  4368. );
  4369. } else {
  4370. Alert.swal({
  4371. title: "操作失败",
  4372. text: "操作失败, 请稍后再试!",
  4373. type: "error"
  4374. });
  4375. }
  4376. });
  4377. })
  4378. }else{
  4379. SweetAlert.swal(
  4380. {
  4381. title: "提交成功!",
  4382. type: "success",
  4383. confirmButtonColor: "#007AFF",
  4384. },
  4385. function (isConfirm) {
  4386. if(isConfirm){
  4387. if (localStorage.getItem('fenjiNumber')) {
  4388. $rootScope.jry_shixian();
  4389. }
  4390. scope.cancel();
  4391. $modalInstance.dismiss("cancel");
  4392. $rootScope.newOrderShowOpen = false;
  4393. if($state.current.name === 'app.incident.list'){
  4394. $state.reload();
  4395. }else{
  4396. $state.go("app.incident.list");
  4397. }
  4398. }
  4399. }
  4400. );
  4401. }
  4402. // -------------------------------------------
  4403. $rootScope.isMask = false;
  4404. SweetAlert.swal(
  4405. {
  4406. title: "保存成功!",
  4407. type: "success",
  4408. confirmButtonColor: "#007AFF",
  4409. },
  4410. function (isConfirm) {
  4411. if(isConfirm){
  4412. $modalInstance.dismiss("cancel");
  4413. // 是否连续建单
  4414. if(scope.isBuildOrderAgagin){
  4415. scope.categorySelect = "";
  4416. scope.categorySelectId = 0;
  4417. scope.incidentModel.assign = 1;
  4418. scope.incidentModel.user = "";
  4419. scope.incidentModel.group = "";
  4420. }else{
  4421. if (localStorage.getItem('fenjiNumber')) {
  4422. $rootScope.jry_shixian();
  4423. }
  4424. scope.cancel();
  4425. }
  4426. $rootScope.newOrderShowOpen = false;
  4427. if($state.current.name === 'app.incident.list'){
  4428. $state.reload();
  4429. }else{
  4430. $state.go("app.incident.list");
  4431. }
  4432. }
  4433. }
  4434. );
  4435. });
  4436. })
  4437. }
  4438. // 取消
  4439. $scope.cancel = function () {
  4440. if (localStorage.getItem('fenjiNumber')) {
  4441. $rootScope.jry_shixian();
  4442. }
  4443. $modalInstance.dismiss("cancel");
  4444. };
  4445. },
  4446. size:'lg',
  4447. resolve: {
  4448. SweetAlert: function () {
  4449. return SweetAlert;
  4450. },
  4451. scope: function(){
  4452. return $scope;
  4453. }
  4454. },
  4455. });
  4456. }
  4457. // 处理顶部责任科室数据
  4458. $scope.handlerDuty = function(){
  4459. if(!$scope.categorySelect){
  4460. return;
  4461. }
  4462. if($scope.categorySelect.branchType == 1){
  4463. // 分院区
  4464. if($scope.incidentModel.branch){
  4465. var dutyConfig = $scope.categorySelect.branchUserGroups.find(v=>v.branchId == $scope.incidentModel.branch.id);
  4466. if(dutyConfig && dutyConfig.dutyId && dutyConfig.dutyName){
  4467. $scope.selectedDuty = {id:dutyConfig.dutyId,dept:dutyConfig.dutyName};
  4468. }else{
  4469. $scope.selectedDuty = null;
  4470. }
  4471. }else{
  4472. $scope.selectedDuty = null;
  4473. }
  4474. }else{
  4475. // 不分院区
  4476. $scope.selectedDuty = $scope.categorySelect.dutyDepartment;
  4477. }
  4478. }
  4479. // 优先级
  4480. $scope.priorityArray = [];
  4481. $scope.jry_prioritySearch = function () {
  4482. api_wechatfile
  4483. .getDictionary({ type: "list", key: "incident_priority" })
  4484. .then(function (data) {
  4485. $scope.priorityArray = data;
  4486. });
  4487. };
  4488. $scope.jry_prioritySearch();
  4489. // 事件来源
  4490. $scope.sourceArray = [];
  4491. $scope.jry_sourceSearch = function () {
  4492. api_wechatfile
  4493. .getDictionary({ type: "list", key: "incident_source" })
  4494. .then(function (data) {
  4495. $scope.sourceArray = data;
  4496. if($scope.incidentModel.source){
  4497. if(!$scope.incidentModel.source.name && $scope.incidentModel.source.id){
  4498. $scope.incidentModel.source = data.find(v=>v.id == $scope.incidentModel.source.id)
  4499. }
  4500. }
  4501. });
  4502. };
  4503. $scope.jry_sourceSearch();
  4504. // 报修科室模糊搜索
  4505. $scope.jry_deptSearch = function (key = "",branchId) {
  4506. console.log(branchId)
  4507. if(!branchId){
  4508. $scope.jry_deptData = [];
  4509. return;
  4510. }
  4511. var deptData = {
  4512. idx: 0,
  4513. sum: 20,
  4514. department: {
  4515. branch:branchId,
  4516. dept:key,
  4517. selectType: "pinyin_qs",
  4518. searchType: "quickStart",
  4519. },
  4520. };
  4521. api_user_data.fetchDataList("department", deptData).then(function (data) {
  4522. $scope.jry_deptData = data.list;
  4523. if($scope.incidentModel.department){
  4524. if(!$scope.incidentModel.department.dept && $scope.incidentModel.department.id){
  4525. // $scope.incidentModel.department = data.list.find(v=>v.id == $scope.incidentModel.department.id)
  4526. api_bpm_data.fetchData('department', $scope.incidentModel.department.id).then(res=>{
  4527. if(res.status == 200){
  4528. $scope.incidentModel.department = res.data;
  4529. }else{
  4530. $scope.incidentModel.department = '';
  4531. }
  4532. })
  4533. }
  4534. }
  4535. });
  4536. };
  4537. // $scope.jry_deptSearch();
  4538. // 报修人模糊搜索
  4539. $scope.jry_requesterSearch = function (key = "") {
  4540. var postData = {
  4541. idx: 0,
  4542. sum: 10,
  4543. requester: {
  4544. searchKey: key,
  4545. },
  4546. };
  4547. api_user_data.fetchDataList("requester", postData).then(function (data) {
  4548. $scope.jry_requesterData = data.list;
  4549. });
  4550. };
  4551. $scope.jry_requesterSearch();
  4552. $scope.$watch("incidentModel.requester", function (newVal,oldVal) {
  4553. if(newVal){
  4554. $scope.incidentModel.contacts = newVal.name;
  4555. SweetAlert.swal({
  4556. title: "提示",
  4557. text: "是否覆盖联系电话?",
  4558. type: "warning",
  4559. showCancelButton: true,
  4560. confirmButtonColor: "#DD6B55",
  4561. confirmButtonText: "确认覆盖",
  4562. cancelButtonText: "取消操作",
  4563. closeOnConfirm: true,
  4564. closeOnCancel: true
  4565. }, function (isConfirm) {
  4566. if (isConfirm) {
  4567. $scope.incidentModel.contactsInformation = newVal.mphone;
  4568. }
  4569. });
  4570. }
  4571. });
  4572. // 处理人模糊搜索
  4573. $scope.jry_userSearch = function (key = "") {
  4574. var userData = {
  4575. idx: 0,
  4576. sum: 1000,
  4577. user: {
  4578. roledata: {rolecode: "first-line support"},
  4579. selectDetails:'1',
  4580. simple:true,
  4581. name: key,
  4582. selectType: "pinyin_qs",
  4583. engineer: 1,
  4584. },
  4585. };
  4586. api_user_data.fetchDataList("user", userData).then(function (data) {
  4587. $scope.jry_userData = data.list;
  4588. if($scope.incidentModel.user){
  4589. if(!$scope.incidentModel.user.userTaskCount){
  4590. $scope.incidentModel.user = data.list.find(v=>v.id == $scope.incidentModel.user.id);
  4591. }
  4592. }
  4593. });
  4594. };
  4595. $scope.jry_userSearch();
  4596. // 处理组模糊搜索
  4597. $scope.jry_groupSearch = function (key = "") {
  4598. var groupData = {
  4599. idx: 0,
  4600. sum: 1000,
  4601. group: {
  4602. selectType: "nouser"
  4603. },
  4604. };
  4605. api_user_data.fetchDataList("group", groupData).then(function (data) {
  4606. $scope.jry_groupData = data.list;
  4607. });
  4608. };
  4609. $scope.jry_groupSearch();
  4610. // 院区模糊搜索
  4611. $scope.jry_branchSearch = function (key = "") {
  4612. var postData = {
  4613. idx: 0,
  4614. sum: 1000
  4615. };
  4616. api_user_data.fetchDataList("branch", postData).then(function (data) {
  4617. $scope.jry_branchData = data.list;
  4618. if(modelData && modelData.incident && modelData.incident.department){
  4619. api_bpm_data.fetchData('department', modelData.incident.department.id).then(res=>{
  4620. if(res.status == 200){
  4621. $scope.incidentModel.branch = $scope.jry_branchData.find(v=>v.id == res.data.branch);
  4622. }
  4623. })
  4624. }
  4625. });
  4626. };
  4627. $scope.jry_branchSearch();
  4628. // 区域模糊搜索
  4629. $scope.jry_areaSearch = function (key='',branchId) {
  4630. if(!branchId){
  4631. $scope.jry_areaData = [];
  4632. return;
  4633. }
  4634. var areaData = {
  4635. idx: 0,
  4636. sum: 30,
  4637. area: {
  4638. branch:branchId,
  4639. area:key,
  4640. selectType:'pinyin_qs'
  4641. },
  4642. };
  4643. api_user_data.fetchDataList("area", areaData).then(function (data) {
  4644. $scope.jry_areaData = data.list;
  4645. });
  4646. };
  4647. // 地点模糊搜索
  4648. $scope.jry_placeSearch = function (key='',areaId) {
  4649. if(!areaId){
  4650. $scope.jry_placeData = [];
  4651. return;
  4652. }
  4653. var placeData = {
  4654. idx: 0,
  4655. sum: 30,
  4656. place: {
  4657. place: key,
  4658. areaId: areaId,
  4659. selectType:'pinyin_qs'
  4660. },
  4661. };
  4662. api_user_data.fetchDataList("place", placeData).then(function (data) {
  4663. $scope.jry_placeData = data.list;
  4664. });
  4665. };
  4666. $scope.changeBranch = function(){
  4667. $scope.incidentModel.area = '';
  4668. $scope.incidentModel.place = '';
  4669. $scope.incidentModel.department = '';
  4670. $scope.jry_placeData = [];
  4671. }
  4672. $scope.changeArea = function(){
  4673. $scope.incidentModel.place = '';
  4674. }
  4675. $scope.$watch("incidentModel.branch", function (newVal,oldVal) {
  4676. $scope.showUserOrGroup();
  4677. newVal && $scope.jry_areaSearch('',newVal.id);
  4678. newVal && $scope.jry_deptSearch('',newVal.id);
  4679. $scope.handlerDuty();
  4680. });
  4681. $scope.$watch("incidentModel.area", function (newVal,oldVal) {
  4682. newVal && $scope.jry_placeSearch('',newVal.id);
  4683. console.log(modelData, $scope.oldDept,$scope.incidentModel)
  4684. });
  4685. $scope.$watch("categorySelect", function (newVal,oldVal) {
  4686. if(newVal&&newVal.priority){
  4687. // 回显优先级
  4688. $scope.incidentModel.priority = newVal.priority;
  4689. }
  4690. // 选择了院区,科室,故障现象,责任科室
  4691. $scope.showUserOrGroup();
  4692. // 回显人员
  4693. if($scope.incidentModel.user){
  4694. if(!$scope.incidentModel.user.userTaskCount){
  4695. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == $scope.incidentModel.user.id);
  4696. }
  4697. }
  4698. });
  4699. // 派人或派组
  4700. function assignCommon(sj){
  4701. console.log(sj);
  4702. if(!sj){return;}
  4703. if (sj.branchType == 0) {
  4704. if (sj.userOrGroupType === 1) {
  4705. //派人
  4706. $scope.incidentModel.assign = 1;
  4707. $scope.incidentModel.user = sj.handleUser ? $scope.jry_userData.find(v=>v.id == sj.handleUser.id) : "";
  4708. } else if (sj.userOrGroupType === 2) {
  4709. //派组
  4710. $scope.incidentModel.assign = 2;
  4711. $scope.incidentModel.group = sj.group ? sj.group : "";
  4712. } else {
  4713. $scope.incidentModel.assign = 0;
  4714. $scope.incidentModel.user = "";
  4715. $scope.incidentModel.group = "";
  4716. }
  4717. } else if (sj.branchType == 1) {
  4718. // 分院区
  4719. // 选择了院区
  4720. if ($scope.incidentModel.branch) {
  4721. let branchId = $scope.incidentModel.branch.id;
  4722. let branchUserGroup =
  4723. sj.branchUserGroups.find(v => v.branchId == branchId) || {};
  4724. if (branchUserGroup.branchUserOrGroupType == 1) {
  4725. //派人
  4726. $scope.incidentModel.assign = 1;
  4727. console.log($scope.jry_userData)
  4728. $scope.incidentModel.user = branchUserGroup.userId
  4729. ? $scope.jry_userData.find(v=>v.id == branchUserGroup.userId)
  4730. : "";
  4731. } else if (branchUserGroup.branchUserOrGroupType === 2) {
  4732. //派组
  4733. $scope.incidentModel.assign = 2;
  4734. $scope.incidentModel.group = branchUserGroup.groupId
  4735. ? {id:branchUserGroup.groupId,groupName:branchUserGroup.groupName}
  4736. : "";
  4737. } else {
  4738. $scope.incidentModel.assign = 1;
  4739. $scope.incidentModel.user = "";
  4740. $scope.incidentModel.group = "";
  4741. }
  4742. } else {
  4743. $scope.incidentModel.assign = 1;
  4744. $scope.incidentModel.user = "";
  4745. $scope.incidentModel.group = "";
  4746. }
  4747. }
  4748. }
  4749. // 取消故障描述弹窗
  4750. $scope.isShowAlertMask = false;
  4751. $scope.copyItem = null;
  4752. $scope.cancelAlertMask = function(){
  4753. $scope.isShowAlertMask = false;
  4754. }
  4755. // 覆盖
  4756. $scope.overlayAlertMask = function(){
  4757. $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  4758. $scope.isShowAlertMask = false;
  4759. }
  4760. // 前覆盖
  4761. $scope.overlayLeftAlertMask = function(){
  4762. $scope.incidentModel.description = $scope.copyItem.mutiCategory + $scope.incidentModel.description;
  4763. $scope.isShowAlertMask = false;
  4764. }
  4765. // 后覆盖
  4766. $scope.overlayRightAlertMask = function(){
  4767. $scope.incidentModel.description = $scope.incidentModel.description + $scope.copyItem.mutiCategory;
  4768. $scope.isShowAlertMask = false;
  4769. }
  4770. // 故障现象选中
  4771. $scope.categorySelectId = 0;
  4772. $scope.categorySelect = "";
  4773. $scope.selectedDuty = null;//选择故障现象后的责任科室
  4774. $scope.changeCategorySelect = function(item){
  4775. $scope.copyItem = angular.copy(item);
  4776. $scope.copyItem.mutiCategory = $scope.copyItem.mutiCategory.replace(/<[^<>]+>/g,'');
  4777. if($scope.incidentModel.description){
  4778. $scope.isShowAlertMask = true;
  4779. // SweetAlert.swal({
  4780. // title: "提示",
  4781. // text: "是否覆盖故障描述?",
  4782. // type: "warning",
  4783. // showCancelButton: true,
  4784. // confirmButtonColor: "#DD6B55",
  4785. // confirmButtonText: "确认覆盖",
  4786. // cancelButtonText: "取消操作",
  4787. // closeOnConfirm: true,
  4788. // closeOnCancel: true
  4789. // }, function (isConfirm) {
  4790. // if (isConfirm) {
  4791. // $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  4792. // }
  4793. // });
  4794. }else{
  4795. $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  4796. }
  4797. $scope.categorySelect = $scope.copyItem;
  4798. $scope.categorySelectId = $scope.copyItem.id;
  4799. // 处理责任科室数据
  4800. $scope.handlerDuty();
  4801. if($scope.selectTab == 2){
  4802. $scope.jry_solution($scope.categorySelect.id);
  4803. }
  4804. }
  4805. // 故障现象查询
  4806. $scope.c_timer = null;
  4807. $scope.c_keyword = '';
  4808. $scope.jry_categorySearch = function (key = '') {
  4809. $scope.c_keyword = key;
  4810. clearTimeout($scope.c_timer);
  4811. $scope.c_timer = setTimeout(()=>{
  4812. var categoryData = {
  4813. idx: 0,
  4814. sum: 9999,
  4815. incidentcategory: {
  4816. category: key,
  4817. selectType:'pinyin_qs',
  4818. hierarchyQuery:'three'
  4819. },
  4820. };
  4821. if($rootScope.user.duty){
  4822. categoryData.incidentcategory.dutyDepartment = $rootScope.user.duty;
  4823. }else if($rootScope.user.branch){
  4824. // categoryData.incidentcategory.branch = $rootScope.user.branch.id;
  4825. }
  4826. $scope.loading_c = true;
  4827. api_user_data.fetchDataList("incidentcategory", categoryData).then(function (data) {
  4828. if($scope.c_keyword == key){
  4829. $scope.loading_c = false;
  4830. data.list.forEach(v=>{
  4831. if(v.mutiCategory){
  4832. v.mutiCategory = v.mutiCategory.replace($scope.jry_modelLeft,'<span class="colorRed">'+$scope.jry_modelLeft+'</span>');
  4833. }
  4834. })
  4835. $scope.jry_categoryData = data.list;
  4836. if(modelData){
  4837. if( modelData.incident.category && !modelData.incident.category.complexity){
  4838. $scope.categorySelect = data.list.find(v=>v.id == modelData.incident.category.id);
  4839. if($scope.categorySelect){
  4840. $scope.categorySelectId = $scope.categorySelect.id;
  4841. }
  4842. }
  4843. }
  4844. }
  4845. });
  4846. },500)
  4847. };
  4848. $scope.jry_categorySearch($scope.jry_modelLeft);
  4849. // 右侧tab选中
  4850. $scope.selectTab = 1;
  4851. $scope.changeTab = function(id){
  4852. $scope.selectTab = id;
  4853. if(id == 1){
  4854. $scope.jry_incident($scope.incidentModel.department?$scope.incidentModel.department.id:undefined);
  4855. }else if(id == 2){
  4856. $scope.jry_solution($scope.categorySelect?$scope.categorySelect.id:undefined);
  4857. }
  4858. }
  4859. // 近期报修
  4860. $scope.jry_incident = function (deptId) {
  4861. $scope.loading_i = true;
  4862. var placeData = {
  4863. idx: 0,
  4864. sum: 6,
  4865. incident: {
  4866. department: {id:deptId},
  4867. },
  4868. };
  4869. api_user_data.fetchDataList("incident", placeData).then(function (data) {
  4870. $scope.loading_i = false;
  4871. data.list.forEach(v=>{
  4872. v.acceptDate = moment(v.acceptDate).format('MM-DD HH:mm')
  4873. })
  4874. $scope.jry_incidentData = data.list;
  4875. });
  4876. };
  4877. $scope.$watch("incidentModel.department", function (newVal,oldVal) {
  4878. $scope.showUserOrGroup();
  4879. newVal && $scope.jry_incident(newVal.id);
  4880. console.log(newVal);
  4881. if(newVal){
  4882. api_bpm_data.fetchData('department', $scope.incidentModel.department.id).then(res=>{
  4883. if(res.status == 200){
  4884. // $scope.incidentModel.department = res.data;
  4885. if(res.data && res.data.place){
  4886. $scope.incidentModel.place = res.data.place;
  4887. $scope.incidentModel.area = res.data.place.area;
  4888. }else{
  4889. $scope.incidentModel.place = '';
  4890. $scope.incidentModel.area = '';
  4891. }
  4892. $scope.incidentModel.address = res.data.address || '';
  4893. // 如果回显的有联系电话,联系电话不用科室带出
  4894. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (res.data&&res.data.phone)?res.data.phone.split(',')[0]:'');
  4895. }else{
  4896. $scope.incidentModel.place = '';
  4897. $scope.incidentModel.area = '';
  4898. $scope.incidentModel.address = '';
  4899. // 如果回显的有联系电话,联系电话不用科室带出
  4900. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  4901. }
  4902. })
  4903. }else{
  4904. $scope.incidentModel.place = '';
  4905. $scope.incidentModel.area = '';
  4906. $scope.incidentModel.address = '';
  4907. // 如果回显的有联系电话,联系电话不用科室带出
  4908. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  4909. }
  4910. // if(newVal && newVal.place){
  4911. // $scope.incidentModel.place = newVal.place;
  4912. // $scope.incidentModel.area = newVal.place.area;
  4913. // }else{
  4914. // $scope.incidentModel.place = '';
  4915. // $scope.incidentModel.area = '';
  4916. // }
  4917. // // 如果回显的有联系电话,联系电话不用科室带出
  4918. // !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  4919. });
  4920. // 知识库
  4921. $scope.jry_solution = function (id,key='') {
  4922. $scope.loading_i = true;
  4923. var placeData = {
  4924. idx: 0,
  4925. sum: 1000,
  4926. solution: {
  4927. threeSearch:key,
  4928. status: {id: 72},
  4929. selectType: "keySearch",
  4930. },
  4931. };
  4932. if(id){
  4933. placeData.solution.category = {id:id};
  4934. }
  4935. api_user_data.fetchDataList("solution", placeData).then(function (data) {
  4936. $scope.loading_i = false;
  4937. $scope.jry_solutionData = data.list;
  4938. });
  4939. };
  4940. // getFileFromBase64($scope.imgshows[0],'tt')
  4941. // 图片上传
  4942. $scope.imgshows = [];
  4943. $scope.uploadimgs = [];
  4944. var model = $parse("upload_img");
  4945. var modelSetter = model.assign;
  4946. var uploader = ($scope.uploader = new FileUploader({
  4947. url: "/uploader",
  4948. }));
  4949. // uploader.filters.push({
  4950. // name: "customFilter",
  4951. // fn: function (item /*{File|FileLikeObject}*/, options) {
  4952. // return this.queue.length < 10;
  4953. // },
  4954. // });
  4955. $scope.getDetail = function(imgs){
  4956. function getImageFileFromUrl(url, imageName, callback) {
  4957. // imageName一定要带上后缀
  4958. var blob = null
  4959. var xhr = new XMLHttpRequest()
  4960. xhr.open('GET', url)
  4961. xhr.setRequestHeader('Accept', 'image/jpeg')
  4962. xhr.responseType = 'blob'
  4963. xhr.onload = () => {
  4964. if (xhr.status === 200) {
  4965. blob = xhr.response
  4966. let imgFile = new File([blob], imageName, {type: 'image/jpeg'})
  4967. console.log(imgFile)
  4968. callback.call(this, imgFile)
  4969. }
  4970. }
  4971. xhr.send()
  4972. }
  4973. imgs.forEach((v,i)=>{
  4974. v.previewUrl = $rootScope.attachmentAddressSplicing(v.relativeFilePath);
  4975. getImageFileFromUrl(v.previewUrl,v.name,function(file){
  4976. var dummy = new FileUploader.FileItem(uploader, file);
  4977. uploader.queue.push(dummy);
  4978. getFile(file, $scope);
  4979. })
  4980. })
  4981. //获得预览图地址并且把file对象放入上传合集内
  4982. function getFile(imgupload, $scope) {
  4983. if (!imgupload) {
  4984. return;
  4985. }
  4986. fileReader.readAsDataUrl(imgupload, $scope).then(function (result) {
  4987. console.log(result)
  4988. $scope.imgshows.push(result);
  4989. var file = imgupload;
  4990. $scope.uploadimgs.push(file); //这里是放着传给后台的数据file,下面controller的时候会有
  4991. console.log($scope.imgshows, $scope.uploadimgs);
  4992. if ($scope.imgshows.length < 3) {
  4993. $("#upupgogo").show();
  4994. } else {
  4995. $("#upupgogo").hide();
  4996. }
  4997. });
  4998. }
  4999. }
  5000. // 是否回显报修端图片
  5001. // if(modelData){
  5002. // if (modelData.flow) {
  5003. // api_wechatfile
  5004. // .listAttachment("wechatRequesterIncident", modelData.flow)
  5005. // .then(function (res) {
  5006. // $scope.getDetail(res.data)
  5007. // });
  5008. // }
  5009. // }
  5010. // 添加
  5011. $scope.change = function (event) {
  5012. var element = $(".upinp");
  5013. modelSetter($scope, element[0].files[0]);
  5014. //附件预览
  5015. $scope.imgupload = event.files[0];
  5016. getFile($scope.imgupload, $scope);
  5017. //获得预览图地址并且把file对象放入上传合集内
  5018. function getFile(imgupload, $scope) {
  5019. if (!imgupload) {
  5020. return;
  5021. }
  5022. fileReader.readAsDataUrl(imgupload, $scope).then(function (result) {
  5023. console.log(result)
  5024. $scope.imgshows.push(result);
  5025. var file = document.querySelector("#upupgogo input[type=file]").files[0];
  5026. $scope.uploadimgs.push(file); //这里是放着传给后台的数据file,下面controller的时候会有
  5027. console.log($scope.imgshows, $scope.uploadimgs);
  5028. if ($scope.imgshows.length < 3) {
  5029. $("#upupgogo").show();
  5030. } else {
  5031. $("#upupgogo").hide();
  5032. }
  5033. });
  5034. }
  5035. };
  5036. // 删除
  5037. $scope.uploadimg_del = function (index, imgs) {
  5038. console.log(index, imgs);
  5039. $scope.imgshows.splice(index, 1);
  5040. $scope.uploadimgs.splice(index, 1);
  5041. $scope.uploader.queue.splice(index, 1);
  5042. if ($scope.imgshows.length < 3) {
  5043. $("#upupgogo").show();
  5044. } else {
  5045. $("#upupgogo").hide();
  5046. }
  5047. };
  5048. // 预览
  5049. $scope.preview = function (url, idx) {
  5050. var name = $scope.uploadimgs[idx].name;
  5051. $modal.open({
  5052. backdrop: false,
  5053. templateUrl: "assets/views/customform/tpl/ui-showimage.html",
  5054. controller: function ($scope, scope, $modalInstance) {
  5055. //创建一个标签用来加载图片
  5056. const image = document.createElement("img");
  5057. image.src = url
  5058. //待图片加载完成读取图片的真实宽高。
  5059. image.addEventListener("load", function(e) {
  5060. $scope.imgWidth = e.target.width + 'px';
  5061. $scope.imgHeight = e.target.height + 'px';
  5062. })
  5063. $scope.title = name;
  5064. $scope.imageurl = url;
  5065. $scope.cancel = function () {
  5066. $modalInstance.dismiss("cancel");
  5067. };
  5068. },
  5069. resolve: {
  5070. scope: function () {
  5071. return $scope;
  5072. },
  5073. },
  5074. });
  5075. };
  5076. if (uploader) {
  5077. uploader.onWhenAddingFileFailed = function (
  5078. item /*{File|FileLikeObject}*/,
  5079. filter,
  5080. options
  5081. ) {
  5082. console.info("onWhenAddingFileFailed", item, filter, options);
  5083. };
  5084. uploader.onAfterAddingFile = function (fileItem) {
  5085. console.info("onAfterAddingFile", fileItem);
  5086. };
  5087. uploader.onAfterAddingAll = function (addedFileItems) {
  5088. console.info("onAfterAddingAll", addedFileItems);
  5089. };
  5090. uploader.onBeforeUploadItem = function (item) {
  5091. console.info("onBeforeUploadItem", item);
  5092. };
  5093. uploader.onProgressItem = function (fileItem, progress) {
  5094. console.info("onProgressItem", fileItem, progress);
  5095. };
  5096. uploader.onProgressAll = function (progress) {
  5097. console.info("onProgressAll", progress);
  5098. };
  5099. uploader.onSuccessItem = function (
  5100. fileItem,
  5101. response,
  5102. status,
  5103. headers
  5104. ) {
  5105. console.info("onSuccessItem", fileItem, response, status, headers);
  5106. };
  5107. uploader.onErrorItem = function (
  5108. fileItem,
  5109. response,
  5110. status,
  5111. headers
  5112. ) {
  5113. console.info("onErrorItem", fileItem, response, status, headers);
  5114. };
  5115. uploader.onCancelItem = function (
  5116. fileItem,
  5117. response,
  5118. status,
  5119. headers
  5120. ) {
  5121. console.info("onCancelItem", fileItem, response, status, headers);
  5122. };
  5123. uploader.onCompleteItem = function (
  5124. fileItem,
  5125. response,
  5126. status,
  5127. headers
  5128. ) {
  5129. console.info("onCompleteItem", fileItem, response, status, headers);
  5130. };
  5131. uploader.onCompleteAll = function () {
  5132. console.info("onCompleteAll");
  5133. };
  5134. }
  5135. // 取消
  5136. $scope.cancel = function () {
  5137. if (localStorage.getItem('fenjiNumber')) {
  5138. $rootScope.jry_shixian();
  5139. }
  5140. $rootScope.newOrderShowOpen = false;
  5141. $modalInstance.dismiss("cancel");
  5142. };
  5143. // -------------------end----------------------
  5144. },
  5145. resolve: {
  5146. modelData:function(){
  5147. return model1;
  5148. }
  5149. },
  5150. });
  5151. }
  5152. // 事件实时播报
  5153. $rootScope.realtimeBroadcast = function(){
  5154. location.href = location.origin+'/#/bigScreen/realtimeBroadcast';
  5155. // window.open(location.origin+'/#/bigScreen/realtimeBroadcast');
  5156. }
  5157. // save settings to local storage
  5158. if (angular.isDefined($localStorage.layout)) {
  5159. $scope.app.layout = $localStorage.layout;
  5160. } else {
  5161. $localStorage.layout = $scope.app.layout;
  5162. }
  5163. $scope.$watch('app.layout', function () {
  5164. // save to local storage
  5165. $localStorage.layout = $scope.app.layout;
  5166. }, true);
  5167. //global function to scroll page up
  5168. $scope.toTheTop = function () {
  5169. $document.scrollTopAnimated(0, 600);
  5170. };
  5171. // angular translate
  5172. // ----------------------
  5173. $scope.language = {
  5174. // Handles language dropdown
  5175. listIsOpen: false,
  5176. // list of available languages
  5177. available: {
  5178. 'en': 'English',
  5179. 'it_IT': 'Italiano',
  5180. 'de_DE': 'Deutsch',
  5181. 'zh_cn': 'Chinese'
  5182. },
  5183. // display always the current ui language
  5184. init: function () {
  5185. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  5186. var preferredLanguage = $translate.preferredLanguage();
  5187. // we know we have set a preferred one in app.config
  5188. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  5189. },
  5190. set: function (localeId, ev) {
  5191. $translate.use(localeId);
  5192. $scope.language.selected = $scope.language.available[localeId];
  5193. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  5194. }
  5195. };
  5196. $scope.language.init();
  5197. // Function that find the exact height and width of the viewport in a cross-browser way
  5198. var viewport = function () {
  5199. var e = window,
  5200. a = 'inner';
  5201. if (!('innerWidth' in window)) {
  5202. a = 'client';
  5203. e = document.documentElement || document.body;
  5204. }
  5205. return {
  5206. width: e[a + 'Width'],
  5207. height: e[a + 'Height']
  5208. };
  5209. };
  5210. // function that adds information in a scope of the height and width of the page
  5211. $scope.getWindowDimensions = function () {
  5212. return {
  5213. 'h': viewport().height,
  5214. 'w': viewport().width
  5215. };
  5216. };
  5217. // Detect when window is resized and set some variables
  5218. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  5219. $scope.windowHeight = newValue.h;
  5220. $scope.windowWidth = newValue.w;
  5221. if (newValue.w >= 992) {
  5222. $scope.isLargeDevice = true;
  5223. } else {
  5224. $scope.isLargeDevice = false;
  5225. }
  5226. if (newValue.w < 992) {
  5227. $scope.isSmallDevice = true;
  5228. } else {
  5229. $scope.isSmallDevice = false;
  5230. }
  5231. if (newValue.w <= 768) {
  5232. $scope.isMobileDevice = true;
  5233. } else {
  5234. $scope.isMobileDevice = false;
  5235. }
  5236. }, true);
  5237. // Apply on resize
  5238. $win.on('resize', function () {
  5239. $scope.$apply();
  5240. });
  5241. $rootScope.app.layout.isNavbarFixed = false;
  5242. $rootScope.app.layout.isSidebarFixed = false;
  5243. $rootScope.app.layout.isFooterFixed = false;
  5244. $scope.login_signquick = function (Requesteruserinform) {
  5245. $rootScope.statuscall = 1;
  5246. $scope.loginForm = {
  5247. username: Requesteruserinform.username,
  5248. password: Requesteruserinform.password
  5249. }
  5250. $auth.submitLogin($scope.loginForm)
  5251. .then(function (resp) {
  5252. localStorage.setItem("jry_user", JSON.stringify(resp));
  5253. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  5254. $rootScope.isRealtimeBroadcast = ($rootScope.user && $rootScope.user.menu)?$rootScope.user.menu.some(v => v.link == 'realtimeBroadcast'):false;
  5255. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  5256. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  5257. var onlyMenu = [];
  5258. for (var i = 0; i < allJurisdiction.length; i++) {
  5259. if (allJurisdiction[i].event == "1") {
  5260. onlyMenu.push(allJurisdiction[i])
  5261. }
  5262. };
  5263. $rootScope.userMenus = onlyMenu;
  5264. getMenus();
  5265. if (resp.error != 500) {
  5266. // $state.go('app.dashboard');
  5267. $rootScope.app.isLoginFixed = false;
  5268. } else {
  5269. resp.error = "";
  5270. $scope.loginForm.password = "";
  5271. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  5272. }
  5273. })
  5274. .catch(function (resp) {
  5275. $scope.loginForm.password = "";
  5276. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  5277. });
  5278. }
  5279. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  5280. var theRequest = {};
  5281. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  5282. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  5283. var str = url.substr(index + 1);
  5284. var strs = str.split("&");
  5285. for (var i = 0; i < strs.length; i++) {
  5286. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  5287. }
  5288. // return theRequest;
  5289. $scope.login_signquick(theRequest)
  5290. }
  5291. // $scope.casUserId = window.location.search;
  5292. // $scope.loginForm = {
  5293. // username: theRequest[0].split("=")[1],
  5294. // password: theRequest[1].split("=")[1]
  5295. // }
  5296. // $scope.lodingstyle = 'nodata';
  5297. var userAgent = window.navigator.userAgent.toLowerCase();
  5298. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  5299. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  5300. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  5301. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  5302. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  5303. if (isOpera) {
  5304. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  5305. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  5306. }
  5307. if (isIE) {
  5308. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  5309. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  5310. }
  5311. if (isFF) {
  5312. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  5313. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  5314. }
  5315. if (isSafari) {
  5316. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  5317. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  5318. }
  5319. if (isChrome) {
  5320. // login_sign();
  5321. $rootScope.app.isChrome = false;
  5322. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  5323. } else {
  5324. $rootScope.app.isChrome = true;
  5325. $scope.checkchrome = '';
  5326. // return alert("访问失败,请用Chrome浏览器访问!");
  5327. }
  5328. // }
  5329. // $scope.handleloginEnter = function(e) {
  5330. // if (e.keyCode == 13) {
  5331. // $scope.handleLoginClick();
  5332. // }
  5333. // };
  5334. // if (document.getElementById("isWatch").value == "true") {
  5335. // $scope.isHanderuser = true;
  5336. // } else {
  5337. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  5338. // $scope.isHanderuser = false;
  5339. // $scope.login_sign();
  5340. // }
  5341. // }
  5342. // $scope.viewType = "password";
  5343. // $scope.isPassword = true;
  5344. // $scope.toggleView = function() {
  5345. // $scope.isPassword = !$scope.isPassword;
  5346. // $scope.viewType = $scope.isPassword ? "password" : "text";
  5347. // }
  5348. // $scope.handleSignOutBtnClick = function() {
  5349. // $auth.signOut()
  5350. // .then(function(resp) {
  5351. // // handle success response
  5352. // })
  5353. // .catch(function(resp) {
  5354. // // handle error response
  5355. // });
  5356. // };
  5357. // }
  5358. // }
  5359. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  5360. // } else {
  5361. // $scope.loginstart();
  5362. // }
  5363. //websocket 信息中心
  5364. console.log(atmosphere)
  5365. var socket = atmosphere;
  5366. var subSocket;
  5367. // We are now ready to cut the request
  5368. var request = {
  5369. url: 'ws://192.168.199.150:8080/messagestation/cache',
  5370. contentType: "application/json",
  5371. shared: true, // 标签共享
  5372. trackMessageLength: true, //校验数据完整性
  5373. transport: 'websocket'
  5374. };
  5375. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  5376. request.onOpen = function (response) {
  5377. console.log(response)
  5378. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  5379. // alert("开始连接")
  5380. };
  5381. request.onMessage = function (response) {
  5382. var message = response.responseBody;
  5383. // alert("连接成功")
  5384. console.log(message)
  5385. try {
  5386. var json = JSON.parse(message);
  5387. console.log(json.noRead)
  5388. $scope.noReadData = json.noRead
  5389. } catch (e) {
  5390. console.log('呵呵哒: ', message);
  5391. return;
  5392. }
  5393. };
  5394. request.onClose = function (response) {
  5395. // alert("连接结束")
  5396. }
  5397. request.onError = function (response) {
  5398. // alert('连接失败')
  5399. };
  5400. //信息中心模态框
  5401. var loginUser = $rootScope.user;
  5402. // if(loginUser){
  5403. // // 未读消息数量
  5404. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  5405. // if (data.status == 200) {
  5406. // $scope.noReadData=data.totalNum
  5407. // // $rootScope.option.all = $rootScope.all;
  5408. // } else {
  5409. // $scope.noReadData=0
  5410. // }
  5411. // })
  5412. // }
  5413. // $scope.noReadData=($rootScope.noReadData||0)
  5414. // // $rootScope.all = 5;
  5415. // setTimeout(function() {
  5416. // console.log($scope.noReadData)
  5417. // }, 500)
  5418. $rootScope.wt_messages = function () {
  5419. var modalInstance = $modal.open({
  5420. templateUrl: '../../../assets/views/wt_messages.html',
  5421. controller: function ($scope, $modalInstance, SweetAlert) {
  5422. $rootScope.msgData = {
  5423. idx: 0,
  5424. sum: 5,
  5425. messageStation: {
  5426. readStatus: 0,
  5427. userId: $rootScope.user.id
  5428. }
  5429. }
  5430. // 关闭
  5431. $scope.closeModel = function () {
  5432. modalInstance.close();
  5433. }
  5434. $scope.getMsgData = function () {
  5435. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5436. if (data) {
  5437. $rootScope.msg = data.list
  5438. $rootScope.all = data.pageCount;
  5439. $scope.wt_msgData = data
  5440. $rootScope.noReadData = data.totalNum
  5441. }
  5442. })
  5443. }
  5444. $scope.getMsgData()
  5445. $scope.message_type = 2;
  5446. $scope.message_no = function (type) { //未读1
  5447. $scope.wt_msgData = {};
  5448. $scope.message_type = type;
  5449. $rootScope.msgData.messageStation.readStatus = 0,
  5450. // $rootScope.option.curr = 1;
  5451. $rootScope.msgData.idx = 0;
  5452. // console.log($rootScope.option.curr)
  5453. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5454. $scope.msg_yesType = true;
  5455. if (data.status == 200) {
  5456. $scope.msg_yesType = false
  5457. $scope.wt_msgData = data
  5458. $rootScope.msg = data.list
  5459. $rootScope.all = data.pageCount;
  5460. $rootScope.noReadData = data.totalNum;
  5461. // $rootScope.option.all = $rootScope.all;
  5462. } else {
  5463. $scope.msg_yesType = true;
  5464. }
  5465. })
  5466. }
  5467. $scope.message_yes = function (type) { //已读0
  5468. $scope.wt_msgData = {};
  5469. $scope.message_type = type;
  5470. $rootScope.msgData.messageStation.readStatus = 1,
  5471. $rootScope.msgData.idx = 0;
  5472. // $rootScope.option.curr = 1;
  5473. // console.log($rootScope.option.curr)
  5474. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5475. $scope.msg_noType = true;
  5476. if (data.status == 200) {
  5477. $scope.msg_noType = false
  5478. $scope.wt_msgData = data
  5479. $rootScope.msg = data.list;
  5480. $rootScope.all = data.pageCount;
  5481. // $rootScope.option.all = $rootScope.all;
  5482. } else {
  5483. $scope.msg_noType = true
  5484. }
  5485. })
  5486. };
  5487. $scope.sBtn = function () {
  5488. // console.log($rootScope.msgData)
  5489. // console.log($scope.wt_msgData)
  5490. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  5491. console.log($rootScope.msgData)
  5492. $scope.getMsgData()
  5493. }
  5494. $scope.xBtn = function () {
  5495. // console.log($rootScope.msgData)
  5496. // console.log($scope.wt_msgData)
  5497. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  5498. console.log($rootScope.msgData)
  5499. $scope.getMsgData()
  5500. }
  5501. $scope.redIn = function (data) {
  5502. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  5503. $scope.messageStation = {
  5504. messageStation: {
  5505. id: data.id,
  5506. readStatus: 1,
  5507. readTime: start
  5508. }
  5509. }
  5510. api_msg.updateDataList($scope.messageStation).then(function (data) {
  5511. console.log(data);
  5512. if (data.status == 200) {
  5513. $rootScope.msgData.messageStation.readStatus = 0,
  5514. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5515. $rootScope.msg = data.list
  5516. $rootScope.all = data.pageCount;
  5517. $rootScope.noReadData = data.totalNum;
  5518. })
  5519. }
  5520. })
  5521. };
  5522. // 一键已读
  5523. $scope.redAllIn = function () {
  5524. SweetAlert.swal({
  5525. title: "是否确认?",
  5526. type: "warning",
  5527. showCancelButton: true,
  5528. confirmButtonColor: "#DD6B55",
  5529. confirmButtonText: "确认",
  5530. cancelButtonText: "取消",
  5531. closeOnConfirm: true,
  5532. closeOnCancel: true
  5533. }, function (isConfirm) {
  5534. if (isConfirm) {
  5535. $rootScope.isMask = true;
  5536. api_msg.oneClickRead({userId: $rootScope.user.id}).then(function (data) {
  5537. $rootScope.isMask = false;
  5538. if (data.status == 200) {
  5539. $rootScope.msgData.messageStation.readStatus = 0,
  5540. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5541. $scope.wt_msgData = data
  5542. $rootScope.msg = data.list
  5543. $rootScope.all = data.pageCount;
  5544. $rootScope.noReadData = data.totalNum;
  5545. })
  5546. }
  5547. })
  5548. } else {}
  5549. });
  5550. };
  5551. },
  5552. size: 'lg',
  5553. resolve: {
  5554. }
  5555. })
  5556. }
  5557. }
  5558. ]);
  5559. // 录音盒子
  5560. app.service('WebsocketPhoneService', function () {
  5561. return {
  5562. lockReconnect: false, //避免ws重复连接
  5563. ws: null, //定义websocket
  5564. url: "", //ws连接地址
  5565. urlParams: null, //ws连接传参
  5566. isHandler: false, //是否手动
  5567. subject: null,
  5568. reconnectTimer: null,//重连的计时器
  5569. // 连接websocket
  5570. connectWs(url, data) {
  5571. this.url = url;
  5572. this.urlParams = data;
  5573. this.subject = new rxjs.Subject();
  5574. let request = {
  5575. webSocketUrl: url,
  5576. trackMessageLength: true, //校验数据完整性
  5577. transport: "websocket",
  5578. handleOnlineOffline: false,
  5579. suspend: false,
  5580. maxReconnectOnClose: 0,
  5581. };
  5582. request.onOpen = (response) => {
  5583. console.log("ws连接成功" + new Date().toLocaleString());
  5584. this.heartCheck.reset().start(this);
  5585. console.log(response);
  5586. this.ws.push(JSON.stringify(data));
  5587. };
  5588. request.onMessage = (response) => {
  5589. this.heartCheck.reset().start(this);
  5590. let message = response.responseBody;
  5591. try {
  5592. console.log("收到消息" + message);
  5593. if (message !== "pong") {
  5594. this.subject.next(JSON.parse(message));
  5595. }
  5596. } catch (e) {
  5597. console.log("This doesn't look like a valid JSON: ", message);
  5598. return;
  5599. }
  5600. };
  5601. request.onClose = (response) => {
  5602. console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
  5603. this.ws = null;
  5604. console.log(response)
  5605. if (!this.isHandler && response.status === 408) {
  5606. this.reconnect(this.url, this.urlParams);
  5607. }
  5608. };
  5609. request.onError = (response) => {
  5610. console.log("ws连接错误", this.isHandler);
  5611. this.ws = null;
  5612. if (response.status === 0) {
  5613. this.reconnect(this.url, this.urlParams);
  5614. }
  5615. };
  5616. this.ws = atmosphere.subscribe(request);
  5617. return this.subject.asObservable();
  5618. },
  5619. //断线重连
  5620. reconnect(url, data) {
  5621. if (this.lockReconnect) return;
  5622. this.lockReconnect = true;
  5623. this.reconnectTimer = setTimeout(() => {
  5624. //没连接上会一直重连,设置延迟避免请求过多
  5625. this.connectWs(url, data);
  5626. this.lockReconnect = false;
  5627. }, 15000);
  5628. },
  5629. heartCheck: {
  5630. timeout: 30000, //发一次心跳的间隔时间
  5631. timeoutObj: null,
  5632. serverTimeoutObj: null,
  5633. reset: function () {
  5634. clearTimeout(this.timeoutObj);
  5635. clearTimeout(this.serverTimeoutObj);
  5636. return this;
  5637. },
  5638. start: function (_this) {
  5639. this.timeoutObj = setTimeout(() => {
  5640. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  5641. //onmessage拿到返回的心跳就说明连接正常
  5642. if (_this.ws) {
  5643. _this.ws.push("ping");
  5644. }
  5645. this.serverTimeoutObj = setTimeout(() => {
  5646. //如果超过一定时间还没重置,说明后端主动断开了
  5647. _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  5648. }, this.timeout);
  5649. }, this.timeout);
  5650. },
  5651. },
  5652. // 断开websocket
  5653. closeWs(flag = false) {
  5654. this.isHandler = flag;
  5655. if (flag) {
  5656. clearTimeout(this.reconnectTimer);
  5657. }
  5658. if (this.ws) {
  5659. this.ws.close();
  5660. }
  5661. }
  5662. };
  5663. });
  5664. //消息中心分页组件
  5665. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  5666. $rootScope.option = {
  5667. curr: 1, //当前页数
  5668. all: $rootScope.all, //总页数
  5669. count: 5, //最多显示的页数,默认为10
  5670. //点击页数的回调函数,参数page为点击的页数
  5671. click: function (page) {
  5672. $rootScope.msgData.idx = page - 1;
  5673. //这里可以写跳转到某个页面等...
  5674. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5675. $rootScope.msg = data.list
  5676. $rootScope.all = data.pageCount;
  5677. $rootScope.option.all = $rootScope.all;
  5678. })
  5679. }
  5680. }
  5681. }]);
  5682. app.directive('myPagination', function () {
  5683. return {
  5684. restrict: 'EA',
  5685. replace: true,
  5686. rootScope: {
  5687. option: '=pageOption'
  5688. },
  5689. controller: 'msgCtrl',
  5690. template: '<ul class="pagination">' +
  5691. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  5692. '<a href="javascript:;">{{p}}</a>' +
  5693. '</li>' +
  5694. '</ul>',
  5695. link: function ($rootScope) {
  5696. //容错处理
  5697. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  5698. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  5699. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  5700. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  5701. //得到显示页数的数组
  5702. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  5703. //绑定点击事件
  5704. $rootScope.pageClick = function (page) {
  5705. if (page == '«') {
  5706. page = parseInt($rootScope.option.curr) - 1;
  5707. } else if (page == '»') {
  5708. page = parseInt($rootScope.option.curr) + 1;
  5709. }
  5710. if (page < 1) page = 1;
  5711. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  5712. //点击相同的页数 不执行点击事件
  5713. if (page == $rootScope.option.curr) return;
  5714. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  5715. $rootScope.option.click(page);
  5716. $rootScope.option.curr = page;
  5717. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  5718. }
  5719. };
  5720. //返回页数范围(用来遍历)
  5721. function getRange(curr, all, count) {
  5722. //计算显示的页数
  5723. // console.log(curr, all, count)
  5724. curr = parseInt(curr);
  5725. all = parseInt(all);
  5726. count = parseInt(count);
  5727. var from = curr - parseInt(count / 2);
  5728. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  5729. //显示的页数容处理
  5730. if (from <= 0) {
  5731. from = 1;
  5732. to = from + count - 1;
  5733. if (to > all) {
  5734. to = all;
  5735. }
  5736. }
  5737. if (to > all) {
  5738. to = all;
  5739. from = to - count + 1;
  5740. if (from <= 0) {
  5741. from = 1;
  5742. }
  5743. }
  5744. var range = [];
  5745. for (var i = from; i <= to; i++) {
  5746. range.push(i);
  5747. }
  5748. range.push('»');
  5749. range.unshift('«');
  5750. return range;
  5751. }
  5752. }
  5753. }
  5754. });
  5755. app.service('Myservice', function () {
  5756. return {
  5757. };
  5758. });
  5759. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  5760. // console.log(bh)
  5761. // if(bh>=0&&bh<=53){
  5762. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  5763. // }else{
  5764. // $('#sidebar').css('padding-bottom', 0 + 'px')
  5765. // }
  5766. window.onscroll = function () {
  5767. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  5768. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  5769. } else {
  5770. $('#sidebar').css('padding-top', '0')
  5771. }
  5772. // console.log(window.pageYOffset)
  5773. // console.log(window.innerHeight)
  5774. // console.log(document.body.scrollHeight)
  5775. // 底部padding
  5776. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  5777. // console.log(bh)
  5778. // if(bh>=0&&bh<=53){
  5779. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  5780. // }else{
  5781. // $('#sidebar').css('padding-bottom', 0 + 'px')
  5782. // }
  5783. }