app.js 201 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234
  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'], 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']);
  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. AuthenticationService.redirectSignin();
  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. $urlRouterProvider.otherwise('/index');
  25. $stateProvider.state('index', {
  26. url : "/index",
  27. views : {
  28. "left-view" : {
  29. templateUrl : "static/tpl/index/home/left.html",
  30. controller: 'LeftCtrl'
  31. },
  32. "right-view" : {
  33. templateUrl : "static/tpl/index/home/right.html",
  34. controller: 'RightCtrl'
  35. }
  36. }
  37. }).state('home', {
  38. url : "/",
  39. views : {
  40. "left-view" : {
  41. templateUrl : "static/tpl/index/home/left.html",
  42. controller: 'LeftCtrl'
  43. },
  44. "right-view" : {
  45. templateUrl : "static/tpl/index/home/right.html",
  46. controller: 'RightCtrl'
  47. }
  48. }
  49. }).state('sale', {
  50. url : "/sale",
  51. views : {
  52. "left-view" : {
  53. templateUrl : "static/tpl/index/sale/left.html",
  54. controller: 'LeftCtrl'
  55. },
  56. "right-view" : {
  57. templateUrl : "static/tpl/index/sale/right.html"
  58. }
  59. },
  60. controller: function($scope) {
  61. $scope.truck = [];
  62. $scope.dataChanged = false;
  63. }
  64. }).state('sale.index', {
  65. url : "",
  66. templateUrl : "static/tpl/index/sale/index.html"
  67. }).state('sale.home', {
  68. url : "/",
  69. templateUrl : "static/tpl/index/sale/index.html"
  70. }).state('purc', {
  71. url : "/purc",
  72. views : {
  73. "left-view" : {
  74. templateUrl : "static/tpl/index/purc/left.html",
  75. controller: 'LeftCtrl'
  76. },
  77. "right-view" : {
  78. templateUrl : "static/tpl/index/purc/right.html"
  79. }
  80. },
  81. controller: function($scope) {
  82. $scope.truck = [];
  83. $scope.dataChanged = false;
  84. }
  85. }).state('purc.index', {
  86. url : "",
  87. templateUrl : "static/tpl/index/purc/index.html"
  88. }).state('purc.home', {
  89. url : "/",
  90. templateUrl : "static/tpl/index/purc/index.html"
  91. }).state('purc.introduce', {
  92. url : "/introduce",
  93. templateUrl : "static/tpl/index/purc/introduce.html"
  94. }).state('purc.order', {
  95. url : "/order",
  96. templateUrl : "static/tpl/index/purc/order.html",
  97. controller: 'PurcOrderCtrl'
  98. }).state('sale.todo', {
  99. url : "/todo",
  100. templateUrl : "static/tpl/index/sale/todo.html"
  101. }).state('sale.todo.inquiry', {
  102. url : "/inquiry",
  103. templateUrl : "static/tpl/index/sale/inquiry.html",
  104. controller: 'SaleInquiryCtrl'
  105. }).state('sale.todo.order', {
  106. url : "/order",
  107. templateUrl : "static/tpl/index/sale/order.html",
  108. controller: 'SaleOrderCtrl'
  109. }).state('sale.todo.change', {
  110. url : "/change",
  111. templateUrl : "static/tpl/index/sale/change.html",
  112. controller: 'SaleChangeCtrl'
  113. }).state('sale.todo.notice', {
  114. url : "/notice",
  115. templateUrl : "static/tpl/index/sale/notice.html",
  116. controller: 'SaleNoticeCtrl'
  117. }).state('sale.customer', {
  118. url : "/customer",
  119. templateUrl : "static/tpl/index/sale/customer.html",
  120. controller: 'CustomerCtrl'
  121. }).state('sale.customerProduct', {
  122. url : "/customerProduct",
  123. templateUrl : "static/tpl/index/sale/customer.html",
  124. controller: 'CustomerCtrl'
  125. }).state('sale.inquiry', {
  126. url : "/inquiry",
  127. templateUrl : "static/tpl/index/sale/inquiry.html",
  128. controller: 'SaleInquiryCtrl'
  129. }).state('sale.inquiry_detail', {
  130. url : "/inquiry/:id",
  131. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  132. controller: 'SaleInquiryDetailCtrl'
  133. }).state('sale.quotation', {
  134. url : "/quotation",
  135. templateUrl : "static/tpl/index/sale/quotation.html"
  136. }).state('sale.quotation.new', {
  137. url : "/new",
  138. templateUrl : "static/tpl/index/sale/quotation_new.html",
  139. controller: 'SaleQuotationNewCtrl'
  140. }).state('sale.quotation.list', {
  141. url : "/list",
  142. templateUrl : "static/tpl/index/sale/quotation_list.html",
  143. controller: 'SaleQuotationListCtrl'
  144. }).state('sale.quotation.item', {
  145. url : "/:id",
  146. templateUrl : "static/tpl/index/sale/quotation_new.html",
  147. controller: 'SaleQuotationNewCtrl'
  148. }).state('sale.order', {
  149. url : "/order",
  150. templateUrl : "static/tpl/index/sale/order.html",
  151. controller: 'SaleOrderCtrl'
  152. }).state('sale.order_detail', {
  153. url : "/order/:id",
  154. templateUrl : "static/tpl/index/sale/order_detail.html",
  155. controller: 'SaleOrderDetailCtrl'
  156. }).state('sale.change', {
  157. url : "/change",
  158. templateUrl : "static/tpl/index/sale/change.html",
  159. controller: 'SaleChangeCtrl'
  160. }).state('sale.change_detail', {
  161. url : "/change/:id",
  162. templateUrl : "static/tpl/index/sale/change_detail.html",
  163. controller: 'SaleChangeDetailCtrl'
  164. }).state('sale.notice', {
  165. url : "/notice",
  166. templateUrl : "static/tpl/index/sale/notice.html",
  167. controller: 'SaleNoticeCtrl'
  168. }).state('sale.send', {
  169. url : "/send",
  170. templateUrl : "static/tpl/index/sale/send.html",
  171. controller: 'SaleSendCtrl'
  172. }).state('sale.send_detail', {
  173. url : "/send/:id",
  174. templateUrl : "static/tpl/index/sale/send_detail.html",
  175. controller: 'SaleSendDetailCtrl'
  176. }).state('sale.forecast', {
  177. url : "/forecast",
  178. templateUrl : "static/tpl/index/sale/forecast.html",
  179. controller: 'SaleForecastCtrl'
  180. }).state('sale.accept', {
  181. url : "/accept",
  182. templateUrl : "static/tpl/index/sale/accept.html",
  183. controller: 'SaleAcceptCtrl'
  184. }).state('sale.returns', {
  185. url : "/returns",
  186. templateUrl : "static/tpl/index/sale/returns.html",
  187. controller: 'SaleReturnsCtrl'
  188. }).state('sale.sample', {
  189. url : "/sample",
  190. templateUrl : "static/tpl/index/sale/sample.html",
  191. controller: 'SaleSampleCtrl'
  192. }).state('sale.sample_detail', {
  193. url : "/sample/:id",
  194. templateUrl : "static/tpl/index/sale/sample_detail.html",
  195. controller: 'SaleSampleDetailCtrl'
  196. }).state('sale.approval', {
  197. url : "/approval",
  198. templateUrl : "static/tpl/index/sale/approval.html",
  199. controller: 'SaleApprovalCtrl'
  200. }).state('account', {
  201. url : "/account",
  202. views : {
  203. "left-view" : {
  204. templateUrl : "static/tpl/index/account/left.html",
  205. controller: 'LeftCtrl'
  206. },
  207. "right-view" : {
  208. templateUrl : "static/tpl/index/account/right.html"
  209. }
  210. }
  211. }).state('account.index', {
  212. url : "",
  213. templateUrl : "static/tpl/index/account/index.html",
  214. controller: 'RightCtrl'
  215. }).state('account.home', {
  216. url : "/",
  217. templateUrl : "static/tpl/index/account/index.html",
  218. controller: 'RightCtrl'
  219. }).state('account.enterprise', {
  220. url : "/enterprise",
  221. templateUrl : "static/tpl/index/account/enterprise.html",
  222. controller: 'EnterpriseCtrl'
  223. }).state('account.user', {
  224. url : "/user",
  225. templateUrl : "static/tpl/index/account/user.html",
  226. controller: 'UserCtrl'
  227. }).state('account.log', {
  228. url : "/log",
  229. templateUrl : "static/tpl/index/account/log.html",
  230. controller: 'LogCtrl'
  231. }).state('account.resource', {
  232. url : "/resource",
  233. templateUrl : "static/tpl/index/account/resource.html",
  234. controller: 'ResourceCtrl'
  235. }).state('account.role', {
  236. url : "/role",
  237. templateUrl : "static/tpl/index/account/role.html",
  238. controller: 'RoleCtrl'
  239. }).state('qc', {
  240. url : "/qc",
  241. views : {
  242. "left-view" : {
  243. templateUrl : "static/tpl/index/qc/left.html"
  244. },
  245. "right-view" : {
  246. templateUrl : "static/tpl/index/qc/right.html"
  247. }
  248. }
  249. }).state('qc.index', {
  250. url : "",
  251. templateUrl : "static/tpl/index/qc/index.html"
  252. }).state('qc.home', {
  253. url : "/",
  254. templateUrl : "static/tpl/index/qc/index.html"
  255. }).state('qc.badIn', {
  256. url : "/badIn",
  257. templateUrl : "static/tpl/index/qc/badIn.html",
  258. controller: 'SaleBadInCtrl'
  259. }).state('qc.badOut', {
  260. url : "/badOut",
  261. templateUrl : "static/tpl/index/qc/badOut.html",
  262. controller: 'SaleBadOutCtrl'
  263. }).state('qc.MRB', {
  264. url : "/MRB",
  265. templateUrl : "static/tpl/index/qc/MRB.html",
  266. controller: 'SaleMRBCtrl'
  267. }).state('fa', {
  268. url : "/fa",
  269. views : {
  270. "left-view" : {
  271. templateUrl : "static/tpl/index/fa/left.html"
  272. },
  273. "right-view" : {
  274. templateUrl : "static/tpl/index/fa/right.html"
  275. }
  276. }
  277. }).state('fa.index', {
  278. url : "",
  279. templateUrl : "static/tpl/index/fa/index.html"
  280. }).state('fa.home', {
  281. url : "/",
  282. templateUrl : "static/tpl/index/fa/index.html"
  283. }).state('fa.apBill', {
  284. url : "/apBill",
  285. templateUrl : "static/tpl/index/fa/apBill.html",
  286. controller: 'SaleApBillCtrl'
  287. }).state('fa.arCheck', {
  288. url : "/arCheck",
  289. templateUrl : "static/tpl/index/fa/arCheck.html",
  290. controller: 'SaleArCheckCtrl'
  291. }).state('fa.arCheck_detail', {
  292. url : "/arCheck/:id",
  293. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  294. controller: 'SaleArCheckDetailCtrl'
  295. }).state('fa.apCheck', {
  296. url : "/apCheck",
  297. params:{
  298. 'id':null
  299. },
  300. templateUrl : "static/tpl/index/fa/apCheck.html",
  301. controller: 'PurchaseApCheckCtrl'
  302. }).state('fa.apCheck_detail', {
  303. url : "/apCheck/:id",
  304. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  305. controller: 'PurchaseApCheckDetailCtrl'
  306. }).state('fa.apCheckList', {
  307. url : "/apCheckList",
  308. templateUrl : "static/tpl/index/fa/apCheckList.html",
  309. controller: 'PurchaseApCheckListCtrl'
  310. }).state('make', {
  311. url : "/make",
  312. views : {
  313. "left-view" : {
  314. templateUrl : "static/tpl/index/make/left.html"
  315. },
  316. "right-view" : {
  317. templateUrl : "static/tpl/index/make/right.html"
  318. }
  319. }
  320. }).state('make.index', {
  321. url : "",
  322. templateUrl : "static/tpl/index/make/index.html"
  323. }).state('make.home', {
  324. url : "/",
  325. templateUrl : "static/tpl/index/make/index.html"
  326. }).state('make.todo', {
  327. url : "/todo",
  328. templateUrl : "static/tpl/index/make/todo.html"
  329. }).state('make.todo.order', {
  330. url : "/order",
  331. templateUrl : "static/tpl/index/make/order.html",
  332. controller: 'MakeOrderCtrl'
  333. }).state('make.order', {
  334. url : "/order",
  335. templateUrl : "static/tpl/index/make/order.html",
  336. controller: 'MakeOrderCtrl'
  337. }).state('make.order_detail', {
  338. url : "/order/:id",
  339. templateUrl : "static/tpl/index/make/order_detail.html",
  340. controller: 'MakeOrderDetailCtrl'
  341. }).state('make.change', {
  342. url : "/change",
  343. templateUrl : "static/tpl/index/make/change.html",
  344. controller: 'MakeChangeCtrl'
  345. }).state('make.change_detail', {
  346. url : "/change/:id",
  347. templateUrl : "static/tpl/index/make/change_detail.html",
  348. controller: 'MakeChangeDetailCtrl'
  349. }).state('make.outorder', {
  350. url : "/outorder",
  351. templateUrl : "static/tpl/index/make/outorder.html",
  352. controller: 'MakeOutOrderCtrl'
  353. }).state('make.outorder_detail', {
  354. url : "/outorder/:id",
  355. templateUrl : "static/tpl/index/make/outorder_detail.html",
  356. controller: 'MakeOutOrderDetailCtrl'
  357. }).state('make.accept', {
  358. url : "/accept",
  359. templateUrl : "static/tpl/index/make/accept.html",
  360. controller: 'MakeAcceptCtrl'
  361. }).state('make.returns', {
  362. url : "/returns",
  363. templateUrl : "static/tpl/index/make/returns.html",
  364. controller: 'MakeReturnCtrl'
  365. }).state('cs', {// 客户服务
  366. url : "/cs",
  367. views : {
  368. "left-view" : {
  369. templateUrl : "static/tpl/index/cs/left.html"
  370. },
  371. "right-view" : {
  372. templateUrl : "static/tpl/index/cs/right.html"
  373. }
  374. }
  375. }).state('cs.index', {
  376. url : "",
  377. templateUrl : "static/tpl/index/cs/index.html"
  378. }).state('cs.home', {
  379. url : "/",
  380. templateUrl : "static/tpl/index/cs/index.html"
  381. });
  382. }]);
  383. /**
  384. * 表示符号
  385. */
  386. app.factory('Symbol', function(){
  387. return {
  388. currency: function(cur) {
  389. if(cur == 'RMB') return '¥';
  390. else if(cur == 'USD') return '$';
  391. else if(cur == 'EUR') return '€';
  392. else if(cur == null || cur == '') return '¥';
  393. else return cur;
  394. }
  395. };
  396. }).factory('Lodop',function(){
  397. return {
  398. getLodop:function(oOBJECT,oEMBED){
  399. var CreatedOKLodop7766=null;
  400. /**************************
  401. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  402. IE系列、IE内核系列的浏览器采用oOBJECT,
  403. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  404. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  405. 64位浏览器指向64位的安装程序install_lodop64.exe。
  406. **************************/
  407. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  408. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  409. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  410. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  411. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  412. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  413. var LODOP;
  414. try{
  415. //=====判断浏览器类型:===============
  416. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  417. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  418. //=====如果页面有Lodop就直接使用,没有则新建:==========
  419. if (oOBJECT!=undefined || oEMBED!=undefined) {
  420. if (isIE)
  421. LODOP=oOBJECT;
  422. else
  423. LODOP=oEMBED;
  424. } else {
  425. if (CreatedOKLodop7766==null){
  426. LODOP=document.createElement("object");
  427. LODOP.setAttribute("width",0);
  428. LODOP.setAttribute("height",0);
  429. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  430. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  431. else LODOP.setAttribute("type","application/x-print-lodop");
  432. document.documentElement.appendChild(LODOP);
  433. CreatedOKLodop7766=LODOP;
  434. } else
  435. LODOP=CreatedOKLodop7766;
  436. };
  437. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  438. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  439. if (navigator.userAgent.indexOf('Chrome')>=0)
  440. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  441. if (navigator.userAgent.indexOf('Firefox')>=0)
  442. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  443. if (is64IE) document.write(strHtm64_Install); else
  444. if (isIE) document.write(strHtmInstall); else
  445. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  446. return LODOP;
  447. } else
  448. if (LODOP.VERSION<"6.1.9.8") {
  449. if (is64IE) document.write(strHtm64_Update); else
  450. if (isIE) document.write(strHtmUpdate); else
  451. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  452. return LODOP;
  453. };
  454. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  455. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  456. //============================================================
  457. return LODOP;
  458. } catch(err) {
  459. if (is64IE)
  460. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  461. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  462. return LODOP;
  463. };
  464. }
  465. }
  466. });
  467. app.controller('MyCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  468. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  469. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  470. if (routeState.indexOf('/') > -1)
  471. routeState = routeState.substring(0, routeState.indexOf('/'));
  472. if (routeState.indexOf('.') > -1)
  473. routeState = routeState.substring(0, routeState.indexOf('.'));
  474. $scope.routeState = routeState || 'home';
  475. });
  476. }]);
  477. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  478. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  479. //手机号码格式验证
  480. // var checkTel = function(data){
  481. // var userTel = data.userTel;
  482. // $scope.checkResult = false;
  483. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  484. // if(!(telephone).test(userTel)){
  485. // var modalInstance = $modal.open({
  486. // animation: true,
  487. // templateUrl: 'static/tpl/index/account/checkTel.html',
  488. // controller: 'CheckTelCtrl',
  489. // backdrop: 'static',
  490. // keyboard: false,
  491. // resolve: {
  492. // user: function(){
  493. // return data;
  494. // },
  495. // }
  496. // });
  497. // modalInstance.result.then(function(){
  498. // }, function(){
  499. //
  500. // });
  501. // } else {
  502. // $scope.checkResult = true;
  503. // }
  504. // };
  505. AuthenticationService.getAuthentication().success(function(data) {
  506. if(data.enterprises) {
  507. data.enterprise = data.enterprises[data.enterprises.length - 1];
  508. if(data.enterprises.length > 1) {
  509. var enSelect = [];
  510. angular.forEach(data.enterprises, function(e){
  511. if(e.current)
  512. data.enterprise = e;
  513. else
  514. enSelect.push(e);
  515. });
  516. data.enSelect = enSelect;
  517. }
  518. }
  519. $scope.userInfo = data;
  520. if (data == null || !data.userUU) {
  521. $scope.isAuthed = false;
  522. AuthenticationService.redirectSignin();
  523. } else {
  524. //跳转到手机号码验证
  525. // checkTel($scope.userInfo);
  526. }
  527. });
  528. $scope.logout = function() {
  529. AuthenticationService.logout();
  530. };
  531. $scope.switchto = function(enUU) {// 切换企业
  532. AuthenticationService.reSignin(enUU).success(function(){
  533. $window.location.reload();
  534. });
  535. };
  536. $scope.addFavorite = function(){
  537. var url = encodeURI(window.location.href);
  538. try{
  539. //ie浏览器收藏方式
  540. window.external.addFavorite(url, "优软商务平台");
  541. }catch(e) {
  542. try{
  543. //火狐浏览器收藏方式
  544. window.sidebar.addPanel("优软商务平台", url);
  545. }catch (e) {
  546. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  547. "或手动在浏览器里进行设置。");
  548. }
  549. }
  550. };
  551. }]);
  552. app.controller('TodoCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  553. SnapshotService.getTodo(function(data){
  554. $scope.todo = data;
  555. });
  556. }]);
  557. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  558. SaleTruck.query({}, function(data){
  559. $rootScope.truck = data;
  560. $scope.truckCount = data ? data.length : 0;
  561. });
  562. $scope.$watch(function(){
  563. return $rootScope.truck;
  564. }, function(data) {
  565. $scope.truckCount = data ? data.length : 0;
  566. }, true);
  567. $scope.clearAll = function() {
  568. SaleTruck.remove({}, function(){
  569. $rootScope.truck = [];
  570. });
  571. };
  572. $scope.openTrack = function() {
  573. $modal.open({
  574. templateUrl: 'static/tpl/index/sale/track.html',
  575. controller: 'TruckModalCtrl',
  576. size: 'lg'
  577. }).result.then(function(s){
  578. if(s) {
  579. $scope.clearAll();
  580. $rootScope.dataChanged = true;
  581. }
  582. });
  583. };
  584. }]);
  585. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  586. $scope.saleSend = {sendItems: []};
  587. SaleTruck.detail({}, function(data){
  588. // 按物料编号排序
  589. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  590. });
  591. $scope.remove = function(index, notice) {
  592. SaleTruck.remove({noticeId: notice.id}, function(data){
  593. $rootScope.truck = data;
  594. $scope.notices.splice(index, 1);
  595. });
  596. };
  597. $scope.$watch(function(){
  598. return $scope.notices;
  599. }, function(data) {
  600. var q = 0, t = 0;
  601. if(data) {
  602. angular.forEach(data,function(d){
  603. q += d.thisSendQty;
  604. t += d.thisSendQty * d.orderItem.price;
  605. });
  606. }
  607. $scope.totalQty = q;
  608. $scope.total = t;
  609. }, true);
  610. $scope.cancel = function() {
  611. $modalInstance.close();
  612. };
  613. $scope.send = function() {// 发货
  614. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  615. toaster.pop('error', '错误', '请输入送货单号');
  616. return;
  617. }
  618. var currency = $scope.notices[0].orderItem.order.currency,
  619. custUU = $scope.notices[0].enUU,
  620. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  621. var num = 1;
  622. for(var i in $scope.notices) {
  623. var item = $scope.notices[i];
  624. if(item.id) {
  625. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  626. valid = false;
  627. break;
  628. }
  629. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  630. }
  631. }
  632. if(!valid) {
  633. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  634. } else {
  635. var send = angular.extend(angular.copy($scope.saleSend), {
  636. currency: currency,
  637. custUU: custUU,
  638. payments: payments,
  639. sendItems: items
  640. });
  641. PurcNotice.sendByBatch({}, send, function(data){
  642. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  643. $modalInstance.close(true);
  644. $state.go('sale.send_detail', {id: data.id});
  645. }, function(response){
  646. toaster.pop('error', '错误', response.data);
  647. });
  648. }
  649. };
  650. }]);
  651. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  652. SaleStat.cust({}, function(data){
  653. var p = [], q = [];
  654. angular.forEach(data.month, function(d){
  655. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  656. });
  657. angular.forEach(data.year, function(d){
  658. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  659. });
  660. $scope.custCharts = {
  661. month : {
  662. chartType : 'pie',
  663. datas : {
  664. data : p
  665. },
  666. config : {
  667. labels : false,
  668. title : "客户月采购量排行榜",
  669. legend : {
  670. display : true,
  671. position : 'right'
  672. },
  673. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  674. click : function(d) {
  675. },
  676. mouseover : function(d) {
  677. },
  678. mouseout : function(d) {
  679. },
  680. innerRadius : 0,
  681. lineLegend : 'lineEnd'
  682. }
  683. },
  684. year : {
  685. chartType : 'pie',
  686. datas : {
  687. data : q
  688. },
  689. config : {
  690. labels : false,
  691. title : "客户年采购量排行榜",
  692. legend : {
  693. display : true,
  694. position : 'right'
  695. },
  696. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  697. click : function(d) {
  698. },
  699. mouseover : function(d) {
  700. },
  701. mouseout : function(d) {
  702. },
  703. innerRadius : 0,
  704. lineLegend : 'lineEnd'
  705. }
  706. }
  707. };
  708. });
  709. SaleStat.seller({}, function(data){
  710. var p = [], q = [];
  711. angular.forEach(data.month, function(d){
  712. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  713. });
  714. angular.forEach(data.year, function(d){
  715. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  716. });
  717. $scope.sellerCharts = {
  718. month : {
  719. chartType : 'pie',
  720. datas : {
  721. data : p
  722. },
  723. config : {
  724. labels : false,
  725. title : "业务员月销量排行榜",
  726. legend : {
  727. display : true,
  728. position : 'right'
  729. },
  730. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  731. click : function(d) {
  732. },
  733. mouseover : function(d) {
  734. },
  735. mouseout : function(d) {
  736. },
  737. innerRadius : 0,
  738. lineLegend : 'lineEnd'
  739. }
  740. },
  741. year : {
  742. chartType : 'pie',
  743. datas : {
  744. data : q
  745. },
  746. config : {
  747. labels : false,
  748. title : "业务员年销量排行榜",
  749. legend : {
  750. display : true,
  751. position : 'right'
  752. },
  753. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  754. click : function(d) {
  755. },
  756. mouseover : function(d) {
  757. },
  758. mouseout : function(d) {
  759. },
  760. innerRadius : 0,
  761. lineLegend : 'lineEnd'
  762. }
  763. }
  764. };
  765. });
  766. }]);
  767. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  768. SaleStat.get({}, function(data){
  769. var p = [], q = [], r = [];
  770. angular.forEach(data.day, function(d){
  771. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  772. });
  773. angular.forEach(data.month, function(d){
  774. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  775. });
  776. angular.forEach(data.year, function(d){
  777. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  778. });
  779. $scope.charts = {
  780. day : {
  781. chartType : "line",
  782. datas: {
  783. series: ['销售额'],
  784. data: p
  785. },
  786. config : {
  787. "labels": false,
  788. "title": "销售额统计(近15日线)",
  789. "legend": {
  790. "display": true,
  791. "position": "right"
  792. },
  793. colors : [ '#4D9934'],
  794. "innerRadius": 0,
  795. "lineLegend": "lineEnd"
  796. }
  797. },
  798. month: {
  799. chartType : "line",
  800. datas: {
  801. series: ['销售额'],
  802. data: q
  803. },
  804. config : {
  805. "labels": false,
  806. "title": "销售额统计(近12月线)",
  807. "legend": {
  808. "display": true,
  809. "position": "right"
  810. },
  811. colors : [ '#4D9934'],
  812. "innerRadius": 0,
  813. "lineLegend": "lineEnd"
  814. }
  815. },
  816. year: {
  817. chartType : "line",
  818. datas: {
  819. series: ['销售额'],
  820. data: r
  821. },
  822. config : {
  823. "labels": false,
  824. "title": "销售额统计(近10年线)",
  825. "legend": {
  826. "display": true,
  827. "position": "right"
  828. },
  829. colors : [ '#4D9934'],
  830. "innerRadius": 0,
  831. "lineLegend": "lineEnd"
  832. }
  833. }
  834. };
  835. });
  836. }]);
  837. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  838. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  839. $scope.notices = data;
  840. });
  841. $scope.dateTime = new Date();
  842. }]);
  843. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  844. VendorService.getCount(function(date){
  845. $scope.count = date;
  846. });
  847. }]);
  848. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  849. $scope.userInfoResult = true;
  850. AuthenticationService.getAuthentication().success(function(data) {
  851. $scope.loading = false;
  852. $scope.thisUser = data;
  853. });
  854. var getCustInfos = function(custuu) {
  855. if(custuu) {
  856. VendorService.userInfo.query({uu:custuu},null,function(data) {
  857. $scope.custInfos = data;
  858. var getPage = function(page, size){
  859. if($scope.custInfos) {
  860. var result = {};
  861. result.totalCount = $scope.custInfos.length;
  862. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  863. if($scope.custInfos.length % size == 0) {
  864. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  865. }else {
  866. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  867. }
  868. result.first = page == 1;
  869. result.last = page == result.totalPage;
  870. result.page = page;
  871. result.next = page - 0 + 1;
  872. result.pre = page - 1;
  873. return result;
  874. }
  875. }
  876. $scope.userdata = getPage(1,4);
  877. $scope.first = function (){
  878. $scope.userdata = getPage($scope.userdata.pre,4);
  879. }
  880. $scope.last = function (){
  881. $scope.userdata = getPage($scope.userdata.next,4);
  882. }
  883. }, function(response){
  884. $scope.loading = false;
  885. toaster.pop('error', '数据加载失败', response.data);
  886. });
  887. }
  888. }
  889. $scope.addUserInfo = function(customer) {
  890. //TODO
  891. if ($scope.thisUser.sys) {
  892. var modalInstance = $modal.open({
  893. animation: true,
  894. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  895. controller: 'AddUserInfoCtrl',
  896. resolve: {
  897. customer: function() {
  898. return customer;
  899. }
  900. }
  901. });
  902. modalInstance.result.then(function(changed, checked){
  903. if(changed) {
  904. if(checked)
  905. $scope.newUser.roles = checked;
  906. else
  907. loadUsers();
  908. }
  909. });
  910. } else {
  911. toaster.pop('error', '您不是管理员,无权限分配用户!');
  912. }
  913. }
  914. $scope.showUserInfo = function(customer,boo) {
  915. $scope.custInfo = customer;
  916. if(boo) {
  917. getCustInfos(customer.myEnterprise.uu);
  918. $scope.userInfoResult = true;
  919. }
  920. }
  921. $scope.customerParams = new ngTableParams({
  922. page : 1,
  923. count : 10
  924. }, {
  925. total : 0,
  926. counts: [5, 10, 25, 50],
  927. getData : function($defer, params) {
  928. $scope.loading = true;
  929. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  930. $scope.loading = false;
  931. if(page) {
  932. params.total(page.totalElements);
  933. $defer.resolve(page.content);
  934. }
  935. $scope.totalCount = page.totalElements;
  936. }, function(response){
  937. $scope.loading = false;
  938. toaster.pop('error', '数据加载失败', response.data);
  939. });
  940. }
  941. });
  942. }]);
  943. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  944. $scope.checkboxes = {
  945. checked : false
  946. };
  947. $scope.loading = true;
  948. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  949. $scope.userinfos = data;
  950. $scope.loading = false;
  951. })
  952. // 点击勾选全部的复选框
  953. $scope.checkAll = function() {
  954. angular.forEach($scope.userinfos, function(item) {
  955. item.distribute = $scope.checkboxes.checked;
  956. });
  957. };
  958. // 点击其中一个明细的复选框
  959. $scope.checkOne = function(vendor){
  960. var result = true;
  961. angular.forEach($scope.userinfos, function(item) {
  962. if(item.distribute != true){
  963. result = false;
  964. return;
  965. }
  966. });
  967. $scope.checkboxes.checked = result;
  968. };
  969. $scope.close = function(save) {
  970. var chooseResult = [];
  971. if(save) {
  972. if(customer.myEnterprise.uu) {
  973. angular.forEach($scope.userinfos, function(item, i) {
  974. chooseResult.push(item);
  975. });
  976. if(chooseResult.length > 0) {
  977. $scope.loading = true;
  978. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  979. $scope.loading = false;
  980. toaster.pop('success', '提示', '保存成功');
  981. $modalInstance.close(false);
  982. }, function(response){
  983. $scope.loading = false;
  984. toaster.pop('error', '保存失败', response.data);
  985. $modalInstance.close(false);
  986. })
  987. } else {
  988. toaster.pop('error', '保存失败', "您未勾选任何记录");
  989. }
  990. } else {
  991. $modalInstance.close(true, $scope.checkboxes.checked);
  992. }
  993. } else {
  994. $modalInstance.close(false);
  995. }
  996. };
  997. }]);
  998. var getState = function(active) {
  999. var fn = 'get';
  1000. switch(active) {
  1001. case 'done':
  1002. fn = 'getDone';break;
  1003. case 'todo':
  1004. fn = 'getTodo';break;
  1005. case 'end':
  1006. fn = 'getEnd';break;
  1007. case 'waiting':
  1008. fn = 'getWaiting';break;
  1009. }
  1010. return fn;
  1011. };
  1012. /**
  1013. * 改变单据日期范围
  1014. */
  1015. var getDateCondition = function(zone, condition) {
  1016. var date = new Date();
  1017. if(zone == -1) {
  1018. condition.dateFrom = null;
  1019. condition.dateTo = null;
  1020. } else if(zone == 1) {
  1021. date.setMonth(date.getMonth() - 1);
  1022. condition.dateFrom = date;
  1023. condition.dateTo = new Date();
  1024. } else if (zone == 6) {
  1025. date.setMonth(date.getMonth() - 6);
  1026. condition.dateFrom = date;
  1027. condition.dateTo = new Date();
  1028. } else {
  1029. date.setMonth(date.getMonth() - 6);
  1030. condition.dateFrom = null;
  1031. condition.dateTo = date;
  1032. }
  1033. };
  1034. /**
  1035. * 改变单据交货日期范围
  1036. */
  1037. var getDelveryCondition = function(zone, condition) {
  1038. var date = new Date();
  1039. if(zone == -1) {
  1040. condition.deliveryFrom = null;
  1041. condition.deliveryTo = null;
  1042. } else if(zone == 1) {
  1043. date.setMonth(date.getMonth() + 1);
  1044. condition.deliveryTo = date;
  1045. condition.deliveryFrom = new Date();
  1046. } else if (zone == 2) {
  1047. date.setMonth(date.getMonth() + 2);
  1048. condition.deliveryTo = date;
  1049. condition.deliveryFrom = new Date();
  1050. }
  1051. };
  1052. /**
  1053. * 将日期转化为整数日期
  1054. */
  1055. var getDateTime = function(date) {
  1056. if(angular.isDate(date)) {
  1057. return date.getTime();
  1058. } else {
  1059. return null;
  1060. }
  1061. };
  1062. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1063. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1064. $scope.active = 'todo';
  1065. $scope.dateZoneText = '不限';
  1066. $scope.deliveryZoneText = '不限';
  1067. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1068. $scope.changeDateZone = function(zone) {
  1069. $scope.condition.dateZone = zone;
  1070. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1071. $scope.condition.$dateZoneOpen = false;
  1072. getDateCondition(zone, $scope.condition);
  1073. $scope.tableParams.reload();
  1074. };
  1075. $scope.changeDeliveryZone = function(zone) {
  1076. $scope.condition.deliveryZoneText = zone;
  1077. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1078. $scope.condition.$delievryZoneOpen = false;
  1079. getDelveryCondition(zone, $scope.condition);
  1080. $scope.tableParams.reload();
  1081. };
  1082. // 切换单据类型
  1083. $scope.setActive = function(state) {
  1084. if($scope.active != state) {
  1085. $scope.active = state;
  1086. if($scope.tableParams.page() == 1)
  1087. $scope.tableParams.reload();
  1088. else
  1089. $scope.tableParams.page(1);
  1090. }
  1091. };
  1092. var getPurcStatus = function(active) {
  1093. var fn = 'getPurcAll';
  1094. switch(active) {
  1095. case 'done':
  1096. fn = 'getPurcDone';break;
  1097. case 'todo':
  1098. fn = 'getPurcTodo';break;
  1099. case 'end':
  1100. fn = 'getPurcEnd';break;
  1101. case 'waiting':
  1102. fn = 'getPurcWaiting';break;
  1103. }
  1104. return fn;
  1105. }
  1106. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1107. page : 1,
  1108. count : 5,
  1109. sorting: {
  1110. display: 'desc',
  1111. date: 'desc'
  1112. }
  1113. }, {
  1114. total : 0,
  1115. counts: [5, 10, 15, 25, 50],
  1116. getData : function($defer, params) { // 获取数据的方法
  1117. $scope.loading = true;
  1118. var pageParams = params.url();
  1119. pageParams.searchFilter = { // 筛选条件
  1120. keyword: $scope.keyword,
  1121. fromDate: getDateTime($scope.condition.dateFrom),
  1122. endDate: getDateTime($scope.condition.dateTo)
  1123. };
  1124. console.log(getPurcStatus($scope.active));
  1125. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1126. $scope.loading = false;
  1127. if(page) {
  1128. $defer.resolve(page.content);
  1129. params.total(page.totalElements);
  1130. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1131. }
  1132. }, function(response){
  1133. $scope.loading = false;
  1134. toaster.pop('error', '数据加载失败', response.data);
  1135. });
  1136. }
  1137. });
  1138. $scope.getOrderTotal = function(items) {
  1139. var sum = 0;
  1140. angular.forEach(items, function(item){
  1141. sum += item.qty * item.price;
  1142. });
  1143. return sum;
  1144. };
  1145. $scope.openDatePicker = function($event, item, openParam) {
  1146. $event.preventDefault();
  1147. $event.stopPropagation();
  1148. item[openParam] = !item[openParam];
  1149. };
  1150. $scope.parseDate = function(dateStr) {
  1151. if(dateStr)
  1152. return Date.parse(dateStr, 'yyyy-MM-dd');
  1153. return new Date();
  1154. };
  1155. $scope.checkboxes = {
  1156. checked : false
  1157. };
  1158. // 点击勾选全部的复选框
  1159. $scope.checkAll = function(){
  1160. angular.forEach($scope.tableParams.data, function(item) {
  1161. item.$selected = $scope.checkboxes.checked;
  1162. });
  1163. };
  1164. // 点击其中一个明细的复选框
  1165. $scope.checkOne = function(order){
  1166. var result = true;
  1167. angular.forEach($scope.tableParams.data, function(item) {
  1168. if(item.$selected != true){
  1169. result = false;
  1170. return;
  1171. }
  1172. });
  1173. $scope.checkboxes.checked = result;
  1174. };
  1175. // 搜索框回车
  1176. $scope.onSearch = function() {
  1177. $scope.tableParams.page(1);
  1178. $scope.tableParams.reload();
  1179. };
  1180. // 选择查找日期
  1181. $scope.onDateCondition = function(){
  1182. $scope.tableParams.page(1);
  1183. $scope.tableParams.reload();
  1184. };
  1185. }]);
  1186. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  1187. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  1188. $scope.active = 'todo';
  1189. $scope.dateZoneText = '不限';
  1190. $scope.deliveryZoneText = '不限';
  1191. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1192. $scope.changeDateZone = function(zone) {
  1193. $scope.condition.dateZone = zone;
  1194. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1195. $scope.condition.$dateZoneOpen = false;
  1196. getDateCondition(zone, $scope.condition);
  1197. $scope.tableParams.reload();
  1198. };
  1199. $scope.changeDeliveryZone = function(zone) {
  1200. $scope.condition.deliveryZoneText = zone;
  1201. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1202. $scope.condition.$delievryZoneOpen = false;
  1203. getDelveryCondition(zone, $scope.condition);
  1204. $scope.tableParams.reload();
  1205. };
  1206. // 切换单据类型
  1207. $scope.setActive = function(state) {
  1208. if($scope.active != state) {
  1209. $scope.active = state;
  1210. if($scope.tableParams.page() == 1)
  1211. $scope.tableParams.reload();
  1212. else
  1213. $scope.tableParams.page(1);
  1214. }
  1215. };
  1216. // 切换数据来源(正常数据 or 历史数据)
  1217. var getService = function() {
  1218. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  1219. };
  1220. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1221. page : 1,
  1222. count : 5,
  1223. sorting: {
  1224. display: 'desc',
  1225. date: 'desc'
  1226. }
  1227. }, {
  1228. total : 0,
  1229. counts: [5, 10, 15, 25, 50],
  1230. getData : function($defer, params) { // 获取数据的方法
  1231. $scope.loading = true;
  1232. var pageParams = params.url();
  1233. pageParams.searchFilter = { // 筛选条件
  1234. keyword: $scope.keyword,
  1235. fromDate: getDateTime($scope.condition.dateFrom),
  1236. endDate: getDateTime($scope.condition.dateTo)
  1237. };
  1238. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1239. $scope.loading = false;
  1240. if(page) {
  1241. $defer.resolve(page.content);
  1242. params.total(page.totalElements);
  1243. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1244. }
  1245. }, function(response){
  1246. $scope.loading = false;
  1247. toaster.pop('error', '数据加载失败', response.data);
  1248. });
  1249. }
  1250. });
  1251. $scope.getOrderTotal = function(items) {
  1252. var sum = 0;
  1253. angular.forEach(items, function(item){
  1254. sum += item.qty * item.price;
  1255. });
  1256. return sum;
  1257. };
  1258. $scope.openDatePicker = function($event, item, openParam) {
  1259. $event.preventDefault();
  1260. $event.stopPropagation();
  1261. item[openParam] = !item[openParam];
  1262. };
  1263. $scope.parseDate = function(dateStr) {
  1264. if(dateStr)
  1265. return Date.parse(dateStr, 'yyyy-MM-dd');
  1266. return new Date();
  1267. };
  1268. $scope.onReplyClick = function(item, inverse) {
  1269. if(item.reply) {
  1270. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1271. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1272. return;
  1273. }
  1274. var reply = angular.copy(item.reply);
  1275. if(reply.delivery) {
  1276. if(typeof reply.delivery == 'object')
  1277. reply.delivery = reply.delivery.getTime();
  1278. } else {
  1279. reply.delivery = item.delivery;
  1280. }
  1281. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1282. $scope.loading = true;
  1283. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1284. $scope.loading = false;
  1285. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1286. $scope.tableParams.reload();
  1287. }, function(response){
  1288. $scope.loading = false;
  1289. toaster.pop('error', '回复失败', response.data);
  1290. });
  1291. }
  1292. };
  1293. //打印
  1294. $scope.print = function(order) {
  1295. PurcOrder.printCount({id: order.id},{});//增加打印此次
  1296. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  1297. ReportService.print(order.enUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
  1298. };
  1299. $scope.getReply = function(item) {
  1300. if(!item.replies) {
  1301. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1302. item.replies = replies;
  1303. });
  1304. }
  1305. };
  1306. $scope.checkboxes = {
  1307. checked : false
  1308. };
  1309. // 点击勾选全部的复选框
  1310. $scope.checkAll = function(){
  1311. angular.forEach($scope.tableParams.data, function(item) {
  1312. item.$selected = $scope.checkboxes.checked;
  1313. });
  1314. };
  1315. // 点击其中一个明细的复选框
  1316. $scope.checkOne = function(order){
  1317. var result = true;
  1318. angular.forEach($scope.tableParams.data, function(item) {
  1319. if(item.$selected != true){
  1320. result = false;
  1321. return;
  1322. }
  1323. });
  1324. $scope.checkboxes.checked = result;
  1325. };
  1326. //批量回复采购订单
  1327. $scope.replyByBatch = function() {
  1328. $scope.loading = true;
  1329. var str = '';
  1330. angular.forEach($scope.tableParams.data, function(order) {
  1331. if(order.$selected == true) {
  1332. angular.forEach(order.orderItems, function(item){
  1333. str += item.id;
  1334. str += ',';
  1335. });
  1336. }
  1337. });
  1338. if(!(str == '')) {
  1339. str = str.substr(0, str.length-1);
  1340. PurcOrderItem.replyByBatch(str, function(){
  1341. $scope.loading = false;
  1342. $scope.tableParams.reload();
  1343. toaster.pop('success', '提示', '批量回复成功');
  1344. }, function(data){
  1345. $scope.loading = false;
  1346. toaster.pop('error', '批量回复失败', data);
  1347. });
  1348. } else {//没有勾选其中的明细
  1349. $scope.loading = false;
  1350. }
  1351. };
  1352. // 搜索框回车
  1353. $scope.onSearch = function() {
  1354. $scope.tableParams.page(1);
  1355. $scope.tableParams.reload();
  1356. };
  1357. // 选择查找日期
  1358. $scope.onDateCondition = function(){
  1359. $scope.tableParams.page(1);
  1360. $scope.tableParams.reload();
  1361. };
  1362. //设置为已查看
  1363. $scope.setDisplay = function(state, orderId) {
  1364. if(orderId) {//设置单个
  1365. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1366. $scope.tableParams.reload();
  1367. }, function() {
  1368. toaster.pop('error', '错误', "设置失败");
  1369. });
  1370. } else {//设置已勾选的
  1371. var str = null;
  1372. angular.forEach($scope.tableParams.data, function(order) {
  1373. if(order.$selected == true) {
  1374. if(str != null && str != '') str += ',';
  1375. str += order.id;
  1376. }
  1377. });
  1378. if(str != null && str != '') {
  1379. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1380. $scope.tableParams.reload();
  1381. }, function() {
  1382. toaster.pop('error', '错误', "设置失败");
  1383. });
  1384. }
  1385. }
  1386. };
  1387. }]);
  1388. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1389. var loadData = function() {
  1390. PurcOrder.get({id: $stateParams.id}, function(data){
  1391. $scope.order = data;
  1392. var sum = 0;
  1393. angular.forEach($scope.order.orderItems, function(item){
  1394. sum += item.qty * item.price;
  1395. });
  1396. $scope.order.total = sum;
  1397. if($scope.order.display == 1) {//未查看的设为已查看
  1398. $scope.setDisplay('setRead', $scope.order.id);
  1399. }
  1400. $scope.loading = false;
  1401. });
  1402. };
  1403. loadData();
  1404. $scope.getReply = function(item) {
  1405. if(!item.replies) {
  1406. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1407. item.replies = replies;
  1408. });
  1409. }
  1410. };
  1411. $scope.openDatePicker = function($event, item, openParam) {
  1412. $event.preventDefault();
  1413. $event.stopPropagation();
  1414. item[openParam] = !item[openParam];
  1415. };
  1416. $scope.onReplyClick = function(item, inverse) {
  1417. if(item.reply) {
  1418. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1419. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1420. return;
  1421. }
  1422. var reply = angular.copy(item.reply);
  1423. if(reply.delivery) {
  1424. if(typeof reply.delivery == 'object')
  1425. reply.delivery = reply.delivery.getTime();
  1426. } else {
  1427. reply.delivery = item.delivery;
  1428. }
  1429. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1430. $scope.loading = true;
  1431. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1432. $scope.loading = false;
  1433. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1434. loadData();
  1435. }, function(response){
  1436. $scope.loading = false;
  1437. toaster.pop('error', '回复失败', response.data);
  1438. });
  1439. }
  1440. };
  1441. $scope.print = function(order) {
  1442. PurcOrder.printCount({id: order.id},{});//增加打印此次
  1443. ReportService.print(order.enUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
  1444. };
  1445. //设置为已查看
  1446. $scope.setDisplay = function(state, orderId) {
  1447. if(orderId) {//设置单个
  1448. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1449. $scope.tableParams.reload();
  1450. }, function() {
  1451. toaster.pop('error', '错误', "设置失败");
  1452. });
  1453. } else {//设置已勾选的
  1454. var str = null;
  1455. angular.forEach($scope.tableParams.data, function(order) {
  1456. if(order.$selected == true) {
  1457. if(str != null && str != '') str += ',';
  1458. str += order.id;
  1459. }
  1460. });
  1461. if(str != null && str != '') {
  1462. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1463. $scope.tableParams.reload();
  1464. }, function() {
  1465. toaster.pop('error', '错误', "设置失败");
  1466. });
  1467. }
  1468. }
  1469. };
  1470. }]);
  1471. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  1472. $scope.active = 'todo';
  1473. $scope.agreedText = '全部';
  1474. $scope.dateZoneText = '一个月内';
  1475. $scope.condition = {dateZone: 1};
  1476. $scope.changeAgreed = function(agreed) {
  1477. $scope.condition.agreed = agreed;
  1478. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  1479. $scope.condition.$agreedOpen = false;
  1480. };
  1481. $scope.changeDateZone = function(zone) {
  1482. $scope.condition.dateZone = zone;
  1483. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1484. $scope.condition.$dateZoneOpen = false;
  1485. };
  1486. $scope.setActive = function(state) {
  1487. if($scope.active != state) {
  1488. $scope.active = state;
  1489. if($scope.tableParams.page() == 1)
  1490. $scope.tableParams.reload();
  1491. else
  1492. $scope.tableParams.page(1);
  1493. }
  1494. };
  1495. var getService = function() {
  1496. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  1497. };
  1498. $scope.tableParams = new ngTableParams({
  1499. page : 1,
  1500. count : 5,
  1501. sorting: {
  1502. date: 'desc'
  1503. }
  1504. }, {
  1505. total : 0,
  1506. counts: [5, 10, 25, 50],
  1507. getData : function($defer, params) {
  1508. $scope.loading = true;
  1509. var pageParams = params.url();
  1510. pageParams.keyword = $scope.keyword;
  1511. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1512. $scope.loading = false;
  1513. if(page) {
  1514. params.total(page.totalElements);
  1515. $defer.resolve(page.content);
  1516. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1517. }
  1518. }, function(response){
  1519. $scope.loading = false;
  1520. toaster.pop('error', '数据加载失败', response.data);
  1521. });
  1522. }
  1523. });
  1524. $scope.openDatePicker = function($event, item, openParam) {
  1525. $event.preventDefault();
  1526. $event.stopPropagation();
  1527. item[openParam] = !item[openParam];
  1528. };
  1529. $scope.onReplyClick = function(change) {
  1530. if(change.$agreed) {
  1531. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1532. $scope.loading = true;
  1533. PurcChange.reply({changeId: change.id}, reply, function(){
  1534. $scope.loading = false;
  1535. toaster.pop('info', '提示', '回复成功');
  1536. $scope.tableParams.reload();
  1537. }, function(response){
  1538. $scope.loading = false;
  1539. toaster.pop('error', '回复失败', response.data);
  1540. });
  1541. }
  1542. };
  1543. // 搜索框回车
  1544. $scope.onSearch = function() {
  1545. $scope.tableParams.page(1);
  1546. $scope.tableParams.reload();
  1547. };
  1548. }]);
  1549. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  1550. var loadData = function() {
  1551. PurcChange.get({id: $stateParams.id}, function(data){
  1552. $scope.change = data;
  1553. });
  1554. };
  1555. loadData();
  1556. $scope.openDatePicker = function($event, item, openParam) {
  1557. $event.preventDefault();
  1558. $event.stopPropagation();
  1559. item[openParam] = !item[openParam];
  1560. };
  1561. $scope.onReplyClick = function(change) {
  1562. if(change.$agreed) {
  1563. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1564. PurcChange.reply({changeId: change.id}, reply, function(){
  1565. toaster.pop('info', '提示', '回复成功');
  1566. loadData();
  1567. }, function(response){
  1568. toaster.pop('error', '回复失败', response.data);
  1569. });
  1570. }
  1571. };
  1572. }]);
  1573. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  1574. $scope.active = 'todo';
  1575. $scope.agreedText = '全部';
  1576. $scope.dateZoneText = '一个月内';
  1577. $scope.condition = {dateZone: 1};
  1578. $scope.changeAgreed = function(agreed) {
  1579. $scope.condition.agreed = agreed;
  1580. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  1581. $scope.condition.$agreedOpen = false;
  1582. };
  1583. $scope.changeDateZone = function(zone) {
  1584. $scope.condition.dateZone = zone;
  1585. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1586. $scope.condition.$dateZoneOpen = false;
  1587. };
  1588. $scope.setActive = function(state) {
  1589. if($scope.active != state) {
  1590. $scope.active = state;
  1591. if($scope.tableParams.page() == 1)
  1592. $scope.tableParams.reload();
  1593. else
  1594. $scope.tableParams.page(1);
  1595. }
  1596. };
  1597. var getService = function() {
  1598. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  1599. };
  1600. $scope.tableParams = new ngTableParams({
  1601. page : 1,
  1602. count : 5,
  1603. sorting: {
  1604. 'inquiry.date': 'desc',
  1605. 'inquiry.enterprise.enName': 'asc',
  1606. 'inquiry.code': 'asc'
  1607. }
  1608. }, {
  1609. total : 0,
  1610. counts: [5, 10, 25, 50],
  1611. getData : function($defer, params) {
  1612. $scope.loading = true;
  1613. var pageParams = params.url();
  1614. var realActive = {};
  1615. pageParams.keyword = $scope.keyword;
  1616. if ($scope.active == 'overdue') {
  1617. $scope.active = 'end';
  1618. }
  1619. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1620. $scope.loading = false;
  1621. if(page) {
  1622. params.total(page.totalElements);
  1623. $defer.resolve(page.content);
  1624. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1625. }
  1626. }, function(response){
  1627. $scope.loading = false;
  1628. toaster.pop('error', '数据加载失败', response.data);
  1629. });
  1630. }
  1631. });
  1632. $scope.getMinDate = function(item) {
  1633. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  1634. };
  1635. $scope.replyPrices = [];
  1636. $scope.replylapQtys = [];
  1637. $scope.replyPrices.push(true);
  1638. $scope.replylapQtys.push(true);
  1639. $scope.addStep = function(inquiryItem) {
  1640. $scope.replyPrices.push(true);
  1641. if(inquiryItem.replies.length >= 10) {
  1642. toaster.pop('warning', '提示', '最多支持10个分段!');
  1643. } else {
  1644. inquiryItem.replies.push({});
  1645. if(inquiryItem.replies.length != 1) {
  1646. $scope.replyPrices.push(true);
  1647. $scope.replylapQtys.push(true);
  1648. }
  1649. }
  1650. };
  1651. $scope.removeStep = function(inquiryItem, stepIndex) {
  1652. inquiryItem.replies.splice(stepIndex, 1);
  1653. $scope.replyPrices.splice(stepIndex, 1);
  1654. $scope.replylapQtys.splice(stepIndex, 1);
  1655. };
  1656. $scope.openDatePicker = function($event, item, openParam) {
  1657. $event.preventDefault();
  1658. $event.stopPropagation();
  1659. item[openParam] = !item[openParam];
  1660. };
  1661. $scope.getHistory = function(item) {
  1662. if(!item.history) {
  1663. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1664. item.history = data;
  1665. });
  1666. }
  1667. };
  1668. $scope.isValid = function(item, withSteps) {
  1669. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1670. if(!withSteps || !bool)
  1671. return bool;
  1672. angular.forEach(item.replies, function(r, i){
  1673. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1674. });
  1675. return bool;
  1676. };
  1677. $scope.onReplyClick = function(item, withSteps) {
  1678. if(item.vendFromDate instanceof Date) {
  1679. item.vendFromDate = item.vendFromDate.getTime();
  1680. }
  1681. if(item.vendToDate instanceof Date) {
  1682. item.vendToDate = item.vendToDate.getTime();
  1683. }
  1684. if(item.vendFromDate > item.vendToDate) {
  1685. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  1686. return;
  1687. }
  1688. var replies = [];
  1689. angular.forEach(item.replies, function(r, i){
  1690. if((i > 0 ? r.lapQty : 1) || r.price)
  1691. replies.push(r);
  1692. });
  1693. item.replies = replies;
  1694. $scope.loading = true;
  1695. if(withSteps) {
  1696. PurcInquiry.reply({itemId: item.id}, item, function(){
  1697. $scope.loading = false;
  1698. toaster.pop('info', '提示', '报价成功');
  1699. $scope.tableParams.reload();
  1700. }, function(response){
  1701. $scope.loading = false;
  1702. toaster.pop('error', '报价失败', response.data);
  1703. });
  1704. } else {
  1705. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  1706. $scope.loading = false;
  1707. toaster.pop('info', '提示', '保存成功');
  1708. $scope.tableParams.reload();
  1709. }, function(response){
  1710. $scope.loading = false;
  1711. toaster.pop('error', '保存失败', response.data);
  1712. });
  1713. }
  1714. };
  1715. $scope.verifylapQty = function(value,type) {
  1716. var regex = /^\d+(.\d{1,5})?$/;
  1717. $scope.replylapQtys[type] = regex.test(value);
  1718. }
  1719. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  1720. $scope.verify = function(value,type) {
  1721. var regex = /^\d+(.\d{1,5})?$/;//
  1722. switch(type) {
  1723. case 'minOrderQty':
  1724. $scope.minOrderQtyVerify = regex.test(value);
  1725. break;
  1726. case 'minPackQty':
  1727. $scope.minPackQtyVerify = regex.test(value);
  1728. break;
  1729. case 'leadtime':
  1730. $scope.leadtimeVerify = regex.test(value);
  1731. break;
  1732. default:
  1733. $scope.replyPrices[type] = regex.test(value);
  1734. break;
  1735. }
  1736. }
  1737. // 搜索框回车
  1738. $scope.onSearch = function() {
  1739. $scope.tableParams.page(1);
  1740. $scope.tableParams.reload();
  1741. };
  1742. }]);
  1743. // 询价单明细
  1744. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  1745. var loadData = function() {
  1746. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  1747. $scope.newinquiryItems = data;
  1748. var inquiry = data[0].inquiry;
  1749. //inquiry.inquiryItems = data;
  1750. angular.forEach(inquiry.attachs, function(attach){
  1751. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  1752. });
  1753. $scope.inquiry = inquiry;
  1754. });
  1755. };
  1756. loadData();
  1757. $scope.getMinDate = function(item) {
  1758. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  1759. };
  1760. $scope.addStep = function(inquiryItem) {
  1761. if(inquiryItem.replies.length >= 10) {
  1762. toaster.pop('warning', '提示', '最多支持10个分段!');
  1763. } else
  1764. inquiryItem.replies.push({});
  1765. };
  1766. $scope.removeStep = function(inquiryItem, stepIndex) {
  1767. inquiryItem.replies.splice(stepIndex, 1);
  1768. };
  1769. $scope.openDatePicker = function($event, item, openParam) {
  1770. $event.preventDefault();
  1771. $event.stopPropagation();
  1772. item[openParam] = !item[openParam];
  1773. };
  1774. $scope.getHistory = function(item) {
  1775. if(!item.history) {
  1776. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1777. item.history = data;
  1778. });
  1779. }
  1780. };
  1781. $scope.isValid = function(item, withSteps) {
  1782. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1783. if(!withSteps || !bool)
  1784. return bool;
  1785. angular.forEach(item.replies, function(r, i){
  1786. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1787. });
  1788. return bool;
  1789. };
  1790. $scope.onReplyClick = function(item, withSteps) {
  1791. if(item.vendFromDate instanceof Date) {
  1792. item.vendFromDate = item.vendFromDate.getTime();
  1793. }
  1794. if(item.vendToDate instanceof Date) {
  1795. item.vendToDate = item.vendToDate.getTime();
  1796. }
  1797. if(item.vendFromDate > item.vendToDate) {
  1798. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  1799. return;
  1800. }
  1801. var replies = [];
  1802. angular.forEach(item.replies, function(r, i){
  1803. if((i > 0 ? r.lapQty : 1) || r.price)
  1804. replies.push(r);
  1805. });
  1806. item.replies = replies;
  1807. if(withSteps) {
  1808. PurcInquiry.reply({itemId: item.id}, item, function(){
  1809. toaster.pop('info', '提示', '报价成功');
  1810. loadData();
  1811. }, function(response){
  1812. toaster.pop('error', '报价失败', response.data);
  1813. });
  1814. }
  1815. };
  1816. }]);
  1817. // 主动报价 - 列表
  1818. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  1819. $scope.active = 'todo';
  1820. $scope.agreedText = '全部';
  1821. $scope.dateZoneText = '一个月内';
  1822. $scope.condition = {dateZone: 1};
  1823. $scope.changeDateZone = function(zone) {
  1824. $scope.condition.dateZone = zone;
  1825. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1826. $scope.condition.$dateZoneOpen = false;
  1827. };
  1828. $scope.setActive = function(state) {
  1829. if($scope.active != state) {
  1830. $scope.active = state;
  1831. if($scope.tableParams.page() == 1)
  1832. $scope.tableParams.reload();
  1833. else
  1834. $scope.tableParams.page(1);
  1835. }
  1836. };
  1837. var getService = function() {
  1838. return Quotation;
  1839. };
  1840. $scope.tableParams = new ngTableParams({
  1841. page : 1,
  1842. count : 5,
  1843. sorting: {
  1844. 'quotation.date': 'desc'
  1845. }
  1846. }, {
  1847. total : 0,
  1848. counts: [5, 10, 25, 50],
  1849. getData : function($defer, params) {
  1850. $scope.loading = true;
  1851. var pageParams = params.url();
  1852. pageParams.keyword = $scope.keyword;
  1853. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1854. $scope.loading = false;
  1855. if(page) {
  1856. params.total(page.totalElements);
  1857. $defer.resolve(page.content);
  1858. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1859. }
  1860. }, function(response){
  1861. $scope.loading = false;
  1862. toaster.pop('error', '数据加载失败', response.data);
  1863. });
  1864. }
  1865. });
  1866. $scope.getHistory = function(item) {
  1867. if(!item.history) {
  1868. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1869. item.history = data;
  1870. });
  1871. }
  1872. };
  1873. $scope.isValid = function(item, withSteps) {
  1874. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1875. if(!withSteps || !bool)
  1876. return bool;
  1877. angular.forEach(item.replies, function(r, i){
  1878. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1879. });
  1880. return bool;
  1881. };
  1882. // 搜索框回车
  1883. $scope.onSearch = function() {
  1884. $scope.tableParams.page(1);
  1885. $scope.tableParams.reload();
  1886. };
  1887. }]);
  1888. // Controller 主动报价 - 新增
  1889. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
  1890. var staticItem = null;
  1891. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  1892. $scope.loading = true;
  1893. Quotation.getItem({id: $stateParams.id}, function(data){
  1894. data.$editing = false;
  1895. $scope.item = data;
  1896. staticItem = angular.copy(data);
  1897. $scope.loading = false;
  1898. }, function(response){
  1899. $scope.loading = false;
  1900. toaster.pop('error', '数据加载失败', response.data);
  1901. });
  1902. } else {// 新增模式
  1903. $scope.item = {
  1904. quotation: {
  1905. currency: 'RMB',
  1906. taxrate: 17,
  1907. date: new Date()
  1908. },
  1909. product: {},
  1910. prices: [{lapQty: 0}],
  1911. minOrderQty: 1,
  1912. minPackQty: 1,
  1913. $endDateOpen: false,
  1914. $editing: true
  1915. };
  1916. }
  1917. $scope.getMinDate = function(item) {
  1918. return $filter('date')(new Date, 'yyyy-MM-dd');
  1919. };
  1920. $scope.openDatePicker = function($event, openParam) {
  1921. $event.preventDefault();
  1922. $event.stopPropagation();
  1923. $scope.item.$endDateOpen = !openParam;
  1924. };
  1925. // 增加一个分段
  1926. $scope.addPrice = function(){
  1927. if($scope.item.prices.length >= 10) {
  1928. toaster.pop('warning', '提示', '最多支持10个分段!');
  1929. } else
  1930. $scope.item.prices.push({});
  1931. };
  1932. // 删除一个分段
  1933. $scope.removePrice = function(index) {
  1934. $scope.item.prices.splice(index, 1);
  1935. };
  1936. // 查找客户
  1937. $scope.dbfindCust = function(){
  1938. if($scope.item.$editing) {
  1939. var modalInstance = $modal.open({
  1940. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  1941. controller: 'DbfindCustCtrl',
  1942. size: 'lg',
  1943. resolve: {
  1944. }
  1945. });
  1946. modalInstance.result.then(function(data){
  1947. $scope.item.quotation.cust = data.myEnterprise;
  1948. $scope.item.quotation.custUser = data.myUser;
  1949. $scope.item.product = null;
  1950. }, function(){
  1951. });
  1952. }
  1953. };
  1954. // 查找客户物料
  1955. $scope.dbfindCustProd = function(){
  1956. if($scope.item.$editing) {
  1957. if($scope.item.quotation.cust.uu) {
  1958. var modalInstance = $modal.open({
  1959. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  1960. controller: 'DbfindCustProdCtrl',
  1961. size: 'lg',
  1962. resolve: {
  1963. custUU: function(){return $scope.item.quotation.cust.uu}
  1964. }
  1965. });
  1966. modalInstance.result.then(function(data){
  1967. $scope.item.product = data;
  1968. }, function(){
  1969. });
  1970. } else {
  1971. toaster.pop('error', '错误', '请先选择客户');
  1972. }
  1973. }
  1974. };
  1975. // 保存
  1976. $scope.save = function(){
  1977. $scope.loading = true;
  1978. if(!$scope.item.quotation.code) //新增,设单号
  1979. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  1980. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  1981. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  1982. $scope.item.productId = $scope.item.product.id;
  1983. $scope.item.quotation.status = 100;//在录入
  1984. if($scope.item.quotation.date instanceof Date) {
  1985. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  1986. }
  1987. if($scope.item.quotation.endDate instanceof Date) {
  1988. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  1989. }
  1990. Quotation.save({}, $scope.item, function(data){
  1991. $scope.loading = false;
  1992. toaster.pop('success', '成功', '保存成功');
  1993. if($stateParams.id)
  1994. window.location.reload();
  1995. else
  1996. window.location.hash = '#/sale/quotation/' + data.id;
  1997. }, function(response){
  1998. $scope.loading = false;
  1999. toaster.pop('error', '保存失败', response.data);
  2000. });
  2001. };
  2002. // 更新
  2003. $scope.update = function(){
  2004. $scope.item.$editing = true;
  2005. };
  2006. // 取消
  2007. $scope.cancel = function(){
  2008. $scope.item.$editing = false;
  2009. $scope.item = angular.copy(staticItem);
  2010. };
  2011. // 提交
  2012. $scope.submit = function(){
  2013. $scope.loading = true;
  2014. $scope.item.quotation.status = 101;//在录入
  2015. Quotation.save({}, $scope.item, function(data){
  2016. $scope.loading = false;
  2017. toaster.pop('success', '成功', '提交成功');
  2018. window.location.hash = '#/sale/quotation/' + data.id;
  2019. }, function(response){
  2020. $scope.loading = false;
  2021. toaster.pop('error', '保存失败', response.data);
  2022. });
  2023. };
  2024. }]);
  2025. // 查找客户
  2026. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  2027. $scope.tableParams = new ngTableParams({
  2028. page : 1,
  2029. count : 10
  2030. }, {
  2031. total : 0,
  2032. counts: [5, 10, 25, 50],
  2033. getData : function($defer, params) {
  2034. $scope.loading = true;
  2035. Customer.get(BaseService.parseParams(params.url()), function(page){
  2036. $scope.loading = false;
  2037. if(page) {
  2038. params.total(page.totalElements);
  2039. $defer.resolve(page.content);
  2040. }
  2041. $scope.totalCount = page.totalElements;
  2042. }, function(response){
  2043. $scope.loading = false;
  2044. toaster.pop('error', '数据加载失败', response.data);
  2045. });
  2046. }
  2047. });
  2048. $scope.cancel = function() {
  2049. $modalInstance.dismiss();
  2050. };
  2051. $scope.check = function(cust){
  2052. $modalInstance.close(cust);
  2053. };
  2054. }]);
  2055. // 查找客户物料
  2056. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  2057. $scope.tableParams = new ngTableParams({
  2058. page : 1,
  2059. count : 10
  2060. }, {
  2061. total : 0,
  2062. counts: [5, 10, 25, 50],
  2063. getData : function($defer, params) {
  2064. $scope.loading = true;
  2065. var pageParams = params.url();
  2066. pageParams.keyword = $scope.keyword;
  2067. pageParams.custUU = custUU;
  2068. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  2069. $scope.loading = false;
  2070. if(page) {
  2071. params.total(page.totalElements);
  2072. $defer.resolve(page.content);
  2073. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2074. }
  2075. }, function(response){
  2076. $scope.loading = false;
  2077. toaster.pop('error', '数据加载失败', response.data);
  2078. });
  2079. }
  2080. });
  2081. // 取消
  2082. $scope.cancel = function() {
  2083. $modalInstance.dismiss();
  2084. };
  2085. // 选择
  2086. $scope.check = function(cust){
  2087. $modalInstance.close(cust);
  2088. };
  2089. // 搜索框回车
  2090. $scope.onSearch = function() {
  2091. $scope.tableParams.page(1);
  2092. $scope.tableParams.reload();
  2093. };
  2094. }]);
  2095. // 发货提醒
  2096. 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){
  2097. $scope.active = 'todo';
  2098. $scope.currency = Symbol.currency;
  2099. $scope.dateZoneText = '不限';
  2100. $scope.condition = {dateZone: -1};
  2101. $scope.changeDateZone = function(zone) {
  2102. $scope.condition.dateZone = zone;
  2103. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2104. $scope.condition.$dateZoneOpen = false;
  2105. getDateCondition(zone, $scope.condition);
  2106. $scope.tableParams.reload();
  2107. };
  2108. $scope.setActive = function(state) {
  2109. if($scope.active != state) {
  2110. $scope.active = state;
  2111. if($scope.tableParams.page() == 1)
  2112. $scope.tableParams.reload();
  2113. else
  2114. $scope.tableParams.page(1);
  2115. }
  2116. };
  2117. var getService = function() {
  2118. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  2119. };
  2120. $scope.tableParams = new ngTableParams({
  2121. page : 1,
  2122. count : 5,
  2123. sorting: {
  2124. 'delivery': 'asc',
  2125. 'orderItemOrderCode': 'asc',
  2126. 'orderItemNumber': 'asc'
  2127. }
  2128. }, {
  2129. total : 0,
  2130. counts: [5, 10, 25, 50],
  2131. getData : function($defer, params) {
  2132. $scope.loading = true;
  2133. var pageParams = params.url();
  2134. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2135. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2136. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2137. $scope.loading = false;
  2138. if(page) {
  2139. params.total(page.totalElements);
  2140. $defer.resolve(page.content);
  2141. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2142. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2143. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2144. }
  2145. }, function(response){
  2146. $scope.loading = false;
  2147. toaster.pop('error', '数据加载失败', response.data);
  2148. });
  2149. }
  2150. });
  2151. $scope.openDatePicker = function($event, item, openParam) {
  2152. $event.preventDefault();
  2153. $event.stopPropagation();
  2154. item[openParam] = !item[openParam];
  2155. };
  2156. //生成随机单号
  2157. $scope.autoCode = function(notice){
  2158. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  2159. };
  2160. //可送货日期
  2161. $scope.sendDate = function(notice) {
  2162. var stock = notice.orderItem.product.ltinstock || 0;
  2163. var de = new Date(notice.delivery);
  2164. if(stock == -1) {
  2165. de.setMonth(de.getMonth() -1);
  2166. de.setDate(25);
  2167. } else if(stock >= 0) {
  2168. de.setDate(de.getDate() - stock -1);
  2169. }
  2170. return de;
  2171. };
  2172. $scope.onReplyClick = function(notice) {
  2173. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  2174. toaster.pop('warning', '警告', '数量填写错误!');
  2175. } else if(!notice.send.code) {
  2176. toaster.pop('warning', '警告', '请填写发货单号!');
  2177. } else {
  2178. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  2179. $scope.loading = true;
  2180. PurcNotice.save({id: notice.id}, send, function(data){
  2181. $scope.loading = false;
  2182. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  2183. $state.go('sale.send_detail', {id: data.id});
  2184. }, function(response){
  2185. $scope.loading = false;
  2186. toaster.pop('error', '发货失败', response.data);
  2187. });
  2188. }
  2189. };
  2190. $scope.checkboxes = {
  2191. checked : false
  2192. };
  2193. // 点击勾选全部的复选框
  2194. $scope.checkAll = function(){
  2195. angular.forEach($scope.tableParams.data, function(item) {
  2196. if(!item.waiting)
  2197. item.$selected = $scope.checkboxes.checked;
  2198. });
  2199. };
  2200. // 点击其中一个明细的复选框
  2201. $scope.checkOne = function(order){
  2202. var result = true;
  2203. angular.forEach($scope.tableParams.data, function(item) {
  2204. if(item.$selected != true){
  2205. result = false;
  2206. return;
  2207. }
  2208. });
  2209. $scope.checkboxes.checked = result;
  2210. };
  2211. $scope.sendByBatch = function(){
  2212. var modalInstance = $modal.open({
  2213. animation: true,
  2214. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  2215. controller: 'SaleNoticeSendByBatchCtrl',
  2216. size: 'lg',
  2217. resolve: {
  2218. selectedNotices: function(){return $scope.tableParams.data;}
  2219. }
  2220. });
  2221. modalInstance.result.then(function(){
  2222. $scope.tableParams.reload();
  2223. }, function(){
  2224. });
  2225. };
  2226. $scope.getSends = function(notice){
  2227. if( ! notice.sends && notice.endQty > 0){
  2228. notice.getSendsing = true;
  2229. notice.getSendsError = false;
  2230. PurcNotice.getSends({id: notice.id}, function(data){
  2231. notice.getSendsing = false;
  2232. notice.getSendsError = false;
  2233. notice.sends = data;
  2234. }, function(response){
  2235. notice.getSendsing = false;
  2236. notice.getSendsError = true;
  2237. });
  2238. }
  2239. };
  2240. // 搜索框回车
  2241. $scope.onSearch = function() {
  2242. $scope.tableParams.page(1);
  2243. $scope.tableParams.reload();
  2244. };
  2245. // 选择查找日期
  2246. $scope.onDateCondition = function(){
  2247. $scope.tableParams.page(1);
  2248. $scope.tableParams.reload();
  2249. };
  2250. //货车功能
  2251. var truck = $rootScope.truck;
  2252. if(!truck) {
  2253. SaleTruck.query({}, function(data){
  2254. $rootScope.truck = data;
  2255. });
  2256. }
  2257. $scope.isInTruck = function(noticeId) {
  2258. return truck.indexOf(noticeId) > -1;
  2259. };
  2260. $scope.addtoTruck = function(notice) {
  2261. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  2262. $rootScope.truck = data;
  2263. });
  2264. };
  2265. $scope.delFromTruck = function(notice) {
  2266. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  2267. $rootScope.truck = data;
  2268. });
  2269. };
  2270. $scope.$watch(function(){
  2271. return $rootScope.truck;
  2272. }, function(data) {
  2273. truck = $rootScope.truck;
  2274. }, true);
  2275. $scope.$watch(function(){
  2276. return $rootScope.dataChanged;
  2277. }, function(data) {
  2278. data && ($scope.tableParams.reload());
  2279. }, true);
  2280. }]);
  2281. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  2282. $scope.notices = angular.copy(selectedNotices);
  2283. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2284. $scope.saleSend = {
  2285. code: '',
  2286. payments: '',
  2287. currency: '',
  2288. custUU: null,
  2289. custUserUU: null,
  2290. remark: '批量发货',
  2291. sendItems: []
  2292. };
  2293. // 计算总数、总额
  2294. $scope.$watch(function(){
  2295. return $scope.notices;
  2296. }, function(data) {
  2297. var q = 0, t = 0;
  2298. if(data) {
  2299. angular.forEach(data,function(d){
  2300. q += (d.thisSendQty || 0);
  2301. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  2302. });
  2303. }
  2304. $scope.totalQty = q;
  2305. $scope.total = t;
  2306. }, true);
  2307. /**
  2308. * 删除一个已选中的送货提醒
  2309. */
  2310. $scope.removeOne = function(index) {
  2311. $scope.notices.splice(index, 1);
  2312. };
  2313. //确认送货
  2314. $scope.sendByBatch = function () {
  2315. $scope.saleSend.sendItems = [];
  2316. if($scope.saleSend.code == '') {//送货单号为空
  2317. toaster.pop('error', '错误', '请输入送货单号');
  2318. return;
  2319. }
  2320. var a = 0;
  2321. var num = 1;
  2322. var valid = true;
  2323. angular.forEach($scope.notices, function(item, key){
  2324. if(item.$selected) {
  2325. if(a == 0) {//第一次
  2326. $scope.saleSend.currency = item.orderItem.order.currency;
  2327. $scope.saleSend.custUU = item.enUU;
  2328. $scope.saleSend.payments = item.orderItem.order.payments;
  2329. a = 1;
  2330. } else {//其他
  2331. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  2332. if($scope.saleSend.custUU != item.enUU) valid = false;
  2333. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  2334. }
  2335. $scope.saleSend.sendItems.push({
  2336. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  2337. });
  2338. }
  2339. });
  2340. if(!valid) {
  2341. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  2342. } else {
  2343. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  2344. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  2345. $modalInstance.close('success');
  2346. $state.go('sale.send_detail', {id: data.id});
  2347. }, function(response){
  2348. toaster.pop('error', '错误', response.data);
  2349. });
  2350. }
  2351. };
  2352. $scope.cancel = function () {
  2353. $modalInstance.dismiss();
  2354. };
  2355. }]);
  2356. /**
  2357. * 发货单
  2358. */
  2359. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  2360. $scope.active = 'all';
  2361. $scope.currency = Symbol.currency;
  2362. $scope.dateZoneText = '不限';
  2363. $scope.condition = {dateZone: -1};
  2364. $scope.changeDateZone = function(zone) {
  2365. $scope.condition.dateZone = zone;
  2366. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2367. $scope.condition.$dateZoneOpen = false;
  2368. getDateCondition(zone, $scope.condition);
  2369. $scope.tableParams.reload();
  2370. };
  2371. $scope.setActive = function(state) {
  2372. if($scope.active != state) {
  2373. $scope.active = state;
  2374. if($scope.tableParams.page() == 1)
  2375. $scope.tableParams.reload();
  2376. else
  2377. $scope.tableParams.page(1);
  2378. }
  2379. };
  2380. var getService = function() {
  2381. return SaleSend;
  2382. };
  2383. $scope.tableParams = new ngTableParams({
  2384. page : 1,
  2385. count : 5,
  2386. sorting: {
  2387. date: 'desc'
  2388. }
  2389. }, {
  2390. total : 0,
  2391. counts: [5, 10, 25, 50],
  2392. getData : function($defer, params) {
  2393. $scope.loading = true;
  2394. var pageParams = params.url();
  2395. pageParams.keyword = $scope.keyword;
  2396. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2397. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2398. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2399. $scope.loading = false;
  2400. if(page) {
  2401. params.total(page.totalElements);
  2402. $defer.resolve(page.content);
  2403. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2404. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2405. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2406. }
  2407. }, function(response){
  2408. $scope.loading = false;
  2409. toaster.pop('error', '数据加载失败', response.data);
  2410. });
  2411. }
  2412. });
  2413. $scope.openDatePicker = function($event, item, openParam) {
  2414. $event.preventDefault();
  2415. $event.stopPropagation();
  2416. item[openParam] = !item[openParam];
  2417. };
  2418. // 搜索框回车
  2419. $scope.onSearch = function() {
  2420. $scope.tableParams.page(1);
  2421. $scope.tableParams.reload();
  2422. };
  2423. // 选择查找日期
  2424. $scope.onDateCondition = function(){
  2425. $scope.tableParams.page(1);
  2426. $scope.tableParams.reload();
  2427. };
  2428. }]);
  2429. /**
  2430. * 发货单(包括发货条码维护)
  2431. */
  2432. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  2433. var loading = true;
  2434. $scope.checkBarCode = [];
  2435. $scope.checkBoxCode = [];
  2436. var vm = $scope.vm = {};
  2437. $scope.getCheckedItems = {};
  2438. vm.editBar = false;
  2439. vm.showBarCode = [];
  2440. $scope.barCode = function() {
  2441. vm.editBar = !vm.editBar;
  2442. }
  2443. $scope.checkboxes = {
  2444. checked : false
  2445. };
  2446. $scope.checkbars = {
  2447. checked : false
  2448. };
  2449. // 点击勾选barCode全部的复选框
  2450. $scope.checkBarAll = function(){
  2451. angular.forEach($scope.checkBarCode, function(item,key) {
  2452. $scope.checkBarCode[key] = $scope.checkbars.checked;
  2453. });
  2454. };
  2455. //点击barCode单选
  2456. $scope.checkBarOne = function() {
  2457. var result = true;
  2458. angular.forEach($scope.checkBarCode, function(item,key) {
  2459. if(item != true){
  2460. result = false;
  2461. return;
  2462. }
  2463. });
  2464. $scope.checkbars.checked = result;
  2465. }
  2466. // 点击boxCode全部的复选框
  2467. $scope.checkBoxAll = function(){
  2468. angular.forEach($scope.checkBoxCode, function(item,key) {
  2469. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  2470. });
  2471. };
  2472. //点击boxCode单选
  2473. $scope.checkBoxOne = function() {
  2474. var result = true;
  2475. angular.forEach($scope.checkBoxCode, function(item) {
  2476. if(item != true){
  2477. result = false;
  2478. return;
  2479. }
  2480. });
  2481. $scope.checkboxes.checked = result;
  2482. }
  2483. /**
  2484. * 生成条码和箱号
  2485. */
  2486. $scope.generateBarCode = function(item) {
  2487. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  2488. $scope.getCheckedItems = [];
  2489. var warningdata = '';
  2490. angular.forEach($scope.checkBarCode, function(item,key) {
  2491. $scope.getCheckedItem = {};
  2492. if(item == true ){
  2493. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  2494. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  2495. $scope.getCheckedItems.push($scope.getCheckedItem);
  2496. //判断是否生成过条码
  2497. if($scope.order.sendItems[key].barSendNotify.length > 0){
  2498. warningdata += $scope.order.sendItems[key].number+","
  2499. }
  2500. }
  2501. });
  2502. if($scope.getCheckedItems.length == 0){
  2503. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  2504. return;
  2505. }
  2506. if(warningdata != ''){
  2507. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  2508. return ;
  2509. }
  2510. }
  2511. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  2512. toaster.pop('success', '提示','生成成功!');
  2513. loadData();
  2514. },function(response){
  2515. $scope.loading = false;
  2516. toaster.pop('error', '生成失败', response.data);
  2517. });
  2518. }
  2519. /**
  2520. * 打印条码和箱号
  2521. */
  2522. $scope.printCode = function(type) {
  2523. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  2524. //勾选需要打印的行
  2525. $scope.getCheckedItems = [];
  2526. var warningdata = ''
  2527. angular.forEach($scope.checkBarCode, function(item,key) {
  2528. $scope.getCheckedItem = {};
  2529. if(item == true ){
  2530. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  2531. $scope.getCheckedItems.push($scope.getCheckedItem);
  2532. //判断是否生成过条码
  2533. if($scope.order.sendItems[key].barSendNotify.length > 0){
  2534. warningdata += $scope.order.sendItems[key].number+","
  2535. }
  2536. }
  2537. });
  2538. if($scope.getCheckedItems.length == 0){
  2539. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  2540. return;
  2541. }
  2542. if(warningdata == ''){
  2543. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  2544. return;
  2545. }
  2546. //选择打印模板
  2547. var modalInstance = $modal.open({
  2548. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  2549. controller: 'BarPrintModalCtrl',
  2550. resolve: {
  2551. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  2552. }
  2553. });
  2554. modalInstance.result.then(function(s){
  2555. if(s) {
  2556. //获取打印数据
  2557. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  2558. if(s.type == 'print'){//判断选择是打印还是打印预览
  2559. lodopPrint(data.message,LODOP,type);
  2560. }else if(s.type == 'printPreview'){
  2561. lodopPrintPreview(data.message,LODOP,type);
  2562. }
  2563. },function(response){
  2564. toaster.pop('error', '获取打印数据失败', response.data);
  2565. });
  2566. }
  2567. });
  2568. };
  2569. //打印单个条码
  2570. $scope.printSingleCode = function(id){
  2571. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  2572. //选择打印模板
  2573. var modalInstance = $modal.open({
  2574. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  2575. controller: 'BarPrintModalCtrl',
  2576. resolve: {
  2577. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  2578. }
  2579. });
  2580. modalInstance.result.then(function(s){
  2581. if(s) {
  2582. //获取打印数据
  2583. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  2584. if(s.type == 'print'){//判断选择是打印还是打印预览
  2585. lodopSPrint(data.message,LODOP);
  2586. }else if(s.type == 'printPreview'){
  2587. lodopSPrintPreview(data.message,LODOP);
  2588. }
  2589. },function(response){
  2590. toaster.pop('error', '获取打印数据失败', response.data);
  2591. });
  2592. }
  2593. });
  2594. }
  2595. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  2596. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  2597. if (selectOrNot != -1) {
  2598. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  2599. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  2600. var strs = pagesize.split("*"); //字符分割
  2601. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  2602. angular.forEach(printStore, function(data, index) {
  2603. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  2604. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  2605. if (data['LP_VALUETYPE'] == 'barcode') {
  2606. 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']);
  2607. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  2608. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  2609. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  2610. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  2611. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  2612. } else if (data['LP_VALUETYPE'] == 'text') {
  2613. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  2614. }
  2615. });
  2616. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  2617. LODOP.PRINT();
  2618. }
  2619. };
  2620. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  2621. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  2622. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  2623. var strs = pagesize.split("*"); //字符分割
  2624. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  2625. angular.forEach(printStore,function(data,index){
  2626. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  2627. if(data['LP_VALUETYPE'] == 'barcode'){
  2628. 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']);
  2629. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  2630. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  2631. }else if(data['LP_VALUETYPE'] == 'text'){
  2632. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  2633. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  2634. }
  2635. });
  2636. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  2637. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  2638. LODOP.PREVIEW();//打印预览
  2639. };
  2640. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  2641. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  2642. if (selectOrNot != -1) {
  2643. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  2644. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  2645. var strs= new Array(); //定义一数组
  2646. strs = pagesize.split("*"); //字符分割
  2647. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  2648. var ids = new Array();
  2649. angular.forEach(printStore, function(value,key) {
  2650. //LODOP.NewPage();
  2651. angular.forEach(value['data'], function(record,key) {
  2652. angular.forEach(record['store'], function(data, index) {
  2653. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  2654. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  2655. if (data['LP_VALUETYPE'] == 'barcode') {
  2656. 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']);
  2657. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  2658. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  2659. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  2660. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  2661. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  2662. } else if (data['LP_VALUETYPE'] == 'text') {
  2663. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  2664. }
  2665. });
  2666. });
  2667. var o = new Object();
  2668. o['id'] = record['si_id']
  2669. ids.push(o);
  2670. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  2671. LODOP.PRINT();
  2672. });
  2673. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  2674. if(type == 'Bar'){
  2675. //更新打印状态
  2676. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  2677. }
  2678. }
  2679. };
  2680. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  2681. var ids = new Array();
  2682. angular.forEach(printData, function(record, index){
  2683. angular.forEach(record['data'],function(value,index){
  2684. LODOP.NewPage();
  2685. angular.forEach(value['store'],function(data,index){
  2686. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  2687. if(data['LP_VALUETYPE'] == 'barcode'){
  2688. 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']);
  2689. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  2690. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  2691. }else if(data['LP_VALUETYPE'] == 'text'){
  2692. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  2693. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  2694. }
  2695. });
  2696. });
  2697. var o = new Object();
  2698. o['id'] = record['si_id']
  2699. ids.push(o);
  2700. });
  2701. var pagesize = printData[0]['pagesize'];//获取标签的大小
  2702. var strs= new Array(); //定义一数组
  2703. strs = pagesize.split("*"); //字符分割
  2704. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  2705. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  2706. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  2707. var times = LODOP.PREVIEW();//打印预览
  2708. if(times > 0){//点击了打印预览内的打印按钮
  2709. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  2710. if(type == 'Bar'){
  2711. //更新打印状态
  2712. SaleSend.updatePrintStatus({},ids,function(data){
  2713. loadData();
  2714. },function(res){});
  2715. }
  2716. }
  2717. };
  2718. /**
  2719. * 查看条码按钮
  2720. */
  2721. $scope.showBarCode = function(number) {
  2722. $scope.keys = number;
  2723. for(var i=0;i<vm.showBarCode.length;i++){
  2724. if(i!=number){
  2725. vm.showBarCode[i] = false;
  2726. }
  2727. }
  2728. vm.showBarCode[number] = !vm.showBarCode[number];
  2729. $scope.barcodes = [];
  2730. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  2731. var getPage = function(page, size){
  2732. if($scope.barcodes) {
  2733. var result = {};
  2734. result.totalCount = $scope.barcodes.length;
  2735. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  2736. if($scope.barcodes.length % size == 0) {
  2737. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  2738. }else {
  2739. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  2740. }
  2741. result.first = page == 1;
  2742. result.last = page == result.totalPage;
  2743. result.page = page;
  2744. result.next = page - 0 + 1;
  2745. result.pre = page - 1;
  2746. return result;
  2747. }
  2748. }
  2749. $scope.barData = getPage(1,5);
  2750. $scope.first = function (){
  2751. $scope.barData = getPage($scope.barData.pre,5);
  2752. }
  2753. $scope.last = function (){
  2754. $scope.barData = getPage($scope.barData.next,5);
  2755. }
  2756. };
  2757. /**
  2758. * 更新外箱号
  2759. */
  2760. $scope.updateOutBox = function(item,number) {
  2761. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  2762. }else {
  2763. if(item.outBoxQty > 0) {
  2764. if(!(item.outBoxQty % item.packageQty)) {
  2765. SaleSend.update({id:item.id},item,function(){
  2766. toaster.pop('success', '提示','保存成功!');
  2767. loadData();
  2768. }, function(response){
  2769. $scope.loading = false;
  2770. toaster.pop('error', '回复失败', response.data);
  2771. })
  2772. }else {
  2773. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  2774. }
  2775. }else {
  2776. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2777. }
  2778. }
  2779. loadData();
  2780. };
  2781. /**
  2782. * 更新最小包数
  2783. */
  2784. $scope.updatePackage = function(item, number) {
  2785. if(item.packageQty == $scope.oldpackageQty[number]) {
  2786. }else {
  2787. if(item.orderItem.product.minPack != 0) {
  2788. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  2789. if(!(item.packageQty % item.orderItem.product.minPack)) {
  2790. SaleSend.update({id:item.id},item,function(){
  2791. toaster.pop('success', '提示','保存成功!');
  2792. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  2793. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  2794. }
  2795. loadData();
  2796. }, function(response){
  2797. $scope.loading = false;
  2798. toaster.pop('error', '回复失败', response.data);
  2799. })
  2800. }else {
  2801. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  2802. }
  2803. }else {
  2804. toaster.pop('warning', '提示', '请填写有效的数量!');
  2805. }
  2806. }else {
  2807. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  2808. SaleSend.update({id:item.id},item,function(){
  2809. toaster.pop('success', '提示','保存成功!');
  2810. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  2811. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  2812. }
  2813. loadData();
  2814. }, function(response){
  2815. $scope.loading = false;
  2816. toaster.pop('error', '回复失败', response.data);
  2817. })
  2818. }else {
  2819. toaster.pop('warning', '提示', '请填写有效的数量!');
  2820. }
  2821. }
  2822. }
  2823. loadData();
  2824. };
  2825. var loadData = function() {
  2826. SaleSend.get({id: $stateParams.id}, function(data){
  2827. $scope.order = data;
  2828. var orderCount = $scope.order.sendItems.length;
  2829. $scope.oldpackageQty = [];
  2830. $scope.oldoutBoxQty = [];
  2831. var sum = 0;
  2832. vm.oldpackageQty = [];
  2833. angular.forEach(data.sendItems, function(value, key){
  2834. //给showBarCode数组赋初值
  2835. if (vm.showBarCode.length < orderCount){
  2836. vm.showBarCode.push(false);
  2837. }
  2838. if($scope.checkBarCode.length < orderCount) {
  2839. $scope.checkBarCode.push(false);
  2840. }
  2841. if($scope.checkBoxCode.length < orderCount) {
  2842. $scope.checkBoxCode.push(false);
  2843. }
  2844. //给个初值
  2845. if(!value.packageQty) {
  2846. value.packageQty = value.orderItem.product.minPack;
  2847. }
  2848. $scope.oldpackageQty.push(value.packageQty);
  2849. if(value.outBoxQty) {
  2850. $scope.oldoutBoxQty.push(value.outBoxQty);
  2851. }
  2852. sum += value.price * value.qty;
  2853. });
  2854. data.total = sum;
  2855. $scope.loading = false;
  2856. }, function(response){
  2857. loading = false;
  2858. toaster.pop('error', '获取数据失败', response.data);
  2859. });
  2860. };
  2861. loadData();
  2862. }]);
  2863. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  2864. $scope.typeItem = typeItem;
  2865. $scope.template = [];
  2866. $scope.choose = {};
  2867. //获取打印模板
  2868. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  2869. if(data.message){
  2870. $scope.template = data.message;
  2871. $scope.choose.tp_id = $scope.template[0].id;
  2872. }
  2873. },function(res){
  2874. toaster.pop('error', '获取模板错误', res.data);
  2875. });
  2876. $scope.print = function(){
  2877. $scope.choose.type = 'print';
  2878. $modalInstance.close($scope.choose);
  2879. };
  2880. $scope.printPreview = function(){
  2881. $scope.choose.type = 'printPreview';
  2882. $modalInstance.close($scope.choose);
  2883. }
  2884. $scope.cancel = function(){
  2885. $modalInstance.close();
  2886. }
  2887. }]);
  2888. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  2889. var loading = true;
  2890. var loadData = function() {
  2891. PurcSample.get({id: $stateParams.id}, function(data){
  2892. $scope.sample = data;
  2893. if(!$scope.sample.send){
  2894. $scope.sample.getSendInfo = '加载中...';
  2895. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  2896. if(sendData) {
  2897. $scope.sample.getSendInfo = null;
  2898. $scope.sample.send = sendData;
  2899. } else {
  2900. $scope.sample.getSendInfo = '无送样信息';
  2901. $scope.sample.send = '无送样信息';
  2902. }
  2903. }, function(response){
  2904. $scope.sample.getSendInfo = '加载失败!';
  2905. });
  2906. }
  2907. $scope.loading = false;
  2908. }, function(response){
  2909. loading = false;
  2910. toaster.pop('error', '获取数据失败', response.data);
  2911. });
  2912. };
  2913. loadData();
  2914. }]);
  2915. /**
  2916. * 客户打样申请
  2917. */
  2918. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  2919. $scope.active = 'todo';
  2920. $scope.agreedText = '全部';
  2921. $scope.dateZoneText = '一个月内';
  2922. $scope.condition = {dateZone: 1};
  2923. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2924. $scope.changeAgreed = function(agreed) {
  2925. $scope.condition.agreed = agreed;
  2926. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2927. $scope.condition.$agreedOpen = false;
  2928. };
  2929. $scope.changeDateZone = function(zone) {
  2930. $scope.condition.dateZone = zone;
  2931. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2932. $scope.condition.$dateZoneOpen = false;
  2933. };
  2934. $scope.setActive = function(state) {
  2935. if($scope.active != state) {
  2936. $scope.active = state;
  2937. if($scope.tableParams.page() == 1)
  2938. $scope.tableParams.reload();
  2939. else
  2940. $scope.tableParams.page(1);
  2941. }
  2942. };
  2943. var getService = function() {
  2944. return PurcSample;
  2945. };
  2946. $scope.tableParams = new ngTableParams({
  2947. page : 1,
  2948. count : 5,
  2949. sorting: {
  2950. proofingDate: 'desc'
  2951. }
  2952. }, {
  2953. total : 0,
  2954. counts: [5, 10, 25, 50],
  2955. getData : function($defer, params) {
  2956. $scope.loading = true;
  2957. var pageParams = params.url();
  2958. pageParams.keyword = $scope.keyword;
  2959. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2960. $scope.loading = false;
  2961. if(page) {
  2962. params.total(page.totalElements);
  2963. $defer.resolve(page.content);
  2964. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2965. }
  2966. }, function(response){
  2967. $scope.loading = false;
  2968. toaster.pop('error', '数据加载失败', response.data);
  2969. });
  2970. }
  2971. });
  2972. $scope.openDatePicker = function($event, item, openParam) {
  2973. $event.preventDefault();
  2974. $event.stopPropagation();
  2975. item[openParam] = !item[openParam];
  2976. };
  2977. $scope.openSend = function(index, sample) {
  2978. var modalInstance = $modal.open({
  2979. animation: true,
  2980. templateUrl: 'static/tpl/index/sale/sample_send.html',
  2981. controller: 'SampleSendCtrl',
  2982. resolve: {
  2983. sampleItem: function(){return sample;}
  2984. }
  2985. });
  2986. modalInstance.result.then(function(){
  2987. toaster.pop('info', '提示', '送样成功');
  2988. $scope.tableParams.reload();
  2989. }, function(){
  2990. });
  2991. };
  2992. //打印
  2993. $scope.print = function(sample) {
  2994. PurcSample.printCount({id: sample.id},{});//增加打印此次
  2995. ReportService.print(sample.proofing.enUU, 'proofing', '{purc_proofingitems.ppi_id}=' + sample.id, '客户打样申请-' + sample.proofing.code);
  2996. };
  2997. $scope.getSend = function(proofing){
  2998. if( !proofing.send) {
  2999. proofing.getSendInfo = '加载中...';
  3000. PurcSample.getSend({id: proofing.id}, function(data){
  3001. if(data) {
  3002. proofing.getSendInfo = null;
  3003. proofing.send = data;
  3004. } else {
  3005. proofing.getSendInfo = '无送样信息';
  3006. proofing.send = '无送样信息';
  3007. }
  3008. }, function(response){
  3009. proofing.getSendInfo = '加载失败!';
  3010. });
  3011. }
  3012. };
  3013. // 搜索框回车
  3014. $scope.onSearch = function() {
  3015. $scope.tableParams.page(1);
  3016. $scope.tableParams.reload();
  3017. };
  3018. }]);
  3019. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  3020. $scope.sampleItem = sampleItem;
  3021. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  3022. //确认送样
  3023. $scope.ok = function (form) {
  3024. $scope.loading = true;
  3025. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  3026. $upload.upload({
  3027. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  3028. method: 'POST',
  3029. file: file,
  3030. data: {
  3031. json: $scope.sampleItem.sampleSend
  3032. }
  3033. }).success(function(data){
  3034. $scope.loading = false;
  3035. $modalInstance.close('success');
  3036. }).error(function(data){
  3037. $scope.loading = false;
  3038. toaster.pop('danger', '错误', data);
  3039. });
  3040. };
  3041. $scope.cancel = function () {
  3042. $modalInstance.dismiss(sampleItem);
  3043. };
  3044. }]);
  3045. /**
  3046. * 客户认定单
  3047. */
  3048. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  3049. $scope.active = 'all';
  3050. $scope.agreedText = '全部';
  3051. $scope.dateZoneText = '一个月内';
  3052. $scope.condition = {dateZone: 1};
  3053. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3054. $scope.changeDateZone = function(zone) {
  3055. $scope.condition.dateZone = zone;
  3056. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3057. $scope.condition.$dateZoneOpen = false;
  3058. getDateCondition(zone, $scope.condition);
  3059. $scope.tableParams.reload();
  3060. };
  3061. $scope.setActive = function(state) {
  3062. if($scope.active != state) {
  3063. $scope.active = state;
  3064. if($scope.tableParams.page() == 1)
  3065. $scope.tableParams.reload();
  3066. else
  3067. $scope.tableParams.page(1);
  3068. }
  3069. };
  3070. var getService = function() {
  3071. return PurcApproval;
  3072. };
  3073. $scope.tableParams = new ngTableParams({
  3074. page : 1,
  3075. count : 5,
  3076. sorting: {
  3077. inDate: 'desc'
  3078. }
  3079. }, {
  3080. total : 0,
  3081. counts: [5, 10, 25, 50],
  3082. getData : function($defer, params) {
  3083. $scope.loading = true;
  3084. var pageParams = params.url();
  3085. pageParams.keyword = $scope.keyword;
  3086. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3087. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3088. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3089. $scope.loading = false;
  3090. if(page) {
  3091. params.total(page.totalElements);
  3092. $defer.resolve(page.content);
  3093. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3094. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3095. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3096. }
  3097. }, function(response){
  3098. $scope.loading = false;
  3099. toaster.pop('error', '数据加载失败', response.data);
  3100. });
  3101. }
  3102. });
  3103. $scope.openDatePicker = function($event, item, openParam) {
  3104. $event.preventDefault();
  3105. $event.stopPropagation();
  3106. item[openParam] = !item[openParam];
  3107. };
  3108. $scope.parseDate = function(dateStr) {
  3109. if(dateStr)
  3110. return Date.parse(dateStr, 'yyyy-MM-dd');
  3111. return new Date();
  3112. };
  3113. // 搜索框回车
  3114. $scope.onSearch = function() {
  3115. $scope.tableParams.page(1);
  3116. $scope.tableParams.reload();
  3117. };
  3118. // 选择查找日期
  3119. $scope.onDateCondition = function(){
  3120. $scope.tableParams.page(1);
  3121. $scope.tableParams.reload();
  3122. };
  3123. }]);
  3124. /**
  3125. * 客户采购预测
  3126. */
  3127. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  3128. $scope.active = 'all';
  3129. $scope.agreedText = '全部';
  3130. $scope.dateZoneText = '一个月内';
  3131. $scope.condition = {dateZone: 1};
  3132. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3133. $scope.changeAgreed = function(agreed) {
  3134. $scope.condition.agreed = agreed;
  3135. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3136. $scope.condition.$agreedOpen = false;
  3137. };
  3138. $scope.changeDateZone = function(zone) {
  3139. $scope.condition.dateZone = zone;
  3140. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3141. $scope.condition.$dateZoneOpen = false;
  3142. };
  3143. $scope.setActive = function(state) {
  3144. if($scope.active != state) {
  3145. $scope.active = state;
  3146. if($scope.tableParams.page() == 1)
  3147. $scope.tableParams.reload();
  3148. else
  3149. $scope.tableParams.page(1);
  3150. }
  3151. };
  3152. var getService = function() {
  3153. return PurcForecast;
  3154. };
  3155. $scope.tableParams = new ngTableParams({
  3156. page : 1,
  3157. count : 5,
  3158. sorting: {
  3159. orderDate: 'desc'
  3160. }
  3161. }, {
  3162. total : 0,
  3163. counts: [5, 10, 25, 50],
  3164. getData : function($defer, params) {
  3165. $scope.loading = true;
  3166. var pageParams = params.url();
  3167. pageParams.keyword = $scope.keyword;
  3168. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3169. $scope.loading = false;
  3170. if(page) {
  3171. params.total(page.totalElements);
  3172. $defer.resolve(page.content);
  3173. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3174. }
  3175. }, function(response){
  3176. $scope.loading = false;
  3177. toaster.pop('error', '数据加载失败', response.data);
  3178. });
  3179. }
  3180. });
  3181. $scope.openDatePicker = function($event, item, openParam) {
  3182. $event.preventDefault();
  3183. $event.stopPropagation();
  3184. item[openParam] = !item[openParam];
  3185. };
  3186. // 搜索框回车
  3187. $scope.onSearch = function() {
  3188. $scope.tableParams.page(1);
  3189. $scope.tableParams.reload();
  3190. };
  3191. }]);
  3192. /**
  3193. * 客户采购验收
  3194. */
  3195. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  3196. $scope.active = 'all';
  3197. $scope.agreedText = '全部';
  3198. $scope.dateZoneText = '一个月内';
  3199. $scope.condition = {dateZone: 1};
  3200. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3201. $scope.changeAgreed = function(agreed) {
  3202. $scope.condition.agreed = agreed;
  3203. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3204. $scope.condition.$agreedOpen = false;
  3205. };
  3206. $scope.changeDateZone = function(zone) {
  3207. $scope.condition.dateZone = zone;
  3208. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3209. $scope.condition.$dateZoneOpen = false;
  3210. };
  3211. $scope.setActive = function(state) {
  3212. if($scope.active != state) {
  3213. $scope.active = state;
  3214. if($scope.tableParams.page() == 1)
  3215. $scope.tableParams.reload();
  3216. else
  3217. $scope.tableParams.page(1);
  3218. }
  3219. };
  3220. var getService = function() {
  3221. return PurcAccept;
  3222. };
  3223. $scope.tableParams = new ngTableParams({
  3224. page : 1,
  3225. count : 5,
  3226. sorting: {
  3227. date: 'desc'
  3228. }
  3229. }, {
  3230. total : 0,
  3231. counts: [5, 10, 25, 50],
  3232. getData : function($defer, params) {
  3233. $scope.loading = true;
  3234. var pageParams = params.url();
  3235. pageParams.keyword = $scope.keyword;
  3236. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3237. $scope.loading = false;
  3238. if(page) {
  3239. params.total(page.totalElements);
  3240. $defer.resolve(page.content);
  3241. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3242. }
  3243. }, function(response){
  3244. $scope.loading = false;
  3245. toaster.pop('error', '数据加载失败', response.data);
  3246. });
  3247. }
  3248. });
  3249. $scope.openDatePicker = function($event, item, openParam) {
  3250. $event.preventDefault();
  3251. $event.stopPropagation();
  3252. item[openParam] = !item[openParam];
  3253. };
  3254. // 搜索框回车
  3255. $scope.onSearch = function() {
  3256. $scope.tableParams.page(1);
  3257. $scope.tableParams.reload();
  3258. };
  3259. }]);
  3260. /**
  3261. * 客户采购验退
  3262. */
  3263. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  3264. $scope.active = 'all';
  3265. $scope.agreedText = '全部';
  3266. $scope.dateZoneText = '一个月内';
  3267. $scope.condition = {dateZone: 1};
  3268. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3269. $scope.changeAgreed = function(agreed) {
  3270. $scope.condition.agreed = agreed;
  3271. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3272. $scope.condition.$agreedOpen = false;
  3273. };
  3274. $scope.changeDateZone = function(zone) {
  3275. $scope.condition.dateZone = zone;
  3276. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3277. $scope.condition.$dateZoneOpen = false;
  3278. };
  3279. $scope.setActive = function(state) {
  3280. if($scope.active != state) {
  3281. $scope.active = state;
  3282. if($scope.tableParams.page() == 1)
  3283. $scope.tableParams.reload();
  3284. else
  3285. $scope.tableParams.page(1);
  3286. }
  3287. };
  3288. var getService = function() {
  3289. return PurcReturn;
  3290. };
  3291. $scope.tableParams = new ngTableParams({
  3292. page : 1,
  3293. count : 5,
  3294. sorting: {
  3295. date: 'desc'
  3296. }
  3297. }, {
  3298. total : 0,
  3299. counts: [5, 10, 25, 50],
  3300. getData : function($defer, params) {
  3301. $scope.loading = true;
  3302. var pageParams = params.url();
  3303. pageParams.keyword = $scope.keyword;
  3304. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3305. $scope.loading = false;
  3306. if(page) {
  3307. params.total(page.totalElements);
  3308. $defer.resolve(page.content);
  3309. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3310. }
  3311. }, function(response){
  3312. $scope.loading = false;
  3313. toaster.pop('error', '数据加载失败', response.data);
  3314. });
  3315. }
  3316. });
  3317. $scope.openDatePicker = function($event, item, openParam) {
  3318. $event.preventDefault();
  3319. $event.stopPropagation();
  3320. item[openParam] = !item[openParam];
  3321. };
  3322. // 搜索框回车
  3323. $scope.onSearch = function() {
  3324. $scope.tableParams.page(1);
  3325. $scope.tableParams.reload();
  3326. };
  3327. }]);
  3328. /**
  3329. * 客户不良品入库
  3330. */
  3331. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  3332. $scope.active = 'all';
  3333. $scope.agreedText = '全部';
  3334. $scope.dateZoneText = '一个月内';
  3335. $scope.condition = {dateZone: 1};
  3336. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3337. $scope.changeAgreed = function(agreed) {
  3338. $scope.condition.agreed = agreed;
  3339. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3340. $scope.condition.$agreedOpen = false;
  3341. };
  3342. $scope.changeDateZone = function(zone) {
  3343. $scope.condition.dateZone = zone;
  3344. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3345. $scope.condition.$dateZoneOpen = false;
  3346. };
  3347. $scope.setActive = function(state) {
  3348. if($scope.active != state) {
  3349. $scope.active = state;
  3350. if($scope.tableParams.page() == 1)
  3351. $scope.tableParams.reload();
  3352. else
  3353. $scope.tableParams.page(1);
  3354. }
  3355. };
  3356. var getService = function() {
  3357. return PurcBadIn;
  3358. };
  3359. $scope.tableParams = new ngTableParams({
  3360. page : 1,
  3361. count : 5,
  3362. sorting: {
  3363. date: 'desc'
  3364. }
  3365. }, {
  3366. total : 0,
  3367. counts: [5, 10, 25, 50],
  3368. getData : function($defer, params) {
  3369. $scope.loading = true;
  3370. var pageParams = params.url();
  3371. pageParams.keyword = $scope.keyword;
  3372. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3373. $scope.loading = false;
  3374. if(page) {
  3375. params.total(page.totalElements);
  3376. $defer.resolve(page.content);
  3377. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3378. }
  3379. }, function(response){
  3380. $scope.loading = false;
  3381. toaster.pop('error', '数据加载失败', response.data);
  3382. });
  3383. }
  3384. });
  3385. $scope.openDatePicker = function($event, item, openParam) {
  3386. $event.preventDefault();
  3387. $event.stopPropagation();
  3388. item[openParam] = !item[openParam];
  3389. };
  3390. // 搜索框回车
  3391. $scope.onSearch = function() {
  3392. $scope.tableParams.page(1);
  3393. $scope.tableParams.reload();
  3394. };
  3395. }]);
  3396. /**
  3397. * 客户不良品出库
  3398. */
  3399. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  3400. $scope.active = 'all';
  3401. $scope.agreedText = '全部';
  3402. $scope.dateZoneText = '一个月内';
  3403. $scope.condition = {dateZone: 1};
  3404. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3405. $scope.changeAgreed = function(agreed) {
  3406. $scope.condition.agreed = agreed;
  3407. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3408. $scope.condition.$agreedOpen = false;
  3409. };
  3410. $scope.changeDateZone = function(zone) {
  3411. $scope.condition.dateZone = zone;
  3412. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3413. $scope.condition.$dateZoneOpen = false;
  3414. };
  3415. $scope.setActive = function(state) {
  3416. if($scope.active != state) {
  3417. $scope.active = state;
  3418. if($scope.tableParams.page() == 1)
  3419. $scope.tableParams.reload();
  3420. else
  3421. $scope.tableParams.page(1);
  3422. }
  3423. };
  3424. var getService = function() {
  3425. return PurcBadOut;
  3426. };
  3427. $scope.tableParams = new ngTableParams({
  3428. page : 1,
  3429. count : 5,
  3430. sorting: {
  3431. date: 'desc'
  3432. }
  3433. }, {
  3434. total : 0,
  3435. counts: [5, 10, 25, 50],
  3436. getData : function($defer, params) {
  3437. $scope.loading = true;
  3438. var pageParams = params.url();
  3439. pageParams.keyword = $scope.keyword;
  3440. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3441. $scope.loading = false;
  3442. if(page) {
  3443. params.total(page.totalElements);
  3444. $defer.resolve(page.content);
  3445. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3446. }
  3447. }, function(response){
  3448. $scope.loading = false;
  3449. toaster.pop('error', '数据加载失败', response.data);
  3450. });
  3451. }
  3452. });
  3453. $scope.openDatePicker = function($event, item, openParam) {
  3454. $event.preventDefault();
  3455. $event.stopPropagation();
  3456. item[openParam] = !item[openParam];
  3457. };
  3458. // 搜索框回车
  3459. $scope.onSearch = function() {
  3460. $scope.tableParams.page(1);
  3461. $scope.tableParams.reload();
  3462. };
  3463. }]);
  3464. /**
  3465. * 客户MRB
  3466. */
  3467. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  3468. $scope.active = 'all';
  3469. $scope.agreedText = '全部';
  3470. $scope.dateZoneText = '一个月内';
  3471. $scope.condition = {dateZone: 1};
  3472. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3473. $scope.changeAgreed = function(agreed) {
  3474. $scope.condition.agreed = agreed;
  3475. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3476. $scope.condition.$agreedOpen = false;
  3477. };
  3478. $scope.changeDateZone = function(zone) {
  3479. $scope.condition.dateZone = zone;
  3480. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3481. $scope.condition.$dateZoneOpen = false;
  3482. };
  3483. $scope.setActive = function(state) {
  3484. if($scope.active != state) {
  3485. $scope.active = state;
  3486. if($scope.tableParams.page() == 1)
  3487. $scope.tableParams.reload();
  3488. else
  3489. $scope.tableParams.page(1);
  3490. }
  3491. };
  3492. var getService = function() {
  3493. return PurcMRB;
  3494. };
  3495. $scope.tableParams = new ngTableParams({
  3496. page : 1,
  3497. count : 5,
  3498. sorting: {
  3499. date: 'desc'
  3500. }
  3501. }, {
  3502. total : 0,
  3503. counts: [5, 10, 25, 50],
  3504. getData : function($defer, params) {
  3505. $scope.loading = true;
  3506. var pageParams = params.url();
  3507. pageParams.keyword = $scope.keyword;
  3508. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3509. $scope.loading = false;
  3510. if(page) {
  3511. params.total(page.totalElements);
  3512. $defer.resolve(page.content);
  3513. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3514. }
  3515. }, function(response){
  3516. $scope.loading = false;
  3517. toaster.pop('error', '数据加载失败', response.data);
  3518. });
  3519. }
  3520. });
  3521. $scope.openDatePicker = function($event, item, openParam) {
  3522. $event.preventDefault();
  3523. $event.stopPropagation();
  3524. item[openParam] = !item[openParam];
  3525. };
  3526. // 搜索框回车
  3527. $scope.onSearch = function() {
  3528. $scope.tableParams.page(1);
  3529. $scope.tableParams.reload();
  3530. };
  3531. }]);
  3532. /**
  3533. * 客户应付发票
  3534. */
  3535. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  3536. $scope.active = 'all';
  3537. $scope.dateZoneText = '不限';
  3538. $scope.condition = {dateZone: -1};
  3539. $scope.changeDateZone = function(zone) {
  3540. $scope.condition.dateZone = zone;
  3541. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3542. $scope.condition.$dateZoneOpen = false;
  3543. getDateCondition(zone, $scope.condition);
  3544. $scope.tableParams.reload();
  3545. };
  3546. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3547. $scope.setActive = function(state) {
  3548. if($scope.active != state) {
  3549. $scope.active = state;
  3550. if($scope.tableParams.page() == 1)
  3551. $scope.tableParams.reload();
  3552. else
  3553. $scope.tableParams.page(1);
  3554. }
  3555. };
  3556. var getService = function() {
  3557. return FaApBill;
  3558. };
  3559. $scope.tableParams = new ngTableParams({
  3560. page : 1,
  3561. count : 5,
  3562. sorting: {
  3563. date: 'desc'
  3564. }
  3565. }, {
  3566. total : 0,
  3567. counts: [5, 10, 25, 50],
  3568. getData : function($defer, params) {
  3569. $scope.loading = true;
  3570. var pageParams = params.url();
  3571. pageParams.keyword = $scope.keyword;
  3572. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3573. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3574. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3575. $scope.loading = false;
  3576. if(page) {
  3577. params.total(page.totalElements);
  3578. $defer.resolve(page.content);
  3579. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3580. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3581. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3582. }
  3583. }, function(response){
  3584. $scope.loading = false;
  3585. toaster.pop('error', '数据加载失败', response.data);
  3586. });
  3587. }
  3588. });
  3589. $scope.openDatePicker = function($event, item, openParam) {
  3590. $event.preventDefault();
  3591. $event.stopPropagation();
  3592. item[openParam] = !item[openParam];
  3593. };
  3594. // 搜索框回车
  3595. $scope.onSearch = function() {
  3596. $scope.tableParams.page(1);
  3597. $scope.tableParams.reload();
  3598. };
  3599. // 选择查找日期
  3600. $scope.onDateCondition = function(){
  3601. $scope.tableParams.page(1);
  3602. $scope.tableParams.reload();
  3603. };
  3604. }]);
  3605. /**
  3606. * 应付对账单
  3607. */
  3608. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  3609. $scope.active = 'all';
  3610. $scope.dateZoneText = '不限';
  3611. $scope.condition = {dateZone: -1};
  3612. $scope.changeDateZone = function(zone) {
  3613. $scope.condition.dateZone = zone;
  3614. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3615. $scope.condition.$dateZoneOpen = false;
  3616. getDateCondition(zone, $scope.condition);
  3617. $scope.tableParams.reload();
  3618. };
  3619. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3620. $scope.setActive = function(state) {
  3621. if($scope.active != state) {
  3622. $scope.active = state;
  3623. if($scope.tableParams.page() == 1)
  3624. $scope.tableParams.reload();
  3625. else
  3626. $scope.tableParams.page(1);
  3627. }
  3628. };
  3629. var getService = function() {
  3630. return FaArCheck;
  3631. };
  3632. $scope.tableParams = new ngTableParams({
  3633. page : 1,
  3634. count : 5,
  3635. sorting: {
  3636. date: 'desc'
  3637. }
  3638. }, {
  3639. total : 0,
  3640. counts: [5, 10, 25, 50],
  3641. getData : function($defer, params) {
  3642. $scope.loading = true;
  3643. var pageParams = params.url();
  3644. pageParams.keyword = $scope.keyword;
  3645. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3646. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3647. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3648. $scope.loading = false;
  3649. if(page) {
  3650. params.total(page.totalElements);
  3651. $defer.resolve(page.content);
  3652. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3653. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3654. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3655. }
  3656. }, function(response){
  3657. $scope.loading = false;
  3658. toaster.pop('error', '数据加载失败', response.data);
  3659. });
  3660. }
  3661. });
  3662. $scope.openDatePicker = function($event, item, openParam) {
  3663. $event.preventDefault();
  3664. $event.stopPropagation();
  3665. item[openParam] = !item[openParam];
  3666. };
  3667. // 计算单据的商品总数
  3668. $scope.getTotalProd = function(check) {
  3669. var total = 0;
  3670. if(check.items) {
  3671. angular.forEach(check.items, function(value) {
  3672. total += value.qty;
  3673. });
  3674. }
  3675. return total;
  3676. };
  3677. // 搜索框回车
  3678. $scope.onSearch = function() {
  3679. $scope.tableParams.page(1);
  3680. $scope.tableParams.reload();
  3681. };
  3682. // 选择查找日期
  3683. $scope.onDateCondition = function(){
  3684. $scope.tableParams.page(1);
  3685. $scope.tableParams.reload();
  3686. };
  3687. }]);
  3688. // 应付对账单详情页
  3689. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', function($scope, $stateParams, FaArCheck, toaster, $state){
  3690. var loadData = function() {
  3691. FaArCheck.get({id: $stateParams.id}, function(data){
  3692. $scope.order = data;
  3693. $scope.loading = false;
  3694. });
  3695. };
  3696. loadData(); // 初始获取单据数据
  3697. $scope.onReplyClick = function(item, isAgreed) {
  3698. if(isAgreed) {// 同意确认
  3699. FaArCheck.agree({itemId: item.id}, {}, function(data){
  3700. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  3701. }, function(response){
  3702. toaster.pop('danger', '确认失败', response.data);
  3703. });
  3704. } else {// 不同意回复
  3705. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  3706. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  3707. }, function(response) {
  3708. toaster.pop('danger', '确认失败', response.data);
  3709. });
  3710. }
  3711. };
  3712. // 获取明细的回复记录
  3713. $scope.getReplies = function(item) {
  3714. if(!item.replies) {
  3715. FaArCheck.getReplies({itemId: item.id}, function(data) {
  3716. item.replies = data;
  3717. }, function(response) {
  3718. toaster.pop('danger', '获取对账记录失败', response.data);
  3719. });
  3720. }
  3721. };
  3722. }]);
  3723. //应收对账单列表
  3724. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  3725. $scope.dateZoneText = '不限';
  3726. $scope.condition = {dateZone: -1};
  3727. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3728. $scope.active = 'todo';
  3729. //打印
  3730. $scope.print = function(check) {
  3731. console.log(check);
  3732. FaApCheck.printCount({id: check.id},{});//增加打印此次
  3733. ReportService.print(check.custUu, 'purcapcheck', '{purc_apcheck.pa_id}=' + check.id, '应收对账单-' + check.code);
  3734. };
  3735. //状态
  3736. $scope.setActive = function (state){
  3737. if($scope.active != state) {
  3738. $scope.active = state;
  3739. if($scope.tableParams.page() == 1)
  3740. $scope.tableParams.reload();
  3741. else
  3742. $scope.tableParams.page(1);
  3743. }
  3744. };
  3745. $scope.changeDateZone = function(zone) {
  3746. $scope.condition.dateZone = zone;
  3747. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3748. $scope.condition.$dateZoneOpen = false;
  3749. getDateCondition(zone, $scope.condition);
  3750. $scope.tableParams.reload();
  3751. };
  3752. //获取应收对账单全部
  3753. $scope.tableParams = new ngTableParams({
  3754. page : 1,
  3755. count : 5,
  3756. sorting: {
  3757. recordDate: 'desc'
  3758. }
  3759. }, {
  3760. total : 0,
  3761. counts: [5, 10, 25, 50],
  3762. getData : function($defer, params) {
  3763. $scope.loading = true;
  3764. var pageParams = params.url();
  3765. pageParams.searchFilter = {};
  3766. pageParams.keyword = $scope.keyword;
  3767. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3768. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3769. pageParams.searchFilter.keyword = pageParams.keyword;
  3770. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  3771. $scope.loading = false;
  3772. if(page) {
  3773. params.total(page.totalElements);
  3774. $scope.data = $defer.resolve(page.content);
  3775. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  3776. // $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3777. // $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3778. // $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3779. }
  3780. }, function(response){
  3781. $scope.loading = false;
  3782. toaster.pop('error', '数据加载失败', response.data);
  3783. });
  3784. }
  3785. });
  3786. $scope.openDatePicker = function($event, item, openParam) {
  3787. $event.preventDefault();
  3788. $event.stopPropagation();
  3789. item[openParam] = !item[openParam];
  3790. };
  3791. // 计算单据的商品总数
  3792. $scope.getTotalProd = function(check) {
  3793. var total = 0;
  3794. if(check.items) {
  3795. angular.forEach(check.items, function(value) {
  3796. total += value.checkQty;
  3797. });
  3798. }
  3799. return total;
  3800. };
  3801. // 搜索框回车
  3802. $scope.onSearch = function() {
  3803. $scope.tableParams.page(1);
  3804. $scope.tableParams.reload();
  3805. };
  3806. // 选择查找日期
  3807. $scope.onDateCondition = function(){
  3808. $scope.tableParams.page(1);
  3809. $scope.tableParams.reload();
  3810. };
  3811. }]);
  3812. //应收对账单详情
  3813. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams',function($scope,toaster,FaApCheck,$stateParams){
  3814. $scope.haveSelected = true;
  3815. $scope.data = {};
  3816. //控制提交和删除按钮的显示
  3817. $scope.ifShow = true;
  3818. var loadData = function(){
  3819. FaApCheck.get({id:$stateParams.id},function(data){
  3820. $scope.data = data;
  3821. if($scope.data.status){
  3822. }else{
  3823. $scope.ifShow = true;
  3824. }
  3825. })
  3826. };
  3827. if($stateParams.id){
  3828. loadData();
  3829. }
  3830. $scope.haveSource = false;
  3831. //提交应收对账单
  3832. $scope.submitApCheck = function(){
  3833. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  3834. if(data.result) {
  3835. toaster.pop('success', '提示', '提交成功');
  3836. $scope.haveSelected = false;
  3837. window.location.href = '#/fa/apCheck';
  3838. }else {
  3839. $scope.haveSource = true;
  3840. loadData();
  3841. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  3842. $scope.haveSelected = true;
  3843. }
  3844. },function(){
  3845. $scope.loading = false;
  3846. toaster.pop('error', '提示', '更新已转数失败');
  3847. });
  3848. }
  3849. //删除应收对账单的同时更新来源表已转数
  3850. var updateYCheckQty = function(){
  3851. var sourceInfos = [];
  3852. angular.forEach($scope.data.items, function(item){
  3853. $scope.sourceInfo = {
  3854. sourceId: '',
  3855. sourceTable: '',
  3856. newYCheckQty: ''
  3857. };
  3858. $scope.sourceInfo.sourceId = item.sourceId;
  3859. $scope.sourceInfo.sourceTable = item.sourceTable;
  3860. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  3861. sourceInfos.push($scope.sourceInfo);
  3862. });
  3863. FaApCheck.update({}, sourceInfos, function(){
  3864. },function(response){
  3865. $scope.loading = false;
  3866. toaster.pop('error', '更新已转数失败', response.data);
  3867. });
  3868. }
  3869. //删除应收对账单
  3870. $scope.deleteApCheck = function(){
  3871. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  3872. updateYCheckQty();
  3873. toaster.pop('success','提示','删除成功');
  3874. },function(){
  3875. toaster.pop('error','提示','删除失败');
  3876. });
  3877. $scope.haveSelected = false;
  3878. }
  3879. //作废应收对账单
  3880. $scope.cancelApCheck = function(check) {
  3881. FaApCheck.cancel({id:check.id},function(data){
  3882. $scope.checkResult = false;
  3883. if(data.result) {
  3884. $scope.checkResult = true;
  3885. toaster.pop('success', '提示', '作废成功');
  3886. $scope.tableParams.reload();
  3887. }else{
  3888. toaster.pop('error', '提示', '作废失败');
  3889. }
  3890. },function(){
  3891. $scope.loading = false;
  3892. toaster.pop('error', '提示', '作废失败');
  3893. });
  3894. }
  3895. }]);
  3896. //未对账单据列表
  3897. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', function($scope, FaApCheck, toaster, $state, $filter){
  3898. $scope.data = {};// 列表数据
  3899. $scope.loading = true;
  3900. $scope.getData = function(){
  3901. FaApCheck.getAll(function(data){
  3902. $scope.data = data;
  3903. angular.forEach($scope.data, function(item) {
  3904. item:{
  3905. $selected:true;
  3906. }
  3907. });
  3908. $scope.loading = false;
  3909. });
  3910. }
  3911. $scope.getData();
  3912. $scope.condition = {
  3913. $fromOpened:false
  3914. }
  3915. $scope.openDatePicker = function($event, item, openParam) {
  3916. $event.preventDefault();
  3917. $event.stopPropagation();
  3918. item[openParam] = !item[openParam];
  3919. }
  3920. // 点击筛选根据条件选择数据
  3921. $scope.suuorname = '';
  3922. $scope.sdateFrom = '';
  3923. $scope.sdateTo = '';
  3924. $scope.vuuorname = '';
  3925. $scope.condition.uuorname = '';
  3926. $scope.condition.dateFrom = '';
  3927. $scope.condition.dateTo = '';
  3928. $scope.condition.venduuorname = '';
  3929. $scope.condition.factory = '';
  3930. $scope.condition.prodTitle = '';
  3931. $scope.condition.prodSpec = '';
  3932. $scope.searchOrder = function(check) {
  3933. angular.forEach($scope.data, function(item) {
  3934. $scope.checkboxes.checked = false;
  3935. item.$selected = false;
  3936. });
  3937. console.log($scope.data);
  3938. $scope.totalMoney = 0;
  3939. $scope.condition.uuorname = $scope.suuorname;
  3940. $scope.condition.factory = $scope.factory
  3941. $scope.condition.prodTitle = $scope.prodTitle;
  3942. $scope.condition.prodSpec = $scope.prodSpec;
  3943. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  3944. $scope.thisdatato = ($scope.sdateTo || 0);
  3945. if($scope.thisdatato != 0) {
  3946. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  3947. } else {
  3948. $scope.condition.dateTo = ($scope.sdateTo || 0);
  3949. }
  3950. $scope.condition.venduuorname = $scope.vuuorname;
  3951. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname) + "-" + ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname));//保存当前取值的关键词
  3952. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3953. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3954. }
  3955. /**
  3956. * 点击勾选框,选中要转应收对账单的订单
  3957. * */
  3958. $scope.totalMoney = 0;
  3959. $scope.checkboxes = {
  3960. checked : false
  3961. };
  3962. // 点击勾选全部的复选框
  3963. $scope.checkAll = function(){
  3964. $scope.totalMoney = 0;
  3965. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.uuorname, $scope.condition.venduuorname);
  3966. var uuorname = $scope.suuorname;
  3967. var venduuorname = $scope.venduuorname;
  3968. var dateFrom = $scope.condition.dateFrom;
  3969. var dateTo = $scope.condition.dateTo;
  3970. angular.forEach($scope.filteredData, function(item) {
  3971. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  3972. item.$selected = $scope.checkboxes.checked;
  3973. }
  3974. });
  3975. $scope.getTotalMoney();
  3976. };
  3977. //获取已选单据总金额
  3978. var total = true;
  3979. $scope.getTotalMoney = function(){
  3980. $scope.totalMoney = 0;
  3981. angular.forEach($scope.data, function(check) {
  3982. if(check.$selected){
  3983. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  3984. }else{
  3985. $scope.totalMoney += 0;
  3986. }
  3987. });
  3988. }
  3989. // 点击其中一个明细的复选框
  3990. $scope.checkOne = function(check){
  3991. var result = true;
  3992. angular.forEach($scope.data, function(item) {
  3993. if(item.$selected != true){
  3994. result = false;
  3995. return;
  3996. }
  3997. });
  3998. $scope.checkboxes.checked = result;
  3999. };
  4000. $scope.haveSelected = false;
  4001. //生成应收对账单
  4002. $scope.createApCheck = function(){
  4003. //保存应收对账单主记录字段
  4004. $scope.apCheck = {
  4005. custUu: '',
  4006. custName: '',
  4007. enUu: '',
  4008. apDate: '',
  4009. beginDate: '',
  4010. endDate: '',
  4011. checkStatus: '未对账',
  4012. checkAmount: 0,
  4013. currency: '',
  4014. rate: '',
  4015. items: []
  4016. };
  4017. //保存来源单据相关信息
  4018. var sourceInfos = [];
  4019. //所允许的本次对账最大最小数量
  4020. $scope.data.maxThisCheckQty = 0;
  4021. $scope.data.minThisCheckQty = 0;
  4022. $scope.sameCust = true;
  4023. $scope.validQty = true;
  4024. $scope.loading = true;
  4025. angular.forEach($scope.data, function(check) {
  4026. //保存应收对账单明细行数据
  4027. $scope.item = {
  4028. inoutno: '',
  4029. inoutnodetno: '',
  4030. orderCode: '',
  4031. orderClass: '',
  4032. orderDetno: '',
  4033. price: '',
  4034. checkQty: '',
  4035. amount: '',
  4036. sourceId:'',
  4037. sourceTable:'',
  4038. oldYCheckQty:'',
  4039. status: 0,
  4040. receiveCode:'',
  4041. receiveName:'',
  4042. prodCode:'',
  4043. prodTitle:'',
  4044. prodSpec:'',
  4045. taxrate: '',
  4046. sendcode: '',
  4047. whname: '',
  4048. };
  4049. //应收对账单明细行来源表信息
  4050. $scope.sourceInfo = {
  4051. sourceId: '',
  4052. sourceTable: '',
  4053. newYCheckQty: ''
  4054. };
  4055. //此次对账后新的已转数
  4056. $scope.newYCheckQty = 0;
  4057. if(check.$selected == true) {
  4058. $scope.apCheck.custName = check.custName;
  4059. $scope.apCheck.enUu = check.enUu;
  4060. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4061. $scope.apCheck.apDate = check.piDate;
  4062. $scope.apCheck.rate = check.rate;
  4063. //必须是同一家客户才能生成对账单,否则提示错误
  4064. if($scope.apCheck.custUu == ''){
  4065. $scope.apCheck.custUu = check.custUu;
  4066. }else if($scope.apCheck.custUu !== check.custUu){
  4067. $scope.sameCust = false;
  4068. $scope.loading = false;
  4069. toaster.pop('error', '请选择同一家客户');
  4070. }
  4071. //必须是相同币别才能生成对账单,否则提示错误
  4072. if($scope.apCheck.currency == ''){
  4073. $scope.apCheck.currency = check.currency;
  4074. }else if($scope.apCheck.currency !== check.currency){
  4075. $scope.sameCust = false;
  4076. $scope.loading = false;
  4077. toaster.pop('error', '请选择同一种币别');
  4078. }
  4079. //本次对账数量必须小于总对账数量
  4080. if(check.qty > 0){
  4081. $scope.data.maxThisCheckQty = check.qty;
  4082. $scope.data.minThisCheckQty = 0;
  4083. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  4084. $scope.validQty = false;
  4085. $scope.loading = false;
  4086. toaster.pop('error','本次对账数量,填写有误!');
  4087. }
  4088. }else if(check.qty < 0){
  4089. $scope.data.maxThisCheckQty = 0;
  4090. $scope.data.minThisCheckQty = check.qty;
  4091. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  4092. $scope.validQty = false;
  4093. $scope.loading = false;
  4094. toaster.pop('error','本次对账数量,填写有误!');
  4095. }
  4096. }
  4097. //获取最小时间作为对账区间的起始时间
  4098. if($scope.apCheck.beginDate == ''){
  4099. $scope.apCheck.beginDate = check.piDate;
  4100. }else{
  4101. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  4102. }
  4103. //获取最大时间作为对账区间的截止时间
  4104. if($scope.apCheck.endDate == ''){
  4105. $scope.apCheck.endDate = check.piDate;
  4106. }else{
  4107. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  4108. }
  4109. //应收对账单明细行数据
  4110. $scope.item.orderCode = check.orderCode;
  4111. $scope.item.orderClass = check.piClass;
  4112. $scope.item.orderDetno = check.orderDetno;
  4113. $scope.item.price = check.orderPrice;
  4114. $scope.item.checkQty = check.thisCheckQty;
  4115. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4116. $scope.item.sourceId = check.sourceId;
  4117. $scope.item.sourceTable = check.sourceTable;
  4118. $scope.item.oldYCheckQty = check.yCheckQty;
  4119. $scope.item.prodCode = check.prodCode;
  4120. $scope.item.prodTitle = check.prodTitle;
  4121. $scope.item.prodSpec = check.prodSpec;
  4122. $scope.item.inoutno = check.inOutNo;
  4123. $scope.item.inoutnodetno = check.detno;
  4124. $scope.item.taxrate = check.taxrate;
  4125. $scope.item.receiveCode = check.receiveCode;
  4126. $scope.item.receiveName = check.receiveName;
  4127. $scope.item.sendcode = check.sendcode;
  4128. $scope.item.whname = check.whname;
  4129. //来源表相关信息
  4130. $scope.sourceInfo.sourceId = check.sourceId;
  4131. $scope.sourceInfo.sourceTable = check.sourceTable;
  4132. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  4133. sourceInfos.push($scope.sourceInfo);
  4134. console.log($scope.sourceInfo);
  4135. $scope.apCheck.items.push($scope.item);
  4136. $scope.haveSelected = true;
  4137. }
  4138. });
  4139. //保存生成的应收对账单
  4140. $scope.saveApCheck = function(){
  4141. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  4142. $scope.loading = false;
  4143. toaster.pop('success', '成功', '生成应收对账成功');
  4144. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  4145. }, function(response){
  4146. toaster.pop('error', '失败', '生成对账失败,请刷新界面');
  4147. })
  4148. };
  4149. //如果是同一家客户,生成对账单的同时,关闭模态框
  4150. if($scope.sameCust && $scope.validQty) {
  4151. $scope.saveApCheck();
  4152. }
  4153. }
  4154. }]);
  4155. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
  4156. $scope.loading = true;
  4157. AccountEnterprise.get({}, function(data){
  4158. $scope.loading = false;
  4159. $scope.enterprise = data;
  4160. });
  4161. AccountEnterprise.growth({}, function(data){
  4162. if(data != null && data.length > 0) {
  4163. var growth = [], years = [];
  4164. angular.forEach(data, function(d){
  4165. var date = new Date(d.date), year = date.getFullYear();
  4166. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  4167. if(years.indexOf(year) == -1) {
  4168. years.push(year);
  4169. growth.push({year: year});
  4170. }
  4171. growth.push(d);
  4172. });
  4173. $scope.growth = growth;
  4174. }
  4175. });
  4176. // 更新企业信息
  4177. $scope.updateDetailInfo = function(){
  4178. $scope.loading = true;
  4179. AccountEnterprise.save($scope.enterprise, function(){
  4180. $scope.loading = false;
  4181. $scope.connectionEditing = false;
  4182. toaster.pop('success', '提示', '修改企业信息成功');
  4183. $state.reload();
  4184. }, function(response){
  4185. $scope.loading = false;
  4186. toaster.pop('error', '修改信息失败', response.data);
  4187. });
  4188. };
  4189. // 申请Saas
  4190. $scope.applySaas = function(){
  4191. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  4192. var modalInstance = $modal.open({
  4193. animation: true,
  4194. templateUrl: 'static/tpl/index/account/applySaas.html',
  4195. controller: 'ApplySaasCtrl',
  4196. resolve: {
  4197. enterprise: function(){return angular.copy($scope.enterprise);}
  4198. }
  4199. });
  4200. modalInstance.result.then(function(){
  4201. $state.reload();
  4202. }, function(){
  4203. });
  4204. } else {
  4205. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  4206. }
  4207. };
  4208. }]);
  4209. // 申请Saas Controller
  4210. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  4211. $scope.enterprise = enterprise;
  4212. $scope.checking = false;
  4213. $scope.$watch('enterprise.enSaasUrl', function(){
  4214. if($scope.enterprise.enSaasUrl) {
  4215. $http.get('signup/saasUrlEnable', {
  4216. params: {
  4217. enSaasUrl: $scope.enterprise.enSaasUrl
  4218. }
  4219. }).success(function(data){
  4220. if(data && data == 'true') {
  4221. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  4222. } else {
  4223. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  4224. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  4225. }
  4226. }).error(function(){
  4227. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  4228. $scope.enSaasUrlErrorInfo = '验证出错';
  4229. });
  4230. } else {
  4231. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  4232. }
  4233. });
  4234. var setSaasUrl = function(url) {
  4235. var index = url.indexOf('www.');
  4236. if(index != -1) {//包含www.
  4237. var substr = url.substring(index+4, url.length);
  4238. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  4239. } else {
  4240. $scope.enterprise.enSaasUrl = getHost(url);
  4241. }
  4242. };
  4243. // 解析获取网址的一级域名
  4244. var getHost = function(host){
  4245. var newhost;
  4246. var domain;
  4247. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  4248. for(var k in ArrDomain){
  4249. var re = eval('/\\' + ArrDomain[k] + '$/g');
  4250. newhost = host.replace(re, '');
  4251. if(newhost != host){
  4252. domain = ArrDomain[k];
  4253. break;
  4254. }
  4255. }
  4256. var hostar = newhost.split('.');
  4257. var s = hostar[hostar.length-1];
  4258. return s;
  4259. };
  4260. // 设置优企云服域名为官网网址一级域名
  4261. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  4262. $scope.apply = function(){
  4263. $scope.loading = true;
  4264. AccountEnterprise.applySaas({
  4265. enUU: $scope.enterprise.uu,
  4266. enSaasUrl: $scope.enterprise.enSaasUrl,
  4267. enAdminPassword: $scope.enterprise.enAdminPassword
  4268. }, {}, function(){
  4269. $scope.loading = false;
  4270. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  4271. $modalInstance.close();
  4272. }, function(response){
  4273. $scope.loading = false;
  4274. toaster.pop('error', '申请失败', response.data);
  4275. });
  4276. };
  4277. $scope.cancel = function () {
  4278. $modalInstance.dismiss();
  4279. };
  4280. }]);
  4281. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert){
  4282. $scope.editing = false;
  4283. $scope.loading = true;
  4284. AccountUser.findDistribute({},function(data) {
  4285. $scope.distributes = data;
  4286. console.log($scope.distributes);
  4287. },function(response) {
  4288. toaster.pop('error', '系统错误', response.data);
  4289. })
  4290. AuthenticationService.getAuthentication().success(function(data) {
  4291. $scope.loading = false;
  4292. $scope.user = data;
  4293. });
  4294. var users = [];
  4295. $scope.tableParams = new ngTableParams({
  4296. page : 1,
  4297. count : 5,
  4298. sorting: {
  4299. userName: 'asc'
  4300. }
  4301. }, {
  4302. total : 0,
  4303. counts: [15, 25, 50, 100],
  4304. getData : function($defer, params) {
  4305. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  4306. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  4307. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  4308. params.total(orderedData.length);
  4309. $defer.resolve($scope.users);
  4310. }
  4311. });
  4312. var loadUsers = function() {
  4313. AccountUser.query({}, function(data){
  4314. users = data;
  4315. $scope.tableParams.reload();
  4316. $scope.loading = false;
  4317. });
  4318. };
  4319. loadUsers();
  4320. $scope.saveUser = function(){
  4321. $scope.loading = true;
  4322. AccountUser.update({}, $scope.user, function(data){
  4323. $scope.loading = false;
  4324. toaster.pop('success', '提示', '修改用户信息成功');
  4325. AuthenticationService.getAuthentication().success(function(data) {
  4326. $scope.user = data;
  4327. });
  4328. loadUsers();
  4329. $scope.editing = false;
  4330. }, function(reponse){
  4331. $scope.loading = false;
  4332. toaster.pop('error', '失败', reponse.data);
  4333. });
  4334. };
  4335. $scope.updatePassword = function(){
  4336. var modalInstance = $modal.open({
  4337. animation: true,
  4338. templateUrl: 'updatePassword.html',
  4339. controller: 'PasswordCtrl',
  4340. resolve: {
  4341. user: function(){return $scope.user;}
  4342. }
  4343. });
  4344. modalInstance.result.then(function(){
  4345. }, function(){
  4346. });
  4347. };
  4348. $scope.newUser = {};
  4349. //弹出添加用户模态框
  4350. $scope.addExistUser = function(){
  4351. var modalInstance = $modal.open({
  4352. animation :true,
  4353. templateUrl : 'static/tpl/index/account/addExistUser.html',
  4354. controller : 'AddExistUserCtrl'
  4355. });
  4356. modalInstance.result.then(function(){
  4357. $scope.userTelSuccess = false;
  4358. $scope.userTelError = false;
  4359. }, function(){
  4360. });
  4361. };
  4362. /**
  4363. * 添加未注册用户
  4364. */
  4365. $scope.addUser = function() {
  4366. $scope.adding = true;
  4367. AccountUser.save({}, $scope.newUser, function(){
  4368. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  4369. $scope.newUser = {userSex: 'M'};
  4370. loadUsers();
  4371. $scope.adding = false;
  4372. $scope.newUserForm.newUserTel.$setValidity('available', false);
  4373. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  4374. $scope.userTelSuccess = false;
  4375. $scope.userTelError = false;
  4376. $scope.userEmailSuccess = false;
  4377. $scope.userEmailError = false;
  4378. }, function(response){
  4379. toaster.pop('error', '错误', response.data);
  4380. });
  4381. };
  4382. /**
  4383. * 验证手机号是否可用
  4384. */
  4385. $scope.telValid = function(tel) {
  4386. if(tel) {
  4387. $http.get('account/user/telEnable', {
  4388. params: {
  4389. tel: tel
  4390. }
  4391. }).success(function(data){
  4392. data = eval(data);
  4393. if(data == true) {
  4394. $scope.newUserForm.newUserTel.$setValidity('available', true);
  4395. $scope.userTelSuccess = true;
  4396. $scope.userTelError = false;
  4397. }else{
  4398. $scope.newUserForm.newUserTel.$setValidity('available', false);
  4399. $scope.userTelError = true;
  4400. $scope.userTelSuccess = false;
  4401. if(tel.length == 11)
  4402. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  4403. }
  4404. }).error(function(){
  4405. $scope.userTelSuccess = false;
  4406. $scope.userTelError = true;
  4407. });
  4408. } else {
  4409. $scope.userTelSuccess = false;
  4410. $scope.userTelError = false;
  4411. }
  4412. };
  4413. /**
  4414. * 验证邮箱是否可用
  4415. */
  4416. $scope.emailValid = function(email) {
  4417. if(email) {
  4418. $http.get('account/user/emailEnable', {
  4419. params: {
  4420. email: email
  4421. }
  4422. }).success(function(data){
  4423. data = eval(data);
  4424. if(data == true) {
  4425. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  4426. $scope.userEmailSuccess = true;
  4427. $scope.userEmailError = false;
  4428. } else {
  4429. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  4430. $scope.userEmailError = true;
  4431. $scope.userEmailSuccess = false;
  4432. }
  4433. }).error(function(){
  4434. $scope.userEmailError = true;
  4435. $scope.userEmailSuccess = false;
  4436. });
  4437. } else {
  4438. $scope.userEmailError = false;
  4439. $scope.userEmailSuccess = false;
  4440. }
  4441. };
  4442. /**
  4443. * 删除用户
  4444. */
  4445. $scope.removeUser = function(user) {
  4446. new ngAlert({
  4447. title: '提示',
  4448. content: '确定删除用户(' + user.userName + ')吗?'
  4449. }, function(){
  4450. AccountUser.remove({uu: user.userUU}, function(){
  4451. toaster.pop('success', '提示', '用户删除成功。');
  4452. loadUsers();
  4453. }, function(response){
  4454. toaster.pop('error', '删除失败', response.data);
  4455. });
  4456. });
  4457. };
  4458. // 编辑用户的角色
  4459. $scope.editUserRole = function(user) {
  4460. var modalInstance = $modal.open({
  4461. animation: true,
  4462. templateUrl: 'static/tpl/index/account/user_role.html',
  4463. controller: 'UserRoleCtrl',
  4464. resolve: {
  4465. user: function() {
  4466. return user;
  4467. }
  4468. }
  4469. });
  4470. modalInstance.result.then(function(changed, checked){
  4471. if(changed) {
  4472. if(checked)
  4473. $scope.newUser.roles = checked;
  4474. else
  4475. loadUsers();
  4476. }
  4477. });
  4478. };
  4479. // 为用户分配角色(删除企业)
  4480. $scope.removeVendor = function(user) {
  4481. var resultRole = true;
  4482. angular.forEach(user.roles,function(role){
  4483. if(role.issys == 1) {
  4484. toaster.pop('error', '提示', '管理员无需分配客户');
  4485. resultRole = false;
  4486. return;
  4487. }
  4488. })
  4489. if(resultRole) {
  4490. var modalInstance = $modal.open({
  4491. animation: true,
  4492. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  4493. controller: 'RemoveVendorCtrl',
  4494. resolve: {
  4495. user: function() {
  4496. return user;
  4497. }
  4498. }
  4499. });
  4500. }
  4501. }
  4502. // 为用户分配角色(添加企业)
  4503. $scope.addVendor = function(user,isIssy) {
  4504. if(!isIssy) {
  4505. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  4506. return;
  4507. }
  4508. var resultRole = true;
  4509. angular.forEach(user.roles,function(role){
  4510. if(role.issys == 1) {
  4511. toaster.pop('error', '提示', '管理员无需分配客户');
  4512. resultRole = false;
  4513. return;
  4514. }
  4515. })
  4516. if(resultRole) {
  4517. var modalInstance = $modal.open({
  4518. animation: true,
  4519. templateUrl: 'static/tpl/index/account/add_vendor.html',
  4520. controller: 'AddVendorCtrl',
  4521. resolve: {
  4522. user: function() {
  4523. return user;
  4524. }
  4525. }
  4526. });
  4527. modalInstance.result.then(function(changed, checked){
  4528. if(changed) {
  4529. if(checked)
  4530. $scope.newUser.roles = checked;
  4531. else
  4532. loadUsers();
  4533. }
  4534. });
  4535. }
  4536. };
  4537. }]);
  4538. // 登录手机号码验证
  4539. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  4540. $scope.user = user;
  4541. $scope.cancel = function(){
  4542. $modalInstance.close();
  4543. }
  4544. /*$scope.loading = false;
  4545. $scope.btnState = false;
  4546. $scope.clicks = 0;
  4547. var storage = window.localStorage;
  4548. //手机验证码定时器
  4549. $scope.msgInfoError = false;
  4550. var setBtnTimeDown = function(value) {
  4551. if(value > 0) {
  4552. $scope.btnState = true;
  4553. $timeout(function() {
  4554. $scope.$apply(function(){
  4555. storage.setItem("btnTimes", $scope.btnTimes);
  4556. $scope.btnTimes --;
  4557. value --;
  4558. setBtnTimeDown (value);
  4559. });
  4560. }, 500);
  4561. }else{
  4562. $scope.btnState = false;
  4563. }
  4564. };
  4565. if(storage.btnTimes > 1){
  4566. $scope.btnTimes = storage.btnTimes;
  4567. setBtnTimeDown(storage.btnTimes)
  4568. }else{
  4569. storage.removeItem("btnTimes");
  4570. }
  4571. $scope.updateTel = function(phoneCode, userTel, uu){
  4572. $scope.loading = true;
  4573. $scope.msgInfoError = false;
  4574. $scope.result = false;
  4575. //更新联系方式
  4576. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  4577. $scope.loading = false;
  4578. $scope.msgInfoError2 = false;
  4579. $scope.result = true;
  4580. AuthenticationService.getAuthentication().success(function(data) {
  4581. $timeout(function(){
  4582. $modalInstance.dismiss();
  4583. window.location.reload();
  4584. }, 1000);
  4585. }).error(function(response) {
  4586. });
  4587. }, function(response){
  4588. $scope.loading = false;
  4589. $scope.msgInfoError2 = response;
  4590. });
  4591. };
  4592. //获取验证码
  4593. $scope.getPhoneCode = function(userTel){
  4594. var timeInfo = 10;
  4595. $scope.clicks ++;
  4596. $scope.timeInfo = timeInfo;
  4597. if($scope.clicks >= 5){
  4598. $scope.errorloading = true;
  4599. $scope.msgInfoSuccess = false;
  4600. $scope.msgInfoError = false;
  4601. }else{
  4602. $scope.loading = true;
  4603. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  4604. $scope.loading = false;
  4605. $scope.msgInfoSuccess = data.success;
  4606. $scope.sendMsg = data;
  4607. $scope.btnTimes = 60;
  4608. setBtnTimeDown($scope.btnTimes);
  4609. $scope.msgInfoError = false;
  4610. },function(response){
  4611. console.log(response);
  4612. $scope.loading = false;
  4613. $scope.msgInfoError = false;
  4614. $scope.sendCheckMsg = false;
  4615. $scope.msgInfoSuccess = true;
  4616. });
  4617. }
  4618. }; */
  4619. }]);
  4620. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  4621. $scope.checkboxes = {
  4622. checked : false
  4623. };
  4624. $scope.loading = true;
  4625. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  4626. $scope.enters = data;
  4627. $scope.loading = false;
  4628. angular.forEach($scope.enters, function(item) {
  4629. item:{
  4630. $selected:true;
  4631. }
  4632. });
  4633. })
  4634. // 点击勾选全部的复选框
  4635. $scope.checkAll = function() {
  4636. angular.forEach($scope.enters, function(item) {
  4637. item.$selected = $scope.checkboxes.checked;
  4638. });
  4639. };
  4640. // 点击其中一个明细的复选框
  4641. $scope.checkOne = function(vendor){
  4642. var result = true;
  4643. angular.forEach($scope.enters, function(item) {
  4644. if(item.$selected != true){
  4645. result = false;
  4646. return;
  4647. }
  4648. });
  4649. $scope.checkboxes.checked = result;
  4650. };
  4651. $scope.close = function(save) {
  4652. var chooseResult = [];
  4653. if(save) {
  4654. if(user.userUU) {
  4655. angular.forEach($scope.enters, function(item, i) {
  4656. if(item.$selected) {
  4657. chooseResult.push(item.id);
  4658. }
  4659. });
  4660. if(chooseResult.length > 0) {
  4661. $scope.loading = true;
  4662. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  4663. $scope.loading = false;
  4664. toaster.pop('success', '提示', '删除成功');
  4665. $modalInstance.close(false);
  4666. }, function(response){
  4667. $scope.loading = false;
  4668. toaster.pop('error', '删除失败', response.data);
  4669. $modalInstance.close(false);
  4670. })
  4671. } else {
  4672. toaster.pop('error', '删除失败', "您未勾选任何记录");
  4673. }
  4674. } else {
  4675. $modalInstance.close(true, $scope.checkboxes.checked);
  4676. }
  4677. } else {
  4678. $modalInstance.close(false);
  4679. }
  4680. };
  4681. }]);
  4682. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  4683. $scope.checkboxes = {
  4684. checked : false
  4685. };
  4686. $scope.loading = true;
  4687. AccountUser.findVendor({uu : user.userUU},function(data) {
  4688. $scope.enters = data;
  4689. $scope.loading = false;
  4690. // angular.forEach($scope.enters, function(item) {
  4691. // if(item.distribute) {
  4692. // item:{
  4693. // $selected:false;
  4694. // }
  4695. // } else {
  4696. // item:{
  4697. // $selected:true;
  4698. // }
  4699. // }
  4700. // });
  4701. })
  4702. // 点击勾选全部的复选框
  4703. $scope.checkAll = function() {
  4704. angular.forEach($scope.enters, function(item) {
  4705. item.distribute = $scope.checkboxes.checked;
  4706. });
  4707. };
  4708. // 点击其中一个明细的复选框
  4709. $scope.checkOne = function(vendor){
  4710. var result = true;
  4711. angular.forEach($scope.enters, function(item) {
  4712. if(item.distribute != true){
  4713. result = false;
  4714. return;
  4715. }
  4716. });
  4717. $scope.checkboxes.checked = result;
  4718. };
  4719. $scope.close = function(save) {
  4720. var chooseResult = [];
  4721. if(save) {
  4722. if(user.userUU) {
  4723. angular.forEach($scope.enters, function(item, i) {
  4724. // if(item.distribute) {
  4725. chooseResult.push(item);
  4726. // }
  4727. });
  4728. if(chooseResult.length > 0) {
  4729. $scope.loading = true;
  4730. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  4731. $scope.loading = false;
  4732. toaster.pop('success', '提示', '保存成功');
  4733. $modalInstance.close(false);
  4734. }, function(response){
  4735. $scope.loading = false;
  4736. toaster.pop('error', '保存失败', response.data);
  4737. $modalInstance.close(false);
  4738. })
  4739. } else {
  4740. toaster.pop('error', '保存失败', "您未勾选任何记录");
  4741. }
  4742. } else {
  4743. $modalInstance.close(true, $scope.checkboxes.checked);
  4744. }
  4745. } else {
  4746. $modalInstance.close(false);
  4747. }
  4748. };
  4749. }]);
  4750. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  4751. $scope.checked = [];
  4752. $scope.master = [];
  4753. AccountRole.query({}, function(data){
  4754. if(user && data) {
  4755. var rs = [], checked = [];
  4756. angular.forEach(user.roles, function(r){
  4757. rs.push(r.id);
  4758. });
  4759. angular.forEach(data, function(d){
  4760. if(rs.indexOf(d.id) > -1) {
  4761. d.$checked = true;
  4762. checked.push(d);
  4763. }
  4764. });
  4765. }
  4766. $scope.roles = data;
  4767. $scope.checked = checked;
  4768. $scope.master = angular.copy($scope.checked);
  4769. });
  4770. $scope.select = function(role) {
  4771. role.$checked = !role.$checked;
  4772. if(role.$checked) {
  4773. $scope.checked.push(role);
  4774. } else {
  4775. angular.forEach($scope.checked, function(c, i){
  4776. if(c.id == role.id)
  4777. $scope.checked.splice(i, 1);
  4778. });
  4779. }
  4780. };
  4781. $scope.isChanged = function() {
  4782. return !angular.equals($scope.master, $scope.checked);
  4783. };
  4784. $scope.close = function(save) {
  4785. if(save) {
  4786. if(user.userUU) {
  4787. user.roles = $scope.checked;
  4788. AccountUser.update({}, user, function(){
  4789. toaster.pop('success', '提示', '保存成功');
  4790. $modalInstance.close(true);
  4791. }, function(response){
  4792. toaster.pop('error', '保存失败', response.data);
  4793. });
  4794. } else {
  4795. $modalInstance.close(true, $scope.checked);
  4796. }
  4797. } else {
  4798. $modalInstance.close(false);
  4799. }
  4800. };
  4801. }]);
  4802. // 修改密码Controller
  4803. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  4804. $scope.user = user;
  4805. $scope.checking = false;
  4806. //输入原密码后验证原密码是否正确
  4807. $scope.checkPassword = function(password) {
  4808. $scope.checking = true;
  4809. $scope.checkSuccess = false;
  4810. $scope.checkFailed = false;
  4811. AccountUser.checkPassword({password: password}, function(data){
  4812. $scope.checkSuccess = true;
  4813. $scope.checking = false;
  4814. $scope.checkFailed = false;
  4815. }, function(response){
  4816. $scope.checkFailed = true;
  4817. $scope.checking = false;
  4818. $scope.checkSuccess = false;
  4819. });
  4820. };
  4821. //修改密码
  4822. $scope.ok = function () {
  4823. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  4824. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  4825. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  4826. $scope.user.password = null;
  4827. $scope.user.newPassword = null;
  4828. $scope.user.newPassword1 = null;
  4829. $scope.checking = false;
  4830. $scope.checkSuccess = false;
  4831. $scope.checkFailed = false;
  4832. }, function(response){
  4833. toaster.pop('error', '错误', response.data);
  4834. });
  4835. } else {
  4836. toaster.pop('error', '错误', '重复密码不一致');
  4837. }
  4838. };
  4839. $scope.cancel = function () {
  4840. $modalInstance.dismiss();
  4841. };
  4842. }]);
  4843. /*
  4844. * 绑定用户到企业
  4845. */
  4846. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', function($scope, $modalInstance, FuzzySearch,AuthenticationService){
  4847. $scope.searching = false;
  4848. //根据输入的内容查找用户
  4849. $scope.searchUser = function(keyWord) {
  4850. $scope.searching = true;
  4851. $scope.searchSuccess = false;
  4852. $scope.searchFailed = false;
  4853. $scope.illegalError = false;
  4854. $scope.reBindError = false;
  4855. $scope.bindSuccess = false;
  4856. $scope.okDisabled = false;
  4857. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  4858. $scope.searchSuccess = true;
  4859. $scope.searchFailed = false;
  4860. $scope.user = data; //查询到的用户
  4861. }, function(response){
  4862. $scope.searchSuccess = false;
  4863. $scope.searchFailed = true;
  4864. });
  4865. };
  4866. //确认绑定
  4867. $scope.ok = function (keyWord) {
  4868. AuthenticationService.getAuthentication().success(function(data) {
  4869. $scope.currentUser = data; //当前登录的用户(管理员)
  4870. //不可自己绑定自己
  4871. if($scope.currentUser.userUU == $scope.user.userUU){
  4872. $scope.illegalError = true;
  4873. $scope.okDisabled = true;
  4874. return false;
  4875. }
  4876. //用户未绑定到任何企业时
  4877. if(!$scope.user.enterprises){
  4878. //正常绑定
  4879. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  4880. $scope.bindSuccess = true; //绑定成功
  4881. $scope.okDisabled = true;
  4882. }, function(response){
  4883. });
  4884. return true;
  4885. }
  4886. //用户已绑定到某些企业时
  4887. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  4888. if($scope.currentUser.enterprises[i].current){
  4889. for(var j = 0; j < $scope.user.enterprises.length; j++){
  4890. //该用户已绑定到当前企业,不可重复绑定
  4891. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  4892. $scope.reBindError = true;
  4893. $scope.okDisabled = true;
  4894. return false;
  4895. }
  4896. }
  4897. //该用户未绑定到当前企业,可以进行绑定
  4898. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  4899. $scope.bindSuccess = true; //绑定成功
  4900. $scope.okDisabled = true;
  4901. }, function(response){
  4902. console.log("绑定失败!");
  4903. });
  4904. }
  4905. }
  4906. });
  4907. };
  4908. $scope.cancel = function () {
  4909. $modalInstance.dismiss();
  4910. };
  4911. }]);
  4912. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  4913. $scope.erpParams = new ngTableParams({
  4914. page : 1,
  4915. count : 5,
  4916. sorting: {
  4917. time: 'desc'
  4918. }
  4919. }, {
  4920. total : 0,
  4921. counts: [5, 10, 25, 50],
  4922. getData : function($defer, params) {
  4923. $scope.loading = true;
  4924. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  4925. $scope.loading = false;
  4926. if(page) {
  4927. params.total(page.totalElements);
  4928. $defer.resolve(page.content);
  4929. }
  4930. }, function(response){
  4931. $scope.loading = false;
  4932. toaster.pop('error', '数据加载失败', response.data);
  4933. });
  4934. }
  4935. });
  4936. $scope.usageParams = new ngTableParams({
  4937. page : 1,
  4938. count : 5,
  4939. sorting: {
  4940. time: 'desc'
  4941. }
  4942. }, {
  4943. total : 0,
  4944. counts: [5, 10, 25, 50],
  4945. getData : function($defer, params) {
  4946. $scope.loading = true;
  4947. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  4948. $scope.loading = false;
  4949. if(page) {
  4950. params.total(page.totalElements);
  4951. $defer.resolve(page.content);
  4952. }
  4953. }, function(response){
  4954. $scope.loading = false;
  4955. toaster.pop('error', '数据加载失败', response.data);
  4956. });
  4957. }
  4958. });
  4959. }]);
  4960. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  4961. AccountResource.query({}, function(data){
  4962. if(data && data.length > 0) {
  4963. data[0].$open = true;
  4964. }
  4965. $scope.resources = data;
  4966. });
  4967. }]);
  4968. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  4969. $scope.roles = {};
  4970. var getData = function() {
  4971. AccountRole.query({}, function(data){
  4972. var defaults = [], custom = [];
  4973. angular.forEach(data, function(d){
  4974. if(d.isdefault == 1)
  4975. defaults.push(d);
  4976. else
  4977. custom.push(d);
  4978. });
  4979. $scope.roles = {defaults: defaults, custom: custom};
  4980. });
  4981. };
  4982. getData();
  4983. $scope.editRole = function(role){
  4984. var modalInstance = $modal.open({
  4985. animation: true,
  4986. templateUrl: 'static/tpl/index/account/role_detail.html',
  4987. controller: 'RoleEditCtrl',
  4988. resolve: {
  4989. role: function() {
  4990. return role;
  4991. }
  4992. }
  4993. });
  4994. modalInstance.result.then(function(added){
  4995. added && (getData());
  4996. });
  4997. };
  4998. }]);
  4999. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
  5000. $scope.role = role;
  5001. $scope.master = angular.copy($scope.role);
  5002. var isNew = role == null;
  5003. $scope.cancel = function() {
  5004. $modalInstance.close(false);
  5005. };
  5006. AccountResource.query({}, function(data){
  5007. if(data && data.length > 0) {
  5008. if(role && role.resourceItems) {
  5009. var rs = [];// 已分配的资源的id
  5010. angular.forEach(role.resourceItems, function(item){
  5011. rs.push(item.id);
  5012. });
  5013. angular.forEach(data, function(resource){
  5014. var c = 0;
  5015. angular.forEach(resource.items, function(item){
  5016. if(rs.indexOf(item.id) > -1) {
  5017. item.$checked = true;
  5018. c += 1;
  5019. }
  5020. });
  5021. resource.$checked = c == resource.items.length;
  5022. });
  5023. }
  5024. $scope.resourceItems = data[0].items;
  5025. data[0].$active = true;
  5026. }
  5027. $scope.resources = data;
  5028. $timeout(function(){
  5029. angular.forEach($scope.resources, function(resource){
  5030. var c = 0;
  5031. angular.forEach(resource.items, function(item){
  5032. item.$checked && (c+=1);
  5033. });
  5034. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5035. });
  5036. }, 100);
  5037. });
  5038. $scope.onItemClick = function(resource) {
  5039. $scope.resourceItems = resource.items;
  5040. angular.forEach($scope.resources, function(r){
  5041. r.$active = false;
  5042. });
  5043. resource.$active = true;
  5044. };
  5045. var getChecked = function() {
  5046. var items = [];
  5047. angular.forEach($scope.resources, function(resource){
  5048. angular.forEach(resource.items, function(item){
  5049. item.$checked && (items.push(item));
  5050. });
  5051. });
  5052. $scope.role.resourceItems = items;
  5053. };
  5054. $scope.onResourceChange = function(resource) {
  5055. angular.forEach(resource.items, function(item){
  5056. item.$checked = resource.$checked;
  5057. });
  5058. getChecked();
  5059. };
  5060. $scope.onItemChange = function() {
  5061. angular.forEach($scope.resources, function(resource){
  5062. if(resource.$active) {
  5063. var c = 0;
  5064. angular.forEach(resource.items, function(item){
  5065. item.$checked && (c+=1);
  5066. });
  5067. resource.$checked = (c == resource.items.length);
  5068. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5069. }
  5070. });
  5071. getChecked();
  5072. };
  5073. $scope.isChanged = function(formData) {
  5074. if(!$scope.master)
  5075. return true;
  5076. return !angular.equals(formData, $scope.master);
  5077. };
  5078. $scope.save = function() {
  5079. $scope.master = angular.copy($scope.role);
  5080. AccountRole.save($scope.master, function(){
  5081. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  5082. $modalInstance.close(true);
  5083. }, function(response){
  5084. toaster.pop('error', '错误', response.data);
  5085. });
  5086. };
  5087. $scope.del = function() {
  5088. new ngAlert({
  5089. title: '提示',
  5090. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  5091. }, function(){
  5092. AccountRole.remove({id: role.id}, function(){
  5093. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  5094. $modalInstance.close(true);
  5095. }, function(response){
  5096. toaster.pop('error', '错误', response.data);
  5097. });
  5098. })
  5099. };
  5100. }]);
  5101. /**
  5102. * 委外订单
  5103. */
  5104. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  5105. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  5106. $scope.active = 'todo';
  5107. $scope.dateZoneText = '不限';
  5108. $scope.condition = {dateZone: -1};
  5109. $scope.changeDateZone = function(zone) {
  5110. $scope.condition.dateZone = zone;
  5111. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5112. $scope.condition.$dateZoneOpen = false;
  5113. getDateCondition(zone, $scope.condition);
  5114. $scope.tableParams.reload();
  5115. };
  5116. $scope.setActive = function(state) {
  5117. if($scope.active != state) {
  5118. $scope.active = state;
  5119. if($scope.tableParams.page() == 1)
  5120. $scope.tableParams.reload();
  5121. else
  5122. $scope.tableParams.page(1);
  5123. }
  5124. };
  5125. var getService = function() {
  5126. return MakeOrder;
  5127. };
  5128. $scope.tableParams = new ngTableParams({
  5129. page : 1,
  5130. count : 5,
  5131. sorting: {
  5132. date: 'desc'
  5133. }
  5134. }, {
  5135. total : 0,
  5136. counts: [5, 10, 25, 50],
  5137. getData : function($defer, params) {
  5138. $scope.loading = true;
  5139. var pageParams = params.url();
  5140. pageParams.searchFilter = {};
  5141. pageParams.searchFilter.keyword = $scope.keyword;
  5142. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5143. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5144. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5145. $scope.loading = false;
  5146. if(page) {
  5147. params.total(page.totalElements);
  5148. $defer.resolve(page.content);
  5149. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5150. }
  5151. }, function(response){
  5152. $scope.loading = false;
  5153. toaster.pop('error', '数据加载失败', response.data);
  5154. });
  5155. }
  5156. });
  5157. $scope.getOrderTotal = function(items) {
  5158. var sum = 0;
  5159. angular.forEach(items, function(item){
  5160. sum += item.qty * item.price;
  5161. });
  5162. return sum;
  5163. };
  5164. $scope.openDatePicker = function($event, item, openParam) {
  5165. $event.preventDefault();
  5166. $event.stopPropagation();
  5167. item[openParam] = !item[openParam];
  5168. };
  5169. $scope.parseDate = function(dateStr) {
  5170. if(dateStr)
  5171. return Date.parse(dateStr, 'yyyy-MM-dd');
  5172. return new Date();
  5173. };
  5174. // 打开回复
  5175. $scope.openReply = function(order) {
  5176. if(!order.reply) {
  5177. order.reply = {
  5178. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  5179. delivery: order.delivery
  5180. }
  5181. }
  5182. order.$editing = true;
  5183. };
  5184. // 关闭回复
  5185. $scope.closeReply = function(order) {
  5186. order.$editing = false;
  5187. }
  5188. // 搜索框回车
  5189. $scope.onSearch = function() {
  5190. $scope.tableParams.page(1);
  5191. $scope.tableParams.reload();
  5192. };
  5193. // 选择查找日期
  5194. $scope.onDateCondition = function(){
  5195. $scope.tableParams.page(1);
  5196. $scope.tableParams.reload();
  5197. };
  5198. // 点击回复
  5199. $scope.onReplyClick = function(order, inverse) {
  5200. if(order.reply) {
  5201. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  5202. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5203. return;
  5204. }
  5205. var reply = angular.copy(order.reply);
  5206. if(reply.delivery) {
  5207. if(typeof reply.delivery == 'object')
  5208. reply.delivery = reply.delivery.getTime();
  5209. } else {
  5210. reply.delivery = order.delivery;
  5211. }
  5212. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  5213. $scope.loading = true;
  5214. MakeOrder.reply({orderId: order.id}, reply, function(){
  5215. $scope.loading = false;
  5216. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  5217. $scope.tableParams.reload();
  5218. }, function(response){
  5219. $scope.loading = false;
  5220. toaster.pop('error', '回复失败', response.data);
  5221. });
  5222. }
  5223. };
  5224. $scope.print = function(order) {
  5225. MakeOrder.printCount({id: order.id},{});//增加打印此次
  5226. ReportService.print(order.enUU, 'make', '{make_orders.ma_id}=' + order.id, ' 委外订单-' + order.code);
  5227. };
  5228. // 获取回复记录
  5229. $scope.getReply = function(order) {
  5230. if(!order.replies) {
  5231. MakeOrder.getReply({orderId: order.id}, function(replies){
  5232. order.replies = replies;
  5233. });
  5234. }
  5235. };
  5236. }]);
  5237. /**
  5238. * 委外加工单详细
  5239. */
  5240. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOrder, toaster, ReportService){
  5241. var loadData = function() {
  5242. MakeOrder.get({id: $stateParams.id}, function(data){
  5243. $scope.order = data;
  5244. var sum = $scope.order.qty * $scope.order.price;
  5245. $scope.order.total = sum;
  5246. $scope.loading = false;
  5247. });
  5248. };
  5249. loadData();
  5250. // 获取回复记录
  5251. $scope.getReply = function(item) {
  5252. if(!item.replies) {
  5253. MakeOrder.getReply({orderId: item.id}, function(replies){
  5254. item.replies = replies;
  5255. });
  5256. }
  5257. };
  5258. $scope.openDatePicker = function($event, item, openParam) {
  5259. $event.preventDefault();
  5260. $event.stopPropagation();
  5261. item[openParam] = !item[openParam];
  5262. };
  5263. // 点击回复
  5264. $scope.onReplyClick = function(order, inverse) {
  5265. if(order.reply) {
  5266. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  5267. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5268. return;
  5269. }
  5270. var reply = angular.copy(order.reply);
  5271. if(reply.delivery) {
  5272. if(typeof reply.delivery == 'object')
  5273. reply.delivery = reply.delivery.getTime();
  5274. } else {
  5275. reply.delivery = order.delivery;
  5276. }
  5277. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  5278. $scope.loading = true;
  5279. MakeOrder.reply({orderId: order.id}, reply, function(){
  5280. $scope.loading = false;
  5281. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  5282. loadData();
  5283. }, function(response){
  5284. $scope.loading = false;
  5285. toaster.pop('error', '回复失败', response.data);
  5286. });
  5287. }
  5288. };
  5289. // 打开回复
  5290. $scope.openReply = function(order) {
  5291. if(!order.reply) {
  5292. order.reply = {
  5293. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  5294. delivery: order.delivery
  5295. }
  5296. }
  5297. order.$editing = true;
  5298. };
  5299. // 关闭回复
  5300. $scope.closeReply = function(order) {
  5301. order.$editing = false;
  5302. }
  5303. $scope.print = function(order) {
  5304. MakeOrder.printCount({id: order.id},{});//增加打印此次
  5305. ReportService.print(order.enUU, 'make', '{make_orders.ma_id}=' + order.id, ' 委外订单-' + order.code);
  5306. };
  5307. }]);
  5308. /**
  5309. * 客户委外验收
  5310. */
  5311. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  5312. $scope.active = 'all';
  5313. $scope.agreedText = '全部';
  5314. $scope.dateZoneText = '一个月内';
  5315. $scope.condition = {dateZone: 1};
  5316. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5317. $scope.changeAgreed = function(agreed) {
  5318. $scope.condition.agreed = agreed;
  5319. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5320. $scope.condition.$agreedOpen = false;
  5321. };
  5322. $scope.changeDateZone = function(zone) {
  5323. $scope.condition.dateZone = zone;
  5324. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5325. $scope.condition.$dateZoneOpen = false;
  5326. getDateCondition(zone, $scope.condition);
  5327. $scope.tableParams.reload();
  5328. };
  5329. $scope.setActive = function(state) {
  5330. if($scope.active != state) {
  5331. $scope.active = state;
  5332. if($scope.tableParams.page() == 1)
  5333. $scope.tableParams.reload();
  5334. else
  5335. $scope.tableParams.page(1);
  5336. }
  5337. };
  5338. var getService = function() {
  5339. return MakeAccept;
  5340. };
  5341. $scope.tableParams = new ngTableParams({
  5342. page : 1,
  5343. count : 5,
  5344. sorting: {
  5345. date: 'desc'
  5346. }
  5347. }, {
  5348. total : 0,
  5349. counts: [5, 10, 25, 50],
  5350. getData : function($defer, params) {
  5351. $scope.loading = true;
  5352. var pageParams = params.url();
  5353. pageParams.searchFilter = {};
  5354. pageParams.searchFilter.keyword = $scope.keyword;
  5355. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5356. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5357. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5358. $scope.loading = false;
  5359. if(page) {
  5360. params.total(page.totalElements);
  5361. $defer.resolve(page.content);
  5362. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5363. }
  5364. }, function(response){
  5365. $scope.loading = false;
  5366. toaster.pop('error', '数据加载失败', response.data);
  5367. });
  5368. }
  5369. });
  5370. $scope.openDatePicker = function($event, item, openParam) {
  5371. $event.preventDefault();
  5372. $event.stopPropagation();
  5373. item[openParam] = !item[openParam];
  5374. };
  5375. // 搜索框回车
  5376. $scope.onSearch = function() {
  5377. $scope.tableParams.page(1);
  5378. $scope.tableParams.reload();
  5379. };
  5380. // 选择查找日期
  5381. $scope.onDateCondition = function(){
  5382. $scope.tableParams.page(1);
  5383. $scope.tableParams.reload();
  5384. };
  5385. }]);
  5386. /**
  5387. * 客户委外验退
  5388. */
  5389. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  5390. $scope.active = 'all';
  5391. $scope.agreedText = '全部';
  5392. $scope.dateZoneText = '一个月内';
  5393. $scope.condition = {dateZone: 1};
  5394. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5395. $scope.changeAgreed = function(agreed) {
  5396. $scope.condition.agreed = agreed;
  5397. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5398. $scope.condition.$agreedOpen = false;
  5399. };
  5400. $scope.changeDateZone = function(zone) {
  5401. $scope.condition.dateZone = zone;
  5402. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5403. $scope.condition.$dateZoneOpen = false;
  5404. getDateCondition(zone, $scope.condition);
  5405. $scope.tableParams.reload();
  5406. };
  5407. $scope.setActive = function(state) {
  5408. if($scope.active != state) {
  5409. $scope.active = state;
  5410. if($scope.tableParams.page() == 1)
  5411. $scope.tableParams.reload();
  5412. else
  5413. $scope.tableParams.page(1);
  5414. }
  5415. };
  5416. var getService = function() {
  5417. return MakeReturn;
  5418. };
  5419. $scope.tableParams = new ngTableParams({
  5420. page : 1,
  5421. count : 5,
  5422. sorting: {
  5423. date: 'desc'
  5424. }
  5425. }, {
  5426. total : 0,
  5427. counts: [5, 10, 25, 50],
  5428. getData : function($defer, params) {
  5429. $scope.loading = true;
  5430. var pageParams = params.url();
  5431. pageParams.searchFilter = {};
  5432. pageParams.searchFilter.keyword = $scope.keyword;
  5433. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5434. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5435. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5436. $scope.loading = false;
  5437. if(page) {
  5438. params.total(page.totalElements);
  5439. $defer.resolve(page.content);
  5440. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5441. }
  5442. }, function(response){
  5443. $scope.loading = false;
  5444. toaster.pop('error', '数据加载失败', response.data);
  5445. });
  5446. }
  5447. });
  5448. $scope.openDatePicker = function($event, item, openParam) {
  5449. $event.preventDefault();
  5450. $event.stopPropagation();
  5451. item[openParam] = !item[openParam];
  5452. };
  5453. // 搜索框回车
  5454. $scope.onSearch = function() {
  5455. $scope.tableParams.page(1);
  5456. $scope.tableParams.reload();
  5457. };
  5458. // 选择查找日期
  5459. $scope.onDateCondition = function(){
  5460. $scope.tableParams.page(1);
  5461. $scope.tableParams.reload();
  5462. };
  5463. }]);
  5464. /**
  5465. * 委外加工变更
  5466. */
  5467. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  5468. $scope.active = 'all';
  5469. $scope.agreedText = '全部';
  5470. $scope.dateZoneText = '一个月内';
  5471. $scope.condition = {dateZone: 1};
  5472. $scope.changeAgreed = function(agreed) {
  5473. $scope.condition.agreed = agreed;
  5474. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5475. $scope.condition.$agreedOpen = false;
  5476. };
  5477. $scope.changeDateZone = function(zone) {
  5478. $scope.condition.dateZone = zone;
  5479. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5480. $scope.condition.$dateZoneOpen = false;
  5481. getDateCondition(zone, $scope.condition);
  5482. $scope.tableParams.reload();
  5483. };
  5484. $scope.setActive = function(state) {
  5485. if($scope.active != state) {
  5486. $scope.active = state;
  5487. if($scope.tableParams.page() == 1)
  5488. $scope.tableParams.reload();
  5489. else
  5490. $scope.tableParams.page(1);
  5491. }
  5492. };
  5493. var getService = function() {
  5494. return MakeChange;
  5495. };
  5496. $scope.tableParams = new ngTableParams({
  5497. page : 1,
  5498. count : 5,
  5499. sorting: {
  5500. orderChangeDate: 'desc'
  5501. }
  5502. }, {
  5503. total : 0,
  5504. counts: [5, 10, 25, 50],
  5505. getData : function($defer, params) {
  5506. $scope.loading = true;
  5507. var pageParams = params.url();
  5508. pageParams.searchFilter = {};
  5509. pageParams.searchFilter.keyword = $scope.keyword;
  5510. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5511. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5512. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5513. $scope.loading = false;
  5514. if(page) {
  5515. params.total(page.totalElements);
  5516. $defer.resolve(page.content);
  5517. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5518. }
  5519. }, function(response){
  5520. $scope.loading = false;
  5521. toaster.pop('error', '数据加载失败', response.data);
  5522. });
  5523. }
  5524. });
  5525. $scope.openDatePicker = function($event, item, openParam) {
  5526. $event.preventDefault();
  5527. $event.stopPropagation();
  5528. item[openParam] = !item[openParam];
  5529. };
  5530. // 打开回复
  5531. $scope.openReply = function(change) {
  5532. change.$editing = true;
  5533. };
  5534. // 关闭回复
  5535. $scope.closeReply = function(change) {
  5536. change.$editing = false;
  5537. }
  5538. // 确定回复
  5539. $scope.onReplyClick = function(change) {
  5540. if(change.$agreed) {
  5541. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  5542. $scope.loading = true;
  5543. MakeChange.reply({itemId: change.id}, reply, function(){
  5544. $scope.loading = false;
  5545. toaster.pop('info', '提示', '回复成功');
  5546. $scope.tableParams.reload();
  5547. }, function(response){
  5548. $scope.loading = false;
  5549. toaster.pop('error', '回复失败', response.data);
  5550. });
  5551. }
  5552. };
  5553. // 搜索框回车
  5554. $scope.onSearch = function() {
  5555. $scope.tableParams.page(1);
  5556. $scope.tableParams.reload();
  5557. };
  5558. // 选择查找日期
  5559. $scope.onDateCondition = function(){
  5560. $scope.tableParams.page(1);
  5561. $scope.tableParams.reload();
  5562. };
  5563. }]);
  5564. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', function($scope, $stateParams, MakeChange, toaster){
  5565. var loadData = function() {
  5566. MakeChange.get({id: $stateParams.id}, function(data){
  5567. $scope.change = data;
  5568. });
  5569. };
  5570. loadData();
  5571. $scope.openDatePicker = function($event, item, openParam) {
  5572. $event.preventDefault();
  5573. $event.stopPropagation();
  5574. item[openParam] = !item[openParam];
  5575. };
  5576. $scope.onReplyClick = function(change) {
  5577. if(change.$agreed) {
  5578. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  5579. MakeChange.reply({itemId: change.id}, reply, function(){
  5580. toaster.pop('info', '提示', '回复成功');
  5581. loadData();
  5582. }, function(response){
  5583. toaster.pop('error', '回复失败', response.data);
  5584. });
  5585. }
  5586. };
  5587. }]);
  5588. /**
  5589. * 委外加工
  5590. */
  5591. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  5592. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  5593. $scope.active = 'all';
  5594. $scope.agreedText = '全部';
  5595. $scope.dateZoneText = '一个月内';
  5596. $scope.condition = {dateZone: 1};
  5597. $scope.changeAgreed = function(agreed) {
  5598. $scope.condition.agreed = agreed;
  5599. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5600. $scope.condition.$agreedOpen = false;
  5601. };
  5602. $scope.changeDateZone = function(zone) {
  5603. $scope.condition.dateZone = zone;
  5604. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5605. $scope.condition.$dateZoneOpen = false;
  5606. getDateCondition(zone, $scope.condition);
  5607. $scope.tableParams.reload();
  5608. };
  5609. $scope.setActive = function(state) {
  5610. if($scope.active != state) {
  5611. $scope.active = state;
  5612. if($scope.tableParams.page() == 1)
  5613. $scope.tableParams.reload();
  5614. else
  5615. $scope.tableParams.page(1);
  5616. }
  5617. };
  5618. var getService = function() {
  5619. return MakeOutOrder;
  5620. };
  5621. $scope.tableParams = new ngTableParams({
  5622. page : 1,
  5623. count : 5,
  5624. sorting: {
  5625. date: 'desc'
  5626. }
  5627. }, {
  5628. total : 0,
  5629. counts: [5, 10, 25, 50],
  5630. getData : function($defer, params) {
  5631. $scope.loading = true;
  5632. var pageParams = params.url();
  5633. pageParams.searchFilter = {};
  5634. pageParams.searchFilter.keyword = $scope.keyword;
  5635. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5636. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5637. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5638. $scope.loading = false;
  5639. if(page) {
  5640. params.total(page.totalElements);
  5641. $defer.resolve(page.content);
  5642. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5643. }
  5644. }, function(response){
  5645. $scope.loading = false;
  5646. toaster.pop('error', '数据加载失败', response.data);
  5647. });
  5648. }
  5649. });
  5650. $scope.openDatePicker = function($event, item, openParam) {
  5651. $event.preventDefault();
  5652. $event.stopPropagation();
  5653. item[openParam] = !item[openParam];
  5654. };
  5655. // 打开回复
  5656. $scope.openReply = function(change) {
  5657. change.$editing = true;
  5658. };
  5659. // 关闭回复
  5660. $scope.closeReply = function(change) {
  5661. change.$editing = false;
  5662. }
  5663. // 确定回复
  5664. $scope.onReplyClick = function(change) {
  5665. if(change.$agreed) {
  5666. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  5667. $scope.loading = true;
  5668. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  5669. $scope.loading = false;
  5670. toaster.pop('info', '提示', '回复成功');
  5671. $scope.tableParams.reload();
  5672. }, function(response){
  5673. $scope.loading = false;
  5674. toaster.pop('error', '回复失败', response.data);
  5675. });
  5676. }
  5677. };
  5678. // 搜索框回车
  5679. $scope.onSearch = function() {
  5680. $scope.tableParams.page(1);
  5681. $scope.tableParams.reload();
  5682. };
  5683. // 选择查找日期
  5684. $scope.onDateCondition = function(){
  5685. $scope.tableParams.page(1);
  5686. $scope.tableParams.reload();
  5687. };
  5688. }]);
  5689. /**
  5690. * 委外加工详细
  5691. */
  5692. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService) {
  5693. var loadData = function() {
  5694. MakeOutOrder.get({id: $stateParams.id}, function(data){
  5695. $scope.order = data;
  5696. var sum = $scope.order.qty * $scope.order.price;
  5697. $scope.order.total = sum;
  5698. $scope.loading = false;
  5699. });
  5700. };
  5701. loadData();
  5702. // 获取回复记录
  5703. $scope.getReply = function(item) {
  5704. if(!item.replies) {
  5705. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  5706. item.replies = replies;
  5707. });
  5708. }
  5709. };
  5710. $scope.openDatePicker = function($event, item, openParam) {
  5711. $event.preventDefault();
  5712. $event.stopPropagation();
  5713. item[openParam] = !item[openParam];
  5714. };
  5715. // 点击回复
  5716. $scope.onReplyClick = function(order, inverse) {
  5717. if(order.reply) {
  5718. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  5719. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5720. return;
  5721. }
  5722. var reply = angular.copy(order.reply);
  5723. if(reply.delivery) {
  5724. if(typeof reply.delivery == 'object')
  5725. reply.delivery = reply.delivery.getTime();
  5726. } else {
  5727. reply.delivery = order.delivery;
  5728. }
  5729. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  5730. $scope.loading = true;
  5731. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  5732. $scope.loading = false;
  5733. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  5734. loadData();
  5735. }, function(response){
  5736. $scope.loading = false;
  5737. toaster.pop('error', '回复失败', response.data);
  5738. });
  5739. }
  5740. };
  5741. // 打开回复
  5742. $scope.openReply = function(order) {
  5743. if(!order.reply) {
  5744. order.reply = {
  5745. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  5746. delivery: order.delivery
  5747. }
  5748. }
  5749. order.$editing = true;
  5750. };
  5751. // 关闭回复
  5752. $scope.closeReply = function(order) {
  5753. order.$editing = false;
  5754. }
  5755. $scope.print = function(order) {
  5756. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  5757. ReportService.print(order.enUU, 'make', '{make_outorders.ma_id}=' + order.id, ' 自己委外加工订单-' + order.code);
  5758. };
  5759. }]);
  5760. /**
  5761. * 计算时间差
  5762. */
  5763. app.filter('timespan', function(){
  5764. return function(time) {
  5765. if(time == null)
  5766. return '9999年';
  5767. var now = new Date().getTime(), span = time - now,
  5768. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  5769. m = Math.ceil(span/60000);
  5770. if(span < 0)
  5771. return '0天';
  5772. if(d > 0)
  5773. return d + '天';
  5774. if(h > 0)
  5775. return h + '小时';
  5776. if(m > 0)
  5777. return m + '分钟';
  5778. return '0天';
  5779. };
  5780. });
  5781. app.filter('firstchar', function(){
  5782. return function(str) {
  5783. if(str == null)
  5784. return null;
  5785. return str.substring(0, 1);
  5786. };
  5787. });
  5788. /**
  5789. * 搜索框,回车触发
  5790. */
  5791. app.directive('ngSearch', ['$parse', function($parse) {
  5792. return {
  5793. require : '?ngModel',
  5794. restrict : 'A',
  5795. link : function(scope, element, attrs, ngModel) {
  5796. var searchFn = $parse(attrs.ngSearch);
  5797. element.bind('keypress', function(event) {
  5798. if (event.keyCode == '13') {
  5799. event.preventDefault();
  5800. event.stopPropagation();
  5801. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  5802. }
  5803. });
  5804. }
  5805. };
  5806. }]);
  5807. /**
  5808. * 状态码 -> 描述
  5809. */
  5810. app.filter('status', function(){
  5811. return function(data) {
  5812. var statusConfig = {
  5813. '101': '已提交',
  5814. '102': '已审核',
  5815. '103': '未通过',
  5816. '200': '未回复',
  5817. '201': '已回复',
  5818. '313': '已激活',
  5819. '316': '已过账',
  5820. '311': '申请中',
  5821. '312': '未激活'
  5822. };
  5823. return statusConfig[data];
  5824. }
  5825. });
  5826. //弹出问题反馈模态框
  5827. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  5828. //获取当前用户
  5829. AuthenticationService.getAuthentication().success(function(data) {
  5830. $scope.user = data;
  5831. });
  5832. $scope.showModal = function(){
  5833. var modalInstance = $modal.open({
  5834. animation: true,
  5835. templateUrl: 'static/tpl/serve/feedback.html',
  5836. controller: 'FeedbackCtrl',
  5837. resolve: {
  5838. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  5839. }
  5840. });
  5841. modalInstance.result.then(function(){
  5842. }, function(){
  5843. })
  5844. }
  5845. }]);
  5846. /*
  5847. * 提交我的反馈
  5848. */
  5849. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  5850. $scope.isPublic = 1; //默认公开
  5851. $scope.classId = 1; //默认类别
  5852. $scope.user = user;
  5853. $scope.ok = function(){
  5854. if(!$scope.user){ //用户未登录
  5855. $scope.uu = null;
  5856. }else{ //用户已登录
  5857. $scope.uu = $scope.user.userUU;
  5858. }
  5859. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  5860. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  5861. function(data){
  5862. toaster.pop('success', '成功', '您的问题反馈成功!');
  5863. $scope.cancel();
  5864. }, function(response){
  5865. toaster.pop('error', '错误', response.data);
  5866. });
  5867. }
  5868. $scope.cancel = function () {
  5869. $modalInstance.dismiss();
  5870. };
  5871. }]);
  5872. //“我的问题反馈”跳转控制
  5873. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  5874. $scope.myFeedback = function(){
  5875. AuthenticationService.getAuthentication().success(function(data){
  5876. $scope.user = data;
  5877. if(!$scope.user){
  5878. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  5879. return false;
  5880. }else{
  5881. window.location.href = "./serve#/question/myFeedback";
  5882. }
  5883. });
  5884. }
  5885. }]);
  5886. //客户服务
  5887. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  5888. Vendor.getServe(function(datas){
  5889. $scope.vendors = datas;
  5890. console.log($scope.Vender);
  5891. // 自动跳转
  5892. if(datas && datas.length == 1)
  5893. $scope.redirect(datas[0]);
  5894. });
  5895. $scope.redirect = function(vendor) {
  5896. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  5897. };
  5898. }]);
  5899. return app;
  5900. });