app.js 313 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder'], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config([ '$httpProvider', function($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function(response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url : "/index",
  26. views : {
  27. "left-view" : {
  28. templateUrl : "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view" : {
  32. templateUrl : "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url : "/",
  38. views : {
  39. "left-view" : {
  40. templateUrl : "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view" : {
  44. templateUrl : "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url : "/sale",
  50. views : {
  51. "left-view" : {
  52. templateUrl : "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view" : {
  56. templateUrl : "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url : "",
  65. templateUrl : "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url : "/",
  68. templateUrl : "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url : "/purc",
  71. views : {
  72. "left-view" : {
  73. templateUrl : "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view" : {
  77. templateUrl : "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url : "",
  86. templateUrl : "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url : "/",
  89. templateUrl : "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url : "/introduce",
  92. templateUrl : "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url : "/order",
  95. templateUrl : "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url : "/order/:id",
  99. templateUrl : "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url : "/addOrder",
  103. templateUrl : "static/tpl/index/purc/addOrder.html",
  104. controller : 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url : "/cart",
  107. templateUrl : "static/tpl/index/purc/cart.html",
  108. controller : 'CartController'
  109. }).state('purc.cartDetail', {
  110. url : "/cart/:id",
  111. templateUrl : "static/tpl/index/purc/cart_detail.html",
  112. controller : 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url : "/deputy",
  115. templateUrl : "static/tpl/index/purc/deputyOrder.html",
  116. controller : 'DeputyOrderCtrl'
  117. }).state('purc.newdeputy', {
  118. url : "/deputy/add",
  119. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  120. controller : 'NewDeputyOrderCtrl'
  121. /* 招标列表 */
  122. }).state('purc.tenderlist', {
  123. url : "/tender",
  124. templateUrl : "static/tpl/index/purc/tenderlist.html",
  125. controller : 'PurcTenderCtrl'
  126. }).state('purc.done.tenderlist', {
  127. url : "/tender",
  128. templateUrl : "static/tpl/index/purc/tenderlist.html",
  129. controller : 'PurcTenderCtrl'
  130. /* 招标 */
  131. }).state('purc.tender', {
  132. url : "/tender/:id",
  133. templateUrl : "static/tpl/index/purc/tender.html",
  134. controller : 'PurcNewTenderCtrl'
  135. /* 评标 */
  136. }).state('purc.evaluation', {
  137. url : "/evaluation/:id",
  138. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  139. controller : 'PurcEvaluationCtrl'
  140. /* 客户指定招标列表 */
  141. }).state('sale.tenderlist', {
  142. url : "/tender",
  143. templateUrl : "static/tpl/index/sale/tenderlist.html",
  144. controller : 'SaleTenderCtrl'
  145. }).state('sale.todo.tenderlist', {
  146. url : "/tender",
  147. templateUrl : "static/tpl/index/sale/tenderlist.html",
  148. controller : 'SaleTenderCtrl'
  149. /* 平台公开招标列表 */
  150. }).state('sale.opentenderlist', {
  151. url : "/opentender",
  152. templateUrl : "static/tpl/index/sale/opentenderlist.html",
  153. controller : 'SaleOpenTenderCtrl'
  154. }).state('sale.todo.opentenderlist', {
  155. url : "/opentender",
  156. templateUrl : "static/tpl/index/sale/opentenderlist.html",
  157. controller : 'SaleOpenTenderCtrl'
  158. /* 公开招标单转投标单 */
  159. }).state('sale.opentender', {
  160. url : "/opentender/:id",
  161. templateUrl : "static/tpl/index/sale/tender.html",
  162. controller : 'SaleTenderDetailCtrl'
  163. /* 投标 */
  164. }).state('sale.tender', {
  165. url : "/tender/:id",
  166. templateUrl : "static/tpl/index/sale/tender.html",
  167. controller : 'SaleTenderDetailCtrl'
  168. /* 采购方查看供应商投标 */
  169. }).state('sale.vendortender', {
  170. url : "/tender/:vendUU/:id",
  171. templateUrl : "static/tpl/index/sale/tender_vendor.html",
  172. controller : 'SaleVendorTenderDetailCtrl'
  173. }).state('sale.todo', {
  174. url : "/todo",
  175. templateUrl : "static/tpl/index/sale/todo.html"
  176. }).state('sale.todo.inquiry', {
  177. url : "/inquiry",
  178. templateUrl : "static/tpl/index/sale/inquiry.html",
  179. controller: 'SaleInquiryCtrl'
  180. }).state('sale.todo.order', {
  181. url : "/order",
  182. templateUrl : "static/tpl/index/sale/order.html",
  183. controller: 'SaleOrderCtrl'
  184. }).state('sale.todo.change', {
  185. url : "/change",
  186. templateUrl : "static/tpl/index/sale/change.html",
  187. controller: 'SaleChangeCtrl'
  188. }).state('sale.todo.notice', {
  189. url : "/notice",
  190. templateUrl : "static/tpl/index/sale/notice.html",
  191. controller: 'SaleNoticeCtrl'
  192. }).state('sale.customer', {
  193. url : "/customer",
  194. templateUrl : "static/tpl/index/sale/customer.html",
  195. controller: 'CustomerCtrl'
  196. }).state('sale.customerProduct', {
  197. url : "/customerProduct",
  198. templateUrl : "static/tpl/index/sale/customer.html",
  199. controller: 'CustomerCtrl'
  200. }).state('sale.inquiry', {
  201. url : "/inquiry",
  202. templateUrl : "static/tpl/index/sale/inquiry.html",
  203. controller: 'SaleInquiryCtrl'
  204. }).state('sale.inquirymould', {
  205. url : "/mould",
  206. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  207. controller: 'SaleInquiryMouldCtrl'
  208. }).state('sale.todo.inquirymould', {
  209. url : "/mould",
  210. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  211. controller: 'SaleInquiryMouldCtrl'
  212. }).state('sale.inquiry_mould_detail', {
  213. url : "/mould/:id",
  214. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  215. controller: 'SaleInquiryMouldDetailCtrl'
  216. }).state('sale.inquiry_detail', {
  217. url : "/inquiry/:id",
  218. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  219. controller: 'SaleInquiryDetailCtrl'
  220. }).state('sale.quotation', {
  221. url : "/quotation",
  222. templateUrl : "static/tpl/index/sale/quotation.html"
  223. }).state('sale.quotation.new', {
  224. url : "/new",
  225. templateUrl : "static/tpl/index/sale/quotation_new.html",
  226. controller: 'SaleQuotationNewCtrl'
  227. }).state('sale.quotation.list', {
  228. url : "/list",
  229. templateUrl : "static/tpl/index/sale/quotation_list.html",
  230. controller: 'SaleQuotationListCtrl'
  231. }).state('sale.quotation.item', {
  232. url : "/:id",
  233. templateUrl : "static/tpl/index/sale/quotation_new.html",
  234. controller: 'SaleQuotationNewCtrl'
  235. }).state('sale.order', {
  236. url : "/order",
  237. templateUrl : "static/tpl/index/sale/order.html",
  238. controller: 'SaleOrderCtrl'
  239. }).state('sale.order_detail', {
  240. url : "/order/:id",
  241. templateUrl : "static/tpl/index/sale/order_detail.html",
  242. controller: 'SaleOrderDetailCtrl'
  243. }).state('sale.change', {
  244. url : "/change",
  245. templateUrl : "static/tpl/index/sale/change.html",
  246. controller: 'SaleChangeCtrl'
  247. }).state('sale.change_detail', {
  248. url : "/change/:id",
  249. templateUrl : "static/tpl/index/sale/change_detail.html",
  250. controller: 'SaleChangeDetailCtrl'
  251. }).state('sale.notice', {
  252. url : "/notice",
  253. templateUrl : "static/tpl/index/sale/notice.html",
  254. controller: 'SaleNoticeCtrl'
  255. }).state('sale.send', {
  256. url : "/send",
  257. templateUrl : "static/tpl/index/sale/send.html",
  258. controller: 'SaleSendCtrl'
  259. }).state('sale.send_detail', {
  260. url : "/send/:id",
  261. templateUrl : "static/tpl/index/sale/send_detail.html",
  262. controller: 'SaleSendDetailCtrl'
  263. }).state('sale.forecast', {
  264. url : "/forecast",
  265. templateUrl : "static/tpl/index/sale/forecast.html",
  266. controller: 'SaleForecastCtrl'
  267. }).state('sale.accept', {
  268. url : "/accept",
  269. templateUrl : "static/tpl/index/sale/accept.html",
  270. controller: 'SaleAcceptCtrl'
  271. }).state('sale.returns', {
  272. url : "/returns",
  273. templateUrl : "static/tpl/index/sale/returns.html",
  274. controller: 'SaleReturnsCtrl'
  275. }).state('sale.sample', {
  276. url : "/sample",
  277. templateUrl : "static/tpl/index/sale/sample.html",
  278. controller: 'SaleSampleCtrl'
  279. }).state('sale.sample_detail', {
  280. url : "/sample/:id",
  281. templateUrl : "static/tpl/index/sale/sample_detail.html",
  282. controller: 'SaleSampleDetailCtrl'
  283. }).state('sale.approval', {
  284. url : "/approval",
  285. templateUrl : "static/tpl/index/sale/approval.html",
  286. controller: 'SaleApprovalCtrl'
  287. }).state('account', {
  288. url : "/account",
  289. views : {
  290. "left-view" : {
  291. templateUrl : "static/tpl/index/account/left.html",
  292. controller: 'LeftCtrl'
  293. },
  294. "right-view" : {
  295. templateUrl : "static/tpl/index/account/right.html"
  296. }
  297. }
  298. }).state('account.index', {
  299. url : "",
  300. templateUrl : "static/tpl/index/account/index.html",
  301. controller: 'RightCtrl'
  302. }).state('account.home', {
  303. url : "/",
  304. templateUrl : "static/tpl/index/account/index.html",
  305. controller: 'RightCtrl'
  306. }).state('account.enterprise', {
  307. url : "/enterprise",
  308. templateUrl : "static/tpl/index/account/enterprise.html",
  309. controller: 'EnterpriseCtrl'
  310. }).state('account.user', {
  311. url : "/user",
  312. templateUrl : "static/tpl/index/account/user.html",
  313. controller: 'UserCtrl'
  314. }).state('account.log', {
  315. url : "/log",
  316. templateUrl : "static/tpl/index/account/log.html",
  317. controller: 'LogCtrl'
  318. }).state('account.resource', {
  319. url : "/resource",
  320. templateUrl : "static/tpl/index/account/resource.html",
  321. controller: 'ResourceCtrl'
  322. }).state('account.role', {
  323. url : "/role",
  324. templateUrl : "static/tpl/index/account/role.html",
  325. controller: 'RoleCtrl'
  326. }).state('baseInfo', {//基础资料
  327. url : "/baseInfo",
  328. views : {
  329. "left-view" : {
  330. templateUrl : "static/tpl/index/baseInfo/left.html",
  331. controller: 'LeftCtrl'
  332. },
  333. "right-view" : {
  334. templateUrl : "static/tpl/index/baseInfo/right.html"
  335. }
  336. }
  337. }).state('baseInfo.index', {
  338. url : "/enterpriseList",
  339. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  340. controller: 'EnterpriseListCtrl'
  341. }).state('baseInfo.home', {
  342. url : "/enterpriseList",
  343. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  344. controller: 'EnterpriseListCtrl'
  345. }).state('baseInfo.prodList', {
  346. url : "/prodList",
  347. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  348. controller : 'ProductListCtrl'
  349. }).state('baseInfo.uploadByBatch', {
  350. url : "/uploadByBatch",
  351. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  352. controller : 'UploadByBatchCtrl'
  353. }).state('baseInfo.productDetail', {
  354. url : "/prodList/:id",
  355. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  356. controller : 'ProductDetailCtrl'
  357. }).state('baseInfo.newProdInfo', {
  358. url : "/newProdInfo",
  359. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  360. controller : 'NewProdInfoCtrl'
  361. }).state('baseInfo.enterpriseList', {
  362. url : "/enterpriseList",
  363. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  364. controller : 'EnterpriseListCtrl'
  365. }).state('baseInfo.myClient', {
  366. url : "/myClient",
  367. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  368. controller : 'MyClientCtrl'
  369. }).state('baseInfo.mySupplier', {
  370. url : "/mySupplier",
  371. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  372. controller : 'MySupplierCtrl'
  373. }).state('baseInfo.myRequest', {
  374. url : "/myRquest",
  375. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  376. controller : 'AddPartnerRequestCtrl'
  377. }).state('baseInfo.myMessage', {
  378. url : "/myMessage",
  379. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  380. controller : 'AddPartnerMessageCtrl'
  381. }).state('baseInfo.myPartners', {
  382. url : '/myPartners',
  383. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  384. controller : 'MyPartnersCtrl'
  385. }).state('baseInfo.businessGroups', {
  386. url : '/businessGroups',
  387. controller : 'BusinessGroupsCtrl'
  388. }).state('qc', {
  389. url : "/qc",
  390. views : {
  391. "left-view" : {
  392. templateUrl : "static/tpl/index/qc/left.html"
  393. },
  394. "right-view" : {
  395. templateUrl : "static/tpl/index/qc/right.html"
  396. }
  397. }
  398. }).state('qc.index', {
  399. url : "",
  400. templateUrl : "static/tpl/index/qc/index.html"
  401. }).state('qc.home', {
  402. url : "/",
  403. templateUrl : "static/tpl/index/qc/index.html"
  404. }).state('qc.badIn', {
  405. url : "/badIn",
  406. templateUrl : "static/tpl/index/qc/badIn.html",
  407. controller: 'SaleBadInCtrl'
  408. }).state('qc.badOut', {
  409. url : "/badOut",
  410. templateUrl : "static/tpl/index/qc/badOut.html",
  411. controller: 'SaleBadOutCtrl'
  412. }).state('qc.MRB', {
  413. url : "/MRB",
  414. templateUrl : "static/tpl/index/qc/MRB.html",
  415. controller: 'SaleMRBCtrl'
  416. }).state('fa', {
  417. url : "/fa",
  418. views : {
  419. "left-view" : {
  420. templateUrl : "static/tpl/index/fa/left.html"
  421. },
  422. "right-view" : {
  423. templateUrl : "static/tpl/index/fa/right.html"
  424. }
  425. }
  426. }).state('fa.index', {
  427. url : "",
  428. templateUrl : "static/tpl/index/fa/index.html"
  429. }).state('fa.home', {
  430. url : "/",
  431. templateUrl : "static/tpl/index/fa/index.html"
  432. }).state('fa.apBill', {
  433. url : "/apBill",
  434. templateUrl : "static/tpl/index/fa/apBill.html",
  435. controller: 'SaleApBillCtrl'
  436. }).state('fa.arCheck', {
  437. url : "/arCheck",
  438. templateUrl : "static/tpl/index/fa/arCheck.html",
  439. controller: 'SaleArCheckCtrl'
  440. }).state('fa.arCheck_detail', {
  441. url : "/arCheck/:id",
  442. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  443. controller: 'SaleArCheckDetailCtrl'
  444. }).state('fa.apCheck', {
  445. url : "/apCheck",
  446. params:{
  447. 'id':null
  448. },
  449. templateUrl : "static/tpl/index/fa/apCheck.html",
  450. controller: 'PurchaseApCheckCtrl'
  451. }).state('fa.apCheck_detail', {
  452. url : "/apCheck/:id",
  453. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  454. controller: 'PurchaseApCheckDetailCtrl'
  455. }).state('fa.apCheckList', {
  456. url : "/apCheckList",
  457. templateUrl : "static/tpl/index/fa/apCheckList.html",
  458. controller: 'PurchaseApCheckListCtrl'
  459. }).state('make', {
  460. url : "/make",
  461. views : {
  462. "left-view" : {
  463. templateUrl : "static/tpl/index/make/left.html"
  464. },
  465. "right-view" : {
  466. templateUrl : "static/tpl/index/make/right.html"
  467. }
  468. }
  469. }).state('make.index', {
  470. url : "",
  471. templateUrl : "static/tpl/index/make/index.html"
  472. }).state('make.home', {
  473. url : "/",
  474. templateUrl : "static/tpl/index/make/index.html"
  475. }).state('make.todo', {
  476. url : "/todo",
  477. templateUrl : "static/tpl/index/make/todo.html"
  478. }).state('make.todo.order', {
  479. url : "/order",
  480. templateUrl : "static/tpl/index/make/order.html",
  481. controller: 'MakeOrderCtrl'
  482. }).state('make.order', {
  483. url : "/order",
  484. templateUrl : "static/tpl/index/make/order.html",
  485. controller: 'MakeOrderCtrl'
  486. }).state('make.order_detail', {
  487. url : "/order/:id",
  488. templateUrl : "static/tpl/index/make/order_detail.html",
  489. controller: 'MakeOrderDetailCtrl'
  490. }).state('make.change', {
  491. url : "/change",
  492. templateUrl : "static/tpl/index/make/change.html",
  493. controller: 'MakeChangeCtrl'
  494. }).state('make.change_detail', {
  495. url : "/change/:id",
  496. templateUrl : "static/tpl/index/make/change_detail.html",
  497. controller: 'MakeChangeDetailCtrl'
  498. }).state('make.outorder', {
  499. url : "/outorder",
  500. templateUrl : "static/tpl/index/make/outorder.html",
  501. controller: 'MakeOutOrderCtrl'
  502. }).state('make.outorder_detail', {
  503. url : "/outorder/:id",
  504. templateUrl : "static/tpl/index/make/outorder_detail.html",
  505. controller: 'MakeOutOrderDetailCtrl'
  506. }).state('make.accept', {
  507. url : "/accept",
  508. templateUrl : "static/tpl/index/make/accept.html",
  509. controller: 'MakeAcceptCtrl'
  510. }).state('make.returns', {
  511. url : "/returns",
  512. templateUrl : "static/tpl/index/make/returns.html",
  513. controller: 'MakeReturnCtrl'
  514. }).state('cs', {// 客户服务
  515. url : "/cs",
  516. views : {
  517. "left-view" : {
  518. templateUrl : "static/tpl/index/cs/left.html"
  519. },
  520. "right-view" : {
  521. templateUrl : "static/tpl/index/cs/right.html"
  522. }
  523. }
  524. }).state('cs.index', {
  525. url : "",
  526. templateUrl : "static/tpl/index/cs/index.html"
  527. }).state('cs.home', {
  528. url : "/",
  529. templateUrl : "static/tpl/index/cs/index.html"
  530. }).state('search', { //顶部搜索
  531. url: "/search?keyword=",
  532. views : {
  533. "left-view" : {
  534. templateUrl : "static/tpl/index/search/left.html"
  535. },
  536. "right-view" : {
  537. templateUrl: "static/tpl/index/search/search_result.html",
  538. controller: 'TopSearchCtrl'
  539. }
  540. },
  541. }).state('approvalflow', { //审批流
  542. url: "/approvalFlow",
  543. views : {
  544. "left-view" : {
  545. templateUrl : "static/tpl/index/approvalFlow/left.html"
  546. },
  547. "right-view" : {
  548. templateUrl: "static/tpl/index/approvalFlow/home.html",
  549. controller: 'approvalFlowCtrl'
  550. }
  551. },
  552. });
  553. $urlRouterProvider.otherwise('/index');
  554. }]);
  555. /**
  556. * 表示符号
  557. */
  558. app.factory('Symbol', function(){
  559. return {
  560. currency: function(cur) {
  561. if(cur == 'RMB') return '¥';
  562. else if(cur == 'USD') return '$';
  563. else if(cur == 'EUR') return '€';
  564. else if(cur == null || cur == '') return '¥';
  565. else return cur;
  566. }
  567. };
  568. }).factory('Lodop',function(){
  569. return {
  570. getLodop:function(oOBJECT,oEMBED){
  571. var CreatedOKLodop7766=null;
  572. /**************************
  573. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  574. IE系列、IE内核系列的浏览器采用oOBJECT,
  575. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  576. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  577. 64位浏览器指向64位的安装程序install_lodop64.exe。
  578. **************************/
  579. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  580. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  581. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  582. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  583. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  584. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  585. var LODOP;
  586. try{
  587. //=====判断浏览器类型:===============
  588. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  589. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  590. //=====如果页面有Lodop就直接使用,没有则新建:==========
  591. if (oOBJECT!=undefined || oEMBED!=undefined) {
  592. if (isIE)
  593. LODOP=oOBJECT;
  594. else
  595. LODOP=oEMBED;
  596. } else {
  597. if (CreatedOKLodop7766==null){
  598. LODOP=document.createElement("object");
  599. LODOP.setAttribute("width",0);
  600. LODOP.setAttribute("height",0);
  601. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  602. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  603. else LODOP.setAttribute("type","application/x-print-lodop");
  604. document.documentElement.appendChild(LODOP);
  605. CreatedOKLodop7766=LODOP;
  606. } else
  607. LODOP=CreatedOKLodop7766;
  608. };
  609. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  610. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  611. if (navigator.userAgent.indexOf('Chrome')>=0)
  612. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  613. if (navigator.userAgent.indexOf('Firefox')>=0)
  614. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  615. if (is64IE) document.write(strHtm64_Install); else
  616. if (isIE) document.write(strHtmInstall); else
  617. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  618. return LODOP;
  619. } else
  620. if (LODOP.VERSION<"6.1.9.8") {
  621. if (is64IE) document.write(strHtm64_Update); else
  622. if (isIE) document.write(strHtmUpdate); else
  623. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  624. return LODOP;
  625. };
  626. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  627. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  628. //============================================================
  629. return LODOP;
  630. } catch(err) {
  631. if (is64IE)
  632. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  633. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  634. return LODOP;
  635. };
  636. }
  637. }
  638. });
  639. app.controller('MyCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  640. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  641. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  642. if (routeState.indexOf('/') > -1)
  643. routeState = routeState.substring(0, routeState.indexOf('/'));
  644. if (routeState.indexOf('.') > -1)
  645. routeState = routeState.substring(0, routeState.indexOf('.'));
  646. $scope.routeState = routeState || 'home';
  647. });
  648. $scope.search = function(keyword) {
  649. if(keyword != null ) {
  650. $rootScope.searchKeyword = keyword;
  651. window.location.hash = '#/search?keyword='+keyword;
  652. }
  653. };
  654. }]);
  655. // TODO
  656. app.controller('TopSearchCtrl', ['$scope', '$rootScope', 'getAccountUserSpace', 'ngTableParams', 'toaster', 'BaseService', 'AddPartner', '$filter', '$stateParams', 'SearchProd', '$sce', function($scope, $rootScope, getAccountUserSpace, ngTableParams, toaster, BaseService, AddPartner, $filter, $stateParams, SearchProd, $sce) {
  657. $scope.active = 'all';
  658. $scope.tip = $rootScope.searchKeyword;
  659. // 企业搜索
  660. var getService = function() {
  661. return getAccountUserSpace;
  662. };
  663. $scope.tableParams = new ngTableParams({
  664. page : 1,
  665. count : 5,
  666. sorting: {
  667. }
  668. }, {
  669. total : 0,
  670. counts: [5, 10, 25, 50],
  671. getData : function($defer, params) {
  672. $scope.loading = true;
  673. var pageParams = params.url();
  674. pageParams.keyword = $rootScope.searchKeyword;
  675. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  676. $scope.loading = false;
  677. if(page) {
  678. $scope.total = page.totalElement;
  679. params.total(page.totalElement);
  680. $defer.resolve(page.content);
  681. }
  682. }, function(response) {
  683. $scope.loading = false;
  684. toaster.pop('error', '数据加载失败', response.data);
  685. });
  686. }
  687. });
  688. // 添加合作关系
  689. $scope.addPartner = function(name, businessCode) {
  690. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  691. if(data.success) {
  692. toaster.pop("success", '添加成功', data.success);
  693. }
  694. if(data.error) {
  695. toaster.pop("error", '添加失败', data.error);
  696. }
  697. }, function(response) {
  698. toaster.pop('error','失败',response.data);
  699. });
  700. }
  701. // 物料搜索
  702. var getProdService = function() {
  703. return SearchProd;
  704. };
  705. $scope.prodTableParams = new ngTableParams({
  706. page : 1,
  707. count : 5,
  708. sorting: {
  709. }
  710. }, {
  711. total : 0,
  712. counts: [5, 10, 25, 50],
  713. getData : function($defer, params) {
  714. $scope.loading = true;
  715. var pageParams = params.url();
  716. pageParams.keyword = $rootScope.searchKeyword;
  717. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  718. $scope.loading = false;
  719. if(page) {
  720. $scope.prodtotal = page.totalElement;
  721. params.total(page.totalElement);
  722. $defer.resolve(page.content);
  723. }
  724. }, function(response) {
  725. $scope.loading = false;
  726. toaster.pop('error', '数据加载失败', response.data);
  727. });
  728. }
  729. });
  730. /**
  731. * 向企业购买
  732. */
  733. $scope.PurcByEn = function(businessCode) {
  734. $rootScope.businessCode = businessCode;
  735. window.location.hash = "#/purc/addOrder";
  736. }
  737. /**
  738. * 选中单个物料购买
  739. * @param businessCode
  740. * @param id
  741. */
  742. $scope.PurcByEnAndProd = function(businessCode, id) {
  743. $rootScope.businessCode = businessCode;
  744. $rootScope.prodId = id;
  745. window.location.hash = "#/purc/addOrder";
  746. }
  747. }]);
  748. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  749. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  750. //手机号码格式验证
  751. // var checkTel = function(data){
  752. // var userTel = data.userTel;
  753. // $scope.checkResult = false;
  754. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  755. // if(!(telephone).test(userTel)){
  756. // var modalInstance = $modal.open({
  757. // animation: true,
  758. // templateUrl: 'static/tpl/index/account/checkTel.html',
  759. // controller: 'CheckTelCtrl',
  760. // backdrop: 'static',
  761. // keyboard: false,
  762. // resolve: {
  763. // user: function(){
  764. // return data;
  765. // },
  766. // }
  767. // });
  768. // modalInstance.result.then(function(){
  769. // }, function(){
  770. //
  771. // });
  772. // } else {
  773. // $scope.checkResult = true;
  774. // }
  775. // };
  776. AuthenticationService.getAuthentication().success(function(data) {
  777. if(data.enterprises) {
  778. data.enterprise = data.enterprises[data.enterprises.length - 1];
  779. if(data.enterprises.length > 1) {
  780. var enSelect = [];
  781. angular.forEach(data.enterprises, function(e){
  782. if(e.current)
  783. data.enterprise = e;
  784. else
  785. enSelect.push(e);
  786. });
  787. data.enSelect = enSelect;
  788. }
  789. }
  790. $scope.userInfo = data;
  791. if (data == null || !data.userUU) {
  792. $scope.isAuthed = false;
  793. AuthenticationService.redirectSignin();
  794. } else {
  795. //跳转到手机号码验证
  796. // checkTel($scope.userInfo);
  797. }
  798. });
  799. $scope.showImageDialog = function(modal) {
  800. require([ 'jquery-uploadify' ], function() {
  801. $modal.open({
  802. templateUrl : 'static/tpl/index/home/insert.html',
  803. controller : 'ImageInsertCtrl',
  804. backdrop : 'static'
  805. }).result.then(function(image){
  806. $scope.imageUrl = image.thumb;
  807. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  808. $scope.user = data;
  809. }, function(response) {
  810. toaster.pop('error', '设置图像失败,' + response.data);
  811. });
  812. });
  813. });
  814. }
  815. $scope.logout = function() {
  816. AuthenticationService.logout();
  817. };
  818. $scope.switchto = function(enUU) {// 切换企业
  819. AuthenticationService.reSignin(enUU).success(function(){
  820. $window.location.reload();
  821. });
  822. };
  823. $scope.addFavorite = function(){
  824. var url = encodeURI(window.location.href);
  825. try{
  826. //ie浏览器收藏方式
  827. window.external.addFavorite(url, "优软商务平台");
  828. }catch(e) {
  829. try{
  830. //火狐浏览器收藏方式
  831. window.sidebar.addPanel("优软商务平台", url);
  832. }catch (e) {
  833. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  834. "或手动在浏览器里进行设置。");
  835. }
  836. }
  837. };
  838. }]);
  839. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  840. $scope.image = {src: null};
  841. // 图片上传成功之后
  842. $scope.onUploadSuccess = function(data){
  843. var path = data.path;
  844. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  845. $scope.$apply(function(){
  846. $scope.image.src = data.path;
  847. $scope.image.thumb = path;
  848. });
  849. };
  850. $scope.close = function() {
  851. $modalInstance.dismiss();
  852. };
  853. $scope.confirm = function() {
  854. $modalInstance.close($scope.image);
  855. $scope.imageUrl = null;
  856. };
  857. }]);
  858. app.controller('TodoCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  859. SnapshotService.getTodo(function(data){
  860. $scope.todo = data;
  861. });
  862. }]);
  863. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  864. SaleTruck.query({}, function(data){
  865. $rootScope.truck = data;
  866. $scope.truckCount = data ? data.length : 0;
  867. });
  868. $scope.$watch(function(){
  869. return $rootScope.truck;
  870. }, function(data) {
  871. $scope.truckCount = data ? data.length : 0;
  872. }, true);
  873. $scope.clearAll = function() {
  874. SaleTruck.remove({}, function(){
  875. $rootScope.truck = [];
  876. });
  877. };
  878. $scope.openTrack = function() {
  879. $modal.open({
  880. templateUrl: 'static/tpl/index/sale/track.html',
  881. controller: 'TruckModalCtrl',
  882. size: 'lg'
  883. }).result.then(function(s){
  884. if(s) {
  885. $scope.clearAll();
  886. $rootScope.dataChanged = true;
  887. }
  888. });
  889. };
  890. }]);
  891. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  892. $scope.saleSend = {sendItems: []};
  893. SaleTruck.detail({}, function(data){
  894. // 按物料编号排序
  895. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  896. });
  897. $scope.remove = function(index, notice) {
  898. SaleTruck.remove({noticeId: notice.id}, function(data){
  899. $rootScope.truck = data;
  900. $scope.notices.splice(index, 1);
  901. });
  902. };
  903. $scope.$watch(function(){
  904. return $scope.notices;
  905. }, function(data) {
  906. var q = 0, t = 0;
  907. if(data) {
  908. angular.forEach(data,function(d){
  909. q += d.thisSendQty;
  910. t += d.thisSendQty * d.orderItem.price;
  911. });
  912. }
  913. $scope.totalQty = q;
  914. $scope.total = t;
  915. }, true);
  916. $scope.cancel = function() {
  917. $modalInstance.close();
  918. };
  919. $scope.send = function() {// 发货
  920. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  921. toaster.pop('error', '错误', '请输入送货单号');
  922. return;
  923. }
  924. var currency = $scope.notices[0].orderItem.order.currency,
  925. custUU = $scope.notices[0].enUU,
  926. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  927. var num = 1;
  928. for(var i in $scope.notices) {
  929. var item = $scope.notices[i];
  930. if(item.id) {
  931. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  932. valid = false;
  933. break;
  934. }
  935. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  936. }
  937. }
  938. if(!valid) {
  939. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  940. } else {
  941. var send = angular.extend(angular.copy($scope.saleSend), {
  942. currency: currency,
  943. custUU: custUU,
  944. payments: payments,
  945. sendItems: items
  946. });
  947. PurcNotice.sendByBatch({}, send, function(data){
  948. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  949. $modalInstance.close(true);
  950. $state.go('sale.send_detail', {id: data.id});
  951. }, function(response){
  952. toaster.pop('error', '错误', response.data);
  953. });
  954. }
  955. };
  956. }]);
  957. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  958. SaleStat.cust({}, function(data){
  959. var p = [], q = [];
  960. angular.forEach(data.month, function(d){
  961. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  962. });
  963. angular.forEach(data.year, function(d){
  964. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  965. });
  966. $scope.custCharts = {
  967. month : {
  968. chartType : 'pie',
  969. datas : {
  970. data : p
  971. },
  972. config : {
  973. labels : false,
  974. title : "客户月采购量排行榜",
  975. legend : {
  976. display : true,
  977. position : 'right'
  978. },
  979. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  980. click : function(d) {
  981. },
  982. mouseover : function(d) {
  983. },
  984. mouseout : function(d) {
  985. },
  986. innerRadius : 0,
  987. lineLegend : 'lineEnd'
  988. }
  989. },
  990. year : {
  991. chartType : 'pie',
  992. datas : {
  993. data : q
  994. },
  995. config : {
  996. labels : false,
  997. title : "客户年采购量排行榜",
  998. legend : {
  999. display : true,
  1000. position : 'right'
  1001. },
  1002. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1003. click : function(d) {
  1004. },
  1005. mouseover : function(d) {
  1006. },
  1007. mouseout : function(d) {
  1008. },
  1009. innerRadius : 0,
  1010. lineLegend : 'lineEnd'
  1011. }
  1012. }
  1013. };
  1014. });
  1015. SaleStat.seller({}, function(data){
  1016. var p = [], q = [];
  1017. angular.forEach(data.month, function(d){
  1018. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1019. });
  1020. angular.forEach(data.year, function(d){
  1021. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1022. });
  1023. $scope.sellerCharts = {
  1024. month : {
  1025. chartType : 'pie',
  1026. datas : {
  1027. data : p
  1028. },
  1029. config : {
  1030. labels : false,
  1031. title : "业务员月销量排行榜",
  1032. legend : {
  1033. display : true,
  1034. position : 'right'
  1035. },
  1036. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1037. click : function(d) {
  1038. },
  1039. mouseover : function(d) {
  1040. },
  1041. mouseout : function(d) {
  1042. },
  1043. innerRadius : 0,
  1044. lineLegend : 'lineEnd'
  1045. }
  1046. },
  1047. year : {
  1048. chartType : 'pie',
  1049. datas : {
  1050. data : q
  1051. },
  1052. config : {
  1053. labels : false,
  1054. title : "业务员年销量排行榜",
  1055. legend : {
  1056. display : true,
  1057. position : 'right'
  1058. },
  1059. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1060. click : function(d) {
  1061. },
  1062. mouseover : function(d) {
  1063. },
  1064. mouseout : function(d) {
  1065. },
  1066. innerRadius : 0,
  1067. lineLegend : 'lineEnd'
  1068. }
  1069. }
  1070. };
  1071. });
  1072. }]);
  1073. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1074. SaleStat.get({}, function(data){
  1075. var p = [], q = [], r = [];
  1076. angular.forEach(data.day, function(d){
  1077. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1078. });
  1079. angular.forEach(data.month, function(d){
  1080. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1081. });
  1082. angular.forEach(data.year, function(d){
  1083. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1084. });
  1085. $scope.charts = {
  1086. day : {
  1087. chartType : "line",
  1088. datas: {
  1089. series: ['销售额'],
  1090. data: p
  1091. },
  1092. config : {
  1093. "labels": false,
  1094. "title": "销售额统计(近15日线)",
  1095. "legend": {
  1096. "display": true,
  1097. "position": "right"
  1098. },
  1099. colors : [ '#4D9934'],
  1100. "innerRadius": 0,
  1101. "lineLegend": "lineEnd"
  1102. }
  1103. },
  1104. month: {
  1105. chartType : "line",
  1106. datas: {
  1107. series: ['销售额'],
  1108. data: q
  1109. },
  1110. config : {
  1111. "labels": false,
  1112. "title": "销售额统计(近12月线)",
  1113. "legend": {
  1114. "display": true,
  1115. "position": "right"
  1116. },
  1117. colors : [ '#4D9934'],
  1118. "innerRadius": 0,
  1119. "lineLegend": "lineEnd"
  1120. }
  1121. },
  1122. year: {
  1123. chartType : "line",
  1124. datas: {
  1125. series: ['销售额'],
  1126. data: r
  1127. },
  1128. config : {
  1129. "labels": false,
  1130. "title": "销售额统计(近10年线)",
  1131. "legend": {
  1132. "display": true,
  1133. "position": "right"
  1134. },
  1135. colors : [ '#4D9934'],
  1136. "innerRadius": 0,
  1137. "lineLegend": "lineEnd"
  1138. }
  1139. }
  1140. };
  1141. });
  1142. }]);
  1143. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1144. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1145. $scope.notices = data;
  1146. });
  1147. $scope.dateTime = new Date();
  1148. }]);
  1149. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1150. SnapshotService.getTender(5, function(data){ //5表示首页显示的招标单条数
  1151. $scope.tenders = data;
  1152. });
  1153. SnapshotService.getOpenTender(5, function(data){ //5表示首页显示的招标单条数
  1154. $scope.openTenders = data;
  1155. });
  1156. $scope.dateTime = new Date();
  1157. }]);
  1158. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1159. VendorService.getCount(function(date){
  1160. $scope.count = date;
  1161. });
  1162. }]);
  1163. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1164. $scope.userInfoResult = true;
  1165. AuthenticationService.getAuthentication().success(function(data) {
  1166. $scope.loading = false;
  1167. $scope.thisUser = data;
  1168. });
  1169. var getCustInfos = function(custuu) {
  1170. if(custuu) {
  1171. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1172. $scope.custInfos = data;
  1173. var getPage = function(page, size){
  1174. if($scope.custInfos) {
  1175. var result = {};
  1176. result.totalCount = $scope.custInfos.length;
  1177. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1178. if($scope.custInfos.length % size == 0) {
  1179. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1180. }else {
  1181. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1182. }
  1183. result.first = page == 1;
  1184. result.last = page == result.totalPage;
  1185. result.page = page;
  1186. result.next = page - 0 + 1;
  1187. result.pre = page - 1;
  1188. return result;
  1189. }
  1190. }
  1191. $scope.userdata = getPage(1,4);
  1192. $scope.first = function (){
  1193. $scope.userdata = getPage($scope.userdata.pre,4);
  1194. }
  1195. $scope.last = function (){
  1196. $scope.userdata = getPage($scope.userdata.next,4);
  1197. }
  1198. }, function(response){
  1199. $scope.loading = false;
  1200. toaster.pop('error', '数据加载失败', response.data);
  1201. });
  1202. }
  1203. }
  1204. $scope.addUserInfo = function(customer) {
  1205. //TODO
  1206. if ($scope.thisUser.sys) {
  1207. var modalInstance = $modal.open({
  1208. animation: true,
  1209. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1210. controller: 'AddUserInfoCtrl',
  1211. resolve: {
  1212. customer: function() {
  1213. return customer;
  1214. }
  1215. }
  1216. });
  1217. modalInstance.result.then(function(changed, checked){
  1218. if(changed) {
  1219. if(checked)
  1220. $scope.newUser.roles = checked;
  1221. else
  1222. loadUsers();
  1223. }
  1224. });
  1225. } else {
  1226. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1227. }
  1228. }
  1229. $scope.showUserInfo = function(customer,boo) {
  1230. $scope.custInfo = customer;
  1231. if(boo) {
  1232. getCustInfos(customer.myEnterprise.uu);
  1233. $scope.userInfoResult = true;
  1234. }
  1235. }
  1236. $scope.customerParams = new ngTableParams({
  1237. page : 1,
  1238. count : 10
  1239. }, {
  1240. total : 0,
  1241. counts: [5, 10, 25, 50],
  1242. getData : function($defer, params) {
  1243. $scope.loading = true;
  1244. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  1245. $scope.loading = false;
  1246. if(page) {
  1247. params.total(page.totalElements);
  1248. $defer.resolve(page.content);
  1249. }
  1250. $scope.totalCount = page.totalElements;
  1251. }, function(response){
  1252. $scope.loading = false;
  1253. toaster.pop('error', '数据加载失败', response.data);
  1254. });
  1255. }
  1256. });
  1257. }]);
  1258. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1259. $scope.checkboxes = {
  1260. checked : false
  1261. };
  1262. $scope.loading = true;
  1263. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1264. $scope.userinfos = data;
  1265. $scope.loading = false;
  1266. })
  1267. // 点击勾选全部的复选框
  1268. $scope.checkAll = function() {
  1269. angular.forEach($scope.userinfos, function(item) {
  1270. item.distribute = $scope.checkboxes.checked;
  1271. });
  1272. };
  1273. // 点击其中一个明细的复选框
  1274. $scope.checkOne = function(vendor){
  1275. var result = true;
  1276. angular.forEach($scope.userinfos, function(item) {
  1277. if(item.distribute != true){
  1278. result = false;
  1279. return;
  1280. }
  1281. });
  1282. $scope.checkboxes.checked = result;
  1283. };
  1284. $scope.close = function(save) {
  1285. var chooseResult = [];
  1286. if(save) {
  1287. if(customer.myEnterprise.uu) {
  1288. angular.forEach($scope.userinfos, function(item, i) {
  1289. chooseResult.push(item);
  1290. });
  1291. if(chooseResult.length > 0) {
  1292. $scope.loading = true;
  1293. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1294. $scope.loading = false;
  1295. toaster.pop('success', '提示', '保存成功');
  1296. $modalInstance.close(false);
  1297. }, function(response){
  1298. $scope.loading = false;
  1299. toaster.pop('error', '保存失败', response.data);
  1300. $modalInstance.close(false);
  1301. })
  1302. } else {
  1303. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1304. }
  1305. } else {
  1306. $modalInstance.close(true, $scope.checkboxes.checked);
  1307. }
  1308. } else {
  1309. $modalInstance.close(false);
  1310. }
  1311. };
  1312. }]);
  1313. /**
  1314. * 页面状态按钮过滤
  1315. */
  1316. var getState = function(active) {
  1317. var fn = 'get';
  1318. switch(active) {
  1319. case 'done':
  1320. fn = 'getDone';break;
  1321. case 'todo':
  1322. fn = 'getTodo';break;
  1323. case 'end':
  1324. fn = 'getEnd';break;
  1325. case 'waiting':
  1326. fn = 'getWaiting';break;
  1327. case 'invalid':
  1328. fn = 'getInvalid';break;
  1329. }
  1330. return fn;
  1331. };
  1332. /**
  1333. * 改变单据日期范围
  1334. */
  1335. var getDateCondition = function(zone, condition) {
  1336. var date = new Date();
  1337. if(zone == -1) {
  1338. condition.dateFrom = null;
  1339. condition.dateTo = null;
  1340. } else if(zone == 1) {
  1341. date.setMonth(date.getMonth() - 1);
  1342. condition.dateFrom = date;
  1343. condition.dateTo = new Date();
  1344. } else if (zone == 6) {
  1345. date.setMonth(date.getMonth() - 6);
  1346. condition.dateFrom = date;
  1347. condition.dateTo = new Date();
  1348. } else {
  1349. date.setMonth(date.getMonth() - 6);
  1350. condition.dateFrom = null;
  1351. condition.dateTo = date;
  1352. }
  1353. };
  1354. /**
  1355. * 改变单据交货日期范围
  1356. */
  1357. var getDelveryCondition = function(zone, condition) {
  1358. var date = new Date();
  1359. if(zone == -1) {
  1360. condition.deliveryFrom = null;
  1361. condition.deliveryTo = null;
  1362. } else if(zone == 1) {
  1363. date.setMonth(date.getMonth() + 1);
  1364. condition.deliveryTo = date;
  1365. condition.deliveryFrom = new Date();
  1366. } else if (zone == 2) {
  1367. date.setMonth(date.getMonth() + 2);
  1368. condition.deliveryTo = date;
  1369. condition.deliveryFrom = new Date();
  1370. }
  1371. };
  1372. /**
  1373. * 将日期转化为整数日期
  1374. */
  1375. var getDateTime = function(date) {
  1376. if(angular.isDate(date)) {
  1377. return date.getTime();
  1378. } else {
  1379. return null;
  1380. }
  1381. };
  1382. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1383. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1384. $scope.active = 'todo';
  1385. $scope.dateZoneText = '不限';
  1386. $scope.deliveryZoneText = '不限';
  1387. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1388. $scope.changeDateZone = function(zone) {
  1389. $scope.condition.dateZone = zone;
  1390. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1391. $scope.condition.$dateZoneOpen = false;
  1392. getDateCondition(zone, $scope.condition);
  1393. $scope.tableParams.reload();
  1394. };
  1395. $scope.changeDeliveryZone = function(zone) {
  1396. $scope.condition.deliveryZoneText = zone;
  1397. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1398. $scope.condition.$delievryZoneOpen = false;
  1399. getDelveryCondition(zone, $scope.condition);
  1400. $scope.tableParams.reload();
  1401. };
  1402. // 切换单据类型
  1403. $scope.setActive = function(state) {
  1404. if($scope.active != state) {
  1405. $scope.active = state;
  1406. if($scope.tableParams.page() == 1)
  1407. $scope.tableParams.reload();
  1408. else
  1409. $scope.tableParams.page(1);
  1410. }
  1411. };
  1412. var getPurcStatus = function(active) {
  1413. var fn = 'getPurcAll';
  1414. switch(active) {
  1415. case 'done':
  1416. fn = 'getPurcDone';break;
  1417. case 'todo':
  1418. fn = 'getPurcTodo';break;
  1419. case 'end':
  1420. fn = 'getPurcEnd';break;
  1421. case 'waiting':
  1422. fn = 'getPurcWaiting';break;
  1423. }
  1424. return fn;
  1425. }
  1426. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1427. page : 1,
  1428. count : 5,
  1429. sorting: {
  1430. display: 'desc',
  1431. date: 'desc'
  1432. }
  1433. }, {
  1434. total : 0,
  1435. counts: [5, 10, 15, 25, 50],
  1436. getData : function($defer, params) {// 获取数据的方法
  1437. $scope.loading = true;
  1438. var pageParams = params.url();
  1439. pageParams.searchFilter = { // 筛选条件
  1440. keyword: $scope.keyword,
  1441. fromDate: getDateTime($scope.condition.dateFrom),
  1442. endDate: getDateTime($scope.condition.dateTo)
  1443. };
  1444. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1445. $scope.loading = false;
  1446. if(page) {
  1447. $defer.resolve(page.content);
  1448. params.total(page.totalElement);
  1449. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1450. }
  1451. }, function(response){
  1452. $scope.loading = false;
  1453. toaster.pop('error', '数据加载失败', response.data);
  1454. });
  1455. }
  1456. });
  1457. $scope.getReply = function(item) {
  1458. if(!item.replies) {
  1459. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1460. item.replies = replies;
  1461. });
  1462. }
  1463. };
  1464. $scope.getOrderTotal = function(items) {
  1465. var sum = 0;
  1466. angular.forEach(items, function(item){
  1467. sum += item.qty * item.price;
  1468. });
  1469. return sum;
  1470. };
  1471. $scope.openDatePicker = function($event, item, openParam) {
  1472. $event.preventDefault();
  1473. $event.stopPropagation();
  1474. item[openParam] = !item[openParam];
  1475. };
  1476. $scope.parseDate = function(dateStr) {
  1477. if(dateStr)
  1478. return Date.parse(dateStr, 'yyyy-MM-dd');
  1479. return new Date();
  1480. };
  1481. $scope.checkboxes = {
  1482. checked : false
  1483. };
  1484. // 点击勾选全部的复选框
  1485. $scope.checkAll = function(){
  1486. angular.forEach($scope.tableParams.data, function(item) {
  1487. item.$selected = $scope.checkboxes.checked;
  1488. });
  1489. };
  1490. // 点击其中一个明细的复选框
  1491. $scope.checkOne = function(order){
  1492. var result = true;
  1493. angular.forEach($scope.tableParams.data, function(item) {
  1494. if(item.$selected != true){
  1495. result = false;
  1496. return;
  1497. }
  1498. });
  1499. $scope.checkboxes.checked = result;
  1500. };
  1501. // 搜索框回车
  1502. $scope.onSearch = function() {
  1503. $scope.tableParams.page(1);
  1504. $scope.tableParams.reload();
  1505. };
  1506. // 选择查找日期
  1507. $scope.onDateCondition = function(){
  1508. $scope.tableParams.page(1);
  1509. $scope.tableParams.reload();
  1510. };
  1511. }]);
  1512. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1513. var loadData = function() {
  1514. PurcOrder.get({id: $stateParams.id}, function(data){
  1515. $scope.order = data;
  1516. var sum = 0;
  1517. angular.forEach($scope.order.orderItems, function(item){
  1518. sum += item.qty * item.price;
  1519. });
  1520. $scope.order.total = sum;
  1521. if($scope.order.display == 1) {//未查看的设为已查看
  1522. $scope.setDisplay('setRead', $scope.order.id);
  1523. }
  1524. $scope.loading = false;
  1525. });
  1526. };
  1527. loadData();
  1528. $scope.getReply = function(item) {
  1529. if(!item.replies) {
  1530. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1531. item.replies = replies;
  1532. });
  1533. }
  1534. };
  1535. $scope.openDatePicker = function($event, item, openParam) {
  1536. $event.preventDefault();
  1537. $event.stopPropagation();
  1538. item[openParam] = !item[openParam];
  1539. };
  1540. $scope.onReplyClick = function(item, inverse) {
  1541. if(item.reply) {
  1542. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1543. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1544. return;
  1545. }
  1546. var reply = angular.copy(item.reply);
  1547. if(reply.delivery) {
  1548. if(typeof reply.delivery == 'object')
  1549. reply.delivery = reply.delivery.getTime();
  1550. } else {
  1551. reply.delivery = item.delivery;
  1552. }
  1553. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1554. $scope.loading = true;
  1555. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1556. $scope.loading = false;
  1557. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1558. loadData();
  1559. }, function(response){
  1560. $scope.loading = false;
  1561. toaster.pop('error', '回复失败', response.data);
  1562. });
  1563. }
  1564. };
  1565. // // 采购单
  1566. // $scope.print = function(order) {
  1567. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  1568. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1569. // };
  1570. //设置为已查看
  1571. $scope.setDisplay = function(state, orderId) {
  1572. if(orderId) {//设置单个
  1573. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1574. // $scope.tableParams.reload();
  1575. }, function() {
  1576. toaster.pop('error', '错误', "设置失败");
  1577. });
  1578. } else {//设置已勾选的
  1579. var str = null;
  1580. angular.forEach($scope.tableParams.data, function(order) {
  1581. if(order.$selected == true) {
  1582. if(str != null && str != '') str += ',';
  1583. str += order.id;
  1584. }
  1585. });
  1586. if(str != null && str != '') {
  1587. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1588. $scope.tableParams.reload();
  1589. }, function() {
  1590. toaster.pop('error', '错误', "设置失败");
  1591. });
  1592. }
  1593. }
  1594. };
  1595. }]);
  1596. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  1597. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  1598. $scope.active = 'todo';
  1599. $scope.dateZoneText = '不限';
  1600. $scope.deliveryZoneText = '不限';
  1601. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1602. $scope.changeDateZone = function(zone) {
  1603. $scope.condition.dateZone = zone;
  1604. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1605. $scope.condition.$dateZoneOpen = false;
  1606. getDateCondition(zone, $scope.condition);
  1607. $scope.tableParams.reload();
  1608. };
  1609. $scope.changeDeliveryZone = function(zone) {
  1610. $scope.condition.deliveryZoneText = zone;
  1611. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1612. $scope.condition.$delievryZoneOpen = false;
  1613. getDelveryCondition(zone, $scope.condition);
  1614. $scope.tableParams.reload();
  1615. };
  1616. // 切换单据类型
  1617. $scope.setActive = function(state) {
  1618. if($scope.active != state) {
  1619. $scope.active = state;
  1620. if($scope.tableParams.page() == 1)
  1621. $scope.tableParams.reload();
  1622. else
  1623. $scope.tableParams.page(1);
  1624. }
  1625. };
  1626. // 切换数据来源(正常数据 or 历史数据)
  1627. var getService = function() {
  1628. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  1629. };
  1630. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1631. page : 1,
  1632. count : 5,
  1633. sorting: {
  1634. display: 'desc',
  1635. date: 'desc',
  1636. id: 'desc'
  1637. }
  1638. }, {
  1639. total : 0,
  1640. counts: [5, 10, 15, 25, 50],
  1641. getData : function($defer, params) { // 获取数据的方法
  1642. $scope.loading = true;
  1643. var pageParams = params.url();
  1644. pageParams.searchFilter = { // 筛选条件
  1645. keyword: $scope.keyword,
  1646. fromDate: getDateTime($scope.condition.dateFrom),
  1647. endDate: getDateTime($scope.condition.dateTo)
  1648. };
  1649. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1650. $scope.loading = false;
  1651. if(page) {
  1652. $defer.resolve(page.content);
  1653. params.total(page.totalElement);
  1654. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1655. }
  1656. }, function(response){
  1657. $scope.loading = false;
  1658. toaster.pop('error', '数据加载失败', response.data);
  1659. });
  1660. }
  1661. });
  1662. $scope.getOrderTotal = function(items) {
  1663. var sum = 0;
  1664. angular.forEach(items, function(item){
  1665. sum += item.qty * item.price;
  1666. });
  1667. return sum;
  1668. };
  1669. $scope.openDatePicker = function($event, item, openParam) {
  1670. $event.preventDefault();
  1671. $event.stopPropagation();
  1672. item[openParam] = !item[openParam];
  1673. };
  1674. $scope.parseDate = function(dateStr) {
  1675. if(dateStr)
  1676. return Date.parse(dateStr, 'yyyy-MM-dd');
  1677. return new Date();
  1678. };
  1679. $scope.onReplyClick = function(item, inverse) {
  1680. if(item.reply) {
  1681. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1682. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1683. return;
  1684. }
  1685. var reply = angular.copy(item.reply);
  1686. if(reply.delivery) {
  1687. if(typeof reply.delivery == 'object')
  1688. reply.delivery = reply.delivery.getTime();
  1689. } else {
  1690. reply.delivery = item.delivery;
  1691. }
  1692. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1693. $scope.loading = true;
  1694. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1695. $scope.loading = false;
  1696. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1697. $scope.tableParams.reload();
  1698. }, function(response){
  1699. $scope.loading = false;
  1700. toaster.pop('error', '回复失败', response.data);
  1701. });
  1702. }
  1703. };
  1704. //打印 采购单
  1705. $scope.print = function(order) {
  1706. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  1707. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  1708. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1709. };
  1710. $scope.getReply = function(item) {
  1711. if(!item.replies) {
  1712. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1713. item.replies = replies;
  1714. });
  1715. }
  1716. };
  1717. $scope.checkboxes = {
  1718. checked : false
  1719. };
  1720. // 点击勾选全部的复选框
  1721. $scope.checkAll = function(){
  1722. angular.forEach($scope.tableParams.data, function(item) {
  1723. item.$selected = $scope.checkboxes.checked;
  1724. });
  1725. };
  1726. // 点击其中一个明细的复选框
  1727. $scope.checkOne = function(order){
  1728. var result = true;
  1729. angular.forEach($scope.tableParams.data, function(item) {
  1730. if(item.$selected != true){
  1731. result = false;
  1732. return;
  1733. }
  1734. });
  1735. $scope.checkboxes.checked = result;
  1736. };
  1737. //批量回复采购订单
  1738. $scope.replyByBatch = function() {
  1739. $scope.loading = true;
  1740. var str = '';
  1741. angular.forEach($scope.tableParams.data, function(order) {
  1742. if(order.$selected == true) {
  1743. angular.forEach(order.orderItems, function(item){
  1744. str += item.id;
  1745. str += ',';
  1746. });
  1747. }
  1748. });
  1749. if(!(str == '')) {
  1750. str = str.substr(0, str.length-1);
  1751. PurcOrderItem.replyByBatch(str, function(){
  1752. $scope.loading = false;
  1753. $scope.tableParams.reload();
  1754. toaster.pop('success', '提示', '批量回复成功');
  1755. }, function(data){
  1756. $scope.loading = false;
  1757. toaster.pop('error', '批量回复失败', data);
  1758. });
  1759. } else {//没有勾选其中的明细
  1760. $scope.loading = false;
  1761. }
  1762. };
  1763. // 搜索框回车
  1764. $scope.onSearch = function() {
  1765. $scope.tableParams.page(1);
  1766. $scope.tableParams.reload();
  1767. };
  1768. // 选择查找日期
  1769. $scope.onDateCondition = function(){
  1770. $scope.tableParams.page(1);
  1771. $scope.tableParams.reload();
  1772. };
  1773. //设置为已查看
  1774. $scope.setDisplay = function(state, orderId) {
  1775. if(orderId) {//设置单个
  1776. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1777. $scope.tableParams.reload();
  1778. }, function() {
  1779. toaster.pop('error', '错误', "设置失败");
  1780. });
  1781. } else {//设置已勾选的
  1782. var str = null;
  1783. angular.forEach($scope.tableParams.data, function(order) {
  1784. if(order.$selected == true) {
  1785. if(str != null && str != '') str += ',';
  1786. str += order.id;
  1787. }
  1788. });
  1789. if(str != null && str != '') {
  1790. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1791. $scope.tableParams.reload();
  1792. }, function() {
  1793. toaster.pop('error', '错误', "设置失败");
  1794. });
  1795. }
  1796. }
  1797. };
  1798. }]);
  1799. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1800. var loadData = function() {
  1801. PurcOrder.get({id: $stateParams.id}, function(data){
  1802. $scope.order = data;
  1803. var sum = 0;
  1804. angular.forEach($scope.order.orderItems, function(item){
  1805. sum += item.qty * item.price;
  1806. });
  1807. $scope.order.total = sum;
  1808. if($scope.order.display == 1) {//未查看的设为已查看
  1809. $scope.setDisplay('setRead', $scope.order.id);
  1810. }
  1811. $scope.loading = false;
  1812. });
  1813. };
  1814. loadData();
  1815. $scope.getReply = function(item) {
  1816. if(!item.replies) {
  1817. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1818. item.replies = replies;
  1819. });
  1820. }
  1821. };
  1822. $scope.openDatePicker = function($event, item, openParam) {
  1823. $event.preventDefault();
  1824. $event.stopPropagation();
  1825. item[openParam] = !item[openParam];
  1826. };
  1827. $scope.onReplyClick = function(item, inverse) {
  1828. if(item.reply) {
  1829. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1830. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1831. return;
  1832. }
  1833. var reply = angular.copy(item.reply);
  1834. if(reply.delivery) {
  1835. if(typeof reply.delivery == 'object')
  1836. reply.delivery = reply.delivery.getTime();
  1837. } else {
  1838. reply.delivery = item.delivery;
  1839. }
  1840. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1841. $scope.loading = true;
  1842. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1843. $scope.loading = false;
  1844. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1845. loadData();
  1846. }, function(response){
  1847. $scope.loading = false;
  1848. toaster.pop('error', '回复失败', response.data);
  1849. });
  1850. }
  1851. };
  1852. // 采购单
  1853. $scope.print = function(order) {
  1854. PurcOrder.printCount({id: order.id},{});//增加打印此次
  1855. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1856. };
  1857. //设置为已查看
  1858. $scope.setDisplay = function(state, orderId) {
  1859. if(orderId) {//设置单个
  1860. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1861. $scope.tableParams.reload();
  1862. }, function() {
  1863. toaster.pop('error', '错误', "设置失败");
  1864. });
  1865. } else {//设置已勾选的
  1866. var str = null;
  1867. angular.forEach($scope.tableParams.data, function(order) {
  1868. if(order.$selected == true) {
  1869. if(str != null && str != '') str += ',';
  1870. str += order.id;
  1871. }
  1872. });
  1873. if(str != null && str != '') {
  1874. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1875. $scope.tableParams.reload();
  1876. }, function() {
  1877. toaster.pop('error', '错误', "设置失败");
  1878. });
  1879. }
  1880. }
  1881. };
  1882. }]);
  1883. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  1884. $scope.active = 'todo';
  1885. $scope.agreedText = '全部';
  1886. $scope.dateZoneText = '一个月内';
  1887. $scope.condition = {dateZone: 1};
  1888. $scope.changeAgreed = function(agreed) {
  1889. $scope.condition.agreed = agreed;
  1890. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  1891. $scope.condition.$agreedOpen = false;
  1892. };
  1893. $scope.changeDateZone = function(zone) {
  1894. $scope.condition.dateZone = zone;
  1895. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1896. $scope.condition.$dateZoneOpen = false;
  1897. };
  1898. $scope.setActive = function(state) {
  1899. if($scope.active != state) {
  1900. $scope.active = state;
  1901. if($scope.tableParams.page() == 1)
  1902. $scope.tableParams.reload();
  1903. else
  1904. $scope.tableParams.page(1);
  1905. }
  1906. };
  1907. var getService = function() {
  1908. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  1909. };
  1910. $scope.tableParams = new ngTableParams({
  1911. page : 1,
  1912. count : 5,
  1913. sorting: {
  1914. date: 'desc'
  1915. }
  1916. }, {
  1917. total : 0,
  1918. counts: [5, 10, 25, 50],
  1919. getData : function($defer, params) {
  1920. $scope.loading = true;
  1921. var pageParams = params.url();
  1922. pageParams.keyword = $scope.keyword;
  1923. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1924. $scope.loading = false;
  1925. if(page) {
  1926. params.total(page.totalElement);
  1927. $defer.resolve(page.content);
  1928. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1929. }
  1930. }, function(response){
  1931. $scope.loading = false;
  1932. toaster.pop('error', '数据加载失败', response.data);
  1933. });
  1934. }
  1935. });
  1936. $scope.openDatePicker = function($event, item, openParam) {
  1937. $event.preventDefault();
  1938. $event.stopPropagation();
  1939. item[openParam] = !item[openParam];
  1940. };
  1941. $scope.onReplyClick = function(change) {
  1942. if(change.$agreed) {
  1943. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1944. $scope.loading = true;
  1945. PurcChange.reply({changeId: change.id}, reply, function(){
  1946. $scope.loading = false;
  1947. toaster.pop('info', '提示', '回复成功');
  1948. $scope.tableParams.reload();
  1949. }, function(response){
  1950. $scope.loading = false;
  1951. toaster.pop('error', '回复失败', response.data);
  1952. });
  1953. }
  1954. };
  1955. // 搜索框回车
  1956. $scope.onSearch = function() {
  1957. $scope.tableParams.page(1);
  1958. $scope.tableParams.reload();
  1959. };
  1960. }]);
  1961. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  1962. var loadData = function() {
  1963. PurcChange.get({id: $stateParams.id}, function(data){
  1964. $scope.change = data;
  1965. });
  1966. };
  1967. loadData();
  1968. $scope.openDatePicker = function($event, item, openParam) {
  1969. $event.preventDefault();
  1970. $event.stopPropagation();
  1971. item[openParam] = !item[openParam];
  1972. };
  1973. $scope.onReplyClick = function(change) {
  1974. if(change.$agreed) {
  1975. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1976. PurcChange.reply({changeId: change.id}, reply, function(){
  1977. toaster.pop('info', '提示', '回复成功');
  1978. loadData();
  1979. }, function(response){
  1980. toaster.pop('error', '回复失败', response.data);
  1981. });
  1982. }
  1983. };
  1984. }]);
  1985. //采购询价
  1986. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  1987. $scope.active = 'todo';
  1988. $scope.agreedText = '全部';
  1989. $scope.dateZoneText = '一个月内';
  1990. $scope.condition = {dateZone: 1};
  1991. $scope.changeAgreed = function(agreed) {
  1992. $scope.condition.agreed = agreed;
  1993. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  1994. $scope.condition.$agreedOpen = false;
  1995. };
  1996. $scope.changeDateZone = function(zone) {
  1997. $scope.condition.dateZone = zone;
  1998. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1999. $scope.condition.$dateZoneOpen = false;
  2000. };
  2001. $scope.setActive = function(state) {
  2002. if($scope.active != state) {
  2003. $scope.active = state;
  2004. if($scope.tableParams.page() == 1)
  2005. $scope.tableParams.reload();
  2006. else
  2007. $scope.tableParams.page(1);
  2008. }
  2009. };
  2010. var getService = function() {
  2011. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2012. };
  2013. $scope.tableParams = new ngTableParams({
  2014. page : 1,
  2015. count : 5,
  2016. sorting: {
  2017. 'inquiry.date': 'desc',
  2018. 'inquiry.enterprise.enName': 'asc',
  2019. 'inquiry.code': 'asc'
  2020. }
  2021. }, {
  2022. total : 0,
  2023. counts: [5, 10, 25, 50],
  2024. getData : function($defer, params) {
  2025. $scope.loading = true;
  2026. var pageParams = params.url();
  2027. var realActive = {};
  2028. pageParams.keyword = $scope.keyword;
  2029. if ($scope.active == 'overdue') {
  2030. $scope.active = 'end';
  2031. }
  2032. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2033. $scope.loading = false;
  2034. if(page) {
  2035. params.total(page.totalElement);
  2036. $defer.resolve(page.content);
  2037. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2038. }
  2039. }, function(response){
  2040. $scope.loading = false;
  2041. toaster.pop('error', '数据加载失败', response.data);
  2042. });
  2043. }
  2044. });
  2045. $scope.getMinDate = function(item) {
  2046. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2047. };
  2048. $scope.replyPrices = [];
  2049. $scope.replylapQtys = [];
  2050. $scope.replyPrices.push(true);
  2051. $scope.replylapQtys.push(true);
  2052. $scope.addStep = function(inquiryItem) {
  2053. $scope.replyPrices.push(true);
  2054. if(inquiryItem.replies.length >= 10) {
  2055. toaster.pop('warning', '提示', '最多支持10个分段!');
  2056. } else {
  2057. inquiryItem.replies.push({});
  2058. if(inquiryItem.replies.length != 1) {
  2059. $scope.replyPrices.push(true);
  2060. $scope.replylapQtys.push(true);
  2061. }
  2062. }
  2063. };
  2064. $scope.removeStep = function(inquiryItem, stepIndex) {
  2065. inquiryItem.replies.splice(stepIndex, 1);
  2066. $scope.replyPrices.splice(stepIndex, 1);
  2067. $scope.replylapQtys.splice(stepIndex, 1);
  2068. };
  2069. $scope.openDatePicker = function($event, item, openParam) {
  2070. $event.preventDefault();
  2071. $event.stopPropagation();
  2072. item[openParam] = !item[openParam];
  2073. };
  2074. $scope.getHistory = function(item) {
  2075. if(!item.history) {
  2076. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2077. item.history = data;
  2078. });
  2079. }
  2080. };
  2081. $scope.isValid = function(item, withSteps) {
  2082. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2083. if(!withSteps || !bool)
  2084. return bool;
  2085. angular.forEach(item.replies, function(r, i){
  2086. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2087. });
  2088. return bool;
  2089. };
  2090. $scope.onReplyClick = function(item, withSteps) {
  2091. if(item.vendFromDate instanceof Date) {
  2092. item.vendFromDate = item.vendFromDate.getTime();
  2093. }
  2094. if(item.vendToDate instanceof Date) {
  2095. item.vendToDate = item.vendToDate.getTime();
  2096. }
  2097. if(item.vendFromDate > item.vendToDate) {
  2098. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2099. return;
  2100. }
  2101. var replies = [];
  2102. angular.forEach(item.replies, function(r, i){
  2103. if((i > 0 ? r.lapQty : 1) || r.price)
  2104. replies.push(r);
  2105. });
  2106. item.replies = replies;
  2107. $scope.loading = true;
  2108. if(withSteps) {
  2109. PurcInquiry.reply({itemId: item.id}, item, function(){
  2110. $scope.loading = false;
  2111. toaster.pop('info', '提示', '报价成功');
  2112. $scope.tableParams.reload();
  2113. }, function(response){
  2114. $scope.loading = false;
  2115. toaster.pop('error', '报价失败', response.data);
  2116. });
  2117. } else {
  2118. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2119. $scope.loading = false;
  2120. toaster.pop('info', '提示', '保存成功');
  2121. $scope.tableParams.reload();
  2122. }, function(response){
  2123. $scope.loading = false;
  2124. toaster.pop('error', '保存失败', response.data);
  2125. });
  2126. }
  2127. };
  2128. $scope.verifylapQty = function(value,type) {
  2129. var regex = /^\d+(.\d{1,5})?$/;
  2130. $scope.replylapQtys[type] = regex.test(value);
  2131. }
  2132. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2133. $scope.verify = function(value,type) {
  2134. var regex = /^\d+(.\d{1,5})?$/;//
  2135. switch(type) {
  2136. case 'minOrderQty':
  2137. $scope.minOrderQtyVerify = regex.test(value);
  2138. break;
  2139. case 'minPackQty':
  2140. $scope.minPackQtyVerify = regex.test(value);
  2141. break;
  2142. case 'leadtime':
  2143. $scope.leadtimeVerify = regex.test(value);
  2144. break;
  2145. default:
  2146. $scope.replyPrices[type] = regex.test(value);
  2147. break;
  2148. }
  2149. }
  2150. // 搜索框回车
  2151. $scope.onSearch = function() {
  2152. $scope.tableParams.page(1);
  2153. $scope.tableParams.reload();
  2154. };
  2155. }]);
  2156. // 询价单明细
  2157. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2158. var loadData = function() {
  2159. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2160. $scope.newinquiryItems = data;
  2161. var inquiry = data[0].inquiry;
  2162. //inquiry.inquiryItems = data;
  2163. angular.forEach(inquiry.attachs, function(attach){
  2164. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2165. });
  2166. $scope.inquiry = inquiry;
  2167. });
  2168. };
  2169. loadData();
  2170. $scope.getMinDate = function(item) {
  2171. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2172. };
  2173. $scope.addStep = function(inquiryItem) {
  2174. if(inquiryItem.replies.length >= 10) {
  2175. toaster.pop('warning', '提示', '最多支持10个分段!');
  2176. } else
  2177. inquiryItem.replies.push({});
  2178. };
  2179. $scope.removeStep = function(inquiryItem, stepIndex) {
  2180. inquiryItem.replies.splice(stepIndex, 1);
  2181. };
  2182. $scope.openDatePicker = function($event, item, openParam) {
  2183. $event.preventDefault();
  2184. $event.stopPropagation();
  2185. item[openParam] = !item[openParam];
  2186. };
  2187. $scope.getHistory = function(item) {
  2188. if(!item.history) {
  2189. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2190. item.history = data;
  2191. });
  2192. }
  2193. };
  2194. $scope.isValid = function(item, withSteps) {
  2195. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2196. if(!withSteps || !bool)
  2197. return bool;
  2198. angular.forEach(item.replies, function(r, i){
  2199. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2200. });
  2201. return bool;
  2202. };
  2203. $scope.onReplyClick = function(item, withSteps) {
  2204. if(item.vendFromDate instanceof Date) {
  2205. item.vendFromDate = item.vendFromDate.getTime();
  2206. }
  2207. if(item.vendToDate instanceof Date) {
  2208. item.vendToDate = item.vendToDate.getTime();
  2209. }
  2210. if(item.vendFromDate > item.vendToDate) {
  2211. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2212. return;
  2213. }
  2214. var replies = [];
  2215. angular.forEach(item.replies, function(r, i){
  2216. if((i > 0 ? r.lapQty : 1) || r.price)
  2217. replies.push(r);
  2218. });
  2219. item.replies = replies;
  2220. if(withSteps) {
  2221. PurcInquiry.reply({itemId: item.id}, item, function(){
  2222. toaster.pop('info', '提示', '报价成功');
  2223. loadData();
  2224. }, function(response){
  2225. toaster.pop('error', '报价失败', response.data);
  2226. });
  2227. }
  2228. };
  2229. }]);
  2230. // 模具询价管理
  2231. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  2232. $scope.active = 'todo';
  2233. $scope.agreedText = '全部';
  2234. $scope.dateZoneText = '一个月内';
  2235. $scope.condition = {dateZone: 1};
  2236. var inquiryMould_copy = {};
  2237. $scope.changeAgreed = function(agreed) {
  2238. $scope.condition.agreed = agreed;
  2239. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2240. $scope.condition.$agreedOpen = false;
  2241. };
  2242. $scope.changeDateZone = function(zone) {
  2243. $scope.condition.dateZone = zone;
  2244. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2245. $scope.condition.$dateZoneOpen = false;
  2246. };
  2247. $scope.setActive = function(state) {
  2248. if($scope.active != state ) {
  2249. $scope.active = state;
  2250. if ($scope.tableParams.page() == 1) {
  2251. $scope.tableParams.reload();
  2252. } else {
  2253. $scope.tableParams.page(1);
  2254. }
  2255. }
  2256. }
  2257. var getService = function() {
  2258. return PurcInquiryMould;
  2259. };
  2260. $scope.tableParams = new ngTableParams({
  2261. page: 1,
  2262. count: 5
  2263. },{
  2264. total: 0,
  2265. counts: [5, 10, 25, 50],
  2266. getData: function($defer, params) {
  2267. $scope.loading = true;
  2268. var pageParams = params.url();
  2269. var realActive = {};
  2270. pageParams.keyword = $scope.keyword;
  2271. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2272. $scope.loading = false;
  2273. // 用来验证价格修改
  2274. var mould = page.content;
  2275. inquiryMould_copy = angular.copy(mould);
  2276. if(page) {
  2277. params.total(page.totalElement);
  2278. $defer.resolve(page.content);
  2279. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2280. }
  2281. }, function(response){
  2282. $scope.loading = false;
  2283. toaster.pop('error', '数据加载失败', response.data);
  2284. });
  2285. }
  2286. })
  2287. $scope.getMinDate = function(item) {
  2288. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  2289. };
  2290. $scope.replyPrices = [];
  2291. $scope.replyPrices.push(true);
  2292. // 取消
  2293. $scope.reload = function() {
  2294. $scope.tableParams.reload();
  2295. $scope.canSave = false;
  2296. }
  2297. // 能否保存设置
  2298. $scope.canSave = false;
  2299. // items价格验证
  2300. $scope.verifyItems = function(price, reply) {
  2301. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  2302. if(regex.test(price) && price != 0) {
  2303. if (price != reply) {
  2304. $scope.canSave = true;
  2305. } else {
  2306. $scope.canSave = false;
  2307. }
  2308. } else {
  2309. $scope.canSave = false;
  2310. }
  2311. }
  2312. // prod下prods价格验证
  2313. $scope.verifyProds = function(price, reply) {
  2314. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2315. if(regex.test(price) && price != 0) {
  2316. if (price != reply) {
  2317. $scope.canSave = true;
  2318. } else {
  2319. $scope.canSave = false;
  2320. }
  2321. } else {
  2322. $scope.canSave = false;
  2323. }
  2324. }
  2325. //有价格为0或者不符合正则式,则不能报价
  2326. $scope.notZero = function (mould) {
  2327. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2328. angular.forEach(mould.inquiryMouldItems, function(item){
  2329. if (item.price == 0 || !regex.test(item.price)) {
  2330. $scope.canSave = false;
  2331. }
  2332. angular.forEach(item.inquiryMouldDetails, function(detail){
  2333. if (detail.price == 0 || !regex.test(detail.price)) {
  2334. $scope.canSave = false;
  2335. }
  2336. })
  2337. });
  2338. }
  2339. $scope.blurPrice = function (price) {
  2340. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2341. if (!regex.test(price)) {
  2342. toaster.pop('warning','格式错误','请输入有效价格');
  2343. }
  2344. }
  2345. // 获取历史报价
  2346. $scope.getHistory = function(mould) {
  2347. if(!mould.history) {
  2348. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  2349. mould.history = data;
  2350. console.log(mould.history);
  2351. });
  2352. }
  2353. };
  2354. $scope.uploadAttach = function(mould) {
  2355. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2356. var file = mould.attachs[0];
  2357. $scope.mould = mould;
  2358. $upload.upload({
  2359. url: 'sale/mould/' + mould.id + '/send',
  2360. method: 'POST',
  2361. file: file,
  2362. data: {
  2363. json: $scope.mould
  2364. }
  2365. }).success(function(res){
  2366. console.log("success");
  2367. console.log(res);
  2368. }).error(function(res){
  2369. console.log("failure");
  2370. console.log(res);
  2371. });
  2372. }
  2373. // 保存并确认报价
  2374. $scope.onReplyClick = function(mould, withSteps) {
  2375. $scope.loading = true;
  2376. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2377. // var file = mould.attachs[0];
  2378. // $scope.mould = mould;
  2379. // $upload.upload({
  2380. // url: 'sale/mould/' + mould.id + '/send',
  2381. // method: 'POST',
  2382. // file: file,
  2383. // data: {
  2384. // json: $scope.mould
  2385. // }
  2386. // }).success(function(res){
  2387. // console.log("success");
  2388. // console.log(res);
  2389. // }).error(function(res){
  2390. // console.log("failure");
  2391. // });
  2392. if(withSteps) {
  2393. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  2394. $scope.loading = false;
  2395. toaster.pop('info', '提示', '报价成功');
  2396. $scope.tableParams.reload();
  2397. $scope.canSave = false;
  2398. }, function(response){
  2399. $scope.loading = false;
  2400. toaster.pop('error', '报价失败', response.data);
  2401. });
  2402. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  2403. }, function(response){
  2404. });
  2405. } else {
  2406. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  2407. $scope.loading = false;
  2408. toaster.pop('info', '提示', '保存成功');
  2409. $scope.tableParams.reload();
  2410. }, function(response){
  2411. $scope.loading = false;
  2412. toaster.pop('error', '保存失败', response.data);
  2413. });
  2414. }
  2415. };
  2416. // 搜索框回车
  2417. $scope.onSearch = function() {
  2418. $scope.tableParams.page(1);
  2419. $scope.tableParams.reload();
  2420. };
  2421. }]);
  2422. // 模具询价单明细
  2423. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  2424. var inquiryMould_copy = {};
  2425. var loadData = function() {
  2426. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  2427. // 用来验证价格修改
  2428. inquiryMould_copy = angular.copy(data);
  2429. $scope.inquiryMould_copy = inquiryMould_copy;
  2430. $scope.newinquirymould = data;
  2431. var mould = data;
  2432. angular.forEach(mould.attachs, function(attach){
  2433. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2434. });
  2435. $scope.inquiryMould = mould;
  2436. });
  2437. };
  2438. loadData();
  2439. $scope.getMinDate = function(item) {
  2440. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2441. };
  2442. // 取消
  2443. $scope.reload = function() {
  2444. loadData();
  2445. $scope.canSave = false;
  2446. }
  2447. //有价格为0,则不能报价
  2448. $scope.notZero = function (mould) {
  2449. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2450. angular.forEach(mould.inquiryMouldItems, function(item){
  2451. if (item.price == 0 || !regex.test(item.price)) {
  2452. $scope.canSave = false;
  2453. }
  2454. angular.forEach(item.inquiryMouldDetails, function(detail){
  2455. if (detail.price == 0 || !regex.test(detail.price)) {
  2456. $scope.canSave = false;
  2457. }
  2458. })
  2459. });
  2460. }
  2461. $scope.blurPrice = function (price) {
  2462. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2463. if (!regex.test(price)) {
  2464. toaster.pop('warning','格式错误','请输入有效价格');
  2465. }
  2466. }
  2467. // 获取历史报价
  2468. $scope.getHistory = function(mould) {
  2469. if(!mould.history) {
  2470. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  2471. mould.history = data;
  2472. console.log(mould.history);
  2473. });
  2474. }
  2475. };
  2476. $scope.canSave = false;
  2477. // items价格验证
  2478. $scope.verifyItems = function(price, index) {
  2479. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2480. if(regex.test(price) && price != 0) {
  2481. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  2482. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  2483. $scope.canSave = true;
  2484. } else {
  2485. $scope.canSave = false;
  2486. }
  2487. } else {
  2488. $scope.canSave = false;
  2489. }
  2490. }
  2491. // prod下prods价格验证
  2492. $scope.verifyProds = function(price, index, parentIndex) {
  2493. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2494. if(regex.test(price) && price != 0) {
  2495. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  2496. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  2497. $scope.canSave = true;
  2498. } else {
  2499. $scope.canSave = false;
  2500. }
  2501. } else {
  2502. $scope.canSave = false;
  2503. }
  2504. }
  2505. // // 上传附件
  2506. // $scope.uploadAttach = function(mould) {
  2507. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2508. // var file = mould.attachs[0];
  2509. // $scope.mould = mould;
  2510. // $upload.upload({
  2511. // url: 'sale/mould/' + mould.id + '/send',
  2512. // method: 'POST',
  2513. // file: file,
  2514. // data: {
  2515. // json: $scope.mould
  2516. // }
  2517. // }).success(function(res){
  2518. // console.log("success");
  2519. // console.log(res);
  2520. // }).error(function(res){
  2521. // console.log("failure");
  2522. // console.log(res);
  2523. // });
  2524. // }
  2525. $scope.onReplyClick = function(mould, withSteps) {
  2526. $scope.loading = true;
  2527. // var file = mould.attachs[0];
  2528. // $scope.mould = mould;
  2529. // $upload.upload({
  2530. // url: 'sale/mould/' + mould.id + '/send',
  2531. // method: 'POST',
  2532. // file: file,
  2533. // data: {
  2534. // json: $scope.mould
  2535. // }
  2536. // }).success(function(res){
  2537. //
  2538. // }).error(function(res){
  2539. // console.log(res);
  2540. // });
  2541. if(withSteps) {
  2542. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  2543. $scope.loading = false;
  2544. toaster.pop('info', '提示', '报价成功');
  2545. loadData();
  2546. $scope.canSave = false;
  2547. }, function(response){
  2548. $scope.loading = false;
  2549. toaster.pop('error', '报价失败', response.data);
  2550. });
  2551. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  2552. }, function(response){
  2553. });
  2554. } else {
  2555. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  2556. $scope.loading = false;
  2557. toaster.pop('info', '提示', '保存成功');
  2558. loadData();
  2559. }, function(response){
  2560. $scope.loading = false;
  2561. toaster.pop('error', '保存失败', response.data);
  2562. });
  2563. }
  2564. };
  2565. }]);
  2566. // 主动报价 - 列表
  2567. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  2568. $scope.active = 'todo';
  2569. $scope.agreedText = '全部';
  2570. $scope.dateZoneText = '一个月内';
  2571. $scope.condition = {dateZone: 1};
  2572. $scope.changeDateZone = function(zone) {
  2573. $scope.condition.dateZone = zone;
  2574. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2575. $scope.condition.$dateZoneOpen = false;
  2576. };
  2577. $scope.setActive = function(state) {
  2578. if($scope.active != state) {
  2579. $scope.active = state;
  2580. if($scope.tableParams.page() == 1)
  2581. $scope.tableParams.reload();
  2582. else
  2583. $scope.tableParams.page(1);
  2584. }
  2585. };
  2586. var getService = function() {
  2587. return Quotation;
  2588. };
  2589. $scope.tableParams = new ngTableParams({
  2590. page : 1,
  2591. count : 5,
  2592. sorting: {
  2593. 'quotation.date': 'desc'
  2594. }
  2595. }, {
  2596. total : 0,
  2597. counts: [5, 10, 25, 50],
  2598. getData : function($defer, params) {
  2599. $scope.loading = true;
  2600. var pageParams = params.url();
  2601. pageParams.keyword = $scope.keyword;
  2602. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2603. $scope.loading = false;
  2604. if(page) {
  2605. params.total(page.totalElement);
  2606. $defer.resolve(page.content);
  2607. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2608. }
  2609. }, function(response){
  2610. $scope.loading = false;
  2611. toaster.pop('error', '数据加载失败', response.data);
  2612. });
  2613. }
  2614. });
  2615. $scope.getHistory = function(item) {
  2616. if(!item.history) {
  2617. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2618. item.history = data;
  2619. });
  2620. }
  2621. };
  2622. $scope.isValid = function(item, withSteps) {
  2623. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2624. if(!withSteps || !bool)
  2625. return bool;
  2626. angular.forEach(item.replies, function(r, i){
  2627. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2628. });
  2629. return bool;
  2630. };
  2631. // 搜索框回车
  2632. $scope.onSearch = function() {
  2633. $scope.tableParams.page(1);
  2634. $scope.tableParams.reload();
  2635. };
  2636. }]);
  2637. // Controller 主动报价 - 新增
  2638. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
  2639. var staticItem = null;
  2640. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  2641. $scope.loading = true;
  2642. Quotation.getItem({id: $stateParams.id}, function(data){
  2643. data.$editing = false;
  2644. $scope.item = data;
  2645. staticItem = angular.copy(data);
  2646. $scope.loading = false;
  2647. }, function(response){
  2648. $scope.loading = false;
  2649. toaster.pop('error', '数据加载失败', response.data);
  2650. });
  2651. } else {// 新增模式
  2652. $scope.item = {
  2653. quotation: {
  2654. currency: 'RMB',
  2655. taxrate: 17,
  2656. date: new Date()
  2657. },
  2658. product: {},
  2659. prices: [{lapQty: 0}],
  2660. minOrderQty: 1,
  2661. minPackQty: 1,
  2662. $endDateOpen: false,
  2663. $editing: true
  2664. };
  2665. }
  2666. $scope.getMinDate = function(item) {
  2667. return $filter('date')(new Date, 'yyyy-MM-dd');
  2668. };
  2669. $scope.openDatePicker = function($event, openParam) {
  2670. $event.preventDefault();
  2671. $event.stopPropagation();
  2672. $scope.item.$endDateOpen = !openParam;
  2673. };
  2674. // 增加一个分段
  2675. $scope.addPrice = function(){
  2676. if($scope.item.prices.length >= 10) {
  2677. toaster.pop('warning', '提示', '最多支持10个分段!');
  2678. } else
  2679. $scope.item.prices.push({});
  2680. };
  2681. // 删除一个分段
  2682. $scope.removePrice = function(index) {
  2683. $scope.item.prices.splice(index, 1);
  2684. };
  2685. // 查找客户
  2686. $scope.dbfindCust = function(){
  2687. if($scope.item.$editing) {
  2688. var modalInstance = $modal.open({
  2689. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  2690. controller: 'DbfindCustCtrl',
  2691. size: 'lg',
  2692. resolve: {
  2693. }
  2694. });
  2695. modalInstance.result.then(function(data){
  2696. $scope.item.quotation.cust = data.myEnterprise;
  2697. $scope.item.quotation.custUser = data.myUser;
  2698. $scope.item.product = null;
  2699. }, function(){
  2700. });
  2701. }
  2702. };
  2703. // 查找客户物料
  2704. $scope.dbfindCustProd = function(){
  2705. if($scope.item.$editing) {
  2706. if($scope.item.quotation.cust.uu) {
  2707. var modalInstance = $modal.open({
  2708. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  2709. controller: 'DbfindCustProdCtrl',
  2710. size: 'lg',
  2711. resolve: {
  2712. custUU: function(){return $scope.item.quotation.cust.uu}
  2713. }
  2714. });
  2715. modalInstance.result.then(function(data){
  2716. $scope.item.product = data;
  2717. }, function(){
  2718. });
  2719. } else {
  2720. toaster.pop('error', '错误', '请先选择客户');
  2721. }
  2722. }
  2723. };
  2724. // 保存
  2725. $scope.save = function(){
  2726. $scope.loading = true;
  2727. if(!$scope.item.quotation.code) //新增,设单号
  2728. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  2729. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  2730. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  2731. $scope.item.productId = $scope.item.product.id;
  2732. $scope.item.quotation.status = 100;//在录入
  2733. if($scope.item.quotation.date instanceof Date) {
  2734. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  2735. }
  2736. if($scope.item.quotation.endDate instanceof Date) {
  2737. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  2738. }
  2739. Quotation.save({}, $scope.item, function(data){
  2740. $scope.loading = false;
  2741. toaster.pop('success', '成功', '保存成功');
  2742. if($stateParams.id)
  2743. window.location.reload();
  2744. else
  2745. window.location.hash = '#/sale/quotation/' + data.id;
  2746. }, function(response){
  2747. $scope.loading = false;
  2748. toaster.pop('error', '保存失败', response.data);
  2749. });
  2750. };
  2751. // 更新
  2752. $scope.update = function(){
  2753. $scope.item.$editing = true;
  2754. };
  2755. // 取消
  2756. $scope.cancel = function(){
  2757. $scope.item.$editing = false;
  2758. $scope.item = angular.copy(staticItem);
  2759. };
  2760. // 提交
  2761. $scope.submit = function(){
  2762. $scope.loading = true;
  2763. $scope.item.quotation.status = 101;//在录入
  2764. Quotation.save({}, $scope.item, function(data){
  2765. $scope.loading = false;
  2766. toaster.pop('success', '成功', '提交成功');
  2767. window.location.hash = '#/sale/quotation/' + data.id;
  2768. }, function(response){
  2769. $scope.loading = false;
  2770. toaster.pop('error', '保存失败', response.data);
  2771. });
  2772. };
  2773. }]);
  2774. // 查找客户
  2775. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  2776. $scope.tableParams = new ngTableParams({
  2777. page : 1,
  2778. count : 10
  2779. }, {
  2780. total : 0,
  2781. counts: [5, 10, 25, 50],
  2782. getData : function($defer, params) {
  2783. $scope.loading = true;
  2784. Customer.get(BaseService.parseParams(params.url()), function(page){
  2785. $scope.loading = false;
  2786. if(page) {
  2787. params.total(page.totalElements);
  2788. $defer.resolve(page.content);
  2789. }
  2790. $scope.totalCount = page.totalElements;
  2791. }, function(response){
  2792. $scope.loading = false;
  2793. toaster.pop('error', '数据加载失败', response.data);
  2794. });
  2795. }
  2796. });
  2797. $scope.cancel = function() {
  2798. $modalInstance.dismiss();
  2799. };
  2800. $scope.check = function(cust){
  2801. $modalInstance.close(cust);
  2802. };
  2803. }]);
  2804. // 查找客户物料
  2805. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  2806. $scope.tableParams = new ngTableParams({
  2807. page : 1,
  2808. count : 10
  2809. }, {
  2810. total : 0,
  2811. counts: [5, 10, 25, 50],
  2812. getData : function($defer, params) {
  2813. $scope.loading = true;
  2814. var pageParams = params.url();
  2815. pageParams.keyword = $scope.keyword;
  2816. pageParams.custUU = custUU;
  2817. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  2818. $scope.loading = false;
  2819. if(page) {
  2820. params.total(page.totalElements);
  2821. $defer.resolve(page.content);
  2822. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2823. }
  2824. }, function(response){
  2825. $scope.loading = false;
  2826. toaster.pop('error', '数据加载失败', response.data);
  2827. });
  2828. }
  2829. });
  2830. // 取消
  2831. $scope.cancel = function() {
  2832. $modalInstance.dismiss();
  2833. };
  2834. // 选择
  2835. $scope.check = function(cust){
  2836. $modalInstance.close(cust);
  2837. };
  2838. // 搜索框回车
  2839. $scope.onSearch = function() {
  2840. $scope.tableParams.page(1);
  2841. $scope.tableParams.reload();
  2842. };
  2843. }]);
  2844. // 查找供应商
  2845. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  2846. console.log($rootScope);
  2847. $scope.tableParams = new ngTableParams({
  2848. page : 1,
  2849. count : 25
  2850. }, {
  2851. total : 0,
  2852. counts: [10, 25, 50, 100],
  2853. getData : function($defer, params) {
  2854. $scope.loading = true;
  2855. Vendor.getVendor(BaseService.parseParams(params.url()), function(page){
  2856. $scope.loading = false;
  2857. if(page) {
  2858. params.total(page.totalElements);
  2859. $defer.resolve(page.content);
  2860. // 添加供应商时,将已存在的选中
  2861. if ($rootScope.tenderVendor) {
  2862. angular.forEach(page.content, function(vendor) {
  2863. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  2864. vendor.checked = false;
  2865. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  2866. vendor.checked = true;
  2867. break;
  2868. }
  2869. }
  2870. });
  2871. }
  2872. }
  2873. $scope.totalCount = page.totalElements;
  2874. }, function(response){
  2875. $scope.loading = false;
  2876. toaster.pop('error', '数据加载失败', response.data);
  2877. });
  2878. }
  2879. });
  2880. $scope.cancel = function() {
  2881. $modalInstance.dismiss();
  2882. };
  2883. $scope.checks = {
  2884. checked : false
  2885. };// 全选框
  2886. $scope.checkAll = function() {
  2887. angular.forEach($scope.tableParams.data, function(vendor) {
  2888. vendor.checked = $scope.checks.checked;
  2889. });
  2890. };
  2891. // 单选
  2892. $scope.checkOne = function(vendor) {
  2893. vendor.checked = true;
  2894. }
  2895. $scope.close = function(){
  2896. var vendors = [];
  2897. angular.forEach($scope.tableParams.data, function(vendor) {
  2898. if(vendor.checked) {
  2899. vendors.push(vendor);
  2900. $modalInstance.close(vendors);
  2901. }
  2902. });
  2903. }
  2904. }]);
  2905. // 发货提醒
  2906. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', function($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state){
  2907. $scope.active = 'todo';
  2908. $scope.currency = Symbol.currency;
  2909. $scope.dateZoneText = '不限';
  2910. $scope.condition = {dateZone: -1};
  2911. $scope.changeDateZone = function(zone) {
  2912. $scope.condition.dateZone = zone;
  2913. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2914. $scope.condition.$dateZoneOpen = false;
  2915. getDateCondition(zone, $scope.condition);
  2916. $scope.tableParams.reload();
  2917. };
  2918. $scope.setActive = function(state) {
  2919. if($scope.active != state) {
  2920. $scope.active = state;
  2921. if($scope.tableParams.page() == 1)
  2922. $scope.tableParams.reload();
  2923. else
  2924. $scope.tableParams.page(1);
  2925. }
  2926. };
  2927. var getService = function() {
  2928. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  2929. };
  2930. $scope.tableParams = new ngTableParams({
  2931. page : 1,
  2932. count : 5,
  2933. sorting: {
  2934. 'delivery': 'asc',
  2935. 'orderItemOrderCode': 'asc',
  2936. 'orderItemNumber': 'asc'
  2937. }
  2938. }, {
  2939. total : 0,
  2940. counts: [5, 10, 25, 50],
  2941. getData : function($defer, params) {
  2942. $scope.loading = true;
  2943. var pageParams = params.url();
  2944. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2945. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2946. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2947. $scope.loading = false;
  2948. if(page) {
  2949. params.total(page.totalElement);
  2950. $defer.resolve(page.content);
  2951. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2952. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2953. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2954. }
  2955. }, function(response){
  2956. $scope.loading = false;
  2957. toaster.pop('error', '数据加载失败', response.data);
  2958. });
  2959. }
  2960. });
  2961. $scope.openDatePicker = function($event, item, openParam) {
  2962. $event.preventDefault();
  2963. $event.stopPropagation();
  2964. item[openParam] = !item[openParam];
  2965. };
  2966. //生成随机单号
  2967. $scope.autoCode = function(notice){
  2968. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  2969. };
  2970. //可送货日期
  2971. $scope.sendDate = function(notice) {
  2972. var stock = notice.orderItem.product.ltinstock || 0;
  2973. var de = new Date(notice.delivery);
  2974. if(stock == -1) {
  2975. de.setMonth(de.getMonth() -1);
  2976. de.setDate(25);
  2977. } else if(stock >= 0) {
  2978. de.setDate(de.getDate() - stock -1);
  2979. }
  2980. return de;
  2981. };
  2982. $scope.onReplyClick = function(notice) {
  2983. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  2984. toaster.pop('warning', '警告', '数量填写错误!');
  2985. } else if(!notice.send.code) {
  2986. toaster.pop('warning', '警告', '请填写发货单号!');
  2987. } else {
  2988. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  2989. $scope.loading = true;
  2990. PurcNotice.save({id: notice.id}, send, function(data){
  2991. $scope.loading = false;
  2992. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  2993. $state.go('sale.send_detail', {id: data.id});
  2994. }, function(response){
  2995. $scope.loading = false;
  2996. toaster.pop('error', '发货失败', response.data);
  2997. });
  2998. }
  2999. };
  3000. $scope.checkboxes = {
  3001. checked : false
  3002. };
  3003. // 点击勾选全部的复选框
  3004. $scope.checkAll = function(){
  3005. angular.forEach($scope.tableParams.data, function(item) {
  3006. if(!item.waiting)
  3007. item.$selected = $scope.checkboxes.checked;
  3008. });
  3009. };
  3010. // 点击其中一个明细的复选框
  3011. $scope.checkOne = function(order){
  3012. var result = true;
  3013. angular.forEach($scope.tableParams.data, function(item) {
  3014. if(item.$selected != true){
  3015. result = false;
  3016. return;
  3017. }
  3018. });
  3019. $scope.checkboxes.checked = result;
  3020. };
  3021. $scope.sendByBatch = function(){
  3022. var modalInstance = $modal.open({
  3023. animation: true,
  3024. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  3025. controller: 'SaleNoticeSendByBatchCtrl',
  3026. size: 'lg',
  3027. resolve: {
  3028. selectedNotices: function(){return $scope.tableParams.data;}
  3029. }
  3030. });
  3031. modalInstance.result.then(function(){
  3032. $scope.tableParams.reload();
  3033. }, function(){
  3034. });
  3035. };
  3036. $scope.getSends = function(notice){
  3037. if( ! notice.sends && notice.endQty > 0){
  3038. notice.getSendsing = true;
  3039. notice.getSendsError = false;
  3040. PurcNotice.getSends({id: notice.id}, function(data){
  3041. notice.getSendsing = false;
  3042. notice.getSendsError = false;
  3043. notice.sends = data;
  3044. }, function(response){
  3045. notice.getSendsing = false;
  3046. notice.getSendsError = true;
  3047. });
  3048. }
  3049. };
  3050. // 搜索框回车
  3051. $scope.onSearch = function() {
  3052. $scope.tableParams.page(1);
  3053. $scope.tableParams.reload();
  3054. };
  3055. // 选择查找日期
  3056. $scope.onDateCondition = function(){
  3057. $scope.tableParams.page(1);
  3058. $scope.tableParams.reload();
  3059. };
  3060. //货车功能
  3061. var truck = $rootScope.truck;
  3062. if(!truck) {
  3063. SaleTruck.query({}, function(data){
  3064. $rootScope.truck = data;
  3065. });
  3066. }
  3067. $scope.isInTruck = function(noticeId) {
  3068. return truck.indexOf(noticeId) > -1;
  3069. };
  3070. $scope.addtoTruck = function(notice) {
  3071. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  3072. $rootScope.truck = data;
  3073. });
  3074. };
  3075. $scope.delFromTruck = function(notice) {
  3076. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  3077. $rootScope.truck = data;
  3078. });
  3079. };
  3080. $scope.$watch(function(){
  3081. return $rootScope.truck;
  3082. }, function(data) {
  3083. truck = $rootScope.truck;
  3084. }, true);
  3085. $scope.$watch(function(){
  3086. return $rootScope.dataChanged;
  3087. }, function(data) {
  3088. data && ($scope.tableParams.reload());
  3089. }, true);
  3090. }]);
  3091. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  3092. $scope.notices = angular.copy(selectedNotices);
  3093. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3094. $scope.saleSend = {
  3095. code: '',
  3096. payments: '',
  3097. currency: '',
  3098. custUU: null,
  3099. custUserUU: null,
  3100. remark: '批量发货',
  3101. sendItems: []
  3102. };
  3103. // 计算总数、总额
  3104. $scope.$watch(function(){
  3105. return $scope.notices;
  3106. }, function(data) {
  3107. var q = 0, t = 0;
  3108. if(data) {
  3109. angular.forEach(data,function(d){
  3110. q += (d.thisSendQty || 0);
  3111. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  3112. });
  3113. }
  3114. $scope.totalQty = q;
  3115. $scope.total = t;
  3116. }, true);
  3117. /**
  3118. * 删除一个已选中的送货提醒
  3119. */
  3120. $scope.removeOne = function(index) {
  3121. $scope.notices.splice(index, 1);
  3122. };
  3123. //确认送货
  3124. $scope.sendByBatch = function () {
  3125. $scope.saleSend.sendItems = [];
  3126. if($scope.saleSend.code == '') {//送货单号为空
  3127. toaster.pop('error', '错误', '请输入送货单号');
  3128. return;
  3129. }
  3130. var a = 0;
  3131. var num = 1;
  3132. var valid = true;
  3133. angular.forEach($scope.notices, function(item, key){
  3134. if(item.$selected) {
  3135. if(a == 0) {//第一次
  3136. $scope.saleSend.currency = item.orderItem.order.currency;
  3137. $scope.saleSend.custUU = item.enUU;
  3138. $scope.saleSend.payments = item.orderItem.order.payments;
  3139. a = 1;
  3140. } else {//其他
  3141. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  3142. if($scope.saleSend.custUU != item.enUU) valid = false;
  3143. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  3144. }
  3145. $scope.saleSend.sendItems.push({
  3146. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  3147. });
  3148. }
  3149. });
  3150. if(!valid) {
  3151. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  3152. } else {
  3153. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  3154. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  3155. $modalInstance.close('success');
  3156. $state.go('sale.send_detail', {id: data.id});
  3157. }, function(response){
  3158. toaster.pop('error', '错误', response.data);
  3159. });
  3160. }
  3161. };
  3162. $scope.cancel = function () {
  3163. $modalInstance.dismiss();
  3164. };
  3165. }]);
  3166. /**
  3167. * 发货单
  3168. */
  3169. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  3170. $scope.active = 'all';
  3171. $scope.currency = Symbol.currency;
  3172. $scope.dateZoneText = '不限';
  3173. $scope.condition = {dateZone: -1};
  3174. $scope.changeDateZone = function(zone) {
  3175. $scope.condition.dateZone = zone;
  3176. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3177. $scope.condition.$dateZoneOpen = false;
  3178. getDateCondition(zone, $scope.condition);
  3179. $scope.tableParams.reload();
  3180. };
  3181. $scope.setActive = function(state) {
  3182. if($scope.active != state) {
  3183. $scope.active = state;
  3184. if($scope.tableParams.page() == 1)
  3185. $scope.tableParams.reload();
  3186. else
  3187. $scope.tableParams.page(1);
  3188. }
  3189. };
  3190. var getService = function() {
  3191. return SaleSend;
  3192. };
  3193. $scope.tableParams = new ngTableParams({
  3194. page : 1,
  3195. count : 5,
  3196. sorting: {
  3197. date: 'desc'
  3198. }
  3199. }, {
  3200. total : 0,
  3201. counts: [5, 10, 25, 50],
  3202. getData : function($defer, params) {
  3203. $scope.loading = true;
  3204. var pageParams = params.url();
  3205. pageParams.keyword = $scope.keyword;
  3206. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3207. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3208. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3209. $scope.loading = false;
  3210. if(page) {
  3211. params.total(page.totalElement);
  3212. $defer.resolve(page.content);
  3213. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3214. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3215. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3216. }
  3217. }, function(response){
  3218. $scope.loading = false;
  3219. toaster.pop('error', '数据加载失败', response.data);
  3220. });
  3221. }
  3222. });
  3223. $scope.openDatePicker = function($event, item, openParam) {
  3224. $event.preventDefault();
  3225. $event.stopPropagation();
  3226. item[openParam] = !item[openParam];
  3227. };
  3228. // 搜索框回车
  3229. $scope.onSearch = function() {
  3230. $scope.tableParams.page(1);
  3231. $scope.tableParams.reload();
  3232. };
  3233. // 选择查找日期
  3234. $scope.onDateCondition = function(){
  3235. $scope.tableParams.page(1);
  3236. $scope.tableParams.reload();
  3237. };
  3238. }]);
  3239. /**
  3240. * 发货单(包括发货条码维护)
  3241. */
  3242. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  3243. var loading = true;
  3244. $scope.checkBarCode = [];
  3245. $scope.checkBoxCode = [];
  3246. var vm = $scope.vm = {};
  3247. $scope.getCheckedItems = {};
  3248. vm.editBar = false;
  3249. vm.showBarCode = [];
  3250. $scope.barCode = function() {
  3251. vm.editBar = !vm.editBar;
  3252. }
  3253. $scope.checkboxes = {
  3254. checked : false
  3255. };
  3256. $scope.checkbars = {
  3257. checked : false
  3258. };
  3259. // 点击勾选barCode全部的复选框
  3260. $scope.checkBarAll = function(){
  3261. angular.forEach($scope.checkBarCode, function(item,key) {
  3262. $scope.checkBarCode[key] = $scope.checkbars.checked;
  3263. });
  3264. };
  3265. //点击barCode单选
  3266. $scope.checkBarOne = function() {
  3267. var result = true;
  3268. angular.forEach($scope.checkBarCode, function(item,key) {
  3269. if(item != true){
  3270. result = false;
  3271. return;
  3272. }
  3273. });
  3274. $scope.checkbars.checked = result;
  3275. }
  3276. // 点击boxCode全部的复选框
  3277. $scope.checkBoxAll = function(){
  3278. angular.forEach($scope.checkBoxCode, function(item,key) {
  3279. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  3280. });
  3281. };
  3282. //点击boxCode单选
  3283. $scope.checkBoxOne = function() {
  3284. var result = true;
  3285. angular.forEach($scope.checkBoxCode, function(item) {
  3286. if(item != true){
  3287. result = false;
  3288. return;
  3289. }
  3290. });
  3291. $scope.checkboxes.checked = result;
  3292. }
  3293. /**
  3294. * 生成条码和箱号
  3295. */
  3296. $scope.generateBarCode = function(item) {
  3297. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  3298. $scope.getCheckedItems = [];
  3299. var warningdata = '';
  3300. angular.forEach($scope.checkBarCode, function(item,key) {
  3301. $scope.getCheckedItem = {};
  3302. if(item == true ){
  3303. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  3304. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  3305. $scope.getCheckedItems.push($scope.getCheckedItem);
  3306. //判断是否生成过条码
  3307. if($scope.order.sendItems[key].barSendNotify.length > 0){
  3308. warningdata += $scope.order.sendItems[key].number+","
  3309. }
  3310. }
  3311. });
  3312. if($scope.getCheckedItems.length == 0){
  3313. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  3314. return;
  3315. }
  3316. if(warningdata != ''){
  3317. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  3318. return ;
  3319. }
  3320. }
  3321. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  3322. toaster.pop('success', '提示','生成成功!');
  3323. loadData();
  3324. },function(response){
  3325. $scope.loading = false;
  3326. toaster.pop('error', '生成失败', response.data);
  3327. });
  3328. }
  3329. /**
  3330. * 打印条码和箱号
  3331. */
  3332. $scope.printCode = function(type) {
  3333. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  3334. //勾选需要打印的行
  3335. $scope.getCheckedItems = [];
  3336. var warningdata = ''
  3337. angular.forEach($scope.checkBarCode, function(item,key) {
  3338. $scope.getCheckedItem = {};
  3339. if(item == true ){
  3340. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  3341. $scope.getCheckedItems.push($scope.getCheckedItem);
  3342. //判断是否生成过条码
  3343. if($scope.order.sendItems[key].barSendNotify.length > 0){
  3344. warningdata += $scope.order.sendItems[key].number+","
  3345. }
  3346. }
  3347. });
  3348. if($scope.getCheckedItems.length == 0){
  3349. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  3350. return;
  3351. }
  3352. if(warningdata == ''){
  3353. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  3354. return;
  3355. }
  3356. //选择打印模板
  3357. var modalInstance = $modal.open({
  3358. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  3359. controller: 'BarPrintModalCtrl',
  3360. resolve: {
  3361. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  3362. }
  3363. });
  3364. modalInstance.result.then(function(s){
  3365. if(s) {
  3366. //获取打印数据
  3367. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  3368. if(s.type == 'print'){//判断选择是打印还是打印预览
  3369. lodopPrint(data.message,LODOP,type);
  3370. }else if(s.type == 'printPreview'){
  3371. lodopPrintPreview(data.message,LODOP,type);
  3372. }
  3373. },function(response){
  3374. toaster.pop('error', '获取打印数据失败', response.data);
  3375. });
  3376. }
  3377. });
  3378. };
  3379. //打印单个条码
  3380. $scope.printSingleCode = function(id){
  3381. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  3382. //选择打印模板
  3383. var modalInstance = $modal.open({
  3384. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  3385. controller: 'BarPrintModalCtrl',
  3386. resolve: {
  3387. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  3388. }
  3389. });
  3390. modalInstance.result.then(function(s){
  3391. if(s) {
  3392. //获取打印数据
  3393. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  3394. if(s.type == 'print'){//判断选择是打印还是打印预览
  3395. lodopSPrint(data.message,LODOP);
  3396. }else if(s.type == 'printPreview'){
  3397. lodopSPrintPreview(data.message,LODOP);
  3398. }
  3399. },function(response){
  3400. toaster.pop('error', '获取打印数据失败', response.data);
  3401. });
  3402. }
  3403. });
  3404. }
  3405. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  3406. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  3407. if (selectOrNot != -1) {
  3408. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3409. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  3410. var strs = pagesize.split("*"); //字符分割
  3411. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3412. angular.forEach(printStore, function(data, index) {
  3413. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  3414. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3415. if (data['LP_VALUETYPE'] == 'barcode') {
  3416. LODOP.ADD_PRINT_BARCODE(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['LP_ENCODE'], data['value']);
  3417. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  3418. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  3419. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  3420. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  3421. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  3422. } else if (data['LP_VALUETYPE'] == 'text') {
  3423. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  3424. }
  3425. });
  3426. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  3427. LODOP.PRINT();
  3428. }
  3429. };
  3430. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  3431. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3432. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  3433. var strs = pagesize.split("*"); //字符分割
  3434. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3435. angular.forEach(printStore,function(data,index){
  3436. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  3437. if(data['LP_VALUETYPE'] == 'barcode'){
  3438. LODOP.ADD_PRINT_BARCODE(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['LP_ENCODE'],data['value']);
  3439. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  3440. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  3441. }else if(data['LP_VALUETYPE'] == 'text'){
  3442. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3443. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  3444. }
  3445. });
  3446. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  3447. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  3448. LODOP.PREVIEW();//打印预览
  3449. };
  3450. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  3451. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  3452. if (selectOrNot != -1) {
  3453. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3454. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  3455. var strs= new Array(); //定义一数组
  3456. strs = pagesize.split("*"); //字符分割
  3457. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3458. var ids = new Array();
  3459. angular.forEach(printStore, function(value,key) {
  3460. //LODOP.NewPage();
  3461. angular.forEach(value['data'], function(record,key) {
  3462. angular.forEach(record['store'], function(data, index) {
  3463. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  3464. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3465. if (data['LP_VALUETYPE'] == 'barcode') {
  3466. LODOP.ADD_PRINT_BARCODE(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['LP_ENCODE'], data['value']);
  3467. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  3468. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  3469. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  3470. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  3471. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  3472. } else if (data['LP_VALUETYPE'] == 'text') {
  3473. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  3474. }
  3475. });
  3476. });
  3477. var o = new Object();
  3478. o['id'] = record['si_id']
  3479. ids.push(o);
  3480. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  3481. LODOP.PRINT();
  3482. });
  3483. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  3484. if(type == 'Bar'){
  3485. //更新打印状态
  3486. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  3487. }
  3488. }
  3489. };
  3490. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  3491. var ids = new Array();
  3492. angular.forEach(printData, function(record, index){
  3493. angular.forEach(record['data'],function(value,index){
  3494. LODOP.NewPage();
  3495. angular.forEach(value['store'],function(data,index){
  3496. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  3497. if(data['LP_VALUETYPE'] == 'barcode'){
  3498. LODOP.ADD_PRINT_BARCODE(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['LP_ENCODE'],data['value']);
  3499. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  3500. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  3501. }else if(data['LP_VALUETYPE'] == 'text'){
  3502. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3503. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  3504. }
  3505. });
  3506. });
  3507. var o = new Object();
  3508. o['id'] = record['si_id']
  3509. ids.push(o);
  3510. });
  3511. var pagesize = printData[0]['pagesize'];//获取标签的大小
  3512. var strs= new Array(); //定义一数组
  3513. strs = pagesize.split("*"); //字符分割
  3514. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  3515. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  3516. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3517. var times = LODOP.PREVIEW();//打印预览
  3518. if(times > 0){//点击了打印预览内的打印按钮
  3519. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  3520. if(type == 'Bar'){
  3521. //更新打印状态
  3522. SaleSend.updatePrintStatus({},ids,function(data){
  3523. loadData();
  3524. },function(res){});
  3525. }
  3526. }
  3527. };
  3528. /**
  3529. * 查看条码按钮
  3530. */
  3531. $scope.showBarCode = function(number) {
  3532. $scope.keys = number;
  3533. for(var i=0;i<vm.showBarCode.length;i++){
  3534. if(i!=number){
  3535. vm.showBarCode[i] = false;
  3536. }
  3537. }
  3538. vm.showBarCode[number] = !vm.showBarCode[number];
  3539. $scope.barcodes = [];
  3540. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  3541. var getPage = function(page, size){
  3542. if($scope.barcodes) {
  3543. var result = {};
  3544. result.totalCount = $scope.barcodes.length;
  3545. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  3546. if($scope.barcodes.length % size == 0) {
  3547. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  3548. }else {
  3549. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  3550. }
  3551. result.first = page == 1;
  3552. result.last = page == result.totalPage;
  3553. result.page = page;
  3554. result.next = page - 0 + 1;
  3555. result.pre = page - 1;
  3556. return result;
  3557. }
  3558. }
  3559. $scope.barData = getPage(1,5);
  3560. $scope.first = function (){
  3561. $scope.barData = getPage($scope.barData.pre,5);
  3562. }
  3563. $scope.last = function (){
  3564. $scope.barData = getPage($scope.barData.next,5);
  3565. }
  3566. };
  3567. /**
  3568. * 更新外箱号
  3569. */
  3570. $scope.updateOutBox = function(item,number) {
  3571. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  3572. }else {
  3573. if(item.outBoxQty > 0) {
  3574. if(!(item.outBoxQty % item.packageQty)) {
  3575. SaleSend.update({id:item.id},item,function(){
  3576. toaster.pop('success', '提示','保存成功!');
  3577. loadData();
  3578. }, function(response){
  3579. $scope.loading = false;
  3580. toaster.pop('error', '回复失败', response.data);
  3581. })
  3582. }else {
  3583. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  3584. }
  3585. }else {
  3586. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3587. }
  3588. }
  3589. loadData();
  3590. };
  3591. /**
  3592. * 更新最小包数
  3593. */
  3594. $scope.updatePackage = function(item, number) {
  3595. if(item.packageQty == $scope.oldpackageQty[number]) {
  3596. }else {
  3597. if(item.orderItem.product.minPack != 0) {
  3598. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  3599. if(!(item.packageQty % item.orderItem.product.minPack)) {
  3600. SaleSend.update({id:item.id},item,function(){
  3601. toaster.pop('success', '提示','保存成功!');
  3602. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  3603. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  3604. }
  3605. loadData();
  3606. }, function(response){
  3607. $scope.loading = false;
  3608. toaster.pop('error', '回复失败', response.data);
  3609. })
  3610. }else {
  3611. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  3612. }
  3613. }else {
  3614. toaster.pop('warning', '提示', '请填写有效的数量!');
  3615. }
  3616. }else {
  3617. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  3618. SaleSend.update({id:item.id},item,function(){
  3619. toaster.pop('success', '提示','保存成功!');
  3620. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  3621. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  3622. }
  3623. loadData();
  3624. }, function(response){
  3625. $scope.loading = false;
  3626. toaster.pop('error', '回复失败', response.data);
  3627. })
  3628. }else {
  3629. toaster.pop('warning', '提示', '请填写有效的数量!');
  3630. }
  3631. }
  3632. }
  3633. loadData();
  3634. };
  3635. var loadData = function() {
  3636. SaleSend.get({id: $stateParams.id}, function(data){
  3637. $scope.order = data;
  3638. var orderCount = $scope.order.sendItems.length;
  3639. $scope.oldpackageQty = [];
  3640. $scope.oldoutBoxQty = [];
  3641. var sum = 0;
  3642. vm.oldpackageQty = [];
  3643. angular.forEach(data.sendItems, function(value, key){
  3644. //给showBarCode数组赋初值
  3645. if (vm.showBarCode.length < orderCount){
  3646. vm.showBarCode.push(false);
  3647. }
  3648. if($scope.checkBarCode.length < orderCount) {
  3649. $scope.checkBarCode.push(false);
  3650. }
  3651. if($scope.checkBoxCode.length < orderCount) {
  3652. $scope.checkBoxCode.push(false);
  3653. }
  3654. //给个初值
  3655. if(!value.packageQty) {
  3656. value.packageQty = value.orderItem.product.minPack;
  3657. }
  3658. $scope.oldpackageQty.push(value.packageQty);
  3659. if(value.outBoxQty) {
  3660. $scope.oldoutBoxQty.push(value.outBoxQty);
  3661. }
  3662. sum += value.price * value.qty;
  3663. });
  3664. data.total = sum;
  3665. $scope.loading = false;
  3666. }, function(response){
  3667. loading = false;
  3668. toaster.pop('error', '获取数据失败', response.data);
  3669. });
  3670. };
  3671. loadData();
  3672. }]);
  3673. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  3674. $scope.typeItem = typeItem;
  3675. $scope.template = [];
  3676. $scope.choose = {};
  3677. //获取打印模板
  3678. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  3679. if(data.message){
  3680. $scope.template = data.message;
  3681. $scope.choose.tp_id = $scope.template[0].id;
  3682. }
  3683. },function(res){
  3684. toaster.pop('error', '获取模板错误', res.data);
  3685. });
  3686. $scope.print = function(){
  3687. $scope.choose.type = 'print';
  3688. $modalInstance.close($scope.choose);
  3689. };
  3690. $scope.printPreview = function(){
  3691. $scope.choose.type = 'printPreview';
  3692. $modalInstance.close($scope.choose);
  3693. }
  3694. $scope.cancel = function(){
  3695. $modalInstance.close();
  3696. }
  3697. }]);
  3698. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  3699. var loading = true;
  3700. var loadData = function() {
  3701. PurcSample.get({id: $stateParams.id}, function(data){
  3702. $scope.sample = data;
  3703. if(!$scope.sample.send){
  3704. $scope.sample.getSendInfo = '加载中...';
  3705. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  3706. if(sendData) {
  3707. $scope.sample.getSendInfo = null;
  3708. $scope.sample.send = sendData;
  3709. } else {
  3710. $scope.sample.getSendInfo = '无送样信息';
  3711. $scope.sample.send = '无送样信息';
  3712. }
  3713. }, function(response){
  3714. $scope.sample.getSendInfo = '加载失败!';
  3715. });
  3716. }
  3717. $scope.loading = false;
  3718. }, function(response){
  3719. loading = false;
  3720. toaster.pop('error', '获取数据失败', response.data);
  3721. });
  3722. };
  3723. loadData();
  3724. }]);
  3725. /**
  3726. * 客户打样申请
  3727. */
  3728. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  3729. $scope.active = 'todo';
  3730. $scope.agreedText = '全部';
  3731. $scope.dateZoneText = '一个月内';
  3732. $scope.condition = {dateZone: 1};
  3733. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3734. $scope.changeAgreed = function(agreed) {
  3735. $scope.condition.agreed = agreed;
  3736. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3737. $scope.condition.$agreedOpen = false;
  3738. };
  3739. $scope.changeDateZone = function(zone) {
  3740. $scope.condition.dateZone = zone;
  3741. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3742. $scope.condition.$dateZoneOpen = false;
  3743. };
  3744. $scope.setActive = function(state) {
  3745. if($scope.active != state) {
  3746. $scope.active = state;
  3747. if($scope.tableParams.page() == 1)
  3748. $scope.tableParams.reload();
  3749. else
  3750. $scope.tableParams.page(1);
  3751. }
  3752. };
  3753. var getService = function() {
  3754. return PurcSample;
  3755. };
  3756. $scope.tableParams = new ngTableParams({
  3757. page : 1,
  3758. count : 5,
  3759. sorting: {
  3760. proofingDate: 'desc'
  3761. }
  3762. }, {
  3763. total : 0,
  3764. counts: [5, 10, 25, 50],
  3765. getData : function($defer, params) {
  3766. $scope.loading = true;
  3767. var pageParams = params.url();
  3768. pageParams.keyword = $scope.keyword;
  3769. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3770. $scope.loading = false;
  3771. if(page) {
  3772. params.total(page.totalElement);
  3773. $defer.resolve(page.content);
  3774. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3775. }
  3776. }, function(response){
  3777. $scope.loading = false;
  3778. toaster.pop('error', '数据加载失败', response.data);
  3779. });
  3780. }
  3781. });
  3782. $scope.openDatePicker = function($event, item, openParam) {
  3783. $event.preventDefault();
  3784. $event.stopPropagation();
  3785. item[openParam] = !item[openParam];
  3786. };
  3787. $scope.openSend = function(index, sample) {
  3788. var modalInstance = $modal.open({
  3789. animation: true,
  3790. templateUrl: 'static/tpl/index/sale/sample_send.html',
  3791. controller: 'SampleSendCtrl',
  3792. resolve: {
  3793. sampleItem: function(){return sample;}
  3794. }
  3795. });
  3796. modalInstance.result.then(function(){
  3797. toaster.pop('info', '提示', '送样成功');
  3798. $scope.tableParams.reload();
  3799. }, function(){
  3800. });
  3801. };
  3802. //打印 样品采购单
  3803. $scope.print = function(sample) {
  3804. console.log(sample);
  3805. PurcSample.printCount({id: sample.id},{});//增加打印此次
  3806. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  3807. };
  3808. $scope.getSend = function(proofing){
  3809. if( !proofing.send) {
  3810. proofing.getSendInfo = '加载中...';
  3811. PurcSample.getSend({id: proofing.id}, function(data){
  3812. if(data) {
  3813. proofing.getSendInfo = null;
  3814. proofing.send = data;
  3815. } else {
  3816. proofing.getSendInfo = '无送样信息';
  3817. proofing.send = '无送样信息';
  3818. }
  3819. }, function(response){
  3820. proofing.getSendInfo = '加载失败!';
  3821. });
  3822. }
  3823. };
  3824. // 搜索框回车
  3825. $scope.onSearch = function() {
  3826. $scope.tableParams.page(1);
  3827. $scope.tableParams.reload();
  3828. };
  3829. }]);
  3830. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  3831. $scope.sampleItem = sampleItem;
  3832. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  3833. //确认送样
  3834. $scope.ok = function (form) {
  3835. $scope.loading = true;
  3836. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  3837. $upload.upload({
  3838. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  3839. method: 'POST',
  3840. file: file,
  3841. data: {
  3842. json: $scope.sampleItem.sampleSend
  3843. }
  3844. }).success(function(data){
  3845. $scope.loading = false;
  3846. $modalInstance.close('success');
  3847. }).error(function(data){
  3848. $scope.loading = false;
  3849. toaster.pop('danger', '错误', data);
  3850. });
  3851. };
  3852. $scope.cancel = function () {
  3853. $modalInstance.dismiss(sampleItem);
  3854. };
  3855. }]);
  3856. /**
  3857. * 客户认定单
  3858. */
  3859. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  3860. $scope.active = 'all';
  3861. $scope.agreedText = '全部';
  3862. $scope.dateZoneText = '一个月内';
  3863. $scope.condition = {dateZone: 1};
  3864. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3865. $scope.changeDateZone = function(zone) {
  3866. $scope.condition.dateZone = zone;
  3867. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3868. $scope.condition.$dateZoneOpen = false;
  3869. getDateCondition(zone, $scope.condition);
  3870. $scope.tableParams.reload();
  3871. };
  3872. $scope.setActive = function(state) {
  3873. if($scope.active != state) {
  3874. $scope.active = state;
  3875. if($scope.tableParams.page() == 1)
  3876. $scope.tableParams.reload();
  3877. else
  3878. $scope.tableParams.page(1);
  3879. }
  3880. };
  3881. var getService = function() {
  3882. return PurcApproval;
  3883. };
  3884. $scope.tableParams = new ngTableParams({
  3885. page : 1,
  3886. count : 5,
  3887. sorting: {
  3888. inDate: 'desc'
  3889. }
  3890. }, {
  3891. total : 0,
  3892. counts: [5, 10, 25, 50],
  3893. getData : function($defer, params) {
  3894. $scope.loading = true;
  3895. var pageParams = params.url();
  3896. pageParams.keyword = $scope.keyword;
  3897. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3898. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3899. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3900. $scope.loading = false;
  3901. if(page) {
  3902. params.total(page.totalElement);
  3903. $defer.resolve(page.content);
  3904. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3905. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3906. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3907. }
  3908. }, function(response){
  3909. $scope.loading = false;
  3910. toaster.pop('error', '数据加载失败', response.data);
  3911. });
  3912. }
  3913. });
  3914. $scope.openDatePicker = function($event, item, openParam) {
  3915. $event.preventDefault();
  3916. $event.stopPropagation();
  3917. item[openParam] = !item[openParam];
  3918. };
  3919. $scope.parseDate = function(dateStr) {
  3920. if(dateStr)
  3921. return Date.parse(dateStr, 'yyyy-MM-dd');
  3922. return new Date();
  3923. };
  3924. // 搜索框回车
  3925. $scope.onSearch = function() {
  3926. $scope.tableParams.page(1);
  3927. $scope.tableParams.reload();
  3928. };
  3929. // 选择查找日期
  3930. $scope.onDateCondition = function(){
  3931. $scope.tableParams.page(1);
  3932. $scope.tableParams.reload();
  3933. };
  3934. }]);
  3935. /**
  3936. * 客户采购预测
  3937. */
  3938. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  3939. $scope.active = 'all';
  3940. $scope.agreedText = '全部';
  3941. $scope.dateZoneText = '一个月内';
  3942. $scope.condition = {dateZone: 1};
  3943. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3944. $scope.changeAgreed = function(agreed) {
  3945. $scope.condition.agreed = agreed;
  3946. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3947. $scope.condition.$agreedOpen = false;
  3948. };
  3949. $scope.changeDateZone = function(zone) {
  3950. $scope.condition.dateZone = zone;
  3951. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3952. $scope.condition.$dateZoneOpen = false;
  3953. };
  3954. $scope.setActive = function(state) {
  3955. if($scope.active != state) {
  3956. $scope.active = state;
  3957. if($scope.tableParams.page() == 1)
  3958. $scope.tableParams.reload();
  3959. else
  3960. $scope.tableParams.page(1);
  3961. }
  3962. };
  3963. var getService = function() {
  3964. return PurcForecast;
  3965. };
  3966. $scope.tableParams = new ngTableParams({
  3967. page : 1,
  3968. count : 5,
  3969. sorting: {
  3970. orderDate: 'desc'
  3971. }
  3972. }, {
  3973. total : 0,
  3974. counts: [5, 10, 25, 50],
  3975. getData : function($defer, params) {
  3976. $scope.loading = true;
  3977. var pageParams = params.url();
  3978. pageParams.keyword = $scope.keyword;
  3979. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3980. $scope.loading = false;
  3981. if(page) {
  3982. console.log(page);
  3983. params.total(page.totalElement);
  3984. $defer.resolve(page.content);
  3985. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3986. }
  3987. }, function(response){
  3988. $scope.loading = false;
  3989. toaster.pop('error', '数据加载失败', response.data);
  3990. });
  3991. }
  3992. });
  3993. $scope.openDatePicker = function($event, item, openParam) {
  3994. $event.preventDefault();
  3995. $event.stopPropagation();
  3996. item[openParam] = !item[openParam];
  3997. };
  3998. // 搜索框回车
  3999. $scope.onSearch = function() {
  4000. $scope.tableParams.page(1);
  4001. $scope.tableParams.reload();
  4002. };
  4003. }]);
  4004. /**
  4005. * 客户采购验收
  4006. */
  4007. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  4008. $scope.active = 'all';
  4009. $scope.dateZoneText = '不限';
  4010. $scope.deliveryZoneText = '不限';
  4011. $scope.condition = {dateZone: -1, deliveryZone: -1};
  4012. $scope.changeDateZone = function(zone) {
  4013. $scope.condition.dateZone = zone;
  4014. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4015. $scope.condition.$dateZoneOpen = false;
  4016. getDateCondition(zone, $scope.condition);
  4017. $scope.tableParams.reload();
  4018. };
  4019. $scope.changeDeliveryZone = function(zone) {
  4020. $scope.condition.deliveryZoneText = zone;
  4021. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  4022. $scope.condition.$delievryZoneOpen = false;
  4023. getDelveryCondition(zone, $scope.condition);
  4024. $scope.tableParams.reload();
  4025. };
  4026. $scope.setActive = function(state) {
  4027. if($scope.active != state) {
  4028. $scope.active = state;
  4029. if($scope.tableParams.page() == 1)
  4030. $scope.tableParams.reload();
  4031. else
  4032. $scope.tableParams.page(1);
  4033. }
  4034. };
  4035. var getService = function() {
  4036. return PurcAccept;
  4037. };
  4038. $scope.tableParams = new ngTableParams({
  4039. page : 1,
  4040. count : 5,
  4041. sorting: {
  4042. date: 'desc'
  4043. }
  4044. }, {
  4045. total : 0,
  4046. counts: [5, 10, 25, 50],
  4047. getData : function($defer, params) {
  4048. $scope.loading = true;
  4049. var pageParams = params.url();
  4050. pageParams.searchFilter = { // 筛选条件
  4051. keyword: $scope.keyword,
  4052. fromDate: getDateTime($scope.condition.dateFrom),
  4053. endDate: getDateTime($scope.condition.dateTo)
  4054. };
  4055. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4056. $scope.loading = false;
  4057. if(page) {
  4058. console.log(pageParams.searchFilter);
  4059. params.total(page.totalElement);
  4060. $defer.resolve(page.content);
  4061. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4062. }
  4063. }, function(response){
  4064. $scope.loading = false;
  4065. toaster.pop('error', '数据加载失败', response.data);
  4066. });
  4067. }
  4068. });
  4069. $scope.openDatePicker = function($event, item, openParam) {
  4070. $event.preventDefault();
  4071. $event.stopPropagation();
  4072. item[openParam] = !item[openParam];
  4073. };
  4074. $scope.parseDate = function(dateStr) {
  4075. if(dateStr)
  4076. return Date.parse(dateStr, 'yyyy-MM-dd');
  4077. return new Date();
  4078. };
  4079. // 选择查找日期
  4080. $scope.onDateCondition = function(){
  4081. $scope.tableParams.page(1);
  4082. $scope.tableParams.reload();
  4083. };
  4084. // 搜索框回车
  4085. $scope.onSearch = function() {
  4086. $scope.tableParams.page(1);
  4087. $scope.tableParams.reload();
  4088. };
  4089. }]);
  4090. /**
  4091. * 客户采购验退
  4092. */
  4093. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  4094. $scope.active = 'all';
  4095. $scope.agreedText = '全部';
  4096. $scope.dateZoneText = '一个月内';
  4097. $scope.condition = {dateZone: 1};
  4098. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4099. $scope.changeAgreed = function(agreed) {
  4100. $scope.condition.agreed = agreed;
  4101. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4102. $scope.condition.$agreedOpen = false;
  4103. };
  4104. $scope.changeDateZone = function(zone) {
  4105. $scope.condition.dateZone = zone;
  4106. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4107. $scope.condition.$dateZoneOpen = false;
  4108. };
  4109. $scope.setActive = function(state) {
  4110. if($scope.active != state) {
  4111. $scope.active = state;
  4112. if($scope.tableParams.page() == 1)
  4113. $scope.tableParams.reload();
  4114. else
  4115. $scope.tableParams.page(1);
  4116. }
  4117. };
  4118. var getService = function() {
  4119. return PurcReturn;
  4120. };
  4121. $scope.tableParams = new ngTableParams({
  4122. page : 1,
  4123. count : 5,
  4124. sorting: {
  4125. date: 'desc'
  4126. }
  4127. }, {
  4128. total : 0,
  4129. counts: [5, 10, 25, 50],
  4130. getData : function($defer, params) {
  4131. $scope.loading = true;
  4132. var pageParams = params.url();
  4133. pageParams.keyword = $scope.keyword;
  4134. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4135. $scope.loading = false;
  4136. if(page) {
  4137. params.total(page.totalElement);
  4138. $defer.resolve(page.content);
  4139. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4140. angular.forEach(page.content, function(data) {
  4141. if (!data.returnItems[0].orderItem) {
  4142. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  4143. data.enName = enterprise.enName;
  4144. });
  4145. }
  4146. });
  4147. }
  4148. }, function(response){
  4149. $scope.loading = false;
  4150. toaster.pop('error', '数据加载失败', response.data);
  4151. });
  4152. }
  4153. });
  4154. $scope.openDatePicker = function($event, item, openParam) {
  4155. $event.preventDefault();
  4156. $event.stopPropagation();
  4157. item[openParam] = !item[openParam];
  4158. };
  4159. // 搜索框回车
  4160. $scope.onSearch = function() {
  4161. $scope.tableParams.page(1);
  4162. $scope.tableParams.reload();
  4163. };
  4164. }]);
  4165. /**
  4166. * 客户不良品入库
  4167. */
  4168. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  4169. $scope.active = 'all';
  4170. $scope.agreedText = '全部';
  4171. $scope.dateZoneText = '一个月内';
  4172. $scope.condition = {dateZone: 1};
  4173. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4174. $scope.changeAgreed = function(agreed) {
  4175. $scope.condition.agreed = agreed;
  4176. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4177. $scope.condition.$agreedOpen = false;
  4178. };
  4179. $scope.changeDateZone = function(zone) {
  4180. $scope.condition.dateZone = zone;
  4181. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4182. $scope.condition.$dateZoneOpen = false;
  4183. };
  4184. $scope.setActive = function(state) {
  4185. if($scope.active != state) {
  4186. $scope.active = state;
  4187. if($scope.tableParams.page() == 1)
  4188. $scope.tableParams.reload();
  4189. else
  4190. $scope.tableParams.page(1);
  4191. }
  4192. };
  4193. var getService = function() {
  4194. return PurcBadIn;
  4195. };
  4196. $scope.tableParams = new ngTableParams({
  4197. page : 1,
  4198. count : 5,
  4199. sorting: {
  4200. date: 'desc'
  4201. }
  4202. }, {
  4203. total : 0,
  4204. counts: [5, 10, 25, 50],
  4205. getData : function($defer, params) {
  4206. $scope.loading = true;
  4207. var pageParams = params.url();
  4208. pageParams.keyword = $scope.keyword;
  4209. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4210. $scope.loading = false;
  4211. if(page) {
  4212. params.total(page.totalElement);
  4213. $defer.resolve(page.content);
  4214. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4215. }
  4216. }, function(response){
  4217. $scope.loading = false;
  4218. toaster.pop('error', '数据加载失败', response.data);
  4219. });
  4220. }
  4221. });
  4222. $scope.openDatePicker = function($event, item, openParam) {
  4223. $event.preventDefault();
  4224. $event.stopPropagation();
  4225. item[openParam] = !item[openParam];
  4226. };
  4227. // 搜索框回车
  4228. $scope.onSearch = function() {
  4229. $scope.tableParams.page(1);
  4230. $scope.tableParams.reload();
  4231. };
  4232. }]);
  4233. /**
  4234. * 客户不良品出库
  4235. */
  4236. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  4237. $scope.active = 'all';
  4238. $scope.agreedText = '全部';
  4239. $scope.dateZoneText = '一个月内';
  4240. $scope.condition = {dateZone: 1};
  4241. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4242. $scope.changeAgreed = function(agreed) {
  4243. $scope.condition.agreed = agreed;
  4244. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4245. $scope.condition.$agreedOpen = false;
  4246. };
  4247. $scope.changeDateZone = function(zone) {
  4248. $scope.condition.dateZone = zone;
  4249. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4250. $scope.condition.$dateZoneOpen = false;
  4251. };
  4252. $scope.setActive = function(state) {
  4253. if($scope.active != state) {
  4254. $scope.active = state;
  4255. if($scope.tableParams.page() == 1)
  4256. $scope.tableParams.reload();
  4257. else
  4258. $scope.tableParams.page(1);
  4259. }
  4260. };
  4261. var getService = function() {
  4262. return PurcBadOut;
  4263. };
  4264. $scope.tableParams = new ngTableParams({
  4265. page : 1,
  4266. count : 5,
  4267. sorting: {
  4268. date: 'desc'
  4269. }
  4270. }, {
  4271. total : 0,
  4272. counts: [5, 10, 25, 50],
  4273. getData : function($defer, params) {
  4274. $scope.loading = true;
  4275. var pageParams = params.url();
  4276. pageParams.keyword = $scope.keyword;
  4277. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4278. $scope.loading = false;
  4279. if(page) {
  4280. params.total(page.totalElement);
  4281. $defer.resolve(page.content);
  4282. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4283. }
  4284. }, function(response){
  4285. $scope.loading = false;
  4286. toaster.pop('error', '数据加载失败', response.data);
  4287. });
  4288. }
  4289. });
  4290. $scope.openDatePicker = function($event, item, openParam) {
  4291. $event.preventDefault();
  4292. $event.stopPropagation();
  4293. item[openParam] = !item[openParam];
  4294. };
  4295. // 搜索框回车
  4296. $scope.onSearch = function() {
  4297. $scope.tableParams.page(1);
  4298. $scope.tableParams.reload();
  4299. };
  4300. }]);
  4301. /**
  4302. * 客户MRB
  4303. */
  4304. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  4305. $scope.active = 'all';
  4306. $scope.agreedText = '全部';
  4307. $scope.dateZoneText = '一个月内';
  4308. $scope.condition = {dateZone: 1};
  4309. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4310. $scope.changeAgreed = function(agreed) {
  4311. $scope.condition.agreed = agreed;
  4312. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4313. $scope.condition.$agreedOpen = false;
  4314. };
  4315. $scope.changeDateZone = function(zone) {
  4316. $scope.condition.dateZone = zone;
  4317. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4318. $scope.condition.$dateZoneOpen = false;
  4319. };
  4320. $scope.setActive = function(state) {
  4321. if($scope.active != state) {
  4322. $scope.active = state;
  4323. if($scope.tableParams.page() == 1)
  4324. $scope.tableParams.reload();
  4325. else
  4326. $scope.tableParams.page(1);
  4327. }
  4328. };
  4329. var getService = function() {
  4330. return PurcMRB;
  4331. };
  4332. $scope.tableParams = new ngTableParams({
  4333. page : 1,
  4334. count : 5,
  4335. sorting: {
  4336. date: 'desc'
  4337. }
  4338. }, {
  4339. total : 0,
  4340. counts: [5, 10, 25, 50],
  4341. getData : function($defer, params) {
  4342. $scope.loading = true;
  4343. var pageParams = params.url();
  4344. pageParams.keyword = $scope.keyword;
  4345. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4346. $scope.loading = false;
  4347. if(page) {
  4348. params.total(page.totalElement);
  4349. $defer.resolve(page.content);
  4350. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4351. }
  4352. }, function(response){
  4353. $scope.loading = false;
  4354. toaster.pop('error', '数据加载失败', response.data);
  4355. });
  4356. }
  4357. });
  4358. $scope.openDatePicker = function($event, item, openParam) {
  4359. $event.preventDefault();
  4360. $event.stopPropagation();
  4361. item[openParam] = !item[openParam];
  4362. };
  4363. // 搜索框回车
  4364. $scope.onSearch = function() {
  4365. $scope.tableParams.page(1);
  4366. $scope.tableParams.reload();
  4367. };
  4368. }]);
  4369. /**
  4370. * 客户应付发票
  4371. */
  4372. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  4373. $scope.active = 'all';
  4374. $scope.dateZoneText = '不限';
  4375. $scope.condition = {dateZone: -1};
  4376. $scope.changeDateZone = function(zone) {
  4377. $scope.condition.dateZone = zone;
  4378. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4379. $scope.condition.$dateZoneOpen = false;
  4380. getDateCondition(zone, $scope.condition);
  4381. $scope.tableParams.reload();
  4382. };
  4383. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4384. $scope.setActive = function(state) {
  4385. if($scope.active != state) {
  4386. $scope.active = state;
  4387. if($scope.tableParams.page() == 1)
  4388. $scope.tableParams.reload();
  4389. else
  4390. $scope.tableParams.page(1);
  4391. }
  4392. };
  4393. var getService = function() {
  4394. return FaApBill;
  4395. };
  4396. $scope.tableParams = new ngTableParams({
  4397. page : 1,
  4398. count : 5,
  4399. sorting: {
  4400. date: 'desc'
  4401. }
  4402. }, {
  4403. total : 0,
  4404. counts: [5, 10, 25, 50],
  4405. getData : function($defer, params) {
  4406. $scope.loading = true;
  4407. var pageParams = params.url();
  4408. pageParams.searchFilter = { // 筛选条件
  4409. keyword: $scope.keyword,
  4410. fromDate: getDateTime($scope.condition.dateFrom),
  4411. endDate: getDateTime($scope.condition.dateTo)
  4412. };
  4413. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4414. $scope.loading = false;
  4415. if(page) {
  4416. params.total(page.totalElement);
  4417. $defer.resolve(page.content);
  4418. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  4419. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4420. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4421. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  4422. }
  4423. }, function(response){
  4424. $scope.loading = false;
  4425. toaster.pop('error', '数据加载失败', response.data);
  4426. });
  4427. }
  4428. });
  4429. $scope.openDatePicker = function($event, item, openParam) {
  4430. $event.preventDefault();
  4431. $event.stopPropagation();
  4432. item[openParam] = !item[openParam];
  4433. };
  4434. $scope.parseDate = function(dateStr) {
  4435. if(dateStr)
  4436. return Date.parse(dateStr, 'yyyy-MM-dd');
  4437. return new Date();
  4438. };
  4439. // 搜索框回车
  4440. $scope.onSearch = function() {
  4441. $scope.tableParams.page(1);
  4442. $scope.tableParams.reload();
  4443. };
  4444. // 选择查找日期
  4445. $scope.onDateCondition = function(){
  4446. $scope.tableParams.page(1);
  4447. $scope.tableParams.reload();
  4448. };
  4449. }]);
  4450. /**
  4451. * 应付对账单
  4452. */
  4453. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  4454. $scope.active = 'all';
  4455. $scope.dateZoneText = '不限';
  4456. $scope.condition = {dateZone: -1};
  4457. $scope.changeDateZone = function(zone) {
  4458. $scope.condition.dateZone = zone;
  4459. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4460. $scope.condition.$dateZoneOpen = false;
  4461. getDateCondition(zone, $scope.condition);
  4462. $scope.tableParams.reload();
  4463. };
  4464. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4465. $scope.setActive = function(state) {
  4466. if($scope.active != state) {
  4467. $scope.active = state;
  4468. if($scope.tableParams.page() == 1)
  4469. $scope.tableParams.reload();
  4470. else
  4471. $scope.tableParams.page(1);
  4472. }
  4473. };
  4474. var getService = function() {
  4475. return FaArCheck;
  4476. };
  4477. $scope.tableParams = new ngTableParams({
  4478. page : 1,
  4479. count : 5,
  4480. sorting: {
  4481. date: 'desc'
  4482. }
  4483. }, {
  4484. total : 0,
  4485. counts: [5, 10, 25, 50],
  4486. getData : function($defer, params) {
  4487. $scope.loading = true;
  4488. var pageParams = params.url();
  4489. pageParams.keyword = $scope.keyword;
  4490. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4491. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4492. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4493. $scope.loading = false;
  4494. if(page) {
  4495. params.total(page.totalElement);
  4496. $defer.resolve(page.content);
  4497. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4498. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4499. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4500. }
  4501. }, function(response){
  4502. $scope.loading = false;
  4503. toaster.pop('error', '数据加载失败', response.data);
  4504. });
  4505. }
  4506. });
  4507. $scope.openDatePicker = function($event, item, openParam) {
  4508. $event.preventDefault();
  4509. $event.stopPropagation();
  4510. item[openParam] = !item[openParam];
  4511. };
  4512. // 计算单据的商品总数
  4513. $scope.getTotalProd = function(check) {
  4514. var total = 0;
  4515. if(check.items) {
  4516. angular.forEach(check.items, function(value) {
  4517. total += value.qty;
  4518. });
  4519. }
  4520. return total;
  4521. };
  4522. // 搜索框回车
  4523. $scope.onSearch = function() {
  4524. $scope.tableParams.page(1);
  4525. $scope.tableParams.reload();
  4526. };
  4527. // 选择查找日期
  4528. $scope.onDateCondition = function(){
  4529. $scope.tableParams.page(1);
  4530. $scope.tableParams.reload();
  4531. };
  4532. }]);
  4533. // 应付对账单详情页
  4534. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', function($scope, $stateParams, FaArCheck, toaster, $state){
  4535. var loadData = function() {
  4536. FaArCheck.get({id: $stateParams.id}, function(data){
  4537. $scope.order = data;
  4538. $scope.loading = false;
  4539. });
  4540. };
  4541. loadData(); // 初始获取单据数据
  4542. $scope.onReplyClick = function(item, isAgreed) {
  4543. if(isAgreed) {// 同意确认
  4544. FaArCheck.agree({itemId: item.id}, {}, function(data){
  4545. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  4546. }, function(response){
  4547. toaster.pop('danger', '确认失败', response.data);
  4548. });
  4549. } else {// 不同意回复
  4550. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  4551. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  4552. }, function(response) {
  4553. toaster.pop('danger', '确认失败', response.data);
  4554. });
  4555. }
  4556. };
  4557. // 获取明细的回复记录
  4558. $scope.getReplies = function(item) {
  4559. if(!item.replies) {
  4560. FaArCheck.getReplies({itemId: item.id}, function(data) {
  4561. item.replies = data;
  4562. }, function(response) {
  4563. toaster.pop('danger', '获取对账记录失败', response.data);
  4564. });
  4565. }
  4566. };
  4567. }]);
  4568. //应收对账单列表
  4569. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  4570. $scope.dateZoneText = '不限';
  4571. $scope.condition = {dateZone: -1};
  4572. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4573. $scope.active = 'todo';
  4574. //打印 对账单
  4575. $scope.print = function(check) {
  4576. FaApCheck.printCount({id: check.id},{});//增加打印此次
  4577. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  4578. };
  4579. //状态
  4580. $scope.setActive = function (state){
  4581. if($scope.active != state) {
  4582. $scope.active = state;
  4583. if($scope.tableParams.page() == 1)
  4584. $scope.tableParams.reload();
  4585. else
  4586. $scope.tableParams.page(1);
  4587. }
  4588. };
  4589. $scope.changeDateZone = function(zone) {
  4590. $scope.condition.dateZone = zone;
  4591. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4592. $scope.condition.$dateZoneOpen = false;
  4593. getDateCondition(zone, $scope.condition);
  4594. $scope.tableParams.reload();
  4595. };
  4596. //获取应收对账单全部
  4597. $scope.tableParams = new ngTableParams({
  4598. page : 1,
  4599. count : 5,
  4600. sorting: {
  4601. recordDate: 'desc'
  4602. }
  4603. }, {
  4604. total : 0,
  4605. counts: [5, 10, 25, 50],
  4606. getData : function($defer, params) {
  4607. $scope.loading = true;
  4608. var pageParams = params.url();
  4609. pageParams.searchFilter = { // 筛选条件
  4610. keyword: $scope.keyword,
  4611. fromDate: getDateTime($scope.condition.dateFrom),
  4612. endDate: getDateTime($scope.condition.dateTo)
  4613. };
  4614. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  4615. $scope.loading = false;
  4616. if(page) {
  4617. params.total(page.totalElement);
  4618. $scope.data = $defer.resolve(page.content);
  4619. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  4620. }
  4621. }, function(response){
  4622. $scope.loading = false;
  4623. toaster.pop('error', '数据加载失败', response.data);
  4624. });
  4625. }
  4626. });
  4627. $scope.openDatePicker = function($event, item, openParam) {
  4628. $event.preventDefault();
  4629. $event.stopPropagation();
  4630. item[openParam] = !item[openParam];
  4631. };
  4632. // 计算单据的商品总数
  4633. $scope.getTotalProd = function(check) {
  4634. var total = 0;
  4635. if(check.items) {
  4636. angular.forEach(check.items, function(value) {
  4637. total += value.checkQty;
  4638. });
  4639. }
  4640. return total;
  4641. };
  4642. // 搜索框回车
  4643. $scope.onSearch = function() {
  4644. $scope.tableParams.page(1);
  4645. $scope.tableParams.reload();
  4646. };
  4647. // 选择查找日期
  4648. $scope.onDateCondition = function(){
  4649. $scope.tableParams.page(1);
  4650. $scope.tableParams.reload();
  4651. };
  4652. }]);
  4653. //应收对账单详情
  4654. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams',function($scope,toaster,FaApCheck,$stateParams){
  4655. $scope.haveSelected = true;
  4656. $scope.data = {};
  4657. //控制提交和删除按钮的显示
  4658. $scope.ifShow = true;
  4659. var loadData = function(){
  4660. FaApCheck.get({id:$stateParams.id},function(data){
  4661. $scope.data = data;
  4662. if($scope.data.status){
  4663. }else{
  4664. $scope.ifShow = true;
  4665. }
  4666. })
  4667. };
  4668. if($stateParams.id){
  4669. loadData();
  4670. }
  4671. $scope.haveSource = false;
  4672. //提交应收对账单
  4673. $scope.submitApCheck = function(){
  4674. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  4675. if(data.result) {
  4676. toaster.pop('success', '提示', '提交成功');
  4677. $scope.haveSelected = false;
  4678. window.location.href = '#/fa/apCheck';
  4679. }else {
  4680. $scope.haveSource = true;
  4681. loadData();
  4682. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  4683. $scope.haveSelected = true;
  4684. }
  4685. },function(){
  4686. $scope.loading = false;
  4687. toaster.pop('error', '提示', '更新已转数失败');
  4688. });
  4689. }
  4690. //删除应收对账单的同时更新来源表已转数
  4691. var updateYCheckQty = function(){
  4692. var sourceInfos = [];
  4693. angular.forEach($scope.data.items, function(item){
  4694. $scope.sourceInfo = {
  4695. sourceId: '',
  4696. sourceTable: '',
  4697. newYCheckQty: ''
  4698. };
  4699. $scope.sourceInfo.sourceId = item.sourceId;
  4700. $scope.sourceInfo.sourceTable = item.sourceTable;
  4701. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  4702. sourceInfos.push($scope.sourceInfo);
  4703. });
  4704. FaApCheck.update({}, sourceInfos, function(){
  4705. },function(response){
  4706. $scope.loading = false;
  4707. toaster.pop('error', '更新已转数失败', response.data);
  4708. });
  4709. }
  4710. //删除应收对账单
  4711. $scope.deleteApCheck = function(){
  4712. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  4713. updateYCheckQty();
  4714. toaster.pop('success','提示','删除成功');
  4715. },function(){
  4716. toaster.pop('error','提示','删除失败');
  4717. });
  4718. $scope.haveSelected = false;
  4719. }
  4720. //作废应收对账单
  4721. $scope.cancelApCheck = function(check) {
  4722. FaApCheck.cancel({id:check.id},function(data){
  4723. $scope.checkResult = false;
  4724. if(data.result) {
  4725. $scope.checkResult = true;
  4726. toaster.pop('success', '提示', '作废成功');
  4727. $scope.tableParams.reload();
  4728. }else{
  4729. toaster.pop('error', '提示', '作废失败');
  4730. }
  4731. },function(){
  4732. $scope.loading = false;
  4733. toaster.pop('error', '提示', '作废失败');
  4734. });
  4735. }
  4736. }]);
  4737. //未对账单据列表
  4738. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  4739. $scope.data = {};// 列表数据
  4740. $scope.loading = true;
  4741. // $scope.getData = function(){
  4742. // FaApCheck.getAll(function(data){
  4743. // $scope.data = data;
  4744. // angular.forEach($scope.data, function(item) {
  4745. // item:{
  4746. // $selected:true;
  4747. // }
  4748. // });
  4749. // $scope.loading = false;
  4750. // });
  4751. //
  4752. // }
  4753. document.getElementById('suuorname').focus();//光标默认在客户
  4754. // $scope.getData();
  4755. $scope.condition = {
  4756. $fromOpened:false
  4757. }
  4758. $scope.openDatePicker = function($event, item, openParam) {
  4759. $event.preventDefault();
  4760. $event.stopPropagation();
  4761. item[openParam] = !item[openParam];
  4762. }
  4763. //查找客户
  4764. $scope.searchCust = function(suuorname) {
  4765. var modalInstance = $modal.open({
  4766. animation: true,
  4767. templateUrl: 'static/tpl/index/fa/custInfo.html',
  4768. controller: 'SearchCustInfoCtrl',
  4769. resolve: {
  4770. suuorname: function() {
  4771. return suuorname;
  4772. }
  4773. }
  4774. });
  4775. modalInstance.result.then(function(suuorname){
  4776. $scope.suuorname = suuorname;
  4777. });
  4778. }
  4779. // 点击筛选根据条件选择数据
  4780. $scope.suuorname = '';
  4781. $scope.sdateFrom = '';
  4782. $scope.sdateTo = '';
  4783. $scope.vuuorname = '';
  4784. $scope.factory = '';
  4785. $scope.prodTitle = '';
  4786. $scope.prodSpec = '';
  4787. $scope.condition.uuorname = '';
  4788. $scope.condition.dateFrom = '';
  4789. $scope.condition.dateTo = '';
  4790. $scope.condition.venduuorname = '';
  4791. $scope.condition.factory = '';
  4792. $scope.condition.prodTitle = '';
  4793. $scope.condition.prodSpec = '';
  4794. $scope.searchOrder = function(check) {
  4795. angular.forEach($scope.data, function(item) {
  4796. $scope.checkboxes.checked = false;
  4797. item.$selected = false;
  4798. });
  4799. $scope.totalMoney = 0;
  4800. $scope.condition.uuorname = $scope.suuorname;
  4801. $scope.condition.factory = $scope.factory
  4802. $scope.condition.prodTitle = $scope.prodTitle;
  4803. $scope.condition.prodSpec = $scope.prodSpec;
  4804. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  4805. $scope.thisdatato = ($scope.sdateTo || 0);
  4806. if($scope.thisdatato != 0) {
  4807. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  4808. } else {
  4809. $scope.condition.dateTo = ($scope.sdateTo || 0);
  4810. }
  4811. $scope.condition.venduuorname = $scope.vuuorname;
  4812. // //物料名称和物料规格存在特殊符号,用|作分割符
  4813. // $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  4814. // + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  4815. // + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  4816. // + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  4817. // + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  4818. // $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4819. // $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4820. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  4821. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4822. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4823. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  4824. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  4825. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  4826. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  4827. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  4828. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4829. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4830. if($scope.suuorname == '') {
  4831. toaster.pop('info','提示', '请先选择客户');
  4832. document.getElementById('suuorname').focus();//光标默认在客户
  4833. } else {
  4834. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  4835. $scope.data = data;
  4836. angular.forEach($scope.data, function(item) {
  4837. item:{
  4838. $selected:true;
  4839. }
  4840. });
  4841. $scope.loading = false;
  4842. }, function(response) {
  4843. toaster.pop('error', '提示', response.data);
  4844. });
  4845. }
  4846. }
  4847. }
  4848. /**
  4849. * 点击勾选框,选中要转应收对账单的订单
  4850. * */
  4851. $scope.totalMoney = 0;
  4852. $scope.checkboxes = {
  4853. checked : false
  4854. };
  4855. // 点击勾选全部的复选框
  4856. $scope.checkAll = function(){
  4857. $scope.totalMoney = 0;
  4858. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  4859. var uuorname = $scope.suuorname;
  4860. var venduuorname = $scope.venduuorname;
  4861. var dateFrom = $scope.condition.dateFrom;
  4862. var dateTo = $scope.condition.dateTo;
  4863. var prodTitle = $scope.condition.prodTitle;
  4864. var prodSpec = $scope.condition.prodSpec;
  4865. var factory = $scope.condition.factory;
  4866. angular.forEach($scope.filteredData, function(item) {
  4867. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  4868. item.$selected = $scope.checkboxes.checked;
  4869. }
  4870. });
  4871. $scope.getTotalMoney();
  4872. };
  4873. //获取已选单据总金额
  4874. var total = true;
  4875. $scope.getTotalMoney = function(){
  4876. $scope.totalMoney = 0;
  4877. angular.forEach($scope.data, function(check) {
  4878. if(check.$selected){
  4879. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4880. }else{
  4881. $scope.totalMoney += 0;
  4882. }
  4883. });
  4884. }
  4885. // 点击其中一个明细的复选框
  4886. $scope.checkOne = function(check){
  4887. var result = true;
  4888. angular.forEach($scope.data, function(item) {
  4889. if(item.$selected != true){
  4890. result = false;
  4891. return;
  4892. }
  4893. });
  4894. $scope.checkboxes.checked = result;
  4895. };
  4896. $scope.haveSelected = false;
  4897. //生成应收对账单
  4898. $scope.createApCheck = function(){
  4899. //保存应收对账单主记录字段
  4900. $scope.apCheck = {
  4901. custUu: '',
  4902. custName: '',
  4903. enUu: '',
  4904. apDate: '',
  4905. beginDate: '',
  4906. endDate: '',
  4907. checkStatus: '未对账',
  4908. checkAmount: 0,
  4909. currency: '',
  4910. rate: '',
  4911. items: []
  4912. };
  4913. //保存来源单据相关信息
  4914. var sourceInfos = [];
  4915. //所允许的本次对账最大最小数量
  4916. $scope.data.maxThisCheckQty = 0;
  4917. $scope.data.minThisCheckQty = 0;
  4918. $scope.sameCust = true;
  4919. $scope.validQty = true;
  4920. $scope.loading = true;
  4921. angular.forEach($scope.data, function(check) {
  4922. //保存应收对账单明细行数据
  4923. $scope.item = {
  4924. inoutno: '',
  4925. inoutnodetno: '',
  4926. orderCode: '',
  4927. orderClass: '',
  4928. orderDetno: '',
  4929. price: '',
  4930. checkQty: '',
  4931. amount: '',
  4932. sourceId:'',
  4933. sourceTable:'',
  4934. oldYCheckQty:'',
  4935. status: 0,
  4936. receiveCode:'',
  4937. receiveName:'',
  4938. prodCode:'',
  4939. prodTitle:'',
  4940. prodSpec:'',
  4941. taxrate: '',
  4942. sendcode: '',
  4943. whname: '',
  4944. };
  4945. //应收对账单明细行来源表信息
  4946. $scope.sourceInfo = {
  4947. sourceId: '',
  4948. sourceTable: '',
  4949. newYCheckQty: ''
  4950. };
  4951. //此次对账后新的已转数
  4952. $scope.newYCheckQty = 0;
  4953. if(check.$selected == true) {
  4954. $scope.apCheck.custName = check.custName;
  4955. $scope.apCheck.enUu = check.enUu;
  4956. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4957. $scope.apCheck.apDate = check.piDate;
  4958. $scope.apCheck.rate = check.rate;
  4959. //必须是同一家客户才能生成对账单,否则提示错误
  4960. if($scope.apCheck.custUu == ''){
  4961. $scope.apCheck.custUu = check.custUu;
  4962. }else if($scope.apCheck.custUu !== check.custUu){
  4963. $scope.sameCust = false;
  4964. $scope.loading = false;
  4965. toaster.pop('error', '请选择同一家客户');
  4966. }
  4967. //必须是相同币别才能生成对账单,否则提示错误
  4968. if($scope.apCheck.currency == ''){
  4969. $scope.apCheck.currency = check.currency;
  4970. }else if($scope.apCheck.currency !== check.currency){
  4971. $scope.sameCust = false;
  4972. $scope.loading = false;
  4973. toaster.pop('error', '请选择同一种币别');
  4974. }
  4975. //本次对账数量必须小于总对账数量
  4976. if(check.qty > 0){
  4977. $scope.data.maxThisCheckQty = check.qty;
  4978. $scope.data.minThisCheckQty = 0;
  4979. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  4980. $scope.validQty = false;
  4981. $scope.loading = false;
  4982. toaster.pop('error','本次对账数量,填写有误!');
  4983. }
  4984. }else if(check.qty < 0){
  4985. $scope.data.maxThisCheckQty = 0;
  4986. $scope.data.minThisCheckQty = check.qty;
  4987. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  4988. $scope.validQty = false;
  4989. $scope.loading = false;
  4990. toaster.pop('error','本次对账数量,填写有误!');
  4991. }
  4992. }
  4993. //获取最小时间作为对账区间的起始时间
  4994. if($scope.apCheck.beginDate == ''){
  4995. $scope.apCheck.beginDate = check.piDate;
  4996. }else{
  4997. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  4998. }
  4999. //获取最大时间作为对账区间的截止时间
  5000. if($scope.apCheck.endDate == ''){
  5001. $scope.apCheck.endDate = check.piDate;
  5002. }else{
  5003. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  5004. }
  5005. //应收对账单明细行数据
  5006. $scope.item.orderCode = check.orderCode;
  5007. $scope.item.orderClass = check.piClass;
  5008. $scope.item.orderDetno = check.orderDetno;
  5009. $scope.item.price = check.orderPrice;
  5010. $scope.item.checkQty = check.thisCheckQty;
  5011. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5012. $scope.item.sourceId = check.sourceId;
  5013. $scope.item.sourceTable = check.sourceTable;
  5014. $scope.item.oldYCheckQty = check.yCheckQty;
  5015. $scope.item.prodCode = check.prodCode;
  5016. $scope.item.prodTitle = check.prodTitle;
  5017. $scope.item.prodSpec = check.prodSpec;
  5018. $scope.item.inoutno = check.inOutNo;
  5019. $scope.item.inoutnodetno = check.detno;
  5020. $scope.item.taxrate = check.taxrate;
  5021. $scope.item.receiveCode = check.receiveCode;
  5022. $scope.item.receiveName = check.receiveName;
  5023. $scope.item.sendcode = check.sendcode;
  5024. $scope.item.whname = check.whname;
  5025. //来源表相关信息
  5026. $scope.sourceInfo.sourceId = check.sourceId;
  5027. $scope.sourceInfo.sourceTable = check.sourceTable;
  5028. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  5029. sourceInfos.push($scope.sourceInfo);
  5030. $scope.apCheck.items.push($scope.item);
  5031. $scope.haveSelected = true;
  5032. }
  5033. });
  5034. //保存生成的应收对账单
  5035. $scope.saveApCheck = function(){
  5036. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  5037. $scope.loading = false;
  5038. toaster.pop('success', '成功', '生成应收对账成功');
  5039. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  5040. }, function(response){
  5041. toaster.pop('error', '生成对账单失败', response.data);
  5042. })
  5043. };
  5044. //如果是同一家客户,生成对账单的同时,关闭模态框
  5045. if($scope.sameCust && $scope.validQty) {
  5046. $scope.saveApCheck();
  5047. }
  5048. }
  5049. }]);
  5050. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
  5051. $scope.loading = true;
  5052. AccountEnterprise.get({}, function(data){
  5053. $scope.loading = false;
  5054. $scope.enterprise = data;
  5055. });
  5056. AccountEnterprise.growth({}, function(data){
  5057. if(data != null && data.length > 0) {
  5058. var growth = [], years = [];
  5059. angular.forEach(data, function(d){
  5060. var date = new Date(d.date), year = date.getFullYear();
  5061. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  5062. if(years.indexOf(year) == -1) {
  5063. years.push(year);
  5064. growth.push({year: year});
  5065. }
  5066. growth.push(d);
  5067. });
  5068. $scope.growth = growth;
  5069. }
  5070. });
  5071. // 更新企业信息
  5072. $scope.updateDetailInfo = function(){
  5073. $scope.loading = true;
  5074. AccountEnterprise.save($scope.enterprise, function(){
  5075. $scope.loading = false;
  5076. $scope.connectionEditing = false;
  5077. toaster.pop('success', '提示', '修改企业信息成功');
  5078. $state.reload();
  5079. }, function(response){
  5080. $scope.loading = false;
  5081. toaster.pop('error', '修改信息失败', response.data);
  5082. });
  5083. };
  5084. // 申请Saas
  5085. $scope.applySaas = function(){
  5086. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  5087. var modalInstance = $modal.open({
  5088. animation: true,
  5089. templateUrl: 'static/tpl/index/account/applySaas.html',
  5090. controller: 'ApplySaasCtrl',
  5091. resolve: {
  5092. enterprise: function(){return angular.copy($scope.enterprise);}
  5093. }
  5094. });
  5095. modalInstance.result.then(function(){
  5096. $state.reload();
  5097. }, function(){
  5098. });
  5099. } else {
  5100. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  5101. }
  5102. };
  5103. }]);
  5104. // 申请Saas Controller
  5105. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  5106. $scope.enterprise = enterprise;
  5107. $scope.checking = false;
  5108. $scope.$watch('enterprise.enSaasUrl', function(){
  5109. if($scope.enterprise.enSaasUrl) {
  5110. $http.get('signup/saasUrlEnable', {
  5111. params: {
  5112. enSaasUrl: $scope.enterprise.enSaasUrl
  5113. }
  5114. }).success(function(data){
  5115. if(data && data == 'true') {
  5116. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  5117. } else {
  5118. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  5119. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  5120. }
  5121. }).error(function(){
  5122. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  5123. $scope.enSaasUrlErrorInfo = '验证出错';
  5124. });
  5125. } else {
  5126. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  5127. }
  5128. });
  5129. var setSaasUrl = function(url) {
  5130. var index = url.indexOf('www.');
  5131. if(index != -1) {//包含www.
  5132. var substr = url.substring(index+4, url.length);
  5133. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  5134. } else {
  5135. $scope.enterprise.enSaasUrl = getHost(url);
  5136. }
  5137. };
  5138. // 解析获取网址的一级域名
  5139. var getHost = function(host){
  5140. var newhost;
  5141. var domain;
  5142. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  5143. for(var k in ArrDomain){
  5144. var re = eval('/\\' + ArrDomain[k] + '$/g');
  5145. newhost = host.replace(re, '');
  5146. if(newhost != host){
  5147. domain = ArrDomain[k];
  5148. break;
  5149. }
  5150. }
  5151. var hostar = newhost.split('.');
  5152. var s = hostar[hostar.length-1];
  5153. return s;
  5154. };
  5155. // 设置优企云服域名为官网网址一级域名
  5156. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  5157. $scope.apply = function(){
  5158. $scope.loading = true;
  5159. AccountEnterprise.applySaas({
  5160. enUU: $scope.enterprise.uu,
  5161. enSaasUrl: $scope.enterprise.enSaasUrl,
  5162. enAdminPassword: $scope.enterprise.enAdminPassword
  5163. }, {}, function(){
  5164. $scope.loading = false;
  5165. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  5166. $modalInstance.close();
  5167. }, function(response){
  5168. $scope.loading = false;
  5169. toaster.pop('error', '申请失败', response.data);
  5170. });
  5171. };
  5172. $scope.cancel = function () {
  5173. $modalInstance.dismiss();
  5174. };
  5175. }]);
  5176. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', 'AccountEnterprise', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert, AccountEnterprise){
  5177. $scope.editing = false;
  5178. $scope.loading = true;
  5179. $scope.enterprise = null;
  5180. AccountUser.findDistribute({},function(data) {
  5181. $scope.distributes = data;
  5182. },function(response) {
  5183. toaster.pop('error', '系统错误', response.data);
  5184. })
  5185. AuthenticationService.getAuthentication().success(function(data) {
  5186. $scope.loading = false;
  5187. $scope.user = data;
  5188. });
  5189. var users = [];
  5190. $scope.tableParams = new ngTableParams({
  5191. page : 1,
  5192. count : 5,
  5193. sorting: {
  5194. userName: 'asc'
  5195. }
  5196. }, {
  5197. total : 0,
  5198. counts: [15, 25, 50, 100],
  5199. getData : function($defer, params) {
  5200. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  5201. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  5202. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  5203. angular.forEach($scope.users,function(user){
  5204. AccountEnterprise.get({}, function(data){
  5205. $scope.loading = false;
  5206. $scope.enterprise = data;
  5207. });
  5208. });
  5209. params.total(orderedData.length);
  5210. $defer.resolve($scope.users);
  5211. }
  5212. });
  5213. var loadUsers = function() {
  5214. AccountUser.query({}, function(data){
  5215. users = data;
  5216. $scope.tableParams.reload();
  5217. $scope.loading = false;
  5218. });
  5219. };
  5220. loadUsers();
  5221. $scope.saveUser = function(){
  5222. $scope.loading = true;
  5223. AccountUser.update({}, $scope.user, function(data){
  5224. $scope.loading = false;
  5225. toaster.pop('success', '提示', '修改用户信息成功');
  5226. AuthenticationService.getAuthentication().success(function(data) {
  5227. $scope.user = data;
  5228. });
  5229. loadUsers();
  5230. $scope.editing = false;
  5231. }, function(reponse){
  5232. $scope.loading = false;
  5233. toaster.pop('error', '失败', reponse.data);
  5234. });
  5235. };
  5236. $scope.updatePassword = function(){
  5237. var modalInstance = $modal.open({
  5238. animation: true,
  5239. templateUrl: 'updatePassword.html',
  5240. controller: 'PasswordCtrl',
  5241. resolve: {
  5242. user: function(){return $scope.user;}
  5243. }
  5244. });
  5245. modalInstance.result.then(function(){
  5246. }, function(){
  5247. });
  5248. };
  5249. $scope.newUser = {};
  5250. //弹出添加用户模态框
  5251. $scope.addExistUser = function(){
  5252. var modalInstance = $modal.open({
  5253. animation :true,
  5254. templateUrl : 'static/tpl/index/account/addExistUser.html',
  5255. controller : 'AddExistUserCtrl'
  5256. });
  5257. modalInstance.result.then(function(){
  5258. $scope.userTelSuccess = false;
  5259. $scope.userTelError = false;
  5260. }, function(){
  5261. });
  5262. };
  5263. /**
  5264. * 添加未注册用户
  5265. */
  5266. $scope.addUser = function() {
  5267. $scope.adding = true;
  5268. AccountUser.save({}, $scope.newUser, function(){
  5269. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  5270. $scope.newUser = {userSex: 'M'};
  5271. loadUsers();
  5272. $scope.adding = false;
  5273. $scope.newUserForm.newUserTel.$setValidity('available', false);
  5274. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  5275. $scope.userTelSuccess = false;
  5276. $scope.userTelError = false;
  5277. $scope.userEmailSuccess = false;
  5278. $scope.userEmailError = false;
  5279. }, function(response){
  5280. toaster.pop('error', '错误', response.data);
  5281. });
  5282. };
  5283. /**
  5284. * 验证手机号是否可用
  5285. */
  5286. $scope.telValid = function(tel) {
  5287. if(tel) {
  5288. $http.get('account/user/telEnable', {
  5289. params: {
  5290. tel: tel
  5291. }
  5292. }).success(function(data){
  5293. data = eval(data);
  5294. if(data == true) {
  5295. $scope.newUserForm.newUserTel.$setValidity('available', true);
  5296. $scope.userTelSuccess = true;
  5297. $scope.userTelError = false;
  5298. }else{
  5299. $scope.newUserForm.newUserTel.$setValidity('available', false);
  5300. $scope.userTelError = true;
  5301. $scope.userTelSuccess = false;
  5302. if(tel.length == 11)
  5303. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  5304. }
  5305. }).error(function(){
  5306. $scope.userTelSuccess = false;
  5307. $scope.userTelError = true;
  5308. });
  5309. } else {
  5310. $scope.userTelSuccess = false;
  5311. $scope.userTelError = false;
  5312. }
  5313. };
  5314. /**
  5315. * 验证邮箱是否可用
  5316. */
  5317. $scope.emailValid = function(email) {
  5318. if(email) {
  5319. $http.get('account/user/emailEnable', {
  5320. params: {
  5321. email: email
  5322. }
  5323. }).success(function(data){
  5324. data = eval(data);
  5325. if(data == true) {
  5326. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  5327. $scope.userEmailSuccess = true;
  5328. $scope.userEmailError = false;
  5329. } else {
  5330. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  5331. $scope.userEmailError = true;
  5332. $scope.userEmailSuccess = false;
  5333. }
  5334. }).error(function(){
  5335. $scope.userEmailError = true;
  5336. $scope.userEmailSuccess = false;
  5337. });
  5338. } else {
  5339. $scope.userEmailError = false;
  5340. $scope.userEmailSuccess = false;
  5341. }
  5342. };
  5343. /**
  5344. * 删除用户
  5345. */
  5346. $scope.removeUser = function(user) {
  5347. new ngAlert({
  5348. title: '提示',
  5349. content: '确定删除用户(' + user.userName + ')吗?'
  5350. }, function(){
  5351. AccountUser.remove({uu: user.userUU}, function(){
  5352. toaster.pop('success', '提示', '用户删除成功。');
  5353. loadUsers();
  5354. }, function(response){
  5355. toaster.pop('error', '删除失败', response.data);
  5356. });
  5357. });
  5358. };
  5359. // 编辑用户的角色
  5360. $scope.editUserRole = function(user) {
  5361. var modalInstance = $modal.open({
  5362. animation: true,
  5363. templateUrl: 'static/tpl/index/account/user_role.html',
  5364. controller: 'UserRoleCtrl',
  5365. resolve: {
  5366. user: function() {
  5367. return user;
  5368. }
  5369. }
  5370. });
  5371. modalInstance.result.then(function(changed, checked){
  5372. if(changed) {
  5373. if(checked)
  5374. $scope.newUser.roles = checked;
  5375. else
  5376. loadUsers();
  5377. }
  5378. });
  5379. };
  5380. // 为用户分配角色(删除企业)
  5381. $scope.removeVendor = function(user) {
  5382. var resultRole = true;
  5383. angular.forEach(user.roles,function(role){
  5384. if(role.issys == 1) {
  5385. toaster.pop('error', '提示', '管理员无需分配客户');
  5386. resultRole = false;
  5387. return;
  5388. }
  5389. })
  5390. if(resultRole) {
  5391. var modalInstance = $modal.open({
  5392. animation: true,
  5393. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  5394. controller: 'RemoveVendorCtrl',
  5395. resolve: {
  5396. user: function() {
  5397. return user;
  5398. }
  5399. }
  5400. });
  5401. }
  5402. }
  5403. // 为用户分配角色(添加企业)
  5404. $scope.addVendor = function(user,isIssy) {
  5405. if(!isIssy) {
  5406. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  5407. return;
  5408. }
  5409. var resultRole = true;
  5410. angular.forEach(user.roles,function(role){
  5411. if(role.issys == 1) {
  5412. toaster.pop('error', '提示', '管理员无需分配客户');
  5413. resultRole = false;
  5414. return;
  5415. }
  5416. })
  5417. if(resultRole) {
  5418. var modalInstance = $modal.open({
  5419. animation: true,
  5420. templateUrl: 'static/tpl/index/account/add_vendor.html',
  5421. controller: 'AddVendorCtrl',
  5422. resolve: {
  5423. user: function() {
  5424. return user;
  5425. }
  5426. }
  5427. });
  5428. modalInstance.result.then(function(changed, checked){
  5429. if(changed) {
  5430. if(checked)
  5431. $scope.newUser.roles = checked;
  5432. else
  5433. loadUsers();
  5434. }
  5435. });
  5436. }
  5437. };
  5438. }]);
  5439. // 登录手机号码验证
  5440. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  5441. $scope.user = user;
  5442. $scope.cancel = function(){
  5443. $modalInstance.close();
  5444. }
  5445. /*$scope.loading = false;
  5446. $scope.btnState = false;
  5447. $scope.clicks = 0;
  5448. var storage = window.localStorage;
  5449. //手机验证码定时器
  5450. $scope.msgInfoError = false;
  5451. var setBtnTimeDown = function(value) {
  5452. if(value > 0) {
  5453. $scope.btnState = true;
  5454. $timeout(function() {
  5455. $scope.$apply(function(){
  5456. storage.setItem("btnTimes", $scope.btnTimes);
  5457. $scope.btnTimes --;
  5458. value --;
  5459. setBtnTimeDown (value);
  5460. });
  5461. }, 500);
  5462. }else{
  5463. $scope.btnState = false;
  5464. }
  5465. };
  5466. if(storage.btnTimes > 1){
  5467. $scope.btnTimes = storage.btnTimes;
  5468. setBtnTimeDown(storage.btnTimes)
  5469. }else{
  5470. storage.removeItem("btnTimes");
  5471. }
  5472. $scope.updateTel = function(phoneCode, userTel, uu){
  5473. $scope.loading = true;
  5474. $scope.msgInfoError = false;
  5475. $scope.result = false;
  5476. //更新联系方式
  5477. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  5478. $scope.loading = false;
  5479. $scope.msgInfoError2 = false;
  5480. $scope.result = true;
  5481. AuthenticationService.getAuthentication().success(function(data) {
  5482. $timeout(function(){
  5483. $modalInstance.dismiss();
  5484. window.location.reload();
  5485. }, 1000);
  5486. }).error(function(response) {
  5487. });
  5488. }, function(response){
  5489. $scope.loading = false;
  5490. $scope.msgInfoError2 = response;
  5491. });
  5492. };
  5493. //获取验证码
  5494. $scope.getPhoneCode = function(userTel){
  5495. var timeInfo = 10;
  5496. $scope.clicks ++;
  5497. $scope.timeInfo = timeInfo;
  5498. if($scope.clicks >= 5){
  5499. $scope.errorloading = true;
  5500. $scope.msgInfoSuccess = false;
  5501. $scope.msgInfoError = false;
  5502. }else{
  5503. $scope.loading = true;
  5504. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  5505. $scope.loading = false;
  5506. $scope.msgInfoSuccess = data.success;
  5507. $scope.sendMsg = data;
  5508. $scope.btnTimes = 60;
  5509. setBtnTimeDown($scope.btnTimes);
  5510. $scope.msgInfoError = false;
  5511. },function(response){
  5512. console.log(response);
  5513. $scope.loading = false;
  5514. $scope.msgInfoError = false;
  5515. $scope.sendCheckMsg = false;
  5516. $scope.msgInfoSuccess = true;
  5517. });
  5518. }
  5519. }; */
  5520. }]);
  5521. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5522. $scope.checkboxes = {
  5523. checked : false
  5524. };
  5525. $scope.loading = true;
  5526. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  5527. $scope.enters = data;
  5528. $scope.loading = false;
  5529. angular.forEach($scope.enters, function(item) {
  5530. item:{
  5531. $selected:true;
  5532. }
  5533. });
  5534. })
  5535. // 点击勾选全部的复选框
  5536. $scope.checkAll = function() {
  5537. angular.forEach($scope.enters, function(item) {
  5538. item.$selected = $scope.checkboxes.checked;
  5539. });
  5540. };
  5541. // 点击其中一个明细的复选框
  5542. $scope.checkOne = function(vendor){
  5543. var result = true;
  5544. angular.forEach($scope.enters, function(item) {
  5545. if(item.$selected != true){
  5546. result = false;
  5547. return;
  5548. }
  5549. });
  5550. $scope.checkboxes.checked = result;
  5551. };
  5552. $scope.close = function(save) {
  5553. var chooseResult = [];
  5554. if(save) {
  5555. if(user.userUU) {
  5556. angular.forEach($scope.enters, function(item, i) {
  5557. if(item.$selected) {
  5558. chooseResult.push(item.id);
  5559. }
  5560. });
  5561. if(chooseResult.length > 0) {
  5562. $scope.loading = true;
  5563. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  5564. $scope.loading = false;
  5565. toaster.pop('success', '提示', '删除成功');
  5566. $modalInstance.close(false);
  5567. }, function(response){
  5568. $scope.loading = false;
  5569. toaster.pop('error', '删除失败', response.data);
  5570. $modalInstance.close(false);
  5571. })
  5572. } else {
  5573. toaster.pop('error', '删除失败', "您未勾选任何记录");
  5574. }
  5575. } else {
  5576. $modalInstance.close(true, $scope.checkboxes.checked);
  5577. }
  5578. } else {
  5579. $modalInstance.close(false);
  5580. }
  5581. };
  5582. }]);
  5583. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5584. $scope.checkboxes = {
  5585. checked : false
  5586. };
  5587. $scope.loading = true;
  5588. AccountUser.findVendor({uu : user.userUU},function(data) {
  5589. $scope.enters = data;
  5590. $scope.loading = false;
  5591. // angular.forEach($scope.enters, function(item) {
  5592. // if(item.distribute) {
  5593. // item:{
  5594. // $selected:false;
  5595. // }
  5596. // } else {
  5597. // item:{
  5598. // $selected:true;
  5599. // }
  5600. // }
  5601. // });
  5602. })
  5603. // 点击勾选全部的复选框
  5604. $scope.checkAll = function() {
  5605. angular.forEach($scope.enters, function(item) {
  5606. item.distribute = $scope.checkboxes.checked;
  5607. });
  5608. };
  5609. // 点击其中一个明细的复选框
  5610. $scope.checkOne = function(vendor){
  5611. var result = true;
  5612. angular.forEach($scope.enters, function(item) {
  5613. if(item.distribute != true){
  5614. result = false;
  5615. return;
  5616. }
  5617. });
  5618. $scope.checkboxes.checked = result;
  5619. };
  5620. $scope.close = function(save) {
  5621. var chooseResult = [];
  5622. if(save) {
  5623. if(user.userUU) {
  5624. angular.forEach($scope.enters, function(item, i) {
  5625. // if(item.distribute) {
  5626. chooseResult.push(item);
  5627. // }
  5628. });
  5629. if(chooseResult.length > 0) {
  5630. $scope.loading = true;
  5631. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  5632. $scope.loading = false;
  5633. toaster.pop('success', '提示', '保存成功');
  5634. $modalInstance.close(false);
  5635. }, function(response){
  5636. $scope.loading = false;
  5637. toaster.pop('error', '保存失败', response.data);
  5638. $modalInstance.close(false);
  5639. })
  5640. } else {
  5641. toaster.pop('error', '保存失败', "您未勾选任何记录");
  5642. }
  5643. } else {
  5644. $modalInstance.close(true, $scope.checkboxes.checked);
  5645. }
  5646. } else {
  5647. $modalInstance.close(false);
  5648. }
  5649. };
  5650. }]);
  5651. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  5652. $scope.checked = [];
  5653. $scope.master = [];
  5654. AccountRole.query({}, function(data){
  5655. if(user && data) {
  5656. var rs = [], checked = [];
  5657. angular.forEach(user.roles, function(r){
  5658. rs.push(r.id);
  5659. });
  5660. angular.forEach(data, function(d){
  5661. if(rs.indexOf(d.id) > -1) {
  5662. d.$checked = true;
  5663. checked.push(d);
  5664. }
  5665. });
  5666. }
  5667. $scope.roles = data;
  5668. $scope.checked = checked;
  5669. $scope.master = angular.copy($scope.checked);
  5670. });
  5671. $scope.select = function(role) {
  5672. role.$checked = !role.$checked;
  5673. if(role.$checked) {
  5674. $scope.checked.push(role);
  5675. } else {
  5676. angular.forEach($scope.checked, function(c, i){
  5677. if(c.id == role.id)
  5678. $scope.checked.splice(i, 1);
  5679. });
  5680. }
  5681. };
  5682. $scope.isChanged = function() {
  5683. return !angular.equals($scope.master, $scope.checked);
  5684. };
  5685. $scope.close = function(save) {
  5686. if(save) {
  5687. if(user.userUU) {
  5688. user.roles = $scope.checked;
  5689. AccountUser.update({}, user, function(){
  5690. toaster.pop('success', '提示', '保存成功');
  5691. $modalInstance.close(true);
  5692. }, function(response){
  5693. toaster.pop('error', '保存失败', response.data);
  5694. });
  5695. } else {
  5696. $modalInstance.close(true, $scope.checked);
  5697. }
  5698. } else {
  5699. $modalInstance.close(false);
  5700. }
  5701. };
  5702. }]);
  5703. // 修改密码Controller
  5704. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5705. $scope.user = user;
  5706. $scope.checking = false;
  5707. //输入原密码后验证原密码是否正确
  5708. $scope.checkPassword = function(password) {
  5709. $scope.checking = true;
  5710. $scope.checkSuccess = false;
  5711. $scope.checkFailed = false;
  5712. AccountUser.checkPassword({password: password}, function(data){
  5713. $scope.checkSuccess = true;
  5714. $scope.checking = false;
  5715. $scope.checkFailed = false;
  5716. }, function(response){
  5717. $scope.checkFailed = true;
  5718. $scope.checking = false;
  5719. $scope.checkSuccess = false;
  5720. });
  5721. };
  5722. //修改密码
  5723. $scope.ok = function () {
  5724. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  5725. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  5726. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  5727. $scope.user.password = null;
  5728. $scope.user.newPassword = null;
  5729. $scope.user.newPassword1 = null;
  5730. $scope.checking = false;
  5731. $scope.checkSuccess = false;
  5732. $scope.checkFailed = false;
  5733. }, function(response){
  5734. toaster.pop('error', '错误', response.data);
  5735. });
  5736. } else {
  5737. toaster.pop('error', '错误', '重复密码不一致');
  5738. }
  5739. };
  5740. $scope.cancel = function () {
  5741. $modalInstance.dismiss();
  5742. };
  5743. }]);
  5744. /*
  5745. * 绑定用户到企业
  5746. */
  5747. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout){
  5748. $scope.searching = false;
  5749. //根据输入的内容查找用户
  5750. $scope.searchUser = function(keyWord) {
  5751. $scope.searching = true;
  5752. $scope.searchSuccess = false;
  5753. $scope.searchFailed = false;
  5754. $scope.illegalError = false;
  5755. $scope.reBindError = false;
  5756. $scope.bindSuccess = false;
  5757. $scope.okDisabled = false;
  5758. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  5759. $scope.searchSuccess = true;
  5760. $scope.searchFailed = false;
  5761. $scope.user = data; //查询到的用户
  5762. }, function(response){
  5763. $scope.searchSuccess = false;
  5764. $scope.searchFailed = true;
  5765. });
  5766. };
  5767. //确认绑定
  5768. $scope.ok = function (keyWord) {
  5769. AuthenticationService.getAuthentication().success(function(data) {
  5770. $scope.currentUser = data; //当前登录的用户(管理员)
  5771. //不可自己绑定自己
  5772. if($scope.currentUser.userUU == $scope.user.userUU){
  5773. $scope.illegalError = true;
  5774. $scope.okDisabled = true;
  5775. return false;
  5776. }
  5777. //用户未绑定到任何企业时
  5778. if(!$scope.user.enterprises){
  5779. //正常绑定
  5780. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  5781. $scope.bindSuccess = true; //绑定成功
  5782. $scope.okDisabled = true;
  5783. }, function(response){
  5784. });
  5785. return true;
  5786. }
  5787. //用户已绑定到某些企业时
  5788. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  5789. if($scope.currentUser.enterprises[i].current){
  5790. for(var j = 0; j < $scope.user.enterprises.length; j++){
  5791. //该用户已绑定到当前企业,不可重复绑定
  5792. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  5793. $scope.reBindError = true;
  5794. $scope.okDisabled = true;
  5795. return false;
  5796. }
  5797. }
  5798. //该用户未绑定到当前企业,可以进行绑定
  5799. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  5800. $scope.bindSuccess = true; //绑定成功
  5801. $scope.okDisabled = true;
  5802. }, function(response){
  5803. console.log("绑定失败!");
  5804. });
  5805. }
  5806. }
  5807. });
  5808. $timeout(function() {
  5809. $modalInstance.close(true);
  5810. }, 500);
  5811. };
  5812. $scope.cancel = function () {
  5813. $modalInstance.dismiss();
  5814. };
  5815. }]);
  5816. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  5817. $scope.erpParams = new ngTableParams({
  5818. page : 1,
  5819. count : 5,
  5820. sorting: {
  5821. time: 'desc'
  5822. }
  5823. }, {
  5824. total : 0,
  5825. counts: [5, 10, 25, 50],
  5826. getData : function($defer, params) {
  5827. $scope.loading = true;
  5828. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  5829. $scope.loading = false;
  5830. if(page) {
  5831. params.total(page.totalElements);
  5832. $defer.resolve(page.content);
  5833. }
  5834. }, function(response){
  5835. $scope.loading = false;
  5836. toaster.pop('error', '数据加载失败', response.data);
  5837. });
  5838. }
  5839. });
  5840. $scope.usageParams = new ngTableParams({
  5841. page : 1,
  5842. count : 5,
  5843. sorting: {
  5844. time: 'desc'
  5845. }
  5846. }, {
  5847. total : 0,
  5848. counts: [5, 10, 25, 50],
  5849. getData : function($defer, params) {
  5850. $scope.loading = true;
  5851. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  5852. $scope.loading = false;
  5853. if(page) {
  5854. params.total(page.totalElements);
  5855. $defer.resolve(page.content);
  5856. }
  5857. }, function(response){
  5858. $scope.loading = false;
  5859. toaster.pop('error', '数据加载失败', response.data);
  5860. });
  5861. }
  5862. });
  5863. }]);
  5864. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  5865. AccountResource.query({}, function(data){
  5866. if(data && data.length > 0) {
  5867. data[0].$open = true;
  5868. }
  5869. $scope.resources = data;
  5870. });
  5871. }]);
  5872. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  5873. $scope.roles = {};
  5874. var getData = function() {
  5875. AccountRole.query({}, function(data){
  5876. var defaults = [], custom = [];
  5877. angular.forEach(data, function(d){
  5878. if(d.isdefault == 1)
  5879. defaults.push(d);
  5880. else
  5881. custom.push(d);
  5882. });
  5883. $scope.roles = {defaults: defaults, custom: custom};
  5884. });
  5885. };
  5886. getData();
  5887. $scope.editRole = function(role){
  5888. var modalInstance = $modal.open({
  5889. animation: true,
  5890. templateUrl: 'static/tpl/index/account/role_detail.html',
  5891. controller: 'RoleEditCtrl',
  5892. resolve: {
  5893. role: function() {
  5894. return role;
  5895. }
  5896. }
  5897. });
  5898. modalInstance.result.then(function(added){
  5899. added && (getData());
  5900. });
  5901. };
  5902. }]);
  5903. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
  5904. $scope.role = role;
  5905. $scope.master = angular.copy($scope.role);
  5906. var isNew = role == null;
  5907. $scope.cancel = function() {
  5908. $modalInstance.close(false);
  5909. };
  5910. AccountResource.query({}, function(data){
  5911. if(data && data.length > 0) {
  5912. if(role && role.resourceItems) {
  5913. var rs = [];// 已分配的资源的id
  5914. angular.forEach(role.resourceItems, function(item){
  5915. rs.push(item.id);
  5916. });
  5917. angular.forEach(data, function(resource){
  5918. var c = 0;
  5919. angular.forEach(resource.items, function(item){
  5920. if(rs.indexOf(item.id) > -1) {
  5921. item.$checked = true;
  5922. c += 1;
  5923. }
  5924. });
  5925. resource.$checked = c == resource.items.length;
  5926. });
  5927. }
  5928. $scope.resourceItems = data[0].items;
  5929. data[0].$active = true;
  5930. }
  5931. $scope.resources = data;
  5932. $timeout(function(){
  5933. angular.forEach($scope.resources, function(resource){
  5934. var c = 0;
  5935. angular.forEach(resource.items, function(item){
  5936. item.$checked && (c+=1);
  5937. });
  5938. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5939. });
  5940. }, 100);
  5941. });
  5942. $scope.onItemClick = function(resource) {
  5943. $scope.resourceItems = resource.items;
  5944. angular.forEach($scope.resources, function(r){
  5945. r.$active = false;
  5946. });
  5947. resource.$active = true;
  5948. };
  5949. var getChecked = function() {
  5950. var items = [];
  5951. angular.forEach($scope.resources, function(resource){
  5952. angular.forEach(resource.items, function(item){
  5953. item.$checked && (items.push(item));
  5954. });
  5955. });
  5956. $scope.role.resourceItems = items;
  5957. };
  5958. $scope.onResourceChange = function(resource) {
  5959. angular.forEach(resource.items, function(item){
  5960. item.$checked = resource.$checked;
  5961. });
  5962. getChecked();
  5963. };
  5964. $scope.onItemChange = function() {
  5965. angular.forEach($scope.resources, function(resource){
  5966. if(resource.$active) {
  5967. var c = 0;
  5968. angular.forEach(resource.items, function(item){
  5969. item.$checked && (c+=1);
  5970. });
  5971. resource.$checked = (c == resource.items.length);
  5972. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5973. }
  5974. });
  5975. getChecked();
  5976. };
  5977. $scope.isChanged = function(formData) {
  5978. if(!$scope.master)
  5979. return true;
  5980. return !angular.equals(formData, $scope.master);
  5981. };
  5982. $scope.save = function() {
  5983. $scope.master = angular.copy($scope.role);
  5984. AccountRole.save($scope.master, function(){
  5985. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  5986. $modalInstance.close(true);
  5987. }, function(response){
  5988. toaster.pop('error', '错误', response.data);
  5989. });
  5990. };
  5991. $scope.del = function() {
  5992. new ngAlert({
  5993. title: '提示',
  5994. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  5995. }, function(){
  5996. AccountRole.remove({id: role.id}, function(){
  5997. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  5998. $modalInstance.close(true);
  5999. }, function(response){
  6000. toaster.pop('error', '错误', response.data);
  6001. });
  6002. })
  6003. };
  6004. }]);
  6005. /**
  6006. * 委外订单
  6007. */
  6008. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  6009. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  6010. $scope.active = 'todo';
  6011. $scope.dateZoneText = '不限';
  6012. $scope.condition = {dateZone: -1};
  6013. $scope.changeDateZone = function(zone) {
  6014. $scope.condition.dateZone = zone;
  6015. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6016. $scope.condition.$dateZoneOpen = false;
  6017. getDateCondition(zone, $scope.condition);
  6018. $scope.tableParams.reload();
  6019. };
  6020. $scope.setActive = function(state) {
  6021. if($scope.active != state) {
  6022. $scope.active = state;
  6023. if($scope.tableParams.page() == 1)
  6024. $scope.tableParams.reload();
  6025. else
  6026. $scope.tableParams.page(1);
  6027. }
  6028. };
  6029. var getService = function() {
  6030. return MakeOrder;
  6031. };
  6032. $scope.tableParams = new ngTableParams({
  6033. page : 1,
  6034. count : 5,
  6035. sorting: {
  6036. date: 'desc'
  6037. }
  6038. }, {
  6039. total : 0,
  6040. counts: [5, 10, 25, 50],
  6041. getData : function($defer, params) {
  6042. $scope.loading = true;
  6043. var pageParams = params.url();
  6044. pageParams.searchFilter = {};
  6045. pageParams.searchFilter.keyword = $scope.keyword;
  6046. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6047. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6048. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6049. $scope.loading = false;
  6050. if(page) {
  6051. params.total(page.totalElement);
  6052. $defer.resolve(page.content);
  6053. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6054. }
  6055. }, function(response){
  6056. $scope.loading = false;
  6057. toaster.pop('error', '数据加载失败', response.data);
  6058. });
  6059. }
  6060. });
  6061. $scope.getOrderTotal = function(items) {
  6062. var sum = 0;
  6063. angular.forEach(items, function(item){
  6064. sum += item.qty * item.price;
  6065. });
  6066. return sum;
  6067. };
  6068. $scope.openDatePicker = function($event, item, openParam) {
  6069. $event.preventDefault();
  6070. $event.stopPropagation();
  6071. item[openParam] = !item[openParam];
  6072. };
  6073. $scope.parseDate = function(dateStr) {
  6074. if(dateStr)
  6075. return Date.parse(dateStr, 'yyyy-MM-dd');
  6076. return new Date();
  6077. };
  6078. // 打开回复
  6079. $scope.openReply = function(order) {
  6080. if(!order.reply) {
  6081. order.reply = {
  6082. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6083. delivery: order.delivery
  6084. }
  6085. }
  6086. order.$editing = true;
  6087. };
  6088. // 关闭回复
  6089. $scope.closeReply = function(order) {
  6090. order.$editing = false;
  6091. }
  6092. // 搜索框回车
  6093. $scope.onSearch = function() {
  6094. $scope.tableParams.page(1);
  6095. $scope.tableParams.reload();
  6096. };
  6097. // 选择查找日期
  6098. $scope.onDateCondition = function(){
  6099. $scope.tableParams.page(1);
  6100. $scope.tableParams.reload();
  6101. };
  6102. // 点击回复
  6103. $scope.onReplyClick = function(order, inverse) {
  6104. if(order.reply) {
  6105. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6106. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6107. return;
  6108. }
  6109. var reply = angular.copy(order.reply);
  6110. if(reply.delivery) {
  6111. if(typeof reply.delivery == 'object')
  6112. reply.delivery = reply.delivery.getTime();
  6113. } else {
  6114. reply.delivery = order.delivery;
  6115. }
  6116. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6117. $scope.loading = true;
  6118. MakeOrder.reply({orderId: order.id}, reply, function(){
  6119. $scope.loading = false;
  6120. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6121. $scope.tableParams.reload();
  6122. }, function(response){
  6123. $scope.loading = false;
  6124. toaster.pop('error', '回复失败', response.data);
  6125. });
  6126. }
  6127. };
  6128. //委外加工单
  6129. $scope.print = function(order) {
  6130. MakeOrder.printCount({id: order.id},{});//增加打印此次
  6131. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  6132. };
  6133. // 获取回复记录
  6134. $scope.getReply = function(order) {
  6135. if(!order.replies) {
  6136. MakeOrder.getReply({orderId: order.id}, function(replies){
  6137. order.replies = replies;
  6138. });
  6139. }
  6140. };
  6141. }]);
  6142. /**
  6143. * 委外加工单详细
  6144. */
  6145. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOrder, toaster, ReportService){
  6146. var loadData = function() {
  6147. MakeOrder.get({id: $stateParams.id}, function(data){
  6148. $scope.order = data;
  6149. var sum = $scope.order.qty * $scope.order.price;
  6150. $scope.order.total = sum;
  6151. $scope.loading = false;
  6152. });
  6153. };
  6154. loadData();
  6155. // 获取回复记录
  6156. $scope.getReply = function(item) {
  6157. if(!item.replies) {
  6158. MakeOrder.getReply({orderId: item.id}, function(replies){
  6159. item.replies = replies;
  6160. });
  6161. }
  6162. };
  6163. $scope.openDatePicker = function($event, item, openParam) {
  6164. $event.preventDefault();
  6165. $event.stopPropagation();
  6166. item[openParam] = !item[openParam];
  6167. };
  6168. // 点击回复
  6169. $scope.onReplyClick = function(order, inverse) {
  6170. if(order.reply) {
  6171. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6172. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6173. return;
  6174. }
  6175. var reply = angular.copy(order.reply);
  6176. if(reply.delivery) {
  6177. if(typeof reply.delivery == 'object')
  6178. reply.delivery = reply.delivery.getTime();
  6179. } else {
  6180. reply.delivery = order.delivery;
  6181. }
  6182. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6183. $scope.loading = true;
  6184. MakeOrder.reply({orderId: order.id}, reply, function(){
  6185. $scope.loading = false;
  6186. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6187. loadData();
  6188. }, function(response){
  6189. $scope.loading = false;
  6190. toaster.pop('error', '回复失败', response.data);
  6191. });
  6192. }
  6193. };
  6194. // 打开回复
  6195. $scope.openReply = function(order) {
  6196. if(!order.reply) {
  6197. order.reply = {
  6198. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6199. delivery: order.delivery
  6200. }
  6201. }
  6202. order.$editing = true;
  6203. };
  6204. // 关闭回复
  6205. $scope.closeReply = function(order) {
  6206. order.$editing = false;
  6207. }
  6208. // 委外订单
  6209. $scope.print = function(order) {
  6210. MakeOrder.printCount({id: order.id},{});//增加打印此次
  6211. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  6212. };
  6213. }]);
  6214. /**
  6215. * 客户委外验收
  6216. */
  6217. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  6218. $scope.active = 'all';
  6219. $scope.agreedText = '全部';
  6220. $scope.dateZoneText = '一个月内';
  6221. $scope.condition = {dateZone: 1};
  6222. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6223. $scope.changeAgreed = function(agreed) {
  6224. $scope.condition.agreed = agreed;
  6225. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6226. $scope.condition.$agreedOpen = false;
  6227. };
  6228. $scope.changeDateZone = function(zone) {
  6229. $scope.condition.dateZone = zone;
  6230. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6231. $scope.condition.$dateZoneOpen = false;
  6232. getDateCondition(zone, $scope.condition);
  6233. $scope.tableParams.reload();
  6234. };
  6235. $scope.setActive = function(state) {
  6236. if($scope.active != state) {
  6237. $scope.active = state;
  6238. if($scope.tableParams.page() == 1)
  6239. $scope.tableParams.reload();
  6240. else
  6241. $scope.tableParams.page(1);
  6242. }
  6243. };
  6244. var getService = function() {
  6245. return MakeAccept;
  6246. };
  6247. $scope.tableParams = new ngTableParams({
  6248. page : 1,
  6249. count : 5,
  6250. sorting: {
  6251. date: 'desc'
  6252. }
  6253. }, {
  6254. total : 0,
  6255. counts: [5, 10, 25, 50],
  6256. getData : function($defer, params) {
  6257. $scope.loading = true;
  6258. var pageParams = params.url();
  6259. pageParams.searchFilter = {};
  6260. pageParams.searchFilter.keyword = $scope.keyword;
  6261. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6262. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6263. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6264. $scope.loading = false;
  6265. if(page) {
  6266. params.total(page.totalElement);
  6267. $defer.resolve(page.content);
  6268. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6269. }
  6270. }, function(response){
  6271. $scope.loading = false;
  6272. toaster.pop('error', '数据加载失败', response.data);
  6273. });
  6274. }
  6275. });
  6276. $scope.openDatePicker = function($event, item, openParam) {
  6277. $event.preventDefault();
  6278. $event.stopPropagation();
  6279. item[openParam] = !item[openParam];
  6280. };
  6281. // 搜索框回车
  6282. $scope.onSearch = function() {
  6283. $scope.tableParams.page(1);
  6284. $scope.tableParams.reload();
  6285. };
  6286. // 选择查找日期
  6287. $scope.onDateCondition = function(){
  6288. $scope.tableParams.page(1);
  6289. $scope.tableParams.reload();
  6290. };
  6291. }]);
  6292. /**
  6293. * 客户委外验退
  6294. */
  6295. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  6296. $scope.active = 'all';
  6297. $scope.agreedText = '全部';
  6298. $scope.dateZoneText = '一个月内';
  6299. $scope.condition = {dateZone: 1};
  6300. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6301. $scope.changeAgreed = function(agreed) {
  6302. $scope.condition.agreed = agreed;
  6303. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6304. $scope.condition.$agreedOpen = false;
  6305. };
  6306. $scope.changeDateZone = function(zone) {
  6307. $scope.condition.dateZone = zone;
  6308. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6309. $scope.condition.$dateZoneOpen = false;
  6310. getDateCondition(zone, $scope.condition);
  6311. $scope.tableParams.reload();
  6312. };
  6313. $scope.setActive = function(state) {
  6314. if($scope.active != state) {
  6315. $scope.active = state;
  6316. if($scope.tableParams.page() == 1)
  6317. $scope.tableParams.reload();
  6318. else
  6319. $scope.tableParams.page(1);
  6320. }
  6321. };
  6322. var getService = function() {
  6323. return MakeReturn;
  6324. };
  6325. $scope.tableParams = new ngTableParams({
  6326. page : 1,
  6327. count : 5,
  6328. sorting: {
  6329. date: 'desc'
  6330. }
  6331. }, {
  6332. total : 0,
  6333. counts: [5, 10, 25, 50],
  6334. getData : function($defer, params) {
  6335. $scope.loading = true;
  6336. var pageParams = params.url();
  6337. pageParams.searchFilter = {};
  6338. pageParams.searchFilter.keyword = $scope.keyword;
  6339. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6340. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6341. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6342. $scope.loading = false;
  6343. if(page) {
  6344. params.total(page.totalElement);
  6345. $defer.resolve(page.content);
  6346. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6347. }
  6348. }, function(response){
  6349. $scope.loading = false;
  6350. toaster.pop('error', '数据加载失败', response.data);
  6351. });
  6352. }
  6353. });
  6354. $scope.openDatePicker = function($event, item, openParam) {
  6355. $event.preventDefault();
  6356. $event.stopPropagation();
  6357. item[openParam] = !item[openParam];
  6358. };
  6359. // 搜索框回车
  6360. $scope.onSearch = function() {
  6361. $scope.tableParams.page(1);
  6362. $scope.tableParams.reload();
  6363. };
  6364. // 选择查找日期
  6365. $scope.onDateCondition = function(){
  6366. $scope.tableParams.page(1);
  6367. $scope.tableParams.reload();
  6368. };
  6369. }]);
  6370. /**
  6371. * 委外加工变更
  6372. */
  6373. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  6374. $scope.active = 'all';
  6375. $scope.agreedText = '全部';
  6376. $scope.dateZoneText = '一个月内';
  6377. $scope.condition = {dateZone: 1};
  6378. $scope.changeAgreed = function(agreed) {
  6379. $scope.condition.agreed = agreed;
  6380. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6381. $scope.condition.$agreedOpen = false;
  6382. };
  6383. $scope.changeDateZone = function(zone) {
  6384. $scope.condition.dateZone = zone;
  6385. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6386. $scope.condition.$dateZoneOpen = false;
  6387. getDateCondition(zone, $scope.condition);
  6388. $scope.tableParams.reload();
  6389. };
  6390. $scope.setActive = function(state) {
  6391. if($scope.active != state) {
  6392. $scope.active = state;
  6393. if($scope.tableParams.page() == 1)
  6394. $scope.tableParams.reload();
  6395. else
  6396. $scope.tableParams.page(1);
  6397. }
  6398. };
  6399. var getService = function() {
  6400. return MakeChange;
  6401. };
  6402. $scope.tableParams = new ngTableParams({
  6403. page : 1,
  6404. count : 5,
  6405. sorting: {
  6406. orderChangeDate: 'desc'
  6407. }
  6408. }, {
  6409. total : 0,
  6410. counts: [5, 10, 25, 50],
  6411. getData : function($defer, params) {
  6412. $scope.loading = true;
  6413. var pageParams = params.url();
  6414. pageParams.searchFilter = {};
  6415. pageParams.searchFilter.keyword = $scope.keyword;
  6416. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6417. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6418. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6419. $scope.loading = false;
  6420. if(page) {
  6421. params.total(page.totalElement);
  6422. $defer.resolve(page.content);
  6423. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6424. }
  6425. }, function(response){
  6426. $scope.loading = false;
  6427. toaster.pop('error', '数据加载失败', response.data);
  6428. });
  6429. }
  6430. });
  6431. $scope.openDatePicker = function($event, item, openParam) {
  6432. $event.preventDefault();
  6433. $event.stopPropagation();
  6434. item[openParam] = !item[openParam];
  6435. };
  6436. // 打开回复
  6437. $scope.openReply = function(change) {
  6438. change.$editing = true;
  6439. };
  6440. // 关闭回复
  6441. $scope.closeReply = function(change) {
  6442. change.$editing = false;
  6443. }
  6444. // 确定回复
  6445. $scope.onReplyClick = function(change) {
  6446. if(change.$agreed) {
  6447. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6448. $scope.loading = true;
  6449. MakeChange.reply({itemId: change.id}, reply, function(){
  6450. $scope.loading = false;
  6451. toaster.pop('info', '提示', '回复成功');
  6452. $scope.tableParams.reload();
  6453. }, function(response){
  6454. $scope.loading = false;
  6455. toaster.pop('error', '回复失败', response.data);
  6456. });
  6457. }
  6458. };
  6459. // 搜索框回车
  6460. $scope.onSearch = function() {
  6461. $scope.tableParams.page(1);
  6462. $scope.tableParams.reload();
  6463. };
  6464. // 选择查找日期
  6465. $scope.onDateCondition = function(){
  6466. $scope.tableParams.page(1);
  6467. $scope.tableParams.reload();
  6468. };
  6469. }]);
  6470. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', function($scope, $stateParams, MakeChange, toaster){
  6471. var loadData = function() {
  6472. MakeChange.get({id: $stateParams.id}, function(data){
  6473. $scope.change = data;
  6474. });
  6475. };
  6476. loadData();
  6477. $scope.openDatePicker = function($event, item, openParam) {
  6478. $event.preventDefault();
  6479. $event.stopPropagation();
  6480. item[openParam] = !item[openParam];
  6481. };
  6482. $scope.onReplyClick = function(change) {
  6483. if(change.$agreed) {
  6484. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6485. MakeChange.reply({itemId: change.id}, reply, function(){
  6486. toaster.pop('info', '提示', '回复成功');
  6487. loadData();
  6488. }, function(response){
  6489. toaster.pop('error', '回复失败', response.data);
  6490. });
  6491. }
  6492. };
  6493. }]);
  6494. /**
  6495. * 委外加工
  6496. */
  6497. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  6498. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  6499. $scope.active = 'all';
  6500. $scope.agreedText = '全部';
  6501. $scope.dateZoneText = '一个月内';
  6502. $scope.condition = {dateZone: 1};
  6503. $scope.changeAgreed = function(agreed) {
  6504. $scope.condition.agreed = agreed;
  6505. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6506. $scope.condition.$agreedOpen = false;
  6507. };
  6508. $scope.changeDateZone = function(zone) {
  6509. $scope.condition.dateZone = zone;
  6510. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6511. $scope.condition.$dateZoneOpen = false;
  6512. getDateCondition(zone, $scope.condition);
  6513. $scope.tableParams.reload();
  6514. };
  6515. $scope.setActive = function(state) {
  6516. if($scope.active != state) {
  6517. $scope.active = state;
  6518. if($scope.tableParams.page() == 1)
  6519. $scope.tableParams.reload();
  6520. else
  6521. $scope.tableParams.page(1);
  6522. }
  6523. };
  6524. var getService = function() {
  6525. return MakeOutOrder;
  6526. };
  6527. $scope.tableParams = new ngTableParams({
  6528. page : 1,
  6529. count : 5,
  6530. sorting: {
  6531. date: 'desc'
  6532. }
  6533. }, {
  6534. total : 0,
  6535. counts: [5, 10, 25, 50],
  6536. getData : function($defer, params) {
  6537. $scope.loading = true;
  6538. var pageParams = params.url();
  6539. pageParams.searchFilter = {};
  6540. pageParams.searchFilter.keyword = $scope.keyword;
  6541. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6542. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6543. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6544. $scope.loading = false;
  6545. if(page) {
  6546. params.total(page.totalElement);
  6547. $defer.resolve(page.content);
  6548. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6549. }
  6550. }, function(response){
  6551. $scope.loading = false;
  6552. toaster.pop('error', '数据加载失败', response.data);
  6553. });
  6554. }
  6555. });
  6556. $scope.openDatePicker = function($event, item, openParam) {
  6557. $event.preventDefault();
  6558. $event.stopPropagation();
  6559. item[openParam] = !item[openParam];
  6560. };
  6561. // 打开回复
  6562. $scope.openReply = function(change) {
  6563. change.$editing = true;
  6564. };
  6565. // 关闭回复
  6566. $scope.closeReply = function(change) {
  6567. change.$editing = false;
  6568. }
  6569. // 确定回复
  6570. $scope.onReplyClick = function(change) {
  6571. if(change.$agreed) {
  6572. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6573. $scope.loading = true;
  6574. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  6575. $scope.loading = false;
  6576. toaster.pop('info', '提示', '回复成功');
  6577. $scope.tableParams.reload();
  6578. }, function(response){
  6579. $scope.loading = false;
  6580. toaster.pop('error', '回复失败', response.data);
  6581. });
  6582. }
  6583. };
  6584. // 搜索框回车
  6585. $scope.onSearch = function() {
  6586. $scope.tableParams.page(1);
  6587. $scope.tableParams.reload();
  6588. };
  6589. // 选择查找日期
  6590. $scope.onDateCondition = function(){
  6591. $scope.tableParams.page(1);
  6592. $scope.tableParams.reload();
  6593. };
  6594. }]);
  6595. /**
  6596. * 委外加工详细
  6597. */
  6598. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService) {
  6599. var loadData = function() {
  6600. MakeOutOrder.get({id: $stateParams.id}, function(data){
  6601. $scope.order = data;
  6602. var sum = $scope.order.qty * $scope.order.price;
  6603. $scope.order.total = sum;
  6604. $scope.loading = false;
  6605. });
  6606. };
  6607. loadData();
  6608. // 获取回复记录
  6609. $scope.getReply = function(item) {
  6610. if(!item.replies) {
  6611. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  6612. item.replies = replies;
  6613. });
  6614. }
  6615. };
  6616. $scope.openDatePicker = function($event, item, openParam) {
  6617. $event.preventDefault();
  6618. $event.stopPropagation();
  6619. item[openParam] = !item[openParam];
  6620. };
  6621. // 点击回复
  6622. $scope.onReplyClick = function(order, inverse) {
  6623. if(order.reply) {
  6624. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6625. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6626. return;
  6627. }
  6628. var reply = angular.copy(order.reply);
  6629. if(reply.delivery) {
  6630. if(typeof reply.delivery == 'object')
  6631. reply.delivery = reply.delivery.getTime();
  6632. } else {
  6633. reply.delivery = order.delivery;
  6634. }
  6635. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6636. $scope.loading = true;
  6637. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  6638. $scope.loading = false;
  6639. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6640. loadData();
  6641. }, function(response){
  6642. $scope.loading = false;
  6643. toaster.pop('error', '回复失败', response.data);
  6644. });
  6645. }
  6646. };
  6647. // 打开回复
  6648. $scope.openReply = function(order) {
  6649. if(!order.reply) {
  6650. order.reply = {
  6651. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6652. delivery: order.delivery
  6653. }
  6654. }
  6655. order.$editing = true;
  6656. };
  6657. // 关闭回复
  6658. $scope.closeReply = function(order) {
  6659. order.$editing = false;
  6660. }
  6661. // 自己委外加工订单
  6662. $scope.print = function(order) {
  6663. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  6664. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  6665. };
  6666. }]);
  6667. /**
  6668. * 计算时间差
  6669. */
  6670. app.filter('timespan', function(){
  6671. return function(time) {
  6672. if(time == null)
  6673. return '9999年';
  6674. var now = new Date().getTime(), span = time - now,
  6675. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  6676. m = Math.ceil(span/60000);
  6677. if(span < 0)
  6678. return '0天';
  6679. if(d > 0)
  6680. return d + '天';
  6681. if(h > 0)
  6682. return h + '小时';
  6683. if(m > 0)
  6684. return m + '分钟';
  6685. return '0天';
  6686. };
  6687. });
  6688. app.filter('firstchar', function(){
  6689. return function(str) {
  6690. if(str == null)
  6691. return null;
  6692. return str.substring(0, 1);
  6693. };
  6694. });
  6695. /**
  6696. * 搜索框,回车触发
  6697. */
  6698. app.directive('ngSearch', ['$parse', function($parse) {
  6699. return {
  6700. require : '?ngModel',
  6701. restrict : 'A',
  6702. link : function(scope, element, attrs, ngModel) {
  6703. var searchFn = $parse(attrs.ngSearch);
  6704. element.bind('keypress', function(event) {
  6705. if (event.keyCode == '13') {
  6706. event.preventDefault();
  6707. event.stopPropagation();
  6708. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  6709. }
  6710. });
  6711. }
  6712. };
  6713. }]);
  6714. /**
  6715. * 状态码 -> 描述
  6716. */
  6717. app.filter('status', function(){
  6718. return function(data) {
  6719. var statusConfig = {
  6720. '101': '已提交',
  6721. '102': '已审核',
  6722. '103': '未通过',
  6723. '200': '未回复',
  6724. '201': '已回复',
  6725. '313': '已激活',
  6726. '316': '已过账',
  6727. '311': '申请中',
  6728. '312': '未激活'
  6729. };
  6730. return statusConfig[data];
  6731. }
  6732. });
  6733. //弹出问题反馈模态框
  6734. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  6735. //获取当前用户
  6736. AuthenticationService.getAuthentication().success(function(data) {
  6737. $scope.user = data;
  6738. });
  6739. $scope.showModal = function(){
  6740. var modalInstance = $modal.open({
  6741. animation: true,
  6742. templateUrl: 'static/tpl/serve/feedback.html',
  6743. controller: 'FeedbackCtrl',
  6744. resolve: {
  6745. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  6746. }
  6747. });
  6748. modalInstance.result.then(function(){
  6749. }, function(){
  6750. })
  6751. }
  6752. }]);
  6753. /*
  6754. * 提交我的反馈
  6755. */
  6756. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  6757. $scope.isPublic = 1; //默认公开
  6758. $scope.classId = 1; //默认类别
  6759. $scope.user = user;
  6760. $scope.ok = function(){
  6761. if(!$scope.user){ //用户未登录
  6762. $scope.uu = null;
  6763. }else{ //用户已登录
  6764. $scope.uu = $scope.user.userUU;
  6765. }
  6766. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  6767. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  6768. function(data){
  6769. toaster.pop('success', '成功', '您的问题反馈成功!');
  6770. $scope.cancel();
  6771. }, function(response){
  6772. toaster.pop('error', '错误', response.data);
  6773. });
  6774. }
  6775. $scope.cancel = function () {
  6776. $modalInstance.dismiss();
  6777. };
  6778. }]);
  6779. //“我的问题反馈”跳转控制
  6780. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  6781. $scope.myFeedback = function(){
  6782. AuthenticationService.getAuthentication().success(function(data){
  6783. $scope.user = data;
  6784. if(!$scope.user){
  6785. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  6786. return false;
  6787. }else{
  6788. window.location.href = "./serve#/question/myFeedback";
  6789. }
  6790. });
  6791. }
  6792. }]);
  6793. //客户服务
  6794. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  6795. Vendor.getServe(function(datas){
  6796. $scope.vendors = datas;
  6797. console.log($scope.Vender);
  6798. // 自动跳转
  6799. if(datas && datas.length == 1)
  6800. $scope.redirect(datas[0]);
  6801. });
  6802. $scope.redirect = function(vendor) {
  6803. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  6804. };
  6805. }]);
  6806. /**
  6807. * 物料资料
  6808. */
  6809. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  6810. $scope.active = 'all';
  6811. $scope.agreedText = '全部';
  6812. $scope.dateZoneText = '一个月内';
  6813. $scope.condition = {dateZone: 1};
  6814. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6815. $scope.changeAgreed = function(agreed) {
  6816. $scope.condition.agreed = agreed;
  6817. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6818. $scope.condition.$agreedOpen = false;
  6819. };
  6820. $scope.changeDateZone = function(zone) {
  6821. $scope.condition.dateZone = zone;
  6822. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6823. $scope.condition.$dateZoneOpen = false;
  6824. getDateCondition(zone, $scope.condition);
  6825. $scope.tableParams.reload();
  6826. };
  6827. $scope.setActive = function(state) {
  6828. if($scope.active != state) {
  6829. $scope.active = state;
  6830. if($scope.tableParams.page() == 1)
  6831. $scope.tableParams.reload();
  6832. else
  6833. $scope.tableParams.page(1);
  6834. }
  6835. };
  6836. var getService = function() {
  6837. return GetProductInfo;
  6838. };
  6839. $scope.tableParams = new ngTableParams({
  6840. page : 1,
  6841. count : 5,
  6842. sorting: {
  6843. }
  6844. }, {
  6845. total : 0,
  6846. counts: [5, 10, 25, 50],
  6847. getData : function($defer, params) {
  6848. $scope.loading = true;
  6849. var pageParams = params.url();
  6850. pageParams.keyword = $scope.keyword;
  6851. pageParams.searchFilter = $scope.searchFilter;
  6852. console.log(pageParams.searchFilter);
  6853. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6854. $scope.loading = false;
  6855. if(page) {
  6856. params.total(page.totalElement);
  6857. $defer.resolve(page.content);
  6858. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  6859. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  6860. }
  6861. }, function(response) {
  6862. $scope.loading = false;
  6863. toaster.pop('error', '数据加载失败', response.data);
  6864. });
  6865. }
  6866. });
  6867. // 搜索框回车
  6868. $scope.onSearch = function() {
  6869. $scope.tableParams.page(1);
  6870. $scope.tableParams.reload();
  6871. };
  6872. //删除
  6873. $scope.deleteById = function(id) {
  6874. GetProductInfo.deleteById({id: id}, function(data) {
  6875. toaster.pop("success", "提示", "删除成功");
  6876. $timeout(function() {
  6877. window.location.reload();
  6878. }, 500);
  6879. }), function(response) {
  6880. toaster.pop("error", "删除失败", response.data);
  6881. };
  6882. }
  6883. }]);
  6884. /**
  6885. * 物料批量上传
  6886. */
  6887. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', function($scope, $upload, toaster) {
  6888. // 通过excel批量上传物料
  6889. $scope.upload = function() {
  6890. var file = $scope.myFiles[0];
  6891. $upload.upload({
  6892. url: 'product/baseInfo/release/excel',
  6893. file: file,
  6894. method: 'POST'
  6895. }).success(function(data) {
  6896. $scope.result = data;
  6897. $scope.success = $scope.result.success;
  6898. $scope.total = $scope.result.total;
  6899. $scope.alters = $scope.result.alters;
  6900. }).error(function(response) {
  6901. toaster.pop('error', response.data || response);
  6902. });
  6903. };
  6904. // 查看范例
  6905. $scope.showImg = function() {
  6906. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  6907. box.show();
  6908. box.find('img').attr('src', src);
  6909. box.find('a').click(function(){
  6910. box.hide();
  6911. });
  6912. box.dblclick(function(){
  6913. box.hide();
  6914. });
  6915. };
  6916. // 下载模板
  6917. $scope.download = function() {
  6918. window.location.href = 'product/baseInfo/upload/template';
  6919. };
  6920. }]);
  6921. /**
  6922. * 物料详情
  6923. */
  6924. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster) {
  6925. var loadData = function() {
  6926. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  6927. if(data.attach) {
  6928. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  6929. console.log(data.url);
  6930. // 查看范例
  6931. $scope.showImg = function() {
  6932. var src = data.url, box = $('#image-box');
  6933. box.show();
  6934. box.find('img').attr('src', src);
  6935. box.find('a').click(function(){
  6936. box.hide();
  6937. });
  6938. box.dblclick(function(){
  6939. box.hide();
  6940. });
  6941. };
  6942. })
  6943. }
  6944. $scope.prodInfo = data;
  6945. $scope.prodInfo.$editing = false;
  6946. $scope.loading = false;
  6947. });
  6948. };
  6949. loadData();
  6950. // 更新
  6951. $scope.update = function() {
  6952. $scope.prodInfo.$editing = true;
  6953. };
  6954. // 取消
  6955. $scope.cancel = function() {
  6956. $scope.prodInfo.$editing = false;
  6957. };
  6958. $scope.submit = function(prodInfo) {
  6959. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  6960. console.log(file);
  6961. $upload.upload({
  6962. url: 'product/baseInfo/updateProdInfo',
  6963. file: file,
  6964. method: 'POST',
  6965. data: {
  6966. prodInfo: $scope.prodInfo
  6967. },
  6968. }).success(function(data) {
  6969. if(data.success) {
  6970. toaster.pop('success', '提示', data.success);
  6971. window.location.reload();
  6972. }
  6973. if(data.error) {
  6974. toaster.pop('error', '提示', data.error);
  6975. }
  6976. }).error(function(data) {
  6977. $scope.loadingShow = false;
  6978. toaster.pop('error', '操作失败', data.error);
  6979. });
  6980. }
  6981. $scope.previewShow = false;
  6982. $scope.pdfShow = false;
  6983. $scope.noneFileShow = true;
  6984. $scope.$watch('myFiles', function(){
  6985. if($scope.myFiles) {
  6986. $scope.noneFileShow = false;
  6987. var file = $scope.myFiles[0];
  6988. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  6989. $scope.pdfShow = true;
  6990. $scope.previewShow = false;
  6991. $scope.imgPreviewName = file.name;
  6992. } else{
  6993. if (typeof(Worker) !== "undefined") {//支持HTML5
  6994. $scope.imgPreview = getObjectURL(file);
  6995. $scope.imgPreviewName = file.name;
  6996. } else{//不支持HTML5
  6997. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  6998. $scope.imgPreviewName = file.name;
  6999. }
  7000. $scope.previewShow = true;
  7001. $scope.pdfShow = false;
  7002. }
  7003. } else {
  7004. $scope.noneFileShow = true;
  7005. $scope.previewShow = false;
  7006. $scope.pdfShow = false;
  7007. }
  7008. });
  7009. //建立一个可存取到该file的url
  7010. var getObjectURL = function(file) {
  7011. var url = null ;
  7012. if (window.createObjectURL!=undefined) { // basic
  7013. url = window.createObjectURL(file) ;
  7014. } else if (window.URL!=undefined) { // mozilla(firefox)
  7015. url = window.URL.createObjectURL(file) ;
  7016. } else if (window.webkitURL!=undefined) { // webkit or chrome
  7017. url = window.webkitURL.createObjectURL(file) ;
  7018. }
  7019. return url ;
  7020. };
  7021. }]);
  7022. /**
  7023. * 新增物料
  7024. */
  7025. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout) {
  7026. $scope.prodInfo = {unit: 'PCS'};
  7027. // 选择类目
  7028. $scope.selectKind = function(uuids) {
  7029. $modal.open({
  7030. animation: true,
  7031. size: 'lg',
  7032. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  7033. controller: 'KindChooseCtrl',
  7034. }).result.then(function(data){
  7035. $scope.kindId = data;
  7036. var modalInstance = $modal.open({
  7037. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  7038. controller: 'FindComponentCtrl',
  7039. size: 'lg',
  7040. resolve: {
  7041. KindId: function() {
  7042. return $scope.kindId;
  7043. }
  7044. }
  7045. });
  7046. modalInstance.result.then(function(data) {
  7047. $scope.prodInfo.cmpUuId = data.uuid;
  7048. $scope.prodInfo.cmpCode = data.code;
  7049. $scope.prodInfo.brand = data.brand.nameEn;
  7050. }, function(){
  7051. });
  7052. }, function(){
  7053. });
  7054. };
  7055. //提交
  7056. $scope.submit = function(prodInfo){
  7057. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  7058. $upload.upload({
  7059. url: 'product/baseInfo/addNewProduct',
  7060. file: file,
  7061. method: 'POST',
  7062. data: {
  7063. prodInfo: $scope.prodInfo
  7064. },
  7065. }).success(function(data) {
  7066. if(data.success) {
  7067. toaster.pop('success', '提示', data.success);
  7068. $timeout(function() {
  7069. //提交后跳转到详情页面,防止重复提交
  7070. window.location.href="#/baseInfo/prodList/"+data.id;
  7071. }, 500);
  7072. }
  7073. if(data.error) {
  7074. toaster.pop('error', '提示', data.error);
  7075. $timeout(function() {
  7076. //提交后跳转到详情页面,防止重复提交
  7077. window.location.href="#/baseInfo/prodList/"+data.id;
  7078. }, 500);
  7079. }
  7080. }).error(function(data) {
  7081. $scope.loadingShow = false;
  7082. toaster.pop('error', '操作失败', data.error);
  7083. });
  7084. // GetProductInfo.addNewProd({}, prodInfo, function(data) {
  7085. // toaster.pop("success", "提示", "提交成功");
  7086. //
  7087. //
  7088. // }, function(res) {
  7089. // toaster.pop("error", "提示" + res);
  7090. // });
  7091. };
  7092. $scope.previewShow = false;
  7093. $scope.pdfShow = false;
  7094. $scope.noneFileShow = true;
  7095. $scope.$watch('myFiles', function(){
  7096. if($scope.myFiles) {
  7097. $scope.noneFileShow = false;
  7098. var file = $scope.myFiles[0];
  7099. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  7100. $scope.pdfShow = true;
  7101. $scope.previewShow = false;
  7102. $scope.imgPreviewName = file.name;
  7103. } else{
  7104. if (typeof(Worker) !== "undefined") {//支持HTML5
  7105. $scope.imgPreview = getObjectURL(file);
  7106. $scope.imgPreviewName = file.name;
  7107. } else{//不支持HTML5
  7108. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  7109. $scope.imgPreviewName = file.name;
  7110. }
  7111. $scope.previewShow = true;
  7112. $scope.pdfShow = false;
  7113. }
  7114. } else {
  7115. $scope.noneFileShow = true;
  7116. $scope.previewShow = false;
  7117. $scope.pdfShow = false;
  7118. }
  7119. });
  7120. //建立一个可存取到该file的url
  7121. var getObjectURL = function(file) {
  7122. var url = null ;
  7123. if (window.createObjectURL!=undefined) { // basic
  7124. url = window.createObjectURL(file) ;
  7125. } else if (window.URL!=undefined) { // mozilla(firefox)
  7126. url = window.URL.createObjectURL(file) ;
  7127. } else if (window.webkitURL!=undefined) { // webkit or chrome
  7128. url = window.webkitURL.createObjectURL(file) ;
  7129. }
  7130. return url ;
  7131. };
  7132. // 取消
  7133. $scope.cancel = function(){
  7134. $scope.prodInfo = angular.copy($scope.prodInfo);
  7135. };
  7136. }]);
  7137. /**
  7138. * 类目选择模态框
  7139. */
  7140. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  7141. $scope.kindId = null;
  7142. $scope.kinds = [[], [], [], []];
  7143. // 获取子类目
  7144. var getChildren = function(pid, deep) {
  7145. KindAPI.getChildren({parentId: pid}, function(data) {
  7146. $scope.kinds[deep] = data;
  7147. }, function(response) {
  7148. toaster.pop('error', '获取子类目失败', response.data);
  7149. });
  7150. };
  7151. // 改变节点选中状态
  7152. var changeStatus = function(item, deep) {
  7153. var kindId = null, level = 0;
  7154. angular.forEach($scope.kinds, function(ks, i) {
  7155. if(i > deep) {
  7156. $scope.kinds[i] = [];
  7157. } else {
  7158. angular.forEach(ks, function(k, j) {
  7159. if(i == deep) {
  7160. if(k.id == item.id) {
  7161. $scope.kinds[i][j].$active = true;
  7162. kindId = k.id;
  7163. } else {
  7164. k.$active = null;
  7165. }
  7166. }
  7167. });
  7168. }
  7169. });
  7170. // 选择的节点
  7171. $scope.kindId = kindId;
  7172. $scope.active = item;
  7173. // 当前可操作的层级
  7174. if(deep < 3) {
  7175. $scope.activeDeep = deep + 1;
  7176. }
  7177. };
  7178. // 节点点击后获取子类目,节点被选中
  7179. $scope.onItemClick = function(item, deep) {
  7180. changeStatus(item, deep);
  7181. if (!item.isLeaf) {
  7182. getChildren(item.id, deep + 1);
  7183. }
  7184. };
  7185. // 重新加载数据
  7186. function reload(deep) {
  7187. var pid;
  7188. if(deep) {
  7189. pid = $scope.actives[deep - 1].id;
  7190. } else {
  7191. pid = 0;
  7192. deep = 0;
  7193. }
  7194. getChildren(pid, deep);
  7195. }
  7196. // 初始加载数据,获取第一层的类目
  7197. if($scope.actives) {
  7198. angular.forEach($scope.actives, function(v, k) {
  7199. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  7200. $scope.kinds[k] = data;
  7201. angular.forEach($scope.kinds[k], function(kind, i){
  7202. if(kind.id == v.id) {
  7203. $scope.kinds[k][i].$active = true;
  7204. $scope.actives[k] = $scope.kinds[k][i];
  7205. }
  7206. })
  7207. }, function(response) {
  7208. toaster.pop('error', '获取子类目失败', response.data);
  7209. });
  7210. });
  7211. } else {
  7212. reload();
  7213. }
  7214. // 取消
  7215. $scope.cancel = function() {
  7216. $modalInstance.dismiss();
  7217. };
  7218. // 确认选择
  7219. $scope.check = function() {
  7220. $modalInstance.close($scope.kindId);
  7221. };
  7222. }]);
  7223. /**
  7224. * 器件筛选
  7225. */
  7226. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  7227. //状态
  7228. $scope.setActive = function (state){
  7229. if($scope.active != state) {
  7230. $scope.active = state;
  7231. if($scope.tableParams.page() == 1)
  7232. $scope.tableParams.reload();
  7233. else
  7234. $scope.tableParams.page(1);
  7235. }
  7236. };
  7237. $scope.tableParams = new ngTableParams({
  7238. page : 1,
  7239. count : 10
  7240. }, {
  7241. total : 0,
  7242. counts: [5, 10, 25, 50],
  7243. getData : function($defer, params) {
  7244. $scope.loading = true;
  7245. var pageParams = params.url();
  7246. pageParams.keyword = $scope.keyword;
  7247. pageParams.kindId = KindId;
  7248. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  7249. console.log(page);
  7250. $scope.loading = false;
  7251. if(page) {
  7252. params.total(page.totalElement);
  7253. $defer.resolve(page.content);
  7254. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7255. }
  7256. }, function(response){
  7257. $scope.loading = false;
  7258. toaster.pop('error', '数据加载失败', response.data);
  7259. });
  7260. }
  7261. });
  7262. // 取消
  7263. $scope.cancel = function() {
  7264. $modalInstance.dismiss();
  7265. };
  7266. // 选择
  7267. $scope.check = function(data){
  7268. $modalInstance.close(data);
  7269. };
  7270. // 搜索框回车
  7271. $scope.onSearch = function() {
  7272. $scope.tableParams.page(1);
  7273. $scope.tableParams.reload();
  7274. };
  7275. }]);
  7276. /**
  7277. * 企业列表
  7278. */
  7279. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  7280. $scope.active = 'all';
  7281. $scope.agreedText = '全部';
  7282. $scope.dateZoneText = '一个月内';
  7283. $scope.condition = {dateZone: 1};
  7284. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7285. $scope.changeAgreed = function(agreed) {
  7286. $scope.condition.agreed = agreed;
  7287. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7288. $scope.condition.$agreedOpen = false;
  7289. };
  7290. $scope.changeDateZone = function(zone) {
  7291. $scope.condition.dateZone = zone;
  7292. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7293. $scope.condition.$dateZoneOpen = false;
  7294. getDateCondition(zone, $scope.condition);
  7295. $scope.tableParams.reload();
  7296. };
  7297. $scope.setActive = function(state) {
  7298. if($scope.active != state) {
  7299. $scope.active = state;
  7300. if($scope.tableParams.page() == 1)
  7301. $scope.tableParams.reload();
  7302. else
  7303. $scope.tableParams.page(1);
  7304. }
  7305. };
  7306. var getService = function() {
  7307. return getAccountUserSpace;
  7308. };
  7309. $scope.tableParams = new ngTableParams({
  7310. page : 1,
  7311. count : 5,
  7312. sorting: {
  7313. }
  7314. }, {
  7315. total : 0,
  7316. counts: [5, 10, 25, 50],
  7317. getData : function($defer, params) {
  7318. $scope.loading = true;
  7319. var pageParams = params.url();
  7320. pageParams.keyword = $rootScope.keyword;
  7321. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  7322. $scope.loading = false;
  7323. if(page) {
  7324. params.total(page.totalElement);
  7325. $defer.resolve(page.content);
  7326. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7327. }
  7328. }, function(response) {
  7329. $scope.loading = false;
  7330. toaster.pop('error', '数据加载失败', response.data);
  7331. });
  7332. }
  7333. });
  7334. // 搜索框回车
  7335. $scope.onSearch = function() {
  7336. $scope.tableParams.page(1);
  7337. $scope.tableParams.reload();
  7338. };
  7339. // 添加合作关系
  7340. $scope.addPartner = function(name, businessCode) {
  7341. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  7342. if(data.success) {
  7343. toaster.pop("success", '添加成功', data.success);
  7344. }
  7345. if(data.error) {
  7346. toaster.pop("error", '添加失败', data.error);
  7347. }
  7348. }, function(response) {
  7349. toaster.pop('error','失败',response.data);
  7350. });
  7351. }
  7352. $scope.status = 'enList';
  7353. }]);
  7354. /**
  7355. * 新增采购单
  7356. */
  7357. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder) {
  7358. $scope.order = {
  7359. date : new Date(),
  7360. cust : {
  7361. uu : '',
  7362. },
  7363. custUser : {
  7364. },
  7365. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  7366. orderItems : {
  7367. product : {},
  7368. $endDateOpen: false
  7369. },
  7370. };
  7371. if($rootScope.businessCode) {
  7372. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  7373. $scope.order.cust.enName = data.vendorEnterprise.enName;
  7374. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  7375. $scope.order.cust.uu = data.vendorEnterprise.uu;
  7376. $scope.order.custUser.userName = data.vendorUser.userName;
  7377. $scope.order.custUser.userTel = data.vendorUser.userTel;
  7378. }, function(response) {
  7379. });
  7380. };
  7381. // 查找客户
  7382. $scope.dbfindCust = function(){
  7383. var modalInstance = $modal.open({
  7384. templateUrl: 'static/tpl/index/purc/modal/purc_order_cust.html',
  7385. controller: 'DbfindCustCtrl',
  7386. size: 'lg',
  7387. resolve: {
  7388. }
  7389. });
  7390. modalInstance.result.then(function(data) {
  7391. $scope.order.cust = data.myEnterprise;
  7392. $scope.order.custUser = data.myUser;
  7393. $scope.order.orderItems = [];
  7394. var item = {
  7395. code: null,
  7396. title: null,
  7397. spec: null,
  7398. unit: null,
  7399. qty: null,
  7400. price: null,
  7401. remark: null,
  7402. delivery: null
  7403. };
  7404. // $scope.order.orderItems.push(item);
  7405. }, function(){
  7406. });
  7407. };
  7408. //商品信息
  7409. $scope.order.orderItems = [];
  7410. var item = {
  7411. code: null,
  7412. title: null,
  7413. spec: null,
  7414. unit: null,
  7415. qty: null,
  7416. price: null,
  7417. remark: null,
  7418. delivery: null
  7419. };
  7420. // $scope.order.orderItems.push(item);
  7421. if($rootScope.prodId) {
  7422. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  7423. item.code = data.code;
  7424. item.title = data.title;
  7425. item.spec = data.spec;
  7426. item.unit = data.unit;
  7427. $scope.order.orderItems.push(item);
  7428. }, function(response) {
  7429. });
  7430. }
  7431. //增加商品
  7432. $scope.addProduct = function(index) {
  7433. if($scope.order.orderItems[index].code == null) {
  7434. toaster.pop('info', '提示', '请先选择商品');
  7435. } else {
  7436. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null});
  7437. }
  7438. };
  7439. //删除商品
  7440. $scope.deleteProduct = function(index) {
  7441. $scope.order.orderItems.splice(index, 1);
  7442. };
  7443. $scope.tableParams = new ngTableParams({
  7444. page : 1,
  7445. count : 10
  7446. }, {
  7447. total : 0,
  7448. counts: [5, 10, 25, 50],
  7449. getData : function($defer, params) {
  7450. $scope.loading = true;
  7451. var pageParams = params.url();
  7452. pageParams.keyword = $scope.keyword;
  7453. $scope.tip = $scope.keyword;
  7454. pageParams.custUU = $scope.order.cust.uu;
  7455. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  7456. $scope.loading = false;
  7457. if(page) {
  7458. params.total(page.totalElement);
  7459. $scope.total = page.totalElement;
  7460. $defer.resolve(page.content);
  7461. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7462. }
  7463. }, function(response){
  7464. $scope.loading = false;
  7465. toaster.pop('error', '数据加载失败', response.data);
  7466. });
  7467. }
  7468. });
  7469. // 选择
  7470. $scope.check = function(data) {
  7471. $scope.order.orderItems.push(data);
  7472. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7473. if($scope.order.orderItems[i].code == null) {
  7474. $scope.order.orderItems.splice(i, 1);
  7475. }
  7476. }
  7477. };
  7478. // 搜索框回车
  7479. $scope.onSearch = function() {
  7480. $scope.tableParams.page(1);
  7481. $scope.tableParams.reload();
  7482. };
  7483. $scope.$watch('order.cust.uu', function(n, o) {
  7484. if(n==o) {
  7485. return;
  7486. } else {
  7487. $scope.tableParams.page(1);
  7488. $scope.tableParams.reload();
  7489. }
  7490. }, true);
  7491. // 查找客户物料
  7492. $scope.dbfindCustProd = function(index){
  7493. if($scope.order.cust.uu) {
  7494. var modalInstance = $modal.open({
  7495. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  7496. controller: 'DbfindCustProdCtrl',
  7497. size: 'lg',
  7498. resolve: {
  7499. custUU: function() {
  7500. return $scope.order.cust.uu
  7501. }
  7502. }
  7503. });
  7504. modalInstance.result.then(function(data) {
  7505. $scope.order.orderItems.push(data);
  7506. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7507. if($scope.order.orderItems[i].code == null || i == index) {
  7508. $scope.order.orderItems.splice(i, 1);
  7509. }
  7510. }
  7511. }, function() {
  7512. });
  7513. } else {
  7514. toaster.pop('info', '提示', '请先选择供应商');
  7515. }
  7516. };
  7517. $scope.getMinDate = function(item) {
  7518. return $filter('date')(new Date, 'yyyy-MM-dd');
  7519. };
  7520. $scope.openDatePicker = function($event, openParam, index) {
  7521. $event.preventDefault();
  7522. $event.stopPropagation();
  7523. $scope.order.orderItems[index].$endDateOpen = !openParam;
  7524. };
  7525. // 添加到购物车
  7526. $scope.addToCart = function(order) {
  7527. $scope.loading = true;
  7528. $scope.order.custUU = $scope.order.cust.uu;
  7529. $scope.order.custUserUU = $scope.order.custUser.userUU;
  7530. if($scope.order.date instanceof Date) {
  7531. $scope.order.date = $scope.order.date.getTime();
  7532. }
  7533. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7534. if($scope.order.orderItems[i].delivery instanceof Date) {
  7535. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  7536. }
  7537. }
  7538. addtoCart.save({}, $scope.order, function(data){
  7539. console.log($scope.order);
  7540. $scope.loading = false;
  7541. toaster.pop('success', '成功', '保存成功');
  7542. window.location.hash = '#/purc/cart/'+data.id;
  7543. }, function(response){
  7544. $scope.loading = false;
  7545. toaster.pop('error', '保存失败', response.data);
  7546. });
  7547. };
  7548. // 立即购买
  7549. $scope.addToOrder = function(order) {
  7550. $scope.loading = true;
  7551. $scope.order.custUU = $scope.order.cust.uu;
  7552. $scope.order.custUserUU = $scope.order.custUser.userUU;
  7553. if($scope.order.date instanceof Date) {
  7554. $scope.order.date = $scope.order.date.getTime();
  7555. }
  7556. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7557. if($scope.order.orderItems[i].delivery instanceof Date) {
  7558. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  7559. }
  7560. }
  7561. newPurcOrder.save({}, $scope.order, function(data){
  7562. $scope.loading = false;
  7563. toaster.pop('success', '成功', '保存成功');
  7564. window.location.hash = '#/purc/order/'+data.id;
  7565. }, function(response){
  7566. $scope.loading = false;
  7567. toaster.pop('error', '保存失败', response.data);
  7568. });
  7569. };
  7570. }]);
  7571. /**
  7572. * 我的客户
  7573. */
  7574. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  7575. $scope.userInfoResult = true;
  7576. AuthenticationService.getAuthentication().success(function(data) {
  7577. $scope.loading = false;
  7578. $scope.thisUser = data;
  7579. });
  7580. var getCustInfos = function(custuu) {
  7581. if(custuu) {
  7582. VendorService.userInfo.query({uu:custuu},null,function(data) {
  7583. console.log(data);
  7584. $scope.custInfos = data;
  7585. var getPage = function(page, size){
  7586. if($scope.custInfos) {
  7587. var result = {};
  7588. result.totalCount = $scope.custInfos.length;
  7589. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  7590. if($scope.custInfos.length % size == 0) {
  7591. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  7592. }else {
  7593. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  7594. }
  7595. result.first = page == 1;
  7596. result.last = page == result.totalPage;
  7597. result.page = page;
  7598. result.next = page - 0 + 1;
  7599. result.pre = page - 1;
  7600. return result;
  7601. }
  7602. }
  7603. $scope.userdata = getPage(1,4);
  7604. $scope.first = function (){
  7605. $scope.userdata = getPage($scope.userdata.pre,4);
  7606. }
  7607. $scope.last = function (){
  7608. $scope.userdata = getPage($scope.userdata.next,4);
  7609. }
  7610. }, function(response){
  7611. $scope.loading = false;
  7612. toaster.pop('error', '数据加载失败', response.data);
  7613. });
  7614. }
  7615. }
  7616. $scope.addUserInfo = function(customer) {
  7617. //TODO
  7618. if ($scope.thisUser.sys) {
  7619. var modalInstance = $modal.open({
  7620. animation: true,
  7621. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  7622. controller: 'AddUserInfoCtrl',
  7623. resolve: {
  7624. customer: function() {
  7625. return customer;
  7626. }
  7627. }
  7628. });
  7629. modalInstance.result.then(function(changed, checked){
  7630. if(changed) {
  7631. if(checked)
  7632. $scope.newUser.roles = checked;
  7633. else
  7634. loadUsers();
  7635. }
  7636. });
  7637. } else {
  7638. toaster.pop('error', '您不是管理员,无权限分配用户!');
  7639. }
  7640. }
  7641. $scope.showUserInfo = function(customer,boo) {
  7642. $scope.custInfo = customer;
  7643. if(boo) {
  7644. getCustInfos(customer.myEnterprise.uu);
  7645. $scope.userInfoResult = true;
  7646. }
  7647. }
  7648. $scope.customerParams = new ngTableParams({
  7649. page : 1,
  7650. count : 10
  7651. }, {
  7652. total : 0,
  7653. counts: [5, 10, 25, 50],
  7654. getData : function($defer, params) {
  7655. $scope.loading = true;
  7656. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  7657. $scope.loading = false;
  7658. if(page) {
  7659. params.total(page.totalElements);
  7660. $defer.resolve(page.content);
  7661. }
  7662. $scope.totalCount = page.totalElements;
  7663. }, function(response){
  7664. $scope.loading = false;
  7665. toaster.pop('error', '数据加载失败', response.data);
  7666. });
  7667. }
  7668. });
  7669. }]);
  7670. /**
  7671. * 我的供应商
  7672. */
  7673. app.controller('MySupplierCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  7674. $scope.userInfoResult = true;
  7675. AuthenticationService.getAuthentication().success(function(data) {
  7676. $scope.loading = false;
  7677. $scope.thisUser = data;
  7678. });
  7679. var getCustInfos = function(custuu) {
  7680. if(custuu) {
  7681. VendorService.userInfo.query({uu:custuu},null,function(data) {
  7682. $scope.custInfos = data;
  7683. var getPage = function(page, size){
  7684. if($scope.custInfos) {
  7685. var result = {};
  7686. result.totalCount = $scope.custInfos.length;
  7687. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  7688. if($scope.custInfos.length % size == 0) {
  7689. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  7690. }else {
  7691. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  7692. }
  7693. result.first = page == 1;
  7694. result.last = page == result.totalPage;
  7695. result.page = page;
  7696. result.next = page - 0 + 1;
  7697. result.pre = page - 1;
  7698. return result;
  7699. }
  7700. }
  7701. $scope.userdata = getPage(1,4);
  7702. $scope.first = function (){
  7703. $scope.userdata = getPage($scope.userdata.pre,4);
  7704. }
  7705. $scope.last = function (){
  7706. $scope.userdata = getPage($scope.userdata.next,4);
  7707. }
  7708. }, function(response){
  7709. $scope.loading = false;
  7710. toaster.pop('error', '数据加载失败', response.data);
  7711. });
  7712. }
  7713. }
  7714. $scope.addUserInfo = function(customer) {
  7715. //TODO
  7716. if ($scope.thisUser.sys) {
  7717. var modalInstance = $modal.open({
  7718. animation: true,
  7719. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  7720. controller: 'AddUserInfoCtrl',
  7721. resolve: {
  7722. customer: function() {
  7723. return customer;
  7724. }
  7725. }
  7726. });
  7727. modalInstance.result.then(function(changed, checked){
  7728. if(changed) {
  7729. if(checked)
  7730. $scope.newUser.roles = checked;
  7731. else
  7732. loadUsers();
  7733. }
  7734. });
  7735. } else {
  7736. toaster.pop('error', '您不是管理员,无权限分配用户!');
  7737. }
  7738. }
  7739. $scope.showUserInfo = function(customer,boo) {
  7740. $scope.custInfo = customer;
  7741. if(boo) {
  7742. getCustInfos(customer.myEnterprise.uu);
  7743. $scope.userInfoResult = true;
  7744. }
  7745. }
  7746. $scope.customerParams = new ngTableParams({
  7747. page : 1,
  7748. count : 10
  7749. }, {
  7750. total : 0,
  7751. counts: [5, 10, 25, 50],
  7752. getData : function($defer, params) {
  7753. $scope.loading = true;
  7754. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  7755. $scope.loading = false;
  7756. if(page) {
  7757. params.total(page.totalElements);
  7758. $defer.resolve(page.content);
  7759. }
  7760. $scope.totalCount = page.totalElements;
  7761. }, function(response){
  7762. $scope.loading = false;
  7763. toaster.pop('error', '数据加载失败', response.data);
  7764. });
  7765. }
  7766. });
  7767. }]);
  7768. /**
  7769. * 建立合作关系申请
  7770. */
  7771. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout) {
  7772. $scope.active = 'todo';
  7773. var getRequestStatus = function(active) {
  7774. var fn = 'getAllRequest';
  7775. switch(active) {
  7776. case 'done':
  7777. fn = 'getRequestDone';break;
  7778. case 'todo':
  7779. fn = 'getRequestTodo';break;
  7780. case 'end':
  7781. fn = 'getRequestEnd';break;
  7782. }
  7783. return fn;
  7784. }
  7785. // 切换单据类型
  7786. $scope.setActive = function(state) {
  7787. if($scope.active != state) {
  7788. $scope.active = state;
  7789. if($scope.tableParams.page() == 1)
  7790. $scope.tableParams.reload();
  7791. else
  7792. $scope.tableParams.page(1);
  7793. }
  7794. };
  7795. // 切换数据来源(正常数据 or 历史数据)
  7796. var getService = function() {
  7797. return AddPartnerMyRequest;
  7798. };
  7799. $scope.tableParams = new ngTableParams({ // ng-Table参数
  7800. page : 1,
  7801. count : 5,
  7802. sorting: {
  7803. }
  7804. }, {
  7805. total : 0,
  7806. counts: [5, 10, 15, 25, 50],
  7807. getData : function($defer, params) { // 获取数据的方法
  7808. $scope.loading = true;
  7809. var pageParams = params.url();
  7810. pageParams.keyword = $scope.keyword;
  7811. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7812. $scope.loading = false;
  7813. if(page) {
  7814. params.total(page.totalElement);
  7815. $defer.resolve(page.content);
  7816. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7817. }
  7818. }, function(response){
  7819. $scope.loading = false;
  7820. toaster.pop('error', '数据加载失败', response.data);
  7821. });
  7822. }
  7823. });
  7824. // 再次申请
  7825. $scope.reapply = function(id) {
  7826. AddPartner.reapply({id: id}, {}, function(data) {
  7827. toaster.pop('success', '提示', '操作成功');
  7828. }, function(response) {
  7829. toaster.pop('error','失败',response.data);
  7830. });
  7831. }
  7832. // 添加为供应商
  7833. $scope.addSupplier = function(vendUID) {
  7834. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  7835. if(data.success) {
  7836. toaster.pop('success', '提示', data.success);
  7837. }
  7838. if(data.error) {
  7839. toaster.pop('error','提示', data.error);
  7840. }
  7841. }, function(response) {
  7842. toaster.pop('error', '失败', response.data);
  7843. })
  7844. };
  7845. // 添加客户
  7846. $scope.addCust = function(vendUID) {
  7847. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  7848. if(data.success) {
  7849. toaster.pop('success', '提示', data.success);
  7850. }
  7851. if(data.error) {
  7852. toaster.pop('error','提示', data.error);
  7853. }
  7854. }, function(response) {
  7855. toaster.pop('error', '失败', response.data);
  7856. })
  7857. };
  7858. // 搜索框回车
  7859. $scope.onSearch = function() {
  7860. $scope.tableParams.page(1);
  7861. $scope.tableParams.reload();
  7862. };
  7863. // 同意申请
  7864. $scope.agree = function(id) {
  7865. AddPartner.agreeRequest({id: id}, {}, function(data) {
  7866. toaster.pop('success', '提示', '操作成功');
  7867. $timeout(function() {
  7868. window.location.reload();
  7869. }, 500);
  7870. }, function(response) {
  7871. toaster.pop('error', '提示', response.data);
  7872. });
  7873. }
  7874. // 拒绝申请
  7875. $scope.refuse = function(id, reason) {
  7876. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  7877. toaster.pop('success', '提示', '操作成功');
  7878. $timeout(function() {
  7879. window.location.reload();
  7880. }, 500);
  7881. }, function(response) {
  7882. toaster.pop('error', '提示', response.data);
  7883. });
  7884. }
  7885. $scope.status = 'send';
  7886. }]);
  7887. /**
  7888. * 建立合作关系处理申请
  7889. */
  7890. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  7891. $scope.active = 'todo';
  7892. var getMessagetStatus = function(active) {
  7893. var fn = 'getAllMessage';
  7894. switch(active) {
  7895. case 'done':
  7896. fn = 'getMessageDone';break;
  7897. case 'todo':
  7898. fn = 'getMessageTodo';break;
  7899. case 'end':
  7900. fn = 'getMessageEnd';break;
  7901. }
  7902. return fn;
  7903. }
  7904. // 切换单据类型
  7905. $scope.setActive = function(state) {
  7906. if($scope.active != state) {
  7907. $scope.active = state;
  7908. if($scope.tableParams.page() == 1)
  7909. $scope.tableParams.reload();
  7910. else
  7911. $scope.tableParams.page(1);
  7912. }
  7913. };
  7914. var getService = function() {
  7915. return AddPartnerMyMessage;
  7916. };
  7917. $scope.tableParams = new ngTableParams({ // ng-Table参数
  7918. page : 1,
  7919. count : 5,
  7920. sorting: {
  7921. }
  7922. }, {
  7923. total : 0,
  7924. counts: [5, 10, 15, 25, 50],
  7925. getData : function($defer, params) { // 获取数据的方法
  7926. $scope.loading = true;
  7927. var pageParams = params.url();
  7928. pageParams.searchFilter = { // 筛选条件
  7929. keyword: $scope.keyword,
  7930. };
  7931. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7932. $scope.loading = false;
  7933. console.log(page);
  7934. if(page) {
  7935. params.total(page.totalElement);
  7936. $defer.resolve(page.content);
  7937. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7938. }
  7939. }, function(response){
  7940. $scope.loading = false;
  7941. toaster.pop('error', '数据加载失败', response.data);
  7942. });
  7943. }
  7944. });
  7945. // 同意申请
  7946. $scope.agree = function(id) {
  7947. AddPartner.agreeRequest({id: id}, {}, function(data) {
  7948. toaster.pop('success', '提示', '操作成功');
  7949. }, function(response) {
  7950. toaster.pop('error', '提示', response.data);
  7951. });
  7952. }
  7953. // 拒绝申请
  7954. $scope.refuse = function(id, reason) {
  7955. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  7956. toaster.pop('success', '提示', '操作成功');
  7957. }, function(response) {
  7958. toaster.pop('error', '提示', response.data);
  7959. });
  7960. }
  7961. $scope.status = 'get';
  7962. }]);
  7963. /**
  7964. * 我的合作伙伴
  7965. */
  7966. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', function($scope, toaster, GetProductInfo) {
  7967. // 默认显示合作伙伴
  7968. $scope.status = 'news';
  7969. // 获取所有的合作伙伴
  7970. GetProductInfo.getAllPartners({}, function(data) {
  7971. console.log(data);
  7972. $scope.partners = data;
  7973. }, function(res) {
  7974. toaster.pop('error', '获取列表失败', res.data);
  7975. });
  7976. // 添加为客户
  7977. $scope.addCust = function(partner) {
  7978. GetProductInfo.addCust({}, partner, function(data) {
  7979. toaster.pop('success', '提示', '添加客户成功');
  7980. }, function(response) {
  7981. toaster.pop('error', '添加客户失败', response.data);
  7982. });
  7983. }
  7984. // 添加为供应商
  7985. $scope.addSupplier = function(partner) {
  7986. GetProductInfo.addSupplier({}, partner, function(data) {
  7987. toaster.pop('success', '提示', '添加供应商成功');
  7988. }, function(response) {
  7989. toaster.pop('error', '添加供应商失败', response.data);
  7990. });
  7991. }
  7992. }]);
  7993. /**
  7994. * 财务对账时,企业进行筛选操作
  7995. */
  7996. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  7997. $scope.getData = function(){
  7998. FaApCheck.getAllCustomers(function(data) {
  7999. console.log(data);
  8000. $scope.custs= data;
  8001. angular.forEach($scope.data, function(item) {
  8002. item:{
  8003. $selected: true;
  8004. }
  8005. });
  8006. $scope.loading = false;
  8007. });
  8008. }
  8009. $scope.getData();
  8010. $scope.CustName= function(suuorname) {
  8011. $modalInstance.close(suuorname);
  8012. }
  8013. $scope.close = function() {
  8014. $modalInstance.close();
  8015. }
  8016. }]);
  8017. /**
  8018. * 跳转到企业圈
  8019. */
  8020. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  8021. GetProductInfo.businessGroups({}, function(data) {
  8022. window.open(data.url);
  8023. }, function(response) {
  8024. toaster.pop('error', '提示', response.data);
  8025. });
  8026. }]);
  8027. /**
  8028. * 购物车
  8029. */
  8030. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  8031. $scope.active = 'all';
  8032. $scope.agreedText = '全部';
  8033. $scope.dateZoneText = '一个月内';
  8034. $scope.condition = {dateZone: 1};
  8035. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8036. $scope.changeAgreed = function(agreed) {
  8037. $scope.condition.agreed = agreed;
  8038. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8039. $scope.condition.$agreedOpen = false;
  8040. };
  8041. $scope.changeDateZone = function(zone) {
  8042. $scope.condition.dateZone = zone;
  8043. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8044. $scope.condition.$dateZoneOpen = false;
  8045. getDateCondition(zone, $scope.condition);
  8046. $scope.tableParams.reload();
  8047. };
  8048. $scope.setActive = function(state) {
  8049. if($scope.active != state) {
  8050. $scope.active = state;
  8051. if($scope.tableParams.page() == 1)
  8052. $scope.tableParams.reload();
  8053. else
  8054. $scope.tableParams.page(1);
  8055. }
  8056. };
  8057. var getService = function() {
  8058. return getCartList;
  8059. };
  8060. $scope.tableParams = new ngTableParams({
  8061. page : 1,
  8062. count : 5,
  8063. sorting: {
  8064. }
  8065. }, {
  8066. total : 0,
  8067. counts: [5, 10, 25, 50],
  8068. getData : function($defer, params) {
  8069. $scope.loading = true;
  8070. var pageParams = params.url();
  8071. pageParams.keyword = $scope.keyword;
  8072. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8073. $scope.loading = false;
  8074. if(page) {
  8075. params.total(page.totalElements);
  8076. $defer.resolve(page.content);
  8077. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8078. }
  8079. }, function(response) {
  8080. $scope.loading = false;
  8081. toaster.pop('error', '数据加载失败', response.data);
  8082. });
  8083. }
  8084. });
  8085. $scope.getCartTotal = function(items) {
  8086. var sum = 0;
  8087. angular.forEach(items, function(item){
  8088. sum += item.qty * item.price;
  8089. });
  8090. return sum;
  8091. };
  8092. // 搜索框回车
  8093. $scope.onSearch = function() {
  8094. $scope.tableParams.page(1);
  8095. $scope.tableParams.reload();
  8096. };
  8097. // 提交
  8098. $scope.addtoOrder = function(id) {
  8099. console.log(id);
  8100. cartOperation.addToOrder({id: id}, {}, function(data) {
  8101. if(data.success) {
  8102. toaster.pop('success', '提示', data.success);
  8103. $timeout(function() {
  8104. window.location.hash = '#/purc/cartdetail/'+data.id;
  8105. },500);
  8106. }
  8107. if(data.error) {
  8108. toaster.pop('error', '提示', data.error);
  8109. }
  8110. }, function(response) {
  8111. toaster.pop('erroer', '提示', response.data);
  8112. });
  8113. };
  8114. // 删除一条主记录
  8115. $scope.deleteCart = function(id) {
  8116. cartOperation.deleteCart({id: id}, {}, function(data) {
  8117. if(data.success) {
  8118. toaster.pop('success', '提示', data.success);
  8119. $timeout(function() {
  8120. window.location.reload();
  8121. },500);
  8122. }
  8123. if(data.error) {
  8124. toaster.pop('error', '提示', data.error);
  8125. }
  8126. }, function(response) {
  8127. toaster.pop('erroer', '提示', response.data);
  8128. });
  8129. };
  8130. // 删除一条明细
  8131. $scope.deleteDetail = function(id) {
  8132. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  8133. if(data.success) {
  8134. toaster.pop('success', '提示', data.success);
  8135. $timeout(function() {
  8136. window.location.reload();
  8137. },500);
  8138. }
  8139. if(data.error) {
  8140. toaster.pop('error', '提示', data.error);
  8141. }
  8142. }, function(response) {
  8143. toaster.pop('erroer', '提示', response.data);
  8144. });
  8145. };
  8146. // 清空购物车
  8147. $scope.clearCart = function() {
  8148. cartOperation.deleteCarts({}, function(data) {
  8149. if(data.success) {
  8150. toaster.pop('success', '提示', data.success);
  8151. $timeout(function() {
  8152. window.location.reload();
  8153. },500);
  8154. }
  8155. if(data.error) {
  8156. toaster.pop('error', '提示', data.error);
  8157. }
  8158. }, function(response) {
  8159. toaster.pop('erroer', '提示', response.data);
  8160. });
  8161. }
  8162. }]);
  8163. /**
  8164. * 购物车详情
  8165. */
  8166. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', function($scope, cartOperation, $stateParams, toaster, $timeout) {
  8167. var loadData = function() {
  8168. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  8169. if(data.code) {
  8170. $scope.cart = data;
  8171. var sum = 0;
  8172. angular.forEach($scope.cart.cartDetails, function(item) {
  8173. sum += item.qty * item.price;
  8174. });
  8175. $scope.cart.total = sum;
  8176. $scope.loading = false;
  8177. } else {
  8178. window.location.hash = '#/purc/cart';
  8179. }
  8180. });
  8181. };
  8182. loadData();
  8183. // 删除一条明细
  8184. $scope.deleteDetail = function(id) {
  8185. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  8186. if(data.success) {
  8187. toaster.pop('success', '提示', data.success);
  8188. $timeout(function() {
  8189. window.location.reload();
  8190. },500);
  8191. }
  8192. if(data.error) {
  8193. toaster.pop('error', '提示', data.error);
  8194. }
  8195. }, function(response) {
  8196. toaster.pop('erroer', '提示', response.data);
  8197. });
  8198. };
  8199. }]);
  8200. /**
  8201. * 审批流
  8202. */
  8203. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', function($scope, toaster, $modal, appFlow) {
  8204. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  8205. $scope.nodes = data;
  8206. }, function(response) {
  8207. });
  8208. $scope.NoteSet = function() {
  8209. var modalInstance = $modal.open({
  8210. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8211. controller: 'NoteStep1Ctrl',
  8212. size: 'lg',
  8213. resolve: {
  8214. AppName: function() {
  8215. return '请假单';
  8216. }
  8217. }
  8218. });
  8219. modalInstance.result.then(function(data) {
  8220. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8221. if(data.error) {
  8222. toaster.pop('error', '提示', data.error);
  8223. }
  8224. if(data.success) {
  8225. toaster.pop('success', '提示', data.success);
  8226. }
  8227. }, function(response) {
  8228. });
  8229. }, function(){
  8230. });
  8231. }
  8232. $scope.overTimeSet = function() {
  8233. var modalInstance = $modal.open({
  8234. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8235. controller: 'NoteStep1Ctrl',
  8236. size: 'lg',
  8237. resolve: {
  8238. AppName: function() {
  8239. return '加班单';
  8240. }
  8241. }
  8242. });
  8243. modalInstance.result.then(function(data) {
  8244. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8245. if(data.error) {
  8246. toaster.pop('error', '提示', data.error);
  8247. }
  8248. if(data.success) {
  8249. toaster.pop('success', '提示', data.success);
  8250. }
  8251. }, function(response) {
  8252. });
  8253. }, function(){
  8254. });
  8255. }
  8256. $scope.feePleaseSet = function() {
  8257. var modalInstance = $modal.open({
  8258. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8259. controller: 'NoteStep1Ctrl',
  8260. size: 'lg',
  8261. resolve: {
  8262. AppName: function() {
  8263. return '出差单';
  8264. }
  8265. }
  8266. });
  8267. modalInstance.result.then(function(data) {
  8268. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8269. if(data.error) {
  8270. toaster.pop('error', '提示', data.error);
  8271. }
  8272. if(data.success) {
  8273. toaster.pop('success', '提示', data.success);
  8274. }
  8275. }, function(response) {
  8276. });
  8277. }, function(){
  8278. });
  8279. }
  8280. $scope.workDailySet = function() {
  8281. var modalInstance = $modal.open({
  8282. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8283. controller: 'NoteStep1Ctrl',
  8284. size: 'lg',
  8285. resolve: {
  8286. AppName: function() {
  8287. return '工作日报';
  8288. }
  8289. }
  8290. });
  8291. modalInstance.result.then(function(data) {
  8292. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8293. if(data.error) {
  8294. toaster.pop('error', '提示', data.error);
  8295. }
  8296. if(data.success) {
  8297. toaster.pop('success', '提示', data.success);
  8298. }
  8299. }, function(response) {
  8300. });
  8301. }, function(){
  8302. });
  8303. }
  8304. }]);
  8305. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', function($scope, toaster, $modalInstance, appFlow, AppName, $filter) {
  8306. $scope.appName = AppName;// 标题名称
  8307. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  8308. if(data.appname) {
  8309. $scope.node = data;
  8310. }
  8311. }, function() {
  8312. });
  8313. $scope.AppFlow = {appName: $scope.appName,
  8314. AppNodes:{}};
  8315. $scope.AppFlow.AppNodes = [];
  8316. appFlow.getPositions({}, function(data) {// 获取人员信息
  8317. $scope.users = data;
  8318. }, function(response) {
  8319. });
  8320. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  8321. $scope.roles = data;
  8322. },function(response) {
  8323. });
  8324. $scope.SelectUser = function(data) { // 添加人员
  8325. var item = {
  8326. useruu: null,
  8327. username: null,
  8328. level: null
  8329. };
  8330. item.useruu = data.useruu;
  8331. item.username = data.username;
  8332. // if($scope.AppFlow.AppNodes.length != 0){
  8333. // angular.forEach($scope.AppFlow.AppNodes, function(node) {
  8334. // if(node) {
  8335. // if(node.useruu == item.useruu) {
  8336. // toaster.pop('info', '提示', '不能重复添加');
  8337. // } else {
  8338. // $scope.AppFlow.AppNodes.push(item);
  8339. // }
  8340. // }
  8341. // });
  8342. // } else {
  8343. $scope.AppFlow.AppNodes.push(item);
  8344. // }
  8345. }
  8346. $scope.SelectRole = function(data) {// 添加职位
  8347. var item = {
  8348. position: null,
  8349. level: null
  8350. };
  8351. item.position = data;
  8352. $scope.AppFlow.AppNodes.push(item);
  8353. }
  8354. $scope.deleteNode = function(index) {// 删除节点
  8355. $scope.AppFlow.AppNodes.splice(index, 1);
  8356. };
  8357. $scope.saveNode = function() { // 保存
  8358. angular.forEach($scope.AppFlow.AppNodes, function(value, key) {
  8359. $scope.AppFlow.AppNodes[key].level = key;
  8360. });
  8361. if($scope.AppFlow.AppNodes.length == 0) {
  8362. toaster.pop('info', '提示', '您还未设置审批人');
  8363. } else {
  8364. $modalInstance.close($scope.AppFlow);
  8365. };
  8366. };
  8367. $scope.cancel = function() {// 取消
  8368. $modalInstance.dismiss();
  8369. }
  8370. }]);
  8371. /***
  8372. * 代采定单
  8373. */
  8374. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', function($scope, toaster, getDeOrder, ngTableParams, BaseService) {
  8375. $scope.active = 'all';
  8376. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8377. $scope.setActive = function(state) {
  8378. if($scope.active != state) {
  8379. $scope.active = state;
  8380. if($scope.tableParams.page() == 1)
  8381. $scope.tableParams.reload();
  8382. else
  8383. $scope.tableParams.page(1);
  8384. }
  8385. };
  8386. $scope.tableParams = new ngTableParams({
  8387. page : 1,
  8388. count : 5,
  8389. sorting: {
  8390. }
  8391. }, {
  8392. total : 0,
  8393. counts: [5, 10, 25, 50],
  8394. getData : function($defer, params) {
  8395. $scope.loading = true;
  8396. var pageParams = params.url();
  8397. pageParams.keyword = $scope.keyword;
  8398. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8399. $scope.loading = false;
  8400. if(page) {
  8401. params.total(page.totalElements);
  8402. $defer.resolve(page.content);
  8403. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8404. }
  8405. }, function(response) {
  8406. $scope.loading = false;
  8407. toaster.pop('error', '数据加载失败', response.data);
  8408. });
  8409. }
  8410. });
  8411. // 搜索框回车
  8412. $scope.onSearch = function() {
  8413. $scope.tableParams.page(1);
  8414. $scope.tableParams.reload();
  8415. };
  8416. }]);
  8417. /**
  8418. * 新增代采订单
  8419. */
  8420. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', function($scope, toaster, $modal, DeputyOrder, $filter) {
  8421. $scope.deOrder = {
  8422. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  8423. entrydate: new Date(),
  8424. status: '在录入',
  8425. $dateOpen: false,
  8426. };
  8427. $scope.uplodaByBatch = function() {
  8428. var modalInstance = $modal.open({
  8429. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  8430. controller: 'DeputyOrderUploadCtrl',
  8431. size: 'lg',
  8432. resolve: {
  8433. }
  8434. });
  8435. modalInstance.result.then(function(data) {
  8436. $scope.deOrder.deputyOrderItems = data;
  8437. $scope.deOrder.totalamount = 0;
  8438. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  8439. $scope.deOrder.totalamount += item.amount * item.unitprice;
  8440. console.log($scope.deOrder.totalamount);
  8441. });
  8442. }, function(){
  8443. });
  8444. }
  8445. $scope.save = function() {
  8446. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  8447. if(data.success) {
  8448. toaster.pop('success', '提示', '保存成功');
  8449. }
  8450. if(data.error) {
  8451. toaster.pop('error', '提示', '保存失败');
  8452. }
  8453. }, function(response) {
  8454. });
  8455. }
  8456. $scope.openDatePicker = function($event, deOrder, openParam) {
  8457. $event.preventDefault();
  8458. $event.stopPropagation();
  8459. deOrder[openParam] = !deOrder[openParam];
  8460. };
  8461. }]);
  8462. /**
  8463. * 代采订单批量导入
  8464. */
  8465. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  8466. // 通过excel批量上传物料
  8467. $scope.result = null;
  8468. $scope.upload = function() {
  8469. var file = $scope.myFiles[0];
  8470. $upload.upload({
  8471. url: 'deputyOrder/release/excel',
  8472. file: file,
  8473. method: 'POST'
  8474. }).success(function(data) {
  8475. $scope.result = data;
  8476. $scope.success = $scope.result.success;
  8477. $scope.total = $scope.result.total;
  8478. $scope.alters = $scope.result.alters;
  8479. }).error(function(response) {
  8480. toaster.pop('error', response.data || response);
  8481. });
  8482. };
  8483. // 查看范例
  8484. $scope.showImg = function() {
  8485. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  8486. box.show();
  8487. box.find('img').attr('src', src);
  8488. box.find('a').click(function(){
  8489. box.hide();
  8490. });
  8491. box.dblclick(function(){
  8492. box.hide();
  8493. });
  8494. };
  8495. // 下载模板
  8496. $scope.download = function() {
  8497. window.location.href = 'deputyOrder/upload/template';
  8498. };
  8499. $scope.enSure = function() {
  8500. $modalInstance.close($scope.result.items);
  8501. }
  8502. $scope.cancel = function() {
  8503. $modalInstance.dismiss();
  8504. }
  8505. }]);
  8506. /**
  8507. * 招标单
  8508. */
  8509. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  8510. $scope.active = 'done';
  8511. $scope.setActive = function(state) {
  8512. if($scope.active != state) {
  8513. $scope.active = state;
  8514. if($scope.tableParams.page() == 1)
  8515. $scope.tableParams.reload();
  8516. else
  8517. $scope.tableParams.page(1);
  8518. }
  8519. };
  8520. var getTenderStatus = function(active) {
  8521. var fn = 'getMyAll';
  8522. switch(active) {
  8523. case 'done':
  8524. fn = 'getMyDone';break;
  8525. case 'todo':
  8526. fn = 'getMyTodo';break;
  8527. // case 'end':
  8528. // fn = 'getMyEnd';break;
  8529. case 'waiting':
  8530. fn = 'getMyWaiting';break;
  8531. }
  8532. return fn;
  8533. }
  8534. $scope.tableParams = new ngTableParams({
  8535. page : 1,
  8536. count : 5,
  8537. sorting: {
  8538. 'tender.endDate': 'desc',
  8539. 'tender.enterprise.enName': 'asc',
  8540. 'tender.code': 'asc'
  8541. }
  8542. }, {
  8543. total : 0,
  8544. counts: [5, 10, 25, 50],
  8545. getData : function($defer, params) {
  8546. $scope.loading = true;
  8547. var pageParams = params.url();
  8548. var realActive = {};
  8549. pageParams.searchFilter = { // 筛选条件
  8550. keyword: $scope.keyword,
  8551. // fromDate: getDateTime($scope.condition.dateFrom),
  8552. // endDate: getDateTime($scope.condition.dateTo)
  8553. };
  8554. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8555. $scope.loading = false;
  8556. if(page) {
  8557. params.total(page.totalElement);
  8558. $defer.resolve(page.content);
  8559. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  8560. }
  8561. }, function(response){
  8562. $scope.loading = false;
  8563. toaster.pop('error', '数据加载失败', response.data);
  8564. });
  8565. }
  8566. });
  8567. // 搜索框回车
  8568. $scope.onSearch = function() {
  8569. $scope.tableParams.page(1);
  8570. $scope.tableParams.reload();
  8571. };
  8572. }]);
  8573. /**
  8574. * 新增招标单
  8575. */
  8576. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload) {
  8577. // if( ! angular.isUndefined($stateParams.id) && $stateParams.id != "") {
  8578. // $scope.loading = true;
  8579. // PurcTender.getOne({id: $stateParams.id}, function(data){
  8580. // data.$editing = false;
  8581. // $scope.tenderItem.tender = data;
  8582. // staticItem = angular.copy(data);
  8583. // $scope.loading = false;
  8584. // }, function(response){
  8585. // $scope.loading = false;
  8586. // toaster.pop('error', '数据加载失败', response.data);
  8587. // });
  8588. // } else {//
  8589. $scope.loading = false;
  8590. $scope.condition = {dateZone: 1};
  8591. $scope.tenderItem = {
  8592. $editing: true,
  8593. tender: {
  8594. date: new Date(),
  8595. unit: 'PCS',
  8596. currency: 'RMB',
  8597. ifOpen: 1,
  8598. ifTax: 1,
  8599. invoiceType: 2,
  8600. tenderAttachs:[{}]
  8601. }
  8602. // 供应商企业信息
  8603. // enterpriseBaseInfo: [{}]
  8604. };
  8605. // 删除一个供应商
  8606. $scope.removeVendor = function(index) {
  8607. $scope.tenderItem.enterpriseBaseInfo.splice(index, 1);
  8608. };
  8609. // 可选的证照要求
  8610. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  8611. // 处理区域
  8612. var parseCertificate = function(a) {
  8613. if (a) {
  8614. var arr = a.split(',');
  8615. angular.forEach(arr, function(app) {
  8616. var contained = false;
  8617. angular.forEach($scope.certificates, function($app) {
  8618. if($app.name == app) {
  8619. $app.checked = true;
  8620. contained = true;
  8621. }
  8622. });
  8623. if(!contained) {
  8624. $scope.certificates.push({name: app, checked: true});
  8625. }
  8626. });
  8627. }
  8628. }
  8629. // 查找客户
  8630. $scope.dbfindVendor = function(){
  8631. var modalInstance = $modal.open({
  8632. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  8633. controller: 'DbfindVendorCtrl',
  8634. size: 'lg',
  8635. resolve: {
  8636. }
  8637. });
  8638. var ifPush = true;
  8639. modalInstance.result.then(function(data){
  8640. angular.forEach(data, function(vendor) {
  8641. if (!$scope.tenderItem.enterpriseBaseInfo) {// 不存在就先创建
  8642. $scope.tenderItem.enterpriseBaseInfo = [{}];
  8643. $scope.tenderItem.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  8644. } else {
  8645. for (var i = 0;i<$scope.tenderItem.enterpriseBaseInfo.length; i++) {
  8646. ifPush = true;
  8647. if ($scope.tenderItem.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  8648. ifPush = false;
  8649. break; // 判定到已存在供应商,就终止循环。
  8650. }
  8651. }
  8652. if (ifPush) {
  8653. $scope.tenderItem.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  8654. }
  8655. }
  8656. });
  8657. $rootScope.tenderVendor = $scope.tenderItem.enterpriseBaseInfo;
  8658. }, function(){
  8659. });
  8660. };
  8661. // // 查找客户物料
  8662. // $scope.dbfindCustProd = function(){
  8663. // if($scope.item.$editing) {
  8664. // if($scope.item.quotation.cust.uu) {
  8665. // var modalInstance = $modal.open({
  8666. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  8667. // controller: 'DbfindCustProdCtrl',
  8668. // size: 'lg',
  8669. // resolve: {
  8670. // custUU: function(){return $scope.item.quotation.cust.uu}
  8671. // }
  8672. // });
  8673. //
  8674. // modalInstance.result.then(function(data){
  8675. // $scope.item.product = data;
  8676. // }, function(){
  8677. //
  8678. // });
  8679. // } else {
  8680. // toaster.pop('error', '错误', '请先选择客户');
  8681. // }
  8682. // }
  8683. // };
  8684. var sleep = function (d){
  8685. for(var t = Date.now();Date.now() - t <= d;);
  8686. }
  8687. // 保存和发布招标单
  8688. $scope.save = function(isPublish){
  8689. $scope.loading = true;
  8690. // --组装证照要求
  8691. var myCertificate = [];
  8692. angular.forEach($scope.certificates, function(certificate) {
  8693. if (certificate.checked) {
  8694. myCertificate.push(certificate.name);
  8695. }
  8696. });
  8697. $scope.tenderItem.tender.certificate = myCertificate.join(',');
  8698. if(!$scope.tenderItem.tender.code) { //新增,设单号
  8699. $scope.tenderItem.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  8700. }
  8701. if($scope.tenderItem.tender.date instanceof Date) {
  8702. $scope.tenderItem.tender.date = $scope.tenderItem.tender.date.getTime();
  8703. }
  8704. if($scope.tenderItem.tender.endDate instanceof Date) {
  8705. $scope.tenderItem.tender.endDate = $scope.tenderItem.tender.endDate.getTime();
  8706. }
  8707. if($scope.tenderItem.tender.publishDate instanceof Date) {
  8708. $scope.tenderItem.tender.publishDate = $scope.tenderItem.tender.publishDate.getTime();
  8709. }
  8710. if (isPublish) { // 发布
  8711. toaster.pop('info', '提示', '正在发布,请稍候');
  8712. PurcTender.publish({tender: $scope.tenderItem.tender, enterpriseBaseInfo: $scope.tenderItem.enterpriseBaseInfo}, {}, function(tender,enterprise){
  8713. // angular.forEach(tender.tenderAttaches, function(tenderAttach) {
  8714. var file = $scope.MyFiles, file = file && file.length>0 ? file[0]: null;
  8715. $upload.upload({
  8716. url: 'tender/addTenderAttach',
  8717. file: file,
  8718. method: 'POST',
  8719. data: {
  8720. tender: $scope.tenderItem.tender
  8721. }
  8722. // });
  8723. });
  8724. parseCertificate(tender.certificate);
  8725. sleep(1500); //当前方法暂停1.5秒
  8726. $scope.loading = false;
  8727. toaster.pop('success', '成功', '发布成功');
  8728. window.location.hash = '#/purc/tender';
  8729. }, function(response){
  8730. $scope.loading = false;
  8731. toaster.pop('error', '发布失败', response.data);
  8732. });
  8733. } else { // 保存
  8734. toaster.pop('info', '提示', '正在保存,请稍候');
  8735. PurcTender.save({tender: $scope.tenderItem.tender, enterpriseBaseInfo: $scope.tenderItem.enterpriseBaseInfo}, {}, function(tender,enterprise) {
  8736. var file = $scope.MyFiles, file = file && file.length>0 ? file[0]: null;
  8737. $upload.upload({
  8738. url: 'tender/addTenderAttach',
  8739. file: file,
  8740. method: 'POST',
  8741. data: {
  8742. tender: $scope.tenderItem.tender
  8743. }
  8744. });
  8745. $scope.loading = false;
  8746. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  8747. toaster.pop('success', '成功', '保存成功');
  8748. window.location.hash = '#/purc/tender';
  8749. }, function(response){
  8750. $scope.loading = false;
  8751. toaster.pop('error', '保存失败', response.data);
  8752. });
  8753. }
  8754. };
  8755. $scope.getMinDate = function() {
  8756. if (!$scope.tenderItem.tender) {
  8757. return $filter('date')(new Date(), 'yyyy-MM-dd');
  8758. }
  8759. return $scope.tenderItem.tender.endDate ? $filter('date')($scope.tenderItem.tender.endDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  8760. };
  8761. $scope.openDatePicker = function($event, item, openParam) {
  8762. $event.preventDefault();
  8763. $event.stopPropagation();
  8764. item[openParam] = !item[openParam];
  8765. };
  8766. }]);
  8767. /**
  8768. * 评标
  8769. */
  8770. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  8771. $scope.tenderItems = [];
  8772. // 采购方获取评标单
  8773. var evaluation = function() {
  8774. $scope.loading = true;
  8775. PurcTender.getOne({id: $stateParams.id}, function(data){
  8776. data.$editing = false;
  8777. $scope.tender = data;
  8778. $scope.loading = false;
  8779. }, function(response){
  8780. $scope.loading = false;
  8781. toaster.pop('error', '数据加载失败', response.data);
  8782. });
  8783. }
  8784. evaluation();
  8785. $scope.submit = function(tender) {
  8786. PurcTender.decide(tender, function(){
  8787. toaster.pop('success', '确认成功');
  8788. window.location.hash = '#/purc/tender';
  8789. }, function(response){
  8790. toaster.pop('error', '确认失败', response.data);
  8791. });
  8792. }
  8793. }]);
  8794. /**
  8795. * 客户指定招标
  8796. *
  8797. */
  8798. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  8799. $scope.active = 'todo';
  8800. $scope.condition = {dateZone: 1};
  8801. $scope.setActive = function(state) {
  8802. if($scope.active != state) {
  8803. $scope.active = state;
  8804. if($scope.tableParams.page() == 1)
  8805. $scope.tableParams.reload();
  8806. else
  8807. $scope.tableParams.page(1);
  8808. }
  8809. };
  8810. $scope.tableParams = new ngTableParams({
  8811. page : 1,
  8812. count : 5,
  8813. sorting: {
  8814. 'tender.endDate': 'desc',
  8815. 'tender.enterprise.enName': 'asc',
  8816. 'tender.code': 'asc'
  8817. }
  8818. }, {
  8819. total : 0,
  8820. counts: [5, 10, 25, 50],
  8821. getData : function($defer, params) {
  8822. $scope.loading = true;
  8823. var pageParams = params.url();
  8824. var realActive = {};
  8825. pageParams.searchFilter = { // 筛选条件
  8826. keyword: $scope.keyword
  8827. // fromDate: getDateTime($scope.condition.dateFrom),
  8828. // endDate: getDateTime($scope.condition.dateTo)
  8829. };
  8830. AccountEnterprise.get({}, function(data){
  8831. $scope.loading = false;
  8832. $scope.currentEn = data;
  8833. });
  8834. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8835. $scope.loading = false;
  8836. if(page) {
  8837. params.total(page.totalElement);
  8838. $defer.resolve(page.content);
  8839. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  8840. }
  8841. }, function(response){
  8842. $scope.loading = false;
  8843. toaster.pop('error', '数据加载失败', response.data);
  8844. });
  8845. }
  8846. });
  8847. var stautsItem = [];
  8848. $scope.getTenderStatus = function (tender) {
  8849. angular.forEach(tender.purchaseTenderItems, function(thisItem){
  8850. if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  8851. stautsItem = thisItem;
  8852. }
  8853. });
  8854. if (!stautsItem.price) {
  8855. return "daitoubiao";
  8856. } else if (!stautsItem.applystatus) {
  8857. return "yitoubiao";
  8858. } else if (stautsItem.applystatus == 1) {
  8859. return "zhongbiao";
  8860. } else if (stautsItem.applystatus == 0) {
  8861. return "weizhongbiao";
  8862. }
  8863. };
  8864. // 搜索框回车
  8865. $scope.onSearch = function() {
  8866. $scope.tableParams.page(1);
  8867. $scope.tableParams.reload();
  8868. };
  8869. }]);
  8870. /**
  8871. * 平台公开招标
  8872. *
  8873. */
  8874. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  8875. $scope.active = 'todo';
  8876. $scope.condition = {dateZone: 1};
  8877. $scope.setActive = function(state) {
  8878. if($scope.active != state) {
  8879. $scope.active = state;
  8880. if($scope.tableParams.page() == 1)
  8881. $scope.tableParams.reload();
  8882. else
  8883. $scope.tableParams.page(1);
  8884. }
  8885. };
  8886. var getOpenState = function(active) {
  8887. var fn = 'getOpenAll';
  8888. switch(active) {
  8889. // case 'done':
  8890. // fn = 'getOpenDone';break;
  8891. case 'todo':
  8892. fn = 'getOpenTodo';break;
  8893. case 'end':
  8894. fn = 'getOpenEnd';break;
  8895. // case 'waiting':
  8896. // fn = 'getOpenWaiting';break;
  8897. }
  8898. return fn;
  8899. };
  8900. $scope.tableParams = new ngTableParams({
  8901. page : 1,
  8902. count : 5,
  8903. sorting: {
  8904. 'tender.endDate': 'desc',
  8905. 'tender.enterprise.enName': 'asc',
  8906. 'tender.code': 'asc'
  8907. }
  8908. }, {
  8909. total : 0,
  8910. counts: [5, 10, 25, 50],
  8911. getData : function($defer, params) {
  8912. $scope.loading = true;
  8913. var pageParams = params.url();
  8914. var realActive = {};
  8915. pageParams.searchFilter = { // 筛选条件
  8916. keyword: $scope.keyword,
  8917. // fromDate: getDateTime($scope.condition.dateFrom),
  8918. // endDate: getDateTime($scope.condition.dateTo)
  8919. };
  8920. AccountEnterprise.get({}, function(data){
  8921. $scope.loading = false;
  8922. $scope.currentEn = data;
  8923. });
  8924. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8925. $scope.loading = false;
  8926. if(page) {
  8927. params.total(page.totalElement);
  8928. $defer.resolve(page.content);
  8929. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  8930. }
  8931. }, function(response){
  8932. $scope.loading = false;
  8933. toaster.pop('error', '数据加载失败', response.data);
  8934. });
  8935. }
  8936. });
  8937. var stautsItem = [];
  8938. $scope.getTenderStatus = function (tender) {
  8939. angular.forEach(tender.purchaseTenderItems, function(thisItem){
  8940. if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  8941. stautsItem = thisItem;
  8942. }
  8943. });
  8944. if (!stautsItem.price) {
  8945. return "daitoubiao";
  8946. } else if (!stautsItem.applystatus) {
  8947. return "yitoubiao";
  8948. } else if (stautsItem.applystatus == 1) {
  8949. return "zhongbiao";
  8950. } else if (stautsItem.applystatus == 0) {
  8951. return "weizhongbiao";
  8952. }
  8953. };
  8954. // 搜索框回车
  8955. $scope.onSearch = function() {
  8956. $scope.tableParams.page(1);
  8957. $scope.tableParams.reload();
  8958. };
  8959. }]);
  8960. /**
  8961. * 采购方查看供应商投标单
  8962. */
  8963. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  8964. PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  8965. $scope.item = data; // 供应商查看
  8966. $scope.loading = false;
  8967. }, function(response){
  8968. $scope.loading = false;
  8969. toaster.pop('error', '数据加载失败', response.data);
  8970. });
  8971. PurcTender.getOne({id: $stateParams.id}, function(data){
  8972. $scope.bid = data; // 用于展示
  8973. }, function(response){
  8974. toaster.pop('error', '数据加载失败', response.data);
  8975. });
  8976. }]);
  8977. /**
  8978. * 投标
  8979. */
  8980. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload) {
  8981. var staticItem = null;
  8982. // $scope.loading = true;
  8983. PurcTender.getItem({id: $stateParams.id}, function(data){
  8984. $scope.item = data; // 用于投标
  8985. if ($scope.item.enterpriseBaseInfo != null) {
  8986. $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  8987. }
  8988. staticItem = angular.copy(data);
  8989. $scope.loading = false;
  8990. }, function(response){
  8991. $scope.loading = false;
  8992. toaster.pop('error', '数据加载失败', response.data);
  8993. });
  8994. var sleep = function (d){
  8995. for(var t = Date.now();Date.now() - t <= d;);
  8996. }
  8997. PurcTender.getOne({id: $stateParams.id}, function(data){
  8998. $scope.bid = data; // 用于展示
  8999. }, function(response){
  9000. toaster.pop('error', '数据加载失败', response.data);
  9001. });
  9002. // 投标
  9003. $scope.bidIt = function(tender,item){
  9004. $scope.loading = true;
  9005. if(item.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  9006. item.enterpriseBaseInfo.enEstablishDate = item.enterpriseBaseInfo.enEstablishDate.getTime();
  9007. }
  9008. PurcTender.reply({bid:tender, tenderItem:item}, {}, function(tender, tenderItem){
  9009. var file = $scope.MyFiles, file = file && file.length>0 ? file[0]: null;
  9010. $upload.upload({
  9011. url: 'tender/addTenderItemAttach',
  9012. file: file,
  9013. method: 'POST',
  9014. data: {
  9015. tenderItem: $scope.item
  9016. }
  9017. });
  9018. $scope.loading = false;
  9019. toaster.pop('info', '成功', '投标成功');
  9020. // $window.location.reload();
  9021. window.location.hash = '#/sale/tender';
  9022. }, function(response){
  9023. $scope.loading = false;
  9024. toaster.pop('error', '投标失败', '出现异常,投标失败');
  9025. });
  9026. };
  9027. $scope.condition = {
  9028. $fromOpened:false
  9029. }
  9030. $scope.getMaxDate = function() {
  9031. return $filter('date')(new Date(), 'yyyy-MM-dd');
  9032. };
  9033. $scope.openDatePicker = function($event, item, openParam) {
  9034. $event.preventDefault();
  9035. $event.stopPropagation();
  9036. item[openParam] = !item[openParam];
  9037. };
  9038. }]);
  9039. return app;
  9040. });