app.js 573 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128
  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.deputylog', {
  118. url : "/deputylog",
  119. templateUrl : "static/tpl/index/purc/deputyorders_log.html",
  120. controller : 'DeputyOrderLogCtrl'
  121. }).state('purc.newdeputy', {
  122. url : "/deputy/add",
  123. templateUrl : "static/tpl/index/purc/deputyOrder_new.html",
  124. controller : 'NewDeputyOrderCtrl'
  125. }).state('purc.deputydetail', {
  126. url : "/deputy/:id",
  127. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  128. controller : 'DeputyOrderDetailCtrl'
  129. /* 招标列表 */
  130. }).state('purc.tenderlist', {
  131. url : "/tender",
  132. templateUrl : "static/tpl/index/purc/tenderlist.html",
  133. controller : 'PurcTenderCtrl'
  134. }).state('purc.waiting.tenderlist', {
  135. url : "/tender",
  136. templateUrl : "static/tpl/index/purc/tenderlist.html",
  137. controller : 'PurcTenderCtrl'
  138. }).state('purc.todo.tenderlist', {
  139. url : "/tender/todo",
  140. templateUrl : "static/tpl/index/purc/tenderlist.html",
  141. controller : 'PurcTenderCtrl'
  142. /* 招标 */
  143. }).state('purc.tender', {
  144. url : "/addTender",
  145. templateUrl : "static/tpl/index/purc/tender.html",
  146. controller : 'PurcNewTenderCtrl'
  147. }).state('purc.savedtender', {
  148. url : "/tender/:id",
  149. templateUrl : "static/tpl/index/purc/tender.html",
  150. controller : 'PurcNewTenderCtrl'
  151. /* 评标 */
  152. }).state('purc.evaluation', {
  153. url : "/evaluation/:id",
  154. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  155. controller : 'PurcEvaluationCtrl'
  156. /* 采购供应商资料 */
  157. }).state('purc.vendor', {
  158. url : "/vendor",
  159. templateUrl : "static/tpl/index/purc/vendor.html",
  160. controller : 'PurcVendorCtrl'
  161. /* 采购供应商资料 详情*/
  162. }).state('purc.vendordetail', {
  163. url : "/vendor/:id",
  164. templateUrl : "static/tpl/index/purc/vendor_detail.html",
  165. controller : 'PurcVendorDetailCtrl'
  166. /* 客户指定招标列表 */
  167. }).state('purc.makeoutorder', {
  168. url : "/makeoutorder",
  169. templateUrl : "static/tpl/index/make/outorder.html",
  170. controller: 'MakeOutOrderCtrl'
  171. }).state('purc.outorder_detail', {
  172. url : "/makeoutorder/:id",
  173. templateUrl : "static/tpl/index/make/outorder_detail.html",
  174. controller: 'MakeOutOrderDetailCtrl'
  175. /*平台新增询价单*/
  176. }).state('purc.inquiry_new', {
  177. url : "/purcinquiry",
  178. templateUrl : "static/tpl/index/purc/inquiry_new.html",
  179. controller: 'PurcInquiryCtrl'
  180. }).state('purc.purcinquiry_new', {
  181. url : "/purcinquiry/:bussinessCode",
  182. templateUrl : "static/tpl/index/purc/purcinquiry_new.html",
  183. controller: 'PurcInquiryNewCtrl'
  184. }).state('purc.inquiry', {
  185. url : "/purchaseinquiry",
  186. templateUrl : "static/tpl/index/purc/inquiry.html",
  187. controller: 'PurchaseInquiryCtrl'
  188. }).state('purc.inquiry_detail', {
  189. url : "/purcinquirydetail",
  190. templateUrl : "static/tpl/index/purc/inquiry_detail.html",
  191. controller: 'PurcInquiryDetailCtrl'
  192. }).state('purc.inquiryInfo_detail', {
  193. url : "/purcinquirydetail/:id",
  194. templateUrl : "static/tpl/index/purc/inquiryInfo_detail.html",
  195. controller: 'PurcInquiryInfoDetailCtrl'
  196. }).state('purc.inquiry_unapply', {
  197. url : "/inquiry_unapply",
  198. templateUrl : "static/tpl/index/purc/inquiry_unapply.html",
  199. controller: 'UnapplyInquiryCtrl'
  200. }).state('purc.product', {
  201. url : "/product",
  202. templateUrl : "static/tpl/index/purc/prodList.html",
  203. controller: 'PurcProductCtrl'
  204. }).state('purc.newProduct', {
  205. url : "/newProduct",
  206. templateUrl : "static/tpl/index/purc/newProdInfo.html",
  207. controller : 'PurcNewProdInfoCtrl'
  208. }).state('purc.productDetail', {
  209. url : "/prodList/:id",
  210. templateUrl : "static/tpl/index/purc/productDetail.html",
  211. controller : 'PurcProdDetailCtrl'
  212. }).state('purc.productmatches', {
  213. url : "/productmatches",
  214. templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
  215. controller: 'ProductmatchesForPurcCtrl'
  216. }).state('purc.uploadProduct', {
  217. url : "/uploadProduct",
  218. templateUrl : "static/tpl/index/purc/uploadByBatch.html",
  219. controller: 'UploadProductCtrl'
  220. }).state('sale.tenderlist', {
  221. url : "/tender",
  222. templateUrl : "static/tpl/index/sale/tenderlist.html",
  223. controller : 'SaleTenderCtrl'
  224. }).state('sale.todo.tenderlist', {
  225. url : "/tender",
  226. templateUrl : "static/tpl/index/sale/tenderlist.html",
  227. controller : 'SaleTenderCtrl'
  228. /* 平台公开招标列表 */
  229. }).state('baseInfo.openTenderList', {
  230. url : "/openTenderList",
  231. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  232. controller: 'SaleOpenTenderCtrl'
  233. /* 查看公开招标详情 */
  234. }).state('baseInfo.open_tender_detail', {
  235. url : "/openTenderDetail/:id",
  236. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  237. controller : 'OpenSaleTenderDetailCtrl'
  238. /* 投标 */
  239. }).state('sale.tender', {
  240. url : "/tender/:id",
  241. templateUrl : "static/tpl/index/sale/tender.html",
  242. controller : 'SaleTenderDetailCtrl'
  243. /* 采购方查看供应商投标 */
  244. }).state('sale.vendortender', {
  245. url : "/tender/:vendUU/:id",
  246. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  247. controller : 'SaleVendorTenderDetailCtrl'
  248. }).state('sale.todo', {
  249. url : "/todo",
  250. templateUrl : "static/tpl/index/sale/todo.html"
  251. }).state('sale.todo.inquiry', {
  252. url : "/inquiry",
  253. templateUrl : "static/tpl/index/sale/inquiry.html",
  254. controller: 'SaleInquiryCtrl'
  255. }).state('sale.todo.order', {
  256. url : "/order",
  257. templateUrl : "static/tpl/index/sale/order.html",
  258. controller: 'SaleOrderCtrl'
  259. }).state('sale.todo.change', {
  260. url : "/change",
  261. templateUrl : "static/tpl/index/sale/change.html",
  262. controller: 'SaleChangeCtrl'
  263. }).state('sale.todo.notice', {
  264. url : "/notice",
  265. templateUrl : "static/tpl/index/sale/notice.html",
  266. controller: 'SaleNoticeCtrl'
  267. }).state('sale.customer', {
  268. url : "/customer",
  269. templateUrl : "static/tpl/index/sale/customer.html",
  270. controller: 'CustomerCtrl'
  271. }).state('sale.customer_detail', {
  272. url : "/customer/:id",
  273. templateUrl : "static/tpl/index/sale/customer_detail.html",
  274. controller: 'CustomerDetailCtrl'
  275. }).state('sale.customerProduct', {
  276. url : "/customerProduct",
  277. templateUrl : "static/tpl/index/sale/customer.html",
  278. controller: 'CustomerCtrl'
  279. }).state('sale.inquiry', {
  280. url : "/inquiry",
  281. templateUrl : "static/tpl/index/sale/inquiry.html",
  282. controller: 'SaleInquiryCtrl'
  283. }).state('sale.inquirymould', {
  284. url : "/mould",
  285. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  286. controller: 'SaleInquiryMouldCtrl'
  287. }).state('sale.todo.inquirymould', {
  288. url : "/mould",
  289. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  290. controller: 'SaleInquiryMouldCtrl'
  291. }).state('sale.inquiry_mould_detail', {
  292. url : "/mould/:id",
  293. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  294. controller: 'SaleInquiryMouldDetailCtrl'
  295. }).state('sale.inquiry_detail', {
  296. url : "/inquiry/:id",
  297. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  298. controller: 'SaleInquiryDetailCtrl'
  299. }).state('sale.quotation', {
  300. url : "/quotation",
  301. templateUrl : "static/tpl/index/sale/quotation.html"
  302. }).state('sale.quotation.new', {
  303. url : "/new",
  304. templateUrl : "static/tpl/index/sale/quotation_new.html",
  305. controller: 'SaleQuotationNewCtrl'
  306. }).state('sale.quotation.list', {
  307. url : "/list",
  308. templateUrl : "static/tpl/index/sale/quotation_list.html",
  309. controller: 'SaleQuotationListCtrl'
  310. }).state('sale.quotation.item', {
  311. url : "/:id",
  312. templateUrl : "static/tpl/index/sale/quotation_new.html",
  313. controller: 'SaleQuotationNewCtrl'
  314. }).state('sale.order', {
  315. url : "/order",
  316. templateUrl : "static/tpl/index/sale/order.html",
  317. controller: 'SaleOrderCtrl'
  318. }).state('sale.order_detail', {
  319. url : "/order/:id",
  320. templateUrl : "static/tpl/index/sale/order_detail.html",
  321. controller: 'SaleOrderDetailCtrl'
  322. }).state('sale.change', {
  323. url : "/change",
  324. templateUrl : "static/tpl/index/sale/change.html",
  325. controller: 'SaleChangeCtrl'
  326. }).state('sale.change_detail', {
  327. url : "/change/:id",
  328. templateUrl : "static/tpl/index/sale/change_detail.html",
  329. controller: 'SaleChangeDetailCtrl'
  330. }).state('sale.notice', {
  331. url : "/notice",
  332. templateUrl : "static/tpl/index/sale/notice.html",
  333. controller: 'SaleNoticeCtrl'
  334. }).state('sale.send', {
  335. url : "/send",
  336. templateUrl : "static/tpl/index/sale/send.html",
  337. controller: 'SaleSendCtrl'
  338. }).state('sale.send_detail', {
  339. url : "/send/:id",
  340. templateUrl : "static/tpl/index/sale/send_detail.html",
  341. controller: 'SaleSendDetailCtrl'
  342. }).state('sale.forecast', {
  343. url : "/forecast",
  344. templateUrl : "static/tpl/index/sale/forecast.html",
  345. controller: 'SaleForecastCtrl'
  346. }).state('sale.accept', {
  347. url : "/accept",
  348. templateUrl : "static/tpl/index/sale/accept.html",
  349. controller: 'SaleAcceptCtrl'
  350. }).state('sale.accept_detail', {
  351. url : "/accept/:id",
  352. templateUrl : "static/tpl/index/sale/accept_detail.html",
  353. controller: 'SaleAcceptDetailCtrl'
  354. }).state('sale.returns', {
  355. url : "/returns",
  356. templateUrl : "static/tpl/index/sale/returns.html",
  357. controller: 'SaleReturnsCtrl'
  358. }).state('sale.return_detail', {
  359. url : "/return/:id",
  360. templateUrl : "static/tpl/index/sale/return_detail.html",
  361. controller: 'SaleReturnsDetailCtrl'
  362. }).state('sale.sample', {
  363. url : "/sample",
  364. templateUrl : "static/tpl/index/sale/sample.html",
  365. controller: 'SaleSampleCtrl'
  366. }).state('sale.sample_detail', {
  367. url : "/sample/:id",
  368. templateUrl : "static/tpl/index/sale/sample_detail.html",
  369. controller: 'SaleSampleDetailCtrl'
  370. }).state('sale.approval', {
  371. url : "/approval",
  372. templateUrl : "static/tpl/index/sale/approval.html",
  373. controller: 'SaleApprovalCtrl'
  374. }).state('sale.prodList', {
  375. url : "/prodList",
  376. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  377. controller : 'ProductListCtrl'
  378. }).state('sale.newProdInfo', {
  379. url : "/newProdInfo",
  380. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  381. controller : 'NewProdInfoCtrl'
  382. }).state('sale.uploadByBatch', {
  383. url : "/uploadByBatch",
  384. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  385. controller : 'UploadByBatchCtrl'
  386. }).state('sale.productDetail', {
  387. url : "/prodList/:id",
  388. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  389. controller : 'ProductDetailCtrl'
  390. }).state('sale.productmatches', {
  391. url : "/productmatches",
  392. templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
  393. controller: 'ProductmatchesForSaleCtrl'
  394. }).state('sale.maketodo', {
  395. url : "/maketodo",
  396. templateUrl : "static/tpl/index/make/todo.html"
  397. }).state('sale.maketodo.order', {
  398. url : "/makeorder",
  399. templateUrl : "static/tpl/index/make/order.html",
  400. controller: 'MakeOrderCtrl'
  401. }).state('sale.makeorder', {
  402. url : "/makeorder",
  403. templateUrl : "static/tpl/index/make/order.html",
  404. controller: 'MakeOrderCtrl'
  405. }).state('sale.makeorder_detail', {
  406. url : "/makeorder/:id",
  407. templateUrl : "static/tpl/index/make/order_detail.html",
  408. controller: 'MakeOrderDetailCtrl'
  409. }).state('sale.badOut', {
  410. url : "/badOut",
  411. templateUrl : "static/tpl/index/qc/badOut.html",
  412. controller: 'SaleBadOutCtrl'
  413. }).state('sale.MRB', {
  414. url : "/MRB",
  415. templateUrl : "static/tpl/index/qc/MRB.html",
  416. controller: 'SaleMRBCtrl'
  417. }).state('sale.badIn', {
  418. url : "/badIn",
  419. templateUrl : "static/tpl/index/qc/badIn.html",
  420. controller: 'SaleBadInCtrl'
  421. }).state('sale.makeaccept', {
  422. url : "/makeaccept",
  423. templateUrl : "static/tpl/index/make/accept.html",
  424. controller: 'MakeAcceptCtrl'
  425. }).state('sale.makereturns', {
  426. url : "/makereturns",
  427. templateUrl : "static/tpl/index/make/returns.html",
  428. controller: 'MakeReturnCtrl'
  429. }).state('sale.makechange', {
  430. url : "/makechange",
  431. templateUrl : "static/tpl/index/make/change.html",
  432. controller: 'MakeChangeCtrl'
  433. }).state('sale.makechange_detail', {
  434. url : "/makechange/:id",
  435. templateUrl : "static/tpl/index/make/change_detail.html",
  436. controller: 'MakeChangeDetailCtrl'
  437. }).state('account', {
  438. url : "/account",
  439. views : {
  440. "left-view" : {
  441. templateUrl : "static/tpl/index/account/left.html",
  442. controller: 'LeftCtrl'
  443. },
  444. "right-view" : {
  445. templateUrl : "static/tpl/index/account/right.html"
  446. }
  447. }
  448. }).state('account.index', {
  449. url : "",
  450. templateUrl : "static/tpl/index/account/index.html",
  451. controller: 'RightCtrl'
  452. }).state('account.home', {
  453. url : "/",
  454. templateUrl : "static/tpl/index/account/index.html",
  455. controller: 'RightCtrl'
  456. }).state('baseInfo', {//基础资料
  457. url : "/baseInfo",
  458. views : {
  459. "left-view" : {
  460. },
  461. "right-view" : {
  462. templateUrl : "static/tpl/index/baseInfo/right.html"
  463. }
  464. }
  465. }).state('baseInfo.index', {
  466. url : "/enterpriseList",
  467. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  468. controller: 'EnterpriseListCtrl'
  469. }).state('baseInfo.home', {
  470. url : "/enterpriseList",
  471. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  472. controller: 'EnterpriseListCtrl'
  473. }).state('baseInfo.enterpriseList', {
  474. url : "/enterpriseList",
  475. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  476. controller : 'EnterpriseListCtrl'
  477. }).state('baseInfo.myClient', {
  478. url : "/myClient",
  479. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  480. controller : 'MyClientCtrl'
  481. }).state('baseInfo.mySupplier', {
  482. url : "/mySupplier",
  483. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  484. controller : 'MySupplierCtrl'
  485. }).state('baseInfo.myRequest', {
  486. url : "/myRequest",
  487. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  488. controller : 'AddPartnerRequestCtrl'
  489. }).state('baseInfo.newPartner', {
  490. url : "/newPartner",
  491. templateUrl : "static/tpl/index/baseInfo/newPartner.html",
  492. controller : 'NewPartnerCtrl'
  493. }).state('baseInfo.myMessage', {
  494. url : "/myMessage",
  495. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  496. controller : 'AddPartnerMessageCtrl'
  497. }).state('baseInfo.myPartners', {
  498. url : '/myPartners',
  499. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  500. controller : 'MyPartnersCtrl'
  501. }).state('baseInfo.businessGroups', {
  502. url : '/businessGroups',
  503. controller : 'BusinessGroupsCtrl'
  504. }).state('baseInfo.inquiryList', {
  505. url : '/inquiryList',
  506. templateUrl : "static/tpl/index/baseInfo/inquiry_list.html",
  507. controller : 'PublicInquiryListCtrl'
  508. }).state('baseInfo.inquiryListDetail', {
  509. url : '/inquiryList/:id',
  510. templateUrl : "static/tpl/index/baseInfo/inquiryItem_detail.html",
  511. controller : 'PublicInquiryListDetailCtrl'
  512. }).state('baseInfo.vendorInfo', {
  513. url : '/enume/vendorInfo',
  514. templateUrl : "static/tpl/index/baseInfo/vendorsInfo.html",
  515. controller : 'VendorsInfoCtrl'
  516. }).state('baseInfo.customerInfo', {
  517. url : '/enume/customerInfo',
  518. templateUrl : "static/tpl/index/baseInfo/customersInfo.html",
  519. controller : 'CustomersInfoCtrl'
  520. }).state('baseInfo.enume', {
  521. url : '/enume',
  522. templateUrl : "static/tpl/index/baseInfo/vendorAndCustomer.html",
  523. }).state('baseInfo.partner', {
  524. url : '/partner',
  525. templateUrl : "static/tpl/index/baseInfo/addPartners.html",
  526. controller : 'AddPartnersCtrl'
  527. }).state('baseInfo.partner_searchresult', {
  528. url : '/search',
  529. templateUrl : "static/tpl/index/baseInfo/searchresult.html",
  530. controller : 'EnterpriseSearchCtrl'
  531. }).state('baseInfo.invitation', {
  532. url : '/invitation',
  533. templateUrl : "static/tpl/index/baseInfo/invitation.html",
  534. controller : 'InvitationCtrl'
  535. // }).state('baseInfo.invitationforEn', {
  536. // url : '/invitationforEn',
  537. // templateUrl : "static/tpl/index/baseInfo/invitation.html",
  538. // controller : 'InvitationByEnCtrl'
  539. }).state('qc', {
  540. url : "/qc",
  541. views : {
  542. "left-view" : {
  543. templateUrl : "static/tpl/index/qc/left.html"
  544. },
  545. "right-view" : {
  546. templateUrl : "static/tpl/index/qc/right.html"
  547. }
  548. }
  549. }).state('qc.index', {
  550. url : "",
  551. templateUrl : "static/tpl/index/qc/index.html"
  552. }).state('qc.home', {
  553. url : "/",
  554. templateUrl : "static/tpl/index/qc/index.html"
  555. }).state('fa', {
  556. url : "/fa",
  557. views : {
  558. "left-view" : {
  559. templateUrl : "static/tpl/index/fa/left.html"
  560. },
  561. "right-view" : {
  562. templateUrl : "static/tpl/index/fa/right.html"
  563. }
  564. }
  565. }).state('fa.index', {
  566. url : "",
  567. templateUrl : "static/tpl/index/fa/index.html"
  568. }).state('fa.home', {
  569. url : "/",
  570. templateUrl : "static/tpl/index/fa/index.html"
  571. }).state('fa.apBill', {
  572. url : "/apBill",
  573. templateUrl : "static/tpl/index/fa/apBill.html",
  574. controller: 'SaleApBillCtrl'
  575. }).state('fa.apBill_detail', {
  576. url : "/apBill/:id",
  577. templateUrl : "static/tpl/index/fa/apBill_detail.html",
  578. controller: 'SaleApBillDetailCtrl'
  579. }).state('fa.arCheck', {
  580. url : "/arCheck",
  581. templateUrl : "static/tpl/index/fa/arCheck.html",
  582. controller: 'SaleArCheckCtrl'
  583. }).state('fa.arCheck_detail', {
  584. url : "/arCheck/:id",
  585. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  586. controller: 'SaleArCheckDetailCtrl'
  587. }).state('fa.apCheck', {
  588. url : "/apCheck",
  589. params:{
  590. 'id':null
  591. },
  592. templateUrl : "static/tpl/index/fa/apCheck.html",
  593. controller: 'PurchaseApCheckCtrl'
  594. }).state('fa.apCheck_detail', {
  595. url : "/apCheck/:id",
  596. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  597. controller: 'PurchaseApCheckDetailCtrl'
  598. }).state('fa.apCheckList', {
  599. url : "/apCheckList",
  600. templateUrl : "static/tpl/index/fa/apCheckList.html",
  601. controller: 'PurchaseApCheckListCtrl'
  602. }).state('fa.adjustList', {
  603. url : "/adjustList",
  604. templateUrl : "static/tpl/index/fa/adjustList.html",
  605. controller: 'PurchaseAdjustListCtrl'
  606. }).state('make', {
  607. url : "/make",
  608. views : {
  609. "left-view" : {
  610. templateUrl : "static/tpl/index/make/left.html"
  611. },
  612. "right-view" : {
  613. templateUrl : "static/tpl/index/make/right.html"
  614. }
  615. }
  616. }).state('make.index', {
  617. url : "",
  618. templateUrl : "static/tpl/index/make/index.html"
  619. }).state('make.home', {
  620. url : "/",
  621. templateUrl : "static/tpl/index/make/index.html"
  622. }).state('cs', {// 客户服务
  623. url : "/cs",
  624. views : {
  625. "left-view" : {
  626. templateUrl : "static/tpl/index/cs/left.html"
  627. },
  628. "right-view" : {
  629. templateUrl : "static/tpl/index/cs/right.html"
  630. }
  631. }
  632. }).state('cs.index', {
  633. url : "",
  634. templateUrl : "static/tpl/index/cs/index.html"
  635. }).state('cs.home', {
  636. url : "/",
  637. templateUrl : "static/tpl/index/cs/index.html"
  638. }).state('search', { //顶部搜索
  639. url: "/search?keyword=",
  640. views : {
  641. "left-view" : {
  642. templateUrl : "static/tpl/index/search/left.html"
  643. },
  644. "right-view" : {
  645. templateUrl: "static/tpl/index/search/search_result.html",
  646. controller: 'TopSearchCtrl'
  647. }
  648. }
  649. }).state('approvalflow', { //审批流
  650. url: "/approvalFlow",
  651. views : {
  652. "left-view" : {
  653. templateUrl : "static/tpl/index/approvalFlow/left.html"
  654. },
  655. "right-view" : {
  656. templateUrl: "static/tpl/index/approvalFlow/right.html",
  657. }
  658. }
  659. }).state('approvalflow.flow', {
  660. url : "/flow",
  661. templateUrl : "static/tpl/index/approvalFlow/home.html",
  662. controller: 'approvalFlowCtrl'
  663. }).state('approvalflow.enterprise', {
  664. url : "/enterprise",
  665. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  666. controller: 'EnterpriseCtrl'
  667. }).state('approvalflow.user', {
  668. url : "/user",
  669. templateUrl : "static/tpl/index/approvalFlow/user.html",
  670. controller: 'UserCtrl'
  671. }).state('approvalflow.log', {
  672. url : "/log",
  673. templateUrl : "static/tpl/index/approvalFlow/log.html",
  674. controller: 'LogCtrl'
  675. }).state('approvalflow.resource', {
  676. url : "/resource",
  677. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  678. controller: 'ResourceCtrl'
  679. }).state('approvalflow.role', {
  680. url : "/role",
  681. templateUrl : "static/tpl/index/approvalFlow/role.html",
  682. controller: 'RoleCtrl'
  683. }).state('approvalflow.product', {
  684. url : "/product",
  685. templateUrl : "static/tpl/index/approvalFlow/prodList.html",
  686. controller: 'ProductAllCtrl'
  687. }).state('approvalflow.productmatches', {
  688. url : "/productmatches",
  689. templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
  690. controller: 'ProductmatchesCtrl'
  691. });
  692. $urlRouterProvider.otherwise('/index');
  693. }]);
  694. /**
  695. * 表示符号
  696. */
  697. app.factory('Symbol', function(){
  698. return {
  699. currency: function(cur) {
  700. if(cur == 'RMB') return '¥';
  701. else if(cur == 'USD') return '$';
  702. else if(cur == 'EUR') return '€';
  703. else if(cur == null || cur == '') return '¥';
  704. else return cur;
  705. }
  706. };
  707. }).factory('Lodop',function(){
  708. return {
  709. getLodop:function(oOBJECT,oEMBED){
  710. var CreatedOKLodop7766=null;
  711. /**************************
  712. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  713. IE系列、IE内核系列的浏览器采用oOBJECT,
  714. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  715. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  716. 64位浏览器指向64位的安装程序install_lodop64.exe。
  717. **************************/
  718. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  719. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  720. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  721. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  722. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  723. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  724. var LODOP;
  725. try{
  726. //=====判断浏览器类型:===============
  727. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  728. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  729. //=====如果页面有Lodop就直接使用,没有则新建:==========
  730. if (oOBJECT!=undefined || oEMBED!=undefined) {
  731. if (isIE)
  732. LODOP=oOBJECT;
  733. else
  734. LODOP=oEMBED;
  735. } else {
  736. if (CreatedOKLodop7766==null){
  737. LODOP=document.createElement("object");
  738. LODOP.setAttribute("width",0);
  739. LODOP.setAttribute("height",0);
  740. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  741. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  742. else LODOP.setAttribute("type","application/x-print-lodop");
  743. document.documentElement.appendChild(LODOP);
  744. CreatedOKLodop7766=LODOP;
  745. } else
  746. LODOP=CreatedOKLodop7766;
  747. };
  748. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  749. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  750. if (navigator.userAgent.indexOf('Chrome')>=0)
  751. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  752. if (navigator.userAgent.indexOf('Firefox')>=0)
  753. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  754. if (is64IE) document.write(strHtm64_Install); else
  755. if (isIE) document.write(strHtmInstall); else
  756. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  757. return LODOP;
  758. } else
  759. if (LODOP.VERSION<"6.1.9.8") {
  760. if (is64IE) document.write(strHtm64_Update); else
  761. if (isIE) document.write(strHtmUpdate); else
  762. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  763. return LODOP;
  764. };
  765. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  766. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  767. //============================================================
  768. return LODOP;
  769. } catch(err) {
  770. if (is64IE)
  771. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  772. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  773. return LODOP;
  774. };
  775. }
  776. }
  777. });
  778. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
  779. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  780. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  781. if (routeState.indexOf('/') > -1)
  782. routeState = routeState.substring(0, routeState.indexOf('/'));
  783. if (routeState.indexOf('.') > -1)
  784. routeState = routeState.substring(0, routeState.indexOf('.'));
  785. $scope.routeState = routeState || 'home';
  786. });
  787. $scope.search = function(keyword) {
  788. // if(keyword != null && keyword != '') {
  789. $rootScope.searchKeyword = keyword;
  790. window.location.hash = '#/search?keyword='+keyword;
  791. // }
  792. };
  793. $scope.showMessage = function() {
  794. var $modalInstance = $modal.open({
  795. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  796. controller: 'PagingReleaseCtrl'
  797. });
  798. };
  799. // 连接到询价
  800. $scope.linktoInquiry = function(active) {
  801. $rootScope.active = active;
  802. window.location.href = "#/sale/inquiry";
  803. }
  804. // 连接到招标
  805. $scope.linktoSaleTender = function(active) {
  806. $rootScope.active = active;
  807. window.location.href = "#/sale/tender";
  808. }
  809. // 链接到打样申请
  810. $scope.linktoSample = function(active) {
  811. $rootScope.active = active;
  812. window.location.href = "#/sale/sample";
  813. }
  814. // 链接到采购招标
  815. $scope.linktoPurcTender = function(active) {
  816. $rootScope.tenderActive = active;
  817. window.location.href = "#/purc/tender";
  818. }
  819. $scope.linktoPurcInquiry = function(active) {
  820. $rootScope.active = active;
  821. window.location.href = "#/purc/purchaseinquiry";
  822. }
  823. }]);
  824. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  825. BaseService.scrollBackToTop();
  826. $scope.active = "todo";
  827. $scope.setActive = function(state) {
  828. if($scope.active != state) {
  829. $scope.active = state;
  830. if($scope.tableParams.page() == 1)
  831. $scope.tableParams.reload();
  832. else
  833. $scope.tableParams.page(1);
  834. }
  835. };
  836. $scope.tableParams = new ngTableParams({
  837. page : 1,
  838. count : 20,
  839. sorting: {
  840. 'releaseDetail.release.date': 'desc'
  841. }
  842. }, {
  843. total : 0,
  844. counts: [5, 10, 25, 50],
  845. getData : function($defer, params) {
  846. $scope.loading = true;
  847. var pageParams = params.url();
  848. var realActive = {};
  849. pageParams.searchFilter = { // 筛选条件
  850. keyword: $scope.keyword
  851. // fromDate: getDateTime($scope.condition.dateFrom),
  852. // endDate: getDateTime($scope.condition.dateTo)
  853. };
  854. // AccountEnterprise.get({}, function(data){
  855. // $scope.loading = false;
  856. // $scope.currentEn = data;
  857. // });
  858. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  859. $scope.loading = false;
  860. if(page) {
  861. params.total(page.totalElement);
  862. $defer.resolve(page.content);
  863. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  864. }
  865. }, function(response){
  866. $scope.loading = false;
  867. toaster.pop('error', '数据加载失败', response.data);
  868. });
  869. }
  870. });
  871. $scope.close = function() {
  872. $modalInstance.close();
  873. };
  874. $scope.checks = {
  875. checked : false
  876. };// 全选框
  877. $scope.checkAll = function() {
  878. angular.forEach($scope.tableParams.data, function(message) {
  879. message.checked = $scope.checks.checked;
  880. });
  881. };
  882. // 单选
  883. $scope.checkOne = function(vendor) {
  884. vendor.checked = true;
  885. var checked = true;
  886. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  887. if (!message.checked) {
  888. checked = false;
  889. }
  890. });
  891. $scope.checks.checked = checked;
  892. };
  893. // 单反选
  894. $scope.unCheckOne = function(vendor) {
  895. vendor.checked = false;
  896. $scope.checks.checked = false;
  897. };
  898. // 标为已读
  899. $scope.setRead = function() {
  900. var selectedMessages = [];
  901. angular.forEach($scope.tableParams.data, function(message) {
  902. if(message.checked) {
  903. selectedMessages.push(message);
  904. }
  905. });
  906. PagingRelease.setRead({}, selectedMessages , function(message) {
  907. $scope.tableParams.page(1);
  908. $scope.tableParams.reload();
  909. });
  910. };
  911. // 搜索框回车
  912. $scope.onSearch = function() {
  913. $scope.tableParams.page(1);
  914. $scope.tableParams.reload();
  915. };
  916. }]);
  917. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  918. var search = $rootScope.searchKeyword;
  919. return function(content, search) {
  920. content = encodeURI(content);
  921. search = encodeURI(search);
  922. var reg = new RegExp(search, 'gim');
  923. var result = content.replace(reg,'<font color="red">$&</font>');
  924. result = decodeURI(result);
  925. return $sce.trustAsHtml(result);
  926. };
  927. $rootScope.searchKeyword = null;// 清除缓存的关键字
  928. }]);
  929. /**
  930. * 顶部搜索
  931. */
  932. 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) {
  933. BaseService.scrollBackToTop();
  934. $scope.active = 'all';
  935. $scope.tip = $rootScope.searchKeyword;
  936. // 企业搜索
  937. var getService = function() {
  938. return getAccountUserSpace;
  939. };
  940. $scope.tableParams = new ngTableParams({
  941. page : 1,
  942. count : 20,
  943. sorting: {
  944. }
  945. }, {
  946. total : 0,
  947. counts: [5, 10, 25, 50],
  948. getData : function($defer, params) {
  949. $scope.loading = true;
  950. var pageParams = params.url();
  951. pageParams.keyword = $rootScope.searchKeyword;
  952. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  953. $scope.loading = false;
  954. if(page) {
  955. $scope.total = page.totalElement;
  956. params.total(page.totalElement);
  957. $defer.resolve(page.content);
  958. }
  959. }, function(response) {
  960. $scope.loading = false;
  961. toaster.pop('error', '数据加载失败', response.data);
  962. });
  963. }
  964. });
  965. // 添加合作关系
  966. $scope.addPartner = function(name, businessCode) {
  967. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  968. if(data.success) {
  969. toaster.pop("success", '添加成功', data.success);
  970. $scope.tableParams.reload();
  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. var getProdService = function() {
  981. return SearchProd;
  982. };
  983. $scope.prodTableParams = new ngTableParams({
  984. page : 1,
  985. count : 20,
  986. sorting: {
  987. }
  988. }, {
  989. total : 0,
  990. counts: [5, 10, 25, 50],
  991. getData : function($defer, params) {
  992. $scope.loading = true;
  993. var pageParams = params.url();
  994. pageParams.keyword = $rootScope.searchKeyword;
  995. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  996. $scope.loading = false;
  997. if(page) {
  998. $scope.prodtotal = page.totalElement;
  999. params.total(page.totalElement);
  1000. $defer.resolve(page.content);
  1001. }
  1002. }, function(response) {
  1003. $scope.loading = false;
  1004. toaster.pop('error', '数据加载失败', response.data);
  1005. });
  1006. }
  1007. });
  1008. /**
  1009. * 向企业购买
  1010. */
  1011. $scope.PurcByEn = function(businessCode) {
  1012. $rootScope.businessCode = businessCode;
  1013. window.location.hash = "#/purc/addOrder";
  1014. }
  1015. /**
  1016. * 选中单个物料购买
  1017. * @param businessCode
  1018. * @param id
  1019. */
  1020. $scope.PurcByEnAndProd = function(businessCode, id) {
  1021. $rootScope.businessCode = businessCode;
  1022. $rootScope.prodId = id;
  1023. window.location.hash = "#/purc/addOrder";
  1024. }
  1025. /**
  1026. * 询价
  1027. */
  1028. $scope.PurcInquiry = function(businessCode, id){
  1029. $rootScope.prodId = id;
  1030. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1031. }
  1032. /**
  1033. * 邀请注册商务平台
  1034. */
  1035. $scope.invite = function(name) {
  1036. var modalInstance = $modal.open({
  1037. animation: true,
  1038. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1039. controller: 'InviteCtrl',
  1040. resolve: {
  1041. enname: function(){return name}
  1042. }
  1043. });
  1044. modalInstance.result.then(function(data) {
  1045. InvitationRecord.invite({formStore: data}, {}, function(data) {
  1046. if(data.success) {
  1047. toaster.pop('success', '提示', data.success);
  1048. }
  1049. if(data.error) {
  1050. toaster.pop('error', '提示', data.error);
  1051. }
  1052. }, function(response) {
  1053. toaster.pop('error', '提示', response.data);
  1054. });
  1055. });
  1056. }
  1057. /**
  1058. * 立即查看
  1059. */
  1060. $scope.view = function(name) {
  1061. $rootScope.vendName = name;
  1062. window.location.hash = "#/baseInfo/newPartner";
  1063. }
  1064. }]);
  1065. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  1066. $scope.enter = {
  1067. vendname: enname
  1068. };
  1069. $scope.save = function(enter) {
  1070. if(!enter.vendusertel && !enter.venduseremail) {
  1071. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1072. } else {
  1073. $modalInstance.close(enter);
  1074. }
  1075. }
  1076. $scope.cancel = function() {
  1077. $modalInstance.dismiss();
  1078. }
  1079. }]);
  1080. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function($scope, toaster, $modalInstance, id, InvitationRecord) {
  1081. var loadData = function (id) {
  1082. InvitationRecord.getRecordById({id: id}, {}, function(data) {
  1083. if (data.user !== null) {
  1084. data.user = {};
  1085. }
  1086. $scope.enter = data;
  1087. });
  1088. };
  1089. loadData(id);
  1090. $scope.save = function(enter) {
  1091. if(!enter.vendusertel && !enter.venduseremail) {
  1092. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1093. } else {
  1094. $modalInstance.close(enter);
  1095. }
  1096. };
  1097. $scope.cancel = function() {
  1098. $modalInstance.dismiss();
  1099. }
  1100. }]);
  1101. /**
  1102. * 邀请记录
  1103. */
  1104. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1105. BaseService.scrollBackToTop();
  1106. $scope.status = "invitation";
  1107. $scope.active = "invitation";
  1108. var getService = function() {
  1109. if ($scope.active === "invitation") {
  1110. return InvitationRecord.records;
  1111. } else if ($scope.active === "invitationTeam") {
  1112. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1113. }
  1114. };
  1115. $scope.setActive = function(state) {
  1116. if($scope.active !== state) {
  1117. $scope.active = state;
  1118. if($scope.tableParams.page() === 1)
  1119. $scope.tableParams.reload();
  1120. else
  1121. $scope.tableParams.page(1);
  1122. }
  1123. };
  1124. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1125. page : 1,
  1126. count : 20,
  1127. sorting: {
  1128. }
  1129. }, {
  1130. total : 0,
  1131. counts: [],
  1132. getData : function($defer, params) { // 获取数据的方法
  1133. $scope.loading = true;
  1134. var pageParams = params.url();
  1135. pageParams.keyword = $scope.keyword;
  1136. $scope.tip = $scope.keyword;
  1137. getService().call(null, BaseService.parseParams(pageParams), function(page){
  1138. $scope.loading = false;
  1139. if(page) {
  1140. params.total(page.totalElement);
  1141. $defer.resolve(page.content);
  1142. }
  1143. }, function(response){
  1144. $scope.loading = false;
  1145. toaster.pop('error', '数据加载失败', response.data);
  1146. });
  1147. }
  1148. });
  1149. $scope.onSearch = function(keyword){
  1150. $scope.tableParams.page(1);
  1151. $scope.tableParams.reload();
  1152. $scope.tip = keyword;
  1153. }
  1154. $scope.search = function(name) {
  1155. $modal.open({
  1156. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1157. controller: 'FuzzySearchCtrl',
  1158. resolve: {name: function() {return name}}
  1159. }).result.then(function(data){
  1160. });
  1161. };
  1162. // 再次邀请
  1163. $scope.reInvite = function(id) {
  1164. var modalInstance = $modal.open({
  1165. animation: true,
  1166. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1167. controller: 'ReInviteCtrl',
  1168. resolve: {
  1169. id: function(){return id}
  1170. }
  1171. });
  1172. modalInstance.result.then(function(data) {
  1173. InvitationRecord.invite({formStore: data}, {}, function(data) {
  1174. if(data.success) {
  1175. toaster.pop('success', '提示', data.success);
  1176. $scope.tableParams.reload();
  1177. }
  1178. if(data.error) {
  1179. toaster.pop('error', '提示', data.error);
  1180. }
  1181. }, function(response) {
  1182. toaster.pop('error', '提示', response.data);
  1183. });
  1184. });
  1185. }
  1186. }]);
  1187. /**
  1188. * 模糊查询相似的企业名称
  1189. */
  1190. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function($scope, name, InvitationRecord, toaster, BaseService) {
  1191. $scope.name = name;
  1192. if($scope.name != null) {
  1193. InvitationRecord.enterpriseList({name: $scope.name}, {}, function(data) {
  1194. $scope.enterprises = data;
  1195. }, function(response) {
  1196. toaster.pop('error', '提示', response.data);
  1197. });
  1198. }
  1199. }]);
  1200. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1201. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1202. //手机号码格式验证
  1203. // var checkTel = function(data){
  1204. // var userTel = data.userTel;
  1205. // $scope.checkResult = false;
  1206. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  1207. // if(!(telephone).test(userTel)){
  1208. // var modalInstance = $modal.open({
  1209. // animation: true,
  1210. // templateUrl: 'static/tpl/index/account/checkTel.html',
  1211. // controller: 'CheckTelCtrl',
  1212. // backdrop: 'static',
  1213. // keyboard: false,
  1214. // resolve: {
  1215. // user: function(){
  1216. // return data;
  1217. // },
  1218. // }
  1219. // });
  1220. // modalInstance.result.then(function(){
  1221. // }, function(){
  1222. //
  1223. // });
  1224. // } else {
  1225. // $scope.checkResult = true;
  1226. // }
  1227. // };
  1228. AuthenticationService.getAuthentication().success(function(data) {
  1229. if(data.enterprises) {
  1230. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1231. if(data.enterprises.length > 1) {
  1232. var enSelect = [];
  1233. angular.forEach(data.enterprises, function(e){
  1234. if(e.current)
  1235. data.enterprise = e;
  1236. else
  1237. enSelect.push(e);
  1238. });
  1239. data.enSelect = enSelect;
  1240. }
  1241. }
  1242. $scope.userInfo = data;
  1243. if (data == null || !data.userUU) {
  1244. $scope.isAuthed = false;
  1245. AuthenticationService.redirectSignin();
  1246. } else {
  1247. //跳转到手机号码验证
  1248. // checkTel($scope.userInfo);
  1249. }
  1250. });
  1251. $scope.logout = function() {
  1252. $modal.open({
  1253. templateUrl: 'static/tpl/index/account/logout.html',
  1254. controller: 'LogOutCtrl'
  1255. }).result.then(function(s){
  1256. if(s) {
  1257. AuthenticationService.logout();
  1258. }
  1259. });
  1260. };
  1261. $scope.switchto = function(enUU) {// 切换企业
  1262. AuthenticationService.reSignin(enUU).success(function(){
  1263. $window.location.reload();
  1264. });
  1265. };
  1266. $scope.addFavorite = function(){
  1267. var url = encodeURI(window.location.href);
  1268. try{
  1269. //ie浏览器收藏方式
  1270. window.external.addFavorite(url, "优软商务平台");
  1271. }catch(e) {
  1272. try{
  1273. //火狐浏览器收藏方式
  1274. window.sidebar.addPanel("优软商务平台", url);
  1275. }catch (e) {
  1276. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  1277. "或手动在浏览器里进行设置。");
  1278. }
  1279. }
  1280. };
  1281. }]);
  1282. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1283. $scope.close = function(confirm) {
  1284. $modalInstance.close(confirm);
  1285. };
  1286. }]);
  1287. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1288. $scope.image = {src: null};
  1289. // 图片上传成功之后
  1290. $scope.onUploadSuccess = function(data){
  1291. var path = data.path;
  1292. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1293. $scope.$apply(function(){
  1294. $scope.image.src = data.path;
  1295. $scope.image.thumb = path;
  1296. });
  1297. };
  1298. $scope.close = function() {
  1299. $modalInstance.dismiss();
  1300. };
  1301. $scope.confirm = function() {
  1302. $modalInstance.close($scope.image);
  1303. $scope.imageUrl = null;
  1304. };
  1305. }]);
  1306. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function($scope, SnapshotService, BaseService, $rootScope){
  1307. BaseService.scrollBackToTop();
  1308. SnapshotService.getTodo(function(data){
  1309. $scope.todo = data;
  1310. });
  1311. $scope.setTenderActive = function(active) {
  1312. $rootScope.tenderActive = active;
  1313. window.location.hash = '#/purc/tender';
  1314. }
  1315. }]);
  1316. // header
  1317. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1318. SnapshotService.getMessage(function(data){
  1319. $scope.message = data;
  1320. });
  1321. }]);
  1322. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1323. SaleTruck.query({}, function(data){
  1324. $rootScope.truck = data;
  1325. $scope.truckCount = data ? data.length : 0;
  1326. });
  1327. $scope.$watch(function(){
  1328. return $rootScope.truck;
  1329. }, function(data) {
  1330. $scope.truckCount = data ? data.length : 0;
  1331. }, true);
  1332. $scope.clearAll = function() {
  1333. SaleTruck.remove({}, function(){
  1334. $rootScope.truck = [];
  1335. });
  1336. };
  1337. $scope.openTrack = function() {
  1338. $modal.open({
  1339. templateUrl: 'static/tpl/index/sale/track.html',
  1340. controller: 'TruckModalCtrl',
  1341. size: 'lg'
  1342. }).result.then(function(s){
  1343. if(s) {
  1344. $scope.clearAll();
  1345. $rootScope.dataChanged = true;
  1346. }
  1347. });
  1348. };
  1349. }]);
  1350. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout){
  1351. $scope.saleSend = {sendItems: []};
  1352. SaleTruck.detail({}, function(data){
  1353. // 按物料编号排序
  1354. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1355. });
  1356. $scope.remove = function(index, notice) {
  1357. SaleTruck.remove({noticeId: notice.id}, function(data){
  1358. $rootScope.truck = data;
  1359. $scope.notices.splice(index, 1);
  1360. });
  1361. };
  1362. $scope.$watch(function(){
  1363. return $scope.notices;
  1364. }, function(data) {
  1365. var q = 0, t = 0;
  1366. if(data) {
  1367. angular.forEach(data,function(d){
  1368. q += d.thisSendQty;
  1369. t += d.thisSendQty * d.orderItem.price;
  1370. });
  1371. }
  1372. $scope.totalQty = q;
  1373. $scope.total = t;
  1374. }, true);
  1375. $scope.cancel = function() {
  1376. $modalInstance.close();
  1377. };
  1378. $scope.lockstatus = false;
  1379. // 锁定时间按钮5秒
  1380. $scope.lockClick = function() {
  1381. $scope.lockstatus = true;
  1382. $timeout(function() {
  1383. $scope.lockstatus = false;
  1384. }, 5000);
  1385. }
  1386. $scope.send = function() {// 发货
  1387. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1388. toaster.pop('error', '错误', '请输入送货单号');
  1389. return;
  1390. }
  1391. var currency = $scope.notices[0].orderItem.order.currency,
  1392. custUU = $scope.notices[0].enUU,
  1393. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1394. var num = 1;
  1395. for(var i in $scope.notices) {
  1396. var item = $scope.notices[i];
  1397. if(item.id) {
  1398. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1399. valid = false;
  1400. break;
  1401. }
  1402. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1403. }
  1404. }
  1405. if(!valid) {
  1406. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1407. } else {
  1408. var send = angular.extend(angular.copy($scope.saleSend), {
  1409. currency: currency,
  1410. custUU: custUU,
  1411. payments: payments,
  1412. sendItems: items
  1413. });
  1414. PurcNotice.sendByBatch({}, send, function(data){
  1415. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1416. $modalInstance.close(true);
  1417. $state.go('sale.send_detail', {id: data.id});
  1418. }, function(response){
  1419. toaster.pop('error', '错误', response.data);
  1420. });
  1421. }
  1422. };
  1423. }]);
  1424. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1425. SaleStat.cust({}, function(data){
  1426. var p = [], q = [];
  1427. angular.forEach(data.month, function(d){
  1428. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1429. });
  1430. angular.forEach(data.year, function(d){
  1431. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1432. });
  1433. $scope.custCharts = {
  1434. month : {
  1435. chartType : 'pie',
  1436. datas : {
  1437. data : p
  1438. },
  1439. config : {
  1440. labels : false,
  1441. title : "客户月采购量排行榜",
  1442. legend : {
  1443. display : true,
  1444. position : 'right'
  1445. },
  1446. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1447. click : function(d) {
  1448. },
  1449. mouseover : function(d) {
  1450. },
  1451. mouseout : function(d) {
  1452. },
  1453. innerRadius : 0,
  1454. lineLegend : 'lineEnd'
  1455. }
  1456. },
  1457. year : {
  1458. chartType : 'pie',
  1459. datas : {
  1460. data : q
  1461. },
  1462. config : {
  1463. labels : false,
  1464. title : "客户年采购量排行榜",
  1465. legend : {
  1466. display : true,
  1467. position : 'right'
  1468. },
  1469. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1470. click : function(d) {
  1471. },
  1472. mouseover : function(d) {
  1473. },
  1474. mouseout : function(d) {
  1475. },
  1476. innerRadius : 0,
  1477. lineLegend : 'lineEnd'
  1478. }
  1479. }
  1480. };
  1481. });
  1482. SaleStat.seller({}, function(data){
  1483. var p = [], q = [];
  1484. angular.forEach(data.month, function(d){
  1485. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1486. });
  1487. angular.forEach(data.year, function(d){
  1488. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1489. });
  1490. $scope.sellerCharts = {
  1491. month : {
  1492. chartType : 'pie',
  1493. datas : {
  1494. data : p
  1495. },
  1496. config : {
  1497. labels : false,
  1498. title : "业务员月销量排行榜",
  1499. legend : {
  1500. display : true,
  1501. position : 'right'
  1502. },
  1503. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1504. click : function(d) {
  1505. },
  1506. mouseover : function(d) {
  1507. },
  1508. mouseout : function(d) {
  1509. },
  1510. innerRadius : 0,
  1511. lineLegend : 'lineEnd'
  1512. }
  1513. },
  1514. year : {
  1515. chartType : 'pie',
  1516. datas : {
  1517. data : q
  1518. },
  1519. config : {
  1520. labels : false,
  1521. title : "业务员年销量排行榜",
  1522. legend : {
  1523. display : true,
  1524. position : 'right'
  1525. },
  1526. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1527. click : function(d) {
  1528. },
  1529. mouseover : function(d) {
  1530. },
  1531. mouseout : function(d) {
  1532. },
  1533. innerRadius : 0,
  1534. lineLegend : 'lineEnd'
  1535. }
  1536. }
  1537. };
  1538. });
  1539. }]);
  1540. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1541. SaleStat.get({}, function(data){
  1542. var p = [], q = [], r = [];
  1543. angular.forEach(data.day, function(d){
  1544. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1545. });
  1546. angular.forEach(data.month, function(d){
  1547. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1548. });
  1549. angular.forEach(data.year, function(d){
  1550. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1551. });
  1552. $scope.charts = {
  1553. day : {
  1554. chartType : "line",
  1555. datas: {
  1556. series: ['销售额'],
  1557. data: p
  1558. },
  1559. config : {
  1560. "labels": false,
  1561. "title": "销售额统计(近15日线)",
  1562. "legend": {
  1563. "display": true,
  1564. "position": "right"
  1565. },
  1566. colors : [ '#4D9934'],
  1567. "innerRadius": 0,
  1568. "lineLegend": "lineEnd"
  1569. }
  1570. },
  1571. month: {
  1572. chartType : "line",
  1573. datas: {
  1574. series: ['销售额'],
  1575. data: q
  1576. },
  1577. config : {
  1578. "labels": false,
  1579. "title": "销售额统计(近12月线)",
  1580. "legend": {
  1581. "display": true,
  1582. "position": "right"
  1583. },
  1584. colors : [ '#4D9934'],
  1585. "innerRadius": 0,
  1586. "lineLegend": "lineEnd"
  1587. }
  1588. },
  1589. year: {
  1590. chartType : "line",
  1591. datas: {
  1592. series: ['销售额'],
  1593. data: r
  1594. },
  1595. config : {
  1596. "labels": false,
  1597. "title": "销售额统计(近10年线)",
  1598. "legend": {
  1599. "display": true,
  1600. "position": "right"
  1601. },
  1602. colors : [ '#4D9934'],
  1603. "innerRadius": 0,
  1604. "lineLegend": "lineEnd"
  1605. }
  1606. }
  1607. };
  1608. });
  1609. }]);
  1610. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1611. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1612. $scope.notices = data;
  1613. });
  1614. $scope.dateTime = new Date();
  1615. }]);
  1616. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1617. // SnapshotService.getTender(250, function(data){
  1618. // $scope.tenders = data;
  1619. // console.log(data);
  1620. // var newDate = new Date();
  1621. // newDate = newDate.setDate(newDate.getDate() - 3);
  1622. // angular.forEach($scope.tenders, function(tender) {
  1623. // if (tender.date > newDate) {
  1624. // tender.isNew = true;
  1625. // } else {
  1626. // tender.isNew = false;
  1627. // }
  1628. // });
  1629. // });
  1630. SnapshotService.getOpenTender(5, function(data){
  1631. $scope.openTenders = data;
  1632. var newDate = new Date();
  1633. newDate = newDate.getTime() - 3*24*60*60*1000;
  1634. angular.forEach($scope.openTenders, function(tender) {
  1635. if (tender.date - newDate > 0) {
  1636. tender.isNew = true;
  1637. } else {
  1638. tender.isNew = false;
  1639. }
  1640. });
  1641. });
  1642. $scope.dateTime = new Date();
  1643. }]);
  1644. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1645. VendorService.getCount(function(date){
  1646. $scope.count = date;
  1647. });
  1648. }]);
  1649. // 客户
  1650. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1651. BaseService.scrollBackToTop();
  1652. $scope.userInfoResult = true;
  1653. AuthenticationService.getAuthentication().success(function(data) {
  1654. $scope.loading = false;
  1655. $scope.thisUser = data;
  1656. });
  1657. var getCustInfos = function(custuu) {
  1658. if(custuu) {
  1659. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1660. $scope.custInfos = data;
  1661. var getPage = function(page, size){
  1662. if($scope.custInfos) {
  1663. var result = {};
  1664. result.totalCount = $scope.custInfos.length;
  1665. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1666. if($scope.custInfos.length % size == 0) {
  1667. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1668. }else {
  1669. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1670. }
  1671. result.first = page == 1;
  1672. result.last = page == result.totalPage;
  1673. result.page = page;
  1674. result.next = page - 0 + 1;
  1675. result.pre = page - 1;
  1676. return result;
  1677. }
  1678. }
  1679. $scope.userdata = getPage(1,4);
  1680. $scope.first = function (){
  1681. $scope.userdata = getPage($scope.userdata.pre,4);
  1682. }
  1683. $scope.last = function (){
  1684. $scope.userdata = getPage($scope.userdata.next,4);
  1685. }
  1686. }, function(response){
  1687. $scope.loading = false;
  1688. toaster.pop('error', '数据加载失败', response.data);
  1689. });
  1690. }
  1691. }
  1692. $scope.addUserInfo = function(customer) {
  1693. //TODO
  1694. if ($scope.thisUser.sys) {
  1695. var modalInstance = $modal.open({
  1696. animation: true,
  1697. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1698. controller: 'AddUserInfoCtrl',
  1699. resolve: {
  1700. customer: function() {
  1701. return customer;
  1702. }
  1703. }
  1704. });
  1705. modalInstance.result.then(function(changed, checked){
  1706. if(changed) {
  1707. if(checked)
  1708. $scope.newUser.roles = checked;
  1709. else
  1710. loadUsers();
  1711. }
  1712. });
  1713. } else {
  1714. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1715. }
  1716. }
  1717. $scope.showUserInfo = function(customer,boo) {
  1718. $scope.custInfo = customer;
  1719. if(boo) {
  1720. getCustInfos(customer.myEnterprise.uu);
  1721. $scope.userInfoResult = true;
  1722. }
  1723. }
  1724. $scope.customerParams = new ngTableParams({
  1725. page : 1,
  1726. count : 20
  1727. }, {
  1728. total : 0,
  1729. counts: [5, 10, 25, 50],
  1730. getData : function($defer, params) {
  1731. $scope.loading = true;
  1732. var pageParams = params.url();
  1733. pageParams.keyword = $scope.keyword;
  1734. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1735. $scope.loading = false;
  1736. if(page) {
  1737. params.total(page.totalElement);
  1738. $defer.resolve(page.content);
  1739. }
  1740. $scope.totalCount = page.totalElement;
  1741. }, function(response){
  1742. $scope.loading = false;
  1743. toaster.pop('error', '数据加载失败', response.data);
  1744. });
  1745. }
  1746. });
  1747. // 搜索框回车
  1748. $scope.onSearch = function(keyword) {
  1749. $scope.customerParams.page(1);
  1750. $scope.customerParams.reload();
  1751. $scope.tip = keyword;
  1752. };
  1753. // 查看详情
  1754. $scope.viewDetail = function(id) {
  1755. window.location.hash = "#/sale/customer/" + id;
  1756. }
  1757. }]);
  1758. // 客户详情
  1759. 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) {
  1760. BaseService.scrollBackToTop();
  1761. $scope.userInfoResult = true;
  1762. AuthenticationService.getAuthentication().success(function(data) {
  1763. $scope.loading = false;
  1764. $scope.thisUser = data;
  1765. });
  1766. $scope.vendorContacts = [];
  1767. var loadData = function() {
  1768. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1769. $scope.customer = data.myEnterprise;
  1770. $scope.customerInfo = data;
  1771. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1772. $scope.Contacts = data;
  1773. });
  1774. // 查看已分配人员
  1775. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1776. $scope.custInfos = data;
  1777. var getPage = function(page, size){
  1778. if($scope.custInfos) {
  1779. var result = {};
  1780. result.totalCount = $scope.custInfos.length;
  1781. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1782. if($scope.custInfos.length % size == 0) {
  1783. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1784. }else {
  1785. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1786. }
  1787. result.first = page == 1;
  1788. result.last = page == result.totalPage;
  1789. result.page = page;
  1790. result.next = page - 0 + 1;
  1791. result.pre = page - 1;
  1792. return result;
  1793. }
  1794. }
  1795. $scope.userdata = getPage(1,4);
  1796. $scope.first = function (){
  1797. $scope.userdata = getPage($scope.userdata.pre,4);
  1798. }
  1799. $scope.last = function (){
  1800. $scope.userdata = getPage($scope.userdata.next,4);
  1801. }
  1802. }, function(response){
  1803. $scope.loading = false;
  1804. toaster.pop('error', '数据加载失败', response.data);
  1805. });
  1806. });
  1807. };
  1808. loadData();
  1809. // 新增客户联系人
  1810. $scope.addContact = function(uu) {
  1811. var modalInstance = $modal.open({
  1812. animation: true,
  1813. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1814. controller: 'AddContacCtrl',
  1815. resolve: {
  1816. }
  1817. });
  1818. modalInstance.result.then(function(data) {
  1819. $scope.contact = data;
  1820. $scope.contact.myenuu = uu;
  1821. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1822. toaster.pop('success', '提示', '联系人保存成功');
  1823. $scope.Contacts.push(data);
  1824. }, function(response) {
  1825. toaster.pop('error', '失败', response.data);
  1826. });
  1827. });
  1828. }
  1829. // 编辑客户联系人
  1830. $scope.edit = function(contact) {
  1831. var modalInstance = $modal.open({
  1832. animation: true,
  1833. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1834. controller: 'EditContacCtrl',
  1835. resolve: {
  1836. contact: function() {
  1837. return contact;
  1838. }
  1839. }
  1840. });
  1841. modalInstance.result.then(function(data) {
  1842. Vendor.saveContact({}, data, function(data) {
  1843. loadData();
  1844. toaster.pop('success', '提示', '联系人修改成功');
  1845. }, function(response) {
  1846. toaster.pop('error', '失败', response.data);
  1847. });
  1848. });
  1849. }
  1850. // 删除客户联系人
  1851. $scope.deleteById = function(id, index) {
  1852. $scope.Contacts.splice(index, 1);
  1853. Vendor.deleteContact({id: id}, {}, function(data) {
  1854. toaster.pop('success', '提示', '客户联系人删除成功');
  1855. loadData();
  1856. }, function(response) {
  1857. toaster.pop('error', '提示', response.data);
  1858. });
  1859. }
  1860. // 供应商物料信息
  1861. $scope.viewProdList = function(uu){
  1862. $scope.uu = uu;
  1863. $scope.tableParams.page(1);
  1864. $scope.tableParams.reload();
  1865. };
  1866. // 搜索框回车
  1867. $scope.onSearch = function(keyword) {
  1868. $scope.keyword = keyword;
  1869. $scope.tableParams.page(1);
  1870. $scope.tableParams.reload();
  1871. };
  1872. // 供应商物料信息
  1873. $scope.tableParams = new ngTableParams({
  1874. page : 1,
  1875. count : 20
  1876. }, {
  1877. total : 0,
  1878. counts: [5, 10, 25, 50],
  1879. getData : function($defer, params) {
  1880. $scope.loading = true;
  1881. var pageParams = params.url();
  1882. pageParams.custUU = $scope.uu;
  1883. pageParams.keyword = $scope.keyword;
  1884. $scope.tip = $scope.keyword;
  1885. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1886. $scope.loading = false;
  1887. if(page) {
  1888. params.total(page.totalElement);
  1889. $scope.total = page.totalElement;
  1890. $defer.resolve(page.content);
  1891. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1892. }
  1893. }, function(response){
  1894. $scope.loading = false;
  1895. toaster.pop('error', '数据加载失败', response.data);
  1896. });
  1897. }
  1898. });
  1899. $scope.addUserInfo = function() {
  1900. //TODO
  1901. if ($scope.thisUser.sys) {
  1902. var modalInstance = $modal.open({
  1903. animation: true,
  1904. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1905. controller: 'AddUserInfoCtrl',
  1906. resolve: {
  1907. customer: function() {
  1908. return $scope.customerInfo;
  1909. }
  1910. }
  1911. });
  1912. modalInstance.result.then(function(changed, checked){
  1913. loadData();
  1914. if(changed) {
  1915. if(checked) {
  1916. $scope.newUser.roles = checked;
  1917. } else {
  1918. loadUsers();
  1919. }
  1920. }
  1921. });
  1922. } else {
  1923. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1924. }
  1925. }
  1926. $scope.Quotation = function(uu, id) {
  1927. $rootScope.custuu = uu;
  1928. $rootScope.prodId = id;
  1929. window.location.hash = "#/sale/quotation/new";
  1930. }
  1931. }]);
  1932. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1933. $scope.checkboxes = {
  1934. checked : false
  1935. };
  1936. $scope.loading = true;
  1937. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1938. $scope.userinfos = data;
  1939. $scope.loading = false;
  1940. })
  1941. // 点击勾选全部的复选框
  1942. $scope.checkAll = function() {
  1943. angular.forEach($scope.userinfos, function(item) {
  1944. item.distribute = $scope.checkboxes.checked;
  1945. });
  1946. };
  1947. // 点击其中一个明细的复选框
  1948. $scope.checkOne = function(vendor){
  1949. var result = true;
  1950. angular.forEach($scope.userinfos, function(item) {
  1951. if(item.distribute != true){
  1952. result = false;
  1953. return;
  1954. }
  1955. });
  1956. $scope.checkboxes.checked = result;
  1957. };
  1958. $scope.close = function(save) {
  1959. var chooseResult = [];
  1960. if(save) {
  1961. if(customer.myEnterprise.uu) {
  1962. angular.forEach($scope.userinfos, function(item, i) {
  1963. chooseResult.push(item);
  1964. });
  1965. if(chooseResult.length > 0) {
  1966. $scope.loading = true;
  1967. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1968. $scope.loading = false;
  1969. toaster.pop('success', '提示', '保存成功');
  1970. $modalInstance.close(false);
  1971. }, function(response){
  1972. $scope.loading = false;
  1973. toaster.pop('error', '保存失败', response.data);
  1974. $modalInstance.close(false);
  1975. })
  1976. } else {
  1977. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1978. }
  1979. } else {
  1980. $modalInstance.close(true, $scope.checkboxes.checked);
  1981. }
  1982. } else {
  1983. $modalInstance.close(false);
  1984. }
  1985. };
  1986. }]);
  1987. /**
  1988. * 页面状态按钮过滤
  1989. */
  1990. var getState = function(active) {
  1991. var fn = 'get';
  1992. switch(active) {
  1993. case 'done':
  1994. fn = 'getDone';break;
  1995. case 'todo':
  1996. fn = 'getTodo';break;
  1997. case 'end':
  1998. fn = 'getEnd';break;
  1999. case 'waiting':
  2000. fn = 'getWaiting';break;
  2001. case 'invalid':
  2002. fn = 'getInvalid';break;
  2003. // 已采纳
  2004. case 'agreed':
  2005. fn = 'getAgreed';break;
  2006. // 未采纳
  2007. case 'refused':
  2008. fn = 'getRefused';break;
  2009. // 个人
  2010. case 'personal':
  2011. fn = 'getPersonal';break;
  2012. // 集体
  2013. case 'teams':
  2014. fn = 'getTeams';break;
  2015. // 非标准
  2016. case 'nonstandard':
  2017. fn = 'getNonstandard';break;
  2018. // 标准
  2019. case 'standard':
  2020. fn = 'getStandard';break;
  2021. }
  2022. return fn;
  2023. };
  2024. /**
  2025. * 改变单据日期范围
  2026. */
  2027. var getDateCondition = function(zone, condition) {
  2028. var date = new Date();
  2029. if(zone == -1) {
  2030. condition.dateFrom = null;
  2031. condition.dateTo = null;
  2032. } else if(zone == 1) {
  2033. date.setMonth(date.getMonth() - 1);
  2034. condition.dateFrom = date;
  2035. condition.dateTo = new Date();
  2036. } else if (zone == 6) {
  2037. date.setMonth(date.getMonth() - 6);
  2038. condition.dateFrom = date;
  2039. condition.dateTo = new Date();
  2040. } else {
  2041. date.setMonth(date.getMonth() - 6);
  2042. condition.dateFrom = null;
  2043. condition.dateTo = date;
  2044. }
  2045. };
  2046. /**
  2047. * 改变单据交货日期范围
  2048. */
  2049. var getDelveryCondition = function(zone, condition) {
  2050. var date = new Date();
  2051. if(zone == -1) {
  2052. condition.deliveryFrom = null;
  2053. condition.deliveryTo = null;
  2054. } else if(zone == 1) {
  2055. date.setMonth(date.getMonth() + 1);
  2056. condition.deliveryTo = date;
  2057. condition.deliveryFrom = new Date();
  2058. } else if (zone == 2) {
  2059. date.setMonth(date.getMonth() + 2);
  2060. condition.deliveryTo = date;
  2061. condition.deliveryFrom = new Date();
  2062. }
  2063. };
  2064. /**
  2065. * 将日期转化为整数日期
  2066. */
  2067. var getDateTime = function(date) {
  2068. if(angular.isDate(date)) {
  2069. return date.getTime();
  2070. } else {
  2071. return null;
  2072. }
  2073. };
  2074. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope',
  2075. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope){
  2076. BaseService.scrollBackToTop();
  2077. if ($rootScope.active) {
  2078. $scope.active = $rootScope.active;
  2079. $rootScope.active = null;
  2080. } else {
  2081. $scope.active = 'all';
  2082. }
  2083. $scope.dateZoneText = '不限';
  2084. $scope.deliveryZoneText = '不限';
  2085. $scope.condition = {dateZone: -1, deliveryZone: -1};
  2086. $scope.changeDateZone = function(zone) {
  2087. $scope.condition.dateZone = zone;
  2088. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2089. $scope.condition.$dateZoneOpen = false;
  2090. getDateCondition(zone, $scope.condition);
  2091. $scope.tableParams.reload();
  2092. };
  2093. $scope.changeDeliveryZone = function(zone) {
  2094. $scope.condition.deliveryZoneText = zone;
  2095. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2096. $scope.condition.$delievryZoneOpen = false;
  2097. getDelveryCondition(zone, $scope.condition);
  2098. $scope.tableParams.reload();
  2099. };
  2100. // 切换单据类型
  2101. $scope.setActive = function(state) {
  2102. if($scope.active != state) {
  2103. $scope.active = state;
  2104. if($scope.tableParams.page() == 1)
  2105. $scope.tableParams.reload();
  2106. else
  2107. $scope.tableParams.page(1);
  2108. }
  2109. };
  2110. var getPurcStatus = function(active) {
  2111. var fn = 'getPurcAll';
  2112. switch(active) {
  2113. case 'done':
  2114. fn = 'getPurcDone';break;
  2115. case 'todo':
  2116. fn = 'getPurcTodo';break;
  2117. case 'end':
  2118. fn = 'getPurcEnd';break;
  2119. case 'waiting':
  2120. fn = 'getPurcWaiting';break;
  2121. }
  2122. return fn;
  2123. };
  2124. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2125. page : 1,
  2126. count : 20,
  2127. sorting: {
  2128. display: 'desc',
  2129. date: 'desc'
  2130. }
  2131. }, {
  2132. total : 0,
  2133. counts: [5, 10, 15, 25, 50],
  2134. getData : function($defer, params) {// 获取数据的方法
  2135. $scope.loading = true;
  2136. var pageParams = params.url();
  2137. pageParams.searchFilter = { // 筛选条件
  2138. keyword: $scope.keyword,
  2139. fromDate: getDateTime($scope.condition.dateFrom),
  2140. endDate: getDateTime($scope.condition.dateTo)
  2141. };
  2142. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2143. $scope.loading = false;
  2144. if(page) {
  2145. $defer.resolve(page.content);
  2146. $scope.total = page.totalElement;
  2147. params.total(page.totalElement);
  2148. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2149. }
  2150. }, function(response){
  2151. $scope.loading = false;
  2152. toaster.pop('error', '数据加载失败', response.data);
  2153. });
  2154. }
  2155. });
  2156. $scope.getReply = function(item) {
  2157. if(!item.replies) {
  2158. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2159. item.replies = replies;
  2160. });
  2161. }
  2162. };
  2163. $scope.getOrderTotal = function(items) {
  2164. var sum = 0;
  2165. angular.forEach(items, function(item){
  2166. sum += item.qty * item.price;
  2167. });
  2168. return sum;
  2169. };
  2170. $scope.openDatePicker = function($event, item, openParam) {
  2171. $event.preventDefault();
  2172. $event.stopPropagation();
  2173. item[openParam] = !item[openParam];
  2174. };
  2175. $scope.parseDate = function(dateStr) {
  2176. if(dateStr)
  2177. return Date.parse(dateStr, 'yyyy-MM-dd');
  2178. return new Date();
  2179. };
  2180. $scope.checkboxes = {
  2181. checked : false
  2182. };
  2183. // 点击勾选全部的复选框
  2184. $scope.checkAll = function(){
  2185. angular.forEach($scope.tableParams.data, function(item) {
  2186. item.$selected = $scope.checkboxes.checked;
  2187. });
  2188. };
  2189. // 点击其中一个明细的复选框
  2190. $scope.checkOne = function(order){
  2191. var result = true;
  2192. angular.forEach($scope.tableParams.data, function(item) {
  2193. if(item.$selected != true){
  2194. result = false;
  2195. return;
  2196. }
  2197. });
  2198. $scope.checkboxes.checked = result;
  2199. };
  2200. // 搜索框回车
  2201. $scope.onSearch = function(keyword) {
  2202. $scope.tableParams.page(1);
  2203. $scope.tableParams.reload();
  2204. $scope.tip = keyword;
  2205. };
  2206. // 选择查找日期
  2207. $scope.onDateCondition = function(){
  2208. $scope.tableParams.page(1);
  2209. $scope.tableParams.reload();
  2210. };
  2211. }]);
  2212. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2213. var loadData = function() {
  2214. PurcOrder.get({id: $stateParams.id}, function(data){
  2215. $scope.order = data;
  2216. var sum = 0;
  2217. angular.forEach($scope.order.orderItems, function(item){
  2218. sum += item.qty * item.price;
  2219. });
  2220. $scope.order.total = sum;
  2221. if($scope.order.display == 1) {//未查看的设为已查看
  2222. $scope.setDisplay('setRead', $scope.order.id);
  2223. }
  2224. $scope.loading = false;
  2225. });
  2226. };
  2227. loadData();
  2228. $scope.getReply = function(item) {
  2229. if(!item.replies) {
  2230. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2231. item.replies = replies;
  2232. });
  2233. }
  2234. };
  2235. $scope.openDatePicker = function($event, item, openParam) {
  2236. $event.preventDefault();
  2237. $event.stopPropagation();
  2238. item[openParam] = !item[openParam];
  2239. };
  2240. $scope.onReplyClick = function(item, inverse) {
  2241. if(item.reply) {
  2242. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2243. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2244. return;
  2245. }
  2246. var reply = angular.copy(item.reply);
  2247. if(reply.delivery) {
  2248. if(typeof reply.delivery == 'object')
  2249. reply.delivery = reply.delivery.getTime();
  2250. } else {
  2251. reply.delivery = item.delivery;
  2252. }
  2253. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2254. $scope.loading = true;
  2255. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2256. $scope.loading = false;
  2257. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2258. loadData();
  2259. }, function(response){
  2260. $scope.loading = false;
  2261. toaster.pop('error', '回复失败', response.data);
  2262. });
  2263. }
  2264. };
  2265. // // 采购单
  2266. // $scope.print = function(order) {
  2267. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  2268. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2269. // };
  2270. //设置为已查看
  2271. $scope.setDisplay = function(state, orderId) {
  2272. if(orderId) {//设置单个
  2273. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2274. // $scope.tableParams.reload();
  2275. }, function() {
  2276. toaster.pop('error', '错误', "设置失败");
  2277. });
  2278. } else {//设置已勾选的
  2279. var str = null;
  2280. angular.forEach($scope.tableParams.data, function(order) {
  2281. if(order.$selected == true) {
  2282. if(str != null && str != '') str += ',';
  2283. str += order.id;
  2284. }
  2285. });
  2286. if(str != null && str != '') {
  2287. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2288. $scope.tableParams.reload();
  2289. }, function() {
  2290. toaster.pop('error', '错误', "设置失败");
  2291. });
  2292. }
  2293. }
  2294. };
  2295. }]);
  2296. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  2297. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  2298. BaseService.scrollBackToTop();
  2299. $scope.active = 'todo';
  2300. $scope.dateZoneText = '不限';
  2301. $scope.deliveryZoneText = '不限';
  2302. $scope.condition = {dateZone: -1, deliveryZone: -1};
  2303. $scope.changeDateZone = function(zone) {
  2304. if(typeof zone == 'undefined'){
  2305. $scope.condition.dateZone = -6;
  2306. } else {
  2307. $scope.condition.dateZone = zone;
  2308. }
  2309. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2310. $scope.condition.$dateZoneOpen = false;
  2311. getDateCondition(zone, $scope.condition);
  2312. $scope.tableParams.reload();
  2313. };
  2314. $scope.changeDeliveryZone = function(zone) {
  2315. $scope.condition.deliveryZoneText = zone;
  2316. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2317. $scope.condition.$delievryZoneOpen = false;
  2318. getDelveryCondition(zone, $scope.condition);
  2319. $scope.tableParams.reload();
  2320. };
  2321. $scope.nowdate = new Date();
  2322. // 切换单据类型
  2323. $scope.setActive = function(state) {
  2324. if($scope.active != state) {
  2325. $scope.active = state;
  2326. if($scope.tableParams.page() == 1)
  2327. $scope.tableParams.reload();
  2328. else
  2329. $scope.tableParams.page(1);
  2330. }
  2331. };
  2332. // 切换数据来源(正常数据 or 历史数据)
  2333. var getService = function() {
  2334. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  2335. };
  2336. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2337. page : 1,
  2338. count : 20,
  2339. sorting: {
  2340. display: 'desc',
  2341. date: 'desc',
  2342. id: 'desc'
  2343. }
  2344. }, {
  2345. total : 0,
  2346. counts: [5, 10, 15, 25, 50],
  2347. getData : function($defer, params) { // 获取数据的方法
  2348. $scope.loading = true;
  2349. var pageParams = params.url();
  2350. pageParams.searchFilter = { // 筛选条件
  2351. keyword: $scope.keyword,
  2352. fromDate: getDateTime($scope.condition.dateFrom),
  2353. endDate: getDateTime($scope.condition.dateTo)
  2354. };
  2355. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2356. $scope.loading = false;
  2357. if(page) {
  2358. $defer.resolve(page.content);
  2359. params.total(page.totalElement);
  2360. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2361. }
  2362. }, function(response){
  2363. $scope.loading = false;
  2364. toaster.pop('error', '数据加载失败', response.data);
  2365. });
  2366. }
  2367. });
  2368. $scope.getOrderTotal = function(items) {
  2369. var sum = 0;
  2370. angular.forEach(items, function(item){
  2371. sum += item.qty * item.price;
  2372. });
  2373. return sum;
  2374. };
  2375. $scope.openDatePicker = function($event, item, openParam) {
  2376. $event.preventDefault();
  2377. $event.stopPropagation();
  2378. item[openParam] = !item[openParam];
  2379. };
  2380. $scope.parseDate = function(dateStr) {
  2381. if(dateStr)
  2382. return Date.parse(dateStr, 'yyyy-MM-dd');
  2383. return new Date();
  2384. };
  2385. $scope.onReplyClick = function(item, inverse) {
  2386. if(item.reply) {
  2387. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2388. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2389. return;
  2390. }
  2391. var reply = angular.copy(item.reply);
  2392. if(reply.delivery) {
  2393. if(typeof reply.delivery == 'object')
  2394. reply.delivery = reply.delivery.getTime();
  2395. } else {
  2396. reply.delivery = item.delivery;
  2397. }
  2398. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2399. $scope.loading = true;
  2400. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2401. $scope.loading = false;
  2402. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2403. $scope.tableParams.reload();
  2404. }, function(response){
  2405. $scope.loading = false;
  2406. toaster.pop('error', '回复失败', response.data);
  2407. });
  2408. }
  2409. };
  2410. //打印 采购单
  2411. $scope.print = function(order) {
  2412. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2413. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2414. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2415. };
  2416. $scope.getReply = function(item) {
  2417. if(!item.replies) {
  2418. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2419. item.replies = replies;
  2420. });
  2421. }
  2422. };
  2423. $scope.checkboxes = {
  2424. checked : false
  2425. };
  2426. // 点击勾选全部的复选框
  2427. $scope.checkAll = function(){
  2428. angular.forEach($scope.tableParams.data, function(item) {
  2429. item.$selected = $scope.checkboxes.checked;
  2430. });
  2431. };
  2432. // 点击其中一个明细的复选框
  2433. $scope.checkOne = function(order){
  2434. var result = true;
  2435. angular.forEach($scope.tableParams.data, function(item) {
  2436. if(item.$selected != true){
  2437. result = false;
  2438. return;
  2439. }
  2440. });
  2441. $scope.checkboxes.checked = result;
  2442. };
  2443. //批量回复采购订单
  2444. $scope.replyByBatch = function() {
  2445. $scope.loading = true;
  2446. var str = '';
  2447. angular.forEach($scope.tableParams.data, function(order) {
  2448. if(order.$selected == true) {
  2449. angular.forEach(order.orderItems, function(item){
  2450. str += item.id;
  2451. str += ',';
  2452. });
  2453. }
  2454. });
  2455. if(!(str == '')) {
  2456. str = str.substr(0, str.length-1);
  2457. PurcOrderItem.replyByBatch(str, function(){
  2458. $scope.loading = false;
  2459. $scope.tableParams.reload();
  2460. toaster.pop('success', '提示', '批量回复成功');
  2461. }, function(data){
  2462. $scope.loading = false;
  2463. toaster.pop('error', '批量回复失败', data);
  2464. });
  2465. } else {//没有勾选其中的明细
  2466. $scope.loading = false;
  2467. }
  2468. };
  2469. // 搜索框回车
  2470. $scope.onSearch = function() {
  2471. $scope.tableParams.page(1);
  2472. $scope.tableParams.reload();
  2473. };
  2474. // 选择查找日期
  2475. $scope.onDateCondition = function(){
  2476. $scope.tableParams.page(1);
  2477. $scope.tableParams.reload();
  2478. };
  2479. //设置为已查看
  2480. $scope.setDisplay = function(state, orderId) {
  2481. if(orderId) {//设置单个
  2482. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2483. $scope.tableParams.reload();
  2484. }, function() {
  2485. toaster.pop('error', '错误', "设置失败");
  2486. });
  2487. } else {//设置已勾选的
  2488. var str = null;
  2489. angular.forEach($scope.tableParams.data, function(order) {
  2490. if(order.$selected == true) {
  2491. if(str != null && str != '') str += ',';
  2492. str += order.id;
  2493. }
  2494. });
  2495. if(str != null && str != '') {
  2496. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2497. $scope.tableParams.reload();
  2498. }, function() {
  2499. toaster.pop('error', '错误', "设置失败");
  2500. });
  2501. }
  2502. }
  2503. };
  2504. }]);
  2505. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2506. var loadData = function() {
  2507. PurcOrder.get({id: $stateParams.id}, function(data){
  2508. $scope.order = data;
  2509. var sum = 0;
  2510. angular.forEach($scope.order.orderItems, function(item){
  2511. sum += item.qty * item.price;
  2512. });
  2513. $scope.order.total = sum;
  2514. if($scope.order.display == 1) {//未查看的设为已查看
  2515. $scope.setDisplay('setRead', $scope.order.id);
  2516. }
  2517. $scope.loading = false;
  2518. });
  2519. };
  2520. loadData();
  2521. $scope.getReply = function(item) {
  2522. if(!item.replies) {
  2523. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2524. item.replies = replies;
  2525. });
  2526. }
  2527. };
  2528. $scope.openDatePicker = function($event, item, openParam) {
  2529. $event.preventDefault();
  2530. $event.stopPropagation();
  2531. item[openParam] = !item[openParam];
  2532. };
  2533. $scope.onReplyClick = function(item, inverse) {
  2534. if(item.reply) {
  2535. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2536. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2537. return;
  2538. }
  2539. var reply = angular.copy(item.reply);
  2540. if(reply.delivery) {
  2541. if(typeof reply.delivery == 'object')
  2542. reply.delivery = reply.delivery.getTime();
  2543. } else {
  2544. reply.delivery = item.delivery;
  2545. }
  2546. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2547. $scope.loading = true;
  2548. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2549. $scope.loading = false;
  2550. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2551. loadData();
  2552. }, function(response){
  2553. $scope.loading = false;
  2554. toaster.pop('error', '回复失败', response.data);
  2555. });
  2556. }
  2557. };
  2558. // 采购单
  2559. $scope.print = function(order) {
  2560. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2561. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2562. };
  2563. //设置为已查看
  2564. $scope.setDisplay = function(state, orderId) {
  2565. if(orderId) {//设置单个
  2566. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2567. $scope.tableParams.reload();
  2568. }, function() {
  2569. toaster.pop('error', '错误', "设置失败");
  2570. });
  2571. } else {//设置已勾选的
  2572. var str = null;
  2573. angular.forEach($scope.tableParams.data, function(order) {
  2574. if(order.$selected == true) {
  2575. if(str != null && str != '') str += ',';
  2576. str += order.id;
  2577. }
  2578. });
  2579. if(str != null && str != '') {
  2580. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2581. $scope.tableParams.reload();
  2582. }, function() {
  2583. toaster.pop('error', '错误', "设置失败");
  2584. });
  2585. }
  2586. }
  2587. };
  2588. }]);
  2589. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  2590. BaseService.scrollBackToTop();
  2591. $scope.active = 'todo';
  2592. $scope.agreedText = '全部';
  2593. $scope.dateZoneText = '一个月内';
  2594. $scope.condition = {dateZone: 1};
  2595. $scope.changeAgreed = function(agreed) {
  2596. $scope.condition.agreed = agreed;
  2597. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2598. $scope.condition.$agreedOpen = false;
  2599. };
  2600. $scope.changeDateZone = function(zone) {
  2601. $scope.condition.dateZone = zone;
  2602. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2603. $scope.condition.$dateZoneOpen = false;
  2604. };
  2605. $scope.setActive = function(state) {
  2606. if($scope.active != state) {
  2607. $scope.active = state;
  2608. if($scope.tableParams.page() == 1)
  2609. $scope.tableParams.reload();
  2610. else
  2611. $scope.tableParams.page(1);
  2612. }
  2613. };
  2614. var getService = function() {
  2615. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2616. };
  2617. $scope.tableParams = new ngTableParams({
  2618. page : 1,
  2619. count : 20,
  2620. sorting: {
  2621. date: 'desc'
  2622. }
  2623. }, {
  2624. total : 0,
  2625. counts: [5, 10, 25, 50],
  2626. getData : function($defer, params) {
  2627. $scope.loading = true;
  2628. var pageParams = params.url();
  2629. pageParams.keyword = $scope.keyword;
  2630. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2631. $scope.loading = false;
  2632. if(page) {
  2633. params.total(page.totalElement);
  2634. $defer.resolve(page.content);
  2635. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2636. }
  2637. }, function(response){
  2638. $scope.loading = false;
  2639. toaster.pop('error', '数据加载失败', response.data);
  2640. });
  2641. }
  2642. });
  2643. $scope.openDatePicker = function($event, item, openParam) {
  2644. $event.preventDefault();
  2645. $event.stopPropagation();
  2646. item[openParam] = !item[openParam];
  2647. };
  2648. $scope.onReplyClick = function(change) {
  2649. if(change.$agreed) {
  2650. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2651. $scope.loading = true;
  2652. PurcChange.reply({changeId: change.id}, reply, function(){
  2653. $scope.loading = false;
  2654. toaster.pop('info', '提示', '回复成功');
  2655. $scope.tableParams.reload();
  2656. }, function(response){
  2657. $scope.loading = false;
  2658. toaster.pop('error', '回复失败', response.data);
  2659. });
  2660. }
  2661. };
  2662. // 搜索框回车
  2663. $scope.onSearch = function() {
  2664. $scope.tableParams.page(1);
  2665. $scope.tableParams.reload();
  2666. };
  2667. }]);
  2668. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2669. var loadData = function() {
  2670. PurcChange.get({id: $stateParams.id}, function(data){
  2671. $scope.change = data;
  2672. });
  2673. };
  2674. loadData();
  2675. $scope.openDatePicker = function($event, item, openParam) {
  2676. $event.preventDefault();
  2677. $event.stopPropagation();
  2678. item[openParam] = !item[openParam];
  2679. };
  2680. $scope.onReplyClick = function(change) {
  2681. if(change.$agreed) {
  2682. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2683. PurcChange.reply({changeId: change.id}, reply, function(){
  2684. toaster.pop('info', '提示', '回复成功');
  2685. loadData();
  2686. }, function(response){
  2687. toaster.pop('error', '回复失败', response.data);
  2688. });
  2689. }
  2690. };
  2691. }]);
  2692. //采购询价
  2693. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', '$upload', '$rootScope', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis, $upload, $rootScope){
  2694. BaseService.scrollBackToTop();
  2695. if($rootScope.active) {
  2696. $scope.active = $rootScope.active;
  2697. $rootScope.active = null;
  2698. } else {
  2699. $scope.active = 'todo';
  2700. }
  2701. $scope.agreedText = '全部';
  2702. $scope.dateZoneText = '一个月内';
  2703. $scope.condition = {dateZone: 1};
  2704. $scope.changeAgreed = function(agreed) {
  2705. $scope.condition.agreed = agreed;
  2706. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2707. $scope.condition.$agreedOpen = false;
  2708. };
  2709. $scope.changeDateZone = function(zone) {
  2710. $scope.condition.dateZone = zone;
  2711. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2712. $scope.condition.$dateZoneOpen = false;
  2713. };
  2714. $scope.setActive = function(state) {
  2715. if($scope.active != state) {
  2716. $scope.active = state;
  2717. if($scope.tableParams.page() == 1)
  2718. $scope.tableParams.reload();
  2719. else
  2720. $scope.tableParams.page(1);
  2721. }
  2722. };
  2723. // 得到消息
  2724. PurcInquiry.getMessage({}, function(data){
  2725. $scope.message = data;
  2726. }, function(response) {
  2727. });
  2728. var getService = function() {
  2729. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2730. };
  2731. $scope.tableParams = new ngTableParams({
  2732. page : 1,
  2733. count : 20,
  2734. sorting: {
  2735. 'inquiry.date': 'desc',
  2736. 'inquiry.enterprise.enName': 'asc',
  2737. 'inquiry.code': 'asc'
  2738. }
  2739. }, {
  2740. total : 0,
  2741. counts: [5, 10, 25, 50],
  2742. getData : function($defer, params) {
  2743. $scope.loading = true;
  2744. var pageParams = params.url();
  2745. var realActive = {};
  2746. pageParams.keyword = $scope.keyword;
  2747. if ($scope.active == 'overdue') {
  2748. $scope.active = 'end';
  2749. }
  2750. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2751. $scope.loading = false;
  2752. if(page) {
  2753. params.total(page.totalElement);
  2754. $defer.resolve(page.content);
  2755. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2756. }
  2757. }, function(response){
  2758. $scope.loading = false;
  2759. toaster.pop('error', '数据加载失败', response.data);
  2760. });
  2761. }
  2762. });
  2763. $scope.getMinDate = function(item) {
  2764. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2765. };
  2766. $scope.replyPrices = [];
  2767. $scope.replylapQtys = [];
  2768. $scope.replyPrices.push(true);
  2769. $scope.replylapQtys.push(true);
  2770. $scope.addStep = function(inquiryItem) {
  2771. $scope.replyPrices.push(true);
  2772. if(inquiryItem.replies.length >= 10) {
  2773. toaster.pop('warning', '提示', '最多支持10个分段!');
  2774. } else {
  2775. inquiryItem.replies.push({});
  2776. if(inquiryItem.replies.length != 1) {
  2777. $scope.replyPrices.push(true);
  2778. $scope.replylapQtys.push(true);
  2779. }
  2780. }
  2781. };
  2782. $scope.removeStep = function(inquiryItem, stepIndex) {
  2783. inquiryItem.replies.splice(stepIndex, 1);
  2784. $scope.replyPrices.splice(stepIndex, 1);
  2785. $scope.replylapQtys.splice(stepIndex, 1);
  2786. };
  2787. $scope.openDatePicker = function($event, item, openParam) {
  2788. $event.preventDefault();
  2789. $event.stopPropagation();
  2790. item[openParam] = !item[openParam];
  2791. };
  2792. $scope.getHistory = function(item) {
  2793. if(!item.history) {
  2794. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2795. item.history = data;
  2796. });
  2797. }
  2798. };
  2799. $scope.isValid = function(item, withSteps) {
  2800. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2801. if(!withSteps || !bool)
  2802. return bool;
  2803. angular.forEach(item.replies, function(r, i){
  2804. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2805. });
  2806. return bool;
  2807. };
  2808. $scope.onReplyClick = function(item, withSteps) {
  2809. if(item.vendFromDate instanceof Date) {
  2810. item.vendFromDate = item.vendFromDate.getTime();
  2811. }
  2812. if(item.vendToDate instanceof Date) {
  2813. item.vendToDate = item.vendToDate.getTime();
  2814. }
  2815. if(item.vendFromDate > item.vendToDate) {
  2816. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2817. return;
  2818. }
  2819. var replies = [];
  2820. angular.forEach(item.replies, function(r, i){
  2821. if((i > 0 ? r.lapQty : 1) || r.price)
  2822. replies.push(r);
  2823. });
  2824. item.replies = replies;
  2825. $scope.loading = true;
  2826. if(withSteps) {
  2827. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  2828. $upload.upload({
  2829. url: 'sale/inquiry/addAttach',
  2830. file: file,
  2831. method: 'POST',
  2832. data: {
  2833. itemId:item.id
  2834. }
  2835. }).success(function (attach) {
  2836. console.log(attach);
  2837. });
  2838. PurcInquiry.reply({itemId: item.id}, item, function(){
  2839. $scope.loading = false;
  2840. toaster.pop('info', '提示', '报价成功');
  2841. $scope.tableParams.reload();
  2842. }, function(response){
  2843. $scope.loading = false;
  2844. toaster.pop('error', '询价失效', response.data);
  2845. });
  2846. } else {
  2847. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2848. $scope.loading = false;
  2849. toaster.pop('info', '提示', '保存成功');
  2850. $scope.tableParams.reload();
  2851. }, function(response){
  2852. $scope.loading = false;
  2853. toaster.pop('error', '保存失败', response.data);
  2854. });
  2855. }
  2856. };
  2857. $scope.verifylapQty = function(value,type) {
  2858. var regex = /^\d+(.\d{1,5})?$/;
  2859. $scope.replylapQtys[type] = regex.test(value);
  2860. }
  2861. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2862. $scope.verify = function(value,type) {
  2863. var regex = /^\d+(.\d{1,5})?$/;//
  2864. switch(type) {
  2865. case 'minOrderQty':
  2866. $scope.minOrderQtyVerify = regex.test(value);
  2867. break;
  2868. case 'minPackQty':
  2869. $scope.minPackQtyVerify = regex.test(value);
  2870. break;
  2871. case 'leadtime':
  2872. $scope.leadtimeVerify = regex.test(value);
  2873. break;
  2874. default:
  2875. $scope.replyPrices[type] = regex.test(value);
  2876. break;
  2877. }
  2878. }
  2879. // 搜索框回车
  2880. $scope.onSearch = function() {
  2881. $scope.tableParams.page(1);
  2882. $scope.tableParams.reload();
  2883. };
  2884. // 取消
  2885. $scope.cancel = function() {
  2886. $scope.tableParams.reload();
  2887. }
  2888. }]);
  2889. // 询价单明细
  2890. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', '$upload', function($scope, $stateParams, PurcInquiry,$filter, toaster, $upload){
  2891. var loadData = function() {
  2892. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2893. $scope.newinquiryItems = data;
  2894. var inquiry = data[0].inquiry;
  2895. //inquiry.inquiryItems = data;
  2896. angular.forEach(inquiry.attachs, function(attach){
  2897. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2898. });
  2899. $scope.inquiry = inquiry;
  2900. });
  2901. };
  2902. loadData();
  2903. $scope.getMinDate = function(item) {
  2904. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2905. };
  2906. $scope.addStep = function(inquiryItem) {
  2907. if(inquiryItem.replies.length >= 10) {
  2908. toaster.pop('warning', '提示', '最多支持10个分段!');
  2909. } else
  2910. inquiryItem.replies.push({});
  2911. };
  2912. $scope.removeStep = function(inquiryItem, stepIndex) {
  2913. inquiryItem.replies.splice(stepIndex, 1);
  2914. };
  2915. $scope.openDatePicker = function($event, item, openParam) {
  2916. $event.preventDefault();
  2917. $event.stopPropagation();
  2918. item[openParam] = !item[openParam];
  2919. };
  2920. $scope.getHistory = function(item) {
  2921. if(!item.history) {
  2922. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2923. item.history = data;
  2924. });
  2925. }
  2926. };
  2927. $scope.isValid = function(item, withSteps) {
  2928. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2929. if(!withSteps || !bool)
  2930. return bool;
  2931. angular.forEach(item.replies, function(r, i){
  2932. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2933. });
  2934. return bool;
  2935. };
  2936. $scope.onReplyClick = function(item, withSteps) {
  2937. if(item.vendFromDate instanceof Date) {
  2938. item.vendFromDate = item.vendFromDate.getTime();
  2939. }
  2940. if(item.vendToDate instanceof Date) {
  2941. item.vendToDate = item.vendToDate.getTime();
  2942. }
  2943. if(item.vendFromDate > item.vendToDate) {
  2944. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2945. return;
  2946. }
  2947. var replies = [];
  2948. angular.forEach(item.replies, function(r, i){
  2949. if((i > 0 ? r.lapQty : 1) || r.price)
  2950. replies.push(r);
  2951. });
  2952. item.replies = replies;
  2953. if(withSteps) {
  2954. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  2955. $upload.upload({
  2956. url: 'sale/inquiry/addAttach',
  2957. file: file,
  2958. method: 'POST',
  2959. data: {
  2960. itemId:item.id
  2961. }
  2962. }).success(function (attach) {
  2963. console.log(attach);
  2964. });
  2965. PurcInquiry.reply({itemId: item.id}, item, function(){
  2966. toaster.pop('info', '提示', '报价成功');
  2967. loadData();
  2968. }, function(response){
  2969. toaster.pop('error', '报价失败', response.data);
  2970. });
  2971. } else {
  2972. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2973. $scope.loading = false;
  2974. toaster.pop('info', '提示', '保存成功');
  2975. loadData();
  2976. }, function(response){
  2977. $scope.loading = false;
  2978. toaster.pop('error', '保存失败', response.data);
  2979. });
  2980. }
  2981. };
  2982. // 取消
  2983. $scope.cancel = function() {
  2984. $scope.tableParams.reload();
  2985. }
  2986. }]);
  2987. // 平台新增的询价单
  2988. 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) {
  2989. $scope.status = 'InquiryNew';
  2990. $scope.active = 'all';
  2991. $rootScope.tenderVendor = null;// 清除掉已选择的
  2992. var getService = function() {
  2993. return GetProductInfo;
  2994. };
  2995. $scope.inquiry = {
  2996. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  2997. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  2998. priceType: '采购',
  2999. isOpen: 1,
  3000. invoice: 0,
  3001. ifTax: 1,
  3002. currency: 'RMB',
  3003. inquirytype: '询价'
  3004. };
  3005. $scope.changeCurrency = function(inquiry) {
  3006. if (inquiry.currency !== 'RMB') {
  3007. $scope.notRMB = true;
  3008. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  3009. inquiry.invoice = 0;
  3010. } else {
  3011. $scope.notRMB = false;
  3012. }
  3013. };
  3014. // 获取收货地址列表
  3015. var loadShipAddress = function() {
  3016. ShipAddress.shipAddList({}, function(data) {
  3017. $scope.ships = data;
  3018. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  3019. });
  3020. };
  3021. loadShipAddress();
  3022. // 获取地址信息
  3023. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  3024. }).then(function(response) {
  3025. $scope.provinces = response.data;
  3026. });
  3027. // 新增收货地址保存
  3028. $scope.saveShipAddress = function(ship) {
  3029. ship.address = ship.province + ship.city + ship.district;
  3030. ShipAddress.saveAddress( {}, ship, function(data) {
  3031. if(data.success) {
  3032. // 获取收货地址列表
  3033. loadShipAddress();
  3034. toaster.pop('success', '提示', data.success);
  3035. }
  3036. if(data.error) {
  3037. toaster.pop('error', '提示', data.error);
  3038. }
  3039. });
  3040. };
  3041. $scope.currentDay = function() {
  3042. return $filter('date')(new Date(), 'yyyy-MM-dd');
  3043. };
  3044. $scope.vendors = [];
  3045. // 查找供应商
  3046. $scope.dbfindVendor = function(){
  3047. var modalInstance = $modal.open({
  3048. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  3049. controller: 'DbfindVendorCtrl',
  3050. size: 'lg',
  3051. resolve: {
  3052. }
  3053. });
  3054. modalInstance.result.then(function(data){
  3055. var ifPush = true;
  3056. modalInstance.result.then(function(data){
  3057. angular.forEach(data, function(vendor) {
  3058. if (!$scope.vendors) {// 不存在就先创建
  3059. $scope.vendors = [{}];
  3060. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  3061. } else {
  3062. for (var i = 0;i<$scope.vendors.length; i++) {
  3063. ifPush = true;
  3064. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  3065. ifPush = false;
  3066. break; // 判定到已存在供应商,就终止循环。
  3067. }
  3068. }
  3069. if (ifPush) {
  3070. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  3071. }
  3072. }
  3073. });
  3074. $rootScope.tenderVendor = $scope.vendors;
  3075. }, function(){
  3076. });
  3077. }, function(){
  3078. });
  3079. };
  3080. // 删除一个供应商
  3081. $scope.removeVendor = function(index) {
  3082. $scope.vendors.splice(index, 1);
  3083. };
  3084. $scope.removeChecked = function() {
  3085. console.log($scope.vendors);
  3086. if ( $scope.vendors.length > 0) {
  3087. $scope.vendors = [];
  3088. $rootScope.tenderVendor = '';
  3089. }
  3090. }
  3091. // 物料信息
  3092. $scope.tableParams = new ngTableParams({
  3093. page : 1,
  3094. count : 20,
  3095. sorting: {
  3096. }
  3097. }, {
  3098. total : 0,
  3099. counts: [5, 10, 25, 50],
  3100. getData : function($defer, params) {
  3101. $scope.loading = true;
  3102. var pageParams = params.url();
  3103. pageParams.keyword = $scope.keyword;
  3104. $scope.tip = $scope.keyword;
  3105. pageParams.searchFilter = $scope.searchFilter;
  3106. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3107. $scope.loading = false;
  3108. if(page) {
  3109. params.total(page.totalElement);
  3110. $scope.total = page.totalElement;
  3111. $defer.resolve(page.content);
  3112. }
  3113. }, function(response) {
  3114. $scope.loading = false;
  3115. toaster.pop('error', '数据加载失败', response.data);
  3116. });
  3117. }
  3118. });
  3119. // 搜索框回车
  3120. $scope.onSearch = function(keyword) {
  3121. $scope.tableParams.page(1);
  3122. $scope.tableParams.reload();
  3123. };
  3124. $scope.inquiry.inquiryItems = [];
  3125. var prod = {
  3126. prodCode: null,
  3127. prodTitle: null,
  3128. inbrand: null,
  3129. toDate: null,
  3130. unit: 'PCS',
  3131. needquantity: null
  3132. };
  3133. $scope.inquiry.inquiryItems.push(prod);
  3134. // 联想词start
  3135. // 获取品牌联想词
  3136. $scope.getSimilarBrands = function(value) {
  3137. if (value) {
  3138. // 获取品牌联想词
  3139. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  3140. return data.map(function(item) {
  3141. return item;
  3142. });
  3143. });
  3144. }
  3145. };
  3146. // 获取产品型号联想词
  3147. $scope.getSimilarCodes = function(value) {
  3148. if (value) {
  3149. // 获取产品型号联想词
  3150. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  3151. return data.map(function (item) {
  3152. return item;
  3153. })
  3154. });
  3155. }
  3156. };
  3157. $scope.selectKind = function(prod) {
  3158. var submit = [];
  3159. $modal.open({
  3160. animation: true,
  3161. size: 'lg',
  3162. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  3163. controller: 'ProdKindChooseCtrl',
  3164. resolve: {
  3165. actives: function() {
  3166. return $scope.actives;
  3167. }
  3168. }
  3169. }).result.then(function(data){
  3170. $scope.actives = data.actives;
  3171. var size = data.actives.length;
  3172. submit.gradeOneKiName = '';
  3173. submit.gradeTwoKiName = '';
  3174. submit.gradeThreeKiName = '';
  3175. if (size > 0) {
  3176. submit.gradeOneKiName = $scope.actives[0].nameCn;
  3177. prod.prodTitle = submit.gradeOneKiName;
  3178. if (size > 1) {
  3179. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  3180. prod.prodTitle = submit.gradeTwoKiName;
  3181. if (size > 2) {
  3182. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  3183. prod.prodTitle = submit.gradeThreeKiName;
  3184. }
  3185. }
  3186. }
  3187. }, function(){
  3188. });
  3189. };
  3190. // 点击联想词获取品牌信息
  3191. $scope.onAssociateBrandClick = function(brand, prod) {
  3192. if (brand instanceof String) {
  3193. prod.inbrand = brand;
  3194. } else if (brand instanceof Object) {
  3195. prod.inbrand = brand.brandCn;
  3196. }
  3197. };
  3198. // 打开品牌选择的模态框
  3199. $scope.selectBrand = function(prod){ //打开模态
  3200. var modalInstance = $modal.open({
  3201. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  3202. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  3203. });
  3204. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  3205. });
  3206. modalInstance.result.then(function(brand){
  3207. prod.inbrand = brand.nameCn;
  3208. }, function(reason){
  3209. });
  3210. };
  3211. // 点击联想词获取器件信息 带入产品分类和品牌
  3212. $scope.onAssociateCmpClick = function(cmp, prod) {
  3213. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  3214. $scope.component = data;
  3215. prod.prodCode = data.code;
  3216. prod.prodTitle = data.kind.nameCn;
  3217. prod.inbrand = data.brand.nameCn;
  3218. }, function(res) {
  3219. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  3220. })
  3221. };
  3222. //联想词end
  3223. // 导入商品信息
  3224. $scope.uplodaByBatch = function() {
  3225. var modalInstance = $modal.open({
  3226. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  3227. controller: 'PurcInquiryUploadCtrl',
  3228. size: 'lg',
  3229. resolve: {
  3230. }
  3231. });
  3232. modalInstance.result.then(function(data) {
  3233. angular.forEach(data, function(prod) {
  3234. console.log(prod);
  3235. $scope.inquiry.inquiryItems.push(prod);
  3236. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3237. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  3238. $scope.inquiry.inquiryItems.splice(i, 1);
  3239. }
  3240. }
  3241. })
  3242. }, function(){
  3243. });
  3244. }
  3245. //增加商品
  3246. $scope.add = function() {
  3247. $scope.inquiry.inquiryItems.push(
  3248. { prodCode: null,
  3249. prodTitle: null,
  3250. unit: 'PCS',
  3251. ibrand: null,
  3252. toDate: null,
  3253. needquantity: null});
  3254. };
  3255. //删除商品
  3256. $scope.del = function(index) {
  3257. $scope.inquiry.inquiryItems.splice(index, 1);
  3258. };
  3259. $scope.check = function(product) {
  3260. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3261. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  3262. $scope.inquiry.inquiryItems.splice(i, 1);
  3263. }
  3264. }
  3265. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  3266. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand});
  3267. }
  3268. $scope.getMinDate = function(item) {
  3269. return $filter('date')(new Date, 'yyyy-MM-dd');
  3270. };
  3271. $scope.openDatePicker = function($event, openParam, index) {
  3272. $event.preventDefault();
  3273. $event.stopPropagation();
  3274. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  3275. };
  3276. $scope.openEndDatePicker = function($event, item, openParam) {
  3277. $event.preventDefault();
  3278. $event.stopPropagation();
  3279. item[openParam] = !item[openParam];
  3280. };
  3281. $scope.ifrepeat = false;
  3282. // 保存
  3283. $scope.save = function() {
  3284. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3285. $scope.item = $scope.inquiry.inquiryItems[i];
  3286. for(var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  3287. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  3288. if(i != j) {
  3289. if($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  3290. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  3291. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  3292. $scope.ifrepeat = true;
  3293. }
  3294. }
  3295. }
  3296. }
  3297. if(!$scope.ifrepeat) {
  3298. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3299. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3300. if( $scope.vendors.length > 0) {
  3301. $upload.upload({
  3302. url: 'purc/inquiry/save',
  3303. file: file,
  3304. method: 'POST',
  3305. data: {
  3306. inquiry: $scope.inquiry,
  3307. contacts: $scope.vendors
  3308. },
  3309. }).success(function(data) {
  3310. if(data.success) {
  3311. toaster.pop('success', '提示', data.success);
  3312. $timeout(function() {
  3313. $rootScope.active = 'todo';
  3314. window.location.hash = "#/purc/inquiry_unapply";
  3315. }, 500);
  3316. }
  3317. if(data.error) {
  3318. toaster.pop('error', '提示', data.error);
  3319. }
  3320. }).error(function(data) {
  3321. $scope.loadingShow = false;
  3322. toaster.pop('error', '操作失败', data.error);
  3323. });
  3324. } else {
  3325. toaster.pop('info', '提示', '请先选择供应商');
  3326. }
  3327. } else {
  3328. $upload.upload({
  3329. url: 'purc/inquiry/saveWithoutVendor',
  3330. file: file,
  3331. method: 'POST',
  3332. data: {
  3333. inquiry: $scope.inquiry,
  3334. },
  3335. }).success(function(data) {
  3336. if(data.success) {
  3337. toaster.pop('success', '提示', data.success);
  3338. $timeout(function() {
  3339. $rootScope.active = 'done';
  3340. window.location.hash = "#/purc/inquiry_unapply";
  3341. }, 500);
  3342. }
  3343. if(data.error) {
  3344. toaster.pop('error', '提示', data.error);
  3345. }
  3346. }).error(function(data) {
  3347. $scope.loadingShow = false;
  3348. toaster.pop('error', '操作失败', data.error);
  3349. });
  3350. }
  3351. } else {
  3352. toaster.pop('error', '提示', '存在相同条件的物料信息');
  3353. }
  3354. }
  3355. // 保存并提交
  3356. $scope.submit = function() {
  3357. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3358. $scope.item = $scope.inquiry.inquiryItems[i];
  3359. for(var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  3360. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  3361. if(i != j) {
  3362. if($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  3363. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  3364. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  3365. $scope.ifrepeat = true;
  3366. }
  3367. }
  3368. }
  3369. }
  3370. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3371. if(!$scope.ifrepeat) {
  3372. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3373. if($scope.vendors.length > 0) {
  3374. $upload.upload({
  3375. url: 'purc/inquiry/saveAndSubmit',
  3376. file: file,
  3377. method: 'POST',
  3378. data: {
  3379. inquiry: $scope.inquiry,
  3380. contacts: $scope.vendors
  3381. },
  3382. }).success(function(data) {
  3383. if(data.success) {
  3384. toaster.pop('success', '提示', data.success);
  3385. $timeout(function() {
  3386. window.location.hash = "#/purc/purchaseinquiry";
  3387. }, 500);
  3388. }
  3389. if(data.error) {
  3390. toaster.pop('error', '提示', data.error);
  3391. }
  3392. }).error(function(data) {
  3393. $scope.loadingShow = false;
  3394. toaster.pop('error', '操作失败', data.error);
  3395. });
  3396. } else {
  3397. toaster.pop('info', '提示', '请先选择供应商');
  3398. }
  3399. } else {
  3400. $upload.upload({
  3401. url: 'purc/inquiry/saveAndSubmitWithoutVendor',
  3402. file: file,
  3403. method: 'POST',
  3404. data: {
  3405. inquiry: $scope.inquiry,
  3406. },
  3407. }).success(function(data) {
  3408. if(data.success) {
  3409. toaster.pop('success', '提示', data.success);
  3410. $timeout(function() {
  3411. window.location.hash = "#/purc/purchaseinquiry";
  3412. }, 500);
  3413. }
  3414. if(data.error) {
  3415. toaster.pop('error', '提示', data.error);
  3416. }
  3417. }).error(function(data) {
  3418. $scope.loadingShow = false;
  3419. toaster.pop('error', '操作失败', data.error);
  3420. });
  3421. }
  3422. } else {
  3423. toaster.pop('error', '提示', '存在相同条件的物料信息');
  3424. }
  3425. }
  3426. $scope.previewShow = false;
  3427. $scope.pdfShow = false;
  3428. $scope.noneFileShow = true;
  3429. $scope.$watch('myFiles', function(){
  3430. if($scope.myFiles) {
  3431. $scope.noneFileShow = false;
  3432. var file = $scope.myFiles[0];
  3433. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  3434. $scope.pdfShow = true;
  3435. $scope.previewShow = false;
  3436. $scope.imgPreviewName = file.name;
  3437. } else{
  3438. if (typeof(Worker) !== "undefined") {//支持HTML5
  3439. $scope.imgPreview = getObjectURL(file);
  3440. $scope.imgPreviewName = file.name;
  3441. } else{//不支持HTML5
  3442. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  3443. $scope.imgPreviewName = file.name;
  3444. }
  3445. $scope.previewShow = true;
  3446. $scope.pdfShow = false;
  3447. }
  3448. } else {
  3449. $scope.noneFileShow = true;
  3450. $scope.previewShow = false;
  3451. $scope.pdfShow = false;
  3452. }
  3453. });
  3454. //建立一个可存取到该file的url
  3455. var getObjectURL = function(file) {
  3456. var url = null ;
  3457. if (window.createObjectURL!=undefined) { // basic
  3458. url = window.createObjectURL(file) ;
  3459. } else if (window.URL!=undefined) { // mozilla(firefox)
  3460. url = window.URL.createObjectURL(file) ;
  3461. } else if (window.webkitURL!=undefined) { // webkit or chrome
  3462. url = window.webkitURL.createObjectURL(file) ;
  3463. }
  3464. return url ;
  3465. };
  3466. }]);
  3467. /**
  3468. * 代采订单批量导入
  3469. */
  3470. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  3471. // 通过excel批量上传物料
  3472. $scope.result = null;
  3473. $scope.upload = function() {
  3474. var file = $scope.myFiles[0];
  3475. $upload.upload({
  3476. url: 'purc/inquiry/release/excel',
  3477. file: file,
  3478. method: 'POST'
  3479. }).success(function(data) {
  3480. $scope.result = data;
  3481. $scope.success = $scope.result.success;
  3482. $scope.total = $scope.result.total;
  3483. $scope.alters = $scope.result.alters;
  3484. }).error(function(response) {
  3485. toaster.pop('error', response.data || response);
  3486. });
  3487. };
  3488. // 查看范例
  3489. $scope.showImg = function() {
  3490. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  3491. box.show();
  3492. box.find('img').attr('src', src);
  3493. box.find('a').click(function(){
  3494. box.hide();
  3495. });
  3496. box.dblclick(function(){
  3497. box.hide();
  3498. });
  3499. };
  3500. // 下载模板
  3501. $scope.download = function() {
  3502. window.location.href = 'purc/inquiry/upload/template';
  3503. };
  3504. $scope.enSure = function() {
  3505. $modalInstance.close($scope.result.items);
  3506. }
  3507. $scope.cancel = function() {
  3508. $modalInstance.dismiss();
  3509. }
  3510. }]);
  3511. // 平台询价单(已提交)
  3512. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope) {
  3513. $scope.status = 'InquirySubmit';
  3514. BaseService.scrollBackToTop();
  3515. if($rootScope.active) {
  3516. $scope.active = $rootScope.active;
  3517. $rootScope.active = null;
  3518. } else {
  3519. $scope.active = 'todo';
  3520. }
  3521. $scope.agreedText = '全部';
  3522. $scope.dateZoneText = '一个月内';
  3523. $scope.condition = {dateZone: 1};
  3524. $scope.changeAgreed = function(agreed) {
  3525. $scope.condition.agreed = agreed;
  3526. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3527. $scope.condition.$agreedOpen = false;
  3528. };
  3529. $scope.changeDateZone = function(zone) {
  3530. $scope.condition.dateZone = zone;
  3531. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3532. $scope.condition.$dateZoneOpen = false;
  3533. };
  3534. $scope.setActive = function(state) {
  3535. if($scope.active != state ) {
  3536. $scope.active = state;
  3537. if ($scope.tableParams.page() == 1) {
  3538. $scope.tableParams.reload();
  3539. } else {
  3540. $scope.tableParams.page(1);
  3541. }
  3542. }
  3543. }
  3544. var getService = function() {
  3545. return PurchaseInquiry;
  3546. };
  3547. $scope.tableParams = new ngTableParams({
  3548. page : 1,
  3549. count : 20,
  3550. sorting: {
  3551. 'inquiry.date': 'desc',
  3552. 'inquiry.enterprise.enName': 'asc',
  3553. 'inquiry.code': 'asc'
  3554. }
  3555. }, {
  3556. total : 0,
  3557. counts: [5, 10, 25, 50],
  3558. getData : function($defer, params) {
  3559. $scope.loading = true;
  3560. var pageParams = params.url();
  3561. var realActive = {};
  3562. pageParams.keyword = $scope.keyword;
  3563. if ($scope.active == 'overdue') {
  3564. $scope.active = 'end';
  3565. }
  3566. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3567. $scope.loading = false;
  3568. if(page) {
  3569. params.total(page.totalElement);
  3570. $defer.resolve(page.content);
  3571. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3572. }
  3573. }, function(response){
  3574. $scope.loading = false;
  3575. toaster.pop('error', '数据加载失败', response.data);
  3576. });
  3577. }
  3578. });
  3579. $scope.openDatePicker = function($event, item, openParam) {
  3580. $event.preventDefault();
  3581. $event.stopPropagation();
  3582. item[openParam] = !item[openParam];
  3583. };
  3584. // 搜索框回车
  3585. $scope.onSearch = function() {
  3586. $scope.tableParams.page(1);
  3587. $scope.tableParams.reload();
  3588. };
  3589. // 采纳
  3590. $scope.accept = function(id) {
  3591. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3592. if(data.success) {
  3593. toaster.pop('success', '提示', data.success);
  3594. $scope.tableParams.reload();
  3595. }
  3596. if(data.error) {
  3597. toaster.pop('error', '提示', data.error);
  3598. }
  3599. }, function(response) {
  3600. toaster.pop('error', '提示', response.data);
  3601. })
  3602. };
  3603. // 拒绝
  3604. $scope.refuse = function(id) {
  3605. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3606. if(data.success) {
  3607. toaster.pop('success', '提示', data.success);
  3608. $scope.tableParams.reload();
  3609. }
  3610. if(data.error) {
  3611. toaster.pop('error', '提示', data.error);
  3612. }
  3613. }, function(response) {
  3614. toaster.pop('error', '提示', response.data);
  3615. })
  3616. }
  3617. }]);
  3618. // 平台询价单(未提交)
  3619. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  3620. BaseService.scrollBackToTop();
  3621. if($rootScope.active = 'done') {
  3622. $scope.active = 'done';
  3623. $rootScope.active = '';
  3624. }
  3625. if($rootScope.active = 'todo') {
  3626. $scope.active = 'todo';
  3627. $rootScope.active = '';
  3628. }
  3629. var getService = function() {
  3630. if($scope.active == 'todo') {
  3631. return PurchaseInquiry.getUnapply;
  3632. }
  3633. if($scope.active == 'done') {
  3634. return PurchaseInquiry.getSubmit;
  3635. }
  3636. }
  3637. $scope.setActive = function(state) {
  3638. if($scope.active != state ) {
  3639. $scope.active = state;
  3640. if ($scope.tableParams.page() == 1) {
  3641. $scope.tableParams.reload();
  3642. } else {
  3643. $scope.tableParams.page(1);
  3644. }
  3645. }
  3646. }
  3647. $scope.tableParams = new ngTableParams({
  3648. page : 1,
  3649. count : 20,
  3650. sorting: {
  3651. 'date': 'desc',
  3652. 'enterprise.enName': 'asc',
  3653. 'code': 'asc'
  3654. }
  3655. }, {
  3656. total : 0,
  3657. counts: [5, 10, 25, 50],
  3658. getData : function($defer, params) {
  3659. $scope.loading = true;
  3660. var pageParams = params.url();
  3661. var realActive = {};
  3662. if ($scope.active == 'overdue') {
  3663. $scope.active = 'end';
  3664. }
  3665. getService().call(null, BaseService.parseParams(pageParams), function(page){
  3666. $scope.loading = false;
  3667. if(page) {
  3668. params.total(page.totalElements);
  3669. $defer.resolve(page.content);
  3670. }
  3671. }, function(response){
  3672. $scope.loading = false;
  3673. toaster.pop('error', '数据加载失败', response.data);
  3674. });
  3675. }
  3676. });
  3677. // 删除明细
  3678. $scope.deleteById = function(id) {
  3679. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  3680. toaster.pop('success', '提示', '删除成功');
  3681. $scope.tableParams.reload();
  3682. }, function(response) {
  3683. toaster.pop('error', '提示', response.data);
  3684. });
  3685. }
  3686. // 删除主表
  3687. $scope.clearOrder = function(id) {
  3688. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  3689. toaster.pop('success', '提示', '删除成功');
  3690. $scope.tableParams.reload();
  3691. }, function(response) {
  3692. toaster.pop('error', '提示', response.data);
  3693. });
  3694. }
  3695. // 提交
  3696. $scope.submit = function(id) {
  3697. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  3698. toaster.pop('success', '提示', '单据提交成功');
  3699. $scope.active = 'done';
  3700. $scope.tableParams.reload();
  3701. }, function(response) {
  3702. toaster.pop('error', '提示', response.data);
  3703. })
  3704. }
  3705. // 发布公共询价
  3706. $scope.publish = function(id) {
  3707. PurchaseInquiry.publishInquiry({id: id}, {}, function(data) {
  3708. toaster.pop('success', '提示', data.success);
  3709. $scope.active = 'done';
  3710. $scope.tableParams.reload();
  3711. }, function(response) {
  3712. toaster.pop('error', '提示', response.data);
  3713. })
  3714. }
  3715. }]);
  3716. // 公共询价列表
  3717. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams) {
  3718. BaseService.scrollBackToTop();
  3719. /**
  3720. * 改变单据日期范围
  3721. */
  3722. var getTenderDateCondition = function(zone, condition) {
  3723. var date = new Date();
  3724. if(zone == -1) {
  3725. condition.dateFrom = null;
  3726. condition.dateTo = null;
  3727. } else if(zone == 7) { // 一星期内
  3728. date.setDate(date.getDate() - 7);
  3729. condition.dateFrom = date;
  3730. condition.dateTo = new Date();
  3731. } else if(zone == 1) { // 一个月内
  3732. date.setMonth(date.getMonth() - 1);
  3733. condition.dateFrom = date;
  3734. condition.dateTo = new Date();
  3735. } else if(zone == 3) { // 三个月内
  3736. date.setMonth(date.getMonth() - 3);
  3737. condition.dateFrom = date;
  3738. condition.dateTo = new Date();
  3739. } else if (zone == 6) { // 半年内
  3740. date.setMonth(date.getMonth() - 6);
  3741. condition.dateFrom = date;
  3742. condition.dateTo = new Date();
  3743. } else { // 一年内
  3744. date.setYear(date.getYear() - 1);
  3745. condition.dateFrom = date;
  3746. condition.dateTo = new Date();
  3747. }
  3748. };
  3749. $scope.dateZoneText = '不限';
  3750. $scope.deliveryZoneText = '不限';
  3751. $scope.condition = {dateZone: -1};
  3752. $scope.changeDateZone = function(zone) {
  3753. $scope.condition.dateZone = zone;
  3754. $scope.condition.$dateZoneOpen = false;
  3755. getTenderDateCondition(zone, $scope.condition);
  3756. $scope.tableParams.reload();
  3757. };
  3758. $scope.openDatePicker = function($event, item, openParam) {
  3759. $event.preventDefault();
  3760. $event.stopPropagation();
  3761. item[openParam] = !item[openParam];
  3762. };
  3763. $scope.parseDate = function(dateStr) {
  3764. if(dateStr)
  3765. return Date.parse(dateStr, 'yyyy-MM-dd');
  3766. return new Date();
  3767. };
  3768. // 选择查找日期
  3769. $scope.onDateCondition = function(){
  3770. $scope.tableParams.page(1);
  3771. $scope.tableParams.reload();
  3772. };
  3773. // $scope.setActive = function(state) {
  3774. // if($scope.active != state) {
  3775. // $scope.active = state;
  3776. // if($scope.tableParams.page() == 1)
  3777. // $scope.tableParams.reload();
  3778. // else
  3779. // $scope.tableParams.page(1);
  3780. // }
  3781. // };
  3782. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  3783. console.log($scope.nowdate);
  3784. var getOpenState = function(active) {
  3785. var fn = 'getOpenAll';
  3786. switch(active) {
  3787. case 'all':
  3788. fn = 'getOpenAll';break;
  3789. case 'todo':
  3790. fn = 'getOpenTodo';break;
  3791. case 'end':
  3792. fn = 'getOpenEnd';break;
  3793. }
  3794. return fn;
  3795. };
  3796. $scope.tableParams = new ngTableParams({
  3797. page : 1,
  3798. count : 20,
  3799. sorting: {
  3800. // 'tender.endDate': 'desc',
  3801. // 'tender.enterprise.enName': 'asc',
  3802. // 'tender.code': 'asc'
  3803. }
  3804. }, {
  3805. total : 0,
  3806. counts: [10, 25, 50, 100],
  3807. getData : function($defer, params) {
  3808. $scope.loading = true;
  3809. var pageParams = params.url();
  3810. // var realActive = {};
  3811. pageParams.searchFilter = { // 筛选条件
  3812. keyword: $scope.keyword,
  3813. fromDate: getDateTime($scope.condition.dateFrom),
  3814. endDate: getDateTime($scope.condition.dateTo)
  3815. };
  3816. // AccountEnterprise.get({}, function(data){
  3817. // $scope.loading = false;
  3818. // $scope.currentEn = data;
  3819. // });
  3820. PurchaseInquiry.publicInquiryItem.call(null, BaseService.parseParams(pageParams), function(page){
  3821. $scope.loading = false;
  3822. if(page) {
  3823. params.total(page.totalElement);
  3824. $defer.resolve(page.content);
  3825. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  3826. }
  3827. }, function(response){
  3828. $scope.loading = false;
  3829. toaster.pop('error', '数据加载失败', response.data);
  3830. });
  3831. }
  3832. });
  3833. $scope.toDetail = function(id) {
  3834. window.location.hash = '#/baseInfo/inquiryList/' + id;
  3835. };
  3836. // 搜索框回车
  3837. $scope.onSearch = function() {
  3838. $scope.tableParams.page(1);
  3839. $scope.tableParams.reload();
  3840. };
  3841. }]);
  3842. /**
  3843. * 公共询价详情
  3844. */
  3845. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise) {
  3846. BaseService.scrollBackToTop();
  3847. $scope.currentHasBid = false;
  3848. var loadData = function() {
  3849. PurchaseInquiry.inquiryItemDetail({id: $stateParams.id}, function(data) {
  3850. $scope.inquiryItem = data.inquiryItem;
  3851. if(data.id) {
  3852. $scope.id = data.id;
  3853. console.log($scope.id);
  3854. $scope.currentHasBid = true;
  3855. }
  3856. }, function(response) {
  3857. toaster.pop('error', '提示', response.data);
  3858. });
  3859. }
  3860. loadData();
  3861. // 当前时间
  3862. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  3863. // 当前企业
  3864. AccountEnterprise.get({}, function(data){
  3865. $scope.loading = false;
  3866. $scope.enterprise = data;
  3867. });
  3868. // 转客户询价
  3869. $scope.transtoInquiry = function(id) {
  3870. PurchaseInquiry.transtoInquiry({id: id}, {}, function(data) {
  3871. if(data.success) {
  3872. toaster.pop('success', '提示', data.success);
  3873. window.location.hash = "sale/inquiry/" + data.id;
  3874. }
  3875. if(data.error) {
  3876. toaster.pop('error', '提示', data.error);
  3877. }
  3878. if(data.info) {
  3879. toaster.pop('info', '提示', data.info);
  3880. }
  3881. }, function(response) {
  3882. toaster.pop('error', '提示', response.data);
  3883. });
  3884. }
  3885. }]);
  3886. // 询价单明细
  3887. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  3888. var loadData = function() {
  3889. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  3890. $scope.newinquiryItems = data;
  3891. var inquiry = data[0].inquiry;
  3892. //inquiry.inquiryItems = data;
  3893. angular.forEach(inquiry.attachs, function(attach){
  3894. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3895. });
  3896. $scope.inquiry = inquiry;
  3897. });
  3898. };
  3899. loadData();
  3900. $scope.getMinDate = function(item) {
  3901. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3902. };
  3903. $scope.addStep = function(inquiryItem) {
  3904. if(inquiryItem.replies.length >= 10) {
  3905. toaster.pop('warning', '提示', '最多支持10个分段!');
  3906. } else
  3907. inquiryItem.replies.push({});
  3908. };
  3909. $scope.removeStep = function(inquiryItem, stepIndex) {
  3910. inquiryItem.replies.splice(stepIndex, 1);
  3911. };
  3912. $scope.openDatePicker = function($event, item, openParam) {
  3913. $event.preventDefault();
  3914. $event.stopPropagation();
  3915. item[openParam] = !item[openParam];
  3916. };
  3917. $scope.getHistory = function(item) {
  3918. if(!item.history) {
  3919. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3920. item.history = data;
  3921. });
  3922. }
  3923. };
  3924. $scope.isValid = function(item, withSteps) {
  3925. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3926. if(!withSteps || !bool)
  3927. return bool;
  3928. angular.forEach(item.replies, function(r, i){
  3929. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3930. });
  3931. return bool;
  3932. };
  3933. $scope.onReplyClick = function(item, withSteps) {
  3934. if(item.vendFromDate instanceof Date) {
  3935. item.vendFromDate = item.vendFromDate.getTime();
  3936. }
  3937. if(item.vendToDate instanceof Date) {
  3938. item.vendToDate = item.vendToDate.getTime();
  3939. }
  3940. if(item.vendFromDate > item.vendToDate) {
  3941. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3942. return;
  3943. }
  3944. var replies = [];
  3945. angular.forEach(item.replies, function(r, i){
  3946. if((i > 0 ? r.lapQty : 1) || r.price)
  3947. replies.push(r);
  3948. });
  3949. item.replies = replies;
  3950. if(withSteps) {
  3951. PurcInquiry.reply({itemId: item.id}, item, function(){
  3952. toaster.pop('info', '提示', '报价成功');
  3953. loadData();
  3954. }, function(response){
  3955. toaster.pop('error', '报价失败', response.data);
  3956. });
  3957. }
  3958. };
  3959. }]);
  3960. // 询价单明细(发出)
  3961. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', function($scope, $stateParams, PurchaseInquiry,$filter, toaster){
  3962. var loadData = function() {
  3963. PurchaseInquiry.detail({id: $stateParams.id}, function(data){
  3964. $scope.inquiry = data;
  3965. });
  3966. };
  3967. loadData();
  3968. $scope.getMinDate = function(item) {
  3969. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3970. };
  3971. $scope.addStep = function(inquiryItem) {
  3972. if(inquiryItem.replies.length >= 10) {
  3973. toaster.pop('warning', '提示', '最多支持10个分段!');
  3974. } else
  3975. inquiryItem.replies.push({});
  3976. };
  3977. $scope.removeStep = function(inquiryItem, stepIndex) {
  3978. inquiryItem.replies.splice(stepIndex, 1);
  3979. };
  3980. $scope.openDatePicker = function($event, item, openParam) {
  3981. $event.preventDefault();
  3982. $event.stopPropagation();
  3983. item[openParam] = !item[openParam];
  3984. };
  3985. $scope.getHistory = function(item) {
  3986. if(!item.history) {
  3987. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3988. item.history = data;
  3989. });
  3990. }
  3991. };
  3992. $scope.isValid = function(item, withSteps) {
  3993. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3994. if(!withSteps || !bool)
  3995. return bool;
  3996. angular.forEach(item.replies, function(r, i){
  3997. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3998. });
  3999. return bool;
  4000. };
  4001. $scope.onReplyClick = function(item, withSteps) {
  4002. if(item.vendFromDate instanceof Date) {
  4003. item.vendFromDate = item.vendFromDate.getTime();
  4004. }
  4005. if(item.vendToDate instanceof Date) {
  4006. item.vendToDate = item.vendToDate.getTime();
  4007. }
  4008. if(item.vendFromDate > item.vendToDate) {
  4009. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4010. return;
  4011. }
  4012. var replies = [];
  4013. angular.forEach(item.replies, function(r, i){
  4014. if((i > 0 ? r.lapQty : 1) || r.price)
  4015. replies.push(r);
  4016. });
  4017. item.replies = replies;
  4018. if(withSteps) {
  4019. PurcInquiry.reply({itemId: item.id}, item, function(){
  4020. toaster.pop('info', '提示', '报价成功');
  4021. loadData();
  4022. }, function(response){
  4023. toaster.pop('error', '报价失败', response.data);
  4024. });
  4025. }
  4026. };
  4027. // 采纳
  4028. $scope.accept = function(id) {
  4029. PurchaseInquiry.accept({id: id}, {}, function(data) {
  4030. if(data.success) {
  4031. toaster.pop('success', '提示', data.success);
  4032. loadData();
  4033. }
  4034. if(data.error) {
  4035. toaster.pop('error', '提示', data.error);
  4036. }
  4037. }, function(response) {
  4038. toaster.pop('error', '提示', response.data);
  4039. })
  4040. };
  4041. // 拒绝
  4042. $scope.refuse = function(id) {
  4043. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  4044. if(data.success) {
  4045. toaster.pop('success', '提示', data.success);
  4046. loadData();
  4047. }
  4048. if(data.error) {
  4049. toaster.pop('error', '提示', data.error);
  4050. }
  4051. }, function(response) {
  4052. toaster.pop('error', '提示', response.data);
  4053. })
  4054. }
  4055. }]);
  4056. // 模具询价管理
  4057. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  4058. BaseService.scrollBackToTop();
  4059. /**
  4060. * 改变单据日期范围
  4061. */
  4062. var getTenderDateCondition = function(zone, condition) {
  4063. var date = new Date();
  4064. if(zone == -1) {
  4065. condition.dateFrom = null;
  4066. condition.dateTo = null;
  4067. } else if(zone == 1) { // 一个月内
  4068. date.setMonth(date.getMonth() - 1);
  4069. condition.dateFrom = date;
  4070. condition.dateTo = new Date();
  4071. } else if (zone == 6) { // 半年内
  4072. date.setMonth(date.getMonth() - 6);
  4073. condition.dateFrom = date;
  4074. condition.dateTo = new Date();
  4075. } else if (zone == -6) { // 半年前
  4076. date.setMonth(date.getMonth() - 6);
  4077. condition.dateFrom = null;
  4078. condition.dateTo = date;
  4079. } else { // 无效zone,转为查找全部
  4080. condition.dateFrom = null;
  4081. condition.dateTo = null;
  4082. }
  4083. };
  4084. $scope.active = 'todo';
  4085. $scope.agreedText = '全部';
  4086. $scope.dateZoneText = '不限';
  4087. $scope.condition = {dateZone: -1};
  4088. var inquiryMould_copy = {};
  4089. $scope.changeAgreed = function(agreed) {
  4090. $scope.condition.agreed = agreed;
  4091. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4092. $scope.condition.$agreedOpen = false;
  4093. };
  4094. $scope.changeDateZone = function(zone) {
  4095. $scope.condition.dateZone = zone;
  4096. $scope.dateZoneText = zone == -6 ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4097. $scope.condition.$dateZoneOpen = false;
  4098. $scope.condition.dateZone = zone;
  4099. getTenderDateCondition(zone, $scope.condition);
  4100. $scope.tableParams.reload();
  4101. };
  4102. $scope.setActive = function(state) {
  4103. if($scope.active != state ) {
  4104. $scope.active = state;
  4105. if ($scope.tableParams.page() == 1) {
  4106. $scope.tableParams.reload();
  4107. } else {
  4108. $scope.tableParams.page(1);
  4109. }
  4110. }
  4111. };
  4112. var getService = function() {
  4113. return PurcInquiryMould;
  4114. };
  4115. $scope.tableParams = new ngTableParams({
  4116. page: 1,
  4117. count: 5
  4118. },{
  4119. total: 0,
  4120. counts: [5, 10, 25, 50],
  4121. getData: function($defer, params) {
  4122. $scope.loading = true;
  4123. var pageParams = params.url();
  4124. var realActive = {};
  4125. pageParams.searchFilter = {
  4126. keyword: $scope.keyword,
  4127. fromDate: getDateTime($scope.condition.dateFrom),
  4128. endDate: getDateTime($scope.condition.dateTo)
  4129. };
  4130. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4131. $scope.loading = false;
  4132. // 用来验证价格修改
  4133. var mould = page.content;
  4134. inquiryMould_copy = angular.copy(mould);
  4135. if(page) {
  4136. params.total(page.totalElement);
  4137. $defer.resolve(page.content);
  4138. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4139. }
  4140. }, function(response){
  4141. $scope.loading = false;
  4142. toaster.pop('error', '数据加载失败', response.data);
  4143. });
  4144. }
  4145. })
  4146. $scope.getMinDate = function(item) {
  4147. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  4148. };
  4149. $scope.replyPrices = [];
  4150. $scope.replyPrices.push(true);
  4151. // 取消
  4152. $scope.reload = function() {
  4153. $scope.tableParams.reload();
  4154. $scope.canSave = false;
  4155. }
  4156. // 能否保存设置
  4157. $scope.canSave = false;
  4158. // items价格验证
  4159. $scope.verifyItems = function(price, reply) {
  4160. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  4161. if(regex.test(price) && price != 0) {
  4162. if (price != reply) {
  4163. $scope.canSave = true;
  4164. } else {
  4165. $scope.canSave = false;
  4166. }
  4167. } else {
  4168. $scope.canSave = false;
  4169. }
  4170. }
  4171. // prod下prods价格验证
  4172. $scope.verifyProds = function(price, reply) {
  4173. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4174. if(regex.test(price) && price != 0) {
  4175. if (price != reply) {
  4176. $scope.canSave = true;
  4177. } else {
  4178. $scope.canSave = false;
  4179. }
  4180. } else {
  4181. $scope.canSave = false;
  4182. }
  4183. }
  4184. //有价格为0或者不符合正则式,则不能报价
  4185. $scope.notZero = function (mould) {
  4186. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4187. angular.forEach(mould.inquiryMouldItems, function(item){
  4188. if (item.price == 0 || !regex.test(item.price)) {
  4189. $scope.canSave = false;
  4190. }
  4191. angular.forEach(item.inquiryMouldDetails, function(detail){
  4192. if (detail.price == 0 || !regex.test(detail.price)) {
  4193. $scope.canSave = false;
  4194. }
  4195. })
  4196. });
  4197. }
  4198. $scope.blurPrice = function (price) {
  4199. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4200. if (!regex.test(price)) {
  4201. toaster.pop('warning','格式错误','请输入有效价格');
  4202. }
  4203. }
  4204. // 获取历史报价
  4205. $scope.getHistory = function(mould) {
  4206. if(!mould.history) {
  4207. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  4208. mould.history = data;
  4209. });
  4210. }
  4211. };
  4212. $scope.uploadAttach = function(mould) {
  4213. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4214. var file = mould.attachs[0];
  4215. $scope.mould = mould;
  4216. $upload.upload({
  4217. url: 'sale/mould/' + mould.id + '/send',
  4218. method: 'POST',
  4219. file: file,
  4220. data: {
  4221. json: $scope.mould
  4222. }
  4223. }).success(function(res){
  4224. }).error(function(res){
  4225. });
  4226. }
  4227. // 保存并确认报价
  4228. $scope.onReplyClick = function(mould, withSteps) {
  4229. $scope.loading = true;
  4230. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4231. // var file = mould.attachs[0];
  4232. // $scope.mould = mould;
  4233. // $upload.upload({
  4234. // url: 'sale/mould/' + mould.id + '/send',
  4235. // method: 'POST',
  4236. // file: file,
  4237. // data: {
  4238. // json: $scope.mould
  4239. // }
  4240. // }).success(function(res){
  4241. // console.log("success");
  4242. // console.log(res);
  4243. // }).error(function(res){
  4244. // console.log("failure");
  4245. // });
  4246. if(withSteps) {
  4247. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4248. $scope.loading = false;
  4249. toaster.pop('info', '提示', '报价成功');
  4250. $scope.tableParams.reload();
  4251. $scope.canSave = false;
  4252. }, function(response){
  4253. $scope.loading = false;
  4254. toaster.pop('error', '报价失败', response.data);
  4255. });
  4256. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4257. }, function(response){
  4258. });
  4259. } else {
  4260. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4261. $scope.loading = false;
  4262. toaster.pop('info', '提示', '保存成功');
  4263. $scope.tableParams.reload();
  4264. }, function(response){
  4265. $scope.loading = false;
  4266. toaster.pop('error', '保存失败', response.data);
  4267. });
  4268. }
  4269. };
  4270. // 搜索框回车
  4271. $scope.onSearch = function() {
  4272. $scope.tableParams.page(1);
  4273. $scope.tableParams.reload();
  4274. };
  4275. $scope.openDatePicker = function($event, item, openParam) {
  4276. $event.preventDefault();
  4277. $event.stopPropagation();
  4278. item[openParam] = !item[openParam];
  4279. };
  4280. $scope.parseDate = function(dateStr) {
  4281. if(dateStr)
  4282. return Date.parse(dateStr, 'yyyy-MM-dd');
  4283. return new Date();
  4284. };
  4285. }]);
  4286. // 模具询价单明细
  4287. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  4288. var inquiryMould_copy = {};
  4289. var loadData = function() {
  4290. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  4291. // 用来验证价格修改
  4292. inquiryMould_copy = angular.copy(data);
  4293. $scope.inquiryMould_copy = inquiryMould_copy;
  4294. $scope.newinquirymould = data;
  4295. var mould = data;
  4296. angular.forEach(mould.attachs, function(attach){
  4297. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  4298. });
  4299. $scope.inquiryMould = mould;
  4300. });
  4301. };
  4302. loadData();
  4303. $scope.getMinDate = function(item) {
  4304. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4305. };
  4306. // 取消
  4307. $scope.reload = function() {
  4308. loadData();
  4309. $scope.canSave = false;
  4310. }
  4311. //有价格为0,则不能报价
  4312. $scope.notZero = function (mould) {
  4313. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4314. angular.forEach(mould.inquiryMouldItems, function(item){
  4315. if (item.price == 0 || !regex.test(item.price)) {
  4316. $scope.canSave = false;
  4317. }
  4318. angular.forEach(item.inquiryMouldDetails, function(detail){
  4319. if (detail.price == 0 || !regex.test(detail.price)) {
  4320. $scope.canSave = false;
  4321. }
  4322. })
  4323. });
  4324. }
  4325. $scope.blurPrice = function (price) {
  4326. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4327. if (!regex.test(price)) {
  4328. toaster.pop('warning','格式错误','请输入有效价格');
  4329. }
  4330. }
  4331. // 获取历史报价
  4332. $scope.getHistory = function(mould) {
  4333. if(!mould.history) {
  4334. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  4335. mould.history = data;
  4336. });
  4337. }
  4338. };
  4339. $scope.canSave = false;
  4340. // items价格验证
  4341. $scope.verifyItems = function(price, index) {
  4342. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4343. if(regex.test(price) && price != 0) {
  4344. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  4345. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  4346. $scope.canSave = true;
  4347. } else {
  4348. $scope.canSave = false;
  4349. }
  4350. } else {
  4351. $scope.canSave = false;
  4352. }
  4353. }
  4354. // prod下prods价格验证
  4355. $scope.verifyProds = function(price, index, parentIndex) {
  4356. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4357. if(regex.test(price) && price != 0) {
  4358. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  4359. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  4360. $scope.canSave = true;
  4361. } else {
  4362. $scope.canSave = false;
  4363. }
  4364. } else {
  4365. $scope.canSave = false;
  4366. }
  4367. }
  4368. // // 上传附件
  4369. // $scope.uploadAttach = function(mould) {
  4370. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4371. // var file = mould.attachs[0];
  4372. // $scope.mould = mould;
  4373. // $upload.upload({
  4374. // url: 'sale/mould/' + mould.id + '/send',
  4375. // method: 'POST',
  4376. // file: file,
  4377. // data: {
  4378. // json: $scope.mould
  4379. // }
  4380. // }).success(function(res){
  4381. // console.log("success");
  4382. // console.log(res);
  4383. // }).error(function(res){
  4384. // console.log("failure");
  4385. // console.log(res);
  4386. // });
  4387. // }
  4388. $scope.onReplyClick = function(mould, withSteps) {
  4389. $scope.loading = true;
  4390. // var file = mould.attachs[0];
  4391. // $scope.mould = mould;
  4392. // $upload.upload({
  4393. // url: 'sale/mould/' + mould.id + '/send',
  4394. // method: 'POST',
  4395. // file: file,
  4396. // data: {
  4397. // json: $scope.mould
  4398. // }
  4399. // }).success(function(res){
  4400. //
  4401. // }).error(function(res){
  4402. // console.log(res);
  4403. // });
  4404. if(withSteps) {
  4405. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4406. $scope.loading = false;
  4407. toaster.pop('info', '提示', '报价成功');
  4408. loadData();
  4409. $scope.canSave = false;
  4410. }, function(response){
  4411. $scope.loading = false;
  4412. toaster.pop('error', '报价失败', response.data);
  4413. });
  4414. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4415. }, function(response){
  4416. });
  4417. } else {
  4418. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4419. $scope.loading = false;
  4420. toaster.pop('info', '提示', '保存成功');
  4421. loadData();
  4422. }, function(response){
  4423. $scope.loading = false;
  4424. toaster.pop('error', '保存失败', response.data);
  4425. });
  4426. }
  4427. };
  4428. }]);
  4429. // 主动报价 - 列表
  4430. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope){
  4431. BaseService.scrollBackToTop();
  4432. $rootScope.enteryStatus = false;
  4433. $scope.active = 'todo';
  4434. $scope.agreedText = '全部';
  4435. $scope.dateZoneText = '一个月内';
  4436. $scope.condition = {dateZone: 1};
  4437. $scope.changeDateZone = function(zone) {
  4438. $scope.condition.dateZone = zone;
  4439. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4440. $scope.condition.$dateZoneOpen = false;
  4441. };
  4442. $scope.setActive = function(state) {
  4443. if($scope.active != state) {
  4444. $scope.active = state;
  4445. if($scope.tableParams.page() == 1)
  4446. $scope.tableParams.reload();
  4447. else
  4448. $scope.tableParams.page(1);
  4449. }
  4450. };
  4451. var getService = function() {
  4452. return Quotation;
  4453. };
  4454. $scope.tableParams = new ngTableParams({
  4455. page : 1,
  4456. count : 20,
  4457. sorting: {
  4458. 'quotation.date': 'desc'
  4459. }
  4460. }, {
  4461. total : 0,
  4462. counts: [5, 10, 25, 50],
  4463. getData : function($defer, params) {
  4464. $scope.loading = true;
  4465. var pageParams = params.url();
  4466. pageParams.keyword = $scope.keyword;
  4467. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4468. $scope.loading = false;
  4469. if(page) {
  4470. params.total(page.totalElement);
  4471. $defer.resolve(page.content);
  4472. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4473. }
  4474. }, function(response){
  4475. $scope.loading = false;
  4476. toaster.pop('error', '数据加载失败', response.data);
  4477. });
  4478. }
  4479. });
  4480. $scope.getHistory = function(item) {
  4481. if(!item.history) {
  4482. PurcInquiry.getHistory({itemId: item.id}, function(data){
  4483. item.history = data;
  4484. });
  4485. }
  4486. };
  4487. $scope.isValid = function(item, withSteps) {
  4488. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4489. if(!withSteps || !bool)
  4490. return bool;
  4491. angular.forEach(item.replies, function(r, i){
  4492. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4493. });
  4494. return bool;
  4495. };
  4496. // 搜索框回车
  4497. $scope.onSearch = function() {
  4498. $scope.tableParams.page(1);
  4499. $scope.tableParams.reload();
  4500. };
  4501. }]);
  4502. // Controller 主动报价 - 新增
  4503. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope){
  4504. BaseService.scrollBackToTop();
  4505. var staticItem = null;
  4506. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  4507. $scope.loading = true;
  4508. $rootScope.enteryStatus = true;
  4509. Quotation.getItem({id: $stateParams.id}, function(data){
  4510. // data.$editing = false;
  4511. $scope.item = data;
  4512. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  4513. staticItem = angular.copy(data);
  4514. $scope.loading = false;
  4515. }, function(response){
  4516. $scope.loading = false;
  4517. toaster.pop('error', '数据加载失败', response.data);
  4518. });
  4519. } else {// 新增模式
  4520. $rootScope.enteryStatus = false;
  4521. $scope.item = {
  4522. quotation: {
  4523. currency: 'RMB',
  4524. taxrate: 17,
  4525. date: new Date()
  4526. },
  4527. product: {},
  4528. prices: [{lapQty: 0}],
  4529. minOrderQty: 1,
  4530. minPackQty: 1,
  4531. $endDateOpen: false,
  4532. $editing: true
  4533. };
  4534. }
  4535. $scope.getMinDate = function(item) {
  4536. return $filter('date')(new Date, 'yyyy-MM-dd');
  4537. };
  4538. $scope.openDatePicker = function($event, openParam) {
  4539. $event.preventDefault();
  4540. $event.stopPropagation();
  4541. $scope.item.$endDateOpen = !openParam;
  4542. };
  4543. // 增加一个分段
  4544. $scope.addPrice = function(){
  4545. if($scope.item.prices.length >= 10) {
  4546. toaster.pop('warning', '提示', '最多支持10个分段!');
  4547. } else
  4548. $scope.item.prices.push({});
  4549. };
  4550. // 删除一个分段
  4551. $scope.removePrice = function(index) {
  4552. $scope.item.prices.splice(index, 1);
  4553. };
  4554. // 查找客户
  4555. $scope.dbfindCust = function(){
  4556. if($scope.item.$editing) {
  4557. var modalInstance = $modal.open({
  4558. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  4559. controller: 'DbfindCustCtrl',
  4560. size: 'lg',
  4561. resolve: {
  4562. }
  4563. });
  4564. modalInstance.result.then(function(data){
  4565. $scope.item.quotation.cust = data.myEnterprise;
  4566. $scope.item.quotation.custUser = data.myUser;
  4567. $scope.item.product = null;
  4568. }, function(){
  4569. });
  4570. }
  4571. };
  4572. // 赋值客户信息
  4573. if($rootScope.custuu) {
  4574. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function(data) {
  4575. $scope.item.quotation.cust = data.myEnterprise;
  4576. $scope.item.quotation.custUser = data.myUser;
  4577. })
  4578. }
  4579. // 赋值物料信息
  4580. if($rootScope.prodId) {
  4581. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  4582. $scope.item.product.code = data.code;
  4583. $scope.item.product.title = data.title;
  4584. $scope.item.product.spec = data.spec;
  4585. $scope.item.product.unit = data.unit;
  4586. $scope.item.product.id = data.id;
  4587. }, function(response) {
  4588. });
  4589. }
  4590. // 查找客户物料
  4591. $scope.dbfindCustProd = function(){
  4592. if($scope.item.$editing) {
  4593. if($scope.item.quotation.cust.uu) {
  4594. var modalInstance = $modal.open({
  4595. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  4596. controller: 'DbfindCustProdCtrl',
  4597. size: 'lg',
  4598. resolve: {
  4599. custUU: function(){return $scope.item.quotation.cust.uu}
  4600. }
  4601. });
  4602. modalInstance.result.then(function(data){
  4603. $scope.item.product = data;
  4604. }, function(){
  4605. });
  4606. } else {
  4607. toaster.pop('error', '错误', '请先选择客户');
  4608. }
  4609. }
  4610. };
  4611. // 保存
  4612. $scope.save = function(){
  4613. $scope.loading = true;
  4614. if(!$scope.item.quotation.code) //新增,设单号
  4615. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  4616. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  4617. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  4618. $scope.item.productId = $scope.item.product.id;
  4619. $scope.item.quotation.status = 100;//在录入
  4620. if($scope.item.quotation.date instanceof Date) {
  4621. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  4622. }
  4623. if($scope.item.quotation.endDate instanceof Date) {
  4624. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  4625. }
  4626. Quotation.save({}, $scope.item, function(data){
  4627. $scope.loading = false;
  4628. toaster.pop('success', '成功', '保存成功');
  4629. if($stateParams.id)
  4630. window.location.reload();
  4631. else
  4632. window.location.hash = '#/sale/quotation/' + data.id;
  4633. }, function(response){
  4634. $scope.loading = false;
  4635. toaster.pop('error', '保存失败', response.data);
  4636. });
  4637. };
  4638. // 更新
  4639. $scope.update = function(){
  4640. $scope.item.$editing = true;
  4641. };
  4642. // 取消
  4643. $scope.cancel = function(){
  4644. $scope.item.$editing = false;
  4645. $scope.item = angular.copy(staticItem);
  4646. };
  4647. // 提交
  4648. $scope.submit = function(){
  4649. $scope.loading = true;
  4650. $scope.item.quotation.status = 101;//已提交
  4651. Quotation.save({}, $scope.item, function(data){
  4652. $scope.loading = false;
  4653. toaster.pop('success', '成功', '提交成功');
  4654. window.location.hash = '#/sale/quotation/' + data.id;
  4655. }, function(response){
  4656. $scope.loading = false;
  4657. toaster.pop('error', '保存失败', response.data);
  4658. });
  4659. };
  4660. $scope.deleteById = function(id) {
  4661. Quotation.deleteById({id: id}, {}, function(data) {
  4662. window.location.href = "#/sale/quotation/list";
  4663. }, function(response) {
  4664. toaster.pop('error', '提示', response.data);
  4665. })
  4666. }
  4667. }]);
  4668. // 查找客户
  4669. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  4670. BaseService.scrollBackToTop();
  4671. $scope.tableParams = new ngTableParams({
  4672. page : 1,
  4673. count : 20
  4674. }, {
  4675. total : 0,
  4676. counts: [5, 10, 25, 50],
  4677. getData : function($defer, params) {
  4678. $scope.loading = true;
  4679. var pageParams = params.url();
  4680. pageParams.keyword = $scope.keyword;
  4681. Customer.get(BaseService.parseParams(pageParams), function(page){
  4682. $scope.loading = false;
  4683. if(page) {
  4684. params.total(page.totalElement);
  4685. $defer.resolve(page.content);
  4686. }
  4687. $scope.totalCount = page.totalElement;
  4688. }, function(response){
  4689. $scope.loading = false;
  4690. toaster.pop('error', '数据加载失败', response.data);
  4691. });
  4692. }
  4693. });
  4694. $scope.onSearch = function() {
  4695. $scope.tableParams.page(1);
  4696. $scope.tableParams.reload();
  4697. };
  4698. $scope.cancel = function() {
  4699. $modalInstance.dismiss();
  4700. };
  4701. $scope.check = function(cust){
  4702. $modalInstance.close(cust);
  4703. };
  4704. }]);
  4705. // 查找客户物料
  4706. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  4707. BaseService.scrollBackToTop();
  4708. $scope.tableParams = new ngTableParams({
  4709. page : 1,
  4710. count : 20
  4711. }, {
  4712. total : 0,
  4713. counts: [5, 10, 25, 50],
  4714. getData : function($defer, params) {
  4715. $scope.loading = true;
  4716. var pageParams = params.url();
  4717. pageParams.keyword = $scope.keyword;
  4718. pageParams.custUU = custUU;
  4719. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  4720. $scope.loading = false;
  4721. if(page) {
  4722. params.total(page.totalElement);
  4723. $defer.resolve(page.content);
  4724. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4725. }
  4726. }, function(response){
  4727. $scope.loading = false;
  4728. toaster.pop('error', '数据加载失败', response.data);
  4729. });
  4730. }
  4731. });
  4732. // 取消
  4733. $scope.cancel = function() {
  4734. $modalInstance.dismiss();
  4735. };
  4736. // 选择
  4737. $scope.check = function(cust){
  4738. $modalInstance.close(cust);
  4739. };
  4740. // 搜索框回车
  4741. $scope.onSearch = function() {
  4742. $scope.tableParams.page(1);
  4743. $scope.tableParams.reload();
  4744. };
  4745. }]);
  4746. // 查找供应商
  4747. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  4748. BaseService.scrollBackToTop();
  4749. // 搜索框回车
  4750. $scope.onSearch = function(keyword) {
  4751. $scope.keyword = keyword;
  4752. $scope.tableParams.page(1);
  4753. $scope.tableParams.reload();
  4754. };
  4755. $scope.tableParams = new ngTableParams({
  4756. page : 1,
  4757. count : 20
  4758. }, {
  4759. total : 0,
  4760. counts: [10, 25, 50, 100],
  4761. getData : function($defer, params) {
  4762. $scope.loading = true;
  4763. var pageParams = params.url();
  4764. pageParams.keyword = $scope.keyword;
  4765. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  4766. $scope.loading = false;
  4767. if(page) {
  4768. params.total(page.totalElement);
  4769. $defer.resolve(page.content);
  4770. // 添加供应商时,将已存在的选中
  4771. if ($rootScope.tenderVendor) {
  4772. angular.forEach(page.content, function(vendor) {
  4773. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  4774. vendor.checked = false;
  4775. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  4776. vendor.checked = true;
  4777. break;
  4778. }
  4779. }
  4780. });
  4781. }
  4782. }
  4783. $scope.totalCount = page.totalElement;
  4784. }, function(response){
  4785. $scope.loading = false;
  4786. toaster.pop('error', '数据加载失败', response.data);
  4787. });
  4788. }
  4789. });
  4790. $scope.cancel = function() {
  4791. $modalInstance.dismiss();
  4792. };
  4793. $scope.checks = {
  4794. checked : false
  4795. };// 全选框
  4796. $scope.checkAll = function() {
  4797. angular.forEach($scope.tableParams.data, function(vendor) {
  4798. vendor.checked = $scope.checks.checked;
  4799. });
  4800. };
  4801. // 单选
  4802. $scope.checkOne = function(vendor) {
  4803. vendor.checked = true;
  4804. var checked = true;
  4805. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  4806. if (!message.checked) {
  4807. checked = false;
  4808. }
  4809. });
  4810. $scope.checks.checked = checked;
  4811. };
  4812. // 单反选
  4813. $scope.unCheckOne = function(vendor) {
  4814. vendor.checked = false;
  4815. $scope.checks.checked = false;
  4816. };
  4817. $scope.close = function(){
  4818. var vendors = [];
  4819. angular.forEach($scope.tableParams.data, function(vendor) {
  4820. if(vendor.checked) {
  4821. vendors.push(vendor);
  4822. $modalInstance.close(vendors);
  4823. }
  4824. });
  4825. };
  4826. }]);
  4827. // 发货提醒
  4828. 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){
  4829. BaseService.scrollBackToTop();
  4830. $scope.active = 'todo';
  4831. $scope.currency = Symbol.currency;
  4832. $scope.dateZoneText = '不限';
  4833. $scope.condition = {dateZone: -1};
  4834. $scope.changeDateZone = function(zone) {
  4835. $scope.condition.dateZone = zone;
  4836. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4837. $scope.condition.$dateZoneOpen = false;
  4838. getDateCondition(zone, $scope.condition);
  4839. $scope.tableParams.reload();
  4840. };
  4841. $scope.setActive = function(state) {
  4842. if($scope.active != state) {
  4843. $scope.active = state;
  4844. if($scope.tableParams.page() == 1)
  4845. $scope.tableParams.reload();
  4846. else
  4847. $scope.tableParams.page(1);
  4848. }
  4849. };
  4850. var getService = function() {
  4851. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  4852. };
  4853. $scope.tableParams = new ngTableParams({
  4854. page : 1,
  4855. count : 20,
  4856. sorting: {
  4857. 'delivery': 'asc',
  4858. 'orderItemOrderCode': 'asc',
  4859. 'orderItemNumber': 'asc'
  4860. }
  4861. }, {
  4862. total : 0,
  4863. counts: [5, 10, 25, 50],
  4864. getData : function($defer, params) {
  4865. $scope.loading = true;
  4866. var pageParams = params.url();
  4867. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4868. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4869. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4870. $scope.loading = false;
  4871. if(page) {
  4872. params.total(page.totalElement);
  4873. $defer.resolve(page.content);
  4874. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4875. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4876. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4877. }
  4878. }, function(response){
  4879. $scope.loading = false;
  4880. toaster.pop('error', '数据加载失败', response.data);
  4881. });
  4882. }
  4883. });
  4884. $scope.openDatePicker = function($event, item, openParam) {
  4885. $event.preventDefault();
  4886. $event.stopPropagation();
  4887. item[openParam] = !item[openParam];
  4888. };
  4889. //生成随机单号
  4890. $scope.autoCode = function(notice){
  4891. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  4892. };
  4893. //可送货日期
  4894. $scope.sendDate = function(notice) {
  4895. var stock = notice.orderItem.product.ltinstock || 0;
  4896. var de = new Date(notice.delivery);
  4897. if(stock == -1) {
  4898. de.setMonth(de.getMonth() -1);
  4899. de.setDate(25);
  4900. } else if(stock >= 0) {
  4901. de.setDate(de.getDate() - stock -1);
  4902. }
  4903. return de;
  4904. };
  4905. $scope.onReplyClick = function(notice) {
  4906. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  4907. toaster.pop('warning', '警告', '数量填写错误!');
  4908. } else if(!notice.send.code) {
  4909. toaster.pop('warning', '警告', '请填写发货单号!');
  4910. } else {
  4911. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  4912. $scope.loading = true;
  4913. PurcNotice.save({id: notice.id}, send, function(data){
  4914. $scope.loading = false;
  4915. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  4916. $state.go('sale.send_detail', {id: data.id});
  4917. }, function(response){
  4918. $scope.loading = false;
  4919. toaster.pop('error', '发货失败', response.data);
  4920. });
  4921. }
  4922. };
  4923. $scope.checkboxes = {
  4924. checked : false
  4925. };
  4926. // 点击勾选全部的复选框
  4927. $scope.checkAll = function(){
  4928. angular.forEach($scope.tableParams.data, function(item) {
  4929. if(!item.waiting)
  4930. item.$selected = $scope.checkboxes.checked;
  4931. });
  4932. };
  4933. // 点击其中一个明细的复选框
  4934. $scope.checkOne = function(order){
  4935. var result = true;
  4936. angular.forEach($scope.tableParams.data, function(item) {
  4937. if(item.$selected != true){
  4938. result = false;
  4939. return;
  4940. }
  4941. });
  4942. $scope.checkboxes.checked = result;
  4943. };
  4944. $scope.sendByBatch = function(){
  4945. var modalInstance = $modal.open({
  4946. animation: true,
  4947. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  4948. controller: 'SaleNoticeSendByBatchCtrl',
  4949. size: 'lg',
  4950. resolve: {
  4951. selectedNotices: function(){return $scope.tableParams.data;}
  4952. }
  4953. });
  4954. modalInstance.result.then(function(){
  4955. $scope.tableParams.reload();
  4956. }, function(){
  4957. });
  4958. };
  4959. $scope.getSends = function(notice){
  4960. if( ! notice.sends && notice.endQty > 0){
  4961. notice.getSendsing = true;
  4962. notice.getSendsError = false;
  4963. PurcNotice.getSends({id: notice.id}, function(data){
  4964. notice.getSendsing = false;
  4965. notice.getSendsError = false;
  4966. notice.sends = data;
  4967. }, function(response){
  4968. notice.getSendsing = false;
  4969. notice.getSendsError = true;
  4970. });
  4971. }
  4972. };
  4973. // 搜索框回车
  4974. $scope.onSearch = function() {
  4975. $scope.tableParams.page(1);
  4976. $scope.tableParams.reload();
  4977. };
  4978. // 选择查找日期
  4979. $scope.onDateCondition = function(){
  4980. $scope.tableParams.page(1);
  4981. $scope.tableParams.reload();
  4982. };
  4983. //货车功能
  4984. var truck = $rootScope.truck;
  4985. if(!truck) {
  4986. SaleTruck.query({}, function(data){
  4987. $rootScope.truck = data;
  4988. });
  4989. }
  4990. $scope.isInTruck = function(noticeId) {
  4991. return truck.indexOf(noticeId) > -1;
  4992. };
  4993. $scope.addtoTruck = function(notice) {
  4994. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  4995. $rootScope.truck = data;
  4996. });
  4997. };
  4998. $scope.delFromTruck = function(notice) {
  4999. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  5000. $rootScope.truck = data;
  5001. });
  5002. };
  5003. $scope.$watch(function(){
  5004. return $rootScope.truck;
  5005. }, function(data) {
  5006. truck = $rootScope.truck;
  5007. }, true);
  5008. $scope.$watch(function(){
  5009. return $rootScope.dataChanged;
  5010. }, function(data) {
  5011. data && ($scope.tableParams.reload());
  5012. }, true);
  5013. }]);
  5014. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  5015. $scope.notices = angular.copy(selectedNotices);
  5016. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5017. $scope.saleSend = {
  5018. code: '',
  5019. payments: '',
  5020. currency: '',
  5021. custUU: null,
  5022. custUserUU: null,
  5023. remark: '批量发货',
  5024. sendItems: []
  5025. };
  5026. // 计算总数、总额
  5027. $scope.$watch(function(){
  5028. return $scope.notices;
  5029. }, function(data) {
  5030. var q = 0, t = 0;
  5031. if(data) {
  5032. angular.forEach(data,function(d){
  5033. q += (d.thisSendQty || 0);
  5034. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  5035. });
  5036. }
  5037. $scope.totalQty = q;
  5038. $scope.total = t;
  5039. }, true);
  5040. /**
  5041. * 删除一个已选中的送货提醒
  5042. */
  5043. $scope.removeOne = function(index) {
  5044. $scope.notices.splice(index, 1);
  5045. };
  5046. //确认送货
  5047. $scope.sendByBatch = function () {
  5048. $scope.saleSend.sendItems = [];
  5049. if($scope.saleSend.code == '') {//送货单号为空
  5050. toaster.pop('error', '错误', '请输入送货单号');
  5051. return;
  5052. }
  5053. var a = 0;
  5054. var num = 1;
  5055. var valid = true;
  5056. angular.forEach($scope.notices, function(item, key){
  5057. if(item.$selected) {
  5058. if(a == 0) {//第一次
  5059. $scope.saleSend.currency = item.orderItem.order.currency;
  5060. $scope.saleSend.custUU = item.enUU;
  5061. $scope.saleSend.payments = item.orderItem.order.payments;
  5062. a = 1;
  5063. } else {//其他
  5064. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  5065. if($scope.saleSend.custUU != item.enUU) valid = false;
  5066. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  5067. }
  5068. $scope.saleSend.sendItems.push({
  5069. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  5070. });
  5071. }
  5072. });
  5073. if(!valid) {
  5074. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  5075. } else {
  5076. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  5077. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  5078. $modalInstance.close('success');
  5079. $state.go('sale.send_detail', {id: data.id});
  5080. }, function(response){
  5081. toaster.pop('error', '错误', response.data);
  5082. });
  5083. }
  5084. };
  5085. $scope.cancel = function () {
  5086. $modalInstance.dismiss();
  5087. };
  5088. }]);
  5089. /**
  5090. * 发货单
  5091. */
  5092. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol' , 'ReportService', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService){
  5093. BaseService.scrollBackToTop();
  5094. $scope.active = 'all';
  5095. $scope.currency = Symbol.currency;
  5096. $scope.dateZoneText = '不限';
  5097. $scope.condition = {dateZone: -1};
  5098. $scope.changeDateZone = function(zone) {
  5099. $scope.condition.dateZone = zone;
  5100. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5101. $scope.condition.$dateZoneOpen = false;
  5102. getDateCondition(zone, $scope.condition);
  5103. $scope.tableParams.reload();
  5104. };
  5105. $scope.setActive = function(state) {
  5106. if($scope.active != state) {
  5107. $scope.active = state;
  5108. if($scope.tableParams.page() == 1)
  5109. $scope.tableParams.reload();
  5110. else
  5111. $scope.tableParams.page(1);
  5112. }
  5113. };
  5114. var getService = function() {
  5115. return SaleSend;
  5116. };
  5117. $scope.tableParams = new ngTableParams({
  5118. page : 1,
  5119. count : 20,
  5120. sorting: {
  5121. date: 'desc'
  5122. }
  5123. }, {
  5124. total : 0,
  5125. counts: [5, 10, 25, 50],
  5126. getData : function($defer, params) {
  5127. $scope.loading = true;
  5128. var pageParams = params.url();
  5129. pageParams.keyword = $scope.keyword;
  5130. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5131. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5132. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5133. $scope.loading = false;
  5134. if(page) {
  5135. params.total(page.totalElement);
  5136. $defer.resolve(page.content);
  5137. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5138. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5139. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5140. }
  5141. }, function(response){
  5142. $scope.loading = false;
  5143. toaster.pop('error', '数据加载失败', response.data);
  5144. });
  5145. }
  5146. });
  5147. //打印 发货单
  5148. $scope.print = function(send) {
  5149. SaleSend.printCount({id: send.id},{}); //增加打印此次
  5150. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id);
  5151. };
  5152. $scope.openDatePicker = function($event, item, openParam) {
  5153. $event.preventDefault();
  5154. $event.stopPropagation();
  5155. item[openParam] = !item[openParam];
  5156. };
  5157. // 搜索框回车
  5158. $scope.onSearch = function() {
  5159. $scope.tableParams.page(1);
  5160. $scope.tableParams.reload();
  5161. };
  5162. // 选择查找日期
  5163. $scope.onDateCondition = function(){
  5164. $scope.tableParams.page(1);
  5165. $scope.tableParams.reload();
  5166. };
  5167. }]);
  5168. /**
  5169. * 发货单(包括发货条码维护)
  5170. */
  5171. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  5172. var loading = true;
  5173. $scope.checkBarCode = [];
  5174. $scope.checkBoxCode = [];
  5175. var vm = $scope.vm = {};
  5176. $scope.getCheckedItems = {};
  5177. vm.editBar = false;
  5178. vm.showBarCode = [];
  5179. $scope.barCode = function() {
  5180. vm.editBar = !vm.editBar;
  5181. }
  5182. $scope.checkboxes = {
  5183. checked : false
  5184. };
  5185. $scope.checkbars = {
  5186. checked : false
  5187. };
  5188. // 点击勾选barCode全部的复选框
  5189. $scope.checkBarAll = function(){
  5190. angular.forEach($scope.checkBarCode, function(item,key) {
  5191. $scope.checkBarCode[key] = $scope.checkbars.checked;
  5192. });
  5193. };
  5194. //点击barCode单选
  5195. $scope.checkBarOne = function() {
  5196. var result = true;
  5197. angular.forEach($scope.checkBarCode, function(item,key) {
  5198. if(item != true){
  5199. result = false;
  5200. return;
  5201. }
  5202. });
  5203. $scope.checkbars.checked = result;
  5204. }
  5205. // 点击boxCode全部的复选框
  5206. $scope.checkBoxAll = function(){
  5207. angular.forEach($scope.checkBoxCode, function(item,key) {
  5208. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  5209. });
  5210. };
  5211. //点击boxCode单选
  5212. $scope.checkBoxOne = function() {
  5213. var result = true;
  5214. angular.forEach($scope.checkBoxCode, function(item) {
  5215. if(item != true){
  5216. result = false;
  5217. return;
  5218. }
  5219. });
  5220. $scope.checkboxes.checked = result;
  5221. }
  5222. /**
  5223. * 生成条码和箱号
  5224. */
  5225. $scope.generateBarCode = function(item) {
  5226. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  5227. $scope.getCheckedItems = [];
  5228. var warningdata = '';
  5229. angular.forEach($scope.checkBarCode, function(item,key) {
  5230. $scope.getCheckedItem = {};
  5231. if(item == true ){
  5232. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  5233. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  5234. $scope.getCheckedItems.push($scope.getCheckedItem);
  5235. //判断是否生成过条码
  5236. if($scope.order.sendItems[key].barSendNotify.length > 0){
  5237. warningdata += $scope.order.sendItems[key].number+","
  5238. }
  5239. }
  5240. });
  5241. if($scope.getCheckedItems.length == 0){
  5242. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  5243. return;
  5244. }
  5245. if(warningdata != ''){
  5246. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  5247. return ;
  5248. }
  5249. }
  5250. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  5251. toaster.pop('success', '提示','生成成功!');
  5252. loadData();
  5253. },function(response){
  5254. $scope.loading = false;
  5255. toaster.pop('error', '生成失败', response.data);
  5256. });
  5257. }
  5258. /**
  5259. * 打印条码和箱号
  5260. */
  5261. $scope.printCode = function(type) {
  5262. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  5263. //勾选需要打印的行
  5264. $scope.getCheckedItems = [];
  5265. var warningdata = ''
  5266. angular.forEach($scope.checkBarCode, function(item,key) {
  5267. $scope.getCheckedItem = {};
  5268. if(item == true ){
  5269. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  5270. $scope.getCheckedItems.push($scope.getCheckedItem);
  5271. //判断是否生成过条码
  5272. if($scope.order.sendItems[key].barSendNotify.length > 0){
  5273. warningdata += $scope.order.sendItems[key].number+","
  5274. }
  5275. }
  5276. });
  5277. if($scope.getCheckedItems.length == 0){
  5278. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  5279. return;
  5280. }
  5281. if(warningdata == ''){
  5282. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  5283. return;
  5284. }
  5285. //选择打印模板
  5286. var modalInstance = $modal.open({
  5287. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  5288. controller: 'BarPrintModalCtrl',
  5289. resolve: {
  5290. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  5291. }
  5292. });
  5293. modalInstance.result.then(function(s){
  5294. if(s) {
  5295. //获取打印数据
  5296. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  5297. if(s.type == 'print'){//判断选择是打印还是打印预览
  5298. lodopPrint(data.message,LODOP,type);
  5299. }else if(s.type == 'printPreview'){
  5300. lodopPrintPreview(data.message,LODOP,type);
  5301. }
  5302. },function(response){
  5303. toaster.pop('error', '获取打印数据失败', response.data);
  5304. });
  5305. }
  5306. });
  5307. };
  5308. //打印单个条码
  5309. $scope.printSingleCode = function(id){
  5310. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  5311. //选择打印模板
  5312. var modalInstance = $modal.open({
  5313. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  5314. controller: 'BarPrintModalCtrl',
  5315. resolve: {
  5316. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  5317. }
  5318. });
  5319. modalInstance.result.then(function(s){
  5320. if(s) {
  5321. //获取打印数据
  5322. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  5323. if(s.type == 'print'){//判断选择是打印还是打印预览
  5324. lodopSPrint(data.message,LODOP);
  5325. }else if(s.type == 'printPreview'){
  5326. lodopSPrintPreview(data.message,LODOP);
  5327. }
  5328. },function(response){
  5329. toaster.pop('error', '获取打印数据失败', response.data);
  5330. });
  5331. }
  5332. });
  5333. }
  5334. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  5335. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5336. if (selectOrNot != -1) {
  5337. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5338. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5339. var strs = pagesize.split("*"); //字符分割
  5340. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5341. angular.forEach(printStore, function(data, index) {
  5342. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5343. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5344. if (data['LP_VALUETYPE'] == 'barcode') {
  5345. 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']);
  5346. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5347. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5348. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5349. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5350. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5351. } else if (data['LP_VALUETYPE'] == 'text') {
  5352. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5353. }
  5354. });
  5355. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5356. LODOP.PRINT();
  5357. }
  5358. };
  5359. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  5360. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5361. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5362. var strs = pagesize.split("*"); //字符分割
  5363. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5364. angular.forEach(printStore,function(data,index){
  5365. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5366. if(data['LP_VALUETYPE'] == 'barcode'){
  5367. 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']);
  5368. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5369. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5370. }else if(data['LP_VALUETYPE'] == 'text'){
  5371. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5372. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5373. }
  5374. });
  5375. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5376. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5377. LODOP.PREVIEW();//打印预览
  5378. };
  5379. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  5380. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5381. if (selectOrNot != -1) {
  5382. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5383. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  5384. var strs= new Array(); //定义一数组
  5385. strs = pagesize.split("*"); //字符分割
  5386. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5387. var ids = new Array();
  5388. angular.forEach(printStore, function(value,key) {
  5389. //LODOP.NewPage();
  5390. angular.forEach(value['data'], function(record,key) {
  5391. angular.forEach(record['store'], function(data, index) {
  5392. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5393. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5394. if (data['LP_VALUETYPE'] == 'barcode') {
  5395. 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']);
  5396. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5397. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5398. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5399. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5400. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5401. } else if (data['LP_VALUETYPE'] == 'text') {
  5402. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5403. }
  5404. });
  5405. });
  5406. var o = new Object();
  5407. o['id'] = record['si_id']
  5408. ids.push(o);
  5409. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5410. LODOP.PRINT();
  5411. });
  5412. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5413. if(type == 'Bar'){
  5414. //更新打印状态
  5415. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  5416. }
  5417. }
  5418. };
  5419. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  5420. var ids = new Array();
  5421. angular.forEach(printData, function(record, index){
  5422. angular.forEach(record['data'],function(value,index){
  5423. LODOP.NewPage();
  5424. angular.forEach(value['store'],function(data,index){
  5425. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5426. if(data['LP_VALUETYPE'] == 'barcode'){
  5427. 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']);
  5428. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5429. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5430. }else if(data['LP_VALUETYPE'] == 'text'){
  5431. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5432. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5433. }
  5434. });
  5435. });
  5436. var o = new Object();
  5437. o['id'] = record['si_id']
  5438. ids.push(o);
  5439. });
  5440. var pagesize = printData[0]['pagesize'];//获取标签的大小
  5441. var strs= new Array(); //定义一数组
  5442. strs = pagesize.split("*"); //字符分割
  5443. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5444. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5445. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5446. var times = LODOP.PREVIEW();//打印预览
  5447. if(times > 0){//点击了打印预览内的打印按钮
  5448. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5449. if(type == 'Bar'){
  5450. //更新打印状态
  5451. SaleSend.updatePrintStatus({},ids,function(data){
  5452. loadData();
  5453. },function(res){});
  5454. }
  5455. }
  5456. };
  5457. /**
  5458. * 查看条码按钮
  5459. */
  5460. $scope.showBarCode = function(number) {
  5461. $scope.keys = number;
  5462. for(var i=0;i<vm.showBarCode.length;i++){
  5463. if(i!=number){
  5464. vm.showBarCode[i] = false;
  5465. }
  5466. }
  5467. vm.showBarCode[number] = !vm.showBarCode[number];
  5468. $scope.barcodes = [];
  5469. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  5470. var getPage = function(page, size){
  5471. if($scope.barcodes) {
  5472. var result = {};
  5473. result.totalCount = $scope.barcodes.length;
  5474. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  5475. if($scope.barcodes.length % size == 0) {
  5476. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  5477. }else {
  5478. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  5479. }
  5480. result.first = page == 1;
  5481. result.last = page == result.totalPage;
  5482. result.page = page;
  5483. result.next = page - 0 + 1;
  5484. result.pre = page - 1;
  5485. return result;
  5486. }
  5487. }
  5488. $scope.barData = getPage(1,5);
  5489. $scope.first = function (){
  5490. $scope.barData = getPage($scope.barData.pre,5);
  5491. }
  5492. $scope.last = function (){
  5493. $scope.barData = getPage($scope.barData.next,5);
  5494. }
  5495. };
  5496. /**
  5497. * 更新外箱号
  5498. */
  5499. $scope.updateOutBox = function(item,number) {
  5500. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  5501. }else {
  5502. if(item.outBoxQty > 0) {
  5503. if(!(item.outBoxQty % item.packageQty)) {
  5504. SaleSend.update({id:item.id},item,function(){
  5505. toaster.pop('success', '提示','保存成功!');
  5506. loadData();
  5507. }, function(response){
  5508. $scope.loading = false;
  5509. toaster.pop('error', '回复失败', response.data);
  5510. })
  5511. }else {
  5512. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  5513. }
  5514. }else {
  5515. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5516. }
  5517. }
  5518. loadData();
  5519. };
  5520. /**
  5521. * 更新最小包数
  5522. */
  5523. $scope.updatePackage = function(item, number) {
  5524. if(item.packageQty == $scope.oldpackageQty[number]) {
  5525. }else {
  5526. if(item.orderItem.product.minPack != 0) {
  5527. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5528. if(!(item.packageQty % item.orderItem.product.minPack)) {
  5529. SaleSend.update({id:item.id},item,function(){
  5530. toaster.pop('success', '提示','保存成功!');
  5531. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5532. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5533. }
  5534. loadData();
  5535. }, function(response){
  5536. $scope.loading = false;
  5537. toaster.pop('error', '回复失败', response.data);
  5538. })
  5539. }else {
  5540. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  5541. }
  5542. }else {
  5543. toaster.pop('warning', '提示', '请填写有效的数量!');
  5544. }
  5545. }else {
  5546. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5547. SaleSend.update({id:item.id},item,function(){
  5548. toaster.pop('success', '提示','保存成功!');
  5549. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5550. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5551. }
  5552. loadData();
  5553. }, function(response){
  5554. $scope.loading = false;
  5555. toaster.pop('error', '回复失败', response.data);
  5556. })
  5557. }else {
  5558. toaster.pop('warning', '提示', '请填写有效的数量!');
  5559. }
  5560. }
  5561. }
  5562. loadData();
  5563. };
  5564. var loadData = function() {
  5565. SaleSend.get({id: $stateParams.id}, function(data){
  5566. $scope.order = data;
  5567. var orderCount = $scope.order.sendItems.length;
  5568. $scope.oldpackageQty = [];
  5569. $scope.oldoutBoxQty = [];
  5570. var sum = 0;
  5571. vm.oldpackageQty = [];
  5572. angular.forEach(data.sendItems, function(value, key){
  5573. //给showBarCode数组赋初值
  5574. if (vm.showBarCode.length < orderCount){
  5575. vm.showBarCode.push(false);
  5576. }
  5577. if($scope.checkBarCode.length < orderCount) {
  5578. $scope.checkBarCode.push(false);
  5579. }
  5580. if($scope.checkBoxCode.length < orderCount) {
  5581. $scope.checkBoxCode.push(false);
  5582. }
  5583. //给个初值
  5584. if(!value.packageQty) {
  5585. value.packageQty = value.orderItem.product.minPack;
  5586. }
  5587. $scope.oldpackageQty.push(value.packageQty);
  5588. if(value.outBoxQty) {
  5589. $scope.oldoutBoxQty.push(value.outBoxQty);
  5590. }
  5591. sum += value.price * value.qty;
  5592. });
  5593. data.total = sum;
  5594. $scope.loading = false;
  5595. }, function(response){
  5596. loading = false;
  5597. toaster.pop('error', '获取数据失败', response.data);
  5598. });
  5599. };
  5600. loadData();
  5601. }]);
  5602. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  5603. $scope.typeItem = typeItem;
  5604. $scope.template = [];
  5605. $scope.choose = {};
  5606. //获取打印模板
  5607. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  5608. if(data.message){
  5609. $scope.template = data.message;
  5610. $scope.choose.tp_id = $scope.template[0].id;
  5611. }
  5612. },function(res){
  5613. toaster.pop('error', '获取模板错误', res.data);
  5614. });
  5615. $scope.print = function(){
  5616. $scope.choose.type = 'print';
  5617. $modalInstance.close($scope.choose);
  5618. };
  5619. $scope.printPreview = function(){
  5620. $scope.choose.type = 'printPreview';
  5621. $modalInstance.close($scope.choose);
  5622. }
  5623. $scope.cancel = function(){
  5624. $modalInstance.close();
  5625. }
  5626. }]);
  5627. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', function($scope, $stateParams, PurcSample, toaster, $modal, BaseService){
  5628. BaseService.scrollBackToTop();
  5629. var loading = true;
  5630. var loadData = function() {
  5631. PurcSample.get({id: $stateParams.id}, function(data){
  5632. $scope.sample = data;
  5633. if(!$scope.sample.sends){
  5634. $scope.sample.getSendInfo = '加载中...';
  5635. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  5636. if(sendData) {
  5637. $scope.sample.getSendInfo = null;
  5638. $scope.sample.sends = sendData;
  5639. } else {
  5640. $scope.sample.getSendInfo = '无送样信息';
  5641. $scope.sample.sends = '无送样信息';
  5642. }
  5643. }, function(response){
  5644. $scope.sample.getSendInfo = '加载失败!';
  5645. });
  5646. }
  5647. $scope.loading = false;
  5648. }, function(response){
  5649. loading = false;
  5650. toaster.pop('error', '获取数据失败', response.data);
  5651. });
  5652. };
  5653. loadData();
  5654. $scope.openSend = function(index, sample) {
  5655. var modalInstance = $modal.open({
  5656. animation: true,
  5657. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5658. controller: 'SampleSendCtrl',
  5659. resolve: {
  5660. sampleItem: function(){return sample;}
  5661. }
  5662. });
  5663. modalInstance.result.then(function(){
  5664. toaster.pop('info', '提示', '送样成功');
  5665. $scope.tableParams.reload();
  5666. }, function(){
  5667. });
  5668. };
  5669. }]);
  5670. /**
  5671. * 客户打样申请
  5672. */
  5673. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', '$rootScope', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol, $rootScope){
  5674. BaseService.scrollBackToTop();
  5675. if($rootScope.active) {
  5676. $scope.active = $rootScope.active;
  5677. $rootScope.active = null;
  5678. } else {
  5679. $scope.active = 'todo';
  5680. }
  5681. $scope.agreedText = '全部';
  5682. $scope.dateZoneText = '一个月内';
  5683. $scope.condition = {dateZone: 1};
  5684. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5685. $scope.changeAgreed = function(agreed) {
  5686. $scope.condition.agreed = agreed;
  5687. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5688. $scope.condition.$agreedOpen = false;
  5689. };
  5690. $scope.changeDateZone = function(zone) {
  5691. $scope.condition.dateZone = zone;
  5692. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5693. $scope.condition.$dateZoneOpen = false;
  5694. };
  5695. $scope.setActive = function(state) {
  5696. if($scope.active != state) {
  5697. $scope.active = state;
  5698. if($scope.tableParams.page() == 1)
  5699. $scope.tableParams.reload();
  5700. else
  5701. $scope.tableParams.page(1);
  5702. }
  5703. };
  5704. var getService = function() {
  5705. return PurcSample;
  5706. };
  5707. $scope.tableParams = new ngTableParams({
  5708. page : 1,
  5709. count : 20,
  5710. sorting: {
  5711. proofingDate: 'desc'
  5712. }
  5713. }, {
  5714. total : 0,
  5715. counts: [5, 10, 25, 50],
  5716. getData : function($defer, params) {
  5717. $scope.loading = true;
  5718. var pageParams = params.url();
  5719. pageParams.keyword = $scope.keyword;
  5720. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5721. $scope.loading = false;
  5722. if(page) {
  5723. params.total(page.totalElement);
  5724. $defer.resolve(page.content);
  5725. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5726. // angular.forEach(page.content, function(proofing) { // 为了支持多次送样,读取列表的时候获取送样信息作为比较依据
  5727. // if( !proofing.send) {
  5728. // proofing.getSendInfo = '加载中...';
  5729. // PurcSample.getSend({id: proofing.id}, function(data){
  5730. // if(data) {
  5731. // proofing.getSendInfo = null;
  5732. // proofing.send = data;
  5733. // } else {
  5734. // proofing.getSendInfo = '无送样信息';
  5735. // proofing.send = '无送样信息';
  5736. // }
  5737. // }, function(response){
  5738. // proofing.getSendInfo = '加载失败!';
  5739. // });
  5740. // }
  5741. // });
  5742. }
  5743. }, function(response){
  5744. $scope.loading = false;
  5745. toaster.pop('error', '数据加载失败', response.data);
  5746. });
  5747. }
  5748. });
  5749. $scope.openDatePicker = function($event, item, openParam) {
  5750. $event.preventDefault();
  5751. $event.stopPropagation();
  5752. item[openParam] = !item[openParam];
  5753. };
  5754. $scope.openSend = function(index, sample) {
  5755. var modalInstance = $modal.open({
  5756. animation: true,
  5757. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5758. controller: 'SampleSendCtrl',
  5759. resolve: {
  5760. sampleItem: function(){return sample;}
  5761. }
  5762. });
  5763. modalInstance.result.then(function(){
  5764. toaster.pop('info', '提示', '送样成功');
  5765. $scope.tableParams.reload();
  5766. }, function(){
  5767. });
  5768. };
  5769. //打印 样品采购单
  5770. $scope.print = function(sample) {
  5771. PurcSample.printCount({id: sample.id},{});//增加打印此次
  5772. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  5773. };
  5774. $scope.getSend = function(proofing){
  5775. if( !proofing.sends) {
  5776. proofing.getSendInfo = '加载中...';
  5777. PurcSample.getSend({id: proofing.id}, function(data){
  5778. if(data) {
  5779. proofing.getSendInfo = null;
  5780. proofing.sends = data;
  5781. } else {
  5782. proofing.getSendInfo = '无送样信息';
  5783. proofing.sends = '无送样信息';
  5784. }
  5785. }, function(response){
  5786. proofing.getSendInfo = '加载失败!';
  5787. });
  5788. }
  5789. };
  5790. // 搜索框回车
  5791. $scope.onSearch = function() {
  5792. $scope.tableParams.page(1);
  5793. $scope.tableParams.reload();
  5794. };
  5795. }]);
  5796. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  5797. if( !sampleItem.sends) {
  5798. PurcSample.getSend({id: sampleItem.id}, function(data){
  5799. if(data) {
  5800. sampleItem.sends = data; // 获取送样信息
  5801. angular.forEach(data, function(send) {
  5802. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  5803. });
  5804. }
  5805. }, function(response){
  5806. });
  5807. }
  5808. $scope.sampleItem = sampleItem;
  5809. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  5810. //确认送样
  5811. $scope.ok = function (form) {
  5812. $scope.loading = true;
  5813. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  5814. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  5815. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  5816. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  5817. $upload.upload({
  5818. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  5819. method: 'POST',
  5820. file: file,
  5821. data: {
  5822. json: $scope.sampleItem.sampleSend
  5823. }
  5824. }).success(function(data){
  5825. $scope.loading = false;
  5826. $modalInstance.close('success');
  5827. }).error(function(data){
  5828. $scope.loading = false;
  5829. toaster.pop('danger', '错误', data);
  5830. });
  5831. };
  5832. $scope.cancel = function () {
  5833. $modalInstance.dismiss(sampleItem);
  5834. };
  5835. }]);
  5836. /**
  5837. * 客户认定单
  5838. */
  5839. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  5840. BaseService.scrollBackToTop();
  5841. $scope.active = 'all';
  5842. $scope.agreedText = '全部';
  5843. $scope.dateZoneText = '一个月内';
  5844. $scope.condition = {dateZone: 1};
  5845. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5846. $scope.changeDateZone = function(zone) {
  5847. $scope.condition.dateZone = zone;
  5848. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5849. $scope.condition.$dateZoneOpen = false;
  5850. getDateCondition(zone, $scope.condition);
  5851. $scope.tableParams.reload();
  5852. };
  5853. $scope.setActive = function(state) {
  5854. if($scope.active != state) {
  5855. $scope.active = state;
  5856. if($scope.tableParams.page() == 1)
  5857. $scope.tableParams.reload();
  5858. else
  5859. $scope.tableParams.page(1);
  5860. }
  5861. };
  5862. var getService = function() {
  5863. return PurcApproval;
  5864. };
  5865. $scope.tableParams = new ngTableParams({
  5866. page : 1,
  5867. count : 20,
  5868. sorting: {
  5869. inDate: 'desc'
  5870. }
  5871. }, {
  5872. total : 0,
  5873. counts: [5, 10, 25, 50],
  5874. getData : function($defer, params) {
  5875. $scope.loading = true;
  5876. var pageParams = params.url();
  5877. pageParams.keyword = $scope.keyword;
  5878. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5879. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5880. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5881. $scope.loading = false;
  5882. if(page) {
  5883. params.total(page.totalElement);
  5884. $defer.resolve(page.content);
  5885. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5886. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5887. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5888. }
  5889. }, function(response){
  5890. $scope.loading = false;
  5891. toaster.pop('error', '数据加载失败', response.data);
  5892. });
  5893. }
  5894. });
  5895. $scope.openDatePicker = function($event, item, openParam) {
  5896. $event.preventDefault();
  5897. $event.stopPropagation();
  5898. item[openParam] = !item[openParam];
  5899. };
  5900. $scope.parseDate = function(dateStr) {
  5901. if(dateStr)
  5902. return Date.parse(dateStr, 'yyyy-MM-dd');
  5903. return new Date();
  5904. };
  5905. // 搜索框回车
  5906. $scope.onSearch = function() {
  5907. $scope.tableParams.page(1);
  5908. $scope.tableParams.reload();
  5909. };
  5910. // 选择查找日期
  5911. $scope.onDateCondition = function(){
  5912. $scope.tableParams.page(1);
  5913. $scope.tableParams.reload();
  5914. };
  5915. }]);
  5916. /**
  5917. * 客户采购预测
  5918. */
  5919. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  5920. BaseService.scrollBackToTop();
  5921. $scope.active = 'all';
  5922. $scope.agreedText = '全部';
  5923. $scope.dateZoneText = '一个月内';
  5924. $scope.condition = {dateZone: 1};
  5925. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5926. $scope.changeAgreed = function(agreed) {
  5927. $scope.condition.agreed = agreed;
  5928. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5929. $scope.condition.$agreedOpen = false;
  5930. };
  5931. $scope.changeDateZone = function(zone) {
  5932. $scope.condition.dateZone = zone;
  5933. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5934. $scope.condition.$dateZoneOpen = false;
  5935. };
  5936. $scope.setActive = function(state) {
  5937. if($scope.active != state) {
  5938. $scope.active = state;
  5939. if($scope.tableParams.page() == 1)
  5940. $scope.tableParams.reload();
  5941. else
  5942. $scope.tableParams.page(1);
  5943. }
  5944. };
  5945. var getService = function() {
  5946. return PurcForecast;
  5947. };
  5948. $scope.tableParams = new ngTableParams({
  5949. page : 1,
  5950. count : 20,
  5951. sorting: {
  5952. orderDate: 'desc'
  5953. }
  5954. }, {
  5955. total : 0,
  5956. counts: [5, 10, 25, 50],
  5957. getData : function($defer, params) {
  5958. $scope.loading = true;
  5959. var pageParams = params.url();
  5960. pageParams.keyword = $scope.keyword;
  5961. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5962. $scope.loading = false;
  5963. if(page) {
  5964. params.total(page.totalElement);
  5965. $defer.resolve(page.content);
  5966. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5967. }
  5968. }, function(response){
  5969. $scope.loading = false;
  5970. toaster.pop('error', '数据加载失败', response.data);
  5971. });
  5972. }
  5973. });
  5974. $scope.openDatePicker = function($event, item, openParam) {
  5975. $event.preventDefault();
  5976. $event.stopPropagation();
  5977. item[openParam] = !item[openParam];
  5978. };
  5979. // 搜索框回车
  5980. $scope.onSearch = function() {
  5981. $scope.tableParams.page(1);
  5982. $scope.tableParams.reload();
  5983. };
  5984. }]);
  5985. /**
  5986. * 客户采购验收
  5987. */
  5988. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  5989. BaseService.scrollBackToTop();
  5990. $scope.active = 'all';
  5991. $scope.dateZoneText = '不限';
  5992. $scope.deliveryZoneText = '不限';
  5993. $scope.condition = {dateZone: -1, deliveryZone: -1};
  5994. $scope.changeDateZone = function(zone) {
  5995. $scope.condition.dateZone = zone;
  5996. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5997. $scope.condition.$dateZoneOpen = false;
  5998. getDateCondition(zone, $scope.condition);
  5999. $scope.tableParams.reload();
  6000. };
  6001. $scope.changeDeliveryZone = function(zone) {
  6002. $scope.condition.deliveryZoneText = zone;
  6003. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  6004. $scope.condition.$delievryZoneOpen = false;
  6005. getDelveryCondition(zone, $scope.condition);
  6006. $scope.tableParams.reload();
  6007. };
  6008. $scope.setActive = function(state) {
  6009. if($scope.active != state) {
  6010. $scope.active = state;
  6011. if($scope.tableParams.page() == 1)
  6012. $scope.tableParams.reload();
  6013. else
  6014. $scope.tableParams.page(1);
  6015. }
  6016. };
  6017. var getService = function() {
  6018. return PurcAccept;
  6019. };
  6020. $scope.tableParams = new ngTableParams({
  6021. page : 1,
  6022. count : 20,
  6023. sorting: {
  6024. date: 'desc'
  6025. }
  6026. }, {
  6027. total : 0,
  6028. counts: [5, 10, 25, 50],
  6029. getData : function($defer, params) {
  6030. $scope.loading = true;
  6031. var pageParams = params.url();
  6032. pageParams.searchFilter = { // 筛选条件
  6033. keyword: $scope.keyword,
  6034. fromDate: getDateTime($scope.condition.dateFrom),
  6035. endDate: getDateTime($scope.condition.dateTo)
  6036. };
  6037. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6038. $scope.loading = false;
  6039. if(page) {
  6040. params.total(page.totalElement);
  6041. $defer.resolve(page.content);
  6042. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6043. }
  6044. }, function(response){
  6045. $scope.loading = false;
  6046. toaster.pop('error', '数据加载失败', response.data);
  6047. });
  6048. }
  6049. });
  6050. $scope.openDatePicker = function($event, item, openParam) {
  6051. $event.preventDefault();
  6052. $event.stopPropagation();
  6053. item[openParam] = !item[openParam];
  6054. };
  6055. $scope.parseDate = function(dateStr) {
  6056. if(dateStr)
  6057. return Date.parse(dateStr, 'yyyy-MM-dd');
  6058. return new Date();
  6059. };
  6060. // 选择查找日期
  6061. $scope.onDateCondition = function(){
  6062. $scope.tableParams.page(1);
  6063. $scope.tableParams.reload();
  6064. };
  6065. // 搜索框回车
  6066. $scope.onSearch = function() {
  6067. $scope.tableParams.page(1);
  6068. $scope.tableParams.reload();
  6069. };
  6070. }]);
  6071. /**
  6072. * 客户采购验收详情
  6073. */
  6074. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', function($scope, PurcAccept, toaster, BaseService, $stateParams){
  6075. BaseService.scrollBackToTop();
  6076. if($stateParams.id) {
  6077. PurcAccept.getDetail({id: $stateParams.id}, {}, function(data) {
  6078. $scope.accept= data;
  6079. if($scope.accept.acceptItems != null) {
  6080. var sum = 0;
  6081. angular.forEach($scope.accept.acceptItems, function(item) {
  6082. sum += item.orderPrice * item.qty;
  6083. });
  6084. $scope.totalPrice = sum;
  6085. }
  6086. }, function(response) {
  6087. toaster.pop('error', '提示', response.data);
  6088. });
  6089. }
  6090. }]);
  6091. /**
  6092. * 客户采购验退
  6093. */
  6094. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  6095. BaseService.scrollBackToTop();
  6096. $scope.active = 'all';
  6097. $scope.agreedText = '全部';
  6098. $scope.dateZoneText = '一个月内';
  6099. $scope.condition = {dateZone: 1};
  6100. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6101. $scope.changeAgreed = function(agreed) {
  6102. $scope.condition.agreed = agreed;
  6103. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6104. $scope.condition.$agreedOpen = false;
  6105. };
  6106. $scope.changeDateZone = function(zone) {
  6107. $scope.condition.dateZone = zone;
  6108. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6109. $scope.condition.$dateZoneOpen = false;
  6110. };
  6111. $scope.setActive = function(state) {
  6112. if($scope.active != state) {
  6113. $scope.active = state;
  6114. if($scope.tableParams.page() == 1)
  6115. $scope.tableParams.reload();
  6116. else
  6117. $scope.tableParams.page(1);
  6118. }
  6119. };
  6120. var getService = function() {
  6121. return PurcReturn;
  6122. };
  6123. $scope.tableParams = new ngTableParams({
  6124. page : 1,
  6125. count : 20,
  6126. sorting: {
  6127. date: 'desc'
  6128. }
  6129. }, {
  6130. total : 0,
  6131. counts: [5, 10, 25, 50],
  6132. getData : function($defer, params) {
  6133. $scope.loading = true;
  6134. var pageParams = params.url();
  6135. pageParams.keyword = $scope.keyword;
  6136. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6137. $scope.loading = false;
  6138. if(page) {
  6139. params.total(page.totalElement);
  6140. $defer.resolve(page.content);
  6141. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6142. angular.forEach(page.content, function(data) {
  6143. if (!data.returnItems[0].orderItem) {
  6144. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  6145. data.enName = enterprise.enName;
  6146. });
  6147. }
  6148. });
  6149. }
  6150. }, function(response){
  6151. $scope.loading = false;
  6152. toaster.pop('error', '数据加载失败', response.data);
  6153. });
  6154. }
  6155. });
  6156. $scope.openDatePicker = function($event, item, openParam) {
  6157. $event.preventDefault();
  6158. $event.stopPropagation();
  6159. item[openParam] = !item[openParam];
  6160. };
  6161. // 搜索框回车
  6162. $scope.onSearch = function() {
  6163. $scope.tableParams.page(1);
  6164. $scope.tableParams.reload();
  6165. };
  6166. }]);
  6167. /**
  6168. * 客户采购验退详情
  6169. */
  6170. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', function($scope, PurcReturn, toaster, BaseService, $stateParams){
  6171. BaseService.scrollBackToTop();
  6172. if($stateParams.id != null) {
  6173. PurcReturn.getDetail({id: $stateParams.id}, {}, function(data) {
  6174. $scope.returns = data;
  6175. if($scope.returns.returnItems != null) {
  6176. var sum = 0;
  6177. angular.forEach($scope.returns.returnItems, function(item) {
  6178. sum += item.orderPrice * item.qty;
  6179. });
  6180. $scope.totalPrice = sum;
  6181. }
  6182. }, function(response) {
  6183. toaster.pop('error', '提示', response.data);
  6184. });
  6185. }
  6186. }]);
  6187. /**
  6188. * 客户不良品入库
  6189. */
  6190. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  6191. BaseService.scrollBackToTop();
  6192. $scope.active = 'all';
  6193. $scope.agreedText = '全部';
  6194. $scope.dateZoneText = '一个月内';
  6195. $scope.condition = {dateZone: 1};
  6196. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6197. $scope.changeAgreed = function(agreed) {
  6198. $scope.condition.agreed = agreed;
  6199. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6200. $scope.condition.$agreedOpen = false;
  6201. };
  6202. $scope.changeDateZone = function(zone) {
  6203. $scope.condition.dateZone = zone;
  6204. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6205. $scope.condition.$dateZoneOpen = false;
  6206. };
  6207. $scope.setActive = function(state) {
  6208. if($scope.active != state) {
  6209. $scope.active = state;
  6210. if($scope.tableParams.page() == 1)
  6211. $scope.tableParams.reload();
  6212. else
  6213. $scope.tableParams.page(1);
  6214. }
  6215. };
  6216. var getService = function() {
  6217. return PurcBadIn;
  6218. };
  6219. $scope.tableParams = new ngTableParams({
  6220. page : 1,
  6221. count : 20,
  6222. sorting: {
  6223. date: 'desc'
  6224. }
  6225. }, {
  6226. total : 0,
  6227. counts: [5, 10, 25, 50],
  6228. getData : function($defer, params) {
  6229. $scope.loading = true;
  6230. var pageParams = params.url();
  6231. pageParams.keyword = $scope.keyword;
  6232. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6233. $scope.loading = false;
  6234. if(page) {
  6235. params.total(page.totalElement);
  6236. $defer.resolve(page.content);
  6237. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6238. }
  6239. }, function(response){
  6240. $scope.loading = false;
  6241. toaster.pop('error', '数据加载失败', response.data);
  6242. });
  6243. }
  6244. });
  6245. $scope.openDatePicker = function($event, item, openParam) {
  6246. $event.preventDefault();
  6247. $event.stopPropagation();
  6248. item[openParam] = !item[openParam];
  6249. };
  6250. // 搜索框回车
  6251. $scope.onSearch = function() {
  6252. $scope.tableParams.page(1);
  6253. $scope.tableParams.reload();
  6254. };
  6255. }]);
  6256. /**
  6257. * 客户不良品出库
  6258. */
  6259. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  6260. BaseService.scrollBackToTop();
  6261. $scope.active = 'all';
  6262. $scope.agreedText = '全部';
  6263. $scope.dateZoneText = '一个月内';
  6264. $scope.condition = {dateZone: 1};
  6265. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6266. $scope.changeAgreed = function(agreed) {
  6267. $scope.condition.agreed = agreed;
  6268. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6269. $scope.condition.$agreedOpen = false;
  6270. };
  6271. $scope.changeDateZone = function(zone) {
  6272. $scope.condition.dateZone = zone;
  6273. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6274. $scope.condition.$dateZoneOpen = false;
  6275. };
  6276. $scope.setActive = function(state) {
  6277. if($scope.active != state) {
  6278. $scope.active = state;
  6279. if($scope.tableParams.page() == 1)
  6280. $scope.tableParams.reload();
  6281. else
  6282. $scope.tableParams.page(1);
  6283. }
  6284. };
  6285. var getService = function() {
  6286. return PurcBadOut;
  6287. };
  6288. $scope.tableParams = new ngTableParams({
  6289. page : 1,
  6290. count : 20,
  6291. sorting: {
  6292. date: 'desc'
  6293. }
  6294. }, {
  6295. total : 0,
  6296. counts: [5, 10, 25, 50],
  6297. getData : function($defer, params) {
  6298. $scope.loading = true;
  6299. var pageParams = params.url();
  6300. pageParams.keyword = $scope.keyword;
  6301. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6302. $scope.loading = false;
  6303. if(page) {
  6304. params.total(page.totalElement);
  6305. $defer.resolve(page.content);
  6306. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6307. }
  6308. }, function(response){
  6309. $scope.loading = false;
  6310. toaster.pop('error', '数据加载失败', response.data);
  6311. });
  6312. }
  6313. });
  6314. $scope.openDatePicker = function($event, item, openParam) {
  6315. $event.preventDefault();
  6316. $event.stopPropagation();
  6317. item[openParam] = !item[openParam];
  6318. };
  6319. // 搜索框回车
  6320. $scope.onSearch = function() {
  6321. $scope.tableParams.page(1);
  6322. $scope.tableParams.reload();
  6323. };
  6324. }]);
  6325. /**
  6326. * 客户MRB
  6327. */
  6328. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  6329. BaseService.scrollBackToTop();
  6330. $scope.active = 'all';
  6331. $scope.agreedText = '全部';
  6332. $scope.dateZoneText = '一个月内';
  6333. $scope.condition = {dateZone: 1};
  6334. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6335. $scope.changeAgreed = function(agreed) {
  6336. $scope.condition.agreed = agreed;
  6337. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6338. $scope.condition.$agreedOpen = false;
  6339. };
  6340. $scope.changeDateZone = function(zone) {
  6341. $scope.condition.dateZone = zone;
  6342. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6343. $scope.condition.$dateZoneOpen = false;
  6344. };
  6345. $scope.setActive = function(state) {
  6346. if($scope.active != state) {
  6347. $scope.active = state;
  6348. if($scope.tableParams.page() == 1)
  6349. $scope.tableParams.reload();
  6350. else
  6351. $scope.tableParams.page(1);
  6352. }
  6353. };
  6354. var getService = function() {
  6355. return PurcMRB;
  6356. };
  6357. $scope.tableParams = new ngTableParams({
  6358. page : 1,
  6359. count : 20,
  6360. sorting: {
  6361. date: 'desc'
  6362. }
  6363. }, {
  6364. total : 0,
  6365. counts: [5, 10, 25, 50],
  6366. getData : function($defer, params) {
  6367. $scope.loading = true;
  6368. var pageParams = params.url();
  6369. pageParams.keyword = $scope.keyword;
  6370. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6371. $scope.loading = false;
  6372. if(page) {
  6373. params.total(page.totalElement);
  6374. $defer.resolve(page.content);
  6375. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6376. }
  6377. }, function(response){
  6378. $scope.loading = false;
  6379. toaster.pop('error', '数据加载失败', response.data);
  6380. });
  6381. }
  6382. });
  6383. $scope.openDatePicker = function($event, item, openParam) {
  6384. $event.preventDefault();
  6385. $event.stopPropagation();
  6386. item[openParam] = !item[openParam];
  6387. };
  6388. // 搜索框回车
  6389. $scope.onSearch = function() {
  6390. $scope.tableParams.page(1);
  6391. $scope.tableParams.reload();
  6392. };
  6393. }]);
  6394. /**
  6395. * 客户应付发票
  6396. */
  6397. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  6398. BaseService.scrollBackToTop();
  6399. $scope.active = 'all';
  6400. $scope.dateZoneText = '不限';
  6401. $scope.condition = {dateZone: -1};
  6402. $scope.changeDateZone = function(zone) {
  6403. $scope.condition.dateZone = zone;
  6404. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6405. $scope.condition.$dateZoneOpen = false;
  6406. getDateCondition(zone, $scope.condition);
  6407. $scope.tableParams.reload();
  6408. };
  6409. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6410. $scope.setActive = function(state) {
  6411. if($scope.active != state) {
  6412. $scope.active = state;
  6413. if($scope.tableParams.page() == 1)
  6414. $scope.tableParams.reload();
  6415. else
  6416. $scope.tableParams.page(1);
  6417. }
  6418. };
  6419. var getService = function() {
  6420. return FaApBill;
  6421. };
  6422. $scope.tableParams = new ngTableParams({
  6423. page : 1,
  6424. count : 20,
  6425. sorting: {
  6426. date: 'desc'
  6427. }
  6428. }, {
  6429. total : 0,
  6430. counts: [5, 10, 25, 50],
  6431. getData : function($defer, params) {
  6432. $scope.loading = true;
  6433. var pageParams = params.url();
  6434. pageParams.searchFilter = { // 筛选条件
  6435. keyword: $scope.keyword,
  6436. fromDate: getDateTime($scope.condition.dateFrom),
  6437. endDate: getDateTime($scope.condition.dateTo)
  6438. };
  6439. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6440. $scope.loading = false;
  6441. if(page) {
  6442. params.total(page.totalElement);
  6443. $defer.resolve(page.content);
  6444. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  6445. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6446. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6447. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  6448. }
  6449. }, function(response){
  6450. $scope.loading = false;
  6451. toaster.pop('error', '数据加载失败', response.data);
  6452. });
  6453. }
  6454. });
  6455. $scope.openDatePicker = function($event, item, openParam) {
  6456. $event.preventDefault();
  6457. $event.stopPropagation();
  6458. item[openParam] = !item[openParam];
  6459. };
  6460. $scope.parseDate = function(dateStr) {
  6461. if(dateStr)
  6462. return Date.parse(dateStr, 'yyyy-MM-dd');
  6463. return new Date();
  6464. };
  6465. // 搜索框回车
  6466. $scope.onSearch = function() {
  6467. $scope.tableParams.page(1);
  6468. $scope.tableParams.reload();
  6469. };
  6470. // 选择查找日期
  6471. $scope.onDateCondition = function(){
  6472. $scope.tableParams.page(1);
  6473. $scope.tableParams.reload();
  6474. };
  6475. }]);
  6476. /**
  6477. * 客户应付发票详情
  6478. */
  6479. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', function($scope, $filter, FaApBill, toaster, $stateParams, BaseService){
  6480. BaseService.scrollBackToTop();
  6481. var loadData = function() {
  6482. FaApBill.get({id: $stateParams.id}, function(data){
  6483. $scope.bill = data;
  6484. console.log(data);
  6485. $scope.loading = false;
  6486. });
  6487. };
  6488. loadData(); // 初始获取单据数据
  6489. }]);
  6490. /**
  6491. * 应付对账单
  6492. */
  6493. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  6494. BaseService.scrollBackToTop();
  6495. $scope.active = 'all';
  6496. $scope.dateZoneText = '不限';
  6497. $scope.condition = {dateZone: -1};
  6498. $scope.changeDateZone = function(zone) {
  6499. $scope.condition.dateZone = zone;
  6500. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6501. $scope.condition.$dateZoneOpen = false;
  6502. getDateCondition(zone, $scope.condition);
  6503. $scope.tableParams.reload();
  6504. };
  6505. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6506. $scope.setActive = function(state) {
  6507. if($scope.active != state) {
  6508. $scope.active = state;
  6509. if($scope.tableParams.page() == 1)
  6510. $scope.tableParams.reload();
  6511. else
  6512. $scope.tableParams.page(1);
  6513. }
  6514. };
  6515. var getService = function() {
  6516. return FaArCheck;
  6517. };
  6518. $scope.tableParams = new ngTableParams({
  6519. page : 1,
  6520. count : 20,
  6521. sorting: {
  6522. date: 'desc'
  6523. }
  6524. }, {
  6525. total : 0,
  6526. counts: [5, 10, 25, 50],
  6527. getData : function($defer, params) {
  6528. $scope.loading = true;
  6529. var pageParams = params.url();
  6530. pageParams.keyword = $scope.keyword;
  6531. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6532. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6533. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6534. $scope.loading = false;
  6535. if(page) {
  6536. params.total(page.totalElement);
  6537. $defer.resolve(page.content);
  6538. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6539. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6540. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6541. }
  6542. }, function(response){
  6543. $scope.loading = false;
  6544. toaster.pop('error', '数据加载失败', response.data);
  6545. });
  6546. }
  6547. });
  6548. $scope.openDatePicker = function($event, item, openParam) {
  6549. $event.preventDefault();
  6550. $event.stopPropagation();
  6551. item[openParam] = !item[openParam];
  6552. };
  6553. // 计算单据的商品总数
  6554. $scope.getTotalProd = function(check) {
  6555. var total = 0;
  6556. if(check.items) {
  6557. angular.forEach(check.items, function(value) {
  6558. total += value.qty;
  6559. });
  6560. }
  6561. return total;
  6562. };
  6563. // 搜索框回车
  6564. $scope.onSearch = function() {
  6565. $scope.tableParams.page(1);
  6566. $scope.tableParams.reload();
  6567. };
  6568. // 选择查找日期
  6569. $scope.onDateCondition = function(){
  6570. $scope.tableParams.page(1);
  6571. $scope.tableParams.reload();
  6572. };
  6573. }]);
  6574. // 应付对账单详情页
  6575. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  6576. BaseService.scrollBackToTop();
  6577. var loadData = function() {
  6578. FaArCheck.get({id: $stateParams.id}, function(data){
  6579. $scope.order = data;
  6580. $scope.loading = false;
  6581. });
  6582. };
  6583. loadData(); // 初始获取单据数据
  6584. $scope.onReplyClick = function(item, isAgreed) {
  6585. if(isAgreed) {// 同意确认
  6586. FaArCheck.agree({itemId: item.id}, {}, function(data){
  6587. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  6588. }, function(response){
  6589. toaster.pop('danger', '确认失败', response.data);
  6590. });
  6591. } else {// 不同意回复
  6592. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  6593. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  6594. }, function(response) {
  6595. toaster.pop('danger', '确认失败', response.data);
  6596. });
  6597. }
  6598. };
  6599. // 获取明细的回复记录
  6600. $scope.getReplies = function(item) {
  6601. if(!item.replies) {
  6602. FaArCheck.getReplies({itemId: item.id}, function(data) {
  6603. item.replies = data;
  6604. }, function(response) {
  6605. toaster.pop('danger', '获取对账记录失败', response.data);
  6606. });
  6607. }
  6608. };
  6609. }]);
  6610. //应收对账单列表
  6611. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  6612. BaseService.scrollBackToTop();
  6613. $scope.dateZoneText = '不限';
  6614. $scope.condition = {dateZone: -1};
  6615. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6616. $scope.active = 'todo';
  6617. //打印 对账单
  6618. $scope.print = function(check) {
  6619. FaApCheck.printCount({id: check.id},{});//增加打印此次
  6620. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  6621. };
  6622. //状态
  6623. $scope.setActive = function (state){
  6624. if($scope.active != state) {
  6625. $scope.active = state;
  6626. if($scope.tableParams.page() == 1)
  6627. $scope.tableParams.reload();
  6628. else
  6629. $scope.tableParams.page(1);
  6630. }
  6631. };
  6632. $scope.changeDateZone = function(zone) {
  6633. $scope.condition.dateZone = zone;
  6634. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6635. $scope.condition.$dateZoneOpen = false;
  6636. getDateCondition(zone, $scope.condition);
  6637. $scope.tableParams.reload();
  6638. };
  6639. //获取应收对账单全部
  6640. $scope.tableParams = new ngTableParams({
  6641. page : 1,
  6642. count : 20,
  6643. sorting: {
  6644. recordDate: 'desc'
  6645. }
  6646. }, {
  6647. total : 0,
  6648. counts: [5, 10, 25, 50],
  6649. getData : function($defer, params) {
  6650. $scope.loading = true;
  6651. var pageParams = params.url();
  6652. pageParams.searchFilter = { // 筛选条件
  6653. keyword: $scope.keyword,
  6654. fromDate: getDateTime($scope.condition.dateFrom),
  6655. endDate: getDateTime($scope.condition.dateTo)
  6656. };
  6657. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  6658. $scope.loading = false;
  6659. if(page) {
  6660. params.total(page.totalElement);
  6661. $scope.data = $defer.resolve(page.content);
  6662. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  6663. }
  6664. }, function(response){
  6665. $scope.loading = false;
  6666. toaster.pop('error', '数据加载失败', response.data);
  6667. });
  6668. }
  6669. });
  6670. $scope.openDatePicker = function($event, item, openParam) {
  6671. $event.preventDefault();
  6672. $event.stopPropagation();
  6673. item[openParam] = !item[openParam];
  6674. };
  6675. // 计算单据的商品总数
  6676. $scope.getTotalProd = function(check) {
  6677. var total = 0;
  6678. if(check.items) {
  6679. angular.forEach(check.items, function(value) {
  6680. total += value.checkQty;
  6681. });
  6682. }
  6683. return total;
  6684. };
  6685. // 搜索框回车
  6686. $scope.onSearch = function() {
  6687. $scope.tableParams.page(1);
  6688. $scope.tableParams.reload();
  6689. };
  6690. // 选择查找日期
  6691. $scope.onDateCondition = function(){
  6692. $scope.tableParams.page(1);
  6693. $scope.tableParams.reload();
  6694. };
  6695. }]);
  6696. //应收对账单详情
  6697. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  6698. BaseService.scrollBackToTop();
  6699. $scope.haveSelected = true;
  6700. $scope.data = {};
  6701. //控制提交和删除按钮的显示
  6702. $scope.ifShow = true;
  6703. var loadData = function(){
  6704. FaApCheck.get({id:$stateParams.id},function(data){
  6705. $scope.data = data;
  6706. if($scope.data.status){
  6707. }else{
  6708. $scope.ifShow = true;
  6709. }
  6710. })
  6711. };
  6712. if($stateParams.id){
  6713. loadData();
  6714. }
  6715. $scope.haveSource = false;
  6716. //提交应收对账单
  6717. $scope.submitApCheck = function(){
  6718. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  6719. if(data.result) {
  6720. toaster.pop('success', '提示', '提交成功');
  6721. $scope.haveSelected = false;
  6722. window.location.href = '#/fa/apCheck';
  6723. }else {
  6724. $scope.haveSource = true;
  6725. loadData();
  6726. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  6727. $scope.haveSelected = true;
  6728. }
  6729. },function(){
  6730. $scope.loading = false;
  6731. toaster.pop('error', '提示', '更新已转数失败');
  6732. });
  6733. }
  6734. //删除应收对账单的同时更新来源表已转数
  6735. var updateYCheckQty = function(){
  6736. var sourceInfos = [];
  6737. angular.forEach($scope.data.items, function(item){
  6738. $scope.sourceInfo = {
  6739. sourceId: '',
  6740. sourceTable: '',
  6741. newYCheckQty: ''
  6742. };
  6743. $scope.sourceInfo.sourceId = item.sourceId;
  6744. $scope.sourceInfo.sourceTable = item.sourceTable;
  6745. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  6746. sourceInfos.push($scope.sourceInfo);
  6747. });
  6748. FaApCheck.update({}, sourceInfos, function(){
  6749. },function(response){
  6750. $scope.loading = false;
  6751. toaster.pop('error', '更新已转数失败', response.data);
  6752. });
  6753. }
  6754. //删除应收对账单
  6755. $scope.deleteApCheck = function(){
  6756. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  6757. updateYCheckQty();
  6758. toaster.pop('success','提示','删除成功');
  6759. },function(){
  6760. toaster.pop('error','提示','删除失败');
  6761. });
  6762. $scope.haveSelected = false;
  6763. }
  6764. //作废应收对账单
  6765. $scope.cancelApCheck = function(check) {
  6766. FaApCheck.cancel({id:check.id},function(data){
  6767. $scope.checkResult = false;
  6768. if(data.result) {
  6769. $scope.checkResult = true;
  6770. toaster.pop('success', '提示', '作废成功');
  6771. $scope.tableParams.reload();
  6772. }else{
  6773. toaster.pop('error', '提示', '作废失败');
  6774. }
  6775. },function(){
  6776. $scope.loading = false;
  6777. toaster.pop('error', '提示', '作废失败');
  6778. });
  6779. }
  6780. }]);
  6781. //未对账单据列表
  6782. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  6783. $scope.data = [];// 列表数据
  6784. $scope.condition = {
  6785. $fromOpened: false
  6786. }
  6787. $scope.openDatePicker = function($event, item, openParam) {
  6788. $event.preventDefault();
  6789. $event.stopPropagation();
  6790. item[openParam] = !item[openParam];
  6791. }
  6792. //查找客户
  6793. $scope.searchCust = function(suuorname) {
  6794. var modalInstance = $modal.open({
  6795. animation: true,
  6796. templateUrl: 'static/tpl/index/fa/custInfo.html',
  6797. controller: 'SearchCustInfoCtrl',
  6798. resolve: {
  6799. suuorname: function() {
  6800. return suuorname;
  6801. }
  6802. }
  6803. });
  6804. modalInstance.result.then(function(suuorname){
  6805. $scope.suuorname = suuorname;
  6806. });
  6807. }
  6808. // 点击筛选根据条件选择数据
  6809. $scope.suuorname = '';
  6810. // 默认本月
  6811. $scope.sdateTo = new Date();
  6812. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  6813. $scope.vuuorname = '';
  6814. $scope.factory = '';
  6815. $scope.prodTitle = '';
  6816. $scope.prodSpec = '';
  6817. $scope.condition.uuorname = '';
  6818. $scope.condition.dateFrom = '';
  6819. $scope.condition.dateTo = '';
  6820. $scope.condition.venduuorname = '';
  6821. $scope.condition.factory = '';
  6822. $scope.condition.prodTitle = '';
  6823. $scope.condition.prodSpec = '';
  6824. $scope.searchOrder = function(check) {
  6825. $scope.data = [];
  6826. $scope.checkboxes.checked = false;
  6827. $scope.totalMoney = 0;
  6828. $scope.condition.uuorname = $scope.suuorname;
  6829. $scope.condition.factory = $scope.factory
  6830. $scope.condition.prodTitle = $scope.prodTitle;
  6831. $scope.condition.prodSpec = $scope.prodSpec;
  6832. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  6833. $scope.thisdatato = ($scope.sdateTo || 0);
  6834. if($scope.thisdatato != 0) {
  6835. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  6836. } else {
  6837. $scope.condition.dateTo = ($scope.sdateTo || 0);
  6838. }
  6839. $scope.condition.venduuorname = $scope.vuuorname;
  6840. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  6841. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6842. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6843. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  6844. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  6845. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  6846. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  6847. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  6848. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6849. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6850. if(!$scope.suuorname) {
  6851. toaster.pop('warning','提示', '请先选择客户');
  6852. document.getElementById('suuorname').focus();//光标默认在客户
  6853. } else {
  6854. $scope.loading = true;
  6855. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  6856. if(data.length > 0) {
  6857. angular.forEach(data, function(item) {
  6858. item.$selected = true;
  6859. });
  6860. $scope.data = data;
  6861. $scope.checkboxes.checked = true;
  6862. $scope.getTotalMoney();
  6863. } else {
  6864. toaster.pop('info', '提示', '当前没有需要对账记录');
  6865. }
  6866. $scope.loading = false;
  6867. }, function(response) {
  6868. $scope.loading = false;
  6869. toaster.pop('error', '提示', response.data);
  6870. });
  6871. }
  6872. }
  6873. }
  6874. /**
  6875. * 点击勾选框,选中要转应收对账单的订单
  6876. * */
  6877. $scope.totalMoney = 0;
  6878. $scope.checkboxes = {
  6879. checked : false
  6880. };
  6881. // 点击勾选全部的复选框
  6882. $scope.checkAll = function(){
  6883. $scope.totalMoney = 0;
  6884. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  6885. var uuorname = $scope.suuorname;
  6886. var venduuorname = $scope.venduuorname;
  6887. var dateFrom = $scope.condition.dateFrom;
  6888. var dateTo = $scope.condition.dateTo;
  6889. var prodTitle = $scope.condition.prodTitle;
  6890. var prodSpec = $scope.condition.prodSpec;
  6891. var factory = $scope.condition.factory;
  6892. angular.forEach($scope.filteredData, function(item) {
  6893. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  6894. item.$selected = $scope.checkboxes.checked;
  6895. }
  6896. });
  6897. $scope.getTotalMoney();
  6898. };
  6899. //获取已选单据总金额
  6900. var total = true;
  6901. $scope.getTotalMoney = function(){
  6902. $scope.totalMoney = 0;
  6903. angular.forEach($scope.data, function(check) {
  6904. if(check.$selected){
  6905. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6906. }else{
  6907. $scope.totalMoney += 0;
  6908. }
  6909. });
  6910. }
  6911. // 点击其中一个明细的复选框
  6912. $scope.checkOne = function(check){
  6913. var result = true;
  6914. angular.forEach($scope.data, function(item) {
  6915. if(item.$selected != true){
  6916. result = false;
  6917. return;
  6918. }
  6919. });
  6920. $scope.checkboxes.checked = result;
  6921. };
  6922. $scope.haveSelected = false;
  6923. //生成应收对账单
  6924. $scope.createApCheck = function(){
  6925. //保存应收对账单主记录字段
  6926. $scope.apCheck = {
  6927. custUu: '',
  6928. custName: '',
  6929. enUu: '',
  6930. apDate: '',
  6931. beginDate: '',
  6932. endDate: '',
  6933. checkStatus: '未对账',
  6934. checkAmount: 0,
  6935. currency: '',
  6936. rate: '',
  6937. items: []
  6938. };
  6939. //保存来源单据相关信息
  6940. var sourceInfos = [];
  6941. //所允许的本次对账最大最小数量
  6942. $scope.data.maxThisCheckQty = 0;
  6943. $scope.data.minThisCheckQty = 0;
  6944. $scope.sameCust = true;
  6945. $scope.validQty = true;
  6946. $scope.loading = true;
  6947. angular.forEach($scope.data, function(check) {
  6948. //保存应收对账单明细行数据
  6949. $scope.item = {
  6950. inoutno: '',
  6951. inoutnodetno: '',
  6952. orderCode: '',
  6953. orderClass: '',
  6954. orderDetno: '',
  6955. price: '',
  6956. checkQty: '',
  6957. amount: '',
  6958. sourceId:'',
  6959. sourceTable:'',
  6960. oldYCheckQty:'',
  6961. status: 0,
  6962. receiveCode:'',
  6963. receiveName:'',
  6964. prodCode:'',
  6965. prodTitle:'',
  6966. prodSpec:'',
  6967. taxrate: '',
  6968. sendcode: '',
  6969. whname: '',
  6970. };
  6971. //应收对账单明细行来源表信息
  6972. $scope.sourceInfo = {
  6973. sourceId: '',
  6974. sourceTable: '',
  6975. newYCheckQty: ''
  6976. };
  6977. //此次对账后新的已转数
  6978. $scope.newYCheckQty = 0;
  6979. if(check.$selected == true) {
  6980. $scope.apCheck.custName = check.custName;
  6981. $scope.apCheck.enUu = check.enUu;
  6982. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6983. $scope.apCheck.apDate = check.piDate;
  6984. $scope.apCheck.rate = check.rate;
  6985. //必须是同一家客户才能生成对账单,否则提示错误
  6986. if($scope.apCheck.custUu == ''){
  6987. $scope.apCheck.custUu = check.custUu;
  6988. }else if($scope.apCheck.custUu !== check.custUu){
  6989. $scope.sameCust = false;
  6990. $scope.loading = false;
  6991. toaster.pop('error', '请选择同一家客户');
  6992. }
  6993. //必须是相同币别才能生成对账单,否则提示错误
  6994. if($scope.apCheck.currency == ''){
  6995. $scope.apCheck.currency = check.currency;
  6996. }else if($scope.apCheck.currency !== check.currency){
  6997. $scope.sameCust = false;
  6998. $scope.loading = false;
  6999. toaster.pop('error', '请选择同一种币别');
  7000. }
  7001. //本次对账数量必须小于总对账数量
  7002. if(check.qty > 0){
  7003. $scope.data.maxThisCheckQty = check.qty;
  7004. $scope.data.minThisCheckQty = 0;
  7005. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  7006. $scope.validQty = false;
  7007. $scope.loading = false;
  7008. toaster.pop('error','本次对账数量,填写有误!');
  7009. }
  7010. }else if(check.qty < 0){
  7011. $scope.data.maxThisCheckQty = 0;
  7012. $scope.data.minThisCheckQty = check.qty;
  7013. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  7014. $scope.validQty = false;
  7015. $scope.loading = false;
  7016. toaster.pop('error','本次对账数量,填写有误!');
  7017. }
  7018. }
  7019. //获取最小时间作为对账区间的起始时间
  7020. if($scope.apCheck.beginDate == ''){
  7021. $scope.apCheck.beginDate = check.piDate;
  7022. }else{
  7023. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  7024. }
  7025. //获取最大时间作为对账区间的截止时间
  7026. if($scope.apCheck.endDate == ''){
  7027. $scope.apCheck.endDate = check.piDate;
  7028. }else{
  7029. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  7030. }
  7031. //应收对账单明细行数据
  7032. $scope.item.orderCode = check.orderCode;
  7033. $scope.item.orderClass = check.piClass;
  7034. $scope.item.orderDetno = check.orderDetno;
  7035. $scope.item.price = check.orderPrice;
  7036. $scope.item.checkQty = check.thisCheckQty;
  7037. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  7038. $scope.item.sourceId = check.sourceId;
  7039. $scope.item.sourceTable = check.sourceTable;
  7040. $scope.item.oldYCheckQty = check.yCheckQty;
  7041. $scope.item.prodCode = check.prodCode;
  7042. $scope.item.prodTitle = check.prodTitle;
  7043. $scope.item.prodSpec = check.prodSpec;
  7044. $scope.item.inoutno = check.inOutNo;
  7045. $scope.item.inoutnodetno = check.detno;
  7046. $scope.item.taxrate = check.taxrate;
  7047. $scope.item.receiveCode = check.receiveCode;
  7048. $scope.item.receiveName = check.receiveName;
  7049. $scope.item.sendcode = check.sendcode;
  7050. $scope.item.whname = check.whname;
  7051. //来源表相关信息
  7052. $scope.sourceInfo.sourceId = check.sourceId;
  7053. $scope.sourceInfo.sourceTable = check.sourceTable;
  7054. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  7055. sourceInfos.push($scope.sourceInfo);
  7056. $scope.apCheck.items.push($scope.item);
  7057. $scope.haveSelected = true;
  7058. }
  7059. });
  7060. //保存生成的应收对账单
  7061. $scope.saveApCheck = function(){
  7062. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  7063. $scope.loading = false;
  7064. toaster.pop('success', '成功', '生成应收对账成功');
  7065. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  7066. }, function(response){
  7067. toaster.pop('error', '生成对账单失败', response.data);
  7068. })
  7069. };
  7070. //如果是同一家客户,生成对账单的同时,关闭模态框
  7071. if($scope.sameCust && $scope.validQty) {
  7072. $scope.saveApCheck();
  7073. }
  7074. }
  7075. }]);
  7076. //货款调账
  7077. app.controller('PurchaseAdjustListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', 'ApbillAdjustment', function($scope, FaApCheck, toaster, $state, $filter, $modal, ApbillAdjustment){
  7078. $scope.data = [];// 列表数据
  7079. $scope.condition = {
  7080. $fromOpened: false
  7081. }
  7082. $scope.openDatePicker = function($event, item, openParam) {
  7083. $event.preventDefault();
  7084. $event.stopPropagation();
  7085. item[openParam] = !item[openParam];
  7086. }
  7087. //查找客户
  7088. $scope.searchCust = function(suuorname) {
  7089. var modalInstance = $modal.open({
  7090. animation: true,
  7091. templateUrl: 'static/tpl/index/fa/custInfo.html',
  7092. controller: 'SearchCustInfoCtrl',
  7093. resolve: {
  7094. suuorname: function() {
  7095. return suuorname;
  7096. }
  7097. }
  7098. });
  7099. modalInstance.result.then(function(suuorname){
  7100. $scope.suuorname = suuorname;
  7101. });
  7102. }
  7103. // 点击筛选根据条件选择数据
  7104. $scope.suuorname = '';
  7105. // 默认本月
  7106. $scope.sdateTo = new Date();
  7107. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  7108. $scope.vuuorname = '';
  7109. $scope.factory = '';
  7110. $scope.prodTitle = '';
  7111. $scope.prodSpec = '';
  7112. $scope.condition.uuorname = '';
  7113. $scope.condition.dateFrom = '';
  7114. $scope.condition.dateTo = '';
  7115. $scope.condition.venduuorname = '';
  7116. $scope.condition.factory = '';
  7117. $scope.condition.prodTitle = '';
  7118. $scope.condition.prodSpec = '';
  7119. $scope.searchOrder = function(check) {
  7120. $scope.data = [];
  7121. $scope.checkboxes.checked = false;
  7122. $scope.totalMoney = 0;
  7123. $scope.condition.uuorname = $scope.suuorname;
  7124. $scope.condition.factory = $scope.factory
  7125. $scope.condition.prodTitle = $scope.prodTitle;
  7126. $scope.condition.prodSpec = $scope.prodSpec;
  7127. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  7128. $scope.thisdatato = ($scope.sdateTo || 0);
  7129. if($scope.thisdatato != 0) {
  7130. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  7131. } else {
  7132. $scope.condition.dateTo = ($scope.sdateTo || 0);
  7133. }
  7134. $scope.condition.venduuorname = $scope.vuuorname;
  7135. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  7136. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7137. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7138. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  7139. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  7140. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  7141. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  7142. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  7143. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7144. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7145. if(!$scope.suuorname) {
  7146. toaster.pop('warning','提示', '请先选择客户');
  7147. document.getElementById('suuorname').focus();//光标默认在客户
  7148. } else {
  7149. $scope.loading = true;
  7150. ApbillAdjustment.adjustList({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  7151. if(data.length > 0) {
  7152. angular.forEach(data, function(item) {
  7153. item.$selected = true;
  7154. });
  7155. $scope.data = data;
  7156. $scope.checkboxes.checked = true;
  7157. $scope.getTotalMoney();
  7158. } else {
  7159. toaster.pop('info', '提示', '当前没有需要对账记录');
  7160. }
  7161. $scope.loading = false;
  7162. }, function(response) {
  7163. $scope.loading = false;
  7164. toaster.pop('error', '提示', response.data);
  7165. });
  7166. }
  7167. }
  7168. }
  7169. /**
  7170. * 点击勾选框,选中要转应收对账单的订单
  7171. * */
  7172. $scope.totalMoney = 0;
  7173. $scope.checkboxes = {
  7174. checked : false
  7175. };
  7176. // 点击勾选全部的复选框
  7177. $scope.checkAll = function(){
  7178. $scope.totalMoney = 0;
  7179. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  7180. var uuorname = $scope.suuorname;
  7181. var venduuorname = $scope.venduuorname;
  7182. var dateFrom = $scope.condition.dateFrom;
  7183. var dateTo = $scope.condition.dateTo;
  7184. var prodTitle = $scope.condition.prodTitle;
  7185. var prodSpec = $scope.condition.prodSpec;
  7186. var factory = $scope.condition.factory;
  7187. angular.forEach($scope.filteredData, function(item) {
  7188. if((item.orderdate >= dateFrom || dateFrom == '') && (item.orderdate < dateTo || dateTo == '')){
  7189. item.$selected = $scope.checkboxes.checked;
  7190. }
  7191. });
  7192. $scope.getTotalMoney();
  7193. };
  7194. //获取已选单据总金额
  7195. var total = true;
  7196. $scope.getTotalMoney = function(){
  7197. $scope.totalMoney = 0;
  7198. angular.forEach($scope.data, function(check) {
  7199. if(check.$selected){
  7200. $scope.totalMoney += (check.thischeckqty || 0)*(check.orderprice || 0);
  7201. }else{
  7202. $scope.totalMoney += 0;
  7203. }
  7204. });
  7205. }
  7206. // 点击其中一个明细的复选框
  7207. $scope.checkOne = function(check){
  7208. var result = true;
  7209. angular.forEach($scope.data, function(item) {
  7210. if(item.$selected != true){
  7211. result = false;
  7212. return;
  7213. }
  7214. });
  7215. $scope.checkboxes.checked = result;
  7216. };
  7217. $scope.haveSelected = false;
  7218. //生成应收对账单
  7219. $scope.createApCheck = function(){
  7220. //保存应收对账单主记录字段
  7221. $scope.apCheck = {
  7222. custUu: '',
  7223. custName: '',
  7224. enUu: '',
  7225. apDate: '',
  7226. beginDate: '',
  7227. endDate: '',
  7228. checkStatus: '未对账',
  7229. checkAmount: 0,
  7230. currency: '',
  7231. rate: '',
  7232. items: []
  7233. };
  7234. //保存来源单据相关信息
  7235. var sourceInfos = [];
  7236. //所允许的本次对账最大最小数量
  7237. $scope.data.maxThisCheckQty = 0;
  7238. $scope.data.minThisCheckQty = 0;
  7239. $scope.sameCust = true;
  7240. $scope.validQty = true;
  7241. $scope.loading = true;
  7242. angular.forEach($scope.data, function(check) {
  7243. //保存应收对账单明细行数据
  7244. $scope.item = {
  7245. inoutno: '',
  7246. inoutnodetno: '',
  7247. orderCode: '',
  7248. orderClass: '',
  7249. orderDetno: '',
  7250. price: '',
  7251. checkQty: '',
  7252. amount: '',
  7253. sourceId:'',
  7254. sourceTable:'',
  7255. oldYCheckQty:'',
  7256. status: 0,
  7257. receiveCode:'',
  7258. receiveName:'',
  7259. prodCode:'',
  7260. prodTitle:'',
  7261. prodSpec:'',
  7262. taxrate: '',
  7263. sendcode: '',
  7264. whname: '',
  7265. };
  7266. //应收对账单明细行来源表信息
  7267. $scope.sourceInfo = {
  7268. sourceId: '',
  7269. sourceTable: '',
  7270. newYCheckQty: ''
  7271. };
  7272. //此次对账后新的已转数
  7273. $scope.newYCheckQty = 0;
  7274. if(check.$selected == true) {
  7275. $scope.apCheck.custName = check.custname;
  7276. $scope.apCheck.enUu = check.enuu;
  7277. $scope.apCheck.checkAmount += (check.thischeckqty || 0)*(check.orderprice || 0);
  7278. $scope.apCheck.apDate = check.date;
  7279. $scope.apCheck.rate = check.rate;
  7280. //必须是同一家客户才能生成对账单,否则提示错误
  7281. if($scope.apCheck.custUu == ''){
  7282. $scope.apCheck.custUu = check.custuu;
  7283. }else if($scope.apCheck.custUu !== check.custuu){
  7284. $scope.sameCust = false;
  7285. $scope.loading = false;
  7286. toaster.pop('error', '请选择同一家客户');
  7287. }
  7288. //必须是相同币别才能生成对账单,否则提示错误
  7289. if($scope.apCheck.currency == ''){
  7290. $scope.apCheck.currency = check.currency;
  7291. }else if($scope.apCheck.currency !== check.currency){
  7292. $scope.sameCust = false;
  7293. $scope.loading = false;
  7294. toaster.pop('error', '请选择同一种币别');
  7295. }
  7296. //本次对账数量必须小于总对账数量
  7297. if(check.qty > 0){
  7298. $scope.data.maxThisCheckQty = check.qty;
  7299. $scope.data.minThisCheckQty = 0;
  7300. if(check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0){
  7301. $scope.validQty = false;
  7302. $scope.loading = false;
  7303. toaster.pop('error','本次对账数量,填写有误!');
  7304. }
  7305. }else if(check.qty < 0){
  7306. $scope.data.maxThisCheckQty = 0;
  7307. $scope.data.minThisCheckQty = check.qty;
  7308. if(((-check.qty)-(-check.ycheckQty) < (-check.thischeckQty)) || check.thischeckqty > 0 || check.thischeckqty == 0){
  7309. $scope.validQty = false;
  7310. $scope.loading = false;
  7311. toaster.pop('error','本次对账数量,填写有误!');
  7312. }
  7313. }
  7314. //获取最小时间作为对账区间的起始时间
  7315. if($scope.apCheck.beginDate == ''){
  7316. $scope.apCheck.beginDate = check.date;
  7317. }else{
  7318. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.orderdate : $scope.apCheck.beginDate;
  7319. }
  7320. //获取最大时间作为对账区间的截止时间
  7321. if($scope.apCheck.endDate == ''){
  7322. $scope.apCheck.endDate = check.date;
  7323. }else{
  7324. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.orderdate : $scope.apCheck.endDate;
  7325. }
  7326. //应收对账单明细行数据
  7327. $scope.item.orderCode = check.ordercode;
  7328. $scope.item.orderClass = check.piClass;
  7329. $scope.item.orderDetno = check.orderdetno;
  7330. $scope.item.price = check.orderprice;
  7331. $scope.item.checkQty = check.thischeckqty;
  7332. $scope.item.amount = (check.thischeckqty || 0)*(check.orderprice || 0);
  7333. $scope.item.sourceId = check.id;
  7334. $scope.item.sourceTable = 'purc$apbilladjustment';
  7335. $scope.item.orderClass = '货款调账';
  7336. $scope.item.oldYCheckQty = check.ycheckqty;
  7337. $scope.item.prodCode = check.prodcode;
  7338. $scope.item.prodTitle = check.prodtitle;
  7339. $scope.item.prodSpec = check.prodspec;
  7340. $scope.item.inoutno = check.inoutno;
  7341. $scope.item.inoutnodetno = check.detno;
  7342. $scope.item.taxrate = check.taxrate;
  7343. $scope.item.receiveCode = check.receivecode;
  7344. $scope.item.receiveName = check.receivename;
  7345. $scope.item.sendcode = check.sendcode;
  7346. $scope.item.whname = check.whname;
  7347. //来源表相关信息
  7348. $scope.sourceInfo.sourceId = check.id;
  7349. $scope.sourceInfo.sourceTable = 'purc$apbilladjustment';
  7350. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  7351. sourceInfos.push($scope.sourceInfo);
  7352. $scope.apCheck.items.push($scope.item);
  7353. $scope.haveSelected = true;
  7354. }
  7355. });
  7356. //保存生成的应收对账单
  7357. $scope.saveApCheck = function(){
  7358. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  7359. $scope.loading = false;
  7360. toaster.pop('success', '成功', '生成应收对账成功');
  7361. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  7362. }, function(response){
  7363. toaster.pop('error', '生成对账单失败', response.data);
  7364. })
  7365. };
  7366. //如果是同一家客户,生成对账单的同时,关闭模态框
  7367. if($scope.sameCust && $scope.validQty) {
  7368. $scope.saveApCheck();
  7369. }
  7370. }
  7371. }]);
  7372. // 企业信息设置
  7373. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder){
  7374. BaseService.scrollBackToTop();
  7375. $scope.loading = true;
  7376. AccountEnterprise.get({}, function(data){
  7377. $scope.loading = false;
  7378. $scope.enterprise = data;
  7379. // 获取付款企业信息
  7380. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7381. $scope.pays = data;
  7382. }, function(response) {
  7383. toaster.pop('error', '提示', response.data);
  7384. });
  7385. });
  7386. AccountEnterprise.growth({}, function(data){
  7387. if(data != null && data.length > 0) {
  7388. var growth = [], years = [];
  7389. angular.forEach(data, function(d){
  7390. var date = new Date(d.date), year = date.getFullYear();
  7391. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  7392. if(years.indexOf(year) == -1) {
  7393. years.push(year);
  7394. growth.push({year: year});
  7395. }
  7396. growth.push(d);
  7397. });
  7398. $scope.growth = growth;
  7399. }
  7400. });
  7401. // 更新企业信息
  7402. $scope.updateDetailInfo = function(){
  7403. $scope.loading = true;
  7404. AccountEnterprise.save($scope.enterprise, function(){
  7405. $scope.loading = false;
  7406. $scope.connectionEditing = false;
  7407. toaster.pop('success', '提示', '修改企业信息成功');
  7408. $state.reload();
  7409. }, function(response){
  7410. $scope.loading = false;
  7411. toaster.pop('error', '修改信息失败', response.data);
  7412. });
  7413. };
  7414. // 申请Saas
  7415. $scope.applySaas = function(){
  7416. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  7417. var modalInstance = $modal.open({
  7418. animation: true,
  7419. templateUrl: 'static/tpl/index/account/applySaas.html',
  7420. controller: 'ApplySaasCtrl',
  7421. resolve: {
  7422. enterprise: function(){return angular.copy($scope.enterprise);}
  7423. }
  7424. });
  7425. modalInstance.result.then(function(){
  7426. $state.reload();
  7427. }, function(){
  7428. });
  7429. } else {
  7430. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  7431. }
  7432. };
  7433. // 获取收货地址列表
  7434. ShipAddress.shipAddList({}, function(data) {
  7435. $scope.ships = data;
  7436. });
  7437. // 判断是否是代采企业
  7438. DeputyOrder.isDeputyEnterprise({}, function(data) {
  7439. $scope.deputyEnter = data;
  7440. });
  7441. // 获取地址信息
  7442. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7443. }).then(function(response) {
  7444. $scope.provinces = response.data;
  7445. });
  7446. // 新增收货地址保存
  7447. $scope.saveShipAddress = function(ship) {
  7448. ship.address = ship.province + ship.city + ship.district;
  7449. ShipAddress.saveAddress( {}, ship, function(data) {
  7450. if(data.success) {
  7451. ShipAddress.shipAddList({}, function(data) {
  7452. $scope.ships = data;
  7453. });
  7454. toaster.pop('success', '提示', data.success);
  7455. }
  7456. if(data.error) {
  7457. toaster.pop('error', '提示', data.error);
  7458. }
  7459. });
  7460. }
  7461. // 删除收货地址
  7462. $scope.removeShip = function(id, index) {
  7463. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  7464. $scope.ships.splice(index, 1);
  7465. toaster.pop('success', '提示', '收货地址删除成功');
  7466. }, function(response) {
  7467. toaster.pop('error', '提示', response.data);
  7468. });
  7469. };
  7470. // 编辑收货地址
  7471. $scope.editShip = function(ship){
  7472. var modalInstance = $modal.open({
  7473. animation: true,
  7474. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  7475. controller: 'ShipAddressCtrl',
  7476. resolve: {
  7477. ship: function(){return ship;}
  7478. }
  7479. });
  7480. modalInstance.result.then(function() {
  7481. ShipAddress.shipAddList({}, function(data) {
  7482. $scope.ships = data;
  7483. });
  7484. }, function(){
  7485. });
  7486. };
  7487. // 新增付款企业
  7488. $scope.addPayCompany = function() {
  7489. var modalInstance = $modal.open({
  7490. animation: true,
  7491. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7492. controller: 'PayCompanyCtrl',
  7493. resolve: {
  7494. pay: function(){return null;}
  7495. }
  7496. });
  7497. modalInstance.result.then(function() {
  7498. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7499. $scope.pays = data;
  7500. // 获取付款企业信息
  7501. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7502. $scope.pays = data;
  7503. }, function(response) {
  7504. toaster.pop('error', '提示', response.data);
  7505. });
  7506. }, function(response) {
  7507. toaster.pop('error', '提示', response.data);
  7508. });
  7509. }, function(){
  7510. });
  7511. }
  7512. // 删除付款企业
  7513. $scope.removePay = function(id, index) {
  7514. DeputyOrder.removePayCompany({id: id}, {}, function(data) {
  7515. $scope.pays.splice(index, 1);
  7516. toaster.pop('success', '提示', '付款企业信息删除成功');
  7517. }, function(response) {
  7518. toaster.pop('error', '提示', response.data);
  7519. });
  7520. };
  7521. // 编辑付款企业
  7522. $scope.editPay = function(pay, uu) {
  7523. var modalInstance = $modal.open({
  7524. animation: true,
  7525. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7526. controller: 'PayCompanyCtrl',
  7527. resolve: {
  7528. pay: function(){return pay;}
  7529. }
  7530. });
  7531. modalInstance.result.then(function() {
  7532. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7533. $scope.pays = data;
  7534. }, function(response) {
  7535. toaster.pop('error', '提示', response.data);
  7536. });
  7537. }, function(){
  7538. });
  7539. };
  7540. // 设置logo
  7541. $scope.showImageDialog = function(modal) {
  7542. require([ 'jquery-uploadify' ], function() {
  7543. $modal.open({
  7544. templateUrl : 'static/tpl/index/home/insert.html',
  7545. controller : 'ImageInsertCtrl',
  7546. backdrop : 'static'
  7547. }).result.then(function(image){
  7548. $scope.imageUrl = image.thumb;
  7549. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  7550. $scope.user = data;
  7551. }, function(response) {
  7552. toaster.pop('error', '设置图像失败,' + response.data);
  7553. });
  7554. });
  7555. });
  7556. }
  7557. }]);
  7558. // 编辑收货地址
  7559. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  7560. $scope.ship = ship;
  7561. // 获取地址信息
  7562. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7563. }).then(function(response) {
  7564. $scope.provinces = response.data;
  7565. });
  7566. // 新增收货地址保存
  7567. $scope.saveShipAddress = function(ship) {
  7568. ship.address = ship.province + ship.city + ship.district;
  7569. ShipAddress.saveAddress( {}, ship, function(data) {
  7570. if(data.success) {
  7571. toaster.pop('success', '提示', data.success);
  7572. $modalInstance.close();
  7573. }
  7574. if(data.error) {
  7575. toaster.pop('error', '提示', data.error);
  7576. }
  7577. });
  7578. }
  7579. $scope.cancel = function() {
  7580. $modalInstance.dismiss();
  7581. }
  7582. }]);
  7583. // 编辑付款企业信息
  7584. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  7585. $scope.pay = pay;
  7586. // 获取地址信息
  7587. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7588. }).then(function(response) {
  7589. $scope.provinces = response.data;
  7590. });
  7591. // 新增收货地址保存
  7592. $scope.savePayCompany = function(pay) {
  7593. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  7594. DeputyOrder.savePaycompany( {}, pay, function(data) {
  7595. toaster.pop('success', '提示', '保存成功');
  7596. $modalInstance.dismiss();
  7597. }, function(response) {
  7598. toaster.pop('error', '提示', response.data);
  7599. });
  7600. }
  7601. $scope.cancel = function() {
  7602. $modalInstance.dismiss();
  7603. }
  7604. }]);
  7605. // 申请Saas Controller
  7606. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  7607. $scope.enterprise = enterprise;
  7608. $scope.checking = false;
  7609. $scope.$watch('enterprise.enSaasUrl', function(){
  7610. if($scope.enterprise.enSaasUrl) {
  7611. $http.get('signup/saasUrlEnable', {
  7612. params: {
  7613. enSaasUrl: $scope.enterprise.enSaasUrl
  7614. }
  7615. }).success(function(data){
  7616. if(data && data == 'true') {
  7617. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  7618. } else {
  7619. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7620. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  7621. }
  7622. }).error(function(){
  7623. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7624. $scope.enSaasUrlErrorInfo = '验证出错';
  7625. });
  7626. } else {
  7627. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7628. }
  7629. });
  7630. var setSaasUrl = function(url) {
  7631. var index = url.indexOf('www.');
  7632. if(index != -1) {//包含www.
  7633. var substr = url.substring(index+4, url.length);
  7634. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  7635. } else {
  7636. $scope.enterprise.enSaasUrl = getHost(url);
  7637. }
  7638. };
  7639. // 解析获取网址的一级域名
  7640. var getHost = function(host){
  7641. var newhost;
  7642. var domain;
  7643. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  7644. for(var k in ArrDomain){
  7645. var re = eval('/\\' + ArrDomain[k] + '$/g');
  7646. newhost = host.replace(re, '');
  7647. if(newhost != host){
  7648. domain = ArrDomain[k];
  7649. break;
  7650. }
  7651. }
  7652. var hostar = newhost.split('.');
  7653. var s = hostar[hostar.length-1];
  7654. return s;
  7655. };
  7656. // 设置优企云服域名为官网网址一级域名
  7657. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  7658. $scope.apply = function(){
  7659. $scope.loading = true;
  7660. AccountEnterprise.applySaas({
  7661. enUU: $scope.enterprise.uu,
  7662. enSaasUrl: $scope.enterprise.enSaasUrl,
  7663. enAdminPassword: $scope.enterprise.enAdminPassword
  7664. }, {}, function(){
  7665. $scope.loading = false;
  7666. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  7667. $modalInstance.close();
  7668. }, function(response){
  7669. $scope.loading = false;
  7670. toaster.pop('error', '申请失败', response.data);
  7671. });
  7672. };
  7673. $scope.cancel = function () {
  7674. $modalInstance.dismiss();
  7675. };
  7676. }]);
  7677. 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){
  7678. BaseService.scrollBackToTop();
  7679. $scope.editing = false;
  7680. $scope.loading = true;
  7681. $scope.enterprise = null;
  7682. AccountUser.findDistribute({},function(data) {
  7683. $scope.distributes = data;
  7684. },function(response) {
  7685. toaster.pop('error', '系统错误', response.data);
  7686. });
  7687. AuthenticationService.getAuthentication().success(function(data) {
  7688. $scope.loading = false;
  7689. $scope.user = data;
  7690. });
  7691. var users = [];
  7692. $scope.tableParams = new ngTableParams({
  7693. page : 1,
  7694. count : 20,
  7695. sorting: {
  7696. userName: 'asc'
  7697. }
  7698. }, {
  7699. total : 0,
  7700. counts: [15, 25, 50, 100],
  7701. getData : function($defer, params) {
  7702. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  7703. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  7704. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  7705. angular.forEach($scope.users,function(user){
  7706. AccountEnterprise.get({}, function(data){
  7707. $scope.loading = false;
  7708. $scope.enterprise = data;
  7709. });
  7710. });
  7711. params.total(orderedData.length);
  7712. $defer.resolve($scope.users);
  7713. }
  7714. });
  7715. var loadUsers = function() {
  7716. AccountUser.query({}, function(data){
  7717. users = data;
  7718. angular.forEach(users, function(user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  7719. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  7720. $scope.user.userIdcode = user.userIdcode;
  7721. }
  7722. });
  7723. $scope.tableParams.reload();
  7724. $scope.loading = false;
  7725. });
  7726. };
  7727. loadUsers();
  7728. $scope.saveUser = function(){
  7729. $scope.loading = true;
  7730. AccountUser.update({}, $scope.user, function(data){
  7731. $scope.loading = false;
  7732. toaster.pop('success', '提示', '修改用户信息成功');
  7733. AuthenticationService.getAuthentication().success(function(data) {
  7734. $scope.user = data;
  7735. });
  7736. loadUsers();
  7737. $scope.editing = false;
  7738. }, function(reponse){
  7739. $scope.loading = false;
  7740. toaster.pop('error', '失败', reponse.data);
  7741. });
  7742. };
  7743. $scope.updatePassword = function(){
  7744. var modalInstance = $modal.open({
  7745. animation: true,
  7746. templateUrl: 'updatePassword.html',
  7747. controller: 'PasswordCtrl',
  7748. resolve: {
  7749. user: function(){return $scope.user;}
  7750. }
  7751. });
  7752. modalInstance.result.then(function(){
  7753. }, function(){
  7754. });
  7755. };
  7756. $scope.newUser = {};
  7757. //弹出添加用户模态框
  7758. $scope.addExistUser = function(){
  7759. var modalInstance = $modal.open({
  7760. animation :true,
  7761. templateUrl : 'static/tpl/index/account/addExistUser.html',
  7762. controller : 'AddExistUserCtrl'
  7763. });
  7764. modalInstance.result.then(function(){
  7765. $scope.userTelSuccess = false;
  7766. $scope.userTelError = false;
  7767. loadUsers();
  7768. }, function(){
  7769. });
  7770. };
  7771. /**
  7772. * 添加未注册用户
  7773. */
  7774. $scope.addUser = function() {
  7775. $scope.adding = true;
  7776. AccountUser.save({}, $scope.newUser, function(){
  7777. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  7778. $scope.newUser = {userSex: 'M'};
  7779. loadUsers();
  7780. $scope.adding = false;
  7781. $scope.newUserForm.newUserTel.$setValidity('available', false);
  7782. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  7783. $scope.userTelSuccess = false;
  7784. $scope.userTelError = false;
  7785. $scope.userEmailSuccess = false;
  7786. $scope.userEmailError = false;
  7787. }, function(response){
  7788. toaster.pop('error', '错误', response.data);
  7789. });
  7790. };
  7791. /**
  7792. * 验证手机号是否可用
  7793. */
  7794. $scope.telValid = function(tel) {
  7795. if(tel) {
  7796. $http.get('account/user/telEnable', {
  7797. params: {
  7798. tel: tel
  7799. }
  7800. }).success(function(data){
  7801. data = eval(data);
  7802. if(data == true) {
  7803. $scope.newUserForm.newUserTel.$setValidity('available', true);
  7804. $scope.userTelSuccess = true;
  7805. $scope.userTelError = false;
  7806. }else{
  7807. $scope.newUserForm.newUserTel.$setValidity('available', false);
  7808. $scope.userTelError = true;
  7809. $scope.userTelSuccess = false;
  7810. if(tel.length == 11)
  7811. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  7812. }
  7813. }).error(function(){
  7814. $scope.userTelSuccess = false;
  7815. $scope.userTelError = true;
  7816. });
  7817. } else {
  7818. $scope.userTelSuccess = false;
  7819. $scope.userTelError = false;
  7820. }
  7821. };
  7822. /**
  7823. * 验证邮箱是否可用
  7824. */
  7825. $scope.emailValid = function(email) {
  7826. if(email) {
  7827. $http.get('account/user/emailEnable', {
  7828. params: {
  7829. email: email
  7830. }
  7831. }).success(function(data){
  7832. data = eval(data);
  7833. if(data == true) {
  7834. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  7835. $scope.userEmailSuccess = true;
  7836. $scope.userEmailError = false;
  7837. } else {
  7838. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  7839. $scope.userEmailError = true;
  7840. $scope.userEmailSuccess = false;
  7841. }
  7842. }).error(function(){
  7843. $scope.userEmailError = true;
  7844. $scope.userEmailSuccess = false;
  7845. });
  7846. } else {
  7847. $scope.userEmailError = false;
  7848. $scope.userEmailSuccess = false;
  7849. }
  7850. };
  7851. /**
  7852. * 删除用户
  7853. */
  7854. $scope.removeUser = function(user) {
  7855. new ngAlert({
  7856. title: '提示',
  7857. content: '确定删除用户(' + user.userName + ')吗?'
  7858. }, function(){
  7859. AccountUser.remove({uu: user.userUU}, function(){
  7860. toaster.pop('success', '提示', '用户删除成功。');
  7861. loadUsers();
  7862. }, function(response){
  7863. toaster.pop('error', '删除失败', response.data);
  7864. });
  7865. });
  7866. };
  7867. // 编辑用户的角色
  7868. $scope.editUserRole = function(user) {
  7869. var modalInstance = $modal.open({
  7870. animation: true,
  7871. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  7872. controller: 'UserRoleCtrl',
  7873. resolve: {
  7874. user: function() {
  7875. return user;
  7876. }
  7877. }
  7878. });
  7879. modalInstance.result.then(function(changed, checked){
  7880. if(changed) {
  7881. if(checked)
  7882. $scope.newUser.roles = checked;
  7883. else
  7884. loadUsers();
  7885. }
  7886. });
  7887. };
  7888. // 为用户分配角色(删除企业)
  7889. $scope.removeVendor = function(user) {
  7890. var resultRole = true;
  7891. angular.forEach(user.roles,function(role){
  7892. if(role.issys == 1) {
  7893. toaster.pop('error', '提示', '管理员无需分配客户');
  7894. resultRole = false;
  7895. return;
  7896. }
  7897. })
  7898. if(resultRole) {
  7899. var modalInstance = $modal.open({
  7900. animation: true,
  7901. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  7902. controller: 'RemoveVendorCtrl',
  7903. resolve: {
  7904. user: function() {
  7905. return user;
  7906. }
  7907. }
  7908. });
  7909. }
  7910. }
  7911. // 为用户分配角色(添加企业)
  7912. $scope.addVendor = function(user,isIssy) {
  7913. if(!isIssy) {
  7914. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  7915. return;
  7916. }
  7917. var resultRole = true;
  7918. angular.forEach(user.roles,function(role){
  7919. if(role.issys == 1) {
  7920. toaster.pop('error', '提示', '管理员无需分配客户');
  7921. resultRole = false;
  7922. return;
  7923. }
  7924. })
  7925. if(resultRole) {
  7926. var modalInstance = $modal.open({
  7927. animation: true,
  7928. templateUrl: 'static/tpl/index/account/add_vendor.html',
  7929. controller: 'AddVendorCtrl',
  7930. resolve: {
  7931. user: function() {
  7932. return user;
  7933. }
  7934. }
  7935. });
  7936. modalInstance.result.then(function(changed, checked){
  7937. if(changed) {
  7938. if(checked)
  7939. $scope.newUser.roles = checked;
  7940. else
  7941. loadUsers();
  7942. }
  7943. });
  7944. }
  7945. };
  7946. }]);
  7947. // 登录手机号码验证
  7948. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  7949. $scope.user = user;
  7950. $scope.cancel = function(){
  7951. $modalInstance.close();
  7952. }
  7953. /*$scope.loading = false;
  7954. $scope.btnState = false;
  7955. $scope.clicks = 0;
  7956. var storage = window.localStorage;
  7957. //手机验证码定时器
  7958. $scope.msgInfoError = false;
  7959. var setBtnTimeDown = function(value) {
  7960. if(value > 0) {
  7961. $scope.btnState = true;
  7962. $timeout(function() {
  7963. $scope.$apply(function(){
  7964. storage.setItem("btnTimes", $scope.btnTimes);
  7965. $scope.btnTimes --;
  7966. value --;
  7967. setBtnTimeDown (value);
  7968. });
  7969. }, 500);
  7970. }else{
  7971. $scope.btnState = false;
  7972. }
  7973. };
  7974. if(storage.btnTimes > 1){
  7975. $scope.btnTimes = storage.btnTimes;
  7976. setBtnTimeDown(storage.btnTimes)
  7977. }else{
  7978. storage.removeItem("btnTimes");
  7979. }
  7980. $scope.updateTel = function(phoneCode, userTel, uu){
  7981. $scope.loading = true;
  7982. $scope.msgInfoError = false;
  7983. $scope.result = false;
  7984. //更新联系方式
  7985. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  7986. $scope.loading = false;
  7987. $scope.msgInfoError2 = false;
  7988. $scope.result = true;
  7989. AuthenticationService.getAuthentication().success(function(data) {
  7990. $timeout(function(){
  7991. $modalInstance.dismiss();
  7992. window.location.reload();
  7993. }, 1000);
  7994. }).error(function(response) {
  7995. });
  7996. }, function(response){
  7997. $scope.loading = false;
  7998. $scope.msgInfoError2 = response;
  7999. });
  8000. };
  8001. //获取验证码
  8002. $scope.getPhoneCode = function(userTel){
  8003. var timeInfo = 10;
  8004. $scope.clicks ++;
  8005. $scope.timeInfo = timeInfo;
  8006. if($scope.clicks >= 5){
  8007. $scope.errorloading = true;
  8008. $scope.msgInfoSuccess = false;
  8009. $scope.msgInfoError = false;
  8010. }else{
  8011. $scope.loading = true;
  8012. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  8013. $scope.loading = false;
  8014. $scope.msgInfoSuccess = data.success;
  8015. $scope.sendMsg = data;
  8016. $scope.btnTimes = 60;
  8017. setBtnTimeDown($scope.btnTimes);
  8018. $scope.msgInfoError = false;
  8019. },function(response){
  8020. console.log(response);
  8021. $scope.loading = false;
  8022. $scope.msgInfoError = false;
  8023. $scope.sendCheckMsg = false;
  8024. $scope.msgInfoSuccess = true;
  8025. });
  8026. }
  8027. }; */
  8028. }]);
  8029. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  8030. $scope.checkboxes = {
  8031. checked : false
  8032. };
  8033. $scope.loading = true;
  8034. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  8035. $scope.enters = data;
  8036. $scope.loading = false;
  8037. angular.forEach($scope.enters, function(item) {
  8038. item:{
  8039. $selected:true;
  8040. }
  8041. });
  8042. })
  8043. // 点击勾选全部的复选框
  8044. $scope.checkAll = function() {
  8045. angular.forEach($scope.enters, function(item) {
  8046. item.$selected = $scope.checkboxes.checked;
  8047. });
  8048. };
  8049. // 点击其中一个明细的复选框
  8050. $scope.checkOne = function(vendor){
  8051. var result = true;
  8052. angular.forEach($scope.enters, function(item) {
  8053. if(item.$selected != true){
  8054. result = false;
  8055. return;
  8056. }
  8057. });
  8058. $scope.checkboxes.checked = result;
  8059. };
  8060. $scope.close = function(save) {
  8061. var chooseResult = [];
  8062. if(save) {
  8063. if(user.userUU) {
  8064. angular.forEach($scope.enters, function(item, i) {
  8065. if(item.$selected) {
  8066. chooseResult.push(item.id);
  8067. }
  8068. });
  8069. if(chooseResult.length > 0) {
  8070. $scope.loading = true;
  8071. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  8072. $scope.loading = false;
  8073. toaster.pop('success', '提示', '删除成功');
  8074. $modalInstance.close(false);
  8075. }, function(response){
  8076. $scope.loading = false;
  8077. toaster.pop('error', '删除失败', response.data);
  8078. $modalInstance.close(false);
  8079. })
  8080. } else {
  8081. toaster.pop('error', '删除失败', "您未勾选任何记录");
  8082. }
  8083. } else {
  8084. $modalInstance.close(true, $scope.checkboxes.checked);
  8085. }
  8086. } else {
  8087. $modalInstance.close(false);
  8088. }
  8089. };
  8090. }]);
  8091. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  8092. $scope.checkboxes = {
  8093. checked : false
  8094. };
  8095. $scope.loading = true;
  8096. AccountUser.findVendor({uu : user.userUU},function(data) {
  8097. $scope.enters = data;
  8098. $scope.loading = false;
  8099. // angular.forEach($scope.enters, function(item) {
  8100. // if(item.distribute) {
  8101. // item:{
  8102. // $selected:false;
  8103. // }
  8104. // } else {
  8105. // item:{
  8106. // $selected:true;
  8107. // }
  8108. // }
  8109. // });
  8110. })
  8111. // 点击勾选全部的复选框
  8112. $scope.checkAll = function() {
  8113. angular.forEach($scope.enters, function(item) {
  8114. item.distribute = $scope.checkboxes.checked;
  8115. });
  8116. };
  8117. // 点击其中一个明细的复选框
  8118. $scope.checkOne = function(vendor){
  8119. var result = true;
  8120. angular.forEach($scope.enters, function(item) {
  8121. if(item.distribute != true){
  8122. result = false;
  8123. return;
  8124. }
  8125. });
  8126. $scope.checkboxes.checked = result;
  8127. };
  8128. $scope.close = function(save) {
  8129. var chooseResult = [];
  8130. if(save) {
  8131. if(user.userUU) {
  8132. angular.forEach($scope.enters, function(item, i) {
  8133. // if(item.distribute) {
  8134. chooseResult.push(item);
  8135. // }
  8136. });
  8137. if(chooseResult.length > 0) {
  8138. $scope.loading = true;
  8139. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  8140. $scope.loading = false;
  8141. toaster.pop('success', '提示', '保存成功');
  8142. $modalInstance.close(false);
  8143. }, function(response){
  8144. $scope.loading = false;
  8145. toaster.pop('error', '保存失败', response.data);
  8146. $modalInstance.close(false);
  8147. })
  8148. } else {
  8149. toaster.pop('error', '保存失败', "您未勾选任何记录");
  8150. }
  8151. } else {
  8152. $modalInstance.close(true, $scope.checkboxes.checked);
  8153. }
  8154. } else {
  8155. $modalInstance.close(false);
  8156. }
  8157. };
  8158. }]);
  8159. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  8160. $scope.checked = [];
  8161. $scope.master = [];
  8162. AccountRole.query({}, function(data){
  8163. if(user && data) {
  8164. var rs = [], checked = [];
  8165. angular.forEach(user.roles, function(r){
  8166. rs.push(r.id);
  8167. });
  8168. angular.forEach(data, function(d){
  8169. if(rs.indexOf(d.id) > -1) {
  8170. d.$checked = true;
  8171. checked.push(d);
  8172. }
  8173. });
  8174. }
  8175. $scope.roles = data;
  8176. $scope.checked = checked;
  8177. $scope.master = angular.copy($scope.checked);
  8178. });
  8179. $scope.select = function(role) {
  8180. role.$checked = !role.$checked;
  8181. if(role.$checked) {
  8182. $scope.checked.push(role);
  8183. } else {
  8184. angular.forEach($scope.checked, function(c, i){
  8185. if(c.id == role.id)
  8186. $scope.checked.splice(i, 1);
  8187. });
  8188. }
  8189. };
  8190. $scope.isChanged = function() {
  8191. return !angular.equals($scope.master, $scope.checked);
  8192. };
  8193. $scope.close = function(save) {
  8194. if(save) {
  8195. if(user.userUU) {
  8196. user.roles = $scope.checked;
  8197. AccountUser.update({}, user, function(){
  8198. toaster.pop('success', '提示', '保存成功');
  8199. $modalInstance.close(true);
  8200. }, function(response){
  8201. toaster.pop('error', '保存失败', response.data);
  8202. });
  8203. } else {
  8204. $modalInstance.close(true, $scope.checked);
  8205. }
  8206. } else {
  8207. $modalInstance.close(false);
  8208. }
  8209. };
  8210. }]);
  8211. // 修改密码Controller
  8212. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  8213. $scope.user = user;
  8214. $scope.checking = false;
  8215. //输入原密码后验证原密码是否正确
  8216. $scope.checkPassword = function(password) {
  8217. $scope.checking = true;
  8218. $scope.checkSuccess = false;
  8219. $scope.checkFailed = false;
  8220. AccountUser.checkPassword({password: password}, function(data){
  8221. $scope.checkSuccess = true;
  8222. $scope.checking = false;
  8223. $scope.checkFailed = false;
  8224. }, function(response){
  8225. $scope.checkFailed = true;
  8226. $scope.checking = false;
  8227. $scope.checkSuccess = false;
  8228. });
  8229. };
  8230. //修改密码
  8231. $scope.ok = function () {
  8232. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  8233. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  8234. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  8235. toaster.pop('success', '成功', tip);
  8236. $scope.user.password = null;
  8237. $scope.user.newPassword = null;
  8238. $scope.user.newPassword1 = null;
  8239. $scope.checking = false;
  8240. $scope.checkSuccess = false;
  8241. $scope.checkFailed = false;
  8242. $modalInstance.close();
  8243. }, function(response){
  8244. toaster.pop('error', '错误', response.data);
  8245. });
  8246. } else {
  8247. toaster.pop('error', '错误', '重复密码不一致');
  8248. }
  8249. };
  8250. $scope.cancel = function () {
  8251. $modalInstance.dismiss();
  8252. };
  8253. }]);
  8254. /*
  8255. * 绑定用户到企业
  8256. */
  8257. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster){
  8258. $scope.searching = false;
  8259. //根据输入的内容查找用户
  8260. $scope.searchUser = function(keyWord) {
  8261. $scope.searching = true;
  8262. $scope.searchSuccess = false;
  8263. $scope.searchFailed = false;
  8264. $scope.illegalError = false;
  8265. $scope.reBindError = false;
  8266. $scope.okDisabled = false;
  8267. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  8268. $scope.searchSuccess = true;
  8269. $scope.searchFailed = false;
  8270. $scope.user = data; //查询到的用户
  8271. }, function(response){
  8272. $scope.searchSuccess = false;
  8273. $scope.searchFailed = true;
  8274. });
  8275. };
  8276. //确认绑定
  8277. $scope.ok = function (keyWord) {
  8278. AuthenticationService.getAuthentication().success(function(data) {
  8279. $scope.currentUser = data; //当前登录的用户(管理员)
  8280. //不可自己绑定自己
  8281. if($scope.currentUser.userUU == $scope.user.userUU){
  8282. $scope.illegalError = true;
  8283. $scope.okDisabled = true;
  8284. return false;
  8285. }
  8286. //用户未绑定到任何企业时
  8287. if(!$scope.user.enterprises){
  8288. //正常绑定
  8289. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  8290. $scope.okDisabled = true;
  8291. toaster.pop("success", "提示", "用户绑定成功");
  8292. $modalInstance.close(true);
  8293. }, function(response){
  8294. });
  8295. return true;
  8296. }
  8297. //用户已绑定到某些企业时
  8298. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  8299. if($scope.currentUser.enterprises[i].current){
  8300. for(var j = 0; j < $scope.user.enterprises.length; j++){
  8301. //该用户已绑定到当前企业,不可重复绑定
  8302. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  8303. $scope.reBindError = true;
  8304. $scope.okDisabled = true;
  8305. return false;
  8306. }
  8307. }
  8308. //该用户未绑定到当前企业,可以进行绑定
  8309. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  8310. $scope.okDisabled = true;
  8311. toaster.pop("success", "提示", "用户绑定成功");
  8312. $modalInstance.close(true);
  8313. }, function(response){
  8314. console.log("绑定失败!");
  8315. });
  8316. }
  8317. }
  8318. });
  8319. };
  8320. $scope.cancel = function () {
  8321. $modalInstance.dismiss();
  8322. };
  8323. }]);
  8324. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  8325. $scope.erpParams = new ngTableParams({
  8326. page : 1,
  8327. count : 20,
  8328. sorting: {
  8329. time: 'desc'
  8330. }
  8331. }, {
  8332. total : 0,
  8333. counts: [5, 10, 25, 50],
  8334. getData : function($defer, params) {
  8335. $scope.loading = true;
  8336. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  8337. $scope.loading = false;
  8338. if(page) {
  8339. params.total(page.totalElements);
  8340. $defer.resolve(page.content);
  8341. }
  8342. }, function(response){
  8343. $scope.loading = false;
  8344. toaster.pop('error', '数据加载失败', response.data);
  8345. });
  8346. }
  8347. });
  8348. $scope.usageParams = new ngTableParams({
  8349. page : 1,
  8350. count : 20,
  8351. sorting: {
  8352. time: 'desc'
  8353. }
  8354. }, {
  8355. total : 0,
  8356. counts: [5, 10, 25, 50],
  8357. getData : function($defer, params) {
  8358. $scope.loading = true;
  8359. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  8360. $scope.loading = false;
  8361. if(page) {
  8362. params.total(page.totalElements);
  8363. $defer.resolve(page.content);
  8364. }
  8365. }, function(response){
  8366. $scope.loading = false;
  8367. toaster.pop('error', '数据加载失败', response.data);
  8368. });
  8369. }
  8370. });
  8371. }]);
  8372. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  8373. AccountResource.query({}, function(data){
  8374. if(data && data.length > 0) {
  8375. data[0].$open = true;
  8376. }
  8377. $scope.resources = data;
  8378. });
  8379. }]);
  8380. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  8381. $scope.roles = {};
  8382. var getData = function() {
  8383. AccountRole.query({}, function(data){
  8384. var defaults = [], custom = [];
  8385. angular.forEach(data, function(d){
  8386. if(d.isdefault == 1)
  8387. defaults.push(d);
  8388. else
  8389. custom.push(d);
  8390. });
  8391. $scope.roles = {defaults: defaults, custom: custom};
  8392. });
  8393. };
  8394. getData();
  8395. $scope.editRole = function(role){
  8396. var modalInstance = $modal.open({
  8397. animation: true,
  8398. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  8399. controller: 'RoleEditCtrl',
  8400. resolve: {
  8401. role: function() {
  8402. return role;
  8403. }
  8404. }
  8405. });
  8406. modalInstance.result.then(function(added){
  8407. added && (getData());
  8408. });
  8409. };
  8410. }]);
  8411. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  8412. BaseService.scrollBackToTop();
  8413. $scope.role = role;
  8414. $scope.master = angular.copy($scope.role);
  8415. var isNew = role == null;
  8416. $scope.cancel = function() {
  8417. $modalInstance.close(false);
  8418. };
  8419. AccountResource.query({}, function(data){
  8420. if(data && data.length > 0) {
  8421. if(role && role.resourceItems) {
  8422. var rs = [];// 已分配的资源的id
  8423. angular.forEach(role.resourceItems, function(item){
  8424. rs.push(item.id);
  8425. });
  8426. angular.forEach(data, function(resource){
  8427. var c = 0;
  8428. angular.forEach(resource.items, function(item){
  8429. if(rs.indexOf(item.id) > -1) {
  8430. item.$checked = true;
  8431. c += 1;
  8432. }
  8433. });
  8434. resource.$checked = c == resource.items.length;
  8435. });
  8436. }
  8437. $scope.resourceItems = data[0].items;
  8438. data[0].$active = true;
  8439. }
  8440. $scope.resources = data;
  8441. $timeout(function(){
  8442. angular.forEach($scope.resources, function(resource){
  8443. var c = 0;
  8444. angular.forEach(resource.items, function(item){
  8445. item.$checked && (c+=1);
  8446. });
  8447. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8448. });
  8449. }, 100);
  8450. });
  8451. $scope.onItemClick = function(resource) {
  8452. $scope.resourceItems = resource.items;
  8453. angular.forEach($scope.resources, function(r){
  8454. r.$active = false;
  8455. });
  8456. resource.$active = true;
  8457. };
  8458. var getChecked = function() {
  8459. var items = [];
  8460. angular.forEach($scope.resources, function(resource){
  8461. angular.forEach(resource.items, function(item){
  8462. item.$checked && (items.push(item));
  8463. });
  8464. });
  8465. $scope.role.resourceItems = items;
  8466. };
  8467. $scope.onResourceChange = function(resource) {
  8468. angular.forEach(resource.items, function(item){
  8469. item.$checked = resource.$checked;
  8470. });
  8471. getChecked();
  8472. };
  8473. $scope.onItemChange = function() {
  8474. angular.forEach($scope.resources, function(resource){
  8475. if(resource.$active) {
  8476. var c = 0;
  8477. angular.forEach(resource.items, function(item){
  8478. item.$checked && (c+=1);
  8479. });
  8480. resource.$checked = (c == resource.items.length);
  8481. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8482. }
  8483. });
  8484. getChecked();
  8485. };
  8486. $scope.isChanged = function(formData) {
  8487. if(!$scope.master)
  8488. return true;
  8489. return !angular.equals(formData, $scope.master);
  8490. };
  8491. $scope.save = function() {
  8492. $scope.master = angular.copy($scope.role);
  8493. AccountRole.save($scope.master, function(){
  8494. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  8495. $modalInstance.close(true);
  8496. }, function(response){
  8497. toaster.pop('error', '错误', response.data);
  8498. });
  8499. };
  8500. $scope.del = function() {
  8501. new ngAlert({
  8502. title: '提示',
  8503. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  8504. }, function(){
  8505. AccountRole.remove({id: role.id}, function(){
  8506. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  8507. $modalInstance.close(true);
  8508. }, function(response){
  8509. toaster.pop('error', '错误', response.data);
  8510. });
  8511. })
  8512. };
  8513. }]);
  8514. /**
  8515. * 委外订单
  8516. */
  8517. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  8518. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  8519. BaseService.scrollBackToTop();
  8520. $scope.active = 'todo';
  8521. $scope.dateZoneText = '不限';
  8522. $scope.condition = {dateZone: -1};
  8523. $scope.nowdate = new Date();
  8524. $scope.changeDateZone = function(zone) {
  8525. $scope.condition.dateZone = zone;
  8526. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  8527. $scope.condition.$dateZoneOpen = false;
  8528. getDateCondition(zone, $scope.condition);
  8529. $scope.tableParams.reload();
  8530. };
  8531. $scope.setActive = function(state) {
  8532. if($scope.active != state) {
  8533. $scope.active = state;
  8534. if($scope.tableParams.page() == 1)
  8535. $scope.tableParams.reload();
  8536. else
  8537. $scope.tableParams.page(1);
  8538. }
  8539. };
  8540. var getService = function() {
  8541. return MakeOrder;
  8542. };
  8543. $scope.tableParams = new ngTableParams({
  8544. page : 1,
  8545. count : 20,
  8546. sorting: {
  8547. date: 'desc'
  8548. }
  8549. }, {
  8550. total : 0,
  8551. counts: [5, 10, 25, 50],
  8552. getData : function($defer, params) {
  8553. $scope.loading = true;
  8554. var pageParams = params.url();
  8555. pageParams.searchFilter = {};
  8556. pageParams.searchFilter.keyword = $scope.keyword;
  8557. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8558. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8559. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8560. $scope.loading = false;
  8561. if(page) {
  8562. params.total(page.totalElement);
  8563. $defer.resolve(page.content);
  8564. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8565. }
  8566. }, function(response){
  8567. $scope.loading = false;
  8568. toaster.pop('error', '数据加载失败', response.data);
  8569. });
  8570. }
  8571. });
  8572. $scope.getOrderTotal = function(items) {
  8573. var sum = 0;
  8574. angular.forEach(items, function(item){
  8575. sum += item.qty * item.price;
  8576. });
  8577. return sum;
  8578. };
  8579. $scope.openDatePicker = function($event, item, openParam) {
  8580. $event.preventDefault();
  8581. $event.stopPropagation();
  8582. item[openParam] = !item[openParam];
  8583. };
  8584. $scope.parseDate = function(dateStr) {
  8585. if(dateStr)
  8586. return Date.parse(dateStr, 'yyyy-MM-dd');
  8587. return new Date();
  8588. };
  8589. // 打开回复
  8590. $scope.openReply = function(order) {
  8591. if(!order.reply) {
  8592. order.reply = {
  8593. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8594. delivery: order.delivery
  8595. }
  8596. }
  8597. order.$editing = true;
  8598. };
  8599. // 关闭回复
  8600. $scope.closeReply = function(order) {
  8601. order.$editing = false;
  8602. }
  8603. // 搜索框回车
  8604. $scope.onSearch = function() {
  8605. $scope.tableParams.page(1);
  8606. $scope.tableParams.reload();
  8607. };
  8608. // 选择查找日期
  8609. $scope.onDateCondition = function(){
  8610. $scope.tableParams.page(1);
  8611. $scope.tableParams.reload();
  8612. };
  8613. // 点击回复
  8614. $scope.onReplyClick = function(order, inverse) {
  8615. if(order.reply) {
  8616. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8617. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8618. return;
  8619. }
  8620. var reply = angular.copy(order.reply);
  8621. if(reply.delivery) {
  8622. if(typeof reply.delivery == 'object')
  8623. reply.delivery = reply.delivery.getTime();
  8624. } else {
  8625. reply.delivery = order.delivery;
  8626. }
  8627. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8628. $scope.loading = true;
  8629. MakeOrder.reply({orderId: order.id}, reply, function(){
  8630. $scope.loading = false;
  8631. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8632. $scope.tableParams.reload();
  8633. }, function(response){
  8634. $scope.loading = false;
  8635. toaster.pop('error', '回复失败', response.data);
  8636. });
  8637. }
  8638. };
  8639. //委外加工单
  8640. $scope.print = function(order) {
  8641. MakeOrder.printCount({id: order.id},{});//增加打印此次
  8642. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  8643. };
  8644. // 获取回复记录
  8645. $scope.getReply = function(order) {
  8646. if(!order.replies) {
  8647. MakeOrder.getReply({orderId: order.id}, function(replies){
  8648. order.replies = replies;
  8649. });
  8650. }
  8651. };
  8652. }]);
  8653. /**
  8654. * 委外加工单详细
  8655. */
  8656. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  8657. BaseService.scrollBackToTop();
  8658. var loadData = function() {
  8659. MakeOrder.get({id: $stateParams.id}, function(data){
  8660. $scope.order = data;
  8661. var sum = $scope.order.qty * $scope.order.price;
  8662. $scope.order.total = sum;
  8663. $scope.loading = false;
  8664. });
  8665. };
  8666. loadData();
  8667. // 获取回复记录
  8668. $scope.getReply = function(item) {
  8669. if(!item.replies) {
  8670. MakeOrder.getReply({orderId: item.id}, function(replies){
  8671. item.replies = replies;
  8672. });
  8673. }
  8674. };
  8675. $scope.openDatePicker = function($event, item, openParam) {
  8676. $event.preventDefault();
  8677. $event.stopPropagation();
  8678. item[openParam] = !item[openParam];
  8679. };
  8680. // 点击回复
  8681. $scope.onReplyClick = function(order, inverse) {
  8682. if(order.reply) {
  8683. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8684. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8685. return;
  8686. }
  8687. var reply = angular.copy(order.reply);
  8688. if(reply.delivery) {
  8689. if(typeof reply.delivery == 'object')
  8690. reply.delivery = reply.delivery.getTime();
  8691. } else {
  8692. reply.delivery = order.delivery;
  8693. }
  8694. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8695. $scope.loading = true;
  8696. MakeOrder.reply({orderId: order.id}, reply, function(){
  8697. $scope.loading = false;
  8698. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8699. loadData();
  8700. }, function(response){
  8701. $scope.loading = false;
  8702. toaster.pop('error', '回复失败', response.data);
  8703. });
  8704. }
  8705. };
  8706. // 打开回复
  8707. $scope.openReply = function(order) {
  8708. if(!order.reply) {
  8709. order.reply = {
  8710. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8711. delivery: order.delivery
  8712. }
  8713. }
  8714. order.$editing = true;
  8715. };
  8716. // 关闭回复
  8717. $scope.closeReply = function(order) {
  8718. order.$editing = false;
  8719. }
  8720. // 委外订单
  8721. $scope.print = function(order) {
  8722. MakeOrder.printCount({id: order.id},{});//增加打印此次
  8723. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  8724. };
  8725. }]);
  8726. /**
  8727. * 客户委外验收
  8728. */
  8729. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  8730. BaseService.scrollBackToTop();
  8731. $scope.active = 'all';
  8732. $scope.agreedText = '全部';
  8733. $scope.dateZoneText = '一个月内';
  8734. $scope.condition = {dateZone: 1};
  8735. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8736. $scope.changeAgreed = function(agreed) {
  8737. $scope.condition.agreed = agreed;
  8738. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8739. $scope.condition.$agreedOpen = false;
  8740. };
  8741. $scope.changeDateZone = function(zone) {
  8742. $scope.condition.dateZone = zone;
  8743. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8744. $scope.condition.$dateZoneOpen = false;
  8745. getDateCondition(zone, $scope.condition);
  8746. $scope.tableParams.reload();
  8747. };
  8748. $scope.setActive = function(state) {
  8749. if($scope.active != state) {
  8750. $scope.active = state;
  8751. if($scope.tableParams.page() == 1)
  8752. $scope.tableParams.reload();
  8753. else
  8754. $scope.tableParams.page(1);
  8755. }
  8756. };
  8757. var getService = function() {
  8758. return MakeAccept;
  8759. };
  8760. $scope.tableParams = new ngTableParams({
  8761. page : 1,
  8762. count : 20,
  8763. sorting: {
  8764. date: 'desc'
  8765. }
  8766. }, {
  8767. total : 0,
  8768. counts: [5, 10, 25, 50],
  8769. getData : function($defer, params) {
  8770. $scope.loading = true;
  8771. var pageParams = params.url();
  8772. pageParams.searchFilter = {};
  8773. pageParams.searchFilter.keyword = $scope.keyword;
  8774. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8775. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8776. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8777. $scope.loading = false;
  8778. if(page) {
  8779. params.total(page.totalElement);
  8780. $defer.resolve(page.content);
  8781. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8782. }
  8783. }, function(response){
  8784. $scope.loading = false;
  8785. toaster.pop('error', '数据加载失败', response.data);
  8786. });
  8787. }
  8788. });
  8789. $scope.openDatePicker = function($event, item, openParam) {
  8790. $event.preventDefault();
  8791. $event.stopPropagation();
  8792. item[openParam] = !item[openParam];
  8793. };
  8794. // 搜索框回车
  8795. $scope.onSearch = function() {
  8796. $scope.tableParams.page(1);
  8797. $scope.tableParams.reload();
  8798. };
  8799. // 选择查找日期
  8800. $scope.onDateCondition = function(){
  8801. $scope.tableParams.page(1);
  8802. $scope.tableParams.reload();
  8803. };
  8804. }]);
  8805. /**
  8806. * 客户委外验退
  8807. */
  8808. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  8809. BaseService.scrollBackToTop();
  8810. $scope.active = 'all';
  8811. $scope.agreedText = '全部';
  8812. $scope.dateZoneText = '一个月内';
  8813. $scope.condition = {dateZone: 1};
  8814. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8815. $scope.changeAgreed = function(agreed) {
  8816. $scope.condition.agreed = agreed;
  8817. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8818. $scope.condition.$agreedOpen = false;
  8819. };
  8820. $scope.changeDateZone = function(zone) {
  8821. $scope.condition.dateZone = zone;
  8822. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8823. $scope.condition.$dateZoneOpen = false;
  8824. getDateCondition(zone, $scope.condition);
  8825. $scope.tableParams.reload();
  8826. };
  8827. $scope.setActive = function(state) {
  8828. if($scope.active != state) {
  8829. $scope.active = state;
  8830. if($scope.tableParams.page() == 1)
  8831. $scope.tableParams.reload();
  8832. else
  8833. $scope.tableParams.page(1);
  8834. }
  8835. };
  8836. var getService = function() {
  8837. return MakeReturn;
  8838. };
  8839. $scope.tableParams = new ngTableParams({
  8840. page : 1,
  8841. count : 20,
  8842. sorting: {
  8843. date: 'desc'
  8844. }
  8845. }, {
  8846. total : 0,
  8847. counts: [5, 10, 25, 50],
  8848. getData : function($defer, params) {
  8849. $scope.loading = true;
  8850. var pageParams = params.url();
  8851. pageParams.searchFilter = {};
  8852. pageParams.searchFilter.keyword = $scope.keyword;
  8853. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8854. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8855. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8856. $scope.loading = false;
  8857. if(page) {
  8858. params.total(page.totalElement);
  8859. $defer.resolve(page.content);
  8860. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8861. }
  8862. }, function(response){
  8863. $scope.loading = false;
  8864. toaster.pop('error', '数据加载失败', response.data);
  8865. });
  8866. }
  8867. });
  8868. $scope.openDatePicker = function($event, item, openParam) {
  8869. $event.preventDefault();
  8870. $event.stopPropagation();
  8871. item[openParam] = !item[openParam];
  8872. };
  8873. // 搜索框回车
  8874. $scope.onSearch = function() {
  8875. $scope.tableParams.page(1);
  8876. $scope.tableParams.reload();
  8877. };
  8878. // 选择查找日期
  8879. $scope.onDateCondition = function(){
  8880. $scope.tableParams.page(1);
  8881. $scope.tableParams.reload();
  8882. };
  8883. }]);
  8884. /**
  8885. * 委外加工变更
  8886. */
  8887. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  8888. BaseService.scrollBackToTop();
  8889. $scope.active = 'all';
  8890. $scope.agreedText = '全部';
  8891. $scope.dateZoneText = '一个月内';
  8892. $scope.condition = {dateZone: 1};
  8893. $scope.changeAgreed = function(agreed) {
  8894. $scope.condition.agreed = agreed;
  8895. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8896. $scope.condition.$agreedOpen = false;
  8897. };
  8898. $scope.changeDateZone = function(zone) {
  8899. $scope.condition.dateZone = zone;
  8900. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8901. $scope.condition.$dateZoneOpen = false;
  8902. getDateCondition(zone, $scope.condition);
  8903. $scope.tableParams.reload();
  8904. };
  8905. $scope.setActive = function(state) {
  8906. if($scope.active != state) {
  8907. $scope.active = state;
  8908. if($scope.tableParams.page() == 1)
  8909. $scope.tableParams.reload();
  8910. else
  8911. $scope.tableParams.page(1);
  8912. }
  8913. };
  8914. var getService = function() {
  8915. return MakeChange;
  8916. };
  8917. $scope.tableParams = new ngTableParams({
  8918. page : 1,
  8919. count : 20,
  8920. sorting: {
  8921. orderChangeDate: 'desc'
  8922. }
  8923. }, {
  8924. total : 0,
  8925. counts: [5, 10, 25, 50],
  8926. getData : function($defer, params) {
  8927. $scope.loading = true;
  8928. var pageParams = params.url();
  8929. pageParams.searchFilter = {};
  8930. pageParams.searchFilter.keyword = $scope.keyword;
  8931. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8932. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8933. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8934. $scope.loading = false;
  8935. if(page) {
  8936. params.total(page.totalElement);
  8937. $defer.resolve(page.content);
  8938. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8939. }
  8940. }, function(response){
  8941. $scope.loading = false;
  8942. toaster.pop('error', '数据加载失败', response.data);
  8943. });
  8944. }
  8945. });
  8946. $scope.openDatePicker = function($event, item, openParam) {
  8947. $event.preventDefault();
  8948. $event.stopPropagation();
  8949. item[openParam] = !item[openParam];
  8950. };
  8951. // 打开回复
  8952. $scope.openReply = function(change) {
  8953. change.$editing = true;
  8954. };
  8955. // 关闭回复
  8956. $scope.closeReply = function(change) {
  8957. change.$editing = false;
  8958. }
  8959. // 确定回复
  8960. $scope.onReplyClick = function(change) {
  8961. if(change.$agreed) {
  8962. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8963. $scope.loading = true;
  8964. MakeChange.reply({itemId: change.id}, reply, function(){
  8965. $scope.loading = false;
  8966. toaster.pop('info', '提示', '回复成功');
  8967. $scope.tableParams.reload();
  8968. }, function(response){
  8969. $scope.loading = false;
  8970. toaster.pop('error', '回复失败', response.data);
  8971. });
  8972. }
  8973. };
  8974. // 搜索框回车
  8975. $scope.onSearch = function() {
  8976. $scope.tableParams.page(1);
  8977. $scope.tableParams.reload();
  8978. };
  8979. // 选择查找日期
  8980. $scope.onDateCondition = function(){
  8981. $scope.tableParams.page(1);
  8982. $scope.tableParams.reload();
  8983. };
  8984. }]);
  8985. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  8986. BaseService.scrollBackToTop();
  8987. var loadData = function() {
  8988. MakeChange.get({id: $stateParams.id}, function(data){
  8989. $scope.change = data;
  8990. });
  8991. };
  8992. loadData();
  8993. $scope.openDatePicker = function($event, item, openParam) {
  8994. $event.preventDefault();
  8995. $event.stopPropagation();
  8996. item[openParam] = !item[openParam];
  8997. };
  8998. $scope.onReplyClick = function(change) {
  8999. if(change.$agreed) {
  9000. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  9001. MakeChange.reply({itemId: change.id}, reply, function(){
  9002. toaster.pop('info', '提示', '回复成功');
  9003. loadData();
  9004. }, function(response){
  9005. toaster.pop('error', '回复失败', response.data);
  9006. });
  9007. }
  9008. };
  9009. }]);
  9010. /**
  9011. * 委外加工
  9012. */
  9013. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  9014. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  9015. BaseService.scrollBackToTop();
  9016. $scope.active = 'all';
  9017. $scope.agreedText = '全部';
  9018. $scope.dateZoneText = '一个月内';
  9019. $scope.condition = {dateZone: 1};
  9020. $scope.changeAgreed = function(agreed) {
  9021. $scope.condition.agreed = agreed;
  9022. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9023. $scope.condition.$agreedOpen = false;
  9024. };
  9025. $scope.changeDateZone = function(zone) {
  9026. $scope.condition.dateZone = zone;
  9027. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9028. $scope.condition.$dateZoneOpen = false;
  9029. getDateCondition(zone, $scope.condition);
  9030. $scope.tableParams.reload();
  9031. };
  9032. $scope.setActive = function(state) {
  9033. if($scope.active != state) {
  9034. $scope.active = state;
  9035. if($scope.tableParams.page() == 1)
  9036. $scope.tableParams.reload();
  9037. else
  9038. $scope.tableParams.page(1);
  9039. }
  9040. };
  9041. var getService = function() {
  9042. return MakeOutOrder;
  9043. };
  9044. $scope.tableParams = new ngTableParams({
  9045. page : 1,
  9046. count : 20,
  9047. sorting: {
  9048. date: 'desc'
  9049. }
  9050. }, {
  9051. total : 0,
  9052. counts: [5, 10, 25, 50],
  9053. getData : function($defer, params) {
  9054. $scope.loading = true;
  9055. var pageParams = params.url();
  9056. pageParams.searchFilter = {};
  9057. pageParams.searchFilter.keyword = $scope.keyword;
  9058. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9059. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9060. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9061. $scope.loading = false;
  9062. if(page) {
  9063. params.total(page.totalElement);
  9064. $defer.resolve(page.content);
  9065. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  9066. }
  9067. }, function(response){
  9068. $scope.loading = false;
  9069. toaster.pop('error', '数据加载失败', response.data);
  9070. });
  9071. }
  9072. });
  9073. $scope.openDatePicker = function($event, item, openParam) {
  9074. $event.preventDefault();
  9075. $event.stopPropagation();
  9076. item[openParam] = !item[openParam];
  9077. };
  9078. // 打开回复
  9079. $scope.openReply = function(change) {
  9080. change.$editing = true;
  9081. };
  9082. // 关闭回复
  9083. $scope.closeReply = function(change) {
  9084. change.$editing = false;
  9085. }
  9086. // 确定回复
  9087. $scope.onReplyClick = function(change) {
  9088. if(change.$agreed) {
  9089. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  9090. $scope.loading = true;
  9091. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  9092. $scope.loading = false;
  9093. toaster.pop('info', '提示', '回复成功');
  9094. $scope.tableParams.reload();
  9095. }, function(response){
  9096. $scope.loading = false;
  9097. toaster.pop('error', '回复失败', response.data);
  9098. });
  9099. }
  9100. };
  9101. // 搜索框回车
  9102. $scope.onSearch = function() {
  9103. $scope.tableParams.page(1);
  9104. $scope.tableParams.reload();
  9105. };
  9106. // 选择查找日期
  9107. $scope.onDateCondition = function(){
  9108. $scope.tableParams.page(1);
  9109. $scope.tableParams.reload();
  9110. };
  9111. }]);
  9112. /**
  9113. * 委外加工详细
  9114. */
  9115. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  9116. BaseService.scrollBackToTop();
  9117. var loadData = function() {
  9118. MakeOutOrder.get({id: $stateParams.id}, function(data){
  9119. $scope.order = data;
  9120. var sum = $scope.order.qty * $scope.order.price;
  9121. $scope.order.total = sum;
  9122. $scope.loading = false;
  9123. });
  9124. };
  9125. loadData();
  9126. // 获取回复记录
  9127. $scope.getReply = function(item) {
  9128. if(!item.replies) {
  9129. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  9130. item.replies = replies;
  9131. });
  9132. }
  9133. };
  9134. $scope.openDatePicker = function($event, item, openParam) {
  9135. $event.preventDefault();
  9136. $event.stopPropagation();
  9137. item[openParam] = !item[openParam];
  9138. };
  9139. // 点击回复
  9140. $scope.onReplyClick = function(order, inverse) {
  9141. if(order.reply) {
  9142. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  9143. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  9144. return;
  9145. }
  9146. var reply = angular.copy(order.reply);
  9147. if(reply.delivery) {
  9148. if(typeof reply.delivery == 'object')
  9149. reply.delivery = reply.delivery.getTime();
  9150. } else {
  9151. reply.delivery = order.delivery;
  9152. }
  9153. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  9154. $scope.loading = true;
  9155. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  9156. $scope.loading = false;
  9157. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  9158. loadData();
  9159. }, function(response){
  9160. $scope.loading = false;
  9161. toaster.pop('error', '回复失败', response.data);
  9162. });
  9163. }
  9164. };
  9165. // 打开回复
  9166. $scope.openReply = function(order) {
  9167. if(!order.reply) {
  9168. order.reply = {
  9169. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  9170. delivery: order.delivery
  9171. }
  9172. }
  9173. order.$editing = true;
  9174. };
  9175. // 关闭回复
  9176. $scope.closeReply = function(order) {
  9177. order.$editing = false;
  9178. }
  9179. // 自己委外加工订单
  9180. $scope.print = function(order) {
  9181. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  9182. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  9183. };
  9184. }]);
  9185. /**
  9186. * 计算时间差
  9187. */
  9188. app.filter('timespan', function(){
  9189. return function(time) {
  9190. if(time == null)
  9191. return '9999年';
  9192. var now = new Date().getTime(), span = time - now,
  9193. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  9194. m = Math.ceil(span/60000);
  9195. if(span < 0)
  9196. return '1天';
  9197. if(d > 0)
  9198. return d+1 + '天';
  9199. if(h > 0)
  9200. return h + '小时';
  9201. if(m > 0)
  9202. return m + '分钟';
  9203. return '0天';
  9204. };
  9205. });
  9206. app.filter('firstchar', function(){
  9207. return function(str) {
  9208. if(str == null)
  9209. return null;
  9210. return str.substring(0, 1);
  9211. };
  9212. });
  9213. app.filter('summary', function(){
  9214. return function(data, field) {
  9215. var sum = 0;
  9216. if (data) {
  9217. angular.forEach(data, function(d){
  9218. sum += d[field];
  9219. });
  9220. }
  9221. return sum;
  9222. };
  9223. });
  9224. /**
  9225. * 搜索框,回车触发
  9226. */
  9227. app.directive('ngSearch', ['$parse', function($parse) {
  9228. return {
  9229. require : '?ngModel',
  9230. restrict : 'A',
  9231. link : function(scope, element, attrs, ngModel) {
  9232. var searchFn = $parse(attrs.ngSearch);
  9233. element.bind('keypress', function(event) {
  9234. if (event.keyCode == '13') {
  9235. event.preventDefault();
  9236. event.stopPropagation();
  9237. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  9238. }
  9239. });
  9240. }
  9241. };
  9242. }]);
  9243. /**
  9244. * 状态码 -> 描述
  9245. */
  9246. app.filter('status', function(){
  9247. return function(data) {
  9248. var statusConfig = {
  9249. '101': '已提交',
  9250. '102': '已审核',
  9251. '103': '未通过',
  9252. '200': '未回复',
  9253. '201': '已回复',
  9254. '313': '已激活',
  9255. '316': '已过账',
  9256. '311': '申请中',
  9257. '312': '未激活'
  9258. };
  9259. return statusConfig[data];
  9260. }
  9261. });
  9262. //弹出问题反馈模态框
  9263. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  9264. //获取当前用户
  9265. AuthenticationService.getAuthentication().success(function(data) {
  9266. $scope.user = data;
  9267. });
  9268. $scope.showModal = function(){
  9269. var modalInstance = $modal.open({
  9270. animation: true,
  9271. templateUrl: 'static/tpl/serve/feedback.html',
  9272. controller: 'FeedbackCtrl',
  9273. resolve: {
  9274. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  9275. }
  9276. });
  9277. modalInstance.result.then(function(){
  9278. }, function(){
  9279. })
  9280. }
  9281. }]);
  9282. /*
  9283. * 提交我的反馈
  9284. */
  9285. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  9286. $scope.isPublic = 1; //默认公开
  9287. $scope.classId = 1; //默认类别
  9288. $scope.user = user;
  9289. $scope.ok = function(){
  9290. if(!$scope.user){ //用户未登录
  9291. $scope.uu = null;
  9292. }else{ //用户已登录
  9293. $scope.uu = $scope.user.userUU;
  9294. }
  9295. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  9296. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  9297. function(data){
  9298. toaster.pop('success', '成功', '您的问题反馈成功!');
  9299. $scope.cancel();
  9300. }, function(response){
  9301. toaster.pop('error', '错误', response.data);
  9302. });
  9303. }
  9304. $scope.cancel = function () {
  9305. $modalInstance.dismiss();
  9306. };
  9307. }]);
  9308. //“我的问题反馈”跳转控制
  9309. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function($scope, AuthenticationService, toaster, $rootScope){
  9310. $scope.myFeedback = function(){
  9311. AuthenticationService.getAuthentication().success(function(data){
  9312. $scope.user = data;
  9313. if(!$scope.user){
  9314. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  9315. return false;
  9316. }else{
  9317. window.location.href = "./serve#/question/myFeedback";
  9318. }
  9319. });
  9320. };
  9321. $scope.setActive = function(active) {
  9322. $rootScope.active = active;
  9323. }
  9324. }]);
  9325. //客户服务
  9326. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  9327. Vendor.getServe(function(datas){
  9328. $scope.vendors = datas;
  9329. // 自动跳转
  9330. if(datas && datas.length == 1)
  9331. $scope.redirect(datas[0]);
  9332. });
  9333. $scope.redirect = function(vendor) {
  9334. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  9335. };
  9336. }]);
  9337. /**
  9338. * 物料资料
  9339. */
  9340. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$rootScope', '$modal', 'Products', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout, $rootScope, $modal, Products) {
  9341. BaseService.scrollBackToTop();
  9342. $scope.active = 'all';
  9343. $scope.agreedText = '全部';
  9344. $scope.dateZoneText = '一个月内';
  9345. $scope.condition = {dateZone: 1};
  9346. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9347. $scope.changeAgreed = function(agreed) {
  9348. $scope.condition.agreed = agreed;
  9349. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9350. $scope.condition.$agreedOpen = false;
  9351. };
  9352. $scope.changeDateZone = function(zone) {
  9353. $scope.condition.dateZone = zone;
  9354. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9355. $scope.condition.$dateZoneOpen = false;
  9356. getDateCondition(zone, $scope.condition);
  9357. $scope.tableParams.reload();
  9358. };
  9359. $scope.setActive = function(state) {
  9360. if($scope.active != state) {
  9361. $scope.active = state;
  9362. if($scope.tableParams.page() == 1)
  9363. $scope.tableParams.reload();
  9364. else
  9365. $scope.tableParams.page(1);
  9366. }
  9367. };
  9368. var getService = function() {
  9369. return GetProductInfo;
  9370. };
  9371. $scope.tableParams = new ngTableParams({
  9372. page : 1,
  9373. count : 20,
  9374. sorting: {
  9375. }
  9376. }, {
  9377. total : 0,
  9378. counts: [5, 10, 25, 50],
  9379. getData : function($defer, params) {
  9380. $scope.loading = true;
  9381. var pageParams = params.url();
  9382. pageParams.keyword = $scope.keyword;
  9383. pageParams.searchFilter = $scope.searchFilter;
  9384. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9385. $scope.loading = false;
  9386. if(page) {
  9387. params.total(page.totalElement);
  9388. $defer.resolve(page.content);
  9389. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9390. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  9391. }
  9392. }, function(response) {
  9393. $scope.loading = false;
  9394. toaster.pop('error', '数据加载失败', response.data);
  9395. });
  9396. }
  9397. });
  9398. // 搜索框回车
  9399. $scope.onSearch = function() {
  9400. $scope.tableParams.page(1);
  9401. $scope.tableParams.reload();
  9402. };
  9403. //删除
  9404. $scope.deleteById = function(id) {
  9405. GetProductInfo.deleteById({id: id}, function(data) {
  9406. if(data.error) {
  9407. toaster.pop("error", "提示", data.error);
  9408. } else {
  9409. toaster.pop("success", "提示", "删除成功");
  9410. $timeout(function() {
  9411. $scope.tableParams.reload();
  9412. }, 500);
  9413. }
  9414. }), function(response) {
  9415. toaster.pop("error", "删除失败", response.data);
  9416. };
  9417. };
  9418. $rootScope.isProductEdit = false;
  9419. // 编辑
  9420. $scope.isProductEdit = function () {
  9421. $rootScope.isProductEdit = true;
  9422. };
  9423. // 一键开启关闭
  9424. $scope.toggle = function(status) {
  9425. GetProductInfo.toggle({status: status}, {}, function(data) {
  9426. toaster.pop('success', '提示', '操作成功');
  9427. $scope.tableParams.reload();
  9428. }, function(response) {
  9429. toaster.pop('error', '提示', response.data);
  9430. })
  9431. }
  9432. var products = [];
  9433. $scope.checks = {
  9434. checked: false
  9435. };
  9436. // 全选框
  9437. $scope.checkAll = function() {
  9438. products = [];// 每次选择时先清空,防止重复
  9439. angular.forEach($scope.tableParams.data, function(product) {
  9440. if(product.cmpUuId == null) {
  9441. product.checked = $scope.checks.checked;
  9442. }
  9443. });
  9444. };
  9445. // 单选
  9446. $scope.checkOne = function(product) {
  9447. products = [];// 每次选择时先清空,防止重复
  9448. var result = true;
  9449. angular.forEach($scope.tableParams.data, function(item) {
  9450. if(item.$selected != true){
  9451. result = false;
  9452. return;
  9453. }
  9454. });
  9455. $scope.checks.checked = result;
  9456. var checked = true;
  9457. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  9458. if (!message.checked) {
  9459. checked = false;
  9460. }
  9461. });
  9462. $scope.checks.checked = checked;
  9463. };
  9464. $scope.updateByBatch = function(updatetype) {
  9465. var modalInstance = $modal.open({
  9466. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  9467. controller: 'UpdateByBatchCtrl',
  9468. size: 'md',
  9469. resolve: {
  9470. updatetype: function() {
  9471. return updatetype;
  9472. },
  9473. active: function() {
  9474. return $scope.active;
  9475. },
  9476. type: function() {
  9477. return 'sale';
  9478. }
  9479. }
  9480. });
  9481. modalInstance.result.then(function(data) {
  9482. toaster.pop('success', '提示', data.success);
  9483. $scope.tableParams.reload();
  9484. }, function(){
  9485. });
  9486. }
  9487. // 一键匹配
  9488. $scope.matchall = function() {
  9489. $scope.loading = true;
  9490. $scope.type = "sale";
  9491. Products.matchbytype({type: $scope.type}, {}, function(data) {
  9492. toaster.pop('info', '提示', '匹配成功'+data.size+'个标准器件');
  9493. window.location.href = "#/sale/productmatches";
  9494. }, function(response) {
  9495. toaster.pop('error', '提示', response.data);
  9496. });
  9497. }
  9498. }]);
  9499. /**
  9500. * 批量修改
  9501. */
  9502. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  9503. $scope.updatetype = updatetype;
  9504. $scope.changed = false;
  9505. $scope.parameter = {
  9506. updatetype: updatetype,
  9507. standard: active,
  9508. type: type,
  9509. oldvalue: null,
  9510. newvalue: null
  9511. };
  9512. $scope.cancel = function() {
  9513. $modalInstance.dismiss();
  9514. }
  9515. if(updatetype === '品牌')
  9516. var loadData = function() {
  9517. Products.getBrands({parameter: $scope.parameter}, {}, function(data) {
  9518. $scope.products = data;
  9519. }, function(response) {
  9520. toaster.pop('error', '提示', response.data);
  9521. })
  9522. }
  9523. if(updatetype === '名称(类目)')
  9524. var loadData = function() {
  9525. Products.getTitles({parameter: $scope.parameter}, {}, function(data) {
  9526. $scope.products = data;
  9527. }, function(response) {
  9528. toaster.pop('error', '提示', response.data);
  9529. })
  9530. }
  9531. loadData();
  9532. $scope.okay = function() {
  9533. Products.alterByBatch({parameter: $scope.parameter}, {}, function(data) {
  9534. $modalInstance.close(data);
  9535. }, function(response) {
  9536. toaster.pop('error', '提示', response.data);
  9537. });
  9538. }
  9539. }]);
  9540. /**
  9541. * 物料批量上传
  9542. */
  9543. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  9544. BaseService.scrollBackToTop();
  9545. $scope.$watch('myFiles', function(){
  9546. if($scope.myFiles) {
  9547. var file = $scope.myFiles[0];
  9548. $scope.fileName = file.name;
  9549. }
  9550. })
  9551. // 通过excel批量上传物料
  9552. $scope.upload = function() {
  9553. $scope.loading = true;
  9554. if($scope.myFiles) {
  9555. var file = $scope.myFiles[0];
  9556. if(file.name) {
  9557. $upload.upload({
  9558. url: 'product/baseInfo/release/excel',
  9559. file: file,
  9560. method: 'POST'
  9561. }).success(function(data) {
  9562. $scope.loading = false;
  9563. if(data.error) {
  9564. toaster.pop('error', '提示', data.error);
  9565. }
  9566. $scope.result = data;
  9567. $scope.products = $scope.result.products;
  9568. $scope.success = $scope.result.success;
  9569. $scope.total = $scope.result.total;
  9570. $scope.alters = $scope.result.alters;
  9571. $scope.infos = $scope.result.infos;
  9572. $scope.myFiles[0] = "";
  9573. $scope.fileName = "";
  9574. }).error(function(response) {
  9575. $scope.loading = false;
  9576. toaster.pop('error', response.data || response);
  9577. });
  9578. } else {
  9579. $scope.loading = false;
  9580. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  9581. }
  9582. } else {
  9583. $scope.loading = false;
  9584. }
  9585. };
  9586. // 查看范例
  9587. $scope.showImg = function() {
  9588. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  9589. box.show();
  9590. box.find('img').attr('src', src);
  9591. box.find('a').click(function(){
  9592. box.hide();
  9593. });
  9594. box.dblclick(function(){
  9595. box.hide();
  9596. });
  9597. };
  9598. // 下载模板
  9599. $scope.download = function() {
  9600. window.location.href = 'product/baseInfo/upload/template';
  9601. };
  9602. }]);
  9603. /**
  9604. * 物料详情
  9605. */
  9606. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$rootScope', '$modal', 'Products', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $rootScope, $modal, Products) {
  9607. BaseService.scrollBackToTop();
  9608. // 录入人
  9609. AuthenticationService.getAuthentication().success(function(data) {
  9610. $scope.loading = false;
  9611. $scope.user = data;
  9612. });
  9613. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9614. var loadData = function() {
  9615. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  9616. if(data.attach) {
  9617. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  9618. // 查看范例
  9619. $scope.showImg = function() {
  9620. var src = data.url, box = $('#image-box');
  9621. box.show();
  9622. box.find('img').attr('src', src);
  9623. box.find('a').click(function(){
  9624. box.hide();
  9625. });
  9626. box.dblclick(function(){
  9627. box.hide();
  9628. });
  9629. };
  9630. })
  9631. }
  9632. $scope.prodInfo = data;
  9633. if($scope.prodInfo.standard != 1 ) {// 非标准的先进行匹配
  9634. Products.matchone({id: $scope.prodInfo.id}, {}, function(data) {
  9635. $scope.matchresults = data;
  9636. }, function(response) {
  9637. toaster.pop('error', '提示', response.data);
  9638. });
  9639. }
  9640. if ($rootScope.isProductEdit) { // 是否点击编辑
  9641. $scope.prodInfo.$editing = true;
  9642. } else {
  9643. $scope.prodInfo.$editing = false;
  9644. }
  9645. $rootScope.isProductEdit = false; // 第一次进入判断,后续不用
  9646. $scope.loading = false;
  9647. });
  9648. };
  9649. loadData();
  9650. //更新为标准器件
  9651. $scope.updateone = function(id) {
  9652. Products.updateone({id: id}, {}, function(data) {
  9653. if(data.success) {
  9654. toaster.pop('success', '提示', data.success);
  9655. }
  9656. }, function(response) {
  9657. toaster.pop('error', '提示', response.data);
  9658. });
  9659. }
  9660. // 选择类目
  9661. $scope.selectKind = function(cmpcode) {
  9662. if(cmpcode == null) {
  9663. $modal.open({
  9664. animation: true,
  9665. size: 'lg',
  9666. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  9667. controller: 'KindChooseCtrl',
  9668. }).result.then(function(data){
  9669. $scope.kindId = data;
  9670. var modalInstance = $modal.open({
  9671. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  9672. controller: 'FindComponentCtrl',
  9673. size: 'lg',
  9674. resolve: {
  9675. KindId: function() {
  9676. return $scope.kindId;
  9677. }
  9678. }
  9679. });
  9680. modalInstance.result.then(function(data) {
  9681. $scope.prodInfo.cmpUuId = data.uuid;
  9682. $scope.prodInfo.pcmpcode = data.code;
  9683. $scope.prodInfo.pbranden = data.brand.nameEn;
  9684. $scope.prodInfo.pbrand = data.brand.nameCn;
  9685. }, function(){
  9686. });
  9687. }, function(){
  9688. });
  9689. }
  9690. };
  9691. $scope.isShow = true;
  9692. // 更新
  9693. $scope.update = function() {
  9694. $scope.prodInfo.$editing = true;
  9695. $scope.isShow = true;
  9696. };
  9697. // 取消
  9698. $scope.cancel = function() {
  9699. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  9700. $scope.prodInfo = data;
  9701. $scope.prodInfo.$editing = false;
  9702. $scope.isShow = false;
  9703. $scope.loading = false;
  9704. });
  9705. };
  9706. // 删除
  9707. $scope.clearfile = function() {
  9708. $scope.myFiles = null;
  9709. $scope.previewShow = false;
  9710. }
  9711. //删除
  9712. $scope.deleteById = function(id) {
  9713. GetProductInfo.deleteById({id: id}, function(data) {
  9714. if(data.error) {
  9715. toaster.pop("error", "提示", data.error);
  9716. } else {
  9717. toaster.pop("success", "提示", "删除成功");
  9718. window.location.href = "#/sale/prodList";
  9719. }
  9720. }), function(response) {
  9721. toaster.pop("error", "删除失败", response.data);
  9722. };
  9723. };
  9724. $scope.submit = function(prodInfo) {
  9725. $scope.prodInfo.isSale = 1;
  9726. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  9727. $upload.upload({
  9728. url: 'product/baseInfo/updateProdInfo',
  9729. file: file,
  9730. method: 'POST',
  9731. data: {
  9732. prodInfo: $scope.prodInfo
  9733. },
  9734. }).success(function(data) {
  9735. if(data.success) {
  9736. toaster.pop('success', '提示', data.success);
  9737. $rootScope.isProductEdit = false;
  9738. loadData();
  9739. }
  9740. if(data.error) {
  9741. toaster.pop('error', '提示', data.error);
  9742. }
  9743. }).error(function(data) {
  9744. $scope.loadingShow = false;
  9745. toaster.pop('error', '操作失败', data.error);
  9746. });
  9747. }
  9748. $scope.previewShow = false;
  9749. $scope.pdfShow = false;
  9750. $scope.noneFileShow = true;
  9751. $scope.$watch('myFiles', function(){
  9752. if($scope.myFiles) {
  9753. $scope.noneFileShow = false;
  9754. var file = $scope.myFiles[0];
  9755. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  9756. $scope.pdfShow = true;
  9757. $scope.previewShow = false;
  9758. $scope.imgPreviewName = file.name;
  9759. } else{
  9760. if (typeof(Worker) !== "undefined") {//支持HTML5
  9761. $scope.imgPreview = getObjectURL(file);
  9762. $scope.imgPreviewName = file.name;
  9763. } else{//不支持HTML5
  9764. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  9765. $scope.imgPreviewName = file.name;
  9766. }
  9767. $scope.previewShow = true;
  9768. $scope.pdfShow = false;
  9769. }
  9770. } else {
  9771. $scope.noneFileShow = true;
  9772. $scope.previewShow = false;
  9773. $scope.pdfShow = false;
  9774. }
  9775. });
  9776. //建立一个可存取到该file的url
  9777. var getObjectURL = function(file) {
  9778. var url = null ;
  9779. if (window.createObjectURL!=undefined) { // basic
  9780. url = window.createObjectURL(file) ;
  9781. } else if (window.URL!=undefined) { // mozilla(firefox)
  9782. url = window.URL.createObjectURL(file) ;
  9783. } else if (window.webkitURL!=undefined) { // webkit or chrome
  9784. url = window.webkitURL.createObjectURL(file) ;
  9785. }
  9786. return url ;
  9787. };
  9788. }]);
  9789. /**
  9790. * 新增物料(销售)
  9791. */
  9792. 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) {
  9793. BaseService.scrollBackToTop();
  9794. // 录入人
  9795. AuthenticationService.getAuthentication().success(function(data) {
  9796. $scope.loading = false;
  9797. $scope.user = data;
  9798. });
  9799. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9800. $scope.prodInfo = {};
  9801. // 选择类目
  9802. $scope.selectKind = function() {
  9803. $modal.open({
  9804. animation: true,
  9805. size: 'lg',
  9806. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  9807. controller: 'KindChooseCtrl',
  9808. }).result.then(function(data){
  9809. $scope.kindId = data;
  9810. var modalInstance = $modal.open({
  9811. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  9812. controller: 'FindComponentCtrl',
  9813. size: 'lg',
  9814. resolve: {
  9815. KindId: function() {
  9816. return $scope.kindId;
  9817. }
  9818. }
  9819. });
  9820. modalInstance.result.then(function(data) {
  9821. $scope.prodInfo.cmpUuId = data.uuid;
  9822. $scope.prodInfo.pcmpcode = data.code;
  9823. $scope.prodInfo.pbranden = data.brand.nameEn;
  9824. $scope.prodInfo.pbrand = data.brand.nameCn;
  9825. }, function(){
  9826. });
  9827. }, function(){
  9828. });
  9829. };
  9830. // 删除
  9831. $scope.clearfile = function() {
  9832. $scope.myFiles = null;
  9833. $scope.previewShow = false;
  9834. }
  9835. //提交
  9836. $scope.submit = function(prodInfo){
  9837. $scope.prodInfo.isSale = 1;
  9838. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  9839. $upload.upload({
  9840. url: 'product/baseInfo/addNewProduct',
  9841. file: file,
  9842. method: 'POST',
  9843. data: {
  9844. prodInfo: prodInfo
  9845. },
  9846. }).success(function(data) {
  9847. if(data.success) {
  9848. toaster.pop('success', '提示', data.success);
  9849. $timeout(function() {
  9850. //提交后跳转到详情页面,防止重复提交
  9851. window.location.href="#/sale/prodList/"+data.id;
  9852. }, 500);
  9853. }
  9854. if(data.error) {
  9855. toaster.pop('error', '提示', data.error);
  9856. $timeout(function() {
  9857. //提交后跳转到详情页面,防止重复提交
  9858. window.location.href="#/sale/prodList/"+data.id;
  9859. }, 500);
  9860. }
  9861. }).error(function(data) {
  9862. $scope.loadingShow = false;
  9863. toaster.pop('error', '操作失败', data.error);
  9864. });
  9865. };
  9866. $scope.previewShow = false;
  9867. $scope.pdfShow = false;
  9868. $scope.noneFileShow = true;
  9869. $scope.$watch('myFiles', function(){
  9870. if($scope.myFiles) {
  9871. $scope.noneFileShow = false;
  9872. var file = $scope.myFiles[0];
  9873. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  9874. $scope.pdfShow = true;
  9875. $scope.previewShow = false;
  9876. $scope.imgPreviewName = file.name;
  9877. } else{
  9878. if (typeof(Worker) !== "undefined") {//支持HTML5
  9879. $scope.imgPreview = getObjectURL(file);
  9880. $scope.imgPreviewName = file.name;
  9881. } else{//不支持HTML5
  9882. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  9883. $scope.imgPreviewName = file.name;
  9884. }
  9885. $scope.previewShow = true;
  9886. $scope.pdfShow = false;
  9887. }
  9888. } else {
  9889. $scope.noneFileShow = true;
  9890. $scope.previewShow = false;
  9891. $scope.pdfShow = false;
  9892. }
  9893. });
  9894. //建立一个可存取到该file的url
  9895. var getObjectURL = function(file) {
  9896. var url = null ;
  9897. if (window.createObjectURL!=undefined) { // basic
  9898. url = window.createObjectURL(file) ;
  9899. } else if (window.URL!=undefined) { // mozilla(firefox)
  9900. url = window.URL.createObjectURL(file) ;
  9901. } else if (window.webkitURL!=undefined) { // webkit or chrome
  9902. url = window.webkitURL.createObjectURL(file) ;
  9903. }
  9904. return url ;
  9905. };
  9906. // 取消
  9907. $scope.cancel = function(){
  9908. $scope.prodInfo = angular.copy($scope.prodInfo);
  9909. };
  9910. }]);
  9911. /**
  9912. * 类目选择模态框
  9913. */
  9914. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  9915. $scope.kindId = null;
  9916. $scope.kinds = [[], [], [], []];
  9917. // 获取子类目
  9918. var getChildren = function(pid, deep) {
  9919. KindAPI.getChildren({parentId: pid}, function(data) {
  9920. $scope.kinds[deep] = data;
  9921. }, function(response) {
  9922. toaster.pop('error', '获取子类目失败', response.data);
  9923. });
  9924. };
  9925. // 改变节点选中状态
  9926. var changeStatus = function(item, deep) {
  9927. var kindId = null, level = 0;
  9928. angular.forEach($scope.kinds, function(ks, i) {
  9929. if(i > deep) {
  9930. $scope.kinds[i] = [];
  9931. } else {
  9932. angular.forEach(ks, function(k, j) {
  9933. if(i == deep) {
  9934. if(k.id == item.id) {
  9935. $scope.kinds[i][j].$active = true;
  9936. kindId = k.id;
  9937. } else {
  9938. k.$active = null;
  9939. }
  9940. }
  9941. });
  9942. }
  9943. });
  9944. // 选择的节点
  9945. $scope.kindId = kindId;
  9946. $scope.active = item;
  9947. // 当前可操作的层级
  9948. if(deep < 3) {
  9949. $scope.activeDeep = deep + 1;
  9950. }
  9951. };
  9952. // 节点点击后获取子类目,节点被选中
  9953. $scope.onItemClick = function(item, deep) {
  9954. changeStatus(item, deep);
  9955. if (!item.isLeaf) {
  9956. getChildren(item.id, deep + 1);
  9957. }
  9958. };
  9959. // 重新加载数据
  9960. function reload(deep) {
  9961. var pid;
  9962. if(deep) {
  9963. pid = $scope.actives[deep - 1].id;
  9964. } else {
  9965. pid = 0;
  9966. deep = 0;
  9967. }
  9968. getChildren(pid, deep);
  9969. }
  9970. // 初始加载数据,获取第一层的类目
  9971. if($scope.actives) {
  9972. angular.forEach($scope.actives, function(v, k) {
  9973. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  9974. $scope.kinds[k] = data;
  9975. angular.forEach($scope.kinds[k], function(kind, i){
  9976. if(kind.id == v.id) {
  9977. $scope.kinds[k][i].$active = true;
  9978. $scope.actives[k] = $scope.kinds[k][i];
  9979. }
  9980. })
  9981. }, function(response) {
  9982. toaster.pop('error', '获取子类目失败', response.data);
  9983. });
  9984. });
  9985. } else {
  9986. reload();
  9987. }
  9988. // 取消
  9989. $scope.cancel = function() {
  9990. $modalInstance.dismiss();
  9991. };
  9992. // 确认选择
  9993. $scope.check = function() {
  9994. $modalInstance.close($scope.kindId);
  9995. };
  9996. }]);
  9997. /**
  9998. * 器件筛选
  9999. */
  10000. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  10001. //状态
  10002. $scope.setActive = function (state){
  10003. if($scope.active != state) {
  10004. $scope.active = state;
  10005. if($scope.tableParams.page() == 1)
  10006. $scope.tableParams.reload();
  10007. else
  10008. $scope.tableParams.page(1);
  10009. }
  10010. };
  10011. $scope.tableParams = new ngTableParams({
  10012. page : 1,
  10013. count : 20
  10014. }, {
  10015. total : 0,
  10016. counts: [5, 10, 25, 50],
  10017. getData : function($defer, params) {
  10018. $scope.loading = true;
  10019. var pageParams = params.url();
  10020. pageParams.keyword = $scope.keyword;
  10021. pageParams.kindId = KindId;
  10022. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  10023. $scope.loading = false;
  10024. if(page) {
  10025. params.total(page.totalElement);
  10026. $defer.resolve(page.content);
  10027. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10028. }
  10029. }, function(response){
  10030. $scope.loading = false;
  10031. toaster.pop('error', '数据加载失败', response.data);
  10032. });
  10033. }
  10034. });
  10035. // 取消
  10036. $scope.cancel = function() {
  10037. $modalInstance.dismiss();
  10038. };
  10039. // 选择
  10040. $scope.check = function(data){
  10041. $modalInstance.close(data);
  10042. };
  10043. // 搜索框回车
  10044. $scope.onSearch = function() {
  10045. $scope.tableParams.page(1);
  10046. $scope.tableParams.reload();
  10047. };
  10048. }]);
  10049. /**
  10050. * 企业列表
  10051. */
  10052. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  10053. BaseService.scrollBackToTop();
  10054. $scope.active = 'all';
  10055. $scope.agreedText = '全部';
  10056. $scope.dateZoneText = '一个月内';
  10057. $scope.condition = {dateZone: 1};
  10058. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10059. $scope.changeAgreed = function(agreed) {
  10060. $scope.condition.agreed = agreed;
  10061. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  10062. $scope.condition.$agreedOpen = false;
  10063. };
  10064. $scope.changeDateZone = function(zone) {
  10065. $scope.condition.dateZone = zone;
  10066. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  10067. $scope.condition.$dateZoneOpen = false;
  10068. getDateCondition(zone, $scope.condition);
  10069. $scope.tableParams.reload();
  10070. };
  10071. $scope.setActive = function(state) {
  10072. if($scope.active != state) {
  10073. $scope.active = state;
  10074. if($scope.tableParams.page() == 1)
  10075. $scope.tableParams.reload();
  10076. else
  10077. $scope.tableParams.page(1);
  10078. }
  10079. };
  10080. var getService = function() {
  10081. return getAccountUserSpace;
  10082. };
  10083. $scope.tableParams = new ngTableParams({
  10084. page : 1,
  10085. count : 20,
  10086. sorting: {
  10087. }
  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.keyword = $scope.keyword;
  10095. $scope.tip = $scope.keyword;
  10096. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  10097. $scope.loading = false;
  10098. if(page) {
  10099. params.total(page.totalElement);
  10100. $defer.resolve(page.content);
  10101. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10102. }
  10103. }, function(response) {
  10104. $scope.loading = false;
  10105. toaster.pop('error', '数据加载失败', response.data);
  10106. });
  10107. }
  10108. });
  10109. // 搜索框回车
  10110. $scope.onSearch = function() {
  10111. $scope.tableParams.page(1);
  10112. $scope.tableParams.reload();
  10113. };
  10114. // 添加合作关系
  10115. $scope.addPartner = function(name, businessCode) {
  10116. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  10117. if(data.success) {
  10118. toaster.pop("success", '添加成功', data.success);
  10119. $scope.tableParams.reload();
  10120. }
  10121. if(data.error) {
  10122. toaster.pop("error", '添加失败', data.error);
  10123. }
  10124. }, function(response) {
  10125. toaster.pop('error','失败',response.data);
  10126. });
  10127. }
  10128. $scope.status = 'enList';
  10129. }]);
  10130. /**
  10131. * 新增采购单
  10132. */
  10133. 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) {
  10134. BaseService.scrollBackToTop();
  10135. // 每次进入时先清除掉rootScope下的venuu
  10136. $rootScope.venduu = null;
  10137. // 获取收货地址列表
  10138. ShipAddress.shipAddList({}, function(data) {
  10139. $scope.ships = data;
  10140. $scope.order.shipadd = $scope.ships[0];
  10141. });
  10142. // 获取地址信息
  10143. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10144. }).then(function(response) {
  10145. $scope.provinces = response.data;
  10146. });
  10147. $scope.order = {
  10148. date : new Date(),
  10149. cust : {
  10150. uu : '',
  10151. },
  10152. custUser : {
  10153. },
  10154. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  10155. orderItems : {
  10156. product : {},
  10157. },
  10158. rate: 17
  10159. };
  10160. //商品信息
  10161. $scope.order.orderItems = [];
  10162. var item = {
  10163. code: null,
  10164. title: null,
  10165. spec: null,
  10166. unit: null,
  10167. qty: null,
  10168. price: null,
  10169. remark: null,
  10170. delivery: null,
  10171. id: null,
  10172. };
  10173. if($rootScope.businessCode) {
  10174. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  10175. $scope.id = data.id;
  10176. $scope.order.cust.enName = data.vendorEnterprise.enName;
  10177. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  10178. $scope.order.cust.uu = data.vendorEnterprise.uu;
  10179. $scope.order.paymethods = data.paymethod;
  10180. $rootScope.venduu = data.vendorEnterprise.uu;
  10181. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10182. $scope.contacts = data;
  10183. $scope.order.vendor = $scope.contacts[0];
  10184. });
  10185. }, function(response) {
  10186. });
  10187. };
  10188. // 查找供应商
  10189. $scope.dbfindCust = function(){
  10190. var modalInstance = $modal.open({
  10191. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  10192. controller: 'DbfindVendorInfoCtrl',
  10193. size: 'lg',
  10194. resolve: {
  10195. orderItems: function() {
  10196. return $scope.order.orderItems;
  10197. }
  10198. }
  10199. });
  10200. modalInstance.result.then(function(data) {
  10201. $rootScope.venduu = data.vendorEnterprise.uu;
  10202. $scope.id = data.id;
  10203. $scope.order.cust = data.vendorEnterprise;
  10204. $scope.order.custUser = data.vendorUser;
  10205. $scope.order.payments = data.paymethod;
  10206. $scope.order.orderItems = [];
  10207. var item = {
  10208. code: null,
  10209. title: null,
  10210. spec: null,
  10211. unit: null,
  10212. qty: null,
  10213. price: null,
  10214. remark: null,
  10215. delivery: null,
  10216. };
  10217. // $scope.order.orderItems.push(item);
  10218. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10219. $scope.contacts = data;
  10220. $scope.order.vendor = $scope.contacts[0];
  10221. });
  10222. }, function(){
  10223. });
  10224. };
  10225. // 联想词 start
  10226. // 获取供应商
  10227. $scope.getSimilarVendors = function(value) {
  10228. if (value) {
  10229. return Vendor.getSimilarVendors({keyword : value}).$promise.then(function(data) {
  10230. return data.map(function(item) {
  10231. return item;
  10232. });
  10233. });
  10234. }
  10235. };
  10236. $scope.onAssociateCmpClick = function(vendor, order) {
  10237. $scope.order.cust.uu = vendor.venduu;
  10238. $scope.id = vendor.id;
  10239. $scope.order.payments = vendor.paymethod;
  10240. $rootScope.venduu = $scope.order.cust.uu;
  10241. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10242. $scope.contacts = data;
  10243. $scope.order.vendor = $scope.contacts[0];
  10244. });
  10245. }
  10246. // 联想词 end
  10247. // $scope.order.orderItems.push(item);
  10248. if($rootScope.prodId) {
  10249. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  10250. item.code = data.code;
  10251. item.title = data.title;
  10252. item.spec = data.spec;
  10253. item.unit = data.unit;
  10254. item.id = data.id;
  10255. $scope.order.orderItems.push(item);
  10256. $rootScope.prodId = null;// 清除掉prodId
  10257. }, function(response) {
  10258. });
  10259. }
  10260. //增加商品
  10261. $scope.addProduct = function(index) {
  10262. if($scope.order.orderItems[index].code == null) {
  10263. toaster.pop('info', '提示', '请先选择商品');
  10264. } else {
  10265. $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});
  10266. }
  10267. };
  10268. //删除商品
  10269. $scope.deleteProduct = function(index) {
  10270. $scope.order.orderItems.splice(index, 1);
  10271. };
  10272. // 搜索框回车
  10273. $scope.onSearch = function(keyword) {
  10274. $scope.keyword = keyword;
  10275. $scope.tableParams.page(1);
  10276. $scope.tableParams.reload();
  10277. };
  10278. $scope.tableParams = new ngTableParams({
  10279. page : 1,
  10280. count : 20
  10281. }, {
  10282. total : 0,
  10283. counts: [5, 10, 25, 50],
  10284. getData : function($defer, params) {
  10285. $scope.loading = true;
  10286. var pageParams = params.url();
  10287. pageParams.keyword = $scope.keyword;
  10288. $scope.tip = $scope.keyword;
  10289. pageParams.custUU = $scope.order.cust.uu;
  10290. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  10291. $scope.loading = false;
  10292. if(page) {
  10293. params.total(page.totalElement);
  10294. $scope.total = page.totalElement;
  10295. $defer.resolve(page.content);
  10296. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10297. }
  10298. }, function(response){
  10299. $scope.loading = false;
  10300. toaster.pop('error', '数据加载失败', response.data);
  10301. });
  10302. }
  10303. });
  10304. // 选择
  10305. $scope.check = function(data) {
  10306. $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});
  10307. };
  10308. // 导入商品信息
  10309. $scope.uplodaByBatch = function() {
  10310. var modalInstance = $modal.open({
  10311. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  10312. controller: 'PurcUploadByBatchCtrl',
  10313. size: 'lg',
  10314. resolve: {
  10315. }
  10316. });
  10317. modalInstance.result.then(function(data) {
  10318. angular.forEach(data, function(prod) {
  10319. $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});
  10320. // for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  10321. // 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) { // 如果没有填写就删除这行数据
  10322. // $scope.inquiry.inquiryItems.splice(i, 1);
  10323. // }
  10324. // }
  10325. })
  10326. }, function(){
  10327. });
  10328. }
  10329. // 监听custuu发生变化,重新加载物料信息
  10330. $scope.$watch('order.cust.uu', function(n, o) {
  10331. if(n==o) {
  10332. return;
  10333. } else {
  10334. $scope.tableParams.page(1);
  10335. $scope.tableParams.reload();
  10336. }
  10337. }, true);
  10338. // 查找客户物料
  10339. $scope.dbfindCustProd = function(index){
  10340. if($scope.order.cust.uu) {
  10341. var modalInstance = $modal.open({
  10342. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  10343. controller: 'DbfindCustProdCtrl',
  10344. size: 'lg',
  10345. resolve: {
  10346. custUU: function() {
  10347. return $scope.order.cust.uu
  10348. }
  10349. }
  10350. });
  10351. modalInstance.result.then(function(data) {
  10352. $scope.order.orderItems.push(data);
  10353. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  10354. if($scope.order.orderItems[i].code == null || i == index) {
  10355. $scope.order.orderItems.splice(i, 1);
  10356. }
  10357. }
  10358. }, function() {
  10359. });
  10360. } else {
  10361. toaster.pop('info', '提示', '请先选择供应商');
  10362. }
  10363. };
  10364. $scope.getMinDate = function(item) {
  10365. return $filter('date')(new Date, 'yyyy-MM-dd');
  10366. };
  10367. $scope.openDatePicker = function($event, openParam, index) {
  10368. $event.preventDefault();
  10369. $event.stopPropagation();
  10370. $scope.order.orderItems[index].$endDateOpen = !openParam;
  10371. };
  10372. // 添加到购物车
  10373. $scope.addToCart = function(order) {
  10374. $scope.loading = true;
  10375. $scope.order.vendusertel = order.vendor.tel;
  10376. $scope.order.venduser = order.vendor.venduser;
  10377. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  10378. $scope.order.custUU = $scope.order.cust.uu;
  10379. $scope.order.custUserUU = $scope.order.custUser.userUU;
  10380. if($scope.order.date instanceof Date) {
  10381. $scope.order.date = $scope.order.date.getTime();
  10382. }
  10383. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  10384. if($scope.order.orderItems[i].delivery instanceof Date) {
  10385. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  10386. }
  10387. if($scope.order.currency != 'RMB') {
  10388. $scope.order.orderItems[i].rate = 0;
  10389. }
  10390. }
  10391. addtoCart.save({}, $scope.order, function(data){
  10392. $scope.loading = false;
  10393. toaster.pop('success', '成功', '保存成功');
  10394. window.location.hash = '#/purc/cart/'+data.id;
  10395. }, function(response){
  10396. $scope.loading = false;
  10397. toaster.pop('error', '保存失败', response.data);
  10398. });
  10399. };
  10400. // 立即购买
  10401. $scope.addToOrder = function(order) {
  10402. $scope.loading = true;
  10403. $scope.order.vendusertel = order.vendor.tel;
  10404. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  10405. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  10406. $scope.order.custUU = $scope.order.cust.uu;
  10407. $scope.order.custUserUU = $scope.order.custUser.userUU;
  10408. if($scope.order.date instanceof Date) {
  10409. $scope.order.date = $scope.order.date.getTime();
  10410. }
  10411. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  10412. if($scope.order.orderItems[i].delivery instanceof Date) {
  10413. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  10414. }
  10415. if($scope.order.currency != 'RMB') {
  10416. $scope.order.orderItems[i].rate = 0;
  10417. }
  10418. }
  10419. newPurcOrder.save({}, $scope.order, function(data){
  10420. $scope.loading = false;
  10421. toaster.pop('success', '成功', '保存成功');
  10422. window.location.hash = '#/purc/order/'+data.id;
  10423. }, function(response){
  10424. $scope.loading = false;
  10425. toaster.pop('error', '保存失败', response.data);
  10426. });
  10427. };
  10428. // 新增收货地址保存
  10429. $scope.saveShipAddress = function(ship) {
  10430. ship.address = ship.province + ship.city + ship.district;
  10431. ShipAddress.saveAddress( {}, ship, function(data) {
  10432. if(data.success) {
  10433. ShipAddress.shipAddList({}, function(data) {
  10434. $scope.ships = data;
  10435. $scope.order.shipadd = $scope.ships[0];
  10436. });
  10437. toaster.pop('success', '提示', data.success);
  10438. }
  10439. if(data.error) {
  10440. toaster.pop('error', '提示', data.error);
  10441. }
  10442. });
  10443. }
  10444. // 新增供应商联系人
  10445. $scope.addContact = function(uu) {
  10446. var modalInstance = $modal.open({
  10447. animation: true,
  10448. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10449. controller: 'AddContacCtrl',
  10450. resolve: {
  10451. }
  10452. });
  10453. modalInstance.result.then(function(data) {
  10454. $scope.contact = data;
  10455. $scope.contact.venduu = uu;
  10456. Vendor.saveContact({}, $scope.contact, function(data) {
  10457. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10458. $scope.contacts = data;
  10459. $scope.order.vendor = $scope.contacts[0];
  10460. });
  10461. toaster.pop('success', '提示', '联系人保存成功');
  10462. }, function(response) {
  10463. toaster.pop('error', '失败', response.data);
  10464. });
  10465. });
  10466. }
  10467. }]);
  10468. /**
  10469. * 采购批量导入
  10470. */
  10471. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  10472. // 通过excel批量上传物料
  10473. $scope.result = null;
  10474. $scope.upload = function() {
  10475. var file = $scope.myFiles[0];
  10476. $upload.upload({
  10477. url: 'purchase/release/excel',
  10478. file: file,
  10479. method: 'POST'
  10480. }).success(function(data) {
  10481. $scope.result = data;
  10482. $scope.success = $scope.result.success;
  10483. $scope.total = $scope.result.total;
  10484. $scope.alters = $scope.result.alters;
  10485. }).error(function(response) {
  10486. toaster.pop('error', response.data || response);
  10487. });
  10488. };
  10489. // 下载模板
  10490. $scope.download = function() {
  10491. window.location.href = 'purchase/upload/template';
  10492. };
  10493. $scope.enSure = function() {
  10494. $modalInstance.close($scope.result.products);
  10495. }
  10496. $scope.cancel = function() {
  10497. $modalInstance.dismiss();
  10498. }
  10499. }]);
  10500. // 查找供应商
  10501. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  10502. $scope.prod = false;
  10503. if(orderItems.length != 0) {
  10504. $scope.prod = true;
  10505. }
  10506. BaseService.scrollBackToTop();
  10507. if($rootScope.venduu != null) {
  10508. $scope.venduu = $rootScope.venduu;
  10509. }
  10510. // 搜索框回车
  10511. $scope.onSearch = function(keyword) {
  10512. $scope.keyword = keyword;
  10513. $scope.customerParams.page(1);
  10514. $scope.customerParams.reload();
  10515. };
  10516. $scope.customerParams = new ngTableParams({
  10517. page : 1,
  10518. count : 20
  10519. }, {
  10520. total : 0,
  10521. counts: [5, 10, 25, 50],
  10522. getData : function($defer, params) {
  10523. $scope.loading = true;
  10524. var pageParams = params.url();
  10525. pageParams.keyword = $scope.keyword;
  10526. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  10527. $scope.loading = false;
  10528. if(page) {
  10529. params.total(page.totalElement);
  10530. $defer.resolve(page.content);
  10531. }
  10532. $scope.totalCount = page.totalElement;
  10533. }, function(response){
  10534. $scope.loading = false;
  10535. toaster.pop('error', '数据加载失败', response.data);
  10536. });
  10537. }
  10538. });
  10539. $scope.cancel = function() {
  10540. $modalInstance.dismiss();
  10541. };
  10542. $scope.ensure = false;
  10543. $scope.check = function(vendor) { // 需要进行判断的选择
  10544. $scope.vendorInfo = vendor;
  10545. $scope.ensure = true;
  10546. };
  10547. $scope.checkVendor = function(vendor) { // 直接选择
  10548. $modalInstance.close(vendor);
  10549. }
  10550. }]);
  10551. /**
  10552. * 我的客户
  10553. */
  10554. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  10555. $scope.userInfoResult = true;
  10556. AuthenticationService.getAuthentication().success(function(data) {
  10557. $scope.loading = false;
  10558. $scope.thisUser = data;
  10559. });
  10560. var getCustInfos = function(custuu) {
  10561. if(custuu) {
  10562. VendorService.userInfo.query({uu:custuu},null,function(data) {
  10563. $scope.custInfos = data;
  10564. var getPage = function(page, size){
  10565. if($scope.custInfos) {
  10566. var result = {};
  10567. result.totalCount = $scope.custInfos.length;
  10568. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  10569. if($scope.custInfos.length % size == 0) {
  10570. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  10571. }else {
  10572. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  10573. }
  10574. result.first = page == 1;
  10575. result.last = page == result.totalPage;
  10576. result.page = page;
  10577. result.next = page - 0 + 1;
  10578. result.pre = page - 1;
  10579. return result;
  10580. }
  10581. }
  10582. $scope.userdata = getPage(1,4);
  10583. $scope.first = function (){
  10584. $scope.userdata = getPage($scope.userdata.pre,4);
  10585. }
  10586. $scope.last = function (){
  10587. $scope.userdata = getPage($scope.userdata.next,4);
  10588. }
  10589. }, function(response){
  10590. $scope.loading = false;
  10591. toaster.pop('error', '数据加载失败', response.data);
  10592. });
  10593. }
  10594. }
  10595. $scope.addUserInfo = function(customer) {
  10596. //TODO
  10597. if ($scope.thisUser.sys) {
  10598. var modalInstance = $modal.open({
  10599. animation: true,
  10600. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  10601. controller: 'AddUserInfoCtrl',
  10602. resolve: {
  10603. customer: function() {
  10604. return customer;
  10605. }
  10606. }
  10607. });
  10608. modalInstance.result.then(function(changed, checked){
  10609. if(changed) {
  10610. if(checked)
  10611. $scope.newUser.roles = checked;
  10612. else
  10613. loadUsers();
  10614. }
  10615. });
  10616. } else {
  10617. toaster.pop('error', '您不是管理员,无权限分配用户!');
  10618. }
  10619. }
  10620. $scope.showUserInfo = function(customer,boo) {
  10621. $scope.custInfo = customer;
  10622. if(boo) {
  10623. getCustInfos(customer.myEnterprise.uu);
  10624. $scope.userInfoResult = true;
  10625. }
  10626. }
  10627. $scope.customerParams = new ngTableParams({
  10628. page : 1,
  10629. count : 20
  10630. }, {
  10631. total : 0,
  10632. counts: [5, 10, 25, 50],
  10633. getData : function($defer, params) {
  10634. $scope.loading = true;
  10635. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  10636. $scope.loading = false;
  10637. if(page) {
  10638. params.total(page.totalElement);
  10639. $defer.resolve(page.content);
  10640. }
  10641. $scope.totalCount = page.totalElement;
  10642. }, function(response){
  10643. $scope.loading = false;
  10644. toaster.pop('error', '数据加载失败', response.data);
  10645. });
  10646. }
  10647. });
  10648. }]);
  10649. /**
  10650. * 我的供应商
  10651. */
  10652. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  10653. BaseService.scrollBackToTop();
  10654. // 搜索框回车
  10655. $scope.onSearch = function(keyword) {
  10656. $scope.keyword = keyword;
  10657. $scope.customerParams.page(1);
  10658. $scope.customerParams.reload();
  10659. };
  10660. $scope.customerParams = new ngTableParams({
  10661. page : 1,
  10662. count : 20
  10663. }, {
  10664. total : 0,
  10665. counts: [5, 10, 25, 50],
  10666. getData : function($defer, params) {
  10667. $scope.loading = true;
  10668. var pageParams = params.url();
  10669. pageParams.keyword = $scope.keyword;
  10670. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  10671. $scope.loading = false;
  10672. if(page) {
  10673. params.total(page.totalElement);
  10674. $scope.total = page.totalElement;
  10675. $defer.resolve(page.content);
  10676. }
  10677. $scope.totalCount = page.totalElement;
  10678. }, function(response){
  10679. $scope.loading = false;
  10680. toaster.pop('error', '数据加载失败', response.data);
  10681. });
  10682. }
  10683. });
  10684. // 查看供应商详情
  10685. $scope.VendorDetail = function(id, uu) {
  10686. $rootScope.vendorId = id;
  10687. $rootScope.vendoruu = uu;
  10688. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  10689. }
  10690. // 向企业购买
  10691. $scope.purcByEn = function(businessCode) {
  10692. $rootScope.businessCode = businessCode;
  10693. window.location.hash = "#/purc/addOrder";
  10694. }
  10695. }]);
  10696. /**
  10697. * 供应商详情
  10698. */
  10699. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  10700. BaseService.scrollBackToTop();
  10701. $scope.vendorContacts = [];
  10702. var loadData = function() {
  10703. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  10704. $scope.vendor = data.vendorEnterprise;
  10705. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  10706. $scope.vendorContacts = data;
  10707. });
  10708. });
  10709. };
  10710. loadData();
  10711. // 新增供应商联系人
  10712. $scope.addContact = function(uu) {
  10713. var modalInstance = $modal.open({
  10714. animation: true,
  10715. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10716. controller: 'AddContacCtrl',
  10717. resolve: {
  10718. }
  10719. });
  10720. modalInstance.result.then(function(data) {
  10721. $scope.contact = data;
  10722. $scope.contact.venduu = uu;
  10723. Vendor.saveContact({}, $scope.contact, function(data) {
  10724. toaster.pop('success', '提示', '联系人保存成功');
  10725. $scope.vendorContacts.push(data);
  10726. }, function(response) {
  10727. toaster.pop('error', '失败', response.data);
  10728. });
  10729. });
  10730. };
  10731. // 编辑供应商联系人
  10732. $scope.edit = function(contact) {
  10733. var modalInstance = $modal.open({
  10734. animation: true,
  10735. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10736. controller: 'EditContacCtrl',
  10737. resolve: {
  10738. contact: function() {
  10739. return contact;
  10740. }
  10741. }
  10742. });
  10743. modalInstance.result.then(function(data) {
  10744. Vendor.saveContact({}, data, function(data) {
  10745. loadData();
  10746. toaster.pop('success', '提示', '联系人修改成功');
  10747. }, function(response) {
  10748. toaster.pop('error', '失败', response.data);
  10749. });
  10750. });
  10751. }
  10752. // 删除供应商联系人
  10753. $scope.deleteById = function(id, index) {
  10754. $scope.vendorContacts.splice(index, 1);
  10755. Vendor.deleteContact({id: id}, {}, function(data) {
  10756. toaster.pop('success', '提示', '供应商联系人删除成功');
  10757. loadData();
  10758. }, function(response) {
  10759. toaster.pop('error', '提示', response.data);
  10760. });
  10761. }
  10762. // 供应商物料信息
  10763. $scope.viewProdList = function(uu){
  10764. $scope.uu = uu;
  10765. $scope.tableParams.page(1);
  10766. $scope.tableParams.reload();
  10767. };
  10768. // 搜索框回车
  10769. $scope.onSearch = function(keyword) {
  10770. $scope.keyword = keyword;
  10771. $scope.tableParams.page(1);
  10772. $scope.tableParams.reload();
  10773. };
  10774. // 供应商物料信息
  10775. $scope.tableParams = new ngTableParams({
  10776. page : 1,
  10777. count : 20
  10778. }, {
  10779. total : 0,
  10780. counts: [5, 10, 25, 50],
  10781. getData : function($defer, params) {
  10782. $scope.loading = true;
  10783. var pageParams = params.url();
  10784. pageParams.custUU = $scope.uu;
  10785. pageParams.keyword = $scope.keyword;
  10786. $scope.tip = $scope.keyword;
  10787. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  10788. $scope.loading = false;
  10789. if(page) {
  10790. params.total(page.totalElement);
  10791. $scope.total = page.totalElement;
  10792. $defer.resolve(page.content);
  10793. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10794. }
  10795. }, function(response){
  10796. $scope.loading = false;
  10797. toaster.pop('error', '数据加载失败', response.data);
  10798. });
  10799. }
  10800. });
  10801. /**
  10802. * 选中单个物料购买
  10803. * @param businessCode
  10804. * @param id
  10805. */
  10806. $scope.PurcByEnAndProd = function(businessCode, id) {
  10807. $rootScope.businessCode = businessCode;
  10808. $rootScope.prodId = id;
  10809. window.location.hash = "#/purc/addOrder";
  10810. }
  10811. /**
  10812. * 询价
  10813. */
  10814. $scope.PurcInquiry = function(businessCode, id){
  10815. $rootScope.prodId = id;
  10816. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  10817. }
  10818. }]);
  10819. /**
  10820. * 编辑供应商联系人
  10821. */
  10822. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  10823. $scope.contact = angular.copy(contact);
  10824. $scope.save = function(contact) {
  10825. $modalInstance.close(contact);
  10826. };
  10827. $scope.cancel = function() {
  10828. $modalInstance.dismiss();
  10829. }
  10830. }]);
  10831. /**
  10832. * 新增供应商联系人
  10833. */
  10834. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  10835. $scope.save = function(contact) {
  10836. $modalInstance.close(contact);
  10837. };
  10838. $scope.cancel = function() {
  10839. $modalInstance.dismiss();
  10840. }
  10841. }]);
  10842. /**
  10843. * 建立合作关系申请 (我的合作伙伴)
  10844. */
  10845. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo) {
  10846. BaseService.scrollBackToTop();
  10847. $scope.status = "partner";
  10848. $scope.active = 'done';
  10849. var getRequestStatus = function(active) {
  10850. var fn = 'getAllRequest';
  10851. switch(active) {
  10852. case 'done':
  10853. fn = 'getRequestDone';break;
  10854. case 'todo':
  10855. fn = 'getRequestTodo';break;
  10856. case 'end':
  10857. fn = 'getRequestEnd';break;
  10858. }
  10859. return fn;
  10860. }
  10861. // 切换单据类型
  10862. $scope.setActive = function(state) {
  10863. if($scope.active != state) {
  10864. $scope.active = state;
  10865. if($scope.tableParams.page() == 1)
  10866. $scope.tableParams.reload();
  10867. else
  10868. $scope.tableParams.page(1);
  10869. }
  10870. };
  10871. // 切换数据来源(正常数据 or 历史数据)
  10872. var getService = function() {
  10873. return AddPartnerMyRequest;
  10874. };
  10875. $scope.tableParams = new ngTableParams({ // ng-Table参数
  10876. page : 1,
  10877. count : 20,
  10878. sorting: {
  10879. }
  10880. }, {
  10881. total : 0,
  10882. counts: [],
  10883. getData : function($defer, params) { // 获取数据的方法
  10884. $scope.loading = true;
  10885. var pageParams = params.url();
  10886. pageParams.keyword = $scope.keyword;
  10887. if($rootScope.vendName) {
  10888. pageParams.keyword = $rootScope.vendName;
  10889. $scope.keyword = $rootScope.vendName;
  10890. $rootScope.vendName = null;
  10891. }
  10892. $scope.tip = $scope.keyword;
  10893. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10894. $scope.loading = false;
  10895. if(page) {
  10896. params.total(page.totalElement);
  10897. $defer.resolve(page.content);
  10898. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10899. }
  10900. }, function(response){
  10901. $scope.loading = false;
  10902. toaster.pop('error', '数据加载失败', response.data);
  10903. });
  10904. }
  10905. });
  10906. // 再次申请
  10907. $scope.addAgain = function(name, businessCode) {
  10908. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  10909. if(data.success) {
  10910. toaster.pop("success", '添加成功', data.success);
  10911. $scope.tableParams.reload();
  10912. }
  10913. if(data.error) {
  10914. toaster.pop("error", '添加失败', data.error);
  10915. }
  10916. }, function(response) {
  10917. toaster.pop('error','失败',response.data);
  10918. });
  10919. }
  10920. // 添加为供应商
  10921. $scope.addSupplier = function(vendUID) {
  10922. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  10923. if(data.success) {
  10924. toaster.pop('success', '提示', data.success);
  10925. $scope.tableParams.reload();
  10926. }
  10927. if(data.error) {
  10928. toaster.pop('error','提示', data.error);
  10929. }
  10930. }, function(response) {
  10931. toaster.pop('error', '失败', response.data);
  10932. })
  10933. };
  10934. // 添加客户
  10935. $scope.addCust = function(vendUID) {
  10936. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  10937. if(data.success) {
  10938. toaster.pop('success', '提示', data.success);
  10939. $scope.tableParams.reload();
  10940. }
  10941. if(data.error) {
  10942. toaster.pop('error','提示', data.error);
  10943. }
  10944. }, function(response) {
  10945. toaster.pop('error', '失败', response.data);
  10946. })
  10947. };
  10948. // 搜索框回车
  10949. $scope.onSearch = function() {
  10950. $scope.tableParams.page(1);
  10951. $scope.tableParams.reload();
  10952. };
  10953. // 同意申请
  10954. $scope.agree = function(id) {
  10955. AddPartner.agreeRequest({id: id}, {}, function(data) {
  10956. toaster.pop('success', '提示', '操作成功');
  10957. $scope.tableParams.reload();
  10958. }, function(response) {
  10959. toaster.pop('error', '提示', response.data);
  10960. });
  10961. };
  10962. // 拒绝申请
  10963. $scope.refuse = function(id, reason) {
  10964. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  10965. toaster.pop('success', '提示', '操作成功');
  10966. $scope.tableParams.reload();
  10967. }, function(response) {
  10968. toaster.pop('error', '提示', response.data);
  10969. });
  10970. };
  10971. // 取消供应商关系
  10972. $scope.relieve = function(id) {
  10973. VendorInfo.relieve({id: id}, {}, function(data) {
  10974. if(data.success) {
  10975. toaster.pop('success', '提示', data.success);
  10976. }
  10977. $scope.tableParams.page(1);
  10978. $scope.tableParams.reload();
  10979. }, function(response) {
  10980. toaster.pop('error', '提示', response.data);
  10981. });
  10982. };
  10983. // 建立供应商关系
  10984. $scope.activeVend = function(id) {
  10985. VendorInfo.activeVend({id: id}, {}, function(data) {
  10986. if(data.success) {
  10987. toaster.pop('success', '提示', data.success);
  10988. }
  10989. $scope.tableParams.page(1);
  10990. $scope.tableParams.reload();
  10991. }, function(response) {
  10992. toaster.pop('error', '提示', response.data);
  10993. });
  10994. }
  10995. // 取消客户关系
  10996. $scope.disableCust = function(id) {
  10997. VendorInfo.disableCust({id: id}, {}, function(data) {
  10998. if(data.success) {
  10999. toaster.pop('success', '提示', data.success);
  11000. }
  11001. $scope.tableParams.page(1);
  11002. $scope.tableParams.reload();
  11003. }, function(response) {
  11004. toaster.pop('error', '提示', response.data);
  11005. });
  11006. }
  11007. // 激活客户关系
  11008. $scope.activeCust = function(id) {
  11009. VendorInfo.activeCust({id: id}, {}, function(data) {
  11010. if(data.success) {
  11011. toaster.pop('success', '提示', data.success);
  11012. }
  11013. $scope.tableParams.page(1);
  11014. $scope.tableParams.reload();
  11015. }, function(response) {
  11016. toaster.pop('error', '提示', response.data);
  11017. });
  11018. }
  11019. }]);
  11020. /**
  11021. * 建立合作关系申请 (新的合作伙伴)
  11022. */
  11023. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo) {
  11024. BaseService.scrollBackToTop();
  11025. $scope.status = "partner";
  11026. $scope.active = 'all'; // 所有申请记录
  11027. var getRequestStatus = function(active) {
  11028. var fn = 'getAllRequest';
  11029. switch(active) {
  11030. case 'done':
  11031. fn = 'getRequestDone';break;
  11032. case 'todo':
  11033. fn = 'getRequestTodo';break;
  11034. case 'end':
  11035. fn = 'getRequestEnd';break;
  11036. }
  11037. return fn;
  11038. }
  11039. // 切换单据类型
  11040. $scope.setActive = function(state) {
  11041. if($scope.active != state) {
  11042. $scope.active = state;
  11043. if($scope.tableParams.page() == 1)
  11044. $scope.tableParams.reload();
  11045. else
  11046. $scope.tableParams.page(1);
  11047. }
  11048. };
  11049. // 切换数据来源(正常数据 or 历史数据)
  11050. var getService = function() {
  11051. return AddPartnerMyRequest;
  11052. };
  11053. $scope.tableParams = new ngTableParams({ // ng-Table参数
  11054. page : 1,
  11055. count : 20,
  11056. sorting: {
  11057. }
  11058. }, {
  11059. total : 0,
  11060. counts: [],
  11061. getData : function($defer, params) { // 获取数据的方法
  11062. $scope.loading = true;
  11063. var pageParams = params.url();
  11064. pageParams.keyword = $scope.keyword;
  11065. if($rootScope.vendName) {
  11066. pageParams.keyword = $rootScope.vendName;
  11067. $scope.keyword = $rootScope.vendName;
  11068. $rootScope.vendName = null;
  11069. }
  11070. $scope.tip = $scope.keyword;
  11071. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11072. $scope.loading = false;
  11073. if(page) {
  11074. params.total(page.totalElement);
  11075. $defer.resolve(page.content);
  11076. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11077. }
  11078. }, function(response){
  11079. $scope.loading = false;
  11080. toaster.pop('error', '数据加载失败', response.data);
  11081. });
  11082. }
  11083. });
  11084. // 再次申请
  11085. $scope.addAgain = function(name, businessCode) {
  11086. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  11087. if(data.success) {
  11088. toaster.pop("success", '添加成功', data.success);
  11089. $scope.tableParams.reload();
  11090. }
  11091. if(data.error) {
  11092. toaster.pop("error", '添加失败', data.error);
  11093. }
  11094. }, function(response) {
  11095. toaster.pop('error','失败',response.data);
  11096. });
  11097. }
  11098. // 添加为供应商
  11099. $scope.addSupplier = function(vendUID) {
  11100. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  11101. if(data.success) {
  11102. toaster.pop('success', '提示', data.success);
  11103. $scope.tableParams.reload();
  11104. }
  11105. if(data.error) {
  11106. toaster.pop('error','提示', data.error);
  11107. }
  11108. }, function(response) {
  11109. toaster.pop('error', '失败', response.data);
  11110. })
  11111. };
  11112. // 添加客户
  11113. $scope.addCust = function(vendUID) {
  11114. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  11115. if(data.success) {
  11116. toaster.pop('success', '提示', data.success);
  11117. $scope.tableParams.reload();
  11118. }
  11119. if(data.error) {
  11120. toaster.pop('error','提示', data.error);
  11121. }
  11122. }, function(response) {
  11123. toaster.pop('error', '失败', response.data);
  11124. })
  11125. };
  11126. // 搜索框回车
  11127. $scope.onSearch = function() {
  11128. $scope.tableParams.page(1);
  11129. $scope.tableParams.reload();
  11130. };
  11131. // 同意申请
  11132. $scope.agree = function(id) {
  11133. AddPartner.agreeRequest({id: id}, {}, function(data) {
  11134. toaster.pop('success', '提示', '操作成功');
  11135. $scope.tableParams.reload();
  11136. }, function(response) {
  11137. toaster.pop('error', '提示', response.data);
  11138. });
  11139. };
  11140. AddPartnerMyRequest.requestAmount({}, function(data) {
  11141. $scope.requestTodo = data;
  11142. });
  11143. // 拒绝申请
  11144. $scope.refuse = function(id, reason) {
  11145. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  11146. toaster.pop('success', '提示', '操作成功');
  11147. $scope.tableParams.reload();
  11148. }, function(response) {
  11149. toaster.pop('error', '提示', response.data);
  11150. });
  11151. };
  11152. // 取消供应商关系
  11153. $scope.relieve = function(id) {
  11154. VendorInfo.relieve({id: id}, {}, function(data) {
  11155. if(data.success) {
  11156. toaster.pop('success', '提示', data.success);
  11157. }
  11158. // $scope.tableParams.page(1);
  11159. $scope.tableParams.reload();
  11160. }, function(response) {
  11161. toaster.pop('error', '提示', response.data);
  11162. });
  11163. }
  11164. // 建立供应商关系
  11165. $scope.activeVend = function(id) {
  11166. VendorInfo.activeVend({id: id}, {}, function(data) {
  11167. if(data.success) {
  11168. toaster.pop('success', '提示', data.success);
  11169. }
  11170. // $scope.tableParams.page(1);
  11171. $scope.tableParams.reload();
  11172. }, function(response) {
  11173. toaster.pop('error', '提示', response.data);
  11174. });
  11175. }
  11176. // 取消客户关系
  11177. $scope.disableCust = function(id) {
  11178. VendorInfo.disableCust({id: id}, {}, function(data) {
  11179. if(data.success) {
  11180. toaster.pop('success', '提示', data.success);
  11181. }
  11182. // $scope.tableParams.page(1);
  11183. $scope.tableParams.reload();
  11184. }, function(response) {
  11185. toaster.pop('error', '提示', response.data);
  11186. });
  11187. }
  11188. // 激活客户关系
  11189. $scope.activeCust = function(id) {
  11190. VendorInfo.activeCust({id: id}, {}, function(data) {
  11191. if(data.success) {
  11192. toaster.pop('success', '提示', data.success);
  11193. }
  11194. // $scope.tableParams.page(1);
  11195. $scope.tableParams.reload();
  11196. }, function(response) {
  11197. toaster.pop('error', '提示', response.data);
  11198. });
  11199. }
  11200. }]);
  11201. /**
  11202. * 建立合作关系处理申请
  11203. */
  11204. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest) {
  11205. BaseService.scrollBackToTop();
  11206. $scope.active = 'todo';
  11207. var getMessagetStatus = function(active) {
  11208. var fn = 'getAllMessage';
  11209. switch(active) {
  11210. case 'done':
  11211. fn = 'getMessageDone';break;
  11212. case 'todo':
  11213. fn = 'getMessageTodo';break;
  11214. case 'end':
  11215. fn = 'getMessageEnd';break;
  11216. }
  11217. return fn;
  11218. }
  11219. // 切换单据类型
  11220. $scope.setActive = function(state) {
  11221. if($scope.active != state) {
  11222. $scope.active = state;
  11223. if($scope.tableParams.page() == 1)
  11224. $scope.tableParams.reload();
  11225. else
  11226. $scope.tableParams.page(1);
  11227. }
  11228. };
  11229. var getService = function() {
  11230. return AddPartnerMyMessage;
  11231. };
  11232. $scope.tableParams = new ngTableParams({ // ng-Table参数
  11233. page : 1,
  11234. count : 20,
  11235. sorting: {
  11236. }
  11237. }, {
  11238. total : 0,
  11239. counts: [5, 10, 15, 25, 50],
  11240. getData : function($defer, params) { // 获取数据的方法
  11241. $scope.loading = true;
  11242. var pageParams = params.url();
  11243. pageParams.searchFilter = { // 筛选条件
  11244. keyword: $scope.keyword,
  11245. };
  11246. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11247. $scope.loading = false;
  11248. if(page) {
  11249. params.total(page.totalElement);
  11250. $defer.resolve(page.content);
  11251. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11252. }
  11253. }, function(response){
  11254. $scope.loading = false;
  11255. toaster.pop('error', '数据加载失败', response.data);
  11256. });
  11257. }
  11258. });
  11259. // 同意申请
  11260. $scope.agree = function(id) {
  11261. AddPartner.agreeRequest({id: id}, {}, function(data) {
  11262. toaster.pop('success', '提示', '操作成功');
  11263. $scope.tableParams.reload();
  11264. }, function(response) {
  11265. toaster.pop('error', '提示', response.data);
  11266. });
  11267. };
  11268. // 拒绝申请
  11269. $scope.refuse = function(id, reason) {
  11270. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  11271. toaster.pop('success', '提示', '操作成功');
  11272. $scope.tableParams.reload();
  11273. }, function(response) {
  11274. toaster.pop('error', '提示', response.data);
  11275. });
  11276. };
  11277. $scope.status = 'get';
  11278. }]);
  11279. /**
  11280. * 我的合作伙伴
  11281. */
  11282. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  11283. BaseService.scrollBackToTop();
  11284. // 默认显示合作伙伴
  11285. $scope.status = 'news';
  11286. // 获取所有的合作伙伴
  11287. GetProductInfo.getAllPartners({}, function(data) {
  11288. $scope.partners = data;
  11289. }, function(res) {
  11290. toaster.pop('error', '获取列表失败', res.data);
  11291. });
  11292. // 添加为客户
  11293. $scope.addCust = function(partner) {
  11294. GetProductInfo.addCust({}, partner, function(data) {
  11295. toaster.pop('success', '提示', '添加客户成功');
  11296. $scope.tableParams.reload();
  11297. }, function(response) {
  11298. toaster.pop('error', '添加客户失败', response.data);
  11299. });
  11300. }
  11301. // 添加为供应商
  11302. $scope.addSupplier = function(partner) {
  11303. GetProductInfo.addSupplier({}, partner, function(data) {
  11304. toaster.pop('success', '提示', '添加供应商成功');
  11305. $scope.tableParams.reload();
  11306. }, function(response) {
  11307. toaster.pop('error', '添加供应商失败', response.data);
  11308. });
  11309. }
  11310. }]);
  11311. /**
  11312. * 财务对账时,企业进行筛选操作
  11313. */
  11314. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  11315. var getData = function(){
  11316. $scope.loading = true;
  11317. FaApCheck.getAllCustomers(function(data) {
  11318. $scope.custs = data;
  11319. $scope.loading = false;
  11320. });
  11321. };
  11322. getData();
  11323. $scope.select = function(suuorname) {
  11324. $modalInstance.close(suuorname);
  11325. }
  11326. $scope.close = function() {
  11327. $modalInstance.close();
  11328. }
  11329. }]);
  11330. /**
  11331. * 跳转到企业圈
  11332. */
  11333. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  11334. GetProductInfo.businessGroups({}, function(data) {
  11335. window.open(data.url);
  11336. }, function(response) {
  11337. toaster.pop('error', '提示', response.data);
  11338. });
  11339. }]);
  11340. /**
  11341. * 购物车
  11342. */
  11343. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  11344. BaseService.scrollBackToTop();
  11345. $scope.active = 'all';
  11346. $scope.agreedText = '全部';
  11347. $scope.dateZoneText = '一个月内';
  11348. $scope.condition = {dateZone: 1};
  11349. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11350. $scope.changeAgreed = function(agreed) {
  11351. $scope.condition.agreed = agreed;
  11352. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11353. $scope.condition.$agreedOpen = false;
  11354. };
  11355. $scope.changeDateZone = function(zone) {
  11356. $scope.condition.dateZone = zone;
  11357. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11358. $scope.condition.$dateZoneOpen = false;
  11359. getDateCondition(zone, $scope.condition);
  11360. $scope.tableParams.reload();
  11361. };
  11362. $scope.setActive = function(state) {
  11363. if($scope.active != state) {
  11364. $scope.active = state;
  11365. if($scope.tableParams.page() == 1)
  11366. $scope.tableParams.reload();
  11367. else
  11368. $scope.tableParams.page(1);
  11369. }
  11370. };
  11371. var getService = function() {
  11372. return getCartList;
  11373. };
  11374. $scope.tableParams = new ngTableParams({
  11375. page : 1,
  11376. count : 20,
  11377. sorting: {
  11378. date: 'desc'
  11379. }
  11380. }, {
  11381. total : 0,
  11382. counts: [5, 10, 25, 50],
  11383. getData : function($defer, params) {
  11384. $scope.loading = true;
  11385. var pageParams = params.url();
  11386. pageParams.keyword = $scope.keyword;
  11387. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  11388. $scope.loading = false;
  11389. if(page) {
  11390. params.total(page.totalElements);
  11391. $defer.resolve(page.content);
  11392. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11393. }
  11394. }, function(response) {
  11395. $scope.loading = false;
  11396. toaster.pop('error', '数据加载失败', response.data);
  11397. });
  11398. }
  11399. });
  11400. $scope.getCartTotal = function(items) {
  11401. var sum = 0;
  11402. angular.forEach(items, function(item){
  11403. sum += item.qty * item.price;
  11404. });
  11405. return sum;
  11406. };
  11407. // 搜索框回车
  11408. $scope.onSearch = function() {
  11409. $scope.tableParams.page(1);
  11410. $scope.tableParams.reload();
  11411. };
  11412. // 提交
  11413. $scope.addtoOrder = function(id) {
  11414. cartOperation.addToOrder({id: id}, {}, function(data) {
  11415. if(data.success) {
  11416. toaster.pop('success', '提示', data.success);
  11417. $timeout(function() {
  11418. window.location.hash = '#/purc/order/'+data.id;
  11419. },500);
  11420. }
  11421. if(data.error) {
  11422. toaster.pop('error', '提示', data.error);
  11423. }
  11424. }, function(response) {
  11425. toaster.pop('erroer', '提示', response.data);
  11426. });
  11427. };
  11428. // 删除一条主记录
  11429. $scope.deleteCart = function(id) {
  11430. cartOperation.deleteCart({id: id}, {}, function(data) {
  11431. if(data.success) {
  11432. toaster.pop('success', '提示', data.success);
  11433. $timeout(function() {
  11434. window.location.reload();
  11435. },500);
  11436. }
  11437. if(data.error) {
  11438. toaster.pop('error', '提示', data.error);
  11439. }
  11440. }, function(response) {
  11441. toaster.pop('erroer', '提示', response.data);
  11442. });
  11443. };
  11444. // 删除一条明细
  11445. $scope.deleteDetail = function(id) {
  11446. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  11447. if(data.success) {
  11448. toaster.pop('success', '提示', data.success);
  11449. $timeout(function() {
  11450. window.location.reload();
  11451. },500);
  11452. }
  11453. if(data.error) {
  11454. toaster.pop('error', '提示', data.error);
  11455. }
  11456. }, function(response) {
  11457. toaster.pop('erroer', '提示', response.data);
  11458. });
  11459. };
  11460. // 清空购物车
  11461. $scope.clearCart = function() {
  11462. cartOperation.deleteCarts({}, function(data) {
  11463. if(data.success) {
  11464. toaster.pop('success', '提示', data.success);
  11465. $timeout(function() {
  11466. window.location.reload();
  11467. },500);
  11468. }
  11469. if(data.error) {
  11470. toaster.pop('error', '提示', data.error);
  11471. }
  11472. }, function(response) {
  11473. toaster.pop('erroer', '提示', response.data);
  11474. });
  11475. }
  11476. }]);
  11477. /**
  11478. * 购物车详情
  11479. */
  11480. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  11481. BaseService.scrollBackToTop();
  11482. var loadData = function() {
  11483. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  11484. if(data.code) {
  11485. $scope.cart = data;
  11486. var sum = 0;
  11487. angular.forEach($scope.cart.cartDetails, function(item) {
  11488. sum += item.qty * item.price;
  11489. });
  11490. $scope.cart.total = sum;
  11491. $scope.loading = false;
  11492. } else {
  11493. window.location.hash = '#/purc/cart';
  11494. }
  11495. });
  11496. };
  11497. loadData();
  11498. // 删除一条明细
  11499. $scope.deleteDetail = function(id) {
  11500. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  11501. if(data.success) {
  11502. toaster.pop('success', '提示', data.success);
  11503. $timeout(function() {
  11504. window.location.reload();
  11505. },500);
  11506. }
  11507. if(data.error) {
  11508. toaster.pop('error', '提示', data.error);
  11509. }
  11510. }, function(response) {
  11511. toaster.pop('erroer', '提示', response.data);
  11512. });
  11513. };
  11514. // 删除一条主记录
  11515. $scope.deleteCart = function(id) {
  11516. cartOperation.deleteCart({id: id}, {}, function(data) {
  11517. if(data.success) {
  11518. toaster.pop('success', '提示', data.success);
  11519. $timeout(function() {
  11520. window.location.reload();
  11521. },500);
  11522. }
  11523. if(data.error) {
  11524. toaster.pop('error', '提示', data.error);
  11525. }
  11526. }, function(response) {
  11527. toaster.pop('erroer', '提示', response.data);
  11528. });
  11529. };
  11530. // 提交
  11531. $scope.addtoOrder = function(id) {
  11532. cartOperation.addToOrder({id: id}, {}, function(data) {
  11533. if(data.success) {
  11534. toaster.pop('success', '提示', data.success);
  11535. $timeout(function() {
  11536. window.location.hash = '#/purc/order/'+data.id;
  11537. },500);
  11538. }
  11539. if(data.error) {
  11540. toaster.pop('error', '提示', data.error);
  11541. }
  11542. }, function(response) {
  11543. toaster.pop('erroer', '提示', response.data);
  11544. });
  11545. };
  11546. }]);
  11547. /**
  11548. * 审批流
  11549. */
  11550. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  11551. BaseService.scrollBackToTop();
  11552. $scope.vacation = false;
  11553. $scope.workovertime = false;
  11554. $scope.workdaily = false;
  11555. $scope.feeplease = false;
  11556. $scope.signapp = false;
  11557. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  11558. $scope.nodes = data;
  11559. angular.forEach($scope.nodes, function(node) {
  11560. if(node.appname = '请假单') {
  11561. $scope.vacation = true;
  11562. }
  11563. if(node.appname = '加班单') {
  11564. $scope.workovertime = true;
  11565. }
  11566. if(node.appname = '工作日报') {
  11567. $scope.workdaily = true;
  11568. }
  11569. if(node.appname = '出差单') {
  11570. $scope.feeplease = true;
  11571. }
  11572. if(node.appname = '申诉单') {
  11573. $scope.signapp = true;
  11574. }
  11575. });
  11576. }, function(response) {
  11577. });
  11578. $scope.NoteSet = function() {
  11579. var modalInstance = $modal.open({
  11580. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  11581. controller: 'NoteStep1Ctrl',
  11582. size: 'lg',
  11583. resolve: {
  11584. AppName: function() {
  11585. return '请假单';
  11586. }
  11587. }
  11588. });
  11589. modalInstance.result.then(function(data) {
  11590. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  11591. if(data.error) {
  11592. toaster.pop('error', '提示', data.error);
  11593. }
  11594. if(data.success) {
  11595. toaster.pop('success', '提示', data.success);
  11596. }
  11597. }, function(response) {
  11598. });
  11599. }, function(){
  11600. });
  11601. }
  11602. $scope.overTimeSet = function() {
  11603. var modalInstance = $modal.open({
  11604. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  11605. controller: 'NoteStep1Ctrl',
  11606. size: 'lg',
  11607. resolve: {
  11608. AppName: function() {
  11609. return '加班单';
  11610. }
  11611. }
  11612. });
  11613. modalInstance.result.then(function(data) {
  11614. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  11615. if(data.error) {
  11616. toaster.pop('error', '提示', data.error);
  11617. }
  11618. if(data.success) {
  11619. toaster.pop('success', '提示', data.success);
  11620. }
  11621. }, function(response) {
  11622. });
  11623. }, function(){
  11624. });
  11625. }
  11626. $scope.feePleaseSet = function() {
  11627. var modalInstance = $modal.open({
  11628. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  11629. controller: 'NoteStep1Ctrl',
  11630. size: 'lg',
  11631. resolve: {
  11632. AppName: function() {
  11633. return '出差单';
  11634. }
  11635. }
  11636. });
  11637. modalInstance.result.then(function(data) {
  11638. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  11639. if(data.error) {
  11640. toaster.pop('error', '提示', data.error);
  11641. }
  11642. if(data.success) {
  11643. toaster.pop('success', '提示', data.success);
  11644. }
  11645. }, function(response) {
  11646. });
  11647. }, function(){
  11648. });
  11649. }
  11650. $scope.workDailySet = function() {
  11651. var modalInstance = $modal.open({
  11652. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  11653. controller: 'NoteStep1Ctrl',
  11654. size: 'lg',
  11655. resolve: {
  11656. AppName: function() {
  11657. return '工作日报';
  11658. }
  11659. }
  11660. });
  11661. modalInstance.result.then(function(data) {
  11662. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  11663. if(data.error) {
  11664. toaster.pop('error', '提示', data.error);
  11665. }
  11666. if(data.success) {
  11667. toaster.pop('success', '提示', data.success);
  11668. }
  11669. }, function(response) {
  11670. });
  11671. }, function(){
  11672. });
  11673. }
  11674. $scope.signAppSet = function() {
  11675. var modalInstance = $modal.open({
  11676. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  11677. controller: 'NoteStep1Ctrl',
  11678. size: 'lg',
  11679. resolve: {
  11680. AppName: function() {
  11681. return '申诉单';
  11682. }
  11683. }
  11684. });
  11685. modalInstance.result.then(function(data) {
  11686. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  11687. if(data.error) {
  11688. toaster.pop('error', '提示', data.error);
  11689. }
  11690. if(data.success) {
  11691. toaster.pop('success', '提示', data.success);
  11692. }
  11693. }, function(response) {
  11694. });
  11695. }, function(){
  11696. });
  11697. }
  11698. }]);
  11699. /**
  11700. * 审核条件设置
  11701. */
  11702. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  11703. $scope.appName = AppName;// 标题名称
  11704. $scope.AppFlow = {appName: $scope.appName,
  11705. appNodes:{}};
  11706. $scope.AppFlow.appNodes = [];
  11707. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  11708. if(data.appNodes.length != 0) {
  11709. $scope.node = data;
  11710. $scope.AppFlow = data;
  11711. }
  11712. }, function() {
  11713. });
  11714. $scope.copy = function() {//复制
  11715. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  11716. toaster.pop('info', '提示', '复制成功');
  11717. $modalInstance.dismiss();
  11718. }
  11719. $scope.paste = function() {
  11720. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  11721. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  11722. }
  11723. $scope.clear = function() {// 清空
  11724. $scope.AppFlow = {appName: $scope.appName,
  11725. appNodes:{}};
  11726. $scope.AppFlow.appNodes = [];
  11727. }
  11728. appFlow.getPositions({}, function(data) {// 获取人员信息
  11729. $scope.users = data;
  11730. }, function(response) {
  11731. });
  11732. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  11733. $scope.roles = data;
  11734. },function(response) {
  11735. });
  11736. $scope.SelectUser = function(data) { // 添加人员
  11737. var item = {
  11738. useruu: null,
  11739. username: null,
  11740. level: null
  11741. };
  11742. item.useruu = data.useruu;
  11743. item.username = data.username;
  11744. // if($scope.AppFlow.appNodes.length != 0){
  11745. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  11746. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  11747. // toaster.pop('info', '提示', '不能重复添加');
  11748. // } else {
  11749. // $scope.AppFlow.appNodes.push(item);
  11750. // }
  11751. // }
  11752. // } else {
  11753. $scope.AppFlow.appNodes.push(item);
  11754. // }
  11755. }
  11756. $scope.SelectRole = function(data) {// 添加职位
  11757. var item = {
  11758. position: null,
  11759. level: null
  11760. };
  11761. item.position = data;
  11762. $scope.AppFlow.appNodes.push(item);
  11763. }
  11764. $scope.deleteNode = function(index) {// 删除节点
  11765. $scope.AppFlow.appNodes.splice(index, 1);
  11766. };
  11767. $scope.saveNode = function() { // 保存
  11768. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  11769. $scope.AppFlow.appNodes[key].level = key;
  11770. });
  11771. if($scope.AppFlow.appNodes.length == 0) {
  11772. toaster.pop('info', '提示', '您还未设置审批人');
  11773. } else {
  11774. $modalInstance.close($scope.AppFlow);
  11775. };
  11776. };
  11777. $scope.cancel = function() {// 取消
  11778. $modalInstance.dismiss();
  11779. }
  11780. }]);
  11781. /***
  11782. * 代采定单
  11783. */
  11784. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  11785. BaseService.scrollBackToTop();
  11786. $scope.active = 'all';
  11787. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11788. $scope.total = null;
  11789. $scope.setActive = function(state) {
  11790. if($scope.active != state) {
  11791. $scope.active = state;
  11792. if($scope.tableParams.page() == 1)
  11793. $scope.tableParams.reload();
  11794. else
  11795. $scope.tableParams.page(1);
  11796. }
  11797. };
  11798. $scope.tableParams = new ngTableParams({
  11799. page : 1,
  11800. count : 20,
  11801. sorting: {
  11802. }
  11803. }, {
  11804. total : 0,
  11805. counts: [5, 10, 25, 50],
  11806. getData : function($defer, params) {
  11807. $scope.loading = true;
  11808. var pageParams = params.url();
  11809. pageParams.keyword = $scope.keyword;
  11810. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  11811. $scope.loading = false;
  11812. if(page) {
  11813. params.total(page.totalElement);
  11814. $scope.total = page.totalElement;
  11815. $defer.resolve(page.content);
  11816. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11817. }
  11818. }, function(response) {
  11819. $scope.loading = false;
  11820. toaster.pop('error', '数据加载失败', response.data);
  11821. });
  11822. }
  11823. });
  11824. //打印
  11825. $scope.print = function(deputyOrder) {
  11826. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  11827. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  11828. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  11829. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  11830. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  11831. //TODO 目前只有信扬有代采业务,先写死之后再改
  11832. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  11833. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  11834. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  11835. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  11836. };
  11837. // 搜索框回车
  11838. $scope.onSearch = function() {
  11839. $scope.tableParams.page(1);
  11840. $scope.tableParams.reload();
  11841. };
  11842. }]);
  11843. /**
  11844. * 新增代采订单
  11845. */
  11846. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  11847. BaseService.scrollBackToTop();
  11848. $scope.deOrder = {
  11849. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  11850. entrydate: new Date(),
  11851. status: '在录入',
  11852. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  11853. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  11854. riskmethod: '甲方承担',
  11855. taxpaymentmethod: '甲方承担',
  11856. totalamount: 0,
  11857. totalpayament: 0,
  11858. orderamount: 0,
  11859. usdpayment: 0
  11860. };
  11861. $scope.deOrder.deputyOrderItems = [];
  11862. var item = {
  11863. prodname: null,
  11864. prodcode: null,
  11865. prodspec: null,
  11866. amount: null,
  11867. unitprice: null,
  11868. purcprice: null,
  11869. remark: null,
  11870. orderprice: null,
  11871. };
  11872. $scope.deOrder.deputyOrderItems.push(item);
  11873. // 代采企业列表
  11874. DeputyOrder.deputyEnterprise({}, function(data) {
  11875. $scope.deputyEnterprises = data;
  11876. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  11877. // 费率
  11878. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  11879. $scope.rate = data;
  11880. }, function(response){
  11881. });
  11882. });
  11883. // 更新代采企业时更新费率
  11884. $scope.change = function(deputyuu) {
  11885. // 费率
  11886. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  11887. $scope.rate = data;
  11888. }, function(response){
  11889. });
  11890. }
  11891. // 查找付款企业
  11892. $scope.dbfindPayCompany = function(deputyuu) {
  11893. var modalInstance = $modal.open({
  11894. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  11895. controller: 'DbfindDeputyPayCompanyCtrl',
  11896. resolve: {
  11897. deputyuu: function() {return deputyuu}
  11898. }
  11899. });
  11900. modalInstance.result.then(function(data) {
  11901. $scope.deOrder.paycomname = data.enname;
  11902. $scope.deOrder.paycomaddress = data.address;
  11903. })
  11904. }
  11905. // 查询上次的关键词记录
  11906. $scope.getHisKeyword = function(tervendor) {
  11907. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function(data) {
  11908. $scope.deOrder.vendtel = data.vendtel;
  11909. $scope.deOrder.venduser = data.venduser;
  11910. $scope.deOrder.otherdata = data.otherdata;
  11911. $scope.deOrder.companyname = data.companyname;
  11912. $scope.deOrder.bankaccount = data.bankaccount;
  11913. $scope.deOrder.bankaddress = data.bankaddress;
  11914. $scope.deOrder.bankcode = data.bankcode;
  11915. $scope.deOrder.bankname = data.bankname;
  11916. $scope.deOrder.legalrepresent = data.legalrepresent;
  11917. $scope.deOrder.tervendaddress = data.tervendaddress;
  11918. }, function(response) {
  11919. toaster.pop('error', '提示', response.data);
  11920. });
  11921. }
  11922. // 查询历史供应商
  11923. DeputyOrder.hisvendors({}, function(data) {
  11924. $scope.hisvendors = data;
  11925. }, function(response) {
  11926. toaster.pop('error', '提示', response.data);
  11927. });
  11928. //增加商品
  11929. $scope.add = function(index) {
  11930. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  11931. toaster.pop('info', '提示', '请先填写商品信息');
  11932. }else {
  11933. $scope.deOrder.deputyOrderItems.push(
  11934. { prodname: null,
  11935. prodcode: null,
  11936. prodspec: null,
  11937. prodbrand: null,
  11938. amount: null,
  11939. unitprice: null,
  11940. purcprice: null,
  11941. remark: null,
  11942. orderprice: null});
  11943. }
  11944. };
  11945. //删除商品
  11946. $scope.del = function(index) {
  11947. $scope.deOrder.deputyOrderItems.splice(index, 1);
  11948. };
  11949. // 导入商品信息
  11950. $scope.uplodaByBatch = function() {
  11951. var modalInstance = $modal.open({
  11952. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  11953. controller: 'DeputyOrderUploadCtrl',
  11954. size: 'lg',
  11955. resolve: {
  11956. }
  11957. });
  11958. modalInstance.result.then(function(data) {
  11959. angular.forEach(data, function(data) {
  11960. $scope.deOrder.deputyOrderItems.push(data);
  11961. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  11962. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  11963. $scope.deOrder.deputyOrderItems.splice(i, 1);
  11964. }
  11965. }
  11966. })
  11967. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11968. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11969. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11970. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11971. });
  11972. }, function(){
  11973. });
  11974. }
  11975. // 查找供应商
  11976. $scope.dbfindVendor = function(deputyuu) {
  11977. var modalInstance = $modal.open({
  11978. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  11979. controller: 'DbfindDeputyVendorInfoCtrl',
  11980. size: 'lg',
  11981. resolve: {
  11982. deputyuu: function() {return deputyuu}
  11983. }
  11984. });
  11985. modalInstance.result.then(function(data) {
  11986. $scope.deOrder.customer = data.vendorEnterprise.enName;
  11987. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  11988. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  11989. $scope.deOrder.usertel = data.vendorUser.userTel;
  11990. })
  11991. }
  11992. // 检验订单编号是否存在
  11993. $scope.checkOrder = function(salecode, deputyuu) {
  11994. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  11995. if(data.info) {
  11996. toaster.pop('error', '提示', data.info);
  11997. }
  11998. }, function(response) {
  11999. toaster.pop('error', '提示', response.data);
  12000. })
  12001. }
  12002. //计算采购单价
  12003. $scope.checkPrice = function(rate) {
  12004. if(rate == null) {
  12005. toaster.pop('info', '提示', '请先填入税率');
  12006. } else {
  12007. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12008. item.purcprice = item.unitprice * (1 + rate/100);
  12009. });
  12010. }
  12011. }
  12012. // 保存
  12013. $scope.save = function() {
  12014. $scope.deOrder.entrystatus = '保存';
  12015. $scope.deOrder.totalamount = 0;
  12016. $scope.deOrder.totalpayament = 0;
  12017. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12018. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12019. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12020. });
  12021. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  12022. toaster.pop('info', '提示', '您还未填写任何商品信息');
  12023. } else {
  12024. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  12025. if(data.id) {
  12026. toaster.pop('success', '提示', '保存成功');
  12027. window.location.hash = "#/purc/deputy/"+data.id;
  12028. }
  12029. if(data.error) {
  12030. toaster.pop('error', '提示', '保存失败');
  12031. }
  12032. }, function(response) {
  12033. });
  12034. }
  12035. }
  12036. // 提交
  12037. $scope.submit = function() {
  12038. $scope.deOrder.entrystatus = '已提交';
  12039. $scope.deOrder.totalpayament = 0;
  12040. $scope.deOrder.totalamount = 0;
  12041. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12042. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12043. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12044. });
  12045. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  12046. toaster.pop('info', '提示', '您还未填写任何商品信息');
  12047. } else {
  12048. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  12049. if(data.id) {
  12050. toaster.pop('success', '提示', '提交成功');
  12051. window.location.hash = "#/purc/deputy/"+data.id;
  12052. }
  12053. if(data.error) {
  12054. toaster.pop('error', '提示', '保存失败');
  12055. }
  12056. }, function(response) {
  12057. });
  12058. }
  12059. }
  12060. $scope.openDatePicker = function($event, deOrder, openParam) {
  12061. $event.preventDefault();
  12062. $event.stopPropagation();
  12063. deOrder[openParam] = !deOrder[openParam];
  12064. };
  12065. }]);
  12066. // 代采企业供应商
  12067. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  12068. $scope.prod = false;
  12069. BaseService.scrollBackToTop();
  12070. // 搜索框回车
  12071. $scope.onSearch = function(keyword) {
  12072. $scope.keyword = keyword;
  12073. $scope.customerParams.page(1);
  12074. $scope.customerParams.reload();
  12075. };
  12076. $scope.customerParams = new ngTableParams({
  12077. page : 1,
  12078. count : 20
  12079. }, {
  12080. total : 0,
  12081. counts: [5, 10, 25, 50],
  12082. getData : function($defer, params) {
  12083. $scope.loading = true;
  12084. var pageParams = params.url();
  12085. pageParams.keyword = $scope.keyword;
  12086. pageParams.enuu = deputyuu;
  12087. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function(page){
  12088. $scope.loading = false;
  12089. if(page) {
  12090. params.total(page.totalElement);
  12091. $defer.resolve(page.content);
  12092. }
  12093. $scope.totalCount = page.totalElement;
  12094. }, function(response){
  12095. $scope.loading = false;
  12096. toaster.pop('error', '数据加载失败', response.data);
  12097. });
  12098. }
  12099. });
  12100. $scope.cancel = function() {
  12101. $modalInstance.dismiss();
  12102. };
  12103. $scope.checkVendor = function(vendor) { // 直接选择
  12104. $modalInstance.close(vendor);
  12105. }
  12106. }]);
  12107. // 代采企业付款企业
  12108. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  12109. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function(data) {
  12110. $scope.paycompanies = data;
  12111. }, function(response) {
  12112. toaster.pop('error', '提示', response.data);
  12113. });
  12114. $scope.cancel = function() {
  12115. $modalInstance.dismiss();
  12116. };
  12117. $scope.select = function(company) { // 直接选择
  12118. $modalInstance.close(company);
  12119. }
  12120. }]);
  12121. /**
  12122. * 代采订单批量导入
  12123. */
  12124. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  12125. // 通过excel批量上传物料
  12126. $scope.result = null;
  12127. $scope.upload = function() {
  12128. var file = $scope.myFiles[0];
  12129. $upload.upload({
  12130. url: 'deputyOrder/release/excel',
  12131. file: file,
  12132. method: 'POST'
  12133. }).success(function(data) {
  12134. $scope.result = data;
  12135. $scope.success = $scope.result.success;
  12136. $scope.total = $scope.result.total;
  12137. $scope.alters = $scope.result.alters;
  12138. }).error(function(response) {
  12139. toaster.pop('error', response.data || response);
  12140. });
  12141. };
  12142. // 查看范例
  12143. $scope.showImg = function() {
  12144. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  12145. box.show();
  12146. box.find('img').attr('src', src);
  12147. box.find('a').click(function(){
  12148. box.hide();
  12149. });
  12150. box.dblclick(function(){
  12151. box.hide();
  12152. });
  12153. };
  12154. // 下载模板
  12155. $scope.download = function() {
  12156. window.location.href = 'deputyOrder/upload/template';
  12157. };
  12158. $scope.enSure = function() {
  12159. $modalInstance.close($scope.result.items);
  12160. }
  12161. $scope.cancel = function() {
  12162. $modalInstance.dismiss();
  12163. }
  12164. }]);
  12165. /**
  12166. * 代采详情
  12167. */
  12168. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal) {
  12169. BaseService.scrollBackToTop();
  12170. var loadData = function() {
  12171. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  12172. $scope.deOrder = data;
  12173. $scope.deOrder.$editing = false;
  12174. });
  12175. };
  12176. loadData();
  12177. // 查询历史供应商
  12178. DeputyOrder.hisvendors({}, function(data) {
  12179. $scope.hisvendors = data;
  12180. }, function(response) {
  12181. toaster.pop('error', '提示', response.data);
  12182. });
  12183. // 代采企业列表
  12184. DeputyOrder.deputyEnterprise({}, function(data) {
  12185. $scope.deputyEnterprises = data;
  12186. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  12187. // 费率
  12188. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  12189. $scope.rate = data;
  12190. }, function(response){
  12191. });
  12192. });
  12193. // 更新代采企业时更新费率
  12194. $scope.change = function(deputyuu) {
  12195. // 费率
  12196. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  12197. $scope.rate = data;
  12198. }, function(response){
  12199. });
  12200. }
  12201. // 查找付款企业
  12202. $scope.dbfindPayCompany = function(deputyuu) {
  12203. var modalInstance = $modal.open({
  12204. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  12205. controller: 'DbfindDeputyPayCompanyCtrl',
  12206. resolve: {
  12207. deputyuu: function() {return deputyuu}
  12208. }
  12209. });
  12210. modalInstance.result.then(function(data) {
  12211. $scope.deOrder.paycomname = data.enname;
  12212. $scope.deOrder.paycomaddress = data.address;
  12213. })
  12214. }
  12215. // 删除明细
  12216. $scope.del = function(index, id) {
  12217. DeputyOrder.deleteProdById({id: id}, {}, function(data) {
  12218. if(data.success) {
  12219. toaster.pop('success', '提示', data.success);
  12220. $scope.deOrder.deputyOrderItems.splice(index, 1)
  12221. }
  12222. if(data.error) {
  12223. toaster.pop('error', '提示', data.error);
  12224. }
  12225. $scope.deOrder.totalamount = 0;
  12226. $scope.deOrder.usdpayment = 0;
  12227. $scope.deOrder.orderamount = 0;
  12228. $scope.deOrder.totalpayament = 0;
  12229. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12230. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12231. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12232. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  12233. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12234. });
  12235. }, function(response) {
  12236. toaster.pop('error', '提示', response.data);
  12237. });
  12238. }
  12239. //增加商品
  12240. $scope.add = function(index) {
  12241. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  12242. toaster.pop('info', '提示', '请先填写商品信息');
  12243. }else {
  12244. $scope.deOrder.deputyOrderItems.push(
  12245. { prodname: null,
  12246. prodcode: null,
  12247. prodspec: null,
  12248. prodbrand: null,
  12249. amount: null,
  12250. unitprice: null,
  12251. remark: null,
  12252. orderprice: null});
  12253. }
  12254. };
  12255. // 导入商品信息
  12256. $scope.uplodaByBatch = function() {
  12257. var modalInstance = $modal.open({
  12258. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  12259. controller: 'DeputyOrderUploadCtrl',
  12260. size: 'lg',
  12261. resolve: {
  12262. }
  12263. });
  12264. modalInstance.result.then(function(data) {
  12265. angular.forEach(data, function(data) {
  12266. $scope.deOrder.deputyOrderItems.push(data);
  12267. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  12268. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  12269. $scope.deOrder.deputyOrderItems.splice(i, 1);
  12270. }
  12271. }
  12272. })
  12273. $scope.deOrder.totalamount = 0;
  12274. $scope.deOrder.usdpayment = 0;
  12275. $scope.deOrder.orderamount = 0;
  12276. $scope.deOrder.totalpayament = 0;
  12277. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12278. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12279. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12280. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12281. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  12282. });
  12283. }, function(){
  12284. });
  12285. }
  12286. //删除商品
  12287. $scope.delItem = function(index) {
  12288. $scope.deOrder.deputyOrderItems.splice(index, 1);
  12289. };
  12290. var getService = function() {
  12291. return DeputyOrder.getProdList;
  12292. };
  12293. $scope.update = function() {
  12294. $scope.deOrder.$editing = true;
  12295. }
  12296. $scope.cancel = function() {
  12297. $scope.deOrder.$editing = false;
  12298. }
  12299. // 检验订单编号是否存在
  12300. $scope.checkOrder = function(salecode, deputyuu) {
  12301. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  12302. if(data.info) {
  12303. toaster.pop('error', '提示', data.info);
  12304. }
  12305. }, function(response) {
  12306. toaster.pop('error', '提示', response.data);
  12307. })
  12308. }
  12309. //计算采购单价
  12310. $scope.checkPrice = function(rate) {
  12311. if(rate == null) {
  12312. toaster.pop('info', '提示', '请先填入税率');
  12313. } else {
  12314. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12315. item.purcprice = item.unitprice * (1 + rate/100);
  12316. });
  12317. }
  12318. }
  12319. // 保存
  12320. $scope.save = function() {
  12321. $scope.deOrder.entrystatus = '保存';
  12322. $scope.deOrder.totalamount = 0;
  12323. $scope.deOrder.usdpayment = 0;
  12324. $scope.deOrder.orderamount = 0;
  12325. $scope.deOrder.totalpayament = 0;
  12326. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12327. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12328. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12329. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12330. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  12331. });
  12332. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  12333. toaster.pop('info', '提示', '您还未填写任何商品信息');
  12334. } else {
  12335. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  12336. if(data.id) {
  12337. toaster.pop('success', '提示', '保存成功');
  12338. loadData();
  12339. }
  12340. if(data.error) {
  12341. toaster.pop('error', '提示', '保存失败');
  12342. }
  12343. }, function(response) {
  12344. });
  12345. }
  12346. }
  12347. // 提交
  12348. $scope.submit = function() {
  12349. $scope.deOrder.entrystatus = '已提交';
  12350. $scope.deOrder.totalamount = 0;
  12351. $scope.deOrder.usdpayment = 0;
  12352. $scope.deOrder.orderamount = 0;
  12353. $scope.deOrder.totalpayament = 0;
  12354. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12355. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12356. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12357. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12358. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  12359. });
  12360. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  12361. if(data.id) {
  12362. toaster.pop('success', '提示', '提交成功');
  12363. window.location.hash = "#/purc/deputy/"+data.id;
  12364. }
  12365. if(data.error) {
  12366. toaster.pop('error', '提示', '保存失败');
  12367. }
  12368. }, function(response) {
  12369. });
  12370. }
  12371. $scope.openDatePicker = function($event, deOrder, openParam) {
  12372. $event.preventDefault();
  12373. $event.stopPropagation();
  12374. deOrder[openParam] = !deOrder[openParam];
  12375. };
  12376. }]);
  12377. /**
  12378. * 代采错误日志
  12379. */
  12380. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  12381. BaseService.scrollBackToTop();
  12382. var getService = function() {
  12383. return DeputyOrder.getRepetitions;
  12384. };
  12385. $scope.tableParams = new ngTableParams({
  12386. page : 1,
  12387. count : 20,
  12388. sorting: {
  12389. }
  12390. }, {
  12391. total : 0,
  12392. counts: [5, 10, 25, 50],
  12393. getData : function($defer, params) {
  12394. $scope.loading = true;
  12395. var pageParams = params.url();
  12396. pageParams.keyword = $scope.keyword;
  12397. pageParams.searchFilter = $scope.searchFilter;
  12398. getService().call(null, BaseService.parseParams(pageParams), function(page){
  12399. $scope.loading = false;
  12400. if(page) {
  12401. params.total(page.totalElement);
  12402. $defer.resolve(page.content);
  12403. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12404. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  12405. }
  12406. }, function(response) {
  12407. $scope.loading = false;
  12408. toaster.pop('error', '数据加载失败', response.data);
  12409. });
  12410. }
  12411. });
  12412. // 搜索框回车
  12413. $scope.onSearch = function() {
  12414. $scope.tableParams.page(1);
  12415. $scope.tableParams.reload();
  12416. };
  12417. //删除
  12418. $scope.deleteById = function(id) {
  12419. GetProductInfo.deleteById({id: id}, function(data) {
  12420. if(data.error) {
  12421. toaster.pop("error", "提示", data.error);
  12422. } else {
  12423. toaster.pop("success", "提示", "删除成功");
  12424. $timeout(function() {
  12425. $scope.tableParams.reload();
  12426. }, 500);
  12427. }
  12428. }), function(response) {
  12429. toaster.pop("error", "删除失败", response.data);
  12430. };
  12431. }
  12432. }]);
  12433. /**
  12434. * 招标单
  12435. */
  12436. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  12437. BaseService.scrollBackToTop();
  12438. if ($rootScope.tenderActive) {
  12439. $scope.active = $rootScope.tenderActive;
  12440. $rootScope.tenderActive = null;
  12441. } else {
  12442. $scope.active = 'done';
  12443. }
  12444. $scope.dateZoneText = '不限';
  12445. $scope.deliveryZoneText = '不限';
  12446. $scope.condition = {dateZone: -1, deliveryZone: -1};
  12447. $scope.changeDateZone = function(zone) {
  12448. $scope.condition.dateZone = zone;
  12449. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  12450. $scope.condition.$dateZoneOpen = false;
  12451. getDateCondition(zone, $scope.condition);
  12452. $scope.tableParams.reload();
  12453. };
  12454. $scope.changeDeliveryZone = function(zone) {
  12455. $scope.condition.deliveryZoneText = zone;
  12456. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  12457. $scope.condition.$delievryZoneOpen = false;
  12458. getDelveryCondition(zone, $scope.condition);
  12459. $scope.tableParams.reload();
  12460. };
  12461. $scope.setActive = function(state) {
  12462. if($scope.active != state) {
  12463. $scope.active = state;
  12464. if($scope.tableParams.page() == 1)
  12465. $scope.tableParams.reload();
  12466. else
  12467. $scope.tableParams.page(1);
  12468. }
  12469. };
  12470. var getTenderStatus = function(active) {
  12471. var fn = 'getMyAll';
  12472. switch(active) {
  12473. case 'done':
  12474. fn = 'getMyDone';break;
  12475. case 'todo':
  12476. fn = 'getMyTodo';break;
  12477. // case 'end':
  12478. // fn = 'getMyEnd';break;
  12479. case 'waiting':
  12480. fn = 'getMyWaiting';break;
  12481. }
  12482. return fn;
  12483. }
  12484. $scope.tableParams = new ngTableParams({
  12485. page : 1,
  12486. count : 20,
  12487. sorting: {
  12488. 'tender.endDate': 'desc',
  12489. 'tender.enterprise.enName': 'asc',
  12490. 'tender.code': 'asc'
  12491. }
  12492. }, {
  12493. total : 0,
  12494. counts: [5, 10, 25, 50],
  12495. getData : function($defer, params) {
  12496. $scope.loading = true;
  12497. var pageParams = params.url();
  12498. var realActive = {};
  12499. pageParams.searchFilter = { // 筛选条件
  12500. keyword: $scope.keyword,
  12501. fromDate: getDateTime($scope.condition.dateFrom),
  12502. endDate: getDateTime($scope.condition.dateTo)
  12503. };
  12504. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  12505. $scope.loading = false;
  12506. if(page) {
  12507. params.total(page.totalElement);
  12508. $defer.resolve(page.content);
  12509. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  12510. }
  12511. }, function(response){
  12512. $scope.loading = false;
  12513. toaster.pop('error', '数据加载失败', response.data);
  12514. });
  12515. }
  12516. });
  12517. $scope.openDatePicker = function($event, item, openParam) {
  12518. $event.preventDefault();
  12519. $event.stopPropagation();
  12520. item[openParam] = !item[openParam];
  12521. };
  12522. $scope.parseDate = function(dateStr) {
  12523. if(dateStr)
  12524. return Date.parse(dateStr, 'yyyy-MM-dd');
  12525. return new Date();
  12526. };
  12527. // 选择查找日期
  12528. $scope.onDateCondition = function(){
  12529. $scope.tableParams.page(1);
  12530. $scope.tableParams.reload();
  12531. };
  12532. // 搜索框回车
  12533. $scope.onSearch = function() {
  12534. $scope.tableParams.page(1);
  12535. $scope.tableParams.reload();
  12536. };
  12537. }]);
  12538. /**
  12539. * 新增招标单
  12540. */
  12541. 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) {
  12542. // 录入人
  12543. AuthenticationService.getAuthentication().success(function(data) {
  12544. $scope.user = data;
  12545. });
  12546. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12547. var getService = function() {
  12548. return GetProductInfo;
  12549. };
  12550. // 物料信息
  12551. $scope.tableParams = new ngTableParams({
  12552. page : 1,
  12553. count : 20,
  12554. sorting: {
  12555. }
  12556. }, {
  12557. total : 0,
  12558. counts: [5, 10, 25, 50],
  12559. getData : function($defer, params) {
  12560. $scope.loading = true;
  12561. var pageParams = params.url();
  12562. pageParams.keyword = $scope.keyword;
  12563. $scope.tip = $scope.keyword;
  12564. pageParams.searchFilter = $scope.searchFilter;
  12565. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  12566. $scope.loading = false;
  12567. if(page) {
  12568. params.total(page.totalElement);
  12569. $scope.total = page.totalElement;
  12570. $defer.resolve(page.content);
  12571. }
  12572. }, function(response) {
  12573. $scope.loading = false;
  12574. toaster.pop('error', '数据加载失败', response.data);
  12575. });
  12576. }
  12577. });
  12578. // 搜索框回车
  12579. $scope.onSearch = function(keyword) {
  12580. $scope.tableParams.page(1);
  12581. $scope.tableParams.reload();
  12582. };
  12583. //在产品列表添加商品
  12584. $scope.check = function(product) {
  12585. $scope.tenderProd.push({
  12586. prodTitle: product.title,
  12587. prodCode: product.code,
  12588. brand: product.brand,
  12589. unit: product.unit,
  12590. qty: null
  12591. // 供应商企业信息
  12592. // enterpriseBaseInfo: [{}]
  12593. });
  12594. for(var i = 0; i < $scope.tenderProd.length; i++) {
  12595. if($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  12596. $scope.tenderProd.splice(i, 1);
  12597. }
  12598. }
  12599. };
  12600. $scope.loading = false;
  12601. // 获取收货地址列表
  12602. var loadShipAddress = function() {
  12603. ShipAddress.shipAddList({}, function(data) {
  12604. $scope.ships = data;
  12605. $scope.tender.shipadd = $scope.ships[0];
  12606. });
  12607. };
  12608. loadShipAddress();
  12609. // 获取地址信息
  12610. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  12611. }).then(function(response) {
  12612. $scope.provinces = response.data;
  12613. });
  12614. // 新增收货地址保存
  12615. $scope.saveShipAddress = function(ship) {
  12616. ship.address = ship.province + ship.city + ship.district;
  12617. ShipAddress.saveAddress( {}, ship, function(data) {
  12618. if(data.success) {
  12619. // 获取收货地址列表
  12620. loadShipAddress();
  12621. toaster.pop('success', '提示', data.success);
  12622. }
  12623. if(data.error) {
  12624. toaster.pop('error', '提示', data.error);
  12625. }
  12626. });
  12627. };
  12628. // 可选的证照要求
  12629. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  12630. // 处理证照要求
  12631. var parseCertificate = function(a) {
  12632. if (a) {
  12633. var arr = a.split(',');
  12634. angular.forEach(arr, function(app) {
  12635. var contained = false;
  12636. angular.forEach($scope.certificates, function($app) {
  12637. if($app.name == app) {
  12638. $app.checked = true;
  12639. contained = true;
  12640. }
  12641. });
  12642. if(!contained) {
  12643. $scope.certificates.push({name: app, checked: true});
  12644. }
  12645. });
  12646. }
  12647. };
  12648. // 联想词start
  12649. // 获取品牌联想词
  12650. $scope.getSimilarBrands = function(value) {
  12651. if (value) {
  12652. // 获取品牌联想词
  12653. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  12654. return data.map(function(item) {
  12655. return item;
  12656. });
  12657. });
  12658. }
  12659. };
  12660. // 获取产品型号联想词
  12661. $scope.getSimilarCodes = function(value) {
  12662. if (value) {
  12663. // 获取产品型号联想词
  12664. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  12665. return data.map(function (item) {
  12666. return item;
  12667. })
  12668. });
  12669. }
  12670. };
  12671. // // 获取产品类目联想词
  12672. // $scope.getSimilarKinds = function(value) {
  12673. // if (value) {
  12674. // // getSimilarLeafKinds 根据类目名获取末级联想词
  12675. // // 获取类目联想词
  12676. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  12677. // return data.map(function(item) {
  12678. // return item;
  12679. // })
  12680. // });
  12681. // }
  12682. // };
  12683. // // 点击联想词获取类目信息
  12684. // $scope.onAssociateKindClick = function(kind, submit) {
  12685. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  12686. // $scope.actives = data;
  12687. // console.log(data);
  12688. // var size = data.length;
  12689. // if (size > 0) {
  12690. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  12691. // submit.kiName = submit.gradeOneKiName;
  12692. // if (size > 1) {
  12693. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  12694. // submit.kiName = submit.gradeTwoKiName;
  12695. // if (kind.level < 3) {
  12696. // submit.gradeThreeKiName = null;
  12697. // } else if (size > 2) {
  12698. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  12699. // submit.kiName = submit.gradeThreeKiName;
  12700. // }
  12701. // }
  12702. // }
  12703. // console.log(submit);
  12704. // })
  12705. // };
  12706. // 选择类目
  12707. $scope.selectKind = function(prod) {
  12708. var submit = [];
  12709. $modal.open({
  12710. animation: true,
  12711. size: 'lg',
  12712. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  12713. controller: 'ProdKindChooseCtrl',
  12714. resolve: {
  12715. actives: function() {
  12716. return $scope.actives;
  12717. }
  12718. }
  12719. }).result.then(function(data){
  12720. $scope.actives = data.actives;
  12721. var size = data.actives.length;
  12722. submit.gradeOneKiName = '';
  12723. submit.gradeTwoKiName = '';
  12724. submit.gradeThreeKiName = '';
  12725. if (size > 0) {
  12726. submit.gradeOneKiName = $scope.actives[0].nameCn;
  12727. prod.prodTitle = submit.gradeOneKiName;
  12728. if (size > 1) {
  12729. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  12730. prod.prodTitle = submit.gradeTwoKiName;
  12731. if (size > 2) {
  12732. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  12733. prod.prodTitle = submit.gradeThreeKiName;
  12734. }
  12735. }
  12736. }
  12737. }, function(){
  12738. });
  12739. };
  12740. // // 验证分类信息
  12741. // $scope.checkKind = function() {
  12742. // setTimeout(function() {
  12743. // if($scope.activesString == null) {
  12744. // $scope.component.kindid = null;
  12745. // return;
  12746. // }
  12747. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  12748. // $scope.component.kind = kind;
  12749. // $scope.component.kindid = kind.id;
  12750. // $scope.activesString = $scope.component.kind.nameCn;
  12751. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  12752. // $scope.kindProperties = data;
  12753. // angular.forEach($scope.kindProperties, function(kp) {
  12754. // angular.forEach($scope.component.properties, function(pro) {
  12755. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  12756. // kp.value = pro.value;
  12757. // }
  12758. // });
  12759. // });
  12760. // }, function(response) {
  12761. // });
  12762. // }, function (response) {
  12763. // $scope.component.kindid = null;
  12764. // toaster.pop('error', response.data);
  12765. // });
  12766. // }, 500);
  12767. // };
  12768. // 点击联想词获取品牌信息
  12769. $scope.onAssociateBrandClick = function(brand, prod) {
  12770. if (brand instanceof String) {
  12771. prod.brand = brand;
  12772. } else if (brand instanceof Object) {
  12773. prod.brand = brand.brandCn;
  12774. }
  12775. };
  12776. // 打开品牌选择的模态框
  12777. $scope.selectBrand = function(prod){ //打开模态
  12778. var modalInstance = $modal.open({
  12779. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  12780. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  12781. });
  12782. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  12783. });
  12784. modalInstance.result.then(function(brand){
  12785. prod.brand = brand.nameCn;
  12786. }, function(reason){
  12787. });
  12788. };
  12789. // // 验证品牌是否正确
  12790. // $scope.checkBrand = function () {
  12791. // setTimeout(function () {
  12792. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  12793. // // $scope.component.brand = brand;
  12794. // // $scope.component.brandid = brand.id;
  12795. // }, function (response) {
  12796. // // $scope.component.brandid = null;
  12797. // toaster.pop('error', response.data);
  12798. // })
  12799. // } , 500);
  12800. // };
  12801. // 点击联想词获取器件信息 带入产品分类和品牌
  12802. $scope.onAssociateCmpClick = function(cmp, prod) {
  12803. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  12804. $scope.component = data;
  12805. prod.prodCode = data.code;
  12806. prod.prodTitle = data.kind.nameCn;
  12807. prod.brand = data.brand.nameCn;
  12808. }, function(res) {
  12809. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  12810. })
  12811. };
  12812. //联想词end
  12813. $scope.condition = {dateZone: 1};
  12814. $scope.tenderProd = [];
  12815. var prod = {
  12816. prodTitle: null,
  12817. prodCode: null,
  12818. brand: null,
  12819. unit: 'PCS',
  12820. qty: null
  12821. // 供应商企业信息
  12822. // enterpriseBaseInfo: [{}]
  12823. };
  12824. $scope.tender = {
  12825. date: new Date(),
  12826. unit: 'PCS',
  12827. currency: 'RMB',
  12828. ifOpen: 1,
  12829. ifTax: 1,
  12830. invoiceType: 2,
  12831. tenderAttachs:[{}]
  12832. };
  12833. //
  12834. $scope.tenderProd.push(prod);
  12835. //增加商品
  12836. $scope.add = function(index) {
  12837. $scope.tenderProd.push({
  12838. prodTitle: null,
  12839. prodCode: null,
  12840. brand: null,
  12841. unit: 'PCS',
  12842. qty: null
  12843. // 供应商企业信息
  12844. // enterpriseBaseInfo: [{}]
  12845. });
  12846. };
  12847. //删除商品
  12848. $scope.del = function(index) {
  12849. $scope.tenderProd.splice(index, 1);
  12850. };
  12851. // 批量导入
  12852. $scope.uplodaByBatch = function() {
  12853. var modalInstance = $modal.open({
  12854. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  12855. controller: 'PurcTenderUploadCtrl',
  12856. size: 'lg',
  12857. resolve: {
  12858. }
  12859. });
  12860. modalInstance.result.then(function(data) {
  12861. // 获取上传的产品明细,前台展示
  12862. angular.forEach(data, function(data) {
  12863. $scope.tenderProd.push(data);
  12864. for(var i = 0; i < $scope.tenderProd.length; i++) {
  12865. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  12866. $scope.tenderProd.splice(i, 1);
  12867. }
  12868. }
  12869. });
  12870. }, function(){
  12871. });
  12872. };
  12873. $scope.isSave = false;
  12874. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  12875. if( ! angular.isUndefined($stateParams.id)) {
  12876. $scope.isSave = true; // 用于判断是新增还是已保存
  12877. $scope.loading = true;
  12878. PurcTender.getOne({id: $stateParams.id}, function(data){
  12879. data.$editing = false;
  12880. $scope.tender = data;
  12881. $scope.tenderProd = data.purchaseTenderProds;
  12882. parseCertificate($scope.tender.certificate);
  12883. $scope.firstProd = data.purchaseTenderProds[0];
  12884. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  12885. // 获取供应商联系人
  12886. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function(data) {
  12887. item.saleTender.enterpriseBaseInfo.contacts = data;
  12888. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  12889. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function(contact) {
  12890. if (item.saleTender.userTel === contact.tel) {
  12891. item.saleTender.enterpriseBaseInfo.contact = contact;
  12892. }
  12893. });
  12894. });
  12895. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  12896. $scope.tenderProd.enterpriseBaseInfo = [{}];
  12897. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  12898. } else {
  12899. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  12900. }
  12901. });
  12902. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  12903. $scope.loading = false;
  12904. $scope.attaches = $scope.tender.tenderAttaches;
  12905. }, function(response){
  12906. $scope.loading = false;
  12907. toaster.pop('error', '数据加载失败', response.data);
  12908. });
  12909. }
  12910. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  12911. $rootScope.tenderVendor = [{}];
  12912. }
  12913. $scope.changeShipAddress = false;
  12914. $scope.changeAddress = function() {
  12915. if ($scope.changeShipAddress) {
  12916. $scope.changeShipAddress = false;
  12917. } else {
  12918. $scope.changeShipAddress = true;
  12919. }
  12920. };
  12921. $scope.changeContactInfo = function(en) {
  12922. if (en.changeContact) {
  12923. en.changeContact = false;
  12924. } else {
  12925. en.changeContact = true;
  12926. }
  12927. };
  12928. $scope.changeCurrency = function(tender) {
  12929. if (tender.currency !== 'RMB') {
  12930. $scope.notRMB = true;
  12931. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  12932. tender.invoiceType = 0;
  12933. } else {
  12934. $scope.notRMB = false;
  12935. }
  12936. };
  12937. // $scope.validateNumber = function (value) { // 采购数量 正整数
  12938. // var regex = /^\+?[1-9][0-9]*$/;
  12939. // if (!regex.test(value) || value === 0 || value === null) {
  12940. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  12941. // }
  12942. // };
  12943. // 查找供应商
  12944. $scope.dbfindVendor = function(){
  12945. var modalInstance = $modal.open({
  12946. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  12947. controller: 'DbfindVendorCtrl',
  12948. size: 'lg',
  12949. resolve: {
  12950. }
  12951. });
  12952. var ifPush = true;
  12953. modalInstance.result.then(function(data){
  12954. angular.forEach(data, function(vendor) {
  12955. // 获取供应商联系人
  12956. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function(data) {
  12957. vendor.vendorEnterprise.contacts = data;
  12958. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  12959. });
  12960. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  12961. $scope.tenderProd.enterpriseBaseInfo = [{}];
  12962. // 获取供应商联系人
  12963. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  12964. } else {
  12965. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  12966. ifPush = true;
  12967. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  12968. ifPush = false;
  12969. break; // 判定到已存在供应商,就终止循环。
  12970. }
  12971. }
  12972. if (ifPush) {
  12973. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  12974. }
  12975. }
  12976. });
  12977. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  12978. }, function(){
  12979. });
  12980. };
  12981. // 新增供应商联系人
  12982. $scope.addContact = function(en) {
  12983. var modalInstance = $modal.open({
  12984. animation: true,
  12985. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  12986. controller: 'AddContacCtrl',
  12987. resolve: {
  12988. }
  12989. });
  12990. modalInstance.result.then(function(data) {
  12991. en.contact = data;
  12992. en.contact.venduu = en.uu;
  12993. Vendor.saveContact({}, en.contact, function(data) {
  12994. Vendor.contacts({venduu: en.uu}, {}, function(data) {
  12995. en.contacts = data;
  12996. en.contact = data[0]; // 新增的作为联系人
  12997. });
  12998. toaster.pop('success', '提示', '联系人保存成功');
  12999. }, function(response) {
  13000. toaster.pop('error', '失败', response.data);
  13001. });
  13002. });
  13003. };
  13004. // 删除一个供应商
  13005. $scope.removeVendor = function(index) {
  13006. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  13007. };
  13008. // 删除供应商时,后台删除投标单
  13009. $scope.removeSaleTender = function (id, vendUU) {
  13010. var hasSaved = false;
  13011. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  13012. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  13013. hasSaved = true;
  13014. }
  13015. });
  13016. if (hasSaved) {
  13017. PurcTender.removeSaleTender ({id : id, vendUU : vendUU}, {}, function(data) {
  13018. }, function(response) {
  13019. toaster.pop('error', '提示', response.data);
  13020. });
  13021. }
  13022. };
  13023. // 删除产品明细时,后台删除产品明细
  13024. $scope.deleteProd = function (tenderProd) {
  13025. if (tenderProd.id) {
  13026. PurcTender.deleteProd ({tenderProdId : tenderProd.id}, {}, function(data) {
  13027. }, function(response) {
  13028. toaster.pop('error', '提示', response.data);
  13029. });
  13030. }
  13031. };
  13032. // // 查找客户物料
  13033. // $scope.dbfindCustProd = function(){
  13034. // if($scope.item.$editing) {
  13035. // if($scope.item.quotation.cust.uu) {
  13036. // var modalInstance = $modal.open({
  13037. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  13038. // controller: 'DbfindCustProdCtrl',
  13039. // size: 'lg',
  13040. // resolve: {
  13041. // custUU: function(){return $scope.item.quotation.cust.uu}
  13042. // }
  13043. // });
  13044. //
  13045. // modalInstance.result.then(function(data){
  13046. // $scope.item.product = data;
  13047. // }, function(){
  13048. //
  13049. // });
  13050. // } else {
  13051. // toaster.pop('error', '错误', '请先选择客户');
  13052. // }
  13053. // }
  13054. // };
  13055. if (!$scope.attaches) {
  13056. $scope.attaches = []; // 存放上传了的附件
  13057. }
  13058. $scope.upload = function(myFile) { // 上传附件
  13059. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  13060. $upload.upload({
  13061. url: 'tender/addTenderAttach',
  13062. file: file,
  13063. method: 'POST'
  13064. // data: {
  13065. // tender: $scope.tender
  13066. // }
  13067. }).success(function (attach) {
  13068. $scope.attaches.push(attach);
  13069. });
  13070. };
  13071. $scope.removeAttach = function(id, index) {
  13072. $scope.attaches.splice(index, 1);
  13073. // PurcTender.removeAttach({attachId:id}, function() {
  13074. //
  13075. // });
  13076. };
  13077. var sleep = function (d){
  13078. for(var t = Date.now();Date.now() - t <= d;);
  13079. };
  13080. // 保存和发布招标单
  13081. $scope.save = function(isPublish){
  13082. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  13083. toaster.pop('info','提示','请先指定供应商');
  13084. } else {
  13085. $scope.loading = true;
  13086. // --组装证照要求
  13087. var myCertificate = [];
  13088. angular.forEach($scope.certificates, function(certificate) {
  13089. if (certificate.checked) {
  13090. myCertificate.push(certificate.name);
  13091. }
  13092. });
  13093. $scope.tender.certificate = myCertificate.join(',');
  13094. if(!$scope.tender.code) { //新增,设单号
  13095. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  13096. }
  13097. if($scope.tender.date instanceof Date) {
  13098. $scope.tender.date = $scope.tender.date.getTime();
  13099. }
  13100. if($scope.tender.endDate instanceof Date) {
  13101. $scope.tender.endDate = $scope.tender.endDate.getTime();
  13102. }
  13103. if($scope.tender.publishDate instanceof Date) {
  13104. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  13105. }
  13106. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  13107. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  13108. $scope.tender.purchaseTenderProds[i].index = i + 1;
  13109. }
  13110. $scope.tender.tenderAttaches = $scope.attaches;
  13111. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  13112. var enInfos = [];
  13113. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  13114. var enInfo = {
  13115. uu: null,
  13116. contact: null,
  13117. contactTel: null
  13118. };
  13119. enInfo.uu = enterpriseBaseInfo.uu;
  13120. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  13121. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  13122. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  13123. }
  13124. enInfos.push(enInfo);
  13125. });
  13126. if (isPublish) { // 发布
  13127. toaster.pop('info', '提示', '正在发布,请稍候');
  13128. $scope.tender.isPublish = 1;
  13129. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  13130. // sleep(1500); //当前方法暂停1.5秒
  13131. $scope.loading = false;
  13132. toaster.pop('success', '成功', '发布成功');
  13133. window.location.hash = '#/purc/tender';
  13134. }, function(response){
  13135. $scope.loading = false;
  13136. toaster.pop('error', '发布失败', response.data);
  13137. });
  13138. } else { // 保存
  13139. toaster.pop('info', '提示', '正在保存,请稍候');
  13140. $scope.tender.isPublish = 0;
  13141. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  13142. $scope.loading = false;
  13143. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  13144. toaster.pop('success', '成功', '保存成功');
  13145. window.location.hash = '#/purc/tender';
  13146. }, function(response){
  13147. $scope.loading = false;
  13148. toaster.pop('error', '保存失败', response.data);
  13149. });
  13150. }
  13151. }
  13152. };
  13153. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  13154. $scope.removeChecked = function() {
  13155. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  13156. $scope.tenderProd.enterpriseBaseInfo = [];
  13157. }
  13158. };
  13159. // 删除(在录入状态)
  13160. $scope.deleteThis = function(id) {
  13161. PurcTender.deleteOne({id:id}, {}, function(data) {
  13162. toaster.pop('info', '提示', '删除成功');
  13163. window.location.hash = '#/purc/tender';
  13164. });
  13165. };
  13166. // 更新和发布(在录入状态)
  13167. $scope.updateSaved = function(isPublish){
  13168. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  13169. toaster.pop('info','提示','请先指定供应商');
  13170. } else {
  13171. $scope.loading = true;
  13172. // --组装证照要求
  13173. var myCertificate = [];
  13174. angular.forEach($scope.certificates, function(certificate) {
  13175. if (certificate.checked) {
  13176. myCertificate.push(certificate.name);
  13177. }
  13178. });
  13179. $scope.tender.certificate = myCertificate.join(',');
  13180. if($scope.tender.endDate instanceof Date) {
  13181. $scope.tender.endDate = $scope.tender.endDate.getTime();
  13182. }
  13183. if($scope.tender.publishDate instanceof Date) {
  13184. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  13185. }
  13186. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  13187. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  13188. $scope.tender.purchaseTenderProds[i].index = i + 1;
  13189. }
  13190. $scope.tender.tenderAttaches = $scope.attaches;
  13191. if ($scope.tender.shipadd) {
  13192. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  13193. }
  13194. angular.forEach($scope.tender.purchaseTenderProds, function(tenderProd){
  13195. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  13196. });
  13197. var enInfos = [];
  13198. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  13199. var enInfo = {
  13200. uu: null,
  13201. contact: null,
  13202. contactTel: null
  13203. };
  13204. enInfo.uu = enterpriseBaseInfo.uu;
  13205. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  13206. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  13207. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  13208. }
  13209. enInfos.push(enInfo);
  13210. });
  13211. if (isPublish) { // 发布
  13212. toaster.pop('info', '提示', '正在发布,请稍候');
  13213. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  13214. sleep(1500); //当前方法暂停1.5秒
  13215. // $scope.loading = false;
  13216. toaster.pop('success', '成功', '发布成功');
  13217. window.location.hash = '#/purc/tender';
  13218. }, function(response){
  13219. $scope.loading = false;
  13220. toaster.pop('error', '发布失败', response.data);
  13221. });
  13222. } else { // 保存
  13223. toaster.pop('info', '提示', '正在保存,请稍候');
  13224. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  13225. $scope.loading = false;
  13226. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  13227. toaster.pop('success', '成功', '保存成功');
  13228. window.location.reload();
  13229. }, function(response){
  13230. $scope.loading = false;
  13231. toaster.pop('error', '保存失败', response.data);
  13232. });
  13233. }
  13234. }
  13235. };
  13236. $scope.currentDay = function() {
  13237. return $filter('date')(new Date(), 'yyyy-MM-dd');
  13238. };
  13239. $scope.getMinDate = function() {
  13240. // var now = new Date();
  13241. // now = now.setDate(now.getDate()+1);
  13242. // var minDate = angular.copy($scope.tender.endDate);
  13243. // minDate = minDate.setDate(minDate.getDate() + 1);
  13244. if ($scope.tender.endDate instanceof Date) {
  13245. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  13246. }
  13247. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  13248. };
  13249. $scope.getMaxDate = function() {
  13250. // var maxDate = angular.copy($scope.tender.publishDate);
  13251. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  13252. if ($scope.tender.publishDate instanceof Date) {
  13253. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  13254. }
  13255. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  13256. };
  13257. $scope.openDatePicker = function($event, item, openParam) {
  13258. $event.preventDefault();
  13259. $event.stopPropagation();
  13260. item[openParam] = !item[openParam];
  13261. };
  13262. }]);
  13263. //类目选择模态框(招标产品明细)
  13264. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  13265. $scope.actives = actives;
  13266. $scope.kinds = [[], [], [], []];
  13267. // 获取子类目
  13268. var getChildren = function(pid, deep) {
  13269. KindAPI.getChildren({parentId: pid}, function(data) {
  13270. $scope.kinds[deep] = data;
  13271. }, function(response) {
  13272. toaster.pop('error', '获取子类目失败', response.data);
  13273. });
  13274. };
  13275. // 改变节点选中状态
  13276. var changeStatus = function(item, deep) {
  13277. var actives = [], level = 0;
  13278. angular.forEach($scope.kinds, function(ks, i) {
  13279. if(i > deep) {
  13280. $scope.kinds[i] = [];
  13281. } else {
  13282. angular.forEach(ks, function(k, j) {
  13283. if(i == deep) {
  13284. if(k.id == item.id) {
  13285. $scope.kinds[i][j].$active = true;
  13286. actives.push(k);
  13287. } else {
  13288. k.$active = null;
  13289. }
  13290. } else {
  13291. if(k.$active) {
  13292. actives.push(k);
  13293. }
  13294. }
  13295. });
  13296. }
  13297. });
  13298. // 选择的节点
  13299. $scope.actives = actives;
  13300. $scope.active = item;
  13301. // 当前可操作的层级
  13302. if(deep < 3) {
  13303. $scope.activeDeep = deep + 1;
  13304. }
  13305. };
  13306. // 节点点击后获取子类目,节点被选中
  13307. $scope.onItemClick = function(item, deep) {
  13308. changeStatus(item, deep);
  13309. if (!item.isLeaf) {
  13310. getChildren(item.id, deep + 1);
  13311. }
  13312. };
  13313. // 重新加载数据
  13314. function reload(deep) {
  13315. var pid;
  13316. if(deep) {
  13317. pid = $scope.actives[deep - 1].id;
  13318. } else {
  13319. pid = 0;
  13320. deep = 0;
  13321. }
  13322. getChildren(pid, deep);
  13323. }
  13324. // 初始加载数据,获取第一层的类目
  13325. if($scope.actives) {
  13326. angular.forEach($scope.actives, function(v, k) {
  13327. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  13328. $scope.kinds[k] = data;
  13329. angular.forEach($scope.kinds[k], function(kind, i){
  13330. if(kind.id == v.id) {
  13331. $scope.kinds[k][i].$active = true;
  13332. $scope.actives[k] = $scope.kinds[k][i];
  13333. }
  13334. })
  13335. }, function(response) {
  13336. toaster.pop('error', '获取子类目失败', response.data);
  13337. });
  13338. });
  13339. } else {
  13340. reload();
  13341. }
  13342. // 取消
  13343. $scope.cancel = function() {
  13344. $modalInstance.dismiss();
  13345. };
  13346. // 确认选择
  13347. $scope.check = function() {
  13348. var a = {
  13349. active: $scope.active,
  13350. actives: $scope.actives
  13351. };
  13352. $modalInstance.close(a);
  13353. };
  13354. }]);
  13355. //品牌选择模态框的controller
  13356. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  13357. $scope.filter = {};
  13358. $scope.brandsTableParams = new ngTableParams({
  13359. page : 1,
  13360. count : 6,
  13361. sorting : {
  13362. nameCn: 'asc'
  13363. }
  13364. }, {
  13365. total : 0,
  13366. counts : [],
  13367. getData : function($defer, params) {
  13368. var param = BaseService.parseParams(params.url());
  13369. param.keyword = $scope.filter.keyword;
  13370. var keyword = $scope.filter.keyword;
  13371. // param.keyword = $scope.filter.keyword;
  13372. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  13373. if (page) {
  13374. params.total(page.totalElement);
  13375. $defer.resolve(page.content);
  13376. }
  13377. }, function(){
  13378. });
  13379. }
  13380. });
  13381. // 搜索
  13382. $scope.search = function() {
  13383. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  13384. $scope.brandsTableParams.page(1);
  13385. $scope.brandsTableParams.reload();
  13386. };
  13387. // 选择
  13388. $scope.select = function(brand){
  13389. $modalInstance.close(brand);
  13390. };
  13391. // 关闭
  13392. $scope.cancel = function() {
  13393. $modalInstance.dismiss();
  13394. };
  13395. }]);
  13396. /**
  13397. * 招标单批量导入
  13398. */
  13399. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  13400. // 通过excel批量上传物料
  13401. $scope.result = null;
  13402. $scope.upload = function() {
  13403. var file = $scope.myFiles[0];
  13404. $upload.upload({
  13405. url: 'tender/release/excel',
  13406. file: file,
  13407. method: 'POST'
  13408. }).success(function(data) {
  13409. $scope.result = data;
  13410. $scope.success = $scope.result.success;
  13411. $scope.total = $scope.result.total;
  13412. $scope.alters = $scope.result.alters;
  13413. }).error(function(response) {
  13414. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  13415. });
  13416. };
  13417. // 查看范例
  13418. $scope.showImg = function() {
  13419. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  13420. box.show();
  13421. box.find('img').attr('src', src);
  13422. box.find('a').click(function(){
  13423. box.hide();
  13424. });
  13425. box.dblclick(function(){
  13426. box.hide();
  13427. });
  13428. };
  13429. // 下载模板
  13430. $scope.download = function() {
  13431. window.location.href = 'tender/upload/template';
  13432. };
  13433. $scope.enSure = function() {
  13434. $modalInstance.close($scope.result.items);
  13435. }
  13436. $scope.cancel = function() {
  13437. $modalInstance.dismiss();
  13438. }
  13439. }]);
  13440. /**
  13441. * 评标
  13442. */
  13443. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  13444. BaseService.scrollBackToTop();
  13445. $scope.tenderItems = [];
  13446. // 采购方获取评标单
  13447. var evaluation = function() {
  13448. $scope.loading = true;
  13449. PurcTender.getOne({id: $stateParams.id}, function(data){
  13450. data.$editing = false;
  13451. $scope.tender = data;
  13452. $scope.tableParams = new ngTableParams({}, { dataset: data});
  13453. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  13454. $scope.loading = false;
  13455. }, function(response){
  13456. $scope.loading = false;
  13457. toaster.pop('error', '数据加载失败', response.data);
  13458. });
  13459. };
  13460. evaluation();
  13461. $scope.orderType = '';
  13462. // $scope.dir = '-';
  13463. // 改变排序顺序
  13464. $scope.changeOrder = function(type){
  13465. $scope.orderType = type;
  13466. // if(!$scope.dir || $scope.dir === '') {
  13467. // $scope.dir = '-';
  13468. // }else {
  13469. // $scope.dir = '';
  13470. // }
  13471. };
  13472. $scope.submit = function(tender) {
  13473. var canSubmit = false;
  13474. var hasDecide = false;
  13475. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13476. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13477. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  13478. hasDecide = true;
  13479. }
  13480. });
  13481. if (hasDecide) {
  13482. canSubmit = true;
  13483. }
  13484. });
  13485. if (!canSubmit) {
  13486. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  13487. } else {
  13488. PurcTender.decide(tender, function(){
  13489. toaster.pop('success', '确认成功');
  13490. window.location.hash = '#/purc/tender';
  13491. }, function(response){
  13492. toaster.pop('error', '确认失败', response.data);
  13493. });
  13494. }
  13495. }
  13496. }]);
  13497. /**
  13498. * 客户招标
  13499. *
  13500. */
  13501. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  13502. BaseService.scrollBackToTop();
  13503. if($rootScope.active) {
  13504. $scope.active = $rootScope.active;
  13505. $rootScope.active = null;
  13506. } else {
  13507. $scope.active = 'todo';
  13508. }
  13509. /**
  13510. * 改变类型
  13511. */
  13512. var getTypeCondition = function(zone, condition) {
  13513. if(zone == -1) {
  13514. condition.ifOpen = null;
  13515. } else if(zone == 1) {
  13516. condition.ifOpen = 1;
  13517. } else {
  13518. condition.ifOpen = 0;
  13519. }
  13520. };
  13521. $scope.dateZoneText = '不限';
  13522. $scope.typeText = '全部';
  13523. $scope.deliveryZoneText = '不限';
  13524. $scope.condition = {dateZone: -1, deliveryZone: -1, type: -1};
  13525. $scope.changeDateZone = function(zone) {
  13526. $scope.condition.dateZone = zone;
  13527. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  13528. $scope.condition.$dateZoneOpen = false;
  13529. getDateCondition(zone, $scope.condition);
  13530. $scope.tableParams.reload();
  13531. };
  13532. $scope.changeDeliveryZone = function(zone) {
  13533. $scope.condition.deliveryZoneText = zone;
  13534. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  13535. $scope.condition.$delievryZoneOpen = false;
  13536. getDelveryCondition(zone, $scope.condition);
  13537. $scope.tableParams.reload();
  13538. };
  13539. $scope.changeType = function(type) {
  13540. $scope.condition.type = type;
  13541. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  13542. getTypeCondition(type, $scope.condition);
  13543. $scope.tableParams.reload();
  13544. };
  13545. $scope.setActive = function(state) {
  13546. if($scope.active != state) {
  13547. $scope.active = state;
  13548. if($scope.tableParams.page() == 1)
  13549. $scope.tableParams.reload();
  13550. else
  13551. $scope.tableParams.page(1);
  13552. }
  13553. };
  13554. $scope.tableParams = new ngTableParams({
  13555. page : 1,
  13556. count : 20,
  13557. sorting: {
  13558. 'tender.endDate': 'desc',
  13559. 'tender.enterprise.enName': 'asc',
  13560. 'tender.code': 'asc'
  13561. }
  13562. }, {
  13563. total : 0,
  13564. counts: [5, 10, 25, 50],
  13565. getData : function($defer, params) {
  13566. $scope.loading = true;
  13567. var pageParams = params.url();
  13568. var realActive = {};
  13569. pageParams.searchFilter = { // 筛选条件
  13570. keyword: $scope.keyword,
  13571. pt_ifopen: $scope.condition.ifOpen,
  13572. fromDate: getDateTime($scope.condition.dateFrom),
  13573. endDate: getDateTime($scope.condition.dateTo)
  13574. };
  13575. AccountEnterprise.get({}, function(data){
  13576. $scope.loading = false;
  13577. $scope.currentEn = data;
  13578. });
  13579. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  13580. $scope.loading = false;
  13581. if(page) {
  13582. params.total(page.totalElement);
  13583. $defer.resolve(page.content);
  13584. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  13585. angular.forEach(page.content, function(purcTender) {
  13586. purcTender.vendorHasBid = false;
  13587. angular.forEach(purcTender.purchaseTenderProds, function(tenderProd) {
  13588. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13589. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  13590. tenderProd.currentItem = saleTenderItem;
  13591. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  13592. purcTender.vendorHasBid = true;
  13593. }
  13594. }
  13595. });
  13596. });
  13597. });
  13598. }
  13599. }, function(response){
  13600. $scope.loading = false;
  13601. toaster.pop('error', '数据加载失败', response.data);
  13602. });
  13603. }
  13604. });
  13605. $scope.openDatePicker = function($event, item, openParam) {
  13606. $event.preventDefault();
  13607. $event.stopPropagation();
  13608. item[openParam] = !item[openParam];
  13609. };
  13610. $scope.parseDate = function(dateStr) {
  13611. if(dateStr)
  13612. return Date.parse(dateStr, 'yyyy-MM-dd');
  13613. return new Date();
  13614. };
  13615. // 选择查找日期
  13616. $scope.onDateCondition = function(){
  13617. $scope.tableParams.page(1);
  13618. $scope.tableParams.reload();
  13619. };
  13620. // 搜索框回车
  13621. $scope.onSearch = function() {
  13622. $scope.tableParams.page(1);
  13623. $scope.tableParams.reload();
  13624. };
  13625. }]);
  13626. /**
  13627. * 平台公开招标
  13628. *
  13629. */
  13630. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  13631. BaseService.scrollBackToTop();
  13632. /**
  13633. * 改变单据日期范围
  13634. */
  13635. var getTenderDateCondition = function(zone, condition) {
  13636. var date = new Date();
  13637. if(zone == -1) {
  13638. condition.dateFrom = null;
  13639. condition.dateTo = null;
  13640. } else if(zone == 7) { // 一星期内
  13641. date.setDate(date.getDate() - 7);
  13642. condition.dateFrom = date;
  13643. condition.dateTo = new Date();
  13644. } else if(zone == 1) { // 一个月内
  13645. date.setMonth(date.getMonth() - 1);
  13646. condition.dateFrom = date;
  13647. condition.dateTo = new Date();
  13648. } else if(zone == 3) { // 三个月内
  13649. date.setMonth(date.getMonth() - 3);
  13650. condition.dateFrom = date;
  13651. condition.dateTo = new Date();
  13652. } else if (zone == 6) { // 半年内
  13653. date.setMonth(date.getMonth() - 6);
  13654. condition.dateFrom = date;
  13655. condition.dateTo = new Date();
  13656. } else { // 一年内
  13657. date.setYear(date.getYear() - 1);
  13658. condition.dateFrom = date;
  13659. condition.dateTo = new Date();
  13660. }
  13661. };
  13662. $scope.active = 'all';
  13663. $scope.dateZoneText = '不限';
  13664. $scope.deliveryZoneText = '不限';
  13665. $scope.condition = {dateZone: -1};
  13666. $scope.changeDateZone = function(zone) {
  13667. $scope.condition.dateZone = zone;
  13668. $scope.condition.$dateZoneOpen = false;
  13669. getTenderDateCondition(zone, $scope.condition);
  13670. $scope.tableParams.reload();
  13671. };
  13672. $scope.openDatePicker = function($event, item, openParam) {
  13673. $event.preventDefault();
  13674. $event.stopPropagation();
  13675. item[openParam] = !item[openParam];
  13676. };
  13677. $scope.parseDate = function(dateStr) {
  13678. if(dateStr)
  13679. return Date.parse(dateStr, 'yyyy-MM-dd');
  13680. return new Date();
  13681. };
  13682. // 选择查找日期
  13683. $scope.onDateCondition = function(){
  13684. $scope.tableParams.page(1);
  13685. $scope.tableParams.reload();
  13686. };
  13687. // $scope.setActive = function(state) {
  13688. // if($scope.active != state) {
  13689. // $scope.active = state;
  13690. // if($scope.tableParams.page() == 1)
  13691. // $scope.tableParams.reload();
  13692. // else
  13693. // $scope.tableParams.page(1);
  13694. // }
  13695. // };
  13696. var getOpenState = function(active) {
  13697. var fn = 'getOpenAll';
  13698. switch(active) {
  13699. case 'all':
  13700. fn = 'getOpenAll';break;
  13701. // case 'done':
  13702. // fn = 'getOpenDone';break;
  13703. case 'todo':
  13704. fn = 'getOpenTodo';break;
  13705. case 'end':
  13706. fn = 'getOpenEnd';break;
  13707. // case 'waiting':
  13708. // fn = 'getOpenWaiting';break;
  13709. }
  13710. return fn;
  13711. };
  13712. $scope.tableParams = new ngTableParams({
  13713. page : 1,
  13714. count : 20,
  13715. sorting: {
  13716. 'tender.endDate': 'desc',
  13717. 'tender.enterprise.enName': 'asc',
  13718. 'tender.code': 'asc'
  13719. }
  13720. }, {
  13721. total : 0,
  13722. counts: [],
  13723. getData : function($defer, params) {
  13724. $scope.loading = true;
  13725. var pageParams = params.url();
  13726. var realActive = {};
  13727. pageParams.searchFilter = { // 筛选条件
  13728. keyword: $scope.keyword,
  13729. fromDate: getDateTime($scope.condition.dateFrom),
  13730. endDate: getDateTime($scope.condition.dateTo)
  13731. };
  13732. AccountEnterprise.get({}, function(data){
  13733. $scope.loading = false;
  13734. $scope.currentEn = data;
  13735. });
  13736. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  13737. $scope.loading = false;
  13738. if(page) {
  13739. params.total(page.totalElement);
  13740. $defer.resolve(page.content);
  13741. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  13742. }
  13743. }, function(response){
  13744. $scope.loading = false;
  13745. toaster.pop('error', '数据加载失败', response.data);
  13746. });
  13747. }
  13748. });
  13749. $scope.toDetail = function(id) {
  13750. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  13751. };
  13752. // var stautsItem = [];
  13753. // $scope.getTenderStatus = function (tender) {
  13754. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  13755. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  13756. // stautsItem = thisItem;
  13757. // }
  13758. // });
  13759. // if (!stautsItem.price) {
  13760. // return "daitoubiao";
  13761. // } else if (!stautsItem.applystatus) {
  13762. // return "yitoubiao";
  13763. // } else if (stautsItem.applystatus == 1) {
  13764. // return "zhongbiao";
  13765. // } else if (stautsItem.applystatus == 0) {
  13766. // return "weizhongbiao";
  13767. // }
  13768. // };
  13769. // 搜索框回车
  13770. $scope.onSearch = function() {
  13771. $scope.tableParams.page(1);
  13772. $scope.tableParams.reload();
  13773. };
  13774. }]);
  13775. /**
  13776. * 采购方查看供应商投标单
  13777. */
  13778. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  13779. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  13780. // $scope.item = data; // 供应商查看
  13781. // $scope.loading = false;
  13782. // }, function(response){
  13783. // $scope.loading = false;
  13784. // toaster.pop('error', '数据加载失败', response.data);
  13785. // });
  13786. PurcTender.getOne({id: $stateParams.id}, function(data){
  13787. $scope.bid = data;
  13788. var vendUU = Number($stateParams.vendUU);
  13789. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  13790. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13791. if (saleTenderItem.saleTender.vendUU === vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  13792. tenderProd.currentItem = saleTenderItem;
  13793. $scope.saleTender = saleTenderItem.saleTender;
  13794. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  13795. }
  13796. });
  13797. });
  13798. }, function(response){
  13799. toaster.pop('error', '数据加载失败', response.data);
  13800. });
  13801. }]);
  13802. /**
  13803. * 查看投标单详情
  13804. */
  13805. 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) {
  13806. BaseService.scrollBackToTop();
  13807. if (!$scope.attaches) {
  13808. $scope.attaches = []; // 存放上传了的附件
  13809. }
  13810. // var staticItem = null;
  13811. // $scope.loading = true;
  13812. // PurcTender.getItem({id: $stateParams.id}, function(data){
  13813. // $scope.item = data; // 用于投标
  13814. // if ($scope.item.enterpriseBaseInfo != null) {
  13815. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  13816. // }
  13817. // staticItem = angular.copy(data);
  13818. // $scope.loading = false;
  13819. // }, function(response){
  13820. // $scope.loading = false;
  13821. // toaster.pop('error', '数据加载失败', response.data);
  13822. // });
  13823. var sleep = function (d){
  13824. for(var t = Date.now();Date.now() - t <= d;);
  13825. };
  13826. AccountEnterprise.get({}, function(data){
  13827. $scope.currentEn = data;
  13828. });
  13829. PurcTender.getOne({id: $stateParams.id}, function(data){
  13830. $scope.bid = data;
  13831. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  13832. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13833. if (!$scope.currentEn) {
  13834. AccountEnterprise.get({}, function(data){
  13835. $scope.currentEn = data;
  13836. });
  13837. }
  13838. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  13839. tenderProd.currentItem = saleTenderItem;
  13840. $scope.saleTender = saleTenderItem.saleTender;
  13841. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  13842. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  13843. }
  13844. });
  13845. });
  13846. }, function(response){
  13847. toaster.pop('error', '数据加载失败', response.data);
  13848. });
  13849. $scope.upload = function(myFile) { // 上传附件
  13850. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  13851. $upload.upload({
  13852. url: 'tender/addTenderItemAttach',
  13853. file: file,
  13854. method: 'POST'
  13855. }).success(function (attach) {
  13856. $scope.attaches.push(attach);
  13857. });
  13858. };
  13859. $scope.removeAttach = function(attachId, index) {
  13860. $scope.attaches.splice(index, 1);
  13861. // PurcTender.removeAttach({attachId : id}, {}, function() {
  13862. //
  13863. // });
  13864. };
  13865. var taxrateYes = false;
  13866. var cycleYes = false;
  13867. var priceYes = false;
  13868. $scope.canSave = false;
  13869. $scope.validateThis = function(value, type) {
  13870. switch(type) {
  13871. case 'taxrate':
  13872. var regex = /^\+?[0-9][0-9]{0,1}$/;
  13873. if (regex.test(value)) {
  13874. taxrateYes = true;
  13875. } else {
  13876. if (value) {
  13877. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  13878. }
  13879. }
  13880. break;
  13881. case 'cycle':
  13882. regex = /^\+?[1-9][0-9]*$/;
  13883. if (regex.test(value)) {
  13884. cycleYes = true;
  13885. } else {
  13886. if (value) {
  13887. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  13888. }
  13889. }
  13890. break;
  13891. case 'price':
  13892. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13893. if (regex.test(value) && value !== 0) {
  13894. priceYes = true;
  13895. } else {
  13896. if (value) {
  13897. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  13898. }
  13899. }
  13900. break;
  13901. }
  13902. };
  13903. $scope.emNumYes = true;
  13904. $scope.validEmNum = function (value) {
  13905. var regex = /^\+?[1-9][0-9]*$/;
  13906. if (!regex.test(value) || value === 0 || value !== null) {
  13907. $scope.emNumYes = false;
  13908. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  13909. }
  13910. };
  13911. $scope.validateProds = function(tenderProd) {
  13912. $scope.canSave = true;
  13913. if (tenderProd.currentItem.cycle || tenderProd.currentItem.taxrate || tenderProd.currentItem.price) {
  13914. var cycleRegex = /^\+?[1-9][0-9]*$/;
  13915. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  13916. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  13917. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13918. // 判断填写过的有为0或不符合正则式的,设置不能保存
  13919. if (!cycleRegex.test(tenderProd.currentItem.cycle) || !taxrateRegex.test(tenderProd.currentItem.taxrate) || !priceRegex.test(tenderProd.currentItem.price)) {
  13920. $scope.canSave = false;
  13921. } else {
  13922. $scope.canSave = true;
  13923. }
  13924. }
  13925. };
  13926. // 投标
  13927. $scope.bidIt = function(tender, currentEnBaseInfo){
  13928. $scope.loading = true;
  13929. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  13930. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  13931. }
  13932. var saleTenderItems = [];
  13933. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13934. if (tenderProd.currentItem) {
  13935. if ("" !== tenderProd.currentItem.price && "" !== tenderProd.currentItem.taxrate && "" !== tenderProd.currentItem.cycle) {
  13936. tenderProd.currentItem.saleTender = {};
  13937. saleTenderItems.push(tenderProd.currentItem);
  13938. }
  13939. }
  13940. });
  13941. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  13942. $scope.loading = false;
  13943. toaster.pop('info', '成功', '投标成功');
  13944. // $window.location.reload();
  13945. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  13946. // window.location.hash = '#/sale/opentender';
  13947. // } else {
  13948. window.location.hash = '#/sale/tender';
  13949. // }
  13950. }, function(response){
  13951. $scope.loading = false;
  13952. toaster.pop('error', '投标失败', '出现异常,投标失败');
  13953. });
  13954. };
  13955. $scope.condition = {
  13956. $fromOpened:false
  13957. };
  13958. $scope.getMaxDate = function() {
  13959. return $filter('date')(new Date(), 'yyyy-MM-dd');
  13960. };
  13961. $scope.openDatePicker = function($event, item, openParam) {
  13962. $event.preventDefault();
  13963. $event.stopPropagation();
  13964. item[openParam] = !item[openParam];
  13965. };
  13966. }]);
  13967. /**
  13968. * 公开招标转投标单
  13969. */
  13970. 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) {
  13971. BaseService.scrollBackToTop();
  13972. $scope.attaches = []; // 存放上传了的附件
  13973. var sleep = function (d){
  13974. for(var t = Date.now();Date.now() - t <= d;);
  13975. }
  13976. var getCurrentEn = function() {
  13977. AccountEnterprise.get({}, function(data){
  13978. $scope.currentEn = data;
  13979. });
  13980. }
  13981. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  13982. $scope.loading = true;
  13983. getCurrentEn();
  13984. PurcTender.getOne({id: $stateParams.id}, function(data){
  13985. data.$editing = false;
  13986. $scope.tender = data;
  13987. $scope.tenderProd = data.purchaseTenderProds;
  13988. // parseCertificate($scope.tender.certificate);
  13989. // $scope.firstProd = data.purchaseTenderProds[0];
  13990. $scope.currentHasBid = false; // 默认当前企业未转投标单
  13991. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  13992. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  13993. $scope.currentHasBid = true;
  13994. }
  13995. });
  13996. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  13997. // console.log($scope.tenderProd.enterpriseBaseInfo);
  13998. $scope.loading = false;
  13999. $scope.attaches = $scope.tender.tenderAttaches;
  14000. }, function(response){
  14001. $scope.loading = false;
  14002. toaster.pop('error', '数据加载失败', response.data);
  14003. });
  14004. }
  14005. $scope.hasClick = false;
  14006. $scope.iWantToBid = function(id) {
  14007. $scope.hasClick = true;
  14008. PurcTender.addItems({id: id}, {}, function(data){ // 添加明细
  14009. // $scope.tender = data;
  14010. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  14011. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  14012. // if (!$scope.currentEn) {
  14013. // AccountEnterprise.get({}, function(data){
  14014. // $scope.currentEn = data;
  14015. // });
  14016. // }
  14017. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  14018. // tenderProd.currentItem = saleTenderItem;
  14019. // $scope.saleTender = saleTenderItem.saleTender;
  14020. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  14021. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  14022. // }
  14023. // });
  14024. // });
  14025. toaster.pop('success', '成功', '转投标单成功');
  14026. window.location.hash = "#/sale/tender/" + id;
  14027. }, function(response){
  14028. toaster.pop('error', '操作失败', response.data);
  14029. });
  14030. // $scope.upload = function(myFile) { // 上传附件
  14031. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  14032. // $upload.upload({
  14033. // url: 'tender/addTenderItemAttach',
  14034. // file: file,
  14035. // method: 'POST'
  14036. // }).success(function (attach) {
  14037. // $scope.attaches.push(attach);
  14038. // });
  14039. // };
  14040. };
  14041. // $scope.removeAttach = function(id, index) {
  14042. // $scope.attaches.splice(index, 1);
  14043. // PurcTender.removeAttach({attachId:id}, function() {
  14044. //
  14045. // });
  14046. // };
  14047. // var taxrateYes = false;
  14048. // var cycleYes = false;
  14049. // var priceYes = false;
  14050. // $scope.canSave = false;
  14051. // $scope.validateThis = function(value, type) {
  14052. // switch(type) {
  14053. // case 'taxrate':
  14054. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  14055. // if (regex.test(value)) {
  14056. // taxrateYes = true;
  14057. // } else {
  14058. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  14059. // }
  14060. // break;
  14061. // case 'cycle':
  14062. // regex = /^\+?[1-9][0-9]*$/;
  14063. // if (regex.test(value)) {
  14064. // cycleYes = true;
  14065. // } else {
  14066. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  14067. // }
  14068. // break;
  14069. // case 'price':
  14070. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  14071. // if (regex.test(value) && value !== 0) {
  14072. // priceYes = true;
  14073. // } else {
  14074. // if (!(value instanceof Number) || value) {
  14075. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  14076. // }
  14077. // }
  14078. // break;
  14079. // }
  14080. // };
  14081. //
  14082. // $scope.emNumYes = true;
  14083. //
  14084. // $scope.validEmNum = function (value) {
  14085. // var regex = /^\+?[1-9][0-9]*$/;
  14086. // if (!regex.test(value) || value == 0 || value !== null) {
  14087. // $scope.emNumYes = false;
  14088. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  14089. // }
  14090. // };
  14091. //
  14092. // $scope.validateProds = function(tenderProd) {
  14093. // // angular.forEach(tenderProds, function (tenderProd) {
  14094. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  14095. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  14096. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  14097. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  14098. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  14099. // console.log(tenderProd.currentItem.cycle);
  14100. // 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))) {
  14101. // $scope.canSave = false;
  14102. // } else {
  14103. // $scope.canSave = true;
  14104. // }
  14105. // // });
  14106. // };
  14107. //
  14108. // // 投标
  14109. // $scope.bidIt = function(tender, currentEnBaseInfo){
  14110. // $scope.loading = true;
  14111. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  14112. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  14113. // }
  14114. // var saleTenderItems = [];
  14115. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  14116. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  14117. // if (tenderProd.currentItem) {
  14118. // tenderProd.currentItem.saleTender = {};
  14119. // saleTenderItems.push(tenderProd.currentItem);
  14120. // }
  14121. // });
  14122. // } else {
  14123. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  14124. // if (tenderProd.currentItem) {
  14125. // saleTenderItems.push(tenderProd.currentItem);
  14126. // }
  14127. // });
  14128. // }
  14129. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  14130. // $scope.loading = false;
  14131. // toaster.pop('info', '成功', '投标成功');
  14132. // // $window.location.reload();
  14133. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  14134. // // window.location.hash = '#/sale/opentender';
  14135. // // } else {
  14136. // window.location.hash = '#/sale/tender';
  14137. // // }
  14138. // }, function(response){
  14139. // $scope.loading = false;
  14140. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  14141. // });
  14142. //
  14143. // };
  14144. //
  14145. // $scope.condition = {
  14146. // $fromOpened:false
  14147. // };
  14148. //
  14149. // $scope.getMaxDate = function() {
  14150. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  14151. // };
  14152. //
  14153. // $scope.openDatePicker = function($event, item, openParam) {
  14154. // $event.preventDefault();
  14155. // $event.stopPropagation();
  14156. // item[openParam] = !item[openParam];
  14157. // };
  14158. }]);
  14159. // 基础资料客户详情
  14160. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', 'VendorInfo', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster, VendorInfo){
  14161. BaseService.scrollBackToTop();
  14162. $scope.status = 'customer';
  14163. $scope.userInfoResult = true;
  14164. AuthenticationService.getAuthentication().success(function(data) {
  14165. $scope.loading = false;
  14166. $scope.thisUser = data;
  14167. });
  14168. $scope.customerParams = new ngTableParams({
  14169. page : 1,
  14170. count : 20
  14171. }, {
  14172. total : 0,
  14173. counts: [],
  14174. getData : function($defer, params) {
  14175. $scope.loading = true;
  14176. var pageParams = params.url();
  14177. pageParams.keyword = $scope.keyword;
  14178. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function(page){
  14179. $scope.loading = false;
  14180. if(page) {
  14181. params.total(page.totalElement);
  14182. $scope.total = page.totalElement;
  14183. $defer.resolve(page.content);
  14184. }
  14185. $scope.totalCount = page.totalElement;
  14186. }, function(response){
  14187. $scope.loading = false;
  14188. toaster.pop('error', '数据加载失败', response.data);
  14189. });
  14190. }
  14191. });
  14192. // 搜索框回车
  14193. $scope.onSearch = function(keyword) {
  14194. $scope.customerParams.page(1);
  14195. $scope.customerParams.reload();
  14196. $scope.tip = keyword;
  14197. };
  14198. // 查看详情
  14199. $scope.viewDetail = function(id) {
  14200. window.location.hash = "#/sale/customer/" + id;
  14201. }
  14202. // 取消合作关系
  14203. $scope.disableCust = function(id) {
  14204. VendorInfo.disableCust({id: id}, {}, function(data) {
  14205. if(data.success) {
  14206. toaster.pop('success', '提示', data.success);
  14207. }
  14208. // $scope.customerParams.page(1);
  14209. $scope.customerParams.reload();
  14210. }, function(response) {
  14211. toaster.pop('error', '提示', response.data);
  14212. });
  14213. }
  14214. // 解除禁用
  14215. $scope.activeCust = function(id) {
  14216. VendorInfo.activeCust({id: id}, {}, function(data) {
  14217. if(data.success) {
  14218. toaster.pop('success', '提示', data.success);
  14219. }
  14220. // $scope.customerParams.page(1);
  14221. $scope.customerParams.reload();
  14222. }, function(response) {
  14223. toaster.pop('error', '提示', response.data);
  14224. });
  14225. }
  14226. }]);
  14227. // 基础资料供应商
  14228. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  14229. BaseService.scrollBackToTop();
  14230. $scope.status = 'vendor';
  14231. // 搜索框回车
  14232. $scope.onSearch = function() {
  14233. $scope.customerParams.page(1);
  14234. $scope.customerParams.reload();
  14235. };
  14236. $scope.customerParams = new ngTableParams({
  14237. page : 1,
  14238. count : 20
  14239. }, {
  14240. total : 0,
  14241. counts: [],
  14242. getData : function($defer, params) {
  14243. $scope.loading = true;
  14244. var pageParams = params.url();
  14245. pageParams.keyword = $scope.keyword;
  14246. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  14247. $scope.loading = false;
  14248. if(page) {
  14249. params.total(page.totalElement);
  14250. $scope.total = page.totalElement;
  14251. $defer.resolve(page.content);
  14252. }
  14253. $scope.totalCount = page.totalElement;
  14254. }, function(response){
  14255. $scope.loading = false;
  14256. toaster.pop('error', '数据加载失败', response.data);
  14257. });
  14258. }
  14259. });
  14260. // 查看供应商详情
  14261. $scope.VendorDetail = function(id, uu) {
  14262. $rootScope.vendorId = id;
  14263. $rootScope.vendoruu = uu;
  14264. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  14265. }
  14266. // 向企业购买
  14267. $scope.purcByEn = function(businessCode) {
  14268. $rootScope.businessCode = businessCode;
  14269. window.location.hash = "#/purc/addOrder";
  14270. }
  14271. // 取消合作关系
  14272. $scope.relieve = function(id) {
  14273. VendorInfo.relieve({id: id}, {}, function(data) {
  14274. if(data.success) {
  14275. toaster.pop('success', '提示', data.success);
  14276. }
  14277. // $scope.customerParams.page(1);
  14278. $scope.customerParams.reload();
  14279. }, function(response) {
  14280. toaster.pop('error', '提示', response.data);
  14281. });
  14282. }
  14283. // 建立合作关系
  14284. $scope.activeVend = function(id) {
  14285. VendorInfo.activeVend({id: id}, {}, function(data) {
  14286. if(data.success) {
  14287. toaster.pop('success', '提示', data.success);
  14288. }
  14289. // $scope.customerParams.page(1);
  14290. $scope.customerParams.reload();
  14291. }, function(response) {
  14292. toaster.pop('error', '提示', response.data);
  14293. });
  14294. }
  14295. }]);
  14296. // 企业圈搜索界面
  14297. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  14298. $scope.onSearch = function(keyword) {
  14299. $rootScope.enterpriseKeyword = keyword;
  14300. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  14301. }
  14302. }]);
  14303. // 企业圈搜索结果
  14304. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  14305. $scope.status = 'add';
  14306. BaseService.scrollBackToTop();
  14307. $scope.active = 'all';
  14308. $scope.agreedText = '全部';
  14309. $scope.dateZoneText = '一个月内';
  14310. $scope.condition = {dateZone: 1};
  14311. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14312. $scope.changeAgreed = function(agreed) {
  14313. $scope.condition.agreed = agreed;
  14314. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  14315. $scope.condition.$agreedOpen = false;
  14316. };
  14317. $scope.changeDateZone = function(zone) {
  14318. $scope.condition.dateZone = zone;
  14319. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  14320. $scope.condition.$dateZoneOpen = false;
  14321. getDateCondition(zone, $scope.condition);
  14322. $scope.tableParams.reload();
  14323. };
  14324. $scope.setActive = function(state) {
  14325. if($scope.active != state) {
  14326. $scope.active = state;
  14327. if($scope.tableParams.page() == 1)
  14328. $scope.tableParams.reload();
  14329. else
  14330. $scope.tableParams.page(1);
  14331. }
  14332. };
  14333. var getService = function() {
  14334. return getAccountUserSpace;
  14335. };
  14336. $scope.tableParams = new ngTableParams({
  14337. page : 1,
  14338. count : 20,
  14339. sorting: {
  14340. }
  14341. }, {
  14342. total : 0,
  14343. counts: [],
  14344. getData : function($defer, params) {
  14345. $scope.loading = true;
  14346. var pageParams = params.url();
  14347. pageParams.keyword = $scope.keyword;
  14348. $scope.tip = $scope.keyword;
  14349. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  14350. $scope.loading = false;
  14351. if(page) {
  14352. params.total(page.totalElement);
  14353. $defer.resolve(page.content);
  14354. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14355. }
  14356. }, function(response) {
  14357. $scope.loading = false;
  14358. toaster.pop('error', '数据加载失败', response.data);
  14359. });
  14360. }
  14361. });
  14362. // 搜索框回车
  14363. $scope.onSearch = function(keyword) {
  14364. if($scope.keyword != null && $scope.keyword != '') {
  14365. $rootScope.searchKeyword = keyword;
  14366. $scope.keyword = keyword;
  14367. $scope.tableParams.page(1);
  14368. $scope.tableParams.reload();
  14369. }
  14370. };
  14371. // 添加合作关系
  14372. $scope.addPartner = function(name, businessCode) {
  14373. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  14374. if(data.success) {
  14375. toaster.pop("success", '添加成功', data.success);
  14376. $scope.tableParams.reload();
  14377. }
  14378. if(data.error) {
  14379. toaster.pop("error", '添加失败', data.error);
  14380. }
  14381. }, function(response) {
  14382. toaster.pop('error','失败',response.data);
  14383. });
  14384. }
  14385. /**
  14386. * 邀请注册商务平台
  14387. */
  14388. $scope.invite = function(name) {
  14389. var modalInstance = $modal.open({
  14390. animation: true,
  14391. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  14392. controller: 'InviteCtrl',
  14393. resolve: {
  14394. enname: function(){return name}
  14395. }
  14396. });
  14397. modalInstance.result.then(function(data) {
  14398. InvitationRecord.invite({formStore: data}, {}, function(data) {
  14399. if(data.success) {
  14400. toaster.pop('success', '提示', data.success);
  14401. $scope.tableParams.reload();
  14402. }
  14403. if(data.error) {
  14404. toaster.pop('error', '提示', data.error);
  14405. }
  14406. }, function(response) {
  14407. toaster.pop('error', '提示', response.data);
  14408. });
  14409. });
  14410. }
  14411. /**
  14412. * 立即查看
  14413. */
  14414. $scope.view = function(name) {
  14415. $rootScope.vendName = name;
  14416. window.location.hash = "#/baseInfo/newPartner";
  14417. }
  14418. }]);
  14419. // 平台新增的询价单(指定一个供应商)
  14420. 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) {
  14421. $scope.active = 'all';
  14422. // 供应商信息
  14423. var loadData = function() {
  14424. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function(data) {
  14425. $scope.vendor = data;
  14426. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  14427. $scope.vendorContacts = data;
  14428. });
  14429. // 物料信息
  14430. $scope.tableParams = new ngTableParams({
  14431. page : 1,
  14432. count : 20
  14433. }, {
  14434. total : 0,
  14435. counts: [5, 10, 25, 50],
  14436. getData : function($defer, params) {
  14437. $scope.loading = true;
  14438. var pageParams = params.url();
  14439. pageParams.keyword = $scope.keyword;
  14440. $scope.tip = $scope.keyword;
  14441. pageParams.custUU = $scope.vendor.uu;
  14442. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  14443. $scope.loading = false;
  14444. if(page) {
  14445. params.total(page.totalElement);
  14446. $scope.total = page.totalElement;
  14447. $defer.resolve(page.content);
  14448. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  14449. }
  14450. }, function(response){
  14451. $scope.loading = false;
  14452. toaster.pop('error', '数据加载失败', response.data);
  14453. });
  14454. }
  14455. });
  14456. });
  14457. };
  14458. loadData();
  14459. $rootScope.tenderVendor = null;// 清除掉已选择的
  14460. var getService = function() {
  14461. return GetProductInfo;
  14462. };
  14463. $scope.inquiry = {
  14464. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  14465. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  14466. priceType: '采购',
  14467. isOpen: 1,
  14468. invoice: 0,
  14469. ifTax: 1,
  14470. currency: 'RMB'
  14471. };
  14472. $scope.changeCurrency = function(inquiry) {
  14473. if (inquiry.currency !== 'RMB') {
  14474. $scope.notRMB = true;
  14475. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  14476. inquiry.invoice = 0;
  14477. } else {
  14478. $scope.notRMB = false;
  14479. }
  14480. };
  14481. // 获取收货地址列表
  14482. var loadShipAddress = function() {
  14483. ShipAddress.shipAddList({}, function(data) {
  14484. $scope.ships = data;
  14485. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  14486. });
  14487. };
  14488. loadShipAddress();
  14489. // 获取地址信息
  14490. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  14491. }).then(function(response) {
  14492. $scope.provinces = response.data;
  14493. });
  14494. // 新增收货地址保存
  14495. $scope.saveShipAddress = function(ship) {
  14496. ship.address = ship.province + ship.city + ship.district;
  14497. ShipAddress.saveAddress( {}, ship, function(data) {
  14498. if(data.success) {
  14499. // 获取收货地址列表
  14500. loadShipAddress();
  14501. toaster.pop('success', '提示', data.success);
  14502. }
  14503. if(data.error) {
  14504. toaster.pop('error', '提示', data.error);
  14505. }
  14506. });
  14507. };
  14508. $scope.currentDay = function() {
  14509. return $filter('date')(new Date(), 'yyyy-MM-dd');
  14510. };
  14511. // 搜索框回车
  14512. $scope.onSearch = function(keyword) {
  14513. $scope.tableParams.page(1);
  14514. $scope.tableParams.reload();
  14515. };
  14516. $scope.inquiry.inquiryItems = [];
  14517. var prod = {
  14518. prodCode: null,
  14519. prodTitle: null,
  14520. inbrand: null,
  14521. currency: 'RMB',
  14522. toDate: null,
  14523. unit: 'PCS'
  14524. };
  14525. $scope.inquiry.inquiryItems.push(prod);
  14526. // 联想词start
  14527. // 获取品牌联想词
  14528. $scope.getSimilarBrands = function(value) {
  14529. if (value) {
  14530. // 获取品牌联想词
  14531. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  14532. return data.map(function(item) {
  14533. return item;
  14534. });
  14535. });
  14536. }
  14537. };
  14538. // 获取产品型号联想词
  14539. $scope.getSimilarCodes = function(value) {
  14540. if (value) {
  14541. // 获取产品型号联想词
  14542. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  14543. return data.map(function (item) {
  14544. return item;
  14545. })
  14546. });
  14547. }
  14548. };
  14549. $scope.selectKind = function(prod) {
  14550. var submit = [];
  14551. $modal.open({
  14552. animation: true,
  14553. size: 'lg',
  14554. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  14555. controller: 'ProdKindChooseCtrl',
  14556. resolve: {
  14557. actives: function() {
  14558. return $scope.actives;
  14559. }
  14560. }
  14561. }).result.then(function(data){
  14562. $scope.actives = data.actives;
  14563. var size = data.actives.length;
  14564. submit.gradeOneKiName = '';
  14565. submit.gradeTwoKiName = '';
  14566. submit.gradeThreeKiName = '';
  14567. if (size > 0) {
  14568. submit.gradeOneKiName = $scope.actives[0].nameCn;
  14569. prod.prodTitle = submit.gradeOneKiName;
  14570. if (size > 1) {
  14571. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  14572. prod.prodTitle = submit.gradeTwoKiName;
  14573. if (size > 2) {
  14574. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  14575. prod.prodTitle = submit.gradeThreeKiName;
  14576. }
  14577. }
  14578. }
  14579. }, function(){
  14580. });
  14581. };
  14582. // 点击联想词获取品牌信息
  14583. $scope.onAssociateBrandClick = function(brand, prod) {
  14584. if (brand instanceof String) {
  14585. prod.inbrand = brand;
  14586. } else if (brand instanceof Object) {
  14587. prod.inbrand = brand.brandCn;
  14588. }
  14589. };
  14590. // 打开品牌选择的模态框
  14591. $scope.selectBrand = function(prod){ //打开模态
  14592. var modalInstance = $modal.open({
  14593. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  14594. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  14595. });
  14596. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  14597. });
  14598. modalInstance.result.then(function(brand){
  14599. prod.inbrand = brand.nameCn;
  14600. }, function(reason){
  14601. });
  14602. };
  14603. // 点击联想词获取器件信息 带入产品分类和品牌
  14604. $scope.onAssociateCmpClick = function(cmp, prod) {
  14605. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  14606. $scope.component = data;
  14607. prod.prodCode = data.code;
  14608. prod.prodTitle = data.kind.nameCn;
  14609. prod.inbrand = data.brand.nameCn;
  14610. }, function(res) {
  14611. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  14612. })
  14613. };
  14614. //联想词end
  14615. // 导入商品信息
  14616. $scope.uplodaByBatch = function() {
  14617. var modalInstance = $modal.open({
  14618. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  14619. controller: 'PurcInquiryUploadCtrl',
  14620. size: 'lg',
  14621. resolve: {
  14622. }
  14623. });
  14624. modalInstance.result.then(function(data) {
  14625. angular.forEach(data, function(prod) {
  14626. console.log(prod);
  14627. $scope.inquiry.inquiryItems.push(prod);
  14628. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  14629. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  14630. $scope.inquiry.inquiryItems.splice(i, 1);
  14631. }
  14632. }
  14633. })
  14634. }, function(){
  14635. });
  14636. }
  14637. //增加商品
  14638. $scope.add = function() {
  14639. $scope.inquiry.inquiryItems.push(
  14640. { prodCode: null,
  14641. prodTitle: null,
  14642. unit: 'PCS',
  14643. ibrand: null,
  14644. currency: 'RMB',
  14645. toDate: null});
  14646. };
  14647. //删除商品
  14648. $scope.del = function(index) {
  14649. $scope.inquiry.inquiryItems.splice(index, 1);
  14650. };
  14651. // 搜索结果询价
  14652. if($rootScope.prodId) {
  14653. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  14654. prod.prodCode = data.code;
  14655. prod.prodTitle = data.title;
  14656. prod.spec = data.spec;
  14657. prod.unit = data.unit;
  14658. prod.productId = data.id;
  14659. prod.inbrand = data.brand;
  14660. $scope.inquiry.inquiryItems.push(prod);
  14661. $rootScope.prodId = null;// 清除掉prodId
  14662. }, function(response) {
  14663. });
  14664. }
  14665. $scope.check = function(product) {
  14666. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  14667. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  14668. $scope.inquiry.inquiryItems.splice(i, 1);
  14669. }
  14670. }
  14671. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  14672. currency: null, toDate: null, productId: product.id, inbrand: product.brand});
  14673. }
  14674. $scope.getMinDate = function(item) {
  14675. return $filter('date')(new Date, 'yyyy-MM-dd');
  14676. };
  14677. $scope.openDatePicker = function($event, openParam, index) {
  14678. $event.preventDefault();
  14679. $event.stopPropagation();
  14680. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  14681. };
  14682. $scope.openEndDatePicker = function($event, item, openParam) {
  14683. $event.preventDefault();
  14684. $event.stopPropagation();
  14685. item[openParam] = !item[openParam];
  14686. };
  14687. $scope.ifrepeat = false;
  14688. // 保存并提交
  14689. $scope.submit = function() {
  14690. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  14691. $scope.item = $scope.inquiry.inquiryItems[i];
  14692. for(var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  14693. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  14694. if(i != j) {
  14695. if($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  14696. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  14697. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  14698. $scope.ifrepeat = true;
  14699. }
  14700. }
  14701. }
  14702. }
  14703. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  14704. $scope.vendors = [];
  14705. $scope.vendors.push({enName: $scope.vendor.enName, enuu: $scope.vendor.uu, currency: $scope.vendor.currency, rate: $scope.vendor.rate});
  14706. if(!$scope.ifrepeat) {
  14707. $upload.upload({
  14708. url: 'purc/inquiry/saveAndSubmit',
  14709. file: file,
  14710. method: 'POST',
  14711. data: {
  14712. inquiry: $scope.inquiry,
  14713. contacts: $scope.vendors
  14714. },
  14715. }).success(function(data) {
  14716. if(data.success) {
  14717. toaster.pop('success', '提示', data.success);
  14718. $timeout(function() {
  14719. window.location.hash = "#/purc/purchaseinquiry";
  14720. }, 500);
  14721. }
  14722. if(data.error) {
  14723. toaster.pop('error', '提示', data.error);
  14724. }
  14725. }).error(function(data) {
  14726. $scope.loadingShow = false;
  14727. toaster.pop('error', '操作失败', data.error);
  14728. });
  14729. } else {
  14730. toaster.pop('error', '提示', '存在条件相同的物料');
  14731. }
  14732. }
  14733. }]);
  14734. // 企业圈查询收到待处理的数目
  14735. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', function($scope, AddPartnerMyRequest) {
  14736. AddPartnerMyRequest.requestAmount({}, function(data) {
  14737. $scope.requestTodo = data;
  14738. });
  14739. }]);
  14740. // 当前企业所有的物料信息
  14741. app.controller('ProductAllCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products) {
  14742. BaseService.scrollBackToTop();
  14743. $scope.active = 'all';
  14744. $scope.agreedText = '全部';
  14745. $scope.dateZoneText = '一个月内';
  14746. $scope.condition = {dateZone: 1};
  14747. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14748. $scope.changeAgreed = function(agreed) {
  14749. $scope.condition.agreed = agreed;
  14750. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  14751. $scope.condition.$agreedOpen = false;
  14752. };
  14753. $scope.changeDateZone = function(zone) {
  14754. $scope.condition.dateZone = zone;
  14755. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  14756. $scope.condition.$dateZoneOpen = false;
  14757. getDateCondition(zone, $scope.condition);
  14758. $scope.tableParams.reload();
  14759. };
  14760. $scope.setActive = function(state) {
  14761. if($scope.active != state) {
  14762. $scope.active = state;
  14763. if($scope.tableParams.page() == 1)
  14764. $scope.tableParams.reload();
  14765. else
  14766. $scope.tableParams.page(1);
  14767. }
  14768. };
  14769. var getService = function() {
  14770. return ProductAll;
  14771. };
  14772. $scope.tableParams = new ngTableParams({
  14773. page : 1,
  14774. count : 20,
  14775. sorting: {
  14776. }
  14777. }, {
  14778. total : 0,
  14779. counts: [5, 10, 25, 50],
  14780. getData : function($defer, params) {
  14781. $scope.loading = true;
  14782. var pageParams = params.url();
  14783. pageParams.keyword = $scope.keyword;
  14784. pageParams.searchFilter = $scope.searchFilter;
  14785. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  14786. $scope.loading = false;
  14787. if(page) {
  14788. params.total(page.totalElement);
  14789. $defer.resolve(page.content);
  14790. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14791. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  14792. }
  14793. }, function(response) {
  14794. $scope.loading = false;
  14795. toaster.pop('error', '数据加载失败', response.data);
  14796. });
  14797. }
  14798. });
  14799. // 搜索框回车
  14800. $scope.onSearch = function() {
  14801. $scope.tableParams.page(1);
  14802. $scope.tableParams.reload();
  14803. };
  14804. // 开启销售
  14805. $scope.unlock = function(id) {
  14806. Products.unlock({id: id}, {}, function(data) {
  14807. toaster.pop('success', '提示', '操作成功');
  14808. $scope.tableParams.reload();
  14809. }, function(response) {
  14810. toaster.pop('error', '提示', response.data);
  14811. })
  14812. }
  14813. // 关闭销售
  14814. $scope.lock = function(id) {
  14815. Products.lock({id: id}, {}, function(data) {
  14816. toaster.pop('success', '提示', '操作成功');
  14817. $scope.tableParams.reload();
  14818. }, function(response) {
  14819. toaster.pop('error', '提示', response.data);
  14820. })
  14821. }
  14822. // 开启购买
  14823. $scope.unlockPurc = function(id) {
  14824. Products.unlockPurc({id: id}, {}, function(data) {
  14825. toaster.pop('success', '提示', '操作成功');
  14826. $scope.tableParams.reload();
  14827. }, function(response) {
  14828. toaster.pop('error', '提示', response.data);
  14829. })
  14830. }
  14831. // 关闭购买
  14832. $scope.lockPurc = function(id) {
  14833. Products.lockPurc({id: id}, {}, function(data) {
  14834. toaster.pop('success', '提示', '操作成功');
  14835. $scope.tableParams.reload();
  14836. }, function(response) {
  14837. toaster.pop('error', '提示', response.data);
  14838. })
  14839. }
  14840. // 一键匹配
  14841. $scope.matchall = function() {
  14842. $scope.type = "all";
  14843. $scope.loading = true;
  14844. Products.matchbytype({type: $scope.type}, {}, function(data) {
  14845. toaster.pop('info', '提示', '匹配成功'+data.size+'个标准器件');
  14846. window.location.href = "#/approvalFlow/productmatches";
  14847. }, function(response) {
  14848. toaster.pop('error', '提示', response.data);
  14849. });
  14850. }
  14851. }]);
  14852. // 当前企业匹配的标准物料信息
  14853. app.controller('ProductmatchesCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  14854. BaseService.scrollBackToTop();
  14855. $scope.active = 'all';
  14856. $scope.agreedText = '全部';
  14857. $scope.dateZoneText = '一个月内';
  14858. $scope.condition = {dateZone: 1};
  14859. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14860. $scope.changeAgreed = function(agreed) {
  14861. $scope.condition.agreed = agreed;
  14862. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  14863. $scope.condition.$agreedOpen = false;
  14864. };
  14865. $scope.changeDateZone = function(zone) {
  14866. $scope.condition.dateZone = zone;
  14867. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  14868. $scope.condition.$dateZoneOpen = false;
  14869. getDateCondition(zone, $scope.condition);
  14870. $scope.tableParams.reload();
  14871. };
  14872. $scope.setActive = function(state) {
  14873. if($scope.active != state) {
  14874. $scope.active = state;
  14875. if($scope.tableParams.page() == 1)
  14876. $scope.tableParams.reload();
  14877. else
  14878. $scope.tableParams.page(1);
  14879. }
  14880. };
  14881. var getService = function() {
  14882. if($rootScope.productMatchStatus === 'sale') {
  14883. return Products.matchResultforSale;
  14884. } else if($rootScope.productMatchStatus === 'purc') {
  14885. return Products.matchResultforPurc;
  14886. } else {
  14887. return Products.matchResult;
  14888. }
  14889. };
  14890. $scope.tableParams = new ngTableParams({
  14891. page : 1,
  14892. count : 20,
  14893. sorting: {
  14894. }
  14895. }, {
  14896. total : 0,
  14897. counts: [5, 10, 25, 50],
  14898. getData : function($defer, params) {
  14899. $scope.loading = true;
  14900. var pageParams = params.url();
  14901. pageParams.keyword = $scope.keyword;
  14902. pageParams.searchFilter = $scope.searchFilter;
  14903. getService().call(null, BaseService.parseParams(pageParams), function(page){
  14904. $scope.loading = false;
  14905. if(page) {
  14906. params.total(page.totalElement);
  14907. $defer.resolve(page.content);
  14908. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14909. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  14910. angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
  14911. ids = [];
  14912. if(product.matchresults.length == 1) {
  14913. product.checked = $scope.checks.checked;
  14914. }
  14915. });
  14916. $scope.total = page.totalElement;
  14917. Products.matchsize({type: 'all'}, {}, function(data) {
  14918. $scope.size = data.size;
  14919. if($scope.total < $scope.size) {
  14920. $scope.tableParams.reload();
  14921. }
  14922. }, function(response) {
  14923. toaster.pop('error', '提示', response.data);
  14924. });
  14925. }
  14926. }, function(response) {
  14927. $scope.loading = false;
  14928. toaster.pop('error', '数据加载失败', response.data);
  14929. });
  14930. }
  14931. });
  14932. // 搜索框回车
  14933. $scope.onSearch = function() {
  14934. $scope.tableParams.page(1);
  14935. $scope.tableParams.reload();
  14936. };
  14937. var ids = [];
  14938. $scope.checks = {
  14939. checked: false
  14940. };
  14941. // 全选框
  14942. $scope.checkAll = function() {
  14943. ids = [];// 每次选择时先清空,防止重复
  14944. angular.forEach($scope.tableParams.data, function(product) {
  14945. if(product.matchresults.length == 1) {
  14946. product.checked = $scope.checks.checked;
  14947. }
  14948. });
  14949. };
  14950. // 单选
  14951. $scope.checkOne = function(product) {
  14952. ids = [];// 每次选择时先清空,防止重复
  14953. product.checked = !product.checked;
  14954. var result = true;
  14955. angular.forEach($scope.tableParams.data, function(item) {
  14956. if(item.$selected != true){
  14957. result = false;
  14958. return;
  14959. }
  14960. });
  14961. $scope.checks.checked = result;
  14962. var checked = true;
  14963. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  14964. if (!message.checked) {
  14965. checked = false;
  14966. }
  14967. });
  14968. $scope.checks.checked = checked;
  14969. };
  14970. $scope.product = {
  14971. checked: false
  14972. };
  14973. var checkResults = function(result) {
  14974. angular.forEach($scope.tableParams.data, function(product) {
  14975. if (product.id == result.prid) {
  14976. product.checked = false;
  14977. angular.forEach(product.matchresults, function(item) {
  14978. if(result.id == item.id) {
  14979. if(item.checked) {
  14980. product.checked = true;
  14981. return;
  14982. }
  14983. } else {
  14984. item.checked = false;
  14985. }
  14986. });
  14987. }
  14988. });
  14989. // checkProductCheck();
  14990. };
  14991. var checkProductCheck = function () {
  14992. var checked = true;
  14993. angular.forEach($scope.tableParams.data, function(product) {
  14994. if(!product.checked) {
  14995. checked = false;
  14996. }
  14997. });
  14998. $scope.product.checked = checked;
  14999. }
  15000. // 单选明细
  15001. $scope.checkItem = function(result) {
  15002. ids = [];
  15003. result.checked = !result.checked;
  15004. checkResults(result);
  15005. }
  15006. // 一键更新
  15007. $scope.updateAll = function() {
  15008. angular.forEach($scope.tableParams.data, function(product) {
  15009. if(product.checked) {
  15010. if(product.matchresults.length == 1) {
  15011. ids.push(product.matchresults[0].id);
  15012. }
  15013. if (product.matchresults.length > 1) {
  15014. angular.forEach(product.matchresults, function(item) {
  15015. if(item.checked) {
  15016. ids.push(item.id);
  15017. }
  15018. });
  15019. }
  15020. }
  15021. });
  15022. Products.updateall( {}, ids, function(data) {
  15023. if(data.success) {
  15024. toaster.pop('success', '提示', data.success);
  15025. $scope.tableParams.page(1);
  15026. $scope.tableParams.reload();
  15027. }
  15028. ids = []; // 清空ids,防止重复点击出现多余的数据
  15029. }, function(response) {
  15030. toaster.pop('error', '提示', response.data);
  15031. });
  15032. }
  15033. }]);
  15034. // 当前企业匹配的标准物料信息(销售)
  15035. app.controller('ProductmatchesForSaleCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  15036. BaseService.scrollBackToTop();
  15037. $scope.active = 'all';
  15038. $scope.agreedText = '全部';
  15039. $scope.dateZoneText = '一个月内';
  15040. $scope.condition = {dateZone: 1};
  15041. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15042. $scope.changeAgreed = function(agreed) {
  15043. $scope.condition.agreed = agreed;
  15044. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15045. $scope.condition.$agreedOpen = false;
  15046. };
  15047. $scope.changeDateZone = function(zone) {
  15048. $scope.condition.dateZone = zone;
  15049. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15050. $scope.condition.$dateZoneOpen = false;
  15051. getDateCondition(zone, $scope.condition);
  15052. $scope.tableParams.reload();
  15053. };
  15054. $scope.setActive = function(state) {
  15055. if($scope.active != state) {
  15056. $scope.active = state;
  15057. if($scope.tableParams.page() == 1)
  15058. $scope.tableParams.reload();
  15059. else
  15060. $scope.tableParams.page(1);
  15061. }
  15062. };
  15063. var getService = function() {
  15064. return Products.matchResultforSale;
  15065. };
  15066. $scope.tableParams = new ngTableParams({
  15067. page : 1,
  15068. count : 20,
  15069. sorting: {
  15070. }
  15071. }, {
  15072. total : 0,
  15073. counts: [5, 10, 25, 50],
  15074. getData : function($defer, params) {
  15075. $scope.loading = true;
  15076. var pageParams = params.url();
  15077. pageParams.keyword = $scope.keyword;
  15078. pageParams.searchFilter = $scope.searchFilter;
  15079. getService().call(null, BaseService.parseParams(pageParams), function(page){
  15080. $scope.loading = false;
  15081. if(page) {
  15082. params.total(page.totalElement);
  15083. $defer.resolve(page.content);
  15084. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15085. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15086. angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
  15087. ids = [];
  15088. if(product.matchresults.length == 1) {
  15089. product.checked = $scope.checks.checked;
  15090. }
  15091. });
  15092. $scope.total = page.totalElement;
  15093. Products.matchsize({type: 'sale'}, {}, function(data) {
  15094. $scope.size = data.size;
  15095. if($scope.total < $scope.size) {
  15096. $scope.tableParams.reload();
  15097. }
  15098. }, function(response) {
  15099. toaster.pop('error', '提示', response.data);
  15100. });
  15101. }
  15102. }, function(response) {
  15103. $scope.loading = false;
  15104. toaster.pop('error', '数据加载失败', response.data);
  15105. });
  15106. }
  15107. });
  15108. // 搜索框回车
  15109. $scope.onSearch = function() {
  15110. $scope.tableParams.page(1);
  15111. $scope.tableParams.reload();
  15112. };
  15113. var ids = [];
  15114. $scope.checks = {
  15115. checked: false
  15116. };
  15117. // 全选框
  15118. $scope.checkAll = function() {
  15119. ids = [];// 每次选择时先清空,防止重复
  15120. angular.forEach($scope.tableParams.data, function(product) {
  15121. if(product.matchresults.length == 1) {
  15122. product.checked = $scope.checks.checked;
  15123. }
  15124. });
  15125. };
  15126. // 单选
  15127. $scope.checkOne = function(product) {
  15128. ids = [];// 每次选择时先清空,防止重复
  15129. product.checked = !product.checked;
  15130. var result = true;
  15131. angular.forEach($scope.tableParams.data, function(item) {
  15132. if(item.$selected != true){
  15133. result = false;
  15134. return;
  15135. }
  15136. });
  15137. $scope.checks.checked = result;
  15138. var checked = true;
  15139. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  15140. if (!message.checked) {
  15141. checked = false;
  15142. }
  15143. });
  15144. $scope.checks.checked = checked;
  15145. };
  15146. $scope.product = {
  15147. checked: false
  15148. };
  15149. var checkResults = function(result) {
  15150. angular.forEach($scope.tableParams.data, function(product) {
  15151. if (product.id == result.prid) {
  15152. product.checked = false;
  15153. angular.forEach(product.matchresults, function(item) {
  15154. if(result.id == item.id) {
  15155. if(item.checked) {
  15156. product.checked = true;
  15157. return;
  15158. }
  15159. } else {
  15160. item.checked = false;
  15161. }
  15162. });
  15163. }
  15164. });
  15165. // checkProductCheck();
  15166. };
  15167. var checkProductCheck = function () {
  15168. var checked = true;
  15169. angular.forEach($scope.tableParams.data, function(product) {
  15170. if(!product.checked) {
  15171. checked = false;
  15172. }
  15173. });
  15174. $scope.product.checked = checked;
  15175. }
  15176. // 单选明细
  15177. $scope.checkItem = function(result) {
  15178. ids = [];
  15179. result.checked = !result.checked;
  15180. checkResults(result);
  15181. }
  15182. // 一键更新
  15183. $scope.updateAll = function() {
  15184. angular.forEach($scope.tableParams.data, function(product) {
  15185. if(product.checked) {
  15186. if(product.matchresults.length == 1) {
  15187. ids.push(product.matchresults[0].id);
  15188. }
  15189. if (product.matchresults.length > 1) {
  15190. angular.forEach(product.matchresults, function(item) {
  15191. if(item.checked) {
  15192. ids.push(item.id);
  15193. }
  15194. });
  15195. }
  15196. }
  15197. });
  15198. Products.updateall( {}, ids, function(data) {
  15199. if(data.success) {
  15200. toaster.pop('success', '提示', data.success);
  15201. $scope.tableParams.page(1);
  15202. $scope.tableParams.reload();
  15203. }
  15204. ids = []; // 清空ids,防止重复点击出现多余的数据
  15205. }, function(response) {
  15206. toaster.pop('error', '提示', response.data);
  15207. });
  15208. }
  15209. }]);
  15210. // 当前企业匹配的标准物料信息(采购)
  15211. app.controller('ProductmatchesForPurcCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  15212. BaseService.scrollBackToTop();
  15213. $scope.active = 'all';
  15214. $scope.agreedText = '全部';
  15215. $scope.dateZoneText = '一个月内';
  15216. $scope.condition = {dateZone: 1};
  15217. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15218. $scope.changeAgreed = function(agreed) {
  15219. $scope.condition.agreed = agreed;
  15220. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15221. $scope.condition.$agreedOpen = false;
  15222. };
  15223. $scope.changeDateZone = function(zone) {
  15224. $scope.condition.dateZone = zone;
  15225. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15226. $scope.condition.$dateZoneOpen = false;
  15227. getDateCondition(zone, $scope.condition);
  15228. $scope.tableParams.reload();
  15229. };
  15230. $scope.setActive = function(state) {
  15231. if($scope.active != state) {
  15232. $scope.active = state;
  15233. if($scope.tableParams.page() == 1)
  15234. $scope.tableParams.reload();
  15235. else
  15236. $scope.tableParams.page(1);
  15237. }
  15238. };
  15239. var getService = function() {
  15240. return Products.matchResultforPurc;
  15241. };
  15242. $scope.tableParams = new ngTableParams({
  15243. page : 1,
  15244. count : 20,
  15245. sorting: {
  15246. }
  15247. }, {
  15248. total : 0,
  15249. counts: [5, 10, 25, 50],
  15250. getData : function($defer, params) {
  15251. $scope.loading = true;
  15252. var pageParams = params.url();
  15253. pageParams.keyword = $scope.keyword;
  15254. pageParams.searchFilter = $scope.searchFilter;
  15255. getService().call(null, BaseService.parseParams(pageParams), function(page){
  15256. $scope.loading = false;
  15257. if(page) {
  15258. params.total(page.totalElement);
  15259. $defer.resolve(page.content);
  15260. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15261. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15262. angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
  15263. ids = [];
  15264. if(product.matchresults.length == 1) {
  15265. product.checked = $scope.checks.checked;
  15266. }
  15267. });
  15268. $scope.total = page.totalElement;
  15269. Products.matchsize({type: 'purc'}, {}, function(data) {
  15270. $scope.size = data.size;
  15271. if($scope.total < $scope.size) {
  15272. $scope.tableParams.reload();
  15273. }
  15274. }, function(response) {
  15275. toaster.pop('error', '提示', response.data);
  15276. });
  15277. }
  15278. }, function(response) {
  15279. $scope.loading = false;
  15280. toaster.pop('error', '数据加载失败', response.data);
  15281. });
  15282. }
  15283. });
  15284. // 搜索框回车
  15285. $scope.onSearch = function() {
  15286. $scope.tableParams.page(1);
  15287. $scope.tableParams.reload();
  15288. };
  15289. var ids = [];
  15290. $scope.checks = {
  15291. checked: false
  15292. };
  15293. // 全选框
  15294. $scope.checkAll = function() {
  15295. ids = [];// 每次选择时先清空,防止重复
  15296. angular.forEach($scope.tableParams.data, function(product) {
  15297. if(product.matchresults.length == 1) {
  15298. product.checked = $scope.checks.checked;
  15299. }
  15300. });
  15301. };
  15302. // 单选
  15303. $scope.checkOne = function(product) {
  15304. ids = [];// 每次选择时先清空,防止重复
  15305. product.checked = !product.checked;
  15306. var result = true;
  15307. angular.forEach($scope.tableParams.data, function(item) {
  15308. if(item.$selected != true){
  15309. result = false;
  15310. return;
  15311. }
  15312. });
  15313. $scope.checks.checked = result;
  15314. var checked = true;
  15315. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  15316. if (!message.checked) {
  15317. checked = false;
  15318. }
  15319. });
  15320. $scope.checks.checked = checked;
  15321. };
  15322. $scope.product = {
  15323. checked: false
  15324. };
  15325. var checkResults = function(result) {
  15326. angular.forEach($scope.tableParams.data, function(product) {
  15327. if (product.id == result.prid) {
  15328. product.checked = false;
  15329. angular.forEach(product.matchresults, function(item) {
  15330. if(result.id == item.id) {
  15331. if(item.checked) {
  15332. product.checked = true;
  15333. return;
  15334. }
  15335. } else {
  15336. item.checked = false;
  15337. }
  15338. });
  15339. }
  15340. });
  15341. // checkProductCheck();
  15342. };
  15343. var checkProductCheck = function () {
  15344. var checked = true;
  15345. angular.forEach($scope.tableParams.data, function(product) {
  15346. if(!product.checked) {
  15347. checked = false;
  15348. }
  15349. });
  15350. $scope.product.checked = checked;
  15351. }
  15352. // 单选明细
  15353. $scope.checkItem = function(result) {
  15354. ids = [];
  15355. result.checked = !result.checked;
  15356. checkResults(result);
  15357. }
  15358. // 一键更新
  15359. $scope.updateAll = function() {
  15360. angular.forEach($scope.tableParams.data, function(product) {
  15361. if(product.checked) {
  15362. if(product.matchresults.length == 1) {
  15363. ids.push(product.matchresults[0].id);
  15364. }
  15365. if (product.matchresults.length > 1) {
  15366. angular.forEach(product.matchresults, function(item) {
  15367. if(item.checked) {
  15368. ids.push(item.id);
  15369. }
  15370. });
  15371. }
  15372. }
  15373. });
  15374. Products.updateall( {}, ids, function(data) {
  15375. if(data.success) {
  15376. toaster.pop('success', '提示', data.success);
  15377. $scope.tableParams.page(1);
  15378. $scope.tableParams.reload();
  15379. }
  15380. ids = []; // 清空ids,防止重复点击出现多余的数据
  15381. }, function(response) {
  15382. toaster.pop('error', '提示', response.data);
  15383. });
  15384. }
  15385. }]);
  15386. /**
  15387. * 采购物料资料
  15388. */
  15389. app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$modal', 'GetProductInfo', '$rootScope', function($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $modal, GetProductInfo, $rootScope) {
  15390. BaseService.scrollBackToTop();
  15391. $scope.active = 'all';
  15392. $scope.agreedText = '全部';
  15393. $scope.dateZoneText = '一个月内';
  15394. $scope.condition = {dateZone: 1};
  15395. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15396. $scope.changeAgreed = function(agreed) {
  15397. $scope.condition.agreed = agreed;
  15398. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15399. $scope.condition.$agreedOpen = false;
  15400. };
  15401. $scope.changeDateZone = function(zone) {
  15402. $scope.condition.dateZone = zone;
  15403. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15404. $scope.condition.$dateZoneOpen = false;
  15405. getDateCondition(zone, $scope.condition);
  15406. $scope.tableParams.reload();
  15407. };
  15408. $scope.setActive = function(state) {
  15409. if($scope.active != state) {
  15410. $scope.active = state;
  15411. if($scope.tableParams.page() == 1)
  15412. $scope.tableParams.reload();
  15413. else
  15414. $scope.tableParams.page(1);
  15415. }
  15416. };
  15417. var getService = function() {
  15418. return PurcProduct;
  15419. };
  15420. $scope.tableParams = new ngTableParams({
  15421. page : 1,
  15422. count : 20,
  15423. sorting: {
  15424. }
  15425. }, {
  15426. total : 0,
  15427. counts: [5, 10, 25, 50],
  15428. getData : function($defer, params) {
  15429. $scope.loading = true;
  15430. var pageParams = params.url();
  15431. pageParams.keyword = $scope.keyword;
  15432. pageParams.searchFilter = $scope.searchFilter;
  15433. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  15434. $scope.loading = false;
  15435. if(page) {
  15436. params.total(page.totalElement);
  15437. $defer.resolve(page.content);
  15438. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15439. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15440. }
  15441. }, function(response) {
  15442. $scope.loading = false;
  15443. toaster.pop('error', '数据加载失败', response.data);
  15444. });
  15445. }
  15446. });
  15447. // 搜索框回车
  15448. $scope.onSearch = function() {
  15449. $scope.tableParams.page(1);
  15450. $scope.tableParams.reload();
  15451. };
  15452. //删除
  15453. $scope.deleteById = function(id) {
  15454. GetProductInfo.deleteById({id: id}, function(data) {
  15455. if(data.error) {
  15456. toaster.pop("error", "提示", data.error);
  15457. } else {
  15458. toaster.pop("success", "提示", "删除成功");
  15459. $timeout(function() {
  15460. $scope.tableParams.reload();
  15461. }, 500);
  15462. }
  15463. }), function(response) {
  15464. toaster.pop("error", "删除失败", response.data);
  15465. };
  15466. }
  15467. // 一键开启关闭
  15468. $scope.toggle = function(status) {
  15469. console.log(status);
  15470. Products.toggle({status: status}, {}, function(data) {
  15471. toaster.pop('success', '提示', '操作成功');
  15472. $scope.tableParams.reload();
  15473. }, function(response) {
  15474. toaster.pop('error', '提示', response.data);
  15475. })
  15476. }
  15477. var products = [];
  15478. $scope.checks = {
  15479. checked: false
  15480. };
  15481. // 全选框
  15482. $scope.checkAll = function() {
  15483. products = [];// 每次选择时先清空,防止重复
  15484. angular.forEach($scope.tableParams.data, function(product) {
  15485. if(product.cmpUuId == null) {
  15486. product.checked = $scope.checks.checked;
  15487. }
  15488. });
  15489. };
  15490. // 单选
  15491. $scope.checkOne = function(product) {
  15492. products = [];// 每次选择时先清空,防止重复
  15493. var result = true;
  15494. angular.forEach($scope.tableParams.data, function(item) {
  15495. if(item.$selected != true){
  15496. result = false;
  15497. return;
  15498. }
  15499. });
  15500. $scope.checks.checked = result;
  15501. var checked = true;
  15502. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  15503. if (!message.checked) {
  15504. checked = false;
  15505. }
  15506. });
  15507. $scope.checks.checked = checked;
  15508. };
  15509. $scope.updateByBatch = function(updatetype) {
  15510. var modalInstance = $modal.open({
  15511. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  15512. controller: 'UpdateByBatchCtrl',
  15513. size: 'md',
  15514. resolve: {
  15515. updatetype: function() {
  15516. return updatetype;
  15517. },
  15518. active: function() {
  15519. return $scope.active;
  15520. },
  15521. type: function() {
  15522. return 'purchase';
  15523. }
  15524. }
  15525. });
  15526. modalInstance.result.then(function(data) {
  15527. toaster.pop('success', '提示', data.success);
  15528. $scope.tableParams.reload();
  15529. }, function(){
  15530. });
  15531. }
  15532. // 一键匹配
  15533. $scope.matchall = function() {
  15534. $scope.type = "purc";
  15535. $scope.loading = true;
  15536. Products.matchbytype({type: $scope.type}, {}, function(data) {
  15537. toaster.pop('info', '提示', '匹配成功'+data.size+'个标准器件');
  15538. window.location.href = "#/purc/productmatches";
  15539. }, function(response) {
  15540. toaster.pop('error', '提示', response.data);
  15541. });
  15542. }
  15543. }]);
  15544. /**
  15545. * 采购物料批量上传
  15546. */
  15547. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  15548. BaseService.scrollBackToTop();
  15549. $scope.$watch('myFiles', function(){
  15550. if($scope.myFiles) {
  15551. var file = $scope.myFiles[0];
  15552. $scope.fileName = file.name;
  15553. }
  15554. })
  15555. // 通过excel批量上传物料
  15556. $scope.upload = function() {
  15557. $scope.loading = true;
  15558. if($scope.myFiles) {
  15559. var file = $scope.myFiles[0];
  15560. if(file.name) {
  15561. $scope.loading = true;
  15562. $upload.upload({
  15563. url: 'purcProduct/release/excel',
  15564. file: file,
  15565. method: 'POST'
  15566. }).success(function(data) {
  15567. $scope.loading = false;
  15568. if(data.error) {
  15569. toaster.pop('error', '提示', data.error);
  15570. }
  15571. $scope.result = data;
  15572. $scope.products = $scope.result.products;
  15573. $scope.success = $scope.result.success;
  15574. $scope.total = $scope.result.total;
  15575. $scope.alters = $scope.result.alters;
  15576. $scope.infos = $scope.result.infos;
  15577. $scope.myFiles[0] = "";
  15578. $scope.fileName = "";
  15579. }).error(function(response) {
  15580. $scope.loading = false;
  15581. toaster.pop('error', response.data || response);
  15582. });
  15583. } else {
  15584. $scope.loading = false;
  15585. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  15586. }
  15587. } else {
  15588. $scope.loading = false;
  15589. }
  15590. };
  15591. // 查看范例
  15592. $scope.showImg = function() {
  15593. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  15594. box.show();
  15595. box.find('img').attr('src', src);
  15596. box.find('a').click(function(){
  15597. box.hide();
  15598. });
  15599. box.dblclick(function(){
  15600. box.hide();
  15601. });
  15602. };
  15603. // 下载模板
  15604. $scope.download = function() {
  15605. window.location.href = 'product/baseInfo/upload/template';
  15606. };
  15607. }]);
  15608. /**
  15609. * 新增物料(采购)
  15610. */
  15611. app.controller('PurcNewProdInfoCtrl', ['$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) {
  15612. BaseService.scrollBackToTop();
  15613. // 录入人
  15614. AuthenticationService.getAuthentication().success(function(data) {
  15615. $scope.loading = false;
  15616. $scope.user = data;
  15617. });
  15618. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  15619. $scope.prodInfo = {};
  15620. // 选择类目
  15621. $scope.selectKind = function() {
  15622. $modal.open({
  15623. animation: true,
  15624. size: 'lg',
  15625. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  15626. controller: 'KindChooseCtrl',
  15627. }).result.then(function(data){
  15628. $scope.kindId = data;
  15629. var modalInstance = $modal.open({
  15630. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  15631. controller: 'FindComponentCtrl',
  15632. size: 'lg',
  15633. resolve: {
  15634. KindId: function() {
  15635. return $scope.kindId;
  15636. }
  15637. }
  15638. });
  15639. modalInstance.result.then(function(data) {
  15640. $scope.prodInfo.cmpUuId = data.uuid;
  15641. $scope.prodInfo.pcmpcode = data.code;
  15642. $scope.prodInfo.pbranden = data.brand.nameEn;
  15643. $scope.prodInfo.pbrand = data.brand.nameCn;
  15644. }, function(){
  15645. });
  15646. }, function(){
  15647. });
  15648. };
  15649. // 删除
  15650. $scope.clearfile = function() {
  15651. $scope.myFiles = null;
  15652. $scope.previewShow = false;
  15653. }
  15654. //提交
  15655. $scope.submit = function(prodInfo){
  15656. $scope.prodInfo.isPurchase = 1;
  15657. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  15658. $upload.upload({
  15659. url: 'product/baseInfo/addNewProduct',
  15660. file: file,
  15661. method: 'POST',
  15662. data: {
  15663. prodInfo: prodInfo
  15664. },
  15665. }).success(function(data) {
  15666. if(data.success) {
  15667. toaster.pop('success', '提示', data.success);
  15668. $timeout(function() {
  15669. //提交后跳转到详情页面,防止重复提交
  15670. window.location.href="#/sale/prodList/"+data.id;
  15671. }, 500);
  15672. }
  15673. if(data.error) {
  15674. toaster.pop('error', '提示', data.error);
  15675. $timeout(function() {
  15676. //提交后跳转到详情页面,防止重复提交
  15677. window.location.href="#/sale/prodList/"+data.id;
  15678. }, 500);
  15679. }
  15680. }).error(function(data) {
  15681. $scope.loadingShow = false;
  15682. toaster.pop('error', '操作失败', data.error);
  15683. });
  15684. };
  15685. $scope.previewShow = false;
  15686. $scope.pdfShow = false;
  15687. $scope.noneFileShow = true;
  15688. $scope.$watch('myFiles', function(){
  15689. if($scope.myFiles) {
  15690. $scope.noneFileShow = false;
  15691. var file = $scope.myFiles[0];
  15692. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  15693. $scope.pdfShow = true;
  15694. $scope.previewShow = false;
  15695. $scope.imgPreviewName = file.name;
  15696. } else{
  15697. if (typeof(Worker) !== "undefined") {//支持HTML5
  15698. $scope.imgPreview = getObjectURL(file);
  15699. $scope.imgPreviewName = file.name;
  15700. } else{//不支持HTML5
  15701. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  15702. $scope.imgPreviewName = file.name;
  15703. }
  15704. $scope.previewShow = true;
  15705. $scope.pdfShow = false;
  15706. }
  15707. } else {
  15708. $scope.noneFileShow = true;
  15709. $scope.previewShow = false;
  15710. $scope.pdfShow = false;
  15711. }
  15712. });
  15713. //建立一个可存取到该file的url
  15714. var getObjectURL = function(file) {
  15715. var url = null ;
  15716. if (window.createObjectURL!=undefined) { // basic
  15717. url = window.createObjectURL(file) ;
  15718. } else if (window.URL!=undefined) { // mozilla(firefox)
  15719. url = window.URL.createObjectURL(file) ;
  15720. } else if (window.webkitURL!=undefined) { // webkit or chrome
  15721. url = window.webkitURL.createObjectURL(file) ;
  15722. }
  15723. return url ;
  15724. };
  15725. // 取消
  15726. $scope.cancel = function(){
  15727. $scope.prodInfo = angular.copy($scope.prodInfo);
  15728. };
  15729. }]);
  15730. /**
  15731. * 物料详情(采购)
  15732. */
  15733. app.controller('PurcProdDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$modal', 'Products', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $modal, Products) {
  15734. BaseService.scrollBackToTop();
  15735. // 录入人
  15736. AuthenticationService.getAuthentication().success(function(data) {
  15737. $scope.loading = false;
  15738. $scope.user = data;
  15739. });
  15740. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  15741. var loadData = function() {
  15742. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  15743. if(data.attach) {
  15744. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  15745. // 查看范例
  15746. $scope.showImg = function() {
  15747. var src = data.url, box = $('#image-box');
  15748. box.show();
  15749. box.find('img').attr('src', src);
  15750. box.find('a').click(function(){
  15751. box.hide();
  15752. });
  15753. box.dblclick(function(){
  15754. box.hide();
  15755. });
  15756. };
  15757. })
  15758. }
  15759. $scope.prodInfo = data;
  15760. if($scope.prodInfo.standard != 1 ) {// 非标准的先进行匹配
  15761. Products.matchone({id: $scope.prodInfo.id}, {}, function(data) {
  15762. $scope.matchresults = data;
  15763. }, function(response) {
  15764. toaster.pop('error', '提示', response.data);
  15765. });
  15766. }
  15767. $scope.prodInfo.$editing = false;
  15768. $scope.loading = false;
  15769. });
  15770. };
  15771. loadData();
  15772. //更新为标准器件
  15773. $scope.updateone = function(id) {
  15774. Products.updateone({id: id}, {}, function(data) {
  15775. if(data.success) {
  15776. toaster.pop('success', '提示', data.success);
  15777. }
  15778. }, function(response) {
  15779. toaster.pop('error', '提示', response.data);
  15780. });
  15781. }
  15782. // 选择类目
  15783. $scope.selectKind = function(cmpcode) {
  15784. if(cmpcode == null) {
  15785. $modal.open({
  15786. animation: true,
  15787. size: 'lg',
  15788. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  15789. controller: 'KindChooseCtrl',
  15790. }).result.then(function(data){
  15791. $scope.kindId = data;
  15792. var modalInstance = $modal.open({
  15793. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  15794. controller: 'FindComponentCtrl',
  15795. size: 'lg',
  15796. resolve: {
  15797. KindId: function() {
  15798. return $scope.kindId;
  15799. }
  15800. }
  15801. });
  15802. modalInstance.result.then(function(data) {
  15803. $scope.prodInfo.cmpUuId = data.uuid;
  15804. $scope.prodInfo.pcmpcode = data.code;
  15805. $scope.prodInfo.pbranden = data.brand.nameEn;
  15806. $scope.prodInfo.pbrand = data.brand.nameCn;
  15807. }, function(){
  15808. });
  15809. }, function(){
  15810. });
  15811. }
  15812. };
  15813. $scope.isShow = true;
  15814. // 更新
  15815. $scope.update = function() {
  15816. $scope.prodInfo.$editing = true;
  15817. $scope.isShow = true;
  15818. };
  15819. // 取消
  15820. $scope.cancel = function() {
  15821. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  15822. $scope.prodInfo = data;
  15823. $scope.prodInfo.$editing = false;
  15824. $scope.isShow = false;
  15825. $scope.loading = false;
  15826. });
  15827. };
  15828. // 删除
  15829. $scope.clearfile = function() {
  15830. $scope.myFiles = null;
  15831. $scope.previewShow = false;
  15832. }
  15833. //删除
  15834. $scope.deleteById = function(id) {
  15835. GetProductInfo.deleteById({id: id}, function(data) {
  15836. if(data.error) {
  15837. toaster.pop("error", "提示", data.error);
  15838. } else {
  15839. toaster.pop("success", "提示", "删除成功");
  15840. window.location.href = "#/purc/prodList";
  15841. }
  15842. }), function(response) {
  15843. toaster.pop("error", "删除失败", response.data);
  15844. };
  15845. }
  15846. $scope.submit = function(prodInfo) {
  15847. $scope.prodInfo.isPurchase = 1;
  15848. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  15849. $upload.upload({
  15850. url: 'product/baseInfo/updateProdInfo',
  15851. file: file,
  15852. method: 'POST',
  15853. data: {
  15854. prodInfo: $scope.prodInfo
  15855. },
  15856. }).success(function(data) {
  15857. if(data.success) {
  15858. toaster.pop('success', '提示', data.success);
  15859. loadData();
  15860. }
  15861. if(data.error) {
  15862. toaster.pop('error', '提示', data.error);
  15863. }
  15864. }).error(function(data) {
  15865. $scope.loadingShow = false;
  15866. toaster.pop('error', '操作失败', data.error);
  15867. });
  15868. }
  15869. $scope.previewShow = false;
  15870. $scope.pdfShow = false;
  15871. $scope.noneFileShow = true;
  15872. $scope.$watch('myFiles', function(){
  15873. if($scope.myFiles) {
  15874. $scope.noneFileShow = false;
  15875. var file = $scope.myFiles[0];
  15876. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  15877. $scope.pdfShow = true;
  15878. $scope.previewShow = false;
  15879. $scope.imgPreviewName = file.name;
  15880. } else{
  15881. if (typeof(Worker) !== "undefined") {//支持HTML5
  15882. $scope.imgPreview = getObjectURL(file);
  15883. $scope.imgPreviewName = file.name;
  15884. } else{//不支持HTML5
  15885. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  15886. $scope.imgPreviewName = file.name;
  15887. }
  15888. $scope.previewShow = true;
  15889. $scope.pdfShow = false;
  15890. }
  15891. } else {
  15892. $scope.noneFileShow = true;
  15893. $scope.previewShow = false;
  15894. $scope.pdfShow = false;
  15895. }
  15896. });
  15897. //建立一个可存取到该file的url
  15898. var getObjectURL = function(file) {
  15899. var url = null ;
  15900. if (window.createObjectURL!=undefined) { // basic
  15901. url = window.createObjectURL(file) ;
  15902. } else if (window.URL!=undefined) { // mozilla(firefox)
  15903. url = window.URL.createObjectURL(file) ;
  15904. } else if (window.webkitURL!=undefined) { // webkit or chrome
  15905. url = window.webkitURL.createObjectURL(file) ;
  15906. }
  15907. return url ;
  15908. };
  15909. }]);
  15910. return app;
  15911. });