mainCtrl.js 263 KB

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