app.js 418 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553
  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'], 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']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config([ '$httpProvider', function($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function(response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url : "/index",
  26. views : {
  27. "left-view" : {
  28. templateUrl : "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view" : {
  32. templateUrl : "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url : "/",
  38. views : {
  39. "left-view" : {
  40. templateUrl : "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view" : {
  44. templateUrl : "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url : "/sale",
  50. views : {
  51. "left-view" : {
  52. templateUrl : "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view" : {
  56. templateUrl : "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url : "",
  65. templateUrl : "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url : "/",
  68. templateUrl : "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url : "/purc",
  71. views : {
  72. "left-view" : {
  73. templateUrl : "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view" : {
  77. templateUrl : "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url : "",
  86. templateUrl : "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url : "/",
  89. templateUrl : "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url : "/introduce",
  92. templateUrl : "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url : "/order",
  95. templateUrl : "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url : "/order/:id",
  99. templateUrl : "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url : "/addOrder",
  103. templateUrl : "static/tpl/index/purc/addOrder.html",
  104. controller : 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url : "/cart",
  107. templateUrl : "static/tpl/index/purc/cart.html",
  108. controller : 'CartController'
  109. }).state('purc.cartDetail', {
  110. url : "/cart/:id",
  111. templateUrl : "static/tpl/index/purc/cart_detail.html",
  112. controller : 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url : "/deputy",
  115. templateUrl : "static/tpl/index/purc/deputyOrder.html",
  116. controller : 'DeputyOrderCtrl'
  117. }).state('purc.newdeputy', {
  118. url : "/deputy/add",
  119. templateUrl : "static/tpl/index/purc/deputyOrder_new.html",
  120. controller : 'NewDeputyOrderCtrl'
  121. }).state('purc.deputydetail', {
  122. url : "/deputy/:id",
  123. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  124. controller : 'DeputyOrderDetailCtrl'
  125. /* 招标列表 */
  126. }).state('purc.tenderlist', {
  127. url : "/tender",
  128. templateUrl : "static/tpl/index/purc/tenderlist.html",
  129. controller : 'PurcTenderCtrl'
  130. }).state('purc.waiting.tenderlist', {
  131. url : "/tender",
  132. templateUrl : "static/tpl/index/purc/tenderlist.html",
  133. controller : 'PurcTenderCtrl'
  134. }).state('purc.todo.tenderlist', {
  135. url : "/tender/todo",
  136. templateUrl : "static/tpl/index/purc/tenderlist.html",
  137. controller : 'PurcTenderCtrl'
  138. /* 招标 */
  139. }).state('purc.tender', {
  140. url : "/addTender",
  141. templateUrl : "static/tpl/index/purc/tender.html",
  142. controller : 'PurcNewTenderCtrl'
  143. }).state('purc.savedtender', {
  144. url : "/tender/:id",
  145. templateUrl : "static/tpl/index/purc/saved_tender.html",
  146. controller : 'PurcNewTenderCtrl'
  147. /* 评标 */
  148. }).state('purc.evaluation', {
  149. url : "/evaluation/:id",
  150. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  151. controller : 'PurcEvaluationCtrl'
  152. /* 采购供应商资料 */
  153. }).state('purc.vendor', {
  154. url : "/vendor",
  155. templateUrl : "static/tpl/index/purc/vendor.html",
  156. controller : 'PurcVendorCtrl'
  157. /* 采购供应商资料 详情*/
  158. }).state('purc.vendordetail', {
  159. url : "/vendor/:id",
  160. templateUrl : "static/tpl/index/purc/vendor_detail.html",
  161. controller : 'PurcVendorDetailCtrl'
  162. /* 客户指定招标列表 */
  163. }).state('purc.makeoutorder', {
  164. url : "/makeoutorder",
  165. templateUrl : "static/tpl/index/make/outorder.html",
  166. controller: 'MakeOutOrderCtrl'
  167. }).state('purc.outorder_detail', {
  168. url : "/makeoutorder/:id",
  169. templateUrl : "static/tpl/index/make/outorder_detail.html",
  170. controller: 'MakeOutOrderDetailCtrl'
  171. /*平台新增询价单*/
  172. }).state('purc.inquiry_new', {
  173. url : "/purcinquiry",
  174. templateUrl : "static/tpl/index/purc/inquiry_new.html",
  175. controller: 'PurcInquiryCtrl'
  176. }).state('purc.inquiry', {
  177. url : "/purchaseinquiry",
  178. templateUrl : "static/tpl/index/purc/inquiry.html",
  179. controller: 'PurchaseInquiryCtrl'
  180. }).state('purc.inquiry_detail', {
  181. url : "/purcinquirydetail",
  182. templateUrl : "static/tpl/index/purc/inquiry_detail.html",
  183. controller: 'PurcInquiryDetailCtrl'
  184. }).state('purc.inquiryInfo_detail', {
  185. url : "/purcinquirydetail/:id",
  186. templateUrl : "static/tpl/index/purc/inquiryInfo_detail.html",
  187. controller: 'PurcInquiryInfoDetailCtrl'
  188. }).state('purc.inquiry_unapply', {
  189. url : "/inquiry_unapply",
  190. templateUrl : "static/tpl/index/purc/inquiry_unapply.html",
  191. controller: 'UnapplyInquiryCtrl'
  192. }).state('sale.tenderlist', {
  193. url : "/tender",
  194. templateUrl : "static/tpl/index/sale/tenderlist.html",
  195. controller : 'SaleTenderCtrl'
  196. }).state('sale.todo.tenderlist', {
  197. url : "/tender",
  198. templateUrl : "static/tpl/index/sale/tenderlist.html",
  199. controller : 'SaleTenderCtrl'
  200. /* 平台公开招标列表 */
  201. }).state('baseInfo.openTenderList', {
  202. url : "/openTenderList",
  203. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  204. controller: 'SaleOpenTenderCtrl'
  205. /* 查看公开招标详情 */
  206. }).state('baseInfo.open_tender_detail', {
  207. url : "/openTenderDetail/:id",
  208. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  209. controller : 'OpenSaleTenderDetailCtrl'
  210. /* 投标 */
  211. }).state('sale.tender', {
  212. url : "/tender/:id",
  213. templateUrl : "static/tpl/index/sale/tender.html",
  214. controller : 'SaleTenderDetailCtrl'
  215. /* 采购方查看供应商投标 */
  216. }).state('sale.vendortender', {
  217. url : "/tender/:vendUU/:id",
  218. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  219. controller : 'SaleVendorTenderDetailCtrl'
  220. }).state('sale.todo', {
  221. url : "/todo",
  222. templateUrl : "static/tpl/index/sale/todo.html"
  223. }).state('sale.todo.inquiry', {
  224. url : "/inquiry",
  225. templateUrl : "static/tpl/index/sale/inquiry.html",
  226. controller: 'SaleInquiryCtrl'
  227. }).state('sale.todo.order', {
  228. url : "/order",
  229. templateUrl : "static/tpl/index/sale/order.html",
  230. controller: 'SaleOrderCtrl'
  231. }).state('sale.todo.change', {
  232. url : "/change",
  233. templateUrl : "static/tpl/index/sale/change.html",
  234. controller: 'SaleChangeCtrl'
  235. }).state('sale.todo.notice', {
  236. url : "/notice",
  237. templateUrl : "static/tpl/index/sale/notice.html",
  238. controller: 'SaleNoticeCtrl'
  239. }).state('sale.customer', {
  240. url : "/customer",
  241. templateUrl : "static/tpl/index/sale/customer.html",
  242. controller: 'CustomerCtrl'
  243. }).state('sale.customer_detail', {
  244. url : "/customer/:id",
  245. templateUrl : "static/tpl/index/sale/customer_detail.html",
  246. controller: 'CustomerDetailCtrl'
  247. }).state('sale.customerProduct', {
  248. url : "/customerProduct",
  249. templateUrl : "static/tpl/index/sale/customer.html",
  250. controller: 'CustomerCtrl'
  251. }).state('sale.inquiry', {
  252. url : "/inquiry",
  253. templateUrl : "static/tpl/index/sale/inquiry.html",
  254. controller: 'SaleInquiryCtrl'
  255. }).state('sale.inquirymould', {
  256. url : "/mould",
  257. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  258. controller: 'SaleInquiryMouldCtrl'
  259. }).state('sale.todo.inquirymould', {
  260. url : "/mould",
  261. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  262. controller: 'SaleInquiryMouldCtrl'
  263. }).state('sale.inquiry_mould_detail', {
  264. url : "/mould/:id",
  265. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  266. controller: 'SaleInquiryMouldDetailCtrl'
  267. }).state('sale.inquiry_detail', {
  268. url : "/inquiry/:id",
  269. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  270. controller: 'SaleInquiryDetailCtrl'
  271. }).state('sale.quotation', {
  272. url : "/quotation",
  273. templateUrl : "static/tpl/index/sale/quotation.html"
  274. }).state('sale.quotation.new', {
  275. url : "/new",
  276. templateUrl : "static/tpl/index/sale/quotation_new.html",
  277. controller: 'SaleQuotationNewCtrl'
  278. }).state('sale.quotation.list', {
  279. url : "/list",
  280. templateUrl : "static/tpl/index/sale/quotation_list.html",
  281. controller: 'SaleQuotationListCtrl'
  282. }).state('sale.quotation.item', {
  283. url : "/:id",
  284. templateUrl : "static/tpl/index/sale/quotation_new.html",
  285. controller: 'SaleQuotationNewCtrl'
  286. }).state('sale.order', {
  287. url : "/order",
  288. templateUrl : "static/tpl/index/sale/order.html",
  289. controller: 'SaleOrderCtrl'
  290. }).state('sale.order_detail', {
  291. url : "/order/:id",
  292. templateUrl : "static/tpl/index/sale/order_detail.html",
  293. controller: 'SaleOrderDetailCtrl'
  294. }).state('sale.change', {
  295. url : "/change",
  296. templateUrl : "static/tpl/index/sale/change.html",
  297. controller: 'SaleChangeCtrl'
  298. }).state('sale.change_detail', {
  299. url : "/change/:id",
  300. templateUrl : "static/tpl/index/sale/change_detail.html",
  301. controller: 'SaleChangeDetailCtrl'
  302. }).state('sale.notice', {
  303. url : "/notice",
  304. templateUrl : "static/tpl/index/sale/notice.html",
  305. controller: 'SaleNoticeCtrl'
  306. }).state('sale.send', {
  307. url : "/send",
  308. templateUrl : "static/tpl/index/sale/send.html",
  309. controller: 'SaleSendCtrl'
  310. }).state('sale.send_detail', {
  311. url : "/send/:id",
  312. templateUrl : "static/tpl/index/sale/send_detail.html",
  313. controller: 'SaleSendDetailCtrl'
  314. }).state('sale.forecast', {
  315. url : "/forecast",
  316. templateUrl : "static/tpl/index/sale/forecast.html",
  317. controller: 'SaleForecastCtrl'
  318. }).state('sale.accept', {
  319. url : "/accept",
  320. templateUrl : "static/tpl/index/sale/accept.html",
  321. controller: 'SaleAcceptCtrl'
  322. }).state('sale.returns', {
  323. url : "/returns",
  324. templateUrl : "static/tpl/index/sale/returns.html",
  325. controller: 'SaleReturnsCtrl'
  326. }).state('sale.sample', {
  327. url : "/sample",
  328. templateUrl : "static/tpl/index/sale/sample.html",
  329. controller: 'SaleSampleCtrl'
  330. }).state('sale.sample_detail', {
  331. url : "/sample/:id",
  332. templateUrl : "static/tpl/index/sale/sample_detail.html",
  333. controller: 'SaleSampleDetailCtrl'
  334. }).state('sale.approval', {
  335. url : "/approval",
  336. templateUrl : "static/tpl/index/sale/approval.html",
  337. controller: 'SaleApprovalCtrl'
  338. }).state('sale.prodList', {
  339. url : "/prodList",
  340. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  341. controller : 'ProductListCtrl'
  342. }).state('sale.newProdInfo', {
  343. url : "/newProdInfo",
  344. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  345. controller : 'NewProdInfoCtrl'
  346. }).state('sale.uploadByBatch', {
  347. url : "/uploadByBatch",
  348. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  349. controller : 'UploadByBatchCtrl'
  350. }).state('sale.productDetail', {
  351. url : "/prodList/:id",
  352. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  353. controller : 'ProductDetailCtrl'
  354. }).state('sale.maketodo', {
  355. url : "/maketodo",
  356. templateUrl : "static/tpl/index/make/todo.html"
  357. }).state('sale.maketodo.order', {
  358. url : "/makeorder",
  359. templateUrl : "static/tpl/index/make/order.html",
  360. controller: 'MakeOrderCtrl'
  361. }).state('sale.makeorder', {
  362. url : "/makeorder",
  363. templateUrl : "static/tpl/index/make/order.html",
  364. controller: 'MakeOrderCtrl'
  365. }).state('sale.makeorder_detail', {
  366. url : "/makeorder/:id",
  367. templateUrl : "static/tpl/index/make/order_detail.html",
  368. controller: 'MakeOrderDetailCtrl'
  369. }).state('sale.badOut', {
  370. url : "/badOut",
  371. templateUrl : "static/tpl/index/qc/badOut.html",
  372. controller: 'SaleBadOutCtrl'
  373. }).state('sale.MRB', {
  374. url : "/MRB",
  375. templateUrl : "static/tpl/index/qc/MRB.html",
  376. controller: 'SaleMRBCtrl'
  377. }).state('sale.badIn', {
  378. url : "/badIn",
  379. templateUrl : "static/tpl/index/qc/badIn.html",
  380. controller: 'SaleBadInCtrl'
  381. }).state('sale.makeaccept', {
  382. url : "/makeaccept",
  383. templateUrl : "static/tpl/index/make/accept.html",
  384. controller: 'MakeAcceptCtrl'
  385. }).state('sale.makereturns', {
  386. url : "/makereturns",
  387. templateUrl : "static/tpl/index/make/returns.html",
  388. controller: 'MakeReturnCtrl'
  389. }).state('sale.makechange', {
  390. url : "/makechange",
  391. templateUrl : "static/tpl/index/make/change.html",
  392. controller: 'MakeChangeCtrl'
  393. }).state('sale.makechange_detail', {
  394. url : "/makechange/:id",
  395. templateUrl : "static/tpl/index/make/change_detail.html",
  396. controller: 'MakeChangeDetailCtrl'
  397. }).state('account', {
  398. url : "/account",
  399. views : {
  400. "left-view" : {
  401. templateUrl : "static/tpl/index/account/left.html",
  402. controller: 'LeftCtrl'
  403. },
  404. "right-view" : {
  405. templateUrl : "static/tpl/index/account/right.html"
  406. }
  407. }
  408. }).state('account.index', {
  409. url : "",
  410. templateUrl : "static/tpl/index/account/index.html",
  411. controller: 'RightCtrl'
  412. }).state('account.home', {
  413. url : "/",
  414. templateUrl : "static/tpl/index/account/index.html",
  415. controller: 'RightCtrl'
  416. }).state('baseInfo', {//基础资料
  417. url : "/baseInfo",
  418. views : {
  419. "left-view" : {
  420. },
  421. "right-view" : {
  422. templateUrl : "static/tpl/index/baseInfo/right.html"
  423. }
  424. }
  425. }).state('baseInfo.index', {
  426. url : "/enterpriseList",
  427. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  428. controller: 'EnterpriseListCtrl'
  429. }).state('baseInfo.home', {
  430. url : "/enterpriseList",
  431. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  432. controller: 'EnterpriseListCtrl'
  433. }).state('baseInfo.enterpriseList', {
  434. url : "/enterpriseList",
  435. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  436. controller : 'EnterpriseListCtrl'
  437. }).state('baseInfo.myClient', {
  438. url : "/myClient",
  439. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  440. controller : 'MyClientCtrl'
  441. }).state('baseInfo.mySupplier', {
  442. url : "/mySupplier",
  443. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  444. controller : 'MySupplierCtrl'
  445. }).state('baseInfo.myRequest', {
  446. url : "/myRquest",
  447. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  448. controller : 'AddPartnerRequestCtrl'
  449. }).state('baseInfo.myMessage', {
  450. url : "/myMessage",
  451. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  452. controller : 'AddPartnerMessageCtrl'
  453. }).state('baseInfo.myPartners', {
  454. url : '/myPartners',
  455. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  456. controller : 'MyPartnersCtrl'
  457. }).state('baseInfo.businessGroups', {
  458. url : '/businessGroups',
  459. controller : 'BusinessGroupsCtrl'
  460. }).state('qc', {
  461. url : "/qc",
  462. views : {
  463. "left-view" : {
  464. templateUrl : "static/tpl/index/qc/left.html"
  465. },
  466. "right-view" : {
  467. templateUrl : "static/tpl/index/qc/right.html"
  468. }
  469. }
  470. }).state('qc.index', {
  471. url : "",
  472. templateUrl : "static/tpl/index/qc/index.html"
  473. }).state('qc.home', {
  474. url : "/",
  475. templateUrl : "static/tpl/index/qc/index.html"
  476. }).state('fa', {
  477. url : "/fa",
  478. views : {
  479. "left-view" : {
  480. templateUrl : "static/tpl/index/fa/left.html"
  481. },
  482. "right-view" : {
  483. templateUrl : "static/tpl/index/fa/right.html"
  484. }
  485. }
  486. }).state('fa.index', {
  487. url : "",
  488. templateUrl : "static/tpl/index/fa/index.html"
  489. }).state('fa.home', {
  490. url : "/",
  491. templateUrl : "static/tpl/index/fa/index.html"
  492. }).state('fa.apBill', {
  493. url : "/apBill",
  494. templateUrl : "static/tpl/index/fa/apBill.html",
  495. controller: 'SaleApBillCtrl'
  496. }).state('fa.arCheck', {
  497. url : "/arCheck",
  498. templateUrl : "static/tpl/index/fa/arCheck.html",
  499. controller: 'SaleArCheckCtrl'
  500. }).state('fa.arCheck_detail', {
  501. url : "/arCheck/:id",
  502. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  503. controller: 'SaleArCheckDetailCtrl'
  504. }).state('fa.apCheck', {
  505. url : "/apCheck",
  506. params:{
  507. 'id':null
  508. },
  509. templateUrl : "static/tpl/index/fa/apCheck.html",
  510. controller: 'PurchaseApCheckCtrl'
  511. }).state('fa.apCheck_detail', {
  512. url : "/apCheck/:id",
  513. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  514. controller: 'PurchaseApCheckDetailCtrl'
  515. }).state('fa.apCheckList', {
  516. url : "/apCheckList",
  517. templateUrl : "static/tpl/index/fa/apCheckList.html",
  518. controller: 'PurchaseApCheckListCtrl'
  519. }).state('make', {
  520. url : "/make",
  521. views : {
  522. "left-view" : {
  523. templateUrl : "static/tpl/index/make/left.html"
  524. },
  525. "right-view" : {
  526. templateUrl : "static/tpl/index/make/right.html"
  527. }
  528. }
  529. }).state('make.index', {
  530. url : "",
  531. templateUrl : "static/tpl/index/make/index.html"
  532. }).state('make.home', {
  533. url : "/",
  534. templateUrl : "static/tpl/index/make/index.html"
  535. }).state('cs', {// 客户服务
  536. url : "/cs",
  537. views : {
  538. "left-view" : {
  539. templateUrl : "static/tpl/index/cs/left.html"
  540. },
  541. "right-view" : {
  542. templateUrl : "static/tpl/index/cs/right.html"
  543. }
  544. }
  545. }).state('cs.index', {
  546. url : "",
  547. templateUrl : "static/tpl/index/cs/index.html"
  548. }).state('cs.home', {
  549. url : "/",
  550. templateUrl : "static/tpl/index/cs/index.html"
  551. }).state('search', { //顶部搜索
  552. url: "/search?keyword=",
  553. views : {
  554. "left-view" : {
  555. templateUrl : "static/tpl/index/search/left.html"
  556. },
  557. "right-view" : {
  558. templateUrl: "static/tpl/index/search/search_result.html",
  559. controller: 'TopSearchCtrl'
  560. }
  561. }
  562. }).state('approvalflow', { //审批流
  563. url: "/approvalFlow",
  564. views : {
  565. "left-view" : {
  566. templateUrl : "static/tpl/index/approvalFlow/left.html"
  567. },
  568. "right-view" : {
  569. templateUrl: "static/tpl/index/approvalFlow/right.html",
  570. }
  571. }
  572. }).state('approvalflow.flow', {
  573. url : "/flow",
  574. templateUrl : "static/tpl/index/approvalFlow/home.html",
  575. controller: 'approvalFlowCtrl'
  576. }).state('approvalflow.enterprise', {
  577. url : "/enterprise",
  578. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  579. controller: 'EnterpriseCtrl'
  580. }).state('approvalflow.user', {
  581. url : "/user",
  582. templateUrl : "static/tpl/index/approvalFlow/user.html",
  583. controller: 'UserCtrl'
  584. }).state('approvalflow.log', {
  585. url : "/log",
  586. templateUrl : "static/tpl/index/approvalFlow/log.html",
  587. controller: 'LogCtrl'
  588. }).state('approvalflow.resource', {
  589. url : "/resource",
  590. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  591. controller: 'ResourceCtrl'
  592. }).state('approvalflow.role', {
  593. url : "/role",
  594. templateUrl : "static/tpl/index/approvalFlow/role.html",
  595. controller: 'RoleCtrl'
  596. });
  597. $urlRouterProvider.otherwise('/index');
  598. }]);
  599. /**
  600. * 表示符号
  601. */
  602. app.factory('Symbol', function(){
  603. return {
  604. currency: function(cur) {
  605. if(cur == 'RMB') return '¥';
  606. else if(cur == 'USD') return '$';
  607. else if(cur == 'EUR') return '€';
  608. else if(cur == null || cur == '') return '¥';
  609. else return cur;
  610. }
  611. };
  612. }).factory('Lodop',function(){
  613. return {
  614. getLodop:function(oOBJECT,oEMBED){
  615. var CreatedOKLodop7766=null;
  616. /**************************
  617. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  618. IE系列、IE内核系列的浏览器采用oOBJECT,
  619. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  620. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  621. 64位浏览器指向64位的安装程序install_lodop64.exe。
  622. **************************/
  623. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  624. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  625. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  626. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  627. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  628. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  629. var LODOP;
  630. try{
  631. //=====判断浏览器类型:===============
  632. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  633. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  634. //=====如果页面有Lodop就直接使用,没有则新建:==========
  635. if (oOBJECT!=undefined || oEMBED!=undefined) {
  636. if (isIE)
  637. LODOP=oOBJECT;
  638. else
  639. LODOP=oEMBED;
  640. } else {
  641. if (CreatedOKLodop7766==null){
  642. LODOP=document.createElement("object");
  643. LODOP.setAttribute("width",0);
  644. LODOP.setAttribute("height",0);
  645. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  646. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  647. else LODOP.setAttribute("type","application/x-print-lodop");
  648. document.documentElement.appendChild(LODOP);
  649. CreatedOKLodop7766=LODOP;
  650. } else
  651. LODOP=CreatedOKLodop7766;
  652. };
  653. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  654. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  655. if (navigator.userAgent.indexOf('Chrome')>=0)
  656. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  657. if (navigator.userAgent.indexOf('Firefox')>=0)
  658. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  659. if (is64IE) document.write(strHtm64_Install); else
  660. if (isIE) document.write(strHtmInstall); else
  661. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  662. return LODOP;
  663. } else
  664. if (LODOP.VERSION<"6.1.9.8") {
  665. if (is64IE) document.write(strHtm64_Update); else
  666. if (isIE) document.write(strHtmUpdate); else
  667. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  668. return LODOP;
  669. };
  670. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  671. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  672. //============================================================
  673. return LODOP;
  674. } catch(err) {
  675. if (is64IE)
  676. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  677. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  678. return LODOP;
  679. };
  680. }
  681. }
  682. });
  683. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
  684. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  685. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  686. if (routeState.indexOf('/') > -1)
  687. routeState = routeState.substring(0, routeState.indexOf('/'));
  688. if (routeState.indexOf('.') > -1)
  689. routeState = routeState.substring(0, routeState.indexOf('.'));
  690. $scope.routeState = routeState || 'home';
  691. });
  692. $scope.search = function(keyword) {
  693. if(keyword != null ) {
  694. $rootScope.searchKeyword = keyword;
  695. window.location.hash = '#/search?keyword='+keyword;
  696. }
  697. };
  698. $scope.showMessage = function() {
  699. var $modalInstance = $modal.open({
  700. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  701. controller: 'PagingReleaseCtrl'
  702. });
  703. };
  704. }]);
  705. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  706. BaseService.scrollBackToTop();
  707. $scope.active = "todo";
  708. $scope.setActive = function(state) {
  709. if($scope.active != state) {
  710. $scope.active = state;
  711. if($scope.tableParams.page() == 1)
  712. $scope.tableParams.reload();
  713. else
  714. $scope.tableParams.page(1);
  715. }
  716. };
  717. $scope.tableParams = new ngTableParams({
  718. page : 1,
  719. count : 5,
  720. sorting: {
  721. 'releaseDetail.release.date': 'desc'
  722. }
  723. }, {
  724. total : 0,
  725. counts: [5, 10, 25, 50],
  726. getData : function($defer, params) {
  727. $scope.loading = true;
  728. var pageParams = params.url();
  729. var realActive = {};
  730. pageParams.searchFilter = { // 筛选条件
  731. keyword: $scope.keyword
  732. // fromDate: getDateTime($scope.condition.dateFrom),
  733. // endDate: getDateTime($scope.condition.dateTo)
  734. };
  735. // AccountEnterprise.get({}, function(data){
  736. // $scope.loading = false;
  737. // $scope.currentEn = data;
  738. // });
  739. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  740. $scope.loading = false;
  741. if(page) {
  742. params.total(page.totalElement);
  743. $defer.resolve(page.content);
  744. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  745. }
  746. }, function(response){
  747. $scope.loading = false;
  748. toaster.pop('error', '数据加载失败', response.data);
  749. });
  750. }
  751. });
  752. $scope.close = function() {
  753. $modalInstance.close();
  754. };
  755. $scope.checks = {
  756. checked : false
  757. };// 全选框
  758. $scope.checkAll = function() {
  759. angular.forEach($scope.tableParams.data, function(message) {
  760. message.checked = $scope.checks.checked;
  761. });
  762. };
  763. // 单选
  764. $scope.checkOne = function(vendor) {
  765. vendor.checked = true;
  766. var checked = true;
  767. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  768. if (!message.checked) {
  769. checked = false;
  770. }
  771. });
  772. $scope.checks.checked = checked;
  773. };
  774. // 单反选
  775. $scope.unCheckOne = function(vendor) {
  776. vendor.checked = false;
  777. $scope.checks.checked = false;
  778. };
  779. // 标为已读
  780. $scope.setRead = function() {
  781. var selectedMessages = [];
  782. angular.forEach($scope.tableParams.data, function(message) {
  783. if(message.checked) {
  784. selectedMessages.push(message);
  785. }
  786. });
  787. console.log(selectedMessages);
  788. PagingRelease.setRead({}, selectedMessages , function(message) {
  789. $scope.tableParams.page(1);
  790. $scope.tableParams.reload();
  791. });
  792. };
  793. // 搜索框回车
  794. $scope.onSearch = function() {
  795. $scope.tableParams.page(1);
  796. $scope.tableParams.reload();
  797. };
  798. }]);
  799. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  800. var search = $rootScope.searchKeyword;
  801. return function(content, search) {
  802. content = encodeURI(content);
  803. search = encodeURI(search);
  804. var reg = new RegExp(search, 'gim');
  805. var result = content.replace(reg,'<font color="red">$&</font>');
  806. result = decodeURI(result);
  807. return $sce.trustAsHtml(result);
  808. }
  809. }]);
  810. /**
  811. * 顶部搜索
  812. */
  813. 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) {
  814. BaseService.scrollBackToTop();
  815. $scope.active = 'all';
  816. $scope.tip = $rootScope.searchKeyword;
  817. // 企业搜索
  818. var getService = function() {
  819. return getAccountUserSpace;
  820. };
  821. $scope.tableParams = new ngTableParams({
  822. page : 1,
  823. count : 5,
  824. sorting: {
  825. }
  826. }, {
  827. total : 0,
  828. counts: [5, 10, 25, 50],
  829. getData : function($defer, params) {
  830. $scope.loading = true;
  831. var pageParams = params.url();
  832. pageParams.keyword = $rootScope.searchKeyword;
  833. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  834. $scope.loading = false;
  835. if(page) {
  836. $scope.total = page.totalElement;
  837. params.total(page.totalElement);
  838. $defer.resolve(page.content);
  839. }
  840. }, function(response) {
  841. $scope.loading = false;
  842. toaster.pop('error', '数据加载失败', response.data);
  843. });
  844. }
  845. });
  846. // 添加合作关系
  847. $scope.addPartner = function(name, businessCode) {
  848. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  849. if(data.success) {
  850. toaster.pop("success", '添加成功', data.success);
  851. }
  852. if(data.error) {
  853. toaster.pop("error", '添加失败', data.error);
  854. }
  855. }, function(response) {
  856. toaster.pop('error','失败',response.data);
  857. });
  858. }
  859. // 物料搜索
  860. var getProdService = function() {
  861. return SearchProd;
  862. };
  863. $scope.prodTableParams = new ngTableParams({
  864. page : 1,
  865. count : 5,
  866. sorting: {
  867. }
  868. }, {
  869. total : 0,
  870. counts: [5, 10, 25, 50],
  871. getData : function($defer, params) {
  872. $scope.loading = true;
  873. var pageParams = params.url();
  874. pageParams.keyword = $rootScope.searchKeyword;
  875. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  876. $scope.loading = false;
  877. if(page) {
  878. $scope.prodtotal = page.totalElement;
  879. params.total(page.totalElement);
  880. $defer.resolve(page.content);
  881. }
  882. }, function(response) {
  883. $scope.loading = false;
  884. toaster.pop('error', '数据加载失败', response.data);
  885. });
  886. }
  887. });
  888. /**
  889. * 向企业购买
  890. */
  891. $scope.PurcByEn = function(businessCode) {
  892. $rootScope.businessCode = businessCode;
  893. window.location.hash = "#/purc/addOrder";
  894. }
  895. /**
  896. * 选中单个物料购买
  897. * @param businessCode
  898. * @param id
  899. */
  900. $scope.PurcByEnAndProd = function(businessCode, id) {
  901. $rootScope.businessCode = businessCode;
  902. $rootScope.prodId = id;
  903. window.location.hash = "#/purc/addOrder";
  904. }
  905. /**
  906. * 邀请注册商务平台
  907. */
  908. $scope.invite = function(name) {
  909. var modalInstance = $modal.open({
  910. animation: true,
  911. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  912. controller: 'InviteCtrl',
  913. resolve: {
  914. enname: function(){return name}
  915. }
  916. });
  917. modalInstance.result.then(function(data) {
  918. InvitationRecord.invite({formStore: data}, {}, function(data) {
  919. if(data.success) {
  920. toaster.pop('success', '提示', data.success);
  921. }
  922. if(data.error) {
  923. toaster.pop('error', '提示', data.error);
  924. }
  925. }, function(response) {
  926. toaster.pop('error', '提示', response.data);
  927. });
  928. });
  929. }
  930. }]);
  931. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  932. $scope.enter = {
  933. vendname: enname
  934. };
  935. $scope.save = function(enter) {
  936. if(!enter.vendusertel && !enter.venduseremail) {
  937. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  938. } else {
  939. $modalInstance.close(enter);
  940. }
  941. }
  942. $scope.cancel = function() {
  943. $modalInstance.dismiss();
  944. }
  945. }]);
  946. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  947. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  948. //手机号码格式验证
  949. // var checkTel = function(data){
  950. // var userTel = data.userTel;
  951. // $scope.checkResult = false;
  952. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  953. // if(!(telephone).test(userTel)){
  954. // var modalInstance = $modal.open({
  955. // animation: true,
  956. // templateUrl: 'static/tpl/index/account/checkTel.html',
  957. // controller: 'CheckTelCtrl',
  958. // backdrop: 'static',
  959. // keyboard: false,
  960. // resolve: {
  961. // user: function(){
  962. // return data;
  963. // },
  964. // }
  965. // });
  966. // modalInstance.result.then(function(){
  967. // }, function(){
  968. //
  969. // });
  970. // } else {
  971. // $scope.checkResult = true;
  972. // }
  973. // };
  974. AuthenticationService.getAuthentication().success(function(data) {
  975. if(data.enterprises) {
  976. data.enterprise = data.enterprises[data.enterprises.length - 1];
  977. if(data.enterprises.length > 1) {
  978. var enSelect = [];
  979. angular.forEach(data.enterprises, function(e){
  980. if(e.current)
  981. data.enterprise = e;
  982. else
  983. enSelect.push(e);
  984. });
  985. data.enSelect = enSelect;
  986. }
  987. }
  988. $scope.userInfo = data;
  989. if (data == null || !data.userUU) {
  990. $scope.isAuthed = false;
  991. AuthenticationService.redirectSignin();
  992. } else {
  993. //跳转到手机号码验证
  994. // checkTel($scope.userInfo);
  995. }
  996. });
  997. $scope.logout = function() {
  998. AuthenticationService.logout();
  999. };
  1000. $scope.switchto = function(enUU) {// 切换企业
  1001. AuthenticationService.reSignin(enUU).success(function(){
  1002. $window.location.reload();
  1003. });
  1004. };
  1005. $scope.addFavorite = function(){
  1006. var url = encodeURI(window.location.href);
  1007. try{
  1008. //ie浏览器收藏方式
  1009. window.external.addFavorite(url, "优软商务平台");
  1010. }catch(e) {
  1011. try{
  1012. //火狐浏览器收藏方式
  1013. window.sidebar.addPanel("优软商务平台", url);
  1014. }catch (e) {
  1015. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  1016. "或手动在浏览器里进行设置。");
  1017. }
  1018. }
  1019. };
  1020. }]);
  1021. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1022. $scope.image = {src: null};
  1023. // 图片上传成功之后
  1024. $scope.onUploadSuccess = function(data){
  1025. var path = data.path;
  1026. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1027. $scope.$apply(function(){
  1028. $scope.image.src = data.path;
  1029. $scope.image.thumb = path;
  1030. });
  1031. };
  1032. $scope.close = function() {
  1033. $modalInstance.dismiss();
  1034. };
  1035. $scope.confirm = function() {
  1036. $modalInstance.close($scope.image);
  1037. $scope.imageUrl = null;
  1038. };
  1039. }]);
  1040. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function($scope, SnapshotService, BaseService, $rootScope){
  1041. BaseService.scrollBackToTop();
  1042. SnapshotService.getTodo(function(data){
  1043. $scope.todo = data;
  1044. });
  1045. $scope.setTenderActive = function(active) {
  1046. $rootScope.tenderActive = active;
  1047. window.location.hash = '#/purc/tender';
  1048. }
  1049. }]);
  1050. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1051. SaleTruck.query({}, function(data){
  1052. $rootScope.truck = data;
  1053. $scope.truckCount = data ? data.length : 0;
  1054. });
  1055. $scope.$watch(function(){
  1056. return $rootScope.truck;
  1057. }, function(data) {
  1058. $scope.truckCount = data ? data.length : 0;
  1059. }, true);
  1060. $scope.clearAll = function() {
  1061. SaleTruck.remove({}, function(){
  1062. $rootScope.truck = [];
  1063. });
  1064. };
  1065. $scope.openTrack = function() {
  1066. $modal.open({
  1067. templateUrl: 'static/tpl/index/sale/track.html',
  1068. controller: 'TruckModalCtrl',
  1069. size: 'lg'
  1070. }).result.then(function(s){
  1071. if(s) {
  1072. $scope.clearAll();
  1073. $rootScope.dataChanged = true;
  1074. }
  1075. });
  1076. };
  1077. }]);
  1078. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  1079. $scope.saleSend = {sendItems: []};
  1080. SaleTruck.detail({}, function(data){
  1081. // 按物料编号排序
  1082. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1083. });
  1084. $scope.remove = function(index, notice) {
  1085. SaleTruck.remove({noticeId: notice.id}, function(data){
  1086. $rootScope.truck = data;
  1087. $scope.notices.splice(index, 1);
  1088. });
  1089. };
  1090. $scope.$watch(function(){
  1091. return $scope.notices;
  1092. }, function(data) {
  1093. var q = 0, t = 0;
  1094. if(data) {
  1095. angular.forEach(data,function(d){
  1096. q += d.thisSendQty;
  1097. t += d.thisSendQty * d.orderItem.price;
  1098. });
  1099. }
  1100. $scope.totalQty = q;
  1101. $scope.total = t;
  1102. }, true);
  1103. $scope.cancel = function() {
  1104. $modalInstance.close();
  1105. };
  1106. $scope.send = function() {// 发货
  1107. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1108. toaster.pop('error', '错误', '请输入送货单号');
  1109. return;
  1110. }
  1111. var currency = $scope.notices[0].orderItem.order.currency,
  1112. custUU = $scope.notices[0].enUU,
  1113. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1114. var num = 1;
  1115. for(var i in $scope.notices) {
  1116. var item = $scope.notices[i];
  1117. if(item.id) {
  1118. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1119. valid = false;
  1120. break;
  1121. }
  1122. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1123. }
  1124. }
  1125. if(!valid) {
  1126. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1127. } else {
  1128. var send = angular.extend(angular.copy($scope.saleSend), {
  1129. currency: currency,
  1130. custUU: custUU,
  1131. payments: payments,
  1132. sendItems: items
  1133. });
  1134. PurcNotice.sendByBatch({}, send, function(data){
  1135. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1136. $modalInstance.close(true);
  1137. $state.go('sale.send_detail', {id: data.id});
  1138. }, function(response){
  1139. toaster.pop('error', '错误', response.data);
  1140. });
  1141. }
  1142. };
  1143. }]);
  1144. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1145. SaleStat.cust({}, function(data){
  1146. var p = [], q = [];
  1147. angular.forEach(data.month, function(d){
  1148. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1149. });
  1150. angular.forEach(data.year, function(d){
  1151. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1152. });
  1153. $scope.custCharts = {
  1154. month : {
  1155. chartType : 'pie',
  1156. datas : {
  1157. data : p
  1158. },
  1159. config : {
  1160. labels : false,
  1161. title : "客户月采购量排行榜",
  1162. legend : {
  1163. display : true,
  1164. position : 'right'
  1165. },
  1166. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1167. click : function(d) {
  1168. },
  1169. mouseover : function(d) {
  1170. },
  1171. mouseout : function(d) {
  1172. },
  1173. innerRadius : 0,
  1174. lineLegend : 'lineEnd'
  1175. }
  1176. },
  1177. year : {
  1178. chartType : 'pie',
  1179. datas : {
  1180. data : q
  1181. },
  1182. config : {
  1183. labels : false,
  1184. title : "客户年采购量排行榜",
  1185. legend : {
  1186. display : true,
  1187. position : 'right'
  1188. },
  1189. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1190. click : function(d) {
  1191. },
  1192. mouseover : function(d) {
  1193. },
  1194. mouseout : function(d) {
  1195. },
  1196. innerRadius : 0,
  1197. lineLegend : 'lineEnd'
  1198. }
  1199. }
  1200. };
  1201. });
  1202. SaleStat.seller({}, function(data){
  1203. var p = [], q = [];
  1204. angular.forEach(data.month, function(d){
  1205. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1206. });
  1207. angular.forEach(data.year, function(d){
  1208. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1209. });
  1210. $scope.sellerCharts = {
  1211. month : {
  1212. chartType : 'pie',
  1213. datas : {
  1214. data : p
  1215. },
  1216. config : {
  1217. labels : false,
  1218. title : "业务员月销量排行榜",
  1219. legend : {
  1220. display : true,
  1221. position : 'right'
  1222. },
  1223. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1224. click : function(d) {
  1225. },
  1226. mouseover : function(d) {
  1227. },
  1228. mouseout : function(d) {
  1229. },
  1230. innerRadius : 0,
  1231. lineLegend : 'lineEnd'
  1232. }
  1233. },
  1234. year : {
  1235. chartType : 'pie',
  1236. datas : {
  1237. data : q
  1238. },
  1239. config : {
  1240. labels : false,
  1241. title : "业务员年销量排行榜",
  1242. legend : {
  1243. display : true,
  1244. position : 'right'
  1245. },
  1246. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1247. click : function(d) {
  1248. },
  1249. mouseover : function(d) {
  1250. },
  1251. mouseout : function(d) {
  1252. },
  1253. innerRadius : 0,
  1254. lineLegend : 'lineEnd'
  1255. }
  1256. }
  1257. };
  1258. });
  1259. }]);
  1260. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1261. SaleStat.get({}, function(data){
  1262. var p = [], q = [], r = [];
  1263. angular.forEach(data.day, function(d){
  1264. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1265. });
  1266. angular.forEach(data.month, function(d){
  1267. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1268. });
  1269. angular.forEach(data.year, function(d){
  1270. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1271. });
  1272. $scope.charts = {
  1273. day : {
  1274. chartType : "line",
  1275. datas: {
  1276. series: ['销售额'],
  1277. data: p
  1278. },
  1279. config : {
  1280. "labels": false,
  1281. "title": "销售额统计(近15日线)",
  1282. "legend": {
  1283. "display": true,
  1284. "position": "right"
  1285. },
  1286. colors : [ '#4D9934'],
  1287. "innerRadius": 0,
  1288. "lineLegend": "lineEnd"
  1289. }
  1290. },
  1291. month: {
  1292. chartType : "line",
  1293. datas: {
  1294. series: ['销售额'],
  1295. data: q
  1296. },
  1297. config : {
  1298. "labels": false,
  1299. "title": "销售额统计(近12月线)",
  1300. "legend": {
  1301. "display": true,
  1302. "position": "right"
  1303. },
  1304. colors : [ '#4D9934'],
  1305. "innerRadius": 0,
  1306. "lineLegend": "lineEnd"
  1307. }
  1308. },
  1309. year: {
  1310. chartType : "line",
  1311. datas: {
  1312. series: ['销售额'],
  1313. data: r
  1314. },
  1315. config : {
  1316. "labels": false,
  1317. "title": "销售额统计(近10年线)",
  1318. "legend": {
  1319. "display": true,
  1320. "position": "right"
  1321. },
  1322. colors : [ '#4D9934'],
  1323. "innerRadius": 0,
  1324. "lineLegend": "lineEnd"
  1325. }
  1326. }
  1327. };
  1328. });
  1329. }]);
  1330. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1331. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1332. $scope.notices = data;
  1333. });
  1334. $scope.dateTime = new Date();
  1335. }]);
  1336. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1337. // SnapshotService.getTender(250, function(data){
  1338. // $scope.tenders = data;
  1339. // console.log(data);
  1340. // var newDate = new Date();
  1341. // newDate = newDate.setDate(newDate.getDate() - 3);
  1342. // angular.forEach($scope.tenders, function(tender) {
  1343. // if (tender.date > newDate) {
  1344. // tender.isNew = true;
  1345. // } else {
  1346. // tender.isNew = false;
  1347. // }
  1348. // });
  1349. // });
  1350. SnapshotService.getOpenTender(function(data){
  1351. $scope.openTenders = data;
  1352. var newDate = new Date();
  1353. console.log(data);
  1354. newDate = newDate.getTime() - 3*24*60*60*1000;
  1355. angular.forEach($scope.openTenders, function(tender) {
  1356. if (tender.date - newDate > 0) {
  1357. tender.isNew = true;
  1358. } else {
  1359. tender.isNew = false;
  1360. }
  1361. });
  1362. });
  1363. $scope.dateTime = new Date();
  1364. }]);
  1365. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1366. VendorService.getCount(function(date){
  1367. $scope.count = date;
  1368. });
  1369. }]);
  1370. // 客户
  1371. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1372. BaseService.scrollBackToTop();
  1373. $scope.userInfoResult = true;
  1374. AuthenticationService.getAuthentication().success(function(data) {
  1375. $scope.loading = false;
  1376. $scope.thisUser = data;
  1377. });
  1378. var getCustInfos = function(custuu) {
  1379. if(custuu) {
  1380. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1381. $scope.custInfos = data;
  1382. var getPage = function(page, size){
  1383. if($scope.custInfos) {
  1384. var result = {};
  1385. result.totalCount = $scope.custInfos.length;
  1386. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1387. if($scope.custInfos.length % size == 0) {
  1388. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1389. }else {
  1390. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1391. }
  1392. result.first = page == 1;
  1393. result.last = page == result.totalPage;
  1394. result.page = page;
  1395. result.next = page - 0 + 1;
  1396. result.pre = page - 1;
  1397. return result;
  1398. }
  1399. }
  1400. $scope.userdata = getPage(1,4);
  1401. $scope.first = function (){
  1402. $scope.userdata = getPage($scope.userdata.pre,4);
  1403. }
  1404. $scope.last = function (){
  1405. $scope.userdata = getPage($scope.userdata.next,4);
  1406. }
  1407. }, function(response){
  1408. $scope.loading = false;
  1409. toaster.pop('error', '数据加载失败', response.data);
  1410. });
  1411. }
  1412. }
  1413. $scope.addUserInfo = function(customer) {
  1414. //TODO
  1415. if ($scope.thisUser.sys) {
  1416. var modalInstance = $modal.open({
  1417. animation: true,
  1418. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1419. controller: 'AddUserInfoCtrl',
  1420. resolve: {
  1421. customer: function() {
  1422. return customer;
  1423. }
  1424. }
  1425. });
  1426. modalInstance.result.then(function(changed, checked){
  1427. if(changed) {
  1428. if(checked)
  1429. $scope.newUser.roles = checked;
  1430. else
  1431. loadUsers();
  1432. }
  1433. });
  1434. } else {
  1435. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1436. }
  1437. }
  1438. $scope.showUserInfo = function(customer,boo) {
  1439. $scope.custInfo = customer;
  1440. if(boo) {
  1441. getCustInfos(customer.myEnterprise.uu);
  1442. $scope.userInfoResult = true;
  1443. }
  1444. }
  1445. $scope.customerParams = new ngTableParams({
  1446. page : 1,
  1447. count : 10
  1448. }, {
  1449. total : 0,
  1450. counts: [5, 10, 25, 50],
  1451. getData : function($defer, params) {
  1452. $scope.loading = true;
  1453. var pageParams = params.url();
  1454. pageParams.keyword = $scope.keyword;
  1455. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1456. $scope.loading = false;
  1457. if(page) {
  1458. params.total(page.totalElement);
  1459. $defer.resolve(page.content);
  1460. }
  1461. $scope.totalCount = page.totalElement;
  1462. }, function(response){
  1463. $scope.loading = false;
  1464. toaster.pop('error', '数据加载失败', response.data);
  1465. });
  1466. }
  1467. });
  1468. // 搜索框回车
  1469. $scope.onSearch = function(keyword) {
  1470. $scope.customerParams.page(1);
  1471. $scope.customerParams.reload();
  1472. $scope.tip = keyword;
  1473. };
  1474. // 查看详情
  1475. $scope.viewDetail = function(id) {
  1476. console.log(id);
  1477. window.location.hash = "#/sale/customer/" + id;
  1478. }
  1479. }]);
  1480. // 客户详情
  1481. 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) {
  1482. BaseService.scrollBackToTop();
  1483. $scope.userInfoResult = true;
  1484. AuthenticationService.getAuthentication().success(function(data) {
  1485. $scope.loading = false;
  1486. $scope.thisUser = data;
  1487. });
  1488. $scope.vendorContacts = [];
  1489. var loadData = function() {
  1490. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1491. $scope.customer = data.myEnterprise;
  1492. $scope.customerInfo = data;
  1493. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1494. $scope.Contacts = data;
  1495. });
  1496. // 查看已分配人员
  1497. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1498. $scope.custInfos = data;
  1499. var getPage = function(page, size){
  1500. if($scope.custInfos) {
  1501. var result = {};
  1502. result.totalCount = $scope.custInfos.length;
  1503. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1504. if($scope.custInfos.length % size == 0) {
  1505. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1506. }else {
  1507. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1508. }
  1509. result.first = page == 1;
  1510. result.last = page == result.totalPage;
  1511. result.page = page;
  1512. result.next = page - 0 + 1;
  1513. result.pre = page - 1;
  1514. return result;
  1515. }
  1516. }
  1517. $scope.userdata = getPage(1,4);
  1518. $scope.first = function (){
  1519. $scope.userdata = getPage($scope.userdata.pre,4);
  1520. }
  1521. $scope.last = function (){
  1522. $scope.userdata = getPage($scope.userdata.next,4);
  1523. }
  1524. }, function(response){
  1525. $scope.loading = false;
  1526. toaster.pop('error', '数据加载失败', response.data);
  1527. });
  1528. });
  1529. };
  1530. loadData();
  1531. // 新增客户联系人
  1532. $scope.addContact = function(uu) {
  1533. var modalInstance = $modal.open({
  1534. animation: true,
  1535. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1536. controller: 'AddContacCtrl',
  1537. resolve: {
  1538. }
  1539. });
  1540. modalInstance.result.then(function(data) {
  1541. $scope.contact = data;
  1542. $scope.contact.myenuu = uu;
  1543. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1544. toaster.pop('success', '提示', '联系人保存成功');
  1545. $scope.Contacts.push(data);
  1546. }, function(response) {
  1547. toaster.pop('error', '失败', response.data);
  1548. });
  1549. });
  1550. }
  1551. // 编辑客户联系人
  1552. $scope.edit = function(contact) {
  1553. var modalInstance = $modal.open({
  1554. animation: true,
  1555. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  1556. controller: 'EditContacCtrl',
  1557. resolve: {
  1558. contact: function() {
  1559. return contact;
  1560. }
  1561. }
  1562. });
  1563. modalInstance.result.then(function(data) {
  1564. $scope.contact = data;
  1565. Vendor.saveContact({}, $scope.contact, function(data) {
  1566. toaster.pop('success', '提示', '联系人修改成功');
  1567. }, function(response) {
  1568. toaster.pop('error', '失败', response.data);
  1569. });
  1570. });
  1571. }
  1572. // 删除客户联系人
  1573. $scope.deleteById = function(id, index) {
  1574. $scope.Contacts.splice(index, 1);
  1575. Vendor.deleteContact({id: id}, {}, function(data) {
  1576. toaster.pop('success', '提示', '供应商联系人删除成功');
  1577. }, function(response) {
  1578. toaster.pop('error', '提示', response.data);
  1579. });
  1580. }
  1581. // 供应商物料信息
  1582. $scope.viewProdList = function(uu){
  1583. $scope.uu = uu;
  1584. $scope.tableParams.page(1);
  1585. $scope.tableParams.reload();
  1586. };
  1587. // 搜索框回车
  1588. $scope.onSearch = function(keyword) {
  1589. $scope.keyword = keyword;
  1590. $scope.tableParams.page(1);
  1591. $scope.tableParams.reload();
  1592. };
  1593. // 供应商物料信息
  1594. $scope.tableParams = new ngTableParams({
  1595. page : 1,
  1596. count : 10
  1597. }, {
  1598. total : 0,
  1599. counts: [5, 10, 25, 50],
  1600. getData : function($defer, params) {
  1601. $scope.loading = true;
  1602. var pageParams = params.url();
  1603. pageParams.custUU = $scope.uu;
  1604. pageParams.keyword = $scope.keyword;
  1605. $scope.tip = $scope.keyword;
  1606. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1607. $scope.loading = false;
  1608. if(page) {
  1609. params.total(page.totalElement);
  1610. $scope.total = page.totalElement;
  1611. $defer.resolve(page.content);
  1612. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1613. }
  1614. }, function(response){
  1615. $scope.loading = false;
  1616. toaster.pop('error', '数据加载失败', response.data);
  1617. });
  1618. }
  1619. });
  1620. $scope.addUserInfo = function() {
  1621. //TODO
  1622. if ($scope.thisUser.sys) {
  1623. var modalInstance = $modal.open({
  1624. animation: true,
  1625. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1626. controller: 'AddUserInfoCtrl',
  1627. resolve: {
  1628. customer: function() {
  1629. return $scope.customerInfo;
  1630. }
  1631. }
  1632. });
  1633. modalInstance.result.then(function(changed, checked){
  1634. if(changed) {
  1635. if(checked)
  1636. $scope.newUser.roles = checked;
  1637. else
  1638. loadUsers();
  1639. }
  1640. });
  1641. } else {
  1642. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1643. }
  1644. }
  1645. $scope.Quotation = function(uu, id) {
  1646. $rootScope.custuu = uu;
  1647. $rootScope.prodId = id;
  1648. window.location.hash = "#/sale/quotation/new";
  1649. }
  1650. }]);
  1651. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1652. $scope.checkboxes = {
  1653. checked : false
  1654. };
  1655. $scope.loading = true;
  1656. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1657. $scope.userinfos = data;
  1658. $scope.loading = false;
  1659. })
  1660. // 点击勾选全部的复选框
  1661. $scope.checkAll = function() {
  1662. angular.forEach($scope.userinfos, function(item) {
  1663. item.distribute = $scope.checkboxes.checked;
  1664. });
  1665. };
  1666. // 点击其中一个明细的复选框
  1667. $scope.checkOne = function(vendor){
  1668. var result = true;
  1669. angular.forEach($scope.userinfos, function(item) {
  1670. if(item.distribute != true){
  1671. result = false;
  1672. return;
  1673. }
  1674. });
  1675. $scope.checkboxes.checked = result;
  1676. };
  1677. $scope.close = function(save) {
  1678. var chooseResult = [];
  1679. if(save) {
  1680. if(customer.myEnterprise.uu) {
  1681. angular.forEach($scope.userinfos, function(item, i) {
  1682. chooseResult.push(item);
  1683. });
  1684. if(chooseResult.length > 0) {
  1685. $scope.loading = true;
  1686. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1687. $scope.loading = false;
  1688. toaster.pop('success', '提示', '保存成功');
  1689. $modalInstance.close(false);
  1690. }, function(response){
  1691. $scope.loading = false;
  1692. toaster.pop('error', '保存失败', response.data);
  1693. $modalInstance.close(false);
  1694. })
  1695. } else {
  1696. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1697. }
  1698. } else {
  1699. $modalInstance.close(true, $scope.checkboxes.checked);
  1700. }
  1701. } else {
  1702. $modalInstance.close(false);
  1703. }
  1704. };
  1705. }]);
  1706. /**
  1707. * 页面状态按钮过滤
  1708. */
  1709. var getState = function(active) {
  1710. var fn = 'get';
  1711. switch(active) {
  1712. case 'done':
  1713. fn = 'getDone';break;
  1714. case 'todo':
  1715. fn = 'getTodo';break;
  1716. case 'end':
  1717. fn = 'getEnd';break;
  1718. case 'waiting':
  1719. fn = 'getWaiting';break;
  1720. case 'invalid':
  1721. fn = 'getInvalid';break;
  1722. }
  1723. return fn;
  1724. };
  1725. /**
  1726. * 改变单据日期范围
  1727. */
  1728. var getDateCondition = function(zone, condition) {
  1729. var date = new Date();
  1730. if(zone == -1) {
  1731. condition.dateFrom = null;
  1732. condition.dateTo = null;
  1733. } else if(zone == 1) {
  1734. date.setMonth(date.getMonth() - 1);
  1735. condition.dateFrom = date;
  1736. condition.dateTo = new Date();
  1737. } else if (zone == 6) {
  1738. date.setMonth(date.getMonth() - 6);
  1739. condition.dateFrom = date;
  1740. condition.dateTo = new Date();
  1741. } else {
  1742. date.setMonth(date.getMonth() - 6);
  1743. condition.dateFrom = null;
  1744. condition.dateTo = date;
  1745. }
  1746. };
  1747. /**
  1748. * 改变单据交货日期范围
  1749. */
  1750. var getDelveryCondition = function(zone, condition) {
  1751. var date = new Date();
  1752. if(zone == -1) {
  1753. condition.deliveryFrom = null;
  1754. condition.deliveryTo = null;
  1755. } else if(zone == 1) {
  1756. date.setMonth(date.getMonth() + 1);
  1757. condition.deliveryTo = date;
  1758. condition.deliveryFrom = new Date();
  1759. } else if (zone == 2) {
  1760. date.setMonth(date.getMonth() + 2);
  1761. condition.deliveryTo = date;
  1762. condition.deliveryFrom = new Date();
  1763. }
  1764. };
  1765. /**
  1766. * 将日期转化为整数日期
  1767. */
  1768. var getDateTime = function(date) {
  1769. if(angular.isDate(date)) {
  1770. return date.getTime();
  1771. } else {
  1772. return null;
  1773. }
  1774. };
  1775. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1776. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1777. BaseService.scrollBackToTop();
  1778. $scope.active = 'all';
  1779. $scope.dateZoneText = '不限';
  1780. $scope.deliveryZoneText = '不限';
  1781. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1782. $scope.changeDateZone = function(zone) {
  1783. $scope.condition.dateZone = zone;
  1784. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1785. $scope.condition.$dateZoneOpen = false;
  1786. getDateCondition(zone, $scope.condition);
  1787. $scope.tableParams.reload();
  1788. };
  1789. $scope.changeDeliveryZone = function(zone) {
  1790. $scope.condition.deliveryZoneText = zone;
  1791. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1792. $scope.condition.$delievryZoneOpen = false;
  1793. getDelveryCondition(zone, $scope.condition);
  1794. $scope.tableParams.reload();
  1795. };
  1796. // 切换单据类型
  1797. $scope.setActive = function(state) {
  1798. if($scope.active != state) {
  1799. $scope.active = state;
  1800. if($scope.tableParams.page() == 1)
  1801. $scope.tableParams.reload();
  1802. else
  1803. $scope.tableParams.page(1);
  1804. }
  1805. };
  1806. var getPurcStatus = function(active) {
  1807. var fn = 'getPurcAll';
  1808. switch(active) {
  1809. case 'done':
  1810. fn = 'getPurcDone';break;
  1811. case 'todo':
  1812. fn = 'getPurcTodo';break;
  1813. case 'end':
  1814. fn = 'getPurcEnd';break;
  1815. case 'waiting':
  1816. fn = 'getPurcWaiting';break;
  1817. }
  1818. return fn;
  1819. };
  1820. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1821. page : 1,
  1822. count : 5,
  1823. sorting: {
  1824. display: 'desc',
  1825. date: 'desc'
  1826. }
  1827. }, {
  1828. total : 0,
  1829. counts: [5, 10, 15, 25, 50],
  1830. getData : function($defer, params) {// 获取数据的方法
  1831. $scope.loading = true;
  1832. var pageParams = params.url();
  1833. pageParams.searchFilter = { // 筛选条件
  1834. keyword: $scope.keyword,
  1835. fromDate: getDateTime($scope.condition.dateFrom),
  1836. endDate: getDateTime($scope.condition.dateTo)
  1837. };
  1838. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1839. $scope.loading = false;
  1840. if(page) {
  1841. $defer.resolve(page.content);
  1842. params.total(page.totalElement);
  1843. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1844. }
  1845. }, function(response){
  1846. $scope.loading = false;
  1847. toaster.pop('error', '数据加载失败', response.data);
  1848. });
  1849. }
  1850. });
  1851. $scope.getReply = function(item) {
  1852. if(!item.replies) {
  1853. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1854. item.replies = replies;
  1855. });
  1856. }
  1857. };
  1858. $scope.getOrderTotal = function(items) {
  1859. var sum = 0;
  1860. angular.forEach(items, function(item){
  1861. sum += item.qty * item.price;
  1862. });
  1863. return sum;
  1864. };
  1865. $scope.openDatePicker = function($event, item, openParam) {
  1866. $event.preventDefault();
  1867. $event.stopPropagation();
  1868. item[openParam] = !item[openParam];
  1869. };
  1870. $scope.parseDate = function(dateStr) {
  1871. if(dateStr)
  1872. return Date.parse(dateStr, 'yyyy-MM-dd');
  1873. return new Date();
  1874. };
  1875. $scope.checkboxes = {
  1876. checked : false
  1877. };
  1878. // 点击勾选全部的复选框
  1879. $scope.checkAll = function(){
  1880. angular.forEach($scope.tableParams.data, function(item) {
  1881. item.$selected = $scope.checkboxes.checked;
  1882. });
  1883. };
  1884. // 点击其中一个明细的复选框
  1885. $scope.checkOne = function(order){
  1886. var result = true;
  1887. angular.forEach($scope.tableParams.data, function(item) {
  1888. if(item.$selected != true){
  1889. result = false;
  1890. return;
  1891. }
  1892. });
  1893. $scope.checkboxes.checked = result;
  1894. };
  1895. // 搜索框回车
  1896. $scope.onSearch = function(keyword) {
  1897. $scope.tableParams.page(1);
  1898. $scope.tableParams.reload();
  1899. $scope.tip = keyword;
  1900. };
  1901. // 选择查找日期
  1902. $scope.onDateCondition = function(){
  1903. $scope.tableParams.page(1);
  1904. $scope.tableParams.reload();
  1905. };
  1906. }]);
  1907. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1908. var loadData = function() {
  1909. PurcOrder.get({id: $stateParams.id}, function(data){
  1910. $scope.order = data;
  1911. var sum = 0;
  1912. angular.forEach($scope.order.orderItems, function(item){
  1913. sum += item.qty * item.price;
  1914. });
  1915. $scope.order.total = sum;
  1916. if($scope.order.display == 1) {//未查看的设为已查看
  1917. $scope.setDisplay('setRead', $scope.order.id);
  1918. }
  1919. $scope.loading = false;
  1920. });
  1921. };
  1922. loadData();
  1923. $scope.getReply = function(item) {
  1924. if(!item.replies) {
  1925. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1926. item.replies = replies;
  1927. });
  1928. }
  1929. };
  1930. $scope.openDatePicker = function($event, item, openParam) {
  1931. $event.preventDefault();
  1932. $event.stopPropagation();
  1933. item[openParam] = !item[openParam];
  1934. };
  1935. $scope.onReplyClick = function(item, inverse) {
  1936. if(item.reply) {
  1937. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1938. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1939. return;
  1940. }
  1941. var reply = angular.copy(item.reply);
  1942. if(reply.delivery) {
  1943. if(typeof reply.delivery == 'object')
  1944. reply.delivery = reply.delivery.getTime();
  1945. } else {
  1946. reply.delivery = item.delivery;
  1947. }
  1948. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1949. $scope.loading = true;
  1950. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1951. $scope.loading = false;
  1952. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1953. loadData();
  1954. }, function(response){
  1955. $scope.loading = false;
  1956. toaster.pop('error', '回复失败', response.data);
  1957. });
  1958. }
  1959. };
  1960. // // 采购单
  1961. // $scope.print = function(order) {
  1962. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  1963. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1964. // };
  1965. //设置为已查看
  1966. $scope.setDisplay = function(state, orderId) {
  1967. if(orderId) {//设置单个
  1968. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1969. // $scope.tableParams.reload();
  1970. }, function() {
  1971. toaster.pop('error', '错误', "设置失败");
  1972. });
  1973. } else {//设置已勾选的
  1974. var str = null;
  1975. angular.forEach($scope.tableParams.data, function(order) {
  1976. if(order.$selected == true) {
  1977. if(str != null && str != '') str += ',';
  1978. str += order.id;
  1979. }
  1980. });
  1981. if(str != null && str != '') {
  1982. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1983. $scope.tableParams.reload();
  1984. }, function() {
  1985. toaster.pop('error', '错误', "设置失败");
  1986. });
  1987. }
  1988. }
  1989. };
  1990. }]);
  1991. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  1992. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  1993. BaseService.scrollBackToTop();
  1994. $scope.active = 'todo';
  1995. $scope.dateZoneText = '不限';
  1996. $scope.deliveryZoneText = '不限';
  1997. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1998. $scope.changeDateZone = function(zone) {
  1999. $scope.condition.dateZone = zone;
  2000. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2001. $scope.condition.$dateZoneOpen = false;
  2002. getDateCondition(zone, $scope.condition);
  2003. $scope.tableParams.reload();
  2004. };
  2005. $scope.changeDeliveryZone = function(zone) {
  2006. $scope.condition.deliveryZoneText = zone;
  2007. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2008. $scope.condition.$delievryZoneOpen = false;
  2009. getDelveryCondition(zone, $scope.condition);
  2010. $scope.tableParams.reload();
  2011. };
  2012. // 切换单据类型
  2013. $scope.setActive = function(state) {
  2014. if($scope.active != state) {
  2015. $scope.active = state;
  2016. if($scope.tableParams.page() == 1)
  2017. $scope.tableParams.reload();
  2018. else
  2019. $scope.tableParams.page(1);
  2020. }
  2021. };
  2022. // 切换数据来源(正常数据 or 历史数据)
  2023. var getService = function() {
  2024. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  2025. };
  2026. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2027. page : 1,
  2028. count : 5,
  2029. sorting: {
  2030. display: 'desc',
  2031. date: 'desc',
  2032. id: 'desc'
  2033. }
  2034. }, {
  2035. total : 0,
  2036. counts: [5, 10, 15, 25, 50],
  2037. getData : function($defer, params) { // 获取数据的方法
  2038. $scope.loading = true;
  2039. var pageParams = params.url();
  2040. pageParams.searchFilter = { // 筛选条件
  2041. keyword: $scope.keyword,
  2042. fromDate: getDateTime($scope.condition.dateFrom),
  2043. endDate: getDateTime($scope.condition.dateTo)
  2044. };
  2045. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2046. $scope.loading = false;
  2047. if(page) {
  2048. $defer.resolve(page.content);
  2049. params.total(page.totalElement);
  2050. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2051. }
  2052. }, function(response){
  2053. $scope.loading = false;
  2054. toaster.pop('error', '数据加载失败', response.data);
  2055. });
  2056. }
  2057. });
  2058. $scope.getOrderTotal = function(items) {
  2059. var sum = 0;
  2060. angular.forEach(items, function(item){
  2061. sum += item.qty * item.price;
  2062. });
  2063. return sum;
  2064. };
  2065. $scope.openDatePicker = function($event, item, openParam) {
  2066. $event.preventDefault();
  2067. $event.stopPropagation();
  2068. item[openParam] = !item[openParam];
  2069. };
  2070. $scope.parseDate = function(dateStr) {
  2071. if(dateStr)
  2072. return Date.parse(dateStr, 'yyyy-MM-dd');
  2073. return new Date();
  2074. };
  2075. $scope.onReplyClick = function(item, inverse) {
  2076. if(item.reply) {
  2077. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2078. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2079. return;
  2080. }
  2081. var reply = angular.copy(item.reply);
  2082. if(reply.delivery) {
  2083. if(typeof reply.delivery == 'object')
  2084. reply.delivery = reply.delivery.getTime();
  2085. } else {
  2086. reply.delivery = item.delivery;
  2087. }
  2088. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2089. $scope.loading = true;
  2090. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2091. $scope.loading = false;
  2092. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2093. $scope.tableParams.reload();
  2094. }, function(response){
  2095. $scope.loading = false;
  2096. toaster.pop('error', '回复失败', response.data);
  2097. });
  2098. }
  2099. };
  2100. //打印 采购单
  2101. $scope.print = function(order) {
  2102. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2103. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2104. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2105. };
  2106. $scope.getReply = function(item) {
  2107. if(!item.replies) {
  2108. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2109. item.replies = replies;
  2110. });
  2111. }
  2112. };
  2113. $scope.checkboxes = {
  2114. checked : false
  2115. };
  2116. // 点击勾选全部的复选框
  2117. $scope.checkAll = function(){
  2118. angular.forEach($scope.tableParams.data, function(item) {
  2119. item.$selected = $scope.checkboxes.checked;
  2120. });
  2121. };
  2122. // 点击其中一个明细的复选框
  2123. $scope.checkOne = function(order){
  2124. var result = true;
  2125. angular.forEach($scope.tableParams.data, function(item) {
  2126. if(item.$selected != true){
  2127. result = false;
  2128. return;
  2129. }
  2130. });
  2131. $scope.checkboxes.checked = result;
  2132. };
  2133. //批量回复采购订单
  2134. $scope.replyByBatch = function() {
  2135. $scope.loading = true;
  2136. var str = '';
  2137. angular.forEach($scope.tableParams.data, function(order) {
  2138. if(order.$selected == true) {
  2139. angular.forEach(order.orderItems, function(item){
  2140. str += item.id;
  2141. str += ',';
  2142. });
  2143. }
  2144. });
  2145. if(!(str == '')) {
  2146. str = str.substr(0, str.length-1);
  2147. PurcOrderItem.replyByBatch(str, function(){
  2148. $scope.loading = false;
  2149. $scope.tableParams.reload();
  2150. toaster.pop('success', '提示', '批量回复成功');
  2151. }, function(data){
  2152. $scope.loading = false;
  2153. toaster.pop('error', '批量回复失败', data);
  2154. });
  2155. } else {//没有勾选其中的明细
  2156. $scope.loading = false;
  2157. }
  2158. };
  2159. // 搜索框回车
  2160. $scope.onSearch = function() {
  2161. $scope.tableParams.page(1);
  2162. $scope.tableParams.reload();
  2163. };
  2164. // 选择查找日期
  2165. $scope.onDateCondition = function(){
  2166. $scope.tableParams.page(1);
  2167. $scope.tableParams.reload();
  2168. };
  2169. //设置为已查看
  2170. $scope.setDisplay = function(state, orderId) {
  2171. if(orderId) {//设置单个
  2172. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2173. $scope.tableParams.reload();
  2174. }, function() {
  2175. toaster.pop('error', '错误', "设置失败");
  2176. });
  2177. } else {//设置已勾选的
  2178. var str = null;
  2179. angular.forEach($scope.tableParams.data, function(order) {
  2180. if(order.$selected == true) {
  2181. if(str != null && str != '') str += ',';
  2182. str += order.id;
  2183. }
  2184. });
  2185. if(str != null && str != '') {
  2186. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2187. $scope.tableParams.reload();
  2188. }, function() {
  2189. toaster.pop('error', '错误', "设置失败");
  2190. });
  2191. }
  2192. }
  2193. };
  2194. }]);
  2195. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2196. var loadData = function() {
  2197. PurcOrder.get({id: $stateParams.id}, function(data){
  2198. $scope.order = data;
  2199. var sum = 0;
  2200. angular.forEach($scope.order.orderItems, function(item){
  2201. sum += item.qty * item.price;
  2202. });
  2203. $scope.order.total = sum;
  2204. if($scope.order.display == 1) {//未查看的设为已查看
  2205. $scope.setDisplay('setRead', $scope.order.id);
  2206. }
  2207. $scope.loading = false;
  2208. });
  2209. };
  2210. loadData();
  2211. $scope.getReply = function(item) {
  2212. if(!item.replies) {
  2213. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2214. item.replies = replies;
  2215. });
  2216. }
  2217. };
  2218. $scope.openDatePicker = function($event, item, openParam) {
  2219. $event.preventDefault();
  2220. $event.stopPropagation();
  2221. item[openParam] = !item[openParam];
  2222. };
  2223. $scope.onReplyClick = function(item, inverse) {
  2224. if(item.reply) {
  2225. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2226. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2227. return;
  2228. }
  2229. var reply = angular.copy(item.reply);
  2230. if(reply.delivery) {
  2231. if(typeof reply.delivery == 'object')
  2232. reply.delivery = reply.delivery.getTime();
  2233. } else {
  2234. reply.delivery = item.delivery;
  2235. }
  2236. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2237. $scope.loading = true;
  2238. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2239. $scope.loading = false;
  2240. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2241. loadData();
  2242. }, function(response){
  2243. $scope.loading = false;
  2244. toaster.pop('error', '回复失败', response.data);
  2245. });
  2246. }
  2247. };
  2248. // 采购单
  2249. $scope.print = function(order) {
  2250. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2251. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2252. };
  2253. //设置为已查看
  2254. $scope.setDisplay = function(state, orderId) {
  2255. if(orderId) {//设置单个
  2256. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2257. $scope.tableParams.reload();
  2258. }, function() {
  2259. toaster.pop('error', '错误', "设置失败");
  2260. });
  2261. } else {//设置已勾选的
  2262. var str = null;
  2263. angular.forEach($scope.tableParams.data, function(order) {
  2264. if(order.$selected == true) {
  2265. if(str != null && str != '') str += ',';
  2266. str += order.id;
  2267. }
  2268. });
  2269. if(str != null && str != '') {
  2270. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2271. $scope.tableParams.reload();
  2272. }, function() {
  2273. toaster.pop('error', '错误', "设置失败");
  2274. });
  2275. }
  2276. }
  2277. };
  2278. }]);
  2279. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  2280. BaseService.scrollBackToTop();
  2281. $scope.active = 'todo';
  2282. $scope.agreedText = '全部';
  2283. $scope.dateZoneText = '一个月内';
  2284. $scope.condition = {dateZone: 1};
  2285. $scope.changeAgreed = function(agreed) {
  2286. $scope.condition.agreed = agreed;
  2287. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2288. $scope.condition.$agreedOpen = false;
  2289. };
  2290. $scope.changeDateZone = function(zone) {
  2291. $scope.condition.dateZone = zone;
  2292. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2293. $scope.condition.$dateZoneOpen = false;
  2294. };
  2295. $scope.setActive = function(state) {
  2296. if($scope.active != state) {
  2297. $scope.active = state;
  2298. if($scope.tableParams.page() == 1)
  2299. $scope.tableParams.reload();
  2300. else
  2301. $scope.tableParams.page(1);
  2302. }
  2303. };
  2304. var getService = function() {
  2305. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2306. };
  2307. $scope.tableParams = new ngTableParams({
  2308. page : 1,
  2309. count : 5,
  2310. sorting: {
  2311. date: 'desc'
  2312. }
  2313. }, {
  2314. total : 0,
  2315. counts: [5, 10, 25, 50],
  2316. getData : function($defer, params) {
  2317. $scope.loading = true;
  2318. var pageParams = params.url();
  2319. pageParams.keyword = $scope.keyword;
  2320. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2321. $scope.loading = false;
  2322. if(page) {
  2323. params.total(page.totalElement);
  2324. $defer.resolve(page.content);
  2325. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2326. }
  2327. }, function(response){
  2328. $scope.loading = false;
  2329. toaster.pop('error', '数据加载失败', response.data);
  2330. });
  2331. }
  2332. });
  2333. $scope.openDatePicker = function($event, item, openParam) {
  2334. $event.preventDefault();
  2335. $event.stopPropagation();
  2336. item[openParam] = !item[openParam];
  2337. };
  2338. $scope.onReplyClick = function(change) {
  2339. if(change.$agreed) {
  2340. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2341. $scope.loading = true;
  2342. PurcChange.reply({changeId: change.id}, reply, function(){
  2343. $scope.loading = false;
  2344. toaster.pop('info', '提示', '回复成功');
  2345. $scope.tableParams.reload();
  2346. }, function(response){
  2347. $scope.loading = false;
  2348. toaster.pop('error', '回复失败', response.data);
  2349. });
  2350. }
  2351. };
  2352. // 搜索框回车
  2353. $scope.onSearch = function() {
  2354. $scope.tableParams.page(1);
  2355. $scope.tableParams.reload();
  2356. };
  2357. }]);
  2358. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2359. var loadData = function() {
  2360. PurcChange.get({id: $stateParams.id}, function(data){
  2361. $scope.change = data;
  2362. });
  2363. };
  2364. loadData();
  2365. $scope.openDatePicker = function($event, item, openParam) {
  2366. $event.preventDefault();
  2367. $event.stopPropagation();
  2368. item[openParam] = !item[openParam];
  2369. };
  2370. $scope.onReplyClick = function(change) {
  2371. if(change.$agreed) {
  2372. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2373. PurcChange.reply({changeId: change.id}, reply, function(){
  2374. toaster.pop('info', '提示', '回复成功');
  2375. loadData();
  2376. }, function(response){
  2377. toaster.pop('error', '回复失败', response.data);
  2378. });
  2379. }
  2380. };
  2381. }]);
  2382. //采购询价
  2383. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  2384. BaseService.scrollBackToTop();
  2385. $scope.active = 'todo';
  2386. $scope.agreedText = '全部';
  2387. $scope.dateZoneText = '一个月内';
  2388. $scope.condition = {dateZone: 1};
  2389. $scope.changeAgreed = function(agreed) {
  2390. $scope.condition.agreed = agreed;
  2391. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2392. $scope.condition.$agreedOpen = false;
  2393. };
  2394. $scope.changeDateZone = function(zone) {
  2395. $scope.condition.dateZone = zone;
  2396. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2397. $scope.condition.$dateZoneOpen = false;
  2398. };
  2399. $scope.setActive = function(state) {
  2400. if($scope.active != state) {
  2401. $scope.active = state;
  2402. if($scope.tableParams.page() == 1)
  2403. $scope.tableParams.reload();
  2404. else
  2405. $scope.tableParams.page(1);
  2406. }
  2407. };
  2408. // 得到消息
  2409. PurcInquiry.getMessage({}, function(data){
  2410. console.log(data);
  2411. $scope.message = data;
  2412. }, function(response) {
  2413. });
  2414. var getService = function() {
  2415. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2416. };
  2417. $scope.tableParams = new ngTableParams({
  2418. page : 1,
  2419. count : 5,
  2420. sorting: {
  2421. 'inquiry.date': 'desc',
  2422. 'inquiry.enterprise.enName': 'asc',
  2423. 'inquiry.code': 'asc'
  2424. }
  2425. }, {
  2426. total : 0,
  2427. counts: [5, 10, 25, 50],
  2428. getData : function($defer, params) {
  2429. $scope.loading = true;
  2430. var pageParams = params.url();
  2431. var realActive = {};
  2432. pageParams.keyword = $scope.keyword;
  2433. if ($scope.active == 'overdue') {
  2434. $scope.active = 'end';
  2435. }
  2436. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2437. $scope.loading = false;
  2438. if(page) {
  2439. params.total(page.totalElement);
  2440. $defer.resolve(page.content);
  2441. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2442. }
  2443. }, function(response){
  2444. $scope.loading = false;
  2445. toaster.pop('error', '数据加载失败', response.data);
  2446. });
  2447. }
  2448. });
  2449. $scope.getMinDate = function(item) {
  2450. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2451. };
  2452. $scope.replyPrices = [];
  2453. $scope.replylapQtys = [];
  2454. $scope.replyPrices.push(true);
  2455. $scope.replylapQtys.push(true);
  2456. $scope.addStep = function(inquiryItem) {
  2457. $scope.replyPrices.push(true);
  2458. if(inquiryItem.replies.length >= 10) {
  2459. toaster.pop('warning', '提示', '最多支持10个分段!');
  2460. } else {
  2461. inquiryItem.replies.push({});
  2462. if(inquiryItem.replies.length != 1) {
  2463. $scope.replyPrices.push(true);
  2464. $scope.replylapQtys.push(true);
  2465. }
  2466. }
  2467. };
  2468. $scope.removeStep = function(inquiryItem, stepIndex) {
  2469. inquiryItem.replies.splice(stepIndex, 1);
  2470. $scope.replyPrices.splice(stepIndex, 1);
  2471. $scope.replylapQtys.splice(stepIndex, 1);
  2472. };
  2473. $scope.openDatePicker = function($event, item, openParam) {
  2474. $event.preventDefault();
  2475. $event.stopPropagation();
  2476. item[openParam] = !item[openParam];
  2477. };
  2478. $scope.getHistory = function(item) {
  2479. if(!item.history) {
  2480. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2481. item.history = data;
  2482. });
  2483. }
  2484. };
  2485. $scope.isValid = function(item, withSteps) {
  2486. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2487. if(!withSteps || !bool)
  2488. return bool;
  2489. angular.forEach(item.replies, function(r, i){
  2490. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2491. });
  2492. return bool;
  2493. };
  2494. $scope.onReplyClick = function(item, withSteps) {
  2495. if(item.vendFromDate instanceof Date) {
  2496. item.vendFromDate = item.vendFromDate.getTime();
  2497. }
  2498. if(item.vendToDate instanceof Date) {
  2499. item.vendToDate = item.vendToDate.getTime();
  2500. }
  2501. if(item.vendFromDate > item.vendToDate) {
  2502. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2503. return;
  2504. }
  2505. var replies = [];
  2506. angular.forEach(item.replies, function(r, i){
  2507. if((i > 0 ? r.lapQty : 1) || r.price)
  2508. replies.push(r);
  2509. });
  2510. item.replies = replies;
  2511. $scope.loading = true;
  2512. if(withSteps) {
  2513. PurcInquiry.reply({itemId: item.id}, item, function(){
  2514. $scope.loading = false;
  2515. toaster.pop('info', '提示', '报价成功');
  2516. $scope.tableParams.reload();
  2517. }, function(response){
  2518. $scope.loading = false;
  2519. toaster.pop('error', '报价失败', response.data);
  2520. });
  2521. } else {
  2522. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2523. $scope.loading = false;
  2524. toaster.pop('info', '提示', '保存成功');
  2525. $scope.tableParams.reload();
  2526. }, function(response){
  2527. $scope.loading = false;
  2528. toaster.pop('error', '保存失败', response.data);
  2529. });
  2530. }
  2531. };
  2532. $scope.verifylapQty = function(value,type) {
  2533. var regex = /^\d+(.\d{1,5})?$/;
  2534. $scope.replylapQtys[type] = regex.test(value);
  2535. }
  2536. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2537. $scope.verify = function(value,type) {
  2538. var regex = /^\d+(.\d{1,5})?$/;//
  2539. switch(type) {
  2540. case 'minOrderQty':
  2541. $scope.minOrderQtyVerify = regex.test(value);
  2542. break;
  2543. case 'minPackQty':
  2544. $scope.minPackQtyVerify = regex.test(value);
  2545. break;
  2546. case 'leadtime':
  2547. $scope.leadtimeVerify = regex.test(value);
  2548. break;
  2549. default:
  2550. $scope.replyPrices[type] = regex.test(value);
  2551. break;
  2552. }
  2553. }
  2554. // 搜索框回车
  2555. $scope.onSearch = function() {
  2556. $scope.tableParams.page(1);
  2557. $scope.tableParams.reload();
  2558. };
  2559. }]);
  2560. // 询价单明细
  2561. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2562. var loadData = function() {
  2563. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2564. $scope.newinquiryItems = data;
  2565. var inquiry = data[0].inquiry;
  2566. //inquiry.inquiryItems = data;
  2567. angular.forEach(inquiry.attachs, function(attach){
  2568. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2569. });
  2570. $scope.inquiry = inquiry;
  2571. });
  2572. };
  2573. loadData();
  2574. $scope.getMinDate = function(item) {
  2575. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2576. };
  2577. $scope.addStep = function(inquiryItem) {
  2578. if(inquiryItem.replies.length >= 10) {
  2579. toaster.pop('warning', '提示', '最多支持10个分段!');
  2580. } else
  2581. inquiryItem.replies.push({});
  2582. };
  2583. $scope.removeStep = function(inquiryItem, stepIndex) {
  2584. inquiryItem.replies.splice(stepIndex, 1);
  2585. };
  2586. $scope.openDatePicker = function($event, item, openParam) {
  2587. $event.preventDefault();
  2588. $event.stopPropagation();
  2589. item[openParam] = !item[openParam];
  2590. };
  2591. $scope.getHistory = function(item) {
  2592. if(!item.history) {
  2593. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2594. item.history = data;
  2595. });
  2596. }
  2597. };
  2598. $scope.isValid = function(item, withSteps) {
  2599. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2600. if(!withSteps || !bool)
  2601. return bool;
  2602. angular.forEach(item.replies, function(r, i){
  2603. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2604. });
  2605. return bool;
  2606. };
  2607. $scope.onReplyClick = function(item, withSteps) {
  2608. if(item.vendFromDate instanceof Date) {
  2609. item.vendFromDate = item.vendFromDate.getTime();
  2610. }
  2611. if(item.vendToDate instanceof Date) {
  2612. item.vendToDate = item.vendToDate.getTime();
  2613. }
  2614. if(item.vendFromDate > item.vendToDate) {
  2615. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2616. return;
  2617. }
  2618. var replies = [];
  2619. angular.forEach(item.replies, function(r, i){
  2620. if((i > 0 ? r.lapQty : 1) || r.price)
  2621. replies.push(r);
  2622. });
  2623. item.replies = replies;
  2624. if(withSteps) {
  2625. PurcInquiry.reply({itemId: item.id}, item, function(){
  2626. toaster.pop('info', '提示', '报价成功');
  2627. loadData();
  2628. }, function(response){
  2629. toaster.pop('error', '报价失败', response.data);
  2630. });
  2631. }
  2632. };
  2633. }]);
  2634. // 平台新增的询价单
  2635. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', function($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout) {
  2636. BaseService.scrollBackToTop();
  2637. $scope.status = 'InquiryNew';
  2638. $scope.active = 'all';
  2639. $rootScope.tenderVendor = null;// 清除掉已选择的
  2640. var getService = function() {
  2641. return GetProductInfo;
  2642. };
  2643. $scope.inquiry = {
  2644. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  2645. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  2646. priceType: '采购'
  2647. };
  2648. $scope.currentDay = function() {
  2649. return $filter('date')(new Date(), 'yyyy-MM-dd');
  2650. };
  2651. $scope.vendors = [];
  2652. // 查找供应商
  2653. $scope.dbfindVendor = function(){
  2654. var modalInstance = $modal.open({
  2655. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  2656. controller: 'DbfindVendorCtrl',
  2657. size: 'lg',
  2658. resolve: {
  2659. }
  2660. });
  2661. modalInstance.result.then(function(data){
  2662. var ifPush = true;
  2663. modalInstance.result.then(function(data){
  2664. angular.forEach(data, function(vendor) {
  2665. if (!$scope.vendors) {// 不存在就先创建
  2666. $scope.vendors = [{}];
  2667. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  2668. } else {
  2669. for (var i = 0;i<$scope.vendors.length; i++) {
  2670. ifPush = true;
  2671. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  2672. ifPush = false;
  2673. break; // 判定到已存在供应商,就终止循环。
  2674. }
  2675. }
  2676. if (ifPush) {
  2677. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  2678. }
  2679. }
  2680. });
  2681. $rootScope.tenderVendor = $scope.vendors;
  2682. }, function(){
  2683. });
  2684. }, function(){
  2685. });
  2686. };
  2687. // 删除一个供应商
  2688. $scope.removeVendor = function(index) {
  2689. $scope.vendors.splice(index, 1);
  2690. };
  2691. // 物料信息
  2692. $scope.tableParams = new ngTableParams({
  2693. page : 1,
  2694. count : 5,
  2695. sorting: {
  2696. }
  2697. }, {
  2698. total : 0,
  2699. counts: [5, 10, 25, 50],
  2700. getData : function($defer, params) {
  2701. $scope.loading = true;
  2702. var pageParams = params.url();
  2703. pageParams.keyword = $scope.keyword;
  2704. $scope.tip = $scope.keyword;
  2705. pageParams.searchFilter = $scope.searchFilter;
  2706. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2707. $scope.loading = false;
  2708. if(page) {
  2709. params.total(page.totalElement);
  2710. $scope.total = page.totalElement;
  2711. $defer.resolve(page.content);
  2712. }
  2713. }, function(response) {
  2714. $scope.loading = false;
  2715. toaster.pop('error', '数据加载失败', response.data);
  2716. });
  2717. }
  2718. });
  2719. // 搜索框回车
  2720. $scope.onSearch = function(keyword) {
  2721. $scope.tableParams.page(1);
  2722. $scope.tableParams.reload();
  2723. };
  2724. $scope.inquiry.inquiryItems = [];
  2725. //删除商品
  2726. $scope.del = function(index) {
  2727. $scope.inquiry.inquiryItems.splice(index, 1);
  2728. };
  2729. $scope.check = function(product) {
  2730. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  2731. currency: null, toDate: null, productId: product.id});
  2732. }
  2733. $scope.getMinDate = function(item) {
  2734. return $filter('date')(new Date, 'yyyy-MM-dd');
  2735. };
  2736. $scope.openDatePicker = function($event, openParam, index) {
  2737. $event.preventDefault();
  2738. $event.stopPropagation();
  2739. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  2740. };
  2741. $scope.openEndDatePicker = function($event, item, openParam) {
  2742. $event.preventDefault();
  2743. $event.stopPropagation();
  2744. item[openParam] = !item[openParam];
  2745. };
  2746. // 保存
  2747. $scope.save = function() {
  2748. // var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  2749. // $upload.upload({
  2750. // url: 'product/baseInfo/updateProdInfo',
  2751. // file: file,
  2752. // method: 'POST',
  2753. // data: {
  2754. // prodInfo: $scope.prodInfo
  2755. // },
  2756. // }).success(function(data) {
  2757. // if(data.success) {
  2758. // toaster.pop('success', '提示', data.success);
  2759. // window.location.reload();
  2760. // }
  2761. // if(data.error) {
  2762. // toaster.pop('error', '提示', data.error);
  2763. // }
  2764. // }).error(function(data) {
  2765. // $scope.loadingShow = false;
  2766. // toaster.pop('error', '操作失败', data.error);
  2767. // });
  2768. PurchaseInquiry.save({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  2769. if(data.success) {
  2770. toaster.pop('success', '提示', data.success);
  2771. $timeout(function() {
  2772. window.loaction.hash = "#/purc/inquiry_unapply";
  2773. }, 500);
  2774. }
  2775. if(data.error) {
  2776. toaster.pop('error', '提示', data.error);
  2777. }
  2778. }, function(response) {
  2779. toaster.pop('error', '提示', response.data);
  2780. });
  2781. }
  2782. // 保存并提交
  2783. $scope.submit = function() {
  2784. PurchaseInquiry.submit({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  2785. if(data.success) {
  2786. toaster.pop('success', '提示', data.success);
  2787. $timeout(function() {
  2788. window.location.hash = "#/purc/inquiry_unapply";
  2789. }, 500);
  2790. }
  2791. if(data.error) {
  2792. toaster.pop('error', '提示', data.error);
  2793. }
  2794. }, function(response) {
  2795. toaster.pop('error', '提示', response.data);
  2796. });
  2797. }
  2798. }]);
  2799. // 平台询价单(已提交)
  2800. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry) {
  2801. $scope.status = 'InquirySubmit';
  2802. BaseService.scrollBackToTop();
  2803. $scope.active = 'todo';
  2804. $scope.agreedText = '全部';
  2805. $scope.dateZoneText = '一个月内';
  2806. $scope.condition = {dateZone: 1};
  2807. $scope.changeAgreed = function(agreed) {
  2808. $scope.condition.agreed = agreed;
  2809. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2810. $scope.condition.$agreedOpen = false;
  2811. };
  2812. $scope.changeDateZone = function(zone) {
  2813. $scope.condition.dateZone = zone;
  2814. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2815. $scope.condition.$dateZoneOpen = false;
  2816. };
  2817. $scope.setActive = function(state) {
  2818. if($scope.active != state ) {
  2819. $scope.active = state;
  2820. if ($scope.tableParams.page() == 1) {
  2821. $scope.tableParams.reload();
  2822. } else {
  2823. $scope.tableParams.page(1);
  2824. }
  2825. }
  2826. }
  2827. var getService = function() {
  2828. return PurchaseInquiry;
  2829. };
  2830. $scope.tableParams = new ngTableParams({
  2831. page : 1,
  2832. count : 5,
  2833. sorting: {
  2834. 'inquiry.date': 'desc',
  2835. 'inquiry.enterprise.enName': 'asc',
  2836. 'inquiry.code': 'asc'
  2837. }
  2838. }, {
  2839. total : 0,
  2840. counts: [5, 10, 25, 50],
  2841. getData : function($defer, params) {
  2842. $scope.loading = true;
  2843. var pageParams = params.url();
  2844. var realActive = {};
  2845. pageParams.keyword = $scope.keyword;
  2846. if ($scope.active == 'overdue') {
  2847. $scope.active = 'end';
  2848. }
  2849. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2850. $scope.loading = false;
  2851. if(page) {
  2852. params.total(page.totalElement);
  2853. $defer.resolve(page.content);
  2854. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2855. }
  2856. }, function(response){
  2857. $scope.loading = false;
  2858. toaster.pop('error', '数据加载失败', response.data);
  2859. });
  2860. }
  2861. });
  2862. $scope.openDatePicker = function($event, item, openParam) {
  2863. $event.preventDefault();
  2864. $event.stopPropagation();
  2865. item[openParam] = !item[openParam];
  2866. };
  2867. // 搜索框回车
  2868. $scope.onSearch = function() {
  2869. $scope.tableParams.page(1);
  2870. $scope.tableParams.reload();
  2871. };
  2872. // 采纳
  2873. $scope.accept = function(id) {
  2874. PurchaseInquiry.accept({id: id}, {}, function(data) {
  2875. if(data.success) {
  2876. toaster.pop('success', '提示', data.success);
  2877. $scope.tableParams.reload();
  2878. }
  2879. if(data.error) {
  2880. toaster.pop('error', '提示', data.error);
  2881. }
  2882. }, function(response) {
  2883. toaster.pop('error', '提示', response.data);
  2884. })
  2885. };
  2886. // 拒绝
  2887. $scope.refuse = function(id) {
  2888. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  2889. if(data.success) {
  2890. toaster.pop('success', '提示', data.success);
  2891. $scope.tableParams.reload();
  2892. }
  2893. if(data.error) {
  2894. toaster.pop('error', '提示', data.error);
  2895. }
  2896. }, function(response) {
  2897. toaster.pop('error', '提示', response.data);
  2898. })
  2899. }
  2900. }]);
  2901. // 平台询价单(未提交)
  2902. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster) {
  2903. BaseService.scrollBackToTop();
  2904. $scope.status = 'InquiryUnSubmit';
  2905. $scope.tableParams = new ngTableParams({
  2906. page : 1,
  2907. count : 5,
  2908. sorting: {
  2909. 'inquiry.date': 'desc',
  2910. 'inquiry.enterprise.enName': 'asc',
  2911. 'inquiry.code': 'asc'
  2912. }
  2913. }, {
  2914. total : 0,
  2915. counts: [5, 10, 25, 50],
  2916. getData : function($defer, params) {
  2917. $scope.loading = true;
  2918. var pageParams = params.url();
  2919. var realActive = {};
  2920. if ($scope.active == 'overdue') {
  2921. $scope.active = 'end';
  2922. }
  2923. PurchaseInquiry.getUnapply(null, BaseService.parseParams(pageParams), function(page){
  2924. $scope.loading = false;
  2925. if(page) {
  2926. params.total(page.totalElements);
  2927. $defer.resolve(page.content);
  2928. }
  2929. }, function(response){
  2930. $scope.loading = false;
  2931. toaster.pop('error', '数据加载失败', response.data);
  2932. });
  2933. }
  2934. });
  2935. // 删除明细
  2936. $scope.deleteById = function(id) {
  2937. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  2938. toaster.pop('success', '提示', '删除成功');
  2939. $scope.tableParams.reload();
  2940. }, function(response) {
  2941. toaster.pop('error', '提示', response.data);
  2942. });
  2943. }
  2944. // 删除主表
  2945. $scope.clearOrder = function(id) {
  2946. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  2947. toaster.pop('success', '提示', '删除成功');
  2948. $scope.tableParams.reload();
  2949. }, function(response) {
  2950. toaster.pop('error', '提示', response.data);
  2951. });
  2952. }
  2953. // 提交
  2954. $scope.submit = function(id) {
  2955. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  2956. toaster.pop('success', '提示', '单据提交成功');
  2957. }, function(response) {
  2958. toaster.pop('error', '提示', response.data);
  2959. })
  2960. }
  2961. }]);
  2962. // 询价单明细
  2963. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2964. var loadData = function() {
  2965. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2966. $scope.newinquiryItems = data;
  2967. var inquiry = data[0].inquiry;
  2968. //inquiry.inquiryItems = data;
  2969. angular.forEach(inquiry.attachs, function(attach){
  2970. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2971. });
  2972. $scope.inquiry = inquiry;
  2973. });
  2974. };
  2975. loadData();
  2976. $scope.getMinDate = function(item) {
  2977. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2978. };
  2979. $scope.addStep = function(inquiryItem) {
  2980. if(inquiryItem.replies.length >= 10) {
  2981. toaster.pop('warning', '提示', '最多支持10个分段!');
  2982. } else
  2983. inquiryItem.replies.push({});
  2984. };
  2985. $scope.removeStep = function(inquiryItem, stepIndex) {
  2986. inquiryItem.replies.splice(stepIndex, 1);
  2987. };
  2988. $scope.openDatePicker = function($event, item, openParam) {
  2989. $event.preventDefault();
  2990. $event.stopPropagation();
  2991. item[openParam] = !item[openParam];
  2992. };
  2993. $scope.getHistory = function(item) {
  2994. if(!item.history) {
  2995. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2996. item.history = data;
  2997. });
  2998. }
  2999. };
  3000. $scope.isValid = function(item, withSteps) {
  3001. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3002. if(!withSteps || !bool)
  3003. return bool;
  3004. angular.forEach(item.replies, function(r, i){
  3005. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3006. });
  3007. return bool;
  3008. };
  3009. $scope.onReplyClick = function(item, withSteps) {
  3010. if(item.vendFromDate instanceof Date) {
  3011. item.vendFromDate = item.vendFromDate.getTime();
  3012. }
  3013. if(item.vendToDate instanceof Date) {
  3014. item.vendToDate = item.vendToDate.getTime();
  3015. }
  3016. if(item.vendFromDate > item.vendToDate) {
  3017. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3018. return;
  3019. }
  3020. var replies = [];
  3021. angular.forEach(item.replies, function(r, i){
  3022. if((i > 0 ? r.lapQty : 1) || r.price)
  3023. replies.push(r);
  3024. });
  3025. item.replies = replies;
  3026. if(withSteps) {
  3027. PurcInquiry.reply({itemId: item.id}, item, function(){
  3028. toaster.pop('info', '提示', '报价成功');
  3029. loadData();
  3030. }, function(response){
  3031. toaster.pop('error', '报价失败', response.data);
  3032. });
  3033. }
  3034. };
  3035. }]);
  3036. // 询价单明细(发出)
  3037. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', function($scope, $stateParams, PurchaseInquiry,$filter, toaster){
  3038. var loadData = function() {
  3039. PurchaseInquiry.detail({id: $stateParams.id}, function(data){
  3040. $scope.inquiry = data;
  3041. });
  3042. };
  3043. loadData();
  3044. $scope.getMinDate = function(item) {
  3045. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3046. };
  3047. $scope.addStep = function(inquiryItem) {
  3048. if(inquiryItem.replies.length >= 10) {
  3049. toaster.pop('warning', '提示', '最多支持10个分段!');
  3050. } else
  3051. inquiryItem.replies.push({});
  3052. };
  3053. $scope.removeStep = function(inquiryItem, stepIndex) {
  3054. inquiryItem.replies.splice(stepIndex, 1);
  3055. };
  3056. $scope.openDatePicker = function($event, item, openParam) {
  3057. $event.preventDefault();
  3058. $event.stopPropagation();
  3059. item[openParam] = !item[openParam];
  3060. };
  3061. $scope.getHistory = function(item) {
  3062. if(!item.history) {
  3063. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3064. item.history = data;
  3065. });
  3066. }
  3067. };
  3068. $scope.isValid = function(item, withSteps) {
  3069. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3070. if(!withSteps || !bool)
  3071. return bool;
  3072. angular.forEach(item.replies, function(r, i){
  3073. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3074. });
  3075. return bool;
  3076. };
  3077. $scope.onReplyClick = function(item, withSteps) {
  3078. if(item.vendFromDate instanceof Date) {
  3079. item.vendFromDate = item.vendFromDate.getTime();
  3080. }
  3081. if(item.vendToDate instanceof Date) {
  3082. item.vendToDate = item.vendToDate.getTime();
  3083. }
  3084. if(item.vendFromDate > item.vendToDate) {
  3085. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3086. return;
  3087. }
  3088. var replies = [];
  3089. angular.forEach(item.replies, function(r, i){
  3090. if((i > 0 ? r.lapQty : 1) || r.price)
  3091. replies.push(r);
  3092. });
  3093. item.replies = replies;
  3094. if(withSteps) {
  3095. PurcInquiry.reply({itemId: item.id}, item, function(){
  3096. toaster.pop('info', '提示', '报价成功');
  3097. loadData();
  3098. }, function(response){
  3099. toaster.pop('error', '报价失败', response.data);
  3100. });
  3101. }
  3102. };
  3103. }]);
  3104. // 模具询价管理
  3105. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  3106. BaseService.scrollBackToTop();
  3107. $scope.active = 'todo';
  3108. $scope.agreedText = '全部';
  3109. $scope.dateZoneText = '一个月内';
  3110. $scope.condition = {dateZone: 1};
  3111. var inquiryMould_copy = {};
  3112. $scope.changeAgreed = function(agreed) {
  3113. $scope.condition.agreed = agreed;
  3114. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3115. $scope.condition.$agreedOpen = false;
  3116. };
  3117. $scope.changeDateZone = function(zone) {
  3118. $scope.condition.dateZone = zone;
  3119. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3120. $scope.condition.$dateZoneOpen = false;
  3121. };
  3122. $scope.setActive = function(state) {
  3123. if($scope.active != state ) {
  3124. $scope.active = state;
  3125. if ($scope.tableParams.page() == 1) {
  3126. $scope.tableParams.reload();
  3127. } else {
  3128. $scope.tableParams.page(1);
  3129. }
  3130. }
  3131. }
  3132. var getService = function() {
  3133. return PurcInquiryMould;
  3134. };
  3135. $scope.tableParams = new ngTableParams({
  3136. page: 1,
  3137. count: 5
  3138. },{
  3139. total: 0,
  3140. counts: [5, 10, 25, 50],
  3141. getData: function($defer, params) {
  3142. $scope.loading = true;
  3143. var pageParams = params.url();
  3144. var realActive = {};
  3145. pageParams.keyword = $scope.keyword;
  3146. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3147. $scope.loading = false;
  3148. // 用来验证价格修改
  3149. var mould = page.content;
  3150. inquiryMould_copy = angular.copy(mould);
  3151. if(page) {
  3152. params.total(page.totalElement);
  3153. $defer.resolve(page.content);
  3154. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3155. }
  3156. }, function(response){
  3157. $scope.loading = false;
  3158. toaster.pop('error', '数据加载失败', response.data);
  3159. });
  3160. }
  3161. })
  3162. $scope.getMinDate = function(item) {
  3163. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  3164. };
  3165. $scope.replyPrices = [];
  3166. $scope.replyPrices.push(true);
  3167. // 取消
  3168. $scope.reload = function() {
  3169. $scope.tableParams.reload();
  3170. $scope.canSave = false;
  3171. }
  3172. // 能否保存设置
  3173. $scope.canSave = false;
  3174. // items价格验证
  3175. $scope.verifyItems = function(price, reply) {
  3176. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  3177. if(regex.test(price) && price != 0) {
  3178. if (price != reply) {
  3179. $scope.canSave = true;
  3180. } else {
  3181. $scope.canSave = false;
  3182. }
  3183. } else {
  3184. $scope.canSave = false;
  3185. }
  3186. }
  3187. // prod下prods价格验证
  3188. $scope.verifyProds = function(price, reply) {
  3189. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3190. if(regex.test(price) && price != 0) {
  3191. if (price != reply) {
  3192. $scope.canSave = true;
  3193. } else {
  3194. $scope.canSave = false;
  3195. }
  3196. } else {
  3197. $scope.canSave = false;
  3198. }
  3199. }
  3200. //有价格为0或者不符合正则式,则不能报价
  3201. $scope.notZero = function (mould) {
  3202. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3203. angular.forEach(mould.inquiryMouldItems, function(item){
  3204. if (item.price == 0 || !regex.test(item.price)) {
  3205. $scope.canSave = false;
  3206. }
  3207. angular.forEach(item.inquiryMouldDetails, function(detail){
  3208. if (detail.price == 0 || !regex.test(detail.price)) {
  3209. $scope.canSave = false;
  3210. }
  3211. })
  3212. });
  3213. }
  3214. $scope.blurPrice = function (price) {
  3215. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3216. if (!regex.test(price)) {
  3217. toaster.pop('warning','格式错误','请输入有效价格');
  3218. }
  3219. }
  3220. // 获取历史报价
  3221. $scope.getHistory = function(mould) {
  3222. if(!mould.history) {
  3223. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3224. mould.history = data;
  3225. console.log(mould.history);
  3226. });
  3227. }
  3228. };
  3229. $scope.uploadAttach = function(mould) {
  3230. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3231. var file = mould.attachs[0];
  3232. $scope.mould = mould;
  3233. $upload.upload({
  3234. url: 'sale/mould/' + mould.id + '/send',
  3235. method: 'POST',
  3236. file: file,
  3237. data: {
  3238. json: $scope.mould
  3239. }
  3240. }).success(function(res){
  3241. console.log("success");
  3242. console.log(res);
  3243. }).error(function(res){
  3244. console.log("failure");
  3245. console.log(res);
  3246. });
  3247. }
  3248. // 保存并确认报价
  3249. $scope.onReplyClick = function(mould, withSteps) {
  3250. $scope.loading = true;
  3251. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3252. // var file = mould.attachs[0];
  3253. // $scope.mould = mould;
  3254. // $upload.upload({
  3255. // url: 'sale/mould/' + mould.id + '/send',
  3256. // method: 'POST',
  3257. // file: file,
  3258. // data: {
  3259. // json: $scope.mould
  3260. // }
  3261. // }).success(function(res){
  3262. // console.log("success");
  3263. // console.log(res);
  3264. // }).error(function(res){
  3265. // console.log("failure");
  3266. // });
  3267. if(withSteps) {
  3268. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3269. $scope.loading = false;
  3270. toaster.pop('info', '提示', '报价成功');
  3271. $scope.tableParams.reload();
  3272. $scope.canSave = false;
  3273. }, function(response){
  3274. $scope.loading = false;
  3275. toaster.pop('error', '报价失败', response.data);
  3276. });
  3277. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3278. }, function(response){
  3279. });
  3280. } else {
  3281. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3282. $scope.loading = false;
  3283. toaster.pop('info', '提示', '保存成功');
  3284. $scope.tableParams.reload();
  3285. }, function(response){
  3286. $scope.loading = false;
  3287. toaster.pop('error', '保存失败', response.data);
  3288. });
  3289. }
  3290. };
  3291. // 搜索框回车
  3292. $scope.onSearch = function() {
  3293. $scope.tableParams.page(1);
  3294. $scope.tableParams.reload();
  3295. };
  3296. }]);
  3297. // 模具询价单明细
  3298. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  3299. var inquiryMould_copy = {};
  3300. var loadData = function() {
  3301. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  3302. // 用来验证价格修改
  3303. inquiryMould_copy = angular.copy(data);
  3304. $scope.inquiryMould_copy = inquiryMould_copy;
  3305. $scope.newinquirymould = data;
  3306. var mould = data;
  3307. angular.forEach(mould.attachs, function(attach){
  3308. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3309. });
  3310. $scope.inquiryMould = mould;
  3311. });
  3312. };
  3313. loadData();
  3314. $scope.getMinDate = function(item) {
  3315. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3316. };
  3317. // 取消
  3318. $scope.reload = function() {
  3319. loadData();
  3320. $scope.canSave = false;
  3321. }
  3322. //有价格为0,则不能报价
  3323. $scope.notZero = function (mould) {
  3324. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3325. angular.forEach(mould.inquiryMouldItems, function(item){
  3326. if (item.price == 0 || !regex.test(item.price)) {
  3327. $scope.canSave = false;
  3328. }
  3329. angular.forEach(item.inquiryMouldDetails, function(detail){
  3330. if (detail.price == 0 || !regex.test(detail.price)) {
  3331. $scope.canSave = false;
  3332. }
  3333. })
  3334. });
  3335. }
  3336. $scope.blurPrice = function (price) {
  3337. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3338. if (!regex.test(price)) {
  3339. toaster.pop('warning','格式错误','请输入有效价格');
  3340. }
  3341. }
  3342. // 获取历史报价
  3343. $scope.getHistory = function(mould) {
  3344. if(!mould.history) {
  3345. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3346. mould.history = data;
  3347. console.log(mould.history);
  3348. });
  3349. }
  3350. };
  3351. $scope.canSave = false;
  3352. // items价格验证
  3353. $scope.verifyItems = function(price, index) {
  3354. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3355. if(regex.test(price) && price != 0) {
  3356. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  3357. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  3358. $scope.canSave = true;
  3359. } else {
  3360. $scope.canSave = false;
  3361. }
  3362. } else {
  3363. $scope.canSave = false;
  3364. }
  3365. }
  3366. // prod下prods价格验证
  3367. $scope.verifyProds = function(price, index, parentIndex) {
  3368. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3369. if(regex.test(price) && price != 0) {
  3370. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  3371. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  3372. $scope.canSave = true;
  3373. } else {
  3374. $scope.canSave = false;
  3375. }
  3376. } else {
  3377. $scope.canSave = false;
  3378. }
  3379. }
  3380. // // 上传附件
  3381. // $scope.uploadAttach = function(mould) {
  3382. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3383. // var file = mould.attachs[0];
  3384. // $scope.mould = mould;
  3385. // $upload.upload({
  3386. // url: 'sale/mould/' + mould.id + '/send',
  3387. // method: 'POST',
  3388. // file: file,
  3389. // data: {
  3390. // json: $scope.mould
  3391. // }
  3392. // }).success(function(res){
  3393. // console.log("success");
  3394. // console.log(res);
  3395. // }).error(function(res){
  3396. // console.log("failure");
  3397. // console.log(res);
  3398. // });
  3399. // }
  3400. $scope.onReplyClick = function(mould, withSteps) {
  3401. $scope.loading = true;
  3402. // var file = mould.attachs[0];
  3403. // $scope.mould = mould;
  3404. // $upload.upload({
  3405. // url: 'sale/mould/' + mould.id + '/send',
  3406. // method: 'POST',
  3407. // file: file,
  3408. // data: {
  3409. // json: $scope.mould
  3410. // }
  3411. // }).success(function(res){
  3412. //
  3413. // }).error(function(res){
  3414. // console.log(res);
  3415. // });
  3416. if(withSteps) {
  3417. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3418. $scope.loading = false;
  3419. toaster.pop('info', '提示', '报价成功');
  3420. loadData();
  3421. $scope.canSave = false;
  3422. }, function(response){
  3423. $scope.loading = false;
  3424. toaster.pop('error', '报价失败', response.data);
  3425. });
  3426. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3427. }, function(response){
  3428. });
  3429. } else {
  3430. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3431. $scope.loading = false;
  3432. toaster.pop('info', '提示', '保存成功');
  3433. loadData();
  3434. }, function(response){
  3435. $scope.loading = false;
  3436. toaster.pop('error', '保存失败', response.data);
  3437. });
  3438. }
  3439. };
  3440. }]);
  3441. // 主动报价 - 列表
  3442. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  3443. BaseService.scrollBackToTop();
  3444. $scope.active = 'todo';
  3445. $scope.agreedText = '全部';
  3446. $scope.dateZoneText = '一个月内';
  3447. $scope.condition = {dateZone: 1};
  3448. $scope.changeDateZone = function(zone) {
  3449. $scope.condition.dateZone = zone;
  3450. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3451. $scope.condition.$dateZoneOpen = false;
  3452. };
  3453. $scope.setActive = function(state) {
  3454. if($scope.active != state) {
  3455. $scope.active = state;
  3456. if($scope.tableParams.page() == 1)
  3457. $scope.tableParams.reload();
  3458. else
  3459. $scope.tableParams.page(1);
  3460. }
  3461. };
  3462. var getService = function() {
  3463. return Quotation;
  3464. };
  3465. $scope.tableParams = new ngTableParams({
  3466. page : 1,
  3467. count : 5,
  3468. sorting: {
  3469. 'quotation.date': 'desc'
  3470. }
  3471. }, {
  3472. total : 0,
  3473. counts: [5, 10, 25, 50],
  3474. getData : function($defer, params) {
  3475. $scope.loading = true;
  3476. var pageParams = params.url();
  3477. pageParams.keyword = $scope.keyword;
  3478. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3479. $scope.loading = false;
  3480. if(page) {
  3481. params.total(page.totalElement);
  3482. $defer.resolve(page.content);
  3483. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3484. }
  3485. }, function(response){
  3486. $scope.loading = false;
  3487. toaster.pop('error', '数据加载失败', response.data);
  3488. });
  3489. }
  3490. });
  3491. $scope.getHistory = function(item) {
  3492. if(!item.history) {
  3493. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3494. item.history = data;
  3495. });
  3496. }
  3497. };
  3498. $scope.isValid = function(item, withSteps) {
  3499. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3500. if(!withSteps || !bool)
  3501. return bool;
  3502. angular.forEach(item.replies, function(r, i){
  3503. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3504. });
  3505. return bool;
  3506. };
  3507. // 搜索框回车
  3508. $scope.onSearch = function() {
  3509. $scope.tableParams.page(1);
  3510. $scope.tableParams.reload();
  3511. };
  3512. }]);
  3513. // Controller 主动报价 - 新增
  3514. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope){
  3515. BaseService.scrollBackToTop();
  3516. var staticItem = null;
  3517. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  3518. $scope.loading = true;
  3519. Quotation.getItem({id: $stateParams.id}, function(data){
  3520. data.$editing = false;
  3521. $scope.item = data;
  3522. staticItem = angular.copy(data);
  3523. $scope.loading = false;
  3524. }, function(response){
  3525. $scope.loading = false;
  3526. toaster.pop('error', '数据加载失败', response.data);
  3527. });
  3528. } else {// 新增模式
  3529. $scope.item = {
  3530. quotation: {
  3531. currency: 'RMB',
  3532. taxrate: 17,
  3533. date: new Date()
  3534. },
  3535. product: {},
  3536. prices: [{lapQty: 0}],
  3537. minOrderQty: 1,
  3538. minPackQty: 1,
  3539. $endDateOpen: false,
  3540. $editing: true
  3541. };
  3542. }
  3543. $scope.getMinDate = function(item) {
  3544. return $filter('date')(new Date, 'yyyy-MM-dd');
  3545. };
  3546. $scope.openDatePicker = function($event, openParam) {
  3547. $event.preventDefault();
  3548. $event.stopPropagation();
  3549. $scope.item.$endDateOpen = !openParam;
  3550. };
  3551. // 增加一个分段
  3552. $scope.addPrice = function(){
  3553. if($scope.item.prices.length >= 10) {
  3554. toaster.pop('warning', '提示', '最多支持10个分段!');
  3555. } else
  3556. $scope.item.prices.push({});
  3557. };
  3558. // 删除一个分段
  3559. $scope.removePrice = function(index) {
  3560. $scope.item.prices.splice(index, 1);
  3561. };
  3562. // 查找客户
  3563. $scope.dbfindCust = function(){
  3564. if($scope.item.$editing) {
  3565. var modalInstance = $modal.open({
  3566. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  3567. controller: 'DbfindCustCtrl',
  3568. size: 'lg',
  3569. resolve: {
  3570. }
  3571. });
  3572. modalInstance.result.then(function(data){
  3573. $scope.item.quotation.cust = data.myEnterprise;
  3574. $scope.item.quotation.custUser = data.myUser;
  3575. $scope.item.product = null;
  3576. }, function(){
  3577. });
  3578. }
  3579. };
  3580. // 赋值客户信息
  3581. if($rootScope.custuu) {
  3582. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function(data) {
  3583. $scope.item.quotation.cust = data.myEnterprise;
  3584. $scope.item.quotation.custUser = data.myUser;
  3585. })
  3586. }
  3587. // 赋值物料信息
  3588. if($rootScope.prodId) {
  3589. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  3590. $scope.item.product.code = data.code;
  3591. $scope.item.product.title = data.title;
  3592. $scope.item.product.spec = data.spec;
  3593. $scope.item.product.unit = data.unit;
  3594. $scope.item.product.id = data.id;
  3595. }, function(response) {
  3596. });
  3597. }
  3598. // 查找客户物料
  3599. $scope.dbfindCustProd = function(){
  3600. if($scope.item.$editing) {
  3601. if($scope.item.quotation.cust.uu) {
  3602. var modalInstance = $modal.open({
  3603. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  3604. controller: 'DbfindCustProdCtrl',
  3605. size: 'lg',
  3606. resolve: {
  3607. custUU: function(){return $scope.item.quotation.cust.uu}
  3608. }
  3609. });
  3610. modalInstance.result.then(function(data){
  3611. $scope.item.product = data;
  3612. }, function(){
  3613. });
  3614. } else {
  3615. toaster.pop('error', '错误', '请先选择客户');
  3616. }
  3617. }
  3618. };
  3619. // 保存
  3620. $scope.save = function(){
  3621. $scope.loading = true;
  3622. if(!$scope.item.quotation.code) //新增,设单号
  3623. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  3624. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  3625. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  3626. $scope.item.productId = $scope.item.product.id;
  3627. $scope.item.quotation.status = 100;//在录入
  3628. if($scope.item.quotation.date instanceof Date) {
  3629. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  3630. }
  3631. if($scope.item.quotation.endDate instanceof Date) {
  3632. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  3633. }
  3634. Quotation.save({}, $scope.item, function(data){
  3635. $scope.loading = false;
  3636. toaster.pop('success', '成功', '保存成功');
  3637. if($stateParams.id)
  3638. window.location.reload();
  3639. else
  3640. window.location.hash = '#/sale/quotation/' + data.id;
  3641. }, function(response){
  3642. $scope.loading = false;
  3643. toaster.pop('error', '保存失败', response.data);
  3644. });
  3645. };
  3646. // 更新
  3647. $scope.update = function(){
  3648. $scope.item.$editing = true;
  3649. };
  3650. // 取消
  3651. $scope.cancel = function(){
  3652. $scope.item.$editing = false;
  3653. $scope.item = angular.copy(staticItem);
  3654. };
  3655. // 提交
  3656. $scope.submit = function(){
  3657. $scope.loading = true;
  3658. $scope.item.quotation.status = 101;//在录入
  3659. Quotation.save({}, $scope.item, function(data){
  3660. $scope.loading = false;
  3661. toaster.pop('success', '成功', '提交成功');
  3662. window.location.hash = '#/sale/quotation/' + data.id;
  3663. }, function(response){
  3664. $scope.loading = false;
  3665. toaster.pop('error', '保存失败', response.data);
  3666. });
  3667. };
  3668. }]);
  3669. // 查找客户
  3670. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  3671. BaseService.scrollBackToTop();
  3672. $scope.tableParams = new ngTableParams({
  3673. page : 1,
  3674. count : 10
  3675. }, {
  3676. total : 0,
  3677. counts: [5, 10, 25, 50],
  3678. getData : function($defer, params) {
  3679. $scope.loading = true;
  3680. var pageParams = params.url();
  3681. pageParams.keyword = $scope.keyword;
  3682. Customer.get(BaseService.parseParams(pageParams), function(page){
  3683. $scope.loading = false;
  3684. if(page) {
  3685. params.total(page.totalElements);
  3686. $defer.resolve(page.content);
  3687. }
  3688. $scope.totalCount = page.totalElements;
  3689. }, function(response){
  3690. $scope.loading = false;
  3691. toaster.pop('error', '数据加载失败', response.data);
  3692. });
  3693. }
  3694. });
  3695. $scope.onSearch = function() {
  3696. $scope.tableParams.page(1);
  3697. $scope.tableParams.reload();
  3698. };
  3699. $scope.cancel = function() {
  3700. $modalInstance.dismiss();
  3701. };
  3702. $scope.check = function(cust){
  3703. $modalInstance.close(cust);
  3704. };
  3705. }]);
  3706. // 查找客户物料
  3707. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  3708. BaseService.scrollBackToTop();
  3709. $scope.tableParams = new ngTableParams({
  3710. page : 1,
  3711. count : 10
  3712. }, {
  3713. total : 0,
  3714. counts: [5, 10, 25, 50],
  3715. getData : function($defer, params) {
  3716. $scope.loading = true;
  3717. var pageParams = params.url();
  3718. pageParams.keyword = $scope.keyword;
  3719. pageParams.custUU = custUU;
  3720. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  3721. $scope.loading = false;
  3722. if(page) {
  3723. params.total(page.totalElements);
  3724. $defer.resolve(page.content);
  3725. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3726. }
  3727. }, function(response){
  3728. $scope.loading = false;
  3729. toaster.pop('error', '数据加载失败', response.data);
  3730. });
  3731. }
  3732. });
  3733. // 取消
  3734. $scope.cancel = function() {
  3735. $modalInstance.dismiss();
  3736. };
  3737. // 选择
  3738. $scope.check = function(cust){
  3739. $modalInstance.close(cust);
  3740. };
  3741. // 搜索框回车
  3742. $scope.onSearch = function() {
  3743. $scope.tableParams.page(1);
  3744. $scope.tableParams.reload();
  3745. };
  3746. }]);
  3747. // 查找供应商
  3748. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  3749. BaseService.scrollBackToTop();
  3750. // 搜索框回车
  3751. $scope.onSearch = function(keyword) {
  3752. $scope.keyword = keyword;
  3753. $scope.tableParams.page(1);
  3754. $scope.tableParams.reload();
  3755. };
  3756. $scope.tableParams = new ngTableParams({
  3757. page : 1,
  3758. count : 10
  3759. }, {
  3760. total : 0,
  3761. counts: [10, 25, 50, 100],
  3762. getData : function($defer, params) {
  3763. $scope.loading = true;
  3764. var pageParams = params.url();
  3765. pageParams.keyword = $scope.keyword;
  3766. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  3767. $scope.loading = false;
  3768. if(page) {
  3769. params.total(page.totalElements);
  3770. $defer.resolve(page.content);
  3771. // 添加供应商时,将已存在的选中
  3772. if ($rootScope.tenderVendor) {
  3773. angular.forEach(page.content, function(vendor) {
  3774. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  3775. vendor.checked = false;
  3776. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  3777. vendor.checked = true;
  3778. break;
  3779. }
  3780. }
  3781. });
  3782. }
  3783. }
  3784. $scope.totalCount = page.totalElements;
  3785. }, function(response){
  3786. $scope.loading = false;
  3787. toaster.pop('error', '数据加载失败', response.data);
  3788. });
  3789. }
  3790. });
  3791. $scope.cancel = function() {
  3792. $modalInstance.dismiss();
  3793. };
  3794. $scope.checks = {
  3795. checked : false
  3796. };// 全选框
  3797. $scope.checkAll = function() {
  3798. angular.forEach($scope.tableParams.data, function(vendor) {
  3799. vendor.checked = $scope.checks.checked;
  3800. });
  3801. };
  3802. // 单选
  3803. $scope.checkOne = function(vendor) {
  3804. vendor.checked = true;
  3805. var checked = true;
  3806. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  3807. if (!message.checked) {
  3808. checked = false;
  3809. }
  3810. });
  3811. $scope.checks.checked = checked;
  3812. };
  3813. // 单反选
  3814. $scope.unCheckOne = function(vendor) {
  3815. vendor.checked = false;
  3816. $scope.checks.checked = false;
  3817. };
  3818. $scope.close = function(){
  3819. var vendors = [];
  3820. angular.forEach($scope.tableParams.data, function(vendor) {
  3821. if(vendor.checked) {
  3822. vendors.push(vendor);
  3823. $modalInstance.close(vendors);
  3824. }
  3825. });
  3826. };
  3827. }]);
  3828. // 发货提醒
  3829. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', function($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state){
  3830. BaseService.scrollBackToTop();
  3831. $scope.active = 'todo';
  3832. $scope.currency = Symbol.currency;
  3833. $scope.dateZoneText = '不限';
  3834. $scope.condition = {dateZone: -1};
  3835. $scope.changeDateZone = function(zone) {
  3836. $scope.condition.dateZone = zone;
  3837. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  3838. $scope.condition.$dateZoneOpen = false;
  3839. getDateCondition(zone, $scope.condition);
  3840. $scope.tableParams.reload();
  3841. };
  3842. $scope.setActive = function(state) {
  3843. if($scope.active != state) {
  3844. $scope.active = state;
  3845. if($scope.tableParams.page() == 1)
  3846. $scope.tableParams.reload();
  3847. else
  3848. $scope.tableParams.page(1);
  3849. }
  3850. };
  3851. var getService = function() {
  3852. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  3853. };
  3854. $scope.tableParams = new ngTableParams({
  3855. page : 1,
  3856. count : 5,
  3857. sorting: {
  3858. 'delivery': 'asc',
  3859. 'orderItemOrderCode': 'asc',
  3860. 'orderItemNumber': 'asc'
  3861. }
  3862. }, {
  3863. total : 0,
  3864. counts: [5, 10, 25, 50],
  3865. getData : function($defer, params) {
  3866. $scope.loading = true;
  3867. var pageParams = params.url();
  3868. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3869. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3870. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3871. $scope.loading = false;
  3872. if(page) {
  3873. params.total(page.totalElement);
  3874. $defer.resolve(page.content);
  3875. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3876. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3877. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3878. }
  3879. }, function(response){
  3880. $scope.loading = false;
  3881. toaster.pop('error', '数据加载失败', response.data);
  3882. });
  3883. }
  3884. });
  3885. $scope.openDatePicker = function($event, item, openParam) {
  3886. $event.preventDefault();
  3887. $event.stopPropagation();
  3888. item[openParam] = !item[openParam];
  3889. };
  3890. //生成随机单号
  3891. $scope.autoCode = function(notice){
  3892. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  3893. };
  3894. //可送货日期
  3895. $scope.sendDate = function(notice) {
  3896. var stock = notice.orderItem.product.ltinstock || 0;
  3897. var de = new Date(notice.delivery);
  3898. if(stock == -1) {
  3899. de.setMonth(de.getMonth() -1);
  3900. de.setDate(25);
  3901. } else if(stock >= 0) {
  3902. de.setDate(de.getDate() - stock -1);
  3903. }
  3904. return de;
  3905. };
  3906. $scope.onReplyClick = function(notice) {
  3907. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  3908. toaster.pop('warning', '警告', '数量填写错误!');
  3909. } else if(!notice.send.code) {
  3910. toaster.pop('warning', '警告', '请填写发货单号!');
  3911. } else {
  3912. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  3913. $scope.loading = true;
  3914. PurcNotice.save({id: notice.id}, send, function(data){
  3915. $scope.loading = false;
  3916. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  3917. $state.go('sale.send_detail', {id: data.id});
  3918. }, function(response){
  3919. $scope.loading = false;
  3920. toaster.pop('error', '发货失败', response.data);
  3921. });
  3922. }
  3923. };
  3924. $scope.checkboxes = {
  3925. checked : false
  3926. };
  3927. // 点击勾选全部的复选框
  3928. $scope.checkAll = function(){
  3929. angular.forEach($scope.tableParams.data, function(item) {
  3930. if(!item.waiting)
  3931. item.$selected = $scope.checkboxes.checked;
  3932. });
  3933. };
  3934. // 点击其中一个明细的复选框
  3935. $scope.checkOne = function(order){
  3936. var result = true;
  3937. angular.forEach($scope.tableParams.data, function(item) {
  3938. if(item.$selected != true){
  3939. result = false;
  3940. return;
  3941. }
  3942. });
  3943. $scope.checkboxes.checked = result;
  3944. };
  3945. $scope.sendByBatch = function(){
  3946. var modalInstance = $modal.open({
  3947. animation: true,
  3948. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  3949. controller: 'SaleNoticeSendByBatchCtrl',
  3950. size: 'lg',
  3951. resolve: {
  3952. selectedNotices: function(){return $scope.tableParams.data;}
  3953. }
  3954. });
  3955. modalInstance.result.then(function(){
  3956. $scope.tableParams.reload();
  3957. }, function(){
  3958. });
  3959. };
  3960. $scope.getSends = function(notice){
  3961. if( ! notice.sends && notice.endQty > 0){
  3962. notice.getSendsing = true;
  3963. notice.getSendsError = false;
  3964. PurcNotice.getSends({id: notice.id}, function(data){
  3965. notice.getSendsing = false;
  3966. notice.getSendsError = false;
  3967. notice.sends = data;
  3968. }, function(response){
  3969. notice.getSendsing = false;
  3970. notice.getSendsError = true;
  3971. });
  3972. }
  3973. };
  3974. // 搜索框回车
  3975. $scope.onSearch = function() {
  3976. $scope.tableParams.page(1);
  3977. $scope.tableParams.reload();
  3978. };
  3979. // 选择查找日期
  3980. $scope.onDateCondition = function(){
  3981. $scope.tableParams.page(1);
  3982. $scope.tableParams.reload();
  3983. };
  3984. //货车功能
  3985. var truck = $rootScope.truck;
  3986. if(!truck) {
  3987. SaleTruck.query({}, function(data){
  3988. $rootScope.truck = data;
  3989. });
  3990. }
  3991. $scope.isInTruck = function(noticeId) {
  3992. return truck.indexOf(noticeId) > -1;
  3993. };
  3994. $scope.addtoTruck = function(notice) {
  3995. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  3996. $rootScope.truck = data;
  3997. });
  3998. };
  3999. $scope.delFromTruck = function(notice) {
  4000. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  4001. $rootScope.truck = data;
  4002. });
  4003. };
  4004. $scope.$watch(function(){
  4005. return $rootScope.truck;
  4006. }, function(data) {
  4007. truck = $rootScope.truck;
  4008. }, true);
  4009. $scope.$watch(function(){
  4010. return $rootScope.dataChanged;
  4011. }, function(data) {
  4012. data && ($scope.tableParams.reload());
  4013. }, true);
  4014. }]);
  4015. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  4016. $scope.notices = angular.copy(selectedNotices);
  4017. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4018. $scope.saleSend = {
  4019. code: '',
  4020. payments: '',
  4021. currency: '',
  4022. custUU: null,
  4023. custUserUU: null,
  4024. remark: '批量发货',
  4025. sendItems: []
  4026. };
  4027. // 计算总数、总额
  4028. $scope.$watch(function(){
  4029. return $scope.notices;
  4030. }, function(data) {
  4031. var q = 0, t = 0;
  4032. if(data) {
  4033. angular.forEach(data,function(d){
  4034. q += (d.thisSendQty || 0);
  4035. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  4036. });
  4037. }
  4038. $scope.totalQty = q;
  4039. $scope.total = t;
  4040. }, true);
  4041. /**
  4042. * 删除一个已选中的送货提醒
  4043. */
  4044. $scope.removeOne = function(index) {
  4045. $scope.notices.splice(index, 1);
  4046. };
  4047. //确认送货
  4048. $scope.sendByBatch = function () {
  4049. $scope.saleSend.sendItems = [];
  4050. if($scope.saleSend.code == '') {//送货单号为空
  4051. toaster.pop('error', '错误', '请输入送货单号');
  4052. return;
  4053. }
  4054. var a = 0;
  4055. var num = 1;
  4056. var valid = true;
  4057. angular.forEach($scope.notices, function(item, key){
  4058. if(item.$selected) {
  4059. if(a == 0) {//第一次
  4060. $scope.saleSend.currency = item.orderItem.order.currency;
  4061. $scope.saleSend.custUU = item.enUU;
  4062. $scope.saleSend.payments = item.orderItem.order.payments;
  4063. a = 1;
  4064. } else {//其他
  4065. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  4066. if($scope.saleSend.custUU != item.enUU) valid = false;
  4067. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  4068. }
  4069. $scope.saleSend.sendItems.push({
  4070. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  4071. });
  4072. }
  4073. });
  4074. if(!valid) {
  4075. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  4076. } else {
  4077. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  4078. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  4079. $modalInstance.close('success');
  4080. $state.go('sale.send_detail', {id: data.id});
  4081. }, function(response){
  4082. toaster.pop('error', '错误', response.data);
  4083. });
  4084. }
  4085. };
  4086. $scope.cancel = function () {
  4087. $modalInstance.dismiss();
  4088. };
  4089. }]);
  4090. /**
  4091. * 发货单
  4092. */
  4093. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  4094. BaseService.scrollBackToTop();
  4095. $scope.active = 'all';
  4096. $scope.currency = Symbol.currency;
  4097. $scope.dateZoneText = '不限';
  4098. $scope.condition = {dateZone: -1};
  4099. $scope.changeDateZone = function(zone) {
  4100. $scope.condition.dateZone = zone;
  4101. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4102. $scope.condition.$dateZoneOpen = false;
  4103. getDateCondition(zone, $scope.condition);
  4104. $scope.tableParams.reload();
  4105. };
  4106. $scope.setActive = function(state) {
  4107. if($scope.active != state) {
  4108. $scope.active = state;
  4109. if($scope.tableParams.page() == 1)
  4110. $scope.tableParams.reload();
  4111. else
  4112. $scope.tableParams.page(1);
  4113. }
  4114. };
  4115. var getService = function() {
  4116. return SaleSend;
  4117. };
  4118. $scope.tableParams = new ngTableParams({
  4119. page : 1,
  4120. count : 5,
  4121. sorting: {
  4122. date: 'desc'
  4123. }
  4124. }, {
  4125. total : 0,
  4126. counts: [5, 10, 25, 50],
  4127. getData : function($defer, params) {
  4128. $scope.loading = true;
  4129. var pageParams = params.url();
  4130. pageParams.keyword = $scope.keyword;
  4131. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4132. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4133. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4134. $scope.loading = false;
  4135. if(page) {
  4136. params.total(page.totalElement);
  4137. $defer.resolve(page.content);
  4138. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4139. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4140. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4141. }
  4142. }, function(response){
  4143. $scope.loading = false;
  4144. toaster.pop('error', '数据加载失败', response.data);
  4145. });
  4146. }
  4147. });
  4148. $scope.openDatePicker = function($event, item, openParam) {
  4149. $event.preventDefault();
  4150. $event.stopPropagation();
  4151. item[openParam] = !item[openParam];
  4152. };
  4153. // 搜索框回车
  4154. $scope.onSearch = function() {
  4155. $scope.tableParams.page(1);
  4156. $scope.tableParams.reload();
  4157. };
  4158. // 选择查找日期
  4159. $scope.onDateCondition = function(){
  4160. $scope.tableParams.page(1);
  4161. $scope.tableParams.reload();
  4162. };
  4163. }]);
  4164. /**
  4165. * 发货单(包括发货条码维护)
  4166. */
  4167. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  4168. var loading = true;
  4169. $scope.checkBarCode = [];
  4170. $scope.checkBoxCode = [];
  4171. var vm = $scope.vm = {};
  4172. $scope.getCheckedItems = {};
  4173. vm.editBar = false;
  4174. vm.showBarCode = [];
  4175. $scope.barCode = function() {
  4176. vm.editBar = !vm.editBar;
  4177. }
  4178. $scope.checkboxes = {
  4179. checked : false
  4180. };
  4181. $scope.checkbars = {
  4182. checked : false
  4183. };
  4184. // 点击勾选barCode全部的复选框
  4185. $scope.checkBarAll = function(){
  4186. angular.forEach($scope.checkBarCode, function(item,key) {
  4187. $scope.checkBarCode[key] = $scope.checkbars.checked;
  4188. });
  4189. };
  4190. //点击barCode单选
  4191. $scope.checkBarOne = function() {
  4192. var result = true;
  4193. angular.forEach($scope.checkBarCode, function(item,key) {
  4194. if(item != true){
  4195. result = false;
  4196. return;
  4197. }
  4198. });
  4199. $scope.checkbars.checked = result;
  4200. }
  4201. // 点击boxCode全部的复选框
  4202. $scope.checkBoxAll = function(){
  4203. angular.forEach($scope.checkBoxCode, function(item,key) {
  4204. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  4205. });
  4206. };
  4207. //点击boxCode单选
  4208. $scope.checkBoxOne = function() {
  4209. var result = true;
  4210. angular.forEach($scope.checkBoxCode, function(item) {
  4211. if(item != true){
  4212. result = false;
  4213. return;
  4214. }
  4215. });
  4216. $scope.checkboxes.checked = result;
  4217. }
  4218. /**
  4219. * 生成条码和箱号
  4220. */
  4221. $scope.generateBarCode = function(item) {
  4222. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  4223. $scope.getCheckedItems = [];
  4224. var warningdata = '';
  4225. angular.forEach($scope.checkBarCode, function(item,key) {
  4226. $scope.getCheckedItem = {};
  4227. if(item == true ){
  4228. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4229. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  4230. $scope.getCheckedItems.push($scope.getCheckedItem);
  4231. //判断是否生成过条码
  4232. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4233. warningdata += $scope.order.sendItems[key].number+","
  4234. }
  4235. }
  4236. });
  4237. if($scope.getCheckedItems.length == 0){
  4238. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  4239. return;
  4240. }
  4241. if(warningdata != ''){
  4242. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  4243. return ;
  4244. }
  4245. }
  4246. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  4247. toaster.pop('success', '提示','生成成功!');
  4248. loadData();
  4249. },function(response){
  4250. $scope.loading = false;
  4251. toaster.pop('error', '生成失败', response.data);
  4252. });
  4253. }
  4254. /**
  4255. * 打印条码和箱号
  4256. */
  4257. $scope.printCode = function(type) {
  4258. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4259. //勾选需要打印的行
  4260. $scope.getCheckedItems = [];
  4261. var warningdata = ''
  4262. angular.forEach($scope.checkBarCode, function(item,key) {
  4263. $scope.getCheckedItem = {};
  4264. if(item == true ){
  4265. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4266. $scope.getCheckedItems.push($scope.getCheckedItem);
  4267. //判断是否生成过条码
  4268. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4269. warningdata += $scope.order.sendItems[key].number+","
  4270. }
  4271. }
  4272. });
  4273. if($scope.getCheckedItems.length == 0){
  4274. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  4275. return;
  4276. }
  4277. if(warningdata == ''){
  4278. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  4279. return;
  4280. }
  4281. //选择打印模板
  4282. var modalInstance = $modal.open({
  4283. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4284. controller: 'BarPrintModalCtrl',
  4285. resolve: {
  4286. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  4287. }
  4288. });
  4289. modalInstance.result.then(function(s){
  4290. if(s) {
  4291. //获取打印数据
  4292. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  4293. if(s.type == 'print'){//判断选择是打印还是打印预览
  4294. lodopPrint(data.message,LODOP,type);
  4295. }else if(s.type == 'printPreview'){
  4296. lodopPrintPreview(data.message,LODOP,type);
  4297. }
  4298. },function(response){
  4299. toaster.pop('error', '获取打印数据失败', response.data);
  4300. });
  4301. }
  4302. });
  4303. };
  4304. //打印单个条码
  4305. $scope.printSingleCode = function(id){
  4306. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4307. //选择打印模板
  4308. var modalInstance = $modal.open({
  4309. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4310. controller: 'BarPrintModalCtrl',
  4311. resolve: {
  4312. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  4313. }
  4314. });
  4315. modalInstance.result.then(function(s){
  4316. if(s) {
  4317. //获取打印数据
  4318. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  4319. if(s.type == 'print'){//判断选择是打印还是打印预览
  4320. lodopSPrint(data.message,LODOP);
  4321. }else if(s.type == 'printPreview'){
  4322. lodopSPrintPreview(data.message,LODOP);
  4323. }
  4324. },function(response){
  4325. toaster.pop('error', '获取打印数据失败', response.data);
  4326. });
  4327. }
  4328. });
  4329. }
  4330. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  4331. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4332. if (selectOrNot != -1) {
  4333. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4334. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4335. var strs = pagesize.split("*"); //字符分割
  4336. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4337. angular.forEach(printStore, function(data, index) {
  4338. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4339. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4340. if (data['LP_VALUETYPE'] == 'barcode') {
  4341. 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']);
  4342. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4343. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4344. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4345. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4346. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4347. } else if (data['LP_VALUETYPE'] == 'text') {
  4348. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4349. }
  4350. });
  4351. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4352. LODOP.PRINT();
  4353. }
  4354. };
  4355. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  4356. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4357. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4358. var strs = pagesize.split("*"); //字符分割
  4359. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4360. angular.forEach(printStore,function(data,index){
  4361. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  4362. if(data['LP_VALUETYPE'] == 'barcode'){
  4363. 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']);
  4364. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  4365. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  4366. }else if(data['LP_VALUETYPE'] == 'text'){
  4367. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4368. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  4369. }
  4370. });
  4371. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  4372. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  4373. LODOP.PREVIEW();//打印预览
  4374. };
  4375. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  4376. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4377. if (selectOrNot != -1) {
  4378. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4379. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  4380. var strs= new Array(); //定义一数组
  4381. strs = pagesize.split("*"); //字符分割
  4382. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4383. var ids = new Array();
  4384. angular.forEach(printStore, function(value,key) {
  4385. //LODOP.NewPage();
  4386. angular.forEach(value['data'], function(record,key) {
  4387. angular.forEach(record['store'], function(data, index) {
  4388. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4389. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4390. if (data['LP_VALUETYPE'] == 'barcode') {
  4391. 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']);
  4392. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4393. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4394. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4395. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4396. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4397. } else if (data['LP_VALUETYPE'] == 'text') {
  4398. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4399. }
  4400. });
  4401. });
  4402. var o = new Object();
  4403. o['id'] = record['si_id']
  4404. ids.push(o);
  4405. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4406. LODOP.PRINT();
  4407. });
  4408. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  4409. if(type == 'Bar'){
  4410. //更新打印状态
  4411. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  4412. }
  4413. }
  4414. };
  4415. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  4416. var ids = new Array();
  4417. angular.forEach(printData, function(record, index){
  4418. angular.forEach(record['data'],function(value,index){
  4419. LODOP.NewPage();
  4420. angular.forEach(value['store'],function(data,index){
  4421. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  4422. if(data['LP_VALUETYPE'] == 'barcode'){
  4423. 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']);
  4424. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  4425. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  4426. }else if(data['LP_VALUETYPE'] == 'text'){
  4427. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4428. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  4429. }
  4430. });
  4431. });
  4432. var o = new Object();
  4433. o['id'] = record['si_id']
  4434. ids.push(o);
  4435. });
  4436. var pagesize = printData[0]['pagesize'];//获取标签的大小
  4437. var strs= new Array(); //定义一数组
  4438. strs = pagesize.split("*"); //字符分割
  4439. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  4440. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  4441. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4442. var times = LODOP.PREVIEW();//打印预览
  4443. if(times > 0){//点击了打印预览内的打印按钮
  4444. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  4445. if(type == 'Bar'){
  4446. //更新打印状态
  4447. SaleSend.updatePrintStatus({},ids,function(data){
  4448. loadData();
  4449. },function(res){});
  4450. }
  4451. }
  4452. };
  4453. /**
  4454. * 查看条码按钮
  4455. */
  4456. $scope.showBarCode = function(number) {
  4457. $scope.keys = number;
  4458. for(var i=0;i<vm.showBarCode.length;i++){
  4459. if(i!=number){
  4460. vm.showBarCode[i] = false;
  4461. }
  4462. }
  4463. vm.showBarCode[number] = !vm.showBarCode[number];
  4464. $scope.barcodes = [];
  4465. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  4466. var getPage = function(page, size){
  4467. if($scope.barcodes) {
  4468. var result = {};
  4469. result.totalCount = $scope.barcodes.length;
  4470. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  4471. if($scope.barcodes.length % size == 0) {
  4472. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  4473. }else {
  4474. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  4475. }
  4476. result.first = page == 1;
  4477. result.last = page == result.totalPage;
  4478. result.page = page;
  4479. result.next = page - 0 + 1;
  4480. result.pre = page - 1;
  4481. return result;
  4482. }
  4483. }
  4484. $scope.barData = getPage(1,5);
  4485. $scope.first = function (){
  4486. $scope.barData = getPage($scope.barData.pre,5);
  4487. }
  4488. $scope.last = function (){
  4489. $scope.barData = getPage($scope.barData.next,5);
  4490. }
  4491. };
  4492. /**
  4493. * 更新外箱号
  4494. */
  4495. $scope.updateOutBox = function(item,number) {
  4496. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  4497. }else {
  4498. if(item.outBoxQty > 0) {
  4499. if(!(item.outBoxQty % item.packageQty)) {
  4500. SaleSend.update({id:item.id},item,function(){
  4501. toaster.pop('success', '提示','保存成功!');
  4502. loadData();
  4503. }, function(response){
  4504. $scope.loading = false;
  4505. toaster.pop('error', '回复失败', response.data);
  4506. })
  4507. }else {
  4508. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  4509. }
  4510. }else {
  4511. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  4512. }
  4513. }
  4514. loadData();
  4515. };
  4516. /**
  4517. * 更新最小包数
  4518. */
  4519. $scope.updatePackage = function(item, number) {
  4520. if(item.packageQty == $scope.oldpackageQty[number]) {
  4521. }else {
  4522. if(item.orderItem.product.minPack != 0) {
  4523. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  4524. if(!(item.packageQty % item.orderItem.product.minPack)) {
  4525. SaleSend.update({id:item.id},item,function(){
  4526. toaster.pop('success', '提示','保存成功!');
  4527. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  4528. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  4529. }
  4530. loadData();
  4531. }, function(response){
  4532. $scope.loading = false;
  4533. toaster.pop('error', '回复失败', response.data);
  4534. })
  4535. }else {
  4536. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  4537. }
  4538. }else {
  4539. toaster.pop('warning', '提示', '请填写有效的数量!');
  4540. }
  4541. }else {
  4542. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  4543. SaleSend.update({id:item.id},item,function(){
  4544. toaster.pop('success', '提示','保存成功!');
  4545. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  4546. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  4547. }
  4548. loadData();
  4549. }, function(response){
  4550. $scope.loading = false;
  4551. toaster.pop('error', '回复失败', response.data);
  4552. })
  4553. }else {
  4554. toaster.pop('warning', '提示', '请填写有效的数量!');
  4555. }
  4556. }
  4557. }
  4558. loadData();
  4559. };
  4560. var loadData = function() {
  4561. SaleSend.get({id: $stateParams.id}, function(data){
  4562. $scope.order = data;
  4563. var orderCount = $scope.order.sendItems.length;
  4564. $scope.oldpackageQty = [];
  4565. $scope.oldoutBoxQty = [];
  4566. var sum = 0;
  4567. vm.oldpackageQty = [];
  4568. angular.forEach(data.sendItems, function(value, key){
  4569. //给showBarCode数组赋初值
  4570. if (vm.showBarCode.length < orderCount){
  4571. vm.showBarCode.push(false);
  4572. }
  4573. if($scope.checkBarCode.length < orderCount) {
  4574. $scope.checkBarCode.push(false);
  4575. }
  4576. if($scope.checkBoxCode.length < orderCount) {
  4577. $scope.checkBoxCode.push(false);
  4578. }
  4579. //给个初值
  4580. if(!value.packageQty) {
  4581. value.packageQty = value.orderItem.product.minPack;
  4582. }
  4583. $scope.oldpackageQty.push(value.packageQty);
  4584. if(value.outBoxQty) {
  4585. $scope.oldoutBoxQty.push(value.outBoxQty);
  4586. }
  4587. sum += value.price * value.qty;
  4588. });
  4589. data.total = sum;
  4590. $scope.loading = false;
  4591. }, function(response){
  4592. loading = false;
  4593. toaster.pop('error', '获取数据失败', response.data);
  4594. });
  4595. };
  4596. loadData();
  4597. }]);
  4598. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  4599. $scope.typeItem = typeItem;
  4600. $scope.template = [];
  4601. $scope.choose = {};
  4602. //获取打印模板
  4603. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  4604. if(data.message){
  4605. $scope.template = data.message;
  4606. $scope.choose.tp_id = $scope.template[0].id;
  4607. }
  4608. },function(res){
  4609. toaster.pop('error', '获取模板错误', res.data);
  4610. });
  4611. $scope.print = function(){
  4612. $scope.choose.type = 'print';
  4613. $modalInstance.close($scope.choose);
  4614. };
  4615. $scope.printPreview = function(){
  4616. $scope.choose.type = 'printPreview';
  4617. $modalInstance.close($scope.choose);
  4618. }
  4619. $scope.cancel = function(){
  4620. $modalInstance.close();
  4621. }
  4622. }]);
  4623. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  4624. var loading = true;
  4625. var loadData = function() {
  4626. PurcSample.get({id: $stateParams.id}, function(data){
  4627. $scope.sample = data;
  4628. if(!$scope.sample.send){
  4629. $scope.sample.getSendInfo = '加载中...';
  4630. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  4631. if(sendData) {
  4632. $scope.sample.getSendInfo = null;
  4633. $scope.sample.send = sendData;
  4634. } else {
  4635. $scope.sample.getSendInfo = '无送样信息';
  4636. $scope.sample.send = '无送样信息';
  4637. }
  4638. }, function(response){
  4639. $scope.sample.getSendInfo = '加载失败!';
  4640. });
  4641. }
  4642. $scope.loading = false;
  4643. }, function(response){
  4644. loading = false;
  4645. toaster.pop('error', '获取数据失败', response.data);
  4646. });
  4647. };
  4648. loadData();
  4649. }]);
  4650. /**
  4651. * 客户打样申请
  4652. */
  4653. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  4654. BaseService.scrollBackToTop();
  4655. $scope.active = 'todo';
  4656. $scope.agreedText = '全部';
  4657. $scope.dateZoneText = '一个月内';
  4658. $scope.condition = {dateZone: 1};
  4659. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4660. $scope.changeAgreed = function(agreed) {
  4661. $scope.condition.agreed = agreed;
  4662. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4663. $scope.condition.$agreedOpen = false;
  4664. };
  4665. $scope.changeDateZone = function(zone) {
  4666. $scope.condition.dateZone = zone;
  4667. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4668. $scope.condition.$dateZoneOpen = false;
  4669. };
  4670. $scope.setActive = function(state) {
  4671. if($scope.active != state) {
  4672. $scope.active = state;
  4673. if($scope.tableParams.page() == 1)
  4674. $scope.tableParams.reload();
  4675. else
  4676. $scope.tableParams.page(1);
  4677. }
  4678. };
  4679. var getService = function() {
  4680. return PurcSample;
  4681. };
  4682. $scope.tableParams = new ngTableParams({
  4683. page : 1,
  4684. count : 5,
  4685. sorting: {
  4686. proofingDate: 'desc'
  4687. }
  4688. }, {
  4689. total : 0,
  4690. counts: [5, 10, 25, 50],
  4691. getData : function($defer, params) {
  4692. $scope.loading = true;
  4693. var pageParams = params.url();
  4694. pageParams.keyword = $scope.keyword;
  4695. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4696. $scope.loading = false;
  4697. if(page) {
  4698. params.total(page.totalElement);
  4699. $defer.resolve(page.content);
  4700. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4701. }
  4702. }, function(response){
  4703. $scope.loading = false;
  4704. toaster.pop('error', '数据加载失败', response.data);
  4705. });
  4706. }
  4707. });
  4708. $scope.openDatePicker = function($event, item, openParam) {
  4709. $event.preventDefault();
  4710. $event.stopPropagation();
  4711. item[openParam] = !item[openParam];
  4712. };
  4713. $scope.openSend = function(index, sample) {
  4714. var modalInstance = $modal.open({
  4715. animation: true,
  4716. templateUrl: 'static/tpl/index/sale/sample_send.html',
  4717. controller: 'SampleSendCtrl',
  4718. resolve: {
  4719. sampleItem: function(){return sample;}
  4720. }
  4721. });
  4722. modalInstance.result.then(function(){
  4723. toaster.pop('info', '提示', '送样成功');
  4724. $scope.tableParams.reload();
  4725. }, function(){
  4726. });
  4727. };
  4728. //打印 样品采购单
  4729. $scope.print = function(sample) {
  4730. console.log(sample);
  4731. PurcSample.printCount({id: sample.id},{});//增加打印此次
  4732. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  4733. };
  4734. $scope.getSend = function(proofing){
  4735. if( !proofing.send) {
  4736. proofing.getSendInfo = '加载中...';
  4737. PurcSample.getSend({id: proofing.id}, function(data){
  4738. if(data) {
  4739. proofing.getSendInfo = null;
  4740. proofing.send = data;
  4741. } else {
  4742. proofing.getSendInfo = '无送样信息';
  4743. proofing.send = '无送样信息';
  4744. }
  4745. }, function(response){
  4746. proofing.getSendInfo = '加载失败!';
  4747. });
  4748. }
  4749. };
  4750. // 搜索框回车
  4751. $scope.onSearch = function() {
  4752. $scope.tableParams.page(1);
  4753. $scope.tableParams.reload();
  4754. };
  4755. }]);
  4756. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  4757. $scope.sampleItem = sampleItem;
  4758. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  4759. //确认送样
  4760. $scope.ok = function (form) {
  4761. $scope.loading = true;
  4762. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  4763. $upload.upload({
  4764. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  4765. method: 'POST',
  4766. file: file,
  4767. data: {
  4768. json: $scope.sampleItem.sampleSend
  4769. }
  4770. }).success(function(data){
  4771. $scope.loading = false;
  4772. $modalInstance.close('success');
  4773. }).error(function(data){
  4774. $scope.loading = false;
  4775. toaster.pop('danger', '错误', data);
  4776. });
  4777. };
  4778. $scope.cancel = function () {
  4779. $modalInstance.dismiss(sampleItem);
  4780. };
  4781. }]);
  4782. /**
  4783. * 客户认定单
  4784. */
  4785. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  4786. BaseService.scrollBackToTop();
  4787. $scope.active = 'all';
  4788. $scope.agreedText = '全部';
  4789. $scope.dateZoneText = '一个月内';
  4790. $scope.condition = {dateZone: 1};
  4791. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4792. $scope.changeDateZone = function(zone) {
  4793. $scope.condition.dateZone = zone;
  4794. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4795. $scope.condition.$dateZoneOpen = false;
  4796. getDateCondition(zone, $scope.condition);
  4797. $scope.tableParams.reload();
  4798. };
  4799. $scope.setActive = function(state) {
  4800. if($scope.active != state) {
  4801. $scope.active = state;
  4802. if($scope.tableParams.page() == 1)
  4803. $scope.tableParams.reload();
  4804. else
  4805. $scope.tableParams.page(1);
  4806. }
  4807. };
  4808. var getService = function() {
  4809. return PurcApproval;
  4810. };
  4811. $scope.tableParams = new ngTableParams({
  4812. page : 1,
  4813. count : 5,
  4814. sorting: {
  4815. inDate: 'desc'
  4816. }
  4817. }, {
  4818. total : 0,
  4819. counts: [5, 10, 25, 50],
  4820. getData : function($defer, params) {
  4821. $scope.loading = true;
  4822. var pageParams = params.url();
  4823. pageParams.keyword = $scope.keyword;
  4824. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4825. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4826. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4827. $scope.loading = false;
  4828. if(page) {
  4829. params.total(page.totalElement);
  4830. $defer.resolve(page.content);
  4831. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4832. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4833. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4834. }
  4835. }, function(response){
  4836. $scope.loading = false;
  4837. toaster.pop('error', '数据加载失败', response.data);
  4838. });
  4839. }
  4840. });
  4841. $scope.openDatePicker = function($event, item, openParam) {
  4842. $event.preventDefault();
  4843. $event.stopPropagation();
  4844. item[openParam] = !item[openParam];
  4845. };
  4846. $scope.parseDate = function(dateStr) {
  4847. if(dateStr)
  4848. return Date.parse(dateStr, 'yyyy-MM-dd');
  4849. return new Date();
  4850. };
  4851. // 搜索框回车
  4852. $scope.onSearch = function() {
  4853. $scope.tableParams.page(1);
  4854. $scope.tableParams.reload();
  4855. };
  4856. // 选择查找日期
  4857. $scope.onDateCondition = function(){
  4858. $scope.tableParams.page(1);
  4859. $scope.tableParams.reload();
  4860. };
  4861. }]);
  4862. /**
  4863. * 客户采购预测
  4864. */
  4865. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  4866. BaseService.scrollBackToTop();
  4867. $scope.active = 'all';
  4868. $scope.agreedText = '全部';
  4869. $scope.dateZoneText = '一个月内';
  4870. $scope.condition = {dateZone: 1};
  4871. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4872. $scope.changeAgreed = function(agreed) {
  4873. $scope.condition.agreed = agreed;
  4874. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4875. $scope.condition.$agreedOpen = false;
  4876. };
  4877. $scope.changeDateZone = function(zone) {
  4878. $scope.condition.dateZone = zone;
  4879. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4880. $scope.condition.$dateZoneOpen = false;
  4881. };
  4882. $scope.setActive = function(state) {
  4883. if($scope.active != state) {
  4884. $scope.active = state;
  4885. if($scope.tableParams.page() == 1)
  4886. $scope.tableParams.reload();
  4887. else
  4888. $scope.tableParams.page(1);
  4889. }
  4890. };
  4891. var getService = function() {
  4892. return PurcForecast;
  4893. };
  4894. $scope.tableParams = new ngTableParams({
  4895. page : 1,
  4896. count : 5,
  4897. sorting: {
  4898. orderDate: 'desc'
  4899. }
  4900. }, {
  4901. total : 0,
  4902. counts: [5, 10, 25, 50],
  4903. getData : function($defer, params) {
  4904. $scope.loading = true;
  4905. var pageParams = params.url();
  4906. pageParams.keyword = $scope.keyword;
  4907. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4908. $scope.loading = false;
  4909. if(page) {
  4910. console.log(page);
  4911. params.total(page.totalElement);
  4912. $defer.resolve(page.content);
  4913. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4914. }
  4915. }, function(response){
  4916. $scope.loading = false;
  4917. toaster.pop('error', '数据加载失败', response.data);
  4918. });
  4919. }
  4920. });
  4921. $scope.openDatePicker = function($event, item, openParam) {
  4922. $event.preventDefault();
  4923. $event.stopPropagation();
  4924. item[openParam] = !item[openParam];
  4925. };
  4926. // 搜索框回车
  4927. $scope.onSearch = function() {
  4928. $scope.tableParams.page(1);
  4929. $scope.tableParams.reload();
  4930. };
  4931. }]);
  4932. /**
  4933. * 客户采购验收
  4934. */
  4935. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  4936. BaseService.scrollBackToTop();
  4937. $scope.active = 'all';
  4938. $scope.dateZoneText = '不限';
  4939. $scope.deliveryZoneText = '不限';
  4940. $scope.condition = {dateZone: -1, deliveryZone: -1};
  4941. $scope.changeDateZone = function(zone) {
  4942. $scope.condition.dateZone = zone;
  4943. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4944. $scope.condition.$dateZoneOpen = false;
  4945. getDateCondition(zone, $scope.condition);
  4946. $scope.tableParams.reload();
  4947. };
  4948. $scope.changeDeliveryZone = function(zone) {
  4949. $scope.condition.deliveryZoneText = zone;
  4950. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  4951. $scope.condition.$delievryZoneOpen = false;
  4952. getDelveryCondition(zone, $scope.condition);
  4953. $scope.tableParams.reload();
  4954. };
  4955. $scope.setActive = function(state) {
  4956. if($scope.active != state) {
  4957. $scope.active = state;
  4958. if($scope.tableParams.page() == 1)
  4959. $scope.tableParams.reload();
  4960. else
  4961. $scope.tableParams.page(1);
  4962. }
  4963. };
  4964. var getService = function() {
  4965. return PurcAccept;
  4966. };
  4967. $scope.tableParams = new ngTableParams({
  4968. page : 1,
  4969. count : 5,
  4970. sorting: {
  4971. date: 'desc'
  4972. }
  4973. }, {
  4974. total : 0,
  4975. counts: [5, 10, 25, 50],
  4976. getData : function($defer, params) {
  4977. $scope.loading = true;
  4978. var pageParams = params.url();
  4979. pageParams.searchFilter = { // 筛选条件
  4980. keyword: $scope.keyword,
  4981. fromDate: getDateTime($scope.condition.dateFrom),
  4982. endDate: getDateTime($scope.condition.dateTo)
  4983. };
  4984. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4985. $scope.loading = false;
  4986. if(page) {
  4987. params.total(page.totalElement);
  4988. $defer.resolve(page.content);
  4989. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4990. }
  4991. }, function(response){
  4992. $scope.loading = false;
  4993. toaster.pop('error', '数据加载失败', response.data);
  4994. });
  4995. }
  4996. });
  4997. $scope.openDatePicker = function($event, item, openParam) {
  4998. $event.preventDefault();
  4999. $event.stopPropagation();
  5000. item[openParam] = !item[openParam];
  5001. };
  5002. $scope.parseDate = function(dateStr) {
  5003. if(dateStr)
  5004. return Date.parse(dateStr, 'yyyy-MM-dd');
  5005. return new Date();
  5006. };
  5007. // 选择查找日期
  5008. $scope.onDateCondition = function(){
  5009. $scope.tableParams.page(1);
  5010. $scope.tableParams.reload();
  5011. };
  5012. // 搜索框回车
  5013. $scope.onSearch = function() {
  5014. $scope.tableParams.page(1);
  5015. $scope.tableParams.reload();
  5016. };
  5017. }]);
  5018. /**
  5019. * 客户采购验退
  5020. */
  5021. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  5022. BaseService.scrollBackToTop();
  5023. $scope.active = 'all';
  5024. $scope.agreedText = '全部';
  5025. $scope.dateZoneText = '一个月内';
  5026. $scope.condition = {dateZone: 1};
  5027. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5028. $scope.changeAgreed = function(agreed) {
  5029. $scope.condition.agreed = agreed;
  5030. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5031. $scope.condition.$agreedOpen = false;
  5032. };
  5033. $scope.changeDateZone = function(zone) {
  5034. $scope.condition.dateZone = zone;
  5035. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5036. $scope.condition.$dateZoneOpen = false;
  5037. };
  5038. $scope.setActive = function(state) {
  5039. if($scope.active != state) {
  5040. $scope.active = state;
  5041. if($scope.tableParams.page() == 1)
  5042. $scope.tableParams.reload();
  5043. else
  5044. $scope.tableParams.page(1);
  5045. }
  5046. };
  5047. var getService = function() {
  5048. return PurcReturn;
  5049. };
  5050. $scope.tableParams = new ngTableParams({
  5051. page : 1,
  5052. count : 5,
  5053. sorting: {
  5054. date: 'desc'
  5055. }
  5056. }, {
  5057. total : 0,
  5058. counts: [5, 10, 25, 50],
  5059. getData : function($defer, params) {
  5060. $scope.loading = true;
  5061. var pageParams = params.url();
  5062. pageParams.keyword = $scope.keyword;
  5063. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5064. $scope.loading = false;
  5065. if(page) {
  5066. params.total(page.totalElement);
  5067. $defer.resolve(page.content);
  5068. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5069. angular.forEach(page.content, function(data) {
  5070. if (!data.returnItems[0].orderItem) {
  5071. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  5072. data.enName = enterprise.enName;
  5073. });
  5074. }
  5075. });
  5076. }
  5077. }, function(response){
  5078. $scope.loading = false;
  5079. toaster.pop('error', '数据加载失败', response.data);
  5080. });
  5081. }
  5082. });
  5083. $scope.openDatePicker = function($event, item, openParam) {
  5084. $event.preventDefault();
  5085. $event.stopPropagation();
  5086. item[openParam] = !item[openParam];
  5087. };
  5088. // 搜索框回车
  5089. $scope.onSearch = function() {
  5090. $scope.tableParams.page(1);
  5091. $scope.tableParams.reload();
  5092. };
  5093. }]);
  5094. /**
  5095. * 客户不良品入库
  5096. */
  5097. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  5098. BaseService.scrollBackToTop();
  5099. $scope.active = 'all';
  5100. $scope.agreedText = '全部';
  5101. $scope.dateZoneText = '一个月内';
  5102. $scope.condition = {dateZone: 1};
  5103. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5104. $scope.changeAgreed = function(agreed) {
  5105. $scope.condition.agreed = agreed;
  5106. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5107. $scope.condition.$agreedOpen = false;
  5108. };
  5109. $scope.changeDateZone = function(zone) {
  5110. $scope.condition.dateZone = zone;
  5111. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5112. $scope.condition.$dateZoneOpen = false;
  5113. };
  5114. $scope.setActive = function(state) {
  5115. if($scope.active != state) {
  5116. $scope.active = state;
  5117. if($scope.tableParams.page() == 1)
  5118. $scope.tableParams.reload();
  5119. else
  5120. $scope.tableParams.page(1);
  5121. }
  5122. };
  5123. var getService = function() {
  5124. return PurcBadIn;
  5125. };
  5126. $scope.tableParams = new ngTableParams({
  5127. page : 1,
  5128. count : 5,
  5129. sorting: {
  5130. date: 'desc'
  5131. }
  5132. }, {
  5133. total : 0,
  5134. counts: [5, 10, 25, 50],
  5135. getData : function($defer, params) {
  5136. $scope.loading = true;
  5137. var pageParams = params.url();
  5138. pageParams.keyword = $scope.keyword;
  5139. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5140. $scope.loading = false;
  5141. if(page) {
  5142. params.total(page.totalElement);
  5143. $defer.resolve(page.content);
  5144. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5145. }
  5146. }, function(response){
  5147. $scope.loading = false;
  5148. toaster.pop('error', '数据加载失败', response.data);
  5149. });
  5150. }
  5151. });
  5152. $scope.openDatePicker = function($event, item, openParam) {
  5153. $event.preventDefault();
  5154. $event.stopPropagation();
  5155. item[openParam] = !item[openParam];
  5156. };
  5157. // 搜索框回车
  5158. $scope.onSearch = function() {
  5159. $scope.tableParams.page(1);
  5160. $scope.tableParams.reload();
  5161. };
  5162. }]);
  5163. /**
  5164. * 客户不良品出库
  5165. */
  5166. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  5167. BaseService.scrollBackToTop();
  5168. $scope.active = 'all';
  5169. $scope.agreedText = '全部';
  5170. $scope.dateZoneText = '一个月内';
  5171. $scope.condition = {dateZone: 1};
  5172. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5173. $scope.changeAgreed = function(agreed) {
  5174. $scope.condition.agreed = agreed;
  5175. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5176. $scope.condition.$agreedOpen = false;
  5177. };
  5178. $scope.changeDateZone = function(zone) {
  5179. $scope.condition.dateZone = zone;
  5180. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5181. $scope.condition.$dateZoneOpen = false;
  5182. };
  5183. $scope.setActive = function(state) {
  5184. if($scope.active != state) {
  5185. $scope.active = state;
  5186. if($scope.tableParams.page() == 1)
  5187. $scope.tableParams.reload();
  5188. else
  5189. $scope.tableParams.page(1);
  5190. }
  5191. };
  5192. var getService = function() {
  5193. return PurcBadOut;
  5194. };
  5195. $scope.tableParams = new ngTableParams({
  5196. page : 1,
  5197. count : 5,
  5198. sorting: {
  5199. date: 'desc'
  5200. }
  5201. }, {
  5202. total : 0,
  5203. counts: [5, 10, 25, 50],
  5204. getData : function($defer, params) {
  5205. $scope.loading = true;
  5206. var pageParams = params.url();
  5207. pageParams.keyword = $scope.keyword;
  5208. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5209. $scope.loading = false;
  5210. if(page) {
  5211. params.total(page.totalElement);
  5212. $defer.resolve(page.content);
  5213. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5214. }
  5215. }, function(response){
  5216. $scope.loading = false;
  5217. toaster.pop('error', '数据加载失败', response.data);
  5218. });
  5219. }
  5220. });
  5221. $scope.openDatePicker = function($event, item, openParam) {
  5222. $event.preventDefault();
  5223. $event.stopPropagation();
  5224. item[openParam] = !item[openParam];
  5225. };
  5226. // 搜索框回车
  5227. $scope.onSearch = function() {
  5228. $scope.tableParams.page(1);
  5229. $scope.tableParams.reload();
  5230. };
  5231. }]);
  5232. /**
  5233. * 客户MRB
  5234. */
  5235. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  5236. BaseService.scrollBackToTop();
  5237. $scope.active = 'all';
  5238. $scope.agreedText = '全部';
  5239. $scope.dateZoneText = '一个月内';
  5240. $scope.condition = {dateZone: 1};
  5241. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5242. $scope.changeAgreed = function(agreed) {
  5243. $scope.condition.agreed = agreed;
  5244. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5245. $scope.condition.$agreedOpen = false;
  5246. };
  5247. $scope.changeDateZone = function(zone) {
  5248. $scope.condition.dateZone = zone;
  5249. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5250. $scope.condition.$dateZoneOpen = false;
  5251. };
  5252. $scope.setActive = function(state) {
  5253. if($scope.active != state) {
  5254. $scope.active = state;
  5255. if($scope.tableParams.page() == 1)
  5256. $scope.tableParams.reload();
  5257. else
  5258. $scope.tableParams.page(1);
  5259. }
  5260. };
  5261. var getService = function() {
  5262. return PurcMRB;
  5263. };
  5264. $scope.tableParams = new ngTableParams({
  5265. page : 1,
  5266. count : 5,
  5267. sorting: {
  5268. date: 'desc'
  5269. }
  5270. }, {
  5271. total : 0,
  5272. counts: [5, 10, 25, 50],
  5273. getData : function($defer, params) {
  5274. $scope.loading = true;
  5275. var pageParams = params.url();
  5276. pageParams.keyword = $scope.keyword;
  5277. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5278. $scope.loading = false;
  5279. if(page) {
  5280. params.total(page.totalElement);
  5281. $defer.resolve(page.content);
  5282. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5283. }
  5284. }, function(response){
  5285. $scope.loading = false;
  5286. toaster.pop('error', '数据加载失败', response.data);
  5287. });
  5288. }
  5289. });
  5290. $scope.openDatePicker = function($event, item, openParam) {
  5291. $event.preventDefault();
  5292. $event.stopPropagation();
  5293. item[openParam] = !item[openParam];
  5294. };
  5295. // 搜索框回车
  5296. $scope.onSearch = function() {
  5297. $scope.tableParams.page(1);
  5298. $scope.tableParams.reload();
  5299. };
  5300. }]);
  5301. /**
  5302. * 客户应付发票
  5303. */
  5304. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  5305. BaseService.scrollBackToTop();
  5306. $scope.active = 'all';
  5307. $scope.dateZoneText = '不限';
  5308. $scope.condition = {dateZone: -1};
  5309. $scope.changeDateZone = function(zone) {
  5310. $scope.condition.dateZone = zone;
  5311. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5312. $scope.condition.$dateZoneOpen = false;
  5313. getDateCondition(zone, $scope.condition);
  5314. $scope.tableParams.reload();
  5315. };
  5316. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5317. $scope.setActive = function(state) {
  5318. if($scope.active != state) {
  5319. $scope.active = state;
  5320. if($scope.tableParams.page() == 1)
  5321. $scope.tableParams.reload();
  5322. else
  5323. $scope.tableParams.page(1);
  5324. }
  5325. };
  5326. var getService = function() {
  5327. return FaApBill;
  5328. };
  5329. $scope.tableParams = new ngTableParams({
  5330. page : 1,
  5331. count : 5,
  5332. sorting: {
  5333. date: 'desc'
  5334. }
  5335. }, {
  5336. total : 0,
  5337. counts: [5, 10, 25, 50],
  5338. getData : function($defer, params) {
  5339. $scope.loading = true;
  5340. var pageParams = params.url();
  5341. pageParams.searchFilter = { // 筛选条件
  5342. keyword: $scope.keyword,
  5343. fromDate: getDateTime($scope.condition.dateFrom),
  5344. endDate: getDateTime($scope.condition.dateTo)
  5345. };
  5346. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5347. $scope.loading = false;
  5348. if(page) {
  5349. params.total(page.totalElement);
  5350. $defer.resolve(page.content);
  5351. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  5352. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5353. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5354. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  5355. }
  5356. }, function(response){
  5357. $scope.loading = false;
  5358. toaster.pop('error', '数据加载失败', response.data);
  5359. });
  5360. }
  5361. });
  5362. $scope.openDatePicker = function($event, item, openParam) {
  5363. $event.preventDefault();
  5364. $event.stopPropagation();
  5365. item[openParam] = !item[openParam];
  5366. };
  5367. $scope.parseDate = function(dateStr) {
  5368. if(dateStr)
  5369. return Date.parse(dateStr, 'yyyy-MM-dd');
  5370. return new Date();
  5371. };
  5372. // 搜索框回车
  5373. $scope.onSearch = function() {
  5374. $scope.tableParams.page(1);
  5375. $scope.tableParams.reload();
  5376. };
  5377. // 选择查找日期
  5378. $scope.onDateCondition = function(){
  5379. $scope.tableParams.page(1);
  5380. $scope.tableParams.reload();
  5381. };
  5382. }]);
  5383. /**
  5384. * 应付对账单
  5385. */
  5386. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  5387. BaseService.scrollBackToTop();
  5388. $scope.active = 'all';
  5389. $scope.dateZoneText = '不限';
  5390. $scope.condition = {dateZone: -1};
  5391. $scope.changeDateZone = function(zone) {
  5392. $scope.condition.dateZone = zone;
  5393. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5394. $scope.condition.$dateZoneOpen = false;
  5395. getDateCondition(zone, $scope.condition);
  5396. $scope.tableParams.reload();
  5397. };
  5398. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5399. $scope.setActive = function(state) {
  5400. if($scope.active != state) {
  5401. $scope.active = state;
  5402. if($scope.tableParams.page() == 1)
  5403. $scope.tableParams.reload();
  5404. else
  5405. $scope.tableParams.page(1);
  5406. }
  5407. };
  5408. var getService = function() {
  5409. return FaArCheck;
  5410. };
  5411. $scope.tableParams = new ngTableParams({
  5412. page : 1,
  5413. count : 5,
  5414. sorting: {
  5415. date: 'desc'
  5416. }
  5417. }, {
  5418. total : 0,
  5419. counts: [5, 10, 25, 50],
  5420. getData : function($defer, params) {
  5421. $scope.loading = true;
  5422. var pageParams = params.url();
  5423. pageParams.keyword = $scope.keyword;
  5424. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5425. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5426. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5427. $scope.loading = false;
  5428. if(page) {
  5429. params.total(page.totalElement);
  5430. $defer.resolve(page.content);
  5431. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5432. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5433. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5434. }
  5435. }, function(response){
  5436. $scope.loading = false;
  5437. toaster.pop('error', '数据加载失败', response.data);
  5438. });
  5439. }
  5440. });
  5441. $scope.openDatePicker = function($event, item, openParam) {
  5442. $event.preventDefault();
  5443. $event.stopPropagation();
  5444. item[openParam] = !item[openParam];
  5445. };
  5446. // 计算单据的商品总数
  5447. $scope.getTotalProd = function(check) {
  5448. var total = 0;
  5449. if(check.items) {
  5450. angular.forEach(check.items, function(value) {
  5451. total += value.qty;
  5452. });
  5453. }
  5454. return total;
  5455. };
  5456. // 搜索框回车
  5457. $scope.onSearch = function() {
  5458. $scope.tableParams.page(1);
  5459. $scope.tableParams.reload();
  5460. };
  5461. // 选择查找日期
  5462. $scope.onDateCondition = function(){
  5463. $scope.tableParams.page(1);
  5464. $scope.tableParams.reload();
  5465. };
  5466. }]);
  5467. // 应付对账单详情页
  5468. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  5469. BaseService.scrollBackToTop();
  5470. var loadData = function() {
  5471. FaArCheck.get({id: $stateParams.id}, function(data){
  5472. $scope.order = data;
  5473. $scope.loading = false;
  5474. });
  5475. };
  5476. loadData(); // 初始获取单据数据
  5477. $scope.onReplyClick = function(item, isAgreed) {
  5478. if(isAgreed) {// 同意确认
  5479. FaArCheck.agree({itemId: item.id}, {}, function(data){
  5480. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  5481. }, function(response){
  5482. toaster.pop('danger', '确认失败', response.data);
  5483. });
  5484. } else {// 不同意回复
  5485. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  5486. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  5487. }, function(response) {
  5488. toaster.pop('danger', '确认失败', response.data);
  5489. });
  5490. }
  5491. };
  5492. // 获取明细的回复记录
  5493. $scope.getReplies = function(item) {
  5494. if(!item.replies) {
  5495. FaArCheck.getReplies({itemId: item.id}, function(data) {
  5496. item.replies = data;
  5497. }, function(response) {
  5498. toaster.pop('danger', '获取对账记录失败', response.data);
  5499. });
  5500. }
  5501. };
  5502. }]);
  5503. //应收对账单列表
  5504. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  5505. BaseService.scrollBackToTop();
  5506. $scope.dateZoneText = '不限';
  5507. $scope.condition = {dateZone: -1};
  5508. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5509. $scope.active = 'todo';
  5510. //打印 对账单
  5511. $scope.print = function(check) {
  5512. FaApCheck.printCount({id: check.id},{});//增加打印此次
  5513. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  5514. };
  5515. //状态
  5516. $scope.setActive = function (state){
  5517. if($scope.active != state) {
  5518. $scope.active = state;
  5519. if($scope.tableParams.page() == 1)
  5520. $scope.tableParams.reload();
  5521. else
  5522. $scope.tableParams.page(1);
  5523. }
  5524. };
  5525. $scope.changeDateZone = function(zone) {
  5526. $scope.condition.dateZone = zone;
  5527. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5528. $scope.condition.$dateZoneOpen = false;
  5529. getDateCondition(zone, $scope.condition);
  5530. $scope.tableParams.reload();
  5531. };
  5532. //获取应收对账单全部
  5533. $scope.tableParams = new ngTableParams({
  5534. page : 1,
  5535. count : 5,
  5536. sorting: {
  5537. recordDate: 'desc'
  5538. }
  5539. }, {
  5540. total : 0,
  5541. counts: [5, 10, 25, 50],
  5542. getData : function($defer, params) {
  5543. $scope.loading = true;
  5544. var pageParams = params.url();
  5545. pageParams.searchFilter = { // 筛选条件
  5546. keyword: $scope.keyword,
  5547. fromDate: getDateTime($scope.condition.dateFrom),
  5548. endDate: getDateTime($scope.condition.dateTo)
  5549. };
  5550. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  5551. $scope.loading = false;
  5552. if(page) {
  5553. params.total(page.totalElement);
  5554. $scope.data = $defer.resolve(page.content);
  5555. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  5556. }
  5557. }, function(response){
  5558. $scope.loading = false;
  5559. toaster.pop('error', '数据加载失败', response.data);
  5560. });
  5561. }
  5562. });
  5563. $scope.openDatePicker = function($event, item, openParam) {
  5564. $event.preventDefault();
  5565. $event.stopPropagation();
  5566. item[openParam] = !item[openParam];
  5567. };
  5568. // 计算单据的商品总数
  5569. $scope.getTotalProd = function(check) {
  5570. var total = 0;
  5571. if(check.items) {
  5572. angular.forEach(check.items, function(value) {
  5573. total += value.checkQty;
  5574. });
  5575. }
  5576. return total;
  5577. };
  5578. // 搜索框回车
  5579. $scope.onSearch = function() {
  5580. $scope.tableParams.page(1);
  5581. $scope.tableParams.reload();
  5582. };
  5583. // 选择查找日期
  5584. $scope.onDateCondition = function(){
  5585. $scope.tableParams.page(1);
  5586. $scope.tableParams.reload();
  5587. };
  5588. }]);
  5589. //应收对账单详情
  5590. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  5591. BaseService.scrollBackToTop();
  5592. $scope.haveSelected = true;
  5593. $scope.data = {};
  5594. //控制提交和删除按钮的显示
  5595. $scope.ifShow = true;
  5596. var loadData = function(){
  5597. FaApCheck.get({id:$stateParams.id},function(data){
  5598. $scope.data = data;
  5599. if($scope.data.status){
  5600. }else{
  5601. $scope.ifShow = true;
  5602. }
  5603. })
  5604. };
  5605. if($stateParams.id){
  5606. loadData();
  5607. }
  5608. $scope.haveSource = false;
  5609. //提交应收对账单
  5610. $scope.submitApCheck = function(){
  5611. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  5612. if(data.result) {
  5613. toaster.pop('success', '提示', '提交成功');
  5614. $scope.haveSelected = false;
  5615. window.location.href = '#/fa/apCheck';
  5616. }else {
  5617. $scope.haveSource = true;
  5618. loadData();
  5619. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  5620. $scope.haveSelected = true;
  5621. }
  5622. },function(){
  5623. $scope.loading = false;
  5624. toaster.pop('error', '提示', '更新已转数失败');
  5625. });
  5626. }
  5627. //删除应收对账单的同时更新来源表已转数
  5628. var updateYCheckQty = function(){
  5629. var sourceInfos = [];
  5630. angular.forEach($scope.data.items, function(item){
  5631. $scope.sourceInfo = {
  5632. sourceId: '',
  5633. sourceTable: '',
  5634. newYCheckQty: ''
  5635. };
  5636. $scope.sourceInfo.sourceId = item.sourceId;
  5637. $scope.sourceInfo.sourceTable = item.sourceTable;
  5638. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  5639. sourceInfos.push($scope.sourceInfo);
  5640. });
  5641. FaApCheck.update({}, sourceInfos, function(){
  5642. },function(response){
  5643. $scope.loading = false;
  5644. toaster.pop('error', '更新已转数失败', response.data);
  5645. });
  5646. }
  5647. //删除应收对账单
  5648. $scope.deleteApCheck = function(){
  5649. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  5650. updateYCheckQty();
  5651. toaster.pop('success','提示','删除成功');
  5652. },function(){
  5653. toaster.pop('error','提示','删除失败');
  5654. });
  5655. $scope.haveSelected = false;
  5656. }
  5657. //作废应收对账单
  5658. $scope.cancelApCheck = function(check) {
  5659. FaApCheck.cancel({id:check.id},function(data){
  5660. $scope.checkResult = false;
  5661. if(data.result) {
  5662. $scope.checkResult = true;
  5663. toaster.pop('success', '提示', '作废成功');
  5664. $scope.tableParams.reload();
  5665. }else{
  5666. toaster.pop('error', '提示', '作废失败');
  5667. }
  5668. },function(){
  5669. $scope.loading = false;
  5670. toaster.pop('error', '提示', '作废失败');
  5671. });
  5672. }
  5673. }]);
  5674. //未对账单据列表
  5675. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  5676. $scope.data = [];// 列表数据
  5677. $scope.condition = {
  5678. $fromOpened: false
  5679. }
  5680. $scope.openDatePicker = function($event, item, openParam) {
  5681. $event.preventDefault();
  5682. $event.stopPropagation();
  5683. item[openParam] = !item[openParam];
  5684. }
  5685. //查找客户
  5686. $scope.searchCust = function(suuorname) {
  5687. var modalInstance = $modal.open({
  5688. animation: true,
  5689. templateUrl: 'static/tpl/index/fa/custInfo.html',
  5690. controller: 'SearchCustInfoCtrl',
  5691. resolve: {
  5692. suuorname: function() {
  5693. return suuorname;
  5694. }
  5695. }
  5696. });
  5697. modalInstance.result.then(function(suuorname){
  5698. $scope.suuorname = suuorname;
  5699. });
  5700. }
  5701. // 点击筛选根据条件选择数据
  5702. $scope.suuorname = '';
  5703. // 默认本月
  5704. $scope.sdateTo = new Date();
  5705. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  5706. $scope.vuuorname = '';
  5707. $scope.factory = '';
  5708. $scope.prodTitle = '';
  5709. $scope.prodSpec = '';
  5710. $scope.condition.uuorname = '';
  5711. $scope.condition.dateFrom = '';
  5712. $scope.condition.dateTo = '';
  5713. $scope.condition.venduuorname = '';
  5714. $scope.condition.factory = '';
  5715. $scope.condition.prodTitle = '';
  5716. $scope.condition.prodSpec = '';
  5717. $scope.searchOrder = function(check) {
  5718. $scope.data = [];
  5719. $scope.checkboxes.checked = false;
  5720. $scope.totalMoney = 0;
  5721. $scope.condition.uuorname = $scope.suuorname;
  5722. $scope.condition.factory = $scope.factory
  5723. $scope.condition.prodTitle = $scope.prodTitle;
  5724. $scope.condition.prodSpec = $scope.prodSpec;
  5725. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  5726. $scope.thisdatato = ($scope.sdateTo || 0);
  5727. if($scope.thisdatato != 0) {
  5728. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  5729. } else {
  5730. $scope.condition.dateTo = ($scope.sdateTo || 0);
  5731. }
  5732. $scope.condition.venduuorname = $scope.vuuorname;
  5733. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  5734. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5735. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5736. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  5737. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  5738. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  5739. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  5740. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  5741. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5742. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5743. if(!$scope.suuorname) {
  5744. toaster.pop('warning','提示', '请先选择客户');
  5745. document.getElementById('suuorname').focus();//光标默认在客户
  5746. } else {
  5747. $scope.loading = true;
  5748. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  5749. if(data.length > 0) {
  5750. angular.forEach(data, function(item) {
  5751. item.$selected = true;
  5752. });
  5753. $scope.data = data;
  5754. $scope.checkboxes.checked = true;
  5755. $scope.getTotalMoney();
  5756. } else {
  5757. toaster.pop('info', '提示', '当前没有需要对账记录');
  5758. }
  5759. $scope.loading = false;
  5760. }, function(response) {
  5761. $scope.loading = false;
  5762. toaster.pop('error', '提示', response.data);
  5763. });
  5764. }
  5765. }
  5766. }
  5767. /**
  5768. * 点击勾选框,选中要转应收对账单的订单
  5769. * */
  5770. $scope.totalMoney = 0;
  5771. $scope.checkboxes = {
  5772. checked : false
  5773. };
  5774. // 点击勾选全部的复选框
  5775. $scope.checkAll = function(){
  5776. $scope.totalMoney = 0;
  5777. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  5778. var uuorname = $scope.suuorname;
  5779. var venduuorname = $scope.venduuorname;
  5780. var dateFrom = $scope.condition.dateFrom;
  5781. var dateTo = $scope.condition.dateTo;
  5782. var prodTitle = $scope.condition.prodTitle;
  5783. var prodSpec = $scope.condition.prodSpec;
  5784. var factory = $scope.condition.factory;
  5785. angular.forEach($scope.filteredData, function(item) {
  5786. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  5787. item.$selected = $scope.checkboxes.checked;
  5788. }
  5789. });
  5790. $scope.getTotalMoney();
  5791. };
  5792. //获取已选单据总金额
  5793. var total = true;
  5794. $scope.getTotalMoney = function(){
  5795. $scope.totalMoney = 0;
  5796. angular.forEach($scope.data, function(check) {
  5797. if(check.$selected){
  5798. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5799. }else{
  5800. $scope.totalMoney += 0;
  5801. }
  5802. });
  5803. }
  5804. // 点击其中一个明细的复选框
  5805. $scope.checkOne = function(check){
  5806. var result = true;
  5807. angular.forEach($scope.data, function(item) {
  5808. if(item.$selected != true){
  5809. result = false;
  5810. return;
  5811. }
  5812. });
  5813. $scope.checkboxes.checked = result;
  5814. };
  5815. $scope.haveSelected = false;
  5816. //生成应收对账单
  5817. $scope.createApCheck = function(){
  5818. //保存应收对账单主记录字段
  5819. $scope.apCheck = {
  5820. custUu: '',
  5821. custName: '',
  5822. enUu: '',
  5823. apDate: '',
  5824. beginDate: '',
  5825. endDate: '',
  5826. checkStatus: '未对账',
  5827. checkAmount: 0,
  5828. currency: '',
  5829. rate: '',
  5830. items: []
  5831. };
  5832. //保存来源单据相关信息
  5833. var sourceInfos = [];
  5834. //所允许的本次对账最大最小数量
  5835. $scope.data.maxThisCheckQty = 0;
  5836. $scope.data.minThisCheckQty = 0;
  5837. $scope.sameCust = true;
  5838. $scope.validQty = true;
  5839. $scope.loading = true;
  5840. angular.forEach($scope.data, function(check) {
  5841. //保存应收对账单明细行数据
  5842. $scope.item = {
  5843. inoutno: '',
  5844. inoutnodetno: '',
  5845. orderCode: '',
  5846. orderClass: '',
  5847. orderDetno: '',
  5848. price: '',
  5849. checkQty: '',
  5850. amount: '',
  5851. sourceId:'',
  5852. sourceTable:'',
  5853. oldYCheckQty:'',
  5854. status: 0,
  5855. receiveCode:'',
  5856. receiveName:'',
  5857. prodCode:'',
  5858. prodTitle:'',
  5859. prodSpec:'',
  5860. taxrate: '',
  5861. sendcode: '',
  5862. whname: '',
  5863. };
  5864. //应收对账单明细行来源表信息
  5865. $scope.sourceInfo = {
  5866. sourceId: '',
  5867. sourceTable: '',
  5868. newYCheckQty: ''
  5869. };
  5870. //此次对账后新的已转数
  5871. $scope.newYCheckQty = 0;
  5872. if(check.$selected == true) {
  5873. $scope.apCheck.custName = check.custName;
  5874. $scope.apCheck.enUu = check.enUu;
  5875. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5876. $scope.apCheck.apDate = check.piDate;
  5877. $scope.apCheck.rate = check.rate;
  5878. //必须是同一家客户才能生成对账单,否则提示错误
  5879. if($scope.apCheck.custUu == ''){
  5880. $scope.apCheck.custUu = check.custUu;
  5881. }else if($scope.apCheck.custUu !== check.custUu){
  5882. $scope.sameCust = false;
  5883. $scope.loading = false;
  5884. toaster.pop('error', '请选择同一家客户');
  5885. }
  5886. //必须是相同币别才能生成对账单,否则提示错误
  5887. if($scope.apCheck.currency == ''){
  5888. $scope.apCheck.currency = check.currency;
  5889. }else if($scope.apCheck.currency !== check.currency){
  5890. $scope.sameCust = false;
  5891. $scope.loading = false;
  5892. toaster.pop('error', '请选择同一种币别');
  5893. }
  5894. //本次对账数量必须小于总对账数量
  5895. if(check.qty > 0){
  5896. $scope.data.maxThisCheckQty = check.qty;
  5897. $scope.data.minThisCheckQty = 0;
  5898. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  5899. $scope.validQty = false;
  5900. $scope.loading = false;
  5901. toaster.pop('error','本次对账数量,填写有误!');
  5902. }
  5903. }else if(check.qty < 0){
  5904. $scope.data.maxThisCheckQty = 0;
  5905. $scope.data.minThisCheckQty = check.qty;
  5906. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  5907. $scope.validQty = false;
  5908. $scope.loading = false;
  5909. toaster.pop('error','本次对账数量,填写有误!');
  5910. }
  5911. }
  5912. //获取最小时间作为对账区间的起始时间
  5913. if($scope.apCheck.beginDate == ''){
  5914. $scope.apCheck.beginDate = check.piDate;
  5915. }else{
  5916. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  5917. }
  5918. //获取最大时间作为对账区间的截止时间
  5919. if($scope.apCheck.endDate == ''){
  5920. $scope.apCheck.endDate = check.piDate;
  5921. }else{
  5922. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  5923. }
  5924. //应收对账单明细行数据
  5925. $scope.item.orderCode = check.orderCode;
  5926. $scope.item.orderClass = check.piClass;
  5927. $scope.item.orderDetno = check.orderDetno;
  5928. $scope.item.price = check.orderPrice;
  5929. $scope.item.checkQty = check.thisCheckQty;
  5930. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  5931. $scope.item.sourceId = check.sourceId;
  5932. $scope.item.sourceTable = check.sourceTable;
  5933. $scope.item.oldYCheckQty = check.yCheckQty;
  5934. $scope.item.prodCode = check.prodCode;
  5935. $scope.item.prodTitle = check.prodTitle;
  5936. $scope.item.prodSpec = check.prodSpec;
  5937. $scope.item.inoutno = check.inOutNo;
  5938. $scope.item.inoutnodetno = check.detno;
  5939. $scope.item.taxrate = check.taxrate;
  5940. $scope.item.receiveCode = check.receiveCode;
  5941. $scope.item.receiveName = check.receiveName;
  5942. $scope.item.sendcode = check.sendcode;
  5943. $scope.item.whname = check.whname;
  5944. //来源表相关信息
  5945. $scope.sourceInfo.sourceId = check.sourceId;
  5946. $scope.sourceInfo.sourceTable = check.sourceTable;
  5947. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  5948. sourceInfos.push($scope.sourceInfo);
  5949. $scope.apCheck.items.push($scope.item);
  5950. $scope.haveSelected = true;
  5951. }
  5952. });
  5953. //保存生成的应收对账单
  5954. $scope.saveApCheck = function(){
  5955. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  5956. $scope.loading = false;
  5957. toaster.pop('success', '成功', '生成应收对账成功');
  5958. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  5959. }, function(response){
  5960. toaster.pop('error', '生成对账单失败', response.data);
  5961. })
  5962. };
  5963. //如果是同一家客户,生成对账单的同时,关闭模态框
  5964. if($scope.sameCust && $scope.validQty) {
  5965. $scope.saveApCheck();
  5966. }
  5967. }
  5968. }]);
  5969. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http){
  5970. BaseService.scrollBackToTop();
  5971. $scope.loading = true;
  5972. AccountEnterprise.get({}, function(data){
  5973. $scope.loading = false;
  5974. $scope.enterprise = data;
  5975. });
  5976. AccountEnterprise.growth({}, function(data){
  5977. if(data != null && data.length > 0) {
  5978. var growth = [], years = [];
  5979. angular.forEach(data, function(d){
  5980. var date = new Date(d.date), year = date.getFullYear();
  5981. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  5982. if(years.indexOf(year) == -1) {
  5983. years.push(year);
  5984. growth.push({year: year});
  5985. }
  5986. growth.push(d);
  5987. });
  5988. $scope.growth = growth;
  5989. }
  5990. });
  5991. // 更新企业信息
  5992. $scope.updateDetailInfo = function(){
  5993. $scope.loading = true;
  5994. AccountEnterprise.save($scope.enterprise, function(){
  5995. $scope.loading = false;
  5996. $scope.connectionEditing = false;
  5997. toaster.pop('success', '提示', '修改企业信息成功');
  5998. $state.reload();
  5999. }, function(response){
  6000. $scope.loading = false;
  6001. toaster.pop('error', '修改信息失败', response.data);
  6002. });
  6003. };
  6004. // 申请Saas
  6005. $scope.applySaas = function(){
  6006. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  6007. var modalInstance = $modal.open({
  6008. animation: true,
  6009. templateUrl: 'static/tpl/index/account/applySaas.html',
  6010. controller: 'ApplySaasCtrl',
  6011. resolve: {
  6012. enterprise: function(){return angular.copy($scope.enterprise);}
  6013. }
  6014. });
  6015. modalInstance.result.then(function(){
  6016. $state.reload();
  6017. }, function(){
  6018. });
  6019. } else {
  6020. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  6021. }
  6022. };
  6023. // 获取收货地址列表
  6024. ShipAddress.shipAddList({}, function(data) {
  6025. $scope.ships = data;
  6026. });
  6027. // 获取地址信息
  6028. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  6029. }).then(function(response) {
  6030. $scope.provinces = response.data;
  6031. });
  6032. // 新增收货地址保存
  6033. $scope.saveShipAddress = function(ship) {
  6034. ship.address = ship.province + ship.city + ship.district;
  6035. ShipAddress.saveAddress( {}, ship, function(data) {
  6036. if(data.success) {
  6037. ShipAddress.shipAddList({}, function(data) {
  6038. $scope.ships = data;
  6039. });
  6040. toaster.pop('success', '提示', data.success);
  6041. }
  6042. if(data.error) {
  6043. toaster.pop('error', '提示', data.error);
  6044. }
  6045. });
  6046. }
  6047. // 删除收货地址
  6048. $scope.removeShip = function(id, index) {
  6049. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  6050. $scope.ships.splice(index, 1);
  6051. toaster.pop('success', '提示', '收货地址删除成功');
  6052. }, function(response) {
  6053. toaster.pop('error', '提示', response.data);
  6054. });
  6055. };
  6056. // 编辑收货地址
  6057. $scope.editShip = function(ship){
  6058. var modalInstance = $modal.open({
  6059. animation: true,
  6060. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  6061. controller: 'ShipAddressCtrl',
  6062. resolve: {
  6063. ship: function(){return ship;}
  6064. }
  6065. });
  6066. modalInstance.result.then(function() {
  6067. ShipAddress.shipAddList({}, function(data) {
  6068. $scope.ships = data;
  6069. });
  6070. }, function(){
  6071. });
  6072. };
  6073. // 设置logo
  6074. $scope.showImageDialog = function(modal) {
  6075. require([ 'jquery-uploadify' ], function() {
  6076. $modal.open({
  6077. templateUrl : 'static/tpl/index/home/insert.html',
  6078. controller : 'ImageInsertCtrl',
  6079. backdrop : 'static'
  6080. }).result.then(function(image){
  6081. $scope.imageUrl = image.thumb;
  6082. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  6083. $scope.user = data;
  6084. }, function(response) {
  6085. toaster.pop('error', '设置图像失败,' + response.data);
  6086. });
  6087. });
  6088. });
  6089. }
  6090. }]);
  6091. // 编辑收货地址
  6092. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  6093. $scope.ship = ship;
  6094. // 获取地址信息
  6095. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  6096. }).then(function(response) {
  6097. $scope.provinces = response.data;
  6098. });
  6099. // 新增收货地址保存
  6100. $scope.saveShipAddress = function(ship) {
  6101. ship.address = ship.province + ship.city + ship.district;
  6102. ShipAddress.saveAddress( {}, ship, function(data) {
  6103. if(data.success) {
  6104. toaster.pop('success', '提示', data.success);
  6105. $modalInstance.close();
  6106. }
  6107. if(data.error) {
  6108. toaster.pop('error', '提示', data.error);
  6109. }
  6110. });
  6111. }
  6112. $scope.cancel = function() {
  6113. $modalInstance.dismiss();
  6114. }
  6115. }]);
  6116. // 申请Saas Controller
  6117. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  6118. $scope.enterprise = enterprise;
  6119. $scope.checking = false;
  6120. $scope.$watch('enterprise.enSaasUrl', function(){
  6121. if($scope.enterprise.enSaasUrl) {
  6122. $http.get('signup/saasUrlEnable', {
  6123. params: {
  6124. enSaasUrl: $scope.enterprise.enSaasUrl
  6125. }
  6126. }).success(function(data){
  6127. if(data && data == 'true') {
  6128. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  6129. } else {
  6130. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6131. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  6132. }
  6133. }).error(function(){
  6134. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6135. $scope.enSaasUrlErrorInfo = '验证出错';
  6136. });
  6137. } else {
  6138. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6139. }
  6140. });
  6141. var setSaasUrl = function(url) {
  6142. var index = url.indexOf('www.');
  6143. if(index != -1) {//包含www.
  6144. var substr = url.substring(index+4, url.length);
  6145. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  6146. } else {
  6147. $scope.enterprise.enSaasUrl = getHost(url);
  6148. }
  6149. };
  6150. // 解析获取网址的一级域名
  6151. var getHost = function(host){
  6152. var newhost;
  6153. var domain;
  6154. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  6155. for(var k in ArrDomain){
  6156. var re = eval('/\\' + ArrDomain[k] + '$/g');
  6157. newhost = host.replace(re, '');
  6158. if(newhost != host){
  6159. domain = ArrDomain[k];
  6160. break;
  6161. }
  6162. }
  6163. var hostar = newhost.split('.');
  6164. var s = hostar[hostar.length-1];
  6165. return s;
  6166. };
  6167. // 设置优企云服域名为官网网址一级域名
  6168. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  6169. $scope.apply = function(){
  6170. $scope.loading = true;
  6171. AccountEnterprise.applySaas({
  6172. enUU: $scope.enterprise.uu,
  6173. enSaasUrl: $scope.enterprise.enSaasUrl,
  6174. enAdminPassword: $scope.enterprise.enAdminPassword
  6175. }, {}, function(){
  6176. $scope.loading = false;
  6177. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  6178. $modalInstance.close();
  6179. }, function(response){
  6180. $scope.loading = false;
  6181. toaster.pop('error', '申请失败', response.data);
  6182. });
  6183. };
  6184. $scope.cancel = function () {
  6185. $modalInstance.dismiss();
  6186. };
  6187. }]);
  6188. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', 'AccountEnterprise', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert, AccountEnterprise){
  6189. BaseService.scrollBackToTop();
  6190. $scope.editing = false;
  6191. $scope.loading = true;
  6192. $scope.enterprise = null;
  6193. AccountUser.findDistribute({},function(data) {
  6194. $scope.distributes = data;
  6195. },function(response) {
  6196. toaster.pop('error', '系统错误', response.data);
  6197. })
  6198. AuthenticationService.getAuthentication().success(function(data) {
  6199. $scope.loading = false;
  6200. $scope.user = data;
  6201. });
  6202. var users = [];
  6203. $scope.tableParams = new ngTableParams({
  6204. page : 1,
  6205. count : 5,
  6206. sorting: {
  6207. userName: 'asc'
  6208. }
  6209. }, {
  6210. total : 0,
  6211. counts: [15, 25, 50, 100],
  6212. getData : function($defer, params) {
  6213. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  6214. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  6215. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  6216. angular.forEach($scope.users,function(user){
  6217. AccountEnterprise.get({}, function(data){
  6218. $scope.loading = false;
  6219. $scope.enterprise = data;
  6220. });
  6221. });
  6222. params.total(orderedData.length);
  6223. $defer.resolve($scope.users);
  6224. }
  6225. });
  6226. var loadUsers = function() {
  6227. AccountUser.query({}, function(data){
  6228. users = data;
  6229. $scope.tableParams.reload();
  6230. $scope.loading = false;
  6231. });
  6232. };
  6233. loadUsers();
  6234. $scope.saveUser = function(){
  6235. $scope.loading = true;
  6236. AccountUser.update({}, $scope.user, function(data){
  6237. $scope.loading = false;
  6238. toaster.pop('success', '提示', '修改用户信息成功');
  6239. AuthenticationService.getAuthentication().success(function(data) {
  6240. $scope.user = data;
  6241. });
  6242. loadUsers();
  6243. $scope.editing = false;
  6244. }, function(reponse){
  6245. $scope.loading = false;
  6246. toaster.pop('error', '失败', reponse.data);
  6247. });
  6248. };
  6249. $scope.updatePassword = function(){
  6250. var modalInstance = $modal.open({
  6251. animation: true,
  6252. templateUrl: 'updatePassword.html',
  6253. controller: 'PasswordCtrl',
  6254. resolve: {
  6255. user: function(){return $scope.user;}
  6256. }
  6257. });
  6258. modalInstance.result.then(function(){
  6259. }, function(){
  6260. });
  6261. };
  6262. $scope.newUser = {};
  6263. //弹出添加用户模态框
  6264. $scope.addExistUser = function(){
  6265. var modalInstance = $modal.open({
  6266. animation :true,
  6267. templateUrl : 'static/tpl/index/account/addExistUser.html',
  6268. controller : 'AddExistUserCtrl'
  6269. });
  6270. modalInstance.result.then(function(){
  6271. $scope.userTelSuccess = false;
  6272. $scope.userTelError = false;
  6273. }, function(){
  6274. });
  6275. };
  6276. /**
  6277. * 添加未注册用户
  6278. */
  6279. $scope.addUser = function() {
  6280. $scope.adding = true;
  6281. AccountUser.save({}, $scope.newUser, function(){
  6282. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  6283. $scope.newUser = {userSex: 'M'};
  6284. loadUsers();
  6285. $scope.adding = false;
  6286. $scope.newUserForm.newUserTel.$setValidity('available', false);
  6287. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  6288. $scope.userTelSuccess = false;
  6289. $scope.userTelError = false;
  6290. $scope.userEmailSuccess = false;
  6291. $scope.userEmailError = false;
  6292. }, function(response){
  6293. toaster.pop('error', '错误', response.data);
  6294. });
  6295. };
  6296. /**
  6297. * 验证手机号是否可用
  6298. */
  6299. $scope.telValid = function(tel) {
  6300. if(tel) {
  6301. $http.get('account/user/telEnable', {
  6302. params: {
  6303. tel: tel
  6304. }
  6305. }).success(function(data){
  6306. data = eval(data);
  6307. if(data == true) {
  6308. $scope.newUserForm.newUserTel.$setValidity('available', true);
  6309. $scope.userTelSuccess = true;
  6310. $scope.userTelError = false;
  6311. }else{
  6312. $scope.newUserForm.newUserTel.$setValidity('available', false);
  6313. $scope.userTelError = true;
  6314. $scope.userTelSuccess = false;
  6315. if(tel.length == 11)
  6316. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  6317. }
  6318. }).error(function(){
  6319. $scope.userTelSuccess = false;
  6320. $scope.userTelError = true;
  6321. });
  6322. } else {
  6323. $scope.userTelSuccess = false;
  6324. $scope.userTelError = false;
  6325. }
  6326. };
  6327. /**
  6328. * 验证邮箱是否可用
  6329. */
  6330. $scope.emailValid = function(email) {
  6331. if(email) {
  6332. $http.get('account/user/emailEnable', {
  6333. params: {
  6334. email: email
  6335. }
  6336. }).success(function(data){
  6337. data = eval(data);
  6338. if(data == true) {
  6339. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  6340. $scope.userEmailSuccess = true;
  6341. $scope.userEmailError = false;
  6342. } else {
  6343. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  6344. $scope.userEmailError = true;
  6345. $scope.userEmailSuccess = false;
  6346. }
  6347. }).error(function(){
  6348. $scope.userEmailError = true;
  6349. $scope.userEmailSuccess = false;
  6350. });
  6351. } else {
  6352. $scope.userEmailError = false;
  6353. $scope.userEmailSuccess = false;
  6354. }
  6355. };
  6356. /**
  6357. * 删除用户
  6358. */
  6359. $scope.removeUser = function(user) {
  6360. new ngAlert({
  6361. title: '提示',
  6362. content: '确定删除用户(' + user.userName + ')吗?'
  6363. }, function(){
  6364. AccountUser.remove({uu: user.userUU}, function(){
  6365. toaster.pop('success', '提示', '用户删除成功。');
  6366. loadUsers();
  6367. }, function(response){
  6368. toaster.pop('error', '删除失败', response.data);
  6369. });
  6370. });
  6371. };
  6372. // 编辑用户的角色
  6373. $scope.editUserRole = function(user) {
  6374. var modalInstance = $modal.open({
  6375. animation: true,
  6376. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  6377. controller: 'UserRoleCtrl',
  6378. resolve: {
  6379. user: function() {
  6380. return user;
  6381. }
  6382. }
  6383. });
  6384. modalInstance.result.then(function(changed, checked){
  6385. if(changed) {
  6386. if(checked)
  6387. $scope.newUser.roles = checked;
  6388. else
  6389. loadUsers();
  6390. }
  6391. });
  6392. };
  6393. // 为用户分配角色(删除企业)
  6394. $scope.removeVendor = function(user) {
  6395. var resultRole = true;
  6396. angular.forEach(user.roles,function(role){
  6397. if(role.issys == 1) {
  6398. toaster.pop('error', '提示', '管理员无需分配客户');
  6399. resultRole = false;
  6400. return;
  6401. }
  6402. })
  6403. if(resultRole) {
  6404. var modalInstance = $modal.open({
  6405. animation: true,
  6406. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  6407. controller: 'RemoveVendorCtrl',
  6408. resolve: {
  6409. user: function() {
  6410. return user;
  6411. }
  6412. }
  6413. });
  6414. }
  6415. }
  6416. // 为用户分配角色(添加企业)
  6417. $scope.addVendor = function(user,isIssy) {
  6418. if(!isIssy) {
  6419. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  6420. return;
  6421. }
  6422. var resultRole = true;
  6423. angular.forEach(user.roles,function(role){
  6424. if(role.issys == 1) {
  6425. toaster.pop('error', '提示', '管理员无需分配客户');
  6426. resultRole = false;
  6427. return;
  6428. }
  6429. })
  6430. if(resultRole) {
  6431. var modalInstance = $modal.open({
  6432. animation: true,
  6433. templateUrl: 'static/tpl/index/account/add_vendor.html',
  6434. controller: 'AddVendorCtrl',
  6435. resolve: {
  6436. user: function() {
  6437. return user;
  6438. }
  6439. }
  6440. });
  6441. modalInstance.result.then(function(changed, checked){
  6442. if(changed) {
  6443. if(checked)
  6444. $scope.newUser.roles = checked;
  6445. else
  6446. loadUsers();
  6447. }
  6448. });
  6449. }
  6450. };
  6451. }]);
  6452. // 登录手机号码验证
  6453. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  6454. $scope.user = user;
  6455. $scope.cancel = function(){
  6456. $modalInstance.close();
  6457. }
  6458. /*$scope.loading = false;
  6459. $scope.btnState = false;
  6460. $scope.clicks = 0;
  6461. var storage = window.localStorage;
  6462. //手机验证码定时器
  6463. $scope.msgInfoError = false;
  6464. var setBtnTimeDown = function(value) {
  6465. if(value > 0) {
  6466. $scope.btnState = true;
  6467. $timeout(function() {
  6468. $scope.$apply(function(){
  6469. storage.setItem("btnTimes", $scope.btnTimes);
  6470. $scope.btnTimes --;
  6471. value --;
  6472. setBtnTimeDown (value);
  6473. });
  6474. }, 500);
  6475. }else{
  6476. $scope.btnState = false;
  6477. }
  6478. };
  6479. if(storage.btnTimes > 1){
  6480. $scope.btnTimes = storage.btnTimes;
  6481. setBtnTimeDown(storage.btnTimes)
  6482. }else{
  6483. storage.removeItem("btnTimes");
  6484. }
  6485. $scope.updateTel = function(phoneCode, userTel, uu){
  6486. $scope.loading = true;
  6487. $scope.msgInfoError = false;
  6488. $scope.result = false;
  6489. //更新联系方式
  6490. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  6491. $scope.loading = false;
  6492. $scope.msgInfoError2 = false;
  6493. $scope.result = true;
  6494. AuthenticationService.getAuthentication().success(function(data) {
  6495. $timeout(function(){
  6496. $modalInstance.dismiss();
  6497. window.location.reload();
  6498. }, 1000);
  6499. }).error(function(response) {
  6500. });
  6501. }, function(response){
  6502. $scope.loading = false;
  6503. $scope.msgInfoError2 = response;
  6504. });
  6505. };
  6506. //获取验证码
  6507. $scope.getPhoneCode = function(userTel){
  6508. var timeInfo = 10;
  6509. $scope.clicks ++;
  6510. $scope.timeInfo = timeInfo;
  6511. if($scope.clicks >= 5){
  6512. $scope.errorloading = true;
  6513. $scope.msgInfoSuccess = false;
  6514. $scope.msgInfoError = false;
  6515. }else{
  6516. $scope.loading = true;
  6517. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  6518. $scope.loading = false;
  6519. $scope.msgInfoSuccess = data.success;
  6520. $scope.sendMsg = data;
  6521. $scope.btnTimes = 60;
  6522. setBtnTimeDown($scope.btnTimes);
  6523. $scope.msgInfoError = false;
  6524. },function(response){
  6525. console.log(response);
  6526. $scope.loading = false;
  6527. $scope.msgInfoError = false;
  6528. $scope.sendCheckMsg = false;
  6529. $scope.msgInfoSuccess = true;
  6530. });
  6531. }
  6532. }; */
  6533. }]);
  6534. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6535. $scope.checkboxes = {
  6536. checked : false
  6537. };
  6538. $scope.loading = true;
  6539. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  6540. $scope.enters = data;
  6541. $scope.loading = false;
  6542. angular.forEach($scope.enters, function(item) {
  6543. item:{
  6544. $selected:true;
  6545. }
  6546. });
  6547. })
  6548. // 点击勾选全部的复选框
  6549. $scope.checkAll = function() {
  6550. angular.forEach($scope.enters, function(item) {
  6551. item.$selected = $scope.checkboxes.checked;
  6552. });
  6553. };
  6554. // 点击其中一个明细的复选框
  6555. $scope.checkOne = function(vendor){
  6556. var result = true;
  6557. angular.forEach($scope.enters, function(item) {
  6558. if(item.$selected != true){
  6559. result = false;
  6560. return;
  6561. }
  6562. });
  6563. $scope.checkboxes.checked = result;
  6564. };
  6565. $scope.close = function(save) {
  6566. var chooseResult = [];
  6567. if(save) {
  6568. if(user.userUU) {
  6569. angular.forEach($scope.enters, function(item, i) {
  6570. if(item.$selected) {
  6571. chooseResult.push(item.id);
  6572. }
  6573. });
  6574. if(chooseResult.length > 0) {
  6575. $scope.loading = true;
  6576. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  6577. $scope.loading = false;
  6578. toaster.pop('success', '提示', '删除成功');
  6579. $modalInstance.close(false);
  6580. }, function(response){
  6581. $scope.loading = false;
  6582. toaster.pop('error', '删除失败', response.data);
  6583. $modalInstance.close(false);
  6584. })
  6585. } else {
  6586. toaster.pop('error', '删除失败', "您未勾选任何记录");
  6587. }
  6588. } else {
  6589. $modalInstance.close(true, $scope.checkboxes.checked);
  6590. }
  6591. } else {
  6592. $modalInstance.close(false);
  6593. }
  6594. };
  6595. }]);
  6596. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6597. $scope.checkboxes = {
  6598. checked : false
  6599. };
  6600. $scope.loading = true;
  6601. AccountUser.findVendor({uu : user.userUU},function(data) {
  6602. $scope.enters = data;
  6603. $scope.loading = false;
  6604. // angular.forEach($scope.enters, function(item) {
  6605. // if(item.distribute) {
  6606. // item:{
  6607. // $selected:false;
  6608. // }
  6609. // } else {
  6610. // item:{
  6611. // $selected:true;
  6612. // }
  6613. // }
  6614. // });
  6615. })
  6616. // 点击勾选全部的复选框
  6617. $scope.checkAll = function() {
  6618. angular.forEach($scope.enters, function(item) {
  6619. item.distribute = $scope.checkboxes.checked;
  6620. });
  6621. };
  6622. // 点击其中一个明细的复选框
  6623. $scope.checkOne = function(vendor){
  6624. var result = true;
  6625. angular.forEach($scope.enters, function(item) {
  6626. if(item.distribute != true){
  6627. result = false;
  6628. return;
  6629. }
  6630. });
  6631. $scope.checkboxes.checked = result;
  6632. };
  6633. $scope.close = function(save) {
  6634. var chooseResult = [];
  6635. if(save) {
  6636. if(user.userUU) {
  6637. angular.forEach($scope.enters, function(item, i) {
  6638. // if(item.distribute) {
  6639. chooseResult.push(item);
  6640. // }
  6641. });
  6642. if(chooseResult.length > 0) {
  6643. $scope.loading = true;
  6644. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  6645. $scope.loading = false;
  6646. toaster.pop('success', '提示', '保存成功');
  6647. $modalInstance.close(false);
  6648. }, function(response){
  6649. $scope.loading = false;
  6650. toaster.pop('error', '保存失败', response.data);
  6651. $modalInstance.close(false);
  6652. })
  6653. } else {
  6654. toaster.pop('error', '保存失败', "您未勾选任何记录");
  6655. }
  6656. } else {
  6657. $modalInstance.close(true, $scope.checkboxes.checked);
  6658. }
  6659. } else {
  6660. $modalInstance.close(false);
  6661. }
  6662. };
  6663. }]);
  6664. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  6665. $scope.checked = [];
  6666. $scope.master = [];
  6667. AccountRole.query({}, function(data){
  6668. if(user && data) {
  6669. var rs = [], checked = [];
  6670. angular.forEach(user.roles, function(r){
  6671. rs.push(r.id);
  6672. });
  6673. angular.forEach(data, function(d){
  6674. if(rs.indexOf(d.id) > -1) {
  6675. d.$checked = true;
  6676. checked.push(d);
  6677. }
  6678. });
  6679. }
  6680. $scope.roles = data;
  6681. $scope.checked = checked;
  6682. $scope.master = angular.copy($scope.checked);
  6683. });
  6684. $scope.select = function(role) {
  6685. role.$checked = !role.$checked;
  6686. if(role.$checked) {
  6687. $scope.checked.push(role);
  6688. } else {
  6689. angular.forEach($scope.checked, function(c, i){
  6690. if(c.id == role.id)
  6691. $scope.checked.splice(i, 1);
  6692. });
  6693. }
  6694. };
  6695. $scope.isChanged = function() {
  6696. return !angular.equals($scope.master, $scope.checked);
  6697. };
  6698. $scope.close = function(save) {
  6699. if(save) {
  6700. if(user.userUU) {
  6701. user.roles = $scope.checked;
  6702. AccountUser.update({}, user, function(){
  6703. toaster.pop('success', '提示', '保存成功');
  6704. $modalInstance.close(true);
  6705. }, function(response){
  6706. toaster.pop('error', '保存失败', response.data);
  6707. });
  6708. } else {
  6709. $modalInstance.close(true, $scope.checked);
  6710. }
  6711. } else {
  6712. $modalInstance.close(false);
  6713. }
  6714. };
  6715. }]);
  6716. // 修改密码Controller
  6717. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6718. $scope.user = user;
  6719. $scope.checking = false;
  6720. //输入原密码后验证原密码是否正确
  6721. $scope.checkPassword = function(password) {
  6722. $scope.checking = true;
  6723. $scope.checkSuccess = false;
  6724. $scope.checkFailed = false;
  6725. AccountUser.checkPassword({password: password}, function(data){
  6726. $scope.checkSuccess = true;
  6727. $scope.checking = false;
  6728. $scope.checkFailed = false;
  6729. }, function(response){
  6730. $scope.checkFailed = true;
  6731. $scope.checking = false;
  6732. $scope.checkSuccess = false;
  6733. });
  6734. };
  6735. //修改密码
  6736. $scope.ok = function () {
  6737. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  6738. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  6739. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  6740. $scope.user.password = null;
  6741. $scope.user.newPassword = null;
  6742. $scope.user.newPassword1 = null;
  6743. $scope.checking = false;
  6744. $scope.checkSuccess = false;
  6745. $scope.checkFailed = false;
  6746. }, function(response){
  6747. toaster.pop('error', '错误', response.data);
  6748. });
  6749. } else {
  6750. toaster.pop('error', '错误', '重复密码不一致');
  6751. }
  6752. };
  6753. $scope.cancel = function () {
  6754. $modalInstance.dismiss();
  6755. };
  6756. }]);
  6757. /*
  6758. * 绑定用户到企业
  6759. */
  6760. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout){
  6761. $scope.searching = false;
  6762. //根据输入的内容查找用户
  6763. $scope.searchUser = function(keyWord) {
  6764. $scope.searching = true;
  6765. $scope.searchSuccess = false;
  6766. $scope.searchFailed = false;
  6767. $scope.illegalError = false;
  6768. $scope.reBindError = false;
  6769. $scope.bindSuccess = false;
  6770. $scope.okDisabled = false;
  6771. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  6772. $scope.searchSuccess = true;
  6773. $scope.searchFailed = false;
  6774. $scope.user = data; //查询到的用户
  6775. }, function(response){
  6776. $scope.searchSuccess = false;
  6777. $scope.searchFailed = true;
  6778. });
  6779. };
  6780. //确认绑定
  6781. $scope.ok = function (keyWord) {
  6782. AuthenticationService.getAuthentication().success(function(data) {
  6783. $scope.currentUser = data; //当前登录的用户(管理员)
  6784. //不可自己绑定自己
  6785. if($scope.currentUser.userUU == $scope.user.userUU){
  6786. $scope.illegalError = true;
  6787. $scope.okDisabled = true;
  6788. return false;
  6789. }
  6790. //用户未绑定到任何企业时
  6791. if(!$scope.user.enterprises){
  6792. //正常绑定
  6793. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  6794. $scope.bindSuccess = true; //绑定成功
  6795. $scope.okDisabled = true;
  6796. }, function(response){
  6797. });
  6798. return true;
  6799. }
  6800. //用户已绑定到某些企业时
  6801. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  6802. if($scope.currentUser.enterprises[i].current){
  6803. for(var j = 0; j < $scope.user.enterprises.length; j++){
  6804. //该用户已绑定到当前企业,不可重复绑定
  6805. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  6806. $scope.reBindError = true;
  6807. $scope.okDisabled = true;
  6808. return false;
  6809. }
  6810. }
  6811. //该用户未绑定到当前企业,可以进行绑定
  6812. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  6813. $scope.bindSuccess = true; //绑定成功
  6814. $scope.okDisabled = true;
  6815. }, function(response){
  6816. console.log("绑定失败!");
  6817. });
  6818. }
  6819. }
  6820. });
  6821. $timeout(function() {
  6822. $modalInstance.close(true);
  6823. }, 500);
  6824. };
  6825. $scope.cancel = function () {
  6826. $modalInstance.dismiss();
  6827. };
  6828. }]);
  6829. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  6830. $scope.erpParams = new ngTableParams({
  6831. page : 1,
  6832. count : 5,
  6833. sorting: {
  6834. time: 'desc'
  6835. }
  6836. }, {
  6837. total : 0,
  6838. counts: [5, 10, 25, 50],
  6839. getData : function($defer, params) {
  6840. $scope.loading = true;
  6841. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  6842. $scope.loading = false;
  6843. if(page) {
  6844. params.total(page.totalElements);
  6845. $defer.resolve(page.content);
  6846. }
  6847. }, function(response){
  6848. $scope.loading = false;
  6849. toaster.pop('error', '数据加载失败', response.data);
  6850. });
  6851. }
  6852. });
  6853. $scope.usageParams = new ngTableParams({
  6854. page : 1,
  6855. count : 5,
  6856. sorting: {
  6857. time: 'desc'
  6858. }
  6859. }, {
  6860. total : 0,
  6861. counts: [5, 10, 25, 50],
  6862. getData : function($defer, params) {
  6863. $scope.loading = true;
  6864. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  6865. $scope.loading = false;
  6866. if(page) {
  6867. params.total(page.totalElements);
  6868. $defer.resolve(page.content);
  6869. }
  6870. }, function(response){
  6871. $scope.loading = false;
  6872. toaster.pop('error', '数据加载失败', response.data);
  6873. });
  6874. }
  6875. });
  6876. }]);
  6877. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  6878. AccountResource.query({}, function(data){
  6879. if(data && data.length > 0) {
  6880. data[0].$open = true;
  6881. }
  6882. $scope.resources = data;
  6883. });
  6884. }]);
  6885. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  6886. $scope.roles = {};
  6887. var getData = function() {
  6888. AccountRole.query({}, function(data){
  6889. var defaults = [], custom = [];
  6890. angular.forEach(data, function(d){
  6891. if(d.isdefault == 1)
  6892. defaults.push(d);
  6893. else
  6894. custom.push(d);
  6895. });
  6896. $scope.roles = {defaults: defaults, custom: custom};
  6897. });
  6898. };
  6899. getData();
  6900. $scope.editRole = function(role){
  6901. var modalInstance = $modal.open({
  6902. animation: true,
  6903. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  6904. controller: 'RoleEditCtrl',
  6905. resolve: {
  6906. role: function() {
  6907. return role;
  6908. }
  6909. }
  6910. });
  6911. modalInstance.result.then(function(added){
  6912. added && (getData());
  6913. });
  6914. };
  6915. }]);
  6916. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  6917. BaseService.scrollBackToTop();
  6918. $scope.role = role;
  6919. $scope.master = angular.copy($scope.role);
  6920. var isNew = role == null;
  6921. $scope.cancel = function() {
  6922. $modalInstance.close(false);
  6923. };
  6924. AccountResource.query({}, function(data){
  6925. if(data && data.length > 0) {
  6926. if(role && role.resourceItems) {
  6927. var rs = [];// 已分配的资源的id
  6928. angular.forEach(role.resourceItems, function(item){
  6929. rs.push(item.id);
  6930. });
  6931. angular.forEach(data, function(resource){
  6932. var c = 0;
  6933. angular.forEach(resource.items, function(item){
  6934. if(rs.indexOf(item.id) > -1) {
  6935. item.$checked = true;
  6936. c += 1;
  6937. }
  6938. });
  6939. resource.$checked = c == resource.items.length;
  6940. });
  6941. }
  6942. $scope.resourceItems = data[0].items;
  6943. data[0].$active = true;
  6944. }
  6945. $scope.resources = data;
  6946. $timeout(function(){
  6947. angular.forEach($scope.resources, function(resource){
  6948. var c = 0;
  6949. angular.forEach(resource.items, function(item){
  6950. item.$checked && (c+=1);
  6951. });
  6952. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  6953. });
  6954. }, 100);
  6955. });
  6956. $scope.onItemClick = function(resource) {
  6957. $scope.resourceItems = resource.items;
  6958. angular.forEach($scope.resources, function(r){
  6959. r.$active = false;
  6960. });
  6961. resource.$active = true;
  6962. };
  6963. var getChecked = function() {
  6964. var items = [];
  6965. angular.forEach($scope.resources, function(resource){
  6966. angular.forEach(resource.items, function(item){
  6967. item.$checked && (items.push(item));
  6968. });
  6969. });
  6970. $scope.role.resourceItems = items;
  6971. };
  6972. $scope.onResourceChange = function(resource) {
  6973. angular.forEach(resource.items, function(item){
  6974. item.$checked = resource.$checked;
  6975. });
  6976. getChecked();
  6977. };
  6978. $scope.onItemChange = function() {
  6979. angular.forEach($scope.resources, function(resource){
  6980. if(resource.$active) {
  6981. var c = 0;
  6982. angular.forEach(resource.items, function(item){
  6983. item.$checked && (c+=1);
  6984. });
  6985. resource.$checked = (c == resource.items.length);
  6986. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  6987. }
  6988. });
  6989. getChecked();
  6990. };
  6991. $scope.isChanged = function(formData) {
  6992. if(!$scope.master)
  6993. return true;
  6994. return !angular.equals(formData, $scope.master);
  6995. };
  6996. $scope.save = function() {
  6997. $scope.master = angular.copy($scope.role);
  6998. AccountRole.save($scope.master, function(){
  6999. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  7000. $modalInstance.close(true);
  7001. }, function(response){
  7002. toaster.pop('error', '错误', response.data);
  7003. });
  7004. };
  7005. $scope.del = function() {
  7006. new ngAlert({
  7007. title: '提示',
  7008. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  7009. }, function(){
  7010. AccountRole.remove({id: role.id}, function(){
  7011. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  7012. $modalInstance.close(true);
  7013. }, function(response){
  7014. toaster.pop('error', '错误', response.data);
  7015. });
  7016. })
  7017. };
  7018. }]);
  7019. /**
  7020. * 委外订单
  7021. */
  7022. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  7023. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  7024. BaseService.scrollBackToTop();
  7025. $scope.active = 'todo';
  7026. $scope.dateZoneText = '不限';
  7027. $scope.condition = {dateZone: -1};
  7028. $scope.changeDateZone = function(zone) {
  7029. $scope.condition.dateZone = zone;
  7030. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  7031. $scope.condition.$dateZoneOpen = false;
  7032. getDateCondition(zone, $scope.condition);
  7033. $scope.tableParams.reload();
  7034. };
  7035. $scope.setActive = function(state) {
  7036. if($scope.active != state) {
  7037. $scope.active = state;
  7038. if($scope.tableParams.page() == 1)
  7039. $scope.tableParams.reload();
  7040. else
  7041. $scope.tableParams.page(1);
  7042. }
  7043. };
  7044. var getService = function() {
  7045. return MakeOrder;
  7046. };
  7047. $scope.tableParams = new ngTableParams({
  7048. page : 1,
  7049. count : 5,
  7050. sorting: {
  7051. date: 'desc'
  7052. }
  7053. }, {
  7054. total : 0,
  7055. counts: [5, 10, 25, 50],
  7056. getData : function($defer, params) {
  7057. $scope.loading = true;
  7058. var pageParams = params.url();
  7059. pageParams.searchFilter = {};
  7060. pageParams.searchFilter.keyword = $scope.keyword;
  7061. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7062. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7063. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7064. $scope.loading = false;
  7065. if(page) {
  7066. params.total(page.totalElement);
  7067. $defer.resolve(page.content);
  7068. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7069. }
  7070. }, function(response){
  7071. $scope.loading = false;
  7072. toaster.pop('error', '数据加载失败', response.data);
  7073. });
  7074. }
  7075. });
  7076. $scope.getOrderTotal = function(items) {
  7077. var sum = 0;
  7078. angular.forEach(items, function(item){
  7079. sum += item.qty * item.price;
  7080. });
  7081. return sum;
  7082. };
  7083. $scope.openDatePicker = function($event, item, openParam) {
  7084. $event.preventDefault();
  7085. $event.stopPropagation();
  7086. item[openParam] = !item[openParam];
  7087. };
  7088. $scope.parseDate = function(dateStr) {
  7089. if(dateStr)
  7090. return Date.parse(dateStr, 'yyyy-MM-dd');
  7091. return new Date();
  7092. };
  7093. // 打开回复
  7094. $scope.openReply = function(order) {
  7095. if(!order.reply) {
  7096. order.reply = {
  7097. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7098. delivery: order.delivery
  7099. }
  7100. }
  7101. order.$editing = true;
  7102. };
  7103. // 关闭回复
  7104. $scope.closeReply = function(order) {
  7105. order.$editing = false;
  7106. }
  7107. // 搜索框回车
  7108. $scope.onSearch = function() {
  7109. $scope.tableParams.page(1);
  7110. $scope.tableParams.reload();
  7111. };
  7112. // 选择查找日期
  7113. $scope.onDateCondition = function(){
  7114. $scope.tableParams.page(1);
  7115. $scope.tableParams.reload();
  7116. };
  7117. // 点击回复
  7118. $scope.onReplyClick = function(order, inverse) {
  7119. if(order.reply) {
  7120. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7121. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7122. return;
  7123. }
  7124. var reply = angular.copy(order.reply);
  7125. if(reply.delivery) {
  7126. if(typeof reply.delivery == 'object')
  7127. reply.delivery = reply.delivery.getTime();
  7128. } else {
  7129. reply.delivery = order.delivery;
  7130. }
  7131. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7132. $scope.loading = true;
  7133. MakeOrder.reply({orderId: order.id}, reply, function(){
  7134. $scope.loading = false;
  7135. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7136. $scope.tableParams.reload();
  7137. }, function(response){
  7138. $scope.loading = false;
  7139. toaster.pop('error', '回复失败', response.data);
  7140. });
  7141. }
  7142. };
  7143. //委外加工单
  7144. $scope.print = function(order) {
  7145. MakeOrder.printCount({id: order.id},{});//增加打印此次
  7146. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  7147. };
  7148. // 获取回复记录
  7149. $scope.getReply = function(order) {
  7150. if(!order.replies) {
  7151. MakeOrder.getReply({orderId: order.id}, function(replies){
  7152. order.replies = replies;
  7153. });
  7154. }
  7155. };
  7156. }]);
  7157. /**
  7158. * 委外加工单详细
  7159. */
  7160. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  7161. BaseService.scrollBackToTop();
  7162. var loadData = function() {
  7163. MakeOrder.get({id: $stateParams.id}, function(data){
  7164. $scope.order = data;
  7165. var sum = $scope.order.qty * $scope.order.price;
  7166. $scope.order.total = sum;
  7167. $scope.loading = false;
  7168. });
  7169. };
  7170. loadData();
  7171. // 获取回复记录
  7172. $scope.getReply = function(item) {
  7173. if(!item.replies) {
  7174. MakeOrder.getReply({orderId: item.id}, function(replies){
  7175. item.replies = replies;
  7176. });
  7177. }
  7178. };
  7179. $scope.openDatePicker = function($event, item, openParam) {
  7180. $event.preventDefault();
  7181. $event.stopPropagation();
  7182. item[openParam] = !item[openParam];
  7183. };
  7184. // 点击回复
  7185. $scope.onReplyClick = function(order, inverse) {
  7186. if(order.reply) {
  7187. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7188. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7189. return;
  7190. }
  7191. var reply = angular.copy(order.reply);
  7192. if(reply.delivery) {
  7193. if(typeof reply.delivery == 'object')
  7194. reply.delivery = reply.delivery.getTime();
  7195. } else {
  7196. reply.delivery = order.delivery;
  7197. }
  7198. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7199. $scope.loading = true;
  7200. MakeOrder.reply({orderId: order.id}, reply, function(){
  7201. $scope.loading = false;
  7202. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7203. loadData();
  7204. }, function(response){
  7205. $scope.loading = false;
  7206. toaster.pop('error', '回复失败', response.data);
  7207. });
  7208. }
  7209. };
  7210. // 打开回复
  7211. $scope.openReply = function(order) {
  7212. if(!order.reply) {
  7213. order.reply = {
  7214. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7215. delivery: order.delivery
  7216. }
  7217. }
  7218. order.$editing = true;
  7219. };
  7220. // 关闭回复
  7221. $scope.closeReply = function(order) {
  7222. order.$editing = false;
  7223. }
  7224. // 委外订单
  7225. $scope.print = function(order) {
  7226. MakeOrder.printCount({id: order.id},{});//增加打印此次
  7227. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  7228. };
  7229. }]);
  7230. /**
  7231. * 客户委外验收
  7232. */
  7233. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  7234. BaseService.scrollBackToTop();
  7235. $scope.active = 'all';
  7236. $scope.agreedText = '全部';
  7237. $scope.dateZoneText = '一个月内';
  7238. $scope.condition = {dateZone: 1};
  7239. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7240. $scope.changeAgreed = function(agreed) {
  7241. $scope.condition.agreed = agreed;
  7242. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7243. $scope.condition.$agreedOpen = false;
  7244. };
  7245. $scope.changeDateZone = function(zone) {
  7246. $scope.condition.dateZone = zone;
  7247. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7248. $scope.condition.$dateZoneOpen = false;
  7249. getDateCondition(zone, $scope.condition);
  7250. $scope.tableParams.reload();
  7251. };
  7252. $scope.setActive = function(state) {
  7253. if($scope.active != state) {
  7254. $scope.active = state;
  7255. if($scope.tableParams.page() == 1)
  7256. $scope.tableParams.reload();
  7257. else
  7258. $scope.tableParams.page(1);
  7259. }
  7260. };
  7261. var getService = function() {
  7262. return MakeAccept;
  7263. };
  7264. $scope.tableParams = new ngTableParams({
  7265. page : 1,
  7266. count : 5,
  7267. sorting: {
  7268. date: 'desc'
  7269. }
  7270. }, {
  7271. total : 0,
  7272. counts: [5, 10, 25, 50],
  7273. getData : function($defer, params) {
  7274. $scope.loading = true;
  7275. var pageParams = params.url();
  7276. pageParams.searchFilter = {};
  7277. pageParams.searchFilter.keyword = $scope.keyword;
  7278. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7279. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7280. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7281. $scope.loading = false;
  7282. if(page) {
  7283. params.total(page.totalElement);
  7284. $defer.resolve(page.content);
  7285. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7286. }
  7287. }, function(response){
  7288. $scope.loading = false;
  7289. toaster.pop('error', '数据加载失败', response.data);
  7290. });
  7291. }
  7292. });
  7293. $scope.openDatePicker = function($event, item, openParam) {
  7294. $event.preventDefault();
  7295. $event.stopPropagation();
  7296. item[openParam] = !item[openParam];
  7297. };
  7298. // 搜索框回车
  7299. $scope.onSearch = function() {
  7300. $scope.tableParams.page(1);
  7301. $scope.tableParams.reload();
  7302. };
  7303. // 选择查找日期
  7304. $scope.onDateCondition = function(){
  7305. $scope.tableParams.page(1);
  7306. $scope.tableParams.reload();
  7307. };
  7308. }]);
  7309. /**
  7310. * 客户委外验退
  7311. */
  7312. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  7313. BaseService.scrollBackToTop();
  7314. $scope.active = 'all';
  7315. $scope.agreedText = '全部';
  7316. $scope.dateZoneText = '一个月内';
  7317. $scope.condition = {dateZone: 1};
  7318. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7319. $scope.changeAgreed = function(agreed) {
  7320. $scope.condition.agreed = agreed;
  7321. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7322. $scope.condition.$agreedOpen = false;
  7323. };
  7324. $scope.changeDateZone = function(zone) {
  7325. $scope.condition.dateZone = zone;
  7326. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7327. $scope.condition.$dateZoneOpen = false;
  7328. getDateCondition(zone, $scope.condition);
  7329. $scope.tableParams.reload();
  7330. };
  7331. $scope.setActive = function(state) {
  7332. if($scope.active != state) {
  7333. $scope.active = state;
  7334. if($scope.tableParams.page() == 1)
  7335. $scope.tableParams.reload();
  7336. else
  7337. $scope.tableParams.page(1);
  7338. }
  7339. };
  7340. var getService = function() {
  7341. return MakeReturn;
  7342. };
  7343. $scope.tableParams = new ngTableParams({
  7344. page : 1,
  7345. count : 5,
  7346. sorting: {
  7347. date: 'desc'
  7348. }
  7349. }, {
  7350. total : 0,
  7351. counts: [5, 10, 25, 50],
  7352. getData : function($defer, params) {
  7353. $scope.loading = true;
  7354. var pageParams = params.url();
  7355. pageParams.searchFilter = {};
  7356. pageParams.searchFilter.keyword = $scope.keyword;
  7357. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7358. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7359. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7360. $scope.loading = false;
  7361. if(page) {
  7362. params.total(page.totalElement);
  7363. $defer.resolve(page.content);
  7364. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7365. }
  7366. }, function(response){
  7367. $scope.loading = false;
  7368. toaster.pop('error', '数据加载失败', response.data);
  7369. });
  7370. }
  7371. });
  7372. $scope.openDatePicker = function($event, item, openParam) {
  7373. $event.preventDefault();
  7374. $event.stopPropagation();
  7375. item[openParam] = !item[openParam];
  7376. };
  7377. // 搜索框回车
  7378. $scope.onSearch = function() {
  7379. $scope.tableParams.page(1);
  7380. $scope.tableParams.reload();
  7381. };
  7382. // 选择查找日期
  7383. $scope.onDateCondition = function(){
  7384. $scope.tableParams.page(1);
  7385. $scope.tableParams.reload();
  7386. };
  7387. }]);
  7388. /**
  7389. * 委外加工变更
  7390. */
  7391. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  7392. BaseService.scrollBackToTop();
  7393. $scope.active = 'all';
  7394. $scope.agreedText = '全部';
  7395. $scope.dateZoneText = '一个月内';
  7396. $scope.condition = {dateZone: 1};
  7397. $scope.changeAgreed = function(agreed) {
  7398. $scope.condition.agreed = agreed;
  7399. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7400. $scope.condition.$agreedOpen = false;
  7401. };
  7402. $scope.changeDateZone = function(zone) {
  7403. $scope.condition.dateZone = zone;
  7404. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7405. $scope.condition.$dateZoneOpen = false;
  7406. getDateCondition(zone, $scope.condition);
  7407. $scope.tableParams.reload();
  7408. };
  7409. $scope.setActive = function(state) {
  7410. if($scope.active != state) {
  7411. $scope.active = state;
  7412. if($scope.tableParams.page() == 1)
  7413. $scope.tableParams.reload();
  7414. else
  7415. $scope.tableParams.page(1);
  7416. }
  7417. };
  7418. var getService = function() {
  7419. return MakeChange;
  7420. };
  7421. $scope.tableParams = new ngTableParams({
  7422. page : 1,
  7423. count : 5,
  7424. sorting: {
  7425. orderChangeDate: 'desc'
  7426. }
  7427. }, {
  7428. total : 0,
  7429. counts: [5, 10, 25, 50],
  7430. getData : function($defer, params) {
  7431. $scope.loading = true;
  7432. var pageParams = params.url();
  7433. pageParams.searchFilter = {};
  7434. pageParams.searchFilter.keyword = $scope.keyword;
  7435. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7436. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7437. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7438. $scope.loading = false;
  7439. if(page) {
  7440. params.total(page.totalElement);
  7441. $defer.resolve(page.content);
  7442. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7443. }
  7444. }, function(response){
  7445. $scope.loading = false;
  7446. toaster.pop('error', '数据加载失败', response.data);
  7447. });
  7448. }
  7449. });
  7450. $scope.openDatePicker = function($event, item, openParam) {
  7451. $event.preventDefault();
  7452. $event.stopPropagation();
  7453. item[openParam] = !item[openParam];
  7454. };
  7455. // 打开回复
  7456. $scope.openReply = function(change) {
  7457. change.$editing = true;
  7458. };
  7459. // 关闭回复
  7460. $scope.closeReply = function(change) {
  7461. change.$editing = false;
  7462. }
  7463. // 确定回复
  7464. $scope.onReplyClick = function(change) {
  7465. if(change.$agreed) {
  7466. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7467. $scope.loading = true;
  7468. MakeChange.reply({itemId: change.id}, reply, function(){
  7469. $scope.loading = false;
  7470. toaster.pop('info', '提示', '回复成功');
  7471. $scope.tableParams.reload();
  7472. }, function(response){
  7473. $scope.loading = false;
  7474. toaster.pop('error', '回复失败', response.data);
  7475. });
  7476. }
  7477. };
  7478. // 搜索框回车
  7479. $scope.onSearch = function() {
  7480. $scope.tableParams.page(1);
  7481. $scope.tableParams.reload();
  7482. };
  7483. // 选择查找日期
  7484. $scope.onDateCondition = function(){
  7485. $scope.tableParams.page(1);
  7486. $scope.tableParams.reload();
  7487. };
  7488. }]);
  7489. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  7490. BaseService.scrollBackToTop();
  7491. var loadData = function() {
  7492. MakeChange.get({id: $stateParams.id}, function(data){
  7493. $scope.change = data;
  7494. });
  7495. };
  7496. loadData();
  7497. $scope.openDatePicker = function($event, item, openParam) {
  7498. $event.preventDefault();
  7499. $event.stopPropagation();
  7500. item[openParam] = !item[openParam];
  7501. };
  7502. $scope.onReplyClick = function(change) {
  7503. if(change.$agreed) {
  7504. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7505. MakeChange.reply({itemId: change.id}, reply, function(){
  7506. toaster.pop('info', '提示', '回复成功');
  7507. loadData();
  7508. }, function(response){
  7509. toaster.pop('error', '回复失败', response.data);
  7510. });
  7511. }
  7512. };
  7513. }]);
  7514. /**
  7515. * 委外加工
  7516. */
  7517. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  7518. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  7519. BaseService.scrollBackToTop();
  7520. $scope.active = 'all';
  7521. $scope.agreedText = '全部';
  7522. $scope.dateZoneText = '一个月内';
  7523. $scope.condition = {dateZone: 1};
  7524. $scope.changeAgreed = function(agreed) {
  7525. $scope.condition.agreed = agreed;
  7526. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7527. $scope.condition.$agreedOpen = false;
  7528. };
  7529. $scope.changeDateZone = function(zone) {
  7530. $scope.condition.dateZone = zone;
  7531. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7532. $scope.condition.$dateZoneOpen = false;
  7533. getDateCondition(zone, $scope.condition);
  7534. $scope.tableParams.reload();
  7535. };
  7536. $scope.setActive = function(state) {
  7537. if($scope.active != state) {
  7538. $scope.active = state;
  7539. if($scope.tableParams.page() == 1)
  7540. $scope.tableParams.reload();
  7541. else
  7542. $scope.tableParams.page(1);
  7543. }
  7544. };
  7545. var getService = function() {
  7546. return MakeOutOrder;
  7547. };
  7548. $scope.tableParams = new ngTableParams({
  7549. page : 1,
  7550. count : 5,
  7551. sorting: {
  7552. date: 'desc'
  7553. }
  7554. }, {
  7555. total : 0,
  7556. counts: [5, 10, 25, 50],
  7557. getData : function($defer, params) {
  7558. $scope.loading = true;
  7559. var pageParams = params.url();
  7560. pageParams.searchFilter = {};
  7561. pageParams.searchFilter.keyword = $scope.keyword;
  7562. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7563. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7564. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7565. $scope.loading = false;
  7566. if(page) {
  7567. params.total(page.totalElement);
  7568. $defer.resolve(page.content);
  7569. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7570. }
  7571. }, function(response){
  7572. $scope.loading = false;
  7573. toaster.pop('error', '数据加载失败', response.data);
  7574. });
  7575. }
  7576. });
  7577. $scope.openDatePicker = function($event, item, openParam) {
  7578. $event.preventDefault();
  7579. $event.stopPropagation();
  7580. item[openParam] = !item[openParam];
  7581. };
  7582. // 打开回复
  7583. $scope.openReply = function(change) {
  7584. change.$editing = true;
  7585. };
  7586. // 关闭回复
  7587. $scope.closeReply = function(change) {
  7588. change.$editing = false;
  7589. }
  7590. // 确定回复
  7591. $scope.onReplyClick = function(change) {
  7592. if(change.$agreed) {
  7593. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7594. $scope.loading = true;
  7595. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  7596. $scope.loading = false;
  7597. toaster.pop('info', '提示', '回复成功');
  7598. $scope.tableParams.reload();
  7599. }, function(response){
  7600. $scope.loading = false;
  7601. toaster.pop('error', '回复失败', response.data);
  7602. });
  7603. }
  7604. };
  7605. // 搜索框回车
  7606. $scope.onSearch = function() {
  7607. $scope.tableParams.page(1);
  7608. $scope.tableParams.reload();
  7609. };
  7610. // 选择查找日期
  7611. $scope.onDateCondition = function(){
  7612. $scope.tableParams.page(1);
  7613. $scope.tableParams.reload();
  7614. };
  7615. }]);
  7616. /**
  7617. * 委外加工详细
  7618. */
  7619. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  7620. BaseService.scrollBackToTop();
  7621. var loadData = function() {
  7622. MakeOutOrder.get({id: $stateParams.id}, function(data){
  7623. $scope.order = data;
  7624. var sum = $scope.order.qty * $scope.order.price;
  7625. $scope.order.total = sum;
  7626. $scope.loading = false;
  7627. });
  7628. };
  7629. loadData();
  7630. // 获取回复记录
  7631. $scope.getReply = function(item) {
  7632. if(!item.replies) {
  7633. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  7634. item.replies = replies;
  7635. });
  7636. }
  7637. };
  7638. $scope.openDatePicker = function($event, item, openParam) {
  7639. $event.preventDefault();
  7640. $event.stopPropagation();
  7641. item[openParam] = !item[openParam];
  7642. };
  7643. // 点击回复
  7644. $scope.onReplyClick = function(order, inverse) {
  7645. if(order.reply) {
  7646. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7647. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7648. return;
  7649. }
  7650. var reply = angular.copy(order.reply);
  7651. if(reply.delivery) {
  7652. if(typeof reply.delivery == 'object')
  7653. reply.delivery = reply.delivery.getTime();
  7654. } else {
  7655. reply.delivery = order.delivery;
  7656. }
  7657. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7658. $scope.loading = true;
  7659. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  7660. $scope.loading = false;
  7661. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7662. loadData();
  7663. }, function(response){
  7664. $scope.loading = false;
  7665. toaster.pop('error', '回复失败', response.data);
  7666. });
  7667. }
  7668. };
  7669. // 打开回复
  7670. $scope.openReply = function(order) {
  7671. if(!order.reply) {
  7672. order.reply = {
  7673. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7674. delivery: order.delivery
  7675. }
  7676. }
  7677. order.$editing = true;
  7678. };
  7679. // 关闭回复
  7680. $scope.closeReply = function(order) {
  7681. order.$editing = false;
  7682. }
  7683. // 自己委外加工订单
  7684. $scope.print = function(order) {
  7685. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  7686. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  7687. };
  7688. }]);
  7689. /**
  7690. * 计算时间差
  7691. */
  7692. app.filter('timespan', function(){
  7693. return function(time) {
  7694. if(time == null)
  7695. return '9999年';
  7696. var now = new Date().getTime(), span = time - now,
  7697. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  7698. m = Math.ceil(span/60000);
  7699. if(span < 0)
  7700. return '0天';
  7701. if(d > 0)
  7702. return d + '天';
  7703. if(h > 0)
  7704. return h + '小时';
  7705. if(m > 0)
  7706. return m + '分钟';
  7707. return '0天';
  7708. };
  7709. });
  7710. app.filter('firstchar', function(){
  7711. return function(str) {
  7712. if(str == null)
  7713. return null;
  7714. return str.substring(0, 1);
  7715. };
  7716. });
  7717. app.filter('summary', function(){
  7718. return function(data, field) {
  7719. var sum = 0;
  7720. if (data) {
  7721. angular.forEach(data, function(d){
  7722. sum += d[field];
  7723. });
  7724. }
  7725. return sum;
  7726. };
  7727. });
  7728. /**
  7729. * 搜索框,回车触发
  7730. */
  7731. app.directive('ngSearch', ['$parse', function($parse) {
  7732. return {
  7733. require : '?ngModel',
  7734. restrict : 'A',
  7735. link : function(scope, element, attrs, ngModel) {
  7736. var searchFn = $parse(attrs.ngSearch);
  7737. element.bind('keypress', function(event) {
  7738. if (event.keyCode == '13') {
  7739. event.preventDefault();
  7740. event.stopPropagation();
  7741. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  7742. }
  7743. });
  7744. }
  7745. };
  7746. }]);
  7747. /**
  7748. * 状态码 -> 描述
  7749. */
  7750. app.filter('status', function(){
  7751. return function(data) {
  7752. var statusConfig = {
  7753. '101': '已提交',
  7754. '102': '已审核',
  7755. '103': '未通过',
  7756. '200': '未回复',
  7757. '201': '已回复',
  7758. '313': '已激活',
  7759. '316': '已过账',
  7760. '311': '申请中',
  7761. '312': '未激活'
  7762. };
  7763. return statusConfig[data];
  7764. }
  7765. });
  7766. //弹出问题反馈模态框
  7767. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  7768. //获取当前用户
  7769. AuthenticationService.getAuthentication().success(function(data) {
  7770. $scope.user = data;
  7771. });
  7772. $scope.showModal = function(){
  7773. var modalInstance = $modal.open({
  7774. animation: true,
  7775. templateUrl: 'static/tpl/serve/feedback.html',
  7776. controller: 'FeedbackCtrl',
  7777. resolve: {
  7778. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  7779. }
  7780. });
  7781. modalInstance.result.then(function(){
  7782. }, function(){
  7783. })
  7784. }
  7785. }]);
  7786. /*
  7787. * 提交我的反馈
  7788. */
  7789. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  7790. $scope.isPublic = 1; //默认公开
  7791. $scope.classId = 1; //默认类别
  7792. $scope.user = user;
  7793. $scope.ok = function(){
  7794. if(!$scope.user){ //用户未登录
  7795. $scope.uu = null;
  7796. }else{ //用户已登录
  7797. $scope.uu = $scope.user.userUU;
  7798. }
  7799. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  7800. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  7801. function(data){
  7802. toaster.pop('success', '成功', '您的问题反馈成功!');
  7803. $scope.cancel();
  7804. }, function(response){
  7805. toaster.pop('error', '错误', response.data);
  7806. });
  7807. }
  7808. $scope.cancel = function () {
  7809. $modalInstance.dismiss();
  7810. };
  7811. }]);
  7812. //“我的问题反馈”跳转控制
  7813. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  7814. $scope.myFeedback = function(){
  7815. AuthenticationService.getAuthentication().success(function(data){
  7816. $scope.user = data;
  7817. if(!$scope.user){
  7818. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  7819. return false;
  7820. }else{
  7821. window.location.href = "./serve#/question/myFeedback";
  7822. }
  7823. });
  7824. }
  7825. }]);
  7826. //客户服务
  7827. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  7828. Vendor.getServe(function(datas){
  7829. $scope.vendors = datas;
  7830. console.log($scope.Vender);
  7831. // 自动跳转
  7832. if(datas && datas.length == 1)
  7833. $scope.redirect(datas[0]);
  7834. });
  7835. $scope.redirect = function(vendor) {
  7836. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  7837. };
  7838. }]);
  7839. /**
  7840. * 物料资料
  7841. */
  7842. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  7843. BaseService.scrollBackToTop();
  7844. $scope.active = 'all';
  7845. $scope.agreedText = '全部';
  7846. $scope.dateZoneText = '一个月内';
  7847. $scope.condition = {dateZone: 1};
  7848. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7849. $scope.changeAgreed = function(agreed) {
  7850. $scope.condition.agreed = agreed;
  7851. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7852. $scope.condition.$agreedOpen = false;
  7853. };
  7854. $scope.changeDateZone = function(zone) {
  7855. $scope.condition.dateZone = zone;
  7856. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7857. $scope.condition.$dateZoneOpen = false;
  7858. getDateCondition(zone, $scope.condition);
  7859. $scope.tableParams.reload();
  7860. };
  7861. $scope.setActive = function(state) {
  7862. if($scope.active != state) {
  7863. $scope.active = state;
  7864. if($scope.tableParams.page() == 1)
  7865. $scope.tableParams.reload();
  7866. else
  7867. $scope.tableParams.page(1);
  7868. }
  7869. };
  7870. var getService = function() {
  7871. return GetProductInfo;
  7872. };
  7873. $scope.tableParams = new ngTableParams({
  7874. page : 1,
  7875. count : 5,
  7876. sorting: {
  7877. }
  7878. }, {
  7879. total : 0,
  7880. counts: [5, 10, 25, 50],
  7881. getData : function($defer, params) {
  7882. $scope.loading = true;
  7883. var pageParams = params.url();
  7884. pageParams.keyword = $scope.keyword;
  7885. pageParams.searchFilter = $scope.searchFilter;
  7886. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7887. $scope.loading = false;
  7888. if(page) {
  7889. params.total(page.totalElement);
  7890. $defer.resolve(page.content);
  7891. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  7892. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  7893. }
  7894. }, function(response) {
  7895. $scope.loading = false;
  7896. toaster.pop('error', '数据加载失败', response.data);
  7897. });
  7898. }
  7899. });
  7900. // 搜索框回车
  7901. $scope.onSearch = function() {
  7902. $scope.tableParams.page(1);
  7903. $scope.tableParams.reload();
  7904. };
  7905. //删除
  7906. $scope.deleteById = function(id) {
  7907. GetProductInfo.deleteById({id: id}, function(data) {
  7908. if(data.error) {
  7909. toaster.pop("error", "提示", data.error);
  7910. } else {
  7911. toaster.pop("success", "提示", "删除成功");
  7912. $timeout(function() {
  7913. $scope.tableParams.reload();
  7914. }, 500);
  7915. }
  7916. }), function(response) {
  7917. toaster.pop("error", "删除失败", response.data);
  7918. };
  7919. }
  7920. }]);
  7921. /**
  7922. * 物料批量上传
  7923. */
  7924. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  7925. BaseService.scrollBackToTop();
  7926. // 通过excel批量上传物料
  7927. $scope.upload = function() {
  7928. var file = $scope.myFiles[0];
  7929. $upload.upload({
  7930. url: 'product/baseInfo/release/excel',
  7931. file: file,
  7932. method: 'POST'
  7933. }).success(function(data) {
  7934. $scope.result = data;
  7935. $scope.success = $scope.result.success;
  7936. $scope.total = $scope.result.total;
  7937. $scope.alters = $scope.result.alters;
  7938. $scope.infos = $scope.result.infos;
  7939. }).error(function(response) {
  7940. toaster.pop('error', response.data || response);
  7941. });
  7942. };
  7943. // 查看范例
  7944. $scope.showImg = function() {
  7945. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  7946. box.show();
  7947. box.find('img').attr('src', src);
  7948. box.find('a').click(function(){
  7949. box.hide();
  7950. });
  7951. box.dblclick(function(){
  7952. box.hide();
  7953. });
  7954. };
  7955. // 下载模板
  7956. $scope.download = function() {
  7957. window.location.href = 'product/baseInfo/upload/template';
  7958. };
  7959. }]);
  7960. /**
  7961. * 物料详情
  7962. */
  7963. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService) {
  7964. BaseService.scrollBackToTop();
  7965. // 录入人
  7966. AuthenticationService.getAuthentication().success(function(data) {
  7967. $scope.loading = false;
  7968. $scope.user = data;
  7969. });
  7970. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  7971. var loadData = function() {
  7972. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  7973. if(data.attach) {
  7974. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  7975. // 查看范例
  7976. $scope.showImg = function() {
  7977. var src = data.url, box = $('#image-box');
  7978. box.show();
  7979. box.find('img').attr('src', src);
  7980. box.find('a').click(function(){
  7981. box.hide();
  7982. });
  7983. box.dblclick(function(){
  7984. box.hide();
  7985. });
  7986. };
  7987. })
  7988. }
  7989. $scope.prodInfo = data;
  7990. $scope.prodInfo.$editing = false;
  7991. $scope.loading = false;
  7992. });
  7993. };
  7994. loadData();
  7995. // 更新
  7996. $scope.update = function() {
  7997. $scope.prodInfo.$editing = true;
  7998. };
  7999. // 取消
  8000. $scope.cancel = function() {
  8001. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  8002. $scope.prodInfo = data;
  8003. $scope.prodInfo.$editing = false;
  8004. $scope.loading = false;
  8005. });
  8006. };
  8007. $scope.submit = function(prodInfo) {
  8008. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  8009. $upload.upload({
  8010. url: 'product/baseInfo/updateProdInfo',
  8011. file: file,
  8012. method: 'POST',
  8013. data: {
  8014. prodInfo: $scope.prodInfo
  8015. },
  8016. }).success(function(data) {
  8017. if(data.success) {
  8018. toaster.pop('success', '提示', data.success);
  8019. window.location.reload();
  8020. }
  8021. if(data.error) {
  8022. toaster.pop('error', '提示', data.error);
  8023. }
  8024. }).error(function(data) {
  8025. $scope.loadingShow = false;
  8026. toaster.pop('error', '操作失败', data.error);
  8027. });
  8028. }
  8029. $scope.previewShow = false;
  8030. $scope.pdfShow = false;
  8031. $scope.noneFileShow = true;
  8032. $scope.$watch('myFiles', function(){
  8033. if($scope.myFiles) {
  8034. $scope.noneFileShow = false;
  8035. var file = $scope.myFiles[0];
  8036. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  8037. $scope.pdfShow = true;
  8038. $scope.previewShow = false;
  8039. $scope.imgPreviewName = file.name;
  8040. } else{
  8041. if (typeof(Worker) !== "undefined") {//支持HTML5
  8042. $scope.imgPreview = getObjectURL(file);
  8043. $scope.imgPreviewName = file.name;
  8044. } else{//不支持HTML5
  8045. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  8046. $scope.imgPreviewName = file.name;
  8047. }
  8048. $scope.previewShow = true;
  8049. $scope.pdfShow = false;
  8050. }
  8051. } else {
  8052. $scope.noneFileShow = true;
  8053. $scope.previewShow = false;
  8054. $scope.pdfShow = false;
  8055. }
  8056. });
  8057. //建立一个可存取到该file的url
  8058. var getObjectURL = function(file) {
  8059. var url = null ;
  8060. if (window.createObjectURL!=undefined) { // basic
  8061. url = window.createObjectURL(file) ;
  8062. } else if (window.URL!=undefined) { // mozilla(firefox)
  8063. url = window.URL.createObjectURL(file) ;
  8064. } else if (window.webkitURL!=undefined) { // webkit or chrome
  8065. url = window.webkitURL.createObjectURL(file) ;
  8066. }
  8067. return url ;
  8068. };
  8069. }]);
  8070. /**
  8071. * 新增物料
  8072. */
  8073. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService) {
  8074. BaseService.scrollBackToTop();
  8075. // 录入人
  8076. AuthenticationService.getAuthentication().success(function(data) {
  8077. $scope.loading = false;
  8078. $scope.user = data;
  8079. });
  8080. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  8081. $scope.prodInfo = {};
  8082. // 选择类目
  8083. $scope.selectKind = function(uuids) {
  8084. $modal.open({
  8085. animation: true,
  8086. size: 'lg',
  8087. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  8088. controller: 'KindChooseCtrl',
  8089. }).result.then(function(data){
  8090. $scope.kindId = data;
  8091. var modalInstance = $modal.open({
  8092. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  8093. controller: 'FindComponentCtrl',
  8094. size: 'lg',
  8095. resolve: {
  8096. KindId: function() {
  8097. return $scope.kindId;
  8098. }
  8099. }
  8100. });
  8101. modalInstance.result.then(function(data) {
  8102. $scope.prodInfo.cmpUuId = data.uuid;
  8103. $scope.prodInfo.cmpCode = data.code;
  8104. $scope.prodInfo.brand = data.brand.nameEn;
  8105. console.log($scope.prodInfo.brand);
  8106. }, function(){
  8107. });
  8108. }, function(){
  8109. });
  8110. };
  8111. //提交
  8112. $scope.submit = function(prodInfo){
  8113. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  8114. $upload.upload({
  8115. url: 'product/baseInfo/addNewProduct',
  8116. file: file,
  8117. method: 'POST',
  8118. data: {
  8119. prodInfo: $scope.prodInfo
  8120. },
  8121. }).success(function(data) {
  8122. if(data.success) {
  8123. toaster.pop('success', '提示', data.success);
  8124. $timeout(function() {
  8125. //提交后跳转到详情页面,防止重复提交
  8126. window.location.href="#/sale/prodList/"+data.id;
  8127. }, 500);
  8128. }
  8129. if(data.error) {
  8130. toaster.pop('error', '提示', data.error);
  8131. $timeout(function() {
  8132. //提交后跳转到详情页面,防止重复提交
  8133. window.location.href="#/sale/prodList/"+data.id;
  8134. }, 500);
  8135. }
  8136. }).error(function(data) {
  8137. $scope.loadingShow = false;
  8138. toaster.pop('error', '操作失败', data.error);
  8139. });
  8140. // GetProductInfo.addNewProd({}, prodInfo, function(data) {
  8141. // toaster.pop("success", "提示", "提交成功");
  8142. //
  8143. //
  8144. // }, function(res) {
  8145. // toaster.pop("error", "提示" + res);
  8146. // });
  8147. };
  8148. $scope.previewShow = false;
  8149. $scope.pdfShow = false;
  8150. $scope.noneFileShow = true;
  8151. $scope.$watch('myFiles', function(){
  8152. if($scope.myFiles) {
  8153. $scope.noneFileShow = false;
  8154. var file = $scope.myFiles[0];
  8155. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  8156. $scope.pdfShow = true;
  8157. $scope.previewShow = false;
  8158. $scope.imgPreviewName = file.name;
  8159. } else{
  8160. if (typeof(Worker) !== "undefined") {//支持HTML5
  8161. $scope.imgPreview = getObjectURL(file);
  8162. $scope.imgPreviewName = file.name;
  8163. } else{//不支持HTML5
  8164. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  8165. $scope.imgPreviewName = file.name;
  8166. }
  8167. $scope.previewShow = true;
  8168. $scope.pdfShow = false;
  8169. }
  8170. } else {
  8171. $scope.noneFileShow = true;
  8172. $scope.previewShow = false;
  8173. $scope.pdfShow = false;
  8174. }
  8175. });
  8176. //建立一个可存取到该file的url
  8177. var getObjectURL = function(file) {
  8178. var url = null ;
  8179. if (window.createObjectURL!=undefined) { // basic
  8180. url = window.createObjectURL(file) ;
  8181. } else if (window.URL!=undefined) { // mozilla(firefox)
  8182. url = window.URL.createObjectURL(file) ;
  8183. } else if (window.webkitURL!=undefined) { // webkit or chrome
  8184. url = window.webkitURL.createObjectURL(file) ;
  8185. }
  8186. return url ;
  8187. };
  8188. // 取消
  8189. $scope.cancel = function(){
  8190. $scope.prodInfo = angular.copy($scope.prodInfo);
  8191. };
  8192. }]);
  8193. /**
  8194. * 类目选择模态框
  8195. */
  8196. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  8197. $scope.kindId = null;
  8198. $scope.kinds = [[], [], [], []];
  8199. // 获取子类目
  8200. var getChildren = function(pid, deep) {
  8201. KindAPI.getChildren({parentId: pid}, function(data) {
  8202. $scope.kinds[deep] = data;
  8203. }, function(response) {
  8204. toaster.pop('error', '获取子类目失败', response.data);
  8205. });
  8206. };
  8207. // 改变节点选中状态
  8208. var changeStatus = function(item, deep) {
  8209. var kindId = null, level = 0;
  8210. angular.forEach($scope.kinds, function(ks, i) {
  8211. if(i > deep) {
  8212. $scope.kinds[i] = [];
  8213. } else {
  8214. angular.forEach(ks, function(k, j) {
  8215. if(i == deep) {
  8216. if(k.id == item.id) {
  8217. $scope.kinds[i][j].$active = true;
  8218. kindId = k.id;
  8219. } else {
  8220. k.$active = null;
  8221. }
  8222. }
  8223. });
  8224. }
  8225. });
  8226. // 选择的节点
  8227. $scope.kindId = kindId;
  8228. $scope.active = item;
  8229. // 当前可操作的层级
  8230. if(deep < 3) {
  8231. $scope.activeDeep = deep + 1;
  8232. }
  8233. };
  8234. // 节点点击后获取子类目,节点被选中
  8235. $scope.onItemClick = function(item, deep) {
  8236. changeStatus(item, deep);
  8237. if (!item.isLeaf) {
  8238. getChildren(item.id, deep + 1);
  8239. }
  8240. };
  8241. // 重新加载数据
  8242. function reload(deep) {
  8243. var pid;
  8244. if(deep) {
  8245. pid = $scope.actives[deep - 1].id;
  8246. } else {
  8247. pid = 0;
  8248. deep = 0;
  8249. }
  8250. getChildren(pid, deep);
  8251. }
  8252. // 初始加载数据,获取第一层的类目
  8253. if($scope.actives) {
  8254. angular.forEach($scope.actives, function(v, k) {
  8255. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  8256. $scope.kinds[k] = data;
  8257. angular.forEach($scope.kinds[k], function(kind, i){
  8258. if(kind.id == v.id) {
  8259. $scope.kinds[k][i].$active = true;
  8260. $scope.actives[k] = $scope.kinds[k][i];
  8261. }
  8262. })
  8263. }, function(response) {
  8264. toaster.pop('error', '获取子类目失败', response.data);
  8265. });
  8266. });
  8267. } else {
  8268. reload();
  8269. }
  8270. // 取消
  8271. $scope.cancel = function() {
  8272. $modalInstance.dismiss();
  8273. };
  8274. // 确认选择
  8275. $scope.check = function() {
  8276. $modalInstance.close($scope.kindId);
  8277. };
  8278. }]);
  8279. /**
  8280. * 器件筛选
  8281. */
  8282. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  8283. //状态
  8284. $scope.setActive = function (state){
  8285. if($scope.active != state) {
  8286. $scope.active = state;
  8287. if($scope.tableParams.page() == 1)
  8288. $scope.tableParams.reload();
  8289. else
  8290. $scope.tableParams.page(1);
  8291. }
  8292. };
  8293. $scope.tableParams = new ngTableParams({
  8294. page : 1,
  8295. count : 10
  8296. }, {
  8297. total : 0,
  8298. counts: [5, 10, 25, 50],
  8299. getData : function($defer, params) {
  8300. $scope.loading = true;
  8301. var pageParams = params.url();
  8302. pageParams.keyword = $scope.keyword;
  8303. pageParams.kindId = KindId;
  8304. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  8305. console.log(page);
  8306. $scope.loading = false;
  8307. if(page) {
  8308. params.total(page.totalElement);
  8309. $defer.resolve(page.content);
  8310. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8311. }
  8312. }, function(response){
  8313. $scope.loading = false;
  8314. toaster.pop('error', '数据加载失败', response.data);
  8315. });
  8316. }
  8317. });
  8318. // 取消
  8319. $scope.cancel = function() {
  8320. $modalInstance.dismiss();
  8321. };
  8322. // 选择
  8323. $scope.check = function(data){
  8324. $modalInstance.close(data);
  8325. };
  8326. // 搜索框回车
  8327. $scope.onSearch = function() {
  8328. $scope.tableParams.page(1);
  8329. $scope.tableParams.reload();
  8330. };
  8331. }]);
  8332. /**
  8333. * 企业列表
  8334. */
  8335. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  8336. BaseService.scrollBackToTop();
  8337. $scope.active = 'all';
  8338. $scope.agreedText = '全部';
  8339. $scope.dateZoneText = '一个月内';
  8340. $scope.condition = {dateZone: 1};
  8341. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8342. $scope.changeAgreed = function(agreed) {
  8343. $scope.condition.agreed = agreed;
  8344. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8345. $scope.condition.$agreedOpen = false;
  8346. };
  8347. $scope.changeDateZone = function(zone) {
  8348. $scope.condition.dateZone = zone;
  8349. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8350. $scope.condition.$dateZoneOpen = false;
  8351. getDateCondition(zone, $scope.condition);
  8352. $scope.tableParams.reload();
  8353. };
  8354. $scope.setActive = function(state) {
  8355. if($scope.active != state) {
  8356. $scope.active = state;
  8357. if($scope.tableParams.page() == 1)
  8358. $scope.tableParams.reload();
  8359. else
  8360. $scope.tableParams.page(1);
  8361. }
  8362. };
  8363. var getService = function() {
  8364. return getAccountUserSpace;
  8365. };
  8366. $scope.tableParams = new ngTableParams({
  8367. page : 1,
  8368. count : 5,
  8369. sorting: {
  8370. }
  8371. }, {
  8372. total : 0,
  8373. counts: [5, 10, 25, 50],
  8374. getData : function($defer, params) {
  8375. $scope.loading = true;
  8376. var pageParams = params.url();
  8377. pageParams.keyword = $scope.keyword;
  8378. $scope.tip = $scope.keyword;
  8379. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8380. $scope.loading = false;
  8381. if(page) {
  8382. params.total(page.totalElement);
  8383. $defer.resolve(page.content);
  8384. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8385. }
  8386. }, function(response) {
  8387. $scope.loading = false;
  8388. toaster.pop('error', '数据加载失败', response.data);
  8389. });
  8390. }
  8391. });
  8392. // 搜索框回车
  8393. $scope.onSearch = function() {
  8394. $scope.tableParams.page(1);
  8395. $scope.tableParams.reload();
  8396. };
  8397. // 添加合作关系
  8398. $scope.addPartner = function(name, businessCode) {
  8399. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  8400. if(data.success) {
  8401. toaster.pop("success", '添加成功', data.success);
  8402. }
  8403. if(data.error) {
  8404. toaster.pop("error", '添加失败', data.error);
  8405. }
  8406. }, function(response) {
  8407. toaster.pop('error','失败',response.data);
  8408. });
  8409. }
  8410. $scope.status = 'enList';
  8411. }]);
  8412. /**
  8413. * 新增采购单
  8414. */
  8415. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http) {
  8416. BaseService.scrollBackToTop();
  8417. // 每次进入时先清除掉rootScope下的venuu
  8418. $rootScope.venduu = null;
  8419. // 获取收货地址列表
  8420. ShipAddress.shipAddList({}, function(data) {
  8421. $scope.ships = data;
  8422. $scope.order.shipadd = $scope.ships[0];
  8423. });
  8424. // 获取地址信息
  8425. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  8426. }).then(function(response) {
  8427. $scope.provinces = response.data;
  8428. });
  8429. $scope.order = {
  8430. date : new Date(),
  8431. cust : {
  8432. uu : '',
  8433. },
  8434. custUser : {
  8435. },
  8436. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  8437. orderItems : {
  8438. product : {},
  8439. },
  8440. };
  8441. //商品信息
  8442. $scope.order.orderItems = [];
  8443. var item = {
  8444. code: null,
  8445. title: null,
  8446. spec: null,
  8447. unit: null,
  8448. qty: null,
  8449. price: null,
  8450. remark: null,
  8451. delivery: null,
  8452. id: null,
  8453. };
  8454. if($rootScope.businessCode) {
  8455. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  8456. $scope.id = data.id;
  8457. $scope.order.cust.enName = data.vendorEnterprise.enName;
  8458. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  8459. $scope.order.cust.uu = data.vendorEnterprise.uu;
  8460. $rootScope.venduu = data.vendorEnterprise.uu;
  8461. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8462. $scope.contacts = data;
  8463. $scope.order.vendor = $scope.contacts[0];
  8464. });
  8465. }, function(response) {
  8466. });
  8467. };
  8468. // 查找供应商
  8469. $scope.dbfindCust = function(){
  8470. var modalInstance = $modal.open({
  8471. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  8472. controller: 'DbfindVendorInfoCtrl',
  8473. size: 'lg',
  8474. resolve: {
  8475. orderItems: function() {
  8476. return $scope.order.orderItems;
  8477. }
  8478. }
  8479. });
  8480. modalInstance.result.then(function(data) {
  8481. $rootScope.venduu = data.vendorEnterprise.uu;
  8482. $scope.id = data.id;
  8483. $scope.order.cust = data.vendorEnterprise;
  8484. $scope.order.custUser = data.vendorUser;
  8485. $scope.order.orderItems = [];
  8486. var item = {
  8487. code: null,
  8488. title: null,
  8489. spec: null,
  8490. unit: null,
  8491. qty: null,
  8492. price: null,
  8493. remark: null,
  8494. delivery: null,
  8495. };
  8496. // $scope.order.orderItems.push(item);
  8497. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8498. $scope.contacts = data;
  8499. $scope.order.vendor = $scope.contacts[0];
  8500. });
  8501. }, function(){
  8502. });
  8503. };
  8504. // 联想词 start
  8505. // 获取供应商
  8506. $scope.getSimilarVendors = function(value) {
  8507. console.log(value);
  8508. if (value) {
  8509. return Vendor.getSimilarVendors({keyword : value}).$promise.then(function(data) {
  8510. return data.map(function(item) {
  8511. return item;
  8512. });
  8513. });
  8514. }
  8515. };
  8516. $scope.onAssociateCmpClick = function(vendor, order) {
  8517. $scope.order.cust.uu = vendor.venduu;
  8518. $rootScope.venduu = $scope.order.cust.uu;
  8519. }
  8520. // 联想词 end
  8521. // $scope.order.orderItems.push(item);
  8522. if($rootScope.prodId) {
  8523. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  8524. item.code = data.code;
  8525. item.title = data.title;
  8526. item.spec = data.spec;
  8527. item.unit = data.unit;
  8528. item.id = data.id;
  8529. $scope.order.orderItems.push(item);
  8530. }, function(response) {
  8531. });
  8532. }
  8533. //增加商品
  8534. $scope.addProduct = function(index) {
  8535. if($scope.order.orderItems[index].code == null) {
  8536. toaster.pop('info', '提示', '请先选择商品');
  8537. } else {
  8538. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null, $endDateOpen: false});
  8539. }
  8540. };
  8541. //删除商品
  8542. $scope.deleteProduct = function(index) {
  8543. $scope.order.orderItems.splice(index, 1);
  8544. };
  8545. // 搜索框回车
  8546. $scope.onSearch = function(keyword) {
  8547. $scope.keyword = keyword;
  8548. $scope.tableParams.page(1);
  8549. $scope.tableParams.reload();
  8550. };
  8551. $scope.tableParams = new ngTableParams({
  8552. page : 1,
  8553. count : 10
  8554. }, {
  8555. total : 0,
  8556. counts: [5, 10, 25, 50],
  8557. getData : function($defer, params) {
  8558. $scope.loading = true;
  8559. var pageParams = params.url();
  8560. pageParams.keyword = $scope.keyword;
  8561. $scope.tip = $scope.keyword;
  8562. pageParams.custUU = $scope.order.cust.uu;
  8563. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  8564. $scope.loading = false;
  8565. if(page) {
  8566. params.total(page.totalElement);
  8567. $scope.total = page.totalElement;
  8568. $defer.resolve(page.content);
  8569. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8570. }
  8571. }, function(response){
  8572. $scope.loading = false;
  8573. toaster.pop('error', '数据加载失败', response.data);
  8574. });
  8575. }
  8576. });
  8577. // 选择
  8578. $scope.check = function(data) {
  8579. $scope.order.orderItems.push({code: data.code, title: data.title, spec: data.spec, unit: data.unit, qty: null, price: null, remark: null, delivery: null, id: data.id});
  8580. };
  8581. // 监听custuu发生变化,重新加载物料信息
  8582. $scope.$watch('order.cust.uu', function(n, o) {
  8583. if(n==o) {
  8584. return;
  8585. } else {
  8586. $scope.tableParams.page(1);
  8587. $scope.tableParams.reload();
  8588. }
  8589. }, true);
  8590. // 查找客户物料
  8591. $scope.dbfindCustProd = function(index){
  8592. if($scope.order.cust.uu) {
  8593. var modalInstance = $modal.open({
  8594. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  8595. controller: 'DbfindCustProdCtrl',
  8596. size: 'lg',
  8597. resolve: {
  8598. custUU: function() {
  8599. return $scope.order.cust.uu
  8600. }
  8601. }
  8602. });
  8603. modalInstance.result.then(function(data) {
  8604. $scope.order.orderItems.push(data);
  8605. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8606. if($scope.order.orderItems[i].code == null || i == index) {
  8607. $scope.order.orderItems.splice(i, 1);
  8608. }
  8609. }
  8610. }, function() {
  8611. });
  8612. } else {
  8613. toaster.pop('info', '提示', '请先选择供应商');
  8614. }
  8615. };
  8616. $scope.getMinDate = function(item) {
  8617. return $filter('date')(new Date, 'yyyy-MM-dd');
  8618. };
  8619. $scope.openDatePicker = function($event, openParam, index) {
  8620. $event.preventDefault();
  8621. $event.stopPropagation();
  8622. $scope.order.orderItems[index].$endDateOpen = !openParam;
  8623. };
  8624. // 添加到购物车
  8625. $scope.addToCart = function(order) {
  8626. $scope.loading = true;
  8627. $scope.order.vendusertel = order.vendor.tel;
  8628. $scope.order.venduser = order.vendor.venduser;
  8629. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  8630. $scope.order.custUU = $scope.order.cust.uu;
  8631. $scope.order.custUserUU = $scope.order.custUser.userUU;
  8632. if($scope.order.date instanceof Date) {
  8633. $scope.order.date = $scope.order.date.getTime();
  8634. }
  8635. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8636. if($scope.order.orderItems[i].delivery instanceof Date) {
  8637. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  8638. }
  8639. if($scope.order.currency != 'RMB') {
  8640. $scope.order.orderItems[i].rate = 0;
  8641. }
  8642. }
  8643. addtoCart.save({}, $scope.order, function(data){
  8644. $scope.loading = false;
  8645. toaster.pop('success', '成功', '保存成功');
  8646. window.location.hash = '#/purc/cart/'+data.id;
  8647. }, function(response){
  8648. $scope.loading = false;
  8649. toaster.pop('error', '保存失败', response.data);
  8650. });
  8651. };
  8652. // 立即购买
  8653. $scope.addToOrder = function(order) {
  8654. $scope.loading = true;
  8655. $scope.order.vendusertel = order.vendor.tel;
  8656. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  8657. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  8658. $scope.order.custUU = $scope.order.cust.uu;
  8659. $scope.order.custUserUU = $scope.order.custUser.userUU;
  8660. if($scope.order.date instanceof Date) {
  8661. $scope.order.date = $scope.order.date.getTime();
  8662. }
  8663. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8664. if($scope.order.orderItems[i].delivery instanceof Date) {
  8665. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  8666. }
  8667. if($scope.order.currency != 'RMB') {
  8668. $scope.order.orderItems[i].rate = 0;
  8669. }
  8670. }
  8671. newPurcOrder.save({}, $scope.order, function(data){
  8672. $scope.loading = false;
  8673. toaster.pop('success', '成功', '保存成功');
  8674. window.location.hash = '#/purc/order/'+data.id;
  8675. }, function(response){
  8676. $scope.loading = false;
  8677. toaster.pop('error', '保存失败', response.data);
  8678. });
  8679. };
  8680. // 新增收货地址保存
  8681. $scope.saveShipAddress = function(ship) {
  8682. ship.address = ship.province + ship.city + ship.district;
  8683. ShipAddress.saveAddress( {}, ship, function(data) {
  8684. if(data.success) {
  8685. ShipAddress.shipAddList({}, function(data) {
  8686. $scope.ships = data;
  8687. $scope.order.shipadd = $scope.ships[0];
  8688. });
  8689. toaster.pop('success', '提示', data.success);
  8690. }
  8691. if(data.error) {
  8692. toaster.pop('error', '提示', data.error);
  8693. }
  8694. });
  8695. }
  8696. // 新增供应商联系人
  8697. $scope.addContact = function(uu) {
  8698. var modalInstance = $modal.open({
  8699. animation: true,
  8700. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  8701. controller: 'AddContacCtrl',
  8702. resolve: {
  8703. }
  8704. });
  8705. modalInstance.result.then(function(data) {
  8706. $scope.contact = data;
  8707. $scope.contact.venduu = uu;
  8708. Vendor.saveContact({}, $scope.contact, function(data) {
  8709. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8710. $scope.contacts = data;
  8711. $scope.order.vendor = $scope.contacts[0];
  8712. });
  8713. toaster.pop('success', '提示', '联系人保存成功');
  8714. }, function(response) {
  8715. toaster.pop('error', '失败', response.data);
  8716. });
  8717. });
  8718. }
  8719. }]);
  8720. // 查找供应商
  8721. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  8722. $scope.prod = false;
  8723. if(orderItems.length != 0) {
  8724. $scope.prod = true;
  8725. }
  8726. BaseService.scrollBackToTop();
  8727. if($rootScope.venduu != null) {
  8728. $scope.venduu = $rootScope.venduu;
  8729. }
  8730. // 搜索框回车
  8731. $scope.onSearch = function(keyword) {
  8732. $scope.keyword = keyword;
  8733. $scope.customerParams.page(1);
  8734. $scope.customerParams.reload();
  8735. };
  8736. $scope.customerParams = new ngTableParams({
  8737. page : 1,
  8738. count : 10
  8739. }, {
  8740. total : 0,
  8741. counts: [5, 10, 25, 50],
  8742. getData : function($defer, params) {
  8743. $scope.loading = true;
  8744. var pageParams = params.url();
  8745. pageParams.keyword = $scope.keyword;
  8746. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  8747. $scope.loading = false;
  8748. if(page) {
  8749. params.total(page.totalElements);
  8750. $defer.resolve(page.content);
  8751. }
  8752. $scope.totalCount = page.totalElements;
  8753. }, function(response){
  8754. $scope.loading = false;
  8755. toaster.pop('error', '数据加载失败', response.data);
  8756. });
  8757. }
  8758. });
  8759. $scope.cancel = function() {
  8760. $modalInstance.dismiss();
  8761. };
  8762. $scope.ensure = false;
  8763. $scope.check = function(vendor) { // 需要进行判断的选择
  8764. console.log(vendor);
  8765. $scope.vendorInfo = vendor;
  8766. $scope.ensure = true;
  8767. };
  8768. $scope.checkVendor = function(vendor) { // 直接选择
  8769. $modalInstance.close(vendor);
  8770. }
  8771. }]);
  8772. /**
  8773. * 我的客户
  8774. */
  8775. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  8776. $scope.userInfoResult = true;
  8777. AuthenticationService.getAuthentication().success(function(data) {
  8778. $scope.loading = false;
  8779. $scope.thisUser = data;
  8780. });
  8781. var getCustInfos = function(custuu) {
  8782. if(custuu) {
  8783. VendorService.userInfo.query({uu:custuu},null,function(data) {
  8784. $scope.custInfos = data;
  8785. var getPage = function(page, size){
  8786. if($scope.custInfos) {
  8787. var result = {};
  8788. result.totalCount = $scope.custInfos.length;
  8789. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  8790. if($scope.custInfos.length % size == 0) {
  8791. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  8792. }else {
  8793. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  8794. }
  8795. result.first = page == 1;
  8796. result.last = page == result.totalPage;
  8797. result.page = page;
  8798. result.next = page - 0 + 1;
  8799. result.pre = page - 1;
  8800. return result;
  8801. }
  8802. }
  8803. $scope.userdata = getPage(1,4);
  8804. $scope.first = function (){
  8805. $scope.userdata = getPage($scope.userdata.pre,4);
  8806. }
  8807. $scope.last = function (){
  8808. $scope.userdata = getPage($scope.userdata.next,4);
  8809. }
  8810. }, function(response){
  8811. $scope.loading = false;
  8812. toaster.pop('error', '数据加载失败', response.data);
  8813. });
  8814. }
  8815. }
  8816. $scope.addUserInfo = function(customer) {
  8817. //TODO
  8818. if ($scope.thisUser.sys) {
  8819. var modalInstance = $modal.open({
  8820. animation: true,
  8821. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  8822. controller: 'AddUserInfoCtrl',
  8823. resolve: {
  8824. customer: function() {
  8825. return customer;
  8826. }
  8827. }
  8828. });
  8829. modalInstance.result.then(function(changed, checked){
  8830. if(changed) {
  8831. if(checked)
  8832. $scope.newUser.roles = checked;
  8833. else
  8834. loadUsers();
  8835. }
  8836. });
  8837. } else {
  8838. toaster.pop('error', '您不是管理员,无权限分配用户!');
  8839. }
  8840. }
  8841. $scope.showUserInfo = function(customer,boo) {
  8842. $scope.custInfo = customer;
  8843. if(boo) {
  8844. getCustInfos(customer.myEnterprise.uu);
  8845. $scope.userInfoResult = true;
  8846. }
  8847. }
  8848. $scope.customerParams = new ngTableParams({
  8849. page : 1,
  8850. count : 10
  8851. }, {
  8852. total : 0,
  8853. counts: [5, 10, 25, 50],
  8854. getData : function($defer, params) {
  8855. $scope.loading = true;
  8856. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  8857. $scope.loading = false;
  8858. if(page) {
  8859. params.total(page.totalElements);
  8860. $defer.resolve(page.content);
  8861. }
  8862. $scope.totalCount = page.totalElements;
  8863. }, function(response){
  8864. $scope.loading = false;
  8865. toaster.pop('error', '数据加载失败', response.data);
  8866. });
  8867. }
  8868. });
  8869. }]);
  8870. /**
  8871. * 我的供应商
  8872. */
  8873. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope){
  8874. BaseService.scrollBackToTop();
  8875. // 搜索框回车
  8876. $scope.onSearch = function(keyword) {
  8877. $scope.keyword = keyword;
  8878. $scope.customerParams.page(1);
  8879. $scope.customerParams.reload();
  8880. };
  8881. $scope.customerParams = new ngTableParams({
  8882. page : 1,
  8883. count : 10
  8884. }, {
  8885. total : 0,
  8886. counts: [5, 10, 25, 50],
  8887. getData : function($defer, params) {
  8888. $scope.loading = true;
  8889. var pageParams = params.url();
  8890. pageParams.keyword = $scope.keyword;
  8891. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  8892. $scope.loading = false;
  8893. if(page) {
  8894. params.total(page.totalElements);
  8895. $scope.total = page.totalElement;
  8896. $defer.resolve(page.content);
  8897. }
  8898. $scope.totalCount = page.totalElements;
  8899. }, function(response){
  8900. $scope.loading = false;
  8901. toaster.pop('error', '数据加载失败', response.data);
  8902. });
  8903. }
  8904. });
  8905. // 查看供应商详情
  8906. $scope.VendorDetail = function(id, uu) {
  8907. $rootScope.vendorId = id;
  8908. $rootScope.vendoruu = uu;
  8909. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  8910. }
  8911. // 向企业购买
  8912. $scope.purcByEn = function(businessCode) {
  8913. $rootScope.businessCode = businessCode;
  8914. window.location.hash = "#/purc/addOrder";
  8915. }
  8916. }]);
  8917. /**
  8918. * 供应商详情
  8919. */
  8920. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  8921. BaseService.scrollBackToTop();
  8922. $scope.vendorContacts = [];
  8923. var loadData = function() {
  8924. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  8925. $scope.vendor = data.vendorEnterprise;
  8926. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  8927. $scope.vendorContacts = data;
  8928. });
  8929. });
  8930. };
  8931. loadData();
  8932. // 新增供应商联系人
  8933. $scope.addContact = function(uu) {
  8934. var modalInstance = $modal.open({
  8935. animation: true,
  8936. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  8937. controller: 'AddContacCtrl',
  8938. resolve: {
  8939. }
  8940. });
  8941. modalInstance.result.then(function(data) {
  8942. $scope.contact = data;
  8943. $scope.contact.venduu = uu;
  8944. Vendor.saveContact({}, $scope.contact, function(data) {
  8945. toaster.pop('success', '提示', '联系人保存成功');
  8946. $scope.vendorContacts.push(data);
  8947. }, function(response) {
  8948. toaster.pop('error', '失败', response.data);
  8949. });
  8950. });
  8951. }
  8952. // 编辑供应商联系人
  8953. $scope.edit = function(contact) {
  8954. var modalInstance = $modal.open({
  8955. animation: true,
  8956. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  8957. controller: 'EditContacCtrl',
  8958. resolve: {
  8959. contact: function() {
  8960. return contact;
  8961. }
  8962. }
  8963. });
  8964. modalInstance.result.then(function(data) {
  8965. $scope.contact = data;
  8966. Vendor.saveContact({}, $scope.contact, function(data) {
  8967. toaster.pop('success', '提示', '联系人修改成功');
  8968. }, function(response) {
  8969. toaster.pop('error', '失败', response.data);
  8970. });
  8971. });
  8972. }
  8973. // 删除供应商联系人
  8974. $scope.deleteById = function(id, index) {
  8975. $scope.vendorContacts.splice(index, 1);
  8976. Vendor.deleteContact({id: id}, {}, function(data) {
  8977. toaster.pop('success', '提示', '供应商联系人删除成功');
  8978. }, function(response) {
  8979. toaster.pop('error', '提示', response.data);
  8980. });
  8981. }
  8982. // 供应商物料信息
  8983. $scope.viewProdList = function(uu){
  8984. $scope.uu = uu;
  8985. $scope.tableParams.page(1);
  8986. $scope.tableParams.reload();
  8987. };
  8988. // 搜索框回车
  8989. $scope.onSearch = function(keyword) {
  8990. $scope.keyword = keyword;
  8991. $scope.tableParams.page(1);
  8992. $scope.tableParams.reload();
  8993. };
  8994. // 供应商物料信息
  8995. $scope.tableParams = new ngTableParams({
  8996. page : 1,
  8997. count : 10
  8998. }, {
  8999. total : 0,
  9000. counts: [5, 10, 25, 50],
  9001. getData : function($defer, params) {
  9002. $scope.loading = true;
  9003. var pageParams = params.url();
  9004. pageParams.custUU = $scope.uu;
  9005. pageParams.keyword = $scope.keyword;
  9006. $scope.tip = $scope.keyword;
  9007. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  9008. $scope.loading = false;
  9009. if(page) {
  9010. params.total(page.totalElement);
  9011. $scope.total = page.totalElement;
  9012. $defer.resolve(page.content);
  9013. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9014. }
  9015. }, function(response){
  9016. $scope.loading = false;
  9017. toaster.pop('error', '数据加载失败', response.data);
  9018. });
  9019. }
  9020. });
  9021. /**
  9022. * 选中单个物料购买
  9023. * @param businessCode
  9024. * @param id
  9025. */
  9026. $scope.PurcByEnAndProd = function(businessCode, id) {
  9027. $rootScope.businessCode = businessCode;
  9028. $rootScope.prodId = id;
  9029. window.location.hash = "#/purc/addOrder";
  9030. }
  9031. }]);
  9032. /**
  9033. * 编辑供应商联系人
  9034. */
  9035. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  9036. $scope.contact = contact;
  9037. $scope.save = function(contact) {
  9038. $modalInstance.close(contact);
  9039. }
  9040. $scope.cancel = function() {
  9041. $modalInstance.dismiss();
  9042. }
  9043. }]);
  9044. /**
  9045. * 新增供应商联系人
  9046. */
  9047. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  9048. $scope.save = function(contact) {
  9049. $modalInstance.close(contact);
  9050. }
  9051. $scope.cancel = function() {
  9052. $modalInstance.dismiss();
  9053. }
  9054. }]);
  9055. /**
  9056. * 建立合作关系申请
  9057. */
  9058. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout) {
  9059. BaseService.scrollBackToTop();
  9060. $scope.active = 'todo';
  9061. var getRequestStatus = function(active) {
  9062. var fn = 'getAllRequest';
  9063. switch(active) {
  9064. case 'done':
  9065. fn = 'getRequestDone';break;
  9066. case 'todo':
  9067. fn = 'getRequestTodo';break;
  9068. case 'end':
  9069. fn = 'getRequestEnd';break;
  9070. }
  9071. return fn;
  9072. }
  9073. // 切换单据类型
  9074. $scope.setActive = function(state) {
  9075. if($scope.active != state) {
  9076. $scope.active = state;
  9077. if($scope.tableParams.page() == 1)
  9078. $scope.tableParams.reload();
  9079. else
  9080. $scope.tableParams.page(1);
  9081. }
  9082. };
  9083. // 切换数据来源(正常数据 or 历史数据)
  9084. var getService = function() {
  9085. return AddPartnerMyRequest;
  9086. };
  9087. $scope.tableParams = new ngTableParams({ // ng-Table参数
  9088. page : 1,
  9089. count : 5,
  9090. sorting: {
  9091. }
  9092. }, {
  9093. total : 0,
  9094. counts: [5, 10, 15, 25, 50],
  9095. getData : function($defer, params) { // 获取数据的方法
  9096. $scope.loading = true;
  9097. var pageParams = params.url();
  9098. pageParams.keyword = $scope.keyword;
  9099. $scope.tip = $scope.keyword;
  9100. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9101. $scope.loading = false;
  9102. if(page) {
  9103. params.total(page.totalElement);
  9104. $defer.resolve(page.content);
  9105. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9106. }
  9107. }, function(response){
  9108. $scope.loading = false;
  9109. toaster.pop('error', '数据加载失败', response.data);
  9110. });
  9111. }
  9112. });
  9113. // 再次申请
  9114. $scope.reapply = function(id) {
  9115. AddPartner.reapply({id: id}, {}, function(data) {
  9116. toaster.pop('success', '提示', '操作成功');
  9117. }, function(response) {
  9118. toaster.pop('error','失败',response.data);
  9119. });
  9120. }
  9121. // 添加为供应商
  9122. $scope.addSupplier = function(vendUID) {
  9123. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  9124. if(data.success) {
  9125. toaster.pop('success', '提示', data.success);
  9126. }
  9127. if(data.error) {
  9128. toaster.pop('error','提示', data.error);
  9129. }
  9130. }, function(response) {
  9131. toaster.pop('error', '失败', response.data);
  9132. })
  9133. };
  9134. // 添加客户
  9135. $scope.addCust = function(vendUID) {
  9136. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  9137. if(data.success) {
  9138. toaster.pop('success', '提示', data.success);
  9139. }
  9140. if(data.error) {
  9141. toaster.pop('error','提示', data.error);
  9142. }
  9143. }, function(response) {
  9144. toaster.pop('error', '失败', response.data);
  9145. })
  9146. };
  9147. // 搜索框回车
  9148. $scope.onSearch = function() {
  9149. $scope.tableParams.page(1);
  9150. $scope.tableParams.reload();
  9151. };
  9152. // 同意申请
  9153. $scope.agree = function(id) {
  9154. AddPartner.agreeRequest({id: id}, {}, function(data) {
  9155. toaster.pop('success', '提示', '操作成功');
  9156. $timeout(function() {
  9157. window.location.reload();
  9158. }, 500);
  9159. }, function(response) {
  9160. toaster.pop('error', '提示', response.data);
  9161. });
  9162. }
  9163. // 拒绝申请
  9164. $scope.refuse = function(id, reason) {
  9165. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  9166. toaster.pop('success', '提示', '操作成功');
  9167. $timeout(function() {
  9168. window.location.reload();
  9169. }, 500);
  9170. }, function(response) {
  9171. toaster.pop('error', '提示', response.data);
  9172. });
  9173. }
  9174. $scope.status = 'send';
  9175. }]);
  9176. /**
  9177. * 建立合作关系处理申请
  9178. */
  9179. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  9180. BaseService.scrollBackToTop();
  9181. $scope.active = 'todo';
  9182. var getMessagetStatus = function(active) {
  9183. var fn = 'getAllMessage';
  9184. switch(active) {
  9185. case 'done':
  9186. fn = 'getMessageDone';break;
  9187. case 'todo':
  9188. fn = 'getMessageTodo';break;
  9189. case 'end':
  9190. fn = 'getMessageEnd';break;
  9191. }
  9192. return fn;
  9193. }
  9194. // 切换单据类型
  9195. $scope.setActive = function(state) {
  9196. if($scope.active != state) {
  9197. $scope.active = state;
  9198. if($scope.tableParams.page() == 1)
  9199. $scope.tableParams.reload();
  9200. else
  9201. $scope.tableParams.page(1);
  9202. }
  9203. };
  9204. var getService = function() {
  9205. return AddPartnerMyMessage;
  9206. };
  9207. $scope.tableParams = new ngTableParams({ // ng-Table参数
  9208. page : 1,
  9209. count : 5,
  9210. sorting: {
  9211. }
  9212. }, {
  9213. total : 0,
  9214. counts: [5, 10, 15, 25, 50],
  9215. getData : function($defer, params) { // 获取数据的方法
  9216. $scope.loading = true;
  9217. var pageParams = params.url();
  9218. pageParams.searchFilter = { // 筛选条件
  9219. keyword: $scope.keyword,
  9220. };
  9221. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9222. $scope.loading = false;
  9223. console.log(page);
  9224. if(page) {
  9225. params.total(page.totalElement);
  9226. $defer.resolve(page.content);
  9227. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9228. }
  9229. }, function(response){
  9230. $scope.loading = false;
  9231. toaster.pop('error', '数据加载失败', response.data);
  9232. });
  9233. }
  9234. });
  9235. // 同意申请
  9236. $scope.agree = function(id) {
  9237. AddPartner.agreeRequest({id: id}, {}, function(data) {
  9238. toaster.pop('success', '提示', '操作成功');
  9239. }, function(response) {
  9240. toaster.pop('error', '提示', response.data);
  9241. });
  9242. }
  9243. // 拒绝申请
  9244. $scope.refuse = function(id, reason) {
  9245. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  9246. toaster.pop('success', '提示', '操作成功');
  9247. }, function(response) {
  9248. toaster.pop('error', '提示', response.data);
  9249. });
  9250. }
  9251. $scope.status = 'get';
  9252. }]);
  9253. /**
  9254. * 我的合作伙伴
  9255. */
  9256. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  9257. BaseService.scrollBackToTop();
  9258. // 默认显示合作伙伴
  9259. $scope.status = 'news';
  9260. // 获取所有的合作伙伴
  9261. GetProductInfo.getAllPartners({}, function(data) {
  9262. console.log(data);
  9263. $scope.partners = data;
  9264. }, function(res) {
  9265. toaster.pop('error', '获取列表失败', res.data);
  9266. });
  9267. // 添加为客户
  9268. $scope.addCust = function(partner) {
  9269. GetProductInfo.addCust({}, partner, function(data) {
  9270. toaster.pop('success', '提示', '添加客户成功');
  9271. }, function(response) {
  9272. toaster.pop('error', '添加客户失败', response.data);
  9273. });
  9274. }
  9275. // 添加为供应商
  9276. $scope.addSupplier = function(partner) {
  9277. GetProductInfo.addSupplier({}, partner, function(data) {
  9278. toaster.pop('success', '提示', '添加供应商成功');
  9279. }, function(response) {
  9280. toaster.pop('error', '添加供应商失败', response.data);
  9281. });
  9282. }
  9283. }]);
  9284. /**
  9285. * 财务对账时,企业进行筛选操作
  9286. */
  9287. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  9288. var getData = function(){
  9289. $scope.loading = true;
  9290. FaApCheck.getAllCustomers(function(data) {
  9291. $scope.custs = data;
  9292. $scope.loading = false;
  9293. });
  9294. };
  9295. getData();
  9296. $scope.select = function(suuorname) {
  9297. $modalInstance.close(suuorname);
  9298. }
  9299. $scope.close = function() {
  9300. $modalInstance.close();
  9301. }
  9302. }]);
  9303. /**
  9304. * 跳转到企业圈
  9305. */
  9306. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  9307. GetProductInfo.businessGroups({}, function(data) {
  9308. window.open(data.url);
  9309. }, function(response) {
  9310. toaster.pop('error', '提示', response.data);
  9311. });
  9312. }]);
  9313. /**
  9314. * 购物车
  9315. */
  9316. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  9317. BaseService.scrollBackToTop();
  9318. $scope.active = 'all';
  9319. $scope.agreedText = '全部';
  9320. $scope.dateZoneText = '一个月内';
  9321. $scope.condition = {dateZone: 1};
  9322. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9323. $scope.changeAgreed = function(agreed) {
  9324. $scope.condition.agreed = agreed;
  9325. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9326. $scope.condition.$agreedOpen = false;
  9327. };
  9328. $scope.changeDateZone = function(zone) {
  9329. $scope.condition.dateZone = zone;
  9330. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9331. $scope.condition.$dateZoneOpen = false;
  9332. getDateCondition(zone, $scope.condition);
  9333. $scope.tableParams.reload();
  9334. };
  9335. $scope.setActive = function(state) {
  9336. if($scope.active != state) {
  9337. $scope.active = state;
  9338. if($scope.tableParams.page() == 1)
  9339. $scope.tableParams.reload();
  9340. else
  9341. $scope.tableParams.page(1);
  9342. }
  9343. };
  9344. var getService = function() {
  9345. return getCartList;
  9346. };
  9347. $scope.tableParams = new ngTableParams({
  9348. page : 1,
  9349. count : 5,
  9350. sorting: {
  9351. date: 'desc',
  9352. }
  9353. }, {
  9354. total : 0,
  9355. counts: [5, 10, 25, 50],
  9356. getData : function($defer, params) {
  9357. $scope.loading = true;
  9358. var pageParams = params.url();
  9359. pageParams.keyword = $scope.keyword;
  9360. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9361. $scope.loading = false;
  9362. if(page) {
  9363. params.total(page.totalElements);
  9364. $defer.resolve(page.content);
  9365. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9366. }
  9367. }, function(response) {
  9368. $scope.loading = false;
  9369. toaster.pop('error', '数据加载失败', response.data);
  9370. });
  9371. }
  9372. });
  9373. $scope.getCartTotal = function(items) {
  9374. var sum = 0;
  9375. angular.forEach(items, function(item){
  9376. sum += item.qty * item.price;
  9377. });
  9378. return sum;
  9379. };
  9380. // 搜索框回车
  9381. $scope.onSearch = function() {
  9382. $scope.tableParams.page(1);
  9383. $scope.tableParams.reload();
  9384. };
  9385. // 提交
  9386. $scope.addtoOrder = function(id) {
  9387. console.log(id);
  9388. cartOperation.addToOrder({id: id}, {}, function(data) {
  9389. if(data.success) {
  9390. toaster.pop('success', '提示', data.success);
  9391. $timeout(function() {
  9392. window.location.hash = '#/purc/order/'+data.id;
  9393. },500);
  9394. }
  9395. if(data.error) {
  9396. toaster.pop('error', '提示', data.error);
  9397. }
  9398. }, function(response) {
  9399. toaster.pop('erroer', '提示', response.data);
  9400. });
  9401. };
  9402. // 删除一条主记录
  9403. $scope.deleteCart = function(id) {
  9404. cartOperation.deleteCart({id: id}, {}, function(data) {
  9405. if(data.success) {
  9406. toaster.pop('success', '提示', data.success);
  9407. $timeout(function() {
  9408. window.location.reload();
  9409. },500);
  9410. }
  9411. if(data.error) {
  9412. toaster.pop('error', '提示', data.error);
  9413. }
  9414. }, function(response) {
  9415. toaster.pop('erroer', '提示', response.data);
  9416. });
  9417. };
  9418. // 删除一条明细
  9419. $scope.deleteDetail = function(id) {
  9420. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  9421. if(data.success) {
  9422. toaster.pop('success', '提示', data.success);
  9423. $timeout(function() {
  9424. window.location.reload();
  9425. },500);
  9426. }
  9427. if(data.error) {
  9428. toaster.pop('error', '提示', data.error);
  9429. }
  9430. }, function(response) {
  9431. toaster.pop('erroer', '提示', response.data);
  9432. });
  9433. };
  9434. // 清空购物车
  9435. $scope.clearCart = function() {
  9436. cartOperation.deleteCarts({}, function(data) {
  9437. if(data.success) {
  9438. toaster.pop('success', '提示', data.success);
  9439. $timeout(function() {
  9440. window.location.reload();
  9441. },500);
  9442. }
  9443. if(data.error) {
  9444. toaster.pop('error', '提示', data.error);
  9445. }
  9446. }, function(response) {
  9447. toaster.pop('erroer', '提示', response.data);
  9448. });
  9449. }
  9450. }]);
  9451. /**
  9452. * 购物车详情
  9453. */
  9454. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  9455. BaseService.scrollBackToTop();
  9456. var loadData = function() {
  9457. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  9458. if(data.code) {
  9459. $scope.cart = data;
  9460. var sum = 0;
  9461. angular.forEach($scope.cart.cartDetails, function(item) {
  9462. sum += item.qty * item.price;
  9463. });
  9464. $scope.cart.total = sum;
  9465. $scope.loading = false;
  9466. } else {
  9467. window.location.hash = '#/purc/cart';
  9468. }
  9469. });
  9470. };
  9471. loadData();
  9472. // 删除一条明细
  9473. $scope.deleteDetail = function(id) {
  9474. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  9475. if(data.success) {
  9476. toaster.pop('success', '提示', data.success);
  9477. $timeout(function() {
  9478. window.location.reload();
  9479. },500);
  9480. }
  9481. if(data.error) {
  9482. toaster.pop('error', '提示', data.error);
  9483. }
  9484. }, function(response) {
  9485. toaster.pop('erroer', '提示', response.data);
  9486. });
  9487. };
  9488. // 删除一条主记录
  9489. $scope.deleteCart = function(id) {
  9490. cartOperation.deleteCart({id: id}, {}, function(data) {
  9491. if(data.success) {
  9492. toaster.pop('success', '提示', data.success);
  9493. $timeout(function() {
  9494. window.location.reload();
  9495. },500);
  9496. }
  9497. if(data.error) {
  9498. toaster.pop('error', '提示', data.error);
  9499. }
  9500. }, function(response) {
  9501. toaster.pop('erroer', '提示', response.data);
  9502. });
  9503. };
  9504. // 提交
  9505. $scope.addtoOrder = function(id) {
  9506. console.log(id);
  9507. cartOperation.addToOrder({id: id}, {}, function(data) {
  9508. if(data.success) {
  9509. toaster.pop('success', '提示', data.success);
  9510. $timeout(function() {
  9511. window.location.hash = '#/purc/order/'+data.id;
  9512. },500);
  9513. }
  9514. if(data.error) {
  9515. toaster.pop('error', '提示', data.error);
  9516. }
  9517. }, function(response) {
  9518. toaster.pop('erroer', '提示', response.data);
  9519. });
  9520. };
  9521. }]);
  9522. /**
  9523. * 审批流
  9524. */
  9525. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  9526. BaseService.scrollBackToTop();
  9527. $scope.vacation = false;
  9528. $scope.workovertime = false;
  9529. $scope.workdaily = false;
  9530. $scope.feeplease = false;
  9531. $scope.signapp = false;
  9532. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  9533. $scope.nodes = data;
  9534. angular.forEach($scope.nodes, function(node) {
  9535. if(node.appname = '请假单') {
  9536. $scope.vacation = true;
  9537. }
  9538. if(node.appname = '加班单') {
  9539. $scope.workovertime = true;
  9540. }
  9541. if(node.appname = '工作日报') {
  9542. $scope.workdaily = true;
  9543. }
  9544. if(node.appname = '出差单') {
  9545. $scope.feeplease = true;
  9546. }
  9547. if(node.appname = '申诉单') {
  9548. $scope.signapp = true;
  9549. }
  9550. });
  9551. }, function(response) {
  9552. });
  9553. $scope.NoteSet = function() {
  9554. var modalInstance = $modal.open({
  9555. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9556. controller: 'NoteStep1Ctrl',
  9557. size: 'lg',
  9558. resolve: {
  9559. AppName: function() {
  9560. return '请假单';
  9561. }
  9562. }
  9563. });
  9564. modalInstance.result.then(function(data) {
  9565. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9566. if(data.error) {
  9567. toaster.pop('error', '提示', data.error);
  9568. }
  9569. if(data.success) {
  9570. toaster.pop('success', '提示', data.success);
  9571. }
  9572. }, function(response) {
  9573. });
  9574. }, function(){
  9575. });
  9576. }
  9577. $scope.overTimeSet = function() {
  9578. var modalInstance = $modal.open({
  9579. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9580. controller: 'NoteStep1Ctrl',
  9581. size: 'lg',
  9582. resolve: {
  9583. AppName: function() {
  9584. return '加班单';
  9585. }
  9586. }
  9587. });
  9588. modalInstance.result.then(function(data) {
  9589. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9590. if(data.error) {
  9591. toaster.pop('error', '提示', data.error);
  9592. }
  9593. if(data.success) {
  9594. toaster.pop('success', '提示', data.success);
  9595. }
  9596. }, function(response) {
  9597. });
  9598. }, function(){
  9599. });
  9600. }
  9601. $scope.feePleaseSet = function() {
  9602. var modalInstance = $modal.open({
  9603. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9604. controller: 'NoteStep1Ctrl',
  9605. size: 'lg',
  9606. resolve: {
  9607. AppName: function() {
  9608. return '出差单';
  9609. }
  9610. }
  9611. });
  9612. modalInstance.result.then(function(data) {
  9613. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9614. if(data.error) {
  9615. toaster.pop('error', '提示', data.error);
  9616. }
  9617. if(data.success) {
  9618. toaster.pop('success', '提示', data.success);
  9619. }
  9620. }, function(response) {
  9621. });
  9622. }, function(){
  9623. });
  9624. }
  9625. $scope.workDailySet = function() {
  9626. var modalInstance = $modal.open({
  9627. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9628. controller: 'NoteStep1Ctrl',
  9629. size: 'lg',
  9630. resolve: {
  9631. AppName: function() {
  9632. return '工作日报';
  9633. }
  9634. }
  9635. });
  9636. modalInstance.result.then(function(data) {
  9637. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9638. if(data.error) {
  9639. toaster.pop('error', '提示', data.error);
  9640. }
  9641. if(data.success) {
  9642. toaster.pop('success', '提示', data.success);
  9643. }
  9644. }, function(response) {
  9645. });
  9646. }, function(){
  9647. });
  9648. }
  9649. $scope.signAppSet = function() {
  9650. var modalInstance = $modal.open({
  9651. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9652. controller: 'NoteStep1Ctrl',
  9653. size: 'lg',
  9654. resolve: {
  9655. AppName: function() {
  9656. return '申诉单';
  9657. }
  9658. }
  9659. });
  9660. modalInstance.result.then(function(data) {
  9661. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9662. if(data.error) {
  9663. toaster.pop('error', '提示', data.error);
  9664. }
  9665. if(data.success) {
  9666. toaster.pop('success', '提示', data.success);
  9667. }
  9668. }, function(response) {
  9669. });
  9670. }, function(){
  9671. });
  9672. }
  9673. }]);
  9674. /**
  9675. * 审核条件设置
  9676. */
  9677. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  9678. $scope.appName = AppName;// 标题名称
  9679. $scope.AppFlow = {appName: $scope.appName,
  9680. appNodes:{}};
  9681. $scope.AppFlow.appNodes = [];
  9682. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  9683. if(data.appNodes.length != 0) {
  9684. $scope.node = data;
  9685. $scope.AppFlow = data;
  9686. }
  9687. }, function() {
  9688. });
  9689. $scope.copy = function() {//复制
  9690. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  9691. toaster.pop('info', '提示', '复制成功');
  9692. $modalInstance.dismiss();
  9693. }
  9694. $scope.paste = function() {
  9695. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  9696. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  9697. }
  9698. $scope.clear = function() {// 清空
  9699. $scope.AppFlow = {appName: $scope.appName,
  9700. appNodes:{}};
  9701. $scope.AppFlow.appNodes = [];
  9702. }
  9703. appFlow.getPositions({}, function(data) {// 获取人员信息
  9704. $scope.users = data;
  9705. }, function(response) {
  9706. });
  9707. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  9708. $scope.roles = data;
  9709. },function(response) {
  9710. });
  9711. $scope.SelectUser = function(data) { // 添加人员
  9712. var item = {
  9713. useruu: null,
  9714. username: null,
  9715. level: null
  9716. };
  9717. item.useruu = data.useruu;
  9718. item.username = data.username;
  9719. // if($scope.AppFlow.appNodes.length != 0){
  9720. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  9721. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  9722. // toaster.pop('info', '提示', '不能重复添加');
  9723. // } else {
  9724. // $scope.AppFlow.appNodes.push(item);
  9725. // }
  9726. // }
  9727. // } else {
  9728. $scope.AppFlow.appNodes.push(item);
  9729. // }
  9730. }
  9731. $scope.SelectRole = function(data) {// 添加职位
  9732. var item = {
  9733. position: null,
  9734. level: null
  9735. };
  9736. item.position = data;
  9737. $scope.AppFlow.appNodes.push(item);
  9738. }
  9739. $scope.deleteNode = function(index) {// 删除节点
  9740. $scope.AppFlow.appNodes.splice(index, 1);
  9741. };
  9742. $scope.saveNode = function() { // 保存
  9743. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  9744. $scope.AppFlow.appNodes[key].level = key;
  9745. });
  9746. if($scope.AppFlow.appNodes.length == 0) {
  9747. toaster.pop('info', '提示', '您还未设置审批人');
  9748. } else {
  9749. $modalInstance.close($scope.AppFlow);
  9750. };
  9751. };
  9752. $scope.cancel = function() {// 取消
  9753. $modalInstance.dismiss();
  9754. }
  9755. }]);
  9756. /***
  9757. * 代采定单
  9758. */
  9759. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  9760. BaseService.scrollBackToTop();
  9761. $scope.active = 'all';
  9762. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9763. $scope.total = null;
  9764. $scope.setActive = function(state) {
  9765. if($scope.active != state) {
  9766. $scope.active = state;
  9767. if($scope.tableParams.page() == 1)
  9768. $scope.tableParams.reload();
  9769. else
  9770. $scope.tableParams.page(1);
  9771. }
  9772. };
  9773. $scope.tableParams = new ngTableParams({
  9774. page : 1,
  9775. count : 5,
  9776. sorting: {
  9777. }
  9778. }, {
  9779. total : 0,
  9780. counts: [5, 10, 25, 50],
  9781. getData : function($defer, params) {
  9782. $scope.loading = true;
  9783. var pageParams = params.url();
  9784. pageParams.keyword = $scope.keyword;
  9785. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9786. $scope.loading = false;
  9787. if(page) {
  9788. params.total(page.totalElement);
  9789. $scope.total = page.totalElement;
  9790. $defer.resolve(page.content);
  9791. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9792. }
  9793. }, function(response) {
  9794. $scope.loading = false;
  9795. toaster.pop('error', '数据加载失败', response.data);
  9796. });
  9797. }
  9798. });
  9799. //打印
  9800. $scope.print = function(deputyOrder) {
  9801. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  9802. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  9803. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  9804. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  9805. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  9806. //TODO 目前只有信扬有代采业务,先写死之后再改
  9807. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  9808. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  9809. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  9810. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  9811. };
  9812. // 搜索框回车
  9813. $scope.onSearch = function() {
  9814. $scope.tableParams.page(1);
  9815. $scope.tableParams.reload();
  9816. };
  9817. }]);
  9818. /**
  9819. * 新增代采订单
  9820. */
  9821. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  9822. BaseService.scrollBackToTop();
  9823. $scope.deOrder = {
  9824. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  9825. entrydate: new Date(),
  9826. status: '在录入',
  9827. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  9828. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  9829. riskmethod: '甲方承担',
  9830. taxpaymentmethod: '甲方承担',
  9831. totalamount: 0,
  9832. totalpayament: 0,
  9833. orderamount: 0,
  9834. usdpayment: 0
  9835. };
  9836. // 费率
  9837. DeputyOrder.vendorRate({}, function(data) {
  9838. $scope.rate = data;
  9839. }, function(response){
  9840. });
  9841. $scope.deOrder.deputyOrderItems = [];
  9842. var item = {
  9843. prodname: null,
  9844. prodcode: null,
  9845. prodspec: null,
  9846. amount: null,
  9847. unitprice: null,
  9848. remark: null,
  9849. orderprice: null,
  9850. };
  9851. // 代采企业列表
  9852. DeputyOrder.deputyEnterprise({}, function(data) {
  9853. $scope.deputyEnterprises = data;
  9854. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  9855. });
  9856. $scope.deOrder.deputyOrderItems.push(item);
  9857. //增加商品
  9858. $scope.add = function(index) {
  9859. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  9860. toaster.pop('info', '提示', '请先填写商品信息');
  9861. }else {
  9862. $scope.deOrder.deputyOrderItems.push(
  9863. { prodname: null,
  9864. prodcode: null,
  9865. prodspec: null,
  9866. amount: null,
  9867. unitprice: null,
  9868. remark: null,
  9869. orderprice: null});
  9870. }
  9871. };
  9872. //删除商品
  9873. $scope.del = function(index) {
  9874. $scope.deOrder.deputyOrderItems.splice(index, 1);
  9875. };
  9876. $scope.uplodaByBatch = function() {
  9877. var modalInstance = $modal.open({
  9878. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  9879. controller: 'DeputyOrderUploadCtrl',
  9880. size: 'lg',
  9881. resolve: {
  9882. }
  9883. });
  9884. modalInstance.result.then(function(data) {
  9885. angular.forEach(data, function(data) {
  9886. $scope.deOrder.deputyOrderItems.push(data);
  9887. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  9888. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  9889. $scope.deOrder.deputyOrderItems.splice(i, 1);
  9890. }
  9891. }
  9892. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  9893. $scope.deOrder.totalamount += item.amount * item.unitprice;
  9894. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  9895. $scope.deOrder.orderamount += item.amount * item.purcprice;
  9896. });
  9897. })
  9898. }, function(){
  9899. });
  9900. }
  9901. // 查找供应商
  9902. $scope.dbfindVendor = function(deputyuu) {
  9903. var modalInstance = $modal.open({
  9904. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  9905. controller: 'DbfindDeputyVendorInfoCtrl',
  9906. size: 'lg',
  9907. resolve: {
  9908. deputyuu: function() {return deputyuu}
  9909. }
  9910. });
  9911. modalInstance.result.then(function(data) {
  9912. console.log(data);
  9913. $scope.deOrder.customer = data.vendorEnterprise.enName;
  9914. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  9915. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  9916. $scope.deOrder.usertel = data.vendorUser.userTel;
  9917. })
  9918. }
  9919. $scope.save = function() {
  9920. $scope.deOrder.entrystatus = '保存';
  9921. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  9922. $scope.deOrder.totalamount += item.amount * item.unitprice;
  9923. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  9924. });
  9925. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  9926. toaster.pop('info', '提示', '您还未填写任何商品信息');
  9927. } else {
  9928. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  9929. if(data.id) {
  9930. window.location.hash = "#/purc/deputy/"+data.id;
  9931. }
  9932. if(data.error) {
  9933. toaster.pop('error', '提示', '保存失败');
  9934. }
  9935. }, function(response) {
  9936. });
  9937. }
  9938. }
  9939. $scope.submit = function() {
  9940. $scope.deOrder.entrystatus = '已提交';
  9941. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  9942. $scope.deOrder.totalamount += item.amount * item.unitprice;
  9943. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  9944. });
  9945. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  9946. toaster.pop('info', '提示', '您还未填写任何商品信息');
  9947. } else {
  9948. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  9949. if(data.id) {
  9950. window.location.hash = "#/purc/deputy/"+data.id;
  9951. }
  9952. if(data.error) {
  9953. toaster.pop('error', '提示', '保存失败');
  9954. }
  9955. }, function(response) {
  9956. });
  9957. }
  9958. }
  9959. $scope.openDatePicker = function($event, deOrder, openParam) {
  9960. $event.preventDefault();
  9961. $event.stopPropagation();
  9962. deOrder[openParam] = !deOrder[openParam];
  9963. };
  9964. }]);
  9965. // 代采企业供应商
  9966. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  9967. $scope.prod = false;
  9968. BaseService.scrollBackToTop();
  9969. // 搜索框回车
  9970. $scope.onSearch = function(keyword) {
  9971. $scope.keyword = keyword;
  9972. $scope.customerParams.page(1);
  9973. $scope.customerParams.reload();
  9974. };
  9975. $scope.customerParams = new ngTableParams({
  9976. page : 1,
  9977. count : 10
  9978. }, {
  9979. total : 0,
  9980. counts: [5, 10, 25, 50],
  9981. getData : function($defer, params) {
  9982. $scope.loading = true;
  9983. var pageParams = params.url();
  9984. pageParams.keyword = $scope.keyword;
  9985. pageParams.enuu = deputyuu;
  9986. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function(page){
  9987. $scope.loading = false;
  9988. if(page) {
  9989. params.total(page.totalElements);
  9990. $defer.resolve(page.content);
  9991. }
  9992. $scope.totalCount = page.totalElements;
  9993. }, function(response){
  9994. $scope.loading = false;
  9995. toaster.pop('error', '数据加载失败', response.data);
  9996. });
  9997. }
  9998. });
  9999. $scope.cancel = function() {
  10000. $modalInstance.dismiss();
  10001. };
  10002. $scope.checkVendor = function(vendor) { // 直接选择
  10003. $modalInstance.close(vendor);
  10004. }
  10005. }]);
  10006. /**
  10007. * 代采订单批量导入
  10008. */
  10009. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  10010. // 通过excel批量上传物料
  10011. $scope.result = null;
  10012. $scope.upload = function() {
  10013. var file = $scope.myFiles[0];
  10014. $upload.upload({
  10015. url: 'deputyOrder/release/excel',
  10016. file: file,
  10017. method: 'POST'
  10018. }).success(function(data) {
  10019. $scope.result = data;
  10020. $scope.success = $scope.result.success;
  10021. $scope.total = $scope.result.total;
  10022. $scope.alters = $scope.result.alters;
  10023. }).error(function(response) {
  10024. toaster.pop('error', response.data || response);
  10025. });
  10026. };
  10027. // 查看范例
  10028. $scope.showImg = function() {
  10029. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  10030. box.show();
  10031. box.find('img').attr('src', src);
  10032. box.find('a').click(function(){
  10033. box.hide();
  10034. });
  10035. box.dblclick(function(){
  10036. box.hide();
  10037. });
  10038. };
  10039. // 下载模板
  10040. $scope.download = function() {
  10041. window.location.href = 'deputyOrder/upload/template';
  10042. };
  10043. $scope.enSure = function() {
  10044. $modalInstance.close($scope.result.items);
  10045. }
  10046. $scope.cancel = function() {
  10047. $modalInstance.dismiss();
  10048. }
  10049. }]);
  10050. /**
  10051. * 代采详情
  10052. */
  10053. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService) {
  10054. BaseService.scrollBackToTop();
  10055. var loadData = function() {
  10056. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  10057. $scope.deOrder = data;
  10058. $scope.deOrder.$editing = false;
  10059. });
  10060. };
  10061. loadData();
  10062. // 代采企业列表
  10063. DeputyOrder.deputyEnterprise({}, function(data) {
  10064. $scope.deputyEnterprises = data;
  10065. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  10066. });
  10067. var getService = function() {
  10068. return DeputyOrder.getProdList;
  10069. };
  10070. $scope.update = function() {
  10071. $scope.deOrder.$editing = true;
  10072. }
  10073. $scope.cancel = function() {
  10074. $scope.deOrder.$editing = false;
  10075. }
  10076. $scope.submit = function() {
  10077. $scope.deOrder.entrystatus = '已提交';
  10078. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  10079. if(data.id) {
  10080. window.location.hash = "#/purc/deputy/"+data.id;
  10081. }
  10082. if(data.error) {
  10083. toaster.pop('error', '提示', '保存失败');
  10084. }
  10085. }, function(response) {
  10086. });
  10087. }
  10088. $scope.openDatePicker = function($event, deOrder, openParam) {
  10089. $event.preventDefault();
  10090. $event.stopPropagation();
  10091. deOrder[openParam] = !deOrder[openParam];
  10092. };
  10093. }]);
  10094. /**
  10095. * 招标单
  10096. */
  10097. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  10098. BaseService.scrollBackToTop();
  10099. $scope.active = 'done';
  10100. if ($rootScope.tenderActive) {
  10101. $scope.active = $rootScope.tenderActive;
  10102. }
  10103. $scope.dateZoneText = '不限';
  10104. $scope.deliveryZoneText = '不限';
  10105. $scope.condition = {dateZone: -1, deliveryZone: -1};
  10106. $scope.changeDateZone = function(zone) {
  10107. $scope.condition.dateZone = zone;
  10108. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  10109. $scope.condition.$dateZoneOpen = false;
  10110. getDateCondition(zone, $scope.condition);
  10111. $scope.tableParams.reload();
  10112. };
  10113. $scope.changeDeliveryZone = function(zone) {
  10114. $scope.condition.deliveryZoneText = zone;
  10115. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  10116. $scope.condition.$delievryZoneOpen = false;
  10117. getDelveryCondition(zone, $scope.condition);
  10118. $scope.tableParams.reload();
  10119. };
  10120. $scope.setActive = function(state) {
  10121. if($scope.active != state) {
  10122. $scope.active = state;
  10123. if($scope.tableParams.page() == 1)
  10124. $scope.tableParams.reload();
  10125. else
  10126. $scope.tableParams.page(1);
  10127. }
  10128. };
  10129. var getTenderStatus = function(active) {
  10130. var fn = 'getMyAll';
  10131. switch(active) {
  10132. case 'done':
  10133. fn = 'getMyDone';break;
  10134. case 'todo':
  10135. fn = 'getMyTodo';break;
  10136. // case 'end':
  10137. // fn = 'getMyEnd';break;
  10138. case 'waiting':
  10139. fn = 'getMyWaiting';break;
  10140. }
  10141. return fn;
  10142. }
  10143. $scope.tableParams = new ngTableParams({
  10144. page : 1,
  10145. count : 5,
  10146. sorting: {
  10147. 'tender.endDate': 'desc',
  10148. 'tender.enterprise.enName': 'asc',
  10149. 'tender.code': 'asc'
  10150. }
  10151. }, {
  10152. total : 0,
  10153. counts: [5, 10, 25, 50],
  10154. getData : function($defer, params) {
  10155. $scope.loading = true;
  10156. var pageParams = params.url();
  10157. var realActive = {};
  10158. pageParams.searchFilter = { // 筛选条件
  10159. keyword: $scope.keyword,
  10160. fromDate: getDateTime($scope.condition.dateFrom),
  10161. endDate: getDateTime($scope.condition.dateTo)
  10162. };
  10163. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10164. $scope.loading = false;
  10165. if(page) {
  10166. params.total(page.totalElement);
  10167. $defer.resolve(page.content);
  10168. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  10169. }
  10170. }, function(response){
  10171. $scope.loading = false;
  10172. toaster.pop('error', '数据加载失败', response.data);
  10173. });
  10174. }
  10175. });
  10176. $scope.openDatePicker = function($event, item, openParam) {
  10177. $event.preventDefault();
  10178. $event.stopPropagation();
  10179. item[openParam] = !item[openParam];
  10180. };
  10181. $scope.parseDate = function(dateStr) {
  10182. if(dateStr)
  10183. return Date.parse(dateStr, 'yyyy-MM-dd');
  10184. return new Date();
  10185. };
  10186. // 选择查找日期
  10187. $scope.onDateCondition = function(){
  10188. $scope.tableParams.page(1);
  10189. $scope.tableParams.reload();
  10190. };
  10191. // 搜索框回车
  10192. $scope.onSearch = function() {
  10193. $scope.tableParams.page(1);
  10194. $scope.tableParams.reload();
  10195. };
  10196. }]);
  10197. /**
  10198. * 新增招标单
  10199. */
  10200. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'ShipAddress', '$http', 'AuthenticationService', 'KindAPI', 'BrandActiveAPI', 'Search', 'ComponentActiveAPI',function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, ShipAddress, $http, AuthenticationService, KindAPI, BrandActiveAPI, Search, ComponentActiveAPI) {
  10201. // 录入人
  10202. AuthenticationService.getAuthentication().success(function(data) {
  10203. $scope.user = data;
  10204. });
  10205. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  10206. $scope.loading = false;
  10207. // 获取收货地址列表
  10208. var loadShipAddress = function() {
  10209. ShipAddress.shipAddList({}, function(data) {
  10210. $scope.ships = data;
  10211. $scope.tender.shipadd = $scope.ships[0];
  10212. });
  10213. };
  10214. loadShipAddress();
  10215. // 获取地址信息
  10216. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  10217. }).then(function(response) {
  10218. $scope.provinces = response.data;
  10219. });
  10220. // 新增收货地址保存
  10221. $scope.saveShipAddress = function(ship) {
  10222. ship.address = ship.province + ship.city + ship.district;
  10223. ShipAddress.saveAddress( {}, ship, function(data) {
  10224. if(data.success) {
  10225. // 获取收货地址列表
  10226. loadShipAddress();
  10227. toaster.pop('success', '提示', data.success);
  10228. }
  10229. if(data.error) {
  10230. toaster.pop('error', '提示', data.error);
  10231. }
  10232. });
  10233. };
  10234. // 可选的证照要求
  10235. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  10236. // 处理证照要求
  10237. var parseCertificate = function(a) {
  10238. if (a) {
  10239. var arr = a.split(',');
  10240. angular.forEach(arr, function(app) {
  10241. var contained = false;
  10242. angular.forEach($scope.certificates, function($app) {
  10243. if($app.name == app) {
  10244. $app.checked = true;
  10245. contained = true;
  10246. }
  10247. });
  10248. if(!contained) {
  10249. $scope.certificates.push({name: app, checked: true});
  10250. }
  10251. });
  10252. }
  10253. };
  10254. // 联想词start
  10255. // 获取品牌联想词
  10256. $scope.getSimilarBrands = function(value) {
  10257. if (value) {
  10258. // 获取品牌联想词
  10259. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  10260. return data.map(function(item) {
  10261. return item;
  10262. });
  10263. });
  10264. }
  10265. };
  10266. // 获取产品型号联想词
  10267. $scope.getSimilarCodes = function(value) {
  10268. if (value) {
  10269. // 获取产品型号联想词
  10270. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  10271. return data.map(function (item) {
  10272. return item;
  10273. })
  10274. });
  10275. }
  10276. };
  10277. // // 获取产品类目联想词
  10278. // $scope.getSimilarKinds = function(value) {
  10279. // if (value) {
  10280. // // getSimilarLeafKinds 根据类目名获取末级联想词
  10281. // // 获取类目联想词
  10282. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  10283. // return data.map(function(item) {
  10284. // return item;
  10285. // })
  10286. // });
  10287. // }
  10288. // };
  10289. // // 点击联想词获取类目信息
  10290. // $scope.onAssociateKindClick = function(kind, submit) {
  10291. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  10292. // $scope.actives = data;
  10293. // console.log(data);
  10294. // var size = data.length;
  10295. // if (size > 0) {
  10296. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  10297. // submit.kiName = submit.gradeOneKiName;
  10298. // if (size > 1) {
  10299. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  10300. // submit.kiName = submit.gradeTwoKiName;
  10301. // if (kind.level < 3) {
  10302. // submit.gradeThreeKiName = null;
  10303. // } else if (size > 2) {
  10304. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  10305. // submit.kiName = submit.gradeThreeKiName;
  10306. // }
  10307. // }
  10308. // }
  10309. // console.log(submit);
  10310. // })
  10311. // };
  10312. // 选择类目
  10313. $scope.selectKind = function(prod) {
  10314. var submit = [];
  10315. $modal.open({
  10316. animation: true,
  10317. size: 'lg',
  10318. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  10319. controller: 'ProdKindChooseCtrl',
  10320. resolve: {
  10321. actives: function() {
  10322. return $scope.actives;
  10323. }
  10324. }
  10325. }).result.then(function(data){
  10326. $scope.actives = data.actives;
  10327. var size = data.actives.length;
  10328. submit.gradeOneKiName = '';
  10329. submit.gradeTwoKiName = '';
  10330. submit.gradeThreeKiName = '';
  10331. if (size > 0) {
  10332. submit.gradeOneKiName = $scope.actives[0].nameCn;
  10333. prod.prodTitle = submit.gradeOneKiName;
  10334. if (size > 1) {
  10335. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  10336. prod.prodTitle = submit.gradeTwoKiName;
  10337. if (size > 2) {
  10338. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  10339. prod.prodTitle = submit.gradeThreeKiName;
  10340. }
  10341. }
  10342. }
  10343. }, function(){
  10344. });
  10345. };
  10346. // // 验证分类信息
  10347. // $scope.checkKind = function() {
  10348. // setTimeout(function() {
  10349. // if($scope.activesString == null) {
  10350. // $scope.component.kindid = null;
  10351. // return;
  10352. // }
  10353. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  10354. // $scope.component.kind = kind;
  10355. // $scope.component.kindid = kind.id;
  10356. // $scope.activesString = $scope.component.kind.nameCn;
  10357. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  10358. // $scope.kindProperties = data;
  10359. // angular.forEach($scope.kindProperties, function(kp) {
  10360. // angular.forEach($scope.component.properties, function(pro) {
  10361. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  10362. // kp.value = pro.value;
  10363. // }
  10364. // });
  10365. // });
  10366. // }, function(response) {
  10367. // });
  10368. // }, function (response) {
  10369. // $scope.component.kindid = null;
  10370. // toaster.pop('error', response.data);
  10371. // });
  10372. // }, 500);
  10373. // };
  10374. // 点击联想词获取品牌信息
  10375. $scope.onAssociateBrandClick = function(brand, prod) {
  10376. // $scope.component.brand = brand;
  10377. // $scope.component.brandid = brand.id;
  10378. prod.brand = brand;
  10379. };
  10380. // 打开品牌选择的模态框
  10381. $scope.selectBrand = function(prod){ //打开模态
  10382. var modalInstance = $modal.open({
  10383. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  10384. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  10385. });
  10386. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  10387. });
  10388. modalInstance.result.then(function(brand){
  10389. console.log(brand);
  10390. prod.brand = brand.nameCn;
  10391. }, function(reason){
  10392. });
  10393. };
  10394. // // 验证品牌是否正确
  10395. // $scope.checkBrand = function () {
  10396. // setTimeout(function () {
  10397. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  10398. // // $scope.component.brand = brand;
  10399. // // $scope.component.brandid = brand.id;
  10400. // }, function (response) {
  10401. // // $scope.component.brandid = null;
  10402. // toaster.pop('error', response.data);
  10403. // })
  10404. // } , 500);
  10405. // };
  10406. // 点击联想词获取器件信息 带入产品分类和品牌
  10407. $scope.onAssociateCmpClick = function(cmp, prod) {
  10408. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  10409. $scope.component = data;
  10410. prod.prodCode = data.code;
  10411. prod.prodTitle = data.kind.nameCn;
  10412. prod.brand = data.brand.nameCn;
  10413. }, function(res) {
  10414. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  10415. })
  10416. };
  10417. //联想词end
  10418. $scope.condition = {dateZone: 1};
  10419. $scope.tenderProd = [];
  10420. var prod = {
  10421. prodTitle: null,
  10422. prodCode: null,
  10423. brand: null,
  10424. unit: 'PCS',
  10425. qty: null
  10426. // 供应商企业信息
  10427. // enterpriseBaseInfo: [{}]
  10428. };
  10429. $scope.tender = {
  10430. date: new Date(),
  10431. unit: 'PCS',
  10432. currency: 'RMB',
  10433. ifOpen: 0,
  10434. ifTax: 1,
  10435. invoiceType: 2,
  10436. tenderAttachs:[{}]
  10437. };
  10438. //
  10439. $scope.tenderProd.push(prod);
  10440. //增加商品
  10441. $scope.add = function(index) {
  10442. $scope.tenderProd.push({
  10443. prodTitle: null,
  10444. prodCode: null,
  10445. brand: null,
  10446. unit: 'PCS',
  10447. qty: null
  10448. // 供应商企业信息
  10449. // enterpriseBaseInfo: [{}]
  10450. });
  10451. };
  10452. //删除商品
  10453. $scope.del = function(index) {
  10454. $scope.tenderProd.splice(index, 1);
  10455. };
  10456. // 批量导入
  10457. $scope.uplodaByBatch = function() {
  10458. var modalInstance = $modal.open({
  10459. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  10460. controller: 'PurcTenderUploadCtrl',
  10461. size: 'lg',
  10462. resolve: {
  10463. }
  10464. });
  10465. modalInstance.result.then(function(data) {
  10466. // 获取上传的产品明细,前台展示
  10467. angular.forEach(data, function(data) {
  10468. $scope.tenderProd.push(data);
  10469. for(var i = 0; i < $scope.tenderProd.length; i++) {
  10470. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  10471. $scope.tenderProd.splice(i, 1);
  10472. console.log($scope.tenderProd);
  10473. }
  10474. }
  10475. });
  10476. }, function(){
  10477. });
  10478. };
  10479. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  10480. if( ! angular.isUndefined($stateParams.id)) {
  10481. $scope.loading = true;
  10482. PurcTender.getOne({id: $stateParams.id}, function(data){
  10483. data.$editing = false;
  10484. $scope.tender = data;
  10485. $scope.tenderProd = data.purchaseTenderProds;
  10486. parseCertificate($scope.tender.certificate);
  10487. $scope.firstProd = data.purchaseTenderProds[0];
  10488. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  10489. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  10490. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10491. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  10492. } else {
  10493. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  10494. }
  10495. });
  10496. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  10497. console.log($scope.tenderProd.enterpriseBaseInfo);
  10498. $scope.loading = false;
  10499. $scope.attaches = $scope.tender.tenderAttaches;
  10500. }, function(response){
  10501. $scope.loading = false;
  10502. toaster.pop('error', '数据加载失败', response.data);
  10503. });
  10504. }
  10505. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  10506. $rootScope.tenderVendor = [{}];
  10507. }
  10508. $scope.changeShipAddress = false;
  10509. $scope.changeAddress = function() {
  10510. if ($scope.changeShipAddress) {
  10511. $scope.changeShipAddress = false;
  10512. } else {
  10513. $scope.changeShipAddress = true;
  10514. }
  10515. };
  10516. // $scope.validateNumber = function (value) { // 采购数量 正整数
  10517. // var regex = /^\+?[1-9][0-9]*$/;
  10518. // if (!regex.test(value) || value === 0 || value === null) {
  10519. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  10520. // }
  10521. // };
  10522. // 查找供应商
  10523. $scope.dbfindVendor = function(){
  10524. var modalInstance = $modal.open({
  10525. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  10526. controller: 'DbfindVendorCtrl',
  10527. size: 'lg',
  10528. resolve: {
  10529. }
  10530. });
  10531. var ifPush = true;
  10532. modalInstance.result.then(function(data){
  10533. angular.forEach(data, function(vendor) {
  10534. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  10535. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10536. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  10537. } else {
  10538. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  10539. ifPush = true;
  10540. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  10541. ifPush = false;
  10542. break; // 判定到已存在供应商,就终止循环。
  10543. }
  10544. }
  10545. if (ifPush) {
  10546. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  10547. }
  10548. }
  10549. });
  10550. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  10551. }, function(){
  10552. });
  10553. };
  10554. // 删除一个供应商
  10555. $scope.removeVendor = function(index) {
  10556. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  10557. };
  10558. // 删除供应商时,后台删除投标单
  10559. $scope.removeSaleTender = function (id, vendUU) {
  10560. var hasSaved = false;
  10561. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  10562. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  10563. hasSaved = true;
  10564. }
  10565. });
  10566. if (hasSaved) {
  10567. PurcTender.removeSaleTender ({id : id, vendUU : vendUU}, {}, function(data) {
  10568. }, function(response) {
  10569. toaster.pop('error', '提示', response.data);
  10570. });
  10571. }
  10572. };
  10573. // 删除产品明细时,后台删除产品明细
  10574. $scope.deleteProd = function (tenderProd) {
  10575. if (tenderProd.id) {
  10576. PurcTender.deleteProd ({tenderProdId : tenderProd.id}, {}, function(data) {
  10577. }, function(response) {
  10578. toaster.pop('error', '提示', response.data);
  10579. });
  10580. }
  10581. };
  10582. // // 查找客户物料
  10583. // $scope.dbfindCustProd = function(){
  10584. // if($scope.item.$editing) {
  10585. // if($scope.item.quotation.cust.uu) {
  10586. // var modalInstance = $modal.open({
  10587. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  10588. // controller: 'DbfindCustProdCtrl',
  10589. // size: 'lg',
  10590. // resolve: {
  10591. // custUU: function(){return $scope.item.quotation.cust.uu}
  10592. // }
  10593. // });
  10594. //
  10595. // modalInstance.result.then(function(data){
  10596. // $scope.item.product = data;
  10597. // }, function(){
  10598. //
  10599. // });
  10600. // } else {
  10601. // toaster.pop('error', '错误', '请先选择客户');
  10602. // }
  10603. // }
  10604. // };
  10605. if (!$scope.attaches) {
  10606. $scope.attaches = []; // 存放上传了的附件
  10607. }
  10608. $scope.upload = function(myFile) { // 上传附件
  10609. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  10610. $upload.upload({
  10611. url: 'tender/addTenderAttach',
  10612. file: file,
  10613. method: 'POST'
  10614. // data: {
  10615. // tender: $scope.tender
  10616. // }
  10617. }).success(function (attach) {
  10618. $scope.attaches.push(attach);
  10619. });
  10620. };
  10621. $scope.removeAttach = function(id, index) {
  10622. $scope.attaches.splice(index, 1);
  10623. // PurcTender.removeAttach({attachId:id}, function() {
  10624. //
  10625. // });
  10626. };
  10627. var sleep = function (d){
  10628. for(var t = Date.now();Date.now() - t <= d;);
  10629. };
  10630. // 保存和发布招标单
  10631. $scope.save = function(isPublish){
  10632. if (!$scope.tender.ifOpen && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  10633. toaster.pop('info','提示','请先指定供应商');
  10634. } else {
  10635. $scope.loading = true;
  10636. // --组装证照要求
  10637. var myCertificate = [];
  10638. angular.forEach($scope.certificates, function(certificate) {
  10639. if (certificate.checked) {
  10640. myCertificate.push(certificate.name);
  10641. }
  10642. });
  10643. $scope.tender.certificate = myCertificate.join(',');
  10644. if(!$scope.tender.code) { //新增,设单号
  10645. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  10646. }
  10647. if($scope.tender.date instanceof Date) {
  10648. $scope.tender.date = $scope.tender.date.getTime();
  10649. }
  10650. if($scope.tender.endDate instanceof Date) {
  10651. $scope.tender.endDate = $scope.tender.endDate.getTime();
  10652. }
  10653. if($scope.tender.publishDate instanceof Date) {
  10654. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  10655. }
  10656. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  10657. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  10658. $scope.tender.purchaseTenderProds[i].index = i + 1;
  10659. }
  10660. $scope.tender.tenderAttaches = $scope.attaches;
  10661. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  10662. console.log($scope.tender.shipAddress);
  10663. var vendorUUs = [];
  10664. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  10665. vendorUUs.push(enterpriseBaseInfo.uu);
  10666. });
  10667. if (isPublish) { // 发布
  10668. toaster.pop('info', '提示', '正在发布,请稍候');
  10669. PurcTender.publish({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data){
  10670. sleep(1500); //当前方法暂停1.5秒
  10671. $scope.loading = false;
  10672. toaster.pop('success', '成功', '发布成功');
  10673. window.location.hash = '#/purc/tender';
  10674. }, function(response){
  10675. $scope.loading = false;
  10676. toaster.pop('error', '发布失败', response.data);
  10677. });
  10678. } else { // 保存
  10679. toaster.pop('info', '提示', '正在保存,请稍候');
  10680. PurcTender.save({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data) {
  10681. $scope.loading = false;
  10682. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  10683. toaster.pop('success', '成功', '保存成功');
  10684. window.location.hash = '#/purc/tender';
  10685. }, function(response){
  10686. $scope.loading = false;
  10687. toaster.pop('error', '保存失败', response.data);
  10688. });
  10689. }
  10690. }
  10691. };
  10692. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  10693. $scope.removeChecked = function() {
  10694. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  10695. $scope.tenderProd.enterpriseBaseInfo = [];
  10696. }
  10697. };
  10698. // 删除(在录入状态)
  10699. $scope.deleteThis = function(id) {
  10700. PurcTender.deleteOne({id:id}, {}, function(data) {
  10701. toaster.pop('info', '提示', '删除成功');
  10702. window.location.hash = '#/purc/tender';
  10703. });
  10704. };
  10705. // 更新和发布(在录入状态)
  10706. $scope.updateSaved = function(isPublish){
  10707. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  10708. toaster.pop('info','提示','请先指定供应商');
  10709. } else {
  10710. $scope.loading = true;
  10711. // --组装证照要求
  10712. var myCertificate = [];
  10713. angular.forEach($scope.certificates, function(certificate) {
  10714. if (certificate.checked) {
  10715. myCertificate.push(certificate.name);
  10716. }
  10717. });
  10718. $scope.tender.certificate = myCertificate.join(',');
  10719. if($scope.tender.endDate instanceof Date) {
  10720. $scope.tender.endDate = $scope.tender.endDate.getTime();
  10721. }
  10722. if($scope.tender.publishDate instanceof Date) {
  10723. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  10724. }
  10725. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  10726. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  10727. $scope.tender.purchaseTenderProds[i].index = i + 1;
  10728. }
  10729. $scope.tender.tenderAttaches = $scope.attaches;
  10730. if ($scope.tender.shipadd) {
  10731. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  10732. }
  10733. angular.forEach($scope.tender.purchaseTenderProds, function(tenderProd){
  10734. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  10735. });
  10736. var vendorUUs = [];
  10737. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){ // 供应商uu号参数
  10738. vendorUUs.push(enterpriseBaseInfo.uu);
  10739. });
  10740. console.log($scope);
  10741. if (isPublish) { // 发布
  10742. toaster.pop('info', '提示', '正在发布,请稍候');
  10743. PurcTender.publishSaved({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data){
  10744. sleep(1500); //当前方法暂停1.5秒
  10745. $scope.loading = false;
  10746. toaster.pop('success', '成功', '发布成功');
  10747. window.location.hash = '#/purc/tender';
  10748. }, function(response){
  10749. $scope.loading = false;
  10750. toaster.pop('error', '发布失败', response.data);
  10751. });
  10752. } else { // 保存
  10753. toaster.pop('info', '提示', '正在保存,请稍候');
  10754. PurcTender.updateSaved({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data) {
  10755. $scope.loading = false;
  10756. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  10757. toaster.pop('success', '成功', '保存成功');
  10758. window.location.reload();
  10759. }, function(response){
  10760. $scope.loading = false;
  10761. toaster.pop('error', '保存失败', response.data);
  10762. });
  10763. }
  10764. }
  10765. };
  10766. $scope.currentDay = function() {
  10767. return $filter('date')(new Date(), 'yyyy-MM-dd');
  10768. };
  10769. $scope.getMinDate = function() {
  10770. // var now = new Date();
  10771. // now = now.setDate(now.getDate()+1);
  10772. // var minDate = angular.copy($scope.tender.endDate);
  10773. // minDate = minDate.setDate(minDate.getDate() + 1);
  10774. if ($scope.tender.endDate instanceof Date) {
  10775. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  10776. }
  10777. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  10778. };
  10779. $scope.getMaxDate = function() {
  10780. // var maxDate = angular.copy($scope.tender.publishDate);
  10781. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  10782. if ($scope.tender.publishDate instanceof Date) {
  10783. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  10784. }
  10785. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  10786. };
  10787. $scope.openDatePicker = function($event, item, openParam) {
  10788. $event.preventDefault();
  10789. $event.stopPropagation();
  10790. item[openParam] = !item[openParam];
  10791. };
  10792. }]);
  10793. //类目选择模态框(招标产品明细)
  10794. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  10795. $scope.actives = actives;
  10796. $scope.kinds = [[], [], [], []];
  10797. // 获取子类目
  10798. var getChildren = function(pid, deep) {
  10799. KindAPI.getChildren({parentId: pid}, function(data) {
  10800. $scope.kinds[deep] = data;
  10801. }, function(response) {
  10802. toaster.pop('error', '获取子类目失败', response.data);
  10803. });
  10804. };
  10805. // 改变节点选中状态
  10806. var changeStatus = function(item, deep) {
  10807. var actives = [], level = 0;
  10808. angular.forEach($scope.kinds, function(ks, i) {
  10809. if(i > deep) {
  10810. $scope.kinds[i] = [];
  10811. } else {
  10812. angular.forEach(ks, function(k, j) {
  10813. if(i == deep) {
  10814. if(k.id == item.id) {
  10815. $scope.kinds[i][j].$active = true;
  10816. actives.push(k);
  10817. } else {
  10818. k.$active = null;
  10819. }
  10820. } else {
  10821. if(k.$active) {
  10822. actives.push(k);
  10823. }
  10824. }
  10825. });
  10826. }
  10827. });
  10828. // 选择的节点
  10829. $scope.actives = actives;
  10830. $scope.active = item;
  10831. // 当前可操作的层级
  10832. if(deep < 3) {
  10833. $scope.activeDeep = deep + 1;
  10834. }
  10835. };
  10836. // 节点点击后获取子类目,节点被选中
  10837. $scope.onItemClick = function(item, deep) {
  10838. changeStatus(item, deep);
  10839. if (!item.isLeaf) {
  10840. getChildren(item.id, deep + 1);
  10841. }
  10842. };
  10843. // 重新加载数据
  10844. function reload(deep) {
  10845. var pid;
  10846. if(deep) {
  10847. pid = $scope.actives[deep - 1].id;
  10848. } else {
  10849. pid = 0;
  10850. deep = 0;
  10851. }
  10852. getChildren(pid, deep);
  10853. }
  10854. // 初始加载数据,获取第一层的类目
  10855. if($scope.actives) {
  10856. angular.forEach($scope.actives, function(v, k) {
  10857. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  10858. $scope.kinds[k] = data;
  10859. angular.forEach($scope.kinds[k], function(kind, i){
  10860. if(kind.id == v.id) {
  10861. $scope.kinds[k][i].$active = true;
  10862. $scope.actives[k] = $scope.kinds[k][i];
  10863. }
  10864. })
  10865. }, function(response) {
  10866. toaster.pop('error', '获取子类目失败', response.data);
  10867. });
  10868. });
  10869. } else {
  10870. reload();
  10871. }
  10872. // 取消
  10873. $scope.cancel = function() {
  10874. $modalInstance.dismiss();
  10875. };
  10876. // 确认选择
  10877. $scope.check = function() {
  10878. var a = {
  10879. active: $scope.active,
  10880. actives: $scope.actives
  10881. };
  10882. $modalInstance.close(a);
  10883. };
  10884. }]);
  10885. //品牌选择模态框的controller
  10886. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  10887. $scope.filter = {};
  10888. $scope.brandsTableParams = new ngTableParams({
  10889. page : 1,
  10890. count : 6,
  10891. sorting : {
  10892. nameCn: 'asc'
  10893. }
  10894. }, {
  10895. total : 0,
  10896. counts : [],
  10897. getData : function($defer, params) {
  10898. var param = BaseService.parseParams(params.url());
  10899. param.keyword = $scope.filter.keyword;
  10900. var keyword = $scope.filter.keyword;
  10901. // param.keyword = $scope.filter.keyword;
  10902. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  10903. if (page) {
  10904. params.total(page.totalElements);
  10905. $defer.resolve(page.content);
  10906. }
  10907. }, function(){
  10908. });
  10909. }
  10910. });
  10911. // 搜索
  10912. $scope.search = function() {
  10913. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  10914. $scope.brandsTableParams.page(1);
  10915. $scope.brandsTableParams.reload();
  10916. };
  10917. // 选择
  10918. $scope.select = function(brand){
  10919. $modalInstance.close(brand);
  10920. };
  10921. // 关闭
  10922. $scope.cancel = function() {
  10923. $modalInstance.dismiss();
  10924. };
  10925. }]);
  10926. /**
  10927. * 招标单批量导入
  10928. */
  10929. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  10930. // 通过excel批量上传物料
  10931. $scope.result = null;
  10932. $scope.upload = function() {
  10933. var file = $scope.myFiles[0];
  10934. $upload.upload({
  10935. url: 'tender/release/excel',
  10936. file: file,
  10937. method: 'POST'
  10938. }).success(function(data) {
  10939. console.log(data);
  10940. $scope.result = data;
  10941. $scope.success = $scope.result.success;
  10942. $scope.total = $scope.result.total;
  10943. $scope.alters = $scope.result.alters;
  10944. }).error(function(response) {
  10945. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  10946. });
  10947. };
  10948. // 查看范例
  10949. $scope.showImg = function() {
  10950. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  10951. box.show();
  10952. box.find('img').attr('src', src);
  10953. box.find('a').click(function(){
  10954. box.hide();
  10955. });
  10956. box.dblclick(function(){
  10957. box.hide();
  10958. });
  10959. };
  10960. // 下载模板
  10961. $scope.download = function() {
  10962. window.location.href = 'tender/upload/template';
  10963. };
  10964. $scope.enSure = function() {
  10965. $modalInstance.close($scope.result.items);
  10966. }
  10967. $scope.cancel = function() {
  10968. $modalInstance.dismiss();
  10969. }
  10970. }]);
  10971. /**
  10972. * 评标
  10973. */
  10974. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  10975. BaseService.scrollBackToTop();
  10976. $scope.tenderItems = [];
  10977. // 采购方获取评标单
  10978. var evaluation = function() {
  10979. $scope.loading = true;
  10980. PurcTender.getOne({id: $stateParams.id}, function(data){
  10981. data.$editing = false;
  10982. $scope.tender = data;
  10983. console.log(typeof data.purchaseTenderProds[0].saleTenderItems[0].cycle);
  10984. $scope.tableParams = new ngTableParams({}, { dataset: data});
  10985. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  10986. $scope.loading = false;
  10987. }, function(response){
  10988. $scope.loading = false;
  10989. toaster.pop('error', '数据加载失败', response.data);
  10990. });
  10991. }
  10992. evaluation();
  10993. $scope.orderType = 'price';
  10994. // $scope.dir = '-';
  10995. // 改变排序顺序
  10996. $scope.changeOrder = function(type){
  10997. $scope.orderType = type;
  10998. // if(!$scope.dir || $scope.dir === '') {
  10999. // $scope.dir = '-';
  11000. // }else {
  11001. // $scope.dir = '';
  11002. // }
  11003. };
  11004. $scope.submit = function(tender) {
  11005. PurcTender.decide(tender, function(){
  11006. toaster.pop('success', '确认成功');
  11007. window.location.hash = '#/purc/tender';
  11008. }, function(response){
  11009. toaster.pop('error', '确认失败', response.data);
  11010. });
  11011. }
  11012. }]);
  11013. /**
  11014. * 客户招标
  11015. *
  11016. */
  11017. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  11018. BaseService.scrollBackToTop();
  11019. $scope.active = 'todo';
  11020. /**
  11021. * 改变类型
  11022. */
  11023. var getTypeCondition = function(zone, condition) {
  11024. if(zone == -1) {
  11025. condition.ifOpen = null;
  11026. } else if(zone == 1) {
  11027. condition.ifOpen = 1;
  11028. } else {
  11029. condition.ifOpen = 0;
  11030. }
  11031. };
  11032. $scope.dateZoneText = '不限';
  11033. $scope.typeText = '全部';
  11034. $scope.deliveryZoneText = '不限';
  11035. $scope.condition = {dateZone: -1, deliveryZone: -1, type: -1};
  11036. $scope.changeDateZone = function(zone) {
  11037. $scope.condition.dateZone = zone;
  11038. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  11039. $scope.condition.$dateZoneOpen = false;
  11040. getDateCondition(zone, $scope.condition);
  11041. $scope.tableParams.reload();
  11042. };
  11043. $scope.changeDeliveryZone = function(zone) {
  11044. $scope.condition.deliveryZoneText = zone;
  11045. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  11046. $scope.condition.$delievryZoneOpen = false;
  11047. getDelveryCondition(zone, $scope.condition);
  11048. $scope.tableParams.reload();
  11049. };
  11050. $scope.changeType = function(type) {
  11051. $scope.condition.type = type;
  11052. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  11053. getTypeCondition(type, $scope.condition);
  11054. $scope.tableParams.reload();
  11055. };
  11056. $scope.setActive = function(state) {
  11057. if($scope.active != state) {
  11058. $scope.active = state;
  11059. if($scope.tableParams.page() == 1)
  11060. $scope.tableParams.reload();
  11061. else
  11062. $scope.tableParams.page(1);
  11063. }
  11064. };
  11065. $scope.tableParams = new ngTableParams({
  11066. page : 1,
  11067. count : 5,
  11068. sorting: {
  11069. 'tender.endDate': 'desc',
  11070. 'tender.enterprise.enName': 'asc',
  11071. 'tender.code': 'asc'
  11072. }
  11073. }, {
  11074. total : 0,
  11075. counts: [5, 10, 25, 50],
  11076. getData : function($defer, params) {
  11077. $scope.loading = true;
  11078. var pageParams = params.url();
  11079. var realActive = {};
  11080. pageParams.searchFilter = { // 筛选条件
  11081. keyword: $scope.keyword,
  11082. pt_ifopen: $scope.condition.ifOpen,
  11083. fromDate: getDateTime($scope.condition.dateFrom),
  11084. endDate: getDateTime($scope.condition.dateTo)
  11085. };
  11086. AccountEnterprise.get({}, function(data){
  11087. $scope.loading = false;
  11088. $scope.currentEn = data;
  11089. });
  11090. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11091. $scope.loading = false;
  11092. if(page) {
  11093. params.total(page.totalElement);
  11094. $defer.resolve(page.content);
  11095. console.log(page.content);
  11096. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  11097. angular.forEach(page.content, function(purcTender) {
  11098. purcTender.vendorHasBid = false;
  11099. angular.forEach(purcTender.purchaseTenderProds, function(tenderProd) {
  11100. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11101. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  11102. tenderProd.currentItem = saleTenderItem;
  11103. if (saleTenderItem.price) { //TODO 如果存在当前企业的投标明细已投标,即判断为已投标
  11104. purcTender.vendorHasBid = true;
  11105. }
  11106. }
  11107. });
  11108. });
  11109. });
  11110. }
  11111. }, function(response){
  11112. $scope.loading = false;
  11113. toaster.pop('error', '数据加载失败', response.data);
  11114. });
  11115. }
  11116. });
  11117. $scope.openDatePicker = function($event, item, openParam) {
  11118. $event.preventDefault();
  11119. $event.stopPropagation();
  11120. item[openParam] = !item[openParam];
  11121. };
  11122. $scope.parseDate = function(dateStr) {
  11123. if(dateStr)
  11124. return Date.parse(dateStr, 'yyyy-MM-dd');
  11125. return new Date();
  11126. };
  11127. // 选择查找日期
  11128. $scope.onDateCondition = function(){
  11129. $scope.tableParams.page(1);
  11130. $scope.tableParams.reload();
  11131. };
  11132. // 搜索框回车
  11133. $scope.onSearch = function() {
  11134. $scope.tableParams.page(1);
  11135. $scope.tableParams.reload();
  11136. };
  11137. }]);
  11138. /**
  11139. * 平台公开招标
  11140. *
  11141. */
  11142. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  11143. BaseService.scrollBackToTop();
  11144. /**
  11145. * 改变单据日期范围
  11146. */
  11147. var getTenderDateCondition = function(zone, condition) {
  11148. var date = new Date();
  11149. if(zone == -1) {
  11150. condition.dateFrom = null;
  11151. condition.dateTo = null;
  11152. } else if(zone == 7) { // 一星期内
  11153. date.setDate(date.getDate() - 7);
  11154. condition.dateFrom = date;
  11155. condition.dateTo = new Date();
  11156. } else if(zone == 1) { // 一个月内
  11157. date.setMonth(date.getMonth() - 1);
  11158. condition.dateFrom = date;
  11159. condition.dateTo = new Date();
  11160. } else if(zone == 3) { // 三个月内
  11161. date.setMonth(date.getMonth() - 3);
  11162. condition.dateFrom = date;
  11163. condition.dateTo = new Date();
  11164. } else if (zone == 6) { // 半年内
  11165. date.setMonth(date.getMonth() - 6);
  11166. condition.dateFrom = date;
  11167. condition.dateTo = new Date();
  11168. } else { // 一年内
  11169. date.setYear(date.getYear() - 1);
  11170. condition.dateFrom = date;
  11171. condition.dateTo = new Date();
  11172. }
  11173. };
  11174. $scope.active = 'all';
  11175. $scope.dateZoneText = '不限';
  11176. $scope.deliveryZoneText = '不限';
  11177. $scope.condition = {dateZone: -1};
  11178. $scope.changeDateZone = function(zone) {
  11179. $scope.condition.dateZone = zone;
  11180. $scope.condition.$dateZoneOpen = false;
  11181. getTenderDateCondition(zone, $scope.condition);
  11182. $scope.tableParams.reload();
  11183. };
  11184. $scope.openDatePicker = function($event, item, openParam) {
  11185. $event.preventDefault();
  11186. $event.stopPropagation();
  11187. item[openParam] = !item[openParam];
  11188. };
  11189. $scope.parseDate = function(dateStr) {
  11190. if(dateStr)
  11191. return Date.parse(dateStr, 'yyyy-MM-dd');
  11192. return new Date();
  11193. };
  11194. // 选择查找日期
  11195. $scope.onDateCondition = function(){
  11196. $scope.tableParams.page(1);
  11197. $scope.tableParams.reload();
  11198. };
  11199. // $scope.setActive = function(state) {
  11200. // if($scope.active != state) {
  11201. // $scope.active = state;
  11202. // if($scope.tableParams.page() == 1)
  11203. // $scope.tableParams.reload();
  11204. // else
  11205. // $scope.tableParams.page(1);
  11206. // }
  11207. // };
  11208. var getOpenState = function(active) {
  11209. var fn = 'getOpenAll';
  11210. switch(active) {
  11211. case 'all':
  11212. fn = 'getOpenAll';break;
  11213. // case 'done':
  11214. // fn = 'getOpenDone';break;
  11215. case 'todo':
  11216. fn = 'getOpenTodo';break;
  11217. case 'end':
  11218. fn = 'getOpenEnd';break;
  11219. // case 'waiting':
  11220. // fn = 'getOpenWaiting';break;
  11221. }
  11222. return fn;
  11223. };
  11224. $scope.tableParams = new ngTableParams({
  11225. page : 1,
  11226. count : 10,
  11227. sorting: {
  11228. 'tender.endDate': 'desc',
  11229. 'tender.enterprise.enName': 'asc',
  11230. 'tender.code': 'asc'
  11231. }
  11232. }, {
  11233. total : 0,
  11234. counts: [10, 25, 50, 100],
  11235. getData : function($defer, params) {
  11236. $scope.loading = true;
  11237. var pageParams = params.url();
  11238. var realActive = {};
  11239. pageParams.searchFilter = { // 筛选条件
  11240. keyword: $scope.keyword,
  11241. fromDate: getDateTime($scope.condition.dateFrom),
  11242. endDate: getDateTime($scope.condition.dateTo)
  11243. };
  11244. AccountEnterprise.get({}, function(data){
  11245. $scope.loading = false;
  11246. $scope.currentEn = data;
  11247. });
  11248. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11249. $scope.loading = false;
  11250. if(page) {
  11251. params.total(page.totalElement);
  11252. $defer.resolve(page.content);
  11253. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  11254. }
  11255. }, function(response){
  11256. $scope.loading = false;
  11257. toaster.pop('error', '数据加载失败', response.data);
  11258. });
  11259. }
  11260. });
  11261. $scope.toDetail = function(id) {
  11262. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  11263. };
  11264. // var stautsItem = [];
  11265. // $scope.getTenderStatus = function (tender) {
  11266. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  11267. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  11268. // stautsItem = thisItem;
  11269. // }
  11270. // });
  11271. // if (!stautsItem.price) {
  11272. // return "daitoubiao";
  11273. // } else if (!stautsItem.applystatus) {
  11274. // return "yitoubiao";
  11275. // } else if (stautsItem.applystatus == 1) {
  11276. // return "zhongbiao";
  11277. // } else if (stautsItem.applystatus == 0) {
  11278. // return "weizhongbiao";
  11279. // }
  11280. // };
  11281. // 搜索框回车
  11282. $scope.onSearch = function() {
  11283. $scope.tableParams.page(1);
  11284. $scope.tableParams.reload();
  11285. };
  11286. }]);
  11287. /**
  11288. * 采购方查看供应商投标单
  11289. */
  11290. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  11291. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  11292. // $scope.item = data; // 供应商查看
  11293. // $scope.loading = false;
  11294. // }, function(response){
  11295. // $scope.loading = false;
  11296. // toaster.pop('error', '数据加载失败', response.data);
  11297. // });
  11298. console.log($stateParams);
  11299. PurcTender.getOne({id: $stateParams.id}, function(data){
  11300. $scope.bid = data;
  11301. var vendUU = Number($stateParams.vendUU);
  11302. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11303. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11304. if (saleTenderItem.saleTender.vendUU === vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  11305. tenderProd.currentItem = saleTenderItem;
  11306. $scope.saleTender = saleTenderItem.saleTender;
  11307. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11308. }
  11309. });
  11310. });
  11311. }, function(response){
  11312. toaster.pop('error', '数据加载失败', response.data);
  11313. });
  11314. }]);
  11315. /**
  11316. * 查看投标单详情
  11317. */
  11318. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise) {
  11319. BaseService.scrollBackToTop();
  11320. if (!$scope.attaches) {
  11321. $scope.attaches = []; // 存放上传了的附件
  11322. }
  11323. // var staticItem = null;
  11324. // $scope.loading = true;
  11325. // PurcTender.getItem({id: $stateParams.id}, function(data){
  11326. // $scope.item = data; // 用于投标
  11327. // if ($scope.item.enterpriseBaseInfo != null) {
  11328. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  11329. // }
  11330. // staticItem = angular.copy(data);
  11331. // $scope.loading = false;
  11332. // }, function(response){
  11333. // $scope.loading = false;
  11334. // toaster.pop('error', '数据加载失败', response.data);
  11335. // });
  11336. var sleep = function (d){
  11337. for(var t = Date.now();Date.now() - t <= d;);
  11338. };
  11339. AccountEnterprise.get({}, function(data){
  11340. $scope.currentEn = data;
  11341. });
  11342. PurcTender.getOne({id: $stateParams.id}, function(data){
  11343. $scope.bid = data;
  11344. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11345. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11346. if (!$scope.currentEn) {
  11347. AccountEnterprise.get({}, function(data){
  11348. $scope.currentEn = data;
  11349. });
  11350. }
  11351. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  11352. tenderProd.currentItem = saleTenderItem;
  11353. $scope.saleTender = saleTenderItem.saleTender;
  11354. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  11355. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11356. }
  11357. });
  11358. });
  11359. }, function(response){
  11360. toaster.pop('error', '数据加载失败', response.data);
  11361. });
  11362. $scope.upload = function(myFile) { // 上传附件
  11363. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  11364. $upload.upload({
  11365. url: 'tender/addTenderItemAttach',
  11366. file: file,
  11367. method: 'POST'
  11368. }).success(function (attach) {
  11369. $scope.attaches.push(attach);
  11370. });
  11371. };
  11372. $scope.removeAttach = function(attachId, index) {
  11373. $scope.attaches.splice(index, 1);
  11374. // PurcTender.removeAttach({attachId : id}, {}, function() {
  11375. //
  11376. // });
  11377. };
  11378. var taxrateYes = false;
  11379. var cycleYes = false;
  11380. var priceYes = false;
  11381. $scope.canSave = false;
  11382. $scope.validateThis = function(value, type) {
  11383. switch(type) {
  11384. case 'taxrate':
  11385. var regex = /^\+?[0-9][0-9]{0,1}$/;
  11386. if (regex.test(value)) {
  11387. taxrateYes = true;
  11388. } else {
  11389. if (value) {
  11390. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  11391. }
  11392. }
  11393. break;
  11394. case 'cycle':
  11395. regex = /^\+?[1-9][0-9]*$/;
  11396. if (regex.test(value)) {
  11397. cycleYes = true;
  11398. } else {
  11399. if (value) {
  11400. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  11401. }
  11402. }
  11403. break;
  11404. case 'price':
  11405. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11406. if (regex.test(value) && value !== 0) {
  11407. priceYes = true;
  11408. } else {
  11409. if (value) {
  11410. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  11411. }
  11412. }
  11413. break;
  11414. }
  11415. };
  11416. $scope.emNumYes = true;
  11417. $scope.validEmNum = function (value) {
  11418. var regex = /^\+?[1-9][0-9]*$/;
  11419. if (!regex.test(value) || value === 0 || value !== null) {
  11420. $scope.emNumYes = false;
  11421. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  11422. }
  11423. };
  11424. $scope.validateProds = function(tenderProd) {
  11425. $scope.canSave = true;
  11426. if (tenderProd.currentItem.cycle || tenderProd.currentItem.taxrate || tenderProd.currentItem.price) {
  11427. var cycleRegex = /^\+?[1-9][0-9]*$/;
  11428. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  11429. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  11430. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11431. // 判断填写过的有为0或不符合正则式的,设置不能保存
  11432. if (!cycleRegex.test(tenderProd.currentItem.cycle) || !taxrateRegex.test(tenderProd.currentItem.taxrate) || !priceRegex.test(tenderProd.currentItem.price)) {
  11433. $scope.canSave = false;
  11434. } else {
  11435. $scope.canSave = true;
  11436. }
  11437. }
  11438. };
  11439. // 投标
  11440. $scope.bidIt = function(tender, currentEnBaseInfo){
  11441. $scope.loading = true;
  11442. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  11443. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  11444. }
  11445. var saleTenderItems = [];
  11446. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11447. if (tenderProd.currentItem) {
  11448. tenderProd.currentItem.saleTender = {};
  11449. saleTenderItems.push(tenderProd.currentItem);
  11450. }
  11451. });
  11452. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  11453. $scope.loading = false;
  11454. toaster.pop('info', '成功', '投标成功');
  11455. // $window.location.reload();
  11456. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  11457. // window.location.hash = '#/sale/opentender';
  11458. // } else {
  11459. window.location.hash = '#/sale/tender';
  11460. // }
  11461. }, function(response){
  11462. $scope.loading = false;
  11463. toaster.pop('error', '投标失败', '出现异常,投标失败');
  11464. });
  11465. };
  11466. $scope.condition = {
  11467. $fromOpened:false
  11468. };
  11469. $scope.getMaxDate = function() {
  11470. return $filter('date')(new Date(), 'yyyy-MM-dd');
  11471. };
  11472. $scope.openDatePicker = function($event, item, openParam) {
  11473. $event.preventDefault();
  11474. $event.stopPropagation();
  11475. item[openParam] = !item[openParam];
  11476. };
  11477. }]);
  11478. /**
  11479. * 公开招标转投标单
  11480. */
  11481. 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) {
  11482. BaseService.scrollBackToTop();
  11483. $scope.attaches = []; // 存放上传了的附件
  11484. var sleep = function (d){
  11485. for(var t = Date.now();Date.now() - t <= d;);
  11486. }
  11487. var getCurrentEn = function() {
  11488. AccountEnterprise.get({}, function(data){
  11489. $scope.currentEn = data;
  11490. });
  11491. }
  11492. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  11493. $scope.loading = true;
  11494. getCurrentEn();
  11495. PurcTender.getOne({id: $stateParams.id}, function(data){
  11496. data.$editing = false;
  11497. $scope.tender = data;
  11498. $scope.tenderProd = data.purchaseTenderProds;
  11499. // parseCertificate($scope.tender.certificate);
  11500. // $scope.firstProd = data.purchaseTenderProds[0];
  11501. $scope.currentHasBid = false; // 默认当前企业未转投标单
  11502. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  11503. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  11504. $scope.currentHasBid = true;
  11505. }
  11506. });
  11507. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  11508. // console.log($scope.tenderProd.enterpriseBaseInfo);
  11509. $scope.loading = false;
  11510. $scope.attaches = $scope.tender.tenderAttaches;
  11511. }, function(response){
  11512. $scope.loading = false;
  11513. toaster.pop('error', '数据加载失败', response.data);
  11514. });
  11515. }
  11516. $scope.hasClick = false;
  11517. $scope.iWantToBid = function(id) {
  11518. $scope.hasClick = true;
  11519. PurcTender.addItems({id: id}, {}, function(data){ // 添加明细
  11520. // $scope.tender = data;
  11521. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11522. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11523. // if (!$scope.currentEn) {
  11524. // AccountEnterprise.get({}, function(data){
  11525. // $scope.currentEn = data;
  11526. // });
  11527. // }
  11528. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  11529. // tenderProd.currentItem = saleTenderItem;
  11530. // $scope.saleTender = saleTenderItem.saleTender;
  11531. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  11532. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11533. // }
  11534. // });
  11535. // });
  11536. toaster.pop('success', '成功', '转投标单成功');
  11537. window.location.hash = "#/sale/tender/" + id;
  11538. }, function(response){
  11539. toaster.pop('error', '操作失败', response.data);
  11540. });
  11541. // $scope.upload = function(myFile) { // 上传附件
  11542. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  11543. // $upload.upload({
  11544. // url: 'tender/addTenderItemAttach',
  11545. // file: file,
  11546. // method: 'POST'
  11547. // }).success(function (attach) {
  11548. // $scope.attaches.push(attach);
  11549. // });
  11550. // };
  11551. };
  11552. // $scope.removeAttach = function(id, index) {
  11553. // $scope.attaches.splice(index, 1);
  11554. // PurcTender.removeAttach({attachId:id}, function() {
  11555. //
  11556. // });
  11557. // };
  11558. // var taxrateYes = false;
  11559. // var cycleYes = false;
  11560. // var priceYes = false;
  11561. // $scope.canSave = false;
  11562. // $scope.validateThis = function(value, type) {
  11563. // switch(type) {
  11564. // case 'taxrate':
  11565. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  11566. // if (regex.test(value)) {
  11567. // taxrateYes = true;
  11568. // } else {
  11569. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  11570. // }
  11571. // break;
  11572. // case 'cycle':
  11573. // regex = /^\+?[1-9][0-9]*$/;
  11574. // if (regex.test(value)) {
  11575. // cycleYes = true;
  11576. // } else {
  11577. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  11578. // }
  11579. // break;
  11580. // case 'price':
  11581. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11582. // if (regex.test(value) && value !== 0) {
  11583. // priceYes = true;
  11584. // } else {
  11585. // if (!(value instanceof Number) || value) {
  11586. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  11587. // }
  11588. // }
  11589. // break;
  11590. // }
  11591. // };
  11592. //
  11593. // $scope.emNumYes = true;
  11594. //
  11595. // $scope.validEmNum = function (value) {
  11596. // var regex = /^\+?[1-9][0-9]*$/;
  11597. // if (!regex.test(value) || value == 0 || value !== null) {
  11598. // $scope.emNumYes = false;
  11599. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  11600. // }
  11601. // };
  11602. //
  11603. // $scope.validateProds = function(tenderProd) {
  11604. // // angular.forEach(tenderProds, function (tenderProd) {
  11605. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  11606. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  11607. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  11608. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11609. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  11610. // console.log(tenderProd.currentItem.cycle);
  11611. // if (tenderProd.currentItem.cycle !== null && (!cycleRegex.test(tenderProd.currentItem.cycle)) || (tenderProd.currentItem.taxrate !== null && !taxrateRegex.test(tenderProd.currentItem.taxrate)) || (tenderProd.currentItem.price !==null && (!priceRegex.test(tenderProd.currentItem.price) && tenderProd.currentItem.price !== 0))) {
  11612. // $scope.canSave = false;
  11613. // } else {
  11614. // $scope.canSave = true;
  11615. // }
  11616. // // });
  11617. // };
  11618. //
  11619. // // 投标
  11620. // $scope.bidIt = function(tender, currentEnBaseInfo){
  11621. // $scope.loading = true;
  11622. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  11623. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  11624. // }
  11625. // var saleTenderItems = [];
  11626. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  11627. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11628. // if (tenderProd.currentItem) {
  11629. // tenderProd.currentItem.saleTender = {};
  11630. // saleTenderItems.push(tenderProd.currentItem);
  11631. // }
  11632. // });
  11633. // } else {
  11634. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11635. // if (tenderProd.currentItem) {
  11636. // saleTenderItems.push(tenderProd.currentItem);
  11637. // }
  11638. // });
  11639. // }
  11640. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  11641. // $scope.loading = false;
  11642. // toaster.pop('info', '成功', '投标成功');
  11643. // // $window.location.reload();
  11644. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  11645. // // window.location.hash = '#/sale/opentender';
  11646. // // } else {
  11647. // window.location.hash = '#/sale/tender';
  11648. // // }
  11649. // }, function(response){
  11650. // $scope.loading = false;
  11651. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  11652. // });
  11653. //
  11654. // };
  11655. //
  11656. // $scope.condition = {
  11657. // $fromOpened:false
  11658. // };
  11659. //
  11660. // $scope.getMaxDate = function() {
  11661. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  11662. // };
  11663. //
  11664. // $scope.openDatePicker = function($event, item, openParam) {
  11665. // $event.preventDefault();
  11666. // $event.stopPropagation();
  11667. // item[openParam] = !item[openParam];
  11668. // };
  11669. }]);
  11670. return app;
  11671. });