app.js 317 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder'], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config([ '$httpProvider', function($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function(response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url : "/index",
  26. views : {
  27. "left-view" : {
  28. templateUrl : "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view" : {
  32. templateUrl : "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url : "/",
  38. views : {
  39. "left-view" : {
  40. templateUrl : "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view" : {
  44. templateUrl : "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url : "/sale",
  50. views : {
  51. "left-view" : {
  52. templateUrl : "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view" : {
  56. templateUrl : "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url : "",
  65. templateUrl : "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url : "/",
  68. templateUrl : "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url : "/purc",
  71. views : {
  72. "left-view" : {
  73. templateUrl : "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view" : {
  77. templateUrl : "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url : "",
  86. templateUrl : "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url : "/",
  89. templateUrl : "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url : "/introduce",
  92. templateUrl : "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url : "/order",
  95. templateUrl : "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url : "/order/:id",
  99. templateUrl : "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url : "/addOrder",
  103. templateUrl : "static/tpl/index/purc/addOrder.html",
  104. controller : 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url : "/cart",
  107. templateUrl : "static/tpl/index/purc/cart.html",
  108. controller : 'CartController'
  109. }).state('purc.cartDetail', {
  110. url : "/cart/:id",
  111. templateUrl : "static/tpl/index/purc/cart_detail.html",
  112. controller : 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url : "/deputy",
  115. templateUrl : "static/tpl/index/purc/deputyOrder.html",
  116. controller : 'DeputyOrderCtrl'
  117. }).state('purc.newdeputy', {
  118. url : "/deputy/add",
  119. templateUrl : "static/tpl/index/purc/deputyOrder_new.html",
  120. controller : 'NewDeputyOrderCtrl'
  121. }).state('purc.deputydetail', {
  122. url : "/deputy/:id",
  123. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  124. controller : 'DeputyOrderDetailCtrl'
  125. /* 招标列表 */
  126. }).state('purc.tenderlist', {
  127. url : "/tender",
  128. templateUrl : "static/tpl/index/purc/tenderlist.html",
  129. controller : 'PurcTenderCtrl'
  130. }).state('purc.done.tenderlist', {
  131. url : "/tender",
  132. templateUrl : "static/tpl/index/purc/tenderlist.html",
  133. controller : 'PurcTenderCtrl'
  134. /* 招标 */
  135. }).state('purc.tender', {
  136. url : "/tender/:id",
  137. templateUrl : "static/tpl/index/purc/tender.html",
  138. controller : 'PurcNewTenderCtrl'
  139. /* 评标 */
  140. }).state('purc.evaluation', {
  141. url : "/evaluation/:id",
  142. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  143. controller : 'PurcEvaluationCtrl'
  144. /* 客户指定招标列表 */
  145. }).state('sale.tenderlist', {
  146. url : "/tender",
  147. templateUrl : "static/tpl/index/sale/tenderlist.html",
  148. controller : 'SaleTenderCtrl'
  149. }).state('sale.todo.tenderlist', {
  150. url : "/tender",
  151. templateUrl : "static/tpl/index/sale/tenderlist.html",
  152. controller : 'SaleTenderCtrl'
  153. /* 平台公开招标列表 */
  154. }).state('sale.opentenderlist', {
  155. url : "/opentender",
  156. templateUrl : "static/tpl/index/sale/opentenderlist.html",
  157. controller : 'SaleOpenTenderCtrl'
  158. }).state('sale.todo.opentenderlist', {
  159. url : "/opentender",
  160. templateUrl : "static/tpl/index/sale/opentenderlist.html",
  161. controller : 'SaleOpenTenderCtrl'
  162. /* 公开招标单转投标单 */
  163. }).state('sale.opentender', {
  164. url : "/opentender/:id",
  165. templateUrl : "static/tpl/index/sale/tender.html",
  166. controller : 'SaleTenderDetailCtrl'
  167. /* 投标 */
  168. }).state('sale.tender', {
  169. url : "/tender/:id",
  170. templateUrl : "static/tpl/index/sale/tender.html",
  171. controller : 'SaleTenderDetailCtrl'
  172. /* 采购方查看供应商投标 */
  173. }).state('sale.vendortender', {
  174. url : "/tender/:vendUU/:id",
  175. templateUrl : "static/tpl/index/sale/tender_vendor.html",
  176. controller : 'SaleVendorTenderDetailCtrl'
  177. }).state('sale.todo', {
  178. url : "/todo",
  179. templateUrl : "static/tpl/index/sale/todo.html"
  180. }).state('sale.todo.inquiry', {
  181. url : "/inquiry",
  182. templateUrl : "static/tpl/index/sale/inquiry.html",
  183. controller: 'SaleInquiryCtrl'
  184. }).state('sale.todo.order', {
  185. url : "/order",
  186. templateUrl : "static/tpl/index/sale/order.html",
  187. controller: 'SaleOrderCtrl'
  188. }).state('sale.todo.change', {
  189. url : "/change",
  190. templateUrl : "static/tpl/index/sale/change.html",
  191. controller: 'SaleChangeCtrl'
  192. }).state('sale.todo.notice', {
  193. url : "/notice",
  194. templateUrl : "static/tpl/index/sale/notice.html",
  195. controller: 'SaleNoticeCtrl'
  196. }).state('sale.customer', {
  197. url : "/customer",
  198. templateUrl : "static/tpl/index/sale/customer.html",
  199. controller: 'CustomerCtrl'
  200. }).state('sale.customerProduct', {
  201. url : "/customerProduct",
  202. templateUrl : "static/tpl/index/sale/customer.html",
  203. controller: 'CustomerCtrl'
  204. }).state('sale.inquiry', {
  205. url : "/inquiry",
  206. templateUrl : "static/tpl/index/sale/inquiry.html",
  207. controller: 'SaleInquiryCtrl'
  208. }).state('sale.inquirymould', {
  209. url : "/mould",
  210. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  211. controller: 'SaleInquiryMouldCtrl'
  212. }).state('sale.todo.inquirymould', {
  213. url : "/mould",
  214. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  215. controller: 'SaleInquiryMouldCtrl'
  216. }).state('sale.inquiry_mould_detail', {
  217. url : "/mould/:id",
  218. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  219. controller: 'SaleInquiryMouldDetailCtrl'
  220. }).state('sale.inquiry_detail', {
  221. url : "/inquiry/:id",
  222. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  223. controller: 'SaleInquiryDetailCtrl'
  224. }).state('sale.quotation', {
  225. url : "/quotation",
  226. templateUrl : "static/tpl/index/sale/quotation.html"
  227. }).state('sale.quotation.new', {
  228. url : "/new",
  229. templateUrl : "static/tpl/index/sale/quotation_new.html",
  230. controller: 'SaleQuotationNewCtrl'
  231. }).state('sale.quotation.list', {
  232. url : "/list",
  233. templateUrl : "static/tpl/index/sale/quotation_list.html",
  234. controller: 'SaleQuotationListCtrl'
  235. }).state('sale.quotation.item', {
  236. url : "/:id",
  237. templateUrl : "static/tpl/index/sale/quotation_new.html",
  238. controller: 'SaleQuotationNewCtrl'
  239. }).state('sale.order', {
  240. url : "/order",
  241. templateUrl : "static/tpl/index/sale/order.html",
  242. controller: 'SaleOrderCtrl'
  243. }).state('sale.order_detail', {
  244. url : "/order/:id",
  245. templateUrl : "static/tpl/index/sale/order_detail.html",
  246. controller: 'SaleOrderDetailCtrl'
  247. }).state('sale.change', {
  248. url : "/change",
  249. templateUrl : "static/tpl/index/sale/change.html",
  250. controller: 'SaleChangeCtrl'
  251. }).state('sale.change_detail', {
  252. url : "/change/:id",
  253. templateUrl : "static/tpl/index/sale/change_detail.html",
  254. controller: 'SaleChangeDetailCtrl'
  255. }).state('sale.notice', {
  256. url : "/notice",
  257. templateUrl : "static/tpl/index/sale/notice.html",
  258. controller: 'SaleNoticeCtrl'
  259. }).state('sale.send', {
  260. url : "/send",
  261. templateUrl : "static/tpl/index/sale/send.html",
  262. controller: 'SaleSendCtrl'
  263. }).state('sale.send_detail', {
  264. url : "/send/:id",
  265. templateUrl : "static/tpl/index/sale/send_detail.html",
  266. controller: 'SaleSendDetailCtrl'
  267. }).state('sale.forecast', {
  268. url : "/forecast",
  269. templateUrl : "static/tpl/index/sale/forecast.html",
  270. controller: 'SaleForecastCtrl'
  271. }).state('sale.accept', {
  272. url : "/accept",
  273. templateUrl : "static/tpl/index/sale/accept.html",
  274. controller: 'SaleAcceptCtrl'
  275. }).state('sale.returns', {
  276. url : "/returns",
  277. templateUrl : "static/tpl/index/sale/returns.html",
  278. controller: 'SaleReturnsCtrl'
  279. }).state('sale.sample', {
  280. url : "/sample",
  281. templateUrl : "static/tpl/index/sale/sample.html",
  282. controller: 'SaleSampleCtrl'
  283. }).state('sale.sample_detail', {
  284. url : "/sample/:id",
  285. templateUrl : "static/tpl/index/sale/sample_detail.html",
  286. controller: 'SaleSampleDetailCtrl'
  287. }).state('sale.approval', {
  288. url : "/approval",
  289. templateUrl : "static/tpl/index/sale/approval.html",
  290. controller: 'SaleApprovalCtrl'
  291. }).state('account', {
  292. url : "/account",
  293. views : {
  294. "left-view" : {
  295. templateUrl : "static/tpl/index/account/left.html",
  296. controller: 'LeftCtrl'
  297. },
  298. "right-view" : {
  299. templateUrl : "static/tpl/index/account/right.html"
  300. }
  301. }
  302. }).state('account.index', {
  303. url : "",
  304. templateUrl : "static/tpl/index/account/index.html",
  305. controller: 'RightCtrl'
  306. }).state('account.home', {
  307. url : "/",
  308. templateUrl : "static/tpl/index/account/index.html",
  309. controller: 'RightCtrl'
  310. }).state('account.enterprise', {
  311. url : "/enterprise",
  312. templateUrl : "static/tpl/index/account/enterprise.html",
  313. controller: 'EnterpriseCtrl'
  314. }).state('account.user', {
  315. url : "/user",
  316. templateUrl : "static/tpl/index/account/user.html",
  317. controller: 'UserCtrl'
  318. }).state('account.log', {
  319. url : "/log",
  320. templateUrl : "static/tpl/index/account/log.html",
  321. controller: 'LogCtrl'
  322. }).state('account.resource', {
  323. url : "/resource",
  324. templateUrl : "static/tpl/index/account/resource.html",
  325. controller: 'ResourceCtrl'
  326. }).state('account.role', {
  327. url : "/role",
  328. templateUrl : "static/tpl/index/account/role.html",
  329. controller: 'RoleCtrl'
  330. }).state('baseInfo', {//基础资料
  331. url : "/baseInfo",
  332. views : {
  333. "left-view" : {
  334. templateUrl : "static/tpl/index/baseInfo/left.html",
  335. controller: 'LeftCtrl'
  336. },
  337. "right-view" : {
  338. templateUrl : "static/tpl/index/baseInfo/right.html"
  339. }
  340. }
  341. }).state('baseInfo.index', {
  342. url : "/enterpriseList",
  343. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  344. controller: 'EnterpriseListCtrl'
  345. }).state('baseInfo.home', {
  346. url : "/enterpriseList",
  347. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  348. controller: 'EnterpriseListCtrl'
  349. }).state('baseInfo.prodList', {
  350. url : "/prodList",
  351. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  352. controller : 'ProductListCtrl'
  353. }).state('baseInfo.uploadByBatch', {
  354. url : "/uploadByBatch",
  355. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  356. controller : 'UploadByBatchCtrl'
  357. }).state('baseInfo.productDetail', {
  358. url : "/prodList/:id",
  359. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  360. controller : 'ProductDetailCtrl'
  361. }).state('baseInfo.newProdInfo', {
  362. url : "/newProdInfo",
  363. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  364. controller : 'NewProdInfoCtrl'
  365. }).state('baseInfo.enterpriseList', {
  366. url : "/enterpriseList",
  367. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  368. controller : 'EnterpriseListCtrl'
  369. }).state('baseInfo.myClient', {
  370. url : "/myClient",
  371. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  372. controller : 'MyClientCtrl'
  373. }).state('baseInfo.mySupplier', {
  374. url : "/mySupplier",
  375. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  376. controller : 'MySupplierCtrl'
  377. }).state('baseInfo.myRequest', {
  378. url : "/myRquest",
  379. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  380. controller : 'AddPartnerRequestCtrl'
  381. }).state('baseInfo.myMessage', {
  382. url : "/myMessage",
  383. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  384. controller : 'AddPartnerMessageCtrl'
  385. }).state('baseInfo.myPartners', {
  386. url : '/myPartners',
  387. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  388. controller : 'MyPartnersCtrl'
  389. }).state('baseInfo.businessGroups', {
  390. url : '/businessGroups',
  391. controller : 'BusinessGroupsCtrl'
  392. }).state('qc', {
  393. url : "/qc",
  394. views : {
  395. "left-view" : {
  396. templateUrl : "static/tpl/index/qc/left.html"
  397. },
  398. "right-view" : {
  399. templateUrl : "static/tpl/index/qc/right.html"
  400. }
  401. }
  402. }).state('qc.index', {
  403. url : "",
  404. templateUrl : "static/tpl/index/qc/index.html"
  405. }).state('qc.home', {
  406. url : "/",
  407. templateUrl : "static/tpl/index/qc/index.html"
  408. }).state('qc.badIn', {
  409. url : "/badIn",
  410. templateUrl : "static/tpl/index/qc/badIn.html",
  411. controller: 'SaleBadInCtrl'
  412. }).state('qc.badOut', {
  413. url : "/badOut",
  414. templateUrl : "static/tpl/index/qc/badOut.html",
  415. controller: 'SaleBadOutCtrl'
  416. }).state('qc.MRB', {
  417. url : "/MRB",
  418. templateUrl : "static/tpl/index/qc/MRB.html",
  419. controller: 'SaleMRBCtrl'
  420. }).state('fa', {
  421. url : "/fa",
  422. views : {
  423. "left-view" : {
  424. templateUrl : "static/tpl/index/fa/left.html"
  425. },
  426. "right-view" : {
  427. templateUrl : "static/tpl/index/fa/right.html"
  428. }
  429. }
  430. }).state('fa.index', {
  431. url : "",
  432. templateUrl : "static/tpl/index/fa/index.html"
  433. }).state('fa.home', {
  434. url : "/",
  435. templateUrl : "static/tpl/index/fa/index.html"
  436. }).state('fa.apBill', {
  437. url : "/apBill",
  438. templateUrl : "static/tpl/index/fa/apBill.html",
  439. controller: 'SaleApBillCtrl'
  440. }).state('fa.arCheck', {
  441. url : "/arCheck",
  442. templateUrl : "static/tpl/index/fa/arCheck.html",
  443. controller: 'SaleArCheckCtrl'
  444. }).state('fa.arCheck_detail', {
  445. url : "/arCheck/:id",
  446. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  447. controller: 'SaleArCheckDetailCtrl'
  448. }).state('fa.apCheck', {
  449. url : "/apCheck",
  450. params:{
  451. 'id':null
  452. },
  453. templateUrl : "static/tpl/index/fa/apCheck.html",
  454. controller: 'PurchaseApCheckCtrl'
  455. }).state('fa.apCheck_detail', {
  456. url : "/apCheck/:id",
  457. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  458. controller: 'PurchaseApCheckDetailCtrl'
  459. }).state('fa.apCheckList', {
  460. url : "/apCheckList",
  461. templateUrl : "static/tpl/index/fa/apCheckList.html",
  462. controller: 'PurchaseApCheckListCtrl'
  463. }).state('make', {
  464. url : "/make",
  465. views : {
  466. "left-view" : {
  467. templateUrl : "static/tpl/index/make/left.html"
  468. },
  469. "right-view" : {
  470. templateUrl : "static/tpl/index/make/right.html"
  471. }
  472. }
  473. }).state('make.index', {
  474. url : "",
  475. templateUrl : "static/tpl/index/make/index.html"
  476. }).state('make.home', {
  477. url : "/",
  478. templateUrl : "static/tpl/index/make/index.html"
  479. }).state('make.todo', {
  480. url : "/todo",
  481. templateUrl : "static/tpl/index/make/todo.html"
  482. }).state('make.todo.order', {
  483. url : "/order",
  484. templateUrl : "static/tpl/index/make/order.html",
  485. controller: 'MakeOrderCtrl'
  486. }).state('make.order', {
  487. url : "/order",
  488. templateUrl : "static/tpl/index/make/order.html",
  489. controller: 'MakeOrderCtrl'
  490. }).state('make.order_detail', {
  491. url : "/order/:id",
  492. templateUrl : "static/tpl/index/make/order_detail.html",
  493. controller: 'MakeOrderDetailCtrl'
  494. }).state('make.change', {
  495. url : "/change",
  496. templateUrl : "static/tpl/index/make/change.html",
  497. controller: 'MakeChangeCtrl'
  498. }).state('make.change_detail', {
  499. url : "/change/:id",
  500. templateUrl : "static/tpl/index/make/change_detail.html",
  501. controller: 'MakeChangeDetailCtrl'
  502. }).state('make.outorder', {
  503. url : "/outorder",
  504. templateUrl : "static/tpl/index/make/outorder.html",
  505. controller: 'MakeOutOrderCtrl'
  506. }).state('make.outorder_detail', {
  507. url : "/outorder/:id",
  508. templateUrl : "static/tpl/index/make/outorder_detail.html",
  509. controller: 'MakeOutOrderDetailCtrl'
  510. }).state('make.accept', {
  511. url : "/accept",
  512. templateUrl : "static/tpl/index/make/accept.html",
  513. controller: 'MakeAcceptCtrl'
  514. }).state('make.returns', {
  515. url : "/returns",
  516. templateUrl : "static/tpl/index/make/returns.html",
  517. controller: 'MakeReturnCtrl'
  518. }).state('cs', {// 客户服务
  519. url : "/cs",
  520. views : {
  521. "left-view" : {
  522. templateUrl : "static/tpl/index/cs/left.html"
  523. },
  524. "right-view" : {
  525. templateUrl : "static/tpl/index/cs/right.html"
  526. }
  527. }
  528. }).state('cs.index', {
  529. url : "",
  530. templateUrl : "static/tpl/index/cs/index.html"
  531. }).state('cs.home', {
  532. url : "/",
  533. templateUrl : "static/tpl/index/cs/index.html"
  534. }).state('search', { //顶部搜索
  535. url: "/search?keyword=",
  536. views : {
  537. "left-view" : {
  538. templateUrl : "static/tpl/index/search/left.html"
  539. },
  540. "right-view" : {
  541. templateUrl: "static/tpl/index/search/search_result.html",
  542. controller: 'TopSearchCtrl'
  543. }
  544. }
  545. }).state('approvalflow', { //审批流
  546. url: "/approvalFlow",
  547. views : {
  548. "left-view" : {
  549. templateUrl : "static/tpl/index/approvalFlow/left.html"
  550. },
  551. "right-view" : {
  552. templateUrl: "static/tpl/index/approvalFlow/home.html",
  553. controller: 'approvalFlowCtrl'
  554. }
  555. }
  556. });
  557. $urlRouterProvider.otherwise('/index');
  558. }]);
  559. /**
  560. * 表示符号
  561. */
  562. app.factory('Symbol', function(){
  563. return {
  564. currency: function(cur) {
  565. if(cur == 'RMB') return '¥';
  566. else if(cur == 'USD') return '$';
  567. else if(cur == 'EUR') return '€';
  568. else if(cur == null || cur == '') return '¥';
  569. else return cur;
  570. }
  571. };
  572. }).factory('Lodop',function(){
  573. return {
  574. getLodop:function(oOBJECT,oEMBED){
  575. var CreatedOKLodop7766=null;
  576. /**************************
  577. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  578. IE系列、IE内核系列的浏览器采用oOBJECT,
  579. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  580. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  581. 64位浏览器指向64位的安装程序install_lodop64.exe。
  582. **************************/
  583. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  584. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  585. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  586. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  587. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  588. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  589. var LODOP;
  590. try{
  591. //=====判断浏览器类型:===============
  592. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  593. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  594. //=====如果页面有Lodop就直接使用,没有则新建:==========
  595. if (oOBJECT!=undefined || oEMBED!=undefined) {
  596. if (isIE)
  597. LODOP=oOBJECT;
  598. else
  599. LODOP=oEMBED;
  600. } else {
  601. if (CreatedOKLodop7766==null){
  602. LODOP=document.createElement("object");
  603. LODOP.setAttribute("width",0);
  604. LODOP.setAttribute("height",0);
  605. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  606. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  607. else LODOP.setAttribute("type","application/x-print-lodop");
  608. document.documentElement.appendChild(LODOP);
  609. CreatedOKLodop7766=LODOP;
  610. } else
  611. LODOP=CreatedOKLodop7766;
  612. };
  613. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  614. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  615. if (navigator.userAgent.indexOf('Chrome')>=0)
  616. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  617. if (navigator.userAgent.indexOf('Firefox')>=0)
  618. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  619. if (is64IE) document.write(strHtm64_Install); else
  620. if (isIE) document.write(strHtmInstall); else
  621. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  622. return LODOP;
  623. } else
  624. if (LODOP.VERSION<"6.1.9.8") {
  625. if (is64IE) document.write(strHtm64_Update); else
  626. if (isIE) document.write(strHtmUpdate); else
  627. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  628. return LODOP;
  629. };
  630. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  631. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  632. //============================================================
  633. return LODOP;
  634. } catch(err) {
  635. if (is64IE)
  636. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  637. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  638. return LODOP;
  639. };
  640. }
  641. }
  642. });
  643. app.controller('MyCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  644. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  645. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  646. if (routeState.indexOf('/') > -1)
  647. routeState = routeState.substring(0, routeState.indexOf('/'));
  648. if (routeState.indexOf('.') > -1)
  649. routeState = routeState.substring(0, routeState.indexOf('.'));
  650. $scope.routeState = routeState || 'home';
  651. });
  652. $scope.search = function(keyword) {
  653. if(keyword != null ) {
  654. $rootScope.searchKeyword = keyword;
  655. window.location.hash = '#/search?keyword='+keyword;
  656. }
  657. };
  658. }]);
  659. // TODO
  660. app.controller('TopSearchCtrl', ['$scope', '$rootScope', 'getAccountUserSpace', 'ngTableParams', 'toaster', 'BaseService', 'AddPartner', '$filter', '$stateParams', 'SearchProd', '$sce', function($scope, $rootScope, getAccountUserSpace, ngTableParams, toaster, BaseService, AddPartner, $filter, $stateParams, SearchProd, $sce) {
  661. $scope.active = 'all';
  662. $scope.tip = $rootScope.searchKeyword;
  663. // 企业搜索
  664. var getService = function() {
  665. return getAccountUserSpace;
  666. };
  667. $scope.tableParams = new ngTableParams({
  668. page : 1,
  669. count : 5,
  670. sorting: {
  671. }
  672. }, {
  673. total : 0,
  674. counts: [5, 10, 25, 50],
  675. getData : function($defer, params) {
  676. $scope.loading = true;
  677. var pageParams = params.url();
  678. pageParams.keyword = $rootScope.searchKeyword;
  679. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  680. $scope.loading = false;
  681. if(page) {
  682. $scope.total = page.totalElement;
  683. params.total(page.totalElement);
  684. $defer.resolve(page.content);
  685. }
  686. }, function(response) {
  687. $scope.loading = false;
  688. toaster.pop('error', '数据加载失败', response.data);
  689. });
  690. }
  691. });
  692. // 添加合作关系
  693. $scope.addPartner = function(name, businessCode) {
  694. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  695. if(data.success) {
  696. toaster.pop("success", '添加成功', data.success);
  697. }
  698. if(data.error) {
  699. toaster.pop("error", '添加失败', data.error);
  700. }
  701. }, function(response) {
  702. toaster.pop('error','失败',response.data);
  703. });
  704. }
  705. // 物料搜索
  706. var getProdService = function() {
  707. return SearchProd;
  708. };
  709. $scope.prodTableParams = new ngTableParams({
  710. page : 1,
  711. count : 5,
  712. sorting: {
  713. }
  714. }, {
  715. total : 0,
  716. counts: [5, 10, 25, 50],
  717. getData : function($defer, params) {
  718. $scope.loading = true;
  719. var pageParams = params.url();
  720. pageParams.keyword = $rootScope.searchKeyword;
  721. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  722. $scope.loading = false;
  723. if(page) {
  724. $scope.prodtotal = page.totalElement;
  725. params.total(page.totalElement);
  726. $defer.resolve(page.content);
  727. }
  728. }, function(response) {
  729. $scope.loading = false;
  730. toaster.pop('error', '数据加载失败', response.data);
  731. });
  732. }
  733. });
  734. /**
  735. * 向企业购买
  736. */
  737. $scope.PurcByEn = function(businessCode) {
  738. $rootScope.businessCode = businessCode;
  739. window.location.hash = "#/purc/addOrder";
  740. }
  741. /**
  742. * 选中单个物料购买
  743. * @param businessCode
  744. * @param id
  745. */
  746. $scope.PurcByEnAndProd = function(businessCode, id) {
  747. $rootScope.businessCode = businessCode;
  748. $rootScope.prodId = id;
  749. window.location.hash = "#/purc/addOrder";
  750. }
  751. }]);
  752. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  753. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  754. //手机号码格式验证
  755. // var checkTel = function(data){
  756. // var userTel = data.userTel;
  757. // $scope.checkResult = false;
  758. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  759. // if(!(telephone).test(userTel)){
  760. // var modalInstance = $modal.open({
  761. // animation: true,
  762. // templateUrl: 'static/tpl/index/account/checkTel.html',
  763. // controller: 'CheckTelCtrl',
  764. // backdrop: 'static',
  765. // keyboard: false,
  766. // resolve: {
  767. // user: function(){
  768. // return data;
  769. // },
  770. // }
  771. // });
  772. // modalInstance.result.then(function(){
  773. // }, function(){
  774. //
  775. // });
  776. // } else {
  777. // $scope.checkResult = true;
  778. // }
  779. // };
  780. AuthenticationService.getAuthentication().success(function(data) {
  781. if(data.enterprises) {
  782. data.enterprise = data.enterprises[data.enterprises.length - 1];
  783. if(data.enterprises.length > 1) {
  784. var enSelect = [];
  785. angular.forEach(data.enterprises, function(e){
  786. if(e.current)
  787. data.enterprise = e;
  788. else
  789. enSelect.push(e);
  790. });
  791. data.enSelect = enSelect;
  792. }
  793. }
  794. $scope.userInfo = data;
  795. if (data == null || !data.userUU) {
  796. $scope.isAuthed = false;
  797. AuthenticationService.redirectSignin();
  798. } else {
  799. //跳转到手机号码验证
  800. // checkTel($scope.userInfo);
  801. }
  802. });
  803. $scope.showImageDialog = function(modal) {
  804. require([ 'jquery-uploadify' ], function() {
  805. $modal.open({
  806. templateUrl : 'static/tpl/index/home/insert.html',
  807. controller : 'ImageInsertCtrl',
  808. backdrop : 'static'
  809. }).result.then(function(image){
  810. $scope.imageUrl = image.thumb;
  811. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  812. $scope.user = data;
  813. }, function(response) {
  814. toaster.pop('error', '设置图像失败,' + response.data);
  815. });
  816. });
  817. });
  818. }
  819. $scope.logout = function() {
  820. AuthenticationService.logout();
  821. };
  822. $scope.switchto = function(enUU) {// 切换企业
  823. AuthenticationService.reSignin(enUU).success(function(){
  824. $window.location.reload();
  825. });
  826. };
  827. $scope.addFavorite = function(){
  828. var url = encodeURI(window.location.href);
  829. try{
  830. //ie浏览器收藏方式
  831. window.external.addFavorite(url, "优软商务平台");
  832. }catch(e) {
  833. try{
  834. //火狐浏览器收藏方式
  835. window.sidebar.addPanel("优软商务平台", url);
  836. }catch (e) {
  837. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  838. "或手动在浏览器里进行设置。");
  839. }
  840. }
  841. };
  842. }]);
  843. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  844. $scope.image = {src: null};
  845. // 图片上传成功之后
  846. $scope.onUploadSuccess = function(data){
  847. var path = data.path;
  848. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  849. $scope.$apply(function(){
  850. $scope.image.src = data.path;
  851. $scope.image.thumb = path;
  852. });
  853. };
  854. $scope.close = function() {
  855. $modalInstance.dismiss();
  856. };
  857. $scope.confirm = function() {
  858. $modalInstance.close($scope.image);
  859. $scope.imageUrl = null;
  860. };
  861. }]);
  862. app.controller('TodoCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  863. SnapshotService.getTodo(function(data){
  864. $scope.todo = data;
  865. });
  866. }]);
  867. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  868. SaleTruck.query({}, function(data){
  869. $rootScope.truck = data;
  870. $scope.truckCount = data ? data.length : 0;
  871. });
  872. $scope.$watch(function(){
  873. return $rootScope.truck;
  874. }, function(data) {
  875. $scope.truckCount = data ? data.length : 0;
  876. }, true);
  877. $scope.clearAll = function() {
  878. SaleTruck.remove({}, function(){
  879. $rootScope.truck = [];
  880. });
  881. };
  882. $scope.openTrack = function() {
  883. $modal.open({
  884. templateUrl: 'static/tpl/index/sale/track.html',
  885. controller: 'TruckModalCtrl',
  886. size: 'lg'
  887. }).result.then(function(s){
  888. if(s) {
  889. $scope.clearAll();
  890. $rootScope.dataChanged = true;
  891. }
  892. });
  893. };
  894. }]);
  895. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  896. $scope.saleSend = {sendItems: []};
  897. SaleTruck.detail({}, function(data){
  898. // 按物料编号排序
  899. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  900. });
  901. $scope.remove = function(index, notice) {
  902. SaleTruck.remove({noticeId: notice.id}, function(data){
  903. $rootScope.truck = data;
  904. $scope.notices.splice(index, 1);
  905. });
  906. };
  907. $scope.$watch(function(){
  908. return $scope.notices;
  909. }, function(data) {
  910. var q = 0, t = 0;
  911. if(data) {
  912. angular.forEach(data,function(d){
  913. q += d.thisSendQty;
  914. t += d.thisSendQty * d.orderItem.price;
  915. });
  916. }
  917. $scope.totalQty = q;
  918. $scope.total = t;
  919. }, true);
  920. $scope.cancel = function() {
  921. $modalInstance.close();
  922. };
  923. $scope.send = function() {// 发货
  924. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  925. toaster.pop('error', '错误', '请输入送货单号');
  926. return;
  927. }
  928. var currency = $scope.notices[0].orderItem.order.currency,
  929. custUU = $scope.notices[0].enUU,
  930. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  931. var num = 1;
  932. for(var i in $scope.notices) {
  933. var item = $scope.notices[i];
  934. if(item.id) {
  935. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  936. valid = false;
  937. break;
  938. }
  939. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  940. }
  941. }
  942. if(!valid) {
  943. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  944. } else {
  945. var send = angular.extend(angular.copy($scope.saleSend), {
  946. currency: currency,
  947. custUU: custUU,
  948. payments: payments,
  949. sendItems: items
  950. });
  951. PurcNotice.sendByBatch({}, send, function(data){
  952. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  953. $modalInstance.close(true);
  954. $state.go('sale.send_detail', {id: data.id});
  955. }, function(response){
  956. toaster.pop('error', '错误', response.data);
  957. });
  958. }
  959. };
  960. }]);
  961. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  962. SaleStat.cust({}, function(data){
  963. var p = [], q = [];
  964. angular.forEach(data.month, function(d){
  965. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  966. });
  967. angular.forEach(data.year, function(d){
  968. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  969. });
  970. $scope.custCharts = {
  971. month : {
  972. chartType : 'pie',
  973. datas : {
  974. data : p
  975. },
  976. config : {
  977. labels : false,
  978. title : "客户月采购量排行榜",
  979. legend : {
  980. display : true,
  981. position : 'right'
  982. },
  983. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  984. click : function(d) {
  985. },
  986. mouseover : function(d) {
  987. },
  988. mouseout : function(d) {
  989. },
  990. innerRadius : 0,
  991. lineLegend : 'lineEnd'
  992. }
  993. },
  994. year : {
  995. chartType : 'pie',
  996. datas : {
  997. data : q
  998. },
  999. config : {
  1000. labels : false,
  1001. title : "客户年采购量排行榜",
  1002. legend : {
  1003. display : true,
  1004. position : 'right'
  1005. },
  1006. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1007. click : function(d) {
  1008. },
  1009. mouseover : function(d) {
  1010. },
  1011. mouseout : function(d) {
  1012. },
  1013. innerRadius : 0,
  1014. lineLegend : 'lineEnd'
  1015. }
  1016. }
  1017. };
  1018. });
  1019. SaleStat.seller({}, function(data){
  1020. var p = [], q = [];
  1021. angular.forEach(data.month, function(d){
  1022. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1023. });
  1024. angular.forEach(data.year, function(d){
  1025. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1026. });
  1027. $scope.sellerCharts = {
  1028. month : {
  1029. chartType : 'pie',
  1030. datas : {
  1031. data : p
  1032. },
  1033. config : {
  1034. labels : false,
  1035. title : "业务员月销量排行榜",
  1036. legend : {
  1037. display : true,
  1038. position : 'right'
  1039. },
  1040. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1041. click : function(d) {
  1042. },
  1043. mouseover : function(d) {
  1044. },
  1045. mouseout : function(d) {
  1046. },
  1047. innerRadius : 0,
  1048. lineLegend : 'lineEnd'
  1049. }
  1050. },
  1051. year : {
  1052. chartType : 'pie',
  1053. datas : {
  1054. data : q
  1055. },
  1056. config : {
  1057. labels : false,
  1058. title : "业务员年销量排行榜",
  1059. legend : {
  1060. display : true,
  1061. position : 'right'
  1062. },
  1063. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1064. click : function(d) {
  1065. },
  1066. mouseover : function(d) {
  1067. },
  1068. mouseout : function(d) {
  1069. },
  1070. innerRadius : 0,
  1071. lineLegend : 'lineEnd'
  1072. }
  1073. }
  1074. };
  1075. });
  1076. }]);
  1077. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1078. SaleStat.get({}, function(data){
  1079. var p = [], q = [], r = [];
  1080. angular.forEach(data.day, function(d){
  1081. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1082. });
  1083. angular.forEach(data.month, function(d){
  1084. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1085. });
  1086. angular.forEach(data.year, function(d){
  1087. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1088. });
  1089. $scope.charts = {
  1090. day : {
  1091. chartType : "line",
  1092. datas: {
  1093. series: ['销售额'],
  1094. data: p
  1095. },
  1096. config : {
  1097. "labels": false,
  1098. "title": "销售额统计(近15日线)",
  1099. "legend": {
  1100. "display": true,
  1101. "position": "right"
  1102. },
  1103. colors : [ '#4D9934'],
  1104. "innerRadius": 0,
  1105. "lineLegend": "lineEnd"
  1106. }
  1107. },
  1108. month: {
  1109. chartType : "line",
  1110. datas: {
  1111. series: ['销售额'],
  1112. data: q
  1113. },
  1114. config : {
  1115. "labels": false,
  1116. "title": "销售额统计(近12月线)",
  1117. "legend": {
  1118. "display": true,
  1119. "position": "right"
  1120. },
  1121. colors : [ '#4D9934'],
  1122. "innerRadius": 0,
  1123. "lineLegend": "lineEnd"
  1124. }
  1125. },
  1126. year: {
  1127. chartType : "line",
  1128. datas: {
  1129. series: ['销售额'],
  1130. data: r
  1131. },
  1132. config : {
  1133. "labels": false,
  1134. "title": "销售额统计(近10年线)",
  1135. "legend": {
  1136. "display": true,
  1137. "position": "right"
  1138. },
  1139. colors : [ '#4D9934'],
  1140. "innerRadius": 0,
  1141. "lineLegend": "lineEnd"
  1142. }
  1143. }
  1144. };
  1145. });
  1146. }]);
  1147. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1148. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1149. $scope.notices = data;
  1150. });
  1151. $scope.dateTime = new Date();
  1152. }]);
  1153. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1154. SnapshotService.getTender(5, function(data){ //5表示首页显示的招标单条数
  1155. $scope.tenders = data;
  1156. });
  1157. SnapshotService.getOpenTender(5, function(data){ //5表示首页显示的招标单条数
  1158. $scope.openTenders = data;
  1159. });
  1160. $scope.dateTime = new Date();
  1161. }]);
  1162. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1163. VendorService.getCount(function(date){
  1164. $scope.count = date;
  1165. });
  1166. }]);
  1167. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1168. $scope.userInfoResult = true;
  1169. AuthenticationService.getAuthentication().success(function(data) {
  1170. $scope.loading = false;
  1171. $scope.thisUser = data;
  1172. });
  1173. var getCustInfos = function(custuu) {
  1174. if(custuu) {
  1175. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1176. $scope.custInfos = data;
  1177. var getPage = function(page, size){
  1178. if($scope.custInfos) {
  1179. var result = {};
  1180. result.totalCount = $scope.custInfos.length;
  1181. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1182. if($scope.custInfos.length % size == 0) {
  1183. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1184. }else {
  1185. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1186. }
  1187. result.first = page == 1;
  1188. result.last = page == result.totalPage;
  1189. result.page = page;
  1190. result.next = page - 0 + 1;
  1191. result.pre = page - 1;
  1192. return result;
  1193. }
  1194. }
  1195. $scope.userdata = getPage(1,4);
  1196. $scope.first = function (){
  1197. $scope.userdata = getPage($scope.userdata.pre,4);
  1198. }
  1199. $scope.last = function (){
  1200. $scope.userdata = getPage($scope.userdata.next,4);
  1201. }
  1202. }, function(response){
  1203. $scope.loading = false;
  1204. toaster.pop('error', '数据加载失败', response.data);
  1205. });
  1206. }
  1207. }
  1208. $scope.addUserInfo = function(customer) {
  1209. //TODO
  1210. if ($scope.thisUser.sys) {
  1211. var modalInstance = $modal.open({
  1212. animation: true,
  1213. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1214. controller: 'AddUserInfoCtrl',
  1215. resolve: {
  1216. customer: function() {
  1217. return customer;
  1218. }
  1219. }
  1220. });
  1221. modalInstance.result.then(function(changed, checked){
  1222. if(changed) {
  1223. if(checked)
  1224. $scope.newUser.roles = checked;
  1225. else
  1226. loadUsers();
  1227. }
  1228. });
  1229. } else {
  1230. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1231. }
  1232. }
  1233. $scope.showUserInfo = function(customer,boo) {
  1234. $scope.custInfo = customer;
  1235. if(boo) {
  1236. getCustInfos(customer.myEnterprise.uu);
  1237. $scope.userInfoResult = true;
  1238. }
  1239. }
  1240. $scope.customerParams = new ngTableParams({
  1241. page : 1,
  1242. count : 10
  1243. }, {
  1244. total : 0,
  1245. counts: [5, 10, 25, 50],
  1246. getData : function($defer, params) {
  1247. $scope.loading = true;
  1248. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  1249. $scope.loading = false;
  1250. if(page) {
  1251. params.total(page.totalElements);
  1252. $defer.resolve(page.content);
  1253. }
  1254. $scope.totalCount = page.totalElements;
  1255. }, function(response){
  1256. $scope.loading = false;
  1257. toaster.pop('error', '数据加载失败', response.data);
  1258. });
  1259. }
  1260. });
  1261. }]);
  1262. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1263. $scope.checkboxes = {
  1264. checked : false
  1265. };
  1266. $scope.loading = true;
  1267. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1268. $scope.userinfos = data;
  1269. $scope.loading = false;
  1270. })
  1271. // 点击勾选全部的复选框
  1272. $scope.checkAll = function() {
  1273. angular.forEach($scope.userinfos, function(item) {
  1274. item.distribute = $scope.checkboxes.checked;
  1275. });
  1276. };
  1277. // 点击其中一个明细的复选框
  1278. $scope.checkOne = function(vendor){
  1279. var result = true;
  1280. angular.forEach($scope.userinfos, function(item) {
  1281. if(item.distribute != true){
  1282. result = false;
  1283. return;
  1284. }
  1285. });
  1286. $scope.checkboxes.checked = result;
  1287. };
  1288. $scope.close = function(save) {
  1289. var chooseResult = [];
  1290. if(save) {
  1291. if(customer.myEnterprise.uu) {
  1292. angular.forEach($scope.userinfos, function(item, i) {
  1293. chooseResult.push(item);
  1294. });
  1295. if(chooseResult.length > 0) {
  1296. $scope.loading = true;
  1297. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1298. $scope.loading = false;
  1299. toaster.pop('success', '提示', '保存成功');
  1300. $modalInstance.close(false);
  1301. }, function(response){
  1302. $scope.loading = false;
  1303. toaster.pop('error', '保存失败', response.data);
  1304. $modalInstance.close(false);
  1305. })
  1306. } else {
  1307. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1308. }
  1309. } else {
  1310. $modalInstance.close(true, $scope.checkboxes.checked);
  1311. }
  1312. } else {
  1313. $modalInstance.close(false);
  1314. }
  1315. };
  1316. }]);
  1317. /**
  1318. * 页面状态按钮过滤
  1319. */
  1320. var getState = function(active) {
  1321. var fn = 'get';
  1322. switch(active) {
  1323. case 'done':
  1324. fn = 'getDone';break;
  1325. case 'todo':
  1326. fn = 'getTodo';break;
  1327. case 'end':
  1328. fn = 'getEnd';break;
  1329. case 'waiting':
  1330. fn = 'getWaiting';break;
  1331. case 'invalid':
  1332. fn = 'getInvalid';break;
  1333. }
  1334. return fn;
  1335. };
  1336. /**
  1337. * 改变单据日期范围
  1338. */
  1339. var getDateCondition = function(zone, condition) {
  1340. var date = new Date();
  1341. if(zone == -1) {
  1342. condition.dateFrom = null;
  1343. condition.dateTo = null;
  1344. } else if(zone == 1) {
  1345. date.setMonth(date.getMonth() - 1);
  1346. condition.dateFrom = date;
  1347. condition.dateTo = new Date();
  1348. } else if (zone == 6) {
  1349. date.setMonth(date.getMonth() - 6);
  1350. condition.dateFrom = date;
  1351. condition.dateTo = new Date();
  1352. } else {
  1353. date.setMonth(date.getMonth() - 6);
  1354. condition.dateFrom = null;
  1355. condition.dateTo = date;
  1356. }
  1357. };
  1358. /**
  1359. * 改变单据交货日期范围
  1360. */
  1361. var getDelveryCondition = function(zone, condition) {
  1362. var date = new Date();
  1363. if(zone == -1) {
  1364. condition.deliveryFrom = null;
  1365. condition.deliveryTo = null;
  1366. } else if(zone == 1) {
  1367. date.setMonth(date.getMonth() + 1);
  1368. condition.deliveryTo = date;
  1369. condition.deliveryFrom = new Date();
  1370. } else if (zone == 2) {
  1371. date.setMonth(date.getMonth() + 2);
  1372. condition.deliveryTo = date;
  1373. condition.deliveryFrom = new Date();
  1374. }
  1375. };
  1376. /**
  1377. * 将日期转化为整数日期
  1378. */
  1379. var getDateTime = function(date) {
  1380. if(angular.isDate(date)) {
  1381. return date.getTime();
  1382. } else {
  1383. return null;
  1384. }
  1385. };
  1386. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1387. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1388. $scope.active = 'todo';
  1389. $scope.dateZoneText = '不限';
  1390. $scope.deliveryZoneText = '不限';
  1391. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1392. $scope.changeDateZone = function(zone) {
  1393. $scope.condition.dateZone = zone;
  1394. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1395. $scope.condition.$dateZoneOpen = false;
  1396. getDateCondition(zone, $scope.condition);
  1397. $scope.tableParams.reload();
  1398. };
  1399. $scope.changeDeliveryZone = function(zone) {
  1400. $scope.condition.deliveryZoneText = zone;
  1401. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1402. $scope.condition.$delievryZoneOpen = false;
  1403. getDelveryCondition(zone, $scope.condition);
  1404. $scope.tableParams.reload();
  1405. };
  1406. // 切换单据类型
  1407. $scope.setActive = function(state) {
  1408. if($scope.active != state) {
  1409. $scope.active = state;
  1410. if($scope.tableParams.page() == 1)
  1411. $scope.tableParams.reload();
  1412. else
  1413. $scope.tableParams.page(1);
  1414. }
  1415. };
  1416. var getPurcStatus = function(active) {
  1417. var fn = 'getPurcAll';
  1418. switch(active) {
  1419. case 'done':
  1420. fn = 'getPurcDone';break;
  1421. case 'todo':
  1422. fn = 'getPurcTodo';break;
  1423. case 'end':
  1424. fn = 'getPurcEnd';break;
  1425. case 'waiting':
  1426. fn = 'getPurcWaiting';break;
  1427. }
  1428. return fn;
  1429. }
  1430. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1431. page : 1,
  1432. count : 5,
  1433. sorting: {
  1434. display: 'desc',
  1435. date: 'desc'
  1436. }
  1437. }, {
  1438. total : 0,
  1439. counts: [5, 10, 15, 25, 50],
  1440. getData : function($defer, params) {// 获取数据的方法
  1441. $scope.loading = true;
  1442. var pageParams = params.url();
  1443. pageParams.searchFilter = { // 筛选条件
  1444. keyword: $scope.keyword,
  1445. fromDate: getDateTime($scope.condition.dateFrom),
  1446. endDate: getDateTime($scope.condition.dateTo)
  1447. };
  1448. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1449. $scope.loading = false;
  1450. if(page) {
  1451. $defer.resolve(page.content);
  1452. params.total(page.totalElement);
  1453. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1454. }
  1455. }, function(response){
  1456. $scope.loading = false;
  1457. toaster.pop('error', '数据加载失败', response.data);
  1458. });
  1459. }
  1460. });
  1461. $scope.getReply = function(item) {
  1462. if(!item.replies) {
  1463. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1464. item.replies = replies;
  1465. });
  1466. }
  1467. };
  1468. $scope.getOrderTotal = function(items) {
  1469. var sum = 0;
  1470. angular.forEach(items, function(item){
  1471. sum += item.qty * item.price;
  1472. });
  1473. return sum;
  1474. };
  1475. $scope.openDatePicker = function($event, item, openParam) {
  1476. $event.preventDefault();
  1477. $event.stopPropagation();
  1478. item[openParam] = !item[openParam];
  1479. };
  1480. $scope.parseDate = function(dateStr) {
  1481. if(dateStr)
  1482. return Date.parse(dateStr, 'yyyy-MM-dd');
  1483. return new Date();
  1484. };
  1485. $scope.checkboxes = {
  1486. checked : false
  1487. };
  1488. // 点击勾选全部的复选框
  1489. $scope.checkAll = function(){
  1490. angular.forEach($scope.tableParams.data, function(item) {
  1491. item.$selected = $scope.checkboxes.checked;
  1492. });
  1493. };
  1494. // 点击其中一个明细的复选框
  1495. $scope.checkOne = function(order){
  1496. var result = true;
  1497. angular.forEach($scope.tableParams.data, function(item) {
  1498. if(item.$selected != true){
  1499. result = false;
  1500. return;
  1501. }
  1502. });
  1503. $scope.checkboxes.checked = result;
  1504. };
  1505. // 搜索框回车
  1506. $scope.onSearch = function() {
  1507. $scope.tableParams.page(1);
  1508. $scope.tableParams.reload();
  1509. };
  1510. // 选择查找日期
  1511. $scope.onDateCondition = function(){
  1512. $scope.tableParams.page(1);
  1513. $scope.tableParams.reload();
  1514. };
  1515. }]);
  1516. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1517. var loadData = function() {
  1518. PurcOrder.get({id: $stateParams.id}, function(data){
  1519. $scope.order = data;
  1520. var sum = 0;
  1521. angular.forEach($scope.order.orderItems, function(item){
  1522. sum += item.qty * item.price;
  1523. });
  1524. $scope.order.total = sum;
  1525. if($scope.order.display == 1) {//未查看的设为已查看
  1526. $scope.setDisplay('setRead', $scope.order.id);
  1527. }
  1528. $scope.loading = false;
  1529. });
  1530. };
  1531. loadData();
  1532. $scope.getReply = function(item) {
  1533. if(!item.replies) {
  1534. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1535. item.replies = replies;
  1536. });
  1537. }
  1538. };
  1539. $scope.openDatePicker = function($event, item, openParam) {
  1540. $event.preventDefault();
  1541. $event.stopPropagation();
  1542. item[openParam] = !item[openParam];
  1543. };
  1544. $scope.onReplyClick = function(item, inverse) {
  1545. if(item.reply) {
  1546. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1547. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1548. return;
  1549. }
  1550. var reply = angular.copy(item.reply);
  1551. if(reply.delivery) {
  1552. if(typeof reply.delivery == 'object')
  1553. reply.delivery = reply.delivery.getTime();
  1554. } else {
  1555. reply.delivery = item.delivery;
  1556. }
  1557. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1558. $scope.loading = true;
  1559. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1560. $scope.loading = false;
  1561. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1562. loadData();
  1563. }, function(response){
  1564. $scope.loading = false;
  1565. toaster.pop('error', '回复失败', response.data);
  1566. });
  1567. }
  1568. };
  1569. // // 采购单
  1570. // $scope.print = function(order) {
  1571. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  1572. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1573. // };
  1574. //设置为已查看
  1575. $scope.setDisplay = function(state, orderId) {
  1576. if(orderId) {//设置单个
  1577. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1578. // $scope.tableParams.reload();
  1579. }, function() {
  1580. toaster.pop('error', '错误', "设置失败");
  1581. });
  1582. } else {//设置已勾选的
  1583. var str = null;
  1584. angular.forEach($scope.tableParams.data, function(order) {
  1585. if(order.$selected == true) {
  1586. if(str != null && str != '') str += ',';
  1587. str += order.id;
  1588. }
  1589. });
  1590. if(str != null && str != '') {
  1591. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1592. $scope.tableParams.reload();
  1593. }, function() {
  1594. toaster.pop('error', '错误', "设置失败");
  1595. });
  1596. }
  1597. }
  1598. };
  1599. }]);
  1600. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  1601. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  1602. $scope.active = 'todo';
  1603. $scope.dateZoneText = '不限';
  1604. $scope.deliveryZoneText = '不限';
  1605. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1606. $scope.changeDateZone = function(zone) {
  1607. $scope.condition.dateZone = zone;
  1608. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1609. $scope.condition.$dateZoneOpen = false;
  1610. getDateCondition(zone, $scope.condition);
  1611. $scope.tableParams.reload();
  1612. };
  1613. $scope.changeDeliveryZone = function(zone) {
  1614. $scope.condition.deliveryZoneText = zone;
  1615. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1616. $scope.condition.$delievryZoneOpen = false;
  1617. getDelveryCondition(zone, $scope.condition);
  1618. $scope.tableParams.reload();
  1619. };
  1620. // 切换单据类型
  1621. $scope.setActive = function(state) {
  1622. if($scope.active != state) {
  1623. $scope.active = state;
  1624. if($scope.tableParams.page() == 1)
  1625. $scope.tableParams.reload();
  1626. else
  1627. $scope.tableParams.page(1);
  1628. }
  1629. };
  1630. // 切换数据来源(正常数据 or 历史数据)
  1631. var getService = function() {
  1632. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  1633. };
  1634. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1635. page : 1,
  1636. count : 5,
  1637. sorting: {
  1638. display: 'desc',
  1639. date: 'desc',
  1640. id: 'desc'
  1641. }
  1642. }, {
  1643. total : 0,
  1644. counts: [5, 10, 15, 25, 50],
  1645. getData : function($defer, params) { // 获取数据的方法
  1646. $scope.loading = true;
  1647. var pageParams = params.url();
  1648. pageParams.searchFilter = { // 筛选条件
  1649. keyword: $scope.keyword,
  1650. fromDate: getDateTime($scope.condition.dateFrom),
  1651. endDate: getDateTime($scope.condition.dateTo)
  1652. };
  1653. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1654. $scope.loading = false;
  1655. if(page) {
  1656. $defer.resolve(page.content);
  1657. params.total(page.totalElement);
  1658. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1659. }
  1660. }, function(response){
  1661. $scope.loading = false;
  1662. toaster.pop('error', '数据加载失败', response.data);
  1663. });
  1664. }
  1665. });
  1666. $scope.getOrderTotal = function(items) {
  1667. var sum = 0;
  1668. angular.forEach(items, function(item){
  1669. sum += item.qty * item.price;
  1670. });
  1671. return sum;
  1672. };
  1673. $scope.openDatePicker = function($event, item, openParam) {
  1674. $event.preventDefault();
  1675. $event.stopPropagation();
  1676. item[openParam] = !item[openParam];
  1677. };
  1678. $scope.parseDate = function(dateStr) {
  1679. if(dateStr)
  1680. return Date.parse(dateStr, 'yyyy-MM-dd');
  1681. return new Date();
  1682. };
  1683. $scope.onReplyClick = function(item, inverse) {
  1684. if(item.reply) {
  1685. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1686. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1687. return;
  1688. }
  1689. var reply = angular.copy(item.reply);
  1690. if(reply.delivery) {
  1691. if(typeof reply.delivery == 'object')
  1692. reply.delivery = reply.delivery.getTime();
  1693. } else {
  1694. reply.delivery = item.delivery;
  1695. }
  1696. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1697. $scope.loading = true;
  1698. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1699. $scope.loading = false;
  1700. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1701. $scope.tableParams.reload();
  1702. }, function(response){
  1703. $scope.loading = false;
  1704. toaster.pop('error', '回复失败', response.data);
  1705. });
  1706. }
  1707. };
  1708. //打印 采购单
  1709. $scope.print = function(order) {
  1710. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  1711. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  1712. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1713. };
  1714. $scope.getReply = function(item) {
  1715. if(!item.replies) {
  1716. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1717. item.replies = replies;
  1718. });
  1719. }
  1720. };
  1721. $scope.checkboxes = {
  1722. checked : false
  1723. };
  1724. // 点击勾选全部的复选框
  1725. $scope.checkAll = function(){
  1726. angular.forEach($scope.tableParams.data, function(item) {
  1727. item.$selected = $scope.checkboxes.checked;
  1728. });
  1729. };
  1730. // 点击其中一个明细的复选框
  1731. $scope.checkOne = function(order){
  1732. var result = true;
  1733. angular.forEach($scope.tableParams.data, function(item) {
  1734. if(item.$selected != true){
  1735. result = false;
  1736. return;
  1737. }
  1738. });
  1739. $scope.checkboxes.checked = result;
  1740. };
  1741. //批量回复采购订单
  1742. $scope.replyByBatch = function() {
  1743. $scope.loading = true;
  1744. var str = '';
  1745. angular.forEach($scope.tableParams.data, function(order) {
  1746. if(order.$selected == true) {
  1747. angular.forEach(order.orderItems, function(item){
  1748. str += item.id;
  1749. str += ',';
  1750. });
  1751. }
  1752. });
  1753. if(!(str == '')) {
  1754. str = str.substr(0, str.length-1);
  1755. PurcOrderItem.replyByBatch(str, function(){
  1756. $scope.loading = false;
  1757. $scope.tableParams.reload();
  1758. toaster.pop('success', '提示', '批量回复成功');
  1759. }, function(data){
  1760. $scope.loading = false;
  1761. toaster.pop('error', '批量回复失败', data);
  1762. });
  1763. } else {//没有勾选其中的明细
  1764. $scope.loading = false;
  1765. }
  1766. };
  1767. // 搜索框回车
  1768. $scope.onSearch = function() {
  1769. $scope.tableParams.page(1);
  1770. $scope.tableParams.reload();
  1771. };
  1772. // 选择查找日期
  1773. $scope.onDateCondition = function(){
  1774. $scope.tableParams.page(1);
  1775. $scope.tableParams.reload();
  1776. };
  1777. //设置为已查看
  1778. $scope.setDisplay = function(state, orderId) {
  1779. if(orderId) {//设置单个
  1780. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1781. $scope.tableParams.reload();
  1782. }, function() {
  1783. toaster.pop('error', '错误', "设置失败");
  1784. });
  1785. } else {//设置已勾选的
  1786. var str = null;
  1787. angular.forEach($scope.tableParams.data, function(order) {
  1788. if(order.$selected == true) {
  1789. if(str != null && str != '') str += ',';
  1790. str += order.id;
  1791. }
  1792. });
  1793. if(str != null && str != '') {
  1794. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1795. $scope.tableParams.reload();
  1796. }, function() {
  1797. toaster.pop('error', '错误', "设置失败");
  1798. });
  1799. }
  1800. }
  1801. };
  1802. }]);
  1803. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1804. var loadData = function() {
  1805. PurcOrder.get({id: $stateParams.id}, function(data){
  1806. $scope.order = data;
  1807. var sum = 0;
  1808. angular.forEach($scope.order.orderItems, function(item){
  1809. sum += item.qty * item.price;
  1810. });
  1811. $scope.order.total = sum;
  1812. if($scope.order.display == 1) {//未查看的设为已查看
  1813. $scope.setDisplay('setRead', $scope.order.id);
  1814. }
  1815. $scope.loading = false;
  1816. });
  1817. };
  1818. loadData();
  1819. $scope.getReply = function(item) {
  1820. if(!item.replies) {
  1821. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1822. item.replies = replies;
  1823. });
  1824. }
  1825. };
  1826. $scope.openDatePicker = function($event, item, openParam) {
  1827. $event.preventDefault();
  1828. $event.stopPropagation();
  1829. item[openParam] = !item[openParam];
  1830. };
  1831. $scope.onReplyClick = function(item, inverse) {
  1832. if(item.reply) {
  1833. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1834. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1835. return;
  1836. }
  1837. var reply = angular.copy(item.reply);
  1838. if(reply.delivery) {
  1839. if(typeof reply.delivery == 'object')
  1840. reply.delivery = reply.delivery.getTime();
  1841. } else {
  1842. reply.delivery = item.delivery;
  1843. }
  1844. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1845. $scope.loading = true;
  1846. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1847. $scope.loading = false;
  1848. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1849. loadData();
  1850. }, function(response){
  1851. $scope.loading = false;
  1852. toaster.pop('error', '回复失败', response.data);
  1853. });
  1854. }
  1855. };
  1856. // 采购单
  1857. $scope.print = function(order) {
  1858. PurcOrder.printCount({id: order.id},{});//增加打印此次
  1859. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1860. };
  1861. //设置为已查看
  1862. $scope.setDisplay = function(state, orderId) {
  1863. if(orderId) {//设置单个
  1864. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1865. $scope.tableParams.reload();
  1866. }, function() {
  1867. toaster.pop('error', '错误', "设置失败");
  1868. });
  1869. } else {//设置已勾选的
  1870. var str = null;
  1871. angular.forEach($scope.tableParams.data, function(order) {
  1872. if(order.$selected == true) {
  1873. if(str != null && str != '') str += ',';
  1874. str += order.id;
  1875. }
  1876. });
  1877. if(str != null && str != '') {
  1878. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1879. $scope.tableParams.reload();
  1880. }, function() {
  1881. toaster.pop('error', '错误', "设置失败");
  1882. });
  1883. }
  1884. }
  1885. };
  1886. }]);
  1887. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  1888. $scope.active = 'todo';
  1889. $scope.agreedText = '全部';
  1890. $scope.dateZoneText = '一个月内';
  1891. $scope.condition = {dateZone: 1};
  1892. $scope.changeAgreed = function(agreed) {
  1893. $scope.condition.agreed = agreed;
  1894. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  1895. $scope.condition.$agreedOpen = false;
  1896. };
  1897. $scope.changeDateZone = function(zone) {
  1898. $scope.condition.dateZone = zone;
  1899. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1900. $scope.condition.$dateZoneOpen = false;
  1901. };
  1902. $scope.setActive = function(state) {
  1903. if($scope.active != state) {
  1904. $scope.active = state;
  1905. if($scope.tableParams.page() == 1)
  1906. $scope.tableParams.reload();
  1907. else
  1908. $scope.tableParams.page(1);
  1909. }
  1910. };
  1911. var getService = function() {
  1912. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  1913. };
  1914. $scope.tableParams = new ngTableParams({
  1915. page : 1,
  1916. count : 5,
  1917. sorting: {
  1918. date: 'desc'
  1919. }
  1920. }, {
  1921. total : 0,
  1922. counts: [5, 10, 25, 50],
  1923. getData : function($defer, params) {
  1924. $scope.loading = true;
  1925. var pageParams = params.url();
  1926. pageParams.keyword = $scope.keyword;
  1927. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1928. $scope.loading = false;
  1929. if(page) {
  1930. params.total(page.totalElement);
  1931. $defer.resolve(page.content);
  1932. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1933. }
  1934. }, function(response){
  1935. $scope.loading = false;
  1936. toaster.pop('error', '数据加载失败', response.data);
  1937. });
  1938. }
  1939. });
  1940. $scope.openDatePicker = function($event, item, openParam) {
  1941. $event.preventDefault();
  1942. $event.stopPropagation();
  1943. item[openParam] = !item[openParam];
  1944. };
  1945. $scope.onReplyClick = function(change) {
  1946. if(change.$agreed) {
  1947. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1948. $scope.loading = true;
  1949. PurcChange.reply({changeId: change.id}, reply, function(){
  1950. $scope.loading = false;
  1951. toaster.pop('info', '提示', '回复成功');
  1952. $scope.tableParams.reload();
  1953. }, function(response){
  1954. $scope.loading = false;
  1955. toaster.pop('error', '回复失败', response.data);
  1956. });
  1957. }
  1958. };
  1959. // 搜索框回车
  1960. $scope.onSearch = function() {
  1961. $scope.tableParams.page(1);
  1962. $scope.tableParams.reload();
  1963. };
  1964. }]);
  1965. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  1966. var loadData = function() {
  1967. PurcChange.get({id: $stateParams.id}, function(data){
  1968. $scope.change = data;
  1969. });
  1970. };
  1971. loadData();
  1972. $scope.openDatePicker = function($event, item, openParam) {
  1973. $event.preventDefault();
  1974. $event.stopPropagation();
  1975. item[openParam] = !item[openParam];
  1976. };
  1977. $scope.onReplyClick = function(change) {
  1978. if(change.$agreed) {
  1979. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1980. PurcChange.reply({changeId: change.id}, reply, function(){
  1981. toaster.pop('info', '提示', '回复成功');
  1982. loadData();
  1983. }, function(response){
  1984. toaster.pop('error', '回复失败', response.data);
  1985. });
  1986. }
  1987. };
  1988. }]);
  1989. //采购询价
  1990. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  1991. $scope.active = 'todo';
  1992. $scope.agreedText = '全部';
  1993. $scope.dateZoneText = '一个月内';
  1994. $scope.condition = {dateZone: 1};
  1995. $scope.changeAgreed = function(agreed) {
  1996. $scope.condition.agreed = agreed;
  1997. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  1998. $scope.condition.$agreedOpen = false;
  1999. };
  2000. $scope.changeDateZone = function(zone) {
  2001. $scope.condition.dateZone = zone;
  2002. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2003. $scope.condition.$dateZoneOpen = false;
  2004. };
  2005. $scope.setActive = function(state) {
  2006. if($scope.active != state) {
  2007. $scope.active = state;
  2008. if($scope.tableParams.page() == 1)
  2009. $scope.tableParams.reload();
  2010. else
  2011. $scope.tableParams.page(1);
  2012. }
  2013. };
  2014. var getService = function() {
  2015. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2016. };
  2017. $scope.tableParams = new ngTableParams({
  2018. page : 1,
  2019. count : 5,
  2020. sorting: {
  2021. 'inquiry.date': 'desc',
  2022. 'inquiry.enterprise.enName': 'asc',
  2023. 'inquiry.code': 'asc'
  2024. }
  2025. }, {
  2026. total : 0,
  2027. counts: [5, 10, 25, 50],
  2028. getData : function($defer, params) {
  2029. $scope.loading = true;
  2030. var pageParams = params.url();
  2031. var realActive = {};
  2032. pageParams.keyword = $scope.keyword;
  2033. if ($scope.active == 'overdue') {
  2034. $scope.active = 'end';
  2035. }
  2036. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2037. $scope.loading = false;
  2038. if(page) {
  2039. params.total(page.totalElement);
  2040. $defer.resolve(page.content);
  2041. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2042. }
  2043. }, function(response){
  2044. $scope.loading = false;
  2045. toaster.pop('error', '数据加载失败', response.data);
  2046. });
  2047. }
  2048. });
  2049. $scope.getMinDate = function(item) {
  2050. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2051. };
  2052. $scope.replyPrices = [];
  2053. $scope.replylapQtys = [];
  2054. $scope.replyPrices.push(true);
  2055. $scope.replylapQtys.push(true);
  2056. $scope.addStep = function(inquiryItem) {
  2057. $scope.replyPrices.push(true);
  2058. if(inquiryItem.replies.length >= 10) {
  2059. toaster.pop('warning', '提示', '最多支持10个分段!');
  2060. } else {
  2061. inquiryItem.replies.push({});
  2062. if(inquiryItem.replies.length != 1) {
  2063. $scope.replyPrices.push(true);
  2064. $scope.replylapQtys.push(true);
  2065. }
  2066. }
  2067. };
  2068. $scope.removeStep = function(inquiryItem, stepIndex) {
  2069. inquiryItem.replies.splice(stepIndex, 1);
  2070. $scope.replyPrices.splice(stepIndex, 1);
  2071. $scope.replylapQtys.splice(stepIndex, 1);
  2072. };
  2073. $scope.openDatePicker = function($event, item, openParam) {
  2074. $event.preventDefault();
  2075. $event.stopPropagation();
  2076. item[openParam] = !item[openParam];
  2077. };
  2078. $scope.getHistory = function(item) {
  2079. if(!item.history) {
  2080. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2081. item.history = data;
  2082. });
  2083. }
  2084. };
  2085. $scope.isValid = function(item, withSteps) {
  2086. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2087. if(!withSteps || !bool)
  2088. return bool;
  2089. angular.forEach(item.replies, function(r, i){
  2090. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2091. });
  2092. return bool;
  2093. };
  2094. $scope.onReplyClick = function(item, withSteps) {
  2095. if(item.vendFromDate instanceof Date) {
  2096. item.vendFromDate = item.vendFromDate.getTime();
  2097. }
  2098. if(item.vendToDate instanceof Date) {
  2099. item.vendToDate = item.vendToDate.getTime();
  2100. }
  2101. if(item.vendFromDate > item.vendToDate) {
  2102. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2103. return;
  2104. }
  2105. var replies = [];
  2106. angular.forEach(item.replies, function(r, i){
  2107. if((i > 0 ? r.lapQty : 1) || r.price)
  2108. replies.push(r);
  2109. });
  2110. item.replies = replies;
  2111. $scope.loading = true;
  2112. if(withSteps) {
  2113. PurcInquiry.reply({itemId: item.id}, item, function(){
  2114. $scope.loading = false;
  2115. toaster.pop('info', '提示', '报价成功');
  2116. $scope.tableParams.reload();
  2117. }, function(response){
  2118. $scope.loading = false;
  2119. toaster.pop('error', '报价失败', response.data);
  2120. });
  2121. } else {
  2122. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2123. $scope.loading = false;
  2124. toaster.pop('info', '提示', '保存成功');
  2125. $scope.tableParams.reload();
  2126. }, function(response){
  2127. $scope.loading = false;
  2128. toaster.pop('error', '保存失败', response.data);
  2129. });
  2130. }
  2131. };
  2132. $scope.verifylapQty = function(value,type) {
  2133. var regex = /^\d+(.\d{1,5})?$/;
  2134. $scope.replylapQtys[type] = regex.test(value);
  2135. }
  2136. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2137. $scope.verify = function(value,type) {
  2138. var regex = /^\d+(.\d{1,5})?$/;//
  2139. switch(type) {
  2140. case 'minOrderQty':
  2141. $scope.minOrderQtyVerify = regex.test(value);
  2142. break;
  2143. case 'minPackQty':
  2144. $scope.minPackQtyVerify = regex.test(value);
  2145. break;
  2146. case 'leadtime':
  2147. $scope.leadtimeVerify = regex.test(value);
  2148. break;
  2149. default:
  2150. $scope.replyPrices[type] = regex.test(value);
  2151. break;
  2152. }
  2153. }
  2154. // 搜索框回车
  2155. $scope.onSearch = function() {
  2156. $scope.tableParams.page(1);
  2157. $scope.tableParams.reload();
  2158. };
  2159. }]);
  2160. // 询价单明细
  2161. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2162. var loadData = function() {
  2163. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2164. $scope.newinquiryItems = data;
  2165. var inquiry = data[0].inquiry;
  2166. //inquiry.inquiryItems = data;
  2167. angular.forEach(inquiry.attachs, function(attach){
  2168. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2169. });
  2170. $scope.inquiry = inquiry;
  2171. });
  2172. };
  2173. loadData();
  2174. $scope.getMinDate = function(item) {
  2175. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2176. };
  2177. $scope.addStep = function(inquiryItem) {
  2178. if(inquiryItem.replies.length >= 10) {
  2179. toaster.pop('warning', '提示', '最多支持10个分段!');
  2180. } else
  2181. inquiryItem.replies.push({});
  2182. };
  2183. $scope.removeStep = function(inquiryItem, stepIndex) {
  2184. inquiryItem.replies.splice(stepIndex, 1);
  2185. };
  2186. $scope.openDatePicker = function($event, item, openParam) {
  2187. $event.preventDefault();
  2188. $event.stopPropagation();
  2189. item[openParam] = !item[openParam];
  2190. };
  2191. $scope.getHistory = function(item) {
  2192. if(!item.history) {
  2193. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2194. item.history = data;
  2195. });
  2196. }
  2197. };
  2198. $scope.isValid = function(item, withSteps) {
  2199. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2200. if(!withSteps || !bool)
  2201. return bool;
  2202. angular.forEach(item.replies, function(r, i){
  2203. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2204. });
  2205. return bool;
  2206. };
  2207. $scope.onReplyClick = function(item, withSteps) {
  2208. if(item.vendFromDate instanceof Date) {
  2209. item.vendFromDate = item.vendFromDate.getTime();
  2210. }
  2211. if(item.vendToDate instanceof Date) {
  2212. item.vendToDate = item.vendToDate.getTime();
  2213. }
  2214. if(item.vendFromDate > item.vendToDate) {
  2215. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2216. return;
  2217. }
  2218. var replies = [];
  2219. angular.forEach(item.replies, function(r, i){
  2220. if((i > 0 ? r.lapQty : 1) || r.price)
  2221. replies.push(r);
  2222. });
  2223. item.replies = replies;
  2224. if(withSteps) {
  2225. PurcInquiry.reply({itemId: item.id}, item, function(){
  2226. toaster.pop('info', '提示', '报价成功');
  2227. loadData();
  2228. }, function(response){
  2229. toaster.pop('error', '报价失败', response.data);
  2230. });
  2231. }
  2232. };
  2233. }]);
  2234. // 模具询价管理
  2235. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  2236. $scope.active = 'todo';
  2237. $scope.agreedText = '全部';
  2238. $scope.dateZoneText = '一个月内';
  2239. $scope.condition = {dateZone: 1};
  2240. var inquiryMould_copy = {};
  2241. $scope.changeAgreed = function(agreed) {
  2242. $scope.condition.agreed = agreed;
  2243. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2244. $scope.condition.$agreedOpen = false;
  2245. };
  2246. $scope.changeDateZone = function(zone) {
  2247. $scope.condition.dateZone = zone;
  2248. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2249. $scope.condition.$dateZoneOpen = false;
  2250. };
  2251. $scope.setActive = function(state) {
  2252. if($scope.active != state ) {
  2253. $scope.active = state;
  2254. if ($scope.tableParams.page() == 1) {
  2255. $scope.tableParams.reload();
  2256. } else {
  2257. $scope.tableParams.page(1);
  2258. }
  2259. }
  2260. }
  2261. var getService = function() {
  2262. return PurcInquiryMould;
  2263. };
  2264. $scope.tableParams = new ngTableParams({
  2265. page: 1,
  2266. count: 5
  2267. },{
  2268. total: 0,
  2269. counts: [5, 10, 25, 50],
  2270. getData: function($defer, params) {
  2271. $scope.loading = true;
  2272. var pageParams = params.url();
  2273. var realActive = {};
  2274. pageParams.keyword = $scope.keyword;
  2275. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2276. $scope.loading = false;
  2277. // 用来验证价格修改
  2278. var mould = page.content;
  2279. inquiryMould_copy = angular.copy(mould);
  2280. if(page) {
  2281. params.total(page.totalElement);
  2282. $defer.resolve(page.content);
  2283. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2284. }
  2285. }, function(response){
  2286. $scope.loading = false;
  2287. toaster.pop('error', '数据加载失败', response.data);
  2288. });
  2289. }
  2290. })
  2291. $scope.getMinDate = function(item) {
  2292. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  2293. };
  2294. $scope.replyPrices = [];
  2295. $scope.replyPrices.push(true);
  2296. // 取消
  2297. $scope.reload = function() {
  2298. $scope.tableParams.reload();
  2299. $scope.canSave = false;
  2300. }
  2301. // 能否保存设置
  2302. $scope.canSave = false;
  2303. // items价格验证
  2304. $scope.verifyItems = function(price, reply) {
  2305. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  2306. if(regex.test(price) && price != 0) {
  2307. if (price != reply) {
  2308. $scope.canSave = true;
  2309. } else {
  2310. $scope.canSave = false;
  2311. }
  2312. } else {
  2313. $scope.canSave = false;
  2314. }
  2315. }
  2316. // prod下prods价格验证
  2317. $scope.verifyProds = function(price, reply) {
  2318. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2319. if(regex.test(price) && price != 0) {
  2320. if (price != reply) {
  2321. $scope.canSave = true;
  2322. } else {
  2323. $scope.canSave = false;
  2324. }
  2325. } else {
  2326. $scope.canSave = false;
  2327. }
  2328. }
  2329. //有价格为0或者不符合正则式,则不能报价
  2330. $scope.notZero = function (mould) {
  2331. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2332. angular.forEach(mould.inquiryMouldItems, function(item){
  2333. if (item.price == 0 || !regex.test(item.price)) {
  2334. $scope.canSave = false;
  2335. }
  2336. angular.forEach(item.inquiryMouldDetails, function(detail){
  2337. if (detail.price == 0 || !regex.test(detail.price)) {
  2338. $scope.canSave = false;
  2339. }
  2340. })
  2341. });
  2342. }
  2343. $scope.blurPrice = function (price) {
  2344. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2345. if (!regex.test(price)) {
  2346. toaster.pop('warning','格式错误','请输入有效价格');
  2347. }
  2348. }
  2349. // 获取历史报价
  2350. $scope.getHistory = function(mould) {
  2351. if(!mould.history) {
  2352. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  2353. mould.history = data;
  2354. console.log(mould.history);
  2355. });
  2356. }
  2357. };
  2358. $scope.uploadAttach = function(mould) {
  2359. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2360. var file = mould.attachs[0];
  2361. $scope.mould = mould;
  2362. $upload.upload({
  2363. url: 'sale/mould/' + mould.id + '/send',
  2364. method: 'POST',
  2365. file: file,
  2366. data: {
  2367. json: $scope.mould
  2368. }
  2369. }).success(function(res){
  2370. console.log("success");
  2371. console.log(res);
  2372. }).error(function(res){
  2373. console.log("failure");
  2374. console.log(res);
  2375. });
  2376. }
  2377. // 保存并确认报价
  2378. $scope.onReplyClick = function(mould, withSteps) {
  2379. $scope.loading = true;
  2380. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2381. // var file = mould.attachs[0];
  2382. // $scope.mould = mould;
  2383. // $upload.upload({
  2384. // url: 'sale/mould/' + mould.id + '/send',
  2385. // method: 'POST',
  2386. // file: file,
  2387. // data: {
  2388. // json: $scope.mould
  2389. // }
  2390. // }).success(function(res){
  2391. // console.log("success");
  2392. // console.log(res);
  2393. // }).error(function(res){
  2394. // console.log("failure");
  2395. // });
  2396. if(withSteps) {
  2397. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  2398. $scope.loading = false;
  2399. toaster.pop('info', '提示', '报价成功');
  2400. $scope.tableParams.reload();
  2401. $scope.canSave = false;
  2402. }, function(response){
  2403. $scope.loading = false;
  2404. toaster.pop('error', '报价失败', response.data);
  2405. });
  2406. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  2407. }, function(response){
  2408. });
  2409. } else {
  2410. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  2411. $scope.loading = false;
  2412. toaster.pop('info', '提示', '保存成功');
  2413. $scope.tableParams.reload();
  2414. }, function(response){
  2415. $scope.loading = false;
  2416. toaster.pop('error', '保存失败', response.data);
  2417. });
  2418. }
  2419. };
  2420. // 搜索框回车
  2421. $scope.onSearch = function() {
  2422. $scope.tableParams.page(1);
  2423. $scope.tableParams.reload();
  2424. };
  2425. }]);
  2426. // 模具询价单明细
  2427. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  2428. var inquiryMould_copy = {};
  2429. var loadData = function() {
  2430. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  2431. // 用来验证价格修改
  2432. inquiryMould_copy = angular.copy(data);
  2433. $scope.inquiryMould_copy = inquiryMould_copy;
  2434. $scope.newinquirymould = data;
  2435. var mould = data;
  2436. angular.forEach(mould.attachs, function(attach){
  2437. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2438. });
  2439. $scope.inquiryMould = mould;
  2440. });
  2441. };
  2442. loadData();
  2443. $scope.getMinDate = function(item) {
  2444. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2445. };
  2446. // 取消
  2447. $scope.reload = function() {
  2448. loadData();
  2449. $scope.canSave = false;
  2450. }
  2451. //有价格为0,则不能报价
  2452. $scope.notZero = function (mould) {
  2453. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2454. angular.forEach(mould.inquiryMouldItems, function(item){
  2455. if (item.price == 0 || !regex.test(item.price)) {
  2456. $scope.canSave = false;
  2457. }
  2458. angular.forEach(item.inquiryMouldDetails, function(detail){
  2459. if (detail.price == 0 || !regex.test(detail.price)) {
  2460. $scope.canSave = false;
  2461. }
  2462. })
  2463. });
  2464. }
  2465. $scope.blurPrice = function (price) {
  2466. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2467. if (!regex.test(price)) {
  2468. toaster.pop('warning','格式错误','请输入有效价格');
  2469. }
  2470. }
  2471. // 获取历史报价
  2472. $scope.getHistory = function(mould) {
  2473. if(!mould.history) {
  2474. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  2475. mould.history = data;
  2476. console.log(mould.history);
  2477. });
  2478. }
  2479. };
  2480. $scope.canSave = false;
  2481. // items价格验证
  2482. $scope.verifyItems = function(price, index) {
  2483. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2484. if(regex.test(price) && price != 0) {
  2485. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  2486. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  2487. $scope.canSave = true;
  2488. } else {
  2489. $scope.canSave = false;
  2490. }
  2491. } else {
  2492. $scope.canSave = false;
  2493. }
  2494. }
  2495. // prod下prods价格验证
  2496. $scope.verifyProds = function(price, index, parentIndex) {
  2497. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2498. if(regex.test(price) && price != 0) {
  2499. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  2500. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  2501. $scope.canSave = true;
  2502. } else {
  2503. $scope.canSave = false;
  2504. }
  2505. } else {
  2506. $scope.canSave = false;
  2507. }
  2508. }
  2509. // // 上传附件
  2510. // $scope.uploadAttach = function(mould) {
  2511. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2512. // var file = mould.attachs[0];
  2513. // $scope.mould = mould;
  2514. // $upload.upload({
  2515. // url: 'sale/mould/' + mould.id + '/send',
  2516. // method: 'POST',
  2517. // file: file,
  2518. // data: {
  2519. // json: $scope.mould
  2520. // }
  2521. // }).success(function(res){
  2522. // console.log("success");
  2523. // console.log(res);
  2524. // }).error(function(res){
  2525. // console.log("failure");
  2526. // console.log(res);
  2527. // });
  2528. // }
  2529. $scope.onReplyClick = function(mould, withSteps) {
  2530. $scope.loading = true;
  2531. // var file = mould.attachs[0];
  2532. // $scope.mould = mould;
  2533. // $upload.upload({
  2534. // url: 'sale/mould/' + mould.id + '/send',
  2535. // method: 'POST',
  2536. // file: file,
  2537. // data: {
  2538. // json: $scope.mould
  2539. // }
  2540. // }).success(function(res){
  2541. //
  2542. // }).error(function(res){
  2543. // console.log(res);
  2544. // });
  2545. if(withSteps) {
  2546. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  2547. $scope.loading = false;
  2548. toaster.pop('info', '提示', '报价成功');
  2549. loadData();
  2550. $scope.canSave = false;
  2551. }, function(response){
  2552. $scope.loading = false;
  2553. toaster.pop('error', '报价失败', response.data);
  2554. });
  2555. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  2556. }, function(response){
  2557. });
  2558. } else {
  2559. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  2560. $scope.loading = false;
  2561. toaster.pop('info', '提示', '保存成功');
  2562. loadData();
  2563. }, function(response){
  2564. $scope.loading = false;
  2565. toaster.pop('error', '保存失败', response.data);
  2566. });
  2567. }
  2568. };
  2569. }]);
  2570. // 主动报价 - 列表
  2571. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  2572. $scope.active = 'todo';
  2573. $scope.agreedText = '全部';
  2574. $scope.dateZoneText = '一个月内';
  2575. $scope.condition = {dateZone: 1};
  2576. $scope.changeDateZone = function(zone) {
  2577. $scope.condition.dateZone = zone;
  2578. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2579. $scope.condition.$dateZoneOpen = false;
  2580. };
  2581. $scope.setActive = function(state) {
  2582. if($scope.active != state) {
  2583. $scope.active = state;
  2584. if($scope.tableParams.page() == 1)
  2585. $scope.tableParams.reload();
  2586. else
  2587. $scope.tableParams.page(1);
  2588. }
  2589. };
  2590. var getService = function() {
  2591. return Quotation;
  2592. };
  2593. $scope.tableParams = new ngTableParams({
  2594. page : 1,
  2595. count : 5,
  2596. sorting: {
  2597. 'quotation.date': 'desc'
  2598. }
  2599. }, {
  2600. total : 0,
  2601. counts: [5, 10, 25, 50],
  2602. getData : function($defer, params) {
  2603. $scope.loading = true;
  2604. var pageParams = params.url();
  2605. pageParams.keyword = $scope.keyword;
  2606. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2607. $scope.loading = false;
  2608. if(page) {
  2609. params.total(page.totalElement);
  2610. $defer.resolve(page.content);
  2611. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2612. }
  2613. }, function(response){
  2614. $scope.loading = false;
  2615. toaster.pop('error', '数据加载失败', response.data);
  2616. });
  2617. }
  2618. });
  2619. $scope.getHistory = function(item) {
  2620. if(!item.history) {
  2621. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2622. item.history = data;
  2623. });
  2624. }
  2625. };
  2626. $scope.isValid = function(item, withSteps) {
  2627. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2628. if(!withSteps || !bool)
  2629. return bool;
  2630. angular.forEach(item.replies, function(r, i){
  2631. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2632. });
  2633. return bool;
  2634. };
  2635. // 搜索框回车
  2636. $scope.onSearch = function() {
  2637. $scope.tableParams.page(1);
  2638. $scope.tableParams.reload();
  2639. };
  2640. }]);
  2641. // Controller 主动报价 - 新增
  2642. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
  2643. var staticItem = null;
  2644. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  2645. $scope.loading = true;
  2646. Quotation.getItem({id: $stateParams.id}, function(data){
  2647. data.$editing = false;
  2648. $scope.item = data;
  2649. staticItem = angular.copy(data);
  2650. $scope.loading = false;
  2651. }, function(response){
  2652. $scope.loading = false;
  2653. toaster.pop('error', '数据加载失败', response.data);
  2654. });
  2655. } else {// 新增模式
  2656. $scope.item = {
  2657. quotation: {
  2658. currency: 'RMB',
  2659. taxrate: 17,
  2660. date: new Date()
  2661. },
  2662. product: {},
  2663. prices: [{lapQty: 0}],
  2664. minOrderQty: 1,
  2665. minPackQty: 1,
  2666. $endDateOpen: false,
  2667. $editing: true
  2668. };
  2669. }
  2670. $scope.getMinDate = function(item) {
  2671. return $filter('date')(new Date, 'yyyy-MM-dd');
  2672. };
  2673. $scope.openDatePicker = function($event, openParam) {
  2674. $event.preventDefault();
  2675. $event.stopPropagation();
  2676. $scope.item.$endDateOpen = !openParam;
  2677. };
  2678. // 增加一个分段
  2679. $scope.addPrice = function(){
  2680. if($scope.item.prices.length >= 10) {
  2681. toaster.pop('warning', '提示', '最多支持10个分段!');
  2682. } else
  2683. $scope.item.prices.push({});
  2684. };
  2685. // 删除一个分段
  2686. $scope.removePrice = function(index) {
  2687. $scope.item.prices.splice(index, 1);
  2688. };
  2689. // 查找客户
  2690. $scope.dbfindCust = function(){
  2691. if($scope.item.$editing) {
  2692. var modalInstance = $modal.open({
  2693. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  2694. controller: 'DbfindCustCtrl',
  2695. size: 'lg',
  2696. resolve: {
  2697. }
  2698. });
  2699. modalInstance.result.then(function(data){
  2700. $scope.item.quotation.cust = data.myEnterprise;
  2701. $scope.item.quotation.custUser = data.myUser;
  2702. $scope.item.product = null;
  2703. }, function(){
  2704. });
  2705. }
  2706. };
  2707. // 查找客户物料
  2708. $scope.dbfindCustProd = function(){
  2709. if($scope.item.$editing) {
  2710. if($scope.item.quotation.cust.uu) {
  2711. var modalInstance = $modal.open({
  2712. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  2713. controller: 'DbfindCustProdCtrl',
  2714. size: 'lg',
  2715. resolve: {
  2716. custUU: function(){return $scope.item.quotation.cust.uu}
  2717. }
  2718. });
  2719. modalInstance.result.then(function(data){
  2720. $scope.item.product = data;
  2721. }, function(){
  2722. });
  2723. } else {
  2724. toaster.pop('error', '错误', '请先选择客户');
  2725. }
  2726. }
  2727. };
  2728. // 保存
  2729. $scope.save = function(){
  2730. $scope.loading = true;
  2731. if(!$scope.item.quotation.code) //新增,设单号
  2732. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  2733. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  2734. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  2735. $scope.item.productId = $scope.item.product.id;
  2736. $scope.item.quotation.status = 100;//在录入
  2737. if($scope.item.quotation.date instanceof Date) {
  2738. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  2739. }
  2740. if($scope.item.quotation.endDate instanceof Date) {
  2741. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  2742. }
  2743. Quotation.save({}, $scope.item, function(data){
  2744. $scope.loading = false;
  2745. toaster.pop('success', '成功', '保存成功');
  2746. if($stateParams.id)
  2747. window.location.reload();
  2748. else
  2749. window.location.hash = '#/sale/quotation/' + data.id;
  2750. }, function(response){
  2751. $scope.loading = false;
  2752. toaster.pop('error', '保存失败', response.data);
  2753. });
  2754. };
  2755. // 更新
  2756. $scope.update = function(){
  2757. $scope.item.$editing = true;
  2758. };
  2759. // 取消
  2760. $scope.cancel = function(){
  2761. $scope.item.$editing = false;
  2762. $scope.item = angular.copy(staticItem);
  2763. };
  2764. // 提交
  2765. $scope.submit = function(){
  2766. $scope.loading = true;
  2767. $scope.item.quotation.status = 101;//在录入
  2768. Quotation.save({}, $scope.item, function(data){
  2769. $scope.loading = false;
  2770. toaster.pop('success', '成功', '提交成功');
  2771. window.location.hash = '#/sale/quotation/' + data.id;
  2772. }, function(response){
  2773. $scope.loading = false;
  2774. toaster.pop('error', '保存失败', response.data);
  2775. });
  2776. };
  2777. }]);
  2778. // 查找客户
  2779. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  2780. $scope.tableParams = new ngTableParams({
  2781. page : 1,
  2782. count : 10
  2783. }, {
  2784. total : 0,
  2785. counts: [5, 10, 25, 50],
  2786. getData : function($defer, params) {
  2787. $scope.loading = true;
  2788. Customer.get(BaseService.parseParams(params.url()), function(page){
  2789. $scope.loading = false;
  2790. if(page) {
  2791. params.total(page.totalElements);
  2792. $defer.resolve(page.content);
  2793. }
  2794. $scope.totalCount = page.totalElements;
  2795. }, function(response){
  2796. $scope.loading = false;
  2797. toaster.pop('error', '数据加载失败', response.data);
  2798. });
  2799. }
  2800. });
  2801. $scope.cancel = function() {
  2802. $modalInstance.dismiss();
  2803. };
  2804. $scope.check = function(cust){
  2805. $modalInstance.close(cust);
  2806. };
  2807. }]);
  2808. // 查找客户物料
  2809. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  2810. $scope.tableParams = new ngTableParams({
  2811. page : 1,
  2812. count : 10
  2813. }, {
  2814. total : 0,
  2815. counts: [5, 10, 25, 50],
  2816. getData : function($defer, params) {
  2817. $scope.loading = true;
  2818. var pageParams = params.url();
  2819. pageParams.keyword = $scope.keyword;
  2820. pageParams.custUU = custUU;
  2821. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  2822. $scope.loading = false;
  2823. if(page) {
  2824. params.total(page.totalElements);
  2825. $defer.resolve(page.content);
  2826. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2827. }
  2828. }, function(response){
  2829. $scope.loading = false;
  2830. toaster.pop('error', '数据加载失败', response.data);
  2831. });
  2832. }
  2833. });
  2834. // 取消
  2835. $scope.cancel = function() {
  2836. $modalInstance.dismiss();
  2837. };
  2838. // 选择
  2839. $scope.check = function(cust){
  2840. $modalInstance.close(cust);
  2841. };
  2842. // 搜索框回车
  2843. $scope.onSearch = function() {
  2844. $scope.tableParams.page(1);
  2845. $scope.tableParams.reload();
  2846. };
  2847. }]);
  2848. // 查找供应商
  2849. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  2850. console.log($rootScope);
  2851. $scope.tableParams = new ngTableParams({
  2852. page : 1,
  2853. count : 25
  2854. }, {
  2855. total : 0,
  2856. counts: [10, 25, 50, 100],
  2857. getData : function($defer, params) {
  2858. $scope.loading = true;
  2859. Vendor.getVendor(BaseService.parseParams(params.url()), function(page){
  2860. $scope.loading = false;
  2861. if(page) {
  2862. params.total(page.totalElements);
  2863. $defer.resolve(page.content);
  2864. // 添加供应商时,将已存在的选中
  2865. if ($rootScope.tenderVendor) {
  2866. angular.forEach(page.content, function(vendor) {
  2867. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  2868. vendor.checked = false;
  2869. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  2870. vendor.checked = true;
  2871. break;
  2872. }
  2873. }
  2874. });
  2875. }
  2876. }
  2877. $scope.totalCount = page.totalElements;
  2878. }, function(response){
  2879. $scope.loading = false;
  2880. toaster.pop('error', '数据加载失败', response.data);
  2881. });
  2882. }
  2883. });
  2884. $scope.cancel = function() {
  2885. $modalInstance.dismiss();
  2886. };
  2887. $scope.checks = {
  2888. checked : false
  2889. };// 全选框
  2890. $scope.checkAll = function() {
  2891. angular.forEach($scope.tableParams.data, function(vendor) {
  2892. vendor.checked = $scope.checks.checked;
  2893. });
  2894. };
  2895. // 单选
  2896. $scope.checkOne = function(vendor) {
  2897. vendor.checked = true;
  2898. }
  2899. $scope.close = function(){
  2900. var vendors = [];
  2901. angular.forEach($scope.tableParams.data, function(vendor) {
  2902. if(vendor.checked) {
  2903. vendors.push(vendor);
  2904. $modalInstance.close(vendors);
  2905. }
  2906. });
  2907. }
  2908. }]);
  2909. // 发货提醒
  2910. 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){
  2911. $scope.active = 'todo';
  2912. $scope.currency = Symbol.currency;
  2913. $scope.dateZoneText = '不限';
  2914. $scope.condition = {dateZone: -1};
  2915. $scope.changeDateZone = function(zone) {
  2916. $scope.condition.dateZone = zone;
  2917. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2918. $scope.condition.$dateZoneOpen = false;
  2919. getDateCondition(zone, $scope.condition);
  2920. $scope.tableParams.reload();
  2921. };
  2922. $scope.setActive = function(state) {
  2923. if($scope.active != state) {
  2924. $scope.active = state;
  2925. if($scope.tableParams.page() == 1)
  2926. $scope.tableParams.reload();
  2927. else
  2928. $scope.tableParams.page(1);
  2929. }
  2930. };
  2931. var getService = function() {
  2932. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  2933. };
  2934. $scope.tableParams = new ngTableParams({
  2935. page : 1,
  2936. count : 5,
  2937. sorting: {
  2938. 'delivery': 'asc',
  2939. 'orderItemOrderCode': 'asc',
  2940. 'orderItemNumber': 'asc'
  2941. }
  2942. }, {
  2943. total : 0,
  2944. counts: [5, 10, 25, 50],
  2945. getData : function($defer, params) {
  2946. $scope.loading = true;
  2947. var pageParams = params.url();
  2948. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2949. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2950. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2951. $scope.loading = false;
  2952. if(page) {
  2953. params.total(page.totalElement);
  2954. $defer.resolve(page.content);
  2955. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2956. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2957. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2958. }
  2959. }, function(response){
  2960. $scope.loading = false;
  2961. toaster.pop('error', '数据加载失败', response.data);
  2962. });
  2963. }
  2964. });
  2965. $scope.openDatePicker = function($event, item, openParam) {
  2966. $event.preventDefault();
  2967. $event.stopPropagation();
  2968. item[openParam] = !item[openParam];
  2969. };
  2970. //生成随机单号
  2971. $scope.autoCode = function(notice){
  2972. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  2973. };
  2974. //可送货日期
  2975. $scope.sendDate = function(notice) {
  2976. var stock = notice.orderItem.product.ltinstock || 0;
  2977. var de = new Date(notice.delivery);
  2978. if(stock == -1) {
  2979. de.setMonth(de.getMonth() -1);
  2980. de.setDate(25);
  2981. } else if(stock >= 0) {
  2982. de.setDate(de.getDate() - stock -1);
  2983. }
  2984. return de;
  2985. };
  2986. $scope.onReplyClick = function(notice) {
  2987. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  2988. toaster.pop('warning', '警告', '数量填写错误!');
  2989. } else if(!notice.send.code) {
  2990. toaster.pop('warning', '警告', '请填写发货单号!');
  2991. } else {
  2992. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  2993. $scope.loading = true;
  2994. PurcNotice.save({id: notice.id}, send, function(data){
  2995. $scope.loading = false;
  2996. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  2997. $state.go('sale.send_detail', {id: data.id});
  2998. }, function(response){
  2999. $scope.loading = false;
  3000. toaster.pop('error', '发货失败', response.data);
  3001. });
  3002. }
  3003. };
  3004. $scope.checkboxes = {
  3005. checked : false
  3006. };
  3007. // 点击勾选全部的复选框
  3008. $scope.checkAll = function(){
  3009. angular.forEach($scope.tableParams.data, function(item) {
  3010. if(!item.waiting)
  3011. item.$selected = $scope.checkboxes.checked;
  3012. });
  3013. };
  3014. // 点击其中一个明细的复选框
  3015. $scope.checkOne = function(order){
  3016. var result = true;
  3017. angular.forEach($scope.tableParams.data, function(item) {
  3018. if(item.$selected != true){
  3019. result = false;
  3020. return;
  3021. }
  3022. });
  3023. $scope.checkboxes.checked = result;
  3024. };
  3025. $scope.sendByBatch = function(){
  3026. var modalInstance = $modal.open({
  3027. animation: true,
  3028. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  3029. controller: 'SaleNoticeSendByBatchCtrl',
  3030. size: 'lg',
  3031. resolve: {
  3032. selectedNotices: function(){return $scope.tableParams.data;}
  3033. }
  3034. });
  3035. modalInstance.result.then(function(){
  3036. $scope.tableParams.reload();
  3037. }, function(){
  3038. });
  3039. };
  3040. $scope.getSends = function(notice){
  3041. if( ! notice.sends && notice.endQty > 0){
  3042. notice.getSendsing = true;
  3043. notice.getSendsError = false;
  3044. PurcNotice.getSends({id: notice.id}, function(data){
  3045. notice.getSendsing = false;
  3046. notice.getSendsError = false;
  3047. notice.sends = data;
  3048. }, function(response){
  3049. notice.getSendsing = false;
  3050. notice.getSendsError = true;
  3051. });
  3052. }
  3053. };
  3054. // 搜索框回车
  3055. $scope.onSearch = function() {
  3056. $scope.tableParams.page(1);
  3057. $scope.tableParams.reload();
  3058. };
  3059. // 选择查找日期
  3060. $scope.onDateCondition = function(){
  3061. $scope.tableParams.page(1);
  3062. $scope.tableParams.reload();
  3063. };
  3064. //货车功能
  3065. var truck = $rootScope.truck;
  3066. if(!truck) {
  3067. SaleTruck.query({}, function(data){
  3068. $rootScope.truck = data;
  3069. });
  3070. }
  3071. $scope.isInTruck = function(noticeId) {
  3072. return truck.indexOf(noticeId) > -1;
  3073. };
  3074. $scope.addtoTruck = function(notice) {
  3075. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  3076. $rootScope.truck = data;
  3077. });
  3078. };
  3079. $scope.delFromTruck = function(notice) {
  3080. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  3081. $rootScope.truck = data;
  3082. });
  3083. };
  3084. $scope.$watch(function(){
  3085. return $rootScope.truck;
  3086. }, function(data) {
  3087. truck = $rootScope.truck;
  3088. }, true);
  3089. $scope.$watch(function(){
  3090. return $rootScope.dataChanged;
  3091. }, function(data) {
  3092. data && ($scope.tableParams.reload());
  3093. }, true);
  3094. }]);
  3095. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  3096. $scope.notices = angular.copy(selectedNotices);
  3097. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3098. $scope.saleSend = {
  3099. code: '',
  3100. payments: '',
  3101. currency: '',
  3102. custUU: null,
  3103. custUserUU: null,
  3104. remark: '批量发货',
  3105. sendItems: []
  3106. };
  3107. // 计算总数、总额
  3108. $scope.$watch(function(){
  3109. return $scope.notices;
  3110. }, function(data) {
  3111. var q = 0, t = 0;
  3112. if(data) {
  3113. angular.forEach(data,function(d){
  3114. q += (d.thisSendQty || 0);
  3115. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  3116. });
  3117. }
  3118. $scope.totalQty = q;
  3119. $scope.total = t;
  3120. }, true);
  3121. /**
  3122. * 删除一个已选中的送货提醒
  3123. */
  3124. $scope.removeOne = function(index) {
  3125. $scope.notices.splice(index, 1);
  3126. };
  3127. //确认送货
  3128. $scope.sendByBatch = function () {
  3129. $scope.saleSend.sendItems = [];
  3130. if($scope.saleSend.code == '') {//送货单号为空
  3131. toaster.pop('error', '错误', '请输入送货单号');
  3132. return;
  3133. }
  3134. var a = 0;
  3135. var num = 1;
  3136. var valid = true;
  3137. angular.forEach($scope.notices, function(item, key){
  3138. if(item.$selected) {
  3139. if(a == 0) {//第一次
  3140. $scope.saleSend.currency = item.orderItem.order.currency;
  3141. $scope.saleSend.custUU = item.enUU;
  3142. $scope.saleSend.payments = item.orderItem.order.payments;
  3143. a = 1;
  3144. } else {//其他
  3145. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  3146. if($scope.saleSend.custUU != item.enUU) valid = false;
  3147. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  3148. }
  3149. $scope.saleSend.sendItems.push({
  3150. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  3151. });
  3152. }
  3153. });
  3154. if(!valid) {
  3155. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  3156. } else {
  3157. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  3158. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  3159. $modalInstance.close('success');
  3160. $state.go('sale.send_detail', {id: data.id});
  3161. }, function(response){
  3162. toaster.pop('error', '错误', response.data);
  3163. });
  3164. }
  3165. };
  3166. $scope.cancel = function () {
  3167. $modalInstance.dismiss();
  3168. };
  3169. }]);
  3170. /**
  3171. * 发货单
  3172. */
  3173. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  3174. $scope.active = 'all';
  3175. $scope.currency = Symbol.currency;
  3176. $scope.dateZoneText = '不限';
  3177. $scope.condition = {dateZone: -1};
  3178. $scope.changeDateZone = function(zone) {
  3179. $scope.condition.dateZone = zone;
  3180. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3181. $scope.condition.$dateZoneOpen = false;
  3182. getDateCondition(zone, $scope.condition);
  3183. $scope.tableParams.reload();
  3184. };
  3185. $scope.setActive = function(state) {
  3186. if($scope.active != state) {
  3187. $scope.active = state;
  3188. if($scope.tableParams.page() == 1)
  3189. $scope.tableParams.reload();
  3190. else
  3191. $scope.tableParams.page(1);
  3192. }
  3193. };
  3194. var getService = function() {
  3195. return SaleSend;
  3196. };
  3197. $scope.tableParams = new ngTableParams({
  3198. page : 1,
  3199. count : 5,
  3200. sorting: {
  3201. date: 'desc'
  3202. }
  3203. }, {
  3204. total : 0,
  3205. counts: [5, 10, 25, 50],
  3206. getData : function($defer, params) {
  3207. $scope.loading = true;
  3208. var pageParams = params.url();
  3209. pageParams.keyword = $scope.keyword;
  3210. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3211. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3212. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3213. $scope.loading = false;
  3214. if(page) {
  3215. params.total(page.totalElement);
  3216. $defer.resolve(page.content);
  3217. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3218. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3219. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3220. }
  3221. }, function(response){
  3222. $scope.loading = false;
  3223. toaster.pop('error', '数据加载失败', response.data);
  3224. });
  3225. }
  3226. });
  3227. $scope.openDatePicker = function($event, item, openParam) {
  3228. $event.preventDefault();
  3229. $event.stopPropagation();
  3230. item[openParam] = !item[openParam];
  3231. };
  3232. // 搜索框回车
  3233. $scope.onSearch = function() {
  3234. $scope.tableParams.page(1);
  3235. $scope.tableParams.reload();
  3236. };
  3237. // 选择查找日期
  3238. $scope.onDateCondition = function(){
  3239. $scope.tableParams.page(1);
  3240. $scope.tableParams.reload();
  3241. };
  3242. }]);
  3243. /**
  3244. * 发货单(包括发货条码维护)
  3245. */
  3246. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  3247. var loading = true;
  3248. $scope.checkBarCode = [];
  3249. $scope.checkBoxCode = [];
  3250. var vm = $scope.vm = {};
  3251. $scope.getCheckedItems = {};
  3252. vm.editBar = false;
  3253. vm.showBarCode = [];
  3254. $scope.barCode = function() {
  3255. vm.editBar = !vm.editBar;
  3256. }
  3257. $scope.checkboxes = {
  3258. checked : false
  3259. };
  3260. $scope.checkbars = {
  3261. checked : false
  3262. };
  3263. // 点击勾选barCode全部的复选框
  3264. $scope.checkBarAll = function(){
  3265. angular.forEach($scope.checkBarCode, function(item,key) {
  3266. $scope.checkBarCode[key] = $scope.checkbars.checked;
  3267. });
  3268. };
  3269. //点击barCode单选
  3270. $scope.checkBarOne = function() {
  3271. var result = true;
  3272. angular.forEach($scope.checkBarCode, function(item,key) {
  3273. if(item != true){
  3274. result = false;
  3275. return;
  3276. }
  3277. });
  3278. $scope.checkbars.checked = result;
  3279. }
  3280. // 点击boxCode全部的复选框
  3281. $scope.checkBoxAll = function(){
  3282. angular.forEach($scope.checkBoxCode, function(item,key) {
  3283. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  3284. });
  3285. };
  3286. //点击boxCode单选
  3287. $scope.checkBoxOne = function() {
  3288. var result = true;
  3289. angular.forEach($scope.checkBoxCode, function(item) {
  3290. if(item != true){
  3291. result = false;
  3292. return;
  3293. }
  3294. });
  3295. $scope.checkboxes.checked = result;
  3296. }
  3297. /**
  3298. * 生成条码和箱号
  3299. */
  3300. $scope.generateBarCode = function(item) {
  3301. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  3302. $scope.getCheckedItems = [];
  3303. var warningdata = '';
  3304. angular.forEach($scope.checkBarCode, function(item,key) {
  3305. $scope.getCheckedItem = {};
  3306. if(item == true ){
  3307. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  3308. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  3309. $scope.getCheckedItems.push($scope.getCheckedItem);
  3310. //判断是否生成过条码
  3311. if($scope.order.sendItems[key].barSendNotify.length > 0){
  3312. warningdata += $scope.order.sendItems[key].number+","
  3313. }
  3314. }
  3315. });
  3316. if($scope.getCheckedItems.length == 0){
  3317. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  3318. return;
  3319. }
  3320. if(warningdata != ''){
  3321. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  3322. return ;
  3323. }
  3324. }
  3325. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  3326. toaster.pop('success', '提示','生成成功!');
  3327. loadData();
  3328. },function(response){
  3329. $scope.loading = false;
  3330. toaster.pop('error', '生成失败', response.data);
  3331. });
  3332. }
  3333. /**
  3334. * 打印条码和箱号
  3335. */
  3336. $scope.printCode = function(type) {
  3337. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  3338. //勾选需要打印的行
  3339. $scope.getCheckedItems = [];
  3340. var warningdata = ''
  3341. angular.forEach($scope.checkBarCode, function(item,key) {
  3342. $scope.getCheckedItem = {};
  3343. if(item == true ){
  3344. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  3345. $scope.getCheckedItems.push($scope.getCheckedItem);
  3346. //判断是否生成过条码
  3347. if($scope.order.sendItems[key].barSendNotify.length > 0){
  3348. warningdata += $scope.order.sendItems[key].number+","
  3349. }
  3350. }
  3351. });
  3352. if($scope.getCheckedItems.length == 0){
  3353. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  3354. return;
  3355. }
  3356. if(warningdata == ''){
  3357. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  3358. return;
  3359. }
  3360. //选择打印模板
  3361. var modalInstance = $modal.open({
  3362. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  3363. controller: 'BarPrintModalCtrl',
  3364. resolve: {
  3365. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  3366. }
  3367. });
  3368. modalInstance.result.then(function(s){
  3369. if(s) {
  3370. //获取打印数据
  3371. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  3372. if(s.type == 'print'){//判断选择是打印还是打印预览
  3373. lodopPrint(data.message,LODOP,type);
  3374. }else if(s.type == 'printPreview'){
  3375. lodopPrintPreview(data.message,LODOP,type);
  3376. }
  3377. },function(response){
  3378. toaster.pop('error', '获取打印数据失败', response.data);
  3379. });
  3380. }
  3381. });
  3382. };
  3383. //打印单个条码
  3384. $scope.printSingleCode = function(id){
  3385. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  3386. //选择打印模板
  3387. var modalInstance = $modal.open({
  3388. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  3389. controller: 'BarPrintModalCtrl',
  3390. resolve: {
  3391. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  3392. }
  3393. });
  3394. modalInstance.result.then(function(s){
  3395. if(s) {
  3396. //获取打印数据
  3397. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  3398. if(s.type == 'print'){//判断选择是打印还是打印预览
  3399. lodopSPrint(data.message,LODOP);
  3400. }else if(s.type == 'printPreview'){
  3401. lodopSPrintPreview(data.message,LODOP);
  3402. }
  3403. },function(response){
  3404. toaster.pop('error', '获取打印数据失败', response.data);
  3405. });
  3406. }
  3407. });
  3408. }
  3409. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  3410. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  3411. if (selectOrNot != -1) {
  3412. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3413. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  3414. var strs = pagesize.split("*"); //字符分割
  3415. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3416. angular.forEach(printStore, function(data, index) {
  3417. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  3418. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3419. if (data['LP_VALUETYPE'] == 'barcode') {
  3420. 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']);
  3421. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  3422. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  3423. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  3424. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  3425. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  3426. } else if (data['LP_VALUETYPE'] == 'text') {
  3427. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  3428. }
  3429. });
  3430. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  3431. LODOP.PRINT();
  3432. }
  3433. };
  3434. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  3435. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3436. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  3437. var strs = pagesize.split("*"); //字符分割
  3438. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3439. angular.forEach(printStore,function(data,index){
  3440. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  3441. if(data['LP_VALUETYPE'] == 'barcode'){
  3442. 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']);
  3443. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  3444. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  3445. }else if(data['LP_VALUETYPE'] == 'text'){
  3446. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3447. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  3448. }
  3449. });
  3450. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  3451. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  3452. LODOP.PREVIEW();//打印预览
  3453. };
  3454. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  3455. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  3456. if (selectOrNot != -1) {
  3457. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3458. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  3459. var strs= new Array(); //定义一数组
  3460. strs = pagesize.split("*"); //字符分割
  3461. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3462. var ids = new Array();
  3463. angular.forEach(printStore, function(value,key) {
  3464. //LODOP.NewPage();
  3465. angular.forEach(value['data'], function(record,key) {
  3466. angular.forEach(record['store'], function(data, index) {
  3467. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  3468. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3469. if (data['LP_VALUETYPE'] == 'barcode') {
  3470. 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']);
  3471. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  3472. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  3473. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  3474. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  3475. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  3476. } else if (data['LP_VALUETYPE'] == 'text') {
  3477. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  3478. }
  3479. });
  3480. });
  3481. var o = new Object();
  3482. o['id'] = record['si_id']
  3483. ids.push(o);
  3484. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  3485. LODOP.PRINT();
  3486. });
  3487. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  3488. if(type == 'Bar'){
  3489. //更新打印状态
  3490. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  3491. }
  3492. }
  3493. };
  3494. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  3495. var ids = new Array();
  3496. angular.forEach(printData, function(record, index){
  3497. angular.forEach(record['data'],function(value,index){
  3498. LODOP.NewPage();
  3499. angular.forEach(value['store'],function(data,index){
  3500. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  3501. if(data['LP_VALUETYPE'] == 'barcode'){
  3502. 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']);
  3503. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  3504. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  3505. }else if(data['LP_VALUETYPE'] == 'text'){
  3506. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3507. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  3508. }
  3509. });
  3510. });
  3511. var o = new Object();
  3512. o['id'] = record['si_id']
  3513. ids.push(o);
  3514. });
  3515. var pagesize = printData[0]['pagesize'];//获取标签的大小
  3516. var strs= new Array(); //定义一数组
  3517. strs = pagesize.split("*"); //字符分割
  3518. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  3519. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  3520. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3521. var times = LODOP.PREVIEW();//打印预览
  3522. if(times > 0){//点击了打印预览内的打印按钮
  3523. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  3524. if(type == 'Bar'){
  3525. //更新打印状态
  3526. SaleSend.updatePrintStatus({},ids,function(data){
  3527. loadData();
  3528. },function(res){});
  3529. }
  3530. }
  3531. };
  3532. /**
  3533. * 查看条码按钮
  3534. */
  3535. $scope.showBarCode = function(number) {
  3536. $scope.keys = number;
  3537. for(var i=0;i<vm.showBarCode.length;i++){
  3538. if(i!=number){
  3539. vm.showBarCode[i] = false;
  3540. }
  3541. }
  3542. vm.showBarCode[number] = !vm.showBarCode[number];
  3543. $scope.barcodes = [];
  3544. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  3545. var getPage = function(page, size){
  3546. if($scope.barcodes) {
  3547. var result = {};
  3548. result.totalCount = $scope.barcodes.length;
  3549. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  3550. if($scope.barcodes.length % size == 0) {
  3551. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  3552. }else {
  3553. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  3554. }
  3555. result.first = page == 1;
  3556. result.last = page == result.totalPage;
  3557. result.page = page;
  3558. result.next = page - 0 + 1;
  3559. result.pre = page - 1;
  3560. return result;
  3561. }
  3562. }
  3563. $scope.barData = getPage(1,5);
  3564. $scope.first = function (){
  3565. $scope.barData = getPage($scope.barData.pre,5);
  3566. }
  3567. $scope.last = function (){
  3568. $scope.barData = getPage($scope.barData.next,5);
  3569. }
  3570. };
  3571. /**
  3572. * 更新外箱号
  3573. */
  3574. $scope.updateOutBox = function(item,number) {
  3575. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  3576. }else {
  3577. if(item.outBoxQty > 0) {
  3578. if(!(item.outBoxQty % item.packageQty)) {
  3579. SaleSend.update({id:item.id},item,function(){
  3580. toaster.pop('success', '提示','保存成功!');
  3581. loadData();
  3582. }, function(response){
  3583. $scope.loading = false;
  3584. toaster.pop('error', '回复失败', response.data);
  3585. })
  3586. }else {
  3587. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  3588. }
  3589. }else {
  3590. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3591. }
  3592. }
  3593. loadData();
  3594. };
  3595. /**
  3596. * 更新最小包数
  3597. */
  3598. $scope.updatePackage = function(item, number) {
  3599. if(item.packageQty == $scope.oldpackageQty[number]) {
  3600. }else {
  3601. if(item.orderItem.product.minPack != 0) {
  3602. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  3603. if(!(item.packageQty % item.orderItem.product.minPack)) {
  3604. SaleSend.update({id:item.id},item,function(){
  3605. toaster.pop('success', '提示','保存成功!');
  3606. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  3607. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  3608. }
  3609. loadData();
  3610. }, function(response){
  3611. $scope.loading = false;
  3612. toaster.pop('error', '回复失败', response.data);
  3613. })
  3614. }else {
  3615. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  3616. }
  3617. }else {
  3618. toaster.pop('warning', '提示', '请填写有效的数量!');
  3619. }
  3620. }else {
  3621. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  3622. SaleSend.update({id:item.id},item,function(){
  3623. toaster.pop('success', '提示','保存成功!');
  3624. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  3625. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  3626. }
  3627. loadData();
  3628. }, function(response){
  3629. $scope.loading = false;
  3630. toaster.pop('error', '回复失败', response.data);
  3631. })
  3632. }else {
  3633. toaster.pop('warning', '提示', '请填写有效的数量!');
  3634. }
  3635. }
  3636. }
  3637. loadData();
  3638. };
  3639. var loadData = function() {
  3640. SaleSend.get({id: $stateParams.id}, function(data){
  3641. $scope.order = data;
  3642. var orderCount = $scope.order.sendItems.length;
  3643. $scope.oldpackageQty = [];
  3644. $scope.oldoutBoxQty = [];
  3645. var sum = 0;
  3646. vm.oldpackageQty = [];
  3647. angular.forEach(data.sendItems, function(value, key){
  3648. //给showBarCode数组赋初值
  3649. if (vm.showBarCode.length < orderCount){
  3650. vm.showBarCode.push(false);
  3651. }
  3652. if($scope.checkBarCode.length < orderCount) {
  3653. $scope.checkBarCode.push(false);
  3654. }
  3655. if($scope.checkBoxCode.length < orderCount) {
  3656. $scope.checkBoxCode.push(false);
  3657. }
  3658. //给个初值
  3659. if(!value.packageQty) {
  3660. value.packageQty = value.orderItem.product.minPack;
  3661. }
  3662. $scope.oldpackageQty.push(value.packageQty);
  3663. if(value.outBoxQty) {
  3664. $scope.oldoutBoxQty.push(value.outBoxQty);
  3665. }
  3666. sum += value.price * value.qty;
  3667. });
  3668. data.total = sum;
  3669. $scope.loading = false;
  3670. }, function(response){
  3671. loading = false;
  3672. toaster.pop('error', '获取数据失败', response.data);
  3673. });
  3674. };
  3675. loadData();
  3676. }]);
  3677. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  3678. $scope.typeItem = typeItem;
  3679. $scope.template = [];
  3680. $scope.choose = {};
  3681. //获取打印模板
  3682. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  3683. if(data.message){
  3684. $scope.template = data.message;
  3685. $scope.choose.tp_id = $scope.template[0].id;
  3686. }
  3687. },function(res){
  3688. toaster.pop('error', '获取模板错误', res.data);
  3689. });
  3690. $scope.print = function(){
  3691. $scope.choose.type = 'print';
  3692. $modalInstance.close($scope.choose);
  3693. };
  3694. $scope.printPreview = function(){
  3695. $scope.choose.type = 'printPreview';
  3696. $modalInstance.close($scope.choose);
  3697. }
  3698. $scope.cancel = function(){
  3699. $modalInstance.close();
  3700. }
  3701. }]);
  3702. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  3703. var loading = true;
  3704. var loadData = function() {
  3705. PurcSample.get({id: $stateParams.id}, function(data){
  3706. $scope.sample = data;
  3707. if(!$scope.sample.send){
  3708. $scope.sample.getSendInfo = '加载中...';
  3709. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  3710. if(sendData) {
  3711. $scope.sample.getSendInfo = null;
  3712. $scope.sample.send = sendData;
  3713. } else {
  3714. $scope.sample.getSendInfo = '无送样信息';
  3715. $scope.sample.send = '无送样信息';
  3716. }
  3717. }, function(response){
  3718. $scope.sample.getSendInfo = '加载失败!';
  3719. });
  3720. }
  3721. $scope.loading = false;
  3722. }, function(response){
  3723. loading = false;
  3724. toaster.pop('error', '获取数据失败', response.data);
  3725. });
  3726. };
  3727. loadData();
  3728. }]);
  3729. /**
  3730. * 客户打样申请
  3731. */
  3732. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  3733. $scope.active = 'todo';
  3734. $scope.agreedText = '全部';
  3735. $scope.dateZoneText = '一个月内';
  3736. $scope.condition = {dateZone: 1};
  3737. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3738. $scope.changeAgreed = function(agreed) {
  3739. $scope.condition.agreed = agreed;
  3740. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3741. $scope.condition.$agreedOpen = false;
  3742. };
  3743. $scope.changeDateZone = function(zone) {
  3744. $scope.condition.dateZone = zone;
  3745. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3746. $scope.condition.$dateZoneOpen = false;
  3747. };
  3748. $scope.setActive = function(state) {
  3749. if($scope.active != state) {
  3750. $scope.active = state;
  3751. if($scope.tableParams.page() == 1)
  3752. $scope.tableParams.reload();
  3753. else
  3754. $scope.tableParams.page(1);
  3755. }
  3756. };
  3757. var getService = function() {
  3758. return PurcSample;
  3759. };
  3760. $scope.tableParams = new ngTableParams({
  3761. page : 1,
  3762. count : 5,
  3763. sorting: {
  3764. proofingDate: 'desc'
  3765. }
  3766. }, {
  3767. total : 0,
  3768. counts: [5, 10, 25, 50],
  3769. getData : function($defer, params) {
  3770. $scope.loading = true;
  3771. var pageParams = params.url();
  3772. pageParams.keyword = $scope.keyword;
  3773. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3774. $scope.loading = false;
  3775. if(page) {
  3776. params.total(page.totalElement);
  3777. $defer.resolve(page.content);
  3778. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  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. $scope.openSend = function(index, sample) {
  3792. var modalInstance = $modal.open({
  3793. animation: true,
  3794. templateUrl: 'static/tpl/index/sale/sample_send.html',
  3795. controller: 'SampleSendCtrl',
  3796. resolve: {
  3797. sampleItem: function(){return sample;}
  3798. }
  3799. });
  3800. modalInstance.result.then(function(){
  3801. toaster.pop('info', '提示', '送样成功');
  3802. $scope.tableParams.reload();
  3803. }, function(){
  3804. });
  3805. };
  3806. //打印 样品采购单
  3807. $scope.print = function(sample) {
  3808. console.log(sample);
  3809. PurcSample.printCount({id: sample.id},{});//增加打印此次
  3810. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  3811. };
  3812. $scope.getSend = function(proofing){
  3813. if( !proofing.send) {
  3814. proofing.getSendInfo = '加载中...';
  3815. PurcSample.getSend({id: proofing.id}, function(data){
  3816. if(data) {
  3817. proofing.getSendInfo = null;
  3818. proofing.send = data;
  3819. } else {
  3820. proofing.getSendInfo = '无送样信息';
  3821. proofing.send = '无送样信息';
  3822. }
  3823. }, function(response){
  3824. proofing.getSendInfo = '加载失败!';
  3825. });
  3826. }
  3827. };
  3828. // 搜索框回车
  3829. $scope.onSearch = function() {
  3830. $scope.tableParams.page(1);
  3831. $scope.tableParams.reload();
  3832. };
  3833. }]);
  3834. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  3835. $scope.sampleItem = sampleItem;
  3836. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  3837. //确认送样
  3838. $scope.ok = function (form) {
  3839. $scope.loading = true;
  3840. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  3841. $upload.upload({
  3842. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  3843. method: 'POST',
  3844. file: file,
  3845. data: {
  3846. json: $scope.sampleItem.sampleSend
  3847. }
  3848. }).success(function(data){
  3849. $scope.loading = false;
  3850. $modalInstance.close('success');
  3851. }).error(function(data){
  3852. $scope.loading = false;
  3853. toaster.pop('danger', '错误', data);
  3854. });
  3855. };
  3856. $scope.cancel = function () {
  3857. $modalInstance.dismiss(sampleItem);
  3858. };
  3859. }]);
  3860. /**
  3861. * 客户认定单
  3862. */
  3863. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  3864. $scope.active = 'all';
  3865. $scope.agreedText = '全部';
  3866. $scope.dateZoneText = '一个月内';
  3867. $scope.condition = {dateZone: 1};
  3868. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3869. $scope.changeDateZone = function(zone) {
  3870. $scope.condition.dateZone = zone;
  3871. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3872. $scope.condition.$dateZoneOpen = false;
  3873. getDateCondition(zone, $scope.condition);
  3874. $scope.tableParams.reload();
  3875. };
  3876. $scope.setActive = function(state) {
  3877. if($scope.active != state) {
  3878. $scope.active = state;
  3879. if($scope.tableParams.page() == 1)
  3880. $scope.tableParams.reload();
  3881. else
  3882. $scope.tableParams.page(1);
  3883. }
  3884. };
  3885. var getService = function() {
  3886. return PurcApproval;
  3887. };
  3888. $scope.tableParams = new ngTableParams({
  3889. page : 1,
  3890. count : 5,
  3891. sorting: {
  3892. inDate: 'desc'
  3893. }
  3894. }, {
  3895. total : 0,
  3896. counts: [5, 10, 25, 50],
  3897. getData : function($defer, params) {
  3898. $scope.loading = true;
  3899. var pageParams = params.url();
  3900. pageParams.keyword = $scope.keyword;
  3901. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3902. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3903. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3904. $scope.loading = false;
  3905. if(page) {
  3906. params.total(page.totalElement);
  3907. $defer.resolve(page.content);
  3908. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3909. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3910. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3911. }
  3912. }, function(response){
  3913. $scope.loading = false;
  3914. toaster.pop('error', '数据加载失败', response.data);
  3915. });
  3916. }
  3917. });
  3918. $scope.openDatePicker = function($event, item, openParam) {
  3919. $event.preventDefault();
  3920. $event.stopPropagation();
  3921. item[openParam] = !item[openParam];
  3922. };
  3923. $scope.parseDate = function(dateStr) {
  3924. if(dateStr)
  3925. return Date.parse(dateStr, 'yyyy-MM-dd');
  3926. return new Date();
  3927. };
  3928. // 搜索框回车
  3929. $scope.onSearch = function() {
  3930. $scope.tableParams.page(1);
  3931. $scope.tableParams.reload();
  3932. };
  3933. // 选择查找日期
  3934. $scope.onDateCondition = function(){
  3935. $scope.tableParams.page(1);
  3936. $scope.tableParams.reload();
  3937. };
  3938. }]);
  3939. /**
  3940. * 客户采购预测
  3941. */
  3942. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  3943. $scope.active = 'all';
  3944. $scope.agreedText = '全部';
  3945. $scope.dateZoneText = '一个月内';
  3946. $scope.condition = {dateZone: 1};
  3947. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3948. $scope.changeAgreed = function(agreed) {
  3949. $scope.condition.agreed = agreed;
  3950. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3951. $scope.condition.$agreedOpen = false;
  3952. };
  3953. $scope.changeDateZone = function(zone) {
  3954. $scope.condition.dateZone = zone;
  3955. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3956. $scope.condition.$dateZoneOpen = false;
  3957. };
  3958. $scope.setActive = function(state) {
  3959. if($scope.active != state) {
  3960. $scope.active = state;
  3961. if($scope.tableParams.page() == 1)
  3962. $scope.tableParams.reload();
  3963. else
  3964. $scope.tableParams.page(1);
  3965. }
  3966. };
  3967. var getService = function() {
  3968. return PurcForecast;
  3969. };
  3970. $scope.tableParams = new ngTableParams({
  3971. page : 1,
  3972. count : 5,
  3973. sorting: {
  3974. orderDate: 'desc'
  3975. }
  3976. }, {
  3977. total : 0,
  3978. counts: [5, 10, 25, 50],
  3979. getData : function($defer, params) {
  3980. $scope.loading = true;
  3981. var pageParams = params.url();
  3982. pageParams.keyword = $scope.keyword;
  3983. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3984. $scope.loading = false;
  3985. if(page) {
  3986. console.log(page);
  3987. params.total(page.totalElement);
  3988. $defer.resolve(page.content);
  3989. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3990. }
  3991. }, function(response){
  3992. $scope.loading = false;
  3993. toaster.pop('error', '数据加载失败', response.data);
  3994. });
  3995. }
  3996. });
  3997. $scope.openDatePicker = function($event, item, openParam) {
  3998. $event.preventDefault();
  3999. $event.stopPropagation();
  4000. item[openParam] = !item[openParam];
  4001. };
  4002. // 搜索框回车
  4003. $scope.onSearch = function() {
  4004. $scope.tableParams.page(1);
  4005. $scope.tableParams.reload();
  4006. };
  4007. }]);
  4008. /**
  4009. * 客户采购验收
  4010. */
  4011. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  4012. $scope.active = 'all';
  4013. $scope.dateZoneText = '不限';
  4014. $scope.deliveryZoneText = '不限';
  4015. $scope.condition = {dateZone: -1, deliveryZone: -1};
  4016. $scope.changeDateZone = function(zone) {
  4017. $scope.condition.dateZone = zone;
  4018. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4019. $scope.condition.$dateZoneOpen = false;
  4020. getDateCondition(zone, $scope.condition);
  4021. $scope.tableParams.reload();
  4022. };
  4023. $scope.changeDeliveryZone = function(zone) {
  4024. $scope.condition.deliveryZoneText = zone;
  4025. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  4026. $scope.condition.$delievryZoneOpen = false;
  4027. getDelveryCondition(zone, $scope.condition);
  4028. $scope.tableParams.reload();
  4029. };
  4030. $scope.setActive = function(state) {
  4031. if($scope.active != state) {
  4032. $scope.active = state;
  4033. if($scope.tableParams.page() == 1)
  4034. $scope.tableParams.reload();
  4035. else
  4036. $scope.tableParams.page(1);
  4037. }
  4038. };
  4039. var getService = function() {
  4040. return PurcAccept;
  4041. };
  4042. $scope.tableParams = new ngTableParams({
  4043. page : 1,
  4044. count : 5,
  4045. sorting: {
  4046. date: 'desc'
  4047. }
  4048. }, {
  4049. total : 0,
  4050. counts: [5, 10, 25, 50],
  4051. getData : function($defer, params) {
  4052. $scope.loading = true;
  4053. var pageParams = params.url();
  4054. pageParams.searchFilter = { // 筛选条件
  4055. keyword: $scope.keyword,
  4056. fromDate: getDateTime($scope.condition.dateFrom),
  4057. endDate: getDateTime($scope.condition.dateTo)
  4058. };
  4059. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4060. $scope.loading = false;
  4061. if(page) {
  4062. console.log(pageParams.searchFilter);
  4063. params.total(page.totalElement);
  4064. $defer.resolve(page.content);
  4065. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4066. }
  4067. }, function(response){
  4068. $scope.loading = false;
  4069. toaster.pop('error', '数据加载失败', response.data);
  4070. });
  4071. }
  4072. });
  4073. $scope.openDatePicker = function($event, item, openParam) {
  4074. $event.preventDefault();
  4075. $event.stopPropagation();
  4076. item[openParam] = !item[openParam];
  4077. };
  4078. $scope.parseDate = function(dateStr) {
  4079. if(dateStr)
  4080. return Date.parse(dateStr, 'yyyy-MM-dd');
  4081. return new Date();
  4082. };
  4083. // 选择查找日期
  4084. $scope.onDateCondition = function(){
  4085. $scope.tableParams.page(1);
  4086. $scope.tableParams.reload();
  4087. };
  4088. // 搜索框回车
  4089. $scope.onSearch = function() {
  4090. $scope.tableParams.page(1);
  4091. $scope.tableParams.reload();
  4092. };
  4093. }]);
  4094. /**
  4095. * 客户采购验退
  4096. */
  4097. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  4098. $scope.active = 'all';
  4099. $scope.agreedText = '全部';
  4100. $scope.dateZoneText = '一个月内';
  4101. $scope.condition = {dateZone: 1};
  4102. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4103. $scope.changeAgreed = function(agreed) {
  4104. $scope.condition.agreed = agreed;
  4105. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4106. $scope.condition.$agreedOpen = false;
  4107. };
  4108. $scope.changeDateZone = function(zone) {
  4109. $scope.condition.dateZone = zone;
  4110. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4111. $scope.condition.$dateZoneOpen = false;
  4112. };
  4113. $scope.setActive = function(state) {
  4114. if($scope.active != state) {
  4115. $scope.active = state;
  4116. if($scope.tableParams.page() == 1)
  4117. $scope.tableParams.reload();
  4118. else
  4119. $scope.tableParams.page(1);
  4120. }
  4121. };
  4122. var getService = function() {
  4123. return PurcReturn;
  4124. };
  4125. $scope.tableParams = new ngTableParams({
  4126. page : 1,
  4127. count : 5,
  4128. sorting: {
  4129. date: 'desc'
  4130. }
  4131. }, {
  4132. total : 0,
  4133. counts: [5, 10, 25, 50],
  4134. getData : function($defer, params) {
  4135. $scope.loading = true;
  4136. var pageParams = params.url();
  4137. pageParams.keyword = $scope.keyword;
  4138. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4139. $scope.loading = false;
  4140. if(page) {
  4141. params.total(page.totalElement);
  4142. $defer.resolve(page.content);
  4143. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4144. angular.forEach(page.content, function(data) {
  4145. if (!data.returnItems[0].orderItem) {
  4146. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  4147. data.enName = enterprise.enName;
  4148. });
  4149. }
  4150. });
  4151. }
  4152. }, function(response){
  4153. $scope.loading = false;
  4154. toaster.pop('error', '数据加载失败', response.data);
  4155. });
  4156. }
  4157. });
  4158. $scope.openDatePicker = function($event, item, openParam) {
  4159. $event.preventDefault();
  4160. $event.stopPropagation();
  4161. item[openParam] = !item[openParam];
  4162. };
  4163. // 搜索框回车
  4164. $scope.onSearch = function() {
  4165. $scope.tableParams.page(1);
  4166. $scope.tableParams.reload();
  4167. };
  4168. }]);
  4169. /**
  4170. * 客户不良品入库
  4171. */
  4172. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  4173. $scope.active = 'all';
  4174. $scope.agreedText = '全部';
  4175. $scope.dateZoneText = '一个月内';
  4176. $scope.condition = {dateZone: 1};
  4177. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4178. $scope.changeAgreed = function(agreed) {
  4179. $scope.condition.agreed = agreed;
  4180. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4181. $scope.condition.$agreedOpen = false;
  4182. };
  4183. $scope.changeDateZone = function(zone) {
  4184. $scope.condition.dateZone = zone;
  4185. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4186. $scope.condition.$dateZoneOpen = false;
  4187. };
  4188. $scope.setActive = function(state) {
  4189. if($scope.active != state) {
  4190. $scope.active = state;
  4191. if($scope.tableParams.page() == 1)
  4192. $scope.tableParams.reload();
  4193. else
  4194. $scope.tableParams.page(1);
  4195. }
  4196. };
  4197. var getService = function() {
  4198. return PurcBadIn;
  4199. };
  4200. $scope.tableParams = new ngTableParams({
  4201. page : 1,
  4202. count : 5,
  4203. sorting: {
  4204. date: 'desc'
  4205. }
  4206. }, {
  4207. total : 0,
  4208. counts: [5, 10, 25, 50],
  4209. getData : function($defer, params) {
  4210. $scope.loading = true;
  4211. var pageParams = params.url();
  4212. pageParams.keyword = $scope.keyword;
  4213. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4214. $scope.loading = false;
  4215. if(page) {
  4216. params.total(page.totalElement);
  4217. $defer.resolve(page.content);
  4218. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4219. }
  4220. }, function(response){
  4221. $scope.loading = false;
  4222. toaster.pop('error', '数据加载失败', response.data);
  4223. });
  4224. }
  4225. });
  4226. $scope.openDatePicker = function($event, item, openParam) {
  4227. $event.preventDefault();
  4228. $event.stopPropagation();
  4229. item[openParam] = !item[openParam];
  4230. };
  4231. // 搜索框回车
  4232. $scope.onSearch = function() {
  4233. $scope.tableParams.page(1);
  4234. $scope.tableParams.reload();
  4235. };
  4236. }]);
  4237. /**
  4238. * 客户不良品出库
  4239. */
  4240. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  4241. $scope.active = 'all';
  4242. $scope.agreedText = '全部';
  4243. $scope.dateZoneText = '一个月内';
  4244. $scope.condition = {dateZone: 1};
  4245. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4246. $scope.changeAgreed = function(agreed) {
  4247. $scope.condition.agreed = agreed;
  4248. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4249. $scope.condition.$agreedOpen = false;
  4250. };
  4251. $scope.changeDateZone = function(zone) {
  4252. $scope.condition.dateZone = zone;
  4253. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4254. $scope.condition.$dateZoneOpen = false;
  4255. };
  4256. $scope.setActive = function(state) {
  4257. if($scope.active != state) {
  4258. $scope.active = state;
  4259. if($scope.tableParams.page() == 1)
  4260. $scope.tableParams.reload();
  4261. else
  4262. $scope.tableParams.page(1);
  4263. }
  4264. };
  4265. var getService = function() {
  4266. return PurcBadOut;
  4267. };
  4268. $scope.tableParams = new ngTableParams({
  4269. page : 1,
  4270. count : 5,
  4271. sorting: {
  4272. date: 'desc'
  4273. }
  4274. }, {
  4275. total : 0,
  4276. counts: [5, 10, 25, 50],
  4277. getData : function($defer, params) {
  4278. $scope.loading = true;
  4279. var pageParams = params.url();
  4280. pageParams.keyword = $scope.keyword;
  4281. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4282. $scope.loading = false;
  4283. if(page) {
  4284. params.total(page.totalElement);
  4285. $defer.resolve(page.content);
  4286. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4287. }
  4288. }, function(response){
  4289. $scope.loading = false;
  4290. toaster.pop('error', '数据加载失败', response.data);
  4291. });
  4292. }
  4293. });
  4294. $scope.openDatePicker = function($event, item, openParam) {
  4295. $event.preventDefault();
  4296. $event.stopPropagation();
  4297. item[openParam] = !item[openParam];
  4298. };
  4299. // 搜索框回车
  4300. $scope.onSearch = function() {
  4301. $scope.tableParams.page(1);
  4302. $scope.tableParams.reload();
  4303. };
  4304. }]);
  4305. /**
  4306. * 客户MRB
  4307. */
  4308. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  4309. $scope.active = 'all';
  4310. $scope.agreedText = '全部';
  4311. $scope.dateZoneText = '一个月内';
  4312. $scope.condition = {dateZone: 1};
  4313. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4314. $scope.changeAgreed = function(agreed) {
  4315. $scope.condition.agreed = agreed;
  4316. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4317. $scope.condition.$agreedOpen = false;
  4318. };
  4319. $scope.changeDateZone = function(zone) {
  4320. $scope.condition.dateZone = zone;
  4321. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4322. $scope.condition.$dateZoneOpen = false;
  4323. };
  4324. $scope.setActive = function(state) {
  4325. if($scope.active != state) {
  4326. $scope.active = state;
  4327. if($scope.tableParams.page() == 1)
  4328. $scope.tableParams.reload();
  4329. else
  4330. $scope.tableParams.page(1);
  4331. }
  4332. };
  4333. var getService = function() {
  4334. return PurcMRB;
  4335. };
  4336. $scope.tableParams = new ngTableParams({
  4337. page : 1,
  4338. count : 5,
  4339. sorting: {
  4340. date: 'desc'
  4341. }
  4342. }, {
  4343. total : 0,
  4344. counts: [5, 10, 25, 50],
  4345. getData : function($defer, params) {
  4346. $scope.loading = true;
  4347. var pageParams = params.url();
  4348. pageParams.keyword = $scope.keyword;
  4349. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4350. $scope.loading = false;
  4351. if(page) {
  4352. params.total(page.totalElement);
  4353. $defer.resolve(page.content);
  4354. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4355. }
  4356. }, function(response){
  4357. $scope.loading = false;
  4358. toaster.pop('error', '数据加载失败', response.data);
  4359. });
  4360. }
  4361. });
  4362. $scope.openDatePicker = function($event, item, openParam) {
  4363. $event.preventDefault();
  4364. $event.stopPropagation();
  4365. item[openParam] = !item[openParam];
  4366. };
  4367. // 搜索框回车
  4368. $scope.onSearch = function() {
  4369. $scope.tableParams.page(1);
  4370. $scope.tableParams.reload();
  4371. };
  4372. }]);
  4373. /**
  4374. * 客户应付发票
  4375. */
  4376. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  4377. $scope.active = 'all';
  4378. $scope.dateZoneText = '不限';
  4379. $scope.condition = {dateZone: -1};
  4380. $scope.changeDateZone = function(zone) {
  4381. $scope.condition.dateZone = zone;
  4382. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4383. $scope.condition.$dateZoneOpen = false;
  4384. getDateCondition(zone, $scope.condition);
  4385. $scope.tableParams.reload();
  4386. };
  4387. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4388. $scope.setActive = function(state) {
  4389. if($scope.active != state) {
  4390. $scope.active = state;
  4391. if($scope.tableParams.page() == 1)
  4392. $scope.tableParams.reload();
  4393. else
  4394. $scope.tableParams.page(1);
  4395. }
  4396. };
  4397. var getService = function() {
  4398. return FaApBill;
  4399. };
  4400. $scope.tableParams = new ngTableParams({
  4401. page : 1,
  4402. count : 5,
  4403. sorting: {
  4404. date: 'desc'
  4405. }
  4406. }, {
  4407. total : 0,
  4408. counts: [5, 10, 25, 50],
  4409. getData : function($defer, params) {
  4410. $scope.loading = true;
  4411. var pageParams = params.url();
  4412. pageParams.searchFilter = { // 筛选条件
  4413. keyword: $scope.keyword,
  4414. fromDate: getDateTime($scope.condition.dateFrom),
  4415. endDate: getDateTime($scope.condition.dateTo)
  4416. };
  4417. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4418. $scope.loading = false;
  4419. if(page) {
  4420. params.total(page.totalElement);
  4421. $defer.resolve(page.content);
  4422. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  4423. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4424. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4425. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  4426. }
  4427. }, function(response){
  4428. $scope.loading = false;
  4429. toaster.pop('error', '数据加载失败', response.data);
  4430. });
  4431. }
  4432. });
  4433. $scope.openDatePicker = function($event, item, openParam) {
  4434. $event.preventDefault();
  4435. $event.stopPropagation();
  4436. item[openParam] = !item[openParam];
  4437. };
  4438. $scope.parseDate = function(dateStr) {
  4439. if(dateStr)
  4440. return Date.parse(dateStr, 'yyyy-MM-dd');
  4441. return new Date();
  4442. };
  4443. // 搜索框回车
  4444. $scope.onSearch = function() {
  4445. $scope.tableParams.page(1);
  4446. $scope.tableParams.reload();
  4447. };
  4448. // 选择查找日期
  4449. $scope.onDateCondition = function(){
  4450. $scope.tableParams.page(1);
  4451. $scope.tableParams.reload();
  4452. };
  4453. }]);
  4454. /**
  4455. * 应付对账单
  4456. */
  4457. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  4458. $scope.active = 'all';
  4459. $scope.dateZoneText = '不限';
  4460. $scope.condition = {dateZone: -1};
  4461. $scope.changeDateZone = function(zone) {
  4462. $scope.condition.dateZone = zone;
  4463. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4464. $scope.condition.$dateZoneOpen = false;
  4465. getDateCondition(zone, $scope.condition);
  4466. $scope.tableParams.reload();
  4467. };
  4468. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4469. $scope.setActive = function(state) {
  4470. if($scope.active != state) {
  4471. $scope.active = state;
  4472. if($scope.tableParams.page() == 1)
  4473. $scope.tableParams.reload();
  4474. else
  4475. $scope.tableParams.page(1);
  4476. }
  4477. };
  4478. var getService = function() {
  4479. return FaArCheck;
  4480. };
  4481. $scope.tableParams = new ngTableParams({
  4482. page : 1,
  4483. count : 5,
  4484. sorting: {
  4485. date: 'desc'
  4486. }
  4487. }, {
  4488. total : 0,
  4489. counts: [5, 10, 25, 50],
  4490. getData : function($defer, params) {
  4491. $scope.loading = true;
  4492. var pageParams = params.url();
  4493. pageParams.keyword = $scope.keyword;
  4494. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4495. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4496. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4497. $scope.loading = false;
  4498. if(page) {
  4499. params.total(page.totalElement);
  4500. $defer.resolve(page.content);
  4501. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4502. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4503. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4504. }
  4505. }, function(response){
  4506. $scope.loading = false;
  4507. toaster.pop('error', '数据加载失败', response.data);
  4508. });
  4509. }
  4510. });
  4511. $scope.openDatePicker = function($event, item, openParam) {
  4512. $event.preventDefault();
  4513. $event.stopPropagation();
  4514. item[openParam] = !item[openParam];
  4515. };
  4516. // 计算单据的商品总数
  4517. $scope.getTotalProd = function(check) {
  4518. var total = 0;
  4519. if(check.items) {
  4520. angular.forEach(check.items, function(value) {
  4521. total += value.qty;
  4522. });
  4523. }
  4524. return total;
  4525. };
  4526. // 搜索框回车
  4527. $scope.onSearch = function() {
  4528. $scope.tableParams.page(1);
  4529. $scope.tableParams.reload();
  4530. };
  4531. // 选择查找日期
  4532. $scope.onDateCondition = function(){
  4533. $scope.tableParams.page(1);
  4534. $scope.tableParams.reload();
  4535. };
  4536. }]);
  4537. // 应付对账单详情页
  4538. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', function($scope, $stateParams, FaArCheck, toaster, $state){
  4539. var loadData = function() {
  4540. FaArCheck.get({id: $stateParams.id}, function(data){
  4541. $scope.order = data;
  4542. $scope.loading = false;
  4543. });
  4544. };
  4545. loadData(); // 初始获取单据数据
  4546. $scope.onReplyClick = function(item, isAgreed) {
  4547. if(isAgreed) {// 同意确认
  4548. FaArCheck.agree({itemId: item.id}, {}, function(data){
  4549. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  4550. }, function(response){
  4551. toaster.pop('danger', '确认失败', response.data);
  4552. });
  4553. } else {// 不同意回复
  4554. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  4555. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  4556. }, function(response) {
  4557. toaster.pop('danger', '确认失败', response.data);
  4558. });
  4559. }
  4560. };
  4561. // 获取明细的回复记录
  4562. $scope.getReplies = function(item) {
  4563. if(!item.replies) {
  4564. FaArCheck.getReplies({itemId: item.id}, function(data) {
  4565. item.replies = data;
  4566. }, function(response) {
  4567. toaster.pop('danger', '获取对账记录失败', response.data);
  4568. });
  4569. }
  4570. };
  4571. }]);
  4572. //应收对账单列表
  4573. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  4574. $scope.dateZoneText = '不限';
  4575. $scope.condition = {dateZone: -1};
  4576. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4577. $scope.active = 'todo';
  4578. //打印 对账单
  4579. $scope.print = function(check) {
  4580. FaApCheck.printCount({id: check.id},{});//增加打印此次
  4581. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  4582. };
  4583. //状态
  4584. $scope.setActive = function (state){
  4585. if($scope.active != state) {
  4586. $scope.active = state;
  4587. if($scope.tableParams.page() == 1)
  4588. $scope.tableParams.reload();
  4589. else
  4590. $scope.tableParams.page(1);
  4591. }
  4592. };
  4593. $scope.changeDateZone = function(zone) {
  4594. $scope.condition.dateZone = zone;
  4595. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4596. $scope.condition.$dateZoneOpen = false;
  4597. getDateCondition(zone, $scope.condition);
  4598. $scope.tableParams.reload();
  4599. };
  4600. //获取应收对账单全部
  4601. $scope.tableParams = new ngTableParams({
  4602. page : 1,
  4603. count : 5,
  4604. sorting: {
  4605. recordDate: 'desc'
  4606. }
  4607. }, {
  4608. total : 0,
  4609. counts: [5, 10, 25, 50],
  4610. getData : function($defer, params) {
  4611. $scope.loading = true;
  4612. var pageParams = params.url();
  4613. pageParams.searchFilter = { // 筛选条件
  4614. keyword: $scope.keyword,
  4615. fromDate: getDateTime($scope.condition.dateFrom),
  4616. endDate: getDateTime($scope.condition.dateTo)
  4617. };
  4618. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  4619. $scope.loading = false;
  4620. if(page) {
  4621. params.total(page.totalElement);
  4622. $scope.data = $defer.resolve(page.content);
  4623. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  4624. }
  4625. }, function(response){
  4626. $scope.loading = false;
  4627. toaster.pop('error', '数据加载失败', response.data);
  4628. });
  4629. }
  4630. });
  4631. $scope.openDatePicker = function($event, item, openParam) {
  4632. $event.preventDefault();
  4633. $event.stopPropagation();
  4634. item[openParam] = !item[openParam];
  4635. };
  4636. // 计算单据的商品总数
  4637. $scope.getTotalProd = function(check) {
  4638. var total = 0;
  4639. if(check.items) {
  4640. angular.forEach(check.items, function(value) {
  4641. total += value.checkQty;
  4642. });
  4643. }
  4644. return total;
  4645. };
  4646. // 搜索框回车
  4647. $scope.onSearch = function() {
  4648. $scope.tableParams.page(1);
  4649. $scope.tableParams.reload();
  4650. };
  4651. // 选择查找日期
  4652. $scope.onDateCondition = function(){
  4653. $scope.tableParams.page(1);
  4654. $scope.tableParams.reload();
  4655. };
  4656. }]);
  4657. //应收对账单详情
  4658. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams',function($scope,toaster,FaApCheck,$stateParams){
  4659. $scope.haveSelected = true;
  4660. $scope.data = {};
  4661. //控制提交和删除按钮的显示
  4662. $scope.ifShow = true;
  4663. var loadData = function(){
  4664. FaApCheck.get({id:$stateParams.id},function(data){
  4665. $scope.data = data;
  4666. if($scope.data.status){
  4667. }else{
  4668. $scope.ifShow = true;
  4669. }
  4670. })
  4671. };
  4672. if($stateParams.id){
  4673. loadData();
  4674. }
  4675. $scope.haveSource = false;
  4676. //提交应收对账单
  4677. $scope.submitApCheck = function(){
  4678. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  4679. if(data.result) {
  4680. toaster.pop('success', '提示', '提交成功');
  4681. $scope.haveSelected = false;
  4682. window.location.href = '#/fa/apCheck';
  4683. }else {
  4684. $scope.haveSource = true;
  4685. loadData();
  4686. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  4687. $scope.haveSelected = true;
  4688. }
  4689. },function(){
  4690. $scope.loading = false;
  4691. toaster.pop('error', '提示', '更新已转数失败');
  4692. });
  4693. }
  4694. //删除应收对账单的同时更新来源表已转数
  4695. var updateYCheckQty = function(){
  4696. var sourceInfos = [];
  4697. angular.forEach($scope.data.items, function(item){
  4698. $scope.sourceInfo = {
  4699. sourceId: '',
  4700. sourceTable: '',
  4701. newYCheckQty: ''
  4702. };
  4703. $scope.sourceInfo.sourceId = item.sourceId;
  4704. $scope.sourceInfo.sourceTable = item.sourceTable;
  4705. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  4706. sourceInfos.push($scope.sourceInfo);
  4707. });
  4708. FaApCheck.update({}, sourceInfos, function(){
  4709. },function(response){
  4710. $scope.loading = false;
  4711. toaster.pop('error', '更新已转数失败', response.data);
  4712. });
  4713. }
  4714. //删除应收对账单
  4715. $scope.deleteApCheck = function(){
  4716. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  4717. updateYCheckQty();
  4718. toaster.pop('success','提示','删除成功');
  4719. },function(){
  4720. toaster.pop('error','提示','删除失败');
  4721. });
  4722. $scope.haveSelected = false;
  4723. }
  4724. //作废应收对账单
  4725. $scope.cancelApCheck = function(check) {
  4726. FaApCheck.cancel({id:check.id},function(data){
  4727. $scope.checkResult = false;
  4728. if(data.result) {
  4729. $scope.checkResult = true;
  4730. toaster.pop('success', '提示', '作废成功');
  4731. $scope.tableParams.reload();
  4732. }else{
  4733. toaster.pop('error', '提示', '作废失败');
  4734. }
  4735. },function(){
  4736. $scope.loading = false;
  4737. toaster.pop('error', '提示', '作废失败');
  4738. });
  4739. }
  4740. }]);
  4741. //未对账单据列表
  4742. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  4743. $scope.data = {};// 列表数据
  4744. $scope.loading = true;
  4745. // $scope.getData = function(){
  4746. // FaApCheck.getAll(function(data){
  4747. // $scope.data = data;
  4748. // angular.forEach($scope.data, function(item) {
  4749. // item:{
  4750. // $selected:true;
  4751. // }
  4752. // });
  4753. // $scope.loading = false;
  4754. // });
  4755. //
  4756. // }
  4757. document.getElementById('suuorname').focus();//光标默认在客户
  4758. // $scope.getData();
  4759. $scope.condition = {
  4760. $fromOpened:false
  4761. }
  4762. $scope.openDatePicker = function($event, item, openParam) {
  4763. $event.preventDefault();
  4764. $event.stopPropagation();
  4765. item[openParam] = !item[openParam];
  4766. }
  4767. //查找客户
  4768. $scope.searchCust = function(suuorname) {
  4769. var modalInstance = $modal.open({
  4770. animation: true,
  4771. templateUrl: 'static/tpl/index/fa/custInfo.html',
  4772. controller: 'SearchCustInfoCtrl',
  4773. resolve: {
  4774. suuorname: function() {
  4775. return suuorname;
  4776. }
  4777. }
  4778. });
  4779. modalInstance.result.then(function(suuorname){
  4780. $scope.suuorname = suuorname;
  4781. });
  4782. }
  4783. // 点击筛选根据条件选择数据
  4784. $scope.suuorname = '';
  4785. $scope.sdateFrom = '';
  4786. $scope.sdateTo = '';
  4787. $scope.vuuorname = '';
  4788. $scope.factory = '';
  4789. $scope.prodTitle = '';
  4790. $scope.prodSpec = '';
  4791. $scope.condition.uuorname = '';
  4792. $scope.condition.dateFrom = '';
  4793. $scope.condition.dateTo = '';
  4794. $scope.condition.venduuorname = '';
  4795. $scope.condition.factory = '';
  4796. $scope.condition.prodTitle = '';
  4797. $scope.condition.prodSpec = '';
  4798. $scope.searchOrder = function(check) {
  4799. angular.forEach($scope.data, function(item) {
  4800. $scope.checkboxes.checked = false;
  4801. item.$selected = false;
  4802. });
  4803. $scope.totalMoney = 0;
  4804. $scope.condition.uuorname = $scope.suuorname;
  4805. $scope.condition.factory = $scope.factory
  4806. $scope.condition.prodTitle = $scope.prodTitle;
  4807. $scope.condition.prodSpec = $scope.prodSpec;
  4808. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  4809. $scope.thisdatato = ($scope.sdateTo || 0);
  4810. if($scope.thisdatato != 0) {
  4811. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  4812. } else {
  4813. $scope.condition.dateTo = ($scope.sdateTo || 0);
  4814. }
  4815. $scope.condition.venduuorname = $scope.vuuorname;
  4816. // //物料名称和物料规格存在特殊符号,用|作分割符
  4817. // $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  4818. // + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  4819. // + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  4820. // + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  4821. // + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  4822. // $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4823. // $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4824. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  4825. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4826. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4827. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  4828. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  4829. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  4830. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  4831. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  4832. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4833. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4834. if($scope.suuorname == '') {
  4835. toaster.pop('info','提示', '请先选择客户');
  4836. document.getElementById('suuorname').focus();//光标默认在客户
  4837. } else {
  4838. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  4839. $scope.data = data;
  4840. angular.forEach($scope.data, function(item) {
  4841. item:{
  4842. $selected:true;
  4843. }
  4844. });
  4845. $scope.loading = false;
  4846. }, function(response) {
  4847. toaster.pop('error', '提示', response.data);
  4848. });
  4849. }
  4850. }
  4851. }
  4852. /**
  4853. * 点击勾选框,选中要转应收对账单的订单
  4854. * */
  4855. $scope.totalMoney = 0;
  4856. $scope.checkboxes = {
  4857. checked : false
  4858. };
  4859. // 点击勾选全部的复选框
  4860. $scope.checkAll = function(){
  4861. $scope.totalMoney = 0;
  4862. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  4863. var uuorname = $scope.suuorname;
  4864. var venduuorname = $scope.venduuorname;
  4865. var dateFrom = $scope.condition.dateFrom;
  4866. var dateTo = $scope.condition.dateTo;
  4867. var prodTitle = $scope.condition.prodTitle;
  4868. var prodSpec = $scope.condition.prodSpec;
  4869. var factory = $scope.condition.factory;
  4870. angular.forEach($scope.filteredData, function(item) {
  4871. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  4872. item.$selected = $scope.checkboxes.checked;
  4873. }
  4874. });
  4875. $scope.getTotalMoney();
  4876. };
  4877. //获取已选单据总金额
  4878. var total = true;
  4879. $scope.getTotalMoney = function(){
  4880. $scope.totalMoney = 0;
  4881. angular.forEach($scope.data, function(check) {
  4882. if(check.$selected){
  4883. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4884. }else{
  4885. $scope.totalMoney += 0;
  4886. }
  4887. });
  4888. }
  4889. // 点击其中一个明细的复选框
  4890. $scope.checkOne = function(check){
  4891. var result = true;
  4892. angular.forEach($scope.data, function(item) {
  4893. if(item.$selected != true){
  4894. result = false;
  4895. return;
  4896. }
  4897. });
  4898. $scope.checkboxes.checked = result;
  4899. };
  4900. $scope.haveSelected = false;
  4901. //生成应收对账单
  4902. $scope.createApCheck = function(){
  4903. //保存应收对账单主记录字段
  4904. $scope.apCheck = {
  4905. custUu: '',
  4906. custName: '',
  4907. enUu: '',
  4908. apDate: '',
  4909. beginDate: '',
  4910. endDate: '',
  4911. checkStatus: '未对账',
  4912. checkAmount: 0,
  4913. currency: '',
  4914. rate: '',
  4915. items: []
  4916. };
  4917. //保存来源单据相关信息
  4918. var sourceInfos = [];
  4919. //所允许的本次对账最大最小数量
  4920. $scope.data.maxThisCheckQty = 0;
  4921. $scope.data.minThisCheckQty = 0;
  4922. $scope.sameCust = true;
  4923. $scope.validQty = true;
  4924. $scope.loading = true;
  4925. angular.forEach($scope.data, function(check) {
  4926. //保存应收对账单明细行数据
  4927. $scope.item = {
  4928. inoutno: '',
  4929. inoutnodetno: '',
  4930. orderCode: '',
  4931. orderClass: '',
  4932. orderDetno: '',
  4933. price: '',
  4934. checkQty: '',
  4935. amount: '',
  4936. sourceId:'',
  4937. sourceTable:'',
  4938. oldYCheckQty:'',
  4939. status: 0,
  4940. receiveCode:'',
  4941. receiveName:'',
  4942. prodCode:'',
  4943. prodTitle:'',
  4944. prodSpec:'',
  4945. taxrate: '',
  4946. sendcode: '',
  4947. whname: '',
  4948. };
  4949. //应收对账单明细行来源表信息
  4950. $scope.sourceInfo = {
  4951. sourceId: '',
  4952. sourceTable: '',
  4953. newYCheckQty: ''
  4954. };
  4955. //此次对账后新的已转数
  4956. $scope.newYCheckQty = 0;
  4957. if(check.$selected == true) {
  4958. $scope.apCheck.custName = check.custName;
  4959. $scope.apCheck.enUu = check.enUu;
  4960. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4961. $scope.apCheck.apDate = check.piDate;
  4962. $scope.apCheck.rate = check.rate;
  4963. //必须是同一家客户才能生成对账单,否则提示错误
  4964. if($scope.apCheck.custUu == ''){
  4965. $scope.apCheck.custUu = check.custUu;
  4966. }else if($scope.apCheck.custUu !== check.custUu){
  4967. $scope.sameCust = false;
  4968. $scope.loading = false;
  4969. toaster.pop('error', '请选择同一家客户');
  4970. }
  4971. //必须是相同币别才能生成对账单,否则提示错误
  4972. if($scope.apCheck.currency == ''){
  4973. $scope.apCheck.currency = check.currency;
  4974. }else if($scope.apCheck.currency !== check.currency){
  4975. $scope.sameCust = false;
  4976. $scope.loading = false;
  4977. toaster.pop('error', '请选择同一种币别');
  4978. }
  4979. //本次对账数量必须小于总对账数量
  4980. if(check.qty > 0){
  4981. $scope.data.maxThisCheckQty = check.qty;
  4982. $scope.data.minThisCheckQty = 0;
  4983. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  4984. $scope.validQty = false;
  4985. $scope.loading = false;
  4986. toaster.pop('error','本次对账数量,填写有误!');
  4987. }
  4988. }else if(check.qty < 0){
  4989. $scope.data.maxThisCheckQty = 0;
  4990. $scope.data.minThisCheckQty = check.qty;
  4991. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  4992. $scope.validQty = false;
  4993. $scope.loading = false;
  4994. toaster.pop('error','本次对账数量,填写有误!');
  4995. }
  4996. }
  4997. //获取最小时间作为对账区间的起始时间
  4998. if($scope.apCheck.beginDate == ''){
  4999. $scope.apCheck.beginDate = check.piDate;
  5000. }else{
  5001. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  5002. }
  5003. //获取最大时间作为对账区间的截止时间
  5004. if($scope.apCheck.endDate == ''){
  5005. $scope.apCheck.endDate = check.piDate;
  5006. }else{
  5007. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  5008. }
  5009. //应收对账单明细行数据
  5010. $scope.item.orderCode = check.orderCode;
  5011. $scope.item.orderClass = check.piClass;
  5012. $scope.item.orderDetno = check.orderDetno;
  5013. $scope.item.price = check.orderPrice;
  5014. $scope.item.checkQty = check.thisCheckQty;
  5015. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5016. $scope.item.sourceId = check.sourceId;
  5017. $scope.item.sourceTable = check.sourceTable;
  5018. $scope.item.oldYCheckQty = check.yCheckQty;
  5019. $scope.item.prodCode = check.prodCode;
  5020. $scope.item.prodTitle = check.prodTitle;
  5021. $scope.item.prodSpec = check.prodSpec;
  5022. $scope.item.inoutno = check.inOutNo;
  5023. $scope.item.inoutnodetno = check.detno;
  5024. $scope.item.taxrate = check.taxrate;
  5025. $scope.item.receiveCode = check.receiveCode;
  5026. $scope.item.receiveName = check.receiveName;
  5027. $scope.item.sendcode = check.sendcode;
  5028. $scope.item.whname = check.whname;
  5029. //来源表相关信息
  5030. $scope.sourceInfo.sourceId = check.sourceId;
  5031. $scope.sourceInfo.sourceTable = check.sourceTable;
  5032. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  5033. sourceInfos.push($scope.sourceInfo);
  5034. $scope.apCheck.items.push($scope.item);
  5035. $scope.haveSelected = true;
  5036. }
  5037. });
  5038. //保存生成的应收对账单
  5039. $scope.saveApCheck = function(){
  5040. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  5041. $scope.loading = false;
  5042. toaster.pop('success', '成功', '生成应收对账成功');
  5043. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  5044. }, function(response){
  5045. toaster.pop('error', '生成对账单失败', response.data);
  5046. })
  5047. };
  5048. //如果是同一家客户,生成对账单的同时,关闭模态框
  5049. if($scope.sameCust && $scope.validQty) {
  5050. $scope.saveApCheck();
  5051. }
  5052. }
  5053. }]);
  5054. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
  5055. $scope.loading = true;
  5056. AccountEnterprise.get({}, function(data){
  5057. $scope.loading = false;
  5058. $scope.enterprise = data;
  5059. });
  5060. AccountEnterprise.growth({}, function(data){
  5061. if(data != null && data.length > 0) {
  5062. var growth = [], years = [];
  5063. angular.forEach(data, function(d){
  5064. var date = new Date(d.date), year = date.getFullYear();
  5065. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  5066. if(years.indexOf(year) == -1) {
  5067. years.push(year);
  5068. growth.push({year: year});
  5069. }
  5070. growth.push(d);
  5071. });
  5072. $scope.growth = growth;
  5073. }
  5074. });
  5075. // 更新企业信息
  5076. $scope.updateDetailInfo = function(){
  5077. $scope.loading = true;
  5078. AccountEnterprise.save($scope.enterprise, function(){
  5079. $scope.loading = false;
  5080. $scope.connectionEditing = false;
  5081. toaster.pop('success', '提示', '修改企业信息成功');
  5082. $state.reload();
  5083. }, function(response){
  5084. $scope.loading = false;
  5085. toaster.pop('error', '修改信息失败', response.data);
  5086. });
  5087. };
  5088. // 申请Saas
  5089. $scope.applySaas = function(){
  5090. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  5091. var modalInstance = $modal.open({
  5092. animation: true,
  5093. templateUrl: 'static/tpl/index/account/applySaas.html',
  5094. controller: 'ApplySaasCtrl',
  5095. resolve: {
  5096. enterprise: function(){return angular.copy($scope.enterprise);}
  5097. }
  5098. });
  5099. modalInstance.result.then(function(){
  5100. $state.reload();
  5101. }, function(){
  5102. });
  5103. } else {
  5104. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  5105. }
  5106. };
  5107. }]);
  5108. // 申请Saas Controller
  5109. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  5110. $scope.enterprise = enterprise;
  5111. $scope.checking = false;
  5112. $scope.$watch('enterprise.enSaasUrl', function(){
  5113. if($scope.enterprise.enSaasUrl) {
  5114. $http.get('signup/saasUrlEnable', {
  5115. params: {
  5116. enSaasUrl: $scope.enterprise.enSaasUrl
  5117. }
  5118. }).success(function(data){
  5119. if(data && data == 'true') {
  5120. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  5121. } else {
  5122. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  5123. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  5124. }
  5125. }).error(function(){
  5126. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  5127. $scope.enSaasUrlErrorInfo = '验证出错';
  5128. });
  5129. } else {
  5130. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  5131. }
  5132. });
  5133. var setSaasUrl = function(url) {
  5134. var index = url.indexOf('www.');
  5135. if(index != -1) {//包含www.
  5136. var substr = url.substring(index+4, url.length);
  5137. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  5138. } else {
  5139. $scope.enterprise.enSaasUrl = getHost(url);
  5140. }
  5141. };
  5142. // 解析获取网址的一级域名
  5143. var getHost = function(host){
  5144. var newhost;
  5145. var domain;
  5146. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  5147. for(var k in ArrDomain){
  5148. var re = eval('/\\' + ArrDomain[k] + '$/g');
  5149. newhost = host.replace(re, '');
  5150. if(newhost != host){
  5151. domain = ArrDomain[k];
  5152. break;
  5153. }
  5154. }
  5155. var hostar = newhost.split('.');
  5156. var s = hostar[hostar.length-1];
  5157. return s;
  5158. };
  5159. // 设置优企云服域名为官网网址一级域名
  5160. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  5161. $scope.apply = function(){
  5162. $scope.loading = true;
  5163. AccountEnterprise.applySaas({
  5164. enUU: $scope.enterprise.uu,
  5165. enSaasUrl: $scope.enterprise.enSaasUrl,
  5166. enAdminPassword: $scope.enterprise.enAdminPassword
  5167. }, {}, function(){
  5168. $scope.loading = false;
  5169. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  5170. $modalInstance.close();
  5171. }, function(response){
  5172. $scope.loading = false;
  5173. toaster.pop('error', '申请失败', response.data);
  5174. });
  5175. };
  5176. $scope.cancel = function () {
  5177. $modalInstance.dismiss();
  5178. };
  5179. }]);
  5180. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', 'AccountEnterprise', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert, AccountEnterprise){
  5181. $scope.editing = false;
  5182. $scope.loading = true;
  5183. $scope.enterprise = null;
  5184. AccountUser.findDistribute({},function(data) {
  5185. $scope.distributes = data;
  5186. },function(response) {
  5187. toaster.pop('error', '系统错误', response.data);
  5188. })
  5189. AuthenticationService.getAuthentication().success(function(data) {
  5190. $scope.loading = false;
  5191. $scope.user = data;
  5192. });
  5193. var users = [];
  5194. $scope.tableParams = new ngTableParams({
  5195. page : 1,
  5196. count : 5,
  5197. sorting: {
  5198. userName: 'asc'
  5199. }
  5200. }, {
  5201. total : 0,
  5202. counts: [15, 25, 50, 100],
  5203. getData : function($defer, params) {
  5204. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  5205. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  5206. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  5207. angular.forEach($scope.users,function(user){
  5208. AccountEnterprise.get({}, function(data){
  5209. $scope.loading = false;
  5210. $scope.enterprise = data;
  5211. });
  5212. });
  5213. params.total(orderedData.length);
  5214. $defer.resolve($scope.users);
  5215. }
  5216. });
  5217. var loadUsers = function() {
  5218. AccountUser.query({}, function(data){
  5219. users = data;
  5220. $scope.tableParams.reload();
  5221. $scope.loading = false;
  5222. });
  5223. };
  5224. loadUsers();
  5225. $scope.saveUser = function(){
  5226. $scope.loading = true;
  5227. AccountUser.update({}, $scope.user, function(data){
  5228. $scope.loading = false;
  5229. toaster.pop('success', '提示', '修改用户信息成功');
  5230. AuthenticationService.getAuthentication().success(function(data) {
  5231. $scope.user = data;
  5232. });
  5233. loadUsers();
  5234. $scope.editing = false;
  5235. }, function(reponse){
  5236. $scope.loading = false;
  5237. toaster.pop('error', '失败', reponse.data);
  5238. });
  5239. };
  5240. $scope.updatePassword = function(){
  5241. var modalInstance = $modal.open({
  5242. animation: true,
  5243. templateUrl: 'updatePassword.html',
  5244. controller: 'PasswordCtrl',
  5245. resolve: {
  5246. user: function(){return $scope.user;}
  5247. }
  5248. });
  5249. modalInstance.result.then(function(){
  5250. }, function(){
  5251. });
  5252. };
  5253. $scope.newUser = {};
  5254. //弹出添加用户模态框
  5255. $scope.addExistUser = function(){
  5256. var modalInstance = $modal.open({
  5257. animation :true,
  5258. templateUrl : 'static/tpl/index/account/addExistUser.html',
  5259. controller : 'AddExistUserCtrl'
  5260. });
  5261. modalInstance.result.then(function(){
  5262. $scope.userTelSuccess = false;
  5263. $scope.userTelError = false;
  5264. }, function(){
  5265. });
  5266. };
  5267. /**
  5268. * 添加未注册用户
  5269. */
  5270. $scope.addUser = function() {
  5271. $scope.adding = true;
  5272. AccountUser.save({}, $scope.newUser, function(){
  5273. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  5274. $scope.newUser = {userSex: 'M'};
  5275. loadUsers();
  5276. $scope.adding = false;
  5277. $scope.newUserForm.newUserTel.$setValidity('available', false);
  5278. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  5279. $scope.userTelSuccess = false;
  5280. $scope.userTelError = false;
  5281. $scope.userEmailSuccess = false;
  5282. $scope.userEmailError = false;
  5283. }, function(response){
  5284. toaster.pop('error', '错误', response.data);
  5285. });
  5286. };
  5287. /**
  5288. * 验证手机号是否可用
  5289. */
  5290. $scope.telValid = function(tel) {
  5291. if(tel) {
  5292. $http.get('account/user/telEnable', {
  5293. params: {
  5294. tel: tel
  5295. }
  5296. }).success(function(data){
  5297. data = eval(data);
  5298. if(data == true) {
  5299. $scope.newUserForm.newUserTel.$setValidity('available', true);
  5300. $scope.userTelSuccess = true;
  5301. $scope.userTelError = false;
  5302. }else{
  5303. $scope.newUserForm.newUserTel.$setValidity('available', false);
  5304. $scope.userTelError = true;
  5305. $scope.userTelSuccess = false;
  5306. if(tel.length == 11)
  5307. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  5308. }
  5309. }).error(function(){
  5310. $scope.userTelSuccess = false;
  5311. $scope.userTelError = true;
  5312. });
  5313. } else {
  5314. $scope.userTelSuccess = false;
  5315. $scope.userTelError = false;
  5316. }
  5317. };
  5318. /**
  5319. * 验证邮箱是否可用
  5320. */
  5321. $scope.emailValid = function(email) {
  5322. if(email) {
  5323. $http.get('account/user/emailEnable', {
  5324. params: {
  5325. email: email
  5326. }
  5327. }).success(function(data){
  5328. data = eval(data);
  5329. if(data == true) {
  5330. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  5331. $scope.userEmailSuccess = true;
  5332. $scope.userEmailError = false;
  5333. } else {
  5334. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  5335. $scope.userEmailError = true;
  5336. $scope.userEmailSuccess = false;
  5337. }
  5338. }).error(function(){
  5339. $scope.userEmailError = true;
  5340. $scope.userEmailSuccess = false;
  5341. });
  5342. } else {
  5343. $scope.userEmailError = false;
  5344. $scope.userEmailSuccess = false;
  5345. }
  5346. };
  5347. /**
  5348. * 删除用户
  5349. */
  5350. $scope.removeUser = function(user) {
  5351. new ngAlert({
  5352. title: '提示',
  5353. content: '确定删除用户(' + user.userName + ')吗?'
  5354. }, function(){
  5355. AccountUser.remove({uu: user.userUU}, function(){
  5356. toaster.pop('success', '提示', '用户删除成功。');
  5357. loadUsers();
  5358. }, function(response){
  5359. toaster.pop('error', '删除失败', response.data);
  5360. });
  5361. });
  5362. };
  5363. // 编辑用户的角色
  5364. $scope.editUserRole = function(user) {
  5365. var modalInstance = $modal.open({
  5366. animation: true,
  5367. templateUrl: 'static/tpl/index/account/user_role.html',
  5368. controller: 'UserRoleCtrl',
  5369. resolve: {
  5370. user: function() {
  5371. return user;
  5372. }
  5373. }
  5374. });
  5375. modalInstance.result.then(function(changed, checked){
  5376. if(changed) {
  5377. if(checked)
  5378. $scope.newUser.roles = checked;
  5379. else
  5380. loadUsers();
  5381. }
  5382. });
  5383. };
  5384. // 为用户分配角色(删除企业)
  5385. $scope.removeVendor = function(user) {
  5386. var resultRole = true;
  5387. angular.forEach(user.roles,function(role){
  5388. if(role.issys == 1) {
  5389. toaster.pop('error', '提示', '管理员无需分配客户');
  5390. resultRole = false;
  5391. return;
  5392. }
  5393. })
  5394. if(resultRole) {
  5395. var modalInstance = $modal.open({
  5396. animation: true,
  5397. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  5398. controller: 'RemoveVendorCtrl',
  5399. resolve: {
  5400. user: function() {
  5401. return user;
  5402. }
  5403. }
  5404. });
  5405. }
  5406. }
  5407. // 为用户分配角色(添加企业)
  5408. $scope.addVendor = function(user,isIssy) {
  5409. if(!isIssy) {
  5410. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  5411. return;
  5412. }
  5413. var resultRole = true;
  5414. angular.forEach(user.roles,function(role){
  5415. if(role.issys == 1) {
  5416. toaster.pop('error', '提示', '管理员无需分配客户');
  5417. resultRole = false;
  5418. return;
  5419. }
  5420. })
  5421. if(resultRole) {
  5422. var modalInstance = $modal.open({
  5423. animation: true,
  5424. templateUrl: 'static/tpl/index/account/add_vendor.html',
  5425. controller: 'AddVendorCtrl',
  5426. resolve: {
  5427. user: function() {
  5428. return user;
  5429. }
  5430. }
  5431. });
  5432. modalInstance.result.then(function(changed, checked){
  5433. if(changed) {
  5434. if(checked)
  5435. $scope.newUser.roles = checked;
  5436. else
  5437. loadUsers();
  5438. }
  5439. });
  5440. }
  5441. };
  5442. }]);
  5443. // 登录手机号码验证
  5444. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  5445. $scope.user = user;
  5446. $scope.cancel = function(){
  5447. $modalInstance.close();
  5448. }
  5449. /*$scope.loading = false;
  5450. $scope.btnState = false;
  5451. $scope.clicks = 0;
  5452. var storage = window.localStorage;
  5453. //手机验证码定时器
  5454. $scope.msgInfoError = false;
  5455. var setBtnTimeDown = function(value) {
  5456. if(value > 0) {
  5457. $scope.btnState = true;
  5458. $timeout(function() {
  5459. $scope.$apply(function(){
  5460. storage.setItem("btnTimes", $scope.btnTimes);
  5461. $scope.btnTimes --;
  5462. value --;
  5463. setBtnTimeDown (value);
  5464. });
  5465. }, 500);
  5466. }else{
  5467. $scope.btnState = false;
  5468. }
  5469. };
  5470. if(storage.btnTimes > 1){
  5471. $scope.btnTimes = storage.btnTimes;
  5472. setBtnTimeDown(storage.btnTimes)
  5473. }else{
  5474. storage.removeItem("btnTimes");
  5475. }
  5476. $scope.updateTel = function(phoneCode, userTel, uu){
  5477. $scope.loading = true;
  5478. $scope.msgInfoError = false;
  5479. $scope.result = false;
  5480. //更新联系方式
  5481. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  5482. $scope.loading = false;
  5483. $scope.msgInfoError2 = false;
  5484. $scope.result = true;
  5485. AuthenticationService.getAuthentication().success(function(data) {
  5486. $timeout(function(){
  5487. $modalInstance.dismiss();
  5488. window.location.reload();
  5489. }, 1000);
  5490. }).error(function(response) {
  5491. });
  5492. }, function(response){
  5493. $scope.loading = false;
  5494. $scope.msgInfoError2 = response;
  5495. });
  5496. };
  5497. //获取验证码
  5498. $scope.getPhoneCode = function(userTel){
  5499. var timeInfo = 10;
  5500. $scope.clicks ++;
  5501. $scope.timeInfo = timeInfo;
  5502. if($scope.clicks >= 5){
  5503. $scope.errorloading = true;
  5504. $scope.msgInfoSuccess = false;
  5505. $scope.msgInfoError = false;
  5506. }else{
  5507. $scope.loading = true;
  5508. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  5509. $scope.loading = false;
  5510. $scope.msgInfoSuccess = data.success;
  5511. $scope.sendMsg = data;
  5512. $scope.btnTimes = 60;
  5513. setBtnTimeDown($scope.btnTimes);
  5514. $scope.msgInfoError = false;
  5515. },function(response){
  5516. console.log(response);
  5517. $scope.loading = false;
  5518. $scope.msgInfoError = false;
  5519. $scope.sendCheckMsg = false;
  5520. $scope.msgInfoSuccess = true;
  5521. });
  5522. }
  5523. }; */
  5524. }]);
  5525. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5526. $scope.checkboxes = {
  5527. checked : false
  5528. };
  5529. $scope.loading = true;
  5530. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  5531. $scope.enters = data;
  5532. $scope.loading = false;
  5533. angular.forEach($scope.enters, function(item) {
  5534. item:{
  5535. $selected:true;
  5536. }
  5537. });
  5538. })
  5539. // 点击勾选全部的复选框
  5540. $scope.checkAll = function() {
  5541. angular.forEach($scope.enters, function(item) {
  5542. item.$selected = $scope.checkboxes.checked;
  5543. });
  5544. };
  5545. // 点击其中一个明细的复选框
  5546. $scope.checkOne = function(vendor){
  5547. var result = true;
  5548. angular.forEach($scope.enters, function(item) {
  5549. if(item.$selected != true){
  5550. result = false;
  5551. return;
  5552. }
  5553. });
  5554. $scope.checkboxes.checked = result;
  5555. };
  5556. $scope.close = function(save) {
  5557. var chooseResult = [];
  5558. if(save) {
  5559. if(user.userUU) {
  5560. angular.forEach($scope.enters, function(item, i) {
  5561. if(item.$selected) {
  5562. chooseResult.push(item.id);
  5563. }
  5564. });
  5565. if(chooseResult.length > 0) {
  5566. $scope.loading = true;
  5567. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  5568. $scope.loading = false;
  5569. toaster.pop('success', '提示', '删除成功');
  5570. $modalInstance.close(false);
  5571. }, function(response){
  5572. $scope.loading = false;
  5573. toaster.pop('error', '删除失败', response.data);
  5574. $modalInstance.close(false);
  5575. })
  5576. } else {
  5577. toaster.pop('error', '删除失败', "您未勾选任何记录");
  5578. }
  5579. } else {
  5580. $modalInstance.close(true, $scope.checkboxes.checked);
  5581. }
  5582. } else {
  5583. $modalInstance.close(false);
  5584. }
  5585. };
  5586. }]);
  5587. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5588. $scope.checkboxes = {
  5589. checked : false
  5590. };
  5591. $scope.loading = true;
  5592. AccountUser.findVendor({uu : user.userUU},function(data) {
  5593. $scope.enters = data;
  5594. $scope.loading = false;
  5595. // angular.forEach($scope.enters, function(item) {
  5596. // if(item.distribute) {
  5597. // item:{
  5598. // $selected:false;
  5599. // }
  5600. // } else {
  5601. // item:{
  5602. // $selected:true;
  5603. // }
  5604. // }
  5605. // });
  5606. })
  5607. // 点击勾选全部的复选框
  5608. $scope.checkAll = function() {
  5609. angular.forEach($scope.enters, function(item) {
  5610. item.distribute = $scope.checkboxes.checked;
  5611. });
  5612. };
  5613. // 点击其中一个明细的复选框
  5614. $scope.checkOne = function(vendor){
  5615. var result = true;
  5616. angular.forEach($scope.enters, function(item) {
  5617. if(item.distribute != true){
  5618. result = false;
  5619. return;
  5620. }
  5621. });
  5622. $scope.checkboxes.checked = result;
  5623. };
  5624. $scope.close = function(save) {
  5625. var chooseResult = [];
  5626. if(save) {
  5627. if(user.userUU) {
  5628. angular.forEach($scope.enters, function(item, i) {
  5629. // if(item.distribute) {
  5630. chooseResult.push(item);
  5631. // }
  5632. });
  5633. if(chooseResult.length > 0) {
  5634. $scope.loading = true;
  5635. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  5636. $scope.loading = false;
  5637. toaster.pop('success', '提示', '保存成功');
  5638. $modalInstance.close(false);
  5639. }, function(response){
  5640. $scope.loading = false;
  5641. toaster.pop('error', '保存失败', response.data);
  5642. $modalInstance.close(false);
  5643. })
  5644. } else {
  5645. toaster.pop('error', '保存失败', "您未勾选任何记录");
  5646. }
  5647. } else {
  5648. $modalInstance.close(true, $scope.checkboxes.checked);
  5649. }
  5650. } else {
  5651. $modalInstance.close(false);
  5652. }
  5653. };
  5654. }]);
  5655. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  5656. $scope.checked = [];
  5657. $scope.master = [];
  5658. AccountRole.query({}, function(data){
  5659. if(user && data) {
  5660. var rs = [], checked = [];
  5661. angular.forEach(user.roles, function(r){
  5662. rs.push(r.id);
  5663. });
  5664. angular.forEach(data, function(d){
  5665. if(rs.indexOf(d.id) > -1) {
  5666. d.$checked = true;
  5667. checked.push(d);
  5668. }
  5669. });
  5670. }
  5671. $scope.roles = data;
  5672. $scope.checked = checked;
  5673. $scope.master = angular.copy($scope.checked);
  5674. });
  5675. $scope.select = function(role) {
  5676. role.$checked = !role.$checked;
  5677. if(role.$checked) {
  5678. $scope.checked.push(role);
  5679. } else {
  5680. angular.forEach($scope.checked, function(c, i){
  5681. if(c.id == role.id)
  5682. $scope.checked.splice(i, 1);
  5683. });
  5684. }
  5685. };
  5686. $scope.isChanged = function() {
  5687. return !angular.equals($scope.master, $scope.checked);
  5688. };
  5689. $scope.close = function(save) {
  5690. if(save) {
  5691. if(user.userUU) {
  5692. user.roles = $scope.checked;
  5693. AccountUser.update({}, user, function(){
  5694. toaster.pop('success', '提示', '保存成功');
  5695. $modalInstance.close(true);
  5696. }, function(response){
  5697. toaster.pop('error', '保存失败', response.data);
  5698. });
  5699. } else {
  5700. $modalInstance.close(true, $scope.checked);
  5701. }
  5702. } else {
  5703. $modalInstance.close(false);
  5704. }
  5705. };
  5706. }]);
  5707. // 修改密码Controller
  5708. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5709. $scope.user = user;
  5710. $scope.checking = false;
  5711. //输入原密码后验证原密码是否正确
  5712. $scope.checkPassword = function(password) {
  5713. $scope.checking = true;
  5714. $scope.checkSuccess = false;
  5715. $scope.checkFailed = false;
  5716. AccountUser.checkPassword({password: password}, function(data){
  5717. $scope.checkSuccess = true;
  5718. $scope.checking = false;
  5719. $scope.checkFailed = false;
  5720. }, function(response){
  5721. $scope.checkFailed = true;
  5722. $scope.checking = false;
  5723. $scope.checkSuccess = false;
  5724. });
  5725. };
  5726. //修改密码
  5727. $scope.ok = function () {
  5728. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  5729. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  5730. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  5731. $scope.user.password = null;
  5732. $scope.user.newPassword = null;
  5733. $scope.user.newPassword1 = null;
  5734. $scope.checking = false;
  5735. $scope.checkSuccess = false;
  5736. $scope.checkFailed = false;
  5737. }, function(response){
  5738. toaster.pop('error', '错误', response.data);
  5739. });
  5740. } else {
  5741. toaster.pop('error', '错误', '重复密码不一致');
  5742. }
  5743. };
  5744. $scope.cancel = function () {
  5745. $modalInstance.dismiss();
  5746. };
  5747. }]);
  5748. /*
  5749. * 绑定用户到企业
  5750. */
  5751. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout){
  5752. $scope.searching = false;
  5753. //根据输入的内容查找用户
  5754. $scope.searchUser = function(keyWord) {
  5755. $scope.searching = true;
  5756. $scope.searchSuccess = false;
  5757. $scope.searchFailed = false;
  5758. $scope.illegalError = false;
  5759. $scope.reBindError = false;
  5760. $scope.bindSuccess = false;
  5761. $scope.okDisabled = false;
  5762. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  5763. $scope.searchSuccess = true;
  5764. $scope.searchFailed = false;
  5765. $scope.user = data; //查询到的用户
  5766. }, function(response){
  5767. $scope.searchSuccess = false;
  5768. $scope.searchFailed = true;
  5769. });
  5770. };
  5771. //确认绑定
  5772. $scope.ok = function (keyWord) {
  5773. AuthenticationService.getAuthentication().success(function(data) {
  5774. $scope.currentUser = data; //当前登录的用户(管理员)
  5775. //不可自己绑定自己
  5776. if($scope.currentUser.userUU == $scope.user.userUU){
  5777. $scope.illegalError = true;
  5778. $scope.okDisabled = true;
  5779. return false;
  5780. }
  5781. //用户未绑定到任何企业时
  5782. if(!$scope.user.enterprises){
  5783. //正常绑定
  5784. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  5785. $scope.bindSuccess = true; //绑定成功
  5786. $scope.okDisabled = true;
  5787. }, function(response){
  5788. });
  5789. return true;
  5790. }
  5791. //用户已绑定到某些企业时
  5792. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  5793. if($scope.currentUser.enterprises[i].current){
  5794. for(var j = 0; j < $scope.user.enterprises.length; j++){
  5795. //该用户已绑定到当前企业,不可重复绑定
  5796. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  5797. $scope.reBindError = true;
  5798. $scope.okDisabled = true;
  5799. return false;
  5800. }
  5801. }
  5802. //该用户未绑定到当前企业,可以进行绑定
  5803. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  5804. $scope.bindSuccess = true; //绑定成功
  5805. $scope.okDisabled = true;
  5806. }, function(response){
  5807. console.log("绑定失败!");
  5808. });
  5809. }
  5810. }
  5811. });
  5812. $timeout(function() {
  5813. $modalInstance.close(true);
  5814. }, 500);
  5815. };
  5816. $scope.cancel = function () {
  5817. $modalInstance.dismiss();
  5818. };
  5819. }]);
  5820. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  5821. $scope.erpParams = new ngTableParams({
  5822. page : 1,
  5823. count : 5,
  5824. sorting: {
  5825. time: 'desc'
  5826. }
  5827. }, {
  5828. total : 0,
  5829. counts: [5, 10, 25, 50],
  5830. getData : function($defer, params) {
  5831. $scope.loading = true;
  5832. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  5833. $scope.loading = false;
  5834. if(page) {
  5835. params.total(page.totalElements);
  5836. $defer.resolve(page.content);
  5837. }
  5838. }, function(response){
  5839. $scope.loading = false;
  5840. toaster.pop('error', '数据加载失败', response.data);
  5841. });
  5842. }
  5843. });
  5844. $scope.usageParams = new ngTableParams({
  5845. page : 1,
  5846. count : 5,
  5847. sorting: {
  5848. time: 'desc'
  5849. }
  5850. }, {
  5851. total : 0,
  5852. counts: [5, 10, 25, 50],
  5853. getData : function($defer, params) {
  5854. $scope.loading = true;
  5855. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  5856. $scope.loading = false;
  5857. if(page) {
  5858. params.total(page.totalElements);
  5859. $defer.resolve(page.content);
  5860. }
  5861. }, function(response){
  5862. $scope.loading = false;
  5863. toaster.pop('error', '数据加载失败', response.data);
  5864. });
  5865. }
  5866. });
  5867. }]);
  5868. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  5869. AccountResource.query({}, function(data){
  5870. if(data && data.length > 0) {
  5871. data[0].$open = true;
  5872. }
  5873. $scope.resources = data;
  5874. });
  5875. }]);
  5876. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  5877. $scope.roles = {};
  5878. var getData = function() {
  5879. AccountRole.query({}, function(data){
  5880. var defaults = [], custom = [];
  5881. angular.forEach(data, function(d){
  5882. if(d.isdefault == 1)
  5883. defaults.push(d);
  5884. else
  5885. custom.push(d);
  5886. });
  5887. $scope.roles = {defaults: defaults, custom: custom};
  5888. });
  5889. };
  5890. getData();
  5891. $scope.editRole = function(role){
  5892. var modalInstance = $modal.open({
  5893. animation: true,
  5894. templateUrl: 'static/tpl/index/account/role_detail.html',
  5895. controller: 'RoleEditCtrl',
  5896. resolve: {
  5897. role: function() {
  5898. return role;
  5899. }
  5900. }
  5901. });
  5902. modalInstance.result.then(function(added){
  5903. added && (getData());
  5904. });
  5905. };
  5906. }]);
  5907. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
  5908. $scope.role = role;
  5909. $scope.master = angular.copy($scope.role);
  5910. var isNew = role == null;
  5911. $scope.cancel = function() {
  5912. $modalInstance.close(false);
  5913. };
  5914. AccountResource.query({}, function(data){
  5915. if(data && data.length > 0) {
  5916. if(role && role.resourceItems) {
  5917. var rs = [];// 已分配的资源的id
  5918. angular.forEach(role.resourceItems, function(item){
  5919. rs.push(item.id);
  5920. });
  5921. angular.forEach(data, function(resource){
  5922. var c = 0;
  5923. angular.forEach(resource.items, function(item){
  5924. if(rs.indexOf(item.id) > -1) {
  5925. item.$checked = true;
  5926. c += 1;
  5927. }
  5928. });
  5929. resource.$checked = c == resource.items.length;
  5930. });
  5931. }
  5932. $scope.resourceItems = data[0].items;
  5933. data[0].$active = true;
  5934. }
  5935. $scope.resources = data;
  5936. $timeout(function(){
  5937. angular.forEach($scope.resources, function(resource){
  5938. var c = 0;
  5939. angular.forEach(resource.items, function(item){
  5940. item.$checked && (c+=1);
  5941. });
  5942. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5943. });
  5944. }, 100);
  5945. });
  5946. $scope.onItemClick = function(resource) {
  5947. $scope.resourceItems = resource.items;
  5948. angular.forEach($scope.resources, function(r){
  5949. r.$active = false;
  5950. });
  5951. resource.$active = true;
  5952. };
  5953. var getChecked = function() {
  5954. var items = [];
  5955. angular.forEach($scope.resources, function(resource){
  5956. angular.forEach(resource.items, function(item){
  5957. item.$checked && (items.push(item));
  5958. });
  5959. });
  5960. $scope.role.resourceItems = items;
  5961. };
  5962. $scope.onResourceChange = function(resource) {
  5963. angular.forEach(resource.items, function(item){
  5964. item.$checked = resource.$checked;
  5965. });
  5966. getChecked();
  5967. };
  5968. $scope.onItemChange = function() {
  5969. angular.forEach($scope.resources, function(resource){
  5970. if(resource.$active) {
  5971. var c = 0;
  5972. angular.forEach(resource.items, function(item){
  5973. item.$checked && (c+=1);
  5974. });
  5975. resource.$checked = (c == resource.items.length);
  5976. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5977. }
  5978. });
  5979. getChecked();
  5980. };
  5981. $scope.isChanged = function(formData) {
  5982. if(!$scope.master)
  5983. return true;
  5984. return !angular.equals(formData, $scope.master);
  5985. };
  5986. $scope.save = function() {
  5987. $scope.master = angular.copy($scope.role);
  5988. AccountRole.save($scope.master, function(){
  5989. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  5990. $modalInstance.close(true);
  5991. }, function(response){
  5992. toaster.pop('error', '错误', response.data);
  5993. });
  5994. };
  5995. $scope.del = function() {
  5996. new ngAlert({
  5997. title: '提示',
  5998. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  5999. }, function(){
  6000. AccountRole.remove({id: role.id}, function(){
  6001. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  6002. $modalInstance.close(true);
  6003. }, function(response){
  6004. toaster.pop('error', '错误', response.data);
  6005. });
  6006. })
  6007. };
  6008. }]);
  6009. /**
  6010. * 委外订单
  6011. */
  6012. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  6013. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  6014. $scope.active = 'todo';
  6015. $scope.dateZoneText = '不限';
  6016. $scope.condition = {dateZone: -1};
  6017. $scope.changeDateZone = function(zone) {
  6018. $scope.condition.dateZone = zone;
  6019. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6020. $scope.condition.$dateZoneOpen = false;
  6021. getDateCondition(zone, $scope.condition);
  6022. $scope.tableParams.reload();
  6023. };
  6024. $scope.setActive = function(state) {
  6025. if($scope.active != state) {
  6026. $scope.active = state;
  6027. if($scope.tableParams.page() == 1)
  6028. $scope.tableParams.reload();
  6029. else
  6030. $scope.tableParams.page(1);
  6031. }
  6032. };
  6033. var getService = function() {
  6034. return MakeOrder;
  6035. };
  6036. $scope.tableParams = new ngTableParams({
  6037. page : 1,
  6038. count : 5,
  6039. sorting: {
  6040. date: 'desc'
  6041. }
  6042. }, {
  6043. total : 0,
  6044. counts: [5, 10, 25, 50],
  6045. getData : function($defer, params) {
  6046. $scope.loading = true;
  6047. var pageParams = params.url();
  6048. pageParams.searchFilter = {};
  6049. pageParams.searchFilter.keyword = $scope.keyword;
  6050. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6051. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6052. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6053. $scope.loading = false;
  6054. if(page) {
  6055. params.total(page.totalElement);
  6056. $defer.resolve(page.content);
  6057. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6058. }
  6059. }, function(response){
  6060. $scope.loading = false;
  6061. toaster.pop('error', '数据加载失败', response.data);
  6062. });
  6063. }
  6064. });
  6065. $scope.getOrderTotal = function(items) {
  6066. var sum = 0;
  6067. angular.forEach(items, function(item){
  6068. sum += item.qty * item.price;
  6069. });
  6070. return sum;
  6071. };
  6072. $scope.openDatePicker = function($event, item, openParam) {
  6073. $event.preventDefault();
  6074. $event.stopPropagation();
  6075. item[openParam] = !item[openParam];
  6076. };
  6077. $scope.parseDate = function(dateStr) {
  6078. if(dateStr)
  6079. return Date.parse(dateStr, 'yyyy-MM-dd');
  6080. return new Date();
  6081. };
  6082. // 打开回复
  6083. $scope.openReply = function(order) {
  6084. if(!order.reply) {
  6085. order.reply = {
  6086. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6087. delivery: order.delivery
  6088. }
  6089. }
  6090. order.$editing = true;
  6091. };
  6092. // 关闭回复
  6093. $scope.closeReply = function(order) {
  6094. order.$editing = false;
  6095. }
  6096. // 搜索框回车
  6097. $scope.onSearch = function() {
  6098. $scope.tableParams.page(1);
  6099. $scope.tableParams.reload();
  6100. };
  6101. // 选择查找日期
  6102. $scope.onDateCondition = function(){
  6103. $scope.tableParams.page(1);
  6104. $scope.tableParams.reload();
  6105. };
  6106. // 点击回复
  6107. $scope.onReplyClick = function(order, inverse) {
  6108. if(order.reply) {
  6109. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6110. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6111. return;
  6112. }
  6113. var reply = angular.copy(order.reply);
  6114. if(reply.delivery) {
  6115. if(typeof reply.delivery == 'object')
  6116. reply.delivery = reply.delivery.getTime();
  6117. } else {
  6118. reply.delivery = order.delivery;
  6119. }
  6120. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6121. $scope.loading = true;
  6122. MakeOrder.reply({orderId: order.id}, reply, function(){
  6123. $scope.loading = false;
  6124. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6125. $scope.tableParams.reload();
  6126. }, function(response){
  6127. $scope.loading = false;
  6128. toaster.pop('error', '回复失败', response.data);
  6129. });
  6130. }
  6131. };
  6132. //委外加工单
  6133. $scope.print = function(order) {
  6134. MakeOrder.printCount({id: order.id},{});//增加打印此次
  6135. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  6136. };
  6137. // 获取回复记录
  6138. $scope.getReply = function(order) {
  6139. if(!order.replies) {
  6140. MakeOrder.getReply({orderId: order.id}, function(replies){
  6141. order.replies = replies;
  6142. });
  6143. }
  6144. };
  6145. }]);
  6146. /**
  6147. * 委外加工单详细
  6148. */
  6149. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOrder, toaster, ReportService){
  6150. var loadData = function() {
  6151. MakeOrder.get({id: $stateParams.id}, function(data){
  6152. $scope.order = data;
  6153. var sum = $scope.order.qty * $scope.order.price;
  6154. $scope.order.total = sum;
  6155. $scope.loading = false;
  6156. });
  6157. };
  6158. loadData();
  6159. // 获取回复记录
  6160. $scope.getReply = function(item) {
  6161. if(!item.replies) {
  6162. MakeOrder.getReply({orderId: item.id}, function(replies){
  6163. item.replies = replies;
  6164. });
  6165. }
  6166. };
  6167. $scope.openDatePicker = function($event, item, openParam) {
  6168. $event.preventDefault();
  6169. $event.stopPropagation();
  6170. item[openParam] = !item[openParam];
  6171. };
  6172. // 点击回复
  6173. $scope.onReplyClick = function(order, inverse) {
  6174. if(order.reply) {
  6175. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6176. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6177. return;
  6178. }
  6179. var reply = angular.copy(order.reply);
  6180. if(reply.delivery) {
  6181. if(typeof reply.delivery == 'object')
  6182. reply.delivery = reply.delivery.getTime();
  6183. } else {
  6184. reply.delivery = order.delivery;
  6185. }
  6186. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6187. $scope.loading = true;
  6188. MakeOrder.reply({orderId: order.id}, reply, function(){
  6189. $scope.loading = false;
  6190. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6191. loadData();
  6192. }, function(response){
  6193. $scope.loading = false;
  6194. toaster.pop('error', '回复失败', response.data);
  6195. });
  6196. }
  6197. };
  6198. // 打开回复
  6199. $scope.openReply = function(order) {
  6200. if(!order.reply) {
  6201. order.reply = {
  6202. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6203. delivery: order.delivery
  6204. }
  6205. }
  6206. order.$editing = true;
  6207. };
  6208. // 关闭回复
  6209. $scope.closeReply = function(order) {
  6210. order.$editing = false;
  6211. }
  6212. // 委外订单
  6213. $scope.print = function(order) {
  6214. MakeOrder.printCount({id: order.id},{});//增加打印此次
  6215. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  6216. };
  6217. }]);
  6218. /**
  6219. * 客户委外验收
  6220. */
  6221. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  6222. $scope.active = 'all';
  6223. $scope.agreedText = '全部';
  6224. $scope.dateZoneText = '一个月内';
  6225. $scope.condition = {dateZone: 1};
  6226. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6227. $scope.changeAgreed = function(agreed) {
  6228. $scope.condition.agreed = agreed;
  6229. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6230. $scope.condition.$agreedOpen = false;
  6231. };
  6232. $scope.changeDateZone = function(zone) {
  6233. $scope.condition.dateZone = zone;
  6234. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6235. $scope.condition.$dateZoneOpen = false;
  6236. getDateCondition(zone, $scope.condition);
  6237. $scope.tableParams.reload();
  6238. };
  6239. $scope.setActive = function(state) {
  6240. if($scope.active != state) {
  6241. $scope.active = state;
  6242. if($scope.tableParams.page() == 1)
  6243. $scope.tableParams.reload();
  6244. else
  6245. $scope.tableParams.page(1);
  6246. }
  6247. };
  6248. var getService = function() {
  6249. return MakeAccept;
  6250. };
  6251. $scope.tableParams = new ngTableParams({
  6252. page : 1,
  6253. count : 5,
  6254. sorting: {
  6255. date: 'desc'
  6256. }
  6257. }, {
  6258. total : 0,
  6259. counts: [5, 10, 25, 50],
  6260. getData : function($defer, params) {
  6261. $scope.loading = true;
  6262. var pageParams = params.url();
  6263. pageParams.searchFilter = {};
  6264. pageParams.searchFilter.keyword = $scope.keyword;
  6265. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6266. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6267. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6268. $scope.loading = false;
  6269. if(page) {
  6270. params.total(page.totalElement);
  6271. $defer.resolve(page.content);
  6272. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6273. }
  6274. }, function(response){
  6275. $scope.loading = false;
  6276. toaster.pop('error', '数据加载失败', response.data);
  6277. });
  6278. }
  6279. });
  6280. $scope.openDatePicker = function($event, item, openParam) {
  6281. $event.preventDefault();
  6282. $event.stopPropagation();
  6283. item[openParam] = !item[openParam];
  6284. };
  6285. // 搜索框回车
  6286. $scope.onSearch = function() {
  6287. $scope.tableParams.page(1);
  6288. $scope.tableParams.reload();
  6289. };
  6290. // 选择查找日期
  6291. $scope.onDateCondition = function(){
  6292. $scope.tableParams.page(1);
  6293. $scope.tableParams.reload();
  6294. };
  6295. }]);
  6296. /**
  6297. * 客户委外验退
  6298. */
  6299. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  6300. $scope.active = 'all';
  6301. $scope.agreedText = '全部';
  6302. $scope.dateZoneText = '一个月内';
  6303. $scope.condition = {dateZone: 1};
  6304. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6305. $scope.changeAgreed = function(agreed) {
  6306. $scope.condition.agreed = agreed;
  6307. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6308. $scope.condition.$agreedOpen = false;
  6309. };
  6310. $scope.changeDateZone = function(zone) {
  6311. $scope.condition.dateZone = zone;
  6312. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6313. $scope.condition.$dateZoneOpen = false;
  6314. getDateCondition(zone, $scope.condition);
  6315. $scope.tableParams.reload();
  6316. };
  6317. $scope.setActive = function(state) {
  6318. if($scope.active != state) {
  6319. $scope.active = state;
  6320. if($scope.tableParams.page() == 1)
  6321. $scope.tableParams.reload();
  6322. else
  6323. $scope.tableParams.page(1);
  6324. }
  6325. };
  6326. var getService = function() {
  6327. return MakeReturn;
  6328. };
  6329. $scope.tableParams = new ngTableParams({
  6330. page : 1,
  6331. count : 5,
  6332. sorting: {
  6333. date: 'desc'
  6334. }
  6335. }, {
  6336. total : 0,
  6337. counts: [5, 10, 25, 50],
  6338. getData : function($defer, params) {
  6339. $scope.loading = true;
  6340. var pageParams = params.url();
  6341. pageParams.searchFilter = {};
  6342. pageParams.searchFilter.keyword = $scope.keyword;
  6343. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6344. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6345. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6346. $scope.loading = false;
  6347. if(page) {
  6348. params.total(page.totalElement);
  6349. $defer.resolve(page.content);
  6350. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6351. }
  6352. }, function(response){
  6353. $scope.loading = false;
  6354. toaster.pop('error', '数据加载失败', response.data);
  6355. });
  6356. }
  6357. });
  6358. $scope.openDatePicker = function($event, item, openParam) {
  6359. $event.preventDefault();
  6360. $event.stopPropagation();
  6361. item[openParam] = !item[openParam];
  6362. };
  6363. // 搜索框回车
  6364. $scope.onSearch = function() {
  6365. $scope.tableParams.page(1);
  6366. $scope.tableParams.reload();
  6367. };
  6368. // 选择查找日期
  6369. $scope.onDateCondition = function(){
  6370. $scope.tableParams.page(1);
  6371. $scope.tableParams.reload();
  6372. };
  6373. }]);
  6374. /**
  6375. * 委外加工变更
  6376. */
  6377. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  6378. $scope.active = 'all';
  6379. $scope.agreedText = '全部';
  6380. $scope.dateZoneText = '一个月内';
  6381. $scope.condition = {dateZone: 1};
  6382. $scope.changeAgreed = function(agreed) {
  6383. $scope.condition.agreed = agreed;
  6384. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6385. $scope.condition.$agreedOpen = false;
  6386. };
  6387. $scope.changeDateZone = function(zone) {
  6388. $scope.condition.dateZone = zone;
  6389. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6390. $scope.condition.$dateZoneOpen = false;
  6391. getDateCondition(zone, $scope.condition);
  6392. $scope.tableParams.reload();
  6393. };
  6394. $scope.setActive = function(state) {
  6395. if($scope.active != state) {
  6396. $scope.active = state;
  6397. if($scope.tableParams.page() == 1)
  6398. $scope.tableParams.reload();
  6399. else
  6400. $scope.tableParams.page(1);
  6401. }
  6402. };
  6403. var getService = function() {
  6404. return MakeChange;
  6405. };
  6406. $scope.tableParams = new ngTableParams({
  6407. page : 1,
  6408. count : 5,
  6409. sorting: {
  6410. orderChangeDate: 'desc'
  6411. }
  6412. }, {
  6413. total : 0,
  6414. counts: [5, 10, 25, 50],
  6415. getData : function($defer, params) {
  6416. $scope.loading = true;
  6417. var pageParams = params.url();
  6418. pageParams.searchFilter = {};
  6419. pageParams.searchFilter.keyword = $scope.keyword;
  6420. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6421. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6422. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6423. $scope.loading = false;
  6424. if(page) {
  6425. params.total(page.totalElement);
  6426. $defer.resolve(page.content);
  6427. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6428. }
  6429. }, function(response){
  6430. $scope.loading = false;
  6431. toaster.pop('error', '数据加载失败', response.data);
  6432. });
  6433. }
  6434. });
  6435. $scope.openDatePicker = function($event, item, openParam) {
  6436. $event.preventDefault();
  6437. $event.stopPropagation();
  6438. item[openParam] = !item[openParam];
  6439. };
  6440. // 打开回复
  6441. $scope.openReply = function(change) {
  6442. change.$editing = true;
  6443. };
  6444. // 关闭回复
  6445. $scope.closeReply = function(change) {
  6446. change.$editing = false;
  6447. }
  6448. // 确定回复
  6449. $scope.onReplyClick = function(change) {
  6450. if(change.$agreed) {
  6451. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6452. $scope.loading = true;
  6453. MakeChange.reply({itemId: change.id}, reply, function(){
  6454. $scope.loading = false;
  6455. toaster.pop('info', '提示', '回复成功');
  6456. $scope.tableParams.reload();
  6457. }, function(response){
  6458. $scope.loading = false;
  6459. toaster.pop('error', '回复失败', response.data);
  6460. });
  6461. }
  6462. };
  6463. // 搜索框回车
  6464. $scope.onSearch = function() {
  6465. $scope.tableParams.page(1);
  6466. $scope.tableParams.reload();
  6467. };
  6468. // 选择查找日期
  6469. $scope.onDateCondition = function(){
  6470. $scope.tableParams.page(1);
  6471. $scope.tableParams.reload();
  6472. };
  6473. }]);
  6474. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', function($scope, $stateParams, MakeChange, toaster){
  6475. var loadData = function() {
  6476. MakeChange.get({id: $stateParams.id}, function(data){
  6477. $scope.change = data;
  6478. });
  6479. };
  6480. loadData();
  6481. $scope.openDatePicker = function($event, item, openParam) {
  6482. $event.preventDefault();
  6483. $event.stopPropagation();
  6484. item[openParam] = !item[openParam];
  6485. };
  6486. $scope.onReplyClick = function(change) {
  6487. if(change.$agreed) {
  6488. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6489. MakeChange.reply({itemId: change.id}, reply, function(){
  6490. toaster.pop('info', '提示', '回复成功');
  6491. loadData();
  6492. }, function(response){
  6493. toaster.pop('error', '回复失败', response.data);
  6494. });
  6495. }
  6496. };
  6497. }]);
  6498. /**
  6499. * 委外加工
  6500. */
  6501. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  6502. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  6503. $scope.active = 'all';
  6504. $scope.agreedText = '全部';
  6505. $scope.dateZoneText = '一个月内';
  6506. $scope.condition = {dateZone: 1};
  6507. $scope.changeAgreed = function(agreed) {
  6508. $scope.condition.agreed = agreed;
  6509. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6510. $scope.condition.$agreedOpen = false;
  6511. };
  6512. $scope.changeDateZone = function(zone) {
  6513. $scope.condition.dateZone = zone;
  6514. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6515. $scope.condition.$dateZoneOpen = false;
  6516. getDateCondition(zone, $scope.condition);
  6517. $scope.tableParams.reload();
  6518. };
  6519. $scope.setActive = function(state) {
  6520. if($scope.active != state) {
  6521. $scope.active = state;
  6522. if($scope.tableParams.page() == 1)
  6523. $scope.tableParams.reload();
  6524. else
  6525. $scope.tableParams.page(1);
  6526. }
  6527. };
  6528. var getService = function() {
  6529. return MakeOutOrder;
  6530. };
  6531. $scope.tableParams = new ngTableParams({
  6532. page : 1,
  6533. count : 5,
  6534. sorting: {
  6535. date: 'desc'
  6536. }
  6537. }, {
  6538. total : 0,
  6539. counts: [5, 10, 25, 50],
  6540. getData : function($defer, params) {
  6541. $scope.loading = true;
  6542. var pageParams = params.url();
  6543. pageParams.searchFilter = {};
  6544. pageParams.searchFilter.keyword = $scope.keyword;
  6545. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6546. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6547. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6548. $scope.loading = false;
  6549. if(page) {
  6550. params.total(page.totalElement);
  6551. $defer.resolve(page.content);
  6552. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6553. }
  6554. }, function(response){
  6555. $scope.loading = false;
  6556. toaster.pop('error', '数据加载失败', response.data);
  6557. });
  6558. }
  6559. });
  6560. $scope.openDatePicker = function($event, item, openParam) {
  6561. $event.preventDefault();
  6562. $event.stopPropagation();
  6563. item[openParam] = !item[openParam];
  6564. };
  6565. // 打开回复
  6566. $scope.openReply = function(change) {
  6567. change.$editing = true;
  6568. };
  6569. // 关闭回复
  6570. $scope.closeReply = function(change) {
  6571. change.$editing = false;
  6572. }
  6573. // 确定回复
  6574. $scope.onReplyClick = function(change) {
  6575. if(change.$agreed) {
  6576. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6577. $scope.loading = true;
  6578. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  6579. $scope.loading = false;
  6580. toaster.pop('info', '提示', '回复成功');
  6581. $scope.tableParams.reload();
  6582. }, function(response){
  6583. $scope.loading = false;
  6584. toaster.pop('error', '回复失败', response.data);
  6585. });
  6586. }
  6587. };
  6588. // 搜索框回车
  6589. $scope.onSearch = function() {
  6590. $scope.tableParams.page(1);
  6591. $scope.tableParams.reload();
  6592. };
  6593. // 选择查找日期
  6594. $scope.onDateCondition = function(){
  6595. $scope.tableParams.page(1);
  6596. $scope.tableParams.reload();
  6597. };
  6598. }]);
  6599. /**
  6600. * 委外加工详细
  6601. */
  6602. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService) {
  6603. var loadData = function() {
  6604. MakeOutOrder.get({id: $stateParams.id}, function(data){
  6605. $scope.order = data;
  6606. var sum = $scope.order.qty * $scope.order.price;
  6607. $scope.order.total = sum;
  6608. $scope.loading = false;
  6609. });
  6610. };
  6611. loadData();
  6612. // 获取回复记录
  6613. $scope.getReply = function(item) {
  6614. if(!item.replies) {
  6615. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  6616. item.replies = replies;
  6617. });
  6618. }
  6619. };
  6620. $scope.openDatePicker = function($event, item, openParam) {
  6621. $event.preventDefault();
  6622. $event.stopPropagation();
  6623. item[openParam] = !item[openParam];
  6624. };
  6625. // 点击回复
  6626. $scope.onReplyClick = function(order, inverse) {
  6627. if(order.reply) {
  6628. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6629. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6630. return;
  6631. }
  6632. var reply = angular.copy(order.reply);
  6633. if(reply.delivery) {
  6634. if(typeof reply.delivery == 'object')
  6635. reply.delivery = reply.delivery.getTime();
  6636. } else {
  6637. reply.delivery = order.delivery;
  6638. }
  6639. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6640. $scope.loading = true;
  6641. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  6642. $scope.loading = false;
  6643. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6644. loadData();
  6645. }, function(response){
  6646. $scope.loading = false;
  6647. toaster.pop('error', '回复失败', response.data);
  6648. });
  6649. }
  6650. };
  6651. // 打开回复
  6652. $scope.openReply = function(order) {
  6653. if(!order.reply) {
  6654. order.reply = {
  6655. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6656. delivery: order.delivery
  6657. }
  6658. }
  6659. order.$editing = true;
  6660. };
  6661. // 关闭回复
  6662. $scope.closeReply = function(order) {
  6663. order.$editing = false;
  6664. }
  6665. // 自己委外加工订单
  6666. $scope.print = function(order) {
  6667. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  6668. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  6669. };
  6670. }]);
  6671. /**
  6672. * 计算时间差
  6673. */
  6674. app.filter('timespan', function(){
  6675. return function(time) {
  6676. if(time == null)
  6677. return '9999年';
  6678. var now = new Date().getTime(), span = time - now,
  6679. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  6680. m = Math.ceil(span/60000);
  6681. if(span < 0)
  6682. return '0天';
  6683. if(d > 0)
  6684. return d + '天';
  6685. if(h > 0)
  6686. return h + '小时';
  6687. if(m > 0)
  6688. return m + '分钟';
  6689. return '0天';
  6690. };
  6691. });
  6692. app.filter('firstchar', function(){
  6693. return function(str) {
  6694. if(str == null)
  6695. return null;
  6696. return str.substring(0, 1);
  6697. };
  6698. });
  6699. /**
  6700. * 搜索框,回车触发
  6701. */
  6702. app.directive('ngSearch', ['$parse', function($parse) {
  6703. return {
  6704. require : '?ngModel',
  6705. restrict : 'A',
  6706. link : function(scope, element, attrs, ngModel) {
  6707. var searchFn = $parse(attrs.ngSearch);
  6708. element.bind('keypress', function(event) {
  6709. if (event.keyCode == '13') {
  6710. event.preventDefault();
  6711. event.stopPropagation();
  6712. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  6713. }
  6714. });
  6715. }
  6716. };
  6717. }]);
  6718. /**
  6719. * 状态码 -> 描述
  6720. */
  6721. app.filter('status', function(){
  6722. return function(data) {
  6723. var statusConfig = {
  6724. '101': '已提交',
  6725. '102': '已审核',
  6726. '103': '未通过',
  6727. '200': '未回复',
  6728. '201': '已回复',
  6729. '313': '已激活',
  6730. '316': '已过账',
  6731. '311': '申请中',
  6732. '312': '未激活'
  6733. };
  6734. return statusConfig[data];
  6735. }
  6736. });
  6737. //弹出问题反馈模态框
  6738. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  6739. //获取当前用户
  6740. AuthenticationService.getAuthentication().success(function(data) {
  6741. $scope.user = data;
  6742. });
  6743. $scope.showModal = function(){
  6744. var modalInstance = $modal.open({
  6745. animation: true,
  6746. templateUrl: 'static/tpl/serve/feedback.html',
  6747. controller: 'FeedbackCtrl',
  6748. resolve: {
  6749. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  6750. }
  6751. });
  6752. modalInstance.result.then(function(){
  6753. }, function(){
  6754. })
  6755. }
  6756. }]);
  6757. /*
  6758. * 提交我的反馈
  6759. */
  6760. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  6761. $scope.isPublic = 1; //默认公开
  6762. $scope.classId = 1; //默认类别
  6763. $scope.user = user;
  6764. $scope.ok = function(){
  6765. if(!$scope.user){ //用户未登录
  6766. $scope.uu = null;
  6767. }else{ //用户已登录
  6768. $scope.uu = $scope.user.userUU;
  6769. }
  6770. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  6771. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  6772. function(data){
  6773. toaster.pop('success', '成功', '您的问题反馈成功!');
  6774. $scope.cancel();
  6775. }, function(response){
  6776. toaster.pop('error', '错误', response.data);
  6777. });
  6778. }
  6779. $scope.cancel = function () {
  6780. $modalInstance.dismiss();
  6781. };
  6782. }]);
  6783. //“我的问题反馈”跳转控制
  6784. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  6785. $scope.myFeedback = function(){
  6786. AuthenticationService.getAuthentication().success(function(data){
  6787. $scope.user = data;
  6788. if(!$scope.user){
  6789. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  6790. return false;
  6791. }else{
  6792. window.location.href = "./serve#/question/myFeedback";
  6793. }
  6794. });
  6795. }
  6796. }]);
  6797. //客户服务
  6798. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  6799. Vendor.getServe(function(datas){
  6800. $scope.vendors = datas;
  6801. console.log($scope.Vender);
  6802. // 自动跳转
  6803. if(datas && datas.length == 1)
  6804. $scope.redirect(datas[0]);
  6805. });
  6806. $scope.redirect = function(vendor) {
  6807. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  6808. };
  6809. }]);
  6810. /**
  6811. * 物料资料
  6812. */
  6813. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  6814. $scope.active = 'all';
  6815. $scope.agreedText = '全部';
  6816. $scope.dateZoneText = '一个月内';
  6817. $scope.condition = {dateZone: 1};
  6818. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6819. $scope.changeAgreed = function(agreed) {
  6820. $scope.condition.agreed = agreed;
  6821. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6822. $scope.condition.$agreedOpen = false;
  6823. };
  6824. $scope.changeDateZone = function(zone) {
  6825. $scope.condition.dateZone = zone;
  6826. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6827. $scope.condition.$dateZoneOpen = false;
  6828. getDateCondition(zone, $scope.condition);
  6829. $scope.tableParams.reload();
  6830. };
  6831. $scope.setActive = function(state) {
  6832. if($scope.active != state) {
  6833. $scope.active = state;
  6834. if($scope.tableParams.page() == 1)
  6835. $scope.tableParams.reload();
  6836. else
  6837. $scope.tableParams.page(1);
  6838. }
  6839. };
  6840. var getService = function() {
  6841. return GetProductInfo;
  6842. };
  6843. $scope.tableParams = new ngTableParams({
  6844. page : 1,
  6845. count : 5,
  6846. sorting: {
  6847. }
  6848. }, {
  6849. total : 0,
  6850. counts: [5, 10, 25, 50],
  6851. getData : function($defer, params) {
  6852. $scope.loading = true;
  6853. var pageParams = params.url();
  6854. pageParams.keyword = $scope.keyword;
  6855. pageParams.searchFilter = $scope.searchFilter;
  6856. console.log(pageParams.searchFilter);
  6857. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6858. $scope.loading = false;
  6859. if(page) {
  6860. params.total(page.totalElement);
  6861. $defer.resolve(page.content);
  6862. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  6863. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  6864. }
  6865. }, function(response) {
  6866. $scope.loading = false;
  6867. toaster.pop('error', '数据加载失败', response.data);
  6868. });
  6869. }
  6870. });
  6871. // 搜索框回车
  6872. $scope.onSearch = function() {
  6873. $scope.tableParams.page(1);
  6874. $scope.tableParams.reload();
  6875. };
  6876. //删除
  6877. $scope.deleteById = function(id) {
  6878. GetProductInfo.deleteById({id: id}, function(data) {
  6879. toaster.pop("success", "提示", "删除成功");
  6880. $timeout(function() {
  6881. window.location.reload();
  6882. }, 500);
  6883. }), function(response) {
  6884. toaster.pop("error", "删除失败", response.data);
  6885. };
  6886. }
  6887. }]);
  6888. /**
  6889. * 物料批量上传
  6890. */
  6891. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', function($scope, $upload, toaster) {
  6892. // 通过excel批量上传物料
  6893. $scope.upload = function() {
  6894. var file = $scope.myFiles[0];
  6895. $upload.upload({
  6896. url: 'product/baseInfo/release/excel',
  6897. file: file,
  6898. method: 'POST'
  6899. }).success(function(data) {
  6900. $scope.result = data;
  6901. $scope.success = $scope.result.success;
  6902. $scope.total = $scope.result.total;
  6903. $scope.alters = $scope.result.alters;
  6904. }).error(function(response) {
  6905. toaster.pop('error', response.data || response);
  6906. });
  6907. };
  6908. // 查看范例
  6909. $scope.showImg = function() {
  6910. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  6911. box.show();
  6912. box.find('img').attr('src', src);
  6913. box.find('a').click(function(){
  6914. box.hide();
  6915. });
  6916. box.dblclick(function(){
  6917. box.hide();
  6918. });
  6919. };
  6920. // 下载模板
  6921. $scope.download = function() {
  6922. window.location.href = 'product/baseInfo/upload/template';
  6923. };
  6924. }]);
  6925. /**
  6926. * 物料详情
  6927. */
  6928. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster) {
  6929. var loadData = function() {
  6930. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  6931. if(data.attach) {
  6932. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  6933. console.log(data.url);
  6934. // 查看范例
  6935. $scope.showImg = function() {
  6936. var src = data.url, box = $('#image-box');
  6937. box.show();
  6938. box.find('img').attr('src', src);
  6939. box.find('a').click(function(){
  6940. box.hide();
  6941. });
  6942. box.dblclick(function(){
  6943. box.hide();
  6944. });
  6945. };
  6946. })
  6947. }
  6948. $scope.prodInfo = data;
  6949. $scope.prodInfo.$editing = false;
  6950. $scope.loading = false;
  6951. });
  6952. };
  6953. loadData();
  6954. // 更新
  6955. $scope.update = function() {
  6956. $scope.prodInfo.$editing = true;
  6957. };
  6958. // 取消
  6959. $scope.cancel = function() {
  6960. $scope.prodInfo.$editing = false;
  6961. };
  6962. $scope.submit = function(prodInfo) {
  6963. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  6964. console.log(file);
  6965. $upload.upload({
  6966. url: 'product/baseInfo/updateProdInfo',
  6967. file: file,
  6968. method: 'POST',
  6969. data: {
  6970. prodInfo: $scope.prodInfo
  6971. },
  6972. }).success(function(data) {
  6973. if(data.success) {
  6974. toaster.pop('success', '提示', data.success);
  6975. window.location.reload();
  6976. }
  6977. if(data.error) {
  6978. toaster.pop('error', '提示', data.error);
  6979. }
  6980. }).error(function(data) {
  6981. $scope.loadingShow = false;
  6982. toaster.pop('error', '操作失败', data.error);
  6983. });
  6984. }
  6985. $scope.previewShow = false;
  6986. $scope.pdfShow = false;
  6987. $scope.noneFileShow = true;
  6988. $scope.$watch('myFiles', function(){
  6989. if($scope.myFiles) {
  6990. $scope.noneFileShow = false;
  6991. var file = $scope.myFiles[0];
  6992. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  6993. $scope.pdfShow = true;
  6994. $scope.previewShow = false;
  6995. $scope.imgPreviewName = file.name;
  6996. } else{
  6997. if (typeof(Worker) !== "undefined") {//支持HTML5
  6998. $scope.imgPreview = getObjectURL(file);
  6999. $scope.imgPreviewName = file.name;
  7000. } else{//不支持HTML5
  7001. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  7002. $scope.imgPreviewName = file.name;
  7003. }
  7004. $scope.previewShow = true;
  7005. $scope.pdfShow = false;
  7006. }
  7007. } else {
  7008. $scope.noneFileShow = true;
  7009. $scope.previewShow = false;
  7010. $scope.pdfShow = false;
  7011. }
  7012. });
  7013. //建立一个可存取到该file的url
  7014. var getObjectURL = function(file) {
  7015. var url = null ;
  7016. if (window.createObjectURL!=undefined) { // basic
  7017. url = window.createObjectURL(file) ;
  7018. } else if (window.URL!=undefined) { // mozilla(firefox)
  7019. url = window.URL.createObjectURL(file) ;
  7020. } else if (window.webkitURL!=undefined) { // webkit or chrome
  7021. url = window.webkitURL.createObjectURL(file) ;
  7022. }
  7023. return url ;
  7024. };
  7025. }]);
  7026. /**
  7027. * 新增物料
  7028. */
  7029. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout) {
  7030. $scope.prodInfo = {unit: 'PCS'};
  7031. // 选择类目
  7032. $scope.selectKind = function(uuids) {
  7033. $modal.open({
  7034. animation: true,
  7035. size: 'lg',
  7036. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  7037. controller: 'KindChooseCtrl',
  7038. }).result.then(function(data){
  7039. $scope.kindId = data;
  7040. var modalInstance = $modal.open({
  7041. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  7042. controller: 'FindComponentCtrl',
  7043. size: 'lg',
  7044. resolve: {
  7045. KindId: function() {
  7046. return $scope.kindId;
  7047. }
  7048. }
  7049. });
  7050. modalInstance.result.then(function(data) {
  7051. $scope.prodInfo.cmpUuId = data.uuid;
  7052. $scope.prodInfo.cmpCode = data.code;
  7053. $scope.prodInfo.brand = data.brand.nameEn;
  7054. }, function(){
  7055. });
  7056. }, function(){
  7057. });
  7058. };
  7059. //提交
  7060. $scope.submit = function(prodInfo){
  7061. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  7062. $upload.upload({
  7063. url: 'product/baseInfo/addNewProduct',
  7064. file: file,
  7065. method: 'POST',
  7066. data: {
  7067. prodInfo: $scope.prodInfo
  7068. },
  7069. }).success(function(data) {
  7070. if(data.success) {
  7071. toaster.pop('success', '提示', data.success);
  7072. $timeout(function() {
  7073. //提交后跳转到详情页面,防止重复提交
  7074. window.location.href="#/baseInfo/prodList/"+data.id;
  7075. }, 500);
  7076. }
  7077. if(data.error) {
  7078. toaster.pop('error', '提示', data.error);
  7079. $timeout(function() {
  7080. //提交后跳转到详情页面,防止重复提交
  7081. window.location.href="#/baseInfo/prodList/"+data.id;
  7082. }, 500);
  7083. }
  7084. }).error(function(data) {
  7085. $scope.loadingShow = false;
  7086. toaster.pop('error', '操作失败', data.error);
  7087. });
  7088. // GetProductInfo.addNewProd({}, prodInfo, function(data) {
  7089. // toaster.pop("success", "提示", "提交成功");
  7090. //
  7091. //
  7092. // }, function(res) {
  7093. // toaster.pop("error", "提示" + res);
  7094. // });
  7095. };
  7096. $scope.previewShow = false;
  7097. $scope.pdfShow = false;
  7098. $scope.noneFileShow = true;
  7099. $scope.$watch('myFiles', function(){
  7100. if($scope.myFiles) {
  7101. $scope.noneFileShow = false;
  7102. var file = $scope.myFiles[0];
  7103. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  7104. $scope.pdfShow = true;
  7105. $scope.previewShow = false;
  7106. $scope.imgPreviewName = file.name;
  7107. } else{
  7108. if (typeof(Worker) !== "undefined") {//支持HTML5
  7109. $scope.imgPreview = getObjectURL(file);
  7110. $scope.imgPreviewName = file.name;
  7111. } else{//不支持HTML5
  7112. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  7113. $scope.imgPreviewName = file.name;
  7114. }
  7115. $scope.previewShow = true;
  7116. $scope.pdfShow = false;
  7117. }
  7118. } else {
  7119. $scope.noneFileShow = true;
  7120. $scope.previewShow = false;
  7121. $scope.pdfShow = false;
  7122. }
  7123. });
  7124. //建立一个可存取到该file的url
  7125. var getObjectURL = function(file) {
  7126. var url = null ;
  7127. if (window.createObjectURL!=undefined) { // basic
  7128. url = window.createObjectURL(file) ;
  7129. } else if (window.URL!=undefined) { // mozilla(firefox)
  7130. url = window.URL.createObjectURL(file) ;
  7131. } else if (window.webkitURL!=undefined) { // webkit or chrome
  7132. url = window.webkitURL.createObjectURL(file) ;
  7133. }
  7134. return url ;
  7135. };
  7136. // 取消
  7137. $scope.cancel = function(){
  7138. $scope.prodInfo = angular.copy($scope.prodInfo);
  7139. };
  7140. }]);
  7141. /**
  7142. * 类目选择模态框
  7143. */
  7144. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  7145. $scope.kindId = null;
  7146. $scope.kinds = [[], [], [], []];
  7147. // 获取子类目
  7148. var getChildren = function(pid, deep) {
  7149. KindAPI.getChildren({parentId: pid}, function(data) {
  7150. $scope.kinds[deep] = data;
  7151. }, function(response) {
  7152. toaster.pop('error', '获取子类目失败', response.data);
  7153. });
  7154. };
  7155. // 改变节点选中状态
  7156. var changeStatus = function(item, deep) {
  7157. var kindId = null, level = 0;
  7158. angular.forEach($scope.kinds, function(ks, i) {
  7159. if(i > deep) {
  7160. $scope.kinds[i] = [];
  7161. } else {
  7162. angular.forEach(ks, function(k, j) {
  7163. if(i == deep) {
  7164. if(k.id == item.id) {
  7165. $scope.kinds[i][j].$active = true;
  7166. kindId = k.id;
  7167. } else {
  7168. k.$active = null;
  7169. }
  7170. }
  7171. });
  7172. }
  7173. });
  7174. // 选择的节点
  7175. $scope.kindId = kindId;
  7176. $scope.active = item;
  7177. // 当前可操作的层级
  7178. if(deep < 3) {
  7179. $scope.activeDeep = deep + 1;
  7180. }
  7181. };
  7182. // 节点点击后获取子类目,节点被选中
  7183. $scope.onItemClick = function(item, deep) {
  7184. changeStatus(item, deep);
  7185. if (!item.isLeaf) {
  7186. getChildren(item.id, deep + 1);
  7187. }
  7188. };
  7189. // 重新加载数据
  7190. function reload(deep) {
  7191. var pid;
  7192. if(deep) {
  7193. pid = $scope.actives[deep - 1].id;
  7194. } else {
  7195. pid = 0;
  7196. deep = 0;
  7197. }
  7198. getChildren(pid, deep);
  7199. }
  7200. // 初始加载数据,获取第一层的类目
  7201. if($scope.actives) {
  7202. angular.forEach($scope.actives, function(v, k) {
  7203. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  7204. $scope.kinds[k] = data;
  7205. angular.forEach($scope.kinds[k], function(kind, i){
  7206. if(kind.id == v.id) {
  7207. $scope.kinds[k][i].$active = true;
  7208. $scope.actives[k] = $scope.kinds[k][i];
  7209. }
  7210. })
  7211. }, function(response) {
  7212. toaster.pop('error', '获取子类目失败', response.data);
  7213. });
  7214. });
  7215. } else {
  7216. reload();
  7217. }
  7218. // 取消
  7219. $scope.cancel = function() {
  7220. $modalInstance.dismiss();
  7221. };
  7222. // 确认选择
  7223. $scope.check = function() {
  7224. $modalInstance.close($scope.kindId);
  7225. };
  7226. }]);
  7227. /**
  7228. * 器件筛选
  7229. */
  7230. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  7231. //状态
  7232. $scope.setActive = function (state){
  7233. if($scope.active != state) {
  7234. $scope.active = state;
  7235. if($scope.tableParams.page() == 1)
  7236. $scope.tableParams.reload();
  7237. else
  7238. $scope.tableParams.page(1);
  7239. }
  7240. };
  7241. $scope.tableParams = new ngTableParams({
  7242. page : 1,
  7243. count : 10
  7244. }, {
  7245. total : 0,
  7246. counts: [5, 10, 25, 50],
  7247. getData : function($defer, params) {
  7248. $scope.loading = true;
  7249. var pageParams = params.url();
  7250. pageParams.keyword = $scope.keyword;
  7251. pageParams.kindId = KindId;
  7252. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  7253. console.log(page);
  7254. $scope.loading = false;
  7255. if(page) {
  7256. params.total(page.totalElement);
  7257. $defer.resolve(page.content);
  7258. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7259. }
  7260. }, function(response){
  7261. $scope.loading = false;
  7262. toaster.pop('error', '数据加载失败', response.data);
  7263. });
  7264. }
  7265. });
  7266. // 取消
  7267. $scope.cancel = function() {
  7268. $modalInstance.dismiss();
  7269. };
  7270. // 选择
  7271. $scope.check = function(data){
  7272. $modalInstance.close(data);
  7273. };
  7274. // 搜索框回车
  7275. $scope.onSearch = function() {
  7276. $scope.tableParams.page(1);
  7277. $scope.tableParams.reload();
  7278. };
  7279. }]);
  7280. /**
  7281. * 企业列表
  7282. */
  7283. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  7284. $scope.active = 'all';
  7285. $scope.agreedText = '全部';
  7286. $scope.dateZoneText = '一个月内';
  7287. $scope.condition = {dateZone: 1};
  7288. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7289. $scope.changeAgreed = function(agreed) {
  7290. $scope.condition.agreed = agreed;
  7291. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7292. $scope.condition.$agreedOpen = false;
  7293. };
  7294. $scope.changeDateZone = function(zone) {
  7295. $scope.condition.dateZone = zone;
  7296. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7297. $scope.condition.$dateZoneOpen = false;
  7298. getDateCondition(zone, $scope.condition);
  7299. $scope.tableParams.reload();
  7300. };
  7301. $scope.setActive = function(state) {
  7302. if($scope.active != state) {
  7303. $scope.active = state;
  7304. if($scope.tableParams.page() == 1)
  7305. $scope.tableParams.reload();
  7306. else
  7307. $scope.tableParams.page(1);
  7308. }
  7309. };
  7310. var getService = function() {
  7311. return getAccountUserSpace;
  7312. };
  7313. $scope.tableParams = new ngTableParams({
  7314. page : 1,
  7315. count : 5,
  7316. sorting: {
  7317. }
  7318. }, {
  7319. total : 0,
  7320. counts: [5, 10, 25, 50],
  7321. getData : function($defer, params) {
  7322. $scope.loading = true;
  7323. var pageParams = params.url();
  7324. pageParams.keyword = $rootScope.keyword;
  7325. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  7326. $scope.loading = false;
  7327. if(page) {
  7328. params.total(page.totalElement);
  7329. $defer.resolve(page.content);
  7330. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7331. }
  7332. }, function(response) {
  7333. $scope.loading = false;
  7334. toaster.pop('error', '数据加载失败', response.data);
  7335. });
  7336. }
  7337. });
  7338. // 搜索框回车
  7339. $scope.onSearch = function() {
  7340. $scope.tableParams.page(1);
  7341. $scope.tableParams.reload();
  7342. };
  7343. // 添加合作关系
  7344. $scope.addPartner = function(name, businessCode) {
  7345. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  7346. if(data.success) {
  7347. toaster.pop("success", '添加成功', data.success);
  7348. }
  7349. if(data.error) {
  7350. toaster.pop("error", '添加失败', data.error);
  7351. }
  7352. }, function(response) {
  7353. toaster.pop('error','失败',response.data);
  7354. });
  7355. }
  7356. $scope.status = 'enList';
  7357. }]);
  7358. /**
  7359. * 新增采购单
  7360. */
  7361. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder) {
  7362. $scope.order = {
  7363. date : new Date(),
  7364. cust : {
  7365. uu : '',
  7366. },
  7367. custUser : {
  7368. },
  7369. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  7370. orderItems : {
  7371. product : {},
  7372. },
  7373. };
  7374. if($rootScope.businessCode) {
  7375. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  7376. $scope.order.cust.enName = data.vendorEnterprise.enName;
  7377. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  7378. $scope.order.cust.uu = data.vendorEnterprise.uu;
  7379. $scope.order.custUser.userName = data.vendorUser.userName;
  7380. $scope.order.custUser.userTel = data.vendorUser.userTel;
  7381. }, function(response) {
  7382. });
  7383. };
  7384. // 查找客户
  7385. $scope.dbfindCust = function(){
  7386. var modalInstance = $modal.open({
  7387. templateUrl: 'static/tpl/index/purc/modal/purc_order_cust.html',
  7388. controller: 'DbfindCustCtrl',
  7389. size: 'lg',
  7390. resolve: {
  7391. }
  7392. });
  7393. modalInstance.result.then(function(data) {
  7394. $scope.order.cust = data.myEnterprise;
  7395. $scope.order.custUser = data.myUser;
  7396. $scope.order.orderItems = [];
  7397. var item = {
  7398. code: null,
  7399. title: null,
  7400. spec: null,
  7401. unit: null,
  7402. qty: null,
  7403. price: null,
  7404. remark: null,
  7405. delivery: null,
  7406. };
  7407. // $scope.order.orderItems.push(item);
  7408. }, function(){
  7409. });
  7410. };
  7411. //商品信息
  7412. $scope.order.orderItems = [];
  7413. var item = {
  7414. code: null,
  7415. title: null,
  7416. spec: null,
  7417. unit: null,
  7418. qty: null,
  7419. price: null,
  7420. remark: null,
  7421. delivery: null,
  7422. };
  7423. // $scope.order.orderItems.push(item);
  7424. if($rootScope.prodId) {
  7425. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  7426. item.code = data.code;
  7427. item.title = data.title;
  7428. item.spec = data.spec;
  7429. item.unit = data.unit;
  7430. $scope.order.orderItems.push(item);
  7431. }, function(response) {
  7432. });
  7433. }
  7434. //增加商品
  7435. $scope.addProduct = function(index) {
  7436. if($scope.order.orderItems[index].code == null) {
  7437. toaster.pop('info', '提示', '请先选择商品');
  7438. } else {
  7439. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null});
  7440. }
  7441. };
  7442. //删除商品
  7443. $scope.deleteProduct = function(index) {
  7444. $scope.order.orderItems.splice(index, 1);
  7445. };
  7446. $scope.tableParams = new ngTableParams({
  7447. page : 1,
  7448. count : 10
  7449. }, {
  7450. total : 0,
  7451. counts: [5, 10, 25, 50],
  7452. getData : function($defer, params) {
  7453. $scope.loading = true;
  7454. var pageParams = params.url();
  7455. pageParams.keyword = $scope.keyword;
  7456. $scope.tip = $scope.keyword;
  7457. pageParams.custUU = $scope.order.cust.uu;
  7458. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  7459. $scope.loading = false;
  7460. if(page) {
  7461. params.total(page.totalElement);
  7462. $scope.total = page.totalElement;
  7463. $defer.resolve(page.content);
  7464. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7465. }
  7466. }, function(response){
  7467. $scope.loading = false;
  7468. toaster.pop('error', '数据加载失败', response.data);
  7469. });
  7470. }
  7471. });
  7472. // 选择
  7473. $scope.check = function(data) {
  7474. $scope.order.orderItems.push(data);
  7475. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7476. if($scope.order.orderItems[i].code == null) {
  7477. $scope.order.orderItems.splice(i, 1);
  7478. }
  7479. }
  7480. };
  7481. // 搜索框回车
  7482. $scope.onSearch = function() {
  7483. $scope.tableParams.page(1);
  7484. $scope.tableParams.reload();
  7485. };
  7486. $scope.$watch('order.cust.uu', function(n, o) {
  7487. if(n==o) {
  7488. return;
  7489. } else {
  7490. $scope.tableParams.page(1);
  7491. $scope.tableParams.reload();
  7492. }
  7493. }, true);
  7494. // 查找客户物料
  7495. $scope.dbfindCustProd = function(index){
  7496. if($scope.order.cust.uu) {
  7497. var modalInstance = $modal.open({
  7498. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  7499. controller: 'DbfindCustProdCtrl',
  7500. size: 'lg',
  7501. resolve: {
  7502. custUU: function() {
  7503. return $scope.order.cust.uu
  7504. }
  7505. }
  7506. });
  7507. modalInstance.result.then(function(data) {
  7508. $scope.order.orderItems.push(data);
  7509. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7510. if($scope.order.orderItems[i].code == null || i == index) {
  7511. $scope.order.orderItems.splice(i, 1);
  7512. }
  7513. }
  7514. }, function() {
  7515. });
  7516. } else {
  7517. toaster.pop('info', '提示', '请先选择供应商');
  7518. }
  7519. };
  7520. $scope.getMinDate = function(item) {
  7521. return $filter('date')(new Date, 'yyyy-MM-dd');
  7522. };
  7523. $scope.openDatePicker = function($event, openParam, index) {
  7524. $event.preventDefault();
  7525. $event.stopPropagation();
  7526. $scope.order.orderItems[index] = !openParam;
  7527. };
  7528. // 添加到购物车
  7529. $scope.addToCart = function(order) {
  7530. $scope.loading = true;
  7531. $scope.order.custUU = $scope.order.cust.uu;
  7532. $scope.order.custUserUU = $scope.order.custUser.userUU;
  7533. if($scope.order.date instanceof Date) {
  7534. $scope.order.date = $scope.order.date.getTime();
  7535. }
  7536. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7537. if($scope.order.orderItems[i].delivery instanceof Date) {
  7538. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  7539. }
  7540. }
  7541. addtoCart.save({}, $scope.order, function(data){
  7542. console.log($scope.order);
  7543. $scope.loading = false;
  7544. toaster.pop('success', '成功', '保存成功');
  7545. window.location.hash = '#/purc/cart/'+data.id;
  7546. }, function(response){
  7547. $scope.loading = false;
  7548. toaster.pop('error', '保存失败', response.data);
  7549. });
  7550. };
  7551. // 立即购买
  7552. $scope.addToOrder = function(order) {
  7553. $scope.loading = true;
  7554. $scope.order.custUU = $scope.order.cust.uu;
  7555. $scope.order.custUserUU = $scope.order.custUser.userUU;
  7556. if($scope.order.date instanceof Date) {
  7557. $scope.order.date = $scope.order.date.getTime();
  7558. }
  7559. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  7560. if($scope.order.orderItems[i].delivery instanceof Date) {
  7561. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  7562. }
  7563. }
  7564. newPurcOrder.save({}, $scope.order, function(data){
  7565. $scope.loading = false;
  7566. toaster.pop('success', '成功', '保存成功');
  7567. window.location.hash = '#/purc/order/'+data.id;
  7568. }, function(response){
  7569. $scope.loading = false;
  7570. toaster.pop('error', '保存失败', response.data);
  7571. });
  7572. };
  7573. }]);
  7574. /**
  7575. * 我的客户
  7576. */
  7577. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  7578. $scope.userInfoResult = true;
  7579. AuthenticationService.getAuthentication().success(function(data) {
  7580. $scope.loading = false;
  7581. $scope.thisUser = data;
  7582. });
  7583. var getCustInfos = function(custuu) {
  7584. if(custuu) {
  7585. VendorService.userInfo.query({uu:custuu},null,function(data) {
  7586. console.log(data);
  7587. $scope.custInfos = data;
  7588. var getPage = function(page, size){
  7589. if($scope.custInfos) {
  7590. var result = {};
  7591. result.totalCount = $scope.custInfos.length;
  7592. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  7593. if($scope.custInfos.length % size == 0) {
  7594. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  7595. }else {
  7596. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  7597. }
  7598. result.first = page == 1;
  7599. result.last = page == result.totalPage;
  7600. result.page = page;
  7601. result.next = page - 0 + 1;
  7602. result.pre = page - 1;
  7603. return result;
  7604. }
  7605. }
  7606. $scope.userdata = getPage(1,4);
  7607. $scope.first = function (){
  7608. $scope.userdata = getPage($scope.userdata.pre,4);
  7609. }
  7610. $scope.last = function (){
  7611. $scope.userdata = getPage($scope.userdata.next,4);
  7612. }
  7613. }, function(response){
  7614. $scope.loading = false;
  7615. toaster.pop('error', '数据加载失败', response.data);
  7616. });
  7617. }
  7618. }
  7619. $scope.addUserInfo = function(customer) {
  7620. //TODO
  7621. if ($scope.thisUser.sys) {
  7622. var modalInstance = $modal.open({
  7623. animation: true,
  7624. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  7625. controller: 'AddUserInfoCtrl',
  7626. resolve: {
  7627. customer: function() {
  7628. return customer;
  7629. }
  7630. }
  7631. });
  7632. modalInstance.result.then(function(changed, checked){
  7633. if(changed) {
  7634. if(checked)
  7635. $scope.newUser.roles = checked;
  7636. else
  7637. loadUsers();
  7638. }
  7639. });
  7640. } else {
  7641. toaster.pop('error', '您不是管理员,无权限分配用户!');
  7642. }
  7643. }
  7644. $scope.showUserInfo = function(customer,boo) {
  7645. $scope.custInfo = customer;
  7646. if(boo) {
  7647. getCustInfos(customer.myEnterprise.uu);
  7648. $scope.userInfoResult = true;
  7649. }
  7650. }
  7651. $scope.customerParams = new ngTableParams({
  7652. page : 1,
  7653. count : 10
  7654. }, {
  7655. total : 0,
  7656. counts: [5, 10, 25, 50],
  7657. getData : function($defer, params) {
  7658. $scope.loading = true;
  7659. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  7660. $scope.loading = false;
  7661. if(page) {
  7662. params.total(page.totalElements);
  7663. $defer.resolve(page.content);
  7664. }
  7665. $scope.totalCount = page.totalElements;
  7666. }, function(response){
  7667. $scope.loading = false;
  7668. toaster.pop('error', '数据加载失败', response.data);
  7669. });
  7670. }
  7671. });
  7672. }]);
  7673. /**
  7674. * 我的供应商
  7675. */
  7676. app.controller('MySupplierCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  7677. $scope.userInfoResult = true;
  7678. AuthenticationService.getAuthentication().success(function(data) {
  7679. $scope.loading = false;
  7680. $scope.thisUser = data;
  7681. });
  7682. var getCustInfos = function(custuu) {
  7683. if(custuu) {
  7684. VendorService.userInfo.query({uu:custuu},null,function(data) {
  7685. $scope.custInfos = data;
  7686. var getPage = function(page, size){
  7687. if($scope.custInfos) {
  7688. var result = {};
  7689. result.totalCount = $scope.custInfos.length;
  7690. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  7691. if($scope.custInfos.length % size == 0) {
  7692. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  7693. }else {
  7694. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  7695. }
  7696. result.first = page == 1;
  7697. result.last = page == result.totalPage;
  7698. result.page = page;
  7699. result.next = page - 0 + 1;
  7700. result.pre = page - 1;
  7701. return result;
  7702. }
  7703. }
  7704. $scope.userdata = getPage(1,4);
  7705. $scope.first = function (){
  7706. $scope.userdata = getPage($scope.userdata.pre,4);
  7707. }
  7708. $scope.last = function (){
  7709. $scope.userdata = getPage($scope.userdata.next,4);
  7710. }
  7711. }, function(response){
  7712. $scope.loading = false;
  7713. toaster.pop('error', '数据加载失败', response.data);
  7714. });
  7715. }
  7716. }
  7717. $scope.addUserInfo = function(customer) {
  7718. //TODO
  7719. if ($scope.thisUser.sys) {
  7720. var modalInstance = $modal.open({
  7721. animation: true,
  7722. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  7723. controller: 'AddUserInfoCtrl',
  7724. resolve: {
  7725. customer: function() {
  7726. return customer;
  7727. }
  7728. }
  7729. });
  7730. modalInstance.result.then(function(changed, checked){
  7731. if(changed) {
  7732. if(checked)
  7733. $scope.newUser.roles = checked;
  7734. else
  7735. loadUsers();
  7736. }
  7737. });
  7738. } else {
  7739. toaster.pop('error', '您不是管理员,无权限分配用户!');
  7740. }
  7741. }
  7742. $scope.showUserInfo = function(customer,boo) {
  7743. $scope.custInfo = customer;
  7744. if(boo) {
  7745. getCustInfos(customer.myEnterprise.uu);
  7746. $scope.userInfoResult = true;
  7747. }
  7748. }
  7749. $scope.customerParams = new ngTableParams({
  7750. page : 1,
  7751. count : 10
  7752. }, {
  7753. total : 0,
  7754. counts: [5, 10, 25, 50],
  7755. getData : function($defer, params) {
  7756. $scope.loading = true;
  7757. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  7758. $scope.loading = false;
  7759. if(page) {
  7760. params.total(page.totalElements);
  7761. $defer.resolve(page.content);
  7762. }
  7763. $scope.totalCount = page.totalElements;
  7764. }, function(response){
  7765. $scope.loading = false;
  7766. toaster.pop('error', '数据加载失败', response.data);
  7767. });
  7768. }
  7769. });
  7770. }]);
  7771. /**
  7772. * 建立合作关系申请
  7773. */
  7774. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout) {
  7775. $scope.active = 'todo';
  7776. var getRequestStatus = function(active) {
  7777. var fn = 'getAllRequest';
  7778. switch(active) {
  7779. case 'done':
  7780. fn = 'getRequestDone';break;
  7781. case 'todo':
  7782. fn = 'getRequestTodo';break;
  7783. case 'end':
  7784. fn = 'getRequestEnd';break;
  7785. }
  7786. return fn;
  7787. }
  7788. // 切换单据类型
  7789. $scope.setActive = function(state) {
  7790. if($scope.active != state) {
  7791. $scope.active = state;
  7792. if($scope.tableParams.page() == 1)
  7793. $scope.tableParams.reload();
  7794. else
  7795. $scope.tableParams.page(1);
  7796. }
  7797. };
  7798. // 切换数据来源(正常数据 or 历史数据)
  7799. var getService = function() {
  7800. return AddPartnerMyRequest;
  7801. };
  7802. $scope.tableParams = new ngTableParams({ // ng-Table参数
  7803. page : 1,
  7804. count : 5,
  7805. sorting: {
  7806. }
  7807. }, {
  7808. total : 0,
  7809. counts: [5, 10, 15, 25, 50],
  7810. getData : function($defer, params) { // 获取数据的方法
  7811. $scope.loading = true;
  7812. var pageParams = params.url();
  7813. pageParams.keyword = $scope.keyword;
  7814. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7815. $scope.loading = false;
  7816. if(page) {
  7817. params.total(page.totalElement);
  7818. $defer.resolve(page.content);
  7819. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7820. }
  7821. }, function(response){
  7822. $scope.loading = false;
  7823. toaster.pop('error', '数据加载失败', response.data);
  7824. });
  7825. }
  7826. });
  7827. // 再次申请
  7828. $scope.reapply = function(id) {
  7829. AddPartner.reapply({id: id}, {}, function(data) {
  7830. toaster.pop('success', '提示', '操作成功');
  7831. }, function(response) {
  7832. toaster.pop('error','失败',response.data);
  7833. });
  7834. }
  7835. // 添加为供应商
  7836. $scope.addSupplier = function(vendUID) {
  7837. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  7838. if(data.success) {
  7839. toaster.pop('success', '提示', data.success);
  7840. }
  7841. if(data.error) {
  7842. toaster.pop('error','提示', data.error);
  7843. }
  7844. }, function(response) {
  7845. toaster.pop('error', '失败', response.data);
  7846. })
  7847. };
  7848. // 添加客户
  7849. $scope.addCust = function(vendUID) {
  7850. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  7851. if(data.success) {
  7852. toaster.pop('success', '提示', data.success);
  7853. }
  7854. if(data.error) {
  7855. toaster.pop('error','提示', data.error);
  7856. }
  7857. }, function(response) {
  7858. toaster.pop('error', '失败', response.data);
  7859. })
  7860. };
  7861. // 搜索框回车
  7862. $scope.onSearch = function() {
  7863. $scope.tableParams.page(1);
  7864. $scope.tableParams.reload();
  7865. };
  7866. // 同意申请
  7867. $scope.agree = function(id) {
  7868. AddPartner.agreeRequest({id: id}, {}, function(data) {
  7869. toaster.pop('success', '提示', '操作成功');
  7870. $timeout(function() {
  7871. window.location.reload();
  7872. }, 500);
  7873. }, function(response) {
  7874. toaster.pop('error', '提示', response.data);
  7875. });
  7876. }
  7877. // 拒绝申请
  7878. $scope.refuse = function(id, reason) {
  7879. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  7880. toaster.pop('success', '提示', '操作成功');
  7881. $timeout(function() {
  7882. window.location.reload();
  7883. }, 500);
  7884. }, function(response) {
  7885. toaster.pop('error', '提示', response.data);
  7886. });
  7887. }
  7888. $scope.status = 'send';
  7889. }]);
  7890. /**
  7891. * 建立合作关系处理申请
  7892. */
  7893. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  7894. $scope.active = 'todo';
  7895. var getMessagetStatus = function(active) {
  7896. var fn = 'getAllMessage';
  7897. switch(active) {
  7898. case 'done':
  7899. fn = 'getMessageDone';break;
  7900. case 'todo':
  7901. fn = 'getMessageTodo';break;
  7902. case 'end':
  7903. fn = 'getMessageEnd';break;
  7904. }
  7905. return fn;
  7906. }
  7907. // 切换单据类型
  7908. $scope.setActive = function(state) {
  7909. if($scope.active != state) {
  7910. $scope.active = state;
  7911. if($scope.tableParams.page() == 1)
  7912. $scope.tableParams.reload();
  7913. else
  7914. $scope.tableParams.page(1);
  7915. }
  7916. };
  7917. var getService = function() {
  7918. return AddPartnerMyMessage;
  7919. };
  7920. $scope.tableParams = new ngTableParams({ // ng-Table参数
  7921. page : 1,
  7922. count : 5,
  7923. sorting: {
  7924. }
  7925. }, {
  7926. total : 0,
  7927. counts: [5, 10, 15, 25, 50],
  7928. getData : function($defer, params) { // 获取数据的方法
  7929. $scope.loading = true;
  7930. var pageParams = params.url();
  7931. pageParams.searchFilter = { // 筛选条件
  7932. keyword: $scope.keyword,
  7933. };
  7934. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7935. $scope.loading = false;
  7936. console.log(page);
  7937. if(page) {
  7938. params.total(page.totalElement);
  7939. $defer.resolve(page.content);
  7940. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7941. }
  7942. }, function(response){
  7943. $scope.loading = false;
  7944. toaster.pop('error', '数据加载失败', response.data);
  7945. });
  7946. }
  7947. });
  7948. // 同意申请
  7949. $scope.agree = function(id) {
  7950. AddPartner.agreeRequest({id: id}, {}, function(data) {
  7951. toaster.pop('success', '提示', '操作成功');
  7952. }, function(response) {
  7953. toaster.pop('error', '提示', response.data);
  7954. });
  7955. }
  7956. // 拒绝申请
  7957. $scope.refuse = function(id, reason) {
  7958. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  7959. toaster.pop('success', '提示', '操作成功');
  7960. }, function(response) {
  7961. toaster.pop('error', '提示', response.data);
  7962. });
  7963. }
  7964. $scope.status = 'get';
  7965. }]);
  7966. /**
  7967. * 我的合作伙伴
  7968. */
  7969. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', function($scope, toaster, GetProductInfo) {
  7970. // 默认显示合作伙伴
  7971. $scope.status = 'news';
  7972. // 获取所有的合作伙伴
  7973. GetProductInfo.getAllPartners({}, function(data) {
  7974. console.log(data);
  7975. $scope.partners = data;
  7976. }, function(res) {
  7977. toaster.pop('error', '获取列表失败', res.data);
  7978. });
  7979. // 添加为客户
  7980. $scope.addCust = function(partner) {
  7981. GetProductInfo.addCust({}, partner, function(data) {
  7982. toaster.pop('success', '提示', '添加客户成功');
  7983. }, function(response) {
  7984. toaster.pop('error', '添加客户失败', response.data);
  7985. });
  7986. }
  7987. // 添加为供应商
  7988. $scope.addSupplier = function(partner) {
  7989. GetProductInfo.addSupplier({}, partner, function(data) {
  7990. toaster.pop('success', '提示', '添加供应商成功');
  7991. }, function(response) {
  7992. toaster.pop('error', '添加供应商失败', response.data);
  7993. });
  7994. }
  7995. }]);
  7996. /**
  7997. * 财务对账时,企业进行筛选操作
  7998. */
  7999. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  8000. $scope.getData = function(){
  8001. FaApCheck.getAllCustomers(function(data) {
  8002. console.log(data);
  8003. $scope.custs= data;
  8004. angular.forEach($scope.data, function(item) {
  8005. item:{
  8006. $selected: true;
  8007. }
  8008. });
  8009. $scope.loading = false;
  8010. });
  8011. }
  8012. $scope.getData();
  8013. $scope.CustName= function(suuorname) {
  8014. $modalInstance.close(suuorname);
  8015. }
  8016. $scope.close = function() {
  8017. $modalInstance.close();
  8018. }
  8019. }]);
  8020. /**
  8021. * 跳转到企业圈
  8022. */
  8023. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  8024. GetProductInfo.businessGroups({}, function(data) {
  8025. window.open(data.url);
  8026. }, function(response) {
  8027. toaster.pop('error', '提示', response.data);
  8028. });
  8029. }]);
  8030. /**
  8031. * 购物车
  8032. */
  8033. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  8034. $scope.active = 'all';
  8035. $scope.agreedText = '全部';
  8036. $scope.dateZoneText = '一个月内';
  8037. $scope.condition = {dateZone: 1};
  8038. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8039. $scope.changeAgreed = function(agreed) {
  8040. $scope.condition.agreed = agreed;
  8041. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8042. $scope.condition.$agreedOpen = false;
  8043. };
  8044. $scope.changeDateZone = function(zone) {
  8045. $scope.condition.dateZone = zone;
  8046. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8047. $scope.condition.$dateZoneOpen = false;
  8048. getDateCondition(zone, $scope.condition);
  8049. $scope.tableParams.reload();
  8050. };
  8051. $scope.setActive = function(state) {
  8052. if($scope.active != state) {
  8053. $scope.active = state;
  8054. if($scope.tableParams.page() == 1)
  8055. $scope.tableParams.reload();
  8056. else
  8057. $scope.tableParams.page(1);
  8058. }
  8059. };
  8060. var getService = function() {
  8061. return getCartList;
  8062. };
  8063. $scope.tableParams = new ngTableParams({
  8064. page : 1,
  8065. count : 5,
  8066. sorting: {
  8067. }
  8068. }, {
  8069. total : 0,
  8070. counts: [5, 10, 25, 50],
  8071. getData : function($defer, params) {
  8072. $scope.loading = true;
  8073. var pageParams = params.url();
  8074. pageParams.keyword = $scope.keyword;
  8075. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8076. $scope.loading = false;
  8077. if(page) {
  8078. params.total(page.totalElements);
  8079. $defer.resolve(page.content);
  8080. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8081. }
  8082. }, function(response) {
  8083. $scope.loading = false;
  8084. toaster.pop('error', '数据加载失败', response.data);
  8085. });
  8086. }
  8087. });
  8088. $scope.getCartTotal = function(items) {
  8089. var sum = 0;
  8090. angular.forEach(items, function(item){
  8091. sum += item.qty * item.price;
  8092. });
  8093. return sum;
  8094. };
  8095. // 搜索框回车
  8096. $scope.onSearch = function() {
  8097. $scope.tableParams.page(1);
  8098. $scope.tableParams.reload();
  8099. };
  8100. // 提交
  8101. $scope.addtoOrder = function(id) {
  8102. console.log(id);
  8103. cartOperation.addToOrder({id: id}, {}, function(data) {
  8104. if(data.success) {
  8105. toaster.pop('success', '提示', data.success);
  8106. $timeout(function() {
  8107. window.location.hash = '#/purc/cartdetail/'+data.id;
  8108. },500);
  8109. }
  8110. if(data.error) {
  8111. toaster.pop('error', '提示', data.error);
  8112. }
  8113. }, function(response) {
  8114. toaster.pop('erroer', '提示', response.data);
  8115. });
  8116. };
  8117. // 删除一条主记录
  8118. $scope.deleteCart = function(id) {
  8119. cartOperation.deleteCart({id: id}, {}, function(data) {
  8120. if(data.success) {
  8121. toaster.pop('success', '提示', data.success);
  8122. $timeout(function() {
  8123. window.location.reload();
  8124. },500);
  8125. }
  8126. if(data.error) {
  8127. toaster.pop('error', '提示', data.error);
  8128. }
  8129. }, function(response) {
  8130. toaster.pop('erroer', '提示', response.data);
  8131. });
  8132. };
  8133. // 删除一条明细
  8134. $scope.deleteDetail = function(id) {
  8135. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  8136. if(data.success) {
  8137. toaster.pop('success', '提示', data.success);
  8138. $timeout(function() {
  8139. window.location.reload();
  8140. },500);
  8141. }
  8142. if(data.error) {
  8143. toaster.pop('error', '提示', data.error);
  8144. }
  8145. }, function(response) {
  8146. toaster.pop('erroer', '提示', response.data);
  8147. });
  8148. };
  8149. // 清空购物车
  8150. $scope.clearCart = function() {
  8151. cartOperation.deleteCarts({}, function(data) {
  8152. if(data.success) {
  8153. toaster.pop('success', '提示', data.success);
  8154. $timeout(function() {
  8155. window.location.reload();
  8156. },500);
  8157. }
  8158. if(data.error) {
  8159. toaster.pop('error', '提示', data.error);
  8160. }
  8161. }, function(response) {
  8162. toaster.pop('erroer', '提示', response.data);
  8163. });
  8164. }
  8165. }]);
  8166. /**
  8167. * 购物车详情
  8168. */
  8169. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', function($scope, cartOperation, $stateParams, toaster, $timeout) {
  8170. var loadData = function() {
  8171. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  8172. if(data.code) {
  8173. $scope.cart = data;
  8174. var sum = 0;
  8175. angular.forEach($scope.cart.cartDetails, function(item) {
  8176. sum += item.qty * item.price;
  8177. });
  8178. $scope.cart.total = sum;
  8179. $scope.loading = false;
  8180. } else {
  8181. window.location.hash = '#/purc/cart';
  8182. }
  8183. });
  8184. };
  8185. loadData();
  8186. // 删除一条明细
  8187. $scope.deleteDetail = function(id) {
  8188. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  8189. if(data.success) {
  8190. toaster.pop('success', '提示', data.success);
  8191. $timeout(function() {
  8192. window.location.reload();
  8193. },500);
  8194. }
  8195. if(data.error) {
  8196. toaster.pop('error', '提示', data.error);
  8197. }
  8198. }, function(response) {
  8199. toaster.pop('erroer', '提示', response.data);
  8200. });
  8201. };
  8202. }]);
  8203. /**
  8204. * 审批流
  8205. */
  8206. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', function($scope, toaster, $modal, appFlow) {
  8207. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  8208. $scope.nodes = data;
  8209. }, function(response) {
  8210. });
  8211. $scope.NoteSet = function() {
  8212. var modalInstance = $modal.open({
  8213. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8214. controller: 'NoteStep1Ctrl',
  8215. size: 'lg',
  8216. resolve: {
  8217. AppName: function() {
  8218. return '请假单';
  8219. }
  8220. }
  8221. });
  8222. modalInstance.result.then(function(data) {
  8223. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8224. if(data.error) {
  8225. toaster.pop('error', '提示', data.error);
  8226. }
  8227. if(data.success) {
  8228. toaster.pop('success', '提示', data.success);
  8229. }
  8230. }, function(response) {
  8231. });
  8232. }, function(){
  8233. });
  8234. }
  8235. $scope.overTimeSet = function() {
  8236. var modalInstance = $modal.open({
  8237. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8238. controller: 'NoteStep1Ctrl',
  8239. size: 'lg',
  8240. resolve: {
  8241. AppName: function() {
  8242. return '加班单';
  8243. }
  8244. }
  8245. });
  8246. modalInstance.result.then(function(data) {
  8247. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8248. if(data.error) {
  8249. toaster.pop('error', '提示', data.error);
  8250. }
  8251. if(data.success) {
  8252. toaster.pop('success', '提示', data.success);
  8253. }
  8254. }, function(response) {
  8255. });
  8256. }, function(){
  8257. });
  8258. }
  8259. $scope.feePleaseSet = function() {
  8260. var modalInstance = $modal.open({
  8261. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8262. controller: 'NoteStep1Ctrl',
  8263. size: 'lg',
  8264. resolve: {
  8265. AppName: function() {
  8266. return '出差单';
  8267. }
  8268. }
  8269. });
  8270. modalInstance.result.then(function(data) {
  8271. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8272. if(data.error) {
  8273. toaster.pop('error', '提示', data.error);
  8274. }
  8275. if(data.success) {
  8276. toaster.pop('success', '提示', data.success);
  8277. }
  8278. }, function(response) {
  8279. });
  8280. }, function(){
  8281. });
  8282. }
  8283. $scope.workDailySet = function() {
  8284. var modalInstance = $modal.open({
  8285. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  8286. controller: 'NoteStep1Ctrl',
  8287. size: 'lg',
  8288. resolve: {
  8289. AppName: function() {
  8290. return '工作日报';
  8291. }
  8292. }
  8293. });
  8294. modalInstance.result.then(function(data) {
  8295. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  8296. if(data.error) {
  8297. toaster.pop('error', '提示', data.error);
  8298. }
  8299. if(data.success) {
  8300. toaster.pop('success', '提示', data.success);
  8301. }
  8302. }, function(response) {
  8303. });
  8304. }, function(){
  8305. });
  8306. }
  8307. }]);
  8308. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  8309. $scope.appName = AppName;// 标题名称
  8310. $scope.AppFlow = {appName: $scope.appName,
  8311. appNodes:{}};
  8312. $scope.AppFlow.appNodes = [];
  8313. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  8314. if(data.appNodes.length != 0) {
  8315. $scope.node = data;
  8316. $scope.AppFlow = data;
  8317. }
  8318. }, function() {
  8319. });
  8320. $scope.copy = function() {//复制
  8321. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  8322. toaster.pop('info', '提示', '复制成功');
  8323. $modalInstance.dismiss();
  8324. }
  8325. $scope.paste = function() {
  8326. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  8327. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  8328. }
  8329. $scope.clear = function() {// 清空
  8330. $scope.AppFlow = {appName: $scope.appName,
  8331. appNodes:{}};
  8332. $scope.AppFlow.appNodes = [];
  8333. }
  8334. appFlow.getPositions({}, function(data) {// 获取人员信息
  8335. $scope.users = data;
  8336. }, function(response) {
  8337. });
  8338. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  8339. $scope.roles = data;
  8340. },function(response) {
  8341. });
  8342. $scope.SelectUser = function(data) { // 添加人员
  8343. var item = {
  8344. useruu: null,
  8345. username: null,
  8346. level: null
  8347. };
  8348. item.useruu = data.useruu;
  8349. item.username = data.username;
  8350. // if($scope.AppFlow.AppNodes.length != 0){
  8351. // angular.forEach($scope.AppFlow.AppNodes, function(node) {
  8352. // if(node) {
  8353. // if(node.useruu == item.useruu) {
  8354. // toaster.pop('info', '提示', '不能重复添加');
  8355. // } else {
  8356. // $scope.AppFlow.AppNodes.push(item);
  8357. // }
  8358. // }
  8359. // });
  8360. // } else {
  8361. $scope.AppFlow.appNodes.push(item);
  8362. // }
  8363. }
  8364. $scope.SelectRole = function(data) {// 添加职位
  8365. var item = {
  8366. position: null,
  8367. level: null
  8368. };
  8369. item.position = data;
  8370. $scope.AppFlow.appNodes.push(item);
  8371. }
  8372. $scope.deleteNode = function(index) {// 删除节点
  8373. $scope.AppFlow.appNodes.splice(index, 1);
  8374. };
  8375. $scope.saveNode = function() { // 保存
  8376. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  8377. $scope.AppFlow.appNodes[key].level = key;
  8378. });
  8379. if($scope.AppFlow.appNodes.length == 0) {
  8380. toaster.pop('info', '提示', '您还未设置审批人');
  8381. } else {
  8382. $modalInstance.close($scope.AppFlow);
  8383. };
  8384. };
  8385. $scope.cancel = function() {// 取消
  8386. $modalInstance.dismiss();
  8387. }
  8388. }]);
  8389. /***
  8390. * 代采定单
  8391. */
  8392. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', function($scope, toaster, getDeOrder, ngTableParams, BaseService) {
  8393. $scope.active = 'all';
  8394. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8395. $scope.total = null;
  8396. $scope.setActive = function(state) {
  8397. if($scope.active != state) {
  8398. $scope.active = state;
  8399. if($scope.tableParams.page() == 1)
  8400. $scope.tableParams.reload();
  8401. else
  8402. $scope.tableParams.page(1);
  8403. }
  8404. };
  8405. $scope.tableParams = new ngTableParams({
  8406. page : 1,
  8407. count : 5,
  8408. sorting: {
  8409. }
  8410. }, {
  8411. total : 0,
  8412. counts: [5, 10, 25, 50],
  8413. getData : function($defer, params) {
  8414. $scope.loading = true;
  8415. var pageParams = params.url();
  8416. pageParams.keyword = $scope.keyword;
  8417. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8418. $scope.loading = false;
  8419. if(page) {
  8420. params.total(page.totalElements);
  8421. $scope.total = page.totalElement;
  8422. $defer.resolve(page.content);
  8423. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8424. }
  8425. }, function(response) {
  8426. $scope.loading = false;
  8427. toaster.pop('error', '数据加载失败', response.data);
  8428. });
  8429. }
  8430. });
  8431. // 搜索框回车
  8432. $scope.onSearch = function() {
  8433. $scope.tableParams.page(1);
  8434. $scope.tableParams.reload();
  8435. };
  8436. }]);
  8437. /**
  8438. * 新增代采订单
  8439. */
  8440. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams) {
  8441. $scope.deOrder = {
  8442. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  8443. entrydate: new Date(),
  8444. status: '在录入',
  8445. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  8446. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  8447. riskmethod: '甲方承担',
  8448. taxpaymentmethod: '甲方承担',
  8449. };
  8450. $scope.deOrder.deputyOrderItems = [];
  8451. var item = {
  8452. prodname: null,
  8453. prodcode: null,
  8454. prodspec: null,
  8455. amount: null,
  8456. unitprice: null,
  8457. remark: null,
  8458. orderprice: null,
  8459. };
  8460. $scope.deOrder.deputyOrderItems.push(item);
  8461. //增加商品
  8462. $scope.add = function(index) {
  8463. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  8464. toaster.pop('info', '提示', '请先填写商品信息');
  8465. }else {
  8466. $scope.deOrder.deputyOrderItems.push(
  8467. { prodname: null,
  8468. prodcode: null,
  8469. prodspec: null,
  8470. amount: null,
  8471. unitprice: null,
  8472. remark: null,
  8473. orderprice: null});
  8474. }
  8475. };
  8476. //删除商品
  8477. $scope.del = function(index) {
  8478. $scope.deOrder.deputyOrderItems.splice(index, 1);
  8479. };
  8480. $scope.uplodaByBatch = function() {
  8481. var modalInstance = $modal.open({
  8482. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  8483. controller: 'DeputyOrderUploadCtrl',
  8484. size: 'lg',
  8485. resolve: {
  8486. }
  8487. });
  8488. modalInstance.result.then(function(data) {
  8489. angular.forEach(data, function(data) {
  8490. $scope.deOrder.deputyOrderItems.push(data);
  8491. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  8492. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  8493. $scope.deOrder.deputyOrderItems.splice(i, 1);
  8494. }
  8495. }
  8496. })
  8497. $scope.deOrder.totalamount = 0;
  8498. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  8499. $scope.deOrder.totalamount += item.amount * item.unitprice;
  8500. });
  8501. }, function(){
  8502. });
  8503. }
  8504. $scope.save = function() {
  8505. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  8506. if(data.id) {
  8507. window.location.hash = "#/purc/deputy/"+data.id;
  8508. }
  8509. if(data.error) {
  8510. toaster.pop('error', '提示', '保存失败');
  8511. }
  8512. }, function(response) {
  8513. });
  8514. }
  8515. $scope.openDatePicker = function($event, deOrder, openParam) {
  8516. $event.preventDefault();
  8517. $event.stopPropagation();
  8518. deOrder[openParam] = !deOrder[openParam];
  8519. };
  8520. }]);
  8521. /**
  8522. * 代采订单批量导入
  8523. */
  8524. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  8525. // 通过excel批量上传物料
  8526. $scope.result = null;
  8527. $scope.upload = function() {
  8528. var file = $scope.myFiles[0];
  8529. $upload.upload({
  8530. url: 'deputyOrder/release/excel',
  8531. file: file,
  8532. method: 'POST'
  8533. }).success(function(data) {
  8534. $scope.result = data;
  8535. $scope.success = $scope.result.success;
  8536. $scope.total = $scope.result.total;
  8537. $scope.alters = $scope.result.alters;
  8538. }).error(function(response) {
  8539. toaster.pop('error', response.data || response);
  8540. });
  8541. };
  8542. // 查看范例
  8543. $scope.showImg = function() {
  8544. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  8545. box.show();
  8546. box.find('img').attr('src', src);
  8547. box.find('a').click(function(){
  8548. box.hide();
  8549. });
  8550. box.dblclick(function(){
  8551. box.hide();
  8552. });
  8553. };
  8554. // 下载模板
  8555. $scope.download = function() {
  8556. window.location.href = 'deputyOrder/upload/template';
  8557. };
  8558. $scope.enSure = function() {
  8559. $modalInstance.close($scope.result.items);
  8560. }
  8561. $scope.cancel = function() {
  8562. $modalInstance.dismiss();
  8563. }
  8564. }]);
  8565. /**
  8566. * 代采详情
  8567. */
  8568. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService) {
  8569. var loadData = function() {
  8570. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  8571. $scope.deOrder = data;
  8572. });
  8573. };
  8574. loadData();
  8575. var getService = function() {
  8576. return DeputyOrder.getProdList;
  8577. };
  8578. $scope.tableParams = new ngTableParams({
  8579. page : 1,
  8580. count : 5,
  8581. sorting: {
  8582. }
  8583. }, {
  8584. total : 0,
  8585. counts: [5, 10, 25, 50],
  8586. getData : function($defer, params) {
  8587. $scope.loading = true;
  8588. var pageParams = params.url();
  8589. var realActive = {};
  8590. pageParams.searchFilter = { // 筛选条件
  8591. keyword: $stateParams.id,
  8592. };
  8593. getService().get.call(null, BaseService.parseParams(pageParams), function(page){
  8594. $scope.loading = false;
  8595. if(page) {
  8596. params.total(page.totalElement);
  8597. $defer.resolve(page.content);
  8598. }
  8599. }, function(response){
  8600. $scope.loading = false;
  8601. toaster.pop('error', '数据加载失败', response.data);
  8602. });
  8603. }
  8604. });
  8605. }]);
  8606. /**
  8607. * 招标单
  8608. */
  8609. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  8610. $scope.active = 'done';
  8611. $scope.setActive = function(state) {
  8612. if($scope.active != state) {
  8613. $scope.active = state;
  8614. if($scope.tableParams.page() == 1)
  8615. $scope.tableParams.reload();
  8616. else
  8617. $scope.tableParams.page(1);
  8618. }
  8619. };
  8620. var getTenderStatus = function(active) {
  8621. var fn = 'getMyAll';
  8622. switch(active) {
  8623. case 'done':
  8624. fn = 'getMyDone';break;
  8625. case 'todo':
  8626. fn = 'getMyTodo';break;
  8627. // case 'end':
  8628. // fn = 'getMyEnd';break;
  8629. case 'waiting':
  8630. fn = 'getMyWaiting';break;
  8631. }
  8632. return fn;
  8633. }
  8634. $scope.tableParams = new ngTableParams({
  8635. page : 1,
  8636. count : 5,
  8637. sorting: {
  8638. 'tender.endDate': 'desc',
  8639. 'tender.enterprise.enName': 'asc',
  8640. 'tender.code': 'asc'
  8641. }
  8642. }, {
  8643. total : 0,
  8644. counts: [5, 10, 25, 50],
  8645. getData : function($defer, params) {
  8646. $scope.loading = true;
  8647. var pageParams = params.url();
  8648. var realActive = {};
  8649. pageParams.searchFilter = { // 筛选条件
  8650. keyword: $scope.keyword,
  8651. // fromDate: getDateTime($scope.condition.dateFrom),
  8652. // endDate: getDateTime($scope.condition.dateTo)
  8653. };
  8654. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8655. $scope.loading = false;
  8656. if(page) {
  8657. params.total(page.totalElement);
  8658. $defer.resolve(page.content);
  8659. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  8660. }
  8661. }, function(response){
  8662. $scope.loading = false;
  8663. toaster.pop('error', '数据加载失败', response.data);
  8664. });
  8665. }
  8666. });
  8667. // 搜索框回车
  8668. $scope.onSearch = function() {
  8669. $scope.tableParams.page(1);
  8670. $scope.tableParams.reload();
  8671. };
  8672. }]);
  8673. /**
  8674. * 新增招标单
  8675. */
  8676. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload) {
  8677. // if( ! angular.isUndefined($stateParams.id) && $stateParams.id != "") {
  8678. // $scope.loading = true;
  8679. // PurcTender.getOne({id: $stateParams.id}, function(data){
  8680. // data.$editing = false;
  8681. // $scope.tenderItem.tender = data;
  8682. // staticItem = angular.copy(data);
  8683. // $scope.loading = false;
  8684. // }, function(response){
  8685. // $scope.loading = false;
  8686. // toaster.pop('error', '数据加载失败', response.data);
  8687. // });
  8688. // } else {//
  8689. $scope.loading = false;
  8690. $scope.condition = {dateZone: 1};
  8691. $scope.tenderItem = {
  8692. $editing: true,
  8693. tender: {
  8694. date: new Date(),
  8695. unit: 'PCS',
  8696. currency: 'RMB',
  8697. ifOpen: 1,
  8698. ifTax: 1,
  8699. invoiceType: 2,
  8700. tenderAttachs:[{}]
  8701. }
  8702. // 供应商企业信息
  8703. // enterpriseBaseInfo: [{}]
  8704. };
  8705. // 删除一个供应商
  8706. $scope.removeVendor = function(index) {
  8707. $scope.tenderItem.enterpriseBaseInfo.splice(index, 1);
  8708. };
  8709. // 可选的证照要求
  8710. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  8711. // 处理区域
  8712. var parseCertificate = function(a) {
  8713. if (a) {
  8714. var arr = a.split(',');
  8715. angular.forEach(arr, function(app) {
  8716. var contained = false;
  8717. angular.forEach($scope.certificates, function($app) {
  8718. if($app.name == app) {
  8719. $app.checked = true;
  8720. contained = true;
  8721. }
  8722. });
  8723. if(!contained) {
  8724. $scope.certificates.push({name: app, checked: true});
  8725. }
  8726. });
  8727. }
  8728. }
  8729. // 查找客户
  8730. $scope.dbfindVendor = function(){
  8731. var modalInstance = $modal.open({
  8732. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  8733. controller: 'DbfindVendorCtrl',
  8734. size: 'lg',
  8735. resolve: {
  8736. }
  8737. });
  8738. var ifPush = true;
  8739. modalInstance.result.then(function(data){
  8740. angular.forEach(data, function(vendor) {
  8741. if (!$scope.tenderItem.enterpriseBaseInfo) {// 不存在就先创建
  8742. $scope.tenderItem.enterpriseBaseInfo = [{}];
  8743. $scope.tenderItem.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  8744. } else {
  8745. for (var i = 0;i<$scope.tenderItem.enterpriseBaseInfo.length; i++) {
  8746. ifPush = true;
  8747. if ($scope.tenderItem.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  8748. ifPush = false;
  8749. break; // 判定到已存在供应商,就终止循环。
  8750. }
  8751. }
  8752. if (ifPush) {
  8753. $scope.tenderItem.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  8754. }
  8755. }
  8756. });
  8757. $rootScope.tenderVendor = $scope.tenderItem.enterpriseBaseInfo;
  8758. }, function(){
  8759. });
  8760. };
  8761. // // 查找客户物料
  8762. // $scope.dbfindCustProd = function(){
  8763. // if($scope.item.$editing) {
  8764. // if($scope.item.quotation.cust.uu) {
  8765. // var modalInstance = $modal.open({
  8766. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  8767. // controller: 'DbfindCustProdCtrl',
  8768. // size: 'lg',
  8769. // resolve: {
  8770. // custUU: function(){return $scope.item.quotation.cust.uu}
  8771. // }
  8772. // });
  8773. //
  8774. // modalInstance.result.then(function(data){
  8775. // $scope.item.product = data;
  8776. // }, function(){
  8777. //
  8778. // });
  8779. // } else {
  8780. // toaster.pop('error', '错误', '请先选择客户');
  8781. // }
  8782. // }
  8783. // };
  8784. var sleep = function (d){
  8785. for(var t = Date.now();Date.now() - t <= d;);
  8786. }
  8787. // 保存和发布招标单
  8788. $scope.save = function(isPublish){
  8789. $scope.loading = true;
  8790. // --组装证照要求
  8791. var myCertificate = [];
  8792. angular.forEach($scope.certificates, function(certificate) {
  8793. if (certificate.checked) {
  8794. myCertificate.push(certificate.name);
  8795. }
  8796. });
  8797. $scope.tenderItem.tender.certificate = myCertificate.join(',');
  8798. if(!$scope.tenderItem.tender.code) { //新增,设单号
  8799. $scope.tenderItem.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  8800. }
  8801. if($scope.tenderItem.tender.date instanceof Date) {
  8802. $scope.tenderItem.tender.date = $scope.tenderItem.tender.date.getTime();
  8803. }
  8804. if($scope.tenderItem.tender.endDate instanceof Date) {
  8805. $scope.tenderItem.tender.endDate = $scope.tenderItem.tender.endDate.getTime();
  8806. }
  8807. if($scope.tenderItem.tender.publishDate instanceof Date) {
  8808. $scope.tenderItem.tender.publishDate = $scope.tenderItem.tender.publishDate.getTime();
  8809. }
  8810. if (isPublish) { // 发布
  8811. toaster.pop('info', '提示', '正在发布,请稍候');
  8812. PurcTender.publish({tender: $scope.tenderItem.tender, enterpriseBaseInfo: $scope.tenderItem.enterpriseBaseInfo}, {}, function(tender,enterprise){
  8813. // angular.forEach(tender.tenderAttaches, function(tenderAttach) {
  8814. var file = $scope.MyFiles, file = file && file.length>0 ? file[0]: null;
  8815. $upload.upload({
  8816. url: 'tender/addTenderAttach',
  8817. file: file,
  8818. method: 'POST',
  8819. data: {
  8820. tender: $scope.tenderItem.tender
  8821. }
  8822. // });
  8823. });
  8824. parseCertificate(tender.certificate);
  8825. sleep(1500); //当前方法暂停1.5秒
  8826. $scope.loading = false;
  8827. toaster.pop('success', '成功', '发布成功');
  8828. window.location.hash = '#/purc/tender';
  8829. }, function(response){
  8830. $scope.loading = false;
  8831. toaster.pop('error', '发布失败', response.data);
  8832. });
  8833. } else { // 保存
  8834. toaster.pop('info', '提示', '正在保存,请稍候');
  8835. PurcTender.save({tender: $scope.tenderItem.tender, enterpriseBaseInfo: $scope.tenderItem.enterpriseBaseInfo}, {}, function(tender,enterprise) {
  8836. var file = $scope.MyFiles, file = file && file.length>0 ? file[0]: null;
  8837. $upload.upload({
  8838. url: 'tender/addTenderAttach',
  8839. file: file,
  8840. method: 'POST',
  8841. data: {
  8842. tender: $scope.tenderItem.tender
  8843. }
  8844. });
  8845. $scope.loading = false;
  8846. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  8847. toaster.pop('success', '成功', '保存成功');
  8848. window.location.hash = '#/purc/tender';
  8849. }, function(response){
  8850. $scope.loading = false;
  8851. toaster.pop('error', '保存失败', response.data);
  8852. });
  8853. }
  8854. };
  8855. $scope.getMinDate = function() {
  8856. if (!$scope.tenderItem.tender) {
  8857. return $filter('date')(new Date(), 'yyyy-MM-dd');
  8858. }
  8859. return $scope.tenderItem.tender.endDate ? $filter('date')($scope.tenderItem.tender.endDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  8860. };
  8861. $scope.openDatePicker = function($event, item, openParam) {
  8862. $event.preventDefault();
  8863. $event.stopPropagation();
  8864. item[openParam] = !item[openParam];
  8865. };
  8866. }]);
  8867. /**
  8868. * 评标
  8869. */
  8870. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  8871. $scope.tenderItems = [];
  8872. // 采购方获取评标单
  8873. var evaluation = function() {
  8874. $scope.loading = true;
  8875. PurcTender.getOne({id: $stateParams.id}, function(data){
  8876. data.$editing = false;
  8877. $scope.tender = data;
  8878. $scope.loading = false;
  8879. }, function(response){
  8880. $scope.loading = false;
  8881. toaster.pop('error', '数据加载失败', response.data);
  8882. });
  8883. }
  8884. evaluation();
  8885. $scope.submit = function(tender) {
  8886. PurcTender.decide(tender, function(){
  8887. toaster.pop('success', '确认成功');
  8888. window.location.hash = '#/purc/tender';
  8889. }, function(response){
  8890. toaster.pop('error', '确认失败', response.data);
  8891. });
  8892. }
  8893. }]);
  8894. /**
  8895. * 客户指定招标
  8896. *
  8897. */
  8898. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  8899. $scope.active = 'todo';
  8900. $scope.condition = {dateZone: 1};
  8901. $scope.setActive = function(state) {
  8902. if($scope.active != state) {
  8903. $scope.active = state;
  8904. if($scope.tableParams.page() == 1)
  8905. $scope.tableParams.reload();
  8906. else
  8907. $scope.tableParams.page(1);
  8908. }
  8909. };
  8910. $scope.tableParams = new ngTableParams({
  8911. page : 1,
  8912. count : 5,
  8913. sorting: {
  8914. 'tender.endDate': 'desc',
  8915. 'tender.enterprise.enName': 'asc',
  8916. 'tender.code': 'asc'
  8917. }
  8918. }, {
  8919. total : 0,
  8920. counts: [5, 10, 25, 50],
  8921. getData : function($defer, params) {
  8922. $scope.loading = true;
  8923. var pageParams = params.url();
  8924. var realActive = {};
  8925. pageParams.searchFilter = { // 筛选条件
  8926. keyword: $scope.keyword
  8927. // fromDate: getDateTime($scope.condition.dateFrom),
  8928. // endDate: getDateTime($scope.condition.dateTo)
  8929. };
  8930. AccountEnterprise.get({}, function(data){
  8931. $scope.loading = false;
  8932. $scope.currentEn = data;
  8933. });
  8934. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8935. $scope.loading = false;
  8936. if(page) {
  8937. params.total(page.totalElement);
  8938. $defer.resolve(page.content);
  8939. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  8940. }
  8941. }, function(response){
  8942. $scope.loading = false;
  8943. toaster.pop('error', '数据加载失败', response.data);
  8944. });
  8945. }
  8946. });
  8947. var stautsItem = [];
  8948. $scope.getTenderStatus = function (tender) {
  8949. angular.forEach(tender.purchaseTenderItems, function(thisItem){
  8950. if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  8951. stautsItem = thisItem;
  8952. }
  8953. });
  8954. if (!stautsItem.price) {
  8955. return "daitoubiao";
  8956. } else if (!stautsItem.applystatus) {
  8957. return "yitoubiao";
  8958. } else if (stautsItem.applystatus == 1) {
  8959. return "zhongbiao";
  8960. } else if (stautsItem.applystatus == 0) {
  8961. return "weizhongbiao";
  8962. }
  8963. };
  8964. // 搜索框回车
  8965. $scope.onSearch = function() {
  8966. $scope.tableParams.page(1);
  8967. $scope.tableParams.reload();
  8968. };
  8969. }]);
  8970. /**
  8971. * 平台公开招标
  8972. *
  8973. */
  8974. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  8975. $scope.active = 'todo';
  8976. $scope.condition = {dateZone: 1};
  8977. $scope.setActive = function(state) {
  8978. if($scope.active != state) {
  8979. $scope.active = state;
  8980. if($scope.tableParams.page() == 1)
  8981. $scope.tableParams.reload();
  8982. else
  8983. $scope.tableParams.page(1);
  8984. }
  8985. };
  8986. var getOpenState = function(active) {
  8987. var fn = 'getOpenAll';
  8988. switch(active) {
  8989. // case 'done':
  8990. // fn = 'getOpenDone';break;
  8991. case 'todo':
  8992. fn = 'getOpenTodo';break;
  8993. case 'end':
  8994. fn = 'getOpenEnd';break;
  8995. // case 'waiting':
  8996. // fn = 'getOpenWaiting';break;
  8997. }
  8998. return fn;
  8999. };
  9000. $scope.tableParams = new ngTableParams({
  9001. page : 1,
  9002. count : 5,
  9003. sorting: {
  9004. 'tender.endDate': 'desc',
  9005. 'tender.enterprise.enName': 'asc',
  9006. 'tender.code': 'asc'
  9007. }
  9008. }, {
  9009. total : 0,
  9010. counts: [5, 10, 25, 50],
  9011. getData : function($defer, params) {
  9012. $scope.loading = true;
  9013. var pageParams = params.url();
  9014. var realActive = {};
  9015. pageParams.searchFilter = { // 筛选条件
  9016. keyword: $scope.keyword,
  9017. // fromDate: getDateTime($scope.condition.dateFrom),
  9018. // endDate: getDateTime($scope.condition.dateTo)
  9019. };
  9020. AccountEnterprise.get({}, function(data){
  9021. $scope.loading = false;
  9022. $scope.currentEn = data;
  9023. });
  9024. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9025. $scope.loading = false;
  9026. if(page) {
  9027. params.total(page.totalElement);
  9028. $defer.resolve(page.content);
  9029. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  9030. }
  9031. }, function(response){
  9032. $scope.loading = false;
  9033. toaster.pop('error', '数据加载失败', response.data);
  9034. });
  9035. }
  9036. });
  9037. var stautsItem = [];
  9038. $scope.getTenderStatus = function (tender) {
  9039. angular.forEach(tender.purchaseTenderItems, function(thisItem){
  9040. if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  9041. stautsItem = thisItem;
  9042. }
  9043. });
  9044. if (!stautsItem.price) {
  9045. return "daitoubiao";
  9046. } else if (!stautsItem.applystatus) {
  9047. return "yitoubiao";
  9048. } else if (stautsItem.applystatus == 1) {
  9049. return "zhongbiao";
  9050. } else if (stautsItem.applystatus == 0) {
  9051. return "weizhongbiao";
  9052. }
  9053. };
  9054. // 搜索框回车
  9055. $scope.onSearch = function() {
  9056. $scope.tableParams.page(1);
  9057. $scope.tableParams.reload();
  9058. };
  9059. }]);
  9060. /**
  9061. * 采购方查看供应商投标单
  9062. */
  9063. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  9064. PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  9065. $scope.item = data; // 供应商查看
  9066. $scope.loading = false;
  9067. }, function(response){
  9068. $scope.loading = false;
  9069. toaster.pop('error', '数据加载失败', response.data);
  9070. });
  9071. PurcTender.getOne({id: $stateParams.id}, function(data){
  9072. $scope.bid = data; // 用于展示
  9073. }, function(response){
  9074. toaster.pop('error', '数据加载失败', response.data);
  9075. });
  9076. }]);
  9077. /**
  9078. * 投标
  9079. */
  9080. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload) {
  9081. var staticItem = null;
  9082. // $scope.loading = true;
  9083. PurcTender.getItem({id: $stateParams.id}, function(data){
  9084. $scope.item = data; // 用于投标
  9085. if ($scope.item.enterpriseBaseInfo != null) {
  9086. $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  9087. }
  9088. staticItem = angular.copy(data);
  9089. $scope.loading = false;
  9090. }, function(response){
  9091. $scope.loading = false;
  9092. toaster.pop('error', '数据加载失败', response.data);
  9093. });
  9094. var sleep = function (d){
  9095. for(var t = Date.now();Date.now() - t <= d;);
  9096. }
  9097. PurcTender.getOne({id: $stateParams.id}, function(data){
  9098. $scope.bid = data; // 用于展示
  9099. }, function(response){
  9100. toaster.pop('error', '数据加载失败', response.data);
  9101. });
  9102. // 投标
  9103. $scope.bidIt = function(tender,item){
  9104. $scope.loading = true;
  9105. if(item.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  9106. item.enterpriseBaseInfo.enEstablishDate = item.enterpriseBaseInfo.enEstablishDate.getTime();
  9107. }
  9108. PurcTender.reply({bid:tender, tenderItem:item}, {}, function(tender, tenderItem){
  9109. var file = $scope.MyFiles, file = file && file.length>0 ? file[0]: null;
  9110. $upload.upload({
  9111. url: 'tender/addTenderItemAttach',
  9112. file: file,
  9113. method: 'POST',
  9114. data: {
  9115. tenderItem: $scope.item
  9116. }
  9117. });
  9118. $scope.loading = false;
  9119. toaster.pop('info', '成功', '投标成功');
  9120. // $window.location.reload();
  9121. window.location.hash = '#/sale/tender';
  9122. }, function(response){
  9123. $scope.loading = false;
  9124. toaster.pop('error', '投标失败', '出现异常,投标失败');
  9125. });
  9126. };
  9127. $scope.condition = {
  9128. $fromOpened:false
  9129. }
  9130. $scope.getMaxDate = function() {
  9131. return $filter('date')(new Date(), 'yyyy-MM-dd');
  9132. };
  9133. $scope.openDatePicker = function($event, item, openParam) {
  9134. $event.preventDefault();
  9135. $event.stopPropagation();
  9136. item[openParam] = !item[openParam];
  9137. };
  9138. }]);
  9139. return app;
  9140. });