mainCtrl.js 300 KB

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