app.js 195 KB

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