app.js 1003 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648
  1. define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product', 'service/Token', 'service/ProductUsers', 'service/File', 'service/PublicInquiry', 'service/Customer', 'service/PurcChange', 'angularTreeview'], function () {
  2. 'use strict';
  3. var app = angular.module('myApp', ['toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices', 'TokenService', 'ProductUserService', 'ui.tour', 'FileService', 'publicInquiryService', 'CustomerService', 'changeService', 'angularTreeview']);
  4. app.init = function () {
  5. angular.bootstrap(document, ['myApp']);
  6. };
  7. app.config(['$httpProvider', function ($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function ($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function (response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. // window.location.href = response.data.loginUrl || 'index';
  16. // window.location.href = window.location.origin + window.location.pathname + '/login';
  17. window.location.reload();
  18. return $q.reject(response);
  19. }
  20. return $q.reject(response);
  21. }
  22. }
  23. return httpInterceptor;
  24. }]);
  25. app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
  26. $stateProvider.state('index', {
  27. url: "/index",
  28. views: {
  29. "left-view": {
  30. templateUrl: "static/tpl/index/home/left.html",
  31. controller: 'LeftCtrl'
  32. },
  33. "right-view": {
  34. templateUrl: "static/tpl/index/home/right.html",
  35. controller: 'RightCtrl'
  36. }
  37. }
  38. }).state('home', {
  39. url: "/",
  40. views: {
  41. "left-view": {
  42. templateUrl: "static/tpl/index/home/left.html",
  43. controller: 'LeftCtrl'
  44. },
  45. "right-view": {
  46. templateUrl: "static/tpl/index/home/right.html",
  47. controller: 'RightCtrl'
  48. }
  49. }
  50. }).state('sale', {
  51. url: "/sale",
  52. views: {
  53. "left-view": {
  54. templateUrl: "static/tpl/index/common/leftAll.html",
  55. controller: 'LeftCtrl'
  56. },
  57. "right-view": {
  58. templateUrl: "static/tpl/index/sale/right.html"
  59. }
  60. },
  61. controller: function ($scope) {
  62. $scope.truck = [];
  63. $scope.dataChanged = false;
  64. }
  65. }).state('sale.index', {
  66. url: "",
  67. templateUrl: "static/tpl/index/sale/index.html"
  68. }).state('sale.home', {
  69. url: "/",
  70. templateUrl: "static/tpl/index/sale/index.html"
  71. }).state('purc', {
  72. url: "/purc",
  73. views: {
  74. "left-view": {
  75. templateUrl: "static/tpl/index/common/leftAll.html",
  76. controller: 'LeftCtrl'
  77. },
  78. "right-view": {
  79. templateUrl: "static/tpl/index/purc/right.html"
  80. }
  81. },
  82. controller: function ($scope) {
  83. $scope.truck = [];
  84. $scope.dataChanged = false;
  85. }
  86. }).state('purc.index', {
  87. url: "",
  88. templateUrl: "static/tpl/index/purc/index.html"
  89. }).state('purc.home', {
  90. url: "/",
  91. templateUrl: "static/tpl/index/purc/index.html"
  92. }).state('purc.introduce', {
  93. url: "/introduce",
  94. templateUrl: "static/tpl/index/purc/introduce.html"
  95. }).state('purc.order', {
  96. url: "/order",
  97. templateUrl: "static/tpl/index/purc/order.html",
  98. controller: 'PurcOrderCtrl'
  99. }).state('purc.order_detail', {
  100. url: "/order/:id",
  101. templateUrl: "static/tpl/index/purc/order_detail.html",
  102. controller: 'PurcOrderDetailCtrl'
  103. }).state('purc.newOrder', {
  104. url: "/addOrder",
  105. templateUrl: "static/tpl/index/purc/addOrder.html",
  106. controller: 'PurcNewOrderCtrl'
  107. }).state('purc.cart', {
  108. url: "/cart",
  109. templateUrl: "static/tpl/index/purc/cart.html",
  110. controller: 'CartController'
  111. }).state('purc.cartDetail', {
  112. url: "/cart/:id",
  113. templateUrl: "static/tpl/index/purc/cart_detail.html",
  114. controller: 'CartDetailController'
  115. }).state('purc.deputy', {
  116. url: "/deputy",
  117. templateUrl: "static/tpl/index/purc/deputyOrder.html",
  118. controller: 'DeputyOrderCtrl'
  119. }).state('purc.deputylog', {
  120. url: "/deputylog",
  121. templateUrl: "static/tpl/index/purc/deputyorders_log.html",
  122. controller: 'DeputyOrderLogCtrl'
  123. }).state('purc.newdeputy', {
  124. url: "/deputy/add",
  125. templateUrl: "static/tpl/index/purc/deputyOrder_new.html",
  126. controller: 'NewDeputyOrderCtrl'
  127. }).state('purc.deputydetail', {
  128. url: "/deputy/:id",
  129. templateUrl: "static/tpl/index/purc/deputyOrder_detail.html",
  130. controller: 'DeputyOrderDetailCtrl'
  131. }).state('purc.changeList', {// 新增采购变更单
  132. url: "/change",
  133. templateUrl: "static/tpl/index/purc/changeList.html",
  134. controller: 'PurcChangeListCtrl'
  135. /* 采购变更单详情 */
  136. }).state('purc.change_detail', {
  137. url: "/change/:id",
  138. templateUrl: "static/tpl/index/purc/change_detail.html",
  139. controller: 'PurcChangeDetailCtrl'
  140. }).state('purc.changeNew', {// 新增采购变更单
  141. url: "/change_new",
  142. templateUrl: "static/tpl/index/purc/change_new.html",
  143. controller: 'PurcChangeNewCtrl'
  144. /* 招标列表 */
  145. }).state('purc.tenderlist', {
  146. url: "/tender",
  147. templateUrl: "static/tpl/index/purc/tenderlist.html",
  148. controller: 'PurcTenderCtrl'
  149. /* 招标答疑列表 */
  150. }).state('purc.tenderanswerlist', {
  151. url: "/tender/answer",
  152. templateUrl: "static/tpl/index/purc/tender_answer_list.html",
  153. controller: 'PurcTenderAnswerListCtrl'
  154. /* 招标答疑详情 */
  155. }).state('purc.tenderanswerdetail', {
  156. url: "/tender/answer/:id",
  157. templateUrl: "static/tpl/index/purc/tender_answer_detail.html",
  158. controller: 'PurcTenderAnswerDetailCtrl'
  159. }).state('purc.waiting.tenderlist', {
  160. url: "/tender",
  161. templateUrl: "static/tpl/index/purc/tenderlist.html",
  162. controller: 'PurcTenderCtrl'
  163. }).state('purc.todo.tenderlist', {
  164. url: "/tender/todo",
  165. templateUrl: "static/tpl/index/purc/tenderlist.html",
  166. controller: 'PurcTenderCtrl'
  167. /* 招标 */
  168. }).state('purc.tender', {
  169. url: "/addTender",
  170. templateUrl: "static/tpl/index/purc/tender.html",
  171. controller: 'PurcNewTenderCtrl'
  172. }).state('purc.savedtender', {
  173. url: "/tender/:id",
  174. templateUrl: "static/tpl/index/purc/tender.html",
  175. controller: 'PurcNewTenderCtrl'
  176. /* 评标 */
  177. }).state('purc.evaluation', {
  178. url: "/evaluation/:id",
  179. templateUrl: "static/tpl/index/purc/tender_evaluation.html",
  180. controller: 'PurcEvaluationCtrl'
  181. /* 采购供应商资料 */
  182. }).state('purc.vendor', {
  183. url: "/vendor",
  184. templateUrl: "static/tpl/index/purc/vendor.html",
  185. controller: 'PurcVendorCtrl'
  186. /* 采购供应商资料 详情*/
  187. }).state('purc.vendorserve', {
  188. url: "/vendor/serve",
  189. templateUrl: "static/tpl/index/cs/right.html",
  190. controller: 'CustServeCtrl'
  191. }).state('purc.vendordetail', {
  192. url: "/vendor/:id",
  193. templateUrl: "static/tpl/index/purc/vendor_detail.html",
  194. controller: 'PurcVendorDetailCtrl'
  195. /* 客户指定招标列表 */
  196. }).state('purc.makeoutorder', {
  197. url: "/makeoutorder",
  198. templateUrl: "static/tpl/index/make/outorder.html",
  199. controller: 'MakeOutOrderCtrl'
  200. }).state('purc.outorder_detail', {
  201. url: "/makeoutorder/:id",
  202. templateUrl: "static/tpl/index/make/outorder_detail.html",
  203. controller: 'MakeOutOrderDetailCtrl'
  204. /*平台新增询价单*/
  205. }).state('purc.inquiry_new', {
  206. url: "/purcinquiry",
  207. templateUrl: "static/tpl/index/purc/inquiry_new.html",
  208. controller: 'PurcInquiryCtrl'
  209. /*新增公共询价*/
  210. }).state('purc.pubinquiry_new', {
  211. url: "/pubinquiry/new",
  212. templateUrl: "static/tpl/index/purc/pubInquiry_new.html",
  213. controller: 'PurcInquiryCtrl'
  214. }).state('purc.purcinquiry_new', {
  215. url: "/purcinquiry/:bussinessCode",
  216. templateUrl: "static/tpl/index/purc/purcinquiry_new.html",
  217. controller: 'PurcInquiryNewCtrl'
  218. }).state('purc.inquiry', {
  219. url: "/purchaseinquiry",
  220. templateUrl: "static/tpl/index/purc/inquiry.html",
  221. controller: 'PurchaseInquiryCtrl'
  222. }).state('purc.inquiry_detail', {
  223. url: "/purcinquirydetail",
  224. templateUrl: "static/tpl/index/purc/inquiry_detail.html",
  225. controller: 'PurcInquiryDetailCtrl'
  226. }).state('purc.inquiryInfo_detail', {
  227. url: "/purcinquirydetail/:id",
  228. templateUrl: "static/tpl/index/purc/inquiryInfo_detail.html",
  229. controller: 'PurcInquiryInfoDetailCtrl'
  230. }).state('purc.inquiry_unapply', {
  231. url: "/inquiry_unapply",
  232. templateUrl: "static/tpl/index/purc/inquiry_unapply.html",
  233. controller: 'UnapplyInquiryCtrl'
  234. }).state('purc.pubInquiry', {
  235. /**
  236. * 针对客户,查询已转报价的公共询价单列表
  237. */
  238. url: "/publicInquiry",
  239. templateUrl: "static/tpl/index/purc/pubInquiry.html",
  240. controller: 'PurcPubInquiryCtrl'
  241. }).state('purc.pubInquiry_detail', {
  242. /**
  243. * 针对客户,查询已转报价单的公共询价详情
  244. */
  245. url: "/publicInquiry/:id",
  246. templateUrl: "static/tpl/index/purc/pubInquiry_detail.html",
  247. controller: 'PurcPubInquiryDetailCtrl'
  248. }).state('purc.product', {
  249. url: "/product",
  250. templateUrl: "static/tpl/index/purc/prodList.html",
  251. controller: 'PurcProductCtrl'
  252. }).state('purc.newProduct', {
  253. url: "/newProduct",
  254. templateUrl: "static/tpl/index/purc/newProdInfo.html",
  255. controller: 'PurcNewProdInfoCtrl'
  256. }).state('purc.productDetail', {
  257. url: "/prodList/:id",
  258. templateUrl: "static/tpl/index/purc/productDetail.html",
  259. controller: 'PurcProdDetailCtrl'
  260. }).state('purc.productmatches', {
  261. url: "/productmatches",
  262. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  263. controller: 'ProductmatchesForPurcCtrl'
  264. }).state('purc.uploadProduct', {
  265. url: "/uploadProduct",
  266. templateUrl: "static/tpl/index/purc/uploadByBatch.html",
  267. controller: 'UploadProductCtrl'
  268. }).state('sale.tenderlist', {
  269. url: "/tender",
  270. templateUrl: "static/tpl/index/sale/tenderlist.html",
  271. controller: 'SaleTenderCtrl'
  272. /* 招标提问列表 */
  273. }).state('sale.tenderquestionlist', {
  274. url: "/tender/question",
  275. templateUrl: "static/tpl/index/sale/tender_question_list.html",
  276. controller: 'SaleTenderQuestionListCtrl'
  277. /* 招标提问详情 */
  278. }).state('sale.tenderquestiondetail', {
  279. url: "/tender/question/:id",
  280. templateUrl: "static/tpl/index/sale/tender_question_detail.html",
  281. controller: 'SaleTenderQuestionDetailCtrl'
  282. }).state('sale.todo.tenderlist', {
  283. url: "/tender",
  284. templateUrl: "static/tpl/index/sale/tenderlist.html",
  285. controller: 'SaleTenderCtrl'
  286. /* 平台公开招标列表 */
  287. }).state('baseInfo.openTenderList', {
  288. url: "/openTenderList",
  289. templateUrl: "static/tpl/index/sale/open_tender_list.html",
  290. controller: 'SaleOpenTenderCtrl'
  291. /* 查看公开招标详情 */
  292. }).state('baseInfo.open_tender_detail', {
  293. url: "/openTenderDetail/:id",
  294. templateUrl: "static/tpl/index/sale/open_tender_detail.html",
  295. controller: 'OpenSaleTenderDetailCtrl'
  296. /* 投标 */
  297. }).state('sale.tender', {
  298. url: "/tender/:id",
  299. templateUrl: "static/tpl/index/sale/tender.html",
  300. controller: 'SaleTenderDetailCtrl'
  301. /* 采购方查看供应商投标 */
  302. }).state('sale.vendortender', {
  303. url: "/tender/:vendUU/:id",
  304. templateUrl: "static/tpl/index/sale/vendor_tender.html",
  305. controller: 'SaleVendorTenderDetailCtrl'
  306. }).state('sale.todo', {
  307. url: "/todo",
  308. templateUrl: "static/tpl/index/sale/todo.html"
  309. }).state('sale.todo.inquiry', {
  310. url: "/inquiry",
  311. templateUrl: "static/tpl/index/sale/inquiry.html",
  312. controller: 'SaleInquiryCtrl'
  313. }).state('sale.todo.order', {
  314. url: "/order",
  315. templateUrl: "static/tpl/index/sale/order.html",
  316. controller: 'SaleOrderCtrl'
  317. }).state('sale.todo.change', {
  318. url: "/change",
  319. templateUrl: "static/tpl/index/sale/change.html",
  320. controller: 'SaleChangeCtrl'
  321. }).state('sale.todo.notice', {
  322. url: "/notice",
  323. templateUrl: "static/tpl/index/sale/notice.html",
  324. controller: 'SaleNoticeCtrl'
  325. }).state('sale.customer', {
  326. url: "/customer",
  327. templateUrl: "static/tpl/index/sale/customer.html",
  328. controller: 'CustomerCtrl'
  329. }).state('sale.customer_detail', {
  330. url: "/customer/:id",
  331. templateUrl: "static/tpl/index/sale/customer_detail.html",
  332. controller: 'CustomerDetailCtrl'
  333. }).state('sale.customerProduct', {
  334. url: "/customerProduct",
  335. templateUrl: "static/tpl/index/sale/customer.html",
  336. controller: 'CustomerCtrl'
  337. }).state('sale.inquiry', {
  338. url: "/inquiry",
  339. templateUrl: "static/tpl/index/sale/inquiry.html",
  340. controller: 'SaleInquiryCtrl'
  341. }).state('sale.pubinquiry', {
  342. /**
  343. * 针对卖家,展示已转询价报价的公共询价单列表
  344. */
  345. url: "/pubinquiry",
  346. templateUrl: "static/tpl/index/sale/pubinquiry.html",
  347. controller: 'SalePubInquiryCtrl'
  348. }).state('sale.pubinquiry_detail', {
  349. /**
  350. * 针对卖家,已转询价报价单的公共询价单详情
  351. */
  352. url: "/pubinquiry/:id",
  353. templateUrl: "static/tpl/index/sale/pubinquiry_detail.html",
  354. controller: 'SalePubInquiryDetailCtrl'
  355. }).state('sale.inquiryRemind', {
  356. /**
  357. * 针对卖家,查询推荐的询价列表
  358. */
  359. url: "/inquiryRemind",
  360. templateUrl: "static/tpl/index/sale/inquiryRemind.html",
  361. controller: 'SaleInquiryRemindCtrl'
  362. }).state('sale.inquirymould', {
  363. url: "/mould",
  364. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  365. controller: 'SaleInquiryMouldCtrl'
  366. }).state('sale.todo.inquirymould', {
  367. url: "/mould",
  368. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  369. controller: 'SaleInquiryMouldCtrl'
  370. }).state('sale.inquiry_mould_detail', {
  371. url: "/mould/:id",
  372. templateUrl: "static/tpl/index/sale/inquiry_mould_detail.html",
  373. controller: 'SaleInquiryMouldDetailCtrl'
  374. }).state('sale.inquiry_detail', {
  375. url: "/inquiry/:id",
  376. templateUrl: "static/tpl/index/sale/inquiry_detail.html",
  377. controller: 'SaleInquiryDetailCtrl'
  378. }).state('sale.quotation', {
  379. url: "/quotation",
  380. templateUrl: "static/tpl/index/sale/quotation.html"
  381. }).state('sale.quotation.new', {
  382. url: "/new",
  383. templateUrl: "static/tpl/index/sale/quotation_new.html",
  384. controller: 'SaleQuotationNewCtrl',
  385. params: {
  386. 'inquiryItem': null
  387. }
  388. }).state('sale.quotation.list', {
  389. url: "/list",
  390. templateUrl: "static/tpl/index/sale/quotation_list.html",
  391. controller: 'SaleQuotationListCtrl'
  392. }).state('sale.quotation.item', {
  393. url: "/:id",
  394. templateUrl: "static/tpl/index/sale/quotation_new.html",
  395. controller: 'SaleQuotationNewCtrl'
  396. }).state('sale.order', {
  397. url: "/order",
  398. templateUrl: "static/tpl/index/sale/order.html",
  399. controller: 'SaleOrderCtrl'
  400. }).state('sale.order_detail', {
  401. url: "/order/:id",
  402. templateUrl: "static/tpl/index/sale/order_detail.html",
  403. controller: 'SaleOrderDetailCtrl'
  404. }).state('sale.change', {
  405. url: "/change",
  406. templateUrl: "static/tpl/index/sale/change.html",
  407. controller: 'SaleChangeCtrl'
  408. }).state('sale.change_detail', {
  409. url: "/change/:id",
  410. templateUrl: "static/tpl/index/sale/change_detail.html",
  411. controller: 'SaleChangeDetailCtrl'
  412. }).state('sale.notice', {
  413. url: "/notice",
  414. templateUrl: "static/tpl/index/sale/notice.html",
  415. controller: 'SaleNoticeCtrl'
  416. }).state('sale.send', {
  417. url: "/send",
  418. templateUrl: "static/tpl/index/sale/send.html",
  419. controller: 'SaleSendCtrl'
  420. }).state('sale.send_detail', {
  421. url: "/send/:id",
  422. templateUrl: "static/tpl/index/sale/send_detail.html",
  423. controller: 'SaleSendDetailCtrl'
  424. }).state('sale.forecast', {
  425. url: "/forecast",
  426. templateUrl: "static/tpl/index/sale/forecast.html",
  427. controller: 'SaleForecastCtrl'
  428. }).state('sale.accept', {
  429. url: "/accept",
  430. templateUrl: "static/tpl/index/sale/accept.html",
  431. controller: 'SaleAcceptCtrl'
  432. }).state('sale.accept_detail', {
  433. url: "/accept/:id",
  434. templateUrl: "static/tpl/index/sale/accept_detail.html",
  435. controller: 'SaleAcceptDetailCtrl'
  436. }).state('sale.returns', {
  437. url: "/returns",
  438. templateUrl: "static/tpl/index/sale/returns.html",
  439. controller: 'SaleReturnsCtrl'
  440. }).state('sale.return_detail', {
  441. url: "/return/:id",
  442. templateUrl: "static/tpl/index/sale/return_detail.html",
  443. controller: 'SaleReturnsDetailCtrl'
  444. }).state('sale.sample', {
  445. url: "/sample",
  446. templateUrl: "static/tpl/index/sale/sample.html",
  447. controller: 'SaleSampleCtrl'
  448. }).state('sale.sample_detail', {
  449. url: "/sample/:id",
  450. templateUrl: "static/tpl/index/sale/sample_detail.html",
  451. controller: 'SaleSampleDetailCtrl'
  452. }).state('sale.approval', {
  453. url: "/approval",
  454. templateUrl: "static/tpl/index/sale/approval.html",
  455. controller: 'SaleApprovalCtrl'
  456. }).state('sale.prodList', {
  457. url: "/prodList",
  458. templateUrl: "static/tpl/index/baseInfo/prodList.html",
  459. controller: 'ProductListCtrl'
  460. }).state('sale.newProdInfo', {
  461. url: "/newProdInfo",
  462. templateUrl: "static/tpl/index/baseInfo/newProdInfo.html",
  463. controller: 'NewProdInfoCtrl'
  464. }).state('sale.uploadByBatch', {
  465. url: "/uploadByBatch",
  466. templateUrl: "static/tpl/index/baseInfo/uploadByBatch.html",
  467. controller: 'UploadByBatchCtrl'
  468. }).state('sale.productDetail', {
  469. url: "/prodList/:id",
  470. templateUrl: "static/tpl/index/baseInfo/productDetail.html",
  471. controller: 'ProductDetailCtrl'
  472. }).state('sale.productmatches', {
  473. url: "/productmatches",
  474. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  475. controller: 'ProductmatchesForSaleCtrl'
  476. }).state('sale.maketodo', {
  477. url: "/maketodo",
  478. templateUrl: "static/tpl/index/make/todo.html"
  479. }).state('sale.maketodo.order', {
  480. url: "/makeorder",
  481. templateUrl: "static/tpl/index/make/order.html",
  482. controller: 'MakeOrderCtrl'
  483. }).state('sale.makeorder', {
  484. url: "/makeorder",
  485. templateUrl: "static/tpl/index/make/order.html",
  486. controller: 'MakeOrderCtrl'
  487. }).state('sale.makeorder_detail', {
  488. url: "/makeorder/:id",
  489. templateUrl: "static/tpl/index/make/order_detail.html",
  490. controller: 'MakeOrderDetailCtrl'
  491. }).state('sale.badOut', {
  492. url: "/badOut",
  493. templateUrl: "static/tpl/index/qc/badOut.html",
  494. controller: 'SaleBadOutCtrl'
  495. }).state('sale.MRB', {
  496. url: "/MRB",
  497. templateUrl: "static/tpl/index/qc/MRB.html",
  498. controller: 'SaleMRBCtrl'
  499. }).state('sale.badIn', {
  500. url: "/badIn",
  501. templateUrl: "static/tpl/index/qc/badIn.html",
  502. controller: 'SaleBadInCtrl'
  503. }).state('sale.makeaccept', {
  504. url: "/makeaccept",
  505. templateUrl: "static/tpl/index/make/accept.html",
  506. controller: 'MakeAcceptCtrl'
  507. }).state('sale.makereturns', {
  508. url: "/makereturns",
  509. templateUrl: "static/tpl/index/make/returns.html",
  510. controller: 'MakeReturnCtrl'
  511. }).state('sale.makechange', {
  512. url: "/makechange",
  513. templateUrl: "static/tpl/index/make/change.html",
  514. controller: 'MakeChangeCtrl'
  515. }).state('sale.makechange_detail', {
  516. url: "/makechange/:id",
  517. templateUrl: "static/tpl/index/make/change_detail.html",
  518. controller: 'MakeChangeDetailCtrl'
  519. }).state('account', {
  520. url: "/account",
  521. views: {
  522. "left-view": {
  523. templateUrl: "static/tpl/index/account/left.html",
  524. controller: 'LeftCtrl'
  525. },
  526. "right-view": {
  527. templateUrl: "static/tpl/index/account/right.html"
  528. }
  529. }
  530. }).state('account.index', {
  531. url: "",
  532. templateUrl: "static/tpl/index/account/index.html",
  533. controller: 'RightCtrl'
  534. }).state('account.home', {
  535. url: "/",
  536. templateUrl: "static/tpl/index/account/index.html",
  537. controller: 'RightCtrl'
  538. }).state('baseInfo', {//基础资料
  539. url: "/baseInfo",
  540. views: {
  541. "left-view": {},
  542. "right-view": {
  543. templateUrl: "static/tpl/index/baseInfo/right.html"
  544. }
  545. }
  546. }).state('baseInfo.index', {
  547. url: "/enterpriseList",
  548. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  549. controller: 'EnterpriseListCtrl'
  550. }).state('baseInfo.home', {
  551. url: "/enterpriseList",
  552. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  553. controller: 'EnterpriseListCtrl'
  554. }).state('baseInfo.enterpriseList', {
  555. url: "/enterpriseList",
  556. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  557. controller: 'EnterpriseListCtrl'
  558. }).state('baseInfo.myClient', {
  559. url: "/myClient",
  560. templateUrl: "static/tpl/index/baseInfo/myClient.html",
  561. controller: 'MyClientCtrl'
  562. }).state('baseInfo.mySupplier', {
  563. url: "/mySupplier",
  564. templateUrl: "static/tpl/index/baseInfo/mySupplier.html",
  565. controller: 'MySupplierCtrl'
  566. }).state('baseInfo.myRequest', {
  567. url: "/myRequest",
  568. templateUrl: "static/tpl/index/baseInfo/myRequest.html",
  569. controller: 'AddPartnerRequestCtrl'
  570. }).state('baseInfo.newPartner', {
  571. url: "/newPartner",
  572. templateUrl: "static/tpl/index/baseInfo/newPartner.html",
  573. controller: 'NewPartnerCtrl'
  574. }).state('baseInfo.myMessage', {
  575. url: "/myMessage",
  576. templateUrl: "static/tpl/index/baseInfo/myMessage.html",
  577. controller: 'AddPartnerMessageCtrl'
  578. }).state('baseInfo.myPartners', {
  579. url: '/myPartners',
  580. templateUrl: "static/tpl/index/baseInfo/myPartners.html",
  581. controller: 'MyPartnersCtrl'
  582. }).state('baseInfo.businessGroups', {
  583. url: '/businessGroups',
  584. controller: 'BusinessGroupsCtrl'
  585. }).state('baseInfo.inquiryList', {
  586. url: '/inquiryList',
  587. templateUrl: "static/tpl/index/baseInfo/inquiry_list.html",
  588. controller: 'PublicInquiryListCtrl'
  589. }).state('baseInfo.inquiryListDetail', {
  590. url: '/inquiryList/:id',
  591. templateUrl: "static/tpl/index/baseInfo/inquiryItem_detail.html",
  592. controller: 'PublicInquiryListDetailCtrl'
  593. }).state('baseInfo.vendorInfo', {
  594. url: '/enume/vendorInfo',
  595. templateUrl: "static/tpl/index/baseInfo/vendorsInfo.html",
  596. controller: 'VendorsInfoCtrl'
  597. }).state('baseInfo.servicerInfo', {
  598. url: '/enume/servicerInfo',
  599. templateUrl: "static/tpl/index/baseInfo/servicerInfo.html",
  600. controller: 'ServicerInfoCtrl'
  601. }).state('baseInfo.customerInfo', {
  602. url: '/enume/customerInfo',
  603. templateUrl: "static/tpl/index/baseInfo/customersInfo.html",
  604. controller: 'CustomersInfoCtrl'
  605. }).state('baseInfo.enume', {
  606. url: '/enume',
  607. templateUrl: "static/tpl/index/baseInfo/vendorAndCustomer.html"
  608. }).state('baseInfo.partner', {
  609. url: '/partner',
  610. templateUrl: "static/tpl/index/baseInfo/addPartners.html",
  611. controller: 'AddPartnersCtrl'
  612. }).state('baseInfo.partner_searchresult', {
  613. url: '/search',
  614. templateUrl: "static/tpl/index/baseInfo/searchresult.html",
  615. controller: 'EnterpriseSearchCtrl'
  616. }).state('baseInfo.invitation', {
  617. url: '/invitation',
  618. templateUrl: "static/tpl/index/baseInfo/invitation.html",
  619. controller: 'InvitationCtrl'
  620. }).state('qc', {
  621. url: "/qc",
  622. views: {
  623. "left-view": {
  624. templateUrl: "static/tpl/index/qc/left.html"
  625. },
  626. "right-view": {
  627. templateUrl: "static/tpl/index/qc/right.html"
  628. }
  629. }
  630. }).state('qc.index', {
  631. url: "",
  632. templateUrl: "static/tpl/index/qc/index.html"
  633. }).state('qc.home', {
  634. url: "/",
  635. templateUrl: "static/tpl/index/qc/index.html"
  636. }).state('fa', {
  637. url: "/fa",
  638. views: {
  639. "left-view": {
  640. templateUrl: "static/tpl/index/common/leftAll.html"
  641. },
  642. "right-view": {
  643. templateUrl: "static/tpl/index/fa/right.html"
  644. }
  645. }
  646. }).state('fa.index', {
  647. url: "",
  648. templateUrl: "static/tpl/index/fa/index.html"
  649. }).state('fa.home', {
  650. url: "/",
  651. templateUrl: "static/tpl/index/fa/index.html"
  652. }).state('fa.apBill', {
  653. url: "/apBill",
  654. templateUrl: "static/tpl/index/fa/apBill.html",
  655. controller: 'SaleApBillCtrl'
  656. }).state('fa.apBill_detail', {
  657. url: "/apBill/:id",
  658. templateUrl: "static/tpl/index/fa/apBill_detail.html",
  659. controller: 'SaleApBillDetailCtrl'
  660. }).state('fa.arCheck', {
  661. url: "/arCheck",
  662. templateUrl: "static/tpl/index/fa/arCheck.html",
  663. controller: 'SaleArCheckCtrl'
  664. }).state('fa.arCheck_detail', {
  665. url: "/arCheck/:id",
  666. templateUrl: "static/tpl/index/fa/arCheck_detail.html",
  667. controller: 'SaleArCheckDetailCtrl'
  668. }).state('fa.apCheck', {
  669. url: "/apCheck",
  670. params: {
  671. 'id': null
  672. },
  673. templateUrl: "static/tpl/index/fa/apCheck.html",
  674. controller: 'PurchaseApCheckCtrl'
  675. }).state('fa.apCheck_detail', {
  676. url: "/apCheck/:id",
  677. templateUrl: "static/tpl/index/fa/apCheck_detail.html",
  678. controller: 'PurchaseApCheckDetailCtrl'
  679. }).state('fa.apCheckList', {
  680. url: "/apCheckList",
  681. templateUrl: "static/tpl/index/fa/apCheckList.html",
  682. controller: 'PurchaseApCheckListCtrl'
  683. }).state('fa.apBillOut', {
  684. url: "/apBillOut",
  685. params:{
  686. 'id':null
  687. },
  688. templateUrl: "static/tpl/index/fa/apBillOut.html",
  689. controller: 'PurchaseApBillOutCtrl'
  690. }).state('fa.apBillOut_detail', {
  691. url: "/apBillOut/:id",
  692. templateUrl: "static/tpl/index/fa/apBillOut_detail.html",
  693. controller: 'PurchaseApBillOutDetailCtrl'
  694. }).state('fa.apBillOutList', {
  695. url: "/apBillOutList",
  696. templateUrl: "static/tpl/index/fa/apBillOutList.html",
  697. controller: 'PurchaseApBillOutListCtrl'
  698. }).state('fa.adjustList', {
  699. url: "/adjustList",
  700. templateUrl: "static/tpl/index/fa/adjustList.html",
  701. controller: 'PurchaseAdjustListCtrl'
  702. }).state('make', {
  703. url: "/make",
  704. views: {
  705. "left-view": {
  706. templateUrl: "static/tpl/index/make/left.html"
  707. },
  708. "right-view": {
  709. templateUrl: "static/tpl/index/make/right.html"
  710. }
  711. }
  712. }).state('make.index', {
  713. url: "",
  714. templateUrl: "static/tpl/index/make/index.html"
  715. }).state('make.home', {
  716. url: "/",
  717. templateUrl: "static/tpl/index/make/index.html"
  718. }).state('cs', {// 客户服务
  719. url: "/cs",
  720. views: {
  721. "left-view": {
  722. templateUrl: "static/tpl/index/cs/left.html"
  723. },
  724. "right-view": {
  725. templateUrl: "static/tpl/index/cs/right.html"
  726. }
  727. }
  728. }).state('cs.index', {
  729. url: "",
  730. templateUrl: "static/tpl/index/cs/index.html"
  731. }).state('cs.home', {
  732. url: "/",
  733. templateUrl: "static/tpl/index/cs/index.html"
  734. }).state('search', { //顶部搜索
  735. url: "/search?keyword=",
  736. views: {
  737. "left-view": {
  738. templateUrl: "static/tpl/index/search/left.html"
  739. },
  740. "right-view": {
  741. templateUrl: "static/tpl/index/search/search_result.html",
  742. controller: 'TopSearchCtrl'
  743. }
  744. }
  745. }).state('approvalflow', { //审批流
  746. url: "/approvalFlow",
  747. views: {
  748. "left-view": {
  749. templateUrl: "static/tpl/index/common/leftAll.html"
  750. },
  751. "right-view": {
  752. templateUrl: "static/tpl/index/approvalFlow/right.html",
  753. }
  754. }
  755. }).state('approvalflow.flow', {
  756. url: "/flow",
  757. templateUrl: "static/tpl/index/approvalFlow/home.html",
  758. controller: 'approvalFlowCtrl'
  759. }).state('approvalflow.enterprise', {
  760. url: "/enterprise",
  761. templateUrl: "static/tpl/index/approvalFlow/enterprise.html",
  762. controller: 'EnterpriseCtrl'
  763. }).state('approvalflow.user', {
  764. url: "/user",
  765. templateUrl: "static/tpl/index/approvalFlow/user.html",
  766. controller: 'UserCtrl'
  767. }).state('approvalflow.log', {
  768. url: "/log",
  769. templateUrl: "static/tpl/index/approvalFlow/log.html",
  770. controller: 'LogCtrl'
  771. }).state('approvalflow.resource', {
  772. url: "/resource",
  773. templateUrl: "static/tpl/index/approvalFlow/resource.html",
  774. controller: 'ResourceCtrl'
  775. }).state('approvalflow.role', {
  776. url: "/role",
  777. templateUrl: "static/tpl/index/approvalFlow/role.html",
  778. controller: 'RoleCtrl'
  779. }).state('approvalflow.product', {
  780. url: "/product",
  781. templateUrl: "static/tpl/index/approvalFlow/prodList.html",
  782. controller: 'ProductAllCtrl'
  783. }).state('approvalflow.userProduct', {
  784. url: "/userProduct",
  785. templateUrl: "static/tpl/index/approvalFlow/userProduct.html",
  786. controller: 'UserProductCtrl'
  787. }).state('approvalflow.productmatches', {
  788. url: "/productmatches",
  789. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  790. controller: 'ProductmatchesCtrl'
  791. }).state('sale.vendorPerformanceAssess', {
  792. url: "/vendorPerformanceAssess",
  793. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess.html",
  794. controller: 'VendorPerformanceAssessCtrl'
  795. }).state('sale.vendorPerformanceAssess_detail', {
  796. url: "/vendorPerformanceAssess/:id",
  797. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess_detail.html",
  798. controller: 'VendorPerformanceAssessDetailCtrl'
  799. });
  800. $urlRouterProvider.otherwise('sale/pubinquiry');
  801. }]);
  802. /**
  803. * 表示符号
  804. */
  805. app.factory('Symbol', function () {
  806. return {
  807. currency: function (cur) {
  808. if (cur == 'RMB') return '¥';
  809. else if (cur == 'USD') return '$';
  810. else if (cur == 'EUR') return '€';
  811. else if (cur == null || cur == '') return '¥';
  812. else return cur;
  813. }
  814. };
  815. }).factory('Lodop', function () {
  816. return {
  817. getLodop: function (oOBJECT, oEMBED) {
  818. var CreatedOKLodop7766 = null;
  819. /**************************
  820. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  821. IE系列、IE内核系列的浏览器采用oOBJECT,
  822. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  823. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  824. 64位浏览器指向64位的安装程序install_lodop64.exe。
  825. **************************/
  826. var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  827. var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  828. var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  829. var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  830. var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  831. var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  832. var LODOP;
  833. try {
  834. //=====判断浏览器类型:===============
  835. var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
  836. var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
  837. //=====如果页面有Lodop就直接使用,没有则新建:==========
  838. if (oOBJECT != undefined || oEMBED != undefined) {
  839. if (isIE)
  840. LODOP = oOBJECT;
  841. else
  842. LODOP = oEMBED;
  843. } else {
  844. if (CreatedOKLodop7766 == null) {
  845. LODOP = document.createElement("object");
  846. LODOP.setAttribute("width", 0);
  847. LODOP.setAttribute("height", 0);
  848. LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  849. if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  850. else LODOP.setAttribute("type", "application/x-print-lodop");
  851. document.documentElement.appendChild(LODOP);
  852. CreatedOKLodop7766 = LODOP;
  853. } else
  854. LODOP = CreatedOKLodop7766;
  855. }
  856. ;
  857. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  858. if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
  859. if (navigator.userAgent.indexOf('Chrome') >= 0)
  860. document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
  861. if (navigator.userAgent.indexOf('Firefox') >= 0)
  862. document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
  863. if (is64IE) document.write(strHtm64_Install); else if (isIE) document.write(strHtmInstall); else
  864. document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
  865. return LODOP;
  866. } else if (LODOP.VERSION < "6.1.9.8") {
  867. if (is64IE) document.write(strHtm64_Update); else if (isIE) document.write(strHtmUpdate); else
  868. document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
  869. return LODOP;
  870. }
  871. ;
  872. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  873. LODOP.SET_LICENSES("深圳市优软科技有限公司", "BBF53BD5AB0D522B3207D05CDE381F65", "", "");
  874. //============================================================
  875. return LODOP;
  876. } catch (err) {
  877. if (is64IE)
  878. document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML; else
  879. document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML;
  880. return LODOP;
  881. }
  882. ;
  883. }
  884. }
  885. });
  886. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', 'toaster', 'AccountEnterprise', function ($scope, $rootScope, $modal, toaster, AccountEnterprise) {
  887. $rootScope.$on('$locationChangeSuccess', function (evt, newUrl) {
  888. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  889. if (routeState.indexOf('/') > -1)
  890. routeState = routeState.substring(0, routeState.indexOf('/'));
  891. if (routeState.indexOf('.') > -1)
  892. routeState = routeState.substring(0, routeState.indexOf('.'));
  893. $scope.routeState = routeState || 'home';
  894. });
  895. $scope.search = function (keyword) {
  896. if (keyword != null && keyword != '') {
  897. $rootScope.searchKeyword = keyword;
  898. window.location.hash = '#/search?keyword=' + keyword;
  899. } else {
  900. $rootScope.searchKeyword = null;
  901. window.location.hash = '#/search';
  902. }
  903. };
  904. $scope.showMessage = function () {
  905. var modalInstance = $modal.open({
  906. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  907. controller: 'PagingReleaseCtrl'
  908. });
  909. };
  910. // 连接到询价
  911. $scope.linktoInquiry = function (active) {
  912. $rootScope.active = active;
  913. window.location.href = "#/sale/inquiry";
  914. }
  915. // 连接到招标
  916. $scope.linktoSaleTender = function (active) {
  917. $rootScope.active = active;
  918. window.location.href = "#/sale/tender";
  919. }
  920. // 链接到打样申请
  921. $scope.linktoSample = function (active) {
  922. $rootScope.active = active;
  923. window.location.href = "#/sale/sample";
  924. }
  925. // 链接到采购招标
  926. $scope.linktoPurcTender = function (active) {
  927. $rootScope.tenderActive = active;
  928. window.location.href = "#/purc/tender";
  929. }
  930. $scope.linktoPurcInquiry = function (active) {
  931. $rootScope.active = active;
  932. window.location.href = "#/purc/purchaseinquiry";
  933. }
  934. // 跳转到B2C
  935. $scope.b2cLink = function (url) {
  936. AccountEnterprise.getB2cUrl({}, function(data) {
  937. if (url == '/help/home') {
  938. window.open(data.url + url, '_target')
  939. } else {
  940. window.location.href = data.url + url;
  941. }
  942. });
  943. }
  944. }]);
  945. app.controller('AdController', ['$scope', '$modal', '$interval', function($scope, $modal, $interval) {
  946. // 广告操作
  947. $scope.count = 5;
  948. $scope.bannerShow = true;
  949. $scope.imgAnmiation = false;
  950. $scope.jingKongAnmiation = true;
  951. $scope.imgShow = true;
  952. $scope.Times = $interval(function () {
  953. $scope.count--;
  954. if ($scope.count <= 0) {
  955. $scope.count = 5;
  956. $scope.jingKongAnmiation = false;
  957. $interval.cancel($scope.Times);
  958. $scope.closeClick();
  959. }
  960. }, 1000);
  961. // 金控广告动画设置
  962. $scope.closeClick = function () {
  963. $scope.jingKongAnmiation = false;
  964. if ($scope.bannerShow === false) {
  965. $scope.imgAnmiation = false;
  966. $scope.imgShow = false;
  967. } else {
  968. $scope.bannerShow = false;
  969. $scope.imgAnmiation = true;
  970. }
  971. }
  972. }]);
  973. /**
  974. * 新消息提醒(调用公共服务接口) -2018-01-22 19:36:50
  975. * @author dongbw
  976. */
  977. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'PagingReleaseInfo',
  978. function ($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance, PagingReleaseInfo) {
  979. $scope.active = "todo";
  980. $scope.setActive = function (state) {
  981. if ($scope.active != state) {
  982. $scope.active = state;
  983. if ($scope.tableParams.page() == 1)
  984. $scope.tableParams.reload();
  985. else
  986. $scope.tableParams.page(1);
  987. }
  988. };
  989. /**
  990. * 页面状态按钮过滤
  991. */
  992. var getMessageState = function (active) {
  993. var fn = 'get';
  994. switch (active) {
  995. case 'done':
  996. fn = 'getDone';
  997. break;
  998. case 'todo':
  999. fn = 'getTodo';
  1000. break;
  1001. }
  1002. return fn;
  1003. };
  1004. $scope.tableParams = new ngTableParams({
  1005. page: 1,
  1006. count: 5,
  1007. sorting: {
  1008. 'createTime': 'desc'
  1009. }
  1010. }, {
  1011. total: 0,
  1012. counts: [],
  1013. getData: function ($defer, params) {
  1014. $scope.loading = true;
  1015. var pageParams = params.url();
  1016. var realActive = {};
  1017. pageParams.searchFilter = { // 筛选条件
  1018. keyword: $scope.keyword
  1019. // fromDate: getDateTime($scope.condition.dateFrom),
  1020. // endDate: getDateTime($scope.condition.dateTo)
  1021. };
  1022. PagingRelease[getMessageState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1023. $scope.loading = false;
  1024. if (page) {
  1025. params.total(page.totalElements);
  1026. $defer.resolve(page.content);
  1027. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  1028. }
  1029. }, function (response) {
  1030. $scope.loading = false;
  1031. toaster.pop('error', '数据加载失败', response.data);
  1032. });
  1033. }
  1034. });
  1035. $scope.close = function () {
  1036. $modalInstance.close();
  1037. window.location.reload();
  1038. };
  1039. $scope.checks = {
  1040. checked: false
  1041. };// 全选框
  1042. $scope.checkAll = function () {
  1043. angular.forEach($scope.tableParams.data, function (message) {
  1044. message.checked = $scope.checks.checked;
  1045. });
  1046. };
  1047. // 单选
  1048. $scope.checkOne = function (vendor) {
  1049. vendor.checked = true;
  1050. var checked = true;
  1051. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  1052. if (!message.checked) {
  1053. checked = false;
  1054. }
  1055. });
  1056. $scope.checks.checked = checked;
  1057. };
  1058. // 单反选
  1059. $scope.unCheckOne = function (vendor) {
  1060. vendor.checked = false;
  1061. $scope.checks.checked = false;
  1062. };
  1063. /**
  1064. * 当前页标为已读
  1065. */
  1066. $scope.setRead = function () {
  1067. $scope.loading = true;
  1068. var messageIds = [];
  1069. angular.forEach($scope.tableParams.data, function(message) {
  1070. messageIds.push(message.id);
  1071. });
  1072. PagingRelease.setPageRead({}, messageIds, function (data) {
  1073. $scope.loading = false;
  1074. if (data.success) {
  1075. toaster.pop("success", "设置已读成功");
  1076. }
  1077. if (data.error) {
  1078. toaster.pop("error", "设置已读失败");
  1079. }
  1080. $scope.tableParams.page(1);
  1081. $scope.tableParams.reload();
  1082. });
  1083. };
  1084. // 点击内容连接之后,信息标为已读
  1085. $scope.setOneRead = function (id) {
  1086. $scope.loading = true;
  1087. $modalInstance.close();
  1088. PagingRelease.setMessageRead({id: id}, {}, function (data) {
  1089. $scope.loading = false;
  1090. }, function (response) {
  1091. $scope.loading = false;
  1092. toaster.pop('error', '提示', response.data);
  1093. });
  1094. };
  1095. // 搜索框回车
  1096. $scope.onSearch = function () {
  1097. $scope.tableParams.page(1);
  1098. $scope.tableParams.reload();
  1099. };
  1100. }]);
  1101. // 高亮显示关键词
  1102. app.filter('getkey', ['$sce', '$rootScope', function ($sce, $rootScope) {
  1103. var search = $rootScope.searchKeyword;
  1104. return function (content, search) {
  1105. content = encodeURI(content);
  1106. search = encodeURI(search);
  1107. var reg = new RegExp(search, 'gim');
  1108. var result = content.replace(reg, '<font color="red">$&</font>');
  1109. result = decodeURIComponent(result);
  1110. return $sce.trustAsHtml(result);
  1111. };
  1112. $rootScope.searchKeyword = null;// 清除缓存的关键字
  1113. }]);
  1114. /**
  1115. * 顶部搜索
  1116. */
  1117. app.controller('TopSearchCtrl', ['$scope', '$rootScope', 'getAccountUserSpace', 'ngTableParams', 'toaster', 'BaseService', 'AddPartner', '$filter', '$stateParams', 'SearchProd', '$sce', '$modal', 'InvitationRecord', function ($scope, $rootScope, getAccountUserSpace, ngTableParams, toaster, BaseService, AddPartner, $filter, $stateParams, SearchProd, $sce, $modal, InvitationRecord) {
  1118. BaseService.scrollBackToTop();
  1119. $scope.active = 'all';
  1120. $scope.tip = $rootScope.searchKeyword;
  1121. // 企业搜索
  1122. var getService = function () {
  1123. return getAccountUserSpace;
  1124. };
  1125. $scope.tableParams = new ngTableParams({
  1126. page: 1,
  1127. count: 20,
  1128. sorting: {}
  1129. }, {
  1130. total: 0,
  1131. counts: [5, 10, 25, 50],
  1132. getData: function ($defer, params) {
  1133. $scope.loading = true;
  1134. var pageParams = params.url();
  1135. pageParams.keyword = $rootScope.searchKeyword;
  1136. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1137. $scope.loading = false;
  1138. if (page) {
  1139. $scope.total = page.totalElement;
  1140. params.total(page.totalElement);
  1141. $defer.resolve(page.content);
  1142. }
  1143. }, function (response) {
  1144. $scope.loading = false;
  1145. toaster.pop('error', '数据加载失败', response.data);
  1146. });
  1147. }
  1148. });
  1149. // 添加合作关系
  1150. $scope.addPartner = function (name, businessCode) {
  1151. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  1152. if (data.success) {
  1153. toaster.pop("success", '添加成功', data.success);
  1154. $scope.tableParams.reload();
  1155. }
  1156. if (data.error) {
  1157. toaster.pop("error", '添加失败', data.error);
  1158. }
  1159. }, function (response) {
  1160. toaster.pop('error', '失败', response.data);
  1161. });
  1162. }
  1163. // 物料搜索
  1164. var getProdService = function () {
  1165. return SearchProd;
  1166. };
  1167. $scope.prodTableParams = new ngTableParams({
  1168. page: 1,
  1169. count: 20,
  1170. sorting: {}
  1171. }, {
  1172. total: 0,
  1173. counts: [5, 10, 25, 50],
  1174. getData: function ($defer, params) {
  1175. $scope.loading = true;
  1176. var pageParams = params.url();
  1177. pageParams.keyword = $rootScope.searchKeyword;
  1178. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1179. $scope.loading = false;
  1180. if (page) {
  1181. $scope.prodtotal = page.totalElement;
  1182. params.total(page.totalElement);
  1183. $defer.resolve(page.content);
  1184. }
  1185. }, function (response) {
  1186. $scope.loading = false;
  1187. toaster.pop('error', '数据加载失败', response.data);
  1188. });
  1189. }
  1190. });
  1191. /**
  1192. * 向企业购买
  1193. */
  1194. $scope.PurcByEn = function (businessCode) {
  1195. $rootScope.businessCode = businessCode;
  1196. window.location.hash = "#/purc/addOrder";
  1197. }
  1198. /**
  1199. * 选中单个物料购买
  1200. * @param businessCode
  1201. * @param id
  1202. */
  1203. $scope.PurcByEnAndProd = function (businessCode, id) {
  1204. $rootScope.businessCode = businessCode;
  1205. $rootScope.prodId = id;
  1206. window.location.hash = "#/purc/addOrder";
  1207. }
  1208. /**
  1209. * 询价
  1210. */
  1211. $scope.PurcInquiry = function (businessCode, id) {
  1212. $rootScope.prodId = id;
  1213. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1214. }
  1215. /**
  1216. * 邀请注册商务平台
  1217. */
  1218. $scope.invite = function (name) {
  1219. var modalInstance = $modal.open({
  1220. animation: true,
  1221. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1222. controller: 'InviteCtrl',
  1223. resolve: {
  1224. enname: function () {
  1225. return name
  1226. }
  1227. }
  1228. });
  1229. modalInstance.result.then(function (data) {
  1230. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1231. if (data.success) {
  1232. toaster.pop('success', '提示', data.success);
  1233. }
  1234. if (data.error) {
  1235. toaster.pop('error', '提示', data.error);
  1236. }
  1237. }, function (response) {
  1238. toaster.pop('error', '提示', response.data);
  1239. });
  1240. });
  1241. }
  1242. /**
  1243. * 立即查看
  1244. */
  1245. $scope.view = function (name) {
  1246. $rootScope.vendName = name;
  1247. window.location.hash = "#/baseInfo/newPartner";
  1248. }
  1249. }]);
  1250. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', 'InvitationRecord', '$modal', function ($scope, toaster, $modalInstance, enname, InvitationRecord, $modal) {
  1251. $scope.enter = {
  1252. vendname: enname
  1253. };
  1254. $scope.save = function (enter) {
  1255. // 先检验是否已注册
  1256. InvitationRecord.enterpriseList({name: enter.vendname}, {}, function(data) {
  1257. $scope.existEn = data;
  1258. if ($scope.existEn.length == 0) {
  1259. $modalInstance.close(enter);
  1260. var modalInstance = $modal.open({
  1261. animation: true,
  1262. templateUrl: 'static/tpl/index/baseInfo/modal/QQshare_modal.html',
  1263. controller: 'QQShareCtrl',
  1264. });
  1265. } else {
  1266. $scope.enterprise = $scope.existEn[0];
  1267. }
  1268. });
  1269. }
  1270. $scope.viewDetail = function() {
  1271. $scope.exist = 1;
  1272. }
  1273. $scope.cancel = function () {
  1274. $modalInstance.dismiss();
  1275. }
  1276. $scope.closeDetail = function() {
  1277. $scope.exist = 0;
  1278. }
  1279. /**
  1280. * 添加合作伙伴
  1281. * @param enterprise
  1282. */
  1283. $scope.addPartner = function(en) {
  1284. InvitationRecord.addPart({inviteEnUU: $scope.enterprise.uu, inviteUserName: en.vendusername, inviteUserTel: en.vendusertel}, {}, function(data) {
  1285. if (data.success) {
  1286. toaster.pop('success', data.success);
  1287. $modalInstance.dismiss();
  1288. } else if (data.error) {
  1289. toaster.pop('error', data.error);
  1290. }
  1291. }, function(response) {
  1292. toaster.pop('error', response.data);
  1293. });
  1294. }
  1295. }]);
  1296. /**
  1297. * QQ分享
  1298. */
  1299. app.controller('QQShareCtrl', ['$scope', 'InvitationRecord', '$modalInstance', function($scope, InvitationRecord, $modalInstance) {
  1300. InvitationRecord.getInviteUrl({}, function(data) {
  1301. $scope.inviteUrl = data.url;
  1302. var p = {
  1303. url: $scope.inviteUrl, /*获取URL,可加上来自分享到QQ标识,方便统计*/
  1304. // desc: 'hejq', /*分享理由(风格应模拟用户对话),支持多分享语随机展现(使用|分隔)*/
  1305. // title: '', /*分享标题(可选)*/
  1306. // summary: '', /*分享摘要(可选)*/
  1307. // pics: '', /*分享图片(可选)*/
  1308. // flash: '', /*视频地址(可选)*/
  1309. // site: '', /*分享来源(可选) 如:QQ分享*/
  1310. // style: '201',
  1311. // width: 32,
  1312. // height: 32
  1313. };
  1314. var s = [];
  1315. for(var i in p){
  1316. s.push(i + '=' + encodeURIComponent(p[i]||''));
  1317. }
  1318. s.join('&');
  1319. $scope.QQshare = function() {
  1320. window.open("http://connect.qq.com/widget/shareqq/index.html?" + s)
  1321. }
  1322. });
  1323. $scope.close = function() {
  1324. $modalInstance.dismiss();
  1325. }
  1326. }]);
  1327. /**
  1328. * 再次邀请
  1329. */
  1330. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function ($scope, toaster, $modalInstance, id, InvitationRecord) {
  1331. var loadData = function (id) {
  1332. InvitationRecord.getRecordById({id: id}, {}, function (data) {
  1333. if (data.user !== null) {
  1334. data.user = {};
  1335. }
  1336. $scope.enter = data;
  1337. });
  1338. };
  1339. loadData(id);
  1340. $scope.save = function (enter) {
  1341. if (!enter.vendusertel && !enter.venduseremail) {
  1342. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1343. } else {
  1344. $modalInstance.close(enter);
  1345. }
  1346. };
  1347. $scope.cancel = function () {
  1348. $modalInstance.dismiss();
  1349. }
  1350. }]);
  1351. /**
  1352. * 邀请记录
  1353. */
  1354. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function ($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1355. BaseService.scrollBackToTop();
  1356. $scope.status = "invitation";
  1357. $scope.active = "invitation";
  1358. var getService = function () {
  1359. if ($scope.active === "invitation") {
  1360. return InvitationRecord.records;
  1361. } else if ($scope.active === "invitationTeam") {
  1362. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1363. }
  1364. };
  1365. $scope.setActive = function (state) {
  1366. if ($scope.active !== state) {
  1367. $scope.active = state;
  1368. if ($scope.tableParams.page() === 1)
  1369. $scope.tableParams.reload();
  1370. else
  1371. $scope.tableParams.page(1);
  1372. }
  1373. };
  1374. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1375. page: 1,
  1376. count: 20,
  1377. sorting: {}
  1378. }, {
  1379. total: 0,
  1380. counts: [],
  1381. getData: function ($defer, params) { // 获取数据的方法
  1382. $scope.loading = true;
  1383. var pageParams = params.url();
  1384. pageParams.keyword = $scope.keyword;
  1385. $scope.tip = $scope.keyword;
  1386. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  1387. $scope.loading = false;
  1388. if (page) {
  1389. params.total(page.totalElement);
  1390. $defer.resolve(page.content);
  1391. }
  1392. }, function (response) {
  1393. $scope.loading = false;
  1394. toaster.pop('error', '数据加载失败', response.data);
  1395. });
  1396. }
  1397. });
  1398. $scope.onSearch = function (keyword) {
  1399. $scope.tableParams.page(1);
  1400. $scope.tableParams.reload();
  1401. $scope.tip = keyword;
  1402. }
  1403. $scope.search = function (name) {
  1404. $modal.open({
  1405. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1406. controller: 'FuzzySearchCtrl',
  1407. resolve: {
  1408. name: function () {
  1409. return name
  1410. }
  1411. }
  1412. }).result.then(function (data) {
  1413. });
  1414. };
  1415. // 再次邀请
  1416. $scope.reInvite = function (id) {
  1417. var modalInstance = $modal.open({
  1418. animation: true,
  1419. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1420. controller: 'ReInviteCtrl',
  1421. resolve: {
  1422. id: function () {
  1423. return id
  1424. }
  1425. }
  1426. });
  1427. modalInstance.result.then(function (data) {
  1428. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1429. if (data.success) {
  1430. toaster.pop('success', '提示', data.success);
  1431. $scope.tableParams.reload();
  1432. }
  1433. if (data.error) {
  1434. toaster.pop('error', '提示', data.error);
  1435. }
  1436. }, function (response) {
  1437. toaster.pop('error', '提示', response.data);
  1438. });
  1439. });
  1440. }
  1441. }]);
  1442. /**
  1443. * 模糊查询相似的企业名称
  1444. */
  1445. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function ($scope, name, InvitationRecord, toaster, BaseService) {
  1446. $scope.name = name;
  1447. if ($scope.name != null) {
  1448. InvitationRecord.enterpriseList({name: $scope.name}, {}, function (data) {
  1449. $scope.enterprises = data;
  1450. }, function (response) {
  1451. toaster.pop('error', '提示', response.data);
  1452. });
  1453. }
  1454. }]);
  1455. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function ($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1456. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1457. AuthenticationService.getAuthentication().success(function (data) {
  1458. if (data.enterprises) {
  1459. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1460. if (data.enterprises.length > 1) {
  1461. var enSelect = [];
  1462. angular.forEach(data.enterprises, function (e) {
  1463. if (e.current)
  1464. data.enterprise = e;
  1465. else
  1466. enSelect.push(e);
  1467. });
  1468. data.enSelect = enSelect;
  1469. }
  1470. }
  1471. $scope.userInfo = data;
  1472. if (data == null || !data.userUU) {
  1473. $scope.isAuthed = false;
  1474. AuthenticationService.redirectSignin();
  1475. } else {
  1476. }
  1477. });
  1478. $scope.logout = function () {
  1479. $modal.open({
  1480. templateUrl: 'static/tpl/index/account/logout.html',
  1481. controller: 'LogOutCtrl'
  1482. }).result.then(function (s) {
  1483. if (s) {
  1484. AuthenticationService.logout();
  1485. }
  1486. });
  1487. };
  1488. // 打开登录模态框
  1489. $scope.signinModal = function() {
  1490. // 跳转账户中心
  1491. AuthenticationService.redirectSignin();
  1492. };
  1493. // 注册
  1494. $scope.registerModal = function() {
  1495. // 跳转账户中心
  1496. AuthenticationService.redirectRegister();
  1497. };
  1498. $scope.switchto = function (enUU) {// 切换企业
  1499. AuthenticationService.reSignin(enUU).success(function (response) {
  1500. console.log(response);
  1501. if (!response) $window.location.reload();
  1502. $.ajax({
  1503. url:response.url,
  1504. data:response.data,
  1505. type:"get",
  1506. cache:false,
  1507. dataType:"jsonp",
  1508. jsonp:"callback",
  1509. jsonpCallback:"successCallback",
  1510. success:function(data){
  1511. console.log(data);
  1512. },
  1513. error:function(data){
  1514. console.log(data);
  1515. }
  1516. });
  1517. $window.location.reload();
  1518. });
  1519. };
  1520. $scope.addFavorite = function () {
  1521. var url = encodeURI(window.location.href);
  1522. try {
  1523. //ie浏览器收藏方式
  1524. window.external.addFavorite(url, "优软商务平台");
  1525. } catch (e) {
  1526. try {
  1527. //火狐浏览器收藏方式
  1528. window.sidebar.addPanel("优软商务平台", url);
  1529. } catch (e) {
  1530. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加," +
  1531. "或手动在浏览器里进行设置。");
  1532. }
  1533. }
  1534. };
  1535. }]);
  1536. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1537. $scope.close = function (confirm) {
  1538. $modalInstance.close(confirm);
  1539. };
  1540. }]);
  1541. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1542. $scope.image = {src: null};
  1543. // 图片上传成功之后
  1544. $scope.onUploadSuccess = function (data) {
  1545. var path = data.path;
  1546. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1547. $scope.$apply(function () {
  1548. $scope.image.src = data.path;
  1549. $scope.image.thumb = path;
  1550. });
  1551. };
  1552. $scope.close = function () {
  1553. $modalInstance.dismiss();
  1554. };
  1555. $scope.confirm = function () {
  1556. $modalInstance.close($scope.image);
  1557. $scope.imageUrl = null;
  1558. };
  1559. }]);
  1560. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', '$modal',
  1561. function ($scope, SnapshotService, BaseService, $rootScope, $modal) {
  1562. BaseService.scrollBackToTop();
  1563. SnapshotService.getTodo(function (data) {
  1564. $scope.todo = data;
  1565. });
  1566. var getUnread = function () {
  1567. SnapshotService.getUnread('all', function (data) {
  1568. $scope.unread = data;
  1569. });
  1570. };
  1571. getUnread();
  1572. //去除红点
  1573. $scope.setOrdersRead = function (type) {
  1574. switch (type){
  1575. case 'product':
  1576. $scope.unread.product = 0;
  1577. break;
  1578. case 'vendorPerformanceAssess':
  1579. $scope.unread.vendorPerformanceAssess = 0;
  1580. break;
  1581. case 'customer':
  1582. $scope.unread.customer = 0;
  1583. break;
  1584. case 'purcProduct':
  1585. $scope.unread.purcProduct = 0;
  1586. break;
  1587. case 'vendor':
  1588. $scope.unread.purcVendor = 0;
  1589. break;
  1590. }
  1591. };
  1592. $scope.setTenderActive = function (active) {
  1593. $rootScope.tenderActive = active;
  1594. window.location.hash = '#/purc/tender';
  1595. }
  1596. }]);
  1597. // header
  1598. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1599. SnapshotService.getMessage(function (data) {
  1600. $scope.message = data;
  1601. });
  1602. }]);
  1603. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function ($scope, $rootScope, $modal, SaleTruck) {
  1604. SaleTruck.query({}, function (data) {
  1605. $rootScope.truck = data;
  1606. $scope.truckCount = data ? data.length : 0;
  1607. });
  1608. $scope.$watch(function () {
  1609. return $rootScope.truck;
  1610. }, function (data) {
  1611. $scope.truckCount = data ? data.length : 0;
  1612. }, true);
  1613. $scope.clearAll = function () {
  1614. SaleTruck.remove({}, function () {
  1615. $rootScope.truck = [];
  1616. });
  1617. };
  1618. $scope.openTrack = function () {
  1619. $modal.open({
  1620. templateUrl: 'static/tpl/index/sale/track.html',
  1621. controller: 'TruckModalCtrl',
  1622. size: 'lg'
  1623. }).result.then(function (s) {
  1624. if (s) {
  1625. $scope.clearAll();
  1626. $rootScope.dataChanged = true;
  1627. }
  1628. });
  1629. };
  1630. }]);
  1631. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', 'token', function ($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout, token) {
  1632. $scope.loading = false;
  1633. $scope.saleSend = {sendItems: []};
  1634. SaleTruck.detail({}, function (data) {
  1635. // 按物料编号排序
  1636. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1637. });
  1638. $scope.remove = function (index, notice) {
  1639. SaleTruck.remove({noticeId: notice.id}, function (data) {
  1640. $rootScope.truck = data;
  1641. $scope.notices.splice(index, 1);
  1642. });
  1643. };
  1644. $scope.$watch(function () {
  1645. return $scope.notices;
  1646. }, function (data) {
  1647. var q = 0, t = 0;
  1648. if (data) {
  1649. angular.forEach(data, function (d) {
  1650. q += d.thisSendQty;
  1651. t += d.thisSendQty * d.orderItem.price;
  1652. });
  1653. }
  1654. $scope.totalQty = q;
  1655. $scope.total = t;
  1656. }, true);
  1657. $scope.cancel = function () {
  1658. $modalInstance.close();
  1659. };
  1660. $scope.lockstatus = false;
  1661. // 锁定时间按钮5秒
  1662. $scope.lockClick = function () {
  1663. $scope.lockstatus = true;
  1664. $timeout(function () {
  1665. $scope.lockstatus = false;
  1666. }, 5000);
  1667. }
  1668. var getToken = function() {
  1669. token.info({userType: 'salenotice'}, {}, function(data) {
  1670. $scope.token = data.token;
  1671. }, function(response) {
  1672. toaster.pop('error', '提示', response.data);
  1673. });
  1674. }
  1675. getToken();
  1676. $scope.send = function () {// 发货
  1677. $scope.loading = true;
  1678. if (!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1679. toaster.pop('error', '错误', '请输入送货单号');
  1680. $scope.loading = false;
  1681. return;
  1682. }
  1683. var currency = $scope.notices[0].orderItem.order.currency,
  1684. custUU = $scope.notices[0].enUU,
  1685. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1686. var num = 1;
  1687. for (var i in $scope.notices) {
  1688. var item = $scope.notices[i];
  1689. if (item.id) {
  1690. if (item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1691. valid = false;
  1692. break;
  1693. }
  1694. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++};
  1695. }
  1696. }
  1697. if (!valid) {
  1698. $scope.loading = false;
  1699. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  1700. } else {
  1701. var send = angular.extend(angular.copy($scope.saleSend), {
  1702. currency: currency,
  1703. custUU: custUU,
  1704. payments: payments,
  1705. sendItems: items
  1706. });
  1707. if($scope.token != null) {
  1708. PurcNotice.sendByBatch({token: $scope.token}, send, function (data) {
  1709. $scope.loading = false;
  1710. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1711. $modalInstance.close(true);
  1712. $state.go('sale.send_detail', {id: data.id});
  1713. }, function (response) {
  1714. $scope.loading = false;
  1715. toaster.pop('error', '错误', response.data);
  1716. });
  1717. }
  1718. }
  1719. $scope.setCheckedNoticeRead = function () {
  1720. var ids = [];
  1721. for (var i in $scope.notices) {
  1722. var item = $scope.notices[i];
  1723. if (item.id) {
  1724. ids.push(item.id);
  1725. }
  1726. }
  1727. PurcNotice.setRead({}, ids, function (message) {
  1728. });
  1729. }
  1730. };
  1731. }]);
  1732. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1733. SaleStat.cust({}, function (data) {
  1734. var p = [], q = [];
  1735. angular.forEach(data.month, function (d) {
  1736. p.push({
  1737. x: (d.enterprise.enShortname || d.enterprise.enName),
  1738. y: [(d.total || 0)],
  1739. tooltip: (d.total || 0)
  1740. });
  1741. });
  1742. angular.forEach(data.year, function (d) {
  1743. q.push({
  1744. x: (d.enterprise.enShortname || d.enterprise.enName),
  1745. y: [(d.total || 0)],
  1746. tooltip: (d.total || 0)
  1747. });
  1748. });
  1749. $scope.custCharts = {
  1750. month: {
  1751. chartType: 'pie',
  1752. datas: {
  1753. data: p
  1754. },
  1755. config: {
  1756. labels: false,
  1757. title: "客户月采购量排行榜",
  1758. legend: {
  1759. display: true,
  1760. position: 'right'
  1761. },
  1762. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1763. click: function (d) {
  1764. },
  1765. mouseover: function (d) {
  1766. },
  1767. mouseout: function (d) {
  1768. },
  1769. innerRadius: 0,
  1770. lineLegend: 'lineEnd'
  1771. }
  1772. },
  1773. year: {
  1774. chartType: 'pie',
  1775. datas: {
  1776. data: q
  1777. },
  1778. config: {
  1779. labels: false,
  1780. title: "客户年采购量排行榜",
  1781. legend: {
  1782. display: true,
  1783. position: 'right'
  1784. },
  1785. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1786. click: function (d) {
  1787. },
  1788. mouseover: function (d) {
  1789. },
  1790. mouseout: function (d) {
  1791. },
  1792. innerRadius: 0,
  1793. lineLegend: 'lineEnd'
  1794. }
  1795. }
  1796. };
  1797. });
  1798. SaleStat.seller({}, function (data) {
  1799. var p = [], q = [];
  1800. angular.forEach(data.month, function (d) {
  1801. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1802. });
  1803. angular.forEach(data.year, function (d) {
  1804. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1805. });
  1806. $scope.sellerCharts = {
  1807. month: {
  1808. chartType: 'pie',
  1809. datas: {
  1810. data: p
  1811. },
  1812. config: {
  1813. labels: false,
  1814. title: "业务员月销量排行榜",
  1815. legend: {
  1816. display: true,
  1817. position: 'right'
  1818. },
  1819. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1820. click: function (d) {
  1821. },
  1822. mouseover: function (d) {
  1823. },
  1824. mouseout: function (d) {
  1825. },
  1826. innerRadius: 0,
  1827. lineLegend: 'lineEnd'
  1828. }
  1829. },
  1830. year: {
  1831. chartType: 'pie',
  1832. datas: {
  1833. data: q
  1834. },
  1835. config: {
  1836. labels: false,
  1837. title: "业务员年销量排行榜",
  1838. legend: {
  1839. display: true,
  1840. position: 'right'
  1841. },
  1842. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1843. click: function (d) {
  1844. },
  1845. mouseover: function (d) {
  1846. },
  1847. mouseout: function (d) {
  1848. },
  1849. innerRadius: 0,
  1850. lineLegend: 'lineEnd'
  1851. }
  1852. }
  1853. };
  1854. });
  1855. }]);
  1856. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1857. SaleStat.get({}, function (data) {
  1858. var p = [], q = [], r = [];
  1859. angular.forEach(data.day, function (d) {
  1860. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1861. });
  1862. angular.forEach(data.month, function (d) {
  1863. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1864. });
  1865. angular.forEach(data.year, function (d) {
  1866. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1867. });
  1868. $scope.charts = {
  1869. day: {
  1870. chartType: "line",
  1871. datas: {
  1872. series: ['销售额'],
  1873. data: p
  1874. },
  1875. config: {
  1876. "labels": false,
  1877. "title": "销售额统计(近15日线)",
  1878. "legend": {
  1879. "display": true,
  1880. "position": "right"
  1881. },
  1882. colors: ['#4D9934'],
  1883. "innerRadius": 0,
  1884. "lineLegend": "lineEnd"
  1885. }
  1886. },
  1887. month: {
  1888. chartType: "line",
  1889. datas: {
  1890. series: ['销售额'],
  1891. data: q
  1892. },
  1893. config: {
  1894. "labels": false,
  1895. "title": "销售额统计(近12月线)",
  1896. "legend": {
  1897. "display": true,
  1898. "position": "right"
  1899. },
  1900. colors: ['#4D9934'],
  1901. "innerRadius": 0,
  1902. "lineLegend": "lineEnd"
  1903. }
  1904. },
  1905. year: {
  1906. chartType: "line",
  1907. datas: {
  1908. series: ['销售额'],
  1909. data: r
  1910. },
  1911. config: {
  1912. "labels": false,
  1913. "title": "销售额统计(近10年线)",
  1914. "legend": {
  1915. "display": true,
  1916. "position": "right"
  1917. },
  1918. colors: ['#4D9934'],
  1919. "innerRadius": 0,
  1920. "lineLegend": "lineEnd"
  1921. }
  1922. }
  1923. };
  1924. });
  1925. }]);
  1926. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', 'AuthenticationService', function ($scope, SnapshotService, AuthenticationService) {
  1927. AuthenticationService.getAuthentication().success(function (data) {
  1928. $scope.loading = false;
  1929. $scope.useruu = data.userUU;
  1930. SnapshotService.getNotice(7, $scope.useruu, function (data) { //5表示首页显示的公告条数
  1931. $scope.notices = data;
  1932. });
  1933. /**
  1934. * 设置单据阅读状态
  1935. * @param id
  1936. */
  1937. $scope.setReadStatus = function(id) {
  1938. SnapshotService.setNoticeStatusAfterRead(id, $scope.useruu);
  1939. }
  1940. /**
  1941. * 判断是否当天时间
  1942. * @param date
  1943. * @param time
  1944. * @returns {boolean}
  1945. */
  1946. $scope.isCurrentTime = function(date, time) {
  1947. var date1 = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
  1948. var date2 = new Date(time).getFullYear() + '-' + new Date(time).getMonth() + 1 + '-' + new Date(time).getDate();
  1949. return date1 == date2;
  1950. }
  1951. });
  1952. $scope.dateTime = new Date();
  1953. $scope.time = new Date().getTime();
  1954. }]);
  1955. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1956. SnapshotService.getOpenTender(5, function (data) {
  1957. $scope.openTenders = data;
  1958. var newDate = new Date();
  1959. newDate = newDate.getTime() - 3 * 24 * 60 * 60 * 1000;
  1960. angular.forEach($scope.openTenders, function (tender) {
  1961. if (tender.date - newDate > 0) {
  1962. tender.isNew = true;
  1963. } else {
  1964. tender.isNew = false;
  1965. }
  1966. });
  1967. });
  1968. $scope.dateTime = new Date();
  1969. }]);
  1970. app.controller('VendCountCtrl', ['$scope', 'VendorService', function ($scope, VendorService) {
  1971. VendorService.getCount(function (date) {
  1972. $scope.count = date;
  1973. });
  1974. }]);
  1975. // 客户
  1976. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  1977. BaseService.scrollBackToTop();
  1978. $scope.userInfoResult = true;
  1979. AuthenticationService.getAuthentication().success(function (data) {
  1980. $scope.loading = false;
  1981. $scope.thisUser = data;
  1982. });
  1983. // 获取当前用户分配客户的操作权限
  1984. CurrentRole.roles({}, function (data) {
  1985. // 存在权限或者user表sys字段为1时
  1986. $scope.enabled = data.count > 0 || $scope.thisUser.sys;
  1987. }, function (response) {
  1988. });
  1989. var getCustInfos = function (custuu) {
  1990. if (custuu) {
  1991. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  1992. $scope.custInfos = data;
  1993. var getPage = function (page, size) {
  1994. if ($scope.custInfos) {
  1995. var result = {};
  1996. result.totalCount = $scope.custInfos.length;
  1997. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  1998. if ($scope.custInfos.length % size == 0) {
  1999. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2000. } else {
  2001. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2002. }
  2003. result.first = page == 1;
  2004. result.last = page == result.totalPage;
  2005. result.page = page;
  2006. result.next = page - 0 + 1;
  2007. result.pre = page - 1;
  2008. return result;
  2009. }
  2010. }
  2011. $scope.userdata = getPage(1, 4);
  2012. $scope.first = function () {
  2013. $scope.userdata = getPage($scope.userdata.pre, 4);
  2014. }
  2015. $scope.last = function () {
  2016. $scope.userdata = getPage($scope.userdata.next, 4);
  2017. }
  2018. }, function (response) {
  2019. $scope.loading = false;
  2020. toaster.pop('error', '数据加载失败', response.data);
  2021. });
  2022. }
  2023. }
  2024. // 分配用户
  2025. $scope.addUserInfo = function (customer) {
  2026. if (!$scope.enabled) {
  2027. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  2028. return;
  2029. }
  2030. // 获取当前用户在当前企业是否被转移权限
  2031. AccountUser.getEnTransfer ({custUU: customer.myEnterprise.uu}, function(data) {
  2032. customer.enTransfer = data.result;
  2033. //是管理员,或者被转移了权限时
  2034. if ($scope.enabled || customer.enTransfer) {
  2035. var modalInstance = $modal.open({
  2036. animation: true,
  2037. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2038. controller: 'AddUserInfoCtrl',
  2039. resolve: {
  2040. customer: function () {
  2041. return customer;
  2042. }
  2043. }
  2044. });
  2045. modalInstance.result.then(function (changed, checked) {
  2046. if (changed) {
  2047. if (checked)
  2048. $scope.newUser.roles = checked;
  2049. else
  2050. loadUsers();
  2051. }
  2052. });
  2053. } else {
  2054. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  2055. }
  2056. });
  2057. };
  2058. // 转移权限
  2059. $scope.transferUserInfo = function (customer) {
  2060. customer.enDistribute = null;
  2061. if (!$scope.enabled) {
  2062. toaster.pop('error', '您没有转移当前客户权限的权限!');
  2063. return;
  2064. }
  2065. // 获取当前用户在当前企业是否被转移权限
  2066. AccountUser.getDistribute ({custUU: customer.myEnterprise.uu}, function(data) {
  2067. customer.enDistribute = data.result;
  2068. //是管理员,或者被分配时
  2069. if ($scope.enabled || customer.enDistribute) {
  2070. var modalInstance = $modal.open({
  2071. animation: true,
  2072. templateUrl: 'static/tpl/index/account/transfer_userInfo.html',
  2073. controller: 'TransferUserInfoCtrl',
  2074. resolve: {
  2075. customer: function () {
  2076. return customer;
  2077. }
  2078. }
  2079. });
  2080. modalInstance.result.then(function (changed, checked) {
  2081. if (changed) {
  2082. if (checked)
  2083. $scope.newUser.roles = checked;
  2084. else
  2085. loadUsers();
  2086. }
  2087. });
  2088. } else {
  2089. toaster.pop('error', '您没有转移当前客户权限的权限!');
  2090. }
  2091. });
  2092. };
  2093. $scope.showUserInfo = function (customer, boo) {
  2094. $scope.custInfo = customer;
  2095. if (boo) {
  2096. getCustInfos(customer.myEnterprise.uu);
  2097. $scope.userInfoResult = true;
  2098. }
  2099. };
  2100. var getService = function () {
  2101. return VendorService;
  2102. };
  2103. $scope.customerParams = new ngTableParams({
  2104. page: 1,
  2105. count: 20
  2106. }, {
  2107. total: 0,
  2108. counts: [5, 10, 25, 50],
  2109. getData: function ($defer, params) {
  2110. $scope.loading = true;
  2111. var pageParams = params.url();
  2112. pageParams.keyword = $scope.keyword;
  2113. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  2114. $scope.loading = false;
  2115. if (page) {
  2116. params.total(page.totalElement);
  2117. $defer.resolve(page.content);
  2118. $scope.keywordXls = pageParams.keyword;
  2119. }
  2120. $scope.totalCount = page.totalElement;
  2121. }, function (response) {
  2122. $scope.loading = false;
  2123. toaster.pop('error', '数据加载失败', response.data);
  2124. });
  2125. }
  2126. });
  2127. //设置消息已读
  2128. var setOrdersRead = function () {
  2129. var sourceId = [];
  2130. Vendor.setRead({}, sourceId, function (message) {
  2131. // $scope.getUnreadIds();
  2132. });
  2133. };
  2134. setOrdersRead();
  2135. // 搜索框回车
  2136. $scope.onSearch = function (keyword) {
  2137. $scope.customerParams.page(1);
  2138. $scope.customerParams.reload();
  2139. $scope.tip = keyword;
  2140. };
  2141. // 查看详情
  2142. $scope.viewDetail = function (id) {
  2143. window.location.hash = "#/sale/customer/" + id;
  2144. }
  2145. // 导出客户资料列表
  2146. $scope.exportXls = function () {
  2147. VendorService.exportXls.get({}, {}, function (data) {
  2148. if (data.success){
  2149. window.location.href = 'vendor/customer/xls?keyword='+ ($scope.keywordXls || '');
  2150. }
  2151. }, function (response) {
  2152. toaster.pop('error', '数据加载失败', response.data);
  2153. });
  2154. }
  2155. }]);
  2156. // 客户详情
  2157. app.controller('CustomerDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', 'VendorService', 'AuthenticationService', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope, VendorService, AuthenticationService) {
  2158. BaseService.scrollBackToTop();
  2159. $scope.userInfoResult = true;
  2160. AuthenticationService.getAuthentication().success(function (data) {
  2161. $scope.loading = false;
  2162. $scope.thisUser = data;
  2163. });
  2164. $scope.vendorContacts = [];
  2165. var loadData = function () {
  2166. Vendor.getCustomerDetail({id: $stateParams.id}, {}, function (data) {
  2167. $scope.customer = data.myEnterprise;
  2168. $scope.customerInfo = data;
  2169. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function (data) {
  2170. $scope.Contacts = data;
  2171. });
  2172. // 查看已分配人员
  2173. VendorService.userInfo.query({uu: $scope.customer.uu}, null, function (data) {
  2174. $scope.custInfos = data;
  2175. var getPage = function (page, size) {
  2176. if ($scope.custInfos) {
  2177. var result = {};
  2178. result.totalCount = $scope.custInfos.length;
  2179. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  2180. if ($scope.custInfos.length % size == 0) {
  2181. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2182. } else {
  2183. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2184. }
  2185. result.first = page == 1;
  2186. result.last = page == result.totalPage;
  2187. result.page = page;
  2188. result.next = page - 0 + 1;
  2189. result.pre = page - 1;
  2190. return result;
  2191. }
  2192. }
  2193. $scope.userdata = getPage(1, 4);
  2194. $scope.first = function () {
  2195. $scope.userdata = getPage($scope.userdata.pre, 4);
  2196. }
  2197. $scope.last = function () {
  2198. $scope.userdata = getPage($scope.userdata.next, 4);
  2199. }
  2200. }, function (response) {
  2201. $scope.loading = false;
  2202. toaster.pop('error', '数据加载失败', response.data);
  2203. });
  2204. }, function (response) {
  2205. $scope.loading = false;
  2206. toaster.pop('error', '数据加载失败', response.data);
  2207. });
  2208. };
  2209. loadData();
  2210. // 新增客户联系人
  2211. $scope.addContact = function (uu) {
  2212. var modalInstance = $modal.open({
  2213. animation: true,
  2214. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2215. controller: 'AddContacCtrl',
  2216. resolve: {}
  2217. });
  2218. modalInstance.result.then(function (data) {
  2219. $scope.contact = data;
  2220. $scope.contact.myenuu = uu;
  2221. Vendor.saveCustContact({}, $scope.contact, function (data) {
  2222. toaster.pop('success', '提示', '联系人保存成功');
  2223. $scope.Contacts.push(data);
  2224. }, function (response) {
  2225. toaster.pop('error', '失败', response.data);
  2226. });
  2227. });
  2228. }
  2229. // 编辑客户联系人
  2230. $scope.edit = function (contact) {
  2231. var modalInstance = $modal.open({
  2232. animation: true,
  2233. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2234. controller: 'EditContacCtrl',
  2235. resolve: {
  2236. contact: function () {
  2237. return contact;
  2238. }
  2239. }
  2240. });
  2241. modalInstance.result.then(function (data) {
  2242. Vendor.saveContact({}, data, function (data) {
  2243. loadData();
  2244. toaster.pop('success', '提示', '联系人修改成功');
  2245. }, function (response) {
  2246. toaster.pop('error', '失败', response.data);
  2247. });
  2248. });
  2249. }
  2250. // 删除客户联系人
  2251. $scope.deleteById = function (id, index) {
  2252. $scope.Contacts.splice(index, 1);
  2253. Vendor.deleteContact({id: id}, {}, function (data) {
  2254. toaster.pop('success', '提示', '客户联系人删除成功');
  2255. loadData();
  2256. }, function (response) {
  2257. toaster.pop('error', '提示', response.data);
  2258. });
  2259. }
  2260. // 供应商物料信息
  2261. $scope.viewProdList = function (uu) {
  2262. $scope.uu = uu;
  2263. $scope.tableParams.page(1);
  2264. $scope.tableParams.reload();
  2265. };
  2266. // 搜索框回车
  2267. $scope.onSearch = function (keyword) {
  2268. $scope.keyword = keyword;
  2269. $scope.tableParams.page(1);
  2270. $scope.tableParams.reload();
  2271. };
  2272. // 供应商物料信息
  2273. $scope.tableParams = new ngTableParams({
  2274. page: 1,
  2275. count: 20
  2276. }, {
  2277. total: 0,
  2278. counts: [5, 10, 25, 50],
  2279. getData: function ($defer, params) {
  2280. $scope.loading = true;
  2281. var pageParams = params.url();
  2282. pageParams.custUU = $scope.uu;
  2283. pageParams.keyword = $scope.keyword;
  2284. $scope.tip = $scope.keyword;
  2285. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  2286. $scope.loading = false;
  2287. if (page) {
  2288. params.total(page.totalElement);
  2289. $scope.total = page.totalElement;
  2290. $defer.resolve(page.content);
  2291. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2292. }
  2293. }, function (response) {
  2294. $scope.loading = false;
  2295. toaster.pop('error', '数据加载失败', response.data);
  2296. });
  2297. }
  2298. });
  2299. $scope.addUserInfo = function () {
  2300. //TODO
  2301. if ($scope.thisUser.sys) {
  2302. var modalInstance = $modal.open({
  2303. animation: true,
  2304. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2305. controller: 'AddUserInfoCtrl',
  2306. resolve: {
  2307. customer: function () {
  2308. return $scope.customerInfo;
  2309. }
  2310. }
  2311. });
  2312. modalInstance.result.then(function (changed, checked) {
  2313. loadData();
  2314. if (changed) {
  2315. if (checked) {
  2316. $scope.newUser.roles = checked;
  2317. } else {
  2318. loadUsers();
  2319. }
  2320. }
  2321. });
  2322. } else {
  2323. toaster.pop('error', '您不是管理员,无权限分配用户!');
  2324. }
  2325. }
  2326. $scope.Quotation = function (uu, id) {
  2327. $rootScope.custuu = uu;
  2328. $rootScope.prodId = id;
  2329. window.location.hash = "#/sale/quotation/new";
  2330. }
  2331. }]);
  2332. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function ($scope, $modalInstance, customer, AccountUser, toaster) {
  2333. $scope.checkboxes = {
  2334. checked: false
  2335. };
  2336. $scope.loading = true;
  2337. $scope.distribute = [];
  2338. AccountUser.findUsers({uu: customer.myEnterprise.uu}, null, function (data) {
  2339. $scope.userinfos = data;
  2340. var distribute = [];
  2341. angular.forEach($scope.userinfos, function (user, index) {
  2342. if (user.distribute) {
  2343. distribute.push({num: index});
  2344. }
  2345. });
  2346. $scope.distribute = distribute;
  2347. $scope.havedone = angular.copy($scope.distribute);
  2348. $scope.loading = false;
  2349. })
  2350. var checkStatus = function (userinfos) {
  2351. var distribute = [];
  2352. angular.forEach(userinfos, function (user, index) {
  2353. if (user.distribute) {
  2354. distribute.push({num: index});
  2355. }
  2356. });
  2357. $scope.distribute = distribute;
  2358. $scope.isChanged = !angular.equals($scope.havedone, $scope.distribute);
  2359. }
  2360. $scope.isChanged = false;
  2361. $scope.isChangedAll = false;
  2362. $scope.changes = [];
  2363. // 点击勾选全部的复选框
  2364. $scope.checkAll = function () {
  2365. angular.forEach($scope.userinfos, function (item, index) {
  2366. item.distribute = $scope.checkboxes.checked;
  2367. });
  2368. checkStatus($scope.userinfos);
  2369. };
  2370. // 点击其中一个明细的复选框
  2371. $scope.checkOne = function () {
  2372. var result = true;
  2373. angular.forEach($scope.userinfos, function (item) {
  2374. if (item.distribute != true) {
  2375. result = false;
  2376. return;
  2377. }
  2378. });
  2379. $scope.checkboxes.checked = result;
  2380. checkStatus($scope.userinfos);
  2381. };
  2382. $scope.close = function (save) {
  2383. var chooseResult = [];
  2384. if (save) {
  2385. if (customer.myEnterprise.uu) {
  2386. angular.forEach($scope.userinfos, function (item, i) {
  2387. chooseResult.push(item);
  2388. });
  2389. if (chooseResult.length > 0) {
  2390. $scope.loading = true;
  2391. AccountUser.addUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2392. $scope.loading = false;
  2393. toaster.pop('success', '提示', '保存成功');
  2394. $modalInstance.close(false);
  2395. }, function (response) {
  2396. $scope.loading = false;
  2397. toaster.pop('error', '保存失败', response.data);
  2398. $modalInstance.close(false);
  2399. })
  2400. } else {
  2401. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2402. }
  2403. } else {
  2404. $modalInstance.close(true, $scope.checkboxes.checked);
  2405. }
  2406. } else {
  2407. $modalInstance.close(false);
  2408. }
  2409. };
  2410. }]);
  2411. // 转移权限
  2412. app.controller('TransferUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', 'AuthenticationService', function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
  2413. AuthenticationService.getAuthentication().success(function (data) {
  2414. $scope.loading = false;
  2415. $scope.thisUser = data;
  2416. });
  2417. $scope.checkboxes = {
  2418. checked: false
  2419. };
  2420. $scope.loading = true;
  2421. $scope.transfer = [];
  2422. AccountUser.findUsers({uu: customer.myEnterprise.uu}, {}, function (data) {
  2423. $scope.userinfos = data;
  2424. var transfer = [];
  2425. angular.forEach($scope.userinfos, function (user, index) {
  2426. // 当前用户是被管理员转移权限时,转移的是被管理员转移的权限。
  2427. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2428. $scope.thisUser.transfer = true;
  2429. }
  2430. });
  2431. angular.forEach($scope.userinfos, function (user, index) {
  2432. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2433. if (user.transfer) {
  2434. transfer.push({num: index});
  2435. user.checked = true;
  2436. }
  2437. } else {
  2438. if (user.distribute) {
  2439. transfer.push({num: index});
  2440. user.checked = true;
  2441. }
  2442. }
  2443. });
  2444. $scope.transfer = transfer;
  2445. $scope.havedone = angular.copy($scope.transfer);
  2446. $scope.loading = false;
  2447. });
  2448. var checkStatus = function (userinfos) {
  2449. var transfer = [];
  2450. angular.forEach(userinfos, function (user, index) {
  2451. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2452. if (user.transfer) {
  2453. transfer.push({num: index});
  2454. }
  2455. } else {
  2456. if (user.distribute) {
  2457. transfer.push({num: index});
  2458. }
  2459. }
  2460. });
  2461. $scope.transfer = transfer;
  2462. $scope.isChanged = !angular.equals($scope.havedone, $scope.transfer);
  2463. };
  2464. $scope.isChanged = false;
  2465. $scope.isChangedAll = false;
  2466. $scope.changes = [];
  2467. // 点击其中一个明细的复选框
  2468. $scope.checkOne = function (user) {
  2469. $scope.changes = [];
  2470. if ($scope.thisUser.sys) { // 管理员操作
  2471. user.$checked = !user.$checked;
  2472. angular.forEach($scope.userinfos, function (userInfo) {
  2473. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2474. $scope.thisUser.transfer = true;
  2475. }
  2476. if (user.userUU !== userInfo.userUU) {
  2477. userInfo.transfer = false;
  2478. }
  2479. });
  2480. } else if ($scope.thisUser.transfer) { // 被管理员转移权限的非管理员操作
  2481. user.$checked = !user.$checked;
  2482. angular.forEach($scope.userinfos, function (userInfo) {
  2483. if (user.userUU !== userInfo.userUU) {
  2484. userInfo.transfer = false;
  2485. } else {
  2486. userInfo.transfer = true;
  2487. }
  2488. });
  2489. } else { // 被分配客户的用户
  2490. user.$checked = !user.$checked;
  2491. angular.forEach($scope.userinfos, function (userInfo) {
  2492. if (user.userUU !== userInfo.userUU) {
  2493. userInfo.distribute = false;
  2494. } else {
  2495. userInfo.distribute = true;
  2496. }
  2497. });
  2498. }
  2499. checkStatus($scope.userinfos);
  2500. };
  2501. $scope.close = function (save) {
  2502. var chooseResult = [];
  2503. if (save) {
  2504. if (customer.myEnterprise.uu) {
  2505. // 当前用户是管理员时
  2506. if ($scope.thisUser.sys) {
  2507. angular.forEach($scope.userinfos, function (item, i) {
  2508. chooseResult.push(item);
  2509. });
  2510. if (chooseResult.length > 0) {
  2511. $scope.loading = true;
  2512. AccountUser.transferUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2513. $scope.loading = false;
  2514. toaster.pop('success', '提示', '保存成功');
  2515. $modalInstance.close(false);
  2516. }, function (response) {
  2517. $scope.loading = false;
  2518. toaster.pop('error', '保存失败', response.data);
  2519. $modalInstance.close(false);
  2520. })
  2521. } else {
  2522. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2523. }
  2524. } else {
  2525. // 非管理员转移自己的权限时
  2526. angular.forEach($scope.userinfos, function (item, i) {
  2527. if (item.transfer && item.userUU !== $scope.thisUser.userUU) {
  2528. $scope.target = item;
  2529. }
  2530. });
  2531. if (!$scope.target) {
  2532. toaster.pop('error', '保存失败', "您未选择权限转移对象");
  2533. } else {
  2534. $scope.loading = true;
  2535. AccountUser.transferMyDistribute({custUU: customer.myEnterprise.uu, userUU: $scope.target.userUU}, {} ,function (data) {
  2536. $scope.loading = false;
  2537. toaster.pop('success', '提示', '保存成功');
  2538. $modalInstance.close(false);
  2539. }, function (response) {
  2540. $scope.loading = false;
  2541. toaster.pop('error', '保存失败', response.data);
  2542. $modalInstance.close(false);
  2543. });
  2544. }
  2545. }
  2546. } else {
  2547. $modalInstance.close(true, $scope.checkboxes.checked);
  2548. }
  2549. } else {
  2550. $modalInstance.close(false);
  2551. }
  2552. };
  2553. }]);
  2554. /**
  2555. * 页面状态按钮过滤
  2556. */
  2557. var getState = function (active) {
  2558. var fn = 'get';
  2559. switch (active) {
  2560. case 'done':
  2561. fn = 'getDone';
  2562. break;
  2563. case 'todo':
  2564. fn = 'getTodo';
  2565. break;
  2566. case 'end':
  2567. fn = 'getEnd';
  2568. break;
  2569. case 'waiting':
  2570. fn = 'getWaiting';
  2571. break;
  2572. case 'received':
  2573. fn = 'getReceived';
  2574. break;
  2575. case 'invalid':
  2576. fn = 'getInvalid';
  2577. break;
  2578. // 已采纳
  2579. case 'agreed':
  2580. fn = 'getAgreed';
  2581. break;
  2582. // 未采纳
  2583. case 'refused':
  2584. fn = 'getRefused';
  2585. break;
  2586. // 个人
  2587. case 'personal':
  2588. fn = 'getPersonal';
  2589. break;
  2590. // 集体
  2591. case 'teams':
  2592. fn = 'getTeams';
  2593. break;
  2594. // 非标准
  2595. case 'nonstandard':
  2596. fn = 'getNonstandard';
  2597. break;
  2598. // 标准
  2599. case 'standard':
  2600. fn = 'getStandard';
  2601. break;
  2602. // 变更单无需确认
  2603. case 'unread':
  2604. fn = 'getUnread';
  2605. break;
  2606. }
  2607. return fn;
  2608. };
  2609. /**
  2610. * 改变单据日期范围
  2611. */
  2612. var getDateCondition = function (zone, condition) {
  2613. var fromDate = new Date();
  2614. var toDate = new Date();
  2615. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  2616. fromDate.setHours(0, 0, 0, 0);
  2617. toDate.setHours(23, 59, 59, 999);
  2618. if (zone == -1) { // 自定义时间,什么都不做
  2619. } else if (zone == 1) {
  2620. fromDate.setMonth(fromDate.getMonth() - 1);
  2621. condition.dateFrom = fromDate;
  2622. condition.dateTo = toDate;
  2623. } else if (zone == 3) {
  2624. fromDate.setMonth(fromDate.getMonth() - 3);
  2625. condition.dateFrom = fromDate;
  2626. condition.dateTo = toDate;
  2627. } else if (zone == 6) {
  2628. fromDate.setMonth(fromDate.getMonth() - 6);
  2629. condition.dateFrom = fromDate;
  2630. condition.dateTo = toDate;
  2631. } else {
  2632. condition.dateFrom = null;
  2633. condition.dateTo = null;
  2634. }
  2635. };
  2636. /**
  2637. * 改变单据交货日期范围
  2638. */
  2639. var getDelveryCondition = function (zone, condition) {
  2640. var date = new Date();
  2641. if (zone == -1) {
  2642. condition.deliveryFrom = null;
  2643. condition.deliveryTo = null;
  2644. } else if (zone == 1) {
  2645. date.setMonth(date.getMonth() + 1);
  2646. condition.deliveryTo = date;
  2647. condition.deliveryFrom = new Date();
  2648. } else if (zone == 2) {
  2649. date.setMonth(date.getMonth() + 2);
  2650. condition.deliveryTo = date;
  2651. condition.deliveryFrom = new Date();
  2652. }
  2653. };
  2654. /**
  2655. * 将日期转化为整数日期
  2656. */
  2657. var getDateTime = function (date) {
  2658. if (angular.isDate(date)) {
  2659. return date.getTime();
  2660. } else {
  2661. return null;
  2662. }
  2663. };
  2664. /**
  2665. * 删除数组里某个特定的值
  2666. */
  2667. var removeByValue = function (arr, val) {
  2668. for(var i=0; i<arr.length; i++) {
  2669. if(arr[i] == val) {
  2670. arr.splice(i, 1);
  2671. break;
  2672. }
  2673. }
  2674. };
  2675. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrders', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope', 'PurchaseOrder', 'PurcOrdersInfo', 'PurcOrderItem', 'CurrentRole',
  2676. function ($scope, $filter, PurcOrders, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope, PurchaseOrder, PurcOrdersInfo, PurcOrderItem, CurrentRole) {
  2677. BaseService.scrollBackToTop();
  2678. // 获取当前用户是否为普通用户
  2679. CurrentRole.isUser({}, {}, function (data) {
  2680. $scope.isUser = data.isUser;
  2681. });
  2682. if ($rootScope.active) {
  2683. $scope.active = $rootScope.active;
  2684. $rootScope.active = null;
  2685. } else {
  2686. $scope.active = 'all';
  2687. }
  2688. $scope.dateZoneText = '不限';
  2689. $scope.deliveryZoneText = '不限';
  2690. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2691. /* 时间筛选初始化*/
  2692. var fromDate = new Date();
  2693. var toDate = new Date();
  2694. fromDate.setMonth(fromDate.getMonth() - 1);
  2695. fromDate.setHours(0, 0, 0, 0);
  2696. toDate.setHours(23, 59, 59, 999);
  2697. $scope.condition.dateFrom = fromDate;
  2698. $scope.condition.dateTo = toDate;
  2699. $scope.changeDateZone = function (zone) {
  2700. $scope.condition.dateZone = zone;
  2701. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2702. $scope.condition.$dateZoneOpen = false;
  2703. getDateCondition(zone, $scope.condition);
  2704. $scope.tableParams.page(1);
  2705. $scope.tableParams.reload();
  2706. };
  2707. $scope.changeDeliveryZone = function (zone) {
  2708. $scope.condition.deliveryZoneText = zone;
  2709. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2710. $scope.condition.$delievryZoneOpen = false;
  2711. getDelveryCondition(zone, $scope.condition);
  2712. $scope.tableParams.reload();
  2713. };
  2714. $scope.searchMethod = false;
  2715. var getService = function () {
  2716. return $scope.searchMethod ? PurcOrders : PurcOrdersInfo;
  2717. };
  2718. // 切换单据类型
  2719. $scope.setActive = function (state) {
  2720. if ($scope.active != state) {
  2721. $scope.active = state;
  2722. if ($scope.tableParams.page() == 1)
  2723. $scope.tableParams.reload();
  2724. else
  2725. $scope.tableParams.page(1);
  2726. }
  2727. };
  2728. var getPurcStatus = function (active) {
  2729. var fn = 'getPurcAll';
  2730. switch (active) {
  2731. case 'done':
  2732. fn = 'getPurcDone';
  2733. break;
  2734. case 'todo':
  2735. fn = 'getPurcTodo';
  2736. break;
  2737. case 'end':
  2738. fn = 'getPurcEnd';
  2739. break;
  2740. case 'waiting':
  2741. fn = 'getPurcWaiting';
  2742. break;
  2743. }
  2744. return fn;
  2745. };
  2746. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2747. page: 1,
  2748. count: 20,
  2749. sorting: {
  2750. display: 'desc',
  2751. date: 'desc'
  2752. }
  2753. }, {
  2754. total: 0,
  2755. counts: [5, 10, 15, 25, 50],
  2756. getData: function ($defer, params) {// 获取数据的方法
  2757. $scope.loading = true;
  2758. var pageParams = params.url();
  2759. pageParams.searchFilter = { // 筛选条件
  2760. keyword: $scope.keyword,
  2761. fromDate: getDateTime($scope.condition.dateFrom),
  2762. endDate: getDateTime($scope.condition.dateTo)
  2763. };
  2764. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2765. $scope.loading = false;
  2766. if (page) {
  2767. $defer.resolve(page.content);
  2768. $scope.total = page.totalElement;
  2769. params.total(page.totalElement);
  2770. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2771. }
  2772. }, function (response) {
  2773. $scope.loading = false;
  2774. toaster.pop('error', '数据加载失败', response.data);
  2775. });
  2776. }
  2777. });
  2778. //获得各分类未阅读数量
  2779. var getUnreadCount = function () {
  2780. PurcOrders.getUnreadCount(null, function (data) {
  2781. $scope.unread = data;
  2782. });
  2783. };
  2784. getUnreadCount();
  2785. //设置单据已读
  2786. $scope.setOrdersRead = function (id) {
  2787. // 如果单据本身已读,则不发送请求修改数据
  2788. if (!$scope.isUnread(id)){
  2789. return;
  2790. }
  2791. var sourceId = [];
  2792. sourceId.push(id);
  2793. PurcOrders.setRead({}, sourceId, function (message) {
  2794. // $scope.getUnreadIds();
  2795. getUnreadCount();
  2796. });
  2797. };
  2798. //获取未读单据id
  2799. var getUnreadIds = function () {
  2800. PurcOrders.getUnreadIds({}, "", function (message) {
  2801. $scope.unreadCode = message.content;
  2802. });
  2803. };
  2804. getUnreadIds();
  2805. //判断单据是否未读
  2806. $scope.isUnread = function (id) {
  2807. for (var i in $scope.unreadCode) {
  2808. if (id == $scope.unreadCode[i]) {
  2809. return true;
  2810. }
  2811. }
  2812. };
  2813. $scope.getReply = function (item) {
  2814. if (!item.replies) {
  2815. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2816. item.replies = replies;
  2817. });
  2818. }
  2819. };
  2820. $scope.getOrderTotal = function (items) {
  2821. var sum = 0;
  2822. angular.forEach(items, function (item) {
  2823. sum += item.qty * item.price;
  2824. });
  2825. return sum;
  2826. };
  2827. // 需方 打印 采购单
  2828. $scope.custPrint = function (order) {
  2829. var newPage = window.open("about:blank");
  2830. PurcOrder.printPermission({}, function () {
  2831. PurcOrder.custPrintCount({id: order.id}, {});//增加打印此次
  2832. ReportService.print(order.enUU, 'PURCLIST_CUST', "where purc$orders.pu_id=" + order.id, newPage);
  2833. }, function (response) {
  2834. newPage.close();
  2835. toaster.pop('error', '打印失败', response.data);
  2836. });
  2837. };
  2838. $scope.openDatePicker = function ($event, item, openParam) {
  2839. $event.preventDefault();
  2840. $event.stopPropagation();
  2841. item[openParam] = !item[openParam];
  2842. };
  2843. $scope.openFilterDatePicker = function ($event, item, openParam) {
  2844. $event.preventDefault();
  2845. $event.stopPropagation();
  2846. item[openParam] = !item[openParam];
  2847. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  2848. $scope.tableParams.reload();
  2849. }
  2850. };
  2851. $scope.parseDate = function (dateStr) {
  2852. if (dateStr)
  2853. return Date.parse(dateStr, 'yyyy-MM-dd');
  2854. return new Date();
  2855. };
  2856. $scope.checkboxes = {
  2857. checked: false
  2858. };
  2859. // 点击勾选全部的复选框
  2860. $scope.checkAll = function () {
  2861. angular.forEach($scope.tableParams.data, function (item) {
  2862. item.$selected = $scope.checkboxes.checked;
  2863. });
  2864. };
  2865. // 点击其中一个明细的复选框
  2866. $scope.checkOne = function (order) {
  2867. var result = true;
  2868. angular.forEach($scope.tableParams.data, function (item) {
  2869. if (item.$selected != true) {
  2870. result = false;
  2871. return;
  2872. }
  2873. });
  2874. $scope.checkboxes.checked = result;
  2875. };
  2876. // 搜索框回车
  2877. $scope.onSearch = function (keyword) {
  2878. // 每次搜索重置获取数据方法
  2879. $scope.searchMethod = false;
  2880. if(keyword != null && keyword != '') {
  2881. $scope.searchMethod = true;
  2882. }
  2883. $scope.tableParams.page(1);
  2884. $scope.tableParams.reload();
  2885. $scope.tip = keyword;
  2886. };
  2887. // 选择查找日期
  2888. $scope.onDateCondition = function () {
  2889. $scope.tableParams.page(1);
  2890. $scope.tableParams.reload();
  2891. };
  2892. // 复制订单
  2893. $scope.copyorder = function (id) {
  2894. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  2895. if (data.id) {
  2896. toaster.pop('success', '提示', '单据复制成功');
  2897. window.location.hash = "#purc/cart/" + data.id;
  2898. }
  2899. }, function (response) {
  2900. toaster.pop('error', '提示', response.data);
  2901. });
  2902. }
  2903. // 导出
  2904. $scope.exportXls = function () {
  2905. PurcOrders.exportXls({}, {}, function (data) {
  2906. if (data.success){
  2907. window.location.href = 'sale/orders/purc/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  2908. }
  2909. }, function (response) {
  2910. toaster.pop('error', '数据加载失败', response.data);
  2911. });
  2912. }
  2913. }]);
  2914. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'PurcOrdersInfo', 'CurrentRole', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, PurcOrdersInfo, CurrentRole) {
  2915. // 获取当前用户是否为普通用户
  2916. CurrentRole.isUser({}, {}, function (data) {
  2917. $scope.isUser = data.isUser;
  2918. });
  2919. var loadData = function () {
  2920. $scope.loading = true;
  2921. PurcOrdersInfo.getAll({id: $stateParams.id},{}, function (data) {
  2922. $scope.order = data;
  2923. var sum = 0;
  2924. angular.forEach($scope.order.orderItems, function (item) {
  2925. sum += item.qty * item.price;
  2926. });
  2927. $scope.order.total = sum;
  2928. // if($scope.order.display == 1) {//未查看的设为已查看
  2929. // $scope.setDisplay('setRead', $scope.order.id);
  2930. // }
  2931. //$scope.loading = false;
  2932. }, function (response) {
  2933. toaster.pop('error', '提示', response.data);
  2934. });
  2935. };
  2936. loadData();
  2937. $scope.getReply = function (item) {
  2938. if (!item.replies) {
  2939. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2940. item.replies = replies;
  2941. });
  2942. }
  2943. };
  2944. $scope.openDatePicker = function ($event, item, openParam) {
  2945. $event.preventDefault();
  2946. $event.stopPropagation();
  2947. item[openParam] = !item[openParam];
  2948. };
  2949. $scope.onReplyClick = function (item, inverse) {
  2950. if (item.reply) {
  2951. if (!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2952. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2953. return;
  2954. }
  2955. var reply = angular.copy(item.reply);
  2956. if (reply.delivery) {
  2957. if (typeof reply.delivery == 'object')
  2958. reply.delivery = reply.delivery.getTime();
  2959. } else {
  2960. reply.delivery = item.delivery;
  2961. }
  2962. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2963. $scope.loading = true;
  2964. PurcOrderItem.reply({orderItemId: item.id}, reply, function () {
  2965. $scope.loading = false;
  2966. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  2967. loadData();
  2968. }, function (response) {
  2969. $scope.loading = false;
  2970. toaster.pop('error', '回复失败', response.data);
  2971. });
  2972. }
  2973. };
  2974. //设置为已查看
  2975. $scope.setDisplay = function (state, orderId) {
  2976. if (orderId) {//设置单个
  2977. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  2978. // $scope.tableParams.reload();
  2979. }, function () {
  2980. toaster.pop('error', '错误', "设置失败");
  2981. });
  2982. } else {//设置已勾选的
  2983. var str = null;
  2984. angular.forEach($scope.tableParams.data, function (order) {
  2985. if (order.$selected == true) {
  2986. if (str != null && str != '') str += ',';
  2987. str += order.id;
  2988. }
  2989. });
  2990. if (str != null && str != '') {
  2991. PurcOrder[state].call({}, {ids: '' + str}, function () {
  2992. $scope.tableParams.reload();
  2993. }, function () {
  2994. toaster.pop('error', '错误', "设置失败");
  2995. });
  2996. }
  2997. }
  2998. };
  2999. }]);
  3000. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis', 'PagingRelease', 'SnapshotService', 'PurcOrderItemInfo', 'token', 'CurrentRole', '$timeout', '$modal', function ($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis, PagingRelease, SnapshotService, PurcOrderItemInfo, token, CurrentRole, $timeout, $modal) {
  3001. BaseService.scrollBackToTop();
  3002. // 判断是否为普通用户
  3003. CurrentRole.isUser({}, {}, function (data) {
  3004. $scope.isUser = data.isUser;
  3005. });
  3006. $scope.active = 'todo';
  3007. $scope.dateZoneText = '不限';
  3008. $scope.deliveryZoneText = '不限';
  3009. $scope.condition = {dateZone: 1, deliveryZone: -1};
  3010. /* 时间筛选初始化*/
  3011. var fromDate = new Date();
  3012. var toDate = new Date();
  3013. fromDate.setMonth(fromDate.getMonth() - 1);
  3014. fromDate.setHours(0, 0, 0, 0);
  3015. toDate.setHours(23, 59, 59, 999);
  3016. $scope.condition.dateFrom = fromDate;
  3017. $scope.condition.dateTo = toDate;
  3018. $scope.changeDateZone = function (zone) {
  3019. $scope.condition.dateZone = zone;
  3020. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3021. $scope.condition.$dateZoneOpen = false;
  3022. getDateCondition(zone, $scope.condition);
  3023. $scope.tableParams.page(1);
  3024. $scope.tableParams.reload();
  3025. };
  3026. $scope.changeDeliveryZone = function (zone) {
  3027. $scope.condition.deliveryZoneText = zone;
  3028. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  3029. $scope.condition.$delievryZoneOpen = false;
  3030. getDelveryCondition(zone, $scope.condition);
  3031. $scope.tableParams.reload();
  3032. };
  3033. $scope.nowdate = new Date();
  3034. // 切换单据类型
  3035. $scope.setActive = function (state) {
  3036. if ($scope.active != state) {
  3037. $scope.active = state;
  3038. if ($scope.tableParams.page() == 1)
  3039. $scope.tableParams.reload();
  3040. else
  3041. $scope.tableParams.page(1);
  3042. }
  3043. };
  3044. $scope.searchMethod = false;
  3045. // 切换数据来源(正常数据 or 历史数据)
  3046. var getService = function () {
  3047. return $scope.searchMethod ? PurcOrderItem : PurcOrderItemInfo;
  3048. };
  3049. $scope.tableParams = new ngTableParams({ // ng-Table参数
  3050. page: 1,
  3051. count: 20,
  3052. sorting: {
  3053. date: 'desc',
  3054. id: 'desc'
  3055. }
  3056. }, {
  3057. total: 0,
  3058. counts: [5, 10, 15, 25, 50],
  3059. getData: function ($defer, params) { // 获取数据的方法
  3060. $scope.loading = true;
  3061. var pageParams = params.url();
  3062. pageParams.searchFilter = { // 筛选条件
  3063. keyword: $scope.keyword,
  3064. fromDate: getDateTime($scope.condition.dateFrom),
  3065. endDate: getDateTime($scope.condition.dateTo)
  3066. };
  3067. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3068. $scope.loading = false;
  3069. if (page) {
  3070. $defer.resolve(page.content);
  3071. params.total(page.totalElement);
  3072. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  3073. }
  3074. }, function (response) {
  3075. $scope.loading = false;
  3076. toaster.pop('error', '数据加载失败', response.data);
  3077. });
  3078. }
  3079. });
  3080. //获得各分类未阅读数量
  3081. var getUnreadCount = function () {
  3082. PurcOrderItem.getUnreadCount(null, function (data) {
  3083. $scope.unread = data;
  3084. });
  3085. };
  3086. getUnreadCount();
  3087. //设置单据已读
  3088. $scope.setOrdersRead = function (id) {
  3089. // 如果单据本身已读,则不发送请求修改数据
  3090. if (!$scope.isUnread(id)){
  3091. return;
  3092. }
  3093. var sourceId = [];
  3094. sourceId.push(id);
  3095. PurcOrderItem.setRead({}, sourceId, function (message) {
  3096. getUnreadCount();
  3097. });
  3098. };
  3099. //批量设置单据已读
  3100. $scope.setOrdersReadByBatch = function () {
  3101. var sourceId = [];
  3102. angular.forEach($scope.tableParams.data, function (order) {
  3103. if (order.$selected == true) {
  3104. sourceId.push(order.id);
  3105. }
  3106. });
  3107. PurcOrderItem.setRead({}, sourceId, function (message) {
  3108. getUnreadCount();
  3109. });
  3110. };
  3111. $scope.setOrdersReadByState = function () {
  3112. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3113. return;
  3114. }
  3115. PurcOrderItem.setReadByState({}, function () {
  3116. getUnreadIds();
  3117. getUnreadCount();
  3118. });
  3119. };
  3120. var getUnreadIds = function () {
  3121. PurcOrderItem.getUnreadIds({}, "", function (message) {
  3122. $scope.unreadCode = message.content;
  3123. });
  3124. };
  3125. getUnreadIds();
  3126. $scope.isUnread = function (id) {
  3127. for (var i in $scope.unreadCode) {
  3128. if (id == $scope.unreadCode[i]) {
  3129. return true;
  3130. }
  3131. }
  3132. };
  3133. $scope.getOrderTotal = function (items) {
  3134. var sum = 0;
  3135. angular.forEach(items, function (item) {
  3136. sum += item.qty * item.price;
  3137. });
  3138. return sum;
  3139. };
  3140. $scope.openDatePicker = function ($event, item, openParam) {
  3141. $event.preventDefault();
  3142. $event.stopPropagation();
  3143. item[openParam] = !item[openParam];
  3144. };
  3145. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3146. $event.preventDefault();
  3147. $event.stopPropagation();
  3148. item[openParam] = !item[openParam];
  3149. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3150. $scope.tableParams.reload();
  3151. }
  3152. };
  3153. $scope.parseDate = function (dateStr) {
  3154. if (dateStr)
  3155. return Date.parse(dateStr, 'yyyy-MM-dd');
  3156. return new Date();
  3157. };
  3158. // 获取token信息
  3159. $scope.getToken = function() {
  3160. token.info({userType: 'sale'}, {}, function(data) {
  3161. $scope.token = data.token;
  3162. }, function(response) {
  3163. toaster.pop('error', '提示', response.data);
  3164. });
  3165. }
  3166. $scope.onReplyClick = function (item, inverse) {
  3167. if (item.reply) {
  3168. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3169. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3170. return;
  3171. }
  3172. var reply = angular.copy(item.reply);
  3173. if (reply.delivery) {
  3174. if (typeof reply.delivery == 'object')
  3175. reply.delivery = reply.delivery.getTime();
  3176. } else {
  3177. reply.delivery = item.delivery;
  3178. }
  3179. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3180. $scope.loading = true;
  3181. if($scope.token != null) {
  3182. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3183. $scope.loading = false;
  3184. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3185. $scope.tableParams.reload();
  3186. }, function (response) {
  3187. $scope.loading = false;
  3188. toaster.pop('error', '回复失败', response.data);
  3189. });
  3190. }
  3191. }
  3192. };
  3193. //打印 采购单
  3194. $scope.print = function (order) {
  3195. var newPage = window.open("about:blank");
  3196. PurcOrder.printPermission({}, function () {
  3197. PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
  3198. if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  3199. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
  3200. $scope.tableParams.reload();
  3201. },function (response) {
  3202. newPage.close();
  3203. toaster.pop('error', '打印失败', response.data);
  3204. });
  3205. };
  3206. $scope.getReply = function (item) {
  3207. if (!item.replies) {
  3208. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3209. item.replies = replies;
  3210. });
  3211. }
  3212. };
  3213. $scope.checkboxes = {
  3214. checked: false
  3215. };
  3216. // 点击勾选全部的复选框
  3217. $scope.checkAll = function () {
  3218. angular.forEach($scope.tableParams.data, function (item) {
  3219. item.$selected = $scope.checkboxes.checked;
  3220. });
  3221. };
  3222. // 点击其中一个明细的复选框
  3223. $scope.checkOne = function (order) {
  3224. var result = true;
  3225. angular.forEach($scope.tableParams.data, function (item) {
  3226. if (item.$selected != true) {
  3227. result = false;
  3228. return;
  3229. }
  3230. });
  3231. $scope.checkboxes.checked = result;
  3232. };
  3233. //批量回复采购订单
  3234. $scope.replyByBatch = function () {
  3235. $scope.loading = true;
  3236. var str = '';
  3237. angular.forEach($scope.tableParams.data, function (order) {
  3238. if (order.$selected == true) {
  3239. str += order.id;
  3240. str += ',';
  3241. }
  3242. });
  3243. if (!(str == '')) {
  3244. $scope.loading = false;
  3245. str = str.substr(0, str.length - 1);
  3246. var modalInstance = $modal.open({
  3247. animation: true,
  3248. templateUrl: 'static/tpl/index/sale/modal/reply_bybatch.html',
  3249. controller: 'ReplyByBatchCtrl',
  3250. resolve: {}
  3251. });
  3252. modalInstance.result.then(function(data) {
  3253. $scope.loading = true;
  3254. var reply = data;
  3255. var date = null;
  3256. if (reply.date && reply.method == 1) {
  3257. date = reply.date.getTime();
  3258. }
  3259. PurcOrderItem.replyByBatch({date: date}, str, function () {
  3260. $scope.loading = false;
  3261. $scope.tableParams.reload();
  3262. toaster.pop('success', '提示', '批量回复成功');
  3263. }, function (response) {
  3264. $scope.loading = false;
  3265. toaster.pop('error', '提示', '批量回复失败');
  3266. });
  3267. });
  3268. } else {//没有勾选其中的明细
  3269. toaster.pop('error', '提示', '请先选择需要回复的单据');
  3270. $scope.loading = false;
  3271. }
  3272. };
  3273. // 搜索框回车
  3274. $scope.onSearch = function (keyword) {
  3275. // 每次搜索重置获取数据方法
  3276. $scope.searchMethod = false;
  3277. if(keyword != null && keyword != '') {
  3278. $scope.searchMethod = true;
  3279. }
  3280. $scope.tableParams.page(1);
  3281. $scope.tableParams.reload();
  3282. };
  3283. // 选择查找日期
  3284. $scope.onDateCondition = function () {
  3285. $scope.tableParams.page(1);
  3286. $scope.tableParams.reload();
  3287. };
  3288. //设置为已查看
  3289. $scope.setDisplay = function (state, orderId) {
  3290. if (orderId) {//设置单个
  3291. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3292. $scope.tableParams.reload();
  3293. }, function () {
  3294. toaster.pop('error', '错误', "设置失败");
  3295. });
  3296. } else {//设置已勾选的
  3297. var str = null;
  3298. angular.forEach($scope.tableParams.data, function (order) {
  3299. if (order.$selected == true) {
  3300. if (str != null && str != '') str += ',';
  3301. str += order.id;
  3302. }
  3303. });
  3304. if (str != null && str != '') {
  3305. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3306. $scope.tableParams.reload();
  3307. }, function () {
  3308. toaster.pop('error', '错误', "设置失败");
  3309. });
  3310. }
  3311. }
  3312. };
  3313. // 导出
  3314. $scope.exportXls = function () {
  3315. PurcOrderItem.exportXls({}, {}, function (data) {
  3316. if (data.success){
  3317. window.location.href = 'sale/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3318. }
  3319. }, function (response) {
  3320. toaster.pop('error', '数据加载失败', response.data);
  3321. });
  3322. }
  3323. }]);
  3324. /**
  3325. * 批量回复模态框
  3326. */
  3327. app.controller('ReplyByBatchCtrl', ['$scope', '$modalInstance', '$filter', 'toaster', function($scope, $modalInstance, $filter, toaster) {
  3328. $scope.activeTab = 'custom';
  3329. $scope.reply = {
  3330. method: 1
  3331. };
  3332. $scope.getMinDate = function () {
  3333. return $filter('date')(new Date, 'yyyy-MM-dd');
  3334. };
  3335. $scope.openDatePicker = function ($event, openParam) {
  3336. $event.preventDefault();
  3337. $event.stopPropagation();
  3338. $scope.$dateOpen = !openParam;
  3339. };
  3340. // 取消
  3341. $scope.cancel = function () {
  3342. $modalInstance.dismiss();
  3343. }
  3344. // 提交
  3345. $scope.submit = function () {
  3346. if ($scope.reply.method == 0) {
  3347. $modalInstance.close($scope.reply);
  3348. } else if ($scope.reply.method == 1) {
  3349. if (angular.isUndefined($scope.reply.date)) {
  3350. toaster.pop('error', '提示', '请先选择日期')
  3351. } else {
  3352. $modalInstance.close($scope.reply);
  3353. }
  3354. }
  3355. }
  3356. }]);
  3357. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token', 'file', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token, file) {
  3358. // 获取当前用户是否为普通用户
  3359. CurrentRole.isUser({}, {}, function (data) {
  3360. $scope.isUser = data.isUser;
  3361. });
  3362. var existFile = false;
  3363. var loadData = function () {
  3364. PurcOrder.get({id: $stateParams.id}, function (data) {
  3365. $scope.order = data;
  3366. var sum = 0;
  3367. angular.forEach($scope.order.orderItems, function (item) {
  3368. sum += item.qty * item.price;
  3369. if (item.attachs.length > 0) {
  3370. existFile = true;
  3371. }
  3372. });
  3373. $scope.order.total = sum;
  3374. if ($scope.order.display == 1) {//未查看的设为已查看
  3375. $scope.setDisplay('setRead', $scope.order.id);
  3376. }
  3377. $scope.loading = false;
  3378. }, function (response) {
  3379. toaster.pop('error', '', response.data);
  3380. });
  3381. };
  3382. loadData();
  3383. $scope.getReply = function (item) {
  3384. if (!item.replies) {
  3385. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3386. item.replies = replies;
  3387. });
  3388. }
  3389. };
  3390. $scope.openDatePicker = function ($event, item, openParam) {
  3391. $event.preventDefault();
  3392. $event.stopPropagation();
  3393. item[openParam] = !item[openParam];
  3394. };
  3395. // 获取token信息
  3396. var getToken = function() {
  3397. token.info({userType: 'sale'}, {}, function(data) {
  3398. $scope.token = data.token;
  3399. }, function(response) {
  3400. toaster.pop('error', '提示', response.data);
  3401. });
  3402. };
  3403. getToken();
  3404. $scope.onReplyClick = function (item, inverse) {
  3405. if (item.reply) {
  3406. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3407. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3408. return;
  3409. }
  3410. var reply = angular.copy(item.reply);
  3411. if (reply.delivery) {
  3412. if (typeof reply.delivery == 'object')
  3413. reply.delivery = reply.delivery.getTime();
  3414. } else {
  3415. reply.delivery = item.delivery;
  3416. }
  3417. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3418. $scope.loading = true;
  3419. if($scope.token != null) {
  3420. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3421. $scope.loading = false;
  3422. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3423. $scope.tableParams.reload();
  3424. }, function (response) {
  3425. $scope.loading = false;
  3426. toaster.pop('error', '回复失败', response.data);
  3427. });
  3428. }
  3429. }
  3430. };
  3431. // 采购单
  3432. $scope.print = function (order) {
  3433. var newPage = window.open("about:blank");
  3434. PurcOrder.printPermission({}, function () {
  3435. PurcOrder.printCount({id: order.id}, {});//增加打印此次
  3436. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id, newPage);
  3437. },function (response) {
  3438. newPage.close();
  3439. toaster.pop('error', '打印失败', response.data);
  3440. });
  3441. };
  3442. //设置为已查看
  3443. $scope.setDisplay = function (state, orderId) {
  3444. if (orderId) {//设置单个
  3445. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3446. $scope.tableParams.reload();
  3447. }, function () {
  3448. toaster.pop('error', '错误', "设置失败");
  3449. });
  3450. } else {//设置已勾选的
  3451. var str = null;
  3452. angular.forEach($scope.tableParams.data, function (order) {
  3453. if (order.$selected == true) {
  3454. if (str != null && str != '') str += ',';
  3455. str += order.id;
  3456. }
  3457. });
  3458. if (str != null && str != '') {
  3459. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3460. $scope.tableParams.reload();
  3461. }, function () {
  3462. toaster.pop('error', '错误', "设置失败");
  3463. });
  3464. }
  3465. }
  3466. };
  3467. // 下载附件
  3468. $scope.fileDownload = function (id) {
  3469. if (!existFile) {
  3470. toaster.pop('error', '提示', "当前采购单不存在附件信息");
  3471. } else {
  3472. window.open("file/batch/" + id);
  3473. }
  3474. }
  3475. }]);
  3476. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', 'CurrentRole', function ($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, PurcChangeHis, CurrentRole) {
  3477. BaseService.scrollBackToTop();
  3478. // 获取当前用户是否为普通用户
  3479. CurrentRole.isUser({}, {}, function (data) {
  3480. $scope.isUser = data.isUser;
  3481. });
  3482. $scope.active = 'todo';
  3483. $scope.agreedText = '全部';
  3484. $scope.dateZoneText = '一个月内';
  3485. $scope.condition = {dateZone: 1};
  3486. /* 时间筛选初始化*/
  3487. var fromDate = new Date();
  3488. var toDate = new Date();
  3489. fromDate.setMonth(fromDate.getMonth() - 1);
  3490. fromDate.setHours(0, 0, 0, 0);
  3491. toDate.setHours(23, 59, 59, 999);
  3492. $scope.condition.dateFrom = fromDate;
  3493. $scope.condition.dateTo = toDate;
  3494. $scope.changeAgreed = function (agreed) {
  3495. $scope.condition.agreed = agreed;
  3496. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3497. $scope.condition.$agreedOpen = false;
  3498. };
  3499. $scope.changeDateZone = function (zone) {
  3500. $scope.condition.dateZone = zone;
  3501. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3502. $scope.condition.$dateZoneOpen = false;
  3503. getDateCondition(zone, $scope.condition);
  3504. $scope.tableParams.page(1);
  3505. $scope.tableParams.reload();
  3506. };
  3507. $scope.setActive = function (state) {
  3508. if ($scope.active != state) {
  3509. $scope.active = state;
  3510. if ($scope.tableParams.page() == 1)
  3511. $scope.tableParams.reload();
  3512. else
  3513. $scope.tableParams.page(1);
  3514. }
  3515. };
  3516. $scope.searchMethod = false;
  3517. var getService = function () {
  3518. return $scope.searchMethod ? PurcChange : PurcChanges;
  3519. };
  3520. $scope.tableParams = new ngTableParams({
  3521. page: 1,
  3522. count: 20,
  3523. sorting: {
  3524. date: 'desc'
  3525. }
  3526. }, {
  3527. total: 0,
  3528. counts: [5, 10, 25, 50],
  3529. getData: function ($defer, params) {
  3530. $scope.loading = true;
  3531. var pageParams = params.url();
  3532. pageParams.searchFilter = {
  3533. keyword: $scope.keyword,
  3534. fromDate: getDateTime($scope.condition.dateFrom),
  3535. endDate: getDateTime($scope.condition.dateTo)
  3536. };
  3537. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3538. $scope.loading = false;
  3539. if (page) {
  3540. params.total(page.totalElement);
  3541. $defer.resolve(page.content);
  3542. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3543. }
  3544. }, function (response) {
  3545. $scope.loading = false;
  3546. toaster.pop('error', '数据加载失败', response.data);
  3547. });
  3548. }
  3549. });
  3550. //获得各分类未阅读数量
  3551. var getUnreadCount = function () {
  3552. PurcChange.getUnreadCount(null, function(data){
  3553. $scope.unread = data;
  3554. });
  3555. };
  3556. getUnreadCount();
  3557. //设置单据已读
  3558. $scope.setOrdersRead = function (id) {
  3559. // 如果单据本身已读,则不发送请求修改数据
  3560. if (!$scope.isUnread(id)){
  3561. return;
  3562. }
  3563. var sourceId = [];
  3564. sourceId.push(id);
  3565. PurcChange.setRead({}, sourceId, function (message) {
  3566. // $scope.getUnreadIds();
  3567. getUnreadCount();
  3568. });
  3569. };
  3570. $scope.setOrdersReadByState = function () {
  3571. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3572. return;
  3573. }
  3574. PurcChange.setReadByState({}, function () {
  3575. getUnreadIds();
  3576. getUnreadCount();
  3577. });
  3578. };
  3579. //获取未读单据id
  3580. var getUnreadIds = function (){
  3581. PurcChange.getUnreadIds({}, "", function (message) {
  3582. $scope.unreadCode = message.content;
  3583. });
  3584. };
  3585. getUnreadIds();
  3586. //判断单据是否未读
  3587. $scope.isUnread = function (id){
  3588. for (var i in $scope.unreadCode) {
  3589. if (id == $scope.unreadCode[i]) {
  3590. return true;
  3591. }
  3592. }
  3593. };
  3594. $scope.openDatePicker = function ($event, item, openParam) {
  3595. $event.preventDefault();
  3596. $event.stopPropagation();
  3597. item[openParam] = !item[openParam];
  3598. };
  3599. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3600. $event.preventDefault();
  3601. $event.stopPropagation();
  3602. item[openParam] = !item[openParam];
  3603. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3604. $scope.tableParams.reload();
  3605. }
  3606. };
  3607. $scope.onReplyClick = function (change) {
  3608. if (change.$agreed) {
  3609. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3610. $scope.loading = true;
  3611. PurcChange.reply({changeId: change.id}, reply, function () {
  3612. $scope.loading = false;
  3613. toaster.pop('info', '提示', '回复成功');
  3614. $scope.tableParams.reload();
  3615. }, function (response) {
  3616. $scope.loading = false;
  3617. toaster.pop('error', '回复失败', response.data);
  3618. });
  3619. }
  3620. };
  3621. // 搜索框回车
  3622. $scope.onSearch = function (keyword) {
  3623. // 每次搜索重置获取数据方法
  3624. $scope.searchMethod = false;
  3625. if(keyword != null && keyword != '') {
  3626. $scope.searchMethod = true;
  3627. }
  3628. $scope.tableParams.page(1);
  3629. $scope.tableParams.reload();
  3630. };
  3631. // 导出
  3632. $scope.exportXls = function () {
  3633. PurcChange.exportXls({}, {}, function (data) {
  3634. if (data.success){
  3635. window.location.href = 'sale/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3636. }
  3637. }, function (response) {
  3638. toaster.pop('error', '数据加载失败', response.data);
  3639. });
  3640. }
  3641. }]);
  3642. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcChange, toaster, CurrentRole) {
  3643. // 获取当前用户是否为普通用户
  3644. CurrentRole.isUser({}, {}, function (data) {
  3645. $scope.isUser = data.isUser;
  3646. });
  3647. var loadData = function () {
  3648. PurcChange.getItem({id: $stateParams.id}, function (data) {
  3649. $scope.change = data;
  3650. }, function (response) {
  3651. toaster.pop('error', '', response.data);
  3652. });
  3653. };
  3654. loadData();
  3655. $scope.openDatePicker = function ($event, item, openParam) {
  3656. $event.preventDefault();
  3657. $event.stopPropagation();
  3658. item[openParam] = !item[openParam];
  3659. };
  3660. $scope.onReplyClick = function (change) {
  3661. if (change.$agreed) {
  3662. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3663. PurcChange.reply({changeId: change.id}, reply, function () {
  3664. toaster.pop('info', '提示', '回复成功');
  3665. loadData();
  3666. }, function (response) {
  3667. toaster.pop('error', '回复失败', response.data);
  3668. });
  3669. }
  3670. };
  3671. }]);
  3672. //客户采购询价
  3673. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', function ($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryInfo, $upload, $rootScope, token, $timeout, CurrentRole) {
  3674. BaseService.scrollBackToTop();
  3675. // 获取当前用户是否为普通用户
  3676. CurrentRole.isUser({}, {}, function (data) {
  3677. $scope.isUser = data.isUser;
  3678. });
  3679. if ($rootScope.active) {
  3680. $scope.active = $rootScope.active;
  3681. $rootScope.active = null;
  3682. } else {
  3683. $scope.active = 'todo';
  3684. }
  3685. $scope.agreedText = '全部';
  3686. $scope.dateZoneText = '最近一个月';
  3687. $scope.condition = {dateZone: 1};
  3688. /* 时间筛选初始化*/
  3689. var fromDate = new Date();
  3690. var toDate = new Date();
  3691. fromDate.setMonth(fromDate.getMonth() - 1);
  3692. fromDate.setHours(0, 0, 0, 0);
  3693. toDate.setHours(23, 59, 59, 999);
  3694. $scope.condition.dateFrom = fromDate;
  3695. $scope.condition.dateTo = toDate;
  3696. $scope.changeAgreed = function (agreed) {
  3697. $scope.condition.agreed = agreed;
  3698. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3699. $scope.condition.$agreedOpen = false;
  3700. };
  3701. $scope.changeDateZone = function (zone) {
  3702. $scope.condition.dateZone = zone;
  3703. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  3704. $scope.condition.$dateZoneOpen = false;
  3705. getDateCondition(zone, $scope.condition);
  3706. $scope.tableParams.page(1);
  3707. $scope.tableParams.reload();
  3708. };
  3709. $scope.setActive = function (state) {
  3710. if ($scope.active != state) {
  3711. $scope.active = state;
  3712. if ($scope.tableParams.page() == 1)
  3713. $scope.tableParams.reload();
  3714. else
  3715. $scope.tableParams.page(1);
  3716. }
  3717. };
  3718. // 设置阅读状态
  3719. $scope.setReadStatus = function(msg) {
  3720. if(!msg.read) {
  3721. PurcInquiry.setStatus({id: msg.inid}, {}, function(data) {
  3722. });
  3723. }
  3724. }
  3725. $scope.searchMethod = false;
  3726. var getService = function () {
  3727. return $scope.searchMethod ? PurcInquiry : PurcInquiryInfo;
  3728. };
  3729. $scope.tableParams = new ngTableParams({
  3730. page: 1,
  3731. count: 20,
  3732. sorting: {
  3733. 'inquiry.date': 'desc',
  3734. 'inquiry.enterprise.enName': 'asc',
  3735. 'inquiry.code': 'asc'
  3736. }
  3737. }, {
  3738. total: 0,
  3739. counts: [5, 10, 25, 50],
  3740. getData: function ($defer, params) {
  3741. $scope.loading = true;
  3742. var pageParams = params.url();
  3743. var realActive = {};
  3744. pageParams.searchFilter = { // 筛选条件
  3745. keyword: $scope.keyword,
  3746. fromDate: getDateTime($scope.condition.dateFrom),
  3747. endDate: getDateTime($scope.condition.dateTo)
  3748. };
  3749. if ($scope.active == 'overdue') {
  3750. $scope.active = 'end';
  3751. }
  3752. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3753. $scope.loading = false;
  3754. if (page) {
  3755. params.total(page.totalElement);
  3756. $defer.resolve(page.content);
  3757. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3758. }
  3759. }, function (response) {
  3760. $scope.loading = false;
  3761. toaster.pop('error', '数据加载失败', response.data);
  3762. });
  3763. }
  3764. });
  3765. //获得各分类未阅读数量
  3766. var getUnreadCount = function () {
  3767. PurcInquiry.getUnreadCount(null, function (data) {
  3768. $scope.unread = data;
  3769. });
  3770. };
  3771. getUnreadCount();
  3772. //设置单据已读
  3773. $scope.setOrdersRead = function (id) {
  3774. // 如果单据本身已读,则不发送请求修改数据
  3775. if (!$scope.isUnread(id)){
  3776. return;
  3777. }
  3778. var sourceId = [];
  3779. sourceId.push(id);
  3780. PurcInquiry.setRead({}, sourceId, function (message) {
  3781. getUnreadCount();
  3782. removeByValue($scope.unreadCode, id);
  3783. });
  3784. };
  3785. $scope.setOrdersReadByState = function () {
  3786. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3787. return;
  3788. }
  3789. PurcInquiry.setReadByState({}, function () {
  3790. getUnreadIds();
  3791. getUnreadCount();
  3792. });
  3793. };
  3794. var getUnreadIds = function () {
  3795. PurcInquiry.getUnreadIds({}, "", function (message) {
  3796. $scope.unreadCode = message.content;
  3797. });
  3798. };
  3799. getUnreadIds();
  3800. $scope.isUnread = function (id) {
  3801. for (var i in $scope.unreadCode) {
  3802. if (id == $scope.unreadCode[i]) {
  3803. return true;
  3804. }
  3805. }
  3806. };
  3807. $scope.getMinDate = function (item) {
  3808. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3809. };
  3810. $scope.replyPrices = [];
  3811. $scope.replylapQtys = [];
  3812. $scope.replyPrices.push(true);
  3813. $scope.replylapQtys.push(true);
  3814. $scope.addStep = function (inquiryItem) {
  3815. $scope.replyPrices.push(true);
  3816. if (inquiryItem.replies.length >= 10) {
  3817. toaster.pop('warning', '提示', '最多支持10个分段!');
  3818. } else {
  3819. inquiryItem.replies.push({});
  3820. if (inquiryItem.replies.length != 1) {
  3821. $scope.replyPrices.push(true);
  3822. $scope.replylapQtys.push(true);
  3823. }
  3824. }
  3825. };
  3826. $scope.removeStep = function (inquiryItem, stepIndex) {
  3827. inquiryItem.replies.splice(stepIndex, 1);
  3828. $scope.replyPrices.splice(stepIndex, 1);
  3829. $scope.replylapQtys.splice(stepIndex, 1);
  3830. };
  3831. $scope.openDatePicker = function ($event, item, openParam) {
  3832. $event.preventDefault();
  3833. $event.stopPropagation();
  3834. item[openParam] = !item[openParam];
  3835. };
  3836. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3837. $event.preventDefault();
  3838. $event.stopPropagation();
  3839. item[openParam] = !item[openParam];
  3840. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3841. $scope.tableParams.reload();
  3842. }
  3843. };
  3844. $scope.getHistory = function (item) {
  3845. if (!item.history) {
  3846. PurcInquiry.getHistory({itemId: item.id},function (data) {
  3847. $scope.historyShow = true;
  3848. item.history = data;
  3849. }, function (response) {
  3850. $scope.historyShow = false;
  3851. //toaster.pop('error', '数据加载失败', response.data);
  3852. });
  3853. }
  3854. };
  3855. // 获取token信息
  3856. $scope.getToken = function() {
  3857. token.info({userType: 'saleinquiry'}, {}, function(data) {
  3858. $scope.token = data.token;
  3859. }, function(response) {
  3860. toaster.pop('error', '提示', response.data);
  3861. });
  3862. };
  3863. $scope.deleteAttach = function (attaches, index) {
  3864. attaches.splice(index, 1);
  3865. };
  3866. $scope.onReplyClick = function (item, withSteps) {
  3867. if (item.vendFromDate instanceof Date) {
  3868. item.vendFromDate = item.vendFromDate.getTime();
  3869. }
  3870. if (item.vendToDate instanceof Date) {
  3871. item.vendToDate = item.vendToDate.getTime();
  3872. }
  3873. if (item.vendFromDate > item.vendToDate) {
  3874. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3875. return;
  3876. }
  3877. var replies = [];
  3878. // 判断分段数是否合法
  3879. var valid = true;
  3880. var validLapQty = 0;
  3881. angular.forEach(item.replies, function (r, i) {
  3882. if ((i > 0 ? r.lapQty : 1) || r.price) {
  3883. replies.push(r);
  3884. }
  3885. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  3886. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  3887. valid = false;
  3888. validLapQty = r.lapQty;
  3889. }
  3890. });
  3891. item.replies = replies;
  3892. $scope.loading = true;
  3893. if (!valid) {
  3894. if (validLapQty) {
  3895. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  3896. } else {
  3897. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  3898. }
  3899. $scope.loading = false;
  3900. } else {
  3901. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3902. if (withSteps) { // 保存并报价
  3903. if(null != file) {
  3904. $upload.upload({
  3905. url: 'sale/inquiry/addAttach',
  3906. file: file,
  3907. method: 'POST',
  3908. data: {
  3909. item: item,
  3910. method: 'reply'
  3911. }
  3912. }).success(function (data) {
  3913. if (data.item) {
  3914. item = data.item;
  3915. }
  3916. $scope.loading = false;
  3917. toaster.pop('info', '提示', '报价成功');
  3918. $scope.tableParams.reload();
  3919. }).error(function (data) {
  3920. $scope.loading = false;
  3921. toaster.pop('error', '附件上传失败');
  3922. });
  3923. } else {
  3924. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function (data) {
  3925. $scope.loading = false;
  3926. toaster.pop('info', '提示', '报价成功');
  3927. $scope.tableParams.reload();
  3928. }, function (response) {
  3929. $scope.loading = false;
  3930. toaster.pop('error', '询价失效', response.data);
  3931. });
  3932. }
  3933. } else { // 保存
  3934. if(null != file) {
  3935. $upload.upload({
  3936. url: 'sale/inquiry/addAttach',
  3937. file: file,
  3938. method: 'POST',
  3939. data: {
  3940. item: item,
  3941. method: 'save'
  3942. }
  3943. }).success(function (data) {
  3944. if (data.item) {
  3945. item = data.item;
  3946. }
  3947. $scope.loading = false;
  3948. toaster.pop('info', '提示', '保存成功');
  3949. $scope.tableParams.reload();
  3950. }).error(function (data) {
  3951. $scope.loading = false;
  3952. toaster.pop('error', '附件上传失败');
  3953. });
  3954. } else {
  3955. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function (data) {
  3956. $scope.loading = false;
  3957. toaster.pop('info', '提示', '保存成功');
  3958. $scope.tableParams.reload();
  3959. }, function (response) {
  3960. $scope.loading = false;
  3961. toaster.pop('error', '保存失败', response.data);
  3962. });
  3963. }
  3964. }
  3965. }
  3966. };
  3967. $scope.isValid = function (item, withSteps) {
  3968. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3969. if (!withSteps || !bool)
  3970. return bool;
  3971. angular.forEach(item.replies, function (r, i) {
  3972. $scope.verifylapQty(r.lapQty, i, item);
  3973. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  3974. });
  3975. return bool;
  3976. };
  3977. $scope.verifylapQty = function (value, index, inquiryItem) {
  3978. value = parseInt(value);
  3979. var regex = /^\d+(.\d{1,6})?$/;
  3980. var valid = true;
  3981. angular.forEach(inquiryItem.replies, function(reply, $index) {
  3982. if ($index < index && reply.lapQty >= value) {
  3983. valid = false;
  3984. }
  3985. });
  3986. $scope.replylapQtys[index] = regex.test(value) && valid;
  3987. };
  3988. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  3989. $scope.verify = function (value, type) {
  3990. var regex = /^\d+(.\d{1,6})?$/;//
  3991. switch (type) {
  3992. case 'minOrderQty':
  3993. $scope.minOrderQtyVerify = regex.test(value);
  3994. break;
  3995. case 'minPackQty':
  3996. $scope.minPackQtyVerify = regex.test(value);
  3997. break;
  3998. case 'leadtime':
  3999. $scope.leadtimeVerify = regex.test(value);
  4000. break;
  4001. default:
  4002. $scope.replyPrices[type] = regex.test(value);
  4003. break;
  4004. }
  4005. }
  4006. // 搜索框回车
  4007. $scope.onSearch = function (keyword) {
  4008. // 每次搜索重置获取数据方法
  4009. $scope.searchMethod = false;
  4010. if(keyword != null && keyword != '') {
  4011. $scope.searchMethod = true;
  4012. }
  4013. $scope.tableParams.page(1);
  4014. $scope.tableParams.reload();
  4015. };
  4016. // 取消
  4017. $scope.cancel = function () {
  4018. $scope.tableParams.reload();
  4019. }
  4020. // 导出
  4021. $scope.exportXls = function () {
  4022. PurcInquiry.exportXls({}, {}, function (data) {
  4023. if (data.success) {
  4024. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4025. }
  4026. }, function (response) {
  4027. toaster.pop('error', '数据加载失败', response.data);
  4028. })
  4029. }
  4030. }]);
  4031. // 询价单明细
  4032. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole) {
  4033. // 获取当前用户是否为普通用户
  4034. CurrentRole.isUser({}, {}, function (data) {
  4035. $scope.isUser = data.isUser;
  4036. });
  4037. var loadData = function () {
  4038. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  4039. $scope.newinquiryItems = data;
  4040. var inquiry = data[0].inquiry;
  4041. //inquiry.inquiryItems = data;
  4042. angular.forEach(inquiry.attachs, function (attach) {
  4043. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  4044. });
  4045. $scope.inquiry = inquiry;
  4046. }, function (response) {
  4047. $scope.loading = false;
  4048. toaster.pop('error', '', response.data);
  4049. });
  4050. };
  4051. loadData();
  4052. $scope.getMinDate = function (item) {
  4053. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4054. };
  4055. $scope.replyPrices = [];
  4056. $scope.replylapQtys = [];
  4057. $scope.replyPrices.push(true);
  4058. $scope.replylapQtys.push(true);
  4059. $scope.addStep = function (inquiryItem) {
  4060. if (inquiryItem.replies.length >= 10) {
  4061. toaster.pop('warning', '提示', '最多支持10个分段!');
  4062. } else
  4063. inquiryItem.replies.push({});
  4064. };
  4065. $scope.removeStep = function (inquiryItem, stepIndex) {
  4066. inquiryItem.replies.splice(stepIndex, 1);
  4067. };
  4068. $scope.openDatePicker = function ($event, item, openParam) {
  4069. $event.preventDefault();
  4070. $event.stopPropagation();
  4071. item[openParam] = !item[openParam];
  4072. };
  4073. $scope.getHistory = function (item) {
  4074. if (!item.history) {
  4075. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  4076. item.history = data;
  4077. });
  4078. }
  4079. };
  4080. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  4081. $scope.verify = function (value, type) {
  4082. var regex = /^\d+(.\d{1,6})?$/;//
  4083. switch (type) {
  4084. case 'minOrderQty':
  4085. $scope.minOrderQtyVerify = regex.test(value);
  4086. break;
  4087. case 'minPackQty':
  4088. $scope.minPackQtyVerify = regex.test(value);
  4089. break;
  4090. case 'leadtime':
  4091. $scope.leadtimeVerify = regex.test(value);
  4092. break;
  4093. default:
  4094. $scope.replyPrices[type] = regex.test(value);
  4095. break;
  4096. }
  4097. }
  4098. $scope.verifylapQty = function (value, index, inquiryItem) {
  4099. value = parseInt(value);
  4100. var regex = /^\d+(.\d{1,6})?$/;
  4101. var valid = true;
  4102. angular.forEach(inquiryItem.replies, function(reply, $index) {
  4103. if ($index < index && reply.lapQty >= value) {
  4104. valid = false;
  4105. }
  4106. });
  4107. $scope.replylapQtys[index] = regex.test(value) && valid;
  4108. };
  4109. $scope.isValid = function (item, withSteps) {
  4110. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4111. if (!withSteps || !bool)
  4112. return bool;
  4113. angular.forEach(item.replies, function (r, i) {
  4114. $scope.verifylapQty(r.lapQty, i, item);
  4115. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  4116. });
  4117. return bool;
  4118. };
  4119. // 获取token信息
  4120. $scope.getToken = function() {
  4121. token.info({userType: 'saleinquiry'}, {}, function(data) {
  4122. $scope.token = data.token;
  4123. }, function(response) {
  4124. toaster.pop('error', '提示', response.data);
  4125. });
  4126. };
  4127. $scope.deleteAttach = function (attaches, index) {
  4128. attaches.splice(index, 1);
  4129. };
  4130. $scope.onReplyClick = function (item, withSteps) {
  4131. if (item.vendFromDate instanceof Date) {
  4132. item.vendFromDate = item.vendFromDate.getTime();
  4133. }
  4134. if (item.vendToDate instanceof Date) {
  4135. item.vendToDate = item.vendToDate.getTime();
  4136. }
  4137. if (item.vendFromDate > item.vendToDate) {
  4138. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4139. return;
  4140. }
  4141. var replies = [];
  4142. var valid = true;
  4143. var validLapQty = 0;
  4144. angular.forEach(item.replies, function (r, i) {
  4145. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  4146. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  4147. valid = false;
  4148. validLapQty = r.lapQty;
  4149. }
  4150. if ((i > 0 ? r.lapQty : 1) || r.price)
  4151. replies.push(r);
  4152. });
  4153. item.replies = replies;
  4154. $scope.loading = true;
  4155. if (!valid) { // 不合法时给出提示
  4156. if (validLapQty) {
  4157. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  4158. } else {
  4159. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  4160. }
  4161. $scope.loading = false;
  4162. } else {
  4163. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  4164. if (withSteps) {
  4165. if(null != file) {
  4166. $upload.upload({
  4167. url: 'sale/inquiry/addAttach',
  4168. file: file,
  4169. method: 'POST',
  4170. data: {
  4171. item: item,
  4172. method: 'reply'
  4173. }
  4174. }).success(function (data) {
  4175. if (data.item) {
  4176. item = data.item;
  4177. }
  4178. window.location.reload();
  4179. });
  4180. } else {
  4181. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  4182. $scope.loading = false;
  4183. toaster.pop('info', '提示', '报价成功');
  4184. // loadData();
  4185. window.location.reload();
  4186. }, function (response) {
  4187. $scope.loading = false;
  4188. toaster.pop('error', '询价失效', response.data);
  4189. });
  4190. }
  4191. } else {
  4192. if(null != file) {
  4193. $upload.upload({
  4194. url: 'sale/inquiry/addAttach',
  4195. file: file,
  4196. method: 'POST',
  4197. data: {
  4198. item: item,
  4199. method: 'save'
  4200. }
  4201. }).success(function (data) {
  4202. if (data.item) {
  4203. item = data.item;
  4204. }
  4205. window.location.reload();
  4206. });
  4207. } else {
  4208. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  4209. $scope.loading = false;
  4210. toaster.pop('info', '提示', '保存成功');
  4211. // loadData();
  4212. window.location.reload();
  4213. }, function (response) {
  4214. $scope.loading = false;
  4215. toaster.pop('error', '保存失败', response.data);
  4216. });
  4217. }
  4218. }
  4219. }
  4220. };
  4221. // 取消
  4222. $scope.cancel = function () {
  4223. $scope.tableParams.reload();
  4224. }
  4225. }]);
  4226. // 平台新增的询价单
  4227. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'PurcProduct', 'PurcProductNewest', '$timeout', '$http', 'ShipAddress', 'Search', 'ComponentActiveAPI', function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, PurcProduct, PurcProductNewest, $timeout, $http, ShipAddress, Search, ComponentActiveAPI) {
  4228. $scope.status = 'InquiryNew';
  4229. $scope.active = 'all';
  4230. $rootScope.tenderVendor = null;// 清除掉已选择的
  4231. $scope.searchMethod = false;
  4232. var getService = function () {
  4233. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  4234. };
  4235. $scope.inquiry = {
  4236. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  4237. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  4238. priceType: '采购',
  4239. isOpen: 1,
  4240. invoice: 0,
  4241. ifTax: 1,
  4242. currency: 'RMB',
  4243. inquirytype: '询价'
  4244. };
  4245. $scope.changeCurrency = function (inquiry) {
  4246. if (inquiry.currency !== 'RMB') {
  4247. $scope.notRMB = true;
  4248. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  4249. inquiry.invoice = 0;
  4250. } else {
  4251. $scope.notRMB = false;
  4252. }
  4253. };
  4254. // 获取收货地址列表
  4255. var loadShipAddress = function () {
  4256. ShipAddress.shipAddList({}, function (data) {
  4257. $scope.ships = data;
  4258. if (angular.isDefined($scope.ships)) {
  4259. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  4260. }
  4261. });
  4262. };
  4263. loadShipAddress();
  4264. // 获取地址信息
  4265. $http.get('resources/citydata/city.json', {
  4266. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  4267. }).then(function (response) {
  4268. $scope.provinces = response.data;
  4269. });
  4270. // 新增收货地址保存
  4271. $scope.saveShipAddress = function (ship) {
  4272. ship.address = ship.province + ship.city + ship.district;
  4273. ShipAddress.saveAddress({}, ship, function (data) {
  4274. if (data.success) {
  4275. // 获取收货地址列表
  4276. loadShipAddress();
  4277. toaster.pop('success', '提示', data.success);
  4278. }
  4279. if (data.error) {
  4280. toaster.pop('error', '提示', data.error);
  4281. }
  4282. });
  4283. };
  4284. $scope.currentDay = function () {
  4285. return $filter('date')(new Date(), 'yyyy-MM-dd');
  4286. };
  4287. $scope.vendors = [];
  4288. // 查找供应商
  4289. $scope.dbfindVendor = function () {
  4290. var modalInstance = $modal.open({
  4291. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  4292. controller: 'DbfindVendorCtrl',
  4293. size: 'lg',
  4294. resolve: {}
  4295. });
  4296. modalInstance.result.then(function (data) {
  4297. var ifPush = true;
  4298. modalInstance.result.then(function (data) {
  4299. angular.forEach(data, function (vendor) {
  4300. if (!$scope.vendors) {// 不存在就先创建
  4301. $scope.vendors = [{}];
  4302. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  4303. } else {
  4304. for (var i = 0; i < $scope.vendors.length; i++) {
  4305. ifPush = true;
  4306. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  4307. ifPush = false;
  4308. break; // 判定到已存在供应商,就终止循环。
  4309. }
  4310. }
  4311. if (ifPush) {
  4312. $scope.vendors.push({
  4313. enName: vendor.vendorEnterprise.enName,
  4314. enuu: vendor.vendorEnterprise.uu
  4315. });
  4316. }
  4317. }
  4318. });
  4319. $rootScope.tenderVendor = $scope.vendors;
  4320. }, function () {
  4321. });
  4322. }, function () {
  4323. });
  4324. };
  4325. // 删除一个供应商
  4326. $scope.removeVendor = function (index) {
  4327. $scope.vendors.splice(index, 1);
  4328. };
  4329. $scope.removeChecked = function () {
  4330. if ($scope.vendors.length > 0) {
  4331. $scope.vendors = [];
  4332. $rootScope.tenderVendor = '';
  4333. }
  4334. }
  4335. // 物料信息
  4336. $scope.tableParams = new ngTableParams({
  4337. page: 1,
  4338. count: 20,
  4339. sorting: {
  4340. id: 'desc'
  4341. }
  4342. }, {
  4343. total: 0,
  4344. counts: [5, 10, 25, 50],
  4345. getData: function ($defer, params) {
  4346. $scope.loading = true;
  4347. var pageParams = params.url();
  4348. pageParams.keyword = $scope.keyword;
  4349. $scope.tip = $scope.keyword;
  4350. pageParams.searchFilter = $scope.searchFilter;
  4351. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4352. $scope.loading = false;
  4353. if (page) {
  4354. params.total(page.totalElement);
  4355. $scope.total = page.totalElement;
  4356. $defer.resolve(page.content);
  4357. }
  4358. }, function (response) {
  4359. $scope.loading = false;
  4360. toaster.pop('error', '数据加载失败', response.data);
  4361. });
  4362. }
  4363. });
  4364. // 搜索框回车
  4365. $scope.onSearch = function (keyword) {
  4366. // 每次搜索重置获取数据方法
  4367. $scope.searchMethod = false;
  4368. if(keyword != null && keyword != '') {
  4369. $scope.searchMethod = true;
  4370. }
  4371. $scope.tableParams.page(1);
  4372. $scope.tableParams.reload();
  4373. };
  4374. $scope.inquiry.inquiryItems = [];
  4375. var prod = {
  4376. cmpCode: null,
  4377. prodTitle: null,
  4378. inbrand: null,
  4379. toDate: null,
  4380. unit: 'PCS',
  4381. needquantity: null
  4382. };
  4383. $scope.inquiry.inquiryItems.push(prod);
  4384. // 联想词start
  4385. // 获取品牌联想词
  4386. $scope.getSimilarBrands = function (value) {
  4387. if (value) {
  4388. // 获取品牌联想词
  4389. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  4390. return data.map(function (item) {
  4391. return item;
  4392. });
  4393. });
  4394. }
  4395. };
  4396. // 获取产品型号联想词
  4397. $scope.getSimilarCodes = function (value) {
  4398. if (value) {
  4399. // 获取产品型号联想词
  4400. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  4401. return data.map(function (item) {
  4402. return item;
  4403. })
  4404. });
  4405. }
  4406. };
  4407. $scope.selectKind = function (prod) {
  4408. var submit = [];
  4409. $modal.open({
  4410. animation: true,
  4411. size: 'lg',
  4412. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  4413. controller: 'ProdKindChooseCtrl',
  4414. resolve: {
  4415. actives: function () {
  4416. return $scope.actives;
  4417. }
  4418. }
  4419. }).result.then(function (data) {
  4420. $scope.actives = data.actives;
  4421. var size = data.actives.length;
  4422. submit.gradeOneKiName = '';
  4423. submit.gradeTwoKiName = '';
  4424. submit.gradeThreeKiName = '';
  4425. if (size > 0) {
  4426. submit.gradeOneKiName = $scope.actives[0].nameCn;
  4427. prod.prodTitle = submit.gradeOneKiName;
  4428. if (size > 1) {
  4429. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  4430. prod.prodTitle = submit.gradeTwoKiName;
  4431. if (size > 2) {
  4432. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  4433. prod.prodTitle = submit.gradeThreeKiName;
  4434. }
  4435. }
  4436. }
  4437. }, function () {
  4438. });
  4439. };
  4440. // 点击联想词获取品牌信息
  4441. $scope.onAssociateBrandClick = function (brand, prod) {
  4442. if (brand instanceof String) {
  4443. prod.inbrand = brand;
  4444. } else if (brand instanceof Object) {
  4445. prod.inbrand = brand.brandCn;
  4446. }
  4447. };
  4448. // 打开品牌选择的模态框
  4449. $scope.selectBrand = function (prod) { //打开模态
  4450. var modalInstance = $modal.open({
  4451. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  4452. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  4453. });
  4454. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  4455. });
  4456. modalInstance.result.then(function (brand) {
  4457. prod.inbrand = brand.nameCn;
  4458. }, function (reason) {
  4459. });
  4460. };
  4461. // 点击联想词获取器件信息 带入产品分类和品牌
  4462. $scope.onAssociateCmpClick = function (cmp, prod) {
  4463. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  4464. $scope.component = data;
  4465. prod.cmpCode = data.code;
  4466. prod.prodTitle = data.kind.nameCn;
  4467. prod.inbrand = data.brand.nameCn;
  4468. }, function (res) {
  4469. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  4470. })
  4471. };
  4472. //联想词end
  4473. // 导入商品信息
  4474. $scope.uplodaByBatch = function () {
  4475. var modalInstance = $modal.open({
  4476. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  4477. controller: 'PurcInquiryUploadCtrl',
  4478. size: 'lg',
  4479. resolve: {}
  4480. });
  4481. modalInstance.result.then(function (data) {
  4482. angular.forEach(data, function (prod) {
  4483. $scope.inquiry.inquiryItems.push(prod);
  4484. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4485. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4486. $scope.inquiry.inquiryItems.splice(i, 1);
  4487. }
  4488. }
  4489. })
  4490. }, function () {
  4491. });
  4492. }
  4493. //增加商品
  4494. $scope.add = function () {
  4495. $scope.inquiry.inquiryItems.push(
  4496. {
  4497. cmpCode: null,
  4498. prodTitle: null,
  4499. unit: 'PCS',
  4500. ibrand: null,
  4501. toDate: null,
  4502. needquantity: null
  4503. });
  4504. };
  4505. //删除商品
  4506. $scope.del = function (index) {
  4507. $scope.inquiry.inquiryItems.splice(index, 1);
  4508. };
  4509. $scope.check = function (product) {
  4510. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4511. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4512. $scope.inquiry.inquiryItems.splice(i, 1);
  4513. }
  4514. }
  4515. $scope.inquiry.inquiryItems.push({
  4516. cmpCode: product.cmpCode, prodTitle: product.title, spec: product.spec, unit: product.unit,
  4517. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand
  4518. });
  4519. }
  4520. $scope.getMinDate = function (item) {
  4521. return $filter('date')(new Date, 'yyyy-MM-dd');
  4522. };
  4523. $scope.openDatePicker = function ($event, openParam, index) {
  4524. $event.preventDefault();
  4525. $event.stopPropagation();
  4526. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  4527. };
  4528. $scope.openEndDatePicker = function ($event, item, openParam) {
  4529. $event.preventDefault();
  4530. $event.stopPropagation();
  4531. item[openParam] = !item[openParam];
  4532. };
  4533. $scope.ifrepeat = false;
  4534. // 保存
  4535. $scope.save = function () {
  4536. $scope.loading = true;
  4537. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4538. $scope.item = $scope.inquiry.inquiryItems[i];
  4539. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4540. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4541. if (i != j) {
  4542. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4543. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4544. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4545. $scope.ifrepeat = true;
  4546. }
  4547. }
  4548. }
  4549. }
  4550. if (!$scope.ifrepeat) {
  4551. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4552. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4553. if ($scope.vendors.length > 0) {
  4554. $upload.upload({
  4555. url: 'purc/inquiry/save/withVendor',
  4556. file: file,
  4557. method: 'POST',
  4558. data: {
  4559. inquiry: $scope.inquiry,
  4560. contacts: $scope.vendors
  4561. },
  4562. }).success(function (data) {
  4563. $scope.loading = false;
  4564. if (data.success) {
  4565. toaster.pop('success', '提示', data.success);
  4566. $timeout(function () {
  4567. $rootScope.active = 'todo';
  4568. window.location.hash = "#/purc/inquiry_unapply";
  4569. }, 500);
  4570. }
  4571. if (data.error) {
  4572. toaster.pop('error', '提示', data.error);
  4573. }
  4574. }).error(function (data, status, headers, config) {
  4575. $scope.loadingShow = false;
  4576. if (status == 403) { // 抛异常专用
  4577. toaster.pop('error', '操作失败', data);
  4578. } else {
  4579. toaster.pop('error', '操作失败', data.error);
  4580. }
  4581. });
  4582. } else {
  4583. toaster.pop('info', '提示', '请先选择供应商');
  4584. }
  4585. } else {
  4586. $upload.upload({
  4587. url: 'purc/inquiry/save/withoutVendor',
  4588. file: file,
  4589. method: 'POST',
  4590. data: {
  4591. inquiry: $scope.inquiry,
  4592. },
  4593. }).success(function (data) {
  4594. $scope.loading = false;
  4595. if (data.success) {
  4596. toaster.pop('success', '提示', data.success);
  4597. $timeout(function () {
  4598. $rootScope.active = 'done';
  4599. window.location.hash = "#/baseInfo/inquiryList";
  4600. }, 500);
  4601. }
  4602. if (data.error) {
  4603. toaster.pop('error', '提示', data.error);
  4604. }
  4605. }).error(function (data, status, headers, config) {
  4606. $scope.loadingShow = false;
  4607. if (status == 403) { // 抛异常专用
  4608. toaster.pop('error', '操作失败', data);
  4609. } else {
  4610. toaster.pop('error', '操作失败', data.error);
  4611. }
  4612. });
  4613. }
  4614. } else {
  4615. $scope.loading = false;
  4616. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4617. }
  4618. }
  4619. // 保存并提交
  4620. $scope.submit = function () {
  4621. $scope.loading = true;
  4622. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4623. $scope.item = $scope.inquiry.inquiryItems[i];
  4624. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4625. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4626. if (i != j) {
  4627. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4628. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4629. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4630. $scope.ifrepeat = true;
  4631. }
  4632. }
  4633. }
  4634. }
  4635. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4636. if (!$scope.ifrepeat) {
  4637. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4638. if ($scope.vendors.length > 0) {
  4639. $upload.upload({
  4640. url: 'purc/inquiry/submit/withVendor',
  4641. file: file,
  4642. method: 'POST',
  4643. data: {
  4644. inquiry: $scope.inquiry,
  4645. contacts: $scope.vendors
  4646. },
  4647. }).success(function (data) {
  4648. $scope.loading = false;
  4649. if (data.success) {
  4650. toaster.pop('success', '提示', data.success);
  4651. $timeout(function () {
  4652. window.location.hash = "#/purc/purchaseinquiry";
  4653. }, 500);
  4654. }
  4655. if (data.error) {
  4656. toaster.pop('error', '提示', data.error);
  4657. }
  4658. }).error(function (data, status, headers, config) {
  4659. $scope.loadingShow = false;
  4660. if (status == 403) { // 抛异常专用
  4661. toaster.pop('error', '操作失败', data);
  4662. } else {
  4663. toaster.pop('error', '操作失败', data.error);
  4664. }
  4665. });
  4666. } else {
  4667. toaster.pop('info', '提示', '请先选择供应商');
  4668. }
  4669. } else {
  4670. $upload.upload({
  4671. url: 'purc/inquiry/submit/withoutVendor',
  4672. file: file,
  4673. method: 'POST',
  4674. data: {
  4675. inquiry: $scope.inquiry,
  4676. },
  4677. }).success(function (data) {
  4678. $scope.loading = false;
  4679. if (data.success) {
  4680. toaster.pop('success', '提示', data.success);
  4681. $timeout(function () {
  4682. window.location.hash = "#/baseInfo/inquiryList";
  4683. }, 500);
  4684. }
  4685. if (data.error) {
  4686. toaster.pop('error', '提示', data.error);
  4687. }
  4688. }).error(function (data, status, headers, config) {
  4689. $scope.loadingShow = false;
  4690. if (status == 403) { // 抛异常专用
  4691. toaster.pop('error', '操作失败', data);
  4692. } else {
  4693. toaster.pop('error', '操作失败', data.error);
  4694. }
  4695. });
  4696. }
  4697. } else {
  4698. $scope.loading = false;
  4699. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4700. }
  4701. }
  4702. $scope.previewShow = false;
  4703. $scope.pdfShow = false;
  4704. $scope.noneFileShow = true;
  4705. $scope.$watch('myFiles', function () {
  4706. if ($scope.myFiles) {
  4707. $scope.noneFileShow = false;
  4708. var file = $scope.myFiles[0];
  4709. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  4710. $scope.pdfShow = true;
  4711. $scope.previewShow = false;
  4712. $scope.imgPreviewName = file.name;
  4713. } else {
  4714. if (typeof(Worker) !== "undefined") {//支持HTML5
  4715. $scope.imgPreview = getObjectURL(file);
  4716. $scope.imgPreviewName = file.name;
  4717. } else {//不支持HTML5
  4718. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  4719. $scope.imgPreviewName = file.name;
  4720. }
  4721. $scope.previewShow = true;
  4722. $scope.pdfShow = false;
  4723. }
  4724. } else {
  4725. $scope.noneFileShow = true;
  4726. $scope.previewShow = false;
  4727. $scope.pdfShow = false;
  4728. }
  4729. });
  4730. //建立一个可存取到该file的url
  4731. var getObjectURL = function (file) {
  4732. var url = null;
  4733. if (window.createObjectURL != undefined) { // basic
  4734. url = window.createObjectURL(file);
  4735. } else if (window.URL != undefined) { // mozilla(firefox)
  4736. url = window.URL.createObjectURL(file);
  4737. } else if (window.webkitURL != undefined) { // webkit or chrome
  4738. url = window.webkitURL.createObjectURL(file);
  4739. }
  4740. return url;
  4741. };
  4742. }]);
  4743. /**
  4744. * 代采订单批量导入
  4745. */
  4746. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  4747. // 通过excel批量上传物料
  4748. $scope.result = null;
  4749. $scope.upload = function () {
  4750. var file = $scope.myFiles[0];
  4751. $upload.upload({
  4752. url: 'purc/inquiry/release/excel',
  4753. file: file,
  4754. method: 'POST'
  4755. }).success(function (data) {
  4756. $scope.result = data;
  4757. $scope.success = $scope.result.success;
  4758. $scope.total = $scope.result.total;
  4759. $scope.alters = $scope.result.alters;
  4760. }).error(function (response) {
  4761. toaster.pop('error', response.data || response);
  4762. });
  4763. };
  4764. // 查看范例
  4765. $scope.showImg = function () {
  4766. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  4767. box.show();
  4768. box.find('img').attr('src', src);
  4769. box.find('a').click(function () {
  4770. box.hide();
  4771. });
  4772. box.dblclick(function () {
  4773. box.hide();
  4774. });
  4775. };
  4776. // 下载模板
  4777. $scope.download = function () {
  4778. window.location.href = 'purc/inquiry/upload/template';
  4779. };
  4780. $scope.enSure = function () {
  4781. $modalInstance.close($scope.result.items);
  4782. }
  4783. $scope.cancel = function () {
  4784. $modalInstance.dismiss();
  4785. }
  4786. }]);
  4787. // 平台询价单(已提交)
  4788. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', 'CurrentRole', function ($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope, CurrentRole) {
  4789. $scope.status = 'InquirySubmit';
  4790. BaseService.scrollBackToTop();
  4791. // 获取当前用户是否为普通用户
  4792. CurrentRole.isUser({}, {}, function (data) {
  4793. $scope.isUser = data.isUser;
  4794. });
  4795. if ($rootScope.active) {
  4796. $scope.active = $rootScope.active;
  4797. $rootScope.active = null;
  4798. } else {
  4799. $scope.active = 'todo';
  4800. }
  4801. $scope.agreedText = '全部';
  4802. $scope.dateZoneText = '一个月内';
  4803. $scope.condition = {dateZone: 1};
  4804. /* 时间筛选初始化*/
  4805. var fromDate = new Date();
  4806. var toDate = new Date();
  4807. fromDate.setMonth(fromDate.getMonth() - 1);
  4808. fromDate.setHours(0, 0, 0, 0);
  4809. toDate.setHours(23, 59, 59, 999);
  4810. $scope.condition.dateFrom = fromDate;
  4811. $scope.condition.dateTo = toDate;
  4812. $scope.changeAgreed = function (agreed) {
  4813. $scope.condition.agreed = agreed;
  4814. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4815. $scope.condition.$agreedOpen = false;
  4816. };
  4817. $scope.changeDateZone = function (zone) {
  4818. $scope.condition.dateZone = zone;
  4819. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4820. $scope.condition.$dateZoneOpen = false;
  4821. getDateCondition(zone, $scope.condition);
  4822. $scope.tableParams.page(1);
  4823. $scope.tableParams.reload();
  4824. };
  4825. $scope.setActive = function (state) {
  4826. if ($scope.active != state) {
  4827. $scope.active = state;
  4828. if ($scope.tableParams.page() == 1) {
  4829. $scope.tableParams.reload();
  4830. } else {
  4831. $scope.tableParams.page(1);
  4832. }
  4833. }
  4834. }
  4835. var getService = function () {
  4836. return PurchaseInquiry;
  4837. };
  4838. $scope.tableParams = new ngTableParams({
  4839. page: 1,
  4840. count: 20,
  4841. sorting: {
  4842. 'inquiry.date': 'desc',
  4843. 'inquiry.enterprise.enName': 'asc',
  4844. 'inquiry.code': 'asc'
  4845. }
  4846. }, {
  4847. total: 0,
  4848. counts: [5, 10, 25, 50],
  4849. getData: function ($defer, params) {
  4850. $scope.loading = true;
  4851. var pageParams = params.url();
  4852. var realActive = {};
  4853. pageParams.searchFilter = {
  4854. keyword: $scope.keyword,
  4855. fromDate: getDateTime($scope.condition.dateFrom),
  4856. endDate: getDateTime($scope.condition.dateTo)
  4857. };
  4858. if ($scope.active == 'overdue') {
  4859. $scope.active = 'end';
  4860. }
  4861. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4862. $scope.loading = false;
  4863. if (page) {
  4864. params.total(page.totalElement);
  4865. $defer.resolve(page.content);
  4866. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4867. }
  4868. }, function (response) {
  4869. $scope.loading = false;
  4870. toaster.pop('error', '数据加载失败', response.data);
  4871. });
  4872. }
  4873. });
  4874. //获得各分类未阅读数量
  4875. var getUnreadCount = function () {
  4876. PurchaseInquiry.getUnreadCount(null, function(data){
  4877. $scope.unread = data;
  4878. });
  4879. };
  4880. getUnreadCount();
  4881. //设置单据已读
  4882. $scope.setOrdersRead = function (id) {
  4883. // 如果单据本身已读,则不发送请求修改数据
  4884. if (!$scope.isUnread(id)){
  4885. return;
  4886. }
  4887. var sourceId = [];
  4888. sourceId.push(id);
  4889. PurchaseInquiry.setRead({}, sourceId, function (message) {
  4890. getUnreadIds();
  4891. getUnreadCount();
  4892. });
  4893. };
  4894. //获得未读单据id
  4895. var getUnreadIds = function (){
  4896. PurchaseInquiry.getUnreadIds({}, "", function (message) {
  4897. $scope.unreadCode = message.content;
  4898. });
  4899. };
  4900. getUnreadIds();
  4901. //判断单据是否未读
  4902. $scope.isUnread = function (id){
  4903. for (var i in $scope.unreadCode) {
  4904. if (id == $scope.unreadCode[i]) {
  4905. return true;
  4906. }
  4907. }
  4908. };
  4909. $scope.openDatePicker = function ($event, item, openParam) {
  4910. $event.preventDefault();
  4911. $event.stopPropagation();
  4912. item[openParam] = !item[openParam];
  4913. };
  4914. $scope.openFilterDatePicker = function ($event, item, openParam) {
  4915. $event.preventDefault();
  4916. $event.stopPropagation();
  4917. item[openParam] = !item[openParam];
  4918. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  4919. $scope.tableParams.reload();
  4920. }
  4921. };
  4922. // 搜索框回车
  4923. $scope.onSearch = function () {
  4924. $scope.tableParams.page(1);
  4925. $scope.tableParams.reload();
  4926. };
  4927. // 采纳
  4928. $scope.accept = function (id) {
  4929. PurchaseInquiry.accept({id: id}, {}, function (data) {
  4930. if (data.success) {
  4931. toaster.pop('success', '提示', data.success);
  4932. $scope.tableParams.reload();
  4933. }
  4934. if (data.error) {
  4935. toaster.pop('error', '提示', data.error);
  4936. }
  4937. }, function (response) {
  4938. toaster.pop('error', '提示', response.data);
  4939. })
  4940. };
  4941. // 拒绝
  4942. $scope.refuse = function (id) {
  4943. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  4944. if (data.success) {
  4945. toaster.pop('success', '提示', data.success);
  4946. $scope.tableParams.reload();
  4947. }
  4948. if (data.error) {
  4949. toaster.pop('error', '提示', data.error);
  4950. }
  4951. }, function (response) {
  4952. toaster.pop('error', '提示', response.data);
  4953. })
  4954. }
  4955. // 导出
  4956. $scope.exportXls = function () {
  4957. PurchaseInquiry.exportXls({}, {}, function (data) {
  4958. if (data.success){
  4959. window.location.href = 'purc/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4960. }
  4961. }, function (response) {
  4962. toaster.pop('error', '数据加载失败', response.data);
  4963. });
  4964. }
  4965. }]);
  4966. // 平台询价单(未提交)
  4967. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function ($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  4968. BaseService.scrollBackToTop();
  4969. if ($rootScope.active = 'done') {
  4970. $scope.active = 'done';
  4971. $rootScope.active = '';
  4972. }
  4973. if ($rootScope.active = 'todo') {
  4974. $scope.active = 'todo';
  4975. $rootScope.active = '';
  4976. }
  4977. var getService = function () {
  4978. if ($scope.active == 'todo') {
  4979. return PurchaseInquiry.getUnapply;
  4980. }
  4981. if ($scope.active == 'done') {
  4982. return PurchaseInquiry.getSubmit;
  4983. }
  4984. }
  4985. $scope.setActive = function (state) {
  4986. if ($scope.active != state) {
  4987. $scope.active = state;
  4988. if ($scope.tableParams.page() == 1) {
  4989. $scope.tableParams.reload();
  4990. } else {
  4991. $scope.tableParams.page(1);
  4992. }
  4993. }
  4994. }
  4995. $scope.tableParams = new ngTableParams({
  4996. page: 1,
  4997. count: 20,
  4998. sorting: {
  4999. 'date': 'desc',
  5000. 'enterprise.enName': 'asc',
  5001. 'code': 'asc'
  5002. }
  5003. }, {
  5004. total: 0,
  5005. counts: [5, 10, 25, 50],
  5006. getData: function ($defer, params) {
  5007. $scope.loading = true;
  5008. var pageParams = params.url();
  5009. var realActive = {};
  5010. if ($scope.active == 'overdue') {
  5011. $scope.active = 'end';
  5012. }
  5013. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  5014. $scope.loading = false;
  5015. if (page) {
  5016. params.total(page.totalElements);
  5017. $defer.resolve(page.content);
  5018. }
  5019. }, function (response) {
  5020. $scope.loading = false;
  5021. toaster.pop('error', '数据加载失败', response.data);
  5022. });
  5023. }
  5024. });
  5025. // 删除明细
  5026. $scope.deleteById = function (id) {
  5027. PurchaseInquiry.deleteById({id: id}, {}, function (data) {
  5028. toaster.pop('success', '提示', '删除成功');
  5029. $scope.tableParams.reload();
  5030. }, function (response) {
  5031. toaster.pop('error', '提示', response.data);
  5032. });
  5033. }
  5034. // 删除主表
  5035. $scope.clearOrder = function (id) {
  5036. PurchaseInquiry.clearOrder({id: id}, {}, function (data) {
  5037. toaster.pop('success', '提示', '删除成功');
  5038. $scope.tableParams.reload();
  5039. }, function (response) {
  5040. toaster.pop('error', '提示', response.data);
  5041. });
  5042. }
  5043. // 提交
  5044. $scope.submit = function (id) {
  5045. PurchaseInquiry.submitUnapply({id: id}, {}, function (data) {
  5046. toaster.pop('success', '提示', '单据提交成功');
  5047. $scope.active = 'done';
  5048. $scope.tableParams.reload();
  5049. }, function (response) {
  5050. toaster.pop('error', '提示', response.data);
  5051. })
  5052. }
  5053. // 发布公共询价
  5054. $scope.publish = function (id) {
  5055. PurchaseInquiry.publishInquiry({id: id}, {}, function (data) {
  5056. toaster.pop('success', '提示', data.success);
  5057. $scope.active = 'done';
  5058. $scope.tableParams.reload();
  5059. }, function (response) {
  5060. toaster.pop('error', '提示', response.data);
  5061. })
  5062. }
  5063. }]);
  5064. // 公共询价列表
  5065. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'PurcInquiry', 'publicInquiry', 'publicInquiryList', '$modal', '$http', 'AccountEnterprise', 'customer', 'AuthenticationService', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, PurcInquiry, publicInquiry, publicInquiryList, $modal, $http, AccountEnterprise, customer, AuthenticationService) {
  5066. BaseService.scrollBackToTop();
  5067. /**
  5068. * 改变单据日期范围
  5069. */
  5070. var getTenderDateCondition = function (zone, condition) {
  5071. var date = new Date();
  5072. if (zone == -1) {
  5073. condition.dateFrom = null;
  5074. condition.dateTo = null;
  5075. } else if (zone == 7) { // 一星期内
  5076. date.setHours(0, 0, 0 ,0);
  5077. date.setDate(date.getDate() - 7);
  5078. condition.dateFrom = date;
  5079. var ndate = new Date();
  5080. ndate.setHours(23, 59, 59 ,999);
  5081. ndate.setDate(ndate.getDate() - 1);
  5082. condition.dateTo = ndate;
  5083. } else if (zone == 1) { // 一个月内
  5084. date.setMonth(date.getMonth() - 1);
  5085. condition.dateFrom = date;
  5086. condition.dateTo = new Date();
  5087. } else if (zone == 3) { // 三个月内
  5088. date.setMonth(date.getMonth() - 3);
  5089. condition.dateFrom = date;
  5090. condition.dateTo = new Date();
  5091. } else if (zone == 6) { // 半年内
  5092. date.setMonth(date.getMonth() - 6);
  5093. condition.dateFrom = date;
  5094. condition.dateTo = new Date();
  5095. } else { // 一年内
  5096. date.setYear(date.getYear() - 1);
  5097. condition.dateFrom = date;
  5098. condition.dateTo = new Date();
  5099. }
  5100. };
  5101. $scope.active = 'enterprise';
  5102. $scope.dateZoneText = '不限';
  5103. $scope.deliveryZoneText = '不限';
  5104. $scope.condition = {dateZone: -1};
  5105. $scope.changeDateZone = function (zone) {
  5106. $scope.condition.dateZone = zone;
  5107. $scope.condition.$dateZoneOpen = false;
  5108. getTenderDateCondition(zone, $scope.condition);
  5109. $scope.tableParams.page(1);
  5110. $scope.tableParams.reload();
  5111. };
  5112. $scope.openDatePicker = function ($event, item, openParam) {
  5113. $event.preventDefault();
  5114. $event.stopPropagation();
  5115. item[openParam] = !item[openParam];
  5116. };
  5117. $scope.parseDate = function (dateStr) {
  5118. if (dateStr)
  5119. return Date.parse(dateStr, 'yyyy-MM-dd');
  5120. return new Date();
  5121. };
  5122. $scope.isOverDue = function (date) {
  5123. if (date) {
  5124. var ndate = new Date();
  5125. ndate.setHours(23, 59, 59 ,999);
  5126. ndate.setDate(ndate.getDate());
  5127. var timestamp = Date.parse(ndate);
  5128. if (date > timestamp) {
  5129. return true;
  5130. } else {
  5131. return false;
  5132. }
  5133. } else {
  5134. return true;
  5135. }
  5136. }
  5137. // 选择查找日期
  5138. $scope.onDateCondition = function () {
  5139. $scope.tableParams.page(1);
  5140. $scope.tableParams.reload();
  5141. };
  5142. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  5143. var getState = function (active) {
  5144. var fn = 'getOpenAll';
  5145. switch (active) {
  5146. case 'all':
  5147. fn = 'getOpenAll';
  5148. break;
  5149. case 'todo':
  5150. fn = 'getOpenTodo';
  5151. break;
  5152. case 'end':
  5153. fn = 'getOpenEnd';
  5154. break;
  5155. }
  5156. return fn;
  5157. };
  5158. customer.distribute({}, function(data) {
  5159. $scope.customer = data;
  5160. });
  5161. $scope.setActive = function (state) {
  5162. if ($scope.active != state) {
  5163. $scope.active = state;
  5164. if ($scope.active == 'enterprise') {
  5165. $scope.distribute = null;
  5166. $scope.remind = false;
  5167. } else if ($scope.active == 'customer') {
  5168. $scope.distribute = $scope.customer;
  5169. if ($scope.distribute.length == 0) {
  5170. $scope.distribute = [0];
  5171. }
  5172. $scope.remind = false;
  5173. } else if ($scope.active == 'remind') {
  5174. $scope.remind = true;
  5175. } else if ($scope.active == 'all') {
  5176. $scope.distribute = null;
  5177. $scope.remind = false;
  5178. }
  5179. if ($scope.tableParams.page() == 1) {
  5180. $scope.tableParams.reload();
  5181. } else {
  5182. $scope.tableParams.page(1);
  5183. }
  5184. }
  5185. };
  5186. var getService = function () {
  5187. return publicInquiryList.getInquirylist;
  5188. }
  5189. $scope.tableParams = new ngTableParams({
  5190. page: 1,
  5191. count: 20,
  5192. sorting: {
  5193. }
  5194. }, {
  5195. total: 0,
  5196. counts: [10, 25, 50, 100],
  5197. getData: function ($defer, params) {
  5198. $scope.loading = true;
  5199. var pageParams = params.url();
  5200. pageParams.searchFilter = { // 筛选条件
  5201. keyword: $scope.keyword,
  5202. fromDate: getDateTime($scope.condition.dateFrom),
  5203. endDate: getDateTime($scope.condition.dateTo)
  5204. };
  5205. AccountEnterprise.get({}, function(data) {
  5206. $scope.currentEn = data;
  5207. publicInquiry.getUrl({}, function(data) {
  5208. $scope.url = data.url;
  5209. if ($scope.active == 'enterprise') {// 企业商机
  5210. AuthenticationService.getAuthentication().success(function (data) {
  5211. $scope.loading = false;
  5212. $scope.thisUser = data;
  5213. $http({
  5214. method: 'get',
  5215. dataType: 'json',
  5216. url: $scope.url + '/inquiry/sale/enremind',
  5217. params: {
  5218. pageNumber: pageParams.page,
  5219. pageSize: pageParams.count,
  5220. useruu: $scope.thisUser.userUU,
  5221. enuu: $scope.currentEn.uu,
  5222. keyword: $scope.keyword,
  5223. fromDate: getDateTime($scope.condition.dateFrom),
  5224. endDate: getDateTime($scope.condition.dateTo)
  5225. }
  5226. }).success(function (response) {
  5227. $scope.loading = false;
  5228. if (response) {
  5229. params.total(response.totalElements);
  5230. $defer.resolve(response.content);
  5231. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5232. }
  5233. }).error(function (err) {
  5234. $scope.loading = false;
  5235. toaster.pop('error', '数据加载失败', err);
  5236. });
  5237. });
  5238. } else if ($scope.active == 'remind') {// 推荐报价信息
  5239. AuthenticationService.getAuthentication().success(function (data) {
  5240. $scope.loading = false;
  5241. $scope.thisUser = data;
  5242. $http({
  5243. method: 'get',
  5244. dataType: 'json',
  5245. url: $scope.url + '/inquiry/sale/remind',
  5246. params: {pageNumber: pageParams.page, pageSize: pageParams.count, useruu: $scope.thisUser.userUU, enuu: $scope.currentEn.uu,
  5247. keyword: $scope.keyword, fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)}
  5248. }).success(function (response) {
  5249. $scope.loading = false;
  5250. if (response) {
  5251. params.total(response.totalElements);
  5252. $defer.resolve(response.content);
  5253. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5254. }
  5255. }).error(function (err) {
  5256. $scope.loading = false;
  5257. toaster.pop('error', '数据加载失败', err);
  5258. });
  5259. });
  5260. } else if ($scope.active == 'all') {// 全部
  5261. $http({
  5262. method: 'get',
  5263. dataType: 'json',
  5264. url: $scope.url + '/inquiry/public',
  5265. params: {pageNumber: pageParams.page, pageSize: pageParams.count, enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  5266. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo), distribute: $scope.distribute, remind: $scope.remind}
  5267. }).success(function (response) {
  5268. $scope.loading = false;
  5269. if (response) {
  5270. params.total(response.totalElements);
  5271. $defer.resolve(response.content);
  5272. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5273. }
  5274. }).error(function (err) {
  5275. $scope.loading = false;
  5276. toaster.pop('error', '数据加载失败', err);
  5277. });
  5278. }
  5279. // 顶部滚动消息
  5280. $http({
  5281. method: 'get',
  5282. url: $scope.url + '/inquiry/public/messageList',
  5283. params: {enuu: $scope.currentEn.uu, size: 10},
  5284. dataType: 'json'
  5285. }).success(function(data) {
  5286. $scope.message = data;
  5287. }).error(function(error) {
  5288. });
  5289. });
  5290. });
  5291. }
  5292. });
  5293. $scope.toDetail = function (item) {
  5294. if (item.quoted == 0) {
  5295. window.location.hash = '#/baseInfo/inquiryList/' + item.id;
  5296. } else {
  5297. window.open("#/sale/pubinquiry/" + item.quteId);
  5298. }
  5299. };
  5300. // 转客户询价
  5301. $scope.qute = function (remind) {
  5302. $http({
  5303. method: 'get',
  5304. dataType: 'json',
  5305. url: $scope.url + '/inquiry/sale/quote',
  5306. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  5307. }).success(function (response) {
  5308. $scope.loading = false;
  5309. if (response.inquiry != null) {
  5310. toaster.pop('error', '该单据已报价');
  5311. } else {
  5312. $http({
  5313. method: 'get',
  5314. dataType: 'json',
  5315. url: $scope.url + '/inquiry/public/findItemByItemId',
  5316. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  5317. }).success(function (response) {
  5318. var inquiryItem = response;
  5319. var modalInstance = $modal.open({
  5320. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5321. controller: 'QuoteCtrl',
  5322. size: 'lg',
  5323. resolve: {
  5324. inquiryItem: function () {
  5325. return inquiryItem
  5326. }
  5327. }
  5328. });
  5329. modalInstance.result.then(function (data) {
  5330. $scope.tableParams.reload();
  5331. }, function () {
  5332. });
  5333. }).error(function (error) {
  5334. toaster.pop('error', '数据加载失败', error);
  5335. });
  5336. }
  5337. }).error(function (err) {
  5338. toaster.pop('error', '数据加载失败', err);
  5339. });
  5340. }
  5341. // 跳转详情
  5342. $scope.remindDetail = function(remind) {
  5343. if (remind.newId == null) {
  5344. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  5345. } else {
  5346. window.open("#/sale/pubinquiry/" + remind.newId);
  5347. }
  5348. }
  5349. // 搜索框回车
  5350. $scope.onSearch = function () {
  5351. $scope.tableParams.page(1);
  5352. $scope.tableParams.reload();
  5353. };
  5354. // 转客户询价
  5355. $scope.transtoInquiry = function (inquiryItem) {
  5356. if ($scope.currentEn.uu == inquiryItem.inquiry.enUU) {
  5357. toaster.pop('warning', '不能对自己企业报价');
  5358. } else {
  5359. var modalInstance = $modal.open({
  5360. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5361. controller: 'QuoteCtrl',
  5362. size: 'lg',
  5363. resolve: {
  5364. inquiryItem: function () {
  5365. return inquiryItem
  5366. }
  5367. }
  5368. });
  5369. modalInstance.result.then(function (data) {
  5370. $scope.tableParams.reload();
  5371. }, function () {
  5372. });
  5373. }
  5374. }
  5375. // 跳转到我的报价列表
  5376. $scope.linkToInquiry = function () {
  5377. window.open("#/sale/pubinquiry");
  5378. }
  5379. }]);
  5380. /**
  5381. * 报价操作
  5382. */
  5383. app.controller('QuoteCtrl', ['$scope', 'inquiryItem', 'toaster', 'publicInquiry', '$modalInstance', '$upload', function($scope, inquiryItem, toaster, publicInquiry, $modalInstance, $upload) {
  5384. $scope.inquiryItem = inquiryItem;
  5385. if ($scope.inquiryItem.replies == null || $scope.inquiryItem.replies.length == 0) {
  5386. $scope.inquiryItem.replies = [];
  5387. var reply = {
  5388. lapQty: 0,
  5389. price: null
  5390. };
  5391. $scope.inquiryItem.replies.push(reply);
  5392. }
  5393. $scope.replyPrices = [];
  5394. $scope.replylapQtys = [];
  5395. $scope.replyPrices.push(true);
  5396. $scope.replylapQtys.push(true);
  5397. // 获取默认币别
  5398. publicInquiry.getCurrency({}, function(data) {
  5399. $scope.currencies = data;
  5400. });
  5401. // 增加一列分段报价
  5402. $scope.addStep = function (inquiryItem) {
  5403. var check = true;
  5404. angular.forEach(inquiryItem.replies, function(reply) {
  5405. if (reply.lapQty == null) {
  5406. toaster.pop('error', '提示', '存在未填写分段数量的分段,请先填写分段数量');
  5407. check = false;
  5408. }
  5409. if (check && reply.price == null) {
  5410. toaster.pop('error', '提示', '存在未填写价格的分段,请先填写价格');
  5411. check = false;
  5412. }
  5413. });
  5414. if (check) {
  5415. $scope.replyPrices.push(true);
  5416. if (inquiryItem.replies.length >= 5) {
  5417. toaster.pop('warning', '提示', '最多支持5个分段!');
  5418. } else {
  5419. inquiryItem.replies.push({});
  5420. if (inquiryItem.replies.length != 1) {
  5421. $scope.replyPrices.push(true);
  5422. $scope.replylapQtys.push(true);
  5423. }
  5424. }
  5425. }
  5426. };
  5427. // 删除一列分段报价
  5428. $scope.removeStep = function (inquiryItem, stepIndex) {
  5429. inquiryItem.replies.splice(stepIndex, 1);
  5430. $scope.replyPrices.splice(stepIndex, 1);
  5431. $scope.replylapQtys.splice(stepIndex, 1);
  5432. };
  5433. // 取消,关闭弹出框
  5434. $scope.cancel = function() {
  5435. $modalInstance.dismiss();
  5436. }
  5437. // 保存报价信息
  5438. $scope.save = function(inquiryItem, method) {
  5439. var replies = [];
  5440. // 判断分段数是否合法
  5441. var valid = true;
  5442. var validLapQty = 0;
  5443. angular.forEach(inquiryItem.replies, function (r, i) {
  5444. if ((i > 0 ? r.lapQty : 1) || r.price) {
  5445. replies.push(r);
  5446. }
  5447. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  5448. if (i > 0 && parseInt(r.lapQty) <= parseInt(inquiryItem.replies[i - 1].lapQty) || r.lapQty == null) {
  5449. valid = false;
  5450. validLapQty = r.lapQty;
  5451. }
  5452. });
  5453. inquiryItem.replies = replies;
  5454. $scope.loading = true;
  5455. if (!valid) {
  5456. if (validLapQty) {
  5457. toaster.pop('error', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  5458. } else {
  5459. toaster.pop('error', '提示', '分段数量不合法,不能报价!');
  5460. }
  5461. } else {
  5462. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  5463. $upload.upload({
  5464. url: 'pubInquiry/turnToQuotation',
  5465. file: file,
  5466. method: 'POST',
  5467. data: {
  5468. item: inquiryItem,
  5469. method: method
  5470. }
  5471. }).success(function (data) {
  5472. if (data.item) {
  5473. item = data.item;
  5474. }
  5475. $scope.loading = false;
  5476. toaster.pop('info', '提示', '报价成功');
  5477. $modalInstance.close();
  5478. }).error(function (data) {
  5479. $scope.loading = false;
  5480. toaster.pop('error', '附件上传失败');
  5481. });
  5482. }
  5483. }
  5484. $scope.previewShow = false;
  5485. $scope.pdfShow = false;
  5486. $scope.noneFileShow = true;
  5487. $scope.$watch('myFiles', function () {
  5488. if ($scope.myFiles) {
  5489. $scope.noneFileShow = false;
  5490. var file = $scope.myFiles[0];
  5491. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  5492. $scope.pdfShow = true;
  5493. $scope.previewShow = false;
  5494. $scope.imgPreviewName = file.name;
  5495. } else {
  5496. if (typeof(Worker) !== "undefined") {//支持HTML5
  5497. $scope.imgPreview = getObjectURL(file);
  5498. $scope.imgPreviewName = file.name;
  5499. } else {//不支持HTML5
  5500. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  5501. $scope.imgPreviewName = file.name;
  5502. }
  5503. $scope.previewShow = true;
  5504. $scope.pdfShow = false;
  5505. }
  5506. } else {
  5507. $scope.noneFileShow = true;
  5508. $scope.previewShow = false;
  5509. $scope.pdfShow = false;
  5510. }
  5511. });
  5512. //建立一个可存取到该file的url
  5513. var imgurl = null;
  5514. var getObjectURL = function (file) {
  5515. var url = null;
  5516. if (window.createObjectURL != undefined) { // basic
  5517. url = window.createObjectURL(file);
  5518. } else if (window.URL != undefined) { // mozilla(firefox)
  5519. url = window.URL.createObjectURL(file);
  5520. } else if (window.webkitURL != undefined) { // webkit or chrome
  5521. url = window.webkitURL.createObjectURL(file);
  5522. }
  5523. imgurl = url;
  5524. return url;
  5525. };
  5526. }]);
  5527. /**
  5528. * 公共询价详情
  5529. */
  5530. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', 'publicInquiry', 'publicInquiryList', '$modal', '$http', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise, publicInquiry, publicInquiryList, $modal, $http) {
  5531. BaseService.scrollBackToTop();
  5532. $scope.currentHasBid = false;
  5533. var loadData = function () {
  5534. // 当前企业
  5535. AccountEnterprise.get({}, function (data) {
  5536. $scope.enterprise = data
  5537. publicInquiry.getUrl({}, function(data) {
  5538. var url = data.url;
  5539. $http({
  5540. method: 'get',
  5541. dataType: 'json',
  5542. url: url + '/inquiry/sale/publicInquiry/detail',
  5543. params: {id: $stateParams.id, enuu: $scope.enterprise.uu}
  5544. }).success(function (response) {
  5545. if (response) {
  5546. $scope.inquiryItem = response.inquiryItem;
  5547. }
  5548. }).error(function (err) {
  5549. toaster.pop('error', '数据加载失败', err);
  5550. });
  5551. });
  5552. });
  5553. };
  5554. loadData();
  5555. // 当前时间
  5556. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  5557. // 当前企业
  5558. AccountEnterprise.get({}, function (data) {
  5559. $scope.enterprise = data;
  5560. });
  5561. $scope.isOverDue = function (date) {
  5562. if (date) {
  5563. var ndate = new Date();
  5564. ndate.setHours(23, 59, 59 ,999);
  5565. ndate.setDate(ndate.getDate());
  5566. var timestamp = Date.parse(ndate);
  5567. if (date > timestamp) {
  5568. return true;
  5569. } else {
  5570. return false;
  5571. }
  5572. } else {
  5573. return true;
  5574. }
  5575. }
  5576. // 转客户询价
  5577. $scope.transtoInquiry = function (inquiryItem) {
  5578. publicInquiry.quotationInfo({id: inquiryItem.id}, function(data) {
  5579. if (data.inquiryItem) { //存在已报价的就不进行报价操作
  5580. toaster.pop('error', '该询价单已已经报价');
  5581. } else {
  5582. var modalInstance = $modal.open({
  5583. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5584. controller: 'QuoteCtrl',
  5585. size: 'lg',
  5586. resolve: {
  5587. inquiryItem: function () {
  5588. return inquiryItem
  5589. }
  5590. }
  5591. });
  5592. modalInstance.result.then(function (data) {
  5593. $scope.tableParams.reload();
  5594. }, function () {
  5595. });
  5596. }
  5597. });
  5598. }
  5599. }]);
  5600. // 询价单明细
  5601. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, CurrentRole) {
  5602. // 获取当前用户是否为普通用户
  5603. CurrentRole.isUser({}, {}, function (data) {
  5604. $scope.isUser = !data.isUser;
  5605. });
  5606. var loadData = function () {
  5607. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  5608. $scope.newinquiryItems = data;
  5609. var inquiry = data[0].inquiry;
  5610. //inquiry.inquiryItems = data;
  5611. angular.forEach(inquiry.attachs, function (attach) {
  5612. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5613. });
  5614. $scope.inquiry = inquiry;
  5615. });
  5616. };
  5617. loadData();
  5618. $scope.getMinDate = function (item) {
  5619. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5620. };
  5621. $scope.addStep = function (inquiryItem) {
  5622. if (inquiryItem.replies.length >= 10) {
  5623. toaster.pop('warning', '提示', '最多支持10个分段!');
  5624. } else
  5625. inquiryItem.replies.push({});
  5626. };
  5627. $scope.removeStep = function (inquiryItem, stepIndex) {
  5628. inquiryItem.replies.splice(stepIndex, 1);
  5629. };
  5630. $scope.openDatePicker = function ($event, item, openParam) {
  5631. $event.preventDefault();
  5632. $event.stopPropagation();
  5633. item[openParam] = !item[openParam];
  5634. };
  5635. $scope.getHistory = function (item) {
  5636. if (!item.history) {
  5637. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5638. item.history = data;
  5639. });
  5640. }
  5641. };
  5642. $scope.isValid = function (item, withSteps) {
  5643. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5644. if (!withSteps || !bool)
  5645. return bool;
  5646. angular.forEach(item.replies, function (r, i) {
  5647. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5648. });
  5649. return bool;
  5650. };
  5651. $scope.onReplyClick = function (item, withSteps) {
  5652. if (item.vendFromDate instanceof Date) {
  5653. item.vendFromDate = item.vendFromDate.getTime();
  5654. }
  5655. if (item.vendToDate instanceof Date) {
  5656. item.vendToDate = item.vendToDate.getTime();
  5657. }
  5658. if (item.vendFromDate > item.vendToDate) {
  5659. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5660. return;
  5661. }
  5662. var replies = [];
  5663. angular.forEach(item.replies, function (r, i) {
  5664. if ((i > 0 ? r.lapQty : 1) || r.price)
  5665. replies.push(r);
  5666. });
  5667. item.replies = replies;
  5668. if (withSteps) {
  5669. PurcInquiry.reply({itemId: item.id}, item, function () {
  5670. toaster.pop('info', '提示', '报价成功');
  5671. loadData();
  5672. }, function (response) {
  5673. toaster.pop('error', '报价失败', response.data);
  5674. });
  5675. }
  5676. };
  5677. }]);
  5678. // 询价单明细(发出)
  5679. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, CurrentRole) {
  5680. // 获取当前用户是否为普通用户
  5681. CurrentRole.isUser({}, {}, function (data) {
  5682. $scope.isUser = data.isUser;
  5683. });
  5684. var loadData = function () {
  5685. PurchaseInquiry.detail({id: $stateParams.id}, {},function (data) {
  5686. $scope.inquiry = data;
  5687. },function (response) {
  5688. toaster.pop('error', '提示', response.data);
  5689. });
  5690. };
  5691. loadData();
  5692. $scope.getMinDate = function (item) {
  5693. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5694. };
  5695. $scope.nowDate = new Date().getTime();
  5696. $scope.addStep = function (inquiryItem) {
  5697. if (inquiryItem.replies.length >= 10) {
  5698. toaster.pop('warning', '提示', '最多支持10个分段!');
  5699. } else
  5700. inquiryItem.replies.push({});
  5701. };
  5702. $scope.removeStep = function (inquiryItem, stepIndex) {
  5703. inquiryItem.replies.splice(stepIndex, 1);
  5704. };
  5705. $scope.openDatePicker = function ($event, item, openParam) {
  5706. $event.preventDefault();
  5707. $event.stopPropagation();
  5708. item[openParam] = !item[openParam];
  5709. };
  5710. $scope.getHistory = function (item) {
  5711. if (!item.history) {
  5712. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5713. item.history = data;
  5714. });
  5715. }
  5716. };
  5717. $scope.isValid = function (item, withSteps) {
  5718. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5719. if (!withSteps || !bool)
  5720. return bool;
  5721. angular.forEach(item.replies, function (r, i) {
  5722. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5723. });
  5724. return bool;
  5725. };
  5726. $scope.onReplyClick = function (item, withSteps) {
  5727. if (item.vendFromDate instanceof Date) {
  5728. item.vendFromDate = item.vendFromDate.getTime();
  5729. }
  5730. if (item.vendToDate instanceof Date) {
  5731. item.vendToDate = item.vendToDate.getTime();
  5732. }
  5733. if (item.vendFromDate > item.vendToDate) {
  5734. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5735. return;
  5736. }
  5737. var replies = [];
  5738. angular.forEach(item.replies, function (r, i) {
  5739. if ((i > 0 ? r.lapQty : 1) || r.price)
  5740. replies.push(r);
  5741. });
  5742. item.replies = replies;
  5743. if (withSteps) {
  5744. PurcInquiry.reply({itemId: item.id}, item, function () {
  5745. toaster.pop('info', '提示', '报价成功');
  5746. loadData();
  5747. }, function (response) {
  5748. toaster.pop('error', '报价失败', response.data);
  5749. });
  5750. }
  5751. };
  5752. // 采纳
  5753. $scope.accept = function (id) {
  5754. PurchaseInquiry.accept({id: id}, {}, function (data) {
  5755. if (data.success) {
  5756. toaster.pop('success', '提示', data.success);
  5757. loadData();
  5758. }
  5759. if (data.error) {
  5760. toaster.pop('error', '提示', data.error);
  5761. }
  5762. }, function (response) {
  5763. toaster.pop('error', '提示', response.data);
  5764. })
  5765. };
  5766. // 拒绝
  5767. $scope.refuse = function (id) {
  5768. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  5769. if (data.success) {
  5770. toaster.pop('success', '提示', data.success);
  5771. loadData();
  5772. }
  5773. if (data.error) {
  5774. toaster.pop('error', '提示', data.error);
  5775. }
  5776. }, function (response) {
  5777. toaster.pop('error', '提示', response.data);
  5778. })
  5779. }
  5780. }]);
  5781. // 模具询价管理
  5782. app.controller('SaleInquiryMouldCtrl', ['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', 'PurcInquiryMouldSql', 'CurrentRole', function ($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload, PurcInquiryMouldSql, CurrentRole) {
  5783. BaseService.scrollBackToTop();
  5784. // 获取当前用户是否为普通用户
  5785. CurrentRole.isUser({}, {}, function (data) {
  5786. $scope.isUser = data.isUser;
  5787. });
  5788. $scope.active = 'todo';
  5789. $scope.agreedText = '全部';
  5790. $scope.dateZoneText = '不限';
  5791. $scope.condition = {dateZone: 1};
  5792. /* 时间筛选初始化*/
  5793. var fromDate = new Date();
  5794. var toDate = new Date();
  5795. fromDate.setMonth(fromDate.getMonth() - 1);
  5796. fromDate.setHours(0, 0, 0, 0);
  5797. toDate.setHours(23, 59, 59, 999);
  5798. $scope.condition.dateFrom = fromDate;
  5799. $scope.condition.dateTo = toDate;
  5800. var inquiryMould_copy = {};
  5801. $scope.changeAgreed = function (agreed) {
  5802. $scope.condition.agreed = agreed;
  5803. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  5804. $scope.condition.$agreedOpen = false;
  5805. };
  5806. $scope.changeDateZone = function (zone) {
  5807. $scope.condition.dateZone = zone;
  5808. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5809. $scope.condition.$dateZoneOpen = false;
  5810. getDateCondition(zone, $scope.condition);
  5811. $scope.tableParams.page(1);
  5812. $scope.tableParams.reload();
  5813. };
  5814. $scope.setActive = function (state) {
  5815. if ($scope.active != state) {
  5816. $scope.active = state;
  5817. if ($scope.tableParams.page() == 1) {
  5818. $scope.tableParams.reload();
  5819. } else {
  5820. $scope.tableParams.page(1);
  5821. }
  5822. }
  5823. };
  5824. var getService = function () {
  5825. if ($scope.keyword) {
  5826. return PurcInquiryMould;
  5827. } else {
  5828. return PurcInquiryMouldSql;
  5829. }
  5830. };
  5831. $scope.tableParams = new ngTableParams({
  5832. page: 1,
  5833. count: 5
  5834. }, {
  5835. total: 0,
  5836. counts: [5, 10, 25, 50],
  5837. getData: function ($defer, params) {
  5838. $scope.loading = true;
  5839. var pageParams = params.url();
  5840. var realActive = {};
  5841. pageParams.searchFilter = {
  5842. keyword: $scope.keyword,
  5843. fromDate: getDateTime($scope.condition.dateFrom),
  5844. endDate: getDateTime($scope.condition.dateTo)
  5845. };
  5846. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  5847. $scope.loading = false;
  5848. // 用来验证价格修改
  5849. var mould = page.content;
  5850. inquiryMould_copy = angular.copy(mould);
  5851. if (page) {
  5852. params.total(page.totalElement);
  5853. $defer.resolve(page.content);
  5854. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词 $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5855. }
  5856. }, function (response) {
  5857. $scope.loading = false;
  5858. toaster.pop('error', '数据加载失败', response.data);
  5859. });
  5860. }
  5861. });
  5862. //获得各分类未阅读数量
  5863. var getUnreadCount = function () {
  5864. PurcInquiryMould.getUnreadCount(null, function(data){
  5865. $scope.unread = data;
  5866. });
  5867. };
  5868. getUnreadCount();
  5869. //设置单据已读
  5870. $scope.setOrdersRead = function (id) {
  5871. // 如果单据本身已读,则不发送请求修改数据
  5872. if (!$scope.isUnread(id)){
  5873. return;
  5874. }
  5875. var sourceId = [];
  5876. sourceId.push(id);
  5877. PurcInquiryMould.setRead({}, sourceId, function (message) {
  5878. // $scope.getUnreadIds();
  5879. getUnreadCount();
  5880. });
  5881. };
  5882. $scope.setOrdersReadByState = function () {
  5883. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  5884. return;
  5885. }
  5886. PurcInquiryMould.setReadByState({}, function () {
  5887. getUnreadIds();
  5888. getUnreadCount();
  5889. });
  5890. };
  5891. //获取未读单据id
  5892. var getUnreadIds = function (){
  5893. PurcInquiryMould.getUnreadIds({}, "", function (message) {
  5894. $scope.unreadCode = message.content;
  5895. });
  5896. };
  5897. getUnreadIds();
  5898. //判断单据是否未读
  5899. $scope.isUnread = function (id){
  5900. for (var i in $scope.unreadCode) {
  5901. if (id == $scope.unreadCode[i]) {
  5902. return true;
  5903. }
  5904. }
  5905. };
  5906. $scope.getMinDate = function (item) {
  5907. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  5908. };
  5909. $scope.replyPrices = [];
  5910. $scope.replyPrices.push(true);
  5911. // 取消
  5912. $scope.reload = function () {
  5913. $scope.tableParams.reload();
  5914. $scope.canSave = false;
  5915. }
  5916. // 能否保存设置
  5917. $scope.canSave = false;
  5918. // items价格验证
  5919. $scope.verifyItems = function (price, reply) {
  5920. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  5921. if (regex.test(price) && price != 0) {
  5922. if (price != reply) {
  5923. $scope.canSave = true;
  5924. } else {
  5925. $scope.canSave = false;
  5926. }
  5927. } else {
  5928. $scope.canSave = false;
  5929. }
  5930. }
  5931. // prod下prods价格验证
  5932. $scope.verifyProds = function (price, reply) {
  5933. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5934. if (regex.test(price) && price != 0) {
  5935. if (price != reply) {
  5936. $scope.canSave = true;
  5937. } else {
  5938. $scope.canSave = false;
  5939. }
  5940. } else {
  5941. $scope.canSave = false;
  5942. }
  5943. }
  5944. //有价格为0或者不符合正则式,则不能报价
  5945. $scope.notZero = function (mould) {
  5946. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5947. angular.forEach(mould.inquiryMouldItems, function (item) {
  5948. if (item.price == 0 || !regex.test(item.price)) {
  5949. $scope.canSave = false;
  5950. }
  5951. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5952. if (detail.price == 0 || !regex.test(detail.price)) {
  5953. $scope.canSave = false;
  5954. }
  5955. })
  5956. });
  5957. }
  5958. $scope.blurPrice = function (price) {
  5959. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5960. if (!regex.test(price)) {
  5961. toaster.pop('warning', '格式错误', '请输入有效价格');
  5962. }
  5963. }
  5964. // 获取历史报价
  5965. $scope.getHistory = function (mould) {
  5966. if (!mould.history) {
  5967. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  5968. $scope.historyShow = true;
  5969. mould.history = data;
  5970. },function (response) {
  5971. $scope.historyShow = false;
  5972. });
  5973. }
  5974. };
  5975. var uploadAttach = function (mould, file) {
  5976. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5977. $scope.mould = mould;
  5978. $upload.upload({
  5979. url: 'sale/mould/' + mould.id + '/send',
  5980. method: 'POST',
  5981. file: file,
  5982. data: {
  5983. json: $scope.mould
  5984. }
  5985. }).success(function (res) {
  5986. $scope.mould.sellAttachs.push(res);
  5987. }).error(function (res) {
  5988. });
  5989. }
  5990. $scope.pushFile = function(mould, file) {
  5991. // var file = $scope.myFiles;
  5992. if (file.length > 0) {
  5993. for (var i = 0; i < file.length; i++) {
  5994. console.log(file[i].name);
  5995. var flag = true;
  5996. if (mould.sellAttachs.length > 0) {
  5997. for (var j = 0; j < mould.sellAttachs.length; j++) {
  5998. if (mould.sellAttachs[j].name == file[i].name
  5999. && mould.sellAttachs[j].size == file[i].size) {
  6000. flag = false;
  6001. break;
  6002. }
  6003. }
  6004. }
  6005. if (flag) {
  6006. uploadAttach(mould, file[i]);
  6007. $scope.canSave = true;
  6008. }
  6009. }
  6010. }
  6011. document.getElementById("inquiryMould.sellAttachs").value = "";
  6012. };
  6013. $scope.removeFile = function(mould, file) {
  6014. $scope.inquiryMould = mould;
  6015. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  6016. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  6017. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  6018. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  6019. $scope.inquiryMould.sellAttachs.splice(i, 1);
  6020. }
  6021. }
  6022. }
  6023. };
  6024. // 保存并确认报价
  6025. $scope.onReplyClick = function (mould, withSteps) {
  6026. $scope.loading = true;
  6027. if (withSteps) {
  6028. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  6029. $scope.loading = false;
  6030. toaster.pop('info', '提示', '报价成功');
  6031. $scope.tableParams.reload();
  6032. $scope.canSave = false;
  6033. }, function (response) {
  6034. $scope.loading = false;
  6035. toaster.pop('error', '报价失败', response.data);
  6036. });
  6037. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  6038. }, function (response) {
  6039. });
  6040. } else {
  6041. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  6042. $scope.loading = false;
  6043. toaster.pop('info', '提示', '保存成功');
  6044. $scope.tableParams.reload();
  6045. }, function (response) {
  6046. $scope.loading = false;
  6047. toaster.pop('error', '保存失败', response.data);
  6048. });
  6049. }
  6050. };
  6051. // 搜索框回车
  6052. $scope.onSearch = function () {
  6053. $scope.tableParams.page(1);
  6054. $scope.tableParams.reload();
  6055. };
  6056. $scope.openDatePicker = function ($event, item, openParam) {
  6057. $event.preventDefault();
  6058. $event.stopPropagation();
  6059. item[openParam] = !item[openParam];
  6060. };
  6061. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6062. $event.preventDefault();
  6063. $event.stopPropagation();
  6064. item[openParam] = !item[openParam];
  6065. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6066. $scope.tableParams.reload();
  6067. }
  6068. };
  6069. $scope.parseDate = function (dateStr) {
  6070. if (dateStr)
  6071. return Date.parse(dateStr, 'yyyy-MM-dd');
  6072. return new Date();
  6073. };
  6074. // 导出客户资料列表
  6075. $scope.exportXls = function () {
  6076. PurcInquiryMould.exportXls({}, {}, function (data) {
  6077. if (data.success){
  6078. window.location.href = 'sale/mould/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  6079. }
  6080. }, function (response) {
  6081. toaster.pop('error', '数据加载失败', response.data);
  6082. });
  6083. }
  6084. }]);
  6085. // 模具询价单明细
  6086. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould', '$filter', 'toaster', '$upload', 'CurrentRole', function ($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload, CurrentRole) {
  6087. // 获取当前用户是否为普通用户
  6088. CurrentRole.isUser({}, {}, function (data) {
  6089. $scope.isUser = data.isUser;
  6090. });
  6091. var inquiryMould_copy = {};
  6092. var loadData = function () {
  6093. PurcInquiryMould.getAll({id: $stateParams.id}, function (data) {
  6094. // 用来验证价格修改
  6095. inquiryMould_copy = angular.copy(data);
  6096. $scope.inquiryMould_copy = inquiryMould_copy;
  6097. $scope.newinquirymould = data;
  6098. var mould = data;
  6099. angular.forEach(mould.attachs, function (attach) {
  6100. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  6101. });
  6102. $scope.inquiryMould = mould;
  6103. }, function (response) {
  6104. toaster.pop('error', '数据加载失败', response.data);
  6105. });
  6106. };
  6107. loadData();
  6108. $scope.getMinDate = function (item) {
  6109. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  6110. };
  6111. // 取消
  6112. $scope.reload = function () {
  6113. loadData();
  6114. $scope.canSave = false;
  6115. }
  6116. //有价格为0,则不能报价
  6117. $scope.notZero = function (mould) {
  6118. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  6119. angular.forEach(mould.inquiryMouldItems, function (item) {
  6120. if (item.price == 0 || !regex.test(item.price)) {
  6121. $scope.canSave = false;
  6122. }
  6123. angular.forEach(item.inquiryMouldDetails, function (detail) {
  6124. if (detail.price == 0 || !regex.test(detail.price)) {
  6125. $scope.canSave = false;
  6126. }
  6127. })
  6128. });
  6129. }
  6130. $scope.blurPrice = function (price) {
  6131. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  6132. if (!regex.test(price)) {
  6133. toaster.pop('warning', '格式错误', '请输入有效价格');
  6134. }
  6135. }
  6136. // 获取历史报价
  6137. $scope.getHistory = function (mould) {
  6138. if (!mould.history) {
  6139. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  6140. $scope.historyShow = true;
  6141. mould.history = data;
  6142. },function (response) {
  6143. $scope.historyShow = false;
  6144. //toaster.pop('error', '提示', response.data);
  6145. });
  6146. }
  6147. };
  6148. $scope.canSave = false;
  6149. // items价格验证
  6150. $scope.verifyItems = function (price, index) {
  6151. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  6152. if (regex.test(price) && price != 0) {
  6153. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  6154. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  6155. $scope.canSave = true;
  6156. } else {
  6157. $scope.canSave = false;
  6158. }
  6159. } else {
  6160. $scope.canSave = false;
  6161. }
  6162. }
  6163. // prod下prods价格验证
  6164. $scope.verifyProds = function (price, index, parentIndex) {
  6165. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  6166. if (regex.test(price) && price != 0) {
  6167. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  6168. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  6169. $scope.canSave = true;
  6170. } else {
  6171. $scope.canSave = false;
  6172. }
  6173. } else {
  6174. $scope.canSave = false;
  6175. }
  6176. }
  6177. // 上传附件
  6178. var uploadAttach = function(file) {
  6179. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  6180. $scope.mould = $scope.inquiryMould;
  6181. $upload.upload({
  6182. url: 'sale/mould/' + $scope.mould.id + '/send',
  6183. method: 'POST',
  6184. file: file,
  6185. data: {
  6186. json: $scope.mould
  6187. }
  6188. }).success(function(attach){
  6189. if (attach){
  6190. $scope.inquiryMould.sellAttachs.push(attach);
  6191. }
  6192. }).error(function(res){
  6193. console.log("failure");
  6194. console.log(res);
  6195. });
  6196. }
  6197. $scope.pushFile = function(file) {
  6198. // var file = $scope.myFiles;
  6199. if (file.length > 0) {
  6200. for (var i = 0; i < file.length; i++) {
  6201. console.log(file[i].name);
  6202. var flag = true;
  6203. if ($scope.inquiryMould.sellAttachs.length > 0) {
  6204. for (var j = 0; j < $scope.inquiryMould.sellAttachs.length; j++) {
  6205. if ($scope.inquiryMould.sellAttachs[j].name == file[i].name
  6206. && $scope.inquiryMould.sellAttachs[j].size == file[i].size) {
  6207. flag = false;
  6208. break;
  6209. }
  6210. }
  6211. }
  6212. if (flag) {
  6213. uploadAttach(file[i]);
  6214. }
  6215. }
  6216. }
  6217. };
  6218. $scope.removeFile = function(file) {
  6219. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  6220. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  6221. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  6222. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  6223. $scope.inquiryMould.sellAttachs.splice(i, 1);
  6224. document.getElementById("file").value = "";
  6225. }
  6226. }
  6227. }
  6228. };
  6229. $scope.onReplyClick = function (mould, withSteps) {
  6230. $scope.loading = true;
  6231. if (withSteps) {
  6232. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  6233. $scope.loading = false;
  6234. toaster.pop('info', '提示', '报价成功');
  6235. loadData();
  6236. $scope.canSave = false;
  6237. }, function (response) {
  6238. $scope.loading = false;
  6239. toaster.pop('error', '报价失败', response.data);
  6240. });
  6241. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  6242. }, function (response) {
  6243. });
  6244. } else {
  6245. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  6246. $scope.loading = false;
  6247. toaster.pop('info', '提示', '保存成功');
  6248. loadData();
  6249. }, function (response) {
  6250. $scope.loading = false;
  6251. toaster.pop('error', '保存失败', response.data);
  6252. });
  6253. }
  6254. };
  6255. }]);
  6256. // 主动报价 - 列表
  6257. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', 'QuotationInfo', 'CurrentRole', function ($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope, QuotationInfo, CurrentRole) {
  6258. BaseService.scrollBackToTop();
  6259. // 获取当前用户是否为普通用户
  6260. CurrentRole.isUser({}, {}, function (data) {
  6261. $scope.isUser = data.isUser;
  6262. });
  6263. $rootScope.enteryStatus = false;
  6264. $scope.active = 'todo';
  6265. $scope.agreedText = '全部';
  6266. $scope.dateZoneText = '一个月内';
  6267. $scope.condition = {dateZone: 1};
  6268. /* 时间筛选初始化*/
  6269. var fromDate = new Date();
  6270. var toDate = new Date();
  6271. fromDate.setMonth(fromDate.getMonth() - 1);
  6272. fromDate.setHours(0, 0, 0, 0);
  6273. toDate.setHours(23, 59, 59, 999);
  6274. $scope.condition.dateFrom = fromDate;
  6275. $scope.condition.dateTo = toDate;
  6276. $scope.changeDateZone = function (zone) {
  6277. $scope.condition.dateZone = zone;
  6278. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6279. $scope.condition.$dateZoneOpen = false;
  6280. getDateCondition(zone, $scope.condition);
  6281. $scope.tableParams.page(1);
  6282. $scope.tableParams.reload();
  6283. };
  6284. $scope.setActive = function (state) {
  6285. if ($scope.active != state) {
  6286. $scope.active = state;
  6287. if ($scope.tableParams.page() == 1)
  6288. $scope.tableParams.reload();
  6289. else
  6290. $scope.tableParams.page(1);
  6291. }
  6292. };
  6293. $scope.searchMethod = false;
  6294. var getService = function () {
  6295. return $scope.searchMethod ? Quotation : QuotationInfo;
  6296. };
  6297. $scope.tableParams = new ngTableParams({
  6298. page: 1,
  6299. count: 20,
  6300. sorting: {
  6301. 'date': 'desc'
  6302. }
  6303. }, {
  6304. total: 0,
  6305. counts: [5, 10, 25, 50],
  6306. getData: function ($defer, params) {
  6307. $scope.loading = true;
  6308. var pageParams = params.url();
  6309. pageParams.searchFilter = {
  6310. keyword: $scope.keyword,
  6311. fromDate: getDateTime($scope.condition.dateFrom),
  6312. endDate: getDateTime($scope.condition.dateTo)
  6313. };
  6314. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6315. $scope.loading = false;
  6316. if (page) {
  6317. params.total(page.totalElement);
  6318. $defer.resolve(page.content);
  6319. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6320. }
  6321. }, function (response) {
  6322. $scope.loading = false;
  6323. toaster.pop('error', '数据加载失败', response.data);
  6324. });
  6325. }
  6326. });
  6327. $scope.openDatePicker = function ($event, item, openParam) {
  6328. $event.preventDefault();
  6329. $event.stopPropagation();
  6330. item[openParam] = !item[openParam];
  6331. };
  6332. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6333. $event.preventDefault();
  6334. $event.stopPropagation();
  6335. item[openParam] = !item[openParam];
  6336. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6337. $scope.tableParams.reload();
  6338. }
  6339. };
  6340. $scope.getHistory = function (item) {
  6341. if (!item.history) {
  6342. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  6343. item.history = data;
  6344. });
  6345. }
  6346. };
  6347. $scope.isValid = function (item, withSteps) {
  6348. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  6349. if (!withSteps || !bool)
  6350. return bool;
  6351. angular.forEach(item.replies, function (r, i) {
  6352. bool = (i > 0 ? r.lapQty : 1) && r.price;
  6353. });
  6354. return bool;
  6355. };
  6356. // 搜索框回车
  6357. $scope.onSearch = function (keyword) {
  6358. // 每次搜索重置获取数据方法
  6359. $scope.searchMethod = false;
  6360. if(keyword != null && keyword != '') {
  6361. $scope.searchMethod = true;
  6362. }
  6363. $scope.tableParams.page(1);
  6364. $scope.tableParams.reload();
  6365. };
  6366. // 导出
  6367. $scope.exportXls = function () {
  6368. Quotation.exportXls({}, {}, function (data) {
  6369. if (data.success){
  6370. window.location.href = 'sale/quotation/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  6371. }
  6372. }, function (response) {
  6373. toaster.pop('error', '数据加载失败', response.data);
  6374. });
  6375. }
  6376. }]);
  6377. // Controller 主动报价 - 新增
  6378. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', 'CurrentRole', function ($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope, CurrentRole) {
  6379. BaseService.scrollBackToTop();
  6380. // 获取当前用户是否为普通用户
  6381. CurrentRole.isUser({}, {}, function (data) {
  6382. $scope.isUser = data.isUser;
  6383. });
  6384. var staticItem = null;
  6385. if (!angular.isUndefined($stateParams.id)) {// 查看模式
  6386. $scope.loading = true;
  6387. $rootScope.enteryStatus = true;
  6388. Quotation.getItem({id: $stateParams.id}, function (data) {
  6389. // data.$editing = false;
  6390. $scope.item = data;
  6391. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  6392. staticItem = angular.copy(data);
  6393. $scope.loading = false;
  6394. }, function (response) {
  6395. $scope.loading = false;
  6396. toaster.pop('error', '数据加载失败', response.data);
  6397. });
  6398. } else {// 新增模式
  6399. $rootScope.enteryStatus = false;
  6400. $scope.item = {
  6401. quotation: {
  6402. currency: 'RMB',
  6403. taxrate: 17,
  6404. },
  6405. product: {},
  6406. prices: [{lapQty: 0}],
  6407. minOrderQty: 1,
  6408. minPackQty: 1,
  6409. $endDateOpen: false,
  6410. $editing: true
  6411. };
  6412. }
  6413. $scope.getMinDate = function (item) {
  6414. return $filter('date')(new Date, 'yyyy-MM-dd');
  6415. };
  6416. //是否不能被点击
  6417. $scope.isDisabled = function () {
  6418. return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
  6419. }
  6420. $scope.openDatePicker = function ($event, openParam) {
  6421. $event.preventDefault();
  6422. $event.stopPropagation();
  6423. $scope.item.$endDateOpen = !openParam;
  6424. };
  6425. // 增加一个分段
  6426. $scope.addPrice = function () {
  6427. if ($scope.item.prices.length >= 10) {
  6428. toaster.pop('warning', '提示', '最多支持10个分段!');
  6429. } else
  6430. $scope.item.prices.push({});
  6431. };
  6432. // 删除一个分段
  6433. $scope.removePrice = function (index) {
  6434. $scope.item.prices.splice(index, 1);
  6435. };
  6436. // 查找客户
  6437. $scope.dbfindCust = function () {
  6438. if ($scope.item.$editing) {
  6439. var modalInstance = $modal.open({
  6440. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  6441. controller: 'DbfindCustCtrl',
  6442. size: 'lg',
  6443. resolve: {}
  6444. });
  6445. modalInstance.result.then(function (data) {
  6446. $scope.item.quotation.cust = data.myEnterprise;
  6447. $scope.item.quotation.custUser = data.myUser;
  6448. $scope.item.product = null;
  6449. }, function () {
  6450. });
  6451. }
  6452. };
  6453. // 赋值客户信息
  6454. if ($rootScope.custuu) {
  6455. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function (data) {
  6456. $scope.item.quotation.cust = data.myEnterprise;
  6457. $scope.item.quotation.custUser = data.myUser;
  6458. })
  6459. }
  6460. // 赋值物料信息
  6461. if ($rootScope.prodId) {
  6462. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  6463. $scope.item.product.code = data.code;
  6464. $scope.item.product.title = data.title;
  6465. $scope.item.product.spec = data.spec;
  6466. $scope.item.product.unit = data.unit;
  6467. $scope.item.product.id = data.id;
  6468. }, function (response) {
  6469. });
  6470. }
  6471. // 查找客户物料
  6472. $scope.dbfindCustProd = function () {
  6473. if ($scope.item.$editing) {
  6474. if ($scope.item.quotation.cust) {
  6475. var modalInstance = $modal.open({
  6476. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  6477. controller: 'DbfindCustProdCtrl',
  6478. size: 'lg',
  6479. resolve: {
  6480. custUU: function () {
  6481. return $scope.item.quotation.cust.uu
  6482. }
  6483. }
  6484. });
  6485. modalInstance.result.then(function (data) {
  6486. $scope.item.product = data;
  6487. }, function () {
  6488. });
  6489. } else {
  6490. toaster.pop('error', '错误', '请先选择客户');
  6491. }
  6492. }
  6493. };
  6494. // 根据传入的询价相关的信息封装成报价需要的信息
  6495. if ($stateParams.inquiryItem != null) {
  6496. var item = $stateParams.inquiryItem;
  6497. $scope.item.quotation.cust = item.inquiry.enterprise;
  6498. $scope.item.quotation.custUser = item.inquiry.recorderUser;
  6499. $scope.item.quotation.custUserUU = item.inquiry.recorderUU;
  6500. if (item.product == null || item.product.id == null) {
  6501. toaster.pop('info', '暂未匹配到物料信息,请手动选择');
  6502. } else {
  6503. $scope.item.product = item.product;
  6504. if (item.replies.length > 0) {
  6505. $scope.item.prices = item.replies;
  6506. angular.forEach($scope.item.prices, function(price) {
  6507. price.id = null;
  6508. });
  6509. }
  6510. $scope.item.quotation.taxrate = item.taxrate;
  6511. $scope.item.minPackQty = item.minPackQty;
  6512. $scope.item.minOrderQty = item.minOrderQty;
  6513. $scope.item.leadtime = item.leadtime;
  6514. $scope.item.quotation.currency = item.currency;
  6515. }
  6516. }
  6517. // 保存
  6518. $scope.save = function () {
  6519. var valid = true;
  6520. angular.forEach($scope.item.prices, function(price, $index) {
  6521. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6522. valid = false;
  6523. }
  6524. });
  6525. if (!valid) {
  6526. toaster.pop('info', '提示', '分段数量请保持递增!');
  6527. } else {
  6528. $scope.loading = true;
  6529. if (!$scope.item.quotation.code) //新增,设单号
  6530. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6531. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6532. if ($scope.item.quotation.custUserUU == null) {
  6533. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6534. }
  6535. $scope.item.productId = $scope.item.product.id;
  6536. Quotation.save({}, $scope.item, function (data) {
  6537. $scope.loading = false;
  6538. $scope.item = data;
  6539. toaster.pop('success', '成功', '保存成功');
  6540. if ($stateParams.id)
  6541. window.location.reload();
  6542. else
  6543. window.location.hash = '#/sale/quotation/list';
  6544. }, function (response) {
  6545. $scope.loading = false;
  6546. toaster.pop('error', '保存失败', response.data);
  6547. });
  6548. }
  6549. };
  6550. // 更新
  6551. $scope.update = function () {
  6552. $scope.item.$editing = true;
  6553. };
  6554. // 取消
  6555. $scope.cancel = function () {
  6556. $scope.item.$editing = false;
  6557. $scope.item = angular.copy(staticItem);
  6558. };
  6559. // 提交
  6560. $scope.submit = function () {
  6561. var valid = true;
  6562. angular.forEach($scope.item.prices, function(price, $index) {
  6563. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6564. valid = false;
  6565. }
  6566. });
  6567. if (!valid) {
  6568. toaster.pop('info', '提示', '分段数量请保持递增!');
  6569. } else {
  6570. $scope.loading = true;
  6571. if (!$scope.item.quotation.code) //新增,设单号
  6572. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6573. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6574. if ($scope.item.quotation.custUserUU == null) {
  6575. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6576. }
  6577. $scope.item.productId = $scope.item.product.id;
  6578. // $scope.item.quotation.status = 101;//已提交
  6579. if ($scope.item.quotation.date instanceof Date) {
  6580. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  6581. }
  6582. if ($scope.item.quotation.endDate instanceof Date) {
  6583. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  6584. }
  6585. Quotation.submit({}, $scope.item, function (data) {
  6586. $scope.loading = false;
  6587. $scope.item = data;
  6588. toaster.pop('success', '成功', '提交成功');
  6589. // window.location.hash = '#/sale/quotation/' + data.id;
  6590. window.location.hash = '#/sale/quotation/list';
  6591. }, function (response) {
  6592. $scope.loading = false;
  6593. toaster.pop('error', '保存失败', response.data);
  6594. });
  6595. }
  6596. };
  6597. $scope.deleteById = function (id) {
  6598. Quotation.deleteById({id: id}, {}, function (data) {
  6599. window.location.href = "#/sale/quotation/list";
  6600. }, function (response) {
  6601. toaster.pop('error', '提示', response.data);
  6602. })
  6603. }
  6604. }]);
  6605. // 查找客户
  6606. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function ($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance) {
  6607. BaseService.scrollBackToTop();
  6608. $scope.tableParams = new ngTableParams({
  6609. page: 1,
  6610. count: 20
  6611. }, {
  6612. total: 0,
  6613. counts: [5, 10, 25, 50],
  6614. getData: function ($defer, params) {
  6615. $scope.loading = true;
  6616. var pageParams = params.url();
  6617. pageParams.keyword = $scope.keyword;
  6618. Customer.get(BaseService.parseParams(pageParams), function (page) {
  6619. $scope.loading = false;
  6620. if (page) {
  6621. params.total(page.totalElement);
  6622. $defer.resolve(page.content);
  6623. }
  6624. $scope.totalCount = page.totalElement;
  6625. }, function (response) {
  6626. $scope.loading = false;
  6627. toaster.pop('error', '数据加载失败', response.data);
  6628. });
  6629. }
  6630. });
  6631. $scope.onSearch = function () {
  6632. $scope.tableParams.page(1);
  6633. $scope.tableParams.reload();
  6634. };
  6635. $scope.cancel = function () {
  6636. $modalInstance.dismiss();
  6637. };
  6638. $scope.check = function (cust) {
  6639. $modalInstance.close(cust);
  6640. };
  6641. }]);
  6642. // 查找客户物料
  6643. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function ($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU) {
  6644. BaseService.scrollBackToTop();
  6645. $scope.tableParams = new ngTableParams({
  6646. page: 1,
  6647. count: 20
  6648. }, {
  6649. total: 0,
  6650. counts: [5, 10, 25, 50],
  6651. getData: function ($defer, params) {
  6652. $scope.loading = true;
  6653. var pageParams = params.url();
  6654. pageParams.keyword = $scope.keyword;
  6655. pageParams.custUU = custUU;
  6656. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  6657. $scope.loading = false;
  6658. if (page) {
  6659. params.total(page.totalElement);
  6660. $defer.resolve(page.content);
  6661. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6662. }
  6663. }, function (response) {
  6664. $scope.loading = false;
  6665. toaster.pop('error', '数据加载失败', response.data);
  6666. });
  6667. }
  6668. });
  6669. // 取消
  6670. $scope.cancel = function () {
  6671. $modalInstance.dismiss();
  6672. };
  6673. // 选择
  6674. $scope.check = function (cust) {
  6675. $modalInstance.close(cust);
  6676. };
  6677. // 搜索框回车
  6678. $scope.onSearch = function () {
  6679. $scope.tableParams.page(1);
  6680. $scope.tableParams.reload();
  6681. };
  6682. }]);
  6683. // 查找供应商
  6684. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', '$rootScope', function ($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope) {
  6685. BaseService.scrollBackToTop();
  6686. // 搜索框回车
  6687. $scope.onSearch = function (keyword) {
  6688. $scope.keyword = keyword;
  6689. $scope.tableParams.page(1);
  6690. $scope.tableParams.reload();
  6691. };
  6692. $scope.tableParams = new ngTableParams({
  6693. page: 1,
  6694. count: 20
  6695. }, {
  6696. total: 0,
  6697. counts: [10, 25, 50, 100],
  6698. getData: function ($defer, params) {
  6699. $scope.loading = true;
  6700. var pageParams = params.url();
  6701. pageParams.keyword = $scope.keyword;
  6702. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  6703. $scope.loading = false;
  6704. if (page) {
  6705. params.total(page.totalElement);
  6706. $defer.resolve(page.content);
  6707. // 添加供应商时,将已存在的选中
  6708. if ($rootScope.tenderVendor) {
  6709. angular.forEach(page.content, function (vendor) {
  6710. for (var i = 0; i < $rootScope.tenderVendor.length; i++) {
  6711. vendor.checked = false;
  6712. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  6713. vendor.checked = true;
  6714. break;
  6715. }
  6716. }
  6717. });
  6718. }
  6719. }
  6720. $scope.totalCount = page.totalElement;
  6721. }, function (response) {
  6722. $scope.loading = false;
  6723. toaster.pop('error', '数据加载失败', response.data);
  6724. });
  6725. }
  6726. });
  6727. $scope.cancel = function () {
  6728. $modalInstance.dismiss();
  6729. };
  6730. $scope.checks = {
  6731. checked: false
  6732. };// 全选框
  6733. $scope.checkAll = function () {
  6734. angular.forEach($scope.tableParams.data, function (vendor) {
  6735. vendor.checked = $scope.checks.checked;
  6736. });
  6737. };
  6738. // 单选
  6739. $scope.checkOne = function (vendor) {
  6740. vendor.checked = true;
  6741. var checked = true;
  6742. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  6743. if (!message.checked) {
  6744. checked = false;
  6745. }
  6746. });
  6747. $scope.checks.checked = checked;
  6748. };
  6749. // 单反选
  6750. $scope.unCheckOne = function (vendor) {
  6751. vendor.checked = false;
  6752. $scope.checks.checked = false;
  6753. };
  6754. $scope.close = function () {
  6755. var vendors = [];
  6756. angular.forEach($scope.tableParams.data, function (vendor) {
  6757. if (vendor.checked) {
  6758. vendors.push(vendor);
  6759. $modalInstance.close(vendors);
  6760. }
  6761. });
  6762. };
  6763. }]);
  6764. // 发货提醒
  6765. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', '$timeout', 'PurcNoticeInfo', 'token', 'CurrentRole', function ($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state, $timeout, PurcNoticeInfo, token, CurrentRole) {
  6766. BaseService.scrollBackToTop();
  6767. // 获取当前用户是否为普通用户
  6768. CurrentRole.isUser({}, {}, function (data) {
  6769. $scope.isUser = data.isUser;
  6770. });
  6771. // 用来记录已经选择的id
  6772. $rootScope.ids = [];
  6773. $scope.active = 'todo';
  6774. $scope.currency = Symbol.currency;
  6775. $scope.dateZoneText = '不限';
  6776. $scope.condition = {dateZone: 6};
  6777. $scope.searchStatus = false;
  6778. /* 时间筛选初始化*/
  6779. var fromDate = new Date();
  6780. var toDate = new Date();
  6781. fromDate.setMonth(fromDate.getMonth() - 6);
  6782. fromDate.setHours(0, 0, 0, 0);
  6783. toDate.setHours(23, 59, 59, 999);
  6784. $scope.condition.dateFrom = fromDate;
  6785. $scope.condition.dateTo = toDate;
  6786. $scope.changeDateZone = function (zone) {
  6787. $scope.condition.dateZone = zone;
  6788. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6789. $scope.condition.$dateZoneOpen = false;
  6790. getDateCondition(zone, $scope.condition);
  6791. $scope.tableParams.page(1);
  6792. $scope.tableParams.reload();
  6793. };
  6794. $scope.setActive = function (state) {
  6795. if ($scope.active != state) {
  6796. $scope.active = state;
  6797. if ($scope.tableParams.page() == 1)
  6798. $scope.tableParams.reload();
  6799. else
  6800. $scope.tableParams.page(1);
  6801. }
  6802. };
  6803. var getService = function () {
  6804. if ($scope.searchStatus) {
  6805. return PurcNotice;
  6806. }
  6807. return PurcNoticeInfo;
  6808. };
  6809. $scope.tableParams = new ngTableParams({
  6810. page: 1,
  6811. count: 20,
  6812. sorting: {
  6813. 'id': 'desc'
  6814. }
  6815. }, {
  6816. total: 0,
  6817. counts: [5, 10, 25, 50],
  6818. getData: function ($defer, params) {
  6819. $scope.loading = true;
  6820. var pageParams = params.url();
  6821. pageParams.keyword = $scope.keyword;
  6822. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6823. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6824. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6825. $scope.loading = false;
  6826. if (page) {
  6827. params.total(page.totalElement);
  6828. $defer.resolve(page.content);
  6829. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6830. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6831. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6832. $scope.checkall = true;
  6833. angular.forEach(page.content, function (notice) {
  6834. if ($rootScope.ids.indexOf(notice.id) > -1) {
  6835. notice.$selected = true;
  6836. } else {
  6837. $scope.checkall = false;
  6838. }
  6839. });
  6840. $scope.checkboxes = {
  6841. checked: $scope.checkall
  6842. };
  6843. }
  6844. }, function (response) {
  6845. $scope.loading = false;
  6846. toaster.pop('error', '数据加载失败', response.data);
  6847. });
  6848. }
  6849. });
  6850. //获得各分类未阅读数量
  6851. var getUnreadCount = function () {
  6852. PurcNotice.getUnreadCount(null, function (data) {
  6853. $scope.unread = data;
  6854. });
  6855. };
  6856. getUnreadCount();
  6857. //设置单据已读
  6858. $scope.setOrdersRead = function (id) {
  6859. // 如果单据本身已读,则不发送请求修改数据
  6860. if (!$scope.isUnread(id)){
  6861. return;
  6862. }
  6863. var sourceId = [];
  6864. sourceId.push(id);
  6865. PurcNotice.setRead({}, sourceId, function (message) {
  6866. // $scope.getUnreadIds();
  6867. getUnreadCount();
  6868. });
  6869. };
  6870. $scope.setOrdersReadByState = function () {
  6871. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  6872. return;
  6873. }
  6874. PurcNotice.setReadByState({}, function () {
  6875. getUnreadIds();
  6876. getUnreadCount();
  6877. });
  6878. };
  6879. var getUnreadIds = function () {
  6880. PurcNotice.getUnreadIds({}, "", function (message) {
  6881. $scope.unreadCode = message.content;
  6882. });
  6883. };
  6884. getUnreadIds();
  6885. $scope.isUnread = function (id) {
  6886. for (var i in $scope.unreadCode) {
  6887. if (id == $scope.unreadCode[i]) {
  6888. return true;
  6889. }
  6890. }
  6891. };
  6892. $scope.openDatePicker = function ($event, item, openParam) {
  6893. $event.preventDefault();
  6894. $event.stopPropagation();
  6895. item[openParam] = !item[openParam];
  6896. };
  6897. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6898. $event.preventDefault();
  6899. $event.stopPropagation();
  6900. item[openParam] = !item[openParam];
  6901. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6902. $scope.tableParams.reload();
  6903. }
  6904. };
  6905. //生成随机单号
  6906. $scope.autoCode = function (notice) {
  6907. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  6908. };
  6909. // 获取token信息 并打开询价模态框
  6910. $scope.getToken = function() {
  6911. token.info({userType: 'salenotice'}, {}, function(data) {
  6912. $scope.token = data.token;
  6913. }, function(response) {
  6914. toaster.pop('error', '提示', response.data);
  6915. });
  6916. }
  6917. //可送货日期
  6918. $scope.sendDate = function (notice) {
  6919. var stock = notice.orderItem.product.ltinstock || 0;
  6920. var de = new Date(notice.delivery);
  6921. if (stock == -1) {
  6922. de.setMonth(de.getMonth() - 1);
  6923. de.setDate(26);
  6924. } else if (stock >= 0) {
  6925. de.setDate(de.getDate() - stock - 1);
  6926. }
  6927. return de;
  6928. };
  6929. $scope.lockstatus = false;
  6930. // 锁定时间按钮5秒
  6931. $scope.lockClick = function (notice) {
  6932. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6933. } else if (!notice.send.code) {
  6934. } else {
  6935. $scope.lockstatus = true;
  6936. $timeout(function () {
  6937. $scope.lockstatus = false;
  6938. }, 5000);
  6939. }
  6940. };
  6941. var isSumbit = false;
  6942. $scope.onReplyClick = function (notice) {
  6943. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6944. toaster.pop('warning', '警告', '数量填写错误!');
  6945. } else if (!notice.send.code) {
  6946. toaster.pop('warning', '警告', '请填写发货单号!');
  6947. } else {
  6948. if (!isSumbit) {
  6949. var send = {
  6950. code: notice.send.code,
  6951. remark: notice.send.remark,
  6952. sendItems: [{qty: notice.send.qty}]
  6953. };
  6954. $scope.loading = true;
  6955. PurcNotice.save({id: notice.id, token: $scope.token}, send, function (data) {
  6956. $scope.loading = false;
  6957. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  6958. $state.go('sale.send_detail', {id: data.id});
  6959. }, function (response) {
  6960. $scope.loading = false;
  6961. toaster.pop('error', '发货失败', response.data);
  6962. });
  6963. isSumbit = true;
  6964. return true;
  6965. } else {
  6966. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6967. return false;
  6968. }
  6969. }
  6970. }
  6971. $scope.checkboxes = {
  6972. checked: false
  6973. };
  6974. angular.forEach($scope.tableParams.data, function (item) {
  6975. $scope.checkboxes.checked = false;
  6976. if($rootScope.ids.in_array(item.id)) {
  6977. $rootScope.ids.remove(item.id);
  6978. $scope.checkboxes.checked = true;
  6979. }
  6980. });
  6981. // 点击勾选全部的复选框
  6982. $scope.checkAll = function () {
  6983. angular.forEach($scope.tableParams.data, function (item) {
  6984. if (!item.waiting) {
  6985. item.$selected = $scope.checkboxes.checked;
  6986. if(item.$selected) {
  6987. if(!$rootScope.ids.in_array(item.id)) {
  6988. $rootScope.ids.push(item.id);
  6989. }
  6990. } else {
  6991. if($rootScope.ids.in_array(item.id)) {
  6992. $rootScope.ids.remove(item.id);
  6993. }
  6994. }
  6995. }
  6996. });
  6997. };
  6998. // 判断数组中是否存在某个对象
  6999. Array.prototype.S = String.fromCharCode(2);
  7000. Array.prototype.in_array = function(e) {
  7001. var r = new RegExp(this.S + e + this.S);
  7002. return (r.test(this.S + this.join(this.S) + this.S));
  7003. }
  7004. // 从数组中移除某个对象
  7005. Array.prototype.remove = function(val) {
  7006. var index = this.indexOf(val);
  7007. if (index > -1) {
  7008. this.splice(index, 1);
  7009. }
  7010. };
  7011. // 点击其中一个明细的复选框
  7012. $scope.checkOne = function (order) {
  7013. var result = true;
  7014. angular.forEach($scope.tableParams.data, function (item) {
  7015. if (item.$selected != true) {
  7016. result = false;
  7017. return;
  7018. }
  7019. });
  7020. if(order.$selected) {
  7021. if(!$rootScope.ids.in_array(order.id)) {
  7022. $rootScope.ids.push(order.id);
  7023. }
  7024. } else {
  7025. if($rootScope.ids.in_array(order.id)) {
  7026. $rootScope.ids.remove(order.id);
  7027. }
  7028. }
  7029. $scope.checkboxes = {
  7030. checked: result
  7031. };
  7032. };
  7033. // 打开批量发货模态框
  7034. var sendByBatch = function() {
  7035. var modalInstance = $modal.open({
  7036. animation: true,
  7037. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  7038. controller: 'SaleNoticeSendByBatchCtrl',
  7039. size: 'lg',
  7040. resolve: {
  7041. selectedNotices: function () {
  7042. return $scope.tableParams.data;
  7043. },
  7044. token: function() {
  7045. return $scope.token;
  7046. },
  7047. ids: function() {
  7048. return $rootScope.ids;
  7049. }
  7050. }
  7051. });
  7052. modalInstance.result.then(function () {
  7053. $scope.tableParams.reload();
  7054. }, function () {
  7055. });
  7056. }
  7057. $scope.sendByBatch = function () {
  7058. if($scope.token == null) {
  7059. token.info({userType: 'salenotice'}, {}, function(data) {
  7060. $scope.token = data.token;
  7061. sendByBatch();
  7062. }, function(response) {
  7063. toaster.pop('error', '提示', response.data);
  7064. });
  7065. } else {
  7066. sendByBatch();
  7067. }
  7068. };
  7069. $scope.getSends = function (notice) {
  7070. if (!notice.sends && notice.endQty > 0) {
  7071. notice.getSendsing = true;
  7072. notice.getSendsError = false;
  7073. PurcNotice.getSends({id: notice.id}, function (data) {
  7074. notice.getSendsing = false;
  7075. notice.getSendsError = false;
  7076. notice.sends = data;
  7077. }, function (response) {
  7078. notice.getSendsing = false;
  7079. notice.getSendsError = true;
  7080. notice.getErrorMessage = response.data;
  7081. });
  7082. }
  7083. };
  7084. // 搜索框回车
  7085. $scope.onSearch = function () {
  7086. $scope.searchStatus = true;
  7087. $scope.tableParams.page(1);
  7088. $scope.tableParams.reload();
  7089. };
  7090. // 选择查找日期
  7091. $scope.onDateCondition = function () {
  7092. $scope.tableParams.page(1);
  7093. $scope.tableParams.reload();
  7094. };
  7095. //货车功能
  7096. var truck = $rootScope.truck;
  7097. if (!truck) {
  7098. SaleTruck.query({}, function (data) {
  7099. $rootScope.truck = data;
  7100. });
  7101. }
  7102. $scope.isInTruck = function (noticeId) {
  7103. return truck.indexOf(noticeId) > -1;
  7104. };
  7105. $scope.addtoTruck = function (notice) {
  7106. SaleTruck.save({noticeId: notice.id}, {}, function (data) {
  7107. $rootScope.truck = data;
  7108. });
  7109. };
  7110. $scope.delFromTruck = function (notice) {
  7111. SaleTruck.remove({noticeId: notice.id}, {}, function (data) {
  7112. $rootScope.truck = data;
  7113. });
  7114. };
  7115. $scope.$watch(function () {
  7116. return $rootScope.truck;
  7117. }, function (data) {
  7118. truck = $rootScope.truck;
  7119. }, true);
  7120. $scope.$watch(function () {
  7121. return $rootScope.dataChanged;
  7122. }, function (data) {
  7123. data && ($scope.tableParams.reload());
  7124. }, true);
  7125. // 导出
  7126. $scope.exportXls = function () {
  7127. PurcNotice.exportXls({}, {}, function (data) {
  7128. if (data.success){
  7129. window.location.href = 'sale/notice/xls?_state='+$scope.active+
  7130. '&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7131. }
  7132. }, function (response) {
  7133. toaster.pop('error', '数据加载失败', response.data);
  7134. });
  7135. }
  7136. }]);
  7137. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', '$timeout', 'token', 'ids', '$rootScope', function ($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state, $timeout, token, ids, $rootScope) {
  7138. // $scope.notices = angular.copy(selectedNotices);
  7139. PurcNotice.findByIds({ids : angular.toJson(ids)}, function(data) {
  7140. $scope.notices = angular.copy(data);
  7141. }, function(res) {
  7142. toaster.pop('error', '提示', '发货提醒查询失败');
  7143. });
  7144. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7145. $scope.saleSend = {
  7146. code: '',
  7147. payments: '',
  7148. currency: '',
  7149. custUU: null,
  7150. custUserUU: null,
  7151. remark: '批量发货',
  7152. sendItems: []
  7153. };
  7154. // 计算总数、总额
  7155. $scope.$watch(function () {
  7156. return $scope.notices;
  7157. }, function (data) {
  7158. var q = 0, t = 0;
  7159. if (data) {
  7160. angular.forEach(data, function (d) {
  7161. q += (d.thisSendQty || 0);
  7162. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  7163. });
  7164. }
  7165. $scope.totalQty = q;
  7166. $scope.total = t;
  7167. }, true);
  7168. /**
  7169. * 删除一个已选中的送货提醒
  7170. */
  7171. $scope.removeOne = function (index) {
  7172. $scope.notices.splice(index, 1);
  7173. };
  7174. $scope.lockstatus = false;
  7175. // 锁定时间按钮5秒
  7176. $scope.lockClick = function () {
  7177. $scope.lockstatus = true;
  7178. $timeout(function () {
  7179. $scope.lockstatus = false;
  7180. }, 5000);
  7181. }
  7182. $scope.lockstatus = false;
  7183. // 锁定时间按钮5秒
  7184. $scope.lockClick = function (notice) {
  7185. if ($scope.saleSend.code == '') {//送货单号为空
  7186. return;
  7187. } else {
  7188. $scope.lockstatus = true;
  7189. $timeout(function () {
  7190. $scope.lockstatus = false;
  7191. }, 5000);
  7192. }
  7193. };
  7194. var isSumbit = false;
  7195. //确认送货
  7196. $scope.sendByBatch = function () {
  7197. $scope.saleSend.sendItems = [];
  7198. if ($scope.saleSend.code == '') {//送货单号为空
  7199. toaster.pop('error', '错误', '请输入送货单号');
  7200. return;
  7201. }
  7202. var a = 0;
  7203. var num = 1;
  7204. var valid = true;
  7205. angular.forEach($scope.notices, function (item, key) {
  7206. if (a == 0) {//第一次
  7207. $scope.saleSend.currency = item.orderItem.order.currency;
  7208. $scope.saleSend.custUU = item.enUU;
  7209. $scope.saleSend.payments = item.orderItem.order.payments;
  7210. a = 1;
  7211. } else {//其他
  7212. if ($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  7213. if ($scope.saleSend.custUU != item.enUU) valid = false;
  7214. if ($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  7215. }
  7216. $scope.saleSend.sendItems.push({
  7217. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++
  7218. });
  7219. });
  7220. if (!valid) {
  7221. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  7222. } else {
  7223. if (!isSumbit) {
  7224. PurcNotice.sendByBatch({token: token}, $scope.saleSend, function (data) {
  7225. if(data.id) {
  7226. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  7227. $modalInstance.close('success');
  7228. $state.go('sale.send_detail', {id: data.id});
  7229. } else {
  7230. toaster.pop('error', '提示', '发货失败,请刷新页面重试');
  7231. }
  7232. }, function (response) {
  7233. toaster.pop('error', '错误', response.data);
  7234. });
  7235. isSumbit = true;
  7236. return true;
  7237. } else {
  7238. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  7239. return false;
  7240. }
  7241. }
  7242. };
  7243. $scope.cancel = function () {
  7244. $modalInstance.dismiss();
  7245. };
  7246. }]);
  7247. /**
  7248. * 发货单
  7249. */
  7250. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'ReportService', function ($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService) {
  7251. BaseService.scrollBackToTop();
  7252. $scope.active = 'all';
  7253. $scope.currency = Symbol.currency;
  7254. $scope.dateZoneText = '不限';
  7255. $scope.condition = {dateZone: 1};
  7256. /* 时间筛选初始化*/
  7257. var fromDate = new Date();
  7258. var toDate = new Date();
  7259. fromDate.setMonth(fromDate.getMonth() - 1);
  7260. fromDate.setHours(0, 0, 0, 0);
  7261. toDate.setHours(23, 59, 59, 999);
  7262. $scope.condition.dateFrom = fromDate;
  7263. $scope.condition.dateTo = toDate;
  7264. $scope.changeDateZone = function (zone) {
  7265. $scope.condition.dateZone = zone;
  7266. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  7267. $scope.condition.$dateZoneOpen = false;
  7268. getDateCondition(zone, $scope.condition);
  7269. $scope.tableParams.page(1);
  7270. $scope.tableParams.reload();
  7271. };
  7272. $scope.setActive = function (state) {
  7273. if ($scope.active != state) {
  7274. $scope.active = state;
  7275. if ($scope.tableParams.page() == 1)
  7276. $scope.tableParams.reload();
  7277. else
  7278. $scope.tableParams.page(1);
  7279. }
  7280. };
  7281. var getService = function () {
  7282. return SaleSend;
  7283. };
  7284. $scope.tableParams = new ngTableParams({
  7285. page: 1,
  7286. count: 20,
  7287. sorting: {
  7288. date: 'desc'
  7289. }
  7290. }, {
  7291. total: 0,
  7292. counts: [5, 10, 25, 50],
  7293. getData: function ($defer, params) {
  7294. $scope.loading = true;
  7295. var pageParams = params.url();
  7296. pageParams.keyword = $scope.keyword;
  7297. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7298. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7299. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7300. $scope.loading = false;
  7301. if (page) {
  7302. params.total(page.totalElement);
  7303. $defer.resolve(page.content);
  7304. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7305. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7306. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7307. }
  7308. }, function (response) {
  7309. $scope.loading = false;
  7310. toaster.pop('error', '数据加载失败', response.data);
  7311. });
  7312. }
  7313. });
  7314. //打印 发货单
  7315. $scope.print = function (send) {
  7316. var newPage = window.open("about:blank");
  7317. SaleSend.printPermission({}, function () {
  7318. SaleSend.printCount({id: send.id}, {}); //增加打印此次
  7319. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id, newPage);
  7320. $scope.tableParams.reload();
  7321. }, function (response) {
  7322. newPage.close();
  7323. toaster.pop('error', '打印失败', response.data);
  7324. });
  7325. };
  7326. $scope.openDatePicker = function ($event, item, openParam) {
  7327. $event.preventDefault();
  7328. $event.stopPropagation();
  7329. item[openParam] = !item[openParam];
  7330. };
  7331. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7332. $event.preventDefault();
  7333. $event.stopPropagation();
  7334. item[openParam] = !item[openParam];
  7335. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7336. $scope.tableParams.reload();
  7337. }
  7338. };
  7339. // 搜索框回车
  7340. $scope.onSearch = function () {
  7341. $scope.tableParams.page(1);
  7342. $scope.tableParams.reload();
  7343. };
  7344. // 选择查找日期
  7345. $scope.onDateCondition = function () {
  7346. $scope.tableParams.page(1);
  7347. $scope.tableParams.reload();
  7348. };
  7349. $scope.exportXls = function () {
  7350. SaleSend.exportXls({}, {}, function (data) {
  7351. if (data.success){
  7352. window.location.href = 'sale/notice/sends/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7353. }
  7354. }, function (response) {
  7355. toaster.pop('error', '数据加载失败', response.data);
  7356. });
  7357. }
  7358. }]);
  7359. /**
  7360. * 发货单(包括发货条码维护)
  7361. */
  7362. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService', 'ngTableParams', 'Lodop', '$modal', 'CurrentRole', function ($scope, $stateParams, SaleSend, toaster, ReportService, ngTableParams, Lodop, $modal, CurrentRole) {
  7363. // 获取当前用户是否为普通用户
  7364. CurrentRole.isUser({}, {}, function (data) {
  7365. $scope.isUser = data.isUser;
  7366. });
  7367. var loading = true;
  7368. $scope.checkBarCode = [];
  7369. $scope.checkBoxCode = [];
  7370. var vm = $scope.vm = {};
  7371. $scope.getCheckedItems = {};
  7372. vm.editBar = false;
  7373. vm.showBarCode = [];
  7374. $scope.barCode = function () {
  7375. vm.editBar = !vm.editBar;
  7376. }
  7377. $scope.checkboxes = {
  7378. checked: false
  7379. };
  7380. $scope.checkbars = {
  7381. checked: false
  7382. };
  7383. // 点击勾选barCode全部的复选框
  7384. $scope.checkBarAll = function () {
  7385. angular.forEach($scope.checkBarCode, function (item, key) {
  7386. $scope.checkBarCode[key] = $scope.checkbars.checked;
  7387. });
  7388. };
  7389. //点击barCode单选
  7390. $scope.checkBarOne = function () {
  7391. var result = true;
  7392. angular.forEach($scope.checkBarCode, function (item, key) {
  7393. if (item != true) {
  7394. result = false;
  7395. return;
  7396. }
  7397. });
  7398. $scope.checkbars.checked = result;
  7399. }
  7400. // 点击boxCode全部的复选框
  7401. $scope.checkBoxAll = function () {
  7402. angular.forEach($scope.checkBoxCode, function (item, key) {
  7403. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  7404. });
  7405. };
  7406. //点击boxCode单选
  7407. $scope.checkBoxOne = function () {
  7408. var result = true;
  7409. angular.forEach($scope.checkBoxCode, function (item) {
  7410. if (item != true) {
  7411. result = false;
  7412. return;
  7413. }
  7414. });
  7415. $scope.checkboxes.checked = result;
  7416. }
  7417. /**
  7418. * 生成条码和箱号
  7419. */
  7420. $scope.generateBarCode = function (item) {
  7421. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  7422. $scope.getCheckedItems = [];
  7423. var warningdata = '';
  7424. angular.forEach($scope.checkBarCode, function (item, key) {
  7425. $scope.getCheckedItem = {};
  7426. if (item == true) {
  7427. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7428. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  7429. $scope.getCheckedItems.push($scope.getCheckedItem);
  7430. //判断是否生成过条码
  7431. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7432. warningdata += $scope.order.sendItems[key].number + ","
  7433. }
  7434. }
  7435. });
  7436. if ($scope.getCheckedItems.length == 0) {
  7437. toaster.pop('warning', '提示', '请勾选需要生成条码的明细行!');
  7438. return;
  7439. }
  7440. if (warningdata != '') {
  7441. if (!confirm('明细行序号:' + warningdata + "已经生成了条码,继续生成将清空原有条码?")) {
  7442. return;
  7443. }
  7444. }
  7445. SaleSend.generateBarcodes({id: $scope.order.id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7446. toaster.pop('success', '提示', '生成成功!');
  7447. loadData();
  7448. }, function (response) {
  7449. $scope.loading = false;
  7450. toaster.pop('error', '生成失败', response.data);
  7451. });
  7452. }
  7453. /**
  7454. * 打印条码和箱号
  7455. */
  7456. $scope.printCode = function (type) {
  7457. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7458. //勾选需要打印的行
  7459. $scope.getCheckedItems = [];
  7460. var warningdata = ''
  7461. angular.forEach($scope.checkBarCode, function (item, key) {
  7462. $scope.getCheckedItem = {};
  7463. if (item == true) {
  7464. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7465. $scope.getCheckedItems.push($scope.getCheckedItem);
  7466. //判断是否生成过条码
  7467. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7468. warningdata += $scope.order.sendItems[key].number + ","
  7469. }
  7470. }
  7471. });
  7472. if ($scope.getCheckedItems.length == 0) {
  7473. toaster.pop('warning', '提示', '请勾选需要打印的明细行!');
  7474. return;
  7475. }
  7476. if (warningdata == '') {
  7477. toaster.pop('warning', '提示', '明细行序号:' + warningdata + '未生成条码无法打印');
  7478. return;
  7479. }
  7480. //选择打印模板
  7481. var modalInstance = $modal.open({
  7482. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7483. controller: 'BarPrintModalCtrl',
  7484. resolve: {
  7485. typeItem: function () {
  7486. return {'type': type, 'id': $scope.order.id};
  7487. }
  7488. }
  7489. });
  7490. modalInstance.result.then(function (s) {
  7491. if (s) {
  7492. //获取打印数据
  7493. SaleSend.getPrintBarcodes({lpsId: s.tp_id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7494. if (s.type == 'print') {//判断选择是打印还是打印预览
  7495. lodopPrint(data.message, LODOP, type);
  7496. } else if (s.type == 'printPreview') {
  7497. lodopPrintPreview(data.message, LODOP, type);
  7498. }
  7499. }, function (response) {
  7500. toaster.pop('error', '获取打印数据失败', response.data);
  7501. });
  7502. }
  7503. });
  7504. };
  7505. //打印单个条码
  7506. $scope.printSingleCode = function (id) {
  7507. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7508. //选择打印模板
  7509. var modalInstance = $modal.open({
  7510. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7511. controller: 'BarPrintModalCtrl',
  7512. resolve: {
  7513. typeItem: function () {
  7514. return {'type': 'Bar', 'id': $scope.order.id};
  7515. }
  7516. }
  7517. });
  7518. modalInstance.result.then(function (s) {
  7519. if (s) {
  7520. //获取打印数据
  7521. SaleSend.getSPrintBarcode({lpsId: s.tp_id, bsnId: id}, function (data) {
  7522. if (s.type == 'print') {//判断选择是打印还是打印预览
  7523. lodopSPrint(data.message, LODOP);
  7524. } else if (s.type == 'printPreview') {
  7525. lodopSPrintPreview(data.message, LODOP);
  7526. }
  7527. }, function (response) {
  7528. toaster.pop('error', '获取打印数据失败', response.data);
  7529. });
  7530. }
  7531. });
  7532. }
  7533. var lodopSPrint = function (printStore, LODOP) {//单个条码打印
  7534. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7535. if (selectOrNot != -1) {
  7536. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7537. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7538. var strs = pagesize.split("*"); //字符分割
  7539. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7540. angular.forEach(printStore, function (data, index) {
  7541. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7542. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7543. if (data['LP_VALUETYPE'] == 'barcode') {
  7544. 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']);
  7545. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7546. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7547. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7548. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7549. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7550. } else if (data['LP_VALUETYPE'] == 'text') {
  7551. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7552. }
  7553. });
  7554. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7555. LODOP.PRINT();
  7556. }
  7557. };
  7558. var lodopSPrintPreview = function (printStore, LODOP) {//单个条码打印预览
  7559. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7560. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7561. var strs = pagesize.split("*"); //字符分割
  7562. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7563. angular.forEach(printStore, function (data, index) {
  7564. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7565. if (data['LP_VALUETYPE'] == 'barcode') {
  7566. 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']);
  7567. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7568. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7569. } else if (data['LP_VALUETYPE'] == 'text') {
  7570. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7571. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7572. }
  7573. });
  7574. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7575. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7576. LODOP.PREVIEW();//打印预览
  7577. };
  7578. var lodopPrint = function (printStore, LODOP, type) {//勾选发货单明细进行打印
  7579. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7580. if (selectOrNot != -1) {
  7581. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7582. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  7583. var strs = new Array(); //定义一数组
  7584. strs = pagesize.split("*"); //字符分割
  7585. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7586. var ids = new Array();
  7587. angular.forEach(printStore, function (value, key) {
  7588. //LODOP.NewPage();
  7589. angular.forEach(value['data'], function (record, key) {
  7590. angular.forEach(record['store'], function (data, index) {
  7591. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7592. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7593. if (data['LP_VALUETYPE'] == 'barcode') {
  7594. 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']);
  7595. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7596. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7597. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7598. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7599. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7600. } else if (data['LP_VALUETYPE'] == 'text') {
  7601. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7602. }
  7603. });
  7604. });
  7605. var o = new Object();
  7606. o['id'] = record['si_id']
  7607. ids.push(o);
  7608. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7609. LODOP.PRINT();
  7610. });
  7611. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7612. if (type == 'Bar') {
  7613. //更新打印状态
  7614. SaleSend.updatePrintStatus({}, ids, function (data) {
  7615. }, function (res) {
  7616. });
  7617. }
  7618. }
  7619. };
  7620. var lodopPrintPreview = function (printData, LODOP, type) {//打印预览
  7621. var ids = new Array();
  7622. angular.forEach(printData, function (record, index) {
  7623. angular.forEach(record['data'], function (value, index) {
  7624. LODOP.NewPage();
  7625. angular.forEach(value['store'], function (data, index) {
  7626. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7627. if (data['LP_VALUETYPE'] == 'barcode') {
  7628. 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']);
  7629. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7630. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7631. } else if (data['LP_VALUETYPE'] == 'text') {
  7632. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7633. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7634. }
  7635. });
  7636. });
  7637. var o = new Object();
  7638. o['id'] = record['si_id']
  7639. ids.push(o);
  7640. });
  7641. var pagesize = printData[0]['pagesize'];//获取标签的大小
  7642. var strs = new Array(); //定义一数组
  7643. strs = pagesize.split("*"); //字符分割
  7644. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7645. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7646. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7647. var times = LODOP.PREVIEW();//打印预览
  7648. if (times > 0) {//点击了打印预览内的打印按钮
  7649. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7650. if (type == 'Bar') {
  7651. //更新打印状态
  7652. SaleSend.updatePrintStatus({}, ids, function (data) {
  7653. loadData();
  7654. }, function (res) {
  7655. });
  7656. }
  7657. }
  7658. };
  7659. /**
  7660. * 查看条码按钮
  7661. */
  7662. $scope.showBarCode = function (number) {
  7663. $scope.keys = number;
  7664. for (var i = 0; i < vm.showBarCode.length; i++) {
  7665. if (i != number) {
  7666. vm.showBarCode[i] = false;
  7667. }
  7668. }
  7669. vm.showBarCode[number] = !vm.showBarCode[number];
  7670. $scope.barcodes = [];
  7671. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  7672. var getPage = function (page, size) {
  7673. if ($scope.barcodes) {
  7674. var result = {};
  7675. result.totalCount = $scope.barcodes.length;
  7676. result.content = $scope.barcodes.slice((page - 1) * size, page * size);
  7677. if ($scope.barcodes.length % size == 0) {
  7678. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  7679. } else {
  7680. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  7681. }
  7682. result.first = page == 1;
  7683. result.last = page == result.totalPage;
  7684. result.page = page;
  7685. result.next = page - 0 + 1;
  7686. result.pre = page - 1;
  7687. return result;
  7688. }
  7689. }
  7690. $scope.barData = getPage(1, 5);
  7691. $scope.first = function () {
  7692. $scope.barData = getPage($scope.barData.pre, 5);
  7693. }
  7694. $scope.last = function () {
  7695. $scope.barData = getPage($scope.barData.next, 5);
  7696. }
  7697. };
  7698. /**
  7699. * 更新外箱号
  7700. */
  7701. $scope.updateOutBox = function (item, number) {
  7702. if ($scope.oldoutBoxQty[number] == item.outBoxQty) {
  7703. } else {
  7704. if (item.outBoxQty > 0) {
  7705. if (!(item.outBoxQty % item.packageQty)) {
  7706. SaleSend.update({id: item.id}, item, function () {
  7707. toaster.pop('success', '提示', '保存成功!');
  7708. loadData();
  7709. }, function (response) {
  7710. $scope.loading = false;
  7711. toaster.pop('error', '回复失败', response.data);
  7712. })
  7713. } else {
  7714. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  7715. }
  7716. } else {
  7717. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7718. }
  7719. }
  7720. loadData();
  7721. };
  7722. /**
  7723. * 更新最小包数
  7724. */
  7725. $scope.updatePackage = function (item, number) {
  7726. if (item.packageQty == $scope.oldpackageQty[number]) {
  7727. } else {
  7728. if (item.orderItem.product.minPack != 0) {
  7729. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7730. if (!(item.packageQty % item.orderItem.product.minPack)) {
  7731. SaleSend.update({id: item.id}, item, function () {
  7732. toaster.pop('success', '提示', '保存成功!');
  7733. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7734. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7735. }
  7736. loadData();
  7737. }, function (response) {
  7738. $scope.loading = false;
  7739. toaster.pop('error', '回复失败', response.data);
  7740. })
  7741. } else {
  7742. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  7743. }
  7744. } else {
  7745. toaster.pop('warning', '提示', '请填写有效的数量!');
  7746. }
  7747. } else {
  7748. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7749. SaleSend.update({id: item.id}, item, function () {
  7750. toaster.pop('success', '提示', '保存成功!');
  7751. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7752. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7753. }
  7754. loadData();
  7755. }, function (response) {
  7756. $scope.loading = false;
  7757. toaster.pop('error', '回复失败', response.data);
  7758. })
  7759. } else {
  7760. toaster.pop('warning', '提示', '请填写有效的数量!');
  7761. }
  7762. }
  7763. }
  7764. loadData();
  7765. };
  7766. var loadData = function () {
  7767. SaleSend.getItem({id: $stateParams.id}, function (data) {
  7768. $scope.order = data;
  7769. var orderCount = $scope.order.sendItems.length;
  7770. $scope.oldpackageQty = [];
  7771. $scope.oldoutBoxQty = [];
  7772. var sum = 0;
  7773. vm.oldpackageQty = [];
  7774. angular.forEach(data.sendItems, function (value, key) {
  7775. //给showBarCode数组赋初值
  7776. if (vm.showBarCode.length < orderCount) {
  7777. vm.showBarCode.push(false);
  7778. }
  7779. if ($scope.checkBarCode.length < orderCount) {
  7780. $scope.checkBarCode.push(false);
  7781. }
  7782. if ($scope.checkBoxCode.length < orderCount) {
  7783. $scope.checkBoxCode.push(false);
  7784. }
  7785. //给个初值
  7786. if (!value.packageQty) {
  7787. value.packageQty = value.orderItem.product.minPack;
  7788. }
  7789. $scope.oldpackageQty.push(value.packageQty);
  7790. if (value.outBoxQty) {
  7791. $scope.oldoutBoxQty.push(value.outBoxQty);
  7792. }
  7793. sum += value.price * value.qty;
  7794. });
  7795. data.total = sum;
  7796. $scope.loading = false;
  7797. }, function (response) {
  7798. loading = false;
  7799. toaster.pop('error', '获取数据失败', response.data);
  7800. });
  7801. };
  7802. loadData();
  7803. }]);
  7804. app.controller('BarPrintModalCtrl', ['$scope', 'typeItem', 'SaleSend', 'toaster', '$modalInstance', function ($scope, typeItem, SaleSend, toaster, $modalInstance) {
  7805. $scope.typeItem = typeItem;
  7806. $scope.template = [];
  7807. $scope.choose = {};
  7808. //获取打印模板
  7809. SaleSend.getPrintTemplate({id: $scope.typeItem.id, type: $scope.typeItem.type}, function (data) {
  7810. if (data.message) {
  7811. $scope.template = data.message;
  7812. $scope.choose.tp_id = $scope.template[0].id;
  7813. }
  7814. }, function (res) {
  7815. toaster.pop('error', '获取模板错误', res.data);
  7816. });
  7817. $scope.print = function () {
  7818. $scope.choose.type = 'print';
  7819. $modalInstance.close($scope.choose);
  7820. };
  7821. $scope.printPreview = function () {
  7822. $scope.choose.type = 'printPreview';
  7823. $modalInstance.close($scope.choose);
  7824. }
  7825. $scope.cancel = function () {
  7826. $modalInstance.close();
  7827. }
  7828. }]);
  7829. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', 'CurrentRole', function ($scope, $stateParams, PurcSample, toaster, $modal, BaseService, CurrentRole) {
  7830. BaseService.scrollBackToTop();
  7831. // 获取当前用户是否为普通用户
  7832. CurrentRole.isUser({}, {}, function (data) {
  7833. $scope.isUser = data.isUser;
  7834. });
  7835. var loading = true;
  7836. var loadData = function () {
  7837. PurcSample.getItem({id: $stateParams.id}, function (data) {
  7838. $scope.sample = data;
  7839. if (!$scope.sample.sends) {
  7840. $scope.sample.getSendInfo = '加载中...';
  7841. PurcSample.getSend({id: $stateParams.id}, function (sendData) {
  7842. if (sendData) {
  7843. $scope.sample.getSendInfo = null;
  7844. $scope.sample.sends = sendData;
  7845. } else {
  7846. $scope.sample.getSendInfo = '无送样信息';
  7847. $scope.sample.sends = '无送样信息';
  7848. }
  7849. }, function (response) {
  7850. $scope.sample.getSendInfo = '加载失败!';
  7851. toaster.pop('error', '', response.data);
  7852. });
  7853. }
  7854. $scope.loading = false;
  7855. }, function (response) {
  7856. loading = false;
  7857. toaster.pop('error', '获取数据失败', response.data);
  7858. });
  7859. };
  7860. loadData();
  7861. $scope.openSend = function (index, sample) {
  7862. var modalInstance = $modal.open({
  7863. animation: true,
  7864. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7865. controller: 'SampleSendCtrl',
  7866. resolve: {
  7867. sampleItem: function () {
  7868. return sample;
  7869. }
  7870. }
  7871. });
  7872. modalInstance.result.then(function () {
  7873. toaster.pop('info', '提示', '送样成功');
  7874. $scope.tableParams.reload();
  7875. }, function () {
  7876. });
  7877. };
  7878. }]);
  7879. /**
  7880. * 客户打样申请
  7881. */
  7882. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService', 'ReportService', 'Symbol', '$rootScope', 'PurcSampleInfo', 'CurrentRole', function ($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService, ReportService, Symbol, $rootScope, PurcSampleInfo, CurrentRole) {
  7883. BaseService.scrollBackToTop();
  7884. // 获取当前用户是否为普通用户
  7885. CurrentRole.isUser({}, {}, function (data) {
  7886. $scope.isUser = data.isUser;
  7887. });
  7888. if ($rootScope.active) {
  7889. $scope.active = $rootScope.active;
  7890. $rootScope.active = null;
  7891. } else {
  7892. $scope.active = 'todo';
  7893. }
  7894. $scope.agreedText = '全部';
  7895. $scope.dateZoneText = '一个月内';
  7896. $scope.condition = {dateZone: 1};
  7897. /*初始化筛选时间*/
  7898. var fromDate = new Date();
  7899. var toDate = new Date();
  7900. fromDate.setMonth(fromDate.getMonth() - 1);
  7901. fromDate.setHours(0, 0, 0, 0);
  7902. toDate.setHours(23, 59, 59, 999);
  7903. $scope.condition.dateFrom = fromDate;
  7904. $scope.condition.dateTo = toDate;
  7905. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7906. $scope.changeAgreed = function (agreed) {
  7907. $scope.condition.agreed = agreed;
  7908. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7909. $scope.condition.$agreedOpen = false;
  7910. };
  7911. $scope.changeDateZone = function (zone) {
  7912. $scope.condition.dateZone = zone;
  7913. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7914. $scope.condition.$dateZoneOpen = false;
  7915. getDateCondition(zone, $scope.condition);
  7916. $scope.tableParams.page(1);
  7917. $scope.tableParams.reload();
  7918. };
  7919. $scope.setActive = function (state) {
  7920. if ($scope.active != state) {
  7921. $scope.active = state;
  7922. if ($scope.tableParams.page() == 1)
  7923. $scope.tableParams.reload();
  7924. else
  7925. $scope.tableParams.page(1);
  7926. }
  7927. };
  7928. $scope.searchMethod = false;
  7929. var getService = function () {
  7930. return $scope.searchMethod ? PurcSample : PurcSampleInfo;
  7931. };
  7932. $scope.tableParams = new ngTableParams({
  7933. page: 1,
  7934. count: 20,
  7935. sorting: {
  7936. proofingDate: 'desc'
  7937. }
  7938. }, {
  7939. total: 0,
  7940. counts: [5, 10, 25, 50],
  7941. getData: function ($defer, params) {
  7942. $scope.loading = true;
  7943. var pageParams = params.url();
  7944. pageParams.searchFilter = {
  7945. keyword: $scope.keyword,
  7946. fromDate: getDateTime($scope.condition.dateFrom),
  7947. endDate: getDateTime($scope.condition.dateTo)
  7948. };
  7949. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7950. $scope.loading = false;
  7951. if (page) {
  7952. params.total(page.totalElement);
  7953. $defer.resolve(page.content);
  7954. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7955. }
  7956. getUnreadCount();
  7957. }, function (response) {
  7958. $scope.loading = false;
  7959. toaster.pop('error', '数据加载失败', response.data);
  7960. });
  7961. }
  7962. });
  7963. //获得各分类未阅读数量
  7964. var getUnreadCount = function () {
  7965. PurcSample.getUnreadCount(null, function(data){
  7966. $scope.unread = data;
  7967. });
  7968. };
  7969. getUnreadCount();
  7970. //设置单个单据已读
  7971. $scope.setOrdersRead = function (id) {
  7972. if (!$scope.isUnread(id)) {
  7973. return;
  7974. }
  7975. var sourceId = [];
  7976. sourceId.push(id);
  7977. PurcSample.setRead({}, sourceId, function (message) {
  7978. getUnreadIds();
  7979. getUnreadCount();
  7980. });
  7981. };
  7982. //获取未读单据id
  7983. var getUnreadIds = function (){
  7984. PurcSample.getUnreadIds({}, "", function (message) {
  7985. $scope.unreadCode = message.content;
  7986. });
  7987. };
  7988. getUnreadIds();
  7989. //判断单据是否未读
  7990. $scope.isUnread = function (id){
  7991. for (var i in $scope.unreadCode) {
  7992. if (id == $scope.unreadCode[i]) {
  7993. return true;
  7994. }
  7995. }
  7996. };
  7997. $scope.openDatePicker = function ($event, item, openParam) {
  7998. $event.preventDefault();
  7999. $event.stopPropagation();
  8000. item[openParam] = !item[openParam];
  8001. };
  8002. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8003. $event.preventDefault();
  8004. $event.stopPropagation();
  8005. item[openParam] = !item[openParam];
  8006. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8007. $scope.tableParams.reload();
  8008. }
  8009. };
  8010. $scope.openSend = function (index, sample) {
  8011. var modalInstance = $modal.open({
  8012. animation: true,
  8013. templateUrl: 'static/tpl/index/sale/sample_send.html',
  8014. controller: 'SampleSendCtrl',
  8015. resolve: {
  8016. sampleItem: function () {
  8017. return sample;
  8018. }
  8019. }
  8020. });
  8021. modalInstance.result.then(function () {
  8022. toaster.pop('info', '提示', '送样成功');
  8023. $scope.tableParams.reload();
  8024. }, function () {
  8025. });
  8026. };
  8027. //打印 样品采购单
  8028. $scope.print = function (sample) {
  8029. var newPage = window.open("about:blank");
  8030. PurcSample.printPermission({}, function () {
  8031. PurcSample.printCount({id: sample.id}, {});//增加打印此次
  8032. ReportService.print(sample.proofing.enUU, 'PURCPROOFING', "where purc$proofingitems.ppi_id =" + sample.id, newPage);
  8033. }, function (response) {
  8034. newPage.close();
  8035. toaster.pop('error', '打印失败', response.data);
  8036. });
  8037. };
  8038. $scope.getSend = function (proofing) {
  8039. if (!proofing.sends) {
  8040. proofing.getSendInfo = '加载中...';
  8041. PurcSample.getSend({id: proofing.id}, function (data) {
  8042. if (data) {
  8043. proofing.getSendInfo = null;
  8044. proofing.sends = data;
  8045. } else {
  8046. proofing.getSendInfo = '无送样信息';
  8047. proofing.sends = '无送样信息';
  8048. }
  8049. }, function (response) {
  8050. proofing.getSendInfo = '加载失败!';
  8051. });
  8052. }
  8053. };
  8054. // 搜索框回车
  8055. $scope.onSearch = function (keyword) {
  8056. // 每次搜索重置获取数据方法
  8057. $scope.searchMethod = false;
  8058. if(keyword != null && keyword != '') {
  8059. $scope.searchMethod = true;
  8060. }
  8061. $scope.tableParams.page(1);
  8062. $scope.tableParams.reload();
  8063. };
  8064. // 导出
  8065. $scope.exportXls = function () {
  8066. PurcSample.exportXls({}, {}, function (data) {
  8067. if (data.success){
  8068. window.location.href = 'sale/sample/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8069. }
  8070. }, function (response) {
  8071. toaster.pop('error', '数据加载失败', response.data);
  8072. });
  8073. }
  8074. }]);
  8075. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function ($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster) {
  8076. if (!sampleItem.sends) {
  8077. PurcSample.getSend({id: sampleItem.id}, function (data) {
  8078. if (data) {
  8079. sampleItem.sends = data; // 获取送样信息
  8080. angular.forEach(data, function (send) {
  8081. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  8082. });
  8083. }
  8084. }, function (response) {
  8085. });
  8086. }
  8087. $scope.sampleItem = sampleItem;
  8088. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  8089. //确认送样
  8090. $scope.ok = function (form) {
  8091. $scope.loading = true;
  8092. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  8093. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  8094. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  8095. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  8096. $upload.upload({
  8097. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  8098. method: 'POST',
  8099. file: file,
  8100. data: {
  8101. json: $scope.sampleItem.sampleSend
  8102. }
  8103. }).success(function (data) {
  8104. $scope.loading = false;
  8105. $modalInstance.close('success');
  8106. }).error(function (data) {
  8107. $scope.loading = false;
  8108. toaster.pop('error', '错误', data);
  8109. });
  8110. };
  8111. $scope.cancel = function () {
  8112. $modalInstance.dismiss(sampleItem);
  8113. };
  8114. //设置单个单据已读
  8115. $scope.setOrdersRead = function (id) {
  8116. var sourceId = [];
  8117. sourceId.push(id);
  8118. PurcSample.setRead({}, sourceId, function (message) {
  8119. // $scope.getUnreadIds();
  8120. });
  8121. };
  8122. }]);
  8123. /**
  8124. * 客户认定单
  8125. */
  8126. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol) {
  8127. BaseService.scrollBackToTop();
  8128. $scope.active = 'all';
  8129. $scope.agreedText = '全部';
  8130. $scope.dateZoneText = '一个月内';
  8131. $scope.condition = {dateZone: 1};
  8132. /* 时间筛选初始化*/
  8133. var fromDate = new Date();
  8134. var toDate = new Date();
  8135. fromDate.setMonth(fromDate.getMonth() - 1);
  8136. fromDate.setHours(0, 0, 0, 0);
  8137. toDate.setHours(23, 59, 59, 999);
  8138. $scope.condition.dateFrom = fromDate;
  8139. $scope.condition.dateTo = toDate;
  8140. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8141. $scope.changeDateZone = function (zone) {
  8142. $scope.condition.dateZone = zone;
  8143. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8144. $scope.condition.$dateZoneOpen = false;
  8145. getDateCondition(zone, $scope.condition);
  8146. $scope.tableParams.page(1);
  8147. $scope.tableParams.reload();
  8148. };
  8149. $scope.setActive = function (state) {
  8150. if ($scope.active != state) {
  8151. $scope.active = state;
  8152. if ($scope.tableParams.page() == 1)
  8153. $scope.tableParams.reload();
  8154. else
  8155. $scope.tableParams.page(1);
  8156. }
  8157. };
  8158. var getService = function () {
  8159. return PurcApproval;
  8160. };
  8161. $scope.tableParams = new ngTableParams({
  8162. page: 1,
  8163. count: 20,
  8164. sorting: {
  8165. inDate: 'desc'
  8166. }
  8167. }, {
  8168. total: 0,
  8169. counts: [5, 10, 25, 50],
  8170. getData: function ($defer, params) {
  8171. $scope.loading = true;
  8172. var pageParams = params.url();
  8173. pageParams.keyword = $scope.keyword;
  8174. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8175. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8176. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8177. $scope.loading = false;
  8178. if (page) {
  8179. params.total(page.totalElement);
  8180. $defer.resolve(page.content);
  8181. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8182. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8183. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  8184. }
  8185. }, function (response) {
  8186. $scope.loading = false;
  8187. toaster.pop('error', '数据加载失败', response.data);
  8188. });
  8189. }
  8190. });
  8191. $scope.openDatePicker = function ($event, item, openParam) {
  8192. $event.preventDefault();
  8193. $event.stopPropagation();
  8194. item[openParam] = !item[openParam];
  8195. };
  8196. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8197. $event.preventDefault();
  8198. $event.stopPropagation();
  8199. item[openParam] = !item[openParam];
  8200. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8201. $scope.tableParams.reload();
  8202. }
  8203. };
  8204. $scope.parseDate = function (dateStr) {
  8205. if (dateStr)
  8206. return Date.parse(dateStr, 'yyyy-MM-dd');
  8207. return new Date();
  8208. };
  8209. // 搜索框回车
  8210. $scope.onSearch = function () {
  8211. $scope.tableParams.page(1);
  8212. $scope.tableParams.reload();
  8213. };
  8214. // 选择查找日期
  8215. $scope.onDateCondition = function () {
  8216. $scope.tableParams.page(1);
  8217. $scope.tableParams.reload();
  8218. };
  8219. // 导出
  8220. $scope.exportXls = function () {
  8221. PurcApproval.exportXls({}, {}, function (data) {
  8222. if (data.success){
  8223. window.location.href = 'sale/sample/approval/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  8224. }
  8225. }, function (response) {
  8226. toaster.pop('error', '数据加载失败', response.data);
  8227. });
  8228. }
  8229. }]);
  8230. /**
  8231. * 客户采购预测
  8232. */
  8233. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol) {
  8234. BaseService.scrollBackToTop();
  8235. $scope.active = 'all';
  8236. $scope.agreedText = '全部';
  8237. $scope.dateZoneText = '一个月内';
  8238. $scope.condition = {dateZone: 1};
  8239. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8240. $scope.changeAgreed = function (agreed) {
  8241. $scope.condition.agreed = agreed;
  8242. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8243. $scope.condition.$agreedOpen = false;
  8244. };
  8245. $scope.changeDateZone = function (zone) {
  8246. $scope.condition.dateZone = zone;
  8247. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8248. $scope.condition.$dateZoneOpen = false;
  8249. };
  8250. $scope.setActive = function (state) {
  8251. if ($scope.active != state) {
  8252. $scope.active = state;
  8253. if ($scope.tableParams.page() == 1)
  8254. $scope.tableParams.reload();
  8255. else
  8256. $scope.tableParams.page(1);
  8257. }
  8258. };
  8259. var getService = function () {
  8260. return PurcForecast;
  8261. };
  8262. $scope.tableParams = new ngTableParams({
  8263. page: 1,
  8264. count: 20,
  8265. sorting: {
  8266. orderDate: 'desc'
  8267. }
  8268. }, {
  8269. total: 0,
  8270. counts: [5, 10, 25, 50],
  8271. getData: function ($defer, params) {
  8272. $scope.loading = true;
  8273. var pageParams = params.url();
  8274. pageParams.keyword = $scope.keyword;
  8275. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8276. $scope.loading = false;
  8277. if (page) {
  8278. params.total(page.totalElement);
  8279. $defer.resolve(page.content);
  8280. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8281. }
  8282. }, function (response) {
  8283. $scope.loading = false;
  8284. toaster.pop('error', '数据加载失败', response.data);
  8285. });
  8286. }
  8287. });
  8288. $scope.openDatePicker = function ($event, item, openParam) {
  8289. $event.preventDefault();
  8290. $event.stopPropagation();
  8291. item[openParam] = !item[openParam];
  8292. };
  8293. // 搜索框回车
  8294. $scope.onSearch = function () {
  8295. $scope.tableParams.page(1);
  8296. $scope.tableParams.reload();
  8297. };
  8298. }]);
  8299. /**
  8300. * 客户采购验收
  8301. */
  8302. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8303. BaseService.scrollBackToTop();
  8304. // 获取当前用户是否为普通用户
  8305. CurrentRole.isUser({}, {}, function (data) {
  8306. $scope.isUser = data.isUser;
  8307. });
  8308. $scope.active = 'all';
  8309. $scope.dateZoneText = '不限';
  8310. $scope.deliveryZoneText = '不限';
  8311. $scope.condition = {dateZone: 1, deliveryZone: -1};
  8312. /* 时间筛选初始化*/
  8313. var fromDate = new Date();
  8314. var toDate = new Date();
  8315. fromDate.setMonth(fromDate.getMonth() - 1);
  8316. fromDate.setHours(0, 0, 0, 0);
  8317. toDate.setHours(23, 59, 59, 999);
  8318. $scope.condition.dateFrom = fromDate;
  8319. $scope.condition.dateTo = toDate;
  8320. $scope.changeDateZone = function (zone) {
  8321. $scope.condition.dateZone = zone;
  8322. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8323. $scope.condition.$dateZoneOpen = false;
  8324. getDateCondition(zone, $scope.condition);
  8325. $scope.tableParams.page(1);
  8326. $scope.tableParams.reload();
  8327. };
  8328. $scope.changeDeliveryZone = function (zone) {
  8329. $scope.condition.deliveryZoneText = zone;
  8330. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  8331. $scope.condition.$delievryZoneOpen = false;
  8332. getDelveryCondition(zone, $scope.condition);
  8333. $scope.tableParams.reload();
  8334. };
  8335. $scope.setActive = function (state) {
  8336. if ($scope.active != state) {
  8337. $scope.active = state;
  8338. if ($scope.tableParams.page() == 1)
  8339. $scope.tableParams.reload();
  8340. else
  8341. $scope.tableParams.page(1);
  8342. }
  8343. };
  8344. var getService = function () {
  8345. return PurcAccept;
  8346. };
  8347. $scope.tableParams = new ngTableParams({
  8348. page: 1,
  8349. count: 20,
  8350. sorting: {
  8351. date: 'desc'
  8352. }
  8353. }, {
  8354. total: 0,
  8355. counts: [5, 10, 25, 50],
  8356. getData: function ($defer, params) {
  8357. $scope.loading = true;
  8358. var pageParams = params.url();
  8359. pageParams.searchFilter = { // 筛选条件
  8360. keyword: $scope.keyword,
  8361. fromDate: getDateTime($scope.condition.dateFrom),
  8362. endDate: getDateTime($scope.condition.dateTo)
  8363. };
  8364. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8365. $scope.loading = false;
  8366. if (page) {
  8367. params.total(page.totalElement);
  8368. $defer.resolve(page.content);
  8369. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8370. }
  8371. }, function (response) {
  8372. $scope.loading = false;
  8373. toaster.pop('error', '数据加载失败', response.data);
  8374. });
  8375. }
  8376. });
  8377. $scope.openDatePicker = function ($event, item, openParam) {
  8378. $event.preventDefault();
  8379. $event.stopPropagation();
  8380. item[openParam] = !item[openParam];
  8381. };
  8382. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8383. $event.preventDefault();
  8384. $event.stopPropagation();
  8385. item[openParam] = !item[openParam];
  8386. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8387. $scope.tableParams.reload();
  8388. }
  8389. };
  8390. $scope.parseDate = function (dateStr) {
  8391. if (dateStr)
  8392. return Date.parse(dateStr, 'yyyy-MM-dd');
  8393. return new Date();
  8394. };
  8395. // 选择查找日期
  8396. $scope.onDateCondition = function () {
  8397. $scope.tableParams.page(1);
  8398. $scope.tableParams.reload();
  8399. };
  8400. // 搜索框回车
  8401. $scope.onSearch = function () {
  8402. $scope.tableParams.page(1);
  8403. $scope.tableParams.reload();
  8404. };
  8405. // 导出
  8406. $scope.exportXls = function () {
  8407. PurcAccept.exportXls({}, {}, function (data) {
  8408. if (data.success){
  8409. window.location.href = 'sale/accept/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8410. }
  8411. }, function (response) {
  8412. toaster.pop('error', '数据加载失败', response.data);
  8413. });
  8414. }
  8415. }]);
  8416. /**
  8417. * 客户采购验收详情
  8418. */
  8419. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcAccept, toaster, BaseService, $stateParams, CurrentRole) {
  8420. BaseService.scrollBackToTop();
  8421. // 获取当前用户是否为普通用户
  8422. CurrentRole.isUser({}, {}, function (data) {
  8423. $scope.isUser = data.isUser;
  8424. });
  8425. if ($stateParams.id) {
  8426. PurcAccept.getDetail({id: $stateParams.id}, {}, function (data) {
  8427. $scope.accept = data;
  8428. if ($scope.accept.acceptItems != null) {
  8429. var sum = 0;
  8430. angular.forEach($scope.accept.acceptItems, function (item) {
  8431. if (item.orderPrice == null) {
  8432. item.orderPrice = 0;
  8433. }
  8434. sum += item.orderPrice * item.qty;
  8435. });
  8436. $scope.totalPrice = sum;
  8437. }
  8438. }, function (response) {
  8439. toaster.pop('error', '提示', response.data);
  8440. });
  8441. }
  8442. }]);
  8443. /**
  8444. * 客户采购验退
  8445. */
  8446. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8447. BaseService.scrollBackToTop();
  8448. // 获取当前用户是否为普通用户
  8449. CurrentRole.isUser({}, {}, function (data) {
  8450. $scope.isUser = data.isUser;
  8451. });
  8452. $scope.active = 'all';
  8453. $scope.agreedText = '全部';
  8454. $scope.dateZoneText = '一个月内';
  8455. $scope.condition = {dateZone: 1};
  8456. /* 时间筛选初始化*/
  8457. var fromDate = new Date();
  8458. var toDate = new Date();
  8459. fromDate.setMonth(fromDate.getMonth() - 1);
  8460. fromDate.setHours(0, 0, 0, 0);
  8461. toDate.setHours(23, 59, 59, 999);
  8462. $scope.condition.dateFrom = fromDate;
  8463. $scope.condition.dateTo = toDate;
  8464. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8465. $scope.changeAgreed = function (agreed) {
  8466. $scope.condition.agreed = agreed;
  8467. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8468. $scope.condition.$agreedOpen = false;
  8469. };
  8470. $scope.changeDateZone = function (zone) {
  8471. $scope.condition.dateZone = zone;
  8472. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8473. $scope.condition.$dateZoneOpen = false;
  8474. getDateCondition(zone, $scope.condition);
  8475. $scope.tableParams.page(1);
  8476. $scope.tableParams.reload();
  8477. };
  8478. $scope.setActive = function (state) {
  8479. if ($scope.active != state) {
  8480. $scope.active = state;
  8481. if ($scope.tableParams.page() == 1)
  8482. $scope.tableParams.reload();
  8483. else
  8484. $scope.tableParams.page(1);
  8485. }
  8486. };
  8487. var getService = function () {
  8488. return PurcReturn;
  8489. };
  8490. $scope.tableParams = new ngTableParams({
  8491. page: 1,
  8492. count: 20,
  8493. sorting: {
  8494. date: 'desc'
  8495. }
  8496. }, {
  8497. total: 0,
  8498. counts: [5, 10, 25, 50],
  8499. getData: function ($defer, params) {
  8500. $scope.loading = true;
  8501. var pageParams = params.url();
  8502. pageParams.searchFilter = {
  8503. keyword: $scope.keyword,
  8504. fromDate: getDateTime($scope.condition.dateFrom),
  8505. endDate: getDateTime($scope.condition.dateTo)
  8506. };
  8507. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8508. $scope.loading = false;
  8509. if (page) {
  8510. params.total(page.totalElement);
  8511. $defer.resolve(page.content);
  8512. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8513. angular.forEach(page.content, function (data) {
  8514. if (!data.returnItems[0].orderItem) {
  8515. PurcReturn.getEnterpriseName({id: data.id, enuu: data.enUU}, function (enterprise) {
  8516. data.enName = enterprise.enName;
  8517. });
  8518. }
  8519. });
  8520. }
  8521. }, function (response) {
  8522. $scope.loading = false;
  8523. toaster.pop('error', '数据加载失败', response.data);
  8524. });
  8525. }
  8526. });
  8527. $scope.openDatePicker = function ($event, item, openParam) {
  8528. $event.preventDefault();
  8529. $event.stopPropagation();
  8530. item[openParam] = !item[openParam];
  8531. };
  8532. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8533. $event.preventDefault();
  8534. $event.stopPropagation();
  8535. item[openParam] = !item[openParam];
  8536. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8537. $scope.tableParams.reload();
  8538. }
  8539. };
  8540. // 搜索框回车
  8541. $scope.onSearch = function () {
  8542. $scope.tableParams.page(1);
  8543. $scope.tableParams.reload();
  8544. };
  8545. // 导出
  8546. $scope.exportXls = function () {
  8547. PurcReturn.exportXls({}, {}, function (data) {
  8548. if (data.success){
  8549. window.location.href = 'sale/return/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8550. }
  8551. }, function (response) {
  8552. toaster.pop('error', '数据加载失败', response.data);
  8553. });
  8554. }
  8555. }]);
  8556. /**
  8557. * 客户采购验退详情
  8558. */
  8559. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcReturn, toaster, BaseService, $stateParams, CurrentRole) {
  8560. BaseService.scrollBackToTop();'' +
  8561. // 获取当前用户是否为普通用户
  8562. CurrentRole.isUser({}, {}, function (data) {
  8563. $scope.isUser = data.isUser;
  8564. });
  8565. if ($stateParams.id != null) {
  8566. PurcReturn.getDetail({id: $stateParams.id}, {}, function (data) {
  8567. $scope.returns = data;
  8568. if ($scope.returns.returnItems != null) {
  8569. var sum = 0;
  8570. angular.forEach($scope.returns.returnItems, function (item) {
  8571. if (null != item.orderPrice) {
  8572. sum += item.orderPrice * item.qty;
  8573. }
  8574. });
  8575. $scope.totalPrice = sum;
  8576. }
  8577. }, function (response) {
  8578. toaster.pop('error', '提示', response.data);
  8579. });
  8580. }
  8581. }]);
  8582. /**
  8583. * 客户不良品入库
  8584. */
  8585. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8586. BaseService.scrollBackToTop();
  8587. // 获取当前用户是否为普通用户
  8588. CurrentRole.isUser({}, {}, function (data) {
  8589. $scope.isUser = data.isUser;
  8590. });
  8591. $scope.active = 'all';
  8592. $scope.agreedText = '全部';
  8593. $scope.dateZoneText = '一个月内';
  8594. $scope.condition = {dateZone: 1};
  8595. /* 时间筛选初始化*/
  8596. var fromDate = new Date();
  8597. var toDate = new Date();
  8598. fromDate.setMonth(fromDate.getMonth() - 1);
  8599. fromDate.setHours(0, 0, 0, 0);
  8600. toDate.setHours(23, 59, 59, 999);
  8601. $scope.condition.dateFrom = fromDate;
  8602. $scope.condition.dateTo = toDate;
  8603. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8604. $scope.changeAgreed = function (agreed) {
  8605. $scope.condition.agreed = agreed;
  8606. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8607. $scope.condition.$agreedOpen = false;
  8608. };
  8609. $scope.changeDateZone = function (zone) {
  8610. $scope.condition.dateZone = zone;
  8611. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8612. $scope.condition.$dateZoneOpen = false;
  8613. getDateCondition(zone, $scope.condition);
  8614. $scope.tableParams.page(1);
  8615. $scope.tableParams.reload();
  8616. };
  8617. $scope.setActive = function (state) {
  8618. if ($scope.active != state) {
  8619. $scope.active = state;
  8620. if ($scope.tableParams.page() == 1)
  8621. $scope.tableParams.reload();
  8622. else
  8623. $scope.tableParams.page(1);
  8624. }
  8625. };
  8626. var getService = function () {
  8627. return PurcBadIn;
  8628. };
  8629. $scope.tableParams = new ngTableParams({
  8630. page: 1,
  8631. count: 20,
  8632. sorting: {
  8633. date: 'desc'
  8634. }
  8635. }, {
  8636. total: 0,
  8637. counts: [5, 10, 25, 50],
  8638. getData: function ($defer, params) {
  8639. $scope.loading = true;
  8640. var pageParams = params.url();
  8641. pageParams.searchFilter = {
  8642. keyword: $scope.keyword,
  8643. fromDate: getDateTime($scope.condition.dateFrom),
  8644. endDate: getDateTime($scope.condition.dateTo)
  8645. };
  8646. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8647. $scope.loading = false;
  8648. if (page) {
  8649. params.total(page.totalElement);
  8650. $defer.resolve(page.content);
  8651. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8652. }
  8653. }, function (response) {
  8654. $scope.loading = false;
  8655. toaster.pop('error', '数据加载失败', response.data);
  8656. });
  8657. }
  8658. });
  8659. $scope.openDatePicker = function ($event, item, openParam) {
  8660. $event.preventDefault();
  8661. $event.stopPropagation();
  8662. item[openParam] = !item[openParam];
  8663. };
  8664. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8665. $event.preventDefault();
  8666. $event.stopPropagation();
  8667. item[openParam] = !item[openParam];
  8668. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8669. $scope.tableParams.reload();
  8670. }
  8671. };
  8672. // 搜索框回车
  8673. $scope.onSearch = function (keyword) {
  8674. $scope.keyword = keyword;
  8675. $scope.tableParams.page(1);
  8676. $scope.tableParams.reload();
  8677. };
  8678. // 导出
  8679. $scope.exportXls = function () {
  8680. PurcBadIn.exportXls({}, {}, function (data) {
  8681. if (data.success){
  8682. window.location.href = 'sale/badIn/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8683. }
  8684. }, function (response) {
  8685. toaster.pop('error', '数据加载失败', response.data);
  8686. });
  8687. }
  8688. }]);
  8689. /**
  8690. * 客户不良品出库
  8691. */
  8692. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8693. BaseService.scrollBackToTop();
  8694. // 获取当前用户是否为普通用户
  8695. CurrentRole.isUser({}, {}, function (data) {
  8696. $scope.isUser = data.isUser;
  8697. });
  8698. $scope.active = 'all';
  8699. $scope.agreedText = '全部';
  8700. $scope.dateZoneText = '一个月内';
  8701. $scope.condition = {dateZone: 1};
  8702. /* 时间筛选初始化*/
  8703. var fromDate = new Date();
  8704. var toDate = new Date();
  8705. fromDate.setMonth(fromDate.getMonth() - 1);
  8706. fromDate.setHours(0, 0, 0, 0);
  8707. toDate.setHours(23, 59, 59, 999);
  8708. $scope.condition.dateFrom = fromDate;
  8709. $scope.condition.dateTo = toDate;
  8710. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8711. $scope.changeAgreed = function (agreed) {
  8712. $scope.condition.agreed = agreed;
  8713. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8714. $scope.condition.$agreedOpen = false;
  8715. };
  8716. $scope.changeDateZone = function (zone) {
  8717. $scope.condition.dateZone = zone;
  8718. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8719. $scope.condition.$dateZoneOpen = false;
  8720. getDateCondition(zone, $scope.condition);
  8721. $scope.tableParams.page(1);
  8722. $scope.tableParams.reload();
  8723. };
  8724. $scope.setActive = function (state) {
  8725. if ($scope.active != state) {
  8726. $scope.active = state;
  8727. if ($scope.tableParams.page() == 1)
  8728. $scope.tableParams.reload();
  8729. else
  8730. $scope.tableParams.page(1);
  8731. }
  8732. };
  8733. var getService = function () {
  8734. return PurcBadOut;
  8735. };
  8736. $scope.tableParams = new ngTableParams({
  8737. page: 1,
  8738. count: 20,
  8739. sorting: {
  8740. date: 'desc'
  8741. }
  8742. }, {
  8743. total: 0,
  8744. counts: [5, 10, 25, 50],
  8745. getData: function ($defer, params) {
  8746. $scope.loading = true;
  8747. var pageParams = params.url();
  8748. pageParams.searchFilter = {
  8749. keyword: $scope.keyword,
  8750. fromDate: getDateTime($scope.condition.dateFrom),
  8751. endDate: getDateTime($scope.condition.dateTo)
  8752. };
  8753. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8754. $scope.loading = false;
  8755. if (page) {
  8756. params.total(page.totalElement);
  8757. $defer.resolve(page.content);
  8758. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8759. }
  8760. }, function (response) {
  8761. $scope.loading = false;
  8762. toaster.pop('error', '数据加载失败', response.data);
  8763. });
  8764. }
  8765. });
  8766. $scope.openDatePicker = function ($event, item, openParam) {
  8767. $event.preventDefault();
  8768. $event.stopPropagation();
  8769. item[openParam] = !item[openParam];
  8770. };
  8771. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8772. $event.preventDefault();
  8773. $event.stopPropagation();
  8774. item[openParam] = !item[openParam];
  8775. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8776. $scope.tableParams.reload();
  8777. }
  8778. };
  8779. // 搜索框回车
  8780. $scope.onSearch = function () {
  8781. $scope.tableParams.page(1);
  8782. $scope.tableParams.reload();
  8783. };
  8784. // 导出
  8785. $scope.exportXls = function () {
  8786. PurcBadOut.exportXls({}, {}, function (data) {
  8787. if (data.success){
  8788. window.location.href = 'sale/badOut/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8789. }
  8790. }, function (response) {
  8791. toaster.pop('error', '数据加载失败', response.data);
  8792. });
  8793. }
  8794. }]);
  8795. /**
  8796. * 客户MRB
  8797. */
  8798. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol) {
  8799. BaseService.scrollBackToTop();
  8800. $scope.active = 'all';
  8801. $scope.agreedText = '全部';
  8802. $scope.dateZoneText = '一个月内';
  8803. $scope.condition = {dateZone: 1};
  8804. /* 时间筛选初始化*/
  8805. var fromDate = new Date();
  8806. var toDate = new Date();
  8807. fromDate.setMonth(fromDate.getMonth() - 1);
  8808. fromDate.setHours(0, 0, 0, 0);
  8809. toDate.setHours(23, 59, 59, 999);
  8810. $scope.condition.dateFrom = fromDate;
  8811. $scope.condition.dateTo = toDate;
  8812. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8813. $scope.changeAgreed = function (agreed) {
  8814. $scope.condition.agreed = agreed;
  8815. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8816. $scope.condition.$agreedOpen = false;
  8817. };
  8818. $scope.changeDateZone = function (zone) {
  8819. $scope.condition.dateZone = zone;
  8820. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8821. $scope.condition.$dateZoneOpen = false;
  8822. getDateCondition(zone, $scope.condition);
  8823. $scope.tableParams.page(1);
  8824. $scope.tableParams.reload();
  8825. };
  8826. $scope.setActive = function (state) {
  8827. if ($scope.active != state) {
  8828. $scope.active = state;
  8829. if ($scope.tableParams.page() == 1)
  8830. $scope.tableParams.reload();
  8831. else
  8832. $scope.tableParams.page(1);
  8833. }
  8834. };
  8835. var getService = function () {
  8836. return PurcMRB;
  8837. };
  8838. $scope.tableParams = new ngTableParams({
  8839. page: 1,
  8840. count: 20,
  8841. sorting: {
  8842. date: 'desc'
  8843. }
  8844. }, {
  8845. total: 0,
  8846. counts: [5, 10, 25, 50],
  8847. getData: function ($defer, params) {
  8848. $scope.loading = true;
  8849. var pageParams = params.url();
  8850. pageParams.searchFilter = {
  8851. keyword: $scope.keyword,
  8852. fromDate: getDateTime($scope.condition.dateFrom),
  8853. endDate: getDateTime($scope.condition.dateTo)
  8854. };
  8855. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8856. $scope.loading = false;
  8857. if (page) {
  8858. params.total(page.totalElement);
  8859. $defer.resolve(page.content);
  8860. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8861. }
  8862. }, function (response) {
  8863. $scope.loading = false;
  8864. toaster.pop('error', '数据加载失败', response.data);
  8865. });
  8866. }
  8867. });
  8868. $scope.openDatePicker = function ($event, item, openParam) {
  8869. $event.preventDefault();
  8870. $event.stopPropagation();
  8871. item[openParam] = !item[openParam];
  8872. };
  8873. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8874. $event.preventDefault();
  8875. $event.stopPropagation();
  8876. item[openParam] = !item[openParam];
  8877. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8878. $scope.tableParams.reload();
  8879. }
  8880. };
  8881. // 搜索框回车
  8882. $scope.onSearch = function () {
  8883. $scope.tableParams.page(1);
  8884. $scope.tableParams.reload();
  8885. };
  8886. // 导出
  8887. $scope.exportXls = function () {
  8888. PurcMRB.exportXls({}, {}, function (data) {
  8889. if (data.success){
  8890. window.location.href = 'sale/MRB/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8891. }
  8892. }, function (response) {
  8893. toaster.pop('error', '数据加载失败', response.data);
  8894. });
  8895. }
  8896. }]);
  8897. //客户航天开票
  8898. app.controller('PurchaseApBillOutCtrl',['$scope', 'FaApBillOut', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function ($scope, FaApBillOut, BaseService, ngTableParams, toaster, ReportService , Symbol) {
  8899. BaseService.scrollBackToTop();
  8900. $scope.dateZoneText = '不限';
  8901. $scope.condition = {dateZone: 1};
  8902. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8903. $scope.active = 'all';
  8904. /* 时间筛选初始化*/
  8905. var fromDate = new Date();
  8906. var toDate = new Date();
  8907. fromDate.setMonth(fromDate.getMonth() - 1);
  8908. fromDate.setHours(0,0,0,0);
  8909. toDate.setHours(23,59,59,999);
  8910. $scope.condition.dateFrom = fromDate;
  8911. $scope.condition.dateTo = toDate;
  8912. //打印 开票单
  8913. $scope.print = function (billOut) {
  8914. FaApBillOut.printCount({id: billOut.id},function (data) {
  8915. if(!data.error) {
  8916. toaster.pop('success', '提示', '打印成功');
  8917. //$scope.tableParams.reload();
  8918. }else{
  8919. toaster.pop('error', '提示', '打印失败');
  8920. }
  8921. });
  8922. //ReportService.print(billOut.custUu, 'PURCBILLOUT', 'where purc$apbillout.pabo_id =' + billOut.id);
  8923. };
  8924. //状态
  8925. $scope.setActive = function (state) {
  8926. if($scope.active != state) {
  8927. $scope.active = state;
  8928. if($scope.tableParams.page() == 1)
  8929. $scope.tableParams.reload();
  8930. else
  8931. $scope.tableParams.page(1);
  8932. }
  8933. };
  8934. $scope.changeDateZone = function (zone) {
  8935. $scope.condition.dateZone = zone;
  8936. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8937. $scope.condition.$dateZoneOpen = false;
  8938. getDateCondition(zone, $scope.condition);
  8939. $scope.tableParams.page(1);
  8940. $scope.tableParams.reload();
  8941. };
  8942. //获取全部已确定应收对账单
  8943. $scope.tableParams = new ngTableParams({
  8944. page: 1,
  8945. count: 20,
  8946. sorting: {
  8947. recordDate: 'desc'
  8948. }
  8949. }, {
  8950. total: 0,
  8951. counts: [5, 10, 25, 50],
  8952. getData: function ($defer, params) {
  8953. $scope.loading = true;
  8954. var pageParams = params.url();
  8955. pageParams.searchFilter = { // 筛选条件
  8956. keyword: $scope.keyword,
  8957. fromDate: getDateTime($scope.condition.dateFrom),
  8958. endDate: getDateTime($scope.condition.dateTo)
  8959. };
  8960. FaApBillOut[getState($scope.active )](BaseService.parseParams(pageParams), function (page) {
  8961. $scope.loading = false;
  8962. if(page) {
  8963. params.total(page.totalElement);
  8964. $scope.data = $defer.resolve(page.content);
  8965. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  8966. }
  8967. }, function (response) {
  8968. $scope.loading = false;
  8969. toaster.pop('error', '数据加载失败', response.data);
  8970. });
  8971. }
  8972. });
  8973. $scope.openDatePicker = function ($event, item, openParam) {
  8974. $event.preventDefault();
  8975. $event.stopPropagation();
  8976. item[openParam] = !item[openParam];
  8977. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  8978. $scope.tableParams.reload();
  8979. }
  8980. };
  8981. // 计算开票数量
  8982. $scope.getTotalProd = function (billOut) {
  8983. var total = 0;
  8984. if(billOut.items) {
  8985. angular.forEach(billOut.items, function (value) {
  8986. total += value.NowQty;
  8987. });
  8988. }
  8989. return total;
  8990. };
  8991. // 搜索框回车
  8992. $scope.onSearch = function () {
  8993. $scope.tableParams.page(1);
  8994. $scope.tableParams.reload();
  8995. };
  8996. // 选择查找日期
  8997. $scope.onDateCondition = function () {
  8998. $scope.tableParams.page(1);
  8999. $scope.tableParams.reload();
  9000. };
  9001. }]);
  9002. //开票单详情
  9003. app.controller('PurchaseApBillOutDetailCtrl',['$scope', 'toaster', 'FaApBillOut', 'FaApCheck', '$stateParams', 'BaseService', function ($scope, toaster, FaApBillOut, FaApCheck, $stateParams, BaseService) {
  9004. BaseService.scrollBackToTop();
  9005. $scope.haveSelected = true;
  9006. $scope.data = {};
  9007. //控制提交和删除按钮的显示
  9008. $scope.ifShow = true;
  9009. var loadData = function () {
  9010. FaApBillOut.get({id:$stateParams.id},function (data) {
  9011. $scope.data = data;
  9012. if($scope.data.status){
  9013. }else{
  9014. $scope.ifShow = true;
  9015. }
  9016. })
  9017. };
  9018. if($stateParams.id){
  9019. loadData();
  9020. }
  9021. $scope.haveSource = false;
  9022. //TODO 提交开票单
  9023. $scope.invoiceIssued = function (apBillOut) {
  9024. $scope.loading = true;
  9025. FaApBillOut.invoiceIssued({id:apBillOut.id},function (data) {
  9026. $scope.loading = false;
  9027. if(data.apBillOut) {
  9028. $scope.haveSelected = false;
  9029. window.location.href = '#/fa/apBillOut';
  9030. toaster.pop('success', '提示', '提交成功');
  9031. } else {
  9032. $scope.loading = false;
  9033. toaster.pop('error', '提示', data.error);
  9034. }
  9035. })
  9036. }
  9037. //删除开票单(后台同时更新对账单明细表已开票数)
  9038. $scope.deleteApBillOut = function () {
  9039. FaApBillOut.deleteApBillOut({id:$stateParams.id},function (data) {
  9040. window.location.href = '#/fa/apBillOut';
  9041. toaster.pop('success','提示','删除成功');
  9042. },function () {
  9043. toaster.pop('error','提示','删除失败');
  9044. });
  9045. $scope.haveSelected = false;
  9046. }
  9047. //TODO 作废开票单
  9048. $scope.InvoiceCancel = function () {
  9049. $scope.loading = true;
  9050. FaApBillOut.InvoiceCancel({id:$stateParams.id},function (data) {
  9051. $scope.loading = false;
  9052. if(!data.error) {
  9053. toaster.pop('success', '提示', '作废成功');
  9054. window.location.href = '#/fa/apBillOut';
  9055. $scope.tableParams.reload();
  9056. }else{
  9057. toaster.pop('error', '提示', data.error);
  9058. }
  9059. },function (response) {
  9060. $scope.loading = false;
  9061. toaster.pop('error', '提示', response.data);
  9062. });
  9063. }
  9064. }]);
  9065. //航天开票单据列表
  9066. app.controller('PurchaseApBillOutListCtrl',['$scope', 'FaApCheck', 'FaApBillOut', 'toaster', '$state','$filter', '$modal', function ($scope, FaApCheck, FaApBillOut, toaster, $state, $filter, $modal) {
  9067. $scope.data = [];// 列表数据
  9068. $scope.condition = {
  9069. $fromOpened: false
  9070. }
  9071. $scope.openDatePicker = function ($event, item, openParam) {
  9072. $event.preventDefault();
  9073. $event.stopPropagation();
  9074. item[openParam] = !item[openParam];
  9075. }
  9076. //查找客户
  9077. $scope.searchCust = function (suuorname) {
  9078. var modalInstance = $modal.open({
  9079. animation: true,
  9080. templateUrl: 'static/tpl/index/fa/custInfo.html',
  9081. controller: 'SearchCustInfoCtrl',
  9082. resolve: {
  9083. suuorname: function () {
  9084. return suuorname;
  9085. }
  9086. }
  9087. });
  9088. modalInstance.result.then(function (suuorname) {
  9089. $scope.suuorname = suuorname;
  9090. });
  9091. }
  9092. // 点击筛选根据条件选择数据
  9093. $scope.suuorname = '';
  9094. // 默认本月
  9095. $scope.sdateTo = new Date();
  9096. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  9097. $scope.vuuorname = '';
  9098. $scope.factory = '';
  9099. $scope.prodTitle = '';
  9100. $scope.prodSpec = '';
  9101. $scope.condition.uuorname = '';
  9102. $scope.condition.dateFrom = '';
  9103. $scope.condition.dateTo = '';
  9104. $scope.condition.venduuorname = '';
  9105. $scope.condition.factory = '';
  9106. $scope.condition.prodTitle = '';
  9107. $scope.condition.prodSpec = '';
  9108. $scope.searchOrder = function (check) {
  9109. $scope.data = [];
  9110. $scope.checkboxes.checked = false;
  9111. $scope.totalMoney = 0;
  9112. $scope.condition.uuorname = $scope.suuorname;
  9113. $scope.condition.factory = $scope.factory;
  9114. $scope.condition.prodTitle = $scope.prodTitle;
  9115. $scope.condition.prodSpec = $scope.prodSpec;
  9116. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9117. $scope.thisdatato = ($scope.sdateTo || 0);
  9118. if($scope.thisdatato != 0) {
  9119. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9120. } else {
  9121. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9122. }
  9123. $scope.condition.venduuorname = $scope.vuuorname;
  9124. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9125. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9126. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9127. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  9128. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  9129. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  9130. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  9131. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  9132. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9133. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9134. if(!$scope.suuorname) {
  9135. toaster.pop('warning','提示', '请先选择客户');
  9136. document.getElementById('suuorname').focus();//光标默认在客户
  9137. } else {
  9138. $scope.loading = true;
  9139. FaApBillOut.getDoneApCheckByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  9140. if(data.length > 0) {
  9141. angular.forEach(data, function (checkItem) {
  9142. checkItem.$selected = true;
  9143. if(checkItem.billed) {
  9144. checkItem.thisBilledQty = checkItem.checkQty - checkItem.billed;
  9145. //$filter('number')(checkItem.thisBilledQty, 2);
  9146. } else {
  9147. checkItem.billed = 0;
  9148. checkItem.thisBilledQty = checkItem.checkQty;
  9149. }
  9150. //最大最小开票数
  9151. checkItem.maxThisBilledQty = checkItem.thisBilledQty;
  9152. checkItem.minThisBilledQty = 0;
  9153. });
  9154. $scope.data = data;
  9155. $scope.checkboxes.checked = true;
  9156. $scope.getTotalMoney();
  9157. } else {
  9158. toaster.pop('info', '提示', '当前没有需要对账记录');
  9159. }
  9160. $scope.loading = false;
  9161. }, function (response) {
  9162. $scope.loading = false;
  9163. toaster.pop('error', '提示', response.data);
  9164. });
  9165. }
  9166. }
  9167. }
  9168. /**
  9169. * 点击勾选框,选中要转应收对账单的订单
  9170. * */
  9171. $scope.totalMoney = 0;
  9172. $scope.checkboxes = {
  9173. checked: false
  9174. };
  9175. // 点击勾选全部的复选框
  9176. $scope.checkAll = function () {
  9177. $scope.totalMoney = 0;
  9178. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  9179. var uuorname = $scope.suuorname;
  9180. var venduuorname = $scope.venduuorname;
  9181. var dateFrom = $scope.condition.dateFrom;
  9182. var dateTo = $scope.condition.dateTo;
  9183. var prodTitle = $scope.condition.prodTitle;
  9184. var prodSpec = $scope.condition.prodSpec;
  9185. var factory = $scope.condition.factory;
  9186. angular.forEach($scope.filteredData, function (item) {
  9187. if((item.apCheck.apDate >= dateFrom || dateFrom == '') && (item.apCheck.apDate < dateTo || dateTo == '')){
  9188. item.$selected = $scope.checkboxes.checked;
  9189. }
  9190. });
  9191. $scope.getTotalMoney();
  9192. };
  9193. //获取已选单据总金额
  9194. var total = true;
  9195. $scope.getTotalMoney = function () {
  9196. $scope.totalMoney = 0;
  9197. angular.forEach($scope.data, function (check) {
  9198. if(check.$selected){
  9199. $scope.totalMoney += (check.CheckQty || 0)*(check.orderPrice || 0);
  9200. }else{
  9201. $scope.totalMoney += 0;
  9202. }
  9203. });
  9204. }
  9205. // 点击其中一个明细的复选框
  9206. $scope.checkOne = function (check) {
  9207. var result = true;
  9208. angular.forEach($scope.data, function (item) {
  9209. if(item.$selected != true){
  9210. result = false;
  9211. return;
  9212. }
  9213. });
  9214. $scope.checkboxes.checked = result;
  9215. };
  9216. $scope.haveSelected = false;
  9217. //生成开票单
  9218. $scope.createApBillOut = function () {
  9219. //保存应收对账单主记录字段
  9220. $scope.apBillOut = {
  9221. custUu: '',
  9222. custName: '',
  9223. beginDate: '',
  9224. endDate: '',
  9225. enUu: '',
  9226. recordDate: '',
  9227. checkStatus: '未开票',
  9228. currency: '',
  9229. rate: '',
  9230. //billed:'',
  9231. //apBillOutItemId:'',
  9232. items: [],
  9233. sourceInfos: []
  9234. };
  9235. //保存来源单据相关信息
  9236. //var sourceInfos = [];
  9237. //所允许的本次对账最大最小数量
  9238. //$scope.data.maxThisCheckQty = 0;
  9239. //$scope.data.minThisCheckQty = 0;
  9240. $scope.sameCust = true;
  9241. $scope.validQty = true;
  9242. $scope.loading = true;
  9243. angular.forEach($scope.data, function (checkItem) {
  9244. //保存开票单明细行数据
  9245. $scope.item = {
  9246. inoutno: '',
  9247. inoutnodetno: '',
  9248. orderCode: '',
  9249. orderClass: '',
  9250. orderDetno: '',
  9251. price: '',
  9252. NowQty: '',
  9253. //amount: '',
  9254. sourceId:'',
  9255. sourceTable:'',
  9256. //oldYCheckQty:'',
  9257. status: 0,
  9258. //receiveCode:'',
  9259. //receiveName:'',
  9260. prodCode:'',
  9261. //prodSpec:'',
  9262. taxrate: '',
  9263. //sendcode: '',
  9264. //whname: '',
  9265. };
  9266. //开票单明细行来源表信息(新的已开票数)
  9267. $scope.sourceInfo = {
  9268. sourceId: '',
  9269. sourceTable: '',
  9270. newBilledQty: 0
  9271. };
  9272. //本次开票新的开票数
  9273. //$scope.thisBilledQty = 0;
  9274. if(checkItem.$selected == true) {
  9275. $scope.apBillOut.custName = checkItem.apCheck.custName;
  9276. $scope.apBillOut.enUu = checkItem.apCheck.enUu;
  9277. $scope.item.inoutno = checkItem.inoutno;
  9278. $scope.item.inoutnodetno = checkItem.inoutnodetno;
  9279. $scope.item.orderCode = checkItem.orderCode;
  9280. $scope.item.orderClass = checkItem.orderClass;
  9281. $scope.item.orderDetno = checkItem.orderDetno;
  9282. $scope.item.NowQty = checkItem.thisBilledQty;
  9283. if (typeof(checkItem.billed) == "undefined") {
  9284. checkItem.billed = 0;
  9285. $scope.sourceInfo.newBilledQty =checkItem.thisBilledQty;
  9286. } else {
  9287. //TODO 变成了字符串相加?
  9288. $scope.sourceInfo.newBilledQty = checkItem.thisBilledQty + checkItem.billed;
  9289. }
  9290. //$scope.apBillOut.apBillOutItemId = check.id;
  9291. $scope.apBillOut.recordDate = checkItem.recordDate;
  9292. $scope.apBillOut.rate = checkItem.apCheck.rate;
  9293. //必须是同一家客户才能生成对账单,否则提示错误
  9294. if($scope.apBillOut.custUu == ''){
  9295. $scope.apBillOut.custUu = checkItem.apCheck.custUu;
  9296. }else if($scope.apBillOut.custUu !== checkItem.apCheck.custUu){
  9297. $scope.sameCust = false;
  9298. $scope.loading = false;
  9299. toaster.pop('error', '请选择同一家客户');
  9300. }
  9301. //必须是相同币别才能生成对账单,否则提示错误
  9302. if ($scope.apBillOut.currency == '') {
  9303. $scope.apBillOut.currency = checkItem.apCheck.currency;
  9304. } else if ($scope.apBillOut.currency !== checkItem.apCheck.currency) {
  9305. $scope.sameCust = false;
  9306. $scope.loading = false;
  9307. toaster.pop('error', '请选择同一种币别');
  9308. }
  9309. //本次对账数量必须小于总对账数量
  9310. if (checkItem.checkQty > 0) {
  9311. if (checkItem.minThisBilledQty >checkItem.thisBilledQty || checkItem.maxThisBilledQty <checkItem.thisBilledQty) {
  9312. $scope.validQty = false;
  9313. $scope.loading = false;
  9314. toaster.pop('error','本次开票数量,填写有误!');
  9315. }
  9316. } else if (check.qty < 0) {
  9317. $scope.data.maxCheckQty = 0;
  9318. $scope.data.minCheckQty = check.qty;
  9319. if(((-check.qty)-(-check.yCheckQty) < (-check.CheckQty)) || check.CheckQty > 0 || check.CheckQty == 0){
  9320. $scope.validQty = false;
  9321. $scope.loading = false;
  9322. toaster.pop('error','本次开票数量,填写有误!');
  9323. }
  9324. }
  9325. //TODO
  9326. //获取最小时间作为对账区间的起始时间
  9327. if($scope.apBillOut.beginDate == ''){
  9328. $scope.apBillOut.beginDate = checkItem.apCheck.apDate;
  9329. }else{
  9330. $scope.apBillOut.beginDate = $scope.apBillOut.beginDate>checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.beginDate;
  9331. }
  9332. //获取最大时间作为对账区间的截止时间
  9333. if($scope.apBillOut.endDate == ''){
  9334. $scope.apBillOut.endDate = checkItem.apCheck.apDate;
  9335. }else{
  9336. $scope.apBillOut.endDate = $scope.apBillOut.endDate<checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.endDate;
  9337. }
  9338. //应收开票单明细行数据
  9339. $scope.item.price = checkItem.price;
  9340. $scope.item.sourceId = checkItem.id;
  9341. $scope.item.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  9342. $scope.item.NowQty = checkItem.thisBilledQty;
  9343. $scope.item.prodCode = checkItem.prodCode;
  9344. $scope.item.taxrate = checkItem.taxrate;
  9345. //来源表相关信息
  9346. $scope.sourceInfo.sourceId = checkItem.id;
  9347. $scope.sourceInfo.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  9348. $scope.sourceInfo.newBilledQty = ((checkItem.billed || 0) + checkItem.thisBilledQty);
  9349. //sourceInfos.push($scope.sourceInfo);
  9350. $scope.apBillOut.items.push($scope.item);
  9351. $scope.apBillOut.sourceInfos.push($scope.sourceInfo);
  9352. $scope.haveSelected = true;
  9353. }
  9354. });
  9355. //保存生成的开票单,后台同时更新对账单明细表中已开票数
  9356. $scope.saveApBillOut = function () {
  9357. FaApBillOut.saveApBillOut({}, $scope.apBillOut, function (data) {
  9358. $scope.loading = false;
  9359. toaster.pop('success', '成功', '生成开票单成功');
  9360. $state.go('fa.apBillOut_detail', {id: data.id}, {reload:true});
  9361. }, function (response) {
  9362. toaster.pop('error', '生成开票单失败', response.data);
  9363. });
  9364. };
  9365. //如果是同一家客户,生成对账单的同时,关闭模态框
  9366. if($scope.sameCust && $scope.validQty) {
  9367. $scope.saveApBillOut();
  9368. }
  9369. }
  9370. }]);
  9371. /**
  9372. * 客户应付发票
  9373. */
  9374. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  9375. BaseService.scrollBackToTop();
  9376. // 获取当前用户是否为普通用户
  9377. CurrentRole.isUser({}, {}, function (data) {
  9378. $scope.isUser = data.isUser;
  9379. });
  9380. $scope.active = 'all';
  9381. $scope.dateZoneText = '不限';
  9382. $scope.condition = {dateZone: 1};
  9383. /* 时间筛选初始化*/
  9384. var fromDate = new Date();
  9385. var toDate = new Date();
  9386. fromDate.setMonth(fromDate.getMonth() - 1);
  9387. fromDate.setHours(0, 0, 0, 0);
  9388. toDate.setHours(23, 59, 59, 999);
  9389. $scope.condition.dateFrom = fromDate;
  9390. $scope.condition.dateTo = toDate;
  9391. $scope.changeDateZone = function (zone) {
  9392. $scope.condition.dateZone = zone;
  9393. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9394. $scope.condition.$dateZoneOpen = false;
  9395. getDateCondition(zone, $scope.condition);
  9396. $scope.tableParams.page(1);
  9397. $scope.tableParams.reload();
  9398. };
  9399. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9400. $scope.setActive = function (state) {
  9401. if ($scope.active != state) {
  9402. $scope.active = state;
  9403. if ($scope.tableParams.page() == 1)
  9404. $scope.tableParams.reload();
  9405. else
  9406. $scope.tableParams.page(1);
  9407. }
  9408. };
  9409. var getService = function () {
  9410. return FaApBill;
  9411. };
  9412. $scope.tableParams = new ngTableParams({
  9413. page: 1,
  9414. count: 20,
  9415. sorting: {
  9416. date: 'desc'
  9417. }
  9418. }, {
  9419. total: 0,
  9420. counts: [5, 10, 25, 50],
  9421. getData: function ($defer, params) {
  9422. $scope.loading = true;
  9423. var pageParams = params.url();
  9424. pageParams.searchFilter = { // 筛选条件
  9425. keyword: $scope.keyword,
  9426. fromDate: getDateTime($scope.condition.dateFrom),
  9427. endDate: getDateTime($scope.condition.dateTo)
  9428. };
  9429. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  9430. $scope.loading = false;
  9431. if (page) {
  9432. params.total(page.totalElement);
  9433. $defer.resolve(page.content);
  9434. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  9435. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9436. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9437. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  9438. }
  9439. }, function (response) {
  9440. $scope.loading = false;
  9441. toaster.pop('error', '数据加载失败', response.data);
  9442. });
  9443. }
  9444. });
  9445. $scope.openDatePicker = function ($event, item, openParam) {
  9446. $event.preventDefault();
  9447. $event.stopPropagation();
  9448. item[openParam] = !item[openParam];
  9449. };
  9450. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9451. $event.preventDefault();
  9452. $event.stopPropagation();
  9453. item[openParam] = !item[openParam];
  9454. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9455. $scope.tableParams.reload();
  9456. }
  9457. };
  9458. $scope.parseDate = function (dateStr) {
  9459. if (dateStr)
  9460. return Date.parse(dateStr, 'yyyy-MM-dd');
  9461. return new Date();
  9462. };
  9463. // 搜索框回车
  9464. $scope.onSearch = function () {
  9465. $scope.tableParams.page(1);
  9466. $scope.tableParams.reload();
  9467. };
  9468. // 选择查找日期
  9469. $scope.onDateCondition = function () {
  9470. $scope.tableParams.page(1);
  9471. $scope.tableParams.reload();
  9472. };
  9473. // 导出
  9474. $scope.exportXls = function () {
  9475. FaApBill.exportXls({}, {}, function (data) {
  9476. if (data.success){
  9477. window.location.href = 'sale/apBill/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  9478. }
  9479. }, function (response) {
  9480. toaster.pop('error', '数据加载失败', response.data);
  9481. });
  9482. }
  9483. }]);
  9484. /**
  9485. * 客户应付发票详情
  9486. */
  9487. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, $filter, FaApBill, toaster, $stateParams, BaseService, CurrentRole) {
  9488. BaseService.scrollBackToTop();
  9489. // 获取当前用户是否为普通用户
  9490. CurrentRole.isUser({}, {}, function (data) {
  9491. $scope.isUser = data.isUser;
  9492. });
  9493. var loadData = function () {
  9494. FaApBill.getAll({id: $stateParams.id}, function (data) {
  9495. $scope.bill = data;
  9496. $scope.loading = false;
  9497. }, function (response) {
  9498. toaster.pop('error', '', response.data);
  9499. });
  9500. };
  9501. loadData(); // 初始获取单据数据
  9502. }]);
  9503. /**
  9504. * 应付对账单
  9505. */
  9506. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol) {
  9507. BaseService.scrollBackToTop();
  9508. $scope.active = 'all';
  9509. $scope.dateZoneText = '不限';
  9510. $scope.condition = {dateZone: 1};
  9511. /* 时间筛选初始化*/
  9512. var fromDate = new Date();
  9513. var toDate = new Date();
  9514. fromDate.setMonth(fromDate.getMonth() - 1);
  9515. fromDate.setHours(0, 0, 0, 0);
  9516. toDate.setHours(23, 59, 59, 999);
  9517. $scope.condition.dateFrom = fromDate;
  9518. $scope.condition.dateTo = toDate;
  9519. $scope.changeDateZone = function (zone) {
  9520. $scope.condition.dateZone = zone;
  9521. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9522. $scope.condition.$dateZoneOpen = false;
  9523. getDateCondition(zone, $scope.condition);
  9524. $scope.tableParams.page(1);
  9525. $scope.tableParams.reload();
  9526. };
  9527. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9528. $scope.setActive = function (state) {
  9529. if ($scope.active != state) {
  9530. $scope.active = state;
  9531. if ($scope.tableParams.page() == 1)
  9532. $scope.tableParams.reload();
  9533. else
  9534. $scope.tableParams.page(1);
  9535. }
  9536. };
  9537. var getService = function () {
  9538. return FaArCheck;
  9539. };
  9540. $scope.tableParams = new ngTableParams({
  9541. page: 1,
  9542. count: 20,
  9543. sorting: {
  9544. date: 'desc'
  9545. }
  9546. }, {
  9547. total: 0,
  9548. counts: [5, 10, 25, 50],
  9549. getData: function ($defer, params) {
  9550. $scope.loading = true;
  9551. var pageParams = params.url();
  9552. pageParams.searchFilter = {};
  9553. pageParams.searchFilter.keyword = $scope.keyword;
  9554. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9555. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9556. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  9557. $scope.loading = false;
  9558. if (page) {
  9559. params.total(page.totalElement);
  9560. $defer.resolve(page.content);
  9561. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9562. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9563. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9564. }
  9565. }, function (response) {
  9566. $scope.loading = false;
  9567. toaster.pop('error', '数据加载失败', response.data);
  9568. });
  9569. }
  9570. });
  9571. $scope.openDatePicker = function ($event, item, openParam) {
  9572. $event.preventDefault();
  9573. $event.stopPropagation();
  9574. item[openParam] = !item[openParam];
  9575. };
  9576. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9577. $event.preventDefault();
  9578. $event.stopPropagation();
  9579. item[openParam] = !item[openParam];
  9580. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9581. $scope.tableParams.reload();
  9582. }
  9583. };
  9584. // 计算单据的商品总数
  9585. $scope.getTotalProd = function (check) {
  9586. var total = 0;
  9587. if (check.items) {
  9588. angular.forEach(check.items, function (value) {
  9589. total += value.qty;
  9590. });
  9591. }
  9592. return total;
  9593. };
  9594. // 搜索框回车
  9595. $scope.onSearch = function () {
  9596. $scope.tableParams.page(1);
  9597. $scope.tableParams.reload();
  9598. };
  9599. // 选择查找日期
  9600. $scope.onDateCondition = function () {
  9601. $scope.tableParams.page(1);
  9602. $scope.tableParams.reload();
  9603. };
  9604. }]);
  9605. // 应付对账单详情页
  9606. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function ($scope, $stateParams, FaArCheck, toaster, $state, BaseService) {
  9607. BaseService.scrollBackToTop();
  9608. var loadData = function () {
  9609. FaArCheck.get({id: $stateParams.id}, function (data) {
  9610. $scope.order = data;
  9611. $scope.loading = false;
  9612. });
  9613. };
  9614. loadData(); // 初始获取单据数据
  9615. $scope.onReplyClick = function (item, isAgreed) {
  9616. if (isAgreed) {// 同意确认
  9617. FaArCheck.agree({itemId: item.id}, {}, function (data) {
  9618. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  9619. }, function (response) {
  9620. toaster.pop('danger', '确认失败', response.data);
  9621. });
  9622. } else {// 不同意回复
  9623. FaArCheck.disagree({itemId: item.id}, {
  9624. qty: item.$replyQty,
  9625. remark: item.$replyRemark
  9626. }, function (data) {
  9627. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  9628. }, function (response) {
  9629. toaster.pop('danger', '确认失败', response.data);
  9630. });
  9631. }
  9632. };
  9633. // 获取明细的回复记录
  9634. $scope.getReplies = function (item) {
  9635. if (!item.replies) {
  9636. FaArCheck.getReplies({itemId: item.id}, function (data) {
  9637. item.replies = data;
  9638. }, function (response) {
  9639. toaster.pop('danger', '获取对账记录失败', response.data);
  9640. });
  9641. }
  9642. };
  9643. }]);
  9644. //应收对账单列表
  9645. app.controller('PurchaseApCheckCtrl', ['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster', 'ReportService', 'Symbol', 'CurrentRole', function ($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService, Symbol, CurrentRole) {
  9646. BaseService.scrollBackToTop();
  9647. // 获取当前用户是否为普通用户
  9648. CurrentRole.isUser({}, {}, function (data) {
  9649. $scope.isUser = data.isUser;
  9650. });
  9651. $scope.dateZoneText = '不限';
  9652. $scope.condition = {dateZone: 1};
  9653. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9654. $scope.active = 'todo';
  9655. /* 时间筛选初始化*/
  9656. var fromDate = new Date();
  9657. var toDate = new Date();
  9658. fromDate.setMonth(fromDate.getMonth() - 1);
  9659. fromDate.setHours(0, 0, 0, 0);
  9660. toDate.setHours(23, 59, 59, 999);
  9661. $scope.condition.dateFrom = fromDate;
  9662. $scope.condition.dateTo = toDate;
  9663. //打印 对账单
  9664. $scope.print = function (check) {
  9665. var newPage = window.open("about:blank");
  9666. FaApCheck.printPermission({}, function () {
  9667. FaApCheck.printCount({id: check.id}, {});//增加打印此次
  9668. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id, newPage);
  9669. }, function (response) {
  9670. newPage.close();
  9671. toaster.pop('error', '打印失败', response.data);
  9672. });
  9673. };
  9674. //状态
  9675. $scope.setActive = function (state) {
  9676. if ($scope.active != state) {
  9677. $scope.active = state;
  9678. if ($scope.tableParams.page() == 1)
  9679. $scope.tableParams.reload();
  9680. else
  9681. $scope.tableParams.page(1);
  9682. }
  9683. };
  9684. $scope.changeDateZone = function (zone) {
  9685. $scope.condition.dateZone = zone;
  9686. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9687. $scope.condition.$dateZoneOpen = false;
  9688. getDateCondition(zone, $scope.condition);
  9689. $scope.tableParams.page(1);
  9690. $scope.tableParams.reload();
  9691. };
  9692. //获取应收对账单全部
  9693. $scope.tableParams = new ngTableParams({
  9694. page: 1,
  9695. count: 20,
  9696. sorting: {
  9697. recordDate: 'desc'
  9698. }
  9699. }, {
  9700. total: 0,
  9701. counts: [5, 10, 25, 50],
  9702. getData: function ($defer, params) {
  9703. $scope.loading = true;
  9704. var pageParams = params.url();
  9705. pageParams.searchFilter = { // 筛选条件
  9706. keyword: $scope.keyword,
  9707. fromDate: getDateTime($scope.condition.dateFrom),
  9708. endDate: getDateTime($scope.condition.dateTo)
  9709. };
  9710. FaApCheck[getState($scope.active)](BaseService.parseParams(pageParams), function (page) {
  9711. $scope.loading = false;
  9712. if (page) {
  9713. params.total(page.totalElement);
  9714. $scope.data = $defer.resolve(page.content);
  9715. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  9716. }
  9717. }, function (response) {
  9718. $scope.loading = false;
  9719. toaster.pop('error', '数据加载失败', response.data);
  9720. });
  9721. }
  9722. });
  9723. //获得各分类未阅读数量
  9724. var getUnreadCount = function () {
  9725. FaApCheck.getUnreadCount(null, function(data){
  9726. $scope.unread = data;
  9727. });
  9728. };
  9729. getUnreadCount();
  9730. //设置单据已读
  9731. $scope.setOrdersRead = function (id) {
  9732. // 如果单据本身已读,则不发送请求修改数据
  9733. if (!$scope.isUnread(id)){
  9734. return;
  9735. }
  9736. var sourceId = [];
  9737. sourceId.push(id);
  9738. FaApCheck.setRead({}, sourceId, function (message) {
  9739. getUnreadCount();
  9740. });
  9741. };
  9742. //获取未读单据id
  9743. var getUnreadIds = function (){
  9744. FaApCheck.getUnreadIds({}, "", function (message) {
  9745. $scope.unreadCode = message.content;
  9746. });
  9747. };
  9748. getUnreadIds();
  9749. //判断单据是否未读
  9750. $scope.isUnread = function (id){
  9751. for (var i in $scope.unreadCode) {
  9752. if (id == $scope.unreadCode[i]) {
  9753. return true;
  9754. }
  9755. }
  9756. };
  9757. $scope.openDatePicker = function ($event, item, openParam) {
  9758. $event.preventDefault();
  9759. $event.stopPropagation();
  9760. item[openParam] = !item[openParam];
  9761. };
  9762. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9763. $event.preventDefault();
  9764. $event.stopPropagation();
  9765. item[openParam] = !item[openParam];
  9766. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9767. $scope.tableParams.reload();
  9768. }
  9769. };
  9770. // 计算单据的商品总数
  9771. $scope.getTotalProd = function (check) {
  9772. var total = 0;
  9773. if (check.items) {
  9774. angular.forEach(check.items, function (value) {
  9775. total += value.checkQty;
  9776. });
  9777. }
  9778. return total;
  9779. };
  9780. // 搜索框回车
  9781. $scope.onSearch = function () {
  9782. $scope.tableParams.page(1);
  9783. $scope.tableParams.reload();
  9784. };
  9785. // 选择查找日期
  9786. $scope.onDateCondition = function () {
  9787. $scope.tableParams.page(1);
  9788. $scope.tableParams.reload();
  9789. };
  9790. // 导出
  9791. $scope.exportXls = function () {
  9792. FaApCheck.exportXls({}, {}, function (data) {
  9793. if (data.success){
  9794. window.location.href = 'sale/apCheck/xls/list?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  9795. }
  9796. }, function (response) {
  9797. toaster.pop('error', '数据加载失败', response.data);
  9798. });
  9799. }
  9800. }]);
  9801. //应收对账单详情
  9802. app.controller('PurchaseApCheckDetailCtrl', ['$scope', 'toaster', 'FaApCheck', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, toaster, FaApCheck, $stateParams, BaseService, CurrentRole) {
  9803. BaseService.scrollBackToTop();
  9804. // 获取当前用户是否为普通用户
  9805. CurrentRole.isUser({}, {}, function (data) {
  9806. $scope.isUser = data.isUser;
  9807. });
  9808. $scope.haveSelected = true;
  9809. $scope.data = {};
  9810. //控制提交和删除按钮的显示
  9811. $scope.ifShow = true;
  9812. var loadData = function () {
  9813. FaApCheck.getItem({id: $stateParams.id}, function (data) {
  9814. $scope.data = data;
  9815. if ($scope.data.status) {
  9816. } else {
  9817. $scope.ifShow = true;
  9818. }
  9819. }, function (response) {
  9820. toaster.pop('error', '', response.data);
  9821. })
  9822. };
  9823. if ($stateParams.id) {
  9824. loadData();
  9825. }
  9826. $scope.haveSource = false;
  9827. //提交应收对账单
  9828. $scope.submitApCheck = function () {
  9829. FaApCheck.updateStatus({id: $stateParams.id}, {}, function (data) {
  9830. if (data.result) {
  9831. toaster.pop('success', '提示', '提交成功');
  9832. $scope.haveSelected = false;
  9833. window.location.href = '#/fa/apCheck';
  9834. } else {
  9835. $scope.haveSource = true;
  9836. loadData();
  9837. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  9838. $scope.haveSelected = true;
  9839. }
  9840. }, function (response) {
  9841. $scope.loading = false;
  9842. toaster.pop('error', '更新已转数失败', response.data);
  9843. });
  9844. }
  9845. //删除应收对账单的同时更新来源表已转数
  9846. var updateYCheckQty = function () {
  9847. var sourceInfos = [];
  9848. angular.forEach($scope.data.items, function (item) {
  9849. $scope.sourceInfo = {
  9850. sourceId: '',
  9851. sourceTable: '',
  9852. newYCheckQty: ''
  9853. };
  9854. $scope.sourceInfo.sourceId = item.sourceId;
  9855. $scope.sourceInfo.sourceTable = item.sourceTable;
  9856. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  9857. sourceInfos.push($scope.sourceInfo);
  9858. });
  9859. FaApCheck.update({}, sourceInfos, function () {
  9860. }, function (response) {
  9861. $scope.loading = false;
  9862. toaster.pop('error', '更新已转数失败', response.data);
  9863. });
  9864. }
  9865. //删除应收对账单
  9866. $scope.deleteApCheck = function () {
  9867. FaApCheck.deleteApCheck({id: $stateParams.id}, {}, function (data) {
  9868. updateYCheckQty();
  9869. toaster.pop('success', '提示', '删除成功');
  9870. }, function (response) {
  9871. toaster.pop('error', '删除失败', response.data);
  9872. });
  9873. $scope.haveSelected = false;
  9874. }
  9875. //作废应收对账单
  9876. $scope.cancelApCheck = function (check) {
  9877. FaApCheck.cancel({id: check.id}, {}, function (data) {
  9878. $scope.checkResult = false;
  9879. if (data.result) {
  9880. $scope.checkResult = true;
  9881. toaster.pop('success', '提示', '作废成功');
  9882. $scope.tableParams.reload();
  9883. } else {
  9884. toaster.pop('error', '提示', '作废失败');
  9885. }
  9886. }, function (response) {
  9887. $scope.loading = false;
  9888. toaster.pop('error', '作废失败', response.data);
  9889. });
  9890. }
  9891. }]);
  9892. //未对账单据列表
  9893. app.controller('PurchaseApCheckListCtrl', ['$scope', 'FaApCheck', 'toaster', '$state', '$filter', '$modal', 'Vendor', 'DecimalNumber', function ($scope, FaApCheck, toaster, $state, $filter, $modal, Vendor, DecimalNumber) {
  9894. $scope.data = [];// 列表数据
  9895. $scope.condition = {
  9896. $fromOpened: false
  9897. }
  9898. $scope.openDatePicker = function ($event, item, openParam) {
  9899. $event.preventDefault();
  9900. $event.stopPropagation();
  9901. item[openParam] = !item[openParam];
  9902. }
  9903. // 客户联想词
  9904. $scope.getSimilarCustomers = function (value) {
  9905. if (value) {
  9906. return Vendor.getSimilarCustomers({keyword: value}).$promise.then(function (data) {
  9907. return data.map(function (item) {
  9908. return item;
  9909. });
  9910. });
  9911. }
  9912. };
  9913. $scope.onAssociateCustomerClick = function (vendor) {
  9914. if (vendor.apcheck == 0) {
  9915. toaster.pop('info', '提示', '该客户暂未启用平台对账功能');
  9916. $scope.suuorname = '';
  9917. } else {
  9918. $scope.suuorname = vendor.custName;
  9919. }
  9920. }
  9921. //查找客户
  9922. $scope.searchCust = function (suuorname) {
  9923. var modalInstance = $modal.open({
  9924. animation: true,
  9925. templateUrl: 'static/tpl/index/fa/apcheck_customer.html',
  9926. controller: 'SearchCustInfoCtrl',
  9927. size: 'lg',
  9928. resolve: {
  9929. suuorname: function () {
  9930. return suuorname;
  9931. }
  9932. }
  9933. });
  9934. modalInstance.result.then(function (customer) {
  9935. $scope.suuorname = customer.myEnterprise.enName;
  9936. });
  9937. }
  9938. // 点击筛选根据条件选择数据
  9939. $scope.suuorname = '';
  9940. // 默认本月
  9941. $scope.sdateTo = new Date();
  9942. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  9943. $scope.vuuorname = '';
  9944. $scope.factory = '';
  9945. $scope.prodtitle = '';
  9946. $scope.prodspec = '';
  9947. $scope.condition.uuorname = '';
  9948. $scope.condition.dateFrom = '';
  9949. $scope.condition.dateTo = '';
  9950. $scope.condition.venduuorname = '';
  9951. $scope.condition.factory = '';
  9952. $scope.condition.prodtitle = '';
  9953. $scope.condition.prodspec = '';
  9954. $scope.searchOrder = function (check) {
  9955. $scope.data = [];
  9956. $scope.checkboxes.checked = false;
  9957. $scope.totalMoney = 0;
  9958. $scope.condition.uuorname = $scope.suuorname;
  9959. $scope.condition.factory = $scope.factory
  9960. $scope.condition.prodtitle = $scope.prodtitle;
  9961. $scope.condition.prodspec = $scope.prodspec;
  9962. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9963. $scope.thisdatato = ($scope.sdateTo || 0);
  9964. if ($scope.thisdatato != 0) {
  9965. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9966. } else {
  9967. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9968. }
  9969. $scope.condition.venduuorname = $scope.vuuorname;
  9970. if ($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9971. $scope.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9972. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9973. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  9974. + "|" + ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  9975. + "|" + ($scope.condition.factory == null ? "" : $scope.condition.factory)
  9976. + "|" + ($scope.condition.prodtitle == null ? "" : $scope.condition.prodtitle)
  9977. + "|" + ($scope.condition.prodspec == null ? "" : $scope.condition.prodspec));//保存当前取值的关键词
  9978. $scope.exportKeywordXls = encodeURIComponent($scope.keywordXls);
  9979. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9980. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9981. if (!$scope.suuorname) {
  9982. toaster.pop('warning', '提示', '请先选择客户');
  9983. document.getElementById('suuorname').focus();//光标默认在客户
  9984. } else {
  9985. $scope.loading = true;
  9986. FaApCheck.getAllByKeywords({
  9987. fromDate: $scope.fromDate,
  9988. endDate: $scope.endDate,
  9989. keyword: $scope.keywordXls
  9990. }, function (data) {
  9991. if (data.length > 0) {
  9992. angular.forEach(data, function (item) {
  9993. item.$selected = true;
  9994. });
  9995. $scope.data = data;
  9996. $scope.checkboxes.checked = true;
  9997. $scope.getTotalMoney();
  9998. } else {
  9999. toaster.pop('info', '提示', '当前没有需要对账记录');
  10000. }
  10001. $scope.loading = false;
  10002. }, function (response) {
  10003. $scope.loading = false;
  10004. toaster.pop('error', '提示', response.data);
  10005. });
  10006. }
  10007. }
  10008. }
  10009. /**
  10010. * 点击勾选框,选中要转应收对账单的订单
  10011. * */
  10012. $scope.totalMoney = 0;
  10013. $scope.checkboxes = {
  10014. checked: false
  10015. };
  10016. // 点击勾选全部的复选框
  10017. $scope.checkAll = function () {
  10018. $scope.totalMoney = 0;
  10019. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodtitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodspec || $scope.condition.factory);
  10020. var uuorname = $scope.suuorname;
  10021. var venduuorname = $scope.venduuorname;
  10022. var dateFrom = $scope.condition.dateFrom;
  10023. var dateTo = $scope.condition.dateTo;
  10024. var prodTitle = $scope.condition.prodtitle;
  10025. var prodSpec = $scope.condition.prodspec;
  10026. var factory = $scope.condition.factory;
  10027. angular.forEach($scope.filteredData, function (item) {
  10028. if ((item.pidate >= dateFrom || dateFrom == '') && (item.pidate < dateTo || dateTo == '')) {
  10029. item.$selected = $scope.checkboxes.checked;
  10030. }
  10031. });
  10032. $scope.getTotalMoney();
  10033. };
  10034. //获取已选单据总金额
  10035. var total = true;
  10036. $scope.getTotalMoney = function () {
  10037. $scope.totalMoney = 0;
  10038. angular.forEach($scope.data, function (check) {
  10039. if (check.$selected) {
  10040. var price = DecimalNumber.accMul((check.thischeckqty || 0), (check.orderprice || 0));
  10041. $scope.totalMoney += Math.round(price * 100) / 100;
  10042. } else {
  10043. $scope.totalMoney += 0;
  10044. }
  10045. });
  10046. }
  10047. // 点击其中一个明细的复选框
  10048. $scope.checkOne = function (check) {
  10049. var result = true;
  10050. angular.forEach($scope.data, function (item) {
  10051. if (item.$selected != true) {
  10052. result = false;
  10053. return;
  10054. }
  10055. });
  10056. $scope.checkboxes.checked = result;
  10057. };
  10058. $scope.haveSelected = false;
  10059. //生成应收对账单
  10060. $scope.createApCheck = function () {
  10061. //保存应收对账单主记录字段
  10062. $scope.apCheck = {
  10063. custUu: '',
  10064. custName: '',
  10065. enUu: '',
  10066. apDate: '',
  10067. beginDate: '',
  10068. endDate: '',
  10069. checkStatus: '未对账',
  10070. checkAmount: 0,
  10071. currency: '',
  10072. rate: '',
  10073. items: [],
  10074. taxrate: ''
  10075. };
  10076. //保存来源单据相关信息
  10077. var sourceInfos = [];
  10078. //所允许的本次对账最大最小数量
  10079. $scope.data.maxThisCheckQty = 0;
  10080. $scope.data.minThisCheckQty = 0;
  10081. $scope.sameCust = true;
  10082. $scope.validQty = true;
  10083. $scope.loading = true;
  10084. angular.forEach($scope.data, function (check) {
  10085. //保存应收对账单明细行数据
  10086. $scope.item = {
  10087. inoutno: '',
  10088. inoutnodetno: '',
  10089. orderCode: '',
  10090. orderClass: '',
  10091. orderDetno: '',
  10092. price: '',
  10093. checkQty: '',
  10094. amount: '',
  10095. sourceId: '',
  10096. sourceTable: '',
  10097. oldYCheckQty: '',
  10098. status: 0,
  10099. receiveCode: '',
  10100. receiveName: '',
  10101. prodCode: '',
  10102. prodTitle: '',
  10103. prodSpec: '',
  10104. taxrate: '',
  10105. sendcode: '',
  10106. whname: '',
  10107. };
  10108. //应收对账单明细行来源表信息
  10109. $scope.sourceInfo = {
  10110. sourceId: '',
  10111. sourceTable: '',
  10112. newYCheckQty: ''
  10113. };
  10114. //此次对账后新的已转数
  10115. $scope.newYCheckQty = 0;
  10116. if (check.$selected == true) {
  10117. $scope.apCheck.custName = check.custname;
  10118. $scope.apCheck.enUu = check.enuu;
  10119. $scope.apCheck.checkAmount += (check.thischeckqty || 0) * (check.orderprice || 0);
  10120. $scope.apCheck.apDate = check.pidate;
  10121. $scope.apCheck.rate = check.rate;
  10122. //必须是同一家客户才能生成对账单,否则提示错误
  10123. if ($scope.apCheck.custUu == '') {
  10124. $scope.apCheck.custUu = check.custuu;
  10125. } else if ($scope.apCheck.custUu !== check.custuu) {
  10126. $scope.sameCust = false;
  10127. $scope.loading = false;
  10128. toaster.pop('error', '请选择同一家客户');
  10129. }
  10130. //必须是相同币别才能生成对账单,否则提示错误
  10131. if ($scope.apCheck.currency == '') {
  10132. $scope.apCheck.currency = check.currency;
  10133. } else if ($scope.apCheck.currency !== check.currency) {
  10134. $scope.sameCust = false;
  10135. $scope.loading = false;
  10136. toaster.pop('error', '请选择同一种币别');
  10137. }
  10138. //必须是相同税率才能生成对账单,否则提示错误
  10139. if (!angular.isNumber($scope.apCheck.taxrate)) {
  10140. $scope.apCheck.taxrate = check.taxrate;
  10141. } else if ($scope.apCheck.taxrate != check.taxrate) {
  10142. $scope.sameCust = false;
  10143. $scope.loading = false;
  10144. toaster.pop('error', '请选择相同的税率');
  10145. }
  10146. //本次对账数量必须小于总对账数量
  10147. if (check.qty > 0) {
  10148. $scope.data.maxThisCheckQty = check.qty;
  10149. $scope.data.minThisCheckQty = 0;
  10150. if (check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0) {
  10151. $scope.validQty = false;
  10152. $scope.loading = false;
  10153. toaster.pop('error', '本次对账数量,填写有误!');
  10154. }
  10155. } else if (check.qty < 0) {
  10156. $scope.data.maxThisCheckQty = 0;
  10157. $scope.data.minThisCheckQty = check.qty;
  10158. if (((-check.qty) - (-check.ycheckqty) < (-check.thischeckqty)) || check.thischeckqty > 0 || check.thischeckqty == 0) {
  10159. $scope.validQty = false;
  10160. $scope.loading = false;
  10161. toaster.pop('error', '本次对账数量,填写有误!');
  10162. }
  10163. }
  10164. //获取最小时间作为对账区间的起始时间
  10165. if ($scope.apCheck.beginDate == '') {
  10166. $scope.apCheck.beginDate = check.pidate;
  10167. } else {
  10168. $scope.apCheck.beginDate = $scope.apCheck.beginDate > check.pidate ? check.pidate : $scope.apCheck.beginDate;
  10169. }
  10170. //获取最大时间作为对账区间的截止时间
  10171. if ($scope.apCheck.endDate == '') {
  10172. $scope.apCheck.endDate = check.pidate;
  10173. } else {
  10174. $scope.apCheck.endDate = $scope.apCheck.endDate < check.pidate ? check.pidate : $scope.apCheck.endDate;
  10175. }
  10176. //应收对账单明细行数据
  10177. $scope.item.orderCode = check.ordercode;
  10178. $scope.item.orderClass = check.piclass;
  10179. $scope.item.orderDetno = check.orderdetno;
  10180. $scope.item.price = check.orderprice;
  10181. $scope.item.checkQty = check.thischeckqty;
  10182. $scope.item.amount = (check.thischeckqty || 0) * (check.orderprice || 0);
  10183. $scope.item.sourceId = check.sourceid;
  10184. $scope.item.sourceTable = check.sourcetable;
  10185. $scope.item.oldYCheckQty = check.ycheckqty;
  10186. $scope.item.prodCode = check.prodcode;
  10187. $scope.item.prodTitle = check.prodtitle;
  10188. $scope.item.prodSpec = check.prodspec;
  10189. $scope.item.inoutno = check.inoutno;
  10190. $scope.item.inoutnodetno = check.detno;
  10191. $scope.item.taxrate = check.taxrate;
  10192. $scope.item.receiveCode = check.receivecode;
  10193. $scope.item.receiveName = check.receivename;
  10194. $scope.item.sendcode = check.sendcode;
  10195. $scope.item.whname = check.whname;
  10196. //来源表相关信息
  10197. $scope.sourceInfo.sourceid = check.sourceid;
  10198. $scope.sourceInfo.sourcetable = check.sourcetable;
  10199. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  10200. sourceInfos.push($scope.sourceInfo);
  10201. $scope.apCheck.items.push($scope.item);
  10202. $scope.haveSelected = true;
  10203. }
  10204. });
  10205. //保存生成的应收对账单
  10206. $scope.saveApCheck = function () {
  10207. FaApCheck.saveApCheck({}, $scope.apCheck, function (data) {
  10208. $scope.loading = false;
  10209. toaster.pop('success', '成功', '生成应收对账成功');
  10210. $state.go('fa.apCheck_detail', {id: data.id}, {reload: true});
  10211. }, function (response) {
  10212. $scope.loading = false;
  10213. toaster.pop('error', '生成对账单失败', response.data);
  10214. })
  10215. };
  10216. //如果是同一家客户,生成对账单的同时,关闭模态框
  10217. if ($scope.sameCust && $scope.validQty) {
  10218. $scope.saveApCheck();
  10219. }
  10220. }
  10221. }]);
  10222. // 企业信息设置
  10223. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function ($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder) {
  10224. BaseService.scrollBackToTop();
  10225. $scope.loading = true;
  10226. AccountEnterprise.get({}, function (data) {
  10227. $scope.loading = false;
  10228. $scope.enterprise = data;
  10229. if (data.tags) {
  10230. $scope.tags = data.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  10231. } else {
  10232. $scope.tags = [];
  10233. }
  10234. // 获取付款企业信息
  10235. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  10236. $scope.pays = data;
  10237. }, function (response) {
  10238. toaster.pop('error', '提示', response.data);
  10239. });
  10240. // 获取企业开票信息
  10241. AccountEnterprise.getApBillOutInfo({enuu: $scope.enterprise.uu}, {}, function(data) {
  10242. $scope.apBillOutInfo = data;
  10243. }, function(response) {
  10244. toaster.pop('error', '提示', response.data);
  10245. });
  10246. });
  10247. // 更新企业信息
  10248. $scope.updateDetailInfo = function () {
  10249. $scope.loading = true;
  10250. $scope.enterprise = $scope.copyEnterprise;
  10251. $scope.enterprise.tags = $scope.tags.join(','); // 将标签数组转换成逗号分隔的字符串,便于储存
  10252. AccountEnterprise.save($scope.enterprise, function () {
  10253. $scope.loading = false;
  10254. $scope.connectionEditing = false;
  10255. toaster.pop('success', '提示', '修改企业信息成功');
  10256. $state.reload();
  10257. }, function (response) {
  10258. $scope.loading = false;
  10259. toaster.pop('error', '修改信息失败', response.data);
  10260. });
  10261. };
  10262. // 更新企业开票信息
  10263. $scope.updateApBillOutInfo = function(uu){
  10264. $scope.loading = true;
  10265. $scope.apBillOutInfo.uu = uu;
  10266. AccountEnterprise.saveApBillOutInfo($scope.apBillOutInfo, function(){
  10267. $scope.loading = false;
  10268. $scope.apBillOutInfoEditing = false;
  10269. toaster.pop('success', '提示', '修改企业开票信息成功');
  10270. $state.reload();
  10271. }, function(response){
  10272. $scope.loading = false;
  10273. toaster.pop('error', '修改信息失败', response.data);
  10274. });
  10275. };
  10276. // 申请Saas
  10277. $scope.applySaas = function () {
  10278. if ($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  10279. var modalInstance = $modal.open({
  10280. animation: true,
  10281. templateUrl: 'static/tpl/index/account/applySaas.html',
  10282. controller: 'ApplySaasCtrl',
  10283. resolve: {
  10284. enterprise: function () {
  10285. return angular.copy($scope.enterprise);
  10286. }
  10287. }
  10288. });
  10289. modalInstance.result.then(function () {
  10290. $state.reload();
  10291. }, function () {
  10292. });
  10293. } else {
  10294. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  10295. }
  10296. };
  10297. // 获取收货地址列表
  10298. ShipAddress.shipAddList({}, function (data) {
  10299. $scope.ships = data;
  10300. });
  10301. // 判断是否是代采企业
  10302. DeputyOrder.isDeputyEnterprise({}, function (data) {
  10303. $scope.deputyEnter = data;
  10304. });
  10305. // 获取地址信息
  10306. $http.get('resources/citydata/city.json', {
  10307. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10308. }).then(function (response) {
  10309. $scope.provinces = response.data;
  10310. });
  10311. // 新增收货地址保存
  10312. $scope.saveShipAddress = function (ship) {
  10313. ship.address = ship.province + ship.city + ship.district;
  10314. ShipAddress.saveAddress({}, ship, function (data) {
  10315. if (data.success) {
  10316. ShipAddress.shipAddList({}, function (data) {
  10317. $scope.ships = data;
  10318. });
  10319. toaster.pop('success', '提示', data.success);
  10320. $scope.ship = {receiver: null, usertel: null, phone: null, email: null, province: null, city: null, district: null, addressdet: null, addalias: null, address: null};
  10321. }
  10322. if (data.error) {
  10323. toaster.pop('error', '提示', data.error);
  10324. }
  10325. });
  10326. }
  10327. // 删除收货地址
  10328. $scope.removeShip = function (id, index) {
  10329. ShipAddress.removeShipAddress({id: id}, {}, function (data) {
  10330. $scope.ships.splice(index, 1);
  10331. toaster.pop('success', '提示', '收货地址删除成功');
  10332. }, function (response) {
  10333. toaster.pop('error', '提示', response.data);
  10334. });
  10335. };
  10336. // 编辑收货地址
  10337. $scope.editShip = function (ship) {
  10338. var modalInstance = $modal.open({
  10339. animation: true,
  10340. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  10341. controller: 'ShipAddressCtrl',
  10342. resolve: {
  10343. ship: function () {
  10344. return ship;
  10345. }
  10346. }
  10347. });
  10348. modalInstance.result.then(function () {
  10349. ShipAddress.shipAddList({}, function (data) {
  10350. $scope.ships = data;
  10351. });
  10352. }, function () {
  10353. });
  10354. };
  10355. // 新增付款企业
  10356. $scope.addPayCompany = function () {
  10357. var modalInstance = $modal.open({
  10358. animation: true,
  10359. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  10360. controller: 'PayCompanyCtrl',
  10361. resolve: {
  10362. pay: function () {
  10363. return null;
  10364. }
  10365. }
  10366. });
  10367. modalInstance.result.then(function () {
  10368. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  10369. $scope.pays = data;
  10370. // 获取付款企业信息
  10371. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  10372. $scope.pays = data;
  10373. }, function (response) {
  10374. toaster.pop('error', '提示', response.data);
  10375. });
  10376. }, function (response) {
  10377. toaster.pop('error', '提示', response.data);
  10378. });
  10379. }, function () {
  10380. });
  10381. }
  10382. // 删除付款企业
  10383. $scope.removePay = function (id, index) {
  10384. DeputyOrder.removePayCompany({id: id}, {}, function (data) {
  10385. $scope.pays.splice(index, 1);
  10386. toaster.pop('success', '提示', '付款企业信息删除成功');
  10387. }, function (response) {
  10388. toaster.pop('error', '提示', response.data);
  10389. });
  10390. };
  10391. // 编辑付款企业
  10392. $scope.editPay = function (pay, uu) {
  10393. var modalInstance = $modal.open({
  10394. animation: true,
  10395. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  10396. controller: 'PayCompanyCtrl',
  10397. resolve: {
  10398. pay: function () {
  10399. return pay;
  10400. }
  10401. }
  10402. });
  10403. modalInstance.result.then(function () {
  10404. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  10405. $scope.pays = data;
  10406. }, function (response) {
  10407. toaster.pop('error', '提示', response.data);
  10408. });
  10409. }, function () {
  10410. });
  10411. };
  10412. // 设置logo
  10413. $scope.showImageDialog = function (modal) {
  10414. require(['jquery-uploadify'], function () {
  10415. $modal.open({
  10416. templateUrl: 'static/tpl/index/home/insert.html',
  10417. controller: 'ImageInsertCtrl',
  10418. backdrop: 'static'
  10419. }).result.then(function (image) {
  10420. $scope.imageUrl = image.thumb;
  10421. User.postImageUrl(null, angular.toJson($scope.imageUrl), function (data) {
  10422. $scope.user = data;
  10423. }, function (response) {
  10424. toaster.pop('error', '设置图像失败,' + response.data);
  10425. });
  10426. });
  10427. });
  10428. }
  10429. // 添加经营范围标签
  10430. $scope.addTag = function () {
  10431. if ($scope.tags.indexOf($scope.tag) == -1){
  10432. if (null != $scope.tag && '' != $scope.tag) {
  10433. $scope.tags.push($scope.tag);
  10434. }
  10435. }
  10436. $scope.tag = '';
  10437. }
  10438. // 移除经营范围标签
  10439. $scope.removeTag = function (tag) {
  10440. removeByValue($scope.tags, tag);
  10441. }
  10442. // 获取行业信息
  10443. $http.get('static/data/profession.json').success(function (data) {
  10444. $scope.list = data;
  10445. });
  10446. // 选择行业
  10447. $scope.profession = new Array();
  10448. $scope.showProfession = false;
  10449. $scope.selectProfession = function () {
  10450. $scope.professionArray = [];
  10451. $scope.active = [];
  10452. $scope.showProfession = !$scope.showProfession;
  10453. $scope.profession[0] = $scope.list;
  10454. }
  10455. $scope.isInList = false;
  10456. $scope.isInInput = false;
  10457. $scope.hideList = function () {
  10458. if (!$scope.isInList && !$scope.isInInput && $scope.showProfession) {
  10459. $scope.showProfession = false;
  10460. }
  10461. }
  10462. // 行业子菜单点击
  10463. $scope.onItemClick = function (key, index, value) {
  10464. $scope.active[index] = key;
  10465. if (angular.isString(value)){ // 值为字符串说明点击的是最后一级
  10466. $scope.copyEnterprise.profession = value;
  10467. $scope.showProfession = false;
  10468. return;
  10469. }
  10470. $scope.professionArray = [];
  10471. $scope.profession.splice(index+1);
  10472. if (angular.isArray(value)){ // 值为数组说明下一级是最后一级
  10473. $scope.professionArray = value;
  10474. } else if (angular.isObject(value)) {
  10475. $scope.profession[index+1] = value;
  10476. }
  10477. }
  10478. // 判断值是否为字符串
  10479. $scope.isString = function (value) {
  10480. return angular.isString(value);
  10481. }
  10482. // 拷贝企业数据,在编辑企业数据是使用拷贝数据
  10483. $scope.copyData = function () {
  10484. $scope.copyEnterprise = angular.copy($scope.enterprise);
  10485. if ($scope.enterprise.tags) {
  10486. $scope.tags = $scope.enterprise.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  10487. } else {
  10488. $scope.tags = [];
  10489. }
  10490. }
  10491. }]);
  10492. // 编辑收货地址
  10493. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function ($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  10494. $scope.ship = ship;
  10495. // 获取地址信息
  10496. $http.get('resources/citydata/city.json', {
  10497. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10498. }).then(function (response) {
  10499. $scope.provinces = response.data;
  10500. });
  10501. // 新增收货地址保存
  10502. $scope.saveShipAddress = function (ship) {
  10503. ship.address = ship.province + ship.city + ship.district;
  10504. ShipAddress.saveAddress({}, ship, function (data) {
  10505. if (data.success) {
  10506. toaster.pop('success', '提示', data.success);
  10507. $modalInstance.close();
  10508. }
  10509. if (data.error) {
  10510. toaster.pop('error', '提示', data.error);
  10511. }
  10512. });
  10513. }
  10514. $scope.cancel = function () {
  10515. $modalInstance.dismiss();
  10516. }
  10517. }]);
  10518. // 编辑付款企业信息
  10519. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function ($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  10520. $scope.pay = pay;
  10521. // 获取地址信息
  10522. $http.get('resources/citydata/city.json', {
  10523. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10524. }).then(function (response) {
  10525. $scope.provinces = response.data;
  10526. });
  10527. // 新增收货地址保存
  10528. $scope.savePayCompany = function (pay) {
  10529. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  10530. DeputyOrder.savePaycompany({}, pay, function (data) {
  10531. toaster.pop('success', '提示', '保存成功');
  10532. $modalInstance.dismiss();
  10533. }, function (response) {
  10534. toaster.pop('error', '提示', response.data);
  10535. });
  10536. }
  10537. $scope.cancel = function () {
  10538. $modalInstance.dismiss();
  10539. }
  10540. }]);
  10541. // 申请Saas Controller
  10542. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function ($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http) {
  10543. $scope.enterprise = enterprise;
  10544. $scope.checking = false;
  10545. $scope.$watch('enterprise.enSaasUrl', function () {
  10546. if ($scope.enterprise.enSaasUrl) {
  10547. $http.get('signup/saasUrlEnable', {
  10548. params: {
  10549. enSaasUrl: $scope.enterprise.enSaasUrl
  10550. }
  10551. }).success(function (data) {
  10552. if (data && data == 'true') {
  10553. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  10554. } else {
  10555. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10556. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  10557. }
  10558. }).error(function () {
  10559. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10560. $scope.enSaasUrlErrorInfo = '验证出错';
  10561. });
  10562. } else {
  10563. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10564. }
  10565. });
  10566. var setSaasUrl = function (url) {
  10567. var index = url.indexOf('www.');
  10568. if (index != -1) {//包含www.
  10569. var substr = url.substring(index + 4, url.length);
  10570. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  10571. } else {
  10572. $scope.enterprise.enSaasUrl = getHost(url);
  10573. }
  10574. };
  10575. // 解析获取网址的一级域名
  10576. var getHost = function (host) {
  10577. var newhost;
  10578. var domain;
  10579. var ArrDomain = new Array('.com.cn', '.net.cn', '.org.cn', '.gov.cn', '.com', '.cn', '.tel', '.mobi', '.net', '.org', '.asia', '.me', '.cc', '.name', '.info');//枚举所有后缀
  10580. for (var k in ArrDomain) {
  10581. var re = eval('/\\' + ArrDomain[k] + '$/g');
  10582. newhost = host.replace(re, '');
  10583. if (newhost != host) {
  10584. domain = ArrDomain[k];
  10585. break;
  10586. }
  10587. }
  10588. var hostar = newhost.split('.');
  10589. var s = hostar[hostar.length - 1];
  10590. return s;
  10591. };
  10592. // 设置优企云服域名为官网网址一级域名
  10593. if ($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  10594. $scope.apply = function () {
  10595. $scope.loading = true;
  10596. AccountEnterprise.applySaas({
  10597. enUU: $scope.enterprise.uu,
  10598. enSaasUrl: $scope.enterprise.enSaasUrl,
  10599. enAdminPassword: $scope.enterprise.enAdminPassword
  10600. }, {}, function () {
  10601. $scope.loading = false;
  10602. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  10603. $modalInstance.close();
  10604. }, function (response) {
  10605. $scope.loading = false;
  10606. toaster.pop('error', '申请失败', response.data);
  10607. });
  10608. };
  10609. $scope.cancel = function () {
  10610. $modalInstance.dismiss();
  10611. };
  10612. }]);
  10613. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', 'AccountEnterprise', 'CurrentRole', function ($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert, AccountEnterprise, CurrentRole) {
  10614. BaseService.scrollBackToTop();
  10615. $scope.editing = false;
  10616. $scope.loading = true;
  10617. $scope.enterprise = null;
  10618. $scope.searchMthod = false;
  10619. $scope.keyword = null;
  10620. AccountUser.findDistribute({}, function (data) {
  10621. $scope.distributes = data;
  10622. }, function (response) {
  10623. toaster.pop('error', '系统错误', response.data);
  10624. });
  10625. AuthenticationService.getAuthentication().success(function (data) {
  10626. $scope.loading = false;
  10627. $scope.user = data;
  10628. });
  10629. var users = [];
  10630. var getMangagerInfo = function() {
  10631. CurrentRole.isManager({}, function(data) {
  10632. $scope.isManager = data.isManager || $scope.user.sys;
  10633. });
  10634. CurrentRole.roles({}, function(data) {
  10635. $scope.roles = data.count || $scope.user.sys;
  10636. });
  10637. };
  10638. getMangagerInfo();
  10639. $scope.tableParams = new ngTableParams({
  10640. page: 1,
  10641. count: 20,
  10642. sorting: {
  10643. userName: 'asc'
  10644. }
  10645. }, {
  10646. total: 0,
  10647. counts: [15, 25, 50, 100],
  10648. getData: function ($defer, params) {
  10649. $scope.loading = true;
  10650. var pageParams = params.url();
  10651. pageParams.keyword = $scope.keyword;
  10652. $scope.tip = $scope.keyword;
  10653. AccountUser.getAll.call(null, BaseService.parseParams(pageParams), function (page) {
  10654. $scope.loading = false;
  10655. if (page) {
  10656. params.total(page.totalElement);
  10657. $defer.resolve(page.content);
  10658. users = page.content;
  10659. if(users.length > 0) {
  10660. if(users.length > 0) {
  10661. angular.forEach(users, function (user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  10662. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  10663. $scope.user.userIdcode = user.userIdcode;
  10664. }
  10665. });
  10666. }
  10667. }
  10668. }
  10669. }, function (response) {
  10670. $scope.loading = false;
  10671. toaster.pop('error', '数据加载失败', response.data);
  10672. });
  10673. }
  10674. });
  10675. $scope.onSearch = function(keyword) {
  10676. $scope.keyword = keyword;
  10677. $scope.tableParams.reload();
  10678. $scope.tableParams.page(1);
  10679. }
  10680. $scope.saveUser = function () {
  10681. $scope.loading = true;
  10682. AccountUser.update({}, $scope.user, function (data) {
  10683. $scope.loading = false;
  10684. toaster.pop('success', '提示', '修改用户信息成功');
  10685. AuthenticationService.getAuthentication().success(function (data) {
  10686. $scope.user = data;
  10687. });
  10688. loadUsers();
  10689. $scope.editing = false;
  10690. }, function (reponse) {
  10691. $scope.loading = false;
  10692. toaster.pop('error', '失败', reponse.data);
  10693. });
  10694. };
  10695. $scope.updatePassword = function () {
  10696. var newPage = window.open("about:black");
  10697. AccountUser.getUpdatePasswordUrl({returnUrl: window.location.href}, function (data) {
  10698. newPage.location.href = data.url;
  10699. });
  10700. };
  10701. $scope.updateDetail = function () {
  10702. var newPage = window.open("about:black");
  10703. AccountUser.getCloudCenterUrl({}, function (data) {
  10704. newPage.location.href = data.url;
  10705. });
  10706. }
  10707. $scope.newUser = {};
  10708. //弹出添加用户模态框
  10709. $scope.addExistUser = function () {
  10710. var modalInstance = $modal.open({
  10711. animation: true,
  10712. templateUrl: 'static/tpl/index/account/addExistUser.html',
  10713. controller: 'AddExistUserCtrl'
  10714. });
  10715. modalInstance.result.then(function () {
  10716. $scope.userTelSuccess = false;
  10717. $scope.userTelError = false;
  10718. $scope.tableParams.reload();
  10719. }, function () {
  10720. });
  10721. };
  10722. /**
  10723. * 添加未注册用户
  10724. */
  10725. $scope.submit = false;
  10726. $scope.addUser = function () {
  10727. $scope.submit = true;
  10728. $scope.adding = true;
  10729. $scope.loading = true;
  10730. AccountUser.save({}, $scope.newUser, function (data) {
  10731. $scope.loading = false;
  10732. $scope.submit = false;
  10733. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  10734. $scope.newUser = {userSex: 'M'};
  10735. $scope.tableParams.reload();
  10736. $scope.adding = false;
  10737. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10738. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10739. $scope.userTelSuccess = false;
  10740. $scope.userTelError = false;
  10741. $scope.userEmailSuccess = false;
  10742. $scope.userEmailError = false;
  10743. }, function (response) {
  10744. $scope.submit = false;
  10745. $scope.loading = false;
  10746. toaster.pop('error', '错误', response.data);
  10747. });
  10748. };
  10749. /**
  10750. * 验证手机号是否可用
  10751. */
  10752. $scope.telValid = function (tel) {
  10753. if (tel) {
  10754. $http.get('account/user/telEnable', {
  10755. params: {
  10756. tel: tel
  10757. }
  10758. }).success(function (data) {
  10759. data = eval(data);
  10760. if (data == true) {
  10761. $scope.newUserForm.newUserTel.$setValidity('available', true);
  10762. $scope.userTelSuccess = true;
  10763. $scope.userTelError = false;
  10764. } else {
  10765. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10766. $scope.userTelError = true;
  10767. $scope.userTelSuccess = false;
  10768. if (tel.length == 11)
  10769. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  10770. }
  10771. }).error(function () {
  10772. $scope.userTelSuccess = false;
  10773. $scope.userTelError = true;
  10774. });
  10775. } else {
  10776. $scope.userTelSuccess = false;
  10777. $scope.userTelError = false;
  10778. }
  10779. };
  10780. /**
  10781. * 验证邮箱是否可用
  10782. */
  10783. $scope.emailValid = function (email) {
  10784. if (email) {
  10785. $http.get('account/user/emailEnable', {
  10786. params: {
  10787. email: email
  10788. }
  10789. }).success(function (data) {
  10790. data = eval(data);
  10791. if (data == true) {
  10792. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  10793. $scope.userEmailSuccess = true;
  10794. $scope.userEmailError = false;
  10795. } else {
  10796. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10797. $scope.userEmailError = true;
  10798. $scope.userEmailSuccess = false;
  10799. }
  10800. }).error(function () {
  10801. $scope.userEmailError = true;
  10802. $scope.userEmailSuccess = false;
  10803. });
  10804. } else {
  10805. $scope.userEmailError = false;
  10806. $scope.userEmailSuccess = false;
  10807. }
  10808. };
  10809. /**
  10810. * 删除用户
  10811. */
  10812. $scope.removeUser = function (user) {
  10813. new ngAlert({
  10814. title: '提示',
  10815. content: '确定删除用户(' + user.userName + ')吗?'
  10816. }, function () {
  10817. AccountUser.remove({uu: user.userUU}, function () {
  10818. toaster.pop('success', '提示', '用户删除成功。');
  10819. loadUsers();
  10820. }, function (response) {
  10821. toaster.pop('error', '删除失败', response.data);
  10822. });
  10823. });
  10824. };
  10825. // 编辑用户的角色
  10826. $scope.editUserRole = function (user) {
  10827. var modalInstance = $modal.open({
  10828. animation: true,
  10829. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  10830. controller: 'UserRoleCtrl',
  10831. resolve: {
  10832. user: function () {
  10833. return user;
  10834. }
  10835. }
  10836. });
  10837. modalInstance.result.then(function (changed, checked) {
  10838. if (changed) {
  10839. if (checked)
  10840. $scope.newUser.roles = checked;
  10841. else
  10842. loadUsers();
  10843. }
  10844. });
  10845. };
  10846. // 为用户分配角色(删除企业)
  10847. $scope.removeVendor = function (user) {
  10848. var resultRole = true;
  10849. angular.forEach(user.roles, function (role) {
  10850. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10851. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10852. resultRole = false;
  10853. return;
  10854. }
  10855. });
  10856. if (resultRole) {
  10857. var modalInstance = $modal.open({
  10858. animation: true,
  10859. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  10860. controller: 'RemoveVendorCtrl',
  10861. resolve: {
  10862. user: function () {
  10863. return user;
  10864. }
  10865. }
  10866. });
  10867. }
  10868. };
  10869. // 为用户分配角色(添加企业)
  10870. $scope.addVendor = function (user, isIssy) {
  10871. if (!$scope.roles) {
  10872. toaster.pop('error', '提示', '你不是管理员或销售经理,无权限分配!请立即联系管理员');
  10873. return;
  10874. }
  10875. var resultRole = true;
  10876. angular.forEach(user.roles, function (role) {
  10877. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10878. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10879. resultRole = false;
  10880. return;
  10881. }
  10882. })
  10883. if (resultRole) {
  10884. var modalInstance = $modal.open({
  10885. animation: true,
  10886. templateUrl: 'static/tpl/index/account/add_vendor.html',
  10887. controller: 'AddVendorCtrl',
  10888. resolve: {
  10889. user: function () {
  10890. return user;
  10891. }
  10892. }
  10893. });
  10894. modalInstance.result.then(function (changed, checked) {
  10895. if (changed) {
  10896. if (checked)
  10897. $scope.newUser.roles = checked;
  10898. else
  10899. loadUsers();
  10900. }
  10901. });
  10902. }
  10903. };
  10904. }]);
  10905. // 登录手机号码验证
  10906. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function ($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout) {
  10907. $scope.user = user;
  10908. $scope.cancel = function () {
  10909. $modalInstance.close();
  10910. }
  10911. }]);
  10912. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10913. $scope.checkboxes = {
  10914. checked: false
  10915. };
  10916. $scope.loading = true;
  10917. AccountUser.findChooseVendor({uu: user.userUU}, function (data) {
  10918. $scope.enters = data;
  10919. $scope.loading = false;
  10920. angular.forEach($scope.enters, function (item) {
  10921. item:{
  10922. $selected:true;
  10923. }
  10924. });
  10925. })
  10926. // 点击勾选全部的复选框
  10927. $scope.checkAll = function () {
  10928. angular.forEach($scope.enters, function (item) {
  10929. item.$selected = $scope.checkboxes.checked;
  10930. });
  10931. };
  10932. // 点击其中一个明细的复选框
  10933. $scope.checkOne = function (vendor) {
  10934. var result = true;
  10935. angular.forEach($scope.enters, function (item) {
  10936. if (item.$selected != true) {
  10937. result = false;
  10938. return;
  10939. }
  10940. });
  10941. $scope.checkboxes.checked = result;
  10942. };
  10943. $scope.close = function (save) {
  10944. var chooseResult = [];
  10945. if (save) {
  10946. if (user.userUU) {
  10947. angular.forEach($scope.enters, function (item, i) {
  10948. if (item.$selected) {
  10949. chooseResult.push(item.id);
  10950. }
  10951. });
  10952. if (chooseResult.length > 0) {
  10953. $scope.loading = true;
  10954. AccountUser.removeChooseVendor({uu: user.userUU}, chooseResult, function (data) {
  10955. $scope.loading = false;
  10956. toaster.pop('success', '提示', '删除成功');
  10957. $modalInstance.close(false);
  10958. }, function (response) {
  10959. $scope.loading = false;
  10960. toaster.pop('error', '删除失败', response.data);
  10961. $modalInstance.close(false);
  10962. })
  10963. } else {
  10964. toaster.pop('error', '删除失败', "您未勾选任何记录");
  10965. }
  10966. } else {
  10967. $modalInstance.close(true, $scope.checkboxes.checked);
  10968. }
  10969. } else {
  10970. $modalInstance.close(false);
  10971. }
  10972. };
  10973. }]);
  10974. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10975. $scope.checkboxes = {
  10976. checked: false
  10977. };
  10978. $scope.loading = true;
  10979. AccountUser.findVendor({uu: user.userUU}, function (data) {
  10980. $scope.enters = data;
  10981. $scope.loading = false;
  10982. })
  10983. // 点击勾选全部的复选框
  10984. $scope.checkAll = function () {
  10985. angular.forEach($scope.enters, function (item) {
  10986. item.distribute = $scope.checkboxes.checked;
  10987. });
  10988. };
  10989. // 点击其中一个明细的复选框
  10990. $scope.checkOne = function (vendor) {
  10991. var result = true;
  10992. angular.forEach($scope.enters, function (item) {
  10993. if (item.distribute != true) {
  10994. result = false;
  10995. return;
  10996. }
  10997. });
  10998. $scope.checkboxes.checked = result;
  10999. };
  11000. $scope.close = function (save) {
  11001. var chooseResult = [];
  11002. if (save) {
  11003. if (user.userUU) {
  11004. angular.forEach($scope.enters, function (item, i) {
  11005. chooseResult.push(item);
  11006. });
  11007. if (chooseResult.length > 0) {
  11008. $scope.loading = true;
  11009. AccountUser.addVendor({uu: user.userUU}, chooseResult, function (data) {
  11010. $scope.loading = false;
  11011. toaster.pop('success', '提示', '保存成功');
  11012. $modalInstance.close(false);
  11013. }, function (response) {
  11014. $scope.loading = false;
  11015. toaster.pop('error', '保存失败', response.data);
  11016. $modalInstance.close(false);
  11017. })
  11018. } else {
  11019. toaster.pop('error', '保存失败', "您未勾选任何记录");
  11020. }
  11021. } else {
  11022. $modalInstance.close(true, $scope.checkboxes.checked);
  11023. }
  11024. } else {
  11025. $modalInstance.close(false);
  11026. }
  11027. };
  11028. }]);
  11029. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountRole, AccountUser, toaster) {
  11030. $scope.checked = [];
  11031. $scope.master = [];
  11032. AccountRole.query({}, function (data) {
  11033. if (user && data) {
  11034. var rs = [], checked = [];
  11035. angular.forEach(user.roles, function (r) {
  11036. rs.push(r.id);
  11037. });
  11038. angular.forEach(data, function (d) {
  11039. if (rs.indexOf(d.id) > -1) {
  11040. d.$checked = true;
  11041. checked.push(d);
  11042. }
  11043. });
  11044. }
  11045. $scope.roles = data;
  11046. $scope.checked = checked;
  11047. $scope.master = angular.copy($scope.checked);
  11048. });
  11049. $scope.select = function (role) {
  11050. role.$checked = !role.$checked;
  11051. if (role.$checked) {
  11052. if (role.desc === '管理员' || role.desc === '普通用户') {
  11053. $scope.checked = [];
  11054. angular.forEach($scope.roles, function (r) {
  11055. r.$checked = false;
  11056. });
  11057. role.$checked = true;
  11058. $scope.checked.push(role);
  11059. } else {
  11060. angular.forEach( $scope.checked, function (r, i) {
  11061. if (r.desc === '管理员' || r.desc === '普通用户') {
  11062. $scope.checked.splice(i, 1);
  11063. }
  11064. });
  11065. angular.forEach($scope.roles, function (r) {
  11066. if (r.desc === '管理员' || r.desc === '普通用户') {
  11067. r.$checked = false;
  11068. }
  11069. });
  11070. $scope.checked.push(role);
  11071. }
  11072. } else {
  11073. angular.forEach($scope.checked, function (c, i) {
  11074. if (c.id == role.id)
  11075. $scope.checked.splice(i, 1);
  11076. });
  11077. }
  11078. };
  11079. $scope.isChanged = function () {
  11080. return !angular.equals($scope.master, $scope.checked);
  11081. };
  11082. $scope.close = function (save) {
  11083. if (save) {
  11084. if (user.userUU) {
  11085. user.roles = $scope.checked;
  11086. AccountUser.updateRole({}, user, function () {
  11087. toaster.pop('success', '提示', '保存成功');
  11088. $modalInstance.close(true);
  11089. }, function (response) {
  11090. toaster.pop('error', '保存失败', response.data);
  11091. });
  11092. } else {
  11093. $modalInstance.close(true, $scope.checked);
  11094. }
  11095. } else {
  11096. $modalInstance.close(false);
  11097. }
  11098. };
  11099. }]);
  11100. // 修改密码Controller
  11101. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  11102. $scope.user = user;
  11103. $scope.checking = false;
  11104. //输入原密码后验证原密码是否正确
  11105. $scope.checkPassword = function (password) {
  11106. $scope.checking = true;
  11107. $scope.checkSuccess = false;
  11108. $scope.checkFailed = false;
  11109. AccountUser.checkPassword({password: password}, function (data) {
  11110. $scope.checkSuccess = true;
  11111. $scope.checking = false;
  11112. $scope.checkFailed = false;
  11113. }, function (response) {
  11114. $scope.checkFailed = true;
  11115. $scope.checking = false;
  11116. $scope.checkSuccess = false;
  11117. });
  11118. };
  11119. //修改密码
  11120. $scope.ok = function () {
  11121. if ($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  11122. AccountUser.updatePassword({
  11123. password: $scope.user.password,
  11124. newPassword: $scope.user.newPassword
  11125. }, {}, function (data) {
  11126. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  11127. toaster.pop('success', '成功', tip);
  11128. $scope.user.password = null;
  11129. $scope.user.newPassword = null;
  11130. $scope.user.newPassword1 = null;
  11131. $scope.checking = false;
  11132. $scope.checkSuccess = false;
  11133. $scope.checkFailed = false;
  11134. $modalInstance.close();
  11135. }, function (response) {
  11136. toaster.pop('error', '错误', response.data);
  11137. });
  11138. } else {
  11139. toaster.pop('error', '错误', '重复密码不一致');
  11140. }
  11141. };
  11142. $scope.cancel = function () {
  11143. $modalInstance.dismiss();
  11144. };
  11145. }]);
  11146. /*
  11147. * 绑定用户到企业
  11148. */
  11149. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function ($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster) {
  11150. $scope.searching = false;
  11151. //根据输入的内容查找用户
  11152. $scope.searchUser = function (keyWord) {
  11153. $scope.searching = true;
  11154. $scope.searchSuccess = false;
  11155. $scope.searchFailed = false;
  11156. $scope.illegalError = false;
  11157. $scope.reBindError = false;
  11158. $scope.okDisabled = false;
  11159. FuzzySearch.searchUser({keyWord: keyWord}, function (data) {
  11160. $scope.searchSuccess = true;
  11161. $scope.searchFailed = false;
  11162. $scope.user = data; //查询到的用户
  11163. }, function (response) {
  11164. $scope.searchSuccess = false;
  11165. $scope.searchFailed = true;
  11166. });
  11167. };
  11168. //确认绑定
  11169. $scope.ok = function (keyWord) {
  11170. AuthenticationService.getAuthentication().success(function (data) {
  11171. $scope.currentUser = data; //当前登录的用户(管理员)
  11172. //不可自己绑定自己
  11173. if ($scope.currentUser.userUU == $scope.user.userUU) {
  11174. $scope.illegalError = true;
  11175. $scope.okDisabled = true;
  11176. return false;
  11177. }
  11178. //用户未绑定到任何企业时
  11179. if (!$scope.user.enterprises) {
  11180. //正常绑定
  11181. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  11182. $scope.okDisabled = true;
  11183. toaster.pop("success", "提示", "用户绑定成功");
  11184. $modalInstance.close(true);
  11185. }, function (response) {
  11186. });
  11187. return true;
  11188. }
  11189. //用户已绑定到某些企业时
  11190. for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
  11191. if ($scope.currentUser.enterprises[i].current) {
  11192. for (var j = 0; j < $scope.user.enterprises.length; j++) {
  11193. //该用户已绑定到当前企业,不可重复绑定
  11194. if ($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu) {
  11195. $scope.reBindError = true;
  11196. $scope.okDisabled = true;
  11197. return false;
  11198. }
  11199. }
  11200. //该用户未绑定到当前企业,可以进行绑定
  11201. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  11202. $scope.okDisabled = true;
  11203. toaster.pop("success", "提示", "用户绑定成功");
  11204. $modalInstance.close(true);
  11205. }, function (response) {
  11206. console.log("绑定失败!");
  11207. });
  11208. }
  11209. }
  11210. });
  11211. };
  11212. $scope.cancel = function () {
  11213. $modalInstance.dismiss();
  11214. };
  11215. }]);
  11216. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function ($scope, BaseService, ngTableParams, ErpLog, UsageLog) {
  11217. $scope.erpParams = new ngTableParams({
  11218. page: 1,
  11219. count: 20,
  11220. sorting: {
  11221. time: 'desc'
  11222. }
  11223. }, {
  11224. total: 0,
  11225. counts: [5, 10, 25, 50],
  11226. getData: function ($defer, params) {
  11227. $scope.loading = true;
  11228. ErpLog.get(BaseService.parseParams(params.url()), function (page) {
  11229. $scope.loading = false;
  11230. if (page) {
  11231. params.total(page.totalElements);
  11232. $defer.resolve(page.content);
  11233. }
  11234. }, function (response) {
  11235. $scope.loading = false;
  11236. toaster.pop('error', '数据加载失败', response.data);
  11237. });
  11238. }
  11239. });
  11240. $scope.usageParams = new ngTableParams({
  11241. page: 1,
  11242. count: 20,
  11243. sorting: {
  11244. time: 'desc'
  11245. }
  11246. }, {
  11247. total: 0,
  11248. counts: [5, 10, 25, 50],
  11249. getData: function ($defer, params) {
  11250. $scope.loading = true;
  11251. UsageLog.get(BaseService.parseParams(params.url()), function (page) {
  11252. $scope.loading = false;
  11253. if (page) {
  11254. params.total(page.totalElements);
  11255. $defer.resolve(page.content);
  11256. }
  11257. }, function (response) {
  11258. $scope.loading = false;
  11259. toaster.pop('error', '数据加载失败', response.data);
  11260. });
  11261. }
  11262. });
  11263. }]);
  11264. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function ($scope, AccountResource) {
  11265. AccountResource.query({}, function (data) {
  11266. if (data && data.length > 0) {
  11267. data[0].$open = true;
  11268. }
  11269. $scope.resources = data;
  11270. });
  11271. }]);
  11272. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function ($scope, $modal, AccountRole) {
  11273. $scope.roles = {};
  11274. var getData = function () {
  11275. AccountRole.query({}, function (data) {
  11276. var defaults = [], custom = [];
  11277. angular.forEach(data, function (d) {
  11278. if (d.isdefault == 1)
  11279. defaults.push(d);
  11280. else
  11281. custom.push(d);
  11282. });
  11283. $scope.roles = {defaults: defaults, custom: custom};
  11284. });
  11285. };
  11286. getData();
  11287. $scope.editRole = function (role) {
  11288. var modalInstance = $modal.open({
  11289. animation: true,
  11290. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  11291. controller: 'RoleEditCtrl',
  11292. resolve: {
  11293. role: function () {
  11294. return role;
  11295. }
  11296. }
  11297. });
  11298. modalInstance.result.then(function (added) {
  11299. added && (getData());
  11300. });
  11301. };
  11302. }]);
  11303. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', 'CurrentRole', 'AuthenticationService', function ($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService, CurrentRole, AuthenticationService) {
  11304. BaseService.scrollBackToTop();
  11305. // 获取当前用户是否为管理员
  11306. AuthenticationService.getAuthentication().success(function (data) {
  11307. $scope.loading = false;
  11308. $scope.user = data;
  11309. });
  11310. CurrentRole.isManager({}, {}, function (data) {
  11311. $scope.isManager = data.isManager || $scope.user.sys;
  11312. });
  11313. $scope.role = role;
  11314. $scope.master = angular.copy($scope.role);
  11315. var isNew = role == null;
  11316. $scope.cancel = function () {
  11317. $modalInstance.close(false);
  11318. };
  11319. AccountResource.query({}, function (data) {
  11320. if (data && data.length > 0) {
  11321. if (role && role.resourceItems) {
  11322. var rs = [];// 已分配的资源的id
  11323. angular.forEach(role.resourceItems, function (item) {
  11324. rs.push(item.id);
  11325. });
  11326. angular.forEach(data, function (resource) {
  11327. var c = 0;
  11328. angular.forEach(resource.items, function (item) {
  11329. if (rs.indexOf(item.id) > -1) {
  11330. item.$checked = true;
  11331. c += 1;
  11332. }
  11333. });
  11334. resource.$checked = c == resource.items.length;
  11335. });
  11336. }
  11337. $scope.resourceItems = data[0].items;
  11338. data[0].$active = true;
  11339. }
  11340. $scope.resources = data;
  11341. $timeout(function () {
  11342. angular.forEach($scope.resources, function (resource) {
  11343. var c = 0;
  11344. angular.forEach(resource.items, function (item) {
  11345. item.$checked && (c += 1);
  11346. });
  11347. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  11348. });
  11349. }, 100);
  11350. });
  11351. $scope.onItemClick = function (resource) {
  11352. $scope.resourceItems = resource.items;
  11353. angular.forEach($scope.resources, function (r) {
  11354. r.$active = false;
  11355. });
  11356. resource.$active = true;
  11357. };
  11358. var getChecked = function () {
  11359. var items = [];
  11360. angular.forEach($scope.resources, function (resource) {
  11361. angular.forEach(resource.items, function (item) {
  11362. item.$checked && (items.push(item));
  11363. });
  11364. });
  11365. $scope.role.resourceItems = items;
  11366. };
  11367. $scope.onResourceChange = function (resource) {
  11368. angular.forEach(resource.items, function (item) {
  11369. item.$checked = resource.$checked;
  11370. });
  11371. getChecked();
  11372. };
  11373. $scope.onItemChange = function () {
  11374. angular.forEach($scope.resources, function (resource) {
  11375. if (resource.$active) {
  11376. var c = 0;
  11377. angular.forEach(resource.items, function (item) {
  11378. item.$checked && (c += 1);
  11379. });
  11380. resource.$checked = (c == resource.items.length);
  11381. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  11382. }
  11383. });
  11384. getChecked();
  11385. };
  11386. $scope.isChanged = function (formData) {
  11387. if (!$scope.master)
  11388. return true;
  11389. return !angular.equals(formData, $scope.master);
  11390. };
  11391. $scope.save = function () {
  11392. $scope.master = angular.copy($scope.role);
  11393. AccountRole.save($scope.master, function () {
  11394. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
  11395. $modalInstance.close(true);
  11396. }, function (response) {
  11397. toaster.pop('error', '错误', response.data);
  11398. });
  11399. };
  11400. $scope.del = function () {
  11401. new ngAlert({
  11402. title: '提示',
  11403. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  11404. }, function () {
  11405. AccountRole.remove({id: role.id}, {}, function () {
  11406. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  11407. $modalInstance.close(true);
  11408. }, function (response) {
  11409. toaster.pop('error', '错误', response.data);
  11410. });
  11411. })
  11412. };
  11413. $scope.updateDefault = function () {
  11414. new ngAlert({
  11415. title: '提示',
  11416. content: '确定把(' + $scope.role.desc + ')信息更新到标准库吗?'
  11417. }, function () {
  11418. AccountRole.updateDefault({desc: $scope.role.desc}, $scope.role.resourceItems, function () {
  11419. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 更新成功');
  11420. $modalInstance.close(true);
  11421. }, function (response) {
  11422. toaster.pop('error', '错误', response.data);
  11423. });
  11424. })
  11425. }
  11426. $scope.recover = function () {
  11427. new ngAlert({
  11428. title: '提示',
  11429. content: '确定将“' + $scope.role.desc + '”恢复默认权限吗?'
  11430. }, function () {
  11431. AccountRole.recover({roleId: role.id}, {}, function () {
  11432. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 恢复默认权限成功');
  11433. $modalInstance.close(true);
  11434. }, function (response) {
  11435. toaster.pop('error', '错误', response.data);
  11436. });
  11437. })
  11438. };
  11439. }]);
  11440. /**
  11441. * 委外订单
  11442. */
  11443. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole',
  11444. function ($scope, $filter, MakeOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  11445. BaseService.scrollBackToTop();
  11446. // 获取当前用户是否为普通用户
  11447. CurrentRole.isUser({}, {}, function (data) {
  11448. $scope.isUser = data.isUser;
  11449. });
  11450. $scope.active = 'todo';
  11451. $scope.dateZoneText = '不限';
  11452. $scope.condition = {dateZone: 1};
  11453. /* 时间筛选初始化*/
  11454. var fromDate = new Date();
  11455. var toDate = new Date();
  11456. fromDate.setMonth(fromDate.getMonth() - 1);
  11457. fromDate.setHours(0, 0, 0, 0);
  11458. toDate.setHours(23, 59, 59, 999);
  11459. $scope.condition.dateFrom = fromDate;
  11460. $scope.condition.dateTo = toDate;
  11461. $scope.changeDateZone = function (zone) {
  11462. $scope.condition.dateZone = zone;
  11463. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11464. $scope.condition.$dateZoneOpen = false;
  11465. getDateCondition(zone, $scope.condition);
  11466. $scope.tableParams.page(1);
  11467. $scope.tableParams.reload();
  11468. };
  11469. $scope.setActive = function (state) {
  11470. if ($scope.active != state) {
  11471. $scope.active = state;
  11472. if ($scope.tableParams.page() == 1)
  11473. $scope.tableParams.reload();
  11474. else
  11475. $scope.tableParams.page(1);
  11476. }
  11477. };
  11478. var getService = function () {
  11479. return MakeOrder;
  11480. };
  11481. $scope.tableParams = new ngTableParams({
  11482. page: 1,
  11483. count: 20,
  11484. sorting: {
  11485. date: 'desc'
  11486. }
  11487. }, {
  11488. total: 0,
  11489. counts: [5, 10, 25, 50],
  11490. getData: function ($defer, params) {
  11491. $scope.loading = true;
  11492. var pageParams = params.url();
  11493. pageParams.searchFilter = {
  11494. keyword: $scope.keyword,
  11495. fromDate: getDateTime($scope.condition.dateFrom),
  11496. endDate: getDateTime($scope.condition.dateTo)
  11497. };
  11498. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11499. $scope.loading = false;
  11500. if (page) {
  11501. params.total(page.totalElement);
  11502. $defer.resolve(page.content);
  11503. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11504. }
  11505. }, function (response) {
  11506. $scope.loading = false;
  11507. toaster.pop('error', '数据加载失败', response.data);
  11508. });
  11509. }
  11510. });
  11511. //获得各分类未阅读数量
  11512. var getUnreadCount = function () {
  11513. MakeOrder.getUnreadCount(null, function (data) {
  11514. $scope.unread = data;
  11515. });
  11516. };
  11517. getUnreadCount();
  11518. //设置单据已读
  11519. $scope.setOrdersRead = function (id) {
  11520. // 如果单据本身已读,则不发送请求修改数据
  11521. if (!$scope.isUnread(id)){
  11522. return;
  11523. }
  11524. var sourceId = [];
  11525. sourceId.push(id);
  11526. MakeOrder.setRead({}, sourceId, function (message) {
  11527. // $scope.getUnreadIds();
  11528. getUnreadCount();
  11529. });
  11530. };
  11531. $scope.setOrdersReadByState = function () {
  11532. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  11533. return;
  11534. }
  11535. MakeOrder.setReadByState({}, function () {
  11536. getUnreadIds();
  11537. getUnreadCount();
  11538. });
  11539. };
  11540. var getUnreadIds = function () {
  11541. MakeOrder.getUnreadIds({}, "", function (message) {
  11542. $scope.unreadCode = message.content;
  11543. });
  11544. };
  11545. getUnreadIds();
  11546. $scope.isUnread = function (id) {
  11547. for (var i in $scope.unreadCode) {
  11548. if (id == $scope.unreadCode[i]) {
  11549. return true;
  11550. }
  11551. }
  11552. };
  11553. $scope.getOrderTotal = function (items) {
  11554. var sum = 0;
  11555. angular.forEach(items, function (item) {
  11556. sum += item.qty * item.price;
  11557. });
  11558. return sum;
  11559. };
  11560. $scope.openDatePicker = function ($event, item, openParam) {
  11561. $event.preventDefault();
  11562. $event.stopPropagation();
  11563. item[openParam] = !item[openParam];
  11564. };
  11565. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11566. $event.preventDefault();
  11567. $event.stopPropagation();
  11568. item[openParam] = !item[openParam];
  11569. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11570. $scope.tableParams.reload();
  11571. }
  11572. };
  11573. $scope.parseDate = function (dateStr) {
  11574. if (dateStr)
  11575. return Date.parse(dateStr, 'yyyy-MM-dd');
  11576. return new Date();
  11577. };
  11578. // 打开回复
  11579. $scope.openReply = function (order) {
  11580. if (!order.reply) {
  11581. order.reply = {
  11582. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11583. delivery: order.delivery
  11584. }
  11585. }
  11586. order.$editing = true;
  11587. };
  11588. // 关闭回复
  11589. $scope.closeReply = function (order) {
  11590. order.$editing = false;
  11591. }
  11592. // 搜索框回车
  11593. $scope.onSearch = function () {
  11594. $scope.tableParams.page(1);
  11595. $scope.tableParams.reload();
  11596. };
  11597. // 选择查找日期
  11598. $scope.onDateCondition = function () {
  11599. $scope.tableParams.page(1);
  11600. $scope.tableParams.reload();
  11601. };
  11602. // 点击回复
  11603. $scope.onReplyClick = function (order, inverse) {
  11604. if (order.reply) {
  11605. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11606. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11607. return;
  11608. }
  11609. var reply = angular.copy(order.reply);
  11610. if (reply.delivery) {
  11611. if (typeof reply.delivery == 'object')
  11612. reply.delivery = reply.delivery.getTime();
  11613. } else {
  11614. reply.delivery = order.delivery;
  11615. }
  11616. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11617. $scope.loading = true;
  11618. MakeOrder.reply({orderId: order.id}, reply, function () {
  11619. $scope.loading = false;
  11620. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11621. $scope.tableParams.reload();
  11622. }, function (response) {
  11623. $scope.loading = false;
  11624. toaster.pop('error', '回复失败', response.data);
  11625. });
  11626. }
  11627. };
  11628. //委外加工单
  11629. $scope.print = function (order) {
  11630. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11631. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  11632. };
  11633. // 获取回复记录
  11634. $scope.getReply = function (order) {
  11635. if (!order.replies) {
  11636. MakeOrder.getReply({orderId: order.id}, function (replies) {
  11637. order.replies = replies;
  11638. });
  11639. }
  11640. };
  11641. // 导出
  11642. $scope.exportXls = function () {
  11643. MakeOrder.exportXls({}, {}, function (data) {
  11644. if (data.success){
  11645. window.location.href = 'make/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11646. }
  11647. }, function (response) {
  11648. toaster.pop('error', '数据加载失败', response.data);
  11649. });
  11650. }
  11651. }]);
  11652. /**
  11653. * 委外加工单详细
  11654. */
  11655. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService, CurrentRole) {
  11656. BaseService.scrollBackToTop();
  11657. // 获取当前用户是否为普通用户
  11658. CurrentRole.isUser({}, {}, function (data) {
  11659. $scope.isUser = data.isUser;
  11660. });
  11661. var loadData = function () {
  11662. MakeOrder.getItem({id: $stateParams.id}, function (data) {
  11663. $scope.order = data;
  11664. var sum = $scope.order.qty * $scope.order.price;
  11665. $scope.order.total = sum;
  11666. $scope.loading = false;
  11667. }, function (response) {
  11668. toaster.pop('error', '', response.data);
  11669. });
  11670. };
  11671. loadData();
  11672. // 获取回复记录
  11673. $scope.getReply = function (item) {
  11674. if (!item.replies) {
  11675. MakeOrder.getReply({orderId: item.id}, function (replies) {
  11676. item.replies = replies;
  11677. });
  11678. }
  11679. };
  11680. $scope.openDatePicker = function ($event, item, openParam) {
  11681. $event.preventDefault();
  11682. $event.stopPropagation();
  11683. item[openParam] = !item[openParam];
  11684. };
  11685. // 点击回复
  11686. $scope.onReplyClick = function (order, inverse) {
  11687. if (order.reply) {
  11688. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11689. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11690. return;
  11691. }
  11692. var reply = angular.copy(order.reply);
  11693. if (reply.delivery) {
  11694. if (typeof reply.delivery == 'object')
  11695. reply.delivery = reply.delivery.getTime();
  11696. } else {
  11697. reply.delivery = order.delivery;
  11698. }
  11699. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11700. $scope.loading = true;
  11701. MakeOrder.reply({orderId: order.id}, reply, function () {
  11702. $scope.loading = false;
  11703. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11704. loadData();
  11705. }, function (response) {
  11706. $scope.loading = false;
  11707. toaster.pop('error', '回复失败', response.data);
  11708. });
  11709. }
  11710. };
  11711. // 打开回复
  11712. $scope.openReply = function (order) {
  11713. if (!order.reply) {
  11714. order.reply = {
  11715. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11716. delivery: order.delivery
  11717. }
  11718. }
  11719. order.$editing = true;
  11720. };
  11721. // 关闭回复
  11722. $scope.closeReply = function (order) {
  11723. order.$editing = false;
  11724. }
  11725. // 委外订单
  11726. $scope.print = function (order) {
  11727. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11728. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  11729. };
  11730. }]);
  11731. /**
  11732. * 客户委外验收
  11733. */
  11734. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11735. BaseService.scrollBackToTop();
  11736. // 获取当前用户是否为普通用户
  11737. CurrentRole.isUser({}, {}, function (data) {
  11738. $scope.isUser = data.isUser;
  11739. });
  11740. $scope.active = 'all';
  11741. $scope.agreedText = '全部';
  11742. $scope.dateZoneText = '一个月内';
  11743. $scope.condition = {dateZone: 1};
  11744. /* 时间筛选初始化*/
  11745. var fromDate = new Date();
  11746. var toDate = new Date();
  11747. fromDate.setMonth(fromDate.getMonth() - 1);
  11748. fromDate.setHours(0, 0, 0, 0);
  11749. toDate.setHours(23, 59, 59, 999);
  11750. $scope.condition.dateFrom = fromDate;
  11751. $scope.condition.dateTo = toDate;
  11752. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11753. $scope.changeAgreed = function (agreed) {
  11754. $scope.condition.agreed = agreed;
  11755. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11756. $scope.condition.$agreedOpen = false;
  11757. };
  11758. $scope.changeDateZone = function (zone) {
  11759. $scope.condition.dateZone = zone;
  11760. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11761. $scope.condition.$dateZoneOpen = false;
  11762. getDateCondition(zone, $scope.condition);
  11763. $scope.tableParams.page(1);
  11764. $scope.tableParams.reload();
  11765. };
  11766. $scope.setActive = function (state) {
  11767. if ($scope.active != state) {
  11768. $scope.active = state;
  11769. if ($scope.tableParams.page() == 1)
  11770. $scope.tableParams.reload();
  11771. else
  11772. $scope.tableParams.page(1);
  11773. }
  11774. };
  11775. var getService = function () {
  11776. return MakeAccept;
  11777. };
  11778. $scope.tableParams = new ngTableParams({
  11779. page: 1,
  11780. count: 20,
  11781. sorting: {
  11782. date: 'desc'
  11783. }
  11784. }, {
  11785. total: 0,
  11786. counts: [5, 10, 25, 50],
  11787. getData: function ($defer, params) {
  11788. $scope.loading = true;
  11789. var pageParams = params.url();
  11790. pageParams.searchFilter = {};
  11791. pageParams.searchFilter.keyword = $scope.keyword;
  11792. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11793. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11794. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11795. $scope.loading = false;
  11796. if (page) {
  11797. params.total(page.totalElement);
  11798. $defer.resolve(page.content);
  11799. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11800. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11801. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11802. }
  11803. }, function (response) {
  11804. $scope.loading = false;
  11805. toaster.pop('error', '数据加载失败', response.data);
  11806. });
  11807. }
  11808. });
  11809. $scope.openDatePicker = function ($event, item, openParam) {
  11810. $event.preventDefault();
  11811. $event.stopPropagation();
  11812. item[openParam] = !item[openParam];
  11813. };
  11814. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11815. $event.preventDefault();
  11816. $event.stopPropagation();
  11817. item[openParam] = !item[openParam];
  11818. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11819. $scope.tableParams.reload();
  11820. }
  11821. };
  11822. // 搜索框回车
  11823. $scope.onSearch = function () {
  11824. $scope.tableParams.page(1);
  11825. $scope.tableParams.reload();
  11826. };
  11827. // 选择查找日期
  11828. $scope.onDateCondition = function () {
  11829. $scope.tableParams.page(1);
  11830. $scope.tableParams.reload();
  11831. };
  11832. // 导出
  11833. $scope.exportXls = function () {
  11834. MakeAccept.exportXls({}, {}, function (data) {
  11835. if (data.success){
  11836. window.location.href = 'make/accept/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11837. }
  11838. }, function (response) {
  11839. toaster.pop('error', '数据加载失败', response.data);
  11840. });
  11841. }
  11842. }]);
  11843. /**
  11844. * 客户委外验退
  11845. */
  11846. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11847. BaseService.scrollBackToTop();
  11848. // 获取当前用户是否为普通用户
  11849. CurrentRole.isUser({}, {}, function (data) {
  11850. $scope.isUser = data.isUser;
  11851. });
  11852. $scope.active = 'all';
  11853. $scope.agreedText = '全部';
  11854. $scope.dateZoneText = '一个月内';
  11855. $scope.condition = {dateZone: 1};
  11856. /* 时间筛选初始化*/
  11857. var fromDate = new Date();
  11858. var toDate = new Date();
  11859. fromDate.setMonth(fromDate.getMonth() - 1);
  11860. fromDate.setHours(0, 0, 0, 0);
  11861. toDate.setHours(23, 59, 59, 999);
  11862. $scope.condition.dateFrom = fromDate;
  11863. $scope.condition.dateTo = toDate;
  11864. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11865. $scope.changeAgreed = function (agreed) {
  11866. $scope.condition.agreed = agreed;
  11867. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11868. $scope.condition.$agreedOpen = false;
  11869. };
  11870. $scope.changeDateZone = function (zone) {
  11871. $scope.condition.dateZone = zone;
  11872. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11873. $scope.condition.$dateZoneOpen = false;
  11874. getDateCondition(zone, $scope.condition);
  11875. $scope.tableParams.page(1);
  11876. $scope.tableParams.reload();
  11877. };
  11878. $scope.setActive = function (state) {
  11879. if ($scope.active != state) {
  11880. $scope.active = state;
  11881. if ($scope.tableParams.page() == 1)
  11882. $scope.tableParams.reload();
  11883. else
  11884. $scope.tableParams.page(1);
  11885. }
  11886. };
  11887. var getService = function () {
  11888. return MakeReturn;
  11889. };
  11890. $scope.tableParams = new ngTableParams({
  11891. page: 1,
  11892. count: 20,
  11893. sorting: {
  11894. date: 'desc'
  11895. }
  11896. }, {
  11897. total: 0,
  11898. counts: [5, 10, 25, 50],
  11899. getData: function ($defer, params) {
  11900. $scope.loading = true;
  11901. var pageParams = params.url();
  11902. pageParams.searchFilter = {};
  11903. pageParams.searchFilter.keyword = $scope.keyword;
  11904. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11905. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11906. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11907. $scope.loading = false;
  11908. if (page) {
  11909. params.total(page.totalElement);
  11910. $defer.resolve(page.content);
  11911. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11912. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11913. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11914. }
  11915. }, function (response) {
  11916. $scope.loading = false;
  11917. toaster.pop('error', '数据加载失败', response.data);
  11918. });
  11919. }
  11920. });
  11921. $scope.openDatePicker = function ($event, item, openParam) {
  11922. $event.preventDefault();
  11923. $event.stopPropagation();
  11924. item[openParam] = !item[openParam];
  11925. };
  11926. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11927. $event.preventDefault();
  11928. $event.stopPropagation();
  11929. item[openParam] = !item[openParam];
  11930. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11931. $scope.tableParams.reload();
  11932. }
  11933. };
  11934. // 搜索框回车
  11935. $scope.onSearch = function () {
  11936. $scope.tableParams.page(1);
  11937. $scope.tableParams.reload();
  11938. };
  11939. // 选择查找日期
  11940. $scope.onDateCondition = function () {
  11941. $scope.tableParams.page(1);
  11942. $scope.tableParams.reload();
  11943. };
  11944. // 导出
  11945. $scope.exportXls = function () {
  11946. MakeReturn.exportXls({}, {}, function (data) {
  11947. if (data.success){
  11948. window.location.href = 'make/return/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11949. }
  11950. }, function (response) {
  11951. toaster.pop('error', '数据加载失败', response.data);
  11952. });
  11953. }
  11954. }]);
  11955. /**
  11956. * 委外加工变更
  11957. */
  11958. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeChange, ngTableParams, toaster, BaseService, CurrentRole) {
  11959. BaseService.scrollBackToTop();
  11960. // 获取当前用户是否为普通用户
  11961. CurrentRole.isUser({}, {}, function (data) {
  11962. $scope.isUser = data.isUser;
  11963. });
  11964. $scope.active = 'all';
  11965. $scope.agreedText = '全部';
  11966. $scope.dateZoneText = '一个月内';
  11967. $scope.condition = {dateZone: 1};
  11968. /* 时间筛选初始化*/
  11969. var fromDate = new Date();
  11970. var toDate = new Date();
  11971. fromDate.setMonth(fromDate.getMonth() - 1);
  11972. fromDate.setHours(0, 0, 0, 0);
  11973. toDate.setHours(23, 59, 59, 999);
  11974. $scope.condition.dateFrom = fromDate;
  11975. $scope.condition.dateTo = toDate;
  11976. $scope.changeAgreed = function (agreed) {
  11977. $scope.condition.agreed = agreed;
  11978. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11979. $scope.condition.$agreedOpen = false;
  11980. };
  11981. $scope.changeDateZone = function (zone) {
  11982. $scope.condition.dateZone = zone;
  11983. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11984. $scope.condition.$dateZoneOpen = false;
  11985. getDateCondition(zone, $scope.condition);
  11986. $scope.tableParams.page(1);
  11987. $scope.tableParams.reload();
  11988. };
  11989. $scope.setActive = function (state) {
  11990. if ($scope.active != state) {
  11991. $scope.active = state;
  11992. if ($scope.tableParams.page() == 1)
  11993. $scope.tableParams.reload();
  11994. else
  11995. $scope.tableParams.page(1);
  11996. }
  11997. };
  11998. var getService = function () {
  11999. return MakeChange;
  12000. };
  12001. $scope.tableParams = new ngTableParams({
  12002. page: 1,
  12003. count: 20,
  12004. sorting: {
  12005. orderChangeDate: 'desc'
  12006. }
  12007. }, {
  12008. total: 0,
  12009. counts: [5, 10, 25, 50],
  12010. getData: function ($defer, params) {
  12011. $scope.loading = true;
  12012. var pageParams = params.url();
  12013. pageParams.searchFilter = {
  12014. keyword: $scope.keyword,
  12015. fromDate: getDateTime($scope.condition.dateFrom),
  12016. endDate: getDateTime($scope.condition.dateTo)
  12017. };
  12018. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12019. $scope.loading = false;
  12020. if (page) {
  12021. params.total(page.totalElement);
  12022. $defer.resolve(page.content);
  12023. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  12024. }
  12025. }, function (response) {
  12026. $scope.loading = false;
  12027. toaster.pop('error', '数据加载失败', response.data);
  12028. });
  12029. }
  12030. });
  12031. $scope.openDatePicker = function ($event, item, openParam) {
  12032. $event.preventDefault();
  12033. $event.stopPropagation();
  12034. item[openParam] = !item[openParam];
  12035. };
  12036. $scope.openFilterDatePicker = function ($event, item, openParam) {
  12037. $event.preventDefault();
  12038. $event.stopPropagation();
  12039. item[openParam] = !item[openParam];
  12040. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  12041. $scope.tableParams.reload();
  12042. }
  12043. };
  12044. // 打开回复
  12045. $scope.openReply = function (change) {
  12046. change.$editing = true;
  12047. };
  12048. // 关闭回复
  12049. $scope.closeReply = function (change) {
  12050. change.$editing = false;
  12051. }
  12052. // 确定回复
  12053. $scope.onReplyClick = function (change) {
  12054. if (change.$agreed) {
  12055. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  12056. $scope.loading = true;
  12057. MakeChange.reply({itemId: change.id}, reply, function () {
  12058. $scope.loading = false;
  12059. toaster.pop('info', '提示', '回复成功');
  12060. $scope.tableParams.reload();
  12061. }, function (response) {
  12062. $scope.loading = false;
  12063. toaster.pop('error', '回复失败', response.data);
  12064. });
  12065. }
  12066. };
  12067. // 搜索框回车
  12068. $scope.onSearch = function () {
  12069. $scope.tableParams.page(1);
  12070. $scope.tableParams.reload();
  12071. };
  12072. // 选择查找日期
  12073. $scope.onDateCondition = function () {
  12074. $scope.tableParams.page(1);
  12075. $scope.tableParams.reload();
  12076. };
  12077. // 导出
  12078. $scope.exportXls = function () {
  12079. MakeChange.exportXls({}, {}, function (data) {
  12080. if (data.success){
  12081. window.location.href = 'make/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  12082. }
  12083. }, function (response) {
  12084. toaster.pop('error', '数据加载失败', response.data);
  12085. });
  12086. }
  12087. }]);
  12088. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeChange, toaster, BaseService, CurrentRole) {
  12089. BaseService.scrollBackToTop();
  12090. CurrentRole.isUser({}, {}, function (data) {
  12091. $scope.isUser = data.isUser;
  12092. });
  12093. var loadData = function () {
  12094. MakeChange.getItem({id: $stateParams.id}, function (data) {
  12095. $scope.change = data;
  12096. }, function (response) {
  12097. toaster.pop('error', '数据加载失败', response.data);
  12098. });
  12099. };
  12100. loadData();
  12101. $scope.openDatePicker = function ($event, item, openParam) {
  12102. $event.preventDefault();
  12103. $event.stopPropagation();
  12104. item[openParam] = !item[openParam];
  12105. };
  12106. $scope.onReplyClick = function (change) {
  12107. if (change.$agreed) {
  12108. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  12109. MakeChange.reply({itemId: change.id}, reply, function () {
  12110. toaster.pop('info', '提示', '回复成功');
  12111. loadData();
  12112. }, function (response) {
  12113. toaster.pop('error', '回复失败', response.data);
  12114. });
  12115. }
  12116. };
  12117. }]);
  12118. /**
  12119. * 委外加工
  12120. */
  12121. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeOutOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  12122. BaseService.scrollBackToTop();
  12123. // 获取当前用户是否为普通用户
  12124. CurrentRole.isUser({}, {}, function (data) {
  12125. $scope.isUser = data.isUser;
  12126. });
  12127. $scope.active = 'all';
  12128. $scope.agreedText = '全部';
  12129. $scope.dateZoneText = '一个月内';
  12130. $scope.condition = {dateZone: 1};
  12131. /* 时间筛选初始化*/
  12132. var fromDate = new Date();
  12133. var toDate = new Date();
  12134. fromDate.setMonth(fromDate.getMonth() - 1);
  12135. fromDate.setHours(0, 0, 0, 0);
  12136. toDate.setHours(23, 59, 59, 999);
  12137. $scope.condition.dateFrom = fromDate;
  12138. $scope.condition.dateTo = toDate;
  12139. $scope.changeAgreed = function (agreed) {
  12140. $scope.condition.agreed = agreed;
  12141. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12142. $scope.condition.$agreedOpen = false;
  12143. };
  12144. $scope.changeDateZone = function (zone) {
  12145. $scope.condition.dateZone = zone;
  12146. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  12147. $scope.condition.$dateZoneOpen = false;
  12148. getDateCondition(zone, $scope.condition);
  12149. $scope.tableParams.page(1);
  12150. $scope.tableParams.reload();
  12151. };
  12152. $scope.setActive = function (state) {
  12153. if ($scope.active != state) {
  12154. $scope.active = state;
  12155. if ($scope.tableParams.page() == 1)
  12156. $scope.tableParams.reload();
  12157. else
  12158. $scope.tableParams.page(1);
  12159. }
  12160. };
  12161. var getService = function () {
  12162. return MakeOutOrder;
  12163. };
  12164. $scope.tableParams = new ngTableParams({
  12165. page: 1,
  12166. count: 20,
  12167. sorting: {
  12168. date: 'desc'
  12169. }
  12170. }, {
  12171. total: 0,
  12172. counts: [5, 10, 25, 50],
  12173. getData: function ($defer, params) {
  12174. $scope.loading = true;
  12175. var pageParams = params.url();
  12176. pageParams.searchFilter = {};
  12177. pageParams.searchFilter.keyword = $scope.keyword;
  12178. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  12179. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  12180. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12181. $scope.loading = false;
  12182. if (page) {
  12183. params.total(page.totalElement);
  12184. $defer.resolve(page.content);
  12185. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  12186. }
  12187. }, function (response) {
  12188. $scope.loading = false;
  12189. toaster.pop('error', '数据加载失败', response.data);
  12190. });
  12191. }
  12192. });
  12193. $scope.openDatePicker = function ($event, item, openParam) {
  12194. $event.preventDefault();
  12195. $event.stopPropagation();
  12196. item[openParam] = !item[openParam];
  12197. };
  12198. $scope.openFilterDatePicker = function ($event, item, openParam) {
  12199. $event.preventDefault();
  12200. $event.stopPropagation();
  12201. item[openParam] = !item[openParam];
  12202. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  12203. $scope.tableParams.reload();
  12204. }
  12205. };
  12206. // 获取回复记录
  12207. $scope.getReply = function (item) {
  12208. if (!item.replies) {
  12209. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  12210. item.replies = replies;
  12211. });
  12212. }
  12213. };
  12214. // 打开回复
  12215. $scope.openReply = function (change) {
  12216. change.$editing = true;
  12217. };
  12218. // 关闭回复
  12219. $scope.closeReply = function (change) {
  12220. change.$editing = false;
  12221. }
  12222. // 确定回复
  12223. $scope.onReplyClick = function (change) {
  12224. if (change.$agreed) {
  12225. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  12226. $scope.loading = true;
  12227. MakeOutOrder.reply({itemId: change.id}, reply, function () {
  12228. $scope.loading = false;
  12229. toaster.pop('info', '提示', '回复成功');
  12230. $scope.tableParams.reload();
  12231. }, function (response) {
  12232. $scope.loading = false;
  12233. toaster.pop('error', '回复失败', response.data);
  12234. });
  12235. }
  12236. };
  12237. // 搜索框回车
  12238. $scope.onSearch = function () {
  12239. $scope.tableParams.page(1);
  12240. $scope.tableParams.reload();
  12241. };
  12242. // 选择查找日期
  12243. $scope.onDateCondition = function () {
  12244. $scope.tableParams.page(1);
  12245. $scope.tableParams.reload();
  12246. };
  12247. // 导出
  12248. $scope.exportXls = function () {
  12249. MakeOutOrder.exportXls({}, {}, function (data) {
  12250. if (data.success){
  12251. window.location.href = 'make/outorders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  12252. }
  12253. }, function (response) {
  12254. toaster.pop('error', '数据加载失败', response.data);
  12255. });
  12256. }
  12257. }]);
  12258. /**
  12259. * 委外加工详细
  12260. */
  12261. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService, CurrentRole) {
  12262. BaseService.scrollBackToTop();
  12263. // 获取当前用户是否为普通用户
  12264. CurrentRole.isUser({}, {}, function (data) {
  12265. $scope.isUser = data.isUser;
  12266. });
  12267. var loadData = function () {
  12268. MakeOutOrder.getItem({id: $stateParams.id},{}, function (data) {
  12269. $scope.order = data;
  12270. var sum = $scope.order.qty * $scope.order.price;
  12271. $scope.order.total = sum;
  12272. $scope.loading = false;
  12273. }, function (response) {
  12274. toaster.pop('error', '提示', response.data);
  12275. });
  12276. };
  12277. loadData();
  12278. // 获取回复记录
  12279. $scope.getReply = function (item) {
  12280. if (!item.replies) {
  12281. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  12282. item.replies = replies;
  12283. });
  12284. }
  12285. };
  12286. $scope.openDatePicker = function ($event, item, openParam) {
  12287. $event.preventDefault();
  12288. $event.stopPropagation();
  12289. item[openParam] = !item[openParam];
  12290. };
  12291. // 点击回复
  12292. $scope.onReplyClick = function (order, inverse) {
  12293. if (order.reply) {
  12294. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  12295. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  12296. return;
  12297. }
  12298. var reply = angular.copy(order.reply);
  12299. if (reply.delivery) {
  12300. if (typeof reply.delivery == 'object')
  12301. reply.delivery = reply.delivery.getTime();
  12302. } else {
  12303. reply.delivery = order.delivery;
  12304. }
  12305. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  12306. $scope.loading = true;
  12307. MakeOutOrder.reply({orderId: order.id}, reply, function () {
  12308. $scope.loading = false;
  12309. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  12310. loadData();
  12311. }, function (response) {
  12312. $scope.loading = false;
  12313. toaster.pop('error', '回复失败', response.data);
  12314. });
  12315. }
  12316. };
  12317. // 打开回复
  12318. $scope.openReply = function (order) {
  12319. if (!order.reply) {
  12320. order.reply = {
  12321. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  12322. delivery: order.delivery
  12323. }
  12324. }
  12325. order.$editing = true;
  12326. };
  12327. // 关闭回复
  12328. $scope.closeReply = function (order) {
  12329. order.$editing = false;
  12330. }
  12331. // 自己委外加工订单
  12332. $scope.print = function (order) {
  12333. MakeOutOrder.printCount({id: order.id}, {});//增加打印此次
  12334. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  12335. };
  12336. }]);
  12337. /**
  12338. * 计算时间差
  12339. */
  12340. app.filter('timespan', function () {
  12341. return function (time) {
  12342. if (time == null)
  12343. return '9999年';
  12344. var now = new Date().getTime(), span = time - now,
  12345. d = Math.ceil(span / 86400000), h = Math.ceil(span / 3600000),
  12346. m = Math.ceil(span / 60000);
  12347. if (span < 0)
  12348. return '1天';
  12349. if (d > 0)
  12350. return d + 1 + '天';
  12351. if (h > 0)
  12352. return h + '小时';
  12353. if (m > 0)
  12354. return m + '分钟';
  12355. return '0天';
  12356. };
  12357. });
  12358. /**
  12359. * 公共询价计算时间差
  12360. */
  12361. app.filter('datespan', function () {
  12362. return function (time) {
  12363. if (time == null) {
  12364. return '剩余9999年';
  12365. }
  12366. var now = new Date().getTime(), span = time - now,
  12367. d = Math.floor(span / 86400000), h = Math.floor(span / 3600000),
  12368. m = Math.floor(span / 60000);
  12369. if (d > 0) {
  12370. var day = d + 1;
  12371. return '剩余' + day + '天';
  12372. }
  12373. if (h > 0) {
  12374. return '<span class="text-inverse">剩余' + h + '小时</span>';
  12375. }
  12376. if (m > 0) {
  12377. return '<span class="text-inverse">剩余' + m + '分钟</span>';
  12378. }
  12379. return '已结束';
  12380. };
  12381. });
  12382. app.filter('firstchar', function () {
  12383. return function (str) {
  12384. if (str == null)
  12385. return null;
  12386. return str.substring(0, 1);
  12387. };
  12388. });
  12389. app.filter('summary', function () {
  12390. return function (data, field) {
  12391. var sum = 0;
  12392. if (data) {
  12393. angular.forEach(data, function (d) {
  12394. sum += d[field];
  12395. });
  12396. }
  12397. return sum;
  12398. };
  12399. });
  12400. /**
  12401. * 搜索框,回车触发
  12402. */
  12403. app.directive('ngSearch', ['$parse', function ($parse) {
  12404. return {
  12405. require: '?ngModel',
  12406. restrict: 'A',
  12407. link: function (scope, element, attrs, ngModel) {
  12408. var searchFn = $parse(attrs.ngSearch);
  12409. element.bind('keypress', function (event) {
  12410. if (event.keyCode == '13') {
  12411. event.preventDefault();
  12412. event.stopPropagation();
  12413. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  12414. }
  12415. });
  12416. }
  12417. };
  12418. }]);
  12419. /**
  12420. * 状态码 -> 描述
  12421. */
  12422. app.filter('status', function () {
  12423. return function (data) {
  12424. var statusConfig = {
  12425. '101': '已提交',
  12426. '102': '已审核',
  12427. '103': '未通过',
  12428. '200': '未回复',
  12429. '201': '已回复',
  12430. '313': '已激活',
  12431. '316': '已过账',
  12432. '311': '申请中',
  12433. '312': '未激活'
  12434. };
  12435. return statusConfig[data];
  12436. }
  12437. });
  12438. //弹出问题反馈模态框
  12439. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function ($scope, $modal, AuthenticationService) {
  12440. //获取当前用户
  12441. AuthenticationService.getAuthentication().success(function (data) {
  12442. $scope.user = data;
  12443. });
  12444. $scope.showModal = function () {
  12445. var modalInstance = $modal.open({
  12446. animation: true,
  12447. templateUrl: 'static/tpl/serve/feedback.html',
  12448. controller: 'FeedbackCtrl',
  12449. resolve: {
  12450. user: function () {
  12451. return $scope.user;
  12452. } //传递当前用户到模态框Controller
  12453. }
  12454. });
  12455. modalInstance.result.then(function () {
  12456. }, function () {
  12457. });
  12458. }
  12459. }]);
  12460. /*
  12461. * 提交我的反馈
  12462. */
  12463. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function ($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user) {
  12464. $scope.isPublic = 1; //默认公开
  12465. $scope.classId = 1; //默认类别
  12466. $scope.user = user;
  12467. $scope.ok = function () {
  12468. if (!$scope.user) { //用户未登录
  12469. $scope.uu = null;
  12470. } else { //用户已登录
  12471. $scope.uu = $scope.user.userUU;
  12472. }
  12473. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  12474. FeedBackService.feedBackQuestion({
  12475. classId: $scope.classId,
  12476. isPublic: $scope.isPublic,
  12477. title: $scope.title,
  12478. userUU: $scope.uu
  12479. }, {},
  12480. function (data) {
  12481. toaster.pop('success', '成功', '您的问题反馈成功!');
  12482. $scope.cancel();
  12483. }, function (response) {
  12484. toaster.pop('error', '错误', response.data);
  12485. });
  12486. }
  12487. $scope.cancel = function () {
  12488. $modalInstance.dismiss();
  12489. };
  12490. }]);
  12491. //“我的问题反馈”跳转控制
  12492. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function ($scope, AuthenticationService, toaster, $rootScope) {
  12493. $scope.myFeedback = function () {
  12494. AuthenticationService.getAuthentication().success(function (data) {
  12495. $scope.user = data;
  12496. if (!$scope.user) {
  12497. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  12498. return false;
  12499. } else {
  12500. window.location.href = "./serve#/question/myFeedback";
  12501. }
  12502. });
  12503. };
  12504. $scope.getSaleOrderCount = function (unread) {
  12505. if (unread != undefined) {
  12506. return unread.order + unread.change + unread.makeOrder;
  12507. }
  12508. };
  12509. $scope.getSaleInquiryCount = function (unread) {
  12510. if (unread != undefined) {
  12511. return unread.inquiry + unread.mould;
  12512. }
  12513. };
  12514. $scope.setActive = function (active) {
  12515. $rootScope.active = active;
  12516. }
  12517. }]);
  12518. //客户服务
  12519. app.controller('CustServeCtrl', ['$scope', 'Vendor', function ($scope, Vendor) {
  12520. Vendor.getServe(function (datas) {
  12521. $scope.vendors = datas;
  12522. // 自动跳转
  12523. if (datas && datas.length == 1)
  12524. $scope.redirect(datas[0]);
  12525. });
  12526. $scope.redirect = function (vendor) {
  12527. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  12528. };
  12529. }]);
  12530. /**
  12531. * 物料资料
  12532. */
  12533. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$rootScope', '$modal', 'Products', 'GetProductInfoNewest', 'AccountEnterprise', function ($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout, $rootScope, $modal, Products, GetProductInfoNewest, AccountEnterprise) {
  12534. BaseService.scrollBackToTop();
  12535. var loadAccount = function () {
  12536. AccountEnterprise.get({}, function (data) {
  12537. $scope.loading = false;
  12538. $scope.enterprise = data;
  12539. $scope.saleStatus = $scope.enterprise.prodsale;
  12540. });
  12541. }
  12542. loadAccount();
  12543. $scope.active = 'all';
  12544. $scope.agreedText = '全部';
  12545. $scope.dateZoneText = '一个月内';
  12546. $scope.condition = {dateZone: 1};
  12547. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12548. $scope.changeAgreed = function (agreed) {
  12549. $scope.condition.agreed = agreed;
  12550. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12551. $scope.condition.$agreedOpen = false;
  12552. };
  12553. $scope.changeDateZone = function (zone) {
  12554. $scope.condition.dateZone = zone;
  12555. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12556. $scope.condition.$dateZoneOpen = false;
  12557. getDateCondition(zone, $scope.condition);
  12558. $scope.tableParams.reload();
  12559. };
  12560. $scope.setActive = function (state) {
  12561. if ($scope.active != state) {
  12562. $scope.active = state;
  12563. if ($scope.tableParams.page() == 1)
  12564. $scope.tableParams.reload();
  12565. else
  12566. $scope.tableParams.page(1);
  12567. }
  12568. };
  12569. $scope.searchMethod = false;
  12570. var getService = function () {
  12571. return $scope.searchMethod ? GetProductInfo : GetProductInfoNewest;
  12572. };
  12573. $scope.tableParams = new ngTableParams({
  12574. page: 1,
  12575. count: 20,
  12576. sorting: {
  12577. id: 'desc',
  12578. }
  12579. }, {
  12580. total: 0,
  12581. counts: [5, 10, 25, 50],
  12582. getData: function ($defer, params) {
  12583. $scope.loading = true;
  12584. var pageParams = params.url();
  12585. pageParams.keyword = $scope.keyword;
  12586. pageParams.searchFilter = $scope.searchFilter;
  12587. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12588. $scope.loading = false;
  12589. if (page) {
  12590. params.total(page.totalElement);
  12591. $defer.resolve(page.content);
  12592. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12593. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  12594. }
  12595. }, function (response) {
  12596. $scope.loading = false;
  12597. toaster.pop('error', '数据加载失败', response.data);
  12598. });
  12599. }
  12600. });
  12601. // //设置单据已读
  12602. // var setOrdersRead = function () {
  12603. // var ids = [];
  12604. // GetProductInfo.setRead({}, ids, function (message) {
  12605. // });
  12606. // };
  12607. // setOrdersRead();
  12608. // 搜索框回车
  12609. $scope.onSearch = function (keyword) {
  12610. // 每次搜索重置获取数据方法
  12611. $scope.searchMethod = false;
  12612. if(keyword != null && keyword != '') {
  12613. $scope.searchMethod = true;
  12614. }
  12615. $scope.tableParams.page(1);
  12616. $scope.tableParams.reload();
  12617. };
  12618. //删除
  12619. $scope.deleteById = function (id) {
  12620. $scope.loading = true;
  12621. GetProductInfo.deleteById({}, id, function (data) {
  12622. if (data.error) {
  12623. toaster.pop("error", "提示", data.error);
  12624. } else {
  12625. toaster.pop("success", "提示", "删除成功");
  12626. $timeout(function () {
  12627. $scope.tableParams.reload();
  12628. }, 500);
  12629. }
  12630. $scope.loading = false;
  12631. }, function (response) {
  12632. $scope.loading = false;
  12633. toaster.pop("error", "删除失败", response.data);
  12634. });
  12635. };
  12636. $rootScope.isProductEdit = false;
  12637. // 编辑
  12638. $scope.isProductEdit = function () {
  12639. $rootScope.isProductEdit = true;
  12640. };
  12641. // 一键开启关闭
  12642. $scope.toggle = function (status) {
  12643. if ($scope.saleStatus == 0) {
  12644. $scope.saleStatus = 1;
  12645. } else {
  12646. $scope.saleStatus = 0;
  12647. }
  12648. $scope.loading = true;
  12649. GetProductInfo.toggle({status: status}, {}, function (data) {
  12650. $scope.loading = false;
  12651. toaster.pop('success', '提示', '操作成功');
  12652. loadAccount();
  12653. $scope.tableParams.reload();
  12654. }, function (response) {
  12655. $scope.loading = false;
  12656. toaster.pop('error', '提示', response.data);
  12657. })
  12658. }
  12659. var products = [];
  12660. $scope.checks = {
  12661. checked: false
  12662. };
  12663. // 全选框
  12664. $scope.checkAll = function () {
  12665. products = [];// 每次选择时先清空,防止重复
  12666. angular.forEach($scope.tableParams.data, function (product) {
  12667. if (product.cmpUuId == null) {
  12668. product.checked = $scope.checks.checked;
  12669. }
  12670. });
  12671. };
  12672. // 单选
  12673. $scope.checkOne = function (product) {
  12674. products = [];// 每次选择时先清空,防止重复
  12675. var result = true;
  12676. angular.forEach($scope.tableParams.data, function (item) {
  12677. if (item.$selected != true) {
  12678. result = false;
  12679. return;
  12680. }
  12681. });
  12682. $scope.checks.checked = result;
  12683. var checked = true;
  12684. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  12685. if (!message.checked) {
  12686. checked = false;
  12687. }
  12688. });
  12689. $scope.checks.checked = checked;
  12690. };
  12691. $scope.updateByBatch = function (updatetype) {
  12692. var modalInstance = $modal.open({
  12693. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  12694. controller: 'UpdateByBatchCtrl',
  12695. size: 'md',
  12696. resolve: {
  12697. updatetype: function () {
  12698. return updatetype;
  12699. },
  12700. active: function () {
  12701. return $scope.active;
  12702. },
  12703. type: function () {
  12704. return 'sale';
  12705. }
  12706. }
  12707. });
  12708. modalInstance.result.then(function (data) {
  12709. toaster.pop('success', '提示', data.success);
  12710. $scope.tableParams.reload();
  12711. }, function () {
  12712. });
  12713. }
  12714. // 一键匹配
  12715. $scope.matchall = function () {
  12716. $scope.loading = true;
  12717. $scope.type = "sale";
  12718. GetProductInfo.matchbytype({type: $scope.type}, {}, function (data) {
  12719. if (data.error) {
  12720. $scope.loading = false;
  12721. toaster.pop('error', '提示', data.error);
  12722. } else {
  12723. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  12724. window.location.href = "#/sale/productmatches";
  12725. }
  12726. }, function (response) {
  12727. $scope.loading = false;
  12728. toaster.pop('error', '提示', response.data);
  12729. });
  12730. }
  12731. $scope.exportXls = function () {
  12732. GetProductInfo.exportXls({},{}, function (data) {
  12733. if (data.success) {
  12734. window.location.href = 'product/baseInfo/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  12735. }
  12736. }, function (response) {
  12737. toaster.pop('error', '数据加载失败', response.data);
  12738. })
  12739. }
  12740. }]);
  12741. /**
  12742. * 批量修改
  12743. */
  12744. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function ($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  12745. $scope.updatetype = updatetype;
  12746. $scope.changed = false;
  12747. $scope.parameter = {
  12748. updatetype: updatetype,
  12749. standard: active,
  12750. type: type,
  12751. oldvalue: null,
  12752. newvalue: null
  12753. };
  12754. $scope.cancel = function () {
  12755. $modalInstance.dismiss();
  12756. }
  12757. if (updatetype === '品牌')
  12758. var loadData = function () {
  12759. Products.getBrands({parameter: $scope.parameter}, {}, function (data) {
  12760. $scope.products = data;
  12761. }, function (response) {
  12762. toaster.pop('error', '提示', response.data);
  12763. })
  12764. }
  12765. if (updatetype === '名称(类目)')
  12766. var loadData = function () {
  12767. Products.getTitles({parameter: $scope.parameter}, {}, function (data) {
  12768. $scope.products = data;
  12769. }, function (response) {
  12770. toaster.pop('error', '提示', response.data);
  12771. })
  12772. }
  12773. loadData();
  12774. $scope.okay = function (newvalue) {
  12775. if (newvalue == '' || newvalue == null) {
  12776. toaster.pop('error', '提示', '修改的值不能为空');
  12777. } else {
  12778. $scope.loading = true;
  12779. Products.alterByBatch({parameter: $scope.parameter}, {}, function (data) {
  12780. $scope.loading = false;
  12781. $modalInstance.close(data);
  12782. }, function (response) {
  12783. $scope.loading = false;
  12784. toaster.pop('error', '提示', response.data);
  12785. });
  12786. }
  12787. }
  12788. }]);
  12789. /**
  12790. * 物料批量上传
  12791. */
  12792. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  12793. BaseService.scrollBackToTop();
  12794. $scope.$watch('myFiles', function () {
  12795. if ($scope.myFiles) {
  12796. var file = $scope.myFiles[0];
  12797. $scope.fileName = file.name;
  12798. }
  12799. })
  12800. // 通过excel批量上传物料
  12801. $scope.upload = function () {
  12802. $scope.loading = true;
  12803. if ($scope.myFiles) {
  12804. var file = $scope.myFiles[0];
  12805. if (file.name) {
  12806. $upload.upload({
  12807. url: 'product/baseInfo/edit/release/excel',
  12808. file: file,
  12809. method: 'POST'
  12810. }).success(function (data) {
  12811. $scope.loading = false;
  12812. if (data.error) {
  12813. toaster.pop('error', '提示', data.error);
  12814. }
  12815. $scope.result = data;
  12816. // $scope.products = $scope.result.products;
  12817. $scope.success = $scope.result.success;
  12818. $scope.total = $scope.result.total;
  12819. $scope.alters = $scope.result.alters;
  12820. $scope.infos = $scope.result.infos;
  12821. $scope.myFiles[0] = "";
  12822. $scope.fileName = "";
  12823. }).error(function (response) {
  12824. $scope.loading = false;
  12825. toaster.pop('error', response.data || response);
  12826. });
  12827. } else {
  12828. $scope.loading = false;
  12829. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  12830. }
  12831. } else {
  12832. $scope.loading = false;
  12833. }
  12834. };
  12835. // 查看范例
  12836. $scope.showImg = function () {
  12837. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  12838. box.show();
  12839. box.find('img').attr('src', src);
  12840. box.find('a').click(function () {
  12841. box.hide();
  12842. });
  12843. box.dblclick(function () {
  12844. box.hide();
  12845. });
  12846. };
  12847. // 下载模板
  12848. $scope.download = function () {
  12849. window.location.href = 'product/baseInfo/upload/template';
  12850. };
  12851. }]);
  12852. /**
  12853. * 物料详情
  12854. */
  12855. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$rootScope', '$modal', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $rootScope, $modal, Products) {
  12856. BaseService.scrollBackToTop();
  12857. // 录入人
  12858. AuthenticationService.getAuthentication().success(function (data) {
  12859. $scope.loading = false;
  12860. $scope.user = data;
  12861. });
  12862. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12863. $scope.editstatus = false;
  12864. var loadData = function () {
  12865. GetProductInfo.getSaleProduct({id: $stateParams.id}, function (data) {
  12866. if (data.attachment) {
  12867. $scope.imgPreview = data.attachment;
  12868. $scope.previewShow = true;
  12869. }
  12870. $scope.prodInfo = data;
  12871. if ($scope.prodInfo.isbusiness == 0) {
  12872. $scope.editstatus = true;
  12873. }
  12874. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  12875. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  12876. $scope.matchresults = data;
  12877. }, function (response) {
  12878. toaster.pop('error', '提示', response.data);
  12879. });
  12880. }
  12881. $scope.loading = false;
  12882. }, function (response) {
  12883. $scope.loading = false;
  12884. toaster.pop('error', '数据加载失败', response.data);
  12885. });
  12886. };
  12887. loadData();
  12888. // 联想词 start
  12889. // 获取类目
  12890. $scope.getSimilarKinds = function (value) {
  12891. if (value) {
  12892. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12893. return data.map(function (item) {
  12894. return item;
  12895. });
  12896. });
  12897. }
  12898. };
  12899. // 设置类目
  12900. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12901. $scope.prodInfo.kind = kind.kindName;
  12902. }
  12903. // 设置名称
  12904. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  12905. $scope.prodInfo.title = kind.kindName;
  12906. }
  12907. $scope.getSimilarBrands = function (value) {
  12908. if (value) {
  12909. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12910. return data.map(function (item) {
  12911. return item;
  12912. });
  12913. });
  12914. }
  12915. }
  12916. // 设置导入品牌
  12917. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12918. $scope.prodInfo.brand = brand.brandName;
  12919. }
  12920. // 设置标准品牌
  12921. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  12922. $scope.prodInfo.pbranden = brand.brandName;
  12923. }
  12924. $scope.getSimilarComponents = function (value) {
  12925. if (value) {
  12926. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12927. return data.map(function (item) {
  12928. return item;
  12929. });
  12930. });
  12931. }
  12932. }
  12933. // 设置标准型号
  12934. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12935. $scope.prodInfo.pcmpcode = cmp.code;
  12936. }
  12937. // 设置导入的型号
  12938. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  12939. $scope.prodInfo.cmpCode = cmp.code;
  12940. }
  12941. // 联想词 end
  12942. //更新为标准器件
  12943. $scope.updateone = function (id) {
  12944. $scope.loading = true;
  12945. Products.updateone({id: id}, {}, function (data) {
  12946. if (data.success) {
  12947. toaster.pop('success', '提示', data.success);
  12948. window.location.reload();
  12949. }
  12950. $scope.loading = false;
  12951. }, function (response) {
  12952. toaster.pop('error', '提示', response.data);
  12953. });
  12954. }
  12955. // 选择类目
  12956. $scope.selectKind = function (cmpcode) {
  12957. if (cmpcode == null) {
  12958. $modal.open({
  12959. animation: true,
  12960. size: 'lg',
  12961. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12962. controller: 'KindChooseCtrl',
  12963. }).result.then(function (data) {
  12964. $scope.kindId = data;
  12965. var modalInstance = $modal.open({
  12966. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12967. controller: 'FindComponentCtrl',
  12968. size: 'lg',
  12969. resolve: {
  12970. KindId: function () {
  12971. return $scope.kindId;
  12972. }
  12973. }
  12974. });
  12975. modalInstance.result.then(function (data) {
  12976. $scope.prodInfo.cmpUuId = data.uuid;
  12977. $scope.prodInfo.pcmpcode = data.code;
  12978. $scope.prodInfo.pbranden = data.brand.nameEn;
  12979. $scope.prodInfo.pbrand = data.brand.nameCn;
  12980. }, function () {
  12981. });
  12982. }, function () {
  12983. });
  12984. }
  12985. };
  12986. $scope.isShow = true;
  12987. // 更新
  12988. $scope.update = function () {
  12989. $scope.prodInfo.$editing = true;
  12990. $scope.isShow = true;
  12991. };
  12992. // 取消
  12993. $scope.cancel = function () {
  12994. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  12995. $scope.prodInfo = data;
  12996. $scope.prodInfo.$editing = false;
  12997. $scope.isShow = false;
  12998. $scope.loading = false;
  12999. });
  13000. };
  13001. // 删除
  13002. $scope.clearfile = function () {
  13003. $scope.prodInfo.attachment = null;
  13004. $scope.myFiles = null;
  13005. $scope.previewShow = false;
  13006. }
  13007. //删除
  13008. $scope.deleteById = function (id) {
  13009. $scope.loading = true;
  13010. GetProductInfo.deleteById({}, id, function (data) {
  13011. $scope.loading = false;
  13012. if (data.error) {
  13013. toaster.pop("error", "提示", data.error);
  13014. } else {
  13015. toaster.pop("success", "提示", "删除成功");
  13016. window.location.href = "#/sale/prodList";
  13017. }
  13018. }, function (response) {
  13019. $scope.loading = false;
  13020. toaster.pop("error", "删除失败", response.data);
  13021. });
  13022. };
  13023. $scope.submit = function (prodInfo) {
  13024. $scope.prodInfo.isSale = 1;
  13025. $scope.loading = true;
  13026. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  13027. $upload.upload({
  13028. url: 'product/baseInfo/edit/updateProdInfo',
  13029. file: file,
  13030. method: 'POST',
  13031. data: {
  13032. prodInfo: $scope.prodInfo
  13033. },
  13034. }).success(function (data) {
  13035. $scope.loading = false;
  13036. if (data.success) {
  13037. toaster.pop('success', '提示', data.success);
  13038. $rootScope.isProductEdit = false;
  13039. loadData();
  13040. // window.location.href="#/sale/prodList";
  13041. }
  13042. if (data.error) {
  13043. toaster.pop('error', '提示', data.error);
  13044. }
  13045. }).error(function (data, status) {
  13046. $scope.loading = false;
  13047. $scope.loadingShow = false;
  13048. if (status == 403){
  13049. toaster.pop('error', '操作失败', data);
  13050. } else {
  13051. toaster.pop('error', '操作失败', data.error);
  13052. }
  13053. });
  13054. }
  13055. $scope.previewShow = false;
  13056. $scope.pdfShow = false;
  13057. $scope.noneFileShow = true;
  13058. $scope.$watch('myFiles', function () {
  13059. if ($scope.myFiles) {
  13060. $scope.noneFileShow = false;
  13061. var file = $scope.myFiles[0];
  13062. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  13063. $scope.pdfShow = true;
  13064. $scope.previewShow = false;
  13065. $scope.imgPreviewName = file.name;
  13066. } else {
  13067. if (typeof(Worker) !== "undefined") {//支持HTML5
  13068. $scope.imgPreview = getObjectURL(file);
  13069. $scope.imgPreviewName = file.name;
  13070. } else {//不支持HTML5
  13071. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  13072. $scope.imgPreviewName = file.name;
  13073. }
  13074. $scope.previewShow = true;
  13075. $scope.pdfShow = false;
  13076. }
  13077. } else {
  13078. $scope.noneFileShow = true;
  13079. $scope.previewShow = false;
  13080. $scope.pdfShow = false;
  13081. }
  13082. });
  13083. //建立一个可存取到该file的url
  13084. var imgurl = null;
  13085. var getObjectURL = function (file) {
  13086. var url = null;
  13087. if (window.createObjectURL != undefined) { // basic
  13088. url = window.createObjectURL(file);
  13089. } else if (window.URL != undefined) { // mozilla(firefox)
  13090. url = window.URL.createObjectURL(file);
  13091. } else if (window.webkitURL != undefined) { // webkit or chrome
  13092. url = window.webkitURL.createObjectURL(file);
  13093. }
  13094. imgurl = url;
  13095. return url;
  13096. };
  13097. // 查看范例
  13098. $scope.showImg = function () {
  13099. if ($scope.prodInfo.attachment) {
  13100. $scope.imgPreview = $scope.prodInfo.attachment;
  13101. var src = $scope.prodInfo.attachment, box = $('#image-box');
  13102. box.show();
  13103. box.find('img').attr('src', src);
  13104. box.find('a').click(function () {
  13105. box.hide();
  13106. });
  13107. box.dblclick(function () {
  13108. box.hide();
  13109. });
  13110. $scope.previewShow = true;
  13111. } else if (imgurl != null) {
  13112. var src = imgurl, box = $('#image-box');
  13113. box.show();
  13114. box.find('img').attr('src', src);
  13115. box.find('a').click(function () {
  13116. box.hide();
  13117. });
  13118. box.dblclick(function () {
  13119. box.hide();
  13120. });
  13121. }
  13122. };
  13123. }]);
  13124. /**
  13125. * 新增物料(销售)
  13126. */
  13127. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService, Products) {
  13128. BaseService.scrollBackToTop();
  13129. // 录入人
  13130. AuthenticationService.getAuthentication().success(function (data) {
  13131. $scope.loading = false;
  13132. $scope.user = data;
  13133. });
  13134. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  13135. $scope.prodInfo = {};
  13136. // 选择类目
  13137. $scope.selectKind = function () {
  13138. $modal.open({
  13139. animation: true,
  13140. size: 'lg',
  13141. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  13142. controller: 'KindChooseCtrl',
  13143. }).result.then(function (data) {
  13144. $scope.kindId = data;
  13145. var modalInstance = $modal.open({
  13146. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  13147. controller: 'FindComponentCtrl',
  13148. size: 'lg',
  13149. resolve: {
  13150. KindId: function () {
  13151. return $scope.kindId;
  13152. }
  13153. }
  13154. });
  13155. modalInstance.result.then(function (data) {
  13156. $scope.prodInfo.cmpUuId = data.uuid;
  13157. $scope.prodInfo.pcmpcode = data.code;
  13158. $scope.prodInfo.pbranden = data.brand.nameEn;
  13159. $scope.prodInfo.pbrand = data.brand.nameCn;
  13160. }, function () {
  13161. });
  13162. }, function () {
  13163. });
  13164. };
  13165. // 联想词 start
  13166. // 获取类目
  13167. $scope.getSimilarKinds = function (value) {
  13168. if (value) {
  13169. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  13170. return data.map(function (item) {
  13171. return item;
  13172. });
  13173. });
  13174. }
  13175. };
  13176. $scope.onAssociateKindClick = function (kind, prodInfo) {
  13177. $scope.prodInfo.title = kind.kindName;
  13178. }
  13179. $scope.getSimilarBrands = function (value) {
  13180. if (value) {
  13181. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  13182. return data.map(function (item) {
  13183. return item;
  13184. });
  13185. });
  13186. }
  13187. }
  13188. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  13189. $scope.prodInfo.brand = brand.brandName;
  13190. }
  13191. $scope.getSimilarComponents = function (value) {
  13192. if (value) {
  13193. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  13194. return data.map(function (item) {
  13195. return item;
  13196. });
  13197. });
  13198. }
  13199. }
  13200. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  13201. $scope.prodInfo.cmpCode = cmp.code;
  13202. }
  13203. // 联想词 end
  13204. // 删除
  13205. $scope.clearfile = function () {
  13206. $scope.myFiles = null;
  13207. $scope.previewShow = false;
  13208. }
  13209. //提交
  13210. $scope.submit = function (prodInfo) {
  13211. $scope.loading = true;
  13212. $scope.prodInfo.isSale = 1;
  13213. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  13214. $upload.upload({
  13215. url: 'product/baseInfo/edit/addNewProduct',
  13216. file: file,
  13217. method: 'POST',
  13218. data: {
  13219. prodInfo: prodInfo
  13220. },
  13221. }).success(function (data) {
  13222. $scope.loading = false;
  13223. if (data.success) {
  13224. toaster.pop('success', '提示', '产品添加成功');
  13225. $timeout(function () {
  13226. //提交后跳转到详情页面,防止重复提交
  13227. window.location.href = "#/sale/prodList/" + data.id;
  13228. // window.location.href="#/sale/prodList";
  13229. }, 500);
  13230. }
  13231. if (data.error) {
  13232. toaster.pop('error', '提示', data.error);
  13233. $timeout(function () {
  13234. //提交后跳转到详情页面,防止重复提交
  13235. window.location.href = "#/sale/prodList/" + data.id;
  13236. // window.location.href="#/sale/prodList";
  13237. }, 500);
  13238. }
  13239. }).error(function (data, status) {
  13240. $scope.loading = false;
  13241. $scope.loadingShow = false;
  13242. if (status == 403) {
  13243. toaster.pop('error', '操作失败', data);
  13244. } else {
  13245. toaster.pop('error', '操作失败', data.error);
  13246. }
  13247. });
  13248. };
  13249. $scope.previewShow = false;
  13250. $scope.pdfShow = false;
  13251. $scope.noneFileShow = true;
  13252. $scope.$watch('myFiles', function () {
  13253. if ($scope.myFiles) {
  13254. $scope.noneFileShow = false;
  13255. var file = $scope.myFiles[0];
  13256. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  13257. $scope.pdfShow = true;
  13258. $scope.previewShow = false;
  13259. $scope.imgPreviewName = file.name;
  13260. } else {
  13261. if (typeof(Worker) !== "undefined") {//支持HTML5
  13262. $scope.imgPreview = getObjectURL(file);
  13263. $scope.imgPreviewName = file.name;
  13264. } else {//不支持HTML5
  13265. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  13266. $scope.imgPreviewName = file.name;
  13267. }
  13268. $scope.previewShow = true;
  13269. $scope.pdfShow = false;
  13270. }
  13271. } else {
  13272. $scope.noneFileShow = true;
  13273. $scope.previewShow = false;
  13274. $scope.pdfShow = false;
  13275. }
  13276. });
  13277. //建立一个可存取到该file的url
  13278. var imgUrl = null
  13279. var getObjectURL = function (file) {
  13280. var url = null;
  13281. if (window.createObjectURL != undefined) { // basic
  13282. url = window.createObjectURL(file);
  13283. } else if (window.URL != undefined) { // mozilla(firefox)
  13284. url = window.URL.createObjectURL(file);
  13285. } else if (window.webkitURL != undefined) { // webkit or chrome
  13286. url = window.webkitURL.createObjectURL(file);
  13287. }
  13288. imgUrl = url;
  13289. return url;
  13290. };
  13291. // 查看范例
  13292. $scope.showImg = function () {
  13293. var src = imgUrl, box = $('#image-box');
  13294. box.show();
  13295. box.find('img').attr('src', src);
  13296. box.find('a').click(function () {
  13297. box.hide();
  13298. });
  13299. box.dblclick(function () {
  13300. box.hide();
  13301. });
  13302. };
  13303. // 取消
  13304. $scope.cancel = function () {
  13305. $scope.prodInfo = angular.copy($scope.prodInfo);
  13306. };
  13307. }]);
  13308. /**
  13309. * 类目选择模态框
  13310. */
  13311. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function ($scope, KindAPI, toaster, $modalInstance, $modal) {
  13312. $scope.kindId = null;
  13313. $scope.kinds = [[], [], [], []];
  13314. // 获取子类目
  13315. var getChildren = function (pid, deep) {
  13316. KindAPI.getChildren({parentId: pid}, function (data) {
  13317. $scope.kinds[deep] = data;
  13318. }, function (response) {
  13319. toaster.pop('error', '获取子类目失败', response.data);
  13320. });
  13321. };
  13322. // 改变节点选中状态
  13323. var changeStatus = function (item, deep) {
  13324. var kindId = null, level = 0;
  13325. angular.forEach($scope.kinds, function (ks, i) {
  13326. if (i > deep) {
  13327. $scope.kinds[i] = [];
  13328. } else {
  13329. angular.forEach(ks, function (k, j) {
  13330. if (i == deep) {
  13331. if (k.id == item.id) {
  13332. $scope.kinds[i][j].$active = true;
  13333. kindId = k.id;
  13334. } else {
  13335. k.$active = null;
  13336. }
  13337. }
  13338. });
  13339. }
  13340. });
  13341. // 选择的节点
  13342. $scope.kindId = kindId;
  13343. $scope.active = item;
  13344. // 当前可操作的层级
  13345. if (deep < 3) {
  13346. $scope.activeDeep = deep + 1;
  13347. }
  13348. };
  13349. // 节点点击后获取子类目,节点被选中
  13350. $scope.onItemClick = function (item, deep) {
  13351. changeStatus(item, deep);
  13352. if (!item.isLeaf) {
  13353. getChildren(item.id, deep + 1);
  13354. }
  13355. };
  13356. // 重新加载数据
  13357. function reload(deep) {
  13358. var pid;
  13359. if (deep) {
  13360. pid = $scope.actives[deep - 1].id;
  13361. } else {
  13362. pid = 0;
  13363. deep = 0;
  13364. }
  13365. getChildren(pid, deep);
  13366. }
  13367. // 初始加载数据,获取第一层的类目
  13368. if ($scope.actives) {
  13369. angular.forEach($scope.actives, function (v, k) {
  13370. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  13371. $scope.kinds[k] = data;
  13372. angular.forEach($scope.kinds[k], function (kind, i) {
  13373. if (kind.id == v.id) {
  13374. $scope.kinds[k][i].$active = true;
  13375. $scope.actives[k] = $scope.kinds[k][i];
  13376. }
  13377. })
  13378. }, function (response) {
  13379. toaster.pop('error', '获取子类目失败', response.data);
  13380. });
  13381. });
  13382. } else {
  13383. reload();
  13384. }
  13385. // 取消
  13386. $scope.cancel = function () {
  13387. $modalInstance.dismiss();
  13388. };
  13389. // 确认选择
  13390. $scope.check = function () {
  13391. $modalInstance.close($scope.kindId);
  13392. };
  13393. }]);
  13394. /**
  13395. * 器件筛选
  13396. */
  13397. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  13398. //状态
  13399. $scope.setActive = function (state) {
  13400. if ($scope.active != state) {
  13401. $scope.active = state;
  13402. if ($scope.tableParams.page() == 1)
  13403. $scope.tableParams.reload();
  13404. else
  13405. $scope.tableParams.page(1);
  13406. }
  13407. };
  13408. $scope.tableParams = new ngTableParams({
  13409. page: 1,
  13410. count: 20
  13411. }, {
  13412. total: 0,
  13413. counts: [5, 10, 25, 50],
  13414. getData: function ($defer, params) {
  13415. $scope.loading = true;
  13416. var pageParams = params.url();
  13417. pageParams.keyword = $scope.keyword;
  13418. pageParams.kindId = KindId;
  13419. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function (page) {
  13420. $scope.loading = false;
  13421. if (page) {
  13422. params.total(page.totalElement);
  13423. $defer.resolve(page.content);
  13424. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13425. }
  13426. }, function (response) {
  13427. $scope.loading = false;
  13428. toaster.pop('error', '数据加载失败', response.data);
  13429. });
  13430. }
  13431. });
  13432. // 取消
  13433. $scope.cancel = function () {
  13434. $modalInstance.dismiss();
  13435. };
  13436. // 选择
  13437. $scope.check = function (data) {
  13438. $modalInstance.close(data);
  13439. };
  13440. // 搜索框回车
  13441. $scope.onSearch = function () {
  13442. $scope.tableParams.page(1);
  13443. $scope.tableParams.reload();
  13444. };
  13445. }]);
  13446. /**
  13447. * 企业列表
  13448. */
  13449. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  13450. BaseService.scrollBackToTop();
  13451. $scope.active = 'all';
  13452. $scope.agreedText = '全部';
  13453. $scope.dateZoneText = '一个月内';
  13454. $scope.condition = {dateZone: 1};
  13455. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13456. $scope.changeAgreed = function (agreed) {
  13457. $scope.condition.agreed = agreed;
  13458. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13459. $scope.condition.$agreedOpen = false;
  13460. };
  13461. $scope.changeDateZone = function (zone) {
  13462. $scope.condition.dateZone = zone;
  13463. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13464. $scope.condition.$dateZoneOpen = false;
  13465. getDateCondition(zone, $scope.condition);
  13466. $scope.tableParams.reload();
  13467. };
  13468. $scope.setActive = function (state) {
  13469. if ($scope.active != state) {
  13470. $scope.active = state;
  13471. if ($scope.tableParams.page() == 1)
  13472. $scope.tableParams.reload();
  13473. else
  13474. $scope.tableParams.page(1);
  13475. }
  13476. };
  13477. var getService = function () {
  13478. return getAccountUserSpace;
  13479. };
  13480. $scope.tableParams = new ngTableParams({
  13481. page: 1,
  13482. count: 20,
  13483. sorting: {}
  13484. }, {
  13485. total: 0,
  13486. counts: [5, 10, 25, 50],
  13487. getData: function ($defer, params) {
  13488. $scope.loading = true;
  13489. var pageParams = params.url();
  13490. pageParams.keyword = $scope.keyword;
  13491. $scope.tip = $scope.keyword;
  13492. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  13493. $scope.loading = false;
  13494. if (page) {
  13495. params.total(page.totalElement);
  13496. $defer.resolve(page.content);
  13497. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13498. }
  13499. }, function (response) {
  13500. $scope.loading = false;
  13501. toaster.pop('error', '数据加载失败', response.data);
  13502. });
  13503. }
  13504. });
  13505. // 搜索框回车
  13506. $scope.onSearch = function () {
  13507. $scope.tableParams.page(1);
  13508. $scope.tableParams.reload();
  13509. };
  13510. // 添加合作关系
  13511. $scope.addPartner = function (name, businessCode) {
  13512. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  13513. if (data.success) {
  13514. toaster.pop("success", '添加成功', data.success);
  13515. $scope.tableParams.reload();
  13516. }
  13517. if (data.error) {
  13518. toaster.pop("error", '添加失败', data.error);
  13519. }
  13520. }, function (response) {
  13521. toaster.pop('error', '失败', response.data);
  13522. });
  13523. }
  13524. $scope.status = 'enList';
  13525. }]);
  13526. /**
  13527. * 新增采购单
  13528. */
  13529. app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', 'recentPrice',
  13530. function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token, recentPrice) {
  13531. BaseService.scrollBackToTop();
  13532. // 每次进入时先清除掉rootScope下的venduu
  13533. $rootScope.venduu = null;
  13534. // 获取收货地址列表
  13535. ShipAddress.shipAddList({}, function (data) {
  13536. $scope.ships = data;
  13537. $scope.order.shipadd = $scope.ships[0];
  13538. });
  13539. // 获取地址信息
  13540. $http.get('resources/citydata/city.json', {
  13541. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  13542. }).then(function (response) {
  13543. $scope.provinces = response.data;
  13544. });
  13545. var getToken = function() {
  13546. if($scope.token == null) {
  13547. token.info({userType: 'purcorder'}, {}, function(data) {
  13548. $scope.token = data.token;
  13549. }, function(response) {
  13550. toaster.pop('error', '提示', response.data);
  13551. });
  13552. }
  13553. }
  13554. getToken();
  13555. $scope.order = {
  13556. date: new Date(),
  13557. vend: {
  13558. uu: '',
  13559. },
  13560. vendUser: {},
  13561. code: $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  13562. orderItems: {
  13563. product: {},
  13564. },
  13565. rate: 17
  13566. };
  13567. //商品信息
  13568. $scope.order.orderItems = [];
  13569. var item = {
  13570. code: null,
  13571. title: null,
  13572. spec: null,
  13573. unit: null,
  13574. qty: null,
  13575. price: null,
  13576. remark: null,
  13577. delivery: null,
  13578. prid: null,
  13579. taxrate: null
  13580. };
  13581. if ($rootScope.businessCode) {
  13582. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function (data) {
  13583. $scope.id = data.id;
  13584. $scope.order.vend.enName = data.vendorEnterprise.enName;
  13585. $scope.order.vend.enAddress = data.vendorEnterprise.enAddress;
  13586. $scope.order.vend.uu = data.vendorEnterprise.uu;
  13587. $scope.order.paymethods = data.paymethod;
  13588. $rootScope.venduu = data.vendorEnterprise.uu;
  13589. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13590. $scope.contacts = data;
  13591. $scope.order.vendor = $scope.contacts[0];
  13592. });
  13593. }, function (response) {
  13594. });
  13595. }
  13596. ;
  13597. // 查找供应商
  13598. $scope.dbfindVend = function () {
  13599. var modalInstance = $modal.open({
  13600. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  13601. controller: 'DbfindVendorInfoCtrl',
  13602. size: 'lg',
  13603. resolve: {
  13604. orderItems: function () {
  13605. return $scope.order.orderItems;
  13606. }
  13607. }
  13608. });
  13609. modalInstance.result.then(function (data) {
  13610. $rootScope.venduu = data.vendorEnterprise.uu;
  13611. $scope.id = data.id;
  13612. $scope.order.vend = data.vendorEnterprise;
  13613. $scope.order.vend.enName = data.vendorEnterprise.enName;
  13614. $scope.order.vendUser = data.vendorUser;
  13615. $scope.order.payments = data.paymethod;
  13616. $scope.order.orderItems = [];
  13617. var item = {
  13618. code: null,
  13619. title: null,
  13620. spec: null,
  13621. unit: null,
  13622. qty: null,
  13623. price: null,
  13624. remark: null,
  13625. delivery: null,
  13626. taxrate: null
  13627. };
  13628. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13629. $scope.contacts = data;
  13630. $scope.order.vendor = $scope.contacts[0];
  13631. });
  13632. }, function () {
  13633. });
  13634. };
  13635. // 联想词 start
  13636. // 获取供应商
  13637. $scope.getSimilarVendors = function (value) {
  13638. if (value) {
  13639. return Vendor.getSimilarVendors({keyword: value}).$promise.then(function (data) {
  13640. return data.map(function (item) {
  13641. return item;
  13642. });
  13643. });
  13644. }
  13645. };
  13646. $scope.onAssociateCmpClick = function (vendor, order) {
  13647. $scope.order.vend.uu = vendor.venduu;
  13648. $scope.id = vendor.id;
  13649. $scope.order.payments = vendor.paymethod;
  13650. $rootScope.venduu = $scope.order.vend.uu;
  13651. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13652. $scope.contacts = data;
  13653. $scope.order.vendor = $scope.contacts[0];
  13654. });
  13655. }
  13656. // 联想词 end
  13657. // $scope.order.orderItems.push(item);
  13658. if ($rootScope.prodId) {
  13659. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  13660. item.code = data.code;
  13661. item.title = data.title;
  13662. item.spec = data.spec;
  13663. item.unit = data.unit;
  13664. item.id = data.id;
  13665. $scope.order.orderItems.push(item);
  13666. $rootScope.prodId = null;// 清除掉prodId
  13667. }, function (response) {
  13668. });
  13669. }
  13670. //增加商品
  13671. $scope.addProduct = function (index) {
  13672. if ($scope.order.orderItems[index].code == null) {
  13673. toaster.pop('info', '提示', '请先选择商品');
  13674. } else {
  13675. $scope.order.orderItems.push({
  13676. code: null,
  13677. title: null,
  13678. spec: null,
  13679. unit: null,
  13680. qty: null,
  13681. price: null,
  13682. remark: null,
  13683. delivery: null,
  13684. $endDateOpen: false,
  13685. taxrate: $scope.order.rate,
  13686. prodsource: 'seller'
  13687. });
  13688. }
  13689. };
  13690. //删除商品
  13691. $scope.deleteProduct = function (index) {
  13692. $scope.order.orderItems.splice(index, 1);
  13693. };
  13694. // 搜索框回车
  13695. $scope.onSearch = function (keyword) {
  13696. $scope.keyword = keyword;
  13697. $scope.tableParams.page(1);
  13698. $scope.tableParams.reload();
  13699. };
  13700. $scope.tableParams = new ngTableParams({
  13701. page: 1,
  13702. count: 20
  13703. }, {
  13704. total: 0,
  13705. counts: [5, 10, 25, 50],
  13706. getData: function ($defer, params) {
  13707. $scope.loading = true;
  13708. var pageParams = params.url();
  13709. pageParams.keyword = $scope.keyword;
  13710. $scope.tip = $scope.keyword;
  13711. pageParams.vendUU = $scope.order.vend.uu;
  13712. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  13713. $scope.loading = false;
  13714. if (page) {
  13715. params.total(page.totalElement);
  13716. $scope.total = page.totalElement;
  13717. $defer.resolve(page.content);
  13718. }
  13719. }, function (response) {
  13720. $scope.loading = false;
  13721. toaster.pop('error', '数据加载失败', response.data);
  13722. });
  13723. }
  13724. });
  13725. // 选择
  13726. $scope.check = function (data) {
  13727. var price = null;
  13728. var qty = null;
  13729. var taxRate = null;
  13730. if (data.id) {
  13731. recentPrice.agreed({prId: data.id}, {}, function(response) {
  13732. price = response.price;
  13733. qty = response.qty;
  13734. taxRate = response.taxRate;
  13735. $scope.order.orderItems.push({
  13736. code: data.code,
  13737. title: data.title,
  13738. spec: data.spec,
  13739. unit: data.unit,
  13740. qty: qty,
  13741. price: price,
  13742. remark: null,
  13743. delivery: null,
  13744. prid: data.id,
  13745. taxrate: taxRate,
  13746. prodsource: 'seller',
  13747. });
  13748. });
  13749. }
  13750. };
  13751. // 导入商品信息
  13752. $scope.uplodaByBatch = function () {
  13753. var modalInstance = $modal.open({
  13754. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  13755. controller: 'PurcUploadByBatchCtrl',
  13756. size: 'lg',
  13757. resolve: {}
  13758. });
  13759. modalInstance.result.then(function (data) {
  13760. angular.forEach(data, function (prod) {
  13761. $scope.order.orderItems.push({
  13762. code: prod.code,
  13763. title: prod.title,
  13764. unit: 'PCS',
  13765. spec: prod.spec,
  13766. qty: prod.amount,
  13767. price: prod.price,
  13768. remark: prod.remark,
  13769. delivery: prod.date,
  13770. prid: prod.id,
  13771. taxrate: prod.rate,
  13772. prodsource: 'purchaser'
  13773. });
  13774. })
  13775. }, function () {
  13776. });
  13777. };
  13778. // 监听venduu发生变化,重新加载物料信息
  13779. $scope.$watch('order.vend.uu', function (n, o) {
  13780. if (n == o) {
  13781. return;
  13782. } else {
  13783. $scope.tableParams.page(1);
  13784. $scope.tableParams.reload();
  13785. }
  13786. }, true);
  13787. $scope.getMinDate = function (item) {
  13788. return $filter('date')(new Date, 'yyyy-MM-dd');
  13789. };
  13790. $scope.openDatePicker = function ($event, openParam, index) {
  13791. $event.preventDefault();
  13792. $event.stopPropagation();
  13793. $scope.order.orderItems[index].$endDateOpen = !openParam;
  13794. };
  13795. // 添加到购物车
  13796. $scope.addToCart = function (order) {
  13797. $scope.loading = true;
  13798. $scope.order.status = 311;
  13799. $scope.order.vendusertel = order.vendor.tel;
  13800. $scope.order.venduser = order.vendor.venduser;
  13801. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13802. $scope.order.vendUU = $scope.order.vend.uu;
  13803. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13804. if ($scope.order.date instanceof Date) {
  13805. $scope.order.date = $scope.order.date.getTime();
  13806. }
  13807. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13808. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13809. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13810. }
  13811. if ($scope.order.currency != 'RMB') {
  13812. $scope.order.orderItems[i].rate = 0;
  13813. }
  13814. }
  13815. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13816. $scope.loading = false;
  13817. toaster.pop('success', '成功', '保存成功');
  13818. window.location.hash = '#/purc/cart/' + data.id;
  13819. $window.location.reload();
  13820. }, function (response) {
  13821. $scope.loading = false;
  13822. toaster.pop('error', '保存失败', response.data);
  13823. });
  13824. };
  13825. // 立即购买
  13826. $scope.addToOrder = function (order) {
  13827. $scope.loading = true;
  13828. $scope.order.status = 200;
  13829. $scope.order.vendusertel = order.vendor.tel;
  13830. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  13831. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13832. $scope.order.vendUU = $scope.order.vend.uu;
  13833. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13834. if ($scope.order.date instanceof Date) {
  13835. $scope.order.date = $scope.order.date.getTime();
  13836. }
  13837. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13838. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13839. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13840. }
  13841. if ($scope.order.currency != 'RMB') {
  13842. $scope.order.orderItems[i].rate = 0;
  13843. }
  13844. }
  13845. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13846. $scope.loading = false;
  13847. toaster.pop('success', '成功', '保存成功');
  13848. window.location.hash = '#/purc/order/' + data.id;
  13849. }, function (response) {
  13850. $scope.loading = false;
  13851. toaster.pop('error', '保存失败', response.data);
  13852. });
  13853. };
  13854. // 新增收货地址保存
  13855. $scope.saveShipAddress = function (ship) {
  13856. ship.address = ship.province + ship.city + ship.district;
  13857. ShipAddress.saveAddress({}, ship, function (data) {
  13858. if (data.success) {
  13859. ShipAddress.shipAddList({}, function (data) {
  13860. $scope.ships = data;
  13861. $scope.order.shipadd = $scope.ships[0];
  13862. });
  13863. toaster.pop('success', '提示', data.success);
  13864. }
  13865. if (data.error) {
  13866. toaster.pop('error', '提示', data.error);
  13867. }
  13868. });
  13869. }
  13870. // 新增供应商联系人
  13871. $scope.addContact = function (uu) {
  13872. var modalInstance = $modal.open({
  13873. animation: true,
  13874. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13875. controller: 'AddContacCtrl',
  13876. resolve: {}
  13877. });
  13878. modalInstance.result.then(function (data) {
  13879. $scope.contact = data;
  13880. $scope.contact.venduu = uu;
  13881. Vendor.saveContact({}, $scope.contact, function (data) {
  13882. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13883. $scope.contacts = data;
  13884. $scope.order.vendor = $scope.contacts[0];
  13885. });
  13886. toaster.pop('success', '提示', '联系人保存成功');
  13887. }, function (response) {
  13888. toaster.pop('error', '失败', response.data);
  13889. });
  13890. });
  13891. }
  13892. }]);
  13893. /**
  13894. * 采购批量导入
  13895. */
  13896. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  13897. // 通过excel批量上传物料
  13898. $scope.result = null;
  13899. $scope.loading = false;
  13900. $scope.upload = function () {
  13901. $scope.loading = true;
  13902. var file = $scope.myFiles[0];
  13903. $upload.upload({
  13904. url: 'purchase/release/excel',
  13905. file: file,
  13906. method: 'POST'
  13907. }).success(function (data) {
  13908. $scope.loading = false;
  13909. $scope.result = data;
  13910. $scope.success = $scope.result.success;
  13911. $scope.total = $scope.result.total;
  13912. $scope.alters = $scope.result.alters;
  13913. }).error(function (response) {
  13914. $scope.loading = false;
  13915. toaster.pop('error', response.data || response);
  13916. });
  13917. };
  13918. // 下载模板
  13919. $scope.download = function () {
  13920. window.location.href = 'purchase/upload/template';
  13921. };
  13922. $scope.enSure = function () {
  13923. $modalInstance.close($scope.result.products);
  13924. }
  13925. // 点击确定时增加加载标志
  13926. $scope.addClass = function() {
  13927. $scope.loading = true;
  13928. }
  13929. $scope.cancel = function () {
  13930. $modalInstance.dismiss();
  13931. }
  13932. }]);
  13933. // 查找供应商
  13934. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems) {
  13935. $scope.prod = false;
  13936. if (orderItems.length != 0) {
  13937. $scope.prod = true;
  13938. }
  13939. BaseService.scrollBackToTop();
  13940. if ($rootScope.venduu != null) {
  13941. $scope.venduu = $rootScope.venduu;
  13942. }
  13943. // 搜索框回车
  13944. $scope.onSearch = function (keyword) {
  13945. $scope.keyword = keyword;
  13946. $scope.customerParams.page(1);
  13947. $scope.customerParams.reload();
  13948. };
  13949. $scope.customerParams = new ngTableParams({
  13950. page: 1,
  13951. count: 20
  13952. }, {
  13953. total: 0,
  13954. counts: [5, 10, 25, 50],
  13955. getData: function ($defer, params) {
  13956. $scope.loading = true;
  13957. var pageParams = params.url();
  13958. pageParams.keyword = $scope.keyword;
  13959. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13960. $scope.loading = false;
  13961. if (page) {
  13962. params.total(page.totalElement);
  13963. $defer.resolve(page.content);
  13964. }
  13965. $scope.totalCount = page.totalElement;
  13966. }, function (response) {
  13967. $scope.loading = false;
  13968. toaster.pop('error', '数据加载失败', response.data);
  13969. });
  13970. }
  13971. });
  13972. $scope.cancel = function () {
  13973. $modalInstance.dismiss();
  13974. };
  13975. $scope.ensure = false;
  13976. $scope.check = function (vendor) { // 需要进行判断的选择
  13977. $scope.vendorInfo = vendor;
  13978. $scope.ensure = true;
  13979. };
  13980. $scope.checkVendor = function (vendor) { // 直接选择
  13981. $modalInstance.close(vendor);
  13982. }
  13983. }]);
  13984. /**
  13985. * 我的客户
  13986. */
  13987. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster) {
  13988. $scope.userInfoResult = true;
  13989. AuthenticationService.getAuthentication().success(function (data) {
  13990. $scope.loading = false;
  13991. $scope.thisUser = data;
  13992. });
  13993. var getCustInfos = function (custuu) {
  13994. if (custuu) {
  13995. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  13996. $scope.custInfos = data;
  13997. var getPage = function (page, size) {
  13998. if ($scope.custInfos) {
  13999. var result = {};
  14000. result.totalCount = $scope.custInfos.length;
  14001. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  14002. if ($scope.custInfos.length % size == 0) {
  14003. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  14004. } else {
  14005. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  14006. }
  14007. result.first = page == 1;
  14008. result.last = page == result.totalPage;
  14009. result.page = page;
  14010. result.next = page - 0 + 1;
  14011. result.pre = page - 1;
  14012. return result;
  14013. }
  14014. }
  14015. $scope.userdata = getPage(1, 4);
  14016. $scope.first = function () {
  14017. $scope.userdata = getPage($scope.userdata.pre, 4);
  14018. }
  14019. $scope.last = function () {
  14020. $scope.userdata = getPage($scope.userdata.next, 4);
  14021. }
  14022. }, function (response) {
  14023. $scope.loading = false;
  14024. toaster.pop('error', '数据加载失败', response.data);
  14025. });
  14026. }
  14027. }
  14028. // 分配权限
  14029. $scope.addUserInfo = function (customer) {
  14030. //TODO
  14031. if ($scope.thisUser.sys) {
  14032. var modalInstance = $modal.open({
  14033. animation: true,
  14034. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  14035. controller: 'AddUserInfoCtrl',
  14036. resolve: {
  14037. customer: function () {
  14038. return customer;
  14039. }
  14040. }
  14041. });
  14042. modalInstance.result.then(function (changed, checked) {
  14043. if (changed) {
  14044. if (checked)
  14045. $scope.newUser.roles = checked;
  14046. else
  14047. loadUsers();
  14048. }
  14049. });
  14050. } else {
  14051. toaster.pop('error', '您没有分配用户的权限!');
  14052. }
  14053. };
  14054. $scope.showUserInfo = function (customer, boo) {
  14055. $scope.custInfo = customer;
  14056. if (boo) {
  14057. getCustInfos(customer.myEnterprise.uu);
  14058. $scope.userInfoResult = true;
  14059. }
  14060. }
  14061. $scope.customerParams = new ngTableParams({
  14062. page: 1,
  14063. count: 20
  14064. }, {
  14065. total: 0,
  14066. counts: [5, 10, 25, 50],
  14067. getData: function ($defer, params) {
  14068. $scope.loading = true;
  14069. VendorService.customer.get(BaseService.parseParams(params.url()), function (page) {
  14070. $scope.loading = false;
  14071. if (page) {
  14072. params.total(page.totalElement);
  14073. $defer.resolve(page.content);
  14074. }
  14075. $scope.totalCount = page.totalElement;
  14076. }, function (response) {
  14077. $scope.loading = false;
  14078. toaster.pop('error', '数据加载失败', response.data);
  14079. });
  14080. }
  14081. });
  14082. }]);
  14083. /**
  14084. * 我的供应商
  14085. */
  14086. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  14087. BaseService.scrollBackToTop();
  14088. // 搜索框回车
  14089. $scope.onSearch = function (keyword) {
  14090. $scope.keyword = keyword;
  14091. $scope.customerParams.page(1);
  14092. $scope.customerParams.reload();
  14093. };
  14094. $scope.customerParams = new ngTableParams({
  14095. page: 1,
  14096. count: 20
  14097. }, {
  14098. total: 0,
  14099. counts: [5, 10, 25, 50],
  14100. getData: function ($defer, params) {
  14101. $scope.loading = true;
  14102. var pageParams = params.url();
  14103. pageParams.keyword = $scope.keyword;
  14104. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  14105. $scope.loading = false;
  14106. if (page) {
  14107. params.total(page.totalElement);
  14108. $scope.total = page.totalElement;
  14109. $defer.resolve(page.content);
  14110. }
  14111. $scope.totalCount = page.totalElement;
  14112. }, function (response) {
  14113. $scope.loading = false;
  14114. toaster.pop('error', '数据加载失败', response.data);
  14115. });
  14116. }
  14117. });
  14118. //设置消息已读
  14119. var setOrdersRead = function () {
  14120. var ids=[];
  14121. Vendor.setVendorRead({}, ids, function (message) {
  14122. });
  14123. };
  14124. setOrdersRead();
  14125. // 查看供应商详情
  14126. $scope.VendorDetail = function (id, uu) {
  14127. $rootScope.vendorId = id;
  14128. $rootScope.vendoruu = uu;
  14129. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  14130. }
  14131. // 向企业购买
  14132. $scope.purcByEn = function (businessCode) {
  14133. $rootScope.businessCode = businessCode;
  14134. window.location.hash = "#/purc/addOrder";
  14135. }
  14136. }]);
  14137. /**
  14138. * 供应商详情
  14139. */
  14140. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  14141. BaseService.scrollBackToTop();
  14142. $scope.vendorContacts = [];
  14143. var loadData = function () {
  14144. Vendor.getVendorDetail({id: $stateParams.id}, {}, function (data) {
  14145. $scope.vendor = data.vendorEnterprise;
  14146. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  14147. $scope.vendorContacts = data;
  14148. });
  14149. }, function (response) {
  14150. toaster.pop('error', '提示', response.data);
  14151. });
  14152. };
  14153. loadData();
  14154. // 新增供应商联系人
  14155. $scope.addContact = function (uu) {
  14156. var modalInstance = $modal.open({
  14157. animation: true,
  14158. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  14159. controller: 'AddContacCtrl',
  14160. resolve: {}
  14161. });
  14162. modalInstance.result.then(function (data) {
  14163. $scope.contact = data;
  14164. $scope.contact.venduu = uu;
  14165. Vendor.saveContact({}, $scope.contact, function (data) {
  14166. toaster.pop('success', '提示', '联系人保存成功');
  14167. $scope.vendorContacts.push(data);
  14168. }, function (response) {
  14169. toaster.pop('error', '失败', response.data);
  14170. });
  14171. });
  14172. };
  14173. // 编辑供应商联系人
  14174. $scope.edit = function (contact) {
  14175. var modalInstance = $modal.open({
  14176. animation: true,
  14177. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  14178. controller: 'EditContacCtrl',
  14179. resolve: {
  14180. contact: function () {
  14181. return contact;
  14182. }
  14183. }
  14184. });
  14185. modalInstance.result.then(function (data) {
  14186. Vendor.saveContact({}, data, function (data) {
  14187. loadData();
  14188. toaster.pop('success', '提示', '联系人修改成功');
  14189. }, function (response) {
  14190. toaster.pop('error', '失败', response.data);
  14191. });
  14192. });
  14193. }
  14194. // 删除供应商联系人
  14195. $scope.deleteById = function (id, index) {
  14196. $scope.vendorContacts.splice(index, 1);
  14197. Vendor.deleteContact({id: id}, {}, function (data) {
  14198. toaster.pop('success', '提示', '供应商联系人删除成功');
  14199. loadData();
  14200. }, function (response) {
  14201. toaster.pop('error', '提示', response.data);
  14202. });
  14203. }
  14204. // 供应商物料信息
  14205. $scope.viewProdList = function (uu) {
  14206. $scope.uu = uu;
  14207. $scope.tableParams.page(1);
  14208. $scope.tableParams.reload();
  14209. };
  14210. // 搜索框回车
  14211. $scope.onSearch = function (keyword) {
  14212. $scope.keyword = keyword;
  14213. $scope.tableParams.page(1);
  14214. $scope.tableParams.reload();
  14215. };
  14216. // 供应商物料信息
  14217. $scope.tableParams = new ngTableParams({
  14218. page: 1,
  14219. count: 20
  14220. }, {
  14221. total: 0,
  14222. counts: [5, 10, 25, 50],
  14223. getData: function ($defer, params) {
  14224. $scope.loading = true;
  14225. var pageParams = params.url();
  14226. pageParams.custUU = $scope.uu;
  14227. pageParams.keyword = $scope.keyword;
  14228. $scope.tip = $scope.keyword;
  14229. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  14230. $scope.loading = false;
  14231. if (page) {
  14232. params.total(page.totalElement);
  14233. $scope.total = page.totalElement;
  14234. $defer.resolve(page.content);
  14235. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  14236. }
  14237. }, function (response) {
  14238. $scope.loading = false;
  14239. toaster.pop('error', '数据加载失败', response.data);
  14240. });
  14241. }
  14242. });
  14243. /**
  14244. * 选中单个物料购买
  14245. * @param businessCode
  14246. * @param id
  14247. */
  14248. $scope.PurcByEnAndProd = function (businessCode, id) {
  14249. $rootScope.businessCode = businessCode;
  14250. $rootScope.prodId = id;
  14251. window.location.hash = "#/purc/addOrder";
  14252. }
  14253. /**
  14254. * 询价
  14255. */
  14256. $scope.PurcInquiry = function (businessCode, id) {
  14257. $rootScope.prodId = id;
  14258. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  14259. }
  14260. }]);
  14261. /**
  14262. * 编辑供应商联系人
  14263. */
  14264. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function ($scope, toaster, $modalInstance, contact) {
  14265. $scope.contact = angular.copy(contact);
  14266. $scope.save = function (contact) {
  14267. $modalInstance.close(contact);
  14268. };
  14269. $scope.cancel = function () {
  14270. $modalInstance.dismiss();
  14271. }
  14272. }]);
  14273. /**
  14274. * 新增供应商联系人
  14275. */
  14276. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function ($scope, toaster, $modalInstance) {
  14277. $scope.save = function (contact) {
  14278. $modalInstance.close(contact);
  14279. };
  14280. $scope.cancel = function () {
  14281. $modalInstance.dismiss();
  14282. }
  14283. }]);
  14284. /**
  14285. * 建立合作关系申请 (我的合作伙伴)
  14286. */
  14287. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  14288. BaseService.scrollBackToTop();
  14289. $scope.status = "partner";
  14290. $scope.active = 'done';
  14291. var getRequestStatus = function (active) {
  14292. var fn = 'getAllRequest';
  14293. switch (active) {
  14294. case 'done':
  14295. fn = 'getRequestDone';
  14296. break;
  14297. case 'todo':
  14298. fn = 'getRequestTodo';
  14299. break;
  14300. case 'end':
  14301. fn = 'getRequestEnd';
  14302. break;
  14303. }
  14304. return fn;
  14305. }
  14306. // 切换单据类型
  14307. $scope.setActive = function (state) {
  14308. if ($scope.active != state) {
  14309. $scope.active = state;
  14310. if ($scope.tableParams.page() == 1)
  14311. $scope.tableParams.reload();
  14312. else
  14313. $scope.tableParams.page(1);
  14314. }
  14315. };
  14316. // 切换数据来源(正常数据 or 历史数据)
  14317. var getService = function () {
  14318. return AddPartnerMyRequest;
  14319. };
  14320. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14321. page: 1,
  14322. count: 20,
  14323. sorting: {}
  14324. }, {
  14325. total: 0,
  14326. counts: [],
  14327. getData: function ($defer, params) { // 获取数据的方法
  14328. $scope.loading = true;
  14329. var pageParams = params.url();
  14330. pageParams.keyword = $scope.keyword;
  14331. if ($rootScope.vendName) {
  14332. pageParams.keyword = $rootScope.vendName;
  14333. $scope.keyword = $rootScope.vendName;
  14334. $rootScope.vendName = null;
  14335. }
  14336. $scope.tip = $scope.keyword;
  14337. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14338. $scope.loading = false;
  14339. if (page) {
  14340. params.total(page.totalElement);
  14341. $defer.resolve(page.content);
  14342. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14343. }
  14344. }, function (response) {
  14345. $scope.loading = false;
  14346. toaster.pop('error', '数据加载失败', response.data);
  14347. });
  14348. }
  14349. });
  14350. // 再次申请
  14351. $scope.addAgain = function (name, businessCode) {
  14352. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14353. if (data.success) {
  14354. toaster.pop("success", '添加成功', data.success);
  14355. $scope.tableParams.reload();
  14356. }
  14357. if (data.error) {
  14358. toaster.pop("error", '添加失败', data.error);
  14359. }
  14360. }, function (response) {
  14361. toaster.pop('error', '失败', response.data);
  14362. });
  14363. }
  14364. // 添加为供应商
  14365. $scope.addSupplier = function (vendUID) {
  14366. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14367. if (data.success) {
  14368. toaster.pop('success', '提示', data.success);
  14369. $scope.tableParams.reload();
  14370. }
  14371. if (data.error) {
  14372. toaster.pop('error', '提示', data.error);
  14373. }
  14374. }, function (response) {
  14375. toaster.pop('error', '失败', response.data);
  14376. })
  14377. };
  14378. // 添加为供应商
  14379. $scope.addServicer = function (vendUID) {
  14380. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14381. if (data.success) {
  14382. toaster.pop('success', '提示', data.success);
  14383. $scope.tableParams.reload();
  14384. }
  14385. if (data.error) {
  14386. toaster.pop('error', '提示', data.error);
  14387. }
  14388. }, function (response) {
  14389. toaster.pop('error', '失败', response.data);
  14390. })
  14391. };
  14392. // 添加客户
  14393. $scope.addCust = function (vendUID) {
  14394. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14395. if (data.success) {
  14396. toaster.pop('success', '提示', data.success);
  14397. $scope.tableParams.reload();
  14398. }
  14399. if (data.error) {
  14400. toaster.pop('error', '提示', data.error);
  14401. }
  14402. }, function (response) {
  14403. toaster.pop('error', '失败', response.data);
  14404. })
  14405. };
  14406. // 搜索框回车
  14407. $scope.onSearch = function () {
  14408. $scope.tableParams.page(1);
  14409. $scope.tableParams.reload();
  14410. };
  14411. // 同意申请
  14412. $scope.agree = function (id) {
  14413. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14414. if (data.success) {
  14415. toaster.pop('success', '提示', '操作成功');
  14416. }
  14417. if (data.error) {
  14418. toaster.pop('error', '提示', '操作失败');
  14419. }
  14420. // $scope.tableParams.reload();
  14421. $window.location.reload();
  14422. }, function (response) {
  14423. toaster.pop('error', '提示', response.data);
  14424. });
  14425. };
  14426. // 拒绝申请
  14427. $scope.refuse = function (id, reason) {
  14428. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14429. if (data.success) {
  14430. toaster.pop('success', '提示', '操作成功');
  14431. }
  14432. if (data.error) {
  14433. toaster.pop('error', '提示', '操作失败');
  14434. }
  14435. // $scope.tableParams.reload();
  14436. $window.location.reload();
  14437. }, function (response) {
  14438. toaster.pop('error', '提示', response.data);
  14439. });
  14440. };
  14441. // 取消供应商关系
  14442. $scope.relieve = function (id) {
  14443. VendorInfo.relieve({id: id}, {}, function (data) {
  14444. if (data.success) {
  14445. toaster.pop('success', '提示', data.success);
  14446. }
  14447. // $scope.tableParams.page(1);
  14448. $scope.tableParams.reload();
  14449. }, function (response) {
  14450. toaster.pop('error', '提示', response.data);
  14451. });
  14452. };
  14453. // 建立供应商关系
  14454. $scope.activeVend = function (id) {
  14455. VendorInfo.activeVend({id: id}, {}, function (data) {
  14456. if (data.success) {
  14457. toaster.pop('success', '提示', data.success);
  14458. }
  14459. // $scope.tableParams.page(1);
  14460. $scope.tableParams.reload();
  14461. }, function (response) {
  14462. toaster.pop('error', '提示', response.data);
  14463. });
  14464. };
  14465. // 取消服务商
  14466. $scope.relieveServicer = function (id) {
  14467. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14468. if (data.success) {
  14469. toaster.pop('success', '提示', data.success);
  14470. }
  14471. $scope.tableParams.reload();
  14472. }, function (response) {
  14473. toaster.pop('error', '提示', response.data);
  14474. });
  14475. };
  14476. // 启用服务商
  14477. $scope.activeServicer = function (id) {
  14478. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14479. if (data.success) {
  14480. toaster.pop('success', '提示', data.success);
  14481. }
  14482. $scope.tableParams.reload();
  14483. }, function (response) {
  14484. toaster.pop('error', '提示', response.data);
  14485. });
  14486. };
  14487. // 取消客户关系
  14488. $scope.disableCust = function (id) {
  14489. VendorInfo.disableCust({id: id}, {}, function (data) {
  14490. if (data.success) {
  14491. toaster.pop('success', '提示', data.success);
  14492. }
  14493. $scope.tableParams.page(1);
  14494. $scope.tableParams.reload();
  14495. }, function (response) {
  14496. toaster.pop('error', '提示', response.data);
  14497. });
  14498. };
  14499. // 激活客户关系
  14500. $scope.activeCust = function (id) {
  14501. VendorInfo.activeCust({id: id}, {}, function (data) {
  14502. if (data.success) {
  14503. toaster.pop('success', '提示', data.success);
  14504. }
  14505. $scope.tableParams.page(1);
  14506. $scope.tableParams.reload();
  14507. }, function (response) {
  14508. toaster.pop('error', '提示', response.data);
  14509. });
  14510. }
  14511. }]);
  14512. /**
  14513. * 建立合作关系申请 (新的合作伙伴)
  14514. */
  14515. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  14516. BaseService.scrollBackToTop();
  14517. $scope.status = "partner";
  14518. $scope.active = 'all'; // 所有申请记录
  14519. var getRequestStatus = function (active) {
  14520. var fn = 'getAllRequest';
  14521. switch (active) {
  14522. case 'done':
  14523. fn = 'getRequestDone';
  14524. break;
  14525. case 'todo':
  14526. fn = 'getRequestTodo';
  14527. break;
  14528. case 'end':
  14529. fn = 'getRequestEnd';
  14530. break;
  14531. }
  14532. return fn;
  14533. }
  14534. // 切换单据类型
  14535. $scope.setActive = function (state) {
  14536. if ($scope.active != state) {
  14537. $scope.active = state;
  14538. if ($scope.tableParams.page() == 1)
  14539. $scope.tableParams.reload();
  14540. else
  14541. $scope.tableParams.page(1);
  14542. }
  14543. };
  14544. // 切换数据来源(正常数据 or 历史数据)
  14545. var getService = function () {
  14546. return AddPartnerMyRequest;
  14547. };
  14548. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14549. page: 1,
  14550. count: 20,
  14551. sorting: {}
  14552. }, {
  14553. total: 0,
  14554. counts: [],
  14555. getData: function ($defer, params) { // 获取数据的方法
  14556. $scope.loading = true;
  14557. var pageParams = params.url();
  14558. pageParams.keyword = $scope.keyword;
  14559. if ($rootScope.vendName) {
  14560. pageParams.keyword = $rootScope.vendName;
  14561. $scope.keyword = $rootScope.vendName;
  14562. $rootScope.vendName = null;
  14563. }
  14564. $scope.tip = $scope.keyword;
  14565. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14566. $scope.loading = false;
  14567. if (page) {
  14568. params.total(page.totalElement);
  14569. $defer.resolve(page.content);
  14570. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14571. }
  14572. }, function (response) {
  14573. $scope.loading = false;
  14574. toaster.pop('error', '数据加载失败', response.data);
  14575. });
  14576. }
  14577. });
  14578. // 再次申请
  14579. $scope.addAgain = function (name, businessCode) {
  14580. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14581. if (data.success) {
  14582. toaster.pop("success", '添加成功', data.success);
  14583. $scope.tableParams.reload();
  14584. }
  14585. if (data.error) {
  14586. toaster.pop("error", '添加失败', data.error);
  14587. }
  14588. }, function (response) {
  14589. toaster.pop('error', '失败', response.data);
  14590. });
  14591. }
  14592. // 添加为供应商
  14593. $scope.addSupplier = function (vendUID) {
  14594. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14595. if (data.success) {
  14596. toaster.pop('success', '提示', data.success);
  14597. $scope.tableParams.reload();
  14598. }
  14599. if (data.error) {
  14600. toaster.pop('error', '提示', data.error);
  14601. }
  14602. }, function (response) {
  14603. toaster.pop('error', '失败', response.data);
  14604. })
  14605. };
  14606. // 添加为供应商
  14607. $scope.addServicer = function (vendUID) {
  14608. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14609. if (data.success) {
  14610. toaster.pop('success', '提示', data.success);
  14611. $scope.tableParams.reload();
  14612. }
  14613. if (data.error) {
  14614. toaster.pop('error', '提示', data.error);
  14615. }
  14616. }, function (response) {
  14617. toaster.pop('error', '失败', response.data);
  14618. })
  14619. };
  14620. // 添加客户
  14621. $scope.addCust = function (vendUID) {
  14622. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14623. if (data.success) {
  14624. toaster.pop('success', '提示', data.success);
  14625. $scope.tableParams.reload();
  14626. }
  14627. if (data.error) {
  14628. toaster.pop('error', '提示', data.error);
  14629. }
  14630. }, function (response) {
  14631. toaster.pop('error', '失败', response.data);
  14632. })
  14633. };
  14634. // 搜索框回车
  14635. $scope.onSearch = function () {
  14636. $scope.tableParams.page(1);
  14637. $scope.tableParams.reload();
  14638. };
  14639. // 同意申请
  14640. $scope.agree = function (id) {
  14641. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14642. if (data.success) {
  14643. toaster.pop('success', '提示', '操作成功');
  14644. }
  14645. if (data.error) {
  14646. toaster.pop('error', '提示', '操作失败');
  14647. }
  14648. // $scope.tableParams.reload();
  14649. $window.location.reload();
  14650. }, function (response) {
  14651. toaster.pop('error', '提示', response.data);
  14652. });
  14653. };
  14654. AddPartnerMyRequest.requestAmount({}, function (data) {
  14655. $scope.requestTodo = data;
  14656. });
  14657. // 拒绝申请
  14658. $scope.refuse = function (id, reason) {
  14659. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14660. if (data.success) {
  14661. toaster.pop('success', '提示', '操作成功');
  14662. }
  14663. if (data.error) {
  14664. toaster.pop('error', '提示', '操作失败');
  14665. }
  14666. // $scope.tableParams.reload();
  14667. $window.location.reload();
  14668. }, function (response) {
  14669. toaster.pop('error', '提示', response.data);
  14670. });
  14671. };
  14672. // 取消供应商关系
  14673. $scope.relieve = function (id) {
  14674. VendorInfo.relieve({id: id}, {}, function (data) {
  14675. if (data.success) {
  14676. toaster.pop('success', '提示', data.success);
  14677. }
  14678. // $scope.tableParams.page(1);
  14679. $scope.tableParams.reload();
  14680. }, function (response) {
  14681. toaster.pop('error', '提示', response.data);
  14682. });
  14683. }
  14684. // 建立供应商关系
  14685. $scope.activeVend = function (id) {
  14686. VendorInfo.activeVend({id: id}, {}, function (data) {
  14687. if (data.success) {
  14688. toaster.pop('success', '提示', data.success);
  14689. }
  14690. // $scope.tableParams.page(1);
  14691. $scope.tableParams.reload();
  14692. }, function (response) {
  14693. toaster.pop('error', '提示', response.data);
  14694. });
  14695. }
  14696. // 取消服务商
  14697. $scope.relieveServicer = function (id) {
  14698. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14699. if (data.success) {
  14700. toaster.pop('success', '提示', data.success);
  14701. }
  14702. $scope.tableParams.reload();
  14703. }, function (response) {
  14704. toaster.pop('error', '提示', response.data);
  14705. });
  14706. }
  14707. // 启用服务商
  14708. $scope.activeServicer = function (id) {
  14709. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14710. if (data.success) {
  14711. toaster.pop('success', '提示', data.success);
  14712. }
  14713. $scope.tableParams.reload();
  14714. }, function (response) {
  14715. toaster.pop('error', '提示', response.data);
  14716. });
  14717. }
  14718. // 取消客户关系
  14719. $scope.disableCust = function (id) {
  14720. VendorInfo.disableCust({id: id}, {}, function (data) {
  14721. if (data.success) {
  14722. toaster.pop('success', '提示', data.success);
  14723. }
  14724. // $scope.tableParams.page(1);
  14725. $scope.tableParams.reload();
  14726. }, function (response) {
  14727. toaster.pop('error', '提示', response.data);
  14728. });
  14729. }
  14730. // 激活客户关系
  14731. $scope.activeCust = function (id) {
  14732. VendorInfo.activeCust({id: id}, {}, function (data) {
  14733. if (data.success) {
  14734. toaster.pop('success', '提示', data.success);
  14735. }
  14736. // $scope.tableParams.page(1);
  14737. $scope.tableParams.reload();
  14738. }, function (response) {
  14739. toaster.pop('error', '提示', response.data);
  14740. });
  14741. }
  14742. }]);
  14743. /**
  14744. * 建立合作关系处理申请
  14745. */
  14746. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', '$window', function ($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest, $window) {
  14747. BaseService.scrollBackToTop();
  14748. $scope.active = 'todo';
  14749. var getMessagetStatus = function (active) {
  14750. var fn = 'getAllMessage';
  14751. switch (active) {
  14752. case 'done':
  14753. fn = 'getMessageDone';
  14754. break;
  14755. case 'todo':
  14756. fn = 'getMessageTodo';
  14757. break;
  14758. case 'end':
  14759. fn = 'getMessageEnd';
  14760. break;
  14761. }
  14762. return fn;
  14763. }
  14764. // 切换单据类型
  14765. $scope.setActive = function (state) {
  14766. if ($scope.active != state) {
  14767. $scope.active = state;
  14768. if ($scope.tableParams.page() == 1)
  14769. $scope.tableParams.reload();
  14770. else
  14771. $scope.tableParams.page(1);
  14772. }
  14773. };
  14774. var getService = function () {
  14775. return AddPartnerMyMessage;
  14776. };
  14777. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14778. page: 1,
  14779. count: 20,
  14780. sorting: {}
  14781. }, {
  14782. total: 0,
  14783. counts: [5, 10, 15, 25, 50],
  14784. getData: function ($defer, params) { // 获取数据的方法
  14785. $scope.loading = true;
  14786. var pageParams = params.url();
  14787. pageParams.searchFilter = { // 筛选条件
  14788. keyword: $scope.keyword,
  14789. };
  14790. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14791. $scope.loading = false;
  14792. if (page) {
  14793. params.total(page.totalElement);
  14794. $defer.resolve(page.content);
  14795. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14796. }
  14797. }, function (response) {
  14798. $scope.loading = false;
  14799. toaster.pop('error', '数据加载失败', response.data);
  14800. });
  14801. }
  14802. });
  14803. // 同意申请
  14804. $scope.agree = function (id) {
  14805. AddPartner.agreeReq
  14806. uest({id: id}, {}, function (data) {
  14807. if (data.success) {
  14808. toaster.pop('success', '提示', '操作成功');
  14809. }
  14810. if (data.error) {
  14811. toaster.pop('error', '提示', '操作失败');
  14812. }
  14813. // $scope.tableParams.reload();
  14814. $window.location.reload();
  14815. }, function (response) {
  14816. toaster.pop('error', '提示', response.data);
  14817. });
  14818. };
  14819. // 拒绝申请
  14820. $scope.refuse = function (id, reason) {
  14821. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14822. if (data.success) {
  14823. toaster.pop('success', '提示', '操作成功');
  14824. }
  14825. if (data.error) {
  14826. toaster.pop('error', '提示', '操作失败');
  14827. }
  14828. // $scope.tableParams.reload();
  14829. $window.location.reload();
  14830. }, function (response) {
  14831. toaster.pop('error', '提示', response.data);
  14832. });
  14833. };
  14834. $scope.status = 'get';
  14835. }]);
  14836. /**
  14837. * 我的合作伙伴
  14838. */
  14839. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function ($scope, toaster, GetProductInfo, BaseService) {
  14840. BaseService.scrollBackToTop();
  14841. // 默认显示合作伙伴
  14842. $scope.status = 'news';
  14843. // 获取所有的合作伙伴
  14844. GetProductInfo.getAllPartners({}, function (data) {
  14845. $scope.partners = data;
  14846. }, function (res) {
  14847. toaster.pop('error', '获取列表失败', res.data);
  14848. });
  14849. // 添加为客户
  14850. $scope.addCust = function (partner) {
  14851. GetProductInfo.addCust({}, partner, function (data) {
  14852. toaster.pop('success', '提示', '添加客户成功');
  14853. $scope.tableParams.reload();
  14854. }, function (response) {
  14855. toaster.pop('error', '添加客户失败', response.data);
  14856. });
  14857. }
  14858. // 添加为供应商
  14859. $scope.addSupplier = function (partner) {
  14860. GetProductInfo.addSupplier({}, partner, function (data) {
  14861. toaster.pop('success', '提示', '添加供应商成功');
  14862. $scope.tableParams.reload();
  14863. }, function (response) {
  14864. toaster.pop('error', '添加供应商失败', response.data);
  14865. });
  14866. }
  14867. }]);
  14868. /**
  14869. * 财务对账时,企业进行筛选操作
  14870. */
  14871. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', 'VendorService', 'ngTableParams', 'BaseService', function ($scope, $modalInstance, suuorname, FaApCheck, VendorService, ngTableParams, BaseService) {
  14872. var getData = function () {
  14873. $scope.loading = true;
  14874. FaApCheck.getAllCustomers(function (data) {
  14875. $scope.custs = data;
  14876. $scope.loading = false;
  14877. });
  14878. };
  14879. getData();
  14880. $scope.customerParams = new ngTableParams({
  14881. page: 1,
  14882. count: 20
  14883. }, {
  14884. total: 0,
  14885. counts: [5, 10, 25, 50],
  14886. getData: function ($defer, params) {
  14887. $scope.loading = true;
  14888. var pageParams = params.url();
  14889. pageParams.keyword = $scope.keyword;
  14890. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  14891. $scope.loading = false;
  14892. if (page) {
  14893. params.total(page.totalElement);
  14894. $defer.resolve(page.content);
  14895. }
  14896. $scope.totalCount = page.totalElement;
  14897. }, function (response) {
  14898. $scope.loading = false;
  14899. toaster.pop('error', '数据加载失败', response.data);
  14900. });
  14901. }
  14902. });
  14903. // 搜索框回车
  14904. $scope.onSearch = function (keyword) {
  14905. $scope.customerParams.page(1);
  14906. $scope.customerParams.reload();
  14907. $scope.tip = keyword;
  14908. };
  14909. $scope.select = function (customer) {
  14910. if (customer.apcheck != 0) {
  14911. $modalInstance.close(customer);
  14912. }
  14913. }
  14914. $scope.close = function () {
  14915. $modalInstance.dismiss();
  14916. }
  14917. }]);
  14918. /**
  14919. * 跳转到企业圈
  14920. */
  14921. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function ($scope, GetProductInfo, toaster) {
  14922. GetProductInfo.businessGroups({}, function (data) {
  14923. window.open(data.url);
  14924. }, function (response) {
  14925. toaster.pop('error', '提示', response.data);
  14926. });
  14927. }]);
  14928. /**
  14929. * 购物车
  14930. */
  14931. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', 'cartList', 'PurchaseOrder', function ($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout, cartList, PurchaseOrder) {
  14932. BaseService.scrollBackToTop();
  14933. $scope.active = 'all';
  14934. $scope.agreedText = '全部';
  14935. $scope.dateZoneText = '一个月内';
  14936. $scope.condition = {dateZone: 1};
  14937. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14938. $scope.hasClick = false;
  14939. /* 时间筛选初始化*/
  14940. var fromDate = new Date();
  14941. var toDate = new Date();
  14942. fromDate.setMonth(fromDate.getMonth() - 1);
  14943. fromDate.setHours(0, 0, 0, 0);
  14944. toDate.setHours(23, 59, 59, 999);
  14945. $scope.condition.dateFrom = fromDate;
  14946. $scope.condition.dateTo = toDate;
  14947. $scope.changeDateZone = function (zone) {
  14948. $scope.condition.dateZone = zone;
  14949. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14950. $scope.condition.$dateZoneOpen = false;
  14951. getDateCondition(zone, $scope.condition);
  14952. $scope.tableParams.page(1);
  14953. $scope.tableParams.reload();
  14954. };
  14955. $scope.changeDeliveryZone = function (zone) {
  14956. $scope.condition.deliveryZoneText = zone;
  14957. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  14958. $scope.condition.$delievryZoneOpen = false;
  14959. getDelveryCondition(zone, $scope.condition);
  14960. $scope.tableParams.reload();
  14961. };
  14962. $scope.openDatePicker = function ($event, item, openParam) {
  14963. $event.preventDefault();
  14964. $event.stopPropagation();
  14965. item[openParam] = !item[openParam];
  14966. };
  14967. $scope.openFilterDatePicker = function ($event, item, openParam) {
  14968. $event.preventDefault();
  14969. $event.stopPropagation();
  14970. item[openParam] = !item[openParam];
  14971. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  14972. $scope.tableParams.reload();
  14973. }
  14974. };
  14975. $scope.parseDate = function (dateStr) {
  14976. if (dateStr)
  14977. return Date.parse(dateStr, 'yyyy-MM-dd');
  14978. return new Date();
  14979. };
  14980. $scope.setActive = function (state) {
  14981. if ($scope.active != state) {
  14982. $scope.active = state;
  14983. if ($scope.tableParams.page() == 1)
  14984. $scope.tableParams.reload();
  14985. else
  14986. $scope.tableParams.page(1);
  14987. }
  14988. };
  14989. $scope.searchMethod = false;
  14990. var getService = function () {
  14991. return $scope.searchMethod ? cartList : getCartList;
  14992. };
  14993. var getTodoCartCount = function () {
  14994. cartOperation.getTodoCartCount({}, function (data) {
  14995. $scope.countTodo = data.cartTodo;
  14996. });
  14997. };
  14998. getTodoCartCount();
  14999. $scope.tableParams = new ngTableParams({
  15000. page: 1,
  15001. count: 20,
  15002. sorting: {
  15003. date: 'desc'
  15004. }
  15005. }, {
  15006. total: 0,
  15007. counts: [5, 10, 25, 50],
  15008. getData: function ($defer, params) {
  15009. $scope.loading = true;
  15010. var pageParams = params.url();
  15011. pageParams.searchFilter = { // 筛选条件
  15012. keyword: $scope.keyword,
  15013. fromDate: getDateTime($scope.condition.dateFrom),
  15014. endDate: getDateTime($scope.condition.dateTo)
  15015. };
  15016. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  15017. $scope.loading = false;
  15018. if (page) {
  15019. params.total(page.totalElement);
  15020. $defer.resolve(page.content);
  15021. }
  15022. }, function (response) {
  15023. $scope.loading = false;
  15024. toaster.pop('error', '数据加载失败', response.data);
  15025. });
  15026. }
  15027. });
  15028. $scope.getCartTotal = function (items) {
  15029. var sum = 0;
  15030. angular.forEach(items, function (item) {
  15031. sum += item.qty * item.price;
  15032. });
  15033. return sum;
  15034. };
  15035. // 搜索框回车
  15036. $scope.onSearch = function (keyword) {
  15037. // 每次搜索重置获取数据方法
  15038. $scope.searchMethod = false;
  15039. if(keyword != null && keyword != '') {
  15040. $scope.searchMethod = true;
  15041. }
  15042. $scope.tableParams.page(1);
  15043. $scope.tableParams.reload();
  15044. };
  15045. var changeClickStatus = function () {
  15046. $scope.hasClick = true;
  15047. $timeout(function () {
  15048. $scope.hasClick = false;
  15049. }, 500);
  15050. }
  15051. // 提交
  15052. $scope.addtoOrder = function (id) {
  15053. cartOperation.addToOrder({id: id}, {}, function (data) {
  15054. if (data.success) {
  15055. toaster.pop('success', '提示', data.success);
  15056. getTodoCartCount();
  15057. $timeout(function () {
  15058. window.location.hash = '#/purc/order/' + data.id;
  15059. window.location.reload();
  15060. }, 500);
  15061. }
  15062. if (data.error) {
  15063. toaster.pop('error', '提示', data.error);
  15064. }
  15065. }, function (response) {
  15066. toaster.pop('erroer', '提示', response.data);
  15067. });
  15068. };
  15069. // 删除一条主记录
  15070. $scope.deleteCart = function (id) {
  15071. changeClickStatus();
  15072. $scope.loading = true;
  15073. cartOperation.deleteCart({id: id}, {}, function (data) {
  15074. if (data.success) {
  15075. toaster.pop('success', '提示', data.success);
  15076. getTodoCartCount();
  15077. getTodoCartCount();
  15078. $timeout(function () {
  15079. $scope.tableParams.page(1);
  15080. $scope.tableParams.reload();
  15081. }, 500);
  15082. }
  15083. if (data.error) {
  15084. toaster.pop('error', '提示', data.error);
  15085. }
  15086. $scope.loading = false;
  15087. }, function (response) {
  15088. $scope.loading = false;
  15089. toaster.pop('erroer', '提示', response.data);
  15090. });
  15091. };
  15092. // 删除一条明细
  15093. $scope.deleteDetail = function (id) {
  15094. changeClickStatus();
  15095. $scope.loading = true;
  15096. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  15097. if (data.success) {
  15098. toaster.pop('success', '提示', data.success);
  15099. $timeout(function () {
  15100. $scope.tableParams.reload();
  15101. }, 500);
  15102. }
  15103. if (data.error) {
  15104. toaster.pop('error', '提示', data.error);
  15105. }
  15106. $scope.loading = false;
  15107. }, function (response) {
  15108. toaster.pop('erroer', '提示', response.data);
  15109. $scope.loading = false;
  15110. });
  15111. };
  15112. // 清空购物车
  15113. $scope.clearCart = function () {
  15114. changeClickStatus();
  15115. $scope.loading = true;
  15116. cartOperation.deleteCarts({}, function (data) {
  15117. if (data.success) {
  15118. toaster.pop('success', '提示', data.success);
  15119. getTodoCartCount();
  15120. $timeout(function () {
  15121. $scope.tableParams.reload();
  15122. }, 500);
  15123. }
  15124. if (data.error) {
  15125. toaster.pop('error', '提示', data.error);
  15126. }
  15127. $scope.loading = false;
  15128. }, function (response) {
  15129. toaster.pop('erroer', '提示', response.data);
  15130. $scope.loading = false;
  15131. });
  15132. }
  15133. // 复制订单
  15134. $scope.copyorder = function (id) {
  15135. changeClickStatus();
  15136. $scope.loading = true;
  15137. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  15138. if (data.id) {
  15139. toaster.pop('success', '提示', '单据复制成功');
  15140. getTodoCartCount();
  15141. $scope.loading = false;
  15142. window.location.hash = "#purc/cart/" + data.id;
  15143. }
  15144. }, function (response) {
  15145. toaster.pop('error', '提示', response.data);
  15146. $scope.loading = false;
  15147. });
  15148. }
  15149. }]);
  15150. /**
  15151. * 购物车详情
  15152. */
  15153. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', 'recentPrice',
  15154. function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token, recentPrice) {
  15155. BaseService.scrollBackToTop();
  15156. $scope.loading = true;
  15157. var loadData = function () {
  15158. cartOperation.getCartDetail({id: $stateParams.id}, function (data) {
  15159. if (data.code) {
  15160. $scope.order = data;
  15161. var sum = 0;
  15162. angular.forEach($scope.order.orderItems, function (item) {
  15163. sum += item.qty * item.price;
  15164. });
  15165. $scope.order.total = sum;
  15166. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  15167. $scope.contacts = data;
  15168. $scope.order.vendor = $scope.order.venduser;
  15169. });
  15170. $scope.loading = false;
  15171. } else {
  15172. window.location.hash = '#/purc/cart';
  15173. }
  15174. });
  15175. };
  15176. loadData();
  15177. var getToken = function() {
  15178. token.info({userType: 'cart'}, {}, function(data) {
  15179. $scope.token = data.token;
  15180. }, function(response) {
  15181. toaster.pop('error', '提示', response.data);
  15182. });
  15183. }
  15184. getToken();
  15185. // 获取地址信息
  15186. $http.get('resources/citydata/city.json', {
  15187. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  15188. }).then(function (response) {
  15189. $scope.provinces = response.data;
  15190. });
  15191. // 获取收货地址列表
  15192. ShipAddress.shipAddList({}, function (data) {
  15193. $scope.ships = data;
  15194. $scope.order.shipadd = $scope.ships[0];
  15195. });
  15196. //增加商品
  15197. $scope.addProduct = function (index) {
  15198. if ($scope.order.orderItems[index].code == null) {
  15199. toaster.pop('info', '提示', '请先选择商品');
  15200. } else {
  15201. $scope.order.orderItems.push({
  15202. code: null,
  15203. title: null,
  15204. spec: null,
  15205. unit: null,
  15206. qty: null,
  15207. price: null,
  15208. remark: null,
  15209. delivery: null,
  15210. $endDateOpen: false,
  15211. taxrate: $scope.order.rate
  15212. });
  15213. }
  15214. };
  15215. //删除商品
  15216. $scope.deleteProduct = function (index, id) {
  15217. $scope.order.orderItems.splice(index, 1);
  15218. if (id != null) {
  15219. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  15220. if (data.success) {
  15221. loadData();
  15222. }
  15223. if (data.error) {
  15224. toaster.pop('error', '提示', data.error);
  15225. }
  15226. }, function (response) {
  15227. toaster.pop('erroer', '提示', response.data);
  15228. });
  15229. }
  15230. };
  15231. // 搜索框回车
  15232. $scope.onSearch = function (keyword) {
  15233. $scope.keyword = keyword;
  15234. $scope.tableParams.page(1);
  15235. $scope.tableParams.reload();
  15236. };
  15237. $scope.tableParams = new ngTableParams({
  15238. page: 1,
  15239. count: 20
  15240. }, {
  15241. total: 0,
  15242. counts: [5, 10, 25, 50],
  15243. getData: function ($defer, params) {
  15244. $scope.loading = true;
  15245. var pageParams = params.url();
  15246. pageParams.keyword = $scope.keyword;
  15247. $scope.tip = $scope.keyword;
  15248. pageParams.vendUU = $scope.order.receiveCode;
  15249. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  15250. $scope.loading = false;
  15251. if (page) {
  15252. params.total(page.totalElement);
  15253. $scope.total = page.totalElement;
  15254. $defer.resolve(page.content);
  15255. }
  15256. }, function (response) {
  15257. $scope.loading = false;
  15258. toaster.pop('error', '数据加载失败', response.data);
  15259. });
  15260. }
  15261. });
  15262. // 选择
  15263. $scope.check = function (data) {
  15264. var price = null;
  15265. var qty = null;
  15266. var taxRate = null;
  15267. if (data.id) {
  15268. recentPrice.agreed({prId: data.id}, {}, function(response) {
  15269. price = response.price;
  15270. qty = response.qty;
  15271. taxRate = response.taxRate;
  15272. $scope.order.orderItems.push({
  15273. code: data.code,
  15274. title: data.title,
  15275. spec: data.spec,
  15276. unit: data.unit,
  15277. qty: qty,
  15278. price: price,
  15279. remark: null,
  15280. delivery: null,
  15281. prid: data.id,
  15282. taxrate: taxRate,
  15283. prodsource: 'seller',
  15284. });
  15285. });
  15286. }
  15287. };
  15288. // 导入商品信息
  15289. $scope.uplodaByBatch = function () {
  15290. var modalInstance = $modal.open({
  15291. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  15292. controller: 'PurcUploadByBatchCtrl',
  15293. size: 'lg',
  15294. resolve: {}
  15295. });
  15296. modalInstance.result.then(function (data) {
  15297. angular.forEach(data, function (prod) {
  15298. $scope.order.orderItems.push({
  15299. code: prod.code,
  15300. title: data.title,
  15301. unit: 'PCS',
  15302. spec: prod.spec,
  15303. qty: prod.amount,
  15304. price: prod.price,
  15305. remark: prod.remark,
  15306. delivery: prod.date,
  15307. prid: prod.id,
  15308. taxrate: prod.rate
  15309. });
  15310. })
  15311. }, function () {
  15312. });
  15313. }
  15314. // 删除一条主记录
  15315. $scope.deleteCart = function (id) {
  15316. cartOperation.deleteCart({id: id}, {}, function (data) {
  15317. if (data.success) {
  15318. toaster.pop('success', '提示', data.success);
  15319. $timeout(function () {
  15320. window.location.reload();
  15321. }, 500);
  15322. }
  15323. if (data.error) {
  15324. toaster.pop('error', '提示', data.error);
  15325. }
  15326. }, function (response) {
  15327. toaster.pop('erroer', '提示', response.data);
  15328. });
  15329. };
  15330. $scope.getMinDate = function (item) {
  15331. return $filter('date')(new Date, 'yyyy-MM-dd');
  15332. };
  15333. $scope.openDatePicker = function ($event, openParam, index) {
  15334. $event.preventDefault();
  15335. $event.stopPropagation();
  15336. $scope.order.orderItems[index].$endDateOpen = !openParam;
  15337. };
  15338. // 添加到购物车
  15339. $scope.addToCart = function (order) {
  15340. $scope.loading = true;
  15341. if (order.vendor.tel != null) {
  15342. $scope.order.vendusertel = order.vendor.tel;
  15343. }
  15344. if (order.vendor.venduser != null && order.vendor.tel != null) {
  15345. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  15346. }
  15347. if (order.shipadd != null) {
  15348. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  15349. }
  15350. if ($scope.order.date instanceof Date) {
  15351. $scope.order.date = $scope.order.date.getTime();
  15352. }
  15353. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  15354. if ($scope.order.orderItems[i].delivery instanceof Date) {
  15355. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  15356. }
  15357. if ($scope.order.currency != 'RMB') {
  15358. $scope.order.orderItems[i].rate = 0;
  15359. }
  15360. }
  15361. $scope.order.status = 311;
  15362. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  15363. $scope.loading = false;
  15364. toaster.pop('success', '成功', '保存成功');
  15365. loadData();
  15366. }, function (response) {
  15367. $scope.loading = false;
  15368. toaster.pop('error', '保存失败', response.data);
  15369. });
  15370. };
  15371. // 立即购买
  15372. $scope.addToOrder = function (order) {
  15373. $scope.loading = true;
  15374. if (order.vendor.tel != null) {
  15375. $scope.order.vendusertel = order.vendor.tel;
  15376. }
  15377. if (order.vendor.venduser != null && order.vendor.tel != null) {
  15378. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  15379. }
  15380. if (order.shipadd != null) {
  15381. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  15382. }
  15383. if ($scope.order.date instanceof Date) {
  15384. $scope.order.date = $scope.order.date.getTime();
  15385. }
  15386. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  15387. if ($scope.order.orderItems[i].delivery instanceof Date) {
  15388. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  15389. }
  15390. if ($scope.order.currency != 'RMB') {
  15391. $scope.order.orderItems[i].rate = 0;
  15392. }
  15393. }
  15394. $scope.order.status = 200;
  15395. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  15396. $scope.loading = false;
  15397. toaster.pop('success', '成功', '保存成功');
  15398. window.location.hash = '#/purc/order/' + data.id;
  15399. }, function (response) {
  15400. $scope.loading = false;
  15401. toaster.pop('error', '保存失败', response.data);
  15402. });
  15403. };
  15404. // 新增收货地址保存
  15405. $scope.saveShipAddress = function (ship) {
  15406. ship.address = ship.province + ship.city + ship.district;
  15407. ShipAddress.saveAddress({}, ship, function (data) {
  15408. if (data.success) {
  15409. ShipAddress.shipAddList({}, function (data) {
  15410. $scope.ships = data;
  15411. $scope.order.shipadd = $scope.ships[0];
  15412. });
  15413. toaster.pop('success', '提示', data.success);
  15414. }
  15415. if (data.error) {
  15416. toaster.pop('error', '提示', data.error);
  15417. }
  15418. });
  15419. }
  15420. // 新增供应商联系人
  15421. $scope.addContact = function (uu) {
  15422. var modalInstance = $modal.open({
  15423. animation: true,
  15424. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  15425. controller: 'AddContacCtrl',
  15426. resolve: {}
  15427. });
  15428. modalInstance.result.then(function (data) {
  15429. $scope.contact = data;
  15430. $scope.contact.venduu = $scope.order.receiveCode;
  15431. Vendor.saveContact({}, $scope.contact, function (data) {
  15432. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  15433. $scope.contacts = data;
  15434. });
  15435. toaster.pop('success', '提示', '联系人保存成功');
  15436. }, function (response) {
  15437. toaster.pop('error', '失败', response.data);
  15438. });
  15439. });
  15440. }
  15441. }]);
  15442. /**
  15443. * 审批流
  15444. */
  15445. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function ($scope, toaster, $modal, appFlow, BaseService) {
  15446. BaseService.scrollBackToTop();
  15447. $scope.vacation = false;
  15448. $scope.workovertime = false;
  15449. $scope.workdaily = false;
  15450. $scope.feeplease = false;
  15451. $scope.signapp = false;
  15452. appFlow.viewAppFlow({}, function (data) {// 获取已设置的列表
  15453. $scope.nodes = data;
  15454. angular.forEach($scope.nodes, function (node) {
  15455. if (node.appname = '请假单') {
  15456. $scope.vacation = true;
  15457. }
  15458. if (node.appname = '加班单') {
  15459. $scope.workovertime = true;
  15460. }
  15461. if (node.appname = '工作日报') {
  15462. $scope.workdaily = true;
  15463. }
  15464. if (node.appname = '出差单') {
  15465. $scope.feeplease = true;
  15466. }
  15467. if (node.appname = '申诉单') {
  15468. $scope.signapp = true;
  15469. }
  15470. });
  15471. }, function (response) {
  15472. });
  15473. $scope.NoteSet = function () {
  15474. var modalInstance = $modal.open({
  15475. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15476. controller: 'NoteStep1Ctrl',
  15477. size: 'lg',
  15478. resolve: {
  15479. AppName: function () {
  15480. return '请假单';
  15481. }
  15482. }
  15483. });
  15484. modalInstance.result.then(function (data) {
  15485. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15486. if (data.error) {
  15487. toaster.pop('error', '提示', data.error);
  15488. }
  15489. if (data.success) {
  15490. toaster.pop('success', '提示', data.success);
  15491. }
  15492. }, function (response) {
  15493. });
  15494. }, function () {
  15495. });
  15496. }
  15497. $scope.overTimeSet = function () {
  15498. var modalInstance = $modal.open({
  15499. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15500. controller: 'NoteStep1Ctrl',
  15501. size: 'lg',
  15502. resolve: {
  15503. AppName: function () {
  15504. return '加班单';
  15505. }
  15506. }
  15507. });
  15508. modalInstance.result.then(function (data) {
  15509. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15510. if (data.error) {
  15511. toaster.pop('error', '提示', data.error);
  15512. }
  15513. if (data.success) {
  15514. toaster.pop('success', '提示', data.success);
  15515. }
  15516. }, function (response) {
  15517. });
  15518. }, function () {
  15519. });
  15520. }
  15521. $scope.feePleaseSet = function () {
  15522. var modalInstance = $modal.open({
  15523. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15524. controller: 'NoteStep1Ctrl',
  15525. size: 'lg',
  15526. resolve: {
  15527. AppName: function () {
  15528. return '出差单';
  15529. }
  15530. }
  15531. });
  15532. modalInstance.result.then(function (data) {
  15533. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15534. if (data.error) {
  15535. toaster.pop('error', '提示', data.error);
  15536. }
  15537. if (data.success) {
  15538. toaster.pop('success', '提示', data.success);
  15539. }
  15540. }, function (response) {
  15541. });
  15542. }, function () {
  15543. });
  15544. }
  15545. $scope.workDailySet = function () {
  15546. var modalInstance = $modal.open({
  15547. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15548. controller: 'NoteStep1Ctrl',
  15549. size: 'lg',
  15550. resolve: {
  15551. AppName: function () {
  15552. return '工作日报';
  15553. }
  15554. }
  15555. });
  15556. modalInstance.result.then(function (data) {
  15557. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15558. if (data.error) {
  15559. toaster.pop('error', '提示', data.error);
  15560. }
  15561. if (data.success) {
  15562. toaster.pop('success', '提示', data.success);
  15563. }
  15564. }, function (response) {
  15565. });
  15566. }, function () {
  15567. });
  15568. }
  15569. $scope.signAppSet = function () {
  15570. var modalInstance = $modal.open({
  15571. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15572. controller: 'NoteStep1Ctrl',
  15573. size: 'lg',
  15574. resolve: {
  15575. AppName: function () {
  15576. return '申诉单';
  15577. }
  15578. }
  15579. });
  15580. modalInstance.result.then(function (data) {
  15581. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15582. if (data.error) {
  15583. toaster.pop('error', '提示', data.error);
  15584. }
  15585. if (data.success) {
  15586. toaster.pop('success', '提示', data.success);
  15587. }
  15588. }, function (response) {
  15589. });
  15590. }, function () {
  15591. });
  15592. }
  15593. }]);
  15594. /**
  15595. * 审核条件设置
  15596. */
  15597. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function ($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  15598. $scope.appName = AppName;// 标题名称
  15599. $scope.AppFlow = {
  15600. appName: $scope.appName,
  15601. appNodes: {}
  15602. };
  15603. $scope.AppFlow.appNodes = [];
  15604. appFlow.getNodeByName({name: AppName}, {}, function (data) {// 通过单据名称查询单个审批流
  15605. if (data.appNodes.length != 0) {
  15606. $scope.node = data;
  15607. $scope.AppFlow = data;
  15608. }
  15609. }, function () {
  15610. });
  15611. $scope.copy = function () {//复制
  15612. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  15613. toaster.pop('info', '提示', '复制成功');
  15614. $modalInstance.dismiss();
  15615. }
  15616. $scope.paste = function () {
  15617. $scope.AppFlow = {appName: $scope.appName, appNodes: {}};
  15618. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  15619. }
  15620. $scope.clear = function () {// 清空
  15621. $scope.AppFlow = {
  15622. appName: $scope.appName,
  15623. appNodes: {}
  15624. };
  15625. $scope.AppFlow.appNodes = [];
  15626. }
  15627. appFlow.getPositions({}, function (data) {// 获取人员信息
  15628. $scope.users = data;
  15629. }, function (response) {
  15630. });
  15631. appFlow.getPositionInfo({}, function (data) { // 获取职位信息
  15632. $scope.roles = data;
  15633. }, function (response) {
  15634. });
  15635. $scope.SelectUser = function (data) { // 添加人员
  15636. var item = {
  15637. useruu: null,
  15638. username: null,
  15639. level: null
  15640. };
  15641. item.useruu = data.useruu;
  15642. item.username = data.username;
  15643. $scope.AppFlow.appNodes.push(item);
  15644. }
  15645. $scope.SelectRole = function (data) {// 添加职位
  15646. var item = {
  15647. position: null,
  15648. level: null
  15649. };
  15650. item.position = data;
  15651. $scope.AppFlow.appNodes.push(item);
  15652. }
  15653. $scope.deleteNode = function (index) {// 删除节点
  15654. $scope.AppFlow.appNodes.splice(index, 1);
  15655. };
  15656. $scope.saveNode = function () { // 保存
  15657. angular.forEach($scope.AppFlow.appNodes, function (value, key) {
  15658. $scope.AppFlow.appNodes[key].level = key;
  15659. });
  15660. if ($scope.AppFlow.appNodes.length == 0) {
  15661. toaster.pop('info', '提示', '您还未设置审批人');
  15662. } else {
  15663. $modalInstance.close($scope.AppFlow);
  15664. }
  15665. ;
  15666. };
  15667. $scope.cancel = function () {// 取消
  15668. $modalInstance.dismiss();
  15669. }
  15670. }]);
  15671. /***
  15672. * 代采定单
  15673. */
  15674. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', 'getOrderInfo', '$modal', 'CurrentRole', function ($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService, getOrderInfo, $modal, CurrentRole) {
  15675. BaseService.scrollBackToTop();
  15676. // 获取当前用户是否为普通用户
  15677. CurrentRole.isUser({}, {}, function (data) {
  15678. $scope.isUser = data.isUser;
  15679. });
  15680. $scope.active = 'all';
  15681. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15682. $scope.total = null;
  15683. $scope.setActive = function (state) {
  15684. if ($scope.active != state) {
  15685. $scope.active = state;
  15686. if ($scope.tableParams.page() == 1)
  15687. $scope.tableParams.reload();
  15688. else
  15689. $scope.tableParams.page(1);
  15690. }
  15691. };
  15692. $scope.agreedText = '全部';
  15693. $scope.dateZoneText = '不限';
  15694. $scope.condition = {dateZone: 1};
  15695. /* 时间筛选初始化*/
  15696. var fromDate = new Date();
  15697. var toDate = new Date();
  15698. fromDate.setMonth(fromDate.getMonth() - 1);
  15699. fromDate.setHours(0, 0, 0, 0);
  15700. toDate.setHours(23, 59, 59, 999);
  15701. $scope.condition.dateFrom = fromDate;
  15702. $scope.condition.dateTo = toDate;
  15703. $scope.changeDateZone = function (zone) {
  15704. $scope.condition.dateZone = zone;
  15705. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  15706. $scope.condition.$dateZoneOpen = false;
  15707. getDateCondition(zone, $scope.condition);
  15708. $scope.tableParams.page(1);
  15709. $scope.tableParams.reload();
  15710. };
  15711. $scope.openDatePicker = function ($event, item, openParam) {
  15712. $event.preventDefault();
  15713. $event.stopPropagation();
  15714. item[openParam] = !item[openParam];
  15715. };
  15716. $scope.openFilterDatePicker = function ($event, item, openParam) {
  15717. $event.preventDefault();
  15718. $event.stopPropagation();
  15719. item[openParam] = !item[openParam];
  15720. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  15721. $scope.tableParams.reload();
  15722. }
  15723. };
  15724. $scope.searchMethod = false;
  15725. var getSerivce = function() {
  15726. return $scope.searchMethod ? getDeOrder : getOrderInfo;
  15727. }
  15728. getSerivce();
  15729. // 获取订单总金额
  15730. var getOrdersAmount = function() {
  15731. DeputyOrder.odersAmount({}, function(data) {
  15732. $scope.odersAmount = data.amount;
  15733. });
  15734. }
  15735. getOrdersAmount();
  15736. $scope.tableParams = new ngTableParams({
  15737. page: 1,
  15738. count: 20,
  15739. sorting: {'date': 'desc', 'id': 'desc'}
  15740. }, {
  15741. total: 0,
  15742. counts: [5, 10, 25, 50],
  15743. getData: function ($defer, params) {
  15744. $scope.loading = true;
  15745. var pageParams = params.url();
  15746. pageParams.searchFilter = {
  15747. keyword: $scope.keyword,
  15748. fromDate: getDateTime($scope.condition.dateFrom),
  15749. endDate: getDateTime($scope.condition.dateTo)
  15750. };
  15751. getSerivce()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  15752. $scope.loading = false;
  15753. if (page) {
  15754. params.total(page.totalElement);
  15755. $scope.total = page.totalElement;
  15756. $defer.resolve(page.content);
  15757. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  15758. }
  15759. }, function (response) {
  15760. $scope.loading = false;
  15761. toaster.pop('error', '数据加载失败', response.data);
  15762. });
  15763. }
  15764. });
  15765. //打印
  15766. $scope.print = function (deputyOrder) {
  15767. DeputyOrder.printCount({id: deputyOrder.id}, {});//增加打印此次
  15768. $scope.tableParams.reload();
  15769. ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  15770. ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  15771. ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  15772. ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  15773. };
  15774. // 搜索框回车
  15775. $scope.onSearch = function (keyword) {
  15776. // 每次搜索重置获取数据方法
  15777. $scope.searchMethod = false;
  15778. if(keyword != null && keyword != '') {
  15779. $scope.searchMethod = true;
  15780. }
  15781. $scope.tableParams.page(1);
  15782. $scope.tableParams.reload();
  15783. };
  15784. // 复制采购单
  15785. $scope.copyorder = function (id) {
  15786. $scope.loading = true;
  15787. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  15788. $scope.loading = false;
  15789. if (data.id) {
  15790. toaster.pop('success', '提示', '复制生成单据成功');
  15791. window.location.hash = "#/purc/deputy/" + data.id;
  15792. }
  15793. if (data.error) {
  15794. toaster.pop('error', '提示', '保存失败');
  15795. }
  15796. }, function (response) {
  15797. $scope.loading = false;
  15798. toaster.pop('error', '提示', response.data);
  15799. });
  15800. }
  15801. // 删除代采订单
  15802. $scope.clear = function (id) {
  15803. $scope.loading = true;
  15804. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  15805. if (data.success) {
  15806. toaster.pop('success', '提示', data.success);
  15807. $scope.tableParams.reload();
  15808. }
  15809. $scope.loading = false;
  15810. }, function (response) {
  15811. $scope.loading = false;
  15812. toaster.pop('error', '提示', response.data);
  15813. });
  15814. }
  15815. $scope.viewApprove = function(salecode, uu) {
  15816. var modalInstance = $modal.open({
  15817. templateUrl: 'static/tpl/index/purc/modal/approval_detail.html',
  15818. controller: 'ViewApprovalDetailCtrl',
  15819. resolve: {
  15820. uu: function () {
  15821. return uu
  15822. },
  15823. salecode: function () {
  15824. return salecode
  15825. }
  15826. }
  15827. });
  15828. }
  15829. }]);
  15830. // 查询代采定单在信扬中的审批情况
  15831. app.controller('ViewApprovalDetailCtrl', ['$scope', 'toaster', '$modalInstance', 'DeputyOrder', 'BaseService', 'ngTableParams', 'uu', 'salecode', function ($scope, toaster, $modalInstance, DeputyOrder, BaseService, ngTableParams, uu, salecode) {
  15832. DeputyOrder.approve({uu: uu, code: salecode}, {}, function (data) {
  15833. $scope.nodes = data.nodes;
  15834. $scope.process = data.process;
  15835. if(data.error) {
  15836. toaster.pop('error', '提示', data.error);
  15837. }
  15838. }, function (response) {
  15839. toaster.pop('error', '提示', '暂未获取到相关单据的信息');
  15840. });
  15841. $scope.cancel = function () {
  15842. $modalInstance.dismiss();
  15843. };
  15844. $scope.select = function (company) { // 直接选择
  15845. $modalInstance.close(company);
  15846. }
  15847. }]);
  15848. /**
  15849. * 新增代采订单
  15850. */
  15851. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', 'DecimalNumber', 'DekeyValue', function ($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService, DecimalNumber, DekeyValue) {
  15852. BaseService.scrollBackToTop();
  15853. //默认采购单号不重复
  15854. $scope.orderCodeEnable = true;
  15855. $scope.deOrder = {
  15856. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  15857. entrydate: new Date(),
  15858. status: '在录入',
  15859. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  15860. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  15861. riskmethod: '甲方承担',
  15862. taxpaymentmethod: '甲方承担',
  15863. totalamount: 0,
  15864. totalpayament: 0,
  15865. orderamount: 0,
  15866. usdpayment: 0
  15867. };
  15868. $scope.deOrder.deputyOrderItems = [];
  15869. var item = {
  15870. prodname: null,
  15871. prodcode: null,
  15872. prodspec: null,
  15873. amount: null,
  15874. unitprice: null,
  15875. purcprice: null,
  15876. remark: null,
  15877. orderprice: null,
  15878. };
  15879. $scope.deOrder.deputyOrderItems.push(item);
  15880. // 代采企业列表
  15881. DeputyOrder.deputyEnterprise({}, function (data) {
  15882. $scope.deputyEnterprises = data;
  15883. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15884. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15885. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  15886. });
  15887. var getPayMethod = function(enuu, key) {
  15888. // 获取我方付款支付方式默认值
  15889. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  15890. $scope.methods = data.content;
  15891. });
  15892. }
  15893. // 更新名称时后台更改uu号
  15894. $scope.change = function (deputyname) {
  15895. DeputyOrder.deputyEnterprise({}, function (data) {
  15896. $scope.deputyEn = data;
  15897. angular.forEach($scope.deputyEn, function (en) {
  15898. if (deputyname == en.deputyenname) {
  15899. $scope.deputyuu = en.deputyenuu;
  15900. getPayMethod($scope.deputyuu, 'paymentmethod');
  15901. }
  15902. });
  15903. });
  15904. }
  15905. // 查找付款企业
  15906. $scope.dbfindPayCompany = function (deputyuu) {
  15907. var modalInstance = $modal.open({
  15908. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15909. controller: 'DbfindDeputyPayCompanyCtrl',
  15910. resolve: {
  15911. deputyuu: function () {
  15912. return deputyuu
  15913. }
  15914. }
  15915. });
  15916. modalInstance.result.then(function (data) {
  15917. $scope.deOrder.paycomname = data.enname;
  15918. $scope.deOrder.paycomaddress = data.address;
  15919. })
  15920. }
  15921. // 查询上次的关键词记录
  15922. $scope.getHisKeyword = function (tervendor) {
  15923. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function (data) {
  15924. $scope.deOrder.vendtel = data.vendtel;
  15925. $scope.deOrder.venduser = data.venduser;
  15926. $scope.deOrder.otherdata = data.otherdata;
  15927. $scope.deOrder.companyname = data.companyname;
  15928. $scope.deOrder.bankaccount = data.bankaccount;
  15929. $scope.deOrder.bankaddress = data.bankaddress;
  15930. $scope.deOrder.bankcode = data.bankcode;
  15931. $scope.deOrder.bankname = data.bankname;
  15932. $scope.deOrder.legalrepresent = data.legalrepresent;
  15933. $scope.deOrder.tervendaddress = data.tervendaddress;
  15934. $scope.deOrder.enfax = data.enfax;
  15935. $scope.deOrder.deliverymethod = data.deliverymethod;
  15936. }, function (response) {
  15937. toaster.pop('error', '提示', response.data);
  15938. });
  15939. }
  15940. // 查询历史供应商
  15941. DeputyOrder.hisvendors({}, function (data) {
  15942. $scope.hisvendors = data;
  15943. }, function (response) {
  15944. toaster.pop('error', '提示', response.data);
  15945. });
  15946. // 上次填写记录(不关联供应商)
  15947. DeputyOrder.lastKeywords({}, function (data) {
  15948. $scope.lastkeyowrds = data;
  15949. $scope.deOrder.madealdate = $scope.lastkeyowrds.madealdate;
  15950. $scope.deOrder.madealcode = $scope.lastkeyowrds.madealcode;
  15951. }, function (response) {
  15952. toaster.pop('error', '提示', response.data);
  15953. });
  15954. //增加商品
  15955. $scope.add = function (index) {
  15956. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15957. toaster.pop('info', '提示', '请先填写商品信息');
  15958. } else {
  15959. $scope.deOrder.deputyOrderItems.push(
  15960. {
  15961. prodname: null,
  15962. prodcode: null,
  15963. prodspec: null,
  15964. prodbrand: null,
  15965. amount: null,
  15966. unitprice: null,
  15967. purcprice: null,
  15968. remark: null,
  15969. orderprice: null
  15970. });
  15971. }
  15972. };
  15973. //删除商品
  15974. $scope.del = function (index) {
  15975. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15976. };
  15977. // 导入商品信息
  15978. $scope.uplodaByBatch = function () {
  15979. var modalInstance = $modal.open({
  15980. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15981. controller: 'DeputyOrderUploadCtrl',
  15982. size: 'lg',
  15983. resolve: {}
  15984. });
  15985. modalInstance.result.then(function (data) {
  15986. angular.forEach(data, function (data) {
  15987. $scope.deOrder.deputyOrderItems.push(data);
  15988. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15989. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15990. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15991. }
  15992. }
  15993. })
  15994. $scope.deOrder.totalamount = 0;
  15995. $scope.deOrder.usdpayment = 0;
  15996. $scope.deOrder.orderamount = 0;
  15997. $scope.deOrder.totalpayament = 0;
  15998. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15999. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16000. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16001. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16002. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16003. });
  16004. }, function () {
  16005. });
  16006. }
  16007. // 查找供应商
  16008. $scope.dbfindVendor = function (deputyuu) {
  16009. var modalInstance = $modal.open({
  16010. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  16011. controller: 'DbfindDeputyVendorInfoCtrl',
  16012. size: 'lg',
  16013. resolve: {
  16014. deputyuu: function () {
  16015. return deputyuu
  16016. }
  16017. }
  16018. });
  16019. modalInstance.result.then(function (data) {
  16020. $scope.deOrder.customer = data.vendorEnterprise.enName;
  16021. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  16022. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  16023. $scope.deOrder.usertel = data.vendorUser.userTel;
  16024. })
  16025. }
  16026. // 检验订单编号是否存在
  16027. $scope.checkOrder = function (salecode, deputyuu) {
  16028. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  16029. $scope.orderCodeEnable = true;
  16030. if (data.info) {
  16031. toaster.pop('error', '提示', data.info);
  16032. $scope.orderCodeEnable = false;
  16033. }
  16034. }, function (response) {
  16035. toaster.pop('error', '提示', response.data);
  16036. })
  16037. }
  16038. //计算采购单价
  16039. $scope.checkPrice = function (rate) {
  16040. $scope.deOrder.totalamount = 0;
  16041. $scope.deOrder.usdpayment = 0;
  16042. $scope.deOrder.orderamount = 0;
  16043. $scope.deOrder.totalpayament = 0;
  16044. if (rate == null) {
  16045. toaster.pop('info', '提示', '请先填入税率');
  16046. } else {
  16047. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16048. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  16049. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16050. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16051. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16052. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16053. });
  16054. }
  16055. }
  16056. // 获取订单总价
  16057. $scope.totalPrice = function () {
  16058. $scope.deOrder.totalamount = 0;
  16059. $scope.deOrder.usdpayment = 0;
  16060. $scope.deOrder.orderamount = 0;
  16061. $scope.deOrder.totalpayament = 0;
  16062. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16063. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  16064. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16065. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16066. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16067. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16068. }
  16069. });
  16070. }
  16071. $scope.checkresult = false;
  16072. var checkKeyword = function () {
  16073. if ($scope.deOrder.madealdate == null) {
  16074. toaster.pop('info', '提示', '主协议签订日期未选择');
  16075. } else if ($scope.deOrder.madealcode == null) {
  16076. toaster.pop('info', '提示', '主协议签订编号未填写');
  16077. } else if ($scope.deOrder.tervendor == null) {
  16078. toaster.pop('info', '提示', '终端供应商名称未填写');
  16079. } else if ($scope.deOrder.vendtel == null) {
  16080. toaster.pop('info', '提示', '电话号码未填写');
  16081. } else if ($scope.deOrder.venduser == null) {
  16082. toaster.pop('info', '提示', '联系人未填写');
  16083. } else if ($scope.deOrder.shipdate == null) {
  16084. toaster.pop('info', '提示', '供应商发货时间未选择');
  16085. } else if ($scope.deOrder.goodspacking == null) {
  16086. toaster.pop('info', '提示', '货物包装要求未填写');
  16087. } else if ($scope.deOrder.deliverymethod == null) {
  16088. toaster.pop('info', '提示', '供应商交货方式未填写');
  16089. } else if ($scope.deOrder.pickupmethod == null) {
  16090. toaster.pop('info', '提示', '我方提货方式未填写');
  16091. } else if ($scope.deOrder.paymentmethod == null) {
  16092. toaster.pop('info', '提示', '我方付款方式未填写');
  16093. } else if ($scope.deOrder.pickupdate == null) {
  16094. toaster.pop('info', '提示', '我方提货时间未选择');
  16095. } else if ($scope.deOrder.currency == null) {
  16096. toaster.pop('info', '提示', '交易币别未选择');
  16097. } else if ($scope.deOrder.deputyuu == null) {
  16098. toaster.pop('info', '提示', '代采企业未选择');
  16099. } else if ($scope.deOrder.salecode == null) {
  16100. toaster.pop('info', '提示', '订单编号未填写');
  16101. } else if ($scope.deOrder.paydeldate == null) {
  16102. toaster.pop('info', '提示', '我方付款提货时间未选择');
  16103. } else if ($scope.deOrder.riskmethod == null) {
  16104. toaster.pop('info', '提示', '风险承担方式未填写');
  16105. } else if ($scope.deOrder.taxpaymentmethod == null) {
  16106. toaster.pop('info', '提示', '运、税费承担方式');
  16107. } else if ($scope.deOrder.tervendaddress == null) {
  16108. toaster.pop('info', '提示', '终端供应商地址未填写');
  16109. } else if ($scope.deOrder.companyname == null) {
  16110. toaster.pop('info', '提示', '公司全称(英文)未填写');
  16111. } else if ($scope.deOrder.requirepaydate == null) {
  16112. toaster.pop('info', '提示', '要求付汇日期未选择');
  16113. } else if ($scope.deOrder.bankname == null) {
  16114. toaster.pop('info', '提示', '银行名称(英文)未填写');
  16115. } else if ($scope.deOrder.bankaccount == null) {
  16116. toaster.pop('info', '提示', '银行账号未填写');
  16117. } else if ($scope.deOrder.bankaddress == null) {
  16118. toaster.pop('info', '提示', '银行地址未填写');
  16119. } else if ($scope.deOrder.bankcode == null) {
  16120. toaster.pop('info', '提示', '银行代码未填写');
  16121. } else if ($scope.deOrder.salepocode == null) {
  16122. toaster.pop('info', '提示', '合同编号未填写');
  16123. } else if ($scope.deOrder.legalrepresent == null) {
  16124. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  16125. } else if ($scope.deOrder.paycomname == null) {
  16126. toaster.pop('info', '提示', '付款公司未填写');
  16127. } else if ($scope.deOrder.paycomaddress == null) {
  16128. toaster.pop('info', '提示', '付款公司地址未填写');
  16129. } else if ($scope.deOrder.enfax == null) {
  16130. toaster.pop('info', '提示', '供应商方法人电话未填写');
  16131. } else if ($scope.deOrder.paydate == null) {
  16132. toaster.pop('info', '提示', '货款支付时间未选择');
  16133. } else if ($scope.deOrder.paymethod == null) {
  16134. toaster.pop('info', '提示', '货款支付方式未填写');
  16135. } else if ($scope.deOrder.deliverydate == null) {
  16136. toaster.pop('info', '提示', '交货时间未选择');
  16137. } else if (!$scope.orderCodeEnable) {
  16138. toaster.pop('info', '提示', '采购单号重复');
  16139. } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
  16140. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
  16141. } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
  16142. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
  16143. } else {
  16144. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  16145. if (orderitem.prodname == null) {
  16146. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  16147. } else if (orderitem.prodcode == null) {
  16148. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  16149. } else if (orderitem.prodspec == null) {
  16150. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  16151. } else if (orderitem.prodbrand == null) {
  16152. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  16153. } else if (orderitem.amount == null) {
  16154. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  16155. } else if (orderitem.unitprice == null) {
  16156. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  16157. } else if (orderitem.purcprice == null) {
  16158. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  16159. } else {
  16160. $scope.checkresult = true;
  16161. $scope.isSave = true;
  16162. }
  16163. })
  16164. };
  16165. }
  16166. // 保存
  16167. $scope.isSave = false;
  16168. $scope.save = function (status) {
  16169. $scope.deOrder.entrystatus = status;
  16170. checkKeyword();
  16171. if ($scope.checkresult) {
  16172. $scope.deOrder.totalamount = 0;
  16173. $scope.deOrder.usdpayment = 0;
  16174. $scope.deOrder.orderamount = 0;
  16175. $scope.deOrder.totalpayament = 0;
  16176. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16177. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16178. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16179. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16180. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16181. });
  16182. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  16183. toaster.pop('info', '提示', '您还未填写任何商品信息');
  16184. } else {
  16185. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  16186. if (data.id) {
  16187. toaster.pop('success', '提示', status + '成功');
  16188. window.location.hash = "#/purc/deputy/" + data.id;
  16189. }
  16190. if (data.error) {
  16191. toaster.pop('error', '提示', status + '失败');
  16192. }
  16193. }, function (response) {
  16194. });
  16195. }
  16196. }
  16197. }
  16198. $scope.openDatePicker = function ($event, deOrder, openParam) {
  16199. $event.preventDefault();
  16200. $event.stopPropagation();
  16201. deOrder[openParam] = !deOrder[openParam];
  16202. };
  16203. }]);
  16204. // 代采企业供应商
  16205. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  16206. $scope.prod = false;
  16207. BaseService.scrollBackToTop();
  16208. // 搜索框回车
  16209. $scope.onSearch = function (keyword) {
  16210. $scope.keyword = keyword;
  16211. $scope.customerParams.page(1);
  16212. $scope.customerParams.reload();
  16213. };
  16214. $scope.customerParams = new ngTableParams({
  16215. page: 1,
  16216. count: 20
  16217. }, {
  16218. total: 0,
  16219. counts: [5, 10, 25, 50],
  16220. getData: function ($defer, params) {
  16221. $scope.loading = true;
  16222. var pageParams = params.url();
  16223. pageParams.keyword = $scope.keyword;
  16224. pageParams.enuu = deputyuu;
  16225. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function (page) {
  16226. $scope.loading = false;
  16227. if (page) {
  16228. params.total(page.totalElement);
  16229. $defer.resolve(page.content);
  16230. }
  16231. $scope.totalCount = page.totalElement;
  16232. }, function (response) {
  16233. $scope.loading = false;
  16234. toaster.pop('error', '数据加载失败', response.data);
  16235. });
  16236. }
  16237. });
  16238. $scope.cancel = function () {
  16239. $modalInstance.dismiss();
  16240. };
  16241. $scope.checkVendor = function (vendor) { // 直接选择
  16242. $modalInstance.close(vendor);
  16243. }
  16244. }]);
  16245. // 代采企业付款企业
  16246. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  16247. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function (data) {
  16248. $scope.paycompanies = data;
  16249. }, function (response) {
  16250. toaster.pop('error', '提示', response.data);
  16251. });
  16252. $scope.cancel = function () {
  16253. $modalInstance.dismiss();
  16254. };
  16255. $scope.select = function (company) { // 直接选择
  16256. $modalInstance.close(company);
  16257. }
  16258. }]);
  16259. /**
  16260. * 代采订单批量导入
  16261. */
  16262. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  16263. // 通过excel批量上传物料
  16264. $scope.result = null;
  16265. $scope.upload = function () {
  16266. var file = $scope.myFiles[0];
  16267. $upload.upload({
  16268. url: 'deputyOrder/release/excel',
  16269. file: file,
  16270. method: 'POST'
  16271. }).success(function (data) {
  16272. $scope.result = data;
  16273. $scope.success = $scope.result.success;
  16274. $scope.total = $scope.result.total;
  16275. $scope.alters = $scope.result.alters;
  16276. }).error(function (response) {
  16277. toaster.pop('error', response.data || response);
  16278. });
  16279. };
  16280. // 查看范例
  16281. $scope.showImg = function () {
  16282. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  16283. box.show();
  16284. box.find('img').attr('src', src);
  16285. box.find('a').click(function () {
  16286. box.hide();
  16287. });
  16288. box.dblclick(function () {
  16289. box.hide();
  16290. });
  16291. };
  16292. // 下载模板
  16293. $scope.download = function () {
  16294. window.location.href = 'deputyOrder/upload/template';
  16295. };
  16296. $scope.enSure = function () {
  16297. $modalInstance.close($scope.result.items);
  16298. }
  16299. $scope.cancel = function () {
  16300. $modalInstance.dismiss();
  16301. }
  16302. }]);
  16303. /**
  16304. * 代采详情
  16305. */
  16306. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', 'DecimalNumber', 'CurrentRole', 'DekeyValue', function ($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal, DecimalNumber, CurrentRole, DekeyValue) {
  16307. BaseService.scrollBackToTop();
  16308. // 获取当前用户是否为普通用户
  16309. CurrentRole.isUser({}, {}, function (data) {
  16310. $scope.isUser = data.isUser;
  16311. });
  16312. var loadData = function () {
  16313. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function (data) {
  16314. $scope.deOrder = data;
  16315. $scope.deOrder.$editing = true;
  16316. }, function (response) {
  16317. toaster.pop('error', '提示', response.data);
  16318. });
  16319. };
  16320. loadData();
  16321. //默认采购单号不重复
  16322. $scope.orderCodeEnable = true;
  16323. // 查询历史供应商
  16324. DeputyOrder.hisvendors({}, function (data) {
  16325. $scope.hisvendors = data;
  16326. }, function (response) {
  16327. toaster.pop('error', '提示', response.data);
  16328. });
  16329. // 代采企业列表
  16330. DeputyOrder.deputyEnterprise({}, function (data) {
  16331. $scope.deputyEnterprises = data;
  16332. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  16333. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  16334. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  16335. });
  16336. var getPayMethod = function(enuu, key) {
  16337. // 获取我方付款支付方式默认值
  16338. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  16339. $scope.methods = data.content;
  16340. });
  16341. }
  16342. // 更新代采企业时更新费率
  16343. $scope.change = function (deputyname) {
  16344. DeputyOrder.deputyEnterprise({}, function (data) {
  16345. $scope.deputyEn = data;
  16346. angular.forEach($scope.deputyEn, function (en) {
  16347. if (deputyname == en.deputyenname) {
  16348. $scope.deputyuu = en.deputyenuu;
  16349. getPayMethod($scope.deputyuu, 'paymentmethod');
  16350. }
  16351. });
  16352. });
  16353. }
  16354. // 查找付款企业
  16355. $scope.dbfindPayCompany = function (deputyuu) {
  16356. var modalInstance = $modal.open({
  16357. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  16358. controller: 'DbfindDeputyPayCompanyCtrl',
  16359. resolve: {
  16360. deputyuu: function () {
  16361. return deputyuu
  16362. }
  16363. }
  16364. });
  16365. modalInstance.result.then(function (data) {
  16366. $scope.deOrder.paycomname = data.enname;
  16367. $scope.deOrder.paycomaddress = data.address;
  16368. })
  16369. }
  16370. // 删除明细
  16371. $scope.del = function (index, id) {
  16372. DeputyOrder.deleteProdById({id: id}, {}, function (data) {
  16373. if (data.success) {
  16374. toaster.pop('success', '提示', data.success);
  16375. $scope.deOrder.deputyOrderItems.splice(index, 1)
  16376. }
  16377. if (data.error) {
  16378. toaster.pop('error', '提示', data.error);
  16379. }
  16380. $scope.deOrder.totalamount = 0;
  16381. $scope.deOrder.usdpayment = 0;
  16382. $scope.deOrder.orderamount = 0;
  16383. $scope.deOrder.totalpayament = 0;
  16384. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16385. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16386. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16387. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16388. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16389. });
  16390. }, function (response) {
  16391. toaster.pop('error', '提示', response.data);
  16392. });
  16393. }
  16394. //增加商品
  16395. $scope.add = function (index) {
  16396. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  16397. toaster.pop('info', '提示', '请先填写商品信息');
  16398. } else {
  16399. $scope.deOrder.deputyOrderItems.push(
  16400. {
  16401. prodname: null,
  16402. prodcode: null,
  16403. prodspec: null,
  16404. prodbrand: null,
  16405. amount: null,
  16406. unitprice: null,
  16407. remark: null,
  16408. orderprice: null
  16409. });
  16410. }
  16411. };
  16412. // 导入商品信息
  16413. $scope.uplodaByBatch = function () {
  16414. var modalInstance = $modal.open({
  16415. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  16416. controller: 'DeputyOrderUploadCtrl',
  16417. size: 'lg',
  16418. resolve: {}
  16419. });
  16420. modalInstance.result.then(function (data) {
  16421. angular.forEach(data, function (data) {
  16422. $scope.deOrder.deputyOrderItems.push(data);
  16423. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  16424. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  16425. $scope.deOrder.deputyOrderItems.splice(i, 1);
  16426. }
  16427. }
  16428. })
  16429. $scope.deOrder.totalamount = 0;
  16430. $scope.deOrder.usdpayment = 0;
  16431. $scope.deOrder.orderamount = 0;
  16432. $scope.deOrder.totalpayament = 0;
  16433. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16434. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16435. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16436. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16437. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16438. });
  16439. }, function () {
  16440. });
  16441. }
  16442. //删除商品
  16443. $scope.delItem = function (index) {
  16444. $scope.deOrder.deputyOrderItems.splice(index, 1);
  16445. };
  16446. var getService = function () {
  16447. return DeputyOrder.getProdList;
  16448. };
  16449. $scope.update = function () {
  16450. $scope.deOrder.$editing = true;
  16451. }
  16452. $scope.cancel = function () {
  16453. $scope.deOrder.$editing = false;
  16454. }
  16455. // 检验订单编号是否存在
  16456. $scope.checkOrder = function (salecode, deputyuu) {
  16457. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  16458. $scope.orderCodeEnable = true;
  16459. if (data.info) {
  16460. toaster.pop('error', '提示', data.info);
  16461. $scope.orderCodeEnable = false;
  16462. }
  16463. }, function (response) {
  16464. toaster.pop('error', '提示', response.data);
  16465. })
  16466. }
  16467. //计算采购单价
  16468. $scope.checkPrice = function (rate) {
  16469. $scope.deOrder.totalamount = 0;
  16470. $scope.deOrder.usdpayment = 0;
  16471. $scope.deOrder.orderamount = 0;
  16472. $scope.deOrder.totalpayament = 0;
  16473. if (rate == null) {
  16474. toaster.pop('info', '提示', '请先填入税率');
  16475. } else {
  16476. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16477. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  16478. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16479. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16480. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16481. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16482. });
  16483. }
  16484. }
  16485. // 获取订单总价
  16486. $scope.totalPrice = function () {
  16487. $scope.deOrder.totalamount = 0;
  16488. $scope.deOrder.usdpayment = 0;
  16489. $scope.deOrder.orderamount = 0;
  16490. $scope.deOrder.totalpayament = 0;
  16491. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16492. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  16493. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16494. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16495. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16496. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16497. }
  16498. });
  16499. }
  16500. $scope.checkresult = false;
  16501. var checkKeyword = function () {
  16502. if ($scope.deOrder.madealdate == null) {
  16503. toaster.pop('info', '提示', '主协议签订日期未选择');
  16504. } else if ($scope.deOrder.madealcode == null) {
  16505. toaster.pop('info', '提示', '主协议签订编号未填写');
  16506. } else if ($scope.deOrder.tervendor == null) {
  16507. toaster.pop('info', '提示', '终端供应商名称未填写');
  16508. } else if ($scope.deOrder.vendtel == null) {
  16509. toaster.pop('info', '提示', '电话号码未填写');
  16510. } else if ($scope.deOrder.venduser == null) {
  16511. toaster.pop('info', '提示', '联系人未填写');
  16512. } else if ($scope.deOrder.shipdate == null) {
  16513. toaster.pop('info', '提示', '供应商发货时间未选择');
  16514. } else if ($scope.deOrder.goodspacking == null) {
  16515. toaster.pop('info', '提示', '货物包装要求未填写');
  16516. } else if ($scope.deOrder.deliverymethod == null) {
  16517. toaster.pop('info', '提示', '供应商交货方式未填写');
  16518. } else if ($scope.deOrder.pickupmethod == null) {
  16519. toaster.pop('info', '提示', '我方提货方式未填写');
  16520. } else if ($scope.deOrder.paymentmethod == null) {
  16521. toaster.pop('info', '提示', '我方付款方式未填写');
  16522. } else if ($scope.deOrder.pickupdate == null) {
  16523. toaster.pop('info', '提示', '我方提货时间未选择');
  16524. } else if ($scope.deOrder.currency == null) {
  16525. toaster.pop('info', '提示', '交易币别未选择');
  16526. } else if ($scope.deOrder.deputyuu == null) {
  16527. toaster.pop('info', '提示', '代采企业未选择');
  16528. } else if ($scope.deOrder.salecode == null) {
  16529. toaster.pop('info', '提示', '订单编号未填写');
  16530. } else if ($scope.deOrder.paydeldate == null) {
  16531. toaster.pop('info', '提示', '我方付款提货时间未选择');
  16532. } else if ($scope.deOrder.riskmethod == null) {
  16533. toaster.pop('info', '提示', '风险承担方式未填写');
  16534. } else if ($scope.deOrder.taxpaymentmethod == null) {
  16535. toaster.pop('info', '提示', '运、税费承担方式');
  16536. } else if ($scope.deOrder.tervendaddress == null) {
  16537. toaster.pop('info', '提示', '终端供应商地址未填写');
  16538. } else if ($scope.deOrder.companyname == null) {
  16539. toaster.pop('info', '提示', '公司全称(英文)未填写');
  16540. } else if ($scope.deOrder.requirepaydate == null) {
  16541. toaster.pop('info', '提示', '要求付汇日期未选择');
  16542. } else if ($scope.deOrder.bankname == null) {
  16543. toaster.pop('info', '提示', '银行名称(英文)未填写');
  16544. } else if ($scope.deOrder.bankaccount == null) {
  16545. toaster.pop('info', '提示', '银行账号未填写');
  16546. } else if ($scope.deOrder.bankaddress == null) {
  16547. toaster.pop('info', '提示', '银行地址未填写');
  16548. } else if ($scope.deOrder.bankcode == null) {
  16549. toaster.pop('info', '提示', '银行代码未填写');
  16550. } else if ($scope.deOrder.salepocode == null) {
  16551. toaster.pop('info', '提示', '合同编号未填写');
  16552. } else if ($scope.deOrder.legalrepresent == null) {
  16553. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  16554. } else if ($scope.deOrder.paycomname == null) {
  16555. toaster.pop('info', '提示', '付款公司未填写');
  16556. } else if ($scope.deOrder.paycomaddress == null) {
  16557. toaster.pop('info', '提示', '付款公司地址未填写');
  16558. } else if ($scope.deOrder.enfax == null) {
  16559. toaster.pop('info', '提示', '供应商方法人电话未填写');
  16560. } else if ($scope.deOrder.paydate == null) {
  16561. toaster.pop('info', '提示', '货款支付时间未选择');
  16562. } else if ($scope.deOrder.paymethod == null) {
  16563. toaster.pop('info', '提示', '货款支付方式未填写');
  16564. } else if ($scope.deOrder.deliverydate == null) {
  16565. toaster.pop('info', '提示', '交货时间未选择');
  16566. } else if (!$scope.orderCodeEnable) {
  16567. toaster.pop('info', '提示', '采购单号重复');
  16568. } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
  16569. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
  16570. } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
  16571. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
  16572. } else {
  16573. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  16574. if (orderitem.prodname == null) {
  16575. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  16576. } else if (orderitem.prodcode == null) {
  16577. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  16578. } else if (orderitem.prodspec == null) {
  16579. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  16580. } else if (orderitem.prodbrand == null) {
  16581. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  16582. } else if (orderitem.amount == null) {
  16583. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  16584. } else if (orderitem.unitprice == null) {
  16585. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  16586. } else if (orderitem.purcprice == null) {
  16587. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  16588. } else {
  16589. $scope.checkresult = true;
  16590. $scope.isSave = true;
  16591. }
  16592. });
  16593. }
  16594. }
  16595. // 保存
  16596. $scope.isSave = false;
  16597. $scope.save = function (status) {
  16598. $scope.deOrder.entrystatus = status;
  16599. checkKeyword();
  16600. if ($scope.checkresult) {
  16601. $scope.deOrder.totalamount = 0;
  16602. $scope.deOrder.usdpayment = 0;
  16603. $scope.deOrder.orderamount = 0;
  16604. $scope.deOrder.totalpayament = 0;
  16605. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16606. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16607. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16608. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16609. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16610. });
  16611. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  16612. toaster.pop('info', '提示', '您还未填写任何商品信息');
  16613. } else {
  16614. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  16615. if (data.id) {
  16616. toaster.pop('success', '提示', '保存成功');
  16617. loadData();
  16618. window.location.reload();
  16619. }
  16620. if (data.error) {
  16621. toaster.pop('error', '提示', '保存失败');
  16622. }
  16623. }, function (response) {
  16624. toaster.pop('error', '保存失败', response.data);
  16625. });
  16626. }
  16627. }
  16628. }
  16629. $scope.openDatePicker = function ($event, deOrder, openParam) {
  16630. $event.preventDefault();
  16631. $event.stopPropagation();
  16632. deOrder[openParam] = !deOrder[openParam];
  16633. };
  16634. //复制采购单
  16635. $scope.copyorder = function (id) {
  16636. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  16637. if (data.id) {
  16638. toaster.pop('success', '提示', '复制生成单据成功');
  16639. window.location.hash = "#/purc/deputy/" + data.id;
  16640. }
  16641. if (data.error) {
  16642. toaster.pop('error', '提示', '保存失败');
  16643. }
  16644. }, function (response) {
  16645. toaster.pop('error', '提示', response.data);
  16646. });
  16647. }
  16648. // 删除代采订单
  16649. $scope.clear = function (id) {
  16650. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  16651. if (data.success) {
  16652. toaster.pop('success', '提示', data.success);
  16653. window.location.hash = "#/purc/deputy";
  16654. }
  16655. }, function (response) {
  16656. toaster.pop('error', '提示', response.data);
  16657. });
  16658. }
  16659. }]);
  16660. /**
  16661. * 代采错误日志
  16662. */
  16663. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function ($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  16664. BaseService.scrollBackToTop();
  16665. var getService = function () {
  16666. return DeputyOrder.getRepetitions;
  16667. };
  16668. $scope.tableParams = new ngTableParams({
  16669. page: 1,
  16670. count: 20,
  16671. sorting: {}
  16672. }, {
  16673. total: 0,
  16674. counts: [5, 10, 25, 50],
  16675. getData: function ($defer, params) {
  16676. $scope.loading = true;
  16677. var pageParams = params.url();
  16678. pageParams.keyword = $scope.keyword;
  16679. pageParams.searchFilter = $scope.searchFilter;
  16680. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  16681. $scope.loading = false;
  16682. if (page) {
  16683. params.total(page.totalElement);
  16684. $defer.resolve(page.content);
  16685. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  16686. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  16687. }
  16688. }, function (response) {
  16689. $scope.loading = false;
  16690. toaster.pop('error', '数据加载失败', response.data);
  16691. });
  16692. }
  16693. });
  16694. // 搜索框回车
  16695. $scope.onSearch = function () {
  16696. $scope.tableParams.page(1);
  16697. $scope.tableParams.reload();
  16698. };
  16699. //删除
  16700. $scope.deleteById = function (id) {
  16701. GetProductInfo.deleteById({id: id}, function (data) {
  16702. if (data.error) {
  16703. toaster.pop("error", "提示", data.error);
  16704. } else {
  16705. toaster.pop("success", "提示", "删除成功");
  16706. $timeout(function () {
  16707. $scope.tableParams.reload();
  16708. }, 500);
  16709. }
  16710. }), function (response) {
  16711. toaster.pop("error", "删除失败", response.data);
  16712. };
  16713. }
  16714. }]);
  16715. /**
  16716. * 招标单
  16717. */
  16718. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams',
  16719. '$modal', '$rootScope', 'PurcTenderInfo', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, PurcTenderInfo) {
  16720. BaseService.scrollBackToTop();
  16721. $scope.searchStatus = false;
  16722. if ($rootScope.tenderActive) {
  16723. $scope.active = $rootScope.tenderActive;
  16724. $rootScope.tenderActive = null;
  16725. } else {
  16726. $scope.active = 'todo';
  16727. }
  16728. $scope.dateZoneText = '不限';
  16729. $scope.deliveryZoneText = '不限';
  16730. $scope.condition = {dateZone: 1, deliveryZone: -1};
  16731. /* 时间筛选初始化*/
  16732. var fromDate = new Date();
  16733. var toDate = new Date();
  16734. fromDate.setMonth(fromDate.getMonth() - 1);
  16735. fromDate.setHours(0, 0, 0, 0);
  16736. toDate.setHours(23, 59, 59, 999);
  16737. $scope.condition.dateFrom = fromDate;
  16738. $scope.condition.dateTo = toDate;
  16739. $scope.changeDateZone = function (zone) {
  16740. $scope.condition.dateZone = zone;
  16741. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  16742. $scope.condition.$dateZoneOpen = false;
  16743. getDateCondition(zone, $scope.condition);
  16744. $scope.tableParams.reload();
  16745. };
  16746. $scope.changeDeliveryZone = function (zone) {
  16747. $scope.condition.deliveryZoneText = zone;
  16748. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  16749. $scope.condition.$delievryZoneOpen = false;
  16750. getDelveryCondition(zone, $scope.condition);
  16751. $scope.tableParams.page(1);
  16752. $scope.tableParams.reload();
  16753. };
  16754. $scope.setActive = function (state) {
  16755. if ($scope.active != state) {
  16756. $scope.active = state;
  16757. if ($scope.tableParams.page() == 1)
  16758. $scope.tableParams.reload();
  16759. else
  16760. $scope.tableParams.page(1);
  16761. }
  16762. };
  16763. var getTenderStatus = function (active) {
  16764. var fn = 'getMyAll';
  16765. switch (active) {
  16766. case 'done':
  16767. fn = 'getMyDone';
  16768. break;
  16769. case 'todo':
  16770. fn = 'getMyTodo';
  16771. break;
  16772. // case 'end':
  16773. // fn = 'getMyEnd';break;
  16774. case 'waiting':
  16775. fn = 'getMyWaiting';
  16776. break;
  16777. }
  16778. return fn;
  16779. };
  16780. var getService = function () {
  16781. if ($scope.searchStatus) {
  16782. return PurcTender;
  16783. }
  16784. return PurcTenderInfo;
  16785. };
  16786. $scope.tableParams = new ngTableParams({
  16787. page: 1,
  16788. count: 20,
  16789. sorting: {
  16790. 'id': 'desc'
  16791. }
  16792. }, {
  16793. total: 0,
  16794. counts: [5, 10, 25, 50],
  16795. getData: function ($defer, params) {
  16796. $scope.loading = true;
  16797. var pageParams = params.url();
  16798. var realActive = {};
  16799. pageParams.searchFilter = { // 筛选条件
  16800. keyword: $scope.keyword,
  16801. fromDate: getDateTime($scope.condition.dateFrom),
  16802. endDate: getDateTime($scope.condition.dateTo)
  16803. };
  16804. getService()[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16805. $scope.loading = false;
  16806. if (page) {
  16807. params.total(page.totalElement);
  16808. $defer.resolve(page.content);
  16809. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  16810. }
  16811. }, function (response) {
  16812. $scope.loading = false;
  16813. toaster.pop('error', '数据加载失败', response.data);
  16814. });
  16815. }
  16816. });
  16817. //获得各分类未阅读数量
  16818. var getUnreadCount = function () {
  16819. PurcTender.getPurcUnreadCount(null, function(data){
  16820. $scope.unread = data;
  16821. });
  16822. };
  16823. getUnreadCount();
  16824. //设置单据已读
  16825. $scope.setOrdersRead = function (id) {
  16826. // 如果单据本身已读,则不发送请求修改数据
  16827. if (!$scope.isUnread(id)){
  16828. return;
  16829. }
  16830. var sourceId = [];
  16831. sourceId.push(id);
  16832. PurcTender.setPurcRead({}, sourceId, function (message) {
  16833. // $scope.getUnreadIds();
  16834. getUnreadCount();
  16835. });
  16836. };
  16837. //获取未读单据id
  16838. var getUnreadIds = function (){
  16839. PurcTender.getPurcUnreadIds({}, "", function (message) {
  16840. $scope.unreadCode = message.content;
  16841. });
  16842. };
  16843. getUnreadIds();
  16844. //判断单据是否未读
  16845. $scope.isUnread = function (tender){
  16846. for (var i in $scope.unreadCode) {
  16847. if (tender.id == $scope.unreadCode[i]) {
  16848. var flag = tender.status == '待评标' && tender.overdue == 1 && tender.result != 1;
  16849. if (!flag) {
  16850. $scope.unreadCode.splice(i,1);
  16851. return false;
  16852. }
  16853. return true;
  16854. }
  16855. }
  16856. };
  16857. $scope.openDatePicker = function ($event, item, openParam) {
  16858. $event.preventDefault();
  16859. $event.stopPropagation();
  16860. item[openParam] = !item[openParam];
  16861. };
  16862. $scope.openFilterDatePicker = function ($event, item, openParam) {
  16863. $event.preventDefault();
  16864. $event.stopPropagation();
  16865. item[openParam] = !item[openParam];
  16866. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  16867. $scope.tableParams.reload();
  16868. }
  16869. };
  16870. $scope.parseDate = function (dateStr) {
  16871. if (dateStr)
  16872. return Date.parse(dateStr, 'yyyy-MM-dd');
  16873. return new Date();
  16874. };
  16875. // 选择查找日期
  16876. $scope.onDateCondition = function () {
  16877. $scope.tableParams.page(1);
  16878. $scope.tableParams.reload();
  16879. };
  16880. // 搜索框回车
  16881. $scope.onSearch = function () {
  16882. $scope.searchStatus = true;
  16883. $scope.tableParams.page(1);
  16884. $scope.tableParams.reload();
  16885. };
  16886. }]);
  16887. /**
  16888. * 新增招标单
  16889. */
  16890. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'ShipAddress', '$http', 'AuthenticationService', 'KindAPI', 'BrandActiveAPI', 'Search', 'ComponentActiveAPI', 'GetProductInfo', 'Vendor', 'PurcProduct', 'PurcProductNewest', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, ShipAddress, $http, AuthenticationService, KindAPI, BrandActiveAPI, Search, ComponentActiveAPI, GetProductInfo, Vendor, PurcProduct, PurcProductNewest) {
  16891. // 录入人
  16892. AuthenticationService.getAuthentication().success(function (data) {
  16893. $scope.user = data;
  16894. });
  16895. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16896. $scope.searchMethod = false;
  16897. var getService = function () {
  16898. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  16899. };
  16900. // 物料信息
  16901. $scope.tableParams = new ngTableParams({
  16902. page: 1,
  16903. count: 20,
  16904. sorting: {}
  16905. }, {
  16906. total: 0,
  16907. counts: [5, 10, 25, 50],
  16908. getData: function ($defer, params) {
  16909. $scope.loading = true;
  16910. var pageParams = params.url();
  16911. pageParams.keyword = $scope.keyword;
  16912. $scope.tip = $scope.keyword;
  16913. pageParams.searchFilter = $scope.searchFilter;
  16914. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16915. $scope.loading = false;
  16916. if (page) {
  16917. params.total(page.totalElement);
  16918. $scope.total = page.totalElement;
  16919. $defer.resolve(page.content);
  16920. }
  16921. }, function (response) {
  16922. $scope.loading = false;
  16923. toaster.pop('error', '数据加载失败', response.data);
  16924. });
  16925. }
  16926. });
  16927. // 搜索框回车
  16928. $scope.onSearch = function (keyword) {
  16929. // 每次搜索重置获取数据方法
  16930. $scope.searchMethod = false;
  16931. if(keyword != null && keyword != '') {
  16932. $scope.searchMethod = true;
  16933. }
  16934. $scope.tableParams.page(1);
  16935. $scope.tableParams.reload();
  16936. };
  16937. //在产品列表添加商品
  16938. $scope.check = function (product) {
  16939. $scope.tenderProd.push({
  16940. prodTitle: product.title,
  16941. prodCode: product.code,
  16942. brand: product.brand,
  16943. unit: product.unit,
  16944. qty: null
  16945. // 供应商企业信息
  16946. // enterpriseBaseInfo: [{}]
  16947. });
  16948. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16949. if ($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  16950. $scope.tenderProd.splice(i, 1);
  16951. }
  16952. }
  16953. };
  16954. $scope.loading = false;
  16955. // 获取收货地址列表
  16956. var loadShipAddress = function () {
  16957. ShipAddress.shipAddList({}, function (data) {
  16958. $scope.ships = data;
  16959. $scope.tender.shipadd = $scope.ships[0];
  16960. });
  16961. };
  16962. loadShipAddress();
  16963. // 获取地址信息
  16964. $http.get('resources/citydata/city.json', {
  16965. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  16966. }).then(function (response) {
  16967. $scope.provinces = response.data;
  16968. });
  16969. // 新增收货地址保存
  16970. $scope.saveShipAddress = function (ship) {
  16971. ship.address = ship.province + ship.city + ship.district;
  16972. ShipAddress.saveAddress({}, ship, function (data) {
  16973. if (data.success) {
  16974. // 获取收货地址列表
  16975. loadShipAddress();
  16976. toaster.pop('success', '提示', data.success);
  16977. }
  16978. if (data.error) {
  16979. toaster.pop('error', '提示', data.error);
  16980. }
  16981. });
  16982. };
  16983. // 可选的证照要求
  16984. $scope.certificates = [{name: '三/五证合一'}, {name: '营业执照'}, {name: '组织机构代码证'}, {name: '一般纳税人证明材料'}, {name: '统计登记证'}, {name: '社会保险登记证'}];
  16985. // 处理证照要求
  16986. var parseCertificate = function (a) {
  16987. if (a) {
  16988. var arr = a.split(',');
  16989. angular.forEach(arr, function (app) {
  16990. var contained = false;
  16991. angular.forEach($scope.certificates, function ($app) {
  16992. if ($app.name == app) {
  16993. $app.checked = true;
  16994. contained = true;
  16995. }
  16996. });
  16997. if (!contained) {
  16998. $scope.certificates.push({name: app, checked: true});
  16999. }
  17000. });
  17001. }
  17002. };
  17003. // 联想词start
  17004. // 获取品牌联想词
  17005. $scope.getSimilarBrands = function (value) {
  17006. if (value) {
  17007. // 获取品牌联想词
  17008. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  17009. return data.map(function (item) {
  17010. return item;
  17011. });
  17012. });
  17013. }
  17014. };
  17015. // 获取产品型号联想词
  17016. $scope.getSimilarCodes = function (value) {
  17017. if (value) {
  17018. // 获取产品型号联想词
  17019. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  17020. return data.map(function (item) {
  17021. return item;
  17022. })
  17023. });
  17024. }
  17025. };
  17026. // 选择类目
  17027. $scope.selectKind = function (prod) {
  17028. var submit = [];
  17029. $modal.open({
  17030. animation: true,
  17031. size: 'lg',
  17032. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  17033. controller: 'ProdKindChooseCtrl',
  17034. resolve: {
  17035. actives: function () {
  17036. return $scope.actives;
  17037. }
  17038. }
  17039. }).result.then(function (data) {
  17040. $scope.actives = data.actives;
  17041. var size = data.actives.length;
  17042. submit.gradeOneKiName = '';
  17043. submit.gradeTwoKiName = '';
  17044. submit.gradeThreeKiName = '';
  17045. if (size > 0) {
  17046. submit.gradeOneKiName = $scope.actives[0].nameCn;
  17047. prod.prodTitle = submit.gradeOneKiName;
  17048. if (size > 1) {
  17049. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  17050. prod.prodTitle = submit.gradeTwoKiName;
  17051. if (size > 2) {
  17052. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  17053. prod.prodTitle = submit.gradeThreeKiName;
  17054. }
  17055. }
  17056. }
  17057. }, function () {
  17058. });
  17059. };
  17060. // 点击联想词获取品牌信息
  17061. $scope.onAssociateBrandClick = function (brand, prod) {
  17062. if (brand instanceof String) {
  17063. prod.brand = brand;
  17064. } else if (brand instanceof Object) {
  17065. prod.brand = brand.brandCn;
  17066. }
  17067. };
  17068. // 打开品牌选择的模态框
  17069. $scope.selectBrand = function (prod) { //打开模态
  17070. var modalInstance = $modal.open({
  17071. size: 'lg',
  17072. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  17073. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  17074. });
  17075. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  17076. });
  17077. modalInstance.result.then(function (brand) {
  17078. prod.brand = brand.nameCn;
  17079. }, function (reason) {
  17080. });
  17081. };
  17082. // 点击联想词获取器件信息 带入产品分类和品牌
  17083. $scope.onAssociateCmpClick = function (cmp, prod) {
  17084. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  17085. $scope.component = data;
  17086. prod.prodCode = data.code;
  17087. prod.prodTitle = data.kind.nameCn;
  17088. prod.brand = data.brand.nameCn;
  17089. }, function (res) {
  17090. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  17091. })
  17092. };
  17093. //联想词end
  17094. $scope.condition = {dateZone: 1};
  17095. $scope.tenderProd = [];
  17096. var prod = {
  17097. prodTitle: null,
  17098. prodCode: null,
  17099. brand: null,
  17100. unit: 'PCS',
  17101. qty: null
  17102. // 供应商企业信息
  17103. // enterpriseBaseInfo: [{}]
  17104. };
  17105. $scope.tender = {
  17106. date: new Date(),
  17107. unit: 'PCS',
  17108. currency: 'RMB',
  17109. ifOpen: 1,
  17110. ifTax: 1,
  17111. invoiceType: 2,
  17112. tenderAttachs: [{}]
  17113. };
  17114. //
  17115. $scope.tenderProd.push(prod);
  17116. //增加商品
  17117. $scope.add = function (index) {
  17118. $scope.tenderProd.push({
  17119. prodTitle: null,
  17120. prodCode: null,
  17121. brand: null,
  17122. unit: 'PCS',
  17123. qty: null
  17124. // 供应商企业信息
  17125. // enterpriseBaseInfo: [{}]
  17126. });
  17127. };
  17128. //删除商品
  17129. $scope.del = function (index) {
  17130. $scope.tenderProd.splice(index, 1);
  17131. };
  17132. // 批量导入
  17133. $scope.uplodaByBatch = function () {
  17134. var modalInstance = $modal.open({
  17135. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  17136. controller: 'PurcTenderUploadCtrl',
  17137. size: 'lg',
  17138. resolve: {}
  17139. });
  17140. modalInstance.result.then(function (data) {
  17141. // 获取上传的产品明细,前台展示
  17142. angular.forEach(data, function (data) {
  17143. $scope.tenderProd.push(data);
  17144. for (var i = 0; i < $scope.tenderProd.length; i++) {
  17145. if ($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  17146. $scope.tenderProd.splice(i, 1);
  17147. }
  17148. }
  17149. });
  17150. }, function () {
  17151. });
  17152. };
  17153. $scope.isSave = false;
  17154. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  17155. if (!angular.isUndefined($stateParams.id)) {
  17156. $scope.isSave = true; // 用于判断是新增还是已保存
  17157. $scope.loading = true;
  17158. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17159. data.$editing = false;
  17160. $scope.tender = data;
  17161. $scope.tenderProd = data.purchaseTenderProds;
  17162. parseCertificate($scope.tender.certificate);
  17163. $scope.firstProd = data.purchaseTenderProds[0];
  17164. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  17165. // 获取供应商联系人
  17166. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function (data) {
  17167. item.saleTender.enterpriseBaseInfo.contacts = data;
  17168. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  17169. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function (contact) {
  17170. if (item.saleTender.userTel === contact.tel) {
  17171. item.saleTender.enterpriseBaseInfo.contact = contact;
  17172. }
  17173. });
  17174. });
  17175. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  17176. $scope.tenderProd.enterpriseBaseInfo = [{}];
  17177. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  17178. } else {
  17179. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  17180. }
  17181. });
  17182. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  17183. $scope.loading = false;
  17184. $scope.attaches = $scope.tender.tenderAttaches;
  17185. }, function (response) {
  17186. $scope.loading = false;
  17187. toaster.pop('error', '数据加载失败', response.data);
  17188. });
  17189. }
  17190. if (angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  17191. $rootScope.tenderVendor = [{}];
  17192. }
  17193. $scope.changeShipAddress = false;
  17194. $scope.changeAddress = function () {
  17195. if ($scope.changeShipAddress) {
  17196. $scope.changeShipAddress = false;
  17197. } else {
  17198. $scope.changeShipAddress = true;
  17199. }
  17200. };
  17201. $scope.changeContactInfo = function (en) {
  17202. if (en.changeContact) {
  17203. en.changeContact = false;
  17204. } else {
  17205. en.changeContact = true;
  17206. }
  17207. };
  17208. $scope.changeCurrency = function (tender) {
  17209. if (tender.currency !== 'RMB') {
  17210. $scope.notRMB = true;
  17211. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  17212. tender.invoiceType = 0;
  17213. } else {
  17214. $scope.notRMB = false;
  17215. }
  17216. };
  17217. // 查找供应商
  17218. $scope.dbfindVendor = function () {
  17219. var modalInstance = $modal.open({
  17220. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  17221. controller: 'DbfindVendorCtrl',
  17222. size: 'lg',
  17223. resolve: {}
  17224. });
  17225. var ifPush = true;
  17226. modalInstance.result.then(function (data) {
  17227. angular.forEach(data, function (vendor) {
  17228. // 获取供应商联系人
  17229. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function (data) {
  17230. vendor.vendorEnterprise.contacts = data;
  17231. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  17232. });
  17233. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  17234. $scope.tenderProd.enterpriseBaseInfo = [{}];
  17235. // 获取供应商联系人
  17236. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  17237. } else {
  17238. for (var i = 0; i < $scope.tenderProd.enterpriseBaseInfo.length; i++) {
  17239. ifPush = true;
  17240. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  17241. ifPush = false;
  17242. break; // 判定到已存在供应商,就终止循环。
  17243. }
  17244. }
  17245. if (ifPush) {
  17246. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  17247. }
  17248. }
  17249. });
  17250. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  17251. }, function () {
  17252. });
  17253. };
  17254. // 新增供应商联系人
  17255. $scope.addContact = function (en) {
  17256. var modalInstance = $modal.open({
  17257. animation: true,
  17258. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  17259. controller: 'AddContacCtrl',
  17260. resolve: {}
  17261. });
  17262. modalInstance.result.then(function (data) {
  17263. en.contact = data;
  17264. en.contact.venduu = en.uu;
  17265. Vendor.saveContact({}, en.contact, function (data) {
  17266. Vendor.contacts({venduu: en.uu}, {}, function (data) {
  17267. en.contacts = data;
  17268. en.contact = data[0]; // 新增的作为联系人
  17269. });
  17270. toaster.pop('success', '提示', '联系人保存成功');
  17271. }, function (response) {
  17272. toaster.pop('error', '失败', response.data);
  17273. });
  17274. });
  17275. };
  17276. // 删除一个供应商
  17277. $scope.removeVendor = function (index) {
  17278. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  17279. };
  17280. // 删除供应商时,后台删除投标单
  17281. $scope.removeSaleTender = function (id, vendUU) {
  17282. var hasSaved = false;
  17283. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function (saleTenderItem) {
  17284. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  17285. hasSaved = true;
  17286. }
  17287. });
  17288. if (hasSaved) {
  17289. PurcTender.removeSaleTender({id: id, vendUU: vendUU}, {}, function (data) {
  17290. }, function (response) {
  17291. toaster.pop('error', '提示', response.data);
  17292. });
  17293. }
  17294. };
  17295. // 删除产品明细时,后台删除产品明细
  17296. $scope.deleteProd = function (tenderProd) {
  17297. if (tenderProd.id) {
  17298. PurcTender.deleteProd({tenderProdId: tenderProd.id}, {}, function (data) {
  17299. }, function (response) {
  17300. toaster.pop('error', '提示', response.data);
  17301. });
  17302. }
  17303. };
  17304. if (!$scope.attaches) {
  17305. $scope.attaches = []; // 存放上传了的附件
  17306. }
  17307. $scope.upload = function (myFile) { // 上传附件
  17308. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  17309. $upload.upload({
  17310. url: 'tender/addTenderAttach',
  17311. file: file,
  17312. method: 'POST'
  17313. }).success(function (attach) {
  17314. $scope.attaches.push(attach);
  17315. });
  17316. };
  17317. $scope.removeAttach = function (id, index) {
  17318. $scope.attaches.splice(index, 1);
  17319. };
  17320. var sleep = function (d) {
  17321. for (var t = Date.now(); Date.now() - t <= d;);
  17322. };
  17323. // 保存和发布招标单
  17324. $scope.save = function (isPublish) {
  17325. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  17326. toaster.pop('info', '提示', '请先指定供应商');
  17327. } else {
  17328. $scope.loading = true;
  17329. // --组装证照要求
  17330. var myCertificate = [];
  17331. angular.forEach($scope.certificates, function (certificate) {
  17332. if (certificate.checked) {
  17333. myCertificate.push(certificate.name);
  17334. }
  17335. });
  17336. $scope.tender.certificate = myCertificate.join(',');
  17337. if (!$scope.tender.code) { //新增,设单号
  17338. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  17339. }
  17340. if ($scope.tender.date instanceof Date) {
  17341. $scope.tender.date = $scope.tender.date.getTime();
  17342. }
  17343. if ($scope.tender.endDate instanceof Date) {
  17344. $scope.tender.endDate = $scope.tender.endDate.getTime();
  17345. }
  17346. if ($scope.tender.publishDate instanceof Date) {
  17347. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  17348. }
  17349. if ($scope.tender.questionEndDate instanceof Date) {
  17350. $scope.tender.questionEndDate = $scope.tender.questionEndDate.getTime();
  17351. }
  17352. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  17353. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  17354. $scope.tender.purchaseTenderProds[i].index = i + 1;
  17355. }
  17356. $scope.tender.tenderAttaches = $scope.attaches;
  17357. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  17358. var enInfos = [];
  17359. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  17360. var enInfo = {
  17361. uu: null,
  17362. contact: null,
  17363. contactTel: null
  17364. };
  17365. enInfo.uu = enterpriseBaseInfo.uu;
  17366. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17367. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17368. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17369. }
  17370. enInfos.push(enInfo);
  17371. });
  17372. if (isPublish) { // 发布
  17373. toaster.pop('info', '提示', '正在发布,请稍候');
  17374. $scope.tender.isPublish = 1;
  17375. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17376. // sleep(1500); //当前方法暂停1.5秒
  17377. $scope.loading = false;
  17378. toaster.pop('success', '成功', '发布成功');
  17379. window.location.hash = '#/purc/tender';
  17380. }, function (response) {
  17381. $scope.loading = false;
  17382. toaster.pop('error', '发布失败', response.data);
  17383. });
  17384. } else { // 保存
  17385. toaster.pop('info', '提示', '正在保存,请稍候');
  17386. $scope.tender.isPublish = 0;
  17387. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17388. $scope.loading = false;
  17389. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  17390. toaster.pop('success', '成功', '保存成功');
  17391. window.location.hash = '#/purc/tender';
  17392. }, function (response) {
  17393. $scope.loading = false;
  17394. toaster.pop('error', '保存失败', response.data);
  17395. });
  17396. }
  17397. }
  17398. };
  17399. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  17400. $scope.removeChecked = function () {
  17401. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  17402. $scope.tenderProd.enterpriseBaseInfo = [];
  17403. }
  17404. };
  17405. // 删除(在录入状态)
  17406. $scope.deleteThis = function (id) {
  17407. PurcTender.deleteOne({id: id}, {}, function (data) {
  17408. toaster.pop('info', '提示', '删除成功');
  17409. window.location.hash = '#/purc/tender';
  17410. });
  17411. };
  17412. // 更新和发布(在录入状态)
  17413. $scope.updateSaved = function (isPublish) {
  17414. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  17415. toaster.pop('info', '提示', '请先指定供应商');
  17416. } else {
  17417. $scope.loading = true;
  17418. // --组装证照要求
  17419. var myCertificate = [];
  17420. angular.forEach($scope.certificates, function (certificate) {
  17421. if (certificate.checked) {
  17422. myCertificate.push(certificate.name);
  17423. }
  17424. });
  17425. $scope.tender.certificate = myCertificate.join(',');
  17426. if ($scope.tender.endDate instanceof Date) {
  17427. $scope.tender.endDate = $scope.tender.endDate.getTime();
  17428. }
  17429. if ($scope.tender.publishDate instanceof Date) {
  17430. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  17431. }
  17432. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  17433. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  17434. $scope.tender.purchaseTenderProds[i].index = i + 1;
  17435. }
  17436. $scope.tender.tenderAttaches = $scope.attaches;
  17437. if ($scope.tender.shipadd) {
  17438. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  17439. }
  17440. angular.forEach($scope.tender.purchaseTenderProds, function (tenderProd) {
  17441. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  17442. });
  17443. var enInfos = [];
  17444. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  17445. var enInfo = {
  17446. uu: null,
  17447. contact: null,
  17448. contactTel: null
  17449. };
  17450. enInfo.uu = enterpriseBaseInfo.uu;
  17451. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17452. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17453. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17454. }
  17455. enInfos.push(enInfo);
  17456. });
  17457. if (isPublish) { // 发布
  17458. toaster.pop('info', '提示', '正在发布,请稍候');
  17459. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17460. $scope.loading = false;
  17461. toaster.pop('success', '成功', '发布成功');
  17462. window.location.hash = '#/purc/tender';
  17463. }, function (response) {
  17464. $scope.loading = false;
  17465. toaster.pop('error', '发布失败', response.data);
  17466. });
  17467. } else { // 保存
  17468. toaster.pop('info', '提示', '正在保存,请稍候');
  17469. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17470. $scope.loading = false;
  17471. toaster.pop('success', '成功', '保存成功');
  17472. window.location.reload();
  17473. }, function (response) {
  17474. $scope.loading = false;
  17475. toaster.pop('error', '保存失败', response.data);
  17476. });
  17477. }
  17478. }
  17479. };
  17480. $scope.currentDay = function () {
  17481. return $filter('date')(new Date(), 'yyyy-MM-dd');
  17482. };
  17483. $scope.getMinDate = function () {
  17484. if ($scope.tender.endDate instanceof Date) {
  17485. var minDate = new Date($scope.tender.endDate.getTime() + 2 * 24 * 60 * 60 * 1000 + 1); // 公布结果日期与截止报价日期至少隔一天
  17486. }
  17487. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd') : $filter('date')(new Date(new Date().getTime() + 24 * 60 * 60 * 1000 + 1), 'yyyy-MM-dd');
  17488. };
  17489. $scope.getMaxDate = function () {
  17490. // var maxDate = angular.copy($scope.tender.publishDate);
  17491. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  17492. if ($scope.tender.publishDate instanceof Date) {
  17493. var maxDate = new Date($scope.tender.publishDate.getTime() - 24 * 60 * 60 * 1000 - 1); // 至少提前两天
  17494. }
  17495. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd') : "";
  17496. };
  17497. $scope.openDatePicker = function ($event, item, openParam) {
  17498. $event.preventDefault();
  17499. $event.stopPropagation();
  17500. item[openParam] = !item[openParam];
  17501. };
  17502. }]);
  17503. //类目选择模态框(招标产品明细)
  17504. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function ($scope, KindAPI, actives, toaster, $modalInstance) {
  17505. $scope.actives = actives;
  17506. $scope.kinds = [[], [], [], []];
  17507. // 获取子类目
  17508. var getChildren = function (pid, deep) {
  17509. KindAPI.getChildren({parentId: pid}, function (data) {
  17510. $scope.kinds[deep] = data;
  17511. }, function (response) {
  17512. toaster.pop('error', '获取子类目失败', response.data);
  17513. });
  17514. };
  17515. // 改变节点选中状态
  17516. var changeStatus = function (item, deep) {
  17517. var actives = [], level = 0;
  17518. angular.forEach($scope.kinds, function (ks, i) {
  17519. if (i > deep) {
  17520. $scope.kinds[i] = [];
  17521. } else {
  17522. angular.forEach(ks, function (k, j) {
  17523. if (i == deep) {
  17524. if (k.id == item.id) {
  17525. $scope.kinds[i][j].$active = true;
  17526. actives.push(k);
  17527. } else {
  17528. k.$active = null;
  17529. }
  17530. } else {
  17531. if (k.$active) {
  17532. actives.push(k);
  17533. }
  17534. }
  17535. });
  17536. }
  17537. });
  17538. // 选择的节点
  17539. $scope.actives = actives;
  17540. $scope.active = item;
  17541. // 当前可操作的层级
  17542. if (deep < 3) {
  17543. $scope.activeDeep = deep + 1;
  17544. }
  17545. };
  17546. // 节点点击后获取子类目,节点被选中
  17547. $scope.onItemClick = function (item, deep) {
  17548. changeStatus(item, deep);
  17549. if (!item.isLeaf) {
  17550. getChildren(item.id, deep + 1);
  17551. }
  17552. };
  17553. // 重新加载数据
  17554. function reload(deep) {
  17555. var pid;
  17556. if (deep) {
  17557. pid = $scope.actives[deep - 1].id;
  17558. } else {
  17559. pid = 0;
  17560. deep = 0;
  17561. }
  17562. getChildren(pid, deep);
  17563. }
  17564. // 初始加载数据,获取第一层的类目
  17565. if ($scope.actives) {
  17566. angular.forEach($scope.actives, function (v, k) {
  17567. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  17568. $scope.kinds[k] = data;
  17569. angular.forEach($scope.kinds[k], function (kind, i) {
  17570. if (kind.id == v.id) {
  17571. $scope.kinds[k][i].$active = true;
  17572. $scope.actives[k] = $scope.kinds[k][i];
  17573. }
  17574. })
  17575. }, function (response) {
  17576. toaster.pop('error', '获取子类目失败', response.data);
  17577. });
  17578. });
  17579. } else {
  17580. reload();
  17581. }
  17582. // 取消
  17583. $scope.cancel = function () {
  17584. $modalInstance.dismiss();
  17585. };
  17586. // 确认选择
  17587. $scope.check = function () {
  17588. var a = {
  17589. active: $scope.active,
  17590. actives: $scope.actives
  17591. };
  17592. $modalInstance.close(a);
  17593. };
  17594. }]);
  17595. //品牌选择模态框的controller
  17596. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function ($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  17597. $scope.filter = {};
  17598. $scope.brandsTableParams = new ngTableParams({
  17599. page: 1,
  17600. count: 6,
  17601. sorting: {
  17602. nameCn: 'asc'
  17603. }
  17604. }, {
  17605. total: 0,
  17606. counts: [],
  17607. getData: function ($defer, params) {
  17608. var param = BaseService.parseParams(params.url());
  17609. param.keyword = $scope.filter.keyword;
  17610. var keyword = $scope.filter.keyword;
  17611. // param.keyword = $scope.filter.keyword;
  17612. BrandActiveAPI.getSimpleInfoPage(param, {}, function (page) {
  17613. if (page) {
  17614. params.total(page.totalElements);
  17615. $defer.resolve(page.content);
  17616. }
  17617. }, function () {
  17618. });
  17619. }
  17620. });
  17621. // 搜索
  17622. $scope.search = function () {
  17623. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  17624. $scope.brandsTableParams.page(1);
  17625. $scope.brandsTableParams.reload();
  17626. };
  17627. // 选择
  17628. $scope.select = function (brand) {
  17629. $modalInstance.close(brand);
  17630. };
  17631. // 关闭
  17632. $scope.cancel = function () {
  17633. $modalInstance.dismiss();
  17634. };
  17635. }]);
  17636. /**
  17637. * 招标单批量导入
  17638. */
  17639. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  17640. // 通过excel批量上传物料
  17641. $scope.result = null;
  17642. $scope.upload = function () {
  17643. var file = $scope.myFiles[0];
  17644. $upload.upload({
  17645. url: 'tender/release/excel',
  17646. file: file,
  17647. method: 'POST'
  17648. }).success(function (data) {
  17649. $scope.result = data;
  17650. $scope.success = $scope.result.success;
  17651. $scope.total = $scope.result.total;
  17652. $scope.alters = $scope.result.alters;
  17653. }).error(function (response) {
  17654. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  17655. });
  17656. };
  17657. // 查看范例
  17658. $scope.showImg = function () {
  17659. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  17660. box.show();
  17661. box.find('img').attr('src', src);
  17662. box.find('a').click(function () {
  17663. box.hide();
  17664. });
  17665. box.dblclick(function () {
  17666. box.hide();
  17667. });
  17668. };
  17669. // 下载模板
  17670. $scope.download = function () {
  17671. window.location.href = 'tender/upload/template';
  17672. };
  17673. $scope.enSure = function () {
  17674. $modalInstance.close($scope.result.items);
  17675. }
  17676. $scope.cancel = function () {
  17677. $modalInstance.dismiss();
  17678. }
  17679. }]);
  17680. /**
  17681. * 评标
  17682. */
  17683. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, CurrentRole) {
  17684. BaseService.scrollBackToTop();
  17685. // 获取当前用户是否为普通用户
  17686. CurrentRole.isUser({}, {}, function (data) {
  17687. $scope.isUser = data.isUser;
  17688. });
  17689. $scope.tenderItems = [];
  17690. // 采购方获取评标单
  17691. var evaluation = function () {
  17692. $scope.loading = true;
  17693. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17694. data.$editing = false;
  17695. $scope.tender = data;
  17696. $scope.tableParams = new ngTableParams({}, {dataset: data});
  17697. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  17698. $scope.loading = false;
  17699. }, function (response) {
  17700. $scope.loading = false;
  17701. toaster.pop('error', '数据加载失败', response.data);
  17702. });
  17703. };
  17704. evaluation();
  17705. $scope.orderType = '';
  17706. // $scope.dir = '-';
  17707. // 改变排序顺序
  17708. $scope.changeOrder = function (type) {
  17709. $scope.orderType = type;
  17710. };
  17711. $scope.submit = function (tender) {
  17712. var canSubmit = false;
  17713. var hasDecide = false;
  17714. angular.forEach(tender.purchaseTenderProds, function (tenderProd) {
  17715. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17716. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  17717. hasDecide = true;
  17718. }
  17719. });
  17720. if (hasDecide) {
  17721. canSubmit = true;
  17722. }
  17723. });
  17724. if (!canSubmit) {
  17725. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  17726. } else {
  17727. PurcTender.decide(tender, function () {
  17728. toaster.pop('success', '确认成功');
  17729. window.location.hash = '#/purc/tender';
  17730. }, function (response) {
  17731. toaster.pop('error', '确认失败', response.data);
  17732. });
  17733. }
  17734. }
  17735. }]);
  17736. /**
  17737. * 客户招标
  17738. *
  17739. */
  17740. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', 'PurcTenderInfo',
  17741. function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise, PurcTenderInfo) {
  17742. BaseService.scrollBackToTop();
  17743. if ($rootScope.active) {
  17744. $scope.active = $rootScope.active;
  17745. $rootScope.active = null;
  17746. } else {
  17747. $scope.active = 'todo';
  17748. }
  17749. $scope.searchStatus = false;
  17750. /**
  17751. * 改变类型
  17752. */
  17753. var getTypeCondition = function (zone, condition) {
  17754. if (zone == -1) {
  17755. condition.ifOpen = null;
  17756. } else if (zone == 1) {
  17757. condition.ifOpen = 1;
  17758. } else {
  17759. condition.ifOpen = 0;
  17760. }
  17761. };
  17762. $scope.dateZoneText = '不限';
  17763. $scope.typeText = '全部';
  17764. $scope.deliveryZoneText = '不限';
  17765. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17766. /* 时间筛选初始化*/
  17767. var fromDate = new Date();
  17768. var toDate = new Date();
  17769. fromDate.setMonth(fromDate.getMonth() - 1);
  17770. fromDate.setHours(0, 0, 0, 0);
  17771. toDate.setHours(23, 59, 59, 999);
  17772. $scope.condition.dateFrom = fromDate;
  17773. $scope.condition.dateTo = toDate;
  17774. $scope.changeDateZone = function (zone) {
  17775. $scope.condition.dateZone = zone;
  17776. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17777. $scope.condition.$dateZoneOpen = false;
  17778. getDateCondition(zone, $scope.condition);
  17779. $scope.tableParams.page(1);
  17780. $scope.tableParams.reload();
  17781. };
  17782. $scope.changeDeliveryZone = function (zone) {
  17783. $scope.condition.deliveryZoneText = zone;
  17784. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17785. $scope.condition.$delievryZoneOpen = false;
  17786. getDelveryCondition(zone, $scope.condition);
  17787. $scope.tableParams.page(1);
  17788. $scope.tableParams.reload();
  17789. };
  17790. $scope.changeType = function (type) {
  17791. $scope.condition.type = type;
  17792. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17793. getTypeCondition(type, $scope.condition);
  17794. $scope.tableParams.reload();
  17795. };
  17796. $scope.setActive = function (state) {
  17797. if ($scope.active != state) {
  17798. $scope.active = state;
  17799. if ($scope.tableParams.page() == 1)
  17800. $scope.tableParams.reload();
  17801. else
  17802. $scope.tableParams.page(1);
  17803. }
  17804. };
  17805. var getService = function () {
  17806. if ($scope.searchStatus) {
  17807. return PurcTender;
  17808. }
  17809. return PurcTenderInfo;
  17810. };
  17811. $scope.tableParams = new ngTableParams({
  17812. page: 1,
  17813. count: 20,
  17814. sorting: {
  17815. 'id': 'desc'
  17816. }
  17817. }, {
  17818. total: 0,
  17819. counts: [5, 10, 25, 50],
  17820. getData: function ($defer, params) {
  17821. $scope.loading = true;
  17822. var pageParams = params.url();
  17823. var realActive = {};
  17824. pageParams.searchFilter = { // 筛选条件
  17825. keyword: $scope.keyword,
  17826. pt_ifopen: $scope.condition.ifOpen,
  17827. fromDate: getDateTime($scope.condition.dateFrom),
  17828. endDate: getDateTime($scope.condition.dateTo)
  17829. };
  17830. AccountEnterprise.get({}, function (data) {
  17831. $scope.currentEn = data;
  17832. });
  17833. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17834. $scope.loading = false;
  17835. if (page) {
  17836. params.total(page.totalElement);
  17837. $defer.resolve(page.content);
  17838. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17839. angular.forEach(page.content, function (purcTender) {
  17840. purcTender.vendorHasBid = false;
  17841. angular.forEach(purcTender.purchaseTenderProds, function (tenderProd) {
  17842. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17843. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  17844. tenderProd.currentItem = saleTenderItem;
  17845. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  17846. purcTender.vendorHasBid = true;
  17847. }
  17848. }
  17849. });
  17850. });
  17851. });
  17852. }
  17853. }, function (response) {
  17854. $scope.loading = false;
  17855. toaster.pop('error', '数据加载失败', response.data);
  17856. });
  17857. }
  17858. });
  17859. //获得各分类未阅读数量
  17860. var getUnreadCount = function () {
  17861. PurcTender.getUnreadCount(null, function (data) {
  17862. $scope.unread = data;
  17863. });
  17864. };
  17865. getUnreadCount();
  17866. //设置单据已读
  17867. $scope.setOrdersRead = function (id) {
  17868. // 如果单据本身已读,则不发送请求修改数据
  17869. if (!$scope.isUnread(id)){
  17870. return;
  17871. }
  17872. var sourceId = [];
  17873. sourceId.push(id);
  17874. PurcTender.setRead({}, sourceId, function (message) {
  17875. // $scope.getUnreadIds();
  17876. getUnreadCount();
  17877. });
  17878. };
  17879. var getUnreadIds = function () {
  17880. PurcTender.getUnreadIds({}, "", function (message) {
  17881. $scope.unreadCode = message.content;
  17882. });
  17883. };
  17884. getUnreadIds();
  17885. $scope.isUnread = function (id) {
  17886. for (var i in $scope.unreadCode) {
  17887. if (id == $scope.unreadCode[i]) {
  17888. return true;
  17889. }
  17890. }
  17891. };
  17892. $scope.openDatePicker = function ($event, item, openParam) {
  17893. $event.preventDefault();
  17894. $event.stopPropagation();
  17895. item[openParam] = !item[openParam];
  17896. };
  17897. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17898. $event.preventDefault();
  17899. $event.stopPropagation();
  17900. item[openParam] = !item[openParam];
  17901. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17902. $scope.tableParams.reload();
  17903. }
  17904. };
  17905. $scope.parseDate = function (dateStr) {
  17906. if (dateStr)
  17907. return Date.parse(dateStr, 'yyyy-MM-dd');
  17908. return new Date();
  17909. };
  17910. // 选择查找日期
  17911. $scope.onDateCondition = function () {
  17912. $scope.tableParams.page(1);
  17913. $scope.tableParams.reload();
  17914. };
  17915. // 搜索框回车
  17916. $scope.onSearch = function () {
  17917. $scope.searchStatus = true;
  17918. $scope.tableParams.page(1);
  17919. $scope.tableParams.reload();
  17920. };
  17921. }]);
  17922. /**
  17923. * 招标提问列表
  17924. *
  17925. */
  17926. app.controller('SaleTenderQuestionListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17927. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17928. BaseService.scrollBackToTop();
  17929. if ($rootScope.active) {
  17930. $scope.active = $rootScope.active;
  17931. $rootScope.active = null;
  17932. } else {
  17933. $scope.active = 'todo';
  17934. }
  17935. $scope.searchStatus = false;
  17936. /**
  17937. * 改变类型
  17938. */
  17939. var getTypeCondition = function (zone, condition) {
  17940. if (zone == -1) {
  17941. condition.ifOpen = null;
  17942. } else if (zone == 1) {
  17943. condition.ifOpen = 1;
  17944. } else {
  17945. condition.ifOpen = 0;
  17946. }
  17947. };
  17948. $scope.dateZoneText = '不限';
  17949. $scope.typeText = '全部';
  17950. $scope.deliveryZoneText = '不限';
  17951. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17952. /* 时间筛选初始化*/
  17953. var fromDate = new Date();
  17954. var toDate = new Date();
  17955. fromDate.setMonth(fromDate.getMonth() - 1);
  17956. fromDate.setHours(0, 0, 0, 0);
  17957. toDate.setHours(23, 59, 59, 999);
  17958. $scope.condition.dateFrom = fromDate;
  17959. $scope.condition.dateTo = toDate;
  17960. $scope.changeDateZone = function (zone) {
  17961. $scope.condition.dateZone = zone;
  17962. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17963. $scope.condition.$dateZoneOpen = false;
  17964. getDateCondition(zone, $scope.condition);
  17965. $scope.tableParams.page(1);
  17966. $scope.tableParams.reload();
  17967. };
  17968. $scope.changeDeliveryZone = function (zone) {
  17969. $scope.condition.deliveryZoneText = zone;
  17970. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17971. $scope.condition.$delievryZoneOpen = false;
  17972. getDelveryCondition(zone, $scope.condition);
  17973. $scope.tableParams.page(1);
  17974. $scope.tableParams.reload();
  17975. };
  17976. $scope.changeType = function (type) {
  17977. $scope.condition.type = type;
  17978. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17979. getTypeCondition(type, $scope.condition);
  17980. $scope.tableParams.reload();
  17981. };
  17982. $scope.setActive = function (state) {
  17983. if ($scope.active != state) {
  17984. $scope.active = state;
  17985. if ($scope.tableParams.page() == 1)
  17986. $scope.tableParams.reload();
  17987. else
  17988. $scope.tableParams.page(1);
  17989. }
  17990. };
  17991. //TODO 增加直接从数据库取方法之后修改
  17992. var getService = function () {
  17993. if ($scope.searchStatus) {
  17994. return SaleTenderQuestion;
  17995. }
  17996. return SaleTenderQuestion;
  17997. };
  17998. $scope.tableParams = new ngTableParams({
  17999. page: 1,
  18000. count: 20,
  18001. sorting: {
  18002. 'id': 'desc'
  18003. }
  18004. }, {
  18005. total: 0,
  18006. counts: [5, 10, 25, 50],
  18007. getData: function ($defer, params) {
  18008. $scope.loading = true;
  18009. var pageParams = params.url();
  18010. var realActive = {};
  18011. pageParams.searchFilter = { // 筛选条件
  18012. keyword: $scope.keyword,
  18013. fromDate: getDateTime($scope.condition.dateFrom),
  18014. endDate: getDateTime($scope.condition.dateTo)
  18015. };
  18016. AccountEnterprise.get({}, function (data) {
  18017. $scope.currentEn = data;
  18018. });
  18019. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18020. $scope.loading = false;
  18021. params.total(page.totalElement);
  18022. $defer.resolve(page.content);
  18023. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  18024. }, function (response) {
  18025. $scope.loading = false;
  18026. toaster.pop('error', '数据加载失败', response.data);
  18027. });
  18028. }
  18029. });
  18030. //TODO 获得各分类未阅读数量
  18031. //TODO 设置单据已读
  18032. $scope.openDatePicker = function ($event, item, openParam) {
  18033. $event.preventDefault();
  18034. $event.stopPropagation();
  18035. item[openParam] = !item[openParam];
  18036. };
  18037. $scope.openFilterDatePicker = function ($event, item, openParam) {
  18038. $event.preventDefault();
  18039. $event.stopPropagation();
  18040. item[openParam] = !item[openParam];
  18041. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  18042. $scope.tableParams.reload();
  18043. }
  18044. };
  18045. $scope.parseDate = function (dateStr) {
  18046. if (dateStr)
  18047. return Date.parse(dateStr, 'yyyy-MM-dd');
  18048. return new Date();
  18049. };
  18050. // 选择查找日期
  18051. $scope.onDateCondition = function () {
  18052. $scope.tableParams.page(1);
  18053. $scope.tableParams.reload();
  18054. };
  18055. // 搜索框回车
  18056. $scope.onSearch = function (keyword) {
  18057. // 每次搜索重置获取数据方法
  18058. $scope.searchMethod = false;
  18059. if(keyword != null && keyword != '') {
  18060. $scope.searchMethod = true;
  18061. }
  18062. $scope.tableParams.page(1);
  18063. $scope.tableParams.reload();
  18064. };
  18065. }]);
  18066. /**
  18067. * 投标单提问单详情
  18068. */
  18069. app.controller('SaleTenderQuestionDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams'
  18070. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams){
  18071. BaseService.scrollBackToTop();
  18072. $scope.loading = true;
  18073. var loadData = function () {
  18074. SaleTenderQuestion.getDetail({id: $stateParams.id}, function(data){
  18075. $scope.loading = false;
  18076. $scope.question = data;
  18077. } , function (response) {
  18078. $scope.loading = false;
  18079. toaster.pop('error', '数据加载失败');
  18080. });
  18081. };
  18082. loadData();
  18083. }]);
  18084. /**
  18085. * 招标答疑列表
  18086. *
  18087. */
  18088. app.controller('PurcTenderAnswerListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  18089. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  18090. BaseService.scrollBackToTop();
  18091. if ($rootScope.active) {
  18092. $scope.active = $rootScope.active;
  18093. $rootScope.active = null;
  18094. } else {
  18095. $scope.active = 'todo';
  18096. }
  18097. $scope.searchStatus = false;
  18098. /**
  18099. * 改变类型
  18100. */
  18101. var getTypeCondition = function (zone, condition) {
  18102. if (zone == -1) {
  18103. condition.ifOpen = null;
  18104. } else if (zone == 1) {
  18105. condition.ifOpen = 1;
  18106. } else {
  18107. condition.ifOpen = 0;
  18108. }
  18109. };
  18110. /**
  18111. * 当前页面状态按钮过滤
  18112. */
  18113. var getAnswer = function (active) {
  18114. var fn = 'getAllAnswer';
  18115. switch (active) {
  18116. case 'done':
  18117. fn = 'getDoneAnswer';
  18118. break;
  18119. case 'todo':
  18120. fn = 'getTodoAnswer';
  18121. break;
  18122. }
  18123. return fn;
  18124. };
  18125. $scope.dateZoneText = '不限';
  18126. $scope.typeText = '全部';
  18127. $scope.deliveryZoneText = '不限';
  18128. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  18129. /* 时间筛选初始化*/
  18130. var fromDate = new Date();
  18131. var toDate = new Date();
  18132. fromDate.setMonth(fromDate.getMonth() - 1);
  18133. fromDate.setHours(0, 0, 0, 0);
  18134. toDate.setHours(23, 59, 59, 999);
  18135. $scope.condition.dateFrom = fromDate;
  18136. $scope.condition.dateTo = toDate;
  18137. $scope.changeDateZone = function (zone) {
  18138. $scope.condition.dateZone = zone;
  18139. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  18140. $scope.condition.$dateZoneOpen = false;
  18141. getDateCondition(zone, $scope.condition);
  18142. $scope.tableParams.page(1);
  18143. $scope.tableParams.reload();
  18144. };
  18145. $scope.changeDeliveryZone = function (zone) {
  18146. $scope.condition.deliveryZoneText = zone;
  18147. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  18148. $scope.condition.$delievryZoneOpen = false;
  18149. getDelveryCondition(zone, $scope.condition);
  18150. $scope.tableParams.page(1);
  18151. $scope.tableParams.reload();
  18152. };
  18153. $scope.changeType = function (type) {
  18154. $scope.condition.type = type;
  18155. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  18156. getTypeCondition(type, $scope.condition);
  18157. $scope.tableParams.reload();
  18158. };
  18159. $scope.setActive = function (state) {
  18160. if ($scope.active != state) {
  18161. $scope.active = state;
  18162. if ($scope.tableParams.page() == 1)
  18163. $scope.tableParams.reload();
  18164. else
  18165. $scope.tableParams.page(1);
  18166. }
  18167. };
  18168. //TODO 增加直接从数据库取方法之后修改
  18169. var getService = function () {
  18170. if ($scope.searchStatus) {
  18171. return SaleTenderQuestion;
  18172. }
  18173. return SaleTenderQuestion;
  18174. };
  18175. $scope.tableParams = new ngTableParams({
  18176. page: 1,
  18177. count: 20,
  18178. sorting: {
  18179. 'id': 'desc'
  18180. }
  18181. }, {
  18182. total: 0,
  18183. counts: [5, 10, 25, 50],
  18184. getData: function ($defer, params) {
  18185. $scope.loading = true;
  18186. var pageParams = params.url();
  18187. var realActive = {};
  18188. pageParams.searchFilter = { // 筛选条件
  18189. keyword: $scope.keyword,
  18190. fromDate: getDateTime($scope.condition.dateFrom),
  18191. endDate: getDateTime($scope.condition.dateTo)
  18192. };
  18193. AccountEnterprise.get({}, function (data) {
  18194. $scope.currentEn = data;
  18195. });
  18196. getService()[getAnswer($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18197. $scope.loading = false;
  18198. params.total(page.totalElement);
  18199. $defer.resolve(page.content);
  18200. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  18201. }, function (response) {
  18202. $scope.loading = false;
  18203. toaster.pop('error', '数据加载失败', response.data);
  18204. });
  18205. }
  18206. });
  18207. //TODO 获得各分类未阅读数量
  18208. //TODO 设置单据已读
  18209. $scope.openDatePicker = function ($event, item, openParam) {
  18210. $event.preventDefault();
  18211. $event.stopPropagation();
  18212. item[openParam] = !item[openParam];
  18213. };
  18214. $scope.openFilterDatePicker = function ($event, item, openParam) {
  18215. $event.preventDefault();
  18216. $event.stopPropagation();
  18217. item[openParam] = !item[openParam];
  18218. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  18219. $scope.tableParams.reload();
  18220. }
  18221. };
  18222. $scope.parseDate = function (dateStr) {
  18223. if (dateStr)
  18224. return Date.parse(dateStr, 'yyyy-MM-dd');
  18225. return new Date();
  18226. };
  18227. // 选择查找日期
  18228. $scope.onDateCondition = function () {
  18229. $scope.tableParams.page(1);
  18230. $scope.tableParams.reload();
  18231. };
  18232. // 搜索框回车
  18233. $scope.onSearch = function (keyword) {
  18234. // 每次搜索重置获取数据方法
  18235. $scope.searchMethod = false;
  18236. if(keyword != null && keyword != '') {
  18237. $scope.searchMethod = true;
  18238. }
  18239. $scope.tableParams.page(1);
  18240. $scope.tableParams.reload();
  18241. };
  18242. }]);
  18243. /**
  18244. * 招标答疑单详情
  18245. */
  18246. app.controller('PurcTenderAnswerDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams', '$modal'
  18247. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams, $modal){
  18248. BaseService.scrollBackToTop();
  18249. $scope.loading = true;
  18250. var loadData = function () {
  18251. SaleTenderQuestion.getAnswerDetail({id: $stateParams.id}, function(data){
  18252. $scope.loading = false;
  18253. $scope.answer = data;
  18254. var now = new Date();
  18255. if ($scope.answer.questionEndDate < now.getTime()) {
  18256. $scope.answer.questionEnd = 1;
  18257. } else {
  18258. $scope.answer.questionEnd = 0;
  18259. }
  18260. } , function (response) {
  18261. $scope.loading = false;
  18262. toaster.pop('error', '数据加载失败');
  18263. });
  18264. };
  18265. loadData();
  18266. // 回答
  18267. $scope.sendAnswer = function (){
  18268. var modalInstance = $modal.open({
  18269. animation: true,
  18270. templateUrl: 'static/tpl/index/purc/tender_answer.html',
  18271. controller: 'PurcTenderAnswerCtrl',
  18272. size: 'lg',
  18273. resolve: {
  18274. answer: function () {
  18275. return $scope.answer;
  18276. } //传递当前答疑单到模态框Controller
  18277. }
  18278. });
  18279. modalInstance.result.then(function () {
  18280. toaster.pop('success', '答疑成功');
  18281. }, function () {
  18282. });
  18283. };
  18284. }]);
  18285. /**
  18286. * 招标单答疑
  18287. */
  18288. app.controller('PurcTenderAnswerCtrl', ['$scope', 'answer','$modalInstance', '$upload', 'toaster', function($scope, answer, $modalInstance, $upload ,toaster){
  18289. $scope.answer = answer;
  18290. $scope.cancel = function() {
  18291. $modalInstance.dismiss();
  18292. };
  18293. //确认回答
  18294. $scope.ok = function (form) {
  18295. $scope.loading = true;
  18296. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18297. $upload.upload({
  18298. url: 'tender/question/answer/send',
  18299. method: 'POST',
  18300. file: file,
  18301. data: {
  18302. json: $scope.answer
  18303. }
  18304. }).success(function (data) {
  18305. $scope.loading = false;
  18306. $modalInstance.close('success');
  18307. }).error(function (data) {
  18308. $scope.loading = false;
  18309. toaster.pop('error', '错误', '出现异常,答疑失败');
  18310. });
  18311. };
  18312. }]);
  18313. /**
  18314. * 平台公开招标
  18315. *
  18316. */
  18317. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  18318. BaseService.scrollBackToTop();
  18319. /**
  18320. * 改变单据日期范围
  18321. */
  18322. var getTenderDateCondition = function (zone, condition) {
  18323. var date = new Date();
  18324. if (zone == -1) {
  18325. condition.dateFrom = null;
  18326. condition.dateTo = null;
  18327. } else if (zone == 7) { // 一星期内
  18328. date.setDate(date.getDate() - 7);
  18329. condition.dateFrom = date;
  18330. condition.dateTo = new Date();
  18331. } else if (zone == 1) { // 一个月内
  18332. date.setMonth(date.getMonth() - 1);
  18333. condition.dateFrom = date;
  18334. condition.dateTo = new Date();
  18335. } else if (zone == 3) { // 三个月内
  18336. date.setMonth(date.getMonth() - 3);
  18337. condition.dateFrom = date;
  18338. condition.dateTo = new Date();
  18339. } else if (zone == 6) { // 半年内
  18340. date.setMonth(date.getMonth() - 6);
  18341. condition.dateFrom = date;
  18342. condition.dateTo = new Date();
  18343. } else { // 一年内
  18344. date.setYear(date.getYear() - 1);
  18345. condition.dateFrom = date;
  18346. condition.dateTo = new Date();
  18347. }
  18348. };
  18349. $scope.active = 'all';
  18350. $scope.dateZoneText = '不限';
  18351. $scope.deliveryZoneText = '不限';
  18352. $scope.condition = {dateZone: -1};
  18353. $scope.changeDateZone = function (zone) {
  18354. $scope.condition.dateZone = zone;
  18355. $scope.condition.$dateZoneOpen = false;
  18356. getTenderDateCondition(zone, $scope.condition);
  18357. $scope.tableParams.page(1);
  18358. $scope.tableParams.reload();
  18359. };
  18360. $scope.openDatePicker = function ($event, item, openParam) {
  18361. $event.preventDefault();
  18362. $event.stopPropagation();
  18363. item[openParam] = !item[openParam];
  18364. };
  18365. $scope.parseDate = function (dateStr) {
  18366. if (dateStr)
  18367. return Date.parse(dateStr, 'yyyy-MM-dd');
  18368. return new Date();
  18369. };
  18370. // 选择查找日期
  18371. $scope.onDateCondition = function () {
  18372. $scope.tableParams.page(1);
  18373. $scope.tableParams.reload();
  18374. };
  18375. var getOpenState = function (active) {
  18376. var fn = 'getOpenAll';
  18377. switch (active) {
  18378. case 'all':
  18379. fn = 'getOpenAll';
  18380. break;
  18381. // case 'done':
  18382. // fn = 'getOpenDone';break;
  18383. case 'todo':
  18384. fn = 'getOpenTodo';
  18385. break;
  18386. case 'end':
  18387. fn = 'getOpenEnd';
  18388. break;
  18389. // case 'waiting':
  18390. // fn = 'getOpenWaiting';break;
  18391. }
  18392. return fn;
  18393. };
  18394. $scope.tableParams = new ngTableParams({
  18395. page: 1,
  18396. count: 20,
  18397. sorting: {
  18398. 'tender.endDate': 'desc',
  18399. 'tender.enterprise.enName': 'asc',
  18400. 'tender.code': 'asc'
  18401. }
  18402. }, {
  18403. total: 0,
  18404. counts: [],
  18405. getData: function ($defer, params) {
  18406. $scope.loading = true;
  18407. var pageParams = params.url();
  18408. var realActive = {};
  18409. pageParams.searchFilter = { // 筛选条件
  18410. keyword: $scope.keyword,
  18411. fromDate: getDateTime($scope.condition.dateFrom),
  18412. endDate: getDateTime($scope.condition.dateTo)
  18413. };
  18414. AccountEnterprise.get({}, function (data) {
  18415. $scope.currentEn = data;
  18416. });
  18417. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18418. $scope.loading = false;
  18419. if (page) {
  18420. params.total(page.totalElement);
  18421. $defer.resolve(page.content);
  18422. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  18423. }
  18424. }, function (response) {
  18425. $scope.loading = false;
  18426. toaster.pop('error', '数据加载失败', response.data);
  18427. });
  18428. }
  18429. });
  18430. $scope.toDetail = function (id) {
  18431. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  18432. };
  18433. // 搜索框回车
  18434. $scope.onSearch = function () {
  18435. $scope.tableParams.page(1);
  18436. $scope.tableParams.reload();
  18437. };
  18438. }]);
  18439. /**
  18440. * 采购方查看供应商投标单
  18441. */
  18442. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  18443. $scope.loading = true;
  18444. PurcTender.getVendorSaleTenderDetail({tenderId: $stateParams.id, vendUU:$stateParams.vendUU}, function (data) {
  18445. $scope.saleTender = data.saleTender;
  18446. $scope.tender = data.tender;
  18447. $scope.loading = false;
  18448. }, function (response) {
  18449. $scope.loading = false;
  18450. toaster.pop('error', '数据加载失败', response.data);
  18451. });
  18452. }]);
  18453. /**
  18454. * 查看投标单详情
  18455. */
  18456. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise, CurrentRole) {
  18457. BaseService.scrollBackToTop();
  18458. if (!$scope.attaches) {
  18459. $scope.attaches = []; // 存放上传了的附件
  18460. }
  18461. AccountEnterprise.get({}, function (data) {
  18462. $scope.currentEn = data;
  18463. });
  18464. // 获取当前用户是否为普通用户
  18465. CurrentRole.isUser({}, {}, function (data) {
  18466. $scope.isUser = data.isUser;
  18467. });
  18468. $scope.loading = true;
  18469. PurcTender.getSaleTenderDetail({tenderId: $stateParams.id}, function (data) {
  18470. $scope.saleTender = data.saleTender;
  18471. $scope.tender = data.tender;
  18472. $scope.loading = false;
  18473. }, function (response) {
  18474. $scope.loading = false;
  18475. toaster.pop('error', '数据加载失败', response.data);
  18476. });
  18477. // 提问
  18478. $scope.sendQuestion = function (){
  18479. var modalInstance = $modal.open({
  18480. animation: true,
  18481. templateUrl: 'static/tpl/index/sale/tender_question.html',
  18482. controller: 'SaleTenderQuestionCtrl',
  18483. size: 'lg',
  18484. resolve: {
  18485. saleTender: function () {
  18486. return $scope.saleTender;
  18487. } //传递当前投标单到模态框Controller
  18488. }
  18489. });
  18490. modalInstance.result.then(function () {
  18491. toaster.pop('success', '提问成功');
  18492. }, function () {
  18493. });
  18494. };
  18495. $scope.upload = function (myFile) { // 上传附件
  18496. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  18497. $upload.upload({
  18498. url: 'tender/addTenderItemAttach',
  18499. file: file,
  18500. method: 'POST'
  18501. }).success(function (attach) {
  18502. $scope.attaches.push(attach);
  18503. });
  18504. };
  18505. $scope.removeAttach = function (attachId, index) {
  18506. $scope.attaches.splice(index, 1);
  18507. };
  18508. var taxrateYes = false;
  18509. var cycleYes = false;
  18510. var priceYes = false;
  18511. $scope.canSave = false;
  18512. $scope.validateThis = function (value, type) {
  18513. if ("" != value) {
  18514. switch (type) {
  18515. case 'taxrate':
  18516. var regex = /^\+?[0-9][0-9]{0,1}$/;
  18517. if (regex.test(value)) {
  18518. taxrateYes = true;
  18519. } else {
  18520. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  18521. }
  18522. break;
  18523. case 'cycle':
  18524. regex = /^\+?[1-9][0-9]*$/;
  18525. if (regex.test(value)) {
  18526. cycleYes = true;
  18527. } else {
  18528. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  18529. }
  18530. break;
  18531. case 'price':
  18532. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18533. if (regex.test(value) && value !== 0) {
  18534. priceYes = true;
  18535. } else {
  18536. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  18537. }
  18538. break;
  18539. }
  18540. }
  18541. };
  18542. $scope.emNumYes = true;
  18543. $scope.validEmNum = function (value) {
  18544. var regex = /^\+?[1-9][0-9]*$/;
  18545. if (!regex.test(value) || value === 0 || value !== null) {
  18546. $scope.emNumYes = false;
  18547. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  18548. }
  18549. };
  18550. $scope.validateProds = function (saleTender) {
  18551. $scope.canSave = true;
  18552. var cycleRegex = /^\+?[1-9][0-9]*$/;
  18553. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  18554. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  18555. if ($scope.tender.ifAll == 1) { // 全包时需要所有信息都填写并合法才可以投标
  18556. // 全包全部需要填写,且需要符合正则式
  18557. angular.forEach(saleTender.saleTenderItems, function(item) {
  18558. if ((!item.cycle || !item.price) || (!cycleRegex.test(item.cycle) || !priceRegex.test(item.price))) {
  18559. $scope.canSave = false;
  18560. }
  18561. });
  18562. if (!saleTender.cycle || !saleTender.taxrate || !cycleRegex.test(saleTender.cycle) || !taxrateRegex.test(saleTender.taxrate)) {
  18563. $scope.canSave = false;
  18564. }
  18565. } else { // 非全包模式
  18566. angular.forEach(saleTender.saleTenderItems, function(item) {
  18567. if (item.cycle || item.taxrate || item.price) {
  18568. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18569. // 判断填写过的有为0或不符合正则式的,设置不能保存
  18570. if (!cycleRegex.test(item.cycle) || !taxrateRegex.test(item.taxrate) || !priceRegex.test(item.price)) {
  18571. $scope.canSave = false;
  18572. } else {
  18573. $scope.canSave = true;
  18574. }
  18575. }
  18576. });
  18577. }
  18578. };
  18579. // 投标
  18580. $scope.bidIt = function (saleTender) {
  18581. $scope.loading = true;
  18582. if (saleTender.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  18583. saleTender.enterpriseBaseInfo.enEstablishDate = saleTender.enterpriseBaseInfo.enEstablishDate.getTime();
  18584. }
  18585. saleTender.bidAttaches.push.apply(saleTender.bidAttaches, $scope.attaches);
  18586. angular.forEach(saleTender.saleTenderItems, function (item) {
  18587. item.tenderProd = {};
  18588. if ("" == item.price && "" == item.taxrate && "" == item.cycle) {
  18589. item.price = 0;
  18590. item.cycle = 0;
  18591. item.taxrate = 0;
  18592. }
  18593. });
  18594. PurcTender.reply({}, saleTender, function (data) {
  18595. $scope.loading = false;
  18596. toaster.pop('info', '成功', '投标成功');
  18597. window.location.hash = '#/sale/tender';
  18598. }, function (response) {
  18599. $scope.loading = false;
  18600. toaster.pop('error', '投标失败', response.data);
  18601. });
  18602. };
  18603. $scope.condition = {
  18604. $fromOpened: false
  18605. };
  18606. $scope.getMaxDate = function () {
  18607. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18608. };
  18609. $scope.openDatePicker = function ($event, item, openParam) {
  18610. $event.preventDefault();
  18611. $event.stopPropagation();
  18612. item[openParam] = !item[openParam];
  18613. };
  18614. }]);
  18615. /**
  18616. * 投标单提问
  18617. */
  18618. app.controller('SaleTenderQuestionCtrl', ['$scope', 'saleTender','$modalInstance', '$upload', 'toaster', function($scope, saleTender, $modalInstance, $upload ,toaster){
  18619. $scope.saleTender = saleTender;
  18620. // 当前日期,用作新增提问
  18621. $scope.currentDay = new Date();
  18622. $scope.question = {
  18623. inDate : null,
  18624. replyDate : null,
  18625. topic : null,
  18626. status : null,
  18627. content : null,
  18628. questionAttaches : []
  18629. };
  18630. $scope.cancel = function() {
  18631. $modalInstance.dismiss();
  18632. };
  18633. //确认提问
  18634. $scope.ok = function (form) {
  18635. $scope.loading = true;
  18636. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18637. $upload.upload({
  18638. url: 'tender/question/send/' + $scope.saleTender.id,
  18639. method: 'POST',
  18640. file: file,
  18641. data: {
  18642. json: $scope.question
  18643. }
  18644. }).success(function (data) {
  18645. $scope.loading = false;
  18646. $modalInstance.close('success');
  18647. }).error(function (data) {
  18648. $scope.loading = false;
  18649. toaster.pop('error', '错误', '出现异常,提问失败');
  18650. });
  18651. };
  18652. }]);
  18653. /**
  18654. * 公开招标转投标单
  18655. */
  18656. app.controller('OpenSaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise) {
  18657. BaseService.scrollBackToTop();
  18658. $scope.attaches = []; // 存放上传了的附件
  18659. var sleep = function (d) {
  18660. for (var t = Date.now(); Date.now() - t <= d;);
  18661. }
  18662. var getCurrentEn = function () {
  18663. AccountEnterprise.get({}, function (data) {
  18664. $scope.currentEn = data;
  18665. });
  18666. }
  18667. if (!angular.isUndefined($stateParams.id)) { // 获取招标单详情
  18668. $scope.loading = true;
  18669. getCurrentEn();
  18670. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  18671. data.$editing = false;
  18672. $scope.tender = data;
  18673. $scope.tenderProd = data.purchaseTenderProds;
  18674. $scope.currentHasBid = false; // 默认当前企业未转投标单
  18675. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  18676. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  18677. $scope.currentHasBid = true;
  18678. }
  18679. });
  18680. $scope.loading = false;
  18681. $scope.attaches = $scope.tender.tenderAttaches;
  18682. }, function (response) {
  18683. $scope.loading = false;
  18684. toaster.pop('error', '数据加载失败', response.data);
  18685. });
  18686. }
  18687. $scope.hasClick = false;
  18688. $scope.iWantToBid = function (id) {
  18689. $scope.hasClick = true;
  18690. PurcTender.addItems({id: id}, {}, function (data) { // 添加明细
  18691. toaster.pop('success', '成功', '转投标单成功');
  18692. window.location.hash = "#/sale/tender/" + id;
  18693. }, function (response) {
  18694. toaster.pop('error', '操作失败', response.data);
  18695. });
  18696. };
  18697. }]);
  18698. // 基础资料客户详情
  18699. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'VendorInfo', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, VendorInfo) {
  18700. BaseService.scrollBackToTop();
  18701. $scope.status = 'customer';
  18702. $scope.userInfoResult = true;
  18703. AuthenticationService.getAuthentication().success(function (data) {
  18704. $scope.loading = false;
  18705. $scope.thisUser = data;
  18706. });
  18707. $scope.customerParams = new ngTableParams({
  18708. page: 1,
  18709. count: 20
  18710. }, {
  18711. total: 0,
  18712. counts: [],
  18713. getData: function ($defer, params) {
  18714. $scope.loading = true;
  18715. var pageParams = params.url();
  18716. pageParams.keyword = $scope.keyword;
  18717. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18718. $scope.loading = false;
  18719. if (page) {
  18720. params.total(page.totalElement);
  18721. $scope.total = page.totalElement;
  18722. $defer.resolve(page.content);
  18723. }
  18724. $scope.totalCount = page.totalElement;
  18725. }, function (response) {
  18726. $scope.loading = false;
  18727. toaster.pop('error', '数据加载失败', response.data);
  18728. });
  18729. }
  18730. });
  18731. // 搜索框回车
  18732. $scope.onSearch = function (keyword) {
  18733. $scope.customerParams.page(1);
  18734. $scope.customerParams.reload();
  18735. $scope.tip = keyword;
  18736. };
  18737. // 查看详情
  18738. $scope.viewDetail = function (id) {
  18739. window.location.hash = "#/sale/customer/" + id;
  18740. }
  18741. // 取消合作关系
  18742. $scope.disableCust = function (id) {
  18743. VendorInfo.disableCust({id: id}, {}, function (data) {
  18744. if (data.success) {
  18745. toaster.pop('success', '提示', data.success);
  18746. }
  18747. // $scope.customerParams.page(1);
  18748. $scope.customerParams.reload();
  18749. }, function (response) {
  18750. toaster.pop('error', '提示', response.data);
  18751. });
  18752. }
  18753. // 解除禁用
  18754. $scope.activeCust = function (id) {
  18755. VendorInfo.activeCust({id: id}, {}, function (data) {
  18756. if (data.success) {
  18757. toaster.pop('success', '提示', data.success);
  18758. }
  18759. // $scope.customerParams.page(1);
  18760. $scope.customerParams.reload();
  18761. }, function (response) {
  18762. toaster.pop('error', '提示', response.data);
  18763. });
  18764. }
  18765. }]);
  18766. // 基础资料供应商
  18767. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18768. BaseService.scrollBackToTop();
  18769. $scope.status = 'vendor';
  18770. // 搜索框回车
  18771. $scope.onSearch = function () {
  18772. $scope.customerParams.page(1);
  18773. $scope.customerParams.reload();
  18774. };
  18775. $scope.customerParams = new ngTableParams({
  18776. page: 1,
  18777. count: 20
  18778. }, {
  18779. total: 0,
  18780. counts: [],
  18781. getData: function ($defer, params) {
  18782. $scope.loading = true;
  18783. var pageParams = params.url();
  18784. pageParams.keyword = $scope.keyword;
  18785. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  18786. $scope.loading = false;
  18787. if (page) {
  18788. params.total(page.totalElement);
  18789. $scope.total = page.totalElement;
  18790. $defer.resolve(page.content);
  18791. }
  18792. $scope.totalCount = page.totalElement;
  18793. }, function (response) {
  18794. $scope.loading = false;
  18795. toaster.pop('error', '数据加载失败', response.data);
  18796. });
  18797. }
  18798. });
  18799. // 查看供应商详情
  18800. $scope.VendorDetail = function (id, uu) {
  18801. $rootScope.vendorId = id;
  18802. $rootScope.vendoruu = uu;
  18803. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18804. }
  18805. // 向企业购买
  18806. $scope.purcByEn = function (businessCode) {
  18807. $rootScope.businessCode = businessCode;
  18808. window.location.hash = "#/purc/addOrder";
  18809. }
  18810. // 取消合作关系
  18811. $scope.relieve = function (id) {
  18812. VendorInfo.relieve({id: id}, {}, function (data) {
  18813. if (data.success) {
  18814. toaster.pop('success', '提示', data.success);
  18815. }
  18816. // $scope.customerParams.page(1);
  18817. $scope.customerParams.reload();
  18818. }, function (response) {
  18819. toaster.pop('error', '提示', response.data);
  18820. });
  18821. }
  18822. // 建立合作关系
  18823. $scope.activeVend = function (id) {
  18824. VendorInfo.activeVend({id: id}, {}, function (data) {
  18825. if (data.success) {
  18826. toaster.pop('success', '提示', data.success);
  18827. }
  18828. // $scope.customerParams.page(1);
  18829. $scope.customerParams.reload();
  18830. }, function (response) {
  18831. toaster.pop('error', '提示', response.data);
  18832. });
  18833. }
  18834. }]);
  18835. // 基础资料服务商
  18836. app.controller('ServicerInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18837. BaseService.scrollBackToTop();
  18838. $scope.status = 'servicer';
  18839. // 搜索框回车
  18840. $scope.onSearch = function () {
  18841. $scope.customerParams.page(1);
  18842. $scope.customerParams.reload();
  18843. };
  18844. $scope.customerParams = new ngTableParams({
  18845. page: 1,
  18846. count: 20
  18847. }, {
  18848. total: 0,
  18849. counts: [],
  18850. getData: function ($defer, params) {
  18851. $scope.loading = true;
  18852. var pageParams = params.url();
  18853. pageParams.keyword = $scope.keyword;
  18854. Vendor.getServicer.call(null, BaseService.parseParams(pageParams), function (page) {
  18855. $scope.loading = false;
  18856. if (page) {
  18857. params.total(page.totalElement);
  18858. $scope.total = page.totalElement;
  18859. $defer.resolve(page.content);
  18860. }
  18861. $scope.totalCount = page.totalElement;
  18862. }, function (response) {
  18863. $scope.loading = false;
  18864. toaster.pop('error', '数据加载失败', response.data);
  18865. });
  18866. }
  18867. });
  18868. // 查看服务商详情
  18869. $scope.VendorDetail = function (id, uu) {
  18870. $rootScope.vendorId = id;
  18871. $rootScope.vendoruu = uu;
  18872. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18873. };
  18874. // 取消合作关系
  18875. $scope.relieveServicer = function (id) {
  18876. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  18877. if (data.success) {
  18878. toaster.pop('success', '提示', data.success);
  18879. }
  18880. // $scope.customerParams.page(1);
  18881. $scope.customerParams.reload();
  18882. }, function (response) {
  18883. toaster.pop('error', '提示', response.data);
  18884. });
  18885. }
  18886. // 建立合作关系
  18887. $scope.activeServicer = function (id) {
  18888. VendorInfo.activeServicer({id: id}, {}, function (data) {
  18889. if (data.success) {
  18890. toaster.pop('success', '提示', data.success);
  18891. }
  18892. // $scope.customerParams.page(1);
  18893. $scope.customerParams.reload();
  18894. }, function (response) {
  18895. toaster.pop('error', '提示', response.data);
  18896. });
  18897. }
  18898. }]);
  18899. // 企业圈搜索界面
  18900. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
  18901. $scope.onSearch = function (keyword) {
  18902. $rootScope.enterpriseKeyword = keyword;
  18903. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  18904. }
  18905. }]);
  18906. // 企业圈搜索结果
  18907. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  18908. $scope.status = 'add';
  18909. BaseService.scrollBackToTop();
  18910. $scope.active = 'all';
  18911. $scope.agreedText = '全部';
  18912. $scope.dateZoneText = '一个月内';
  18913. $scope.condition = {dateZone: 1};
  18914. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18915. $scope.changeAgreed = function (agreed) {
  18916. $scope.condition.agreed = agreed;
  18917. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18918. $scope.condition.$agreedOpen = false;
  18919. };
  18920. $scope.changeDateZone = function (zone) {
  18921. $scope.condition.dateZone = zone;
  18922. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18923. $scope.condition.$dateZoneOpen = false;
  18924. getDateCondition(zone, $scope.condition);
  18925. $scope.tableParams.reload();
  18926. };
  18927. $scope.setActive = function (state) {
  18928. if ($scope.active != state) {
  18929. $scope.active = state;
  18930. if ($scope.tableParams.page() == 1)
  18931. $scope.tableParams.reload();
  18932. else
  18933. $scope.tableParams.page(1);
  18934. }
  18935. };
  18936. var getService = function () {
  18937. return getAccountUserSpace;
  18938. };
  18939. $scope.tableParams = new ngTableParams({
  18940. page: 1,
  18941. count: 20,
  18942. sorting: {}
  18943. }, {
  18944. total: 0,
  18945. counts: [],
  18946. getData: function ($defer, params) {
  18947. $scope.loading = true;
  18948. var pageParams = params.url();
  18949. pageParams.keyword = $scope.keyword;
  18950. $scope.tip = $scope.keyword;
  18951. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18952. $scope.loading = false;
  18953. if (page) {
  18954. params.total(page.totalElement);
  18955. $defer.resolve(page.content);
  18956. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18957. }
  18958. }, function (response) {
  18959. $scope.loading = false;
  18960. toaster.pop('error', '数据加载失败', response.data);
  18961. });
  18962. }
  18963. });
  18964. // 搜索框回车
  18965. $scope.onSearch = function (keyword) {
  18966. if (keyword === '') {
  18967. keyword = null;
  18968. $rootScope.searchKeyword = keyword;
  18969. $scope.keyword = keyword;
  18970. $scope.tableParams.page(1);
  18971. $scope.tableParams.reload();
  18972. } else {
  18973. $rootScope.searchKeyword = keyword;
  18974. $scope.keyword = keyword;
  18975. $scope.tableParams.page(1);
  18976. $scope.tableParams.reload();
  18977. }
  18978. };
  18979. // 添加合作关系
  18980. $scope.addPartner = function (name, businessCode) {
  18981. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  18982. if (data.success) {
  18983. toaster.pop("success", '添加成功', data.success);
  18984. $scope.tableParams.reload();
  18985. }
  18986. if (data.error) {
  18987. toaster.pop("error", '添加失败', data.error);
  18988. }
  18989. }, function (response) {
  18990. toaster.pop('error', '失败', response.data);
  18991. });
  18992. }
  18993. /**
  18994. * 邀请注册商务平台
  18995. */
  18996. $scope.invite = function (name) {
  18997. var modalInstance = $modal.open({
  18998. animation: true,
  18999. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  19000. controller: 'InviteCtrl',
  19001. resolve: {
  19002. enname: function () {
  19003. return name
  19004. }
  19005. }
  19006. });
  19007. modalInstance.result.then(function (data) {
  19008. InvitationRecord.invite({formStore: data}, {}, function (data) {
  19009. if (data.success) {
  19010. toaster.pop('success', '提示', data.success);
  19011. $scope.tableParams.reload();
  19012. }
  19013. if (data.error) {
  19014. toaster.pop('error', '提示', data.error);
  19015. }
  19016. }, function (response) {
  19017. toaster.pop('error', '提示', response.data);
  19018. });
  19019. });
  19020. }
  19021. /**
  19022. * 立即查看
  19023. */
  19024. $scope.view = function (name) {
  19025. $rootScope.vendName = name;
  19026. window.location.hash = "#/baseInfo/newPartner";
  19027. }
  19028. }]);
  19029. // 平台新增的询价单(指定一个供应商)
  19030. app.controller('PurcInquiryNewCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', '$http', 'ShipAddress', '$stateParams', 'Vendor', 'Product', 'Search', 'ComponentActiveAPI', 'VendorInfo', function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout, $http, ShipAddress, $stateParams, Vendor, Product, Search, ComponentActiveAPI, VendorInfo) {
  19031. $scope.active = 'all';
  19032. // 供应商信息
  19033. var loadData = function () {
  19034. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function (data) {
  19035. $scope.vendor = data;
  19036. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  19037. $scope.vendorContacts = data;
  19038. });
  19039. // 物料信息
  19040. $scope.tableParams = new ngTableParams({
  19041. page: 1,
  19042. count: 20
  19043. }, {
  19044. total: 0,
  19045. counts: [5, 10, 25, 50],
  19046. getData: function ($defer, params) {
  19047. $scope.loading = true;
  19048. var pageParams = params.url();
  19049. pageParams.keyword = $scope.keyword;
  19050. $scope.tip = $scope.keyword;
  19051. pageParams.custUU = $scope.vendor.uu;
  19052. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  19053. $scope.loading = false;
  19054. if (page) {
  19055. params.total(page.totalElement);
  19056. $scope.total = page.totalElement;
  19057. $defer.resolve(page.content);
  19058. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  19059. }
  19060. }, function (response) {
  19061. $scope.loading = false;
  19062. toaster.pop('error', '数据加载失败', response.data);
  19063. });
  19064. }
  19065. });
  19066. });
  19067. };
  19068. loadData();
  19069. $rootScope.tenderVendor = null;// 清除掉已选择的
  19070. var getService = function () {
  19071. return GetProductInfo;
  19072. };
  19073. $scope.inquiry = {
  19074. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  19075. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  19076. priceType: '采购',
  19077. isOpen: 0,
  19078. invoice: 0,
  19079. ifTax: 1,
  19080. currency: 'RMB'
  19081. };
  19082. $scope.changeCurrency = function (inquiry) {
  19083. if (inquiry.currency !== 'RMB') {
  19084. $scope.notRMB = true;
  19085. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  19086. inquiry.invoice = 0;
  19087. } else {
  19088. $scope.notRMB = false;
  19089. }
  19090. };
  19091. // 获取收货地址列表
  19092. var loadShipAddress = function () {
  19093. ShipAddress.shipAddList({}, function (data) {
  19094. $scope.ships = data;
  19095. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  19096. });
  19097. };
  19098. loadShipAddress();
  19099. // 获取地址信息
  19100. $http.get('resources/citydata/city.json', {
  19101. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  19102. }).then(function (response) {
  19103. $scope.provinces = response.data;
  19104. });
  19105. // 新增收货地址保存
  19106. $scope.saveShipAddress = function (ship) {
  19107. ship.address = ship.province + ship.city + ship.district;
  19108. ShipAddress.saveAddress({}, ship, function (data) {
  19109. if (data.success) {
  19110. // 获取收货地址列表
  19111. loadShipAddress();
  19112. toaster.pop('success', '提示', data.success);
  19113. }
  19114. if (data.error) {
  19115. toaster.pop('error', '提示', data.error);
  19116. }
  19117. });
  19118. };
  19119. $scope.currentDay = function () {
  19120. return $filter('date')(new Date(), 'yyyy-MM-dd');
  19121. };
  19122. // 搜索框回车
  19123. $scope.onSearch = function (keyword) {
  19124. $scope.tableParams.page(1);
  19125. $scope.tableParams.reload();
  19126. };
  19127. $scope.inquiry.inquiryItems = [];
  19128. var prod = {
  19129. prodCode: null,
  19130. prodTitle: null,
  19131. inbrand: null,
  19132. currency: 'RMB',
  19133. toDate: null,
  19134. unit: 'PCS'
  19135. };
  19136. $scope.inquiry.inquiryItems.push(prod);
  19137. // 联想词start
  19138. // 获取品牌联想词
  19139. $scope.getSimilarBrands = function (value) {
  19140. if (value) {
  19141. // 获取品牌联想词
  19142. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  19143. return data.map(function (item) {
  19144. return item;
  19145. });
  19146. });
  19147. }
  19148. };
  19149. // 获取产品型号联想词
  19150. $scope.getSimilarCodes = function (value) {
  19151. if (value) {
  19152. // 获取产品型号联想词
  19153. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  19154. return data.map(function (item) {
  19155. return item;
  19156. })
  19157. });
  19158. }
  19159. };
  19160. $scope.selectKind = function (prod) {
  19161. var submit = [];
  19162. $modal.open({
  19163. animation: true,
  19164. size: 'lg',
  19165. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  19166. controller: 'ProdKindChooseCtrl',
  19167. resolve: {
  19168. actives: function () {
  19169. return $scope.actives;
  19170. }
  19171. }
  19172. }).result.then(function (data) {
  19173. $scope.actives = data.actives;
  19174. var size = data.actives.length;
  19175. submit.gradeOneKiName = '';
  19176. submit.gradeTwoKiName = '';
  19177. submit.gradeThreeKiName = '';
  19178. if (size > 0) {
  19179. submit.gradeOneKiName = $scope.actives[0].nameCn;
  19180. prod.prodTitle = submit.gradeOneKiName;
  19181. if (size > 1) {
  19182. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  19183. prod.prodTitle = submit.gradeTwoKiName;
  19184. if (size > 2) {
  19185. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  19186. prod.prodTitle = submit.gradeThreeKiName;
  19187. }
  19188. }
  19189. }
  19190. }, function () {
  19191. });
  19192. };
  19193. // 点击联想词获取品牌信息
  19194. $scope.onAssociateBrandClick = function (brand, prod) {
  19195. if (brand instanceof String) {
  19196. prod.inbrand = brand;
  19197. } else if (brand instanceof Object) {
  19198. prod.inbrand = brand.brandCn;
  19199. }
  19200. };
  19201. // 打开品牌选择的模态框
  19202. $scope.selectBrand = function (prod) { //打开模态
  19203. var modalInstance = $modal.open({
  19204. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  19205. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  19206. });
  19207. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  19208. });
  19209. modalInstance.result.then(function (brand) {
  19210. prod.inbrand = brand.nameCn;
  19211. }, function (reason) {
  19212. });
  19213. };
  19214. // 点击联想词获取器件信息 带入产品分类和品牌
  19215. $scope.onAssociateCmpClick = function (cmp, prod) {
  19216. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  19217. $scope.component = data;
  19218. prod.prodCode = data.code;
  19219. prod.prodTitle = data.kind.nameCn;
  19220. prod.inbrand = data.brand.nameCn;
  19221. }, function (res) {
  19222. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  19223. })
  19224. };
  19225. //联想词end
  19226. // 导入商品信息
  19227. $scope.uplodaByBatch = function () {
  19228. var modalInstance = $modal.open({
  19229. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  19230. controller: 'PurcInquiryUploadCtrl',
  19231. size: 'lg',
  19232. resolve: {}
  19233. });
  19234. modalInstance.result.then(function (data) {
  19235. angular.forEach(data, function (prod) {
  19236. $scope.inquiry.inquiryItems.push(prod);
  19237. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19238. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19239. $scope.inquiry.inquiryItems.splice(i, 1);
  19240. }
  19241. }
  19242. })
  19243. }, function () {
  19244. });
  19245. }
  19246. //增加商品
  19247. $scope.add = function () {
  19248. $scope.inquiry.inquiryItems.push(
  19249. {
  19250. prodCode: null,
  19251. prodTitle: null,
  19252. unit: 'PCS',
  19253. ibrand: null,
  19254. currency: 'RMB',
  19255. toDate: null
  19256. });
  19257. };
  19258. //删除商品
  19259. $scope.del = function (index) {
  19260. $scope.inquiry.inquiryItems.splice(index, 1);
  19261. };
  19262. // 搜索结果询价
  19263. if ($rootScope.prodId) {
  19264. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  19265. prod.prodCode = data.code;
  19266. prod.prodTitle = data.title;
  19267. prod.spec = data.spec;
  19268. prod.unit = data.unit;
  19269. prod.productId = data.id;
  19270. prod.inbrand = data.brand;
  19271. $scope.inquiry.inquiryItems.push(prod);
  19272. $rootScope.prodId = null;// 清除掉prodId
  19273. }, function (response) {
  19274. });
  19275. }
  19276. $scope.check = function (product) {
  19277. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19278. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19279. $scope.inquiry.inquiryItems.splice(i, 1);
  19280. }
  19281. }
  19282. $scope.inquiry.inquiryItems.push({
  19283. prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  19284. currency: null, toDate: null, productId: product.id, inbrand: product.brand
  19285. });
  19286. }
  19287. $scope.getMinDate = function (item) {
  19288. return $filter('date')(new Date, 'yyyy-MM-dd');
  19289. };
  19290. $scope.openDatePicker = function ($event, openParam, index) {
  19291. $event.preventDefault();
  19292. $event.stopPropagation();
  19293. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  19294. };
  19295. $scope.openEndDatePicker = function ($event, item, openParam) {
  19296. $event.preventDefault();
  19297. $event.stopPropagation();
  19298. item[openParam] = !item[openParam];
  19299. };
  19300. $scope.ifrepeat = false;
  19301. // 保存并提交
  19302. $scope.submit = function () {
  19303. $scope.loading = true;
  19304. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19305. $scope.item = $scope.inquiry.inquiryItems[i];
  19306. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  19307. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  19308. if (i != j) {
  19309. if ($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  19310. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  19311. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  19312. $scope.ifrepeat = true;
  19313. }
  19314. }
  19315. }
  19316. }
  19317. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  19318. $scope.vendors = [];
  19319. $scope.vendors.push({
  19320. enName: $scope.vendor.enName,
  19321. enuu: $scope.vendor.uu,
  19322. currency: $scope.vendor.currency,
  19323. rate: $scope.vendor.rate
  19324. });
  19325. if (!$scope.ifrepeat) {
  19326. $upload.upload({
  19327. url: 'purc/inquiry/submit/withVendor',
  19328. file: file,
  19329. method: 'POST',
  19330. data: {
  19331. inquiry: $scope.inquiry,
  19332. contacts: $scope.vendors
  19333. },
  19334. }).success(function (data) {
  19335. if (data.success) {
  19336. $scope.loading = false;
  19337. toaster.pop('success', '提示', data.success);
  19338. $timeout(function () {
  19339. window.location.hash = "#/purc/purchaseinquiry";
  19340. }, 500);
  19341. }
  19342. if (data.error) {
  19343. $scope.loading = false;
  19344. toaster.pop('error', '提示', data.error);
  19345. }
  19346. }).error(function (data) {
  19347. $scope.loadingShow = false;
  19348. toaster.pop('error', '操作失败', data.error);
  19349. });
  19350. } else {
  19351. $scope.loading = false;
  19352. toaster.pop('error', '提示', '存在条件相同的物料');
  19353. }
  19354. }
  19355. }]);
  19356. // 企业圈查询收到待处理的数目
  19357. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', '$modal', 'InvitationRecord', 'toaster', function ($scope, AddPartnerMyRequest, $modal, InvitationRecord, toaster) {
  19358. AddPartnerMyRequest.requestAmount({}, function (data) {
  19359. $scope.requestTodo = data;
  19360. });
  19361. /**
  19362. * 邀请注册商务平台
  19363. */
  19364. $scope.invite = function () {
  19365. var modalInstance = $modal.open({
  19366. animation: true,
  19367. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  19368. controller: 'InviteCtrl',
  19369. resolve: {
  19370. enname: function () {
  19371. return null
  19372. }
  19373. }
  19374. });
  19375. modalInstance.result.then(function (data) {
  19376. InvitationRecord.invite({formStore: data}, {}, function (data) {
  19377. if (data.success) {
  19378. toaster.pop('success', '提示', data.success);
  19379. $scope.tableParams.reload();
  19380. }
  19381. if (data.error) {
  19382. toaster.pop('error', '提示', data.error);
  19383. }
  19384. }, function (response) {
  19385. toaster.pop('error', '提示', response.data);
  19386. });
  19387. });
  19388. }
  19389. }]);
  19390. // 当前企业所有的物料信息
  19391. app.controller('ProductAllCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', 'ProductAllNewest', '$rootScope', 'prodUser', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, ProductAllNewest, $rootScope, prodUser) {
  19392. BaseService.scrollBackToTop();
  19393. $rootScope.ids = [];// 用来记录已经选择的物料
  19394. $scope.active = 'all';
  19395. $scope.agreedText = '全部';
  19396. $scope.dateZoneText = '一个月内';
  19397. $scope.condition = {dateZone: 1};
  19398. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19399. $scope.changeAgreed = function (agreed) {
  19400. $scope.condition.agreed = agreed;
  19401. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19402. $scope.condition.$agreedOpen = false;
  19403. };
  19404. $scope.changeDateZone = function (zone) {
  19405. $scope.condition.dateZone = zone;
  19406. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19407. $scope.condition.$dateZoneOpen = false;
  19408. getDateCondition(zone, $scope.condition);
  19409. $scope.tableParams.reload();
  19410. };
  19411. $scope.setActive = function (state) {
  19412. if ($scope.active != state) {
  19413. $scope.active = state;
  19414. if ($scope.tableParams.page() == 1)
  19415. $scope.tableParams.reload();
  19416. else
  19417. $scope.tableParams.page(1);
  19418. }
  19419. };
  19420. $scope.searchMethod = false;
  19421. var getService = function () {
  19422. return $scope.searchMethod ? ProductAll : ProductAllNewest;
  19423. };
  19424. $scope.tableParams = new ngTableParams({
  19425. page: 1,
  19426. count: 20,
  19427. sorting: {
  19428. standard: 'desc',
  19429. id: 'desc',
  19430. }
  19431. }, {
  19432. total: 0,
  19433. counts: [5, 10, 25, 50],
  19434. getData: function ($defer, params) {
  19435. $scope.loading = true;
  19436. var pageParams = params.url();
  19437. pageParams.keyword = $scope.keyword;
  19438. pageParams.searchFilter = $scope.searchFilter;
  19439. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19440. $scope.loading = false;
  19441. if (page) {
  19442. params.total(page.totalElement);
  19443. $defer.resolve(page.content);
  19444. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19445. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19446. $scope.checkall = true;
  19447. if(page.content.length <= 2) {
  19448. $scope.checkall = false;
  19449. } else {
  19450. angular.forEach(page.content, function (prod) {
  19451. if ($rootScope.ids.indexOf(prod.id) > -1) {
  19452. prod.$selected = true;
  19453. } else {
  19454. $scope.checkall = false;
  19455. }
  19456. });
  19457. }
  19458. $scope.checkboxes = {
  19459. checked: $scope.checkall
  19460. };
  19461. }
  19462. }, function (response) {
  19463. $scope.loading = false;
  19464. toaster.pop('error', '数据加载失败', response.data);
  19465. });
  19466. }
  19467. });
  19468. // 搜索框回车
  19469. $scope.onSearch = function (keyword) {
  19470. // 每次搜索重置获取数据方法
  19471. $scope.searchMethod = false;
  19472. if(keyword != null && keyword != '') {
  19473. $scope.searchMethod = true;
  19474. }
  19475. $scope.tableParams.page(1);
  19476. $scope.tableParams.reload();
  19477. };
  19478. // 开启销售
  19479. $scope.unlock = function (id) {
  19480. $scope.loading = true;
  19481. Products.unlock({id: id}, {}, function (data) {
  19482. $scope.loading = false;
  19483. toaster.pop('success', '提示', '操作成功');
  19484. $scope.tableParams.reload();
  19485. }, function (response) {
  19486. toaster.pop('error', '提示', response.data);
  19487. })
  19488. }
  19489. // 关闭销售
  19490. $scope.lock = function (id) {
  19491. $scope.loading = true;
  19492. Products.lock({id: id}, {}, function (data) {
  19493. $scope.loading = false;
  19494. toaster.pop('success', '提示', '操作成功');
  19495. $scope.tableParams.reload();
  19496. }, function (response) {
  19497. toaster.pop('error', '提示', response.data);
  19498. })
  19499. }
  19500. // 开启购买
  19501. $scope.unlockPurc = function (id) {
  19502. $scope.loading = true;
  19503. Products.unlockPurc({id: id}, {}, function (data) {
  19504. $scope.loading = false;
  19505. toaster.pop('success', '提示', '操作成功');
  19506. $scope.tableParams.reload();
  19507. }, function (response) {
  19508. toaster.pop('error', '提示', response.data);
  19509. })
  19510. }
  19511. // 关闭购买
  19512. $scope.lockPurc = function (id) {
  19513. $scope.loading = true;
  19514. Products.lockPurc({id: id}, {}, function (data) {
  19515. $scope.loading = false;
  19516. toaster.pop('success', '提示', '操作成功');
  19517. $scope.tableParams.reload();
  19518. }, function (response) {
  19519. toaster.pop('error', '提示', response.data);
  19520. })
  19521. }
  19522. // 一键匹配
  19523. $scope.matchall = function () {
  19524. $scope.type = "all";
  19525. $scope.loading = true;
  19526. Products.matchbytype({type: $scope.type}, {}, function (data) {
  19527. if (data.error) {
  19528. $scope.loading = false;
  19529. toaster.pop('error', '提示', data.error);
  19530. } else {
  19531. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  19532. window.location.href = "#/approvalFlow/productmatches";
  19533. }
  19534. }, function (response) {
  19535. toaster.pop('error', '提示', response.data);
  19536. });
  19537. }
  19538. $scope.checkboxes = {
  19539. checked: false
  19540. };
  19541. angular.forEach($scope.tableParams.data, function (item) {
  19542. $scope.checkboxes.checked = false;
  19543. if($rootScope.ids.in_array(item.id)) {
  19544. $rootScope.ids.remove(item.id);
  19545. $scope.checkboxes.checked = true;
  19546. }
  19547. });
  19548. // 点击勾选全部的复选框
  19549. $scope.checkAll = function () {
  19550. angular.forEach($scope.tableParams.data, function (item) {
  19551. if (!item.waiting) {
  19552. item.$selected = $scope.checkboxes.checked;
  19553. if(item.$selected) {
  19554. if(!$rootScope.ids.in_array(item.id)) {
  19555. $rootScope.ids.push(item.id);
  19556. }
  19557. } else {
  19558. if($rootScope.ids.in_array(item.id)) {
  19559. $rootScope.ids.remove(item.id);
  19560. }
  19561. }
  19562. }
  19563. });
  19564. };
  19565. // 判断数组中是否存在某个对象
  19566. Array.prototype.S = String.fromCharCode(2);
  19567. Array.prototype.in_array = function(e) {
  19568. var r = new RegExp(this.S + e + this.S);
  19569. return (r.test(this.S + this.join(this.S) + this.S));
  19570. }
  19571. // 从数组中移除某个对象
  19572. Array.prototype.remove = function(val) {
  19573. var index = this.indexOf(val);
  19574. if (index > -1) {
  19575. this.splice(index, 1);
  19576. }
  19577. };
  19578. // 点击其中一个明细的复选框
  19579. $scope.checkOne = function (product) {
  19580. var result = true;
  19581. angular.forEach($scope.tableParams.data, function (item) {
  19582. if (item.$selected != true) {
  19583. result = false;
  19584. return;
  19585. }
  19586. });
  19587. if(product.$selected) {
  19588. if(!$rootScope.ids.in_array(product.id)) {
  19589. $rootScope.ids.push(product.id);
  19590. }
  19591. } else {
  19592. if($rootScope.ids.in_array(product.id)) {
  19593. $rootScope.ids.remove(product.id);
  19594. }
  19595. }
  19596. $scope.checkboxes = {
  19597. checked: result
  19598. };
  19599. };
  19600. // 批量转入我的产品库
  19601. $scope.addtoUserByCheck = function() {
  19602. var ids = angular.copy($rootScope.ids);
  19603. if($rootScope.ids.length == 0) {
  19604. toaster.pop('error', '提示', '请先选择产品');
  19605. } else {
  19606. prodUser.coverToUserByIds({}, ids, function(data) {
  19607. toaster.pop('success', '提示', '选择' + $rootScope.ids.length + '个产品,成功转入' + data.count + '个产品');
  19608. $rootScope.ids = [];
  19609. $scope.tableParams.page(1);
  19610. $scope.tableParams.reload();
  19611. }, function(res) {
  19612. toaster.pop('error', '提示', '转入失败');
  19613. });
  19614. }
  19615. }
  19616. // 转入我的产品库
  19617. $scope.addtoUser = function(id) {
  19618. $scope.loading = true;
  19619. prodUser.coverToUser({id: id}, {}, function(data) {
  19620. $scope.loading = false;
  19621. toaster.pop('success', '提示', '转入成功');
  19622. }, function(res) {
  19623. $scope.loading = false;
  19624. toaster.pop('error', '提示', '转入失败');
  19625. });
  19626. }
  19627. }]);
  19628. // 当前企业匹配的标准物料信息
  19629. app.controller('ProductmatchesCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  19630. BaseService.scrollBackToTop();
  19631. $scope.active = 'all';
  19632. $scope.agreedText = '全部';
  19633. $scope.dateZoneText = '一个月内';
  19634. $scope.condition = {dateZone: 1};
  19635. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19636. $scope.changeAgreed = function (agreed) {
  19637. $scope.condition.agreed = agreed;
  19638. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19639. $scope.condition.$agreedOpen = false;
  19640. };
  19641. $scope.changeDateZone = function (zone) {
  19642. $scope.condition.dateZone = zone;
  19643. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19644. $scope.condition.$dateZoneOpen = false;
  19645. getDateCondition(zone, $scope.condition);
  19646. $scope.tableParams.reload();
  19647. };
  19648. $scope.setActive = function (state) {
  19649. if ($scope.active != state) {
  19650. $scope.active = state;
  19651. if ($scope.tableParams.page() == 1)
  19652. $scope.tableParams.reload();
  19653. else
  19654. $scope.tableParams.page(1);
  19655. }
  19656. };
  19657. $scope.searchMethod = false;
  19658. var getService = function () {
  19659. if ($rootScope.productMatchStatus === 'sale') {
  19660. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19661. } else if ($rootScope.productMatchStatus === 'purc') {
  19662. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19663. } else {
  19664. return $scope.searchMethod ? Products.matchResult : Products.newestMatchResult;
  19665. }
  19666. };
  19667. $scope.tableParams = new ngTableParams({
  19668. page: 1,
  19669. count: 20,
  19670. sorting: {
  19671. matchsize: 'asc',
  19672. id: 'desc'
  19673. }
  19674. }, {
  19675. total: 0,
  19676. counts: [5, 10, 25, 50],
  19677. getData: function ($defer, params) {
  19678. $scope.loading = true;
  19679. var pageParams = params.url();
  19680. pageParams.keyword = $scope.keyword;
  19681. pageParams.searchFilter = $scope.searchFilter;
  19682. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19683. if (page) {
  19684. $scope.loading = false;
  19685. params.total(page.totalElement);
  19686. $defer.resolve(page.content);
  19687. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19688. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19689. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19690. ids = [];
  19691. if (product.matchresults.length == 1) {
  19692. product.checked = $scope.checks.checked;
  19693. }
  19694. });
  19695. }
  19696. }, function (response) {
  19697. $scope.loading = false;
  19698. toaster.pop('error', '数据加载失败', response.data);
  19699. });
  19700. }
  19701. });
  19702. // 搜索框回车
  19703. $scope.onSearch = function (keyword) {
  19704. $scope.searchMethod = false;
  19705. if(keyword != null && keyword != '') {
  19706. $scope.searchMethod = true;
  19707. }
  19708. $scope.tableParams.page(1);
  19709. $scope.tableParams.reload();
  19710. };
  19711. var ids = [];
  19712. $scope.checks = {
  19713. checked: false
  19714. };
  19715. // 全选框
  19716. $scope.checkAll = function () {
  19717. ids = [];// 每次选择时先清空,防止重复
  19718. angular.forEach($scope.tableParams.data, function (product) {
  19719. if (product.matchresults.length == 1) {
  19720. product.checked = $scope.checks.checked;
  19721. }
  19722. });
  19723. };
  19724. // 单选
  19725. $scope.checkOne = function (product) {
  19726. ids = [];// 每次选择时先清空,防止重复
  19727. product.checked = !product.checked;
  19728. var result = true;
  19729. angular.forEach($scope.tableParams.data, function (item) {
  19730. if (item.$selected != true) {
  19731. result = false;
  19732. return;
  19733. }
  19734. });
  19735. $scope.checks.checked = result;
  19736. var checked = true;
  19737. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19738. if (!message.checked) {
  19739. checked = false;
  19740. }
  19741. });
  19742. $scope.checks.checked = checked;
  19743. };
  19744. $scope.product = {
  19745. checked: false
  19746. };
  19747. var checkResults = function (result) {
  19748. angular.forEach($scope.tableParams.data, function (product) {
  19749. if (product.id == result.prid) {
  19750. product.checked = false;
  19751. angular.forEach(product.matchresults, function (item) {
  19752. if (result.id == item.id) {
  19753. if (item.checked) {
  19754. product.checked = true;
  19755. return;
  19756. }
  19757. } else {
  19758. item.checked = false;
  19759. }
  19760. });
  19761. }
  19762. });
  19763. // checkProductCheck();
  19764. };
  19765. var checkProductCheck = function () {
  19766. var checked = true;
  19767. angular.forEach($scope.tableParams.data, function (product) {
  19768. if (!product.checked) {
  19769. checked = false;
  19770. }
  19771. });
  19772. $scope.product.checked = checked;
  19773. }
  19774. // 单选明细
  19775. $scope.checkItem = function (result) {
  19776. ids = [];
  19777. result.checked = !result.checked;
  19778. checkResults(result);
  19779. }
  19780. // 一键更新
  19781. $scope.updateAll = function () {
  19782. $scope.loading = true;
  19783. angular.forEach($scope.tableParams.data, function (product) {
  19784. if (product.checked) {
  19785. if (product.matchresults.length == 1) {
  19786. ids.push(product.matchresults[0].id);
  19787. }
  19788. if (product.matchresults.length > 1) {
  19789. angular.forEach(product.matchresults, function (item) {
  19790. if (item.checked) {
  19791. ids.push(item.id);
  19792. }
  19793. });
  19794. }
  19795. }
  19796. });
  19797. Products.updateall({status: $scope.checks.checked, type: 'all'}, ids, function (data) {
  19798. if (data.success) {
  19799. toaster.pop('success', '提示', data.success);
  19800. $timeout(function () {
  19801. $scope.tableParams.page(1);
  19802. $scope.tableParams.reload();
  19803. $scope.loading = false;
  19804. }, 500);
  19805. }
  19806. ids = []; // 清空ids,防止重复点击出现多余的数据
  19807. }, function (response) {
  19808. $scope.loading = false;
  19809. toaster.pop('error', '提示', response.data);
  19810. });
  19811. }
  19812. }]);
  19813. // 当前企业匹配的标准物料信息(销售)
  19814. app.controller('ProductmatchesForSaleCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  19815. BaseService.scrollBackToTop();
  19816. $scope.active = 'all';
  19817. $scope.agreedText = '全部';
  19818. $scope.dateZoneText = '一个月内';
  19819. $scope.condition = {dateZone: 1};
  19820. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19821. $scope.changeAgreed = function (agreed) {
  19822. $scope.condition.agreed = agreed;
  19823. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19824. $scope.condition.$agreedOpen = false;
  19825. };
  19826. $scope.changeDateZone = function (zone) {
  19827. $scope.condition.dateZone = zone;
  19828. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19829. $scope.condition.$dateZoneOpen = false;
  19830. getDateCondition(zone, $scope.condition);
  19831. $scope.tableParams.reload();
  19832. };
  19833. $scope.setActive = function (state) {
  19834. if ($scope.active != state) {
  19835. $scope.active = state;
  19836. if ($scope.tableParams.page() == 1)
  19837. $scope.tableParams.reload();
  19838. else
  19839. $scope.tableParams.page(1);
  19840. }
  19841. };
  19842. $scope.searchMethod = false;
  19843. var getService = function () {
  19844. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19845. };
  19846. $scope.tableParams = new ngTableParams({
  19847. page: 1,
  19848. count: 20,
  19849. sorting: {
  19850. matchsize: 'asc',
  19851. id: 'desc'
  19852. }
  19853. }, {
  19854. total: 0,
  19855. counts: [5, 10, 25, 50],
  19856. getData: function ($defer, params) {
  19857. $scope.loading = true;
  19858. var pageParams = params.url();
  19859. pageParams.keyword = $scope.keyword;
  19860. pageParams.searchFilter = $scope.searchFilter;
  19861. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19862. if (page) {
  19863. $scope.loading = false;
  19864. params.total(page.totalElement);
  19865. $defer.resolve(page.content);
  19866. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19867. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19868. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19869. ids = [];
  19870. if (product.matchresults.length == 1) {
  19871. product.checked = $scope.checks.checked;
  19872. }
  19873. });
  19874. }
  19875. }, function (response) {
  19876. $scope.loading = false;
  19877. toaster.pop('error', '数据加载失败', response.data);
  19878. });
  19879. }
  19880. });
  19881. // 搜索框回车
  19882. $scope.onSearch = function (keyword) {
  19883. $scope.searchMethod = false;
  19884. if(keyword != null && keyword != '') {
  19885. $scope.searchMethod = true;
  19886. }
  19887. $scope.tableParams.page(1);
  19888. $scope.tableParams.reload();
  19889. };
  19890. var ids = [];
  19891. $scope.checks = {
  19892. checked: false
  19893. };
  19894. // 全选框
  19895. $scope.checkAll = function () {
  19896. ids = [];// 每次选择时先清空,防止重复
  19897. angular.forEach($scope.tableParams.data, function (product) {
  19898. if (product.matchresults.length == 1) {
  19899. product.checked = $scope.checks.checked;
  19900. }
  19901. });
  19902. };
  19903. // 单选
  19904. $scope.checkOne = function (product) {
  19905. ids = [];// 每次选择时先清空,防止重复
  19906. product.checked = !product.checked;
  19907. var result = true;
  19908. angular.forEach($scope.tableParams.data, function (item) {
  19909. if (item.$selected != true) {
  19910. result = false;
  19911. return;
  19912. }
  19913. });
  19914. $scope.checks.checked = result;
  19915. var checked = true;
  19916. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19917. if (!message.checked) {
  19918. checked = false;
  19919. }
  19920. });
  19921. $scope.checks.checked = checked;
  19922. };
  19923. $scope.product = {
  19924. checked: false
  19925. };
  19926. var checkResults = function (result) {
  19927. angular.forEach($scope.tableParams.data, function (product) {
  19928. if (product.id == result.prid) {
  19929. product.checked = false;
  19930. angular.forEach(product.matchresults, function (item) {
  19931. if (result.id == item.id) {
  19932. if (item.checked) {
  19933. product.checked = true;
  19934. return;
  19935. }
  19936. } else {
  19937. item.checked = false;
  19938. }
  19939. });
  19940. }
  19941. });
  19942. // checkProductCheck();
  19943. };
  19944. var checkProductCheck = function () {
  19945. var checked = true;
  19946. angular.forEach($scope.tableParams.data, function (product) {
  19947. if (!product.checked) {
  19948. checked = false;
  19949. }
  19950. });
  19951. $scope.product.checked = checked;
  19952. }
  19953. // 单选明细
  19954. $scope.checkItem = function (result) {
  19955. ids = [];
  19956. result.checked = !result.checked;
  19957. checkResults(result);
  19958. }
  19959. // 一键更新
  19960. $scope.updateAll = function () {
  19961. $scope.loading = true;
  19962. angular.forEach($scope.tableParams.data, function (product) {
  19963. if (product.checked) {
  19964. if (product.matchresults.length == 1) {
  19965. ids.push(product.matchresults[0].id);
  19966. }
  19967. if (product.matchresults.length > 1) {
  19968. angular.forEach(product.matchresults, function (item) {
  19969. if (item.checked) {
  19970. ids.push(item.id);
  19971. }
  19972. });
  19973. }
  19974. }
  19975. });
  19976. Products.updateall({status: $scope.checks.checked, type: 'sale'}, ids, function (data) {
  19977. if (data.success) {
  19978. toaster.pop('success', '提示', data.success);
  19979. $timeout(function () {
  19980. $scope.tableParams.page(1);
  19981. $scope.tableParams.reload();
  19982. $scope.loading = false;
  19983. }, 500);
  19984. }
  19985. ids = []; // 清空ids,防止重复点击出现多余的数据
  19986. }, function (response) {
  19987. $scope.loading = true;
  19988. toaster.pop('error', '提示', response.data);
  19989. });
  19990. }
  19991. }]);
  19992. // 当前企业匹配的标准物料信息(采购)
  19993. app.controller('ProductmatchesForPurcCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  19994. BaseService.scrollBackToTop();
  19995. $scope.active = 'all';
  19996. $scope.agreedText = '全部';
  19997. $scope.dateZoneText = '一个月内';
  19998. $scope.condition = {dateZone: 1};
  19999. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  20000. $scope.changeAgreed = function (agreed) {
  20001. $scope.condition.agreed = agreed;
  20002. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  20003. $scope.condition.$agreedOpen = false;
  20004. };
  20005. $scope.changeDateZone = function (zone) {
  20006. $scope.condition.dateZone = zone;
  20007. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  20008. $scope.condition.$dateZoneOpen = false;
  20009. getDateCondition(zone, $scope.condition);
  20010. $scope.tableParams.reload();
  20011. };
  20012. $scope.setActive = function (state) {
  20013. if ($scope.active != state) {
  20014. $scope.active = state;
  20015. if ($scope.tableParams.page() == 1)
  20016. $scope.tableParams.reload();
  20017. else
  20018. $scope.tableParams.page(1);
  20019. }
  20020. };
  20021. $scope.searchMethod = false;
  20022. var getService = function () {
  20023. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  20024. };
  20025. $scope.tableParams = new ngTableParams({
  20026. page: 1,
  20027. count: 20,
  20028. sorting: {
  20029. matchsize: 'asc',
  20030. id: 'desc'
  20031. }
  20032. }, {
  20033. total: 0,
  20034. counts: [5, 10, 25, 50],
  20035. getData: function ($defer, params) {
  20036. $scope.loading = true;
  20037. var pageParams = params.url();
  20038. pageParams.keyword = $scope.keyword;
  20039. pageParams.searchFilter = $scope.searchFilter;
  20040. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  20041. if (page) {
  20042. $scope.loading = false;
  20043. params.total(page.totalElement);
  20044. $defer.resolve(page.content);
  20045. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  20046. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  20047. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  20048. ids = [];
  20049. if (product.matchresults.length == 1) {
  20050. product.checked = $scope.checks.checked;
  20051. }
  20052. });
  20053. $scope.total = page.totalElement;
  20054. }
  20055. }, function (response) {
  20056. $scope.loading = false;
  20057. toaster.pop('error', '数据加载失败', response.data);
  20058. });
  20059. }
  20060. });
  20061. // 搜索框回车
  20062. $scope.onSearch = function (keyword) {
  20063. $scope.searchMethod = false;
  20064. if(keyword != null && keyword != '') {
  20065. $scope.searchMethod = true;
  20066. }
  20067. $scope.tableParams.page(1);
  20068. $scope.tableParams.reload();
  20069. };
  20070. var ids = [];
  20071. $scope.checks = {
  20072. checked: false
  20073. };
  20074. // 全选框
  20075. $scope.checkAll = function () {
  20076. ids = [];// 每次选择时先清空,防止重复
  20077. angular.forEach($scope.tableParams.data, function (product) {
  20078. if (product.matchresults.length == 1) {
  20079. product.checked = $scope.checks.checked;
  20080. }
  20081. });
  20082. };
  20083. // 单选
  20084. $scope.checkOne = function (product) {
  20085. ids = [];// 每次选择时先清空,防止重复
  20086. product.checked = !product.checked;
  20087. var result = true;
  20088. angular.forEach($scope.tableParams.data, function (item) {
  20089. if (item.$selected != true) {
  20090. result = false;
  20091. return;
  20092. }
  20093. });
  20094. $scope.checks.checked = result;
  20095. var checked = true;
  20096. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  20097. if (!message.checked) {
  20098. checked = false;
  20099. }
  20100. });
  20101. $scope.checks.checked = checked;
  20102. };
  20103. $scope.product = {
  20104. checked: false
  20105. };
  20106. var checkResults = function (result) {
  20107. angular.forEach($scope.tableParams.data, function (product) {
  20108. if (product.id == result.prid) {
  20109. product.checked = false;
  20110. angular.forEach(product.matchresults, function (item) {
  20111. if (result.id == item.id) {
  20112. if (item.checked) {
  20113. product.checked = true;
  20114. return;
  20115. }
  20116. } else {
  20117. item.checked = false;
  20118. }
  20119. });
  20120. }
  20121. });
  20122. // checkProductCheck();
  20123. };
  20124. var checkProductCheck = function () {
  20125. var checked = true;
  20126. angular.forEach($scope.tableParams.data, function (product) {
  20127. if (!product.checked) {
  20128. checked = false;
  20129. }
  20130. });
  20131. $scope.product.checked = checked;
  20132. }
  20133. // 单选明细
  20134. $scope.checkItem = function (result) {
  20135. ids = [];
  20136. result.checked = !result.checked;
  20137. checkResults(result);
  20138. }
  20139. // 一键更新
  20140. $scope.updateAll = function () {
  20141. $scope.loading = true;
  20142. angular.forEach($scope.tableParams.data, function (product) {
  20143. if (product.checked) {
  20144. if (product.matchresults.length == 1) {
  20145. ids.push(product.matchresults[0].id);
  20146. }
  20147. if (product.matchresults.length > 1) {
  20148. angular.forEach(product.matchresults, function (item) {
  20149. if (item.checked) {
  20150. ids.push(item.id);
  20151. }
  20152. });
  20153. }
  20154. }
  20155. });
  20156. Products.updateall({status: $scope.checks.checked, type: 'purc'}, ids, function (data) {
  20157. if (data.success) {
  20158. toaster.pop('success', '提示', data.success);
  20159. $timeout(function () {
  20160. $scope.tableParams.page(1);
  20161. $scope.tableParams.reload();
  20162. $scope.loading = false;
  20163. }, 500);
  20164. }
  20165. ids = []; // 清空ids,防止重复点击出现多余的数据
  20166. }, function (response) {
  20167. $scope.loading = false;
  20168. toaster.pop('error', '提示', response.data);
  20169. });
  20170. }
  20171. }]);
  20172. /**
  20173. * 采购物料资料
  20174. */
  20175. app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$modal', 'GetProductInfo', '$rootScope', 'PurcProductNewest', 'AccountEnterprise', function ($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $modal, GetProductInfo, $rootScope, PurcProductNewest, AccountEnterprise) {
  20176. BaseService.scrollBackToTop();
  20177. // 用来记录已经选择的id
  20178. $rootScope.ids = [];
  20179. var loadAccount = function () {
  20180. AccountEnterprise.get({}, function (data) {
  20181. $scope.enterprise = data;
  20182. $scope.purcStatus = $scope.enterprise.prodpurc;
  20183. });
  20184. }
  20185. loadAccount();
  20186. $scope.active = 'all';
  20187. $scope.agreedText = '全部';
  20188. $scope.dateZoneText = '一个月内';
  20189. $scope.condition = {dateZone: 1};
  20190. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  20191. $scope.changeAgreed = function (agreed) {
  20192. $scope.condition.agreed = agreed;
  20193. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  20194. $scope.condition.$agreedOpen = false;
  20195. };
  20196. $scope.changeDateZone = function (zone) {
  20197. $scope.condition.dateZone = zone;
  20198. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  20199. $scope.condition.$dateZoneOpen = false;
  20200. getDateCondition(zone, $scope.condition);
  20201. $scope.tableParams.reload();
  20202. };
  20203. $scope.setActive = function (state) {
  20204. if ($scope.active != state) {
  20205. $scope.active = state;
  20206. if ($scope.tableParams.page() == 1)
  20207. $scope.tableParams.reload();
  20208. else
  20209. $scope.tableParams.page(1);
  20210. }
  20211. };
  20212. $scope.searchMethod = false;
  20213. var getService = function () {
  20214. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  20215. };
  20216. $scope.tableParams = new ngTableParams({
  20217. page: 1,
  20218. count: 20,
  20219. sorting: {
  20220. id: 'desc'
  20221. }
  20222. }, {
  20223. total: 0,
  20224. counts: [5, 10, 25, 50],
  20225. getData: function ($defer, params) {
  20226. $scope.loading = true;
  20227. var pageParams = params.url();
  20228. pageParams.keyword = $scope.keyword;
  20229. pageParams.searchFilter = $scope.searchFilter;
  20230. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  20231. $scope.loading = false;
  20232. if (page) {
  20233. params.total(page.totalElement);
  20234. $defer.resolve(page.content);
  20235. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  20236. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  20237. }
  20238. }, function (response) {
  20239. $scope.loading = false;
  20240. toaster.pop('error', '数据加载失败', response.data);
  20241. });
  20242. }
  20243. });
  20244. // //设置单据已读
  20245. // var setOrdersRead = function () {
  20246. // var ids = [];
  20247. // PurcProduct.setRead({}, ids, function (message) {
  20248. // // $scope.getUnreadIds();
  20249. // });
  20250. // };
  20251. // setOrdersRead();
  20252. // 搜索框回车
  20253. $scope.onSearch = function (keyword) {
  20254. $scope.searchMethod = false;
  20255. if(keyword != null && keyword != '') {
  20256. $scope.searchMethod = true;
  20257. }
  20258. $scope.tableParams.page(1);
  20259. $scope.tableParams.reload();
  20260. };
  20261. //删除
  20262. $scope.deleteById = function (id) {
  20263. GetProductInfo.deletePurcById({}, id, function (data) {
  20264. if (data.error) {
  20265. toaster.pop("error", "提示", data.error);
  20266. } else {
  20267. toaster.pop("success", "提示", "删除成功");
  20268. $timeout(function () {
  20269. $scope.tableParams.reload();
  20270. }, 500);
  20271. }
  20272. }), function (response) {
  20273. toaster.pop("error", "删除失败", response.data);
  20274. };
  20275. }
  20276. // 一键开启关闭
  20277. $scope.toggle = function (status) {
  20278. $scope.loading = true;
  20279. Products.toggle({status: status}, {}, function (data) {
  20280. $scope.loading = false;
  20281. toaster.pop('success', '提示', '操作成功');
  20282. loadAccount();
  20283. $scope.tableParams.reload();
  20284. if ($scope.purcStatus == 0) {
  20285. $scope.purcStatus = 1;
  20286. } else {
  20287. $scope.purcStatus = 0;
  20288. }
  20289. }, function (response) {
  20290. $scope.loading = false;
  20291. toaster.pop('error', '提示', response.data);
  20292. })
  20293. }
  20294. var products = [];
  20295. $scope.checks = {
  20296. checked: false
  20297. };
  20298. // 全选框
  20299. $scope.checkAll = function () {
  20300. products = [];// 每次选择时先清空,防止重复
  20301. angular.forEach($scope.tableParams.data, function (product) {
  20302. if (product.cmpUuId == null) {
  20303. product.checked = $scope.checks.checked;
  20304. }
  20305. });
  20306. };
  20307. // 单选
  20308. $scope.checkOne = function (product) {
  20309. products = [];// 每次选择时先清空,防止重复
  20310. var result = true;
  20311. angular.forEach($scope.tableParams.data, function (item) {
  20312. if (item.$selected != true) {
  20313. result = false;
  20314. return;
  20315. }
  20316. });
  20317. $scope.checks.checked = result;
  20318. var checked = true;
  20319. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  20320. if (!message.checked) {
  20321. checked = false;
  20322. }
  20323. });
  20324. $scope.checks.checked = checked;
  20325. };
  20326. $scope.updateByBatch = function (updatetype) {
  20327. var modalInstance = $modal.open({
  20328. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  20329. controller: 'UpdateByBatchCtrl',
  20330. size: 'md',
  20331. resolve: {
  20332. updatetype: function () {
  20333. return updatetype;
  20334. },
  20335. active: function () {
  20336. return $scope.active;
  20337. },
  20338. type: function () {
  20339. return 'purchase';
  20340. }
  20341. }
  20342. });
  20343. modalInstance.result.then(function (data) {
  20344. toaster.pop('success', '提示', data.success);
  20345. $scope.tableParams.reload();
  20346. }, function () {
  20347. });
  20348. }
  20349. // 一键匹配
  20350. $scope.matchall = function () {
  20351. $scope.type = "purc";
  20352. $scope.loading = true;
  20353. PurcProduct.matchbytype({type: $scope.type}, {}, function (data) {
  20354. if (data.error) {
  20355. $scope.loading = false;
  20356. toaster.pop('error', '提示', data.error);
  20357. } else {
  20358. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  20359. window.location.href = "#/purc/productmatches";
  20360. }
  20361. }, function (response) {
  20362. $scope.loading = false;
  20363. toaster.pop('error', '提示', response.data);
  20364. });
  20365. }
  20366. // 导出
  20367. $scope.exportXls = function () {
  20368. PurcProduct.exportXls({}, {}, function (data) {
  20369. if (data.success){
  20370. window.location.href = 'purcProduct/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  20371. }
  20372. }, function (response) {
  20373. toaster.pop('error', '数据加载失败', response.data);
  20374. });
  20375. }
  20376. }]);
  20377. /**
  20378. * 采购物料批量上传
  20379. */
  20380. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  20381. BaseService.scrollBackToTop();
  20382. $scope.$watch('myFiles', function () {
  20383. if ($scope.myFiles) {
  20384. var file = $scope.myFiles[0];
  20385. $scope.fileName = file.name;
  20386. }
  20387. })
  20388. // 通过excel批量上传物料
  20389. $scope.upload = function () {
  20390. $scope.loading = true;
  20391. if ($scope.myFiles) {
  20392. var file = $scope.myFiles[0];
  20393. if (file.name) {
  20394. $scope.loading = true;
  20395. $upload.upload({
  20396. url: 'purcProduct/edit/release/excel',
  20397. file: file,
  20398. method: 'POST'
  20399. }).success(function (data) {
  20400. $scope.loading = false;
  20401. if (data.error) {
  20402. toaster.pop('error', '提示', data.error);
  20403. }
  20404. $scope.result = data;
  20405. // $scope.products = $scope.result.products;
  20406. $scope.success = $scope.result.success;
  20407. $scope.total = $scope.result.total;
  20408. $scope.alters = $scope.result.alters;
  20409. $scope.infos = $scope.result.infos;
  20410. $scope.myFiles[0] = "";
  20411. $scope.fileName = "";
  20412. }).error(function (response) {
  20413. $scope.loading = false;
  20414. toaster.pop('error', response.data || response);
  20415. });
  20416. } else {
  20417. $scope.loading = false;
  20418. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20419. }
  20420. } else {
  20421. $scope.loading = false;
  20422. }
  20423. };
  20424. // 查看范例
  20425. $scope.showImg = function () {
  20426. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  20427. box.show();
  20428. box.find('img').attr('src', src);
  20429. box.find('a').click(function () {
  20430. box.hide();
  20431. });
  20432. box.dblclick(function () {
  20433. box.hide();
  20434. });
  20435. };
  20436. // 下载模板
  20437. $scope.download = function () {
  20438. window.location.href = 'product/baseInfo/upload/template';
  20439. };
  20440. }]);
  20441. /**
  20442. * 新增物料(采购)
  20443. */
  20444. app.controller('PurcNewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService, Products) {
  20445. BaseService.scrollBackToTop();
  20446. // 录入人
  20447. AuthenticationService.getAuthentication().success(function (data) {
  20448. $scope.loading = false;
  20449. $scope.user = data;
  20450. });
  20451. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20452. $scope.prodInfo = {};
  20453. // 选择类目
  20454. $scope.selectKind = function () {
  20455. $modal.open({
  20456. animation: true,
  20457. size: 'lg',
  20458. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20459. controller: 'KindChooseCtrl',
  20460. }).result.then(function (data) {
  20461. $scope.kindId = data;
  20462. var modalInstance = $modal.open({
  20463. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20464. controller: 'FindComponentCtrl',
  20465. size: 'lg',
  20466. resolve: {
  20467. KindId: function () {
  20468. return $scope.kindId;
  20469. }
  20470. }
  20471. });
  20472. modalInstance.result.then(function (data) {
  20473. $scope.prodInfo.cmpUuId = data.uuid;
  20474. $scope.prodInfo.pcmpcode = data.code;
  20475. $scope.prodInfo.pbranden = data.brand.nameEn;
  20476. $scope.prodInfo.pbrand = data.brand.nameCn;
  20477. }, function () {
  20478. });
  20479. }, function () {
  20480. });
  20481. };
  20482. // 联想词 start
  20483. // 获取类目
  20484. $scope.getSimilarKinds = function (value) {
  20485. if (value) {
  20486. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20487. return data.map(function (item) {
  20488. return item;
  20489. });
  20490. });
  20491. }
  20492. };
  20493. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20494. $scope.prodInfo.title = kind.kindName;
  20495. }
  20496. $scope.getSimilarBrands = function (value) {
  20497. if (value) {
  20498. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20499. return data.map(function (item) {
  20500. return item;
  20501. });
  20502. });
  20503. }
  20504. }
  20505. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20506. $scope.prodInfo.brand = brand.brandName;
  20507. }
  20508. $scope.getSimilarComponents = function (value) {
  20509. if (value) {
  20510. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20511. return data.map(function (item) {
  20512. return item;
  20513. });
  20514. });
  20515. }
  20516. }
  20517. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20518. $scope.prodInfo.cmpCode = cmp.code;
  20519. }
  20520. // 联想词 end
  20521. // 删除
  20522. $scope.clearfile = function () {
  20523. $scope.myFiles = null;
  20524. $scope.previewShow = false;
  20525. }
  20526. //提交
  20527. $scope.submit = function (prodInfo) {
  20528. $scope.loading = true;
  20529. $scope.prodInfo.isPurchase = 1;
  20530. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20531. $upload.upload({
  20532. url: 'purcProduct/edit/addNewProduct',
  20533. file: file,
  20534. method: 'POST',
  20535. data: {
  20536. prodInfo: prodInfo
  20537. },
  20538. }).success(function (data) {
  20539. $scope.loading = false;
  20540. if (data.success) {
  20541. toaster.pop('success', '提示', data.success);
  20542. $timeout(function () {
  20543. //提交后跳转到详情页面,防止重复提交
  20544. window.location.href = "#/purc/prodList/" + data.id;
  20545. // window.location.href="#/purc/product";
  20546. }, 500);
  20547. }
  20548. if (data.error) {
  20549. toaster.pop('error', '提示', data.error);
  20550. $timeout(function () {
  20551. //提交后跳转到详情页面,防止重复提交
  20552. window.location.href = "#/purc/prodList/" + data.id;
  20553. // window.location.href="#/purc/product";
  20554. }, 500);
  20555. }
  20556. }).error(function (data, status, headers, config) {
  20557. $scope.loading = false;
  20558. $scope.loadingShow = false;
  20559. if (status == 403) {
  20560. toaster.pop('error', '操作失败', data);
  20561. } else {
  20562. toaster.pop('error', '操作失败', data.error);
  20563. }
  20564. });
  20565. };
  20566. $scope.previewShow = false;
  20567. $scope.pdfShow = false;
  20568. $scope.noneFileShow = true;
  20569. $scope.$watch('myFiles', function () {
  20570. if ($scope.myFiles) {
  20571. $scope.noneFileShow = false;
  20572. var file = $scope.myFiles[0];
  20573. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20574. $scope.pdfShow = true;
  20575. $scope.previewShow = false;
  20576. $scope.imgPreviewName = file.name;
  20577. } else {
  20578. if (typeof(Worker) !== "undefined") {//支持HTML5
  20579. $scope.imgPreview = getObjectURL(file);
  20580. $scope.imgPreviewName = file.name;
  20581. } else {//不支持HTML5
  20582. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20583. $scope.imgPreviewName = file.name;
  20584. }
  20585. $scope.previewShow = true;
  20586. $scope.pdfShow = false;
  20587. }
  20588. } else {
  20589. $scope.noneFileShow = true;
  20590. $scope.previewShow = false;
  20591. $scope.pdfShow = false;
  20592. }
  20593. });
  20594. //建立一个可存取到该file的url
  20595. var imgurl = null;
  20596. var getObjectURL = function (file) {
  20597. var url = null;
  20598. if (window.createObjectURL != undefined) { // basic
  20599. url = window.createObjectURL(file);
  20600. } else if (window.URL != undefined) { // mozilla(firefox)
  20601. url = window.URL.createObjectURL(file);
  20602. } else if (window.webkitURL != undefined) { // webkit or chrome
  20603. url = window.webkitURL.createObjectURL(file);
  20604. }
  20605. imgurl = url;
  20606. return url;
  20607. };
  20608. // 取消
  20609. $scope.cancel = function () {
  20610. $scope.prodInfo = angular.copy($scope.prodInfo);
  20611. };
  20612. // 查看大图
  20613. $scope.showImg = function () {
  20614. var src = imgurl, box = $('#image-box');
  20615. box.show();
  20616. box.find('img').attr('src', src);
  20617. box.find('a').click(function () {
  20618. box.hide();
  20619. });
  20620. box.dblclick(function () {
  20621. box.hide();
  20622. });
  20623. };
  20624. }]);
  20625. /**
  20626. * 物料详情(采购)
  20627. */
  20628. app.controller('PurcProdDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$modal', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $modal, Products) {
  20629. BaseService.scrollBackToTop();
  20630. // 录入人
  20631. AuthenticationService.getAuthentication().success(function (data) {
  20632. $scope.loading = false;
  20633. $scope.user = data;
  20634. });
  20635. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20636. $scope.editstatus = false;
  20637. var loadData = function () {
  20638. GetProductInfo.getPurcProduct({id: $stateParams.id}, function (data) {
  20639. if (data.attach) {
  20640. GetProductInfo.getAttach({id: data.attach.id}, function (data) {
  20641. $scope.imgPreview = data.url;
  20642. $scope.previewShow = true;
  20643. })
  20644. }
  20645. $scope.prodInfo = data;
  20646. if ($scope.prodInfo.isbusiness == 0) {
  20647. $scope.editstatus = true;
  20648. }
  20649. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  20650. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  20651. $scope.matchresults = data;
  20652. }, function (response) {
  20653. toaster.pop('error', '提示', response.data);
  20654. });
  20655. }
  20656. $scope.loading = false;
  20657. }, function (response) {
  20658. toaster.pop('error', '数据加载失败', response.data);
  20659. });
  20660. };
  20661. loadData();
  20662. // 联想词 start
  20663. // 获取类目
  20664. $scope.getSimilarKinds = function (value) {
  20665. if (value) {
  20666. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20667. return data.map(function (item) {
  20668. return item;
  20669. });
  20670. });
  20671. }
  20672. };
  20673. // 设置类目
  20674. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20675. $scope.prodInfo.kind = kind.kindName;
  20676. }
  20677. // 设置名称
  20678. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  20679. $scope.prodInfo.title = kind.kindName;
  20680. }
  20681. $scope.getSimilarBrands = function (value) {
  20682. if (value) {
  20683. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20684. return data.map(function (item) {
  20685. return item;
  20686. });
  20687. });
  20688. }
  20689. }
  20690. // 设置导入品牌
  20691. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20692. $scope.prodInfo.brand = brand.brandName;
  20693. }
  20694. // 设置标准品牌
  20695. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  20696. $scope.prodInfo.pbranden = brand.brandName;
  20697. }
  20698. $scope.getSimilarComponents = function (value) {
  20699. if (value) {
  20700. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20701. return data.map(function (item) {
  20702. return item;
  20703. });
  20704. });
  20705. }
  20706. }
  20707. // 设置标准型号
  20708. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20709. $scope.prodInfo.pcmpcode = cmp.code;
  20710. }
  20711. // 设置导入的型号
  20712. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  20713. $scope.prodInfo.cmpCode = cmp.code;
  20714. }
  20715. // 联想词 end
  20716. //更新为标准器件
  20717. $scope.updateone = function (id) {
  20718. Products.updateone({id: id}, {}, function (data) {
  20719. if (data.success) {
  20720. toaster.pop('success', '提示', data.success);
  20721. window.location.reload();
  20722. }
  20723. }, function (response) {
  20724. toaster.pop('error', '提示', response.data);
  20725. });
  20726. }
  20727. // 选择类目
  20728. $scope.selectKind = function (cmpcode) {
  20729. if (cmpcode == null) {
  20730. $modal.open({
  20731. animation: true,
  20732. size: 'lg',
  20733. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20734. controller: 'KindChooseCtrl',
  20735. }).result.then(function (data) {
  20736. $scope.kindId = data;
  20737. var modalInstance = $modal.open({
  20738. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20739. controller: 'FindComponentCtrl',
  20740. size: 'lg',
  20741. resolve: {
  20742. KindId: function () {
  20743. return $scope.kindId;
  20744. }
  20745. }
  20746. });
  20747. modalInstance.result.then(function (data) {
  20748. $scope.prodInfo.cmpUuId = data.uuid;
  20749. $scope.prodInfo.pcmpcode = data.code;
  20750. $scope.prodInfo.pbranden = data.brand.nameEn;
  20751. $scope.prodInfo.pbrand = data.brand.nameCn;
  20752. }, function () {
  20753. });
  20754. }, function () {
  20755. });
  20756. }
  20757. };
  20758. $scope.isShow = true;
  20759. // 更新
  20760. $scope.update = function () {
  20761. $scope.prodInfo.$editing = true;
  20762. $scope.isShow = true;
  20763. };
  20764. // 取消
  20765. $scope.cancel = function () {
  20766. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  20767. $scope.prodInfo = data;
  20768. $scope.prodInfo.$editing = false;
  20769. $scope.isShow = false;
  20770. $scope.loading = false;
  20771. });
  20772. };
  20773. // 删除
  20774. $scope.clearfile = function () {
  20775. $scope.prodInfo.attach = null;
  20776. $scope.myFiles = null;
  20777. $scope.previewShow = false;
  20778. }
  20779. //删除
  20780. $scope.deleteById = function (id) {
  20781. GetProductInfo.deletePurcById({}, id, function (data) {
  20782. if (data.error) {
  20783. toaster.pop("error", "提示", data.error);
  20784. } else {
  20785. toaster.pop("success", "提示", "删除成功");
  20786. window.location.href = "#/purc/product";
  20787. }
  20788. }, function (response) {
  20789. toaster.pop("error", "删除失败", response.data);
  20790. });
  20791. }
  20792. $scope.submit = function (prodInfo) {
  20793. $scope.prodInfo.isPurchase = 1;
  20794. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20795. $upload.upload({
  20796. url: 'purcProduct/edit/updateProdInfo',
  20797. file: file,
  20798. method: 'POST',
  20799. data: {
  20800. prodInfo: $scope.prodInfo
  20801. },
  20802. }).success(function (data) {
  20803. if (data.success) {
  20804. toaster.pop('success', '提示', data.success);
  20805. loadData();
  20806. // window.location.href="#/sale/prodList";
  20807. }
  20808. if (data.error) {
  20809. toaster.pop('error', '提示', data.error);
  20810. }
  20811. }).error(function (data, status) {
  20812. $scope.loadingShow = false;
  20813. if (status == 403) {
  20814. toaster.pop('error', '操作失败', data);
  20815. } else {
  20816. toaster.pop('error', '操作失败', data.error);
  20817. }
  20818. });
  20819. }
  20820. $scope.previewShow = false;
  20821. $scope.pdfShow = false;
  20822. $scope.noneFileShow = true;
  20823. $scope.$watch('myFiles', function () {
  20824. if ($scope.myFiles) {
  20825. $scope.noneFileShow = false;
  20826. var file = $scope.myFiles[0];
  20827. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20828. $scope.pdfShow = true;
  20829. $scope.previewShow = false;
  20830. $scope.imgPreviewName = file.name;
  20831. } else {
  20832. if (typeof(Worker) !== "undefined") {//支持HTML5
  20833. $scope.imgPreview = getObjectURL(file);
  20834. $scope.imgPreviewName = file.name;
  20835. } else {//不支持HTML5
  20836. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20837. $scope.imgPreviewName = file.name;
  20838. }
  20839. $scope.previewShow = true;
  20840. $scope.pdfShow = false;
  20841. }
  20842. } else {
  20843. $scope.noneFileShow = true;
  20844. $scope.previewShow = false;
  20845. $scope.pdfShow = false;
  20846. }
  20847. });
  20848. //建立一个可存取到该file的url
  20849. var imgurl = null;
  20850. var getObjectURL = function (file) {
  20851. var url = null;
  20852. if (window.createObjectURL != undefined) { // basic
  20853. url = window.createObjectURL(file);
  20854. } else if (window.URL != undefined) { // mozilla(firefox)
  20855. url = window.URL.createObjectURL(file);
  20856. } else if (window.webkitURL != undefined) { // webkit or chrome
  20857. url = window.webkitURL.createObjectURL(file);
  20858. }
  20859. imgurl = url;
  20860. return url;
  20861. };
  20862. // 查看范例
  20863. $scope.showImg = function () {
  20864. if ($scope.prodInfo.attach) {
  20865. GetProductInfo.getAttach({id: $scope.prodInfo.attach.id}, function (data) {
  20866. var src = data.url, box = $('#image-box');
  20867. box.show();
  20868. box.find('img').attr('src', src);
  20869. box.find('a').click(function () {
  20870. box.hide();
  20871. });
  20872. box.dblclick(function () {
  20873. box.hide();
  20874. });
  20875. })
  20876. } else if (imgurl != null) {
  20877. var src = imgurl, box = $('#image-box');
  20878. box.show();
  20879. box.find('img').attr('src', src);
  20880. box.find('a').click(function () {
  20881. box.hide();
  20882. });
  20883. box.dblclick(function () {
  20884. box.hide();
  20885. });
  20886. }
  20887. };
  20888. }]);
  20889. // 供应商绩效考核
  20890. app.controller('VendorPerformanceAssessCtrl', ['$scope', 'VendorPerformanceAssessService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorPerformanceAssessService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  20891. BaseService.scrollBackToTop();
  20892. $scope.vendorPerformanceAssessParams = new ngTableParams({
  20893. page: 1,
  20894. count: 20
  20895. }, {
  20896. total: 0,
  20897. counts: [5, 10, 25, 50],
  20898. getData: function ($defer, params) {
  20899. $scope.loading = true;
  20900. var pageParams = params.url();
  20901. pageParams.keyword = $scope.keyword;
  20902. VendorPerformanceAssessService.get(BaseService.parseParams(pageParams), function (page) {
  20903. $scope.loading = false;
  20904. if (page) {
  20905. params.total(page.totalElement);
  20906. $defer.resolve(page.content);
  20907. $scope.keywordXls = pageParams.keyword;
  20908. }
  20909. $scope.totalCount = page.totalElement;
  20910. }, function (response) {
  20911. $scope.loading = false;
  20912. toaster.pop('error', '数据加载失败', response.data);
  20913. });
  20914. }
  20915. });
  20916. //设置消息已读
  20917. var setOrdersRead = function () {
  20918. var sourceId = [];
  20919. VendorPerformanceAssessService.setRead({}, sourceId, function (message) {
  20920. // $scope.getUnreadIds();
  20921. });
  20922. };
  20923. setOrdersRead();
  20924. // 搜索框回车
  20925. $scope.onSearch = function (keyword) {
  20926. $scope.vendorPerformanceAssessParams.page(1);
  20927. $scope.vendorPerformanceAssessParams.reload();
  20928. $scope.tip = keyword;
  20929. };
  20930. // 查看详情
  20931. $scope.viewDetail = function (id) {
  20932. window.location.hash = "#/sale/vendorPerformanceAssess/" + id;
  20933. }
  20934. }]);
  20935. // 客户详情
  20936. app.controller('VendorPerformanceAssessDetailCtrl', ['$scope', 'toaster', '$stateParams', 'VendorPerformanceAssessService', '$modal', 'ngTableParams', 'BaseService', '$rootScope', 'AuthenticationService', function ($scope, toaster, $stateParams, VendorPerformanceAssessService, $modal, ngTableParams, BaseService, $rootScope, AuthenticationService) {
  20937. BaseService.scrollBackToTop();
  20938. var loadData = function () {
  20939. VendorPerformanceAssessService.getDetail({id: $stateParams.id}, {}, function (data) {
  20940. $scope.vendorPerformanceAssess = data;
  20941. }, function (response) {
  20942. $scope.loading = false;
  20943. toaster.pop('error', '数据加载失败', response.data);
  20944. });
  20945. };
  20946. loadData();
  20947. }]);
  20948. /**
  20949. * 个人产品库
  20950. */
  20951. app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', '$rootScope', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal, $rootScope) {
  20952. BaseService.scrollBackToTop();
  20953. $rootScope.ids = [];// 每次加载先清空数据
  20954. $scope.searchMethod = false;
  20955. var getService = function () {
  20956. return $scope.searchMethod ? prodUser.getInfo : prodUser.info;
  20957. };
  20958. $scope.tableParams = new ngTableParams({ // ng-Table参数
  20959. page: 1,
  20960. count: 20,
  20961. sorting: {
  20962. 'date': 'desc',
  20963. 'id': 'desc'
  20964. }
  20965. }, {
  20966. total: 0,
  20967. counts: [],
  20968. getData: function ($defer, params) { // 获取数据的方法
  20969. $scope.loading = true;
  20970. var pageParams = params.url();
  20971. pageParams.keyword = $scope.keyword;
  20972. $scope.tip = $scope.keyword;
  20973. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  20974. $scope.loading = false;
  20975. if (page) {
  20976. params.total(page.totalElement);
  20977. $defer.resolve(page.content);
  20978. $scope.checkall = true;
  20979. if(page.content.length <= 2) {
  20980. $scope.checkall = false;
  20981. } else {
  20982. angular.forEach(page.content, function (prod) {
  20983. if ($rootScope.ids.indexOf(prod.id) > -1) {
  20984. prod.$selected = true;
  20985. } else {
  20986. $scope.checkall = false;
  20987. }
  20988. });
  20989. }
  20990. $scope.checkboxes = {
  20991. checked: $scope.checkall
  20992. };
  20993. }
  20994. }, function (response) {
  20995. $scope.loading = false;
  20996. toaster.pop('error', '数据加载失败', response.data);
  20997. });
  20998. }
  20999. });
  21000. // 搜索框回车
  21001. $scope.onSearch = function (keyword) {
  21002. // 每次搜索重置获取数据方法
  21003. $scope.searchMethod = false;
  21004. if(keyword != null && keyword != '') {
  21005. $scope.searchMethod = true;
  21006. $scope.tip = keyword;
  21007. }
  21008. $scope.tableParams.page(1);
  21009. $scope.tableParams.reload();
  21010. };
  21011. // 新增产品信息
  21012. $scope.addProduct = function() {
  21013. $modal.open({
  21014. animation: true,
  21015. size: 'lg',
  21016. templateUrl: 'static/tpl/index/approvalFlow/modal/userprod_new_modal.html',
  21017. controller: 'UserProductNewCtrl',
  21018. }).result.then(function (data) {
  21019. $scope.tableParams.page(1);
  21020. $scope.tableParams.reload();
  21021. }, function () {
  21022. });
  21023. }
  21024. // 导入商品信息
  21025. $scope.uploadByBatch = function () {
  21026. var modalInstance = $modal.open({
  21027. templateUrl: 'static/tpl/index/approvalFlow/modal/uplodaByBatch.html',
  21028. controller: 'UserProdUploadCtrl',
  21029. backdrop: 'static',
  21030. keyboard: false,
  21031. size: 'lg',
  21032. resolve: {}
  21033. });
  21034. modalInstance.result.then(function (data) {
  21035. $scope.tableParams.page(1);
  21036. $scope.tableParams.reload();
  21037. }, function () {
  21038. });
  21039. }
  21040. // 删除
  21041. $scope.deleteById = function(id) {
  21042. prodUser.deleteById({}, id, function(data) {
  21043. toaster.pop('success', '提示', '删除成功');
  21044. $scope.tableParams.page(1);
  21045. $scope.tableParams.reload();
  21046. }, function(res) {
  21047. toaster.pop('error', '提示', '删除失败');
  21048. });
  21049. }
  21050. $scope.checkboxes = {
  21051. checked: false
  21052. };
  21053. angular.forEach($scope.tableParams.data, function (item) {
  21054. $scope.checkboxes.checked = false;
  21055. if($rootScope.ids.in_array(item.id)) {
  21056. $rootScope.ids.remove(item.id);
  21057. $scope.checkboxes.checked = true;
  21058. }
  21059. });
  21060. // 点击勾选全部的复选框
  21061. $scope.checkAll = function () {
  21062. angular.forEach($scope.tableParams.data, function (item) {
  21063. item.$selected = $scope.checkboxes.checked;
  21064. if(item.$selected) {
  21065. if(!$rootScope.ids.in_array(item.id)) {
  21066. $rootScope.ids.push(item.id);
  21067. }
  21068. } else {
  21069. if($rootScope.ids.in_array(item.id)) {
  21070. $rootScope.ids.remove(item.id);
  21071. }
  21072. }
  21073. });
  21074. };
  21075. // 判断数组中是否存在某个对象
  21076. Array.prototype.S = String.fromCharCode(2);
  21077. Array.prototype.in_array = function(e) {
  21078. var r = new RegExp(this.S + e + this.S);
  21079. return (r.test(this.S + this.join(this.S) + this.S));
  21080. }
  21081. // 从数组中移除某个对象
  21082. Array.prototype.remove = function(val) {
  21083. var index = this.indexOf(val);
  21084. if (index > -1) {
  21085. this.splice(index, 1);
  21086. }
  21087. };
  21088. // 点击其中一个明细的复选框
  21089. $scope.checkOne = function (product) {
  21090. var result = true;
  21091. angular.forEach($scope.tableParams.data, function (item) {
  21092. if (item.$selected != true) {
  21093. result = false;
  21094. return;
  21095. }
  21096. });
  21097. if(product.$selected) {
  21098. if(!$rootScope.ids.in_array(product.id)) {
  21099. $rootScope.ids.push(product.id);
  21100. }
  21101. } else {
  21102. if($rootScope.ids.in_array(product.id)) {
  21103. $rootScope.ids.remove(product.id);
  21104. }
  21105. }
  21106. $scope.checkboxes = {
  21107. checked: result
  21108. };
  21109. };
  21110. // 批量删除
  21111. $scope.deleteByBatch = function() {
  21112. var ids = angular.toJson($rootScope.ids);
  21113. if($rootScope.ids.length > 0) {
  21114. prodUser.deleteByBatch({ids: ids}, {}, function(data) {
  21115. toaster.pop('success', '提示', '成功移除' + $rootScope.ids.length + '个产品');
  21116. $rootScope.ids = [];
  21117. $scope.tableParams.page(1);
  21118. $scope.tableParams.reload();
  21119. }, function(res) {
  21120. toaster.pop('error', '提示', '移除失败');
  21121. });
  21122. } else {
  21123. toaster.pop('error', '提示', '请先选择产品');
  21124. }
  21125. }
  21126. }]);
  21127. /**
  21128. * 用户产品新增产品
  21129. */
  21130. app.controller('UserProductNewCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', function($scope, toaster, prodUser, $modalInstance) {
  21131. // 确定
  21132. $scope.submit = function(prodInfo) {
  21133. prodUser.addProduct({}, prodInfo, function(data) {
  21134. if(data.success) {
  21135. toaster.pop('success', '提示', data.success);
  21136. } else if(data.info) {
  21137. toaster.pop('info', '提示', data.info);
  21138. }
  21139. $modalInstance.close('success');
  21140. }, function(res) {
  21141. toaster.pop('error', '提示', '添加失败');
  21142. });
  21143. }
  21144. // 取消
  21145. $scope.cancel = function() {
  21146. $modalInstance.dismiss();
  21147. }
  21148. }]);
  21149. /**
  21150. * 用户产品批量导入产品
  21151. */
  21152. app.controller('UserProdUploadCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', '$upload', function($scope, toaster, prodUser, $modalInstance, $upload) {
  21153. // 通过excel批量上传物料
  21154. $scope.upload = function () {
  21155. $scope.loading = true;
  21156. if ($scope.myFiles) {
  21157. var file = $scope.myFiles[0];
  21158. if (file.name) {
  21159. $upload.upload({
  21160. url: 'productuser/edit/release/excel',
  21161. file: file,
  21162. method: 'POST'
  21163. }).success(function (data) {
  21164. $scope.loading = false;
  21165. if (data.error) {
  21166. toaster.pop('error', '提示', data.error);
  21167. }
  21168. $scope.result = data;
  21169. $scope.success = $scope.result.success;
  21170. $scope.total = $scope.result.total;
  21171. $scope.myFiles[0] = "";
  21172. $scope.fileName = "";
  21173. }).error(function (response) {
  21174. $scope.loading = false;
  21175. toaster.pop('error', response.data || response);
  21176. });
  21177. } else {
  21178. $scope.loading = false;
  21179. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  21180. }
  21181. } else {
  21182. $scope.loading = false;
  21183. }
  21184. };
  21185. // 取消
  21186. $scope.cancel = function() {
  21187. $modalInstance.dismiss();
  21188. }
  21189. // 下载模板
  21190. $scope.download = function () {
  21191. window.location.href = 'productuser/upload/template';
  21192. };
  21193. // 确定
  21194. $scope.enSure = function() {
  21195. $modalInstance.close('success');
  21196. }
  21197. }]);
  21198. /**
  21199. * 针对卖家,已转询价的公共询价单列表
  21200. */
  21201. app.controller('SalePubInquiryCtrl', ['$scope', '$filter', 'PubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', function ($scope, $filter, PubInquirySearchInfo, ngTableParams, toaster, BaseService, PubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, $modal, AccountEnterprise, $http) {
  21202. BaseService.scrollBackToTop();
  21203. // 获取当前用户是否为普通用户
  21204. CurrentRole.isUser({}, {}, function (data) {
  21205. $scope.isUser = data.isUser;
  21206. });
  21207. if ($rootScope.active) {
  21208. $scope.active = $rootScope.active;
  21209. $rootScope.active = null;
  21210. } else {
  21211. $scope.active = 'all';
  21212. }
  21213. $scope.agreedText = '全部';
  21214. $scope.dateZoneText = '最近一个月';
  21215. $scope.condition = {dateZone: 1};
  21216. /* 时间筛选初始化*/
  21217. var fromDate = new Date();
  21218. var toDate = new Date();
  21219. fromDate.setMonth(fromDate.getMonth() - 1);
  21220. fromDate.setHours(0, 0, 0, 0);
  21221. toDate.setHours(23, 59, 59, 999);
  21222. $scope.condition.dateFrom = fromDate;
  21223. $scope.condition.dateTo = toDate;
  21224. $scope.changeAgreed = function (agreed) {
  21225. $scope.condition.agreed = agreed;
  21226. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  21227. $scope.condition.$agreedOpen = false;
  21228. };
  21229. $scope.changeDateZone = function (zone) {
  21230. $scope.condition.dateZone = zone;
  21231. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21232. $scope.condition.$dateZoneOpen = false;
  21233. getDateCondition(zone, $scope.condition);
  21234. $scope.tableParams.page(1);
  21235. $scope.tableParams.reload();
  21236. };
  21237. $scope.setActive = function (state) {
  21238. if ($scope.active != state) {
  21239. $scope.active = state;
  21240. if ($scope.tableParams.page() == 1)
  21241. $scope.tableParams.reload();
  21242. else
  21243. $scope.tableParams.page(1);
  21244. }
  21245. };
  21246. $scope.searchMethod = false;
  21247. var getService = function () {
  21248. return $scope.searchMethod ? PubInquirySearchInfo : PubInquiryNoSearchInfo;
  21249. };
  21250. $scope.tableParams = new ngTableParams({
  21251. page: 1,
  21252. count: 20,
  21253. sorting: {
  21254. 'inquiry.date': 'desc',
  21255. 'inquiry.enterprise.enName': 'asc',
  21256. 'inquiry.code': 'asc'
  21257. }
  21258. }, {
  21259. total: 0,
  21260. counts: [5, 10, 25, 50],
  21261. getData: function ($defer, params) {
  21262. $scope.loading = true;
  21263. var pageParams = params.url();
  21264. var realActive = {};
  21265. pageParams.searchFilter = { // 筛选条件
  21266. keyword: $scope.keyword,
  21267. fromDate: getDateTime($scope.condition.dateFrom),
  21268. endDate: getDateTime($scope.condition.dateTo)
  21269. };
  21270. if ($scope.active == 'overdue') {
  21271. $scope.active = 'end';
  21272. }
  21273. AccountEnterprise.get({}, function(data) {
  21274. $scope.currentEn = data;
  21275. publicInquiry.getUrl({}, function(data) {
  21276. var url = data.url;
  21277. var filter = {vendUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21278. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21279. $http({
  21280. method: 'get',
  21281. dataType: 'json',
  21282. url: url + '/inquiry/public/quotation/list',
  21283. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21284. }).success(function (response) {
  21285. $scope.loading = false;
  21286. if (response) {
  21287. params.total(response.totalElements);
  21288. $defer.resolve(response.content);
  21289. }
  21290. }).error(function (err) {
  21291. $scope.loading = false;
  21292. toaster.pop('error', '数据加载失败', err);
  21293. });
  21294. });
  21295. });
  21296. }
  21297. });
  21298. $scope.isUnread = function (id) {
  21299. for (var i in $scope.unreadCode) {
  21300. if (id == $scope.unreadCode[i]) {
  21301. return true;
  21302. }
  21303. }
  21304. };
  21305. $scope.getMinDate = function (item) {
  21306. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21307. };
  21308. $scope.replyPrices = [];
  21309. $scope.replylapQtys = [];
  21310. $scope.replyPrices.push(true);
  21311. $scope.replylapQtys.push(true);
  21312. $scope.addStep = function (inquiryItem) {
  21313. $scope.replyPrices.push(true);
  21314. if (inquiryItem.replies.length >= 10) {
  21315. toaster.pop('warning', '提示', '最多支持10个分段!');
  21316. } else {
  21317. inquiryItem.replies.push({});
  21318. if (inquiryItem.replies.length != 1) {
  21319. $scope.replyPrices.push(true);
  21320. $scope.replylapQtys.push(true);
  21321. }
  21322. }
  21323. };
  21324. $scope.removeStep = function (inquiryItem, stepIndex) {
  21325. inquiryItem.replies.splice(stepIndex, 1);
  21326. $scope.replyPrices.splice(stepIndex, 1);
  21327. $scope.replylapQtys.splice(stepIndex, 1);
  21328. };
  21329. $scope.openDatePicker = function ($event, item, openParam) {
  21330. $event.preventDefault();
  21331. $event.stopPropagation();
  21332. item[openParam] = !item[openParam];
  21333. };
  21334. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21335. $event.preventDefault();
  21336. $event.stopPropagation();
  21337. item[openParam] = !item[openParam];
  21338. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21339. $scope.tableParams.reload();
  21340. }
  21341. };
  21342. $scope.getHistory = function (item) {
  21343. if (!item.history) {
  21344. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21345. item.history = data;
  21346. });
  21347. }
  21348. };
  21349. // 报价
  21350. $scope.quote = function(inquiryItem) {
  21351. $modal.open({
  21352. animation: true,
  21353. templateUrl: 'static/tpl/index/sale/modal/quote_inquiry.html',
  21354. controller: 'QuoteInquiryCtrl',
  21355. resolve: {
  21356. inquiryItem: function () {
  21357. return inquiryItem
  21358. }
  21359. }
  21360. }).result.then(function (data) {
  21361. }, function () {})
  21362. };
  21363. $scope.deleteAttach = function (attaches, index) {
  21364. attaches.splice(index, 1);
  21365. };
  21366. $scope.onReplyClick = function (item, withSteps) {
  21367. if (item.vendFromDate instanceof Date) {
  21368. item.vendFromDate = item.vendFromDate.getTime();
  21369. }
  21370. if (item.vendToDate instanceof Date) {
  21371. item.vendToDate = item.vendToDate.getTime();
  21372. }
  21373. if (item.vendFromDate > item.vendToDate) {
  21374. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  21375. return;
  21376. }
  21377. var replies = [];
  21378. // 判断分段数是否合法
  21379. var valid = true;
  21380. var validLapQty = 0;
  21381. angular.forEach(item.replies, function (r, i) {
  21382. if ((i > 0 ? r.lapQty : 1) || r.price) {
  21383. replies.push(r);
  21384. }
  21385. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  21386. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  21387. valid = false;
  21388. validLapQty = r.lapQty;
  21389. }
  21390. });
  21391. item.replies = replies;
  21392. $scope.loading = true;
  21393. if (!valid) {
  21394. if (validLapQty) {
  21395. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  21396. } else {
  21397. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  21398. }
  21399. $scope.loading = false;
  21400. } else {
  21401. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  21402. if (withSteps) { // 保存并报价
  21403. if(null != file) {
  21404. $upload.upload({
  21405. url: 'sale/pubInquiry/addAttach',
  21406. file: file,
  21407. method: 'POST',
  21408. data: {
  21409. item: item,
  21410. method: 'reply'
  21411. }
  21412. }).success(function (data) {
  21413. if (data.item) {
  21414. item = data.item;
  21415. }
  21416. $scope.loading = false;
  21417. toaster.pop('info', '提示', '报价成功');
  21418. $scope.tableParams.reload();
  21419. }).error(function (data) {
  21420. $scope.loading = false;
  21421. toaster.pop('error', '附件上传失败');
  21422. });
  21423. } else {
  21424. publicInquiry.reply({itemId: item.id, token: $scope.token}, item, function (data) {
  21425. $scope.loading = false;
  21426. toaster.pop('info', '提示', '报价成功');
  21427. $scope.tableParams.reload();
  21428. }, function (response) {
  21429. $scope.loading = false;
  21430. toaster.pop('error', '询价失效', response.data);
  21431. });
  21432. }
  21433. } else { // 保存
  21434. if(null != file) {
  21435. $upload.upload({
  21436. url: 'sale/pubInquiry/addAttach',
  21437. file: file,
  21438. method: 'POST',
  21439. data: {
  21440. item: item,
  21441. method: 'save'
  21442. }
  21443. }).success(function (data) {
  21444. if (data.item) {
  21445. item = data.item;
  21446. }
  21447. $scope.loading = false;
  21448. toaster.pop('info', '提示', '保存成功');
  21449. $scope.tableParams.reload();
  21450. }).error(function (data) {
  21451. $scope.loading = false;
  21452. toaster.pop('error', '附件上传失败');
  21453. });
  21454. } else {
  21455. publicInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function (data) {
  21456. $scope.loading = false;
  21457. toaster.pop('info', '提示', '保存成功');
  21458. $scope.tableParams.reload();
  21459. }, function (response) {
  21460. $scope.loading = false;
  21461. toaster.pop('error', '保存失败', response.data);
  21462. });
  21463. }
  21464. }
  21465. }
  21466. };
  21467. $scope.isValid = function (item, withSteps) {
  21468. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  21469. if (!withSteps || !bool)
  21470. return bool;
  21471. angular.forEach(item.replies, function (r, i) {
  21472. $scope.verifylapQty(r.lapQty, i, item);
  21473. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  21474. });
  21475. return bool;
  21476. };
  21477. $scope.verifylapQty = function (value, index, inquiryItem) {
  21478. value = parseInt(value);
  21479. var regex = /^\d+(.\d{1,5})?$/;
  21480. var valid = true;
  21481. angular.forEach(inquiryItem.replies, function(reply, $index) {
  21482. if ($index < index && reply.lapQty >= value) {
  21483. valid = false;
  21484. }
  21485. });
  21486. $scope.replylapQtys[index] = regex.test(value) && valid;
  21487. };
  21488. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21489. $scope.verify = function (value, type) {
  21490. var regex = /^\d+(.\d{1,6})?$/;//
  21491. switch (type) {
  21492. case 'minOrderQty':
  21493. $scope.minOrderQtyVerify = regex.test(value);
  21494. break;
  21495. case 'minPackQty':
  21496. $scope.minPackQtyVerify = regex.test(value);
  21497. break;
  21498. case 'leadtime':
  21499. $scope.leadtimeVerify = regex.test(value);
  21500. break;
  21501. default:
  21502. $scope.replyPrices[type] = regex.test(value);
  21503. break;
  21504. }
  21505. }
  21506. // 搜索框回车
  21507. $scope.onSearch = function (keyword) {
  21508. // 每次搜索重置获取数据方法
  21509. $scope.searchMethod = false;
  21510. if(keyword != null && keyword != '') {
  21511. $scope.searchMethod = true;
  21512. }
  21513. $scope.tableParams.page(1);
  21514. $scope.tableParams.reload();
  21515. };
  21516. // 取消
  21517. $scope.cancel = function () {
  21518. $scope.tableParams.reload();
  21519. }
  21520. // 导出
  21521. $scope.exportXls = function () {
  21522. PurcInquiry.exportXls({}, {}, function (data) {
  21523. if (data.success) {
  21524. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21525. }
  21526. }, function (response) {
  21527. toaster.pop('error', '数据加载失败', response.data);
  21528. })
  21529. }
  21530. }]);
  21531. /**
  21532. * 针对卖家,已转询价单的客户公共询价单明细
  21533. */
  21534. app.controller('SalePubInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'publicInquiry', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole, publicInquiry) {
  21535. // 获取当前用户是否为普通用户
  21536. var loadData = function () {
  21537. publicInquiry.inquiryDetail({id: $stateParams.id}, function (data) {
  21538. $scope.inquiryItem = data;
  21539. var inquiry = data.inquiry;
  21540. angular.forEach(inquiry.attachs, function (attach) {
  21541. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21542. });
  21543. $scope.inquiry = inquiry;
  21544. $scope.attach = null;
  21545. if ($scope.inquiryItem.attaches.length > 0) {
  21546. $scope.attach = $scope.inquiryItem.attaches[0];
  21547. }
  21548. }, function (response) {
  21549. $scope.loading = false;
  21550. toaster.pop('error', '', response.data);
  21551. });
  21552. };
  21553. loadData();
  21554. $scope.getMinDate = function (item) {
  21555. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21556. };
  21557. $scope.replyPrices = [];
  21558. $scope.replylapQtys = [];
  21559. $scope.replyPrices.push(true);
  21560. $scope.replylapQtys.push(true);
  21561. $scope.addStep = function (inquiryItem) {
  21562. if (inquiryItem.replies.length >= 10) {
  21563. toaster.pop('warning', '提示', '最多支持10个分段!');
  21564. } else
  21565. inquiryItem.replies.push({});
  21566. };
  21567. $scope.removeStep = function (inquiryItem, stepIndex) {
  21568. inquiryItem.replies.splice(stepIndex, 1);
  21569. };
  21570. $scope.openDatePicker = function ($event, item, openParam) {
  21571. $event.preventDefault();
  21572. $event.stopPropagation();
  21573. item[openParam] = !item[openParam];
  21574. };
  21575. $scope.getHistory = function (item) {
  21576. if (!item.history) {
  21577. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21578. item.history = data;
  21579. });
  21580. }
  21581. };
  21582. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21583. $scope.verify = function (value, type) {
  21584. var regex = /^\d+(.\d{1,6})?$/;//
  21585. switch (type) {
  21586. case 'minOrderQty':
  21587. $scope.minOrderQtyVerify = regex.test(value);
  21588. break;
  21589. case 'minPackQty':
  21590. $scope.minPackQtyVerify = regex.test(value);
  21591. break;
  21592. case 'leadtime':
  21593. $scope.leadtimeVerify = regex.test(value);
  21594. break;
  21595. default:
  21596. $scope.replyPrices[type] = regex.test(value);
  21597. break;
  21598. }
  21599. }
  21600. $scope.verifylapQty = function (value, index, inquiryItem) {
  21601. value = parseInt(value);
  21602. var regex = /^\d+(.\d{1,6})?$/;
  21603. var valid = true;
  21604. angular.forEach(inquiryItem.replies, function(reply, $index) {
  21605. if ($index < index && reply.lapQty >= value) {
  21606. valid = false;
  21607. }
  21608. });
  21609. $scope.replylapQtys[index] = regex.test(value) && valid;
  21610. };
  21611. $scope.isValid = function (item, withSteps) {
  21612. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  21613. if (!withSteps || !bool)
  21614. return bool;
  21615. angular.forEach(item.replies, function (r, i) {
  21616. $scope.verifylapQty(r.lapQty, i, item);
  21617. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  21618. });
  21619. return bool;
  21620. };
  21621. $scope.deleteAttach = function (attaches, index) {
  21622. attaches.splice(index, 1);
  21623. };
  21624. $scope.onReplyClick = function (item, withSteps) {
  21625. if (item.vendFromDate instanceof Date) {
  21626. item.vendFromDate = item.vendFromDate.getTime();
  21627. }
  21628. if (item.vendToDate instanceof Date) {
  21629. item.vendToDate = item.vendToDate.getTime();
  21630. }
  21631. if (item.vendFromDate > item.vendToDate) {
  21632. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  21633. return;
  21634. }
  21635. var replies = [];
  21636. var valid = true;
  21637. var validLapQty = 0;
  21638. angular.forEach(item.replies, function (r, i) {
  21639. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  21640. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  21641. valid = false;
  21642. validLapQty = r.lapQty;
  21643. }
  21644. if ((i > 0 ? r.lapQty : 1) || r.price)
  21645. replies.push(r);
  21646. });
  21647. item.replies = replies;
  21648. $scope.loading = true;
  21649. if (!valid) { // 不合法时给出提示
  21650. if (validLapQty) {
  21651. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  21652. } else {
  21653. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  21654. }
  21655. $scope.loading = false;
  21656. } else {
  21657. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  21658. if (withSteps) {
  21659. if(null != file) {
  21660. $upload.upload({
  21661. url: 'sale/pubInquiry/addAttach',
  21662. file: file,
  21663. method: 'POST',
  21664. data: {
  21665. item: item,
  21666. method: 'reply'
  21667. }
  21668. }).success(function (data) {
  21669. if (data.item) {
  21670. item = data.item;
  21671. }
  21672. toaster.pop('success', '提示', '报价成功');
  21673. loadData();
  21674. }).error(function () {
  21675. toaster.pop('error', '提示', '报价失败');
  21676. });
  21677. } else {
  21678. publicInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  21679. $scope.loading = false;
  21680. toaster.pop('success', '提示', '报价成功');
  21681. loadData();
  21682. }, function (response) {
  21683. $scope.loading = false;
  21684. toaster.pop('error', '询价失效', response.data);
  21685. });
  21686. }
  21687. } else {
  21688. if(null != file) {
  21689. $upload.upload({
  21690. url: 'sale/pubInquiry/addAttach',
  21691. file: file,
  21692. method: 'POST',
  21693. data: {
  21694. item: item,
  21695. method: 'save'
  21696. }
  21697. }).success(function (data) {
  21698. if (data.item) {
  21699. item = data.item;
  21700. }
  21701. toaster.pop('success', '提示', '保存成功');
  21702. loadData();
  21703. }).error(function () {
  21704. toaster.pop('error', '提示', '保存失败');
  21705. });
  21706. } else {
  21707. publicInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  21708. $scope.loading = false;
  21709. toaster.pop('info', '提示', '保存成功');
  21710. loadData();
  21711. }, function (response) {
  21712. $scope.loading = false;
  21713. toaster.pop('error', '保存失败', response.data);
  21714. });
  21715. }
  21716. }
  21717. }
  21718. };
  21719. // 取消
  21720. $scope.cancel = function () {
  21721. $scope.tableParams.reload();
  21722. }
  21723. }]);
  21724. /**
  21725. * 针对买家,已转询价的公共询价单列表
  21726. */
  21727. app.controller('PurcPubInquiryCtrl', ['$scope', '$filter', 'PurcPubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PurcPubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', 'AccountEnterprise', '$http', function ($scope, $filter, PurcPubInquirySearchInfo, ngTableParams, toaster, BaseService, PurcPubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, AccountEnterprise, $http) {
  21728. BaseService.scrollBackToTop();
  21729. // 获取当前用户是否为普通用户
  21730. CurrentRole.isUser({}, {}, function (data) {
  21731. $scope.isUser = data.isUser;
  21732. });
  21733. if ($rootScope.active) {
  21734. $scope.active = $rootScope.active;
  21735. $rootScope.active = null;
  21736. } else {
  21737. $scope.active = 'all';
  21738. }
  21739. $scope.agreedText = '全部';
  21740. $scope.dateZoneText = '最近一个月';
  21741. $scope.condition = {dateZone: 1};
  21742. /* 时间筛选初始化*/
  21743. var fromDate = new Date();
  21744. var toDate = new Date();
  21745. fromDate.setMonth(fromDate.getMonth() - 1);
  21746. fromDate.setHours(0, 0, 0, 0);
  21747. toDate.setHours(23, 59, 59, 999);
  21748. $scope.condition.dateFrom = fromDate;
  21749. $scope.condition.dateTo = toDate;
  21750. $scope.changeAgreed = function (agreed) {
  21751. $scope.condition.agreed = agreed;
  21752. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  21753. $scope.condition.$agreedOpen = false;
  21754. };
  21755. $scope.changeDateZone = function (zone) {
  21756. $scope.condition.dateZone = zone;
  21757. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21758. $scope.condition.$dateZoneOpen = false;
  21759. getDateCondition(zone, $scope.condition);
  21760. $scope.tableParams.page(1);
  21761. $scope.tableParams.reload();
  21762. };
  21763. $scope.setActive = function (state) {
  21764. if ($scope.active != state) {
  21765. $scope.active = state;
  21766. if ($scope.tableParams.page() == 1)
  21767. $scope.tableParams.reload();
  21768. else
  21769. $scope.tableParams.page(1);
  21770. }
  21771. };
  21772. $scope.searchMethod = false;
  21773. var getService = function () {
  21774. return $scope.searchMethod ? PurcPubInquirySearchInfo : PurcPubInquiryNoSearchInfo;
  21775. };
  21776. $scope.tableParams = new ngTableParams({
  21777. page: 1,
  21778. count: 20,
  21779. sorting: {
  21780. 'inquiry.date': 'desc',
  21781. 'inquiry.enterprise.enName': 'asc',
  21782. 'inquiry.code': 'asc'
  21783. }
  21784. }, {
  21785. total: 0,
  21786. counts: [5, 10, 25, 50],
  21787. getData: function ($defer, params) {
  21788. $scope.loading = true;
  21789. var pageParams = params.url();
  21790. var realActive = {};
  21791. pageParams.searchFilter = { // 筛选条件
  21792. keyword: $scope.keyword,
  21793. fromDate: getDateTime($scope.condition.dateFrom),
  21794. endDate: getDateTime($scope.condition.dateTo)
  21795. };
  21796. if ($scope.active == 'overdue') {
  21797. $scope.active = 'end';
  21798. }
  21799. AccountEnterprise.get({}, function(data) {
  21800. $scope.currentEn = data;
  21801. publicInquiry.getUrl({}, function(data) {
  21802. var url = data.url;
  21803. var filter = {enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21804. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21805. $http({
  21806. method: 'get',
  21807. dataType: 'json',
  21808. url: url + '/inquiry/public/quotation/list',
  21809. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21810. }).success(function (response) {
  21811. $scope.loading = false;
  21812. if (response) {
  21813. params.total(response.totalElements);
  21814. $defer.resolve(response.content);
  21815. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  21816. }
  21817. }).error(function (err) {
  21818. $scope.loading = false;
  21819. toaster.pop('error', '数据加载失败', err);
  21820. });
  21821. });
  21822. });
  21823. }
  21824. });
  21825. $scope.isUnread = function (id) {
  21826. for (var i in $scope.unreadCode) {
  21827. if (id == $scope.unreadCode[i]) {
  21828. return true;
  21829. }
  21830. }
  21831. };
  21832. $scope.getMinDate = function (item) {
  21833. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21834. };
  21835. $scope.replyPrices = [];
  21836. $scope.replylapQtys = [];
  21837. $scope.replyPrices.push(true);
  21838. $scope.replylapQtys.push(true);
  21839. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21840. $event.preventDefault();
  21841. $event.stopPropagation();
  21842. item[openParam] = !item[openParam];
  21843. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21844. $scope.tableParams.reload();
  21845. }
  21846. };
  21847. $scope.getHistory = function (item) {
  21848. if (!item.history) {
  21849. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21850. item.history = data;
  21851. });
  21852. }
  21853. };
  21854. // 搜索框回车
  21855. $scope.onSearch = function (keyword) {
  21856. // 每次搜索重置获取数据方法
  21857. $scope.searchMethod = false;
  21858. if(keyword != null && keyword != '') {
  21859. $scope.searchMethod = true;
  21860. }
  21861. $scope.tableParams.page(1);
  21862. $scope.tableParams.reload();
  21863. };
  21864. // 采纳
  21865. $scope.accept = function (id) {
  21866. publicInquiry.accept({id: id}, {}, function (data) {
  21867. if (data.success) {
  21868. toaster.pop('success', '提示', data.success);
  21869. $scope.tableParams.page(1);
  21870. $scope.tableParams.reload();
  21871. }
  21872. if (data.error) {
  21873. toaster.pop('error', '提示', data.error);
  21874. $scope.tableParams.page(1);
  21875. $scope.tableParams.reload();
  21876. }
  21877. }, function (response) {
  21878. toaster.pop('error', '提示', '采纳失败');
  21879. $scope.tableParams.page(1);
  21880. $scope.tableParams.reload();
  21881. })
  21882. };
  21883. // 拒绝
  21884. $scope.refuse = function (id) {
  21885. publicInquiry.refuse({id: id}, {}, function (data) {
  21886. if (data.success) {
  21887. toaster.pop('success', '提示', data.success);
  21888. $scope.tableParams.page(1);
  21889. $scope.tableParams.reload();
  21890. }
  21891. if (data.error) {
  21892. toaster.pop('error', '提示', data.error);
  21893. $scope.tableParams.page(1);
  21894. $scope.tableParams.reload();
  21895. }
  21896. }, function (response) {
  21897. toaster.pop('error', '提示', '操作失败');
  21898. $scope.tableParams.page(1);
  21899. $scope.tableParams.reload();
  21900. })
  21901. }
  21902. // 导出
  21903. $scope.exportXls = function () {
  21904. PurcInquiry.exportXls({}, {}, function (data) {
  21905. if (data.success) {
  21906. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21907. }
  21908. }, function (response) {
  21909. toaster.pop('error', '数据加载失败', response.data);
  21910. })
  21911. }
  21912. }]);
  21913. /**
  21914. * 针对买家,已转询价单的客户公共询价单明细
  21915. */
  21916. app.controller('PurcPubInquiryDetailCtrl', ['$scope', '$stateParams', 'publicInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'AccountEnterprise', '$http', function ($scope, $stateParams, publicInquiry, $filter, toaster, $upload, token, CurrentRole, AccountEnterprise, $http) {
  21917. // 获取当前用户是否为普通用户
  21918. CurrentRole.isUser({}, {}, function (data) {
  21919. $scope.isUser = data.isUser;
  21920. });
  21921. AccountEnterprise.get({}, function(data) {
  21922. $scope.currentEn = data;
  21923. publicInquiry.getUrl({}, function(data) {
  21924. var url = data.url;
  21925. $http({
  21926. method: 'get',
  21927. dataType: 'json',
  21928. url: url + '/inquiry/buyer/detail',
  21929. params: {id: $stateParams.id, enuu: $scope.currentEn.uu}
  21930. }).success(function (response) {
  21931. $scope.newinquiryItems = response;
  21932. var inquiry = response;
  21933. angular.forEach(inquiry.attachs, function (attach) {
  21934. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21935. });
  21936. $scope.inquiry = inquiry;
  21937. });
  21938. });
  21939. });
  21940. $scope.getMinDate = function (item) {
  21941. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21942. };
  21943. $scope.replyPrices = [];
  21944. $scope.replylapQtys = [];
  21945. $scope.replyPrices.push(true);
  21946. $scope.replylapQtys.push(true);
  21947. $scope.getHistory = function (item) {
  21948. if (!item.history) {
  21949. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21950. item.history = data;
  21951. });
  21952. }
  21953. };
  21954. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21955. $scope.verify = function (value, type) {
  21956. var regex = /^\d+(.\d{1,6})?$/;//
  21957. switch (type) {
  21958. case 'minOrderQty':
  21959. $scope.minOrderQtyVerify = regex.test(value);
  21960. break;
  21961. case 'minPackQty':
  21962. $scope.minPackQtyVerify = regex.test(value);
  21963. break;
  21964. case 'leadtime':
  21965. $scope.leadtimeVerify = regex.test(value);
  21966. break;
  21967. default:
  21968. $scope.replyPrices[type] = regex.test(value);
  21969. break;
  21970. }
  21971. }
  21972. // 采纳
  21973. $scope.accept = function (id) {
  21974. publicInquiry.accept({id: id}, {}, function (data) {
  21975. if (data.success) {
  21976. toaster.pop('success', '提示', data.success);
  21977. loadData();
  21978. }
  21979. if (data.error) {
  21980. toaster.pop('error', '提示', data.error);
  21981. }
  21982. }, function (response) {
  21983. toaster.pop('error', '提示', response.data);
  21984. })
  21985. };
  21986. // 拒绝
  21987. $scope.refuse = function (id) {
  21988. publicInquiry.refuse({id: id}, {}, function (data) {
  21989. if (data.success) {
  21990. toaster.pop('success', '提示', data.success);
  21991. loadData();
  21992. }
  21993. if (data.error) {
  21994. toaster.pop('error', '提示', data.error);
  21995. }
  21996. }, function (response) {
  21997. toaster.pop('error', '提示', response.data);
  21998. })
  21999. }
  22000. }]);
  22001. /**
  22002. * 公共询价模态框(供应商报价)
  22003. */
  22004. app.controller('QuoteInquiryCtrl', ['$scope', '$stateParams', 'toaster', 'inquiryItem', '$modalInstance', '$upload', function ($scope, $stateParams, toaster, inquiryItem, $modalInstance, $upload) {
  22005. $scope.inquiryItem = inquiryItem;
  22006. $scope.replyPrices = [];
  22007. $scope.replylapQtys = [];
  22008. $scope.replyPrices.push(true);
  22009. $scope.replylapQtys.push(true);
  22010. // 增加一列分段报价
  22011. $scope.addStep = function (inquiryItem) {
  22012. $scope.replyPrices.push(true);
  22013. if (inquiryItem.replies.length >= 5) {
  22014. toaster.pop('warning', '提示', '最多支持5个分段!');
  22015. } else {
  22016. inquiryItem.replies.push({});
  22017. if (inquiryItem.replies.length != 1) {
  22018. $scope.replyPrices.push(true);
  22019. $scope.replylapQtys.push(true);
  22020. }
  22021. }
  22022. };
  22023. // 删除一列分段报价
  22024. $scope.removeStep = function (inquiryItem, stepIndex) {
  22025. inquiryItem.replies.splice(stepIndex, 1);
  22026. $scope.replyPrices.splice(stepIndex, 1);
  22027. $scope.replylapQtys.splice(stepIndex, 1);
  22028. };
  22029. // 取消,关闭弹出框
  22030. $scope.cancel = function() {
  22031. $modalInstance.dismiss();
  22032. }
  22033. // 保存报价信息
  22034. $scope.save = function(inquiryItem, method) {
  22035. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  22036. $upload.upload({
  22037. url: 'pubInquiry/turnToQuotation',
  22038. file: file,
  22039. method: 'POST',
  22040. data: {
  22041. item: inquiryItem,
  22042. method: method
  22043. }
  22044. }).success(function (data) {
  22045. if (data.item) {
  22046. item = data.item;
  22047. }
  22048. $scope.loading = false;
  22049. toaster.pop('info', '提示', '报价成功');
  22050. $scope.tableParams.reload();
  22051. }).error(function (data) {
  22052. $scope.loading = false;
  22053. toaster.pop('error', '报价失败');
  22054. });
  22055. }
  22056. }]);
  22057. /**
  22058. * 首页侧边栏询价列表
  22059. */
  22060. app.controller('InquiryMessageListCtrl', ['$scope', 'publicInquiry', 'AccountEnterprise', '$http', function($scope, publicInquiry, AccountEnterprise, $http) {
  22061. AccountEnterprise.get({}, function(data) {
  22062. $scope.currentEn = data;
  22063. publicInquiry.getUrl({}, function (data) {
  22064. var url = data.url;
  22065. $http({
  22066. method: 'get',
  22067. url: url + '/inquiry/public/messageList',
  22068. params: {enuu: $scope.currentEn.uu, size: 7},
  22069. dataType: 'json'
  22070. }).success(function(data) {
  22071. $scope.message = data;
  22072. }).error(function(error) {
  22073. });
  22074. });
  22075. });
  22076. }]);
  22077. /**
  22078. * 针对卖家,询价推荐列表
  22079. */
  22080. app.controller('SaleInquiryRemindCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', 'AuthenticationService', function ($scope, $filter, ngTableParams, toaster, BaseService, publicInquiry, $modal, AccountEnterprise, $http, AuthenticationService) {
  22081. BaseService.scrollBackToTop();
  22082. $scope.agreedText = '全部';
  22083. $scope.dateZoneText = '最近一个月';
  22084. $scope.condition = {dateZone: 1};
  22085. /* 时间筛选初始化*/
  22086. var fromDate = new Date();
  22087. var toDate = new Date();
  22088. fromDate.setMonth(fromDate.getMonth() - 1);
  22089. fromDate.setHours(0, 0, 0, 0);
  22090. toDate.setHours(23, 59, 59, 999);
  22091. $scope.condition.dateFrom = fromDate;
  22092. $scope.condition.dateTo = toDate;
  22093. $scope.changeDateZone = function (zone) {
  22094. $scope.condition.dateZone = zone;
  22095. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  22096. $scope.condition.$dateZoneOpen = false;
  22097. getDateCondition(zone, $scope.condition);
  22098. $scope.tableParams.page(1);
  22099. $scope.tableParams.reload();
  22100. };
  22101. $scope.tableParams = new ngTableParams({
  22102. page: 1,
  22103. count: 20,
  22104. sorting: {
  22105. 'date': 'desc'
  22106. }
  22107. }, {
  22108. total: 0,
  22109. counts: [5, 10, 25, 50],
  22110. getData: function ($defer, params) {
  22111. $scope.loading = true;
  22112. var pageParams = params.url();
  22113. var realActive = {};
  22114. pageParams.searchFilter = { // 筛选条件
  22115. keyword: $scope.keyword,
  22116. fromDate: getDateTime($scope.condition.dateFrom),
  22117. endDate: getDateTime($scope.condition.dateTo)
  22118. };
  22119. if ($scope.active == 'overdue') {
  22120. $scope.active = 'end';
  22121. }
  22122. AccountEnterprise.get({}, function(data) {
  22123. $scope.currentEn = data;
  22124. publicInquiry.getUrl({}, function(data) {
  22125. $scope.url = data.url;
  22126. AuthenticationService.getAuthentication().success(function (data) {
  22127. $scope.loading = false;
  22128. $scope.thisUser = data;
  22129. $http({
  22130. method: 'get',
  22131. dataType: 'json',
  22132. url: $scope.url + '/inquiry/sale/remind',
  22133. params: {pageNumber: pageParams.page, pageSize: pageParams.count, useruu: $scope.thisUser.userUU, enuu: $scope.currentEn.uu,
  22134. keyword: $scope.keyword, fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)}
  22135. }).success(function (response) {
  22136. $scope.loading = false;
  22137. if (response) {
  22138. params.total(response.totalElements);
  22139. $defer.resolve(response.content);
  22140. }
  22141. }).error(function (err) {
  22142. $scope.loading = false;
  22143. toaster.pop('error', '数据加载失败', err);
  22144. });
  22145. });
  22146. });
  22147. });
  22148. }
  22149. });
  22150. $scope.getMinDate = function (item) {
  22151. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  22152. };
  22153. $scope.openDatePicker = function ($event, item, openParam) {
  22154. $event.preventDefault();
  22155. $event.stopPropagation();
  22156. item[openParam] = !item[openParam];
  22157. };
  22158. $scope.openFilterDatePicker = function ($event, item, openParam) {
  22159. $event.preventDefault();
  22160. $event.stopPropagation();
  22161. item[openParam] = !item[openParam];
  22162. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  22163. $scope.tableParams.reload();
  22164. }
  22165. };
  22166. // 搜索框回车
  22167. $scope.onSearch = function (keyword) {
  22168. // 每次搜索重置获取数据方法
  22169. $scope.searchMethod = false;
  22170. if(keyword != null && keyword != '') {
  22171. $scope.searchMethod = true;
  22172. }
  22173. $scope.tableParams.page(1);
  22174. $scope.tableParams.reload();
  22175. };
  22176. // 取消
  22177. $scope.cancel = function () {
  22178. $scope.tableParams.reload();
  22179. }
  22180. // 转客户询价
  22181. $scope.qute = function (remind) {
  22182. $http({
  22183. method: 'get',
  22184. dataType: 'json',
  22185. url: $scope.url + '/inquiry/sale/quote',
  22186. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  22187. }).success(function (response) {
  22188. $scope.loading = false;
  22189. if (response.inquiry != null) {
  22190. toaster.pop('error', '该单据已报价');
  22191. } else {
  22192. $http({
  22193. method: 'get',
  22194. dataType: 'json',
  22195. url: $scope.url + '/inquiry/public/findItemByItemId',
  22196. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  22197. }).success(function (response) {
  22198. var inquiryItem = response;
  22199. var modalInstance = $modal.open({
  22200. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  22201. controller: 'QuoteCtrl',
  22202. size: 'lg',
  22203. resolve: {
  22204. inquiryItem: function () {
  22205. return inquiryItem
  22206. }
  22207. }
  22208. });
  22209. modalInstance.result.then(function (data) {
  22210. $scope.tableParams.reload();
  22211. }, function () {
  22212. });
  22213. }).error(function (error) {
  22214. toaster.pop('error', '数据加载失败', error);
  22215. });
  22216. }
  22217. }).error(function (err) {
  22218. toaster.pop('error', '数据加载失败', err);
  22219. });
  22220. }
  22221. // 跳转详情
  22222. $scope.toDetail = function(remind) {
  22223. if (remind.newId == null) {
  22224. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  22225. } else {
  22226. window.open("#/sale/pubinquiry/" + remind.newId);
  22227. }
  22228. }
  22229. }]);
  22230. /**
  22231. * 采购变更单列表
  22232. *
  22233. * @author hejq
  22234. * @date 2018-06-25 17:13
  22235. */
  22236. app.controller('PurcChangeListCtrl', ['$scope', '$filter', 'change', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, change, ngTableParams, toaster, BaseService, CurrentRole) {
  22237. BaseService.scrollBackToTop();
  22238. $scope.active = 'todo';
  22239. $scope.agreedText = '全部';
  22240. $scope.dateZoneText = '一个月内';
  22241. $scope.condition = {dateZone: 1};
  22242. /* 时间筛选初始化*/
  22243. var fromDate = new Date();
  22244. var toDate = new Date();
  22245. fromDate.setMonth(fromDate.getMonth() - 1);
  22246. fromDate.setHours(0, 0, 0, 0);
  22247. toDate.setHours(23, 59, 59, 999);
  22248. $scope.condition.dateFrom = fromDate;
  22249. $scope.condition.dateTo = toDate;
  22250. $scope.changeAgreed = function (agreed) {
  22251. $scope.condition.agreed = agreed;
  22252. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  22253. $scope.condition.$agreedOpen = false;
  22254. };
  22255. $scope.changeDateZone = function (zone) {
  22256. $scope.condition.dateZone = zone;
  22257. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  22258. $scope.condition.$dateZoneOpen = false;
  22259. getDateCondition(zone, $scope.condition);
  22260. $scope.tableParams.page(1);
  22261. $scope.tableParams.reload();
  22262. };
  22263. $scope.setActive = function (state) {
  22264. if ($scope.active != state) {
  22265. $scope.active = state;
  22266. if ($scope.tableParams.page() == 1)
  22267. $scope.tableParams.reload();
  22268. else
  22269. $scope.tableParams.page(1);
  22270. }
  22271. };
  22272. var getService = function () {
  22273. return change;
  22274. };
  22275. $scope.tableParams = new ngTableParams({
  22276. page: 1,
  22277. count: 20,
  22278. sorting: {
  22279. date: 'desc'
  22280. }
  22281. }, {
  22282. total: 0,
  22283. counts: [5, 10, 25, 50],
  22284. getData: function ($defer, params) {
  22285. $scope.loading = true;
  22286. var pageParams = params.url();
  22287. pageParams.searchFilter = {
  22288. keyword: $scope.keyword,
  22289. fromDate: getDateTime($scope.condition.dateFrom),
  22290. endDate: getDateTime($scope.condition.dateTo)
  22291. };
  22292. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  22293. $scope.loading = false;
  22294. if (page) {
  22295. params.total(page.totalElement);
  22296. $defer.resolve(page.content);
  22297. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  22298. }
  22299. }, function (response) {
  22300. $scope.loading = false;
  22301. toaster.pop('error', '数据加载失败', response.data);
  22302. });
  22303. }
  22304. });
  22305. $scope.openDatePicker = function ($event, item, openParam) {
  22306. $event.preventDefault();
  22307. $event.stopPropagation();
  22308. item[openParam] = !item[openParam];
  22309. };
  22310. $scope.openFilterDatePicker = function ($event, item, openParam) {
  22311. $event.preventDefault();
  22312. $event.stopPropagation();
  22313. item[openParam] = !item[openParam];
  22314. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  22315. $scope.tableParams.reload();
  22316. }
  22317. };
  22318. // 搜索框回车
  22319. $scope.onSearch = function (keyword) {
  22320. $scope.tableParams.page(1);
  22321. $scope.tableParams.reload();
  22322. };
  22323. // 导出
  22324. $scope.exportXls = function () {
  22325. change.exportXls({}, {}, function (data) {
  22326. if (data.success){
  22327. window.location.href = 'purc/change/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  22328. }
  22329. }, function (response) {
  22330. toaster.pop('error', '数据加载失败', response.data);
  22331. });
  22332. }
  22333. }]);
  22334. /**
  22335. * 新增采购变更单
  22336. *
  22337. * @author hejq
  22338. * @date 2018-06-25 16:38
  22339. */
  22340. app.controller('PurcChangeNewCtrl', ['$scope', 'toaster', 'BaseService', 'AuthenticationService', '$modal', '$filter', 'change',
  22341. function ($scope, toaster, BaseService, AuthenticationService, $modal, $filter, change) {
  22342. // 获取登录人员信息
  22343. AuthenticationService.getAuthentication().success(function (data) {
  22344. $scope.user = data;
  22345. initChange();
  22346. });
  22347. // 初始化变更单信息
  22348. var initChange = function () {
  22349. $scope.change = {
  22350. date: new Date(),
  22351. recorder: $scope.user.userName,
  22352. orderCode: null,
  22353. code: 'B2BPC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  22354. orderId: null,
  22355. orderChangeItems: []
  22356. }
  22357. }
  22358. $scope.getEnableOrders = function() {
  22359. initChange();
  22360. var modalInstance = $modal.open({
  22361. animation: true,
  22362. size: 'lg',
  22363. templateUrl: 'static/tpl/index/purc/modal/enableOrderList.html',
  22364. controller: 'EnableChangeListCtrl',
  22365. resolve: {
  22366. }
  22367. });
  22368. modalInstance.result.then(function (data) {
  22369. $scope.change.orderCode = data.code;
  22370. $scope.change.orderId = data.id;
  22371. $scope.orderItems = data.orderItems;
  22372. $scope.change.oldCurrency = data.currency;
  22373. $scope.change.oldPayments = data.payments;
  22374. $scope.change.oldRate = data.rate;
  22375. $scope.change.vendUU = data.vendUU;
  22376. $scope.change.apVendorName = data.receiveName;
  22377. $scope.change.vendUserUU = data.vendUserUU;
  22378. $scope.change.newCurrency = data.currency != null ? data.currency :null;
  22379. $scope.change.newPayments = data.payments != null ? data.payments :null;
  22380. angular.forEach($scope.orderItems, function (item, index) {
  22381. $scope.change.orderChangeItems.push({
  22382. oldProductId: item.productId,
  22383. orderItemId: item.id,
  22384. orderItemNumber: item.number,
  22385. oldQty: item.qty,
  22386. oldPrice: item.price,
  22387. oldTaxrate: item.taxrate,
  22388. oldDelivery: item.delivery,
  22389. newQty: item.qty != null ? item.qty :null,
  22390. newPrice: item.price != null ? item.price :null,
  22391. newTaxrate: item.taxrate != null ? item.taxrate :null,
  22392. newDelivery: item.delivery != null ? item.delivery :null,
  22393. oldProduct: item.product,
  22394. number: index + 1
  22395. });
  22396. });
  22397. });
  22398. }
  22399. // 删除明细
  22400. $scope.del = function (index) {
  22401. $scope.change.orderChangeItems.splice(index, 1);
  22402. }
  22403. $scope.getMinDate = function () {
  22404. return $filter('date')(new Date, 'yyyy-MM-dd');
  22405. };
  22406. $scope.openDatePicker = function ($event, openParam, index) {
  22407. $event.preventDefault();
  22408. $event.stopPropagation();
  22409. $scope.change.orderChangeItems[index].$dateOpen = !openParam;
  22410. };
  22411. $scope.save = function() {
  22412. if ($scope.change.unNeedReply == null) {
  22413. toaster.pop('error', '请选择是否需要供应商确认');
  22414. } else if ($scope.change.orderChangeItems.length == 0) {
  22415. toaster.pop('error', '请至少选择一条采购明细')
  22416. } else {
  22417. change.save({}, $scope.change, function (data) {
  22418. window.location.hash = "/purc/change/" + data.id;
  22419. toaster.pop('success', '采购变更单保存成功');
  22420. }, function(res) {
  22421. toaster.pop('error','请输入正确的信息')
  22422. });
  22423. }
  22424. }
  22425. }]);
  22426. /**
  22427. * 获取可以作为采购变更单的采购单
  22428. *
  22429. * @author hejq
  22430. * @date 2018-06-25 18:41
  22431. */
  22432. app.controller('EnableChangeListCtrl', ['$scope', 'change', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance',
  22433. function ($scope, change, BaseService, ngTableParams, toaster, $modalInstance) {
  22434. $scope.dateZoneText = '一个月内';
  22435. $scope.condition = {dateZone: 1};
  22436. /* 时间筛选初始化*/
  22437. var fromDate = new Date();
  22438. var toDate = new Date();
  22439. fromDate.setMonth(fromDate.getMonth() - 1);
  22440. fromDate.setHours(0, 0, 0, 0);
  22441. toDate.setHours(23, 59, 59, 999);
  22442. $scope.condition.dateFrom = fromDate;
  22443. $scope.condition.dateTo = toDate;
  22444. $scope.changeDateZone = function (zone) {
  22445. $scope.condition.dateZone = zone;
  22446. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  22447. $scope.condition.$dateZoneOpen = false;
  22448. getDateCondition(zone, $scope.condition);
  22449. $scope.tableParams.page(1);
  22450. $scope.tableParams.reload();
  22451. };
  22452. $scope.openFilterDatePicker = function ($event, item, openParam) {
  22453. $event.preventDefault();
  22454. $event.stopPropagation();
  22455. item[openParam] = !item[openParam];
  22456. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  22457. $scope.tableParams.reload();
  22458. }
  22459. };
  22460. $scope.tableParams = new ngTableParams({
  22461. page: 1,
  22462. count: 5,
  22463. sorting: {
  22464. 'id': 'desc'
  22465. }
  22466. }, {
  22467. total: 0,
  22468. counts: [],
  22469. getData: function ($defer, params) {
  22470. $scope.loading = true;
  22471. var pageParams = params.url();
  22472. pageParams.searchFilter = { // 筛选条件
  22473. keyword: $scope.keyword,
  22474. fromDate: getDateTime($scope.condition.dateFrom),
  22475. endDate: getDateTime($scope.condition.dateTo)
  22476. };
  22477. change.getEnableOrderList.call(null, BaseService.parseParams(pageParams), function (page) {
  22478. $scope.loading = false;
  22479. if (page) {
  22480. params.total(page.totalElement);
  22481. $defer.resolve(page.content);
  22482. }
  22483. }, function (response) {
  22484. $scope.loading = false;
  22485. toaster.pop('error', '数据加载失败', response.data);
  22486. });
  22487. }
  22488. });
  22489. $scope.checkedOrder = null;
  22490. var checkItems = [];
  22491. // 单选
  22492. $scope.checkOne = function (order) {
  22493. var changeflag = false;
  22494. order.checked = !order.checked;
  22495. if ((order.checked) && ($scope.checkedOrder != null) && ($scope.checkedOrder != order)) {
  22496. $scope.checkedOrder.checked = false;
  22497. angular.forEach($scope.checkedOrder.orderItems, function (item) {
  22498. item.checked = false;
  22499. });
  22500. $scope.checkedOrder = null;
  22501. checkItems = [];
  22502. }
  22503. if (order.checked) {
  22504. $scope.checkedOrder = order;
  22505. angular.forEach(order.orderItems, function (item) {
  22506. if (item.change) {
  22507. item.checked = false;
  22508. changeflag = true;
  22509. } else {
  22510. item.checked = true;
  22511. checkItems.push(item);
  22512. }
  22513. });
  22514. } else {
  22515. $scope.checkedOrder = null;
  22516. angular.forEach(order.orderItems, function (item) {
  22517. item.checked = false;
  22518. });
  22519. checkItems = [];
  22520. }
  22521. if (checkItems.length == 0 && changeflag) {
  22522. order.checked =false;
  22523. toaster.pop('warning', '提示', "该采购单所有明细正在变更中,在供应商确认之前不可再次变更");
  22524. }
  22525. };
  22526. // 明细
  22527. $scope.checkItem = function (item, order) {
  22528. // 先判断选中信息
  22529. if (item.change) {
  22530. toaster.pop('warning', '提示', "该明细正在变更中,在供应商确认之前不可再次变更");
  22531. item.checked = null;
  22532. return;
  22533. }
  22534. order.checked = true;
  22535. if ($scope.checkedOrder != null && order.id != $scope.checkedOrder.id) {
  22536. $scope.checkedOrder.checked = false;
  22537. $scope.checkedOrder = order;
  22538. order.checked = true;
  22539. angular.forEach(checkItems, function (checkItem) {
  22540. checkItem.checked = false;
  22541. });
  22542. checkItems = [];
  22543. }
  22544. item.checked = !item.checked;
  22545. if (item.checked) {
  22546. checkItems.push(item);
  22547. if ($scope.checkedOrder == null) {
  22548. $scope.checkedOrder = order;
  22549. }
  22550. order.checked = true;
  22551. } else {
  22552. angular.forEach(checkItems, function (checkItem, index) {
  22553. if (checkItem.id == item.id) {
  22554. checkItems.splice(index, 1);
  22555. }
  22556. });
  22557. }
  22558. if (checkItems.length == 0) {
  22559. $scope.checkedOrder = null;
  22560. order.checked = false;
  22561. }
  22562. };
  22563. // 搜索框回车
  22564. $scope.onSearch = function (keyword) {
  22565. $scope.tableParams.page(1);
  22566. $scope.tableParams.reload();
  22567. };
  22568. $scope.getCartTotal = function (items) {
  22569. var sum = 0;
  22570. angular.forEach(items, function (item) {
  22571. sum += item.qty * item.price;
  22572. });
  22573. return sum;
  22574. };
  22575. // 选择
  22576. $scope.choose = function () {
  22577. if ($scope.checkedOrder == null || checkItems.length == 0) {
  22578. toaster.pop('error', '请先选择采购单信息');
  22579. } else {
  22580. $scope.checkedOrder.orderItems = checkItems;
  22581. $modalInstance.close($scope.checkedOrder);
  22582. }
  22583. }
  22584. // 关闭
  22585. $scope.close = function () {
  22586. $modalInstance.dismiss();
  22587. };
  22588. }]);
  22589. /**
  22590. * 采购变更单详情
  22591. */
  22592. app.controller('PurcChangeDetailCtrl', ['$scope', '$stateParams', 'change', 'toaster', 'CurrentRole',
  22593. function ($scope, $stateParams, change, toaster, CurrentRole) {
  22594. // 获取当前用户是否为普通用户
  22595. CurrentRole.isUser({}, {}, function (data) {
  22596. $scope.isUser = data.isUser;
  22597. });
  22598. var loadData = function () {
  22599. change.getItem({id: $stateParams.id}, function (data) {
  22600. $scope.change = data;
  22601. }, function (response) {
  22602. toaster.pop('error', '', response.data);
  22603. });
  22604. };
  22605. loadData();
  22606. $scope.openDatePicker = function ($event, item, openParam) {
  22607. $event.preventDefault();
  22608. $event.stopPropagation();
  22609. item[openParam] = !item[openParam];
  22610. };
  22611. }]);
  22612. /**
  22613. * B2C搜索
  22614. */
  22615. app.controller('SearchCtrl', ['$scope', '$http', '$rootScope', 'SessionService', 'AccountEnterprise', function($scope, $http, $rootScope, SessionService, AccountEnterprise) {
  22616. // 默认搜索类型
  22617. $scope.searchType = 'component';
  22618. // 选搜索类型
  22619. $scope.setTypeClick = function (type) {
  22620. $scope.searchType = type
  22621. $scope.search()
  22622. };
  22623. // 搜索
  22624. $scope.search = function() {
  22625. if($scope.keyword) {
  22626. SessionService.set('brand', true);
  22627. SessionService.unset('component');
  22628. AccountEnterprise.getB2cUrl({}, function(data) {
  22629. window.location.href = data.url + '/search?w=' + encodeURI($scope.keyword) + '&type=' + $scope.searchType;
  22630. });
  22631. }
  22632. };
  22633. // 搜索框获得焦点,显示联想框
  22634. $scope.onFocus = function() {
  22635. $scope.associate = true;
  22636. $scope.selectIndex = -1;
  22637. if(!$scope.keyword) $scope.keyword = '';
  22638. };
  22639. // 搜索框失去焦点,关闭联想框
  22640. $scope.onBlur = function() {
  22641. $scope.associate = false;
  22642. };
  22643. // 搜索框通过按键选取想要的联想词
  22644. $scope.onKeyup = function() {
  22645. if($scope.associates && $scope.associates.length) {
  22646. if(event.keyCode == 40) { //监听到按下键
  22647. $scope.selectIndex ++;
  22648. if($scope.selectIndex >= $scope.associates.length) $scope.selectIndex = 0;
  22649. $scope.keyword = $scope.associates[$scope.selectIndex];
  22650. } else if(event.keyCode == 38) { //监听到按上键
  22651. $scope.selectIndex --;
  22652. if($scope.selectIndex < 0) $scope.selectIndex = $scope.associates.length - 1;
  22653. $scope.keyword = $scope.keyword = $scope.associates[$scope.selectIndex];
  22654. } else if(event.keyCode == 13) { //确定键
  22655. $scope.search();
  22656. }
  22657. }
  22658. };
  22659. // 输入框内容变化,获取新的联想词
  22660. $scope.onChange = function() {
  22661. if ($scope.keyword) {
  22662. var params = {
  22663. keyword: $scope.keyword,
  22664. type: $scope.searchType
  22665. };
  22666. AccountEnterprise.getB2cUrl({}, function(data) {
  22667. $http.get(data.url + '/search/similarKeywords', {
  22668. params : params
  22669. }).success(function(data){
  22670. $scope.associates = data;// 联想词数组
  22671. }).error(function(response) {
  22672. console.log(response)
  22673. });
  22674. })
  22675. } else {
  22676. $scope.associates = [];// 联想词数组
  22677. }
  22678. };
  22679. // 点击联想词
  22680. $scope.onAssociateClick = function(component) {
  22681. $scope.keyword = component;
  22682. $scope.search();
  22683. };
  22684. // 鼠标进入联想词框,不能关闭联想词框
  22685. $scope.onAssociateEnter = function() {
  22686. $scope.associateEnter = true;
  22687. };
  22688. // 鼠标离开联想词框,可以关闭联想词框
  22689. $scope.onAssociateLeave = function() {
  22690. $scope.associateEnter = false;
  22691. };
  22692. // 热词
  22693. $scope.hotwords = [{name : 'SCT2080KEC', url : 'product/component/1100400300009990/', id : 0},
  22694. {name : '电池组', url : 'product/kinds/346', id : 1},
  22695. {name : 'Vishay',url : 'product/brand/30327265e42a871be050007f01003d96/', id : 2},
  22696. {name : 'Panasonic Battery', url : 'product/brand/30327265e4e7871be050007f01003d96/', id : 3}];
  22697. // 热门搜索跳转
  22698. angular.forEach($scope.hotwords, function (value, key) {
  22699. AccountEnterprise.getB2cUrl({}, function(data) {
  22700. $scope.hotwords[key].url = data.url + '/' + value.url
  22701. })
  22702. })
  22703. // 跳转到B2C
  22704. $scope.b2cLink = function (url) {
  22705. AccountEnterprise.getB2cUrl({}, function(data) {
  22706. window.location.href = data.url + url;
  22707. });
  22708. }
  22709. }]);
  22710. /**
  22711. * 树结构
  22712. */
  22713. app.controller('treeController', function($scope, $location){
  22714. $scope.roleList = [
  22715. { "roleName" : "卖家中心(销售)", "roleId" : "role1", 'path': 'sale', level: 0, collapsed: true, "children" : [
  22716. { "roleName" : "商务管理", "roleId" : "role1-1", collapsed: true, "children" : [
  22717. { "roleName" : "客户采购询价", "roleId" : "role1-1-1", 'link' : '#/sale/inquiry', "children" : [] },
  22718. { "roleName" : "客户公共询价", "roleId" : "role1-1-2", 'link' : '#/sale/pubinquiry', "children" : [] },
  22719. { "roleName" : "客户模具询价", "roleId" : "role1-1-3", 'link' : '#/sale/mould', "children" : [] },
  22720. { "roleName" : "主动报价", "roleId" : "role1-1-4", 'link' : '#/sale/quotation/list', "children" : [] },
  22721. { "roleName" : "客户招标", "roleId" : "role1-1-5", 'link' : '#/sale/tender', "children" : [] }
  22722. ] },
  22723. { "roleName" : "订单管理", "roleId" : "role1-2", collapsed: true, "children" : [
  22724. { "roleName" : "客户采购订单", "roleId" : "role1-2-1", 'link' : '#/sale/order', "children" : [] },
  22725. { "roleName" : "客户采购变更单", "roleId" : "role1-2-2", 'link' : '#/sale/change', "children" : [] },
  22726. { "roleName" : "客户委外单", "roleId" : "role1-2-3", 'link' : '#/sale/maketodo/makeorder', "children" : [] },
  22727. { "roleName" : "委外变更单", "roleId" : "role1-2-4", 'link' : '#/sale/makechange', "children" : [] },
  22728. { "roleName" : "客户发货提醒", "roleId" : "role1-2-5", 'link' : '#/sale/notice', "children" : [] },
  22729. { "roleName" : "发货单", "roleId" : "role1-2-6", 'link' : '#/sale/send', "children" : [] }
  22730. ]},
  22731. { "roleName" : "客户出入库", "roleId" : "role1-3", collapsed: true, "children" : [
  22732. { "roleName" : "MRB单", "roleId" : "role1211", 'link' : '#/sale/MRB', "children" : [] },
  22733. { "roleName" : "不良品出库单", "roleId" : "role1-3-1", 'link' : '#/sale/badOut', "children" : [] },
  22734. { "roleName" : "不良品入库单", "roleId" : "role1-3-2", 'link' : '#/sale/badIn', "children" : [] },
  22735. { "roleName" : "客户采购验收单", "roleId" : "role1-3-3", 'link' : '#/sale/accept', "children" : [] },
  22736. { "roleName" : "客户采购验退单", "roleId" : "role1-3-4", 'link' : '#/sale/returns', "children" : [] },
  22737. { "roleName" : "客户委外验收单", "roleId" : "role1-3-5", 'link' : '#/sale/makeaccept', "children" : [] },
  22738. { "roleName" : "客户委外验退单", "roleId" : "role1-3-6", 'link' : '#/sale/makereturns', "children" : [] }
  22739. ] },
  22740. { "roleName" : "样品管理", "roleId" : "role1-4", collapsed: true, "children" : [
  22741. { "roleName" : "客户打样申请", "roleId" : "role1-4-1", 'link' : '#/sale/sample', "children" : [] },
  22742. { "roleName" : "客户认定单", "roleId" : "role1-4-2", 'link' : '#/sale/approval', "children" : [] }
  22743. ] },
  22744. { "roleName" : "基础资料", "roleId" : "role1-5", collapsed: true, "children" : [
  22745. { "roleName" : "客户资料", "roleId" : "role1-5-1", 'link' : '#/sale/customer', "children" : [] },
  22746. { "roleName" : "绩效考核", "roleId" : "role1-5-2", 'link' : '#/sale/vendorPerformanceAssess', "children" : [] },
  22747. { "roleName" : "产品导入", "roleId" : "role1-5-3", 'link' : '#/sale/prodList', "children" : [] }
  22748. ] }
  22749. ]},
  22750. { "roleName" : "买家中心(采购)", "roleId" : "role2", 'path': 'purc', level: 0, collapsed: true, "children" : [
  22751. { "roleName" : "采购管理", "roleId" : "role2-1", collapsed: true, "children" : [
  22752. { "roleName" : "供应商资料", "roleId" : "role2-1-1", 'link' : '#/purc/vendor', "children" : [] },
  22753. { "roleName" : "供应商服务", "roleId" : "role2-1-2", 'link' : '#/purc/vendor/serve', "children" : [] },
  22754. { "roleName" : "采购物料", "roleId" : "role2-1-3", 'link' : '#/purc/product', "children" : [] },
  22755. { "roleName" : "采购招标", "roleId" : "role2-1-4", 'link' : '#/purc/tender', "children" : [] },
  22756. { "roleName" : "采购询价", "roleId" : "role2-1-5", 'link' : '#/purc/purchaseinquiry', "children" : [] },
  22757. { "roleName" : "公共询价", "roleId" : "role2-1-6", 'link' : '#/purc/publicInquiry', "children" : [] },
  22758. { "roleName" : "采购订单", "roleId" : "role2-1-7", 'link' : '#/purc/order', "children" : [] },
  22759. { "roleName" : "采购变更单", "roleId" : "role2-1-8", 'link' : '#/purc/change', "children" : [] },
  22760. { "roleName" : "代采订单", "roleId" : "role2-1-9", 'link' : '#/purc/deputy', "children" : [] },
  22761. { "roleName" : "委外订单", "roleId" : "role2-1-10", 'link' : '#/purc/makeoutorder', "children" : [] }
  22762. ] }
  22763. ]},
  22764. { "roleName" : "财务", "roleId" : "role3", 'path': 'fa', level: 0, collapsed: true, "children" : [
  22765. { "roleName" : "应收", "roleId" : "role3-1", collapsed: true, "children" : [
  22766. { "roleName" : "发票", "roleId" : "role3-1-1", 'link' : '#/fa/apBill', "children" : [] },
  22767. { "roleName" : "应收对账单", "roleId" : "role3-1-2", 'link' : '#/fa/apCheck', "children" : [] }
  22768. ] },
  22769. { "roleName" : "应付", "roleId" : "role3-2", collapsed: true, "children" : [
  22770. { "roleName" : "应付对账单", "roleId" : "role3-2-1", 'link' : '#/fa/arCheck', "children" : [] }
  22771. ]}
  22772. ]},
  22773. { "roleName" : "企业圈", "roleId" : "role4", 'link' : '#/baseInfo/enterpriseList', level: 0, "children" : [
  22774. ]},
  22775. { "roleName" : "基础设置", "roleId" : "role5", 'path': 'approvalFlow', collapsed: true, level: 0, "children" : [
  22776. { "roleName" : "企业设置", "roleId" : "role5-1", collapsed: true, "children" : [
  22777. { "roleName" : "企业信息", "roleId" : "role5-1-1", 'link' : '#/approvalFlow/enterprise', "children" : [] },
  22778. { "roleName" : "物料信息", "roleId" : "role5-1-2", 'link' : '#/approvalFlow/product', "children" : [] },
  22779. { "roleName" : "我的产品库", "roleId" : "role5-1-3", 'link' : '#/approvalFlow/userProduct', "children" : [] },
  22780. { "roleName" : "人员信息", "roleId" : "role5-1-4", 'link' : '#/approvalFlow/user', "children" : [] },
  22781. { "roleName" : "角色权限", "roleId" : "role5-1-5", 'link' : '#/approvalFlow/role', "children" : [] },
  22782. { "roleName" : "审批流", "roleId" : "role5-1-6", 'link' : '#/approvalFlow/flow', "children" : [] },
  22783. { "roleName" : "操作日志", "roleId" : "role5-1-7", 'link' : '#/approvalFlow/log', "children" : [] }
  22784. ]}
  22785. ]}
  22786. ];
  22787. $scope.currentObj = {};
  22788. var hasChildrenObj = function (target) {
  22789. var flag = false;
  22790. if ($scope.currentObj.roleId && target && target.children) {
  22791. angular.forEach(target.children, function (item) {
  22792. if (item.roleId == $scope.currentObj.roleId) {
  22793. flag = true;
  22794. }
  22795. if (item.children.length && hasChildrenObj(item)) {
  22796. flag = true;
  22797. }
  22798. });
  22799. }
  22800. return flag;
  22801. }
  22802. var roopCall = function (arr, callBack) {
  22803. angular.forEach(arr, function (item) {
  22804. if (item.children && item.children.length) {
  22805. roopCall(item.children, callBack);
  22806. }
  22807. callBack(item);
  22808. })
  22809. }
  22810. var initObj = function (arr, flag) {
  22811. angular.forEach(arr, function (item) {
  22812. if (flag) {
  22813. item.collapsed = false;
  22814. }
  22815. if (item.children && item.children.length) {
  22816. initObj(item.children, item.path && item.path == $location.$$path.split('/')[1]);
  22817. } else {
  22818. if (item.link && item.link.split('#')[1] == $location.$$path) {
  22819. item.selected = 'selected';
  22820. $scope.currentObj = item;
  22821. }
  22822. }
  22823. })
  22824. }
  22825. initObj($scope.roleList);
  22826. var initClose = function () {
  22827. roopCall($scope.roleList, function (item) {
  22828. item.collapsed = !hasChildrenObj(item);
  22829. })
  22830. }
  22831. initClose();
  22832. var closeRow = function (arr) {
  22833. angular.forEach(arr, function (item) {
  22834. item.selected = undefined;
  22835. if (item.children) {
  22836. closeRow(item.children);
  22837. }
  22838. })
  22839. }
  22840. $scope.$watch( 'myTree.currentNode', function( newObj, oldObj ) {
  22841. if( $scope.myTree && angular.isObject($scope.myTree.currentNode) ) {
  22842. $scope.currentObj = newObj;
  22843. if (newObj.link) {
  22844. window.location.href = newObj.link
  22845. }
  22846. closeRow($scope.roleList);
  22847. newObj.selected = 'selected';
  22848. roopCall($scope.roleList, function (item) {
  22849. // if ((!hasChildrenObj(item) && (item.roleId != $scope.currentObj.roleId))) {
  22850. // item.collapsed = true;
  22851. // }
  22852. // if ($scope.currentObj.roleId == item.roleId && item.children.length) {
  22853. // // angular.forEach(item.children, function (obj) {
  22854. // // obj.col
  22855. // // })
  22856. // item.collapsed = false;
  22857. // }
  22858. item.collapsed = !hasChildrenObj(item) && (item.roleId != $scope.currentObj.roleId);
  22859. })
  22860. }
  22861. }, false);
  22862. })
  22863. return app;
  22864. });