app.js 248 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo'], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices']);
  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. $urlRouterProvider.otherwise('/index');
  25. $stateProvider.state('index', {
  26. url : "/index",
  27. views : {
  28. "left-view" : {
  29. templateUrl : "static/tpl/index/home/left.html",
  30. controller: 'LeftCtrl'
  31. },
  32. "right-view" : {
  33. templateUrl : "static/tpl/index/home/right.html",
  34. controller: 'RightCtrl'
  35. }
  36. }
  37. }).state('home', {
  38. url : "/",
  39. views : {
  40. "left-view" : {
  41. templateUrl : "static/tpl/index/home/left.html",
  42. controller: 'LeftCtrl'
  43. },
  44. "right-view" : {
  45. templateUrl : "static/tpl/index/home/right.html",
  46. controller: 'RightCtrl'
  47. }
  48. }
  49. }).state('sale', {
  50. url : "/sale",
  51. views : {
  52. "left-view" : {
  53. templateUrl : "static/tpl/index/sale/left.html",
  54. controller: 'LeftCtrl'
  55. },
  56. "right-view" : {
  57. templateUrl : "static/tpl/index/sale/right.html"
  58. }
  59. },
  60. controller: function($scope) {
  61. $scope.truck = [];
  62. $scope.dataChanged = false;
  63. }
  64. }).state('sale.index', {
  65. url : "",
  66. templateUrl : "static/tpl/index/sale/index.html"
  67. }).state('sale.home', {
  68. url : "/",
  69. templateUrl : "static/tpl/index/sale/index.html"
  70. }).state('purc', {
  71. url : "/purc",
  72. views : {
  73. "left-view" : {
  74. templateUrl : "static/tpl/index/purc/left.html",
  75. controller: 'LeftCtrl'
  76. },
  77. "right-view" : {
  78. templateUrl : "static/tpl/index/purc/right.html"
  79. }
  80. },
  81. controller: function($scope) {
  82. $scope.truck = [];
  83. $scope.dataChanged = false;
  84. }
  85. }).state('purc.index', {
  86. url : "",
  87. templateUrl : "static/tpl/index/purc/index.html"
  88. }).state('purc.home', {
  89. url : "/",
  90. templateUrl : "static/tpl/index/purc/index.html"
  91. }).state('purc.introduce', {
  92. url : "/introduce",
  93. templateUrl : "static/tpl/index/purc/introduce.html"
  94. }).state('purc.order', {
  95. url : "/order",
  96. templateUrl : "static/tpl/index/purc/order.html",
  97. controller: 'PurcOrderCtrl'
  98. }).state('purc.order_detail', {
  99. url : "/order/:id",
  100. templateUrl : "static/tpl/index/purc/order_detail.html",
  101. controller: 'PurcOrderDetailCtrl'
  102. }).state('purc.newOrder', {
  103. url : "addOrder",
  104. templateUrl : "static/tpl/index/purc/addOrder.html",
  105. controller : 'PurcNewOrderCtrl'
  106. }).state('sale.todo', {
  107. url : "/todo",
  108. templateUrl : "static/tpl/index/sale/todo.html"
  109. }).state('sale.todo.inquiry', {
  110. url : "/inquiry",
  111. templateUrl : "static/tpl/index/sale/inquiry.html",
  112. controller: 'SaleInquiryCtrl'
  113. }).state('sale.todo.order', {
  114. url : "/order",
  115. templateUrl : "static/tpl/index/sale/order.html",
  116. controller: 'SaleOrderCtrl'
  117. }).state('sale.todo.change', {
  118. url : "/change",
  119. templateUrl : "static/tpl/index/sale/change.html",
  120. controller: 'SaleChangeCtrl'
  121. }).state('sale.todo.notice', {
  122. url : "/notice",
  123. templateUrl : "static/tpl/index/sale/notice.html",
  124. controller: 'SaleNoticeCtrl'
  125. }).state('sale.customer', {
  126. url : "/customer",
  127. templateUrl : "static/tpl/index/sale/customer.html",
  128. controller: 'CustomerCtrl'
  129. }).state('sale.customerProduct', {
  130. url : "/customerProduct",
  131. templateUrl : "static/tpl/index/sale/customer.html",
  132. controller: 'CustomerCtrl'
  133. }).state('sale.inquiry', {
  134. url : "/inquiry",
  135. templateUrl : "static/tpl/index/sale/inquiry.html",
  136. controller: 'SaleInquiryCtrl'
  137. }).state('sale.inquirymould', {
  138. url : "/mould",
  139. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  140. controller: 'SaleInquiryMouldCtrl'
  141. }).state('sale.todo.inquirymould', {
  142. url : "/mould",
  143. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  144. controller: 'SaleInquiryMouldCtrl'
  145. }).state('sale.inquiry_mould_detail', {
  146. url : "/mould/:id",
  147. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  148. controller: 'SaleInquiryMouldDetailCtrl'
  149. }).state('sale.inquiry_detail', {
  150. url : "/inquiry/:id",
  151. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  152. controller: 'SaleInquiryDetailCtrl'
  153. }).state('sale.quotation', {
  154. url : "/quotation",
  155. templateUrl : "static/tpl/index/sale/quotation.html"
  156. }).state('sale.quotation.new', {
  157. url : "/new",
  158. templateUrl : "static/tpl/index/sale/quotation_new.html",
  159. controller: 'SaleQuotationNewCtrl'
  160. }).state('sale.quotation.list', {
  161. url : "/list",
  162. templateUrl : "static/tpl/index/sale/quotation_list.html",
  163. controller: 'SaleQuotationListCtrl'
  164. }).state('sale.quotation.item', {
  165. url : "/:id",
  166. templateUrl : "static/tpl/index/sale/quotation_new.html",
  167. controller: 'SaleQuotationNewCtrl'
  168. }).state('sale.order', {
  169. url : "/order",
  170. templateUrl : "static/tpl/index/sale/order.html",
  171. controller: 'SaleOrderCtrl'
  172. }).state('sale.order_detail', {
  173. url : "/order/:id",
  174. templateUrl : "static/tpl/index/sale/order_detail.html",
  175. controller: 'SaleOrderDetailCtrl'
  176. }).state('sale.change', {
  177. url : "/change",
  178. templateUrl : "static/tpl/index/sale/change.html",
  179. controller: 'SaleChangeCtrl'
  180. }).state('sale.change_detail', {
  181. url : "/change/:id",
  182. templateUrl : "static/tpl/index/sale/change_detail.html",
  183. controller: 'SaleChangeDetailCtrl'
  184. }).state('sale.notice', {
  185. url : "/notice",
  186. templateUrl : "static/tpl/index/sale/notice.html",
  187. controller: 'SaleNoticeCtrl'
  188. }).state('sale.send', {
  189. url : "/send",
  190. templateUrl : "static/tpl/index/sale/send.html",
  191. controller: 'SaleSendCtrl'
  192. }).state('sale.send_detail', {
  193. url : "/send/:id",
  194. templateUrl : "static/tpl/index/sale/send_detail.html",
  195. controller: 'SaleSendDetailCtrl'
  196. }).state('sale.forecast', {
  197. url : "/forecast",
  198. templateUrl : "static/tpl/index/sale/forecast.html",
  199. controller: 'SaleForecastCtrl'
  200. }).state('sale.accept', {
  201. url : "/accept",
  202. templateUrl : "static/tpl/index/sale/accept.html",
  203. controller: 'SaleAcceptCtrl'
  204. }).state('sale.returns', {
  205. url : "/returns",
  206. templateUrl : "static/tpl/index/sale/returns.html",
  207. controller: 'SaleReturnsCtrl'
  208. }).state('sale.sample', {
  209. url : "/sample",
  210. templateUrl : "static/tpl/index/sale/sample.html",
  211. controller: 'SaleSampleCtrl'
  212. }).state('sale.sample_detail', {
  213. url : "/sample/:id",
  214. templateUrl : "static/tpl/index/sale/sample_detail.html",
  215. controller: 'SaleSampleDetailCtrl'
  216. }).state('sale.approval', {
  217. url : "/approval",
  218. templateUrl : "static/tpl/index/sale/approval.html",
  219. controller: 'SaleApprovalCtrl'
  220. }).state('account', {
  221. url : "/account",
  222. views : {
  223. "left-view" : {
  224. templateUrl : "static/tpl/index/account/left.html",
  225. controller: 'LeftCtrl'
  226. },
  227. "right-view" : {
  228. templateUrl : "static/tpl/index/account/right.html"
  229. }
  230. }
  231. }).state('account.index', {
  232. url : "",
  233. templateUrl : "static/tpl/index/account/index.html",
  234. controller: 'RightCtrl'
  235. }).state('account.home', {
  236. url : "/",
  237. templateUrl : "static/tpl/index/account/index.html",
  238. controller: 'RightCtrl'
  239. }).state('account.enterprise', {
  240. url : "/enterprise",
  241. templateUrl : "static/tpl/index/account/enterprise.html",
  242. controller: 'EnterpriseCtrl'
  243. }).state('account.user', {
  244. url : "/user",
  245. templateUrl : "static/tpl/index/account/user.html",
  246. controller: 'UserCtrl'
  247. }).state('account.log', {
  248. url : "/log",
  249. templateUrl : "static/tpl/index/account/log.html",
  250. controller: 'LogCtrl'
  251. }).state('account.resource', {
  252. url : "/resource",
  253. templateUrl : "static/tpl/index/account/resource.html",
  254. controller: 'ResourceCtrl'
  255. }).state('account.role', {
  256. url : "/role",
  257. templateUrl : "static/tpl/index/account/role.html",
  258. controller: 'RoleCtrl'
  259. }).state('baseInfo', {//基础资料
  260. url : "/baseInfo",
  261. views : {
  262. "left-view" : {
  263. templateUrl : "static/tpl/index/baseInfo/left.html",
  264. controller: 'LeftCtrl'
  265. },
  266. "right-view" : {
  267. templateUrl : "static/tpl/index/baseInfo/right.html"
  268. }
  269. }
  270. }).state('baseInfo.index', {
  271. url : "",
  272. templateUrl : "static/tpl/index/baseInfo/index.html",
  273. controller: 'RightCtrl'
  274. }).state('baseInfo.home', {
  275. url : "/",
  276. templateUrl : "static/tpl/index/baseInfo/index.html",
  277. controller: 'RightCtrl'
  278. }).state('baseInfo.prodList', {
  279. url : "/prodList",
  280. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  281. controller : 'ProductListCtrl'
  282. }).state('baseInfo.uploadByBatch', {
  283. url : "/uploadByBatch",
  284. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  285. controller : 'UploadByBatchCtrl'
  286. }).state('baseInfo.productDetail', {
  287. url : "/prodList/:id",
  288. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  289. controller : 'ProductDetailCtrl'
  290. }).state('baseInfo.newProdInfo', {
  291. url : "/newProdInfo",
  292. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  293. controller : 'NewProdInfoCtrl'
  294. }).state('baseInfo.enterpriseList', {
  295. url : "/enterpriseList",
  296. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  297. controller : 'EnterpriseListCtrl'
  298. }).state('baseInfo.myClient', {
  299. url : "/myClient",
  300. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  301. controller : 'MyClientCtrl'
  302. }).state('baseInfo.mySupplier', {
  303. url : "/mySupplier",
  304. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  305. controller : 'MySupplierCtrl'
  306. }).state('baseInfo.myRequest', {
  307. url : "/myRquest",
  308. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  309. controller : 'AddPartnerRequestCtrl'
  310. }).state('baseInfo.myMessage', {
  311. url : "/myMessage",
  312. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  313. controller : 'AddPartnerMessageCtrl'
  314. }).state('baseInfo.myPartners', {
  315. url : '/myPartners',
  316. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  317. controller : 'MyPartnersCtrl'
  318. }).state('baseInfo.businessGroups', {
  319. url : '/businessGroups',
  320. controller : 'BusinessGroupsCtrl'
  321. }).state('qc', {
  322. url : "/qc",
  323. views : {
  324. "left-view" : {
  325. templateUrl : "static/tpl/index/qc/left.html"
  326. },
  327. "right-view" : {
  328. templateUrl : "static/tpl/index/qc/right.html"
  329. }
  330. }
  331. }).state('qc.index', {
  332. url : "",
  333. templateUrl : "static/tpl/index/qc/index.html"
  334. }).state('qc.home', {
  335. url : "/",
  336. templateUrl : "static/tpl/index/qc/index.html"
  337. }).state('qc.badIn', {
  338. url : "/badIn",
  339. templateUrl : "static/tpl/index/qc/badIn.html",
  340. controller: 'SaleBadInCtrl'
  341. }).state('qc.badOut', {
  342. url : "/badOut",
  343. templateUrl : "static/tpl/index/qc/badOut.html",
  344. controller: 'SaleBadOutCtrl'
  345. }).state('qc.MRB', {
  346. url : "/MRB",
  347. templateUrl : "static/tpl/index/qc/MRB.html",
  348. controller: 'SaleMRBCtrl'
  349. }).state('fa', {
  350. url : "/fa",
  351. views : {
  352. "left-view" : {
  353. templateUrl : "static/tpl/index/fa/left.html"
  354. },
  355. "right-view" : {
  356. templateUrl : "static/tpl/index/fa/right.html"
  357. }
  358. }
  359. }).state('fa.index', {
  360. url : "",
  361. templateUrl : "static/tpl/index/fa/index.html"
  362. }).state('fa.home', {
  363. url : "/",
  364. templateUrl : "static/tpl/index/fa/index.html"
  365. }).state('fa.apBill', {
  366. url : "/apBill",
  367. templateUrl : "static/tpl/index/fa/apBill.html",
  368. controller: 'SaleApBillCtrl'
  369. }).state('fa.arCheck', {
  370. url : "/arCheck",
  371. templateUrl : "static/tpl/index/fa/arCheck.html",
  372. controller: 'SaleArCheckCtrl'
  373. }).state('fa.arCheck_detail', {
  374. url : "/arCheck/:id",
  375. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  376. controller: 'SaleArCheckDetailCtrl'
  377. }).state('fa.apCheck', {
  378. url : "/apCheck",
  379. params:{
  380. 'id':null
  381. },
  382. templateUrl : "static/tpl/index/fa/apCheck.html",
  383. controller: 'PurchaseApCheckCtrl'
  384. }).state('fa.apCheck_detail', {
  385. url : "/apCheck/:id",
  386. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  387. controller: 'PurchaseApCheckDetailCtrl'
  388. }).state('fa.apCheckList', {
  389. url : "/apCheckList",
  390. templateUrl : "static/tpl/index/fa/apCheckList.html",
  391. controller: 'PurchaseApCheckListCtrl'
  392. }).state('make', {
  393. url : "/make",
  394. views : {
  395. "left-view" : {
  396. templateUrl : "static/tpl/index/make/left.html"
  397. },
  398. "right-view" : {
  399. templateUrl : "static/tpl/index/make/right.html"
  400. }
  401. }
  402. }).state('make.index', {
  403. url : "",
  404. templateUrl : "static/tpl/index/make/index.html"
  405. }).state('make.home', {
  406. url : "/",
  407. templateUrl : "static/tpl/index/make/index.html"
  408. }).state('make.todo', {
  409. url : "/todo",
  410. templateUrl : "static/tpl/index/make/todo.html"
  411. }).state('make.todo.order', {
  412. url : "/order",
  413. templateUrl : "static/tpl/index/make/order.html",
  414. controller: 'MakeOrderCtrl'
  415. }).state('make.order', {
  416. url : "/order",
  417. templateUrl : "static/tpl/index/make/order.html",
  418. controller: 'MakeOrderCtrl'
  419. }).state('make.order_detail', {
  420. url : "/order/:id",
  421. templateUrl : "static/tpl/index/make/order_detail.html",
  422. controller: 'MakeOrderDetailCtrl'
  423. }).state('make.change', {
  424. url : "/change",
  425. templateUrl : "static/tpl/index/make/change.html",
  426. controller: 'MakeChangeCtrl'
  427. }).state('make.change_detail', {
  428. url : "/change/:id",
  429. templateUrl : "static/tpl/index/make/change_detail.html",
  430. controller: 'MakeChangeDetailCtrl'
  431. }).state('make.outorder', {
  432. url : "/outorder",
  433. templateUrl : "static/tpl/index/make/outorder.html",
  434. controller: 'MakeOutOrderCtrl'
  435. }).state('make.outorder_detail', {
  436. url : "/outorder/:id",
  437. templateUrl : "static/tpl/index/make/outorder_detail.html",
  438. controller: 'MakeOutOrderDetailCtrl'
  439. }).state('make.accept', {
  440. url : "/accept",
  441. templateUrl : "static/tpl/index/make/accept.html",
  442. controller: 'MakeAcceptCtrl'
  443. }).state('make.returns', {
  444. url : "/returns",
  445. templateUrl : "static/tpl/index/make/returns.html",
  446. controller: 'MakeReturnCtrl'
  447. }).state('cs', {// 客户服务
  448. url : "/cs",
  449. views : {
  450. "left-view" : {
  451. templateUrl : "static/tpl/index/cs/left.html"
  452. },
  453. "right-view" : {
  454. templateUrl : "static/tpl/index/cs/right.html"
  455. }
  456. }
  457. }).state('cs.index', {
  458. url : "",
  459. templateUrl : "static/tpl/index/cs/index.html"
  460. }).state('cs.home', {
  461. url : "/",
  462. templateUrl : "static/tpl/index/cs/index.html"
  463. });
  464. }]);
  465. /**
  466. * 表示符号
  467. */
  468. app.factory('Symbol', function(){
  469. return {
  470. currency: function(cur) {
  471. if(cur == 'RMB') return '¥';
  472. else if(cur == 'USD') return '$';
  473. else if(cur == 'EUR') return '€';
  474. else if(cur == null || cur == '') return '¥';
  475. else return cur;
  476. }
  477. };
  478. }).factory('Lodop',function(){
  479. return {
  480. getLodop:function(oOBJECT,oEMBED){
  481. var CreatedOKLodop7766=null;
  482. /**************************
  483. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  484. IE系列、IE内核系列的浏览器采用oOBJECT,
  485. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  486. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  487. 64位浏览器指向64位的安装程序install_lodop64.exe。
  488. **************************/
  489. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  490. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  491. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  492. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  493. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  494. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  495. var LODOP;
  496. try{
  497. //=====判断浏览器类型:===============
  498. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  499. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  500. //=====如果页面有Lodop就直接使用,没有则新建:==========
  501. if (oOBJECT!=undefined || oEMBED!=undefined) {
  502. if (isIE)
  503. LODOP=oOBJECT;
  504. else
  505. LODOP=oEMBED;
  506. } else {
  507. if (CreatedOKLodop7766==null){
  508. LODOP=document.createElement("object");
  509. LODOP.setAttribute("width",0);
  510. LODOP.setAttribute("height",0);
  511. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  512. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  513. else LODOP.setAttribute("type","application/x-print-lodop");
  514. document.documentElement.appendChild(LODOP);
  515. CreatedOKLodop7766=LODOP;
  516. } else
  517. LODOP=CreatedOKLodop7766;
  518. };
  519. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  520. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  521. if (navigator.userAgent.indexOf('Chrome')>=0)
  522. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  523. if (navigator.userAgent.indexOf('Firefox')>=0)
  524. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  525. if (is64IE) document.write(strHtm64_Install); else
  526. if (isIE) document.write(strHtmInstall); else
  527. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  528. return LODOP;
  529. } else
  530. if (LODOP.VERSION<"6.1.9.8") {
  531. if (is64IE) document.write(strHtm64_Update); else
  532. if (isIE) document.write(strHtmUpdate); else
  533. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  534. return LODOP;
  535. };
  536. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  537. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  538. //============================================================
  539. return LODOP;
  540. } catch(err) {
  541. if (is64IE)
  542. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  543. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  544. return LODOP;
  545. };
  546. }
  547. }
  548. });
  549. app.controller('MyCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  550. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  551. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  552. if (routeState.indexOf('/') > -1)
  553. routeState = routeState.substring(0, routeState.indexOf('/'));
  554. if (routeState.indexOf('.') > -1)
  555. routeState = routeState.substring(0, routeState.indexOf('.'));
  556. $scope.routeState = routeState || 'home';
  557. });
  558. }]);
  559. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  560. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  561. //手机号码格式验证
  562. // var checkTel = function(data){
  563. // var userTel = data.userTel;
  564. // $scope.checkResult = false;
  565. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  566. // if(!(telephone).test(userTel)){
  567. // var modalInstance = $modal.open({
  568. // animation: true,
  569. // templateUrl: 'static/tpl/index/account/checkTel.html',
  570. // controller: 'CheckTelCtrl',
  571. // backdrop: 'static',
  572. // keyboard: false,
  573. // resolve: {
  574. // user: function(){
  575. // return data;
  576. // },
  577. // }
  578. // });
  579. // modalInstance.result.then(function(){
  580. // }, function(){
  581. //
  582. // });
  583. // } else {
  584. // $scope.checkResult = true;
  585. // }
  586. // };
  587. AuthenticationService.getAuthentication().success(function(data) {
  588. if(data.enterprises) {
  589. data.enterprise = data.enterprises[data.enterprises.length - 1];
  590. if(data.enterprises.length > 1) {
  591. var enSelect = [];
  592. angular.forEach(data.enterprises, function(e){
  593. if(e.current)
  594. data.enterprise = e;
  595. else
  596. enSelect.push(e);
  597. });
  598. data.enSelect = enSelect;
  599. }
  600. }
  601. $scope.userInfo = data;
  602. if (data == null || !data.userUU) {
  603. $scope.isAuthed = false;
  604. AuthenticationService.redirectSignin();
  605. } else {
  606. //跳转到手机号码验证
  607. // checkTel($scope.userInfo);
  608. }
  609. });
  610. $scope.logout = function() {
  611. AuthenticationService.logout();
  612. };
  613. $scope.switchto = function(enUU) {// 切换企业
  614. AuthenticationService.reSignin(enUU).success(function(){
  615. $window.location.reload();
  616. });
  617. };
  618. $scope.addFavorite = function(){
  619. var url = encodeURI(window.location.href);
  620. try{
  621. //ie浏览器收藏方式
  622. window.external.addFavorite(url, "优软商务平台");
  623. }catch(e) {
  624. try{
  625. //火狐浏览器收藏方式
  626. window.sidebar.addPanel("优软商务平台", url);
  627. }catch (e) {
  628. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  629. "或手动在浏览器里进行设置。");
  630. }
  631. }
  632. };
  633. }]);
  634. app.controller('TodoCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  635. SnapshotService.getTodo(function(data){
  636. $scope.todo = data;
  637. });
  638. }]);
  639. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  640. SaleTruck.query({}, function(data){
  641. $rootScope.truck = data;
  642. $scope.truckCount = data ? data.length : 0;
  643. });
  644. $scope.$watch(function(){
  645. return $rootScope.truck;
  646. }, function(data) {
  647. $scope.truckCount = data ? data.length : 0;
  648. }, true);
  649. $scope.clearAll = function() {
  650. SaleTruck.remove({}, function(){
  651. $rootScope.truck = [];
  652. });
  653. };
  654. $scope.openTrack = function() {
  655. $modal.open({
  656. templateUrl: 'static/tpl/index/sale/track.html',
  657. controller: 'TruckModalCtrl',
  658. size: 'lg'
  659. }).result.then(function(s){
  660. if(s) {
  661. $scope.clearAll();
  662. $rootScope.dataChanged = true;
  663. }
  664. });
  665. };
  666. }]);
  667. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  668. $scope.saleSend = {sendItems: []};
  669. SaleTruck.detail({}, function(data){
  670. // 按物料编号排序
  671. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  672. });
  673. $scope.remove = function(index, notice) {
  674. SaleTruck.remove({noticeId: notice.id}, function(data){
  675. $rootScope.truck = data;
  676. $scope.notices.splice(index, 1);
  677. });
  678. };
  679. $scope.$watch(function(){
  680. return $scope.notices;
  681. }, function(data) {
  682. var q = 0, t = 0;
  683. if(data) {
  684. angular.forEach(data,function(d){
  685. q += d.thisSendQty;
  686. t += d.thisSendQty * d.orderItem.price;
  687. });
  688. }
  689. $scope.totalQty = q;
  690. $scope.total = t;
  691. }, true);
  692. $scope.cancel = function() {
  693. $modalInstance.close();
  694. };
  695. $scope.send = function() {// 发货
  696. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  697. toaster.pop('error', '错误', '请输入送货单号');
  698. return;
  699. }
  700. var currency = $scope.notices[0].orderItem.order.currency,
  701. custUU = $scope.notices[0].enUU,
  702. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  703. var num = 1;
  704. for(var i in $scope.notices) {
  705. var item = $scope.notices[i];
  706. if(item.id) {
  707. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  708. valid = false;
  709. break;
  710. }
  711. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  712. }
  713. }
  714. if(!valid) {
  715. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  716. } else {
  717. var send = angular.extend(angular.copy($scope.saleSend), {
  718. currency: currency,
  719. custUU: custUU,
  720. payments: payments,
  721. sendItems: items
  722. });
  723. PurcNotice.sendByBatch({}, send, function(data){
  724. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  725. $modalInstance.close(true);
  726. $state.go('sale.send_detail', {id: data.id});
  727. }, function(response){
  728. toaster.pop('error', '错误', response.data);
  729. });
  730. }
  731. };
  732. }]);
  733. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  734. SaleStat.cust({}, function(data){
  735. var p = [], q = [];
  736. angular.forEach(data.month, function(d){
  737. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  738. });
  739. angular.forEach(data.year, function(d){
  740. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  741. });
  742. $scope.custCharts = {
  743. month : {
  744. chartType : 'pie',
  745. datas : {
  746. data : p
  747. },
  748. config : {
  749. labels : false,
  750. title : "客户月采购量排行榜",
  751. legend : {
  752. display : true,
  753. position : 'right'
  754. },
  755. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  756. click : function(d) {
  757. },
  758. mouseover : function(d) {
  759. },
  760. mouseout : function(d) {
  761. },
  762. innerRadius : 0,
  763. lineLegend : 'lineEnd'
  764. }
  765. },
  766. year : {
  767. chartType : 'pie',
  768. datas : {
  769. data : q
  770. },
  771. config : {
  772. labels : false,
  773. title : "客户年采购量排行榜",
  774. legend : {
  775. display : true,
  776. position : 'right'
  777. },
  778. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  779. click : function(d) {
  780. },
  781. mouseover : function(d) {
  782. },
  783. mouseout : function(d) {
  784. },
  785. innerRadius : 0,
  786. lineLegend : 'lineEnd'
  787. }
  788. }
  789. };
  790. });
  791. SaleStat.seller({}, function(data){
  792. var p = [], q = [];
  793. angular.forEach(data.month, function(d){
  794. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  795. });
  796. angular.forEach(data.year, function(d){
  797. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  798. });
  799. $scope.sellerCharts = {
  800. month : {
  801. chartType : 'pie',
  802. datas : {
  803. data : p
  804. },
  805. config : {
  806. labels : false,
  807. title : "业务员月销量排行榜",
  808. legend : {
  809. display : true,
  810. position : 'right'
  811. },
  812. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  813. click : function(d) {
  814. },
  815. mouseover : function(d) {
  816. },
  817. mouseout : function(d) {
  818. },
  819. innerRadius : 0,
  820. lineLegend : 'lineEnd'
  821. }
  822. },
  823. year : {
  824. chartType : 'pie',
  825. datas : {
  826. data : q
  827. },
  828. config : {
  829. labels : false,
  830. title : "业务员年销量排行榜",
  831. legend : {
  832. display : true,
  833. position : 'right'
  834. },
  835. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  836. click : function(d) {
  837. },
  838. mouseover : function(d) {
  839. },
  840. mouseout : function(d) {
  841. },
  842. innerRadius : 0,
  843. lineLegend : 'lineEnd'
  844. }
  845. }
  846. };
  847. });
  848. }]);
  849. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  850. SaleStat.get({}, function(data){
  851. var p = [], q = [], r = [];
  852. angular.forEach(data.day, function(d){
  853. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  854. });
  855. angular.forEach(data.month, function(d){
  856. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  857. });
  858. angular.forEach(data.year, function(d){
  859. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  860. });
  861. $scope.charts = {
  862. day : {
  863. chartType : "line",
  864. datas: {
  865. series: ['销售额'],
  866. data: p
  867. },
  868. config : {
  869. "labels": false,
  870. "title": "销售额统计(近15日线)",
  871. "legend": {
  872. "display": true,
  873. "position": "right"
  874. },
  875. colors : [ '#4D9934'],
  876. "innerRadius": 0,
  877. "lineLegend": "lineEnd"
  878. }
  879. },
  880. month: {
  881. chartType : "line",
  882. datas: {
  883. series: ['销售额'],
  884. data: q
  885. },
  886. config : {
  887. "labels": false,
  888. "title": "销售额统计(近12月线)",
  889. "legend": {
  890. "display": true,
  891. "position": "right"
  892. },
  893. colors : [ '#4D9934'],
  894. "innerRadius": 0,
  895. "lineLegend": "lineEnd"
  896. }
  897. },
  898. year: {
  899. chartType : "line",
  900. datas: {
  901. series: ['销售额'],
  902. data: r
  903. },
  904. config : {
  905. "labels": false,
  906. "title": "销售额统计(近10年线)",
  907. "legend": {
  908. "display": true,
  909. "position": "right"
  910. },
  911. colors : [ '#4D9934'],
  912. "innerRadius": 0,
  913. "lineLegend": "lineEnd"
  914. }
  915. }
  916. };
  917. });
  918. }]);
  919. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  920. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  921. $scope.notices = data;
  922. });
  923. $scope.dateTime = new Date();
  924. }]);
  925. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  926. VendorService.getCount(function(date){
  927. $scope.count = date;
  928. });
  929. }]);
  930. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  931. $scope.userInfoResult = true;
  932. AuthenticationService.getAuthentication().success(function(data) {
  933. $scope.loading = false;
  934. $scope.thisUser = data;
  935. });
  936. var getCustInfos = function(custuu) {
  937. if(custuu) {
  938. VendorService.userInfo.query({uu:custuu},null,function(data) {
  939. $scope.custInfos = data;
  940. var getPage = function(page, size){
  941. if($scope.custInfos) {
  942. var result = {};
  943. result.totalCount = $scope.custInfos.length;
  944. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  945. if($scope.custInfos.length % size == 0) {
  946. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  947. }else {
  948. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  949. }
  950. result.first = page == 1;
  951. result.last = page == result.totalPage;
  952. result.page = page;
  953. result.next = page - 0 + 1;
  954. result.pre = page - 1;
  955. return result;
  956. }
  957. }
  958. $scope.userdata = getPage(1,4);
  959. $scope.first = function (){
  960. $scope.userdata = getPage($scope.userdata.pre,4);
  961. }
  962. $scope.last = function (){
  963. $scope.userdata = getPage($scope.userdata.next,4);
  964. }
  965. }, function(response){
  966. $scope.loading = false;
  967. toaster.pop('error', '数据加载失败', response.data);
  968. });
  969. }
  970. }
  971. $scope.addUserInfo = function(customer) {
  972. //TODO
  973. if ($scope.thisUser.sys) {
  974. var modalInstance = $modal.open({
  975. animation: true,
  976. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  977. controller: 'AddUserInfoCtrl',
  978. resolve: {
  979. customer: function() {
  980. return customer;
  981. }
  982. }
  983. });
  984. modalInstance.result.then(function(changed, checked){
  985. if(changed) {
  986. if(checked)
  987. $scope.newUser.roles = checked;
  988. else
  989. loadUsers();
  990. }
  991. });
  992. } else {
  993. toaster.pop('error', '您不是管理员,无权限分配用户!');
  994. }
  995. }
  996. $scope.showUserInfo = function(customer,boo) {
  997. $scope.custInfo = customer;
  998. if(boo) {
  999. getCustInfos(customer.myEnterprise.uu);
  1000. $scope.userInfoResult = true;
  1001. }
  1002. }
  1003. $scope.customerParams = new ngTableParams({
  1004. page : 1,
  1005. count : 10
  1006. }, {
  1007. total : 0,
  1008. counts: [5, 10, 25, 50],
  1009. getData : function($defer, params) {
  1010. $scope.loading = true;
  1011. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  1012. $scope.loading = false;
  1013. if(page) {
  1014. params.total(page.totalElements);
  1015. $defer.resolve(page.content);
  1016. }
  1017. $scope.totalCount = page.totalElements;
  1018. }, function(response){
  1019. $scope.loading = false;
  1020. toaster.pop('error', '数据加载失败', response.data);
  1021. });
  1022. }
  1023. });
  1024. }]);
  1025. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1026. $scope.checkboxes = {
  1027. checked : false
  1028. };
  1029. $scope.loading = true;
  1030. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1031. $scope.userinfos = data;
  1032. $scope.loading = false;
  1033. })
  1034. // 点击勾选全部的复选框
  1035. $scope.checkAll = function() {
  1036. angular.forEach($scope.userinfos, function(item) {
  1037. item.distribute = $scope.checkboxes.checked;
  1038. });
  1039. };
  1040. // 点击其中一个明细的复选框
  1041. $scope.checkOne = function(vendor){
  1042. var result = true;
  1043. angular.forEach($scope.userinfos, function(item) {
  1044. if(item.distribute != true){
  1045. result = false;
  1046. return;
  1047. }
  1048. });
  1049. $scope.checkboxes.checked = result;
  1050. };
  1051. $scope.close = function(save) {
  1052. var chooseResult = [];
  1053. if(save) {
  1054. if(customer.myEnterprise.uu) {
  1055. angular.forEach($scope.userinfos, function(item, i) {
  1056. chooseResult.push(item);
  1057. });
  1058. if(chooseResult.length > 0) {
  1059. $scope.loading = true;
  1060. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1061. $scope.loading = false;
  1062. toaster.pop('success', '提示', '保存成功');
  1063. $modalInstance.close(false);
  1064. }, function(response){
  1065. $scope.loading = false;
  1066. toaster.pop('error', '保存失败', response.data);
  1067. $modalInstance.close(false);
  1068. })
  1069. } else {
  1070. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1071. }
  1072. } else {
  1073. $modalInstance.close(true, $scope.checkboxes.checked);
  1074. }
  1075. } else {
  1076. $modalInstance.close(false);
  1077. }
  1078. };
  1079. }]);
  1080. /**
  1081. * 页面状态按钮过滤
  1082. */
  1083. var getState = function(active) {
  1084. var fn = 'get';
  1085. switch(active) {
  1086. case 'done':
  1087. fn = 'getDone';break;
  1088. case 'todo':
  1089. fn = 'getTodo';break;
  1090. case 'end':
  1091. fn = 'getEnd';break;
  1092. case 'waiting':
  1093. fn = 'getWaiting';break;
  1094. case 'invalid':
  1095. fn = 'getInvalid';break;
  1096. }
  1097. return fn;
  1098. };
  1099. /**
  1100. * 改变单据日期范围
  1101. */
  1102. var getDateCondition = function(zone, condition) {
  1103. var date = new Date();
  1104. if(zone == -1) {
  1105. condition.dateFrom = null;
  1106. condition.dateTo = null;
  1107. } else if(zone == 1) {
  1108. date.setMonth(date.getMonth() - 1);
  1109. condition.dateFrom = date;
  1110. condition.dateTo = new Date();
  1111. } else if (zone == 6) {
  1112. date.setMonth(date.getMonth() - 6);
  1113. condition.dateFrom = date;
  1114. condition.dateTo = new Date();
  1115. } else {
  1116. date.setMonth(date.getMonth() - 6);
  1117. condition.dateFrom = null;
  1118. condition.dateTo = date;
  1119. }
  1120. };
  1121. /**
  1122. * 改变单据交货日期范围
  1123. */
  1124. var getDelveryCondition = function(zone, condition) {
  1125. var date = new Date();
  1126. if(zone == -1) {
  1127. condition.deliveryFrom = null;
  1128. condition.deliveryTo = null;
  1129. } else if(zone == 1) {
  1130. date.setMonth(date.getMonth() + 1);
  1131. condition.deliveryTo = date;
  1132. condition.deliveryFrom = new Date();
  1133. } else if (zone == 2) {
  1134. date.setMonth(date.getMonth() + 2);
  1135. condition.deliveryTo = date;
  1136. condition.deliveryFrom = new Date();
  1137. }
  1138. };
  1139. /**
  1140. * 将日期转化为整数日期
  1141. */
  1142. var getDateTime = function(date) {
  1143. if(angular.isDate(date)) {
  1144. return date.getTime();
  1145. } else {
  1146. return null;
  1147. }
  1148. };
  1149. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1150. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1151. $scope.active = 'todo';
  1152. $scope.dateZoneText = '不限';
  1153. $scope.deliveryZoneText = '不限';
  1154. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1155. $scope.changeDateZone = function(zone) {
  1156. $scope.condition.dateZone = zone;
  1157. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1158. $scope.condition.$dateZoneOpen = false;
  1159. getDateCondition(zone, $scope.condition);
  1160. $scope.tableParams.reload();
  1161. };
  1162. $scope.changeDeliveryZone = function(zone) {
  1163. $scope.condition.deliveryZoneText = zone;
  1164. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1165. $scope.condition.$delievryZoneOpen = false;
  1166. getDelveryCondition(zone, $scope.condition);
  1167. $scope.tableParams.reload();
  1168. };
  1169. // 切换单据类型
  1170. $scope.setActive = function(state) {
  1171. if($scope.active != state) {
  1172. $scope.active = state;
  1173. if($scope.tableParams.page() == 1)
  1174. $scope.tableParams.reload();
  1175. else
  1176. $scope.tableParams.page(1);
  1177. }
  1178. };
  1179. var getPurcStatus = function(active) {
  1180. var fn = 'getPurcAll';
  1181. switch(active) {
  1182. case 'done':
  1183. fn = 'getPurcDone';break;
  1184. case 'todo':
  1185. fn = 'getPurcTodo';break;
  1186. case 'end':
  1187. fn = 'getPurcEnd';break;
  1188. case 'waiting':
  1189. fn = 'getPurcWaiting';break;
  1190. }
  1191. return fn;
  1192. }
  1193. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1194. page : 1,
  1195. count : 5,
  1196. sorting: {
  1197. display: 'desc',
  1198. date: 'desc'
  1199. }
  1200. }, {
  1201. total : 0,
  1202. counts: [5, 10, 15, 25, 50],
  1203. getData : function($defer, params) {// 获取数据的方法
  1204. $scope.loading = true;
  1205. var pageParams = params.url();
  1206. pageParams.searchFilter = { // 筛选条件
  1207. keyword: $scope.keyword,
  1208. fromDate: getDateTime($scope.condition.dateFrom),
  1209. endDate: getDateTime($scope.condition.dateTo)
  1210. };
  1211. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1212. $scope.loading = false;
  1213. if(page) {
  1214. $defer.resolve(page.content);
  1215. params.total(page.totalElement);
  1216. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1217. }
  1218. }, function(response){
  1219. $scope.loading = false;
  1220. toaster.pop('error', '数据加载失败', response.data);
  1221. });
  1222. }
  1223. });
  1224. $scope.getReply = function(item) {
  1225. if(!item.replies) {
  1226. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1227. item.replies = replies;
  1228. });
  1229. }
  1230. };
  1231. $scope.getOrderTotal = function(items) {
  1232. var sum = 0;
  1233. angular.forEach(items, function(item){
  1234. sum += item.qty * item.price;
  1235. });
  1236. return sum;
  1237. };
  1238. $scope.openDatePicker = function($event, item, openParam) {
  1239. $event.preventDefault();
  1240. $event.stopPropagation();
  1241. item[openParam] = !item[openParam];
  1242. };
  1243. $scope.parseDate = function(dateStr) {
  1244. if(dateStr)
  1245. return Date.parse(dateStr, 'yyyy-MM-dd');
  1246. return new Date();
  1247. };
  1248. $scope.checkboxes = {
  1249. checked : false
  1250. };
  1251. // 点击勾选全部的复选框
  1252. $scope.checkAll = function(){
  1253. angular.forEach($scope.tableParams.data, function(item) {
  1254. item.$selected = $scope.checkboxes.checked;
  1255. });
  1256. };
  1257. // 点击其中一个明细的复选框
  1258. $scope.checkOne = function(order){
  1259. var result = true;
  1260. angular.forEach($scope.tableParams.data, function(item) {
  1261. if(item.$selected != true){
  1262. result = false;
  1263. return;
  1264. }
  1265. });
  1266. $scope.checkboxes.checked = result;
  1267. };
  1268. // 搜索框回车
  1269. $scope.onSearch = function() {
  1270. $scope.tableParams.page(1);
  1271. $scope.tableParams.reload();
  1272. };
  1273. // 选择查找日期
  1274. $scope.onDateCondition = function(){
  1275. $scope.tableParams.page(1);
  1276. $scope.tableParams.reload();
  1277. };
  1278. }]);
  1279. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1280. var loadData = function() {
  1281. PurcOrder.get({id: $stateParams.id}, function(data){
  1282. $scope.order = data;
  1283. var sum = 0;
  1284. angular.forEach($scope.order.orderItems, function(item){
  1285. sum += item.qty * item.price;
  1286. });
  1287. $scope.order.total = sum;
  1288. if($scope.order.display == 1) {//未查看的设为已查看
  1289. $scope.setDisplay('setRead', $scope.order.id);
  1290. }
  1291. $scope.loading = false;
  1292. });
  1293. };
  1294. loadData();
  1295. $scope.getReply = function(item) {
  1296. if(!item.replies) {
  1297. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1298. item.replies = replies;
  1299. });
  1300. }
  1301. };
  1302. $scope.openDatePicker = function($event, item, openParam) {
  1303. $event.preventDefault();
  1304. $event.stopPropagation();
  1305. item[openParam] = !item[openParam];
  1306. };
  1307. $scope.onReplyClick = function(item, inverse) {
  1308. if(item.reply) {
  1309. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1310. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1311. return;
  1312. }
  1313. var reply = angular.copy(item.reply);
  1314. if(reply.delivery) {
  1315. if(typeof reply.delivery == 'object')
  1316. reply.delivery = reply.delivery.getTime();
  1317. } else {
  1318. reply.delivery = item.delivery;
  1319. }
  1320. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1321. $scope.loading = true;
  1322. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1323. $scope.loading = false;
  1324. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1325. loadData();
  1326. }, function(response){
  1327. $scope.loading = false;
  1328. toaster.pop('error', '回复失败', response.data);
  1329. });
  1330. }
  1331. };
  1332. // // 采购单
  1333. // $scope.print = function(order) {
  1334. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  1335. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1336. // };
  1337. //设置为已查看
  1338. $scope.setDisplay = function(state, orderId) {
  1339. if(orderId) {//设置单个
  1340. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1341. // $scope.tableParams.reload();
  1342. }, function() {
  1343. toaster.pop('error', '错误', "设置失败");
  1344. });
  1345. } else {//设置已勾选的
  1346. var str = null;
  1347. angular.forEach($scope.tableParams.data, function(order) {
  1348. if(order.$selected == true) {
  1349. if(str != null && str != '') str += ',';
  1350. str += order.id;
  1351. }
  1352. });
  1353. if(str != null && str != '') {
  1354. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1355. $scope.tableParams.reload();
  1356. }, function() {
  1357. toaster.pop('error', '错误', "设置失败");
  1358. });
  1359. }
  1360. }
  1361. };
  1362. }]);
  1363. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  1364. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  1365. $scope.active = 'todo';
  1366. $scope.dateZoneText = '不限';
  1367. $scope.deliveryZoneText = '不限';
  1368. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1369. $scope.changeDateZone = function(zone) {
  1370. $scope.condition.dateZone = zone;
  1371. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1372. $scope.condition.$dateZoneOpen = false;
  1373. getDateCondition(zone, $scope.condition);
  1374. $scope.tableParams.reload();
  1375. };
  1376. $scope.changeDeliveryZone = function(zone) {
  1377. $scope.condition.deliveryZoneText = zone;
  1378. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1379. $scope.condition.$delievryZoneOpen = false;
  1380. getDelveryCondition(zone, $scope.condition);
  1381. $scope.tableParams.reload();
  1382. };
  1383. // 切换单据类型
  1384. $scope.setActive = function(state) {
  1385. if($scope.active != state) {
  1386. $scope.active = state;
  1387. if($scope.tableParams.page() == 1)
  1388. $scope.tableParams.reload();
  1389. else
  1390. $scope.tableParams.page(1);
  1391. }
  1392. };
  1393. // 切换数据来源(正常数据 or 历史数据)
  1394. var getService = function() {
  1395. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  1396. };
  1397. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1398. page : 1,
  1399. count : 5,
  1400. sorting: {
  1401. display: 'desc',
  1402. date: 'desc',
  1403. id: 'desc'
  1404. }
  1405. }, {
  1406. total : 0,
  1407. counts: [5, 10, 15, 25, 50],
  1408. getData : function($defer, params) { // 获取数据的方法
  1409. $scope.loading = true;
  1410. var pageParams = params.url();
  1411. pageParams.searchFilter = { // 筛选条件
  1412. keyword: $scope.keyword,
  1413. fromDate: getDateTime($scope.condition.dateFrom),
  1414. endDate: getDateTime($scope.condition.dateTo)
  1415. };
  1416. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1417. $scope.loading = false;
  1418. if(page) {
  1419. $defer.resolve(page.content);
  1420. params.total(page.totalElement);
  1421. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1422. }
  1423. }, function(response){
  1424. $scope.loading = false;
  1425. toaster.pop('error', '数据加载失败', response.data);
  1426. });
  1427. }
  1428. });
  1429. $scope.getOrderTotal = function(items) {
  1430. var sum = 0;
  1431. angular.forEach(items, function(item){
  1432. sum += item.qty * item.price;
  1433. });
  1434. return sum;
  1435. };
  1436. $scope.openDatePicker = function($event, item, openParam) {
  1437. $event.preventDefault();
  1438. $event.stopPropagation();
  1439. item[openParam] = !item[openParam];
  1440. };
  1441. $scope.parseDate = function(dateStr) {
  1442. if(dateStr)
  1443. return Date.parse(dateStr, 'yyyy-MM-dd');
  1444. return new Date();
  1445. };
  1446. $scope.onReplyClick = function(item, inverse) {
  1447. if(item.reply) {
  1448. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1449. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1450. return;
  1451. }
  1452. var reply = angular.copy(item.reply);
  1453. if(reply.delivery) {
  1454. if(typeof reply.delivery == 'object')
  1455. reply.delivery = reply.delivery.getTime();
  1456. } else {
  1457. reply.delivery = item.delivery;
  1458. }
  1459. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1460. $scope.loading = true;
  1461. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1462. $scope.loading = false;
  1463. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1464. $scope.tableParams.reload();
  1465. }, function(response){
  1466. $scope.loading = false;
  1467. toaster.pop('error', '回复失败', response.data);
  1468. });
  1469. }
  1470. };
  1471. //打印 采购单
  1472. $scope.print = function(order) {
  1473. PurcOrder.printCount({id: order.id},{});//增加打印此次
  1474. console.log(order);
  1475. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  1476. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1477. };
  1478. $scope.getReply = function(item) {
  1479. if(!item.replies) {
  1480. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1481. item.replies = replies;
  1482. });
  1483. }
  1484. };
  1485. $scope.checkboxes = {
  1486. checked : false
  1487. };
  1488. // 点击勾选全部的复选框
  1489. $scope.checkAll = function(){
  1490. angular.forEach($scope.tableParams.data, function(item) {
  1491. item.$selected = $scope.checkboxes.checked;
  1492. });
  1493. };
  1494. // 点击其中一个明细的复选框
  1495. $scope.checkOne = function(order){
  1496. var result = true;
  1497. angular.forEach($scope.tableParams.data, function(item) {
  1498. if(item.$selected != true){
  1499. result = false;
  1500. return;
  1501. }
  1502. });
  1503. $scope.checkboxes.checked = result;
  1504. };
  1505. //批量回复采购订单
  1506. $scope.replyByBatch = function() {
  1507. $scope.loading = true;
  1508. var str = '';
  1509. angular.forEach($scope.tableParams.data, function(order) {
  1510. if(order.$selected == true) {
  1511. angular.forEach(order.orderItems, function(item){
  1512. str += item.id;
  1513. str += ',';
  1514. });
  1515. }
  1516. });
  1517. if(!(str == '')) {
  1518. str = str.substr(0, str.length-1);
  1519. PurcOrderItem.replyByBatch(str, function(){
  1520. $scope.loading = false;
  1521. $scope.tableParams.reload();
  1522. toaster.pop('success', '提示', '批量回复成功');
  1523. }, function(data){
  1524. $scope.loading = false;
  1525. toaster.pop('error', '批量回复失败', data);
  1526. });
  1527. } else {//没有勾选其中的明细
  1528. $scope.loading = false;
  1529. }
  1530. };
  1531. // 搜索框回车
  1532. $scope.onSearch = function() {
  1533. $scope.tableParams.page(1);
  1534. $scope.tableParams.reload();
  1535. };
  1536. // 选择查找日期
  1537. $scope.onDateCondition = function(){
  1538. $scope.tableParams.page(1);
  1539. $scope.tableParams.reload();
  1540. };
  1541. //设置为已查看
  1542. $scope.setDisplay = function(state, orderId) {
  1543. if(orderId) {//设置单个
  1544. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1545. $scope.tableParams.reload();
  1546. }, function() {
  1547. toaster.pop('error', '错误', "设置失败");
  1548. });
  1549. } else {//设置已勾选的
  1550. var str = null;
  1551. angular.forEach($scope.tableParams.data, function(order) {
  1552. if(order.$selected == true) {
  1553. if(str != null && str != '') str += ',';
  1554. str += order.id;
  1555. }
  1556. });
  1557. if(str != null && str != '') {
  1558. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1559. $scope.tableParams.reload();
  1560. }, function() {
  1561. toaster.pop('error', '错误', "设置失败");
  1562. });
  1563. }
  1564. }
  1565. };
  1566. }]);
  1567. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1568. var loadData = function() {
  1569. PurcOrder.get({id: $stateParams.id}, function(data){
  1570. $scope.order = data;
  1571. var sum = 0;
  1572. angular.forEach($scope.order.orderItems, function(item){
  1573. sum += item.qty * item.price;
  1574. });
  1575. $scope.order.total = sum;
  1576. if($scope.order.display == 1) {//未查看的设为已查看
  1577. $scope.setDisplay('setRead', $scope.order.id);
  1578. }
  1579. $scope.loading = false;
  1580. });
  1581. };
  1582. loadData();
  1583. $scope.getReply = function(item) {
  1584. if(!item.replies) {
  1585. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1586. item.replies = replies;
  1587. });
  1588. }
  1589. };
  1590. $scope.openDatePicker = function($event, item, openParam) {
  1591. $event.preventDefault();
  1592. $event.stopPropagation();
  1593. item[openParam] = !item[openParam];
  1594. };
  1595. $scope.onReplyClick = function(item, inverse) {
  1596. if(item.reply) {
  1597. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1598. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1599. return;
  1600. }
  1601. var reply = angular.copy(item.reply);
  1602. if(reply.delivery) {
  1603. if(typeof reply.delivery == 'object')
  1604. reply.delivery = reply.delivery.getTime();
  1605. } else {
  1606. reply.delivery = item.delivery;
  1607. }
  1608. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1609. $scope.loading = true;
  1610. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1611. $scope.loading = false;
  1612. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1613. loadData();
  1614. }, function(response){
  1615. $scope.loading = false;
  1616. toaster.pop('error', '回复失败', response.data);
  1617. });
  1618. }
  1619. };
  1620. // 采购单
  1621. $scope.print = function(order) {
  1622. PurcOrder.printCount({id: order.id},{});//增加打印此次
  1623. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1624. };
  1625. //设置为已查看
  1626. $scope.setDisplay = function(state, orderId) {
  1627. if(orderId) {//设置单个
  1628. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  1629. $scope.tableParams.reload();
  1630. }, function() {
  1631. toaster.pop('error', '错误', "设置失败");
  1632. });
  1633. } else {//设置已勾选的
  1634. var str = null;
  1635. angular.forEach($scope.tableParams.data, function(order) {
  1636. if(order.$selected == true) {
  1637. if(str != null && str != '') str += ',';
  1638. str += order.id;
  1639. }
  1640. });
  1641. if(str != null && str != '') {
  1642. PurcOrder[state].call({}, {ids: '' + str}, function(){
  1643. $scope.tableParams.reload();
  1644. }, function() {
  1645. toaster.pop('error', '错误', "设置失败");
  1646. });
  1647. }
  1648. }
  1649. };
  1650. }]);
  1651. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  1652. $scope.active = 'todo';
  1653. $scope.agreedText = '全部';
  1654. $scope.dateZoneText = '一个月内';
  1655. $scope.condition = {dateZone: 1};
  1656. $scope.changeAgreed = function(agreed) {
  1657. $scope.condition.agreed = agreed;
  1658. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  1659. $scope.condition.$agreedOpen = false;
  1660. };
  1661. $scope.changeDateZone = function(zone) {
  1662. $scope.condition.dateZone = zone;
  1663. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1664. $scope.condition.$dateZoneOpen = false;
  1665. };
  1666. $scope.setActive = function(state) {
  1667. if($scope.active != state) {
  1668. $scope.active = state;
  1669. if($scope.tableParams.page() == 1)
  1670. $scope.tableParams.reload();
  1671. else
  1672. $scope.tableParams.page(1);
  1673. }
  1674. };
  1675. var getService = function() {
  1676. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  1677. };
  1678. $scope.tableParams = new ngTableParams({
  1679. page : 1,
  1680. count : 5,
  1681. sorting: {
  1682. date: 'desc'
  1683. }
  1684. }, {
  1685. total : 0,
  1686. counts: [5, 10, 25, 50],
  1687. getData : function($defer, params) {
  1688. $scope.loading = true;
  1689. var pageParams = params.url();
  1690. pageParams.keyword = $scope.keyword;
  1691. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1692. $scope.loading = false;
  1693. if(page) {
  1694. params.total(page.totalElement);
  1695. $defer.resolve(page.content);
  1696. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1697. }
  1698. }, function(response){
  1699. $scope.loading = false;
  1700. toaster.pop('error', '数据加载失败', response.data);
  1701. });
  1702. }
  1703. });
  1704. $scope.openDatePicker = function($event, item, openParam) {
  1705. $event.preventDefault();
  1706. $event.stopPropagation();
  1707. item[openParam] = !item[openParam];
  1708. };
  1709. $scope.onReplyClick = function(change) {
  1710. if(change.$agreed) {
  1711. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1712. $scope.loading = true;
  1713. PurcChange.reply({changeId: change.id}, reply, function(){
  1714. $scope.loading = false;
  1715. toaster.pop('info', '提示', '回复成功');
  1716. $scope.tableParams.reload();
  1717. }, function(response){
  1718. $scope.loading = false;
  1719. toaster.pop('error', '回复失败', response.data);
  1720. });
  1721. }
  1722. };
  1723. // 搜索框回车
  1724. $scope.onSearch = function() {
  1725. $scope.tableParams.page(1);
  1726. $scope.tableParams.reload();
  1727. };
  1728. }]);
  1729. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  1730. var loadData = function() {
  1731. PurcChange.get({id: $stateParams.id}, function(data){
  1732. $scope.change = data;
  1733. });
  1734. };
  1735. loadData();
  1736. $scope.openDatePicker = function($event, item, openParam) {
  1737. $event.preventDefault();
  1738. $event.stopPropagation();
  1739. item[openParam] = !item[openParam];
  1740. };
  1741. $scope.onReplyClick = function(change) {
  1742. if(change.$agreed) {
  1743. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1744. PurcChange.reply({changeId: change.id}, reply, function(){
  1745. toaster.pop('info', '提示', '回复成功');
  1746. loadData();
  1747. }, function(response){
  1748. toaster.pop('error', '回复失败', response.data);
  1749. });
  1750. }
  1751. };
  1752. }]);
  1753. //采购询价
  1754. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  1755. $scope.active = 'todo';
  1756. $scope.agreedText = '全部';
  1757. $scope.dateZoneText = '一个月内';
  1758. $scope.condition = {dateZone: 1};
  1759. $scope.changeAgreed = function(agreed) {
  1760. $scope.condition.agreed = agreed;
  1761. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  1762. $scope.condition.$agreedOpen = false;
  1763. };
  1764. $scope.changeDateZone = function(zone) {
  1765. $scope.condition.dateZone = zone;
  1766. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1767. $scope.condition.$dateZoneOpen = false;
  1768. };
  1769. $scope.setActive = function(state) {
  1770. if($scope.active != state) {
  1771. $scope.active = state;
  1772. if($scope.tableParams.page() == 1)
  1773. $scope.tableParams.reload();
  1774. else
  1775. $scope.tableParams.page(1);
  1776. }
  1777. };
  1778. var getService = function() {
  1779. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  1780. };
  1781. $scope.tableParams = new ngTableParams({
  1782. page : 1,
  1783. count : 5,
  1784. sorting: {
  1785. 'inquiry.date': 'desc',
  1786. 'inquiry.enterprise.enName': 'asc',
  1787. 'inquiry.code': 'asc'
  1788. }
  1789. }, {
  1790. total : 0,
  1791. counts: [5, 10, 25, 50],
  1792. getData : function($defer, params) {
  1793. $scope.loading = true;
  1794. var pageParams = params.url();
  1795. var realActive = {};
  1796. pageParams.keyword = $scope.keyword;
  1797. if ($scope.active == 'overdue') {
  1798. $scope.active = 'end';
  1799. }
  1800. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1801. $scope.loading = false;
  1802. if(page) {
  1803. params.total(page.totalElement);
  1804. $defer.resolve(page.content);
  1805. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1806. }
  1807. }, function(response){
  1808. $scope.loading = false;
  1809. toaster.pop('error', '数据加载失败', response.data);
  1810. });
  1811. }
  1812. });
  1813. $scope.getMinDate = function(item) {
  1814. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  1815. };
  1816. $scope.replyPrices = [];
  1817. $scope.replylapQtys = [];
  1818. $scope.replyPrices.push(true);
  1819. $scope.replylapQtys.push(true);
  1820. $scope.addStep = function(inquiryItem) {
  1821. $scope.replyPrices.push(true);
  1822. if(inquiryItem.replies.length >= 10) {
  1823. toaster.pop('warning', '提示', '最多支持10个分段!');
  1824. } else {
  1825. inquiryItem.replies.push({});
  1826. if(inquiryItem.replies.length != 1) {
  1827. $scope.replyPrices.push(true);
  1828. $scope.replylapQtys.push(true);
  1829. }
  1830. }
  1831. };
  1832. $scope.removeStep = function(inquiryItem, stepIndex) {
  1833. inquiryItem.replies.splice(stepIndex, 1);
  1834. $scope.replyPrices.splice(stepIndex, 1);
  1835. $scope.replylapQtys.splice(stepIndex, 1);
  1836. };
  1837. $scope.openDatePicker = function($event, item, openParam) {
  1838. $event.preventDefault();
  1839. $event.stopPropagation();
  1840. item[openParam] = !item[openParam];
  1841. };
  1842. $scope.getHistory = function(item) {
  1843. if(!item.history) {
  1844. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1845. item.history = data;
  1846. });
  1847. }
  1848. };
  1849. $scope.isValid = function(item, withSteps) {
  1850. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1851. if(!withSteps || !bool)
  1852. return bool;
  1853. angular.forEach(item.replies, function(r, i){
  1854. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1855. });
  1856. return bool;
  1857. };
  1858. $scope.onReplyClick = function(item, withSteps) {
  1859. if(item.vendFromDate instanceof Date) {
  1860. item.vendFromDate = item.vendFromDate.getTime();
  1861. }
  1862. if(item.vendToDate instanceof Date) {
  1863. item.vendToDate = item.vendToDate.getTime();
  1864. }
  1865. if(item.vendFromDate > item.vendToDate) {
  1866. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  1867. return;
  1868. }
  1869. var replies = [];
  1870. angular.forEach(item.replies, function(r, i){
  1871. if((i > 0 ? r.lapQty : 1) || r.price)
  1872. replies.push(r);
  1873. });
  1874. item.replies = replies;
  1875. $scope.loading = true;
  1876. if(withSteps) {
  1877. PurcInquiry.reply({itemId: item.id}, item, function(){
  1878. $scope.loading = false;
  1879. toaster.pop('info', '提示', '报价成功');
  1880. $scope.tableParams.reload();
  1881. }, function(response){
  1882. $scope.loading = false;
  1883. toaster.pop('error', '报价失败', response.data);
  1884. });
  1885. } else {
  1886. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  1887. $scope.loading = false;
  1888. toaster.pop('info', '提示', '保存成功');
  1889. $scope.tableParams.reload();
  1890. }, function(response){
  1891. $scope.loading = false;
  1892. toaster.pop('error', '保存失败', response.data);
  1893. });
  1894. }
  1895. };
  1896. $scope.verifylapQty = function(value,type) {
  1897. var regex = /^\d+(.\d{1,5})?$/;
  1898. $scope.replylapQtys[type] = regex.test(value);
  1899. }
  1900. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  1901. $scope.verify = function(value,type) {
  1902. var regex = /^\d+(.\d{1,5})?$/;//
  1903. switch(type) {
  1904. case 'minOrderQty':
  1905. $scope.minOrderQtyVerify = regex.test(value);
  1906. break;
  1907. case 'minPackQty':
  1908. $scope.minPackQtyVerify = regex.test(value);
  1909. break;
  1910. case 'leadtime':
  1911. $scope.leadtimeVerify = regex.test(value);
  1912. break;
  1913. default:
  1914. $scope.replyPrices[type] = regex.test(value);
  1915. break;
  1916. }
  1917. }
  1918. // 搜索框回车
  1919. $scope.onSearch = function() {
  1920. $scope.tableParams.page(1);
  1921. $scope.tableParams.reload();
  1922. };
  1923. }]);
  1924. // 询价单明细
  1925. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  1926. var loadData = function() {
  1927. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  1928. $scope.newinquiryItems = data;
  1929. var inquiry = data[0].inquiry;
  1930. //inquiry.inquiryItems = data;
  1931. angular.forEach(inquiry.attachs, function(attach){
  1932. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  1933. });
  1934. $scope.inquiry = inquiry;
  1935. });
  1936. };
  1937. loadData();
  1938. $scope.getMinDate = function(item) {
  1939. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  1940. };
  1941. $scope.addStep = function(inquiryItem) {
  1942. if(inquiryItem.replies.length >= 10) {
  1943. toaster.pop('warning', '提示', '最多支持10个分段!');
  1944. } else
  1945. inquiryItem.replies.push({});
  1946. };
  1947. $scope.removeStep = function(inquiryItem, stepIndex) {
  1948. inquiryItem.replies.splice(stepIndex, 1);
  1949. };
  1950. $scope.openDatePicker = function($event, item, openParam) {
  1951. $event.preventDefault();
  1952. $event.stopPropagation();
  1953. item[openParam] = !item[openParam];
  1954. };
  1955. $scope.getHistory = function(item) {
  1956. if(!item.history) {
  1957. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1958. item.history = data;
  1959. });
  1960. }
  1961. };
  1962. $scope.isValid = function(item, withSteps) {
  1963. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1964. if(!withSteps || !bool)
  1965. return bool;
  1966. angular.forEach(item.replies, function(r, i){
  1967. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1968. });
  1969. return bool;
  1970. };
  1971. $scope.onReplyClick = function(item, withSteps) {
  1972. if(item.vendFromDate instanceof Date) {
  1973. item.vendFromDate = item.vendFromDate.getTime();
  1974. }
  1975. if(item.vendToDate instanceof Date) {
  1976. item.vendToDate = item.vendToDate.getTime();
  1977. }
  1978. if(item.vendFromDate > item.vendToDate) {
  1979. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  1980. return;
  1981. }
  1982. var replies = [];
  1983. angular.forEach(item.replies, function(r, i){
  1984. if((i > 0 ? r.lapQty : 1) || r.price)
  1985. replies.push(r);
  1986. });
  1987. item.replies = replies;
  1988. if(withSteps) {
  1989. PurcInquiry.reply({itemId: item.id}, item, function(){
  1990. toaster.pop('info', '提示', '报价成功');
  1991. loadData();
  1992. }, function(response){
  1993. toaster.pop('error', '报价失败', response.data);
  1994. });
  1995. }
  1996. };
  1997. }]);
  1998. // 模具询价管理
  1999. //TODO
  2000. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  2001. $scope.active = 'todo';
  2002. $scope.agreedText = '全部';
  2003. $scope.dateZoneText = '一个月内';
  2004. $scope.condition = {dateZone: 1};
  2005. var inquiryMould_copy = {};
  2006. $scope.changeAgreed = function(agreed) {
  2007. $scope.condition.agreed = agreed;
  2008. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2009. $scope.condition.$agreedOpen = false;
  2010. };
  2011. $scope.changeDateZone = function(zone) {
  2012. $scope.condition.dateZone = zone;
  2013. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2014. $scope.condition.$dateZoneOpen = false;
  2015. };
  2016. $scope.setActive = function(state) {
  2017. if($scope.active != state ) {
  2018. $scope.active = state;
  2019. if ($scope.tableParams.page() == 1) {
  2020. $scope.tableParams.reload();
  2021. } else {
  2022. $scope.tableParams.page(1);
  2023. }
  2024. }
  2025. }
  2026. var getService = function() {
  2027. return PurcInquiryMould;
  2028. };
  2029. $scope.tableParams = new ngTableParams({
  2030. page: 1,
  2031. count: 5
  2032. },{
  2033. total: 0,
  2034. counts: [5, 10, 25, 50],
  2035. getData: function($defer, params) {
  2036. $scope.loading = true;
  2037. var pageParams = params.url();
  2038. var realActive = {};
  2039. pageParams.keyword = $scope.keyword;
  2040. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2041. $scope.loading = false;
  2042. // 用来验证价格修改
  2043. var mould = page.content;
  2044. inquiryMould_copy = angular.copy(mould);
  2045. if(page) {
  2046. params.total(page.totalElement);
  2047. $defer.resolve(page.content);
  2048. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2049. }
  2050. }, function(response){
  2051. $scope.loading = false;
  2052. toaster.pop('error', '数据加载失败', response.data);
  2053. });
  2054. }
  2055. })
  2056. $scope.getMinDate = function(item) {
  2057. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  2058. };
  2059. $scope.replyPrices = [];
  2060. $scope.replyPrices.push(true);
  2061. // 取消
  2062. $scope.reload = function() {
  2063. $scope.tableParams.reload();
  2064. $scope.canSave = false;
  2065. }
  2066. // 能否保存设置
  2067. $scope.canSave = false;
  2068. // items价格验证
  2069. $scope.verifyItems = function(price, reply) {
  2070. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  2071. if(regex.test(price) && price != 0) {
  2072. if (price != reply) {
  2073. $scope.canSave = true;
  2074. } else {
  2075. $scope.canSave = false;
  2076. }
  2077. } else {
  2078. $scope.canSave = false;
  2079. }
  2080. }
  2081. // prod下prods价格验证
  2082. $scope.verifyProds = function(price, reply) {
  2083. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2084. if(regex.test(price) && price != 0) {
  2085. if (price != reply) {
  2086. $scope.canSave = true;
  2087. } else {
  2088. $scope.canSave = false;
  2089. }
  2090. } else {
  2091. $scope.canSave = false;
  2092. }
  2093. }
  2094. //有价格为0或者不符合正则式,则不能报价
  2095. $scope.notZero = function (mould) {
  2096. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2097. angular.forEach(mould.inquiryMouldItems, function(item){
  2098. if (item.price == 0 || !regex.test(item.price)) {
  2099. $scope.canSave = false;
  2100. }
  2101. angular.forEach(item.inquiryMouldDetails, function(detail){
  2102. if (detail.price == 0 || !regex.test(detail.price)) {
  2103. $scope.canSave = false;
  2104. }
  2105. })
  2106. });
  2107. }
  2108. $scope.blurPrice = function (price) {
  2109. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2110. if (!regex.test(price)) {
  2111. toaster.pop('warning','格式错误','请输入有效价格');
  2112. }
  2113. }
  2114. // 获取历史报价
  2115. $scope.getHistory = function(mould) {
  2116. if(!mould.history) {
  2117. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  2118. mould.history = data;
  2119. console.log(mould.history);
  2120. });
  2121. }
  2122. };
  2123. $scope.uploadAttach = function(mould) {
  2124. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2125. var file = mould.attachs[0];
  2126. $scope.mould = mould;
  2127. $upload.upload({
  2128. url: 'sale/mould/' + mould.id + '/send',
  2129. method: 'POST',
  2130. file: file,
  2131. data: {
  2132. json: $scope.mould
  2133. }
  2134. }).success(function(res){
  2135. console.log("success");
  2136. console.log(res);
  2137. }).error(function(res){
  2138. console.log("failure");
  2139. console.log(res);
  2140. });
  2141. }
  2142. // 保存并确认报价
  2143. $scope.onReplyClick = function(mould, withSteps) {
  2144. $scope.loading = true;
  2145. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2146. // var file = mould.attachs[0];
  2147. // $scope.mould = mould;
  2148. // $upload.upload({
  2149. // url: 'sale/mould/' + mould.id + '/send',
  2150. // method: 'POST',
  2151. // file: file,
  2152. // data: {
  2153. // json: $scope.mould
  2154. // }
  2155. // }).success(function(res){
  2156. // console.log("success");
  2157. // console.log(res);
  2158. // }).error(function(res){
  2159. // console.log("failure");
  2160. // });
  2161. if(withSteps) {
  2162. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  2163. $scope.loading = false;
  2164. toaster.pop('info', '提示', '报价成功');
  2165. $scope.tableParams.reload();
  2166. $scope.canSave = false;
  2167. }, function(response){
  2168. $scope.loading = false;
  2169. toaster.pop('error', '报价失败', response.data);
  2170. });
  2171. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  2172. }, function(response){
  2173. });
  2174. } else {
  2175. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  2176. $scope.loading = false;
  2177. toaster.pop('info', '提示', '保存成功');
  2178. $scope.tableParams.reload();
  2179. }, function(response){
  2180. $scope.loading = false;
  2181. toaster.pop('error', '保存失败', response.data);
  2182. });
  2183. }
  2184. };
  2185. // 搜索框回车
  2186. $scope.onSearch = function() {
  2187. $scope.tableParams.page(1);
  2188. $scope.tableParams.reload();
  2189. };
  2190. }]);
  2191. //TODO 模具询价单明细
  2192. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  2193. var inquiryMould_copy = {};
  2194. var loadData = function() {
  2195. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  2196. // 用来验证价格修改
  2197. inquiryMould_copy = angular.copy(data);
  2198. $scope.inquiryMould_copy = inquiryMould_copy;
  2199. $scope.newinquirymould = data;
  2200. var mould = data;
  2201. angular.forEach(mould.attachs, function(attach){
  2202. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2203. });
  2204. $scope.inquiryMould = mould;
  2205. });
  2206. };
  2207. loadData();
  2208. $scope.getMinDate = function(item) {
  2209. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2210. };
  2211. // 取消
  2212. $scope.reload = function() {
  2213. loadData();
  2214. $scope.canSave = false;
  2215. }
  2216. //有价格为0,则不能报价
  2217. $scope.notZero = function (mould) {
  2218. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2219. angular.forEach(mould.inquiryMouldItems, function(item){
  2220. if (item.price == 0 || !regex.test(item.price)) {
  2221. $scope.canSave = false;
  2222. }
  2223. angular.forEach(item.inquiryMouldDetails, function(detail){
  2224. if (detail.price == 0 || !regex.test(detail.price)) {
  2225. $scope.canSave = false;
  2226. }
  2227. })
  2228. });
  2229. }
  2230. $scope.blurPrice = function (price) {
  2231. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  2232. if (!regex.test(price)) {
  2233. toaster.pop('warning','格式错误','请输入有效价格');
  2234. }
  2235. }
  2236. // 获取历史报价
  2237. $scope.getHistory = function(mould) {
  2238. if(!mould.history) {
  2239. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  2240. mould.history = data;
  2241. console.log(mould.history);
  2242. });
  2243. }
  2244. };
  2245. $scope.canSave = false;
  2246. // items价格验证
  2247. $scope.verifyItems = function(price, index) {
  2248. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2249. if(regex.test(price) && price != 0) {
  2250. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  2251. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  2252. $scope.canSave = true;
  2253. } else {
  2254. $scope.canSave = false;
  2255. }
  2256. } else {
  2257. $scope.canSave = false;
  2258. }
  2259. }
  2260. // prod下prods价格验证
  2261. $scope.verifyProds = function(price, index, parentIndex) {
  2262. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  2263. if(regex.test(price) && price != 0) {
  2264. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  2265. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  2266. $scope.canSave = true;
  2267. } else {
  2268. $scope.canSave = false;
  2269. }
  2270. } else {
  2271. $scope.canSave = false;
  2272. }
  2273. }
  2274. // // 上传附件
  2275. // $scope.uploadAttach = function(mould) {
  2276. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  2277. // var file = mould.attachs[0];
  2278. // $scope.mould = mould;
  2279. // $upload.upload({
  2280. // url: 'sale/mould/' + mould.id + '/send',
  2281. // method: 'POST',
  2282. // file: file,
  2283. // data: {
  2284. // json: $scope.mould
  2285. // }
  2286. // }).success(function(res){
  2287. // console.log("success");
  2288. // console.log(res);
  2289. // }).error(function(res){
  2290. // console.log("failure");
  2291. // console.log(res);
  2292. // });
  2293. // }
  2294. $scope.onReplyClick = function(mould, withSteps) {
  2295. $scope.loading = true;
  2296. // var file = mould.attachs[0];
  2297. // $scope.mould = mould;
  2298. // $upload.upload({
  2299. // url: 'sale/mould/' + mould.id + '/send',
  2300. // method: 'POST',
  2301. // file: file,
  2302. // data: {
  2303. // json: $scope.mould
  2304. // }
  2305. // }).success(function(res){
  2306. //
  2307. // }).error(function(res){
  2308. // console.log(res);
  2309. // });
  2310. if(withSteps) {
  2311. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  2312. $scope.loading = false;
  2313. toaster.pop('info', '提示', '报价成功');
  2314. loadData();
  2315. $scope.canSave = false;
  2316. }, function(response){
  2317. $scope.loading = false;
  2318. toaster.pop('error', '报价失败', response.data);
  2319. });
  2320. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  2321. }, function(response){
  2322. });
  2323. } else {
  2324. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  2325. $scope.loading = false;
  2326. toaster.pop('info', '提示', '保存成功');
  2327. loadData();
  2328. }, function(response){
  2329. $scope.loading = false;
  2330. toaster.pop('error', '保存失败', response.data);
  2331. });
  2332. }
  2333. };
  2334. }]);
  2335. // 主动报价 - 列表
  2336. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  2337. $scope.active = 'todo';
  2338. $scope.agreedText = '全部';
  2339. $scope.dateZoneText = '一个月内';
  2340. $scope.condition = {dateZone: 1};
  2341. $scope.changeDateZone = function(zone) {
  2342. $scope.condition.dateZone = zone;
  2343. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2344. $scope.condition.$dateZoneOpen = false;
  2345. };
  2346. $scope.setActive = function(state) {
  2347. if($scope.active != state) {
  2348. $scope.active = state;
  2349. if($scope.tableParams.page() == 1)
  2350. $scope.tableParams.reload();
  2351. else
  2352. $scope.tableParams.page(1);
  2353. }
  2354. };
  2355. var getService = function() {
  2356. return Quotation;
  2357. };
  2358. $scope.tableParams = new ngTableParams({
  2359. page : 1,
  2360. count : 5,
  2361. sorting: {
  2362. 'quotation.date': 'desc'
  2363. }
  2364. }, {
  2365. total : 0,
  2366. counts: [5, 10, 25, 50],
  2367. getData : function($defer, params) {
  2368. $scope.loading = true;
  2369. var pageParams = params.url();
  2370. pageParams.keyword = $scope.keyword;
  2371. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2372. $scope.loading = false;
  2373. if(page) {
  2374. params.total(page.totalElement);
  2375. $defer.resolve(page.content);
  2376. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2377. }
  2378. }, function(response){
  2379. $scope.loading = false;
  2380. toaster.pop('error', '数据加载失败', response.data);
  2381. });
  2382. }
  2383. });
  2384. $scope.getHistory = function(item) {
  2385. if(!item.history) {
  2386. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2387. item.history = data;
  2388. });
  2389. }
  2390. };
  2391. $scope.isValid = function(item, withSteps) {
  2392. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2393. if(!withSteps || !bool)
  2394. return bool;
  2395. angular.forEach(item.replies, function(r, i){
  2396. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2397. });
  2398. return bool;
  2399. };
  2400. // 搜索框回车
  2401. $scope.onSearch = function() {
  2402. $scope.tableParams.page(1);
  2403. $scope.tableParams.reload();
  2404. };
  2405. }]);
  2406. // Controller 主动报价 - 新增
  2407. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
  2408. var staticItem = null;
  2409. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  2410. $scope.loading = true;
  2411. Quotation.getItem({id: $stateParams.id}, function(data){
  2412. data.$editing = false;
  2413. $scope.item = data;
  2414. staticItem = angular.copy(data);
  2415. $scope.loading = false;
  2416. }, function(response){
  2417. $scope.loading = false;
  2418. toaster.pop('error', '数据加载失败', response.data);
  2419. });
  2420. } else {// 新增模式
  2421. $scope.item = {
  2422. quotation: {
  2423. currency: 'RMB',
  2424. taxrate: 17,
  2425. date: new Date()
  2426. },
  2427. product: {},
  2428. prices: [{lapQty: 0}],
  2429. minOrderQty: 1,
  2430. minPackQty: 1,
  2431. $endDateOpen: false,
  2432. $editing: true
  2433. };
  2434. }
  2435. $scope.getMinDate = function(item) {
  2436. return $filter('date')(new Date, 'yyyy-MM-dd');
  2437. };
  2438. $scope.openDatePicker = function($event, openParam) {
  2439. $event.preventDefault();
  2440. $event.stopPropagation();
  2441. $scope.item.$endDateOpen = !openParam;
  2442. };
  2443. // 增加一个分段
  2444. $scope.addPrice = function(){
  2445. if($scope.item.prices.length >= 10) {
  2446. toaster.pop('warning', '提示', '最多支持10个分段!');
  2447. } else
  2448. $scope.item.prices.push({});
  2449. };
  2450. // 删除一个分段
  2451. $scope.removePrice = function(index) {
  2452. $scope.item.prices.splice(index, 1);
  2453. };
  2454. // 查找客户
  2455. $scope.dbfindCust = function(){
  2456. if($scope.item.$editing) {
  2457. var modalInstance = $modal.open({
  2458. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  2459. controller: 'DbfindCustCtrl',
  2460. size: 'lg',
  2461. resolve: {
  2462. }
  2463. });
  2464. modalInstance.result.then(function(data){
  2465. $scope.item.quotation.cust = data.myEnterprise;
  2466. $scope.item.quotation.custUser = data.myUser;
  2467. $scope.item.product = null;
  2468. }, function(){
  2469. });
  2470. }
  2471. };
  2472. // 查找客户物料
  2473. $scope.dbfindCustProd = function(){
  2474. if($scope.item.$editing) {
  2475. if($scope.item.quotation.cust.uu) {
  2476. var modalInstance = $modal.open({
  2477. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  2478. controller: 'DbfindCustProdCtrl',
  2479. size: 'lg',
  2480. resolve: {
  2481. custUU: function(){return $scope.item.quotation.cust.uu}
  2482. }
  2483. });
  2484. modalInstance.result.then(function(data){
  2485. $scope.item.product = data;
  2486. }, function(){
  2487. });
  2488. } else {
  2489. toaster.pop('error', '错误', '请先选择客户');
  2490. }
  2491. }
  2492. };
  2493. // 保存
  2494. $scope.save = function(){
  2495. $scope.loading = true;
  2496. if(!$scope.item.quotation.code) //新增,设单号
  2497. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  2498. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  2499. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  2500. $scope.item.productId = $scope.item.product.id;
  2501. $scope.item.quotation.status = 100;//在录入
  2502. if($scope.item.quotation.date instanceof Date) {
  2503. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  2504. }
  2505. if($scope.item.quotation.endDate instanceof Date) {
  2506. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  2507. }
  2508. Quotation.save({}, $scope.item, function(data){
  2509. $scope.loading = false;
  2510. toaster.pop('success', '成功', '保存成功');
  2511. if($stateParams.id)
  2512. window.location.reload();
  2513. else
  2514. window.location.hash = '#/sale/quotation/' + data.id;
  2515. }, function(response){
  2516. $scope.loading = false;
  2517. toaster.pop('error', '保存失败', response.data);
  2518. });
  2519. };
  2520. // 更新
  2521. $scope.update = function(){
  2522. $scope.item.$editing = true;
  2523. };
  2524. // 取消
  2525. $scope.cancel = function(){
  2526. $scope.item.$editing = false;
  2527. $scope.item = angular.copy(staticItem);
  2528. };
  2529. // 提交
  2530. $scope.submit = function(){
  2531. $scope.loading = true;
  2532. $scope.item.quotation.status = 101;//在录入
  2533. Quotation.save({}, $scope.item, function(data){
  2534. $scope.loading = false;
  2535. toaster.pop('success', '成功', '提交成功');
  2536. window.location.hash = '#/sale/quotation/' + data.id;
  2537. }, function(response){
  2538. $scope.loading = false;
  2539. toaster.pop('error', '保存失败', response.data);
  2540. });
  2541. };
  2542. }]);
  2543. // 查找客户
  2544. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  2545. $scope.tableParams = new ngTableParams({
  2546. page : 1,
  2547. count : 10
  2548. }, {
  2549. total : 0,
  2550. counts: [5, 10, 25, 50],
  2551. getData : function($defer, params) {
  2552. $scope.loading = true;
  2553. Customer.get(BaseService.parseParams(params.url()), function(page){
  2554. $scope.loading = false;
  2555. if(page) {
  2556. params.total(page.totalElements);
  2557. $defer.resolve(page.content);
  2558. }
  2559. $scope.totalCount = page.totalElements;
  2560. }, function(response){
  2561. $scope.loading = false;
  2562. toaster.pop('error', '数据加载失败', response.data);
  2563. });
  2564. }
  2565. });
  2566. $scope.cancel = function() {
  2567. $modalInstance.dismiss();
  2568. };
  2569. $scope.check = function(cust){
  2570. $modalInstance.close(cust);
  2571. };
  2572. }]);
  2573. // 查找客户物料
  2574. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  2575. $scope.tableParams = new ngTableParams({
  2576. page : 1,
  2577. count : 10
  2578. }, {
  2579. total : 0,
  2580. counts: [5, 10, 25, 50],
  2581. getData : function($defer, params) {
  2582. $scope.loading = true;
  2583. var pageParams = params.url();
  2584. pageParams.keyword = $scope.keyword;
  2585. pageParams.custUU = custUU;
  2586. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  2587. $scope.loading = false;
  2588. if(page) {
  2589. params.total(page.totalElements);
  2590. $defer.resolve(page.content);
  2591. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2592. }
  2593. }, function(response){
  2594. $scope.loading = false;
  2595. toaster.pop('error', '数据加载失败', response.data);
  2596. });
  2597. }
  2598. });
  2599. // 取消
  2600. $scope.cancel = function() {
  2601. $modalInstance.dismiss();
  2602. };
  2603. // 选择
  2604. $scope.check = function(cust){
  2605. $modalInstance.close(cust);
  2606. };
  2607. // 搜索框回车
  2608. $scope.onSearch = function() {
  2609. $scope.tableParams.page(1);
  2610. $scope.tableParams.reload();
  2611. };
  2612. }]);
  2613. // 发货提醒
  2614. 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){
  2615. $scope.active = 'todo';
  2616. $scope.currency = Symbol.currency;
  2617. $scope.dateZoneText = '不限';
  2618. $scope.condition = {dateZone: -1};
  2619. $scope.changeDateZone = function(zone) {
  2620. $scope.condition.dateZone = zone;
  2621. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2622. $scope.condition.$dateZoneOpen = false;
  2623. getDateCondition(zone, $scope.condition);
  2624. $scope.tableParams.reload();
  2625. };
  2626. $scope.setActive = function(state) {
  2627. if($scope.active != state) {
  2628. $scope.active = state;
  2629. if($scope.tableParams.page() == 1)
  2630. $scope.tableParams.reload();
  2631. else
  2632. $scope.tableParams.page(1);
  2633. }
  2634. };
  2635. var getService = function() {
  2636. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  2637. };
  2638. $scope.tableParams = new ngTableParams({
  2639. page : 1,
  2640. count : 5,
  2641. sorting: {
  2642. 'delivery': 'asc',
  2643. 'orderItemOrderCode': 'asc',
  2644. 'orderItemNumber': 'asc'
  2645. }
  2646. }, {
  2647. total : 0,
  2648. counts: [5, 10, 25, 50],
  2649. getData : function($defer, params) {
  2650. $scope.loading = true;
  2651. var pageParams = params.url();
  2652. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2653. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2654. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2655. $scope.loading = false;
  2656. if(page) {
  2657. params.total(page.totalElement);
  2658. $defer.resolve(page.content);
  2659. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2660. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2661. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2662. }
  2663. }, function(response){
  2664. $scope.loading = false;
  2665. toaster.pop('error', '数据加载失败', response.data);
  2666. });
  2667. }
  2668. });
  2669. $scope.openDatePicker = function($event, item, openParam) {
  2670. $event.preventDefault();
  2671. $event.stopPropagation();
  2672. item[openParam] = !item[openParam];
  2673. };
  2674. //生成随机单号
  2675. $scope.autoCode = function(notice){
  2676. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  2677. };
  2678. //可送货日期
  2679. $scope.sendDate = function(notice) {
  2680. var stock = notice.orderItem.product.ltinstock || 0;
  2681. var de = new Date(notice.delivery);
  2682. if(stock == -1) {
  2683. de.setMonth(de.getMonth() -1);
  2684. de.setDate(25);
  2685. } else if(stock >= 0) {
  2686. de.setDate(de.getDate() - stock -1);
  2687. }
  2688. return de;
  2689. };
  2690. $scope.onReplyClick = function(notice) {
  2691. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  2692. toaster.pop('warning', '警告', '数量填写错误!');
  2693. } else if(!notice.send.code) {
  2694. toaster.pop('warning', '警告', '请填写发货单号!');
  2695. } else {
  2696. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  2697. $scope.loading = true;
  2698. PurcNotice.save({id: notice.id}, send, function(data){
  2699. $scope.loading = false;
  2700. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  2701. $state.go('sale.send_detail', {id: data.id});
  2702. }, function(response){
  2703. $scope.loading = false;
  2704. toaster.pop('error', '发货失败', response.data);
  2705. });
  2706. }
  2707. };
  2708. $scope.checkboxes = {
  2709. checked : false
  2710. };
  2711. // 点击勾选全部的复选框
  2712. $scope.checkAll = function(){
  2713. angular.forEach($scope.tableParams.data, function(item) {
  2714. if(!item.waiting)
  2715. item.$selected = $scope.checkboxes.checked;
  2716. });
  2717. };
  2718. // 点击其中一个明细的复选框
  2719. $scope.checkOne = function(order){
  2720. var result = true;
  2721. angular.forEach($scope.tableParams.data, function(item) {
  2722. if(item.$selected != true){
  2723. result = false;
  2724. return;
  2725. }
  2726. });
  2727. $scope.checkboxes.checked = result;
  2728. };
  2729. $scope.sendByBatch = function(){
  2730. var modalInstance = $modal.open({
  2731. animation: true,
  2732. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  2733. controller: 'SaleNoticeSendByBatchCtrl',
  2734. size: 'lg',
  2735. resolve: {
  2736. selectedNotices: function(){return $scope.tableParams.data;}
  2737. }
  2738. });
  2739. modalInstance.result.then(function(){
  2740. $scope.tableParams.reload();
  2741. }, function(){
  2742. });
  2743. };
  2744. $scope.getSends = function(notice){
  2745. if( ! notice.sends && notice.endQty > 0){
  2746. notice.getSendsing = true;
  2747. notice.getSendsError = false;
  2748. PurcNotice.getSends({id: notice.id}, function(data){
  2749. notice.getSendsing = false;
  2750. notice.getSendsError = false;
  2751. notice.sends = data;
  2752. }, function(response){
  2753. notice.getSendsing = false;
  2754. notice.getSendsError = true;
  2755. });
  2756. }
  2757. };
  2758. // 搜索框回车
  2759. $scope.onSearch = function() {
  2760. $scope.tableParams.page(1);
  2761. $scope.tableParams.reload();
  2762. };
  2763. // 选择查找日期
  2764. $scope.onDateCondition = function(){
  2765. $scope.tableParams.page(1);
  2766. $scope.tableParams.reload();
  2767. };
  2768. //货车功能
  2769. var truck = $rootScope.truck;
  2770. if(!truck) {
  2771. SaleTruck.query({}, function(data){
  2772. $rootScope.truck = data;
  2773. });
  2774. }
  2775. $scope.isInTruck = function(noticeId) {
  2776. return truck.indexOf(noticeId) > -1;
  2777. };
  2778. $scope.addtoTruck = function(notice) {
  2779. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  2780. $rootScope.truck = data;
  2781. });
  2782. };
  2783. $scope.delFromTruck = function(notice) {
  2784. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  2785. $rootScope.truck = data;
  2786. });
  2787. };
  2788. $scope.$watch(function(){
  2789. return $rootScope.truck;
  2790. }, function(data) {
  2791. truck = $rootScope.truck;
  2792. }, true);
  2793. $scope.$watch(function(){
  2794. return $rootScope.dataChanged;
  2795. }, function(data) {
  2796. data && ($scope.tableParams.reload());
  2797. }, true);
  2798. }]);
  2799. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  2800. $scope.notices = angular.copy(selectedNotices);
  2801. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2802. $scope.saleSend = {
  2803. code: '',
  2804. payments: '',
  2805. currency: '',
  2806. custUU: null,
  2807. custUserUU: null,
  2808. remark: '批量发货',
  2809. sendItems: []
  2810. };
  2811. // 计算总数、总额
  2812. $scope.$watch(function(){
  2813. return $scope.notices;
  2814. }, function(data) {
  2815. var q = 0, t = 0;
  2816. if(data) {
  2817. angular.forEach(data,function(d){
  2818. q += (d.thisSendQty || 0);
  2819. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  2820. });
  2821. }
  2822. $scope.totalQty = q;
  2823. $scope.total = t;
  2824. }, true);
  2825. /**
  2826. * 删除一个已选中的送货提醒
  2827. */
  2828. $scope.removeOne = function(index) {
  2829. $scope.notices.splice(index, 1);
  2830. };
  2831. //确认送货
  2832. $scope.sendByBatch = function () {
  2833. $scope.saleSend.sendItems = [];
  2834. if($scope.saleSend.code == '') {//送货单号为空
  2835. toaster.pop('error', '错误', '请输入送货单号');
  2836. return;
  2837. }
  2838. var a = 0;
  2839. var num = 1;
  2840. var valid = true;
  2841. angular.forEach($scope.notices, function(item, key){
  2842. if(item.$selected) {
  2843. if(a == 0) {//第一次
  2844. $scope.saleSend.currency = item.orderItem.order.currency;
  2845. $scope.saleSend.custUU = item.enUU;
  2846. $scope.saleSend.payments = item.orderItem.order.payments;
  2847. a = 1;
  2848. } else {//其他
  2849. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  2850. if($scope.saleSend.custUU != item.enUU) valid = false;
  2851. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  2852. }
  2853. $scope.saleSend.sendItems.push({
  2854. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  2855. });
  2856. }
  2857. });
  2858. if(!valid) {
  2859. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  2860. } else {
  2861. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  2862. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  2863. $modalInstance.close('success');
  2864. $state.go('sale.send_detail', {id: data.id});
  2865. }, function(response){
  2866. toaster.pop('error', '错误', response.data);
  2867. });
  2868. }
  2869. };
  2870. $scope.cancel = function () {
  2871. $modalInstance.dismiss();
  2872. };
  2873. }]);
  2874. /**
  2875. * 发货单
  2876. */
  2877. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  2878. $scope.active = 'all';
  2879. $scope.currency = Symbol.currency;
  2880. $scope.dateZoneText = '不限';
  2881. $scope.condition = {dateZone: -1};
  2882. $scope.changeDateZone = function(zone) {
  2883. $scope.condition.dateZone = zone;
  2884. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2885. $scope.condition.$dateZoneOpen = false;
  2886. getDateCondition(zone, $scope.condition);
  2887. $scope.tableParams.reload();
  2888. };
  2889. $scope.setActive = function(state) {
  2890. if($scope.active != state) {
  2891. $scope.active = state;
  2892. if($scope.tableParams.page() == 1)
  2893. $scope.tableParams.reload();
  2894. else
  2895. $scope.tableParams.page(1);
  2896. }
  2897. };
  2898. var getService = function() {
  2899. return SaleSend;
  2900. };
  2901. $scope.tableParams = new ngTableParams({
  2902. page : 1,
  2903. count : 5,
  2904. sorting: {
  2905. date: 'desc'
  2906. }
  2907. }, {
  2908. total : 0,
  2909. counts: [5, 10, 25, 50],
  2910. getData : function($defer, params) {
  2911. $scope.loading = true;
  2912. var pageParams = params.url();
  2913. pageParams.keyword = $scope.keyword;
  2914. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2915. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2916. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2917. $scope.loading = false;
  2918. if(page) {
  2919. params.total(page.totalElement);
  2920. $defer.resolve(page.content);
  2921. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2922. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2923. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2924. }
  2925. }, function(response){
  2926. $scope.loading = false;
  2927. toaster.pop('error', '数据加载失败', response.data);
  2928. });
  2929. }
  2930. });
  2931. $scope.openDatePicker = function($event, item, openParam) {
  2932. $event.preventDefault();
  2933. $event.stopPropagation();
  2934. item[openParam] = !item[openParam];
  2935. };
  2936. // 搜索框回车
  2937. $scope.onSearch = function() {
  2938. $scope.tableParams.page(1);
  2939. $scope.tableParams.reload();
  2940. };
  2941. // 选择查找日期
  2942. $scope.onDateCondition = function(){
  2943. $scope.tableParams.page(1);
  2944. $scope.tableParams.reload();
  2945. };
  2946. }]);
  2947. /**
  2948. * 发货单(包括发货条码维护)
  2949. */
  2950. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  2951. var loading = true;
  2952. $scope.checkBarCode = [];
  2953. $scope.checkBoxCode = [];
  2954. var vm = $scope.vm = {};
  2955. $scope.getCheckedItems = {};
  2956. vm.editBar = false;
  2957. vm.showBarCode = [];
  2958. $scope.barCode = function() {
  2959. vm.editBar = !vm.editBar;
  2960. }
  2961. $scope.checkboxes = {
  2962. checked : false
  2963. };
  2964. $scope.checkbars = {
  2965. checked : false
  2966. };
  2967. // 点击勾选barCode全部的复选框
  2968. $scope.checkBarAll = function(){
  2969. angular.forEach($scope.checkBarCode, function(item,key) {
  2970. $scope.checkBarCode[key] = $scope.checkbars.checked;
  2971. });
  2972. };
  2973. //点击barCode单选
  2974. $scope.checkBarOne = function() {
  2975. var result = true;
  2976. angular.forEach($scope.checkBarCode, function(item,key) {
  2977. if(item != true){
  2978. result = false;
  2979. return;
  2980. }
  2981. });
  2982. $scope.checkbars.checked = result;
  2983. }
  2984. // 点击boxCode全部的复选框
  2985. $scope.checkBoxAll = function(){
  2986. angular.forEach($scope.checkBoxCode, function(item,key) {
  2987. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  2988. });
  2989. };
  2990. //点击boxCode单选
  2991. $scope.checkBoxOne = function() {
  2992. var result = true;
  2993. angular.forEach($scope.checkBoxCode, function(item) {
  2994. if(item != true){
  2995. result = false;
  2996. return;
  2997. }
  2998. });
  2999. $scope.checkboxes.checked = result;
  3000. }
  3001. /**
  3002. * 生成条码和箱号
  3003. */
  3004. $scope.generateBarCode = function(item) {
  3005. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  3006. $scope.getCheckedItems = [];
  3007. var warningdata = '';
  3008. angular.forEach($scope.checkBarCode, function(item,key) {
  3009. $scope.getCheckedItem = {};
  3010. if(item == true ){
  3011. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  3012. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  3013. $scope.getCheckedItems.push($scope.getCheckedItem);
  3014. //判断是否生成过条码
  3015. if($scope.order.sendItems[key].barSendNotify.length > 0){
  3016. warningdata += $scope.order.sendItems[key].number+","
  3017. }
  3018. }
  3019. });
  3020. if($scope.getCheckedItems.length == 0){
  3021. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  3022. return;
  3023. }
  3024. if(warningdata != ''){
  3025. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  3026. return ;
  3027. }
  3028. }
  3029. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  3030. toaster.pop('success', '提示','生成成功!');
  3031. loadData();
  3032. },function(response){
  3033. $scope.loading = false;
  3034. toaster.pop('error', '生成失败', response.data);
  3035. });
  3036. }
  3037. /**
  3038. * 打印条码和箱号
  3039. */
  3040. $scope.printCode = function(type) {
  3041. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  3042. //勾选需要打印的行
  3043. $scope.getCheckedItems = [];
  3044. var warningdata = ''
  3045. angular.forEach($scope.checkBarCode, function(item,key) {
  3046. $scope.getCheckedItem = {};
  3047. if(item == true ){
  3048. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  3049. $scope.getCheckedItems.push($scope.getCheckedItem);
  3050. //判断是否生成过条码
  3051. if($scope.order.sendItems[key].barSendNotify.length > 0){
  3052. warningdata += $scope.order.sendItems[key].number+","
  3053. }
  3054. }
  3055. });
  3056. if($scope.getCheckedItems.length == 0){
  3057. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  3058. return;
  3059. }
  3060. if(warningdata == ''){
  3061. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  3062. return;
  3063. }
  3064. //选择打印模板
  3065. var modalInstance = $modal.open({
  3066. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  3067. controller: 'BarPrintModalCtrl',
  3068. resolve: {
  3069. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  3070. }
  3071. });
  3072. modalInstance.result.then(function(s){
  3073. if(s) {
  3074. //获取打印数据
  3075. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  3076. if(s.type == 'print'){//判断选择是打印还是打印预览
  3077. lodopPrint(data.message,LODOP,type);
  3078. }else if(s.type == 'printPreview'){
  3079. lodopPrintPreview(data.message,LODOP,type);
  3080. }
  3081. },function(response){
  3082. toaster.pop('error', '获取打印数据失败', response.data);
  3083. });
  3084. }
  3085. });
  3086. };
  3087. //打印单个条码
  3088. $scope.printSingleCode = function(id){
  3089. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  3090. //选择打印模板
  3091. var modalInstance = $modal.open({
  3092. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  3093. controller: 'BarPrintModalCtrl',
  3094. resolve: {
  3095. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  3096. }
  3097. });
  3098. modalInstance.result.then(function(s){
  3099. if(s) {
  3100. //获取打印数据
  3101. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  3102. if(s.type == 'print'){//判断选择是打印还是打印预览
  3103. lodopSPrint(data.message,LODOP);
  3104. }else if(s.type == 'printPreview'){
  3105. lodopSPrintPreview(data.message,LODOP);
  3106. }
  3107. },function(response){
  3108. toaster.pop('error', '获取打印数据失败', response.data);
  3109. });
  3110. }
  3111. });
  3112. }
  3113. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  3114. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  3115. if (selectOrNot != -1) {
  3116. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3117. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  3118. var strs = pagesize.split("*"); //字符分割
  3119. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3120. angular.forEach(printStore, function(data, index) {
  3121. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  3122. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3123. if (data['LP_VALUETYPE'] == 'barcode') {
  3124. 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']);
  3125. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  3126. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  3127. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  3128. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  3129. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  3130. } else if (data['LP_VALUETYPE'] == 'text') {
  3131. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  3132. }
  3133. });
  3134. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  3135. LODOP.PRINT();
  3136. }
  3137. };
  3138. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  3139. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3140. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  3141. var strs = pagesize.split("*"); //字符分割
  3142. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3143. angular.forEach(printStore,function(data,index){
  3144. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  3145. if(data['LP_VALUETYPE'] == 'barcode'){
  3146. 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']);
  3147. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  3148. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  3149. }else if(data['LP_VALUETYPE'] == 'text'){
  3150. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3151. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  3152. }
  3153. });
  3154. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  3155. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  3156. LODOP.PREVIEW();//打印预览
  3157. };
  3158. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  3159. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  3160. if (selectOrNot != -1) {
  3161. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  3162. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  3163. var strs= new Array(); //定义一数组
  3164. strs = pagesize.split("*"); //字符分割
  3165. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3166. var ids = new Array();
  3167. angular.forEach(printStore, function(value,key) {
  3168. //LODOP.NewPage();
  3169. angular.forEach(value['data'], function(record,key) {
  3170. angular.forEach(record['store'], function(data, index) {
  3171. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  3172. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3173. if (data['LP_VALUETYPE'] == 'barcode') {
  3174. 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']);
  3175. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  3176. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  3177. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  3178. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  3179. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  3180. } else if (data['LP_VALUETYPE'] == 'text') {
  3181. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  3182. }
  3183. });
  3184. });
  3185. var o = new Object();
  3186. o['id'] = record['si_id']
  3187. ids.push(o);
  3188. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  3189. LODOP.PRINT();
  3190. });
  3191. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  3192. if(type == 'Bar'){
  3193. //更新打印状态
  3194. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  3195. }
  3196. }
  3197. };
  3198. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  3199. var ids = new Array();
  3200. angular.forEach(printData, function(record, index){
  3201. angular.forEach(record['data'],function(value,index){
  3202. LODOP.NewPage();
  3203. angular.forEach(value['store'],function(data,index){
  3204. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  3205. if(data['LP_VALUETYPE'] == 'barcode'){
  3206. 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']);
  3207. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  3208. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  3209. }else if(data['LP_VALUETYPE'] == 'text'){
  3210. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  3211. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  3212. }
  3213. });
  3214. });
  3215. var o = new Object();
  3216. o['id'] = record['si_id']
  3217. ids.push(o);
  3218. });
  3219. var pagesize = printData[0]['pagesize'];//获取标签的大小
  3220. var strs= new Array(); //定义一数组
  3221. strs = pagesize.split("*"); //字符分割
  3222. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  3223. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  3224. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  3225. var times = LODOP.PREVIEW();//打印预览
  3226. if(times > 0){//点击了打印预览内的打印按钮
  3227. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  3228. if(type == 'Bar'){
  3229. //更新打印状态
  3230. SaleSend.updatePrintStatus({},ids,function(data){
  3231. loadData();
  3232. },function(res){});
  3233. }
  3234. }
  3235. };
  3236. /**
  3237. * 查看条码按钮
  3238. */
  3239. $scope.showBarCode = function(number) {
  3240. $scope.keys = number;
  3241. for(var i=0;i<vm.showBarCode.length;i++){
  3242. if(i!=number){
  3243. vm.showBarCode[i] = false;
  3244. }
  3245. }
  3246. vm.showBarCode[number] = !vm.showBarCode[number];
  3247. $scope.barcodes = [];
  3248. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  3249. var getPage = function(page, size){
  3250. if($scope.barcodes) {
  3251. var result = {};
  3252. result.totalCount = $scope.barcodes.length;
  3253. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  3254. if($scope.barcodes.length % size == 0) {
  3255. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  3256. }else {
  3257. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  3258. }
  3259. result.first = page == 1;
  3260. result.last = page == result.totalPage;
  3261. result.page = page;
  3262. result.next = page - 0 + 1;
  3263. result.pre = page - 1;
  3264. return result;
  3265. }
  3266. }
  3267. $scope.barData = getPage(1,5);
  3268. $scope.first = function (){
  3269. $scope.barData = getPage($scope.barData.pre,5);
  3270. }
  3271. $scope.last = function (){
  3272. $scope.barData = getPage($scope.barData.next,5);
  3273. }
  3274. };
  3275. /**
  3276. * 更新外箱号
  3277. */
  3278. $scope.updateOutBox = function(item,number) {
  3279. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  3280. }else {
  3281. if(item.outBoxQty > 0) {
  3282. if(!(item.outBoxQty % item.packageQty)) {
  3283. SaleSend.update({id:item.id},item,function(){
  3284. toaster.pop('success', '提示','保存成功!');
  3285. loadData();
  3286. }, function(response){
  3287. $scope.loading = false;
  3288. toaster.pop('error', '回复失败', response.data);
  3289. })
  3290. }else {
  3291. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  3292. }
  3293. }else {
  3294. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3295. }
  3296. }
  3297. loadData();
  3298. };
  3299. /**
  3300. * 更新最小包数
  3301. */
  3302. $scope.updatePackage = function(item, number) {
  3303. if(item.packageQty == $scope.oldpackageQty[number]) {
  3304. }else {
  3305. if(item.orderItem.product.minPack != 0) {
  3306. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  3307. if(!(item.packageQty % item.orderItem.product.minPack)) {
  3308. SaleSend.update({id:item.id},item,function(){
  3309. toaster.pop('success', '提示','保存成功!');
  3310. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  3311. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  3312. }
  3313. loadData();
  3314. }, function(response){
  3315. $scope.loading = false;
  3316. toaster.pop('error', '回复失败', response.data);
  3317. })
  3318. }else {
  3319. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  3320. }
  3321. }else {
  3322. toaster.pop('warning', '提示', '请填写有效的数量!');
  3323. }
  3324. }else {
  3325. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  3326. SaleSend.update({id:item.id},item,function(){
  3327. toaster.pop('success', '提示','保存成功!');
  3328. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  3329. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  3330. }
  3331. loadData();
  3332. }, function(response){
  3333. $scope.loading = false;
  3334. toaster.pop('error', '回复失败', response.data);
  3335. })
  3336. }else {
  3337. toaster.pop('warning', '提示', '请填写有效的数量!');
  3338. }
  3339. }
  3340. }
  3341. loadData();
  3342. };
  3343. var loadData = function() {
  3344. SaleSend.get({id: $stateParams.id}, function(data){
  3345. $scope.order = data;
  3346. var orderCount = $scope.order.sendItems.length;
  3347. $scope.oldpackageQty = [];
  3348. $scope.oldoutBoxQty = [];
  3349. var sum = 0;
  3350. vm.oldpackageQty = [];
  3351. angular.forEach(data.sendItems, function(value, key){
  3352. //给showBarCode数组赋初值
  3353. if (vm.showBarCode.length < orderCount){
  3354. vm.showBarCode.push(false);
  3355. }
  3356. if($scope.checkBarCode.length < orderCount) {
  3357. $scope.checkBarCode.push(false);
  3358. }
  3359. if($scope.checkBoxCode.length < orderCount) {
  3360. $scope.checkBoxCode.push(false);
  3361. }
  3362. //给个初值
  3363. if(!value.packageQty) {
  3364. value.packageQty = value.orderItem.product.minPack;
  3365. }
  3366. $scope.oldpackageQty.push(value.packageQty);
  3367. if(value.outBoxQty) {
  3368. $scope.oldoutBoxQty.push(value.outBoxQty);
  3369. }
  3370. sum += value.price * value.qty;
  3371. });
  3372. data.total = sum;
  3373. $scope.loading = false;
  3374. }, function(response){
  3375. loading = false;
  3376. toaster.pop('error', '获取数据失败', response.data);
  3377. });
  3378. };
  3379. loadData();
  3380. }]);
  3381. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  3382. $scope.typeItem = typeItem;
  3383. $scope.template = [];
  3384. $scope.choose = {};
  3385. //获取打印模板
  3386. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  3387. if(data.message){
  3388. $scope.template = data.message;
  3389. $scope.choose.tp_id = $scope.template[0].id;
  3390. }
  3391. },function(res){
  3392. toaster.pop('error', '获取模板错误', res.data);
  3393. });
  3394. $scope.print = function(){
  3395. $scope.choose.type = 'print';
  3396. $modalInstance.close($scope.choose);
  3397. };
  3398. $scope.printPreview = function(){
  3399. $scope.choose.type = 'printPreview';
  3400. $modalInstance.close($scope.choose);
  3401. }
  3402. $scope.cancel = function(){
  3403. $modalInstance.close();
  3404. }
  3405. }]);
  3406. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  3407. var loading = true;
  3408. var loadData = function() {
  3409. PurcSample.get({id: $stateParams.id}, function(data){
  3410. $scope.sample = data;
  3411. if(!$scope.sample.send){
  3412. $scope.sample.getSendInfo = '加载中...';
  3413. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  3414. if(sendData) {
  3415. $scope.sample.getSendInfo = null;
  3416. $scope.sample.send = sendData;
  3417. } else {
  3418. $scope.sample.getSendInfo = '无送样信息';
  3419. $scope.sample.send = '无送样信息';
  3420. }
  3421. }, function(response){
  3422. $scope.sample.getSendInfo = '加载失败!';
  3423. });
  3424. }
  3425. $scope.loading = false;
  3426. }, function(response){
  3427. loading = false;
  3428. toaster.pop('error', '获取数据失败', response.data);
  3429. });
  3430. };
  3431. loadData();
  3432. }]);
  3433. /**
  3434. * 客户打样申请
  3435. */
  3436. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  3437. $scope.active = 'todo';
  3438. $scope.agreedText = '全部';
  3439. $scope.dateZoneText = '一个月内';
  3440. $scope.condition = {dateZone: 1};
  3441. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3442. $scope.changeAgreed = function(agreed) {
  3443. $scope.condition.agreed = agreed;
  3444. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3445. $scope.condition.$agreedOpen = false;
  3446. };
  3447. $scope.changeDateZone = function(zone) {
  3448. $scope.condition.dateZone = zone;
  3449. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3450. $scope.condition.$dateZoneOpen = false;
  3451. };
  3452. $scope.setActive = function(state) {
  3453. if($scope.active != state) {
  3454. $scope.active = state;
  3455. if($scope.tableParams.page() == 1)
  3456. $scope.tableParams.reload();
  3457. else
  3458. $scope.tableParams.page(1);
  3459. }
  3460. };
  3461. var getService = function() {
  3462. return PurcSample;
  3463. };
  3464. $scope.tableParams = new ngTableParams({
  3465. page : 1,
  3466. count : 5,
  3467. sorting: {
  3468. proofingDate: 'desc'
  3469. }
  3470. }, {
  3471. total : 0,
  3472. counts: [5, 10, 25, 50],
  3473. getData : function($defer, params) {
  3474. $scope.loading = true;
  3475. var pageParams = params.url();
  3476. pageParams.keyword = $scope.keyword;
  3477. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3478. $scope.loading = false;
  3479. if(page) {
  3480. params.total(page.totalElement);
  3481. $defer.resolve(page.content);
  3482. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3483. }
  3484. }, function(response){
  3485. $scope.loading = false;
  3486. toaster.pop('error', '数据加载失败', response.data);
  3487. });
  3488. }
  3489. });
  3490. $scope.openDatePicker = function($event, item, openParam) {
  3491. $event.preventDefault();
  3492. $event.stopPropagation();
  3493. item[openParam] = !item[openParam];
  3494. };
  3495. $scope.openSend = function(index, sample) {
  3496. var modalInstance = $modal.open({
  3497. animation: true,
  3498. templateUrl: 'static/tpl/index/sale/sample_send.html',
  3499. controller: 'SampleSendCtrl',
  3500. resolve: {
  3501. sampleItem: function(){return sample;}
  3502. }
  3503. });
  3504. modalInstance.result.then(function(){
  3505. toaster.pop('info', '提示', '送样成功');
  3506. $scope.tableParams.reload();
  3507. }, function(){
  3508. });
  3509. };
  3510. //打印 样品采购单
  3511. $scope.print = function(sample) {
  3512. console.log(sample);
  3513. PurcSample.printCount({id: sample.id},{});//增加打印此次
  3514. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  3515. };
  3516. $scope.getSend = function(proofing){
  3517. if( !proofing.send) {
  3518. proofing.getSendInfo = '加载中...';
  3519. PurcSample.getSend({id: proofing.id}, function(data){
  3520. if(data) {
  3521. proofing.getSendInfo = null;
  3522. proofing.send = data;
  3523. } else {
  3524. proofing.getSendInfo = '无送样信息';
  3525. proofing.send = '无送样信息';
  3526. }
  3527. }, function(response){
  3528. proofing.getSendInfo = '加载失败!';
  3529. });
  3530. }
  3531. };
  3532. // 搜索框回车
  3533. $scope.onSearch = function() {
  3534. $scope.tableParams.page(1);
  3535. $scope.tableParams.reload();
  3536. };
  3537. }]);
  3538. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  3539. $scope.sampleItem = sampleItem;
  3540. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  3541. //确认送样
  3542. $scope.ok = function (form) {
  3543. $scope.loading = true;
  3544. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  3545. $upload.upload({
  3546. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  3547. method: 'POST',
  3548. file: file,
  3549. data: {
  3550. json: $scope.sampleItem.sampleSend
  3551. }
  3552. }).success(function(data){
  3553. $scope.loading = false;
  3554. $modalInstance.close('success');
  3555. }).error(function(data){
  3556. $scope.loading = false;
  3557. toaster.pop('danger', '错误', data);
  3558. });
  3559. };
  3560. $scope.cancel = function () {
  3561. $modalInstance.dismiss(sampleItem);
  3562. };
  3563. }]);
  3564. /**
  3565. * 客户认定单
  3566. */
  3567. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  3568. $scope.active = 'all';
  3569. $scope.agreedText = '全部';
  3570. $scope.dateZoneText = '一个月内';
  3571. $scope.condition = {dateZone: 1};
  3572. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3573. $scope.changeDateZone = function(zone) {
  3574. $scope.condition.dateZone = zone;
  3575. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3576. $scope.condition.$dateZoneOpen = false;
  3577. getDateCondition(zone, $scope.condition);
  3578. $scope.tableParams.reload();
  3579. };
  3580. $scope.setActive = function(state) {
  3581. if($scope.active != state) {
  3582. $scope.active = state;
  3583. if($scope.tableParams.page() == 1)
  3584. $scope.tableParams.reload();
  3585. else
  3586. $scope.tableParams.page(1);
  3587. }
  3588. };
  3589. var getService = function() {
  3590. return PurcApproval;
  3591. };
  3592. $scope.tableParams = new ngTableParams({
  3593. page : 1,
  3594. count : 5,
  3595. sorting: {
  3596. inDate: 'desc'
  3597. }
  3598. }, {
  3599. total : 0,
  3600. counts: [5, 10, 25, 50],
  3601. getData : function($defer, params) {
  3602. $scope.loading = true;
  3603. var pageParams = params.url();
  3604. pageParams.keyword = $scope.keyword;
  3605. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  3606. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  3607. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3608. $scope.loading = false;
  3609. if(page) {
  3610. params.total(page.totalElement);
  3611. $defer.resolve(page.content);
  3612. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3613. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  3614. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  3615. }
  3616. }, function(response){
  3617. $scope.loading = false;
  3618. toaster.pop('error', '数据加载失败', response.data);
  3619. });
  3620. }
  3621. });
  3622. $scope.openDatePicker = function($event, item, openParam) {
  3623. $event.preventDefault();
  3624. $event.stopPropagation();
  3625. item[openParam] = !item[openParam];
  3626. };
  3627. $scope.parseDate = function(dateStr) {
  3628. if(dateStr)
  3629. return Date.parse(dateStr, 'yyyy-MM-dd');
  3630. return new Date();
  3631. };
  3632. // 搜索框回车
  3633. $scope.onSearch = function() {
  3634. $scope.tableParams.page(1);
  3635. $scope.tableParams.reload();
  3636. };
  3637. // 选择查找日期
  3638. $scope.onDateCondition = function(){
  3639. $scope.tableParams.page(1);
  3640. $scope.tableParams.reload();
  3641. };
  3642. }]);
  3643. /**
  3644. * 客户采购预测
  3645. */
  3646. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  3647. $scope.active = 'all';
  3648. $scope.agreedText = '全部';
  3649. $scope.dateZoneText = '一个月内';
  3650. $scope.condition = {dateZone: 1};
  3651. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3652. $scope.changeAgreed = function(agreed) {
  3653. $scope.condition.agreed = agreed;
  3654. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3655. $scope.condition.$agreedOpen = false;
  3656. };
  3657. $scope.changeDateZone = function(zone) {
  3658. $scope.condition.dateZone = zone;
  3659. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3660. $scope.condition.$dateZoneOpen = false;
  3661. };
  3662. $scope.setActive = function(state) {
  3663. if($scope.active != state) {
  3664. $scope.active = state;
  3665. if($scope.tableParams.page() == 1)
  3666. $scope.tableParams.reload();
  3667. else
  3668. $scope.tableParams.page(1);
  3669. }
  3670. };
  3671. var getService = function() {
  3672. return PurcForecast;
  3673. };
  3674. $scope.tableParams = new ngTableParams({
  3675. page : 1,
  3676. count : 5,
  3677. sorting: {
  3678. orderDate: 'desc'
  3679. }
  3680. }, {
  3681. total : 0,
  3682. counts: [5, 10, 25, 50],
  3683. getData : function($defer, params) {
  3684. $scope.loading = true;
  3685. var pageParams = params.url();
  3686. pageParams.keyword = $scope.keyword;
  3687. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3688. $scope.loading = false;
  3689. if(page) {
  3690. console.log(page);
  3691. params.total(page.totalElement);
  3692. $defer.resolve(page.content);
  3693. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3694. }
  3695. }, function(response){
  3696. $scope.loading = false;
  3697. toaster.pop('error', '数据加载失败', response.data);
  3698. });
  3699. }
  3700. });
  3701. $scope.openDatePicker = function($event, item, openParam) {
  3702. $event.preventDefault();
  3703. $event.stopPropagation();
  3704. item[openParam] = !item[openParam];
  3705. };
  3706. // 搜索框回车
  3707. $scope.onSearch = function() {
  3708. $scope.tableParams.page(1);
  3709. $scope.tableParams.reload();
  3710. };
  3711. }]);
  3712. /**
  3713. * 客户采购验收
  3714. */
  3715. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  3716. $scope.active = 'all';
  3717. $scope.agreedText = '全部';
  3718. $scope.dateZoneText = '一个月内';
  3719. $scope.condition = {dateZone: 1};
  3720. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3721. $scope.changeAgreed = function(agreed) {
  3722. $scope.condition.agreed = agreed;
  3723. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3724. $scope.condition.$agreedOpen = false;
  3725. };
  3726. $scope.changeDateZone = function(zone) {
  3727. $scope.condition.dateZone = zone;
  3728. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3729. $scope.condition.$dateZoneOpen = false;
  3730. };
  3731. $scope.setActive = function(state) {
  3732. if($scope.active != state) {
  3733. $scope.active = state;
  3734. if($scope.tableParams.page() == 1)
  3735. $scope.tableParams.reload();
  3736. else
  3737. $scope.tableParams.page(1);
  3738. }
  3739. };
  3740. var getService = function() {
  3741. return PurcAccept;
  3742. };
  3743. $scope.tableParams = new ngTableParams({
  3744. page : 1,
  3745. count : 5,
  3746. sorting: {
  3747. date: 'desc'
  3748. }
  3749. }, {
  3750. total : 0,
  3751. counts: [5, 10, 25, 50],
  3752. getData : function($defer, params) {
  3753. $scope.loading = true;
  3754. var pageParams = params.url();
  3755. pageParams.keyword = $scope.keyword;
  3756. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3757. $scope.loading = false;
  3758. if(page) {
  3759. params.total(page.totalElement);
  3760. $defer.resolve(page.content);
  3761. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3762. }
  3763. }, function(response){
  3764. $scope.loading = false;
  3765. toaster.pop('error', '数据加载失败', response.data);
  3766. });
  3767. }
  3768. });
  3769. $scope.openDatePicker = function($event, item, openParam) {
  3770. $event.preventDefault();
  3771. $event.stopPropagation();
  3772. item[openParam] = !item[openParam];
  3773. };
  3774. // 搜索框回车
  3775. $scope.onSearch = function() {
  3776. $scope.tableParams.page(1);
  3777. $scope.tableParams.reload();
  3778. };
  3779. }]);
  3780. /**
  3781. * 客户采购验退
  3782. */
  3783. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  3784. $scope.active = 'all';
  3785. $scope.agreedText = '全部';
  3786. $scope.dateZoneText = '一个月内';
  3787. $scope.condition = {dateZone: 1};
  3788. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3789. $scope.changeAgreed = function(agreed) {
  3790. $scope.condition.agreed = agreed;
  3791. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3792. $scope.condition.$agreedOpen = false;
  3793. };
  3794. $scope.changeDateZone = function(zone) {
  3795. $scope.condition.dateZone = zone;
  3796. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3797. $scope.condition.$dateZoneOpen = false;
  3798. };
  3799. $scope.setActive = function(state) {
  3800. if($scope.active != state) {
  3801. $scope.active = state;
  3802. if($scope.tableParams.page() == 1)
  3803. $scope.tableParams.reload();
  3804. else
  3805. $scope.tableParams.page(1);
  3806. }
  3807. };
  3808. var getService = function() {
  3809. return PurcReturn;
  3810. };
  3811. $scope.tableParams = new ngTableParams({
  3812. page : 1,
  3813. count : 5,
  3814. sorting: {
  3815. date: 'desc'
  3816. }
  3817. }, {
  3818. total : 0,
  3819. counts: [5, 10, 25, 50],
  3820. getData : function($defer, params) {
  3821. $scope.loading = true;
  3822. var pageParams = params.url();
  3823. pageParams.keyword = $scope.keyword;
  3824. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3825. $scope.loading = false;
  3826. if(page) {
  3827. params.total(page.totalElement);
  3828. $defer.resolve(page.content);
  3829. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3830. angular.forEach(page.content, function(data) {
  3831. if (!data.returnItems[0].orderItem) {
  3832. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  3833. data.enName = enterprise.enName;
  3834. });
  3835. }
  3836. });
  3837. }
  3838. }, function(response){
  3839. $scope.loading = false;
  3840. toaster.pop('error', '数据加载失败', response.data);
  3841. });
  3842. }
  3843. });
  3844. $scope.openDatePicker = function($event, item, openParam) {
  3845. $event.preventDefault();
  3846. $event.stopPropagation();
  3847. item[openParam] = !item[openParam];
  3848. };
  3849. // 搜索框回车
  3850. $scope.onSearch = function() {
  3851. $scope.tableParams.page(1);
  3852. $scope.tableParams.reload();
  3853. };
  3854. }]);
  3855. /**
  3856. * 客户不良品入库
  3857. */
  3858. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  3859. $scope.active = 'all';
  3860. $scope.agreedText = '全部';
  3861. $scope.dateZoneText = '一个月内';
  3862. $scope.condition = {dateZone: 1};
  3863. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3864. $scope.changeAgreed = function(agreed) {
  3865. $scope.condition.agreed = agreed;
  3866. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3867. $scope.condition.$agreedOpen = false;
  3868. };
  3869. $scope.changeDateZone = function(zone) {
  3870. $scope.condition.dateZone = zone;
  3871. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3872. $scope.condition.$dateZoneOpen = false;
  3873. };
  3874. $scope.setActive = function(state) {
  3875. if($scope.active != state) {
  3876. $scope.active = state;
  3877. if($scope.tableParams.page() == 1)
  3878. $scope.tableParams.reload();
  3879. else
  3880. $scope.tableParams.page(1);
  3881. }
  3882. };
  3883. var getService = function() {
  3884. return PurcBadIn;
  3885. };
  3886. $scope.tableParams = new ngTableParams({
  3887. page : 1,
  3888. count : 5,
  3889. sorting: {
  3890. date: 'desc'
  3891. }
  3892. }, {
  3893. total : 0,
  3894. counts: [5, 10, 25, 50],
  3895. getData : function($defer, params) {
  3896. $scope.loading = true;
  3897. var pageParams = params.url();
  3898. pageParams.keyword = $scope.keyword;
  3899. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3900. $scope.loading = false;
  3901. if(page) {
  3902. params.total(page.totalElement);
  3903. $defer.resolve(page.content);
  3904. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3905. }
  3906. }, function(response){
  3907. $scope.loading = false;
  3908. toaster.pop('error', '数据加载失败', response.data);
  3909. });
  3910. }
  3911. });
  3912. $scope.openDatePicker = function($event, item, openParam) {
  3913. $event.preventDefault();
  3914. $event.stopPropagation();
  3915. item[openParam] = !item[openParam];
  3916. };
  3917. // 搜索框回车
  3918. $scope.onSearch = function() {
  3919. $scope.tableParams.page(1);
  3920. $scope.tableParams.reload();
  3921. };
  3922. }]);
  3923. /**
  3924. * 客户不良品出库
  3925. */
  3926. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  3927. $scope.active = 'all';
  3928. $scope.agreedText = '全部';
  3929. $scope.dateZoneText = '一个月内';
  3930. $scope.condition = {dateZone: 1};
  3931. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  3932. $scope.changeAgreed = function(agreed) {
  3933. $scope.condition.agreed = agreed;
  3934. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3935. $scope.condition.$agreedOpen = false;
  3936. };
  3937. $scope.changeDateZone = function(zone) {
  3938. $scope.condition.dateZone = zone;
  3939. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3940. $scope.condition.$dateZoneOpen = false;
  3941. };
  3942. $scope.setActive = function(state) {
  3943. if($scope.active != state) {
  3944. $scope.active = state;
  3945. if($scope.tableParams.page() == 1)
  3946. $scope.tableParams.reload();
  3947. else
  3948. $scope.tableParams.page(1);
  3949. }
  3950. };
  3951. var getService = function() {
  3952. return PurcBadOut;
  3953. };
  3954. $scope.tableParams = new ngTableParams({
  3955. page : 1,
  3956. count : 5,
  3957. sorting: {
  3958. date: 'desc'
  3959. }
  3960. }, {
  3961. total : 0,
  3962. counts: [5, 10, 25, 50],
  3963. getData : function($defer, params) {
  3964. $scope.loading = true;
  3965. var pageParams = params.url();
  3966. pageParams.keyword = $scope.keyword;
  3967. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3968. $scope.loading = false;
  3969. if(page) {
  3970. params.total(page.totalElement);
  3971. $defer.resolve(page.content);
  3972. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3973. }
  3974. }, function(response){
  3975. $scope.loading = false;
  3976. toaster.pop('error', '数据加载失败', response.data);
  3977. });
  3978. }
  3979. });
  3980. $scope.openDatePicker = function($event, item, openParam) {
  3981. $event.preventDefault();
  3982. $event.stopPropagation();
  3983. item[openParam] = !item[openParam];
  3984. };
  3985. // 搜索框回车
  3986. $scope.onSearch = function() {
  3987. $scope.tableParams.page(1);
  3988. $scope.tableParams.reload();
  3989. };
  3990. }]);
  3991. /**
  3992. * 客户MRB
  3993. */
  3994. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  3995. $scope.active = 'all';
  3996. $scope.agreedText = '全部';
  3997. $scope.dateZoneText = '一个月内';
  3998. $scope.condition = {dateZone: 1};
  3999. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4000. $scope.changeAgreed = function(agreed) {
  4001. $scope.condition.agreed = agreed;
  4002. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4003. $scope.condition.$agreedOpen = false;
  4004. };
  4005. $scope.changeDateZone = function(zone) {
  4006. $scope.condition.dateZone = zone;
  4007. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4008. $scope.condition.$dateZoneOpen = false;
  4009. };
  4010. $scope.setActive = function(state) {
  4011. if($scope.active != state) {
  4012. $scope.active = state;
  4013. if($scope.tableParams.page() == 1)
  4014. $scope.tableParams.reload();
  4015. else
  4016. $scope.tableParams.page(1);
  4017. }
  4018. };
  4019. var getService = function() {
  4020. return PurcMRB;
  4021. };
  4022. $scope.tableParams = new ngTableParams({
  4023. page : 1,
  4024. count : 5,
  4025. sorting: {
  4026. date: 'desc'
  4027. }
  4028. }, {
  4029. total : 0,
  4030. counts: [5, 10, 25, 50],
  4031. getData : function($defer, params) {
  4032. $scope.loading = true;
  4033. var pageParams = params.url();
  4034. pageParams.keyword = $scope.keyword;
  4035. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4036. $scope.loading = false;
  4037. if(page) {
  4038. params.total(page.totalElement);
  4039. $defer.resolve(page.content);
  4040. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4041. }
  4042. }, function(response){
  4043. $scope.loading = false;
  4044. toaster.pop('error', '数据加载失败', response.data);
  4045. });
  4046. }
  4047. });
  4048. $scope.openDatePicker = function($event, item, openParam) {
  4049. $event.preventDefault();
  4050. $event.stopPropagation();
  4051. item[openParam] = !item[openParam];
  4052. };
  4053. // 搜索框回车
  4054. $scope.onSearch = function() {
  4055. $scope.tableParams.page(1);
  4056. $scope.tableParams.reload();
  4057. };
  4058. }]);
  4059. /**
  4060. * 客户应付发票
  4061. */
  4062. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  4063. $scope.active = 'all';
  4064. $scope.dateZoneText = '不限';
  4065. $scope.condition = {dateZone: -1};
  4066. $scope.changeDateZone = function(zone) {
  4067. $scope.condition.dateZone = zone;
  4068. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4069. $scope.condition.$dateZoneOpen = false;
  4070. getDateCondition(zone, $scope.condition);
  4071. $scope.tableParams.reload();
  4072. };
  4073. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4074. $scope.setActive = function(state) {
  4075. if($scope.active != state) {
  4076. $scope.active = state;
  4077. if($scope.tableParams.page() == 1)
  4078. $scope.tableParams.reload();
  4079. else
  4080. $scope.tableParams.page(1);
  4081. }
  4082. };
  4083. var getService = function() {
  4084. return FaApBill;
  4085. };
  4086. $scope.tableParams = new ngTableParams({
  4087. page : 1,
  4088. count : 5,
  4089. sorting: {
  4090. date: 'desc'
  4091. }
  4092. }, {
  4093. total : 0,
  4094. counts: [5, 10, 25, 50],
  4095. getData : function($defer, params) {
  4096. $scope.loading = true;
  4097. var pageParams = params.url();
  4098. pageParams.searchFilter = { // 筛选条件
  4099. keyword: $scope.keyword,
  4100. fromDate: getDateTime($scope.condition.dateFrom),
  4101. endDate: getDateTime($scope.condition.dateTo)
  4102. };
  4103. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4104. $scope.loading = false;
  4105. if(page) {
  4106. params.total(page.totalElement);
  4107. $defer.resolve(page.content);
  4108. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4109. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4110. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  4111. }
  4112. }, function(response){
  4113. $scope.loading = false;
  4114. toaster.pop('error', '数据加载失败', response.data);
  4115. });
  4116. }
  4117. });
  4118. $scope.openDatePicker = function($event, item, openParam) {
  4119. $event.preventDefault();
  4120. $event.stopPropagation();
  4121. item[openParam] = !item[openParam];
  4122. };
  4123. $scope.parseDate = function(dateStr) {
  4124. if(dateStr)
  4125. return Date.parse(dateStr, 'yyyy-MM-dd');
  4126. return new Date();
  4127. };
  4128. // 搜索框回车
  4129. $scope.onSearch = function() {
  4130. $scope.tableParams.page(1);
  4131. $scope.tableParams.reload();
  4132. };
  4133. // 选择查找日期
  4134. $scope.onDateCondition = function(){
  4135. $scope.tableParams.page(1);
  4136. $scope.tableParams.reload();
  4137. };
  4138. }]);
  4139. /**
  4140. * 应付对账单
  4141. */
  4142. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  4143. $scope.active = 'all';
  4144. $scope.dateZoneText = '不限';
  4145. $scope.condition = {dateZone: -1};
  4146. $scope.changeDateZone = function(zone) {
  4147. $scope.condition.dateZone = zone;
  4148. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4149. $scope.condition.$dateZoneOpen = false;
  4150. getDateCondition(zone, $scope.condition);
  4151. $scope.tableParams.reload();
  4152. };
  4153. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4154. $scope.setActive = function(state) {
  4155. if($scope.active != state) {
  4156. $scope.active = state;
  4157. if($scope.tableParams.page() == 1)
  4158. $scope.tableParams.reload();
  4159. else
  4160. $scope.tableParams.page(1);
  4161. }
  4162. };
  4163. var getService = function() {
  4164. return FaArCheck;
  4165. };
  4166. $scope.tableParams = new ngTableParams({
  4167. page : 1,
  4168. count : 5,
  4169. sorting: {
  4170. date: 'desc'
  4171. }
  4172. }, {
  4173. total : 0,
  4174. counts: [5, 10, 25, 50],
  4175. getData : function($defer, params) {
  4176. $scope.loading = true;
  4177. var pageParams = params.url();
  4178. pageParams.keyword = $scope.keyword;
  4179. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4180. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4181. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4182. $scope.loading = false;
  4183. if(page) {
  4184. params.total(page.totalElement);
  4185. $defer.resolve(page.content);
  4186. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4187. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4188. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4189. }
  4190. }, function(response){
  4191. $scope.loading = false;
  4192. toaster.pop('error', '数据加载失败', response.data);
  4193. });
  4194. }
  4195. });
  4196. $scope.openDatePicker = function($event, item, openParam) {
  4197. $event.preventDefault();
  4198. $event.stopPropagation();
  4199. item[openParam] = !item[openParam];
  4200. };
  4201. // 计算单据的商品总数
  4202. $scope.getTotalProd = function(check) {
  4203. var total = 0;
  4204. if(check.items) {
  4205. angular.forEach(check.items, function(value) {
  4206. total += value.qty;
  4207. });
  4208. }
  4209. return total;
  4210. };
  4211. // 搜索框回车
  4212. $scope.onSearch = function() {
  4213. $scope.tableParams.page(1);
  4214. $scope.tableParams.reload();
  4215. };
  4216. // 选择查找日期
  4217. $scope.onDateCondition = function(){
  4218. $scope.tableParams.page(1);
  4219. $scope.tableParams.reload();
  4220. };
  4221. }]);
  4222. // 应付对账单详情页
  4223. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', function($scope, $stateParams, FaArCheck, toaster, $state){
  4224. var loadData = function() {
  4225. FaArCheck.get({id: $stateParams.id}, function(data){
  4226. $scope.order = data;
  4227. $scope.loading = false;
  4228. });
  4229. };
  4230. loadData(); // 初始获取单据数据
  4231. $scope.onReplyClick = function(item, isAgreed) {
  4232. if(isAgreed) {// 同意确认
  4233. FaArCheck.agree({itemId: item.id}, {}, function(data){
  4234. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  4235. }, function(response){
  4236. toaster.pop('danger', '确认失败', response.data);
  4237. });
  4238. } else {// 不同意回复
  4239. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  4240. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  4241. }, function(response) {
  4242. toaster.pop('danger', '确认失败', response.data);
  4243. });
  4244. }
  4245. };
  4246. // 获取明细的回复记录
  4247. $scope.getReplies = function(item) {
  4248. if(!item.replies) {
  4249. FaArCheck.getReplies({itemId: item.id}, function(data) {
  4250. item.replies = data;
  4251. }, function(response) {
  4252. toaster.pop('danger', '获取对账记录失败', response.data);
  4253. });
  4254. }
  4255. };
  4256. }]);
  4257. //应收对账单列表
  4258. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  4259. $scope.dateZoneText = '不限';
  4260. $scope.condition = {dateZone: -1};
  4261. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4262. $scope.active = 'todo';
  4263. //打印 对账单
  4264. $scope.print = function(check) {
  4265. FaApCheck.printCount({id: check.id},{});//增加打印此次
  4266. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  4267. };
  4268. //状态
  4269. $scope.setActive = function (state){
  4270. if($scope.active != state) {
  4271. $scope.active = state;
  4272. if($scope.tableParams.page() == 1)
  4273. $scope.tableParams.reload();
  4274. else
  4275. $scope.tableParams.page(1);
  4276. }
  4277. };
  4278. $scope.changeDateZone = function(zone) {
  4279. $scope.condition.dateZone = zone;
  4280. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4281. $scope.condition.$dateZoneOpen = false;
  4282. getDateCondition(zone, $scope.condition);
  4283. $scope.tableParams.reload();
  4284. };
  4285. //获取应收对账单全部
  4286. $scope.tableParams = new ngTableParams({
  4287. page : 1,
  4288. count : 5,
  4289. sorting: {
  4290. recordDate: 'desc'
  4291. }
  4292. }, {
  4293. total : 0,
  4294. counts: [5, 10, 25, 50],
  4295. getData : function($defer, params) {
  4296. $scope.loading = true;
  4297. var pageParams = params.url();
  4298. pageParams.searchFilter = { // 筛选条件
  4299. keyword: $scope.keyword,
  4300. fromDate: getDateTime($scope.condition.dateFrom),
  4301. endDate: getDateTime($scope.condition.dateTo)
  4302. };
  4303. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  4304. $scope.loading = false;
  4305. if(page) {
  4306. params.total(page.totalElement);
  4307. $scope.data = $defer.resolve(page.content);
  4308. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  4309. }
  4310. }, function(response){
  4311. $scope.loading = false;
  4312. toaster.pop('error', '数据加载失败', response.data);
  4313. });
  4314. }
  4315. });
  4316. $scope.openDatePicker = function($event, item, openParam) {
  4317. $event.preventDefault();
  4318. $event.stopPropagation();
  4319. item[openParam] = !item[openParam];
  4320. };
  4321. // 计算单据的商品总数
  4322. $scope.getTotalProd = function(check) {
  4323. var total = 0;
  4324. if(check.items) {
  4325. angular.forEach(check.items, function(value) {
  4326. total += value.checkQty;
  4327. });
  4328. }
  4329. return total;
  4330. };
  4331. // 搜索框回车
  4332. $scope.onSearch = function() {
  4333. $scope.tableParams.page(1);
  4334. $scope.tableParams.reload();
  4335. };
  4336. // 选择查找日期
  4337. $scope.onDateCondition = function(){
  4338. $scope.tableParams.page(1);
  4339. $scope.tableParams.reload();
  4340. };
  4341. }]);
  4342. //应收对账单详情
  4343. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams',function($scope,toaster,FaApCheck,$stateParams){
  4344. $scope.haveSelected = true;
  4345. $scope.data = {};
  4346. //控制提交和删除按钮的显示
  4347. $scope.ifShow = true;
  4348. var loadData = function(){
  4349. FaApCheck.get({id:$stateParams.id},function(data){
  4350. $scope.data = data;
  4351. if($scope.data.status){
  4352. }else{
  4353. $scope.ifShow = true;
  4354. }
  4355. })
  4356. };
  4357. if($stateParams.id){
  4358. loadData();
  4359. }
  4360. $scope.haveSource = false;
  4361. //提交应收对账单
  4362. $scope.submitApCheck = function(){
  4363. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  4364. if(data.result) {
  4365. toaster.pop('success', '提示', '提交成功');
  4366. $scope.haveSelected = false;
  4367. window.location.href = '#/fa/apCheck';
  4368. }else {
  4369. $scope.haveSource = true;
  4370. loadData();
  4371. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  4372. $scope.haveSelected = true;
  4373. }
  4374. },function(){
  4375. $scope.loading = false;
  4376. toaster.pop('error', '提示', '更新已转数失败');
  4377. });
  4378. }
  4379. //删除应收对账单的同时更新来源表已转数
  4380. var updateYCheckQty = function(){
  4381. var sourceInfos = [];
  4382. angular.forEach($scope.data.items, function(item){
  4383. $scope.sourceInfo = {
  4384. sourceId: '',
  4385. sourceTable: '',
  4386. newYCheckQty: ''
  4387. };
  4388. $scope.sourceInfo.sourceId = item.sourceId;
  4389. $scope.sourceInfo.sourceTable = item.sourceTable;
  4390. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  4391. sourceInfos.push($scope.sourceInfo);
  4392. });
  4393. FaApCheck.update({}, sourceInfos, function(){
  4394. },function(response){
  4395. $scope.loading = false;
  4396. toaster.pop('error', '更新已转数失败', response.data);
  4397. });
  4398. }
  4399. //删除应收对账单
  4400. $scope.deleteApCheck = function(){
  4401. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  4402. updateYCheckQty();
  4403. toaster.pop('success','提示','删除成功');
  4404. },function(){
  4405. toaster.pop('error','提示','删除失败');
  4406. });
  4407. $scope.haveSelected = false;
  4408. }
  4409. //作废应收对账单
  4410. $scope.cancelApCheck = function(check) {
  4411. FaApCheck.cancel({id:check.id},function(data){
  4412. $scope.checkResult = false;
  4413. if(data.result) {
  4414. $scope.checkResult = true;
  4415. toaster.pop('success', '提示', '作废成功');
  4416. $scope.tableParams.reload();
  4417. }else{
  4418. toaster.pop('error', '提示', '作废失败');
  4419. }
  4420. },function(){
  4421. $scope.loading = false;
  4422. toaster.pop('error', '提示', '作废失败');
  4423. });
  4424. }
  4425. }]);
  4426. //未对账单据列表
  4427. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  4428. $scope.data = {};// 列表数据
  4429. $scope.loading = true;
  4430. $scope.getData = function(){
  4431. FaApCheck.getAll(function(data){
  4432. $scope.data = data;
  4433. angular.forEach($scope.data, function(item) {
  4434. item:{
  4435. $selected:true;
  4436. }
  4437. });
  4438. $scope.loading = false;
  4439. });
  4440. }
  4441. document.getElementById('suuorname').focus();//光标默认在客户
  4442. $scope.getData();
  4443. $scope.condition = {
  4444. $fromOpened:false
  4445. }
  4446. $scope.openDatePicker = function($event, item, openParam) {
  4447. $event.preventDefault();
  4448. $event.stopPropagation();
  4449. item[openParam] = !item[openParam];
  4450. }
  4451. //查找客户
  4452. $scope.searchCust = function(suuorname) {
  4453. var modalInstance = $modal.open({
  4454. animation: true,
  4455. templateUrl: 'static/tpl/index/fa/custInfo.html',
  4456. controller: 'SearchCustInfoCtrl',
  4457. resolve: {
  4458. suuorname: function() {
  4459. return suuorname;
  4460. }
  4461. }
  4462. });
  4463. modalInstance.result.then(function(suuorname){
  4464. $scope.suuorname = suuorname;
  4465. });
  4466. }
  4467. // 点击筛选根据条件选择数据
  4468. $scope.suuorname = '';
  4469. $scope.sdateFrom = '';
  4470. $scope.sdateTo = '';
  4471. $scope.vuuorname = '';
  4472. $scope.factory = '';
  4473. $scope.prodTitle = '';
  4474. $scope.prodSpec = '';
  4475. $scope.condition.uuorname = '';
  4476. $scope.condition.dateFrom = '';
  4477. $scope.condition.dateTo = '';
  4478. $scope.condition.venduuorname = '';
  4479. $scope.condition.factory = '';
  4480. $scope.condition.prodTitle = '';
  4481. $scope.condition.prodSpec = '';
  4482. $scope.searchOrder = function(check) {
  4483. angular.forEach($scope.data, function(item) {
  4484. $scope.checkboxes.checked = false;
  4485. item.$selected = false;
  4486. });
  4487. // if($scope.suuorname == '') {
  4488. // toaster.pop('info','提示', '请先输入客户');
  4489. // document.getElementById('suuorname').focus();//光标默认在客户
  4490. // }
  4491. $scope.totalMoney = 0;
  4492. $scope.condition.uuorname = $scope.suuorname;
  4493. $scope.condition.factory = $scope.factory
  4494. $scope.condition.prodTitle = $scope.prodTitle;
  4495. $scope.condition.prodSpec = $scope.prodSpec;
  4496. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  4497. $scope.thisdatato = ($scope.sdateTo || 0);
  4498. if($scope.thisdatato != 0) {
  4499. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  4500. } else {
  4501. $scope.condition.dateTo = ($scope.sdateTo || 0);
  4502. }
  4503. $scope.condition.venduuorname = $scope.vuuorname;
  4504. //物料名称和物料规格存在特殊符号,用|作分割符
  4505. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  4506. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  4507. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  4508. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  4509. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  4510. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4511. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4512. if($scope.keywordXls.length == 4){
  4513. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null) {
  4514. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4515. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4516. FaApCheck.getAllByDate({fromDate: $scope.fromDate, endDate: $scope.endDate}, function(data) {
  4517. $scope.data = data;
  4518. angular.forEach($scope.data, function(item) {
  4519. item:{
  4520. $selected:true;
  4521. }
  4522. });
  4523. $scope.loading = false;
  4524. }, function(response) {
  4525. toaster.pop('error', '提示', response.data);
  4526. });
  4527. }
  4528. }
  4529. }
  4530. /**
  4531. * 点击勾选框,选中要转应收对账单的订单
  4532. * */
  4533. $scope.totalMoney = 0;
  4534. $scope.checkboxes = {
  4535. checked : false
  4536. };
  4537. // 点击勾选全部的复选框
  4538. $scope.checkAll = function(){
  4539. $scope.totalMoney = 0;
  4540. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  4541. var uuorname = $scope.suuorname;
  4542. var venduuorname = $scope.venduuorname;
  4543. var dateFrom = $scope.condition.dateFrom;
  4544. var dateTo = $scope.condition.dateTo;
  4545. var prodTitle = $scope.condition.prodTitle;
  4546. var prodSpec = $scope.condition.prodSpec;
  4547. var factory = $scope.condition.factory;
  4548. angular.forEach($scope.filteredData, function(item) {
  4549. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  4550. item.$selected = $scope.checkboxes.checked;
  4551. }
  4552. });
  4553. $scope.getTotalMoney();
  4554. };
  4555. //获取已选单据总金额
  4556. var total = true;
  4557. $scope.getTotalMoney = function(){
  4558. $scope.totalMoney = 0;
  4559. angular.forEach($scope.data, function(check) {
  4560. if(check.$selected){
  4561. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4562. }else{
  4563. $scope.totalMoney += 0;
  4564. }
  4565. });
  4566. }
  4567. // 点击其中一个明细的复选框
  4568. $scope.checkOne = function(check){
  4569. var result = true;
  4570. angular.forEach($scope.data, function(item) {
  4571. if(item.$selected != true){
  4572. result = false;
  4573. return;
  4574. }
  4575. });
  4576. $scope.checkboxes.checked = result;
  4577. };
  4578. $scope.haveSelected = false;
  4579. //生成应收对账单
  4580. $scope.createApCheck = function(){
  4581. //保存应收对账单主记录字段
  4582. $scope.apCheck = {
  4583. custUu: '',
  4584. custName: '',
  4585. enUu: '',
  4586. apDate: '',
  4587. beginDate: '',
  4588. endDate: '',
  4589. checkStatus: '未对账',
  4590. checkAmount: 0,
  4591. currency: '',
  4592. rate: '',
  4593. items: []
  4594. };
  4595. //保存来源单据相关信息
  4596. var sourceInfos = [];
  4597. //所允许的本次对账最大最小数量
  4598. $scope.data.maxThisCheckQty = 0;
  4599. $scope.data.minThisCheckQty = 0;
  4600. $scope.sameCust = true;
  4601. $scope.validQty = true;
  4602. $scope.loading = true;
  4603. angular.forEach($scope.data, function(check) {
  4604. //保存应收对账单明细行数据
  4605. $scope.item = {
  4606. inoutno: '',
  4607. inoutnodetno: '',
  4608. orderCode: '',
  4609. orderClass: '',
  4610. orderDetno: '',
  4611. price: '',
  4612. checkQty: '',
  4613. amount: '',
  4614. sourceId:'',
  4615. sourceTable:'',
  4616. oldYCheckQty:'',
  4617. status: 0,
  4618. receiveCode:'',
  4619. receiveName:'',
  4620. prodCode:'',
  4621. prodTitle:'',
  4622. prodSpec:'',
  4623. taxrate: '',
  4624. sendcode: '',
  4625. whname: '',
  4626. };
  4627. //应收对账单明细行来源表信息
  4628. $scope.sourceInfo = {
  4629. sourceId: '',
  4630. sourceTable: '',
  4631. newYCheckQty: ''
  4632. };
  4633. //此次对账后新的已转数
  4634. $scope.newYCheckQty = 0;
  4635. if(check.$selected == true) {
  4636. $scope.apCheck.custName = check.custName;
  4637. $scope.apCheck.enUu = check.enUu;
  4638. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4639. $scope.apCheck.apDate = check.piDate;
  4640. $scope.apCheck.rate = check.rate;
  4641. //必须是同一家客户才能生成对账单,否则提示错误
  4642. if($scope.apCheck.custUu == ''){
  4643. $scope.apCheck.custUu = check.custUu;
  4644. }else if($scope.apCheck.custUu !== check.custUu){
  4645. $scope.sameCust = false;
  4646. $scope.loading = false;
  4647. toaster.pop('error', '请选择同一家客户');
  4648. }
  4649. //必须是相同币别才能生成对账单,否则提示错误
  4650. if($scope.apCheck.currency == ''){
  4651. $scope.apCheck.currency = check.currency;
  4652. }else if($scope.apCheck.currency !== check.currency){
  4653. $scope.sameCust = false;
  4654. $scope.loading = false;
  4655. toaster.pop('error', '请选择同一种币别');
  4656. }
  4657. //本次对账数量必须小于总对账数量
  4658. if(check.qty > 0){
  4659. $scope.data.maxThisCheckQty = check.qty;
  4660. $scope.data.minThisCheckQty = 0;
  4661. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  4662. $scope.validQty = false;
  4663. $scope.loading = false;
  4664. toaster.pop('error','本次对账数量,填写有误!');
  4665. }
  4666. }else if(check.qty < 0){
  4667. $scope.data.maxThisCheckQty = 0;
  4668. $scope.data.minThisCheckQty = check.qty;
  4669. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  4670. $scope.validQty = false;
  4671. $scope.loading = false;
  4672. toaster.pop('error','本次对账数量,填写有误!');
  4673. }
  4674. }
  4675. //获取最小时间作为对账区间的起始时间
  4676. if($scope.apCheck.beginDate == ''){
  4677. $scope.apCheck.beginDate = check.piDate;
  4678. }else{
  4679. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  4680. }
  4681. //获取最大时间作为对账区间的截止时间
  4682. if($scope.apCheck.endDate == ''){
  4683. $scope.apCheck.endDate = check.piDate;
  4684. }else{
  4685. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  4686. }
  4687. //应收对账单明细行数据
  4688. $scope.item.orderCode = check.orderCode;
  4689. $scope.item.orderClass = check.piClass;
  4690. $scope.item.orderDetno = check.orderDetno;
  4691. $scope.item.price = check.orderPrice;
  4692. $scope.item.checkQty = check.thisCheckQty;
  4693. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  4694. $scope.item.sourceId = check.sourceId;
  4695. $scope.item.sourceTable = check.sourceTable;
  4696. $scope.item.oldYCheckQty = check.yCheckQty;
  4697. $scope.item.prodCode = check.prodCode;
  4698. $scope.item.prodTitle = check.prodTitle;
  4699. $scope.item.prodSpec = check.prodSpec;
  4700. $scope.item.inoutno = check.inOutNo;
  4701. $scope.item.inoutnodetno = check.detno;
  4702. $scope.item.taxrate = check.taxrate;
  4703. $scope.item.receiveCode = check.receiveCode;
  4704. $scope.item.receiveName = check.receiveName;
  4705. $scope.item.sendcode = check.sendcode;
  4706. $scope.item.whname = check.whname;
  4707. //来源表相关信息
  4708. $scope.sourceInfo.sourceId = check.sourceId;
  4709. $scope.sourceInfo.sourceTable = check.sourceTable;
  4710. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  4711. sourceInfos.push($scope.sourceInfo);
  4712. $scope.apCheck.items.push($scope.item);
  4713. $scope.haveSelected = true;
  4714. }
  4715. });
  4716. //保存生成的应收对账单
  4717. $scope.saveApCheck = function(){
  4718. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  4719. $scope.loading = false;
  4720. toaster.pop('success', '成功', '生成应收对账成功');
  4721. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  4722. }, function(response){
  4723. toaster.pop('error', '生成对账单失败', response.data);
  4724. })
  4725. };
  4726. //如果是同一家客户,生成对账单的同时,关闭模态框
  4727. if($scope.sameCust && $scope.validQty) {
  4728. $scope.saveApCheck();
  4729. }
  4730. }
  4731. }]);
  4732. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
  4733. $scope.loading = true;
  4734. AccountEnterprise.get({}, function(data){
  4735. $scope.loading = false;
  4736. $scope.enterprise = data;
  4737. });
  4738. AccountEnterprise.growth({}, function(data){
  4739. if(data != null && data.length > 0) {
  4740. var growth = [], years = [];
  4741. angular.forEach(data, function(d){
  4742. var date = new Date(d.date), year = date.getFullYear();
  4743. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  4744. if(years.indexOf(year) == -1) {
  4745. years.push(year);
  4746. growth.push({year: year});
  4747. }
  4748. growth.push(d);
  4749. });
  4750. $scope.growth = growth;
  4751. }
  4752. });
  4753. // 更新企业信息
  4754. $scope.updateDetailInfo = function(){
  4755. $scope.loading = true;
  4756. AccountEnterprise.save($scope.enterprise, function(){
  4757. $scope.loading = false;
  4758. $scope.connectionEditing = false;
  4759. toaster.pop('success', '提示', '修改企业信息成功');
  4760. $state.reload();
  4761. }, function(response){
  4762. $scope.loading = false;
  4763. toaster.pop('error', '修改信息失败', response.data);
  4764. });
  4765. };
  4766. // 申请Saas
  4767. $scope.applySaas = function(){
  4768. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  4769. var modalInstance = $modal.open({
  4770. animation: true,
  4771. templateUrl: 'static/tpl/index/account/applySaas.html',
  4772. controller: 'ApplySaasCtrl',
  4773. resolve: {
  4774. enterprise: function(){return angular.copy($scope.enterprise);}
  4775. }
  4776. });
  4777. modalInstance.result.then(function(){
  4778. $state.reload();
  4779. }, function(){
  4780. });
  4781. } else {
  4782. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  4783. }
  4784. };
  4785. }]);
  4786. // 申请Saas Controller
  4787. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  4788. $scope.enterprise = enterprise;
  4789. $scope.checking = false;
  4790. $scope.$watch('enterprise.enSaasUrl', function(){
  4791. if($scope.enterprise.enSaasUrl) {
  4792. $http.get('signup/saasUrlEnable', {
  4793. params: {
  4794. enSaasUrl: $scope.enterprise.enSaasUrl
  4795. }
  4796. }).success(function(data){
  4797. if(data && data == 'true') {
  4798. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  4799. } else {
  4800. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  4801. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  4802. }
  4803. }).error(function(){
  4804. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  4805. $scope.enSaasUrlErrorInfo = '验证出错';
  4806. });
  4807. } else {
  4808. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  4809. }
  4810. });
  4811. var setSaasUrl = function(url) {
  4812. var index = url.indexOf('www.');
  4813. if(index != -1) {//包含www.
  4814. var substr = url.substring(index+4, url.length);
  4815. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  4816. } else {
  4817. $scope.enterprise.enSaasUrl = getHost(url);
  4818. }
  4819. };
  4820. // 解析获取网址的一级域名
  4821. var getHost = function(host){
  4822. var newhost;
  4823. var domain;
  4824. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  4825. for(var k in ArrDomain){
  4826. var re = eval('/\\' + ArrDomain[k] + '$/g');
  4827. newhost = host.replace(re, '');
  4828. if(newhost != host){
  4829. domain = ArrDomain[k];
  4830. break;
  4831. }
  4832. }
  4833. var hostar = newhost.split('.');
  4834. var s = hostar[hostar.length-1];
  4835. return s;
  4836. };
  4837. // 设置优企云服域名为官网网址一级域名
  4838. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  4839. $scope.apply = function(){
  4840. $scope.loading = true;
  4841. AccountEnterprise.applySaas({
  4842. enUU: $scope.enterprise.uu,
  4843. enSaasUrl: $scope.enterprise.enSaasUrl,
  4844. enAdminPassword: $scope.enterprise.enAdminPassword
  4845. }, {}, function(){
  4846. $scope.loading = false;
  4847. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  4848. $modalInstance.close();
  4849. }, function(response){
  4850. $scope.loading = false;
  4851. toaster.pop('error', '申请失败', response.data);
  4852. });
  4853. };
  4854. $scope.cancel = function () {
  4855. $modalInstance.dismiss();
  4856. };
  4857. }]);
  4858. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert){
  4859. $scope.editing = false;
  4860. $scope.loading = true;
  4861. AccountUser.findDistribute({},function(data) {
  4862. $scope.distributes = data;
  4863. },function(response) {
  4864. toaster.pop('error', '系统错误', response.data);
  4865. })
  4866. AuthenticationService.getAuthentication().success(function(data) {
  4867. $scope.loading = false;
  4868. $scope.user = data;
  4869. });
  4870. var users = [];
  4871. $scope.tableParams = new ngTableParams({
  4872. page : 1,
  4873. count : 5,
  4874. sorting: {
  4875. userName: 'asc'
  4876. }
  4877. }, {
  4878. total : 0,
  4879. counts: [15, 25, 50, 100],
  4880. getData : function($defer, params) {
  4881. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  4882. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  4883. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  4884. params.total(orderedData.length);
  4885. $defer.resolve($scope.users);
  4886. }
  4887. });
  4888. var loadUsers = function() {
  4889. AccountUser.query({}, function(data){
  4890. users = data;
  4891. $scope.tableParams.reload();
  4892. $scope.loading = false;
  4893. });
  4894. };
  4895. loadUsers();
  4896. $scope.saveUser = function(){
  4897. $scope.loading = true;
  4898. AccountUser.update({}, $scope.user, function(data){
  4899. $scope.loading = false;
  4900. toaster.pop('success', '提示', '修改用户信息成功');
  4901. AuthenticationService.getAuthentication().success(function(data) {
  4902. $scope.user = data;
  4903. });
  4904. loadUsers();
  4905. $scope.editing = false;
  4906. }, function(reponse){
  4907. $scope.loading = false;
  4908. toaster.pop('error', '失败', reponse.data);
  4909. });
  4910. };
  4911. $scope.updatePassword = function(){
  4912. var modalInstance = $modal.open({
  4913. animation: true,
  4914. templateUrl: 'updatePassword.html',
  4915. controller: 'PasswordCtrl',
  4916. resolve: {
  4917. user: function(){return $scope.user;}
  4918. }
  4919. });
  4920. modalInstance.result.then(function(){
  4921. }, function(){
  4922. });
  4923. };
  4924. $scope.newUser = {};
  4925. //弹出添加用户模态框
  4926. $scope.addExistUser = function(){
  4927. var modalInstance = $modal.open({
  4928. animation :true,
  4929. templateUrl : 'static/tpl/index/account/addExistUser.html',
  4930. controller : 'AddExistUserCtrl'
  4931. });
  4932. modalInstance.result.then(function(){
  4933. $scope.userTelSuccess = false;
  4934. $scope.userTelError = false;
  4935. }, function(){
  4936. });
  4937. };
  4938. /**
  4939. * 添加未注册用户
  4940. */
  4941. $scope.addUser = function() {
  4942. $scope.adding = true;
  4943. AccountUser.save({}, $scope.newUser, function(){
  4944. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  4945. $scope.newUser = {userSex: 'M'};
  4946. loadUsers();
  4947. $scope.adding = false;
  4948. $scope.newUserForm.newUserTel.$setValidity('available', false);
  4949. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  4950. $scope.userTelSuccess = false;
  4951. $scope.userTelError = false;
  4952. $scope.userEmailSuccess = false;
  4953. $scope.userEmailError = false;
  4954. }, function(response){
  4955. toaster.pop('error', '错误', response.data);
  4956. });
  4957. };
  4958. /**
  4959. * 验证手机号是否可用
  4960. */
  4961. $scope.telValid = function(tel) {
  4962. if(tel) {
  4963. $http.get('account/user/telEnable', {
  4964. params: {
  4965. tel: tel
  4966. }
  4967. }).success(function(data){
  4968. data = eval(data);
  4969. if(data == true) {
  4970. $scope.newUserForm.newUserTel.$setValidity('available', true);
  4971. $scope.userTelSuccess = true;
  4972. $scope.userTelError = false;
  4973. }else{
  4974. $scope.newUserForm.newUserTel.$setValidity('available', false);
  4975. $scope.userTelError = true;
  4976. $scope.userTelSuccess = false;
  4977. if(tel.length == 11)
  4978. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  4979. }
  4980. }).error(function(){
  4981. $scope.userTelSuccess = false;
  4982. $scope.userTelError = true;
  4983. });
  4984. } else {
  4985. $scope.userTelSuccess = false;
  4986. $scope.userTelError = false;
  4987. }
  4988. };
  4989. /**
  4990. * 验证邮箱是否可用
  4991. */
  4992. $scope.emailValid = function(email) {
  4993. if(email) {
  4994. $http.get('account/user/emailEnable', {
  4995. params: {
  4996. email: email
  4997. }
  4998. }).success(function(data){
  4999. data = eval(data);
  5000. if(data == true) {
  5001. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  5002. $scope.userEmailSuccess = true;
  5003. $scope.userEmailError = false;
  5004. } else {
  5005. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  5006. $scope.userEmailError = true;
  5007. $scope.userEmailSuccess = false;
  5008. }
  5009. }).error(function(){
  5010. $scope.userEmailError = true;
  5011. $scope.userEmailSuccess = false;
  5012. });
  5013. } else {
  5014. $scope.userEmailError = false;
  5015. $scope.userEmailSuccess = false;
  5016. }
  5017. };
  5018. /**
  5019. * 删除用户
  5020. */
  5021. $scope.removeUser = function(user) {
  5022. new ngAlert({
  5023. title: '提示',
  5024. content: '确定删除用户(' + user.userName + ')吗?'
  5025. }, function(){
  5026. AccountUser.remove({uu: user.userUU}, function(){
  5027. toaster.pop('success', '提示', '用户删除成功。');
  5028. loadUsers();
  5029. }, function(response){
  5030. toaster.pop('error', '删除失败', response.data);
  5031. });
  5032. });
  5033. };
  5034. // 编辑用户的角色
  5035. $scope.editUserRole = function(user) {
  5036. var modalInstance = $modal.open({
  5037. animation: true,
  5038. templateUrl: 'static/tpl/index/account/user_role.html',
  5039. controller: 'UserRoleCtrl',
  5040. resolve: {
  5041. user: function() {
  5042. return user;
  5043. }
  5044. }
  5045. });
  5046. modalInstance.result.then(function(changed, checked){
  5047. if(changed) {
  5048. if(checked)
  5049. $scope.newUser.roles = checked;
  5050. else
  5051. loadUsers();
  5052. }
  5053. });
  5054. };
  5055. // 为用户分配角色(删除企业)
  5056. $scope.removeVendor = function(user) {
  5057. var resultRole = true;
  5058. angular.forEach(user.roles,function(role){
  5059. if(role.issys == 1) {
  5060. toaster.pop('error', '提示', '管理员无需分配客户');
  5061. resultRole = false;
  5062. return;
  5063. }
  5064. })
  5065. if(resultRole) {
  5066. var modalInstance = $modal.open({
  5067. animation: true,
  5068. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  5069. controller: 'RemoveVendorCtrl',
  5070. resolve: {
  5071. user: function() {
  5072. return user;
  5073. }
  5074. }
  5075. });
  5076. }
  5077. }
  5078. // 为用户分配角色(添加企业)
  5079. $scope.addVendor = function(user,isIssy) {
  5080. if(!isIssy) {
  5081. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  5082. return;
  5083. }
  5084. var resultRole = true;
  5085. angular.forEach(user.roles,function(role){
  5086. if(role.issys == 1) {
  5087. toaster.pop('error', '提示', '管理员无需分配客户');
  5088. resultRole = false;
  5089. return;
  5090. }
  5091. })
  5092. if(resultRole) {
  5093. var modalInstance = $modal.open({
  5094. animation: true,
  5095. templateUrl: 'static/tpl/index/account/add_vendor.html',
  5096. controller: 'AddVendorCtrl',
  5097. resolve: {
  5098. user: function() {
  5099. return user;
  5100. }
  5101. }
  5102. });
  5103. modalInstance.result.then(function(changed, checked){
  5104. if(changed) {
  5105. if(checked)
  5106. $scope.newUser.roles = checked;
  5107. else
  5108. loadUsers();
  5109. }
  5110. });
  5111. }
  5112. };
  5113. }]);
  5114. // 登录手机号码验证
  5115. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  5116. $scope.user = user;
  5117. $scope.cancel = function(){
  5118. $modalInstance.close();
  5119. }
  5120. /*$scope.loading = false;
  5121. $scope.btnState = false;
  5122. $scope.clicks = 0;
  5123. var storage = window.localStorage;
  5124. //手机验证码定时器
  5125. $scope.msgInfoError = false;
  5126. var setBtnTimeDown = function(value) {
  5127. if(value > 0) {
  5128. $scope.btnState = true;
  5129. $timeout(function() {
  5130. $scope.$apply(function(){
  5131. storage.setItem("btnTimes", $scope.btnTimes);
  5132. $scope.btnTimes --;
  5133. value --;
  5134. setBtnTimeDown (value);
  5135. });
  5136. }, 500);
  5137. }else{
  5138. $scope.btnState = false;
  5139. }
  5140. };
  5141. if(storage.btnTimes > 1){
  5142. $scope.btnTimes = storage.btnTimes;
  5143. setBtnTimeDown(storage.btnTimes)
  5144. }else{
  5145. storage.removeItem("btnTimes");
  5146. }
  5147. $scope.updateTel = function(phoneCode, userTel, uu){
  5148. $scope.loading = true;
  5149. $scope.msgInfoError = false;
  5150. $scope.result = false;
  5151. //更新联系方式
  5152. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  5153. $scope.loading = false;
  5154. $scope.msgInfoError2 = false;
  5155. $scope.result = true;
  5156. AuthenticationService.getAuthentication().success(function(data) {
  5157. $timeout(function(){
  5158. $modalInstance.dismiss();
  5159. window.location.reload();
  5160. }, 1000);
  5161. }).error(function(response) {
  5162. });
  5163. }, function(response){
  5164. $scope.loading = false;
  5165. $scope.msgInfoError2 = response;
  5166. });
  5167. };
  5168. //获取验证码
  5169. $scope.getPhoneCode = function(userTel){
  5170. var timeInfo = 10;
  5171. $scope.clicks ++;
  5172. $scope.timeInfo = timeInfo;
  5173. if($scope.clicks >= 5){
  5174. $scope.errorloading = true;
  5175. $scope.msgInfoSuccess = false;
  5176. $scope.msgInfoError = false;
  5177. }else{
  5178. $scope.loading = true;
  5179. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  5180. $scope.loading = false;
  5181. $scope.msgInfoSuccess = data.success;
  5182. $scope.sendMsg = data;
  5183. $scope.btnTimes = 60;
  5184. setBtnTimeDown($scope.btnTimes);
  5185. $scope.msgInfoError = false;
  5186. },function(response){
  5187. console.log(response);
  5188. $scope.loading = false;
  5189. $scope.msgInfoError = false;
  5190. $scope.sendCheckMsg = false;
  5191. $scope.msgInfoSuccess = true;
  5192. });
  5193. }
  5194. }; */
  5195. }]);
  5196. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5197. $scope.checkboxes = {
  5198. checked : false
  5199. };
  5200. $scope.loading = true;
  5201. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  5202. $scope.enters = data;
  5203. $scope.loading = false;
  5204. angular.forEach($scope.enters, function(item) {
  5205. item:{
  5206. $selected:true;
  5207. }
  5208. });
  5209. })
  5210. // 点击勾选全部的复选框
  5211. $scope.checkAll = function() {
  5212. angular.forEach($scope.enters, function(item) {
  5213. item.$selected = $scope.checkboxes.checked;
  5214. });
  5215. };
  5216. // 点击其中一个明细的复选框
  5217. $scope.checkOne = function(vendor){
  5218. var result = true;
  5219. angular.forEach($scope.enters, function(item) {
  5220. if(item.$selected != true){
  5221. result = false;
  5222. return;
  5223. }
  5224. });
  5225. $scope.checkboxes.checked = result;
  5226. };
  5227. $scope.close = function(save) {
  5228. var chooseResult = [];
  5229. if(save) {
  5230. if(user.userUU) {
  5231. angular.forEach($scope.enters, function(item, i) {
  5232. if(item.$selected) {
  5233. chooseResult.push(item.id);
  5234. }
  5235. });
  5236. if(chooseResult.length > 0) {
  5237. $scope.loading = true;
  5238. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  5239. $scope.loading = false;
  5240. toaster.pop('success', '提示', '删除成功');
  5241. $modalInstance.close(false);
  5242. }, function(response){
  5243. $scope.loading = false;
  5244. toaster.pop('error', '删除失败', response.data);
  5245. $modalInstance.close(false);
  5246. })
  5247. } else {
  5248. toaster.pop('error', '删除失败', "您未勾选任何记录");
  5249. }
  5250. } else {
  5251. $modalInstance.close(true, $scope.checkboxes.checked);
  5252. }
  5253. } else {
  5254. $modalInstance.close(false);
  5255. }
  5256. };
  5257. }]);
  5258. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5259. $scope.checkboxes = {
  5260. checked : false
  5261. };
  5262. $scope.loading = true;
  5263. AccountUser.findVendor({uu : user.userUU},function(data) {
  5264. $scope.enters = data;
  5265. $scope.loading = false;
  5266. // angular.forEach($scope.enters, function(item) {
  5267. // if(item.distribute) {
  5268. // item:{
  5269. // $selected:false;
  5270. // }
  5271. // } else {
  5272. // item:{
  5273. // $selected:true;
  5274. // }
  5275. // }
  5276. // });
  5277. })
  5278. // 点击勾选全部的复选框
  5279. $scope.checkAll = function() {
  5280. angular.forEach($scope.enters, function(item) {
  5281. item.distribute = $scope.checkboxes.checked;
  5282. });
  5283. };
  5284. // 点击其中一个明细的复选框
  5285. $scope.checkOne = function(vendor){
  5286. var result = true;
  5287. angular.forEach($scope.enters, function(item) {
  5288. if(item.distribute != true){
  5289. result = false;
  5290. return;
  5291. }
  5292. });
  5293. $scope.checkboxes.checked = result;
  5294. };
  5295. $scope.close = function(save) {
  5296. var chooseResult = [];
  5297. if(save) {
  5298. if(user.userUU) {
  5299. angular.forEach($scope.enters, function(item, i) {
  5300. // if(item.distribute) {
  5301. chooseResult.push(item);
  5302. // }
  5303. });
  5304. if(chooseResult.length > 0) {
  5305. $scope.loading = true;
  5306. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  5307. $scope.loading = false;
  5308. toaster.pop('success', '提示', '保存成功');
  5309. $modalInstance.close(false);
  5310. }, function(response){
  5311. $scope.loading = false;
  5312. toaster.pop('error', '保存失败', response.data);
  5313. $modalInstance.close(false);
  5314. })
  5315. } else {
  5316. toaster.pop('error', '保存失败', "您未勾选任何记录");
  5317. }
  5318. } else {
  5319. $modalInstance.close(true, $scope.checkboxes.checked);
  5320. }
  5321. } else {
  5322. $modalInstance.close(false);
  5323. }
  5324. };
  5325. }]);
  5326. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  5327. $scope.checked = [];
  5328. $scope.master = [];
  5329. AccountRole.query({}, function(data){
  5330. if(user && data) {
  5331. var rs = [], checked = [];
  5332. angular.forEach(user.roles, function(r){
  5333. rs.push(r.id);
  5334. });
  5335. angular.forEach(data, function(d){
  5336. if(rs.indexOf(d.id) > -1) {
  5337. d.$checked = true;
  5338. checked.push(d);
  5339. }
  5340. });
  5341. }
  5342. $scope.roles = data;
  5343. $scope.checked = checked;
  5344. $scope.master = angular.copy($scope.checked);
  5345. });
  5346. $scope.select = function(role) {
  5347. role.$checked = !role.$checked;
  5348. if(role.$checked) {
  5349. $scope.checked.push(role);
  5350. } else {
  5351. angular.forEach($scope.checked, function(c, i){
  5352. if(c.id == role.id)
  5353. $scope.checked.splice(i, 1);
  5354. });
  5355. }
  5356. };
  5357. $scope.isChanged = function() {
  5358. return !angular.equals($scope.master, $scope.checked);
  5359. };
  5360. $scope.close = function(save) {
  5361. if(save) {
  5362. if(user.userUU) {
  5363. user.roles = $scope.checked;
  5364. AccountUser.update({}, user, function(){
  5365. toaster.pop('success', '提示', '保存成功');
  5366. $modalInstance.close(true);
  5367. }, function(response){
  5368. toaster.pop('error', '保存失败', response.data);
  5369. });
  5370. } else {
  5371. $modalInstance.close(true, $scope.checked);
  5372. }
  5373. } else {
  5374. $modalInstance.close(false);
  5375. }
  5376. };
  5377. }]);
  5378. // 修改密码Controller
  5379. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  5380. $scope.user = user;
  5381. $scope.checking = false;
  5382. //输入原密码后验证原密码是否正确
  5383. $scope.checkPassword = function(password) {
  5384. $scope.checking = true;
  5385. $scope.checkSuccess = false;
  5386. $scope.checkFailed = false;
  5387. AccountUser.checkPassword({password: password}, function(data){
  5388. $scope.checkSuccess = true;
  5389. $scope.checking = false;
  5390. $scope.checkFailed = false;
  5391. }, function(response){
  5392. $scope.checkFailed = true;
  5393. $scope.checking = false;
  5394. $scope.checkSuccess = false;
  5395. });
  5396. };
  5397. //修改密码
  5398. $scope.ok = function () {
  5399. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  5400. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  5401. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  5402. $scope.user.password = null;
  5403. $scope.user.newPassword = null;
  5404. $scope.user.newPassword1 = null;
  5405. $scope.checking = false;
  5406. $scope.checkSuccess = false;
  5407. $scope.checkFailed = false;
  5408. }, function(response){
  5409. toaster.pop('error', '错误', response.data);
  5410. });
  5411. } else {
  5412. toaster.pop('error', '错误', '重复密码不一致');
  5413. }
  5414. };
  5415. $scope.cancel = function () {
  5416. $modalInstance.dismiss();
  5417. };
  5418. }]);
  5419. /*
  5420. * 绑定用户到企业
  5421. */
  5422. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', function($scope, $modalInstance, FuzzySearch,AuthenticationService){
  5423. $scope.searching = false;
  5424. //根据输入的内容查找用户
  5425. $scope.searchUser = function(keyWord) {
  5426. $scope.searching = true;
  5427. $scope.searchSuccess = false;
  5428. $scope.searchFailed = false;
  5429. $scope.illegalError = false;
  5430. $scope.reBindError = false;
  5431. $scope.bindSuccess = false;
  5432. $scope.okDisabled = false;
  5433. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  5434. $scope.searchSuccess = true;
  5435. $scope.searchFailed = false;
  5436. $scope.user = data; //查询到的用户
  5437. }, function(response){
  5438. $scope.searchSuccess = false;
  5439. $scope.searchFailed = true;
  5440. });
  5441. };
  5442. //确认绑定
  5443. $scope.ok = function (keyWord) {
  5444. AuthenticationService.getAuthentication().success(function(data) {
  5445. $scope.currentUser = data; //当前登录的用户(管理员)
  5446. //不可自己绑定自己
  5447. if($scope.currentUser.userUU == $scope.user.userUU){
  5448. $scope.illegalError = true;
  5449. $scope.okDisabled = true;
  5450. return false;
  5451. }
  5452. //用户未绑定到任何企业时
  5453. if(!$scope.user.enterprises){
  5454. //正常绑定
  5455. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  5456. $scope.bindSuccess = true; //绑定成功
  5457. $scope.okDisabled = true;
  5458. }, function(response){
  5459. });
  5460. return true;
  5461. }
  5462. //用户已绑定到某些企业时
  5463. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  5464. if($scope.currentUser.enterprises[i].current){
  5465. for(var j = 0; j < $scope.user.enterprises.length; j++){
  5466. //该用户已绑定到当前企业,不可重复绑定
  5467. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  5468. $scope.reBindError = true;
  5469. $scope.okDisabled = true;
  5470. return false;
  5471. }
  5472. }
  5473. //该用户未绑定到当前企业,可以进行绑定
  5474. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  5475. $scope.bindSuccess = true; //绑定成功
  5476. $scope.okDisabled = true;
  5477. }, function(response){
  5478. console.log("绑定失败!");
  5479. });
  5480. }
  5481. }
  5482. });
  5483. };
  5484. $scope.cancel = function () {
  5485. $modalInstance.dismiss();
  5486. };
  5487. }]);
  5488. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  5489. $scope.erpParams = new ngTableParams({
  5490. page : 1,
  5491. count : 5,
  5492. sorting: {
  5493. time: 'desc'
  5494. }
  5495. }, {
  5496. total : 0,
  5497. counts: [5, 10, 25, 50],
  5498. getData : function($defer, params) {
  5499. $scope.loading = true;
  5500. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  5501. $scope.loading = false;
  5502. if(page) {
  5503. params.total(page.totalElements);
  5504. $defer.resolve(page.content);
  5505. }
  5506. }, function(response){
  5507. $scope.loading = false;
  5508. toaster.pop('error', '数据加载失败', response.data);
  5509. });
  5510. }
  5511. });
  5512. $scope.usageParams = new ngTableParams({
  5513. page : 1,
  5514. count : 5,
  5515. sorting: {
  5516. time: 'desc'
  5517. }
  5518. }, {
  5519. total : 0,
  5520. counts: [5, 10, 25, 50],
  5521. getData : function($defer, params) {
  5522. $scope.loading = true;
  5523. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  5524. $scope.loading = false;
  5525. if(page) {
  5526. params.total(page.totalElements);
  5527. $defer.resolve(page.content);
  5528. }
  5529. }, function(response){
  5530. $scope.loading = false;
  5531. toaster.pop('error', '数据加载失败', response.data);
  5532. });
  5533. }
  5534. });
  5535. }]);
  5536. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  5537. AccountResource.query({}, function(data){
  5538. if(data && data.length > 0) {
  5539. data[0].$open = true;
  5540. }
  5541. $scope.resources = data;
  5542. });
  5543. }]);
  5544. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  5545. $scope.roles = {};
  5546. var getData = function() {
  5547. AccountRole.query({}, function(data){
  5548. var defaults = [], custom = [];
  5549. angular.forEach(data, function(d){
  5550. if(d.isdefault == 1)
  5551. defaults.push(d);
  5552. else
  5553. custom.push(d);
  5554. });
  5555. $scope.roles = {defaults: defaults, custom: custom};
  5556. });
  5557. };
  5558. getData();
  5559. $scope.editRole = function(role){
  5560. var modalInstance = $modal.open({
  5561. animation: true,
  5562. templateUrl: 'static/tpl/index/account/role_detail.html',
  5563. controller: 'RoleEditCtrl',
  5564. resolve: {
  5565. role: function() {
  5566. return role;
  5567. }
  5568. }
  5569. });
  5570. modalInstance.result.then(function(added){
  5571. added && (getData());
  5572. });
  5573. };
  5574. }]);
  5575. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
  5576. $scope.role = role;
  5577. $scope.master = angular.copy($scope.role);
  5578. var isNew = role == null;
  5579. $scope.cancel = function() {
  5580. $modalInstance.close(false);
  5581. };
  5582. AccountResource.query({}, function(data){
  5583. if(data && data.length > 0) {
  5584. if(role && role.resourceItems) {
  5585. var rs = [];// 已分配的资源的id
  5586. angular.forEach(role.resourceItems, function(item){
  5587. rs.push(item.id);
  5588. });
  5589. angular.forEach(data, function(resource){
  5590. var c = 0;
  5591. angular.forEach(resource.items, function(item){
  5592. if(rs.indexOf(item.id) > -1) {
  5593. item.$checked = true;
  5594. c += 1;
  5595. }
  5596. });
  5597. resource.$checked = c == resource.items.length;
  5598. });
  5599. }
  5600. $scope.resourceItems = data[0].items;
  5601. data[0].$active = true;
  5602. }
  5603. $scope.resources = data;
  5604. $timeout(function(){
  5605. angular.forEach($scope.resources, function(resource){
  5606. var c = 0;
  5607. angular.forEach(resource.items, function(item){
  5608. item.$checked && (c+=1);
  5609. });
  5610. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5611. });
  5612. }, 100);
  5613. });
  5614. $scope.onItemClick = function(resource) {
  5615. $scope.resourceItems = resource.items;
  5616. angular.forEach($scope.resources, function(r){
  5617. r.$active = false;
  5618. });
  5619. resource.$active = true;
  5620. };
  5621. var getChecked = function() {
  5622. var items = [];
  5623. angular.forEach($scope.resources, function(resource){
  5624. angular.forEach(resource.items, function(item){
  5625. item.$checked && (items.push(item));
  5626. });
  5627. });
  5628. $scope.role.resourceItems = items;
  5629. };
  5630. $scope.onResourceChange = function(resource) {
  5631. angular.forEach(resource.items, function(item){
  5632. item.$checked = resource.$checked;
  5633. });
  5634. getChecked();
  5635. };
  5636. $scope.onItemChange = function() {
  5637. angular.forEach($scope.resources, function(resource){
  5638. if(resource.$active) {
  5639. var c = 0;
  5640. angular.forEach(resource.items, function(item){
  5641. item.$checked && (c+=1);
  5642. });
  5643. resource.$checked = (c == resource.items.length);
  5644. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  5645. }
  5646. });
  5647. getChecked();
  5648. };
  5649. $scope.isChanged = function(formData) {
  5650. if(!$scope.master)
  5651. return true;
  5652. return !angular.equals(formData, $scope.master);
  5653. };
  5654. $scope.save = function() {
  5655. $scope.master = angular.copy($scope.role);
  5656. AccountRole.save($scope.master, function(){
  5657. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  5658. $modalInstance.close(true);
  5659. }, function(response){
  5660. toaster.pop('error', '错误', response.data);
  5661. });
  5662. };
  5663. $scope.del = function() {
  5664. new ngAlert({
  5665. title: '提示',
  5666. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  5667. }, function(){
  5668. AccountRole.remove({id: role.id}, function(){
  5669. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  5670. $modalInstance.close(true);
  5671. }, function(response){
  5672. toaster.pop('error', '错误', response.data);
  5673. });
  5674. })
  5675. };
  5676. }]);
  5677. /**
  5678. * 委外订单
  5679. */
  5680. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  5681. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  5682. $scope.active = 'todo';
  5683. $scope.dateZoneText = '不限';
  5684. $scope.condition = {dateZone: -1};
  5685. $scope.changeDateZone = function(zone) {
  5686. $scope.condition.dateZone = zone;
  5687. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5688. $scope.condition.$dateZoneOpen = false;
  5689. getDateCondition(zone, $scope.condition);
  5690. $scope.tableParams.reload();
  5691. };
  5692. $scope.setActive = function(state) {
  5693. if($scope.active != state) {
  5694. $scope.active = state;
  5695. if($scope.tableParams.page() == 1)
  5696. $scope.tableParams.reload();
  5697. else
  5698. $scope.tableParams.page(1);
  5699. }
  5700. };
  5701. var getService = function() {
  5702. return MakeOrder;
  5703. };
  5704. $scope.tableParams = new ngTableParams({
  5705. page : 1,
  5706. count : 5,
  5707. sorting: {
  5708. date: 'desc'
  5709. }
  5710. }, {
  5711. total : 0,
  5712. counts: [5, 10, 25, 50],
  5713. getData : function($defer, params) {
  5714. $scope.loading = true;
  5715. var pageParams = params.url();
  5716. pageParams.searchFilter = {};
  5717. pageParams.searchFilter.keyword = $scope.keyword;
  5718. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5719. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5720. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5721. $scope.loading = false;
  5722. if(page) {
  5723. params.total(page.totalElement);
  5724. $defer.resolve(page.content);
  5725. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5726. }
  5727. }, function(response){
  5728. $scope.loading = false;
  5729. toaster.pop('error', '数据加载失败', response.data);
  5730. });
  5731. }
  5732. });
  5733. $scope.getOrderTotal = function(items) {
  5734. var sum = 0;
  5735. angular.forEach(items, function(item){
  5736. sum += item.qty * item.price;
  5737. });
  5738. return sum;
  5739. };
  5740. $scope.openDatePicker = function($event, item, openParam) {
  5741. $event.preventDefault();
  5742. $event.stopPropagation();
  5743. item[openParam] = !item[openParam];
  5744. };
  5745. $scope.parseDate = function(dateStr) {
  5746. if(dateStr)
  5747. return Date.parse(dateStr, 'yyyy-MM-dd');
  5748. return new Date();
  5749. };
  5750. // 打开回复
  5751. $scope.openReply = function(order) {
  5752. if(!order.reply) {
  5753. order.reply = {
  5754. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  5755. delivery: order.delivery
  5756. }
  5757. }
  5758. order.$editing = true;
  5759. };
  5760. // 关闭回复
  5761. $scope.closeReply = function(order) {
  5762. order.$editing = false;
  5763. }
  5764. // 搜索框回车
  5765. $scope.onSearch = function() {
  5766. $scope.tableParams.page(1);
  5767. $scope.tableParams.reload();
  5768. };
  5769. // 选择查找日期
  5770. $scope.onDateCondition = function(){
  5771. $scope.tableParams.page(1);
  5772. $scope.tableParams.reload();
  5773. };
  5774. // 点击回复
  5775. $scope.onReplyClick = function(order, inverse) {
  5776. if(order.reply) {
  5777. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  5778. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5779. return;
  5780. }
  5781. var reply = angular.copy(order.reply);
  5782. if(reply.delivery) {
  5783. if(typeof reply.delivery == 'object')
  5784. reply.delivery = reply.delivery.getTime();
  5785. } else {
  5786. reply.delivery = order.delivery;
  5787. }
  5788. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  5789. $scope.loading = true;
  5790. MakeOrder.reply({orderId: order.id}, reply, function(){
  5791. $scope.loading = false;
  5792. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  5793. $scope.tableParams.reload();
  5794. }, function(response){
  5795. $scope.loading = false;
  5796. toaster.pop('error', '回复失败', response.data);
  5797. });
  5798. }
  5799. };
  5800. //委外加工单
  5801. $scope.print = function(order) {
  5802. MakeOrder.printCount({id: order.id},{});//增加打印此次
  5803. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  5804. };
  5805. // 获取回复记录
  5806. $scope.getReply = function(order) {
  5807. if(!order.replies) {
  5808. MakeOrder.getReply({orderId: order.id}, function(replies){
  5809. order.replies = replies;
  5810. });
  5811. }
  5812. };
  5813. }]);
  5814. /**
  5815. * 委外加工单详细
  5816. */
  5817. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOrder, toaster, ReportService){
  5818. var loadData = function() {
  5819. MakeOrder.get({id: $stateParams.id}, function(data){
  5820. $scope.order = data;
  5821. var sum = $scope.order.qty * $scope.order.price;
  5822. $scope.order.total = sum;
  5823. $scope.loading = false;
  5824. });
  5825. };
  5826. loadData();
  5827. // 获取回复记录
  5828. $scope.getReply = function(item) {
  5829. if(!item.replies) {
  5830. MakeOrder.getReply({orderId: item.id}, function(replies){
  5831. item.replies = replies;
  5832. });
  5833. }
  5834. };
  5835. $scope.openDatePicker = function($event, item, openParam) {
  5836. $event.preventDefault();
  5837. $event.stopPropagation();
  5838. item[openParam] = !item[openParam];
  5839. };
  5840. // 点击回复
  5841. $scope.onReplyClick = function(order, inverse) {
  5842. if(order.reply) {
  5843. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  5844. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5845. return;
  5846. }
  5847. var reply = angular.copy(order.reply);
  5848. if(reply.delivery) {
  5849. if(typeof reply.delivery == 'object')
  5850. reply.delivery = reply.delivery.getTime();
  5851. } else {
  5852. reply.delivery = order.delivery;
  5853. }
  5854. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  5855. $scope.loading = true;
  5856. MakeOrder.reply({orderId: order.id}, reply, function(){
  5857. $scope.loading = false;
  5858. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  5859. loadData();
  5860. }, function(response){
  5861. $scope.loading = false;
  5862. toaster.pop('error', '回复失败', response.data);
  5863. });
  5864. }
  5865. };
  5866. // 打开回复
  5867. $scope.openReply = function(order) {
  5868. if(!order.reply) {
  5869. order.reply = {
  5870. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  5871. delivery: order.delivery
  5872. }
  5873. }
  5874. order.$editing = true;
  5875. };
  5876. // 关闭回复
  5877. $scope.closeReply = function(order) {
  5878. order.$editing = false;
  5879. }
  5880. // 委外订单
  5881. $scope.print = function(order) {
  5882. MakeOrder.printCount({id: order.id},{});//增加打印此次
  5883. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  5884. };
  5885. }]);
  5886. /**
  5887. * 客户委外验收
  5888. */
  5889. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  5890. $scope.active = 'all';
  5891. $scope.agreedText = '全部';
  5892. $scope.dateZoneText = '一个月内';
  5893. $scope.condition = {dateZone: 1};
  5894. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5895. $scope.changeAgreed = function(agreed) {
  5896. $scope.condition.agreed = agreed;
  5897. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5898. $scope.condition.$agreedOpen = false;
  5899. };
  5900. $scope.changeDateZone = function(zone) {
  5901. $scope.condition.dateZone = zone;
  5902. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5903. $scope.condition.$dateZoneOpen = false;
  5904. getDateCondition(zone, $scope.condition);
  5905. $scope.tableParams.reload();
  5906. };
  5907. $scope.setActive = function(state) {
  5908. if($scope.active != state) {
  5909. $scope.active = state;
  5910. if($scope.tableParams.page() == 1)
  5911. $scope.tableParams.reload();
  5912. else
  5913. $scope.tableParams.page(1);
  5914. }
  5915. };
  5916. var getService = function() {
  5917. return MakeAccept;
  5918. };
  5919. $scope.tableParams = new ngTableParams({
  5920. page : 1,
  5921. count : 5,
  5922. sorting: {
  5923. date: 'desc'
  5924. }
  5925. }, {
  5926. total : 0,
  5927. counts: [5, 10, 25, 50],
  5928. getData : function($defer, params) {
  5929. $scope.loading = true;
  5930. var pageParams = params.url();
  5931. pageParams.searchFilter = {};
  5932. pageParams.searchFilter.keyword = $scope.keyword;
  5933. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5934. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5935. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5936. $scope.loading = false;
  5937. if(page) {
  5938. params.total(page.totalElement);
  5939. $defer.resolve(page.content);
  5940. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5941. }
  5942. }, function(response){
  5943. $scope.loading = false;
  5944. toaster.pop('error', '数据加载失败', response.data);
  5945. });
  5946. }
  5947. });
  5948. $scope.openDatePicker = function($event, item, openParam) {
  5949. $event.preventDefault();
  5950. $event.stopPropagation();
  5951. item[openParam] = !item[openParam];
  5952. };
  5953. // 搜索框回车
  5954. $scope.onSearch = function() {
  5955. $scope.tableParams.page(1);
  5956. $scope.tableParams.reload();
  5957. };
  5958. // 选择查找日期
  5959. $scope.onDateCondition = function(){
  5960. $scope.tableParams.page(1);
  5961. $scope.tableParams.reload();
  5962. };
  5963. }]);
  5964. /**
  5965. * 客户委外验退
  5966. */
  5967. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  5968. $scope.active = 'all';
  5969. $scope.agreedText = '全部';
  5970. $scope.dateZoneText = '一个月内';
  5971. $scope.condition = {dateZone: 1};
  5972. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5973. $scope.changeAgreed = function(agreed) {
  5974. $scope.condition.agreed = agreed;
  5975. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5976. $scope.condition.$agreedOpen = false;
  5977. };
  5978. $scope.changeDateZone = function(zone) {
  5979. $scope.condition.dateZone = zone;
  5980. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5981. $scope.condition.$dateZoneOpen = false;
  5982. getDateCondition(zone, $scope.condition);
  5983. $scope.tableParams.reload();
  5984. };
  5985. $scope.setActive = function(state) {
  5986. if($scope.active != state) {
  5987. $scope.active = state;
  5988. if($scope.tableParams.page() == 1)
  5989. $scope.tableParams.reload();
  5990. else
  5991. $scope.tableParams.page(1);
  5992. }
  5993. };
  5994. var getService = function() {
  5995. return MakeReturn;
  5996. };
  5997. $scope.tableParams = new ngTableParams({
  5998. page : 1,
  5999. count : 5,
  6000. sorting: {
  6001. date: 'desc'
  6002. }
  6003. }, {
  6004. total : 0,
  6005. counts: [5, 10, 25, 50],
  6006. getData : function($defer, params) {
  6007. $scope.loading = true;
  6008. var pageParams = params.url();
  6009. pageParams.searchFilter = {};
  6010. pageParams.searchFilter.keyword = $scope.keyword;
  6011. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6012. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6013. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6014. $scope.loading = false;
  6015. if(page) {
  6016. params.total(page.totalElement);
  6017. $defer.resolve(page.content);
  6018. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6019. }
  6020. }, function(response){
  6021. $scope.loading = false;
  6022. toaster.pop('error', '数据加载失败', response.data);
  6023. });
  6024. }
  6025. });
  6026. $scope.openDatePicker = function($event, item, openParam) {
  6027. $event.preventDefault();
  6028. $event.stopPropagation();
  6029. item[openParam] = !item[openParam];
  6030. };
  6031. // 搜索框回车
  6032. $scope.onSearch = function() {
  6033. $scope.tableParams.page(1);
  6034. $scope.tableParams.reload();
  6035. };
  6036. // 选择查找日期
  6037. $scope.onDateCondition = function(){
  6038. $scope.tableParams.page(1);
  6039. $scope.tableParams.reload();
  6040. };
  6041. }]);
  6042. /**
  6043. * 委外加工变更
  6044. */
  6045. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  6046. $scope.active = 'all';
  6047. $scope.agreedText = '全部';
  6048. $scope.dateZoneText = '一个月内';
  6049. $scope.condition = {dateZone: 1};
  6050. $scope.changeAgreed = function(agreed) {
  6051. $scope.condition.agreed = agreed;
  6052. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6053. $scope.condition.$agreedOpen = false;
  6054. };
  6055. $scope.changeDateZone = function(zone) {
  6056. $scope.condition.dateZone = zone;
  6057. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6058. $scope.condition.$dateZoneOpen = false;
  6059. getDateCondition(zone, $scope.condition);
  6060. $scope.tableParams.reload();
  6061. };
  6062. $scope.setActive = function(state) {
  6063. if($scope.active != state) {
  6064. $scope.active = state;
  6065. if($scope.tableParams.page() == 1)
  6066. $scope.tableParams.reload();
  6067. else
  6068. $scope.tableParams.page(1);
  6069. }
  6070. };
  6071. var getService = function() {
  6072. return MakeChange;
  6073. };
  6074. $scope.tableParams = new ngTableParams({
  6075. page : 1,
  6076. count : 5,
  6077. sorting: {
  6078. orderChangeDate: 'desc'
  6079. }
  6080. }, {
  6081. total : 0,
  6082. counts: [5, 10, 25, 50],
  6083. getData : function($defer, params) {
  6084. $scope.loading = true;
  6085. var pageParams = params.url();
  6086. pageParams.searchFilter = {};
  6087. pageParams.searchFilter.keyword = $scope.keyword;
  6088. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6089. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6090. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6091. $scope.loading = false;
  6092. if(page) {
  6093. params.total(page.totalElement);
  6094. $defer.resolve(page.content);
  6095. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6096. }
  6097. }, function(response){
  6098. $scope.loading = false;
  6099. toaster.pop('error', '数据加载失败', response.data);
  6100. });
  6101. }
  6102. });
  6103. $scope.openDatePicker = function($event, item, openParam) {
  6104. $event.preventDefault();
  6105. $event.stopPropagation();
  6106. item[openParam] = !item[openParam];
  6107. };
  6108. // 打开回复
  6109. $scope.openReply = function(change) {
  6110. change.$editing = true;
  6111. };
  6112. // 关闭回复
  6113. $scope.closeReply = function(change) {
  6114. change.$editing = false;
  6115. }
  6116. // 确定回复
  6117. $scope.onReplyClick = function(change) {
  6118. if(change.$agreed) {
  6119. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6120. $scope.loading = true;
  6121. MakeChange.reply({itemId: change.id}, reply, function(){
  6122. $scope.loading = false;
  6123. toaster.pop('info', '提示', '回复成功');
  6124. $scope.tableParams.reload();
  6125. }, function(response){
  6126. $scope.loading = false;
  6127. toaster.pop('error', '回复失败', response.data);
  6128. });
  6129. }
  6130. };
  6131. // 搜索框回车
  6132. $scope.onSearch = function() {
  6133. $scope.tableParams.page(1);
  6134. $scope.tableParams.reload();
  6135. };
  6136. // 选择查找日期
  6137. $scope.onDateCondition = function(){
  6138. $scope.tableParams.page(1);
  6139. $scope.tableParams.reload();
  6140. };
  6141. }]);
  6142. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', function($scope, $stateParams, MakeChange, toaster){
  6143. var loadData = function() {
  6144. MakeChange.get({id: $stateParams.id}, function(data){
  6145. $scope.change = data;
  6146. });
  6147. };
  6148. loadData();
  6149. $scope.openDatePicker = function($event, item, openParam) {
  6150. $event.preventDefault();
  6151. $event.stopPropagation();
  6152. item[openParam] = !item[openParam];
  6153. };
  6154. $scope.onReplyClick = function(change) {
  6155. if(change.$agreed) {
  6156. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6157. MakeChange.reply({itemId: change.id}, reply, function(){
  6158. toaster.pop('info', '提示', '回复成功');
  6159. loadData();
  6160. }, function(response){
  6161. toaster.pop('error', '回复失败', response.data);
  6162. });
  6163. }
  6164. };
  6165. }]);
  6166. /**
  6167. * 委外加工
  6168. */
  6169. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  6170. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  6171. $scope.active = 'all';
  6172. $scope.agreedText = '全部';
  6173. $scope.dateZoneText = '一个月内';
  6174. $scope.condition = {dateZone: 1};
  6175. $scope.changeAgreed = function(agreed) {
  6176. $scope.condition.agreed = agreed;
  6177. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6178. $scope.condition.$agreedOpen = false;
  6179. };
  6180. $scope.changeDateZone = function(zone) {
  6181. $scope.condition.dateZone = zone;
  6182. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6183. $scope.condition.$dateZoneOpen = false;
  6184. getDateCondition(zone, $scope.condition);
  6185. $scope.tableParams.reload();
  6186. };
  6187. $scope.setActive = function(state) {
  6188. if($scope.active != state) {
  6189. $scope.active = state;
  6190. if($scope.tableParams.page() == 1)
  6191. $scope.tableParams.reload();
  6192. else
  6193. $scope.tableParams.page(1);
  6194. }
  6195. };
  6196. var getService = function() {
  6197. return MakeOutOrder;
  6198. };
  6199. $scope.tableParams = new ngTableParams({
  6200. page : 1,
  6201. count : 5,
  6202. sorting: {
  6203. date: 'desc'
  6204. }
  6205. }, {
  6206. total : 0,
  6207. counts: [5, 10, 25, 50],
  6208. getData : function($defer, params) {
  6209. $scope.loading = true;
  6210. var pageParams = params.url();
  6211. pageParams.searchFilter = {};
  6212. pageParams.searchFilter.keyword = $scope.keyword;
  6213. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6214. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6215. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6216. $scope.loading = false;
  6217. if(page) {
  6218. params.total(page.totalElement);
  6219. $defer.resolve(page.content);
  6220. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6221. }
  6222. }, function(response){
  6223. $scope.loading = false;
  6224. toaster.pop('error', '数据加载失败', response.data);
  6225. });
  6226. }
  6227. });
  6228. $scope.openDatePicker = function($event, item, openParam) {
  6229. $event.preventDefault();
  6230. $event.stopPropagation();
  6231. item[openParam] = !item[openParam];
  6232. };
  6233. // 打开回复
  6234. $scope.openReply = function(change) {
  6235. change.$editing = true;
  6236. };
  6237. // 关闭回复
  6238. $scope.closeReply = function(change) {
  6239. change.$editing = false;
  6240. }
  6241. // 确定回复
  6242. $scope.onReplyClick = function(change) {
  6243. if(change.$agreed) {
  6244. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  6245. $scope.loading = true;
  6246. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  6247. $scope.loading = false;
  6248. toaster.pop('info', '提示', '回复成功');
  6249. $scope.tableParams.reload();
  6250. }, function(response){
  6251. $scope.loading = false;
  6252. toaster.pop('error', '回复失败', response.data);
  6253. });
  6254. }
  6255. };
  6256. // 搜索框回车
  6257. $scope.onSearch = function() {
  6258. $scope.tableParams.page(1);
  6259. $scope.tableParams.reload();
  6260. };
  6261. // 选择查找日期
  6262. $scope.onDateCondition = function(){
  6263. $scope.tableParams.page(1);
  6264. $scope.tableParams.reload();
  6265. };
  6266. }]);
  6267. /**
  6268. * 委外加工详细
  6269. */
  6270. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService) {
  6271. var loadData = function() {
  6272. MakeOutOrder.get({id: $stateParams.id}, function(data){
  6273. $scope.order = data;
  6274. var sum = $scope.order.qty * $scope.order.price;
  6275. $scope.order.total = sum;
  6276. $scope.loading = false;
  6277. });
  6278. };
  6279. loadData();
  6280. // 获取回复记录
  6281. $scope.getReply = function(item) {
  6282. if(!item.replies) {
  6283. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  6284. item.replies = replies;
  6285. });
  6286. }
  6287. };
  6288. $scope.openDatePicker = function($event, item, openParam) {
  6289. $event.preventDefault();
  6290. $event.stopPropagation();
  6291. item[openParam] = !item[openParam];
  6292. };
  6293. // 点击回复
  6294. $scope.onReplyClick = function(order, inverse) {
  6295. if(order.reply) {
  6296. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  6297. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  6298. return;
  6299. }
  6300. var reply = angular.copy(order.reply);
  6301. if(reply.delivery) {
  6302. if(typeof reply.delivery == 'object')
  6303. reply.delivery = reply.delivery.getTime();
  6304. } else {
  6305. reply.delivery = order.delivery;
  6306. }
  6307. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  6308. $scope.loading = true;
  6309. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  6310. $scope.loading = false;
  6311. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  6312. loadData();
  6313. }, function(response){
  6314. $scope.loading = false;
  6315. toaster.pop('error', '回复失败', response.data);
  6316. });
  6317. }
  6318. };
  6319. // 打开回复
  6320. $scope.openReply = function(order) {
  6321. if(!order.reply) {
  6322. order.reply = {
  6323. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  6324. delivery: order.delivery
  6325. }
  6326. }
  6327. order.$editing = true;
  6328. };
  6329. // 关闭回复
  6330. $scope.closeReply = function(order) {
  6331. order.$editing = false;
  6332. }
  6333. // 自己委外加工订单
  6334. $scope.print = function(order) {
  6335. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  6336. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  6337. };
  6338. }]);
  6339. /**
  6340. * 计算时间差
  6341. */
  6342. app.filter('timespan', function(){
  6343. return function(time) {
  6344. if(time == null)
  6345. return '9999年';
  6346. var now = new Date().getTime(), span = time - now,
  6347. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  6348. m = Math.ceil(span/60000);
  6349. if(span < 0)
  6350. return '0天';
  6351. if(d > 0)
  6352. return d + '天';
  6353. if(h > 0)
  6354. return h + '小时';
  6355. if(m > 0)
  6356. return m + '分钟';
  6357. return '0天';
  6358. };
  6359. });
  6360. app.filter('firstchar', function(){
  6361. return function(str) {
  6362. if(str == null)
  6363. return null;
  6364. return str.substring(0, 1);
  6365. };
  6366. });
  6367. /**
  6368. * 搜索框,回车触发
  6369. */
  6370. app.directive('ngSearch', ['$parse', function($parse) {
  6371. return {
  6372. require : '?ngModel',
  6373. restrict : 'A',
  6374. link : function(scope, element, attrs, ngModel) {
  6375. var searchFn = $parse(attrs.ngSearch);
  6376. element.bind('keypress', function(event) {
  6377. if (event.keyCode == '13') {
  6378. event.preventDefault();
  6379. event.stopPropagation();
  6380. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  6381. }
  6382. });
  6383. }
  6384. };
  6385. }]);
  6386. /**
  6387. * 状态码 -> 描述
  6388. */
  6389. app.filter('status', function(){
  6390. return function(data) {
  6391. var statusConfig = {
  6392. '101': '已提交',
  6393. '102': '已审核',
  6394. '103': '未通过',
  6395. '200': '未回复',
  6396. '201': '已回复',
  6397. '313': '已激活',
  6398. '316': '已过账',
  6399. '311': '申请中',
  6400. '312': '未激活'
  6401. };
  6402. return statusConfig[data];
  6403. }
  6404. });
  6405. //弹出问题反馈模态框
  6406. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  6407. //获取当前用户
  6408. AuthenticationService.getAuthentication().success(function(data) {
  6409. $scope.user = data;
  6410. });
  6411. $scope.showModal = function(){
  6412. var modalInstance = $modal.open({
  6413. animation: true,
  6414. templateUrl: 'static/tpl/serve/feedback.html',
  6415. controller: 'FeedbackCtrl',
  6416. resolve: {
  6417. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  6418. }
  6419. });
  6420. modalInstance.result.then(function(){
  6421. }, function(){
  6422. })
  6423. }
  6424. }]);
  6425. /*
  6426. * 提交我的反馈
  6427. */
  6428. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  6429. $scope.isPublic = 1; //默认公开
  6430. $scope.classId = 1; //默认类别
  6431. $scope.user = user;
  6432. $scope.ok = function(){
  6433. if(!$scope.user){ //用户未登录
  6434. $scope.uu = null;
  6435. }else{ //用户已登录
  6436. $scope.uu = $scope.user.userUU;
  6437. }
  6438. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  6439. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  6440. function(data){
  6441. toaster.pop('success', '成功', '您的问题反馈成功!');
  6442. $scope.cancel();
  6443. }, function(response){
  6444. toaster.pop('error', '错误', response.data);
  6445. });
  6446. }
  6447. $scope.cancel = function () {
  6448. $modalInstance.dismiss();
  6449. };
  6450. }]);
  6451. //“我的问题反馈”跳转控制
  6452. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  6453. $scope.myFeedback = function(){
  6454. AuthenticationService.getAuthentication().success(function(data){
  6455. $scope.user = data;
  6456. if(!$scope.user){
  6457. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  6458. return false;
  6459. }else{
  6460. window.location.href = "./serve#/question/myFeedback";
  6461. }
  6462. });
  6463. }
  6464. }]);
  6465. //客户服务
  6466. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  6467. Vendor.getServe(function(datas){
  6468. $scope.vendors = datas;
  6469. console.log($scope.Vender);
  6470. // 自动跳转
  6471. if(datas && datas.length == 1)
  6472. $scope.redirect(datas[0]);
  6473. });
  6474. $scope.redirect = function(vendor) {
  6475. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  6476. };
  6477. }]);
  6478. /**
  6479. * 物料资料
  6480. */
  6481. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster) {
  6482. $scope.active = 'all';
  6483. $scope.agreedText = '全部';
  6484. $scope.dateZoneText = '一个月内';
  6485. $scope.condition = {dateZone: 1};
  6486. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6487. $scope.changeAgreed = function(agreed) {
  6488. $scope.condition.agreed = agreed;
  6489. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6490. $scope.condition.$agreedOpen = false;
  6491. };
  6492. $scope.changeDateZone = function(zone) {
  6493. $scope.condition.dateZone = zone;
  6494. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6495. $scope.condition.$dateZoneOpen = false;
  6496. getDateCondition(zone, $scope.condition);
  6497. $scope.tableParams.reload();
  6498. };
  6499. $scope.setActive = function(state) {
  6500. if($scope.active != state) {
  6501. $scope.active = state;
  6502. if($scope.tableParams.page() == 1)
  6503. $scope.tableParams.reload();
  6504. else
  6505. $scope.tableParams.page(1);
  6506. }
  6507. };
  6508. var getService = function() {
  6509. return GetProductInfo;
  6510. };
  6511. $scope.tableParams = new ngTableParams({
  6512. page : 1,
  6513. count : 5,
  6514. sorting: {
  6515. }
  6516. }, {
  6517. total : 0,
  6518. counts: [5, 10, 25, 50],
  6519. getData : function($defer, params) {
  6520. $scope.loading = true;
  6521. var pageParams = params.url();
  6522. pageParams.keyword = $scope.keyword;
  6523. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6524. $scope.loading = false;
  6525. if(page) {
  6526. params.total(page.totalElement);
  6527. $defer.resolve(page.content);
  6528. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  6529. }
  6530. }, function(response) {
  6531. $scope.loading = false;
  6532. toaster.pop('error', '数据加载失败', response.data);
  6533. });
  6534. }
  6535. });
  6536. // 搜索框回车
  6537. $scope.onSearch = function() {
  6538. $scope.tableParams.page(1);
  6539. $scope.tableParams.reload();
  6540. };
  6541. //删除
  6542. $scope.deleteById = function(id) {
  6543. console.log(id);
  6544. GetProductInfo.deleteById({id: id}, function(data) {
  6545. toaster.pop("success", "提示", "删除成功");
  6546. }), function(response) {
  6547. toaster.pop("error", "删除失败", response);
  6548. };
  6549. }
  6550. }]);
  6551. /**
  6552. * 物料批量上传
  6553. */
  6554. app.controller('UploadByBatchCtrl', ['$scope', 'GetProductInfo', '$upload', 'toaster', function($scope, GetProductInfo, $upload, toaster) {
  6555. // 通过excel批量上传物料
  6556. $scope.upload = function() {
  6557. var file = $scope.myFiles[0];
  6558. $upload.upload({
  6559. url: 'product/baseInfo/release/excel',
  6560. file: file,
  6561. method: 'POST'
  6562. }).success(function(data) {
  6563. console.log(data);
  6564. $scope.result = data;
  6565. $scope.success = $scope.result.success;
  6566. $scope.total = $scope.result.total;
  6567. $scope.alters = $scope.result.alters;
  6568. }).error(function(response) {
  6569. toaster.pop('error', response.data || response);
  6570. });
  6571. };
  6572. // 查看范例
  6573. $scope.showImg = function() {
  6574. var src = "/static/img/all/auditing.png", box = $('#image-box');
  6575. box.show();
  6576. box.find('img').attr('src', src);
  6577. box.find('a').click(function(){
  6578. box.hide();
  6579. });
  6580. box.dblclick(function(){
  6581. box.hide();
  6582. });
  6583. };
  6584. // 下载模板
  6585. $scope.download = function() {
  6586. window.location.href = 'product/baseInfo/upload/template';
  6587. };
  6588. }]);
  6589. /**
  6590. * 物料详情
  6591. */
  6592. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster) {
  6593. var loadData = function() {
  6594. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  6595. $scope.prodInfo = data;
  6596. $scope.prodInfo.$editing = false;
  6597. $scope.loading = false;
  6598. });
  6599. };
  6600. loadData();
  6601. // 更新
  6602. $scope.update = function() {
  6603. $scope.prodInfo.$editing = true;
  6604. };
  6605. // 取消
  6606. $scope.cancel = function() {
  6607. $scope.prodInfo.$editing = false;
  6608. };
  6609. $scope.submit = function(prodInfo) {
  6610. console.log(prodInfo);
  6611. GetProductInfo.update({}, prodInfo, function(data) {
  6612. toaster.pop("success", "提示", "提交成功");
  6613. }, function(res) {
  6614. toaster.pop("error", "提示" + res);
  6615. });
  6616. }
  6617. }]);
  6618. /**
  6619. * 新增物料
  6620. */
  6621. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI) {
  6622. $scope.prodInfo = {unit: 'PCS'};
  6623. // 选择类目
  6624. $scope.selectKind = function(uuids) {
  6625. $modal.open({
  6626. animation: true,
  6627. size: 'lg',
  6628. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  6629. controller: 'KindChooseCtrl',
  6630. }).result.then(function(data){
  6631. $scope.kindId = data;
  6632. var modalInstance = $modal.open({
  6633. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  6634. controller: 'FindComponentCtrl',
  6635. size: 'lg',
  6636. resolve: {
  6637. KindId: function() {
  6638. return $scope.kindId;
  6639. }
  6640. }
  6641. });
  6642. modalInstance.result.then(function(data) {
  6643. $scope.prodInfo.cmpUuId = data.uuid;
  6644. $scope.prodInfo.cmpCode = data.code;
  6645. $scope.prodInfo.brand = data.brand.nameEn;
  6646. }, function(){
  6647. });
  6648. }, function(){
  6649. });
  6650. };
  6651. //提交
  6652. $scope.submit = function(prodInfo){
  6653. GetProductInfo.addNewProd({}, prodInfo, function(data) {
  6654. toaster.pop("success", "提示", "提交成功");
  6655. //提交后跳转到详情页面,防止重复提交
  6656. window.location.href="#/baseInfo/prodList/"+data.id;
  6657. }, function(res) {
  6658. toaster.pop("error", "提示" + res);
  6659. });
  6660. };
  6661. // 取消
  6662. $scope.cancel = function(){
  6663. $scope.prodInfo = angular.copy($scope.prodInfo);
  6664. };
  6665. }]);
  6666. /**
  6667. * 类目选择模态框
  6668. */
  6669. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  6670. $scope.kindId = null;
  6671. $scope.kinds = [[], [], [], []];
  6672. // 获取子类目
  6673. var getChildren = function(pid, deep) {
  6674. KindAPI.getChildren({parentId: pid}, function(data) {
  6675. $scope.kinds[deep] = data;
  6676. }, function(response) {
  6677. toaster.pop('error', '获取子类目失败', response.data);
  6678. });
  6679. };
  6680. // 改变节点选中状态
  6681. var changeStatus = function(item, deep) {
  6682. var kindId = null, level = 0;
  6683. angular.forEach($scope.kinds, function(ks, i) {
  6684. if(i > deep) {
  6685. $scope.kinds[i] = [];
  6686. } else {
  6687. angular.forEach(ks, function(k, j) {
  6688. if(i == deep) {
  6689. if(k.id == item.id) {
  6690. $scope.kinds[i][j].$active = true;
  6691. kindId = k.id;
  6692. } else {
  6693. k.$active = null;
  6694. }
  6695. }
  6696. });
  6697. }
  6698. });
  6699. // 选择的节点
  6700. $scope.kindId = kindId;
  6701. $scope.active = item;
  6702. // 当前可操作的层级
  6703. if(deep < 3) {
  6704. $scope.activeDeep = deep + 1;
  6705. }
  6706. };
  6707. // 节点点击后获取子类目,节点被选中
  6708. $scope.onItemClick = function(item, deep) {
  6709. changeStatus(item, deep);
  6710. if (!item.isLeaf) {
  6711. getChildren(item.id, deep + 1);
  6712. }
  6713. };
  6714. // 重新加载数据
  6715. function reload(deep) {
  6716. var pid;
  6717. if(deep) {
  6718. pid = $scope.actives[deep - 1].id;
  6719. } else {
  6720. pid = 0;
  6721. deep = 0;
  6722. }
  6723. getChildren(pid, deep);
  6724. }
  6725. // 初始加载数据,获取第一层的类目
  6726. if($scope.actives) {
  6727. angular.forEach($scope.actives, function(v, k) {
  6728. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  6729. $scope.kinds[k] = data;
  6730. angular.forEach($scope.kinds[k], function(kind, i){
  6731. if(kind.id == v.id) {
  6732. $scope.kinds[k][i].$active = true;
  6733. $scope.actives[k] = $scope.kinds[k][i];
  6734. }
  6735. })
  6736. }, function(response) {
  6737. toaster.pop('error', '获取子类目失败', response.data);
  6738. });
  6739. });
  6740. } else {
  6741. reload();
  6742. }
  6743. // 取消
  6744. $scope.cancel = function() {
  6745. $modalInstance.dismiss();
  6746. };
  6747. // 确认选择
  6748. $scope.check = function() {
  6749. $modalInstance.close($scope.kindId);
  6750. };
  6751. }]);
  6752. /**
  6753. * 器件筛选
  6754. */
  6755. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  6756. //状态
  6757. $scope.setActive = function (state){
  6758. if($scope.active != state) {
  6759. $scope.active = state;
  6760. if($scope.tableParams.page() == 1)
  6761. $scope.tableParams.reload();
  6762. else
  6763. $scope.tableParams.page(1);
  6764. }
  6765. };
  6766. $scope.tableParams = new ngTableParams({
  6767. page : 1,
  6768. count : 10
  6769. }, {
  6770. total : 0,
  6771. counts: [5, 10, 25, 50],
  6772. getData : function($defer, params) {
  6773. $scope.loading = true;
  6774. var pageParams = params.url();
  6775. pageParams.keyword = $scope.keyword;
  6776. pageParams.kindId = KindId;
  6777. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  6778. console.log(page);
  6779. $scope.loading = false;
  6780. if(page) {
  6781. params.total(page.totalElement);
  6782. $defer.resolve(page.content);
  6783. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6784. }
  6785. }, function(response){
  6786. $scope.loading = false;
  6787. toaster.pop('error', '数据加载失败', response.data);
  6788. });
  6789. }
  6790. });
  6791. // 取消
  6792. $scope.cancel = function() {
  6793. $modalInstance.dismiss();
  6794. };
  6795. // 选择
  6796. $scope.check = function(data){
  6797. $modalInstance.close(data);
  6798. };
  6799. // 搜索框回车
  6800. $scope.onSearch = function() {
  6801. $scope.tableParams.page(1);
  6802. $scope.tableParams.reload();
  6803. };
  6804. }]);
  6805. /**
  6806. * 企业列表
  6807. */
  6808. app.controller('EnterpriseListCtrl', ['$scope', 'EnterpriseList', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', function($scope, EnterpriseList, ngTableParams, $filter, BaseService, toaster, AddPartner) {
  6809. $scope.active = 'all';
  6810. $scope.agreedText = '全部';
  6811. $scope.dateZoneText = '一个月内';
  6812. $scope.condition = {dateZone: 1};
  6813. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6814. $scope.changeAgreed = function(agreed) {
  6815. $scope.condition.agreed = agreed;
  6816. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6817. $scope.condition.$agreedOpen = false;
  6818. };
  6819. $scope.changeDateZone = function(zone) {
  6820. $scope.condition.dateZone = zone;
  6821. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6822. $scope.condition.$dateZoneOpen = false;
  6823. getDateCondition(zone, $scope.condition);
  6824. $scope.tableParams.reload();
  6825. };
  6826. $scope.setActive = function(state) {
  6827. if($scope.active != state) {
  6828. $scope.active = state;
  6829. if($scope.tableParams.page() == 1)
  6830. $scope.tableParams.reload();
  6831. else
  6832. $scope.tableParams.page(1);
  6833. }
  6834. };
  6835. var getService = function() {
  6836. return EnterpriseList;
  6837. };
  6838. $scope.tableParams = new ngTableParams({
  6839. page : 1,
  6840. count : 5,
  6841. sorting: {
  6842. }
  6843. }, {
  6844. total : 0,
  6845. counts: [5, 10, 25, 50],
  6846. getData : function($defer, params) {
  6847. $scope.loading = true;
  6848. var pageParams = params.url();
  6849. pageParams.keyword = $scope.keyword;
  6850. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  6851. console.log(page);
  6852. $scope.loading = false;
  6853. if(page) {
  6854. params.total(page.totalElement);
  6855. $defer.resolve(page.content);
  6856. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  6857. }
  6858. }, function(response) {
  6859. $scope.loading = false;
  6860. toaster.pop('error', '数据加载失败', response.data);
  6861. });
  6862. }
  6863. });
  6864. // 搜索框回车
  6865. $scope.onSearch = function() {
  6866. $scope.tableParams.page(1);
  6867. $scope.tableParams.reload();
  6868. };
  6869. // 增加合作关系
  6870. $scope.addPartner = function(uu) {
  6871. console.log(uu);
  6872. AddPartner.addPartner({uu: uu}, {}, function(data) {
  6873. toaster.pop('success', '提示', '请求发送成功');
  6874. }, function(response) {
  6875. toaster.pop('error','失败',response.data);
  6876. });
  6877. }
  6878. }]);
  6879. /**
  6880. * 新增采购单
  6881. */
  6882. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'newPurcOrder', function($scope, $modal, toaster, $filter, newPurcOrder) {
  6883. $scope.order = {
  6884. date : new Date(),
  6885. cust : {
  6886. uu : '',
  6887. },
  6888. orderItems : {
  6889. product : {},
  6890. $endDateOpen: false
  6891. },
  6892. };
  6893. // 查找客户
  6894. $scope.dbfindCust = function(){
  6895. var modalInstance = $modal.open({
  6896. templateUrl: 'static/tpl/index/purc/modal/purc_order_cust.html',
  6897. controller: 'DbfindCustCtrl',
  6898. size: 'lg',
  6899. resolve: {
  6900. }
  6901. });
  6902. modalInstance.result.then(function(data) {
  6903. $scope.order.cust = data.myEnterprise;
  6904. $scope.order.custUser = data.myUser;
  6905. $scope.order.orderItems = [];
  6906. var item = {
  6907. code: null,
  6908. title: null,
  6909. spec: null,
  6910. unit: null,
  6911. qty: null,
  6912. price: null,
  6913. remark: null,
  6914. delivery: null
  6915. };
  6916. $scope.order.orderItems.push(item);
  6917. }, function(){
  6918. });
  6919. };
  6920. //商品信息
  6921. $scope.order.orderItems = [];
  6922. var item = {
  6923. code: null,
  6924. title: null,
  6925. spec: null,
  6926. unit: null,
  6927. qty: null,
  6928. price: null,
  6929. remark: null,
  6930. delivery: null
  6931. };
  6932. $scope.order.orderItems.push(item);
  6933. //增加商品
  6934. $scope.addProduct = function() {
  6935. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null});
  6936. };
  6937. //删除商品
  6938. $scope.deleteProduct = function(index) {
  6939. $scope.order.orderItems.splice(index, 1);
  6940. };
  6941. // 查找客户物料
  6942. $scope.dbfindCustProd = function(){
  6943. if($scope.order.cust.uu) {
  6944. var modalInstance = $modal.open({
  6945. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  6946. controller: 'DbfindCustProdCtrl',
  6947. size: 'lg',
  6948. resolve: {
  6949. custUU: function() {
  6950. return $scope.order.cust.uu
  6951. }
  6952. }
  6953. });
  6954. modalInstance.result.then(function(data) {
  6955. $scope.order.orderItems.push(data);
  6956. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  6957. if($scope.order.orderItems[i].code == null) {
  6958. $scope.order.orderItems.splice(i, 1);
  6959. }
  6960. }
  6961. }, function() {
  6962. });
  6963. } else {
  6964. toaster.pop('info', '提示', '请先选择供应商');
  6965. }
  6966. };
  6967. $scope.getMinDate = function(item) {
  6968. return $filter('date')(new Date, 'yyyy-MM-dd');
  6969. };
  6970. $scope.openDatePicker = function($event, openParam, index) {
  6971. $event.preventDefault();
  6972. $event.stopPropagation();
  6973. $scope.order.orderItems[index].$endDateOpen = !openParam;
  6974. };
  6975. // 保存
  6976. $scope.save = function(order){
  6977. $scope.loading = true;
  6978. if(!$scope.order.code) //新增,设单号
  6979. $scope.order.code = 'BMP' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6980. $scope.order.custUU = $scope.order.cust.uu;
  6981. $scope.order.custUserUU = $scope.order.custUser.userUU;
  6982. if($scope.order.date instanceof Date) {
  6983. $scope.order.date = $scope.order.date.getTime();
  6984. }
  6985. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  6986. if($scope.order.orderItems[i].delivery instanceof Date) {
  6987. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  6988. }
  6989. }
  6990. newPurcOrder.save({}, $scope.order, function(data){
  6991. $scope.loading = false;
  6992. toaster.pop('success', '成功', '保存成功');
  6993. window.location.hash = '#/purc/order/'+data.id;
  6994. }, function(response){
  6995. $scope.loading = false;
  6996. toaster.pop('error', '保存失败', response.data);
  6997. });
  6998. };
  6999. }]);
  7000. /**
  7001. * 我的客户
  7002. */
  7003. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  7004. $scope.userInfoResult = true;
  7005. AuthenticationService.getAuthentication().success(function(data) {
  7006. $scope.loading = false;
  7007. $scope.thisUser = data;
  7008. });
  7009. var getCustInfos = function(custuu) {
  7010. if(custuu) {
  7011. VendorService.userInfo.query({uu:custuu},null,function(data) {
  7012. $scope.custInfos = data;
  7013. var getPage = function(page, size){
  7014. if($scope.custInfos) {
  7015. var result = {};
  7016. result.totalCount = $scope.custInfos.length;
  7017. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  7018. if($scope.custInfos.length % size == 0) {
  7019. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  7020. }else {
  7021. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  7022. }
  7023. result.first = page == 1;
  7024. result.last = page == result.totalPage;
  7025. result.page = page;
  7026. result.next = page - 0 + 1;
  7027. result.pre = page - 1;
  7028. return result;
  7029. }
  7030. }
  7031. $scope.userdata = getPage(1,4);
  7032. $scope.first = function (){
  7033. $scope.userdata = getPage($scope.userdata.pre,4);
  7034. }
  7035. $scope.last = function (){
  7036. $scope.userdata = getPage($scope.userdata.next,4);
  7037. }
  7038. }, function(response){
  7039. $scope.loading = false;
  7040. toaster.pop('error', '数据加载失败', response.data);
  7041. });
  7042. }
  7043. }
  7044. $scope.addUserInfo = function(customer) {
  7045. //TODO
  7046. if ($scope.thisUser.sys) {
  7047. var modalInstance = $modal.open({
  7048. animation: true,
  7049. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  7050. controller: 'AddUserInfoCtrl',
  7051. resolve: {
  7052. customer: function() {
  7053. return customer;
  7054. }
  7055. }
  7056. });
  7057. modalInstance.result.then(function(changed, checked){
  7058. if(changed) {
  7059. if(checked)
  7060. $scope.newUser.roles = checked;
  7061. else
  7062. loadUsers();
  7063. }
  7064. });
  7065. } else {
  7066. toaster.pop('error', '您不是管理员,无权限分配用户!');
  7067. }
  7068. }
  7069. $scope.showUserInfo = function(customer,boo) {
  7070. $scope.custInfo = customer;
  7071. if(boo) {
  7072. getCustInfos(customer.myEnterprise.uu);
  7073. $scope.userInfoResult = true;
  7074. }
  7075. }
  7076. $scope.customerParams = new ngTableParams({
  7077. page : 1,
  7078. count : 10
  7079. }, {
  7080. total : 0,
  7081. counts: [5, 10, 25, 50],
  7082. getData : function($defer, params) {
  7083. $scope.loading = true;
  7084. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  7085. $scope.loading = false;
  7086. if(page) {
  7087. params.total(page.totalElements);
  7088. $defer.resolve(page.content);
  7089. }
  7090. $scope.totalCount = page.totalElements;
  7091. }, function(response){
  7092. $scope.loading = false;
  7093. toaster.pop('error', '数据加载失败', response.data);
  7094. });
  7095. }
  7096. });
  7097. }]);
  7098. /**
  7099. * 我的供应商
  7100. */
  7101. app.controller('MySupplierCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  7102. $scope.userInfoResult = true;
  7103. AuthenticationService.getAuthentication().success(function(data) {
  7104. $scope.loading = false;
  7105. $scope.thisUser = data;
  7106. });
  7107. var getCustInfos = function(custuu) {
  7108. if(custuu) {
  7109. VendorService.userInfo.query({uu:custuu},null,function(data) {
  7110. $scope.custInfos = data;
  7111. var getPage = function(page, size){
  7112. if($scope.custInfos) {
  7113. var result = {};
  7114. result.totalCount = $scope.custInfos.length;
  7115. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  7116. if($scope.custInfos.length % size == 0) {
  7117. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  7118. }else {
  7119. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  7120. }
  7121. result.first = page == 1;
  7122. result.last = page == result.totalPage;
  7123. result.page = page;
  7124. result.next = page - 0 + 1;
  7125. result.pre = page - 1;
  7126. return result;
  7127. }
  7128. }
  7129. $scope.userdata = getPage(1,4);
  7130. $scope.first = function (){
  7131. $scope.userdata = getPage($scope.userdata.pre,4);
  7132. }
  7133. $scope.last = function (){
  7134. $scope.userdata = getPage($scope.userdata.next,4);
  7135. }
  7136. }, function(response){
  7137. $scope.loading = false;
  7138. toaster.pop('error', '数据加载失败', response.data);
  7139. });
  7140. }
  7141. }
  7142. $scope.addUserInfo = function(customer) {
  7143. //TODO
  7144. if ($scope.thisUser.sys) {
  7145. var modalInstance = $modal.open({
  7146. animation: true,
  7147. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  7148. controller: 'AddUserInfoCtrl',
  7149. resolve: {
  7150. customer: function() {
  7151. return customer;
  7152. }
  7153. }
  7154. });
  7155. modalInstance.result.then(function(changed, checked){
  7156. if(changed) {
  7157. if(checked)
  7158. $scope.newUser.roles = checked;
  7159. else
  7160. loadUsers();
  7161. }
  7162. });
  7163. } else {
  7164. toaster.pop('error', '您不是管理员,无权限分配用户!');
  7165. }
  7166. }
  7167. $scope.showUserInfo = function(customer,boo) {
  7168. $scope.custInfo = customer;
  7169. if(boo) {
  7170. getCustInfos(customer.myEnterprise.uu);
  7171. $scope.userInfoResult = true;
  7172. }
  7173. }
  7174. $scope.customerParams = new ngTableParams({
  7175. page : 1,
  7176. count : 10
  7177. }, {
  7178. total : 0,
  7179. counts: [5, 10, 25, 50],
  7180. getData : function($defer, params) {
  7181. $scope.loading = true;
  7182. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  7183. $scope.loading = false;
  7184. if(page) {
  7185. params.total(page.totalElements);
  7186. $defer.resolve(page.content);
  7187. }
  7188. $scope.totalCount = page.totalElements;
  7189. }, function(response){
  7190. $scope.loading = false;
  7191. toaster.pop('error', '数据加载失败', response.data);
  7192. });
  7193. }
  7194. });
  7195. }]);
  7196. /**
  7197. * 建立合作关系申请
  7198. */
  7199. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner) {
  7200. $scope.active = 'todo';
  7201. var getRequestStatus = function(active) {
  7202. var fn = 'getAllRequest';
  7203. switch(active) {
  7204. case 'done':
  7205. fn = 'getRequestDone';break;
  7206. case 'todo':
  7207. fn = 'getRequestTodo';break;
  7208. case 'end':
  7209. fn = 'getRequestEnd';break;
  7210. }
  7211. return fn;
  7212. }
  7213. // 切换单据类型
  7214. $scope.setActive = function(state) {
  7215. if($scope.active != state) {
  7216. $scope.active = state;
  7217. if($scope.tableParams.page() == 1)
  7218. $scope.tableParams.reload();
  7219. else
  7220. $scope.tableParams.page(1);
  7221. }
  7222. };
  7223. // 切换数据来源(正常数据 or 历史数据)
  7224. var getService = function() {
  7225. return AddPartnerMyRequest;
  7226. };
  7227. $scope.tableParams = new ngTableParams({ // ng-Table参数
  7228. page : 1,
  7229. count : 5,
  7230. sorting: {
  7231. }
  7232. }, {
  7233. total : 0,
  7234. counts: [5, 10, 15, 25, 50],
  7235. getData : function($defer, params) { // 获取数据的方法
  7236. $scope.loading = true;
  7237. var pageParams = params.url();
  7238. pageParams.searchFilter = { // 筛选条件
  7239. keyword: $scope.keyword,
  7240. };
  7241. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7242. console.log(page);
  7243. $scope.loading = false;
  7244. if(page) {
  7245. $defer.resolve(page.content);
  7246. params.total(page.totalElements);
  7247. }
  7248. }, function(response){
  7249. $scope.loading = false;
  7250. toaster.pop('error', '数据加载失败', response.data);
  7251. });
  7252. }
  7253. });
  7254. // 再次申请
  7255. $scope.reapply = function(id) {
  7256. AddPartner.reapply({id: id}, {}, function(data) {
  7257. toaster.pop('success', '提示', '请求发送成功');
  7258. }, function(response) {
  7259. toaster.pop('error','失败',response.data);
  7260. });
  7261. }
  7262. // 添加为供应商
  7263. $scope.addSupplier = function(id) {
  7264. AddPartner.addSupplier({id: id}, {}, function(data) {
  7265. toaster.pop('success', '提示', '添加供应商成功');
  7266. }, function(response) {
  7267. toaster.pop('error', '失败', response.data);
  7268. })
  7269. };
  7270. // 添加客户
  7271. $scope.addCust = function(id) {
  7272. AddPartner.addCust({id: id}, {}, function(data) {
  7273. toaster.pop('success', '提示', '添加客户成功');
  7274. }, function(response) {
  7275. toaster.pop('error', '失败', response.data);
  7276. })
  7277. };
  7278. }]);
  7279. /**
  7280. * 建立合作关系处理申请
  7281. */
  7282. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  7283. $scope.active = 'todo';
  7284. var getMessagetStatus = function(active) {
  7285. var fn = 'getAllMessage';
  7286. switch(active) {
  7287. case 'done':
  7288. fn = 'getMessageDone';break;
  7289. case 'todo':
  7290. fn = 'getMessageTodo';break;
  7291. case 'end':
  7292. fn = 'getMessageEnd';break;
  7293. }
  7294. return fn;
  7295. }
  7296. // 切换单据类型
  7297. $scope.setActive = function(state) {
  7298. if($scope.active != state) {
  7299. $scope.active = state;
  7300. if($scope.tableParams.page() == 1)
  7301. $scope.tableParams.reload();
  7302. else
  7303. $scope.tableParams.page(1);
  7304. }
  7305. };
  7306. var getService = function() {
  7307. return AddPartnerMyMessage;
  7308. };
  7309. $scope.tableParams = new ngTableParams({ // ng-Table参数
  7310. page : 1,
  7311. count : 5,
  7312. sorting: {
  7313. }
  7314. }, {
  7315. total : 0,
  7316. counts: [5, 10, 15, 25, 50],
  7317. getData : function($defer, params) { // 获取数据的方法
  7318. $scope.loading = true;
  7319. var pageParams = params.url();
  7320. pageParams.searchFilter = { // 筛选条件
  7321. keyword: $scope.keyword,
  7322. };
  7323. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7324. $scope.loading = false;
  7325. if(page) {
  7326. $defer.resolve(page.content);
  7327. params.total(page.totalElements);
  7328. }
  7329. }, function(response){
  7330. $scope.loading = false;
  7331. toaster.pop('error', '数据加载失败', response.data);
  7332. });
  7333. }
  7334. });
  7335. // 同意申请
  7336. $scope.agree = function(id) {
  7337. AddPartner.agreeRequest({id: id}, {}, function(data) {
  7338. toaster.pop('success', '提示', '操作成功');
  7339. }, function(response) {
  7340. toaster.pop('error', '提示', response.data);
  7341. });
  7342. }
  7343. // 拒绝申请
  7344. $scope.refuse = function(id, reason) {
  7345. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  7346. toaster.pop('success', '提示', '操作成功');
  7347. }, function(response) {
  7348. toaster.pop('error', '提示', response.data);
  7349. });
  7350. }
  7351. }]);
  7352. /**
  7353. * 我的合作伙伴
  7354. */
  7355. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', function($scope, toaster, GetProductInfo) {
  7356. // 获取所有的合作伙伴
  7357. GetProductInfo.getAllPartners({}, function(data) {
  7358. console.log(data);
  7359. $scope.partners = data;
  7360. }, function(res) {
  7361. toaster.pop('error', '获取列表失败', res.data);
  7362. });
  7363. // 添加为客户
  7364. $scope.addCust = function(partner) {
  7365. GetProductInfo.addCust({}, partner, function(data) {
  7366. toaster.pop('success', '提示', '添加客户成功');
  7367. }, function(response) {
  7368. toaster.pop('error', '添加客户失败', response.data);
  7369. });
  7370. }
  7371. // 添加为供应商
  7372. $scope.addSupplier = function(partner) {
  7373. GetProductInfo.addSupplier({}, partner, function(data) {
  7374. toaster.pop('success', '提示', '添加供应商成功');
  7375. }, function(response) {
  7376. toaster.pop('error', '添加供应商失败', response.data);
  7377. });
  7378. }
  7379. }]);
  7380. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  7381. $scope.getData = function(){
  7382. FaApCheck.getAll(function(data){
  7383. $scope.custs= data;
  7384. angular.forEach($scope.data, function(item) {
  7385. item:{
  7386. $selected:true;
  7387. }
  7388. });
  7389. $scope.loading = false;
  7390. });
  7391. }
  7392. $scope.getData();
  7393. $scope.CustName= function(suuorname) {
  7394. $modalInstance.close(suuorname);
  7395. }
  7396. $scope.close = function() {
  7397. $modalInstance.close();
  7398. }
  7399. }]);
  7400. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', function($scope, GetProductInfo) {
  7401. console.log('enter');
  7402. GetProductInfo.businessGroups({}, function(data) {
  7403. }, function(response) {
  7404. });
  7405. }]);
  7406. return app;
  7407. });