mainCtrl.js 264 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992
  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: 0, } }
  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: 0,
  1086. },
  1087. idx: 0,
  1088. sum: 10
  1089. };
  1090. } else {
  1091. var filterData = {
  1092. idx: 0,
  1093. sum: 10,
  1094. user: {
  1095. engineer: 0,
  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: 0,
  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: 0,
  1424. },
  1425. idx: 0,
  1426. sum: 10
  1427. };
  1428. } else {
  1429. var filterData = {
  1430. idx: 0,
  1431. sum: 10,
  1432. user: {engineer: 0,}
  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.userMenus && $rootScope.userMenus.length > 0) {
  3269. if ($rootScope.user.group) {
  3270. var groupArr = [];
  3271. for (var i = 0; i < $rootScope.user.group.length; i++) {
  3272. groupArr.push($rootScope.user.group[i].id)
  3273. }
  3274. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  3275. angular.forEach($rootScope.userMenus, function (item, i) {
  3276. item.tipshow = false;
  3277. if (response) {
  3278. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  3279. if (item.id == 58) {
  3280. item.tipshow = true;
  3281. }
  3282. }
  3283. if (response.inspectionCount > 0) {
  3284. if (item.id == 27) {
  3285. item.tipshow = true;
  3286. }
  3287. }
  3288. if (response.incidentCount > 0) {
  3289. if (item.id == 2) {
  3290. item.tipshow = true;
  3291. }
  3292. }
  3293. if (response.releaseCount > 0) {
  3294. if (item.id == 1215) {
  3295. item.tipshow = true;
  3296. }
  3297. }
  3298. if (response.solutionCount > 0) {
  3299. if (item.id == 21) {
  3300. item.tipshow = true;
  3301. }
  3302. }
  3303. if (response.changeCount > 0) {
  3304. if (item.id == 1212) {
  3305. item.tipshow = true;
  3306. }
  3307. }
  3308. if (response.problemCount > 0) {
  3309. if (item.id == 1209) {
  3310. item.tipshow = true;
  3311. }
  3312. }
  3313. if (response.applicationForm > 0) {
  3314. if (item.id == 1221) {
  3315. item.tipshow = true;
  3316. }
  3317. }
  3318. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  3319. if (item.id == 21) {
  3320. item.tipshow = true;
  3321. }
  3322. }
  3323. if (item.children) {
  3324. angular.forEach(item.children, function (index) {
  3325. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  3326. if (index.id == 1208) {
  3327. if (response.hjzxCount < 100) {
  3328. index.tipnum = response.hjzxCount;
  3329. } else {
  3330. index.tipnum = "99+";
  3331. }
  3332. }
  3333. }
  3334. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  3335. if (index.id == 59) {
  3336. if (response.wechatWarningCount < 100) {
  3337. index.tipnum = response.wechatWarningCount;
  3338. } else {
  3339. index.tipnum = "99+";
  3340. }
  3341. }
  3342. }
  3343. if (response.problemCount !== null && response.problemCount !== undefined) {
  3344. if (index.id == 1210) {
  3345. if (response.problemCount < 100) {
  3346. index.tipnum = response.problemCount;
  3347. } else {
  3348. index.tipnum = "99+";
  3349. }
  3350. }
  3351. }
  3352. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  3353. if (index.id == 1216) {
  3354. if (response.releaseCount < 100) {
  3355. index.tipnum = response.releaseCount;
  3356. } else {
  3357. index.tipnum = "99+";
  3358. }
  3359. }
  3360. }
  3361. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  3362. if (index.id == 147) {
  3363. if (response.inspectionCount < 100) {
  3364. index.tipnum = response.inspectionCount;
  3365. } else {
  3366. index.tipnum = "99+";
  3367. }
  3368. }
  3369. }
  3370. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  3371. if (index.id == 23) {
  3372. if (response.solutionCount < 100) {
  3373. index.tipnum = response.solutionCount;
  3374. } else {
  3375. index.tipnum = "99+";
  3376. }
  3377. }
  3378. }
  3379. if (response.changeCount !== null && response.changeCount !== undefined) {
  3380. if (index.id == 1213) {
  3381. if (response.changeCount < 100) {
  3382. index.tipnum = response.changeCount;
  3383. } else {
  3384. index.tipnum = "99+";
  3385. }
  3386. }
  3387. }
  3388. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  3389. if (index.id == 3) {
  3390. if (response.incidentCount < 100) {
  3391. index.tipnum = response.incidentCount;
  3392. } else {
  3393. index.tipnum = "99+";
  3394. }
  3395. }
  3396. }
  3397. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  3398. if (index.id == 1231) {
  3399. if (response.applicationForm < 100) {
  3400. index.tipnum = response.applicationForm;
  3401. } else {
  3402. index.tipnum = "99+";
  3403. }
  3404. }
  3405. }
  3406. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  3407. if (index.id == 23) {
  3408. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  3409. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  3410. } else {
  3411. index.tipnum = "99+";
  3412. }
  3413. }
  3414. }
  3415. })
  3416. }
  3417. }
  3418. })
  3419. // return $rootScope.userMenus;
  3420. // $scope.recordpending = response.;
  3421. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  3422. })
  3423. } else {
  3424. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  3425. }
  3426. }
  3427. // console.log($rootScope.userMenus);
  3428. }
  3429. $rootScope.userMenus = [];
  3430. var getMenus = function () {
  3431. function convertListToTree(data, treeMap) {
  3432. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  3433. var root = null; //Initially set our loop to null
  3434. var parentNode = null;
  3435. //loop over data
  3436. for (var i = 0; i < data.length; i++) {
  3437. // data[i].id = Number(data[i].id);
  3438. var datum = data[i];
  3439. //each node will have children, so let's give it a "children" poperty
  3440. datum.children = [];
  3441. //add an entry for this node to the map so that any future children can
  3442. //lookup the parent
  3443. idToNodeMap[datum.id] = datum;
  3444. //Does this node have a parent?
  3445. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  3446. //Doesn't look like it, so this node is the root of the tree
  3447. root = datum;
  3448. treeMap[datum.id] = root;
  3449. } else {
  3450. //This node has a parent, so let's look it up using the id
  3451. parentNode = idToNodeMap[datum.parentid];
  3452. //We don't need this property, so let's delete it.
  3453. //delete datum.parentid;
  3454. //Let's add the current node as a child of the parent node.
  3455. parentNode.children.push(datum);
  3456. }
  3457. }
  3458. return root;
  3459. }
  3460. function convertParentToChildList(data) {
  3461. var treeMap = {};
  3462. var list = [];
  3463. convertListToTree(data, treeMap);
  3464. angular.forEach(treeMap, function (item) {
  3465. list.push(item);
  3466. });
  3467. list = window._.sortBy(list, function (o) {
  3468. return o.orders;
  3469. });
  3470. return list;
  3471. }
  3472. //if(userMenus.length==0){
  3473. var userMenus = [];
  3474. var idMapMenu = {};
  3475. if ($rootScope.user) {
  3476. if ($rootScope.user.menu) {
  3477. var allJurisdiction2 = $rootScope.user.menu;
  3478. var onlyMenu2 = [];
  3479. for (var i = 0; i < allJurisdiction2.length; i++) {
  3480. if (allJurisdiction2[i].event == "1") {
  3481. onlyMenu2.push(allJurisdiction2[i])
  3482. }
  3483. }
  3484. // userMenus = convertParentToChildList($rootScope.user.menu);
  3485. userMenus = convertParentToChildList(onlyMenu2);
  3486. }
  3487. }
  3488. //}
  3489. $rootScope.userMenus = userMenus;
  3490. if ($rootScope.userMenus.length > 0) {
  3491. $rootScope.getpending();
  3492. // setInterval($rootScope.getpending(), 30000);
  3493. }
  3494. return userMenus;
  3495. }
  3496. setInterval(function () {
  3497. if ($rootScope.userMenus.length > 0) {
  3498. $rootScope.getpending()
  3499. $rootScope.getMsgNum($rootScope.user.id)
  3500. }
  3501. }, 10000);
  3502. getMenus();
  3503. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  3504. $rootScope.logout = function () {
  3505. // var userid =data.id;
  3506. // console.log(' userid='+JSON.stringify( userid));
  3507. //单点登录
  3508. if (localStorage.getItem('isSSo') === '1') {
  3509. sessionStorage.clear();
  3510. localStorage.clear();
  3511. location.href = 'http://' + location.hostname + ':8080/pc_logout.jsp'
  3512. } else {
  3513. $auth.signOut()
  3514. .then(function (resp) {
  3515. // $auth.deleteData('auth_headers')
  3516. sessionStorage.clear();
  3517. localStorage.clear();
  3518. console.log($rootScope.isHk,'hk');
  3519. console.log($rootScope.isZncd,'zncd');
  3520. console.log($rootScope.isXy,'xy');
  3521. console.log($rootScope.isXyBox,'isXyBox');
  3522. if($rootScope.isZncd || $rootScope.isXy){
  3523. if ($rootScope.isFuwutai) {
  3524. tlwsa.tlaClose();
  3525. $.toaster({
  3526. priority: 'info',
  3527. title: '操作',
  3528. message: '呼叫中心断开连接'
  3529. });
  3530. }
  3531. }else if($rootScope.isXyBox){
  3532. if ($rootScope.isFuwutai) {
  3533. WebsocketPhoneService.closeWs(true);
  3534. }
  3535. }
  3536. $state.go("login.signin");
  3537. })
  3538. .catch(function (resp) { });
  3539. }
  3540. //$cookieStore.remove("userObm");
  3541. //$cookieStore.remove("menuObm");
  3542. //$cookieStore.remove("session");
  3543. //$rootScope.user = undefined;
  3544. //$rootScope.menus = undefined;
  3545. //$rootScope.nickname = undefined;
  3546. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  3547. // //logout: function(noServerLogout){
  3548. // window.sessionStorage.clear();
  3549. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  3550. // //},
  3551. }
  3552. // 首页统计跳转
  3553. $scope.goTo = function(url,data){
  3554. $state.go(url,data);
  3555. }
  3556. //获取首页建单统计信息
  3557. $rootScope.getOrderCount = function(){
  3558. // api_bpm_data.getManagerIndexInfo({}).then(function(result) {
  3559. // $scope.managerIndexInfo = result.data;
  3560. // });
  3561. var postData = {}
  3562. // 根据权限查询
  3563. if($rootScope.user.duty){
  3564. // 当前的所属责任科室
  3565. postData.dutyId = $rootScope.user.duty.id;
  3566. }else if($rootScope.user.branch){
  3567. // 当前的所属院区
  3568. postData.branchId = $rootScope.user.branch.id;
  3569. }
  3570. api_newreport.fetchDataListIndex('dutyOrderCount', postData).then(function(data) {
  3571. if (data.status == 200) {
  3572. $scope.managerIndexInfo = {
  3573. createOrders: data.today,
  3574. waitOrders: data.receiving,
  3575. doingOrders: data.doing,
  3576. doneOrders: data.complete,
  3577. }
  3578. }
  3579. })
  3580. }
  3581. // $rootScope.getOrderCount();
  3582. // 快速建单
  3583. $rootScope.newOrder = function (model1, type = '') {
  3584. $rootScope.newOrderShowOpen = true;
  3585. //进入弹窗,强制示忙
  3586. if (localStorage.getItem('fenjiNumber')) {
  3587. setTimeout(()=>{
  3588. tlwsa.tlaAcw();
  3589. },0)
  3590. }
  3591. $modal.open({
  3592. backdrop: false,
  3593. templateUrl:
  3594. "assets/views/newOrderSeimin.html",
  3595. controller: function (
  3596. $scope,
  3597. $parse,
  3598. fileReader,
  3599. FileUploader,
  3600. $modalInstance,
  3601. SweetAlert,
  3602. api_user_data,
  3603. api_bpm_domain,
  3604. up_down_file,
  3605. $rootScope,
  3606. modelData
  3607. ) {
  3608. // -------------------start----------------------
  3609. $scope.modelData = modelData;
  3610. // 当前所属院区处理
  3611. console.log(modelData);
  3612. // if(modelData){
  3613. // var curentHospital = undefined;
  3614. // api_bpm_data.fetchData('department', modelData.incident.department.id).then(res=>{
  3615. // if(res.status == 200){
  3616. // console.log(res.data);
  3617. // curentHospital = {id:1,hosName:'同济医院-主院区'}
  3618. // }
  3619. // })
  3620. // }else{
  3621. // var curentHospital = $rootScope.user.duty?{id:$rootScope.user.duty.branch,hosName:$rootScope.user.duty.branchName}:$rootScope.user.branch;
  3622. // }
  3623. if(modelData){
  3624. var curentHospital = {};
  3625. }else{
  3626. var curentHospital = $rootScope.user.duty?{id:$rootScope.user.duty.branch,hosName:$rootScope.user.duty.branchName}:$rootScope.user.branch;
  3627. }
  3628. // 是否连续建单
  3629. $scope.isBuildOrderAgagin = false;
  3630. //工单列表数据存储
  3631. $scope.incidentModel = {
  3632. department: "", //报修科室
  3633. requester: "", //报修人
  3634. contacts: "", //联系人
  3635. contactsInformation: "", //联系电话
  3636. branch: curentHospital, //院区
  3637. area: "", //区域
  3638. place: "", //地点
  3639. address: "", //详细地址
  3640. priority: "", //优先级
  3641. description: "", //故障描述
  3642. source: {id:1547,name:'电话'}, //事件来源
  3643. yyTime: null, //预约报修时间
  3644. assign: 1, //派单人或组
  3645. user: "", //处理人
  3646. group: "", //处理组
  3647. };
  3648. console.log(modelData)
  3649. if(modelData){
  3650. //报修生成事件,数据回显
  3651. //来电生成事件,数据回显
  3652. //暂存生成事件,数据回显
  3653. $scope.categorySelect = modelData.incident.category;
  3654. $scope.jry_modelLeft = modelData.incident.category?modelData.incident.category.mutiCategory:'';
  3655. console.log($scope.jry_deptData)
  3656. $scope.incidentModel = {
  3657. id: modelData.incident.id || undefined, //事件id
  3658. department: modelData.incident.department, //报修科室
  3659. requester: "", //报修人
  3660. contacts: modelData.incident.contacts, //联系人
  3661. contactsInformation: modelData.incident.contactsInformation, //联系电话
  3662. branch: curentHospital, //院区
  3663. area: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.area : "") : modelData.incident.area, //区域
  3664. place: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.place : "") : modelData.incident.place, //地点
  3665. address: type === 'incomingCall' ? (modelData.incident.department ? modelData.incident.department.address : "") : modelData.incident.houseNumber, //详细地址
  3666. priority: modelData.incident.priority, //优先级
  3667. description: modelData.incident.description, //故障描述
  3668. source: modelData.incident.source, //事件来源
  3669. yyTime: null, //预约报修时间
  3670. assign: 1, //派单人或组
  3671. user: "", //处理人
  3672. group: "", //处理组
  3673. callID: modelData.incident.sockid || undefined, //callID
  3674. incomingPhone: modelData.incident.incomingPhone || undefined, //来电电话
  3675. };
  3676. }
  3677. $scope.minYYtime = new Date();
  3678. // 建单并派单
  3679. $scope.buildAndAssign = function(){
  3680. if(!$scope.categorySelectId){
  3681. SweetAlert.swal({
  3682. title: "提示",
  3683. text: "请选择故障现象!",
  3684. type: "error",
  3685. confirmButtonColor: "#DD6B55"
  3686. });
  3687. return;
  3688. }
  3689. if(!$scope.selectedDuty){
  3690. SweetAlert.swal({
  3691. title: "提示",
  3692. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  3693. type: "error",
  3694. confirmButtonColor: "#DD6B55"
  3695. });
  3696. return;
  3697. }
  3698. if(!$scope.incidentModel.department){
  3699. SweetAlert.swal({
  3700. title: "提示",
  3701. text: "请选择报修科室!",
  3702. type: "error",
  3703. confirmButtonColor: "#DD6B55"
  3704. });
  3705. return;
  3706. }
  3707. if(!$scope.incidentModel.contactsInformation){
  3708. SweetAlert.swal({
  3709. title: "提示",
  3710. text: "请填写联系电话!",
  3711. type: "error",
  3712. confirmButtonColor: "#DD6B55"
  3713. });
  3714. return;
  3715. }
  3716. if(!$scope.incidentModel.priority){
  3717. SweetAlert.swal({
  3718. title: "提示",
  3719. text: "请选择优先级!",
  3720. type: "error",
  3721. confirmButtonColor: "#DD6B55"
  3722. });
  3723. return;
  3724. }
  3725. if(!$scope.incidentModel.description){
  3726. SweetAlert.swal({
  3727. title: "提示",
  3728. text: "请选择故障描述!",
  3729. type: "error",
  3730. confirmButtonColor: "#DD6B55"
  3731. });
  3732. return;
  3733. }
  3734. if($scope.incidentModel.assign == 0){
  3735. SweetAlert.swal({
  3736. title: "提示",
  3737. text: "请选择派单给人或组!",
  3738. type: "error",
  3739. confirmButtonColor: "#DD6B55"
  3740. });
  3741. return;
  3742. }
  3743. if($scope.incidentModel.assign == 1 && !$scope.incidentModel.user){
  3744. SweetAlert.swal({
  3745. title: "提示",
  3746. text: "请选择处理人!",
  3747. type: "error",
  3748. confirmButtonColor: "#DD6B55"
  3749. });
  3750. return;
  3751. }
  3752. if($scope.incidentModel.assign == 2 && !$scope.incidentModel.group){
  3753. SweetAlert.swal({
  3754. title: "提示",
  3755. text: "请选择处理组!",
  3756. type: "error",
  3757. confirmButtonColor: "#DD6B55"
  3758. });
  3759. return;
  3760. }
  3761. $rootScope.isMask = true;
  3762. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  3763. // var postData = {
  3764. // "loginUser": $rootScope.user,
  3765. // "incident": {
  3766. // "deleteFlag": 0,
  3767. // "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3768. // "department": $scope.incidentModel.department||undefined,
  3769. // "contactsInformation": $scope.incidentModel.contactsInformation,
  3770. // "contacts": $scope.incidentModel.contacts,
  3771. // "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3772. // "area": $scope.incidentModel.area||undefined,
  3773. // "place": $scope.incidentModel.place||undefined,
  3774. // "houseNumber": $scope.incidentModel.address,
  3775. // "category": $scope.categorySelect||undefined,
  3776. // "priority": $scope.incidentModel.priority||undefined,
  3777. // "source": $scope.incidentModel.source||undefined,
  3778. // "title": $scope.categorySelect.category,
  3779. // "description": $scope.incidentModel.description,
  3780. // "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3781. // "repairType": repair_main?repair_main.valueconfig:undefined,
  3782. // "requester":$scope.incidentModel.requester||undefined,
  3783. // "acceptUser": $rootScope.user||undefined,
  3784. // "callID": $scope.incidentModel.callID||undefined,
  3785. // "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3786. // },
  3787. // "start_code": "assignment",
  3788. // "initUser": $rootScope.user.id
  3789. // };
  3790. var postData = {
  3791. "incident": {
  3792. "id": $scope.incidentModel.id || undefined,
  3793. "deleteFlag": 0,
  3794. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3795. "department": $scope.incidentModel.department||undefined,
  3796. "contactsInformation": $scope.incidentModel.contactsInformation,
  3797. "contacts": $scope.incidentModel.contacts,
  3798. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3799. "area": $scope.incidentModel.area||undefined,
  3800. "place": $scope.incidentModel.place||undefined,
  3801. "houseNumber": $scope.incidentModel.address,
  3802. "category": $scope.categorySelect||undefined,
  3803. "priority": $scope.incidentModel.priority||undefined,
  3804. "source": $scope.incidentModel.source||undefined,
  3805. "title": $scope.categorySelect.category,
  3806. "description": $scope.incidentModel.description,
  3807. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3808. "repairType": repair_main?repair_main.valueconfig:undefined,
  3809. "requester":$scope.incidentModel.requester||undefined,
  3810. "acceptUser": $rootScope.user||undefined,
  3811. "callID": $scope.incidentModel.callID||undefined,
  3812. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3813. }
  3814. };
  3815. // if(modelData){
  3816. // // 微信报修转事件
  3817. // postData.flow = modelData.flow;
  3818. // }
  3819. if($scope.incidentModel.assign == 1){
  3820. postData.incident.assignee = $scope.incidentModel.user.id;
  3821. }else if($scope.incidentModel.assign == 2){
  3822. postData.incident.candidateGroups = $scope.incidentModel.group.id;
  3823. }
  3824. api_bpm_domain.workernumber('sj').then(res1=>{
  3825. postData.incident.incidentsign = res1.data;
  3826. api_flow.accept("accept", postData).then(function (response) {
  3827. if ($scope.uploader != null) {
  3828. // 有图片
  3829. $scope.uploader.onBeforeUploadItem = function(item) {
  3830. angular.extend(item.headers, $rootScope.getSession());
  3831. item.url = api_bpm_domain.uploadAttachment(response.id).getRequestedUrl();
  3832. item.formData.push({ 'fileName': item.file.name });
  3833. };
  3834. $scope.uploader.uploadAll();
  3835. }
  3836. $rootScope.isMask = false;
  3837. SweetAlert.swal(
  3838. {
  3839. title: "保存成功!",
  3840. type: "success",
  3841. confirmButtonColor: "#007AFF",
  3842. },
  3843. function (isConfirm) {
  3844. if(isConfirm){
  3845. // 是否连续建单
  3846. if($scope.isBuildOrderAgagin){
  3847. $scope.categorySelect = "";
  3848. $scope.categorySelectId = 0;
  3849. $scope.incidentModel.assign = 1;
  3850. $scope.incidentModel.user = "";
  3851. $scope.incidentModel.group = "";
  3852. }else{
  3853. if (localStorage.getItem('fenjiNumber')) {
  3854. $rootScope.jry_shixian();
  3855. }
  3856. $modalInstance.dismiss("cancel");
  3857. }
  3858. $rootScope.newOrderShowOpen = false;
  3859. if($state.current.name === 'app.incident.list'){
  3860. $state.reload();
  3861. }else{
  3862. $state.go("app.incident.list");
  3863. }
  3864. }
  3865. }
  3866. );
  3867. });
  3868. })
  3869. }
  3870. // 暂存
  3871. $scope.temporaryStorage = function(){
  3872. $rootScope.isMask = true;
  3873. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  3874. var postData = {
  3875. "incident": {
  3876. "id": $scope.incidentModel.id || undefined,
  3877. "deleteFlag": 0,
  3878. "duty":$scope.selectedDuty?$scope.selectedDuty:undefined,
  3879. "department": $scope.incidentModel.department||undefined,
  3880. "contactsInformation": $scope.incidentModel.contactsInformation,
  3881. "contacts": $scope.incidentModel.contacts,
  3882. "branch": $scope.incidentModel.branch?$scope.incidentModel.branch.id:undefined,
  3883. "area": $scope.incidentModel.area||undefined,
  3884. "place": $scope.incidentModel.place||undefined,
  3885. "houseNumber": $scope.incidentModel.address,
  3886. "category": $scope.categorySelect||undefined,
  3887. "priority": $scope.incidentModel.priority||undefined,
  3888. "source": $scope.incidentModel.source||undefined,
  3889. "title": $scope.categorySelect.category,
  3890. "description": $scope.incidentModel.description,
  3891. "yyTime": $scope.incidentModel.yyTime ? moment($scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  3892. "repairType": repair_main?repair_main.valueconfig:undefined,
  3893. "requester":$scope.incidentModel.requester||undefined,
  3894. "acceptUser": $rootScope.user||undefined,
  3895. "callID": $scope.incidentModel.callID||undefined,
  3896. "incomingPhone": $scope.incidentModel.incomingPhone||undefined,
  3897. }
  3898. };
  3899. // if(modelData){
  3900. // // 微信报修转事件
  3901. // postData.flow = modelData.flow;
  3902. // }
  3903. if($scope.incidentModel.assign == 1){
  3904. postData.incident.assignee = $scope.incidentModel ? $scope.incidentModel.user.id : undefined;
  3905. }else if($scope.incidentModel.assign == 2){
  3906. postData.incident.candidateGroups = $scope.incidentModel ? $scope.incidentModel.group.id : undefined;
  3907. }
  3908. api_bpm_domain.workernumber('sj').then(res1=>{
  3909. postData.incident.incidentsign = res1.data;
  3910. api_flow.accept("storage", postData).then(function (response) {
  3911. if ($scope.uploader != null) {
  3912. // 有图片
  3913. $scope.uploader.onBeforeUploadItem = function(item) {
  3914. angular.extend(item.headers, $rootScope.getSession());
  3915. item.url = api_bpm_domain.uploadAttachment(response.id).getRequestedUrl();
  3916. item.formData.push({ 'fileName': item.file.name });
  3917. };
  3918. $scope.uploader.uploadAll();
  3919. }
  3920. $rootScope.isMask = false;
  3921. SweetAlert.swal(
  3922. {
  3923. title: "保存成功!",
  3924. type: "success",
  3925. confirmButtonColor: "#007AFF",
  3926. },
  3927. function (isConfirm) {
  3928. if(isConfirm){
  3929. // 是否连续建单
  3930. if($scope.isBuildOrderAgagin){
  3931. $scope.categorySelect = "";
  3932. $scope.categorySelectId = 0;
  3933. $scope.incidentModel.assign = 1;
  3934. $scope.incidentModel.user = "";
  3935. $scope.incidentModel.group = "";
  3936. }else{
  3937. if (localStorage.getItem('fenjiNumber')) {
  3938. $rootScope.jry_shixian();
  3939. }
  3940. $modalInstance.dismiss("cancel");
  3941. }
  3942. $rootScope.newOrderShowOpen = false;
  3943. if($state.current.name === 'app.incident.list'){
  3944. $state.reload();
  3945. }else{
  3946. $state.go("app.incident.list");
  3947. }
  3948. }
  3949. }
  3950. );
  3951. });
  3952. })
  3953. }
  3954. // 展开/收起
  3955. $scope.showId = "";
  3956. $scope.ifshow = false;
  3957. $scope.showAll = function (id) {
  3958. $scope.attachments = [];
  3959. if ($scope.showId == id) {
  3960. $scope.ifshow = !$scope.ifshow;
  3961. } else {
  3962. $scope.ifshow = true;
  3963. }
  3964. $scope.showId = id;
  3965. // 获取附件
  3966. api_wechatfile
  3967. .listAttachments("knowledge", $scope.showId)
  3968. .then(function (data) {
  3969. $scope.attachments = data.data;
  3970. $scope.download = function (token, filename) {
  3971. var downUrl = up_down_file
  3972. .downloadAttachment("common/common/downloadAttachment", token)
  3973. .getRequestedUrl();
  3974. var a = document.createElement("a");
  3975. a.href = downUrl;
  3976. a.target = "_blank";
  3977. a.download = filename;
  3978. document.body.appendChild(a);
  3979. a.click();
  3980. };
  3981. });
  3982. };
  3983. // 回显处理人或组
  3984. $scope.showUserOrGroup = function(){
  3985. if($scope.incidentModel.department && $scope.categorySelect && $scope.selectedDuty && $scope.incidentModel.branch){
  3986. var postData = {
  3987. idx: 0,
  3988. sum: 10,
  3989. incidentAssignManager: {
  3990. deptId:$scope.incidentModel.department.id,
  3991. categoryId:$scope.categorySelect.id,
  3992. branch:$scope.incidentModel.branch.id,
  3993. dutyId: $scope.selectedDuty.id
  3994. },
  3995. };
  3996. api_user_data.fetchDataList("incidentAssignManager", postData).then(function(result){
  3997. if(result.status == 200){
  3998. var deptBinduserConfig = result.list?result.list[0]:null;//获取第一条配置
  3999. if(deptBinduserConfig){
  4000. // 如果有科室绑定人员的配置
  4001. if(deptBinduserConfig.userOrGroupType == 1){
  4002. // 派单给人
  4003. $scope.incidentModel.assign = 1;
  4004. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == deptBinduserConfig.handleUser);
  4005. }else if(deptBinduserConfig.userOrGroupType == 2){
  4006. // 派单给组
  4007. $scope.incidentModel.assign = 2;
  4008. $scope.incidentModel.group = $scope.jry_groupData.find(v=>v.id == deptBinduserConfig.group);
  4009. }
  4010. }else{
  4011. // 没有查询到科室绑定人员的配置,则根据院区,普通科室,责任科室查询
  4012. var postData = {
  4013. idx: 0,
  4014. sum: 10,
  4015. incidentAssignManager: {
  4016. deptId:$scope.incidentModel.department.id,
  4017. branch:$scope.incidentModel.branch.id,
  4018. dutyId: $scope.selectedDuty.id
  4019. },
  4020. };
  4021. api_user_data.fetchDataList("incidentAssignManager", postData).then(function(result){
  4022. if(result.status == 200){
  4023. //获取配置
  4024. var deptBinduserConfig = result.list || [];
  4025. // 过滤掉有故障现象的配置
  4026. deptBinduserConfig = deptBinduserConfig.filter(v => !v.categoryId);
  4027. // 获取第一条配置
  4028. deptBinduserConfig = deptBinduserConfig[0] || null;
  4029. if(deptBinduserConfig){
  4030. // 如果有科室绑定人员的配置
  4031. if(deptBinduserConfig.userOrGroupType == 1){
  4032. // 派单给人
  4033. $scope.incidentModel.assign = 1;
  4034. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == deptBinduserConfig.handleUser);
  4035. }else if(deptBinduserConfig.userOrGroupType == 2){
  4036. // 派单给组
  4037. $scope.incidentModel.assign = 2;
  4038. $scope.incidentModel.group = $scope.jry_groupData.find(v=>v.id == deptBinduserConfig.group);
  4039. }
  4040. }else{
  4041. if($scope.categorySelect){
  4042. // 选择了故障现象
  4043. assignCommon($scope.categorySelect);
  4044. }
  4045. }
  4046. }
  4047. })
  4048. }
  4049. }
  4050. })
  4051. }else if($scope.categorySelect){
  4052. // 选择了故障现象
  4053. assignCommon($scope.categorySelect);
  4054. }
  4055. }
  4056. // 直接解决
  4057. $scope.build = function(){
  4058. if(!$scope.categorySelectId){
  4059. SweetAlert.swal({
  4060. title: "提示",
  4061. text: "请选择故障现象!",
  4062. type: "error",
  4063. confirmButtonColor: "#DD6B55"
  4064. });
  4065. return;
  4066. }
  4067. if(!$scope.selectedDuty){
  4068. SweetAlert.swal({
  4069. title: "提示",
  4070. text: "故障现象【"+ $scope.categorySelect.category +"】没有设置责任科室!",
  4071. type: "error",
  4072. confirmButtonColor: "#DD6B55"
  4073. });
  4074. return;
  4075. }
  4076. if(!$scope.incidentModel.department){
  4077. SweetAlert.swal({
  4078. title: "提示",
  4079. text: "请选择报修科室!",
  4080. type: "error",
  4081. confirmButtonColor: "#DD6B55"
  4082. });
  4083. return;
  4084. }
  4085. if(!$scope.incidentModel.contactsInformation){
  4086. SweetAlert.swal({
  4087. title: "提示",
  4088. text: "请填写联系电话!",
  4089. type: "error",
  4090. confirmButtonColor: "#DD6B55"
  4091. });
  4092. return;
  4093. }
  4094. if(!$scope.incidentModel.priority){
  4095. SweetAlert.swal({
  4096. title: "提示",
  4097. text: "请选择优先级!",
  4098. type: "error",
  4099. confirmButtonColor: "#DD6B55"
  4100. });
  4101. return;
  4102. }
  4103. if(!$scope.incidentModel.description){
  4104. SweetAlert.swal({
  4105. title: "提示",
  4106. text: "请选择故障描述!",
  4107. type: "error",
  4108. confirmButtonColor: "#DD6B55"
  4109. });
  4110. return;
  4111. }
  4112. $modal.open({
  4113. templateUrl: "assets/views/newOrderDirectly.html",
  4114. controller: function ($scope,scope,$state, $modalInstance, SweetAlert,api_bpm) {
  4115. $scope.categorySelect = scope.categorySelect;
  4116. console.log($scope.categorySelect)
  4117. $scope.incidentModel = {
  4118. handlerMsg:'',//处理方案
  4119. closecode:'',//关闭代码
  4120. };
  4121. // 关闭代码
  4122. $scope.closecodeArray = [];
  4123. $scope.jry_closecodeSearch = function () {
  4124. api_wechatfile
  4125. .getDictionary({ type: "list", key: "incident_closecode" })
  4126. .then(function (data) {
  4127. $scope.closecodeArray = data;
  4128. });
  4129. };
  4130. $scope.jry_closecodeSearch();
  4131. // 确定
  4132. $scope.ok = function () {
  4133. if($scope.categorySelect.hasSimple != 1 && !$scope.incidentModel.handlerMsg){
  4134. SweetAlert.swal({
  4135. title: "提示",
  4136. text: "请填写处理方案!",
  4137. type: "error",
  4138. confirmButtonColor: "#DD6B55"
  4139. });
  4140. return;
  4141. }
  4142. if(!$scope.incidentModel.closecode.id){
  4143. SweetAlert.swal({
  4144. title: "提示",
  4145. text: "请选择关闭代码!",
  4146. type: "error",
  4147. confirmButtonColor: "#DD6B55"
  4148. });
  4149. return;
  4150. }
  4151. // -------新建事件,积分机制,直接处理--------
  4152. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4153. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4154. $modal.open({
  4155. templateUrl: 'assets/views/incident/tpl/toIntegralMechanism.tpl.html',
  4156. controller: function ($scope, $modalInstance, incidentData,categorySelect, currentUserId, Alert, api_wechatfile,scope,api_bpm_data) {
  4157. console.log(incidentData,currentUserId,categorySelect);
  4158. $scope.complexityConfirm = {complexity:null,updateReason:''};
  4159. $scope.complexityFn = function(category){
  4160. if(category.complexity){
  4161. return category.complexity.value;
  4162. }else if(category.parent){
  4163. return $scope.complexityFn(category.parent);
  4164. }else{
  4165. return $scope.list[0]?$scope.list[0].value:1;
  4166. }
  4167. }
  4168. $scope.list = [];
  4169. api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){
  4170. $scope.list = res;
  4171. if(categorySelect && categorySelect.id){
  4172. api_bpm_data.fetchData("incidentCategory",categorySelect.id).then(function(result){
  4173. if(result.status == 200){
  4174. $scope.complexity = $scope.complexityFn(result.data);
  4175. $scope.complexityConfirm.complexity = $scope.list.find(v=>v.value == $scope.complexity);
  4176. }
  4177. })
  4178. }
  4179. })
  4180. $scope.onChangeComplexity = function(item){
  4181. }
  4182. $scope.ok = function () {
  4183. if (!$scope.complexityConfirm.complexity){
  4184. Alert.swal({
  4185. title: "操作失败",
  4186. text: "请选择工时!",
  4187. type: "error"
  4188. });
  4189. return;
  4190. }
  4191. if ($scope.complexityConfirm.complexity.value != $scope.complexity&&!$scope.complexityConfirm.updateReason.trim()){
  4192. Alert.swal({
  4193. title: "操作失败",
  4194. text: "请填写升级原因!",
  4195. type: "error"
  4196. });
  4197. return;
  4198. }
  4199. $modalInstance.close('success');
  4200. handlerStart();
  4201. scope.complexity = $scope.complexity;
  4202. scope.complexityConfirm = $scope.complexityConfirm;
  4203. // 暂存--后面直接处理后调用积分接口
  4204. }
  4205. $scope.cancel = function () {
  4206. if (localStorage.getItem('fenjiNumber')) {
  4207. $rootScope.jry_shixian();
  4208. }
  4209. $modalInstance.dismiss('cancel');
  4210. }
  4211. },
  4212. size: 'sm',
  4213. resolve: {
  4214. scope: function () {
  4215. return $scope;
  4216. },
  4217. api_bpm: function () {
  4218. return api_bpm;
  4219. },
  4220. incidentData: function () {
  4221. return scope.incidentModel;
  4222. },
  4223. categorySelect: function () {
  4224. return scope.categorySelect;
  4225. },
  4226. currentUserId: function () {
  4227. return $rootScope.user.id;
  4228. },
  4229. Alert: function () {
  4230. return SweetAlert;
  4231. },
  4232. api_user_data: function () {
  4233. return api_user_data;
  4234. },
  4235. api_wechatfile: function () {
  4236. return api_wechatfile;
  4237. }
  4238. }
  4239. });
  4240. }else{
  4241. handlerStart();
  4242. }
  4243. // -------新建事件,积分机制,直接处理--------
  4244. };
  4245. // 直接处理,新建事件
  4246. function handlerStart(){
  4247. $rootScope.isMask = true;
  4248. console.log(scope.incidentModel,$scope.incidentModel);
  4249. var repair_main = JSON.parse(sessionStorage.getItem('repair_main'));
  4250. // var postData = {
  4251. // "loginUser": $rootScope.user||undefined,
  4252. // "incident": {
  4253. // "deleteFlag": 0,
  4254. // "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4255. // "requester":$scope.incidentModel.requester||undefined,
  4256. // "alarmType": false,
  4257. // "department": scope.incidentModel.department||undefined,
  4258. // "contactsInformation": scope.incidentModel.contactsInformation,
  4259. // "contacts": scope.incidentModel.contacts,
  4260. // "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4261. // "area": scope.incidentModel.area||undefined,
  4262. // "place": scope.incidentModel.place||undefined,
  4263. // "houseNumber": scope.incidentModel.address,
  4264. // "category": scope.categorySelect||undefined,
  4265. // "priority": scope.incidentModel.priority||undefined,
  4266. // "source": scope.incidentModel.source||undefined,
  4267. // "title": scope.categorySelect.category,
  4268. // "description": scope.incidentModel.description,
  4269. // "directProcess": 1,
  4270. // "handleDescription": $scope.incidentModel.handlerMsg,
  4271. // "handlingPersonnelUser":{id:$rootScope.user.id},
  4272. // "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4273. // "closecode": $scope.incidentModel.closecode||undefined,
  4274. // "repairType": repair_main?repair_main.valueconfig:undefined,
  4275. // "acceptUser": $rootScope.user||undefined,
  4276. // "callID": scope.incidentModel.callID||undefined,
  4277. // "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  4278. // },
  4279. // "start_code": "close",
  4280. // "handler_code": "resolve",
  4281. // "initUser": $rootScope.user.id,
  4282. // "isSolution": false
  4283. // };
  4284. var postData = {
  4285. "incident": {
  4286. "id": scope.incidentModel.id || undefined,
  4287. "deleteFlag": 0,
  4288. "duty":scope.selectedDuty?scope.selectedDuty:undefined,
  4289. "requester":$scope.incidentModel.requester||undefined,
  4290. "alarmType": false,
  4291. "department": scope.incidentModel.department||undefined,
  4292. "contactsInformation": scope.incidentModel.contactsInformation,
  4293. "contacts": scope.incidentModel.contacts,
  4294. "branch": scope.incidentModel.branch?scope.incidentModel.branch.id:undefined,
  4295. "area": scope.incidentModel.area||undefined,
  4296. "place": scope.incidentModel.place||undefined,
  4297. "houseNumber": scope.incidentModel.address,
  4298. "category": scope.categorySelect||undefined,
  4299. "priority": scope.incidentModel.priority||undefined,
  4300. "source": scope.incidentModel.source||undefined,
  4301. "title": scope.categorySelect.category,
  4302. "description": scope.incidentModel.description,
  4303. "directProcess": 1,
  4304. "handleDescription": $scope.incidentModel.handlerMsg,
  4305. "handlingPersonnelUser":{id:$rootScope.user.id},
  4306. "yyTime": scope.incidentModel.yyTime ? moment(scope.incidentModel.yyTime).format('YYYY-MM-DD HH:mm:ss') : undefined,
  4307. "closecode": $scope.incidentModel.closecode||undefined,
  4308. "repairType": repair_main?repair_main.valueconfig:undefined,
  4309. "acceptUser": $rootScope.user||undefined,
  4310. "callID": scope.incidentModel.callID||undefined,
  4311. "incomingPhone": scope.incidentModel.incomingPhone||undefined,
  4312. },
  4313. };
  4314. // if(scope.modelData){
  4315. // // 微信报修转事件
  4316. // postData.flow = scope.modelData.flow;
  4317. // }
  4318. api_bpm_domain.workernumber('sj').then(res1=>{
  4319. postData.incident.incidentsign = res1.data;
  4320. api_flow.accept("accept", postData).then(function (resData) {
  4321. if (scope.uploader != null) {
  4322. // 有图片
  4323. scope.uploader.onBeforeUploadItem = function(item) {
  4324. angular.extend(item.headers, $rootScope.getSession());
  4325. item.url = api_bpm_domain.uploadAttachment(resData.id).getRequestedUrl();
  4326. item.formData.push({ 'fileName': item.file.name });
  4327. };
  4328. scope.uploader.uploadAll();
  4329. }
  4330. var integralMechanism = sessionStorage.getItem('integralMechanism');
  4331. if(integralMechanism == 1 || (integralMechanism == 2 && $rootScope.user.userType.value == 2)){
  4332. api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
  4333. var auditState = res.find(v=>v.value == 0);
  4334. var postData = {
  4335. incidentIntegral: {
  4336. incidentId:resData.bussId,
  4337. auditState:auditState,
  4338. handlerUser:$rootScope.user.id,
  4339. handlerUserName:$rootScope.user.name,
  4340. sourceScore:$scope.complexity,
  4341. currentScore:$scope.complexityConfirm.complexity.value,
  4342. updateReason:$scope.complexityConfirm.updateReason.trim() || undefined,
  4343. }
  4344. }
  4345. console.log(postData)
  4346. api_bpm_data.addData('incidentIntegral', postData).then(function (response) {
  4347. console.log(response)
  4348. $rootScope.isMask = false;
  4349. if (response.status == 200) {
  4350. SweetAlert.swal(
  4351. {
  4352. title: "保存成功!",
  4353. type: "success",
  4354. confirmButtonColor: "#007AFF",
  4355. },
  4356. function (isConfirm) {
  4357. if(isConfirm){
  4358. $modalInstance.dismiss("cancel");
  4359. // 是否连续建单
  4360. if(scope.isBuildOrderAgagin){
  4361. scope.categorySelect = "";
  4362. scope.categorySelectId = 0;
  4363. scope.incidentModel.assign = 1;
  4364. scope.incidentModel.user = "";
  4365. scope.incidentModel.group = "";
  4366. }else{
  4367. if (localStorage.getItem('fenjiNumber')) {
  4368. $rootScope.jry_shixian();
  4369. }
  4370. scope.cancel();
  4371. }
  4372. $rootScope.newOrderShowOpen = false;
  4373. if($state.current.name === 'app.incident.list'){
  4374. $state.reload();
  4375. }else{
  4376. $state.go("app.incident.list");
  4377. }
  4378. }
  4379. }
  4380. );
  4381. } else {
  4382. Alert.swal({
  4383. title: "操作失败",
  4384. text: "操作失败, 请稍后再试!",
  4385. type: "error"
  4386. });
  4387. }
  4388. });
  4389. })
  4390. }else{
  4391. SweetAlert.swal(
  4392. {
  4393. title: "提交成功!",
  4394. type: "success",
  4395. confirmButtonColor: "#007AFF",
  4396. },
  4397. function (isConfirm) {
  4398. if(isConfirm){
  4399. if (localStorage.getItem('fenjiNumber')) {
  4400. $rootScope.jry_shixian();
  4401. }
  4402. scope.cancel();
  4403. $modalInstance.dismiss("cancel");
  4404. $rootScope.newOrderShowOpen = false;
  4405. if($state.current.name === 'app.incident.list'){
  4406. $state.reload();
  4407. }else{
  4408. $state.go("app.incident.list");
  4409. }
  4410. }
  4411. }
  4412. );
  4413. }
  4414. // -------------------------------------------
  4415. $rootScope.isMask = false;
  4416. SweetAlert.swal(
  4417. {
  4418. title: "保存成功!",
  4419. type: "success",
  4420. confirmButtonColor: "#007AFF",
  4421. },
  4422. function (isConfirm) {
  4423. if(isConfirm){
  4424. $modalInstance.dismiss("cancel");
  4425. // 是否连续建单
  4426. if(scope.isBuildOrderAgagin){
  4427. scope.categorySelect = "";
  4428. scope.categorySelectId = 0;
  4429. scope.incidentModel.assign = 1;
  4430. scope.incidentModel.user = "";
  4431. scope.incidentModel.group = "";
  4432. }else{
  4433. if (localStorage.getItem('fenjiNumber')) {
  4434. $rootScope.jry_shixian();
  4435. }
  4436. scope.cancel();
  4437. }
  4438. $rootScope.newOrderShowOpen = false;
  4439. if($state.current.name === 'app.incident.list'){
  4440. $state.reload();
  4441. }else{
  4442. $state.go("app.incident.list");
  4443. }
  4444. }
  4445. }
  4446. );
  4447. });
  4448. })
  4449. }
  4450. // 取消
  4451. $scope.cancel = function () {
  4452. if (localStorage.getItem('fenjiNumber')) {
  4453. $rootScope.jry_shixian();
  4454. }
  4455. $modalInstance.dismiss("cancel");
  4456. };
  4457. },
  4458. size:'lg',
  4459. resolve: {
  4460. SweetAlert: function () {
  4461. return SweetAlert;
  4462. },
  4463. scope: function(){
  4464. return $scope;
  4465. }
  4466. },
  4467. });
  4468. }
  4469. // 处理顶部责任科室数据
  4470. $scope.handlerDuty = function(){
  4471. if(!$scope.categorySelect){
  4472. return;
  4473. }
  4474. if($scope.categorySelect.branchType == 1){
  4475. // 分院区
  4476. if($scope.incidentModel.branch){
  4477. var dutyConfig = $scope.categorySelect.branchUserGroups.find(v=>v.branchId == $scope.incidentModel.branch.id);
  4478. if(dutyConfig && dutyConfig.dutyId && dutyConfig.dutyName){
  4479. $scope.selectedDuty = {id:dutyConfig.dutyId,dept:dutyConfig.dutyName};
  4480. }else{
  4481. $scope.selectedDuty = null;
  4482. }
  4483. }else{
  4484. $scope.selectedDuty = null;
  4485. }
  4486. }else{
  4487. // 不分院区
  4488. $scope.selectedDuty = $scope.categorySelect.dutyDepartment;
  4489. }
  4490. }
  4491. // 优先级
  4492. $scope.priorityArray = [];
  4493. $scope.jry_prioritySearch = function () {
  4494. api_wechatfile
  4495. .getDictionary({ type: "list", key: "incident_priority" })
  4496. .then(function (data) {
  4497. $scope.priorityArray = data;
  4498. });
  4499. };
  4500. $scope.jry_prioritySearch();
  4501. // 事件来源
  4502. $scope.sourceArray = [];
  4503. $scope.jry_sourceSearch = function () {
  4504. api_wechatfile
  4505. .getDictionary({ type: "list", key: "incident_source" })
  4506. .then(function (data) {
  4507. $scope.sourceArray = data;
  4508. if($scope.incidentModel.source){
  4509. if(!$scope.incidentModel.source.name && $scope.incidentModel.source.id){
  4510. $scope.incidentModel.source = data.find(v=>v.id == $scope.incidentModel.source.id)
  4511. }
  4512. }
  4513. });
  4514. };
  4515. $scope.jry_sourceSearch();
  4516. // 报修科室模糊搜索
  4517. $scope.jry_deptSearch = function (key = "",branchId) {
  4518. console.log(branchId)
  4519. if(!branchId){
  4520. $scope.jry_deptData = [];
  4521. return;
  4522. }
  4523. var deptData = {
  4524. idx: 0,
  4525. sum: 20,
  4526. department: {
  4527. branch:branchId,
  4528. dept:key,
  4529. selectType: "pinyin_qs",
  4530. searchType: "quickStart",
  4531. },
  4532. };
  4533. api_user_data.fetchDataList("department", deptData).then(function (data) {
  4534. $scope.jry_deptData = data.list;
  4535. if($scope.incidentModel.department){
  4536. if(!$scope.incidentModel.department.dept && $scope.incidentModel.department.id){
  4537. // $scope.incidentModel.department = data.list.find(v=>v.id == $scope.incidentModel.department.id)
  4538. api_bpm_data.fetchData('department', $scope.incidentModel.department.id).then(res=>{
  4539. if(res.status == 200){
  4540. $scope.incidentModel.department = res.data;
  4541. }else{
  4542. $scope.incidentModel.department = '';
  4543. }
  4544. })
  4545. }
  4546. }
  4547. });
  4548. };
  4549. // $scope.jry_deptSearch();
  4550. // 报修人模糊搜索
  4551. $scope.jry_requesterSearch = function (key = "") {
  4552. var postData = {
  4553. idx: 0,
  4554. sum: 10,
  4555. user: {
  4556. name: key,
  4557. selectType: "pinyin_all",
  4558. engineer: 0,
  4559. },
  4560. };
  4561. api_user_data.fetchDataList("user", postData).then(function (data) {
  4562. $scope.jry_requesterData = data.list;
  4563. });
  4564. };
  4565. $scope.jry_requesterSearch();
  4566. $scope.$watch("incidentModel.requester", function (newVal,oldVal) {
  4567. if(newVal){
  4568. $scope.incidentModel.contacts = newVal.name;
  4569. SweetAlert.swal({
  4570. title: "提示",
  4571. text: "是否覆盖联系电话?",
  4572. type: "warning",
  4573. showCancelButton: true,
  4574. confirmButtonColor: "#DD6B55",
  4575. confirmButtonText: "确认覆盖",
  4576. cancelButtonText: "取消操作",
  4577. closeOnConfirm: true,
  4578. closeOnCancel: true
  4579. }, function (isConfirm) {
  4580. if (isConfirm) {
  4581. $scope.incidentModel.contactsInformation = newVal.phone;
  4582. }
  4583. });
  4584. }
  4585. });
  4586. // 处理人模糊搜索
  4587. $scope.jry_userSearch = function (key = "") {
  4588. var userData = {
  4589. idx: 0,
  4590. sum: 1000,
  4591. user: {
  4592. roledata: {rolecode: "first-line support"},
  4593. selectDetails:'1',
  4594. simple:true,
  4595. name: key,
  4596. selectType: "pinyin_qs",
  4597. engineer: 1,
  4598. },
  4599. };
  4600. api_user_data.fetchDataList("user", userData).then(function (data) {
  4601. $scope.jry_userData = data.list;
  4602. if($scope.incidentModel.user){
  4603. if(!$scope.incidentModel.user.userTaskCount){
  4604. $scope.incidentModel.user = data.list.find(v=>v.id == $scope.incidentModel.user.id);
  4605. }
  4606. }
  4607. });
  4608. };
  4609. $scope.jry_userSearch();
  4610. // 处理组模糊搜索
  4611. $scope.jry_groupSearch = function (key = "") {
  4612. var groupData = {
  4613. idx: 0,
  4614. sum: 1000,
  4615. group: {
  4616. selectType: "nouser"
  4617. },
  4618. };
  4619. api_user_data.fetchDataList("group", groupData).then(function (data) {
  4620. $scope.jry_groupData = data.list;
  4621. });
  4622. };
  4623. $scope.jry_groupSearch();
  4624. // 院区模糊搜索
  4625. $scope.jry_branchSearch = function (key = "") {
  4626. var postData = {
  4627. idx: 0,
  4628. sum: 1000
  4629. };
  4630. api_user_data.fetchDataList("branch", postData).then(function (data) {
  4631. $scope.jry_branchData = data.list;
  4632. if(modelData && modelData.incident && modelData.incident.department){
  4633. api_bpm_data.fetchData('department', modelData.incident.department.id).then(res=>{
  4634. if(res.status == 200){
  4635. $scope.incidentModel.branch = $scope.jry_branchData.find(v=>v.id == res.data.branch);
  4636. }
  4637. })
  4638. }
  4639. });
  4640. };
  4641. $scope.jry_branchSearch();
  4642. // 区域模糊搜索
  4643. $scope.jry_areaSearch = function (key='',branchId) {
  4644. if(!branchId){
  4645. $scope.jry_areaData = [];
  4646. return;
  4647. }
  4648. var areaData = {
  4649. idx: 0,
  4650. sum: 30,
  4651. area: {
  4652. branch:branchId,
  4653. area:key,
  4654. selectType:'pinyin_qs'
  4655. },
  4656. };
  4657. api_user_data.fetchDataList("area", areaData).then(function (data) {
  4658. $scope.jry_areaData = data.list;
  4659. });
  4660. };
  4661. // 地点模糊搜索
  4662. $scope.jry_placeSearch = function (key='',areaId) {
  4663. if(!areaId){
  4664. $scope.jry_placeData = [];
  4665. return;
  4666. }
  4667. var placeData = {
  4668. idx: 0,
  4669. sum: 30,
  4670. place: {
  4671. place: key,
  4672. areaId: areaId,
  4673. selectType:'pinyin_qs'
  4674. },
  4675. };
  4676. api_user_data.fetchDataList("place", placeData).then(function (data) {
  4677. $scope.jry_placeData = data.list;
  4678. });
  4679. };
  4680. $scope.changeBranch = function(){
  4681. $scope.incidentModel.area = '';
  4682. $scope.incidentModel.place = '';
  4683. $scope.incidentModel.department = '';
  4684. $scope.jry_placeData = [];
  4685. }
  4686. $scope.changeArea = function(){
  4687. $scope.incidentModel.place = '';
  4688. }
  4689. $scope.$watch("incidentModel.branch", function (newVal,oldVal) {
  4690. $scope.showUserOrGroup();
  4691. newVal && $scope.jry_areaSearch('',newVal.id);
  4692. newVal && $scope.jry_deptSearch('',newVal.id);
  4693. $scope.handlerDuty();
  4694. });
  4695. $scope.$watch("incidentModel.area", function (newVal,oldVal) {
  4696. newVal && $scope.jry_placeSearch('',newVal.id);
  4697. console.log(modelData, $scope.oldDept,$scope.incidentModel)
  4698. });
  4699. $scope.$watch("categorySelect", function (newVal,oldVal) {
  4700. if(newVal&&newVal.priority){
  4701. // 回显优先级
  4702. $scope.incidentModel.priority = newVal.priority;
  4703. }
  4704. // 选择了院区,科室,故障现象,责任科室
  4705. $scope.showUserOrGroup();
  4706. // 回显人员
  4707. if($scope.incidentModel.user){
  4708. if(!$scope.incidentModel.user.userTaskCount){
  4709. $scope.incidentModel.user = $scope.jry_userData.find(v=>v.id == $scope.incidentModel.user.id);
  4710. }
  4711. }
  4712. });
  4713. // 派人或派组
  4714. function assignCommon(sj){
  4715. console.log(sj);
  4716. if(!sj){return;}
  4717. if (sj.branchType == 0) {
  4718. if (sj.userOrGroupType === 1) {
  4719. //派人
  4720. $scope.incidentModel.assign = 1;
  4721. $scope.incidentModel.user = sj.handleUser ? $scope.jry_userData.find(v=>v.id == sj.handleUser.id) : "";
  4722. } else if (sj.userOrGroupType === 2) {
  4723. //派组
  4724. $scope.incidentModel.assign = 2;
  4725. $scope.incidentModel.group = sj.group ? sj.group : "";
  4726. } else {
  4727. $scope.incidentModel.assign = 0;
  4728. $scope.incidentModel.user = "";
  4729. $scope.incidentModel.group = "";
  4730. }
  4731. } else if (sj.branchType == 1) {
  4732. // 分院区
  4733. // 选择了院区
  4734. if ($scope.incidentModel.branch) {
  4735. let branchId = $scope.incidentModel.branch.id;
  4736. let branchUserGroup =
  4737. sj.branchUserGroups.find(v => v.branchId == branchId) || {};
  4738. if (branchUserGroup.branchUserOrGroupType == 1) {
  4739. //派人
  4740. $scope.incidentModel.assign = 1;
  4741. console.log($scope.jry_userData)
  4742. $scope.incidentModel.user = branchUserGroup.userId
  4743. ? $scope.jry_userData.find(v=>v.id == branchUserGroup.userId)
  4744. : "";
  4745. } else if (branchUserGroup.branchUserOrGroupType === 2) {
  4746. //派组
  4747. $scope.incidentModel.assign = 2;
  4748. $scope.incidentModel.group = branchUserGroup.groupId
  4749. ? {id:branchUserGroup.groupId,groupName:branchUserGroup.groupName}
  4750. : "";
  4751. } else {
  4752. $scope.incidentModel.assign = 1;
  4753. $scope.incidentModel.user = "";
  4754. $scope.incidentModel.group = "";
  4755. }
  4756. } else {
  4757. $scope.incidentModel.assign = 1;
  4758. $scope.incidentModel.user = "";
  4759. $scope.incidentModel.group = "";
  4760. }
  4761. }
  4762. }
  4763. // 取消故障描述弹窗
  4764. $scope.isShowAlertMask = false;
  4765. $scope.copyItem = null;
  4766. $scope.cancelAlertMask = function(){
  4767. $scope.isShowAlertMask = false;
  4768. }
  4769. // 覆盖
  4770. $scope.overlayAlertMask = function(){
  4771. $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  4772. $scope.isShowAlertMask = false;
  4773. }
  4774. // 前覆盖
  4775. $scope.overlayLeftAlertMask = function(){
  4776. $scope.incidentModel.description = $scope.copyItem.mutiCategory + $scope.incidentModel.description;
  4777. $scope.isShowAlertMask = false;
  4778. }
  4779. // 后覆盖
  4780. $scope.overlayRightAlertMask = function(){
  4781. $scope.incidentModel.description = $scope.incidentModel.description + $scope.copyItem.mutiCategory;
  4782. $scope.isShowAlertMask = false;
  4783. }
  4784. // 故障现象选中
  4785. $scope.categorySelectId = 0;
  4786. $scope.categorySelect = "";
  4787. $scope.selectedDuty = null;//选择故障现象后的责任科室
  4788. $scope.changeCategorySelect = function(item){
  4789. $scope.copyItem = angular.copy(item);
  4790. $scope.copyItem.mutiCategory = $scope.copyItem.mutiCategory.replace(/<[^<>]+>/g,'');
  4791. if($scope.incidentModel.description){
  4792. $scope.isShowAlertMask = true;
  4793. // SweetAlert.swal({
  4794. // title: "提示",
  4795. // text: "是否覆盖故障描述?",
  4796. // type: "warning",
  4797. // showCancelButton: true,
  4798. // confirmButtonColor: "#DD6B55",
  4799. // confirmButtonText: "确认覆盖",
  4800. // cancelButtonText: "取消操作",
  4801. // closeOnConfirm: true,
  4802. // closeOnCancel: true
  4803. // }, function (isConfirm) {
  4804. // if (isConfirm) {
  4805. // $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  4806. // }
  4807. // });
  4808. }else{
  4809. $scope.incidentModel.description = $scope.copyItem.mutiCategory;
  4810. }
  4811. $scope.categorySelect = $scope.copyItem;
  4812. $scope.categorySelectId = $scope.copyItem.id;
  4813. // 处理责任科室数据
  4814. $scope.handlerDuty();
  4815. if($scope.selectTab == 2){
  4816. $scope.jry_solution($scope.categorySelect.id);
  4817. }
  4818. }
  4819. // 故障现象查询
  4820. $scope.c_timer = null;
  4821. $scope.c_keyword = '';
  4822. $scope.jry_categorySearch = function (key = '') {
  4823. $scope.c_keyword = key;
  4824. clearTimeout($scope.c_timer);
  4825. $scope.c_timer = setTimeout(()=>{
  4826. var categoryData = {
  4827. idx: 0,
  4828. sum: 9999,
  4829. incidentcategory: {
  4830. category: key,
  4831. selectType:'pinyin_qs',
  4832. hierarchyQuery:'three'
  4833. },
  4834. };
  4835. if($rootScope.user.duty){
  4836. categoryData.incidentcategory.dutyDepartment = $rootScope.user.duty;
  4837. }else if($rootScope.user.branch){
  4838. // categoryData.incidentcategory.branch = $rootScope.user.branch.id;
  4839. }
  4840. $scope.loading_c = true;
  4841. api_user_data.fetchDataList("incidentcategory", categoryData).then(function (data) {
  4842. if($scope.c_keyword == key){
  4843. $scope.loading_c = false;
  4844. data.list.forEach(v=>{
  4845. if(v.mutiCategory){
  4846. v.mutiCategory = v.mutiCategory.replace($scope.jry_modelLeft,'<span class="colorRed">'+$scope.jry_modelLeft+'</span>');
  4847. }
  4848. })
  4849. $scope.jry_categoryData = data.list;
  4850. if(modelData){
  4851. if( modelData.incident.category && !modelData.incident.category.complexity){
  4852. $scope.categorySelect = data.list.find(v=>v.id == modelData.incident.category.id);
  4853. if($scope.categorySelect){
  4854. $scope.categorySelectId = $scope.categorySelect.id;
  4855. }
  4856. }
  4857. }
  4858. }
  4859. });
  4860. },500)
  4861. };
  4862. $scope.jry_categorySearch($scope.jry_modelLeft);
  4863. // 右侧tab选中
  4864. $scope.selectTab = 1;
  4865. $scope.changeTab = function(id){
  4866. $scope.selectTab = id;
  4867. if(id == 1){
  4868. $scope.jry_incident($scope.incidentModel.department?$scope.incidentModel.department.id:undefined);
  4869. }else if(id == 2){
  4870. $scope.jry_solution($scope.categorySelect?$scope.categorySelect.id:undefined);
  4871. }
  4872. }
  4873. // 近期报修
  4874. $scope.jry_incident = function (deptId) {
  4875. $scope.loading_i = true;
  4876. var placeData = {
  4877. idx: 0,
  4878. sum: 6,
  4879. incident: {
  4880. department: {id:deptId},
  4881. },
  4882. };
  4883. api_user_data.fetchDataList("incident", placeData).then(function (data) {
  4884. $scope.loading_i = false;
  4885. data.list.forEach(v=>{
  4886. v.acceptDate = moment(v.acceptDate).format('MM-DD HH:mm')
  4887. })
  4888. $scope.jry_incidentData = data.list;
  4889. });
  4890. };
  4891. $scope.$watch("incidentModel.department", function (newVal,oldVal) {
  4892. $scope.showUserOrGroup();
  4893. newVal && $scope.jry_incident(newVal.id);
  4894. console.log(newVal);
  4895. if(newVal){
  4896. api_bpm_data.fetchData('department', $scope.incidentModel.department.id).then(res=>{
  4897. if(res.status == 200){
  4898. // $scope.incidentModel.department = res.data;
  4899. if(res.data && res.data.place){
  4900. $scope.incidentModel.place = res.data.place;
  4901. $scope.incidentModel.area = res.data.place.area;
  4902. }else{
  4903. $scope.incidentModel.place = '';
  4904. $scope.incidentModel.area = '';
  4905. }
  4906. $scope.incidentModel.address = res.data.address || '';
  4907. // 如果回显的有联系电话,联系电话不用科室带出
  4908. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (res.data&&res.data.phone)?res.data.phone.split(',')[0]:'');
  4909. }else{
  4910. $scope.incidentModel.place = '';
  4911. $scope.incidentModel.area = '';
  4912. $scope.incidentModel.address = '';
  4913. // 如果回显的有联系电话,联系电话不用科室带出
  4914. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  4915. }
  4916. })
  4917. }else{
  4918. $scope.incidentModel.place = '';
  4919. $scope.incidentModel.area = '';
  4920. $scope.incidentModel.address = '';
  4921. // 如果回显的有联系电话,联系电话不用科室带出
  4922. !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  4923. }
  4924. // if(newVal && newVal.place){
  4925. // $scope.incidentModel.place = newVal.place;
  4926. // $scope.incidentModel.area = newVal.place.area;
  4927. // }else{
  4928. // $scope.incidentModel.place = '';
  4929. // $scope.incidentModel.area = '';
  4930. // }
  4931. // // 如果回显的有联系电话,联系电话不用科室带出
  4932. // !(oldVal && !oldVal.dept) && ($scope.incidentModel.contactsInformation = (newVal&&newVal.phone)?newVal.phone:'');
  4933. });
  4934. // 知识库
  4935. $scope.jry_solution = function (id,key='') {
  4936. $scope.loading_i = true;
  4937. var placeData = {
  4938. idx: 0,
  4939. sum: 1000,
  4940. solution: {
  4941. threeSearch:key,
  4942. status: {id: 72},
  4943. selectType: "keySearch",
  4944. },
  4945. };
  4946. if(id){
  4947. placeData.solution.category = {id:id};
  4948. }
  4949. api_user_data.fetchDataList("solution", placeData).then(function (data) {
  4950. $scope.loading_i = false;
  4951. $scope.jry_solutionData = data.list;
  4952. });
  4953. };
  4954. // getFileFromBase64($scope.imgshows[0],'tt')
  4955. // 图片上传
  4956. $scope.imgshows = [];
  4957. $scope.uploadimgs = [];
  4958. var model = $parse("upload_img");
  4959. var modelSetter = model.assign;
  4960. var uploader = ($scope.uploader = new FileUploader({
  4961. url: "/uploader",
  4962. }));
  4963. // uploader.filters.push({
  4964. // name: "customFilter",
  4965. // fn: function (item /*{File|FileLikeObject}*/, options) {
  4966. // return this.queue.length < 10;
  4967. // },
  4968. // });
  4969. $scope.getDetail = function(imgs){
  4970. function getImageFileFromUrl(url, imageName, callback) {
  4971. // imageName一定要带上后缀
  4972. var blob = null
  4973. var xhr = new XMLHttpRequest()
  4974. xhr.open('GET', url)
  4975. xhr.setRequestHeader('Accept', 'image/jpeg')
  4976. xhr.responseType = 'blob'
  4977. xhr.onload = () => {
  4978. if (xhr.status === 200) {
  4979. blob = xhr.response
  4980. let imgFile = new File([blob], imageName, {type: 'image/jpeg'})
  4981. console.log(imgFile)
  4982. callback.call(this, imgFile)
  4983. }
  4984. }
  4985. xhr.send()
  4986. }
  4987. imgs.forEach((v,i)=>{
  4988. v.previewUrl = $rootScope.attachmentAddressSplicing(v.relativeFilePath);
  4989. getImageFileFromUrl(v.previewUrl,v.name,function(file){
  4990. var dummy = new FileUploader.FileItem(uploader, file);
  4991. uploader.queue.push(dummy);
  4992. getFile(file, $scope);
  4993. })
  4994. })
  4995. //获得预览图地址并且把file对象放入上传合集内
  4996. function getFile(imgupload, $scope) {
  4997. if (!imgupload) {
  4998. return;
  4999. }
  5000. fileReader.readAsDataUrl(imgupload, $scope).then(function (result) {
  5001. console.log(result)
  5002. $scope.imgshows.push(result);
  5003. var file = imgupload;
  5004. $scope.uploadimgs.push(file); //这里是放着传给后台的数据file,下面controller的时候会有
  5005. console.log($scope.imgshows, $scope.uploadimgs);
  5006. if ($scope.imgshows.length < 3) {
  5007. $("#upupgogo").show();
  5008. } else {
  5009. $("#upupgogo").hide();
  5010. }
  5011. });
  5012. }
  5013. }
  5014. // 是否回显报修端图片
  5015. // if(modelData){
  5016. // if (modelData.flow) {
  5017. // api_wechatfile
  5018. // .listAttachment("wechatRequesterIncident", modelData.flow)
  5019. // .then(function (res) {
  5020. // $scope.getDetail(res.data)
  5021. // });
  5022. // }
  5023. // }
  5024. // 添加
  5025. $scope.change = function (event) {
  5026. var element = $(".upinp");
  5027. modelSetter($scope, element[0].files[0]);
  5028. //附件预览
  5029. $scope.imgupload = event.files[0];
  5030. getFile($scope.imgupload, $scope);
  5031. //获得预览图地址并且把file对象放入上传合集内
  5032. function getFile(imgupload, $scope) {
  5033. if (!imgupload) {
  5034. return;
  5035. }
  5036. fileReader.readAsDataUrl(imgupload, $scope).then(function (result) {
  5037. console.log(result)
  5038. $scope.imgshows.push(result);
  5039. var file = document.querySelector("#upupgogo input[type=file]").files[0];
  5040. $scope.uploadimgs.push(file); //这里是放着传给后台的数据file,下面controller的时候会有
  5041. console.log($scope.imgshows, $scope.uploadimgs);
  5042. if ($scope.imgshows.length < 3) {
  5043. $("#upupgogo").show();
  5044. } else {
  5045. $("#upupgogo").hide();
  5046. }
  5047. });
  5048. }
  5049. };
  5050. // 删除
  5051. $scope.uploadimg_del = function (index, imgs) {
  5052. console.log(index, imgs);
  5053. $scope.imgshows.splice(index, 1);
  5054. $scope.uploadimgs.splice(index, 1);
  5055. $scope.uploader.queue.splice(index, 1);
  5056. if ($scope.imgshows.length < 3) {
  5057. $("#upupgogo").show();
  5058. } else {
  5059. $("#upupgogo").hide();
  5060. }
  5061. };
  5062. // 预览
  5063. $scope.preview = function (url, idx) {
  5064. var name = $scope.uploadimgs[idx].name;
  5065. $modal.open({
  5066. backdrop: false,
  5067. templateUrl: "assets/views/customform/tpl/ui-showimage.html",
  5068. controller: function ($scope, scope, $modalInstance) {
  5069. //创建一个标签用来加载图片
  5070. const image = document.createElement("img");
  5071. image.src = url
  5072. //待图片加载完成读取图片的真实宽高。
  5073. image.addEventListener("load", function(e) {
  5074. $scope.imgWidth = e.target.width + 'px';
  5075. $scope.imgHeight = e.target.height + 'px';
  5076. })
  5077. $scope.title = name;
  5078. $scope.imageurl = url;
  5079. $scope.cancel = function () {
  5080. $modalInstance.dismiss("cancel");
  5081. };
  5082. },
  5083. resolve: {
  5084. scope: function () {
  5085. return $scope;
  5086. },
  5087. },
  5088. });
  5089. };
  5090. if (uploader) {
  5091. uploader.onWhenAddingFileFailed = function (
  5092. item /*{File|FileLikeObject}*/,
  5093. filter,
  5094. options
  5095. ) {
  5096. console.info("onWhenAddingFileFailed", item, filter, options);
  5097. };
  5098. uploader.onAfterAddingFile = function (fileItem) {
  5099. console.info("onAfterAddingFile", fileItem);
  5100. };
  5101. uploader.onAfterAddingAll = function (addedFileItems) {
  5102. console.info("onAfterAddingAll", addedFileItems);
  5103. };
  5104. uploader.onBeforeUploadItem = function (item) {
  5105. console.info("onBeforeUploadItem", item);
  5106. };
  5107. uploader.onProgressItem = function (fileItem, progress) {
  5108. console.info("onProgressItem", fileItem, progress);
  5109. };
  5110. uploader.onProgressAll = function (progress) {
  5111. console.info("onProgressAll", progress);
  5112. };
  5113. uploader.onSuccessItem = function (
  5114. fileItem,
  5115. response,
  5116. status,
  5117. headers
  5118. ) {
  5119. console.info("onSuccessItem", fileItem, response, status, headers);
  5120. };
  5121. uploader.onErrorItem = function (
  5122. fileItem,
  5123. response,
  5124. status,
  5125. headers
  5126. ) {
  5127. console.info("onErrorItem", fileItem, response, status, headers);
  5128. };
  5129. uploader.onCancelItem = function (
  5130. fileItem,
  5131. response,
  5132. status,
  5133. headers
  5134. ) {
  5135. console.info("onCancelItem", fileItem, response, status, headers);
  5136. };
  5137. uploader.onCompleteItem = function (
  5138. fileItem,
  5139. response,
  5140. status,
  5141. headers
  5142. ) {
  5143. console.info("onCompleteItem", fileItem, response, status, headers);
  5144. };
  5145. uploader.onCompleteAll = function () {
  5146. console.info("onCompleteAll");
  5147. };
  5148. }
  5149. // 取消
  5150. $scope.cancel = function () {
  5151. if (localStorage.getItem('fenjiNumber')) {
  5152. $rootScope.jry_shixian();
  5153. }
  5154. $rootScope.newOrderShowOpen = false;
  5155. $modalInstance.dismiss("cancel");
  5156. };
  5157. // -------------------end----------------------
  5158. },
  5159. resolve: {
  5160. modelData:function(){
  5161. return model1;
  5162. }
  5163. },
  5164. });
  5165. }
  5166. // 事件实时播报
  5167. $rootScope.realtimeBroadcast = function(){
  5168. location.href = location.origin+'/#/bigScreen/realtimeBroadcast';
  5169. // window.open(location.origin+'/#/bigScreen/realtimeBroadcast');
  5170. }
  5171. // save settings to local storage
  5172. if (angular.isDefined($localStorage.layout)) {
  5173. $scope.app.layout = $localStorage.layout;
  5174. } else {
  5175. $localStorage.layout = $scope.app.layout;
  5176. }
  5177. $scope.$watch('app.layout', function () {
  5178. // save to local storage
  5179. $localStorage.layout = $scope.app.layout;
  5180. }, true);
  5181. //global function to scroll page up
  5182. $scope.toTheTop = function () {
  5183. $document.scrollTopAnimated(0, 600);
  5184. };
  5185. // angular translate
  5186. // ----------------------
  5187. $scope.language = {
  5188. // Handles language dropdown
  5189. listIsOpen: false,
  5190. // list of available languages
  5191. available: {
  5192. 'en': 'English',
  5193. 'it_IT': 'Italiano',
  5194. 'de_DE': 'Deutsch',
  5195. 'zh_cn': 'Chinese'
  5196. },
  5197. // display always the current ui language
  5198. init: function () {
  5199. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  5200. var preferredLanguage = $translate.preferredLanguage();
  5201. // we know we have set a preferred one in app.config
  5202. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  5203. },
  5204. set: function (localeId, ev) {
  5205. $translate.use(localeId);
  5206. $scope.language.selected = $scope.language.available[localeId];
  5207. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  5208. }
  5209. };
  5210. $scope.language.init();
  5211. // Function that find the exact height and width of the viewport in a cross-browser way
  5212. var viewport = function () {
  5213. var e = window,
  5214. a = 'inner';
  5215. if (!('innerWidth' in window)) {
  5216. a = 'client';
  5217. e = document.documentElement || document.body;
  5218. }
  5219. return {
  5220. width: e[a + 'Width'],
  5221. height: e[a + 'Height']
  5222. };
  5223. };
  5224. // function that adds information in a scope of the height and width of the page
  5225. $scope.getWindowDimensions = function () {
  5226. return {
  5227. 'h': viewport().height,
  5228. 'w': viewport().width
  5229. };
  5230. };
  5231. // Detect when window is resized and set some variables
  5232. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  5233. $scope.windowHeight = newValue.h;
  5234. $scope.windowWidth = newValue.w;
  5235. if (newValue.w >= 992) {
  5236. $scope.isLargeDevice = true;
  5237. } else {
  5238. $scope.isLargeDevice = false;
  5239. }
  5240. if (newValue.w < 992) {
  5241. $scope.isSmallDevice = true;
  5242. } else {
  5243. $scope.isSmallDevice = false;
  5244. }
  5245. if (newValue.w <= 768) {
  5246. $scope.isMobileDevice = true;
  5247. } else {
  5248. $scope.isMobileDevice = false;
  5249. }
  5250. }, true);
  5251. // Apply on resize
  5252. $win.on('resize', function () {
  5253. $scope.$apply();
  5254. });
  5255. $rootScope.app.layout.isNavbarFixed = false;
  5256. $rootScope.app.layout.isSidebarFixed = false;
  5257. $rootScope.app.layout.isFooterFixed = false;
  5258. $scope.login_signquick = function (Requesteruserinform) {
  5259. $rootScope.statuscall = 1;
  5260. $scope.loginForm = {
  5261. username: Requesteruserinform.username,
  5262. password: Requesteruserinform.password
  5263. }
  5264. $auth.submitLogin($scope.loginForm)
  5265. .then(function (resp) {
  5266. localStorage.setItem("jry_user", JSON.stringify(resp));
  5267. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  5268. $rootScope.isRealtimeBroadcast = ($rootScope.user && $rootScope.user.menu)?$rootScope.user.menu.some(v => v.link == 'realtimeBroadcast'):false;
  5269. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  5270. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  5271. var onlyMenu = [];
  5272. for (var i = 0; i < allJurisdiction.length; i++) {
  5273. if (allJurisdiction[i].event == "1") {
  5274. onlyMenu.push(allJurisdiction[i])
  5275. }
  5276. };
  5277. $rootScope.userMenus = onlyMenu;
  5278. getMenus();
  5279. if (resp.error != 500) {
  5280. // $state.go('app.dashboard');
  5281. $rootScope.app.isLoginFixed = false;
  5282. } else {
  5283. resp.error = "";
  5284. $scope.loginForm.password = "";
  5285. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  5286. }
  5287. })
  5288. .catch(function (resp) {
  5289. $scope.loginForm.password = "";
  5290. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  5291. });
  5292. }
  5293. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  5294. var theRequest = {};
  5295. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  5296. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  5297. var str = url.substr(index + 1);
  5298. var strs = str.split("&");
  5299. for (var i = 0; i < strs.length; i++) {
  5300. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  5301. }
  5302. // return theRequest;
  5303. $scope.login_signquick(theRequest)
  5304. }
  5305. // $scope.casUserId = window.location.search;
  5306. // $scope.loginForm = {
  5307. // username: theRequest[0].split("=")[1],
  5308. // password: theRequest[1].split("=")[1]
  5309. // }
  5310. // $scope.lodingstyle = 'nodata';
  5311. var userAgent = window.navigator.userAgent.toLowerCase();
  5312. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  5313. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  5314. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  5315. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  5316. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  5317. if (isOpera) {
  5318. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  5319. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  5320. }
  5321. if (isIE) {
  5322. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  5323. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  5324. }
  5325. if (isFF) {
  5326. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  5327. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  5328. }
  5329. if (isSafari) {
  5330. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  5331. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  5332. }
  5333. if (isChrome) {
  5334. // login_sign();
  5335. $rootScope.app.isChrome = false;
  5336. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  5337. } else {
  5338. $rootScope.app.isChrome = true;
  5339. $scope.checkchrome = '';
  5340. // return alert("访问失败,请用Chrome浏览器访问!");
  5341. }
  5342. // }
  5343. // $scope.handleloginEnter = function(e) {
  5344. // if (e.keyCode == 13) {
  5345. // $scope.handleLoginClick();
  5346. // }
  5347. // };
  5348. // if (document.getElementById("isWatch").value == "true") {
  5349. // $scope.isHanderuser = true;
  5350. // } else {
  5351. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  5352. // $scope.isHanderuser = false;
  5353. // $scope.login_sign();
  5354. // }
  5355. // }
  5356. // $scope.viewType = "password";
  5357. // $scope.isPassword = true;
  5358. // $scope.toggleView = function() {
  5359. // $scope.isPassword = !$scope.isPassword;
  5360. // $scope.viewType = $scope.isPassword ? "password" : "text";
  5361. // }
  5362. // $scope.handleSignOutBtnClick = function() {
  5363. // $auth.signOut()
  5364. // .then(function(resp) {
  5365. // // handle success response
  5366. // })
  5367. // .catch(function(resp) {
  5368. // // handle error response
  5369. // });
  5370. // };
  5371. // }
  5372. // }
  5373. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  5374. // } else {
  5375. // $scope.loginstart();
  5376. // }
  5377. //websocket 信息中心
  5378. console.log(atmosphere)
  5379. var socket = atmosphere;
  5380. var subSocket;
  5381. // We are now ready to cut the request
  5382. var request = {
  5383. url: 'ws://192.168.199.150:8080/messagestation/cache',
  5384. contentType: "application/json",
  5385. shared: true, // 标签共享
  5386. trackMessageLength: true, //校验数据完整性
  5387. transport: 'websocket'
  5388. };
  5389. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  5390. request.onOpen = function (response) {
  5391. console.log(response)
  5392. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  5393. // alert("开始连接")
  5394. };
  5395. request.onMessage = function (response) {
  5396. var message = response.responseBody;
  5397. // alert("连接成功")
  5398. console.log(message)
  5399. try {
  5400. var json = JSON.parse(message);
  5401. console.log(json.noRead)
  5402. $scope.noReadData = json.noRead
  5403. } catch (e) {
  5404. console.log('呵呵哒: ', message);
  5405. return;
  5406. }
  5407. };
  5408. request.onClose = function (response) {
  5409. // alert("连接结束")
  5410. }
  5411. request.onError = function (response) {
  5412. // alert('连接失败')
  5413. };
  5414. //信息中心模态框
  5415. var loginUser = $rootScope.user;
  5416. // if(loginUser){
  5417. // // 未读消息数量
  5418. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  5419. // if (data.status == 200) {
  5420. // $scope.noReadData=data.totalNum
  5421. // // $rootScope.option.all = $rootScope.all;
  5422. // } else {
  5423. // $scope.noReadData=0
  5424. // }
  5425. // })
  5426. // }
  5427. // $scope.noReadData=($rootScope.noReadData||0)
  5428. // // $rootScope.all = 5;
  5429. // setTimeout(function() {
  5430. // console.log($scope.noReadData)
  5431. // }, 500)
  5432. $rootScope.wt_messages = function () {
  5433. var modalInstance = $modal.open({
  5434. templateUrl: '../../../assets/views/wt_messages.html',
  5435. controller: function ($scope, $modalInstance, SweetAlert) {
  5436. $rootScope.msgData = {
  5437. idx: 0,
  5438. sum: 5,
  5439. messageStation: {
  5440. readStatus: 0,
  5441. userId: $rootScope.user.id
  5442. }
  5443. }
  5444. // 关闭
  5445. $scope.closeModel = function () {
  5446. modalInstance.close();
  5447. }
  5448. $scope.getMsgData = function () {
  5449. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5450. if (data) {
  5451. $rootScope.msg = data.list
  5452. $rootScope.all = data.pageCount;
  5453. $scope.wt_msgData = data
  5454. $rootScope.noReadData = data.totalNum
  5455. }
  5456. })
  5457. }
  5458. $scope.getMsgData()
  5459. $scope.message_type = 2;
  5460. $scope.message_no = function (type) { //未读1
  5461. $scope.wt_msgData = {};
  5462. $scope.message_type = type;
  5463. $rootScope.msgData.messageStation.readStatus = 0,
  5464. // $rootScope.option.curr = 1;
  5465. $rootScope.msgData.idx = 0;
  5466. // console.log($rootScope.option.curr)
  5467. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5468. $scope.msg_yesType = true;
  5469. if (data.status == 200) {
  5470. $scope.msg_yesType = false
  5471. $scope.wt_msgData = data
  5472. $rootScope.msg = data.list
  5473. $rootScope.all = data.pageCount;
  5474. $rootScope.noReadData = data.totalNum;
  5475. // $rootScope.option.all = $rootScope.all;
  5476. } else {
  5477. $scope.msg_yesType = true;
  5478. }
  5479. })
  5480. }
  5481. $scope.message_yes = function (type) { //已读0
  5482. $scope.wt_msgData = {};
  5483. $scope.message_type = type;
  5484. $rootScope.msgData.messageStation.readStatus = 1,
  5485. $rootScope.msgData.idx = 0;
  5486. // $rootScope.option.curr = 1;
  5487. // console.log($rootScope.option.curr)
  5488. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5489. $scope.msg_noType = true;
  5490. if (data.status == 200) {
  5491. $scope.msg_noType = false
  5492. $scope.wt_msgData = data
  5493. $rootScope.msg = data.list;
  5494. $rootScope.all = data.pageCount;
  5495. // $rootScope.option.all = $rootScope.all;
  5496. } else {
  5497. $scope.msg_noType = true
  5498. }
  5499. })
  5500. };
  5501. $scope.sBtn = function () {
  5502. // console.log($rootScope.msgData)
  5503. // console.log($scope.wt_msgData)
  5504. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  5505. console.log($rootScope.msgData)
  5506. $scope.getMsgData()
  5507. }
  5508. $scope.xBtn = function () {
  5509. // console.log($rootScope.msgData)
  5510. // console.log($scope.wt_msgData)
  5511. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  5512. console.log($rootScope.msgData)
  5513. $scope.getMsgData()
  5514. }
  5515. $scope.redIn = function (data) {
  5516. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  5517. $scope.messageStation = {
  5518. messageStation: {
  5519. id: data.id,
  5520. readStatus: 1,
  5521. readTime: start
  5522. }
  5523. }
  5524. api_msg.updateDataList($scope.messageStation).then(function (data) {
  5525. console.log(data);
  5526. if (data.status == 200) {
  5527. $rootScope.msgData.messageStation.readStatus = 0,
  5528. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5529. $rootScope.msg = data.list
  5530. $rootScope.all = data.pageCount;
  5531. $rootScope.noReadData = data.totalNum;
  5532. })
  5533. }
  5534. })
  5535. };
  5536. // 一键已读
  5537. $scope.redAllIn = function () {
  5538. SweetAlert.swal({
  5539. title: "是否确认?",
  5540. type: "warning",
  5541. showCancelButton: true,
  5542. confirmButtonColor: "#DD6B55",
  5543. confirmButtonText: "确认",
  5544. cancelButtonText: "取消",
  5545. closeOnConfirm: true,
  5546. closeOnCancel: true
  5547. }, function (isConfirm) {
  5548. if (isConfirm) {
  5549. $rootScope.isMask = true;
  5550. api_msg.oneClickRead({userId: $rootScope.user.id}).then(function (data) {
  5551. $rootScope.isMask = false;
  5552. if (data.status == 200) {
  5553. $rootScope.msgData.messageStation.readStatus = 0,
  5554. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5555. $scope.wt_msgData = data
  5556. $rootScope.msg = data.list
  5557. $rootScope.all = data.pageCount;
  5558. $rootScope.noReadData = data.totalNum;
  5559. })
  5560. }
  5561. })
  5562. } else {}
  5563. });
  5564. };
  5565. },
  5566. size: 'lg',
  5567. resolve: {
  5568. }
  5569. })
  5570. }
  5571. }
  5572. ]);
  5573. // 录音盒子
  5574. app.service('WebsocketPhoneService', function () {
  5575. return {
  5576. lockReconnect: false, //避免ws重复连接
  5577. ws: null, //定义websocket
  5578. url: "", //ws连接地址
  5579. urlParams: null, //ws连接传参
  5580. isHandler: false, //是否手动
  5581. subject: null,
  5582. reconnectTimer: null,//重连的计时器
  5583. // 连接websocket
  5584. connectWs(url, data) {
  5585. this.url = url;
  5586. this.urlParams = data;
  5587. this.subject = new rxjs.Subject();
  5588. let request = {
  5589. webSocketUrl: url,
  5590. trackMessageLength: true, //校验数据完整性
  5591. transport: "websocket",
  5592. handleOnlineOffline: false,
  5593. suspend: false,
  5594. maxReconnectOnClose: 0,
  5595. };
  5596. request.onOpen = (response) => {
  5597. console.log("ws连接成功" + new Date().toLocaleString());
  5598. this.heartCheck.reset().start(this);
  5599. console.log(response);
  5600. this.ws.push(JSON.stringify(data));
  5601. };
  5602. request.onMessage = (response) => {
  5603. this.heartCheck.reset().start(this);
  5604. let message = response.responseBody;
  5605. try {
  5606. console.log("收到消息" + message);
  5607. if (message !== "pong") {
  5608. this.subject.next(JSON.parse(message));
  5609. }
  5610. } catch (e) {
  5611. console.log("This doesn't look like a valid JSON: ", message);
  5612. return;
  5613. }
  5614. };
  5615. request.onClose = (response) => {
  5616. console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
  5617. this.ws = null;
  5618. console.log(response)
  5619. if (!this.isHandler && response.status === 408) {
  5620. this.reconnect(this.url, this.urlParams);
  5621. }
  5622. };
  5623. request.onError = (response) => {
  5624. console.log("ws连接错误", this.isHandler);
  5625. this.ws = null;
  5626. if (response.status === 0) {
  5627. this.reconnect(this.url, this.urlParams);
  5628. }
  5629. };
  5630. this.ws = atmosphere.subscribe(request);
  5631. return this.subject.asObservable();
  5632. },
  5633. //断线重连
  5634. reconnect(url, data) {
  5635. if (this.lockReconnect) return;
  5636. this.lockReconnect = true;
  5637. this.reconnectTimer = setTimeout(() => {
  5638. //没连接上会一直重连,设置延迟避免请求过多
  5639. this.connectWs(url, data);
  5640. this.lockReconnect = false;
  5641. }, 15000);
  5642. },
  5643. heartCheck: {
  5644. timeout: 30000, //发一次心跳的间隔时间
  5645. timeoutObj: null,
  5646. serverTimeoutObj: null,
  5647. reset: function () {
  5648. clearTimeout(this.timeoutObj);
  5649. clearTimeout(this.serverTimeoutObj);
  5650. return this;
  5651. },
  5652. start: function (_this) {
  5653. this.timeoutObj = setTimeout(() => {
  5654. //这里发送一个心跳,后端收到后,返回一个心跳消息,
  5655. //onmessage拿到返回的心跳就说明连接正常
  5656. if (_this.ws) {
  5657. _this.ws.push("ping");
  5658. }
  5659. this.serverTimeoutObj = setTimeout(() => {
  5660. //如果超过一定时间还没重置,说明后端主动断开了
  5661. _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  5662. }, this.timeout);
  5663. }, this.timeout);
  5664. },
  5665. },
  5666. // 断开websocket
  5667. closeWs(flag = false) {
  5668. this.isHandler = flag;
  5669. if (flag) {
  5670. clearTimeout(this.reconnectTimer);
  5671. }
  5672. if (this.ws) {
  5673. this.ws.close();
  5674. }
  5675. }
  5676. };
  5677. });
  5678. //消息中心分页组件
  5679. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  5680. $rootScope.option = {
  5681. curr: 1, //当前页数
  5682. all: $rootScope.all, //总页数
  5683. count: 5, //最多显示的页数,默认为10
  5684. //点击页数的回调函数,参数page为点击的页数
  5685. click: function (page) {
  5686. $rootScope.msgData.idx = page - 1;
  5687. //这里可以写跳转到某个页面等...
  5688. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  5689. $rootScope.msg = data.list
  5690. $rootScope.all = data.pageCount;
  5691. $rootScope.option.all = $rootScope.all;
  5692. })
  5693. }
  5694. }
  5695. }]);
  5696. app.directive('myPagination', function () {
  5697. return {
  5698. restrict: 'EA',
  5699. replace: true,
  5700. rootScope: {
  5701. option: '=pageOption'
  5702. },
  5703. controller: 'msgCtrl',
  5704. template: '<ul class="pagination">' +
  5705. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  5706. '<a href="javascript:;">{{p}}</a>' +
  5707. '</li>' +
  5708. '</ul>',
  5709. link: function ($rootScope) {
  5710. //容错处理
  5711. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  5712. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  5713. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  5714. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  5715. //得到显示页数的数组
  5716. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  5717. //绑定点击事件
  5718. $rootScope.pageClick = function (page) {
  5719. if (page == '«') {
  5720. page = parseInt($rootScope.option.curr) - 1;
  5721. } else if (page == '»') {
  5722. page = parseInt($rootScope.option.curr) + 1;
  5723. }
  5724. if (page < 1) page = 1;
  5725. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  5726. //点击相同的页数 不执行点击事件
  5727. if (page == $rootScope.option.curr) return;
  5728. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  5729. $rootScope.option.click(page);
  5730. $rootScope.option.curr = page;
  5731. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  5732. }
  5733. };
  5734. //返回页数范围(用来遍历)
  5735. function getRange(curr, all, count) {
  5736. //计算显示的页数
  5737. // console.log(curr, all, count)
  5738. curr = parseInt(curr);
  5739. all = parseInt(all);
  5740. count = parseInt(count);
  5741. var from = curr - parseInt(count / 2);
  5742. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  5743. //显示的页数容处理
  5744. if (from <= 0) {
  5745. from = 1;
  5746. to = from + count - 1;
  5747. if (to > all) {
  5748. to = all;
  5749. }
  5750. }
  5751. if (to > all) {
  5752. to = all;
  5753. from = to - count + 1;
  5754. if (from <= 0) {
  5755. from = 1;
  5756. }
  5757. }
  5758. var range = [];
  5759. for (var i = from; i <= to; i++) {
  5760. range.push(i);
  5761. }
  5762. range.push('»');
  5763. range.unshift('«');
  5764. return range;
  5765. }
  5766. }
  5767. }
  5768. });
  5769. app.service('Myservice', function () {
  5770. return {
  5771. };
  5772. });
  5773. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  5774. // console.log(bh)
  5775. // if(bh>=0&&bh<=53){
  5776. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  5777. // }else{
  5778. // $('#sidebar').css('padding-bottom', 0 + 'px')
  5779. // }
  5780. window.onscroll = function () {
  5781. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  5782. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  5783. } else {
  5784. $('#sidebar').css('padding-top', '0')
  5785. }
  5786. // console.log(window.pageYOffset)
  5787. // console.log(window.innerHeight)
  5788. // console.log(document.body.scrollHeight)
  5789. // 底部padding
  5790. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  5791. // console.log(bh)
  5792. // if(bh>=0&&bh<=53){
  5793. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  5794. // }else{
  5795. // $('#sidebar').css('padding-bottom', 0 + 'px')
  5796. // }
  5797. }