app.js 407 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222
  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 : "/addTender",
  137. templateUrl : "static/tpl/index/purc/tender.html",
  138. controller : 'PurcNewTenderCtrl'
  139. }).state('purc.savedtender', {
  140. url : "/tender/:id",
  141. templateUrl : "static/tpl/index/purc/saved_tender.html",
  142. controller : 'PurcNewTenderCtrl'
  143. /* 评标 */
  144. }).state('purc.evaluation', {
  145. url : "/evaluation/:id",
  146. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  147. controller : 'PurcEvaluationCtrl'
  148. /* 采购供应商资料 */
  149. }).state('purc.vendor', {
  150. url : "/vendor",
  151. templateUrl : "static/tpl/index/purc/vendor.html",
  152. controller : 'PurcVendorCtrl'
  153. /* 采购供应商资料 详情*/
  154. }).state('purc.vendordetail', {
  155. url : "/vendor/:id",
  156. templateUrl : "static/tpl/index/purc/vendor_detail.html",
  157. controller : 'PurcVendorDetailCtrl'
  158. /* 客户指定招标列表 */
  159. }).state('purc.makeoutorder', {
  160. url : "/makeoutorder",
  161. templateUrl : "static/tpl/index/make/outorder.html",
  162. controller: 'MakeOutOrderCtrl'
  163. }).state('purc.outorder_detail', {
  164. url : "/makeoutorder/:id",
  165. templateUrl : "static/tpl/index/make/outorder_detail.html",
  166. controller: 'MakeOutOrderDetailCtrl'
  167. /*平台新增询价单*/
  168. }).state('purc.inquiry_new', {
  169. url : "/purcinquiry",
  170. templateUrl : "static/tpl/index/purc/inquiry_new.html",
  171. controller: 'PurcInquiryCtrl'
  172. }).state('purc.inquiry', {
  173. url : "/purchaseinquiry",
  174. templateUrl : "static/tpl/index/purc/inquiry.html",
  175. controller: 'PurchaseInquiryCtrl'
  176. }).state('purc.inquiry_detail', {
  177. url : "/purcinquirydetail",
  178. templateUrl : "static/tpl/index/purc/inquiry_detail.html",
  179. controller: 'PurcInquiryDetailCtrl'
  180. }).state('purc.inquiry_unapply', {
  181. url : "/inquiry_unapply",
  182. templateUrl : "static/tpl/index/purc/inquiry_unapply.html",
  183. controller: 'UnapplyInquiryCtrl'
  184. }).state('sale.tenderlist', {
  185. url : "/tender",
  186. templateUrl : "static/tpl/index/sale/tenderlist.html",
  187. controller : 'SaleTenderCtrl'
  188. }).state('sale.todo.tenderlist', {
  189. url : "/tender",
  190. templateUrl : "static/tpl/index/sale/tenderlist.html",
  191. controller : 'SaleTenderCtrl'
  192. /* 平台公开招标列表 */
  193. }).state('baseInfo.openTenderList', {
  194. url : "/openTenderList",
  195. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  196. controller: 'SaleOpenTenderCtrl'
  197. /* 查看公开招标详情 */
  198. }).state('baseInfo.open_tender_detail', {
  199. url : "/openTenderDetail/:id",
  200. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  201. controller : 'OpenSaleTenderDetailCtrl'
  202. /* 投标 */
  203. }).state('sale.tender', {
  204. url : "/tender/:id",
  205. templateUrl : "static/tpl/index/sale/tender.html",
  206. controller : 'SaleTenderDetailCtrl'
  207. /* 采购方查看供应商投标 */
  208. }).state('sale.vendortender', {
  209. url : "/tender/:vendUU/:id",
  210. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  211. controller : 'SaleVendorTenderDetailCtrl'
  212. }).state('sale.todo', {
  213. url : "/todo",
  214. templateUrl : "static/tpl/index/sale/todo.html"
  215. }).state('sale.todo.inquiry', {
  216. url : "/inquiry",
  217. templateUrl : "static/tpl/index/sale/inquiry.html",
  218. controller: 'SaleInquiryCtrl'
  219. }).state('sale.todo.order', {
  220. url : "/order",
  221. templateUrl : "static/tpl/index/sale/order.html",
  222. controller: 'SaleOrderCtrl'
  223. }).state('sale.todo.change', {
  224. url : "/change",
  225. templateUrl : "static/tpl/index/sale/change.html",
  226. controller: 'SaleChangeCtrl'
  227. }).state('sale.todo.notice', {
  228. url : "/notice",
  229. templateUrl : "static/tpl/index/sale/notice.html",
  230. controller: 'SaleNoticeCtrl'
  231. }).state('sale.customer', {
  232. url : "/customer",
  233. templateUrl : "static/tpl/index/sale/customer.html",
  234. controller: 'CustomerCtrl'
  235. }).state('sale.customer_detail', {
  236. url : "/customer/:id",
  237. templateUrl : "static/tpl/index/sale/customer_detail.html",
  238. controller: 'CustomerDetailCtrl'
  239. }).state('sale.customerProduct', {
  240. url : "/customerProduct",
  241. templateUrl : "static/tpl/index/sale/customer.html",
  242. controller: 'CustomerCtrl'
  243. }).state('sale.inquiry', {
  244. url : "/inquiry",
  245. templateUrl : "static/tpl/index/sale/inquiry.html",
  246. controller: 'SaleInquiryCtrl'
  247. }).state('sale.inquirymould', {
  248. url : "/mould",
  249. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  250. controller: 'SaleInquiryMouldCtrl'
  251. }).state('sale.todo.inquirymould', {
  252. url : "/mould",
  253. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  254. controller: 'SaleInquiryMouldCtrl'
  255. }).state('sale.inquiry_mould_detail', {
  256. url : "/mould/:id",
  257. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  258. controller: 'SaleInquiryMouldDetailCtrl'
  259. }).state('sale.inquiry_detail', {
  260. url : "/inquiry/:id",
  261. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  262. controller: 'SaleInquiryDetailCtrl'
  263. }).state('sale.quotation', {
  264. url : "/quotation",
  265. templateUrl : "static/tpl/index/sale/quotation.html"
  266. }).state('sale.quotation.new', {
  267. url : "/new",
  268. templateUrl : "static/tpl/index/sale/quotation_new.html",
  269. controller: 'SaleQuotationNewCtrl'
  270. }).state('sale.quotation.list', {
  271. url : "/list",
  272. templateUrl : "static/tpl/index/sale/quotation_list.html",
  273. controller: 'SaleQuotationListCtrl'
  274. }).state('sale.quotation.item', {
  275. url : "/:id",
  276. templateUrl : "static/tpl/index/sale/quotation_new.html",
  277. controller: 'SaleQuotationNewCtrl'
  278. }).state('sale.order', {
  279. url : "/order",
  280. templateUrl : "static/tpl/index/sale/order.html",
  281. controller: 'SaleOrderCtrl'
  282. }).state('sale.order_detail', {
  283. url : "/order/:id",
  284. templateUrl : "static/tpl/index/sale/order_detail.html",
  285. controller: 'SaleOrderDetailCtrl'
  286. }).state('sale.change', {
  287. url : "/change",
  288. templateUrl : "static/tpl/index/sale/change.html",
  289. controller: 'SaleChangeCtrl'
  290. }).state('sale.change_detail', {
  291. url : "/change/:id",
  292. templateUrl : "static/tpl/index/sale/change_detail.html",
  293. controller: 'SaleChangeDetailCtrl'
  294. }).state('sale.notice', {
  295. url : "/notice",
  296. templateUrl : "static/tpl/index/sale/notice.html",
  297. controller: 'SaleNoticeCtrl'
  298. }).state('sale.send', {
  299. url : "/send",
  300. templateUrl : "static/tpl/index/sale/send.html",
  301. controller: 'SaleSendCtrl'
  302. }).state('sale.send_detail', {
  303. url : "/send/:id",
  304. templateUrl : "static/tpl/index/sale/send_detail.html",
  305. controller: 'SaleSendDetailCtrl'
  306. }).state('sale.forecast', {
  307. url : "/forecast",
  308. templateUrl : "static/tpl/index/sale/forecast.html",
  309. controller: 'SaleForecastCtrl'
  310. }).state('sale.accept', {
  311. url : "/accept",
  312. templateUrl : "static/tpl/index/sale/accept.html",
  313. controller: 'SaleAcceptCtrl'
  314. }).state('sale.returns', {
  315. url : "/returns",
  316. templateUrl : "static/tpl/index/sale/returns.html",
  317. controller: 'SaleReturnsCtrl'
  318. }).state('sale.sample', {
  319. url : "/sample",
  320. templateUrl : "static/tpl/index/sale/sample.html",
  321. controller: 'SaleSampleCtrl'
  322. }).state('sale.sample_detail', {
  323. url : "/sample/:id",
  324. templateUrl : "static/tpl/index/sale/sample_detail.html",
  325. controller: 'SaleSampleDetailCtrl'
  326. }).state('sale.approval', {
  327. url : "/approval",
  328. templateUrl : "static/tpl/index/sale/approval.html",
  329. controller: 'SaleApprovalCtrl'
  330. }).state('sale.prodList', {
  331. url : "/prodList",
  332. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  333. controller : 'ProductListCtrl'
  334. }).state('sale.newProdInfo', {
  335. url : "/newProdInfo",
  336. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  337. controller : 'NewProdInfoCtrl'
  338. }).state('sale.uploadByBatch', {
  339. url : "/uploadByBatch",
  340. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  341. controller : 'UploadByBatchCtrl'
  342. }).state('sale.productDetail', {
  343. url : "/prodList/:id",
  344. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  345. controller : 'ProductDetailCtrl'
  346. }).state('sale.maketodo', {
  347. url : "/maketodo",
  348. templateUrl : "static/tpl/index/make/todo.html"
  349. }).state('sale.maketodo.order', {
  350. url : "/makeorder",
  351. templateUrl : "static/tpl/index/make/order.html",
  352. controller: 'MakeOrderCtrl'
  353. }).state('sale.makeorder', {
  354. url : "/makeorder",
  355. templateUrl : "static/tpl/index/make/order.html",
  356. controller: 'MakeOrderCtrl'
  357. }).state('sale.makeorder_detail', {
  358. url : "/makeorder/:id",
  359. templateUrl : "static/tpl/index/make/order_detail.html",
  360. controller: 'MakeOrderDetailCtrl'
  361. }).state('sale.badOut', {
  362. url : "/badOut",
  363. templateUrl : "static/tpl/index/qc/badOut.html",
  364. controller: 'SaleBadOutCtrl'
  365. }).state('sale.MRB', {
  366. url : "/MRB",
  367. templateUrl : "static/tpl/index/qc/MRB.html",
  368. controller: 'SaleMRBCtrl'
  369. }).state('sale.badIn', {
  370. url : "/badIn",
  371. templateUrl : "static/tpl/index/qc/badIn.html",
  372. controller: 'SaleBadInCtrl'
  373. }).state('sale.makeaccept', {
  374. url : "/makeaccept",
  375. templateUrl : "static/tpl/index/make/accept.html",
  376. controller: 'MakeAcceptCtrl'
  377. }).state('sale.makereturns', {
  378. url : "/makereturns",
  379. templateUrl : "static/tpl/index/make/returns.html",
  380. controller: 'MakeReturnCtrl'
  381. }).state('sale.makechange', {
  382. url : "/makechange",
  383. templateUrl : "static/tpl/index/make/change.html",
  384. controller: 'MakeChangeCtrl'
  385. }).state('sale.makechange_detail', {
  386. url : "/makechange/:id",
  387. templateUrl : "static/tpl/index/make/change_detail.html",
  388. controller: 'MakeChangeDetailCtrl'
  389. }).state('account', {
  390. url : "/account",
  391. views : {
  392. "left-view" : {
  393. templateUrl : "static/tpl/index/account/left.html",
  394. controller: 'LeftCtrl'
  395. },
  396. "right-view" : {
  397. templateUrl : "static/tpl/index/account/right.html"
  398. }
  399. }
  400. }).state('account.index', {
  401. url : "",
  402. templateUrl : "static/tpl/index/account/index.html",
  403. controller: 'RightCtrl'
  404. }).state('account.home', {
  405. url : "/",
  406. templateUrl : "static/tpl/index/account/index.html",
  407. controller: 'RightCtrl'
  408. }).state('baseInfo', {//基础资料
  409. url : "/baseInfo",
  410. views : {
  411. "left-view" : {
  412. },
  413. "right-view" : {
  414. templateUrl : "static/tpl/index/baseInfo/right.html"
  415. }
  416. }
  417. }).state('baseInfo.index', {
  418. url : "/enterpriseList",
  419. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  420. controller: 'EnterpriseListCtrl'
  421. }).state('baseInfo.home', {
  422. url : "/enterpriseList",
  423. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  424. controller: 'EnterpriseListCtrl'
  425. }).state('baseInfo.enterpriseList', {
  426. url : "/enterpriseList",
  427. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  428. controller : 'EnterpriseListCtrl'
  429. }).state('baseInfo.myClient', {
  430. url : "/myClient",
  431. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  432. controller : 'MyClientCtrl'
  433. }).state('baseInfo.mySupplier', {
  434. url : "/mySupplier",
  435. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  436. controller : 'MySupplierCtrl'
  437. }).state('baseInfo.myRequest', {
  438. url : "/myRquest",
  439. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  440. controller : 'AddPartnerRequestCtrl'
  441. }).state('baseInfo.myMessage', {
  442. url : "/myMessage",
  443. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  444. controller : 'AddPartnerMessageCtrl'
  445. }).state('baseInfo.myPartners', {
  446. url : '/myPartners',
  447. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  448. controller : 'MyPartnersCtrl'
  449. }).state('baseInfo.businessGroups', {
  450. url : '/businessGroups',
  451. controller : 'BusinessGroupsCtrl'
  452. }).state('qc', {
  453. url : "/qc",
  454. views : {
  455. "left-view" : {
  456. templateUrl : "static/tpl/index/qc/left.html"
  457. },
  458. "right-view" : {
  459. templateUrl : "static/tpl/index/qc/right.html"
  460. }
  461. }
  462. }).state('qc.index', {
  463. url : "",
  464. templateUrl : "static/tpl/index/qc/index.html"
  465. }).state('qc.home', {
  466. url : "/",
  467. templateUrl : "static/tpl/index/qc/index.html"
  468. }).state('fa', {
  469. url : "/fa",
  470. views : {
  471. "left-view" : {
  472. templateUrl : "static/tpl/index/fa/left.html"
  473. },
  474. "right-view" : {
  475. templateUrl : "static/tpl/index/fa/right.html"
  476. }
  477. }
  478. }).state('fa.index', {
  479. url : "",
  480. templateUrl : "static/tpl/index/fa/index.html"
  481. }).state('fa.home', {
  482. url : "/",
  483. templateUrl : "static/tpl/index/fa/index.html"
  484. }).state('fa.apBill', {
  485. url : "/apBill",
  486. templateUrl : "static/tpl/index/fa/apBill.html",
  487. controller: 'SaleApBillCtrl'
  488. }).state('fa.arCheck', {
  489. url : "/arCheck",
  490. templateUrl : "static/tpl/index/fa/arCheck.html",
  491. controller: 'SaleArCheckCtrl'
  492. }).state('fa.arCheck_detail', {
  493. url : "/arCheck/:id",
  494. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  495. controller: 'SaleArCheckDetailCtrl'
  496. }).state('fa.apCheck', {
  497. url : "/apCheck",
  498. params:{
  499. 'id':null
  500. },
  501. templateUrl : "static/tpl/index/fa/apCheck.html",
  502. controller: 'PurchaseApCheckCtrl'
  503. }).state('fa.apCheck_detail', {
  504. url : "/apCheck/:id",
  505. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  506. controller: 'PurchaseApCheckDetailCtrl'
  507. }).state('fa.apCheckList', {
  508. url : "/apCheckList",
  509. templateUrl : "static/tpl/index/fa/apCheckList.html",
  510. controller: 'PurchaseApCheckListCtrl'
  511. }).state('make', {
  512. url : "/make",
  513. views : {
  514. "left-view" : {
  515. templateUrl : "static/tpl/index/make/left.html"
  516. },
  517. "right-view" : {
  518. templateUrl : "static/tpl/index/make/right.html"
  519. }
  520. }
  521. }).state('make.index', {
  522. url : "",
  523. templateUrl : "static/tpl/index/make/index.html"
  524. }).state('make.home', {
  525. url : "/",
  526. templateUrl : "static/tpl/index/make/index.html"
  527. }).state('cs', {// 客户服务
  528. url : "/cs",
  529. views : {
  530. "left-view" : {
  531. templateUrl : "static/tpl/index/cs/left.html"
  532. },
  533. "right-view" : {
  534. templateUrl : "static/tpl/index/cs/right.html"
  535. }
  536. }
  537. }).state('cs.index', {
  538. url : "",
  539. templateUrl : "static/tpl/index/cs/index.html"
  540. }).state('cs.home', {
  541. url : "/",
  542. templateUrl : "static/tpl/index/cs/index.html"
  543. }).state('search', { //顶部搜索
  544. url: "/search?keyword=",
  545. views : {
  546. "left-view" : {
  547. templateUrl : "static/tpl/index/search/left.html"
  548. },
  549. "right-view" : {
  550. templateUrl: "static/tpl/index/search/search_result.html",
  551. controller: 'TopSearchCtrl'
  552. }
  553. }
  554. }).state('approvalflow', { //审批流
  555. url: "/approvalFlow",
  556. views : {
  557. "left-view" : {
  558. templateUrl : "static/tpl/index/approvalFlow/left.html"
  559. },
  560. "right-view" : {
  561. templateUrl: "static/tpl/index/approvalFlow/right.html",
  562. }
  563. }
  564. }).state('approvalflow.flow', {
  565. url : "/flow",
  566. templateUrl : "static/tpl/index/approvalFlow/home.html",
  567. controller: 'approvalFlowCtrl'
  568. }).state('approvalflow.enterprise', {
  569. url : "/enterprise",
  570. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  571. controller: 'EnterpriseCtrl'
  572. }).state('approvalflow.user', {
  573. url : "/user",
  574. templateUrl : "static/tpl/index/approvalFlow/user.html",
  575. controller: 'UserCtrl'
  576. }).state('approvalflow.log', {
  577. url : "/log",
  578. templateUrl : "static/tpl/index/approvalFlow/log.html",
  579. controller: 'LogCtrl'
  580. }).state('approvalflow.resource', {
  581. url : "/resource",
  582. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  583. controller: 'ResourceCtrl'
  584. }).state('approvalflow.role', {
  585. url : "/role",
  586. templateUrl : "static/tpl/index/approvalFlow/role.html",
  587. controller: 'RoleCtrl'
  588. });
  589. $urlRouterProvider.otherwise('/index');
  590. }]);
  591. /**
  592. * 表示符号
  593. */
  594. app.factory('Symbol', function(){
  595. return {
  596. currency: function(cur) {
  597. if(cur == 'RMB') return '¥';
  598. else if(cur == 'USD') return '$';
  599. else if(cur == 'EUR') return '€';
  600. else if(cur == null || cur == '') return '¥';
  601. else return cur;
  602. }
  603. };
  604. }).factory('Lodop',function(){
  605. return {
  606. getLodop:function(oOBJECT,oEMBED){
  607. var CreatedOKLodop7766=null;
  608. /**************************
  609. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  610. IE系列、IE内核系列的浏览器采用oOBJECT,
  611. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  612. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  613. 64位浏览器指向64位的安装程序install_lodop64.exe。
  614. **************************/
  615. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  616. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  617. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  618. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  619. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  620. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  621. var LODOP;
  622. try{
  623. //=====判断浏览器类型:===============
  624. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  625. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  626. //=====如果页面有Lodop就直接使用,没有则新建:==========
  627. if (oOBJECT!=undefined || oEMBED!=undefined) {
  628. if (isIE)
  629. LODOP=oOBJECT;
  630. else
  631. LODOP=oEMBED;
  632. } else {
  633. if (CreatedOKLodop7766==null){
  634. LODOP=document.createElement("object");
  635. LODOP.setAttribute("width",0);
  636. LODOP.setAttribute("height",0);
  637. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  638. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  639. else LODOP.setAttribute("type","application/x-print-lodop");
  640. document.documentElement.appendChild(LODOP);
  641. CreatedOKLodop7766=LODOP;
  642. } else
  643. LODOP=CreatedOKLodop7766;
  644. };
  645. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  646. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  647. if (navigator.userAgent.indexOf('Chrome')>=0)
  648. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  649. if (navigator.userAgent.indexOf('Firefox')>=0)
  650. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  651. if (is64IE) document.write(strHtm64_Install); else
  652. if (isIE) document.write(strHtmInstall); else
  653. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  654. return LODOP;
  655. } else
  656. if (LODOP.VERSION<"6.1.9.8") {
  657. if (is64IE) document.write(strHtm64_Update); else
  658. if (isIE) document.write(strHtmUpdate); else
  659. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  660. return LODOP;
  661. };
  662. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  663. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  664. //============================================================
  665. return LODOP;
  666. } catch(err) {
  667. if (is64IE)
  668. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  669. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  670. return LODOP;
  671. };
  672. }
  673. }
  674. });
  675. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
  676. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  677. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  678. if (routeState.indexOf('/') > -1)
  679. routeState = routeState.substring(0, routeState.indexOf('/'));
  680. if (routeState.indexOf('.') > -1)
  681. routeState = routeState.substring(0, routeState.indexOf('.'));
  682. $scope.routeState = routeState || 'home';
  683. });
  684. $scope.search = function(keyword) {
  685. if(keyword != null ) {
  686. $rootScope.searchKeyword = keyword;
  687. window.location.hash = '#/search?keyword='+keyword;
  688. }
  689. };
  690. $scope.showMessage = function() {
  691. $rootScope.isOpen = true;
  692. var $modalInstance = $modal.open({
  693. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  694. controller: 'PagingReleaseCtrl'
  695. });
  696. };
  697. }]);
  698. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  699. BaseService.scrollBackToTop();
  700. $scope.active = "todo";
  701. $scope.setActive = function(state) {
  702. if($scope.active != state) {
  703. $scope.active = state;
  704. if($scope.tableParams.page() == 1)
  705. $scope.tableParams.reload();
  706. else
  707. $scope.tableParams.page(1);
  708. }
  709. };
  710. $scope.tableParams = new ngTableParams({
  711. page : 1,
  712. count : 5,
  713. sorting: {
  714. 'releaseDetail.release.date': 'desc'
  715. }
  716. }, {
  717. total : 0,
  718. counts: [5, 10, 25, 50],
  719. getData : function($defer, params) {
  720. $scope.loading = true;
  721. var pageParams = params.url();
  722. var realActive = {};
  723. pageParams.searchFilter = { // 筛选条件
  724. keyword: $scope.keyword
  725. // fromDate: getDateTime($scope.condition.dateFrom),
  726. // endDate: getDateTime($scope.condition.dateTo)
  727. };
  728. // AccountEnterprise.get({}, function(data){
  729. // $scope.loading = false;
  730. // $scope.currentEn = data;
  731. // });
  732. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  733. $scope.loading = false;
  734. if(page) {
  735. params.total(page.totalElement);
  736. $defer.resolve(page.content);
  737. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  738. }
  739. }, function(response){
  740. $scope.loading = false;
  741. toaster.pop('error', '数据加载失败', response.data);
  742. });
  743. }
  744. });
  745. $scope.close = function() {
  746. $modalInstance.close();
  747. };
  748. $scope.checks = {
  749. checked : false
  750. };// 全选框
  751. $scope.checkAll = function() {
  752. angular.forEach($scope.tableParams.data, function(message) {
  753. message.checked = $scope.checks.checked;
  754. });
  755. };
  756. // 单选
  757. $scope.checkOne = function(message) {
  758. message.checked = true;
  759. };
  760. // 标为已读
  761. $scope.setRead = function() {
  762. var selectedMessages = [];
  763. angular.forEach($scope.tableParams.data, function(message) {
  764. if(message.checked) {
  765. selectedMessages.push(message);
  766. }
  767. });
  768. console.log(selectedMessages);
  769. PagingRelease.setRead({}, selectedMessages , function(message) {
  770. $scope.tableParams.page(1);
  771. $scope.tableParams.reload();
  772. });
  773. };
  774. // 搜索框回车
  775. $scope.onSearch = function() {
  776. $scope.tableParams.page(1);
  777. $scope.tableParams.reload();
  778. };
  779. }]);
  780. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  781. var search = $rootScope.searchKeyword;
  782. return function(content, search) {
  783. content = encodeURI(content);
  784. search = encodeURI(search);
  785. var reg = new RegExp(search, 'gim');
  786. var result = content.replace(reg,'<font color="red">$&</font>');
  787. result = decodeURI(result);
  788. return $sce.trustAsHtml(result);
  789. }
  790. }]);
  791. /**
  792. * 顶部搜索
  793. */
  794. app.controller('TopSearchCtrl', ['$scope', '$rootScope', 'getAccountUserSpace', 'ngTableParams', 'toaster', 'BaseService', 'AddPartner', '$filter', '$stateParams', 'SearchProd', '$sce', '$modal', 'InvitationRecord', function($scope, $rootScope, getAccountUserSpace, ngTableParams, toaster, BaseService, AddPartner, $filter, $stateParams, SearchProd, $sce, $modal, InvitationRecord) {
  795. BaseService.scrollBackToTop();
  796. $scope.active = 'all';
  797. $scope.tip = $rootScope.searchKeyword;
  798. // 企业搜索
  799. var getService = function() {
  800. return getAccountUserSpace;
  801. };
  802. $scope.tableParams = new ngTableParams({
  803. page : 1,
  804. count : 5,
  805. sorting: {
  806. }
  807. }, {
  808. total : 0,
  809. counts: [5, 10, 25, 50],
  810. getData : function($defer, params) {
  811. $scope.loading = true;
  812. var pageParams = params.url();
  813. pageParams.keyword = $rootScope.searchKeyword;
  814. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  815. $scope.loading = false;
  816. if(page) {
  817. $scope.total = page.totalElement;
  818. params.total(page.totalElement);
  819. $defer.resolve(page.content);
  820. }
  821. }, function(response) {
  822. $scope.loading = false;
  823. toaster.pop('error', '数据加载失败', response.data);
  824. });
  825. }
  826. });
  827. // 添加合作关系
  828. $scope.addPartner = function(name, businessCode) {
  829. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  830. if(data.success) {
  831. toaster.pop("success", '添加成功', data.success);
  832. }
  833. if(data.error) {
  834. toaster.pop("error", '添加失败', data.error);
  835. }
  836. }, function(response) {
  837. toaster.pop('error','失败',response.data);
  838. });
  839. }
  840. // 物料搜索
  841. var getProdService = function() {
  842. return SearchProd;
  843. };
  844. $scope.prodTableParams = new ngTableParams({
  845. page : 1,
  846. count : 5,
  847. sorting: {
  848. }
  849. }, {
  850. total : 0,
  851. counts: [5, 10, 25, 50],
  852. getData : function($defer, params) {
  853. $scope.loading = true;
  854. var pageParams = params.url();
  855. pageParams.keyword = $rootScope.searchKeyword;
  856. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  857. $scope.loading = false;
  858. if(page) {
  859. $scope.prodtotal = page.totalElement;
  860. params.total(page.totalElement);
  861. $defer.resolve(page.content);
  862. }
  863. }, function(response) {
  864. $scope.loading = false;
  865. toaster.pop('error', '数据加载失败', response.data);
  866. });
  867. }
  868. });
  869. /**
  870. * 向企业购买
  871. */
  872. $scope.PurcByEn = function(businessCode) {
  873. $rootScope.businessCode = businessCode;
  874. window.location.hash = "#/purc/addOrder";
  875. }
  876. /**
  877. * 选中单个物料购买
  878. * @param businessCode
  879. * @param id
  880. */
  881. $scope.PurcByEnAndProd = function(businessCode, id) {
  882. $rootScope.businessCode = businessCode;
  883. $rootScope.prodId = id;
  884. window.location.hash = "#/purc/addOrder";
  885. }
  886. /**
  887. * 邀请注册商务平台
  888. */
  889. $scope.invite = function(name) {
  890. var modalInstance = $modal.open({
  891. animation: true,
  892. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  893. controller: 'InviteCtrl',
  894. resolve: {
  895. enname: function(){return name}
  896. }
  897. });
  898. modalInstance.result.then(function(data) {
  899. InvitationRecord.invite({formStore: data}, {}, function(data) {
  900. if(data.success) {
  901. toaster.pop('success', '提示', data.success);
  902. }
  903. if(data.error) {
  904. toaster.pop('error', '提示', data.error);
  905. }
  906. }, function(response) {
  907. toaster.pop('error', '提示', response.data);
  908. });
  909. });
  910. }
  911. }]);
  912. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  913. $scope.enter = {
  914. vendname: enname
  915. };
  916. $scope.save = function(enter) {
  917. if(!enter.vendusertel && !enter.venduseremail) {
  918. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  919. } else {
  920. $modalInstance.close(enter);
  921. }
  922. }
  923. $scope.cancel = function() {
  924. $modalInstance.dismiss();
  925. }
  926. }]);
  927. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  928. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  929. //手机号码格式验证
  930. // var checkTel = function(data){
  931. // var userTel = data.userTel;
  932. // $scope.checkResult = false;
  933. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  934. // if(!(telephone).test(userTel)){
  935. // var modalInstance = $modal.open({
  936. // animation: true,
  937. // templateUrl: 'static/tpl/index/account/checkTel.html',
  938. // controller: 'CheckTelCtrl',
  939. // backdrop: 'static',
  940. // keyboard: false,
  941. // resolve: {
  942. // user: function(){
  943. // return data;
  944. // },
  945. // }
  946. // });
  947. // modalInstance.result.then(function(){
  948. // }, function(){
  949. //
  950. // });
  951. // } else {
  952. // $scope.checkResult = true;
  953. // }
  954. // };
  955. AuthenticationService.getAuthentication().success(function(data) {
  956. if(data.enterprises) {
  957. data.enterprise = data.enterprises[data.enterprises.length - 1];
  958. if(data.enterprises.length > 1) {
  959. var enSelect = [];
  960. angular.forEach(data.enterprises, function(e){
  961. if(e.current)
  962. data.enterprise = e;
  963. else
  964. enSelect.push(e);
  965. });
  966. data.enSelect = enSelect;
  967. }
  968. }
  969. $scope.userInfo = data;
  970. if (data == null || !data.userUU) {
  971. $scope.isAuthed = false;
  972. AuthenticationService.redirectSignin();
  973. } else {
  974. //跳转到手机号码验证
  975. // checkTel($scope.userInfo);
  976. }
  977. });
  978. $scope.logout = function() {
  979. AuthenticationService.logout();
  980. };
  981. $scope.switchto = function(enUU) {// 切换企业
  982. AuthenticationService.reSignin(enUU).success(function(){
  983. $window.location.reload();
  984. });
  985. };
  986. $scope.addFavorite = function(){
  987. var url = encodeURI(window.location.href);
  988. try{
  989. //ie浏览器收藏方式
  990. window.external.addFavorite(url, "优软商务平台");
  991. }catch(e) {
  992. try{
  993. //火狐浏览器收藏方式
  994. window.sidebar.addPanel("优软商务平台", url);
  995. }catch (e) {
  996. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  997. "或手动在浏览器里进行设置。");
  998. }
  999. }
  1000. };
  1001. }]);
  1002. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1003. $scope.image = {src: null};
  1004. // 图片上传成功之后
  1005. $scope.onUploadSuccess = function(data){
  1006. var path = data.path;
  1007. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1008. $scope.$apply(function(){
  1009. $scope.image.src = data.path;
  1010. $scope.image.thumb = path;
  1011. });
  1012. };
  1013. $scope.close = function() {
  1014. $modalInstance.dismiss();
  1015. };
  1016. $scope.confirm = function() {
  1017. $modalInstance.close($scope.image);
  1018. $scope.imageUrl = null;
  1019. };
  1020. }]);
  1021. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', function($scope, SnapshotService, BaseService){
  1022. BaseService.scrollBackToTop();
  1023. SnapshotService.getTodo(function(data){
  1024. $scope.todo = data;
  1025. });
  1026. }]);
  1027. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1028. SaleTruck.query({}, function(data){
  1029. $rootScope.truck = data;
  1030. $scope.truckCount = data ? data.length : 0;
  1031. });
  1032. $scope.$watch(function(){
  1033. return $rootScope.truck;
  1034. }, function(data) {
  1035. $scope.truckCount = data ? data.length : 0;
  1036. }, true);
  1037. $scope.clearAll = function() {
  1038. SaleTruck.remove({}, function(){
  1039. $rootScope.truck = [];
  1040. });
  1041. };
  1042. $scope.openTrack = function() {
  1043. $modal.open({
  1044. templateUrl: 'static/tpl/index/sale/track.html',
  1045. controller: 'TruckModalCtrl',
  1046. size: 'lg'
  1047. }).result.then(function(s){
  1048. if(s) {
  1049. $scope.clearAll();
  1050. $rootScope.dataChanged = true;
  1051. }
  1052. });
  1053. };
  1054. }]);
  1055. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  1056. $scope.saleSend = {sendItems: []};
  1057. SaleTruck.detail({}, function(data){
  1058. // 按物料编号排序
  1059. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1060. });
  1061. $scope.remove = function(index, notice) {
  1062. SaleTruck.remove({noticeId: notice.id}, function(data){
  1063. $rootScope.truck = data;
  1064. $scope.notices.splice(index, 1);
  1065. });
  1066. };
  1067. $scope.$watch(function(){
  1068. return $scope.notices;
  1069. }, function(data) {
  1070. var q = 0, t = 0;
  1071. if(data) {
  1072. angular.forEach(data,function(d){
  1073. q += d.thisSendQty;
  1074. t += d.thisSendQty * d.orderItem.price;
  1075. });
  1076. }
  1077. $scope.totalQty = q;
  1078. $scope.total = t;
  1079. }, true);
  1080. $scope.cancel = function() {
  1081. $modalInstance.close();
  1082. };
  1083. $scope.send = function() {// 发货
  1084. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1085. toaster.pop('error', '错误', '请输入送货单号');
  1086. return;
  1087. }
  1088. var currency = $scope.notices[0].orderItem.order.currency,
  1089. custUU = $scope.notices[0].enUU,
  1090. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1091. var num = 1;
  1092. for(var i in $scope.notices) {
  1093. var item = $scope.notices[i];
  1094. if(item.id) {
  1095. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1096. valid = false;
  1097. break;
  1098. }
  1099. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1100. }
  1101. }
  1102. if(!valid) {
  1103. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1104. } else {
  1105. var send = angular.extend(angular.copy($scope.saleSend), {
  1106. currency: currency,
  1107. custUU: custUU,
  1108. payments: payments,
  1109. sendItems: items
  1110. });
  1111. PurcNotice.sendByBatch({}, send, function(data){
  1112. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1113. $modalInstance.close(true);
  1114. $state.go('sale.send_detail', {id: data.id});
  1115. }, function(response){
  1116. toaster.pop('error', '错误', response.data);
  1117. });
  1118. }
  1119. };
  1120. }]);
  1121. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1122. SaleStat.cust({}, function(data){
  1123. var p = [], q = [];
  1124. angular.forEach(data.month, function(d){
  1125. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1126. });
  1127. angular.forEach(data.year, function(d){
  1128. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1129. });
  1130. $scope.custCharts = {
  1131. month : {
  1132. chartType : 'pie',
  1133. datas : {
  1134. data : p
  1135. },
  1136. config : {
  1137. labels : false,
  1138. title : "客户月采购量排行榜",
  1139. legend : {
  1140. display : true,
  1141. position : 'right'
  1142. },
  1143. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1144. click : function(d) {
  1145. },
  1146. mouseover : function(d) {
  1147. },
  1148. mouseout : function(d) {
  1149. },
  1150. innerRadius : 0,
  1151. lineLegend : 'lineEnd'
  1152. }
  1153. },
  1154. year : {
  1155. chartType : 'pie',
  1156. datas : {
  1157. data : q
  1158. },
  1159. config : {
  1160. labels : false,
  1161. title : "客户年采购量排行榜",
  1162. legend : {
  1163. display : true,
  1164. position : 'right'
  1165. },
  1166. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1167. click : function(d) {
  1168. },
  1169. mouseover : function(d) {
  1170. },
  1171. mouseout : function(d) {
  1172. },
  1173. innerRadius : 0,
  1174. lineLegend : 'lineEnd'
  1175. }
  1176. }
  1177. };
  1178. });
  1179. SaleStat.seller({}, function(data){
  1180. var p = [], q = [];
  1181. angular.forEach(data.month, function(d){
  1182. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1183. });
  1184. angular.forEach(data.year, function(d){
  1185. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1186. });
  1187. $scope.sellerCharts = {
  1188. month : {
  1189. chartType : 'pie',
  1190. datas : {
  1191. data : p
  1192. },
  1193. config : {
  1194. labels : false,
  1195. title : "业务员月销量排行榜",
  1196. legend : {
  1197. display : true,
  1198. position : 'right'
  1199. },
  1200. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1201. click : function(d) {
  1202. },
  1203. mouseover : function(d) {
  1204. },
  1205. mouseout : function(d) {
  1206. },
  1207. innerRadius : 0,
  1208. lineLegend : 'lineEnd'
  1209. }
  1210. },
  1211. year : {
  1212. chartType : 'pie',
  1213. datas : {
  1214. data : q
  1215. },
  1216. config : {
  1217. labels : false,
  1218. title : "业务员年销量排行榜",
  1219. legend : {
  1220. display : true,
  1221. position : 'right'
  1222. },
  1223. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1224. click : function(d) {
  1225. },
  1226. mouseover : function(d) {
  1227. },
  1228. mouseout : function(d) {
  1229. },
  1230. innerRadius : 0,
  1231. lineLegend : 'lineEnd'
  1232. }
  1233. }
  1234. };
  1235. });
  1236. }]);
  1237. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1238. SaleStat.get({}, function(data){
  1239. var p = [], q = [], r = [];
  1240. angular.forEach(data.day, function(d){
  1241. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1242. });
  1243. angular.forEach(data.month, function(d){
  1244. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1245. });
  1246. angular.forEach(data.year, function(d){
  1247. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1248. });
  1249. $scope.charts = {
  1250. day : {
  1251. chartType : "line",
  1252. datas: {
  1253. series: ['销售额'],
  1254. data: p
  1255. },
  1256. config : {
  1257. "labels": false,
  1258. "title": "销售额统计(近15日线)",
  1259. "legend": {
  1260. "display": true,
  1261. "position": "right"
  1262. },
  1263. colors : [ '#4D9934'],
  1264. "innerRadius": 0,
  1265. "lineLegend": "lineEnd"
  1266. }
  1267. },
  1268. month: {
  1269. chartType : "line",
  1270. datas: {
  1271. series: ['销售额'],
  1272. data: q
  1273. },
  1274. config : {
  1275. "labels": false,
  1276. "title": "销售额统计(近12月线)",
  1277. "legend": {
  1278. "display": true,
  1279. "position": "right"
  1280. },
  1281. colors : [ '#4D9934'],
  1282. "innerRadius": 0,
  1283. "lineLegend": "lineEnd"
  1284. }
  1285. },
  1286. year: {
  1287. chartType : "line",
  1288. datas: {
  1289. series: ['销售额'],
  1290. data: r
  1291. },
  1292. config : {
  1293. "labels": false,
  1294. "title": "销售额统计(近10年线)",
  1295. "legend": {
  1296. "display": true,
  1297. "position": "right"
  1298. },
  1299. colors : [ '#4D9934'],
  1300. "innerRadius": 0,
  1301. "lineLegend": "lineEnd"
  1302. }
  1303. }
  1304. };
  1305. });
  1306. }]);
  1307. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1308. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1309. $scope.notices = data;
  1310. });
  1311. $scope.dateTime = new Date();
  1312. }]);
  1313. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1314. SnapshotService.getTender(250, function(data){
  1315. $scope.tenders = data;
  1316. console.log(data);
  1317. var newDate = new Date();
  1318. newDate = newDate.setDate(newDate.getDate() - 3);
  1319. angular.forEach($scope.tenders, function(tender) {
  1320. if (tender.date > newDate) {
  1321. tender.isNew = true;
  1322. } else {
  1323. tender.isNew = false;
  1324. }
  1325. });
  1326. });
  1327. SnapshotService.getOpenTender(250, function(data){
  1328. $scope.openTenders = data;
  1329. var newDate = new Date();
  1330. console.log(data);
  1331. newDate = newDate.setDate(newDate.getDate() - 3);
  1332. angular.forEach($scope.openTenders, function(tender) {
  1333. if (tender.date > newDate) {
  1334. tender.isNew = true;
  1335. } else {
  1336. tender.isNew = false;
  1337. }
  1338. });
  1339. });
  1340. $scope.dateTime = new Date();
  1341. }]);
  1342. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1343. VendorService.getCount(function(date){
  1344. $scope.count = date;
  1345. });
  1346. }]);
  1347. // 客户
  1348. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1349. BaseService.scrollBackToTop();
  1350. $scope.userInfoResult = true;
  1351. AuthenticationService.getAuthentication().success(function(data) {
  1352. $scope.loading = false;
  1353. $scope.thisUser = data;
  1354. });
  1355. var getCustInfos = function(custuu) {
  1356. if(custuu) {
  1357. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1358. $scope.custInfos = data;
  1359. var getPage = function(page, size){
  1360. if($scope.custInfos) {
  1361. var result = {};
  1362. result.totalCount = $scope.custInfos.length;
  1363. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1364. if($scope.custInfos.length % size == 0) {
  1365. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1366. }else {
  1367. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1368. }
  1369. result.first = page == 1;
  1370. result.last = page == result.totalPage;
  1371. result.page = page;
  1372. result.next = page - 0 + 1;
  1373. result.pre = page - 1;
  1374. return result;
  1375. }
  1376. }
  1377. $scope.userdata = getPage(1,4);
  1378. $scope.first = function (){
  1379. $scope.userdata = getPage($scope.userdata.pre,4);
  1380. }
  1381. $scope.last = function (){
  1382. $scope.userdata = getPage($scope.userdata.next,4);
  1383. }
  1384. }, function(response){
  1385. $scope.loading = false;
  1386. toaster.pop('error', '数据加载失败', response.data);
  1387. });
  1388. }
  1389. }
  1390. $scope.addUserInfo = function(customer) {
  1391. //TODO
  1392. if ($scope.thisUser.sys) {
  1393. var modalInstance = $modal.open({
  1394. animation: true,
  1395. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1396. controller: 'AddUserInfoCtrl',
  1397. resolve: {
  1398. customer: function() {
  1399. return customer;
  1400. }
  1401. }
  1402. });
  1403. modalInstance.result.then(function(changed, checked){
  1404. if(changed) {
  1405. if(checked)
  1406. $scope.newUser.roles = checked;
  1407. else
  1408. loadUsers();
  1409. }
  1410. });
  1411. } else {
  1412. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1413. }
  1414. }
  1415. $scope.showUserInfo = function(customer,boo) {
  1416. $scope.custInfo = customer;
  1417. if(boo) {
  1418. getCustInfos(customer.myEnterprise.uu);
  1419. $scope.userInfoResult = true;
  1420. }
  1421. }
  1422. $scope.customerParams = new ngTableParams({
  1423. page : 1,
  1424. count : 10
  1425. }, {
  1426. total : 0,
  1427. counts: [5, 10, 25, 50],
  1428. getData : function($defer, params) {
  1429. $scope.loading = true;
  1430. var pageParams = params.url();
  1431. pageParams.keyword = $scope.keyword;
  1432. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1433. $scope.loading = false;
  1434. if(page) {
  1435. params.total(page.totalElement);
  1436. $defer.resolve(page.content);
  1437. }
  1438. $scope.totalCount = page.totalElement;
  1439. }, function(response){
  1440. $scope.loading = false;
  1441. toaster.pop('error', '数据加载失败', response.data);
  1442. });
  1443. }
  1444. });
  1445. // 搜索框回车
  1446. $scope.onSearch = function(keyword) {
  1447. $scope.customerParams.page(1);
  1448. $scope.customerParams.reload();
  1449. $scope.tip = keyword;
  1450. };
  1451. // 查看详情
  1452. $scope.viewDetail = function(id) {
  1453. console.log(id);
  1454. window.location.hash = "#/sale/customer/" + id;
  1455. }
  1456. }]);
  1457. // 客户详情
  1458. app.controller('CustomerDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', 'VendorService', 'AuthenticationService', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope, VendorService, AuthenticationService) {
  1459. BaseService.scrollBackToTop();
  1460. $scope.userInfoResult = true;
  1461. AuthenticationService.getAuthentication().success(function(data) {
  1462. $scope.loading = false;
  1463. $scope.thisUser = data;
  1464. });
  1465. $scope.vendorContacts = [];
  1466. var loadData = function() {
  1467. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1468. $scope.customer = data.myEnterprise;
  1469. $scope.customerInfo = data;
  1470. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1471. $scope.Contacts = data;
  1472. });
  1473. // 查看已分配人员
  1474. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1475. $scope.custInfos = data;
  1476. var getPage = function(page, size){
  1477. if($scope.custInfos) {
  1478. var result = {};
  1479. result.totalCount = $scope.custInfos.length;
  1480. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1481. if($scope.custInfos.length % size == 0) {
  1482. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1483. }else {
  1484. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1485. }
  1486. result.first = page == 1;
  1487. result.last = page == result.totalPage;
  1488. result.page = page;
  1489. result.next = page - 0 + 1;
  1490. result.pre = page - 1;
  1491. return result;
  1492. }
  1493. }
  1494. $scope.userdata = getPage(1,4);
  1495. $scope.first = function (){
  1496. $scope.userdata = getPage($scope.userdata.pre,4);
  1497. }
  1498. $scope.last = function (){
  1499. $scope.userdata = getPage($scope.userdata.next,4);
  1500. }
  1501. }, function(response){
  1502. $scope.loading = false;
  1503. toaster.pop('error', '数据加载失败', response.data);
  1504. });
  1505. });
  1506. };
  1507. loadData();
  1508. // 新增客户联系人
  1509. $scope.addContact = function(uu) {
  1510. var modalInstance = $modal.open({
  1511. animation: true,
  1512. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1513. controller: 'AddContacCtrl',
  1514. resolve: {
  1515. }
  1516. });
  1517. modalInstance.result.then(function(data) {
  1518. $scope.contact = data;
  1519. $scope.contact.myenuu = uu;
  1520. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1521. toaster.pop('success', '提示', '联系人保存成功');
  1522. $scope.Contacts.push(data);
  1523. }, function(response) {
  1524. toaster.pop('error', '失败', response.data);
  1525. });
  1526. });
  1527. }
  1528. // 编辑客户联系人
  1529. $scope.edit = function(contact) {
  1530. var modalInstance = $modal.open({
  1531. animation: true,
  1532. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  1533. controller: 'EditContacCtrl',
  1534. resolve: {
  1535. contact: function() {
  1536. return contact;
  1537. }
  1538. }
  1539. });
  1540. modalInstance.result.then(function(data) {
  1541. $scope.contact = data;
  1542. Vendor.saveContact({}, $scope.contact, function(data) {
  1543. toaster.pop('success', '提示', '联系人修改成功');
  1544. }, function(response) {
  1545. toaster.pop('error', '失败', response.data);
  1546. });
  1547. });
  1548. }
  1549. // 删除客户联系人
  1550. $scope.deleteById = function(id, index) {
  1551. $scope.Contacts.splice(index, 1);
  1552. Vendor.deleteContact({id: id}, {}, function(data) {
  1553. toaster.pop('success', '提示', '供应商联系人删除成功');
  1554. }, function(response) {
  1555. toaster.pop('error', '提示', response.data);
  1556. });
  1557. }
  1558. // 供应商物料信息
  1559. $scope.viewProdList = function(uu){
  1560. $scope.uu = uu;
  1561. $scope.tableParams.page(1);
  1562. $scope.tableParams.reload();
  1563. };
  1564. // 搜索框回车
  1565. $scope.onSearch = function(keyword) {
  1566. $scope.keyword = keyword;
  1567. $scope.tableParams.page(1);
  1568. $scope.tableParams.reload();
  1569. };
  1570. // 供应商物料信息
  1571. $scope.tableParams = new ngTableParams({
  1572. page : 1,
  1573. count : 10
  1574. }, {
  1575. total : 0,
  1576. counts: [5, 10, 25, 50],
  1577. getData : function($defer, params) {
  1578. $scope.loading = true;
  1579. var pageParams = params.url();
  1580. pageParams.custUU = $scope.uu;
  1581. pageParams.keyword = $scope.keyword;
  1582. $scope.tip = $scope.keyword;
  1583. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1584. $scope.loading = false;
  1585. if(page) {
  1586. params.total(page.totalElement);
  1587. $scope.total = page.totalElement;
  1588. $defer.resolve(page.content);
  1589. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1590. }
  1591. }, function(response){
  1592. $scope.loading = false;
  1593. toaster.pop('error', '数据加载失败', response.data);
  1594. });
  1595. }
  1596. });
  1597. $scope.addUserInfo = function() {
  1598. //TODO
  1599. if ($scope.thisUser.sys) {
  1600. var modalInstance = $modal.open({
  1601. animation: true,
  1602. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1603. controller: 'AddUserInfoCtrl',
  1604. resolve: {
  1605. customer: function() {
  1606. return $scope.customerInfo;
  1607. }
  1608. }
  1609. });
  1610. modalInstance.result.then(function(changed, checked){
  1611. if(changed) {
  1612. if(checked)
  1613. $scope.newUser.roles = checked;
  1614. else
  1615. loadUsers();
  1616. }
  1617. });
  1618. } else {
  1619. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1620. }
  1621. }
  1622. }]);
  1623. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1624. $scope.checkboxes = {
  1625. checked : false
  1626. };
  1627. $scope.loading = true;
  1628. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1629. $scope.userinfos = data;
  1630. $scope.loading = false;
  1631. })
  1632. // 点击勾选全部的复选框
  1633. $scope.checkAll = function() {
  1634. angular.forEach($scope.userinfos, function(item) {
  1635. item.distribute = $scope.checkboxes.checked;
  1636. });
  1637. };
  1638. // 点击其中一个明细的复选框
  1639. $scope.checkOne = function(vendor){
  1640. var result = true;
  1641. angular.forEach($scope.userinfos, function(item) {
  1642. if(item.distribute != true){
  1643. result = false;
  1644. return;
  1645. }
  1646. });
  1647. $scope.checkboxes.checked = result;
  1648. };
  1649. $scope.close = function(save) {
  1650. var chooseResult = [];
  1651. if(save) {
  1652. if(customer.myEnterprise.uu) {
  1653. angular.forEach($scope.userinfos, function(item, i) {
  1654. chooseResult.push(item);
  1655. });
  1656. if(chooseResult.length > 0) {
  1657. $scope.loading = true;
  1658. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1659. $scope.loading = false;
  1660. toaster.pop('success', '提示', '保存成功');
  1661. $modalInstance.close(false);
  1662. }, function(response){
  1663. $scope.loading = false;
  1664. toaster.pop('error', '保存失败', response.data);
  1665. $modalInstance.close(false);
  1666. })
  1667. } else {
  1668. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1669. }
  1670. } else {
  1671. $modalInstance.close(true, $scope.checkboxes.checked);
  1672. }
  1673. } else {
  1674. $modalInstance.close(false);
  1675. }
  1676. };
  1677. }]);
  1678. /**
  1679. * 页面状态按钮过滤
  1680. */
  1681. var getState = function(active) {
  1682. var fn = 'get';
  1683. switch(active) {
  1684. case 'done':
  1685. fn = 'getDone';break;
  1686. case 'todo':
  1687. fn = 'getTodo';break;
  1688. case 'end':
  1689. fn = 'getEnd';break;
  1690. case 'waiting':
  1691. fn = 'getWaiting';break;
  1692. case 'invalid':
  1693. fn = 'getInvalid';break;
  1694. }
  1695. return fn;
  1696. };
  1697. /**
  1698. * 改变单据日期范围
  1699. */
  1700. var getDateCondition = function(zone, condition) {
  1701. var date = new Date();
  1702. if(zone == -1) {
  1703. condition.dateFrom = null;
  1704. condition.dateTo = null;
  1705. } else if(zone == 1) {
  1706. date.setMonth(date.getMonth() - 1);
  1707. condition.dateFrom = date;
  1708. condition.dateTo = new Date();
  1709. } else if (zone == 6) {
  1710. date.setMonth(date.getMonth() - 6);
  1711. condition.dateFrom = date;
  1712. condition.dateTo = new Date();
  1713. } else {
  1714. date.setMonth(date.getMonth() - 6);
  1715. condition.dateFrom = null;
  1716. condition.dateTo = date;
  1717. }
  1718. };
  1719. /**
  1720. * 改变单据交货日期范围
  1721. */
  1722. var getDelveryCondition = function(zone, condition) {
  1723. var date = new Date();
  1724. if(zone == -1) {
  1725. condition.deliveryFrom = null;
  1726. condition.deliveryTo = null;
  1727. } else if(zone == 1) {
  1728. date.setMonth(date.getMonth() + 1);
  1729. condition.deliveryTo = date;
  1730. condition.deliveryFrom = new Date();
  1731. } else if (zone == 2) {
  1732. date.setMonth(date.getMonth() + 2);
  1733. condition.deliveryTo = date;
  1734. condition.deliveryFrom = new Date();
  1735. }
  1736. };
  1737. /**
  1738. * 将日期转化为整数日期
  1739. */
  1740. var getDateTime = function(date) {
  1741. if(angular.isDate(date)) {
  1742. return date.getTime();
  1743. } else {
  1744. return null;
  1745. }
  1746. };
  1747. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1748. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1749. BaseService.scrollBackToTop();
  1750. $scope.active = 'all';
  1751. $scope.dateZoneText = '不限';
  1752. $scope.deliveryZoneText = '不限';
  1753. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1754. $scope.changeDateZone = function(zone) {
  1755. $scope.condition.dateZone = zone;
  1756. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1757. $scope.condition.$dateZoneOpen = false;
  1758. getDateCondition(zone, $scope.condition);
  1759. $scope.tableParams.reload();
  1760. };
  1761. $scope.changeDeliveryZone = function(zone) {
  1762. $scope.condition.deliveryZoneText = zone;
  1763. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1764. $scope.condition.$delievryZoneOpen = false;
  1765. getDelveryCondition(zone, $scope.condition);
  1766. $scope.tableParams.reload();
  1767. };
  1768. // 切换单据类型
  1769. $scope.setActive = function(state) {
  1770. if($scope.active != state) {
  1771. $scope.active = state;
  1772. if($scope.tableParams.page() == 1)
  1773. $scope.tableParams.reload();
  1774. else
  1775. $scope.tableParams.page(1);
  1776. }
  1777. };
  1778. var getPurcStatus = function(active) {
  1779. var fn = 'getPurcAll';
  1780. switch(active) {
  1781. case 'done':
  1782. fn = 'getPurcDone';break;
  1783. case 'todo':
  1784. fn = 'getPurcTodo';break;
  1785. case 'end':
  1786. fn = 'getPurcEnd';break;
  1787. case 'waiting':
  1788. fn = 'getPurcWaiting';break;
  1789. }
  1790. return fn;
  1791. }
  1792. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1793. page : 1,
  1794. count : 5,
  1795. sorting: {
  1796. display: 'desc',
  1797. date: 'desc'
  1798. }
  1799. }, {
  1800. total : 0,
  1801. counts: [5, 10, 15, 25, 50],
  1802. getData : function($defer, params) {// 获取数据的方法
  1803. $scope.loading = true;
  1804. var pageParams = params.url();
  1805. pageParams.searchFilter = { // 筛选条件
  1806. keyword: $scope.keyword,
  1807. fromDate: getDateTime($scope.condition.dateFrom),
  1808. endDate: getDateTime($scope.condition.dateTo)
  1809. };
  1810. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1811. $scope.loading = false;
  1812. if(page) {
  1813. $defer.resolve(page.content);
  1814. params.total(page.totalElement);
  1815. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1816. }
  1817. }, function(response){
  1818. $scope.loading = false;
  1819. toaster.pop('error', '数据加载失败', response.data);
  1820. });
  1821. }
  1822. });
  1823. $scope.getReply = function(item) {
  1824. if(!item.replies) {
  1825. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1826. item.replies = replies;
  1827. });
  1828. }
  1829. };
  1830. $scope.getOrderTotal = function(items) {
  1831. var sum = 0;
  1832. angular.forEach(items, function(item){
  1833. sum += item.qty * item.price;
  1834. });
  1835. return sum;
  1836. };
  1837. $scope.openDatePicker = function($event, item, openParam) {
  1838. $event.preventDefault();
  1839. $event.stopPropagation();
  1840. item[openParam] = !item[openParam];
  1841. };
  1842. $scope.parseDate = function(dateStr) {
  1843. if(dateStr)
  1844. return Date.parse(dateStr, 'yyyy-MM-dd');
  1845. return new Date();
  1846. };
  1847. $scope.checkboxes = {
  1848. checked : false
  1849. };
  1850. // 点击勾选全部的复选框
  1851. $scope.checkAll = function(){
  1852. angular.forEach($scope.tableParams.data, function(item) {
  1853. item.$selected = $scope.checkboxes.checked;
  1854. });
  1855. };
  1856. // 点击其中一个明细的复选框
  1857. $scope.checkOne = function(order){
  1858. var result = true;
  1859. angular.forEach($scope.tableParams.data, function(item) {
  1860. if(item.$selected != true){
  1861. result = false;
  1862. return;
  1863. }
  1864. });
  1865. $scope.checkboxes.checked = result;
  1866. };
  1867. // 搜索框回车
  1868. $scope.onSearch = function(keyword) {
  1869. $scope.tableParams.page(1);
  1870. $scope.tableParams.reload();
  1871. $scope.tip = keyword;
  1872. };
  1873. // 选择查找日期
  1874. $scope.onDateCondition = function(){
  1875. $scope.tableParams.page(1);
  1876. $scope.tableParams.reload();
  1877. };
  1878. }]);
  1879. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1880. var loadData = function() {
  1881. PurcOrder.get({id: $stateParams.id}, function(data){
  1882. $scope.order = data;
  1883. var sum = 0;
  1884. angular.forEach($scope.order.orderItems, function(item){
  1885. sum += item.qty * item.price;
  1886. });
  1887. $scope.order.total = sum;
  1888. if($scope.order.display == 1) {//未查看的设为已查看
  1889. $scope.setDisplay('setRead', $scope.order.id);
  1890. }
  1891. $scope.loading = false;
  1892. });
  1893. };
  1894. loadData();
  1895. $scope.getReply = function(item) {
  1896. if(!item.replies) {
  1897. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1898. item.replies = replies;
  1899. });
  1900. }
  1901. };
  1902. $scope.openDatePicker = function($event, item, openParam) {
  1903. $event.preventDefault();
  1904. $event.stopPropagation();
  1905. item[openParam] = !item[openParam];
  1906. };
  1907. $scope.onReplyClick = function(item, inverse) {
  1908. if(item.reply) {
  1909. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1910. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1911. return;
  1912. }
  1913. var reply = angular.copy(item.reply);
  1914. if(reply.delivery) {
  1915. if(typeof reply.delivery == 'object')
  1916. reply.delivery = reply.delivery.getTime();
  1917. } else {
  1918. reply.delivery = item.delivery;
  1919. }
  1920. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1921. $scope.loading = true;
  1922. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1923. $scope.loading = false;
  1924. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1925. loadData();
  1926. }, function(response){
  1927. $scope.loading = false;
  1928. toaster.pop('error', '回复失败', response.data);
  1929. });
  1930. }
  1931. };
  1932. // // 采购单
  1933. // $scope.print = function(order) {
  1934. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  1935. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1936. // };
  1937. //设置为已查看
  1938. $scope.setDisplay = function(state, orderId) {
  1939. if(orderId) {//设置单个
  1940. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1941. // $scope.tableParams.reload();
  1942. }, function() {
  1943. toaster.pop('error', '错误', "设置失败");
  1944. });
  1945. } else {//设置已勾选的
  1946. var str = null;
  1947. angular.forEach($scope.tableParams.data, function(order) {
  1948. if(order.$selected == true) {
  1949. if(str != null && str != '') str += ',';
  1950. str += order.id;
  1951. }
  1952. });
  1953. if(str != null && str != '') {
  1954. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1955. $scope.tableParams.reload();
  1956. }, function() {
  1957. toaster.pop('error', '错误', "设置失败");
  1958. });
  1959. }
  1960. }
  1961. };
  1962. }]);
  1963. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  1964. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  1965. BaseService.scrollBackToTop();
  1966. $scope.active = 'todo';
  1967. $scope.dateZoneText = '不限';
  1968. $scope.deliveryZoneText = '不限';
  1969. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1970. $scope.changeDateZone = function(zone) {
  1971. $scope.condition.dateZone = zone;
  1972. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1973. $scope.condition.$dateZoneOpen = false;
  1974. getDateCondition(zone, $scope.condition);
  1975. $scope.tableParams.reload();
  1976. };
  1977. $scope.changeDeliveryZone = function(zone) {
  1978. $scope.condition.deliveryZoneText = zone;
  1979. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1980. $scope.condition.$delievryZoneOpen = false;
  1981. getDelveryCondition(zone, $scope.condition);
  1982. $scope.tableParams.reload();
  1983. };
  1984. // 切换单据类型
  1985. $scope.setActive = function(state) {
  1986. if($scope.active != state) {
  1987. $scope.active = state;
  1988. if($scope.tableParams.page() == 1)
  1989. $scope.tableParams.reload();
  1990. else
  1991. $scope.tableParams.page(1);
  1992. }
  1993. };
  1994. // 切换数据来源(正常数据 or 历史数据)
  1995. var getService = function() {
  1996. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  1997. };
  1998. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1999. page : 1,
  2000. count : 5,
  2001. sorting: {
  2002. display: 'desc',
  2003. date: 'desc',
  2004. id: 'desc'
  2005. }
  2006. }, {
  2007. total : 0,
  2008. counts: [5, 10, 15, 25, 50],
  2009. getData : function($defer, params) { // 获取数据的方法
  2010. $scope.loading = true;
  2011. var pageParams = params.url();
  2012. pageParams.searchFilter = { // 筛选条件
  2013. keyword: $scope.keyword,
  2014. fromDate: getDateTime($scope.condition.dateFrom),
  2015. endDate: getDateTime($scope.condition.dateTo)
  2016. };
  2017. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2018. $scope.loading = false;
  2019. if(page) {
  2020. $defer.resolve(page.content);
  2021. params.total(page.totalElement);
  2022. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2023. }
  2024. }, function(response){
  2025. $scope.loading = false;
  2026. toaster.pop('error', '数据加载失败', response.data);
  2027. });
  2028. }
  2029. });
  2030. $scope.getOrderTotal = function(items) {
  2031. var sum = 0;
  2032. angular.forEach(items, function(item){
  2033. sum += item.qty * item.price;
  2034. });
  2035. return sum;
  2036. };
  2037. $scope.openDatePicker = function($event, item, openParam) {
  2038. $event.preventDefault();
  2039. $event.stopPropagation();
  2040. item[openParam] = !item[openParam];
  2041. };
  2042. $scope.parseDate = function(dateStr) {
  2043. if(dateStr)
  2044. return Date.parse(dateStr, 'yyyy-MM-dd');
  2045. return new Date();
  2046. };
  2047. $scope.onReplyClick = function(item, inverse) {
  2048. if(item.reply) {
  2049. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2050. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2051. return;
  2052. }
  2053. var reply = angular.copy(item.reply);
  2054. if(reply.delivery) {
  2055. if(typeof reply.delivery == 'object')
  2056. reply.delivery = reply.delivery.getTime();
  2057. } else {
  2058. reply.delivery = item.delivery;
  2059. }
  2060. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2061. $scope.loading = true;
  2062. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2063. $scope.loading = false;
  2064. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2065. $scope.tableParams.reload();
  2066. }, function(response){
  2067. $scope.loading = false;
  2068. toaster.pop('error', '回复失败', response.data);
  2069. });
  2070. }
  2071. };
  2072. //打印 采购单
  2073. $scope.print = function(order) {
  2074. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2075. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2076. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2077. };
  2078. $scope.getReply = function(item) {
  2079. if(!item.replies) {
  2080. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2081. item.replies = replies;
  2082. });
  2083. }
  2084. };
  2085. $scope.checkboxes = {
  2086. checked : false
  2087. };
  2088. // 点击勾选全部的复选框
  2089. $scope.checkAll = function(){
  2090. angular.forEach($scope.tableParams.data, function(item) {
  2091. item.$selected = $scope.checkboxes.checked;
  2092. });
  2093. };
  2094. // 点击其中一个明细的复选框
  2095. $scope.checkOne = function(order){
  2096. var result = true;
  2097. angular.forEach($scope.tableParams.data, function(item) {
  2098. if(item.$selected != true){
  2099. result = false;
  2100. return;
  2101. }
  2102. });
  2103. $scope.checkboxes.checked = result;
  2104. };
  2105. //批量回复采购订单
  2106. $scope.replyByBatch = function() {
  2107. $scope.loading = true;
  2108. var str = '';
  2109. angular.forEach($scope.tableParams.data, function(order) {
  2110. if(order.$selected == true) {
  2111. angular.forEach(order.orderItems, function(item){
  2112. str += item.id;
  2113. str += ',';
  2114. });
  2115. }
  2116. });
  2117. if(!(str == '')) {
  2118. str = str.substr(0, str.length-1);
  2119. PurcOrderItem.replyByBatch(str, function(){
  2120. $scope.loading = false;
  2121. $scope.tableParams.reload();
  2122. toaster.pop('success', '提示', '批量回复成功');
  2123. }, function(data){
  2124. $scope.loading = false;
  2125. toaster.pop('error', '批量回复失败', data);
  2126. });
  2127. } else {//没有勾选其中的明细
  2128. $scope.loading = false;
  2129. }
  2130. };
  2131. // 搜索框回车
  2132. $scope.onSearch = function() {
  2133. $scope.tableParams.page(1);
  2134. $scope.tableParams.reload();
  2135. };
  2136. // 选择查找日期
  2137. $scope.onDateCondition = function(){
  2138. $scope.tableParams.page(1);
  2139. $scope.tableParams.reload();
  2140. };
  2141. //设置为已查看
  2142. $scope.setDisplay = function(state, orderId) {
  2143. if(orderId) {//设置单个
  2144. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2145. $scope.tableParams.reload();
  2146. }, function() {
  2147. toaster.pop('error', '错误', "设置失败");
  2148. });
  2149. } else {//设置已勾选的
  2150. var str = null;
  2151. angular.forEach($scope.tableParams.data, function(order) {
  2152. if(order.$selected == true) {
  2153. if(str != null && str != '') str += ',';
  2154. str += order.id;
  2155. }
  2156. });
  2157. if(str != null && str != '') {
  2158. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2159. $scope.tableParams.reload();
  2160. }, function() {
  2161. toaster.pop('error', '错误', "设置失败");
  2162. });
  2163. }
  2164. }
  2165. };
  2166. }]);
  2167. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2168. var loadData = function() {
  2169. PurcOrder.get({id: $stateParams.id}, function(data){
  2170. $scope.order = data;
  2171. var sum = 0;
  2172. angular.forEach($scope.order.orderItems, function(item){
  2173. sum += item.qty * item.price;
  2174. });
  2175. $scope.order.total = sum;
  2176. if($scope.order.display == 1) {//未查看的设为已查看
  2177. $scope.setDisplay('setRead', $scope.order.id);
  2178. }
  2179. $scope.loading = false;
  2180. });
  2181. };
  2182. loadData();
  2183. $scope.getReply = function(item) {
  2184. if(!item.replies) {
  2185. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2186. item.replies = replies;
  2187. });
  2188. }
  2189. };
  2190. $scope.openDatePicker = function($event, item, openParam) {
  2191. $event.preventDefault();
  2192. $event.stopPropagation();
  2193. item[openParam] = !item[openParam];
  2194. };
  2195. $scope.onReplyClick = function(item, inverse) {
  2196. if(item.reply) {
  2197. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2198. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2199. return;
  2200. }
  2201. var reply = angular.copy(item.reply);
  2202. if(reply.delivery) {
  2203. if(typeof reply.delivery == 'object')
  2204. reply.delivery = reply.delivery.getTime();
  2205. } else {
  2206. reply.delivery = item.delivery;
  2207. }
  2208. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2209. $scope.loading = true;
  2210. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2211. $scope.loading = false;
  2212. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2213. loadData();
  2214. }, function(response){
  2215. $scope.loading = false;
  2216. toaster.pop('error', '回复失败', response.data);
  2217. });
  2218. }
  2219. };
  2220. // 采购单
  2221. $scope.print = function(order) {
  2222. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2223. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2224. };
  2225. //设置为已查看
  2226. $scope.setDisplay = function(state, orderId) {
  2227. if(orderId) {//设置单个
  2228. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2229. $scope.tableParams.reload();
  2230. }, function() {
  2231. toaster.pop('error', '错误', "设置失败");
  2232. });
  2233. } else {//设置已勾选的
  2234. var str = null;
  2235. angular.forEach($scope.tableParams.data, function(order) {
  2236. if(order.$selected == true) {
  2237. if(str != null && str != '') str += ',';
  2238. str += order.id;
  2239. }
  2240. });
  2241. if(str != null && str != '') {
  2242. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2243. $scope.tableParams.reload();
  2244. }, function() {
  2245. toaster.pop('error', '错误', "设置失败");
  2246. });
  2247. }
  2248. }
  2249. };
  2250. }]);
  2251. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  2252. BaseService.scrollBackToTop();
  2253. $scope.active = 'todo';
  2254. $scope.agreedText = '全部';
  2255. $scope.dateZoneText = '一个月内';
  2256. $scope.condition = {dateZone: 1};
  2257. $scope.changeAgreed = function(agreed) {
  2258. $scope.condition.agreed = agreed;
  2259. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2260. $scope.condition.$agreedOpen = false;
  2261. };
  2262. $scope.changeDateZone = function(zone) {
  2263. $scope.condition.dateZone = zone;
  2264. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2265. $scope.condition.$dateZoneOpen = false;
  2266. };
  2267. $scope.setActive = function(state) {
  2268. if($scope.active != state) {
  2269. $scope.active = state;
  2270. if($scope.tableParams.page() == 1)
  2271. $scope.tableParams.reload();
  2272. else
  2273. $scope.tableParams.page(1);
  2274. }
  2275. };
  2276. var getService = function() {
  2277. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2278. };
  2279. $scope.tableParams = new ngTableParams({
  2280. page : 1,
  2281. count : 5,
  2282. sorting: {
  2283. date: 'desc'
  2284. }
  2285. }, {
  2286. total : 0,
  2287. counts: [5, 10, 25, 50],
  2288. getData : function($defer, params) {
  2289. $scope.loading = true;
  2290. var pageParams = params.url();
  2291. pageParams.keyword = $scope.keyword;
  2292. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2293. $scope.loading = false;
  2294. if(page) {
  2295. params.total(page.totalElement);
  2296. $defer.resolve(page.content);
  2297. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2298. }
  2299. }, function(response){
  2300. $scope.loading = false;
  2301. toaster.pop('error', '数据加载失败', response.data);
  2302. });
  2303. }
  2304. });
  2305. $scope.openDatePicker = function($event, item, openParam) {
  2306. $event.preventDefault();
  2307. $event.stopPropagation();
  2308. item[openParam] = !item[openParam];
  2309. };
  2310. $scope.onReplyClick = function(change) {
  2311. if(change.$agreed) {
  2312. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2313. $scope.loading = true;
  2314. PurcChange.reply({changeId: change.id}, reply, function(){
  2315. $scope.loading = false;
  2316. toaster.pop('info', '提示', '回复成功');
  2317. $scope.tableParams.reload();
  2318. }, function(response){
  2319. $scope.loading = false;
  2320. toaster.pop('error', '回复失败', response.data);
  2321. });
  2322. }
  2323. };
  2324. // 搜索框回车
  2325. $scope.onSearch = function() {
  2326. $scope.tableParams.page(1);
  2327. $scope.tableParams.reload();
  2328. };
  2329. }]);
  2330. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2331. var loadData = function() {
  2332. PurcChange.get({id: $stateParams.id}, function(data){
  2333. $scope.change = data;
  2334. });
  2335. };
  2336. loadData();
  2337. $scope.openDatePicker = function($event, item, openParam) {
  2338. $event.preventDefault();
  2339. $event.stopPropagation();
  2340. item[openParam] = !item[openParam];
  2341. };
  2342. $scope.onReplyClick = function(change) {
  2343. if(change.$agreed) {
  2344. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2345. PurcChange.reply({changeId: change.id}, reply, function(){
  2346. toaster.pop('info', '提示', '回复成功');
  2347. loadData();
  2348. }, function(response){
  2349. toaster.pop('error', '回复失败', response.data);
  2350. });
  2351. }
  2352. };
  2353. }]);
  2354. //采购询价
  2355. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  2356. BaseService.scrollBackToTop();
  2357. $scope.active = 'todo';
  2358. $scope.agreedText = '全部';
  2359. $scope.dateZoneText = '一个月内';
  2360. $scope.condition = {dateZone: 1};
  2361. $scope.changeAgreed = function(agreed) {
  2362. $scope.condition.agreed = agreed;
  2363. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2364. $scope.condition.$agreedOpen = false;
  2365. };
  2366. $scope.changeDateZone = function(zone) {
  2367. $scope.condition.dateZone = zone;
  2368. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2369. $scope.condition.$dateZoneOpen = false;
  2370. };
  2371. $scope.setActive = function(state) {
  2372. if($scope.active != state) {
  2373. $scope.active = state;
  2374. if($scope.tableParams.page() == 1)
  2375. $scope.tableParams.reload();
  2376. else
  2377. $scope.tableParams.page(1);
  2378. }
  2379. };
  2380. // 得到消息
  2381. PurcInquiry.getMessage({}, function(data){
  2382. console.log(data);
  2383. $scope.message = data;
  2384. }, function(response) {
  2385. });
  2386. var getService = function() {
  2387. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2388. };
  2389. $scope.tableParams = new ngTableParams({
  2390. page : 1,
  2391. count : 5,
  2392. sorting: {
  2393. 'inquiry.date': 'desc',
  2394. 'inquiry.enterprise.enName': 'asc',
  2395. 'inquiry.code': 'asc'
  2396. }
  2397. }, {
  2398. total : 0,
  2399. counts: [5, 10, 25, 50],
  2400. getData : function($defer, params) {
  2401. $scope.loading = true;
  2402. var pageParams = params.url();
  2403. var realActive = {};
  2404. pageParams.keyword = $scope.keyword;
  2405. if ($scope.active == 'overdue') {
  2406. $scope.active = 'end';
  2407. }
  2408. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2409. $scope.loading = false;
  2410. if(page) {
  2411. params.total(page.totalElement);
  2412. $defer.resolve(page.content);
  2413. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2414. }
  2415. }, function(response){
  2416. $scope.loading = false;
  2417. toaster.pop('error', '数据加载失败', response.data);
  2418. });
  2419. }
  2420. });
  2421. $scope.getMinDate = function(item) {
  2422. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2423. };
  2424. $scope.replyPrices = [];
  2425. $scope.replylapQtys = [];
  2426. $scope.replyPrices.push(true);
  2427. $scope.replylapQtys.push(true);
  2428. $scope.addStep = function(inquiryItem) {
  2429. $scope.replyPrices.push(true);
  2430. if(inquiryItem.replies.length >= 10) {
  2431. toaster.pop('warning', '提示', '最多支持10个分段!');
  2432. } else {
  2433. inquiryItem.replies.push({});
  2434. if(inquiryItem.replies.length != 1) {
  2435. $scope.replyPrices.push(true);
  2436. $scope.replylapQtys.push(true);
  2437. }
  2438. }
  2439. };
  2440. $scope.removeStep = function(inquiryItem, stepIndex) {
  2441. inquiryItem.replies.splice(stepIndex, 1);
  2442. $scope.replyPrices.splice(stepIndex, 1);
  2443. $scope.replylapQtys.splice(stepIndex, 1);
  2444. };
  2445. $scope.openDatePicker = function($event, item, openParam) {
  2446. $event.preventDefault();
  2447. $event.stopPropagation();
  2448. item[openParam] = !item[openParam];
  2449. };
  2450. $scope.getHistory = function(item) {
  2451. if(!item.history) {
  2452. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2453. item.history = data;
  2454. });
  2455. }
  2456. };
  2457. $scope.isValid = function(item, withSteps) {
  2458. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2459. if(!withSteps || !bool)
  2460. return bool;
  2461. angular.forEach(item.replies, function(r, i){
  2462. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2463. });
  2464. return bool;
  2465. };
  2466. $scope.onReplyClick = function(item, withSteps) {
  2467. if(item.vendFromDate instanceof Date) {
  2468. item.vendFromDate = item.vendFromDate.getTime();
  2469. }
  2470. if(item.vendToDate instanceof Date) {
  2471. item.vendToDate = item.vendToDate.getTime();
  2472. }
  2473. if(item.vendFromDate > item.vendToDate) {
  2474. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2475. return;
  2476. }
  2477. var replies = [];
  2478. angular.forEach(item.replies, function(r, i){
  2479. if((i > 0 ? r.lapQty : 1) || r.price)
  2480. replies.push(r);
  2481. });
  2482. item.replies = replies;
  2483. $scope.loading = true;
  2484. if(withSteps) {
  2485. PurcInquiry.reply({itemId: item.id}, item, function(){
  2486. $scope.loading = false;
  2487. toaster.pop('info', '提示', '报价成功');
  2488. $scope.tableParams.reload();
  2489. }, function(response){
  2490. $scope.loading = false;
  2491. toaster.pop('error', '报价失败', response.data);
  2492. });
  2493. } else {
  2494. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2495. $scope.loading = false;
  2496. toaster.pop('info', '提示', '保存成功');
  2497. $scope.tableParams.reload();
  2498. }, function(response){
  2499. $scope.loading = false;
  2500. toaster.pop('error', '保存失败', response.data);
  2501. });
  2502. }
  2503. };
  2504. $scope.verifylapQty = function(value,type) {
  2505. var regex = /^\d+(.\d{1,5})?$/;
  2506. $scope.replylapQtys[type] = regex.test(value);
  2507. }
  2508. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2509. $scope.verify = function(value,type) {
  2510. var regex = /^\d+(.\d{1,5})?$/;//
  2511. switch(type) {
  2512. case 'minOrderQty':
  2513. $scope.minOrderQtyVerify = regex.test(value);
  2514. break;
  2515. case 'minPackQty':
  2516. $scope.minPackQtyVerify = regex.test(value);
  2517. break;
  2518. case 'leadtime':
  2519. $scope.leadtimeVerify = regex.test(value);
  2520. break;
  2521. default:
  2522. $scope.replyPrices[type] = regex.test(value);
  2523. break;
  2524. }
  2525. }
  2526. // 搜索框回车
  2527. $scope.onSearch = function() {
  2528. $scope.tableParams.page(1);
  2529. $scope.tableParams.reload();
  2530. };
  2531. }]);
  2532. // 询价单明细
  2533. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2534. var loadData = function() {
  2535. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2536. $scope.newinquiryItems = data;
  2537. var inquiry = data[0].inquiry;
  2538. //inquiry.inquiryItems = data;
  2539. angular.forEach(inquiry.attachs, function(attach){
  2540. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2541. });
  2542. $scope.inquiry = inquiry;
  2543. });
  2544. };
  2545. loadData();
  2546. $scope.getMinDate = function(item) {
  2547. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2548. };
  2549. $scope.addStep = function(inquiryItem) {
  2550. if(inquiryItem.replies.length >= 10) {
  2551. toaster.pop('warning', '提示', '最多支持10个分段!');
  2552. } else
  2553. inquiryItem.replies.push({});
  2554. };
  2555. $scope.removeStep = function(inquiryItem, stepIndex) {
  2556. inquiryItem.replies.splice(stepIndex, 1);
  2557. };
  2558. $scope.openDatePicker = function($event, item, openParam) {
  2559. $event.preventDefault();
  2560. $event.stopPropagation();
  2561. item[openParam] = !item[openParam];
  2562. };
  2563. $scope.getHistory = function(item) {
  2564. if(!item.history) {
  2565. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2566. item.history = data;
  2567. });
  2568. }
  2569. };
  2570. $scope.isValid = function(item, withSteps) {
  2571. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2572. if(!withSteps || !bool)
  2573. return bool;
  2574. angular.forEach(item.replies, function(r, i){
  2575. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2576. });
  2577. return bool;
  2578. };
  2579. $scope.onReplyClick = function(item, withSteps) {
  2580. if(item.vendFromDate instanceof Date) {
  2581. item.vendFromDate = item.vendFromDate.getTime();
  2582. }
  2583. if(item.vendToDate instanceof Date) {
  2584. item.vendToDate = item.vendToDate.getTime();
  2585. }
  2586. if(item.vendFromDate > item.vendToDate) {
  2587. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2588. return;
  2589. }
  2590. var replies = [];
  2591. angular.forEach(item.replies, function(r, i){
  2592. if((i > 0 ? r.lapQty : 1) || r.price)
  2593. replies.push(r);
  2594. });
  2595. item.replies = replies;
  2596. if(withSteps) {
  2597. PurcInquiry.reply({itemId: item.id}, item, function(){
  2598. toaster.pop('info', '提示', '报价成功');
  2599. loadData();
  2600. }, function(response){
  2601. toaster.pop('error', '报价失败', response.data);
  2602. });
  2603. }
  2604. };
  2605. }]);
  2606. // 平台新增的询价单
  2607. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', function($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout) {
  2608. BaseService.scrollBackToTop();
  2609. $scope.status = 'InquiryNew';
  2610. $scope.active = 'all';
  2611. $rootScope.tenderVendor = null;// 清除掉已选择的
  2612. var getService = function() {
  2613. return GetProductInfo;
  2614. };
  2615. $scope.inquiry = {
  2616. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  2617. showdate: $filter('date')(new Date, 'yyyy-MM-dd')
  2618. };
  2619. $scope.currentDay = function() {
  2620. return $filter('date')(new Date(), 'yyyy-MM-dd');
  2621. };
  2622. $scope.vendors = [];
  2623. // 查找供应商
  2624. $scope.dbfindVendor = function(){
  2625. var modalInstance = $modal.open({
  2626. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  2627. controller: 'DbfindVendorCtrl',
  2628. size: 'lg',
  2629. resolve: {
  2630. }
  2631. });
  2632. modalInstance.result.then(function(data){
  2633. var ifPush = true;
  2634. modalInstance.result.then(function(data){
  2635. angular.forEach(data, function(vendor) {
  2636. if (!$scope.vendors) {// 不存在就先创建
  2637. $scope.vendors = [{}];
  2638. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  2639. } else {
  2640. for (var i = 0;i<$scope.vendors.length; i++) {
  2641. ifPush = true;
  2642. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  2643. ifPush = false;
  2644. break; // 判定到已存在供应商,就终止循环。
  2645. }
  2646. }
  2647. if (ifPush) {
  2648. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  2649. }
  2650. }
  2651. });
  2652. $rootScope.tenderVendor = $scope.vendors;
  2653. }, function(){
  2654. });
  2655. }, function(){
  2656. });
  2657. };
  2658. // 删除一个供应商
  2659. $scope.removeVendor = function(index) {
  2660. $scope.vendors.splice(index, 1);
  2661. };
  2662. // 物料信息
  2663. $scope.tableParams = new ngTableParams({
  2664. page : 1,
  2665. count : 5,
  2666. sorting: {
  2667. }
  2668. }, {
  2669. total : 0,
  2670. counts: [5, 10, 25, 50],
  2671. getData : function($defer, params) {
  2672. $scope.loading = true;
  2673. var pageParams = params.url();
  2674. pageParams.keyword = $scope.keyword;
  2675. $scope.tip = $scope.keyword;
  2676. pageParams.searchFilter = $scope.searchFilter;
  2677. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2678. $scope.loading = false;
  2679. if(page) {
  2680. params.total(page.totalElement);
  2681. $scope.total = page.totalElement;
  2682. $defer.resolve(page.content);
  2683. }
  2684. }, function(response) {
  2685. $scope.loading = false;
  2686. toaster.pop('error', '数据加载失败', response.data);
  2687. });
  2688. }
  2689. });
  2690. // 搜索框回车
  2691. $scope.onSearch = function(keyword) {
  2692. $scope.tableParams.page(1);
  2693. $scope.tableParams.reload();
  2694. };
  2695. $scope.inquiry.inquiryItems = [];
  2696. //删除商品
  2697. $scope.del = function(index) {
  2698. $scope.inquiry.inquiryItems.splice(index, 1);
  2699. };
  2700. $scope.check = function(product) {
  2701. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  2702. currency: null, toDate: null, productId: product.id});
  2703. }
  2704. $scope.getMinDate = function(item) {
  2705. return $filter('date')(new Date, 'yyyy-MM-dd');
  2706. };
  2707. $scope.openDatePicker = function($event, openParam, index) {
  2708. $event.preventDefault();
  2709. $event.stopPropagation();
  2710. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  2711. };
  2712. $scope.openEndDatePicker = function($event, item, openParam) {
  2713. $event.preventDefault();
  2714. $event.stopPropagation();
  2715. item[openParam] = !item[openParam];
  2716. };
  2717. // 保存
  2718. $scope.save = function() {
  2719. // var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  2720. // $upload.upload({
  2721. // url: 'product/baseInfo/updateProdInfo',
  2722. // file: file,
  2723. // method: 'POST',
  2724. // data: {
  2725. // prodInfo: $scope.prodInfo
  2726. // },
  2727. // }).success(function(data) {
  2728. // if(data.success) {
  2729. // toaster.pop('success', '提示', data.success);
  2730. // window.location.reload();
  2731. // }
  2732. // if(data.error) {
  2733. // toaster.pop('error', '提示', data.error);
  2734. // }
  2735. // }).error(function(data) {
  2736. // $scope.loadingShow = false;
  2737. // toaster.pop('error', '操作失败', data.error);
  2738. // });
  2739. PurchaseInquiry.save({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  2740. if(data.success) {
  2741. toaster.pop('success', '提示', data.success);
  2742. $timeout(function() {
  2743. window.loaction.hash = "#/purc/inquiry_unapply";
  2744. }, 500);
  2745. }
  2746. if(data.error) {
  2747. toaster.pop('error', '提示', data.error);
  2748. }
  2749. }, function(response) {
  2750. toaster.pop('error', '提示', response.data);
  2751. });
  2752. }
  2753. // 保存并提交
  2754. $scope.submit = function() {
  2755. PurchaseInquiry.submit({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  2756. if(data.success) {
  2757. toaster.pop('success', '提示', data.success);
  2758. $timeout(function() {
  2759. window.location.hash = "#/purc/inquiry_unapply";
  2760. }, 500);
  2761. }
  2762. if(data.error) {
  2763. toaster.pop('error', '提示', data.error);
  2764. }
  2765. }, function(response) {
  2766. toaster.pop('error', '提示', response.data);
  2767. });
  2768. }
  2769. }]);
  2770. // 平台询价单(已提交)
  2771. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry) {
  2772. $scope.status = 'InquirySubmit';
  2773. BaseService.scrollBackToTop();
  2774. $scope.active = 'todo';
  2775. $scope.agreedText = '全部';
  2776. $scope.dateZoneText = '一个月内';
  2777. $scope.condition = {dateZone: 1};
  2778. $scope.changeAgreed = function(agreed) {
  2779. $scope.condition.agreed = agreed;
  2780. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2781. $scope.condition.$agreedOpen = false;
  2782. };
  2783. $scope.changeDateZone = function(zone) {
  2784. $scope.condition.dateZone = zone;
  2785. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2786. $scope.condition.$dateZoneOpen = false;
  2787. };
  2788. $scope.setActive = function(state) {
  2789. if($scope.active != state ) {
  2790. $scope.active = state;
  2791. if ($scope.tableParams.page() == 1) {
  2792. $scope.tableParams.reload();
  2793. } else {
  2794. $scope.tableParams.page(1);
  2795. }
  2796. }
  2797. }
  2798. var getService = function() {
  2799. return PurchaseInquiry;
  2800. };
  2801. $scope.tableParams = new ngTableParams({
  2802. page : 1,
  2803. count : 5,
  2804. sorting: {
  2805. 'inquiry.date': 'desc',
  2806. 'inquiry.enterprise.enName': 'asc',
  2807. 'inquiry.code': 'asc'
  2808. }
  2809. }, {
  2810. total : 0,
  2811. counts: [5, 10, 25, 50],
  2812. getData : function($defer, params) {
  2813. $scope.loading = true;
  2814. var pageParams = params.url();
  2815. var realActive = {};
  2816. pageParams.keyword = $scope.keyword;
  2817. if ($scope.active == 'overdue') {
  2818. $scope.active = 'end';
  2819. }
  2820. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2821. $scope.loading = false;
  2822. if(page) {
  2823. params.total(page.totalElement);
  2824. $defer.resolve(page.content);
  2825. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2826. }
  2827. }, function(response){
  2828. $scope.loading = false;
  2829. toaster.pop('error', '数据加载失败', response.data);
  2830. });
  2831. }
  2832. });
  2833. $scope.openDatePicker = function($event, item, openParam) {
  2834. $event.preventDefault();
  2835. $event.stopPropagation();
  2836. item[openParam] = !item[openParam];
  2837. };
  2838. // 搜索框回车
  2839. $scope.onSearch = function() {
  2840. $scope.tableParams.page(1);
  2841. $scope.tableParams.reload();
  2842. };
  2843. // 采纳
  2844. $scope.accept = function(id) {
  2845. PurchaseInquiry.accept({id: id}, {}, function(data) {
  2846. if(data.success) {
  2847. toaster.pop('success', '提示', data.success);
  2848. $scope.tableParams.reload();
  2849. }
  2850. if(data.error) {
  2851. toaster.pop('error', '提示', data.error);
  2852. }
  2853. }, function(response) {
  2854. toaster.pop('error', '提示', response.data);
  2855. })
  2856. };
  2857. // 拒绝
  2858. $scope.refuse = function(id) {
  2859. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  2860. if(data.success) {
  2861. toaster.pop('success', '提示', data.success);
  2862. $scope.tableParams.reload();
  2863. }
  2864. if(data.error) {
  2865. toaster.pop('error', '提示', data.error);
  2866. }
  2867. }, function(response) {
  2868. toaster.pop('error', '提示', response.data);
  2869. })
  2870. }
  2871. }]);
  2872. // 平台询价单(未提交)
  2873. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster) {
  2874. BaseService.scrollBackToTop();
  2875. $scope.status = 'InquiryUnSubmit';
  2876. $scope.tableParams = new ngTableParams({
  2877. page : 1,
  2878. count : 5,
  2879. sorting: {
  2880. 'inquiry.date': 'desc',
  2881. 'inquiry.enterprise.enName': 'asc',
  2882. 'inquiry.code': 'asc'
  2883. }
  2884. }, {
  2885. total : 0,
  2886. counts: [5, 10, 25, 50],
  2887. getData : function($defer, params) {
  2888. $scope.loading = true;
  2889. var pageParams = params.url();
  2890. var realActive = {};
  2891. if ($scope.active == 'overdue') {
  2892. $scope.active = 'end';
  2893. }
  2894. PurchaseInquiry.getUnapply(null, BaseService.parseParams(pageParams), function(page){
  2895. $scope.loading = false;
  2896. if(page) {
  2897. params.total(page.totalElements);
  2898. $defer.resolve(page.content);
  2899. }
  2900. }, function(response){
  2901. $scope.loading = false;
  2902. toaster.pop('error', '数据加载失败', response.data);
  2903. });
  2904. }
  2905. });
  2906. // 删除明细
  2907. $scope.deleteById = function(id) {
  2908. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  2909. toaster.pop('success', '提示', '删除成功');
  2910. $scope.tableParams.reload();
  2911. }, function(response) {
  2912. toaster.pop('error', '提示', response.data);
  2913. });
  2914. }
  2915. // 删除主表
  2916. $scope.clearOrder = function(id) {
  2917. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  2918. toaster.pop('success', '提示', '删除成功');
  2919. $scope.tableParams.reload();
  2920. }, function(response) {
  2921. toaster.pop('error', '提示', response.data);
  2922. });
  2923. }
  2924. // 提交
  2925. $scope.submit = function(id) {
  2926. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  2927. toaster.pop('success', '提示', '单据提交成功');
  2928. }, function(response) {
  2929. toaster.pop('error', '提示', response.data);
  2930. })
  2931. }
  2932. }]);
  2933. // 询价单明细
  2934. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2935. var loadData = function() {
  2936. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2937. $scope.newinquiryItems = data;
  2938. var inquiry = data[0].inquiry;
  2939. //inquiry.inquiryItems = data;
  2940. angular.forEach(inquiry.attachs, function(attach){
  2941. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2942. });
  2943. $scope.inquiry = inquiry;
  2944. });
  2945. };
  2946. loadData();
  2947. $scope.getMinDate = function(item) {
  2948. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2949. };
  2950. $scope.addStep = function(inquiryItem) {
  2951. if(inquiryItem.replies.length >= 10) {
  2952. toaster.pop('warning', '提示', '最多支持10个分段!');
  2953. } else
  2954. inquiryItem.replies.push({});
  2955. };
  2956. $scope.removeStep = function(inquiryItem, stepIndex) {
  2957. inquiryItem.replies.splice(stepIndex, 1);
  2958. };
  2959. $scope.openDatePicker = function($event, item, openParam) {
  2960. $event.preventDefault();
  2961. $event.stopPropagation();
  2962. item[openParam] = !item[openParam];
  2963. };
  2964. $scope.getHistory = function(item) {
  2965. if(!item.history) {
  2966. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2967. item.history = data;
  2968. });
  2969. }
  2970. };
  2971. $scope.isValid = function(item, withSteps) {
  2972. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2973. if(!withSteps || !bool)
  2974. return bool;
  2975. angular.forEach(item.replies, function(r, i){
  2976. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2977. });
  2978. return bool;
  2979. };
  2980. $scope.onReplyClick = function(item, withSteps) {
  2981. if(item.vendFromDate instanceof Date) {
  2982. item.vendFromDate = item.vendFromDate.getTime();
  2983. }
  2984. if(item.vendToDate instanceof Date) {
  2985. item.vendToDate = item.vendToDate.getTime();
  2986. }
  2987. if(item.vendFromDate > item.vendToDate) {
  2988. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2989. return;
  2990. }
  2991. var replies = [];
  2992. angular.forEach(item.replies, function(r, i){
  2993. if((i > 0 ? r.lapQty : 1) || r.price)
  2994. replies.push(r);
  2995. });
  2996. item.replies = replies;
  2997. if(withSteps) {
  2998. PurcInquiry.reply({itemId: item.id}, item, function(){
  2999. toaster.pop('info', '提示', '报价成功');
  3000. loadData();
  3001. }, function(response){
  3002. toaster.pop('error', '报价失败', response.data);
  3003. });
  3004. }
  3005. };
  3006. }]);
  3007. // 模具询价管理
  3008. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  3009. BaseService.scrollBackToTop();
  3010. $scope.active = 'todo';
  3011. $scope.agreedText = '全部';
  3012. $scope.dateZoneText = '一个月内';
  3013. $scope.condition = {dateZone: 1};
  3014. var inquiryMould_copy = {};
  3015. $scope.changeAgreed = function(agreed) {
  3016. $scope.condition.agreed = agreed;
  3017. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3018. $scope.condition.$agreedOpen = false;
  3019. };
  3020. $scope.changeDateZone = function(zone) {
  3021. $scope.condition.dateZone = zone;
  3022. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3023. $scope.condition.$dateZoneOpen = false;
  3024. };
  3025. $scope.setActive = function(state) {
  3026. if($scope.active != state ) {
  3027. $scope.active = state;
  3028. if ($scope.tableParams.page() == 1) {
  3029. $scope.tableParams.reload();
  3030. } else {
  3031. $scope.tableParams.page(1);
  3032. }
  3033. }
  3034. }
  3035. var getService = function() {
  3036. return PurcInquiryMould;
  3037. };
  3038. $scope.tableParams = new ngTableParams({
  3039. page: 1,
  3040. count: 5
  3041. },{
  3042. total: 0,
  3043. counts: [5, 10, 25, 50],
  3044. getData: function($defer, params) {
  3045. $scope.loading = true;
  3046. var pageParams = params.url();
  3047. var realActive = {};
  3048. pageParams.keyword = $scope.keyword;
  3049. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3050. $scope.loading = false;
  3051. // 用来验证价格修改
  3052. var mould = page.content;
  3053. inquiryMould_copy = angular.copy(mould);
  3054. if(page) {
  3055. params.total(page.totalElement);
  3056. $defer.resolve(page.content);
  3057. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3058. }
  3059. }, function(response){
  3060. $scope.loading = false;
  3061. toaster.pop('error', '数据加载失败', response.data);
  3062. });
  3063. }
  3064. })
  3065. $scope.getMinDate = function(item) {
  3066. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  3067. };
  3068. $scope.replyPrices = [];
  3069. $scope.replyPrices.push(true);
  3070. // 取消
  3071. $scope.reload = function() {
  3072. $scope.tableParams.reload();
  3073. $scope.canSave = false;
  3074. }
  3075. // 能否保存设置
  3076. $scope.canSave = false;
  3077. // items价格验证
  3078. $scope.verifyItems = function(price, reply) {
  3079. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  3080. if(regex.test(price) && price != 0) {
  3081. if (price != reply) {
  3082. $scope.canSave = true;
  3083. } else {
  3084. $scope.canSave = false;
  3085. }
  3086. } else {
  3087. $scope.canSave = false;
  3088. }
  3089. }
  3090. // prod下prods价格验证
  3091. $scope.verifyProds = function(price, reply) {
  3092. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3093. if(regex.test(price) && price != 0) {
  3094. if (price != reply) {
  3095. $scope.canSave = true;
  3096. } else {
  3097. $scope.canSave = false;
  3098. }
  3099. } else {
  3100. $scope.canSave = false;
  3101. }
  3102. }
  3103. //有价格为0或者不符合正则式,则不能报价
  3104. $scope.notZero = function (mould) {
  3105. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3106. angular.forEach(mould.inquiryMouldItems, function(item){
  3107. if (item.price == 0 || !regex.test(item.price)) {
  3108. $scope.canSave = false;
  3109. }
  3110. angular.forEach(item.inquiryMouldDetails, function(detail){
  3111. if (detail.price == 0 || !regex.test(detail.price)) {
  3112. $scope.canSave = false;
  3113. }
  3114. })
  3115. });
  3116. }
  3117. $scope.blurPrice = function (price) {
  3118. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3119. if (!regex.test(price)) {
  3120. toaster.pop('warning','格式错误','请输入有效价格');
  3121. }
  3122. }
  3123. // 获取历史报价
  3124. $scope.getHistory = function(mould) {
  3125. if(!mould.history) {
  3126. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3127. mould.history = data;
  3128. console.log(mould.history);
  3129. });
  3130. }
  3131. };
  3132. $scope.uploadAttach = function(mould) {
  3133. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3134. var file = mould.attachs[0];
  3135. $scope.mould = mould;
  3136. $upload.upload({
  3137. url: 'sale/mould/' + mould.id + '/send',
  3138. method: 'POST',
  3139. file: file,
  3140. data: {
  3141. json: $scope.mould
  3142. }
  3143. }).success(function(res){
  3144. console.log("success");
  3145. console.log(res);
  3146. }).error(function(res){
  3147. console.log("failure");
  3148. console.log(res);
  3149. });
  3150. }
  3151. // 保存并确认报价
  3152. $scope.onReplyClick = function(mould, withSteps) {
  3153. $scope.loading = true;
  3154. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3155. // var file = mould.attachs[0];
  3156. // $scope.mould = mould;
  3157. // $upload.upload({
  3158. // url: 'sale/mould/' + mould.id + '/send',
  3159. // method: 'POST',
  3160. // file: file,
  3161. // data: {
  3162. // json: $scope.mould
  3163. // }
  3164. // }).success(function(res){
  3165. // console.log("success");
  3166. // console.log(res);
  3167. // }).error(function(res){
  3168. // console.log("failure");
  3169. // });
  3170. if(withSteps) {
  3171. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3172. $scope.loading = false;
  3173. toaster.pop('info', '提示', '报价成功');
  3174. $scope.tableParams.reload();
  3175. $scope.canSave = false;
  3176. }, function(response){
  3177. $scope.loading = false;
  3178. toaster.pop('error', '报价失败', response.data);
  3179. });
  3180. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3181. }, function(response){
  3182. });
  3183. } else {
  3184. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3185. $scope.loading = false;
  3186. toaster.pop('info', '提示', '保存成功');
  3187. $scope.tableParams.reload();
  3188. }, function(response){
  3189. $scope.loading = false;
  3190. toaster.pop('error', '保存失败', response.data);
  3191. });
  3192. }
  3193. };
  3194. // 搜索框回车
  3195. $scope.onSearch = function() {
  3196. $scope.tableParams.page(1);
  3197. $scope.tableParams.reload();
  3198. };
  3199. }]);
  3200. // 模具询价单明细
  3201. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  3202. var inquiryMould_copy = {};
  3203. var loadData = function() {
  3204. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  3205. // 用来验证价格修改
  3206. inquiryMould_copy = angular.copy(data);
  3207. $scope.inquiryMould_copy = inquiryMould_copy;
  3208. $scope.newinquirymould = data;
  3209. var mould = data;
  3210. angular.forEach(mould.attachs, function(attach){
  3211. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3212. });
  3213. $scope.inquiryMould = mould;
  3214. });
  3215. };
  3216. loadData();
  3217. $scope.getMinDate = function(item) {
  3218. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3219. };
  3220. // 取消
  3221. $scope.reload = function() {
  3222. loadData();
  3223. $scope.canSave = false;
  3224. }
  3225. //有价格为0,则不能报价
  3226. $scope.notZero = function (mould) {
  3227. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3228. angular.forEach(mould.inquiryMouldItems, function(item){
  3229. if (item.price == 0 || !regex.test(item.price)) {
  3230. $scope.canSave = false;
  3231. }
  3232. angular.forEach(item.inquiryMouldDetails, function(detail){
  3233. if (detail.price == 0 || !regex.test(detail.price)) {
  3234. $scope.canSave = false;
  3235. }
  3236. })
  3237. });
  3238. }
  3239. $scope.blurPrice = function (price) {
  3240. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3241. if (!regex.test(price)) {
  3242. toaster.pop('warning','格式错误','请输入有效价格');
  3243. }
  3244. }
  3245. // 获取历史报价
  3246. $scope.getHistory = function(mould) {
  3247. if(!mould.history) {
  3248. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3249. mould.history = data;
  3250. console.log(mould.history);
  3251. });
  3252. }
  3253. };
  3254. $scope.canSave = false;
  3255. // items价格验证
  3256. $scope.verifyItems = function(price, index) {
  3257. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3258. if(regex.test(price) && price != 0) {
  3259. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  3260. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  3261. $scope.canSave = true;
  3262. } else {
  3263. $scope.canSave = false;
  3264. }
  3265. } else {
  3266. $scope.canSave = false;
  3267. }
  3268. }
  3269. // prod下prods价格验证
  3270. $scope.verifyProds = function(price, index, parentIndex) {
  3271. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3272. if(regex.test(price) && price != 0) {
  3273. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  3274. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  3275. $scope.canSave = true;
  3276. } else {
  3277. $scope.canSave = false;
  3278. }
  3279. } else {
  3280. $scope.canSave = false;
  3281. }
  3282. }
  3283. // // 上传附件
  3284. // $scope.uploadAttach = function(mould) {
  3285. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3286. // var file = mould.attachs[0];
  3287. // $scope.mould = mould;
  3288. // $upload.upload({
  3289. // url: 'sale/mould/' + mould.id + '/send',
  3290. // method: 'POST',
  3291. // file: file,
  3292. // data: {
  3293. // json: $scope.mould
  3294. // }
  3295. // }).success(function(res){
  3296. // console.log("success");
  3297. // console.log(res);
  3298. // }).error(function(res){
  3299. // console.log("failure");
  3300. // console.log(res);
  3301. // });
  3302. // }
  3303. $scope.onReplyClick = function(mould, withSteps) {
  3304. $scope.loading = true;
  3305. // var file = mould.attachs[0];
  3306. // $scope.mould = mould;
  3307. // $upload.upload({
  3308. // url: 'sale/mould/' + mould.id + '/send',
  3309. // method: 'POST',
  3310. // file: file,
  3311. // data: {
  3312. // json: $scope.mould
  3313. // }
  3314. // }).success(function(res){
  3315. //
  3316. // }).error(function(res){
  3317. // console.log(res);
  3318. // });
  3319. if(withSteps) {
  3320. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3321. $scope.loading = false;
  3322. toaster.pop('info', '提示', '报价成功');
  3323. loadData();
  3324. $scope.canSave = false;
  3325. }, function(response){
  3326. $scope.loading = false;
  3327. toaster.pop('error', '报价失败', response.data);
  3328. });
  3329. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3330. }, function(response){
  3331. });
  3332. } else {
  3333. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3334. $scope.loading = false;
  3335. toaster.pop('info', '提示', '保存成功');
  3336. loadData();
  3337. }, function(response){
  3338. $scope.loading = false;
  3339. toaster.pop('error', '保存失败', response.data);
  3340. });
  3341. }
  3342. };
  3343. }]);
  3344. // 主动报价 - 列表
  3345. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  3346. BaseService.scrollBackToTop();
  3347. $scope.active = 'todo';
  3348. $scope.agreedText = '全部';
  3349. $scope.dateZoneText = '一个月内';
  3350. $scope.condition = {dateZone: 1};
  3351. $scope.changeDateZone = function(zone) {
  3352. $scope.condition.dateZone = zone;
  3353. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3354. $scope.condition.$dateZoneOpen = false;
  3355. };
  3356. $scope.setActive = function(state) {
  3357. if($scope.active != state) {
  3358. $scope.active = state;
  3359. if($scope.tableParams.page() == 1)
  3360. $scope.tableParams.reload();
  3361. else
  3362. $scope.tableParams.page(1);
  3363. }
  3364. };
  3365. var getService = function() {
  3366. return Quotation;
  3367. };
  3368. $scope.tableParams = new ngTableParams({
  3369. page : 1,
  3370. count : 5,
  3371. sorting: {
  3372. 'quotation.date': 'desc'
  3373. }
  3374. }, {
  3375. total : 0,
  3376. counts: [5, 10, 25, 50],
  3377. getData : function($defer, params) {
  3378. $scope.loading = true;
  3379. var pageParams = params.url();
  3380. pageParams.keyword = $scope.keyword;
  3381. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3382. $scope.loading = false;
  3383. if(page) {
  3384. params.total(page.totalElement);
  3385. $defer.resolve(page.content);
  3386. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3387. }
  3388. }, function(response){
  3389. $scope.loading = false;
  3390. toaster.pop('error', '数据加载失败', response.data);
  3391. });
  3392. }
  3393. });
  3394. $scope.getHistory = function(item) {
  3395. if(!item.history) {
  3396. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3397. item.history = data;
  3398. });
  3399. }
  3400. };
  3401. $scope.isValid = function(item, withSteps) {
  3402. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3403. if(!withSteps || !bool)
  3404. return bool;
  3405. angular.forEach(item.replies, function(r, i){
  3406. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3407. });
  3408. return bool;
  3409. };
  3410. // 搜索框回车
  3411. $scope.onSearch = function() {
  3412. $scope.tableParams.page(1);
  3413. $scope.tableParams.reload();
  3414. };
  3415. }]);
  3416. // Controller 主动报价 - 新增
  3417. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
  3418. BaseService.scrollBackToTop();
  3419. var staticItem = null;
  3420. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  3421. $scope.loading = true;
  3422. Quotation.getItem({id: $stateParams.id}, function(data){
  3423. data.$editing = false;
  3424. $scope.item = data;
  3425. staticItem = angular.copy(data);
  3426. $scope.loading = false;
  3427. }, function(response){
  3428. $scope.loading = false;
  3429. toaster.pop('error', '数据加载失败', response.data);
  3430. });
  3431. } else {// 新增模式
  3432. $scope.item = {
  3433. quotation: {
  3434. currency: 'RMB',
  3435. taxrate: 17,
  3436. date: new Date()
  3437. },
  3438. product: {},
  3439. prices: [{lapQty: 0}],
  3440. minOrderQty: 1,
  3441. minPackQty: 1,
  3442. $endDateOpen: false,
  3443. $editing: true
  3444. };
  3445. }
  3446. $scope.getMinDate = function(item) {
  3447. return $filter('date')(new Date, 'yyyy-MM-dd');
  3448. };
  3449. $scope.openDatePicker = function($event, openParam) {
  3450. $event.preventDefault();
  3451. $event.stopPropagation();
  3452. $scope.item.$endDateOpen = !openParam;
  3453. };
  3454. // 增加一个分段
  3455. $scope.addPrice = function(){
  3456. if($scope.item.prices.length >= 10) {
  3457. toaster.pop('warning', '提示', '最多支持10个分段!');
  3458. } else
  3459. $scope.item.prices.push({});
  3460. };
  3461. // 删除一个分段
  3462. $scope.removePrice = function(index) {
  3463. $scope.item.prices.splice(index, 1);
  3464. };
  3465. // 查找客户
  3466. $scope.dbfindCust = function(){
  3467. if($scope.item.$editing) {
  3468. var modalInstance = $modal.open({
  3469. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  3470. controller: 'DbfindCustCtrl',
  3471. size: 'lg',
  3472. resolve: {
  3473. }
  3474. });
  3475. modalInstance.result.then(function(data){
  3476. $scope.item.quotation.cust = data.myEnterprise;
  3477. $scope.item.quotation.custUser = data.myUser;
  3478. $scope.item.product = null;
  3479. }, function(){
  3480. });
  3481. }
  3482. };
  3483. // 查找客户物料
  3484. $scope.dbfindCustProd = function(){
  3485. if($scope.item.$editing) {
  3486. if($scope.item.quotation.cust.uu) {
  3487. var modalInstance = $modal.open({
  3488. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  3489. controller: 'DbfindCustProdCtrl',
  3490. size: 'lg',
  3491. resolve: {
  3492. custUU: function(){return $scope.item.quotation.cust.uu}
  3493. }
  3494. });
  3495. modalInstance.result.then(function(data){
  3496. $scope.item.product = data;
  3497. }, function(){
  3498. });
  3499. } else {
  3500. toaster.pop('error', '错误', '请先选择客户');
  3501. }
  3502. }
  3503. };
  3504. // 保存
  3505. $scope.save = function(){
  3506. $scope.loading = true;
  3507. if(!$scope.item.quotation.code) //新增,设单号
  3508. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  3509. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  3510. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  3511. $scope.item.productId = $scope.item.product.id;
  3512. $scope.item.quotation.status = 100;//在录入
  3513. if($scope.item.quotation.date instanceof Date) {
  3514. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  3515. }
  3516. if($scope.item.quotation.endDate instanceof Date) {
  3517. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  3518. }
  3519. Quotation.save({}, $scope.item, function(data){
  3520. $scope.loading = false;
  3521. toaster.pop('success', '成功', '保存成功');
  3522. if($stateParams.id)
  3523. window.location.reload();
  3524. else
  3525. window.location.hash = '#/sale/quotation/' + data.id;
  3526. }, function(response){
  3527. $scope.loading = false;
  3528. toaster.pop('error', '保存失败', response.data);
  3529. });
  3530. };
  3531. // 更新
  3532. $scope.update = function(){
  3533. $scope.item.$editing = true;
  3534. };
  3535. // 取消
  3536. $scope.cancel = function(){
  3537. $scope.item.$editing = false;
  3538. $scope.item = angular.copy(staticItem);
  3539. };
  3540. // 提交
  3541. $scope.submit = function(){
  3542. $scope.loading = true;
  3543. $scope.item.quotation.status = 101;//在录入
  3544. Quotation.save({}, $scope.item, function(data){
  3545. $scope.loading = false;
  3546. toaster.pop('success', '成功', '提交成功');
  3547. window.location.hash = '#/sale/quotation/' + data.id;
  3548. }, function(response){
  3549. $scope.loading = false;
  3550. toaster.pop('error', '保存失败', response.data);
  3551. });
  3552. };
  3553. }]);
  3554. // 查找客户
  3555. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  3556. BaseService.scrollBackToTop();
  3557. $scope.tableParams = new ngTableParams({
  3558. page : 1,
  3559. count : 10
  3560. }, {
  3561. total : 0,
  3562. counts: [5, 10, 25, 50],
  3563. getData : function($defer, params) {
  3564. $scope.loading = true;
  3565. var pageParams = params.url();
  3566. pageParams.keyword = $scope.keyword;
  3567. Customer.get(BaseService.parseParams(pageParams), function(page){
  3568. $scope.loading = false;
  3569. if(page) {
  3570. params.total(page.totalElements);
  3571. $defer.resolve(page.content);
  3572. }
  3573. $scope.totalCount = page.totalElements;
  3574. }, function(response){
  3575. $scope.loading = false;
  3576. toaster.pop('error', '数据加载失败', response.data);
  3577. });
  3578. }
  3579. });
  3580. $scope.onSearch = function() {
  3581. $scope.tableParams.page(1);
  3582. $scope.tableParams.reload();
  3583. };
  3584. $scope.cancel = function() {
  3585. $modalInstance.dismiss();
  3586. };
  3587. $scope.check = function(cust){
  3588. $modalInstance.close(cust);
  3589. };
  3590. }]);
  3591. // 查找客户物料
  3592. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  3593. BaseService.scrollBackToTop();
  3594. $scope.tableParams = new ngTableParams({
  3595. page : 1,
  3596. count : 10
  3597. }, {
  3598. total : 0,
  3599. counts: [5, 10, 25, 50],
  3600. getData : function($defer, params) {
  3601. $scope.loading = true;
  3602. var pageParams = params.url();
  3603. pageParams.keyword = $scope.keyword;
  3604. pageParams.custUU = custUU;
  3605. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  3606. $scope.loading = false;
  3607. if(page) {
  3608. params.total(page.totalElements);
  3609. $defer.resolve(page.content);
  3610. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3611. }
  3612. }, function(response){
  3613. $scope.loading = false;
  3614. toaster.pop('error', '数据加载失败', response.data);
  3615. });
  3616. }
  3617. });
  3618. // 取消
  3619. $scope.cancel = function() {
  3620. $modalInstance.dismiss();
  3621. };
  3622. // 选择
  3623. $scope.check = function(cust){
  3624. $modalInstance.close(cust);
  3625. };
  3626. // 搜索框回车
  3627. $scope.onSearch = function() {
  3628. $scope.tableParams.page(1);
  3629. $scope.tableParams.reload();
  3630. };
  3631. }]);
  3632. // 查找供应商
  3633. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  3634. BaseService.scrollBackToTop();
  3635. // 搜索框回车
  3636. $scope.onSearch = function(keyword) {
  3637. $scope.keyword = keyword;
  3638. $scope.tableParams.page(1);
  3639. $scope.tableParams.reload();
  3640. };
  3641. $scope.tableParams = new ngTableParams({
  3642. page : 1,
  3643. count : 10
  3644. }, {
  3645. total : 0,
  3646. counts: [10, 25, 50, 100],
  3647. getData : function($defer, params) {
  3648. $scope.loading = true;
  3649. var pageParams = params.url();
  3650. pageParams.keyword = $scope.keyword;
  3651. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  3652. $scope.loading = false;
  3653. if(page) {
  3654. params.total(page.totalElements);
  3655. $defer.resolve(page.content);
  3656. // 添加供应商时,将已存在的选中
  3657. if ($rootScope.tenderVendor) {
  3658. angular.forEach(page.content, function(vendor) {
  3659. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  3660. vendor.checked = false;
  3661. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  3662. vendor.checked = true;
  3663. break;
  3664. }
  3665. }
  3666. });
  3667. }
  3668. }
  3669. $scope.totalCount = page.totalElements;
  3670. }, function(response){
  3671. $scope.loading = false;
  3672. toaster.pop('error', '数据加载失败', response.data);
  3673. });
  3674. }
  3675. });
  3676. $scope.cancel = function() {
  3677. $modalInstance.dismiss();
  3678. };
  3679. $scope.checks = {
  3680. checked : false
  3681. };// 全选框
  3682. $scope.checkAll = function() {
  3683. angular.forEach($scope.tableParams.data, function(vendor) {
  3684. vendor.checked = $scope.checks.checked;
  3685. });
  3686. };
  3687. // 单选
  3688. $scope.checkOne = function(vendor) {
  3689. vendor.checked = true;
  3690. };
  3691. // 单反选
  3692. $scope.unCheckOne = function(vendor) {
  3693. vendor.checked = false;
  3694. };
  3695. $scope.close = function(){
  3696. var vendors = [];
  3697. angular.forEach($scope.tableParams.data, function(vendor) {
  3698. if(vendor.checked) {
  3699. vendors.push(vendor);
  3700. $modalInstance.close(vendors);
  3701. }
  3702. });
  3703. };
  3704. }]);
  3705. // 发货提醒
  3706. 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){
  3707. BaseService.scrollBackToTop();
  3708. $scope.active = 'todo';
  3709. $scope.currency = Symbol.currency;
  3710. $scope.dateZoneText = '不限';
  3711. $scope.condition = {dateZone: -1};
  3712. $scope.changeDateZone = function(zone) {
  3713. $scope.condition.dateZone = zone;
  3714. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3715. $scope.condition.$dateZoneOpen = false;
  3716. getDateCondition(zone, $scope.condition);
  3717. $scope.tableParams.reload();
  3718. };
  3719. $scope.setActive = function(state) {
  3720. if($scope.active != state) {
  3721. $scope.active = state;
  3722. if($scope.tableParams.page() == 1)
  3723. $scope.tableParams.reload();
  3724. else
  3725. $scope.tableParams.page(1);
  3726. }
  3727. };
  3728. var getService = function() {
  3729. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  3730. };
  3731. $scope.tableParams = new ngTableParams({
  3732. page : 1,
  3733. count : 5,
  3734. sorting: {
  3735. 'delivery': 'asc',
  3736. 'orderItemOrderCode': 'asc',
  3737. 'orderItemNumber': 'asc'
  3738. }
  3739. }, {
  3740. total : 0,
  3741. counts: [5, 10, 25, 50],
  3742. getData : function($defer, params) {
  3743. $scope.loading = true;
  3744. var pageParams = params.url();
  3745. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3746. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3747. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3748. $scope.loading = false;
  3749. if(page) {
  3750. params.total(page.totalElement);
  3751. $defer.resolve(page.content);
  3752. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3753. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3754. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3755. }
  3756. }, function(response){
  3757. $scope.loading = false;
  3758. toaster.pop('error', '数据加载失败', response.data);
  3759. });
  3760. }
  3761. });
  3762. $scope.openDatePicker = function($event, item, openParam) {
  3763. $event.preventDefault();
  3764. $event.stopPropagation();
  3765. item[openParam] = !item[openParam];
  3766. };
  3767. //生成随机单号
  3768. $scope.autoCode = function(notice){
  3769. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  3770. };
  3771. //可送货日期
  3772. $scope.sendDate = function(notice) {
  3773. var stock = notice.orderItem.product.ltinstock || 0;
  3774. var de = new Date(notice.delivery);
  3775. if(stock == -1) {
  3776. de.setMonth(de.getMonth() -1);
  3777. de.setDate(25);
  3778. } else if(stock >= 0) {
  3779. de.setDate(de.getDate() - stock -1);
  3780. }
  3781. return de;
  3782. };
  3783. $scope.onReplyClick = function(notice) {
  3784. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  3785. toaster.pop('warning', '警告', '数量填写错误!');
  3786. } else if(!notice.send.code) {
  3787. toaster.pop('warning', '警告', '请填写发货单号!');
  3788. } else {
  3789. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  3790. $scope.loading = true;
  3791. PurcNotice.save({id: notice.id}, send, function(data){
  3792. $scope.loading = false;
  3793. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  3794. $state.go('sale.send_detail', {id: data.id});
  3795. }, function(response){
  3796. $scope.loading = false;
  3797. toaster.pop('error', '发货失败', response.data);
  3798. });
  3799. }
  3800. };
  3801. $scope.checkboxes = {
  3802. checked : false
  3803. };
  3804. // 点击勾选全部的复选框
  3805. $scope.checkAll = function(){
  3806. angular.forEach($scope.tableParams.data, function(item) {
  3807. if(!item.waiting)
  3808. item.$selected = $scope.checkboxes.checked;
  3809. });
  3810. };
  3811. // 点击其中一个明细的复选框
  3812. $scope.checkOne = function(order){
  3813. var result = true;
  3814. angular.forEach($scope.tableParams.data, function(item) {
  3815. if(item.$selected != true){
  3816. result = false;
  3817. return;
  3818. }
  3819. });
  3820. $scope.checkboxes.checked = result;
  3821. };
  3822. $scope.sendByBatch = function(){
  3823. var modalInstance = $modal.open({
  3824. animation: true,
  3825. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  3826. controller: 'SaleNoticeSendByBatchCtrl',
  3827. size: 'lg',
  3828. resolve: {
  3829. selectedNotices: function(){return $scope.tableParams.data;}
  3830. }
  3831. });
  3832. modalInstance.result.then(function(){
  3833. $scope.tableParams.reload();
  3834. }, function(){
  3835. });
  3836. };
  3837. $scope.getSends = function(notice){
  3838. if( ! notice.sends && notice.endQty > 0){
  3839. notice.getSendsing = true;
  3840. notice.getSendsError = false;
  3841. PurcNotice.getSends({id: notice.id}, function(data){
  3842. notice.getSendsing = false;
  3843. notice.getSendsError = false;
  3844. notice.sends = data;
  3845. }, function(response){
  3846. notice.getSendsing = false;
  3847. notice.getSendsError = true;
  3848. });
  3849. }
  3850. };
  3851. // 搜索框回车
  3852. $scope.onSearch = function() {
  3853. $scope.tableParams.page(1);
  3854. $scope.tableParams.reload();
  3855. };
  3856. // 选择查找日期
  3857. $scope.onDateCondition = function(){
  3858. $scope.tableParams.page(1);
  3859. $scope.tableParams.reload();
  3860. };
  3861. //货车功能
  3862. var truck = $rootScope.truck;
  3863. if(!truck) {
  3864. SaleTruck.query({}, function(data){
  3865. $rootScope.truck = data;
  3866. });
  3867. }
  3868. $scope.isInTruck = function(noticeId) {
  3869. return truck.indexOf(noticeId) > -1;
  3870. };
  3871. $scope.addtoTruck = function(notice) {
  3872. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  3873. $rootScope.truck = data;
  3874. });
  3875. };
  3876. $scope.delFromTruck = function(notice) {
  3877. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  3878. $rootScope.truck = data;
  3879. });
  3880. };
  3881. $scope.$watch(function(){
  3882. return $rootScope.truck;
  3883. }, function(data) {
  3884. truck = $rootScope.truck;
  3885. }, true);
  3886. $scope.$watch(function(){
  3887. return $rootScope.dataChanged;
  3888. }, function(data) {
  3889. data && ($scope.tableParams.reload());
  3890. }, true);
  3891. }]);
  3892. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  3893. $scope.notices = angular.copy(selectedNotices);
  3894. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3895. $scope.saleSend = {
  3896. code: '',
  3897. payments: '',
  3898. currency: '',
  3899. custUU: null,
  3900. custUserUU: null,
  3901. remark: '批量发货',
  3902. sendItems: []
  3903. };
  3904. // 计算总数、总额
  3905. $scope.$watch(function(){
  3906. return $scope.notices;
  3907. }, function(data) {
  3908. var q = 0, t = 0;
  3909. if(data) {
  3910. angular.forEach(data,function(d){
  3911. q += (d.thisSendQty || 0);
  3912. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  3913. });
  3914. }
  3915. $scope.totalQty = q;
  3916. $scope.total = t;
  3917. }, true);
  3918. /**
  3919. * 删除一个已选中的送货提醒
  3920. */
  3921. $scope.removeOne = function(index) {
  3922. $scope.notices.splice(index, 1);
  3923. };
  3924. //确认送货
  3925. $scope.sendByBatch = function () {
  3926. $scope.saleSend.sendItems = [];
  3927. if($scope.saleSend.code == '') {//送货单号为空
  3928. toaster.pop('error', '错误', '请输入送货单号');
  3929. return;
  3930. }
  3931. var a = 0;
  3932. var num = 1;
  3933. var valid = true;
  3934. angular.forEach($scope.notices, function(item, key){
  3935. if(item.$selected) {
  3936. if(a == 0) {//第一次
  3937. $scope.saleSend.currency = item.orderItem.order.currency;
  3938. $scope.saleSend.custUU = item.enUU;
  3939. $scope.saleSend.payments = item.orderItem.order.payments;
  3940. a = 1;
  3941. } else {//其他
  3942. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  3943. if($scope.saleSend.custUU != item.enUU) valid = false;
  3944. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  3945. }
  3946. $scope.saleSend.sendItems.push({
  3947. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  3948. });
  3949. }
  3950. });
  3951. if(!valid) {
  3952. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  3953. } else {
  3954. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  3955. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  3956. $modalInstance.close('success');
  3957. $state.go('sale.send_detail', {id: data.id});
  3958. }, function(response){
  3959. toaster.pop('error', '错误', response.data);
  3960. });
  3961. }
  3962. };
  3963. $scope.cancel = function () {
  3964. $modalInstance.dismiss();
  3965. };
  3966. }]);
  3967. /**
  3968. * 发货单
  3969. */
  3970. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  3971. BaseService.scrollBackToTop();
  3972. $scope.active = 'all';
  3973. $scope.currency = Symbol.currency;
  3974. $scope.dateZoneText = '不限';
  3975. $scope.condition = {dateZone: -1};
  3976. $scope.changeDateZone = function(zone) {
  3977. $scope.condition.dateZone = zone;
  3978. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3979. $scope.condition.$dateZoneOpen = false;
  3980. getDateCondition(zone, $scope.condition);
  3981. $scope.tableParams.reload();
  3982. };
  3983. $scope.setActive = function(state) {
  3984. if($scope.active != state) {
  3985. $scope.active = state;
  3986. if($scope.tableParams.page() == 1)
  3987. $scope.tableParams.reload();
  3988. else
  3989. $scope.tableParams.page(1);
  3990. }
  3991. };
  3992. var getService = function() {
  3993. return SaleSend;
  3994. };
  3995. $scope.tableParams = new ngTableParams({
  3996. page : 1,
  3997. count : 5,
  3998. sorting: {
  3999. date: 'desc'
  4000. }
  4001. }, {
  4002. total : 0,
  4003. counts: [5, 10, 25, 50],
  4004. getData : function($defer, params) {
  4005. $scope.loading = true;
  4006. var pageParams = params.url();
  4007. pageParams.keyword = $scope.keyword;
  4008. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4009. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4010. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4011. $scope.loading = false;
  4012. if(page) {
  4013. params.total(page.totalElement);
  4014. $defer.resolve(page.content);
  4015. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4016. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4017. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4018. }
  4019. }, function(response){
  4020. $scope.loading = false;
  4021. toaster.pop('error', '数据加载失败', response.data);
  4022. });
  4023. }
  4024. });
  4025. $scope.openDatePicker = function($event, item, openParam) {
  4026. $event.preventDefault();
  4027. $event.stopPropagation();
  4028. item[openParam] = !item[openParam];
  4029. };
  4030. // 搜索框回车
  4031. $scope.onSearch = function() {
  4032. $scope.tableParams.page(1);
  4033. $scope.tableParams.reload();
  4034. };
  4035. // 选择查找日期
  4036. $scope.onDateCondition = function(){
  4037. $scope.tableParams.page(1);
  4038. $scope.tableParams.reload();
  4039. };
  4040. }]);
  4041. /**
  4042. * 发货单(包括发货条码维护)
  4043. */
  4044. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  4045. var loading = true;
  4046. $scope.checkBarCode = [];
  4047. $scope.checkBoxCode = [];
  4048. var vm = $scope.vm = {};
  4049. $scope.getCheckedItems = {};
  4050. vm.editBar = false;
  4051. vm.showBarCode = [];
  4052. $scope.barCode = function() {
  4053. vm.editBar = !vm.editBar;
  4054. }
  4055. $scope.checkboxes = {
  4056. checked : false
  4057. };
  4058. $scope.checkbars = {
  4059. checked : false
  4060. };
  4061. // 点击勾选barCode全部的复选框
  4062. $scope.checkBarAll = function(){
  4063. angular.forEach($scope.checkBarCode, function(item,key) {
  4064. $scope.checkBarCode[key] = $scope.checkbars.checked;
  4065. });
  4066. };
  4067. //点击barCode单选
  4068. $scope.checkBarOne = function() {
  4069. var result = true;
  4070. angular.forEach($scope.checkBarCode, function(item,key) {
  4071. if(item != true){
  4072. result = false;
  4073. return;
  4074. }
  4075. });
  4076. $scope.checkbars.checked = result;
  4077. }
  4078. // 点击boxCode全部的复选框
  4079. $scope.checkBoxAll = function(){
  4080. angular.forEach($scope.checkBoxCode, function(item,key) {
  4081. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  4082. });
  4083. };
  4084. //点击boxCode单选
  4085. $scope.checkBoxOne = function() {
  4086. var result = true;
  4087. angular.forEach($scope.checkBoxCode, function(item) {
  4088. if(item != true){
  4089. result = false;
  4090. return;
  4091. }
  4092. });
  4093. $scope.checkboxes.checked = result;
  4094. }
  4095. /**
  4096. * 生成条码和箱号
  4097. */
  4098. $scope.generateBarCode = function(item) {
  4099. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  4100. $scope.getCheckedItems = [];
  4101. var warningdata = '';
  4102. angular.forEach($scope.checkBarCode, function(item,key) {
  4103. $scope.getCheckedItem = {};
  4104. if(item == true ){
  4105. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4106. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  4107. $scope.getCheckedItems.push($scope.getCheckedItem);
  4108. //判断是否生成过条码
  4109. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4110. warningdata += $scope.order.sendItems[key].number+","
  4111. }
  4112. }
  4113. });
  4114. if($scope.getCheckedItems.length == 0){
  4115. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  4116. return;
  4117. }
  4118. if(warningdata != ''){
  4119. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  4120. return ;
  4121. }
  4122. }
  4123. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  4124. toaster.pop('success', '提示','生成成功!');
  4125. loadData();
  4126. },function(response){
  4127. $scope.loading = false;
  4128. toaster.pop('error', '生成失败', response.data);
  4129. });
  4130. }
  4131. /**
  4132. * 打印条码和箱号
  4133. */
  4134. $scope.printCode = function(type) {
  4135. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4136. //勾选需要打印的行
  4137. $scope.getCheckedItems = [];
  4138. var warningdata = ''
  4139. angular.forEach($scope.checkBarCode, function(item,key) {
  4140. $scope.getCheckedItem = {};
  4141. if(item == true ){
  4142. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4143. $scope.getCheckedItems.push($scope.getCheckedItem);
  4144. //判断是否生成过条码
  4145. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4146. warningdata += $scope.order.sendItems[key].number+","
  4147. }
  4148. }
  4149. });
  4150. if($scope.getCheckedItems.length == 0){
  4151. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  4152. return;
  4153. }
  4154. if(warningdata == ''){
  4155. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  4156. return;
  4157. }
  4158. //选择打印模板
  4159. var modalInstance = $modal.open({
  4160. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4161. controller: 'BarPrintModalCtrl',
  4162. resolve: {
  4163. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  4164. }
  4165. });
  4166. modalInstance.result.then(function(s){
  4167. if(s) {
  4168. //获取打印数据
  4169. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  4170. if(s.type == 'print'){//判断选择是打印还是打印预览
  4171. lodopPrint(data.message,LODOP,type);
  4172. }else if(s.type == 'printPreview'){
  4173. lodopPrintPreview(data.message,LODOP,type);
  4174. }
  4175. },function(response){
  4176. toaster.pop('error', '获取打印数据失败', response.data);
  4177. });
  4178. }
  4179. });
  4180. };
  4181. //打印单个条码
  4182. $scope.printSingleCode = function(id){
  4183. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4184. //选择打印模板
  4185. var modalInstance = $modal.open({
  4186. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4187. controller: 'BarPrintModalCtrl',
  4188. resolve: {
  4189. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  4190. }
  4191. });
  4192. modalInstance.result.then(function(s){
  4193. if(s) {
  4194. //获取打印数据
  4195. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  4196. if(s.type == 'print'){//判断选择是打印还是打印预览
  4197. lodopSPrint(data.message,LODOP);
  4198. }else if(s.type == 'printPreview'){
  4199. lodopSPrintPreview(data.message,LODOP);
  4200. }
  4201. },function(response){
  4202. toaster.pop('error', '获取打印数据失败', response.data);
  4203. });
  4204. }
  4205. });
  4206. }
  4207. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  4208. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4209. if (selectOrNot != -1) {
  4210. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4211. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4212. var strs = pagesize.split("*"); //字符分割
  4213. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4214. angular.forEach(printStore, function(data, index) {
  4215. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4216. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4217. if (data['LP_VALUETYPE'] == 'barcode') {
  4218. 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']);
  4219. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4220. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4221. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4222. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4223. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4224. } else if (data['LP_VALUETYPE'] == 'text') {
  4225. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4226. }
  4227. });
  4228. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4229. LODOP.PRINT();
  4230. }
  4231. };
  4232. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  4233. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4234. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4235. var strs = pagesize.split("*"); //字符分割
  4236. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4237. angular.forEach(printStore,function(data,index){
  4238. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  4239. if(data['LP_VALUETYPE'] == 'barcode'){
  4240. 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']);
  4241. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  4242. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  4243. }else if(data['LP_VALUETYPE'] == 'text'){
  4244. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4245. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  4246. }
  4247. });
  4248. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  4249. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  4250. LODOP.PREVIEW();//打印预览
  4251. };
  4252. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  4253. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4254. if (selectOrNot != -1) {
  4255. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4256. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  4257. var strs= new Array(); //定义一数组
  4258. strs = pagesize.split("*"); //字符分割
  4259. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4260. var ids = new Array();
  4261. angular.forEach(printStore, function(value,key) {
  4262. //LODOP.NewPage();
  4263. angular.forEach(value['data'], function(record,key) {
  4264. angular.forEach(record['store'], function(data, index) {
  4265. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4266. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4267. if (data['LP_VALUETYPE'] == 'barcode') {
  4268. 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']);
  4269. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4270. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4271. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4272. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4273. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4274. } else if (data['LP_VALUETYPE'] == 'text') {
  4275. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4276. }
  4277. });
  4278. });
  4279. var o = new Object();
  4280. o['id'] = record['si_id']
  4281. ids.push(o);
  4282. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4283. LODOP.PRINT();
  4284. });
  4285. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  4286. if(type == 'Bar'){
  4287. //更新打印状态
  4288. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  4289. }
  4290. }
  4291. };
  4292. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  4293. var ids = new Array();
  4294. angular.forEach(printData, function(record, index){
  4295. angular.forEach(record['data'],function(value,index){
  4296. LODOP.NewPage();
  4297. angular.forEach(value['store'],function(data,index){
  4298. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  4299. if(data['LP_VALUETYPE'] == 'barcode'){
  4300. 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']);
  4301. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  4302. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  4303. }else if(data['LP_VALUETYPE'] == 'text'){
  4304. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4305. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  4306. }
  4307. });
  4308. });
  4309. var o = new Object();
  4310. o['id'] = record['si_id']
  4311. ids.push(o);
  4312. });
  4313. var pagesize = printData[0]['pagesize'];//获取标签的大小
  4314. var strs= new Array(); //定义一数组
  4315. strs = pagesize.split("*"); //字符分割
  4316. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  4317. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  4318. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4319. var times = LODOP.PREVIEW();//打印预览
  4320. if(times > 0){//点击了打印预览内的打印按钮
  4321. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  4322. if(type == 'Bar'){
  4323. //更新打印状态
  4324. SaleSend.updatePrintStatus({},ids,function(data){
  4325. loadData();
  4326. },function(res){});
  4327. }
  4328. }
  4329. };
  4330. /**
  4331. * 查看条码按钮
  4332. */
  4333. $scope.showBarCode = function(number) {
  4334. $scope.keys = number;
  4335. for(var i=0;i<vm.showBarCode.length;i++){
  4336. if(i!=number){
  4337. vm.showBarCode[i] = false;
  4338. }
  4339. }
  4340. vm.showBarCode[number] = !vm.showBarCode[number];
  4341. $scope.barcodes = [];
  4342. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  4343. var getPage = function(page, size){
  4344. if($scope.barcodes) {
  4345. var result = {};
  4346. result.totalCount = $scope.barcodes.length;
  4347. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  4348. if($scope.barcodes.length % size == 0) {
  4349. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  4350. }else {
  4351. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  4352. }
  4353. result.first = page == 1;
  4354. result.last = page == result.totalPage;
  4355. result.page = page;
  4356. result.next = page - 0 + 1;
  4357. result.pre = page - 1;
  4358. return result;
  4359. }
  4360. }
  4361. $scope.barData = getPage(1,5);
  4362. $scope.first = function (){
  4363. $scope.barData = getPage($scope.barData.pre,5);
  4364. }
  4365. $scope.last = function (){
  4366. $scope.barData = getPage($scope.barData.next,5);
  4367. }
  4368. };
  4369. /**
  4370. * 更新外箱号
  4371. */
  4372. $scope.updateOutBox = function(item,number) {
  4373. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  4374. }else {
  4375. if(item.outBoxQty > 0) {
  4376. if(!(item.outBoxQty % item.packageQty)) {
  4377. SaleSend.update({id:item.id},item,function(){
  4378. toaster.pop('success', '提示','保存成功!');
  4379. loadData();
  4380. }, function(response){
  4381. $scope.loading = false;
  4382. toaster.pop('error', '回复失败', response.data);
  4383. })
  4384. }else {
  4385. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  4386. }
  4387. }else {
  4388. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  4389. }
  4390. }
  4391. loadData();
  4392. };
  4393. /**
  4394. * 更新最小包数
  4395. */
  4396. $scope.updatePackage = function(item, number) {
  4397. if(item.packageQty == $scope.oldpackageQty[number]) {
  4398. }else {
  4399. if(item.orderItem.product.minPack != 0) {
  4400. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  4401. if(!(item.packageQty % item.orderItem.product.minPack)) {
  4402. SaleSend.update({id:item.id},item,function(){
  4403. toaster.pop('success', '提示','保存成功!');
  4404. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  4405. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  4406. }
  4407. loadData();
  4408. }, function(response){
  4409. $scope.loading = false;
  4410. toaster.pop('error', '回复失败', response.data);
  4411. })
  4412. }else {
  4413. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  4414. }
  4415. }else {
  4416. toaster.pop('warning', '提示', '请填写有效的数量!');
  4417. }
  4418. }else {
  4419. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  4420. SaleSend.update({id:item.id},item,function(){
  4421. toaster.pop('success', '提示','保存成功!');
  4422. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  4423. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  4424. }
  4425. loadData();
  4426. }, function(response){
  4427. $scope.loading = false;
  4428. toaster.pop('error', '回复失败', response.data);
  4429. })
  4430. }else {
  4431. toaster.pop('warning', '提示', '请填写有效的数量!');
  4432. }
  4433. }
  4434. }
  4435. loadData();
  4436. };
  4437. var loadData = function() {
  4438. SaleSend.get({id: $stateParams.id}, function(data){
  4439. $scope.order = data;
  4440. var orderCount = $scope.order.sendItems.length;
  4441. $scope.oldpackageQty = [];
  4442. $scope.oldoutBoxQty = [];
  4443. var sum = 0;
  4444. vm.oldpackageQty = [];
  4445. angular.forEach(data.sendItems, function(value, key){
  4446. //给showBarCode数组赋初值
  4447. if (vm.showBarCode.length < orderCount){
  4448. vm.showBarCode.push(false);
  4449. }
  4450. if($scope.checkBarCode.length < orderCount) {
  4451. $scope.checkBarCode.push(false);
  4452. }
  4453. if($scope.checkBoxCode.length < orderCount) {
  4454. $scope.checkBoxCode.push(false);
  4455. }
  4456. //给个初值
  4457. if(!value.packageQty) {
  4458. value.packageQty = value.orderItem.product.minPack;
  4459. }
  4460. $scope.oldpackageQty.push(value.packageQty);
  4461. if(value.outBoxQty) {
  4462. $scope.oldoutBoxQty.push(value.outBoxQty);
  4463. }
  4464. sum += value.price * value.qty;
  4465. });
  4466. data.total = sum;
  4467. $scope.loading = false;
  4468. }, function(response){
  4469. loading = false;
  4470. toaster.pop('error', '获取数据失败', response.data);
  4471. });
  4472. };
  4473. loadData();
  4474. }]);
  4475. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  4476. $scope.typeItem = typeItem;
  4477. $scope.template = [];
  4478. $scope.choose = {};
  4479. //获取打印模板
  4480. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  4481. if(data.message){
  4482. $scope.template = data.message;
  4483. $scope.choose.tp_id = $scope.template[0].id;
  4484. }
  4485. },function(res){
  4486. toaster.pop('error', '获取模板错误', res.data);
  4487. });
  4488. $scope.print = function(){
  4489. $scope.choose.type = 'print';
  4490. $modalInstance.close($scope.choose);
  4491. };
  4492. $scope.printPreview = function(){
  4493. $scope.choose.type = 'printPreview';
  4494. $modalInstance.close($scope.choose);
  4495. }
  4496. $scope.cancel = function(){
  4497. $modalInstance.close();
  4498. }
  4499. }]);
  4500. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  4501. var loading = true;
  4502. var loadData = function() {
  4503. PurcSample.get({id: $stateParams.id}, function(data){
  4504. $scope.sample = data;
  4505. if(!$scope.sample.send){
  4506. $scope.sample.getSendInfo = '加载中...';
  4507. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  4508. if(sendData) {
  4509. $scope.sample.getSendInfo = null;
  4510. $scope.sample.send = sendData;
  4511. } else {
  4512. $scope.sample.getSendInfo = '无送样信息';
  4513. $scope.sample.send = '无送样信息';
  4514. }
  4515. }, function(response){
  4516. $scope.sample.getSendInfo = '加载失败!';
  4517. });
  4518. }
  4519. $scope.loading = false;
  4520. }, function(response){
  4521. loading = false;
  4522. toaster.pop('error', '获取数据失败', response.data);
  4523. });
  4524. };
  4525. loadData();
  4526. }]);
  4527. /**
  4528. * 客户打样申请
  4529. */
  4530. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  4531. BaseService.scrollBackToTop();
  4532. $scope.active = 'todo';
  4533. $scope.agreedText = '全部';
  4534. $scope.dateZoneText = '一个月内';
  4535. $scope.condition = {dateZone: 1};
  4536. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4537. $scope.changeAgreed = function(agreed) {
  4538. $scope.condition.agreed = agreed;
  4539. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4540. $scope.condition.$agreedOpen = false;
  4541. };
  4542. $scope.changeDateZone = function(zone) {
  4543. $scope.condition.dateZone = zone;
  4544. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4545. $scope.condition.$dateZoneOpen = false;
  4546. };
  4547. $scope.setActive = function(state) {
  4548. if($scope.active != state) {
  4549. $scope.active = state;
  4550. if($scope.tableParams.page() == 1)
  4551. $scope.tableParams.reload();
  4552. else
  4553. $scope.tableParams.page(1);
  4554. }
  4555. };
  4556. var getService = function() {
  4557. return PurcSample;
  4558. };
  4559. $scope.tableParams = new ngTableParams({
  4560. page : 1,
  4561. count : 5,
  4562. sorting: {
  4563. proofingDate: 'desc'
  4564. }
  4565. }, {
  4566. total : 0,
  4567. counts: [5, 10, 25, 50],
  4568. getData : function($defer, params) {
  4569. $scope.loading = true;
  4570. var pageParams = params.url();
  4571. pageParams.keyword = $scope.keyword;
  4572. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4573. $scope.loading = false;
  4574. if(page) {
  4575. params.total(page.totalElement);
  4576. $defer.resolve(page.content);
  4577. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4578. }
  4579. }, function(response){
  4580. $scope.loading = false;
  4581. toaster.pop('error', '数据加载失败', response.data);
  4582. });
  4583. }
  4584. });
  4585. $scope.openDatePicker = function($event, item, openParam) {
  4586. $event.preventDefault();
  4587. $event.stopPropagation();
  4588. item[openParam] = !item[openParam];
  4589. };
  4590. $scope.openSend = function(index, sample) {
  4591. var modalInstance = $modal.open({
  4592. animation: true,
  4593. templateUrl: 'static/tpl/index/sale/sample_send.html',
  4594. controller: 'SampleSendCtrl',
  4595. resolve: {
  4596. sampleItem: function(){return sample;}
  4597. }
  4598. });
  4599. modalInstance.result.then(function(){
  4600. toaster.pop('info', '提示', '送样成功');
  4601. $scope.tableParams.reload();
  4602. }, function(){
  4603. });
  4604. };
  4605. //打印 样品采购单
  4606. $scope.print = function(sample) {
  4607. console.log(sample);
  4608. PurcSample.printCount({id: sample.id},{});//增加打印此次
  4609. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  4610. };
  4611. $scope.getSend = function(proofing){
  4612. if( !proofing.send) {
  4613. proofing.getSendInfo = '加载中...';
  4614. PurcSample.getSend({id: proofing.id}, function(data){
  4615. if(data) {
  4616. proofing.getSendInfo = null;
  4617. proofing.send = data;
  4618. } else {
  4619. proofing.getSendInfo = '无送样信息';
  4620. proofing.send = '无送样信息';
  4621. }
  4622. }, function(response){
  4623. proofing.getSendInfo = '加载失败!';
  4624. });
  4625. }
  4626. };
  4627. // 搜索框回车
  4628. $scope.onSearch = function() {
  4629. $scope.tableParams.page(1);
  4630. $scope.tableParams.reload();
  4631. };
  4632. }]);
  4633. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  4634. $scope.sampleItem = sampleItem;
  4635. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  4636. //确认送样
  4637. $scope.ok = function (form) {
  4638. $scope.loading = true;
  4639. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  4640. $upload.upload({
  4641. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  4642. method: 'POST',
  4643. file: file,
  4644. data: {
  4645. json: $scope.sampleItem.sampleSend
  4646. }
  4647. }).success(function(data){
  4648. $scope.loading = false;
  4649. $modalInstance.close('success');
  4650. }).error(function(data){
  4651. $scope.loading = false;
  4652. toaster.pop('danger', '错误', data);
  4653. });
  4654. };
  4655. $scope.cancel = function () {
  4656. $modalInstance.dismiss(sampleItem);
  4657. };
  4658. }]);
  4659. /**
  4660. * 客户认定单
  4661. */
  4662. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  4663. BaseService.scrollBackToTop();
  4664. $scope.active = 'all';
  4665. $scope.agreedText = '全部';
  4666. $scope.dateZoneText = '一个月内';
  4667. $scope.condition = {dateZone: 1};
  4668. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4669. $scope.changeDateZone = function(zone) {
  4670. $scope.condition.dateZone = zone;
  4671. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4672. $scope.condition.$dateZoneOpen = false;
  4673. getDateCondition(zone, $scope.condition);
  4674. $scope.tableParams.reload();
  4675. };
  4676. $scope.setActive = function(state) {
  4677. if($scope.active != state) {
  4678. $scope.active = state;
  4679. if($scope.tableParams.page() == 1)
  4680. $scope.tableParams.reload();
  4681. else
  4682. $scope.tableParams.page(1);
  4683. }
  4684. };
  4685. var getService = function() {
  4686. return PurcApproval;
  4687. };
  4688. $scope.tableParams = new ngTableParams({
  4689. page : 1,
  4690. count : 5,
  4691. sorting: {
  4692. inDate: 'desc'
  4693. }
  4694. }, {
  4695. total : 0,
  4696. counts: [5, 10, 25, 50],
  4697. getData : function($defer, params) {
  4698. $scope.loading = true;
  4699. var pageParams = params.url();
  4700. pageParams.keyword = $scope.keyword;
  4701. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4702. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4703. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4704. $scope.loading = false;
  4705. if(page) {
  4706. params.total(page.totalElement);
  4707. $defer.resolve(page.content);
  4708. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4709. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4710. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4711. }
  4712. }, function(response){
  4713. $scope.loading = false;
  4714. toaster.pop('error', '数据加载失败', response.data);
  4715. });
  4716. }
  4717. });
  4718. $scope.openDatePicker = function($event, item, openParam) {
  4719. $event.preventDefault();
  4720. $event.stopPropagation();
  4721. item[openParam] = !item[openParam];
  4722. };
  4723. $scope.parseDate = function(dateStr) {
  4724. if(dateStr)
  4725. return Date.parse(dateStr, 'yyyy-MM-dd');
  4726. return new Date();
  4727. };
  4728. // 搜索框回车
  4729. $scope.onSearch = function() {
  4730. $scope.tableParams.page(1);
  4731. $scope.tableParams.reload();
  4732. };
  4733. // 选择查找日期
  4734. $scope.onDateCondition = function(){
  4735. $scope.tableParams.page(1);
  4736. $scope.tableParams.reload();
  4737. };
  4738. }]);
  4739. /**
  4740. * 客户采购预测
  4741. */
  4742. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  4743. BaseService.scrollBackToTop();
  4744. $scope.active = 'all';
  4745. $scope.agreedText = '全部';
  4746. $scope.dateZoneText = '一个月内';
  4747. $scope.condition = {dateZone: 1};
  4748. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4749. $scope.changeAgreed = function(agreed) {
  4750. $scope.condition.agreed = agreed;
  4751. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4752. $scope.condition.$agreedOpen = false;
  4753. };
  4754. $scope.changeDateZone = function(zone) {
  4755. $scope.condition.dateZone = zone;
  4756. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4757. $scope.condition.$dateZoneOpen = false;
  4758. };
  4759. $scope.setActive = function(state) {
  4760. if($scope.active != state) {
  4761. $scope.active = state;
  4762. if($scope.tableParams.page() == 1)
  4763. $scope.tableParams.reload();
  4764. else
  4765. $scope.tableParams.page(1);
  4766. }
  4767. };
  4768. var getService = function() {
  4769. return PurcForecast;
  4770. };
  4771. $scope.tableParams = new ngTableParams({
  4772. page : 1,
  4773. count : 5,
  4774. sorting: {
  4775. orderDate: 'desc'
  4776. }
  4777. }, {
  4778. total : 0,
  4779. counts: [5, 10, 25, 50],
  4780. getData : function($defer, params) {
  4781. $scope.loading = true;
  4782. var pageParams = params.url();
  4783. pageParams.keyword = $scope.keyword;
  4784. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4785. $scope.loading = false;
  4786. if(page) {
  4787. console.log(page);
  4788. params.total(page.totalElement);
  4789. $defer.resolve(page.content);
  4790. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4791. }
  4792. }, function(response){
  4793. $scope.loading = false;
  4794. toaster.pop('error', '数据加载失败', response.data);
  4795. });
  4796. }
  4797. });
  4798. $scope.openDatePicker = function($event, item, openParam) {
  4799. $event.preventDefault();
  4800. $event.stopPropagation();
  4801. item[openParam] = !item[openParam];
  4802. };
  4803. // 搜索框回车
  4804. $scope.onSearch = function() {
  4805. $scope.tableParams.page(1);
  4806. $scope.tableParams.reload();
  4807. };
  4808. }]);
  4809. /**
  4810. * 客户采购验收
  4811. */
  4812. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  4813. BaseService.scrollBackToTop();
  4814. $scope.active = 'all';
  4815. $scope.dateZoneText = '不限';
  4816. $scope.deliveryZoneText = '不限';
  4817. $scope.condition = {dateZone: -1, deliveryZone: -1};
  4818. $scope.changeDateZone = function(zone) {
  4819. $scope.condition.dateZone = zone;
  4820. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4821. $scope.condition.$dateZoneOpen = false;
  4822. getDateCondition(zone, $scope.condition);
  4823. $scope.tableParams.reload();
  4824. };
  4825. $scope.changeDeliveryZone = function(zone) {
  4826. $scope.condition.deliveryZoneText = zone;
  4827. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  4828. $scope.condition.$delievryZoneOpen = false;
  4829. getDelveryCondition(zone, $scope.condition);
  4830. $scope.tableParams.reload();
  4831. };
  4832. $scope.setActive = function(state) {
  4833. if($scope.active != state) {
  4834. $scope.active = state;
  4835. if($scope.tableParams.page() == 1)
  4836. $scope.tableParams.reload();
  4837. else
  4838. $scope.tableParams.page(1);
  4839. }
  4840. };
  4841. var getService = function() {
  4842. return PurcAccept;
  4843. };
  4844. $scope.tableParams = new ngTableParams({
  4845. page : 1,
  4846. count : 5,
  4847. sorting: {
  4848. date: 'desc'
  4849. }
  4850. }, {
  4851. total : 0,
  4852. counts: [5, 10, 25, 50],
  4853. getData : function($defer, params) {
  4854. $scope.loading = true;
  4855. var pageParams = params.url();
  4856. pageParams.searchFilter = { // 筛选条件
  4857. keyword: $scope.keyword,
  4858. fromDate: getDateTime($scope.condition.dateFrom),
  4859. endDate: getDateTime($scope.condition.dateTo)
  4860. };
  4861. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4862. $scope.loading = false;
  4863. if(page) {
  4864. params.total(page.totalElement);
  4865. $defer.resolve(page.content);
  4866. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4867. }
  4868. }, function(response){
  4869. $scope.loading = false;
  4870. toaster.pop('error', '数据加载失败', response.data);
  4871. });
  4872. }
  4873. });
  4874. $scope.openDatePicker = function($event, item, openParam) {
  4875. $event.preventDefault();
  4876. $event.stopPropagation();
  4877. item[openParam] = !item[openParam];
  4878. };
  4879. $scope.parseDate = function(dateStr) {
  4880. if(dateStr)
  4881. return Date.parse(dateStr, 'yyyy-MM-dd');
  4882. return new Date();
  4883. };
  4884. // 选择查找日期
  4885. $scope.onDateCondition = function(){
  4886. $scope.tableParams.page(1);
  4887. $scope.tableParams.reload();
  4888. };
  4889. // 搜索框回车
  4890. $scope.onSearch = function() {
  4891. $scope.tableParams.page(1);
  4892. $scope.tableParams.reload();
  4893. };
  4894. }]);
  4895. /**
  4896. * 客户采购验退
  4897. */
  4898. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  4899. BaseService.scrollBackToTop();
  4900. $scope.active = 'all';
  4901. $scope.agreedText = '全部';
  4902. $scope.dateZoneText = '一个月内';
  4903. $scope.condition = {dateZone: 1};
  4904. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4905. $scope.changeAgreed = function(agreed) {
  4906. $scope.condition.agreed = agreed;
  4907. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4908. $scope.condition.$agreedOpen = false;
  4909. };
  4910. $scope.changeDateZone = function(zone) {
  4911. $scope.condition.dateZone = zone;
  4912. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4913. $scope.condition.$dateZoneOpen = false;
  4914. };
  4915. $scope.setActive = function(state) {
  4916. if($scope.active != state) {
  4917. $scope.active = state;
  4918. if($scope.tableParams.page() == 1)
  4919. $scope.tableParams.reload();
  4920. else
  4921. $scope.tableParams.page(1);
  4922. }
  4923. };
  4924. var getService = function() {
  4925. return PurcReturn;
  4926. };
  4927. $scope.tableParams = new ngTableParams({
  4928. page : 1,
  4929. count : 5,
  4930. sorting: {
  4931. date: 'desc'
  4932. }
  4933. }, {
  4934. total : 0,
  4935. counts: [5, 10, 25, 50],
  4936. getData : function($defer, params) {
  4937. $scope.loading = true;
  4938. var pageParams = params.url();
  4939. pageParams.keyword = $scope.keyword;
  4940. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4941. $scope.loading = false;
  4942. if(page) {
  4943. params.total(page.totalElement);
  4944. $defer.resolve(page.content);
  4945. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4946. angular.forEach(page.content, function(data) {
  4947. if (!data.returnItems[0].orderItem) {
  4948. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  4949. data.enName = enterprise.enName;
  4950. });
  4951. }
  4952. });
  4953. }
  4954. }, function(response){
  4955. $scope.loading = false;
  4956. toaster.pop('error', '数据加载失败', response.data);
  4957. });
  4958. }
  4959. });
  4960. $scope.openDatePicker = function($event, item, openParam) {
  4961. $event.preventDefault();
  4962. $event.stopPropagation();
  4963. item[openParam] = !item[openParam];
  4964. };
  4965. // 搜索框回车
  4966. $scope.onSearch = function() {
  4967. $scope.tableParams.page(1);
  4968. $scope.tableParams.reload();
  4969. };
  4970. }]);
  4971. /**
  4972. * 客户不良品入库
  4973. */
  4974. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  4975. BaseService.scrollBackToTop();
  4976. $scope.active = 'all';
  4977. $scope.agreedText = '全部';
  4978. $scope.dateZoneText = '一个月内';
  4979. $scope.condition = {dateZone: 1};
  4980. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4981. $scope.changeAgreed = function(agreed) {
  4982. $scope.condition.agreed = agreed;
  4983. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4984. $scope.condition.$agreedOpen = false;
  4985. };
  4986. $scope.changeDateZone = function(zone) {
  4987. $scope.condition.dateZone = zone;
  4988. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4989. $scope.condition.$dateZoneOpen = false;
  4990. };
  4991. $scope.setActive = function(state) {
  4992. if($scope.active != state) {
  4993. $scope.active = state;
  4994. if($scope.tableParams.page() == 1)
  4995. $scope.tableParams.reload();
  4996. else
  4997. $scope.tableParams.page(1);
  4998. }
  4999. };
  5000. var getService = function() {
  5001. return PurcBadIn;
  5002. };
  5003. $scope.tableParams = new ngTableParams({
  5004. page : 1,
  5005. count : 5,
  5006. sorting: {
  5007. date: 'desc'
  5008. }
  5009. }, {
  5010. total : 0,
  5011. counts: [5, 10, 25, 50],
  5012. getData : function($defer, params) {
  5013. $scope.loading = true;
  5014. var pageParams = params.url();
  5015. pageParams.keyword = $scope.keyword;
  5016. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5017. $scope.loading = false;
  5018. if(page) {
  5019. params.total(page.totalElement);
  5020. $defer.resolve(page.content);
  5021. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5022. }
  5023. }, function(response){
  5024. $scope.loading = false;
  5025. toaster.pop('error', '数据加载失败', response.data);
  5026. });
  5027. }
  5028. });
  5029. $scope.openDatePicker = function($event, item, openParam) {
  5030. $event.preventDefault();
  5031. $event.stopPropagation();
  5032. item[openParam] = !item[openParam];
  5033. };
  5034. // 搜索框回车
  5035. $scope.onSearch = function() {
  5036. $scope.tableParams.page(1);
  5037. $scope.tableParams.reload();
  5038. };
  5039. }]);
  5040. /**
  5041. * 客户不良品出库
  5042. */
  5043. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  5044. BaseService.scrollBackToTop();
  5045. $scope.active = 'all';
  5046. $scope.agreedText = '全部';
  5047. $scope.dateZoneText = '一个月内';
  5048. $scope.condition = {dateZone: 1};
  5049. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5050. $scope.changeAgreed = function(agreed) {
  5051. $scope.condition.agreed = agreed;
  5052. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5053. $scope.condition.$agreedOpen = false;
  5054. };
  5055. $scope.changeDateZone = function(zone) {
  5056. $scope.condition.dateZone = zone;
  5057. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5058. $scope.condition.$dateZoneOpen = false;
  5059. };
  5060. $scope.setActive = function(state) {
  5061. if($scope.active != state) {
  5062. $scope.active = state;
  5063. if($scope.tableParams.page() == 1)
  5064. $scope.tableParams.reload();
  5065. else
  5066. $scope.tableParams.page(1);
  5067. }
  5068. };
  5069. var getService = function() {
  5070. return PurcBadOut;
  5071. };
  5072. $scope.tableParams = new ngTableParams({
  5073. page : 1,
  5074. count : 5,
  5075. sorting: {
  5076. date: 'desc'
  5077. }
  5078. }, {
  5079. total : 0,
  5080. counts: [5, 10, 25, 50],
  5081. getData : function($defer, params) {
  5082. $scope.loading = true;
  5083. var pageParams = params.url();
  5084. pageParams.keyword = $scope.keyword;
  5085. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5086. $scope.loading = false;
  5087. if(page) {
  5088. params.total(page.totalElement);
  5089. $defer.resolve(page.content);
  5090. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5091. }
  5092. }, function(response){
  5093. $scope.loading = false;
  5094. toaster.pop('error', '数据加载失败', response.data);
  5095. });
  5096. }
  5097. });
  5098. $scope.openDatePicker = function($event, item, openParam) {
  5099. $event.preventDefault();
  5100. $event.stopPropagation();
  5101. item[openParam] = !item[openParam];
  5102. };
  5103. // 搜索框回车
  5104. $scope.onSearch = function() {
  5105. $scope.tableParams.page(1);
  5106. $scope.tableParams.reload();
  5107. };
  5108. }]);
  5109. /**
  5110. * 客户MRB
  5111. */
  5112. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  5113. BaseService.scrollBackToTop();
  5114. $scope.active = 'all';
  5115. $scope.agreedText = '全部';
  5116. $scope.dateZoneText = '一个月内';
  5117. $scope.condition = {dateZone: 1};
  5118. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5119. $scope.changeAgreed = function(agreed) {
  5120. $scope.condition.agreed = agreed;
  5121. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5122. $scope.condition.$agreedOpen = false;
  5123. };
  5124. $scope.changeDateZone = function(zone) {
  5125. $scope.condition.dateZone = zone;
  5126. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5127. $scope.condition.$dateZoneOpen = false;
  5128. };
  5129. $scope.setActive = function(state) {
  5130. if($scope.active != state) {
  5131. $scope.active = state;
  5132. if($scope.tableParams.page() == 1)
  5133. $scope.tableParams.reload();
  5134. else
  5135. $scope.tableParams.page(1);
  5136. }
  5137. };
  5138. var getService = function() {
  5139. return PurcMRB;
  5140. };
  5141. $scope.tableParams = new ngTableParams({
  5142. page : 1,
  5143. count : 5,
  5144. sorting: {
  5145. date: 'desc'
  5146. }
  5147. }, {
  5148. total : 0,
  5149. counts: [5, 10, 25, 50],
  5150. getData : function($defer, params) {
  5151. $scope.loading = true;
  5152. var pageParams = params.url();
  5153. pageParams.keyword = $scope.keyword;
  5154. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5155. $scope.loading = false;
  5156. if(page) {
  5157. params.total(page.totalElement);
  5158. $defer.resolve(page.content);
  5159. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5160. }
  5161. }, function(response){
  5162. $scope.loading = false;
  5163. toaster.pop('error', '数据加载失败', response.data);
  5164. });
  5165. }
  5166. });
  5167. $scope.openDatePicker = function($event, item, openParam) {
  5168. $event.preventDefault();
  5169. $event.stopPropagation();
  5170. item[openParam] = !item[openParam];
  5171. };
  5172. // 搜索框回车
  5173. $scope.onSearch = function() {
  5174. $scope.tableParams.page(1);
  5175. $scope.tableParams.reload();
  5176. };
  5177. }]);
  5178. /**
  5179. * 客户应付发票
  5180. */
  5181. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  5182. BaseService.scrollBackToTop();
  5183. $scope.active = 'all';
  5184. $scope.dateZoneText = '不限';
  5185. $scope.condition = {dateZone: -1};
  5186. $scope.changeDateZone = function(zone) {
  5187. $scope.condition.dateZone = zone;
  5188. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5189. $scope.condition.$dateZoneOpen = false;
  5190. getDateCondition(zone, $scope.condition);
  5191. $scope.tableParams.reload();
  5192. };
  5193. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5194. $scope.setActive = function(state) {
  5195. if($scope.active != state) {
  5196. $scope.active = state;
  5197. if($scope.tableParams.page() == 1)
  5198. $scope.tableParams.reload();
  5199. else
  5200. $scope.tableParams.page(1);
  5201. }
  5202. };
  5203. var getService = function() {
  5204. return FaApBill;
  5205. };
  5206. $scope.tableParams = new ngTableParams({
  5207. page : 1,
  5208. count : 5,
  5209. sorting: {
  5210. date: 'desc'
  5211. }
  5212. }, {
  5213. total : 0,
  5214. counts: [5, 10, 25, 50],
  5215. getData : function($defer, params) {
  5216. $scope.loading = true;
  5217. var pageParams = params.url();
  5218. pageParams.searchFilter = { // 筛选条件
  5219. keyword: $scope.keyword,
  5220. fromDate: getDateTime($scope.condition.dateFrom),
  5221. endDate: getDateTime($scope.condition.dateTo)
  5222. };
  5223. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5224. $scope.loading = false;
  5225. if(page) {
  5226. params.total(page.totalElement);
  5227. $defer.resolve(page.content);
  5228. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  5229. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5230. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5231. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  5232. }
  5233. }, function(response){
  5234. $scope.loading = false;
  5235. toaster.pop('error', '数据加载失败', response.data);
  5236. });
  5237. }
  5238. });
  5239. $scope.openDatePicker = function($event, item, openParam) {
  5240. $event.preventDefault();
  5241. $event.stopPropagation();
  5242. item[openParam] = !item[openParam];
  5243. };
  5244. $scope.parseDate = function(dateStr) {
  5245. if(dateStr)
  5246. return Date.parse(dateStr, 'yyyy-MM-dd');
  5247. return new Date();
  5248. };
  5249. // 搜索框回车
  5250. $scope.onSearch = function() {
  5251. $scope.tableParams.page(1);
  5252. $scope.tableParams.reload();
  5253. };
  5254. // 选择查找日期
  5255. $scope.onDateCondition = function(){
  5256. $scope.tableParams.page(1);
  5257. $scope.tableParams.reload();
  5258. };
  5259. }]);
  5260. /**
  5261. * 应付对账单
  5262. */
  5263. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  5264. BaseService.scrollBackToTop();
  5265. $scope.active = 'all';
  5266. $scope.dateZoneText = '不限';
  5267. $scope.condition = {dateZone: -1};
  5268. $scope.changeDateZone = function(zone) {
  5269. $scope.condition.dateZone = zone;
  5270. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5271. $scope.condition.$dateZoneOpen = false;
  5272. getDateCondition(zone, $scope.condition);
  5273. $scope.tableParams.reload();
  5274. };
  5275. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5276. $scope.setActive = function(state) {
  5277. if($scope.active != state) {
  5278. $scope.active = state;
  5279. if($scope.tableParams.page() == 1)
  5280. $scope.tableParams.reload();
  5281. else
  5282. $scope.tableParams.page(1);
  5283. }
  5284. };
  5285. var getService = function() {
  5286. return FaArCheck;
  5287. };
  5288. $scope.tableParams = new ngTableParams({
  5289. page : 1,
  5290. count : 5,
  5291. sorting: {
  5292. date: 'desc'
  5293. }
  5294. }, {
  5295. total : 0,
  5296. counts: [5, 10, 25, 50],
  5297. getData : function($defer, params) {
  5298. $scope.loading = true;
  5299. var pageParams = params.url();
  5300. pageParams.keyword = $scope.keyword;
  5301. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5302. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5303. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5304. $scope.loading = false;
  5305. if(page) {
  5306. params.total(page.totalElement);
  5307. $defer.resolve(page.content);
  5308. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5309. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5310. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5311. }
  5312. }, function(response){
  5313. $scope.loading = false;
  5314. toaster.pop('error', '数据加载失败', response.data);
  5315. });
  5316. }
  5317. });
  5318. $scope.openDatePicker = function($event, item, openParam) {
  5319. $event.preventDefault();
  5320. $event.stopPropagation();
  5321. item[openParam] = !item[openParam];
  5322. };
  5323. // 计算单据的商品总数
  5324. $scope.getTotalProd = function(check) {
  5325. var total = 0;
  5326. if(check.items) {
  5327. angular.forEach(check.items, function(value) {
  5328. total += value.qty;
  5329. });
  5330. }
  5331. return total;
  5332. };
  5333. // 搜索框回车
  5334. $scope.onSearch = function() {
  5335. $scope.tableParams.page(1);
  5336. $scope.tableParams.reload();
  5337. };
  5338. // 选择查找日期
  5339. $scope.onDateCondition = function(){
  5340. $scope.tableParams.page(1);
  5341. $scope.tableParams.reload();
  5342. };
  5343. }]);
  5344. // 应付对账单详情页
  5345. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  5346. BaseService.scrollBackToTop();
  5347. var loadData = function() {
  5348. FaArCheck.get({id: $stateParams.id}, function(data){
  5349. $scope.order = data;
  5350. $scope.loading = false;
  5351. });
  5352. };
  5353. loadData(); // 初始获取单据数据
  5354. $scope.onReplyClick = function(item, isAgreed) {
  5355. if(isAgreed) {// 同意确认
  5356. FaArCheck.agree({itemId: item.id}, {}, function(data){
  5357. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  5358. }, function(response){
  5359. toaster.pop('danger', '确认失败', response.data);
  5360. });
  5361. } else {// 不同意回复
  5362. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  5363. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  5364. }, function(response) {
  5365. toaster.pop('danger', '确认失败', response.data);
  5366. });
  5367. }
  5368. };
  5369. // 获取明细的回复记录
  5370. $scope.getReplies = function(item) {
  5371. if(!item.replies) {
  5372. FaArCheck.getReplies({itemId: item.id}, function(data) {
  5373. item.replies = data;
  5374. }, function(response) {
  5375. toaster.pop('danger', '获取对账记录失败', response.data);
  5376. });
  5377. }
  5378. };
  5379. }]);
  5380. //应收对账单列表
  5381. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  5382. BaseService.scrollBackToTop();
  5383. $scope.dateZoneText = '不限';
  5384. $scope.condition = {dateZone: -1};
  5385. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5386. $scope.active = 'todo';
  5387. //打印 对账单
  5388. $scope.print = function(check) {
  5389. FaApCheck.printCount({id: check.id},{});//增加打印此次
  5390. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  5391. };
  5392. //状态
  5393. $scope.setActive = function (state){
  5394. if($scope.active != state) {
  5395. $scope.active = state;
  5396. if($scope.tableParams.page() == 1)
  5397. $scope.tableParams.reload();
  5398. else
  5399. $scope.tableParams.page(1);
  5400. }
  5401. };
  5402. $scope.changeDateZone = function(zone) {
  5403. $scope.condition.dateZone = zone;
  5404. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5405. $scope.condition.$dateZoneOpen = false;
  5406. getDateCondition(zone, $scope.condition);
  5407. $scope.tableParams.reload();
  5408. };
  5409. //获取应收对账单全部
  5410. $scope.tableParams = new ngTableParams({
  5411. page : 1,
  5412. count : 5,
  5413. sorting: {
  5414. recordDate: 'desc'
  5415. }
  5416. }, {
  5417. total : 0,
  5418. counts: [5, 10, 25, 50],
  5419. getData : function($defer, params) {
  5420. $scope.loading = true;
  5421. var pageParams = params.url();
  5422. pageParams.searchFilter = { // 筛选条件
  5423. keyword: $scope.keyword,
  5424. fromDate: getDateTime($scope.condition.dateFrom),
  5425. endDate: getDateTime($scope.condition.dateTo)
  5426. };
  5427. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  5428. $scope.loading = false;
  5429. if(page) {
  5430. params.total(page.totalElement);
  5431. $scope.data = $defer.resolve(page.content);
  5432. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  5433. }
  5434. }, function(response){
  5435. $scope.loading = false;
  5436. toaster.pop('error', '数据加载失败', response.data);
  5437. });
  5438. }
  5439. });
  5440. $scope.openDatePicker = function($event, item, openParam) {
  5441. $event.preventDefault();
  5442. $event.stopPropagation();
  5443. item[openParam] = !item[openParam];
  5444. };
  5445. // 计算单据的商品总数
  5446. $scope.getTotalProd = function(check) {
  5447. var total = 0;
  5448. if(check.items) {
  5449. angular.forEach(check.items, function(value) {
  5450. total += value.checkQty;
  5451. });
  5452. }
  5453. return total;
  5454. };
  5455. // 搜索框回车
  5456. $scope.onSearch = function() {
  5457. $scope.tableParams.page(1);
  5458. $scope.tableParams.reload();
  5459. };
  5460. // 选择查找日期
  5461. $scope.onDateCondition = function(){
  5462. $scope.tableParams.page(1);
  5463. $scope.tableParams.reload();
  5464. };
  5465. }]);
  5466. //应收对账单详情
  5467. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  5468. BaseService.scrollBackToTop();
  5469. $scope.haveSelected = true;
  5470. $scope.data = {};
  5471. //控制提交和删除按钮的显示
  5472. $scope.ifShow = true;
  5473. var loadData = function(){
  5474. FaApCheck.get({id:$stateParams.id},function(data){
  5475. $scope.data = data;
  5476. if($scope.data.status){
  5477. }else{
  5478. $scope.ifShow = true;
  5479. }
  5480. })
  5481. };
  5482. if($stateParams.id){
  5483. loadData();
  5484. }
  5485. $scope.haveSource = false;
  5486. //提交应收对账单
  5487. $scope.submitApCheck = function(){
  5488. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  5489. if(data.result) {
  5490. toaster.pop('success', '提示', '提交成功');
  5491. $scope.haveSelected = false;
  5492. window.location.href = '#/fa/apCheck';
  5493. }else {
  5494. $scope.haveSource = true;
  5495. loadData();
  5496. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  5497. $scope.haveSelected = true;
  5498. }
  5499. },function(){
  5500. $scope.loading = false;
  5501. toaster.pop('error', '提示', '更新已转数失败');
  5502. });
  5503. }
  5504. //删除应收对账单的同时更新来源表已转数
  5505. var updateYCheckQty = function(){
  5506. var sourceInfos = [];
  5507. angular.forEach($scope.data.items, function(item){
  5508. $scope.sourceInfo = {
  5509. sourceId: '',
  5510. sourceTable: '',
  5511. newYCheckQty: ''
  5512. };
  5513. $scope.sourceInfo.sourceId = item.sourceId;
  5514. $scope.sourceInfo.sourceTable = item.sourceTable;
  5515. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  5516. sourceInfos.push($scope.sourceInfo);
  5517. });
  5518. FaApCheck.update({}, sourceInfos, function(){
  5519. },function(response){
  5520. $scope.loading = false;
  5521. toaster.pop('error', '更新已转数失败', response.data);
  5522. });
  5523. }
  5524. //删除应收对账单
  5525. $scope.deleteApCheck = function(){
  5526. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  5527. updateYCheckQty();
  5528. toaster.pop('success','提示','删除成功');
  5529. },function(){
  5530. toaster.pop('error','提示','删除失败');
  5531. });
  5532. $scope.haveSelected = false;
  5533. }
  5534. //作废应收对账单
  5535. $scope.cancelApCheck = function(check) {
  5536. FaApCheck.cancel({id:check.id},function(data){
  5537. $scope.checkResult = false;
  5538. if(data.result) {
  5539. $scope.checkResult = true;
  5540. toaster.pop('success', '提示', '作废成功');
  5541. $scope.tableParams.reload();
  5542. }else{
  5543. toaster.pop('error', '提示', '作废失败');
  5544. }
  5545. },function(){
  5546. $scope.loading = false;
  5547. toaster.pop('error', '提示', '作废失败');
  5548. });
  5549. }
  5550. }]);
  5551. //未对账单据列表
  5552. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  5553. $scope.data = {};// 列表数据
  5554. $scope.loading = true;
  5555. // $scope.getData = function(){
  5556. // FaApCheck.getAll(function(data){
  5557. // $scope.data = data;
  5558. // angular.forEach($scope.data, function(item) {
  5559. // item:{
  5560. // $selected:true;
  5561. // }
  5562. // });
  5563. // $scope.loading = false;
  5564. // });
  5565. //
  5566. // }
  5567. document.getElementById('suuorname').focus();//光标默认在客户
  5568. // $scope.getData();
  5569. $scope.condition = {
  5570. $fromOpened:false
  5571. }
  5572. $scope.openDatePicker = function($event, item, openParam) {
  5573. $event.preventDefault();
  5574. $event.stopPropagation();
  5575. item[openParam] = !item[openParam];
  5576. }
  5577. //查找客户
  5578. $scope.searchCust = function(suuorname) {
  5579. var modalInstance = $modal.open({
  5580. animation: true,
  5581. templateUrl: 'static/tpl/index/fa/custInfo.html',
  5582. controller: 'SearchCustInfoCtrl',
  5583. resolve: {
  5584. suuorname: function() {
  5585. return suuorname;
  5586. }
  5587. }
  5588. });
  5589. modalInstance.result.then(function(suuorname){
  5590. $scope.suuorname = suuorname;
  5591. });
  5592. }
  5593. // 点击筛选根据条件选择数据
  5594. $scope.suuorname = '';
  5595. $scope.sdateFrom = '';
  5596. $scope.sdateTo = '';
  5597. $scope.vuuorname = '';
  5598. $scope.factory = '';
  5599. $scope.prodTitle = '';
  5600. $scope.prodSpec = '';
  5601. $scope.condition.uuorname = '';
  5602. $scope.condition.dateFrom = '';
  5603. $scope.condition.dateTo = '';
  5604. $scope.condition.venduuorname = '';
  5605. $scope.condition.factory = '';
  5606. $scope.condition.prodTitle = '';
  5607. $scope.condition.prodSpec = '';
  5608. $scope.searchOrder = function(check) {
  5609. angular.forEach($scope.data, function(item) {
  5610. $scope.checkboxes.checked = false;
  5611. item.$selected = false;
  5612. });
  5613. $scope.totalMoney = 0;
  5614. $scope.condition.uuorname = $scope.suuorname;
  5615. $scope.condition.factory = $scope.factory
  5616. $scope.condition.prodTitle = $scope.prodTitle;
  5617. $scope.condition.prodSpec = $scope.prodSpec;
  5618. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  5619. $scope.thisdatato = ($scope.sdateTo || 0);
  5620. if($scope.thisdatato != 0) {
  5621. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  5622. } else {
  5623. $scope.condition.dateTo = ($scope.sdateTo || 0);
  5624. }
  5625. $scope.condition.venduuorname = $scope.vuuorname;
  5626. // //物料名称和物料规格存在特殊符号,用|作分割符
  5627. // $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  5628. // + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  5629. // + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  5630. // + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  5631. // + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  5632. // $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5633. // $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5634. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  5635. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5636. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5637. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  5638. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  5639. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  5640. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  5641. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  5642. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5643. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5644. if($scope.suuorname == '') {
  5645. toaster.pop('info','提示', '请先选择客户');
  5646. document.getElementById('suuorname').focus();//光标默认在客户
  5647. } else {
  5648. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  5649. $scope.data = data;
  5650. angular.forEach($scope.data, function(item) {
  5651. item:{
  5652. $selected:true;
  5653. }
  5654. });
  5655. $scope.loading = false;
  5656. }, function(response) {
  5657. toaster.pop('error', '提示', response.data);
  5658. });
  5659. }
  5660. }
  5661. }
  5662. /**
  5663. * 点击勾选框,选中要转应收对账单的订单
  5664. * */
  5665. $scope.totalMoney = 0;
  5666. $scope.checkboxes = {
  5667. checked : false
  5668. };
  5669. // 点击勾选全部的复选框
  5670. $scope.checkAll = function(){
  5671. $scope.totalMoney = 0;
  5672. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  5673. var uuorname = $scope.suuorname;
  5674. var venduuorname = $scope.venduuorname;
  5675. var dateFrom = $scope.condition.dateFrom;
  5676. var dateTo = $scope.condition.dateTo;
  5677. var prodTitle = $scope.condition.prodTitle;
  5678. var prodSpec = $scope.condition.prodSpec;
  5679. var factory = $scope.condition.factory;
  5680. angular.forEach($scope.filteredData, function(item) {
  5681. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  5682. item.$selected = $scope.checkboxes.checked;
  5683. }
  5684. });
  5685. $scope.getTotalMoney();
  5686. };
  5687. //获取已选单据总金额
  5688. var total = true;
  5689. $scope.getTotalMoney = function(){
  5690. $scope.totalMoney = 0;
  5691. angular.forEach($scope.data, function(check) {
  5692. if(check.$selected){
  5693. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5694. }else{
  5695. $scope.totalMoney += 0;
  5696. }
  5697. });
  5698. }
  5699. // 点击其中一个明细的复选框
  5700. $scope.checkOne = function(check){
  5701. var result = true;
  5702. angular.forEach($scope.data, function(item) {
  5703. if(item.$selected != true){
  5704. result = false;
  5705. return;
  5706. }
  5707. });
  5708. $scope.checkboxes.checked = result;
  5709. };
  5710. $scope.haveSelected = false;
  5711. //生成应收对账单
  5712. $scope.createApCheck = function(){
  5713. //保存应收对账单主记录字段
  5714. $scope.apCheck = {
  5715. custUu: '',
  5716. custName: '',
  5717. enUu: '',
  5718. apDate: '',
  5719. beginDate: '',
  5720. endDate: '',
  5721. checkStatus: '未对账',
  5722. checkAmount: 0,
  5723. currency: '',
  5724. rate: '',
  5725. items: []
  5726. };
  5727. //保存来源单据相关信息
  5728. var sourceInfos = [];
  5729. //所允许的本次对账最大最小数量
  5730. $scope.data.maxThisCheckQty = 0;
  5731. $scope.data.minThisCheckQty = 0;
  5732. $scope.sameCust = true;
  5733. $scope.validQty = true;
  5734. $scope.loading = true;
  5735. angular.forEach($scope.data, function(check) {
  5736. //保存应收对账单明细行数据
  5737. $scope.item = {
  5738. inoutno: '',
  5739. inoutnodetno: '',
  5740. orderCode: '',
  5741. orderClass: '',
  5742. orderDetno: '',
  5743. price: '',
  5744. checkQty: '',
  5745. amount: '',
  5746. sourceId:'',
  5747. sourceTable:'',
  5748. oldYCheckQty:'',
  5749. status: 0,
  5750. receiveCode:'',
  5751. receiveName:'',
  5752. prodCode:'',
  5753. prodTitle:'',
  5754. prodSpec:'',
  5755. taxrate: '',
  5756. sendcode: '',
  5757. whname: '',
  5758. };
  5759. //应收对账单明细行来源表信息
  5760. $scope.sourceInfo = {
  5761. sourceId: '',
  5762. sourceTable: '',
  5763. newYCheckQty: ''
  5764. };
  5765. //此次对账后新的已转数
  5766. $scope.newYCheckQty = 0;
  5767. if(check.$selected == true) {
  5768. $scope.apCheck.custName = check.custName;
  5769. $scope.apCheck.enUu = check.enUu;
  5770. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5771. $scope.apCheck.apDate = check.piDate;
  5772. $scope.apCheck.rate = check.rate;
  5773. //必须是同一家客户才能生成对账单,否则提示错误
  5774. if($scope.apCheck.custUu == ''){
  5775. $scope.apCheck.custUu = check.custUu;
  5776. }else if($scope.apCheck.custUu !== check.custUu){
  5777. $scope.sameCust = false;
  5778. $scope.loading = false;
  5779. toaster.pop('error', '请选择同一家客户');
  5780. }
  5781. //必须是相同币别才能生成对账单,否则提示错误
  5782. if($scope.apCheck.currency == ''){
  5783. $scope.apCheck.currency = check.currency;
  5784. }else if($scope.apCheck.currency !== check.currency){
  5785. $scope.sameCust = false;
  5786. $scope.loading = false;
  5787. toaster.pop('error', '请选择同一种币别');
  5788. }
  5789. //本次对账数量必须小于总对账数量
  5790. if(check.qty > 0){
  5791. $scope.data.maxThisCheckQty = check.qty;
  5792. $scope.data.minThisCheckQty = 0;
  5793. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  5794. $scope.validQty = false;
  5795. $scope.loading = false;
  5796. toaster.pop('error','本次对账数量,填写有误!');
  5797. }
  5798. }else if(check.qty < 0){
  5799. $scope.data.maxThisCheckQty = 0;
  5800. $scope.data.minThisCheckQty = check.qty;
  5801. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  5802. $scope.validQty = false;
  5803. $scope.loading = false;
  5804. toaster.pop('error','本次对账数量,填写有误!');
  5805. }
  5806. }
  5807. //获取最小时间作为对账区间的起始时间
  5808. if($scope.apCheck.beginDate == ''){
  5809. $scope.apCheck.beginDate = check.piDate;
  5810. }else{
  5811. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  5812. }
  5813. //获取最大时间作为对账区间的截止时间
  5814. if($scope.apCheck.endDate == ''){
  5815. $scope.apCheck.endDate = check.piDate;
  5816. }else{
  5817. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  5818. }
  5819. //应收对账单明细行数据
  5820. $scope.item.orderCode = check.orderCode;
  5821. $scope.item.orderClass = check.piClass;
  5822. $scope.item.orderDetno = check.orderDetno;
  5823. $scope.item.price = check.orderPrice;
  5824. $scope.item.checkQty = check.thisCheckQty;
  5825. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5826. $scope.item.sourceId = check.sourceId;
  5827. $scope.item.sourceTable = check.sourceTable;
  5828. $scope.item.oldYCheckQty = check.yCheckQty;
  5829. $scope.item.prodCode = check.prodCode;
  5830. $scope.item.prodTitle = check.prodTitle;
  5831. $scope.item.prodSpec = check.prodSpec;
  5832. $scope.item.inoutno = check.inOutNo;
  5833. $scope.item.inoutnodetno = check.detno;
  5834. $scope.item.taxrate = check.taxrate;
  5835. $scope.item.receiveCode = check.receiveCode;
  5836. $scope.item.receiveName = check.receiveName;
  5837. $scope.item.sendcode = check.sendcode;
  5838. $scope.item.whname = check.whname;
  5839. //来源表相关信息
  5840. $scope.sourceInfo.sourceId = check.sourceId;
  5841. $scope.sourceInfo.sourceTable = check.sourceTable;
  5842. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  5843. sourceInfos.push($scope.sourceInfo);
  5844. $scope.apCheck.items.push($scope.item);
  5845. $scope.haveSelected = true;
  5846. }
  5847. });
  5848. //保存生成的应收对账单
  5849. $scope.saveApCheck = function(){
  5850. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  5851. $scope.loading = false;
  5852. toaster.pop('success', '成功', '生成应收对账成功');
  5853. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  5854. }, function(response){
  5855. toaster.pop('error', '生成对账单失败', response.data);
  5856. })
  5857. };
  5858. //如果是同一家客户,生成对账单的同时,关闭模态框
  5859. if($scope.sameCust && $scope.validQty) {
  5860. $scope.saveApCheck();
  5861. }
  5862. }
  5863. }]);
  5864. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http){
  5865. BaseService.scrollBackToTop();
  5866. $scope.loading = true;
  5867. AccountEnterprise.get({}, function(data){
  5868. $scope.loading = false;
  5869. $scope.enterprise = data;
  5870. });
  5871. AccountEnterprise.growth({}, function(data){
  5872. if(data != null && data.length > 0) {
  5873. var growth = [], years = [];
  5874. angular.forEach(data, function(d){
  5875. var date = new Date(d.date), year = date.getFullYear();
  5876. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  5877. if(years.indexOf(year) == -1) {
  5878. years.push(year);
  5879. growth.push({year: year});
  5880. }
  5881. growth.push(d);
  5882. });
  5883. $scope.growth = growth;
  5884. }
  5885. });
  5886. // 更新企业信息
  5887. $scope.updateDetailInfo = function(){
  5888. $scope.loading = true;
  5889. AccountEnterprise.save($scope.enterprise, function(){
  5890. $scope.loading = false;
  5891. $scope.connectionEditing = false;
  5892. toaster.pop('success', '提示', '修改企业信息成功');
  5893. $state.reload();
  5894. }, function(response){
  5895. $scope.loading = false;
  5896. toaster.pop('error', '修改信息失败', response.data);
  5897. });
  5898. };
  5899. // 申请Saas
  5900. $scope.applySaas = function(){
  5901. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  5902. var modalInstance = $modal.open({
  5903. animation: true,
  5904. templateUrl: 'static/tpl/index/account/applySaas.html',
  5905. controller: 'ApplySaasCtrl',
  5906. resolve: {
  5907. enterprise: function(){return angular.copy($scope.enterprise);}
  5908. }
  5909. });
  5910. modalInstance.result.then(function(){
  5911. $state.reload();
  5912. }, function(){
  5913. });
  5914. } else {
  5915. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  5916. }
  5917. };
  5918. // 获取收货地址列表
  5919. ShipAddress.shipAddList({}, function(data) {
  5920. $scope.ships = data;
  5921. });
  5922. // 获取地址信息
  5923. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  5924. }).then(function(response) {
  5925. $scope.provinces = response.data;
  5926. });
  5927. // 新增收货地址保存
  5928. $scope.saveShipAddress = function(ship) {
  5929. ship.address = ship.province + ship.city + ship.district;
  5930. ShipAddress.saveAddress( {}, ship, function(data) {
  5931. if(data.success) {
  5932. ShipAddress.shipAddList({}, function(data) {
  5933. $scope.ships = data;
  5934. });
  5935. toaster.pop('success', '提示', data.success);
  5936. }
  5937. if(data.error) {
  5938. toaster.pop('error', '提示', data.error);
  5939. }
  5940. });
  5941. }
  5942. // 删除收货地址
  5943. $scope.removeShip = function(id, index) {
  5944. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  5945. $scope.ships.splice(index, 1);
  5946. toaster.pop('success', '提示', '收货地址删除成功');
  5947. }, function(response) {
  5948. toaster.pop('error', '提示', response.data);
  5949. });
  5950. };
  5951. // 编辑收货地址
  5952. $scope.editShip = function(ship){
  5953. var modalInstance = $modal.open({
  5954. animation: true,
  5955. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  5956. controller: 'ShipAddressCtrl',
  5957. resolve: {
  5958. ship: function(){return ship;}
  5959. }
  5960. });
  5961. modalInstance.result.then(function() {
  5962. ShipAddress.shipAddList({}, function(data) {
  5963. $scope.ships = data;
  5964. });
  5965. }, function(){
  5966. });
  5967. };
  5968. // 设置logo
  5969. $scope.showImageDialog = function(modal) {
  5970. require([ 'jquery-uploadify' ], function() {
  5971. $modal.open({
  5972. templateUrl : 'static/tpl/index/home/insert.html',
  5973. controller : 'ImageInsertCtrl',
  5974. backdrop : 'static'
  5975. }).result.then(function(image){
  5976. $scope.imageUrl = image.thumb;
  5977. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  5978. $scope.user = data;
  5979. }, function(response) {
  5980. toaster.pop('error', '设置图像失败,' + response.data);
  5981. });
  5982. });
  5983. });
  5984. }
  5985. }]);
  5986. // 编辑收货地址
  5987. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  5988. $scope.ship = ship;
  5989. // 获取地址信息
  5990. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  5991. }).then(function(response) {
  5992. $scope.provinces = response.data;
  5993. });
  5994. // 新增收货地址保存
  5995. $scope.saveShipAddress = function(ship) {
  5996. ship.address = ship.province + ship.city + ship.district;
  5997. ShipAddress.saveAddress( {}, ship, function(data) {
  5998. if(data.success) {
  5999. toaster.pop('success', '提示', data.success);
  6000. $modalInstance.close();
  6001. }
  6002. if(data.error) {
  6003. toaster.pop('error', '提示', data.error);
  6004. }
  6005. });
  6006. }
  6007. $scope.cancel = function() {
  6008. $modalInstance.dismiss();
  6009. }
  6010. }]);
  6011. // 申请Saas Controller
  6012. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  6013. $scope.enterprise = enterprise;
  6014. $scope.checking = false;
  6015. $scope.$watch('enterprise.enSaasUrl', function(){
  6016. if($scope.enterprise.enSaasUrl) {
  6017. $http.get('signup/saasUrlEnable', {
  6018. params: {
  6019. enSaasUrl: $scope.enterprise.enSaasUrl
  6020. }
  6021. }).success(function(data){
  6022. if(data && data == 'true') {
  6023. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  6024. } else {
  6025. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6026. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  6027. }
  6028. }).error(function(){
  6029. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6030. $scope.enSaasUrlErrorInfo = '验证出错';
  6031. });
  6032. } else {
  6033. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6034. }
  6035. });
  6036. var setSaasUrl = function(url) {
  6037. var index = url.indexOf('www.');
  6038. if(index != -1) {//包含www.
  6039. var substr = url.substring(index+4, url.length);
  6040. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  6041. } else {
  6042. $scope.enterprise.enSaasUrl = getHost(url);
  6043. }
  6044. };
  6045. // 解析获取网址的一级域名
  6046. var getHost = function(host){
  6047. var newhost;
  6048. var domain;
  6049. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  6050. for(var k in ArrDomain){
  6051. var re = eval('/\\' + ArrDomain[k] + '$/g');
  6052. newhost = host.replace(re, '');
  6053. if(newhost != host){
  6054. domain = ArrDomain[k];
  6055. break;
  6056. }
  6057. }
  6058. var hostar = newhost.split('.');
  6059. var s = hostar[hostar.length-1];
  6060. return s;
  6061. };
  6062. // 设置优企云服域名为官网网址一级域名
  6063. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  6064. $scope.apply = function(){
  6065. $scope.loading = true;
  6066. AccountEnterprise.applySaas({
  6067. enUU: $scope.enterprise.uu,
  6068. enSaasUrl: $scope.enterprise.enSaasUrl,
  6069. enAdminPassword: $scope.enterprise.enAdminPassword
  6070. }, {}, function(){
  6071. $scope.loading = false;
  6072. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  6073. $modalInstance.close();
  6074. }, function(response){
  6075. $scope.loading = false;
  6076. toaster.pop('error', '申请失败', response.data);
  6077. });
  6078. };
  6079. $scope.cancel = function () {
  6080. $modalInstance.dismiss();
  6081. };
  6082. }]);
  6083. 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){
  6084. BaseService.scrollBackToTop();
  6085. $scope.editing = false;
  6086. $scope.loading = true;
  6087. $scope.enterprise = null;
  6088. AccountUser.findDistribute({},function(data) {
  6089. $scope.distributes = data;
  6090. },function(response) {
  6091. toaster.pop('error', '系统错误', response.data);
  6092. })
  6093. AuthenticationService.getAuthentication().success(function(data) {
  6094. $scope.loading = false;
  6095. $scope.user = data;
  6096. });
  6097. var users = [];
  6098. $scope.tableParams = new ngTableParams({
  6099. page : 1,
  6100. count : 5,
  6101. sorting: {
  6102. userName: 'asc'
  6103. }
  6104. }, {
  6105. total : 0,
  6106. counts: [15, 25, 50, 100],
  6107. getData : function($defer, params) {
  6108. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  6109. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  6110. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  6111. angular.forEach($scope.users,function(user){
  6112. AccountEnterprise.get({}, function(data){
  6113. $scope.loading = false;
  6114. $scope.enterprise = data;
  6115. });
  6116. });
  6117. params.total(orderedData.length);
  6118. $defer.resolve($scope.users);
  6119. }
  6120. });
  6121. var loadUsers = function() {
  6122. AccountUser.query({}, function(data){
  6123. users = data;
  6124. $scope.tableParams.reload();
  6125. $scope.loading = false;
  6126. });
  6127. };
  6128. loadUsers();
  6129. $scope.saveUser = function(){
  6130. $scope.loading = true;
  6131. AccountUser.update({}, $scope.user, function(data){
  6132. $scope.loading = false;
  6133. toaster.pop('success', '提示', '修改用户信息成功');
  6134. AuthenticationService.getAuthentication().success(function(data) {
  6135. $scope.user = data;
  6136. });
  6137. loadUsers();
  6138. $scope.editing = false;
  6139. }, function(reponse){
  6140. $scope.loading = false;
  6141. toaster.pop('error', '失败', reponse.data);
  6142. });
  6143. };
  6144. $scope.updatePassword = function(){
  6145. var modalInstance = $modal.open({
  6146. animation: true,
  6147. templateUrl: 'updatePassword.html',
  6148. controller: 'PasswordCtrl',
  6149. resolve: {
  6150. user: function(){return $scope.user;}
  6151. }
  6152. });
  6153. modalInstance.result.then(function(){
  6154. }, function(){
  6155. });
  6156. };
  6157. $scope.newUser = {};
  6158. //弹出添加用户模态框
  6159. $scope.addExistUser = function(){
  6160. var modalInstance = $modal.open({
  6161. animation :true,
  6162. templateUrl : 'static/tpl/index/account/addExistUser.html',
  6163. controller : 'AddExistUserCtrl'
  6164. });
  6165. modalInstance.result.then(function(){
  6166. $scope.userTelSuccess = false;
  6167. $scope.userTelError = false;
  6168. }, function(){
  6169. });
  6170. };
  6171. /**
  6172. * 添加未注册用户
  6173. */
  6174. $scope.addUser = function() {
  6175. $scope.adding = true;
  6176. AccountUser.save({}, $scope.newUser, function(){
  6177. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  6178. $scope.newUser = {userSex: 'M'};
  6179. loadUsers();
  6180. $scope.adding = false;
  6181. $scope.newUserForm.newUserTel.$setValidity('available', false);
  6182. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  6183. $scope.userTelSuccess = false;
  6184. $scope.userTelError = false;
  6185. $scope.userEmailSuccess = false;
  6186. $scope.userEmailError = false;
  6187. }, function(response){
  6188. toaster.pop('error', '错误', response.data);
  6189. });
  6190. };
  6191. /**
  6192. * 验证手机号是否可用
  6193. */
  6194. $scope.telValid = function(tel) {
  6195. if(tel) {
  6196. $http.get('account/user/telEnable', {
  6197. params: {
  6198. tel: tel
  6199. }
  6200. }).success(function(data){
  6201. data = eval(data);
  6202. if(data == true) {
  6203. $scope.newUserForm.newUserTel.$setValidity('available', true);
  6204. $scope.userTelSuccess = true;
  6205. $scope.userTelError = false;
  6206. }else{
  6207. $scope.newUserForm.newUserTel.$setValidity('available', false);
  6208. $scope.userTelError = true;
  6209. $scope.userTelSuccess = false;
  6210. if(tel.length == 11)
  6211. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  6212. }
  6213. }).error(function(){
  6214. $scope.userTelSuccess = false;
  6215. $scope.userTelError = true;
  6216. });
  6217. } else {
  6218. $scope.userTelSuccess = false;
  6219. $scope.userTelError = false;
  6220. }
  6221. };
  6222. /**
  6223. * 验证邮箱是否可用
  6224. */
  6225. $scope.emailValid = function(email) {
  6226. if(email) {
  6227. $http.get('account/user/emailEnable', {
  6228. params: {
  6229. email: email
  6230. }
  6231. }).success(function(data){
  6232. data = eval(data);
  6233. if(data == true) {
  6234. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  6235. $scope.userEmailSuccess = true;
  6236. $scope.userEmailError = false;
  6237. } else {
  6238. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  6239. $scope.userEmailError = true;
  6240. $scope.userEmailSuccess = false;
  6241. }
  6242. }).error(function(){
  6243. $scope.userEmailError = true;
  6244. $scope.userEmailSuccess = false;
  6245. });
  6246. } else {
  6247. $scope.userEmailError = false;
  6248. $scope.userEmailSuccess = false;
  6249. }
  6250. };
  6251. /**
  6252. * 删除用户
  6253. */
  6254. $scope.removeUser = function(user) {
  6255. new ngAlert({
  6256. title: '提示',
  6257. content: '确定删除用户(' + user.userName + ')吗?'
  6258. }, function(){
  6259. AccountUser.remove({uu: user.userUU}, function(){
  6260. toaster.pop('success', '提示', '用户删除成功。');
  6261. loadUsers();
  6262. }, function(response){
  6263. toaster.pop('error', '删除失败', response.data);
  6264. });
  6265. });
  6266. };
  6267. // 编辑用户的角色
  6268. $scope.editUserRole = function(user) {
  6269. var modalInstance = $modal.open({
  6270. animation: true,
  6271. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  6272. controller: 'UserRoleCtrl',
  6273. resolve: {
  6274. user: function() {
  6275. return user;
  6276. }
  6277. }
  6278. });
  6279. modalInstance.result.then(function(changed, checked){
  6280. if(changed) {
  6281. if(checked)
  6282. $scope.newUser.roles = checked;
  6283. else
  6284. loadUsers();
  6285. }
  6286. });
  6287. };
  6288. // 为用户分配角色(删除企业)
  6289. $scope.removeVendor = function(user) {
  6290. var resultRole = true;
  6291. angular.forEach(user.roles,function(role){
  6292. if(role.issys == 1) {
  6293. toaster.pop('error', '提示', '管理员无需分配客户');
  6294. resultRole = false;
  6295. return;
  6296. }
  6297. })
  6298. if(resultRole) {
  6299. var modalInstance = $modal.open({
  6300. animation: true,
  6301. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  6302. controller: 'RemoveVendorCtrl',
  6303. resolve: {
  6304. user: function() {
  6305. return user;
  6306. }
  6307. }
  6308. });
  6309. }
  6310. }
  6311. // 为用户分配角色(添加企业)
  6312. $scope.addVendor = function(user,isIssy) {
  6313. if(!isIssy) {
  6314. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  6315. return;
  6316. }
  6317. var resultRole = true;
  6318. angular.forEach(user.roles,function(role){
  6319. if(role.issys == 1) {
  6320. toaster.pop('error', '提示', '管理员无需分配客户');
  6321. resultRole = false;
  6322. return;
  6323. }
  6324. })
  6325. if(resultRole) {
  6326. var modalInstance = $modal.open({
  6327. animation: true,
  6328. templateUrl: 'static/tpl/index/account/add_vendor.html',
  6329. controller: 'AddVendorCtrl',
  6330. resolve: {
  6331. user: function() {
  6332. return user;
  6333. }
  6334. }
  6335. });
  6336. modalInstance.result.then(function(changed, checked){
  6337. if(changed) {
  6338. if(checked)
  6339. $scope.newUser.roles = checked;
  6340. else
  6341. loadUsers();
  6342. }
  6343. });
  6344. }
  6345. };
  6346. }]);
  6347. // 登录手机号码验证
  6348. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  6349. $scope.user = user;
  6350. $scope.cancel = function(){
  6351. $modalInstance.close();
  6352. }
  6353. /*$scope.loading = false;
  6354. $scope.btnState = false;
  6355. $scope.clicks = 0;
  6356. var storage = window.localStorage;
  6357. //手机验证码定时器
  6358. $scope.msgInfoError = false;
  6359. var setBtnTimeDown = function(value) {
  6360. if(value > 0) {
  6361. $scope.btnState = true;
  6362. $timeout(function() {
  6363. $scope.$apply(function(){
  6364. storage.setItem("btnTimes", $scope.btnTimes);
  6365. $scope.btnTimes --;
  6366. value --;
  6367. setBtnTimeDown (value);
  6368. });
  6369. }, 500);
  6370. }else{
  6371. $scope.btnState = false;
  6372. }
  6373. };
  6374. if(storage.btnTimes > 1){
  6375. $scope.btnTimes = storage.btnTimes;
  6376. setBtnTimeDown(storage.btnTimes)
  6377. }else{
  6378. storage.removeItem("btnTimes");
  6379. }
  6380. $scope.updateTel = function(phoneCode, userTel, uu){
  6381. $scope.loading = true;
  6382. $scope.msgInfoError = false;
  6383. $scope.result = false;
  6384. //更新联系方式
  6385. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  6386. $scope.loading = false;
  6387. $scope.msgInfoError2 = false;
  6388. $scope.result = true;
  6389. AuthenticationService.getAuthentication().success(function(data) {
  6390. $timeout(function(){
  6391. $modalInstance.dismiss();
  6392. window.location.reload();
  6393. }, 1000);
  6394. }).error(function(response) {
  6395. });
  6396. }, function(response){
  6397. $scope.loading = false;
  6398. $scope.msgInfoError2 = response;
  6399. });
  6400. };
  6401. //获取验证码
  6402. $scope.getPhoneCode = function(userTel){
  6403. var timeInfo = 10;
  6404. $scope.clicks ++;
  6405. $scope.timeInfo = timeInfo;
  6406. if($scope.clicks >= 5){
  6407. $scope.errorloading = true;
  6408. $scope.msgInfoSuccess = false;
  6409. $scope.msgInfoError = false;
  6410. }else{
  6411. $scope.loading = true;
  6412. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  6413. $scope.loading = false;
  6414. $scope.msgInfoSuccess = data.success;
  6415. $scope.sendMsg = data;
  6416. $scope.btnTimes = 60;
  6417. setBtnTimeDown($scope.btnTimes);
  6418. $scope.msgInfoError = false;
  6419. },function(response){
  6420. console.log(response);
  6421. $scope.loading = false;
  6422. $scope.msgInfoError = false;
  6423. $scope.sendCheckMsg = false;
  6424. $scope.msgInfoSuccess = true;
  6425. });
  6426. }
  6427. }; */
  6428. }]);
  6429. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6430. $scope.checkboxes = {
  6431. checked : false
  6432. };
  6433. $scope.loading = true;
  6434. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  6435. $scope.enters = data;
  6436. $scope.loading = false;
  6437. angular.forEach($scope.enters, function(item) {
  6438. item:{
  6439. $selected:true;
  6440. }
  6441. });
  6442. })
  6443. // 点击勾选全部的复选框
  6444. $scope.checkAll = function() {
  6445. angular.forEach($scope.enters, function(item) {
  6446. item.$selected = $scope.checkboxes.checked;
  6447. });
  6448. };
  6449. // 点击其中一个明细的复选框
  6450. $scope.checkOne = function(vendor){
  6451. var result = true;
  6452. angular.forEach($scope.enters, function(item) {
  6453. if(item.$selected != true){
  6454. result = false;
  6455. return;
  6456. }
  6457. });
  6458. $scope.checkboxes.checked = result;
  6459. };
  6460. $scope.close = function(save) {
  6461. var chooseResult = [];
  6462. if(save) {
  6463. if(user.userUU) {
  6464. angular.forEach($scope.enters, function(item, i) {
  6465. if(item.$selected) {
  6466. chooseResult.push(item.id);
  6467. }
  6468. });
  6469. if(chooseResult.length > 0) {
  6470. $scope.loading = true;
  6471. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  6472. $scope.loading = false;
  6473. toaster.pop('success', '提示', '删除成功');
  6474. $modalInstance.close(false);
  6475. }, function(response){
  6476. $scope.loading = false;
  6477. toaster.pop('error', '删除失败', response.data);
  6478. $modalInstance.close(false);
  6479. })
  6480. } else {
  6481. toaster.pop('error', '删除失败', "您未勾选任何记录");
  6482. }
  6483. } else {
  6484. $modalInstance.close(true, $scope.checkboxes.checked);
  6485. }
  6486. } else {
  6487. $modalInstance.close(false);
  6488. }
  6489. };
  6490. }]);
  6491. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6492. $scope.checkboxes = {
  6493. checked : false
  6494. };
  6495. $scope.loading = true;
  6496. AccountUser.findVendor({uu : user.userUU},function(data) {
  6497. $scope.enters = data;
  6498. $scope.loading = false;
  6499. // angular.forEach($scope.enters, function(item) {
  6500. // if(item.distribute) {
  6501. // item:{
  6502. // $selected:false;
  6503. // }
  6504. // } else {
  6505. // item:{
  6506. // $selected:true;
  6507. // }
  6508. // }
  6509. // });
  6510. })
  6511. // 点击勾选全部的复选框
  6512. $scope.checkAll = function() {
  6513. angular.forEach($scope.enters, function(item) {
  6514. item.distribute = $scope.checkboxes.checked;
  6515. });
  6516. };
  6517. // 点击其中一个明细的复选框
  6518. $scope.checkOne = function(vendor){
  6519. var result = true;
  6520. angular.forEach($scope.enters, function(item) {
  6521. if(item.distribute != true){
  6522. result = false;
  6523. return;
  6524. }
  6525. });
  6526. $scope.checkboxes.checked = result;
  6527. };
  6528. $scope.close = function(save) {
  6529. var chooseResult = [];
  6530. if(save) {
  6531. if(user.userUU) {
  6532. angular.forEach($scope.enters, function(item, i) {
  6533. // if(item.distribute) {
  6534. chooseResult.push(item);
  6535. // }
  6536. });
  6537. if(chooseResult.length > 0) {
  6538. $scope.loading = true;
  6539. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  6540. $scope.loading = false;
  6541. toaster.pop('success', '提示', '保存成功');
  6542. $modalInstance.close(false);
  6543. }, function(response){
  6544. $scope.loading = false;
  6545. toaster.pop('error', '保存失败', response.data);
  6546. $modalInstance.close(false);
  6547. })
  6548. } else {
  6549. toaster.pop('error', '保存失败', "您未勾选任何记录");
  6550. }
  6551. } else {
  6552. $modalInstance.close(true, $scope.checkboxes.checked);
  6553. }
  6554. } else {
  6555. $modalInstance.close(false);
  6556. }
  6557. };
  6558. }]);
  6559. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  6560. $scope.checked = [];
  6561. $scope.master = [];
  6562. AccountRole.query({}, function(data){
  6563. if(user && data) {
  6564. var rs = [], checked = [];
  6565. angular.forEach(user.roles, function(r){
  6566. rs.push(r.id);
  6567. });
  6568. angular.forEach(data, function(d){
  6569. if(rs.indexOf(d.id) > -1) {
  6570. d.$checked = true;
  6571. checked.push(d);
  6572. }
  6573. });
  6574. }
  6575. $scope.roles = data;
  6576. $scope.checked = checked;
  6577. $scope.master = angular.copy($scope.checked);
  6578. });
  6579. $scope.select = function(role) {
  6580. role.$checked = !role.$checked;
  6581. if(role.$checked) {
  6582. $scope.checked.push(role);
  6583. } else {
  6584. angular.forEach($scope.checked, function(c, i){
  6585. if(c.id == role.id)
  6586. $scope.checked.splice(i, 1);
  6587. });
  6588. }
  6589. };
  6590. $scope.isChanged = function() {
  6591. return !angular.equals($scope.master, $scope.checked);
  6592. };
  6593. $scope.close = function(save) {
  6594. if(save) {
  6595. if(user.userUU) {
  6596. user.roles = $scope.checked;
  6597. AccountUser.update({}, user, function(){
  6598. toaster.pop('success', '提示', '保存成功');
  6599. $modalInstance.close(true);
  6600. }, function(response){
  6601. toaster.pop('error', '保存失败', response.data);
  6602. });
  6603. } else {
  6604. $modalInstance.close(true, $scope.checked);
  6605. }
  6606. } else {
  6607. $modalInstance.close(false);
  6608. }
  6609. };
  6610. }]);
  6611. // 修改密码Controller
  6612. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6613. $scope.user = user;
  6614. $scope.checking = false;
  6615. //输入原密码后验证原密码是否正确
  6616. $scope.checkPassword = function(password) {
  6617. $scope.checking = true;
  6618. $scope.checkSuccess = false;
  6619. $scope.checkFailed = false;
  6620. AccountUser.checkPassword({password: password}, function(data){
  6621. $scope.checkSuccess = true;
  6622. $scope.checking = false;
  6623. $scope.checkFailed = false;
  6624. }, function(response){
  6625. $scope.checkFailed = true;
  6626. $scope.checking = false;
  6627. $scope.checkSuccess = false;
  6628. });
  6629. };
  6630. //修改密码
  6631. $scope.ok = function () {
  6632. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  6633. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  6634. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  6635. $scope.user.password = null;
  6636. $scope.user.newPassword = null;
  6637. $scope.user.newPassword1 = null;
  6638. $scope.checking = false;
  6639. $scope.checkSuccess = false;
  6640. $scope.checkFailed = false;
  6641. }, function(response){
  6642. toaster.pop('error', '错误', response.data);
  6643. });
  6644. } else {
  6645. toaster.pop('error', '错误', '重复密码不一致');
  6646. }
  6647. };
  6648. $scope.cancel = function () {
  6649. $modalInstance.dismiss();
  6650. };
  6651. }]);
  6652. /*
  6653. * 绑定用户到企业
  6654. */
  6655. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout){
  6656. $scope.searching = false;
  6657. //根据输入的内容查找用户
  6658. $scope.searchUser = function(keyWord) {
  6659. $scope.searching = true;
  6660. $scope.searchSuccess = false;
  6661. $scope.searchFailed = false;
  6662. $scope.illegalError = false;
  6663. $scope.reBindError = false;
  6664. $scope.bindSuccess = false;
  6665. $scope.okDisabled = false;
  6666. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  6667. $scope.searchSuccess = true;
  6668. $scope.searchFailed = false;
  6669. $scope.user = data; //查询到的用户
  6670. }, function(response){
  6671. $scope.searchSuccess = false;
  6672. $scope.searchFailed = true;
  6673. });
  6674. };
  6675. //确认绑定
  6676. $scope.ok = function (keyWord) {
  6677. AuthenticationService.getAuthentication().success(function(data) {
  6678. $scope.currentUser = data; //当前登录的用户(管理员)
  6679. //不可自己绑定自己
  6680. if($scope.currentUser.userUU == $scope.user.userUU){
  6681. $scope.illegalError = true;
  6682. $scope.okDisabled = true;
  6683. return false;
  6684. }
  6685. //用户未绑定到任何企业时
  6686. if(!$scope.user.enterprises){
  6687. //正常绑定
  6688. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  6689. $scope.bindSuccess = true; //绑定成功
  6690. $scope.okDisabled = true;
  6691. }, function(response){
  6692. });
  6693. return true;
  6694. }
  6695. //用户已绑定到某些企业时
  6696. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  6697. if($scope.currentUser.enterprises[i].current){
  6698. for(var j = 0; j < $scope.user.enterprises.length; j++){
  6699. //该用户已绑定到当前企业,不可重复绑定
  6700. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  6701. $scope.reBindError = true;
  6702. $scope.okDisabled = true;
  6703. return false;
  6704. }
  6705. }
  6706. //该用户未绑定到当前企业,可以进行绑定
  6707. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  6708. $scope.bindSuccess = true; //绑定成功
  6709. $scope.okDisabled = true;
  6710. }, function(response){
  6711. console.log("绑定失败!");
  6712. });
  6713. }
  6714. }
  6715. });
  6716. $timeout(function() {
  6717. $modalInstance.close(true);
  6718. }, 500);
  6719. };
  6720. $scope.cancel = function () {
  6721. $modalInstance.dismiss();
  6722. };
  6723. }]);
  6724. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  6725. $scope.erpParams = new ngTableParams({
  6726. page : 1,
  6727. count : 5,
  6728. sorting: {
  6729. time: 'desc'
  6730. }
  6731. }, {
  6732. total : 0,
  6733. counts: [5, 10, 25, 50],
  6734. getData : function($defer, params) {
  6735. $scope.loading = true;
  6736. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  6737. $scope.loading = false;
  6738. if(page) {
  6739. params.total(page.totalElements);
  6740. $defer.resolve(page.content);
  6741. }
  6742. }, function(response){
  6743. $scope.loading = false;
  6744. toaster.pop('error', '数据加载失败', response.data);
  6745. });
  6746. }
  6747. });
  6748. $scope.usageParams = new ngTableParams({
  6749. page : 1,
  6750. count : 5,
  6751. sorting: {
  6752. time: 'desc'
  6753. }
  6754. }, {
  6755. total : 0,
  6756. counts: [5, 10, 25, 50],
  6757. getData : function($defer, params) {
  6758. $scope.loading = true;
  6759. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  6760. $scope.loading = false;
  6761. if(page) {
  6762. params.total(page.totalElements);
  6763. $defer.resolve(page.content);
  6764. }
  6765. }, function(response){
  6766. $scope.loading = false;
  6767. toaster.pop('error', '数据加载失败', response.data);
  6768. });
  6769. }
  6770. });
  6771. }]);
  6772. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  6773. AccountResource.query({}, function(data){
  6774. if(data && data.length > 0) {
  6775. data[0].$open = true;
  6776. }
  6777. $scope.resources = data;
  6778. });
  6779. }]);
  6780. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  6781. $scope.roles = {};
  6782. var getData = function() {
  6783. AccountRole.query({}, function(data){
  6784. var defaults = [], custom = [];
  6785. angular.forEach(data, function(d){
  6786. if(d.isdefault == 1)
  6787. defaults.push(d);
  6788. else
  6789. custom.push(d);
  6790. });
  6791. $scope.roles = {defaults: defaults, custom: custom};
  6792. });
  6793. };
  6794. getData();
  6795. $scope.editRole = function(role){
  6796. var modalInstance = $modal.open({
  6797. animation: true,
  6798. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  6799. controller: 'RoleEditCtrl',
  6800. resolve: {
  6801. role: function() {
  6802. return role;
  6803. }
  6804. }
  6805. });
  6806. modalInstance.result.then(function(added){
  6807. added && (getData());
  6808. });
  6809. };
  6810. }]);
  6811. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  6812. BaseService.scrollBackToTop();
  6813. $scope.role = role;
  6814. $scope.master = angular.copy($scope.role);
  6815. var isNew = role == null;
  6816. $scope.cancel = function() {
  6817. $modalInstance.close(false);
  6818. };
  6819. AccountResource.query({}, function(data){
  6820. if(data && data.length > 0) {
  6821. if(role && role.resourceItems) {
  6822. var rs = [];// 已分配的资源的id
  6823. angular.forEach(role.resourceItems, function(item){
  6824. rs.push(item.id);
  6825. });
  6826. angular.forEach(data, function(resource){
  6827. var c = 0;
  6828. angular.forEach(resource.items, function(item){
  6829. if(rs.indexOf(item.id) > -1) {
  6830. item.$checked = true;
  6831. c += 1;
  6832. }
  6833. });
  6834. resource.$checked = c == resource.items.length;
  6835. });
  6836. }
  6837. $scope.resourceItems = data[0].items;
  6838. data[0].$active = true;
  6839. }
  6840. $scope.resources = data;
  6841. $timeout(function(){
  6842. angular.forEach($scope.resources, function(resource){
  6843. var c = 0;
  6844. angular.forEach(resource.items, function(item){
  6845. item.$checked && (c+=1);
  6846. });
  6847. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  6848. });
  6849. }, 100);
  6850. });
  6851. $scope.onItemClick = function(resource) {
  6852. $scope.resourceItems = resource.items;
  6853. angular.forEach($scope.resources, function(r){
  6854. r.$active = false;
  6855. });
  6856. resource.$active = true;
  6857. };
  6858. var getChecked = function() {
  6859. var items = [];
  6860. angular.forEach($scope.resources, function(resource){
  6861. angular.forEach(resource.items, function(item){
  6862. item.$checked && (items.push(item));
  6863. });
  6864. });
  6865. $scope.role.resourceItems = items;
  6866. };
  6867. $scope.onResourceChange = function(resource) {
  6868. angular.forEach(resource.items, function(item){
  6869. item.$checked = resource.$checked;
  6870. });
  6871. getChecked();
  6872. };
  6873. $scope.onItemChange = function() {
  6874. angular.forEach($scope.resources, function(resource){
  6875. if(resource.$active) {
  6876. var c = 0;
  6877. angular.forEach(resource.items, function(item){
  6878. item.$checked && (c+=1);
  6879. });
  6880. resource.$checked = (c == resource.items.length);
  6881. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  6882. }
  6883. });
  6884. getChecked();
  6885. };
  6886. $scope.isChanged = function(formData) {
  6887. if(!$scope.master)
  6888. return true;
  6889. return !angular.equals(formData, $scope.master);
  6890. };
  6891. $scope.save = function() {
  6892. $scope.master = angular.copy($scope.role);
  6893. AccountRole.save($scope.master, function(){
  6894. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  6895. $modalInstance.close(true);
  6896. }, function(response){
  6897. toaster.pop('error', '错误', response.data);
  6898. });
  6899. };
  6900. $scope.del = function() {
  6901. new ngAlert({
  6902. title: '提示',
  6903. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  6904. }, function(){
  6905. AccountRole.remove({id: role.id}, function(){
  6906. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  6907. $modalInstance.close(true);
  6908. }, function(response){
  6909. toaster.pop('error', '错误', response.data);
  6910. });
  6911. })
  6912. };
  6913. }]);
  6914. /**
  6915. * 委外订单
  6916. */
  6917. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  6918. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  6919. BaseService.scrollBackToTop();
  6920. $scope.active = 'todo';
  6921. $scope.dateZoneText = '不限';
  6922. $scope.condition = {dateZone: -1};
  6923. $scope.changeDateZone = function(zone) {
  6924. $scope.condition.dateZone = zone;
  6925. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6926. $scope.condition.$dateZoneOpen = false;
  6927. getDateCondition(zone, $scope.condition);
  6928. $scope.tableParams.reload();
  6929. };
  6930. $scope.setActive = function(state) {
  6931. if($scope.active != state) {
  6932. $scope.active = state;
  6933. if($scope.tableParams.page() == 1)
  6934. $scope.tableParams.reload();
  6935. else
  6936. $scope.tableParams.page(1);
  6937. }
  6938. };
  6939. var getService = function() {
  6940. return MakeOrder;
  6941. };
  6942. $scope.tableParams = new ngTableParams({
  6943. page : 1,
  6944. count : 5,
  6945. sorting: {
  6946. date: 'desc'
  6947. }
  6948. }, {
  6949. total : 0,
  6950. counts: [5, 10, 25, 50],
  6951. getData : function($defer, params) {
  6952. $scope.loading = true;
  6953. var pageParams = params.url();
  6954. pageParams.searchFilter = {};
  6955. pageParams.searchFilter.keyword = $scope.keyword;
  6956. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6957. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6958. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6959. $scope.loading = false;
  6960. if(page) {
  6961. params.total(page.totalElement);
  6962. $defer.resolve(page.content);
  6963. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6964. }
  6965. }, function(response){
  6966. $scope.loading = false;
  6967. toaster.pop('error', '数据加载失败', response.data);
  6968. });
  6969. }
  6970. });
  6971. $scope.getOrderTotal = function(items) {
  6972. var sum = 0;
  6973. angular.forEach(items, function(item){
  6974. sum += item.qty * item.price;
  6975. });
  6976. return sum;
  6977. };
  6978. $scope.openDatePicker = function($event, item, openParam) {
  6979. $event.preventDefault();
  6980. $event.stopPropagation();
  6981. item[openParam] = !item[openParam];
  6982. };
  6983. $scope.parseDate = function(dateStr) {
  6984. if(dateStr)
  6985. return Date.parse(dateStr, 'yyyy-MM-dd');
  6986. return new Date();
  6987. };
  6988. // 打开回复
  6989. $scope.openReply = function(order) {
  6990. if(!order.reply) {
  6991. order.reply = {
  6992. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6993. delivery: order.delivery
  6994. }
  6995. }
  6996. order.$editing = true;
  6997. };
  6998. // 关闭回复
  6999. $scope.closeReply = function(order) {
  7000. order.$editing = false;
  7001. }
  7002. // 搜索框回车
  7003. $scope.onSearch = function() {
  7004. $scope.tableParams.page(1);
  7005. $scope.tableParams.reload();
  7006. };
  7007. // 选择查找日期
  7008. $scope.onDateCondition = function(){
  7009. $scope.tableParams.page(1);
  7010. $scope.tableParams.reload();
  7011. };
  7012. // 点击回复
  7013. $scope.onReplyClick = function(order, inverse) {
  7014. if(order.reply) {
  7015. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7016. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7017. return;
  7018. }
  7019. var reply = angular.copy(order.reply);
  7020. if(reply.delivery) {
  7021. if(typeof reply.delivery == 'object')
  7022. reply.delivery = reply.delivery.getTime();
  7023. } else {
  7024. reply.delivery = order.delivery;
  7025. }
  7026. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7027. $scope.loading = true;
  7028. MakeOrder.reply({orderId: order.id}, reply, function(){
  7029. $scope.loading = false;
  7030. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7031. $scope.tableParams.reload();
  7032. }, function(response){
  7033. $scope.loading = false;
  7034. toaster.pop('error', '回复失败', response.data);
  7035. });
  7036. }
  7037. };
  7038. //委外加工单
  7039. $scope.print = function(order) {
  7040. MakeOrder.printCount({id: order.id},{});//增加打印此次
  7041. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  7042. };
  7043. // 获取回复记录
  7044. $scope.getReply = function(order) {
  7045. if(!order.replies) {
  7046. MakeOrder.getReply({orderId: order.id}, function(replies){
  7047. order.replies = replies;
  7048. });
  7049. }
  7050. };
  7051. }]);
  7052. /**
  7053. * 委外加工单详细
  7054. */
  7055. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  7056. BaseService.scrollBackToTop();
  7057. var loadData = function() {
  7058. MakeOrder.get({id: $stateParams.id}, function(data){
  7059. $scope.order = data;
  7060. var sum = $scope.order.qty * $scope.order.price;
  7061. $scope.order.total = sum;
  7062. $scope.loading = false;
  7063. });
  7064. };
  7065. loadData();
  7066. // 获取回复记录
  7067. $scope.getReply = function(item) {
  7068. if(!item.replies) {
  7069. MakeOrder.getReply({orderId: item.id}, function(replies){
  7070. item.replies = replies;
  7071. });
  7072. }
  7073. };
  7074. $scope.openDatePicker = function($event, item, openParam) {
  7075. $event.preventDefault();
  7076. $event.stopPropagation();
  7077. item[openParam] = !item[openParam];
  7078. };
  7079. // 点击回复
  7080. $scope.onReplyClick = function(order, inverse) {
  7081. if(order.reply) {
  7082. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7083. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7084. return;
  7085. }
  7086. var reply = angular.copy(order.reply);
  7087. if(reply.delivery) {
  7088. if(typeof reply.delivery == 'object')
  7089. reply.delivery = reply.delivery.getTime();
  7090. } else {
  7091. reply.delivery = order.delivery;
  7092. }
  7093. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7094. $scope.loading = true;
  7095. MakeOrder.reply({orderId: order.id}, reply, function(){
  7096. $scope.loading = false;
  7097. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7098. loadData();
  7099. }, function(response){
  7100. $scope.loading = false;
  7101. toaster.pop('error', '回复失败', response.data);
  7102. });
  7103. }
  7104. };
  7105. // 打开回复
  7106. $scope.openReply = function(order) {
  7107. if(!order.reply) {
  7108. order.reply = {
  7109. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7110. delivery: order.delivery
  7111. }
  7112. }
  7113. order.$editing = true;
  7114. };
  7115. // 关闭回复
  7116. $scope.closeReply = function(order) {
  7117. order.$editing = false;
  7118. }
  7119. // 委外订单
  7120. $scope.print = function(order) {
  7121. MakeOrder.printCount({id: order.id},{});//增加打印此次
  7122. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  7123. };
  7124. }]);
  7125. /**
  7126. * 客户委外验收
  7127. */
  7128. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  7129. BaseService.scrollBackToTop();
  7130. $scope.active = 'all';
  7131. $scope.agreedText = '全部';
  7132. $scope.dateZoneText = '一个月内';
  7133. $scope.condition = {dateZone: 1};
  7134. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7135. $scope.changeAgreed = function(agreed) {
  7136. $scope.condition.agreed = agreed;
  7137. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7138. $scope.condition.$agreedOpen = false;
  7139. };
  7140. $scope.changeDateZone = function(zone) {
  7141. $scope.condition.dateZone = zone;
  7142. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7143. $scope.condition.$dateZoneOpen = false;
  7144. getDateCondition(zone, $scope.condition);
  7145. $scope.tableParams.reload();
  7146. };
  7147. $scope.setActive = function(state) {
  7148. if($scope.active != state) {
  7149. $scope.active = state;
  7150. if($scope.tableParams.page() == 1)
  7151. $scope.tableParams.reload();
  7152. else
  7153. $scope.tableParams.page(1);
  7154. }
  7155. };
  7156. var getService = function() {
  7157. return MakeAccept;
  7158. };
  7159. $scope.tableParams = new ngTableParams({
  7160. page : 1,
  7161. count : 5,
  7162. sorting: {
  7163. date: 'desc'
  7164. }
  7165. }, {
  7166. total : 0,
  7167. counts: [5, 10, 25, 50],
  7168. getData : function($defer, params) {
  7169. $scope.loading = true;
  7170. var pageParams = params.url();
  7171. pageParams.searchFilter = {};
  7172. pageParams.searchFilter.keyword = $scope.keyword;
  7173. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7174. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7175. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7176. $scope.loading = false;
  7177. if(page) {
  7178. params.total(page.totalElement);
  7179. $defer.resolve(page.content);
  7180. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7181. }
  7182. }, function(response){
  7183. $scope.loading = false;
  7184. toaster.pop('error', '数据加载失败', response.data);
  7185. });
  7186. }
  7187. });
  7188. $scope.openDatePicker = function($event, item, openParam) {
  7189. $event.preventDefault();
  7190. $event.stopPropagation();
  7191. item[openParam] = !item[openParam];
  7192. };
  7193. // 搜索框回车
  7194. $scope.onSearch = function() {
  7195. $scope.tableParams.page(1);
  7196. $scope.tableParams.reload();
  7197. };
  7198. // 选择查找日期
  7199. $scope.onDateCondition = function(){
  7200. $scope.tableParams.page(1);
  7201. $scope.tableParams.reload();
  7202. };
  7203. }]);
  7204. /**
  7205. * 客户委外验退
  7206. */
  7207. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  7208. BaseService.scrollBackToTop();
  7209. $scope.active = 'all';
  7210. $scope.agreedText = '全部';
  7211. $scope.dateZoneText = '一个月内';
  7212. $scope.condition = {dateZone: 1};
  7213. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7214. $scope.changeAgreed = function(agreed) {
  7215. $scope.condition.agreed = agreed;
  7216. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7217. $scope.condition.$agreedOpen = false;
  7218. };
  7219. $scope.changeDateZone = function(zone) {
  7220. $scope.condition.dateZone = zone;
  7221. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7222. $scope.condition.$dateZoneOpen = false;
  7223. getDateCondition(zone, $scope.condition);
  7224. $scope.tableParams.reload();
  7225. };
  7226. $scope.setActive = function(state) {
  7227. if($scope.active != state) {
  7228. $scope.active = state;
  7229. if($scope.tableParams.page() == 1)
  7230. $scope.tableParams.reload();
  7231. else
  7232. $scope.tableParams.page(1);
  7233. }
  7234. };
  7235. var getService = function() {
  7236. return MakeReturn;
  7237. };
  7238. $scope.tableParams = new ngTableParams({
  7239. page : 1,
  7240. count : 5,
  7241. sorting: {
  7242. date: 'desc'
  7243. }
  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.searchFilter = {};
  7251. pageParams.searchFilter.keyword = $scope.keyword;
  7252. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7253. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7254. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7255. $scope.loading = false;
  7256. if(page) {
  7257. params.total(page.totalElement);
  7258. $defer.resolve(page.content);
  7259. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7260. }
  7261. }, function(response){
  7262. $scope.loading = false;
  7263. toaster.pop('error', '数据加载失败', response.data);
  7264. });
  7265. }
  7266. });
  7267. $scope.openDatePicker = function($event, item, openParam) {
  7268. $event.preventDefault();
  7269. $event.stopPropagation();
  7270. item[openParam] = !item[openParam];
  7271. };
  7272. // 搜索框回车
  7273. $scope.onSearch = function() {
  7274. $scope.tableParams.page(1);
  7275. $scope.tableParams.reload();
  7276. };
  7277. // 选择查找日期
  7278. $scope.onDateCondition = function(){
  7279. $scope.tableParams.page(1);
  7280. $scope.tableParams.reload();
  7281. };
  7282. }]);
  7283. /**
  7284. * 委外加工变更
  7285. */
  7286. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  7287. BaseService.scrollBackToTop();
  7288. $scope.active = 'all';
  7289. $scope.agreedText = '全部';
  7290. $scope.dateZoneText = '一个月内';
  7291. $scope.condition = {dateZone: 1};
  7292. $scope.changeAgreed = function(agreed) {
  7293. $scope.condition.agreed = agreed;
  7294. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7295. $scope.condition.$agreedOpen = false;
  7296. };
  7297. $scope.changeDateZone = function(zone) {
  7298. $scope.condition.dateZone = zone;
  7299. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7300. $scope.condition.$dateZoneOpen = false;
  7301. getDateCondition(zone, $scope.condition);
  7302. $scope.tableParams.reload();
  7303. };
  7304. $scope.setActive = function(state) {
  7305. if($scope.active != state) {
  7306. $scope.active = state;
  7307. if($scope.tableParams.page() == 1)
  7308. $scope.tableParams.reload();
  7309. else
  7310. $scope.tableParams.page(1);
  7311. }
  7312. };
  7313. var getService = function() {
  7314. return MakeChange;
  7315. };
  7316. $scope.tableParams = new ngTableParams({
  7317. page : 1,
  7318. count : 5,
  7319. sorting: {
  7320. orderChangeDate: 'desc'
  7321. }
  7322. }, {
  7323. total : 0,
  7324. counts: [5, 10, 25, 50],
  7325. getData : function($defer, params) {
  7326. $scope.loading = true;
  7327. var pageParams = params.url();
  7328. pageParams.searchFilter = {};
  7329. pageParams.searchFilter.keyword = $scope.keyword;
  7330. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7331. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7332. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7333. $scope.loading = false;
  7334. if(page) {
  7335. params.total(page.totalElement);
  7336. $defer.resolve(page.content);
  7337. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7338. }
  7339. }, function(response){
  7340. $scope.loading = false;
  7341. toaster.pop('error', '数据加载失败', response.data);
  7342. });
  7343. }
  7344. });
  7345. $scope.openDatePicker = function($event, item, openParam) {
  7346. $event.preventDefault();
  7347. $event.stopPropagation();
  7348. item[openParam] = !item[openParam];
  7349. };
  7350. // 打开回复
  7351. $scope.openReply = function(change) {
  7352. change.$editing = true;
  7353. };
  7354. // 关闭回复
  7355. $scope.closeReply = function(change) {
  7356. change.$editing = false;
  7357. }
  7358. // 确定回复
  7359. $scope.onReplyClick = function(change) {
  7360. if(change.$agreed) {
  7361. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7362. $scope.loading = true;
  7363. MakeChange.reply({itemId: change.id}, reply, function(){
  7364. $scope.loading = false;
  7365. toaster.pop('info', '提示', '回复成功');
  7366. $scope.tableParams.reload();
  7367. }, function(response){
  7368. $scope.loading = false;
  7369. toaster.pop('error', '回复失败', response.data);
  7370. });
  7371. }
  7372. };
  7373. // 搜索框回车
  7374. $scope.onSearch = function() {
  7375. $scope.tableParams.page(1);
  7376. $scope.tableParams.reload();
  7377. };
  7378. // 选择查找日期
  7379. $scope.onDateCondition = function(){
  7380. $scope.tableParams.page(1);
  7381. $scope.tableParams.reload();
  7382. };
  7383. }]);
  7384. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  7385. BaseService.scrollBackToTop();
  7386. var loadData = function() {
  7387. MakeChange.get({id: $stateParams.id}, function(data){
  7388. $scope.change = data;
  7389. });
  7390. };
  7391. loadData();
  7392. $scope.openDatePicker = function($event, item, openParam) {
  7393. $event.preventDefault();
  7394. $event.stopPropagation();
  7395. item[openParam] = !item[openParam];
  7396. };
  7397. $scope.onReplyClick = function(change) {
  7398. if(change.$agreed) {
  7399. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7400. MakeChange.reply({itemId: change.id}, reply, function(){
  7401. toaster.pop('info', '提示', '回复成功');
  7402. loadData();
  7403. }, function(response){
  7404. toaster.pop('error', '回复失败', response.data);
  7405. });
  7406. }
  7407. };
  7408. }]);
  7409. /**
  7410. * 委外加工
  7411. */
  7412. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  7413. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  7414. BaseService.scrollBackToTop();
  7415. $scope.active = 'all';
  7416. $scope.agreedText = '全部';
  7417. $scope.dateZoneText = '一个月内';
  7418. $scope.condition = {dateZone: 1};
  7419. $scope.changeAgreed = function(agreed) {
  7420. $scope.condition.agreed = agreed;
  7421. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7422. $scope.condition.$agreedOpen = false;
  7423. };
  7424. $scope.changeDateZone = function(zone) {
  7425. $scope.condition.dateZone = zone;
  7426. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7427. $scope.condition.$dateZoneOpen = false;
  7428. getDateCondition(zone, $scope.condition);
  7429. $scope.tableParams.reload();
  7430. };
  7431. $scope.setActive = function(state) {
  7432. if($scope.active != state) {
  7433. $scope.active = state;
  7434. if($scope.tableParams.page() == 1)
  7435. $scope.tableParams.reload();
  7436. else
  7437. $scope.tableParams.page(1);
  7438. }
  7439. };
  7440. var getService = function() {
  7441. return MakeOutOrder;
  7442. };
  7443. $scope.tableParams = new ngTableParams({
  7444. page : 1,
  7445. count : 5,
  7446. sorting: {
  7447. date: 'desc'
  7448. }
  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.searchFilter = {};
  7456. pageParams.searchFilter.keyword = $scope.keyword;
  7457. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7458. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7459. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7460. $scope.loading = false;
  7461. if(page) {
  7462. params.total(page.totalElement);
  7463. $defer.resolve(page.content);
  7464. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7465. }
  7466. }, function(response){
  7467. $scope.loading = false;
  7468. toaster.pop('error', '数据加载失败', response.data);
  7469. });
  7470. }
  7471. });
  7472. $scope.openDatePicker = function($event, item, openParam) {
  7473. $event.preventDefault();
  7474. $event.stopPropagation();
  7475. item[openParam] = !item[openParam];
  7476. };
  7477. // 打开回复
  7478. $scope.openReply = function(change) {
  7479. change.$editing = true;
  7480. };
  7481. // 关闭回复
  7482. $scope.closeReply = function(change) {
  7483. change.$editing = false;
  7484. }
  7485. // 确定回复
  7486. $scope.onReplyClick = function(change) {
  7487. if(change.$agreed) {
  7488. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7489. $scope.loading = true;
  7490. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  7491. $scope.loading = false;
  7492. toaster.pop('info', '提示', '回复成功');
  7493. $scope.tableParams.reload();
  7494. }, function(response){
  7495. $scope.loading = false;
  7496. toaster.pop('error', '回复失败', response.data);
  7497. });
  7498. }
  7499. };
  7500. // 搜索框回车
  7501. $scope.onSearch = function() {
  7502. $scope.tableParams.page(1);
  7503. $scope.tableParams.reload();
  7504. };
  7505. // 选择查找日期
  7506. $scope.onDateCondition = function(){
  7507. $scope.tableParams.page(1);
  7508. $scope.tableParams.reload();
  7509. };
  7510. }]);
  7511. /**
  7512. * 委外加工详细
  7513. */
  7514. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  7515. BaseService.scrollBackToTop();
  7516. var loadData = function() {
  7517. MakeOutOrder.get({id: $stateParams.id}, function(data){
  7518. $scope.order = data;
  7519. var sum = $scope.order.qty * $scope.order.price;
  7520. $scope.order.total = sum;
  7521. $scope.loading = false;
  7522. });
  7523. };
  7524. loadData();
  7525. // 获取回复记录
  7526. $scope.getReply = function(item) {
  7527. if(!item.replies) {
  7528. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  7529. item.replies = replies;
  7530. });
  7531. }
  7532. };
  7533. $scope.openDatePicker = function($event, item, openParam) {
  7534. $event.preventDefault();
  7535. $event.stopPropagation();
  7536. item[openParam] = !item[openParam];
  7537. };
  7538. // 点击回复
  7539. $scope.onReplyClick = function(order, inverse) {
  7540. if(order.reply) {
  7541. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7542. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7543. return;
  7544. }
  7545. var reply = angular.copy(order.reply);
  7546. if(reply.delivery) {
  7547. if(typeof reply.delivery == 'object')
  7548. reply.delivery = reply.delivery.getTime();
  7549. } else {
  7550. reply.delivery = order.delivery;
  7551. }
  7552. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7553. $scope.loading = true;
  7554. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  7555. $scope.loading = false;
  7556. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7557. loadData();
  7558. }, function(response){
  7559. $scope.loading = false;
  7560. toaster.pop('error', '回复失败', response.data);
  7561. });
  7562. }
  7563. };
  7564. // 打开回复
  7565. $scope.openReply = function(order) {
  7566. if(!order.reply) {
  7567. order.reply = {
  7568. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7569. delivery: order.delivery
  7570. }
  7571. }
  7572. order.$editing = true;
  7573. };
  7574. // 关闭回复
  7575. $scope.closeReply = function(order) {
  7576. order.$editing = false;
  7577. }
  7578. // 自己委外加工订单
  7579. $scope.print = function(order) {
  7580. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  7581. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  7582. };
  7583. }]);
  7584. /**
  7585. * 计算时间差
  7586. */
  7587. app.filter('timespan', function(){
  7588. return function(time) {
  7589. if(time == null)
  7590. return '9999年';
  7591. var now = new Date().getTime(), span = time - now,
  7592. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  7593. m = Math.ceil(span/60000);
  7594. if(span < 0)
  7595. return '0天';
  7596. if(d > 0)
  7597. return d + '天';
  7598. if(h > 0)
  7599. return h + '小时';
  7600. if(m > 0)
  7601. return m + '分钟';
  7602. return '0天';
  7603. };
  7604. });
  7605. app.filter('firstchar', function(){
  7606. return function(str) {
  7607. if(str == null)
  7608. return null;
  7609. return str.substring(0, 1);
  7610. };
  7611. });
  7612. /**
  7613. * 搜索框,回车触发
  7614. */
  7615. app.directive('ngSearch', ['$parse', function($parse) {
  7616. return {
  7617. require : '?ngModel',
  7618. restrict : 'A',
  7619. link : function(scope, element, attrs, ngModel) {
  7620. var searchFn = $parse(attrs.ngSearch);
  7621. element.bind('keypress', function(event) {
  7622. if (event.keyCode == '13') {
  7623. event.preventDefault();
  7624. event.stopPropagation();
  7625. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  7626. }
  7627. });
  7628. }
  7629. };
  7630. }]);
  7631. /**
  7632. * 状态码 -> 描述
  7633. */
  7634. app.filter('status', function(){
  7635. return function(data) {
  7636. var statusConfig = {
  7637. '101': '已提交',
  7638. '102': '已审核',
  7639. '103': '未通过',
  7640. '200': '未回复',
  7641. '201': '已回复',
  7642. '313': '已激活',
  7643. '316': '已过账',
  7644. '311': '申请中',
  7645. '312': '未激活'
  7646. };
  7647. return statusConfig[data];
  7648. }
  7649. });
  7650. //弹出问题反馈模态框
  7651. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  7652. //获取当前用户
  7653. AuthenticationService.getAuthentication().success(function(data) {
  7654. $scope.user = data;
  7655. });
  7656. $scope.showModal = function(){
  7657. var modalInstance = $modal.open({
  7658. animation: true,
  7659. templateUrl: 'static/tpl/serve/feedback.html',
  7660. controller: 'FeedbackCtrl',
  7661. resolve: {
  7662. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  7663. }
  7664. });
  7665. modalInstance.result.then(function(){
  7666. }, function(){
  7667. })
  7668. }
  7669. }]);
  7670. /*
  7671. * 提交我的反馈
  7672. */
  7673. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  7674. $scope.isPublic = 1; //默认公开
  7675. $scope.classId = 1; //默认类别
  7676. $scope.user = user;
  7677. $scope.ok = function(){
  7678. if(!$scope.user){ //用户未登录
  7679. $scope.uu = null;
  7680. }else{ //用户已登录
  7681. $scope.uu = $scope.user.userUU;
  7682. }
  7683. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  7684. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  7685. function(data){
  7686. toaster.pop('success', '成功', '您的问题反馈成功!');
  7687. $scope.cancel();
  7688. }, function(response){
  7689. toaster.pop('error', '错误', response.data);
  7690. });
  7691. }
  7692. $scope.cancel = function () {
  7693. $modalInstance.dismiss();
  7694. };
  7695. }]);
  7696. //“我的问题反馈”跳转控制
  7697. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  7698. $scope.myFeedback = function(){
  7699. AuthenticationService.getAuthentication().success(function(data){
  7700. $scope.user = data;
  7701. if(!$scope.user){
  7702. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  7703. return false;
  7704. }else{
  7705. window.location.href = "./serve#/question/myFeedback";
  7706. }
  7707. });
  7708. }
  7709. }]);
  7710. //客户服务
  7711. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  7712. Vendor.getServe(function(datas){
  7713. $scope.vendors = datas;
  7714. console.log($scope.Vender);
  7715. // 自动跳转
  7716. if(datas && datas.length == 1)
  7717. $scope.redirect(datas[0]);
  7718. });
  7719. $scope.redirect = function(vendor) {
  7720. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  7721. };
  7722. }]);
  7723. /**
  7724. * 物料资料
  7725. */
  7726. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  7727. BaseService.scrollBackToTop();
  7728. $scope.active = 'all';
  7729. $scope.agreedText = '全部';
  7730. $scope.dateZoneText = '一个月内';
  7731. $scope.condition = {dateZone: 1};
  7732. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7733. $scope.changeAgreed = function(agreed) {
  7734. $scope.condition.agreed = agreed;
  7735. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7736. $scope.condition.$agreedOpen = false;
  7737. };
  7738. $scope.changeDateZone = function(zone) {
  7739. $scope.condition.dateZone = zone;
  7740. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7741. $scope.condition.$dateZoneOpen = false;
  7742. getDateCondition(zone, $scope.condition);
  7743. $scope.tableParams.reload();
  7744. };
  7745. $scope.setActive = function(state) {
  7746. if($scope.active != state) {
  7747. $scope.active = state;
  7748. if($scope.tableParams.page() == 1)
  7749. $scope.tableParams.reload();
  7750. else
  7751. $scope.tableParams.page(1);
  7752. }
  7753. };
  7754. var getService = function() {
  7755. return GetProductInfo;
  7756. };
  7757. $scope.tableParams = new ngTableParams({
  7758. page : 1,
  7759. count : 5,
  7760. sorting: {
  7761. }
  7762. }, {
  7763. total : 0,
  7764. counts: [5, 10, 25, 50],
  7765. getData : function($defer, params) {
  7766. $scope.loading = true;
  7767. var pageParams = params.url();
  7768. pageParams.keyword = $scope.keyword;
  7769. pageParams.searchFilter = $scope.searchFilter;
  7770. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7771. $scope.loading = false;
  7772. if(page) {
  7773. params.total(page.totalElement);
  7774. $defer.resolve(page.content);
  7775. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7776. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  7777. }
  7778. }, function(response) {
  7779. $scope.loading = false;
  7780. toaster.pop('error', '数据加载失败', response.data);
  7781. });
  7782. }
  7783. });
  7784. // 搜索框回车
  7785. $scope.onSearch = function() {
  7786. $scope.tableParams.page(1);
  7787. $scope.tableParams.reload();
  7788. };
  7789. //删除
  7790. $scope.deleteById = function(id) {
  7791. GetProductInfo.deleteById({id: id}, function(data) {
  7792. if(data.error) {
  7793. toaster.pop("error", "提示", data.error);
  7794. } else {
  7795. toaster.pop("success", "提示", "删除成功");
  7796. $timeout(function() {
  7797. $scope.tableParams.reload();
  7798. }, 500);
  7799. }
  7800. }), function(response) {
  7801. toaster.pop("error", "删除失败", response.data);
  7802. };
  7803. }
  7804. }]);
  7805. /**
  7806. * 物料批量上传
  7807. */
  7808. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  7809. BaseService.scrollBackToTop();
  7810. // 通过excel批量上传物料
  7811. $scope.upload = function() {
  7812. var file = $scope.myFiles[0];
  7813. $upload.upload({
  7814. url: 'product/baseInfo/release/excel',
  7815. file: file,
  7816. method: 'POST'
  7817. }).success(function(data) {
  7818. $scope.result = data;
  7819. $scope.success = $scope.result.success;
  7820. $scope.total = $scope.result.total;
  7821. $scope.alters = $scope.result.alters;
  7822. $scope.infos = $scope.result.infos;
  7823. }).error(function(response) {
  7824. toaster.pop('error', response.data || response);
  7825. });
  7826. };
  7827. // 查看范例
  7828. $scope.showImg = function() {
  7829. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  7830. box.show();
  7831. box.find('img').attr('src', src);
  7832. box.find('a').click(function(){
  7833. box.hide();
  7834. });
  7835. box.dblclick(function(){
  7836. box.hide();
  7837. });
  7838. };
  7839. // 下载模板
  7840. $scope.download = function() {
  7841. window.location.href = 'product/baseInfo/upload/template';
  7842. };
  7843. }]);
  7844. /**
  7845. * 物料详情
  7846. */
  7847. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService) {
  7848. BaseService.scrollBackToTop();
  7849. // 录入人
  7850. AuthenticationService.getAuthentication().success(function(data) {
  7851. $scope.loading = false;
  7852. $scope.user = data;
  7853. });
  7854. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  7855. var loadData = function() {
  7856. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  7857. if(data.attach) {
  7858. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  7859. // 查看范例
  7860. $scope.showImg = function() {
  7861. var src = data.url, box = $('#image-box');
  7862. box.show();
  7863. box.find('img').attr('src', src);
  7864. box.find('a').click(function(){
  7865. box.hide();
  7866. });
  7867. box.dblclick(function(){
  7868. box.hide();
  7869. });
  7870. };
  7871. })
  7872. }
  7873. $scope.prodInfo = data;
  7874. $scope.prodInfo.$editing = false;
  7875. $scope.loading = false;
  7876. });
  7877. };
  7878. loadData();
  7879. // 更新
  7880. $scope.update = function() {
  7881. $scope.prodInfo.$editing = true;
  7882. };
  7883. // 取消
  7884. $scope.cancel = function() {
  7885. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  7886. $scope.prodInfo = data;
  7887. $scope.prodInfo.$editing = false;
  7888. $scope.loading = false;
  7889. });
  7890. };
  7891. $scope.submit = function(prodInfo) {
  7892. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  7893. $upload.upload({
  7894. url: 'product/baseInfo/updateProdInfo',
  7895. file: file,
  7896. method: 'POST',
  7897. data: {
  7898. prodInfo: $scope.prodInfo
  7899. },
  7900. }).success(function(data) {
  7901. if(data.success) {
  7902. toaster.pop('success', '提示', data.success);
  7903. window.location.reload();
  7904. }
  7905. if(data.error) {
  7906. toaster.pop('error', '提示', data.error);
  7907. }
  7908. }).error(function(data) {
  7909. $scope.loadingShow = false;
  7910. toaster.pop('error', '操作失败', data.error);
  7911. });
  7912. }
  7913. $scope.previewShow = false;
  7914. $scope.pdfShow = false;
  7915. $scope.noneFileShow = true;
  7916. $scope.$watch('myFiles', function(){
  7917. if($scope.myFiles) {
  7918. $scope.noneFileShow = false;
  7919. var file = $scope.myFiles[0];
  7920. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  7921. $scope.pdfShow = true;
  7922. $scope.previewShow = false;
  7923. $scope.imgPreviewName = file.name;
  7924. } else{
  7925. if (typeof(Worker) !== "undefined") {//支持HTML5
  7926. $scope.imgPreview = getObjectURL(file);
  7927. $scope.imgPreviewName = file.name;
  7928. } else{//不支持HTML5
  7929. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  7930. $scope.imgPreviewName = file.name;
  7931. }
  7932. $scope.previewShow = true;
  7933. $scope.pdfShow = false;
  7934. }
  7935. } else {
  7936. $scope.noneFileShow = true;
  7937. $scope.previewShow = false;
  7938. $scope.pdfShow = false;
  7939. }
  7940. });
  7941. //建立一个可存取到该file的url
  7942. var getObjectURL = function(file) {
  7943. var url = null ;
  7944. if (window.createObjectURL!=undefined) { // basic
  7945. url = window.createObjectURL(file) ;
  7946. } else if (window.URL!=undefined) { // mozilla(firefox)
  7947. url = window.URL.createObjectURL(file) ;
  7948. } else if (window.webkitURL!=undefined) { // webkit or chrome
  7949. url = window.webkitURL.createObjectURL(file) ;
  7950. }
  7951. return url ;
  7952. };
  7953. }]);
  7954. /**
  7955. * 新增物料
  7956. */
  7957. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService) {
  7958. BaseService.scrollBackToTop();
  7959. // 录入人
  7960. AuthenticationService.getAuthentication().success(function(data) {
  7961. $scope.loading = false;
  7962. $scope.user = data;
  7963. });
  7964. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  7965. $scope.prodInfo = {unit: 'PCS'};
  7966. // 选择类目
  7967. $scope.selectKind = function(uuids) {
  7968. $modal.open({
  7969. animation: true,
  7970. size: 'lg',
  7971. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  7972. controller: 'KindChooseCtrl',
  7973. }).result.then(function(data){
  7974. $scope.kindId = data;
  7975. var modalInstance = $modal.open({
  7976. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  7977. controller: 'FindComponentCtrl',
  7978. size: 'lg',
  7979. resolve: {
  7980. KindId: function() {
  7981. return $scope.kindId;
  7982. }
  7983. }
  7984. });
  7985. modalInstance.result.then(function(data) {
  7986. $scope.prodInfo.cmpUuId = data.uuid;
  7987. $scope.prodInfo.cmpCode = data.code;
  7988. $scope.prodInfo.brand = data.brand.nameEn;
  7989. console.log($scope.prodInfo.brand);
  7990. }, function(){
  7991. });
  7992. }, function(){
  7993. });
  7994. };
  7995. //提交
  7996. $scope.submit = function(prodInfo){
  7997. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  7998. $upload.upload({
  7999. url: 'product/baseInfo/addNewProduct',
  8000. file: file,
  8001. method: 'POST',
  8002. data: {
  8003. prodInfo: $scope.prodInfo
  8004. },
  8005. }).success(function(data) {
  8006. if(data.success) {
  8007. toaster.pop('success', '提示', data.success);
  8008. $timeout(function() {
  8009. //提交后跳转到详情页面,防止重复提交
  8010. window.location.href="#/sale/prodList/"+data.id;
  8011. }, 500);
  8012. }
  8013. if(data.error) {
  8014. toaster.pop('error', '提示', data.error);
  8015. $timeout(function() {
  8016. //提交后跳转到详情页面,防止重复提交
  8017. window.location.href="#/sale/prodList/"+data.id;
  8018. }, 500);
  8019. }
  8020. }).error(function(data) {
  8021. $scope.loadingShow = false;
  8022. toaster.pop('error', '操作失败', data.error);
  8023. });
  8024. // GetProductInfo.addNewProd({}, prodInfo, function(data) {
  8025. // toaster.pop("success", "提示", "提交成功");
  8026. //
  8027. //
  8028. // }, function(res) {
  8029. // toaster.pop("error", "提示" + res);
  8030. // });
  8031. };
  8032. $scope.previewShow = false;
  8033. $scope.pdfShow = false;
  8034. $scope.noneFileShow = true;
  8035. $scope.$watch('myFiles', function(){
  8036. if($scope.myFiles) {
  8037. $scope.noneFileShow = false;
  8038. var file = $scope.myFiles[0];
  8039. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  8040. $scope.pdfShow = true;
  8041. $scope.previewShow = false;
  8042. $scope.imgPreviewName = file.name;
  8043. } else{
  8044. if (typeof(Worker) !== "undefined") {//支持HTML5
  8045. $scope.imgPreview = getObjectURL(file);
  8046. $scope.imgPreviewName = file.name;
  8047. } else{//不支持HTML5
  8048. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  8049. $scope.imgPreviewName = file.name;
  8050. }
  8051. $scope.previewShow = true;
  8052. $scope.pdfShow = false;
  8053. }
  8054. } else {
  8055. $scope.noneFileShow = true;
  8056. $scope.previewShow = false;
  8057. $scope.pdfShow = false;
  8058. }
  8059. });
  8060. //建立一个可存取到该file的url
  8061. var getObjectURL = function(file) {
  8062. var url = null ;
  8063. if (window.createObjectURL!=undefined) { // basic
  8064. url = window.createObjectURL(file) ;
  8065. } else if (window.URL!=undefined) { // mozilla(firefox)
  8066. url = window.URL.createObjectURL(file) ;
  8067. } else if (window.webkitURL!=undefined) { // webkit or chrome
  8068. url = window.webkitURL.createObjectURL(file) ;
  8069. }
  8070. return url ;
  8071. };
  8072. // 取消
  8073. $scope.cancel = function(){
  8074. $scope.prodInfo = angular.copy($scope.prodInfo);
  8075. };
  8076. }]);
  8077. /**
  8078. * 类目选择模态框
  8079. */
  8080. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  8081. $scope.kindId = null;
  8082. $scope.kinds = [[], [], [], []];
  8083. // 获取子类目
  8084. var getChildren = function(pid, deep) {
  8085. KindAPI.getChildren({parentId: pid}, function(data) {
  8086. $scope.kinds[deep] = data;
  8087. }, function(response) {
  8088. toaster.pop('error', '获取子类目失败', response.data);
  8089. });
  8090. };
  8091. // 改变节点选中状态
  8092. var changeStatus = function(item, deep) {
  8093. var kindId = null, level = 0;
  8094. angular.forEach($scope.kinds, function(ks, i) {
  8095. if(i > deep) {
  8096. $scope.kinds[i] = [];
  8097. } else {
  8098. angular.forEach(ks, function(k, j) {
  8099. if(i == deep) {
  8100. if(k.id == item.id) {
  8101. $scope.kinds[i][j].$active = true;
  8102. kindId = k.id;
  8103. } else {
  8104. k.$active = null;
  8105. }
  8106. }
  8107. });
  8108. }
  8109. });
  8110. // 选择的节点
  8111. $scope.kindId = kindId;
  8112. $scope.active = item;
  8113. // 当前可操作的层级
  8114. if(deep < 3) {
  8115. $scope.activeDeep = deep + 1;
  8116. }
  8117. };
  8118. // 节点点击后获取子类目,节点被选中
  8119. $scope.onItemClick = function(item, deep) {
  8120. changeStatus(item, deep);
  8121. if (!item.isLeaf) {
  8122. getChildren(item.id, deep + 1);
  8123. }
  8124. };
  8125. // 重新加载数据
  8126. function reload(deep) {
  8127. var pid;
  8128. if(deep) {
  8129. pid = $scope.actives[deep - 1].id;
  8130. } else {
  8131. pid = 0;
  8132. deep = 0;
  8133. }
  8134. getChildren(pid, deep);
  8135. }
  8136. // 初始加载数据,获取第一层的类目
  8137. if($scope.actives) {
  8138. angular.forEach($scope.actives, function(v, k) {
  8139. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  8140. $scope.kinds[k] = data;
  8141. angular.forEach($scope.kinds[k], function(kind, i){
  8142. if(kind.id == v.id) {
  8143. $scope.kinds[k][i].$active = true;
  8144. $scope.actives[k] = $scope.kinds[k][i];
  8145. }
  8146. })
  8147. }, function(response) {
  8148. toaster.pop('error', '获取子类目失败', response.data);
  8149. });
  8150. });
  8151. } else {
  8152. reload();
  8153. }
  8154. // 取消
  8155. $scope.cancel = function() {
  8156. $modalInstance.dismiss();
  8157. };
  8158. // 确认选择
  8159. $scope.check = function() {
  8160. $modalInstance.close($scope.kindId);
  8161. };
  8162. }]);
  8163. /**
  8164. * 器件筛选
  8165. */
  8166. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  8167. //状态
  8168. $scope.setActive = function (state){
  8169. if($scope.active != state) {
  8170. $scope.active = state;
  8171. if($scope.tableParams.page() == 1)
  8172. $scope.tableParams.reload();
  8173. else
  8174. $scope.tableParams.page(1);
  8175. }
  8176. };
  8177. $scope.tableParams = new ngTableParams({
  8178. page : 1,
  8179. count : 10
  8180. }, {
  8181. total : 0,
  8182. counts: [5, 10, 25, 50],
  8183. getData : function($defer, params) {
  8184. $scope.loading = true;
  8185. var pageParams = params.url();
  8186. pageParams.keyword = $scope.keyword;
  8187. pageParams.kindId = KindId;
  8188. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  8189. console.log(page);
  8190. $scope.loading = false;
  8191. if(page) {
  8192. params.total(page.totalElement);
  8193. $defer.resolve(page.content);
  8194. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8195. }
  8196. }, function(response){
  8197. $scope.loading = false;
  8198. toaster.pop('error', '数据加载失败', response.data);
  8199. });
  8200. }
  8201. });
  8202. // 取消
  8203. $scope.cancel = function() {
  8204. $modalInstance.dismiss();
  8205. };
  8206. // 选择
  8207. $scope.check = function(data){
  8208. $modalInstance.close(data);
  8209. };
  8210. // 搜索框回车
  8211. $scope.onSearch = function() {
  8212. $scope.tableParams.page(1);
  8213. $scope.tableParams.reload();
  8214. };
  8215. }]);
  8216. /**
  8217. * 企业列表
  8218. */
  8219. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  8220. BaseService.scrollBackToTop();
  8221. $scope.active = 'all';
  8222. $scope.agreedText = '全部';
  8223. $scope.dateZoneText = '一个月内';
  8224. $scope.condition = {dateZone: 1};
  8225. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8226. $scope.changeAgreed = function(agreed) {
  8227. $scope.condition.agreed = agreed;
  8228. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8229. $scope.condition.$agreedOpen = false;
  8230. };
  8231. $scope.changeDateZone = function(zone) {
  8232. $scope.condition.dateZone = zone;
  8233. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8234. $scope.condition.$dateZoneOpen = false;
  8235. getDateCondition(zone, $scope.condition);
  8236. $scope.tableParams.reload();
  8237. };
  8238. $scope.setActive = function(state) {
  8239. if($scope.active != state) {
  8240. $scope.active = state;
  8241. if($scope.tableParams.page() == 1)
  8242. $scope.tableParams.reload();
  8243. else
  8244. $scope.tableParams.page(1);
  8245. }
  8246. };
  8247. var getService = function() {
  8248. return getAccountUserSpace;
  8249. };
  8250. $scope.tableParams = new ngTableParams({
  8251. page : 1,
  8252. count : 5,
  8253. sorting: {
  8254. }
  8255. }, {
  8256. total : 0,
  8257. counts: [5, 10, 25, 50],
  8258. getData : function($defer, params) {
  8259. $scope.loading = true;
  8260. var pageParams = params.url();
  8261. pageParams.keyword = $scope.keyword;
  8262. $scope.tip = $scope.keyword;
  8263. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8264. $scope.loading = false;
  8265. if(page) {
  8266. params.total(page.totalElement);
  8267. $defer.resolve(page.content);
  8268. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8269. }
  8270. }, function(response) {
  8271. $scope.loading = false;
  8272. toaster.pop('error', '数据加载失败', response.data);
  8273. });
  8274. }
  8275. });
  8276. // 搜索框回车
  8277. $scope.onSearch = function() {
  8278. $scope.tableParams.page(1);
  8279. $scope.tableParams.reload();
  8280. };
  8281. // 添加合作关系
  8282. $scope.addPartner = function(name, businessCode) {
  8283. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  8284. if(data.success) {
  8285. toaster.pop("success", '添加成功', data.success);
  8286. }
  8287. if(data.error) {
  8288. toaster.pop("error", '添加失败', data.error);
  8289. }
  8290. }, function(response) {
  8291. toaster.pop('error','失败',response.data);
  8292. });
  8293. }
  8294. $scope.status = 'enList';
  8295. }]);
  8296. /**
  8297. * 新增采购单
  8298. */
  8299. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http) {
  8300. BaseService.scrollBackToTop();
  8301. // 每次进入时先清除掉rootScope下的venuu
  8302. $rootScope.venduu = null;
  8303. // 获取收货地址列表
  8304. ShipAddress.shipAddList({}, function(data) {
  8305. $scope.ships = data;
  8306. $scope.order.shipadd = $scope.ships[0];
  8307. });
  8308. // 获取地址信息
  8309. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  8310. }).then(function(response) {
  8311. $scope.provinces = response.data;
  8312. });
  8313. $scope.order = {
  8314. date : new Date(),
  8315. cust : {
  8316. uu : '',
  8317. },
  8318. custUser : {
  8319. },
  8320. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  8321. orderItems : {
  8322. product : {},
  8323. },
  8324. };
  8325. //商品信息
  8326. $scope.order.orderItems = [];
  8327. var item = {
  8328. code: null,
  8329. title: null,
  8330. spec: null,
  8331. unit: null,
  8332. qty: null,
  8333. price: null,
  8334. remark: null,
  8335. delivery: null,
  8336. id: null,
  8337. };
  8338. // 获取供应商列表
  8339. cartOperation.vendorInfo({}, function(data) {
  8340. });
  8341. if($rootScope.businessCode) {
  8342. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  8343. $scope.id = data.id;
  8344. $scope.order.cust.enName = data.vendorEnterprise.enName;
  8345. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  8346. $scope.order.cust.uu = data.vendorEnterprise.uu;
  8347. $rootScope.venduu = data.vendorEnterprise.uu;
  8348. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8349. $scope.contacts = data;
  8350. $scope.order.vendor = $scope.contacts[0];
  8351. });
  8352. }, function(response) {
  8353. });
  8354. };
  8355. // 查找客户
  8356. $scope.dbfindCust = function(){
  8357. var modalInstance = $modal.open({
  8358. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  8359. controller: 'DbfindVendorInfoCtrl',
  8360. size: 'lg',
  8361. resolve: {
  8362. orderItems: function() {
  8363. return $scope.order.orderItems;
  8364. }
  8365. }
  8366. });
  8367. modalInstance.result.then(function(data) {
  8368. $rootScope.venduu = data.vendorEnterprise.uu;
  8369. $scope.id = data.id;
  8370. $scope.order.cust = data.vendorEnterprise;
  8371. $scope.order.custUser = data.vendorUser;
  8372. $scope.order.orderItems = [];
  8373. var item = {
  8374. code: null,
  8375. title: null,
  8376. spec: null,
  8377. unit: null,
  8378. qty: null,
  8379. price: null,
  8380. remark: null,
  8381. delivery: null,
  8382. };
  8383. // $scope.order.orderItems.push(item);
  8384. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8385. $scope.contacts = data;
  8386. $scope.order.vendor = $scope.contacts[0];
  8387. });
  8388. }, function(){
  8389. });
  8390. };
  8391. // $scope.order.orderItems.push(item);
  8392. if($rootScope.prodId) {
  8393. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  8394. item.code = data.code;
  8395. item.title = data.title;
  8396. item.spec = data.spec;
  8397. item.unit = data.unit;
  8398. item.id = data.id;
  8399. $scope.order.orderItems.push(item);
  8400. }, function(response) {
  8401. });
  8402. }
  8403. //增加商品
  8404. $scope.addProduct = function(index) {
  8405. if($scope.order.orderItems[index].code == null) {
  8406. toaster.pop('info', '提示', '请先选择商品');
  8407. } else {
  8408. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null, $endDateOpen: false});
  8409. }
  8410. };
  8411. //删除商品
  8412. $scope.deleteProduct = function(index) {
  8413. $scope.order.orderItems.splice(index, 1);
  8414. };
  8415. // 搜索框回车
  8416. $scope.onSearch = function(keyword) {
  8417. $scope.keyword = keyword;
  8418. $scope.tableParams.page(1);
  8419. $scope.tableParams.reload();
  8420. };
  8421. $scope.tableParams = new ngTableParams({
  8422. page : 1,
  8423. count : 10
  8424. }, {
  8425. total : 0,
  8426. counts: [5, 10, 25, 50],
  8427. getData : function($defer, params) {
  8428. $scope.loading = true;
  8429. var pageParams = params.url();
  8430. pageParams.keyword = $scope.keyword;
  8431. $scope.tip = $scope.keyword;
  8432. pageParams.custUU = $scope.order.cust.uu;
  8433. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  8434. $scope.loading = false;
  8435. if(page) {
  8436. params.total(page.totalElement);
  8437. $scope.total = page.totalElement;
  8438. $defer.resolve(page.content);
  8439. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8440. }
  8441. }, function(response){
  8442. $scope.loading = false;
  8443. toaster.pop('error', '数据加载失败', response.data);
  8444. });
  8445. }
  8446. });
  8447. // 选择
  8448. $scope.check = function(data) {
  8449. $scope.order.orderItems.push({code: data.code, title: data.title, spec: data.spec, unit: data.unit, qty: null, price: null, remark: null, delivery: null, id: data.id});
  8450. };
  8451. // 监听custuu发生变化,重新加载物料信息
  8452. $scope.$watch('order.cust.uu', function(n, o) {
  8453. if(n==o) {
  8454. return;
  8455. } else {
  8456. $scope.tableParams.page(1);
  8457. $scope.tableParams.reload();
  8458. }
  8459. }, true);
  8460. // 查找客户物料
  8461. $scope.dbfindCustProd = function(index){
  8462. if($scope.order.cust.uu) {
  8463. var modalInstance = $modal.open({
  8464. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  8465. controller: 'DbfindCustProdCtrl',
  8466. size: 'lg',
  8467. resolve: {
  8468. custUU: function() {
  8469. return $scope.order.cust.uu
  8470. }
  8471. }
  8472. });
  8473. modalInstance.result.then(function(data) {
  8474. $scope.order.orderItems.push(data);
  8475. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8476. if($scope.order.orderItems[i].code == null || i == index) {
  8477. $scope.order.orderItems.splice(i, 1);
  8478. }
  8479. }
  8480. }, function() {
  8481. });
  8482. } else {
  8483. toaster.pop('info', '提示', '请先选择供应商');
  8484. }
  8485. };
  8486. $scope.getMinDate = function(item) {
  8487. return $filter('date')(new Date, 'yyyy-MM-dd');
  8488. };
  8489. $scope.openDatePicker = function($event, openParam, index) {
  8490. $event.preventDefault();
  8491. $event.stopPropagation();
  8492. $scope.order.orderItems[index].$endDateOpen = !openParam;
  8493. };
  8494. // 添加到购物车
  8495. $scope.addToCart = function(order) {
  8496. $scope.loading = true;
  8497. $scope.order.vendusertel = order.vendor.tel;
  8498. $scope.order.venduser = order.vendor.venduser;
  8499. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  8500. $scope.order.custUU = $scope.order.cust.uu;
  8501. $scope.order.custUserUU = $scope.order.custUser.userUU;
  8502. if($scope.order.date instanceof Date) {
  8503. $scope.order.date = $scope.order.date.getTime();
  8504. }
  8505. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8506. if($scope.order.orderItems[i].delivery instanceof Date) {
  8507. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  8508. }
  8509. if($scope.order.currency != 'RMB') {
  8510. $scope.order.orderItems[i].rate = 0;
  8511. }
  8512. }
  8513. addtoCart.save({}, $scope.order, function(data){
  8514. $scope.loading = false;
  8515. toaster.pop('success', '成功', '保存成功');
  8516. window.location.hash = '#/purc/cart/'+data.id;
  8517. }, function(response){
  8518. $scope.loading = false;
  8519. toaster.pop('error', '保存失败', response.data);
  8520. });
  8521. };
  8522. // 立即购买
  8523. $scope.addToOrder = function(order) {
  8524. $scope.loading = true;
  8525. $scope.order.vendusertel = order.vendor.tel;
  8526. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  8527. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  8528. $scope.order.custUU = $scope.order.cust.uu;
  8529. $scope.order.custUserUU = $scope.order.custUser.userUU;
  8530. if($scope.order.date instanceof Date) {
  8531. $scope.order.date = $scope.order.date.getTime();
  8532. }
  8533. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8534. if($scope.order.orderItems[i].delivery instanceof Date) {
  8535. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  8536. }
  8537. if($scope.order.currency != 'RMB') {
  8538. $scope.order.orderItems[i].rate = 0;
  8539. }
  8540. }
  8541. newPurcOrder.save({}, $scope.order, function(data){
  8542. $scope.loading = false;
  8543. toaster.pop('success', '成功', '保存成功');
  8544. window.location.hash = '#/purc/order/'+data.id;
  8545. }, function(response){
  8546. $scope.loading = false;
  8547. toaster.pop('error', '保存失败', response.data);
  8548. });
  8549. };
  8550. // 新增收货地址保存
  8551. $scope.saveShipAddress = function(ship) {
  8552. ship.address = ship.province + ship.city + ship.district;
  8553. ShipAddress.saveAddress( {}, ship, function(data) {
  8554. if(data.success) {
  8555. ShipAddress.shipAddList({}, function(data) {
  8556. $scope.ships = data;
  8557. $scope.order.shipadd = $scope.ships[0];
  8558. });
  8559. toaster.pop('success', '提示', data.success);
  8560. }
  8561. if(data.error) {
  8562. toaster.pop('error', '提示', data.error);
  8563. }
  8564. });
  8565. }
  8566. // 新增供应商联系人
  8567. $scope.addContact = function(uu) {
  8568. var modalInstance = $modal.open({
  8569. animation: true,
  8570. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  8571. controller: 'AddContacCtrl',
  8572. resolve: {
  8573. }
  8574. });
  8575. modalInstance.result.then(function(data) {
  8576. $scope.contact = data;
  8577. $scope.contact.venduu = uu;
  8578. Vendor.saveContact({}, $scope.contact, function(data) {
  8579. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8580. $scope.contacts = data;
  8581. $scope.order.vendor = $scope.contacts[0];
  8582. });
  8583. toaster.pop('success', '提示', '联系人保存成功');
  8584. }, function(response) {
  8585. toaster.pop('error', '失败', response.data);
  8586. });
  8587. });
  8588. }
  8589. }]);
  8590. // 查找供应商
  8591. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  8592. $scope.prod = false;
  8593. if(orderItems.length != 0) {
  8594. $scope.prod = true;
  8595. }
  8596. BaseService.scrollBackToTop();
  8597. if($rootScope.venduu != null) {
  8598. $scope.venduu = $rootScope.venduu;
  8599. }
  8600. // 搜索框回车
  8601. $scope.onSearch = function(keyword) {
  8602. $scope.keyword = keyword;
  8603. $scope.customerParams.page(1);
  8604. $scope.customerParams.reload();
  8605. };
  8606. $scope.customerParams = new ngTableParams({
  8607. page : 1,
  8608. count : 10
  8609. }, {
  8610. total : 0,
  8611. counts: [5, 10, 25, 50],
  8612. getData : function($defer, params) {
  8613. $scope.loading = true;
  8614. var pageParams = params.url();
  8615. pageParams.keyword = $scope.keyword;
  8616. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  8617. $scope.loading = false;
  8618. if(page) {
  8619. params.total(page.totalElements);
  8620. $defer.resolve(page.content);
  8621. }
  8622. $scope.totalCount = page.totalElements;
  8623. }, function(response){
  8624. $scope.loading = false;
  8625. toaster.pop('error', '数据加载失败', response.data);
  8626. });
  8627. }
  8628. });
  8629. $scope.cancel = function() {
  8630. $modalInstance.dismiss();
  8631. };
  8632. $scope.ensure = false;
  8633. $scope.check = function(vendor) { // 需要进行判断的选择
  8634. console.log(vendor);
  8635. $scope.vendorInfo = vendor;
  8636. $scope.ensure = true;
  8637. };
  8638. $scope.checkVendor = function(vendor) { // 直接选择
  8639. $modalInstance.close(vendor);
  8640. }
  8641. }]);
  8642. /**
  8643. * 我的客户
  8644. */
  8645. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  8646. $scope.userInfoResult = true;
  8647. AuthenticationService.getAuthentication().success(function(data) {
  8648. $scope.loading = false;
  8649. $scope.thisUser = data;
  8650. });
  8651. var getCustInfos = function(custuu) {
  8652. if(custuu) {
  8653. VendorService.userInfo.query({uu:custuu},null,function(data) {
  8654. console.log(data);
  8655. $scope.custInfos = data;
  8656. var getPage = function(page, size){
  8657. if($scope.custInfos) {
  8658. var result = {};
  8659. result.totalCount = $scope.custInfos.length;
  8660. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  8661. if($scope.custInfos.length % size == 0) {
  8662. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  8663. }else {
  8664. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  8665. }
  8666. result.first = page == 1;
  8667. result.last = page == result.totalPage;
  8668. result.page = page;
  8669. result.next = page - 0 + 1;
  8670. result.pre = page - 1;
  8671. return result;
  8672. }
  8673. }
  8674. $scope.userdata = getPage(1,4);
  8675. $scope.first = function (){
  8676. $scope.userdata = getPage($scope.userdata.pre,4);
  8677. }
  8678. $scope.last = function (){
  8679. $scope.userdata = getPage($scope.userdata.next,4);
  8680. }
  8681. }, function(response){
  8682. $scope.loading = false;
  8683. toaster.pop('error', '数据加载失败', response.data);
  8684. });
  8685. }
  8686. }
  8687. $scope.addUserInfo = function(customer) {
  8688. //TODO
  8689. if ($scope.thisUser.sys) {
  8690. var modalInstance = $modal.open({
  8691. animation: true,
  8692. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  8693. controller: 'AddUserInfoCtrl',
  8694. resolve: {
  8695. customer: function() {
  8696. return customer;
  8697. }
  8698. }
  8699. });
  8700. modalInstance.result.then(function(changed, checked){
  8701. if(changed) {
  8702. if(checked)
  8703. $scope.newUser.roles = checked;
  8704. else
  8705. loadUsers();
  8706. }
  8707. });
  8708. } else {
  8709. toaster.pop('error', '您不是管理员,无权限分配用户!');
  8710. }
  8711. }
  8712. $scope.showUserInfo = function(customer,boo) {
  8713. $scope.custInfo = customer;
  8714. if(boo) {
  8715. getCustInfos(customer.myEnterprise.uu);
  8716. $scope.userInfoResult = true;
  8717. }
  8718. }
  8719. $scope.customerParams = new ngTableParams({
  8720. page : 1,
  8721. count : 10
  8722. }, {
  8723. total : 0,
  8724. counts: [5, 10, 25, 50],
  8725. getData : function($defer, params) {
  8726. $scope.loading = true;
  8727. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  8728. $scope.loading = false;
  8729. if(page) {
  8730. params.total(page.totalElements);
  8731. $defer.resolve(page.content);
  8732. }
  8733. $scope.totalCount = page.totalElements;
  8734. }, function(response){
  8735. $scope.loading = false;
  8736. toaster.pop('error', '数据加载失败', response.data);
  8737. });
  8738. }
  8739. });
  8740. }]);
  8741. /**
  8742. * 我的供应商
  8743. */
  8744. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope){
  8745. BaseService.scrollBackToTop();
  8746. // 搜索框回车
  8747. $scope.onSearch = function(keyword) {
  8748. $scope.keyword = keyword;
  8749. $scope.customerParams.page(1);
  8750. $scope.customerParams.reload();
  8751. };
  8752. $scope.customerParams = new ngTableParams({
  8753. page : 1,
  8754. count : 10
  8755. }, {
  8756. total : 0,
  8757. counts: [5, 10, 25, 50],
  8758. getData : function($defer, params) {
  8759. $scope.loading = true;
  8760. var pageParams = params.url();
  8761. pageParams.keyword = $scope.keyword;
  8762. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  8763. $scope.loading = false;
  8764. if(page) {
  8765. params.total(page.totalElements);
  8766. $scope.total = page.totalElement;
  8767. $defer.resolve(page.content);
  8768. }
  8769. $scope.totalCount = page.totalElements;
  8770. }, function(response){
  8771. $scope.loading = false;
  8772. toaster.pop('error', '数据加载失败', response.data);
  8773. });
  8774. }
  8775. });
  8776. // 查看供应商详情
  8777. $scope.VendorDetail = function(id, uu) {
  8778. $rootScope.vendorId = id;
  8779. $rootScope.vendoruu = uu;
  8780. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  8781. }
  8782. // 向企业购买
  8783. $scope.purcByEn = function(businessCode) {
  8784. $rootScope.businessCode = businessCode;
  8785. window.location.hash = "#/purc/addOrder";
  8786. }
  8787. }]);
  8788. /**
  8789. * 供应商详情
  8790. */
  8791. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  8792. BaseService.scrollBackToTop();
  8793. $scope.vendorContacts = [];
  8794. var loadData = function() {
  8795. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  8796. $scope.vendor = data.vendorEnterprise;
  8797. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  8798. $scope.vendorContacts = data;
  8799. });
  8800. });
  8801. };
  8802. loadData();
  8803. // 新增供应商联系人
  8804. $scope.addContact = function(uu) {
  8805. var modalInstance = $modal.open({
  8806. animation: true,
  8807. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  8808. controller: 'AddContacCtrl',
  8809. resolve: {
  8810. }
  8811. });
  8812. modalInstance.result.then(function(data) {
  8813. $scope.contact = data;
  8814. $scope.contact.venduu = uu;
  8815. Vendor.saveContact({}, $scope.contact, function(data) {
  8816. toaster.pop('success', '提示', '联系人保存成功');
  8817. $scope.vendorContacts.push(data);
  8818. }, function(response) {
  8819. toaster.pop('error', '失败', response.data);
  8820. });
  8821. });
  8822. }
  8823. // 编辑供应商联系人
  8824. $scope.edit = function(contact) {
  8825. var modalInstance = $modal.open({
  8826. animation: true,
  8827. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  8828. controller: 'EditContacCtrl',
  8829. resolve: {
  8830. contact: function() {
  8831. return contact;
  8832. }
  8833. }
  8834. });
  8835. modalInstance.result.then(function(data) {
  8836. $scope.contact = data;
  8837. Vendor.saveContact({}, $scope.contact, function(data) {
  8838. toaster.pop('success', '提示', '联系人修改成功');
  8839. }, function(response) {
  8840. toaster.pop('error', '失败', response.data);
  8841. });
  8842. });
  8843. }
  8844. // 删除供应商联系人
  8845. $scope.deleteById = function(id, index) {
  8846. $scope.vendorContacts.splice(index, 1);
  8847. Vendor.deleteContact({id: id}, {}, function(data) {
  8848. toaster.pop('success', '提示', '供应商联系人删除成功');
  8849. }, function(response) {
  8850. toaster.pop('error', '提示', response.data);
  8851. });
  8852. }
  8853. // 供应商物料信息
  8854. $scope.viewProdList = function(uu){
  8855. $scope.uu = uu;
  8856. $scope.tableParams.page(1);
  8857. $scope.tableParams.reload();
  8858. };
  8859. // 搜索框回车
  8860. $scope.onSearch = function(keyword) {
  8861. $scope.keyword = keyword;
  8862. $scope.tableParams.page(1);
  8863. $scope.tableParams.reload();
  8864. };
  8865. // 供应商物料信息
  8866. $scope.tableParams = new ngTableParams({
  8867. page : 1,
  8868. count : 10
  8869. }, {
  8870. total : 0,
  8871. counts: [5, 10, 25, 50],
  8872. getData : function($defer, params) {
  8873. $scope.loading = true;
  8874. var pageParams = params.url();
  8875. pageParams.custUU = $scope.uu;
  8876. pageParams.keyword = $scope.keyword;
  8877. $scope.tip = $scope.keyword;
  8878. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  8879. $scope.loading = false;
  8880. if(page) {
  8881. params.total(page.totalElement);
  8882. $scope.total = page.totalElement;
  8883. $defer.resolve(page.content);
  8884. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8885. }
  8886. }, function(response){
  8887. $scope.loading = false;
  8888. toaster.pop('error', '数据加载失败', response.data);
  8889. });
  8890. }
  8891. });
  8892. /**
  8893. * 选中单个物料购买
  8894. * @param businessCode
  8895. * @param id
  8896. */
  8897. $scope.PurcByEnAndProd = function(businessCode, id) {
  8898. $rootScope.businessCode = businessCode;
  8899. $rootScope.prodId = id;
  8900. window.location.hash = "#/purc/addOrder";
  8901. }
  8902. }]);
  8903. /**
  8904. * 编辑供应商联系人
  8905. */
  8906. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  8907. $scope.contact = contact;
  8908. $scope.save = function(contact) {
  8909. $modalInstance.close(contact);
  8910. }
  8911. $scope.cancel = function() {
  8912. $modalInstance.dismiss();
  8913. }
  8914. }]);
  8915. /**
  8916. * 新增供应商联系人
  8917. */
  8918. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  8919. $scope.save = function(contact) {
  8920. $modalInstance.close(contact);
  8921. }
  8922. $scope.cancel = function() {
  8923. $modalInstance.dismiss();
  8924. }
  8925. }]);
  8926. /**
  8927. * 建立合作关系申请
  8928. */
  8929. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout) {
  8930. BaseService.scrollBackToTop();
  8931. $scope.active = 'todo';
  8932. var getRequestStatus = function(active) {
  8933. var fn = 'getAllRequest';
  8934. switch(active) {
  8935. case 'done':
  8936. fn = 'getRequestDone';break;
  8937. case 'todo':
  8938. fn = 'getRequestTodo';break;
  8939. case 'end':
  8940. fn = 'getRequestEnd';break;
  8941. }
  8942. return fn;
  8943. }
  8944. // 切换单据类型
  8945. $scope.setActive = function(state) {
  8946. if($scope.active != state) {
  8947. $scope.active = state;
  8948. if($scope.tableParams.page() == 1)
  8949. $scope.tableParams.reload();
  8950. else
  8951. $scope.tableParams.page(1);
  8952. }
  8953. };
  8954. // 切换数据来源(正常数据 or 历史数据)
  8955. var getService = function() {
  8956. return AddPartnerMyRequest;
  8957. };
  8958. $scope.tableParams = new ngTableParams({ // ng-Table参数
  8959. page : 1,
  8960. count : 5,
  8961. sorting: {
  8962. }
  8963. }, {
  8964. total : 0,
  8965. counts: [5, 10, 15, 25, 50],
  8966. getData : function($defer, params) { // 获取数据的方法
  8967. $scope.loading = true;
  8968. var pageParams = params.url();
  8969. pageParams.keyword = $scope.keyword;
  8970. $scope.tip = $scope.keyword;
  8971. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8972. $scope.loading = false;
  8973. if(page) {
  8974. params.total(page.totalElement);
  8975. $defer.resolve(page.content);
  8976. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8977. }
  8978. }, function(response){
  8979. $scope.loading = false;
  8980. toaster.pop('error', '数据加载失败', response.data);
  8981. });
  8982. }
  8983. });
  8984. // 再次申请
  8985. $scope.reapply = function(id) {
  8986. AddPartner.reapply({id: id}, {}, function(data) {
  8987. toaster.pop('success', '提示', '操作成功');
  8988. }, function(response) {
  8989. toaster.pop('error','失败',response.data);
  8990. });
  8991. }
  8992. // 添加为供应商
  8993. $scope.addSupplier = function(vendUID) {
  8994. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  8995. if(data.success) {
  8996. toaster.pop('success', '提示', data.success);
  8997. }
  8998. if(data.error) {
  8999. toaster.pop('error','提示', data.error);
  9000. }
  9001. }, function(response) {
  9002. toaster.pop('error', '失败', response.data);
  9003. })
  9004. };
  9005. // 添加客户
  9006. $scope.addCust = function(vendUID) {
  9007. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  9008. if(data.success) {
  9009. toaster.pop('success', '提示', data.success);
  9010. }
  9011. if(data.error) {
  9012. toaster.pop('error','提示', data.error);
  9013. }
  9014. }, function(response) {
  9015. toaster.pop('error', '失败', response.data);
  9016. })
  9017. };
  9018. // 搜索框回车
  9019. $scope.onSearch = function() {
  9020. $scope.tableParams.page(1);
  9021. $scope.tableParams.reload();
  9022. };
  9023. // 同意申请
  9024. $scope.agree = function(id) {
  9025. AddPartner.agreeRequest({id: id}, {}, function(data) {
  9026. toaster.pop('success', '提示', '操作成功');
  9027. $timeout(function() {
  9028. window.location.reload();
  9029. }, 500);
  9030. }, function(response) {
  9031. toaster.pop('error', '提示', response.data);
  9032. });
  9033. }
  9034. // 拒绝申请
  9035. $scope.refuse = function(id, reason) {
  9036. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  9037. toaster.pop('success', '提示', '操作成功');
  9038. $timeout(function() {
  9039. window.location.reload();
  9040. }, 500);
  9041. }, function(response) {
  9042. toaster.pop('error', '提示', response.data);
  9043. });
  9044. }
  9045. $scope.status = 'send';
  9046. }]);
  9047. /**
  9048. * 建立合作关系处理申请
  9049. */
  9050. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  9051. BaseService.scrollBackToTop();
  9052. $scope.active = 'todo';
  9053. var getMessagetStatus = function(active) {
  9054. var fn = 'getAllMessage';
  9055. switch(active) {
  9056. case 'done':
  9057. fn = 'getMessageDone';break;
  9058. case 'todo':
  9059. fn = 'getMessageTodo';break;
  9060. case 'end':
  9061. fn = 'getMessageEnd';break;
  9062. }
  9063. return fn;
  9064. }
  9065. // 切换单据类型
  9066. $scope.setActive = function(state) {
  9067. if($scope.active != state) {
  9068. $scope.active = state;
  9069. if($scope.tableParams.page() == 1)
  9070. $scope.tableParams.reload();
  9071. else
  9072. $scope.tableParams.page(1);
  9073. }
  9074. };
  9075. var getService = function() {
  9076. return AddPartnerMyMessage;
  9077. };
  9078. $scope.tableParams = new ngTableParams({ // ng-Table参数
  9079. page : 1,
  9080. count : 5,
  9081. sorting: {
  9082. }
  9083. }, {
  9084. total : 0,
  9085. counts: [5, 10, 15, 25, 50],
  9086. getData : function($defer, params) { // 获取数据的方法
  9087. $scope.loading = true;
  9088. var pageParams = params.url();
  9089. pageParams.searchFilter = { // 筛选条件
  9090. keyword: $scope.keyword,
  9091. };
  9092. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9093. $scope.loading = false;
  9094. console.log(page);
  9095. if(page) {
  9096. params.total(page.totalElement);
  9097. $defer.resolve(page.content);
  9098. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9099. }
  9100. }, function(response){
  9101. $scope.loading = false;
  9102. toaster.pop('error', '数据加载失败', response.data);
  9103. });
  9104. }
  9105. });
  9106. // 同意申请
  9107. $scope.agree = function(id) {
  9108. AddPartner.agreeRequest({id: id}, {}, function(data) {
  9109. toaster.pop('success', '提示', '操作成功');
  9110. }, function(response) {
  9111. toaster.pop('error', '提示', response.data);
  9112. });
  9113. }
  9114. // 拒绝申请
  9115. $scope.refuse = function(id, reason) {
  9116. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  9117. toaster.pop('success', '提示', '操作成功');
  9118. }, function(response) {
  9119. toaster.pop('error', '提示', response.data);
  9120. });
  9121. }
  9122. $scope.status = 'get';
  9123. }]);
  9124. /**
  9125. * 我的合作伙伴
  9126. */
  9127. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  9128. BaseService.scrollBackToTop();
  9129. // 默认显示合作伙伴
  9130. $scope.status = 'news';
  9131. // 获取所有的合作伙伴
  9132. GetProductInfo.getAllPartners({}, function(data) {
  9133. console.log(data);
  9134. $scope.partners = data;
  9135. }, function(res) {
  9136. toaster.pop('error', '获取列表失败', res.data);
  9137. });
  9138. // 添加为客户
  9139. $scope.addCust = function(partner) {
  9140. GetProductInfo.addCust({}, partner, function(data) {
  9141. toaster.pop('success', '提示', '添加客户成功');
  9142. }, function(response) {
  9143. toaster.pop('error', '添加客户失败', response.data);
  9144. });
  9145. }
  9146. // 添加为供应商
  9147. $scope.addSupplier = function(partner) {
  9148. GetProductInfo.addSupplier({}, partner, function(data) {
  9149. toaster.pop('success', '提示', '添加供应商成功');
  9150. }, function(response) {
  9151. toaster.pop('error', '添加供应商失败', response.data);
  9152. });
  9153. }
  9154. }]);
  9155. /**
  9156. * 财务对账时,企业进行筛选操作
  9157. */
  9158. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  9159. $scope.getData = function(){
  9160. FaApCheck.getAllCustomers(function(data) {
  9161. console.log(data);
  9162. $scope.custs= data;
  9163. angular.forEach($scope.data, function(item) {
  9164. item:{
  9165. $selected: true;
  9166. }
  9167. });
  9168. $scope.loading = false;
  9169. });
  9170. }
  9171. $scope.getData();
  9172. $scope.CustName= function(suuorname) {
  9173. $modalInstance.close(suuorname);
  9174. }
  9175. $scope.close = function() {
  9176. $modalInstance.close();
  9177. }
  9178. }]);
  9179. /**
  9180. * 跳转到企业圈
  9181. */
  9182. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  9183. GetProductInfo.businessGroups({}, function(data) {
  9184. window.open(data.url);
  9185. }, function(response) {
  9186. toaster.pop('error', '提示', response.data);
  9187. });
  9188. }]);
  9189. /**
  9190. * 购物车
  9191. */
  9192. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  9193. BaseService.scrollBackToTop();
  9194. $scope.active = 'all';
  9195. $scope.agreedText = '全部';
  9196. $scope.dateZoneText = '一个月内';
  9197. $scope.condition = {dateZone: 1};
  9198. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9199. $scope.changeAgreed = function(agreed) {
  9200. $scope.condition.agreed = agreed;
  9201. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9202. $scope.condition.$agreedOpen = false;
  9203. };
  9204. $scope.changeDateZone = function(zone) {
  9205. $scope.condition.dateZone = zone;
  9206. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9207. $scope.condition.$dateZoneOpen = false;
  9208. getDateCondition(zone, $scope.condition);
  9209. $scope.tableParams.reload();
  9210. };
  9211. $scope.setActive = function(state) {
  9212. if($scope.active != state) {
  9213. $scope.active = state;
  9214. if($scope.tableParams.page() == 1)
  9215. $scope.tableParams.reload();
  9216. else
  9217. $scope.tableParams.page(1);
  9218. }
  9219. };
  9220. var getService = function() {
  9221. return getCartList;
  9222. };
  9223. $scope.tableParams = new ngTableParams({
  9224. page : 1,
  9225. count : 5,
  9226. sorting: {
  9227. date: 'desc',
  9228. }
  9229. }, {
  9230. total : 0,
  9231. counts: [5, 10, 25, 50],
  9232. getData : function($defer, params) {
  9233. $scope.loading = true;
  9234. var pageParams = params.url();
  9235. pageParams.keyword = $scope.keyword;
  9236. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9237. $scope.loading = false;
  9238. if(page) {
  9239. params.total(page.totalElements);
  9240. $defer.resolve(page.content);
  9241. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9242. }
  9243. }, function(response) {
  9244. $scope.loading = false;
  9245. toaster.pop('error', '数据加载失败', response.data);
  9246. });
  9247. }
  9248. });
  9249. $scope.getCartTotal = function(items) {
  9250. var sum = 0;
  9251. angular.forEach(items, function(item){
  9252. sum += item.qty * item.price;
  9253. });
  9254. return sum;
  9255. };
  9256. // 搜索框回车
  9257. $scope.onSearch = function() {
  9258. $scope.tableParams.page(1);
  9259. $scope.tableParams.reload();
  9260. };
  9261. // 提交
  9262. $scope.addtoOrder = function(id) {
  9263. console.log(id);
  9264. cartOperation.addToOrder({id: id}, {}, function(data) {
  9265. if(data.success) {
  9266. toaster.pop('success', '提示', data.success);
  9267. $timeout(function() {
  9268. window.location.hash = '#/purc/order/'+data.id;
  9269. },500);
  9270. }
  9271. if(data.error) {
  9272. toaster.pop('error', '提示', data.error);
  9273. }
  9274. }, function(response) {
  9275. toaster.pop('erroer', '提示', response.data);
  9276. });
  9277. };
  9278. // 删除一条主记录
  9279. $scope.deleteCart = function(id) {
  9280. cartOperation.deleteCart({id: id}, {}, function(data) {
  9281. if(data.success) {
  9282. toaster.pop('success', '提示', data.success);
  9283. $timeout(function() {
  9284. window.location.reload();
  9285. },500);
  9286. }
  9287. if(data.error) {
  9288. toaster.pop('error', '提示', data.error);
  9289. }
  9290. }, function(response) {
  9291. toaster.pop('erroer', '提示', response.data);
  9292. });
  9293. };
  9294. // 删除一条明细
  9295. $scope.deleteDetail = function(id) {
  9296. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  9297. if(data.success) {
  9298. toaster.pop('success', '提示', data.success);
  9299. $timeout(function() {
  9300. window.location.reload();
  9301. },500);
  9302. }
  9303. if(data.error) {
  9304. toaster.pop('error', '提示', data.error);
  9305. }
  9306. }, function(response) {
  9307. toaster.pop('erroer', '提示', response.data);
  9308. });
  9309. };
  9310. // 清空购物车
  9311. $scope.clearCart = function() {
  9312. cartOperation.deleteCarts({}, function(data) {
  9313. if(data.success) {
  9314. toaster.pop('success', '提示', data.success);
  9315. $timeout(function() {
  9316. window.location.reload();
  9317. },500);
  9318. }
  9319. if(data.error) {
  9320. toaster.pop('error', '提示', data.error);
  9321. }
  9322. }, function(response) {
  9323. toaster.pop('erroer', '提示', response.data);
  9324. });
  9325. }
  9326. }]);
  9327. /**
  9328. * 购物车详情
  9329. */
  9330. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  9331. BaseService.scrollBackToTop();
  9332. var loadData = function() {
  9333. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  9334. if(data.code) {
  9335. $scope.cart = data;
  9336. var sum = 0;
  9337. angular.forEach($scope.cart.cartDetails, function(item) {
  9338. sum += item.qty * item.price;
  9339. });
  9340. $scope.cart.total = sum;
  9341. $scope.loading = false;
  9342. } else {
  9343. window.location.hash = '#/purc/cart';
  9344. }
  9345. });
  9346. };
  9347. loadData();
  9348. // 删除一条明细
  9349. $scope.deleteDetail = function(id) {
  9350. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  9351. if(data.success) {
  9352. toaster.pop('success', '提示', data.success);
  9353. $timeout(function() {
  9354. window.location.reload();
  9355. },500);
  9356. }
  9357. if(data.error) {
  9358. toaster.pop('error', '提示', data.error);
  9359. }
  9360. }, function(response) {
  9361. toaster.pop('erroer', '提示', response.data);
  9362. });
  9363. };
  9364. // 删除一条主记录
  9365. $scope.deleteCart = function(id) {
  9366. cartOperation.deleteCart({id: id}, {}, function(data) {
  9367. if(data.success) {
  9368. toaster.pop('success', '提示', data.success);
  9369. $timeout(function() {
  9370. window.location.reload();
  9371. },500);
  9372. }
  9373. if(data.error) {
  9374. toaster.pop('error', '提示', data.error);
  9375. }
  9376. }, function(response) {
  9377. toaster.pop('erroer', '提示', response.data);
  9378. });
  9379. };
  9380. // 提交
  9381. $scope.addtoOrder = function(id) {
  9382. console.log(id);
  9383. cartOperation.addToOrder({id: id}, {}, function(data) {
  9384. if(data.success) {
  9385. toaster.pop('success', '提示', data.success);
  9386. $timeout(function() {
  9387. window.location.hash = '#/purc/order/'+data.id;
  9388. },500);
  9389. }
  9390. if(data.error) {
  9391. toaster.pop('error', '提示', data.error);
  9392. }
  9393. }, function(response) {
  9394. toaster.pop('erroer', '提示', response.data);
  9395. });
  9396. };
  9397. }]);
  9398. /**
  9399. * 审批流
  9400. */
  9401. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  9402. BaseService.scrollBackToTop();
  9403. $scope.vacation = false;
  9404. $scope.workovertime = false;
  9405. $scope.workdaily = false;
  9406. $scope.feeplease = false;
  9407. $scope.signapp = false;
  9408. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  9409. $scope.nodes = data;
  9410. angular.forEach($scope.nodes, function(node) {
  9411. if(node.appname = '请假单') {
  9412. $scope.vacation = true;
  9413. }
  9414. if(node.appname = '加班单') {
  9415. $scope.workovertime = true;
  9416. }
  9417. if(node.appname = '工作日报') {
  9418. $scope.workdaily = true;
  9419. }
  9420. if(node.appname = '出差单') {
  9421. $scope.feeplease = true;
  9422. }
  9423. if(node.appname = '申诉单') {
  9424. $scope.signapp = true;
  9425. }
  9426. });
  9427. }, function(response) {
  9428. });
  9429. $scope.NoteSet = function() {
  9430. var modalInstance = $modal.open({
  9431. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9432. controller: 'NoteStep1Ctrl',
  9433. size: 'lg',
  9434. resolve: {
  9435. AppName: function() {
  9436. return '请假单';
  9437. }
  9438. }
  9439. });
  9440. modalInstance.result.then(function(data) {
  9441. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9442. if(data.error) {
  9443. toaster.pop('error', '提示', data.error);
  9444. }
  9445. if(data.success) {
  9446. toaster.pop('success', '提示', data.success);
  9447. }
  9448. }, function(response) {
  9449. });
  9450. }, function(){
  9451. });
  9452. }
  9453. $scope.overTimeSet = function() {
  9454. var modalInstance = $modal.open({
  9455. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9456. controller: 'NoteStep1Ctrl',
  9457. size: 'lg',
  9458. resolve: {
  9459. AppName: function() {
  9460. return '加班单';
  9461. }
  9462. }
  9463. });
  9464. modalInstance.result.then(function(data) {
  9465. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9466. if(data.error) {
  9467. toaster.pop('error', '提示', data.error);
  9468. }
  9469. if(data.success) {
  9470. toaster.pop('success', '提示', data.success);
  9471. }
  9472. }, function(response) {
  9473. });
  9474. }, function(){
  9475. });
  9476. }
  9477. $scope.feePleaseSet = function() {
  9478. var modalInstance = $modal.open({
  9479. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9480. controller: 'NoteStep1Ctrl',
  9481. size: 'lg',
  9482. resolve: {
  9483. AppName: function() {
  9484. return '出差单';
  9485. }
  9486. }
  9487. });
  9488. modalInstance.result.then(function(data) {
  9489. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9490. if(data.error) {
  9491. toaster.pop('error', '提示', data.error);
  9492. }
  9493. if(data.success) {
  9494. toaster.pop('success', '提示', data.success);
  9495. }
  9496. }, function(response) {
  9497. });
  9498. }, function(){
  9499. });
  9500. }
  9501. $scope.workDailySet = function() {
  9502. var modalInstance = $modal.open({
  9503. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9504. controller: 'NoteStep1Ctrl',
  9505. size: 'lg',
  9506. resolve: {
  9507. AppName: function() {
  9508. return '工作日报';
  9509. }
  9510. }
  9511. });
  9512. modalInstance.result.then(function(data) {
  9513. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9514. if(data.error) {
  9515. toaster.pop('error', '提示', data.error);
  9516. }
  9517. if(data.success) {
  9518. toaster.pop('success', '提示', data.success);
  9519. }
  9520. }, function(response) {
  9521. });
  9522. }, function(){
  9523. });
  9524. }
  9525. $scope.signAppSet = function() {
  9526. var modalInstance = $modal.open({
  9527. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9528. controller: 'NoteStep1Ctrl',
  9529. size: 'lg',
  9530. resolve: {
  9531. AppName: function() {
  9532. return '申诉单';
  9533. }
  9534. }
  9535. });
  9536. modalInstance.result.then(function(data) {
  9537. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9538. if(data.error) {
  9539. toaster.pop('error', '提示', data.error);
  9540. }
  9541. if(data.success) {
  9542. toaster.pop('success', '提示', data.success);
  9543. }
  9544. }, function(response) {
  9545. });
  9546. }, function(){
  9547. });
  9548. }
  9549. }]);
  9550. /**
  9551. * 审核条件设置
  9552. */
  9553. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  9554. $scope.appName = AppName;// 标题名称
  9555. $scope.AppFlow = {appName: $scope.appName,
  9556. appNodes:{}};
  9557. $scope.AppFlow.appNodes = [];
  9558. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  9559. if(data.appNodes.length != 0) {
  9560. $scope.node = data;
  9561. $scope.AppFlow = data;
  9562. }
  9563. }, function() {
  9564. });
  9565. $scope.copy = function() {//复制
  9566. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  9567. toaster.pop('info', '提示', '复制成功');
  9568. $modalInstance.dismiss();
  9569. }
  9570. $scope.paste = function() {
  9571. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  9572. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  9573. }
  9574. $scope.clear = function() {// 清空
  9575. $scope.AppFlow = {appName: $scope.appName,
  9576. appNodes:{}};
  9577. $scope.AppFlow.appNodes = [];
  9578. }
  9579. appFlow.getPositions({}, function(data) {// 获取人员信息
  9580. $scope.users = data;
  9581. }, function(response) {
  9582. });
  9583. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  9584. $scope.roles = data;
  9585. },function(response) {
  9586. });
  9587. $scope.SelectUser = function(data) { // 添加人员
  9588. var item = {
  9589. useruu: null,
  9590. username: null,
  9591. level: null
  9592. };
  9593. item.useruu = data.useruu;
  9594. item.username = data.username;
  9595. // if($scope.AppFlow.appNodes.length != 0){
  9596. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  9597. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  9598. // toaster.pop('info', '提示', '不能重复添加');
  9599. // } else {
  9600. // $scope.AppFlow.appNodes.push(item);
  9601. // }
  9602. // }
  9603. // } else {
  9604. $scope.AppFlow.appNodes.push(item);
  9605. // }
  9606. }
  9607. $scope.SelectRole = function(data) {// 添加职位
  9608. var item = {
  9609. position: null,
  9610. level: null
  9611. };
  9612. item.position = data;
  9613. $scope.AppFlow.appNodes.push(item);
  9614. }
  9615. $scope.deleteNode = function(index) {// 删除节点
  9616. $scope.AppFlow.appNodes.splice(index, 1);
  9617. };
  9618. $scope.saveNode = function() { // 保存
  9619. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  9620. $scope.AppFlow.appNodes[key].level = key;
  9621. });
  9622. if($scope.AppFlow.appNodes.length == 0) {
  9623. toaster.pop('info', '提示', '您还未设置审批人');
  9624. } else {
  9625. $modalInstance.close($scope.AppFlow);
  9626. };
  9627. };
  9628. $scope.cancel = function() {// 取消
  9629. $modalInstance.dismiss();
  9630. }
  9631. }]);
  9632. /***
  9633. * 代采定单
  9634. */
  9635. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  9636. BaseService.scrollBackToTop();
  9637. $scope.active = 'all';
  9638. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9639. $scope.total = null;
  9640. $scope.setActive = function(state) {
  9641. if($scope.active != state) {
  9642. $scope.active = state;
  9643. if($scope.tableParams.page() == 1)
  9644. $scope.tableParams.reload();
  9645. else
  9646. $scope.tableParams.page(1);
  9647. }
  9648. };
  9649. $scope.tableParams = new ngTableParams({
  9650. page : 1,
  9651. count : 5,
  9652. sorting: {
  9653. }
  9654. }, {
  9655. total : 0,
  9656. counts: [5, 10, 25, 50],
  9657. getData : function($defer, params) {
  9658. $scope.loading = true;
  9659. var pageParams = params.url();
  9660. pageParams.keyword = $scope.keyword;
  9661. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9662. $scope.loading = false;
  9663. if(page) {
  9664. params.total(page.totalElements);
  9665. $scope.total = page.totalElement;
  9666. $defer.resolve(page.content);
  9667. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9668. }
  9669. }, function(response) {
  9670. $scope.loading = false;
  9671. toaster.pop('error', '数据加载失败', response.data);
  9672. });
  9673. }
  9674. });
  9675. //打印
  9676. $scope.print = function(deputyOrder) {
  9677. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  9678. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  9679. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  9680. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  9681. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  9682. //TODO 目前只有信扬有代采业务,先写死之后再改
  9683. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  9684. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  9685. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  9686. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  9687. };
  9688. // 搜索框回车
  9689. $scope.onSearch = function() {
  9690. $scope.tableParams.page(1);
  9691. $scope.tableParams.reload();
  9692. };
  9693. }]);
  9694. /**
  9695. * 新增代采订单
  9696. */
  9697. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  9698. BaseService.scrollBackToTop();
  9699. // 费率
  9700. DeputyOrder.vendorRate({}, function(data) {
  9701. $scope.rate = data;
  9702. }, function(response){
  9703. });
  9704. $scope.deOrder = {
  9705. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  9706. entrydate: new Date(),
  9707. status: '在录入',
  9708. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  9709. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  9710. riskmethod: '甲方承担',
  9711. taxpaymentmethod: '甲方承担',
  9712. totalamount: 0,
  9713. totalpayament: 0,
  9714. orderamount: 0,
  9715. usdpayment: 0
  9716. };
  9717. $scope.deOrder.deputyOrderItems = [];
  9718. var item = {
  9719. prodname: null,
  9720. prodcode: null,
  9721. prodspec: null,
  9722. amount: null,
  9723. unitprice: null,
  9724. remark: null,
  9725. orderprice: null,
  9726. };
  9727. $scope.deOrder.deputyOrderItems.push(item);
  9728. //增加商品
  9729. $scope.add = function(index) {
  9730. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  9731. toaster.pop('info', '提示', '请先填写商品信息');
  9732. }else {
  9733. $scope.deOrder.deputyOrderItems.push(
  9734. { prodname: null,
  9735. prodcode: null,
  9736. prodspec: null,
  9737. amount: null,
  9738. unitprice: null,
  9739. remark: null,
  9740. orderprice: null});
  9741. }
  9742. };
  9743. //删除商品
  9744. $scope.del = function(index) {
  9745. $scope.deOrder.deputyOrderItems.splice(index, 1);
  9746. };
  9747. $scope.uplodaByBatch = function() {
  9748. var modalInstance = $modal.open({
  9749. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  9750. controller: 'DeputyOrderUploadCtrl',
  9751. size: 'lg',
  9752. resolve: {
  9753. }
  9754. });
  9755. modalInstance.result.then(function(data) {
  9756. angular.forEach(data, function(data) {
  9757. $scope.deOrder.deputyOrderItems.push(data);
  9758. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  9759. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  9760. $scope.deOrder.deputyOrderItems.splice(i, 1);
  9761. }
  9762. }
  9763. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  9764. $scope.deOrder.totalamount += item.amount * item.unitprice;
  9765. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  9766. $scope.deOrder.orderamount += item.amount * item.purcprice;
  9767. });
  9768. })
  9769. }, function(){
  9770. });
  9771. }
  9772. $scope.save = function() {
  9773. $scope.deOrder.entrystatus = '保存';
  9774. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  9775. $scope.deOrder.totalamount += item.amount * item.unitprice;
  9776. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  9777. });
  9778. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  9779. if(data.id) {
  9780. window.location.hash = "#/purc/deputy/"+data.id;
  9781. }
  9782. if(data.error) {
  9783. toaster.pop('error', '提示', '保存失败');
  9784. }
  9785. }, function(response) {
  9786. });
  9787. }
  9788. $scope.submit = function() {
  9789. $scope.deOrder.entrystatus = '已提交';
  9790. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  9791. $scope.deOrder.totalamount += item.amount * item.unitprice;
  9792. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  9793. });
  9794. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  9795. if(data.id) {
  9796. window.location.hash = "#/purc/deputy/"+data.id;
  9797. }
  9798. if(data.error) {
  9799. toaster.pop('error', '提示', '保存失败');
  9800. }
  9801. }, function(response) {
  9802. });
  9803. }
  9804. $scope.openDatePicker = function($event, deOrder, openParam) {
  9805. $event.preventDefault();
  9806. $event.stopPropagation();
  9807. deOrder[openParam] = !deOrder[openParam];
  9808. };
  9809. }]);
  9810. /**
  9811. * 代采订单批量导入
  9812. */
  9813. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  9814. // 通过excel批量上传物料
  9815. $scope.result = null;
  9816. $scope.upload = function() {
  9817. var file = $scope.myFiles[0];
  9818. $upload.upload({
  9819. url: 'deputyOrder/release/excel',
  9820. file: file,
  9821. method: 'POST'
  9822. }).success(function(data) {
  9823. $scope.result = data;
  9824. $scope.success = $scope.result.success;
  9825. $scope.total = $scope.result.total;
  9826. $scope.alters = $scope.result.alters;
  9827. }).error(function(response) {
  9828. toaster.pop('error', response.data || response);
  9829. });
  9830. };
  9831. // 查看范例
  9832. $scope.showImg = function() {
  9833. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  9834. box.show();
  9835. box.find('img').attr('src', src);
  9836. box.find('a').click(function(){
  9837. box.hide();
  9838. });
  9839. box.dblclick(function(){
  9840. box.hide();
  9841. });
  9842. };
  9843. // 下载模板
  9844. $scope.download = function() {
  9845. window.location.href = 'deputyOrder/upload/template';
  9846. };
  9847. $scope.enSure = function() {
  9848. $modalInstance.close($scope.result.items);
  9849. }
  9850. $scope.cancel = function() {
  9851. $modalInstance.dismiss();
  9852. }
  9853. }]);
  9854. /**
  9855. * 代采详情
  9856. */
  9857. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService) {
  9858. BaseService.scrollBackToTop();
  9859. var loadData = function() {
  9860. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  9861. $scope.deOrder = data;
  9862. $scope.deOrder.$editing = false;
  9863. });
  9864. };
  9865. loadData();
  9866. var getService = function() {
  9867. return DeputyOrder.getProdList;
  9868. };
  9869. $scope.update = function() {
  9870. $scope.deOrder.$editing = true;
  9871. }
  9872. $scope.cancel = function() {
  9873. $scope.deOrder.$editing = false;
  9874. }
  9875. $scope.submit = function() {
  9876. $scope.deOrder.entrystatus = '已提交';
  9877. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  9878. if(data.id) {
  9879. window.location.hash = "#/purc/deputy/"+data.id;
  9880. }
  9881. if(data.error) {
  9882. toaster.pop('error', '提示', '保存失败');
  9883. }
  9884. }, function(response) {
  9885. });
  9886. }
  9887. $scope.openDatePicker = function($event, deOrder, openParam) {
  9888. $event.preventDefault();
  9889. $event.stopPropagation();
  9890. deOrder[openParam] = !deOrder[openParam];
  9891. };
  9892. }]);
  9893. /**
  9894. * 招标单
  9895. */
  9896. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  9897. BaseService.scrollBackToTop();
  9898. $scope.active = 'done';
  9899. $scope.setActive = function(state) {
  9900. if($scope.active != state) {
  9901. $scope.active = state;
  9902. if($scope.tableParams.page() == 1)
  9903. $scope.tableParams.reload();
  9904. else
  9905. $scope.tableParams.page(1);
  9906. }
  9907. };
  9908. var getTenderStatus = function(active) {
  9909. var fn = 'getMyAll';
  9910. switch(active) {
  9911. case 'done':
  9912. fn = 'getMyDone';break;
  9913. case 'todo':
  9914. fn = 'getMyTodo';break;
  9915. // case 'end':
  9916. // fn = 'getMyEnd';break;
  9917. case 'waiting':
  9918. fn = 'getMyWaiting';break;
  9919. }
  9920. return fn;
  9921. }
  9922. $scope.tableParams = new ngTableParams({
  9923. page : 1,
  9924. count : 5,
  9925. sorting: {
  9926. 'tender.endDate': 'desc',
  9927. 'tender.enterprise.enName': 'asc',
  9928. 'tender.code': 'asc'
  9929. }
  9930. }, {
  9931. total : 0,
  9932. counts: [5, 10, 25, 50],
  9933. getData : function($defer, params) {
  9934. $scope.loading = true;
  9935. var pageParams = params.url();
  9936. var realActive = {};
  9937. pageParams.searchFilter = { // 筛选条件
  9938. keyword: $scope.keyword
  9939. // fromDate: getDateTime($scope.condition.dateFrom),
  9940. // endDate: getDateTime($scope.condition.dateTo)
  9941. };
  9942. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9943. $scope.loading = false;
  9944. if(page) {
  9945. params.total(page.totalElement);
  9946. $defer.resolve(page.content);
  9947. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  9948. }
  9949. }, function(response){
  9950. $scope.loading = false;
  9951. toaster.pop('error', '数据加载失败', response.data);
  9952. });
  9953. }
  9954. });
  9955. // 搜索框回车
  9956. $scope.onSearch = function() {
  9957. $scope.tableParams.page(1);
  9958. $scope.tableParams.reload();
  9959. };
  9960. }]);
  9961. /**
  9962. * 新增招标单
  9963. */
  9964. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'ShipAddress', '$http', 'AuthenticationService', 'KindAPI', 'BrandActiveAPI', 'Search', 'ComponentActiveAPI',function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, ShipAddress, $http, AuthenticationService, KindAPI, BrandActiveAPI, Search, ComponentActiveAPI) {
  9965. // 录入人
  9966. AuthenticationService.getAuthentication().success(function(data) {
  9967. $scope.user = data;
  9968. });
  9969. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9970. $scope.loading = false;
  9971. // 获取收货地址列表
  9972. ShipAddress.shipAddList({}, function(data) {
  9973. $scope.ships = data;
  9974. $scope.tender.shipadd = $scope.ships[0];
  9975. });
  9976. // 获取地址信息
  9977. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  9978. }).then(function(response) {
  9979. $scope.provinces = response.data;
  9980. });
  9981. // 新增收货地址保存
  9982. $scope.saveShipAddress = function(ship) {
  9983. ship.address = ship.province + ship.city + ship.district;
  9984. ShipAddress.saveAddress( {}, ship, function(data) {
  9985. if(data.success) {
  9986. // 获取收货地址列表
  9987. ShipAddress.shipAddList({}, function(data) {
  9988. $scope.ships = data;
  9989. $scope.tender.shipadd = $scope.ships[0];
  9990. });
  9991. toaster.pop('success', '提示', data.success);
  9992. }
  9993. if(data.error) {
  9994. toaster.pop('error', '提示', data.error);
  9995. }
  9996. });
  9997. };
  9998. // 可选的证照要求
  9999. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  10000. // 处理证照要求
  10001. var parseCertificate = function(a) {
  10002. if (a) {
  10003. var arr = a.split(',');
  10004. angular.forEach(arr, function(app) {
  10005. var contained = false;
  10006. angular.forEach($scope.certificates, function($app) {
  10007. if($app.name == app) {
  10008. $app.checked = true;
  10009. contained = true;
  10010. }
  10011. });
  10012. if(!contained) {
  10013. $scope.certificates.push({name: app, checked: true});
  10014. }
  10015. });
  10016. }
  10017. };
  10018. // 联想词start
  10019. // 获取品牌联想词
  10020. $scope.getSimilarBrands = function(value) {
  10021. if (value) {
  10022. // 获取品牌联想词
  10023. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  10024. return data.map(function(item) {
  10025. return item;
  10026. });
  10027. });
  10028. }
  10029. };
  10030. // 获取产品型号联想词
  10031. $scope.getSimilarCodes = function(value) {
  10032. if (value) {
  10033. // 获取产品型号联想词
  10034. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  10035. return data.map(function (item) {
  10036. return item;
  10037. })
  10038. });
  10039. }
  10040. };
  10041. // // 获取产品类目联想词
  10042. // $scope.getSimilarKinds = function(value) {
  10043. // if (value) {
  10044. // // getSimilarLeafKinds 根据类目名获取末级联想词
  10045. // // 获取类目联想词
  10046. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  10047. // return data.map(function(item) {
  10048. // return item;
  10049. // })
  10050. // });
  10051. // }
  10052. // };
  10053. // // 点击联想词获取类目信息
  10054. // $scope.onAssociateKindClick = function(kind, submit) {
  10055. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  10056. // $scope.actives = data;
  10057. // console.log(data);
  10058. // var size = data.length;
  10059. // if (size > 0) {
  10060. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  10061. // submit.kiName = submit.gradeOneKiName;
  10062. // if (size > 1) {
  10063. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  10064. // submit.kiName = submit.gradeTwoKiName;
  10065. // if (kind.level < 3) {
  10066. // submit.gradeThreeKiName = null;
  10067. // } else if (size > 2) {
  10068. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  10069. // submit.kiName = submit.gradeThreeKiName;
  10070. // }
  10071. // }
  10072. // }
  10073. // console.log(submit);
  10074. // })
  10075. // };
  10076. // 选择类目
  10077. $scope.selectKind = function(prod) {
  10078. var submit = [];
  10079. $modal.open({
  10080. animation: true,
  10081. size: 'lg',
  10082. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  10083. controller: 'ProdKindChooseCtrl',
  10084. resolve: {
  10085. actives: function() {
  10086. return $scope.actives;
  10087. }
  10088. }
  10089. }).result.then(function(data){
  10090. $scope.actives = data.actives;
  10091. var size = data.actives.length;
  10092. submit.gradeOneKiName = '';
  10093. submit.gradeTwoKiName = '';
  10094. submit.gradeThreeKiName = '';
  10095. if (size > 0) {
  10096. submit.gradeOneKiName = $scope.actives[0].nameCn;
  10097. prod.prodTitle = submit.gradeOneKiName;
  10098. if (size > 1) {
  10099. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  10100. prod.prodTitle = submit.gradeTwoKiName;
  10101. if (size > 2) {
  10102. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  10103. prod.prodTitle = submit.gradeThreeKiName;
  10104. }
  10105. }
  10106. }
  10107. }, function(){
  10108. });
  10109. };
  10110. // // 验证分类信息
  10111. // $scope.checkKind = function() {
  10112. // setTimeout(function() {
  10113. // if($scope.activesString == null) {
  10114. // $scope.component.kindid = null;
  10115. // return;
  10116. // }
  10117. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  10118. // $scope.component.kind = kind;
  10119. // $scope.component.kindid = kind.id;
  10120. // $scope.activesString = $scope.component.kind.nameCn;
  10121. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  10122. // $scope.kindProperties = data;
  10123. // angular.forEach($scope.kindProperties, function(kp) {
  10124. // angular.forEach($scope.component.properties, function(pro) {
  10125. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  10126. // kp.value = pro.value;
  10127. // }
  10128. // });
  10129. // });
  10130. // }, function(response) {
  10131. // });
  10132. // }, function (response) {
  10133. // $scope.component.kindid = null;
  10134. // toaster.pop('error', response.data);
  10135. // });
  10136. // }, 500);
  10137. // };
  10138. // 点击联想词获取品牌信息
  10139. $scope.onAssociateBrandClick = function(brand, prod) {
  10140. // $scope.component.brand = brand;
  10141. // $scope.component.brandid = brand.id;
  10142. prod.brand = brand;
  10143. };
  10144. // 打开品牌选择的模态框
  10145. $scope.selectBrand = function(prod){ //打开模态
  10146. var modalInstance = $modal.open({
  10147. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  10148. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  10149. });
  10150. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  10151. });
  10152. modalInstance.result.then(function(brand){
  10153. console.log(brand);
  10154. prod.brand = brand.nameCn;
  10155. }, function(reason){
  10156. });
  10157. };
  10158. // // 验证品牌是否正确
  10159. // $scope.checkBrand = function () {
  10160. // setTimeout(function () {
  10161. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  10162. // // $scope.component.brand = brand;
  10163. // // $scope.component.brandid = brand.id;
  10164. // }, function (response) {
  10165. // // $scope.component.brandid = null;
  10166. // toaster.pop('error', response.data);
  10167. // })
  10168. // } , 500);
  10169. // };
  10170. // 点击联想词获取器件信息 带入产品分类和品牌
  10171. $scope.onAssociateCmpClick = function(cmp, prod) {
  10172. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  10173. $scope.component = data;
  10174. prod.prodCode = data.code;
  10175. prod.prodTitle = data.kind.nameCn;
  10176. prod.brand = data.brand.nameCn;
  10177. }, function(res) {
  10178. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  10179. })
  10180. };
  10181. //联想词end
  10182. $scope.condition = {dateZone: 1};
  10183. $scope.tenderProd = [];
  10184. var prod = {
  10185. prodTitle: null,
  10186. prodCode: null,
  10187. brand: null,
  10188. unit: 'PCS',
  10189. qty: null
  10190. // 供应商企业信息
  10191. // enterpriseBaseInfo: [{}]
  10192. };
  10193. $scope.tender = {
  10194. date: new Date(),
  10195. unit: 'PCS',
  10196. currency: 'RMB',
  10197. ifOpen: 0,
  10198. ifTax: 1,
  10199. invoiceType: 2,
  10200. tenderAttachs:[{}]
  10201. };
  10202. //
  10203. $scope.tenderProd.push(prod);
  10204. //增加商品
  10205. $scope.add = function(index) {
  10206. $scope.tenderProd.push({
  10207. prodTitle: null,
  10208. prodCode: null,
  10209. brand: null,
  10210. unit: 'PCS',
  10211. qty: null
  10212. // 供应商企业信息
  10213. // enterpriseBaseInfo: [{}]
  10214. });
  10215. };
  10216. //删除商品
  10217. $scope.del = function(index) {
  10218. $scope.tenderProd.splice(index, 1);
  10219. };
  10220. // 批量导入
  10221. $scope.uplodaByBatch = function() {
  10222. var modalInstance = $modal.open({
  10223. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  10224. controller: 'PurcTenderUploadCtrl',
  10225. size: 'lg',
  10226. resolve: {
  10227. }
  10228. });
  10229. modalInstance.result.then(function(data) {
  10230. // 获取上传的产品明细,前台展示
  10231. angular.forEach(data, function(data) {
  10232. $scope.tenderProd.push(data);
  10233. for(var i = 0; i < $scope.tenderProd.length; i++) {
  10234. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  10235. $scope.tenderProd.splice(i, 1);
  10236. console.log($scope.tenderProd);
  10237. }
  10238. }
  10239. });
  10240. }, function(){
  10241. });
  10242. };
  10243. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  10244. if( ! angular.isUndefined($stateParams.id)) {
  10245. $scope.loading = true;
  10246. PurcTender.getOne({id: $stateParams.id}, function(data){
  10247. data.$editing = false;
  10248. $scope.tender = data;
  10249. $scope.tenderProd = data.purchaseTenderProds;
  10250. parseCertificate($scope.tender.certificate);
  10251. $scope.firstProd = data.purchaseTenderProds[0];
  10252. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  10253. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  10254. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10255. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  10256. } else {
  10257. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  10258. }
  10259. });
  10260. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  10261. console.log($scope.tenderProd.enterpriseBaseInfo);
  10262. $scope.loading = false;
  10263. $scope.attaches = $scope.tender.tenderAttaches;
  10264. }, function(response){
  10265. $scope.loading = false;
  10266. toaster.pop('error', '数据加载失败', response.data);
  10267. });
  10268. }
  10269. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  10270. $rootScope.tenderVendor = [{}];
  10271. }
  10272. $scope.changeShipAddress = false;
  10273. $scope.changeAddress = function() {
  10274. if ($scope.changeShipAddress) {
  10275. $scope.changeShipAddress = false;
  10276. } else {
  10277. $scope.changeShipAddress = true;
  10278. }
  10279. };
  10280. // $scope.validateNumber = function (value) { // 采购数量 正整数
  10281. // var regex = /^\+?[1-9][0-9]*$/;
  10282. // if (!regex.test(value) || value === 0 || value === null) {
  10283. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  10284. // }
  10285. // };
  10286. $scope.removeChecked = function() {
  10287. if ($scope.tenderProd.enterpriseBaseInfo.length > 0) {
  10288. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10289. }
  10290. };
  10291. // 查找供应商
  10292. $scope.dbfindVendor = function(){
  10293. var modalInstance = $modal.open({
  10294. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  10295. controller: 'DbfindVendorCtrl',
  10296. size: 'lg',
  10297. resolve: {
  10298. }
  10299. });
  10300. var ifPush = true;
  10301. modalInstance.result.then(function(data){
  10302. angular.forEach(data, function(vendor) {
  10303. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  10304. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10305. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  10306. } else {
  10307. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  10308. ifPush = true;
  10309. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  10310. ifPush = false;
  10311. break; // 判定到已存在供应商,就终止循环。
  10312. }
  10313. }
  10314. if (ifPush) {
  10315. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  10316. }
  10317. }
  10318. });
  10319. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  10320. }, function(){
  10321. });
  10322. };
  10323. // 删除一个供应商
  10324. $scope.removeVendor = function(index) {
  10325. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  10326. };
  10327. // 删除供应商时,后台删除投标单
  10328. $scope.removeSaleTender = function (tender, vendUU) {
  10329. PurcTender.removeSaleTender ({}, {tender : tender, vendUU : vendUU}, function(data) {
  10330. }, function(response) {
  10331. toaster.pop('error', '提示', response.data);
  10332. });
  10333. };
  10334. // 删除产品明细时,后台删除产品明细
  10335. $scope.deleteProd = function (tenderProdId) {
  10336. PurcTender.deleteProd ({}, {tenderProdId : tenderProdId}, function(data) {
  10337. }, function(response) {
  10338. toaster.pop('error', '提示', response.data);
  10339. });
  10340. };
  10341. // // 查找客户物料
  10342. // $scope.dbfindCustProd = function(){
  10343. // if($scope.item.$editing) {
  10344. // if($scope.item.quotation.cust.uu) {
  10345. // var modalInstance = $modal.open({
  10346. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  10347. // controller: 'DbfindCustProdCtrl',
  10348. // size: 'lg',
  10349. // resolve: {
  10350. // custUU: function(){return $scope.item.quotation.cust.uu}
  10351. // }
  10352. // });
  10353. //
  10354. // modalInstance.result.then(function(data){
  10355. // $scope.item.product = data;
  10356. // }, function(){
  10357. //
  10358. // });
  10359. // } else {
  10360. // toaster.pop('error', '错误', '请先选择客户');
  10361. // }
  10362. // }
  10363. // };
  10364. if (!$scope.attaches) {
  10365. $scope.attaches = []; // 存放上传了的附件
  10366. }
  10367. $scope.upload = function(myFile) { // 上传附件
  10368. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  10369. $upload.upload({
  10370. url: 'tender/addTenderAttach',
  10371. file: file,
  10372. method: 'POST'
  10373. // data: {
  10374. // tender: $scope.tender
  10375. // }
  10376. }).success(function (attach) {
  10377. $scope.attaches.push(attach);
  10378. });
  10379. };
  10380. $scope.removeAttach = function(id, index) {
  10381. $scope.attaches.splice(index, 1);
  10382. PurcTender.removeAttach({attachId:id}, function() {
  10383. });
  10384. };
  10385. var sleep = function (d){
  10386. for(var t = Date.now();Date.now() - t <= d;);
  10387. };
  10388. // 保存和发布招标单
  10389. $scope.save = function(isPublish){
  10390. if (!$scope.tender.ifOpen && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  10391. toaster.pop('info','提示','请先指定供应商');
  10392. } else {
  10393. $scope.loading = true;
  10394. // --组装证照要求
  10395. var myCertificate = [];
  10396. angular.forEach($scope.certificates, function(certificate) {
  10397. if (certificate.checked) {
  10398. myCertificate.push(certificate.name);
  10399. }
  10400. });
  10401. $scope.tender.certificate = myCertificate.join(',');
  10402. if(!$scope.tender.code) { //新增,设单号
  10403. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  10404. }
  10405. if($scope.tender.date instanceof Date) {
  10406. $scope.tender.date = $scope.tender.date.getTime();
  10407. }
  10408. if($scope.tender.endDate instanceof Date) {
  10409. $scope.tender.endDate = $scope.tender.endDate.getTime();
  10410. }
  10411. if($scope.tender.publishDate instanceof Date) {
  10412. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  10413. }
  10414. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  10415. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  10416. $scope.tender.purchaseTenderProds[i].index = i + 1;
  10417. }
  10418. $scope.tender.tenderAttaches = $scope.attaches;
  10419. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  10420. console.log($scope.tender.shipAddress);
  10421. var vendorUUs = [];
  10422. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  10423. vendorUUs.push(enterpriseBaseInfo.uu);
  10424. });
  10425. if (isPublish) { // 发布
  10426. toaster.pop('info', '提示', '正在发布,请稍候');
  10427. PurcTender.publish({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data){
  10428. sleep(1500); //当前方法暂停1.5秒
  10429. $scope.loading = false;
  10430. toaster.pop('success', '成功', '发布成功');
  10431. window.location.hash = '#/purc/tender';
  10432. }, function(response){
  10433. $scope.loading = false;
  10434. toaster.pop('error', '发布失败', response.data);
  10435. });
  10436. } else { // 保存
  10437. toaster.pop('info', '提示', '正在保存,请稍候');
  10438. PurcTender.save({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data) {
  10439. $scope.loading = false;
  10440. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  10441. toaster.pop('success', '成功', '保存成功');
  10442. window.location.hash = '#/purc/tender';
  10443. }, function(response){
  10444. $scope.loading = false;
  10445. toaster.pop('error', '保存失败', response.data);
  10446. });
  10447. }
  10448. }
  10449. };
  10450. // 删除(在录入状态)
  10451. $scope.deleteThis = function(id) {
  10452. PurcTender.deleteOne({}, id, function() {
  10453. toaster.pop('info', '提示', '删除成功');
  10454. window.location.hash = '#/purc/tender';
  10455. });
  10456. };
  10457. // 更新和发布(在录入状态)
  10458. $scope.updateSaved = function(isPublish){
  10459. if (!$scope.tender.ifOpen && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  10460. toaster.pop('info','提示','请先指定供应商');
  10461. } else {
  10462. $scope.loading = true;
  10463. // --组装证照要求
  10464. var myCertificate = [];
  10465. angular.forEach($scope.certificates, function(certificate) {
  10466. if (certificate.checked) {
  10467. myCertificate.push(certificate.name);
  10468. }
  10469. });
  10470. $scope.tender.certificate = myCertificate.join(',');
  10471. if($scope.tender.endDate instanceof Date) {
  10472. $scope.tender.endDate = $scope.tender.endDate.getTime();
  10473. }
  10474. if($scope.tender.publishDate instanceof Date) {
  10475. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  10476. }
  10477. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  10478. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  10479. $scope.tender.purchaseTenderProds[i].index = i + 1;
  10480. }
  10481. $scope.tender.tenderAttaches = $scope.attaches;
  10482. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  10483. var vendorUUs = [];
  10484. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  10485. vendorUUs.push(enterpriseBaseInfo.uu);
  10486. });
  10487. if (isPublish) { // 发布
  10488. toaster.pop('info', '提示', '正在发布,请稍候');
  10489. PurcTender.publishSaved({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data){
  10490. sleep(1500); //当前方法暂停1.5秒
  10491. $scope.loading = false;
  10492. toaster.pop('success', '成功', '发布成功');
  10493. window.location.hash = '#/purc/tender';
  10494. }, function(response){
  10495. $scope.loading = false;
  10496. toaster.pop('error', '发布失败', response.data);
  10497. });
  10498. } else { // 保存
  10499. toaster.pop('info', '提示', '正在保存,请稍候');
  10500. PurcTender.updateSaved({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data) {
  10501. $scope.loading = false;
  10502. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  10503. toaster.pop('success', '成功', '保存成功');
  10504. window.location.hash = '#/purc/tender';
  10505. }, function(response){
  10506. $scope.loading = false;
  10507. toaster.pop('error', '保存失败', response.data);
  10508. });
  10509. }
  10510. }
  10511. };
  10512. $scope.publishSaved = function(tender) {
  10513. var now = new Date() + 1; // 投标截止日为当天的均可以提交
  10514. if (tender.endDate < now) {
  10515. toaster.pop('warning', '警告', '单据已过期,请重新设置日期');
  10516. } else {
  10517. toaster.pop('info', '提示', '正在发布,请稍候');
  10518. PurcTender.publishSaved({tender: tender}, function() {
  10519. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  10520. toaster.pop('success', '提示', '发布成功');
  10521. window.location.hash = '#/purc/tender';
  10522. });
  10523. }
  10524. };
  10525. // 更新(在录入状态)
  10526. $scope.updateSaved = function(tender) {
  10527. var now = new Date() + 1; // 投标截止日为当天的均可以提交
  10528. if (tender.endDate < now) {
  10529. toaster.pop('warning', '警告', '单据已过期,请重新设置日期');
  10530. } else {
  10531. toaster.pop('info', '提示', '正在保存更新,请稍候');
  10532. PurcTender.updateSaved({tender: tender}, function() {
  10533. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  10534. toaster.pop('success', '提示', '更新成功');
  10535. window.location.hash = '#/purc/tender';
  10536. });
  10537. }
  10538. };
  10539. $scope.currentDay = function() {
  10540. return $filter('date')(new Date(), 'yyyy-MM-dd');
  10541. };
  10542. $scope.getMinDate = function() {
  10543. // var now = new Date();
  10544. // now = now.setDate(now.getDate()+1);
  10545. // var minDate = angular.copy($scope.tender.endDate);
  10546. // minDate = minDate.setDate(minDate.getDate() + 1);
  10547. if ($scope.tender.endDate instanceof Date) {
  10548. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  10549. }
  10550. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  10551. };
  10552. $scope.getMaxDate = function() {
  10553. // var maxDate = angular.copy($scope.tender.publishDate);
  10554. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  10555. if ($scope.tender.publishDate instanceof Date) {
  10556. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  10557. }
  10558. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  10559. };
  10560. $scope.openDatePicker = function($event, item, openParam) {
  10561. $event.preventDefault();
  10562. $event.stopPropagation();
  10563. item[openParam] = !item[openParam];
  10564. };
  10565. }]);
  10566. //类目选择模态框(招标产品明细)
  10567. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  10568. $scope.actives = actives;
  10569. $scope.kinds = [[], [], [], []];
  10570. // 获取子类目
  10571. var getChildren = function(pid, deep) {
  10572. KindAPI.getChildren({parentId: pid}, function(data) {
  10573. $scope.kinds[deep] = data;
  10574. }, function(response) {
  10575. toaster.pop('error', '获取子类目失败', response.data);
  10576. });
  10577. };
  10578. // 改变节点选中状态
  10579. var changeStatus = function(item, deep) {
  10580. var actives = [], level = 0;
  10581. angular.forEach($scope.kinds, function(ks, i) {
  10582. if(i > deep) {
  10583. $scope.kinds[i] = [];
  10584. } else {
  10585. angular.forEach(ks, function(k, j) {
  10586. if(i == deep) {
  10587. if(k.id == item.id) {
  10588. $scope.kinds[i][j].$active = true;
  10589. actives.push(k);
  10590. } else {
  10591. k.$active = null;
  10592. }
  10593. } else {
  10594. if(k.$active) {
  10595. actives.push(k);
  10596. }
  10597. }
  10598. });
  10599. }
  10600. });
  10601. // 选择的节点
  10602. $scope.actives = actives;
  10603. $scope.active = item;
  10604. // 当前可操作的层级
  10605. if(deep < 3) {
  10606. $scope.activeDeep = deep + 1;
  10607. }
  10608. };
  10609. // 节点点击后获取子类目,节点被选中
  10610. $scope.onItemClick = function(item, deep) {
  10611. changeStatus(item, deep);
  10612. if (!item.isLeaf) {
  10613. getChildren(item.id, deep + 1);
  10614. }
  10615. };
  10616. // 重新加载数据
  10617. function reload(deep) {
  10618. var pid;
  10619. if(deep) {
  10620. pid = $scope.actives[deep - 1].id;
  10621. } else {
  10622. pid = 0;
  10623. deep = 0;
  10624. }
  10625. getChildren(pid, deep);
  10626. }
  10627. // 初始加载数据,获取第一层的类目
  10628. if($scope.actives) {
  10629. angular.forEach($scope.actives, function(v, k) {
  10630. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  10631. $scope.kinds[k] = data;
  10632. angular.forEach($scope.kinds[k], function(kind, i){
  10633. if(kind.id == v.id) {
  10634. $scope.kinds[k][i].$active = true;
  10635. $scope.actives[k] = $scope.kinds[k][i];
  10636. }
  10637. })
  10638. }, function(response) {
  10639. toaster.pop('error', '获取子类目失败', response.data);
  10640. });
  10641. });
  10642. } else {
  10643. reload();
  10644. }
  10645. // 取消
  10646. $scope.cancel = function() {
  10647. $modalInstance.dismiss();
  10648. };
  10649. // 确认选择
  10650. $scope.check = function() {
  10651. var a = {
  10652. active: $scope.active,
  10653. actives: $scope.actives
  10654. };
  10655. $modalInstance.close(a);
  10656. };
  10657. }]);
  10658. //品牌选择模态框的controller
  10659. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  10660. $scope.filter = {};
  10661. $scope.brandsTableParams = new ngTableParams({
  10662. page : 1,
  10663. count : 5,
  10664. sorting : {
  10665. nameCn: 'asc'
  10666. }
  10667. }, {
  10668. total : 0,
  10669. counts : [],
  10670. getData : function($defer, params) {
  10671. var param = BaseService.parseParams(params.url());
  10672. param.keyword = $scope.filter.keyword;
  10673. var keyword = $scope.filter.keyword;
  10674. // param.keyword = $scope.filter.keyword;
  10675. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  10676. if (page) {
  10677. params.total(page.totalElements);
  10678. $defer.resolve(page.content);
  10679. }
  10680. }, function(){
  10681. });
  10682. }
  10683. });
  10684. // 搜索
  10685. $scope.search = function() {
  10686. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  10687. $scope.brandsTableParams.page(1);
  10688. $scope.brandsTableParams.reload();
  10689. };
  10690. // 选择
  10691. $scope.select = function(brand){
  10692. $modalInstance.close(brand);
  10693. };
  10694. // 关闭
  10695. $scope.cancel = function() {
  10696. $modalInstance.dismiss();
  10697. };
  10698. }]);
  10699. /**
  10700. * 招标单批量导入
  10701. */
  10702. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  10703. // 通过excel批量上传物料
  10704. $scope.result = null;
  10705. $scope.upload = function() {
  10706. var file = $scope.myFiles[0];
  10707. $upload.upload({
  10708. url: 'tender/release/excel',
  10709. file: file,
  10710. method: 'POST'
  10711. }).success(function(data) {
  10712. console.log(data);
  10713. $scope.result = data;
  10714. $scope.success = $scope.result.success;
  10715. $scope.total = $scope.result.total;
  10716. $scope.alters = $scope.result.alters;
  10717. }).error(function(response) {
  10718. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  10719. });
  10720. };
  10721. // 查看范例
  10722. $scope.showImg = function() {
  10723. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  10724. box.show();
  10725. box.find('img').attr('src', src);
  10726. box.find('a').click(function(){
  10727. box.hide();
  10728. });
  10729. box.dblclick(function(){
  10730. box.hide();
  10731. });
  10732. };
  10733. // 下载模板
  10734. $scope.download = function() {
  10735. window.location.href = 'tender/upload/template';
  10736. };
  10737. $scope.enSure = function() {
  10738. $modalInstance.close($scope.result.items);
  10739. }
  10740. $scope.cancel = function() {
  10741. $modalInstance.dismiss();
  10742. }
  10743. }]);
  10744. /**
  10745. * 评标
  10746. */
  10747. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  10748. BaseService.scrollBackToTop();
  10749. $scope.tenderItems = [];
  10750. // 采购方获取评标单
  10751. var evaluation = function() {
  10752. $scope.loading = true;
  10753. PurcTender.getOne({id: $stateParams.id}, function(data){
  10754. data.$editing = false;
  10755. $scope.tender = data;
  10756. $scope.tableParams = new ngTableParams({}, { dataset: data});
  10757. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  10758. $scope.loading = false;
  10759. }, function(response){
  10760. $scope.loading = false;
  10761. toaster.pop('error', '数据加载失败', response.data);
  10762. });
  10763. }
  10764. evaluation();
  10765. // 设置排序方式
  10766. $scope.setSort = function(field, desc) {
  10767. if(field == 'price' && $scope.sort.field != 'price') {// 切换到价格排序时先升序排序
  10768. desc = 'asc';
  10769. } else if( ! desc) {
  10770. // if($scope.sort.desc == 'asc') {
  10771. // desc = 'desc';
  10772. // } else {
  10773. // desc = 'asc';
  10774. // }
  10775. }
  10776. $scope.sort = {field: field, desc: desc};
  10777. $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  10778. };
  10779. $scope.orderType = 'price';
  10780. // $scope.dir = '-';
  10781. // 改变排序顺序
  10782. $scope.changeOrder = function(type){
  10783. $scope.orderType = type;
  10784. // if(!$scope.dir || $scope.dir === '') {
  10785. // $scope.dir = '-';
  10786. // }else {
  10787. // $scope.dir = '';
  10788. // }
  10789. };
  10790. $scope.submit = function(tender) {
  10791. PurcTender.decide(tender, function(){
  10792. toaster.pop('success', '确认成功');
  10793. window.location.hash = '#/purc/tender';
  10794. }, function(response){
  10795. toaster.pop('error', '确认失败', response.data);
  10796. });
  10797. }
  10798. }]);
  10799. /**
  10800. * 客户指定招标
  10801. *
  10802. */
  10803. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  10804. BaseService.scrollBackToTop();
  10805. $scope.active = 'todo';
  10806. $scope.condition = {dateZone: 1};
  10807. $scope.setActive = function(state) {
  10808. if($scope.active != state) {
  10809. $scope.active = state;
  10810. if($scope.tableParams.page() == 1)
  10811. $scope.tableParams.reload();
  10812. else
  10813. $scope.tableParams.page(1);
  10814. }
  10815. };
  10816. $scope.tableParams = new ngTableParams({
  10817. page : 1,
  10818. count : 5,
  10819. sorting: {
  10820. 'tender.endDate': 'desc',
  10821. 'tender.enterprise.enName': 'asc',
  10822. 'tender.code': 'asc'
  10823. }
  10824. }, {
  10825. total : 0,
  10826. counts: [5, 10, 25, 50],
  10827. getData : function($defer, params) {
  10828. $scope.loading = true;
  10829. var pageParams = params.url();
  10830. var realActive = {};
  10831. pageParams.searchFilter = { // 筛选条件
  10832. keyword: $scope.keyword
  10833. // fromDate: getDateTime($scope.condition.dateFrom),
  10834. // endDate: getDateTime($scope.condition.dateTo)
  10835. };
  10836. AccountEnterprise.get({}, function(data){
  10837. $scope.loading = false;
  10838. $scope.currentEn = data;
  10839. });
  10840. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10841. $scope.loading = false;
  10842. if(page) {
  10843. params.total(page.totalElement);
  10844. $defer.resolve(page.content);
  10845. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  10846. angular.forEach(page.content, function(purcTender) {
  10847. angular.forEach(purcTender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  10848. saleTenderItem.saleTender.vendorHasBid = false; // 未投标
  10849. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU && saleTenderItem.price !== null) { // 存在本企业投标明细,且价格已填,判定为已投标
  10850. saleTenderItem.saleTender.vendorHasBid = true; // 已投标
  10851. saleTenderItem.saleTender.applyVendor = false; // 未中标
  10852. if (saleTenderItem.applyStatus === 1) {
  10853. saleTenderItem.saleTender.applyVendor = true; // 是否中标
  10854. }
  10855. }
  10856. });
  10857. });
  10858. }
  10859. }, function(response){
  10860. $scope.loading = false;
  10861. toaster.pop('error', '数据加载失败', response.data);
  10862. });
  10863. }
  10864. });
  10865. var stautsItem = [];
  10866. $scope.getTenderStatus = function (tender) {
  10867. angular.forEach(tender.purchaseTenderItems, function(thisItem){
  10868. if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  10869. stautsItem = thisItem;
  10870. }
  10871. });
  10872. if (!stautsItem.price) {
  10873. return "daitoubiao";
  10874. } else if (!stautsItem.applystatus) {
  10875. return "yitoubiao";
  10876. } else if (stautsItem.applystatus == 1) {
  10877. return "zhongbiao";
  10878. } else if (stautsItem.applystatus == 0) {
  10879. return "weizhongbiao";
  10880. }
  10881. };
  10882. // 搜索框回车
  10883. $scope.onSearch = function() {
  10884. $scope.tableParams.page(1);
  10885. $scope.tableParams.reload();
  10886. };
  10887. }]);
  10888. /**
  10889. * 平台公开招标
  10890. *
  10891. */
  10892. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  10893. BaseService.scrollBackToTop();
  10894. $scope.active = 'all';
  10895. $scope.condition = {dateZone: 1};
  10896. // $scope.setActive = function(state) {
  10897. // if($scope.active != state) {
  10898. // $scope.active = state;
  10899. // if($scope.tableParams.page() == 1)
  10900. // $scope.tableParams.reload();
  10901. // else
  10902. // $scope.tableParams.page(1);
  10903. // }
  10904. // };
  10905. var getOpenState = function(active) {
  10906. var fn = 'getOpenAll';
  10907. switch(active) {
  10908. case 'all':
  10909. fn = 'getOpenAll';break;
  10910. // case 'done':
  10911. // fn = 'getOpenDone';break;
  10912. case 'todo':
  10913. fn = 'getOpenTodo';break;
  10914. case 'end':
  10915. fn = 'getOpenEnd';break;
  10916. // case 'waiting':
  10917. // fn = 'getOpenWaiting';break;
  10918. }
  10919. return fn;
  10920. };
  10921. $scope.tableParams = new ngTableParams({
  10922. page : 1,
  10923. count : 10,
  10924. sorting: {
  10925. 'tender.endDate': 'desc',
  10926. 'tender.enterprise.enName': 'asc',
  10927. 'tender.code': 'asc'
  10928. }
  10929. }, {
  10930. total : 0,
  10931. counts: [10, 25, 50, 100],
  10932. getData : function($defer, params) {
  10933. $scope.loading = true;
  10934. var pageParams = params.url();
  10935. var realActive = {};
  10936. pageParams.searchFilter = { // 筛选条件
  10937. keyword: $scope.keyword,
  10938. // fromDate: getDateTime($scope.condition.dateFrom),
  10939. // endDate: getDateTime($scope.condition.dateTo)
  10940. };
  10941. AccountEnterprise.get({}, function(data){
  10942. $scope.loading = false;
  10943. $scope.currentEn = data;
  10944. });
  10945. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10946. $scope.loading = false;
  10947. if(page) {
  10948. params.total(page.totalElement);
  10949. $defer.resolve(page.content);
  10950. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  10951. }
  10952. }, function(response){
  10953. $scope.loading = false;
  10954. toaster.pop('error', '数据加载失败', response.data);
  10955. });
  10956. }
  10957. });
  10958. $scope.toDetail = function(id) {
  10959. window.location.hash = '#/sale/openTenderDetail/' + id;
  10960. };
  10961. // var stautsItem = [];
  10962. // $scope.getTenderStatus = function (tender) {
  10963. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  10964. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  10965. // stautsItem = thisItem;
  10966. // }
  10967. // });
  10968. // if (!stautsItem.price) {
  10969. // return "daitoubiao";
  10970. // } else if (!stautsItem.applystatus) {
  10971. // return "yitoubiao";
  10972. // } else if (stautsItem.applystatus == 1) {
  10973. // return "zhongbiao";
  10974. // } else if (stautsItem.applystatus == 0) {
  10975. // return "weizhongbiao";
  10976. // }
  10977. // };
  10978. // 搜索框回车
  10979. $scope.onSearch = function() {
  10980. $scope.tableParams.page(1);
  10981. $scope.tableParams.reload();
  10982. };
  10983. }]);
  10984. /**
  10985. * 采购方查看供应商投标单
  10986. */
  10987. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  10988. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  10989. // $scope.item = data; // 供应商查看
  10990. // $scope.loading = false;
  10991. // }, function(response){
  10992. // $scope.loading = false;
  10993. // toaster.pop('error', '数据加载失败', response.data);
  10994. // });
  10995. console.log($stateParams);
  10996. PurcTender.getOne({id: $stateParams.id}, function(data){
  10997. $scope.bid = data;
  10998. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  10999. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11000. if (saleTenderItem.saleTender.vendUU == $stateParams.vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  11001. tenderProd.currentItem = saleTenderItem;
  11002. $scope.saleTender = saleTenderItem.saleTender;
  11003. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11004. }
  11005. });
  11006. });
  11007. }, function(response){
  11008. toaster.pop('error', '数据加载失败', response.data);
  11009. });
  11010. }]);
  11011. /**
  11012. * 查看投标单详情
  11013. */
  11014. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise) {
  11015. BaseService.scrollBackToTop();
  11016. if (!$scope.attaches) {
  11017. $scope.attaches = []; // 存放上传了的附件
  11018. }
  11019. // var staticItem = null;
  11020. // $scope.loading = true;
  11021. // PurcTender.getItem({id: $stateParams.id}, function(data){
  11022. // $scope.item = data; // 用于投标
  11023. // if ($scope.item.enterpriseBaseInfo != null) {
  11024. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  11025. // }
  11026. // staticItem = angular.copy(data);
  11027. // $scope.loading = false;
  11028. // }, function(response){
  11029. // $scope.loading = false;
  11030. // toaster.pop('error', '数据加载失败', response.data);
  11031. // });
  11032. var sleep = function (d){
  11033. for(var t = Date.now();Date.now() - t <= d;);
  11034. }
  11035. AccountEnterprise.get({}, function(data){
  11036. $scope.currentEn = data;
  11037. });
  11038. PurcTender.getOne({id: $stateParams.id}, function(data){
  11039. $scope.bid = data;
  11040. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11041. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11042. if (!$scope.currentEn) {
  11043. AccountEnterprise.get({}, function(data){
  11044. $scope.currentEn = data;
  11045. });
  11046. }
  11047. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  11048. tenderProd.currentItem = saleTenderItem;
  11049. $scope.saleTender = saleTenderItem.saleTender;
  11050. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  11051. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11052. }
  11053. });
  11054. });
  11055. }, function(response){
  11056. toaster.pop('error', '数据加载失败', response.data);
  11057. });
  11058. $scope.upload = function(myFile) { // 上传附件
  11059. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  11060. $upload.upload({
  11061. url: 'tender/addTenderItemAttach',
  11062. file: file,
  11063. method: 'POST'
  11064. }).success(function (attach) {
  11065. $scope.attaches.push(attach);
  11066. });
  11067. };
  11068. $scope.removeAttach = function(attachId, index) {
  11069. $scope.attaches.splice(index, 1);
  11070. // PurcTender.removeAttach({attachId : id}, {}, function() {
  11071. //
  11072. // });
  11073. };
  11074. var taxrateYes = false;
  11075. var cycleYes = false;
  11076. var priceYes = false;
  11077. $scope.canSave = false;
  11078. $scope.validateThis = function(value, type) {
  11079. switch(type) {
  11080. case 'taxrate':
  11081. var regex = /^\+?[0-9][0-9]{0,1}$/;
  11082. if (regex.test(value)) {
  11083. taxrateYes = true;
  11084. } else {
  11085. if (value) {
  11086. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  11087. }
  11088. }
  11089. break;
  11090. case 'cycle':
  11091. regex = /^\+?[1-9][0-9]*$/;
  11092. if (regex.test(value)) {
  11093. cycleYes = true;
  11094. } else {
  11095. if (value) {
  11096. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  11097. }
  11098. }
  11099. break;
  11100. case 'price':
  11101. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11102. if (regex.test(value) && value !== 0) {
  11103. priceYes = true;
  11104. } else {
  11105. if (!(value instanceof Number) || value) {
  11106. toaster.pop('warning', '警告', '单价不合法,请重新填写');
  11107. }
  11108. }
  11109. break;
  11110. }
  11111. };
  11112. $scope.emNumYes = true;
  11113. $scope.validEmNum = function (value) {
  11114. var regex = /^\+?[1-9][0-9]*$/;
  11115. if (!regex.test(value) || value === 0 || value !== null) {
  11116. $scope.emNumYes = false;
  11117. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  11118. }
  11119. };
  11120. $scope.validateProds = function(tenderProd) {
  11121. // angular.forEach(tenderProds, function (tenderProd) {
  11122. var cycleRegex = /^\+?[1-9][0-9]*$/;
  11123. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  11124. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  11125. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11126. // 判断填写过的有为0或不符合正则式的,设置不能保存
  11127. console.log(tenderProd.currentItem.cycle);
  11128. if (tenderProd.currentItem.cycle !== null && (!cycleRegex.test(tenderProd.currentItem.cycle)) || (tenderProd.currentItem.taxrate !== null && !taxrateRegex.test(tenderProd.currentItem.taxrate)) || (tenderProd.currentItem.price !== null && (!priceRegex.test(tenderProd.currentItem.price) && tenderProd.currentItem.price !== 0))) {
  11129. $scope.canSave = false;
  11130. } else {
  11131. $scope.canSave = true;
  11132. }
  11133. // });
  11134. };
  11135. // 投标
  11136. $scope.bidIt = function(tender, currentEnBaseInfo){
  11137. $scope.loading = true;
  11138. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  11139. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  11140. }
  11141. var saleTenderItems = [];
  11142. if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  11143. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11144. if (tenderProd.currentItem) {
  11145. tenderProd.currentItem.saleTender = {};
  11146. saleTenderItems.push(tenderProd.currentItem);
  11147. }
  11148. });
  11149. } else {
  11150. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11151. if (tenderProd.currentItem) {
  11152. saleTenderItems.push(tenderProd.currentItem);
  11153. }
  11154. });
  11155. }
  11156. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  11157. $scope.loading = false;
  11158. toaster.pop('info', '成功', '投标成功');
  11159. // $window.location.reload();
  11160. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  11161. // window.location.hash = '#/sale/opentender';
  11162. // } else {
  11163. window.location.hash = '#/sale/tender';
  11164. // }
  11165. }, function(response){
  11166. $scope.loading = false;
  11167. toaster.pop('error', '投标失败', '出现异常,投标失败');
  11168. });
  11169. };
  11170. $scope.condition = {
  11171. $fromOpened:false
  11172. };
  11173. $scope.getMaxDate = function() {
  11174. return $filter('date')(new Date(), 'yyyy-MM-dd');
  11175. };
  11176. $scope.openDatePicker = function($event, item, openParam) {
  11177. $event.preventDefault();
  11178. $event.stopPropagation();
  11179. item[openParam] = !item[openParam];
  11180. };
  11181. }]);
  11182. /**
  11183. * 公开招标转投标单
  11184. */
  11185. app.controller('OpenSaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise) {
  11186. BaseService.scrollBackToTop();
  11187. $scope.attaches = []; // 存放上传了的附件
  11188. var sleep = function (d){
  11189. for(var t = Date.now();Date.now() - t <= d;);
  11190. }
  11191. AccountEnterprise.get({}, function(data){
  11192. $scope.currentEn = data;
  11193. });
  11194. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  11195. $scope.loading = true;
  11196. PurcTender.getOne({id: $stateParams.id}, function(data){
  11197. data.$editing = false;
  11198. $scope.tender = data;
  11199. $scope.tenderProd = data.purchaseTenderProds;
  11200. // parseCertificate($scope.tender.certificate);
  11201. // $scope.firstProd = data.purchaseTenderProds[0];
  11202. $scope.currentHasBid = false; // 默认当前企业未转投标单
  11203. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  11204. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  11205. $scope.currentHasBid = true;
  11206. }
  11207. });
  11208. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  11209. // console.log($scope.tenderProd.enterpriseBaseInfo);
  11210. $scope.loading = false;
  11211. $scope.attaches = $scope.tender.tenderAttaches;
  11212. }, function(response){
  11213. $scope.loading = false;
  11214. toaster.pop('error', '数据加载失败', response.data);
  11215. });
  11216. }
  11217. $scope.iWantToBid = function(id) {
  11218. PurcTender.addItems({id: id}, function(data){ // 添加明细
  11219. // $scope.tender = data;
  11220. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11221. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11222. // if (!$scope.currentEn) {
  11223. // AccountEnterprise.get({}, function(data){
  11224. // $scope.currentEn = data;
  11225. // });
  11226. // }
  11227. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  11228. // tenderProd.currentItem = saleTenderItem;
  11229. // $scope.saleTender = saleTenderItem.saleTender;
  11230. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  11231. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11232. // }
  11233. // });
  11234. // });
  11235. if (data.success) {
  11236. toaster.pop('success', '成功', '转投标单成功');
  11237. window.location.hash = '#/sale/tender';
  11238. }
  11239. }, function(response){
  11240. toaster.pop('error', '操作失败', response.data);
  11241. });
  11242. $scope.upload = function(myFile) { // 上传附件
  11243. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  11244. $upload.upload({
  11245. url: 'tender/addTenderItemAttach',
  11246. file: file,
  11247. method: 'POST'
  11248. }).success(function (attach) {
  11249. $scope.attaches.push(attach);
  11250. });
  11251. };
  11252. };
  11253. $scope.removeAttach = function(id, index) {
  11254. $scope.attaches.splice(index, 1);
  11255. PurcTender.removeAttach({attachId:id}, function() {
  11256. });
  11257. };
  11258. var taxrateYes = false;
  11259. var cycleYes = false;
  11260. var priceYes = false;
  11261. $scope.canSave = false;
  11262. $scope.validateThis = function(value, type) {
  11263. switch(type) {
  11264. case 'taxrate':
  11265. var regex = /^\+?[0-9][0-9]{0,1}$/;
  11266. if (regex.test(value)) {
  11267. taxrateYes = true;
  11268. } else {
  11269. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  11270. }
  11271. break;
  11272. case 'cycle':
  11273. regex = /^\+?[1-9][0-9]*$/;
  11274. if (regex.test(value)) {
  11275. cycleYes = true;
  11276. } else {
  11277. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  11278. }
  11279. break;
  11280. case 'price':
  11281. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11282. if (regex.test(value) && value !== 0) {
  11283. priceYes = true;
  11284. } else {
  11285. if (!(value instanceof Number) || value) {
  11286. toaster.pop('warning', '警告', '单价不合法,请重新填写');
  11287. }
  11288. }
  11289. break;
  11290. }
  11291. };
  11292. $scope.emNumYes = true;
  11293. $scope.validEmNum = function (value) {
  11294. var regex = /^\+?[1-9][0-9]*$/;
  11295. if (!regex.test(value) || value == 0 || value !== null) {
  11296. $scope.emNumYes = false;
  11297. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  11298. }
  11299. };
  11300. $scope.validateProds = function(tenderProd) {
  11301. // angular.forEach(tenderProds, function (tenderProd) {
  11302. var cycleRegex = /^\+?[1-9][0-9]*$/;
  11303. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  11304. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  11305. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11306. // 判断填写过的有为0或不符合正则式的,设置不能保存
  11307. console.log(tenderProd.currentItem.cycle);
  11308. if (tenderProd.currentItem.cycle !== null && (!cycleRegex.test(tenderProd.currentItem.cycle)) || (tenderProd.currentItem.taxrate !== null && !taxrateRegex.test(tenderProd.currentItem.taxrate)) || (tenderProd.currentItem.price !==null && (!priceRegex.test(tenderProd.currentItem.price) && tenderProd.currentItem.price !== 0))) {
  11309. $scope.canSave = false;
  11310. } else {
  11311. $scope.canSave = true;
  11312. }
  11313. // });
  11314. };
  11315. // 投标
  11316. $scope.bidIt = function(tender, currentEnBaseInfo){
  11317. $scope.loading = true;
  11318. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  11319. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  11320. }
  11321. var saleTenderItems = [];
  11322. if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  11323. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11324. if (tenderProd.currentItem) {
  11325. tenderProd.currentItem.saleTender = {};
  11326. saleTenderItems.push(tenderProd.currentItem);
  11327. }
  11328. });
  11329. } else {
  11330. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11331. if (tenderProd.currentItem) {
  11332. saleTenderItems.push(tenderProd.currentItem);
  11333. }
  11334. });
  11335. }
  11336. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  11337. $scope.loading = false;
  11338. toaster.pop('info', '成功', '投标成功');
  11339. // $window.location.reload();
  11340. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  11341. // window.location.hash = '#/sale/opentender';
  11342. // } else {
  11343. window.location.hash = '#/sale/tender';
  11344. // }
  11345. }, function(response){
  11346. $scope.loading = false;
  11347. toaster.pop('error', '投标失败', '出现异常,投标失败');
  11348. });
  11349. };
  11350. $scope.condition = {
  11351. $fromOpened:false
  11352. };
  11353. $scope.getMaxDate = function() {
  11354. return $filter('date')(new Date(), 'yyyy-MM-dd');
  11355. };
  11356. $scope.openDatePicker = function($event, item, openParam) {
  11357. $event.preventDefault();
  11358. $event.stopPropagation();
  11359. item[openParam] = !item[openParam];
  11360. };
  11361. }]);
  11362. return app;
  11363. });