mainCtrl.js 271 KB

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