mainCtrl.js 301 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774
  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. $rootScope.newOrderType = type;
  3617. console.log('newOrderType', $rootScope.newOrderType)
  3618. //进入弹窗,强制示忙
  3619. if (localStorage.getItem('fenjiNumber')) {
  3620. setTimeout(()=>{
  3621. tlwsa.tlaAcw();
  3622. },0)
  3623. }
  3624. $modal.open({
  3625. backdrop: false,
  3626. templateUrl:
  3627. "assets/views/newOrderSeimin.html",
  3628. controller: function (
  3629. $scope,
  3630. $parse,
  3631. fileReader,
  3632. FileUploader,
  3633. $modalInstance,
  3634. SweetAlert,
  3635. api_user_data,
  3636. api_bpm_domain,
  3637. up_down_file,
  3638. $rootScope,
  3639. modelData
  3640. ) {
  3641. // -------------------start----------------------
  3642. $scope.modelData = modelData;
  3643. $scope.menuAuth = {
  3644. allSupplement: false,//补单
  3645. }
  3646. for (var i = 0; i < $rootScope.user.menu.length; i++) {
  3647. if ($rootScope.user.menu[i].link == "shijianliebiao_supplement") {
  3648. $scope.menuAuth.allSupplement = true
  3649. }
  3650. }
  3651. console.log('补单', $scope.menuAuth.allSupplement)
  3652. // 事件报修图片
  3653. $scope.requestImgs = [];
  3654. // 当前所属院区处理
  3655. console.log(modelData);
  3656. // if(modelData){
  3657. // var curentHospital = undefined;
  3658. // api_bpm_data.fetchData('department', modelData.incident.department.id).then(res=>{
  3659. // if(res.status == 200){
  3660. // console.log(res.data);
  3661. // curentHospital = {id:1,hosName:'同济医院-主院区'}
  3662. // }
  3663. // })
  3664. // }else{
  3665. // var curentHospital = $rootScope.user.duty?{id:$rootScope.user.duty.branch,hosName:$rootScope.user.duty.branchName}:$rootScope.user.branch;
  3666. // }
  3667. if(modelData && type !== 'incomingCall'){
  3668. var curentHospital = {id: modelData.branch, hosName: modelData.branchName};
  3669. }else{
  3670. var curentHospital = $rootScope.user.duty?{id:$rootScope.user.duty.branch,hosName:$rootScope.user.duty.branchName}:$rootScope.user.branch;
  3671. }
  3672. // 是否连续建单
  3673. $scope.btns = {
  3674. isBuildOrderAgagin: false,
  3675. }
  3676. //工单列表数据存储
  3677. $scope.incidentModel = {
  3678. department: "", //报修科室
  3679. requester: "", //报修人
  3680. contacts: "", //联系人
  3681. contactsInformation: "", //联系电话
  3682. branch: curentHospital, //院区
  3683. area: "", //区域
  3684. place: "", //地点
  3685. address: "", //详细地址
  3686. priority: "", //优先级
  3687. description: "", //故障描述
  3688. source: {id:1547,name:'电话'}, //事件来源
  3689. yyTime: null, //预约报修时间
  3690. assign: 1, //派单人或组
  3691. user: "", //处理人
  3692. group: "", //处理组
  3693. };
  3694. console.log(modelData)
  3695. if(modelData){
  3696. //报修生成事件,数据回显
  3697. //来电生成事件,数据回显
  3698. //暂存生成事件,数据回显
  3699. // 报修图片
  3700. if (modelData.incident && modelData.incident.id) {
  3701. $rootScope.isMask = true;
  3702. api_wechatfile.listAttachment("wechatRequesterIncident", modelData.incident.id).then( (res) => {
  3703. $rootScope.isMask = false;
  3704. $scope.requestImgs = res.data || [];
  3705. });
  3706. }
  3707. $scope.categorySelect = modelData.incident.category;
  3708. $scope.jry_modelLeft = modelData.incident.category?modelData.incident.category.mutiCategory:'';
  3709. console.log($scope.jry_deptData)
  3710. $scope.incidentModel = {
  3711. id: modelData.incident.id || undefined, //事件id
  3712. department: modelData.incident.department, //报修科室
  3713. requester: modelData.incident.requester || undefined, //报修人
  3714. contacts: modelData.incident.contacts, //联系人
  3715. contactsInformation: type === 'incomingCall' ? modelData.incident.incomingPhone : modelData.incident.contactsInformation, //联系电话
  3716. branch: curentHospital, //院区
  3717. area: type === 'incomingCall' ? (modelData.incident.department ? (modelData.incident.department.place ? modelData.incident.department.place.area : "") : "") : (modelData.incident.place ? modelData.incident.place.area : ""), //区域
  3718. place: type === 'incomingCall' ? (modelData.incident.department ? (modelData.incident.department.place || "") : "") : (modelData.incident.place || ""), //地点
  3719. address: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.address : "") : modelData.incident.houseNumber, //详细地址
  3720. priority: modelData.incident.priority, //优先级
  3721. description: modelData.incident.description, //故障描述
  3722. source: modelData.incident.source, //事件来源
  3723. yyTime: null, //预约报修时间
  3724. assign: 1, //派单人或组
  3725. user: "", //处理人
  3726. group: "", //处理组
  3727. callID: type === 'incomingCall' ? (modelData.incident.sockid || undefined) : (modelData.incident.callID || undefined), //callID
  3728. incomingPhone: modelData.incident.incomingPhone || undefined, //来电电话
  3729. };
  3730. }
  3731. $scope.minYYtime = new Date();
  3732. // 预览图片
  3733. $scope.previewNew = function (type, url, idx) {
  3734. let title = $scope[type][idx].title;
  3735. $modal.open({
  3736. backdrop: false,
  3737. size: "sm",
  3738. templateUrl: "assets/views/customform/tpl/ui-showimage.html",
  3739. controller: function ($scope, $rootScope, scope, $modalInstance) {
  3740. $scope.title = title;
  3741. $scope.imageurl = $rootScope.attachmentAddressSplicing(url);
  3742. $scope.cancel = function () {
  3743. $modalInstance.dismiss("cancel");
  3744. };
  3745. },
  3746. resolve: {
  3747. scope: function () {
  3748. return $scope;
  3749. },
  3750. },
  3751. });
  3752. };
  3753. // 编辑后保存
  3754. $scope.editSave = function(){
  3755. if(!$scope.categorySelectId){
  3756. SweetAlert.swal({
  3757. title: "提示",
  3758. text: "请选择故障现象!",
  3759. type: "error",
  3760. confirmButtonColor: "#DD6B55"
  3761. });
  3762. return;
  3763. }
  3764. if(!$scope.selectedDuty){
  3765. SweetAlert.swal({
  3766. title: "提示",
  3767. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  3768. type: "error",
  3769. confirmButtonColor: "#DD6B55"
  3770. });
  3771. return;
  3772. }
  3773. if(!$scope.incidentModel.department){
  3774. SweetAlert.swal({
  3775. title: "提示",
  3776. text: "请选择报修科室!",
  3777. type: "error",
  3778. confirmButtonColor: "#DD6B55"
  3779. });
  3780. return;
  3781. }
  3782. if(!$scope.incidentModel.contactsInformation){
  3783. SweetAlert.swal({
  3784. title: "提示",
  3785. text: "请填写联系电话!",
  3786. type: "error",
  3787. confirmButtonColor: "#DD6B55"
  3788. });
  3789. return;
  3790. }
  3791. if(!$scope.incidentModel.priority){
  3792. SweetAlert.swal({
  3793. title: "提示",
  3794. text: "请选择优先级!",
  3795. type: "error",
  3796. confirmButtonColor: "#DD6B55"
  3797. });
  3798. return;
  3799. }
  3800. if(!$scope.incidentModel.description){
  3801. SweetAlert.swal({
  3802. title: "提示",
  3803. text: "请选择故障描述!",
  3804. type: "error",
  3805. confirmButtonColor: "#DD6B55"
  3806. });
  3807. return;
  3808. }
  3809. $rootScope.isMask = true;
  3810. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  3811. var postData = {
  3812. "incident": {
  3813. "id": $scope.incidentModel.id || undefined,
  3814. "deleteFlag": 0,
  3815. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3816. "department": $scope.incidentModel.department||undefined,
  3817. "contactsInformation": $scope.incidentModel.contactsInformation,
  3818. "contacts": $scope.incidentModel.contacts,
  3819. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3820. "area": $scope.incidentModel.area||undefined,
  3821. "place": $scope.incidentModel.place||undefined,
  3822. "houseNumber": $scope.incidentModel.address,
  3823. "category": $scope.categorySelect||undefined,
  3824. "priority": $scope.incidentModel.priority||undefined,
  3825. "source": $scope.incidentModel.source||undefined,
  3826. "title": $scope.categorySelect.category,
  3827. "description": $scope.incidentModel.description,
  3828. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3829. "repairType": repair_main?repair_main.valueconfig:undefined,
  3830. "requester":$scope.incidentModel.requester||undefined,
  3831. "acceptUser": $scope.modelData ? $scope.modelData.incident.acceptUser : undefined,
  3832. "callID": $scope.incidentModel.callID||undefined,
  3833. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3834. }
  3835. };
  3836. $scope.modelData && (postData.incident = Object.assign({}, $scope.modelData.incident, postData.incident));
  3837. api_flow.accept("edit", postData).then(function (response) {
  3838. // if ($scope.uploader != null) {
  3839. // // 有图片
  3840. // $scope.uploader.onBeforeUploadItem = function(item) {
  3841. // angular.extend(item.headers, $rootScope.getSession());
  3842. // item.url = api_bpm_domain.uploadAttachmentJryModel("wechatRequesterIncident", response.data.id).getRequestedUrl();
  3843. // item.formData.push({ 'fileName': item.file.name });
  3844. // };
  3845. // $scope.uploader.uploadAll();
  3846. // }
  3847. $rootScope.isMask = false;
  3848. SweetAlert.swal(
  3849. {
  3850. title: "保存成功!",
  3851. type: "success",
  3852. confirmButtonColor: "#007AFF",
  3853. },
  3854. function (isConfirm) {
  3855. if(isConfirm){
  3856. if (localStorage.getItem('fenjiNumber')) {
  3857. $rootScope.jry_shixian();
  3858. }
  3859. $modalInstance.dismiss("cancel");
  3860. $rootScope.newOrderShowOpen = false;
  3861. if($state.current.name === 'app.incident.list'){
  3862. $state.reload();
  3863. }else{
  3864. $state.go("app.incident.list");
  3865. }
  3866. }
  3867. }
  3868. );
  3869. });
  3870. }
  3871. // 建单并派单
  3872. $scope.buildAndAssign = async function(){
  3873. if(!$scope.categorySelectId){
  3874. SweetAlert.swal({
  3875. title: "提示",
  3876. text: "请选择故障现象!",
  3877. type: "error",
  3878. confirmButtonColor: "#DD6B55"
  3879. });
  3880. return;
  3881. }
  3882. if(!$scope.selectedDuty){
  3883. SweetAlert.swal({
  3884. title: "提示",
  3885. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  3886. type: "error",
  3887. confirmButtonColor: "#DD6B55"
  3888. });
  3889. return;
  3890. }
  3891. if(!$scope.incidentModel.department){
  3892. SweetAlert.swal({
  3893. title: "提示",
  3894. text: "请选择报修科室!",
  3895. type: "error",
  3896. confirmButtonColor: "#DD6B55"
  3897. });
  3898. return;
  3899. }
  3900. if(!$scope.incidentModel.contactsInformation){
  3901. SweetAlert.swal({
  3902. title: "提示",
  3903. text: "请填写联系电话!",
  3904. type: "error",
  3905. confirmButtonColor: "#DD6B55"
  3906. });
  3907. return;
  3908. }
  3909. if(!$scope.incidentModel.priority){
  3910. SweetAlert.swal({
  3911. title: "提示",
  3912. text: "请选择优先级!",
  3913. type: "error",
  3914. confirmButtonColor: "#DD6B55"
  3915. });
  3916. return;
  3917. }
  3918. if(!$scope.incidentModel.description){
  3919. SweetAlert.swal({
  3920. title: "提示",
  3921. text: "请选择故障描述!",
  3922. type: "error",
  3923. confirmButtonColor: "#DD6B55"
  3924. });
  3925. return;
  3926. }
  3927. if($scope.incidentModel.assign == 0){
  3928. SweetAlert.swal({
  3929. title: "提示",
  3930. text: "请选择派单给人或组!",
  3931. type: "error",
  3932. confirmButtonColor: "#DD6B55"
  3933. });
  3934. return;
  3935. }
  3936. if($scope.incidentModel.assign == 1 && !$scope.incidentModel.user){
  3937. SweetAlert.swal({
  3938. title: "提示",
  3939. text: "请选择处理人!",
  3940. type: "error",
  3941. confirmButtonColor: "#DD6B55"
  3942. });
  3943. return;
  3944. }
  3945. if($scope.incidentModel.assign == 2 && !$scope.incidentModel.group){
  3946. SweetAlert.swal({
  3947. title: "提示",
  3948. text: "请选择处理组!",
  3949. type: "error",
  3950. confirmButtonColor: "#DD6B55"
  3951. });
  3952. return;
  3953. }
  3954. $rootScope.isMask = true;
  3955. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  3956. // var postData = {
  3957. // "loginUser": $rootScope.user,
  3958. // "incident": {
  3959. // "deleteFlag": 0,
  3960. // "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3961. // "department": $scope.incidentModel.department||undefined,
  3962. // "contactsInformation": $scope.incidentModel.contactsInformation,
  3963. // "contacts": $scope.incidentModel.contacts,
  3964. // "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3965. // "area": $scope.incidentModel.area||undefined,
  3966. // "place": $scope.incidentModel.place||undefined,
  3967. // "houseNumber": $scope.incidentModel.address,
  3968. // "category": $scope.categorySelect||undefined,
  3969. // "priority": $scope.incidentModel.priority||undefined,
  3970. // "source": $scope.incidentModel.source||undefined,
  3971. // "title": $scope.categorySelect.category,
  3972. // "description": $scope.incidentModel.description,
  3973. // "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3974. // "repairType": repair_main?repair_main.valueconfig:undefined,
  3975. // "requester":$scope.incidentModel.requester||undefined,
  3976. // "acceptUser": $rootScope.user||undefined,
  3977. // "callID": $scope.incidentModel.callID||undefined,
  3978. // "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3979. // },
  3980. // "start_code": "assignment",
  3981. // "initUser": $rootScope.user.id
  3982. // };
  3983. var postData = {
  3984. "incident": {
  3985. "id": $scope.incidentModel.id || undefined,
  3986. "deleteFlag": 0,
  3987. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3988. "department": $scope.incidentModel.department||undefined,
  3989. "contactsInformation": $scope.incidentModel.contactsInformation,
  3990. "contacts": $scope.incidentModel.contacts,
  3991. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3992. "area": $scope.incidentModel.area||undefined,
  3993. "place": $scope.incidentModel.place||undefined,
  3994. "houseNumber": $scope.incidentModel.address,
  3995. "category": $scope.categorySelect||undefined,
  3996. "priority": $scope.incidentModel.priority||undefined,
  3997. "source": $scope.incidentModel.source||undefined,
  3998. "title": $scope.categorySelect.category,
  3999. "description": $scope.incidentModel.description,
  4000. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4001. "repairType": repair_main?repair_main.valueconfig:undefined,
  4002. "requester":$scope.incidentModel.requester||undefined,
  4003. "acceptUser": $rootScope.user||undefined,
  4004. "callID": $scope.incidentModel.callID||undefined,
  4005. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  4006. }
  4007. };
  4008. $scope.modelData && (postData.incident = Object.assign({}, $scope.modelData.incident, postData.incident));
  4009. // if(modelData){
  4010. // // 微信报修转事件
  4011. // postData.flow = modelData.flow;
  4012. // }
  4013. if($scope.incidentModel.assign == 1){
  4014. postData.incident.assignee = $scope.incidentModel.user.id;
  4015. }else if($scope.incidentModel.assign == 2){
  4016. postData.incident.candidateGroups = $scope.incidentModel.group.id;
  4017. }
  4018. if(!postData.incident.incidentsign){
  4019. let res1 = await api_bpm_domain.workernumber('sj');
  4020. postData.incident.incidentsign = res1.data;
  4021. }
  4022. // api_bpm_domain.workernumber('sj').then(res1=>{
  4023. // postData.incident.incidentsign = res1.data;
  4024. api_flow.accept("accept", postData).then(function (response) {
  4025. if ($scope.uploader != null) {
  4026. // 有图片
  4027. $scope.uploader.onBeforeUploadItem = function(item) {
  4028. angular.extend(item.headers, $rootScope.getSession());
  4029. item.url = api_bpm_domain.uploadAttachmentJryModel("wechatRequesterIncident", response.data.id).getRequestedUrl();
  4030. item.formData.push({ 'fileName': item.file.name });
  4031. };
  4032. $scope.uploader.uploadAll();
  4033. }
  4034. $rootScope.isMask = false;
  4035. SweetAlert.swal(
  4036. {
  4037. title: "保存成功!",
  4038. type: "success",
  4039. confirmButtonColor: "#007AFF",
  4040. },
  4041. function (isConfirm) {
  4042. if(isConfirm){
  4043. // 是否连续建单
  4044. if($scope.btns.isBuildOrderAgagin){
  4045. $scope.categorySelect = "";
  4046. $scope.categorySelectId = 0;
  4047. $scope.incidentModel.assign = 1;
  4048. $scope.incidentModel.user = "";
  4049. $scope.incidentModel.group = "";
  4050. }else{
  4051. if (localStorage.getItem('fenjiNumber')) {
  4052. $rootScope.jry_shixian();
  4053. }
  4054. $modalInstance.dismiss("cancel");
  4055. }
  4056. $rootScope.newOrderShowOpen = false;
  4057. if($state.current.name === 'app.incident.list'){
  4058. $state.reload();
  4059. }else{
  4060. $state.go("app.incident.list");
  4061. }
  4062. }
  4063. }
  4064. );
  4065. });
  4066. // })
  4067. }
  4068. // 暂存
  4069. $scope.temporaryStorage = async function(){
  4070. $rootScope.isMask = true;
  4071. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  4072. var postData = {
  4073. "incident": {
  4074. "id": $scope.incidentModel.id || undefined,
  4075. "deleteFlag": 0,
  4076. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  4077. "department": $scope.incidentModel.department||undefined,
  4078. "contactsInformation": $scope.incidentModel.contactsInformation,
  4079. "contacts": $scope.incidentModel.contacts,
  4080. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  4081. "area": $scope.incidentModel.area||undefined,
  4082. "place": $scope.incidentModel.place||undefined,
  4083. "houseNumber": $scope.incidentModel.address,
  4084. "category": $scope.categorySelect||undefined,
  4085. "priority": $scope.incidentModel.priority||undefined,
  4086. "source": $scope.incidentModel.source||undefined,
  4087. "title": $scope.categorySelect.category,
  4088. "description": $scope.incidentModel.description,
  4089. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4090. "repairType": repair_main?repair_main.valueconfig:undefined,
  4091. "requester":$scope.incidentModel.requester||undefined,
  4092. "acceptUser": $rootScope.user||undefined,
  4093. "callID": $scope.incidentModel.callID||undefined,
  4094. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  4095. }
  4096. };
  4097. $scope.modelData && (postData.incident = Object.assign({}, $scope.modelData.incident, postData.incident));
  4098. // if(modelData){
  4099. // // 微信报修转事件
  4100. // postData.flow = modelData.flow;
  4101. // }
  4102. if($scope.incidentModel.assign == 1){
  4103. postData.incident.assignee = $scope.incidentModel ? $scope.incidentModel.user.id : undefined;
  4104. }else if($scope.incidentModel.assign == 2){
  4105. postData.incident.candidateGroups = $scope.incidentModel ? $scope.incidentModel.group.id : undefined;
  4106. }
  4107. if(!postData.incident.incidentsign){
  4108. let res1 = await api_bpm_domain.workernumber('sj');
  4109. postData.incident.incidentsign = res1.data;
  4110. }
  4111. // api_bpm_domain.workernumber('sj').then(res1=>{
  4112. // postData.incident.incidentsign = res1.data;
  4113. api_flow.accept("storage", postData).then(function (response) {
  4114. if ($scope.uploader != null) {
  4115. // 有图片
  4116. $scope.uploader.onBeforeUploadItem = function(item) {
  4117. angular.extend(item.headers, $rootScope.getSession());
  4118. item.url = api_bpm_domain.uploadAttachmentJryModel("wechatRequesterIncident", response.data.id).getRequestedUrl();
  4119. item.formData.push({ 'fileName': item.file.name });
  4120. };
  4121. $scope.uploader.uploadAll();
  4122. }
  4123. $rootScope.isMask = false;
  4124. SweetAlert.swal(
  4125. {
  4126. title: "保存成功!",
  4127. type: "success",
  4128. confirmButtonColor: "#007AFF",
  4129. },
  4130. function (isConfirm) {
  4131. if(isConfirm){
  4132. // 是否连续建单
  4133. if($scope.btns.isBuildOrderAgagin){
  4134. $scope.categorySelect = "";
  4135. $scope.categorySelectId = 0;
  4136. $scope.incidentModel.assign = 1;
  4137. $scope.incidentModel.user = "";
  4138. $scope.incidentModel.group = "";
  4139. }else{
  4140. if (localStorage.getItem('fenjiNumber')) {
  4141. $rootScope.jry_shixian();
  4142. }
  4143. $modalInstance.dismiss("cancel");
  4144. }
  4145. $rootScope.newOrderShowOpen = false;
  4146. if($state.current.name === 'app.incident.list'){
  4147. $state.reload();
  4148. }else{
  4149. $state.go("app.incident.list");
  4150. }
  4151. }
  4152. }
  4153. );
  4154. });
  4155. // })
  4156. }
  4157. // 展开/收起
  4158. $scope.showId = "";
  4159. $scope.ifshow = false;
  4160. $scope.showAll = function (id) {
  4161. $scope.attachments = [];
  4162. if ($scope.showId == id) {
  4163. $scope.ifshow = !$scope.ifshow;
  4164. } else {
  4165. $scope.ifshow = true;
  4166. }
  4167. $scope.showId = id;
  4168. // 获取附件
  4169. api_wechatfile
  4170. .listAttachments("knowledge", $scope.showId)
  4171. .then(function (data) {
  4172. $scope.attachments = data.data;
  4173. $scope.download = function (token, filename) {
  4174. var downUrl = up_down_file
  4175. .downloadAttachment("common/common/downloadAttachment", token)
  4176. .getRequestedUrl();
  4177. var a = document.createElement("a");
  4178. a.href = downUrl;
  4179. a.target = "_blank";
  4180. a.download = filename;
  4181. document.body.appendChild(a);
  4182. a.click();
  4183. };
  4184. });
  4185. };
  4186. // 切换派人或派组
  4187. $scope.assginChange = function(){
  4188. $scope.incidentModel.user = '';
  4189. $scope.incidentModel.group = '';
  4190. }
  4191. // 处理人/处理组加责任科室搜索
  4192. $scope.userAndGroupSearch = async function(){
  4193. // $scope.jry_userSearch();
  4194. // $scope.jry_groupSearch();
  4195. var userData = {
  4196. idx: 0,
  4197. sum: 1000,
  4198. user: {
  4199. duty: $scope.selectedDuty || undefined,
  4200. roledata: {rolecode: "first-line support"},
  4201. selectDetails:'1',
  4202. simple:true,
  4203. name: '',
  4204. selectType: "pinyin_qs",
  4205. engineer: 1,
  4206. },
  4207. };
  4208. var groupData = {
  4209. idx: 0,
  4210. sum: 1000,
  4211. group: {
  4212. duty: $scope.selectedDuty || undefined,
  4213. selectType: "nouser"
  4214. },
  4215. };
  4216. let userResult = await api_user_data.fetchDataList("user", userData);
  4217. let groupResult = await api_user_data.fetchDataList("group", groupData);
  4218. $scope.jry_userData = userResult.list;
  4219. if($scope.incidentModel.user){
  4220. if(!$scope.incidentModel.user.name){
  4221. $scope.incidentModel.user = userResult.list.find(v=>v.id == $scope.incidentModel.user.id);
  4222. }
  4223. }
  4224. $scope.jry_groupData = groupResult.list;
  4225. // if($scope.incidentModel.assign == 0){
  4226. // $scope.jry_userSearch();
  4227. // $scope.jry_groupSearch();
  4228. // }else if($scope.incidentModel.assign == 1){
  4229. // $scope.jry_userSearch();
  4230. // }else if($scope.incidentModel.assign == 2){
  4231. // $scope.jry_groupSearch();
  4232. // }
  4233. }
  4234. // 回显处理人或组
  4235. $scope.showUserOrGroup = function(){
  4236. if($scope.incidentModel.department && $scope.categorySelect && $scope.selectedDuty && $scope.incidentModel.branch){
  4237. var postData = {
  4238. idx: 0,
  4239. sum: 10,
  4240. incidentAssignManager: {
  4241. deptId:$scope.incidentModel.department.id,
  4242. categoryId:$scope.categorySelect.id,
  4243. branch:$scope.incidentModel.branch.id,
  4244. dutyId: $scope.selectedDuty.id
  4245. },
  4246. };
  4247. api_user_data.fetchDataList("incidentAssignManager", postData).then(async function(result){
  4248. if(result.status == 200){
  4249. var deptBinduserConfig = result.list?result.list[0]:null;//获取第一条配置
  4250. if(deptBinduserConfig){
  4251. await $scope.userAndGroupSearch();
  4252. // 如果有科室绑定人员的配置
  4253. if(deptBinduserConfig.userOrGroupType == 1){
  4254. // 派单给人
  4255. $scope.incidentModel.assign = 1;
  4256. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == deptBinduserConfig.handleUser);
  4257. }else if(deptBinduserConfig.userOrGroupType == 2){
  4258. // 派单给组
  4259. $scope.incidentModel.assign = 2;
  4260. $scope.incidentModel.group = $scope.jry_groupData.find(v=>v.id == deptBinduserConfig.group);
  4261. }
  4262. }else{
  4263. // 没有查询到科室绑定人员的配置,则根据院区,普通科室,责任科室查询
  4264. var postData = {
  4265. idx: 0,
  4266. sum: 10,
  4267. incidentAssignManager: {
  4268. deptId:$scope.incidentModel.department.id,
  4269. branch:$scope.incidentModel.branch.id,
  4270. dutyId: $scope.selectedDuty.id
  4271. },
  4272. };
  4273. api_user_data.fetchDataList("incidentAssignManager", postData).then(async function(result){
  4274. if(result.status == 200){
  4275. //获取配置
  4276. var deptBinduserConfig = result.list || [];
  4277. // 过滤掉有故障现象的配置
  4278. deptBinduserConfig = deptBinduserConfig.filter(v => !v.categoryId);
  4279. // 获取第一条配置
  4280. deptBinduserConfig = deptBinduserConfig[0] || null;
  4281. if(deptBinduserConfig){
  4282. await $scope.userAndGroupSearch();
  4283. // 如果有科室绑定人员的配置
  4284. if(deptBinduserConfig.userOrGroupType == 1){
  4285. // 派单给人
  4286. $scope.incidentModel.assign = 1;
  4287. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == deptBinduserConfig.handleUser);
  4288. }else if(deptBinduserConfig.userOrGroupType == 2){
  4289. // 派单给组
  4290. $scope.incidentModel.assign = 2;
  4291. $scope.incidentModel.group = $scope.jry_groupData.find(v=>v.id == deptBinduserConfig.group);
  4292. }
  4293. }else{
  4294. if($scope.categorySelect){
  4295. // 选择了故障现象
  4296. assignCommon($scope.categorySelect);
  4297. }
  4298. }
  4299. }
  4300. })
  4301. }
  4302. }
  4303. })
  4304. }else if($scope.categorySelect){
  4305. // 选择了故障现象
  4306. assignCommon($scope.categorySelect);
  4307. }
  4308. }
  4309. // 直接解决
  4310. $scope.build = function(){
  4311. if(!$scope.categorySelectId){
  4312. SweetAlert.swal({
  4313. title: "提示",
  4314. text: "请选择故障现象!",
  4315. type: "error",
  4316. confirmButtonColor: "#DD6B55"
  4317. });
  4318. return;
  4319. }
  4320. if(!$scope.selectedDuty){
  4321. SweetAlert.swal({
  4322. title: "提示",
  4323. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  4324. type: "error",
  4325. confirmButtonColor: "#DD6B55"
  4326. });
  4327. return;
  4328. }
  4329. if(!$scope.incidentModel.department){
  4330. SweetAlert.swal({
  4331. title: "提示",
  4332. text: "请选择报修科室!",
  4333. type: "error",
  4334. confirmButtonColor: "#DD6B55"
  4335. });
  4336. return;
  4337. }
  4338. if(!$scope.incidentModel.contactsInformation){
  4339. SweetAlert.swal({
  4340. title: "提示",
  4341. text: "请填写联系电话!",
  4342. type: "error",
  4343. confirmButtonColor: "#DD6B55"
  4344. });
  4345. return;
  4346. }
  4347. if(!$scope.incidentModel.priority){
  4348. SweetAlert.swal({
  4349. title: "提示",
  4350. text: "请选择优先级!",
  4351. type: "error",
  4352. confirmButtonColor: "#DD6B55"
  4353. });
  4354. return;
  4355. }
  4356. if(!$scope.incidentModel.description){
  4357. SweetAlert.swal({
  4358. title: "提示",
  4359. text: "请选择故障描述!",
  4360. type: "error",
  4361. confirmButtonColor: "#DD6B55"
  4362. });
  4363. return;
  4364. }
  4365. $modal.open({
  4366. templateUrl: "assets/views/newOrderDirectly.html",
  4367. controller: function ($scope,scope,$state, $modalInstance, SweetAlert,api_bpm) {
  4368. $scope.categorySelect = scope.categorySelect;
  4369. console.log($scope.categorySelect)
  4370. $scope.incidentModel = {
  4371. handlerMsg:'',//处理方案
  4372. closecode:'',//处理结果
  4373. };
  4374. // 处理结果
  4375. $scope.closecodeArray = [];
  4376. $scope.jry_closecodeSearch = function () {
  4377. api_wechatfile
  4378. .getDictionary({ type: "list", key: "incident_closecode" })
  4379. .then(function (data) {
  4380. $scope.closecodeArray = data;
  4381. });
  4382. };
  4383. $scope.jry_closecodeSearch();
  4384. // 确定
  4385. $scope.ok = function () {
  4386. if($scope.categorySelect.hasSimple != 1 && !$scope.incidentModel.handlerMsg){
  4387. SweetAlert.swal({
  4388. title: "提示",
  4389. text: "请填写处理方案!",
  4390. type: "error",
  4391. confirmButtonColor: "#DD6B55"
  4392. });
  4393. return;
  4394. }
  4395. if(!$scope.incidentModel.closecode.id){
  4396. SweetAlert.swal({
  4397. title: "提示",
  4398. text: "请选择处理结果!",
  4399. type: "error",
  4400. confirmButtonColor: "#DD6B55"
  4401. });
  4402. return;
  4403. }
  4404. // -------新建事件,积分机制,直接处理--------
  4405. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4406. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4407. $modal.open({
  4408. templateUrl: 'assets/views/incident/tpl/toIntegralMechanism.tpl.html',
  4409. controller: function ($scope, $modalInstance, incidentData,categorySelect, currentUserId, Alert, api_wechatfile,scope,api_bpm_data) {
  4410. console.log(incidentData,currentUserId,categorySelect);
  4411. $scope.complexityConfirm = {complexity:null,updateReason:''};
  4412. $scope.complexityFn = function(category){
  4413. if(category.complexity){
  4414. return category.complexity.value;
  4415. }else if(category.parent){
  4416. return $scope.complexityFn(category.parent);
  4417. }else{
  4418. return $scope.list[0]?$scope.list[0].value:1;
  4419. }
  4420. }
  4421. $scope.list = [];
  4422. api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){
  4423. $scope.list = res;
  4424. if(categorySelect && categorySelect.id){
  4425. api_bpm_data.fetchData("incidentCategory",categorySelect.id).then(function(result){
  4426. if(result.status == 200){
  4427. $scope.complexity = $scope.complexityFn(result.data);
  4428. $scope.complexityConfirm.complexity = $scope.list.find(v=>v.value == $scope.complexity);
  4429. }
  4430. })
  4431. }
  4432. })
  4433. $scope.onChangeComplexity = function(item){
  4434. }
  4435. $scope.ok = function () {
  4436. if (!$scope.complexityConfirm.complexity){
  4437. Alert.swal({
  4438. title: "操作失败",
  4439. text: "请选择工时!",
  4440. type: "error"
  4441. });
  4442. return;
  4443. }
  4444. if ($scope.complexityConfirm.complexity.value != $scope.complexity&&!$scope.complexityConfirm.updateReason.trim()){
  4445. Alert.swal({
  4446. title: "操作失败",
  4447. text: "请填写升级原因!",
  4448. type: "error"
  4449. });
  4450. return;
  4451. }
  4452. $modalInstance.close('success');
  4453. handlerStart();
  4454. scope.complexity = $scope.complexity;
  4455. scope.complexityConfirm = $scope.complexityConfirm;
  4456. // 暂存--后面直接处理后调用积分接口
  4457. }
  4458. $scope.cancel = function () {
  4459. if (localStorage.getItem('fenjiNumber')) {
  4460. $rootScope.jry_shixian();
  4461. }
  4462. $modalInstance.dismiss('cancel');
  4463. }
  4464. },
  4465. size: 'sm',
  4466. resolve: {
  4467. scope: function () {
  4468. return $scope;
  4469. },
  4470. api_bpm: function () {
  4471. return api_bpm;
  4472. },
  4473. incidentData: function () {
  4474. return scope.incidentModel;
  4475. },
  4476. categorySelect: function () {
  4477. return scope.categorySelect;
  4478. },
  4479. currentUserId: function () {
  4480. return $rootScope.user.id;
  4481. },
  4482. Alert: function () {
  4483. return SweetAlert;
  4484. },
  4485. api_user_data: function () {
  4486. return api_user_data;
  4487. },
  4488. api_wechatfile: function () {
  4489. return api_wechatfile;
  4490. }
  4491. }
  4492. });
  4493. }else{
  4494. handlerStart();
  4495. }
  4496. // -------新建事件,积分机制,直接处理--------
  4497. };
  4498. // 直接处理,新建事件
  4499. async function handlerStart(){
  4500. $rootScope.isMask = true;
  4501. console.log(scope.incidentModel,$scope.incidentModel);
  4502. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  4503. // var postData = {
  4504. // "loginUser": $rootScope.user||undefined,
  4505. // "incident": {
  4506. // "deleteFlag": 0,
  4507. // "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4508. // "requester":$scope.incidentModel.requester||undefined,
  4509. // "alarmType": false,
  4510. // "department": scope.incidentModel.department||undefined,
  4511. // "contactsInformation": scope.incidentModel.contactsInformation,
  4512. // "contacts": scope.incidentModel.contacts,
  4513. // "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4514. // "area": scope.incidentModel.area||undefined,
  4515. // "place": scope.incidentModel.place||undefined,
  4516. // "houseNumber": scope.incidentModel.address,
  4517. // "category": scope.categorySelect||undefined,
  4518. // "priority": scope.incidentModel.priority||undefined,
  4519. // "source": scope.incidentModel.source||undefined,
  4520. // "title": scope.categorySelect.category,
  4521. // "description": scope.incidentModel.description,
  4522. // "directProcess": 1,
  4523. // "handleDescription": $scope.incidentModel.handlerMsg,
  4524. // "handlingPersonnelUser":{id:$rootScope.user.id},
  4525. // "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4526. // "closecode": $scope.incidentModel.closecode||undefined,
  4527. // "repairType": repair_main?repair_main.valueconfig:undefined,
  4528. // "acceptUser": $rootScope.user||undefined,
  4529. // "callID": scope.incidentModel.callID||undefined,
  4530. // "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  4531. // },
  4532. // "start_code": "close",
  4533. // "handler_code": "resolve",
  4534. // "initUser": $rootScope.user.id,
  4535. // "isSolution": false
  4536. // };
  4537. var postData = {
  4538. "incident": {
  4539. "id": scope.incidentModel.id || undefined,
  4540. "deleteFlag": 0,
  4541. "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4542. "requester":scope.incidentModel.requester||undefined,
  4543. "alarmType": false,
  4544. "department": scope.incidentModel.department||undefined,
  4545. "contactsInformation": scope.incidentModel.contactsInformation,
  4546. "contacts": scope.incidentModel.contacts,
  4547. "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4548. "area": scope.incidentModel.area||undefined,
  4549. "place": scope.incidentModel.place||undefined,
  4550. "houseNumber": scope.incidentModel.address,
  4551. "category": scope.categorySelect||undefined,
  4552. "priority": scope.incidentModel.priority||undefined,
  4553. "source": scope.incidentModel.source||undefined,
  4554. "title": scope.categorySelect.category,
  4555. "description": scope.incidentModel.description,
  4556. "directProcess": 1,
  4557. "handleDescription": $scope.incidentModel.handlerMsg,
  4558. "handlingPersonnelUser":{id:$rootScope.user.id},
  4559. "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4560. "closecode": $scope.incidentModel.closecode||undefined,
  4561. "repairType": repair_main?repair_main.valueconfig:undefined,
  4562. "acceptUser": $rootScope.user||undefined,
  4563. "callID": scope.incidentModel.callID||undefined,
  4564. "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  4565. },
  4566. };
  4567. scope.modelData && (postData.incident = Object.assign({}, scope.modelData.incident, postData.incident));
  4568. // if(scope.modelData){
  4569. // // 微信报修转事件
  4570. // postData.flow = scope.modelData.flow;
  4571. // }
  4572. if(!postData.incident.incidentsign){
  4573. let res1 = await api_bpm_domain.workernumber('sj');
  4574. postData.incident.incidentsign = res1.data;
  4575. }
  4576. // api_bpm_domain.workernumber('sj').then(res1=>{
  4577. // postData.incident.incidentsign = res1.data;
  4578. api_flow.accept("accept", postData).then(function (resData) {
  4579. if (scope.uploader != null) {
  4580. // 有图片
  4581. scope.uploader.onBeforeUploadItem = function(item) {
  4582. angular.extend(item.headers, $rootScope.getSession());
  4583. item.url = api_bpm_domain.uploadAttachmentJryModel("wechatRequesterIncident", resData.data.id).getRequestedUrl();
  4584. item.formData.push({ 'fileName': item.file.name });
  4585. };
  4586. scope.uploader.uploadAll();
  4587. }
  4588. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4589. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4590. api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
  4591. var auditState = res.find(v=>v.value == 0);
  4592. var postData = {
  4593. incidentIntegral: {
  4594. incidentId:resData.bussId,
  4595. auditState:auditState,
  4596. handlerUser:$rootScope.user.id,
  4597. handlerUserName:$rootScope.user.name,
  4598. sourceScore:$scope.complexity,
  4599. currentScore:$scope.complexityConfirm.complexity.value,
  4600. updateReason:$scope.complexityConfirm.updateReason.trim() || undefined,
  4601. }
  4602. }
  4603. console.log(postData)
  4604. api_bpm_data.addData('incidentIntegral', postData).then(function (response) {
  4605. console.log(response)
  4606. $rootScope.isMask = false;
  4607. if (response.status == 200) {
  4608. SweetAlert.swal(
  4609. {
  4610. title: "保存成功!",
  4611. type: "success",
  4612. confirmButtonColor: "#007AFF",
  4613. },
  4614. function (isConfirm) {
  4615. if(isConfirm){
  4616. $modalInstance.dismiss("cancel");
  4617. // 是否连续建单
  4618. if(scope.btns.isBuildOrderAgagin){
  4619. scope.categorySelect = "";
  4620. scope.categorySelectId = 0;
  4621. scope.incidentModel.assign = 1;
  4622. scope.incidentModel.user = "";
  4623. scope.incidentModel.group = "";
  4624. }else{
  4625. if (localStorage.getItem('fenjiNumber')) {
  4626. $rootScope.jry_shixian();
  4627. }
  4628. scope.cancel();
  4629. }
  4630. $rootScope.newOrderShowOpen = false;
  4631. if($state.current.name === 'app.incident.list'){
  4632. $state.reload();
  4633. }else{
  4634. $state.go("app.incident.list");
  4635. }
  4636. }
  4637. }
  4638. );
  4639. } else {
  4640. Alert.swal({
  4641. title: "操作失败",
  4642. text: "操作失败, 请稍后再试!",
  4643. type: "error"
  4644. });
  4645. }
  4646. });
  4647. })
  4648. }else{
  4649. SweetAlert.swal(
  4650. {
  4651. title: "提交成功!",
  4652. type: "success",
  4653. confirmButtonColor: "#007AFF",
  4654. },
  4655. function (isConfirm) {
  4656. if(isConfirm){
  4657. if (localStorage.getItem('fenjiNumber')) {
  4658. $rootScope.jry_shixian();
  4659. }
  4660. scope.cancel();
  4661. $modalInstance.dismiss("cancel");
  4662. $rootScope.newOrderShowOpen = false;
  4663. if($state.current.name === 'app.incident.list'){
  4664. $state.reload();
  4665. }else{
  4666. $state.go("app.incident.list");
  4667. }
  4668. }
  4669. }
  4670. );
  4671. }
  4672. // -------------------------------------------
  4673. $rootScope.isMask = false;
  4674. SweetAlert.swal(
  4675. {
  4676. title: "保存成功!",
  4677. type: "success",
  4678. confirmButtonColor: "#007AFF",
  4679. },
  4680. function (isConfirm) {
  4681. if(isConfirm){
  4682. $modalInstance.dismiss("cancel");
  4683. // 是否连续建单
  4684. if(scope.btns.isBuildOrderAgagin){
  4685. scope.categorySelect = "";
  4686. scope.categorySelectId = 0;
  4687. scope.incidentModel.assign = 1;
  4688. scope.incidentModel.user = "";
  4689. scope.incidentModel.group = "";
  4690. }else{
  4691. if (localStorage.getItem('fenjiNumber')) {
  4692. $rootScope.jry_shixian();
  4693. }
  4694. scope.cancel();
  4695. }
  4696. $rootScope.newOrderShowOpen = false;
  4697. if($state.current.name === 'app.incident.list'){
  4698. $state.reload();
  4699. }else{
  4700. $state.go("app.incident.list");
  4701. }
  4702. }
  4703. }
  4704. );
  4705. });
  4706. // })
  4707. }
  4708. // 取消
  4709. $scope.cancel = function () {
  4710. if (localStorage.getItem('fenjiNumber')) {
  4711. $rootScope.jry_shixian();
  4712. }
  4713. $modalInstance.dismiss("cancel");
  4714. };
  4715. },
  4716. size:'lg',
  4717. resolve: {
  4718. SweetAlert: function () {
  4719. return SweetAlert;
  4720. },
  4721. scope: function(){
  4722. return $scope;
  4723. }
  4724. },
  4725. });
  4726. }
  4727. // 补单
  4728. $scope.supplement = function(){
  4729. if(!$scope.categorySelectId){
  4730. SweetAlert.swal({
  4731. title: "提示",
  4732. text: "请选择故障现象!",
  4733. type: "error",
  4734. confirmButtonColor: "#DD6B55"
  4735. });
  4736. return;
  4737. }
  4738. if(!$scope.selectedDuty){
  4739. SweetAlert.swal({
  4740. title: "提示",
  4741. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  4742. type: "error",
  4743. confirmButtonColor: "#DD6B55"
  4744. });
  4745. return;
  4746. }
  4747. if(!$scope.incidentModel.department){
  4748. SweetAlert.swal({
  4749. title: "提示",
  4750. text: "请选择报修科室!",
  4751. type: "error",
  4752. confirmButtonColor: "#DD6B55"
  4753. });
  4754. return;
  4755. }
  4756. if(!$scope.incidentModel.contactsInformation){
  4757. SweetAlert.swal({
  4758. title: "提示",
  4759. text: "请填写联系电话!",
  4760. type: "error",
  4761. confirmButtonColor: "#DD6B55"
  4762. });
  4763. return;
  4764. }
  4765. if(!$scope.incidentModel.priority){
  4766. SweetAlert.swal({
  4767. title: "提示",
  4768. text: "请选择优先级!",
  4769. type: "error",
  4770. confirmButtonColor: "#DD6B55"
  4771. });
  4772. return;
  4773. }
  4774. if(!$scope.incidentModel.description){
  4775. SweetAlert.swal({
  4776. title: "提示",
  4777. text: "请选择故障描述!",
  4778. type: "error",
  4779. confirmButtonColor: "#DD6B55"
  4780. });
  4781. return;
  4782. }
  4783. $modal.open({
  4784. templateUrl: "assets/views/newOrderSupplement.html",
  4785. controller: function ($scope,scope,$state, $modalInstance, SweetAlert,api_bpm) {
  4786. $scope.categorySelect = scope.categorySelect;
  4787. console.log($scope.categorySelect)
  4788. $scope.incidentModel = {
  4789. handlerMsg:'',//处理方案
  4790. closecode:'',//处理结果
  4791. acceptDate:'',//登记时间
  4792. responseHandleTime:'',//接单时间
  4793. handleTime:'',//解决时间
  4794. handlingPersonnelUser:'',//处理人
  4795. };
  4796. // 处理人模糊搜索
  4797. $scope.jry_userSearch = function (key = "") {
  4798. var userData = {
  4799. idx: 0,
  4800. sum: 1000,
  4801. user: {
  4802. duty: scope.selectedDuty || undefined,
  4803. roledata: {rolecode: "first-line support"},
  4804. selectDetails:'1',
  4805. simple:true,
  4806. name: key,
  4807. selectType: "pinyin_qs",
  4808. engineer: 1,
  4809. },
  4810. };
  4811. api_user_data.fetchDataList("user", userData).then(function (data) {
  4812. $scope.jry_userData = data.list;
  4813. });
  4814. };
  4815. $scope.jry_userSearch();
  4816. // 处理结果
  4817. $scope.closecodeArray = [];
  4818. $scope.jry_closecodeSearch = function () {
  4819. api_wechatfile
  4820. .getDictionary({ type: "list", key: "incident_closecode" })
  4821. .then(function (data) {
  4822. $scope.closecodeArray = data;
  4823. });
  4824. };
  4825. $scope.jry_closecodeSearch();
  4826. // 确定
  4827. $scope.ok = function () {
  4828. if($scope.categorySelect.hasSimple != 1 && !$scope.incidentModel.handlerMsg){
  4829. SweetAlert.swal({
  4830. title: "提示",
  4831. text: "请填写处理方案!",
  4832. type: "error",
  4833. confirmButtonColor: "#DD6B55"
  4834. });
  4835. return;
  4836. }
  4837. if(!$scope.incidentModel.closecode.id){
  4838. SweetAlert.swal({
  4839. title: "提示",
  4840. text: "请选择处理结果!",
  4841. type: "error",
  4842. confirmButtonColor: "#DD6B55"
  4843. });
  4844. return;
  4845. }
  4846. if(!$scope.incidentModel.acceptDate){
  4847. SweetAlert.swal({
  4848. title: "提示",
  4849. text: "请选择登记时间!",
  4850. type: "error",
  4851. confirmButtonColor: "#DD6B55"
  4852. });
  4853. return;
  4854. }
  4855. if(!$scope.incidentModel.responseHandleTime){
  4856. SweetAlert.swal({
  4857. title: "提示",
  4858. text: "请选择接单时间!",
  4859. type: "error",
  4860. confirmButtonColor: "#DD6B55"
  4861. });
  4862. return;
  4863. }
  4864. if(!$scope.incidentModel.handleTime){
  4865. SweetAlert.swal({
  4866. title: "提示",
  4867. text: "请选择解决时间!",
  4868. type: "error",
  4869. confirmButtonColor: "#DD6B55"
  4870. });
  4871. return;
  4872. }
  4873. if(!$scope.incidentModel.handlingPersonnelUser){
  4874. SweetAlert.swal({
  4875. title: "提示",
  4876. text: "请选择处理人!",
  4877. type: "error",
  4878. confirmButtonColor: "#DD6B55"
  4879. });
  4880. return;
  4881. }
  4882. // -------新建事件,积分机制,补单-------
  4883. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4884. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4885. $modal.open({
  4886. templateUrl: 'assets/views/incident/tpl/toIntegralMechanism.tpl.html',
  4887. controller: function ($scope, $modalInstance, incidentData,categorySelect, currentUserId, Alert, api_wechatfile,scope,api_bpm_data) {
  4888. console.log(incidentData,currentUserId,categorySelect);
  4889. $scope.complexityConfirm = {complexity:null,updateReason:''};
  4890. $scope.complexityFn = function(category){
  4891. if(category.complexity){
  4892. return category.complexity.value;
  4893. }else if(category.parent){
  4894. return $scope.complexityFn(category.parent);
  4895. }else{
  4896. return $scope.list[0]?$scope.list[0].value:1;
  4897. }
  4898. }
  4899. $scope.list = [];
  4900. api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){
  4901. $scope.list = res;
  4902. if(categorySelect && categorySelect.id){
  4903. api_bpm_data.fetchData("incidentCategory",categorySelect.id).then(function(result){
  4904. if(result.status == 200){
  4905. $scope.complexity = $scope.complexityFn(result.data);
  4906. $scope.complexityConfirm.complexity = $scope.list.find(v=>v.value == $scope.complexity);
  4907. }
  4908. })
  4909. }
  4910. })
  4911. $scope.onChangeComplexity = function(item){
  4912. }
  4913. $scope.ok = function () {
  4914. if (!$scope.complexityConfirm.complexity){
  4915. Alert.swal({
  4916. title: "操作失败",
  4917. text: "请选择工时!",
  4918. type: "error"
  4919. });
  4920. return;
  4921. }
  4922. if ($scope.complexityConfirm.complexity.value != $scope.complexity&&!$scope.complexityConfirm.updateReason.trim()){
  4923. Alert.swal({
  4924. title: "操作失败",
  4925. text: "请填写升级原因!",
  4926. type: "error"
  4927. });
  4928. return;
  4929. }
  4930. $modalInstance.close('success');
  4931. handlerStart();
  4932. scope.complexity = $scope.complexity;
  4933. scope.complexityConfirm = $scope.complexityConfirm;
  4934. // 暂存--后面直接处理后调用积分接口
  4935. }
  4936. $scope.cancel = function () {
  4937. if (localStorage.getItem('fenjiNumber')) {
  4938. $rootScope.jry_shixian();
  4939. }
  4940. $modalInstance.dismiss('cancel');
  4941. }
  4942. },
  4943. size: 'sm',
  4944. resolve: {
  4945. scope: function () {
  4946. return $scope;
  4947. },
  4948. api_bpm: function () {
  4949. return api_bpm;
  4950. },
  4951. incidentData: function () {
  4952. return scope.incidentModel;
  4953. },
  4954. categorySelect: function () {
  4955. return scope.categorySelect;
  4956. },
  4957. currentUserId: function () {
  4958. return $rootScope.user.id;
  4959. },
  4960. Alert: function () {
  4961. return SweetAlert;
  4962. },
  4963. api_user_data: function () {
  4964. return api_user_data;
  4965. },
  4966. api_wechatfile: function () {
  4967. return api_wechatfile;
  4968. }
  4969. }
  4970. });
  4971. }else{
  4972. handlerStart();
  4973. }
  4974. // -------新建事件,积分机制,补单-------
  4975. };
  4976. // 补单,新建事件
  4977. async function handlerStart(){
  4978. $rootScope.isMask = true;
  4979. console.log(scope.incidentModel,$scope.incidentModel);
  4980. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  4981. var postData = {
  4982. "incident": {
  4983. "id": scope.incidentModel.id || undefined,
  4984. "deleteFlag": 0,
  4985. "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4986. "requester":scope.incidentModel.requester||undefined,
  4987. "alarmType": false,
  4988. "department": scope.incidentModel.department||undefined,
  4989. "contactsInformation": scope.incidentModel.contactsInformation,
  4990. "contacts": scope.incidentModel.contacts,
  4991. "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4992. "area": scope.incidentModel.area||undefined,
  4993. "place": scope.incidentModel.place||undefined,
  4994. "houseNumber": scope.incidentModel.address,
  4995. "category": scope.categorySelect||undefined,
  4996. "priority": scope.incidentModel.priority||undefined,
  4997. "source": scope.incidentModel.source||undefined,
  4998. "title": scope.categorySelect.category,
  4999. "description": scope.incidentModel.description,
  5000. "directProcess": 1,
  5001. "handleDescription": $scope.incidentModel.handlerMsg,
  5002. "handlingPersonnelUser":{id:$scope.incidentModel.handlingPersonnelUser.id},
  5003. "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  5004. "acceptDate": $scope.incidentModel.acceptDate ? moment($scope.incidentModel.acceptDate).format('YYYY-MM-DD HH:mm:ss') : undefined,
  5005. "responseHandleTime": $scope.incidentModel.responseHandleTime ? moment($scope.incidentModel.responseHandleTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  5006. "handleTime": $scope.incidentModel.handleTime ? moment($scope.incidentModel.handleTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  5007. "closecode": $scope.incidentModel.closecode||undefined,
  5008. "repairType": repair_main?repair_main.valueconfig:undefined,
  5009. "acceptUser": $scope.incidentModel.handlingPersonnelUser||undefined,
  5010. "callID": scope.incidentModel.callID||undefined,
  5011. "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  5012. },
  5013. };
  5014. scope.modelData && (postData.incident = Object.assign({}, scope.modelData.incident, postData.incident));
  5015. // if(scope.modelData){
  5016. // // 微信报修转事件
  5017. // postData.flow = scope.modelData.flow;
  5018. // }
  5019. if(!postData.incident.incidentsign){
  5020. let res1 = await api_bpm_domain.workernumber('sj');
  5021. postData.incident.incidentsign = res1.data;
  5022. }
  5023. // api_bpm_domain.workernumber('sj').then(res1=>{
  5024. // postData.incident.incidentsign = res1.data;
  5025. api_flow.accept("patchOrder", postData).then(function (resData) {
  5026. if (scope.uploader != null) {
  5027. // 有图片
  5028. scope.uploader.onBeforeUploadItem = function(item) {
  5029. angular.extend(item.headers, $rootScope.getSession());
  5030. item.url = api_bpm_domain.uploadAttachmentJryModel("wechatRequesterIncident", resData.data.id).getRequestedUrl();
  5031. item.formData.push({ 'fileName': item.file.name });
  5032. };
  5033. scope.uploader.uploadAll();
  5034. }
  5035. var integralMechanism = sessionStorage.getItem('integralMechanism');
  5036. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  5037. api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
  5038. var auditState = res.find(v=>v.value == 0);
  5039. var postData = {
  5040. incidentIntegral: {
  5041. incidentId:resData.bussId,
  5042. auditState:auditState,
  5043. handlerUser:$rootScope.user.id,
  5044. handlerUserName:$rootScope.user.name,
  5045. sourceScore:$scope.complexity,
  5046. currentScore:$scope.complexityConfirm.complexity.value,
  5047. updateReason:$scope.complexityConfirm.updateReason.trim() || undefined,
  5048. }
  5049. }
  5050. console.log(postData)
  5051. api_bpm_data.addData('incidentIntegral', postData).then(function (response) {
  5052. console.log(response)
  5053. $rootScope.isMask = false;
  5054. if (response.status == 200) {
  5055. SweetAlert.swal(
  5056. {
  5057. title: "保存成功!",
  5058. type: "success",
  5059. confirmButtonColor: "#007AFF",
  5060. },
  5061. function (isConfirm) {
  5062. if(isConfirm){
  5063. $modalInstance.dismiss("cancel");
  5064. // 是否连续建单
  5065. if(scope.btns.isBuildOrderAgagin){
  5066. scope.categorySelect = "";
  5067. scope.categorySelectId = 0;
  5068. scope.incidentModel.assign = 1;
  5069. scope.incidentModel.user = "";
  5070. scope.incidentModel.group = "";
  5071. }else{
  5072. if (localStorage.getItem('fenjiNumber')) {
  5073. $rootScope.jry_shixian();
  5074. }
  5075. scope.cancel();
  5076. }
  5077. $rootScope.newOrderShowOpen = false;
  5078. if($state.current.name === 'app.incident.list'){
  5079. $state.reload();
  5080. }else{
  5081. $state.go("app.incident.list");
  5082. }
  5083. }
  5084. }
  5085. );
  5086. } else {
  5087. Alert.swal({
  5088. title: "操作失败",
  5089. text: "操作失败, 请稍后再试!",
  5090. type: "error"
  5091. });
  5092. }
  5093. });
  5094. })
  5095. }else{
  5096. SweetAlert.swal(
  5097. {
  5098. title: "提交成功!",
  5099. type: "success",
  5100. confirmButtonColor: "#007AFF",
  5101. },
  5102. function (isConfirm) {
  5103. if(isConfirm){
  5104. if (localStorage.getItem('fenjiNumber')) {
  5105. $rootScope.jry_shixian();
  5106. }
  5107. scope.cancel();
  5108. $modalInstance.dismiss("cancel");
  5109. $rootScope.newOrderShowOpen = false;
  5110. if($state.current.name === 'app.incident.list'){
  5111. $state.reload();
  5112. }else{
  5113. $state.go("app.incident.list");
  5114. }
  5115. }
  5116. }
  5117. );
  5118. }
  5119. // -------------------------------------------
  5120. $rootScope.isMask = false;
  5121. SweetAlert.swal(
  5122. {
  5123. title: "保存成功!",
  5124. type: "success",
  5125. confirmButtonColor: "#007AFF",
  5126. },
  5127. function (isConfirm) {
  5128. if(isConfirm){
  5129. $modalInstance.dismiss("cancel");
  5130. // 是否连续建单
  5131. if(scope.btns.isBuildOrderAgagin){
  5132. scope.categorySelect = "";
  5133. scope.categorySelectId = 0;
  5134. scope.incidentModel.assign = 1;
  5135. scope.incidentModel.user = "";
  5136. scope.incidentModel.group = "";
  5137. }else{
  5138. if (localStorage.getItem('fenjiNumber')) {
  5139. $rootScope.jry_shixian();
  5140. }
  5141. scope.cancel();
  5142. }
  5143. $rootScope.newOrderShowOpen = false;
  5144. if($state.current.name === 'app.incident.list'){
  5145. $state.reload();
  5146. }else{
  5147. $state.go("app.incident.list");
  5148. }
  5149. }
  5150. }
  5151. );
  5152. });
  5153. // })
  5154. }
  5155. // 取消
  5156. $scope.cancel = function () {
  5157. if (localStorage.getItem('fenjiNumber')) {
  5158. $rootScope.jry_shixian();
  5159. }
  5160. $modalInstance.dismiss("cancel");
  5161. };
  5162. },
  5163. size:'lg',
  5164. resolve: {
  5165. SweetAlert: function () {
  5166. return SweetAlert;
  5167. },
  5168. scope: function(){
  5169. return $scope;
  5170. }
  5171. },
  5172. });
  5173. }
  5174. // 处理顶部责任科室数据
  5175. $scope.handlerDuty = function(){
  5176. if(!$scope.categorySelect){
  5177. return;
  5178. }
  5179. if($scope.categorySelect.branchType == 1){
  5180. // 分院区
  5181. if($scope.incidentModel.branch){
  5182. var dutyConfig = $scope.categorySelect.branchUserGroups.find(v=>v.branchId == $scope.incidentModel.branch.id);
  5183. if(dutyConfig && dutyConfig.dutyId && dutyConfig.dutyName){
  5184. $scope.selectedDuty = {id:dutyConfig.dutyId,dept:dutyConfig.dutyName};
  5185. }else{
  5186. $scope.selectedDuty = null;
  5187. }
  5188. }else{
  5189. $scope.selectedDuty = null;
  5190. }
  5191. }else{
  5192. // 不分院区
  5193. $scope.selectedDuty = $scope.categorySelect.dutyDepartment;
  5194. }
  5195. }
  5196. // 优先级
  5197. $scope.priorityArray = [];
  5198. $scope.jry_prioritySearch = function () {
  5199. api_wechatfile
  5200. .getDictionary({ type: "list", key: "incident_priority" })
  5201. .then(function (data) {
  5202. $scope.priorityArray = data;
  5203. });
  5204. };
  5205. $scope.jry_prioritySearch();
  5206. // 事件来源
  5207. $scope.sourceArray = [];
  5208. $scope.jry_sourceSearch = function () {
  5209. api_wechatfile
  5210. .getDictionary({ type: "list", key: "incident_source" })
  5211. .then(function (data) {
  5212. $scope.sourceArray = data;
  5213. if($scope.incidentModel.source){
  5214. if(!$scope.incidentModel.source.name && $scope.incidentModel.source.id){
  5215. $scope.incidentModel.source = data.find(v=>v.id == $scope.incidentModel.source.id)
  5216. }
  5217. }
  5218. });
  5219. };
  5220. $scope.jry_sourceSearch();
  5221. // 报修科室模糊搜索
  5222. $scope.jry_deptSearch = function (key = "",branchId) {
  5223. console.log(branchId)
  5224. if(!branchId){
  5225. $scope.jry_deptData = [];
  5226. return;
  5227. }
  5228. var deptData = {
  5229. idx: 0,
  5230. sum: 20,
  5231. department: {
  5232. branch:branchId,
  5233. dept:key,
  5234. selectType: "pinyin_qs",
  5235. searchType: "quickStart",
  5236. },
  5237. };
  5238. api_user_data.fetchDataList("department", deptData).then(function (data) {
  5239. $scope.jry_deptData = data.list;
  5240. if($scope.incidentModel.department){
  5241. if(!$scope.incidentModel.department.dept && $scope.incidentModel.department.id){
  5242. // $scope.incidentModel.department = data.list.find(v=>v.id == $scope.incidentModel.department.id)
  5243. api_bpm_data.fetchData('department', $scope.incidentModel.department.id).then(res=>{
  5244. if(res.status == 200){
  5245. $scope.incidentModel.department = res.data;
  5246. }else{
  5247. $scope.incidentModel.department = '';
  5248. }
  5249. })
  5250. }
  5251. }
  5252. });
  5253. };
  5254. // $scope.jry_deptSearch();
  5255. // 报修人模糊搜索
  5256. $scope.jry_requesterSearch = function (key = "",branchId) {
  5257. console.log(branchId)
  5258. if(!branchId){
  5259. $scope.jry_requesterData = [];
  5260. return;
  5261. }
  5262. var postData = {
  5263. idx: 0,
  5264. sum: 10,
  5265. user: {
  5266. branch: { id: branchId },
  5267. name: key,
  5268. selectType: "pinyin_all",
  5269. engineer: undefined,
  5270. dept: $scope.incidentModel ? ($scope.incidentModel.department || undefined) : undefined,
  5271. },
  5272. };
  5273. api_user_data.fetchDataList("user", postData).then(function (data) {
  5274. $scope.jry_requesterData = data.list;
  5275. });
  5276. };
  5277. // $scope.jry_requesterSearch();
  5278. $scope.$watch("incidentModel.requester", function (newVal,oldVal) {
  5279. if(newVal){
  5280. if($scope.modelData && newVal == oldVal){
  5281. }else{
  5282. $scope.incidentModel.contacts = newVal.name;
  5283. // if(!oldVal){
  5284. if(newVal.dept){
  5285. api_bpm_data.fetchData('department', newVal.dept.id).then(res=>{
  5286. if(res.status == 200){
  5287. if($scope.incidentModel.branch.id === res.data.branch){
  5288. $scope.incidentModel.department = res.data;
  5289. }else{
  5290. $scope.incidentModel.department = '';
  5291. }
  5292. }else{
  5293. $scope.incidentModel.department = '';
  5294. }
  5295. })
  5296. }else{
  5297. $scope.incidentModel.department = '';
  5298. }
  5299. // }
  5300. SweetAlert.swal({
  5301. title: "提示",
  5302. text: "是否覆盖联系电话?",
  5303. type: "warning",
  5304. showCancelButton: true,
  5305. confirmButtonColor: "#DD6B55",
  5306. confirmButtonText: "确认覆盖",
  5307. cancelButtonText: "取消操作",
  5308. closeOnConfirm: true,
  5309. closeOnCancel: true
  5310. }, function (isConfirm) {
  5311. if (isConfirm) {
  5312. $scope.incidentModel.contactsInformation = newVal.phone;
  5313. }
  5314. });
  5315. }
  5316. }
  5317. });
  5318. // 处理人模糊搜索
  5319. $scope.jry_userSearch = function (key = "") {
  5320. var userData = {
  5321. idx: 0,
  5322. sum: 1000,
  5323. user: {
  5324. duty: $scope.selectedDuty || undefined,
  5325. roledata: {rolecode: "first-line support"},
  5326. selectDetails:'1',
  5327. simple:true,
  5328. name: key,
  5329. selectType: "pinyin_qs",
  5330. engineer: 1,
  5331. },
  5332. };
  5333. api_user_data.fetchDataList("user", userData).then(function (data) {
  5334. $scope.jry_userData = data.list;
  5335. if($scope.incidentModel.user){
  5336. if(!$scope.incidentModel.user.name){
  5337. $scope.incidentModel.user = data.list.find(v=>v.id == $scope.incidentModel.user.id);
  5338. }
  5339. }
  5340. });
  5341. };
  5342. $scope.jry_userSearch();
  5343. // 处理组模糊搜索
  5344. $scope.jry_groupSearch = function (key = "") {
  5345. var groupData = {
  5346. idx: 0,
  5347. sum: 1000,
  5348. group: {
  5349. duty: $scope.selectedDuty || undefined,
  5350. selectType: "nouser"
  5351. },
  5352. };
  5353. api_user_data.fetchDataList("group", groupData).then(function (data) {
  5354. $scope.jry_groupData = data.list;
  5355. });
  5356. };
  5357. $scope.jry_groupSearch();
  5358. // 院区模糊搜索
  5359. $scope.jry_branchSearch = function (key = "") {
  5360. var postData = {
  5361. idx: 0,
  5362. sum: 1000
  5363. };
  5364. api_user_data.fetchDataList("branch", postData).then(function (data) {
  5365. $scope.jry_branchData = data.list;
  5366. if(modelData && modelData.incident && modelData.incident.department){
  5367. api_bpm_data.fetchData('department', modelData.incident.department.id).then(res=>{
  5368. if(res.status == 200){
  5369. $scope.incidentModel.branch = $scope.jry_branchData.find(v=>v.id == res.data.branch);
  5370. }
  5371. })
  5372. }
  5373. });
  5374. };
  5375. $scope.jry_branchSearch();
  5376. // 区域模糊搜索
  5377. $scope.jry_areaSearch = function (key='',branchId) {
  5378. if(!branchId){
  5379. $scope.jry_areaData = [];
  5380. return;
  5381. }
  5382. var areaData = {
  5383. idx: 0,
  5384. sum: 30,
  5385. area: {
  5386. branch:branchId,
  5387. area:key,
  5388. selectType:'pinyin_qs'
  5389. },
  5390. };
  5391. api_user_data.fetchDataList("area", areaData).then(function (data) {
  5392. $scope.jry_areaData = data.list;
  5393. });
  5394. };
  5395. // 地点模糊搜索
  5396. $scope.jry_placeSearch = function (key='',areaId) {
  5397. if(!areaId){
  5398. $scope.jry_placeData = [];
  5399. return;
  5400. }
  5401. var placeData = {
  5402. idx: 0,
  5403. sum: 30,
  5404. place: {
  5405. place: key,
  5406. areaId: areaId,
  5407. selectType:'pinyin_qs'
  5408. },
  5409. };
  5410. api_user_data.fetchDataList("place", placeData).then(function (data) {
  5411. $scope.jry_placeData = data.list;
  5412. });
  5413. };
  5414. $scope.changeBranch = function(){
  5415. $scope.incidentModel.area = '';
  5416. $scope.incidentModel.place = '';
  5417. $scope.incidentModel.department = '';
  5418. $scope.incidentModel.requester = '';
  5419. $scope.jry_placeData = [];
  5420. }
  5421. $scope.changeDept = function(){
  5422. $scope.incidentModel.requester = '';
  5423. }
  5424. $scope.changeArea = function(){
  5425. $scope.incidentModel.place = '';
  5426. }
  5427. $scope.$watch("incidentModel.branch", function (newVal,oldVal) {
  5428. $scope.handlerDuty();
  5429. $scope.showUserOrGroup();
  5430. newVal && $scope.jry_areaSearch('',newVal.id);
  5431. newVal && $scope.jry_deptSearch('',newVal.id);
  5432. newVal && $scope.jry_requesterSearch('',newVal.id);
  5433. });
  5434. $scope.$watch("incidentModel.area", function (newVal,oldVal) {
  5435. newVal && $scope.jry_placeSearch('',newVal.id);
  5436. console.log(modelData, $scope.oldDept,$scope.incidentModel)
  5437. });
  5438. $scope.$watch("categorySelect", function (newVal,oldVal) {
  5439. if(newVal&&newVal.priority){
  5440. // 回显优先级
  5441. $scope.incidentModel.priority = newVal.priority;
  5442. }
  5443. // 选择了院区,科室,故障现象,责任科室
  5444. $scope.showUserOrGroup();
  5445. // 回显人员
  5446. if($scope.incidentModel.user){
  5447. if(!$scope.incidentModel.user.name){
  5448. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == $scope.incidentModel.user.id);
  5449. }
  5450. }
  5451. });
  5452. // 派人或派组
  5453. async function assignCommon(sj){
  5454. console.log(sj);
  5455. if(!sj){return;}
  5456. await $scope.userAndGroupSearch();
  5457. if (sj.branchType == 0) {
  5458. if (sj.userOrGroupType === 1) {
  5459. //派人
  5460. $scope.incidentModel.assign = 1;
  5461. $scope.incidentModel.user = sj.handleUser ? $scope.jry_userData.find(v=>v.id == sj.handleUser.id) : "";
  5462. } else if (sj.userOrGroupType === 2) {
  5463. //派组
  5464. $scope.incidentModel.assign = 2;
  5465. $scope.incidentModel.group = sj.group ? sj.group : "";
  5466. } else {
  5467. $scope.incidentModel.assign = 0;
  5468. $scope.incidentModel.user = "";
  5469. $scope.incidentModel.group = "";
  5470. }
  5471. } else if (sj.branchType == 1) {
  5472. // 分院区
  5473. // 选择了院区
  5474. if ($scope.incidentModel.branch) {
  5475. let branchId = $scope.incidentModel.branch.id;
  5476. let branchUserGroup =
  5477. sj.branchUserGroups.find(v => v.branchId == branchId) || {};
  5478. if (branchUserGroup.branchUserOrGroupType == 1) {
  5479. //派人
  5480. $scope.incidentModel.assign = 1;
  5481. console.log($scope.jry_userData)
  5482. $scope.incidentModel.user = branchUserGroup.userId
  5483. ? $scope.jry_userData.find(v=>v.id == branchUserGroup.userId)
  5484. : "";
  5485. } else if (branchUserGroup.branchUserOrGroupType === 2) {
  5486. //派组
  5487. $scope.incidentModel.assign = 2;
  5488. $scope.incidentModel.group = branchUserGroup.groupId
  5489. ? {id:branchUserGroup.groupId,groupName:branchUserGroup.groupName}
  5490. : "";
  5491. } else {
  5492. $scope.incidentModel.assign = 1;
  5493. $scope.incidentModel.user = "";
  5494. $scope.incidentModel.group = "";
  5495. }
  5496. } else {
  5497. $scope.incidentModel.assign = 1;
  5498. $scope.incidentModel.user = "";
  5499. $scope.incidentModel.group = "";
  5500. }
  5501. }
  5502. }
  5503. // 取消故障描述弹窗
  5504. $scope.isShowAlertMask = false;
  5505. $scope.copyItem = null;
  5506. $scope.cancelAlertMask = function(){
  5507. $scope.isShowAlertMask = false;
  5508. }
  5509. // 覆盖
  5510. $scope.overlayAlertMask = function(){
  5511. $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  5512. $scope.isShowAlertMask = false;
  5513. }
  5514. // 前覆盖
  5515. $scope.overlayLeftAlertMask = function(){
  5516. $scope.incidentModel.description = $scope.copyItem.mutiCategory + $scope.incidentModel.description;
  5517. $scope.isShowAlertMask = false;
  5518. }
  5519. // 后覆盖
  5520. $scope.overlayRightAlertMask = function(){
  5521. $scope.incidentModel.description = $scope.incidentModel.description + $scope.copyItem.mutiCategory;
  5522. $scope.isShowAlertMask = false;
  5523. }
  5524. // 故障现象选中
  5525. $scope.categorySelectId = 0;
  5526. $scope.categorySelect = "";
  5527. $scope.selectedDuty = null;//选择故障现象后的责任科室
  5528. $scope.changeCategorySelect = function(item){
  5529. $scope.copyItem = angular.copy(item);
  5530. $scope.copyItem.mutiCategory = $scope.copyItem.mutiCategory.replace(/<[^<>]+>/g,'');
  5531. if($scope.incidentModel.description){
  5532. $scope.isShowAlertMask = true;
  5533. // SweetAlert.swal({
  5534. // title: "提示",
  5535. // text: "是否覆盖故障描述?",
  5536. // type: "warning",
  5537. // showCancelButton: true,
  5538. // confirmButtonColor: "#DD6B55",
  5539. // confirmButtonText: "确认覆盖",
  5540. // cancelButtonText: "取消操作",
  5541. // closeOnConfirm: true,
  5542. // closeOnCancel: true
  5543. // }, function (isConfirm) {
  5544. // if (isConfirm) {
  5545. // $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  5546. // }
  5547. // });
  5548. }else{
  5549. $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  5550. }
  5551. $scope.categorySelect = $scope.copyItem;
  5552. $scope.categorySelectId = $scope.copyItem.id;
  5553. // 处理责任科室数据
  5554. $scope.handlerDuty();
  5555. if($scope.selectTab == 2){
  5556. $scope.jry_solution($scope.categorySelect.id);
  5557. }
  5558. }
  5559. // 故障现象查询
  5560. $scope.c_timer = null;
  5561. $scope.c_keyword = '';
  5562. $scope.jry_categorySearch = function (key = '') {
  5563. $scope.c_keyword = key;
  5564. clearTimeout($scope.c_timer);
  5565. $scope.c_timer = setTimeout(()=>{
  5566. var categoryData = {
  5567. idx: 0,
  5568. sum: 9999,
  5569. incidentcategory: {
  5570. category: key,
  5571. selectType:'pinyin_qs',
  5572. hierarchyQuery:'three'
  5573. },
  5574. };
  5575. if($rootScope.user.duty){
  5576. categoryData.incidentcategory.dutyDepartment = $rootScope.user.duty;
  5577. }else if($rootScope.user.branch){
  5578. // categoryData.incidentcategory.branch = $rootScope.user.branch.id;
  5579. }
  5580. $scope.loading_c = true;
  5581. api_user_data.fetchDataList("incidentcategory", categoryData).then(function (data) {
  5582. if($scope.c_keyword == key){
  5583. $scope.loading_c = false;
  5584. data.list.forEach(v=>{
  5585. if(v.mutiCategory){
  5586. v.mutiCategory = v.mutiCategory.replace($scope.jry_modelLeft,'<span class="colorRed">'+$scope.jry_modelLeft+'</span>');
  5587. }
  5588. })
  5589. $scope.jry_categoryData = data.list;
  5590. if(modelData){
  5591. if( modelData.incident.category && !modelData.incident.category.complexity){
  5592. $scope.categorySelect = data.list.find(v=>v.id == modelData.incident.category.id);
  5593. if($scope.categorySelect){
  5594. $scope.categorySelectId = $scope.categorySelect.id;
  5595. }
  5596. }
  5597. }
  5598. }
  5599. });
  5600. },500)
  5601. };
  5602. $scope.jry_categorySearch($scope.jry_modelLeft);
  5603. // 右侧tab选中
  5604. $scope.selectTab = 1;
  5605. $scope.changeTab = function(id){
  5606. $scope.selectTab = id;
  5607. if(id == 1){
  5608. $scope.jry_incident($scope.incidentModel.department?$scope.incidentModel.department.id:undefined);
  5609. }else if(id == 2){
  5610. $scope.jry_solution($scope.categorySelect?$scope.categorySelect.id:undefined);
  5611. }
  5612. }
  5613. // 近期报修
  5614. $scope.jry_incident = function (deptId) {
  5615. $scope.loading_i = true;
  5616. var placeData = {
  5617. idx: 0,
  5618. sum: 6,
  5619. incident: {
  5620. department: {id:deptId},
  5621. },
  5622. };
  5623. api_user_data.fetchDataList("incident", placeData).then(function (data) {
  5624. $scope.loading_i = false;
  5625. data.list.forEach(v=>{
  5626. v.acceptDate = moment(v.acceptDate).format('MM-DD HH:mm')
  5627. })
  5628. $scope.jry_incidentData = data.list;
  5629. });
  5630. };
  5631. $scope.$watch("incidentModel.department", function (newVal,oldVal) {
  5632. $scope.showUserOrGroup();
  5633. newVal && $scope.jry_incident(newVal.id);
  5634. console.log(newVal);
  5635. if($scope.modelData && newVal == oldVal){
  5636. }else{
  5637. $scope.jry_requesterSearch('', $scope.incidentModel.branch.id)
  5638. if(newVal){
  5639. if($scope.incidentModel.department){
  5640. if($scope.incidentModel.department.place){
  5641. $scope.incidentModel.place = $scope.incidentModel.department.place;
  5642. $scope.incidentModel.area = $scope.incidentModel.department.place.area;
  5643. }else{
  5644. $scope.incidentModel.place = '';
  5645. $scope.incidentModel.area = '';
  5646. }
  5647. $scope.incidentModel.address = $scope.incidentModel.department.address || '';
  5648. // 如果回显的有联系电话,联系电话不用科室带出
  5649. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = ($scope.incidentModel.department.phone)?$scope.incidentModel.department.phone.split(',')[0]:'');
  5650. }else{
  5651. $scope.incidentModel.place = '';
  5652. $scope.incidentModel.area = '';
  5653. $scope.incidentModel.address = '';
  5654. // 如果回显的有联系电话,联系电话不用科室带出
  5655. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  5656. }
  5657. // api_bpm_data.fetchData('department', $scope.incidentModel.department.id).then(res=>{
  5658. // if(res.status == 200){
  5659. // // $scope.incidentModel.department = res.data;
  5660. // if(res.data && res.data.place){
  5661. // $scope.incidentModel.place = res.data.place;
  5662. // $scope.incidentModel.area = res.data.place.area;
  5663. // }else{
  5664. // $scope.incidentModel.place = '';
  5665. // $scope.incidentModel.area = '';
  5666. // }
  5667. // $scope.incidentModel.address = res.data.address || '';
  5668. // // 如果回显的有联系电话,联系电话不用科室带出
  5669. // !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (res.data&&res.data.phone)?res.data.phone.split(',')[0]:'');
  5670. // }else{
  5671. // $scope.incidentModel.place = '';
  5672. // $scope.incidentModel.area = '';
  5673. // $scope.incidentModel.address = '';
  5674. // // 如果回显的有联系电话,联系电话不用科室带出
  5675. // !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  5676. // }
  5677. // })
  5678. }else{
  5679. $scope.incidentModel.place = '';
  5680. $scope.incidentModel.area = '';
  5681. $scope.incidentModel.address = '';
  5682. // 如果回显的有联系电话,联系电话不用科室带出
  5683. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  5684. }
  5685. // if(newVal && newVal.place){
  5686. // $scope.incidentModel.place = newVal.place;
  5687. // $scope.incidentModel.area = newVal.place.area;
  5688. // }else{
  5689. // $scope.incidentModel.place = '';
  5690. // $scope.incidentModel.area = '';
  5691. // }
  5692. // // 如果回显的有联系电话,联系电话不用科室带出
  5693. // !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  5694. }
  5695. });
  5696. // 知识库
  5697. $scope.jry_solution = function (id,key='') {
  5698. $scope.loading_i = true;
  5699. var placeData = {
  5700. idx: 0,
  5701. sum: 1000,
  5702. solution: {
  5703. threeSearch:key,
  5704. status: {id: 72},
  5705. selectType: "keySearch",
  5706. },
  5707. };
  5708. if(id){
  5709. placeData.solution.category = {id:id};
  5710. }
  5711. api_user_data.fetchDataList("solution", placeData).then(function (data) {
  5712. $scope.loading_i = false;
  5713. $scope.jry_solutionData = data.list;
  5714. });
  5715. };
  5716. // getFileFromBase64($scope.imgshows[0],'tt')
  5717. // 图片上传
  5718. $scope.imgshows = [];
  5719. $scope.uploadimgs = [];
  5720. var model = $parse("upload_img");
  5721. var modelSetter = model.assign;
  5722. var uploader = ($scope.uploader = new FileUploader({
  5723. url: "/uploader",
  5724. }));
  5725. // uploader.filters.push({
  5726. // name: "customFilter",
  5727. // fn: function (item /*{File|FileLikeObject}*/, options) {
  5728. // return this.queue.length < 10;
  5729. // },
  5730. // });
  5731. $scope.getDetail = function(imgs){
  5732. function getImageFileFromUrl(url, imageName, callback) {
  5733. // imageName一定要带上后缀
  5734. var blob = null
  5735. var xhr = new XMLHttpRequest()
  5736. xhr.open('GET', url)
  5737. xhr.setRequestHeader('Accept', 'image/jpeg')
  5738. xhr.responseType = 'blob'
  5739. xhr.onload = () => {
  5740. if (xhr.status === 200) {
  5741. blob = xhr.response
  5742. let imgFile = new File([blob], imageName, {type: 'image/jpeg'})
  5743. console.log(imgFile)
  5744. callback.call(this, imgFile)
  5745. }
  5746. }
  5747. xhr.send()
  5748. }
  5749. imgs.forEach((v,i)=>{
  5750. v.previewUrl = $rootScope.attachmentAddressSplicing(v.relativeFilePath);
  5751. getImageFileFromUrl(v.previewUrl,v.name,function(file){
  5752. var dummy = new FileUploader.FileItem(uploader, file);
  5753. uploader.queue.push(dummy);
  5754. getFile(file, $scope);
  5755. })
  5756. })
  5757. //获得预览图地址并且把file对象放入上传合集内
  5758. function getFile(imgupload, $scope) {
  5759. if (!imgupload) {
  5760. return;
  5761. }
  5762. fileReader.readAsDataUrl(imgupload, $scope).then(function (result) {
  5763. console.log(result)
  5764. $scope.imgshows.push(result);
  5765. var file = imgupload;
  5766. $scope.uploadimgs.push(file); //这里是放着传给后台的数据file,下面controller的时候会有
  5767. console.log($scope.imgshows, $scope.uploadimgs);
  5768. if ($scope.imgshows.length < 3) {
  5769. $("#upupgogo").show();
  5770. } else {
  5771. $("#upupgogo").hide();
  5772. }
  5773. });
  5774. }
  5775. }
  5776. // 是否回显报修端图片
  5777. // if(modelData){
  5778. // if (modelData.flow) {
  5779. // api_wechatfile
  5780. // .listAttachment("wechatRequesterIncident", modelData.flow)
  5781. // .then(function (res) {
  5782. // $scope.getDetail(res.data)
  5783. // });
  5784. // }
  5785. // }
  5786. // 添加
  5787. $scope.change = function (event) {
  5788. var element = $(".upinp");
  5789. modelSetter($scope, element[0].files[0]);
  5790. //附件预览
  5791. $scope.imgupload = event.files[0];
  5792. getFile($scope.imgupload, $scope);
  5793. //获得预览图地址并且把file对象放入上传合集内
  5794. function getFile(imgupload, $scope) {
  5795. if (!imgupload) {
  5796. return;
  5797. }
  5798. fileReader.readAsDataUrl(imgupload, $scope).then(function (result) {
  5799. console.log(result)
  5800. $scope.imgshows.push(result);
  5801. var file = document.querySelector("#upupgogo input[type=file]").files[0];
  5802. $scope.uploadimgs.push(file); //这里是放着传给后台的数据file,下面controller的时候会有
  5803. console.log($scope.imgshows, $scope.uploadimgs);
  5804. if ($scope.imgshows.length < 3) {
  5805. $("#upupgogo").show();
  5806. } else {
  5807. $("#upupgogo").hide();
  5808. }
  5809. });
  5810. }
  5811. };
  5812. // 删除
  5813. $scope.uploadimg_del = function (index, imgs) {
  5814. console.log(index, imgs);
  5815. $scope.imgshows.splice(index, 1);
  5816. $scope.uploadimgs.splice(index, 1);
  5817. $scope.uploader.queue.splice(index, 1);
  5818. if ($scope.imgshows.length < 3) {
  5819. $("#upupgogo").show();
  5820. } else {
  5821. $("#upupgogo").hide();
  5822. }
  5823. };
  5824. // 预览
  5825. $scope.preview = function (url, idx) {
  5826. var name = $scope.uploadimgs[idx].name;
  5827. $modal.open({
  5828. backdrop: false,
  5829. templateUrl: "assets/views/customform/tpl/ui-showimage.html",
  5830. controller: function ($scope, scope, $modalInstance) {
  5831. //创建一个标签用来加载图片
  5832. const image = document.createElement("img");
  5833. image.src = url
  5834. //待图片加载完成读取图片的真实宽高。
  5835. image.addEventListener("load", function(e) {
  5836. $scope.imgWidth = e.target.width + 'px';
  5837. $scope.imgHeight = e.target.height + 'px';
  5838. })
  5839. $scope.title = name;
  5840. $scope.imageurl = url;
  5841. $scope.cancel = function () {
  5842. $modalInstance.dismiss("cancel");
  5843. };
  5844. },
  5845. resolve: {
  5846. scope: function () {
  5847. return $scope;
  5848. },
  5849. },
  5850. });
  5851. };
  5852. if (uploader) {
  5853. uploader.onWhenAddingFileFailed = function (
  5854. item /*{File|FileLikeObject}*/,
  5855. filter,
  5856. options
  5857. ) {
  5858. console.info("onWhenAddingFileFailed", item, filter, options);
  5859. };
  5860. uploader.onAfterAddingFile = function (fileItem) {
  5861. console.info("onAfterAddingFile", fileItem);
  5862. };
  5863. uploader.onAfterAddingAll = function (addedFileItems) {
  5864. console.info("onAfterAddingAll", addedFileItems);
  5865. };
  5866. uploader.onBeforeUploadItem = function (item) {
  5867. console.info("onBeforeUploadItem", item);
  5868. };
  5869. uploader.onProgressItem = function (fileItem, progress) {
  5870. console.info("onProgressItem", fileItem, progress);
  5871. };
  5872. uploader.onProgressAll = function (progress) {
  5873. console.info("onProgressAll", progress);
  5874. };
  5875. uploader.onSuccessItem = function (
  5876. fileItem,
  5877. response,
  5878. status,
  5879. headers
  5880. ) {
  5881. console.info("onSuccessItem", fileItem, response, status, headers);
  5882. };
  5883. uploader.onErrorItem = function (
  5884. fileItem,
  5885. response,
  5886. status,
  5887. headers
  5888. ) {
  5889. console.info("onErrorItem", fileItem, response, status, headers);
  5890. };
  5891. uploader.onCancelItem = function (
  5892. fileItem,
  5893. response,
  5894. status,
  5895. headers
  5896. ) {
  5897. console.info("onCancelItem", fileItem, response, status, headers);
  5898. };
  5899. uploader.onCompleteItem = function (
  5900. fileItem,
  5901. response,
  5902. status,
  5903. headers
  5904. ) {
  5905. console.info("onCompleteItem", fileItem, response, status, headers);
  5906. };
  5907. uploader.onCompleteAll = function () {
  5908. console.info("onCompleteAll");
  5909. };
  5910. }
  5911. // 取消
  5912. $scope.cancel = function () {
  5913. if (localStorage.getItem('fenjiNumber')) {
  5914. $rootScope.jry_shixian();
  5915. }
  5916. $rootScope.newOrderShowOpen = false;
  5917. $modalInstance.dismiss("cancel");
  5918. };
  5919. // -------------------end----------------------
  5920. },
  5921. resolve: {
  5922. modelData:function(){
  5923. return model1;
  5924. }
  5925. },
  5926. });
  5927. }
  5928. // 事件实时播报
  5929. $rootScope.realtimeBroadcast = function(){
  5930. location.href = location.origin+'/#/bigScreen/realtimeBroadcast';
  5931. // window.open(location.origin+'/#/bigScreen/realtimeBroadcast');
  5932. }
  5933. // save settings to local storage
  5934. if (angular.isDefined($localStorage.layout)) {
  5935. $scope.app.layout = $localStorage.layout;
  5936. } else {
  5937. $localStorage.layout = $scope.app.layout;
  5938. }
  5939. $scope.$watch('app.layout', function () {
  5940. // save to local storage
  5941. $localStorage.layout = $scope.app.layout;
  5942. }, true);
  5943. //global function to scroll page up
  5944. $scope.toTheTop = function () {
  5945. $document.scrollTopAnimated(0, 600);
  5946. };
  5947. // angular translate
  5948. // ----------------------
  5949. $scope.language = {
  5950. // Handles language dropdown
  5951. listIsOpen: false,
  5952. // list of available languages
  5953. available: {
  5954. 'en': 'English',
  5955. 'it_IT': 'Italiano',
  5956. 'de_DE': 'Deutsch',
  5957. 'zh_cn': 'Chinese'
  5958. },
  5959. // display always the current ui language
  5960. init: function () {
  5961. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  5962. var preferredLanguage = $translate.preferredLanguage();
  5963. // we know we have set a preferred one in app.config
  5964. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  5965. },
  5966. set: function (localeId, ev) {
  5967. $translate.use(localeId);
  5968. $scope.language.selected = $scope.language.available[localeId];
  5969. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  5970. }
  5971. };
  5972. $scope.language.init();
  5973. // Function that find the exact height and width of the viewport in a cross-browser way
  5974. var viewport = function () {
  5975. var e = window,
  5976. a = 'inner';
  5977. if (!('innerWidth' in window)) {
  5978. a = 'client';
  5979. e = document.documentElement || document.body;
  5980. }
  5981. return {
  5982. width: e[a + 'Width'],
  5983. height: e[a + 'Height']
  5984. };
  5985. };
  5986. // function that adds information in a scope of the height and width of the page
  5987. $scope.getWindowDimensions = function () {
  5988. return {
  5989. 'h': viewport().height,
  5990. 'w': viewport().width
  5991. };
  5992. };
  5993. // Detect when window is resized and set some variables
  5994. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  5995. $scope.windowHeight = newValue.h;
  5996. $scope.windowWidth = newValue.w;
  5997. if (newValue.w >= 992) {
  5998. $scope.isLargeDevice = true;
  5999. } else {
  6000. $scope.isLargeDevice = false;
  6001. }
  6002. if (newValue.w < 992) {
  6003. $scope.isSmallDevice = true;
  6004. } else {
  6005. $scope.isSmallDevice = false;
  6006. }
  6007. if (newValue.w <= 768) {
  6008. $scope.isMobileDevice = true;
  6009. } else {
  6010. $scope.isMobileDevice = false;
  6011. }
  6012. }, true);
  6013. // Apply on resize
  6014. $win.on('resize', function () {
  6015. $scope.$apply();
  6016. });
  6017. $rootScope.app.layout.isNavbarFixed = false;
  6018. $rootScope.app.layout.isSidebarFixed = false;
  6019. $rootScope.app.layout.isFooterFixed = false;
  6020. $scope.login_signquick = function (Requesteruserinform) {
  6021. $rootScope.statuscall = 1;
  6022. $scope.loginForm = {
  6023. username: Requesteruserinform.username,
  6024. password: Requesteruserinform.password
  6025. }
  6026. $auth.submitLogin($scope.loginForm)
  6027. .then(function (resp) {
  6028. localStorage.setItem("jry_user", JSON.stringify(resp));
  6029. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  6030. $rootScope.isRealtimeBroadcast = ($rootScope.user && $rootScope.user.menu)?$rootScope.user.menu.some(v => v.link == 'realtimeBroadcast'):false;
  6031. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  6032. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  6033. var onlyMenu = [];
  6034. for (var i = 0; i < allJurisdiction.length; i++) {
  6035. if (allJurisdiction[i].event == "1") {
  6036. onlyMenu.push(allJurisdiction[i])
  6037. }
  6038. };
  6039. $rootScope.userMenus = onlyMenu;
  6040. getMenus();
  6041. if (resp.error != 500) {
  6042. // $state.go('app.dashboard');
  6043. $rootScope.app.isLoginFixed = false;
  6044. } else {
  6045. resp.error = "";
  6046. $scope.loginForm.password = "";
  6047. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  6048. }
  6049. })
  6050. .catch(function (resp) {
  6051. $scope.loginForm.password = "";
  6052. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  6053. });
  6054. }
  6055. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  6056. var theRequest = {};
  6057. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  6058. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  6059. var str = url.substr(index + 1);
  6060. var strs = str.split("&");
  6061. for (var i = 0; i < strs.length; i++) {
  6062. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  6063. }
  6064. // return theRequest;
  6065. $scope.login_signquick(theRequest)
  6066. }
  6067. // $scope.casUserId = window.location.search;
  6068. // $scope.loginForm = {
  6069. // username: theRequest[0].split("=")[1],
  6070. // password: theRequest[1].split("=")[1]
  6071. // }
  6072. // $scope.lodingstyle = 'nodata';
  6073. var userAgent = window.navigator.userAgent.toLowerCase();
  6074. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  6075. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  6076. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  6077. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  6078. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  6079. if (isOpera) {
  6080. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  6081. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  6082. }
  6083. if (isIE) {
  6084. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  6085. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  6086. }
  6087. if (isFF) {
  6088. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  6089. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  6090. }
  6091. if (isSafari) {
  6092. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  6093. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  6094. }
  6095. if (isChrome) {
  6096. // login_sign();
  6097. $rootScope.app.isChrome = false;
  6098. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  6099. } else {
  6100. $rootScope.app.isChrome = true;
  6101. $scope.checkchrome = '';
  6102. // return alert("访问失败,请用Chrome浏览器访问!");
  6103. }
  6104. // }
  6105. // $scope.handleloginEnter = function(e) {
  6106. // if (e.keyCode == 13) {
  6107. // $scope.handleLoginClick();
  6108. // }
  6109. // };
  6110. // if (document.getElementById("isWatch").value == "true") {
  6111. // $scope.isHanderuser = true;
  6112. // } else {
  6113. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  6114. // $scope.isHanderuser = false;
  6115. // $scope.login_sign();
  6116. // }
  6117. // }
  6118. // $scope.viewType = "password";
  6119. // $scope.isPassword = true;
  6120. // $scope.toggleView = function() {
  6121. // $scope.isPassword = !$scope.isPassword;
  6122. // $scope.viewType = $scope.isPassword ? "password" : "text";
  6123. // }
  6124. // $scope.handleSignOutBtnClick = function() {
  6125. // $auth.signOut()
  6126. // .then(function(resp) {
  6127. // // handle success response
  6128. // })
  6129. // .catch(function(resp) {
  6130. // // handle error response
  6131. // });
  6132. // };
  6133. // }
  6134. // }
  6135. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  6136. // } else {
  6137. // $scope.loginstart();
  6138. // }
  6139. //websocket 信息中心
  6140. console.log(atmosphere)
  6141. var socket = atmosphere;
  6142. var subSocket;
  6143. // We are now ready to cut the request
  6144. var request = {
  6145. url: 'ws://192.168.199.150:8080/messagestation/cache',
  6146. contentType: "application/json",
  6147. shared: true, // 标签共享
  6148. trackMessageLength: true, //校验数据完整性
  6149. transport: 'websocket'
  6150. };
  6151. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  6152. request.onOpen = function (response) {
  6153. console.log(response)
  6154. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  6155. // alert("开始连接")
  6156. };
  6157. request.onMessage = function (response) {
  6158. var message = response.responseBody;
  6159. // alert("连接成功")
  6160. console.log(message)
  6161. try {
  6162. var json = JSON.parse(message);
  6163. console.log(json.noRead)
  6164. $scope.noReadData = json.noRead
  6165. } catch (e) {
  6166. console.log('呵呵哒: ', message);
  6167. return;
  6168. }
  6169. };
  6170. request.onClose = function (response) {
  6171. // alert("连接结束")
  6172. }
  6173. request.onError = function (response) {
  6174. // alert('连接失败')
  6175. };
  6176. //信息中心模态框
  6177. var loginUser = $rootScope.user;
  6178. // if(loginUser){
  6179. // // 未读消息数量
  6180. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  6181. // if (data.status == 200) {
  6182. // $scope.noReadData=data.totalNum
  6183. // // $rootScope.option.all = $rootScope.all;
  6184. // } else {
  6185. // $scope.noReadData=0
  6186. // }
  6187. // })
  6188. // }
  6189. // $scope.noReadData=($rootScope.noReadData||0)
  6190. // // $rootScope.all = 5;
  6191. // setTimeout(function() {
  6192. // console.log($scope.noReadData)
  6193. // }, 500)
  6194. $rootScope.wt_messages = function () {
  6195. var modalInstance = $modal.open({
  6196. templateUrl: '../../../assets/views/wt_messages.html',
  6197. controller: function ($scope, $modalInstance, SweetAlert) {
  6198. $rootScope.msgData = {
  6199. idx: 0,
  6200. sum: 5,
  6201. messageStation: {
  6202. readStatus: 0,
  6203. userId: $rootScope.user.id
  6204. }
  6205. }
  6206. // 关闭
  6207. $scope.closeModel = function () {
  6208. modalInstance.close();
  6209. }
  6210. $scope.getMsgData = function () {
  6211. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  6212. if (data) {
  6213. $rootScope.msg = data.list
  6214. $rootScope.all = data.pageCount;
  6215. $scope.wt_msgData = data
  6216. $rootScope.noReadData = data.totalNum
  6217. }
  6218. })
  6219. }
  6220. $scope.getMsgData()
  6221. $scope.message_type = 2;
  6222. $scope.message_no = function (type) { //未读1
  6223. $scope.wt_msgData = {};
  6224. $scope.message_type = type;
  6225. $rootScope.msgData.messageStation.readStatus = 0,
  6226. // $rootScope.option.curr = 1;
  6227. $rootScope.msgData.idx = 0;
  6228. // console.log($rootScope.option.curr)
  6229. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  6230. $scope.msg_yesType = true;
  6231. if (data.status == 200) {
  6232. $scope.msg_yesType = false
  6233. $scope.wt_msgData = data
  6234. $rootScope.msg = data.list
  6235. $rootScope.all = data.pageCount;
  6236. $rootScope.noReadData = data.totalNum;
  6237. // $rootScope.option.all = $rootScope.all;
  6238. } else {
  6239. $scope.msg_yesType = true;
  6240. }
  6241. })
  6242. }
  6243. $scope.message_yes = function (type) { //已读0
  6244. $scope.wt_msgData = {};
  6245. $scope.message_type = type;
  6246. $rootScope.msgData.messageStation.readStatus = 1,
  6247. $rootScope.msgData.idx = 0;
  6248. // $rootScope.option.curr = 1;
  6249. // console.log($rootScope.option.curr)
  6250. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  6251. $scope.msg_noType = true;
  6252. if (data.status == 200) {
  6253. $scope.msg_noType = false
  6254. $scope.wt_msgData = data
  6255. $rootScope.msg = data.list;
  6256. $rootScope.all = data.pageCount;
  6257. // $rootScope.option.all = $rootScope.all;
  6258. } else {
  6259. $scope.msg_noType = true
  6260. }
  6261. })
  6262. };
  6263. $scope.sBtn = function () {
  6264. // console.log($rootScope.msgData)
  6265. // console.log($scope.wt_msgData)
  6266. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  6267. console.log($rootScope.msgData)
  6268. $scope.getMsgData()
  6269. }
  6270. $scope.xBtn = function () {
  6271. // console.log($rootScope.msgData)
  6272. // console.log($scope.wt_msgData)
  6273. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  6274. console.log($rootScope.msgData)
  6275. $scope.getMsgData()
  6276. }
  6277. $scope.redIn = function (data) {
  6278. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  6279. $scope.messageStation = {
  6280. messageStation: {
  6281. id: data.id,
  6282. readStatus: 1,
  6283. readTime: start
  6284. }
  6285. }
  6286. api_msg.updateDataList($scope.messageStation).then(function (data) {
  6287. console.log(data);
  6288. if (data.status == 200) {
  6289. $rootScope.msgData.messageStation.readStatus = 0,
  6290. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  6291. $rootScope.msg = data.list
  6292. $rootScope.all = data.pageCount;
  6293. $rootScope.noReadData = data.totalNum;
  6294. })
  6295. }
  6296. })
  6297. };
  6298. // 一键已读
  6299. $scope.redAllIn = function () {
  6300. SweetAlert.swal({
  6301. title: "是否确认?",
  6302. type: "warning",
  6303. showCancelButton: true,
  6304. confirmButtonColor: "#DD6B55",
  6305. confirmButtonText: "确认",
  6306. cancelButtonText: "取消",
  6307. closeOnConfirm: true,
  6308. closeOnCancel: true
  6309. }, function (isConfirm) {
  6310. if (isConfirm) {
  6311. $rootScope.isMask = true;
  6312. api_msg.oneClickRead({userId: $rootScope.user.id}).then(function (data) {
  6313. $rootScope.isMask = false;
  6314. if (data.status == 200) {
  6315. $rootScope.msgData.messageStation.readStatus = 0,
  6316. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  6317. $scope.wt_msgData = data
  6318. $rootScope.msg = data.list
  6319. $rootScope.all = data.pageCount;
  6320. $rootScope.noReadData = data.totalNum;
  6321. })
  6322. }
  6323. })
  6324. } else {}
  6325. });
  6326. };
  6327. },
  6328. size: 'lg',
  6329. resolve: {
  6330. }
  6331. })
  6332. }
  6333. }
  6334. ]);
  6335. // 录音盒子
  6336. app.service('WebsocketPhoneService', function () {
  6337. return {
  6338. lockReconnect: false, //避免ws重复连接
  6339. ws: null, //定义websocket
  6340. url: "", //ws连接地址
  6341. urlParams: null, //ws连接传参
  6342. isHandler: false, //是否手动
  6343. subject: null,
  6344. reconnectTimer: null,//重连的计时器
  6345. // 连接websocket
  6346. connectWs(url, data) {
  6347. this.url = url;
  6348. this.urlParams = data;
  6349. this.subject = new rxjs.Subject();
  6350. let request = {
  6351. webSocketUrl: url,
  6352. trackMessageLength: true, //校验数据完整性
  6353. transport: "websocket",
  6354. handleOnlineOffline: false,
  6355. suspend: false,
  6356. maxReconnectOnClose: 0,
  6357. };
  6358. request.onOpen = (response) => {
  6359. console.log("ws连接成功" + new Date().toLocaleString());
  6360. this.heartCheck.reset().start(this);
  6361. console.log(response);
  6362. this.ws.push(JSON.stringify(data));
  6363. };
  6364. request.onMessage = (response) => {
  6365. this.heartCheck.reset().start(this);
  6366. let message = response.responseBody;
  6367. try {
  6368. console.log("收到消息" + message);
  6369. if (message !== "pong") {
  6370. this.subject.next(JSON.parse(message));
  6371. }
  6372. } catch (e) {
  6373. console.log("This doesn't look like a valid JSON: ", message);
  6374. return;
  6375. }
  6376. };
  6377. request.onClose = (response) => {
  6378. console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
  6379. this.ws = null;
  6380. console.log(response)
  6381. if (!this.isHandler && response.status === 408) {
  6382. this.reconnect(this.url, this.urlParams);
  6383. }
  6384. };
  6385. request.onError = (response) => {
  6386. console.log("ws连接错误", this.isHandler);
  6387. this.ws = null;
  6388. if (response.status === 0) {
  6389. this.reconnect(this.url, this.urlParams);
  6390. }
  6391. };
  6392. this.ws = atmosphere.subscribe(request);
  6393. return this.subject.asObservable();
  6394. },
  6395. //断线重连
  6396. reconnect(url, data) {
  6397. if (this.lockReconnect) return;
  6398. this.lockReconnect = true;
  6399. this.reconnectTimer = setTimeout(() => {
  6400. //没连接上会一直重连,设置延迟避免请求过多
  6401. this.connectWs(url, data);
  6402. this.lockReconnect = false;
  6403. }, 15000);
  6404. },
  6405. heartCheck: {
  6406. timeout: 30000, //发一次心跳的间隔时间
  6407. timeoutObj: null,
  6408. serverTimeoutObj: null,
  6409. reset: function () {
  6410. clearTimeout(this.timeoutObj);
  6411. clearTimeout(this.serverTimeoutObj);
  6412. return this;
  6413. },
  6414. start: function (_this) {
  6415. this.timeoutObj = setTimeout(() => {
  6416. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  6417. //onmessage拿到返回的心跳就说明连接正常
  6418. if (_this.ws) {
  6419. _this.ws.push("ping");
  6420. }
  6421. this.serverTimeoutObj = setTimeout(() => {
  6422. //如果超过一定时间还没重置,说明后端主动断开了
  6423. _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  6424. }, this.timeout);
  6425. }, this.timeout);
  6426. },
  6427. },
  6428. // 断开websocket
  6429. closeWs(flag = false) {
  6430. this.isHandler = flag;
  6431. if (flag) {
  6432. clearTimeout(this.reconnectTimer);
  6433. }
  6434. if (this.ws) {
  6435. this.ws.close();
  6436. }
  6437. }
  6438. };
  6439. });
  6440. //消息中心分页组件
  6441. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  6442. $rootScope.option = {
  6443. curr: 1, //当前页数
  6444. all: $rootScope.all, //总页数
  6445. count: 5, //最多显示的页数,默认为10
  6446. //点击页数的回调函数,参数page为点击的页数
  6447. click: function (page) {
  6448. $rootScope.msgData.idx = page - 1;
  6449. //这里可以写跳转到某个页面等...
  6450. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  6451. $rootScope.msg = data.list
  6452. $rootScope.all = data.pageCount;
  6453. $rootScope.option.all = $rootScope.all;
  6454. })
  6455. }
  6456. }
  6457. }]);
  6458. app.directive('myPagination', function () {
  6459. return {
  6460. restrict: 'EA',
  6461. replace: true,
  6462. rootScope: {
  6463. option: '=pageOption'
  6464. },
  6465. controller: 'msgCtrl',
  6466. template: '<ul class="pagination">' +
  6467. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  6468. '<a href="javascript:;">{{p}}</a>' +
  6469. '</li>' +
  6470. '</ul>',
  6471. link: function ($rootScope) {
  6472. //容错处理
  6473. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  6474. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  6475. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  6476. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  6477. //得到显示页数的数组
  6478. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  6479. //绑定点击事件
  6480. $rootScope.pageClick = function (page) {
  6481. if (page == '«') {
  6482. page = parseInt($rootScope.option.curr) - 1;
  6483. } else if (page == '»') {
  6484. page = parseInt($rootScope.option.curr) + 1;
  6485. }
  6486. if (page < 1) page = 1;
  6487. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  6488. //点击相同的页数 不执行点击事件
  6489. if (page == $rootScope.option.curr) return;
  6490. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  6491. $rootScope.option.click(page);
  6492. $rootScope.option.curr = page;
  6493. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  6494. }
  6495. };
  6496. //返回页数范围(用来遍历)
  6497. function getRange(curr, all, count) {
  6498. //计算显示的页数
  6499. // console.log(curr, all, count)
  6500. curr = parseInt(curr);
  6501. all = parseInt(all);
  6502. count = parseInt(count);
  6503. var from = curr - parseInt(count / 2);
  6504. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  6505. //显示的页数容处理
  6506. if (from <= 0) {
  6507. from = 1;
  6508. to = from + count - 1;
  6509. if (to > all) {
  6510. to = all;
  6511. }
  6512. }
  6513. if (to > all) {
  6514. to = all;
  6515. from = to - count + 1;
  6516. if (from <= 0) {
  6517. from = 1;
  6518. }
  6519. }
  6520. var range = [];
  6521. for (var i = from; i <= to; i++) {
  6522. range.push(i);
  6523. }
  6524. range.push('»');
  6525. range.unshift('«');
  6526. return range;
  6527. }
  6528. }
  6529. }
  6530. });
  6531. app.service('Myservice', function () {
  6532. return {
  6533. };
  6534. });
  6535. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  6536. // console.log(bh)
  6537. // if(bh>=0&&bh<=53){
  6538. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  6539. // }else{
  6540. // $('#sidebar').css('padding-bottom', 0 + 'px')
  6541. // }
  6542. window.onscroll = function () {
  6543. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  6544. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  6545. } else {
  6546. $('#sidebar').css('padding-top', '0')
  6547. }
  6548. // console.log(window.pageYOffset)
  6549. // console.log(window.innerHeight)
  6550. // console.log(document.body.scrollHeight)
  6551. // 底部padding
  6552. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  6553. // console.log(bh)
  6554. // if(bh>=0&&bh<=53){
  6555. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  6556. // }else{
  6557. // $('#sidebar').css('padding-bottom', 0 + 'px')
  6558. // }
  6559. }