app.js 496 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product'], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config([ '$httpProvider', function($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function(response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url : "/index",
  26. views : {
  27. "left-view" : {
  28. templateUrl : "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view" : {
  32. templateUrl : "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url : "/",
  38. views : {
  39. "left-view" : {
  40. templateUrl : "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view" : {
  44. templateUrl : "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url : "/sale",
  50. views : {
  51. "left-view" : {
  52. templateUrl : "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view" : {
  56. templateUrl : "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url : "",
  65. templateUrl : "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url : "/",
  68. templateUrl : "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url : "/purc",
  71. views : {
  72. "left-view" : {
  73. templateUrl : "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view" : {
  77. templateUrl : "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url : "",
  86. templateUrl : "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url : "/",
  89. templateUrl : "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url : "/introduce",
  92. templateUrl : "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url : "/order",
  95. templateUrl : "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url : "/order/:id",
  99. templateUrl : "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url : "/addOrder",
  103. templateUrl : "static/tpl/index/purc/addOrder.html",
  104. controller : 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url : "/cart",
  107. templateUrl : "static/tpl/index/purc/cart.html",
  108. controller : 'CartController'
  109. }).state('purc.cartDetail', {
  110. url : "/cart/:id",
  111. templateUrl : "static/tpl/index/purc/cart_detail.html",
  112. controller : 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url : "/deputy",
  115. templateUrl : "static/tpl/index/purc/deputyOrder.html",
  116. controller : 'DeputyOrderCtrl'
  117. }).state('purc.newdeputy', {
  118. url : "/deputy/add",
  119. templateUrl : "static/tpl/index/purc/deputyOrder_new.html",
  120. controller : 'NewDeputyOrderCtrl'
  121. }).state('purc.deputydetail', {
  122. url : "/deputy/:id",
  123. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  124. controller : 'DeputyOrderDetailCtrl'
  125. /* 招标列表 */
  126. }).state('purc.tenderlist', {
  127. url : "/tender",
  128. templateUrl : "static/tpl/index/purc/tenderlist.html",
  129. controller : 'PurcTenderCtrl'
  130. }).state('purc.waiting.tenderlist', {
  131. url : "/tender",
  132. templateUrl : "static/tpl/index/purc/tenderlist.html",
  133. controller : 'PurcTenderCtrl'
  134. }).state('purc.todo.tenderlist', {
  135. url : "/tender/todo",
  136. templateUrl : "static/tpl/index/purc/tenderlist.html",
  137. controller : 'PurcTenderCtrl'
  138. /* 招标 */
  139. }).state('purc.tender', {
  140. url : "/addTender",
  141. templateUrl : "static/tpl/index/purc/tender.html",
  142. controller : 'PurcNewTenderCtrl'
  143. }).state('purc.savedtender', {
  144. url : "/tender/:id",
  145. templateUrl : "static/tpl/index/purc/tender.html",
  146. controller : 'PurcNewTenderCtrl'
  147. /* 评标 */
  148. }).state('purc.evaluation', {
  149. url : "/evaluation/:id",
  150. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  151. controller : 'PurcEvaluationCtrl'
  152. /* 采购供应商资料 */
  153. }).state('purc.vendor', {
  154. url : "/vendor",
  155. templateUrl : "static/tpl/index/purc/vendor.html",
  156. controller : 'PurcVendorCtrl'
  157. /* 采购供应商资料 详情*/
  158. }).state('purc.vendordetail', {
  159. url : "/vendor/:id",
  160. templateUrl : "static/tpl/index/purc/vendor_detail.html",
  161. controller : 'PurcVendorDetailCtrl'
  162. /* 客户指定招标列表 */
  163. }).state('purc.makeoutorder', {
  164. url : "/makeoutorder",
  165. templateUrl : "static/tpl/index/make/outorder.html",
  166. controller: 'MakeOutOrderCtrl'
  167. }).state('purc.outorder_detail', {
  168. url : "/makeoutorder/:id",
  169. templateUrl : "static/tpl/index/make/outorder_detail.html",
  170. controller: 'MakeOutOrderDetailCtrl'
  171. /*平台新增询价单*/
  172. }).state('purc.inquiry_new', {
  173. url : "/purcinquiry",
  174. templateUrl : "static/tpl/index/purc/inquiry_new.html",
  175. controller: 'PurcInquiryCtrl'
  176. }).state('purc.purcinquiry_new', {
  177. url : "/purcinquiry/:bussinessCode",
  178. templateUrl : "static/tpl/index/purc/purcinquiry_new.html",
  179. controller: 'PurcInquiryNewCtrl'
  180. }).state('purc.inquiry', {
  181. url : "/purchaseinquiry",
  182. templateUrl : "static/tpl/index/purc/inquiry.html",
  183. controller: 'PurchaseInquiryCtrl'
  184. }).state('purc.inquiry_detail', {
  185. url : "/purcinquirydetail",
  186. templateUrl : "static/tpl/index/purc/inquiry_detail.html",
  187. controller: 'PurcInquiryDetailCtrl'
  188. }).state('purc.inquiryInfo_detail', {
  189. url : "/purcinquirydetail/:id",
  190. templateUrl : "static/tpl/index/purc/inquiryInfo_detail.html",
  191. controller: 'PurcInquiryInfoDetailCtrl'
  192. }).state('purc.inquiry_unapply', {
  193. url : "/inquiry_unapply",
  194. templateUrl : "static/tpl/index/purc/inquiry_unapply.html",
  195. controller: 'UnapplyInquiryCtrl'
  196. }).state('sale.tenderlist', {
  197. url : "/tender",
  198. templateUrl : "static/tpl/index/sale/tenderlist.html",
  199. controller : 'SaleTenderCtrl'
  200. }).state('sale.todo.tenderlist', {
  201. url : "/tender",
  202. templateUrl : "static/tpl/index/sale/tenderlist.html",
  203. controller : 'SaleTenderCtrl'
  204. /* 平台公开招标列表 */
  205. }).state('baseInfo.openTenderList', {
  206. url : "/openTenderList",
  207. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  208. controller: 'SaleOpenTenderCtrl'
  209. /* 查看公开招标详情 */
  210. }).state('baseInfo.open_tender_detail', {
  211. url : "/openTenderDetail/:id",
  212. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  213. controller : 'OpenSaleTenderDetailCtrl'
  214. /* 投标 */
  215. }).state('sale.tender', {
  216. url : "/tender/:id",
  217. templateUrl : "static/tpl/index/sale/tender.html",
  218. controller : 'SaleTenderDetailCtrl'
  219. /* 采购方查看供应商投标 */
  220. }).state('sale.vendortender', {
  221. url : "/tender/:vendUU/:id",
  222. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  223. controller : 'SaleVendorTenderDetailCtrl'
  224. }).state('sale.todo', {
  225. url : "/todo",
  226. templateUrl : "static/tpl/index/sale/todo.html"
  227. }).state('sale.todo.inquiry', {
  228. url : "/inquiry",
  229. templateUrl : "static/tpl/index/sale/inquiry.html",
  230. controller: 'SaleInquiryCtrl'
  231. }).state('sale.todo.order', {
  232. url : "/order",
  233. templateUrl : "static/tpl/index/sale/order.html",
  234. controller: 'SaleOrderCtrl'
  235. }).state('sale.todo.change', {
  236. url : "/change",
  237. templateUrl : "static/tpl/index/sale/change.html",
  238. controller: 'SaleChangeCtrl'
  239. }).state('sale.todo.notice', {
  240. url : "/notice",
  241. templateUrl : "static/tpl/index/sale/notice.html",
  242. controller: 'SaleNoticeCtrl'
  243. }).state('sale.customer', {
  244. url : "/customer",
  245. templateUrl : "static/tpl/index/sale/customer.html",
  246. controller: 'CustomerCtrl'
  247. }).state('sale.customer_detail', {
  248. url : "/customer/:id",
  249. templateUrl : "static/tpl/index/sale/customer_detail.html",
  250. controller: 'CustomerDetailCtrl'
  251. }).state('sale.customerProduct', {
  252. url : "/customerProduct",
  253. templateUrl : "static/tpl/index/sale/customer.html",
  254. controller: 'CustomerCtrl'
  255. }).state('sale.inquiry', {
  256. url : "/inquiry",
  257. templateUrl : "static/tpl/index/sale/inquiry.html",
  258. controller: 'SaleInquiryCtrl'
  259. }).state('sale.inquirymould', {
  260. url : "/mould",
  261. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  262. controller: 'SaleInquiryMouldCtrl'
  263. }).state('sale.todo.inquirymould', {
  264. url : "/mould",
  265. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  266. controller: 'SaleInquiryMouldCtrl'
  267. }).state('sale.inquiry_mould_detail', {
  268. url : "/mould/:id",
  269. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  270. controller: 'SaleInquiryMouldDetailCtrl'
  271. }).state('sale.inquiry_detail', {
  272. url : "/inquiry/:id",
  273. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  274. controller: 'SaleInquiryDetailCtrl'
  275. }).state('sale.quotation', {
  276. url : "/quotation",
  277. templateUrl : "static/tpl/index/sale/quotation.html"
  278. }).state('sale.quotation.new', {
  279. url : "/new",
  280. templateUrl : "static/tpl/index/sale/quotation_new.html",
  281. controller: 'SaleQuotationNewCtrl'
  282. }).state('sale.quotation.list', {
  283. url : "/list",
  284. templateUrl : "static/tpl/index/sale/quotation_list.html",
  285. controller: 'SaleQuotationListCtrl'
  286. }).state('sale.quotation.item', {
  287. url : "/:id",
  288. templateUrl : "static/tpl/index/sale/quotation_new.html",
  289. controller: 'SaleQuotationNewCtrl'
  290. }).state('sale.order', {
  291. url : "/order",
  292. templateUrl : "static/tpl/index/sale/order.html",
  293. controller: 'SaleOrderCtrl'
  294. }).state('sale.order_detail', {
  295. url : "/order/:id",
  296. templateUrl : "static/tpl/index/sale/order_detail.html",
  297. controller: 'SaleOrderDetailCtrl'
  298. }).state('sale.change', {
  299. url : "/change",
  300. templateUrl : "static/tpl/index/sale/change.html",
  301. controller: 'SaleChangeCtrl'
  302. }).state('sale.change_detail', {
  303. url : "/change/:id",
  304. templateUrl : "static/tpl/index/sale/change_detail.html",
  305. controller: 'SaleChangeDetailCtrl'
  306. }).state('sale.notice', {
  307. url : "/notice",
  308. templateUrl : "static/tpl/index/sale/notice.html",
  309. controller: 'SaleNoticeCtrl'
  310. }).state('sale.send', {
  311. url : "/send",
  312. templateUrl : "static/tpl/index/sale/send.html",
  313. controller: 'SaleSendCtrl'
  314. }).state('sale.send_detail', {
  315. url : "/send/:id",
  316. templateUrl : "static/tpl/index/sale/send_detail.html",
  317. controller: 'SaleSendDetailCtrl'
  318. }).state('sale.forecast', {
  319. url : "/forecast",
  320. templateUrl : "static/tpl/index/sale/forecast.html",
  321. controller: 'SaleForecastCtrl'
  322. }).state('sale.accept', {
  323. url : "/accept",
  324. templateUrl : "static/tpl/index/sale/accept.html",
  325. controller: 'SaleAcceptCtrl'
  326. }).state('sale.returns', {
  327. url : "/returns",
  328. templateUrl : "static/tpl/index/sale/returns.html",
  329. controller: 'SaleReturnsCtrl'
  330. }).state('sale.sample', {
  331. url : "/sample",
  332. templateUrl : "static/tpl/index/sale/sample.html",
  333. controller: 'SaleSampleCtrl'
  334. }).state('sale.sample_detail', {
  335. url : "/sample/:id",
  336. templateUrl : "static/tpl/index/sale/sample_detail.html",
  337. controller: 'SaleSampleDetailCtrl'
  338. }).state('sale.approval', {
  339. url : "/approval",
  340. templateUrl : "static/tpl/index/sale/approval.html",
  341. controller: 'SaleApprovalCtrl'
  342. }).state('sale.prodList', {
  343. url : "/prodList",
  344. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  345. controller : 'ProductListCtrl'
  346. }).state('sale.newProdInfo', {
  347. url : "/newProdInfo",
  348. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  349. controller : 'NewProdInfoCtrl'
  350. }).state('sale.uploadByBatch', {
  351. url : "/uploadByBatch",
  352. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  353. controller : 'UploadByBatchCtrl'
  354. }).state('sale.productDetail', {
  355. url : "/prodList/:id",
  356. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  357. controller : 'ProductDetailCtrl'
  358. }).state('sale.maketodo', {
  359. url : "/maketodo",
  360. templateUrl : "static/tpl/index/make/todo.html"
  361. }).state('sale.maketodo.order', {
  362. url : "/makeorder",
  363. templateUrl : "static/tpl/index/make/order.html",
  364. controller: 'MakeOrderCtrl'
  365. }).state('sale.makeorder', {
  366. url : "/makeorder",
  367. templateUrl : "static/tpl/index/make/order.html",
  368. controller: 'MakeOrderCtrl'
  369. }).state('sale.makeorder_detail', {
  370. url : "/makeorder/:id",
  371. templateUrl : "static/tpl/index/make/order_detail.html",
  372. controller: 'MakeOrderDetailCtrl'
  373. }).state('sale.badOut', {
  374. url : "/badOut",
  375. templateUrl : "static/tpl/index/qc/badOut.html",
  376. controller: 'SaleBadOutCtrl'
  377. }).state('sale.MRB', {
  378. url : "/MRB",
  379. templateUrl : "static/tpl/index/qc/MRB.html",
  380. controller: 'SaleMRBCtrl'
  381. }).state('sale.badIn', {
  382. url : "/badIn",
  383. templateUrl : "static/tpl/index/qc/badIn.html",
  384. controller: 'SaleBadInCtrl'
  385. }).state('sale.makeaccept', {
  386. url : "/makeaccept",
  387. templateUrl : "static/tpl/index/make/accept.html",
  388. controller: 'MakeAcceptCtrl'
  389. }).state('sale.makereturns', {
  390. url : "/makereturns",
  391. templateUrl : "static/tpl/index/make/returns.html",
  392. controller: 'MakeReturnCtrl'
  393. }).state('sale.makechange', {
  394. url : "/makechange",
  395. templateUrl : "static/tpl/index/make/change.html",
  396. controller: 'MakeChangeCtrl'
  397. }).state('sale.makechange_detail', {
  398. url : "/makechange/:id",
  399. templateUrl : "static/tpl/index/make/change_detail.html",
  400. controller: 'MakeChangeDetailCtrl'
  401. }).state('account', {
  402. url : "/account",
  403. views : {
  404. "left-view" : {
  405. templateUrl : "static/tpl/index/account/left.html",
  406. controller: 'LeftCtrl'
  407. },
  408. "right-view" : {
  409. templateUrl : "static/tpl/index/account/right.html"
  410. }
  411. }
  412. }).state('account.index', {
  413. url : "",
  414. templateUrl : "static/tpl/index/account/index.html",
  415. controller: 'RightCtrl'
  416. }).state('account.home', {
  417. url : "/",
  418. templateUrl : "static/tpl/index/account/index.html",
  419. controller: 'RightCtrl'
  420. }).state('baseInfo', {//基础资料
  421. url : "/baseInfo",
  422. views : {
  423. "left-view" : {
  424. },
  425. "right-view" : {
  426. templateUrl : "static/tpl/index/baseInfo/right.html"
  427. }
  428. }
  429. }).state('baseInfo.index', {
  430. url : "/enterpriseList",
  431. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  432. controller: 'EnterpriseListCtrl'
  433. }).state('baseInfo.home', {
  434. url : "/enterpriseList",
  435. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  436. controller: 'EnterpriseListCtrl'
  437. }).state('baseInfo.enterpriseList', {
  438. url : "/enterpriseList",
  439. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  440. controller : 'EnterpriseListCtrl'
  441. }).state('baseInfo.myClient', {
  442. url : "/myClient",
  443. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  444. controller : 'MyClientCtrl'
  445. }).state('baseInfo.mySupplier', {
  446. url : "/mySupplier",
  447. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  448. controller : 'MySupplierCtrl'
  449. }).state('baseInfo.myRequest', {
  450. url : "/myRquest",
  451. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  452. controller : 'AddPartnerRequestCtrl'
  453. }).state('baseInfo.myMessage', {
  454. url : "/myMessage",
  455. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  456. controller : 'AddPartnerMessageCtrl'
  457. }).state('baseInfo.myPartners', {
  458. url : '/myPartners',
  459. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  460. controller : 'MyPartnersCtrl'
  461. }).state('baseInfo.businessGroups', {
  462. url : '/businessGroups',
  463. controller : 'BusinessGroupsCtrl'
  464. }).state('baseInfo.inquiryList', {
  465. url : '/inquiryList',
  466. templateUrl : "static/tpl/index/baseInfo/inquiry_list.html",
  467. controller : 'PublicInquiryListCtrl'
  468. }).state('baseInfo.inquiryListDetail', {
  469. url : '/inquiryList/:id',
  470. templateUrl : "static/tpl/index/baseInfo/inquiryItem_detail.html",
  471. controller : 'PublicInquiryListDetailCtrl'
  472. }).state('baseInfo.vendorInfo', {
  473. url : '/enume/vendorInfo',
  474. templateUrl : "static/tpl/index/baseInfo/vendorsInfo.html",
  475. controller : 'VendorsInfoCtrl'
  476. }).state('baseInfo.customerInfo', {
  477. url : '/enume/customerInfo',
  478. templateUrl : "static/tpl/index/baseInfo/customersInfo.html",
  479. controller : 'CustomersInfoCtrl'
  480. }).state('baseInfo.enume', {
  481. url : '/enume',
  482. templateUrl : "static/tpl/index/baseInfo/vendorAndCustomer.html",
  483. }).state('baseInfo.partner', {
  484. url : '/partner',
  485. templateUrl : "static/tpl/index/baseInfo/addPartners.html",
  486. controller : 'AddPartnersCtrl'
  487. }).state('baseInfo.partner_searchresult', {
  488. url : '/search',
  489. templateUrl : "static/tpl/index/baseInfo/searchresult.html",
  490. controller : 'EnterpriseSearchCtrl'
  491. }).state('baseInfo.invitation', {
  492. url : '/invitation',
  493. templateUrl : "static/tpl/index/baseInfo/invitation.html",
  494. controller : 'InvitationCtrl'
  495. }).state('qc', {
  496. url : "/qc",
  497. views : {
  498. "left-view" : {
  499. templateUrl : "static/tpl/index/qc/left.html"
  500. },
  501. "right-view" : {
  502. templateUrl : "static/tpl/index/qc/right.html"
  503. }
  504. }
  505. }).state('qc.index', {
  506. url : "",
  507. templateUrl : "static/tpl/index/qc/index.html"
  508. }).state('qc.home', {
  509. url : "/",
  510. templateUrl : "static/tpl/index/qc/index.html"
  511. }).state('fa', {
  512. url : "/fa",
  513. views : {
  514. "left-view" : {
  515. templateUrl : "static/tpl/index/fa/left.html"
  516. },
  517. "right-view" : {
  518. templateUrl : "static/tpl/index/fa/right.html"
  519. }
  520. }
  521. }).state('fa.index', {
  522. url : "",
  523. templateUrl : "static/tpl/index/fa/index.html"
  524. }).state('fa.home', {
  525. url : "/",
  526. templateUrl : "static/tpl/index/fa/index.html"
  527. }).state('fa.apBill', {
  528. url : "/apBill",
  529. templateUrl : "static/tpl/index/fa/apBill.html",
  530. controller: 'SaleApBillCtrl'
  531. }).state('fa.arCheck', {
  532. url : "/arCheck",
  533. templateUrl : "static/tpl/index/fa/arCheck.html",
  534. controller: 'SaleArCheckCtrl'
  535. }).state('fa.arCheck_detail', {
  536. url : "/arCheck/:id",
  537. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  538. controller: 'SaleArCheckDetailCtrl'
  539. }).state('fa.apCheck', {
  540. url : "/apCheck",
  541. params:{
  542. 'id':null
  543. },
  544. templateUrl : "static/tpl/index/fa/apCheck.html",
  545. controller: 'PurchaseApCheckCtrl'
  546. }).state('fa.apCheck_detail', {
  547. url : "/apCheck/:id",
  548. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  549. controller: 'PurchaseApCheckDetailCtrl'
  550. }).state('fa.apCheckList', {
  551. url : "/apCheckList",
  552. templateUrl : "static/tpl/index/fa/apCheckList.html",
  553. controller: 'PurchaseApCheckListCtrl'
  554. }).state('fa.adjustList', {
  555. url : "/adjustList",
  556. templateUrl : "static/tpl/index/fa/adjustList.html",
  557. controller: 'PurchaseAdjustListCtrl'
  558. }).state('make', {
  559. url : "/make",
  560. views : {
  561. "left-view" : {
  562. templateUrl : "static/tpl/index/make/left.html"
  563. },
  564. "right-view" : {
  565. templateUrl : "static/tpl/index/make/right.html"
  566. }
  567. }
  568. }).state('make.index', {
  569. url : "",
  570. templateUrl : "static/tpl/index/make/index.html"
  571. }).state('make.home', {
  572. url : "/",
  573. templateUrl : "static/tpl/index/make/index.html"
  574. }).state('cs', {// 客户服务
  575. url : "/cs",
  576. views : {
  577. "left-view" : {
  578. templateUrl : "static/tpl/index/cs/left.html"
  579. },
  580. "right-view" : {
  581. templateUrl : "static/tpl/index/cs/right.html"
  582. }
  583. }
  584. }).state('cs.index', {
  585. url : "",
  586. templateUrl : "static/tpl/index/cs/index.html"
  587. }).state('cs.home', {
  588. url : "/",
  589. templateUrl : "static/tpl/index/cs/index.html"
  590. }).state('search', { //顶部搜索
  591. url: "/search?keyword=",
  592. views : {
  593. "left-view" : {
  594. templateUrl : "static/tpl/index/search/left.html"
  595. },
  596. "right-view" : {
  597. templateUrl: "static/tpl/index/search/search_result.html",
  598. controller: 'TopSearchCtrl'
  599. }
  600. }
  601. }).state('approvalflow', { //审批流
  602. url: "/approvalFlow",
  603. views : {
  604. "left-view" : {
  605. templateUrl : "static/tpl/index/approvalFlow/left.html"
  606. },
  607. "right-view" : {
  608. templateUrl: "static/tpl/index/approvalFlow/right.html",
  609. }
  610. }
  611. }).state('approvalflow.flow', {
  612. url : "/flow",
  613. templateUrl : "static/tpl/index/approvalFlow/home.html",
  614. controller: 'approvalFlowCtrl'
  615. }).state('approvalflow.enterprise', {
  616. url : "/enterprise",
  617. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  618. controller: 'EnterpriseCtrl'
  619. }).state('approvalflow.user', {
  620. url : "/user",
  621. templateUrl : "static/tpl/index/approvalFlow/user.html",
  622. controller: 'UserCtrl'
  623. }).state('approvalflow.log', {
  624. url : "/log",
  625. templateUrl : "static/tpl/index/approvalFlow/log.html",
  626. controller: 'LogCtrl'
  627. }).state('approvalflow.resource', {
  628. url : "/resource",
  629. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  630. controller: 'ResourceCtrl'
  631. }).state('approvalflow.role', {
  632. url : "/role",
  633. templateUrl : "static/tpl/index/approvalFlow/role.html",
  634. controller: 'RoleCtrl'
  635. }).state('approvalflow.product', {
  636. url : "/product",
  637. templateUrl : "static/tpl/index/approvalFlow/prodList.html",
  638. controller: 'ProductAllCtrl'
  639. });
  640. $urlRouterProvider.otherwise('/index');
  641. }]);
  642. /**
  643. * 表示符号
  644. */
  645. app.factory('Symbol', function(){
  646. return {
  647. currency: function(cur) {
  648. if(cur == 'RMB') return '¥';
  649. else if(cur == 'USD') return '$';
  650. else if(cur == 'EUR') return '€';
  651. else if(cur == null || cur == '') return '¥';
  652. else return cur;
  653. }
  654. };
  655. }).factory('Lodop',function(){
  656. return {
  657. getLodop:function(oOBJECT,oEMBED){
  658. var CreatedOKLodop7766=null;
  659. /**************************
  660. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  661. IE系列、IE内核系列的浏览器采用oOBJECT,
  662. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  663. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  664. 64位浏览器指向64位的安装程序install_lodop64.exe。
  665. **************************/
  666. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  667. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  668. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  669. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  670. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  671. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  672. var LODOP;
  673. try{
  674. //=====判断浏览器类型:===============
  675. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  676. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  677. //=====如果页面有Lodop就直接使用,没有则新建:==========
  678. if (oOBJECT!=undefined || oEMBED!=undefined) {
  679. if (isIE)
  680. LODOP=oOBJECT;
  681. else
  682. LODOP=oEMBED;
  683. } else {
  684. if (CreatedOKLodop7766==null){
  685. LODOP=document.createElement("object");
  686. LODOP.setAttribute("width",0);
  687. LODOP.setAttribute("height",0);
  688. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  689. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  690. else LODOP.setAttribute("type","application/x-print-lodop");
  691. document.documentElement.appendChild(LODOP);
  692. CreatedOKLodop7766=LODOP;
  693. } else
  694. LODOP=CreatedOKLodop7766;
  695. };
  696. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  697. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  698. if (navigator.userAgent.indexOf('Chrome')>=0)
  699. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  700. if (navigator.userAgent.indexOf('Firefox')>=0)
  701. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  702. if (is64IE) document.write(strHtm64_Install); else
  703. if (isIE) document.write(strHtmInstall); else
  704. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  705. return LODOP;
  706. } else
  707. if (LODOP.VERSION<"6.1.9.8") {
  708. if (is64IE) document.write(strHtm64_Update); else
  709. if (isIE) document.write(strHtmUpdate); else
  710. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  711. return LODOP;
  712. };
  713. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  714. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  715. //============================================================
  716. return LODOP;
  717. } catch(err) {
  718. if (is64IE)
  719. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  720. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  721. return LODOP;
  722. };
  723. }
  724. }
  725. });
  726. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
  727. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  728. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  729. if (routeState.indexOf('/') > -1)
  730. routeState = routeState.substring(0, routeState.indexOf('/'));
  731. if (routeState.indexOf('.') > -1)
  732. routeState = routeState.substring(0, routeState.indexOf('.'));
  733. $scope.routeState = routeState || 'home';
  734. });
  735. $scope.search = function(keyword) {
  736. if(keyword != null && keyword != '') {
  737. $rootScope.searchKeyword = keyword;
  738. window.location.hash = '#/search?keyword='+keyword;
  739. }
  740. };
  741. $scope.showMessage = function() {
  742. var $modalInstance = $modal.open({
  743. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  744. controller: 'PagingReleaseCtrl'
  745. });
  746. };
  747. }]);
  748. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  749. BaseService.scrollBackToTop();
  750. $scope.active = "todo";
  751. $scope.setActive = function(state) {
  752. if($scope.active != state) {
  753. $scope.active = state;
  754. if($scope.tableParams.page() == 1)
  755. $scope.tableParams.reload();
  756. else
  757. $scope.tableParams.page(1);
  758. }
  759. };
  760. $scope.tableParams = new ngTableParams({
  761. page : 1,
  762. count : 5,
  763. sorting: {
  764. 'releaseDetail.release.date': 'desc'
  765. }
  766. }, {
  767. total : 0,
  768. counts: [5, 10, 25, 50],
  769. getData : function($defer, params) {
  770. $scope.loading = true;
  771. var pageParams = params.url();
  772. var realActive = {};
  773. pageParams.searchFilter = { // 筛选条件
  774. keyword: $scope.keyword
  775. // fromDate: getDateTime($scope.condition.dateFrom),
  776. // endDate: getDateTime($scope.condition.dateTo)
  777. };
  778. // AccountEnterprise.get({}, function(data){
  779. // $scope.loading = false;
  780. // $scope.currentEn = data;
  781. // });
  782. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  783. $scope.loading = false;
  784. if(page) {
  785. params.total(page.totalElement);
  786. $defer.resolve(page.content);
  787. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  788. }
  789. }, function(response){
  790. $scope.loading = false;
  791. toaster.pop('error', '数据加载失败', response.data);
  792. });
  793. }
  794. });
  795. $scope.close = function() {
  796. $modalInstance.close();
  797. };
  798. $scope.checks = {
  799. checked : false
  800. };// 全选框
  801. $scope.checkAll = function() {
  802. angular.forEach($scope.tableParams.data, function(message) {
  803. message.checked = $scope.checks.checked;
  804. });
  805. };
  806. // 单选
  807. $scope.checkOne = function(vendor) {
  808. vendor.checked = true;
  809. var checked = true;
  810. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  811. if (!message.checked) {
  812. checked = false;
  813. }
  814. });
  815. $scope.checks.checked = checked;
  816. };
  817. // 单反选
  818. $scope.unCheckOne = function(vendor) {
  819. vendor.checked = false;
  820. $scope.checks.checked = false;
  821. };
  822. // 标为已读
  823. $scope.setRead = function() {
  824. var selectedMessages = [];
  825. angular.forEach($scope.tableParams.data, function(message) {
  826. if(message.checked) {
  827. selectedMessages.push(message);
  828. }
  829. });
  830. PagingRelease.setRead({}, selectedMessages , function(message) {
  831. $scope.tableParams.page(1);
  832. $scope.tableParams.reload();
  833. });
  834. };
  835. // 搜索框回车
  836. $scope.onSearch = function() {
  837. $scope.tableParams.page(1);
  838. $scope.tableParams.reload();
  839. };
  840. }]);
  841. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  842. var search = $rootScope.searchKeyword;
  843. return function(content, search) {
  844. content = encodeURI(content);
  845. search = encodeURI(search);
  846. var reg = new RegExp(search, 'gim');
  847. var result = content.replace(reg,'<font color="red">$&</font>');
  848. result = decodeURI(result);
  849. return $sce.trustAsHtml(result);
  850. }
  851. $rootScope.searchKeyword = null;// 清除缓存的关键字
  852. }]);
  853. /**
  854. * 顶部搜索
  855. */
  856. app.controller('TopSearchCtrl', ['$scope', '$rootScope', 'getAccountUserSpace', 'ngTableParams', 'toaster', 'BaseService', 'AddPartner', '$filter', '$stateParams', 'SearchProd', '$sce', '$modal', 'InvitationRecord', function($scope, $rootScope, getAccountUserSpace, ngTableParams, toaster, BaseService, AddPartner, $filter, $stateParams, SearchProd, $sce, $modal, InvitationRecord) {
  857. BaseService.scrollBackToTop();
  858. $scope.active = 'all';
  859. $scope.tip = $rootScope.searchKeyword;
  860. // 企业搜索
  861. var getService = function() {
  862. return getAccountUserSpace;
  863. };
  864. $scope.tableParams = new ngTableParams({
  865. page : 1,
  866. count : 5,
  867. sorting: {
  868. }
  869. }, {
  870. total : 0,
  871. counts: [5, 10, 25, 50],
  872. getData : function($defer, params) {
  873. $scope.loading = true;
  874. var pageParams = params.url();
  875. pageParams.keyword = $rootScope.searchKeyword;
  876. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  877. $scope.loading = false;
  878. if(page) {
  879. $scope.total = page.totalElement;
  880. params.total(page.totalElement);
  881. $defer.resolve(page.content);
  882. }
  883. }, function(response) {
  884. $scope.loading = false;
  885. toaster.pop('error', '数据加载失败', response.data);
  886. });
  887. }
  888. });
  889. // 添加合作关系
  890. $scope.addPartner = function(name, businessCode) {
  891. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  892. if(data.success) {
  893. toaster.pop("success", '添加成功', data.success);
  894. }
  895. if(data.error) {
  896. toaster.pop("error", '添加失败', data.error);
  897. }
  898. }, function(response) {
  899. toaster.pop('error','失败',response.data);
  900. });
  901. }
  902. // 物料搜索
  903. var getProdService = function() {
  904. return SearchProd;
  905. };
  906. $scope.prodTableParams = new ngTableParams({
  907. page : 1,
  908. count : 5,
  909. sorting: {
  910. }
  911. }, {
  912. total : 0,
  913. counts: [5, 10, 25, 50],
  914. getData : function($defer, params) {
  915. $scope.loading = true;
  916. var pageParams = params.url();
  917. pageParams.keyword = $rootScope.searchKeyword;
  918. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  919. $scope.loading = false;
  920. if(page) {
  921. $scope.prodtotal = page.totalElement;
  922. params.total(page.totalElement);
  923. $defer.resolve(page.content);
  924. }
  925. }, function(response) {
  926. $scope.loading = false;
  927. toaster.pop('error', '数据加载失败', response.data);
  928. });
  929. }
  930. });
  931. /**
  932. * 向企业购买
  933. */
  934. $scope.PurcByEn = function(businessCode) {
  935. $rootScope.businessCode = businessCode;
  936. window.location.hash = "#/purc/addOrder";
  937. }
  938. /**
  939. * 选中单个物料购买
  940. * @param businessCode
  941. * @param id
  942. */
  943. $scope.PurcByEnAndProd = function(businessCode, id) {
  944. $rootScope.businessCode = businessCode;
  945. $rootScope.prodId = id;
  946. window.location.hash = "#/purc/addOrder";
  947. }
  948. /**
  949. * 询价
  950. */
  951. $scope.PurcInquiry = function(businessCode, id){
  952. $rootScope.prodId = id;
  953. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  954. }
  955. /**
  956. * 邀请注册商务平台
  957. */
  958. $scope.invite = function(name) {
  959. var modalInstance = $modal.open({
  960. animation: true,
  961. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  962. controller: 'InviteCtrl',
  963. resolve: {
  964. enname: function(){return name}
  965. }
  966. });
  967. modalInstance.result.then(function(data) {
  968. InvitationRecord.invite({formStore: data}, {}, function(data) {
  969. if(data.success) {
  970. toaster.pop('success', '提示', data.success);
  971. }
  972. if(data.error) {
  973. toaster.pop('error', '提示', data.error);
  974. }
  975. }, function(response) {
  976. toaster.pop('error', '提示', response.data);
  977. });
  978. });
  979. }
  980. /**
  981. * 立即查看
  982. */
  983. $scope.view = function(name) {
  984. $rootScope.vendName = name;
  985. window.location.hash = "#/baseInfo/myRquest";
  986. }
  987. }]);
  988. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  989. $scope.enter = {
  990. vendname: enname
  991. };
  992. $scope.save = function(enter) {
  993. if(!enter.vendusertel && !enter.venduseremail) {
  994. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  995. } else {
  996. $modalInstance.close(enter);
  997. }
  998. }
  999. $scope.cancel = function() {
  1000. $modalInstance.dismiss();
  1001. }
  1002. }]);
  1003. /**
  1004. * 邀请记录
  1005. */
  1006. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', function($scope, toaster, InvitationRecord, BaseService, ngTableParams) {
  1007. BaseService.scrollBackToTop();
  1008. $scope.status = "invitation";
  1009. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1010. page : 1,
  1011. count : 10,
  1012. sorting: {
  1013. }
  1014. }, {
  1015. total : 0,
  1016. counts: [],
  1017. getData : function($defer, params) { // 获取数据的方法
  1018. $scope.loading = true;
  1019. var pageParams = params.url();
  1020. pageParams.keyword = $scope.keyword;
  1021. $scope.tip = $scope.keyword;
  1022. InvitationRecord.records.call(null, BaseService.parseParams(pageParams), function(page){
  1023. $scope.loading = false;
  1024. if(page) {
  1025. params.total(page.totalElement);
  1026. $defer.resolve(page.content);
  1027. }
  1028. }, function(response){
  1029. $scope.loading = false;
  1030. toaster.pop('error', '数据加载失败', response.data);
  1031. });
  1032. }
  1033. });
  1034. $scope.onSearch = function(keyword){
  1035. $scope.tableParams.page(1);
  1036. $scope.tableParams.reload();
  1037. $scope.tip = keyword;
  1038. }
  1039. }]);
  1040. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1041. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1042. //手机号码格式验证
  1043. // var checkTel = function(data){
  1044. // var userTel = data.userTel;
  1045. // $scope.checkResult = false;
  1046. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  1047. // if(!(telephone).test(userTel)){
  1048. // var modalInstance = $modal.open({
  1049. // animation: true,
  1050. // templateUrl: 'static/tpl/index/account/checkTel.html',
  1051. // controller: 'CheckTelCtrl',
  1052. // backdrop: 'static',
  1053. // keyboard: false,
  1054. // resolve: {
  1055. // user: function(){
  1056. // return data;
  1057. // },
  1058. // }
  1059. // });
  1060. // modalInstance.result.then(function(){
  1061. // }, function(){
  1062. //
  1063. // });
  1064. // } else {
  1065. // $scope.checkResult = true;
  1066. // }
  1067. // };
  1068. AuthenticationService.getAuthentication().success(function(data) {
  1069. if(data.enterprises) {
  1070. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1071. if(data.enterprises.length > 1) {
  1072. var enSelect = [];
  1073. angular.forEach(data.enterprises, function(e){
  1074. if(e.current)
  1075. data.enterprise = e;
  1076. else
  1077. enSelect.push(e);
  1078. });
  1079. data.enSelect = enSelect;
  1080. }
  1081. }
  1082. $scope.userInfo = data;
  1083. if (data == null || !data.userUU) {
  1084. $scope.isAuthed = false;
  1085. AuthenticationService.redirectSignin();
  1086. } else {
  1087. //跳转到手机号码验证
  1088. // checkTel($scope.userInfo);
  1089. }
  1090. });
  1091. $scope.logout = function() {
  1092. AuthenticationService.logout();
  1093. };
  1094. $scope.switchto = function(enUU) {// 切换企业
  1095. AuthenticationService.reSignin(enUU).success(function(){
  1096. $window.location.reload();
  1097. });
  1098. };
  1099. $scope.addFavorite = function(){
  1100. var url = encodeURI(window.location.href);
  1101. try{
  1102. //ie浏览器收藏方式
  1103. window.external.addFavorite(url, "优软商务平台");
  1104. }catch(e) {
  1105. try{
  1106. //火狐浏览器收藏方式
  1107. window.sidebar.addPanel("优软商务平台", url);
  1108. }catch (e) {
  1109. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  1110. "或手动在浏览器里进行设置。");
  1111. }
  1112. }
  1113. };
  1114. }]);
  1115. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1116. $scope.image = {src: null};
  1117. // 图片上传成功之后
  1118. $scope.onUploadSuccess = function(data){
  1119. var path = data.path;
  1120. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1121. $scope.$apply(function(){
  1122. $scope.image.src = data.path;
  1123. $scope.image.thumb = path;
  1124. });
  1125. };
  1126. $scope.close = function() {
  1127. $modalInstance.dismiss();
  1128. };
  1129. $scope.confirm = function() {
  1130. $modalInstance.close($scope.image);
  1131. $scope.imageUrl = null;
  1132. };
  1133. }]);
  1134. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function($scope, SnapshotService, BaseService, $rootScope){
  1135. BaseService.scrollBackToTop();
  1136. SnapshotService.getTodo(function(data){
  1137. $scope.todo = data;
  1138. });
  1139. $scope.setTenderActive = function(active) {
  1140. $rootScope.tenderActive = active;
  1141. window.location.hash = '#/purc/tender';
  1142. }
  1143. }]);
  1144. // header
  1145. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1146. SnapshotService.getMessage(function(data){
  1147. $scope.message = data;
  1148. });
  1149. }]);
  1150. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1151. SaleTruck.query({}, function(data){
  1152. $rootScope.truck = data;
  1153. $scope.truckCount = data ? data.length : 0;
  1154. });
  1155. $scope.$watch(function(){
  1156. return $rootScope.truck;
  1157. }, function(data) {
  1158. $scope.truckCount = data ? data.length : 0;
  1159. }, true);
  1160. $scope.clearAll = function() {
  1161. SaleTruck.remove({}, function(){
  1162. $rootScope.truck = [];
  1163. });
  1164. };
  1165. $scope.openTrack = function() {
  1166. $modal.open({
  1167. templateUrl: 'static/tpl/index/sale/track.html',
  1168. controller: 'TruckModalCtrl',
  1169. size: 'lg'
  1170. }).result.then(function(s){
  1171. if(s) {
  1172. $scope.clearAll();
  1173. $rootScope.dataChanged = true;
  1174. }
  1175. });
  1176. };
  1177. }]);
  1178. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  1179. $scope.saleSend = {sendItems: []};
  1180. SaleTruck.detail({}, function(data){
  1181. // 按物料编号排序
  1182. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1183. });
  1184. $scope.remove = function(index, notice) {
  1185. SaleTruck.remove({noticeId: notice.id}, function(data){
  1186. $rootScope.truck = data;
  1187. $scope.notices.splice(index, 1);
  1188. });
  1189. };
  1190. $scope.$watch(function(){
  1191. return $scope.notices;
  1192. }, function(data) {
  1193. var q = 0, t = 0;
  1194. if(data) {
  1195. angular.forEach(data,function(d){
  1196. q += d.thisSendQty;
  1197. t += d.thisSendQty * d.orderItem.price;
  1198. });
  1199. }
  1200. $scope.totalQty = q;
  1201. $scope.total = t;
  1202. }, true);
  1203. $scope.cancel = function() {
  1204. $modalInstance.close();
  1205. };
  1206. $scope.send = function() {// 发货
  1207. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1208. toaster.pop('error', '错误', '请输入送货单号');
  1209. return;
  1210. }
  1211. var currency = $scope.notices[0].orderItem.order.currency,
  1212. custUU = $scope.notices[0].enUU,
  1213. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1214. var num = 1;
  1215. for(var i in $scope.notices) {
  1216. var item = $scope.notices[i];
  1217. if(item.id) {
  1218. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1219. valid = false;
  1220. break;
  1221. }
  1222. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1223. }
  1224. }
  1225. if(!valid) {
  1226. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1227. } else {
  1228. var send = angular.extend(angular.copy($scope.saleSend), {
  1229. currency: currency,
  1230. custUU: custUU,
  1231. payments: payments,
  1232. sendItems: items
  1233. });
  1234. PurcNotice.sendByBatch({}, send, function(data){
  1235. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1236. $modalInstance.close(true);
  1237. $state.go('sale.send_detail', {id: data.id});
  1238. }, function(response){
  1239. toaster.pop('error', '错误', response.data);
  1240. });
  1241. }
  1242. };
  1243. }]);
  1244. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1245. SaleStat.cust({}, function(data){
  1246. var p = [], q = [];
  1247. angular.forEach(data.month, function(d){
  1248. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1249. });
  1250. angular.forEach(data.year, function(d){
  1251. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1252. });
  1253. $scope.custCharts = {
  1254. month : {
  1255. chartType : 'pie',
  1256. datas : {
  1257. data : p
  1258. },
  1259. config : {
  1260. labels : false,
  1261. title : "客户月采购量排行榜",
  1262. legend : {
  1263. display : true,
  1264. position : 'right'
  1265. },
  1266. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1267. click : function(d) {
  1268. },
  1269. mouseover : function(d) {
  1270. },
  1271. mouseout : function(d) {
  1272. },
  1273. innerRadius : 0,
  1274. lineLegend : 'lineEnd'
  1275. }
  1276. },
  1277. year : {
  1278. chartType : 'pie',
  1279. datas : {
  1280. data : q
  1281. },
  1282. config : {
  1283. labels : false,
  1284. title : "客户年采购量排行榜",
  1285. legend : {
  1286. display : true,
  1287. position : 'right'
  1288. },
  1289. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1290. click : function(d) {
  1291. },
  1292. mouseover : function(d) {
  1293. },
  1294. mouseout : function(d) {
  1295. },
  1296. innerRadius : 0,
  1297. lineLegend : 'lineEnd'
  1298. }
  1299. }
  1300. };
  1301. });
  1302. SaleStat.seller({}, function(data){
  1303. var p = [], q = [];
  1304. angular.forEach(data.month, function(d){
  1305. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1306. });
  1307. angular.forEach(data.year, function(d){
  1308. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1309. });
  1310. $scope.sellerCharts = {
  1311. month : {
  1312. chartType : 'pie',
  1313. datas : {
  1314. data : p
  1315. },
  1316. config : {
  1317. labels : false,
  1318. title : "业务员月销量排行榜",
  1319. legend : {
  1320. display : true,
  1321. position : 'right'
  1322. },
  1323. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1324. click : function(d) {
  1325. },
  1326. mouseover : function(d) {
  1327. },
  1328. mouseout : function(d) {
  1329. },
  1330. innerRadius : 0,
  1331. lineLegend : 'lineEnd'
  1332. }
  1333. },
  1334. year : {
  1335. chartType : 'pie',
  1336. datas : {
  1337. data : q
  1338. },
  1339. config : {
  1340. labels : false,
  1341. title : "业务员年销量排行榜",
  1342. legend : {
  1343. display : true,
  1344. position : 'right'
  1345. },
  1346. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1347. click : function(d) {
  1348. },
  1349. mouseover : function(d) {
  1350. },
  1351. mouseout : function(d) {
  1352. },
  1353. innerRadius : 0,
  1354. lineLegend : 'lineEnd'
  1355. }
  1356. }
  1357. };
  1358. });
  1359. }]);
  1360. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1361. SaleStat.get({}, function(data){
  1362. var p = [], q = [], r = [];
  1363. angular.forEach(data.day, function(d){
  1364. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1365. });
  1366. angular.forEach(data.month, function(d){
  1367. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1368. });
  1369. angular.forEach(data.year, function(d){
  1370. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1371. });
  1372. $scope.charts = {
  1373. day : {
  1374. chartType : "line",
  1375. datas: {
  1376. series: ['销售额'],
  1377. data: p
  1378. },
  1379. config : {
  1380. "labels": false,
  1381. "title": "销售额统计(近15日线)",
  1382. "legend": {
  1383. "display": true,
  1384. "position": "right"
  1385. },
  1386. colors : [ '#4D9934'],
  1387. "innerRadius": 0,
  1388. "lineLegend": "lineEnd"
  1389. }
  1390. },
  1391. month: {
  1392. chartType : "line",
  1393. datas: {
  1394. series: ['销售额'],
  1395. data: q
  1396. },
  1397. config : {
  1398. "labels": false,
  1399. "title": "销售额统计(近12月线)",
  1400. "legend": {
  1401. "display": true,
  1402. "position": "right"
  1403. },
  1404. colors : [ '#4D9934'],
  1405. "innerRadius": 0,
  1406. "lineLegend": "lineEnd"
  1407. }
  1408. },
  1409. year: {
  1410. chartType : "line",
  1411. datas: {
  1412. series: ['销售额'],
  1413. data: r
  1414. },
  1415. config : {
  1416. "labels": false,
  1417. "title": "销售额统计(近10年线)",
  1418. "legend": {
  1419. "display": true,
  1420. "position": "right"
  1421. },
  1422. colors : [ '#4D9934'],
  1423. "innerRadius": 0,
  1424. "lineLegend": "lineEnd"
  1425. }
  1426. }
  1427. };
  1428. });
  1429. }]);
  1430. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1431. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1432. $scope.notices = data;
  1433. });
  1434. $scope.dateTime = new Date();
  1435. }]);
  1436. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1437. // SnapshotService.getTender(250, function(data){
  1438. // $scope.tenders = data;
  1439. // console.log(data);
  1440. // var newDate = new Date();
  1441. // newDate = newDate.setDate(newDate.getDate() - 3);
  1442. // angular.forEach($scope.tenders, function(tender) {
  1443. // if (tender.date > newDate) {
  1444. // tender.isNew = true;
  1445. // } else {
  1446. // tender.isNew = false;
  1447. // }
  1448. // });
  1449. // });
  1450. SnapshotService.getOpenTender(5, function(data){
  1451. $scope.openTenders = data;
  1452. var newDate = new Date();
  1453. newDate = newDate.getTime() - 3*24*60*60*1000;
  1454. angular.forEach($scope.openTenders, function(tender) {
  1455. if (tender.date - newDate > 0) {
  1456. tender.isNew = true;
  1457. } else {
  1458. tender.isNew = false;
  1459. }
  1460. });
  1461. });
  1462. $scope.dateTime = new Date();
  1463. }]);
  1464. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1465. VendorService.getCount(function(date){
  1466. $scope.count = date;
  1467. });
  1468. }]);
  1469. // 客户
  1470. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1471. BaseService.scrollBackToTop();
  1472. $scope.userInfoResult = true;
  1473. AuthenticationService.getAuthentication().success(function(data) {
  1474. $scope.loading = false;
  1475. $scope.thisUser = data;
  1476. });
  1477. var getCustInfos = function(custuu) {
  1478. if(custuu) {
  1479. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1480. $scope.custInfos = data;
  1481. var getPage = function(page, size){
  1482. if($scope.custInfos) {
  1483. var result = {};
  1484. result.totalCount = $scope.custInfos.length;
  1485. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1486. if($scope.custInfos.length % size == 0) {
  1487. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1488. }else {
  1489. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1490. }
  1491. result.first = page == 1;
  1492. result.last = page == result.totalPage;
  1493. result.page = page;
  1494. result.next = page - 0 + 1;
  1495. result.pre = page - 1;
  1496. return result;
  1497. }
  1498. }
  1499. $scope.userdata = getPage(1,4);
  1500. $scope.first = function (){
  1501. $scope.userdata = getPage($scope.userdata.pre,4);
  1502. }
  1503. $scope.last = function (){
  1504. $scope.userdata = getPage($scope.userdata.next,4);
  1505. }
  1506. }, function(response){
  1507. $scope.loading = false;
  1508. toaster.pop('error', '数据加载失败', response.data);
  1509. });
  1510. }
  1511. }
  1512. $scope.addUserInfo = function(customer) {
  1513. //TODO
  1514. if ($scope.thisUser.sys) {
  1515. var modalInstance = $modal.open({
  1516. animation: true,
  1517. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1518. controller: 'AddUserInfoCtrl',
  1519. resolve: {
  1520. customer: function() {
  1521. return customer;
  1522. }
  1523. }
  1524. });
  1525. modalInstance.result.then(function(changed, checked){
  1526. if(changed) {
  1527. if(checked)
  1528. $scope.newUser.roles = checked;
  1529. else
  1530. loadUsers();
  1531. }
  1532. });
  1533. } else {
  1534. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1535. }
  1536. }
  1537. $scope.showUserInfo = function(customer,boo) {
  1538. $scope.custInfo = customer;
  1539. if(boo) {
  1540. getCustInfos(customer.myEnterprise.uu);
  1541. $scope.userInfoResult = true;
  1542. }
  1543. }
  1544. $scope.customerParams = new ngTableParams({
  1545. page : 1,
  1546. count : 10
  1547. }, {
  1548. total : 0,
  1549. counts: [5, 10, 25, 50],
  1550. getData : function($defer, params) {
  1551. $scope.loading = true;
  1552. var pageParams = params.url();
  1553. pageParams.keyword = $scope.keyword;
  1554. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1555. $scope.loading = false;
  1556. if(page) {
  1557. params.total(page.totalElement);
  1558. $defer.resolve(page.content);
  1559. }
  1560. $scope.totalCount = page.totalElement;
  1561. }, function(response){
  1562. $scope.loading = false;
  1563. toaster.pop('error', '数据加载失败', response.data);
  1564. });
  1565. }
  1566. });
  1567. // 搜索框回车
  1568. $scope.onSearch = function(keyword) {
  1569. $scope.customerParams.page(1);
  1570. $scope.customerParams.reload();
  1571. $scope.tip = keyword;
  1572. };
  1573. // 查看详情
  1574. $scope.viewDetail = function(id) {
  1575. window.location.hash = "#/sale/customer/" + id;
  1576. }
  1577. }]);
  1578. // 客户详情
  1579. app.controller('CustomerDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', 'VendorService', 'AuthenticationService', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope, VendorService, AuthenticationService) {
  1580. BaseService.scrollBackToTop();
  1581. $scope.userInfoResult = true;
  1582. AuthenticationService.getAuthentication().success(function(data) {
  1583. $scope.loading = false;
  1584. $scope.thisUser = data;
  1585. });
  1586. $scope.vendorContacts = [];
  1587. var loadData = function() {
  1588. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1589. $scope.customer = data.myEnterprise;
  1590. $scope.customerInfo = data;
  1591. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1592. $scope.Contacts = data;
  1593. });
  1594. // 查看已分配人员
  1595. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1596. $scope.custInfos = data;
  1597. var getPage = function(page, size){
  1598. if($scope.custInfos) {
  1599. var result = {};
  1600. result.totalCount = $scope.custInfos.length;
  1601. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1602. if($scope.custInfos.length % size == 0) {
  1603. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1604. }else {
  1605. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1606. }
  1607. result.first = page == 1;
  1608. result.last = page == result.totalPage;
  1609. result.page = page;
  1610. result.next = page - 0 + 1;
  1611. result.pre = page - 1;
  1612. return result;
  1613. }
  1614. }
  1615. $scope.userdata = getPage(1,4);
  1616. $scope.first = function (){
  1617. $scope.userdata = getPage($scope.userdata.pre,4);
  1618. }
  1619. $scope.last = function (){
  1620. $scope.userdata = getPage($scope.userdata.next,4);
  1621. }
  1622. }, function(response){
  1623. $scope.loading = false;
  1624. toaster.pop('error', '数据加载失败', response.data);
  1625. });
  1626. });
  1627. };
  1628. loadData();
  1629. // 新增客户联系人
  1630. $scope.addContact = function(uu) {
  1631. var modalInstance = $modal.open({
  1632. animation: true,
  1633. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1634. controller: 'AddContacCtrl',
  1635. resolve: {
  1636. }
  1637. });
  1638. modalInstance.result.then(function(data) {
  1639. $scope.contact = data;
  1640. $scope.contact.myenuu = uu;
  1641. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1642. toaster.pop('success', '提示', '联系人保存成功');
  1643. $scope.Contacts.push(data);
  1644. }, function(response) {
  1645. toaster.pop('error', '失败', response.data);
  1646. });
  1647. });
  1648. }
  1649. // 编辑客户联系人
  1650. $scope.edit = function(contact) {
  1651. var modalInstance = $modal.open({
  1652. animation: true,
  1653. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  1654. controller: 'EditContacCtrl',
  1655. resolve: {
  1656. contact: function() {
  1657. return contact;
  1658. }
  1659. }
  1660. });
  1661. modalInstance.result.then(function(data) {
  1662. $scope.contact = data;
  1663. Vendor.saveContact({}, $scope.contact, function(data) {
  1664. toaster.pop('success', '提示', '联系人修改成功');
  1665. }, function(response) {
  1666. toaster.pop('error', '失败', response.data);
  1667. });
  1668. });
  1669. }
  1670. // 删除客户联系人
  1671. $scope.deleteById = function(id, index) {
  1672. $scope.Contacts.splice(index, 1);
  1673. Vendor.deleteContact({id: id}, {}, function(data) {
  1674. toaster.pop('success', '提示', '客户联系人删除成功');
  1675. loadData();
  1676. }, function(response) {
  1677. toaster.pop('error', '提示', response.data);
  1678. });
  1679. }
  1680. // 供应商物料信息
  1681. $scope.viewProdList = function(uu){
  1682. $scope.uu = uu;
  1683. $scope.tableParams.page(1);
  1684. $scope.tableParams.reload();
  1685. };
  1686. // 搜索框回车
  1687. $scope.onSearch = function(keyword) {
  1688. $scope.keyword = keyword;
  1689. $scope.tableParams.page(1);
  1690. $scope.tableParams.reload();
  1691. };
  1692. // 供应商物料信息
  1693. $scope.tableParams = new ngTableParams({
  1694. page : 1,
  1695. count : 10
  1696. }, {
  1697. total : 0,
  1698. counts: [5, 10, 25, 50],
  1699. getData : function($defer, params) {
  1700. $scope.loading = true;
  1701. var pageParams = params.url();
  1702. pageParams.custUU = $scope.uu;
  1703. pageParams.keyword = $scope.keyword;
  1704. $scope.tip = $scope.keyword;
  1705. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1706. $scope.loading = false;
  1707. if(page) {
  1708. params.total(page.totalElement);
  1709. $scope.total = page.totalElement;
  1710. $defer.resolve(page.content);
  1711. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1712. }
  1713. }, function(response){
  1714. $scope.loading = false;
  1715. toaster.pop('error', '数据加载失败', response.data);
  1716. });
  1717. }
  1718. });
  1719. $scope.addUserInfo = function() {
  1720. //TODO
  1721. if ($scope.thisUser.sys) {
  1722. var modalInstance = $modal.open({
  1723. animation: true,
  1724. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1725. controller: 'AddUserInfoCtrl',
  1726. resolve: {
  1727. customer: function() {
  1728. return $scope.customerInfo;
  1729. }
  1730. }
  1731. });
  1732. modalInstance.result.then(function(changed, checked){
  1733. loadData();
  1734. if(changed) {
  1735. if(checked) {
  1736. $scope.newUser.roles = checked;
  1737. } else {
  1738. loadUsers();
  1739. }
  1740. }
  1741. });
  1742. } else {
  1743. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1744. }
  1745. }
  1746. $scope.Quotation = function(uu, id) {
  1747. $rootScope.custuu = uu;
  1748. $rootScope.prodId = id;
  1749. window.location.hash = "#/sale/quotation/new";
  1750. }
  1751. }]);
  1752. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1753. $scope.checkboxes = {
  1754. checked : false
  1755. };
  1756. $scope.loading = true;
  1757. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1758. $scope.userinfos = data;
  1759. $scope.loading = false;
  1760. })
  1761. // 点击勾选全部的复选框
  1762. $scope.checkAll = function() {
  1763. angular.forEach($scope.userinfos, function(item) {
  1764. item.distribute = $scope.checkboxes.checked;
  1765. });
  1766. };
  1767. // 点击其中一个明细的复选框
  1768. $scope.checkOne = function(vendor){
  1769. var result = true;
  1770. angular.forEach($scope.userinfos, function(item) {
  1771. if(item.distribute != true){
  1772. result = false;
  1773. return;
  1774. }
  1775. });
  1776. $scope.checkboxes.checked = result;
  1777. };
  1778. $scope.close = function(save) {
  1779. var chooseResult = [];
  1780. if(save) {
  1781. if(customer.myEnterprise.uu) {
  1782. angular.forEach($scope.userinfos, function(item, i) {
  1783. chooseResult.push(item);
  1784. });
  1785. if(chooseResult.length > 0) {
  1786. $scope.loading = true;
  1787. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1788. $scope.loading = false;
  1789. toaster.pop('success', '提示', '保存成功');
  1790. $modalInstance.close(false);
  1791. }, function(response){
  1792. $scope.loading = false;
  1793. toaster.pop('error', '保存失败', response.data);
  1794. $modalInstance.close(false);
  1795. })
  1796. } else {
  1797. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1798. }
  1799. } else {
  1800. $modalInstance.close(true, $scope.checkboxes.checked);
  1801. }
  1802. } else {
  1803. $modalInstance.close(false);
  1804. }
  1805. };
  1806. }]);
  1807. /**
  1808. * 页面状态按钮过滤
  1809. */
  1810. var getState = function(active) {
  1811. var fn = 'get';
  1812. switch(active) {
  1813. case 'done':
  1814. fn = 'getDone';break;
  1815. case 'todo':
  1816. fn = 'getTodo';break;
  1817. case 'end':
  1818. fn = 'getEnd';break;
  1819. case 'waiting':
  1820. fn = 'getWaiting';break;
  1821. case 'invalid':
  1822. fn = 'getInvalid';break;
  1823. }
  1824. return fn;
  1825. };
  1826. /**
  1827. * 改变单据日期范围
  1828. */
  1829. var getDateCondition = function(zone, condition) {
  1830. var date = new Date();
  1831. if(zone == -1) {
  1832. condition.dateFrom = null;
  1833. condition.dateTo = null;
  1834. } else if(zone == 1) {
  1835. date.setMonth(date.getMonth() - 1);
  1836. condition.dateFrom = date;
  1837. condition.dateTo = new Date();
  1838. } else if (zone == 6) {
  1839. date.setMonth(date.getMonth() - 6);
  1840. condition.dateFrom = date;
  1841. condition.dateTo = new Date();
  1842. } else {
  1843. date.setMonth(date.getMonth() - 6);
  1844. condition.dateFrom = null;
  1845. condition.dateTo = date;
  1846. }
  1847. };
  1848. /**
  1849. * 改变单据交货日期范围
  1850. */
  1851. var getDelveryCondition = function(zone, condition) {
  1852. var date = new Date();
  1853. if(zone == -1) {
  1854. condition.deliveryFrom = null;
  1855. condition.deliveryTo = null;
  1856. } else if(zone == 1) {
  1857. date.setMonth(date.getMonth() + 1);
  1858. condition.deliveryTo = date;
  1859. condition.deliveryFrom = new Date();
  1860. } else if (zone == 2) {
  1861. date.setMonth(date.getMonth() + 2);
  1862. condition.deliveryTo = date;
  1863. condition.deliveryFrom = new Date();
  1864. }
  1865. };
  1866. /**
  1867. * 将日期转化为整数日期
  1868. */
  1869. var getDateTime = function(date) {
  1870. if(angular.isDate(date)) {
  1871. return date.getTime();
  1872. } else {
  1873. return null;
  1874. }
  1875. };
  1876. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1877. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1878. BaseService.scrollBackToTop();
  1879. $scope.active = 'all';
  1880. $scope.dateZoneText = '不限';
  1881. $scope.deliveryZoneText = '不限';
  1882. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1883. $scope.changeDateZone = function(zone) {
  1884. $scope.condition.dateZone = zone;
  1885. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1886. $scope.condition.$dateZoneOpen = false;
  1887. getDateCondition(zone, $scope.condition);
  1888. $scope.tableParams.reload();
  1889. };
  1890. $scope.changeDeliveryZone = function(zone) {
  1891. $scope.condition.deliveryZoneText = zone;
  1892. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1893. $scope.condition.$delievryZoneOpen = false;
  1894. getDelveryCondition(zone, $scope.condition);
  1895. $scope.tableParams.reload();
  1896. };
  1897. // 切换单据类型
  1898. $scope.setActive = function(state) {
  1899. if($scope.active != state) {
  1900. $scope.active = state;
  1901. if($scope.tableParams.page() == 1)
  1902. $scope.tableParams.reload();
  1903. else
  1904. $scope.tableParams.page(1);
  1905. }
  1906. };
  1907. var getPurcStatus = function(active) {
  1908. var fn = 'getPurcAll';
  1909. switch(active) {
  1910. case 'done':
  1911. fn = 'getPurcDone';break;
  1912. case 'todo':
  1913. fn = 'getPurcTodo';break;
  1914. case 'end':
  1915. fn = 'getPurcEnd';break;
  1916. case 'waiting':
  1917. fn = 'getPurcWaiting';break;
  1918. }
  1919. return fn;
  1920. };
  1921. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1922. page : 1,
  1923. count : 5,
  1924. sorting: {
  1925. display: 'desc',
  1926. date: 'desc'
  1927. }
  1928. }, {
  1929. total : 0,
  1930. counts: [5, 10, 15, 25, 50],
  1931. getData : function($defer, params) {// 获取数据的方法
  1932. $scope.loading = true;
  1933. var pageParams = params.url();
  1934. pageParams.searchFilter = { // 筛选条件
  1935. keyword: $scope.keyword,
  1936. fromDate: getDateTime($scope.condition.dateFrom),
  1937. endDate: getDateTime($scope.condition.dateTo)
  1938. };
  1939. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1940. $scope.loading = false;
  1941. if(page) {
  1942. $defer.resolve(page.content);
  1943. $scope.total = page.totalElement;
  1944. params.total(page.totalElement);
  1945. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1946. }
  1947. }, function(response){
  1948. $scope.loading = false;
  1949. toaster.pop('error', '数据加载失败', response.data);
  1950. });
  1951. }
  1952. });
  1953. $scope.getReply = function(item) {
  1954. if(!item.replies) {
  1955. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1956. item.replies = replies;
  1957. });
  1958. }
  1959. };
  1960. $scope.getOrderTotal = function(items) {
  1961. var sum = 0;
  1962. angular.forEach(items, function(item){
  1963. sum += item.qty * item.price;
  1964. });
  1965. return sum;
  1966. };
  1967. $scope.openDatePicker = function($event, item, openParam) {
  1968. $event.preventDefault();
  1969. $event.stopPropagation();
  1970. item[openParam] = !item[openParam];
  1971. };
  1972. $scope.parseDate = function(dateStr) {
  1973. if(dateStr)
  1974. return Date.parse(dateStr, 'yyyy-MM-dd');
  1975. return new Date();
  1976. };
  1977. $scope.checkboxes = {
  1978. checked : false
  1979. };
  1980. // 点击勾选全部的复选框
  1981. $scope.checkAll = function(){
  1982. angular.forEach($scope.tableParams.data, function(item) {
  1983. item.$selected = $scope.checkboxes.checked;
  1984. });
  1985. };
  1986. // 点击其中一个明细的复选框
  1987. $scope.checkOne = function(order){
  1988. var result = true;
  1989. angular.forEach($scope.tableParams.data, function(item) {
  1990. if(item.$selected != true){
  1991. result = false;
  1992. return;
  1993. }
  1994. });
  1995. $scope.checkboxes.checked = result;
  1996. };
  1997. // 搜索框回车
  1998. $scope.onSearch = function(keyword) {
  1999. $scope.tableParams.page(1);
  2000. $scope.tableParams.reload();
  2001. $scope.tip = keyword;
  2002. };
  2003. // 选择查找日期
  2004. $scope.onDateCondition = function(){
  2005. $scope.tableParams.page(1);
  2006. $scope.tableParams.reload();
  2007. };
  2008. }]);
  2009. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2010. var loadData = function() {
  2011. PurcOrder.get({id: $stateParams.id}, function(data){
  2012. $scope.order = data;
  2013. var sum = 0;
  2014. angular.forEach($scope.order.orderItems, function(item){
  2015. sum += item.qty * item.price;
  2016. });
  2017. $scope.order.total = sum;
  2018. if($scope.order.display == 1) {//未查看的设为已查看
  2019. $scope.setDisplay('setRead', $scope.order.id);
  2020. }
  2021. $scope.loading = false;
  2022. });
  2023. };
  2024. loadData();
  2025. $scope.getReply = function(item) {
  2026. if(!item.replies) {
  2027. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2028. item.replies = replies;
  2029. });
  2030. }
  2031. };
  2032. $scope.openDatePicker = function($event, item, openParam) {
  2033. $event.preventDefault();
  2034. $event.stopPropagation();
  2035. item[openParam] = !item[openParam];
  2036. };
  2037. $scope.onReplyClick = function(item, inverse) {
  2038. if(item.reply) {
  2039. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2040. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2041. return;
  2042. }
  2043. var reply = angular.copy(item.reply);
  2044. if(reply.delivery) {
  2045. if(typeof reply.delivery == 'object')
  2046. reply.delivery = reply.delivery.getTime();
  2047. } else {
  2048. reply.delivery = item.delivery;
  2049. }
  2050. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2051. $scope.loading = true;
  2052. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2053. $scope.loading = false;
  2054. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2055. loadData();
  2056. }, function(response){
  2057. $scope.loading = false;
  2058. toaster.pop('error', '回复失败', response.data);
  2059. });
  2060. }
  2061. };
  2062. // // 采购单
  2063. // $scope.print = function(order) {
  2064. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  2065. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2066. // };
  2067. //设置为已查看
  2068. $scope.setDisplay = function(state, orderId) {
  2069. if(orderId) {//设置单个
  2070. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2071. // $scope.tableParams.reload();
  2072. }, function() {
  2073. toaster.pop('error', '错误', "设置失败");
  2074. });
  2075. } else {//设置已勾选的
  2076. var str = null;
  2077. angular.forEach($scope.tableParams.data, function(order) {
  2078. if(order.$selected == true) {
  2079. if(str != null && str != '') str += ',';
  2080. str += order.id;
  2081. }
  2082. });
  2083. if(str != null && str != '') {
  2084. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2085. $scope.tableParams.reload();
  2086. }, function() {
  2087. toaster.pop('error', '错误', "设置失败");
  2088. });
  2089. }
  2090. }
  2091. };
  2092. }]);
  2093. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  2094. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  2095. BaseService.scrollBackToTop();
  2096. $scope.active = 'todo';
  2097. $scope.dateZoneText = '不限';
  2098. $scope.deliveryZoneText = '不限';
  2099. $scope.condition = {dateZone: -1, deliveryZone: -1};
  2100. $scope.changeDateZone = function(zone) {
  2101. $scope.condition.dateZone = zone;
  2102. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2103. $scope.condition.$dateZoneOpen = false;
  2104. getDateCondition(zone, $scope.condition);
  2105. $scope.tableParams.reload();
  2106. };
  2107. $scope.changeDeliveryZone = function(zone) {
  2108. $scope.condition.deliveryZoneText = zone;
  2109. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2110. $scope.condition.$delievryZoneOpen = false;
  2111. getDelveryCondition(zone, $scope.condition);
  2112. $scope.tableParams.reload();
  2113. };
  2114. // 切换单据类型
  2115. $scope.setActive = function(state) {
  2116. if($scope.active != state) {
  2117. $scope.active = state;
  2118. if($scope.tableParams.page() == 1)
  2119. $scope.tableParams.reload();
  2120. else
  2121. $scope.tableParams.page(1);
  2122. }
  2123. };
  2124. // 切换数据来源(正常数据 or 历史数据)
  2125. var getService = function() {
  2126. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  2127. };
  2128. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2129. page : 1,
  2130. count : 5,
  2131. sorting: {
  2132. display: 'desc',
  2133. date: 'desc',
  2134. id: 'desc'
  2135. }
  2136. }, {
  2137. total : 0,
  2138. counts: [5, 10, 15, 25, 50],
  2139. getData : function($defer, params) { // 获取数据的方法
  2140. $scope.loading = true;
  2141. var pageParams = params.url();
  2142. pageParams.searchFilter = { // 筛选条件
  2143. keyword: $scope.keyword,
  2144. fromDate: getDateTime($scope.condition.dateFrom),
  2145. endDate: getDateTime($scope.condition.dateTo)
  2146. };
  2147. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2148. $scope.loading = false;
  2149. if(page) {
  2150. $defer.resolve(page.content);
  2151. params.total(page.totalElement);
  2152. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2153. }
  2154. }, function(response){
  2155. $scope.loading = false;
  2156. toaster.pop('error', '数据加载失败', response.data);
  2157. });
  2158. }
  2159. });
  2160. $scope.getOrderTotal = function(items) {
  2161. var sum = 0;
  2162. angular.forEach(items, function(item){
  2163. sum += item.qty * item.price;
  2164. });
  2165. return sum;
  2166. };
  2167. $scope.openDatePicker = function($event, item, openParam) {
  2168. $event.preventDefault();
  2169. $event.stopPropagation();
  2170. item[openParam] = !item[openParam];
  2171. };
  2172. $scope.parseDate = function(dateStr) {
  2173. if(dateStr)
  2174. return Date.parse(dateStr, 'yyyy-MM-dd');
  2175. return new Date();
  2176. };
  2177. $scope.onReplyClick = function(item, inverse) {
  2178. if(item.reply) {
  2179. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2180. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2181. return;
  2182. }
  2183. var reply = angular.copy(item.reply);
  2184. if(reply.delivery) {
  2185. if(typeof reply.delivery == 'object')
  2186. reply.delivery = reply.delivery.getTime();
  2187. } else {
  2188. reply.delivery = item.delivery;
  2189. }
  2190. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2191. $scope.loading = true;
  2192. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2193. $scope.loading = false;
  2194. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2195. $scope.tableParams.reload();
  2196. }, function(response){
  2197. $scope.loading = false;
  2198. toaster.pop('error', '回复失败', response.data);
  2199. });
  2200. }
  2201. };
  2202. //打印 采购单
  2203. $scope.print = function(order) {
  2204. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2205. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2206. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2207. };
  2208. $scope.getReply = function(item) {
  2209. if(!item.replies) {
  2210. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2211. item.replies = replies;
  2212. });
  2213. }
  2214. };
  2215. $scope.checkboxes = {
  2216. checked : false
  2217. };
  2218. // 点击勾选全部的复选框
  2219. $scope.checkAll = function(){
  2220. angular.forEach($scope.tableParams.data, function(item) {
  2221. item.$selected = $scope.checkboxes.checked;
  2222. });
  2223. };
  2224. // 点击其中一个明细的复选框
  2225. $scope.checkOne = function(order){
  2226. var result = true;
  2227. angular.forEach($scope.tableParams.data, function(item) {
  2228. if(item.$selected != true){
  2229. result = false;
  2230. return;
  2231. }
  2232. });
  2233. $scope.checkboxes.checked = result;
  2234. };
  2235. //批量回复采购订单
  2236. $scope.replyByBatch = function() {
  2237. $scope.loading = true;
  2238. var str = '';
  2239. angular.forEach($scope.tableParams.data, function(order) {
  2240. if(order.$selected == true) {
  2241. angular.forEach(order.orderItems, function(item){
  2242. str += item.id;
  2243. str += ',';
  2244. });
  2245. }
  2246. });
  2247. if(!(str == '')) {
  2248. str = str.substr(0, str.length-1);
  2249. PurcOrderItem.replyByBatch(str, function(){
  2250. $scope.loading = false;
  2251. $scope.tableParams.reload();
  2252. toaster.pop('success', '提示', '批量回复成功');
  2253. }, function(data){
  2254. $scope.loading = false;
  2255. toaster.pop('error', '批量回复失败', data);
  2256. });
  2257. } else {//没有勾选其中的明细
  2258. $scope.loading = false;
  2259. }
  2260. };
  2261. // 搜索框回车
  2262. $scope.onSearch = function() {
  2263. $scope.tableParams.page(1);
  2264. $scope.tableParams.reload();
  2265. };
  2266. // 选择查找日期
  2267. $scope.onDateCondition = function(){
  2268. $scope.tableParams.page(1);
  2269. $scope.tableParams.reload();
  2270. };
  2271. //设置为已查看
  2272. $scope.setDisplay = function(state, orderId) {
  2273. if(orderId) {//设置单个
  2274. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2275. $scope.tableParams.reload();
  2276. }, function() {
  2277. toaster.pop('error', '错误', "设置失败");
  2278. });
  2279. } else {//设置已勾选的
  2280. var str = null;
  2281. angular.forEach($scope.tableParams.data, function(order) {
  2282. if(order.$selected == true) {
  2283. if(str != null && str != '') str += ',';
  2284. str += order.id;
  2285. }
  2286. });
  2287. if(str != null && str != '') {
  2288. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2289. $scope.tableParams.reload();
  2290. }, function() {
  2291. toaster.pop('error', '错误', "设置失败");
  2292. });
  2293. }
  2294. }
  2295. };
  2296. }]);
  2297. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2298. var loadData = function() {
  2299. PurcOrder.get({id: $stateParams.id}, function(data){
  2300. $scope.order = data;
  2301. var sum = 0;
  2302. angular.forEach($scope.order.orderItems, function(item){
  2303. sum += item.qty * item.price;
  2304. });
  2305. $scope.order.total = sum;
  2306. if($scope.order.display == 1) {//未查看的设为已查看
  2307. $scope.setDisplay('setRead', $scope.order.id);
  2308. }
  2309. $scope.loading = false;
  2310. });
  2311. };
  2312. loadData();
  2313. $scope.getReply = function(item) {
  2314. if(!item.replies) {
  2315. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2316. item.replies = replies;
  2317. });
  2318. }
  2319. };
  2320. $scope.openDatePicker = function($event, item, openParam) {
  2321. $event.preventDefault();
  2322. $event.stopPropagation();
  2323. item[openParam] = !item[openParam];
  2324. };
  2325. $scope.onReplyClick = function(item, inverse) {
  2326. if(item.reply) {
  2327. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2328. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2329. return;
  2330. }
  2331. var reply = angular.copy(item.reply);
  2332. if(reply.delivery) {
  2333. if(typeof reply.delivery == 'object')
  2334. reply.delivery = reply.delivery.getTime();
  2335. } else {
  2336. reply.delivery = item.delivery;
  2337. }
  2338. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2339. $scope.loading = true;
  2340. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2341. $scope.loading = false;
  2342. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2343. loadData();
  2344. }, function(response){
  2345. $scope.loading = false;
  2346. toaster.pop('error', '回复失败', response.data);
  2347. });
  2348. }
  2349. };
  2350. // 采购单
  2351. $scope.print = function(order) {
  2352. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2353. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2354. };
  2355. //设置为已查看
  2356. $scope.setDisplay = function(state, orderId) {
  2357. if(orderId) {//设置单个
  2358. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2359. $scope.tableParams.reload();
  2360. }, function() {
  2361. toaster.pop('error', '错误', "设置失败");
  2362. });
  2363. } else {//设置已勾选的
  2364. var str = null;
  2365. angular.forEach($scope.tableParams.data, function(order) {
  2366. if(order.$selected == true) {
  2367. if(str != null && str != '') str += ',';
  2368. str += order.id;
  2369. }
  2370. });
  2371. if(str != null && str != '') {
  2372. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2373. $scope.tableParams.reload();
  2374. }, function() {
  2375. toaster.pop('error', '错误', "设置失败");
  2376. });
  2377. }
  2378. }
  2379. };
  2380. }]);
  2381. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  2382. BaseService.scrollBackToTop();
  2383. $scope.active = 'todo';
  2384. $scope.agreedText = '全部';
  2385. $scope.dateZoneText = '一个月内';
  2386. $scope.condition = {dateZone: 1};
  2387. $scope.changeAgreed = function(agreed) {
  2388. $scope.condition.agreed = agreed;
  2389. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2390. $scope.condition.$agreedOpen = false;
  2391. };
  2392. $scope.changeDateZone = function(zone) {
  2393. $scope.condition.dateZone = zone;
  2394. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2395. $scope.condition.$dateZoneOpen = false;
  2396. };
  2397. $scope.setActive = function(state) {
  2398. if($scope.active != state) {
  2399. $scope.active = state;
  2400. if($scope.tableParams.page() == 1)
  2401. $scope.tableParams.reload();
  2402. else
  2403. $scope.tableParams.page(1);
  2404. }
  2405. };
  2406. var getService = function() {
  2407. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2408. };
  2409. $scope.tableParams = new ngTableParams({
  2410. page : 1,
  2411. count : 5,
  2412. sorting: {
  2413. date: 'desc'
  2414. }
  2415. }, {
  2416. total : 0,
  2417. counts: [5, 10, 25, 50],
  2418. getData : function($defer, params) {
  2419. $scope.loading = true;
  2420. var pageParams = params.url();
  2421. pageParams.keyword = $scope.keyword;
  2422. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2423. $scope.loading = false;
  2424. if(page) {
  2425. params.total(page.totalElement);
  2426. $defer.resolve(page.content);
  2427. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2428. }
  2429. }, function(response){
  2430. $scope.loading = false;
  2431. toaster.pop('error', '数据加载失败', response.data);
  2432. });
  2433. }
  2434. });
  2435. $scope.openDatePicker = function($event, item, openParam) {
  2436. $event.preventDefault();
  2437. $event.stopPropagation();
  2438. item[openParam] = !item[openParam];
  2439. };
  2440. $scope.onReplyClick = function(change) {
  2441. if(change.$agreed) {
  2442. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2443. $scope.loading = true;
  2444. PurcChange.reply({changeId: change.id}, reply, function(){
  2445. $scope.loading = false;
  2446. toaster.pop('info', '提示', '回复成功');
  2447. $scope.tableParams.reload();
  2448. }, function(response){
  2449. $scope.loading = false;
  2450. toaster.pop('error', '回复失败', response.data);
  2451. });
  2452. }
  2453. };
  2454. // 搜索框回车
  2455. $scope.onSearch = function() {
  2456. $scope.tableParams.page(1);
  2457. $scope.tableParams.reload();
  2458. };
  2459. }]);
  2460. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2461. var loadData = function() {
  2462. PurcChange.get({id: $stateParams.id}, function(data){
  2463. $scope.change = data;
  2464. });
  2465. };
  2466. loadData();
  2467. $scope.openDatePicker = function($event, item, openParam) {
  2468. $event.preventDefault();
  2469. $event.stopPropagation();
  2470. item[openParam] = !item[openParam];
  2471. };
  2472. $scope.onReplyClick = function(change) {
  2473. if(change.$agreed) {
  2474. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2475. PurcChange.reply({changeId: change.id}, reply, function(){
  2476. toaster.pop('info', '提示', '回复成功');
  2477. loadData();
  2478. }, function(response){
  2479. toaster.pop('error', '回复失败', response.data);
  2480. });
  2481. }
  2482. };
  2483. }]);
  2484. //采购询价
  2485. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  2486. BaseService.scrollBackToTop();
  2487. $scope.active = 'todo';
  2488. $scope.agreedText = '全部';
  2489. $scope.dateZoneText = '一个月内';
  2490. $scope.condition = {dateZone: 1};
  2491. $scope.changeAgreed = function(agreed) {
  2492. $scope.condition.agreed = agreed;
  2493. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2494. $scope.condition.$agreedOpen = false;
  2495. };
  2496. $scope.changeDateZone = function(zone) {
  2497. $scope.condition.dateZone = zone;
  2498. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2499. $scope.condition.$dateZoneOpen = false;
  2500. };
  2501. $scope.setActive = function(state) {
  2502. if($scope.active != state) {
  2503. $scope.active = state;
  2504. if($scope.tableParams.page() == 1)
  2505. $scope.tableParams.reload();
  2506. else
  2507. $scope.tableParams.page(1);
  2508. }
  2509. };
  2510. // 得到消息
  2511. PurcInquiry.getMessage({}, function(data){
  2512. $scope.message = data;
  2513. }, function(response) {
  2514. });
  2515. var getService = function() {
  2516. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2517. };
  2518. $scope.tableParams = new ngTableParams({
  2519. page : 1,
  2520. count : 5,
  2521. sorting: {
  2522. 'inquiry.date': 'desc',
  2523. 'inquiry.enterprise.enName': 'asc',
  2524. 'inquiry.code': 'asc'
  2525. }
  2526. }, {
  2527. total : 0,
  2528. counts: [5, 10, 25, 50],
  2529. getData : function($defer, params) {
  2530. $scope.loading = true;
  2531. var pageParams = params.url();
  2532. var realActive = {};
  2533. pageParams.keyword = $scope.keyword;
  2534. if ($scope.active == 'overdue') {
  2535. $scope.active = 'end';
  2536. }
  2537. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2538. $scope.loading = false;
  2539. if(page) {
  2540. params.total(page.totalElement);
  2541. $defer.resolve(page.content);
  2542. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2543. }
  2544. }, function(response){
  2545. $scope.loading = false;
  2546. toaster.pop('error', '数据加载失败', response.data);
  2547. });
  2548. }
  2549. });
  2550. $scope.getMinDate = function(item) {
  2551. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2552. };
  2553. $scope.replyPrices = [];
  2554. $scope.replylapQtys = [];
  2555. $scope.replyPrices.push(true);
  2556. $scope.replylapQtys.push(true);
  2557. $scope.addStep = function(inquiryItem) {
  2558. $scope.replyPrices.push(true);
  2559. if(inquiryItem.replies.length >= 10) {
  2560. toaster.pop('warning', '提示', '最多支持10个分段!');
  2561. } else {
  2562. inquiryItem.replies.push({});
  2563. if(inquiryItem.replies.length != 1) {
  2564. $scope.replyPrices.push(true);
  2565. $scope.replylapQtys.push(true);
  2566. }
  2567. }
  2568. };
  2569. $scope.removeStep = function(inquiryItem, stepIndex) {
  2570. inquiryItem.replies.splice(stepIndex, 1);
  2571. $scope.replyPrices.splice(stepIndex, 1);
  2572. $scope.replylapQtys.splice(stepIndex, 1);
  2573. };
  2574. $scope.openDatePicker = function($event, item, openParam) {
  2575. $event.preventDefault();
  2576. $event.stopPropagation();
  2577. item[openParam] = !item[openParam];
  2578. };
  2579. $scope.getHistory = function(item) {
  2580. if(!item.history) {
  2581. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2582. item.history = data;
  2583. });
  2584. }
  2585. };
  2586. $scope.isValid = function(item, withSteps) {
  2587. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2588. if(!withSteps || !bool)
  2589. return bool;
  2590. angular.forEach(item.replies, function(r, i){
  2591. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2592. });
  2593. return bool;
  2594. };
  2595. $scope.onReplyClick = function(item, withSteps) {
  2596. if(item.vendFromDate instanceof Date) {
  2597. item.vendFromDate = item.vendFromDate.getTime();
  2598. }
  2599. if(item.vendToDate instanceof Date) {
  2600. item.vendToDate = item.vendToDate.getTime();
  2601. }
  2602. if(item.vendFromDate > item.vendToDate) {
  2603. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2604. return;
  2605. }
  2606. var replies = [];
  2607. angular.forEach(item.replies, function(r, i){
  2608. if((i > 0 ? r.lapQty : 1) || r.price)
  2609. replies.push(r);
  2610. });
  2611. item.replies = replies;
  2612. $scope.loading = true;
  2613. if(withSteps) {
  2614. PurcInquiry.reply({itemId: item.id}, item, function(){
  2615. $scope.loading = false;
  2616. toaster.pop('info', '提示', '报价成功');
  2617. $scope.tableParams.reload();
  2618. }, function(response){
  2619. $scope.loading = false;
  2620. toaster.pop('error', '报价失败', response.data);
  2621. });
  2622. } else {
  2623. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2624. $scope.loading = false;
  2625. toaster.pop('info', '提示', '保存成功');
  2626. $scope.tableParams.reload();
  2627. }, function(response){
  2628. $scope.loading = false;
  2629. toaster.pop('error', '保存失败', response.data);
  2630. });
  2631. }
  2632. };
  2633. $scope.verifylapQty = function(value,type) {
  2634. var regex = /^\d+(.\d{1,5})?$/;
  2635. $scope.replylapQtys[type] = regex.test(value);
  2636. }
  2637. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2638. $scope.verify = function(value,type) {
  2639. var regex = /^\d+(.\d{1,5})?$/;//
  2640. switch(type) {
  2641. case 'minOrderQty':
  2642. $scope.minOrderQtyVerify = regex.test(value);
  2643. break;
  2644. case 'minPackQty':
  2645. $scope.minPackQtyVerify = regex.test(value);
  2646. break;
  2647. case 'leadtime':
  2648. $scope.leadtimeVerify = regex.test(value);
  2649. break;
  2650. default:
  2651. $scope.replyPrices[type] = regex.test(value);
  2652. break;
  2653. }
  2654. }
  2655. // 搜索框回车
  2656. $scope.onSearch = function() {
  2657. $scope.tableParams.page(1);
  2658. $scope.tableParams.reload();
  2659. };
  2660. }]);
  2661. // 询价单明细
  2662. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2663. var loadData = function() {
  2664. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2665. $scope.newinquiryItems = data;
  2666. var inquiry = data[0].inquiry;
  2667. //inquiry.inquiryItems = data;
  2668. angular.forEach(inquiry.attachs, function(attach){
  2669. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2670. });
  2671. $scope.inquiry = inquiry;
  2672. });
  2673. };
  2674. loadData();
  2675. $scope.getMinDate = function(item) {
  2676. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2677. };
  2678. $scope.addStep = function(inquiryItem) {
  2679. if(inquiryItem.replies.length >= 10) {
  2680. toaster.pop('warning', '提示', '最多支持10个分段!');
  2681. } else
  2682. inquiryItem.replies.push({});
  2683. };
  2684. $scope.removeStep = function(inquiryItem, stepIndex) {
  2685. inquiryItem.replies.splice(stepIndex, 1);
  2686. };
  2687. $scope.openDatePicker = function($event, item, openParam) {
  2688. $event.preventDefault();
  2689. $event.stopPropagation();
  2690. item[openParam] = !item[openParam];
  2691. };
  2692. $scope.getHistory = function(item) {
  2693. if(!item.history) {
  2694. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2695. item.history = data;
  2696. });
  2697. }
  2698. };
  2699. $scope.isValid = function(item, withSteps) {
  2700. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2701. if(!withSteps || !bool)
  2702. return bool;
  2703. angular.forEach(item.replies, function(r, i){
  2704. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2705. });
  2706. return bool;
  2707. };
  2708. $scope.onReplyClick = function(item, withSteps) {
  2709. if(item.vendFromDate instanceof Date) {
  2710. item.vendFromDate = item.vendFromDate.getTime();
  2711. }
  2712. if(item.vendToDate instanceof Date) {
  2713. item.vendToDate = item.vendToDate.getTime();
  2714. }
  2715. if(item.vendFromDate > item.vendToDate) {
  2716. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2717. return;
  2718. }
  2719. var replies = [];
  2720. angular.forEach(item.replies, function(r, i){
  2721. if((i > 0 ? r.lapQty : 1) || r.price)
  2722. replies.push(r);
  2723. });
  2724. item.replies = replies;
  2725. if(withSteps) {
  2726. PurcInquiry.reply({itemId: item.id}, item, function(){
  2727. toaster.pop('info', '提示', '报价成功');
  2728. loadData();
  2729. }, function(response){
  2730. toaster.pop('error', '报价失败', response.data);
  2731. });
  2732. }
  2733. };
  2734. }]);
  2735. // 平台新增的询价单
  2736. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', '$http', 'ShipAddress', 'Search', 'ComponentActiveAPI', function($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout, $http, ShipAddress, Search, ComponentActiveAPI) {
  2737. $scope.status = 'InquiryNew';
  2738. $scope.active = 'all';
  2739. $rootScope.tenderVendor = null;// 清除掉已选择的
  2740. var getService = function() {
  2741. return GetProductInfo;
  2742. };
  2743. $scope.inquiry = {
  2744. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  2745. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  2746. priceType: '采购',
  2747. isOpen: 1,
  2748. invoice: 0,
  2749. ifTax: 1,
  2750. currency: 'RMB'
  2751. };
  2752. $scope.changeCurrency = function(inquiry) {
  2753. if (inquiry.currency !== 'RMB') {
  2754. $scope.notRMB = true;
  2755. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  2756. inquiry.invoice = 0;
  2757. } else {
  2758. $scope.notRMB = false;
  2759. }
  2760. };
  2761. // 获取收货地址列表
  2762. var loadShipAddress = function() {
  2763. ShipAddress.shipAddList({}, function(data) {
  2764. $scope.ships = data;
  2765. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  2766. });
  2767. };
  2768. loadShipAddress();
  2769. // 获取地址信息
  2770. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  2771. }).then(function(response) {
  2772. $scope.provinces = response.data;
  2773. });
  2774. // 新增收货地址保存
  2775. $scope.saveShipAddress = function(ship) {
  2776. ship.address = ship.province + ship.city + ship.district;
  2777. ShipAddress.saveAddress( {}, ship, function(data) {
  2778. if(data.success) {
  2779. // 获取收货地址列表
  2780. loadShipAddress();
  2781. toaster.pop('success', '提示', data.success);
  2782. }
  2783. if(data.error) {
  2784. toaster.pop('error', '提示', data.error);
  2785. }
  2786. });
  2787. };
  2788. $scope.currentDay = function() {
  2789. return $filter('date')(new Date(), 'yyyy-MM-dd');
  2790. };
  2791. $scope.vendors = [];
  2792. // 查找供应商
  2793. $scope.dbfindVendor = function(){
  2794. var modalInstance = $modal.open({
  2795. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  2796. controller: 'DbfindVendorCtrl',
  2797. size: 'lg',
  2798. resolve: {
  2799. }
  2800. });
  2801. modalInstance.result.then(function(data){
  2802. var ifPush = true;
  2803. modalInstance.result.then(function(data){
  2804. angular.forEach(data, function(vendor) {
  2805. if (!$scope.vendors) {// 不存在就先创建
  2806. $scope.vendors = [{}];
  2807. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  2808. } else {
  2809. for (var i = 0;i<$scope.vendors.length; i++) {
  2810. ifPush = true;
  2811. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  2812. ifPush = false;
  2813. break; // 判定到已存在供应商,就终止循环。
  2814. }
  2815. }
  2816. if (ifPush) {
  2817. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  2818. }
  2819. }
  2820. });
  2821. $rootScope.tenderVendor = $scope.vendors;
  2822. }, function(){
  2823. });
  2824. }, function(){
  2825. });
  2826. };
  2827. // 删除一个供应商
  2828. $scope.removeVendor = function(index) {
  2829. $scope.vendors.splice(index, 1);
  2830. };
  2831. // 物料信息
  2832. $scope.tableParams = new ngTableParams({
  2833. page : 1,
  2834. count : 5,
  2835. sorting: {
  2836. }
  2837. }, {
  2838. total : 0,
  2839. counts: [5, 10, 25, 50],
  2840. getData : function($defer, params) {
  2841. $scope.loading = true;
  2842. var pageParams = params.url();
  2843. pageParams.keyword = $scope.keyword;
  2844. $scope.tip = $scope.keyword;
  2845. pageParams.searchFilter = $scope.searchFilter;
  2846. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2847. $scope.loading = false;
  2848. if(page) {
  2849. params.total(page.totalElement);
  2850. $scope.total = page.totalElement;
  2851. $defer.resolve(page.content);
  2852. }
  2853. }, function(response) {
  2854. $scope.loading = false;
  2855. toaster.pop('error', '数据加载失败', response.data);
  2856. });
  2857. }
  2858. });
  2859. // 搜索框回车
  2860. $scope.onSearch = function(keyword) {
  2861. $scope.tableParams.page(1);
  2862. $scope.tableParams.reload();
  2863. };
  2864. $scope.inquiry.inquiryItems = [];
  2865. var prod = {
  2866. prodCode: null,
  2867. prodTitle: null,
  2868. inbrand: null,
  2869. toDate: null,
  2870. unit: 'PCS'
  2871. };
  2872. $scope.inquiry.inquiryItems.push(prod);
  2873. // 联想词start
  2874. // 获取品牌联想词
  2875. $scope.getSimilarBrands = function(value) {
  2876. if (value) {
  2877. // 获取品牌联想词
  2878. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  2879. return data.map(function(item) {
  2880. return item;
  2881. });
  2882. });
  2883. }
  2884. };
  2885. // 获取产品型号联想词
  2886. $scope.getSimilarCodes = function(value) {
  2887. if (value) {
  2888. // 获取产品型号联想词
  2889. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  2890. return data.map(function (item) {
  2891. return item;
  2892. })
  2893. });
  2894. }
  2895. };
  2896. $scope.selectKind = function(prod) {
  2897. var submit = [];
  2898. $modal.open({
  2899. animation: true,
  2900. size: 'lg',
  2901. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  2902. controller: 'ProdKindChooseCtrl',
  2903. resolve: {
  2904. actives: function() {
  2905. return $scope.actives;
  2906. }
  2907. }
  2908. }).result.then(function(data){
  2909. $scope.actives = data.actives;
  2910. var size = data.actives.length;
  2911. submit.gradeOneKiName = '';
  2912. submit.gradeTwoKiName = '';
  2913. submit.gradeThreeKiName = '';
  2914. if (size > 0) {
  2915. submit.gradeOneKiName = $scope.actives[0].nameCn;
  2916. prod.prodTitle = submit.gradeOneKiName;
  2917. if (size > 1) {
  2918. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  2919. prod.prodTitle = submit.gradeTwoKiName;
  2920. if (size > 2) {
  2921. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  2922. prod.prodTitle = submit.gradeThreeKiName;
  2923. }
  2924. }
  2925. }
  2926. }, function(){
  2927. });
  2928. };
  2929. // 点击联想词获取品牌信息
  2930. $scope.onAssociateBrandClick = function(brand, prod) {
  2931. if (brand instanceof String) {
  2932. prod.inbrand = brand;
  2933. } else if (brand instanceof Object) {
  2934. prod.inbrand = brand.brandCn;
  2935. }
  2936. };
  2937. // 打开品牌选择的模态框
  2938. $scope.selectBrand = function(prod){ //打开模态
  2939. var modalInstance = $modal.open({
  2940. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  2941. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  2942. });
  2943. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  2944. });
  2945. modalInstance.result.then(function(brand){
  2946. prod.inbrand = brand.nameCn;
  2947. }, function(reason){
  2948. });
  2949. };
  2950. // 点击联想词获取器件信息 带入产品分类和品牌
  2951. $scope.onAssociateCmpClick = function(cmp, prod) {
  2952. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  2953. $scope.component = data;
  2954. prod.prodCode = data.code;
  2955. prod.prodTitle = data.kind.nameCn;
  2956. prod.inbrand = data.brand.nameCn;
  2957. }, function(res) {
  2958. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  2959. })
  2960. };
  2961. //联想词end
  2962. // 导入商品信息
  2963. $scope.uplodaByBatch = function() {
  2964. var modalInstance = $modal.open({
  2965. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  2966. controller: 'PurcInquiryUploadCtrl',
  2967. size: 'lg',
  2968. resolve: {
  2969. }
  2970. });
  2971. modalInstance.result.then(function(data) {
  2972. angular.forEach(data, function(prod) {
  2973. console.log(prod);
  2974. $scope.inquiry.inquiryItems.push(prod);
  2975. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  2976. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  2977. $scope.inquiry.inquiryItems.splice(i, 1);
  2978. }
  2979. }
  2980. })
  2981. }, function(){
  2982. });
  2983. }
  2984. //增加商品
  2985. $scope.add = function() {
  2986. $scope.inquiry.inquiryItems.push(
  2987. { prodCode: null,
  2988. prodTitle: null,
  2989. unit: 'PCS',
  2990. ibrand: null,
  2991. toDate: null});
  2992. };
  2993. //删除商品
  2994. $scope.del = function(index) {
  2995. $scope.inquiry.inquiryItems.splice(index, 1);
  2996. };
  2997. $scope.check = function(product) {
  2998. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  2999. currency: null, toDate: null, productId: product.id, inbrand: product.brand});
  3000. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3001. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  3002. $scope.inquiry.inquiryItems.splice(i, 1);
  3003. }
  3004. }
  3005. }
  3006. $scope.getMinDate = function(item) {
  3007. return $filter('date')(new Date, 'yyyy-MM-dd');
  3008. };
  3009. $scope.openDatePicker = function($event, openParam, index) {
  3010. $event.preventDefault();
  3011. $event.stopPropagation();
  3012. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  3013. };
  3014. $scope.openEndDatePicker = function($event, item, openParam) {
  3015. $event.preventDefault();
  3016. $event.stopPropagation();
  3017. item[openParam] = !item[openParam];
  3018. };
  3019. // 保存
  3020. $scope.save = function() {
  3021. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3022. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3023. if( $scope.vendors.length > 0) {
  3024. $upload.upload({
  3025. url: 'purc/inquiry/save',
  3026. file: file,
  3027. method: 'POST',
  3028. data: {
  3029. inquiry: $scope.inquiry,
  3030. contacts: $scope.vendors
  3031. },
  3032. }).success(function(data) {
  3033. if(data.success) {
  3034. toaster.pop('success', '提示', data.success);
  3035. $timeout(function() {
  3036. window.location.hash = "#/purc/inquiry_unapply";
  3037. }, 500);
  3038. }
  3039. if(data.error) {
  3040. toaster.pop('error', '提示', data.error);
  3041. }
  3042. }).error(function(data) {
  3043. $scope.loadingShow = false;
  3044. toaster.pop('error', '操作失败', data.error);
  3045. });
  3046. } else {
  3047. toaster.pop('info', '提示', '请先选择供应商');
  3048. }
  3049. } else {
  3050. $upload.upload({
  3051. url: 'purc/inquiry/saveWithoutVendor',
  3052. file: file,
  3053. method: 'POST',
  3054. data: {
  3055. inquiry: $scope.inquiry,
  3056. },
  3057. }).success(function(data) {
  3058. if(data.success) {
  3059. toaster.pop('success', '提示', data.success);
  3060. $timeout(function() {
  3061. window.location.hash = "#/purc/inquiry_unapply";
  3062. }, 500);
  3063. }
  3064. if(data.error) {
  3065. toaster.pop('error', '提示', data.error);
  3066. }
  3067. }).error(function(data) {
  3068. $scope.loadingShow = false;
  3069. toaster.pop('error', '操作失败', data.error);
  3070. });
  3071. }
  3072. }
  3073. // 保存并提交
  3074. $scope.submit = function() {
  3075. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3076. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3077. if($scope.vendors.length > 0) {
  3078. $upload.upload({
  3079. url: 'purc/inquiry/saveAndSubmit',
  3080. file: file,
  3081. method: 'POST',
  3082. data: {
  3083. inquiry: $scope.inquiry,
  3084. contacts: $scope.vendors
  3085. },
  3086. }).success(function(data) {
  3087. if(data.success) {
  3088. toaster.pop('success', '提示', data.success);
  3089. $timeout(function() {
  3090. window.location.hash = "#/purc/purchaseinquiry";
  3091. }, 500);
  3092. }
  3093. if(data.error) {
  3094. toaster.pop('error', '提示', data.error);
  3095. }
  3096. }).error(function(data) {
  3097. $scope.loadingShow = false;
  3098. toaster.pop('error', '操作失败', data.error);
  3099. });
  3100. } else {
  3101. toaster.pop('info', '提示', '请先选择供应商');
  3102. }
  3103. } else {
  3104. $upload.upload({
  3105. url: 'purc/inquiry/saveAndSubmitWithoutVendor',
  3106. file: file,
  3107. method: 'POST',
  3108. data: {
  3109. inquiry: $scope.inquiry,
  3110. },
  3111. }).success(function(data) {
  3112. if(data.success) {
  3113. toaster.pop('success', '提示', data.success);
  3114. $timeout(function() {
  3115. window.location.hash = "#/purc/purchaseinquiry";
  3116. }, 500);
  3117. }
  3118. if(data.error) {
  3119. toaster.pop('error', '提示', data.error);
  3120. }
  3121. }).error(function(data) {
  3122. $scope.loadingShow = false;
  3123. toaster.pop('error', '操作失败', data.error);
  3124. });
  3125. }
  3126. }
  3127. $scope.previewShow = false;
  3128. $scope.pdfShow = false;
  3129. $scope.noneFileShow = true;
  3130. $scope.$watch('myFiles', function(){
  3131. if($scope.myFiles) {
  3132. $scope.noneFileShow = false;
  3133. var file = $scope.myFiles[0];
  3134. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  3135. $scope.pdfShow = true;
  3136. $scope.previewShow = false;
  3137. $scope.imgPreviewName = file.name;
  3138. } else{
  3139. if (typeof(Worker) !== "undefined") {//支持HTML5
  3140. $scope.imgPreview = getObjectURL(file);
  3141. $scope.imgPreviewName = file.name;
  3142. } else{//不支持HTML5
  3143. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  3144. $scope.imgPreviewName = file.name;
  3145. }
  3146. $scope.previewShow = true;
  3147. $scope.pdfShow = false;
  3148. }
  3149. } else {
  3150. $scope.noneFileShow = true;
  3151. $scope.previewShow = false;
  3152. $scope.pdfShow = false;
  3153. }
  3154. });
  3155. //建立一个可存取到该file的url
  3156. var getObjectURL = function(file) {
  3157. var url = null ;
  3158. if (window.createObjectURL!=undefined) { // basic
  3159. url = window.createObjectURL(file) ;
  3160. } else if (window.URL!=undefined) { // mozilla(firefox)
  3161. url = window.URL.createObjectURL(file) ;
  3162. } else if (window.webkitURL!=undefined) { // webkit or chrome
  3163. url = window.webkitURL.createObjectURL(file) ;
  3164. }
  3165. return url ;
  3166. };
  3167. }]);
  3168. /**
  3169. * 代采订单批量导入
  3170. */
  3171. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  3172. // 通过excel批量上传物料
  3173. $scope.result = null;
  3174. $scope.upload = function() {
  3175. var file = $scope.myFiles[0];
  3176. $upload.upload({
  3177. url: 'purc/inquiry/release/excel',
  3178. file: file,
  3179. method: 'POST'
  3180. }).success(function(data) {
  3181. $scope.result = data;
  3182. $scope.success = $scope.result.success;
  3183. $scope.total = $scope.result.total;
  3184. $scope.alters = $scope.result.alters;
  3185. }).error(function(response) {
  3186. toaster.pop('error', response.data || response);
  3187. });
  3188. };
  3189. // 查看范例
  3190. $scope.showImg = function() {
  3191. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  3192. box.show();
  3193. box.find('img').attr('src', src);
  3194. box.find('a').click(function(){
  3195. box.hide();
  3196. });
  3197. box.dblclick(function(){
  3198. box.hide();
  3199. });
  3200. };
  3201. // 下载模板
  3202. $scope.download = function() {
  3203. window.location.href = 'purc/inquiry/upload/template';
  3204. };
  3205. $scope.enSure = function() {
  3206. $modalInstance.close($scope.result.items);
  3207. }
  3208. $scope.cancel = function() {
  3209. $modalInstance.dismiss();
  3210. }
  3211. }]);
  3212. // 平台询价单(已提交)
  3213. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry) {
  3214. $scope.status = 'InquirySubmit';
  3215. BaseService.scrollBackToTop();
  3216. $scope.active = 'todo';
  3217. $scope.agreedText = '全部';
  3218. $scope.dateZoneText = '一个月内';
  3219. $scope.condition = {dateZone: 1};
  3220. $scope.changeAgreed = function(agreed) {
  3221. $scope.condition.agreed = agreed;
  3222. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3223. $scope.condition.$agreedOpen = false;
  3224. };
  3225. $scope.changeDateZone = function(zone) {
  3226. $scope.condition.dateZone = zone;
  3227. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3228. $scope.condition.$dateZoneOpen = false;
  3229. };
  3230. $scope.setActive = function(state) {
  3231. if($scope.active != state ) {
  3232. $scope.active = state;
  3233. if ($scope.tableParams.page() == 1) {
  3234. $scope.tableParams.reload();
  3235. } else {
  3236. $scope.tableParams.page(1);
  3237. }
  3238. }
  3239. }
  3240. var getService = function() {
  3241. return PurchaseInquiry;
  3242. };
  3243. $scope.tableParams = new ngTableParams({
  3244. page : 1,
  3245. count : 5,
  3246. sorting: {
  3247. 'inquiry.date': 'desc',
  3248. 'inquiry.enterprise.enName': 'asc',
  3249. 'inquiry.code': 'asc'
  3250. }
  3251. }, {
  3252. total : 0,
  3253. counts: [5, 10, 25, 50],
  3254. getData : function($defer, params) {
  3255. $scope.loading = true;
  3256. var pageParams = params.url();
  3257. var realActive = {};
  3258. pageParams.keyword = $scope.keyword;
  3259. if ($scope.active == 'overdue') {
  3260. $scope.active = 'end';
  3261. }
  3262. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3263. $scope.loading = false;
  3264. if(page) {
  3265. params.total(page.totalElement);
  3266. $defer.resolve(page.content);
  3267. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3268. }
  3269. }, function(response){
  3270. $scope.loading = false;
  3271. toaster.pop('error', '数据加载失败', response.data);
  3272. });
  3273. }
  3274. });
  3275. $scope.openDatePicker = function($event, item, openParam) {
  3276. $event.preventDefault();
  3277. $event.stopPropagation();
  3278. item[openParam] = !item[openParam];
  3279. };
  3280. // 搜索框回车
  3281. $scope.onSearch = function() {
  3282. $scope.tableParams.page(1);
  3283. $scope.tableParams.reload();
  3284. };
  3285. // 采纳
  3286. $scope.accept = function(id) {
  3287. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3288. if(data.success) {
  3289. toaster.pop('success', '提示', data.success);
  3290. $scope.tableParams.reload();
  3291. }
  3292. if(data.error) {
  3293. toaster.pop('error', '提示', data.error);
  3294. }
  3295. }, function(response) {
  3296. toaster.pop('error', '提示', response.data);
  3297. })
  3298. };
  3299. // 拒绝
  3300. $scope.refuse = function(id) {
  3301. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3302. if(data.success) {
  3303. toaster.pop('success', '提示', data.success);
  3304. $scope.tableParams.reload();
  3305. }
  3306. if(data.error) {
  3307. toaster.pop('error', '提示', data.error);
  3308. }
  3309. }, function(response) {
  3310. toaster.pop('error', '提示', response.data);
  3311. })
  3312. }
  3313. }]);
  3314. // 平台询价单(未提交)
  3315. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster) {
  3316. BaseService.scrollBackToTop();
  3317. $scope.active = 'done';
  3318. var getService = function() {
  3319. if($scope.active == 'todo') {
  3320. return PurchaseInquiry.getUnapply;
  3321. }
  3322. if($scope.active == 'done') {
  3323. return PurchaseInquiry.getSubmit;
  3324. }
  3325. }
  3326. $scope.setActive = function(state) {
  3327. if($scope.active != state ) {
  3328. $scope.active = state;
  3329. if ($scope.tableParams.page() == 1) {
  3330. $scope.tableParams.reload();
  3331. } else {
  3332. $scope.tableParams.page(1);
  3333. }
  3334. }
  3335. }
  3336. $scope.tableParams = new ngTableParams({
  3337. page : 1,
  3338. count : 5,
  3339. sorting: {
  3340. 'date': 'desc',
  3341. 'enterprise.enName': 'asc',
  3342. 'code': 'asc'
  3343. }
  3344. }, {
  3345. total : 0,
  3346. counts: [5, 10, 25, 50],
  3347. getData : function($defer, params) {
  3348. $scope.loading = true;
  3349. var pageParams = params.url();
  3350. var realActive = {};
  3351. if ($scope.active == 'overdue') {
  3352. $scope.active = 'end';
  3353. }
  3354. getService().call(null, BaseService.parseParams(pageParams), function(page){
  3355. $scope.loading = false;
  3356. if(page) {
  3357. params.total(page.totalElements);
  3358. $defer.resolve(page.content);
  3359. }
  3360. }, function(response){
  3361. $scope.loading = false;
  3362. toaster.pop('error', '数据加载失败', response.data);
  3363. });
  3364. }
  3365. });
  3366. // 删除明细
  3367. $scope.deleteById = function(id) {
  3368. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  3369. toaster.pop('success', '提示', '删除成功');
  3370. $scope.tableParams.reload();
  3371. }, function(response) {
  3372. toaster.pop('error', '提示', response.data);
  3373. });
  3374. }
  3375. // 删除主表
  3376. $scope.clearOrder = function(id) {
  3377. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  3378. toaster.pop('success', '提示', '删除成功');
  3379. $scope.tableParams.reload();
  3380. }, function(response) {
  3381. toaster.pop('error', '提示', response.data);
  3382. });
  3383. }
  3384. // 提交
  3385. $scope.submit = function(id) {
  3386. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  3387. toaster.pop('success', '提示', '单据提交成功');
  3388. }, function(response) {
  3389. toaster.pop('error', '提示', response.data);
  3390. })
  3391. }
  3392. // 发布公共询价
  3393. $scope.publish = function(id) {
  3394. PurchaseInquiry.publishInquiry({id: id}, {}, function(data) {
  3395. toaster.pop('success', '提示', data.success);
  3396. }, function(response) {
  3397. toaster.pop('error', '提示', response.data);
  3398. })
  3399. }
  3400. }]);
  3401. // 公共询价列表
  3402. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams) {
  3403. BaseService.scrollBackToTop();
  3404. /**
  3405. * 改变单据日期范围
  3406. */
  3407. var getTenderDateCondition = function(zone, condition) {
  3408. var date = new Date();
  3409. if(zone == -1) {
  3410. condition.dateFrom = null;
  3411. condition.dateTo = null;
  3412. } else if(zone == 7) { // 一星期内
  3413. date.setDate(date.getDate() - 7);
  3414. condition.dateFrom = date;
  3415. condition.dateTo = new Date();
  3416. } else if(zone == 1) { // 一个月内
  3417. date.setMonth(date.getMonth() - 1);
  3418. condition.dateFrom = date;
  3419. condition.dateTo = new Date();
  3420. } else if(zone == 3) { // 三个月内
  3421. date.setMonth(date.getMonth() - 3);
  3422. condition.dateFrom = date;
  3423. condition.dateTo = new Date();
  3424. } else if (zone == 6) { // 半年内
  3425. date.setMonth(date.getMonth() - 6);
  3426. condition.dateFrom = date;
  3427. condition.dateTo = new Date();
  3428. } else { // 一年内
  3429. date.setYear(date.getYear() - 1);
  3430. condition.dateFrom = date;
  3431. condition.dateTo = new Date();
  3432. }
  3433. };
  3434. $scope.dateZoneText = '不限';
  3435. $scope.deliveryZoneText = '不限';
  3436. $scope.condition = {dateZone: -1};
  3437. $scope.changeDateZone = function(zone) {
  3438. $scope.condition.dateZone = zone;
  3439. $scope.condition.$dateZoneOpen = false;
  3440. getTenderDateCondition(zone, $scope.condition);
  3441. $scope.tableParams.reload();
  3442. };
  3443. $scope.openDatePicker = function($event, item, openParam) {
  3444. $event.preventDefault();
  3445. $event.stopPropagation();
  3446. item[openParam] = !item[openParam];
  3447. };
  3448. $scope.parseDate = function(dateStr) {
  3449. if(dateStr)
  3450. return Date.parse(dateStr, 'yyyy-MM-dd');
  3451. return new Date();
  3452. };
  3453. // 选择查找日期
  3454. $scope.onDateCondition = function(){
  3455. $scope.tableParams.page(1);
  3456. $scope.tableParams.reload();
  3457. };
  3458. // $scope.setActive = function(state) {
  3459. // if($scope.active != state) {
  3460. // $scope.active = state;
  3461. // if($scope.tableParams.page() == 1)
  3462. // $scope.tableParams.reload();
  3463. // else
  3464. // $scope.tableParams.page(1);
  3465. // }
  3466. // };
  3467. $scope.nowdate = new Date().getTime();
  3468. var getOpenState = function(active) {
  3469. var fn = 'getOpenAll';
  3470. switch(active) {
  3471. case 'all':
  3472. fn = 'getOpenAll';break;
  3473. case 'todo':
  3474. fn = 'getOpenTodo';break;
  3475. case 'end':
  3476. fn = 'getOpenEnd';break;
  3477. }
  3478. return fn;
  3479. };
  3480. $scope.tableParams = new ngTableParams({
  3481. page : 1,
  3482. count : 10,
  3483. sorting: {
  3484. // 'tender.endDate': 'desc',
  3485. // 'tender.enterprise.enName': 'asc',
  3486. // 'tender.code': 'asc'
  3487. }
  3488. }, {
  3489. total : 0,
  3490. counts: [10, 25, 50, 100],
  3491. getData : function($defer, params) {
  3492. $scope.loading = true;
  3493. var pageParams = params.url();
  3494. // var realActive = {};
  3495. pageParams.searchFilter = { // 筛选条件
  3496. keyword: $scope.keyword,
  3497. fromDate: getDateTime($scope.condition.dateFrom),
  3498. endDate: getDateTime($scope.condition.dateTo)
  3499. };
  3500. // AccountEnterprise.get({}, function(data){
  3501. // $scope.loading = false;
  3502. // $scope.currentEn = data;
  3503. // });
  3504. PurchaseInquiry.publicInquiryItem.call(null, BaseService.parseParams(pageParams), function(page){
  3505. $scope.loading = false;
  3506. if(page) {
  3507. params.total(page.totalElement);
  3508. $defer.resolve(page.content);
  3509. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  3510. }
  3511. }, function(response){
  3512. $scope.loading = false;
  3513. toaster.pop('error', '数据加载失败', response.data);
  3514. });
  3515. }
  3516. });
  3517. $scope.toDetail = function(id) {
  3518. window.location.hash = '#/baseInfo/inquiryList/' + id;
  3519. };
  3520. // 搜索框回车
  3521. $scope.onSearch = function() {
  3522. $scope.tableParams.page(1);
  3523. $scope.tableParams.reload();
  3524. };
  3525. }]);
  3526. /**
  3527. * 公共询价详情
  3528. */
  3529. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise) {
  3530. BaseService.scrollBackToTop();
  3531. $scope.currentHasBid = false;
  3532. var loadData = function() {
  3533. PurchaseInquiry.inquiryItemDetail({id: $stateParams.id}, function(data) {
  3534. $scope.inquiryItem = data.inquiryItem;
  3535. if(data.id) {
  3536. $scope.id = data.id;
  3537. console.log($scope.id);
  3538. $scope.currentHasBid = true;
  3539. }
  3540. }, function(response) {
  3541. toaster.pop('error', '提示', response.data);
  3542. });
  3543. }
  3544. loadData();
  3545. // 当前时间
  3546. $scope.nowdate = new Date().getTime();
  3547. // 当前企业
  3548. AccountEnterprise.get({}, function(data){
  3549. $scope.loading = false;
  3550. $scope.enterprise = data;
  3551. });
  3552. // 转客户询价
  3553. $scope.transtoInquiry = function(id) {
  3554. PurchaseInquiry.transtoInquiry({id: id}, {}, function(data) {
  3555. if(data.success) {
  3556. toaster.pop('success', '提示', data.success);
  3557. window.location.hash = "sale/inquiry/" + data.id;
  3558. }
  3559. if(data.error) {
  3560. toaster.pop('error', '提示', data.error);
  3561. }
  3562. if(data.info) {
  3563. toaster.pop('info', '提示', data.info);
  3564. }
  3565. }, function(response) {
  3566. toaster.pop('error', '提示', response.data);
  3567. });
  3568. }
  3569. }]);
  3570. // 询价单明细
  3571. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  3572. var loadData = function() {
  3573. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  3574. $scope.newinquiryItems = data;
  3575. var inquiry = data[0].inquiry;
  3576. //inquiry.inquiryItems = data;
  3577. angular.forEach(inquiry.attachs, function(attach){
  3578. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3579. });
  3580. $scope.inquiry = inquiry;
  3581. });
  3582. };
  3583. loadData();
  3584. $scope.getMinDate = function(item) {
  3585. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3586. };
  3587. $scope.addStep = function(inquiryItem) {
  3588. if(inquiryItem.replies.length >= 10) {
  3589. toaster.pop('warning', '提示', '最多支持10个分段!');
  3590. } else
  3591. inquiryItem.replies.push({});
  3592. };
  3593. $scope.removeStep = function(inquiryItem, stepIndex) {
  3594. inquiryItem.replies.splice(stepIndex, 1);
  3595. };
  3596. $scope.openDatePicker = function($event, item, openParam) {
  3597. $event.preventDefault();
  3598. $event.stopPropagation();
  3599. item[openParam] = !item[openParam];
  3600. };
  3601. $scope.getHistory = function(item) {
  3602. if(!item.history) {
  3603. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3604. item.history = data;
  3605. });
  3606. }
  3607. };
  3608. $scope.isValid = function(item, withSteps) {
  3609. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3610. if(!withSteps || !bool)
  3611. return bool;
  3612. angular.forEach(item.replies, function(r, i){
  3613. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3614. });
  3615. return bool;
  3616. };
  3617. $scope.onReplyClick = function(item, withSteps) {
  3618. if(item.vendFromDate instanceof Date) {
  3619. item.vendFromDate = item.vendFromDate.getTime();
  3620. }
  3621. if(item.vendToDate instanceof Date) {
  3622. item.vendToDate = item.vendToDate.getTime();
  3623. }
  3624. if(item.vendFromDate > item.vendToDate) {
  3625. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3626. return;
  3627. }
  3628. var replies = [];
  3629. angular.forEach(item.replies, function(r, i){
  3630. if((i > 0 ? r.lapQty : 1) || r.price)
  3631. replies.push(r);
  3632. });
  3633. item.replies = replies;
  3634. if(withSteps) {
  3635. PurcInquiry.reply({itemId: item.id}, item, function(){
  3636. toaster.pop('info', '提示', '报价成功');
  3637. loadData();
  3638. }, function(response){
  3639. toaster.pop('error', '报价失败', response.data);
  3640. });
  3641. }
  3642. };
  3643. }]);
  3644. // 询价单明细(发出)
  3645. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', function($scope, $stateParams, PurchaseInquiry,$filter, toaster){
  3646. var loadData = function() {
  3647. PurchaseInquiry.detail({id: $stateParams.id}, function(data){
  3648. $scope.inquiry = data;
  3649. });
  3650. };
  3651. loadData();
  3652. $scope.getMinDate = function(item) {
  3653. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3654. };
  3655. $scope.addStep = function(inquiryItem) {
  3656. if(inquiryItem.replies.length >= 10) {
  3657. toaster.pop('warning', '提示', '最多支持10个分段!');
  3658. } else
  3659. inquiryItem.replies.push({});
  3660. };
  3661. $scope.removeStep = function(inquiryItem, stepIndex) {
  3662. inquiryItem.replies.splice(stepIndex, 1);
  3663. };
  3664. $scope.openDatePicker = function($event, item, openParam) {
  3665. $event.preventDefault();
  3666. $event.stopPropagation();
  3667. item[openParam] = !item[openParam];
  3668. };
  3669. $scope.getHistory = function(item) {
  3670. if(!item.history) {
  3671. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3672. item.history = data;
  3673. });
  3674. }
  3675. };
  3676. $scope.isValid = function(item, withSteps) {
  3677. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3678. if(!withSteps || !bool)
  3679. return bool;
  3680. angular.forEach(item.replies, function(r, i){
  3681. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3682. });
  3683. return bool;
  3684. };
  3685. $scope.onReplyClick = function(item, withSteps) {
  3686. if(item.vendFromDate instanceof Date) {
  3687. item.vendFromDate = item.vendFromDate.getTime();
  3688. }
  3689. if(item.vendToDate instanceof Date) {
  3690. item.vendToDate = item.vendToDate.getTime();
  3691. }
  3692. if(item.vendFromDate > item.vendToDate) {
  3693. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3694. return;
  3695. }
  3696. var replies = [];
  3697. angular.forEach(item.replies, function(r, i){
  3698. if((i > 0 ? r.lapQty : 1) || r.price)
  3699. replies.push(r);
  3700. });
  3701. item.replies = replies;
  3702. if(withSteps) {
  3703. PurcInquiry.reply({itemId: item.id}, item, function(){
  3704. toaster.pop('info', '提示', '报价成功');
  3705. loadData();
  3706. }, function(response){
  3707. toaster.pop('error', '报价失败', response.data);
  3708. });
  3709. }
  3710. };
  3711. // 采纳
  3712. $scope.accept = function(id) {
  3713. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3714. if(data.success) {
  3715. toaster.pop('success', '提示', data.success);
  3716. loadData();
  3717. }
  3718. if(data.error) {
  3719. toaster.pop('error', '提示', data.error);
  3720. }
  3721. }, function(response) {
  3722. toaster.pop('error', '提示', response.data);
  3723. })
  3724. };
  3725. // 拒绝
  3726. $scope.refuse = function(id) {
  3727. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3728. if(data.success) {
  3729. toaster.pop('success', '提示', data.success);
  3730. loadData();
  3731. }
  3732. if(data.error) {
  3733. toaster.pop('error', '提示', data.error);
  3734. }
  3735. }, function(response) {
  3736. toaster.pop('error', '提示', response.data);
  3737. })
  3738. }
  3739. }]);
  3740. // 模具询价管理
  3741. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  3742. BaseService.scrollBackToTop();
  3743. $scope.active = 'todo';
  3744. $scope.agreedText = '全部';
  3745. $scope.dateZoneText = '不限';
  3746. $scope.condition = {dateZone: -1};
  3747. var inquiryMould_copy = {};
  3748. $scope.changeAgreed = function(agreed) {
  3749. $scope.condition.agreed = agreed;
  3750. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3751. $scope.condition.$agreedOpen = false;
  3752. };
  3753. $scope.changeDateZone = function(zone) {
  3754. $scope.condition.dateZone = zone;
  3755. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3756. $scope.condition.$dateZoneOpen = false;
  3757. };
  3758. $scope.setActive = function(state) {
  3759. if($scope.active != state ) {
  3760. $scope.active = state;
  3761. if ($scope.tableParams.page() == 1) {
  3762. $scope.tableParams.reload();
  3763. } else {
  3764. $scope.tableParams.page(1);
  3765. }
  3766. }
  3767. };
  3768. var getService = function() {
  3769. return PurcInquiryMould;
  3770. };
  3771. $scope.tableParams = new ngTableParams({
  3772. page: 1,
  3773. count: 5
  3774. },{
  3775. total: 0,
  3776. counts: [5, 10, 25, 50],
  3777. getData: function($defer, params) {
  3778. $scope.loading = true;
  3779. var pageParams = params.url();
  3780. var realActive = {};
  3781. pageParams.keyword = $scope.keyword;
  3782. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3783. $scope.loading = false;
  3784. // 用来验证价格修改
  3785. var mould = page.content;
  3786. inquiryMould_copy = angular.copy(mould);
  3787. if(page) {
  3788. params.total(page.totalElement);
  3789. $defer.resolve(page.content);
  3790. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3791. }
  3792. }, function(response){
  3793. $scope.loading = false;
  3794. toaster.pop('error', '数据加载失败', response.data);
  3795. });
  3796. }
  3797. })
  3798. $scope.getMinDate = function(item) {
  3799. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  3800. };
  3801. $scope.replyPrices = [];
  3802. $scope.replyPrices.push(true);
  3803. // 取消
  3804. $scope.reload = function() {
  3805. $scope.tableParams.reload();
  3806. $scope.canSave = false;
  3807. }
  3808. // 能否保存设置
  3809. $scope.canSave = false;
  3810. // items价格验证
  3811. $scope.verifyItems = function(price, reply) {
  3812. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  3813. if(regex.test(price) && price != 0) {
  3814. if (price != reply) {
  3815. $scope.canSave = true;
  3816. } else {
  3817. $scope.canSave = false;
  3818. }
  3819. } else {
  3820. $scope.canSave = false;
  3821. }
  3822. }
  3823. // prod下prods价格验证
  3824. $scope.verifyProds = function(price, reply) {
  3825. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3826. if(regex.test(price) && price != 0) {
  3827. if (price != reply) {
  3828. $scope.canSave = true;
  3829. } else {
  3830. $scope.canSave = false;
  3831. }
  3832. } else {
  3833. $scope.canSave = false;
  3834. }
  3835. }
  3836. //有价格为0或者不符合正则式,则不能报价
  3837. $scope.notZero = function (mould) {
  3838. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3839. angular.forEach(mould.inquiryMouldItems, function(item){
  3840. if (item.price == 0 || !regex.test(item.price)) {
  3841. $scope.canSave = false;
  3842. }
  3843. angular.forEach(item.inquiryMouldDetails, function(detail){
  3844. if (detail.price == 0 || !regex.test(detail.price)) {
  3845. $scope.canSave = false;
  3846. }
  3847. })
  3848. });
  3849. }
  3850. $scope.blurPrice = function (price) {
  3851. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3852. if (!regex.test(price)) {
  3853. toaster.pop('warning','格式错误','请输入有效价格');
  3854. }
  3855. }
  3856. // 获取历史报价
  3857. $scope.getHistory = function(mould) {
  3858. if(!mould.history) {
  3859. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3860. mould.history = data;
  3861. });
  3862. }
  3863. };
  3864. $scope.uploadAttach = function(mould) {
  3865. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3866. var file = mould.attachs[0];
  3867. $scope.mould = mould;
  3868. $upload.upload({
  3869. url: 'sale/mould/' + mould.id + '/send',
  3870. method: 'POST',
  3871. file: file,
  3872. data: {
  3873. json: $scope.mould
  3874. }
  3875. }).success(function(res){
  3876. }).error(function(res){
  3877. });
  3878. }
  3879. // 保存并确认报价
  3880. $scope.onReplyClick = function(mould, withSteps) {
  3881. $scope.loading = true;
  3882. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3883. // var file = mould.attachs[0];
  3884. // $scope.mould = mould;
  3885. // $upload.upload({
  3886. // url: 'sale/mould/' + mould.id + '/send',
  3887. // method: 'POST',
  3888. // file: file,
  3889. // data: {
  3890. // json: $scope.mould
  3891. // }
  3892. // }).success(function(res){
  3893. // console.log("success");
  3894. // console.log(res);
  3895. // }).error(function(res){
  3896. // console.log("failure");
  3897. // });
  3898. if(withSteps) {
  3899. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3900. $scope.loading = false;
  3901. toaster.pop('info', '提示', '报价成功');
  3902. $scope.tableParams.reload();
  3903. $scope.canSave = false;
  3904. }, function(response){
  3905. $scope.loading = false;
  3906. toaster.pop('error', '报价失败', response.data);
  3907. });
  3908. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3909. }, function(response){
  3910. });
  3911. } else {
  3912. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3913. $scope.loading = false;
  3914. toaster.pop('info', '提示', '保存成功');
  3915. $scope.tableParams.reload();
  3916. }, function(response){
  3917. $scope.loading = false;
  3918. toaster.pop('error', '保存失败', response.data);
  3919. });
  3920. }
  3921. };
  3922. // 搜索框回车
  3923. $scope.onSearch = function() {
  3924. $scope.tableParams.page(1);
  3925. $scope.tableParams.reload();
  3926. };
  3927. $scope.openDatePicker = function($event, item, openParam) {
  3928. $event.preventDefault();
  3929. $event.stopPropagation();
  3930. item[openParam] = !item[openParam];
  3931. };
  3932. $scope.parseDate = function(dateStr) {
  3933. if(dateStr)
  3934. return Date.parse(dateStr, 'yyyy-MM-dd');
  3935. return new Date();
  3936. };
  3937. }]);
  3938. // 模具询价单明细
  3939. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  3940. var inquiryMould_copy = {};
  3941. var loadData = function() {
  3942. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  3943. // 用来验证价格修改
  3944. inquiryMould_copy = angular.copy(data);
  3945. $scope.inquiryMould_copy = inquiryMould_copy;
  3946. $scope.newinquirymould = data;
  3947. var mould = data;
  3948. angular.forEach(mould.attachs, function(attach){
  3949. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3950. });
  3951. $scope.inquiryMould = mould;
  3952. });
  3953. };
  3954. loadData();
  3955. $scope.getMinDate = function(item) {
  3956. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3957. };
  3958. // 取消
  3959. $scope.reload = function() {
  3960. loadData();
  3961. $scope.canSave = false;
  3962. }
  3963. //有价格为0,则不能报价
  3964. $scope.notZero = function (mould) {
  3965. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3966. angular.forEach(mould.inquiryMouldItems, function(item){
  3967. if (item.price == 0 || !regex.test(item.price)) {
  3968. $scope.canSave = false;
  3969. }
  3970. angular.forEach(item.inquiryMouldDetails, function(detail){
  3971. if (detail.price == 0 || !regex.test(detail.price)) {
  3972. $scope.canSave = false;
  3973. }
  3974. })
  3975. });
  3976. }
  3977. $scope.blurPrice = function (price) {
  3978. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3979. if (!regex.test(price)) {
  3980. toaster.pop('warning','格式错误','请输入有效价格');
  3981. }
  3982. }
  3983. // 获取历史报价
  3984. $scope.getHistory = function(mould) {
  3985. if(!mould.history) {
  3986. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3987. mould.history = data;
  3988. });
  3989. }
  3990. };
  3991. $scope.canSave = false;
  3992. // items价格验证
  3993. $scope.verifyItems = function(price, index) {
  3994. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3995. if(regex.test(price) && price != 0) {
  3996. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  3997. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  3998. $scope.canSave = true;
  3999. } else {
  4000. $scope.canSave = false;
  4001. }
  4002. } else {
  4003. $scope.canSave = false;
  4004. }
  4005. }
  4006. // prod下prods价格验证
  4007. $scope.verifyProds = function(price, index, parentIndex) {
  4008. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4009. if(regex.test(price) && price != 0) {
  4010. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  4011. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  4012. $scope.canSave = true;
  4013. } else {
  4014. $scope.canSave = false;
  4015. }
  4016. } else {
  4017. $scope.canSave = false;
  4018. }
  4019. }
  4020. // // 上传附件
  4021. // $scope.uploadAttach = function(mould) {
  4022. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4023. // var file = mould.attachs[0];
  4024. // $scope.mould = mould;
  4025. // $upload.upload({
  4026. // url: 'sale/mould/' + mould.id + '/send',
  4027. // method: 'POST',
  4028. // file: file,
  4029. // data: {
  4030. // json: $scope.mould
  4031. // }
  4032. // }).success(function(res){
  4033. // console.log("success");
  4034. // console.log(res);
  4035. // }).error(function(res){
  4036. // console.log("failure");
  4037. // console.log(res);
  4038. // });
  4039. // }
  4040. $scope.onReplyClick = function(mould, withSteps) {
  4041. $scope.loading = true;
  4042. // var file = mould.attachs[0];
  4043. // $scope.mould = mould;
  4044. // $upload.upload({
  4045. // url: 'sale/mould/' + mould.id + '/send',
  4046. // method: 'POST',
  4047. // file: file,
  4048. // data: {
  4049. // json: $scope.mould
  4050. // }
  4051. // }).success(function(res){
  4052. //
  4053. // }).error(function(res){
  4054. // console.log(res);
  4055. // });
  4056. if(withSteps) {
  4057. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4058. $scope.loading = false;
  4059. toaster.pop('info', '提示', '报价成功');
  4060. loadData();
  4061. $scope.canSave = false;
  4062. }, function(response){
  4063. $scope.loading = false;
  4064. toaster.pop('error', '报价失败', response.data);
  4065. });
  4066. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4067. }, function(response){
  4068. });
  4069. } else {
  4070. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4071. $scope.loading = false;
  4072. toaster.pop('info', '提示', '保存成功');
  4073. loadData();
  4074. }, function(response){
  4075. $scope.loading = false;
  4076. toaster.pop('error', '保存失败', response.data);
  4077. });
  4078. }
  4079. };
  4080. }]);
  4081. // 主动报价 - 列表
  4082. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope){
  4083. BaseService.scrollBackToTop();
  4084. $rootScope.enteryStatus = false;
  4085. $scope.active = 'todo';
  4086. $scope.agreedText = '全部';
  4087. $scope.dateZoneText = '一个月内';
  4088. $scope.condition = {dateZone: 1};
  4089. $scope.changeDateZone = function(zone) {
  4090. $scope.condition.dateZone = zone;
  4091. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4092. $scope.condition.$dateZoneOpen = false;
  4093. };
  4094. $scope.setActive = function(state) {
  4095. if($scope.active != state) {
  4096. $scope.active = state;
  4097. if($scope.tableParams.page() == 1)
  4098. $scope.tableParams.reload();
  4099. else
  4100. $scope.tableParams.page(1);
  4101. }
  4102. };
  4103. var getService = function() {
  4104. return Quotation;
  4105. };
  4106. $scope.tableParams = new ngTableParams({
  4107. page : 1,
  4108. count : 5,
  4109. sorting: {
  4110. 'quotation.date': 'desc'
  4111. }
  4112. }, {
  4113. total : 0,
  4114. counts: [5, 10, 25, 50],
  4115. getData : function($defer, params) {
  4116. $scope.loading = true;
  4117. var pageParams = params.url();
  4118. pageParams.keyword = $scope.keyword;
  4119. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4120. $scope.loading = false;
  4121. if(page) {
  4122. params.total(page.totalElement);
  4123. $defer.resolve(page.content);
  4124. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4125. }
  4126. }, function(response){
  4127. $scope.loading = false;
  4128. toaster.pop('error', '数据加载失败', response.data);
  4129. });
  4130. }
  4131. });
  4132. $scope.getHistory = function(item) {
  4133. if(!item.history) {
  4134. PurcInquiry.getHistory({itemId: item.id}, function(data){
  4135. item.history = data;
  4136. });
  4137. }
  4138. };
  4139. $scope.isValid = function(item, withSteps) {
  4140. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4141. if(!withSteps || !bool)
  4142. return bool;
  4143. angular.forEach(item.replies, function(r, i){
  4144. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4145. });
  4146. return bool;
  4147. };
  4148. // 搜索框回车
  4149. $scope.onSearch = function() {
  4150. $scope.tableParams.page(1);
  4151. $scope.tableParams.reload();
  4152. };
  4153. }]);
  4154. // Controller 主动报价 - 新增
  4155. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope){
  4156. BaseService.scrollBackToTop();
  4157. var staticItem = null;
  4158. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  4159. $scope.loading = true;
  4160. $rootScope.enteryStatus = true;
  4161. Quotation.getItem({id: $stateParams.id}, function(data){
  4162. data.$editing = false;
  4163. $scope.item = data;
  4164. staticItem = angular.copy(data);
  4165. $scope.loading = false;
  4166. }, function(response){
  4167. $scope.loading = false;
  4168. toaster.pop('error', '数据加载失败', response.data);
  4169. });
  4170. } else {// 新增模式
  4171. $rootScope.enteryStatus = false;
  4172. $scope.item = {
  4173. quotation: {
  4174. currency: 'RMB',
  4175. taxrate: 17,
  4176. date: new Date()
  4177. },
  4178. product: {},
  4179. prices: [{lapQty: 0}],
  4180. minOrderQty: 1,
  4181. minPackQty: 1,
  4182. $endDateOpen: false,
  4183. $editing: true
  4184. };
  4185. }
  4186. $scope.getMinDate = function(item) {
  4187. return $filter('date')(new Date, 'yyyy-MM-dd');
  4188. };
  4189. $scope.openDatePicker = function($event, openParam) {
  4190. $event.preventDefault();
  4191. $event.stopPropagation();
  4192. $scope.item.$endDateOpen = !openParam;
  4193. };
  4194. // 增加一个分段
  4195. $scope.addPrice = function(){
  4196. if($scope.item.prices.length >= 10) {
  4197. toaster.pop('warning', '提示', '最多支持10个分段!');
  4198. } else
  4199. $scope.item.prices.push({});
  4200. };
  4201. // 删除一个分段
  4202. $scope.removePrice = function(index) {
  4203. $scope.item.prices.splice(index, 1);
  4204. };
  4205. // 查找客户
  4206. $scope.dbfindCust = function(){
  4207. if($scope.item.$editing) {
  4208. var modalInstance = $modal.open({
  4209. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  4210. controller: 'DbfindCustCtrl',
  4211. size: 'lg',
  4212. resolve: {
  4213. }
  4214. });
  4215. modalInstance.result.then(function(data){
  4216. $scope.item.quotation.cust = data.myEnterprise;
  4217. $scope.item.quotation.custUser = data.myUser;
  4218. $scope.item.product = null;
  4219. }, function(){
  4220. });
  4221. }
  4222. };
  4223. // 赋值客户信息
  4224. if($rootScope.custuu) {
  4225. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function(data) {
  4226. $scope.item.quotation.cust = data.myEnterprise;
  4227. $scope.item.quotation.custUser = data.myUser;
  4228. })
  4229. }
  4230. // 赋值物料信息
  4231. if($rootScope.prodId) {
  4232. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  4233. $scope.item.product.code = data.code;
  4234. $scope.item.product.title = data.title;
  4235. $scope.item.product.spec = data.spec;
  4236. $scope.item.product.unit = data.unit;
  4237. $scope.item.product.id = data.id;
  4238. }, function(response) {
  4239. });
  4240. }
  4241. // 查找客户物料
  4242. $scope.dbfindCustProd = function(){
  4243. if($scope.item.$editing) {
  4244. if($scope.item.quotation.cust.uu) {
  4245. var modalInstance = $modal.open({
  4246. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  4247. controller: 'DbfindCustProdCtrl',
  4248. size: 'lg',
  4249. resolve: {
  4250. custUU: function(){return $scope.item.quotation.cust.uu}
  4251. }
  4252. });
  4253. modalInstance.result.then(function(data){
  4254. $scope.item.product = data;
  4255. }, function(){
  4256. });
  4257. } else {
  4258. toaster.pop('error', '错误', '请先选择客户');
  4259. }
  4260. }
  4261. };
  4262. // 保存
  4263. $scope.save = function(){
  4264. $scope.loading = true;
  4265. if(!$scope.item.quotation.code) //新增,设单号
  4266. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  4267. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  4268. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  4269. $scope.item.productId = $scope.item.product.id;
  4270. $scope.item.quotation.status = 100;//在录入
  4271. if($scope.item.quotation.date instanceof Date) {
  4272. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  4273. }
  4274. if($scope.item.quotation.endDate instanceof Date) {
  4275. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  4276. }
  4277. Quotation.save({}, $scope.item, function(data){
  4278. $scope.loading = false;
  4279. toaster.pop('success', '成功', '保存成功');
  4280. if($stateParams.id)
  4281. window.location.reload();
  4282. else
  4283. window.location.hash = '#/sale/quotation/' + data.id;
  4284. }, function(response){
  4285. $scope.loading = false;
  4286. toaster.pop('error', '保存失败', response.data);
  4287. });
  4288. };
  4289. // 更新
  4290. $scope.update = function(){
  4291. $scope.item.$editing = true;
  4292. };
  4293. // 取消
  4294. $scope.cancel = function(){
  4295. $scope.item.$editing = false;
  4296. $scope.item = angular.copy(staticItem);
  4297. };
  4298. // 提交
  4299. $scope.submit = function(){
  4300. $scope.loading = true;
  4301. $scope.item.quotation.status = 101;//在录入
  4302. Quotation.save({}, $scope.item, function(data){
  4303. $scope.loading = false;
  4304. toaster.pop('success', '成功', '提交成功');
  4305. window.location.hash = '#/sale/quotation/' + data.id;
  4306. }, function(response){
  4307. $scope.loading = false;
  4308. toaster.pop('error', '保存失败', response.data);
  4309. });
  4310. };
  4311. }]);
  4312. // 查找客户
  4313. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  4314. BaseService.scrollBackToTop();
  4315. $scope.tableParams = new ngTableParams({
  4316. page : 1,
  4317. count : 10
  4318. }, {
  4319. total : 0,
  4320. counts: [5, 10, 25, 50],
  4321. getData : function($defer, params) {
  4322. $scope.loading = true;
  4323. var pageParams = params.url();
  4324. pageParams.keyword = $scope.keyword;
  4325. Customer.get(BaseService.parseParams(pageParams), function(page){
  4326. $scope.loading = false;
  4327. if(page) {
  4328. params.total(page.totalElements);
  4329. $defer.resolve(page.content);
  4330. }
  4331. $scope.totalCount = page.totalElements;
  4332. }, function(response){
  4333. $scope.loading = false;
  4334. toaster.pop('error', '数据加载失败', response.data);
  4335. });
  4336. }
  4337. });
  4338. $scope.onSearch = function() {
  4339. $scope.tableParams.page(1);
  4340. $scope.tableParams.reload();
  4341. };
  4342. $scope.cancel = function() {
  4343. $modalInstance.dismiss();
  4344. };
  4345. $scope.check = function(cust){
  4346. $modalInstance.close(cust);
  4347. };
  4348. }]);
  4349. // 查找客户物料
  4350. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  4351. BaseService.scrollBackToTop();
  4352. $scope.tableParams = new ngTableParams({
  4353. page : 1,
  4354. count : 10
  4355. }, {
  4356. total : 0,
  4357. counts: [5, 10, 25, 50],
  4358. getData : function($defer, params) {
  4359. $scope.loading = true;
  4360. var pageParams = params.url();
  4361. pageParams.keyword = $scope.keyword;
  4362. pageParams.custUU = custUU;
  4363. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  4364. $scope.loading = false;
  4365. if(page) {
  4366. params.total(page.totalElements);
  4367. $defer.resolve(page.content);
  4368. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4369. }
  4370. }, function(response){
  4371. $scope.loading = false;
  4372. toaster.pop('error', '数据加载失败', response.data);
  4373. });
  4374. }
  4375. });
  4376. // 取消
  4377. $scope.cancel = function() {
  4378. $modalInstance.dismiss();
  4379. };
  4380. // 选择
  4381. $scope.check = function(cust){
  4382. $modalInstance.close(cust);
  4383. };
  4384. // 搜索框回车
  4385. $scope.onSearch = function() {
  4386. $scope.tableParams.page(1);
  4387. $scope.tableParams.reload();
  4388. };
  4389. }]);
  4390. // 查找供应商
  4391. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  4392. BaseService.scrollBackToTop();
  4393. // 搜索框回车
  4394. $scope.onSearch = function(keyword) {
  4395. $scope.keyword = keyword;
  4396. $scope.tableParams.page(1);
  4397. $scope.tableParams.reload();
  4398. };
  4399. $scope.tableParams = new ngTableParams({
  4400. page : 1,
  4401. count : 10
  4402. }, {
  4403. total : 0,
  4404. counts: [10, 25, 50, 100],
  4405. getData : function($defer, params) {
  4406. $scope.loading = true;
  4407. var pageParams = params.url();
  4408. pageParams.keyword = $scope.keyword;
  4409. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  4410. $scope.loading = false;
  4411. if(page) {
  4412. params.total(page.totalElements);
  4413. $defer.resolve(page.content);
  4414. // 添加供应商时,将已存在的选中
  4415. if ($rootScope.tenderVendor) {
  4416. angular.forEach(page.content, function(vendor) {
  4417. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  4418. vendor.checked = false;
  4419. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  4420. vendor.checked = true;
  4421. break;
  4422. }
  4423. }
  4424. });
  4425. }
  4426. }
  4427. $scope.totalCount = page.totalElements;
  4428. }, function(response){
  4429. $scope.loading = false;
  4430. toaster.pop('error', '数据加载失败', response.data);
  4431. });
  4432. }
  4433. });
  4434. $scope.cancel = function() {
  4435. $modalInstance.dismiss();
  4436. };
  4437. $scope.checks = {
  4438. checked : false
  4439. };// 全选框
  4440. $scope.checkAll = function() {
  4441. angular.forEach($scope.tableParams.data, function(vendor) {
  4442. vendor.checked = $scope.checks.checked;
  4443. });
  4444. };
  4445. // 单选
  4446. $scope.checkOne = function(vendor) {
  4447. vendor.checked = true;
  4448. var checked = true;
  4449. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  4450. if (!message.checked) {
  4451. checked = false;
  4452. }
  4453. });
  4454. $scope.checks.checked = checked;
  4455. };
  4456. // 单反选
  4457. $scope.unCheckOne = function(vendor) {
  4458. vendor.checked = false;
  4459. $scope.checks.checked = false;
  4460. };
  4461. $scope.close = function(){
  4462. var vendors = [];
  4463. angular.forEach($scope.tableParams.data, function(vendor) {
  4464. if(vendor.checked) {
  4465. vendors.push(vendor);
  4466. $modalInstance.close(vendors);
  4467. }
  4468. });
  4469. };
  4470. }]);
  4471. // 发货提醒
  4472. 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){
  4473. BaseService.scrollBackToTop();
  4474. $scope.active = 'todo';
  4475. $scope.currency = Symbol.currency;
  4476. $scope.dateZoneText = '不限';
  4477. $scope.condition = {dateZone: -1};
  4478. $scope.changeDateZone = function(zone) {
  4479. $scope.condition.dateZone = zone;
  4480. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4481. $scope.condition.$dateZoneOpen = false;
  4482. getDateCondition(zone, $scope.condition);
  4483. $scope.tableParams.reload();
  4484. };
  4485. $scope.setActive = function(state) {
  4486. if($scope.active != state) {
  4487. $scope.active = state;
  4488. if($scope.tableParams.page() == 1)
  4489. $scope.tableParams.reload();
  4490. else
  4491. $scope.tableParams.page(1);
  4492. }
  4493. };
  4494. var getService = function() {
  4495. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  4496. };
  4497. $scope.tableParams = new ngTableParams({
  4498. page : 1,
  4499. count : 5,
  4500. sorting: {
  4501. 'delivery': 'asc',
  4502. 'orderItemOrderCode': 'asc',
  4503. 'orderItemNumber': 'asc'
  4504. }
  4505. }, {
  4506. total : 0,
  4507. counts: [5, 10, 25, 50],
  4508. getData : function($defer, params) {
  4509. $scope.loading = true;
  4510. var pageParams = params.url();
  4511. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4512. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4513. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4514. $scope.loading = false;
  4515. if(page) {
  4516. params.total(page.totalElement);
  4517. $defer.resolve(page.content);
  4518. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4519. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4520. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4521. }
  4522. }, function(response){
  4523. $scope.loading = false;
  4524. toaster.pop('error', '数据加载失败', response.data);
  4525. });
  4526. }
  4527. });
  4528. $scope.openDatePicker = function($event, item, openParam) {
  4529. $event.preventDefault();
  4530. $event.stopPropagation();
  4531. item[openParam] = !item[openParam];
  4532. };
  4533. //生成随机单号
  4534. $scope.autoCode = function(notice){
  4535. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  4536. };
  4537. //可送货日期
  4538. $scope.sendDate = function(notice) {
  4539. var stock = notice.orderItem.product.ltinstock || 0;
  4540. var de = new Date(notice.delivery);
  4541. if(stock == -1) {
  4542. de.setMonth(de.getMonth() -1);
  4543. de.setDate(25);
  4544. } else if(stock >= 0) {
  4545. de.setDate(de.getDate() - stock -1);
  4546. }
  4547. return de;
  4548. };
  4549. $scope.onReplyClick = function(notice) {
  4550. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  4551. toaster.pop('warning', '警告', '数量填写错误!');
  4552. } else if(!notice.send.code) {
  4553. toaster.pop('warning', '警告', '请填写发货单号!');
  4554. } else {
  4555. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  4556. $scope.loading = true;
  4557. PurcNotice.save({id: notice.id}, send, function(data){
  4558. $scope.loading = false;
  4559. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  4560. $state.go('sale.send_detail', {id: data.id});
  4561. }, function(response){
  4562. $scope.loading = false;
  4563. toaster.pop('error', '发货失败', response.data);
  4564. });
  4565. }
  4566. };
  4567. $scope.checkboxes = {
  4568. checked : false
  4569. };
  4570. // 点击勾选全部的复选框
  4571. $scope.checkAll = function(){
  4572. angular.forEach($scope.tableParams.data, function(item) {
  4573. if(!item.waiting)
  4574. item.$selected = $scope.checkboxes.checked;
  4575. });
  4576. };
  4577. // 点击其中一个明细的复选框
  4578. $scope.checkOne = function(order){
  4579. var result = true;
  4580. angular.forEach($scope.tableParams.data, function(item) {
  4581. if(item.$selected != true){
  4582. result = false;
  4583. return;
  4584. }
  4585. });
  4586. $scope.checkboxes.checked = result;
  4587. };
  4588. $scope.sendByBatch = function(){
  4589. var modalInstance = $modal.open({
  4590. animation: true,
  4591. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  4592. controller: 'SaleNoticeSendByBatchCtrl',
  4593. size: 'lg',
  4594. resolve: {
  4595. selectedNotices: function(){return $scope.tableParams.data;}
  4596. }
  4597. });
  4598. modalInstance.result.then(function(){
  4599. $scope.tableParams.reload();
  4600. }, function(){
  4601. });
  4602. };
  4603. $scope.getSends = function(notice){
  4604. if( ! notice.sends && notice.endQty > 0){
  4605. notice.getSendsing = true;
  4606. notice.getSendsError = false;
  4607. PurcNotice.getSends({id: notice.id}, function(data){
  4608. notice.getSendsing = false;
  4609. notice.getSendsError = false;
  4610. notice.sends = data;
  4611. }, function(response){
  4612. notice.getSendsing = false;
  4613. notice.getSendsError = true;
  4614. });
  4615. }
  4616. };
  4617. // 搜索框回车
  4618. $scope.onSearch = function() {
  4619. $scope.tableParams.page(1);
  4620. $scope.tableParams.reload();
  4621. };
  4622. // 选择查找日期
  4623. $scope.onDateCondition = function(){
  4624. $scope.tableParams.page(1);
  4625. $scope.tableParams.reload();
  4626. };
  4627. //货车功能
  4628. var truck = $rootScope.truck;
  4629. if(!truck) {
  4630. SaleTruck.query({}, function(data){
  4631. $rootScope.truck = data;
  4632. });
  4633. }
  4634. $scope.isInTruck = function(noticeId) {
  4635. return truck.indexOf(noticeId) > -1;
  4636. };
  4637. $scope.addtoTruck = function(notice) {
  4638. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  4639. $rootScope.truck = data;
  4640. });
  4641. };
  4642. $scope.delFromTruck = function(notice) {
  4643. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  4644. $rootScope.truck = data;
  4645. });
  4646. };
  4647. $scope.$watch(function(){
  4648. return $rootScope.truck;
  4649. }, function(data) {
  4650. truck = $rootScope.truck;
  4651. }, true);
  4652. $scope.$watch(function(){
  4653. return $rootScope.dataChanged;
  4654. }, function(data) {
  4655. data && ($scope.tableParams.reload());
  4656. }, true);
  4657. }]);
  4658. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  4659. $scope.notices = angular.copy(selectedNotices);
  4660. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4661. $scope.saleSend = {
  4662. code: '',
  4663. payments: '',
  4664. currency: '',
  4665. custUU: null,
  4666. custUserUU: null,
  4667. remark: '批量发货',
  4668. sendItems: []
  4669. };
  4670. // 计算总数、总额
  4671. $scope.$watch(function(){
  4672. return $scope.notices;
  4673. }, function(data) {
  4674. var q = 0, t = 0;
  4675. if(data) {
  4676. angular.forEach(data,function(d){
  4677. q += (d.thisSendQty || 0);
  4678. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  4679. });
  4680. }
  4681. $scope.totalQty = q;
  4682. $scope.total = t;
  4683. }, true);
  4684. /**
  4685. * 删除一个已选中的送货提醒
  4686. */
  4687. $scope.removeOne = function(index) {
  4688. $scope.notices.splice(index, 1);
  4689. };
  4690. //确认送货
  4691. $scope.sendByBatch = function () {
  4692. $scope.saleSend.sendItems = [];
  4693. if($scope.saleSend.code == '') {//送货单号为空
  4694. toaster.pop('error', '错误', '请输入送货单号');
  4695. return;
  4696. }
  4697. var a = 0;
  4698. var num = 1;
  4699. var valid = true;
  4700. angular.forEach($scope.notices, function(item, key){
  4701. if(item.$selected) {
  4702. if(a == 0) {//第一次
  4703. $scope.saleSend.currency = item.orderItem.order.currency;
  4704. $scope.saleSend.custUU = item.enUU;
  4705. $scope.saleSend.payments = item.orderItem.order.payments;
  4706. a = 1;
  4707. } else {//其他
  4708. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  4709. if($scope.saleSend.custUU != item.enUU) valid = false;
  4710. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  4711. }
  4712. $scope.saleSend.sendItems.push({
  4713. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  4714. });
  4715. }
  4716. });
  4717. if(!valid) {
  4718. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  4719. } else {
  4720. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  4721. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  4722. $modalInstance.close('success');
  4723. $state.go('sale.send_detail', {id: data.id});
  4724. }, function(response){
  4725. toaster.pop('error', '错误', response.data);
  4726. });
  4727. }
  4728. };
  4729. $scope.cancel = function () {
  4730. $modalInstance.dismiss();
  4731. };
  4732. }]);
  4733. /**
  4734. * 发货单
  4735. */
  4736. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  4737. BaseService.scrollBackToTop();
  4738. $scope.active = 'all';
  4739. $scope.currency = Symbol.currency;
  4740. $scope.dateZoneText = '不限';
  4741. $scope.condition = {dateZone: -1};
  4742. $scope.changeDateZone = function(zone) {
  4743. $scope.condition.dateZone = zone;
  4744. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4745. $scope.condition.$dateZoneOpen = false;
  4746. getDateCondition(zone, $scope.condition);
  4747. $scope.tableParams.reload();
  4748. };
  4749. $scope.setActive = function(state) {
  4750. if($scope.active != state) {
  4751. $scope.active = state;
  4752. if($scope.tableParams.page() == 1)
  4753. $scope.tableParams.reload();
  4754. else
  4755. $scope.tableParams.page(1);
  4756. }
  4757. };
  4758. var getService = function() {
  4759. return SaleSend;
  4760. };
  4761. $scope.tableParams = new ngTableParams({
  4762. page : 1,
  4763. count : 5,
  4764. sorting: {
  4765. date: 'desc'
  4766. }
  4767. }, {
  4768. total : 0,
  4769. counts: [5, 10, 25, 50],
  4770. getData : function($defer, params) {
  4771. $scope.loading = true;
  4772. var pageParams = params.url();
  4773. pageParams.keyword = $scope.keyword;
  4774. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4775. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4776. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4777. $scope.loading = false;
  4778. if(page) {
  4779. params.total(page.totalElement);
  4780. $defer.resolve(page.content);
  4781. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4782. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4783. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4784. }
  4785. }, function(response){
  4786. $scope.loading = false;
  4787. toaster.pop('error', '数据加载失败', response.data);
  4788. });
  4789. }
  4790. });
  4791. $scope.openDatePicker = function($event, item, openParam) {
  4792. $event.preventDefault();
  4793. $event.stopPropagation();
  4794. item[openParam] = !item[openParam];
  4795. };
  4796. // 搜索框回车
  4797. $scope.onSearch = function() {
  4798. $scope.tableParams.page(1);
  4799. $scope.tableParams.reload();
  4800. };
  4801. // 选择查找日期
  4802. $scope.onDateCondition = function(){
  4803. $scope.tableParams.page(1);
  4804. $scope.tableParams.reload();
  4805. };
  4806. }]);
  4807. /**
  4808. * 发货单(包括发货条码维护)
  4809. */
  4810. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  4811. var loading = true;
  4812. $scope.checkBarCode = [];
  4813. $scope.checkBoxCode = [];
  4814. var vm = $scope.vm = {};
  4815. $scope.getCheckedItems = {};
  4816. vm.editBar = false;
  4817. vm.showBarCode = [];
  4818. $scope.barCode = function() {
  4819. vm.editBar = !vm.editBar;
  4820. }
  4821. $scope.checkboxes = {
  4822. checked : false
  4823. };
  4824. $scope.checkbars = {
  4825. checked : false
  4826. };
  4827. // 点击勾选barCode全部的复选框
  4828. $scope.checkBarAll = function(){
  4829. angular.forEach($scope.checkBarCode, function(item,key) {
  4830. $scope.checkBarCode[key] = $scope.checkbars.checked;
  4831. });
  4832. };
  4833. //点击barCode单选
  4834. $scope.checkBarOne = function() {
  4835. var result = true;
  4836. angular.forEach($scope.checkBarCode, function(item,key) {
  4837. if(item != true){
  4838. result = false;
  4839. return;
  4840. }
  4841. });
  4842. $scope.checkbars.checked = result;
  4843. }
  4844. // 点击boxCode全部的复选框
  4845. $scope.checkBoxAll = function(){
  4846. angular.forEach($scope.checkBoxCode, function(item,key) {
  4847. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  4848. });
  4849. };
  4850. //点击boxCode单选
  4851. $scope.checkBoxOne = function() {
  4852. var result = true;
  4853. angular.forEach($scope.checkBoxCode, function(item) {
  4854. if(item != true){
  4855. result = false;
  4856. return;
  4857. }
  4858. });
  4859. $scope.checkboxes.checked = result;
  4860. }
  4861. /**
  4862. * 生成条码和箱号
  4863. */
  4864. $scope.generateBarCode = function(item) {
  4865. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  4866. $scope.getCheckedItems = [];
  4867. var warningdata = '';
  4868. angular.forEach($scope.checkBarCode, function(item,key) {
  4869. $scope.getCheckedItem = {};
  4870. if(item == true ){
  4871. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4872. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  4873. $scope.getCheckedItems.push($scope.getCheckedItem);
  4874. //判断是否生成过条码
  4875. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4876. warningdata += $scope.order.sendItems[key].number+","
  4877. }
  4878. }
  4879. });
  4880. if($scope.getCheckedItems.length == 0){
  4881. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  4882. return;
  4883. }
  4884. if(warningdata != ''){
  4885. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  4886. return ;
  4887. }
  4888. }
  4889. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  4890. toaster.pop('success', '提示','生成成功!');
  4891. loadData();
  4892. },function(response){
  4893. $scope.loading = false;
  4894. toaster.pop('error', '生成失败', response.data);
  4895. });
  4896. }
  4897. /**
  4898. * 打印条码和箱号
  4899. */
  4900. $scope.printCode = function(type) {
  4901. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4902. //勾选需要打印的行
  4903. $scope.getCheckedItems = [];
  4904. var warningdata = ''
  4905. angular.forEach($scope.checkBarCode, function(item,key) {
  4906. $scope.getCheckedItem = {};
  4907. if(item == true ){
  4908. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4909. $scope.getCheckedItems.push($scope.getCheckedItem);
  4910. //判断是否生成过条码
  4911. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4912. warningdata += $scope.order.sendItems[key].number+","
  4913. }
  4914. }
  4915. });
  4916. if($scope.getCheckedItems.length == 0){
  4917. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  4918. return;
  4919. }
  4920. if(warningdata == ''){
  4921. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  4922. return;
  4923. }
  4924. //选择打印模板
  4925. var modalInstance = $modal.open({
  4926. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4927. controller: 'BarPrintModalCtrl',
  4928. resolve: {
  4929. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  4930. }
  4931. });
  4932. modalInstance.result.then(function(s){
  4933. if(s) {
  4934. //获取打印数据
  4935. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  4936. if(s.type == 'print'){//判断选择是打印还是打印预览
  4937. lodopPrint(data.message,LODOP,type);
  4938. }else if(s.type == 'printPreview'){
  4939. lodopPrintPreview(data.message,LODOP,type);
  4940. }
  4941. },function(response){
  4942. toaster.pop('error', '获取打印数据失败', response.data);
  4943. });
  4944. }
  4945. });
  4946. };
  4947. //打印单个条码
  4948. $scope.printSingleCode = function(id){
  4949. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4950. //选择打印模板
  4951. var modalInstance = $modal.open({
  4952. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4953. controller: 'BarPrintModalCtrl',
  4954. resolve: {
  4955. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  4956. }
  4957. });
  4958. modalInstance.result.then(function(s){
  4959. if(s) {
  4960. //获取打印数据
  4961. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  4962. if(s.type == 'print'){//判断选择是打印还是打印预览
  4963. lodopSPrint(data.message,LODOP);
  4964. }else if(s.type == 'printPreview'){
  4965. lodopSPrintPreview(data.message,LODOP);
  4966. }
  4967. },function(response){
  4968. toaster.pop('error', '获取打印数据失败', response.data);
  4969. });
  4970. }
  4971. });
  4972. }
  4973. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  4974. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4975. if (selectOrNot != -1) {
  4976. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4977. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4978. var strs = pagesize.split("*"); //字符分割
  4979. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4980. angular.forEach(printStore, function(data, index) {
  4981. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4982. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4983. if (data['LP_VALUETYPE'] == 'barcode') {
  4984. 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']);
  4985. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4986. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4987. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4988. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4989. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4990. } else if (data['LP_VALUETYPE'] == 'text') {
  4991. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4992. }
  4993. });
  4994. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4995. LODOP.PRINT();
  4996. }
  4997. };
  4998. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  4999. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5000. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5001. var strs = pagesize.split("*"); //字符分割
  5002. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5003. angular.forEach(printStore,function(data,index){
  5004. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5005. if(data['LP_VALUETYPE'] == 'barcode'){
  5006. 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']);
  5007. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5008. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5009. }else if(data['LP_VALUETYPE'] == 'text'){
  5010. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5011. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5012. }
  5013. });
  5014. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5015. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5016. LODOP.PREVIEW();//打印预览
  5017. };
  5018. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  5019. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5020. if (selectOrNot != -1) {
  5021. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5022. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  5023. var strs= new Array(); //定义一数组
  5024. strs = pagesize.split("*"); //字符分割
  5025. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5026. var ids = new Array();
  5027. angular.forEach(printStore, function(value,key) {
  5028. //LODOP.NewPage();
  5029. angular.forEach(value['data'], function(record,key) {
  5030. angular.forEach(record['store'], function(data, index) {
  5031. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5032. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5033. if (data['LP_VALUETYPE'] == 'barcode') {
  5034. 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']);
  5035. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5036. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5037. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5038. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5039. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5040. } else if (data['LP_VALUETYPE'] == 'text') {
  5041. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5042. }
  5043. });
  5044. });
  5045. var o = new Object();
  5046. o['id'] = record['si_id']
  5047. ids.push(o);
  5048. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5049. LODOP.PRINT();
  5050. });
  5051. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5052. if(type == 'Bar'){
  5053. //更新打印状态
  5054. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  5055. }
  5056. }
  5057. };
  5058. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  5059. var ids = new Array();
  5060. angular.forEach(printData, function(record, index){
  5061. angular.forEach(record['data'],function(value,index){
  5062. LODOP.NewPage();
  5063. angular.forEach(value['store'],function(data,index){
  5064. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5065. if(data['LP_VALUETYPE'] == 'barcode'){
  5066. 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']);
  5067. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5068. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5069. }else if(data['LP_VALUETYPE'] == 'text'){
  5070. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5071. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5072. }
  5073. });
  5074. });
  5075. var o = new Object();
  5076. o['id'] = record['si_id']
  5077. ids.push(o);
  5078. });
  5079. var pagesize = printData[0]['pagesize'];//获取标签的大小
  5080. var strs= new Array(); //定义一数组
  5081. strs = pagesize.split("*"); //字符分割
  5082. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5083. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5084. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5085. var times = LODOP.PREVIEW();//打印预览
  5086. if(times > 0){//点击了打印预览内的打印按钮
  5087. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5088. if(type == 'Bar'){
  5089. //更新打印状态
  5090. SaleSend.updatePrintStatus({},ids,function(data){
  5091. loadData();
  5092. },function(res){});
  5093. }
  5094. }
  5095. };
  5096. /**
  5097. * 查看条码按钮
  5098. */
  5099. $scope.showBarCode = function(number) {
  5100. $scope.keys = number;
  5101. for(var i=0;i<vm.showBarCode.length;i++){
  5102. if(i!=number){
  5103. vm.showBarCode[i] = false;
  5104. }
  5105. }
  5106. vm.showBarCode[number] = !vm.showBarCode[number];
  5107. $scope.barcodes = [];
  5108. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  5109. var getPage = function(page, size){
  5110. if($scope.barcodes) {
  5111. var result = {};
  5112. result.totalCount = $scope.barcodes.length;
  5113. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  5114. if($scope.barcodes.length % size == 0) {
  5115. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  5116. }else {
  5117. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  5118. }
  5119. result.first = page == 1;
  5120. result.last = page == result.totalPage;
  5121. result.page = page;
  5122. result.next = page - 0 + 1;
  5123. result.pre = page - 1;
  5124. return result;
  5125. }
  5126. }
  5127. $scope.barData = getPage(1,5);
  5128. $scope.first = function (){
  5129. $scope.barData = getPage($scope.barData.pre,5);
  5130. }
  5131. $scope.last = function (){
  5132. $scope.barData = getPage($scope.barData.next,5);
  5133. }
  5134. };
  5135. /**
  5136. * 更新外箱号
  5137. */
  5138. $scope.updateOutBox = function(item,number) {
  5139. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  5140. }else {
  5141. if(item.outBoxQty > 0) {
  5142. if(!(item.outBoxQty % item.packageQty)) {
  5143. SaleSend.update({id:item.id},item,function(){
  5144. toaster.pop('success', '提示','保存成功!');
  5145. loadData();
  5146. }, function(response){
  5147. $scope.loading = false;
  5148. toaster.pop('error', '回复失败', response.data);
  5149. })
  5150. }else {
  5151. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  5152. }
  5153. }else {
  5154. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5155. }
  5156. }
  5157. loadData();
  5158. };
  5159. /**
  5160. * 更新最小包数
  5161. */
  5162. $scope.updatePackage = function(item, number) {
  5163. if(item.packageQty == $scope.oldpackageQty[number]) {
  5164. }else {
  5165. if(item.orderItem.product.minPack != 0) {
  5166. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5167. if(!(item.packageQty % item.orderItem.product.minPack)) {
  5168. SaleSend.update({id:item.id},item,function(){
  5169. toaster.pop('success', '提示','保存成功!');
  5170. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5171. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5172. }
  5173. loadData();
  5174. }, function(response){
  5175. $scope.loading = false;
  5176. toaster.pop('error', '回复失败', response.data);
  5177. })
  5178. }else {
  5179. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  5180. }
  5181. }else {
  5182. toaster.pop('warning', '提示', '请填写有效的数量!');
  5183. }
  5184. }else {
  5185. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5186. SaleSend.update({id:item.id},item,function(){
  5187. toaster.pop('success', '提示','保存成功!');
  5188. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5189. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5190. }
  5191. loadData();
  5192. }, function(response){
  5193. $scope.loading = false;
  5194. toaster.pop('error', '回复失败', response.data);
  5195. })
  5196. }else {
  5197. toaster.pop('warning', '提示', '请填写有效的数量!');
  5198. }
  5199. }
  5200. }
  5201. loadData();
  5202. };
  5203. var loadData = function() {
  5204. SaleSend.get({id: $stateParams.id}, function(data){
  5205. $scope.order = data;
  5206. var orderCount = $scope.order.sendItems.length;
  5207. $scope.oldpackageQty = [];
  5208. $scope.oldoutBoxQty = [];
  5209. var sum = 0;
  5210. vm.oldpackageQty = [];
  5211. angular.forEach(data.sendItems, function(value, key){
  5212. //给showBarCode数组赋初值
  5213. if (vm.showBarCode.length < orderCount){
  5214. vm.showBarCode.push(false);
  5215. }
  5216. if($scope.checkBarCode.length < orderCount) {
  5217. $scope.checkBarCode.push(false);
  5218. }
  5219. if($scope.checkBoxCode.length < orderCount) {
  5220. $scope.checkBoxCode.push(false);
  5221. }
  5222. //给个初值
  5223. if(!value.packageQty) {
  5224. value.packageQty = value.orderItem.product.minPack;
  5225. }
  5226. $scope.oldpackageQty.push(value.packageQty);
  5227. if(value.outBoxQty) {
  5228. $scope.oldoutBoxQty.push(value.outBoxQty);
  5229. }
  5230. sum += value.price * value.qty;
  5231. });
  5232. data.total = sum;
  5233. $scope.loading = false;
  5234. }, function(response){
  5235. loading = false;
  5236. toaster.pop('error', '获取数据失败', response.data);
  5237. });
  5238. };
  5239. loadData();
  5240. }]);
  5241. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  5242. $scope.typeItem = typeItem;
  5243. $scope.template = [];
  5244. $scope.choose = {};
  5245. //获取打印模板
  5246. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  5247. if(data.message){
  5248. $scope.template = data.message;
  5249. $scope.choose.tp_id = $scope.template[0].id;
  5250. }
  5251. },function(res){
  5252. toaster.pop('error', '获取模板错误', res.data);
  5253. });
  5254. $scope.print = function(){
  5255. $scope.choose.type = 'print';
  5256. $modalInstance.close($scope.choose);
  5257. };
  5258. $scope.printPreview = function(){
  5259. $scope.choose.type = 'printPreview';
  5260. $modalInstance.close($scope.choose);
  5261. }
  5262. $scope.cancel = function(){
  5263. $modalInstance.close();
  5264. }
  5265. }]);
  5266. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  5267. var loading = true;
  5268. var loadData = function() {
  5269. PurcSample.get({id: $stateParams.id}, function(data){
  5270. $scope.sample = data;
  5271. if(!$scope.sample.send){
  5272. $scope.sample.getSendInfo = '加载中...';
  5273. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  5274. if(sendData) {
  5275. $scope.sample.getSendInfo = null;
  5276. $scope.sample.send = sendData;
  5277. } else {
  5278. $scope.sample.getSendInfo = '无送样信息';
  5279. $scope.sample.send = '无送样信息';
  5280. }
  5281. }, function(response){
  5282. $scope.sample.getSendInfo = '加载失败!';
  5283. });
  5284. }
  5285. $scope.loading = false;
  5286. }, function(response){
  5287. loading = false;
  5288. toaster.pop('error', '获取数据失败', response.data);
  5289. });
  5290. };
  5291. loadData();
  5292. }]);
  5293. /**
  5294. * 客户打样申请
  5295. */
  5296. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  5297. BaseService.scrollBackToTop();
  5298. $scope.active = 'todo';
  5299. $scope.agreedText = '全部';
  5300. $scope.dateZoneText = '一个月内';
  5301. $scope.condition = {dateZone: 1};
  5302. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5303. $scope.changeAgreed = function(agreed) {
  5304. $scope.condition.agreed = agreed;
  5305. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5306. $scope.condition.$agreedOpen = false;
  5307. };
  5308. $scope.changeDateZone = function(zone) {
  5309. $scope.condition.dateZone = zone;
  5310. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5311. $scope.condition.$dateZoneOpen = false;
  5312. };
  5313. $scope.setActive = function(state) {
  5314. if($scope.active != state) {
  5315. $scope.active = state;
  5316. if($scope.tableParams.page() == 1)
  5317. $scope.tableParams.reload();
  5318. else
  5319. $scope.tableParams.page(1);
  5320. }
  5321. };
  5322. var getService = function() {
  5323. return PurcSample;
  5324. };
  5325. $scope.tableParams = new ngTableParams({
  5326. page : 1,
  5327. count : 5,
  5328. sorting: {
  5329. proofingDate: 'desc'
  5330. }
  5331. }, {
  5332. total : 0,
  5333. counts: [5, 10, 25, 50],
  5334. getData : function($defer, params) {
  5335. $scope.loading = true;
  5336. var pageParams = params.url();
  5337. pageParams.keyword = $scope.keyword;
  5338. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5339. $scope.loading = false;
  5340. if(page) {
  5341. params.total(page.totalElement);
  5342. $defer.resolve(page.content);
  5343. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5344. }
  5345. }, function(response){
  5346. $scope.loading = false;
  5347. toaster.pop('error', '数据加载失败', response.data);
  5348. });
  5349. }
  5350. });
  5351. $scope.openDatePicker = function($event, item, openParam) {
  5352. $event.preventDefault();
  5353. $event.stopPropagation();
  5354. item[openParam] = !item[openParam];
  5355. };
  5356. $scope.openSend = function(index, sample) {
  5357. var modalInstance = $modal.open({
  5358. animation: true,
  5359. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5360. controller: 'SampleSendCtrl',
  5361. resolve: {
  5362. sampleItem: function(){return sample;}
  5363. }
  5364. });
  5365. modalInstance.result.then(function(){
  5366. toaster.pop('info', '提示', '送样成功');
  5367. $scope.tableParams.reload();
  5368. }, function(){
  5369. });
  5370. };
  5371. //打印 样品采购单
  5372. $scope.print = function(sample) {
  5373. PurcSample.printCount({id: sample.id},{});//增加打印此次
  5374. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  5375. };
  5376. $scope.getSend = function(proofing){
  5377. if( !proofing.send) {
  5378. proofing.getSendInfo = '加载中...';
  5379. PurcSample.getSend({id: proofing.id}, function(data){
  5380. if(data) {
  5381. proofing.getSendInfo = null;
  5382. proofing.send = data;
  5383. } else {
  5384. proofing.getSendInfo = '无送样信息';
  5385. proofing.send = '无送样信息';
  5386. }
  5387. }, function(response){
  5388. proofing.getSendInfo = '加载失败!';
  5389. });
  5390. }
  5391. };
  5392. // 搜索框回车
  5393. $scope.onSearch = function() {
  5394. $scope.tableParams.page(1);
  5395. $scope.tableParams.reload();
  5396. };
  5397. }]);
  5398. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  5399. $scope.sampleItem = sampleItem;
  5400. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  5401. //确认送样
  5402. $scope.ok = function (form) {
  5403. $scope.loading = true;
  5404. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  5405. $upload.upload({
  5406. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  5407. method: 'POST',
  5408. file: file,
  5409. data: {
  5410. json: $scope.sampleItem.sampleSend
  5411. }
  5412. }).success(function(data){
  5413. $scope.loading = false;
  5414. $modalInstance.close('success');
  5415. }).error(function(data){
  5416. $scope.loading = false;
  5417. toaster.pop('danger', '错误', data);
  5418. });
  5419. };
  5420. $scope.cancel = function () {
  5421. $modalInstance.dismiss(sampleItem);
  5422. };
  5423. }]);
  5424. /**
  5425. * 客户认定单
  5426. */
  5427. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  5428. BaseService.scrollBackToTop();
  5429. $scope.active = 'all';
  5430. $scope.agreedText = '全部';
  5431. $scope.dateZoneText = '一个月内';
  5432. $scope.condition = {dateZone: 1};
  5433. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5434. $scope.changeDateZone = function(zone) {
  5435. $scope.condition.dateZone = zone;
  5436. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5437. $scope.condition.$dateZoneOpen = false;
  5438. getDateCondition(zone, $scope.condition);
  5439. $scope.tableParams.reload();
  5440. };
  5441. $scope.setActive = function(state) {
  5442. if($scope.active != state) {
  5443. $scope.active = state;
  5444. if($scope.tableParams.page() == 1)
  5445. $scope.tableParams.reload();
  5446. else
  5447. $scope.tableParams.page(1);
  5448. }
  5449. };
  5450. var getService = function() {
  5451. return PurcApproval;
  5452. };
  5453. $scope.tableParams = new ngTableParams({
  5454. page : 1,
  5455. count : 5,
  5456. sorting: {
  5457. inDate: 'desc'
  5458. }
  5459. }, {
  5460. total : 0,
  5461. counts: [5, 10, 25, 50],
  5462. getData : function($defer, params) {
  5463. $scope.loading = true;
  5464. var pageParams = params.url();
  5465. pageParams.keyword = $scope.keyword;
  5466. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5467. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5468. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5469. $scope.loading = false;
  5470. if(page) {
  5471. params.total(page.totalElement);
  5472. $defer.resolve(page.content);
  5473. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5474. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5475. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5476. }
  5477. }, function(response){
  5478. $scope.loading = false;
  5479. toaster.pop('error', '数据加载失败', response.data);
  5480. });
  5481. }
  5482. });
  5483. $scope.openDatePicker = function($event, item, openParam) {
  5484. $event.preventDefault();
  5485. $event.stopPropagation();
  5486. item[openParam] = !item[openParam];
  5487. };
  5488. $scope.parseDate = function(dateStr) {
  5489. if(dateStr)
  5490. return Date.parse(dateStr, 'yyyy-MM-dd');
  5491. return new Date();
  5492. };
  5493. // 搜索框回车
  5494. $scope.onSearch = function() {
  5495. $scope.tableParams.page(1);
  5496. $scope.tableParams.reload();
  5497. };
  5498. // 选择查找日期
  5499. $scope.onDateCondition = function(){
  5500. $scope.tableParams.page(1);
  5501. $scope.tableParams.reload();
  5502. };
  5503. }]);
  5504. /**
  5505. * 客户采购预测
  5506. */
  5507. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  5508. BaseService.scrollBackToTop();
  5509. $scope.active = 'all';
  5510. $scope.agreedText = '全部';
  5511. $scope.dateZoneText = '一个月内';
  5512. $scope.condition = {dateZone: 1};
  5513. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5514. $scope.changeAgreed = function(agreed) {
  5515. $scope.condition.agreed = agreed;
  5516. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5517. $scope.condition.$agreedOpen = false;
  5518. };
  5519. $scope.changeDateZone = function(zone) {
  5520. $scope.condition.dateZone = zone;
  5521. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5522. $scope.condition.$dateZoneOpen = false;
  5523. };
  5524. $scope.setActive = function(state) {
  5525. if($scope.active != state) {
  5526. $scope.active = state;
  5527. if($scope.tableParams.page() == 1)
  5528. $scope.tableParams.reload();
  5529. else
  5530. $scope.tableParams.page(1);
  5531. }
  5532. };
  5533. var getService = function() {
  5534. return PurcForecast;
  5535. };
  5536. $scope.tableParams = new ngTableParams({
  5537. page : 1,
  5538. count : 5,
  5539. sorting: {
  5540. orderDate: 'desc'
  5541. }
  5542. }, {
  5543. total : 0,
  5544. counts: [5, 10, 25, 50],
  5545. getData : function($defer, params) {
  5546. $scope.loading = true;
  5547. var pageParams = params.url();
  5548. pageParams.keyword = $scope.keyword;
  5549. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5550. $scope.loading = false;
  5551. if(page) {
  5552. params.total(page.totalElement);
  5553. $defer.resolve(page.content);
  5554. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5555. }
  5556. }, function(response){
  5557. $scope.loading = false;
  5558. toaster.pop('error', '数据加载失败', response.data);
  5559. });
  5560. }
  5561. });
  5562. $scope.openDatePicker = function($event, item, openParam) {
  5563. $event.preventDefault();
  5564. $event.stopPropagation();
  5565. item[openParam] = !item[openParam];
  5566. };
  5567. // 搜索框回车
  5568. $scope.onSearch = function() {
  5569. $scope.tableParams.page(1);
  5570. $scope.tableParams.reload();
  5571. };
  5572. }]);
  5573. /**
  5574. * 客户采购验收
  5575. */
  5576. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  5577. BaseService.scrollBackToTop();
  5578. $scope.active = 'all';
  5579. $scope.dateZoneText = '不限';
  5580. $scope.deliveryZoneText = '不限';
  5581. $scope.condition = {dateZone: -1, deliveryZone: -1};
  5582. $scope.changeDateZone = function(zone) {
  5583. $scope.condition.dateZone = zone;
  5584. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5585. $scope.condition.$dateZoneOpen = false;
  5586. getDateCondition(zone, $scope.condition);
  5587. $scope.tableParams.reload();
  5588. };
  5589. $scope.changeDeliveryZone = function(zone) {
  5590. $scope.condition.deliveryZoneText = zone;
  5591. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  5592. $scope.condition.$delievryZoneOpen = false;
  5593. getDelveryCondition(zone, $scope.condition);
  5594. $scope.tableParams.reload();
  5595. };
  5596. $scope.setActive = function(state) {
  5597. if($scope.active != state) {
  5598. $scope.active = state;
  5599. if($scope.tableParams.page() == 1)
  5600. $scope.tableParams.reload();
  5601. else
  5602. $scope.tableParams.page(1);
  5603. }
  5604. };
  5605. var getService = function() {
  5606. return PurcAccept;
  5607. };
  5608. $scope.tableParams = new ngTableParams({
  5609. page : 1,
  5610. count : 5,
  5611. sorting: {
  5612. date: 'desc'
  5613. }
  5614. }, {
  5615. total : 0,
  5616. counts: [5, 10, 25, 50],
  5617. getData : function($defer, params) {
  5618. $scope.loading = true;
  5619. var pageParams = params.url();
  5620. pageParams.searchFilter = { // 筛选条件
  5621. keyword: $scope.keyword,
  5622. fromDate: getDateTime($scope.condition.dateFrom),
  5623. endDate: getDateTime($scope.condition.dateTo)
  5624. };
  5625. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5626. $scope.loading = false;
  5627. if(page) {
  5628. params.total(page.totalElement);
  5629. $defer.resolve(page.content);
  5630. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5631. }
  5632. }, function(response){
  5633. $scope.loading = false;
  5634. toaster.pop('error', '数据加载失败', response.data);
  5635. });
  5636. }
  5637. });
  5638. $scope.openDatePicker = function($event, item, openParam) {
  5639. $event.preventDefault();
  5640. $event.stopPropagation();
  5641. item[openParam] = !item[openParam];
  5642. };
  5643. $scope.parseDate = function(dateStr) {
  5644. if(dateStr)
  5645. return Date.parse(dateStr, 'yyyy-MM-dd');
  5646. return new Date();
  5647. };
  5648. // 选择查找日期
  5649. $scope.onDateCondition = function(){
  5650. $scope.tableParams.page(1);
  5651. $scope.tableParams.reload();
  5652. };
  5653. // 搜索框回车
  5654. $scope.onSearch = function() {
  5655. $scope.tableParams.page(1);
  5656. $scope.tableParams.reload();
  5657. };
  5658. }]);
  5659. /**
  5660. * 客户采购验退
  5661. */
  5662. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  5663. BaseService.scrollBackToTop();
  5664. $scope.active = 'all';
  5665. $scope.agreedText = '全部';
  5666. $scope.dateZoneText = '一个月内';
  5667. $scope.condition = {dateZone: 1};
  5668. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5669. $scope.changeAgreed = function(agreed) {
  5670. $scope.condition.agreed = agreed;
  5671. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5672. $scope.condition.$agreedOpen = false;
  5673. };
  5674. $scope.changeDateZone = function(zone) {
  5675. $scope.condition.dateZone = zone;
  5676. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5677. $scope.condition.$dateZoneOpen = false;
  5678. };
  5679. $scope.setActive = function(state) {
  5680. if($scope.active != state) {
  5681. $scope.active = state;
  5682. if($scope.tableParams.page() == 1)
  5683. $scope.tableParams.reload();
  5684. else
  5685. $scope.tableParams.page(1);
  5686. }
  5687. };
  5688. var getService = function() {
  5689. return PurcReturn;
  5690. };
  5691. $scope.tableParams = new ngTableParams({
  5692. page : 1,
  5693. count : 5,
  5694. sorting: {
  5695. date: 'desc'
  5696. }
  5697. }, {
  5698. total : 0,
  5699. counts: [5, 10, 25, 50],
  5700. getData : function($defer, params) {
  5701. $scope.loading = true;
  5702. var pageParams = params.url();
  5703. pageParams.keyword = $scope.keyword;
  5704. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5705. $scope.loading = false;
  5706. if(page) {
  5707. params.total(page.totalElement);
  5708. $defer.resolve(page.content);
  5709. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5710. angular.forEach(page.content, function(data) {
  5711. if (!data.returnItems[0].orderItem) {
  5712. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  5713. data.enName = enterprise.enName;
  5714. });
  5715. }
  5716. });
  5717. }
  5718. }, function(response){
  5719. $scope.loading = false;
  5720. toaster.pop('error', '数据加载失败', response.data);
  5721. });
  5722. }
  5723. });
  5724. $scope.openDatePicker = function($event, item, openParam) {
  5725. $event.preventDefault();
  5726. $event.stopPropagation();
  5727. item[openParam] = !item[openParam];
  5728. };
  5729. // 搜索框回车
  5730. $scope.onSearch = function() {
  5731. $scope.tableParams.page(1);
  5732. $scope.tableParams.reload();
  5733. };
  5734. }]);
  5735. /**
  5736. * 客户不良品入库
  5737. */
  5738. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  5739. BaseService.scrollBackToTop();
  5740. $scope.active = 'all';
  5741. $scope.agreedText = '全部';
  5742. $scope.dateZoneText = '一个月内';
  5743. $scope.condition = {dateZone: 1};
  5744. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5745. $scope.changeAgreed = function(agreed) {
  5746. $scope.condition.agreed = agreed;
  5747. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5748. $scope.condition.$agreedOpen = false;
  5749. };
  5750. $scope.changeDateZone = function(zone) {
  5751. $scope.condition.dateZone = zone;
  5752. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5753. $scope.condition.$dateZoneOpen = false;
  5754. };
  5755. $scope.setActive = function(state) {
  5756. if($scope.active != state) {
  5757. $scope.active = state;
  5758. if($scope.tableParams.page() == 1)
  5759. $scope.tableParams.reload();
  5760. else
  5761. $scope.tableParams.page(1);
  5762. }
  5763. };
  5764. var getService = function() {
  5765. return PurcBadIn;
  5766. };
  5767. $scope.tableParams = new ngTableParams({
  5768. page : 1,
  5769. count : 5,
  5770. sorting: {
  5771. date: 'desc'
  5772. }
  5773. }, {
  5774. total : 0,
  5775. counts: [5, 10, 25, 50],
  5776. getData : function($defer, params) {
  5777. $scope.loading = true;
  5778. var pageParams = params.url();
  5779. pageParams.keyword = $scope.keyword;
  5780. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5781. $scope.loading = false;
  5782. if(page) {
  5783. params.total(page.totalElement);
  5784. $defer.resolve(page.content);
  5785. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5786. }
  5787. }, function(response){
  5788. $scope.loading = false;
  5789. toaster.pop('error', '数据加载失败', response.data);
  5790. });
  5791. }
  5792. });
  5793. $scope.openDatePicker = function($event, item, openParam) {
  5794. $event.preventDefault();
  5795. $event.stopPropagation();
  5796. item[openParam] = !item[openParam];
  5797. };
  5798. // 搜索框回车
  5799. $scope.onSearch = function() {
  5800. $scope.tableParams.page(1);
  5801. $scope.tableParams.reload();
  5802. };
  5803. }]);
  5804. /**
  5805. * 客户不良品出库
  5806. */
  5807. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  5808. BaseService.scrollBackToTop();
  5809. $scope.active = 'all';
  5810. $scope.agreedText = '全部';
  5811. $scope.dateZoneText = '一个月内';
  5812. $scope.condition = {dateZone: 1};
  5813. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5814. $scope.changeAgreed = function(agreed) {
  5815. $scope.condition.agreed = agreed;
  5816. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5817. $scope.condition.$agreedOpen = false;
  5818. };
  5819. $scope.changeDateZone = function(zone) {
  5820. $scope.condition.dateZone = zone;
  5821. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5822. $scope.condition.$dateZoneOpen = false;
  5823. };
  5824. $scope.setActive = function(state) {
  5825. if($scope.active != state) {
  5826. $scope.active = state;
  5827. if($scope.tableParams.page() == 1)
  5828. $scope.tableParams.reload();
  5829. else
  5830. $scope.tableParams.page(1);
  5831. }
  5832. };
  5833. var getService = function() {
  5834. return PurcBadOut;
  5835. };
  5836. $scope.tableParams = new ngTableParams({
  5837. page : 1,
  5838. count : 5,
  5839. sorting: {
  5840. date: 'desc'
  5841. }
  5842. }, {
  5843. total : 0,
  5844. counts: [5, 10, 25, 50],
  5845. getData : function($defer, params) {
  5846. $scope.loading = true;
  5847. var pageParams = params.url();
  5848. pageParams.keyword = $scope.keyword;
  5849. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5850. $scope.loading = false;
  5851. if(page) {
  5852. params.total(page.totalElement);
  5853. $defer.resolve(page.content);
  5854. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5855. }
  5856. }, function(response){
  5857. $scope.loading = false;
  5858. toaster.pop('error', '数据加载失败', response.data);
  5859. });
  5860. }
  5861. });
  5862. $scope.openDatePicker = function($event, item, openParam) {
  5863. $event.preventDefault();
  5864. $event.stopPropagation();
  5865. item[openParam] = !item[openParam];
  5866. };
  5867. // 搜索框回车
  5868. $scope.onSearch = function() {
  5869. $scope.tableParams.page(1);
  5870. $scope.tableParams.reload();
  5871. };
  5872. }]);
  5873. /**
  5874. * 客户MRB
  5875. */
  5876. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  5877. BaseService.scrollBackToTop();
  5878. $scope.active = 'all';
  5879. $scope.agreedText = '全部';
  5880. $scope.dateZoneText = '一个月内';
  5881. $scope.condition = {dateZone: 1};
  5882. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5883. $scope.changeAgreed = function(agreed) {
  5884. $scope.condition.agreed = agreed;
  5885. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5886. $scope.condition.$agreedOpen = false;
  5887. };
  5888. $scope.changeDateZone = function(zone) {
  5889. $scope.condition.dateZone = zone;
  5890. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5891. $scope.condition.$dateZoneOpen = false;
  5892. };
  5893. $scope.setActive = function(state) {
  5894. if($scope.active != state) {
  5895. $scope.active = state;
  5896. if($scope.tableParams.page() == 1)
  5897. $scope.tableParams.reload();
  5898. else
  5899. $scope.tableParams.page(1);
  5900. }
  5901. };
  5902. var getService = function() {
  5903. return PurcMRB;
  5904. };
  5905. $scope.tableParams = new ngTableParams({
  5906. page : 1,
  5907. count : 5,
  5908. sorting: {
  5909. date: 'desc'
  5910. }
  5911. }, {
  5912. total : 0,
  5913. counts: [5, 10, 25, 50],
  5914. getData : function($defer, params) {
  5915. $scope.loading = true;
  5916. var pageParams = params.url();
  5917. pageParams.keyword = $scope.keyword;
  5918. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5919. $scope.loading = false;
  5920. if(page) {
  5921. params.total(page.totalElement);
  5922. $defer.resolve(page.content);
  5923. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5924. }
  5925. }, function(response){
  5926. $scope.loading = false;
  5927. toaster.pop('error', '数据加载失败', response.data);
  5928. });
  5929. }
  5930. });
  5931. $scope.openDatePicker = function($event, item, openParam) {
  5932. $event.preventDefault();
  5933. $event.stopPropagation();
  5934. item[openParam] = !item[openParam];
  5935. };
  5936. // 搜索框回车
  5937. $scope.onSearch = function() {
  5938. $scope.tableParams.page(1);
  5939. $scope.tableParams.reload();
  5940. };
  5941. }]);
  5942. /**
  5943. * 客户应付发票
  5944. */
  5945. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  5946. BaseService.scrollBackToTop();
  5947. $scope.active = 'all';
  5948. $scope.dateZoneText = '不限';
  5949. $scope.condition = {dateZone: -1};
  5950. $scope.changeDateZone = function(zone) {
  5951. $scope.condition.dateZone = zone;
  5952. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5953. $scope.condition.$dateZoneOpen = false;
  5954. getDateCondition(zone, $scope.condition);
  5955. $scope.tableParams.reload();
  5956. };
  5957. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5958. $scope.setActive = function(state) {
  5959. if($scope.active != state) {
  5960. $scope.active = state;
  5961. if($scope.tableParams.page() == 1)
  5962. $scope.tableParams.reload();
  5963. else
  5964. $scope.tableParams.page(1);
  5965. }
  5966. };
  5967. var getService = function() {
  5968. return FaApBill;
  5969. };
  5970. $scope.tableParams = new ngTableParams({
  5971. page : 1,
  5972. count : 5,
  5973. sorting: {
  5974. date: 'desc'
  5975. }
  5976. }, {
  5977. total : 0,
  5978. counts: [5, 10, 25, 50],
  5979. getData : function($defer, params) {
  5980. $scope.loading = true;
  5981. var pageParams = params.url();
  5982. pageParams.searchFilter = { // 筛选条件
  5983. keyword: $scope.keyword,
  5984. fromDate: getDateTime($scope.condition.dateFrom),
  5985. endDate: getDateTime($scope.condition.dateTo)
  5986. };
  5987. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5988. $scope.loading = false;
  5989. if(page) {
  5990. params.total(page.totalElement);
  5991. $defer.resolve(page.content);
  5992. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  5993. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5994. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5995. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  5996. }
  5997. }, function(response){
  5998. $scope.loading = false;
  5999. toaster.pop('error', '数据加载失败', response.data);
  6000. });
  6001. }
  6002. });
  6003. $scope.openDatePicker = function($event, item, openParam) {
  6004. $event.preventDefault();
  6005. $event.stopPropagation();
  6006. item[openParam] = !item[openParam];
  6007. };
  6008. $scope.parseDate = function(dateStr) {
  6009. if(dateStr)
  6010. return Date.parse(dateStr, 'yyyy-MM-dd');
  6011. return new Date();
  6012. };
  6013. // 搜索框回车
  6014. $scope.onSearch = function() {
  6015. $scope.tableParams.page(1);
  6016. $scope.tableParams.reload();
  6017. };
  6018. // 选择查找日期
  6019. $scope.onDateCondition = function(){
  6020. $scope.tableParams.page(1);
  6021. $scope.tableParams.reload();
  6022. };
  6023. }]);
  6024. /**
  6025. * 应付对账单
  6026. */
  6027. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  6028. BaseService.scrollBackToTop();
  6029. $scope.active = 'all';
  6030. $scope.dateZoneText = '不限';
  6031. $scope.condition = {dateZone: -1};
  6032. $scope.changeDateZone = function(zone) {
  6033. $scope.condition.dateZone = zone;
  6034. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6035. $scope.condition.$dateZoneOpen = false;
  6036. getDateCondition(zone, $scope.condition);
  6037. $scope.tableParams.reload();
  6038. };
  6039. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6040. $scope.setActive = function(state) {
  6041. if($scope.active != state) {
  6042. $scope.active = state;
  6043. if($scope.tableParams.page() == 1)
  6044. $scope.tableParams.reload();
  6045. else
  6046. $scope.tableParams.page(1);
  6047. }
  6048. };
  6049. var getService = function() {
  6050. return FaArCheck;
  6051. };
  6052. $scope.tableParams = new ngTableParams({
  6053. page : 1,
  6054. count : 5,
  6055. sorting: {
  6056. date: 'desc'
  6057. }
  6058. }, {
  6059. total : 0,
  6060. counts: [5, 10, 25, 50],
  6061. getData : function($defer, params) {
  6062. $scope.loading = true;
  6063. var pageParams = params.url();
  6064. pageParams.keyword = $scope.keyword;
  6065. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6066. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6067. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6068. $scope.loading = false;
  6069. if(page) {
  6070. params.total(page.totalElement);
  6071. $defer.resolve(page.content);
  6072. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6073. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6074. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6075. }
  6076. }, function(response){
  6077. $scope.loading = false;
  6078. toaster.pop('error', '数据加载失败', response.data);
  6079. });
  6080. }
  6081. });
  6082. $scope.openDatePicker = function($event, item, openParam) {
  6083. $event.preventDefault();
  6084. $event.stopPropagation();
  6085. item[openParam] = !item[openParam];
  6086. };
  6087. // 计算单据的商品总数
  6088. $scope.getTotalProd = function(check) {
  6089. var total = 0;
  6090. if(check.items) {
  6091. angular.forEach(check.items, function(value) {
  6092. total += value.qty;
  6093. });
  6094. }
  6095. return total;
  6096. };
  6097. // 搜索框回车
  6098. $scope.onSearch = function() {
  6099. $scope.tableParams.page(1);
  6100. $scope.tableParams.reload();
  6101. };
  6102. // 选择查找日期
  6103. $scope.onDateCondition = function(){
  6104. $scope.tableParams.page(1);
  6105. $scope.tableParams.reload();
  6106. };
  6107. }]);
  6108. // 应付对账单详情页
  6109. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  6110. BaseService.scrollBackToTop();
  6111. var loadData = function() {
  6112. FaArCheck.get({id: $stateParams.id}, function(data){
  6113. $scope.order = data;
  6114. $scope.loading = false;
  6115. });
  6116. };
  6117. loadData(); // 初始获取单据数据
  6118. $scope.onReplyClick = function(item, isAgreed) {
  6119. if(isAgreed) {// 同意确认
  6120. FaArCheck.agree({itemId: item.id}, {}, function(data){
  6121. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  6122. }, function(response){
  6123. toaster.pop('danger', '确认失败', response.data);
  6124. });
  6125. } else {// 不同意回复
  6126. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  6127. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  6128. }, function(response) {
  6129. toaster.pop('danger', '确认失败', response.data);
  6130. });
  6131. }
  6132. };
  6133. // 获取明细的回复记录
  6134. $scope.getReplies = function(item) {
  6135. if(!item.replies) {
  6136. FaArCheck.getReplies({itemId: item.id}, function(data) {
  6137. item.replies = data;
  6138. }, function(response) {
  6139. toaster.pop('danger', '获取对账记录失败', response.data);
  6140. });
  6141. }
  6142. };
  6143. }]);
  6144. //应收对账单列表
  6145. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  6146. BaseService.scrollBackToTop();
  6147. $scope.dateZoneText = '不限';
  6148. $scope.condition = {dateZone: -1};
  6149. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6150. $scope.active = 'todo';
  6151. //打印 对账单
  6152. $scope.print = function(check) {
  6153. FaApCheck.printCount({id: check.id},{});//增加打印此次
  6154. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  6155. };
  6156. //状态
  6157. $scope.setActive = function (state){
  6158. if($scope.active != state) {
  6159. $scope.active = state;
  6160. if($scope.tableParams.page() == 1)
  6161. $scope.tableParams.reload();
  6162. else
  6163. $scope.tableParams.page(1);
  6164. }
  6165. };
  6166. $scope.changeDateZone = function(zone) {
  6167. $scope.condition.dateZone = zone;
  6168. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6169. $scope.condition.$dateZoneOpen = false;
  6170. getDateCondition(zone, $scope.condition);
  6171. $scope.tableParams.reload();
  6172. };
  6173. //获取应收对账单全部
  6174. $scope.tableParams = new ngTableParams({
  6175. page : 1,
  6176. count : 5,
  6177. sorting: {
  6178. recordDate: 'desc'
  6179. }
  6180. }, {
  6181. total : 0,
  6182. counts: [5, 10, 25, 50],
  6183. getData : function($defer, params) {
  6184. $scope.loading = true;
  6185. var pageParams = params.url();
  6186. pageParams.searchFilter = { // 筛选条件
  6187. keyword: $scope.keyword,
  6188. fromDate: getDateTime($scope.condition.dateFrom),
  6189. endDate: getDateTime($scope.condition.dateTo)
  6190. };
  6191. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  6192. $scope.loading = false;
  6193. if(page) {
  6194. params.total(page.totalElement);
  6195. $scope.data = $defer.resolve(page.content);
  6196. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  6197. }
  6198. }, function(response){
  6199. $scope.loading = false;
  6200. toaster.pop('error', '数据加载失败', response.data);
  6201. });
  6202. }
  6203. });
  6204. $scope.openDatePicker = function($event, item, openParam) {
  6205. $event.preventDefault();
  6206. $event.stopPropagation();
  6207. item[openParam] = !item[openParam];
  6208. };
  6209. // 计算单据的商品总数
  6210. $scope.getTotalProd = function(check) {
  6211. var total = 0;
  6212. if(check.items) {
  6213. angular.forEach(check.items, function(value) {
  6214. total += value.checkQty;
  6215. });
  6216. }
  6217. return total;
  6218. };
  6219. // 搜索框回车
  6220. $scope.onSearch = function() {
  6221. $scope.tableParams.page(1);
  6222. $scope.tableParams.reload();
  6223. };
  6224. // 选择查找日期
  6225. $scope.onDateCondition = function(){
  6226. $scope.tableParams.page(1);
  6227. $scope.tableParams.reload();
  6228. };
  6229. }]);
  6230. //应收对账单详情
  6231. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  6232. BaseService.scrollBackToTop();
  6233. $scope.haveSelected = true;
  6234. $scope.data = {};
  6235. //控制提交和删除按钮的显示
  6236. $scope.ifShow = true;
  6237. var loadData = function(){
  6238. FaApCheck.get({id:$stateParams.id},function(data){
  6239. $scope.data = data;
  6240. if($scope.data.status){
  6241. }else{
  6242. $scope.ifShow = true;
  6243. }
  6244. })
  6245. };
  6246. if($stateParams.id){
  6247. loadData();
  6248. }
  6249. $scope.haveSource = false;
  6250. //提交应收对账单
  6251. $scope.submitApCheck = function(){
  6252. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  6253. if(data.result) {
  6254. toaster.pop('success', '提示', '提交成功');
  6255. $scope.haveSelected = false;
  6256. window.location.href = '#/fa/apCheck';
  6257. }else {
  6258. $scope.haveSource = true;
  6259. loadData();
  6260. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  6261. $scope.haveSelected = true;
  6262. }
  6263. },function(){
  6264. $scope.loading = false;
  6265. toaster.pop('error', '提示', '更新已转数失败');
  6266. });
  6267. }
  6268. //删除应收对账单的同时更新来源表已转数
  6269. var updateYCheckQty = function(){
  6270. var sourceInfos = [];
  6271. angular.forEach($scope.data.items, function(item){
  6272. $scope.sourceInfo = {
  6273. sourceId: '',
  6274. sourceTable: '',
  6275. newYCheckQty: ''
  6276. };
  6277. $scope.sourceInfo.sourceId = item.sourceId;
  6278. $scope.sourceInfo.sourceTable = item.sourceTable;
  6279. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  6280. sourceInfos.push($scope.sourceInfo);
  6281. });
  6282. FaApCheck.update({}, sourceInfos, function(){
  6283. },function(response){
  6284. $scope.loading = false;
  6285. toaster.pop('error', '更新已转数失败', response.data);
  6286. });
  6287. }
  6288. //删除应收对账单
  6289. $scope.deleteApCheck = function(){
  6290. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  6291. updateYCheckQty();
  6292. toaster.pop('success','提示','删除成功');
  6293. },function(){
  6294. toaster.pop('error','提示','删除失败');
  6295. });
  6296. $scope.haveSelected = false;
  6297. }
  6298. //作废应收对账单
  6299. $scope.cancelApCheck = function(check) {
  6300. FaApCheck.cancel({id:check.id},function(data){
  6301. $scope.checkResult = false;
  6302. if(data.result) {
  6303. $scope.checkResult = true;
  6304. toaster.pop('success', '提示', '作废成功');
  6305. $scope.tableParams.reload();
  6306. }else{
  6307. toaster.pop('error', '提示', '作废失败');
  6308. }
  6309. },function(){
  6310. $scope.loading = false;
  6311. toaster.pop('error', '提示', '作废失败');
  6312. });
  6313. }
  6314. }]);
  6315. //未对账单据列表
  6316. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  6317. $scope.data = [];// 列表数据
  6318. $scope.condition = {
  6319. $fromOpened: false
  6320. }
  6321. $scope.openDatePicker = function($event, item, openParam) {
  6322. $event.preventDefault();
  6323. $event.stopPropagation();
  6324. item[openParam] = !item[openParam];
  6325. }
  6326. //查找客户
  6327. $scope.searchCust = function(suuorname) {
  6328. var modalInstance = $modal.open({
  6329. animation: true,
  6330. templateUrl: 'static/tpl/index/fa/custInfo.html',
  6331. controller: 'SearchCustInfoCtrl',
  6332. resolve: {
  6333. suuorname: function() {
  6334. return suuorname;
  6335. }
  6336. }
  6337. });
  6338. modalInstance.result.then(function(suuorname){
  6339. $scope.suuorname = suuorname;
  6340. });
  6341. }
  6342. // 点击筛选根据条件选择数据
  6343. $scope.suuorname = '';
  6344. // 默认本月
  6345. $scope.sdateTo = new Date();
  6346. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  6347. $scope.vuuorname = '';
  6348. $scope.factory = '';
  6349. $scope.prodTitle = '';
  6350. $scope.prodSpec = '';
  6351. $scope.condition.uuorname = '';
  6352. $scope.condition.dateFrom = '';
  6353. $scope.condition.dateTo = '';
  6354. $scope.condition.venduuorname = '';
  6355. $scope.condition.factory = '';
  6356. $scope.condition.prodTitle = '';
  6357. $scope.condition.prodSpec = '';
  6358. $scope.searchOrder = function(check) {
  6359. $scope.data = [];
  6360. $scope.checkboxes.checked = false;
  6361. $scope.totalMoney = 0;
  6362. $scope.condition.uuorname = $scope.suuorname;
  6363. $scope.condition.factory = $scope.factory
  6364. $scope.condition.prodTitle = $scope.prodTitle;
  6365. $scope.condition.prodSpec = $scope.prodSpec;
  6366. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  6367. $scope.thisdatato = ($scope.sdateTo || 0);
  6368. if($scope.thisdatato != 0) {
  6369. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  6370. } else {
  6371. $scope.condition.dateTo = ($scope.sdateTo || 0);
  6372. }
  6373. $scope.condition.venduuorname = $scope.vuuorname;
  6374. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  6375. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6376. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6377. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  6378. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  6379. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  6380. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  6381. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  6382. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6383. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6384. if(!$scope.suuorname) {
  6385. toaster.pop('warning','提示', '请先选择客户');
  6386. document.getElementById('suuorname').focus();//光标默认在客户
  6387. } else {
  6388. $scope.loading = true;
  6389. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  6390. if(data.length > 0) {
  6391. angular.forEach(data, function(item) {
  6392. item.$selected = true;
  6393. });
  6394. $scope.data = data;
  6395. $scope.checkboxes.checked = true;
  6396. $scope.getTotalMoney();
  6397. } else {
  6398. toaster.pop('info', '提示', '当前没有需要对账记录');
  6399. }
  6400. $scope.loading = false;
  6401. }, function(response) {
  6402. $scope.loading = false;
  6403. toaster.pop('error', '提示', response.data);
  6404. });
  6405. }
  6406. }
  6407. }
  6408. /**
  6409. * 点击勾选框,选中要转应收对账单的订单
  6410. * */
  6411. $scope.totalMoney = 0;
  6412. $scope.checkboxes = {
  6413. checked : false
  6414. };
  6415. // 点击勾选全部的复选框
  6416. $scope.checkAll = function(){
  6417. $scope.totalMoney = 0;
  6418. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  6419. var uuorname = $scope.suuorname;
  6420. var venduuorname = $scope.venduuorname;
  6421. var dateFrom = $scope.condition.dateFrom;
  6422. var dateTo = $scope.condition.dateTo;
  6423. var prodTitle = $scope.condition.prodTitle;
  6424. var prodSpec = $scope.condition.prodSpec;
  6425. var factory = $scope.condition.factory;
  6426. angular.forEach($scope.filteredData, function(item) {
  6427. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  6428. item.$selected = $scope.checkboxes.checked;
  6429. }
  6430. });
  6431. $scope.getTotalMoney();
  6432. };
  6433. //获取已选单据总金额
  6434. var total = true;
  6435. $scope.getTotalMoney = function(){
  6436. $scope.totalMoney = 0;
  6437. angular.forEach($scope.data, function(check) {
  6438. if(check.$selected){
  6439. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6440. }else{
  6441. $scope.totalMoney += 0;
  6442. }
  6443. });
  6444. }
  6445. // 点击其中一个明细的复选框
  6446. $scope.checkOne = function(check){
  6447. var result = true;
  6448. angular.forEach($scope.data, function(item) {
  6449. if(item.$selected != true){
  6450. result = false;
  6451. return;
  6452. }
  6453. });
  6454. $scope.checkboxes.checked = result;
  6455. };
  6456. $scope.haveSelected = false;
  6457. //生成应收对账单
  6458. $scope.createApCheck = function(){
  6459. //保存应收对账单主记录字段
  6460. $scope.apCheck = {
  6461. custUu: '',
  6462. custName: '',
  6463. enUu: '',
  6464. apDate: '',
  6465. beginDate: '',
  6466. endDate: '',
  6467. checkStatus: '未对账',
  6468. checkAmount: 0,
  6469. currency: '',
  6470. rate: '',
  6471. items: []
  6472. };
  6473. //保存来源单据相关信息
  6474. var sourceInfos = [];
  6475. //所允许的本次对账最大最小数量
  6476. $scope.data.maxThisCheckQty = 0;
  6477. $scope.data.minThisCheckQty = 0;
  6478. $scope.sameCust = true;
  6479. $scope.validQty = true;
  6480. $scope.loading = true;
  6481. angular.forEach($scope.data, function(check) {
  6482. //保存应收对账单明细行数据
  6483. $scope.item = {
  6484. inoutno: '',
  6485. inoutnodetno: '',
  6486. orderCode: '',
  6487. orderClass: '',
  6488. orderDetno: '',
  6489. price: '',
  6490. checkQty: '',
  6491. amount: '',
  6492. sourceId:'',
  6493. sourceTable:'',
  6494. oldYCheckQty:'',
  6495. status: 0,
  6496. receiveCode:'',
  6497. receiveName:'',
  6498. prodCode:'',
  6499. prodTitle:'',
  6500. prodSpec:'',
  6501. taxrate: '',
  6502. sendcode: '',
  6503. whname: '',
  6504. };
  6505. //应收对账单明细行来源表信息
  6506. $scope.sourceInfo = {
  6507. sourceId: '',
  6508. sourceTable: '',
  6509. newYCheckQty: ''
  6510. };
  6511. //此次对账后新的已转数
  6512. $scope.newYCheckQty = 0;
  6513. if(check.$selected == true) {
  6514. $scope.apCheck.custName = check.custName;
  6515. $scope.apCheck.enUu = check.enUu;
  6516. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6517. $scope.apCheck.apDate = check.piDate;
  6518. $scope.apCheck.rate = check.rate;
  6519. //必须是同一家客户才能生成对账单,否则提示错误
  6520. if($scope.apCheck.custUu == ''){
  6521. $scope.apCheck.custUu = check.custUu;
  6522. }else if($scope.apCheck.custUu !== check.custUu){
  6523. $scope.sameCust = false;
  6524. $scope.loading = false;
  6525. toaster.pop('error', '请选择同一家客户');
  6526. }
  6527. //必须是相同币别才能生成对账单,否则提示错误
  6528. if($scope.apCheck.currency == ''){
  6529. $scope.apCheck.currency = check.currency;
  6530. }else if($scope.apCheck.currency !== check.currency){
  6531. $scope.sameCust = false;
  6532. $scope.loading = false;
  6533. toaster.pop('error', '请选择同一种币别');
  6534. }
  6535. //本次对账数量必须小于总对账数量
  6536. if(check.qty > 0){
  6537. $scope.data.maxThisCheckQty = check.qty;
  6538. $scope.data.minThisCheckQty = 0;
  6539. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  6540. $scope.validQty = false;
  6541. $scope.loading = false;
  6542. toaster.pop('error','本次对账数量,填写有误!');
  6543. }
  6544. }else if(check.qty < 0){
  6545. $scope.data.maxThisCheckQty = 0;
  6546. $scope.data.minThisCheckQty = check.qty;
  6547. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  6548. $scope.validQty = false;
  6549. $scope.loading = false;
  6550. toaster.pop('error','本次对账数量,填写有误!');
  6551. }
  6552. }
  6553. //获取最小时间作为对账区间的起始时间
  6554. if($scope.apCheck.beginDate == ''){
  6555. $scope.apCheck.beginDate = check.piDate;
  6556. }else{
  6557. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  6558. }
  6559. //获取最大时间作为对账区间的截止时间
  6560. if($scope.apCheck.endDate == ''){
  6561. $scope.apCheck.endDate = check.piDate;
  6562. }else{
  6563. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  6564. }
  6565. //应收对账单明细行数据
  6566. $scope.item.orderCode = check.orderCode;
  6567. $scope.item.orderClass = check.piClass;
  6568. $scope.item.orderDetno = check.orderDetno;
  6569. $scope.item.price = check.orderPrice;
  6570. $scope.item.checkQty = check.thisCheckQty;
  6571. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6572. $scope.item.sourceId = check.sourceId;
  6573. $scope.item.sourceTable = check.sourceTable;
  6574. $scope.item.oldYCheckQty = check.yCheckQty;
  6575. $scope.item.prodCode = check.prodCode;
  6576. $scope.item.prodTitle = check.prodTitle;
  6577. $scope.item.prodSpec = check.prodSpec;
  6578. $scope.item.inoutno = check.inOutNo;
  6579. $scope.item.inoutnodetno = check.detno;
  6580. $scope.item.taxrate = check.taxrate;
  6581. $scope.item.receiveCode = check.receiveCode;
  6582. $scope.item.receiveName = check.receiveName;
  6583. $scope.item.sendcode = check.sendcode;
  6584. $scope.item.whname = check.whname;
  6585. //来源表相关信息
  6586. $scope.sourceInfo.sourceId = check.sourceId;
  6587. $scope.sourceInfo.sourceTable = check.sourceTable;
  6588. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  6589. sourceInfos.push($scope.sourceInfo);
  6590. $scope.apCheck.items.push($scope.item);
  6591. $scope.haveSelected = true;
  6592. }
  6593. });
  6594. //保存生成的应收对账单
  6595. $scope.saveApCheck = function(){
  6596. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  6597. $scope.loading = false;
  6598. toaster.pop('success', '成功', '生成应收对账成功');
  6599. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  6600. }, function(response){
  6601. toaster.pop('error', '生成对账单失败', response.data);
  6602. })
  6603. };
  6604. //如果是同一家客户,生成对账单的同时,关闭模态框
  6605. if($scope.sameCust && $scope.validQty) {
  6606. $scope.saveApCheck();
  6607. }
  6608. }
  6609. }]);
  6610. //货款调账
  6611. app.controller('PurchaseAdjustListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', 'ApbillAdjustment', function($scope, FaApCheck, toaster, $state, $filter, $modal, ApbillAdjustment){
  6612. $scope.data = [];// 列表数据
  6613. $scope.condition = {
  6614. $fromOpened: false
  6615. }
  6616. $scope.openDatePicker = function($event, item, openParam) {
  6617. $event.preventDefault();
  6618. $event.stopPropagation();
  6619. item[openParam] = !item[openParam];
  6620. }
  6621. //查找客户
  6622. $scope.searchCust = function(suuorname) {
  6623. var modalInstance = $modal.open({
  6624. animation: true,
  6625. templateUrl: 'static/tpl/index/fa/custInfo.html',
  6626. controller: 'SearchCustInfoCtrl',
  6627. resolve: {
  6628. suuorname: function() {
  6629. return suuorname;
  6630. }
  6631. }
  6632. });
  6633. modalInstance.result.then(function(suuorname){
  6634. $scope.suuorname = suuorname;
  6635. });
  6636. }
  6637. // 点击筛选根据条件选择数据
  6638. $scope.suuorname = '';
  6639. // 默认本月
  6640. $scope.sdateTo = new Date();
  6641. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  6642. $scope.vuuorname = '';
  6643. $scope.factory = '';
  6644. $scope.prodTitle = '';
  6645. $scope.prodSpec = '';
  6646. $scope.condition.uuorname = '';
  6647. $scope.condition.dateFrom = '';
  6648. $scope.condition.dateTo = '';
  6649. $scope.condition.venduuorname = '';
  6650. $scope.condition.factory = '';
  6651. $scope.condition.prodTitle = '';
  6652. $scope.condition.prodSpec = '';
  6653. $scope.searchOrder = function(check) {
  6654. $scope.data = [];
  6655. $scope.checkboxes.checked = false;
  6656. $scope.totalMoney = 0;
  6657. $scope.condition.uuorname = $scope.suuorname;
  6658. $scope.condition.factory = $scope.factory
  6659. $scope.condition.prodTitle = $scope.prodTitle;
  6660. $scope.condition.prodSpec = $scope.prodSpec;
  6661. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  6662. $scope.thisdatato = ($scope.sdateTo || 0);
  6663. if($scope.thisdatato != 0) {
  6664. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  6665. } else {
  6666. $scope.condition.dateTo = ($scope.sdateTo || 0);
  6667. }
  6668. $scope.condition.venduuorname = $scope.vuuorname;
  6669. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  6670. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6671. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6672. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  6673. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  6674. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  6675. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  6676. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  6677. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6678. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6679. if(!$scope.suuorname) {
  6680. toaster.pop('warning','提示', '请先选择客户');
  6681. document.getElementById('suuorname').focus();//光标默认在客户
  6682. } else {
  6683. $scope.loading = true;
  6684. ApbillAdjustment.adjustList({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  6685. if(data.length > 0) {
  6686. angular.forEach(data, function(item) {
  6687. item.$selected = true;
  6688. });
  6689. $scope.data = data;
  6690. $scope.checkboxes.checked = true;
  6691. $scope.getTotalMoney();
  6692. } else {
  6693. toaster.pop('info', '提示', '当前没有需要对账记录');
  6694. }
  6695. $scope.loading = false;
  6696. }, function(response) {
  6697. $scope.loading = false;
  6698. toaster.pop('error', '提示', response.data);
  6699. });
  6700. }
  6701. }
  6702. }
  6703. /**
  6704. * 点击勾选框,选中要转应收对账单的订单
  6705. * */
  6706. $scope.totalMoney = 0;
  6707. $scope.checkboxes = {
  6708. checked : false
  6709. };
  6710. // 点击勾选全部的复选框
  6711. $scope.checkAll = function(){
  6712. $scope.totalMoney = 0;
  6713. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  6714. var uuorname = $scope.suuorname;
  6715. var venduuorname = $scope.venduuorname;
  6716. var dateFrom = $scope.condition.dateFrom;
  6717. var dateTo = $scope.condition.dateTo;
  6718. var prodTitle = $scope.condition.prodTitle;
  6719. var prodSpec = $scope.condition.prodSpec;
  6720. var factory = $scope.condition.factory;
  6721. angular.forEach($scope.filteredData, function(item) {
  6722. if((item.orderdate >= dateFrom || dateFrom == '') && (item.orderdate < dateTo || dateTo == '')){
  6723. item.$selected = $scope.checkboxes.checked;
  6724. }
  6725. });
  6726. $scope.getTotalMoney();
  6727. };
  6728. //获取已选单据总金额
  6729. var total = true;
  6730. $scope.getTotalMoney = function(){
  6731. $scope.totalMoney = 0;
  6732. angular.forEach($scope.data, function(check) {
  6733. if(check.$selected){
  6734. $scope.totalMoney += (check.thischeckqty || 0)*(check.orderprice || 0);
  6735. }else{
  6736. $scope.totalMoney += 0;
  6737. }
  6738. });
  6739. }
  6740. // 点击其中一个明细的复选框
  6741. $scope.checkOne = function(check){
  6742. var result = true;
  6743. angular.forEach($scope.data, function(item) {
  6744. if(item.$selected != true){
  6745. result = false;
  6746. return;
  6747. }
  6748. });
  6749. $scope.checkboxes.checked = result;
  6750. };
  6751. $scope.haveSelected = false;
  6752. //生成应收对账单
  6753. $scope.createApCheck = function(){
  6754. //保存应收对账单主记录字段
  6755. $scope.apCheck = {
  6756. custUu: '',
  6757. custName: '',
  6758. enUu: '',
  6759. apDate: '',
  6760. beginDate: '',
  6761. endDate: '',
  6762. checkStatus: '未对账',
  6763. checkAmount: 0,
  6764. currency: '',
  6765. rate: '',
  6766. items: []
  6767. };
  6768. //保存来源单据相关信息
  6769. var sourceInfos = [];
  6770. //所允许的本次对账最大最小数量
  6771. $scope.data.maxThisCheckQty = 0;
  6772. $scope.data.minThisCheckQty = 0;
  6773. $scope.sameCust = true;
  6774. $scope.validQty = true;
  6775. $scope.loading = true;
  6776. angular.forEach($scope.data, function(check) {
  6777. //保存应收对账单明细行数据
  6778. $scope.item = {
  6779. inoutno: '',
  6780. inoutnodetno: '',
  6781. orderCode: '',
  6782. orderClass: '',
  6783. orderDetno: '',
  6784. price: '',
  6785. checkQty: '',
  6786. amount: '',
  6787. sourceId:'',
  6788. sourceTable:'',
  6789. oldYCheckQty:'',
  6790. status: 0,
  6791. receiveCode:'',
  6792. receiveName:'',
  6793. prodCode:'',
  6794. prodTitle:'',
  6795. prodSpec:'',
  6796. taxrate: '',
  6797. sendcode: '',
  6798. whname: '',
  6799. };
  6800. //应收对账单明细行来源表信息
  6801. $scope.sourceInfo = {
  6802. sourceId: '',
  6803. sourceTable: '',
  6804. newYCheckQty: ''
  6805. };
  6806. //此次对账后新的已转数
  6807. $scope.newYCheckQty = 0;
  6808. if(check.$selected == true) {
  6809. $scope.apCheck.custName = check.custname;
  6810. $scope.apCheck.enUu = check.enuu;
  6811. $scope.apCheck.checkAmount += (check.thischeckqty || 0)*(check.orderprice || 0);
  6812. $scope.apCheck.apDate = check.date;
  6813. $scope.apCheck.rate = check.rate;
  6814. //必须是同一家客户才能生成对账单,否则提示错误
  6815. if($scope.apCheck.custUu == ''){
  6816. $scope.apCheck.custUu = check.custuu;
  6817. }else if($scope.apCheck.custUu !== check.custuu){
  6818. $scope.sameCust = false;
  6819. $scope.loading = false;
  6820. toaster.pop('error', '请选择同一家客户');
  6821. }
  6822. //必须是相同币别才能生成对账单,否则提示错误
  6823. if($scope.apCheck.currency == ''){
  6824. $scope.apCheck.currency = check.currency;
  6825. }else if($scope.apCheck.currency !== check.currency){
  6826. $scope.sameCust = false;
  6827. $scope.loading = false;
  6828. toaster.pop('error', '请选择同一种币别');
  6829. }
  6830. //本次对账数量必须小于总对账数量
  6831. if(check.qty > 0){
  6832. $scope.data.maxThisCheckQty = check.qty;
  6833. $scope.data.minThisCheckQty = 0;
  6834. if(check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0){
  6835. $scope.validQty = false;
  6836. $scope.loading = false;
  6837. toaster.pop('error','本次对账数量,填写有误!');
  6838. }
  6839. }else if(check.qty < 0){
  6840. $scope.data.maxThisCheckQty = 0;
  6841. $scope.data.minThisCheckQty = check.qty;
  6842. if(((-check.qty)-(-check.ycheckQty) < (-check.thischeckQty)) || check.thischeckqty > 0 || check.thischeckqty == 0){
  6843. $scope.validQty = false;
  6844. $scope.loading = false;
  6845. toaster.pop('error','本次对账数量,填写有误!');
  6846. }
  6847. }
  6848. //获取最小时间作为对账区间的起始时间
  6849. if($scope.apCheck.beginDate == ''){
  6850. $scope.apCheck.beginDate = check.date;
  6851. }else{
  6852. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.orderdate : $scope.apCheck.beginDate;
  6853. }
  6854. //获取最大时间作为对账区间的截止时间
  6855. if($scope.apCheck.endDate == ''){
  6856. $scope.apCheck.endDate = check.date;
  6857. }else{
  6858. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.orderdate : $scope.apCheck.endDate;
  6859. }
  6860. //应收对账单明细行数据
  6861. $scope.item.orderCode = check.ordercode;
  6862. $scope.item.orderClass = check.piClass;
  6863. $scope.item.orderDetno = check.orderdetno;
  6864. $scope.item.price = check.orderprice;
  6865. $scope.item.checkQty = check.thischeckqty;
  6866. $scope.item.amount = (check.thischeckqty || 0)*(check.orderprice || 0);
  6867. $scope.item.sourceId = check.id;
  6868. $scope.item.sourceTable = 'purc$apbilladjustment';
  6869. $scope.item.orderClass = '货款调账';
  6870. $scope.item.oldYCheckQty = check.ycheckqty;
  6871. $scope.item.prodCode = check.prodcode;
  6872. $scope.item.prodTitle = check.prodtitle;
  6873. $scope.item.prodSpec = check.prodspec;
  6874. $scope.item.inoutno = check.inoutno;
  6875. $scope.item.inoutnodetno = check.detno;
  6876. $scope.item.taxrate = check.taxrate;
  6877. $scope.item.receiveCode = check.receivecode;
  6878. $scope.item.receiveName = check.receivename;
  6879. $scope.item.sendcode = check.sendcode;
  6880. $scope.item.whname = check.whname;
  6881. //来源表相关信息
  6882. $scope.sourceInfo.sourceId = check.id;
  6883. $scope.sourceInfo.sourceTable = 'purc$apbilladjustment';
  6884. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  6885. sourceInfos.push($scope.sourceInfo);
  6886. $scope.apCheck.items.push($scope.item);
  6887. $scope.haveSelected = true;
  6888. }
  6889. });
  6890. //保存生成的应收对账单
  6891. $scope.saveApCheck = function(){
  6892. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  6893. $scope.loading = false;
  6894. toaster.pop('success', '成功', '生成应收对账成功');
  6895. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  6896. }, function(response){
  6897. toaster.pop('error', '生成对账单失败', response.data);
  6898. })
  6899. };
  6900. //如果是同一家客户,生成对账单的同时,关闭模态框
  6901. if($scope.sameCust && $scope.validQty) {
  6902. $scope.saveApCheck();
  6903. }
  6904. }
  6905. }]);
  6906. // 企业信息设置
  6907. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder){
  6908. BaseService.scrollBackToTop();
  6909. $scope.loading = true;
  6910. AccountEnterprise.get({}, function(data){
  6911. $scope.loading = false;
  6912. $scope.enterprise = data;
  6913. // 获取付款企业信息
  6914. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  6915. $scope.pays = data;
  6916. }, function(response) {
  6917. toaster.pop('error', '提示', response.data);
  6918. });
  6919. });
  6920. AccountEnterprise.growth({}, function(data){
  6921. if(data != null && data.length > 0) {
  6922. var growth = [], years = [];
  6923. angular.forEach(data, function(d){
  6924. var date = new Date(d.date), year = date.getFullYear();
  6925. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  6926. if(years.indexOf(year) == -1) {
  6927. years.push(year);
  6928. growth.push({year: year});
  6929. }
  6930. growth.push(d);
  6931. });
  6932. $scope.growth = growth;
  6933. }
  6934. });
  6935. // 更新企业信息
  6936. $scope.updateDetailInfo = function(){
  6937. $scope.loading = true;
  6938. AccountEnterprise.save($scope.enterprise, function(){
  6939. $scope.loading = false;
  6940. $scope.connectionEditing = false;
  6941. toaster.pop('success', '提示', '修改企业信息成功');
  6942. $state.reload();
  6943. }, function(response){
  6944. $scope.loading = false;
  6945. toaster.pop('error', '修改信息失败', response.data);
  6946. });
  6947. };
  6948. // 申请Saas
  6949. $scope.applySaas = function(){
  6950. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  6951. var modalInstance = $modal.open({
  6952. animation: true,
  6953. templateUrl: 'static/tpl/index/account/applySaas.html',
  6954. controller: 'ApplySaasCtrl',
  6955. resolve: {
  6956. enterprise: function(){return angular.copy($scope.enterprise);}
  6957. }
  6958. });
  6959. modalInstance.result.then(function(){
  6960. $state.reload();
  6961. }, function(){
  6962. });
  6963. } else {
  6964. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  6965. }
  6966. };
  6967. // 获取收货地址列表
  6968. ShipAddress.shipAddList({}, function(data) {
  6969. $scope.ships = data;
  6970. });
  6971. // 判断是否是代采企业
  6972. DeputyOrder.isDeputyEnterprise({}, function(data) {
  6973. $scope.deputyEnter = data;
  6974. });
  6975. // 获取地址信息
  6976. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  6977. }).then(function(response) {
  6978. $scope.provinces = response.data;
  6979. });
  6980. // 新增收货地址保存
  6981. $scope.saveShipAddress = function(ship) {
  6982. ship.address = ship.province + ship.city + ship.district;
  6983. ShipAddress.saveAddress( {}, ship, function(data) {
  6984. if(data.success) {
  6985. ShipAddress.shipAddList({}, function(data) {
  6986. $scope.ships = data;
  6987. });
  6988. toaster.pop('success', '提示', data.success);
  6989. }
  6990. if(data.error) {
  6991. toaster.pop('error', '提示', data.error);
  6992. }
  6993. });
  6994. }
  6995. // 删除收货地址
  6996. $scope.removeShip = function(id, index) {
  6997. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  6998. $scope.ships.splice(index, 1);
  6999. toaster.pop('success', '提示', '收货地址删除成功');
  7000. }, function(response) {
  7001. toaster.pop('error', '提示', response.data);
  7002. });
  7003. };
  7004. // 编辑收货地址
  7005. $scope.editShip = function(ship){
  7006. var modalInstance = $modal.open({
  7007. animation: true,
  7008. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  7009. controller: 'ShipAddressCtrl',
  7010. resolve: {
  7011. ship: function(){return ship;}
  7012. }
  7013. });
  7014. modalInstance.result.then(function() {
  7015. ShipAddress.shipAddList({}, function(data) {
  7016. $scope.ships = data;
  7017. });
  7018. }, function(){
  7019. });
  7020. };
  7021. // 新增付款企业
  7022. $scope.addPayCompany = function() {
  7023. var modalInstance = $modal.open({
  7024. animation: true,
  7025. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7026. controller: 'PayCompanyCtrl',
  7027. resolve: {
  7028. pay: function(){return null;}
  7029. }
  7030. });
  7031. modalInstance.result.then(function() {
  7032. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7033. $scope.pays = data;
  7034. // 获取付款企业信息
  7035. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7036. $scope.pays = data;
  7037. }, function(response) {
  7038. toaster.pop('error', '提示', response.data);
  7039. });
  7040. }, function(response) {
  7041. toaster.pop('error', '提示', response.data);
  7042. });
  7043. }, function(){
  7044. });
  7045. }
  7046. // 删除付款企业
  7047. $scope.removePay = function(id, index) {
  7048. DeputyOrder.removePayCompany({id: id}, {}, function(data) {
  7049. $scope.pays.splice(index, 1);
  7050. toaster.pop('success', '提示', '付款企业信息删除成功');
  7051. }, function(response) {
  7052. toaster.pop('error', '提示', response.data);
  7053. });
  7054. };
  7055. // 编辑付款企业
  7056. $scope.editPay = function(pay, uu) {
  7057. var modalInstance = $modal.open({
  7058. animation: true,
  7059. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7060. controller: 'PayCompanyCtrl',
  7061. resolve: {
  7062. pay: function(){return pay;}
  7063. }
  7064. });
  7065. modalInstance.result.then(function() {
  7066. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7067. $scope.pays = data;
  7068. }, function(response) {
  7069. toaster.pop('error', '提示', response.data);
  7070. });
  7071. }, function(){
  7072. });
  7073. };
  7074. // 设置logo
  7075. $scope.showImageDialog = function(modal) {
  7076. require([ 'jquery-uploadify' ], function() {
  7077. $modal.open({
  7078. templateUrl : 'static/tpl/index/home/insert.html',
  7079. controller : 'ImageInsertCtrl',
  7080. backdrop : 'static'
  7081. }).result.then(function(image){
  7082. $scope.imageUrl = image.thumb;
  7083. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  7084. $scope.user = data;
  7085. }, function(response) {
  7086. toaster.pop('error', '设置图像失败,' + response.data);
  7087. });
  7088. });
  7089. });
  7090. }
  7091. }]);
  7092. // 编辑收货地址
  7093. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  7094. $scope.ship = ship;
  7095. // 获取地址信息
  7096. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7097. }).then(function(response) {
  7098. $scope.provinces = response.data;
  7099. });
  7100. // 新增收货地址保存
  7101. $scope.saveShipAddress = function(ship) {
  7102. ship.address = ship.province + ship.city + ship.district;
  7103. ShipAddress.saveAddress( {}, ship, function(data) {
  7104. if(data.success) {
  7105. toaster.pop('success', '提示', data.success);
  7106. $modalInstance.close();
  7107. }
  7108. if(data.error) {
  7109. toaster.pop('error', '提示', data.error);
  7110. }
  7111. });
  7112. }
  7113. $scope.cancel = function() {
  7114. $modalInstance.dismiss();
  7115. }
  7116. }]);
  7117. // 编辑付款企业信息
  7118. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  7119. $scope.pay = pay;
  7120. // 获取地址信息
  7121. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7122. }).then(function(response) {
  7123. $scope.provinces = response.data;
  7124. });
  7125. // 新增收货地址保存
  7126. $scope.savePayCompany = function(pay) {
  7127. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  7128. DeputyOrder.savePaycompany( {}, pay, function(data) {
  7129. toaster.pop('success', '提示', '保存成功');
  7130. $modalInstance.dismiss();
  7131. }, function(response) {
  7132. toaster.pop('error', '提示', response.data);
  7133. });
  7134. }
  7135. $scope.cancel = function() {
  7136. $modalInstance.dismiss();
  7137. }
  7138. }]);
  7139. // 申请Saas Controller
  7140. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  7141. $scope.enterprise = enterprise;
  7142. $scope.checking = false;
  7143. $scope.$watch('enterprise.enSaasUrl', function(){
  7144. if($scope.enterprise.enSaasUrl) {
  7145. $http.get('signup/saasUrlEnable', {
  7146. params: {
  7147. enSaasUrl: $scope.enterprise.enSaasUrl
  7148. }
  7149. }).success(function(data){
  7150. if(data && data == 'true') {
  7151. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  7152. } else {
  7153. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7154. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  7155. }
  7156. }).error(function(){
  7157. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7158. $scope.enSaasUrlErrorInfo = '验证出错';
  7159. });
  7160. } else {
  7161. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7162. }
  7163. });
  7164. var setSaasUrl = function(url) {
  7165. var index = url.indexOf('www.');
  7166. if(index != -1) {//包含www.
  7167. var substr = url.substring(index+4, url.length);
  7168. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  7169. } else {
  7170. $scope.enterprise.enSaasUrl = getHost(url);
  7171. }
  7172. };
  7173. // 解析获取网址的一级域名
  7174. var getHost = function(host){
  7175. var newhost;
  7176. var domain;
  7177. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  7178. for(var k in ArrDomain){
  7179. var re = eval('/\\' + ArrDomain[k] + '$/g');
  7180. newhost = host.replace(re, '');
  7181. if(newhost != host){
  7182. domain = ArrDomain[k];
  7183. break;
  7184. }
  7185. }
  7186. var hostar = newhost.split('.');
  7187. var s = hostar[hostar.length-1];
  7188. return s;
  7189. };
  7190. // 设置优企云服域名为官网网址一级域名
  7191. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  7192. $scope.apply = function(){
  7193. $scope.loading = true;
  7194. AccountEnterprise.applySaas({
  7195. enUU: $scope.enterprise.uu,
  7196. enSaasUrl: $scope.enterprise.enSaasUrl,
  7197. enAdminPassword: $scope.enterprise.enAdminPassword
  7198. }, {}, function(){
  7199. $scope.loading = false;
  7200. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  7201. $modalInstance.close();
  7202. }, function(response){
  7203. $scope.loading = false;
  7204. toaster.pop('error', '申请失败', response.data);
  7205. });
  7206. };
  7207. $scope.cancel = function () {
  7208. $modalInstance.dismiss();
  7209. };
  7210. }]);
  7211. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', 'AccountEnterprise', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert, AccountEnterprise){
  7212. BaseService.scrollBackToTop();
  7213. $scope.editing = false;
  7214. $scope.loading = true;
  7215. $scope.enterprise = null;
  7216. AccountUser.findDistribute({},function(data) {
  7217. $scope.distributes = data;
  7218. },function(response) {
  7219. toaster.pop('error', '系统错误', response.data);
  7220. });
  7221. AuthenticationService.getAuthentication().success(function(data) {
  7222. $scope.loading = false;
  7223. $scope.user = data;
  7224. });
  7225. var users = [];
  7226. $scope.tableParams = new ngTableParams({
  7227. page : 1,
  7228. count : 5,
  7229. sorting: {
  7230. userName: 'asc'
  7231. }
  7232. }, {
  7233. total : 0,
  7234. counts: [15, 25, 50, 100],
  7235. getData : function($defer, params) {
  7236. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  7237. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  7238. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  7239. angular.forEach($scope.users,function(user){
  7240. AccountEnterprise.get({}, function(data){
  7241. $scope.loading = false;
  7242. $scope.enterprise = data;
  7243. });
  7244. });
  7245. params.total(orderedData.length);
  7246. $defer.resolve($scope.users);
  7247. }
  7248. });
  7249. var loadUsers = function() {
  7250. AccountUser.query({}, function(data){
  7251. users = data;
  7252. angular.forEach(users, function(user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  7253. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  7254. $scope.user.userIdcode = user.userIdcode;
  7255. }
  7256. });
  7257. $scope.tableParams.reload();
  7258. $scope.loading = false;
  7259. });
  7260. };
  7261. loadUsers();
  7262. $scope.saveUser = function(){
  7263. $scope.loading = true;
  7264. AccountUser.update({}, $scope.user, function(data){
  7265. $scope.loading = false;
  7266. toaster.pop('success', '提示', '修改用户信息成功');
  7267. AuthenticationService.getAuthentication().success(function(data) {
  7268. $scope.user = data;
  7269. });
  7270. loadUsers();
  7271. $scope.editing = false;
  7272. }, function(reponse){
  7273. $scope.loading = false;
  7274. toaster.pop('error', '失败', reponse.data);
  7275. });
  7276. };
  7277. $scope.updatePassword = function(){
  7278. var modalInstance = $modal.open({
  7279. animation: true,
  7280. templateUrl: 'updatePassword.html',
  7281. controller: 'PasswordCtrl',
  7282. resolve: {
  7283. user: function(){return $scope.user;}
  7284. }
  7285. });
  7286. modalInstance.result.then(function(){
  7287. }, function(){
  7288. });
  7289. };
  7290. $scope.newUser = {};
  7291. //弹出添加用户模态框
  7292. $scope.addExistUser = function(){
  7293. var modalInstance = $modal.open({
  7294. animation :true,
  7295. templateUrl : 'static/tpl/index/account/addExistUser.html',
  7296. controller : 'AddExistUserCtrl'
  7297. });
  7298. modalInstance.result.then(function(){
  7299. $scope.userTelSuccess = false;
  7300. $scope.userTelError = false;
  7301. loadUsers();
  7302. }, function(){
  7303. });
  7304. };
  7305. /**
  7306. * 添加未注册用户
  7307. */
  7308. $scope.addUser = function() {
  7309. $scope.adding = true;
  7310. AccountUser.save({}, $scope.newUser, function(){
  7311. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  7312. $scope.newUser = {userSex: 'M'};
  7313. loadUsers();
  7314. $scope.adding = false;
  7315. $scope.newUserForm.newUserTel.$setValidity('available', false);
  7316. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  7317. $scope.userTelSuccess = false;
  7318. $scope.userTelError = false;
  7319. $scope.userEmailSuccess = false;
  7320. $scope.userEmailError = false;
  7321. }, function(response){
  7322. toaster.pop('error', '错误', response.data);
  7323. });
  7324. };
  7325. /**
  7326. * 验证手机号是否可用
  7327. */
  7328. $scope.telValid = function(tel) {
  7329. if(tel) {
  7330. $http.get('account/user/telEnable', {
  7331. params: {
  7332. tel: tel
  7333. }
  7334. }).success(function(data){
  7335. data = eval(data);
  7336. if(data == true) {
  7337. $scope.newUserForm.newUserTel.$setValidity('available', true);
  7338. $scope.userTelSuccess = true;
  7339. $scope.userTelError = false;
  7340. }else{
  7341. $scope.newUserForm.newUserTel.$setValidity('available', false);
  7342. $scope.userTelError = true;
  7343. $scope.userTelSuccess = false;
  7344. if(tel.length == 11)
  7345. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  7346. }
  7347. }).error(function(){
  7348. $scope.userTelSuccess = false;
  7349. $scope.userTelError = true;
  7350. });
  7351. } else {
  7352. $scope.userTelSuccess = false;
  7353. $scope.userTelError = false;
  7354. }
  7355. };
  7356. /**
  7357. * 验证邮箱是否可用
  7358. */
  7359. $scope.emailValid = function(email) {
  7360. if(email) {
  7361. $http.get('account/user/emailEnable', {
  7362. params: {
  7363. email: email
  7364. }
  7365. }).success(function(data){
  7366. data = eval(data);
  7367. if(data == true) {
  7368. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  7369. $scope.userEmailSuccess = true;
  7370. $scope.userEmailError = false;
  7371. } else {
  7372. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  7373. $scope.userEmailError = true;
  7374. $scope.userEmailSuccess = false;
  7375. }
  7376. }).error(function(){
  7377. $scope.userEmailError = true;
  7378. $scope.userEmailSuccess = false;
  7379. });
  7380. } else {
  7381. $scope.userEmailError = false;
  7382. $scope.userEmailSuccess = false;
  7383. }
  7384. };
  7385. /**
  7386. * 删除用户
  7387. */
  7388. $scope.removeUser = function(user) {
  7389. new ngAlert({
  7390. title: '提示',
  7391. content: '确定删除用户(' + user.userName + ')吗?'
  7392. }, function(){
  7393. AccountUser.remove({uu: user.userUU}, function(){
  7394. toaster.pop('success', '提示', '用户删除成功。');
  7395. loadUsers();
  7396. }, function(response){
  7397. toaster.pop('error', '删除失败', response.data);
  7398. });
  7399. });
  7400. };
  7401. // 编辑用户的角色
  7402. $scope.editUserRole = function(user) {
  7403. var modalInstance = $modal.open({
  7404. animation: true,
  7405. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  7406. controller: 'UserRoleCtrl',
  7407. resolve: {
  7408. user: function() {
  7409. return user;
  7410. }
  7411. }
  7412. });
  7413. modalInstance.result.then(function(changed, checked){
  7414. if(changed) {
  7415. if(checked)
  7416. $scope.newUser.roles = checked;
  7417. else
  7418. loadUsers();
  7419. }
  7420. });
  7421. };
  7422. // 为用户分配角色(删除企业)
  7423. $scope.removeVendor = function(user) {
  7424. var resultRole = true;
  7425. angular.forEach(user.roles,function(role){
  7426. if(role.issys == 1) {
  7427. toaster.pop('error', '提示', '管理员无需分配客户');
  7428. resultRole = false;
  7429. return;
  7430. }
  7431. })
  7432. if(resultRole) {
  7433. var modalInstance = $modal.open({
  7434. animation: true,
  7435. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  7436. controller: 'RemoveVendorCtrl',
  7437. resolve: {
  7438. user: function() {
  7439. return user;
  7440. }
  7441. }
  7442. });
  7443. }
  7444. }
  7445. // 为用户分配角色(添加企业)
  7446. $scope.addVendor = function(user,isIssy) {
  7447. if(!isIssy) {
  7448. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  7449. return;
  7450. }
  7451. var resultRole = true;
  7452. angular.forEach(user.roles,function(role){
  7453. if(role.issys == 1) {
  7454. toaster.pop('error', '提示', '管理员无需分配客户');
  7455. resultRole = false;
  7456. return;
  7457. }
  7458. })
  7459. if(resultRole) {
  7460. var modalInstance = $modal.open({
  7461. animation: true,
  7462. templateUrl: 'static/tpl/index/account/add_vendor.html',
  7463. controller: 'AddVendorCtrl',
  7464. resolve: {
  7465. user: function() {
  7466. return user;
  7467. }
  7468. }
  7469. });
  7470. modalInstance.result.then(function(changed, checked){
  7471. if(changed) {
  7472. if(checked)
  7473. $scope.newUser.roles = checked;
  7474. else
  7475. loadUsers();
  7476. }
  7477. });
  7478. }
  7479. };
  7480. }]);
  7481. // 登录手机号码验证
  7482. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  7483. $scope.user = user;
  7484. $scope.cancel = function(){
  7485. $modalInstance.close();
  7486. }
  7487. /*$scope.loading = false;
  7488. $scope.btnState = false;
  7489. $scope.clicks = 0;
  7490. var storage = window.localStorage;
  7491. //手机验证码定时器
  7492. $scope.msgInfoError = false;
  7493. var setBtnTimeDown = function(value) {
  7494. if(value > 0) {
  7495. $scope.btnState = true;
  7496. $timeout(function() {
  7497. $scope.$apply(function(){
  7498. storage.setItem("btnTimes", $scope.btnTimes);
  7499. $scope.btnTimes --;
  7500. value --;
  7501. setBtnTimeDown (value);
  7502. });
  7503. }, 500);
  7504. }else{
  7505. $scope.btnState = false;
  7506. }
  7507. };
  7508. if(storage.btnTimes > 1){
  7509. $scope.btnTimes = storage.btnTimes;
  7510. setBtnTimeDown(storage.btnTimes)
  7511. }else{
  7512. storage.removeItem("btnTimes");
  7513. }
  7514. $scope.updateTel = function(phoneCode, userTel, uu){
  7515. $scope.loading = true;
  7516. $scope.msgInfoError = false;
  7517. $scope.result = false;
  7518. //更新联系方式
  7519. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  7520. $scope.loading = false;
  7521. $scope.msgInfoError2 = false;
  7522. $scope.result = true;
  7523. AuthenticationService.getAuthentication().success(function(data) {
  7524. $timeout(function(){
  7525. $modalInstance.dismiss();
  7526. window.location.reload();
  7527. }, 1000);
  7528. }).error(function(response) {
  7529. });
  7530. }, function(response){
  7531. $scope.loading = false;
  7532. $scope.msgInfoError2 = response;
  7533. });
  7534. };
  7535. //获取验证码
  7536. $scope.getPhoneCode = function(userTel){
  7537. var timeInfo = 10;
  7538. $scope.clicks ++;
  7539. $scope.timeInfo = timeInfo;
  7540. if($scope.clicks >= 5){
  7541. $scope.errorloading = true;
  7542. $scope.msgInfoSuccess = false;
  7543. $scope.msgInfoError = false;
  7544. }else{
  7545. $scope.loading = true;
  7546. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  7547. $scope.loading = false;
  7548. $scope.msgInfoSuccess = data.success;
  7549. $scope.sendMsg = data;
  7550. $scope.btnTimes = 60;
  7551. setBtnTimeDown($scope.btnTimes);
  7552. $scope.msgInfoError = false;
  7553. },function(response){
  7554. console.log(response);
  7555. $scope.loading = false;
  7556. $scope.msgInfoError = false;
  7557. $scope.sendCheckMsg = false;
  7558. $scope.msgInfoSuccess = true;
  7559. });
  7560. }
  7561. }; */
  7562. }]);
  7563. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7564. $scope.checkboxes = {
  7565. checked : false
  7566. };
  7567. $scope.loading = true;
  7568. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  7569. $scope.enters = data;
  7570. $scope.loading = false;
  7571. angular.forEach($scope.enters, function(item) {
  7572. item:{
  7573. $selected:true;
  7574. }
  7575. });
  7576. })
  7577. // 点击勾选全部的复选框
  7578. $scope.checkAll = function() {
  7579. angular.forEach($scope.enters, function(item) {
  7580. item.$selected = $scope.checkboxes.checked;
  7581. });
  7582. };
  7583. // 点击其中一个明细的复选框
  7584. $scope.checkOne = function(vendor){
  7585. var result = true;
  7586. angular.forEach($scope.enters, function(item) {
  7587. if(item.$selected != true){
  7588. result = false;
  7589. return;
  7590. }
  7591. });
  7592. $scope.checkboxes.checked = result;
  7593. };
  7594. $scope.close = function(save) {
  7595. var chooseResult = [];
  7596. if(save) {
  7597. if(user.userUU) {
  7598. angular.forEach($scope.enters, function(item, i) {
  7599. if(item.$selected) {
  7600. chooseResult.push(item.id);
  7601. }
  7602. });
  7603. if(chooseResult.length > 0) {
  7604. $scope.loading = true;
  7605. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  7606. $scope.loading = false;
  7607. toaster.pop('success', '提示', '删除成功');
  7608. $modalInstance.close(false);
  7609. }, function(response){
  7610. $scope.loading = false;
  7611. toaster.pop('error', '删除失败', response.data);
  7612. $modalInstance.close(false);
  7613. })
  7614. } else {
  7615. toaster.pop('error', '删除失败', "您未勾选任何记录");
  7616. }
  7617. } else {
  7618. $modalInstance.close(true, $scope.checkboxes.checked);
  7619. }
  7620. } else {
  7621. $modalInstance.close(false);
  7622. }
  7623. };
  7624. }]);
  7625. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7626. $scope.checkboxes = {
  7627. checked : false
  7628. };
  7629. $scope.loading = true;
  7630. AccountUser.findVendor({uu : user.userUU},function(data) {
  7631. $scope.enters = data;
  7632. $scope.loading = false;
  7633. // angular.forEach($scope.enters, function(item) {
  7634. // if(item.distribute) {
  7635. // item:{
  7636. // $selected:false;
  7637. // }
  7638. // } else {
  7639. // item:{
  7640. // $selected:true;
  7641. // }
  7642. // }
  7643. // });
  7644. })
  7645. // 点击勾选全部的复选框
  7646. $scope.checkAll = function() {
  7647. angular.forEach($scope.enters, function(item) {
  7648. item.distribute = $scope.checkboxes.checked;
  7649. });
  7650. };
  7651. // 点击其中一个明细的复选框
  7652. $scope.checkOne = function(vendor){
  7653. var result = true;
  7654. angular.forEach($scope.enters, function(item) {
  7655. if(item.distribute != true){
  7656. result = false;
  7657. return;
  7658. }
  7659. });
  7660. $scope.checkboxes.checked = result;
  7661. };
  7662. $scope.close = function(save) {
  7663. var chooseResult = [];
  7664. if(save) {
  7665. if(user.userUU) {
  7666. angular.forEach($scope.enters, function(item, i) {
  7667. // if(item.distribute) {
  7668. chooseResult.push(item);
  7669. // }
  7670. });
  7671. if(chooseResult.length > 0) {
  7672. $scope.loading = true;
  7673. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  7674. $scope.loading = false;
  7675. toaster.pop('success', '提示', '保存成功');
  7676. $modalInstance.close(false);
  7677. }, function(response){
  7678. $scope.loading = false;
  7679. toaster.pop('error', '保存失败', response.data);
  7680. $modalInstance.close(false);
  7681. })
  7682. } else {
  7683. toaster.pop('error', '保存失败', "您未勾选任何记录");
  7684. }
  7685. } else {
  7686. $modalInstance.close(true, $scope.checkboxes.checked);
  7687. }
  7688. } else {
  7689. $modalInstance.close(false);
  7690. }
  7691. };
  7692. }]);
  7693. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  7694. $scope.checked = [];
  7695. $scope.master = [];
  7696. AccountRole.query({}, function(data){
  7697. if(user && data) {
  7698. var rs = [], checked = [];
  7699. angular.forEach(user.roles, function(r){
  7700. rs.push(r.id);
  7701. });
  7702. angular.forEach(data, function(d){
  7703. if(rs.indexOf(d.id) > -1) {
  7704. d.$checked = true;
  7705. checked.push(d);
  7706. }
  7707. });
  7708. }
  7709. $scope.roles = data;
  7710. $scope.checked = checked;
  7711. $scope.master = angular.copy($scope.checked);
  7712. });
  7713. $scope.select = function(role) {
  7714. role.$checked = !role.$checked;
  7715. if(role.$checked) {
  7716. $scope.checked.push(role);
  7717. } else {
  7718. angular.forEach($scope.checked, function(c, i){
  7719. if(c.id == role.id)
  7720. $scope.checked.splice(i, 1);
  7721. });
  7722. }
  7723. };
  7724. $scope.isChanged = function() {
  7725. return !angular.equals($scope.master, $scope.checked);
  7726. };
  7727. $scope.close = function(save) {
  7728. if(save) {
  7729. if(user.userUU) {
  7730. user.roles = $scope.checked;
  7731. AccountUser.update({}, user, function(){
  7732. toaster.pop('success', '提示', '保存成功');
  7733. $modalInstance.close(true);
  7734. }, function(response){
  7735. toaster.pop('error', '保存失败', response.data);
  7736. });
  7737. } else {
  7738. $modalInstance.close(true, $scope.checked);
  7739. }
  7740. } else {
  7741. $modalInstance.close(false);
  7742. }
  7743. };
  7744. }]);
  7745. // 修改密码Controller
  7746. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7747. $scope.user = user;
  7748. $scope.checking = false;
  7749. //输入原密码后验证原密码是否正确
  7750. $scope.checkPassword = function(password) {
  7751. $scope.checking = true;
  7752. $scope.checkSuccess = false;
  7753. $scope.checkFailed = false;
  7754. AccountUser.checkPassword({password: password}, function(data){
  7755. $scope.checkSuccess = true;
  7756. $scope.checking = false;
  7757. $scope.checkFailed = false;
  7758. }, function(response){
  7759. $scope.checkFailed = true;
  7760. $scope.checking = false;
  7761. $scope.checkSuccess = false;
  7762. });
  7763. };
  7764. //修改密码
  7765. $scope.ok = function () {
  7766. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  7767. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  7768. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  7769. $scope.user.password = null;
  7770. $scope.user.newPassword = null;
  7771. $scope.user.newPassword1 = null;
  7772. $scope.checking = false;
  7773. $scope.checkSuccess = false;
  7774. $scope.checkFailed = false;
  7775. }, function(response){
  7776. toaster.pop('error', '错误', response.data);
  7777. });
  7778. } else {
  7779. toaster.pop('error', '错误', '重复密码不一致');
  7780. }
  7781. };
  7782. $scope.cancel = function () {
  7783. $modalInstance.dismiss();
  7784. };
  7785. }]);
  7786. /*
  7787. * 绑定用户到企业
  7788. */
  7789. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster){
  7790. $scope.searching = false;
  7791. //根据输入的内容查找用户
  7792. $scope.searchUser = function(keyWord) {
  7793. $scope.searching = true;
  7794. $scope.searchSuccess = false;
  7795. $scope.searchFailed = false;
  7796. $scope.illegalError = false;
  7797. $scope.reBindError = false;
  7798. $scope.okDisabled = false;
  7799. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  7800. $scope.searchSuccess = true;
  7801. $scope.searchFailed = false;
  7802. $scope.user = data; //查询到的用户
  7803. }, function(response){
  7804. $scope.searchSuccess = false;
  7805. $scope.searchFailed = true;
  7806. });
  7807. };
  7808. //确认绑定
  7809. $scope.ok = function (keyWord) {
  7810. AuthenticationService.getAuthentication().success(function(data) {
  7811. $scope.currentUser = data; //当前登录的用户(管理员)
  7812. //不可自己绑定自己
  7813. if($scope.currentUser.userUU == $scope.user.userUU){
  7814. $scope.illegalError = true;
  7815. $scope.okDisabled = true;
  7816. return false;
  7817. }
  7818. //用户未绑定到任何企业时
  7819. if(!$scope.user.enterprises){
  7820. //正常绑定
  7821. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  7822. $scope.okDisabled = true;
  7823. toaster.pop("success", "提示", "用户绑定成功");
  7824. $modalInstance.close(true);
  7825. }, function(response){
  7826. });
  7827. return true;
  7828. }
  7829. //用户已绑定到某些企业时
  7830. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  7831. if($scope.currentUser.enterprises[i].current){
  7832. for(var j = 0; j < $scope.user.enterprises.length; j++){
  7833. //该用户已绑定到当前企业,不可重复绑定
  7834. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  7835. $scope.reBindError = true;
  7836. $scope.okDisabled = true;
  7837. return false;
  7838. }
  7839. }
  7840. //该用户未绑定到当前企业,可以进行绑定
  7841. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  7842. $scope.okDisabled = true;
  7843. toaster.pop("success", "提示", "用户绑定成功");
  7844. $modalInstance.close(true);
  7845. }, function(response){
  7846. console.log("绑定失败!");
  7847. });
  7848. }
  7849. }
  7850. });
  7851. };
  7852. $scope.cancel = function () {
  7853. $modalInstance.dismiss();
  7854. };
  7855. }]);
  7856. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  7857. $scope.erpParams = new ngTableParams({
  7858. page : 1,
  7859. count : 5,
  7860. sorting: {
  7861. time: 'desc'
  7862. }
  7863. }, {
  7864. total : 0,
  7865. counts: [5, 10, 25, 50],
  7866. getData : function($defer, params) {
  7867. $scope.loading = true;
  7868. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  7869. $scope.loading = false;
  7870. if(page) {
  7871. params.total(page.totalElements);
  7872. $defer.resolve(page.content);
  7873. }
  7874. }, function(response){
  7875. $scope.loading = false;
  7876. toaster.pop('error', '数据加载失败', response.data);
  7877. });
  7878. }
  7879. });
  7880. $scope.usageParams = new ngTableParams({
  7881. page : 1,
  7882. count : 5,
  7883. sorting: {
  7884. time: 'desc'
  7885. }
  7886. }, {
  7887. total : 0,
  7888. counts: [5, 10, 25, 50],
  7889. getData : function($defer, params) {
  7890. $scope.loading = true;
  7891. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  7892. $scope.loading = false;
  7893. if(page) {
  7894. params.total(page.totalElements);
  7895. $defer.resolve(page.content);
  7896. }
  7897. }, function(response){
  7898. $scope.loading = false;
  7899. toaster.pop('error', '数据加载失败', response.data);
  7900. });
  7901. }
  7902. });
  7903. }]);
  7904. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  7905. AccountResource.query({}, function(data){
  7906. if(data && data.length > 0) {
  7907. data[0].$open = true;
  7908. }
  7909. $scope.resources = data;
  7910. });
  7911. }]);
  7912. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  7913. $scope.roles = {};
  7914. var getData = function() {
  7915. AccountRole.query({}, function(data){
  7916. var defaults = [], custom = [];
  7917. angular.forEach(data, function(d){
  7918. if(d.isdefault == 1)
  7919. defaults.push(d);
  7920. else
  7921. custom.push(d);
  7922. });
  7923. $scope.roles = {defaults: defaults, custom: custom};
  7924. });
  7925. };
  7926. getData();
  7927. $scope.editRole = function(role){
  7928. var modalInstance = $modal.open({
  7929. animation: true,
  7930. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  7931. controller: 'RoleEditCtrl',
  7932. resolve: {
  7933. role: function() {
  7934. return role;
  7935. }
  7936. }
  7937. });
  7938. modalInstance.result.then(function(added){
  7939. added && (getData());
  7940. });
  7941. };
  7942. }]);
  7943. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  7944. BaseService.scrollBackToTop();
  7945. $scope.role = role;
  7946. $scope.master = angular.copy($scope.role);
  7947. var isNew = role == null;
  7948. $scope.cancel = function() {
  7949. $modalInstance.close(false);
  7950. };
  7951. AccountResource.query({}, function(data){
  7952. if(data && data.length > 0) {
  7953. if(role && role.resourceItems) {
  7954. var rs = [];// 已分配的资源的id
  7955. angular.forEach(role.resourceItems, function(item){
  7956. rs.push(item.id);
  7957. });
  7958. angular.forEach(data, function(resource){
  7959. var c = 0;
  7960. angular.forEach(resource.items, function(item){
  7961. if(rs.indexOf(item.id) > -1) {
  7962. item.$checked = true;
  7963. c += 1;
  7964. }
  7965. });
  7966. resource.$checked = c == resource.items.length;
  7967. });
  7968. }
  7969. $scope.resourceItems = data[0].items;
  7970. data[0].$active = true;
  7971. }
  7972. $scope.resources = data;
  7973. $timeout(function(){
  7974. angular.forEach($scope.resources, function(resource){
  7975. var c = 0;
  7976. angular.forEach(resource.items, function(item){
  7977. item.$checked && (c+=1);
  7978. });
  7979. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  7980. });
  7981. }, 100);
  7982. });
  7983. $scope.onItemClick = function(resource) {
  7984. $scope.resourceItems = resource.items;
  7985. angular.forEach($scope.resources, function(r){
  7986. r.$active = false;
  7987. });
  7988. resource.$active = true;
  7989. };
  7990. var getChecked = function() {
  7991. var items = [];
  7992. angular.forEach($scope.resources, function(resource){
  7993. angular.forEach(resource.items, function(item){
  7994. item.$checked && (items.push(item));
  7995. });
  7996. });
  7997. $scope.role.resourceItems = items;
  7998. };
  7999. $scope.onResourceChange = function(resource) {
  8000. angular.forEach(resource.items, function(item){
  8001. item.$checked = resource.$checked;
  8002. });
  8003. getChecked();
  8004. };
  8005. $scope.onItemChange = function() {
  8006. angular.forEach($scope.resources, function(resource){
  8007. if(resource.$active) {
  8008. var c = 0;
  8009. angular.forEach(resource.items, function(item){
  8010. item.$checked && (c+=1);
  8011. });
  8012. resource.$checked = (c == resource.items.length);
  8013. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8014. }
  8015. });
  8016. getChecked();
  8017. };
  8018. $scope.isChanged = function(formData) {
  8019. if(!$scope.master)
  8020. return true;
  8021. return !angular.equals(formData, $scope.master);
  8022. };
  8023. $scope.save = function() {
  8024. $scope.master = angular.copy($scope.role);
  8025. AccountRole.save($scope.master, function(){
  8026. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  8027. $modalInstance.close(true);
  8028. }, function(response){
  8029. toaster.pop('error', '错误', response.data);
  8030. });
  8031. };
  8032. $scope.del = function() {
  8033. new ngAlert({
  8034. title: '提示',
  8035. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  8036. }, function(){
  8037. AccountRole.remove({id: role.id}, function(){
  8038. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  8039. $modalInstance.close(true);
  8040. }, function(response){
  8041. toaster.pop('error', '错误', response.data);
  8042. });
  8043. })
  8044. };
  8045. }]);
  8046. /**
  8047. * 委外订单
  8048. */
  8049. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  8050. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  8051. BaseService.scrollBackToTop();
  8052. $scope.active = 'todo';
  8053. $scope.dateZoneText = '不限';
  8054. $scope.condition = {dateZone: -1};
  8055. $scope.changeDateZone = function(zone) {
  8056. $scope.condition.dateZone = zone;
  8057. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  8058. $scope.condition.$dateZoneOpen = false;
  8059. getDateCondition(zone, $scope.condition);
  8060. $scope.tableParams.reload();
  8061. };
  8062. $scope.setActive = function(state) {
  8063. if($scope.active != state) {
  8064. $scope.active = state;
  8065. if($scope.tableParams.page() == 1)
  8066. $scope.tableParams.reload();
  8067. else
  8068. $scope.tableParams.page(1);
  8069. }
  8070. };
  8071. var getService = function() {
  8072. return MakeOrder;
  8073. };
  8074. $scope.tableParams = new ngTableParams({
  8075. page : 1,
  8076. count : 5,
  8077. sorting: {
  8078. date: 'desc'
  8079. }
  8080. }, {
  8081. total : 0,
  8082. counts: [5, 10, 25, 50],
  8083. getData : function($defer, params) {
  8084. $scope.loading = true;
  8085. var pageParams = params.url();
  8086. pageParams.searchFilter = {};
  8087. pageParams.searchFilter.keyword = $scope.keyword;
  8088. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8089. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8090. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8091. $scope.loading = false;
  8092. if(page) {
  8093. params.total(page.totalElement);
  8094. $defer.resolve(page.content);
  8095. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8096. }
  8097. }, function(response){
  8098. $scope.loading = false;
  8099. toaster.pop('error', '数据加载失败', response.data);
  8100. });
  8101. }
  8102. });
  8103. $scope.getOrderTotal = function(items) {
  8104. var sum = 0;
  8105. angular.forEach(items, function(item){
  8106. sum += item.qty * item.price;
  8107. });
  8108. return sum;
  8109. };
  8110. $scope.openDatePicker = function($event, item, openParam) {
  8111. $event.preventDefault();
  8112. $event.stopPropagation();
  8113. item[openParam] = !item[openParam];
  8114. };
  8115. $scope.parseDate = function(dateStr) {
  8116. if(dateStr)
  8117. return Date.parse(dateStr, 'yyyy-MM-dd');
  8118. return new Date();
  8119. };
  8120. // 打开回复
  8121. $scope.openReply = function(order) {
  8122. if(!order.reply) {
  8123. order.reply = {
  8124. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8125. delivery: order.delivery
  8126. }
  8127. }
  8128. order.$editing = true;
  8129. };
  8130. // 关闭回复
  8131. $scope.closeReply = function(order) {
  8132. order.$editing = false;
  8133. }
  8134. // 搜索框回车
  8135. $scope.onSearch = function() {
  8136. $scope.tableParams.page(1);
  8137. $scope.tableParams.reload();
  8138. };
  8139. // 选择查找日期
  8140. $scope.onDateCondition = function(){
  8141. $scope.tableParams.page(1);
  8142. $scope.tableParams.reload();
  8143. };
  8144. // 点击回复
  8145. $scope.onReplyClick = function(order, inverse) {
  8146. if(order.reply) {
  8147. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8148. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8149. return;
  8150. }
  8151. var reply = angular.copy(order.reply);
  8152. if(reply.delivery) {
  8153. if(typeof reply.delivery == 'object')
  8154. reply.delivery = reply.delivery.getTime();
  8155. } else {
  8156. reply.delivery = order.delivery;
  8157. }
  8158. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8159. $scope.loading = true;
  8160. MakeOrder.reply({orderId: order.id}, reply, function(){
  8161. $scope.loading = false;
  8162. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8163. $scope.tableParams.reload();
  8164. }, function(response){
  8165. $scope.loading = false;
  8166. toaster.pop('error', '回复失败', response.data);
  8167. });
  8168. }
  8169. };
  8170. //委外加工单
  8171. $scope.print = function(order) {
  8172. MakeOrder.printCount({id: order.id},{});//增加打印此次
  8173. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  8174. };
  8175. // 获取回复记录
  8176. $scope.getReply = function(order) {
  8177. if(!order.replies) {
  8178. MakeOrder.getReply({orderId: order.id}, function(replies){
  8179. order.replies = replies;
  8180. });
  8181. }
  8182. };
  8183. }]);
  8184. /**
  8185. * 委外加工单详细
  8186. */
  8187. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  8188. BaseService.scrollBackToTop();
  8189. var loadData = function() {
  8190. MakeOrder.get({id: $stateParams.id}, function(data){
  8191. $scope.order = data;
  8192. var sum = $scope.order.qty * $scope.order.price;
  8193. $scope.order.total = sum;
  8194. $scope.loading = false;
  8195. });
  8196. };
  8197. loadData();
  8198. // 获取回复记录
  8199. $scope.getReply = function(item) {
  8200. if(!item.replies) {
  8201. MakeOrder.getReply({orderId: item.id}, function(replies){
  8202. item.replies = replies;
  8203. });
  8204. }
  8205. };
  8206. $scope.openDatePicker = function($event, item, openParam) {
  8207. $event.preventDefault();
  8208. $event.stopPropagation();
  8209. item[openParam] = !item[openParam];
  8210. };
  8211. // 点击回复
  8212. $scope.onReplyClick = function(order, inverse) {
  8213. if(order.reply) {
  8214. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8215. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8216. return;
  8217. }
  8218. var reply = angular.copy(order.reply);
  8219. if(reply.delivery) {
  8220. if(typeof reply.delivery == 'object')
  8221. reply.delivery = reply.delivery.getTime();
  8222. } else {
  8223. reply.delivery = order.delivery;
  8224. }
  8225. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8226. $scope.loading = true;
  8227. MakeOrder.reply({orderId: order.id}, reply, function(){
  8228. $scope.loading = false;
  8229. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8230. loadData();
  8231. }, function(response){
  8232. $scope.loading = false;
  8233. toaster.pop('error', '回复失败', response.data);
  8234. });
  8235. }
  8236. };
  8237. // 打开回复
  8238. $scope.openReply = function(order) {
  8239. if(!order.reply) {
  8240. order.reply = {
  8241. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8242. delivery: order.delivery
  8243. }
  8244. }
  8245. order.$editing = true;
  8246. };
  8247. // 关闭回复
  8248. $scope.closeReply = function(order) {
  8249. order.$editing = false;
  8250. }
  8251. // 委外订单
  8252. $scope.print = function(order) {
  8253. MakeOrder.printCount({id: order.id},{});//增加打印此次
  8254. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  8255. };
  8256. }]);
  8257. /**
  8258. * 客户委外验收
  8259. */
  8260. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  8261. BaseService.scrollBackToTop();
  8262. $scope.active = 'all';
  8263. $scope.agreedText = '全部';
  8264. $scope.dateZoneText = '一个月内';
  8265. $scope.condition = {dateZone: 1};
  8266. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8267. $scope.changeAgreed = function(agreed) {
  8268. $scope.condition.agreed = agreed;
  8269. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8270. $scope.condition.$agreedOpen = false;
  8271. };
  8272. $scope.changeDateZone = function(zone) {
  8273. $scope.condition.dateZone = zone;
  8274. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8275. $scope.condition.$dateZoneOpen = false;
  8276. getDateCondition(zone, $scope.condition);
  8277. $scope.tableParams.reload();
  8278. };
  8279. $scope.setActive = function(state) {
  8280. if($scope.active != state) {
  8281. $scope.active = state;
  8282. if($scope.tableParams.page() == 1)
  8283. $scope.tableParams.reload();
  8284. else
  8285. $scope.tableParams.page(1);
  8286. }
  8287. };
  8288. var getService = function() {
  8289. return MakeAccept;
  8290. };
  8291. $scope.tableParams = new ngTableParams({
  8292. page : 1,
  8293. count : 5,
  8294. sorting: {
  8295. date: 'desc'
  8296. }
  8297. }, {
  8298. total : 0,
  8299. counts: [5, 10, 25, 50],
  8300. getData : function($defer, params) {
  8301. $scope.loading = true;
  8302. var pageParams = params.url();
  8303. pageParams.searchFilter = {};
  8304. pageParams.searchFilter.keyword = $scope.keyword;
  8305. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8306. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8307. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8308. $scope.loading = false;
  8309. if(page) {
  8310. params.total(page.totalElement);
  8311. $defer.resolve(page.content);
  8312. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8313. }
  8314. }, function(response){
  8315. $scope.loading = false;
  8316. toaster.pop('error', '数据加载失败', response.data);
  8317. });
  8318. }
  8319. });
  8320. $scope.openDatePicker = function($event, item, openParam) {
  8321. $event.preventDefault();
  8322. $event.stopPropagation();
  8323. item[openParam] = !item[openParam];
  8324. };
  8325. // 搜索框回车
  8326. $scope.onSearch = function() {
  8327. $scope.tableParams.page(1);
  8328. $scope.tableParams.reload();
  8329. };
  8330. // 选择查找日期
  8331. $scope.onDateCondition = function(){
  8332. $scope.tableParams.page(1);
  8333. $scope.tableParams.reload();
  8334. };
  8335. }]);
  8336. /**
  8337. * 客户委外验退
  8338. */
  8339. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  8340. BaseService.scrollBackToTop();
  8341. $scope.active = 'all';
  8342. $scope.agreedText = '全部';
  8343. $scope.dateZoneText = '一个月内';
  8344. $scope.condition = {dateZone: 1};
  8345. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8346. $scope.changeAgreed = function(agreed) {
  8347. $scope.condition.agreed = agreed;
  8348. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8349. $scope.condition.$agreedOpen = false;
  8350. };
  8351. $scope.changeDateZone = function(zone) {
  8352. $scope.condition.dateZone = zone;
  8353. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8354. $scope.condition.$dateZoneOpen = false;
  8355. getDateCondition(zone, $scope.condition);
  8356. $scope.tableParams.reload();
  8357. };
  8358. $scope.setActive = function(state) {
  8359. if($scope.active != state) {
  8360. $scope.active = state;
  8361. if($scope.tableParams.page() == 1)
  8362. $scope.tableParams.reload();
  8363. else
  8364. $scope.tableParams.page(1);
  8365. }
  8366. };
  8367. var getService = function() {
  8368. return MakeReturn;
  8369. };
  8370. $scope.tableParams = new ngTableParams({
  8371. page : 1,
  8372. count : 5,
  8373. sorting: {
  8374. date: 'desc'
  8375. }
  8376. }, {
  8377. total : 0,
  8378. counts: [5, 10, 25, 50],
  8379. getData : function($defer, params) {
  8380. $scope.loading = true;
  8381. var pageParams = params.url();
  8382. pageParams.searchFilter = {};
  8383. pageParams.searchFilter.keyword = $scope.keyword;
  8384. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8385. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8386. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8387. $scope.loading = false;
  8388. if(page) {
  8389. params.total(page.totalElement);
  8390. $defer.resolve(page.content);
  8391. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8392. }
  8393. }, function(response){
  8394. $scope.loading = false;
  8395. toaster.pop('error', '数据加载失败', response.data);
  8396. });
  8397. }
  8398. });
  8399. $scope.openDatePicker = function($event, item, openParam) {
  8400. $event.preventDefault();
  8401. $event.stopPropagation();
  8402. item[openParam] = !item[openParam];
  8403. };
  8404. // 搜索框回车
  8405. $scope.onSearch = function() {
  8406. $scope.tableParams.page(1);
  8407. $scope.tableParams.reload();
  8408. };
  8409. // 选择查找日期
  8410. $scope.onDateCondition = function(){
  8411. $scope.tableParams.page(1);
  8412. $scope.tableParams.reload();
  8413. };
  8414. }]);
  8415. /**
  8416. * 委外加工变更
  8417. */
  8418. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  8419. BaseService.scrollBackToTop();
  8420. $scope.active = 'all';
  8421. $scope.agreedText = '全部';
  8422. $scope.dateZoneText = '一个月内';
  8423. $scope.condition = {dateZone: 1};
  8424. $scope.changeAgreed = function(agreed) {
  8425. $scope.condition.agreed = agreed;
  8426. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8427. $scope.condition.$agreedOpen = false;
  8428. };
  8429. $scope.changeDateZone = function(zone) {
  8430. $scope.condition.dateZone = zone;
  8431. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8432. $scope.condition.$dateZoneOpen = false;
  8433. getDateCondition(zone, $scope.condition);
  8434. $scope.tableParams.reload();
  8435. };
  8436. $scope.setActive = function(state) {
  8437. if($scope.active != state) {
  8438. $scope.active = state;
  8439. if($scope.tableParams.page() == 1)
  8440. $scope.tableParams.reload();
  8441. else
  8442. $scope.tableParams.page(1);
  8443. }
  8444. };
  8445. var getService = function() {
  8446. return MakeChange;
  8447. };
  8448. $scope.tableParams = new ngTableParams({
  8449. page : 1,
  8450. count : 5,
  8451. sorting: {
  8452. orderChangeDate: 'desc'
  8453. }
  8454. }, {
  8455. total : 0,
  8456. counts: [5, 10, 25, 50],
  8457. getData : function($defer, params) {
  8458. $scope.loading = true;
  8459. var pageParams = params.url();
  8460. pageParams.searchFilter = {};
  8461. pageParams.searchFilter.keyword = $scope.keyword;
  8462. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8463. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8464. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8465. $scope.loading = false;
  8466. if(page) {
  8467. params.total(page.totalElement);
  8468. $defer.resolve(page.content);
  8469. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8470. }
  8471. }, function(response){
  8472. $scope.loading = false;
  8473. toaster.pop('error', '数据加载失败', response.data);
  8474. });
  8475. }
  8476. });
  8477. $scope.openDatePicker = function($event, item, openParam) {
  8478. $event.preventDefault();
  8479. $event.stopPropagation();
  8480. item[openParam] = !item[openParam];
  8481. };
  8482. // 打开回复
  8483. $scope.openReply = function(change) {
  8484. change.$editing = true;
  8485. };
  8486. // 关闭回复
  8487. $scope.closeReply = function(change) {
  8488. change.$editing = false;
  8489. }
  8490. // 确定回复
  8491. $scope.onReplyClick = function(change) {
  8492. if(change.$agreed) {
  8493. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8494. $scope.loading = true;
  8495. MakeChange.reply({itemId: change.id}, reply, function(){
  8496. $scope.loading = false;
  8497. toaster.pop('info', '提示', '回复成功');
  8498. $scope.tableParams.reload();
  8499. }, function(response){
  8500. $scope.loading = false;
  8501. toaster.pop('error', '回复失败', response.data);
  8502. });
  8503. }
  8504. };
  8505. // 搜索框回车
  8506. $scope.onSearch = function() {
  8507. $scope.tableParams.page(1);
  8508. $scope.tableParams.reload();
  8509. };
  8510. // 选择查找日期
  8511. $scope.onDateCondition = function(){
  8512. $scope.tableParams.page(1);
  8513. $scope.tableParams.reload();
  8514. };
  8515. }]);
  8516. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  8517. BaseService.scrollBackToTop();
  8518. var loadData = function() {
  8519. MakeChange.get({id: $stateParams.id}, function(data){
  8520. $scope.change = data;
  8521. });
  8522. };
  8523. loadData();
  8524. $scope.openDatePicker = function($event, item, openParam) {
  8525. $event.preventDefault();
  8526. $event.stopPropagation();
  8527. item[openParam] = !item[openParam];
  8528. };
  8529. $scope.onReplyClick = function(change) {
  8530. if(change.$agreed) {
  8531. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8532. MakeChange.reply({itemId: change.id}, reply, function(){
  8533. toaster.pop('info', '提示', '回复成功');
  8534. loadData();
  8535. }, function(response){
  8536. toaster.pop('error', '回复失败', response.data);
  8537. });
  8538. }
  8539. };
  8540. }]);
  8541. /**
  8542. * 委外加工
  8543. */
  8544. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  8545. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  8546. BaseService.scrollBackToTop();
  8547. $scope.active = 'all';
  8548. $scope.agreedText = '全部';
  8549. $scope.dateZoneText = '一个月内';
  8550. $scope.condition = {dateZone: 1};
  8551. $scope.changeAgreed = function(agreed) {
  8552. $scope.condition.agreed = agreed;
  8553. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8554. $scope.condition.$agreedOpen = false;
  8555. };
  8556. $scope.changeDateZone = function(zone) {
  8557. $scope.condition.dateZone = zone;
  8558. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8559. $scope.condition.$dateZoneOpen = false;
  8560. getDateCondition(zone, $scope.condition);
  8561. $scope.tableParams.reload();
  8562. };
  8563. $scope.setActive = function(state) {
  8564. if($scope.active != state) {
  8565. $scope.active = state;
  8566. if($scope.tableParams.page() == 1)
  8567. $scope.tableParams.reload();
  8568. else
  8569. $scope.tableParams.page(1);
  8570. }
  8571. };
  8572. var getService = function() {
  8573. return MakeOutOrder;
  8574. };
  8575. $scope.tableParams = new ngTableParams({
  8576. page : 1,
  8577. count : 5,
  8578. sorting: {
  8579. date: 'desc'
  8580. }
  8581. }, {
  8582. total : 0,
  8583. counts: [5, 10, 25, 50],
  8584. getData : function($defer, params) {
  8585. $scope.loading = true;
  8586. var pageParams = params.url();
  8587. pageParams.searchFilter = {};
  8588. pageParams.searchFilter.keyword = $scope.keyword;
  8589. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8590. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8591. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8592. $scope.loading = false;
  8593. if(page) {
  8594. params.total(page.totalElement);
  8595. $defer.resolve(page.content);
  8596. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8597. }
  8598. }, function(response){
  8599. $scope.loading = false;
  8600. toaster.pop('error', '数据加载失败', response.data);
  8601. });
  8602. }
  8603. });
  8604. $scope.openDatePicker = function($event, item, openParam) {
  8605. $event.preventDefault();
  8606. $event.stopPropagation();
  8607. item[openParam] = !item[openParam];
  8608. };
  8609. // 打开回复
  8610. $scope.openReply = function(change) {
  8611. change.$editing = true;
  8612. };
  8613. // 关闭回复
  8614. $scope.closeReply = function(change) {
  8615. change.$editing = false;
  8616. }
  8617. // 确定回复
  8618. $scope.onReplyClick = function(change) {
  8619. if(change.$agreed) {
  8620. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8621. $scope.loading = true;
  8622. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  8623. $scope.loading = false;
  8624. toaster.pop('info', '提示', '回复成功');
  8625. $scope.tableParams.reload();
  8626. }, function(response){
  8627. $scope.loading = false;
  8628. toaster.pop('error', '回复失败', response.data);
  8629. });
  8630. }
  8631. };
  8632. // 搜索框回车
  8633. $scope.onSearch = function() {
  8634. $scope.tableParams.page(1);
  8635. $scope.tableParams.reload();
  8636. };
  8637. // 选择查找日期
  8638. $scope.onDateCondition = function(){
  8639. $scope.tableParams.page(1);
  8640. $scope.tableParams.reload();
  8641. };
  8642. }]);
  8643. /**
  8644. * 委外加工详细
  8645. */
  8646. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  8647. BaseService.scrollBackToTop();
  8648. var loadData = function() {
  8649. MakeOutOrder.get({id: $stateParams.id}, function(data){
  8650. $scope.order = data;
  8651. var sum = $scope.order.qty * $scope.order.price;
  8652. $scope.order.total = sum;
  8653. $scope.loading = false;
  8654. });
  8655. };
  8656. loadData();
  8657. // 获取回复记录
  8658. $scope.getReply = function(item) {
  8659. if(!item.replies) {
  8660. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  8661. item.replies = replies;
  8662. });
  8663. }
  8664. };
  8665. $scope.openDatePicker = function($event, item, openParam) {
  8666. $event.preventDefault();
  8667. $event.stopPropagation();
  8668. item[openParam] = !item[openParam];
  8669. };
  8670. // 点击回复
  8671. $scope.onReplyClick = function(order, inverse) {
  8672. if(order.reply) {
  8673. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8674. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8675. return;
  8676. }
  8677. var reply = angular.copy(order.reply);
  8678. if(reply.delivery) {
  8679. if(typeof reply.delivery == 'object')
  8680. reply.delivery = reply.delivery.getTime();
  8681. } else {
  8682. reply.delivery = order.delivery;
  8683. }
  8684. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8685. $scope.loading = true;
  8686. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  8687. $scope.loading = false;
  8688. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8689. loadData();
  8690. }, function(response){
  8691. $scope.loading = false;
  8692. toaster.pop('error', '回复失败', response.data);
  8693. });
  8694. }
  8695. };
  8696. // 打开回复
  8697. $scope.openReply = function(order) {
  8698. if(!order.reply) {
  8699. order.reply = {
  8700. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8701. delivery: order.delivery
  8702. }
  8703. }
  8704. order.$editing = true;
  8705. };
  8706. // 关闭回复
  8707. $scope.closeReply = function(order) {
  8708. order.$editing = false;
  8709. }
  8710. // 自己委外加工订单
  8711. $scope.print = function(order) {
  8712. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  8713. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  8714. };
  8715. }]);
  8716. /**
  8717. * 计算时间差
  8718. */
  8719. app.filter('timespan', function(){
  8720. return function(time) {
  8721. if(time == null)
  8722. return '9999年';
  8723. var now = new Date().getTime(), span = time - now,
  8724. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  8725. m = Math.ceil(span/60000);
  8726. if(span < 0)
  8727. return '1天';
  8728. if(d > 0)
  8729. return d+1 + '天';
  8730. if(h > 0)
  8731. return h + '小时';
  8732. if(m > 0)
  8733. return m + '分钟';
  8734. return '0天';
  8735. };
  8736. });
  8737. app.filter('firstchar', function(){
  8738. return function(str) {
  8739. if(str == null)
  8740. return null;
  8741. return str.substring(0, 1);
  8742. };
  8743. });
  8744. app.filter('summary', function(){
  8745. return function(data, field) {
  8746. var sum = 0;
  8747. if (data) {
  8748. angular.forEach(data, function(d){
  8749. sum += d[field];
  8750. });
  8751. }
  8752. return sum;
  8753. };
  8754. });
  8755. /**
  8756. * 搜索框,回车触发
  8757. */
  8758. app.directive('ngSearch', ['$parse', function($parse) {
  8759. return {
  8760. require : '?ngModel',
  8761. restrict : 'A',
  8762. link : function(scope, element, attrs, ngModel) {
  8763. var searchFn = $parse(attrs.ngSearch);
  8764. element.bind('keypress', function(event) {
  8765. if (event.keyCode == '13') {
  8766. event.preventDefault();
  8767. event.stopPropagation();
  8768. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  8769. }
  8770. });
  8771. }
  8772. };
  8773. }]);
  8774. /**
  8775. * 状态码 -> 描述
  8776. */
  8777. app.filter('status', function(){
  8778. return function(data) {
  8779. var statusConfig = {
  8780. '101': '已提交',
  8781. '102': '已审核',
  8782. '103': '未通过',
  8783. '200': '未回复',
  8784. '201': '已回复',
  8785. '313': '已激活',
  8786. '316': '已过账',
  8787. '311': '申请中',
  8788. '312': '未激活'
  8789. };
  8790. return statusConfig[data];
  8791. }
  8792. });
  8793. //弹出问题反馈模态框
  8794. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  8795. //获取当前用户
  8796. AuthenticationService.getAuthentication().success(function(data) {
  8797. $scope.user = data;
  8798. });
  8799. $scope.showModal = function(){
  8800. var modalInstance = $modal.open({
  8801. animation: true,
  8802. templateUrl: 'static/tpl/serve/feedback.html',
  8803. controller: 'FeedbackCtrl',
  8804. resolve: {
  8805. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  8806. }
  8807. });
  8808. modalInstance.result.then(function(){
  8809. }, function(){
  8810. })
  8811. }
  8812. }]);
  8813. /*
  8814. * 提交我的反馈
  8815. */
  8816. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  8817. $scope.isPublic = 1; //默认公开
  8818. $scope.classId = 1; //默认类别
  8819. $scope.user = user;
  8820. $scope.ok = function(){
  8821. if(!$scope.user){ //用户未登录
  8822. $scope.uu = null;
  8823. }else{ //用户已登录
  8824. $scope.uu = $scope.user.userUU;
  8825. }
  8826. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  8827. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  8828. function(data){
  8829. toaster.pop('success', '成功', '您的问题反馈成功!');
  8830. $scope.cancel();
  8831. }, function(response){
  8832. toaster.pop('error', '错误', response.data);
  8833. });
  8834. }
  8835. $scope.cancel = function () {
  8836. $modalInstance.dismiss();
  8837. };
  8838. }]);
  8839. //“我的问题反馈”跳转控制
  8840. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  8841. $scope.myFeedback = function(){
  8842. AuthenticationService.getAuthentication().success(function(data){
  8843. $scope.user = data;
  8844. if(!$scope.user){
  8845. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  8846. return false;
  8847. }else{
  8848. window.location.href = "./serve#/question/myFeedback";
  8849. }
  8850. });
  8851. }
  8852. }]);
  8853. //客户服务
  8854. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  8855. Vendor.getServe(function(datas){
  8856. $scope.vendors = datas;
  8857. // 自动跳转
  8858. if(datas && datas.length == 1)
  8859. $scope.redirect(datas[0]);
  8860. });
  8861. $scope.redirect = function(vendor) {
  8862. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  8863. };
  8864. }]);
  8865. /**
  8866. * 物料资料
  8867. */
  8868. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  8869. BaseService.scrollBackToTop();
  8870. $scope.active = 'all';
  8871. $scope.agreedText = '全部';
  8872. $scope.dateZoneText = '一个月内';
  8873. $scope.condition = {dateZone: 1};
  8874. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8875. $scope.changeAgreed = function(agreed) {
  8876. $scope.condition.agreed = agreed;
  8877. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8878. $scope.condition.$agreedOpen = false;
  8879. };
  8880. $scope.changeDateZone = function(zone) {
  8881. $scope.condition.dateZone = zone;
  8882. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8883. $scope.condition.$dateZoneOpen = false;
  8884. getDateCondition(zone, $scope.condition);
  8885. $scope.tableParams.reload();
  8886. };
  8887. $scope.setActive = function(state) {
  8888. if($scope.active != state) {
  8889. $scope.active = state;
  8890. if($scope.tableParams.page() == 1)
  8891. $scope.tableParams.reload();
  8892. else
  8893. $scope.tableParams.page(1);
  8894. }
  8895. };
  8896. var getService = function() {
  8897. return GetProductInfo;
  8898. };
  8899. $scope.tableParams = new ngTableParams({
  8900. page : 1,
  8901. count : 5,
  8902. sorting: {
  8903. }
  8904. }, {
  8905. total : 0,
  8906. counts: [5, 10, 25, 50],
  8907. getData : function($defer, params) {
  8908. $scope.loading = true;
  8909. var pageParams = params.url();
  8910. pageParams.keyword = $scope.keyword;
  8911. pageParams.searchFilter = $scope.searchFilter;
  8912. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8913. $scope.loading = false;
  8914. if(page) {
  8915. params.total(page.totalElement);
  8916. $defer.resolve(page.content);
  8917. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8918. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  8919. }
  8920. }, function(response) {
  8921. $scope.loading = false;
  8922. toaster.pop('error', '数据加载失败', response.data);
  8923. });
  8924. }
  8925. });
  8926. // 搜索框回车
  8927. $scope.onSearch = function() {
  8928. $scope.tableParams.page(1);
  8929. $scope.tableParams.reload();
  8930. };
  8931. //删除
  8932. $scope.deleteById = function(id) {
  8933. GetProductInfo.deleteById({id: id}, function(data) {
  8934. if(data.error) {
  8935. toaster.pop("error", "提示", data.error);
  8936. } else {
  8937. toaster.pop("success", "提示", "删除成功");
  8938. $timeout(function() {
  8939. $scope.tableParams.reload();
  8940. }, 500);
  8941. }
  8942. }), function(response) {
  8943. toaster.pop("error", "删除失败", response.data);
  8944. };
  8945. }
  8946. }]);
  8947. /**
  8948. * 物料批量上传
  8949. */
  8950. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  8951. BaseService.scrollBackToTop();
  8952. // 通过excel批量上传物料
  8953. $scope.upload = function() {
  8954. if($scope.myFiles) {
  8955. var file = $scope.myFiles[0];
  8956. console.log(file);
  8957. if(file.name) {
  8958. $upload.upload({
  8959. url: 'product/baseInfo/release/excel',
  8960. file: file,
  8961. method: 'POST'
  8962. }).success(function(data) {
  8963. $scope.result = data;
  8964. $scope.success = $scope.result.success;
  8965. $scope.total = $scope.result.total;
  8966. $scope.alters = $scope.result.alters;
  8967. $scope.infos = $scope.result.infos;
  8968. $scope.myFiles[0] = "";
  8969. }).error(function(response) {
  8970. toaster.pop('error', response.data || response);
  8971. });
  8972. } else {
  8973. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  8974. }
  8975. }
  8976. };
  8977. // 查看范例
  8978. $scope.showImg = function() {
  8979. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  8980. box.show();
  8981. box.find('img').attr('src', src);
  8982. box.find('a').click(function(){
  8983. box.hide();
  8984. });
  8985. box.dblclick(function(){
  8986. box.hide();
  8987. });
  8988. };
  8989. // 下载模板
  8990. $scope.download = function() {
  8991. window.location.href = 'product/baseInfo/upload/template';
  8992. };
  8993. }]);
  8994. /**
  8995. * 物料详情
  8996. */
  8997. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService) {
  8998. BaseService.scrollBackToTop();
  8999. // 录入人
  9000. AuthenticationService.getAuthentication().success(function(data) {
  9001. $scope.loading = false;
  9002. $scope.user = data;
  9003. });
  9004. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9005. var loadData = function() {
  9006. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  9007. if(data.attach) {
  9008. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  9009. // 查看范例
  9010. $scope.showImg = function() {
  9011. var src = data.url, box = $('#image-box');
  9012. box.show();
  9013. box.find('img').attr('src', src);
  9014. box.find('a').click(function(){
  9015. box.hide();
  9016. });
  9017. box.dblclick(function(){
  9018. box.hide();
  9019. });
  9020. };
  9021. })
  9022. }
  9023. $scope.prodInfo = data;
  9024. $scope.prodInfo.$editing = false;
  9025. $scope.loading = false;
  9026. });
  9027. };
  9028. loadData();
  9029. $scope.isShow = true;
  9030. // 更新
  9031. $scope.update = function() {
  9032. $scope.prodInfo.$editing = true;
  9033. $scope.isShow = true;
  9034. };
  9035. // 取消
  9036. $scope.cancel = function() {
  9037. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  9038. $scope.prodInfo = data;
  9039. $scope.prodInfo.$editing = false;
  9040. $scope.isShow = false;
  9041. $scope.loading = false;
  9042. });
  9043. };
  9044. $scope.submit = function(prodInfo) {
  9045. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  9046. $upload.upload({
  9047. url: 'product/baseInfo/updateProdInfo',
  9048. file: file,
  9049. method: 'POST',
  9050. data: {
  9051. prodInfo: $scope.prodInfo
  9052. },
  9053. }).success(function(data) {
  9054. if(data.success) {
  9055. toaster.pop('success', '提示', data.success);
  9056. window.location.reload();
  9057. }
  9058. if(data.error) {
  9059. toaster.pop('error', '提示', data.error);
  9060. }
  9061. }).error(function(data) {
  9062. $scope.loadingShow = false;
  9063. toaster.pop('error', '操作失败', data.error);
  9064. });
  9065. }
  9066. $scope.previewShow = false;
  9067. $scope.pdfShow = false;
  9068. $scope.noneFileShow = true;
  9069. $scope.$watch('myFiles', function(){
  9070. if($scope.myFiles) {
  9071. $scope.noneFileShow = false;
  9072. var file = $scope.myFiles[0];
  9073. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  9074. $scope.pdfShow = true;
  9075. $scope.previewShow = false;
  9076. $scope.imgPreviewName = file.name;
  9077. } else{
  9078. if (typeof(Worker) !== "undefined") {//支持HTML5
  9079. $scope.imgPreview = getObjectURL(file);
  9080. $scope.imgPreviewName = file.name;
  9081. } else{//不支持HTML5
  9082. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  9083. $scope.imgPreviewName = file.name;
  9084. }
  9085. $scope.previewShow = true;
  9086. $scope.pdfShow = false;
  9087. }
  9088. } else {
  9089. $scope.noneFileShow = true;
  9090. $scope.previewShow = false;
  9091. $scope.pdfShow = false;
  9092. }
  9093. });
  9094. //建立一个可存取到该file的url
  9095. var getObjectURL = function(file) {
  9096. var url = null ;
  9097. if (window.createObjectURL!=undefined) { // basic
  9098. url = window.createObjectURL(file) ;
  9099. } else if (window.URL!=undefined) { // mozilla(firefox)
  9100. url = window.URL.createObjectURL(file) ;
  9101. } else if (window.webkitURL!=undefined) { // webkit or chrome
  9102. url = window.webkitURL.createObjectURL(file) ;
  9103. }
  9104. return url ;
  9105. };
  9106. }]);
  9107. /**
  9108. * 新增物料
  9109. */
  9110. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService) {
  9111. BaseService.scrollBackToTop();
  9112. // 录入人
  9113. AuthenticationService.getAuthentication().success(function(data) {
  9114. $scope.loading = false;
  9115. $scope.user = data;
  9116. });
  9117. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9118. $scope.prodInfo = {};
  9119. // 选择类目
  9120. $scope.selectKind = function(uuids) {
  9121. $modal.open({
  9122. animation: true,
  9123. size: 'lg',
  9124. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  9125. controller: 'KindChooseCtrl',
  9126. }).result.then(function(data){
  9127. $scope.kindId = data;
  9128. var modalInstance = $modal.open({
  9129. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  9130. controller: 'FindComponentCtrl',
  9131. size: 'lg',
  9132. resolve: {
  9133. KindId: function() {
  9134. return $scope.kindId;
  9135. }
  9136. }
  9137. });
  9138. modalInstance.result.then(function(data) {
  9139. $scope.prodInfo.cmpUuId = data.uuid;
  9140. $scope.prodInfo.cmpCode = data.code;
  9141. $scope.prodInfo.brand = data.brand.nameEn;
  9142. }, function(){
  9143. });
  9144. }, function(){
  9145. });
  9146. };
  9147. //提交
  9148. $scope.submit = function(prodInfo){
  9149. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  9150. $upload.upload({
  9151. url: 'product/baseInfo/addNewProduct',
  9152. file: file,
  9153. method: 'POST',
  9154. data: {
  9155. prodInfo: prodInfo
  9156. },
  9157. }).success(function(data) {
  9158. if(data.success) {
  9159. toaster.pop('success', '提示', data.success);
  9160. $timeout(function() {
  9161. //提交后跳转到详情页面,防止重复提交
  9162. window.location.href="#/sale/prodList/"+data.id;
  9163. }, 500);
  9164. }
  9165. if(data.error) {
  9166. toaster.pop('error', '提示', data.error);
  9167. $timeout(function() {
  9168. //提交后跳转到详情页面,防止重复提交
  9169. window.location.href="#/sale/prodList/"+data.id;
  9170. }, 500);
  9171. }
  9172. }).error(function(data) {
  9173. $scope.loadingShow = false;
  9174. toaster.pop('error', '操作失败', data.error);
  9175. });
  9176. };
  9177. $scope.previewShow = false;
  9178. $scope.pdfShow = false;
  9179. $scope.noneFileShow = true;
  9180. $scope.$watch('myFiles', function(){
  9181. if($scope.myFiles) {
  9182. $scope.noneFileShow = false;
  9183. var file = $scope.myFiles[0];
  9184. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  9185. $scope.pdfShow = true;
  9186. $scope.previewShow = false;
  9187. $scope.imgPreviewName = file.name;
  9188. } else{
  9189. if (typeof(Worker) !== "undefined") {//支持HTML5
  9190. $scope.imgPreview = getObjectURL(file);
  9191. $scope.imgPreviewName = file.name;
  9192. } else{//不支持HTML5
  9193. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  9194. $scope.imgPreviewName = file.name;
  9195. }
  9196. $scope.previewShow = true;
  9197. $scope.pdfShow = false;
  9198. }
  9199. } else {
  9200. $scope.noneFileShow = true;
  9201. $scope.previewShow = false;
  9202. $scope.pdfShow = false;
  9203. }
  9204. });
  9205. //建立一个可存取到该file的url
  9206. var getObjectURL = function(file) {
  9207. var url = null ;
  9208. if (window.createObjectURL!=undefined) { // basic
  9209. url = window.createObjectURL(file) ;
  9210. } else if (window.URL!=undefined) { // mozilla(firefox)
  9211. url = window.URL.createObjectURL(file) ;
  9212. } else if (window.webkitURL!=undefined) { // webkit or chrome
  9213. url = window.webkitURL.createObjectURL(file) ;
  9214. }
  9215. return url ;
  9216. };
  9217. // 取消
  9218. $scope.cancel = function(){
  9219. $scope.prodInfo = angular.copy($scope.prodInfo);
  9220. };
  9221. }]);
  9222. /**
  9223. * 类目选择模态框
  9224. */
  9225. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  9226. $scope.kindId = null;
  9227. $scope.kinds = [[], [], [], []];
  9228. // 获取子类目
  9229. var getChildren = function(pid, deep) {
  9230. KindAPI.getChildren({parentId: pid}, function(data) {
  9231. $scope.kinds[deep] = data;
  9232. }, function(response) {
  9233. toaster.pop('error', '获取子类目失败', response.data);
  9234. });
  9235. };
  9236. // 改变节点选中状态
  9237. var changeStatus = function(item, deep) {
  9238. var kindId = null, level = 0;
  9239. angular.forEach($scope.kinds, function(ks, i) {
  9240. if(i > deep) {
  9241. $scope.kinds[i] = [];
  9242. } else {
  9243. angular.forEach(ks, function(k, j) {
  9244. if(i == deep) {
  9245. if(k.id == item.id) {
  9246. $scope.kinds[i][j].$active = true;
  9247. kindId = k.id;
  9248. } else {
  9249. k.$active = null;
  9250. }
  9251. }
  9252. });
  9253. }
  9254. });
  9255. // 选择的节点
  9256. $scope.kindId = kindId;
  9257. $scope.active = item;
  9258. // 当前可操作的层级
  9259. if(deep < 3) {
  9260. $scope.activeDeep = deep + 1;
  9261. }
  9262. };
  9263. // 节点点击后获取子类目,节点被选中
  9264. $scope.onItemClick = function(item, deep) {
  9265. changeStatus(item, deep);
  9266. if (!item.isLeaf) {
  9267. getChildren(item.id, deep + 1);
  9268. }
  9269. };
  9270. // 重新加载数据
  9271. function reload(deep) {
  9272. var pid;
  9273. if(deep) {
  9274. pid = $scope.actives[deep - 1].id;
  9275. } else {
  9276. pid = 0;
  9277. deep = 0;
  9278. }
  9279. getChildren(pid, deep);
  9280. }
  9281. // 初始加载数据,获取第一层的类目
  9282. if($scope.actives) {
  9283. angular.forEach($scope.actives, function(v, k) {
  9284. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  9285. $scope.kinds[k] = data;
  9286. angular.forEach($scope.kinds[k], function(kind, i){
  9287. if(kind.id == v.id) {
  9288. $scope.kinds[k][i].$active = true;
  9289. $scope.actives[k] = $scope.kinds[k][i];
  9290. }
  9291. })
  9292. }, function(response) {
  9293. toaster.pop('error', '获取子类目失败', response.data);
  9294. });
  9295. });
  9296. } else {
  9297. reload();
  9298. }
  9299. // 取消
  9300. $scope.cancel = function() {
  9301. $modalInstance.dismiss();
  9302. };
  9303. // 确认选择
  9304. $scope.check = function() {
  9305. $modalInstance.close($scope.kindId);
  9306. };
  9307. }]);
  9308. /**
  9309. * 器件筛选
  9310. */
  9311. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  9312. //状态
  9313. $scope.setActive = function (state){
  9314. if($scope.active != state) {
  9315. $scope.active = state;
  9316. if($scope.tableParams.page() == 1)
  9317. $scope.tableParams.reload();
  9318. else
  9319. $scope.tableParams.page(1);
  9320. }
  9321. };
  9322. $scope.tableParams = new ngTableParams({
  9323. page : 1,
  9324. count : 10
  9325. }, {
  9326. total : 0,
  9327. counts: [5, 10, 25, 50],
  9328. getData : function($defer, params) {
  9329. $scope.loading = true;
  9330. var pageParams = params.url();
  9331. pageParams.keyword = $scope.keyword;
  9332. pageParams.kindId = KindId;
  9333. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  9334. $scope.loading = false;
  9335. if(page) {
  9336. params.total(page.totalElement);
  9337. $defer.resolve(page.content);
  9338. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9339. }
  9340. }, function(response){
  9341. $scope.loading = false;
  9342. toaster.pop('error', '数据加载失败', response.data);
  9343. });
  9344. }
  9345. });
  9346. // 取消
  9347. $scope.cancel = function() {
  9348. $modalInstance.dismiss();
  9349. };
  9350. // 选择
  9351. $scope.check = function(data){
  9352. $modalInstance.close(data);
  9353. };
  9354. // 搜索框回车
  9355. $scope.onSearch = function() {
  9356. $scope.tableParams.page(1);
  9357. $scope.tableParams.reload();
  9358. };
  9359. }]);
  9360. /**
  9361. * 企业列表
  9362. */
  9363. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  9364. BaseService.scrollBackToTop();
  9365. $scope.active = 'all';
  9366. $scope.agreedText = '全部';
  9367. $scope.dateZoneText = '一个月内';
  9368. $scope.condition = {dateZone: 1};
  9369. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9370. $scope.changeAgreed = function(agreed) {
  9371. $scope.condition.agreed = agreed;
  9372. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9373. $scope.condition.$agreedOpen = false;
  9374. };
  9375. $scope.changeDateZone = function(zone) {
  9376. $scope.condition.dateZone = zone;
  9377. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9378. $scope.condition.$dateZoneOpen = false;
  9379. getDateCondition(zone, $scope.condition);
  9380. $scope.tableParams.reload();
  9381. };
  9382. $scope.setActive = function(state) {
  9383. if($scope.active != state) {
  9384. $scope.active = state;
  9385. if($scope.tableParams.page() == 1)
  9386. $scope.tableParams.reload();
  9387. else
  9388. $scope.tableParams.page(1);
  9389. }
  9390. };
  9391. var getService = function() {
  9392. return getAccountUserSpace;
  9393. };
  9394. $scope.tableParams = new ngTableParams({
  9395. page : 1,
  9396. count : 5,
  9397. sorting: {
  9398. }
  9399. }, {
  9400. total : 0,
  9401. counts: [5, 10, 25, 50],
  9402. getData : function($defer, params) {
  9403. $scope.loading = true;
  9404. var pageParams = params.url();
  9405. pageParams.keyword = $scope.keyword;
  9406. $scope.tip = $scope.keyword;
  9407. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9408. $scope.loading = false;
  9409. if(page) {
  9410. params.total(page.totalElement);
  9411. $defer.resolve(page.content);
  9412. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9413. }
  9414. }, function(response) {
  9415. $scope.loading = false;
  9416. toaster.pop('error', '数据加载失败', response.data);
  9417. });
  9418. }
  9419. });
  9420. // 搜索框回车
  9421. $scope.onSearch = function() {
  9422. $scope.tableParams.page(1);
  9423. $scope.tableParams.reload();
  9424. };
  9425. // 添加合作关系
  9426. $scope.addPartner = function(name, businessCode) {
  9427. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  9428. if(data.success) {
  9429. toaster.pop("success", '添加成功', data.success);
  9430. }
  9431. if(data.error) {
  9432. toaster.pop("error", '添加失败', data.error);
  9433. }
  9434. }, function(response) {
  9435. toaster.pop('error','失败',response.data);
  9436. });
  9437. }
  9438. $scope.status = 'enList';
  9439. }]);
  9440. /**
  9441. * 新增采购单
  9442. */
  9443. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http) {
  9444. BaseService.scrollBackToTop();
  9445. // 每次进入时先清除掉rootScope下的venuu
  9446. $rootScope.venduu = null;
  9447. // 获取收货地址列表
  9448. ShipAddress.shipAddList({}, function(data) {
  9449. $scope.ships = data;
  9450. $scope.order.shipadd = $scope.ships[0];
  9451. });
  9452. // 获取地址信息
  9453. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9454. }).then(function(response) {
  9455. $scope.provinces = response.data;
  9456. });
  9457. $scope.order = {
  9458. date : new Date(),
  9459. cust : {
  9460. uu : '',
  9461. },
  9462. custUser : {
  9463. },
  9464. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  9465. orderItems : {
  9466. product : {},
  9467. },
  9468. rate: 17
  9469. };
  9470. //商品信息
  9471. $scope.order.orderItems = [];
  9472. var item = {
  9473. code: null,
  9474. title: null,
  9475. spec: null,
  9476. unit: null,
  9477. qty: null,
  9478. price: null,
  9479. remark: null,
  9480. delivery: null,
  9481. id: null,
  9482. };
  9483. if($rootScope.businessCode) {
  9484. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  9485. $scope.id = data.id;
  9486. $scope.order.cust.enName = data.vendorEnterprise.enName;
  9487. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  9488. $scope.order.cust.uu = data.vendorEnterprise.uu;
  9489. $scope.order.paymethods = data.paymethod;
  9490. $rootScope.venduu = data.vendorEnterprise.uu;
  9491. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9492. $scope.contacts = data;
  9493. $scope.order.vendor = $scope.contacts[0];
  9494. });
  9495. }, function(response) {
  9496. });
  9497. };
  9498. // 查找供应商
  9499. $scope.dbfindCust = function(){
  9500. var modalInstance = $modal.open({
  9501. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  9502. controller: 'DbfindVendorInfoCtrl',
  9503. size: 'lg',
  9504. resolve: {
  9505. orderItems: function() {
  9506. return $scope.order.orderItems;
  9507. }
  9508. }
  9509. });
  9510. modalInstance.result.then(function(data) {
  9511. $rootScope.venduu = data.vendorEnterprise.uu;
  9512. $scope.id = data.id;
  9513. $scope.order.cust = data.vendorEnterprise;
  9514. $scope.order.custUser = data.vendorUser;
  9515. $scope.order.payments = data.paymethod;
  9516. $scope.order.orderItems = [];
  9517. var item = {
  9518. code: null,
  9519. title: null,
  9520. spec: null,
  9521. unit: null,
  9522. qty: null,
  9523. price: null,
  9524. remark: null,
  9525. delivery: null,
  9526. };
  9527. // $scope.order.orderItems.push(item);
  9528. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9529. $scope.contacts = data;
  9530. $scope.order.vendor = $scope.contacts[0];
  9531. });
  9532. }, function(){
  9533. });
  9534. };
  9535. // 联想词 start
  9536. // 获取供应商
  9537. $scope.getSimilarVendors = function(value) {
  9538. if (value) {
  9539. return Vendor.getSimilarVendors({keyword : value}).$promise.then(function(data) {
  9540. return data.map(function(item) {
  9541. return item;
  9542. });
  9543. });
  9544. }
  9545. };
  9546. $scope.onAssociateCmpClick = function(vendor, order) {
  9547. $scope.order.cust.uu = vendor.venduu;
  9548. $scope.id = vendor.id;
  9549. $scope.order.payments = vendor.paymethod;
  9550. $rootScope.venduu = $scope.order.cust.uu;
  9551. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9552. $scope.contacts = data;
  9553. $scope.order.vendor = $scope.contacts[0];
  9554. });
  9555. }
  9556. // 联想词 end
  9557. // $scope.order.orderItems.push(item);
  9558. if($rootScope.prodId) {
  9559. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  9560. item.code = data.code;
  9561. item.title = data.title;
  9562. item.spec = data.spec;
  9563. item.unit = data.unit;
  9564. item.id = data.id;
  9565. $scope.order.orderItems.push(item);
  9566. $rootScope.prodId = null;// 清除掉prodId
  9567. }, function(response) {
  9568. });
  9569. }
  9570. //增加商品
  9571. $scope.addProduct = function(index) {
  9572. if($scope.order.orderItems[index].code == null) {
  9573. toaster.pop('info', '提示', '请先选择商品');
  9574. } else {
  9575. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null, $endDateOpen: false, rate: $scope.order.rate});
  9576. }
  9577. };
  9578. //删除商品
  9579. $scope.deleteProduct = function(index) {
  9580. $scope.order.orderItems.splice(index, 1);
  9581. };
  9582. // 搜索框回车
  9583. $scope.onSearch = function(keyword) {
  9584. $scope.keyword = keyword;
  9585. $scope.tableParams.page(1);
  9586. $scope.tableParams.reload();
  9587. };
  9588. $scope.tableParams = new ngTableParams({
  9589. page : 1,
  9590. count : 10
  9591. }, {
  9592. total : 0,
  9593. counts: [5, 10, 25, 50],
  9594. getData : function($defer, params) {
  9595. $scope.loading = true;
  9596. var pageParams = params.url();
  9597. pageParams.keyword = $scope.keyword;
  9598. $scope.tip = $scope.keyword;
  9599. pageParams.custUU = $scope.order.cust.uu;
  9600. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  9601. $scope.loading = false;
  9602. if(page) {
  9603. params.total(page.totalElement);
  9604. $scope.total = page.totalElement;
  9605. $defer.resolve(page.content);
  9606. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9607. }
  9608. }, function(response){
  9609. $scope.loading = false;
  9610. toaster.pop('error', '数据加载失败', response.data);
  9611. });
  9612. }
  9613. });
  9614. // 选择
  9615. $scope.check = function(data) {
  9616. $scope.order.orderItems.push({code: data.code, title: data.title, spec: data.spec, unit: data.unit, qty: null, price: null, remark: null, delivery: null, id: data.id, rate: $scope.order.rate});
  9617. };
  9618. // 导入商品信息
  9619. $scope.uplodaByBatch = function() {
  9620. var modalInstance = $modal.open({
  9621. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  9622. controller: 'PurcUploadByBatchCtrl',
  9623. size: 'lg',
  9624. resolve: {
  9625. }
  9626. });
  9627. modalInstance.result.then(function(data) {
  9628. angular.forEach(data, function(prod) {
  9629. $scope.order.orderItems.push({code: prod.code, title: data.title, unit: 'PCS', spec: prod.spec, qty: prod.amount, price: prod.price, remark: prod.remark, delivery: prod.date, id: prod.id, rate: prod.rate});
  9630. // for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  9631. // if($scope.order.orderItems[i].qty == null && $scope.order.orderItems[i].price == null && $scope.order.orderItems[i].qty == null && $scope.order.orderItems[i].delivery == null && $scope.order.orderItems[i].remark == null) { // 如果没有填写就删除这行数据
  9632. // $scope.inquiry.inquiryItems.splice(i, 1);
  9633. // }
  9634. // }
  9635. })
  9636. }, function(){
  9637. });
  9638. }
  9639. // 监听custuu发生变化,重新加载物料信息
  9640. $scope.$watch('order.cust.uu', function(n, o) {
  9641. if(n==o) {
  9642. return;
  9643. } else {
  9644. $scope.tableParams.page(1);
  9645. $scope.tableParams.reload();
  9646. }
  9647. }, true);
  9648. // 查找客户物料
  9649. $scope.dbfindCustProd = function(index){
  9650. if($scope.order.cust.uu) {
  9651. var modalInstance = $modal.open({
  9652. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  9653. controller: 'DbfindCustProdCtrl',
  9654. size: 'lg',
  9655. resolve: {
  9656. custUU: function() {
  9657. return $scope.order.cust.uu
  9658. }
  9659. }
  9660. });
  9661. modalInstance.result.then(function(data) {
  9662. $scope.order.orderItems.push(data);
  9663. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  9664. if($scope.order.orderItems[i].code == null || i == index) {
  9665. $scope.order.orderItems.splice(i, 1);
  9666. }
  9667. }
  9668. }, function() {
  9669. });
  9670. } else {
  9671. toaster.pop('info', '提示', '请先选择供应商');
  9672. }
  9673. };
  9674. $scope.getMinDate = function(item) {
  9675. return $filter('date')(new Date, 'yyyy-MM-dd');
  9676. };
  9677. $scope.openDatePicker = function($event, openParam, index) {
  9678. $event.preventDefault();
  9679. $event.stopPropagation();
  9680. $scope.order.orderItems[index].$endDateOpen = !openParam;
  9681. };
  9682. // 添加到购物车
  9683. $scope.addToCart = function(order) {
  9684. $scope.loading = true;
  9685. $scope.order.vendusertel = order.vendor.tel;
  9686. $scope.order.venduser = order.vendor.venduser;
  9687. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  9688. $scope.order.custUU = $scope.order.cust.uu;
  9689. $scope.order.custUserUU = $scope.order.custUser.userUU;
  9690. if($scope.order.date instanceof Date) {
  9691. $scope.order.date = $scope.order.date.getTime();
  9692. }
  9693. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  9694. if($scope.order.orderItems[i].delivery instanceof Date) {
  9695. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  9696. }
  9697. if($scope.order.currency != 'RMB') {
  9698. $scope.order.orderItems[i].rate = 0;
  9699. }
  9700. }
  9701. addtoCart.save({}, $scope.order, function(data){
  9702. $scope.loading = false;
  9703. toaster.pop('success', '成功', '保存成功');
  9704. window.location.hash = '#/purc/cart/'+data.id;
  9705. }, function(response){
  9706. $scope.loading = false;
  9707. toaster.pop('error', '保存失败', response.data);
  9708. });
  9709. };
  9710. // 立即购买
  9711. $scope.addToOrder = function(order) {
  9712. $scope.loading = true;
  9713. $scope.order.vendusertel = order.vendor.tel;
  9714. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  9715. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  9716. $scope.order.custUU = $scope.order.cust.uu;
  9717. $scope.order.custUserUU = $scope.order.custUser.userUU;
  9718. if($scope.order.date instanceof Date) {
  9719. $scope.order.date = $scope.order.date.getTime();
  9720. }
  9721. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  9722. if($scope.order.orderItems[i].delivery instanceof Date) {
  9723. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  9724. }
  9725. if($scope.order.currency != 'RMB') {
  9726. $scope.order.orderItems[i].rate = 0;
  9727. }
  9728. }
  9729. newPurcOrder.save({}, $scope.order, function(data){
  9730. $scope.loading = false;
  9731. toaster.pop('success', '成功', '保存成功');
  9732. window.location.hash = '#/purc/order/'+data.id;
  9733. }, function(response){
  9734. $scope.loading = false;
  9735. toaster.pop('error', '保存失败', response.data);
  9736. });
  9737. };
  9738. // 新增收货地址保存
  9739. $scope.saveShipAddress = function(ship) {
  9740. ship.address = ship.province + ship.city + ship.district;
  9741. ShipAddress.saveAddress( {}, ship, function(data) {
  9742. if(data.success) {
  9743. ShipAddress.shipAddList({}, function(data) {
  9744. $scope.ships = data;
  9745. $scope.order.shipadd = $scope.ships[0];
  9746. });
  9747. toaster.pop('success', '提示', data.success);
  9748. }
  9749. if(data.error) {
  9750. toaster.pop('error', '提示', data.error);
  9751. }
  9752. });
  9753. }
  9754. // 新增供应商联系人
  9755. $scope.addContact = function(uu) {
  9756. var modalInstance = $modal.open({
  9757. animation: true,
  9758. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  9759. controller: 'AddContacCtrl',
  9760. resolve: {
  9761. }
  9762. });
  9763. modalInstance.result.then(function(data) {
  9764. $scope.contact = data;
  9765. $scope.contact.venduu = uu;
  9766. Vendor.saveContact({}, $scope.contact, function(data) {
  9767. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9768. $scope.contacts = data;
  9769. $scope.order.vendor = $scope.contacts[0];
  9770. });
  9771. toaster.pop('success', '提示', '联系人保存成功');
  9772. }, function(response) {
  9773. toaster.pop('error', '失败', response.data);
  9774. });
  9775. });
  9776. }
  9777. }]);
  9778. /**
  9779. * 采购批量导入
  9780. */
  9781. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  9782. // 通过excel批量上传物料
  9783. $scope.result = null;
  9784. $scope.upload = function() {
  9785. var file = $scope.myFiles[0];
  9786. $upload.upload({
  9787. url: 'purchase/release/excel',
  9788. file: file,
  9789. method: 'POST'
  9790. }).success(function(data) {
  9791. $scope.result = data;
  9792. $scope.success = $scope.result.success;
  9793. $scope.total = $scope.result.total;
  9794. $scope.alters = $scope.result.alters;
  9795. }).error(function(response) {
  9796. toaster.pop('error', response.data || response);
  9797. });
  9798. };
  9799. // 下载模板
  9800. $scope.download = function() {
  9801. window.location.href = 'purchase/upload/template';
  9802. };
  9803. $scope.enSure = function() {
  9804. $modalInstance.close($scope.result.products);
  9805. }
  9806. $scope.cancel = function() {
  9807. $modalInstance.dismiss();
  9808. }
  9809. }]);
  9810. // 查找供应商
  9811. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  9812. $scope.prod = false;
  9813. if(orderItems.length != 0) {
  9814. $scope.prod = true;
  9815. }
  9816. BaseService.scrollBackToTop();
  9817. if($rootScope.venduu != null) {
  9818. $scope.venduu = $rootScope.venduu;
  9819. }
  9820. // 搜索框回车
  9821. $scope.onSearch = function(keyword) {
  9822. $scope.keyword = keyword;
  9823. $scope.customerParams.page(1);
  9824. $scope.customerParams.reload();
  9825. };
  9826. $scope.customerParams = new ngTableParams({
  9827. page : 1,
  9828. count : 10
  9829. }, {
  9830. total : 0,
  9831. counts: [5, 10, 25, 50],
  9832. getData : function($defer, params) {
  9833. $scope.loading = true;
  9834. var pageParams = params.url();
  9835. pageParams.keyword = $scope.keyword;
  9836. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  9837. $scope.loading = false;
  9838. if(page) {
  9839. params.total(page.totalElements);
  9840. $defer.resolve(page.content);
  9841. }
  9842. $scope.totalCount = page.totalElements;
  9843. }, function(response){
  9844. $scope.loading = false;
  9845. toaster.pop('error', '数据加载失败', response.data);
  9846. });
  9847. }
  9848. });
  9849. $scope.cancel = function() {
  9850. $modalInstance.dismiss();
  9851. };
  9852. $scope.ensure = false;
  9853. $scope.check = function(vendor) { // 需要进行判断的选择
  9854. $scope.vendorInfo = vendor;
  9855. $scope.ensure = true;
  9856. };
  9857. $scope.checkVendor = function(vendor) { // 直接选择
  9858. $modalInstance.close(vendor);
  9859. }
  9860. }]);
  9861. /**
  9862. * 我的客户
  9863. */
  9864. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  9865. $scope.userInfoResult = true;
  9866. AuthenticationService.getAuthentication().success(function(data) {
  9867. $scope.loading = false;
  9868. $scope.thisUser = data;
  9869. });
  9870. var getCustInfos = function(custuu) {
  9871. if(custuu) {
  9872. VendorService.userInfo.query({uu:custuu},null,function(data) {
  9873. $scope.custInfos = data;
  9874. var getPage = function(page, size){
  9875. if($scope.custInfos) {
  9876. var result = {};
  9877. result.totalCount = $scope.custInfos.length;
  9878. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  9879. if($scope.custInfos.length % size == 0) {
  9880. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  9881. }else {
  9882. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  9883. }
  9884. result.first = page == 1;
  9885. result.last = page == result.totalPage;
  9886. result.page = page;
  9887. result.next = page - 0 + 1;
  9888. result.pre = page - 1;
  9889. return result;
  9890. }
  9891. }
  9892. $scope.userdata = getPage(1,4);
  9893. $scope.first = function (){
  9894. $scope.userdata = getPage($scope.userdata.pre,4);
  9895. }
  9896. $scope.last = function (){
  9897. $scope.userdata = getPage($scope.userdata.next,4);
  9898. }
  9899. }, function(response){
  9900. $scope.loading = false;
  9901. toaster.pop('error', '数据加载失败', response.data);
  9902. });
  9903. }
  9904. }
  9905. $scope.addUserInfo = function(customer) {
  9906. //TODO
  9907. if ($scope.thisUser.sys) {
  9908. var modalInstance = $modal.open({
  9909. animation: true,
  9910. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  9911. controller: 'AddUserInfoCtrl',
  9912. resolve: {
  9913. customer: function() {
  9914. return customer;
  9915. }
  9916. }
  9917. });
  9918. modalInstance.result.then(function(changed, checked){
  9919. if(changed) {
  9920. if(checked)
  9921. $scope.newUser.roles = checked;
  9922. else
  9923. loadUsers();
  9924. }
  9925. });
  9926. } else {
  9927. toaster.pop('error', '您不是管理员,无权限分配用户!');
  9928. }
  9929. }
  9930. $scope.showUserInfo = function(customer,boo) {
  9931. $scope.custInfo = customer;
  9932. if(boo) {
  9933. getCustInfos(customer.myEnterprise.uu);
  9934. $scope.userInfoResult = true;
  9935. }
  9936. }
  9937. $scope.customerParams = new ngTableParams({
  9938. page : 1,
  9939. count : 10
  9940. }, {
  9941. total : 0,
  9942. counts: [5, 10, 25, 50],
  9943. getData : function($defer, params) {
  9944. $scope.loading = true;
  9945. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  9946. $scope.loading = false;
  9947. if(page) {
  9948. params.total(page.totalElements);
  9949. $defer.resolve(page.content);
  9950. }
  9951. $scope.totalCount = page.totalElements;
  9952. }, function(response){
  9953. $scope.loading = false;
  9954. toaster.pop('error', '数据加载失败', response.data);
  9955. });
  9956. }
  9957. });
  9958. }]);
  9959. /**
  9960. * 我的供应商
  9961. */
  9962. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  9963. BaseService.scrollBackToTop();
  9964. // 搜索框回车
  9965. $scope.onSearch = function(keyword) {
  9966. $scope.keyword = keyword;
  9967. $scope.customerParams.page(1);
  9968. $scope.customerParams.reload();
  9969. };
  9970. $scope.customerParams = new ngTableParams({
  9971. page : 1,
  9972. count : 10
  9973. }, {
  9974. total : 0,
  9975. counts: [5, 10, 25, 50],
  9976. getData : function($defer, params) {
  9977. $scope.loading = true;
  9978. var pageParams = params.url();
  9979. pageParams.keyword = $scope.keyword;
  9980. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  9981. $scope.loading = false;
  9982. if(page) {
  9983. params.total(page.totalElement);
  9984. $scope.total = page.totalElement;
  9985. $defer.resolve(page.content);
  9986. }
  9987. $scope.totalCount = page.totalElements;
  9988. }, function(response){
  9989. $scope.loading = false;
  9990. toaster.pop('error', '数据加载失败', response.data);
  9991. });
  9992. }
  9993. });
  9994. // 查看供应商详情
  9995. $scope.VendorDetail = function(id, uu) {
  9996. $rootScope.vendorId = id;
  9997. $rootScope.vendoruu = uu;
  9998. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  9999. }
  10000. // 向企业购买
  10001. $scope.purcByEn = function(businessCode) {
  10002. $rootScope.businessCode = businessCode;
  10003. window.location.hash = "#/purc/addOrder";
  10004. }
  10005. }]);
  10006. /**
  10007. * 供应商详情
  10008. */
  10009. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  10010. BaseService.scrollBackToTop();
  10011. $scope.vendorContacts = [];
  10012. var loadData = function() {
  10013. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  10014. $scope.vendor = data.vendorEnterprise;
  10015. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  10016. $scope.vendorContacts = data;
  10017. });
  10018. });
  10019. };
  10020. loadData();
  10021. // 新增供应商联系人
  10022. $scope.addContact = function(uu) {
  10023. var modalInstance = $modal.open({
  10024. animation: true,
  10025. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10026. controller: 'AddContacCtrl',
  10027. resolve: {
  10028. }
  10029. });
  10030. modalInstance.result.then(function(data) {
  10031. $scope.contact = data;
  10032. $scope.contact.venduu = uu;
  10033. Vendor.saveContact({}, $scope.contact, function(data) {
  10034. toaster.pop('success', '提示', '联系人保存成功');
  10035. $scope.vendorContacts.push(data);
  10036. }, function(response) {
  10037. toaster.pop('error', '失败', response.data);
  10038. });
  10039. });
  10040. };
  10041. // 编辑供应商联系人
  10042. $scope.edit = function(contact) {
  10043. var modalInstance = $modal.open({
  10044. animation: true,
  10045. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10046. controller: 'EditContacCtrl',
  10047. resolve: {
  10048. contact: function() {
  10049. return contact;
  10050. }
  10051. }
  10052. });
  10053. modalInstance.result.then(function(data) {
  10054. $scope.contact = data;
  10055. Vendor.saveContact({}, $scope.contact, function(data) {
  10056. toaster.pop('success', '提示', '联系人修改成功');
  10057. }, function(response) {
  10058. toaster.pop('error', '失败', response.data);
  10059. });
  10060. });
  10061. }
  10062. // 删除供应商联系人
  10063. $scope.deleteById = function(id, index) {
  10064. $scope.vendorContacts.splice(index, 1);
  10065. Vendor.deleteContact({id: id}, {}, function(data) {
  10066. toaster.pop('success', '提示', '供应商联系人删除成功');
  10067. loadData();
  10068. }, function(response) {
  10069. toaster.pop('error', '提示', response.data);
  10070. });
  10071. }
  10072. // 供应商物料信息
  10073. $scope.viewProdList = function(uu){
  10074. $scope.uu = uu;
  10075. $scope.tableParams.page(1);
  10076. $scope.tableParams.reload();
  10077. };
  10078. // 搜索框回车
  10079. $scope.onSearch = function(keyword) {
  10080. $scope.keyword = keyword;
  10081. $scope.tableParams.page(1);
  10082. $scope.tableParams.reload();
  10083. };
  10084. // 供应商物料信息
  10085. $scope.tableParams = new ngTableParams({
  10086. page : 1,
  10087. count : 10
  10088. }, {
  10089. total : 0,
  10090. counts: [5, 10, 25, 50],
  10091. getData : function($defer, params) {
  10092. $scope.loading = true;
  10093. var pageParams = params.url();
  10094. pageParams.custUU = $scope.uu;
  10095. pageParams.keyword = $scope.keyword;
  10096. $scope.tip = $scope.keyword;
  10097. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  10098. $scope.loading = false;
  10099. if(page) {
  10100. params.total(page.totalElement);
  10101. $scope.total = page.totalElement;
  10102. $defer.resolve(page.content);
  10103. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10104. }
  10105. }, function(response){
  10106. $scope.loading = false;
  10107. toaster.pop('error', '数据加载失败', response.data);
  10108. });
  10109. }
  10110. });
  10111. /**
  10112. * 选中单个物料购买
  10113. * @param businessCode
  10114. * @param id
  10115. */
  10116. $scope.PurcByEnAndProd = function(businessCode, id) {
  10117. $rootScope.businessCode = businessCode;
  10118. $rootScope.prodId = id;
  10119. window.location.hash = "#/purc/addOrder";
  10120. }
  10121. /**
  10122. * 询价
  10123. */
  10124. $scope.PurcInquiry = function(businessCode, id){
  10125. $rootScope.prodId = id;
  10126. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  10127. }
  10128. }]);
  10129. /**
  10130. * 编辑供应商联系人
  10131. */
  10132. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  10133. $scope.contact = contact;
  10134. $scope.save = function(contact) {
  10135. $modalInstance.close(contact);
  10136. }
  10137. $scope.cancel = function() {
  10138. $modalInstance.dismiss();
  10139. }
  10140. }]);
  10141. /**
  10142. * 新增供应商联系人
  10143. */
  10144. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  10145. $scope.save = function(contact) {
  10146. $modalInstance.close(contact);
  10147. }
  10148. $scope.cancel = function() {
  10149. $modalInstance.dismiss();
  10150. }
  10151. }]);
  10152. /**
  10153. * 建立合作关系申请
  10154. */
  10155. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo) {
  10156. BaseService.scrollBackToTop();
  10157. $scope.status = "partner";
  10158. $scope.active = 'all';
  10159. var getRequestStatus = function(active) {
  10160. var fn = 'getAllRequest';
  10161. switch(active) {
  10162. case 'done':
  10163. fn = 'getRequestDone';break;
  10164. case 'todo':
  10165. fn = 'getRequestTodo';break;
  10166. case 'end':
  10167. fn = 'getRequestEnd';break;
  10168. }
  10169. return fn;
  10170. }
  10171. // 切换单据类型
  10172. $scope.setActive = function(state) {
  10173. if($scope.active != state) {
  10174. $scope.active = state;
  10175. if($scope.tableParams.page() == 1)
  10176. $scope.tableParams.reload();
  10177. else
  10178. $scope.tableParams.page(1);
  10179. }
  10180. };
  10181. // 切换数据来源(正常数据 or 历史数据)
  10182. var getService = function() {
  10183. return AddPartnerMyRequest;
  10184. };
  10185. $scope.tableParams = new ngTableParams({ // ng-Table参数
  10186. page : 1,
  10187. count : 10,
  10188. sorting: {
  10189. }
  10190. }, {
  10191. total : 0,
  10192. counts: [],
  10193. getData : function($defer, params) { // 获取数据的方法
  10194. $scope.loading = true;
  10195. var pageParams = params.url();
  10196. pageParams.keyword = $scope.keyword;
  10197. if($rootScope.vendName) {
  10198. pageParams.keyword = $rootScope.vendName;
  10199. $scope.keyword = $rootScope.vendName;
  10200. $rootScope.vendName = null;
  10201. }
  10202. $scope.tip = $scope.keyword;
  10203. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10204. $scope.loading = false;
  10205. if(page) {
  10206. params.total(page.totalElement);
  10207. $defer.resolve(page.content);
  10208. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10209. }
  10210. }, function(response){
  10211. $scope.loading = false;
  10212. toaster.pop('error', '数据加载失败', response.data);
  10213. });
  10214. }
  10215. });
  10216. // 再次申请
  10217. $scope.reapply = function(id) {
  10218. AddPartner.reapply({id: id}, {}, function(data) {
  10219. toaster.pop('success', '提示', '操作成功');
  10220. }, function(response) {
  10221. toaster.pop('error','失败',response.data);
  10222. });
  10223. }
  10224. // 添加为供应商
  10225. $scope.addSupplier = function(vendUID) {
  10226. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  10227. if(data.success) {
  10228. toaster.pop('success', '提示', data.success);
  10229. }
  10230. if(data.error) {
  10231. toaster.pop('error','提示', data.error);
  10232. }
  10233. }, function(response) {
  10234. toaster.pop('error', '失败', response.data);
  10235. })
  10236. };
  10237. // 添加客户
  10238. $scope.addCust = function(vendUID) {
  10239. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  10240. if(data.success) {
  10241. toaster.pop('success', '提示', data.success);
  10242. }
  10243. if(data.error) {
  10244. toaster.pop('error','提示', data.error);
  10245. }
  10246. }, function(response) {
  10247. toaster.pop('error', '失败', response.data);
  10248. })
  10249. };
  10250. // 搜索框回车
  10251. $scope.onSearch = function() {
  10252. $scope.tableParams.page(1);
  10253. $scope.tableParams.reload();
  10254. };
  10255. // 同意申请
  10256. $scope.agree = function(id) {
  10257. AddPartner.agreeRequest({id: id}, {}, function(data) {
  10258. toaster.pop('success', '提示', '操作成功');
  10259. $timeout(function() {
  10260. window.location.reload();
  10261. }, 500);
  10262. }, function(response) {
  10263. toaster.pop('error', '提示', response.data);
  10264. });
  10265. }
  10266. // 拒绝申请
  10267. $scope.refuse = function(id, reason) {
  10268. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  10269. toaster.pop('success', '提示', '操作成功');
  10270. $timeout(function() {
  10271. window.location.reload();
  10272. }, 500);
  10273. }, function(response) {
  10274. toaster.pop('error', '提示', response.data);
  10275. });
  10276. }
  10277. // 取消供应商关系
  10278. $scope.relieve = function(id) {
  10279. VendorInfo.relieve({id: id}, {}, function(data) {
  10280. if(data.success) {
  10281. toaster.pop('success', '提示', data.success);
  10282. }
  10283. $scope.tableParams.page(1);
  10284. $scope.tableParams.reload();
  10285. }, function(response) {
  10286. toaster.pop('error', '提示', response.data);
  10287. });
  10288. }
  10289. // 建立供应商关系
  10290. $scope.activeVend = function(id) {
  10291. VendorInfo.activeVend({id: id}, {}, function(data) {
  10292. if(data.success) {
  10293. toaster.pop('success', '提示', data.success);
  10294. }
  10295. $scope.tableParams.page(1);
  10296. $scope.tableParams.reload();
  10297. }, function(response) {
  10298. toaster.pop('error', '提示', response.data);
  10299. });
  10300. }
  10301. // 取消客户关系
  10302. $scope.disableCust = function(id) {
  10303. VendorInfo.disableCust({id: id}, {}, function(data) {
  10304. if(data.success) {
  10305. toaster.pop('success', '提示', data.success);
  10306. }
  10307. $scope.tableParams.page(1);
  10308. $scope.tableParams.reload();
  10309. }, function(response) {
  10310. toaster.pop('error', '提示', response.data);
  10311. });
  10312. }
  10313. // 激活客户关系
  10314. $scope.activeCust = function(id) {
  10315. VendorInfo.activeCust({id: id}, {}, function(data) {
  10316. if(data.success) {
  10317. toaster.pop('success', '提示', data.success);
  10318. }
  10319. $scope.tableParams.page(1);
  10320. $scope.tableParams.reload();
  10321. }, function(response) {
  10322. toaster.pop('error', '提示', response.data);
  10323. });
  10324. }
  10325. }]);
  10326. /**
  10327. * 建立合作关系处理申请
  10328. */
  10329. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  10330. BaseService.scrollBackToTop();
  10331. $scope.active = 'todo';
  10332. var getMessagetStatus = function(active) {
  10333. var fn = 'getAllMessage';
  10334. switch(active) {
  10335. case 'done':
  10336. fn = 'getMessageDone';break;
  10337. case 'todo':
  10338. fn = 'getMessageTodo';break;
  10339. case 'end':
  10340. fn = 'getMessageEnd';break;
  10341. }
  10342. return fn;
  10343. }
  10344. // 切换单据类型
  10345. $scope.setActive = function(state) {
  10346. if($scope.active != state) {
  10347. $scope.active = state;
  10348. if($scope.tableParams.page() == 1)
  10349. $scope.tableParams.reload();
  10350. else
  10351. $scope.tableParams.page(1);
  10352. }
  10353. };
  10354. var getService = function() {
  10355. return AddPartnerMyMessage;
  10356. };
  10357. $scope.tableParams = new ngTableParams({ // ng-Table参数
  10358. page : 1,
  10359. count : 5,
  10360. sorting: {
  10361. }
  10362. }, {
  10363. total : 0,
  10364. counts: [5, 10, 15, 25, 50],
  10365. getData : function($defer, params) { // 获取数据的方法
  10366. $scope.loading = true;
  10367. var pageParams = params.url();
  10368. pageParams.searchFilter = { // 筛选条件
  10369. keyword: $scope.keyword,
  10370. };
  10371. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10372. $scope.loading = false;
  10373. if(page) {
  10374. params.total(page.totalElement);
  10375. $defer.resolve(page.content);
  10376. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10377. }
  10378. }, function(response){
  10379. $scope.loading = false;
  10380. toaster.pop('error', '数据加载失败', response.data);
  10381. });
  10382. }
  10383. });
  10384. // 同意申请
  10385. $scope.agree = function(id) {
  10386. AddPartner.agreeRequest({id: id}, {}, function(data) {
  10387. toaster.pop('success', '提示', '操作成功');
  10388. }, function(response) {
  10389. toaster.pop('error', '提示', response.data);
  10390. });
  10391. }
  10392. // 拒绝申请
  10393. $scope.refuse = function(id, reason) {
  10394. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  10395. toaster.pop('success', '提示', '操作成功');
  10396. }, function(response) {
  10397. toaster.pop('error', '提示', response.data);
  10398. });
  10399. }
  10400. $scope.status = 'get';
  10401. }]);
  10402. /**
  10403. * 我的合作伙伴
  10404. */
  10405. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  10406. BaseService.scrollBackToTop();
  10407. // 默认显示合作伙伴
  10408. $scope.status = 'news';
  10409. // 获取所有的合作伙伴
  10410. GetProductInfo.getAllPartners({}, function(data) {
  10411. $scope.partners = data;
  10412. }, function(res) {
  10413. toaster.pop('error', '获取列表失败', res.data);
  10414. });
  10415. // 添加为客户
  10416. $scope.addCust = function(partner) {
  10417. GetProductInfo.addCust({}, partner, function(data) {
  10418. toaster.pop('success', '提示', '添加客户成功');
  10419. }, function(response) {
  10420. toaster.pop('error', '添加客户失败', response.data);
  10421. });
  10422. }
  10423. // 添加为供应商
  10424. $scope.addSupplier = function(partner) {
  10425. GetProductInfo.addSupplier({}, partner, function(data) {
  10426. toaster.pop('success', '提示', '添加供应商成功');
  10427. }, function(response) {
  10428. toaster.pop('error', '添加供应商失败', response.data);
  10429. });
  10430. }
  10431. }]);
  10432. /**
  10433. * 财务对账时,企业进行筛选操作
  10434. */
  10435. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  10436. var getData = function(){
  10437. $scope.loading = true;
  10438. FaApCheck.getAllCustomers(function(data) {
  10439. $scope.custs = data;
  10440. $scope.loading = false;
  10441. });
  10442. };
  10443. getData();
  10444. $scope.select = function(suuorname) {
  10445. $modalInstance.close(suuorname);
  10446. }
  10447. $scope.close = function() {
  10448. $modalInstance.close();
  10449. }
  10450. }]);
  10451. /**
  10452. * 跳转到企业圈
  10453. */
  10454. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  10455. GetProductInfo.businessGroups({}, function(data) {
  10456. window.open(data.url);
  10457. }, function(response) {
  10458. toaster.pop('error', '提示', response.data);
  10459. });
  10460. }]);
  10461. /**
  10462. * 购物车
  10463. */
  10464. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  10465. BaseService.scrollBackToTop();
  10466. $scope.active = 'all';
  10467. $scope.agreedText = '全部';
  10468. $scope.dateZoneText = '一个月内';
  10469. $scope.condition = {dateZone: 1};
  10470. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10471. $scope.changeAgreed = function(agreed) {
  10472. $scope.condition.agreed = agreed;
  10473. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  10474. $scope.condition.$agreedOpen = false;
  10475. };
  10476. $scope.changeDateZone = function(zone) {
  10477. $scope.condition.dateZone = zone;
  10478. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  10479. $scope.condition.$dateZoneOpen = false;
  10480. getDateCondition(zone, $scope.condition);
  10481. $scope.tableParams.reload();
  10482. };
  10483. $scope.setActive = function(state) {
  10484. if($scope.active != state) {
  10485. $scope.active = state;
  10486. if($scope.tableParams.page() == 1)
  10487. $scope.tableParams.reload();
  10488. else
  10489. $scope.tableParams.page(1);
  10490. }
  10491. };
  10492. var getService = function() {
  10493. return getCartList;
  10494. };
  10495. $scope.tableParams = new ngTableParams({
  10496. page : 1,
  10497. count : 5,
  10498. sorting: {
  10499. date: 'desc',
  10500. }
  10501. }, {
  10502. total : 0,
  10503. counts: [5, 10, 25, 50],
  10504. getData : function($defer, params) {
  10505. $scope.loading = true;
  10506. var pageParams = params.url();
  10507. pageParams.keyword = $scope.keyword;
  10508. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  10509. $scope.loading = false;
  10510. if(page) {
  10511. params.total(page.totalElements);
  10512. $defer.resolve(page.content);
  10513. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10514. }
  10515. }, function(response) {
  10516. $scope.loading = false;
  10517. toaster.pop('error', '数据加载失败', response.data);
  10518. });
  10519. }
  10520. });
  10521. $scope.getCartTotal = function(items) {
  10522. var sum = 0;
  10523. angular.forEach(items, function(item){
  10524. sum += item.qty * item.price;
  10525. });
  10526. return sum;
  10527. };
  10528. // 搜索框回车
  10529. $scope.onSearch = function() {
  10530. $scope.tableParams.page(1);
  10531. $scope.tableParams.reload();
  10532. };
  10533. // 提交
  10534. $scope.addtoOrder = function(id) {
  10535. cartOperation.addToOrder({id: id}, {}, function(data) {
  10536. if(data.success) {
  10537. toaster.pop('success', '提示', data.success);
  10538. $timeout(function() {
  10539. window.location.hash = '#/purc/order/'+data.id;
  10540. },500);
  10541. }
  10542. if(data.error) {
  10543. toaster.pop('error', '提示', data.error);
  10544. }
  10545. }, function(response) {
  10546. toaster.pop('erroer', '提示', response.data);
  10547. });
  10548. };
  10549. // 删除一条主记录
  10550. $scope.deleteCart = function(id) {
  10551. cartOperation.deleteCart({id: id}, {}, function(data) {
  10552. if(data.success) {
  10553. toaster.pop('success', '提示', data.success);
  10554. $timeout(function() {
  10555. window.location.reload();
  10556. },500);
  10557. }
  10558. if(data.error) {
  10559. toaster.pop('error', '提示', data.error);
  10560. }
  10561. }, function(response) {
  10562. toaster.pop('erroer', '提示', response.data);
  10563. });
  10564. };
  10565. // 删除一条明细
  10566. $scope.deleteDetail = function(id) {
  10567. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  10568. if(data.success) {
  10569. toaster.pop('success', '提示', data.success);
  10570. $timeout(function() {
  10571. window.location.reload();
  10572. },500);
  10573. }
  10574. if(data.error) {
  10575. toaster.pop('error', '提示', data.error);
  10576. }
  10577. }, function(response) {
  10578. toaster.pop('erroer', '提示', response.data);
  10579. });
  10580. };
  10581. // 清空购物车
  10582. $scope.clearCart = function() {
  10583. cartOperation.deleteCarts({}, function(data) {
  10584. if(data.success) {
  10585. toaster.pop('success', '提示', data.success);
  10586. $timeout(function() {
  10587. window.location.reload();
  10588. },500);
  10589. }
  10590. if(data.error) {
  10591. toaster.pop('error', '提示', data.error);
  10592. }
  10593. }, function(response) {
  10594. toaster.pop('erroer', '提示', response.data);
  10595. });
  10596. }
  10597. }]);
  10598. /**
  10599. * 购物车详情
  10600. */
  10601. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  10602. BaseService.scrollBackToTop();
  10603. var loadData = function() {
  10604. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  10605. if(data.code) {
  10606. $scope.cart = data;
  10607. var sum = 0;
  10608. angular.forEach($scope.cart.cartDetails, function(item) {
  10609. sum += item.qty * item.price;
  10610. });
  10611. $scope.cart.total = sum;
  10612. $scope.loading = false;
  10613. } else {
  10614. window.location.hash = '#/purc/cart';
  10615. }
  10616. });
  10617. };
  10618. loadData();
  10619. // 删除一条明细
  10620. $scope.deleteDetail = function(id) {
  10621. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  10622. if(data.success) {
  10623. toaster.pop('success', '提示', data.success);
  10624. $timeout(function() {
  10625. window.location.reload();
  10626. },500);
  10627. }
  10628. if(data.error) {
  10629. toaster.pop('error', '提示', data.error);
  10630. }
  10631. }, function(response) {
  10632. toaster.pop('erroer', '提示', response.data);
  10633. });
  10634. };
  10635. // 删除一条主记录
  10636. $scope.deleteCart = function(id) {
  10637. cartOperation.deleteCart({id: id}, {}, function(data) {
  10638. if(data.success) {
  10639. toaster.pop('success', '提示', data.success);
  10640. $timeout(function() {
  10641. window.location.reload();
  10642. },500);
  10643. }
  10644. if(data.error) {
  10645. toaster.pop('error', '提示', data.error);
  10646. }
  10647. }, function(response) {
  10648. toaster.pop('erroer', '提示', response.data);
  10649. });
  10650. };
  10651. // 提交
  10652. $scope.addtoOrder = function(id) {
  10653. cartOperation.addToOrder({id: id}, {}, function(data) {
  10654. if(data.success) {
  10655. toaster.pop('success', '提示', data.success);
  10656. $timeout(function() {
  10657. window.location.hash = '#/purc/order/'+data.id;
  10658. },500);
  10659. }
  10660. if(data.error) {
  10661. toaster.pop('error', '提示', data.error);
  10662. }
  10663. }, function(response) {
  10664. toaster.pop('erroer', '提示', response.data);
  10665. });
  10666. };
  10667. }]);
  10668. /**
  10669. * 审批流
  10670. */
  10671. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  10672. BaseService.scrollBackToTop();
  10673. $scope.vacation = false;
  10674. $scope.workovertime = false;
  10675. $scope.workdaily = false;
  10676. $scope.feeplease = false;
  10677. $scope.signapp = false;
  10678. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  10679. $scope.nodes = data;
  10680. angular.forEach($scope.nodes, function(node) {
  10681. if(node.appname = '请假单') {
  10682. $scope.vacation = true;
  10683. }
  10684. if(node.appname = '加班单') {
  10685. $scope.workovertime = true;
  10686. }
  10687. if(node.appname = '工作日报') {
  10688. $scope.workdaily = true;
  10689. }
  10690. if(node.appname = '出差单') {
  10691. $scope.feeplease = true;
  10692. }
  10693. if(node.appname = '申诉单') {
  10694. $scope.signapp = true;
  10695. }
  10696. });
  10697. }, function(response) {
  10698. });
  10699. $scope.NoteSet = function() {
  10700. var modalInstance = $modal.open({
  10701. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10702. controller: 'NoteStep1Ctrl',
  10703. size: 'lg',
  10704. resolve: {
  10705. AppName: function() {
  10706. return '请假单';
  10707. }
  10708. }
  10709. });
  10710. modalInstance.result.then(function(data) {
  10711. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10712. if(data.error) {
  10713. toaster.pop('error', '提示', data.error);
  10714. }
  10715. if(data.success) {
  10716. toaster.pop('success', '提示', data.success);
  10717. }
  10718. }, function(response) {
  10719. });
  10720. }, function(){
  10721. });
  10722. }
  10723. $scope.overTimeSet = function() {
  10724. var modalInstance = $modal.open({
  10725. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10726. controller: 'NoteStep1Ctrl',
  10727. size: 'lg',
  10728. resolve: {
  10729. AppName: function() {
  10730. return '加班单';
  10731. }
  10732. }
  10733. });
  10734. modalInstance.result.then(function(data) {
  10735. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10736. if(data.error) {
  10737. toaster.pop('error', '提示', data.error);
  10738. }
  10739. if(data.success) {
  10740. toaster.pop('success', '提示', data.success);
  10741. }
  10742. }, function(response) {
  10743. });
  10744. }, function(){
  10745. });
  10746. }
  10747. $scope.feePleaseSet = function() {
  10748. var modalInstance = $modal.open({
  10749. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10750. controller: 'NoteStep1Ctrl',
  10751. size: 'lg',
  10752. resolve: {
  10753. AppName: function() {
  10754. return '出差单';
  10755. }
  10756. }
  10757. });
  10758. modalInstance.result.then(function(data) {
  10759. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10760. if(data.error) {
  10761. toaster.pop('error', '提示', data.error);
  10762. }
  10763. if(data.success) {
  10764. toaster.pop('success', '提示', data.success);
  10765. }
  10766. }, function(response) {
  10767. });
  10768. }, function(){
  10769. });
  10770. }
  10771. $scope.workDailySet = function() {
  10772. var modalInstance = $modal.open({
  10773. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10774. controller: 'NoteStep1Ctrl',
  10775. size: 'lg',
  10776. resolve: {
  10777. AppName: function() {
  10778. return '工作日报';
  10779. }
  10780. }
  10781. });
  10782. modalInstance.result.then(function(data) {
  10783. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10784. if(data.error) {
  10785. toaster.pop('error', '提示', data.error);
  10786. }
  10787. if(data.success) {
  10788. toaster.pop('success', '提示', data.success);
  10789. }
  10790. }, function(response) {
  10791. });
  10792. }, function(){
  10793. });
  10794. }
  10795. $scope.signAppSet = function() {
  10796. var modalInstance = $modal.open({
  10797. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10798. controller: 'NoteStep1Ctrl',
  10799. size: 'lg',
  10800. resolve: {
  10801. AppName: function() {
  10802. return '申诉单';
  10803. }
  10804. }
  10805. });
  10806. modalInstance.result.then(function(data) {
  10807. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10808. if(data.error) {
  10809. toaster.pop('error', '提示', data.error);
  10810. }
  10811. if(data.success) {
  10812. toaster.pop('success', '提示', data.success);
  10813. }
  10814. }, function(response) {
  10815. });
  10816. }, function(){
  10817. });
  10818. }
  10819. }]);
  10820. /**
  10821. * 审核条件设置
  10822. */
  10823. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  10824. $scope.appName = AppName;// 标题名称
  10825. $scope.AppFlow = {appName: $scope.appName,
  10826. appNodes:{}};
  10827. $scope.AppFlow.appNodes = [];
  10828. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  10829. if(data.appNodes.length != 0) {
  10830. $scope.node = data;
  10831. $scope.AppFlow = data;
  10832. }
  10833. }, function() {
  10834. });
  10835. $scope.copy = function() {//复制
  10836. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  10837. toaster.pop('info', '提示', '复制成功');
  10838. $modalInstance.dismiss();
  10839. }
  10840. $scope.paste = function() {
  10841. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  10842. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  10843. }
  10844. $scope.clear = function() {// 清空
  10845. $scope.AppFlow = {appName: $scope.appName,
  10846. appNodes:{}};
  10847. $scope.AppFlow.appNodes = [];
  10848. }
  10849. appFlow.getPositions({}, function(data) {// 获取人员信息
  10850. $scope.users = data;
  10851. }, function(response) {
  10852. });
  10853. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  10854. $scope.roles = data;
  10855. },function(response) {
  10856. });
  10857. $scope.SelectUser = function(data) { // 添加人员
  10858. var item = {
  10859. useruu: null,
  10860. username: null,
  10861. level: null
  10862. };
  10863. item.useruu = data.useruu;
  10864. item.username = data.username;
  10865. // if($scope.AppFlow.appNodes.length != 0){
  10866. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  10867. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  10868. // toaster.pop('info', '提示', '不能重复添加');
  10869. // } else {
  10870. // $scope.AppFlow.appNodes.push(item);
  10871. // }
  10872. // }
  10873. // } else {
  10874. $scope.AppFlow.appNodes.push(item);
  10875. // }
  10876. }
  10877. $scope.SelectRole = function(data) {// 添加职位
  10878. var item = {
  10879. position: null,
  10880. level: null
  10881. };
  10882. item.position = data;
  10883. $scope.AppFlow.appNodes.push(item);
  10884. }
  10885. $scope.deleteNode = function(index) {// 删除节点
  10886. $scope.AppFlow.appNodes.splice(index, 1);
  10887. };
  10888. $scope.saveNode = function() { // 保存
  10889. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  10890. $scope.AppFlow.appNodes[key].level = key;
  10891. });
  10892. if($scope.AppFlow.appNodes.length == 0) {
  10893. toaster.pop('info', '提示', '您还未设置审批人');
  10894. } else {
  10895. $modalInstance.close($scope.AppFlow);
  10896. };
  10897. };
  10898. $scope.cancel = function() {// 取消
  10899. $modalInstance.dismiss();
  10900. }
  10901. }]);
  10902. /***
  10903. * 代采定单
  10904. */
  10905. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  10906. BaseService.scrollBackToTop();
  10907. $scope.active = 'all';
  10908. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10909. $scope.total = null;
  10910. $scope.setActive = function(state) {
  10911. if($scope.active != state) {
  10912. $scope.active = state;
  10913. if($scope.tableParams.page() == 1)
  10914. $scope.tableParams.reload();
  10915. else
  10916. $scope.tableParams.page(1);
  10917. }
  10918. };
  10919. $scope.tableParams = new ngTableParams({
  10920. page : 1,
  10921. count : 5,
  10922. sorting: {
  10923. }
  10924. }, {
  10925. total : 0,
  10926. counts: [5, 10, 25, 50],
  10927. getData : function($defer, params) {
  10928. $scope.loading = true;
  10929. var pageParams = params.url();
  10930. pageParams.keyword = $scope.keyword;
  10931. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  10932. $scope.loading = false;
  10933. if(page) {
  10934. params.total(page.totalElement);
  10935. $scope.total = page.totalElement;
  10936. $defer.resolve(page.content);
  10937. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10938. }
  10939. }, function(response) {
  10940. $scope.loading = false;
  10941. toaster.pop('error', '数据加载失败', response.data);
  10942. });
  10943. }
  10944. });
  10945. //打印
  10946. $scope.print = function(deputyOrder) {
  10947. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  10948. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  10949. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  10950. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  10951. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  10952. //TODO 目前只有信扬有代采业务,先写死之后再改
  10953. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  10954. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  10955. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  10956. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  10957. };
  10958. // 搜索框回车
  10959. $scope.onSearch = function() {
  10960. $scope.tableParams.page(1);
  10961. $scope.tableParams.reload();
  10962. };
  10963. }]);
  10964. /**
  10965. * 新增代采订单
  10966. */
  10967. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  10968. BaseService.scrollBackToTop();
  10969. $scope.deOrder = {
  10970. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  10971. entrydate: new Date(),
  10972. status: '在录入',
  10973. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  10974. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  10975. riskmethod: '甲方承担',
  10976. taxpaymentmethod: '甲方承担',
  10977. totalamount: 0,
  10978. totalpayament: 0,
  10979. orderamount: 0,
  10980. usdpayment: 0
  10981. };
  10982. $scope.deOrder.deputyOrderItems = [];
  10983. var item = {
  10984. prodname: null,
  10985. prodcode: null,
  10986. prodspec: null,
  10987. amount: null,
  10988. unitprice: null,
  10989. remark: null,
  10990. orderprice: null,
  10991. };
  10992. $scope.deOrder.deputyOrderItems.push(item);
  10993. // 代采企业列表
  10994. DeputyOrder.deputyEnterprise({}, function(data) {
  10995. $scope.deputyEnterprises = data;
  10996. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  10997. // 费率
  10998. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  10999. $scope.rate = data;
  11000. }, function(response){
  11001. });
  11002. });
  11003. // 更新代采企业时更新费率
  11004. $scope.change = function(deputyuu) {
  11005. // 费率
  11006. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  11007. $scope.rate = data;
  11008. }, function(response){
  11009. });
  11010. }
  11011. // 查找付款企业
  11012. $scope.dbfindPayCompany = function(deputyuu) {
  11013. var modalInstance = $modal.open({
  11014. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  11015. controller: 'DbfindDeputyPayCompanyCtrl',
  11016. resolve: {
  11017. deputyuu: function() {return deputyuu}
  11018. }
  11019. });
  11020. modalInstance.result.then(function(data) {
  11021. $scope.deOrder.paycomname = data.enname;
  11022. $scope.deOrder.paycomaddress = data.address;
  11023. })
  11024. }
  11025. //增加商品
  11026. $scope.add = function(index) {
  11027. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  11028. toaster.pop('info', '提示', '请先填写商品信息');
  11029. }else {
  11030. $scope.deOrder.deputyOrderItems.push(
  11031. { prodname: null,
  11032. prodcode: null,
  11033. prodspec: null,
  11034. prodbrand: null,
  11035. amount: null,
  11036. unitprice: null,
  11037. remark: null,
  11038. orderprice: null});
  11039. }
  11040. };
  11041. //删除商品
  11042. $scope.del = function(index) {
  11043. $scope.deOrder.deputyOrderItems.splice(index, 1);
  11044. };
  11045. // 导入商品信息
  11046. $scope.uplodaByBatch = function() {
  11047. var modalInstance = $modal.open({
  11048. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  11049. controller: 'DeputyOrderUploadCtrl',
  11050. size: 'lg',
  11051. resolve: {
  11052. }
  11053. });
  11054. modalInstance.result.then(function(data) {
  11055. angular.forEach(data, function(data) {
  11056. $scope.deOrder.deputyOrderItems.push(data);
  11057. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  11058. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  11059. $scope.deOrder.deputyOrderItems.splice(i, 1);
  11060. }
  11061. }
  11062. })
  11063. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11064. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11065. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11066. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11067. });
  11068. }, function(){
  11069. });
  11070. }
  11071. // 查找供应商
  11072. $scope.dbfindVendor = function(deputyuu) {
  11073. var modalInstance = $modal.open({
  11074. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  11075. controller: 'DbfindDeputyVendorInfoCtrl',
  11076. size: 'lg',
  11077. resolve: {
  11078. deputyuu: function() {return deputyuu}
  11079. }
  11080. });
  11081. modalInstance.result.then(function(data) {
  11082. $scope.deOrder.customer = data.vendorEnterprise.enName;
  11083. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  11084. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  11085. $scope.deOrder.usertel = data.vendorUser.userTel;
  11086. })
  11087. }
  11088. // 检验订单编号是否存在
  11089. $scope.checkOrder = function(salecode, deputyuu) {
  11090. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  11091. if(data.info) {
  11092. toaster.pop('error', '提示', data.info);
  11093. }
  11094. }, function(response) {
  11095. toaster.pop('error', '提示', response.data);
  11096. })
  11097. }
  11098. // 保存
  11099. $scope.save = function() {
  11100. $scope.deOrder.entrystatus = '保存';
  11101. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11102. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11103. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11104. });
  11105. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  11106. toaster.pop('info', '提示', '您还未填写任何商品信息');
  11107. } else {
  11108. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11109. if(data.id) {
  11110. window.location.hash = "#/purc/deputy/"+data.id;
  11111. }
  11112. if(data.error) {
  11113. toaster.pop('error', '提示', '保存失败');
  11114. }
  11115. }, function(response) {
  11116. });
  11117. }
  11118. }
  11119. // 提交
  11120. $scope.submit = function() {
  11121. $scope.deOrder.entrystatus = '已提交';
  11122. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11123. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11124. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11125. });
  11126. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  11127. toaster.pop('info', '提示', '您还未填写任何商品信息');
  11128. } else {
  11129. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11130. if(data.id) {
  11131. window.location.hash = "#/purc/deputy/"+data.id;
  11132. }
  11133. if(data.error) {
  11134. toaster.pop('error', '提示', '保存失败');
  11135. }
  11136. }, function(response) {
  11137. });
  11138. }
  11139. }
  11140. $scope.openDatePicker = function($event, deOrder, openParam) {
  11141. $event.preventDefault();
  11142. $event.stopPropagation();
  11143. deOrder[openParam] = !deOrder[openParam];
  11144. };
  11145. }]);
  11146. // 代采企业供应商
  11147. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  11148. $scope.prod = false;
  11149. BaseService.scrollBackToTop();
  11150. // 搜索框回车
  11151. $scope.onSearch = function(keyword) {
  11152. $scope.keyword = keyword;
  11153. $scope.customerParams.page(1);
  11154. $scope.customerParams.reload();
  11155. };
  11156. $scope.customerParams = new ngTableParams({
  11157. page : 1,
  11158. count : 10
  11159. }, {
  11160. total : 0,
  11161. counts: [5, 10, 25, 50],
  11162. getData : function($defer, params) {
  11163. $scope.loading = true;
  11164. var pageParams = params.url();
  11165. pageParams.keyword = $scope.keyword;
  11166. pageParams.enuu = deputyuu;
  11167. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function(page){
  11168. $scope.loading = false;
  11169. if(page) {
  11170. params.total(page.totalElements);
  11171. $defer.resolve(page.content);
  11172. }
  11173. $scope.totalCount = page.totalElements;
  11174. }, function(response){
  11175. $scope.loading = false;
  11176. toaster.pop('error', '数据加载失败', response.data);
  11177. });
  11178. }
  11179. });
  11180. $scope.cancel = function() {
  11181. $modalInstance.dismiss();
  11182. };
  11183. $scope.checkVendor = function(vendor) { // 直接选择
  11184. $modalInstance.close(vendor);
  11185. }
  11186. }]);
  11187. // 代采企业付款企业
  11188. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  11189. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function(data) {
  11190. $scope.paycompanies = data;
  11191. }, function(response) {
  11192. toaster.pop('error', '提示', response.data);
  11193. });
  11194. $scope.cancel = function() {
  11195. $modalInstance.dismiss();
  11196. };
  11197. $scope.select = function(company) { // 直接选择
  11198. $modalInstance.close(company);
  11199. }
  11200. }]);
  11201. /**
  11202. * 代采订单批量导入
  11203. */
  11204. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  11205. // 通过excel批量上传物料
  11206. $scope.result = null;
  11207. $scope.upload = function() {
  11208. var file = $scope.myFiles[0];
  11209. $upload.upload({
  11210. url: 'deputyOrder/release/excel',
  11211. file: file,
  11212. method: 'POST'
  11213. }).success(function(data) {
  11214. $scope.result = data;
  11215. $scope.success = $scope.result.success;
  11216. $scope.total = $scope.result.total;
  11217. $scope.alters = $scope.result.alters;
  11218. }).error(function(response) {
  11219. toaster.pop('error', response.data || response);
  11220. });
  11221. };
  11222. // 查看范例
  11223. $scope.showImg = function() {
  11224. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  11225. box.show();
  11226. box.find('img').attr('src', src);
  11227. box.find('a').click(function(){
  11228. box.hide();
  11229. });
  11230. box.dblclick(function(){
  11231. box.hide();
  11232. });
  11233. };
  11234. // 下载模板
  11235. $scope.download = function() {
  11236. window.location.href = 'deputyOrder/upload/template';
  11237. };
  11238. $scope.enSure = function() {
  11239. $modalInstance.close($scope.result.items);
  11240. }
  11241. $scope.cancel = function() {
  11242. $modalInstance.dismiss();
  11243. }
  11244. }]);
  11245. /**
  11246. * 代采详情
  11247. */
  11248. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal) {
  11249. BaseService.scrollBackToTop();
  11250. var loadData = function() {
  11251. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  11252. $scope.deOrder = data;
  11253. $scope.deOrder.$editing = false;
  11254. });
  11255. };
  11256. loadData();
  11257. // 代采企业列表
  11258. DeputyOrder.deputyEnterprise({}, function(data) {
  11259. $scope.deputyEnterprises = data;
  11260. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  11261. // 费率
  11262. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  11263. $scope.rate = data;
  11264. }, function(response){
  11265. });
  11266. });
  11267. // 更新代采企业时更新费率
  11268. $scope.change = function(deputyuu) {
  11269. // 费率
  11270. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  11271. $scope.rate = data;
  11272. }, function(response){
  11273. });
  11274. }
  11275. // 查找付款企业
  11276. $scope.dbfindPayCompany = function(deputyuu) {
  11277. var modalInstance = $modal.open({
  11278. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  11279. controller: 'DbfindDeputyPayCompanyCtrl',
  11280. resolve: {
  11281. deputyuu: function() {return deputyuu}
  11282. }
  11283. });
  11284. modalInstance.result.then(function(data) {
  11285. $scope.deOrder.paycomname = data.enname;
  11286. $scope.deOrder.paycomaddress = data.address;
  11287. })
  11288. }
  11289. // 删除明细
  11290. $scope.del = function(index, id) {
  11291. DeputyOrder.deleteProdById({id: id}, {}, function(data) {
  11292. if(data.success) {
  11293. toaster.pop('success', '提示', data.success);
  11294. $scope.deOrder.deputyOrderItems.splice(index, 1)
  11295. }
  11296. if(data.error) {
  11297. toaster.pop('error', '提示', data.error);
  11298. }
  11299. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11300. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11301. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11302. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11303. });
  11304. }, function(response) {
  11305. toaster.pop('error', '提示', response.data);
  11306. });
  11307. }
  11308. //增加商品
  11309. $scope.add = function(index) {
  11310. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  11311. toaster.pop('info', '提示', '请先填写商品信息');
  11312. }else {
  11313. $scope.deOrder.deputyOrderItems.push(
  11314. { prodname: null,
  11315. prodcode: null,
  11316. prodspec: null,
  11317. prodbrand: null,
  11318. amount: null,
  11319. unitprice: null,
  11320. remark: null,
  11321. orderprice: null});
  11322. }
  11323. };
  11324. // 导入商品信息
  11325. $scope.uplodaByBatch = function() {
  11326. var modalInstance = $modal.open({
  11327. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  11328. controller: 'DeputyOrderUploadCtrl',
  11329. size: 'lg',
  11330. resolve: {
  11331. }
  11332. });
  11333. modalInstance.result.then(function(data) {
  11334. angular.forEach(data, function(data) {
  11335. $scope.deOrder.deputyOrderItems.push(data);
  11336. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  11337. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  11338. $scope.deOrder.deputyOrderItems.splice(i, 1);
  11339. }
  11340. }
  11341. })
  11342. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11343. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11344. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11345. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11346. });
  11347. }, function(){
  11348. });
  11349. }
  11350. //删除商品
  11351. $scope.delItem = function(index) {
  11352. $scope.deOrder.deputyOrderItems.splice(index, 1);
  11353. };
  11354. var getService = function() {
  11355. return DeputyOrder.getProdList;
  11356. };
  11357. $scope.update = function() {
  11358. $scope.deOrder.$editing = true;
  11359. }
  11360. $scope.cancel = function() {
  11361. $scope.deOrder.$editing = false;
  11362. }
  11363. // 检验订单编号是否存在
  11364. $scope.checkOrder = function(salecode, deputyuu) {
  11365. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  11366. if(data.info) {
  11367. toaster.pop('error', '提示', data.info);
  11368. }
  11369. }, function(response) {
  11370. toaster.pop('error', '提示', response.data);
  11371. })
  11372. }
  11373. // 保存
  11374. $scope.save = function() {
  11375. $scope.deOrder.entrystatus = '保存';
  11376. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11377. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11378. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11379. });
  11380. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  11381. toaster.pop('info', '提示', '您还未填写任何商品信息');
  11382. } else {
  11383. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11384. if(data.id) {
  11385. toaster.pop('success', '提示', '保存成功');
  11386. window.location.reload();
  11387. }
  11388. if(data.error) {
  11389. toaster.pop('error', '提示', '保存失败');
  11390. }
  11391. }, function(response) {
  11392. });
  11393. }
  11394. }
  11395. // 提交
  11396. $scope.submit = function() {
  11397. $scope.deOrder.entrystatus = '已提交';
  11398. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11399. if(data.id) {
  11400. window.location.hash = "#/purc/deputy/"+data.id;
  11401. }
  11402. if(data.error) {
  11403. toaster.pop('error', '提示', '保存失败');
  11404. }
  11405. }, function(response) {
  11406. });
  11407. }
  11408. $scope.openDatePicker = function($event, deOrder, openParam) {
  11409. $event.preventDefault();
  11410. $event.stopPropagation();
  11411. deOrder[openParam] = !deOrder[openParam];
  11412. };
  11413. }]);
  11414. /**
  11415. * 招标单
  11416. */
  11417. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  11418. BaseService.scrollBackToTop();
  11419. $scope.active = 'done';
  11420. if ($rootScope.tenderActive) {
  11421. $scope.active = $rootScope.tenderActive;
  11422. }
  11423. $scope.dateZoneText = '不限';
  11424. $scope.deliveryZoneText = '不限';
  11425. $scope.condition = {dateZone: -1, deliveryZone: -1};
  11426. $scope.changeDateZone = function(zone) {
  11427. $scope.condition.dateZone = zone;
  11428. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  11429. $scope.condition.$dateZoneOpen = false;
  11430. getDateCondition(zone, $scope.condition);
  11431. $scope.tableParams.reload();
  11432. };
  11433. $scope.changeDeliveryZone = function(zone) {
  11434. $scope.condition.deliveryZoneText = zone;
  11435. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  11436. $scope.condition.$delievryZoneOpen = false;
  11437. getDelveryCondition(zone, $scope.condition);
  11438. $scope.tableParams.reload();
  11439. };
  11440. $scope.setActive = function(state) {
  11441. if($scope.active != state) {
  11442. $scope.active = state;
  11443. if($scope.tableParams.page() == 1)
  11444. $scope.tableParams.reload();
  11445. else
  11446. $scope.tableParams.page(1);
  11447. }
  11448. };
  11449. var getTenderStatus = function(active) {
  11450. var fn = 'getMyAll';
  11451. switch(active) {
  11452. case 'done':
  11453. fn = 'getMyDone';break;
  11454. case 'todo':
  11455. fn = 'getMyTodo';break;
  11456. // case 'end':
  11457. // fn = 'getMyEnd';break;
  11458. case 'waiting':
  11459. fn = 'getMyWaiting';break;
  11460. }
  11461. return fn;
  11462. }
  11463. $scope.tableParams = new ngTableParams({
  11464. page : 1,
  11465. count : 5,
  11466. sorting: {
  11467. 'tender.endDate': 'desc',
  11468. 'tender.enterprise.enName': 'asc',
  11469. 'tender.code': 'asc'
  11470. }
  11471. }, {
  11472. total : 0,
  11473. counts: [5, 10, 25, 50],
  11474. getData : function($defer, params) {
  11475. $scope.loading = true;
  11476. var pageParams = params.url();
  11477. var realActive = {};
  11478. pageParams.searchFilter = { // 筛选条件
  11479. keyword: $scope.keyword,
  11480. fromDate: getDateTime($scope.condition.dateFrom),
  11481. endDate: getDateTime($scope.condition.dateTo)
  11482. };
  11483. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11484. $scope.loading = false;
  11485. if(page) {
  11486. params.total(page.totalElement);
  11487. $defer.resolve(page.content);
  11488. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  11489. }
  11490. }, function(response){
  11491. $scope.loading = false;
  11492. toaster.pop('error', '数据加载失败', response.data);
  11493. });
  11494. }
  11495. });
  11496. $scope.openDatePicker = function($event, item, openParam) {
  11497. $event.preventDefault();
  11498. $event.stopPropagation();
  11499. item[openParam] = !item[openParam];
  11500. };
  11501. $scope.parseDate = function(dateStr) {
  11502. if(dateStr)
  11503. return Date.parse(dateStr, 'yyyy-MM-dd');
  11504. return new Date();
  11505. };
  11506. // 选择查找日期
  11507. $scope.onDateCondition = function(){
  11508. $scope.tableParams.page(1);
  11509. $scope.tableParams.reload();
  11510. };
  11511. // 搜索框回车
  11512. $scope.onSearch = function() {
  11513. $scope.tableParams.page(1);
  11514. $scope.tableParams.reload();
  11515. };
  11516. }]);
  11517. /**
  11518. * 新增招标单
  11519. */
  11520. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'ShipAddress', '$http', 'AuthenticationService', 'KindAPI', 'BrandActiveAPI', 'Search', 'ComponentActiveAPI', 'GetProductInfo', 'Vendor',function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, ShipAddress, $http, AuthenticationService, KindAPI, BrandActiveAPI, Search, ComponentActiveAPI, GetProductInfo, Vendor) {
  11521. // 录入人
  11522. AuthenticationService.getAuthentication().success(function(data) {
  11523. $scope.user = data;
  11524. });
  11525. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  11526. var getService = function() {
  11527. return GetProductInfo;
  11528. };
  11529. // 物料信息
  11530. $scope.tableParams = new ngTableParams({
  11531. page : 1,
  11532. count : 5,
  11533. sorting: {
  11534. }
  11535. }, {
  11536. total : 0,
  11537. counts: [5, 10, 25, 50],
  11538. getData : function($defer, params) {
  11539. $scope.loading = true;
  11540. var pageParams = params.url();
  11541. pageParams.keyword = $scope.keyword;
  11542. $scope.tip = $scope.keyword;
  11543. pageParams.searchFilter = $scope.searchFilter;
  11544. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11545. $scope.loading = false;
  11546. if(page) {
  11547. params.total(page.totalElement);
  11548. $scope.total = page.totalElement;
  11549. $defer.resolve(page.content);
  11550. }
  11551. }, function(response) {
  11552. $scope.loading = false;
  11553. toaster.pop('error', '数据加载失败', response.data);
  11554. });
  11555. }
  11556. });
  11557. // 搜索框回车
  11558. $scope.onSearch = function(keyword) {
  11559. $scope.tableParams.page(1);
  11560. $scope.tableParams.reload();
  11561. };
  11562. //在产品列表添加商品
  11563. $scope.check = function(product) {
  11564. $scope.tenderProd.push({
  11565. prodTitle: product.title,
  11566. prodCode: product.code,
  11567. brand: product.brand,
  11568. unit: product.unit,
  11569. qty: null
  11570. // 供应商企业信息
  11571. // enterpriseBaseInfo: [{}]
  11572. });
  11573. for(var i = 0; i < $scope.tenderProd.length; i++) {
  11574. if($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  11575. $scope.tenderProd.splice(i, 1);
  11576. }
  11577. }
  11578. };
  11579. $scope.loading = false;
  11580. // 获取收货地址列表
  11581. var loadShipAddress = function() {
  11582. ShipAddress.shipAddList({}, function(data) {
  11583. $scope.ships = data;
  11584. $scope.tender.shipadd = $scope.ships[0];
  11585. });
  11586. };
  11587. loadShipAddress();
  11588. // 获取地址信息
  11589. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  11590. }).then(function(response) {
  11591. $scope.provinces = response.data;
  11592. });
  11593. // 新增收货地址保存
  11594. $scope.saveShipAddress = function(ship) {
  11595. ship.address = ship.province + ship.city + ship.district;
  11596. ShipAddress.saveAddress( {}, ship, function(data) {
  11597. if(data.success) {
  11598. // 获取收货地址列表
  11599. loadShipAddress();
  11600. toaster.pop('success', '提示', data.success);
  11601. }
  11602. if(data.error) {
  11603. toaster.pop('error', '提示', data.error);
  11604. }
  11605. });
  11606. };
  11607. // 可选的证照要求
  11608. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  11609. // 处理证照要求
  11610. var parseCertificate = function(a) {
  11611. if (a) {
  11612. var arr = a.split(',');
  11613. angular.forEach(arr, function(app) {
  11614. var contained = false;
  11615. angular.forEach($scope.certificates, function($app) {
  11616. if($app.name == app) {
  11617. $app.checked = true;
  11618. contained = true;
  11619. }
  11620. });
  11621. if(!contained) {
  11622. $scope.certificates.push({name: app, checked: true});
  11623. }
  11624. });
  11625. }
  11626. };
  11627. // 联想词start
  11628. // 获取品牌联想词
  11629. $scope.getSimilarBrands = function(value) {
  11630. if (value) {
  11631. // 获取品牌联想词
  11632. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  11633. return data.map(function(item) {
  11634. return item;
  11635. });
  11636. });
  11637. }
  11638. };
  11639. // 获取产品型号联想词
  11640. $scope.getSimilarCodes = function(value) {
  11641. if (value) {
  11642. // 获取产品型号联想词
  11643. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  11644. return data.map(function (item) {
  11645. return item;
  11646. })
  11647. });
  11648. }
  11649. };
  11650. // // 获取产品类目联想词
  11651. // $scope.getSimilarKinds = function(value) {
  11652. // if (value) {
  11653. // // getSimilarLeafKinds 根据类目名获取末级联想词
  11654. // // 获取类目联想词
  11655. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  11656. // return data.map(function(item) {
  11657. // return item;
  11658. // })
  11659. // });
  11660. // }
  11661. // };
  11662. // // 点击联想词获取类目信息
  11663. // $scope.onAssociateKindClick = function(kind, submit) {
  11664. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  11665. // $scope.actives = data;
  11666. // console.log(data);
  11667. // var size = data.length;
  11668. // if (size > 0) {
  11669. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  11670. // submit.kiName = submit.gradeOneKiName;
  11671. // if (size > 1) {
  11672. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  11673. // submit.kiName = submit.gradeTwoKiName;
  11674. // if (kind.level < 3) {
  11675. // submit.gradeThreeKiName = null;
  11676. // } else if (size > 2) {
  11677. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  11678. // submit.kiName = submit.gradeThreeKiName;
  11679. // }
  11680. // }
  11681. // }
  11682. // console.log(submit);
  11683. // })
  11684. // };
  11685. // 选择类目
  11686. $scope.selectKind = function(prod) {
  11687. var submit = [];
  11688. $modal.open({
  11689. animation: true,
  11690. size: 'lg',
  11691. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  11692. controller: 'ProdKindChooseCtrl',
  11693. resolve: {
  11694. actives: function() {
  11695. return $scope.actives;
  11696. }
  11697. }
  11698. }).result.then(function(data){
  11699. $scope.actives = data.actives;
  11700. var size = data.actives.length;
  11701. submit.gradeOneKiName = '';
  11702. submit.gradeTwoKiName = '';
  11703. submit.gradeThreeKiName = '';
  11704. if (size > 0) {
  11705. submit.gradeOneKiName = $scope.actives[0].nameCn;
  11706. prod.prodTitle = submit.gradeOneKiName;
  11707. if (size > 1) {
  11708. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  11709. prod.prodTitle = submit.gradeTwoKiName;
  11710. if (size > 2) {
  11711. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  11712. prod.prodTitle = submit.gradeThreeKiName;
  11713. }
  11714. }
  11715. }
  11716. }, function(){
  11717. });
  11718. };
  11719. // // 验证分类信息
  11720. // $scope.checkKind = function() {
  11721. // setTimeout(function() {
  11722. // if($scope.activesString == null) {
  11723. // $scope.component.kindid = null;
  11724. // return;
  11725. // }
  11726. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  11727. // $scope.component.kind = kind;
  11728. // $scope.component.kindid = kind.id;
  11729. // $scope.activesString = $scope.component.kind.nameCn;
  11730. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  11731. // $scope.kindProperties = data;
  11732. // angular.forEach($scope.kindProperties, function(kp) {
  11733. // angular.forEach($scope.component.properties, function(pro) {
  11734. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  11735. // kp.value = pro.value;
  11736. // }
  11737. // });
  11738. // });
  11739. // }, function(response) {
  11740. // });
  11741. // }, function (response) {
  11742. // $scope.component.kindid = null;
  11743. // toaster.pop('error', response.data);
  11744. // });
  11745. // }, 500);
  11746. // };
  11747. // 点击联想词获取品牌信息
  11748. $scope.onAssociateBrandClick = function(brand, prod) {
  11749. if (brand instanceof String) {
  11750. prod.brand = brand;
  11751. } else if (brand instanceof Object) {
  11752. prod.brand = brand.brandCn;
  11753. }
  11754. };
  11755. // 打开品牌选择的模态框
  11756. $scope.selectBrand = function(prod){ //打开模态
  11757. var modalInstance = $modal.open({
  11758. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  11759. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  11760. });
  11761. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  11762. });
  11763. modalInstance.result.then(function(brand){
  11764. prod.brand = brand.nameCn;
  11765. }, function(reason){
  11766. });
  11767. };
  11768. // // 验证品牌是否正确
  11769. // $scope.checkBrand = function () {
  11770. // setTimeout(function () {
  11771. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  11772. // // $scope.component.brand = brand;
  11773. // // $scope.component.brandid = brand.id;
  11774. // }, function (response) {
  11775. // // $scope.component.brandid = null;
  11776. // toaster.pop('error', response.data);
  11777. // })
  11778. // } , 500);
  11779. // };
  11780. // 点击联想词获取器件信息 带入产品分类和品牌
  11781. $scope.onAssociateCmpClick = function(cmp, prod) {
  11782. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  11783. $scope.component = data;
  11784. prod.prodCode = data.code;
  11785. prod.prodTitle = data.kind.nameCn;
  11786. prod.brand = data.brand.nameCn;
  11787. }, function(res) {
  11788. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  11789. })
  11790. };
  11791. //联想词end
  11792. $scope.condition = {dateZone: 1};
  11793. $scope.tenderProd = [];
  11794. var prod = {
  11795. prodTitle: null,
  11796. prodCode: null,
  11797. brand: null,
  11798. unit: 'PCS',
  11799. qty: null
  11800. // 供应商企业信息
  11801. // enterpriseBaseInfo: [{}]
  11802. };
  11803. $scope.tender = {
  11804. date: new Date(),
  11805. unit: 'PCS',
  11806. currency: 'RMB',
  11807. ifOpen: 1,
  11808. ifTax: 1,
  11809. invoiceType: 2,
  11810. tenderAttachs:[{}]
  11811. };
  11812. //
  11813. $scope.tenderProd.push(prod);
  11814. //增加商品
  11815. $scope.add = function(index) {
  11816. $scope.tenderProd.push({
  11817. prodTitle: null,
  11818. prodCode: null,
  11819. brand: null,
  11820. unit: 'PCS',
  11821. qty: null
  11822. // 供应商企业信息
  11823. // enterpriseBaseInfo: [{}]
  11824. });
  11825. };
  11826. //删除商品
  11827. $scope.del = function(index) {
  11828. $scope.tenderProd.splice(index, 1);
  11829. };
  11830. // 批量导入
  11831. $scope.uplodaByBatch = function() {
  11832. var modalInstance = $modal.open({
  11833. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  11834. controller: 'PurcTenderUploadCtrl',
  11835. size: 'lg',
  11836. resolve: {
  11837. }
  11838. });
  11839. modalInstance.result.then(function(data) {
  11840. // 获取上传的产品明细,前台展示
  11841. angular.forEach(data, function(data) {
  11842. $scope.tenderProd.push(data);
  11843. for(var i = 0; i < $scope.tenderProd.length; i++) {
  11844. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  11845. $scope.tenderProd.splice(i, 1);
  11846. }
  11847. }
  11848. });
  11849. }, function(){
  11850. });
  11851. };
  11852. $scope.isSave = false;
  11853. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  11854. if( ! angular.isUndefined($stateParams.id)) {
  11855. $scope.isSave = true; // 用于判断是新增还是已保存
  11856. $scope.loading = true;
  11857. PurcTender.getOne({id: $stateParams.id}, function(data){
  11858. data.$editing = false;
  11859. $scope.tender = data;
  11860. $scope.tenderProd = data.purchaseTenderProds;
  11861. parseCertificate($scope.tender.certificate);
  11862. $scope.firstProd = data.purchaseTenderProds[0];
  11863. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  11864. // 获取供应商联系人
  11865. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function(data) {
  11866. item.saleTender.enterpriseBaseInfo.contacts = data;
  11867. item.saleTender.enterpriseBaseInfo.contact = data[0];
  11868. });
  11869. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  11870. $scope.tenderProd.enterpriseBaseInfo = [{}];
  11871. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  11872. } else {
  11873. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  11874. }
  11875. });
  11876. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  11877. $scope.loading = false;
  11878. $scope.attaches = $scope.tender.tenderAttaches;
  11879. }, function(response){
  11880. $scope.loading = false;
  11881. toaster.pop('error', '数据加载失败', response.data);
  11882. });
  11883. }
  11884. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  11885. $rootScope.tenderVendor = [{}];
  11886. }
  11887. $scope.changeShipAddress = false;
  11888. $scope.changeAddress = function() {
  11889. if ($scope.changeShipAddress) {
  11890. $scope.changeShipAddress = false;
  11891. } else {
  11892. $scope.changeShipAddress = true;
  11893. }
  11894. };
  11895. $scope.changeContactInfo = function(en) {
  11896. if (en.changeContact) {
  11897. en.changeContact = false;
  11898. } else {
  11899. en.changeContact = true;
  11900. }
  11901. };
  11902. $scope.changeCurrency = function(tender) {
  11903. if (tender.currency !== 'RMB') {
  11904. $scope.notRMB = true;
  11905. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  11906. tender.invoiceType = 0;
  11907. } else {
  11908. $scope.notRMB = false;
  11909. }
  11910. };
  11911. // $scope.validateNumber = function (value) { // 采购数量 正整数
  11912. // var regex = /^\+?[1-9][0-9]*$/;
  11913. // if (!regex.test(value) || value === 0 || value === null) {
  11914. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  11915. // }
  11916. // };
  11917. // 查找供应商
  11918. $scope.dbfindVendor = function(){
  11919. var modalInstance = $modal.open({
  11920. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  11921. controller: 'DbfindVendorCtrl',
  11922. size: 'lg',
  11923. resolve: {
  11924. }
  11925. });
  11926. var ifPush = true;
  11927. modalInstance.result.then(function(data){
  11928. angular.forEach(data, function(vendor) {
  11929. // 获取供应商联系人
  11930. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function(data) {
  11931. vendor.vendorEnterprise.contacts = data;
  11932. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  11933. });
  11934. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  11935. $scope.tenderProd.enterpriseBaseInfo = [{}];
  11936. // 获取供应商联系人
  11937. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  11938. } else {
  11939. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  11940. ifPush = true;
  11941. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  11942. ifPush = false;
  11943. break; // 判定到已存在供应商,就终止循环。
  11944. }
  11945. }
  11946. if (ifPush) {
  11947. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  11948. }
  11949. }
  11950. });
  11951. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  11952. }, function(){
  11953. });
  11954. };
  11955. // 新增供应商联系人
  11956. $scope.addContact = function(en) {
  11957. var modalInstance = $modal.open({
  11958. animation: true,
  11959. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  11960. controller: 'AddContacCtrl',
  11961. resolve: {
  11962. }
  11963. });
  11964. modalInstance.result.then(function(data) {
  11965. en.contact = data;
  11966. en.contact.venduu = en.uu;
  11967. Vendor.saveContact({}, en.contact, function(data) {
  11968. Vendor.contacts({venduu: en.uu}, {}, function(data) {
  11969. en.contacts = data;
  11970. en.contact = en.contacts[0];
  11971. });
  11972. toaster.pop('success', '提示', '联系人保存成功');
  11973. }, function(response) {
  11974. toaster.pop('error', '失败', response.data);
  11975. });
  11976. });
  11977. };
  11978. // 删除一个供应商
  11979. $scope.removeVendor = function(index) {
  11980. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  11981. };
  11982. // 删除供应商时,后台删除投标单
  11983. $scope.removeSaleTender = function (id, vendUU) {
  11984. var hasSaved = false;
  11985. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  11986. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  11987. hasSaved = true;
  11988. }
  11989. });
  11990. if (hasSaved) {
  11991. PurcTender.removeSaleTender ({id : id, vendUU : vendUU}, {}, function(data) {
  11992. }, function(response) {
  11993. toaster.pop('error', '提示', response.data);
  11994. });
  11995. }
  11996. };
  11997. // 删除产品明细时,后台删除产品明细
  11998. $scope.deleteProd = function (tenderProd) {
  11999. if (tenderProd.id) {
  12000. PurcTender.deleteProd ({tenderProdId : tenderProd.id}, {}, function(data) {
  12001. }, function(response) {
  12002. toaster.pop('error', '提示', response.data);
  12003. });
  12004. }
  12005. };
  12006. // // 查找客户物料
  12007. // $scope.dbfindCustProd = function(){
  12008. // if($scope.item.$editing) {
  12009. // if($scope.item.quotation.cust.uu) {
  12010. // var modalInstance = $modal.open({
  12011. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  12012. // controller: 'DbfindCustProdCtrl',
  12013. // size: 'lg',
  12014. // resolve: {
  12015. // custUU: function(){return $scope.item.quotation.cust.uu}
  12016. // }
  12017. // });
  12018. //
  12019. // modalInstance.result.then(function(data){
  12020. // $scope.item.product = data;
  12021. // }, function(){
  12022. //
  12023. // });
  12024. // } else {
  12025. // toaster.pop('error', '错误', '请先选择客户');
  12026. // }
  12027. // }
  12028. // };
  12029. if (!$scope.attaches) {
  12030. $scope.attaches = []; // 存放上传了的附件
  12031. }
  12032. $scope.upload = function(myFile) { // 上传附件
  12033. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  12034. $upload.upload({
  12035. url: 'tender/addTenderAttach',
  12036. file: file,
  12037. method: 'POST'
  12038. // data: {
  12039. // tender: $scope.tender
  12040. // }
  12041. }).success(function (attach) {
  12042. $scope.attaches.push(attach);
  12043. });
  12044. };
  12045. $scope.removeAttach = function(id, index) {
  12046. $scope.attaches.splice(index, 1);
  12047. // PurcTender.removeAttach({attachId:id}, function() {
  12048. //
  12049. // });
  12050. };
  12051. var sleep = function (d){
  12052. for(var t = Date.now();Date.now() - t <= d;);
  12053. };
  12054. // 保存和发布招标单
  12055. $scope.save = function(isPublish){
  12056. if (!$scope.tender.ifOpen && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  12057. toaster.pop('info','提示','请先指定供应商');
  12058. } else {
  12059. $scope.loading = true;
  12060. // --组装证照要求
  12061. var myCertificate = [];
  12062. angular.forEach($scope.certificates, function(certificate) {
  12063. if (certificate.checked) {
  12064. myCertificate.push(certificate.name);
  12065. }
  12066. });
  12067. $scope.tender.certificate = myCertificate.join(',');
  12068. if(!$scope.tender.code) { //新增,设单号
  12069. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  12070. }
  12071. if($scope.tender.date instanceof Date) {
  12072. $scope.tender.date = $scope.tender.date.getTime();
  12073. }
  12074. if($scope.tender.endDate instanceof Date) {
  12075. $scope.tender.endDate = $scope.tender.endDate.getTime();
  12076. }
  12077. if($scope.tender.publishDate instanceof Date) {
  12078. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  12079. }
  12080. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  12081. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  12082. $scope.tender.purchaseTenderProds[i].index = i + 1;
  12083. }
  12084. $scope.tender.tenderAttaches = $scope.attaches;
  12085. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  12086. var enInfos = [];
  12087. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  12088. var enInfo = {
  12089. vendUU: null,
  12090. contact: null,
  12091. contactTel: null
  12092. };
  12093. enInfo.vendUU = enterpriseBaseInfo.uu;
  12094. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  12095. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  12096. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  12097. }
  12098. enInfos.push(enInfo);
  12099. });
  12100. if (isPublish) { // 发布
  12101. toaster.pop('info', '提示', '正在发布,请稍候');
  12102. $scope.tender.isPublish = 1;
  12103. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  12104. sleep(1500); //当前方法暂停1.5秒
  12105. $scope.loading = false;
  12106. toaster.pop('success', '成功', '发布成功');
  12107. window.location.hash = '#/purc/tender';
  12108. }, function(response){
  12109. $scope.loading = false;
  12110. toaster.pop('error', '发布失败', response.data);
  12111. });
  12112. } else { // 保存
  12113. toaster.pop('info', '提示', '正在保存,请稍候');
  12114. $scope.tender.isPublish = 0;
  12115. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  12116. $scope.loading = false;
  12117. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  12118. toaster.pop('success', '成功', '保存成功');
  12119. window.location.hash = '#/purc/tender';
  12120. }, function(response){
  12121. $scope.loading = false;
  12122. toaster.pop('error', '保存失败', response.data);
  12123. });
  12124. }
  12125. }
  12126. };
  12127. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  12128. $scope.removeChecked = function() {
  12129. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  12130. $scope.tenderProd.enterpriseBaseInfo = [];
  12131. }
  12132. };
  12133. // 删除(在录入状态)
  12134. $scope.deleteThis = function(id) {
  12135. PurcTender.deleteOne({id:id}, {}, function(data) {
  12136. toaster.pop('info', '提示', '删除成功');
  12137. window.location.hash = '#/purc/tender';
  12138. });
  12139. };
  12140. // 更新和发布(在录入状态)
  12141. $scope.updateSaved = function(isPublish){
  12142. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  12143. toaster.pop('info','提示','请先指定供应商');
  12144. } else {
  12145. $scope.loading = true;
  12146. // --组装证照要求
  12147. var myCertificate = [];
  12148. angular.forEach($scope.certificates, function(certificate) {
  12149. if (certificate.checked) {
  12150. myCertificate.push(certificate.name);
  12151. }
  12152. });
  12153. $scope.tender.certificate = myCertificate.join(',');
  12154. if($scope.tender.endDate instanceof Date) {
  12155. $scope.tender.endDate = $scope.tender.endDate.getTime();
  12156. }
  12157. if($scope.tender.publishDate instanceof Date) {
  12158. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  12159. }
  12160. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  12161. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  12162. $scope.tender.purchaseTenderProds[i].index = i + 1;
  12163. }
  12164. $scope.tender.tenderAttaches = $scope.attaches;
  12165. if ($scope.tender.shipadd) {
  12166. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  12167. }
  12168. angular.forEach($scope.tender.purchaseTenderProds, function(tenderProd){
  12169. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  12170. });
  12171. var enInfos = [];
  12172. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  12173. var enInfo = {
  12174. vendUU: null,
  12175. contact: null,
  12176. contactTel: null
  12177. };
  12178. enInfo.vendUU = enterpriseBaseInfo.uu;
  12179. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  12180. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  12181. enInfos.push(enInfo);
  12182. });
  12183. if (isPublish) { // 发布
  12184. toaster.pop('info', '提示', '正在发布,请稍候');
  12185. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  12186. sleep(1500); //当前方法暂停1.5秒
  12187. $scope.loading = false;
  12188. toaster.pop('success', '成功', '发布成功');
  12189. window.location.hash = '#/purc/tender';
  12190. }, function(response){
  12191. $scope.loading = false;
  12192. toaster.pop('error', '发布失败', response.data);
  12193. });
  12194. } else { // 保存
  12195. toaster.pop('info', '提示', '正在保存,请稍候');
  12196. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  12197. $scope.loading = false;
  12198. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  12199. toaster.pop('success', '成功', '保存成功');
  12200. window.location.reload();
  12201. }, function(response){
  12202. $scope.loading = false;
  12203. toaster.pop('error', '保存失败', response.data);
  12204. });
  12205. }
  12206. }
  12207. };
  12208. $scope.currentDay = function() {
  12209. return $filter('date')(new Date(), 'yyyy-MM-dd');
  12210. };
  12211. $scope.getMinDate = function() {
  12212. // var now = new Date();
  12213. // now = now.setDate(now.getDate()+1);
  12214. // var minDate = angular.copy($scope.tender.endDate);
  12215. // minDate = minDate.setDate(minDate.getDate() + 1);
  12216. if ($scope.tender.endDate instanceof Date) {
  12217. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  12218. }
  12219. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  12220. };
  12221. $scope.getMaxDate = function() {
  12222. // var maxDate = angular.copy($scope.tender.publishDate);
  12223. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  12224. if ($scope.tender.publishDate instanceof Date) {
  12225. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  12226. }
  12227. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  12228. };
  12229. $scope.openDatePicker = function($event, item, openParam) {
  12230. $event.preventDefault();
  12231. $event.stopPropagation();
  12232. item[openParam] = !item[openParam];
  12233. };
  12234. }]);
  12235. //类目选择模态框(招标产品明细)
  12236. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  12237. $scope.actives = actives;
  12238. $scope.kinds = [[], [], [], []];
  12239. // 获取子类目
  12240. var getChildren = function(pid, deep) {
  12241. KindAPI.getChildren({parentId: pid}, function(data) {
  12242. $scope.kinds[deep] = data;
  12243. }, function(response) {
  12244. toaster.pop('error', '获取子类目失败', response.data);
  12245. });
  12246. };
  12247. // 改变节点选中状态
  12248. var changeStatus = function(item, deep) {
  12249. var actives = [], level = 0;
  12250. angular.forEach($scope.kinds, function(ks, i) {
  12251. if(i > deep) {
  12252. $scope.kinds[i] = [];
  12253. } else {
  12254. angular.forEach(ks, function(k, j) {
  12255. if(i == deep) {
  12256. if(k.id == item.id) {
  12257. $scope.kinds[i][j].$active = true;
  12258. actives.push(k);
  12259. } else {
  12260. k.$active = null;
  12261. }
  12262. } else {
  12263. if(k.$active) {
  12264. actives.push(k);
  12265. }
  12266. }
  12267. });
  12268. }
  12269. });
  12270. // 选择的节点
  12271. $scope.actives = actives;
  12272. $scope.active = item;
  12273. // 当前可操作的层级
  12274. if(deep < 3) {
  12275. $scope.activeDeep = deep + 1;
  12276. }
  12277. };
  12278. // 节点点击后获取子类目,节点被选中
  12279. $scope.onItemClick = function(item, deep) {
  12280. changeStatus(item, deep);
  12281. if (!item.isLeaf) {
  12282. getChildren(item.id, deep + 1);
  12283. }
  12284. };
  12285. // 重新加载数据
  12286. function reload(deep) {
  12287. var pid;
  12288. if(deep) {
  12289. pid = $scope.actives[deep - 1].id;
  12290. } else {
  12291. pid = 0;
  12292. deep = 0;
  12293. }
  12294. getChildren(pid, deep);
  12295. }
  12296. // 初始加载数据,获取第一层的类目
  12297. if($scope.actives) {
  12298. angular.forEach($scope.actives, function(v, k) {
  12299. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  12300. $scope.kinds[k] = data;
  12301. angular.forEach($scope.kinds[k], function(kind, i){
  12302. if(kind.id == v.id) {
  12303. $scope.kinds[k][i].$active = true;
  12304. $scope.actives[k] = $scope.kinds[k][i];
  12305. }
  12306. })
  12307. }, function(response) {
  12308. toaster.pop('error', '获取子类目失败', response.data);
  12309. });
  12310. });
  12311. } else {
  12312. reload();
  12313. }
  12314. // 取消
  12315. $scope.cancel = function() {
  12316. $modalInstance.dismiss();
  12317. };
  12318. // 确认选择
  12319. $scope.check = function() {
  12320. var a = {
  12321. active: $scope.active,
  12322. actives: $scope.actives
  12323. };
  12324. $modalInstance.close(a);
  12325. };
  12326. }]);
  12327. //品牌选择模态框的controller
  12328. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  12329. $scope.filter = {};
  12330. $scope.brandsTableParams = new ngTableParams({
  12331. page : 1,
  12332. count : 6,
  12333. sorting : {
  12334. nameCn: 'asc'
  12335. }
  12336. }, {
  12337. total : 0,
  12338. counts : [],
  12339. getData : function($defer, params) {
  12340. var param = BaseService.parseParams(params.url());
  12341. param.keyword = $scope.filter.keyword;
  12342. var keyword = $scope.filter.keyword;
  12343. // param.keyword = $scope.filter.keyword;
  12344. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  12345. if (page) {
  12346. params.total(page.totalElements);
  12347. $defer.resolve(page.content);
  12348. }
  12349. }, function(){
  12350. });
  12351. }
  12352. });
  12353. // 搜索
  12354. $scope.search = function() {
  12355. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  12356. $scope.brandsTableParams.page(1);
  12357. $scope.brandsTableParams.reload();
  12358. };
  12359. // 选择
  12360. $scope.select = function(brand){
  12361. $modalInstance.close(brand);
  12362. };
  12363. // 关闭
  12364. $scope.cancel = function() {
  12365. $modalInstance.dismiss();
  12366. };
  12367. }]);
  12368. /**
  12369. * 招标单批量导入
  12370. */
  12371. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  12372. // 通过excel批量上传物料
  12373. $scope.result = null;
  12374. $scope.upload = function() {
  12375. var file = $scope.myFiles[0];
  12376. $upload.upload({
  12377. url: 'tender/release/excel',
  12378. file: file,
  12379. method: 'POST'
  12380. }).success(function(data) {
  12381. $scope.result = data;
  12382. $scope.success = $scope.result.success;
  12383. $scope.total = $scope.result.total;
  12384. $scope.alters = $scope.result.alters;
  12385. }).error(function(response) {
  12386. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  12387. });
  12388. };
  12389. // 查看范例
  12390. $scope.showImg = function() {
  12391. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  12392. box.show();
  12393. box.find('img').attr('src', src);
  12394. box.find('a').click(function(){
  12395. box.hide();
  12396. });
  12397. box.dblclick(function(){
  12398. box.hide();
  12399. });
  12400. };
  12401. // 下载模板
  12402. $scope.download = function() {
  12403. window.location.href = 'tender/upload/template';
  12404. };
  12405. $scope.enSure = function() {
  12406. $modalInstance.close($scope.result.items);
  12407. }
  12408. $scope.cancel = function() {
  12409. $modalInstance.dismiss();
  12410. }
  12411. }]);
  12412. /**
  12413. * 评标
  12414. */
  12415. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  12416. BaseService.scrollBackToTop();
  12417. $scope.tenderItems = [];
  12418. // 采购方获取评标单
  12419. var evaluation = function() {
  12420. $scope.loading = true;
  12421. PurcTender.getOne({id: $stateParams.id}, function(data){
  12422. data.$editing = false;
  12423. $scope.tender = data;
  12424. $scope.tableParams = new ngTableParams({}, { dataset: data});
  12425. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  12426. $scope.loading = false;
  12427. }, function(response){
  12428. $scope.loading = false;
  12429. toaster.pop('error', '数据加载失败', response.data);
  12430. });
  12431. };
  12432. evaluation();
  12433. $scope.orderType = '';
  12434. // $scope.dir = '-';
  12435. // 改变排序顺序
  12436. $scope.changeOrder = function(type){
  12437. $scope.orderType = type;
  12438. // if(!$scope.dir || $scope.dir === '') {
  12439. // $scope.dir = '-';
  12440. // }else {
  12441. // $scope.dir = '';
  12442. // }
  12443. };
  12444. $scope.submit = function(tender) {
  12445. var canSubmit = true;
  12446. var hasPrice = false;
  12447. var hasDecide = false;
  12448. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  12449. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12450. if (saleTenderItem.price) { // 只要存在报价的行,就需要对其中一个定标
  12451. hasPrice = true;
  12452. }
  12453. });
  12454. if (hasPrice) {
  12455. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12456. if (saleTenderItem.applyStatus) { // 只要有一行定标,就可以投标
  12457. hasDecide = true;
  12458. }
  12459. });
  12460. }
  12461. if (!hasDecide) {
  12462. canSubmit = false;
  12463. }
  12464. });
  12465. if (!canSubmit) {
  12466. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  12467. } else {
  12468. PurcTender.decide(tender, function(){
  12469. toaster.pop('success', '确认成功');
  12470. window.location.hash = '#/purc/tender';
  12471. }, function(response){
  12472. toaster.pop('error', '确认失败', response.data);
  12473. });
  12474. }
  12475. }
  12476. }]);
  12477. /**
  12478. * 客户招标
  12479. *
  12480. */
  12481. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  12482. BaseService.scrollBackToTop();
  12483. $scope.active = 'todo';
  12484. /**
  12485. * 改变类型
  12486. */
  12487. var getTypeCondition = function(zone, condition) {
  12488. if(zone == -1) {
  12489. condition.ifOpen = null;
  12490. } else if(zone == 1) {
  12491. condition.ifOpen = 1;
  12492. } else {
  12493. condition.ifOpen = 0;
  12494. }
  12495. };
  12496. $scope.dateZoneText = '不限';
  12497. $scope.typeText = '全部';
  12498. $scope.deliveryZoneText = '不限';
  12499. $scope.condition = {dateZone: -1, deliveryZone: -1, type: -1};
  12500. $scope.changeDateZone = function(zone) {
  12501. $scope.condition.dateZone = zone;
  12502. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  12503. $scope.condition.$dateZoneOpen = false;
  12504. getDateCondition(zone, $scope.condition);
  12505. $scope.tableParams.reload();
  12506. };
  12507. $scope.changeDeliveryZone = function(zone) {
  12508. $scope.condition.deliveryZoneText = zone;
  12509. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  12510. $scope.condition.$delievryZoneOpen = false;
  12511. getDelveryCondition(zone, $scope.condition);
  12512. $scope.tableParams.reload();
  12513. };
  12514. $scope.changeType = function(type) {
  12515. $scope.condition.type = type;
  12516. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  12517. getTypeCondition(type, $scope.condition);
  12518. $scope.tableParams.reload();
  12519. };
  12520. $scope.setActive = function(state) {
  12521. if($scope.active != state) {
  12522. $scope.active = state;
  12523. if($scope.tableParams.page() == 1)
  12524. $scope.tableParams.reload();
  12525. else
  12526. $scope.tableParams.page(1);
  12527. }
  12528. };
  12529. $scope.tableParams = new ngTableParams({
  12530. page : 1,
  12531. count : 5,
  12532. sorting: {
  12533. 'tender.endDate': 'desc',
  12534. 'tender.enterprise.enName': 'asc',
  12535. 'tender.code': 'asc'
  12536. }
  12537. }, {
  12538. total : 0,
  12539. counts: [5, 10, 25, 50],
  12540. getData : function($defer, params) {
  12541. $scope.loading = true;
  12542. var pageParams = params.url();
  12543. var realActive = {};
  12544. pageParams.searchFilter = { // 筛选条件
  12545. keyword: $scope.keyword,
  12546. pt_ifopen: $scope.condition.ifOpen,
  12547. fromDate: getDateTime($scope.condition.dateFrom),
  12548. endDate: getDateTime($scope.condition.dateTo)
  12549. };
  12550. AccountEnterprise.get({}, function(data){
  12551. $scope.loading = false;
  12552. $scope.currentEn = data;
  12553. });
  12554. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  12555. $scope.loading = false;
  12556. if(page) {
  12557. params.total(page.totalElement);
  12558. $defer.resolve(page.content);
  12559. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  12560. angular.forEach(page.content, function(purcTender) {
  12561. purcTender.vendorHasBid = false;
  12562. angular.forEach(purcTender.purchaseTenderProds, function(tenderProd) {
  12563. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12564. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  12565. tenderProd.currentItem = saleTenderItem;
  12566. if (saleTenderItem.price) { //TODO 如果存在当前企业的投标明细已投标,即判断为已投标
  12567. purcTender.vendorHasBid = true;
  12568. }
  12569. }
  12570. });
  12571. });
  12572. });
  12573. }
  12574. }, function(response){
  12575. $scope.loading = false;
  12576. toaster.pop('error', '数据加载失败', response.data);
  12577. });
  12578. }
  12579. });
  12580. $scope.openDatePicker = function($event, item, openParam) {
  12581. $event.preventDefault();
  12582. $event.stopPropagation();
  12583. item[openParam] = !item[openParam];
  12584. };
  12585. $scope.parseDate = function(dateStr) {
  12586. if(dateStr)
  12587. return Date.parse(dateStr, 'yyyy-MM-dd');
  12588. return new Date();
  12589. };
  12590. // 选择查找日期
  12591. $scope.onDateCondition = function(){
  12592. $scope.tableParams.page(1);
  12593. $scope.tableParams.reload();
  12594. };
  12595. // 搜索框回车
  12596. $scope.onSearch = function() {
  12597. $scope.tableParams.page(1);
  12598. $scope.tableParams.reload();
  12599. };
  12600. }]);
  12601. /**
  12602. * 平台公开招标
  12603. *
  12604. */
  12605. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  12606. BaseService.scrollBackToTop();
  12607. /**
  12608. * 改变单据日期范围
  12609. */
  12610. var getTenderDateCondition = function(zone, condition) {
  12611. var date = new Date();
  12612. if(zone == -1) {
  12613. condition.dateFrom = null;
  12614. condition.dateTo = null;
  12615. } else if(zone == 7) { // 一星期内
  12616. date.setDate(date.getDate() - 7);
  12617. condition.dateFrom = date;
  12618. condition.dateTo = new Date();
  12619. } else if(zone == 1) { // 一个月内
  12620. date.setMonth(date.getMonth() - 1);
  12621. condition.dateFrom = date;
  12622. condition.dateTo = new Date();
  12623. } else if(zone == 3) { // 三个月内
  12624. date.setMonth(date.getMonth() - 3);
  12625. condition.dateFrom = date;
  12626. condition.dateTo = new Date();
  12627. } else if (zone == 6) { // 半年内
  12628. date.setMonth(date.getMonth() - 6);
  12629. condition.dateFrom = date;
  12630. condition.dateTo = new Date();
  12631. } else { // 一年内
  12632. date.setYear(date.getYear() - 1);
  12633. condition.dateFrom = date;
  12634. condition.dateTo = new Date();
  12635. }
  12636. };
  12637. $scope.active = 'all';
  12638. $scope.dateZoneText = '不限';
  12639. $scope.deliveryZoneText = '不限';
  12640. $scope.condition = {dateZone: -1};
  12641. $scope.changeDateZone = function(zone) {
  12642. $scope.condition.dateZone = zone;
  12643. $scope.condition.$dateZoneOpen = false;
  12644. getTenderDateCondition(zone, $scope.condition);
  12645. $scope.tableParams.reload();
  12646. };
  12647. $scope.openDatePicker = function($event, item, openParam) {
  12648. $event.preventDefault();
  12649. $event.stopPropagation();
  12650. item[openParam] = !item[openParam];
  12651. };
  12652. $scope.parseDate = function(dateStr) {
  12653. if(dateStr)
  12654. return Date.parse(dateStr, 'yyyy-MM-dd');
  12655. return new Date();
  12656. };
  12657. // 选择查找日期
  12658. $scope.onDateCondition = function(){
  12659. $scope.tableParams.page(1);
  12660. $scope.tableParams.reload();
  12661. };
  12662. // $scope.setActive = function(state) {
  12663. // if($scope.active != state) {
  12664. // $scope.active = state;
  12665. // if($scope.tableParams.page() == 1)
  12666. // $scope.tableParams.reload();
  12667. // else
  12668. // $scope.tableParams.page(1);
  12669. // }
  12670. // };
  12671. var getOpenState = function(active) {
  12672. var fn = 'getOpenAll';
  12673. switch(active) {
  12674. case 'all':
  12675. fn = 'getOpenAll';break;
  12676. // case 'done':
  12677. // fn = 'getOpenDone';break;
  12678. case 'todo':
  12679. fn = 'getOpenTodo';break;
  12680. case 'end':
  12681. fn = 'getOpenEnd';break;
  12682. // case 'waiting':
  12683. // fn = 'getOpenWaiting';break;
  12684. }
  12685. return fn;
  12686. };
  12687. $scope.tableParams = new ngTableParams({
  12688. page : 1,
  12689. count : 20,
  12690. sorting: {
  12691. 'tender.endDate': 'desc',
  12692. 'tender.enterprise.enName': 'asc',
  12693. 'tender.code': 'asc'
  12694. }
  12695. }, {
  12696. total : 0,
  12697. counts: [],
  12698. getData : function($defer, params) {
  12699. $scope.loading = true;
  12700. var pageParams = params.url();
  12701. var realActive = {};
  12702. pageParams.searchFilter = { // 筛选条件
  12703. keyword: $scope.keyword,
  12704. fromDate: getDateTime($scope.condition.dateFrom),
  12705. endDate: getDateTime($scope.condition.dateTo)
  12706. };
  12707. AccountEnterprise.get({}, function(data){
  12708. $scope.loading = false;
  12709. $scope.currentEn = data;
  12710. });
  12711. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  12712. $scope.loading = false;
  12713. if(page) {
  12714. params.total(page.totalElement);
  12715. $defer.resolve(page.content);
  12716. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  12717. }
  12718. }, function(response){
  12719. $scope.loading = false;
  12720. toaster.pop('error', '数据加载失败', response.data);
  12721. });
  12722. }
  12723. });
  12724. $scope.toDetail = function(id) {
  12725. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  12726. };
  12727. // var stautsItem = [];
  12728. // $scope.getTenderStatus = function (tender) {
  12729. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  12730. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  12731. // stautsItem = thisItem;
  12732. // }
  12733. // });
  12734. // if (!stautsItem.price) {
  12735. // return "daitoubiao";
  12736. // } else if (!stautsItem.applystatus) {
  12737. // return "yitoubiao";
  12738. // } else if (stautsItem.applystatus == 1) {
  12739. // return "zhongbiao";
  12740. // } else if (stautsItem.applystatus == 0) {
  12741. // return "weizhongbiao";
  12742. // }
  12743. // };
  12744. // 搜索框回车
  12745. $scope.onSearch = function() {
  12746. $scope.tableParams.page(1);
  12747. $scope.tableParams.reload();
  12748. };
  12749. }]);
  12750. /**
  12751. * 采购方查看供应商投标单
  12752. */
  12753. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  12754. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  12755. // $scope.item = data; // 供应商查看
  12756. // $scope.loading = false;
  12757. // }, function(response){
  12758. // $scope.loading = false;
  12759. // toaster.pop('error', '数据加载失败', response.data);
  12760. // });
  12761. PurcTender.getOne({id: $stateParams.id}, function(data){
  12762. $scope.bid = data;
  12763. var vendUU = Number($stateParams.vendUU);
  12764. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  12765. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12766. if (saleTenderItem.saleTender.vendUU === vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  12767. tenderProd.currentItem = saleTenderItem;
  12768. $scope.saleTender = saleTenderItem.saleTender;
  12769. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  12770. }
  12771. });
  12772. });
  12773. }, function(response){
  12774. toaster.pop('error', '数据加载失败', response.data);
  12775. });
  12776. }]);
  12777. /**
  12778. * 查看投标单详情
  12779. */
  12780. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise) {
  12781. BaseService.scrollBackToTop();
  12782. if (!$scope.attaches) {
  12783. $scope.attaches = []; // 存放上传了的附件
  12784. }
  12785. // var staticItem = null;
  12786. // $scope.loading = true;
  12787. // PurcTender.getItem({id: $stateParams.id}, function(data){
  12788. // $scope.item = data; // 用于投标
  12789. // if ($scope.item.enterpriseBaseInfo != null) {
  12790. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  12791. // }
  12792. // staticItem = angular.copy(data);
  12793. // $scope.loading = false;
  12794. // }, function(response){
  12795. // $scope.loading = false;
  12796. // toaster.pop('error', '数据加载失败', response.data);
  12797. // });
  12798. var sleep = function (d){
  12799. for(var t = Date.now();Date.now() - t <= d;);
  12800. };
  12801. AccountEnterprise.get({}, function(data){
  12802. $scope.currentEn = data;
  12803. });
  12804. PurcTender.getOne({id: $stateParams.id}, function(data){
  12805. $scope.bid = data;
  12806. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  12807. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12808. if (!$scope.currentEn) {
  12809. AccountEnterprise.get({}, function(data){
  12810. $scope.currentEn = data;
  12811. });
  12812. }
  12813. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  12814. tenderProd.currentItem = saleTenderItem;
  12815. $scope.saleTender = saleTenderItem.saleTender;
  12816. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  12817. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  12818. }
  12819. });
  12820. });
  12821. }, function(response){
  12822. toaster.pop('error', '数据加载失败', response.data);
  12823. });
  12824. $scope.upload = function(myFile) { // 上传附件
  12825. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  12826. $upload.upload({
  12827. url: 'tender/addTenderItemAttach',
  12828. file: file,
  12829. method: 'POST'
  12830. }).success(function (attach) {
  12831. $scope.attaches.push(attach);
  12832. });
  12833. };
  12834. $scope.removeAttach = function(attachId, index) {
  12835. $scope.attaches.splice(index, 1);
  12836. // PurcTender.removeAttach({attachId : id}, {}, function() {
  12837. //
  12838. // });
  12839. };
  12840. var taxrateYes = false;
  12841. var cycleYes = false;
  12842. var priceYes = false;
  12843. $scope.canSave = false;
  12844. $scope.validateThis = function(value, type) {
  12845. switch(type) {
  12846. case 'taxrate':
  12847. var regex = /^\+?[0-9][0-9]{0,1}$/;
  12848. if (regex.test(value)) {
  12849. taxrateYes = true;
  12850. } else {
  12851. if (value) {
  12852. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  12853. }
  12854. }
  12855. break;
  12856. case 'cycle':
  12857. regex = /^\+?[1-9][0-9]*$/;
  12858. if (regex.test(value)) {
  12859. cycleYes = true;
  12860. } else {
  12861. if (value) {
  12862. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  12863. }
  12864. }
  12865. break;
  12866. case 'price':
  12867. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  12868. if (regex.test(value) && value !== 0) {
  12869. priceYes = true;
  12870. } else {
  12871. if (value) {
  12872. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  12873. }
  12874. }
  12875. break;
  12876. }
  12877. };
  12878. $scope.emNumYes = true;
  12879. $scope.validEmNum = function (value) {
  12880. var regex = /^\+?[1-9][0-9]*$/;
  12881. if (!regex.test(value) || value === 0 || value !== null) {
  12882. $scope.emNumYes = false;
  12883. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  12884. }
  12885. };
  12886. $scope.validateProds = function(tenderProd) {
  12887. $scope.canSave = true;
  12888. if (tenderProd.currentItem.cycle || tenderProd.currentItem.taxrate || tenderProd.currentItem.price) {
  12889. var cycleRegex = /^\+?[1-9][0-9]*$/;
  12890. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  12891. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  12892. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  12893. // 判断填写过的有为0或不符合正则式的,设置不能保存
  12894. if (!cycleRegex.test(tenderProd.currentItem.cycle) || !taxrateRegex.test(tenderProd.currentItem.taxrate) || !priceRegex.test(tenderProd.currentItem.price)) {
  12895. $scope.canSave = false;
  12896. } else {
  12897. $scope.canSave = true;
  12898. }
  12899. }
  12900. };
  12901. // 投标
  12902. $scope.bidIt = function(tender, currentEnBaseInfo){
  12903. $scope.loading = true;
  12904. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  12905. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  12906. }
  12907. var saleTenderItems = [];
  12908. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  12909. if (tenderProd.currentItem) {
  12910. if ("" !== tenderProd.currentItem.price && "" !== tenderProd.currentItem.taxrate && "" !== tenderProd.currentItem.cycle) {
  12911. tenderProd.currentItem.saleTender = {};
  12912. saleTenderItems.push(tenderProd.currentItem);
  12913. }
  12914. }
  12915. });
  12916. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  12917. $scope.loading = false;
  12918. toaster.pop('info', '成功', '投标成功');
  12919. // $window.location.reload();
  12920. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  12921. // window.location.hash = '#/sale/opentender';
  12922. // } else {
  12923. window.location.hash = '#/sale/tender';
  12924. // }
  12925. }, function(response){
  12926. $scope.loading = false;
  12927. toaster.pop('error', '投标失败', '出现异常,投标失败');
  12928. });
  12929. };
  12930. $scope.condition = {
  12931. $fromOpened:false
  12932. };
  12933. $scope.getMaxDate = function() {
  12934. return $filter('date')(new Date(), 'yyyy-MM-dd');
  12935. };
  12936. $scope.openDatePicker = function($event, item, openParam) {
  12937. $event.preventDefault();
  12938. $event.stopPropagation();
  12939. item[openParam] = !item[openParam];
  12940. };
  12941. }]);
  12942. /**
  12943. * 公开招标转投标单
  12944. */
  12945. app.controller('OpenSaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise) {
  12946. BaseService.scrollBackToTop();
  12947. $scope.attaches = []; // 存放上传了的附件
  12948. var sleep = function (d){
  12949. for(var t = Date.now();Date.now() - t <= d;);
  12950. }
  12951. var getCurrentEn = function() {
  12952. AccountEnterprise.get({}, function(data){
  12953. $scope.currentEn = data;
  12954. });
  12955. }
  12956. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  12957. $scope.loading = true;
  12958. getCurrentEn();
  12959. PurcTender.getOne({id: $stateParams.id}, function(data){
  12960. data.$editing = false;
  12961. $scope.tender = data;
  12962. $scope.tenderProd = data.purchaseTenderProds;
  12963. // parseCertificate($scope.tender.certificate);
  12964. // $scope.firstProd = data.purchaseTenderProds[0];
  12965. $scope.currentHasBid = false; // 默认当前企业未转投标单
  12966. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  12967. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  12968. $scope.currentHasBid = true;
  12969. }
  12970. });
  12971. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  12972. // console.log($scope.tenderProd.enterpriseBaseInfo);
  12973. $scope.loading = false;
  12974. $scope.attaches = $scope.tender.tenderAttaches;
  12975. }, function(response){
  12976. $scope.loading = false;
  12977. toaster.pop('error', '数据加载失败', response.data);
  12978. });
  12979. }
  12980. $scope.hasClick = false;
  12981. $scope.iWantToBid = function(id) {
  12982. $scope.hasClick = true;
  12983. PurcTender.addItems({id: id}, {}, function(data){ // 添加明细
  12984. // $scope.tender = data;
  12985. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  12986. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12987. // if (!$scope.currentEn) {
  12988. // AccountEnterprise.get({}, function(data){
  12989. // $scope.currentEn = data;
  12990. // });
  12991. // }
  12992. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  12993. // tenderProd.currentItem = saleTenderItem;
  12994. // $scope.saleTender = saleTenderItem.saleTender;
  12995. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  12996. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  12997. // }
  12998. // });
  12999. // });
  13000. toaster.pop('success', '成功', '转投标单成功');
  13001. window.location.hash = "#/sale/tender/" + id;
  13002. }, function(response){
  13003. toaster.pop('error', '操作失败', response.data);
  13004. });
  13005. // $scope.upload = function(myFile) { // 上传附件
  13006. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  13007. // $upload.upload({
  13008. // url: 'tender/addTenderItemAttach',
  13009. // file: file,
  13010. // method: 'POST'
  13011. // }).success(function (attach) {
  13012. // $scope.attaches.push(attach);
  13013. // });
  13014. // };
  13015. };
  13016. // $scope.removeAttach = function(id, index) {
  13017. // $scope.attaches.splice(index, 1);
  13018. // PurcTender.removeAttach({attachId:id}, function() {
  13019. //
  13020. // });
  13021. // };
  13022. // var taxrateYes = false;
  13023. // var cycleYes = false;
  13024. // var priceYes = false;
  13025. // $scope.canSave = false;
  13026. // $scope.validateThis = function(value, type) {
  13027. // switch(type) {
  13028. // case 'taxrate':
  13029. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  13030. // if (regex.test(value)) {
  13031. // taxrateYes = true;
  13032. // } else {
  13033. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  13034. // }
  13035. // break;
  13036. // case 'cycle':
  13037. // regex = /^\+?[1-9][0-9]*$/;
  13038. // if (regex.test(value)) {
  13039. // cycleYes = true;
  13040. // } else {
  13041. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  13042. // }
  13043. // break;
  13044. // case 'price':
  13045. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13046. // if (regex.test(value) && value !== 0) {
  13047. // priceYes = true;
  13048. // } else {
  13049. // if (!(value instanceof Number) || value) {
  13050. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  13051. // }
  13052. // }
  13053. // break;
  13054. // }
  13055. // };
  13056. //
  13057. // $scope.emNumYes = true;
  13058. //
  13059. // $scope.validEmNum = function (value) {
  13060. // var regex = /^\+?[1-9][0-9]*$/;
  13061. // if (!regex.test(value) || value == 0 || value !== null) {
  13062. // $scope.emNumYes = false;
  13063. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  13064. // }
  13065. // };
  13066. //
  13067. // $scope.validateProds = function(tenderProd) {
  13068. // // angular.forEach(tenderProds, function (tenderProd) {
  13069. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  13070. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  13071. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  13072. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13073. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  13074. // console.log(tenderProd.currentItem.cycle);
  13075. // if (tenderProd.currentItem.cycle !== null && (!cycleRegex.test(tenderProd.currentItem.cycle)) || (tenderProd.currentItem.taxrate !== null && !taxrateRegex.test(tenderProd.currentItem.taxrate)) || (tenderProd.currentItem.price !==null && (!priceRegex.test(tenderProd.currentItem.price) && tenderProd.currentItem.price !== 0))) {
  13076. // $scope.canSave = false;
  13077. // } else {
  13078. // $scope.canSave = true;
  13079. // }
  13080. // // });
  13081. // };
  13082. //
  13083. // // 投标
  13084. // $scope.bidIt = function(tender, currentEnBaseInfo){
  13085. // $scope.loading = true;
  13086. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  13087. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  13088. // }
  13089. // var saleTenderItems = [];
  13090. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  13091. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13092. // if (tenderProd.currentItem) {
  13093. // tenderProd.currentItem.saleTender = {};
  13094. // saleTenderItems.push(tenderProd.currentItem);
  13095. // }
  13096. // });
  13097. // } else {
  13098. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13099. // if (tenderProd.currentItem) {
  13100. // saleTenderItems.push(tenderProd.currentItem);
  13101. // }
  13102. // });
  13103. // }
  13104. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  13105. // $scope.loading = false;
  13106. // toaster.pop('info', '成功', '投标成功');
  13107. // // $window.location.reload();
  13108. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  13109. // // window.location.hash = '#/sale/opentender';
  13110. // // } else {
  13111. // window.location.hash = '#/sale/tender';
  13112. // // }
  13113. // }, function(response){
  13114. // $scope.loading = false;
  13115. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  13116. // });
  13117. //
  13118. // };
  13119. //
  13120. // $scope.condition = {
  13121. // $fromOpened:false
  13122. // };
  13123. //
  13124. // $scope.getMaxDate = function() {
  13125. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  13126. // };
  13127. //
  13128. // $scope.openDatePicker = function($event, item, openParam) {
  13129. // $event.preventDefault();
  13130. // $event.stopPropagation();
  13131. // item[openParam] = !item[openParam];
  13132. // };
  13133. }]);
  13134. // 基础资料客户详情
  13135. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', 'VendorInfo', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster, VendorInfo){
  13136. BaseService.scrollBackToTop();
  13137. $scope.status = 'customer';
  13138. $scope.userInfoResult = true;
  13139. AuthenticationService.getAuthentication().success(function(data) {
  13140. $scope.loading = false;
  13141. $scope.thisUser = data;
  13142. });
  13143. $scope.customerParams = new ngTableParams({
  13144. page : 1,
  13145. count : 10
  13146. }, {
  13147. total : 0,
  13148. counts: [],
  13149. getData : function($defer, params) {
  13150. $scope.loading = true;
  13151. var pageParams = params.url();
  13152. pageParams.keyword = $scope.keyword;
  13153. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  13154. $scope.loading = false;
  13155. if(page) {
  13156. params.total(page.totalElement);
  13157. $defer.resolve(page.content);
  13158. }
  13159. $scope.totalCount = page.totalElement;
  13160. }, function(response){
  13161. $scope.loading = false;
  13162. toaster.pop('error', '数据加载失败', response.data);
  13163. });
  13164. }
  13165. });
  13166. // 搜索框回车
  13167. $scope.onSearch = function(keyword) {
  13168. $scope.customerParams.page(1);
  13169. $scope.customerParams.reload();
  13170. $scope.tip = keyword;
  13171. };
  13172. // 查看详情
  13173. $scope.viewDetail = function(id) {
  13174. window.location.hash = "#/sale/customer/" + id;
  13175. }
  13176. // 取消合作关系
  13177. $scope.disableCust = function(id) {
  13178. VendorInfo.disableCust({id: id}, {}, function(data) {
  13179. if(data.success) {
  13180. toaster.pop('success', '提示', data.success);
  13181. }
  13182. $scope.customerParams.page(1);
  13183. $scope.customerParams.reload();
  13184. }, function(response) {
  13185. toaster.pop('error', '提示', response.data);
  13186. });
  13187. }
  13188. // 解除禁用
  13189. $scope.activeCust = function(id) {
  13190. VendorInfo.activeCust({id: id}, {}, function(data) {
  13191. if(data.success) {
  13192. toaster.pop('success', '提示', data.success);
  13193. }
  13194. $scope.customerParams.page(1);
  13195. $scope.customerParams.reload();
  13196. }, function(response) {
  13197. toaster.pop('error', '提示', response.data);
  13198. });
  13199. }
  13200. }]);
  13201. // 基础资料供应商
  13202. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  13203. BaseService.scrollBackToTop();
  13204. $scope.status = 'vendor';
  13205. // 搜索框回车
  13206. $scope.onSearch = function(keyword) {
  13207. $scope.keyword = keyword;
  13208. $scope.customerParams.page(1);
  13209. $scope.customerParams.reload();
  13210. };
  13211. $scope.customerParams = new ngTableParams({
  13212. page : 1,
  13213. count : 10
  13214. }, {
  13215. total : 0,
  13216. counts: [],
  13217. getData : function($defer, params) {
  13218. $scope.loading = true;
  13219. var pageParams = params.url();
  13220. pageParams.keyword = $scope.keyword;
  13221. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  13222. $scope.loading = false;
  13223. if(page) {
  13224. params.total(page.totalElement);
  13225. $scope.total = page.totalElement;
  13226. $defer.resolve(page.content);
  13227. }
  13228. $scope.totalCount = page.totalElements;
  13229. }, function(response){
  13230. $scope.loading = false;
  13231. toaster.pop('error', '数据加载失败', response.data);
  13232. });
  13233. }
  13234. });
  13235. // 查看供应商详情
  13236. $scope.VendorDetail = function(id, uu) {
  13237. $rootScope.vendorId = id;
  13238. $rootScope.vendoruu = uu;
  13239. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  13240. }
  13241. // 向企业购买
  13242. $scope.purcByEn = function(businessCode) {
  13243. $rootScope.businessCode = businessCode;
  13244. window.location.hash = "#/purc/addOrder";
  13245. }
  13246. // 取消合作关系
  13247. $scope.relieve = function(id) {
  13248. VendorInfo.relieve({id: id}, {}, function(data) {
  13249. if(data.success) {
  13250. toaster.pop('success', '提示', data.success);
  13251. }
  13252. $scope.customerParams.page(1);
  13253. $scope.customerParams.reload();
  13254. }, function(response) {
  13255. toaster.pop('error', '提示', response.data);
  13256. });
  13257. }
  13258. // 建立合作关系
  13259. $scope.activeVend = function(id) {
  13260. VendorInfo.activeVend({id: id}, {}, function(data) {
  13261. if(data.success) {
  13262. toaster.pop('success', '提示', data.success);
  13263. }
  13264. $scope.customerParams.page(1);
  13265. $scope.customerParams.reload();
  13266. }, function(response) {
  13267. toaster.pop('error', '提示', response.data);
  13268. });
  13269. }
  13270. }]);
  13271. // 企业圈搜索界面
  13272. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  13273. $scope.onSearch = function(keyword) {
  13274. $rootScope.enterpriseKeyword = keyword;
  13275. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  13276. }
  13277. }]);
  13278. // 企业圈搜索结果
  13279. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  13280. $scope.status = 'add';
  13281. BaseService.scrollBackToTop();
  13282. $scope.active = 'all';
  13283. $scope.agreedText = '全部';
  13284. $scope.dateZoneText = '一个月内';
  13285. $scope.condition = {dateZone: 1};
  13286. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13287. $scope.changeAgreed = function(agreed) {
  13288. $scope.condition.agreed = agreed;
  13289. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13290. $scope.condition.$agreedOpen = false;
  13291. };
  13292. $scope.changeDateZone = function(zone) {
  13293. $scope.condition.dateZone = zone;
  13294. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13295. $scope.condition.$dateZoneOpen = false;
  13296. getDateCondition(zone, $scope.condition);
  13297. $scope.tableParams.reload();
  13298. };
  13299. $scope.setActive = function(state) {
  13300. if($scope.active != state) {
  13301. $scope.active = state;
  13302. if($scope.tableParams.page() == 1)
  13303. $scope.tableParams.reload();
  13304. else
  13305. $scope.tableParams.page(1);
  13306. }
  13307. };
  13308. var getService = function() {
  13309. return getAccountUserSpace;
  13310. };
  13311. $scope.tableParams = new ngTableParams({
  13312. page : 1,
  13313. count : 10,
  13314. sorting: {
  13315. }
  13316. }, {
  13317. total : 0,
  13318. counts: [],
  13319. getData : function($defer, params) {
  13320. $scope.loading = true;
  13321. var pageParams = params.url();
  13322. pageParams.keyword = $scope.keyword;
  13323. $scope.tip = $scope.keyword;
  13324. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  13325. $scope.loading = false;
  13326. if(page) {
  13327. params.total(page.totalElement);
  13328. $defer.resolve(page.content);
  13329. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13330. }
  13331. }, function(response) {
  13332. $scope.loading = false;
  13333. toaster.pop('error', '数据加载失败', response.data);
  13334. });
  13335. }
  13336. });
  13337. // 搜索框回车
  13338. $scope.onSearch = function(keyword) {
  13339. if($scope.keyword != null && $scope.keyword != '') {
  13340. $rootScope.searchKeyword = keyword;
  13341. $scope.keyword = keyword;
  13342. $scope.tableParams.page(1);
  13343. $scope.tableParams.reload();
  13344. }
  13345. };
  13346. // 添加合作关系
  13347. $scope.addPartner = function(name, businessCode) {
  13348. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  13349. if(data.success) {
  13350. toaster.pop("success", '添加成功', data.success);
  13351. }
  13352. if(data.error) {
  13353. toaster.pop("error", '添加失败', data.error);
  13354. }
  13355. }, function(response) {
  13356. toaster.pop('error','失败',response.data);
  13357. });
  13358. }
  13359. /**
  13360. * 邀请注册商务平台
  13361. */
  13362. $scope.invite = function(name) {
  13363. var modalInstance = $modal.open({
  13364. animation: true,
  13365. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  13366. controller: 'InviteCtrl',
  13367. resolve: {
  13368. enname: function(){return name}
  13369. }
  13370. });
  13371. modalInstance.result.then(function(data) {
  13372. InvitationRecord.invite({formStore: data}, {}, function(data) {
  13373. if(data.success) {
  13374. toaster.pop('success', '提示', data.success);
  13375. }
  13376. if(data.error) {
  13377. toaster.pop('error', '提示', data.error);
  13378. }
  13379. }, function(response) {
  13380. toaster.pop('error', '提示', response.data);
  13381. });
  13382. });
  13383. }
  13384. /**
  13385. * 立即查看
  13386. */
  13387. $scope.view = function(name) {
  13388. $rootScope.vendName = name;
  13389. window.location.hash = "#/baseInfo/myRquest";
  13390. }
  13391. }]);
  13392. // 平台新增的询价单(指定一个供应商)
  13393. app.controller('PurcInquiryNewCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', '$http', 'ShipAddress', '$stateParams', 'Vendor', 'Product', 'Search', 'ComponentActiveAPI', 'VendorInfo', function($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout, $http, ShipAddress, $stateParams, Vendor, Product, Search, ComponentActiveAPI, VendorInfo) {
  13394. $scope.active = 'all';
  13395. // 供应商信息
  13396. var loadData = function() {
  13397. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function(data) {
  13398. $scope.vendor = data;
  13399. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  13400. $scope.vendorContacts = data;
  13401. });
  13402. // 物料信息
  13403. $scope.tableParams = new ngTableParams({
  13404. page : 1,
  13405. count : 10
  13406. }, {
  13407. total : 0,
  13408. counts: [5, 10, 25, 50],
  13409. getData : function($defer, params) {
  13410. $scope.loading = true;
  13411. var pageParams = params.url();
  13412. pageParams.keyword = $scope.keyword;
  13413. $scope.tip = $scope.keyword;
  13414. pageParams.custUU = $scope.vendor.uu;
  13415. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  13416. $scope.loading = false;
  13417. if(page) {
  13418. params.total(page.totalElement);
  13419. $scope.total = page.totalElement;
  13420. $defer.resolve(page.content);
  13421. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13422. }
  13423. }, function(response){
  13424. $scope.loading = false;
  13425. toaster.pop('error', '数据加载失败', response.data);
  13426. });
  13427. }
  13428. });
  13429. });
  13430. };
  13431. loadData();
  13432. $rootScope.tenderVendor = null;// 清除掉已选择的
  13433. var getService = function() {
  13434. return GetProductInfo;
  13435. };
  13436. $scope.inquiry = {
  13437. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  13438. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  13439. priceType: '采购',
  13440. isOpen: 1,
  13441. invoice: 0,
  13442. ifTax: 1,
  13443. currency: 'RMB'
  13444. };
  13445. $scope.changeCurrency = function(inquiry) {
  13446. if (inquiry.currency !== 'RMB') {
  13447. $scope.notRMB = true;
  13448. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  13449. inquiry.invoice = 0;
  13450. } else {
  13451. $scope.notRMB = false;
  13452. }
  13453. };
  13454. // 获取收货地址列表
  13455. var loadShipAddress = function() {
  13456. ShipAddress.shipAddList({}, function(data) {
  13457. $scope.ships = data;
  13458. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  13459. });
  13460. };
  13461. loadShipAddress();
  13462. // 获取地址信息
  13463. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  13464. }).then(function(response) {
  13465. $scope.provinces = response.data;
  13466. });
  13467. // 新增收货地址保存
  13468. $scope.saveShipAddress = function(ship) {
  13469. ship.address = ship.province + ship.city + ship.district;
  13470. ShipAddress.saveAddress( {}, ship, function(data) {
  13471. if(data.success) {
  13472. // 获取收货地址列表
  13473. loadShipAddress();
  13474. toaster.pop('success', '提示', data.success);
  13475. }
  13476. if(data.error) {
  13477. toaster.pop('error', '提示', data.error);
  13478. }
  13479. });
  13480. };
  13481. $scope.currentDay = function() {
  13482. return $filter('date')(new Date(), 'yyyy-MM-dd');
  13483. };
  13484. // 搜索框回车
  13485. $scope.onSearch = function(keyword) {
  13486. $scope.tableParams.page(1);
  13487. $scope.tableParams.reload();
  13488. };
  13489. $scope.inquiry.inquiryItems = [];
  13490. var prod = {
  13491. prodCode: null,
  13492. prodTitle: null,
  13493. inbrand: null,
  13494. currency: 'RMB',
  13495. toDate: null,
  13496. unit: 'PCS'
  13497. };
  13498. $scope.inquiry.inquiryItems.push(prod);
  13499. // 联想词start
  13500. // 获取品牌联想词
  13501. $scope.getSimilarBrands = function(value) {
  13502. if (value) {
  13503. // 获取品牌联想词
  13504. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  13505. return data.map(function(item) {
  13506. return item;
  13507. });
  13508. });
  13509. }
  13510. };
  13511. // 获取产品型号联想词
  13512. $scope.getSimilarCodes = function(value) {
  13513. if (value) {
  13514. // 获取产品型号联想词
  13515. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  13516. return data.map(function (item) {
  13517. return item;
  13518. })
  13519. });
  13520. }
  13521. };
  13522. $scope.selectKind = function(prod) {
  13523. var submit = [];
  13524. $modal.open({
  13525. animation: true,
  13526. size: 'lg',
  13527. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  13528. controller: 'ProdKindChooseCtrl',
  13529. resolve: {
  13530. actives: function() {
  13531. return $scope.actives;
  13532. }
  13533. }
  13534. }).result.then(function(data){
  13535. $scope.actives = data.actives;
  13536. var size = data.actives.length;
  13537. submit.gradeOneKiName = '';
  13538. submit.gradeTwoKiName = '';
  13539. submit.gradeThreeKiName = '';
  13540. if (size > 0) {
  13541. submit.gradeOneKiName = $scope.actives[0].nameCn;
  13542. prod.prodTitle = submit.gradeOneKiName;
  13543. if (size > 1) {
  13544. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  13545. prod.prodTitle = submit.gradeTwoKiName;
  13546. if (size > 2) {
  13547. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  13548. prod.prodTitle = submit.gradeThreeKiName;
  13549. }
  13550. }
  13551. }
  13552. }, function(){
  13553. });
  13554. };
  13555. // 点击联想词获取品牌信息
  13556. $scope.onAssociateBrandClick = function(brand, prod) {
  13557. if (brand instanceof String) {
  13558. prod.inbrand = brand;
  13559. } else if (brand instanceof Object) {
  13560. prod.inbrand = brand.brandCn;
  13561. }
  13562. };
  13563. // 打开品牌选择的模态框
  13564. $scope.selectBrand = function(prod){ //打开模态
  13565. var modalInstance = $modal.open({
  13566. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  13567. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  13568. });
  13569. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  13570. });
  13571. modalInstance.result.then(function(brand){
  13572. prod.inbrand = brand.nameCn;
  13573. }, function(reason){
  13574. });
  13575. };
  13576. // 点击联想词获取器件信息 带入产品分类和品牌
  13577. $scope.onAssociateCmpClick = function(cmp, prod) {
  13578. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  13579. $scope.component = data;
  13580. prod.prodCode = data.code;
  13581. prod.prodTitle = data.kind.nameCn;
  13582. prod.inbrand = data.brand.nameCn;
  13583. }, function(res) {
  13584. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  13585. })
  13586. };
  13587. //联想词end
  13588. // 导入商品信息
  13589. $scope.uplodaByBatch = function() {
  13590. var modalInstance = $modal.open({
  13591. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  13592. controller: 'PurcInquiryUploadCtrl',
  13593. size: 'lg',
  13594. resolve: {
  13595. }
  13596. });
  13597. modalInstance.result.then(function(data) {
  13598. angular.forEach(data, function(prod) {
  13599. console.log(prod);
  13600. $scope.inquiry.inquiryItems.push(prod);
  13601. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  13602. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  13603. $scope.inquiry.inquiryItems.splice(i, 1);
  13604. }
  13605. }
  13606. })
  13607. }, function(){
  13608. });
  13609. }
  13610. //增加商品
  13611. $scope.add = function() {
  13612. $scope.inquiry.inquiryItems.push(
  13613. { prodCode: null,
  13614. prodTitle: null,
  13615. unit: 'PCS',
  13616. ibrand: null,
  13617. currency: 'RMB',
  13618. toDate: null});
  13619. };
  13620. //删除商品
  13621. $scope.del = function(index) {
  13622. $scope.inquiry.inquiryItems.splice(index, 1);
  13623. };
  13624. // 搜索结果询价
  13625. if($rootScope.prodId) {
  13626. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  13627. prod.prodCode = data.code;
  13628. prod.prodTitle = data.title;
  13629. prod.spec = data.spec;
  13630. prod.unit = data.unit;
  13631. prod.productId = data.id;
  13632. prod.inbrand = data.brand;
  13633. $scope.inquiry.inquiryItems.push(prod);
  13634. $rootScope.prodId = null;// 清除掉prodId
  13635. }, function(response) {
  13636. });
  13637. }
  13638. $scope.check = function(product) {
  13639. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  13640. currency: null, toDate: null, productId: product.id, inbrand: product.brand});
  13641. }
  13642. $scope.getMinDate = function(item) {
  13643. return $filter('date')(new Date, 'yyyy-MM-dd');
  13644. };
  13645. $scope.openDatePicker = function($event, openParam, index) {
  13646. $event.preventDefault();
  13647. $event.stopPropagation();
  13648. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  13649. };
  13650. $scope.openEndDatePicker = function($event, item, openParam) {
  13651. $event.preventDefault();
  13652. $event.stopPropagation();
  13653. item[openParam] = !item[openParam];
  13654. };
  13655. // 保存并提交
  13656. $scope.submit = function() {
  13657. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  13658. $scope.vendors = [];
  13659. $scope.vendors.push({enName: $scope.vendor.enName, enuu: $scope.vendor.uu});
  13660. $upload.upload({
  13661. url: 'purc/inquiry/saveAndSubmit',
  13662. file: file,
  13663. method: 'POST',
  13664. data: {
  13665. inquiry: $scope.inquiry,
  13666. contacts: $scope.vendors
  13667. },
  13668. }).success(function(data) {
  13669. if(data.success) {
  13670. toaster.pop('success', '提示', data.success);
  13671. $timeout(function() {
  13672. window.location.hash = "#/purc/purchaseinquiry";
  13673. }, 500);
  13674. }
  13675. if(data.error) {
  13676. toaster.pop('error', '提示', data.error);
  13677. }
  13678. }).error(function(data) {
  13679. $scope.loadingShow = false;
  13680. toaster.pop('error', '操作失败', data.error);
  13681. });
  13682. }
  13683. }]);
  13684. // 企业圈查询收到待处理的数目
  13685. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', function($scope, AddPartnerMyRequest) {
  13686. AddPartnerMyRequest.requestAmount({}, function(data) {
  13687. $scope.requestTodo = data;
  13688. });
  13689. }]);
  13690. // 当前企业所有的物料信息
  13691. app.controller('ProductAllCtrl', ['$scope', 'Products', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, Products, ngTableParams, $filter, BaseService, toaster, $timeout) {
  13692. BaseService.scrollBackToTop();
  13693. $scope.active = 'all';
  13694. $scope.agreedText = '全部';
  13695. $scope.dateZoneText = '一个月内';
  13696. $scope.condition = {dateZone: 1};
  13697. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13698. $scope.changeAgreed = function(agreed) {
  13699. $scope.condition.agreed = agreed;
  13700. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13701. $scope.condition.$agreedOpen = false;
  13702. };
  13703. $scope.changeDateZone = function(zone) {
  13704. $scope.condition.dateZone = zone;
  13705. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13706. $scope.condition.$dateZoneOpen = false;
  13707. getDateCondition(zone, $scope.condition);
  13708. $scope.tableParams.reload();
  13709. };
  13710. $scope.setActive = function(state) {
  13711. if($scope.active != state) {
  13712. $scope.active = state;
  13713. if($scope.tableParams.page() == 1)
  13714. $scope.tableParams.reload();
  13715. else
  13716. $scope.tableParams.page(1);
  13717. }
  13718. };
  13719. var getService = function() {
  13720. return Products.info;
  13721. };
  13722. $scope.tableParams = new ngTableParams({
  13723. page : 1,
  13724. count : 5,
  13725. sorting: {
  13726. }
  13727. }, {
  13728. total : 0,
  13729. counts: [5, 10, 25, 50],
  13730. getData : function($defer, params) {
  13731. $scope.loading = true;
  13732. var pageParams = params.url();
  13733. pageParams.keyword = $scope.keyword;
  13734. pageParams.searchFilter = $scope.searchFilter;
  13735. getService().call(null, BaseService.parseParams(pageParams), function(page){
  13736. $scope.loading = false;
  13737. if(page) {
  13738. params.total(page.totalElement);
  13739. $defer.resolve(page.content);
  13740. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13741. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  13742. }
  13743. }, function(response) {
  13744. $scope.loading = false;
  13745. toaster.pop('error', '数据加载失败', response.data);
  13746. });
  13747. }
  13748. });
  13749. // 搜索框回车
  13750. $scope.onSearch = function() {
  13751. $scope.tableParams.page(1);
  13752. $scope.tableParams.reload();
  13753. };
  13754. // 开启销售
  13755. $scope.unlock = function(id) {
  13756. Products.unlock({id: id}, {}, function(data) {
  13757. toaster.pop('success', '提示', '操作成功');
  13758. $scope.tableParams.reload();
  13759. }, function(response) {
  13760. toaster.pop('error', '提示', response.data);
  13761. })
  13762. }
  13763. // 关闭销售
  13764. $scope.lock = function(id) {
  13765. Products.lock({id: id}, {}, function(data) {
  13766. toaster.pop('success', '提示', '操作成功');
  13767. $scope.tableParams.reload();
  13768. }, function(response) {
  13769. toaster.pop('error', '提示', response.data);
  13770. })
  13771. }
  13772. }]);
  13773. return app;
  13774. });