app.js 520 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569
  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.uploadProduct', {
  213. url : "/uploadProduct",
  214. templateUrl : "static/tpl/index/purc/uploadByBatch.html",
  215. controller: 'UploadProductCtrl'
  216. }).state('sale.tenderlist', {
  217. url : "/tender",
  218. templateUrl : "static/tpl/index/sale/tenderlist.html",
  219. controller : 'SaleTenderCtrl'
  220. }).state('sale.todo.tenderlist', {
  221. url : "/tender",
  222. templateUrl : "static/tpl/index/sale/tenderlist.html",
  223. controller : 'SaleTenderCtrl'
  224. /* 平台公开招标列表 */
  225. }).state('baseInfo.openTenderList', {
  226. url : "/openTenderList",
  227. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  228. controller: 'SaleOpenTenderCtrl'
  229. /* 查看公开招标详情 */
  230. }).state('baseInfo.open_tender_detail', {
  231. url : "/openTenderDetail/:id",
  232. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  233. controller : 'OpenSaleTenderDetailCtrl'
  234. /* 投标 */
  235. }).state('sale.tender', {
  236. url : "/tender/:id",
  237. templateUrl : "static/tpl/index/sale/tender.html",
  238. controller : 'SaleTenderDetailCtrl'
  239. /* 采购方查看供应商投标 */
  240. }).state('sale.vendortender', {
  241. url : "/tender/:vendUU/:id",
  242. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  243. controller : 'SaleVendorTenderDetailCtrl'
  244. }).state('sale.todo', {
  245. url : "/todo",
  246. templateUrl : "static/tpl/index/sale/todo.html"
  247. }).state('sale.todo.inquiry', {
  248. url : "/inquiry",
  249. templateUrl : "static/tpl/index/sale/inquiry.html",
  250. controller: 'SaleInquiryCtrl'
  251. }).state('sale.todo.order', {
  252. url : "/order",
  253. templateUrl : "static/tpl/index/sale/order.html",
  254. controller: 'SaleOrderCtrl'
  255. }).state('sale.todo.change', {
  256. url : "/change",
  257. templateUrl : "static/tpl/index/sale/change.html",
  258. controller: 'SaleChangeCtrl'
  259. }).state('sale.todo.notice', {
  260. url : "/notice",
  261. templateUrl : "static/tpl/index/sale/notice.html",
  262. controller: 'SaleNoticeCtrl'
  263. }).state('sale.customer', {
  264. url : "/customer",
  265. templateUrl : "static/tpl/index/sale/customer.html",
  266. controller: 'CustomerCtrl'
  267. }).state('sale.customer_detail', {
  268. url : "/customer/:id",
  269. templateUrl : "static/tpl/index/sale/customer_detail.html",
  270. controller: 'CustomerDetailCtrl'
  271. }).state('sale.customerProduct', {
  272. url : "/customerProduct",
  273. templateUrl : "static/tpl/index/sale/customer.html",
  274. controller: 'CustomerCtrl'
  275. }).state('sale.inquiry', {
  276. url : "/inquiry",
  277. templateUrl : "static/tpl/index/sale/inquiry.html",
  278. controller: 'SaleInquiryCtrl'
  279. }).state('sale.inquirymould', {
  280. url : "/mould",
  281. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  282. controller: 'SaleInquiryMouldCtrl'
  283. }).state('sale.todo.inquirymould', {
  284. url : "/mould",
  285. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  286. controller: 'SaleInquiryMouldCtrl'
  287. }).state('sale.inquiry_mould_detail', {
  288. url : "/mould/:id",
  289. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  290. controller: 'SaleInquiryMouldDetailCtrl'
  291. }).state('sale.inquiry_detail', {
  292. url : "/inquiry/:id",
  293. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  294. controller: 'SaleInquiryDetailCtrl'
  295. }).state('sale.quotation', {
  296. url : "/quotation",
  297. templateUrl : "static/tpl/index/sale/quotation.html"
  298. }).state('sale.quotation.new', {
  299. url : "/new",
  300. templateUrl : "static/tpl/index/sale/quotation_new.html",
  301. controller: 'SaleQuotationNewCtrl'
  302. }).state('sale.quotation.list', {
  303. url : "/list",
  304. templateUrl : "static/tpl/index/sale/quotation_list.html",
  305. controller: 'SaleQuotationListCtrl'
  306. }).state('sale.quotation.item', {
  307. url : "/:id",
  308. templateUrl : "static/tpl/index/sale/quotation_new.html",
  309. controller: 'SaleQuotationNewCtrl'
  310. }).state('sale.order', {
  311. url : "/order",
  312. templateUrl : "static/tpl/index/sale/order.html",
  313. controller: 'SaleOrderCtrl'
  314. }).state('sale.order_detail', {
  315. url : "/order/:id",
  316. templateUrl : "static/tpl/index/sale/order_detail.html",
  317. controller: 'SaleOrderDetailCtrl'
  318. }).state('sale.change', {
  319. url : "/change",
  320. templateUrl : "static/tpl/index/sale/change.html",
  321. controller: 'SaleChangeCtrl'
  322. }).state('sale.change_detail', {
  323. url : "/change/:id",
  324. templateUrl : "static/tpl/index/sale/change_detail.html",
  325. controller: 'SaleChangeDetailCtrl'
  326. }).state('sale.notice', {
  327. url : "/notice",
  328. templateUrl : "static/tpl/index/sale/notice.html",
  329. controller: 'SaleNoticeCtrl'
  330. }).state('sale.send', {
  331. url : "/send",
  332. templateUrl : "static/tpl/index/sale/send.html",
  333. controller: 'SaleSendCtrl'
  334. }).state('sale.send_detail', {
  335. url : "/send/:id",
  336. templateUrl : "static/tpl/index/sale/send_detail.html",
  337. controller: 'SaleSendDetailCtrl'
  338. }).state('sale.forecast', {
  339. url : "/forecast",
  340. templateUrl : "static/tpl/index/sale/forecast.html",
  341. controller: 'SaleForecastCtrl'
  342. }).state('sale.accept', {
  343. url : "/accept",
  344. templateUrl : "static/tpl/index/sale/accept.html",
  345. controller: 'SaleAcceptCtrl'
  346. }).state('sale.returns', {
  347. url : "/returns",
  348. templateUrl : "static/tpl/index/sale/returns.html",
  349. controller: 'SaleReturnsCtrl'
  350. }).state('sale.sample', {
  351. url : "/sample",
  352. templateUrl : "static/tpl/index/sale/sample.html",
  353. controller: 'SaleSampleCtrl'
  354. }).state('sale.sample_detail', {
  355. url : "/sample/:id",
  356. templateUrl : "static/tpl/index/sale/sample_detail.html",
  357. controller: 'SaleSampleDetailCtrl'
  358. }).state('sale.approval', {
  359. url : "/approval",
  360. templateUrl : "static/tpl/index/sale/approval.html",
  361. controller: 'SaleApprovalCtrl'
  362. }).state('sale.prodList', {
  363. url : "/prodList",
  364. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  365. controller : 'ProductListCtrl'
  366. }).state('sale.newProdInfo', {
  367. url : "/newProdInfo",
  368. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  369. controller : 'NewProdInfoCtrl'
  370. }).state('sale.uploadByBatch', {
  371. url : "/uploadByBatch",
  372. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  373. controller : 'UploadByBatchCtrl'
  374. }).state('sale.productDetail', {
  375. url : "/prodList/:id",
  376. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  377. controller : 'ProductDetailCtrl'
  378. }).state('sale.maketodo', {
  379. url : "/maketodo",
  380. templateUrl : "static/tpl/index/make/todo.html"
  381. }).state('sale.maketodo.order', {
  382. url : "/makeorder",
  383. templateUrl : "static/tpl/index/make/order.html",
  384. controller: 'MakeOrderCtrl'
  385. }).state('sale.makeorder', {
  386. url : "/makeorder",
  387. templateUrl : "static/tpl/index/make/order.html",
  388. controller: 'MakeOrderCtrl'
  389. }).state('sale.makeorder_detail', {
  390. url : "/makeorder/:id",
  391. templateUrl : "static/tpl/index/make/order_detail.html",
  392. controller: 'MakeOrderDetailCtrl'
  393. }).state('sale.badOut', {
  394. url : "/badOut",
  395. templateUrl : "static/tpl/index/qc/badOut.html",
  396. controller: 'SaleBadOutCtrl'
  397. }).state('sale.MRB', {
  398. url : "/MRB",
  399. templateUrl : "static/tpl/index/qc/MRB.html",
  400. controller: 'SaleMRBCtrl'
  401. }).state('sale.badIn', {
  402. url : "/badIn",
  403. templateUrl : "static/tpl/index/qc/badIn.html",
  404. controller: 'SaleBadInCtrl'
  405. }).state('sale.makeaccept', {
  406. url : "/makeaccept",
  407. templateUrl : "static/tpl/index/make/accept.html",
  408. controller: 'MakeAcceptCtrl'
  409. }).state('sale.makereturns', {
  410. url : "/makereturns",
  411. templateUrl : "static/tpl/index/make/returns.html",
  412. controller: 'MakeReturnCtrl'
  413. }).state('sale.makechange', {
  414. url : "/makechange",
  415. templateUrl : "static/tpl/index/make/change.html",
  416. controller: 'MakeChangeCtrl'
  417. }).state('sale.makechange_detail', {
  418. url : "/makechange/:id",
  419. templateUrl : "static/tpl/index/make/change_detail.html",
  420. controller: 'MakeChangeDetailCtrl'
  421. }).state('account', {
  422. url : "/account",
  423. views : {
  424. "left-view" : {
  425. templateUrl : "static/tpl/index/account/left.html",
  426. controller: 'LeftCtrl'
  427. },
  428. "right-view" : {
  429. templateUrl : "static/tpl/index/account/right.html"
  430. }
  431. }
  432. }).state('account.index', {
  433. url : "",
  434. templateUrl : "static/tpl/index/account/index.html",
  435. controller: 'RightCtrl'
  436. }).state('account.home', {
  437. url : "/",
  438. templateUrl : "static/tpl/index/account/index.html",
  439. controller: 'RightCtrl'
  440. }).state('baseInfo', {//基础资料
  441. url : "/baseInfo",
  442. views : {
  443. "left-view" : {
  444. },
  445. "right-view" : {
  446. templateUrl : "static/tpl/index/baseInfo/right.html"
  447. }
  448. }
  449. }).state('baseInfo.index', {
  450. url : "/enterpriseList",
  451. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  452. controller: 'EnterpriseListCtrl'
  453. }).state('baseInfo.home', {
  454. url : "/enterpriseList",
  455. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  456. controller: 'EnterpriseListCtrl'
  457. }).state('baseInfo.enterpriseList', {
  458. url : "/enterpriseList",
  459. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  460. controller : 'EnterpriseListCtrl'
  461. }).state('baseInfo.myClient', {
  462. url : "/myClient",
  463. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  464. controller : 'MyClientCtrl'
  465. }).state('baseInfo.mySupplier', {
  466. url : "/mySupplier",
  467. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  468. controller : 'MySupplierCtrl'
  469. }).state('baseInfo.myRequest', {
  470. url : "/myRquest",
  471. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  472. controller : 'AddPartnerRequestCtrl'
  473. }).state('baseInfo.myMessage', {
  474. url : "/myMessage",
  475. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  476. controller : 'AddPartnerMessageCtrl'
  477. }).state('baseInfo.myPartners', {
  478. url : '/myPartners',
  479. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  480. controller : 'MyPartnersCtrl'
  481. }).state('baseInfo.businessGroups', {
  482. url : '/businessGroups',
  483. controller : 'BusinessGroupsCtrl'
  484. }).state('baseInfo.inquiryList', {
  485. url : '/inquiryList',
  486. templateUrl : "static/tpl/index/baseInfo/inquiry_list.html",
  487. controller : 'PublicInquiryListCtrl'
  488. }).state('baseInfo.inquiryListDetail', {
  489. url : '/inquiryList/:id',
  490. templateUrl : "static/tpl/index/baseInfo/inquiryItem_detail.html",
  491. controller : 'PublicInquiryListDetailCtrl'
  492. }).state('baseInfo.vendorInfo', {
  493. url : '/enume/vendorInfo',
  494. templateUrl : "static/tpl/index/baseInfo/vendorsInfo.html",
  495. controller : 'VendorsInfoCtrl'
  496. }).state('baseInfo.customerInfo', {
  497. url : '/enume/customerInfo',
  498. templateUrl : "static/tpl/index/baseInfo/customersInfo.html",
  499. controller : 'CustomersInfoCtrl'
  500. }).state('baseInfo.enume', {
  501. url : '/enume',
  502. templateUrl : "static/tpl/index/baseInfo/vendorAndCustomer.html",
  503. }).state('baseInfo.partner', {
  504. url : '/partner',
  505. templateUrl : "static/tpl/index/baseInfo/addPartners.html",
  506. controller : 'AddPartnersCtrl'
  507. }).state('baseInfo.partner_searchresult', {
  508. url : '/search',
  509. templateUrl : "static/tpl/index/baseInfo/searchresult.html",
  510. controller : 'EnterpriseSearchCtrl'
  511. }).state('baseInfo.invitation', {
  512. url : '/invitation',
  513. templateUrl : "static/tpl/index/baseInfo/invitation.html",
  514. controller : 'InvitationCtrl'
  515. }).state('qc', {
  516. url : "/qc",
  517. views : {
  518. "left-view" : {
  519. templateUrl : "static/tpl/index/qc/left.html"
  520. },
  521. "right-view" : {
  522. templateUrl : "static/tpl/index/qc/right.html"
  523. }
  524. }
  525. }).state('qc.index', {
  526. url : "",
  527. templateUrl : "static/tpl/index/qc/index.html"
  528. }).state('qc.home', {
  529. url : "/",
  530. templateUrl : "static/tpl/index/qc/index.html"
  531. }).state('fa', {
  532. url : "/fa",
  533. views : {
  534. "left-view" : {
  535. templateUrl : "static/tpl/index/fa/left.html"
  536. },
  537. "right-view" : {
  538. templateUrl : "static/tpl/index/fa/right.html"
  539. }
  540. }
  541. }).state('fa.index', {
  542. url : "",
  543. templateUrl : "static/tpl/index/fa/index.html"
  544. }).state('fa.home', {
  545. url : "/",
  546. templateUrl : "static/tpl/index/fa/index.html"
  547. }).state('fa.apBill', {
  548. url : "/apBill",
  549. templateUrl : "static/tpl/index/fa/apBill.html",
  550. controller: 'SaleApBillCtrl'
  551. }).state('fa.apBill_detail', {
  552. url : "/apBill/:id",
  553. templateUrl : "static/tpl/index/fa/apBill_detail.html",
  554. controller: 'SaleApBillDetailCtrl'
  555. }).state('fa.arCheck', {
  556. url : "/arCheck",
  557. templateUrl : "static/tpl/index/fa/arCheck.html",
  558. controller: 'SaleArCheckCtrl'
  559. }).state('fa.arCheck_detail', {
  560. url : "/arCheck/:id",
  561. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  562. controller: 'SaleArCheckDetailCtrl'
  563. }).state('fa.apCheck', {
  564. url : "/apCheck",
  565. params:{
  566. 'id':null
  567. },
  568. templateUrl : "static/tpl/index/fa/apCheck.html",
  569. controller: 'PurchaseApCheckCtrl'
  570. }).state('fa.apCheck_detail', {
  571. url : "/apCheck/:id",
  572. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  573. controller: 'PurchaseApCheckDetailCtrl'
  574. }).state('fa.apCheckList', {
  575. url : "/apCheckList",
  576. templateUrl : "static/tpl/index/fa/apCheckList.html",
  577. controller: 'PurchaseApCheckListCtrl'
  578. }).state('fa.adjustList', {
  579. url : "/adjustList",
  580. templateUrl : "static/tpl/index/fa/adjustList.html",
  581. controller: 'PurchaseAdjustListCtrl'
  582. }).state('make', {
  583. url : "/make",
  584. views : {
  585. "left-view" : {
  586. templateUrl : "static/tpl/index/make/left.html"
  587. },
  588. "right-view" : {
  589. templateUrl : "static/tpl/index/make/right.html"
  590. }
  591. }
  592. }).state('make.index', {
  593. url : "",
  594. templateUrl : "static/tpl/index/make/index.html"
  595. }).state('make.home', {
  596. url : "/",
  597. templateUrl : "static/tpl/index/make/index.html"
  598. }).state('cs', {// 客户服务
  599. url : "/cs",
  600. views : {
  601. "left-view" : {
  602. templateUrl : "static/tpl/index/cs/left.html"
  603. },
  604. "right-view" : {
  605. templateUrl : "static/tpl/index/cs/right.html"
  606. }
  607. }
  608. }).state('cs.index', {
  609. url : "",
  610. templateUrl : "static/tpl/index/cs/index.html"
  611. }).state('cs.home', {
  612. url : "/",
  613. templateUrl : "static/tpl/index/cs/index.html"
  614. }).state('search', { //顶部搜索
  615. url: "/search?keyword=",
  616. views : {
  617. "left-view" : {
  618. templateUrl : "static/tpl/index/search/left.html"
  619. },
  620. "right-view" : {
  621. templateUrl: "static/tpl/index/search/search_result.html",
  622. controller: 'TopSearchCtrl'
  623. }
  624. }
  625. }).state('approvalflow', { //审批流
  626. url: "/approvalFlow",
  627. views : {
  628. "left-view" : {
  629. templateUrl : "static/tpl/index/approvalFlow/left.html"
  630. },
  631. "right-view" : {
  632. templateUrl: "static/tpl/index/approvalFlow/right.html",
  633. }
  634. }
  635. }).state('approvalflow.flow', {
  636. url : "/flow",
  637. templateUrl : "static/tpl/index/approvalFlow/home.html",
  638. controller: 'approvalFlowCtrl'
  639. }).state('approvalflow.enterprise', {
  640. url : "/enterprise",
  641. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  642. controller: 'EnterpriseCtrl'
  643. }).state('approvalflow.user', {
  644. url : "/user",
  645. templateUrl : "static/tpl/index/approvalFlow/user.html",
  646. controller: 'UserCtrl'
  647. }).state('approvalflow.log', {
  648. url : "/log",
  649. templateUrl : "static/tpl/index/approvalFlow/log.html",
  650. controller: 'LogCtrl'
  651. }).state('approvalflow.resource', {
  652. url : "/resource",
  653. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  654. controller: 'ResourceCtrl'
  655. }).state('approvalflow.role', {
  656. url : "/role",
  657. templateUrl : "static/tpl/index/approvalFlow/role.html",
  658. controller: 'RoleCtrl'
  659. }).state('approvalflow.product', {
  660. url : "/product",
  661. templateUrl : "static/tpl/index/approvalFlow/prodList.html",
  662. controller: 'ProductAllCtrl'
  663. });
  664. $urlRouterProvider.otherwise('/index');
  665. }]);
  666. /**
  667. * 表示符号
  668. */
  669. app.factory('Symbol', function(){
  670. return {
  671. currency: function(cur) {
  672. if(cur == 'RMB') return '¥';
  673. else if(cur == 'USD') return '$';
  674. else if(cur == 'EUR') return '€';
  675. else if(cur == null || cur == '') return '¥';
  676. else return cur;
  677. }
  678. };
  679. }).factory('Lodop',function(){
  680. return {
  681. getLodop:function(oOBJECT,oEMBED){
  682. var CreatedOKLodop7766=null;
  683. /**************************
  684. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  685. IE系列、IE内核系列的浏览器采用oOBJECT,
  686. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  687. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  688. 64位浏览器指向64位的安装程序install_lodop64.exe。
  689. **************************/
  690. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  691. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  692. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  693. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  694. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  695. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  696. var LODOP;
  697. try{
  698. //=====判断浏览器类型:===============
  699. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  700. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  701. //=====如果页面有Lodop就直接使用,没有则新建:==========
  702. if (oOBJECT!=undefined || oEMBED!=undefined) {
  703. if (isIE)
  704. LODOP=oOBJECT;
  705. else
  706. LODOP=oEMBED;
  707. } else {
  708. if (CreatedOKLodop7766==null){
  709. LODOP=document.createElement("object");
  710. LODOP.setAttribute("width",0);
  711. LODOP.setAttribute("height",0);
  712. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  713. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  714. else LODOP.setAttribute("type","application/x-print-lodop");
  715. document.documentElement.appendChild(LODOP);
  716. CreatedOKLodop7766=LODOP;
  717. } else
  718. LODOP=CreatedOKLodop7766;
  719. };
  720. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  721. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  722. if (navigator.userAgent.indexOf('Chrome')>=0)
  723. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  724. if (navigator.userAgent.indexOf('Firefox')>=0)
  725. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  726. if (is64IE) document.write(strHtm64_Install); else
  727. if (isIE) document.write(strHtmInstall); else
  728. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  729. return LODOP;
  730. } else
  731. if (LODOP.VERSION<"6.1.9.8") {
  732. if (is64IE) document.write(strHtm64_Update); else
  733. if (isIE) document.write(strHtmUpdate); else
  734. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  735. return LODOP;
  736. };
  737. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  738. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  739. //============================================================
  740. return LODOP;
  741. } catch(err) {
  742. if (is64IE)
  743. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  744. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  745. return LODOP;
  746. };
  747. }
  748. }
  749. });
  750. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
  751. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  752. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  753. if (routeState.indexOf('/') > -1)
  754. routeState = routeState.substring(0, routeState.indexOf('/'));
  755. if (routeState.indexOf('.') > -1)
  756. routeState = routeState.substring(0, routeState.indexOf('.'));
  757. $scope.routeState = routeState || 'home';
  758. });
  759. $scope.search = function(keyword) {
  760. if(keyword != null && keyword != '') {
  761. $rootScope.searchKeyword = keyword;
  762. window.location.hash = '#/search?keyword='+keyword;
  763. }
  764. };
  765. $scope.showMessage = function() {
  766. var $modalInstance = $modal.open({
  767. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  768. controller: 'PagingReleaseCtrl'
  769. });
  770. };
  771. }]);
  772. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  773. BaseService.scrollBackToTop();
  774. $scope.active = "todo";
  775. $scope.setActive = function(state) {
  776. if($scope.active != state) {
  777. $scope.active = state;
  778. if($scope.tableParams.page() == 1)
  779. $scope.tableParams.reload();
  780. else
  781. $scope.tableParams.page(1);
  782. }
  783. };
  784. $scope.tableParams = new ngTableParams({
  785. page : 1,
  786. count : 5,
  787. sorting: {
  788. 'releaseDetail.release.date': 'desc'
  789. }
  790. }, {
  791. total : 0,
  792. counts: [5, 10, 25, 50],
  793. getData : function($defer, params) {
  794. $scope.loading = true;
  795. var pageParams = params.url();
  796. var realActive = {};
  797. pageParams.searchFilter = { // 筛选条件
  798. keyword: $scope.keyword
  799. // fromDate: getDateTime($scope.condition.dateFrom),
  800. // endDate: getDateTime($scope.condition.dateTo)
  801. };
  802. // AccountEnterprise.get({}, function(data){
  803. // $scope.loading = false;
  804. // $scope.currentEn = data;
  805. // });
  806. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  807. $scope.loading = false;
  808. if(page) {
  809. params.total(page.totalElement);
  810. $defer.resolve(page.content);
  811. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  812. }
  813. }, function(response){
  814. $scope.loading = false;
  815. toaster.pop('error', '数据加载失败', response.data);
  816. });
  817. }
  818. });
  819. $scope.close = function() {
  820. $modalInstance.close();
  821. };
  822. $scope.checks = {
  823. checked : false
  824. };// 全选框
  825. $scope.checkAll = function() {
  826. angular.forEach($scope.tableParams.data, function(message) {
  827. message.checked = $scope.checks.checked;
  828. });
  829. };
  830. // 单选
  831. $scope.checkOne = function(vendor) {
  832. vendor.checked = true;
  833. var checked = true;
  834. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  835. if (!message.checked) {
  836. checked = false;
  837. }
  838. });
  839. $scope.checks.checked = checked;
  840. };
  841. // 单反选
  842. $scope.unCheckOne = function(vendor) {
  843. vendor.checked = false;
  844. $scope.checks.checked = false;
  845. };
  846. // 标为已读
  847. $scope.setRead = function() {
  848. var selectedMessages = [];
  849. angular.forEach($scope.tableParams.data, function(message) {
  850. if(message.checked) {
  851. selectedMessages.push(message);
  852. }
  853. });
  854. PagingRelease.setRead({}, selectedMessages , function(message) {
  855. $scope.tableParams.page(1);
  856. $scope.tableParams.reload();
  857. });
  858. };
  859. // 搜索框回车
  860. $scope.onSearch = function() {
  861. $scope.tableParams.page(1);
  862. $scope.tableParams.reload();
  863. };
  864. }]);
  865. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  866. var search = $rootScope.searchKeyword;
  867. return function(content, search) {
  868. content = encodeURI(content);
  869. search = encodeURI(search);
  870. var reg = new RegExp(search, 'gim');
  871. var result = content.replace(reg,'<font color="red">$&</font>');
  872. result = decodeURI(result);
  873. return $sce.trustAsHtml(result);
  874. }
  875. $rootScope.searchKeyword = null;// 清除缓存的关键字
  876. }]);
  877. /**
  878. * 顶部搜索
  879. */
  880. 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) {
  881. BaseService.scrollBackToTop();
  882. $scope.active = 'all';
  883. $scope.tip = $rootScope.searchKeyword;
  884. // 企业搜索
  885. var getService = function() {
  886. return getAccountUserSpace;
  887. };
  888. $scope.tableParams = new ngTableParams({
  889. page : 1,
  890. count : 5,
  891. sorting: {
  892. }
  893. }, {
  894. total : 0,
  895. counts: [5, 10, 25, 50],
  896. getData : function($defer, params) {
  897. $scope.loading = true;
  898. var pageParams = params.url();
  899. pageParams.keyword = $rootScope.searchKeyword;
  900. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  901. $scope.loading = false;
  902. if(page) {
  903. $scope.total = page.totalElement;
  904. params.total(page.totalElement);
  905. $defer.resolve(page.content);
  906. }
  907. }, function(response) {
  908. $scope.loading = false;
  909. toaster.pop('error', '数据加载失败', response.data);
  910. });
  911. }
  912. });
  913. // 添加合作关系
  914. $scope.addPartner = function(name, businessCode) {
  915. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  916. if(data.success) {
  917. toaster.pop("success", '添加成功', data.success);
  918. }
  919. if(data.error) {
  920. toaster.pop("error", '添加失败', data.error);
  921. }
  922. }, function(response) {
  923. toaster.pop('error','失败',response.data);
  924. });
  925. }
  926. // 物料搜索
  927. var getProdService = function() {
  928. return SearchProd;
  929. };
  930. $scope.prodTableParams = new ngTableParams({
  931. page : 1,
  932. count : 5,
  933. sorting: {
  934. }
  935. }, {
  936. total : 0,
  937. counts: [5, 10, 25, 50],
  938. getData : function($defer, params) {
  939. $scope.loading = true;
  940. var pageParams = params.url();
  941. pageParams.keyword = $rootScope.searchKeyword;
  942. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  943. $scope.loading = false;
  944. if(page) {
  945. $scope.prodtotal = page.totalElement;
  946. params.total(page.totalElement);
  947. $defer.resolve(page.content);
  948. }
  949. }, function(response) {
  950. $scope.loading = false;
  951. toaster.pop('error', '数据加载失败', response.data);
  952. });
  953. }
  954. });
  955. /**
  956. * 向企业购买
  957. */
  958. $scope.PurcByEn = function(businessCode) {
  959. $rootScope.businessCode = businessCode;
  960. window.location.hash = "#/purc/addOrder";
  961. }
  962. /**
  963. * 选中单个物料购买
  964. * @param businessCode
  965. * @param id
  966. */
  967. $scope.PurcByEnAndProd = function(businessCode, id) {
  968. $rootScope.businessCode = businessCode;
  969. $rootScope.prodId = id;
  970. window.location.hash = "#/purc/addOrder";
  971. }
  972. /**
  973. * 询价
  974. */
  975. $scope.PurcInquiry = function(businessCode, id){
  976. $rootScope.prodId = id;
  977. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  978. }
  979. /**
  980. * 邀请注册商务平台
  981. */
  982. $scope.invite = function(name) {
  983. var modalInstance = $modal.open({
  984. animation: true,
  985. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  986. controller: 'InviteCtrl',
  987. resolve: {
  988. enname: function(){return name}
  989. }
  990. });
  991. modalInstance.result.then(function(data) {
  992. InvitationRecord.invite({formStore: data}, {}, function(data) {
  993. if(data.success) {
  994. toaster.pop('success', '提示', data.success);
  995. }
  996. if(data.error) {
  997. toaster.pop('error', '提示', data.error);
  998. }
  999. }, function(response) {
  1000. toaster.pop('error', '提示', response.data);
  1001. });
  1002. });
  1003. }
  1004. /**
  1005. * 立即查看
  1006. */
  1007. $scope.view = function(name) {
  1008. $rootScope.vendName = name;
  1009. window.location.hash = "#/baseInfo/myRquest";
  1010. }
  1011. }]);
  1012. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  1013. $scope.enter = {
  1014. vendname: enname
  1015. };
  1016. $scope.save = function(enter) {
  1017. if(!enter.vendusertel && !enter.venduseremail) {
  1018. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1019. } else {
  1020. $modalInstance.close(enter);
  1021. }
  1022. }
  1023. $scope.cancel = function() {
  1024. $modalInstance.dismiss();
  1025. }
  1026. }]);
  1027. /**
  1028. * 邀请记录
  1029. */
  1030. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', function($scope, toaster, InvitationRecord, BaseService, ngTableParams) {
  1031. BaseService.scrollBackToTop();
  1032. $scope.status = "invitation";
  1033. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1034. page : 1,
  1035. count : 10,
  1036. sorting: {
  1037. }
  1038. }, {
  1039. total : 0,
  1040. counts: [],
  1041. getData : function($defer, params) { // 获取数据的方法
  1042. $scope.loading = true;
  1043. var pageParams = params.url();
  1044. pageParams.keyword = $scope.keyword;
  1045. $scope.tip = $scope.keyword;
  1046. InvitationRecord.records.call(null, BaseService.parseParams(pageParams), function(page){
  1047. $scope.loading = false;
  1048. if(page) {
  1049. params.total(page.totalElement);
  1050. $defer.resolve(page.content);
  1051. }
  1052. }, function(response){
  1053. $scope.loading = false;
  1054. toaster.pop('error', '数据加载失败', response.data);
  1055. });
  1056. }
  1057. });
  1058. $scope.onSearch = function(keyword){
  1059. $scope.tableParams.page(1);
  1060. $scope.tableParams.reload();
  1061. $scope.tip = keyword;
  1062. }
  1063. }]);
  1064. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1065. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1066. //手机号码格式验证
  1067. // var checkTel = function(data){
  1068. // var userTel = data.userTel;
  1069. // $scope.checkResult = false;
  1070. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  1071. // if(!(telephone).test(userTel)){
  1072. // var modalInstance = $modal.open({
  1073. // animation: true,
  1074. // templateUrl: 'static/tpl/index/account/checkTel.html',
  1075. // controller: 'CheckTelCtrl',
  1076. // backdrop: 'static',
  1077. // keyboard: false,
  1078. // resolve: {
  1079. // user: function(){
  1080. // return data;
  1081. // },
  1082. // }
  1083. // });
  1084. // modalInstance.result.then(function(){
  1085. // }, function(){
  1086. //
  1087. // });
  1088. // } else {
  1089. // $scope.checkResult = true;
  1090. // }
  1091. // };
  1092. AuthenticationService.getAuthentication().success(function(data) {
  1093. if(data.enterprises) {
  1094. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1095. if(data.enterprises.length > 1) {
  1096. var enSelect = [];
  1097. angular.forEach(data.enterprises, function(e){
  1098. if(e.current)
  1099. data.enterprise = e;
  1100. else
  1101. enSelect.push(e);
  1102. });
  1103. data.enSelect = enSelect;
  1104. }
  1105. }
  1106. $scope.userInfo = data;
  1107. if (data == null || !data.userUU) {
  1108. $scope.isAuthed = false;
  1109. AuthenticationService.redirectSignin();
  1110. } else {
  1111. //跳转到手机号码验证
  1112. // checkTel($scope.userInfo);
  1113. }
  1114. });
  1115. $scope.logout = function() {
  1116. $modal.open({
  1117. templateUrl: 'static/tpl/index/account/logout.html',
  1118. controller: 'LogOutCtrl'
  1119. }).result.then(function(s){
  1120. if(s) {
  1121. AuthenticationService.logout();
  1122. }
  1123. });
  1124. };
  1125. $scope.switchto = function(enUU) {// 切换企业
  1126. AuthenticationService.reSignin(enUU).success(function(){
  1127. $window.location.reload();
  1128. });
  1129. };
  1130. $scope.addFavorite = function(){
  1131. var url = encodeURI(window.location.href);
  1132. try{
  1133. //ie浏览器收藏方式
  1134. window.external.addFavorite(url, "优软商务平台");
  1135. }catch(e) {
  1136. try{
  1137. //火狐浏览器收藏方式
  1138. window.sidebar.addPanel("优软商务平台", url);
  1139. }catch (e) {
  1140. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  1141. "或手动在浏览器里进行设置。");
  1142. }
  1143. }
  1144. };
  1145. }]);
  1146. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1147. $scope.close = function(confirm) {
  1148. $modalInstance.close(confirm);
  1149. };
  1150. }]);
  1151. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1152. $scope.image = {src: null};
  1153. // 图片上传成功之后
  1154. $scope.onUploadSuccess = function(data){
  1155. var path = data.path;
  1156. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1157. $scope.$apply(function(){
  1158. $scope.image.src = data.path;
  1159. $scope.image.thumb = path;
  1160. });
  1161. };
  1162. $scope.close = function() {
  1163. $modalInstance.dismiss();
  1164. };
  1165. $scope.confirm = function() {
  1166. $modalInstance.close($scope.image);
  1167. $scope.imageUrl = null;
  1168. };
  1169. }]);
  1170. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function($scope, SnapshotService, BaseService, $rootScope){
  1171. BaseService.scrollBackToTop();
  1172. SnapshotService.getTodo(function(data){
  1173. $scope.todo = data;
  1174. });
  1175. $scope.setTenderActive = function(active) {
  1176. $rootScope.tenderActive = active;
  1177. window.location.hash = '#/purc/tender';
  1178. }
  1179. }]);
  1180. // header
  1181. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1182. SnapshotService.getMessage(function(data){
  1183. $scope.message = data;
  1184. });
  1185. }]);
  1186. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1187. SaleTruck.query({}, function(data){
  1188. $rootScope.truck = data;
  1189. $scope.truckCount = data ? data.length : 0;
  1190. });
  1191. $scope.$watch(function(){
  1192. return $rootScope.truck;
  1193. }, function(data) {
  1194. $scope.truckCount = data ? data.length : 0;
  1195. }, true);
  1196. $scope.clearAll = function() {
  1197. SaleTruck.remove({}, function(){
  1198. $rootScope.truck = [];
  1199. });
  1200. };
  1201. $scope.openTrack = function() {
  1202. $modal.open({
  1203. templateUrl: 'static/tpl/index/sale/track.html',
  1204. controller: 'TruckModalCtrl',
  1205. size: 'lg'
  1206. }).result.then(function(s){
  1207. if(s) {
  1208. $scope.clearAll();
  1209. $rootScope.dataChanged = true;
  1210. }
  1211. });
  1212. };
  1213. }]);
  1214. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  1215. $scope.saleSend = {sendItems: []};
  1216. SaleTruck.detail({}, function(data){
  1217. // 按物料编号排序
  1218. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1219. });
  1220. $scope.remove = function(index, notice) {
  1221. SaleTruck.remove({noticeId: notice.id}, function(data){
  1222. $rootScope.truck = data;
  1223. $scope.notices.splice(index, 1);
  1224. });
  1225. };
  1226. $scope.$watch(function(){
  1227. return $scope.notices;
  1228. }, function(data) {
  1229. var q = 0, t = 0;
  1230. if(data) {
  1231. angular.forEach(data,function(d){
  1232. q += d.thisSendQty;
  1233. t += d.thisSendQty * d.orderItem.price;
  1234. });
  1235. }
  1236. $scope.totalQty = q;
  1237. $scope.total = t;
  1238. }, true);
  1239. $scope.cancel = function() {
  1240. $modalInstance.close();
  1241. };
  1242. $scope.send = function() {// 发货
  1243. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1244. toaster.pop('error', '错误', '请输入送货单号');
  1245. return;
  1246. }
  1247. var currency = $scope.notices[0].orderItem.order.currency,
  1248. custUU = $scope.notices[0].enUU,
  1249. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1250. var num = 1;
  1251. for(var i in $scope.notices) {
  1252. var item = $scope.notices[i];
  1253. if(item.id) {
  1254. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1255. valid = false;
  1256. break;
  1257. }
  1258. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1259. }
  1260. }
  1261. if(!valid) {
  1262. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1263. } else {
  1264. var send = angular.extend(angular.copy($scope.saleSend), {
  1265. currency: currency,
  1266. custUU: custUU,
  1267. payments: payments,
  1268. sendItems: items
  1269. });
  1270. PurcNotice.sendByBatch({}, send, function(data){
  1271. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1272. $modalInstance.close(true);
  1273. $state.go('sale.send_detail', {id: data.id});
  1274. }, function(response){
  1275. toaster.pop('error', '错误', response.data);
  1276. });
  1277. }
  1278. };
  1279. }]);
  1280. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1281. SaleStat.cust({}, function(data){
  1282. var p = [], q = [];
  1283. angular.forEach(data.month, function(d){
  1284. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1285. });
  1286. angular.forEach(data.year, function(d){
  1287. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1288. });
  1289. $scope.custCharts = {
  1290. month : {
  1291. chartType : 'pie',
  1292. datas : {
  1293. data : p
  1294. },
  1295. config : {
  1296. labels : false,
  1297. title : "客户月采购量排行榜",
  1298. legend : {
  1299. display : true,
  1300. position : 'right'
  1301. },
  1302. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1303. click : function(d) {
  1304. },
  1305. mouseover : function(d) {
  1306. },
  1307. mouseout : function(d) {
  1308. },
  1309. innerRadius : 0,
  1310. lineLegend : 'lineEnd'
  1311. }
  1312. },
  1313. year : {
  1314. chartType : 'pie',
  1315. datas : {
  1316. data : q
  1317. },
  1318. config : {
  1319. labels : false,
  1320. title : "客户年采购量排行榜",
  1321. legend : {
  1322. display : true,
  1323. position : 'right'
  1324. },
  1325. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1326. click : function(d) {
  1327. },
  1328. mouseover : function(d) {
  1329. },
  1330. mouseout : function(d) {
  1331. },
  1332. innerRadius : 0,
  1333. lineLegend : 'lineEnd'
  1334. }
  1335. }
  1336. };
  1337. });
  1338. SaleStat.seller({}, function(data){
  1339. var p = [], q = [];
  1340. angular.forEach(data.month, function(d){
  1341. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1342. });
  1343. angular.forEach(data.year, function(d){
  1344. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1345. });
  1346. $scope.sellerCharts = {
  1347. month : {
  1348. chartType : 'pie',
  1349. datas : {
  1350. data : p
  1351. },
  1352. config : {
  1353. labels : false,
  1354. title : "业务员月销量排行榜",
  1355. legend : {
  1356. display : true,
  1357. position : 'right'
  1358. },
  1359. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1360. click : function(d) {
  1361. },
  1362. mouseover : function(d) {
  1363. },
  1364. mouseout : function(d) {
  1365. },
  1366. innerRadius : 0,
  1367. lineLegend : 'lineEnd'
  1368. }
  1369. },
  1370. year : {
  1371. chartType : 'pie',
  1372. datas : {
  1373. data : q
  1374. },
  1375. config : {
  1376. labels : false,
  1377. title : "业务员年销量排行榜",
  1378. legend : {
  1379. display : true,
  1380. position : 'right'
  1381. },
  1382. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1383. click : function(d) {
  1384. },
  1385. mouseover : function(d) {
  1386. },
  1387. mouseout : function(d) {
  1388. },
  1389. innerRadius : 0,
  1390. lineLegend : 'lineEnd'
  1391. }
  1392. }
  1393. };
  1394. });
  1395. }]);
  1396. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1397. SaleStat.get({}, function(data){
  1398. var p = [], q = [], r = [];
  1399. angular.forEach(data.day, function(d){
  1400. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1401. });
  1402. angular.forEach(data.month, function(d){
  1403. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1404. });
  1405. angular.forEach(data.year, function(d){
  1406. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1407. });
  1408. $scope.charts = {
  1409. day : {
  1410. chartType : "line",
  1411. datas: {
  1412. series: ['销售额'],
  1413. data: p
  1414. },
  1415. config : {
  1416. "labels": false,
  1417. "title": "销售额统计(近15日线)",
  1418. "legend": {
  1419. "display": true,
  1420. "position": "right"
  1421. },
  1422. colors : [ '#4D9934'],
  1423. "innerRadius": 0,
  1424. "lineLegend": "lineEnd"
  1425. }
  1426. },
  1427. month: {
  1428. chartType : "line",
  1429. datas: {
  1430. series: ['销售额'],
  1431. data: q
  1432. },
  1433. config : {
  1434. "labels": false,
  1435. "title": "销售额统计(近12月线)",
  1436. "legend": {
  1437. "display": true,
  1438. "position": "right"
  1439. },
  1440. colors : [ '#4D9934'],
  1441. "innerRadius": 0,
  1442. "lineLegend": "lineEnd"
  1443. }
  1444. },
  1445. year: {
  1446. chartType : "line",
  1447. datas: {
  1448. series: ['销售额'],
  1449. data: r
  1450. },
  1451. config : {
  1452. "labels": false,
  1453. "title": "销售额统计(近10年线)",
  1454. "legend": {
  1455. "display": true,
  1456. "position": "right"
  1457. },
  1458. colors : [ '#4D9934'],
  1459. "innerRadius": 0,
  1460. "lineLegend": "lineEnd"
  1461. }
  1462. }
  1463. };
  1464. });
  1465. }]);
  1466. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1467. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1468. $scope.notices = data;
  1469. });
  1470. $scope.dateTime = new Date();
  1471. }]);
  1472. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1473. // SnapshotService.getTender(250, function(data){
  1474. // $scope.tenders = data;
  1475. // console.log(data);
  1476. // var newDate = new Date();
  1477. // newDate = newDate.setDate(newDate.getDate() - 3);
  1478. // angular.forEach($scope.tenders, function(tender) {
  1479. // if (tender.date > newDate) {
  1480. // tender.isNew = true;
  1481. // } else {
  1482. // tender.isNew = false;
  1483. // }
  1484. // });
  1485. // });
  1486. SnapshotService.getOpenTender(5, function(data){
  1487. $scope.openTenders = data;
  1488. var newDate = new Date();
  1489. newDate = newDate.getTime() - 3*24*60*60*1000;
  1490. angular.forEach($scope.openTenders, function(tender) {
  1491. if (tender.date - newDate > 0) {
  1492. tender.isNew = true;
  1493. } else {
  1494. tender.isNew = false;
  1495. }
  1496. });
  1497. });
  1498. $scope.dateTime = new Date();
  1499. }]);
  1500. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1501. VendorService.getCount(function(date){
  1502. $scope.count = date;
  1503. });
  1504. }]);
  1505. // 客户
  1506. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1507. BaseService.scrollBackToTop();
  1508. $scope.userInfoResult = true;
  1509. AuthenticationService.getAuthentication().success(function(data) {
  1510. $scope.loading = false;
  1511. $scope.thisUser = data;
  1512. });
  1513. var getCustInfos = function(custuu) {
  1514. if(custuu) {
  1515. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1516. $scope.custInfos = data;
  1517. var getPage = function(page, size){
  1518. if($scope.custInfos) {
  1519. var result = {};
  1520. result.totalCount = $scope.custInfos.length;
  1521. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1522. if($scope.custInfos.length % size == 0) {
  1523. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1524. }else {
  1525. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1526. }
  1527. result.first = page == 1;
  1528. result.last = page == result.totalPage;
  1529. result.page = page;
  1530. result.next = page - 0 + 1;
  1531. result.pre = page - 1;
  1532. return result;
  1533. }
  1534. }
  1535. $scope.userdata = getPage(1,4);
  1536. $scope.first = function (){
  1537. $scope.userdata = getPage($scope.userdata.pre,4);
  1538. }
  1539. $scope.last = function (){
  1540. $scope.userdata = getPage($scope.userdata.next,4);
  1541. }
  1542. }, function(response){
  1543. $scope.loading = false;
  1544. toaster.pop('error', '数据加载失败', response.data);
  1545. });
  1546. }
  1547. }
  1548. $scope.addUserInfo = function(customer) {
  1549. //TODO
  1550. if ($scope.thisUser.sys) {
  1551. var modalInstance = $modal.open({
  1552. animation: true,
  1553. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1554. controller: 'AddUserInfoCtrl',
  1555. resolve: {
  1556. customer: function() {
  1557. return customer;
  1558. }
  1559. }
  1560. });
  1561. modalInstance.result.then(function(changed, checked){
  1562. if(changed) {
  1563. if(checked)
  1564. $scope.newUser.roles = checked;
  1565. else
  1566. loadUsers();
  1567. }
  1568. });
  1569. } else {
  1570. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1571. }
  1572. }
  1573. $scope.showUserInfo = function(customer,boo) {
  1574. $scope.custInfo = customer;
  1575. if(boo) {
  1576. getCustInfos(customer.myEnterprise.uu);
  1577. $scope.userInfoResult = true;
  1578. }
  1579. }
  1580. $scope.customerParams = new ngTableParams({
  1581. page : 1,
  1582. count : 10
  1583. }, {
  1584. total : 0,
  1585. counts: [5, 10, 25, 50],
  1586. getData : function($defer, params) {
  1587. $scope.loading = true;
  1588. var pageParams = params.url();
  1589. pageParams.keyword = $scope.keyword;
  1590. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1591. $scope.loading = false;
  1592. if(page) {
  1593. params.total(page.totalElement);
  1594. $defer.resolve(page.content);
  1595. }
  1596. $scope.totalCount = page.totalElement;
  1597. }, function(response){
  1598. $scope.loading = false;
  1599. toaster.pop('error', '数据加载失败', response.data);
  1600. });
  1601. }
  1602. });
  1603. // 搜索框回车
  1604. $scope.onSearch = function(keyword) {
  1605. $scope.customerParams.page(1);
  1606. $scope.customerParams.reload();
  1607. $scope.tip = keyword;
  1608. };
  1609. // 查看详情
  1610. $scope.viewDetail = function(id) {
  1611. window.location.hash = "#/sale/customer/" + id;
  1612. }
  1613. }]);
  1614. // 客户详情
  1615. 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) {
  1616. BaseService.scrollBackToTop();
  1617. $scope.userInfoResult = true;
  1618. AuthenticationService.getAuthentication().success(function(data) {
  1619. $scope.loading = false;
  1620. $scope.thisUser = data;
  1621. });
  1622. $scope.vendorContacts = [];
  1623. var loadData = function() {
  1624. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1625. $scope.customer = data.myEnterprise;
  1626. $scope.customerInfo = data;
  1627. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1628. $scope.Contacts = data;
  1629. });
  1630. // 查看已分配人员
  1631. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1632. $scope.custInfos = data;
  1633. var getPage = function(page, size){
  1634. if($scope.custInfos) {
  1635. var result = {};
  1636. result.totalCount = $scope.custInfos.length;
  1637. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1638. if($scope.custInfos.length % size == 0) {
  1639. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1640. }else {
  1641. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1642. }
  1643. result.first = page == 1;
  1644. result.last = page == result.totalPage;
  1645. result.page = page;
  1646. result.next = page - 0 + 1;
  1647. result.pre = page - 1;
  1648. return result;
  1649. }
  1650. }
  1651. $scope.userdata = getPage(1,4);
  1652. $scope.first = function (){
  1653. $scope.userdata = getPage($scope.userdata.pre,4);
  1654. }
  1655. $scope.last = function (){
  1656. $scope.userdata = getPage($scope.userdata.next,4);
  1657. }
  1658. }, function(response){
  1659. $scope.loading = false;
  1660. toaster.pop('error', '数据加载失败', response.data);
  1661. });
  1662. });
  1663. };
  1664. loadData();
  1665. // 新增客户联系人
  1666. $scope.addContact = function(uu) {
  1667. var modalInstance = $modal.open({
  1668. animation: true,
  1669. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1670. controller: 'AddContacCtrl',
  1671. resolve: {
  1672. }
  1673. });
  1674. modalInstance.result.then(function(data) {
  1675. $scope.contact = data;
  1676. $scope.contact.myenuu = uu;
  1677. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1678. toaster.pop('success', '提示', '联系人保存成功');
  1679. $scope.Contacts.push(data);
  1680. }, function(response) {
  1681. toaster.pop('error', '失败', response.data);
  1682. });
  1683. });
  1684. }
  1685. // 编辑客户联系人
  1686. $scope.edit = function(contact) {
  1687. var modalInstance = $modal.open({
  1688. animation: true,
  1689. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  1690. controller: 'EditContacCtrl',
  1691. resolve: {
  1692. contact: function() {
  1693. return contact;
  1694. }
  1695. }
  1696. });
  1697. modalInstance.result.then(function(data) {
  1698. $scope.contact = data;
  1699. Vendor.saveContact({}, $scope.contact, function(data) {
  1700. toaster.pop('success', '提示', '联系人修改成功');
  1701. }, function(response) {
  1702. toaster.pop('error', '失败', response.data);
  1703. });
  1704. });
  1705. }
  1706. // 删除客户联系人
  1707. $scope.deleteById = function(id, index) {
  1708. $scope.Contacts.splice(index, 1);
  1709. Vendor.deleteContact({id: id}, {}, function(data) {
  1710. toaster.pop('success', '提示', '客户联系人删除成功');
  1711. loadData();
  1712. }, function(response) {
  1713. toaster.pop('error', '提示', response.data);
  1714. });
  1715. }
  1716. // 供应商物料信息
  1717. $scope.viewProdList = function(uu){
  1718. $scope.uu = uu;
  1719. $scope.tableParams.page(1);
  1720. $scope.tableParams.reload();
  1721. };
  1722. // 搜索框回车
  1723. $scope.onSearch = function(keyword) {
  1724. $scope.keyword = keyword;
  1725. $scope.tableParams.page(1);
  1726. $scope.tableParams.reload();
  1727. };
  1728. // 供应商物料信息
  1729. $scope.tableParams = new ngTableParams({
  1730. page : 1,
  1731. count : 10
  1732. }, {
  1733. total : 0,
  1734. counts: [5, 10, 25, 50],
  1735. getData : function($defer, params) {
  1736. $scope.loading = true;
  1737. var pageParams = params.url();
  1738. pageParams.custUU = $scope.uu;
  1739. pageParams.keyword = $scope.keyword;
  1740. $scope.tip = $scope.keyword;
  1741. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1742. $scope.loading = false;
  1743. if(page) {
  1744. params.total(page.totalElement);
  1745. $scope.total = page.totalElement;
  1746. $defer.resolve(page.content);
  1747. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1748. }
  1749. }, function(response){
  1750. $scope.loading = false;
  1751. toaster.pop('error', '数据加载失败', response.data);
  1752. });
  1753. }
  1754. });
  1755. $scope.addUserInfo = function() {
  1756. //TODO
  1757. if ($scope.thisUser.sys) {
  1758. var modalInstance = $modal.open({
  1759. animation: true,
  1760. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1761. controller: 'AddUserInfoCtrl',
  1762. resolve: {
  1763. customer: function() {
  1764. return $scope.customerInfo;
  1765. }
  1766. }
  1767. });
  1768. modalInstance.result.then(function(changed, checked){
  1769. loadData();
  1770. if(changed) {
  1771. if(checked) {
  1772. $scope.newUser.roles = checked;
  1773. } else {
  1774. loadUsers();
  1775. }
  1776. }
  1777. });
  1778. } else {
  1779. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1780. }
  1781. }
  1782. $scope.Quotation = function(uu, id) {
  1783. $rootScope.custuu = uu;
  1784. $rootScope.prodId = id;
  1785. window.location.hash = "#/sale/quotation/new";
  1786. }
  1787. }]);
  1788. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1789. $scope.checkboxes = {
  1790. checked : false
  1791. };
  1792. $scope.loading = true;
  1793. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1794. $scope.userinfos = data;
  1795. $scope.loading = false;
  1796. })
  1797. // 点击勾选全部的复选框
  1798. $scope.checkAll = function() {
  1799. angular.forEach($scope.userinfos, function(item) {
  1800. item.distribute = $scope.checkboxes.checked;
  1801. });
  1802. };
  1803. // 点击其中一个明细的复选框
  1804. $scope.checkOne = function(vendor){
  1805. var result = true;
  1806. angular.forEach($scope.userinfos, function(item) {
  1807. if(item.distribute != true){
  1808. result = false;
  1809. return;
  1810. }
  1811. });
  1812. $scope.checkboxes.checked = result;
  1813. };
  1814. $scope.close = function(save) {
  1815. var chooseResult = [];
  1816. if(save) {
  1817. if(customer.myEnterprise.uu) {
  1818. angular.forEach($scope.userinfos, function(item, i) {
  1819. chooseResult.push(item);
  1820. });
  1821. if(chooseResult.length > 0) {
  1822. $scope.loading = true;
  1823. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1824. $scope.loading = false;
  1825. toaster.pop('success', '提示', '保存成功');
  1826. $modalInstance.close(false);
  1827. }, function(response){
  1828. $scope.loading = false;
  1829. toaster.pop('error', '保存失败', response.data);
  1830. $modalInstance.close(false);
  1831. })
  1832. } else {
  1833. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1834. }
  1835. } else {
  1836. $modalInstance.close(true, $scope.checkboxes.checked);
  1837. }
  1838. } else {
  1839. $modalInstance.close(false);
  1840. }
  1841. };
  1842. }]);
  1843. /**
  1844. * 页面状态按钮过滤
  1845. */
  1846. var getState = function(active) {
  1847. var fn = 'get';
  1848. switch(active) {
  1849. case 'done':
  1850. fn = 'getDone';break;
  1851. case 'todo':
  1852. fn = 'getTodo';break;
  1853. case 'end':
  1854. fn = 'getEnd';break;
  1855. case 'waiting':
  1856. fn = 'getWaiting';break;
  1857. case 'invalid':
  1858. fn = 'getInvalid';break;
  1859. // 已采纳
  1860. case 'agreed':
  1861. fn = 'getAgreed';break;
  1862. // 未采纳
  1863. case 'refused':
  1864. fn = 'getRefused';break;
  1865. }
  1866. return fn;
  1867. };
  1868. /**
  1869. * 改变单据日期范围
  1870. */
  1871. var getDateCondition = function(zone, condition) {
  1872. var date = new Date();
  1873. if(zone == -1) {
  1874. condition.dateFrom = null;
  1875. condition.dateTo = null;
  1876. } else if(zone == 1) {
  1877. date.setMonth(date.getMonth() - 1);
  1878. condition.dateFrom = date;
  1879. condition.dateTo = new Date();
  1880. } else if (zone == 6) {
  1881. date.setMonth(date.getMonth() - 6);
  1882. condition.dateFrom = date;
  1883. condition.dateTo = new Date();
  1884. } else {
  1885. date.setMonth(date.getMonth() - 6);
  1886. condition.dateFrom = null;
  1887. condition.dateTo = date;
  1888. }
  1889. };
  1890. /**
  1891. * 改变单据交货日期范围
  1892. */
  1893. var getDelveryCondition = function(zone, condition) {
  1894. var date = new Date();
  1895. if(zone == -1) {
  1896. condition.deliveryFrom = null;
  1897. condition.deliveryTo = null;
  1898. } else if(zone == 1) {
  1899. date.setMonth(date.getMonth() + 1);
  1900. condition.deliveryTo = date;
  1901. condition.deliveryFrom = new Date();
  1902. } else if (zone == 2) {
  1903. date.setMonth(date.getMonth() + 2);
  1904. condition.deliveryTo = date;
  1905. condition.deliveryFrom = new Date();
  1906. }
  1907. };
  1908. /**
  1909. * 将日期转化为整数日期
  1910. */
  1911. var getDateTime = function(date) {
  1912. if(angular.isDate(date)) {
  1913. return date.getTime();
  1914. } else {
  1915. return null;
  1916. }
  1917. };
  1918. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1919. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1920. BaseService.scrollBackToTop();
  1921. $scope.active = 'all';
  1922. $scope.dateZoneText = '不限';
  1923. $scope.deliveryZoneText = '不限';
  1924. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1925. $scope.changeDateZone = function(zone) {
  1926. $scope.condition.dateZone = zone;
  1927. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1928. $scope.condition.$dateZoneOpen = false;
  1929. getDateCondition(zone, $scope.condition);
  1930. $scope.tableParams.reload();
  1931. };
  1932. $scope.changeDeliveryZone = function(zone) {
  1933. $scope.condition.deliveryZoneText = zone;
  1934. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1935. $scope.condition.$delievryZoneOpen = false;
  1936. getDelveryCondition(zone, $scope.condition);
  1937. $scope.tableParams.reload();
  1938. };
  1939. // 切换单据类型
  1940. $scope.setActive = function(state) {
  1941. if($scope.active != state) {
  1942. $scope.active = state;
  1943. if($scope.tableParams.page() == 1)
  1944. $scope.tableParams.reload();
  1945. else
  1946. $scope.tableParams.page(1);
  1947. }
  1948. };
  1949. var getPurcStatus = function(active) {
  1950. var fn = 'getPurcAll';
  1951. switch(active) {
  1952. case 'done':
  1953. fn = 'getPurcDone';break;
  1954. case 'todo':
  1955. fn = 'getPurcTodo';break;
  1956. case 'end':
  1957. fn = 'getPurcEnd';break;
  1958. case 'waiting':
  1959. fn = 'getPurcWaiting';break;
  1960. }
  1961. return fn;
  1962. };
  1963. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1964. page : 1,
  1965. count : 5,
  1966. sorting: {
  1967. display: 'desc',
  1968. date: 'desc'
  1969. }
  1970. }, {
  1971. total : 0,
  1972. counts: [5, 10, 15, 25, 50],
  1973. getData : function($defer, params) {// 获取数据的方法
  1974. $scope.loading = true;
  1975. var pageParams = params.url();
  1976. pageParams.searchFilter = { // 筛选条件
  1977. keyword: $scope.keyword,
  1978. fromDate: getDateTime($scope.condition.dateFrom),
  1979. endDate: getDateTime($scope.condition.dateTo)
  1980. };
  1981. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1982. $scope.loading = false;
  1983. if(page) {
  1984. $defer.resolve(page.content);
  1985. $scope.total = page.totalElement;
  1986. params.total(page.totalElement);
  1987. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1988. }
  1989. }, function(response){
  1990. $scope.loading = false;
  1991. toaster.pop('error', '数据加载失败', response.data);
  1992. });
  1993. }
  1994. });
  1995. $scope.getReply = function(item) {
  1996. if(!item.replies) {
  1997. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1998. item.replies = replies;
  1999. });
  2000. }
  2001. };
  2002. $scope.getOrderTotal = function(items) {
  2003. var sum = 0;
  2004. angular.forEach(items, function(item){
  2005. sum += item.qty * item.price;
  2006. });
  2007. return sum;
  2008. };
  2009. $scope.openDatePicker = function($event, item, openParam) {
  2010. $event.preventDefault();
  2011. $event.stopPropagation();
  2012. item[openParam] = !item[openParam];
  2013. };
  2014. $scope.parseDate = function(dateStr) {
  2015. if(dateStr)
  2016. return Date.parse(dateStr, 'yyyy-MM-dd');
  2017. return new Date();
  2018. };
  2019. $scope.checkboxes = {
  2020. checked : false
  2021. };
  2022. // 点击勾选全部的复选框
  2023. $scope.checkAll = function(){
  2024. angular.forEach($scope.tableParams.data, function(item) {
  2025. item.$selected = $scope.checkboxes.checked;
  2026. });
  2027. };
  2028. // 点击其中一个明细的复选框
  2029. $scope.checkOne = function(order){
  2030. var result = true;
  2031. angular.forEach($scope.tableParams.data, function(item) {
  2032. if(item.$selected != true){
  2033. result = false;
  2034. return;
  2035. }
  2036. });
  2037. $scope.checkboxes.checked = result;
  2038. };
  2039. // 搜索框回车
  2040. $scope.onSearch = function(keyword) {
  2041. $scope.tableParams.page(1);
  2042. $scope.tableParams.reload();
  2043. $scope.tip = keyword;
  2044. };
  2045. // 选择查找日期
  2046. $scope.onDateCondition = function(){
  2047. $scope.tableParams.page(1);
  2048. $scope.tableParams.reload();
  2049. };
  2050. }]);
  2051. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2052. var loadData = function() {
  2053. PurcOrder.get({id: $stateParams.id}, function(data){
  2054. $scope.order = data;
  2055. var sum = 0;
  2056. angular.forEach($scope.order.orderItems, function(item){
  2057. sum += item.qty * item.price;
  2058. });
  2059. $scope.order.total = sum;
  2060. if($scope.order.display == 1) {//未查看的设为已查看
  2061. $scope.setDisplay('setRead', $scope.order.id);
  2062. }
  2063. $scope.loading = false;
  2064. });
  2065. };
  2066. loadData();
  2067. $scope.getReply = function(item) {
  2068. if(!item.replies) {
  2069. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2070. item.replies = replies;
  2071. });
  2072. }
  2073. };
  2074. $scope.openDatePicker = function($event, item, openParam) {
  2075. $event.preventDefault();
  2076. $event.stopPropagation();
  2077. item[openParam] = !item[openParam];
  2078. };
  2079. $scope.onReplyClick = function(item, inverse) {
  2080. if(item.reply) {
  2081. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2082. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2083. return;
  2084. }
  2085. var reply = angular.copy(item.reply);
  2086. if(reply.delivery) {
  2087. if(typeof reply.delivery == 'object')
  2088. reply.delivery = reply.delivery.getTime();
  2089. } else {
  2090. reply.delivery = item.delivery;
  2091. }
  2092. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2093. $scope.loading = true;
  2094. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2095. $scope.loading = false;
  2096. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2097. loadData();
  2098. }, function(response){
  2099. $scope.loading = false;
  2100. toaster.pop('error', '回复失败', response.data);
  2101. });
  2102. }
  2103. };
  2104. // // 采购单
  2105. // $scope.print = function(order) {
  2106. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  2107. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2108. // };
  2109. //设置为已查看
  2110. $scope.setDisplay = function(state, orderId) {
  2111. if(orderId) {//设置单个
  2112. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2113. // $scope.tableParams.reload();
  2114. }, function() {
  2115. toaster.pop('error', '错误', "设置失败");
  2116. });
  2117. } else {//设置已勾选的
  2118. var str = null;
  2119. angular.forEach($scope.tableParams.data, function(order) {
  2120. if(order.$selected == true) {
  2121. if(str != null && str != '') str += ',';
  2122. str += order.id;
  2123. }
  2124. });
  2125. if(str != null && str != '') {
  2126. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2127. $scope.tableParams.reload();
  2128. }, function() {
  2129. toaster.pop('error', '错误', "设置失败");
  2130. });
  2131. }
  2132. }
  2133. };
  2134. }]);
  2135. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  2136. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  2137. BaseService.scrollBackToTop();
  2138. $scope.active = 'todo';
  2139. $scope.dateZoneText = '不限';
  2140. $scope.deliveryZoneText = '不限';
  2141. $scope.condition = {dateZone: -1, deliveryZone: -1};
  2142. $scope.changeDateZone = function(zone) {
  2143. $scope.condition.dateZone = zone;
  2144. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2145. $scope.condition.$dateZoneOpen = false;
  2146. getDateCondition(zone, $scope.condition);
  2147. $scope.tableParams.reload();
  2148. };
  2149. $scope.changeDeliveryZone = function(zone) {
  2150. $scope.condition.deliveryZoneText = zone;
  2151. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2152. $scope.condition.$delievryZoneOpen = false;
  2153. getDelveryCondition(zone, $scope.condition);
  2154. $scope.tableParams.reload();
  2155. };
  2156. $scope.nowdate = new Date();
  2157. // 切换单据类型
  2158. $scope.setActive = function(state) {
  2159. if($scope.active != state) {
  2160. $scope.active = state;
  2161. if($scope.tableParams.page() == 1)
  2162. $scope.tableParams.reload();
  2163. else
  2164. $scope.tableParams.page(1);
  2165. }
  2166. };
  2167. // 切换数据来源(正常数据 or 历史数据)
  2168. var getService = function() {
  2169. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  2170. };
  2171. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2172. page : 1,
  2173. count : 5,
  2174. sorting: {
  2175. display: 'desc',
  2176. date: 'desc',
  2177. id: 'desc'
  2178. }
  2179. }, {
  2180. total : 0,
  2181. counts: [5, 10, 15, 25, 50],
  2182. getData : function($defer, params) { // 获取数据的方法
  2183. $scope.loading = true;
  2184. var pageParams = params.url();
  2185. pageParams.searchFilter = { // 筛选条件
  2186. keyword: $scope.keyword,
  2187. fromDate: getDateTime($scope.condition.dateFrom),
  2188. endDate: getDateTime($scope.condition.dateTo)
  2189. };
  2190. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2191. $scope.loading = false;
  2192. if(page) {
  2193. $defer.resolve(page.content);
  2194. params.total(page.totalElement);
  2195. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2196. }
  2197. }, function(response){
  2198. $scope.loading = false;
  2199. toaster.pop('error', '数据加载失败', response.data);
  2200. });
  2201. }
  2202. });
  2203. $scope.getOrderTotal = function(items) {
  2204. var sum = 0;
  2205. angular.forEach(items, function(item){
  2206. sum += item.qty * item.price;
  2207. });
  2208. return sum;
  2209. };
  2210. $scope.openDatePicker = function($event, item, openParam) {
  2211. $event.preventDefault();
  2212. $event.stopPropagation();
  2213. item[openParam] = !item[openParam];
  2214. };
  2215. $scope.parseDate = function(dateStr) {
  2216. if(dateStr)
  2217. return Date.parse(dateStr, 'yyyy-MM-dd');
  2218. return new Date();
  2219. };
  2220. $scope.onReplyClick = function(item, inverse) {
  2221. if(item.reply) {
  2222. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2223. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2224. return;
  2225. }
  2226. var reply = angular.copy(item.reply);
  2227. if(reply.delivery) {
  2228. if(typeof reply.delivery == 'object')
  2229. reply.delivery = reply.delivery.getTime();
  2230. } else {
  2231. reply.delivery = item.delivery;
  2232. }
  2233. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2234. $scope.loading = true;
  2235. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2236. $scope.loading = false;
  2237. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2238. $scope.tableParams.reload();
  2239. }, function(response){
  2240. $scope.loading = false;
  2241. toaster.pop('error', '回复失败', response.data);
  2242. });
  2243. }
  2244. };
  2245. //打印 采购单
  2246. $scope.print = function(order) {
  2247. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2248. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2249. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2250. };
  2251. $scope.getReply = function(item) {
  2252. if(!item.replies) {
  2253. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2254. item.replies = replies;
  2255. });
  2256. }
  2257. };
  2258. $scope.checkboxes = {
  2259. checked : false
  2260. };
  2261. // 点击勾选全部的复选框
  2262. $scope.checkAll = function(){
  2263. angular.forEach($scope.tableParams.data, function(item) {
  2264. item.$selected = $scope.checkboxes.checked;
  2265. });
  2266. };
  2267. // 点击其中一个明细的复选框
  2268. $scope.checkOne = function(order){
  2269. var result = true;
  2270. angular.forEach($scope.tableParams.data, function(item) {
  2271. if(item.$selected != true){
  2272. result = false;
  2273. return;
  2274. }
  2275. });
  2276. $scope.checkboxes.checked = result;
  2277. };
  2278. //批量回复采购订单
  2279. $scope.replyByBatch = function() {
  2280. $scope.loading = true;
  2281. var str = '';
  2282. angular.forEach($scope.tableParams.data, function(order) {
  2283. if(order.$selected == true) {
  2284. angular.forEach(order.orderItems, function(item){
  2285. str += item.id;
  2286. str += ',';
  2287. });
  2288. }
  2289. });
  2290. if(!(str == '')) {
  2291. str = str.substr(0, str.length-1);
  2292. PurcOrderItem.replyByBatch(str, function(){
  2293. $scope.loading = false;
  2294. $scope.tableParams.reload();
  2295. toaster.pop('success', '提示', '批量回复成功');
  2296. }, function(data){
  2297. $scope.loading = false;
  2298. toaster.pop('error', '批量回复失败', data);
  2299. });
  2300. } else {//没有勾选其中的明细
  2301. $scope.loading = false;
  2302. }
  2303. };
  2304. // 搜索框回车
  2305. $scope.onSearch = function() {
  2306. $scope.tableParams.page(1);
  2307. $scope.tableParams.reload();
  2308. };
  2309. // 选择查找日期
  2310. $scope.onDateCondition = function(){
  2311. $scope.tableParams.page(1);
  2312. $scope.tableParams.reload();
  2313. };
  2314. //设置为已查看
  2315. $scope.setDisplay = function(state, orderId) {
  2316. if(orderId) {//设置单个
  2317. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2318. $scope.tableParams.reload();
  2319. }, function() {
  2320. toaster.pop('error', '错误', "设置失败");
  2321. });
  2322. } else {//设置已勾选的
  2323. var str = null;
  2324. angular.forEach($scope.tableParams.data, function(order) {
  2325. if(order.$selected == true) {
  2326. if(str != null && str != '') str += ',';
  2327. str += order.id;
  2328. }
  2329. });
  2330. if(str != null && str != '') {
  2331. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2332. $scope.tableParams.reload();
  2333. }, function() {
  2334. toaster.pop('error', '错误', "设置失败");
  2335. });
  2336. }
  2337. }
  2338. };
  2339. }]);
  2340. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2341. var loadData = function() {
  2342. PurcOrder.get({id: $stateParams.id}, function(data){
  2343. $scope.order = data;
  2344. var sum = 0;
  2345. angular.forEach($scope.order.orderItems, function(item){
  2346. sum += item.qty * item.price;
  2347. });
  2348. $scope.order.total = sum;
  2349. if($scope.order.display == 1) {//未查看的设为已查看
  2350. $scope.setDisplay('setRead', $scope.order.id);
  2351. }
  2352. $scope.loading = false;
  2353. });
  2354. };
  2355. loadData();
  2356. $scope.getReply = function(item) {
  2357. if(!item.replies) {
  2358. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2359. item.replies = replies;
  2360. });
  2361. }
  2362. };
  2363. $scope.openDatePicker = function($event, item, openParam) {
  2364. $event.preventDefault();
  2365. $event.stopPropagation();
  2366. item[openParam] = !item[openParam];
  2367. };
  2368. $scope.onReplyClick = function(item, inverse) {
  2369. if(item.reply) {
  2370. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2371. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2372. return;
  2373. }
  2374. var reply = angular.copy(item.reply);
  2375. if(reply.delivery) {
  2376. if(typeof reply.delivery == 'object')
  2377. reply.delivery = reply.delivery.getTime();
  2378. } else {
  2379. reply.delivery = item.delivery;
  2380. }
  2381. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2382. $scope.loading = true;
  2383. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2384. $scope.loading = false;
  2385. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2386. loadData();
  2387. }, function(response){
  2388. $scope.loading = false;
  2389. toaster.pop('error', '回复失败', response.data);
  2390. });
  2391. }
  2392. };
  2393. // 采购单
  2394. $scope.print = function(order) {
  2395. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2396. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2397. };
  2398. //设置为已查看
  2399. $scope.setDisplay = function(state, orderId) {
  2400. if(orderId) {//设置单个
  2401. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2402. $scope.tableParams.reload();
  2403. }, function() {
  2404. toaster.pop('error', '错误', "设置失败");
  2405. });
  2406. } else {//设置已勾选的
  2407. var str = null;
  2408. angular.forEach($scope.tableParams.data, function(order) {
  2409. if(order.$selected == true) {
  2410. if(str != null && str != '') str += ',';
  2411. str += order.id;
  2412. }
  2413. });
  2414. if(str != null && str != '') {
  2415. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2416. $scope.tableParams.reload();
  2417. }, function() {
  2418. toaster.pop('error', '错误', "设置失败");
  2419. });
  2420. }
  2421. }
  2422. };
  2423. }]);
  2424. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  2425. BaseService.scrollBackToTop();
  2426. $scope.active = 'todo';
  2427. $scope.agreedText = '全部';
  2428. $scope.dateZoneText = '一个月内';
  2429. $scope.condition = {dateZone: 1};
  2430. $scope.changeAgreed = function(agreed) {
  2431. $scope.condition.agreed = agreed;
  2432. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2433. $scope.condition.$agreedOpen = false;
  2434. };
  2435. $scope.changeDateZone = function(zone) {
  2436. $scope.condition.dateZone = zone;
  2437. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2438. $scope.condition.$dateZoneOpen = false;
  2439. };
  2440. $scope.setActive = function(state) {
  2441. if($scope.active != state) {
  2442. $scope.active = state;
  2443. if($scope.tableParams.page() == 1)
  2444. $scope.tableParams.reload();
  2445. else
  2446. $scope.tableParams.page(1);
  2447. }
  2448. };
  2449. var getService = function() {
  2450. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2451. };
  2452. $scope.tableParams = new ngTableParams({
  2453. page : 1,
  2454. count : 5,
  2455. sorting: {
  2456. date: 'desc'
  2457. }
  2458. }, {
  2459. total : 0,
  2460. counts: [5, 10, 25, 50],
  2461. getData : function($defer, params) {
  2462. $scope.loading = true;
  2463. var pageParams = params.url();
  2464. pageParams.keyword = $scope.keyword;
  2465. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2466. $scope.loading = false;
  2467. if(page) {
  2468. params.total(page.totalElement);
  2469. $defer.resolve(page.content);
  2470. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2471. }
  2472. }, function(response){
  2473. $scope.loading = false;
  2474. toaster.pop('error', '数据加载失败', response.data);
  2475. });
  2476. }
  2477. });
  2478. $scope.openDatePicker = function($event, item, openParam) {
  2479. $event.preventDefault();
  2480. $event.stopPropagation();
  2481. item[openParam] = !item[openParam];
  2482. };
  2483. $scope.onReplyClick = function(change) {
  2484. if(change.$agreed) {
  2485. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2486. $scope.loading = true;
  2487. PurcChange.reply({changeId: change.id}, reply, function(){
  2488. $scope.loading = false;
  2489. toaster.pop('info', '提示', '回复成功');
  2490. $scope.tableParams.reload();
  2491. }, function(response){
  2492. $scope.loading = false;
  2493. toaster.pop('error', '回复失败', response.data);
  2494. });
  2495. }
  2496. };
  2497. // 搜索框回车
  2498. $scope.onSearch = function() {
  2499. $scope.tableParams.page(1);
  2500. $scope.tableParams.reload();
  2501. };
  2502. }]);
  2503. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2504. var loadData = function() {
  2505. PurcChange.get({id: $stateParams.id}, function(data){
  2506. $scope.change = data;
  2507. });
  2508. };
  2509. loadData();
  2510. $scope.openDatePicker = function($event, item, openParam) {
  2511. $event.preventDefault();
  2512. $event.stopPropagation();
  2513. item[openParam] = !item[openParam];
  2514. };
  2515. $scope.onReplyClick = function(change) {
  2516. if(change.$agreed) {
  2517. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2518. PurcChange.reply({changeId: change.id}, reply, function(){
  2519. toaster.pop('info', '提示', '回复成功');
  2520. loadData();
  2521. }, function(response){
  2522. toaster.pop('error', '回复失败', response.data);
  2523. });
  2524. }
  2525. };
  2526. }]);
  2527. //采购询价
  2528. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', '$upload', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis, $upload){
  2529. BaseService.scrollBackToTop();
  2530. $scope.active = 'todo';
  2531. $scope.agreedText = '全部';
  2532. $scope.dateZoneText = '一个月内';
  2533. $scope.condition = {dateZone: 1};
  2534. $scope.changeAgreed = function(agreed) {
  2535. $scope.condition.agreed = agreed;
  2536. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2537. $scope.condition.$agreedOpen = false;
  2538. };
  2539. $scope.changeDateZone = function(zone) {
  2540. $scope.condition.dateZone = zone;
  2541. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2542. $scope.condition.$dateZoneOpen = false;
  2543. };
  2544. $scope.setActive = function(state) {
  2545. if($scope.active != state) {
  2546. $scope.active = state;
  2547. if($scope.tableParams.page() == 1)
  2548. $scope.tableParams.reload();
  2549. else
  2550. $scope.tableParams.page(1);
  2551. }
  2552. };
  2553. // 得到消息
  2554. PurcInquiry.getMessage({}, function(data){
  2555. $scope.message = data;
  2556. }, function(response) {
  2557. });
  2558. var getService = function() {
  2559. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2560. };
  2561. $scope.tableParams = new ngTableParams({
  2562. page : 1,
  2563. count : 5,
  2564. sorting: {
  2565. 'inquiry.date': 'desc',
  2566. 'inquiry.enterprise.enName': 'asc',
  2567. 'inquiry.code': 'asc'
  2568. }
  2569. }, {
  2570. total : 0,
  2571. counts: [5, 10, 25, 50],
  2572. getData : function($defer, params) {
  2573. $scope.loading = true;
  2574. var pageParams = params.url();
  2575. var realActive = {};
  2576. pageParams.keyword = $scope.keyword;
  2577. if ($scope.active == 'overdue') {
  2578. $scope.active = 'end';
  2579. }
  2580. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2581. $scope.loading = false;
  2582. if(page) {
  2583. params.total(page.totalElement);
  2584. $defer.resolve(page.content);
  2585. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2586. }
  2587. }, function(response){
  2588. $scope.loading = false;
  2589. toaster.pop('error', '数据加载失败', response.data);
  2590. });
  2591. }
  2592. });
  2593. $scope.getMinDate = function(item) {
  2594. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2595. };
  2596. $scope.replyPrices = [];
  2597. $scope.replylapQtys = [];
  2598. $scope.replyPrices.push(true);
  2599. $scope.replylapQtys.push(true);
  2600. $scope.addStep = function(inquiryItem) {
  2601. $scope.replyPrices.push(true);
  2602. if(inquiryItem.replies.length >= 10) {
  2603. toaster.pop('warning', '提示', '最多支持10个分段!');
  2604. } else {
  2605. inquiryItem.replies.push({});
  2606. if(inquiryItem.replies.length != 1) {
  2607. $scope.replyPrices.push(true);
  2608. $scope.replylapQtys.push(true);
  2609. }
  2610. }
  2611. };
  2612. $scope.removeStep = function(inquiryItem, stepIndex) {
  2613. inquiryItem.replies.splice(stepIndex, 1);
  2614. $scope.replyPrices.splice(stepIndex, 1);
  2615. $scope.replylapQtys.splice(stepIndex, 1);
  2616. };
  2617. $scope.openDatePicker = function($event, item, openParam) {
  2618. $event.preventDefault();
  2619. $event.stopPropagation();
  2620. item[openParam] = !item[openParam];
  2621. };
  2622. $scope.getHistory = function(item) {
  2623. if(!item.history) {
  2624. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2625. item.history = data;
  2626. });
  2627. }
  2628. };
  2629. $scope.isValid = function(item, withSteps) {
  2630. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2631. if(!withSteps || !bool)
  2632. return bool;
  2633. angular.forEach(item.replies, function(r, i){
  2634. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2635. });
  2636. return bool;
  2637. };
  2638. $scope.onReplyClick = function(item, withSteps) {
  2639. if(item.vendFromDate instanceof Date) {
  2640. item.vendFromDate = item.vendFromDate.getTime();
  2641. }
  2642. if(item.vendToDate instanceof Date) {
  2643. item.vendToDate = item.vendToDate.getTime();
  2644. }
  2645. if(item.vendFromDate > item.vendToDate) {
  2646. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2647. return;
  2648. }
  2649. var replies = [];
  2650. angular.forEach(item.replies, function(r, i){
  2651. if((i > 0 ? r.lapQty : 1) || r.price)
  2652. replies.push(r);
  2653. });
  2654. item.replies = replies;
  2655. $scope.loading = true;
  2656. if(withSteps) {
  2657. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  2658. $upload.upload({
  2659. url: 'sale/inquiry/addAttach',
  2660. file: file,
  2661. method: 'POST',
  2662. data: {
  2663. itemId:item.id
  2664. }
  2665. }).success(function (attach) {
  2666. console.log(attach);
  2667. });
  2668. PurcInquiry.reply({itemId: item.id}, item, function(){
  2669. $scope.loading = false;
  2670. toaster.pop('info', '提示', '报价成功');
  2671. $scope.tableParams.reload();
  2672. }, function(response){
  2673. $scope.loading = false;
  2674. toaster.pop('error', '报价失败', response.data);
  2675. });
  2676. } else {
  2677. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2678. $scope.loading = false;
  2679. toaster.pop('info', '提示', '保存成功');
  2680. $scope.tableParams.reload();
  2681. }, function(response){
  2682. $scope.loading = false;
  2683. toaster.pop('error', '保存失败', response.data);
  2684. });
  2685. }
  2686. };
  2687. $scope.verifylapQty = function(value,type) {
  2688. var regex = /^\d+(.\d{1,5})?$/;
  2689. $scope.replylapQtys[type] = regex.test(value);
  2690. }
  2691. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2692. $scope.verify = function(value,type) {
  2693. var regex = /^\d+(.\d{1,5})?$/;//
  2694. switch(type) {
  2695. case 'minOrderQty':
  2696. $scope.minOrderQtyVerify = regex.test(value);
  2697. break;
  2698. case 'minPackQty':
  2699. $scope.minPackQtyVerify = regex.test(value);
  2700. break;
  2701. case 'leadtime':
  2702. $scope.leadtimeVerify = regex.test(value);
  2703. break;
  2704. default:
  2705. $scope.replyPrices[type] = regex.test(value);
  2706. break;
  2707. }
  2708. }
  2709. // 搜索框回车
  2710. $scope.onSearch = function() {
  2711. $scope.tableParams.page(1);
  2712. $scope.tableParams.reload();
  2713. };
  2714. // 取消
  2715. $scope.cancel = function() {
  2716. $scope.tableParams.reload();
  2717. }
  2718. }]);
  2719. // 询价单明细
  2720. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', '$upload', function($scope, $stateParams, PurcInquiry,$filter, toaster, $upload){
  2721. var loadData = function() {
  2722. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2723. $scope.newinquiryItems = data;
  2724. var inquiry = data[0].inquiry;
  2725. //inquiry.inquiryItems = data;
  2726. angular.forEach(inquiry.attachs, function(attach){
  2727. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2728. });
  2729. $scope.inquiry = inquiry;
  2730. });
  2731. };
  2732. loadData();
  2733. $scope.getMinDate = function(item) {
  2734. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2735. };
  2736. $scope.addStep = function(inquiryItem) {
  2737. if(inquiryItem.replies.length >= 10) {
  2738. toaster.pop('warning', '提示', '最多支持10个分段!');
  2739. } else
  2740. inquiryItem.replies.push({});
  2741. };
  2742. $scope.removeStep = function(inquiryItem, stepIndex) {
  2743. inquiryItem.replies.splice(stepIndex, 1);
  2744. };
  2745. $scope.openDatePicker = function($event, item, openParam) {
  2746. $event.preventDefault();
  2747. $event.stopPropagation();
  2748. item[openParam] = !item[openParam];
  2749. };
  2750. $scope.getHistory = function(item) {
  2751. if(!item.history) {
  2752. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2753. item.history = data;
  2754. });
  2755. }
  2756. };
  2757. $scope.isValid = function(item, withSteps) {
  2758. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2759. if(!withSteps || !bool)
  2760. return bool;
  2761. angular.forEach(item.replies, function(r, i){
  2762. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2763. });
  2764. return bool;
  2765. };
  2766. $scope.onReplyClick = function(item, withSteps) {
  2767. if(item.vendFromDate instanceof Date) {
  2768. item.vendFromDate = item.vendFromDate.getTime();
  2769. }
  2770. if(item.vendToDate instanceof Date) {
  2771. item.vendToDate = item.vendToDate.getTime();
  2772. }
  2773. if(item.vendFromDate > item.vendToDate) {
  2774. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2775. return;
  2776. }
  2777. var replies = [];
  2778. angular.forEach(item.replies, function(r, i){
  2779. if((i > 0 ? r.lapQty : 1) || r.price)
  2780. replies.push(r);
  2781. });
  2782. item.replies = replies;
  2783. if(withSteps) {
  2784. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  2785. $upload.upload({
  2786. url: 'sale/inquiry/addAttach',
  2787. file: file,
  2788. method: 'POST',
  2789. data: {
  2790. itemId:item.id
  2791. }
  2792. }).success(function (attach) {
  2793. console.log(attach);
  2794. });
  2795. PurcInquiry.reply({itemId: item.id}, item, function(){
  2796. toaster.pop('info', '提示', '报价成功');
  2797. loadData();
  2798. }, function(response){
  2799. toaster.pop('error', '报价失败', response.data);
  2800. });
  2801. } else {
  2802. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2803. $scope.loading = false;
  2804. toaster.pop('info', '提示', '保存成功');
  2805. loadData();
  2806. }, function(response){
  2807. $scope.loading = false;
  2808. toaster.pop('error', '保存失败', response.data);
  2809. });
  2810. }
  2811. };
  2812. // 取消
  2813. $scope.cancel = function() {
  2814. $scope.tableParams.reload();
  2815. }
  2816. }]);
  2817. // 平台新增的询价单
  2818. 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) {
  2819. $scope.status = 'InquiryNew';
  2820. $scope.active = 'all';
  2821. $rootScope.tenderVendor = null;// 清除掉已选择的
  2822. var getService = function() {
  2823. return GetProductInfo;
  2824. };
  2825. $scope.inquiry = {
  2826. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  2827. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  2828. priceType: '采购',
  2829. isOpen: 1,
  2830. invoice: 0,
  2831. ifTax: 1,
  2832. currency: 'RMB',
  2833. inquirytype: '询价'
  2834. };
  2835. $scope.changeCurrency = function(inquiry) {
  2836. if (inquiry.currency !== 'RMB') {
  2837. $scope.notRMB = true;
  2838. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  2839. inquiry.invoice = 0;
  2840. } else {
  2841. $scope.notRMB = false;
  2842. }
  2843. };
  2844. // 获取收货地址列表
  2845. var loadShipAddress = function() {
  2846. ShipAddress.shipAddList({}, function(data) {
  2847. $scope.ships = data;
  2848. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  2849. });
  2850. };
  2851. loadShipAddress();
  2852. // 获取地址信息
  2853. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  2854. }).then(function(response) {
  2855. $scope.provinces = response.data;
  2856. });
  2857. // 新增收货地址保存
  2858. $scope.saveShipAddress = function(ship) {
  2859. ship.address = ship.province + ship.city + ship.district;
  2860. ShipAddress.saveAddress( {}, ship, function(data) {
  2861. if(data.success) {
  2862. // 获取收货地址列表
  2863. loadShipAddress();
  2864. toaster.pop('success', '提示', data.success);
  2865. }
  2866. if(data.error) {
  2867. toaster.pop('error', '提示', data.error);
  2868. }
  2869. });
  2870. };
  2871. $scope.currentDay = function() {
  2872. return $filter('date')(new Date(), 'yyyy-MM-dd');
  2873. };
  2874. $scope.vendors = [];
  2875. // 查找供应商
  2876. $scope.dbfindVendor = function(){
  2877. var modalInstance = $modal.open({
  2878. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  2879. controller: 'DbfindVendorCtrl',
  2880. size: 'lg',
  2881. resolve: {
  2882. }
  2883. });
  2884. modalInstance.result.then(function(data){
  2885. var ifPush = true;
  2886. modalInstance.result.then(function(data){
  2887. angular.forEach(data, function(vendor) {
  2888. if (!$scope.vendors) {// 不存在就先创建
  2889. $scope.vendors = [{}];
  2890. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  2891. } else {
  2892. for (var i = 0;i<$scope.vendors.length; i++) {
  2893. ifPush = true;
  2894. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  2895. ifPush = false;
  2896. break; // 判定到已存在供应商,就终止循环。
  2897. }
  2898. }
  2899. if (ifPush) {
  2900. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  2901. }
  2902. }
  2903. });
  2904. $rootScope.tenderVendor = $scope.vendors;
  2905. }, function(){
  2906. });
  2907. }, function(){
  2908. });
  2909. };
  2910. // 删除一个供应商
  2911. $scope.removeVendor = function(index) {
  2912. $scope.vendors.splice(index, 1);
  2913. };
  2914. $scope.removeChecked = function() {
  2915. console.log($scope.vendors);
  2916. if ( $scope.vendors.length > 0) {
  2917. $scope.vendors = [];
  2918. $rootScope.tenderVendor = '';
  2919. }
  2920. }
  2921. // 物料信息
  2922. $scope.tableParams = new ngTableParams({
  2923. page : 1,
  2924. count : 5,
  2925. sorting: {
  2926. }
  2927. }, {
  2928. total : 0,
  2929. counts: [5, 10, 25, 50],
  2930. getData : function($defer, params) {
  2931. $scope.loading = true;
  2932. var pageParams = params.url();
  2933. pageParams.keyword = $scope.keyword;
  2934. $scope.tip = $scope.keyword;
  2935. pageParams.searchFilter = $scope.searchFilter;
  2936. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2937. $scope.loading = false;
  2938. if(page) {
  2939. params.total(page.totalElement);
  2940. $scope.total = page.totalElement;
  2941. $defer.resolve(page.content);
  2942. }
  2943. }, function(response) {
  2944. $scope.loading = false;
  2945. toaster.pop('error', '数据加载失败', response.data);
  2946. });
  2947. }
  2948. });
  2949. // 搜索框回车
  2950. $scope.onSearch = function(keyword) {
  2951. $scope.tableParams.page(1);
  2952. $scope.tableParams.reload();
  2953. };
  2954. $scope.inquiry.inquiryItems = [];
  2955. var prod = {
  2956. prodCode: null,
  2957. prodTitle: null,
  2958. inbrand: null,
  2959. toDate: null,
  2960. unit: 'PCS',
  2961. needquantity: null
  2962. };
  2963. $scope.inquiry.inquiryItems.push(prod);
  2964. // 联想词start
  2965. // 获取品牌联想词
  2966. $scope.getSimilarBrands = function(value) {
  2967. if (value) {
  2968. // 获取品牌联想词
  2969. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  2970. return data.map(function(item) {
  2971. return item;
  2972. });
  2973. });
  2974. }
  2975. };
  2976. // 获取产品型号联想词
  2977. $scope.getSimilarCodes = function(value) {
  2978. if (value) {
  2979. // 获取产品型号联想词
  2980. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  2981. return data.map(function (item) {
  2982. return item;
  2983. })
  2984. });
  2985. }
  2986. };
  2987. $scope.selectKind = function(prod) {
  2988. var submit = [];
  2989. $modal.open({
  2990. animation: true,
  2991. size: 'lg',
  2992. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  2993. controller: 'ProdKindChooseCtrl',
  2994. resolve: {
  2995. actives: function() {
  2996. return $scope.actives;
  2997. }
  2998. }
  2999. }).result.then(function(data){
  3000. $scope.actives = data.actives;
  3001. var size = data.actives.length;
  3002. submit.gradeOneKiName = '';
  3003. submit.gradeTwoKiName = '';
  3004. submit.gradeThreeKiName = '';
  3005. if (size > 0) {
  3006. submit.gradeOneKiName = $scope.actives[0].nameCn;
  3007. prod.prodTitle = submit.gradeOneKiName;
  3008. if (size > 1) {
  3009. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  3010. prod.prodTitle = submit.gradeTwoKiName;
  3011. if (size > 2) {
  3012. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  3013. prod.prodTitle = submit.gradeThreeKiName;
  3014. }
  3015. }
  3016. }
  3017. }, function(){
  3018. });
  3019. };
  3020. // 点击联想词获取品牌信息
  3021. $scope.onAssociateBrandClick = function(brand, prod) {
  3022. if (brand instanceof String) {
  3023. prod.inbrand = brand;
  3024. } else if (brand instanceof Object) {
  3025. prod.inbrand = brand.brandCn;
  3026. }
  3027. };
  3028. // 打开品牌选择的模态框
  3029. $scope.selectBrand = function(prod){ //打开模态
  3030. var modalInstance = $modal.open({
  3031. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  3032. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  3033. });
  3034. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  3035. });
  3036. modalInstance.result.then(function(brand){
  3037. prod.inbrand = brand.nameCn;
  3038. }, function(reason){
  3039. });
  3040. };
  3041. // 点击联想词获取器件信息 带入产品分类和品牌
  3042. $scope.onAssociateCmpClick = function(cmp, prod) {
  3043. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  3044. $scope.component = data;
  3045. prod.prodCode = data.code;
  3046. prod.prodTitle = data.kind.nameCn;
  3047. prod.inbrand = data.brand.nameCn;
  3048. }, function(res) {
  3049. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  3050. })
  3051. };
  3052. //联想词end
  3053. // 导入商品信息
  3054. $scope.uplodaByBatch = function() {
  3055. var modalInstance = $modal.open({
  3056. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  3057. controller: 'PurcInquiryUploadCtrl',
  3058. size: 'lg',
  3059. resolve: {
  3060. }
  3061. });
  3062. modalInstance.result.then(function(data) {
  3063. angular.forEach(data, function(prod) {
  3064. console.log(prod);
  3065. $scope.inquiry.inquiryItems.push(prod);
  3066. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3067. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  3068. $scope.inquiry.inquiryItems.splice(i, 1);
  3069. }
  3070. }
  3071. })
  3072. }, function(){
  3073. });
  3074. }
  3075. //增加商品
  3076. $scope.add = function() {
  3077. $scope.inquiry.inquiryItems.push(
  3078. { prodCode: null,
  3079. prodTitle: null,
  3080. unit: 'PCS',
  3081. ibrand: null,
  3082. toDate: null,
  3083. needquantity: null});
  3084. };
  3085. //删除商品
  3086. $scope.del = function(index) {
  3087. $scope.inquiry.inquiryItems.splice(index, 1);
  3088. };
  3089. $scope.check = function(product) {
  3090. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3091. if($scope.inquiry.inquiryItems[i].prodCode == null || $scope.inquiry.inquiryItems[i].prodCode == product.code) { // 如果没有填写就删除这行数据
  3092. $scope.inquiry.inquiryItems.splice(i, 1);
  3093. }
  3094. }
  3095. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  3096. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand});
  3097. }
  3098. $scope.getMinDate = function(item) {
  3099. return $filter('date')(new Date, 'yyyy-MM-dd');
  3100. };
  3101. $scope.openDatePicker = function($event, openParam, index) {
  3102. $event.preventDefault();
  3103. $event.stopPropagation();
  3104. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  3105. };
  3106. $scope.openEndDatePicker = function($event, item, openParam) {
  3107. $event.preventDefault();
  3108. $event.stopPropagation();
  3109. item[openParam] = !item[openParam];
  3110. };
  3111. // 保存
  3112. $scope.save = function() {
  3113. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3114. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3115. if( $scope.vendors.length > 0) {
  3116. $upload.upload({
  3117. url: 'purc/inquiry/save',
  3118. file: file,
  3119. method: 'POST',
  3120. data: {
  3121. inquiry: $scope.inquiry,
  3122. contacts: $scope.vendors
  3123. },
  3124. }).success(function(data) {
  3125. if(data.success) {
  3126. toaster.pop('success', '提示', data.success);
  3127. $timeout(function() {
  3128. $rootScope.active = 'todo';
  3129. window.location.hash = "#/purc/inquiry_unapply";
  3130. }, 500);
  3131. }
  3132. if(data.error) {
  3133. toaster.pop('error', '提示', data.error);
  3134. }
  3135. }).error(function(data) {
  3136. $scope.loadingShow = false;
  3137. toaster.pop('error', '操作失败', data.error);
  3138. });
  3139. } else {
  3140. toaster.pop('info', '提示', '请先选择供应商');
  3141. }
  3142. } else {
  3143. $upload.upload({
  3144. url: 'purc/inquiry/saveWithoutVendor',
  3145. file: file,
  3146. method: 'POST',
  3147. data: {
  3148. inquiry: $scope.inquiry,
  3149. },
  3150. }).success(function(data) {
  3151. if(data.success) {
  3152. toaster.pop('success', '提示', data.success);
  3153. $timeout(function() {
  3154. $rootScope.active = 'done';
  3155. window.location.hash = "#/purc/inquiry_unapply";
  3156. }, 500);
  3157. }
  3158. if(data.error) {
  3159. toaster.pop('error', '提示', data.error);
  3160. }
  3161. }).error(function(data) {
  3162. $scope.loadingShow = false;
  3163. toaster.pop('error', '操作失败', data.error);
  3164. });
  3165. }
  3166. }
  3167. // 保存并提交
  3168. $scope.submit = function() {
  3169. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3170. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3171. if($scope.vendors.length > 0) {
  3172. $upload.upload({
  3173. url: 'purc/inquiry/saveAndSubmit',
  3174. file: file,
  3175. method: 'POST',
  3176. data: {
  3177. inquiry: $scope.inquiry,
  3178. contacts: $scope.vendors
  3179. },
  3180. }).success(function(data) {
  3181. if(data.success) {
  3182. toaster.pop('success', '提示', data.success);
  3183. $timeout(function() {
  3184. window.location.hash = "#/purc/purchaseinquiry";
  3185. }, 500);
  3186. }
  3187. if(data.error) {
  3188. toaster.pop('error', '提示', data.error);
  3189. }
  3190. }).error(function(data) {
  3191. $scope.loadingShow = false;
  3192. toaster.pop('error', '操作失败', data.error);
  3193. });
  3194. } else {
  3195. toaster.pop('info', '提示', '请先选择供应商');
  3196. }
  3197. } else {
  3198. $upload.upload({
  3199. url: 'purc/inquiry/saveAndSubmitWithoutVendor',
  3200. file: file,
  3201. method: 'POST',
  3202. data: {
  3203. inquiry: $scope.inquiry,
  3204. },
  3205. }).success(function(data) {
  3206. if(data.success) {
  3207. toaster.pop('success', '提示', data.success);
  3208. $timeout(function() {
  3209. window.location.hash = "#/purc/purchaseinquiry";
  3210. }, 500);
  3211. }
  3212. if(data.error) {
  3213. toaster.pop('error', '提示', data.error);
  3214. }
  3215. }).error(function(data) {
  3216. $scope.loadingShow = false;
  3217. toaster.pop('error', '操作失败', data.error);
  3218. });
  3219. }
  3220. }
  3221. $scope.previewShow = false;
  3222. $scope.pdfShow = false;
  3223. $scope.noneFileShow = true;
  3224. $scope.$watch('myFiles', function(){
  3225. if($scope.myFiles) {
  3226. $scope.noneFileShow = false;
  3227. var file = $scope.myFiles[0];
  3228. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  3229. $scope.pdfShow = true;
  3230. $scope.previewShow = false;
  3231. $scope.imgPreviewName = file.name;
  3232. } else{
  3233. if (typeof(Worker) !== "undefined") {//支持HTML5
  3234. $scope.imgPreview = getObjectURL(file);
  3235. $scope.imgPreviewName = file.name;
  3236. } else{//不支持HTML5
  3237. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  3238. $scope.imgPreviewName = file.name;
  3239. }
  3240. $scope.previewShow = true;
  3241. $scope.pdfShow = false;
  3242. }
  3243. } else {
  3244. $scope.noneFileShow = true;
  3245. $scope.previewShow = false;
  3246. $scope.pdfShow = false;
  3247. }
  3248. });
  3249. //建立一个可存取到该file的url
  3250. var getObjectURL = function(file) {
  3251. var url = null ;
  3252. if (window.createObjectURL!=undefined) { // basic
  3253. url = window.createObjectURL(file) ;
  3254. } else if (window.URL!=undefined) { // mozilla(firefox)
  3255. url = window.URL.createObjectURL(file) ;
  3256. } else if (window.webkitURL!=undefined) { // webkit or chrome
  3257. url = window.webkitURL.createObjectURL(file) ;
  3258. }
  3259. return url ;
  3260. };
  3261. }]);
  3262. /**
  3263. * 代采订单批量导入
  3264. */
  3265. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  3266. // 通过excel批量上传物料
  3267. $scope.result = null;
  3268. $scope.upload = function() {
  3269. var file = $scope.myFiles[0];
  3270. $upload.upload({
  3271. url: 'purc/inquiry/release/excel',
  3272. file: file,
  3273. method: 'POST'
  3274. }).success(function(data) {
  3275. $scope.result = data;
  3276. $scope.success = $scope.result.success;
  3277. $scope.total = $scope.result.total;
  3278. $scope.alters = $scope.result.alters;
  3279. }).error(function(response) {
  3280. toaster.pop('error', response.data || response);
  3281. });
  3282. };
  3283. // 查看范例
  3284. $scope.showImg = function() {
  3285. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  3286. box.show();
  3287. box.find('img').attr('src', src);
  3288. box.find('a').click(function(){
  3289. box.hide();
  3290. });
  3291. box.dblclick(function(){
  3292. box.hide();
  3293. });
  3294. };
  3295. // 下载模板
  3296. $scope.download = function() {
  3297. window.location.href = 'purc/inquiry/upload/template';
  3298. };
  3299. $scope.enSure = function() {
  3300. $modalInstance.close($scope.result.items);
  3301. }
  3302. $scope.cancel = function() {
  3303. $modalInstance.dismiss();
  3304. }
  3305. }]);
  3306. // 平台询价单(已提交)
  3307. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry) {
  3308. $scope.status = 'InquirySubmit';
  3309. BaseService.scrollBackToTop();
  3310. $scope.active = 'todo';
  3311. $scope.agreedText = '全部';
  3312. $scope.dateZoneText = '一个月内';
  3313. $scope.condition = {dateZone: 1};
  3314. $scope.changeAgreed = function(agreed) {
  3315. $scope.condition.agreed = agreed;
  3316. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3317. $scope.condition.$agreedOpen = false;
  3318. };
  3319. $scope.changeDateZone = function(zone) {
  3320. $scope.condition.dateZone = zone;
  3321. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3322. $scope.condition.$dateZoneOpen = false;
  3323. };
  3324. $scope.setActive = function(state) {
  3325. if($scope.active != state ) {
  3326. $scope.active = state;
  3327. if ($scope.tableParams.page() == 1) {
  3328. $scope.tableParams.reload();
  3329. } else {
  3330. $scope.tableParams.page(1);
  3331. }
  3332. }
  3333. }
  3334. var getService = function() {
  3335. return PurchaseInquiry;
  3336. };
  3337. $scope.tableParams = new ngTableParams({
  3338. page : 1,
  3339. count : 5,
  3340. sorting: {
  3341. 'inquiry.date': 'desc',
  3342. 'inquiry.enterprise.enName': 'asc',
  3343. 'inquiry.code': 'asc'
  3344. }
  3345. }, {
  3346. total : 0,
  3347. counts: [5, 10, 25, 50],
  3348. getData : function($defer, params) {
  3349. $scope.loading = true;
  3350. var pageParams = params.url();
  3351. var realActive = {};
  3352. pageParams.keyword = $scope.keyword;
  3353. if ($scope.active == 'overdue') {
  3354. $scope.active = 'end';
  3355. }
  3356. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3357. $scope.loading = false;
  3358. if(page) {
  3359. params.total(page.totalElement);
  3360. $defer.resolve(page.content);
  3361. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3362. }
  3363. }, function(response){
  3364. $scope.loading = false;
  3365. toaster.pop('error', '数据加载失败', response.data);
  3366. });
  3367. }
  3368. });
  3369. $scope.openDatePicker = function($event, item, openParam) {
  3370. $event.preventDefault();
  3371. $event.stopPropagation();
  3372. item[openParam] = !item[openParam];
  3373. };
  3374. // 搜索框回车
  3375. $scope.onSearch = function() {
  3376. $scope.tableParams.page(1);
  3377. $scope.tableParams.reload();
  3378. };
  3379. // 采纳
  3380. $scope.accept = function(id) {
  3381. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3382. if(data.success) {
  3383. toaster.pop('success', '提示', data.success);
  3384. $scope.tableParams.reload();
  3385. }
  3386. if(data.error) {
  3387. toaster.pop('error', '提示', data.error);
  3388. }
  3389. }, function(response) {
  3390. toaster.pop('error', '提示', response.data);
  3391. })
  3392. };
  3393. // 拒绝
  3394. $scope.refuse = function(id) {
  3395. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3396. if(data.success) {
  3397. toaster.pop('success', '提示', data.success);
  3398. $scope.tableParams.reload();
  3399. }
  3400. if(data.error) {
  3401. toaster.pop('error', '提示', data.error);
  3402. }
  3403. }, function(response) {
  3404. toaster.pop('error', '提示', response.data);
  3405. })
  3406. }
  3407. }]);
  3408. // 平台询价单(未提交)
  3409. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  3410. BaseService.scrollBackToTop();
  3411. if($rootScope.active = 'done') {
  3412. $scope.active = 'done';
  3413. $rootScope.active = '';
  3414. }
  3415. if($rootScope.active = 'todo') {
  3416. $scope.active = 'todo';
  3417. $rootScope.active = '';
  3418. }
  3419. var getService = function() {
  3420. if($scope.active == 'todo') {
  3421. return PurchaseInquiry.getUnapply;
  3422. }
  3423. if($scope.active == 'done') {
  3424. return PurchaseInquiry.getSubmit;
  3425. }
  3426. }
  3427. $scope.setActive = function(state) {
  3428. if($scope.active != state ) {
  3429. $scope.active = state;
  3430. if ($scope.tableParams.page() == 1) {
  3431. $scope.tableParams.reload();
  3432. } else {
  3433. $scope.tableParams.page(1);
  3434. }
  3435. }
  3436. }
  3437. $scope.tableParams = new ngTableParams({
  3438. page : 1,
  3439. count : 5,
  3440. sorting: {
  3441. 'date': 'desc',
  3442. 'enterprise.enName': 'asc',
  3443. 'code': 'asc'
  3444. }
  3445. }, {
  3446. total : 0,
  3447. counts: [5, 10, 25, 50],
  3448. getData : function($defer, params) {
  3449. $scope.loading = true;
  3450. var pageParams = params.url();
  3451. var realActive = {};
  3452. if ($scope.active == 'overdue') {
  3453. $scope.active = 'end';
  3454. }
  3455. getService().call(null, BaseService.parseParams(pageParams), function(page){
  3456. $scope.loading = false;
  3457. if(page) {
  3458. params.total(page.totalElements);
  3459. $defer.resolve(page.content);
  3460. }
  3461. }, function(response){
  3462. $scope.loading = false;
  3463. toaster.pop('error', '数据加载失败', response.data);
  3464. });
  3465. }
  3466. });
  3467. // 删除明细
  3468. $scope.deleteById = function(id) {
  3469. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  3470. toaster.pop('success', '提示', '删除成功');
  3471. $scope.tableParams.reload();
  3472. }, function(response) {
  3473. toaster.pop('error', '提示', response.data);
  3474. });
  3475. }
  3476. // 删除主表
  3477. $scope.clearOrder = function(id) {
  3478. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  3479. toaster.pop('success', '提示', '删除成功');
  3480. $scope.tableParams.reload();
  3481. }, function(response) {
  3482. toaster.pop('error', '提示', response.data);
  3483. });
  3484. }
  3485. // 提交
  3486. $scope.submit = function(id) {
  3487. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  3488. toaster.pop('success', '提示', '单据提交成功');
  3489. $scope.active = 'done';
  3490. $scope.tableParams.reload();
  3491. }, function(response) {
  3492. toaster.pop('error', '提示', response.data);
  3493. })
  3494. }
  3495. // 发布公共询价
  3496. $scope.publish = function(id) {
  3497. PurchaseInquiry.publishInquiry({id: id}, {}, function(data) {
  3498. toaster.pop('success', '提示', data.success);
  3499. $scope.active = 'done';
  3500. $scope.tableParams.reload();
  3501. }, function(response) {
  3502. toaster.pop('error', '提示', response.data);
  3503. })
  3504. }
  3505. }]);
  3506. // 公共询价列表
  3507. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams) {
  3508. BaseService.scrollBackToTop();
  3509. /**
  3510. * 改变单据日期范围
  3511. */
  3512. var getTenderDateCondition = function(zone, condition) {
  3513. var date = new Date();
  3514. if(zone == -1) {
  3515. condition.dateFrom = null;
  3516. condition.dateTo = null;
  3517. } else if(zone == 7) { // 一星期内
  3518. date.setDate(date.getDate() - 7);
  3519. condition.dateFrom = date;
  3520. condition.dateTo = new Date();
  3521. } else if(zone == 1) { // 一个月内
  3522. date.setMonth(date.getMonth() - 1);
  3523. condition.dateFrom = date;
  3524. condition.dateTo = new Date();
  3525. } else if(zone == 3) { // 三个月内
  3526. date.setMonth(date.getMonth() - 3);
  3527. condition.dateFrom = date;
  3528. condition.dateTo = new Date();
  3529. } else if (zone == 6) { // 半年内
  3530. date.setMonth(date.getMonth() - 6);
  3531. condition.dateFrom = date;
  3532. condition.dateTo = new Date();
  3533. } else { // 一年内
  3534. date.setYear(date.getYear() - 1);
  3535. condition.dateFrom = date;
  3536. condition.dateTo = new Date();
  3537. }
  3538. };
  3539. $scope.dateZoneText = '不限';
  3540. $scope.deliveryZoneText = '不限';
  3541. $scope.condition = {dateZone: -1};
  3542. $scope.changeDateZone = function(zone) {
  3543. $scope.condition.dateZone = zone;
  3544. $scope.condition.$dateZoneOpen = false;
  3545. getTenderDateCondition(zone, $scope.condition);
  3546. $scope.tableParams.reload();
  3547. };
  3548. $scope.openDatePicker = function($event, item, openParam) {
  3549. $event.preventDefault();
  3550. $event.stopPropagation();
  3551. item[openParam] = !item[openParam];
  3552. };
  3553. $scope.parseDate = function(dateStr) {
  3554. if(dateStr)
  3555. return Date.parse(dateStr, 'yyyy-MM-dd');
  3556. return new Date();
  3557. };
  3558. // 选择查找日期
  3559. $scope.onDateCondition = function(){
  3560. $scope.tableParams.page(1);
  3561. $scope.tableParams.reload();
  3562. };
  3563. // $scope.setActive = function(state) {
  3564. // if($scope.active != state) {
  3565. // $scope.active = state;
  3566. // if($scope.tableParams.page() == 1)
  3567. // $scope.tableParams.reload();
  3568. // else
  3569. // $scope.tableParams.page(1);
  3570. // }
  3571. // };
  3572. $scope.nowdate = new Date().getTime();
  3573. var getOpenState = function(active) {
  3574. var fn = 'getOpenAll';
  3575. switch(active) {
  3576. case 'all':
  3577. fn = 'getOpenAll';break;
  3578. case 'todo':
  3579. fn = 'getOpenTodo';break;
  3580. case 'end':
  3581. fn = 'getOpenEnd';break;
  3582. }
  3583. return fn;
  3584. };
  3585. $scope.tableParams = new ngTableParams({
  3586. page : 1,
  3587. count : 10,
  3588. sorting: {
  3589. // 'tender.endDate': 'desc',
  3590. // 'tender.enterprise.enName': 'asc',
  3591. // 'tender.code': 'asc'
  3592. }
  3593. }, {
  3594. total : 0,
  3595. counts: [10, 25, 50, 100],
  3596. getData : function($defer, params) {
  3597. $scope.loading = true;
  3598. var pageParams = params.url();
  3599. // var realActive = {};
  3600. pageParams.searchFilter = { // 筛选条件
  3601. keyword: $scope.keyword,
  3602. fromDate: getDateTime($scope.condition.dateFrom),
  3603. endDate: getDateTime($scope.condition.dateTo)
  3604. };
  3605. // AccountEnterprise.get({}, function(data){
  3606. // $scope.loading = false;
  3607. // $scope.currentEn = data;
  3608. // });
  3609. PurchaseInquiry.publicInquiryItem.call(null, BaseService.parseParams(pageParams), function(page){
  3610. $scope.loading = false;
  3611. if(page) {
  3612. params.total(page.totalElement);
  3613. $defer.resolve(page.content);
  3614. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  3615. }
  3616. }, function(response){
  3617. $scope.loading = false;
  3618. toaster.pop('error', '数据加载失败', response.data);
  3619. });
  3620. }
  3621. });
  3622. $scope.toDetail = function(id) {
  3623. window.location.hash = '#/baseInfo/inquiryList/' + id;
  3624. };
  3625. // 搜索框回车
  3626. $scope.onSearch = function() {
  3627. $scope.tableParams.page(1);
  3628. $scope.tableParams.reload();
  3629. };
  3630. }]);
  3631. /**
  3632. * 公共询价详情
  3633. */
  3634. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise) {
  3635. BaseService.scrollBackToTop();
  3636. $scope.currentHasBid = false;
  3637. var loadData = function() {
  3638. PurchaseInquiry.inquiryItemDetail({id: $stateParams.id}, function(data) {
  3639. $scope.inquiryItem = data.inquiryItem;
  3640. if(data.id) {
  3641. $scope.id = data.id;
  3642. console.log($scope.id);
  3643. $scope.currentHasBid = true;
  3644. }
  3645. }, function(response) {
  3646. toaster.pop('error', '提示', response.data);
  3647. });
  3648. }
  3649. loadData();
  3650. // 当前时间
  3651. $scope.nowdate = new Date().getTime();
  3652. // 当前企业
  3653. AccountEnterprise.get({}, function(data){
  3654. $scope.loading = false;
  3655. $scope.enterprise = data;
  3656. });
  3657. // 转客户询价
  3658. $scope.transtoInquiry = function(id) {
  3659. PurchaseInquiry.transtoInquiry({id: id}, {}, function(data) {
  3660. if(data.success) {
  3661. toaster.pop('success', '提示', data.success);
  3662. window.location.hash = "sale/inquiry/" + data.id;
  3663. }
  3664. if(data.error) {
  3665. toaster.pop('error', '提示', data.error);
  3666. }
  3667. if(data.info) {
  3668. toaster.pop('info', '提示', data.info);
  3669. }
  3670. }, function(response) {
  3671. toaster.pop('error', '提示', response.data);
  3672. });
  3673. }
  3674. }]);
  3675. // 询价单明细
  3676. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  3677. var loadData = function() {
  3678. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  3679. $scope.newinquiryItems = data;
  3680. var inquiry = data[0].inquiry;
  3681. //inquiry.inquiryItems = data;
  3682. angular.forEach(inquiry.attachs, function(attach){
  3683. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3684. });
  3685. $scope.inquiry = inquiry;
  3686. });
  3687. };
  3688. loadData();
  3689. $scope.getMinDate = function(item) {
  3690. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3691. };
  3692. $scope.addStep = function(inquiryItem) {
  3693. if(inquiryItem.replies.length >= 10) {
  3694. toaster.pop('warning', '提示', '最多支持10个分段!');
  3695. } else
  3696. inquiryItem.replies.push({});
  3697. };
  3698. $scope.removeStep = function(inquiryItem, stepIndex) {
  3699. inquiryItem.replies.splice(stepIndex, 1);
  3700. };
  3701. $scope.openDatePicker = function($event, item, openParam) {
  3702. $event.preventDefault();
  3703. $event.stopPropagation();
  3704. item[openParam] = !item[openParam];
  3705. };
  3706. $scope.getHistory = function(item) {
  3707. if(!item.history) {
  3708. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3709. item.history = data;
  3710. });
  3711. }
  3712. };
  3713. $scope.isValid = function(item, withSteps) {
  3714. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3715. if(!withSteps || !bool)
  3716. return bool;
  3717. angular.forEach(item.replies, function(r, i){
  3718. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3719. });
  3720. return bool;
  3721. };
  3722. $scope.onReplyClick = function(item, withSteps) {
  3723. if(item.vendFromDate instanceof Date) {
  3724. item.vendFromDate = item.vendFromDate.getTime();
  3725. }
  3726. if(item.vendToDate instanceof Date) {
  3727. item.vendToDate = item.vendToDate.getTime();
  3728. }
  3729. if(item.vendFromDate > item.vendToDate) {
  3730. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3731. return;
  3732. }
  3733. var replies = [];
  3734. angular.forEach(item.replies, function(r, i){
  3735. if((i > 0 ? r.lapQty : 1) || r.price)
  3736. replies.push(r);
  3737. });
  3738. item.replies = replies;
  3739. if(withSteps) {
  3740. PurcInquiry.reply({itemId: item.id}, item, function(){
  3741. toaster.pop('info', '提示', '报价成功');
  3742. loadData();
  3743. }, function(response){
  3744. toaster.pop('error', '报价失败', response.data);
  3745. });
  3746. }
  3747. };
  3748. }]);
  3749. // 询价单明细(发出)
  3750. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', function($scope, $stateParams, PurchaseInquiry,$filter, toaster){
  3751. var loadData = function() {
  3752. PurchaseInquiry.detail({id: $stateParams.id}, function(data){
  3753. $scope.inquiry = data;
  3754. });
  3755. };
  3756. loadData();
  3757. $scope.getMinDate = function(item) {
  3758. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3759. };
  3760. $scope.addStep = function(inquiryItem) {
  3761. if(inquiryItem.replies.length >= 10) {
  3762. toaster.pop('warning', '提示', '最多支持10个分段!');
  3763. } else
  3764. inquiryItem.replies.push({});
  3765. };
  3766. $scope.removeStep = function(inquiryItem, stepIndex) {
  3767. inquiryItem.replies.splice(stepIndex, 1);
  3768. };
  3769. $scope.openDatePicker = function($event, item, openParam) {
  3770. $event.preventDefault();
  3771. $event.stopPropagation();
  3772. item[openParam] = !item[openParam];
  3773. };
  3774. $scope.getHistory = function(item) {
  3775. if(!item.history) {
  3776. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3777. item.history = data;
  3778. });
  3779. }
  3780. };
  3781. $scope.isValid = function(item, withSteps) {
  3782. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3783. if(!withSteps || !bool)
  3784. return bool;
  3785. angular.forEach(item.replies, function(r, i){
  3786. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3787. });
  3788. return bool;
  3789. };
  3790. $scope.onReplyClick = function(item, withSteps) {
  3791. if(item.vendFromDate instanceof Date) {
  3792. item.vendFromDate = item.vendFromDate.getTime();
  3793. }
  3794. if(item.vendToDate instanceof Date) {
  3795. item.vendToDate = item.vendToDate.getTime();
  3796. }
  3797. if(item.vendFromDate > item.vendToDate) {
  3798. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3799. return;
  3800. }
  3801. var replies = [];
  3802. angular.forEach(item.replies, function(r, i){
  3803. if((i > 0 ? r.lapQty : 1) || r.price)
  3804. replies.push(r);
  3805. });
  3806. item.replies = replies;
  3807. if(withSteps) {
  3808. PurcInquiry.reply({itemId: item.id}, item, function(){
  3809. toaster.pop('info', '提示', '报价成功');
  3810. loadData();
  3811. }, function(response){
  3812. toaster.pop('error', '报价失败', response.data);
  3813. });
  3814. }
  3815. };
  3816. // 采纳
  3817. $scope.accept = function(id) {
  3818. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3819. if(data.success) {
  3820. toaster.pop('success', '提示', data.success);
  3821. loadData();
  3822. }
  3823. if(data.error) {
  3824. toaster.pop('error', '提示', data.error);
  3825. }
  3826. }, function(response) {
  3827. toaster.pop('error', '提示', response.data);
  3828. })
  3829. };
  3830. // 拒绝
  3831. $scope.refuse = function(id) {
  3832. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3833. if(data.success) {
  3834. toaster.pop('success', '提示', data.success);
  3835. loadData();
  3836. }
  3837. if(data.error) {
  3838. toaster.pop('error', '提示', data.error);
  3839. }
  3840. }, function(response) {
  3841. toaster.pop('error', '提示', response.data);
  3842. })
  3843. }
  3844. }]);
  3845. // 模具询价管理
  3846. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  3847. BaseService.scrollBackToTop();
  3848. $scope.active = 'todo';
  3849. $scope.agreedText = '全部';
  3850. $scope.dateZoneText = '不限';
  3851. $scope.condition = {dateZone: -1};
  3852. var inquiryMould_copy = {};
  3853. $scope.changeAgreed = function(agreed) {
  3854. $scope.condition.agreed = agreed;
  3855. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3856. $scope.condition.$agreedOpen = false;
  3857. };
  3858. $scope.changeDateZone = function(zone) {
  3859. $scope.condition.dateZone = zone;
  3860. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3861. $scope.condition.$dateZoneOpen = false;
  3862. };
  3863. $scope.setActive = function(state) {
  3864. if($scope.active != state ) {
  3865. $scope.active = state;
  3866. if ($scope.tableParams.page() == 1) {
  3867. $scope.tableParams.reload();
  3868. } else {
  3869. $scope.tableParams.page(1);
  3870. }
  3871. }
  3872. };
  3873. var getService = function() {
  3874. return PurcInquiryMould;
  3875. };
  3876. $scope.tableParams = new ngTableParams({
  3877. page: 1,
  3878. count: 5
  3879. },{
  3880. total: 0,
  3881. counts: [5, 10, 25, 50],
  3882. getData: function($defer, params) {
  3883. $scope.loading = true;
  3884. var pageParams = params.url();
  3885. var realActive = {};
  3886. pageParams.keyword = $scope.keyword;
  3887. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3888. $scope.loading = false;
  3889. // 用来验证价格修改
  3890. var mould = page.content;
  3891. inquiryMould_copy = angular.copy(mould);
  3892. if(page) {
  3893. params.total(page.totalElement);
  3894. $defer.resolve(page.content);
  3895. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3896. }
  3897. }, function(response){
  3898. $scope.loading = false;
  3899. toaster.pop('error', '数据加载失败', response.data);
  3900. });
  3901. }
  3902. })
  3903. $scope.getMinDate = function(item) {
  3904. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  3905. };
  3906. $scope.replyPrices = [];
  3907. $scope.replyPrices.push(true);
  3908. // 取消
  3909. $scope.reload = function() {
  3910. $scope.tableParams.reload();
  3911. $scope.canSave = false;
  3912. }
  3913. // 能否保存设置
  3914. $scope.canSave = false;
  3915. // items价格验证
  3916. $scope.verifyItems = function(price, reply) {
  3917. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  3918. if(regex.test(price) && price != 0) {
  3919. if (price != reply) {
  3920. $scope.canSave = true;
  3921. } else {
  3922. $scope.canSave = false;
  3923. }
  3924. } else {
  3925. $scope.canSave = false;
  3926. }
  3927. }
  3928. // prod下prods价格验证
  3929. $scope.verifyProds = function(price, reply) {
  3930. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3931. if(regex.test(price) && price != 0) {
  3932. if (price != reply) {
  3933. $scope.canSave = true;
  3934. } else {
  3935. $scope.canSave = false;
  3936. }
  3937. } else {
  3938. $scope.canSave = false;
  3939. }
  3940. }
  3941. //有价格为0或者不符合正则式,则不能报价
  3942. $scope.notZero = function (mould) {
  3943. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3944. angular.forEach(mould.inquiryMouldItems, function(item){
  3945. if (item.price == 0 || !regex.test(item.price)) {
  3946. $scope.canSave = false;
  3947. }
  3948. angular.forEach(item.inquiryMouldDetails, function(detail){
  3949. if (detail.price == 0 || !regex.test(detail.price)) {
  3950. $scope.canSave = false;
  3951. }
  3952. })
  3953. });
  3954. }
  3955. $scope.blurPrice = function (price) {
  3956. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3957. if (!regex.test(price)) {
  3958. toaster.pop('warning','格式错误','请输入有效价格');
  3959. }
  3960. }
  3961. // 获取历史报价
  3962. $scope.getHistory = function(mould) {
  3963. if(!mould.history) {
  3964. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3965. mould.history = data;
  3966. });
  3967. }
  3968. };
  3969. $scope.uploadAttach = function(mould) {
  3970. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3971. var file = mould.attachs[0];
  3972. $scope.mould = mould;
  3973. $upload.upload({
  3974. url: 'sale/mould/' + mould.id + '/send',
  3975. method: 'POST',
  3976. file: file,
  3977. data: {
  3978. json: $scope.mould
  3979. }
  3980. }).success(function(res){
  3981. }).error(function(res){
  3982. });
  3983. }
  3984. // 保存并确认报价
  3985. $scope.onReplyClick = function(mould, withSteps) {
  3986. $scope.loading = true;
  3987. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3988. // var file = mould.attachs[0];
  3989. // $scope.mould = mould;
  3990. // $upload.upload({
  3991. // url: 'sale/mould/' + mould.id + '/send',
  3992. // method: 'POST',
  3993. // file: file,
  3994. // data: {
  3995. // json: $scope.mould
  3996. // }
  3997. // }).success(function(res){
  3998. // console.log("success");
  3999. // console.log(res);
  4000. // }).error(function(res){
  4001. // console.log("failure");
  4002. // });
  4003. if(withSteps) {
  4004. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4005. $scope.loading = false;
  4006. toaster.pop('info', '提示', '报价成功');
  4007. $scope.tableParams.reload();
  4008. $scope.canSave = false;
  4009. }, function(response){
  4010. $scope.loading = false;
  4011. toaster.pop('error', '报价失败', response.data);
  4012. });
  4013. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4014. }, function(response){
  4015. });
  4016. } else {
  4017. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4018. $scope.loading = false;
  4019. toaster.pop('info', '提示', '保存成功');
  4020. $scope.tableParams.reload();
  4021. }, function(response){
  4022. $scope.loading = false;
  4023. toaster.pop('error', '保存失败', response.data);
  4024. });
  4025. }
  4026. };
  4027. // 搜索框回车
  4028. $scope.onSearch = function() {
  4029. $scope.tableParams.page(1);
  4030. $scope.tableParams.reload();
  4031. };
  4032. $scope.openDatePicker = function($event, item, openParam) {
  4033. $event.preventDefault();
  4034. $event.stopPropagation();
  4035. item[openParam] = !item[openParam];
  4036. };
  4037. $scope.parseDate = function(dateStr) {
  4038. if(dateStr)
  4039. return Date.parse(dateStr, 'yyyy-MM-dd');
  4040. return new Date();
  4041. };
  4042. }]);
  4043. // 模具询价单明细
  4044. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  4045. var inquiryMould_copy = {};
  4046. var loadData = function() {
  4047. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  4048. // 用来验证价格修改
  4049. inquiryMould_copy = angular.copy(data);
  4050. $scope.inquiryMould_copy = inquiryMould_copy;
  4051. $scope.newinquirymould = data;
  4052. var mould = data;
  4053. angular.forEach(mould.attachs, function(attach){
  4054. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  4055. });
  4056. $scope.inquiryMould = mould;
  4057. });
  4058. };
  4059. loadData();
  4060. $scope.getMinDate = function(item) {
  4061. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4062. };
  4063. // 取消
  4064. $scope.reload = function() {
  4065. loadData();
  4066. $scope.canSave = false;
  4067. }
  4068. //有价格为0,则不能报价
  4069. $scope.notZero = function (mould) {
  4070. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4071. angular.forEach(mould.inquiryMouldItems, function(item){
  4072. if (item.price == 0 || !regex.test(item.price)) {
  4073. $scope.canSave = false;
  4074. }
  4075. angular.forEach(item.inquiryMouldDetails, function(detail){
  4076. if (detail.price == 0 || !regex.test(detail.price)) {
  4077. $scope.canSave = false;
  4078. }
  4079. })
  4080. });
  4081. }
  4082. $scope.blurPrice = function (price) {
  4083. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4084. if (!regex.test(price)) {
  4085. toaster.pop('warning','格式错误','请输入有效价格');
  4086. }
  4087. }
  4088. // 获取历史报价
  4089. $scope.getHistory = function(mould) {
  4090. if(!mould.history) {
  4091. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  4092. mould.history = data;
  4093. });
  4094. }
  4095. };
  4096. $scope.canSave = false;
  4097. // items价格验证
  4098. $scope.verifyItems = function(price, index) {
  4099. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4100. if(regex.test(price) && price != 0) {
  4101. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  4102. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  4103. $scope.canSave = true;
  4104. } else {
  4105. $scope.canSave = false;
  4106. }
  4107. } else {
  4108. $scope.canSave = false;
  4109. }
  4110. }
  4111. // prod下prods价格验证
  4112. $scope.verifyProds = function(price, index, parentIndex) {
  4113. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4114. if(regex.test(price) && price != 0) {
  4115. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  4116. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  4117. $scope.canSave = true;
  4118. } else {
  4119. $scope.canSave = false;
  4120. }
  4121. } else {
  4122. $scope.canSave = false;
  4123. }
  4124. }
  4125. // // 上传附件
  4126. // $scope.uploadAttach = function(mould) {
  4127. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4128. // var file = mould.attachs[0];
  4129. // $scope.mould = mould;
  4130. // $upload.upload({
  4131. // url: 'sale/mould/' + mould.id + '/send',
  4132. // method: 'POST',
  4133. // file: file,
  4134. // data: {
  4135. // json: $scope.mould
  4136. // }
  4137. // }).success(function(res){
  4138. // console.log("success");
  4139. // console.log(res);
  4140. // }).error(function(res){
  4141. // console.log("failure");
  4142. // console.log(res);
  4143. // });
  4144. // }
  4145. $scope.onReplyClick = function(mould, withSteps) {
  4146. $scope.loading = true;
  4147. // var file = mould.attachs[0];
  4148. // $scope.mould = mould;
  4149. // $upload.upload({
  4150. // url: 'sale/mould/' + mould.id + '/send',
  4151. // method: 'POST',
  4152. // file: file,
  4153. // data: {
  4154. // json: $scope.mould
  4155. // }
  4156. // }).success(function(res){
  4157. //
  4158. // }).error(function(res){
  4159. // console.log(res);
  4160. // });
  4161. if(withSteps) {
  4162. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4163. $scope.loading = false;
  4164. toaster.pop('info', '提示', '报价成功');
  4165. loadData();
  4166. $scope.canSave = false;
  4167. }, function(response){
  4168. $scope.loading = false;
  4169. toaster.pop('error', '报价失败', response.data);
  4170. });
  4171. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4172. }, function(response){
  4173. });
  4174. } else {
  4175. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4176. $scope.loading = false;
  4177. toaster.pop('info', '提示', '保存成功');
  4178. loadData();
  4179. }, function(response){
  4180. $scope.loading = false;
  4181. toaster.pop('error', '保存失败', response.data);
  4182. });
  4183. }
  4184. };
  4185. }]);
  4186. // 主动报价 - 列表
  4187. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope){
  4188. BaseService.scrollBackToTop();
  4189. $rootScope.enteryStatus = false;
  4190. $scope.active = 'todo';
  4191. $scope.agreedText = '全部';
  4192. $scope.dateZoneText = '一个月内';
  4193. $scope.condition = {dateZone: 1};
  4194. $scope.changeDateZone = function(zone) {
  4195. $scope.condition.dateZone = zone;
  4196. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4197. $scope.condition.$dateZoneOpen = false;
  4198. };
  4199. $scope.setActive = function(state) {
  4200. if($scope.active != state) {
  4201. $scope.active = state;
  4202. if($scope.tableParams.page() == 1)
  4203. $scope.tableParams.reload();
  4204. else
  4205. $scope.tableParams.page(1);
  4206. }
  4207. };
  4208. var getService = function() {
  4209. return Quotation;
  4210. };
  4211. $scope.tableParams = new ngTableParams({
  4212. page : 1,
  4213. count : 5,
  4214. sorting: {
  4215. 'quotation.date': 'desc'
  4216. }
  4217. }, {
  4218. total : 0,
  4219. counts: [5, 10, 25, 50],
  4220. getData : function($defer, params) {
  4221. $scope.loading = true;
  4222. var pageParams = params.url();
  4223. pageParams.keyword = $scope.keyword;
  4224. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4225. $scope.loading = false;
  4226. if(page) {
  4227. params.total(page.totalElement);
  4228. $defer.resolve(page.content);
  4229. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4230. }
  4231. }, function(response){
  4232. $scope.loading = false;
  4233. toaster.pop('error', '数据加载失败', response.data);
  4234. });
  4235. }
  4236. });
  4237. $scope.getHistory = function(item) {
  4238. if(!item.history) {
  4239. PurcInquiry.getHistory({itemId: item.id}, function(data){
  4240. item.history = data;
  4241. });
  4242. }
  4243. };
  4244. $scope.isValid = function(item, withSteps) {
  4245. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4246. if(!withSteps || !bool)
  4247. return bool;
  4248. angular.forEach(item.replies, function(r, i){
  4249. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4250. });
  4251. return bool;
  4252. };
  4253. // 搜索框回车
  4254. $scope.onSearch = function() {
  4255. $scope.tableParams.page(1);
  4256. $scope.tableParams.reload();
  4257. };
  4258. }]);
  4259. // Controller 主动报价 - 新增
  4260. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope){
  4261. BaseService.scrollBackToTop();
  4262. var staticItem = null;
  4263. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  4264. $scope.loading = true;
  4265. $rootScope.enteryStatus = true;
  4266. Quotation.getItem({id: $stateParams.id}, function(data){
  4267. // data.$editing = false;
  4268. $scope.item = data;
  4269. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  4270. staticItem = angular.copy(data);
  4271. $scope.loading = false;
  4272. }, function(response){
  4273. $scope.loading = false;
  4274. toaster.pop('error', '数据加载失败', response.data);
  4275. });
  4276. } else {// 新增模式
  4277. $rootScope.enteryStatus = false;
  4278. $scope.item = {
  4279. quotation: {
  4280. currency: 'RMB',
  4281. taxrate: 17,
  4282. date: new Date()
  4283. },
  4284. product: {},
  4285. prices: [{lapQty: 0}],
  4286. minOrderQty: 1,
  4287. minPackQty: 1,
  4288. $endDateOpen: false,
  4289. $editing: true
  4290. };
  4291. }
  4292. $scope.getMinDate = function(item) {
  4293. return $filter('date')(new Date, 'yyyy-MM-dd');
  4294. };
  4295. $scope.openDatePicker = function($event, openParam) {
  4296. $event.preventDefault();
  4297. $event.stopPropagation();
  4298. $scope.item.$endDateOpen = !openParam;
  4299. };
  4300. // 增加一个分段
  4301. $scope.addPrice = function(){
  4302. if($scope.item.prices.length >= 10) {
  4303. toaster.pop('warning', '提示', '最多支持10个分段!');
  4304. } else
  4305. $scope.item.prices.push({});
  4306. };
  4307. // 删除一个分段
  4308. $scope.removePrice = function(index) {
  4309. $scope.item.prices.splice(index, 1);
  4310. };
  4311. // 查找客户
  4312. $scope.dbfindCust = function(){
  4313. if($scope.item.$editing) {
  4314. var modalInstance = $modal.open({
  4315. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  4316. controller: 'DbfindCustCtrl',
  4317. size: 'lg',
  4318. resolve: {
  4319. }
  4320. });
  4321. modalInstance.result.then(function(data){
  4322. $scope.item.quotation.cust = data.myEnterprise;
  4323. $scope.item.quotation.custUser = data.myUser;
  4324. $scope.item.product = null;
  4325. }, function(){
  4326. });
  4327. }
  4328. };
  4329. // 赋值客户信息
  4330. if($rootScope.custuu) {
  4331. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function(data) {
  4332. $scope.item.quotation.cust = data.myEnterprise;
  4333. $scope.item.quotation.custUser = data.myUser;
  4334. })
  4335. }
  4336. // 赋值物料信息
  4337. if($rootScope.prodId) {
  4338. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  4339. $scope.item.product.code = data.code;
  4340. $scope.item.product.title = data.title;
  4341. $scope.item.product.spec = data.spec;
  4342. $scope.item.product.unit = data.unit;
  4343. $scope.item.product.id = data.id;
  4344. }, function(response) {
  4345. });
  4346. }
  4347. // 查找客户物料
  4348. $scope.dbfindCustProd = function(){
  4349. if($scope.item.$editing) {
  4350. if($scope.item.quotation.cust.uu) {
  4351. var modalInstance = $modal.open({
  4352. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  4353. controller: 'DbfindCustProdCtrl',
  4354. size: 'lg',
  4355. resolve: {
  4356. custUU: function(){return $scope.item.quotation.cust.uu}
  4357. }
  4358. });
  4359. modalInstance.result.then(function(data){
  4360. $scope.item.product = data;
  4361. }, function(){
  4362. });
  4363. } else {
  4364. toaster.pop('error', '错误', '请先选择客户');
  4365. }
  4366. }
  4367. };
  4368. // 保存
  4369. $scope.save = function(){
  4370. $scope.loading = true;
  4371. if(!$scope.item.quotation.code) //新增,设单号
  4372. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  4373. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  4374. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  4375. $scope.item.productId = $scope.item.product.id;
  4376. $scope.item.quotation.status = 100;//在录入
  4377. if($scope.item.quotation.date instanceof Date) {
  4378. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  4379. }
  4380. if($scope.item.quotation.endDate instanceof Date) {
  4381. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  4382. }
  4383. Quotation.save({}, $scope.item, function(data){
  4384. $scope.loading = false;
  4385. toaster.pop('success', '成功', '保存成功');
  4386. if($stateParams.id)
  4387. window.location.reload();
  4388. else
  4389. window.location.hash = '#/sale/quotation/' + data.id;
  4390. }, function(response){
  4391. $scope.loading = false;
  4392. toaster.pop('error', '保存失败', response.data);
  4393. });
  4394. };
  4395. // 更新
  4396. $scope.update = function(){
  4397. $scope.item.$editing = true;
  4398. };
  4399. // 取消
  4400. $scope.cancel = function(){
  4401. $scope.item.$editing = false;
  4402. $scope.item = angular.copy(staticItem);
  4403. };
  4404. // 提交
  4405. $scope.submit = function(){
  4406. $scope.loading = true;
  4407. $scope.item.quotation.status = 101;//已提交
  4408. Quotation.save({}, $scope.item, function(data){
  4409. $scope.loading = false;
  4410. toaster.pop('success', '成功', '提交成功');
  4411. window.location.hash = '#/sale/quotation/' + data.id;
  4412. }, function(response){
  4413. $scope.loading = false;
  4414. toaster.pop('error', '保存失败', response.data);
  4415. });
  4416. };
  4417. }]);
  4418. // 查找客户
  4419. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  4420. BaseService.scrollBackToTop();
  4421. $scope.tableParams = new ngTableParams({
  4422. page : 1,
  4423. count : 10
  4424. }, {
  4425. total : 0,
  4426. counts: [5, 10, 25, 50],
  4427. getData : function($defer, params) {
  4428. $scope.loading = true;
  4429. var pageParams = params.url();
  4430. pageParams.keyword = $scope.keyword;
  4431. Customer.get(BaseService.parseParams(pageParams), function(page){
  4432. $scope.loading = false;
  4433. if(page) {
  4434. params.total(page.totalElements);
  4435. $defer.resolve(page.content);
  4436. }
  4437. $scope.totalCount = page.totalElements;
  4438. }, function(response){
  4439. $scope.loading = false;
  4440. toaster.pop('error', '数据加载失败', response.data);
  4441. });
  4442. }
  4443. });
  4444. $scope.onSearch = function() {
  4445. $scope.tableParams.page(1);
  4446. $scope.tableParams.reload();
  4447. };
  4448. $scope.cancel = function() {
  4449. $modalInstance.dismiss();
  4450. };
  4451. $scope.check = function(cust){
  4452. $modalInstance.close(cust);
  4453. };
  4454. }]);
  4455. // 查找客户物料
  4456. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  4457. BaseService.scrollBackToTop();
  4458. $scope.tableParams = new ngTableParams({
  4459. page : 1,
  4460. count : 10
  4461. }, {
  4462. total : 0,
  4463. counts: [5, 10, 25, 50],
  4464. getData : function($defer, params) {
  4465. $scope.loading = true;
  4466. var pageParams = params.url();
  4467. pageParams.keyword = $scope.keyword;
  4468. pageParams.custUU = custUU;
  4469. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  4470. $scope.loading = false;
  4471. if(page) {
  4472. params.total(page.totalElements);
  4473. $defer.resolve(page.content);
  4474. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4475. }
  4476. }, function(response){
  4477. $scope.loading = false;
  4478. toaster.pop('error', '数据加载失败', response.data);
  4479. });
  4480. }
  4481. });
  4482. // 取消
  4483. $scope.cancel = function() {
  4484. $modalInstance.dismiss();
  4485. };
  4486. // 选择
  4487. $scope.check = function(cust){
  4488. $modalInstance.close(cust);
  4489. };
  4490. // 搜索框回车
  4491. $scope.onSearch = function() {
  4492. $scope.tableParams.page(1);
  4493. $scope.tableParams.reload();
  4494. };
  4495. }]);
  4496. // 查找供应商
  4497. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  4498. BaseService.scrollBackToTop();
  4499. // 搜索框回车
  4500. $scope.onSearch = function(keyword) {
  4501. $scope.keyword = keyword;
  4502. $scope.tableParams.page(1);
  4503. $scope.tableParams.reload();
  4504. };
  4505. $scope.tableParams = new ngTableParams({
  4506. page : 1,
  4507. count : 10
  4508. }, {
  4509. total : 0,
  4510. counts: [10, 25, 50, 100],
  4511. getData : function($defer, params) {
  4512. $scope.loading = true;
  4513. var pageParams = params.url();
  4514. pageParams.keyword = $scope.keyword;
  4515. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  4516. $scope.loading = false;
  4517. if(page) {
  4518. params.total(page.totalElements);
  4519. $defer.resolve(page.content);
  4520. // 添加供应商时,将已存在的选中
  4521. if ($rootScope.tenderVendor) {
  4522. angular.forEach(page.content, function(vendor) {
  4523. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  4524. vendor.checked = false;
  4525. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  4526. vendor.checked = true;
  4527. break;
  4528. }
  4529. }
  4530. });
  4531. }
  4532. }
  4533. $scope.totalCount = page.totalElements;
  4534. }, function(response){
  4535. $scope.loading = false;
  4536. toaster.pop('error', '数据加载失败', response.data);
  4537. });
  4538. }
  4539. });
  4540. $scope.cancel = function() {
  4541. $modalInstance.dismiss();
  4542. };
  4543. $scope.checks = {
  4544. checked : false
  4545. };// 全选框
  4546. $scope.checkAll = function() {
  4547. angular.forEach($scope.tableParams.data, function(vendor) {
  4548. vendor.checked = $scope.checks.checked;
  4549. });
  4550. };
  4551. // 单选
  4552. $scope.checkOne = function(vendor) {
  4553. vendor.checked = true;
  4554. var checked = true;
  4555. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  4556. if (!message.checked) {
  4557. checked = false;
  4558. }
  4559. });
  4560. $scope.checks.checked = checked;
  4561. };
  4562. // 单反选
  4563. $scope.unCheckOne = function(vendor) {
  4564. vendor.checked = false;
  4565. $scope.checks.checked = false;
  4566. };
  4567. $scope.close = function(){
  4568. var vendors = [];
  4569. angular.forEach($scope.tableParams.data, function(vendor) {
  4570. if(vendor.checked) {
  4571. vendors.push(vendor);
  4572. $modalInstance.close(vendors);
  4573. }
  4574. });
  4575. };
  4576. }]);
  4577. // 发货提醒
  4578. 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){
  4579. BaseService.scrollBackToTop();
  4580. $scope.active = 'todo';
  4581. $scope.currency = Symbol.currency;
  4582. $scope.dateZoneText = '不限';
  4583. $scope.condition = {dateZone: -1};
  4584. $scope.changeDateZone = function(zone) {
  4585. $scope.condition.dateZone = zone;
  4586. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4587. $scope.condition.$dateZoneOpen = false;
  4588. getDateCondition(zone, $scope.condition);
  4589. $scope.tableParams.reload();
  4590. };
  4591. $scope.setActive = function(state) {
  4592. if($scope.active != state) {
  4593. $scope.active = state;
  4594. if($scope.tableParams.page() == 1)
  4595. $scope.tableParams.reload();
  4596. else
  4597. $scope.tableParams.page(1);
  4598. }
  4599. };
  4600. var getService = function() {
  4601. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  4602. };
  4603. $scope.tableParams = new ngTableParams({
  4604. page : 1,
  4605. count : 5,
  4606. sorting: {
  4607. 'delivery': 'asc',
  4608. 'orderItemOrderCode': 'asc',
  4609. 'orderItemNumber': 'asc'
  4610. }
  4611. }, {
  4612. total : 0,
  4613. counts: [5, 10, 25, 50],
  4614. getData : function($defer, params) {
  4615. $scope.loading = true;
  4616. var pageParams = params.url();
  4617. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4618. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4619. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4620. $scope.loading = false;
  4621. if(page) {
  4622. params.total(page.totalElement);
  4623. $defer.resolve(page.content);
  4624. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4625. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4626. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4627. }
  4628. }, function(response){
  4629. $scope.loading = false;
  4630. toaster.pop('error', '数据加载失败', response.data);
  4631. });
  4632. }
  4633. });
  4634. $scope.openDatePicker = function($event, item, openParam) {
  4635. $event.preventDefault();
  4636. $event.stopPropagation();
  4637. item[openParam] = !item[openParam];
  4638. };
  4639. //生成随机单号
  4640. $scope.autoCode = function(notice){
  4641. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  4642. };
  4643. //可送货日期
  4644. $scope.sendDate = function(notice) {
  4645. var stock = notice.orderItem.product.ltinstock || 0;
  4646. var de = new Date(notice.delivery);
  4647. if(stock == -1) {
  4648. de.setMonth(de.getMonth() -1);
  4649. de.setDate(25);
  4650. } else if(stock >= 0) {
  4651. de.setDate(de.getDate() - stock -1);
  4652. }
  4653. return de;
  4654. };
  4655. $scope.onReplyClick = function(notice) {
  4656. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  4657. toaster.pop('warning', '警告', '数量填写错误!');
  4658. } else if(!notice.send.code) {
  4659. toaster.pop('warning', '警告', '请填写发货单号!');
  4660. } else {
  4661. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  4662. $scope.loading = true;
  4663. PurcNotice.save({id: notice.id}, send, function(data){
  4664. $scope.loading = false;
  4665. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  4666. $state.go('sale.send_detail', {id: data.id});
  4667. }, function(response){
  4668. $scope.loading = false;
  4669. toaster.pop('error', '发货失败', response.data);
  4670. });
  4671. }
  4672. };
  4673. $scope.checkboxes = {
  4674. checked : false
  4675. };
  4676. // 点击勾选全部的复选框
  4677. $scope.checkAll = function(){
  4678. angular.forEach($scope.tableParams.data, function(item) {
  4679. if(!item.waiting)
  4680. item.$selected = $scope.checkboxes.checked;
  4681. });
  4682. };
  4683. // 点击其中一个明细的复选框
  4684. $scope.checkOne = function(order){
  4685. var result = true;
  4686. angular.forEach($scope.tableParams.data, function(item) {
  4687. if(item.$selected != true){
  4688. result = false;
  4689. return;
  4690. }
  4691. });
  4692. $scope.checkboxes.checked = result;
  4693. };
  4694. $scope.sendByBatch = function(){
  4695. var modalInstance = $modal.open({
  4696. animation: true,
  4697. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  4698. controller: 'SaleNoticeSendByBatchCtrl',
  4699. size: 'lg',
  4700. resolve: {
  4701. selectedNotices: function(){return $scope.tableParams.data;}
  4702. }
  4703. });
  4704. modalInstance.result.then(function(){
  4705. $scope.tableParams.reload();
  4706. }, function(){
  4707. });
  4708. };
  4709. $scope.getSends = function(notice){
  4710. if( ! notice.sends && notice.endQty > 0){
  4711. notice.getSendsing = true;
  4712. notice.getSendsError = false;
  4713. PurcNotice.getSends({id: notice.id}, function(data){
  4714. notice.getSendsing = false;
  4715. notice.getSendsError = false;
  4716. notice.sends = data;
  4717. }, function(response){
  4718. notice.getSendsing = false;
  4719. notice.getSendsError = true;
  4720. });
  4721. }
  4722. };
  4723. // 搜索框回车
  4724. $scope.onSearch = function() {
  4725. $scope.tableParams.page(1);
  4726. $scope.tableParams.reload();
  4727. };
  4728. // 选择查找日期
  4729. $scope.onDateCondition = function(){
  4730. $scope.tableParams.page(1);
  4731. $scope.tableParams.reload();
  4732. };
  4733. //货车功能
  4734. var truck = $rootScope.truck;
  4735. if(!truck) {
  4736. SaleTruck.query({}, function(data){
  4737. $rootScope.truck = data;
  4738. });
  4739. }
  4740. $scope.isInTruck = function(noticeId) {
  4741. return truck.indexOf(noticeId) > -1;
  4742. };
  4743. $scope.addtoTruck = function(notice) {
  4744. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  4745. $rootScope.truck = data;
  4746. });
  4747. };
  4748. $scope.delFromTruck = function(notice) {
  4749. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  4750. $rootScope.truck = data;
  4751. });
  4752. };
  4753. $scope.$watch(function(){
  4754. return $rootScope.truck;
  4755. }, function(data) {
  4756. truck = $rootScope.truck;
  4757. }, true);
  4758. $scope.$watch(function(){
  4759. return $rootScope.dataChanged;
  4760. }, function(data) {
  4761. data && ($scope.tableParams.reload());
  4762. }, true);
  4763. }]);
  4764. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  4765. $scope.notices = angular.copy(selectedNotices);
  4766. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4767. $scope.saleSend = {
  4768. code: '',
  4769. payments: '',
  4770. currency: '',
  4771. custUU: null,
  4772. custUserUU: null,
  4773. remark: '批量发货',
  4774. sendItems: []
  4775. };
  4776. // 计算总数、总额
  4777. $scope.$watch(function(){
  4778. return $scope.notices;
  4779. }, function(data) {
  4780. var q = 0, t = 0;
  4781. if(data) {
  4782. angular.forEach(data,function(d){
  4783. q += (d.thisSendQty || 0);
  4784. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  4785. });
  4786. }
  4787. $scope.totalQty = q;
  4788. $scope.total = t;
  4789. }, true);
  4790. /**
  4791. * 删除一个已选中的送货提醒
  4792. */
  4793. $scope.removeOne = function(index) {
  4794. $scope.notices.splice(index, 1);
  4795. };
  4796. //确认送货
  4797. $scope.sendByBatch = function () {
  4798. $scope.saleSend.sendItems = [];
  4799. if($scope.saleSend.code == '') {//送货单号为空
  4800. toaster.pop('error', '错误', '请输入送货单号');
  4801. return;
  4802. }
  4803. var a = 0;
  4804. var num = 1;
  4805. var valid = true;
  4806. angular.forEach($scope.notices, function(item, key){
  4807. if(item.$selected) {
  4808. if(a == 0) {//第一次
  4809. $scope.saleSend.currency = item.orderItem.order.currency;
  4810. $scope.saleSend.custUU = item.enUU;
  4811. $scope.saleSend.payments = item.orderItem.order.payments;
  4812. a = 1;
  4813. } else {//其他
  4814. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  4815. if($scope.saleSend.custUU != item.enUU) valid = false;
  4816. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  4817. }
  4818. $scope.saleSend.sendItems.push({
  4819. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  4820. });
  4821. }
  4822. });
  4823. if(!valid) {
  4824. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  4825. } else {
  4826. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  4827. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  4828. $modalInstance.close('success');
  4829. $state.go('sale.send_detail', {id: data.id});
  4830. }, function(response){
  4831. toaster.pop('error', '错误', response.data);
  4832. });
  4833. }
  4834. };
  4835. $scope.cancel = function () {
  4836. $modalInstance.dismiss();
  4837. };
  4838. }]);
  4839. /**
  4840. * 发货单
  4841. */
  4842. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  4843. BaseService.scrollBackToTop();
  4844. $scope.active = 'all';
  4845. $scope.currency = Symbol.currency;
  4846. $scope.dateZoneText = '不限';
  4847. $scope.condition = {dateZone: -1};
  4848. $scope.changeDateZone = function(zone) {
  4849. $scope.condition.dateZone = zone;
  4850. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4851. $scope.condition.$dateZoneOpen = false;
  4852. getDateCondition(zone, $scope.condition);
  4853. $scope.tableParams.reload();
  4854. };
  4855. $scope.setActive = function(state) {
  4856. if($scope.active != state) {
  4857. $scope.active = state;
  4858. if($scope.tableParams.page() == 1)
  4859. $scope.tableParams.reload();
  4860. else
  4861. $scope.tableParams.page(1);
  4862. }
  4863. };
  4864. var getService = function() {
  4865. return SaleSend;
  4866. };
  4867. $scope.tableParams = new ngTableParams({
  4868. page : 1,
  4869. count : 5,
  4870. sorting: {
  4871. date: 'desc'
  4872. }
  4873. }, {
  4874. total : 0,
  4875. counts: [5, 10, 25, 50],
  4876. getData : function($defer, params) {
  4877. $scope.loading = true;
  4878. var pageParams = params.url();
  4879. pageParams.keyword = $scope.keyword;
  4880. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4881. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4882. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4883. $scope.loading = false;
  4884. if(page) {
  4885. params.total(page.totalElement);
  4886. $defer.resolve(page.content);
  4887. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4888. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4889. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4890. }
  4891. }, function(response){
  4892. $scope.loading = false;
  4893. toaster.pop('error', '数据加载失败', response.data);
  4894. });
  4895. }
  4896. });
  4897. $scope.openDatePicker = function($event, item, openParam) {
  4898. $event.preventDefault();
  4899. $event.stopPropagation();
  4900. item[openParam] = !item[openParam];
  4901. };
  4902. // 搜索框回车
  4903. $scope.onSearch = function() {
  4904. $scope.tableParams.page(1);
  4905. $scope.tableParams.reload();
  4906. };
  4907. // 选择查找日期
  4908. $scope.onDateCondition = function(){
  4909. $scope.tableParams.page(1);
  4910. $scope.tableParams.reload();
  4911. };
  4912. }]);
  4913. /**
  4914. * 发货单(包括发货条码维护)
  4915. */
  4916. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  4917. var loading = true;
  4918. $scope.checkBarCode = [];
  4919. $scope.checkBoxCode = [];
  4920. var vm = $scope.vm = {};
  4921. $scope.getCheckedItems = {};
  4922. vm.editBar = false;
  4923. vm.showBarCode = [];
  4924. $scope.barCode = function() {
  4925. vm.editBar = !vm.editBar;
  4926. }
  4927. $scope.checkboxes = {
  4928. checked : false
  4929. };
  4930. $scope.checkbars = {
  4931. checked : false
  4932. };
  4933. // 点击勾选barCode全部的复选框
  4934. $scope.checkBarAll = function(){
  4935. angular.forEach($scope.checkBarCode, function(item,key) {
  4936. $scope.checkBarCode[key] = $scope.checkbars.checked;
  4937. });
  4938. };
  4939. //点击barCode单选
  4940. $scope.checkBarOne = function() {
  4941. var result = true;
  4942. angular.forEach($scope.checkBarCode, function(item,key) {
  4943. if(item != true){
  4944. result = false;
  4945. return;
  4946. }
  4947. });
  4948. $scope.checkbars.checked = result;
  4949. }
  4950. // 点击boxCode全部的复选框
  4951. $scope.checkBoxAll = function(){
  4952. angular.forEach($scope.checkBoxCode, function(item,key) {
  4953. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  4954. });
  4955. };
  4956. //点击boxCode单选
  4957. $scope.checkBoxOne = function() {
  4958. var result = true;
  4959. angular.forEach($scope.checkBoxCode, function(item) {
  4960. if(item != true){
  4961. result = false;
  4962. return;
  4963. }
  4964. });
  4965. $scope.checkboxes.checked = result;
  4966. }
  4967. /**
  4968. * 生成条码和箱号
  4969. */
  4970. $scope.generateBarCode = function(item) {
  4971. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  4972. $scope.getCheckedItems = [];
  4973. var warningdata = '';
  4974. angular.forEach($scope.checkBarCode, function(item,key) {
  4975. $scope.getCheckedItem = {};
  4976. if(item == true ){
  4977. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4978. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  4979. $scope.getCheckedItems.push($scope.getCheckedItem);
  4980. //判断是否生成过条码
  4981. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4982. warningdata += $scope.order.sendItems[key].number+","
  4983. }
  4984. }
  4985. });
  4986. if($scope.getCheckedItems.length == 0){
  4987. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  4988. return;
  4989. }
  4990. if(warningdata != ''){
  4991. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  4992. return ;
  4993. }
  4994. }
  4995. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  4996. toaster.pop('success', '提示','生成成功!');
  4997. loadData();
  4998. },function(response){
  4999. $scope.loading = false;
  5000. toaster.pop('error', '生成失败', response.data);
  5001. });
  5002. }
  5003. /**
  5004. * 打印条码和箱号
  5005. */
  5006. $scope.printCode = function(type) {
  5007. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  5008. //勾选需要打印的行
  5009. $scope.getCheckedItems = [];
  5010. var warningdata = ''
  5011. angular.forEach($scope.checkBarCode, function(item,key) {
  5012. $scope.getCheckedItem = {};
  5013. if(item == true ){
  5014. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  5015. $scope.getCheckedItems.push($scope.getCheckedItem);
  5016. //判断是否生成过条码
  5017. if($scope.order.sendItems[key].barSendNotify.length > 0){
  5018. warningdata += $scope.order.sendItems[key].number+","
  5019. }
  5020. }
  5021. });
  5022. if($scope.getCheckedItems.length == 0){
  5023. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  5024. return;
  5025. }
  5026. if(warningdata == ''){
  5027. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  5028. return;
  5029. }
  5030. //选择打印模板
  5031. var modalInstance = $modal.open({
  5032. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  5033. controller: 'BarPrintModalCtrl',
  5034. resolve: {
  5035. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  5036. }
  5037. });
  5038. modalInstance.result.then(function(s){
  5039. if(s) {
  5040. //获取打印数据
  5041. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  5042. if(s.type == 'print'){//判断选择是打印还是打印预览
  5043. lodopPrint(data.message,LODOP,type);
  5044. }else if(s.type == 'printPreview'){
  5045. lodopPrintPreview(data.message,LODOP,type);
  5046. }
  5047. },function(response){
  5048. toaster.pop('error', '获取打印数据失败', response.data);
  5049. });
  5050. }
  5051. });
  5052. };
  5053. //打印单个条码
  5054. $scope.printSingleCode = function(id){
  5055. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  5056. //选择打印模板
  5057. var modalInstance = $modal.open({
  5058. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  5059. controller: 'BarPrintModalCtrl',
  5060. resolve: {
  5061. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  5062. }
  5063. });
  5064. modalInstance.result.then(function(s){
  5065. if(s) {
  5066. //获取打印数据
  5067. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  5068. if(s.type == 'print'){//判断选择是打印还是打印预览
  5069. lodopSPrint(data.message,LODOP);
  5070. }else if(s.type == 'printPreview'){
  5071. lodopSPrintPreview(data.message,LODOP);
  5072. }
  5073. },function(response){
  5074. toaster.pop('error', '获取打印数据失败', response.data);
  5075. });
  5076. }
  5077. });
  5078. }
  5079. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  5080. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5081. if (selectOrNot != -1) {
  5082. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5083. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5084. var strs = pagesize.split("*"); //字符分割
  5085. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5086. angular.forEach(printStore, function(data, index) {
  5087. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5088. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5089. if (data['LP_VALUETYPE'] == 'barcode') {
  5090. 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']);
  5091. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5092. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5093. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5094. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5095. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5096. } else if (data['LP_VALUETYPE'] == 'text') {
  5097. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5098. }
  5099. });
  5100. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5101. LODOP.PRINT();
  5102. }
  5103. };
  5104. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  5105. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5106. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5107. var strs = pagesize.split("*"); //字符分割
  5108. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5109. angular.forEach(printStore,function(data,index){
  5110. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5111. if(data['LP_VALUETYPE'] == 'barcode'){
  5112. 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']);
  5113. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5114. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5115. }else if(data['LP_VALUETYPE'] == 'text'){
  5116. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5117. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5118. }
  5119. });
  5120. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5121. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5122. LODOP.PREVIEW();//打印预览
  5123. };
  5124. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  5125. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5126. if (selectOrNot != -1) {
  5127. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5128. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  5129. var strs= new Array(); //定义一数组
  5130. strs = pagesize.split("*"); //字符分割
  5131. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5132. var ids = new Array();
  5133. angular.forEach(printStore, function(value,key) {
  5134. //LODOP.NewPage();
  5135. angular.forEach(value['data'], function(record,key) {
  5136. angular.forEach(record['store'], function(data, index) {
  5137. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5138. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5139. if (data['LP_VALUETYPE'] == 'barcode') {
  5140. 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']);
  5141. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5142. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5143. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5144. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5145. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5146. } else if (data['LP_VALUETYPE'] == 'text') {
  5147. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5148. }
  5149. });
  5150. });
  5151. var o = new Object();
  5152. o['id'] = record['si_id']
  5153. ids.push(o);
  5154. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5155. LODOP.PRINT();
  5156. });
  5157. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5158. if(type == 'Bar'){
  5159. //更新打印状态
  5160. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  5161. }
  5162. }
  5163. };
  5164. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  5165. var ids = new Array();
  5166. angular.forEach(printData, function(record, index){
  5167. angular.forEach(record['data'],function(value,index){
  5168. LODOP.NewPage();
  5169. angular.forEach(value['store'],function(data,index){
  5170. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5171. if(data['LP_VALUETYPE'] == 'barcode'){
  5172. 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']);
  5173. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5174. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5175. }else if(data['LP_VALUETYPE'] == 'text'){
  5176. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5177. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5178. }
  5179. });
  5180. });
  5181. var o = new Object();
  5182. o['id'] = record['si_id']
  5183. ids.push(o);
  5184. });
  5185. var pagesize = printData[0]['pagesize'];//获取标签的大小
  5186. var strs= new Array(); //定义一数组
  5187. strs = pagesize.split("*"); //字符分割
  5188. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5189. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5190. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5191. var times = LODOP.PREVIEW();//打印预览
  5192. if(times > 0){//点击了打印预览内的打印按钮
  5193. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5194. if(type == 'Bar'){
  5195. //更新打印状态
  5196. SaleSend.updatePrintStatus({},ids,function(data){
  5197. loadData();
  5198. },function(res){});
  5199. }
  5200. }
  5201. };
  5202. /**
  5203. * 查看条码按钮
  5204. */
  5205. $scope.showBarCode = function(number) {
  5206. $scope.keys = number;
  5207. for(var i=0;i<vm.showBarCode.length;i++){
  5208. if(i!=number){
  5209. vm.showBarCode[i] = false;
  5210. }
  5211. }
  5212. vm.showBarCode[number] = !vm.showBarCode[number];
  5213. $scope.barcodes = [];
  5214. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  5215. var getPage = function(page, size){
  5216. if($scope.barcodes) {
  5217. var result = {};
  5218. result.totalCount = $scope.barcodes.length;
  5219. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  5220. if($scope.barcodes.length % size == 0) {
  5221. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  5222. }else {
  5223. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  5224. }
  5225. result.first = page == 1;
  5226. result.last = page == result.totalPage;
  5227. result.page = page;
  5228. result.next = page - 0 + 1;
  5229. result.pre = page - 1;
  5230. return result;
  5231. }
  5232. }
  5233. $scope.barData = getPage(1,5);
  5234. $scope.first = function (){
  5235. $scope.barData = getPage($scope.barData.pre,5);
  5236. }
  5237. $scope.last = function (){
  5238. $scope.barData = getPage($scope.barData.next,5);
  5239. }
  5240. };
  5241. /**
  5242. * 更新外箱号
  5243. */
  5244. $scope.updateOutBox = function(item,number) {
  5245. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  5246. }else {
  5247. if(item.outBoxQty > 0) {
  5248. if(!(item.outBoxQty % item.packageQty)) {
  5249. SaleSend.update({id:item.id},item,function(){
  5250. toaster.pop('success', '提示','保存成功!');
  5251. loadData();
  5252. }, function(response){
  5253. $scope.loading = false;
  5254. toaster.pop('error', '回复失败', response.data);
  5255. })
  5256. }else {
  5257. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  5258. }
  5259. }else {
  5260. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5261. }
  5262. }
  5263. loadData();
  5264. };
  5265. /**
  5266. * 更新最小包数
  5267. */
  5268. $scope.updatePackage = function(item, number) {
  5269. if(item.packageQty == $scope.oldpackageQty[number]) {
  5270. }else {
  5271. if(item.orderItem.product.minPack != 0) {
  5272. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5273. if(!(item.packageQty % item.orderItem.product.minPack)) {
  5274. SaleSend.update({id:item.id},item,function(){
  5275. toaster.pop('success', '提示','保存成功!');
  5276. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5277. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5278. }
  5279. loadData();
  5280. }, function(response){
  5281. $scope.loading = false;
  5282. toaster.pop('error', '回复失败', response.data);
  5283. })
  5284. }else {
  5285. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  5286. }
  5287. }else {
  5288. toaster.pop('warning', '提示', '请填写有效的数量!');
  5289. }
  5290. }else {
  5291. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5292. SaleSend.update({id:item.id},item,function(){
  5293. toaster.pop('success', '提示','保存成功!');
  5294. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5295. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5296. }
  5297. loadData();
  5298. }, function(response){
  5299. $scope.loading = false;
  5300. toaster.pop('error', '回复失败', response.data);
  5301. })
  5302. }else {
  5303. toaster.pop('warning', '提示', '请填写有效的数量!');
  5304. }
  5305. }
  5306. }
  5307. loadData();
  5308. };
  5309. var loadData = function() {
  5310. SaleSend.get({id: $stateParams.id}, function(data){
  5311. $scope.order = data;
  5312. var orderCount = $scope.order.sendItems.length;
  5313. $scope.oldpackageQty = [];
  5314. $scope.oldoutBoxQty = [];
  5315. var sum = 0;
  5316. vm.oldpackageQty = [];
  5317. angular.forEach(data.sendItems, function(value, key){
  5318. //给showBarCode数组赋初值
  5319. if (vm.showBarCode.length < orderCount){
  5320. vm.showBarCode.push(false);
  5321. }
  5322. if($scope.checkBarCode.length < orderCount) {
  5323. $scope.checkBarCode.push(false);
  5324. }
  5325. if($scope.checkBoxCode.length < orderCount) {
  5326. $scope.checkBoxCode.push(false);
  5327. }
  5328. //给个初值
  5329. if(!value.packageQty) {
  5330. value.packageQty = value.orderItem.product.minPack;
  5331. }
  5332. $scope.oldpackageQty.push(value.packageQty);
  5333. if(value.outBoxQty) {
  5334. $scope.oldoutBoxQty.push(value.outBoxQty);
  5335. }
  5336. sum += value.price * value.qty;
  5337. });
  5338. data.total = sum;
  5339. $scope.loading = false;
  5340. }, function(response){
  5341. loading = false;
  5342. toaster.pop('error', '获取数据失败', response.data);
  5343. });
  5344. };
  5345. loadData();
  5346. }]);
  5347. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  5348. $scope.typeItem = typeItem;
  5349. $scope.template = [];
  5350. $scope.choose = {};
  5351. //获取打印模板
  5352. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  5353. if(data.message){
  5354. $scope.template = data.message;
  5355. $scope.choose.tp_id = $scope.template[0].id;
  5356. }
  5357. },function(res){
  5358. toaster.pop('error', '获取模板错误', res.data);
  5359. });
  5360. $scope.print = function(){
  5361. $scope.choose.type = 'print';
  5362. $modalInstance.close($scope.choose);
  5363. };
  5364. $scope.printPreview = function(){
  5365. $scope.choose.type = 'printPreview';
  5366. $modalInstance.close($scope.choose);
  5367. }
  5368. $scope.cancel = function(){
  5369. $modalInstance.close();
  5370. }
  5371. }]);
  5372. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', function($scope, $stateParams, PurcSample, toaster, $modal, BaseService){
  5373. BaseService.scrollBackToTop();
  5374. var loading = true;
  5375. var loadData = function() {
  5376. PurcSample.get({id: $stateParams.id}, function(data){
  5377. $scope.sample = data;
  5378. if(!$scope.sample.send){
  5379. $scope.sample.getSendInfo = '加载中...';
  5380. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  5381. if(sendData) {
  5382. $scope.sample.getSendInfo = null;
  5383. $scope.sample.send = sendData;
  5384. } else {
  5385. $scope.sample.getSendInfo = '无送样信息';
  5386. $scope.sample.send = '无送样信息';
  5387. }
  5388. }, function(response){
  5389. $scope.sample.getSendInfo = '加载失败!';
  5390. });
  5391. }
  5392. $scope.loading = false;
  5393. }, function(response){
  5394. loading = false;
  5395. toaster.pop('error', '获取数据失败', response.data);
  5396. });
  5397. };
  5398. loadData();
  5399. $scope.openSend = function(index, sample) {
  5400. var modalInstance = $modal.open({
  5401. animation: true,
  5402. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5403. controller: 'SampleSendCtrl',
  5404. resolve: {
  5405. sampleItem: function(){return sample;}
  5406. }
  5407. });
  5408. modalInstance.result.then(function(){
  5409. toaster.pop('info', '提示', '送样成功');
  5410. $scope.tableParams.reload();
  5411. }, function(){
  5412. });
  5413. };
  5414. }]);
  5415. /**
  5416. * 客户打样申请
  5417. */
  5418. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  5419. BaseService.scrollBackToTop();
  5420. $scope.active = 'todo';
  5421. $scope.agreedText = '全部';
  5422. $scope.dateZoneText = '一个月内';
  5423. $scope.condition = {dateZone: 1};
  5424. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5425. $scope.changeAgreed = function(agreed) {
  5426. $scope.condition.agreed = agreed;
  5427. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5428. $scope.condition.$agreedOpen = false;
  5429. };
  5430. $scope.changeDateZone = function(zone) {
  5431. $scope.condition.dateZone = zone;
  5432. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5433. $scope.condition.$dateZoneOpen = false;
  5434. };
  5435. $scope.setActive = function(state) {
  5436. if($scope.active != state) {
  5437. $scope.active = state;
  5438. if($scope.tableParams.page() == 1)
  5439. $scope.tableParams.reload();
  5440. else
  5441. $scope.tableParams.page(1);
  5442. }
  5443. };
  5444. var getService = function() {
  5445. return PurcSample;
  5446. };
  5447. $scope.tableParams = new ngTableParams({
  5448. page : 1,
  5449. count : 5,
  5450. sorting: {
  5451. proofingDate: 'desc'
  5452. }
  5453. }, {
  5454. total : 0,
  5455. counts: [5, 10, 25, 50],
  5456. getData : function($defer, params) {
  5457. $scope.loading = true;
  5458. var pageParams = params.url();
  5459. pageParams.keyword = $scope.keyword;
  5460. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5461. $scope.loading = false;
  5462. if(page) {
  5463. params.total(page.totalElement);
  5464. $defer.resolve(page.content);
  5465. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5466. angular.forEach(page.content, function(proofing) { // 为了支持多次送样,读取列表的时候获取送样信息作为比较依据
  5467. if( !proofing.send) {
  5468. proofing.getSendInfo = '加载中...';
  5469. PurcSample.getSend({id: proofing.id}, function(data){
  5470. if(data) {
  5471. proofing.getSendInfo = null;
  5472. proofing.send = data;
  5473. } else {
  5474. proofing.getSendInfo = '无送样信息';
  5475. proofing.send = '无送样信息';
  5476. }
  5477. }, function(response){
  5478. proofing.getSendInfo = '加载失败!';
  5479. });
  5480. }
  5481. });
  5482. }
  5483. }, function(response){
  5484. $scope.loading = false;
  5485. toaster.pop('error', '数据加载失败', response.data);
  5486. });
  5487. }
  5488. });
  5489. $scope.openDatePicker = function($event, item, openParam) {
  5490. $event.preventDefault();
  5491. $event.stopPropagation();
  5492. item[openParam] = !item[openParam];
  5493. };
  5494. $scope.openSend = function(index, sample) {
  5495. var modalInstance = $modal.open({
  5496. animation: true,
  5497. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5498. controller: 'SampleSendCtrl',
  5499. resolve: {
  5500. sampleItem: function(){return sample;}
  5501. }
  5502. });
  5503. modalInstance.result.then(function(){
  5504. toaster.pop('info', '提示', '送样成功');
  5505. $scope.tableParams.reload();
  5506. }, function(){
  5507. });
  5508. };
  5509. //打印 样品采购单
  5510. $scope.print = function(sample) {
  5511. PurcSample.printCount({id: sample.id},{});//增加打印此次
  5512. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  5513. };
  5514. $scope.getSend = function(proofing){
  5515. if( !proofing.send) {
  5516. proofing.getSendInfo = '加载中...';
  5517. PurcSample.getSend({id: proofing.id}, function(data){
  5518. if(data) {
  5519. proofing.getSendInfo = null;
  5520. proofing.send = data;
  5521. } else {
  5522. proofing.getSendInfo = '无送样信息';
  5523. proofing.send = '无送样信息';
  5524. }
  5525. }, function(response){
  5526. proofing.getSendInfo = '加载失败!';
  5527. });
  5528. }
  5529. };
  5530. // 搜索框回车
  5531. $scope.onSearch = function() {
  5532. $scope.tableParams.page(1);
  5533. $scope.tableParams.reload();
  5534. };
  5535. }]);
  5536. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  5537. if( !sampleItem.send) {
  5538. PurcSample.getSend({id: sampleItem.id}, function(data){
  5539. if(data) {
  5540. sampleItem.send = data; // 获取送样信息
  5541. }
  5542. }, function(response){
  5543. });
  5544. }
  5545. $scope.sampleItem = sampleItem;
  5546. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  5547. //确认送样
  5548. $scope.ok = function (form) {
  5549. $scope.loading = true;
  5550. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  5551. $upload.upload({
  5552. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  5553. method: 'POST',
  5554. file: file,
  5555. data: {
  5556. json: $scope.sampleItem.sampleSend
  5557. }
  5558. }).success(function(data){
  5559. $scope.loading = false;
  5560. $modalInstance.close('success');
  5561. }).error(function(data){
  5562. $scope.loading = false;
  5563. toaster.pop('danger', '错误', data);
  5564. });
  5565. };
  5566. $scope.cancel = function () {
  5567. $modalInstance.dismiss(sampleItem);
  5568. };
  5569. }]);
  5570. /**
  5571. * 客户认定单
  5572. */
  5573. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  5574. BaseService.scrollBackToTop();
  5575. $scope.active = 'all';
  5576. $scope.agreedText = '全部';
  5577. $scope.dateZoneText = '一个月内';
  5578. $scope.condition = {dateZone: 1};
  5579. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5580. $scope.changeDateZone = function(zone) {
  5581. $scope.condition.dateZone = zone;
  5582. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5583. $scope.condition.$dateZoneOpen = false;
  5584. getDateCondition(zone, $scope.condition);
  5585. $scope.tableParams.reload();
  5586. };
  5587. $scope.setActive = function(state) {
  5588. if($scope.active != state) {
  5589. $scope.active = state;
  5590. if($scope.tableParams.page() == 1)
  5591. $scope.tableParams.reload();
  5592. else
  5593. $scope.tableParams.page(1);
  5594. }
  5595. };
  5596. var getService = function() {
  5597. return PurcApproval;
  5598. };
  5599. $scope.tableParams = new ngTableParams({
  5600. page : 1,
  5601. count : 5,
  5602. sorting: {
  5603. inDate: 'desc'
  5604. }
  5605. }, {
  5606. total : 0,
  5607. counts: [5, 10, 25, 50],
  5608. getData : function($defer, params) {
  5609. $scope.loading = true;
  5610. var pageParams = params.url();
  5611. pageParams.keyword = $scope.keyword;
  5612. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5613. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5614. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5615. $scope.loading = false;
  5616. if(page) {
  5617. params.total(page.totalElement);
  5618. $defer.resolve(page.content);
  5619. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5620. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5621. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5622. }
  5623. }, function(response){
  5624. $scope.loading = false;
  5625. toaster.pop('error', '数据加载失败', response.data);
  5626. });
  5627. }
  5628. });
  5629. $scope.openDatePicker = function($event, item, openParam) {
  5630. $event.preventDefault();
  5631. $event.stopPropagation();
  5632. item[openParam] = !item[openParam];
  5633. };
  5634. $scope.parseDate = function(dateStr) {
  5635. if(dateStr)
  5636. return Date.parse(dateStr, 'yyyy-MM-dd');
  5637. return new Date();
  5638. };
  5639. // 搜索框回车
  5640. $scope.onSearch = function() {
  5641. $scope.tableParams.page(1);
  5642. $scope.tableParams.reload();
  5643. };
  5644. // 选择查找日期
  5645. $scope.onDateCondition = function(){
  5646. $scope.tableParams.page(1);
  5647. $scope.tableParams.reload();
  5648. };
  5649. }]);
  5650. /**
  5651. * 客户采购预测
  5652. */
  5653. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  5654. BaseService.scrollBackToTop();
  5655. $scope.active = 'all';
  5656. $scope.agreedText = '全部';
  5657. $scope.dateZoneText = '一个月内';
  5658. $scope.condition = {dateZone: 1};
  5659. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5660. $scope.changeAgreed = function(agreed) {
  5661. $scope.condition.agreed = agreed;
  5662. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5663. $scope.condition.$agreedOpen = false;
  5664. };
  5665. $scope.changeDateZone = function(zone) {
  5666. $scope.condition.dateZone = zone;
  5667. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5668. $scope.condition.$dateZoneOpen = false;
  5669. };
  5670. $scope.setActive = function(state) {
  5671. if($scope.active != state) {
  5672. $scope.active = state;
  5673. if($scope.tableParams.page() == 1)
  5674. $scope.tableParams.reload();
  5675. else
  5676. $scope.tableParams.page(1);
  5677. }
  5678. };
  5679. var getService = function() {
  5680. return PurcForecast;
  5681. };
  5682. $scope.tableParams = new ngTableParams({
  5683. page : 1,
  5684. count : 5,
  5685. sorting: {
  5686. orderDate: 'desc'
  5687. }
  5688. }, {
  5689. total : 0,
  5690. counts: [5, 10, 25, 50],
  5691. getData : function($defer, params) {
  5692. $scope.loading = true;
  5693. var pageParams = params.url();
  5694. pageParams.keyword = $scope.keyword;
  5695. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5696. $scope.loading = false;
  5697. if(page) {
  5698. params.total(page.totalElement);
  5699. $defer.resolve(page.content);
  5700. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5701. }
  5702. }, function(response){
  5703. $scope.loading = false;
  5704. toaster.pop('error', '数据加载失败', response.data);
  5705. });
  5706. }
  5707. });
  5708. $scope.openDatePicker = function($event, item, openParam) {
  5709. $event.preventDefault();
  5710. $event.stopPropagation();
  5711. item[openParam] = !item[openParam];
  5712. };
  5713. // 搜索框回车
  5714. $scope.onSearch = function() {
  5715. $scope.tableParams.page(1);
  5716. $scope.tableParams.reload();
  5717. };
  5718. }]);
  5719. /**
  5720. * 客户采购验收
  5721. */
  5722. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  5723. BaseService.scrollBackToTop();
  5724. $scope.active = 'all';
  5725. $scope.dateZoneText = '不限';
  5726. $scope.deliveryZoneText = '不限';
  5727. $scope.condition = {dateZone: -1, deliveryZone: -1};
  5728. $scope.changeDateZone = function(zone) {
  5729. $scope.condition.dateZone = zone;
  5730. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5731. $scope.condition.$dateZoneOpen = false;
  5732. getDateCondition(zone, $scope.condition);
  5733. $scope.tableParams.reload();
  5734. };
  5735. $scope.changeDeliveryZone = function(zone) {
  5736. $scope.condition.deliveryZoneText = zone;
  5737. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  5738. $scope.condition.$delievryZoneOpen = false;
  5739. getDelveryCondition(zone, $scope.condition);
  5740. $scope.tableParams.reload();
  5741. };
  5742. $scope.setActive = function(state) {
  5743. if($scope.active != state) {
  5744. $scope.active = state;
  5745. if($scope.tableParams.page() == 1)
  5746. $scope.tableParams.reload();
  5747. else
  5748. $scope.tableParams.page(1);
  5749. }
  5750. };
  5751. var getService = function() {
  5752. return PurcAccept;
  5753. };
  5754. $scope.tableParams = new ngTableParams({
  5755. page : 1,
  5756. count : 5,
  5757. sorting: {
  5758. date: 'desc'
  5759. }
  5760. }, {
  5761. total : 0,
  5762. counts: [5, 10, 25, 50],
  5763. getData : function($defer, params) {
  5764. $scope.loading = true;
  5765. var pageParams = params.url();
  5766. pageParams.searchFilter = { // 筛选条件
  5767. keyword: $scope.keyword,
  5768. fromDate: getDateTime($scope.condition.dateFrom),
  5769. endDate: getDateTime($scope.condition.dateTo)
  5770. };
  5771. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5772. $scope.loading = false;
  5773. if(page) {
  5774. params.total(page.totalElement);
  5775. $defer.resolve(page.content);
  5776. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5777. }
  5778. }, function(response){
  5779. $scope.loading = false;
  5780. toaster.pop('error', '数据加载失败', response.data);
  5781. });
  5782. }
  5783. });
  5784. $scope.openDatePicker = function($event, item, openParam) {
  5785. $event.preventDefault();
  5786. $event.stopPropagation();
  5787. item[openParam] = !item[openParam];
  5788. };
  5789. $scope.parseDate = function(dateStr) {
  5790. if(dateStr)
  5791. return Date.parse(dateStr, 'yyyy-MM-dd');
  5792. return new Date();
  5793. };
  5794. // 选择查找日期
  5795. $scope.onDateCondition = function(){
  5796. $scope.tableParams.page(1);
  5797. $scope.tableParams.reload();
  5798. };
  5799. // 搜索框回车
  5800. $scope.onSearch = function() {
  5801. $scope.tableParams.page(1);
  5802. $scope.tableParams.reload();
  5803. };
  5804. }]);
  5805. /**
  5806. * 客户采购验退
  5807. */
  5808. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  5809. BaseService.scrollBackToTop();
  5810. $scope.active = 'all';
  5811. $scope.agreedText = '全部';
  5812. $scope.dateZoneText = '一个月内';
  5813. $scope.condition = {dateZone: 1};
  5814. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5815. $scope.changeAgreed = function(agreed) {
  5816. $scope.condition.agreed = agreed;
  5817. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5818. $scope.condition.$agreedOpen = false;
  5819. };
  5820. $scope.changeDateZone = function(zone) {
  5821. $scope.condition.dateZone = zone;
  5822. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5823. $scope.condition.$dateZoneOpen = false;
  5824. };
  5825. $scope.setActive = function(state) {
  5826. if($scope.active != state) {
  5827. $scope.active = state;
  5828. if($scope.tableParams.page() == 1)
  5829. $scope.tableParams.reload();
  5830. else
  5831. $scope.tableParams.page(1);
  5832. }
  5833. };
  5834. var getService = function() {
  5835. return PurcReturn;
  5836. };
  5837. $scope.tableParams = new ngTableParams({
  5838. page : 1,
  5839. count : 5,
  5840. sorting: {
  5841. date: 'desc'
  5842. }
  5843. }, {
  5844. total : 0,
  5845. counts: [5, 10, 25, 50],
  5846. getData : function($defer, params) {
  5847. $scope.loading = true;
  5848. var pageParams = params.url();
  5849. pageParams.keyword = $scope.keyword;
  5850. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5851. $scope.loading = false;
  5852. if(page) {
  5853. params.total(page.totalElement);
  5854. $defer.resolve(page.content);
  5855. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5856. angular.forEach(page.content, function(data) {
  5857. if (!data.returnItems[0].orderItem) {
  5858. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  5859. data.enName = enterprise.enName;
  5860. });
  5861. }
  5862. });
  5863. }
  5864. }, function(response){
  5865. $scope.loading = false;
  5866. toaster.pop('error', '数据加载失败', response.data);
  5867. });
  5868. }
  5869. });
  5870. $scope.openDatePicker = function($event, item, openParam) {
  5871. $event.preventDefault();
  5872. $event.stopPropagation();
  5873. item[openParam] = !item[openParam];
  5874. };
  5875. // 搜索框回车
  5876. $scope.onSearch = function() {
  5877. $scope.tableParams.page(1);
  5878. $scope.tableParams.reload();
  5879. };
  5880. }]);
  5881. /**
  5882. * 客户不良品入库
  5883. */
  5884. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  5885. BaseService.scrollBackToTop();
  5886. $scope.active = 'all';
  5887. $scope.agreedText = '全部';
  5888. $scope.dateZoneText = '一个月内';
  5889. $scope.condition = {dateZone: 1};
  5890. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5891. $scope.changeAgreed = function(agreed) {
  5892. $scope.condition.agreed = agreed;
  5893. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5894. $scope.condition.$agreedOpen = false;
  5895. };
  5896. $scope.changeDateZone = function(zone) {
  5897. $scope.condition.dateZone = zone;
  5898. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5899. $scope.condition.$dateZoneOpen = false;
  5900. };
  5901. $scope.setActive = function(state) {
  5902. if($scope.active != state) {
  5903. $scope.active = state;
  5904. if($scope.tableParams.page() == 1)
  5905. $scope.tableParams.reload();
  5906. else
  5907. $scope.tableParams.page(1);
  5908. }
  5909. };
  5910. var getService = function() {
  5911. return PurcBadIn;
  5912. };
  5913. $scope.tableParams = new ngTableParams({
  5914. page : 1,
  5915. count : 5,
  5916. sorting: {
  5917. date: 'desc'
  5918. }
  5919. }, {
  5920. total : 0,
  5921. counts: [5, 10, 25, 50],
  5922. getData : function($defer, params) {
  5923. $scope.loading = true;
  5924. var pageParams = params.url();
  5925. pageParams.keyword = $scope.keyword;
  5926. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5927. $scope.loading = false;
  5928. if(page) {
  5929. params.total(page.totalElement);
  5930. $defer.resolve(page.content);
  5931. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5932. }
  5933. }, function(response){
  5934. $scope.loading = false;
  5935. toaster.pop('error', '数据加载失败', response.data);
  5936. });
  5937. }
  5938. });
  5939. $scope.openDatePicker = function($event, item, openParam) {
  5940. $event.preventDefault();
  5941. $event.stopPropagation();
  5942. item[openParam] = !item[openParam];
  5943. };
  5944. // 搜索框回车
  5945. $scope.onSearch = function() {
  5946. $scope.tableParams.page(1);
  5947. $scope.tableParams.reload();
  5948. };
  5949. }]);
  5950. /**
  5951. * 客户不良品出库
  5952. */
  5953. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  5954. BaseService.scrollBackToTop();
  5955. $scope.active = 'all';
  5956. $scope.agreedText = '全部';
  5957. $scope.dateZoneText = '一个月内';
  5958. $scope.condition = {dateZone: 1};
  5959. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5960. $scope.changeAgreed = function(agreed) {
  5961. $scope.condition.agreed = agreed;
  5962. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5963. $scope.condition.$agreedOpen = false;
  5964. };
  5965. $scope.changeDateZone = function(zone) {
  5966. $scope.condition.dateZone = zone;
  5967. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5968. $scope.condition.$dateZoneOpen = false;
  5969. };
  5970. $scope.setActive = function(state) {
  5971. if($scope.active != state) {
  5972. $scope.active = state;
  5973. if($scope.tableParams.page() == 1)
  5974. $scope.tableParams.reload();
  5975. else
  5976. $scope.tableParams.page(1);
  5977. }
  5978. };
  5979. var getService = function() {
  5980. return PurcBadOut;
  5981. };
  5982. $scope.tableParams = new ngTableParams({
  5983. page : 1,
  5984. count : 5,
  5985. sorting: {
  5986. date: 'desc'
  5987. }
  5988. }, {
  5989. total : 0,
  5990. counts: [5, 10, 25, 50],
  5991. getData : function($defer, params) {
  5992. $scope.loading = true;
  5993. var pageParams = params.url();
  5994. pageParams.keyword = $scope.keyword;
  5995. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5996. $scope.loading = false;
  5997. if(page) {
  5998. params.total(page.totalElement);
  5999. $defer.resolve(page.content);
  6000. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6001. }
  6002. }, function(response){
  6003. $scope.loading = false;
  6004. toaster.pop('error', '数据加载失败', response.data);
  6005. });
  6006. }
  6007. });
  6008. $scope.openDatePicker = function($event, item, openParam) {
  6009. $event.preventDefault();
  6010. $event.stopPropagation();
  6011. item[openParam] = !item[openParam];
  6012. };
  6013. // 搜索框回车
  6014. $scope.onSearch = function() {
  6015. $scope.tableParams.page(1);
  6016. $scope.tableParams.reload();
  6017. };
  6018. }]);
  6019. /**
  6020. * 客户MRB
  6021. */
  6022. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  6023. BaseService.scrollBackToTop();
  6024. $scope.active = 'all';
  6025. $scope.agreedText = '全部';
  6026. $scope.dateZoneText = '一个月内';
  6027. $scope.condition = {dateZone: 1};
  6028. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6029. $scope.changeAgreed = function(agreed) {
  6030. $scope.condition.agreed = agreed;
  6031. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6032. $scope.condition.$agreedOpen = false;
  6033. };
  6034. $scope.changeDateZone = function(zone) {
  6035. $scope.condition.dateZone = zone;
  6036. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6037. $scope.condition.$dateZoneOpen = false;
  6038. };
  6039. $scope.setActive = function(state) {
  6040. if($scope.active != state) {
  6041. $scope.active = state;
  6042. if($scope.tableParams.page() == 1)
  6043. $scope.tableParams.reload();
  6044. else
  6045. $scope.tableParams.page(1);
  6046. }
  6047. };
  6048. var getService = function() {
  6049. return PurcMRB;
  6050. };
  6051. $scope.tableParams = new ngTableParams({
  6052. page : 1,
  6053. count : 5,
  6054. sorting: {
  6055. date: 'desc'
  6056. }
  6057. }, {
  6058. total : 0,
  6059. counts: [5, 10, 25, 50],
  6060. getData : function($defer, params) {
  6061. $scope.loading = true;
  6062. var pageParams = params.url();
  6063. pageParams.keyword = $scope.keyword;
  6064. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6065. $scope.loading = false;
  6066. if(page) {
  6067. params.total(page.totalElement);
  6068. $defer.resolve(page.content);
  6069. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6070. }
  6071. }, function(response){
  6072. $scope.loading = false;
  6073. toaster.pop('error', '数据加载失败', response.data);
  6074. });
  6075. }
  6076. });
  6077. $scope.openDatePicker = function($event, item, openParam) {
  6078. $event.preventDefault();
  6079. $event.stopPropagation();
  6080. item[openParam] = !item[openParam];
  6081. };
  6082. // 搜索框回车
  6083. $scope.onSearch = function() {
  6084. $scope.tableParams.page(1);
  6085. $scope.tableParams.reload();
  6086. };
  6087. }]);
  6088. /**
  6089. * 客户应付发票
  6090. */
  6091. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  6092. BaseService.scrollBackToTop();
  6093. $scope.active = 'all';
  6094. $scope.dateZoneText = '不限';
  6095. $scope.condition = {dateZone: -1};
  6096. $scope.changeDateZone = function(zone) {
  6097. $scope.condition.dateZone = zone;
  6098. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6099. $scope.condition.$dateZoneOpen = false;
  6100. getDateCondition(zone, $scope.condition);
  6101. $scope.tableParams.reload();
  6102. };
  6103. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6104. $scope.setActive = function(state) {
  6105. if($scope.active != state) {
  6106. $scope.active = state;
  6107. if($scope.tableParams.page() == 1)
  6108. $scope.tableParams.reload();
  6109. else
  6110. $scope.tableParams.page(1);
  6111. }
  6112. };
  6113. var getService = function() {
  6114. return FaApBill;
  6115. };
  6116. $scope.tableParams = new ngTableParams({
  6117. page : 1,
  6118. count : 5,
  6119. sorting: {
  6120. date: 'desc'
  6121. }
  6122. }, {
  6123. total : 0,
  6124. counts: [5, 10, 25, 50],
  6125. getData : function($defer, params) {
  6126. $scope.loading = true;
  6127. var pageParams = params.url();
  6128. pageParams.searchFilter = { // 筛选条件
  6129. keyword: $scope.keyword,
  6130. fromDate: getDateTime($scope.condition.dateFrom),
  6131. endDate: getDateTime($scope.condition.dateTo)
  6132. };
  6133. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6134. $scope.loading = false;
  6135. if(page) {
  6136. params.total(page.totalElement);
  6137. $defer.resolve(page.content);
  6138. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  6139. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6140. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6141. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  6142. }
  6143. }, function(response){
  6144. $scope.loading = false;
  6145. toaster.pop('error', '数据加载失败', response.data);
  6146. });
  6147. }
  6148. });
  6149. $scope.openDatePicker = function($event, item, openParam) {
  6150. $event.preventDefault();
  6151. $event.stopPropagation();
  6152. item[openParam] = !item[openParam];
  6153. };
  6154. $scope.parseDate = function(dateStr) {
  6155. if(dateStr)
  6156. return Date.parse(dateStr, 'yyyy-MM-dd');
  6157. return new Date();
  6158. };
  6159. // 搜索框回车
  6160. $scope.onSearch = function() {
  6161. $scope.tableParams.page(1);
  6162. $scope.tableParams.reload();
  6163. };
  6164. // 选择查找日期
  6165. $scope.onDateCondition = function(){
  6166. $scope.tableParams.page(1);
  6167. $scope.tableParams.reload();
  6168. };
  6169. }]);
  6170. /**
  6171. * 客户应付发票详情
  6172. */
  6173. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', function($scope, $filter, FaApBill, toaster, $stateParams, BaseService){
  6174. BaseService.scrollBackToTop();
  6175. var loadData = function() {
  6176. FaApBill.get({id: $stateParams.id}, function(data){
  6177. $scope.bill = data;
  6178. console.log(data);
  6179. $scope.loading = false;
  6180. });
  6181. };
  6182. loadData(); // 初始获取单据数据
  6183. }]);
  6184. /**
  6185. * 应付对账单
  6186. */
  6187. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  6188. BaseService.scrollBackToTop();
  6189. $scope.active = 'all';
  6190. $scope.dateZoneText = '不限';
  6191. $scope.condition = {dateZone: -1};
  6192. $scope.changeDateZone = function(zone) {
  6193. $scope.condition.dateZone = zone;
  6194. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6195. $scope.condition.$dateZoneOpen = false;
  6196. getDateCondition(zone, $scope.condition);
  6197. $scope.tableParams.reload();
  6198. };
  6199. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6200. $scope.setActive = function(state) {
  6201. if($scope.active != state) {
  6202. $scope.active = state;
  6203. if($scope.tableParams.page() == 1)
  6204. $scope.tableParams.reload();
  6205. else
  6206. $scope.tableParams.page(1);
  6207. }
  6208. };
  6209. var getService = function() {
  6210. return FaArCheck;
  6211. };
  6212. $scope.tableParams = new ngTableParams({
  6213. page : 1,
  6214. count : 5,
  6215. sorting: {
  6216. date: 'desc'
  6217. }
  6218. }, {
  6219. total : 0,
  6220. counts: [5, 10, 25, 50],
  6221. getData : function($defer, params) {
  6222. $scope.loading = true;
  6223. var pageParams = params.url();
  6224. pageParams.keyword = $scope.keyword;
  6225. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6226. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6227. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6228. $scope.loading = false;
  6229. if(page) {
  6230. params.total(page.totalElement);
  6231. $defer.resolve(page.content);
  6232. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6233. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6234. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6235. }
  6236. }, function(response){
  6237. $scope.loading = false;
  6238. toaster.pop('error', '数据加载失败', response.data);
  6239. });
  6240. }
  6241. });
  6242. $scope.openDatePicker = function($event, item, openParam) {
  6243. $event.preventDefault();
  6244. $event.stopPropagation();
  6245. item[openParam] = !item[openParam];
  6246. };
  6247. // 计算单据的商品总数
  6248. $scope.getTotalProd = function(check) {
  6249. var total = 0;
  6250. if(check.items) {
  6251. angular.forEach(check.items, function(value) {
  6252. total += value.qty;
  6253. });
  6254. }
  6255. return total;
  6256. };
  6257. // 搜索框回车
  6258. $scope.onSearch = function() {
  6259. $scope.tableParams.page(1);
  6260. $scope.tableParams.reload();
  6261. };
  6262. // 选择查找日期
  6263. $scope.onDateCondition = function(){
  6264. $scope.tableParams.page(1);
  6265. $scope.tableParams.reload();
  6266. };
  6267. }]);
  6268. // 应付对账单详情页
  6269. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  6270. BaseService.scrollBackToTop();
  6271. var loadData = function() {
  6272. FaArCheck.get({id: $stateParams.id}, function(data){
  6273. $scope.order = data;
  6274. $scope.loading = false;
  6275. });
  6276. };
  6277. loadData(); // 初始获取单据数据
  6278. $scope.onReplyClick = function(item, isAgreed) {
  6279. if(isAgreed) {// 同意确认
  6280. FaArCheck.agree({itemId: item.id}, {}, function(data){
  6281. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  6282. }, function(response){
  6283. toaster.pop('danger', '确认失败', response.data);
  6284. });
  6285. } else {// 不同意回复
  6286. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  6287. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  6288. }, function(response) {
  6289. toaster.pop('danger', '确认失败', response.data);
  6290. });
  6291. }
  6292. };
  6293. // 获取明细的回复记录
  6294. $scope.getReplies = function(item) {
  6295. if(!item.replies) {
  6296. FaArCheck.getReplies({itemId: item.id}, function(data) {
  6297. item.replies = data;
  6298. }, function(response) {
  6299. toaster.pop('danger', '获取对账记录失败', response.data);
  6300. });
  6301. }
  6302. };
  6303. }]);
  6304. //应收对账单列表
  6305. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  6306. BaseService.scrollBackToTop();
  6307. $scope.dateZoneText = '不限';
  6308. $scope.condition = {dateZone: -1};
  6309. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6310. $scope.active = 'todo';
  6311. //打印 对账单
  6312. $scope.print = function(check) {
  6313. FaApCheck.printCount({id: check.id},{});//增加打印此次
  6314. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  6315. };
  6316. //状态
  6317. $scope.setActive = function (state){
  6318. if($scope.active != state) {
  6319. $scope.active = state;
  6320. if($scope.tableParams.page() == 1)
  6321. $scope.tableParams.reload();
  6322. else
  6323. $scope.tableParams.page(1);
  6324. }
  6325. };
  6326. $scope.changeDateZone = function(zone) {
  6327. $scope.condition.dateZone = zone;
  6328. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6329. $scope.condition.$dateZoneOpen = false;
  6330. getDateCondition(zone, $scope.condition);
  6331. $scope.tableParams.reload();
  6332. };
  6333. //获取应收对账单全部
  6334. $scope.tableParams = new ngTableParams({
  6335. page : 1,
  6336. count : 5,
  6337. sorting: {
  6338. recordDate: 'desc'
  6339. }
  6340. }, {
  6341. total : 0,
  6342. counts: [5, 10, 25, 50],
  6343. getData : function($defer, params) {
  6344. $scope.loading = true;
  6345. var pageParams = params.url();
  6346. pageParams.searchFilter = { // 筛选条件
  6347. keyword: $scope.keyword,
  6348. fromDate: getDateTime($scope.condition.dateFrom),
  6349. endDate: getDateTime($scope.condition.dateTo)
  6350. };
  6351. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  6352. $scope.loading = false;
  6353. if(page) {
  6354. params.total(page.totalElement);
  6355. $scope.data = $defer.resolve(page.content);
  6356. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  6357. }
  6358. }, function(response){
  6359. $scope.loading = false;
  6360. toaster.pop('error', '数据加载失败', response.data);
  6361. });
  6362. }
  6363. });
  6364. $scope.openDatePicker = function($event, item, openParam) {
  6365. $event.preventDefault();
  6366. $event.stopPropagation();
  6367. item[openParam] = !item[openParam];
  6368. };
  6369. // 计算单据的商品总数
  6370. $scope.getTotalProd = function(check) {
  6371. var total = 0;
  6372. if(check.items) {
  6373. angular.forEach(check.items, function(value) {
  6374. total += value.checkQty;
  6375. });
  6376. }
  6377. return total;
  6378. };
  6379. // 搜索框回车
  6380. $scope.onSearch = function() {
  6381. $scope.tableParams.page(1);
  6382. $scope.tableParams.reload();
  6383. };
  6384. // 选择查找日期
  6385. $scope.onDateCondition = function(){
  6386. $scope.tableParams.page(1);
  6387. $scope.tableParams.reload();
  6388. };
  6389. }]);
  6390. //应收对账单详情
  6391. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  6392. BaseService.scrollBackToTop();
  6393. $scope.haveSelected = true;
  6394. $scope.data = {};
  6395. //控制提交和删除按钮的显示
  6396. $scope.ifShow = true;
  6397. var loadData = function(){
  6398. FaApCheck.get({id:$stateParams.id},function(data){
  6399. $scope.data = data;
  6400. if($scope.data.status){
  6401. }else{
  6402. $scope.ifShow = true;
  6403. }
  6404. })
  6405. };
  6406. if($stateParams.id){
  6407. loadData();
  6408. }
  6409. $scope.haveSource = false;
  6410. //提交应收对账单
  6411. $scope.submitApCheck = function(){
  6412. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  6413. if(data.result) {
  6414. toaster.pop('success', '提示', '提交成功');
  6415. $scope.haveSelected = false;
  6416. window.location.href = '#/fa/apCheck';
  6417. }else {
  6418. $scope.haveSource = true;
  6419. loadData();
  6420. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  6421. $scope.haveSelected = true;
  6422. }
  6423. },function(){
  6424. $scope.loading = false;
  6425. toaster.pop('error', '提示', '更新已转数失败');
  6426. });
  6427. }
  6428. //删除应收对账单的同时更新来源表已转数
  6429. var updateYCheckQty = function(){
  6430. var sourceInfos = [];
  6431. angular.forEach($scope.data.items, function(item){
  6432. $scope.sourceInfo = {
  6433. sourceId: '',
  6434. sourceTable: '',
  6435. newYCheckQty: ''
  6436. };
  6437. $scope.sourceInfo.sourceId = item.sourceId;
  6438. $scope.sourceInfo.sourceTable = item.sourceTable;
  6439. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  6440. sourceInfos.push($scope.sourceInfo);
  6441. });
  6442. FaApCheck.update({}, sourceInfos, function(){
  6443. },function(response){
  6444. $scope.loading = false;
  6445. toaster.pop('error', '更新已转数失败', response.data);
  6446. });
  6447. }
  6448. //删除应收对账单
  6449. $scope.deleteApCheck = function(){
  6450. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  6451. updateYCheckQty();
  6452. toaster.pop('success','提示','删除成功');
  6453. },function(){
  6454. toaster.pop('error','提示','删除失败');
  6455. });
  6456. $scope.haveSelected = false;
  6457. }
  6458. //作废应收对账单
  6459. $scope.cancelApCheck = function(check) {
  6460. FaApCheck.cancel({id:check.id},function(data){
  6461. $scope.checkResult = false;
  6462. if(data.result) {
  6463. $scope.checkResult = true;
  6464. toaster.pop('success', '提示', '作废成功');
  6465. $scope.tableParams.reload();
  6466. }else{
  6467. toaster.pop('error', '提示', '作废失败');
  6468. }
  6469. },function(){
  6470. $scope.loading = false;
  6471. toaster.pop('error', '提示', '作废失败');
  6472. });
  6473. }
  6474. }]);
  6475. //未对账单据列表
  6476. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  6477. $scope.data = [];// 列表数据
  6478. $scope.condition = {
  6479. $fromOpened: false
  6480. }
  6481. $scope.openDatePicker = function($event, item, openParam) {
  6482. $event.preventDefault();
  6483. $event.stopPropagation();
  6484. item[openParam] = !item[openParam];
  6485. }
  6486. //查找客户
  6487. $scope.searchCust = function(suuorname) {
  6488. var modalInstance = $modal.open({
  6489. animation: true,
  6490. templateUrl: 'static/tpl/index/fa/custInfo.html',
  6491. controller: 'SearchCustInfoCtrl',
  6492. resolve: {
  6493. suuorname: function() {
  6494. return suuorname;
  6495. }
  6496. }
  6497. });
  6498. modalInstance.result.then(function(suuorname){
  6499. $scope.suuorname = suuorname;
  6500. });
  6501. }
  6502. // 点击筛选根据条件选择数据
  6503. $scope.suuorname = '';
  6504. // 默认本月
  6505. $scope.sdateTo = new Date();
  6506. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  6507. $scope.vuuorname = '';
  6508. $scope.factory = '';
  6509. $scope.prodTitle = '';
  6510. $scope.prodSpec = '';
  6511. $scope.condition.uuorname = '';
  6512. $scope.condition.dateFrom = '';
  6513. $scope.condition.dateTo = '';
  6514. $scope.condition.venduuorname = '';
  6515. $scope.condition.factory = '';
  6516. $scope.condition.prodTitle = '';
  6517. $scope.condition.prodSpec = '';
  6518. $scope.searchOrder = function(check) {
  6519. $scope.data = [];
  6520. $scope.checkboxes.checked = false;
  6521. $scope.totalMoney = 0;
  6522. $scope.condition.uuorname = $scope.suuorname;
  6523. $scope.condition.factory = $scope.factory
  6524. $scope.condition.prodTitle = $scope.prodTitle;
  6525. $scope.condition.prodSpec = $scope.prodSpec;
  6526. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  6527. $scope.thisdatato = ($scope.sdateTo || 0);
  6528. if($scope.thisdatato != 0) {
  6529. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  6530. } else {
  6531. $scope.condition.dateTo = ($scope.sdateTo || 0);
  6532. }
  6533. $scope.condition.venduuorname = $scope.vuuorname;
  6534. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  6535. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6536. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6537. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  6538. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  6539. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  6540. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  6541. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  6542. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6543. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6544. if(!$scope.suuorname) {
  6545. toaster.pop('warning','提示', '请先选择客户');
  6546. document.getElementById('suuorname').focus();//光标默认在客户
  6547. } else {
  6548. $scope.loading = true;
  6549. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  6550. if(data.length > 0) {
  6551. angular.forEach(data, function(item) {
  6552. item.$selected = true;
  6553. });
  6554. $scope.data = data;
  6555. $scope.checkboxes.checked = true;
  6556. $scope.getTotalMoney();
  6557. } else {
  6558. toaster.pop('info', '提示', '当前没有需要对账记录');
  6559. }
  6560. $scope.loading = false;
  6561. }, function(response) {
  6562. $scope.loading = false;
  6563. toaster.pop('error', '提示', response.data);
  6564. });
  6565. }
  6566. }
  6567. }
  6568. /**
  6569. * 点击勾选框,选中要转应收对账单的订单
  6570. * */
  6571. $scope.totalMoney = 0;
  6572. $scope.checkboxes = {
  6573. checked : false
  6574. };
  6575. // 点击勾选全部的复选框
  6576. $scope.checkAll = function(){
  6577. $scope.totalMoney = 0;
  6578. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  6579. var uuorname = $scope.suuorname;
  6580. var venduuorname = $scope.venduuorname;
  6581. var dateFrom = $scope.condition.dateFrom;
  6582. var dateTo = $scope.condition.dateTo;
  6583. var prodTitle = $scope.condition.prodTitle;
  6584. var prodSpec = $scope.condition.prodSpec;
  6585. var factory = $scope.condition.factory;
  6586. angular.forEach($scope.filteredData, function(item) {
  6587. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  6588. item.$selected = $scope.checkboxes.checked;
  6589. }
  6590. });
  6591. $scope.getTotalMoney();
  6592. };
  6593. //获取已选单据总金额
  6594. var total = true;
  6595. $scope.getTotalMoney = function(){
  6596. $scope.totalMoney = 0;
  6597. angular.forEach($scope.data, function(check) {
  6598. if(check.$selected){
  6599. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6600. }else{
  6601. $scope.totalMoney += 0;
  6602. }
  6603. });
  6604. }
  6605. // 点击其中一个明细的复选框
  6606. $scope.checkOne = function(check){
  6607. var result = true;
  6608. angular.forEach($scope.data, function(item) {
  6609. if(item.$selected != true){
  6610. result = false;
  6611. return;
  6612. }
  6613. });
  6614. $scope.checkboxes.checked = result;
  6615. };
  6616. $scope.haveSelected = false;
  6617. //生成应收对账单
  6618. $scope.createApCheck = function(){
  6619. //保存应收对账单主记录字段
  6620. $scope.apCheck = {
  6621. custUu: '',
  6622. custName: '',
  6623. enUu: '',
  6624. apDate: '',
  6625. beginDate: '',
  6626. endDate: '',
  6627. checkStatus: '未对账',
  6628. checkAmount: 0,
  6629. currency: '',
  6630. rate: '',
  6631. items: []
  6632. };
  6633. //保存来源单据相关信息
  6634. var sourceInfos = [];
  6635. //所允许的本次对账最大最小数量
  6636. $scope.data.maxThisCheckQty = 0;
  6637. $scope.data.minThisCheckQty = 0;
  6638. $scope.sameCust = true;
  6639. $scope.validQty = true;
  6640. $scope.loading = true;
  6641. angular.forEach($scope.data, function(check) {
  6642. //保存应收对账单明细行数据
  6643. $scope.item = {
  6644. inoutno: '',
  6645. inoutnodetno: '',
  6646. orderCode: '',
  6647. orderClass: '',
  6648. orderDetno: '',
  6649. price: '',
  6650. checkQty: '',
  6651. amount: '',
  6652. sourceId:'',
  6653. sourceTable:'',
  6654. oldYCheckQty:'',
  6655. status: 0,
  6656. receiveCode:'',
  6657. receiveName:'',
  6658. prodCode:'',
  6659. prodTitle:'',
  6660. prodSpec:'',
  6661. taxrate: '',
  6662. sendcode: '',
  6663. whname: '',
  6664. };
  6665. //应收对账单明细行来源表信息
  6666. $scope.sourceInfo = {
  6667. sourceId: '',
  6668. sourceTable: '',
  6669. newYCheckQty: ''
  6670. };
  6671. //此次对账后新的已转数
  6672. $scope.newYCheckQty = 0;
  6673. if(check.$selected == true) {
  6674. $scope.apCheck.custName = check.custName;
  6675. $scope.apCheck.enUu = check.enUu;
  6676. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6677. $scope.apCheck.apDate = check.piDate;
  6678. $scope.apCheck.rate = check.rate;
  6679. //必须是同一家客户才能生成对账单,否则提示错误
  6680. if($scope.apCheck.custUu == ''){
  6681. $scope.apCheck.custUu = check.custUu;
  6682. }else if($scope.apCheck.custUu !== check.custUu){
  6683. $scope.sameCust = false;
  6684. $scope.loading = false;
  6685. toaster.pop('error', '请选择同一家客户');
  6686. }
  6687. //必须是相同币别才能生成对账单,否则提示错误
  6688. if($scope.apCheck.currency == ''){
  6689. $scope.apCheck.currency = check.currency;
  6690. }else if($scope.apCheck.currency !== check.currency){
  6691. $scope.sameCust = false;
  6692. $scope.loading = false;
  6693. toaster.pop('error', '请选择同一种币别');
  6694. }
  6695. //本次对账数量必须小于总对账数量
  6696. if(check.qty > 0){
  6697. $scope.data.maxThisCheckQty = check.qty;
  6698. $scope.data.minThisCheckQty = 0;
  6699. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  6700. $scope.validQty = false;
  6701. $scope.loading = false;
  6702. toaster.pop('error','本次对账数量,填写有误!');
  6703. }
  6704. }else if(check.qty < 0){
  6705. $scope.data.maxThisCheckQty = 0;
  6706. $scope.data.minThisCheckQty = check.qty;
  6707. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  6708. $scope.validQty = false;
  6709. $scope.loading = false;
  6710. toaster.pop('error','本次对账数量,填写有误!');
  6711. }
  6712. }
  6713. //获取最小时间作为对账区间的起始时间
  6714. if($scope.apCheck.beginDate == ''){
  6715. $scope.apCheck.beginDate = check.piDate;
  6716. }else{
  6717. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  6718. }
  6719. //获取最大时间作为对账区间的截止时间
  6720. if($scope.apCheck.endDate == ''){
  6721. $scope.apCheck.endDate = check.piDate;
  6722. }else{
  6723. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  6724. }
  6725. //应收对账单明细行数据
  6726. $scope.item.orderCode = check.orderCode;
  6727. $scope.item.orderClass = check.piClass;
  6728. $scope.item.orderDetno = check.orderDetno;
  6729. $scope.item.price = check.orderPrice;
  6730. $scope.item.checkQty = check.thisCheckQty;
  6731. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6732. $scope.item.sourceId = check.sourceId;
  6733. $scope.item.sourceTable = check.sourceTable;
  6734. $scope.item.oldYCheckQty = check.yCheckQty;
  6735. $scope.item.prodCode = check.prodCode;
  6736. $scope.item.prodTitle = check.prodTitle;
  6737. $scope.item.prodSpec = check.prodSpec;
  6738. $scope.item.inoutno = check.inOutNo;
  6739. $scope.item.inoutnodetno = check.detno;
  6740. $scope.item.taxrate = check.taxrate;
  6741. $scope.item.receiveCode = check.receiveCode;
  6742. $scope.item.receiveName = check.receiveName;
  6743. $scope.item.sendcode = check.sendcode;
  6744. $scope.item.whname = check.whname;
  6745. //来源表相关信息
  6746. $scope.sourceInfo.sourceId = check.sourceId;
  6747. $scope.sourceInfo.sourceTable = check.sourceTable;
  6748. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  6749. sourceInfos.push($scope.sourceInfo);
  6750. $scope.apCheck.items.push($scope.item);
  6751. $scope.haveSelected = true;
  6752. }
  6753. });
  6754. //保存生成的应收对账单
  6755. $scope.saveApCheck = function(){
  6756. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  6757. $scope.loading = false;
  6758. toaster.pop('success', '成功', '生成应收对账成功');
  6759. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  6760. }, function(response){
  6761. toaster.pop('error', '生成对账单失败', response.data);
  6762. })
  6763. };
  6764. //如果是同一家客户,生成对账单的同时,关闭模态框
  6765. if($scope.sameCust && $scope.validQty) {
  6766. $scope.saveApCheck();
  6767. }
  6768. }
  6769. }]);
  6770. //货款调账
  6771. app.controller('PurchaseAdjustListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', 'ApbillAdjustment', function($scope, FaApCheck, toaster, $state, $filter, $modal, ApbillAdjustment){
  6772. $scope.data = [];// 列表数据
  6773. $scope.condition = {
  6774. $fromOpened: false
  6775. }
  6776. $scope.openDatePicker = function($event, item, openParam) {
  6777. $event.preventDefault();
  6778. $event.stopPropagation();
  6779. item[openParam] = !item[openParam];
  6780. }
  6781. //查找客户
  6782. $scope.searchCust = function(suuorname) {
  6783. var modalInstance = $modal.open({
  6784. animation: true,
  6785. templateUrl: 'static/tpl/index/fa/custInfo.html',
  6786. controller: 'SearchCustInfoCtrl',
  6787. resolve: {
  6788. suuorname: function() {
  6789. return suuorname;
  6790. }
  6791. }
  6792. });
  6793. modalInstance.result.then(function(suuorname){
  6794. $scope.suuorname = suuorname;
  6795. });
  6796. }
  6797. // 点击筛选根据条件选择数据
  6798. $scope.suuorname = '';
  6799. // 默认本月
  6800. $scope.sdateTo = new Date();
  6801. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  6802. $scope.vuuorname = '';
  6803. $scope.factory = '';
  6804. $scope.prodTitle = '';
  6805. $scope.prodSpec = '';
  6806. $scope.condition.uuorname = '';
  6807. $scope.condition.dateFrom = '';
  6808. $scope.condition.dateTo = '';
  6809. $scope.condition.venduuorname = '';
  6810. $scope.condition.factory = '';
  6811. $scope.condition.prodTitle = '';
  6812. $scope.condition.prodSpec = '';
  6813. $scope.searchOrder = function(check) {
  6814. $scope.data = [];
  6815. $scope.checkboxes.checked = false;
  6816. $scope.totalMoney = 0;
  6817. $scope.condition.uuorname = $scope.suuorname;
  6818. $scope.condition.factory = $scope.factory
  6819. $scope.condition.prodTitle = $scope.prodTitle;
  6820. $scope.condition.prodSpec = $scope.prodSpec;
  6821. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  6822. $scope.thisdatato = ($scope.sdateTo || 0);
  6823. if($scope.thisdatato != 0) {
  6824. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  6825. } else {
  6826. $scope.condition.dateTo = ($scope.sdateTo || 0);
  6827. }
  6828. $scope.condition.venduuorname = $scope.vuuorname;
  6829. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  6830. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6831. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6832. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  6833. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  6834. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  6835. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  6836. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  6837. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6838. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6839. if(!$scope.suuorname) {
  6840. toaster.pop('warning','提示', '请先选择客户');
  6841. document.getElementById('suuorname').focus();//光标默认在客户
  6842. } else {
  6843. $scope.loading = true;
  6844. ApbillAdjustment.adjustList({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  6845. if(data.length > 0) {
  6846. angular.forEach(data, function(item) {
  6847. item.$selected = true;
  6848. });
  6849. $scope.data = data;
  6850. $scope.checkboxes.checked = true;
  6851. $scope.getTotalMoney();
  6852. } else {
  6853. toaster.pop('info', '提示', '当前没有需要对账记录');
  6854. }
  6855. $scope.loading = false;
  6856. }, function(response) {
  6857. $scope.loading = false;
  6858. toaster.pop('error', '提示', response.data);
  6859. });
  6860. }
  6861. }
  6862. }
  6863. /**
  6864. * 点击勾选框,选中要转应收对账单的订单
  6865. * */
  6866. $scope.totalMoney = 0;
  6867. $scope.checkboxes = {
  6868. checked : false
  6869. };
  6870. // 点击勾选全部的复选框
  6871. $scope.checkAll = function(){
  6872. $scope.totalMoney = 0;
  6873. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  6874. var uuorname = $scope.suuorname;
  6875. var venduuorname = $scope.venduuorname;
  6876. var dateFrom = $scope.condition.dateFrom;
  6877. var dateTo = $scope.condition.dateTo;
  6878. var prodTitle = $scope.condition.prodTitle;
  6879. var prodSpec = $scope.condition.prodSpec;
  6880. var factory = $scope.condition.factory;
  6881. angular.forEach($scope.filteredData, function(item) {
  6882. if((item.orderdate >= dateFrom || dateFrom == '') && (item.orderdate < dateTo || dateTo == '')){
  6883. item.$selected = $scope.checkboxes.checked;
  6884. }
  6885. });
  6886. $scope.getTotalMoney();
  6887. };
  6888. //获取已选单据总金额
  6889. var total = true;
  6890. $scope.getTotalMoney = function(){
  6891. $scope.totalMoney = 0;
  6892. angular.forEach($scope.data, function(check) {
  6893. if(check.$selected){
  6894. $scope.totalMoney += (check.thischeckqty || 0)*(check.orderprice || 0);
  6895. }else{
  6896. $scope.totalMoney += 0;
  6897. }
  6898. });
  6899. }
  6900. // 点击其中一个明细的复选框
  6901. $scope.checkOne = function(check){
  6902. var result = true;
  6903. angular.forEach($scope.data, function(item) {
  6904. if(item.$selected != true){
  6905. result = false;
  6906. return;
  6907. }
  6908. });
  6909. $scope.checkboxes.checked = result;
  6910. };
  6911. $scope.haveSelected = false;
  6912. //生成应收对账单
  6913. $scope.createApCheck = function(){
  6914. //保存应收对账单主记录字段
  6915. $scope.apCheck = {
  6916. custUu: '',
  6917. custName: '',
  6918. enUu: '',
  6919. apDate: '',
  6920. beginDate: '',
  6921. endDate: '',
  6922. checkStatus: '未对账',
  6923. checkAmount: 0,
  6924. currency: '',
  6925. rate: '',
  6926. items: []
  6927. };
  6928. //保存来源单据相关信息
  6929. var sourceInfos = [];
  6930. //所允许的本次对账最大最小数量
  6931. $scope.data.maxThisCheckQty = 0;
  6932. $scope.data.minThisCheckQty = 0;
  6933. $scope.sameCust = true;
  6934. $scope.validQty = true;
  6935. $scope.loading = true;
  6936. angular.forEach($scope.data, function(check) {
  6937. //保存应收对账单明细行数据
  6938. $scope.item = {
  6939. inoutno: '',
  6940. inoutnodetno: '',
  6941. orderCode: '',
  6942. orderClass: '',
  6943. orderDetno: '',
  6944. price: '',
  6945. checkQty: '',
  6946. amount: '',
  6947. sourceId:'',
  6948. sourceTable:'',
  6949. oldYCheckQty:'',
  6950. status: 0,
  6951. receiveCode:'',
  6952. receiveName:'',
  6953. prodCode:'',
  6954. prodTitle:'',
  6955. prodSpec:'',
  6956. taxrate: '',
  6957. sendcode: '',
  6958. whname: '',
  6959. };
  6960. //应收对账单明细行来源表信息
  6961. $scope.sourceInfo = {
  6962. sourceId: '',
  6963. sourceTable: '',
  6964. newYCheckQty: ''
  6965. };
  6966. //此次对账后新的已转数
  6967. $scope.newYCheckQty = 0;
  6968. if(check.$selected == true) {
  6969. $scope.apCheck.custName = check.custname;
  6970. $scope.apCheck.enUu = check.enuu;
  6971. $scope.apCheck.checkAmount += (check.thischeckqty || 0)*(check.orderprice || 0);
  6972. $scope.apCheck.apDate = check.date;
  6973. $scope.apCheck.rate = check.rate;
  6974. //必须是同一家客户才能生成对账单,否则提示错误
  6975. if($scope.apCheck.custUu == ''){
  6976. $scope.apCheck.custUu = check.custuu;
  6977. }else if($scope.apCheck.custUu !== check.custuu){
  6978. $scope.sameCust = false;
  6979. $scope.loading = false;
  6980. toaster.pop('error', '请选择同一家客户');
  6981. }
  6982. //必须是相同币别才能生成对账单,否则提示错误
  6983. if($scope.apCheck.currency == ''){
  6984. $scope.apCheck.currency = check.currency;
  6985. }else if($scope.apCheck.currency !== check.currency){
  6986. $scope.sameCust = false;
  6987. $scope.loading = false;
  6988. toaster.pop('error', '请选择同一种币别');
  6989. }
  6990. //本次对账数量必须小于总对账数量
  6991. if(check.qty > 0){
  6992. $scope.data.maxThisCheckQty = check.qty;
  6993. $scope.data.minThisCheckQty = 0;
  6994. if(check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0){
  6995. $scope.validQty = false;
  6996. $scope.loading = false;
  6997. toaster.pop('error','本次对账数量,填写有误!');
  6998. }
  6999. }else if(check.qty < 0){
  7000. $scope.data.maxThisCheckQty = 0;
  7001. $scope.data.minThisCheckQty = check.qty;
  7002. if(((-check.qty)-(-check.ycheckQty) < (-check.thischeckQty)) || check.thischeckqty > 0 || check.thischeckqty == 0){
  7003. $scope.validQty = false;
  7004. $scope.loading = false;
  7005. toaster.pop('error','本次对账数量,填写有误!');
  7006. }
  7007. }
  7008. //获取最小时间作为对账区间的起始时间
  7009. if($scope.apCheck.beginDate == ''){
  7010. $scope.apCheck.beginDate = check.date;
  7011. }else{
  7012. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.orderdate : $scope.apCheck.beginDate;
  7013. }
  7014. //获取最大时间作为对账区间的截止时间
  7015. if($scope.apCheck.endDate == ''){
  7016. $scope.apCheck.endDate = check.date;
  7017. }else{
  7018. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.orderdate : $scope.apCheck.endDate;
  7019. }
  7020. //应收对账单明细行数据
  7021. $scope.item.orderCode = check.ordercode;
  7022. $scope.item.orderClass = check.piClass;
  7023. $scope.item.orderDetno = check.orderdetno;
  7024. $scope.item.price = check.orderprice;
  7025. $scope.item.checkQty = check.thischeckqty;
  7026. $scope.item.amount = (check.thischeckqty || 0)*(check.orderprice || 0);
  7027. $scope.item.sourceId = check.id;
  7028. $scope.item.sourceTable = 'purc$apbilladjustment';
  7029. $scope.item.orderClass = '货款调账';
  7030. $scope.item.oldYCheckQty = check.ycheckqty;
  7031. $scope.item.prodCode = check.prodcode;
  7032. $scope.item.prodTitle = check.prodtitle;
  7033. $scope.item.prodSpec = check.prodspec;
  7034. $scope.item.inoutno = check.inoutno;
  7035. $scope.item.inoutnodetno = check.detno;
  7036. $scope.item.taxrate = check.taxrate;
  7037. $scope.item.receiveCode = check.receivecode;
  7038. $scope.item.receiveName = check.receivename;
  7039. $scope.item.sendcode = check.sendcode;
  7040. $scope.item.whname = check.whname;
  7041. //来源表相关信息
  7042. $scope.sourceInfo.sourceId = check.id;
  7043. $scope.sourceInfo.sourceTable = 'purc$apbilladjustment';
  7044. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  7045. sourceInfos.push($scope.sourceInfo);
  7046. $scope.apCheck.items.push($scope.item);
  7047. $scope.haveSelected = true;
  7048. }
  7049. });
  7050. //保存生成的应收对账单
  7051. $scope.saveApCheck = function(){
  7052. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  7053. $scope.loading = false;
  7054. toaster.pop('success', '成功', '生成应收对账成功');
  7055. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  7056. }, function(response){
  7057. toaster.pop('error', '生成对账单失败', response.data);
  7058. })
  7059. };
  7060. //如果是同一家客户,生成对账单的同时,关闭模态框
  7061. if($scope.sameCust && $scope.validQty) {
  7062. $scope.saveApCheck();
  7063. }
  7064. }
  7065. }]);
  7066. // 企业信息设置
  7067. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder){
  7068. BaseService.scrollBackToTop();
  7069. $scope.loading = true;
  7070. AccountEnterprise.get({}, function(data){
  7071. $scope.loading = false;
  7072. $scope.enterprise = data;
  7073. // 获取付款企业信息
  7074. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7075. $scope.pays = data;
  7076. }, function(response) {
  7077. toaster.pop('error', '提示', response.data);
  7078. });
  7079. });
  7080. AccountEnterprise.growth({}, function(data){
  7081. if(data != null && data.length > 0) {
  7082. var growth = [], years = [];
  7083. angular.forEach(data, function(d){
  7084. var date = new Date(d.date), year = date.getFullYear();
  7085. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  7086. if(years.indexOf(year) == -1) {
  7087. years.push(year);
  7088. growth.push({year: year});
  7089. }
  7090. growth.push(d);
  7091. });
  7092. $scope.growth = growth;
  7093. }
  7094. });
  7095. // 更新企业信息
  7096. $scope.updateDetailInfo = function(){
  7097. $scope.loading = true;
  7098. AccountEnterprise.save($scope.enterprise, function(){
  7099. $scope.loading = false;
  7100. $scope.connectionEditing = false;
  7101. toaster.pop('success', '提示', '修改企业信息成功');
  7102. $state.reload();
  7103. }, function(response){
  7104. $scope.loading = false;
  7105. toaster.pop('error', '修改信息失败', response.data);
  7106. });
  7107. };
  7108. // 申请Saas
  7109. $scope.applySaas = function(){
  7110. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  7111. var modalInstance = $modal.open({
  7112. animation: true,
  7113. templateUrl: 'static/tpl/index/account/applySaas.html',
  7114. controller: 'ApplySaasCtrl',
  7115. resolve: {
  7116. enterprise: function(){return angular.copy($scope.enterprise);}
  7117. }
  7118. });
  7119. modalInstance.result.then(function(){
  7120. $state.reload();
  7121. }, function(){
  7122. });
  7123. } else {
  7124. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  7125. }
  7126. };
  7127. // 获取收货地址列表
  7128. ShipAddress.shipAddList({}, function(data) {
  7129. $scope.ships = data;
  7130. });
  7131. // 判断是否是代采企业
  7132. DeputyOrder.isDeputyEnterprise({}, function(data) {
  7133. $scope.deputyEnter = data;
  7134. });
  7135. // 获取地址信息
  7136. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7137. }).then(function(response) {
  7138. $scope.provinces = response.data;
  7139. });
  7140. // 新增收货地址保存
  7141. $scope.saveShipAddress = function(ship) {
  7142. ship.address = ship.province + ship.city + ship.district;
  7143. ShipAddress.saveAddress( {}, ship, function(data) {
  7144. if(data.success) {
  7145. ShipAddress.shipAddList({}, function(data) {
  7146. $scope.ships = data;
  7147. });
  7148. toaster.pop('success', '提示', data.success);
  7149. }
  7150. if(data.error) {
  7151. toaster.pop('error', '提示', data.error);
  7152. }
  7153. });
  7154. }
  7155. // 删除收货地址
  7156. $scope.removeShip = function(id, index) {
  7157. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  7158. $scope.ships.splice(index, 1);
  7159. toaster.pop('success', '提示', '收货地址删除成功');
  7160. }, function(response) {
  7161. toaster.pop('error', '提示', response.data);
  7162. });
  7163. };
  7164. // 编辑收货地址
  7165. $scope.editShip = function(ship){
  7166. var modalInstance = $modal.open({
  7167. animation: true,
  7168. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  7169. controller: 'ShipAddressCtrl',
  7170. resolve: {
  7171. ship: function(){return ship;}
  7172. }
  7173. });
  7174. modalInstance.result.then(function() {
  7175. ShipAddress.shipAddList({}, function(data) {
  7176. $scope.ships = data;
  7177. });
  7178. }, function(){
  7179. });
  7180. };
  7181. // 新增付款企业
  7182. $scope.addPayCompany = function() {
  7183. var modalInstance = $modal.open({
  7184. animation: true,
  7185. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7186. controller: 'PayCompanyCtrl',
  7187. resolve: {
  7188. pay: function(){return null;}
  7189. }
  7190. });
  7191. modalInstance.result.then(function() {
  7192. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7193. $scope.pays = data;
  7194. // 获取付款企业信息
  7195. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7196. $scope.pays = data;
  7197. }, function(response) {
  7198. toaster.pop('error', '提示', response.data);
  7199. });
  7200. }, function(response) {
  7201. toaster.pop('error', '提示', response.data);
  7202. });
  7203. }, function(){
  7204. });
  7205. }
  7206. // 删除付款企业
  7207. $scope.removePay = function(id, index) {
  7208. DeputyOrder.removePayCompany({id: id}, {}, function(data) {
  7209. $scope.pays.splice(index, 1);
  7210. toaster.pop('success', '提示', '付款企业信息删除成功');
  7211. }, function(response) {
  7212. toaster.pop('error', '提示', response.data);
  7213. });
  7214. };
  7215. // 编辑付款企业
  7216. $scope.editPay = function(pay, uu) {
  7217. var modalInstance = $modal.open({
  7218. animation: true,
  7219. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7220. controller: 'PayCompanyCtrl',
  7221. resolve: {
  7222. pay: function(){return pay;}
  7223. }
  7224. });
  7225. modalInstance.result.then(function() {
  7226. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7227. $scope.pays = data;
  7228. }, function(response) {
  7229. toaster.pop('error', '提示', response.data);
  7230. });
  7231. }, function(){
  7232. });
  7233. };
  7234. // 设置logo
  7235. $scope.showImageDialog = function(modal) {
  7236. require([ 'jquery-uploadify' ], function() {
  7237. $modal.open({
  7238. templateUrl : 'static/tpl/index/home/insert.html',
  7239. controller : 'ImageInsertCtrl',
  7240. backdrop : 'static'
  7241. }).result.then(function(image){
  7242. $scope.imageUrl = image.thumb;
  7243. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  7244. $scope.user = data;
  7245. }, function(response) {
  7246. toaster.pop('error', '设置图像失败,' + response.data);
  7247. });
  7248. });
  7249. });
  7250. }
  7251. }]);
  7252. // 编辑收货地址
  7253. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  7254. $scope.ship = ship;
  7255. // 获取地址信息
  7256. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7257. }).then(function(response) {
  7258. $scope.provinces = response.data;
  7259. });
  7260. // 新增收货地址保存
  7261. $scope.saveShipAddress = function(ship) {
  7262. ship.address = ship.province + ship.city + ship.district;
  7263. ShipAddress.saveAddress( {}, ship, function(data) {
  7264. if(data.success) {
  7265. toaster.pop('success', '提示', data.success);
  7266. $modalInstance.close();
  7267. }
  7268. if(data.error) {
  7269. toaster.pop('error', '提示', data.error);
  7270. }
  7271. });
  7272. }
  7273. $scope.cancel = function() {
  7274. $modalInstance.dismiss();
  7275. }
  7276. }]);
  7277. // 编辑付款企业信息
  7278. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  7279. $scope.pay = pay;
  7280. // 获取地址信息
  7281. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7282. }).then(function(response) {
  7283. $scope.provinces = response.data;
  7284. });
  7285. // 新增收货地址保存
  7286. $scope.savePayCompany = function(pay) {
  7287. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  7288. DeputyOrder.savePaycompany( {}, pay, function(data) {
  7289. toaster.pop('success', '提示', '保存成功');
  7290. $modalInstance.dismiss();
  7291. }, function(response) {
  7292. toaster.pop('error', '提示', response.data);
  7293. });
  7294. }
  7295. $scope.cancel = function() {
  7296. $modalInstance.dismiss();
  7297. }
  7298. }]);
  7299. // 申请Saas Controller
  7300. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  7301. $scope.enterprise = enterprise;
  7302. $scope.checking = false;
  7303. $scope.$watch('enterprise.enSaasUrl', function(){
  7304. if($scope.enterprise.enSaasUrl) {
  7305. $http.get('signup/saasUrlEnable', {
  7306. params: {
  7307. enSaasUrl: $scope.enterprise.enSaasUrl
  7308. }
  7309. }).success(function(data){
  7310. if(data && data == 'true') {
  7311. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  7312. } else {
  7313. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7314. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  7315. }
  7316. }).error(function(){
  7317. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7318. $scope.enSaasUrlErrorInfo = '验证出错';
  7319. });
  7320. } else {
  7321. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  7322. }
  7323. });
  7324. var setSaasUrl = function(url) {
  7325. var index = url.indexOf('www.');
  7326. if(index != -1) {//包含www.
  7327. var substr = url.substring(index+4, url.length);
  7328. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  7329. } else {
  7330. $scope.enterprise.enSaasUrl = getHost(url);
  7331. }
  7332. };
  7333. // 解析获取网址的一级域名
  7334. var getHost = function(host){
  7335. var newhost;
  7336. var domain;
  7337. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  7338. for(var k in ArrDomain){
  7339. var re = eval('/\\' + ArrDomain[k] + '$/g');
  7340. newhost = host.replace(re, '');
  7341. if(newhost != host){
  7342. domain = ArrDomain[k];
  7343. break;
  7344. }
  7345. }
  7346. var hostar = newhost.split('.');
  7347. var s = hostar[hostar.length-1];
  7348. return s;
  7349. };
  7350. // 设置优企云服域名为官网网址一级域名
  7351. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  7352. $scope.apply = function(){
  7353. $scope.loading = true;
  7354. AccountEnterprise.applySaas({
  7355. enUU: $scope.enterprise.uu,
  7356. enSaasUrl: $scope.enterprise.enSaasUrl,
  7357. enAdminPassword: $scope.enterprise.enAdminPassword
  7358. }, {}, function(){
  7359. $scope.loading = false;
  7360. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  7361. $modalInstance.close();
  7362. }, function(response){
  7363. $scope.loading = false;
  7364. toaster.pop('error', '申请失败', response.data);
  7365. });
  7366. };
  7367. $scope.cancel = function () {
  7368. $modalInstance.dismiss();
  7369. };
  7370. }]);
  7371. 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){
  7372. BaseService.scrollBackToTop();
  7373. $scope.editing = false;
  7374. $scope.loading = true;
  7375. $scope.enterprise = null;
  7376. AccountUser.findDistribute({},function(data) {
  7377. $scope.distributes = data;
  7378. },function(response) {
  7379. toaster.pop('error', '系统错误', response.data);
  7380. });
  7381. AuthenticationService.getAuthentication().success(function(data) {
  7382. $scope.loading = false;
  7383. $scope.user = data;
  7384. });
  7385. var users = [];
  7386. $scope.tableParams = new ngTableParams({
  7387. page : 1,
  7388. count : 5,
  7389. sorting: {
  7390. userName: 'asc'
  7391. }
  7392. }, {
  7393. total : 0,
  7394. counts: [15, 25, 50, 100],
  7395. getData : function($defer, params) {
  7396. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  7397. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  7398. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  7399. angular.forEach($scope.users,function(user){
  7400. AccountEnterprise.get({}, function(data){
  7401. $scope.loading = false;
  7402. $scope.enterprise = data;
  7403. });
  7404. });
  7405. params.total(orderedData.length);
  7406. $defer.resolve($scope.users);
  7407. }
  7408. });
  7409. var loadUsers = function() {
  7410. AccountUser.query({}, function(data){
  7411. users = data;
  7412. angular.forEach(users, function(user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  7413. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  7414. $scope.user.userIdcode = user.userIdcode;
  7415. }
  7416. });
  7417. $scope.tableParams.reload();
  7418. $scope.loading = false;
  7419. });
  7420. };
  7421. loadUsers();
  7422. $scope.saveUser = function(){
  7423. $scope.loading = true;
  7424. AccountUser.update({}, $scope.user, function(data){
  7425. $scope.loading = false;
  7426. toaster.pop('success', '提示', '修改用户信息成功');
  7427. AuthenticationService.getAuthentication().success(function(data) {
  7428. $scope.user = data;
  7429. });
  7430. loadUsers();
  7431. $scope.editing = false;
  7432. }, function(reponse){
  7433. $scope.loading = false;
  7434. toaster.pop('error', '失败', reponse.data);
  7435. });
  7436. };
  7437. $scope.updatePassword = function(){
  7438. var modalInstance = $modal.open({
  7439. animation: true,
  7440. templateUrl: 'updatePassword.html',
  7441. controller: 'PasswordCtrl',
  7442. resolve: {
  7443. user: function(){return $scope.user;}
  7444. }
  7445. });
  7446. modalInstance.result.then(function(){
  7447. }, function(){
  7448. });
  7449. };
  7450. $scope.newUser = {};
  7451. //弹出添加用户模态框
  7452. $scope.addExistUser = function(){
  7453. var modalInstance = $modal.open({
  7454. animation :true,
  7455. templateUrl : 'static/tpl/index/account/addExistUser.html',
  7456. controller : 'AddExistUserCtrl'
  7457. });
  7458. modalInstance.result.then(function(){
  7459. $scope.userTelSuccess = false;
  7460. $scope.userTelError = false;
  7461. loadUsers();
  7462. }, function(){
  7463. });
  7464. };
  7465. /**
  7466. * 添加未注册用户
  7467. */
  7468. $scope.addUser = function() {
  7469. $scope.adding = true;
  7470. AccountUser.save({}, $scope.newUser, function(){
  7471. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  7472. $scope.newUser = {userSex: 'M'};
  7473. loadUsers();
  7474. $scope.adding = false;
  7475. $scope.newUserForm.newUserTel.$setValidity('available', false);
  7476. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  7477. $scope.userTelSuccess = false;
  7478. $scope.userTelError = false;
  7479. $scope.userEmailSuccess = false;
  7480. $scope.userEmailError = false;
  7481. }, function(response){
  7482. toaster.pop('error', '错误', response.data);
  7483. });
  7484. };
  7485. /**
  7486. * 验证手机号是否可用
  7487. */
  7488. $scope.telValid = function(tel) {
  7489. if(tel) {
  7490. $http.get('account/user/telEnable', {
  7491. params: {
  7492. tel: tel
  7493. }
  7494. }).success(function(data){
  7495. data = eval(data);
  7496. if(data == true) {
  7497. $scope.newUserForm.newUserTel.$setValidity('available', true);
  7498. $scope.userTelSuccess = true;
  7499. $scope.userTelError = false;
  7500. }else{
  7501. $scope.newUserForm.newUserTel.$setValidity('available', false);
  7502. $scope.userTelError = true;
  7503. $scope.userTelSuccess = false;
  7504. if(tel.length == 11)
  7505. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  7506. }
  7507. }).error(function(){
  7508. $scope.userTelSuccess = false;
  7509. $scope.userTelError = true;
  7510. });
  7511. } else {
  7512. $scope.userTelSuccess = false;
  7513. $scope.userTelError = false;
  7514. }
  7515. };
  7516. /**
  7517. * 验证邮箱是否可用
  7518. */
  7519. $scope.emailValid = function(email) {
  7520. if(email) {
  7521. $http.get('account/user/emailEnable', {
  7522. params: {
  7523. email: email
  7524. }
  7525. }).success(function(data){
  7526. data = eval(data);
  7527. if(data == true) {
  7528. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  7529. $scope.userEmailSuccess = true;
  7530. $scope.userEmailError = false;
  7531. } else {
  7532. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  7533. $scope.userEmailError = true;
  7534. $scope.userEmailSuccess = false;
  7535. }
  7536. }).error(function(){
  7537. $scope.userEmailError = true;
  7538. $scope.userEmailSuccess = false;
  7539. });
  7540. } else {
  7541. $scope.userEmailError = false;
  7542. $scope.userEmailSuccess = false;
  7543. }
  7544. };
  7545. /**
  7546. * 删除用户
  7547. */
  7548. $scope.removeUser = function(user) {
  7549. new ngAlert({
  7550. title: '提示',
  7551. content: '确定删除用户(' + user.userName + ')吗?'
  7552. }, function(){
  7553. AccountUser.remove({uu: user.userUU}, function(){
  7554. toaster.pop('success', '提示', '用户删除成功。');
  7555. loadUsers();
  7556. }, function(response){
  7557. toaster.pop('error', '删除失败', response.data);
  7558. });
  7559. });
  7560. };
  7561. // 编辑用户的角色
  7562. $scope.editUserRole = function(user) {
  7563. var modalInstance = $modal.open({
  7564. animation: true,
  7565. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  7566. controller: 'UserRoleCtrl',
  7567. resolve: {
  7568. user: function() {
  7569. return user;
  7570. }
  7571. }
  7572. });
  7573. modalInstance.result.then(function(changed, checked){
  7574. if(changed) {
  7575. if(checked)
  7576. $scope.newUser.roles = checked;
  7577. else
  7578. loadUsers();
  7579. }
  7580. });
  7581. };
  7582. // 为用户分配角色(删除企业)
  7583. $scope.removeVendor = function(user) {
  7584. var resultRole = true;
  7585. angular.forEach(user.roles,function(role){
  7586. if(role.issys == 1) {
  7587. toaster.pop('error', '提示', '管理员无需分配客户');
  7588. resultRole = false;
  7589. return;
  7590. }
  7591. })
  7592. if(resultRole) {
  7593. var modalInstance = $modal.open({
  7594. animation: true,
  7595. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  7596. controller: 'RemoveVendorCtrl',
  7597. resolve: {
  7598. user: function() {
  7599. return user;
  7600. }
  7601. }
  7602. });
  7603. }
  7604. }
  7605. // 为用户分配角色(添加企业)
  7606. $scope.addVendor = function(user,isIssy) {
  7607. if(!isIssy) {
  7608. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  7609. return;
  7610. }
  7611. var resultRole = true;
  7612. angular.forEach(user.roles,function(role){
  7613. if(role.issys == 1) {
  7614. toaster.pop('error', '提示', '管理员无需分配客户');
  7615. resultRole = false;
  7616. return;
  7617. }
  7618. })
  7619. if(resultRole) {
  7620. var modalInstance = $modal.open({
  7621. animation: true,
  7622. templateUrl: 'static/tpl/index/account/add_vendor.html',
  7623. controller: 'AddVendorCtrl',
  7624. resolve: {
  7625. user: function() {
  7626. return user;
  7627. }
  7628. }
  7629. });
  7630. modalInstance.result.then(function(changed, checked){
  7631. if(changed) {
  7632. if(checked)
  7633. $scope.newUser.roles = checked;
  7634. else
  7635. loadUsers();
  7636. }
  7637. });
  7638. }
  7639. };
  7640. }]);
  7641. // 登录手机号码验证
  7642. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  7643. $scope.user = user;
  7644. $scope.cancel = function(){
  7645. $modalInstance.close();
  7646. }
  7647. /*$scope.loading = false;
  7648. $scope.btnState = false;
  7649. $scope.clicks = 0;
  7650. var storage = window.localStorage;
  7651. //手机验证码定时器
  7652. $scope.msgInfoError = false;
  7653. var setBtnTimeDown = function(value) {
  7654. if(value > 0) {
  7655. $scope.btnState = true;
  7656. $timeout(function() {
  7657. $scope.$apply(function(){
  7658. storage.setItem("btnTimes", $scope.btnTimes);
  7659. $scope.btnTimes --;
  7660. value --;
  7661. setBtnTimeDown (value);
  7662. });
  7663. }, 500);
  7664. }else{
  7665. $scope.btnState = false;
  7666. }
  7667. };
  7668. if(storage.btnTimes > 1){
  7669. $scope.btnTimes = storage.btnTimes;
  7670. setBtnTimeDown(storage.btnTimes)
  7671. }else{
  7672. storage.removeItem("btnTimes");
  7673. }
  7674. $scope.updateTel = function(phoneCode, userTel, uu){
  7675. $scope.loading = true;
  7676. $scope.msgInfoError = false;
  7677. $scope.result = false;
  7678. //更新联系方式
  7679. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  7680. $scope.loading = false;
  7681. $scope.msgInfoError2 = false;
  7682. $scope.result = true;
  7683. AuthenticationService.getAuthentication().success(function(data) {
  7684. $timeout(function(){
  7685. $modalInstance.dismiss();
  7686. window.location.reload();
  7687. }, 1000);
  7688. }).error(function(response) {
  7689. });
  7690. }, function(response){
  7691. $scope.loading = false;
  7692. $scope.msgInfoError2 = response;
  7693. });
  7694. };
  7695. //获取验证码
  7696. $scope.getPhoneCode = function(userTel){
  7697. var timeInfo = 10;
  7698. $scope.clicks ++;
  7699. $scope.timeInfo = timeInfo;
  7700. if($scope.clicks >= 5){
  7701. $scope.errorloading = true;
  7702. $scope.msgInfoSuccess = false;
  7703. $scope.msgInfoError = false;
  7704. }else{
  7705. $scope.loading = true;
  7706. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  7707. $scope.loading = false;
  7708. $scope.msgInfoSuccess = data.success;
  7709. $scope.sendMsg = data;
  7710. $scope.btnTimes = 60;
  7711. setBtnTimeDown($scope.btnTimes);
  7712. $scope.msgInfoError = false;
  7713. },function(response){
  7714. console.log(response);
  7715. $scope.loading = false;
  7716. $scope.msgInfoError = false;
  7717. $scope.sendCheckMsg = false;
  7718. $scope.msgInfoSuccess = true;
  7719. });
  7720. }
  7721. }; */
  7722. }]);
  7723. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7724. $scope.checkboxes = {
  7725. checked : false
  7726. };
  7727. $scope.loading = true;
  7728. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  7729. $scope.enters = data;
  7730. $scope.loading = false;
  7731. angular.forEach($scope.enters, function(item) {
  7732. item:{
  7733. $selected:true;
  7734. }
  7735. });
  7736. })
  7737. // 点击勾选全部的复选框
  7738. $scope.checkAll = function() {
  7739. angular.forEach($scope.enters, function(item) {
  7740. item.$selected = $scope.checkboxes.checked;
  7741. });
  7742. };
  7743. // 点击其中一个明细的复选框
  7744. $scope.checkOne = function(vendor){
  7745. var result = true;
  7746. angular.forEach($scope.enters, function(item) {
  7747. if(item.$selected != true){
  7748. result = false;
  7749. return;
  7750. }
  7751. });
  7752. $scope.checkboxes.checked = result;
  7753. };
  7754. $scope.close = function(save) {
  7755. var chooseResult = [];
  7756. if(save) {
  7757. if(user.userUU) {
  7758. angular.forEach($scope.enters, function(item, i) {
  7759. if(item.$selected) {
  7760. chooseResult.push(item.id);
  7761. }
  7762. });
  7763. if(chooseResult.length > 0) {
  7764. $scope.loading = true;
  7765. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  7766. $scope.loading = false;
  7767. toaster.pop('success', '提示', '删除成功');
  7768. $modalInstance.close(false);
  7769. }, function(response){
  7770. $scope.loading = false;
  7771. toaster.pop('error', '删除失败', response.data);
  7772. $modalInstance.close(false);
  7773. })
  7774. } else {
  7775. toaster.pop('error', '删除失败', "您未勾选任何记录");
  7776. }
  7777. } else {
  7778. $modalInstance.close(true, $scope.checkboxes.checked);
  7779. }
  7780. } else {
  7781. $modalInstance.close(false);
  7782. }
  7783. };
  7784. }]);
  7785. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7786. $scope.checkboxes = {
  7787. checked : false
  7788. };
  7789. $scope.loading = true;
  7790. AccountUser.findVendor({uu : user.userUU},function(data) {
  7791. $scope.enters = data;
  7792. $scope.loading = false;
  7793. // angular.forEach($scope.enters, function(item) {
  7794. // if(item.distribute) {
  7795. // item:{
  7796. // $selected:false;
  7797. // }
  7798. // } else {
  7799. // item:{
  7800. // $selected:true;
  7801. // }
  7802. // }
  7803. // });
  7804. })
  7805. // 点击勾选全部的复选框
  7806. $scope.checkAll = function() {
  7807. angular.forEach($scope.enters, function(item) {
  7808. item.distribute = $scope.checkboxes.checked;
  7809. });
  7810. };
  7811. // 点击其中一个明细的复选框
  7812. $scope.checkOne = function(vendor){
  7813. var result = true;
  7814. angular.forEach($scope.enters, function(item) {
  7815. if(item.distribute != true){
  7816. result = false;
  7817. return;
  7818. }
  7819. });
  7820. $scope.checkboxes.checked = result;
  7821. };
  7822. $scope.close = function(save) {
  7823. var chooseResult = [];
  7824. if(save) {
  7825. if(user.userUU) {
  7826. angular.forEach($scope.enters, function(item, i) {
  7827. // if(item.distribute) {
  7828. chooseResult.push(item);
  7829. // }
  7830. });
  7831. if(chooseResult.length > 0) {
  7832. $scope.loading = true;
  7833. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  7834. $scope.loading = false;
  7835. toaster.pop('success', '提示', '保存成功');
  7836. $modalInstance.close(false);
  7837. }, function(response){
  7838. $scope.loading = false;
  7839. toaster.pop('error', '保存失败', response.data);
  7840. $modalInstance.close(false);
  7841. })
  7842. } else {
  7843. toaster.pop('error', '保存失败', "您未勾选任何记录");
  7844. }
  7845. } else {
  7846. $modalInstance.close(true, $scope.checkboxes.checked);
  7847. }
  7848. } else {
  7849. $modalInstance.close(false);
  7850. }
  7851. };
  7852. }]);
  7853. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  7854. $scope.checked = [];
  7855. $scope.master = [];
  7856. AccountRole.query({}, function(data){
  7857. if(user && data) {
  7858. var rs = [], checked = [];
  7859. angular.forEach(user.roles, function(r){
  7860. rs.push(r.id);
  7861. });
  7862. angular.forEach(data, function(d){
  7863. if(rs.indexOf(d.id) > -1) {
  7864. d.$checked = true;
  7865. checked.push(d);
  7866. }
  7867. });
  7868. }
  7869. $scope.roles = data;
  7870. $scope.checked = checked;
  7871. $scope.master = angular.copy($scope.checked);
  7872. });
  7873. $scope.select = function(role) {
  7874. role.$checked = !role.$checked;
  7875. if(role.$checked) {
  7876. $scope.checked.push(role);
  7877. } else {
  7878. angular.forEach($scope.checked, function(c, i){
  7879. if(c.id == role.id)
  7880. $scope.checked.splice(i, 1);
  7881. });
  7882. }
  7883. };
  7884. $scope.isChanged = function() {
  7885. return !angular.equals($scope.master, $scope.checked);
  7886. };
  7887. $scope.close = function(save) {
  7888. if(save) {
  7889. if(user.userUU) {
  7890. user.roles = $scope.checked;
  7891. AccountUser.update({}, user, function(){
  7892. toaster.pop('success', '提示', '保存成功');
  7893. $modalInstance.close(true);
  7894. }, function(response){
  7895. toaster.pop('error', '保存失败', response.data);
  7896. });
  7897. } else {
  7898. $modalInstance.close(true, $scope.checked);
  7899. }
  7900. } else {
  7901. $modalInstance.close(false);
  7902. }
  7903. };
  7904. }]);
  7905. // 修改密码Controller
  7906. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7907. $scope.user = user;
  7908. $scope.checking = false;
  7909. //输入原密码后验证原密码是否正确
  7910. $scope.checkPassword = function(password) {
  7911. $scope.checking = true;
  7912. $scope.checkSuccess = false;
  7913. $scope.checkFailed = false;
  7914. AccountUser.checkPassword({password: password}, function(data){
  7915. $scope.checkSuccess = true;
  7916. $scope.checking = false;
  7917. $scope.checkFailed = false;
  7918. }, function(response){
  7919. $scope.checkFailed = true;
  7920. $scope.checking = false;
  7921. $scope.checkSuccess = false;
  7922. });
  7923. };
  7924. //修改密码
  7925. $scope.ok = function () {
  7926. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  7927. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  7928. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  7929. toaster.pop('success', '成功', tip);
  7930. $scope.user.password = null;
  7931. $scope.user.newPassword = null;
  7932. $scope.user.newPassword1 = null;
  7933. $scope.checking = false;
  7934. $scope.checkSuccess = false;
  7935. $scope.checkFailed = false;
  7936. }, function(response){
  7937. toaster.pop('error', '错误', response.data);
  7938. });
  7939. } else {
  7940. toaster.pop('error', '错误', '重复密码不一致');
  7941. }
  7942. };
  7943. $scope.cancel = function () {
  7944. $modalInstance.dismiss();
  7945. };
  7946. }]);
  7947. /*
  7948. * 绑定用户到企业
  7949. */
  7950. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster){
  7951. $scope.searching = false;
  7952. //根据输入的内容查找用户
  7953. $scope.searchUser = function(keyWord) {
  7954. $scope.searching = true;
  7955. $scope.searchSuccess = false;
  7956. $scope.searchFailed = false;
  7957. $scope.illegalError = false;
  7958. $scope.reBindError = false;
  7959. $scope.okDisabled = false;
  7960. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  7961. $scope.searchSuccess = true;
  7962. $scope.searchFailed = false;
  7963. $scope.user = data; //查询到的用户
  7964. }, function(response){
  7965. $scope.searchSuccess = false;
  7966. $scope.searchFailed = true;
  7967. });
  7968. };
  7969. //确认绑定
  7970. $scope.ok = function (keyWord) {
  7971. AuthenticationService.getAuthentication().success(function(data) {
  7972. $scope.currentUser = data; //当前登录的用户(管理员)
  7973. //不可自己绑定自己
  7974. if($scope.currentUser.userUU == $scope.user.userUU){
  7975. $scope.illegalError = true;
  7976. $scope.okDisabled = true;
  7977. return false;
  7978. }
  7979. //用户未绑定到任何企业时
  7980. if(!$scope.user.enterprises){
  7981. //正常绑定
  7982. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  7983. $scope.okDisabled = true;
  7984. toaster.pop("success", "提示", "用户绑定成功");
  7985. $modalInstance.close(true);
  7986. }, function(response){
  7987. });
  7988. return true;
  7989. }
  7990. //用户已绑定到某些企业时
  7991. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  7992. if($scope.currentUser.enterprises[i].current){
  7993. for(var j = 0; j < $scope.user.enterprises.length; j++){
  7994. //该用户已绑定到当前企业,不可重复绑定
  7995. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  7996. $scope.reBindError = true;
  7997. $scope.okDisabled = true;
  7998. return false;
  7999. }
  8000. }
  8001. //该用户未绑定到当前企业,可以进行绑定
  8002. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  8003. $scope.okDisabled = true;
  8004. toaster.pop("success", "提示", "用户绑定成功");
  8005. $modalInstance.close(true);
  8006. }, function(response){
  8007. console.log("绑定失败!");
  8008. });
  8009. }
  8010. }
  8011. });
  8012. };
  8013. $scope.cancel = function () {
  8014. $modalInstance.dismiss();
  8015. };
  8016. }]);
  8017. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  8018. $scope.erpParams = new ngTableParams({
  8019. page : 1,
  8020. count : 5,
  8021. sorting: {
  8022. time: 'desc'
  8023. }
  8024. }, {
  8025. total : 0,
  8026. counts: [5, 10, 25, 50],
  8027. getData : function($defer, params) {
  8028. $scope.loading = true;
  8029. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  8030. $scope.loading = false;
  8031. if(page) {
  8032. params.total(page.totalElements);
  8033. $defer.resolve(page.content);
  8034. }
  8035. }, function(response){
  8036. $scope.loading = false;
  8037. toaster.pop('error', '数据加载失败', response.data);
  8038. });
  8039. }
  8040. });
  8041. $scope.usageParams = new ngTableParams({
  8042. page : 1,
  8043. count : 5,
  8044. sorting: {
  8045. time: 'desc'
  8046. }
  8047. }, {
  8048. total : 0,
  8049. counts: [5, 10, 25, 50],
  8050. getData : function($defer, params) {
  8051. $scope.loading = true;
  8052. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  8053. $scope.loading = false;
  8054. if(page) {
  8055. params.total(page.totalElements);
  8056. $defer.resolve(page.content);
  8057. }
  8058. }, function(response){
  8059. $scope.loading = false;
  8060. toaster.pop('error', '数据加载失败', response.data);
  8061. });
  8062. }
  8063. });
  8064. }]);
  8065. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  8066. AccountResource.query({}, function(data){
  8067. if(data && data.length > 0) {
  8068. data[0].$open = true;
  8069. }
  8070. $scope.resources = data;
  8071. });
  8072. }]);
  8073. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  8074. $scope.roles = {};
  8075. var getData = function() {
  8076. AccountRole.query({}, function(data){
  8077. var defaults = [], custom = [];
  8078. angular.forEach(data, function(d){
  8079. if(d.isdefault == 1)
  8080. defaults.push(d);
  8081. else
  8082. custom.push(d);
  8083. });
  8084. $scope.roles = {defaults: defaults, custom: custom};
  8085. });
  8086. };
  8087. getData();
  8088. $scope.editRole = function(role){
  8089. var modalInstance = $modal.open({
  8090. animation: true,
  8091. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  8092. controller: 'RoleEditCtrl',
  8093. resolve: {
  8094. role: function() {
  8095. return role;
  8096. }
  8097. }
  8098. });
  8099. modalInstance.result.then(function(added){
  8100. added && (getData());
  8101. });
  8102. };
  8103. }]);
  8104. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  8105. BaseService.scrollBackToTop();
  8106. $scope.role = role;
  8107. $scope.master = angular.copy($scope.role);
  8108. var isNew = role == null;
  8109. $scope.cancel = function() {
  8110. $modalInstance.close(false);
  8111. };
  8112. AccountResource.query({}, function(data){
  8113. if(data && data.length > 0) {
  8114. if(role && role.resourceItems) {
  8115. var rs = [];// 已分配的资源的id
  8116. angular.forEach(role.resourceItems, function(item){
  8117. rs.push(item.id);
  8118. });
  8119. angular.forEach(data, function(resource){
  8120. var c = 0;
  8121. angular.forEach(resource.items, function(item){
  8122. if(rs.indexOf(item.id) > -1) {
  8123. item.$checked = true;
  8124. c += 1;
  8125. }
  8126. });
  8127. resource.$checked = c == resource.items.length;
  8128. });
  8129. }
  8130. $scope.resourceItems = data[0].items;
  8131. data[0].$active = true;
  8132. }
  8133. $scope.resources = data;
  8134. $timeout(function(){
  8135. angular.forEach($scope.resources, function(resource){
  8136. var c = 0;
  8137. angular.forEach(resource.items, function(item){
  8138. item.$checked && (c+=1);
  8139. });
  8140. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8141. });
  8142. }, 100);
  8143. });
  8144. $scope.onItemClick = function(resource) {
  8145. $scope.resourceItems = resource.items;
  8146. angular.forEach($scope.resources, function(r){
  8147. r.$active = false;
  8148. });
  8149. resource.$active = true;
  8150. };
  8151. var getChecked = function() {
  8152. var items = [];
  8153. angular.forEach($scope.resources, function(resource){
  8154. angular.forEach(resource.items, function(item){
  8155. item.$checked && (items.push(item));
  8156. });
  8157. });
  8158. $scope.role.resourceItems = items;
  8159. };
  8160. $scope.onResourceChange = function(resource) {
  8161. angular.forEach(resource.items, function(item){
  8162. item.$checked = resource.$checked;
  8163. });
  8164. getChecked();
  8165. };
  8166. $scope.onItemChange = function() {
  8167. angular.forEach($scope.resources, function(resource){
  8168. if(resource.$active) {
  8169. var c = 0;
  8170. angular.forEach(resource.items, function(item){
  8171. item.$checked && (c+=1);
  8172. });
  8173. resource.$checked = (c == resource.items.length);
  8174. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8175. }
  8176. });
  8177. getChecked();
  8178. };
  8179. $scope.isChanged = function(formData) {
  8180. if(!$scope.master)
  8181. return true;
  8182. return !angular.equals(formData, $scope.master);
  8183. };
  8184. $scope.save = function() {
  8185. $scope.master = angular.copy($scope.role);
  8186. AccountRole.save($scope.master, function(){
  8187. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  8188. $modalInstance.close(true);
  8189. }, function(response){
  8190. toaster.pop('error', '错误', response.data);
  8191. });
  8192. };
  8193. $scope.del = function() {
  8194. new ngAlert({
  8195. title: '提示',
  8196. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  8197. }, function(){
  8198. AccountRole.remove({id: role.id}, function(){
  8199. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  8200. $modalInstance.close(true);
  8201. }, function(response){
  8202. toaster.pop('error', '错误', response.data);
  8203. });
  8204. })
  8205. };
  8206. }]);
  8207. /**
  8208. * 委外订单
  8209. */
  8210. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  8211. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  8212. BaseService.scrollBackToTop();
  8213. $scope.active = 'todo';
  8214. $scope.dateZoneText = '不限';
  8215. $scope.condition = {dateZone: -1};
  8216. $scope.nowdate = new Date();
  8217. $scope.changeDateZone = function(zone) {
  8218. $scope.condition.dateZone = zone;
  8219. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  8220. $scope.condition.$dateZoneOpen = false;
  8221. getDateCondition(zone, $scope.condition);
  8222. $scope.tableParams.reload();
  8223. };
  8224. $scope.setActive = function(state) {
  8225. if($scope.active != state) {
  8226. $scope.active = state;
  8227. if($scope.tableParams.page() == 1)
  8228. $scope.tableParams.reload();
  8229. else
  8230. $scope.tableParams.page(1);
  8231. }
  8232. };
  8233. var getService = function() {
  8234. return MakeOrder;
  8235. };
  8236. $scope.tableParams = new ngTableParams({
  8237. page : 1,
  8238. count : 5,
  8239. sorting: {
  8240. date: 'desc'
  8241. }
  8242. }, {
  8243. total : 0,
  8244. counts: [5, 10, 25, 50],
  8245. getData : function($defer, params) {
  8246. $scope.loading = true;
  8247. var pageParams = params.url();
  8248. pageParams.searchFilter = {};
  8249. pageParams.searchFilter.keyword = $scope.keyword;
  8250. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8251. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8252. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8253. $scope.loading = false;
  8254. if(page) {
  8255. params.total(page.totalElement);
  8256. $defer.resolve(page.content);
  8257. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8258. }
  8259. }, function(response){
  8260. $scope.loading = false;
  8261. toaster.pop('error', '数据加载失败', response.data);
  8262. });
  8263. }
  8264. });
  8265. $scope.getOrderTotal = function(items) {
  8266. var sum = 0;
  8267. angular.forEach(items, function(item){
  8268. sum += item.qty * item.price;
  8269. });
  8270. return sum;
  8271. };
  8272. $scope.openDatePicker = function($event, item, openParam) {
  8273. $event.preventDefault();
  8274. $event.stopPropagation();
  8275. item[openParam] = !item[openParam];
  8276. };
  8277. $scope.parseDate = function(dateStr) {
  8278. if(dateStr)
  8279. return Date.parse(dateStr, 'yyyy-MM-dd');
  8280. return new Date();
  8281. };
  8282. // 打开回复
  8283. $scope.openReply = function(order) {
  8284. if(!order.reply) {
  8285. order.reply = {
  8286. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8287. delivery: order.delivery
  8288. }
  8289. }
  8290. order.$editing = true;
  8291. };
  8292. // 关闭回复
  8293. $scope.closeReply = function(order) {
  8294. order.$editing = false;
  8295. }
  8296. // 搜索框回车
  8297. $scope.onSearch = function() {
  8298. $scope.tableParams.page(1);
  8299. $scope.tableParams.reload();
  8300. };
  8301. // 选择查找日期
  8302. $scope.onDateCondition = function(){
  8303. $scope.tableParams.page(1);
  8304. $scope.tableParams.reload();
  8305. };
  8306. // 点击回复
  8307. $scope.onReplyClick = function(order, inverse) {
  8308. if(order.reply) {
  8309. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8310. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8311. return;
  8312. }
  8313. var reply = angular.copy(order.reply);
  8314. if(reply.delivery) {
  8315. if(typeof reply.delivery == 'object')
  8316. reply.delivery = reply.delivery.getTime();
  8317. } else {
  8318. reply.delivery = order.delivery;
  8319. }
  8320. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8321. $scope.loading = true;
  8322. MakeOrder.reply({orderId: order.id}, reply, function(){
  8323. $scope.loading = false;
  8324. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8325. $scope.tableParams.reload();
  8326. }, function(response){
  8327. $scope.loading = false;
  8328. toaster.pop('error', '回复失败', response.data);
  8329. });
  8330. }
  8331. };
  8332. //委外加工单
  8333. $scope.print = function(order) {
  8334. MakeOrder.printCount({id: order.id},{});//增加打印此次
  8335. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  8336. };
  8337. // 获取回复记录
  8338. $scope.getReply = function(order) {
  8339. if(!order.replies) {
  8340. MakeOrder.getReply({orderId: order.id}, function(replies){
  8341. order.replies = replies;
  8342. });
  8343. }
  8344. };
  8345. }]);
  8346. /**
  8347. * 委外加工单详细
  8348. */
  8349. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  8350. BaseService.scrollBackToTop();
  8351. var loadData = function() {
  8352. MakeOrder.get({id: $stateParams.id}, function(data){
  8353. $scope.order = data;
  8354. var sum = $scope.order.qty * $scope.order.price;
  8355. $scope.order.total = sum;
  8356. $scope.loading = false;
  8357. });
  8358. };
  8359. loadData();
  8360. // 获取回复记录
  8361. $scope.getReply = function(item) {
  8362. if(!item.replies) {
  8363. MakeOrder.getReply({orderId: item.id}, function(replies){
  8364. item.replies = replies;
  8365. });
  8366. }
  8367. };
  8368. $scope.openDatePicker = function($event, item, openParam) {
  8369. $event.preventDefault();
  8370. $event.stopPropagation();
  8371. item[openParam] = !item[openParam];
  8372. };
  8373. // 点击回复
  8374. $scope.onReplyClick = function(order, inverse) {
  8375. if(order.reply) {
  8376. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8377. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8378. return;
  8379. }
  8380. var reply = angular.copy(order.reply);
  8381. if(reply.delivery) {
  8382. if(typeof reply.delivery == 'object')
  8383. reply.delivery = reply.delivery.getTime();
  8384. } else {
  8385. reply.delivery = order.delivery;
  8386. }
  8387. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8388. $scope.loading = true;
  8389. MakeOrder.reply({orderId: order.id}, reply, function(){
  8390. $scope.loading = false;
  8391. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8392. loadData();
  8393. }, function(response){
  8394. $scope.loading = false;
  8395. toaster.pop('error', '回复失败', response.data);
  8396. });
  8397. }
  8398. };
  8399. // 打开回复
  8400. $scope.openReply = function(order) {
  8401. if(!order.reply) {
  8402. order.reply = {
  8403. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8404. delivery: order.delivery
  8405. }
  8406. }
  8407. order.$editing = true;
  8408. };
  8409. // 关闭回复
  8410. $scope.closeReply = function(order) {
  8411. order.$editing = false;
  8412. }
  8413. // 委外订单
  8414. $scope.print = function(order) {
  8415. MakeOrder.printCount({id: order.id},{});//增加打印此次
  8416. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  8417. };
  8418. }]);
  8419. /**
  8420. * 客户委外验收
  8421. */
  8422. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  8423. BaseService.scrollBackToTop();
  8424. $scope.active = 'all';
  8425. $scope.agreedText = '全部';
  8426. $scope.dateZoneText = '一个月内';
  8427. $scope.condition = {dateZone: 1};
  8428. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8429. $scope.changeAgreed = function(agreed) {
  8430. $scope.condition.agreed = agreed;
  8431. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8432. $scope.condition.$agreedOpen = false;
  8433. };
  8434. $scope.changeDateZone = function(zone) {
  8435. $scope.condition.dateZone = zone;
  8436. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8437. $scope.condition.$dateZoneOpen = false;
  8438. getDateCondition(zone, $scope.condition);
  8439. $scope.tableParams.reload();
  8440. };
  8441. $scope.setActive = function(state) {
  8442. if($scope.active != state) {
  8443. $scope.active = state;
  8444. if($scope.tableParams.page() == 1)
  8445. $scope.tableParams.reload();
  8446. else
  8447. $scope.tableParams.page(1);
  8448. }
  8449. };
  8450. var getService = function() {
  8451. return MakeAccept;
  8452. };
  8453. $scope.tableParams = new ngTableParams({
  8454. page : 1,
  8455. count : 5,
  8456. sorting: {
  8457. date: 'desc'
  8458. }
  8459. }, {
  8460. total : 0,
  8461. counts: [5, 10, 25, 50],
  8462. getData : function($defer, params) {
  8463. $scope.loading = true;
  8464. var pageParams = params.url();
  8465. pageParams.searchFilter = {};
  8466. pageParams.searchFilter.keyword = $scope.keyword;
  8467. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8468. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8469. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8470. $scope.loading = false;
  8471. if(page) {
  8472. params.total(page.totalElement);
  8473. $defer.resolve(page.content);
  8474. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8475. }
  8476. }, function(response){
  8477. $scope.loading = false;
  8478. toaster.pop('error', '数据加载失败', response.data);
  8479. });
  8480. }
  8481. });
  8482. $scope.openDatePicker = function($event, item, openParam) {
  8483. $event.preventDefault();
  8484. $event.stopPropagation();
  8485. item[openParam] = !item[openParam];
  8486. };
  8487. // 搜索框回车
  8488. $scope.onSearch = function() {
  8489. $scope.tableParams.page(1);
  8490. $scope.tableParams.reload();
  8491. };
  8492. // 选择查找日期
  8493. $scope.onDateCondition = function(){
  8494. $scope.tableParams.page(1);
  8495. $scope.tableParams.reload();
  8496. };
  8497. }]);
  8498. /**
  8499. * 客户委外验退
  8500. */
  8501. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  8502. BaseService.scrollBackToTop();
  8503. $scope.active = 'all';
  8504. $scope.agreedText = '全部';
  8505. $scope.dateZoneText = '一个月内';
  8506. $scope.condition = {dateZone: 1};
  8507. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8508. $scope.changeAgreed = function(agreed) {
  8509. $scope.condition.agreed = agreed;
  8510. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8511. $scope.condition.$agreedOpen = false;
  8512. };
  8513. $scope.changeDateZone = function(zone) {
  8514. $scope.condition.dateZone = zone;
  8515. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8516. $scope.condition.$dateZoneOpen = false;
  8517. getDateCondition(zone, $scope.condition);
  8518. $scope.tableParams.reload();
  8519. };
  8520. $scope.setActive = function(state) {
  8521. if($scope.active != state) {
  8522. $scope.active = state;
  8523. if($scope.tableParams.page() == 1)
  8524. $scope.tableParams.reload();
  8525. else
  8526. $scope.tableParams.page(1);
  8527. }
  8528. };
  8529. var getService = function() {
  8530. return MakeReturn;
  8531. };
  8532. $scope.tableParams = new ngTableParams({
  8533. page : 1,
  8534. count : 5,
  8535. sorting: {
  8536. date: 'desc'
  8537. }
  8538. }, {
  8539. total : 0,
  8540. counts: [5, 10, 25, 50],
  8541. getData : function($defer, params) {
  8542. $scope.loading = true;
  8543. var pageParams = params.url();
  8544. pageParams.searchFilter = {};
  8545. pageParams.searchFilter.keyword = $scope.keyword;
  8546. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8547. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8548. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8549. $scope.loading = false;
  8550. if(page) {
  8551. params.total(page.totalElement);
  8552. $defer.resolve(page.content);
  8553. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8554. }
  8555. }, function(response){
  8556. $scope.loading = false;
  8557. toaster.pop('error', '数据加载失败', response.data);
  8558. });
  8559. }
  8560. });
  8561. $scope.openDatePicker = function($event, item, openParam) {
  8562. $event.preventDefault();
  8563. $event.stopPropagation();
  8564. item[openParam] = !item[openParam];
  8565. };
  8566. // 搜索框回车
  8567. $scope.onSearch = function() {
  8568. $scope.tableParams.page(1);
  8569. $scope.tableParams.reload();
  8570. };
  8571. // 选择查找日期
  8572. $scope.onDateCondition = function(){
  8573. $scope.tableParams.page(1);
  8574. $scope.tableParams.reload();
  8575. };
  8576. }]);
  8577. /**
  8578. * 委外加工变更
  8579. */
  8580. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  8581. BaseService.scrollBackToTop();
  8582. $scope.active = 'all';
  8583. $scope.agreedText = '全部';
  8584. $scope.dateZoneText = '一个月内';
  8585. $scope.condition = {dateZone: 1};
  8586. $scope.changeAgreed = function(agreed) {
  8587. $scope.condition.agreed = agreed;
  8588. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8589. $scope.condition.$agreedOpen = false;
  8590. };
  8591. $scope.changeDateZone = function(zone) {
  8592. $scope.condition.dateZone = zone;
  8593. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8594. $scope.condition.$dateZoneOpen = false;
  8595. getDateCondition(zone, $scope.condition);
  8596. $scope.tableParams.reload();
  8597. };
  8598. $scope.setActive = function(state) {
  8599. if($scope.active != state) {
  8600. $scope.active = state;
  8601. if($scope.tableParams.page() == 1)
  8602. $scope.tableParams.reload();
  8603. else
  8604. $scope.tableParams.page(1);
  8605. }
  8606. };
  8607. var getService = function() {
  8608. return MakeChange;
  8609. };
  8610. $scope.tableParams = new ngTableParams({
  8611. page : 1,
  8612. count : 5,
  8613. sorting: {
  8614. orderChangeDate: 'desc'
  8615. }
  8616. }, {
  8617. total : 0,
  8618. counts: [5, 10, 25, 50],
  8619. getData : function($defer, params) {
  8620. $scope.loading = true;
  8621. var pageParams = params.url();
  8622. pageParams.searchFilter = {};
  8623. pageParams.searchFilter.keyword = $scope.keyword;
  8624. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8625. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8626. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8627. $scope.loading = false;
  8628. if(page) {
  8629. params.total(page.totalElement);
  8630. $defer.resolve(page.content);
  8631. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8632. }
  8633. }, function(response){
  8634. $scope.loading = false;
  8635. toaster.pop('error', '数据加载失败', response.data);
  8636. });
  8637. }
  8638. });
  8639. $scope.openDatePicker = function($event, item, openParam) {
  8640. $event.preventDefault();
  8641. $event.stopPropagation();
  8642. item[openParam] = !item[openParam];
  8643. };
  8644. // 打开回复
  8645. $scope.openReply = function(change) {
  8646. change.$editing = true;
  8647. };
  8648. // 关闭回复
  8649. $scope.closeReply = function(change) {
  8650. change.$editing = false;
  8651. }
  8652. // 确定回复
  8653. $scope.onReplyClick = function(change) {
  8654. if(change.$agreed) {
  8655. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8656. $scope.loading = true;
  8657. MakeChange.reply({itemId: change.id}, reply, function(){
  8658. $scope.loading = false;
  8659. toaster.pop('info', '提示', '回复成功');
  8660. $scope.tableParams.reload();
  8661. }, function(response){
  8662. $scope.loading = false;
  8663. toaster.pop('error', '回复失败', response.data);
  8664. });
  8665. }
  8666. };
  8667. // 搜索框回车
  8668. $scope.onSearch = function() {
  8669. $scope.tableParams.page(1);
  8670. $scope.tableParams.reload();
  8671. };
  8672. // 选择查找日期
  8673. $scope.onDateCondition = function(){
  8674. $scope.tableParams.page(1);
  8675. $scope.tableParams.reload();
  8676. };
  8677. }]);
  8678. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  8679. BaseService.scrollBackToTop();
  8680. var loadData = function() {
  8681. MakeChange.get({id: $stateParams.id}, function(data){
  8682. $scope.change = data;
  8683. });
  8684. };
  8685. loadData();
  8686. $scope.openDatePicker = function($event, item, openParam) {
  8687. $event.preventDefault();
  8688. $event.stopPropagation();
  8689. item[openParam] = !item[openParam];
  8690. };
  8691. $scope.onReplyClick = function(change) {
  8692. if(change.$agreed) {
  8693. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8694. MakeChange.reply({itemId: change.id}, reply, function(){
  8695. toaster.pop('info', '提示', '回复成功');
  8696. loadData();
  8697. }, function(response){
  8698. toaster.pop('error', '回复失败', response.data);
  8699. });
  8700. }
  8701. };
  8702. }]);
  8703. /**
  8704. * 委外加工
  8705. */
  8706. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  8707. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  8708. BaseService.scrollBackToTop();
  8709. $scope.active = 'all';
  8710. $scope.agreedText = '全部';
  8711. $scope.dateZoneText = '一个月内';
  8712. $scope.condition = {dateZone: 1};
  8713. $scope.changeAgreed = function(agreed) {
  8714. $scope.condition.agreed = agreed;
  8715. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8716. $scope.condition.$agreedOpen = false;
  8717. };
  8718. $scope.changeDateZone = function(zone) {
  8719. $scope.condition.dateZone = zone;
  8720. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8721. $scope.condition.$dateZoneOpen = false;
  8722. getDateCondition(zone, $scope.condition);
  8723. $scope.tableParams.reload();
  8724. };
  8725. $scope.setActive = function(state) {
  8726. if($scope.active != state) {
  8727. $scope.active = state;
  8728. if($scope.tableParams.page() == 1)
  8729. $scope.tableParams.reload();
  8730. else
  8731. $scope.tableParams.page(1);
  8732. }
  8733. };
  8734. var getService = function() {
  8735. return MakeOutOrder;
  8736. };
  8737. $scope.tableParams = new ngTableParams({
  8738. page : 1,
  8739. count : 5,
  8740. sorting: {
  8741. date: 'desc'
  8742. }
  8743. }, {
  8744. total : 0,
  8745. counts: [5, 10, 25, 50],
  8746. getData : function($defer, params) {
  8747. $scope.loading = true;
  8748. var pageParams = params.url();
  8749. pageParams.searchFilter = {};
  8750. pageParams.searchFilter.keyword = $scope.keyword;
  8751. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8752. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8753. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8754. $scope.loading = false;
  8755. if(page) {
  8756. params.total(page.totalElement);
  8757. $defer.resolve(page.content);
  8758. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8759. }
  8760. }, function(response){
  8761. $scope.loading = false;
  8762. toaster.pop('error', '数据加载失败', response.data);
  8763. });
  8764. }
  8765. });
  8766. $scope.openDatePicker = function($event, item, openParam) {
  8767. $event.preventDefault();
  8768. $event.stopPropagation();
  8769. item[openParam] = !item[openParam];
  8770. };
  8771. // 打开回复
  8772. $scope.openReply = function(change) {
  8773. change.$editing = true;
  8774. };
  8775. // 关闭回复
  8776. $scope.closeReply = function(change) {
  8777. change.$editing = false;
  8778. }
  8779. // 确定回复
  8780. $scope.onReplyClick = function(change) {
  8781. if(change.$agreed) {
  8782. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  8783. $scope.loading = true;
  8784. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  8785. $scope.loading = false;
  8786. toaster.pop('info', '提示', '回复成功');
  8787. $scope.tableParams.reload();
  8788. }, function(response){
  8789. $scope.loading = false;
  8790. toaster.pop('error', '回复失败', response.data);
  8791. });
  8792. }
  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('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  8809. BaseService.scrollBackToTop();
  8810. var loadData = function() {
  8811. MakeOutOrder.get({id: $stateParams.id}, function(data){
  8812. $scope.order = data;
  8813. var sum = $scope.order.qty * $scope.order.price;
  8814. $scope.order.total = sum;
  8815. $scope.loading = false;
  8816. });
  8817. };
  8818. loadData();
  8819. // 获取回复记录
  8820. $scope.getReply = function(item) {
  8821. if(!item.replies) {
  8822. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  8823. item.replies = replies;
  8824. });
  8825. }
  8826. };
  8827. $scope.openDatePicker = function($event, item, openParam) {
  8828. $event.preventDefault();
  8829. $event.stopPropagation();
  8830. item[openParam] = !item[openParam];
  8831. };
  8832. // 点击回复
  8833. $scope.onReplyClick = function(order, inverse) {
  8834. if(order.reply) {
  8835. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  8836. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  8837. return;
  8838. }
  8839. var reply = angular.copy(order.reply);
  8840. if(reply.delivery) {
  8841. if(typeof reply.delivery == 'object')
  8842. reply.delivery = reply.delivery.getTime();
  8843. } else {
  8844. reply.delivery = order.delivery;
  8845. }
  8846. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  8847. $scope.loading = true;
  8848. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  8849. $scope.loading = false;
  8850. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  8851. loadData();
  8852. }, function(response){
  8853. $scope.loading = false;
  8854. toaster.pop('error', '回复失败', response.data);
  8855. });
  8856. }
  8857. };
  8858. // 打开回复
  8859. $scope.openReply = function(order) {
  8860. if(!order.reply) {
  8861. order.reply = {
  8862. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  8863. delivery: order.delivery
  8864. }
  8865. }
  8866. order.$editing = true;
  8867. };
  8868. // 关闭回复
  8869. $scope.closeReply = function(order) {
  8870. order.$editing = false;
  8871. }
  8872. // 自己委外加工订单
  8873. $scope.print = function(order) {
  8874. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  8875. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  8876. };
  8877. }]);
  8878. /**
  8879. * 计算时间差
  8880. */
  8881. app.filter('timespan', function(){
  8882. return function(time) {
  8883. if(time == null)
  8884. return '9999年';
  8885. var now = new Date().getTime(), span = time - now,
  8886. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  8887. m = Math.ceil(span/60000);
  8888. if(span < 0)
  8889. return '1天';
  8890. if(d > 0)
  8891. return d+1 + '天';
  8892. if(h > 0)
  8893. return h + '小时';
  8894. if(m > 0)
  8895. return m + '分钟';
  8896. return '0天';
  8897. };
  8898. });
  8899. app.filter('firstchar', function(){
  8900. return function(str) {
  8901. if(str == null)
  8902. return null;
  8903. return str.substring(0, 1);
  8904. };
  8905. });
  8906. app.filter('summary', function(){
  8907. return function(data, field) {
  8908. var sum = 0;
  8909. if (data) {
  8910. angular.forEach(data, function(d){
  8911. sum += d[field];
  8912. });
  8913. }
  8914. return sum;
  8915. };
  8916. });
  8917. /**
  8918. * 搜索框,回车触发
  8919. */
  8920. app.directive('ngSearch', ['$parse', function($parse) {
  8921. return {
  8922. require : '?ngModel',
  8923. restrict : 'A',
  8924. link : function(scope, element, attrs, ngModel) {
  8925. var searchFn = $parse(attrs.ngSearch);
  8926. element.bind('keypress', function(event) {
  8927. if (event.keyCode == '13') {
  8928. event.preventDefault();
  8929. event.stopPropagation();
  8930. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  8931. }
  8932. });
  8933. }
  8934. };
  8935. }]);
  8936. /**
  8937. * 状态码 -> 描述
  8938. */
  8939. app.filter('status', function(){
  8940. return function(data) {
  8941. var statusConfig = {
  8942. '101': '已提交',
  8943. '102': '已审核',
  8944. '103': '未通过',
  8945. '200': '未回复',
  8946. '201': '已回复',
  8947. '313': '已激活',
  8948. '316': '已过账',
  8949. '311': '申请中',
  8950. '312': '未激活'
  8951. };
  8952. return statusConfig[data];
  8953. }
  8954. });
  8955. //弹出问题反馈模态框
  8956. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  8957. //获取当前用户
  8958. AuthenticationService.getAuthentication().success(function(data) {
  8959. $scope.user = data;
  8960. });
  8961. $scope.showModal = function(){
  8962. var modalInstance = $modal.open({
  8963. animation: true,
  8964. templateUrl: 'static/tpl/serve/feedback.html',
  8965. controller: 'FeedbackCtrl',
  8966. resolve: {
  8967. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  8968. }
  8969. });
  8970. modalInstance.result.then(function(){
  8971. }, function(){
  8972. })
  8973. }
  8974. }]);
  8975. /*
  8976. * 提交我的反馈
  8977. */
  8978. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  8979. $scope.isPublic = 1; //默认公开
  8980. $scope.classId = 1; //默认类别
  8981. $scope.user = user;
  8982. $scope.ok = function(){
  8983. if(!$scope.user){ //用户未登录
  8984. $scope.uu = null;
  8985. }else{ //用户已登录
  8986. $scope.uu = $scope.user.userUU;
  8987. }
  8988. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  8989. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  8990. function(data){
  8991. toaster.pop('success', '成功', '您的问题反馈成功!');
  8992. $scope.cancel();
  8993. }, function(response){
  8994. toaster.pop('error', '错误', response.data);
  8995. });
  8996. }
  8997. $scope.cancel = function () {
  8998. $modalInstance.dismiss();
  8999. };
  9000. }]);
  9001. //“我的问题反馈”跳转控制
  9002. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  9003. $scope.myFeedback = function(){
  9004. AuthenticationService.getAuthentication().success(function(data){
  9005. $scope.user = data;
  9006. if(!$scope.user){
  9007. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  9008. return false;
  9009. }else{
  9010. window.location.href = "./serve#/question/myFeedback";
  9011. }
  9012. });
  9013. }
  9014. }]);
  9015. //客户服务
  9016. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  9017. Vendor.getServe(function(datas){
  9018. $scope.vendors = datas;
  9019. // 自动跳转
  9020. if(datas && datas.length == 1)
  9021. $scope.redirect(datas[0]);
  9022. });
  9023. $scope.redirect = function(vendor) {
  9024. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  9025. };
  9026. }]);
  9027. /**
  9028. * 物料资料
  9029. */
  9030. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  9031. BaseService.scrollBackToTop();
  9032. $scope.active = 'all';
  9033. $scope.agreedText = '全部';
  9034. $scope.dateZoneText = '一个月内';
  9035. $scope.condition = {dateZone: 1};
  9036. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9037. $scope.changeAgreed = function(agreed) {
  9038. $scope.condition.agreed = agreed;
  9039. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9040. $scope.condition.$agreedOpen = false;
  9041. };
  9042. $scope.changeDateZone = function(zone) {
  9043. $scope.condition.dateZone = zone;
  9044. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9045. $scope.condition.$dateZoneOpen = false;
  9046. getDateCondition(zone, $scope.condition);
  9047. $scope.tableParams.reload();
  9048. };
  9049. $scope.setActive = function(state) {
  9050. if($scope.active != state) {
  9051. $scope.active = state;
  9052. if($scope.tableParams.page() == 1)
  9053. $scope.tableParams.reload();
  9054. else
  9055. $scope.tableParams.page(1);
  9056. }
  9057. };
  9058. var getService = function() {
  9059. return GetProductInfo;
  9060. };
  9061. $scope.tableParams = new ngTableParams({
  9062. page : 1,
  9063. count : 5,
  9064. sorting: {
  9065. }
  9066. }, {
  9067. total : 0,
  9068. counts: [5, 10, 25, 50],
  9069. getData : function($defer, params) {
  9070. $scope.loading = true;
  9071. var pageParams = params.url();
  9072. pageParams.keyword = $scope.keyword;
  9073. pageParams.searchFilter = $scope.searchFilter;
  9074. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9075. $scope.loading = false;
  9076. if(page) {
  9077. params.total(page.totalElement);
  9078. $defer.resolve(page.content);
  9079. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9080. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  9081. }
  9082. }, function(response) {
  9083. $scope.loading = false;
  9084. toaster.pop('error', '数据加载失败', response.data);
  9085. });
  9086. }
  9087. });
  9088. // 搜索框回车
  9089. $scope.onSearch = function() {
  9090. $scope.tableParams.page(1);
  9091. $scope.tableParams.reload();
  9092. };
  9093. //删除
  9094. $scope.deleteById = function(id) {
  9095. GetProductInfo.deleteById({id: id}, function(data) {
  9096. if(data.error) {
  9097. toaster.pop("error", "提示", data.error);
  9098. } else {
  9099. toaster.pop("success", "提示", "删除成功");
  9100. $timeout(function() {
  9101. $scope.tableParams.reload();
  9102. }, 500);
  9103. }
  9104. }), function(response) {
  9105. toaster.pop("error", "删除失败", response.data);
  9106. };
  9107. }
  9108. }]);
  9109. /**
  9110. * 物料批量上传
  9111. */
  9112. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  9113. BaseService.scrollBackToTop();
  9114. // 通过excel批量上传物料
  9115. $scope.upload = function() {
  9116. if($scope.myFiles) {
  9117. var file = $scope.myFiles[0];
  9118. if(file.name) {
  9119. $upload.upload({
  9120. url: 'product/baseInfo/release/excel',
  9121. file: file,
  9122. method: 'POST'
  9123. }).success(function(data) {
  9124. $scope.result = data;
  9125. $scope.success = $scope.result.success;
  9126. $scope.total = $scope.result.total;
  9127. $scope.alters = $scope.result.alters;
  9128. $scope.infos = $scope.result.infos;
  9129. $scope.myFiles[0] = "";
  9130. }).error(function(response) {
  9131. toaster.pop('error', response.data || response);
  9132. });
  9133. } else {
  9134. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  9135. }
  9136. }
  9137. };
  9138. // 查看范例
  9139. $scope.showImg = function() {
  9140. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  9141. box.show();
  9142. box.find('img').attr('src', src);
  9143. box.find('a').click(function(){
  9144. box.hide();
  9145. });
  9146. box.dblclick(function(){
  9147. box.hide();
  9148. });
  9149. };
  9150. // 下载模板
  9151. $scope.download = function() {
  9152. window.location.href = 'product/baseInfo/upload/template';
  9153. };
  9154. }]);
  9155. /**
  9156. * 物料详情
  9157. */
  9158. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService) {
  9159. BaseService.scrollBackToTop();
  9160. // 录入人
  9161. AuthenticationService.getAuthentication().success(function(data) {
  9162. $scope.loading = false;
  9163. $scope.user = data;
  9164. });
  9165. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9166. var loadData = function() {
  9167. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  9168. if(data.attach) {
  9169. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  9170. // 查看范例
  9171. $scope.showImg = function() {
  9172. var src = data.url, box = $('#image-box');
  9173. box.show();
  9174. box.find('img').attr('src', src);
  9175. box.find('a').click(function(){
  9176. box.hide();
  9177. });
  9178. box.dblclick(function(){
  9179. box.hide();
  9180. });
  9181. };
  9182. })
  9183. }
  9184. $scope.prodInfo = data;
  9185. $scope.prodInfo.$editing = false;
  9186. $scope.loading = false;
  9187. });
  9188. };
  9189. loadData();
  9190. $scope.isShow = true;
  9191. // 更新
  9192. $scope.update = function() {
  9193. $scope.prodInfo.$editing = true;
  9194. $scope.isShow = true;
  9195. };
  9196. // 取消
  9197. $scope.cancel = function() {
  9198. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  9199. $scope.prodInfo = data;
  9200. $scope.prodInfo.$editing = false;
  9201. $scope.isShow = false;
  9202. $scope.loading = false;
  9203. });
  9204. };
  9205. // 删除
  9206. $scope.clearfile = function() {
  9207. $scope.myFiles = null;
  9208. $scope.previewShow = false;
  9209. }
  9210. $scope.submit = function(prodInfo) {
  9211. $scope.prodInfo.isSale = 1;
  9212. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  9213. $upload.upload({
  9214. url: 'product/baseInfo/updateProdInfo',
  9215. file: file,
  9216. method: 'POST',
  9217. data: {
  9218. prodInfo: $scope.prodInfo
  9219. },
  9220. }).success(function(data) {
  9221. if(data.success) {
  9222. toaster.pop('success', '提示', data.success);
  9223. window.location.reload();
  9224. }
  9225. if(data.error) {
  9226. toaster.pop('error', '提示', data.error);
  9227. }
  9228. }).error(function(data) {
  9229. $scope.loadingShow = false;
  9230. toaster.pop('error', '操作失败', data.error);
  9231. });
  9232. }
  9233. $scope.previewShow = false;
  9234. $scope.pdfShow = false;
  9235. $scope.noneFileShow = true;
  9236. $scope.$watch('myFiles', function(){
  9237. if($scope.myFiles) {
  9238. $scope.noneFileShow = false;
  9239. var file = $scope.myFiles[0];
  9240. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  9241. $scope.pdfShow = true;
  9242. $scope.previewShow = false;
  9243. $scope.imgPreviewName = file.name;
  9244. } else{
  9245. if (typeof(Worker) !== "undefined") {//支持HTML5
  9246. $scope.imgPreview = getObjectURL(file);
  9247. $scope.imgPreviewName = file.name;
  9248. } else{//不支持HTML5
  9249. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  9250. $scope.imgPreviewName = file.name;
  9251. }
  9252. $scope.previewShow = true;
  9253. $scope.pdfShow = false;
  9254. }
  9255. } else {
  9256. $scope.noneFileShow = true;
  9257. $scope.previewShow = false;
  9258. $scope.pdfShow = false;
  9259. }
  9260. });
  9261. //建立一个可存取到该file的url
  9262. var getObjectURL = function(file) {
  9263. var url = null ;
  9264. if (window.createObjectURL!=undefined) { // basic
  9265. url = window.createObjectURL(file) ;
  9266. } else if (window.URL!=undefined) { // mozilla(firefox)
  9267. url = window.URL.createObjectURL(file) ;
  9268. } else if (window.webkitURL!=undefined) { // webkit or chrome
  9269. url = window.webkitURL.createObjectURL(file) ;
  9270. }
  9271. return url ;
  9272. };
  9273. }]);
  9274. /**
  9275. * 新增物料(销售)
  9276. */
  9277. 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) {
  9278. BaseService.scrollBackToTop();
  9279. // 录入人
  9280. AuthenticationService.getAuthentication().success(function(data) {
  9281. $scope.loading = false;
  9282. $scope.user = data;
  9283. });
  9284. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  9285. $scope.prodInfo = {};
  9286. // 选择类目
  9287. $scope.selectKind = function(uuids) {
  9288. $modal.open({
  9289. animation: true,
  9290. size: 'lg',
  9291. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  9292. controller: 'KindChooseCtrl',
  9293. }).result.then(function(data){
  9294. $scope.kindId = data;
  9295. var modalInstance = $modal.open({
  9296. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  9297. controller: 'FindComponentCtrl',
  9298. size: 'lg',
  9299. resolve: {
  9300. KindId: function() {
  9301. return $scope.kindId;
  9302. }
  9303. }
  9304. });
  9305. modalInstance.result.then(function(data) {
  9306. $scope.prodInfo.cmpUuId = data.uuid;
  9307. $scope.prodInfo.cmpCode = data.code;
  9308. $scope.prodInfo.brand = data.brand.nameEn;
  9309. }, function(){
  9310. });
  9311. }, function(){
  9312. });
  9313. };
  9314. // 删除
  9315. $scope.clearfile = function() {
  9316. $scope.myFiles = null;
  9317. $scope.previewShow = false;
  9318. }
  9319. //提交
  9320. $scope.submit = function(prodInfo){
  9321. $scope.prodInfo.isSale = 1;
  9322. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  9323. $upload.upload({
  9324. url: 'product/baseInfo/addNewProduct',
  9325. file: file,
  9326. method: 'POST',
  9327. data: {
  9328. prodInfo: prodInfo
  9329. },
  9330. }).success(function(data) {
  9331. if(data.success) {
  9332. toaster.pop('success', '提示', data.success);
  9333. $timeout(function() {
  9334. //提交后跳转到详情页面,防止重复提交
  9335. window.location.href="#/sale/prodList/"+data.id;
  9336. }, 500);
  9337. }
  9338. if(data.error) {
  9339. toaster.pop('error', '提示', data.error);
  9340. $timeout(function() {
  9341. //提交后跳转到详情页面,防止重复提交
  9342. window.location.href="#/sale/prodList/"+data.id;
  9343. }, 500);
  9344. }
  9345. }).error(function(data) {
  9346. $scope.loadingShow = false;
  9347. toaster.pop('error', '操作失败', data.error);
  9348. });
  9349. };
  9350. $scope.previewShow = false;
  9351. $scope.pdfShow = false;
  9352. $scope.noneFileShow = true;
  9353. $scope.$watch('myFiles', function(){
  9354. if($scope.myFiles) {
  9355. $scope.noneFileShow = false;
  9356. var file = $scope.myFiles[0];
  9357. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  9358. $scope.pdfShow = true;
  9359. $scope.previewShow = false;
  9360. $scope.imgPreviewName = file.name;
  9361. } else{
  9362. if (typeof(Worker) !== "undefined") {//支持HTML5
  9363. $scope.imgPreview = getObjectURL(file);
  9364. $scope.imgPreviewName = file.name;
  9365. } else{//不支持HTML5
  9366. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  9367. $scope.imgPreviewName = file.name;
  9368. }
  9369. $scope.previewShow = true;
  9370. $scope.pdfShow = false;
  9371. }
  9372. } else {
  9373. $scope.noneFileShow = true;
  9374. $scope.previewShow = false;
  9375. $scope.pdfShow = false;
  9376. }
  9377. });
  9378. //建立一个可存取到该file的url
  9379. var getObjectURL = function(file) {
  9380. var url = null ;
  9381. if (window.createObjectURL!=undefined) { // basic
  9382. url = window.createObjectURL(file) ;
  9383. } else if (window.URL!=undefined) { // mozilla(firefox)
  9384. url = window.URL.createObjectURL(file) ;
  9385. } else if (window.webkitURL!=undefined) { // webkit or chrome
  9386. url = window.webkitURL.createObjectURL(file) ;
  9387. }
  9388. return url ;
  9389. };
  9390. // 取消
  9391. $scope.cancel = function(){
  9392. $scope.prodInfo = angular.copy($scope.prodInfo);
  9393. };
  9394. }]);
  9395. /**
  9396. * 类目选择模态框
  9397. */
  9398. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  9399. $scope.kindId = null;
  9400. $scope.kinds = [[], [], [], []];
  9401. // 获取子类目
  9402. var getChildren = function(pid, deep) {
  9403. KindAPI.getChildren({parentId: pid}, function(data) {
  9404. $scope.kinds[deep] = data;
  9405. }, function(response) {
  9406. toaster.pop('error', '获取子类目失败', response.data);
  9407. });
  9408. };
  9409. // 改变节点选中状态
  9410. var changeStatus = function(item, deep) {
  9411. var kindId = null, level = 0;
  9412. angular.forEach($scope.kinds, function(ks, i) {
  9413. if(i > deep) {
  9414. $scope.kinds[i] = [];
  9415. } else {
  9416. angular.forEach(ks, function(k, j) {
  9417. if(i == deep) {
  9418. if(k.id == item.id) {
  9419. $scope.kinds[i][j].$active = true;
  9420. kindId = k.id;
  9421. } else {
  9422. k.$active = null;
  9423. }
  9424. }
  9425. });
  9426. }
  9427. });
  9428. // 选择的节点
  9429. $scope.kindId = kindId;
  9430. $scope.active = item;
  9431. // 当前可操作的层级
  9432. if(deep < 3) {
  9433. $scope.activeDeep = deep + 1;
  9434. }
  9435. };
  9436. // 节点点击后获取子类目,节点被选中
  9437. $scope.onItemClick = function(item, deep) {
  9438. changeStatus(item, deep);
  9439. if (!item.isLeaf) {
  9440. getChildren(item.id, deep + 1);
  9441. }
  9442. };
  9443. // 重新加载数据
  9444. function reload(deep) {
  9445. var pid;
  9446. if(deep) {
  9447. pid = $scope.actives[deep - 1].id;
  9448. } else {
  9449. pid = 0;
  9450. deep = 0;
  9451. }
  9452. getChildren(pid, deep);
  9453. }
  9454. // 初始加载数据,获取第一层的类目
  9455. if($scope.actives) {
  9456. angular.forEach($scope.actives, function(v, k) {
  9457. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  9458. $scope.kinds[k] = data;
  9459. angular.forEach($scope.kinds[k], function(kind, i){
  9460. if(kind.id == v.id) {
  9461. $scope.kinds[k][i].$active = true;
  9462. $scope.actives[k] = $scope.kinds[k][i];
  9463. }
  9464. })
  9465. }, function(response) {
  9466. toaster.pop('error', '获取子类目失败', response.data);
  9467. });
  9468. });
  9469. } else {
  9470. reload();
  9471. }
  9472. // 取消
  9473. $scope.cancel = function() {
  9474. $modalInstance.dismiss();
  9475. };
  9476. // 确认选择
  9477. $scope.check = function() {
  9478. $modalInstance.close($scope.kindId);
  9479. };
  9480. }]);
  9481. /**
  9482. * 器件筛选
  9483. */
  9484. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  9485. //状态
  9486. $scope.setActive = function (state){
  9487. if($scope.active != state) {
  9488. $scope.active = state;
  9489. if($scope.tableParams.page() == 1)
  9490. $scope.tableParams.reload();
  9491. else
  9492. $scope.tableParams.page(1);
  9493. }
  9494. };
  9495. $scope.tableParams = new ngTableParams({
  9496. page : 1,
  9497. count : 10
  9498. }, {
  9499. total : 0,
  9500. counts: [5, 10, 25, 50],
  9501. getData : function($defer, params) {
  9502. $scope.loading = true;
  9503. var pageParams = params.url();
  9504. pageParams.keyword = $scope.keyword;
  9505. pageParams.kindId = KindId;
  9506. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  9507. $scope.loading = false;
  9508. if(page) {
  9509. params.total(page.totalElement);
  9510. $defer.resolve(page.content);
  9511. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9512. }
  9513. }, function(response){
  9514. $scope.loading = false;
  9515. toaster.pop('error', '数据加载失败', response.data);
  9516. });
  9517. }
  9518. });
  9519. // 取消
  9520. $scope.cancel = function() {
  9521. $modalInstance.dismiss();
  9522. };
  9523. // 选择
  9524. $scope.check = function(data){
  9525. $modalInstance.close(data);
  9526. };
  9527. // 搜索框回车
  9528. $scope.onSearch = function() {
  9529. $scope.tableParams.page(1);
  9530. $scope.tableParams.reload();
  9531. };
  9532. }]);
  9533. /**
  9534. * 企业列表
  9535. */
  9536. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  9537. BaseService.scrollBackToTop();
  9538. $scope.active = 'all';
  9539. $scope.agreedText = '全部';
  9540. $scope.dateZoneText = '一个月内';
  9541. $scope.condition = {dateZone: 1};
  9542. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9543. $scope.changeAgreed = function(agreed) {
  9544. $scope.condition.agreed = agreed;
  9545. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9546. $scope.condition.$agreedOpen = false;
  9547. };
  9548. $scope.changeDateZone = function(zone) {
  9549. $scope.condition.dateZone = zone;
  9550. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9551. $scope.condition.$dateZoneOpen = false;
  9552. getDateCondition(zone, $scope.condition);
  9553. $scope.tableParams.reload();
  9554. };
  9555. $scope.setActive = function(state) {
  9556. if($scope.active != state) {
  9557. $scope.active = state;
  9558. if($scope.tableParams.page() == 1)
  9559. $scope.tableParams.reload();
  9560. else
  9561. $scope.tableParams.page(1);
  9562. }
  9563. };
  9564. var getService = function() {
  9565. return getAccountUserSpace;
  9566. };
  9567. $scope.tableParams = new ngTableParams({
  9568. page : 1,
  9569. count : 5,
  9570. sorting: {
  9571. }
  9572. }, {
  9573. total : 0,
  9574. counts: [5, 10, 25, 50],
  9575. getData : function($defer, params) {
  9576. $scope.loading = true;
  9577. var pageParams = params.url();
  9578. pageParams.keyword = $scope.keyword;
  9579. $scope.tip = $scope.keyword;
  9580. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9581. $scope.loading = false;
  9582. if(page) {
  9583. params.total(page.totalElement);
  9584. $defer.resolve(page.content);
  9585. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9586. }
  9587. }, function(response) {
  9588. $scope.loading = false;
  9589. toaster.pop('error', '数据加载失败', response.data);
  9590. });
  9591. }
  9592. });
  9593. // 搜索框回车
  9594. $scope.onSearch = function() {
  9595. $scope.tableParams.page(1);
  9596. $scope.tableParams.reload();
  9597. };
  9598. // 添加合作关系
  9599. $scope.addPartner = function(name, businessCode) {
  9600. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  9601. if(data.success) {
  9602. toaster.pop("success", '添加成功', data.success);
  9603. }
  9604. if(data.error) {
  9605. toaster.pop("error", '添加失败', data.error);
  9606. }
  9607. }, function(response) {
  9608. toaster.pop('error','失败',response.data);
  9609. });
  9610. }
  9611. $scope.status = 'enList';
  9612. }]);
  9613. /**
  9614. * 新增采购单
  9615. */
  9616. 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) {
  9617. BaseService.scrollBackToTop();
  9618. // 每次进入时先清除掉rootScope下的venuu
  9619. $rootScope.venduu = null;
  9620. // 获取收货地址列表
  9621. ShipAddress.shipAddList({}, function(data) {
  9622. $scope.ships = data;
  9623. $scope.order.shipadd = $scope.ships[0];
  9624. });
  9625. // 获取地址信息
  9626. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9627. }).then(function(response) {
  9628. $scope.provinces = response.data;
  9629. });
  9630. $scope.order = {
  9631. date : new Date(),
  9632. cust : {
  9633. uu : '',
  9634. },
  9635. custUser : {
  9636. },
  9637. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  9638. orderItems : {
  9639. product : {},
  9640. },
  9641. rate: 17
  9642. };
  9643. //商品信息
  9644. $scope.order.orderItems = [];
  9645. var item = {
  9646. code: null,
  9647. title: null,
  9648. spec: null,
  9649. unit: null,
  9650. qty: null,
  9651. price: null,
  9652. remark: null,
  9653. delivery: null,
  9654. id: null,
  9655. };
  9656. if($rootScope.businessCode) {
  9657. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  9658. $scope.id = data.id;
  9659. $scope.order.cust.enName = data.vendorEnterprise.enName;
  9660. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  9661. $scope.order.cust.uu = data.vendorEnterprise.uu;
  9662. $scope.order.paymethods = data.paymethod;
  9663. $rootScope.venduu = data.vendorEnterprise.uu;
  9664. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9665. $scope.contacts = data;
  9666. $scope.order.vendor = $scope.contacts[0];
  9667. });
  9668. }, function(response) {
  9669. });
  9670. };
  9671. // 查找供应商
  9672. $scope.dbfindCust = function(){
  9673. var modalInstance = $modal.open({
  9674. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  9675. controller: 'DbfindVendorInfoCtrl',
  9676. size: 'lg',
  9677. resolve: {
  9678. orderItems: function() {
  9679. return $scope.order.orderItems;
  9680. }
  9681. }
  9682. });
  9683. modalInstance.result.then(function(data) {
  9684. $rootScope.venduu = data.vendorEnterprise.uu;
  9685. $scope.id = data.id;
  9686. $scope.order.cust = data.vendorEnterprise;
  9687. $scope.order.custUser = data.vendorUser;
  9688. $scope.order.payments = data.paymethod;
  9689. $scope.order.orderItems = [];
  9690. var item = {
  9691. code: null,
  9692. title: null,
  9693. spec: null,
  9694. unit: null,
  9695. qty: null,
  9696. price: null,
  9697. remark: null,
  9698. delivery: null,
  9699. };
  9700. // $scope.order.orderItems.push(item);
  9701. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9702. $scope.contacts = data;
  9703. $scope.order.vendor = $scope.contacts[0];
  9704. });
  9705. }, function(){
  9706. });
  9707. };
  9708. // 联想词 start
  9709. // 获取供应商
  9710. $scope.getSimilarVendors = function(value) {
  9711. if (value) {
  9712. return Vendor.getSimilarVendors({keyword : value}).$promise.then(function(data) {
  9713. return data.map(function(item) {
  9714. return item;
  9715. });
  9716. });
  9717. }
  9718. };
  9719. $scope.onAssociateCmpClick = function(vendor, order) {
  9720. $scope.order.cust.uu = vendor.venduu;
  9721. $scope.id = vendor.id;
  9722. $scope.order.payments = vendor.paymethod;
  9723. $rootScope.venduu = $scope.order.cust.uu;
  9724. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9725. $scope.contacts = data;
  9726. $scope.order.vendor = $scope.contacts[0];
  9727. });
  9728. }
  9729. // 联想词 end
  9730. // $scope.order.orderItems.push(item);
  9731. if($rootScope.prodId) {
  9732. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  9733. item.code = data.code;
  9734. item.title = data.title;
  9735. item.spec = data.spec;
  9736. item.unit = data.unit;
  9737. item.id = data.id;
  9738. $scope.order.orderItems.push(item);
  9739. $rootScope.prodId = null;// 清除掉prodId
  9740. }, function(response) {
  9741. });
  9742. }
  9743. //增加商品
  9744. $scope.addProduct = function(index) {
  9745. if($scope.order.orderItems[index].code == null) {
  9746. toaster.pop('info', '提示', '请先选择商品');
  9747. } else {
  9748. $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});
  9749. }
  9750. };
  9751. //删除商品
  9752. $scope.deleteProduct = function(index) {
  9753. $scope.order.orderItems.splice(index, 1);
  9754. };
  9755. // 搜索框回车
  9756. $scope.onSearch = function(keyword) {
  9757. $scope.keyword = keyword;
  9758. $scope.tableParams.page(1);
  9759. $scope.tableParams.reload();
  9760. };
  9761. $scope.tableParams = new ngTableParams({
  9762. page : 1,
  9763. count : 10
  9764. }, {
  9765. total : 0,
  9766. counts: [5, 10, 25, 50],
  9767. getData : function($defer, params) {
  9768. $scope.loading = true;
  9769. var pageParams = params.url();
  9770. pageParams.keyword = $scope.keyword;
  9771. $scope.tip = $scope.keyword;
  9772. pageParams.custUU = $scope.order.cust.uu;
  9773. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  9774. $scope.loading = false;
  9775. if(page) {
  9776. params.total(page.totalElement);
  9777. $scope.total = page.totalElement;
  9778. $defer.resolve(page.content);
  9779. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9780. }
  9781. }, function(response){
  9782. $scope.loading = false;
  9783. toaster.pop('error', '数据加载失败', response.data);
  9784. });
  9785. }
  9786. });
  9787. // 选择
  9788. $scope.check = function(data) {
  9789. $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});
  9790. };
  9791. // 导入商品信息
  9792. $scope.uplodaByBatch = function() {
  9793. var modalInstance = $modal.open({
  9794. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  9795. controller: 'PurcUploadByBatchCtrl',
  9796. size: 'lg',
  9797. resolve: {
  9798. }
  9799. });
  9800. modalInstance.result.then(function(data) {
  9801. angular.forEach(data, function(prod) {
  9802. $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});
  9803. // for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  9804. // 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) { // 如果没有填写就删除这行数据
  9805. // $scope.inquiry.inquiryItems.splice(i, 1);
  9806. // }
  9807. // }
  9808. })
  9809. }, function(){
  9810. });
  9811. }
  9812. // 监听custuu发生变化,重新加载物料信息
  9813. $scope.$watch('order.cust.uu', function(n, o) {
  9814. if(n==o) {
  9815. return;
  9816. } else {
  9817. $scope.tableParams.page(1);
  9818. $scope.tableParams.reload();
  9819. }
  9820. }, true);
  9821. // 查找客户物料
  9822. $scope.dbfindCustProd = function(index){
  9823. if($scope.order.cust.uu) {
  9824. var modalInstance = $modal.open({
  9825. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  9826. controller: 'DbfindCustProdCtrl',
  9827. size: 'lg',
  9828. resolve: {
  9829. custUU: function() {
  9830. return $scope.order.cust.uu
  9831. }
  9832. }
  9833. });
  9834. modalInstance.result.then(function(data) {
  9835. $scope.order.orderItems.push(data);
  9836. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  9837. if($scope.order.orderItems[i].code == null || i == index) {
  9838. $scope.order.orderItems.splice(i, 1);
  9839. }
  9840. }
  9841. }, function() {
  9842. });
  9843. } else {
  9844. toaster.pop('info', '提示', '请先选择供应商');
  9845. }
  9846. };
  9847. $scope.getMinDate = function(item) {
  9848. return $filter('date')(new Date, 'yyyy-MM-dd');
  9849. };
  9850. $scope.openDatePicker = function($event, openParam, index) {
  9851. $event.preventDefault();
  9852. $event.stopPropagation();
  9853. $scope.order.orderItems[index].$endDateOpen = !openParam;
  9854. };
  9855. // 添加到购物车
  9856. $scope.addToCart = function(order) {
  9857. $scope.loading = true;
  9858. $scope.order.vendusertel = order.vendor.tel;
  9859. $scope.order.venduser = order.vendor.venduser;
  9860. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  9861. $scope.order.custUU = $scope.order.cust.uu;
  9862. $scope.order.custUserUU = $scope.order.custUser.userUU;
  9863. if($scope.order.date instanceof Date) {
  9864. $scope.order.date = $scope.order.date.getTime();
  9865. }
  9866. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  9867. if($scope.order.orderItems[i].delivery instanceof Date) {
  9868. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  9869. }
  9870. if($scope.order.currency != 'RMB') {
  9871. $scope.order.orderItems[i].rate = 0;
  9872. }
  9873. }
  9874. addtoCart.save({}, $scope.order, function(data){
  9875. $scope.loading = false;
  9876. toaster.pop('success', '成功', '保存成功');
  9877. window.location.hash = '#/purc/cart/'+data.id;
  9878. }, function(response){
  9879. $scope.loading = false;
  9880. toaster.pop('error', '保存失败', response.data);
  9881. });
  9882. };
  9883. // 立即购买
  9884. $scope.addToOrder = function(order) {
  9885. $scope.loading = true;
  9886. $scope.order.vendusertel = order.vendor.tel;
  9887. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  9888. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  9889. $scope.order.custUU = $scope.order.cust.uu;
  9890. $scope.order.custUserUU = $scope.order.custUser.userUU;
  9891. if($scope.order.date instanceof Date) {
  9892. $scope.order.date = $scope.order.date.getTime();
  9893. }
  9894. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  9895. if($scope.order.orderItems[i].delivery instanceof Date) {
  9896. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  9897. }
  9898. if($scope.order.currency != 'RMB') {
  9899. $scope.order.orderItems[i].rate = 0;
  9900. }
  9901. }
  9902. newPurcOrder.save({}, $scope.order, function(data){
  9903. $scope.loading = false;
  9904. toaster.pop('success', '成功', '保存成功');
  9905. window.location.hash = '#/purc/order/'+data.id;
  9906. }, function(response){
  9907. $scope.loading = false;
  9908. toaster.pop('error', '保存失败', response.data);
  9909. });
  9910. };
  9911. // 新增收货地址保存
  9912. $scope.saveShipAddress = function(ship) {
  9913. ship.address = ship.province + ship.city + ship.district;
  9914. ShipAddress.saveAddress( {}, ship, function(data) {
  9915. if(data.success) {
  9916. ShipAddress.shipAddList({}, function(data) {
  9917. $scope.ships = data;
  9918. $scope.order.shipadd = $scope.ships[0];
  9919. });
  9920. toaster.pop('success', '提示', data.success);
  9921. }
  9922. if(data.error) {
  9923. toaster.pop('error', '提示', data.error);
  9924. }
  9925. });
  9926. }
  9927. // 新增供应商联系人
  9928. $scope.addContact = function(uu) {
  9929. var modalInstance = $modal.open({
  9930. animation: true,
  9931. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  9932. controller: 'AddContacCtrl',
  9933. resolve: {
  9934. }
  9935. });
  9936. modalInstance.result.then(function(data) {
  9937. $scope.contact = data;
  9938. $scope.contact.venduu = uu;
  9939. Vendor.saveContact({}, $scope.contact, function(data) {
  9940. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9941. $scope.contacts = data;
  9942. $scope.order.vendor = $scope.contacts[0];
  9943. });
  9944. toaster.pop('success', '提示', '联系人保存成功');
  9945. }, function(response) {
  9946. toaster.pop('error', '失败', response.data);
  9947. });
  9948. });
  9949. }
  9950. }]);
  9951. /**
  9952. * 采购批量导入
  9953. */
  9954. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  9955. // 通过excel批量上传物料
  9956. $scope.result = null;
  9957. $scope.upload = function() {
  9958. var file = $scope.myFiles[0];
  9959. $upload.upload({
  9960. url: 'purchase/release/excel',
  9961. file: file,
  9962. method: 'POST'
  9963. }).success(function(data) {
  9964. $scope.result = data;
  9965. $scope.success = $scope.result.success;
  9966. $scope.total = $scope.result.total;
  9967. $scope.alters = $scope.result.alters;
  9968. }).error(function(response) {
  9969. toaster.pop('error', response.data || response);
  9970. });
  9971. };
  9972. // 下载模板
  9973. $scope.download = function() {
  9974. window.location.href = 'purchase/upload/template';
  9975. };
  9976. $scope.enSure = function() {
  9977. $modalInstance.close($scope.result.products);
  9978. }
  9979. $scope.cancel = function() {
  9980. $modalInstance.dismiss();
  9981. }
  9982. }]);
  9983. // 查找供应商
  9984. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  9985. $scope.prod = false;
  9986. if(orderItems.length != 0) {
  9987. $scope.prod = true;
  9988. }
  9989. BaseService.scrollBackToTop();
  9990. if($rootScope.venduu != null) {
  9991. $scope.venduu = $rootScope.venduu;
  9992. }
  9993. // 搜索框回车
  9994. $scope.onSearch = function(keyword) {
  9995. $scope.keyword = keyword;
  9996. $scope.customerParams.page(1);
  9997. $scope.customerParams.reload();
  9998. };
  9999. $scope.customerParams = new ngTableParams({
  10000. page : 1,
  10001. count : 10
  10002. }, {
  10003. total : 0,
  10004. counts: [5, 10, 25, 50],
  10005. getData : function($defer, params) {
  10006. $scope.loading = true;
  10007. var pageParams = params.url();
  10008. pageParams.keyword = $scope.keyword;
  10009. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  10010. $scope.loading = false;
  10011. if(page) {
  10012. params.total(page.totalElements);
  10013. $defer.resolve(page.content);
  10014. }
  10015. $scope.totalCount = page.totalElements;
  10016. }, function(response){
  10017. $scope.loading = false;
  10018. toaster.pop('error', '数据加载失败', response.data);
  10019. });
  10020. }
  10021. });
  10022. $scope.cancel = function() {
  10023. $modalInstance.dismiss();
  10024. };
  10025. $scope.ensure = false;
  10026. $scope.check = function(vendor) { // 需要进行判断的选择
  10027. $scope.vendorInfo = vendor;
  10028. $scope.ensure = true;
  10029. };
  10030. $scope.checkVendor = function(vendor) { // 直接选择
  10031. $modalInstance.close(vendor);
  10032. }
  10033. }]);
  10034. /**
  10035. * 我的客户
  10036. */
  10037. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  10038. $scope.userInfoResult = true;
  10039. AuthenticationService.getAuthentication().success(function(data) {
  10040. $scope.loading = false;
  10041. $scope.thisUser = data;
  10042. });
  10043. var getCustInfos = function(custuu) {
  10044. if(custuu) {
  10045. VendorService.userInfo.query({uu:custuu},null,function(data) {
  10046. $scope.custInfos = data;
  10047. var getPage = function(page, size){
  10048. if($scope.custInfos) {
  10049. var result = {};
  10050. result.totalCount = $scope.custInfos.length;
  10051. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  10052. if($scope.custInfos.length % size == 0) {
  10053. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  10054. }else {
  10055. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  10056. }
  10057. result.first = page == 1;
  10058. result.last = page == result.totalPage;
  10059. result.page = page;
  10060. result.next = page - 0 + 1;
  10061. result.pre = page - 1;
  10062. return result;
  10063. }
  10064. }
  10065. $scope.userdata = getPage(1,4);
  10066. $scope.first = function (){
  10067. $scope.userdata = getPage($scope.userdata.pre,4);
  10068. }
  10069. $scope.last = function (){
  10070. $scope.userdata = getPage($scope.userdata.next,4);
  10071. }
  10072. }, function(response){
  10073. $scope.loading = false;
  10074. toaster.pop('error', '数据加载失败', response.data);
  10075. });
  10076. }
  10077. }
  10078. $scope.addUserInfo = function(customer) {
  10079. //TODO
  10080. if ($scope.thisUser.sys) {
  10081. var modalInstance = $modal.open({
  10082. animation: true,
  10083. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  10084. controller: 'AddUserInfoCtrl',
  10085. resolve: {
  10086. customer: function() {
  10087. return customer;
  10088. }
  10089. }
  10090. });
  10091. modalInstance.result.then(function(changed, checked){
  10092. if(changed) {
  10093. if(checked)
  10094. $scope.newUser.roles = checked;
  10095. else
  10096. loadUsers();
  10097. }
  10098. });
  10099. } else {
  10100. toaster.pop('error', '您不是管理员,无权限分配用户!');
  10101. }
  10102. }
  10103. $scope.showUserInfo = function(customer,boo) {
  10104. $scope.custInfo = customer;
  10105. if(boo) {
  10106. getCustInfos(customer.myEnterprise.uu);
  10107. $scope.userInfoResult = true;
  10108. }
  10109. }
  10110. $scope.customerParams = new ngTableParams({
  10111. page : 1,
  10112. count : 10
  10113. }, {
  10114. total : 0,
  10115. counts: [5, 10, 25, 50],
  10116. getData : function($defer, params) {
  10117. $scope.loading = true;
  10118. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  10119. $scope.loading = false;
  10120. if(page) {
  10121. params.total(page.totalElements);
  10122. $defer.resolve(page.content);
  10123. }
  10124. $scope.totalCount = page.totalElements;
  10125. }, function(response){
  10126. $scope.loading = false;
  10127. toaster.pop('error', '数据加载失败', response.data);
  10128. });
  10129. }
  10130. });
  10131. }]);
  10132. /**
  10133. * 我的供应商
  10134. */
  10135. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  10136. BaseService.scrollBackToTop();
  10137. // 搜索框回车
  10138. $scope.onSearch = function(keyword) {
  10139. $scope.keyword = keyword;
  10140. $scope.customerParams.page(1);
  10141. $scope.customerParams.reload();
  10142. };
  10143. $scope.customerParams = new ngTableParams({
  10144. page : 1,
  10145. count : 10
  10146. }, {
  10147. total : 0,
  10148. counts: [5, 10, 25, 50],
  10149. getData : function($defer, params) {
  10150. $scope.loading = true;
  10151. var pageParams = params.url();
  10152. pageParams.keyword = $scope.keyword;
  10153. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  10154. $scope.loading = false;
  10155. if(page) {
  10156. params.total(page.totalElement);
  10157. $scope.total = page.totalElement;
  10158. $defer.resolve(page.content);
  10159. }
  10160. $scope.totalCount = page.totalElements;
  10161. }, function(response){
  10162. $scope.loading = false;
  10163. toaster.pop('error', '数据加载失败', response.data);
  10164. });
  10165. }
  10166. });
  10167. // 查看供应商详情
  10168. $scope.VendorDetail = function(id, uu) {
  10169. $rootScope.vendorId = id;
  10170. $rootScope.vendoruu = uu;
  10171. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  10172. }
  10173. // 向企业购买
  10174. $scope.purcByEn = function(businessCode) {
  10175. $rootScope.businessCode = businessCode;
  10176. window.location.hash = "#/purc/addOrder";
  10177. }
  10178. }]);
  10179. /**
  10180. * 供应商详情
  10181. */
  10182. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  10183. BaseService.scrollBackToTop();
  10184. $scope.vendorContacts = [];
  10185. var loadData = function() {
  10186. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  10187. $scope.vendor = data.vendorEnterprise;
  10188. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  10189. $scope.vendorContacts = data;
  10190. });
  10191. });
  10192. };
  10193. loadData();
  10194. // 新增供应商联系人
  10195. $scope.addContact = function(uu) {
  10196. var modalInstance = $modal.open({
  10197. animation: true,
  10198. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10199. controller: 'AddContacCtrl',
  10200. resolve: {
  10201. }
  10202. });
  10203. modalInstance.result.then(function(data) {
  10204. $scope.contact = data;
  10205. $scope.contact.venduu = uu;
  10206. Vendor.saveContact({}, $scope.contact, function(data) {
  10207. toaster.pop('success', '提示', '联系人保存成功');
  10208. $scope.vendorContacts.push(data);
  10209. }, function(response) {
  10210. toaster.pop('error', '失败', response.data);
  10211. });
  10212. });
  10213. };
  10214. // 编辑供应商联系人
  10215. $scope.edit = function(contact) {
  10216. var modalInstance = $modal.open({
  10217. animation: true,
  10218. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10219. controller: 'EditContacCtrl',
  10220. resolve: {
  10221. contact: function() {
  10222. return contact;
  10223. }
  10224. }
  10225. });
  10226. modalInstance.result.then(function(data) {
  10227. $scope.contact = data;
  10228. Vendor.saveContact({}, $scope.contact, function(data) {
  10229. toaster.pop('success', '提示', '联系人修改成功');
  10230. }, function(response) {
  10231. toaster.pop('error', '失败', response.data);
  10232. });
  10233. });
  10234. }
  10235. // 删除供应商联系人
  10236. $scope.deleteById = function(id, index) {
  10237. $scope.vendorContacts.splice(index, 1);
  10238. Vendor.deleteContact({id: id}, {}, function(data) {
  10239. toaster.pop('success', '提示', '供应商联系人删除成功');
  10240. loadData();
  10241. }, function(response) {
  10242. toaster.pop('error', '提示', response.data);
  10243. });
  10244. }
  10245. // 供应商物料信息
  10246. $scope.viewProdList = function(uu){
  10247. $scope.uu = uu;
  10248. $scope.tableParams.page(1);
  10249. $scope.tableParams.reload();
  10250. };
  10251. // 搜索框回车
  10252. $scope.onSearch = function(keyword) {
  10253. $scope.keyword = keyword;
  10254. $scope.tableParams.page(1);
  10255. $scope.tableParams.reload();
  10256. };
  10257. // 供应商物料信息
  10258. $scope.tableParams = new ngTableParams({
  10259. page : 1,
  10260. count : 10
  10261. }, {
  10262. total : 0,
  10263. counts: [5, 10, 25, 50],
  10264. getData : function($defer, params) {
  10265. $scope.loading = true;
  10266. var pageParams = params.url();
  10267. pageParams.custUU = $scope.uu;
  10268. pageParams.keyword = $scope.keyword;
  10269. $scope.tip = $scope.keyword;
  10270. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  10271. $scope.loading = false;
  10272. if(page) {
  10273. params.total(page.totalElement);
  10274. $scope.total = page.totalElement;
  10275. $defer.resolve(page.content);
  10276. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10277. }
  10278. }, function(response){
  10279. $scope.loading = false;
  10280. toaster.pop('error', '数据加载失败', response.data);
  10281. });
  10282. }
  10283. });
  10284. /**
  10285. * 选中单个物料购买
  10286. * @param businessCode
  10287. * @param id
  10288. */
  10289. $scope.PurcByEnAndProd = function(businessCode, id) {
  10290. $rootScope.businessCode = businessCode;
  10291. $rootScope.prodId = id;
  10292. window.location.hash = "#/purc/addOrder";
  10293. }
  10294. /**
  10295. * 询价
  10296. */
  10297. $scope.PurcInquiry = function(businessCode, id){
  10298. $rootScope.prodId = id;
  10299. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  10300. }
  10301. }]);
  10302. /**
  10303. * 编辑供应商联系人
  10304. */
  10305. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  10306. $scope.contact = contact;
  10307. $scope.save = function(contact) {
  10308. $modalInstance.close(contact);
  10309. }
  10310. $scope.cancel = function() {
  10311. $modalInstance.dismiss();
  10312. }
  10313. }]);
  10314. /**
  10315. * 新增供应商联系人
  10316. */
  10317. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  10318. $scope.save = function(contact) {
  10319. $modalInstance.close(contact);
  10320. }
  10321. $scope.cancel = function() {
  10322. $modalInstance.dismiss();
  10323. }
  10324. }]);
  10325. /**
  10326. * 建立合作关系申请
  10327. */
  10328. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo) {
  10329. BaseService.scrollBackToTop();
  10330. $scope.status = "partner";
  10331. $scope.active = 'all';
  10332. var getRequestStatus = function(active) {
  10333. var fn = 'getAllRequest';
  10334. switch(active) {
  10335. case 'done':
  10336. fn = 'getRequestDone';break;
  10337. case 'todo':
  10338. fn = 'getRequestTodo';break;
  10339. case 'end':
  10340. fn = 'getRequestEnd';break;
  10341. }
  10342. return fn;
  10343. }
  10344. // 切换单据类型
  10345. $scope.setActive = function(state) {
  10346. if($scope.active != state) {
  10347. $scope.active = state;
  10348. if($scope.tableParams.page() == 1)
  10349. $scope.tableParams.reload();
  10350. else
  10351. $scope.tableParams.page(1);
  10352. }
  10353. };
  10354. // 切换数据来源(正常数据 or 历史数据)
  10355. var getService = function() {
  10356. return AddPartnerMyRequest;
  10357. };
  10358. $scope.tableParams = new ngTableParams({ // ng-Table参数
  10359. page : 1,
  10360. count : 10,
  10361. sorting: {
  10362. }
  10363. }, {
  10364. total : 0,
  10365. counts: [],
  10366. getData : function($defer, params) { // 获取数据的方法
  10367. $scope.loading = true;
  10368. var pageParams = params.url();
  10369. pageParams.keyword = $scope.keyword;
  10370. if($rootScope.vendName) {
  10371. pageParams.keyword = $rootScope.vendName;
  10372. $scope.keyword = $rootScope.vendName;
  10373. $rootScope.vendName = null;
  10374. }
  10375. $scope.tip = $scope.keyword;
  10376. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10377. $scope.loading = false;
  10378. if(page) {
  10379. params.total(page.totalElement);
  10380. $defer.resolve(page.content);
  10381. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10382. }
  10383. }, function(response){
  10384. $scope.loading = false;
  10385. toaster.pop('error', '数据加载失败', response.data);
  10386. });
  10387. }
  10388. });
  10389. // 再次申请
  10390. $scope.addAgain = function(name, businessCode) {
  10391. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  10392. if(data.success) {
  10393. toaster.pop("success", '添加成功', data.success);
  10394. $scope.tableParams.reload();
  10395. }
  10396. if(data.error) {
  10397. toaster.pop("error", '添加失败', data.error);
  10398. }
  10399. }, function(response) {
  10400. toaster.pop('error','失败',response.data);
  10401. });
  10402. }
  10403. // 添加为供应商
  10404. $scope.addSupplier = function(vendUID) {
  10405. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  10406. if(data.success) {
  10407. toaster.pop('success', '提示', data.success);
  10408. }
  10409. if(data.error) {
  10410. toaster.pop('error','提示', data.error);
  10411. }
  10412. }, function(response) {
  10413. toaster.pop('error', '失败', response.data);
  10414. })
  10415. };
  10416. // 添加客户
  10417. $scope.addCust = function(vendUID) {
  10418. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  10419. if(data.success) {
  10420. toaster.pop('success', '提示', data.success);
  10421. }
  10422. if(data.error) {
  10423. toaster.pop('error','提示', data.error);
  10424. }
  10425. }, function(response) {
  10426. toaster.pop('error', '失败', response.data);
  10427. })
  10428. };
  10429. // 搜索框回车
  10430. $scope.onSearch = function() {
  10431. $scope.tableParams.page(1);
  10432. $scope.tableParams.reload();
  10433. };
  10434. // 同意申请
  10435. $scope.agree = function(id) {
  10436. AddPartner.agreeRequest({id: id}, {}, function(data) {
  10437. toaster.pop('success', '提示', '操作成功');
  10438. $scope.tableParams.reload();
  10439. }, function(response) {
  10440. toaster.pop('error', '提示', response.data);
  10441. });
  10442. }
  10443. // 拒绝申请
  10444. $scope.refuse = function(id, reason) {
  10445. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  10446. toaster.pop('success', '提示', '操作成功');
  10447. $scope.tableParams.reload();
  10448. }, function(response) {
  10449. toaster.pop('error', '提示', response.data);
  10450. });
  10451. }
  10452. // 取消供应商关系
  10453. $scope.relieve = function(id) {
  10454. VendorInfo.relieve({id: id}, {}, function(data) {
  10455. if(data.success) {
  10456. toaster.pop('success', '提示', data.success);
  10457. }
  10458. $scope.tableParams.page(1);
  10459. $scope.tableParams.reload();
  10460. }, function(response) {
  10461. toaster.pop('error', '提示', response.data);
  10462. });
  10463. }
  10464. // 建立供应商关系
  10465. $scope.activeVend = function(id) {
  10466. VendorInfo.activeVend({id: id}, {}, function(data) {
  10467. if(data.success) {
  10468. toaster.pop('success', '提示', data.success);
  10469. }
  10470. $scope.tableParams.page(1);
  10471. $scope.tableParams.reload();
  10472. }, function(response) {
  10473. toaster.pop('error', '提示', response.data);
  10474. });
  10475. }
  10476. // 取消客户关系
  10477. $scope.disableCust = function(id) {
  10478. VendorInfo.disableCust({id: id}, {}, function(data) {
  10479. if(data.success) {
  10480. toaster.pop('success', '提示', data.success);
  10481. }
  10482. $scope.tableParams.page(1);
  10483. $scope.tableParams.reload();
  10484. }, function(response) {
  10485. toaster.pop('error', '提示', response.data);
  10486. });
  10487. }
  10488. // 激活客户关系
  10489. $scope.activeCust = function(id) {
  10490. VendorInfo.activeCust({id: id}, {}, function(data) {
  10491. if(data.success) {
  10492. toaster.pop('success', '提示', data.success);
  10493. }
  10494. $scope.tableParams.page(1);
  10495. $scope.tableParams.reload();
  10496. }, function(response) {
  10497. toaster.pop('error', '提示', response.data);
  10498. });
  10499. }
  10500. }]);
  10501. /**
  10502. * 建立合作关系处理申请
  10503. */
  10504. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  10505. BaseService.scrollBackToTop();
  10506. $scope.active = 'todo';
  10507. var getMessagetStatus = function(active) {
  10508. var fn = 'getAllMessage';
  10509. switch(active) {
  10510. case 'done':
  10511. fn = 'getMessageDone';break;
  10512. case 'todo':
  10513. fn = 'getMessageTodo';break;
  10514. case 'end':
  10515. fn = 'getMessageEnd';break;
  10516. }
  10517. return fn;
  10518. }
  10519. // 切换单据类型
  10520. $scope.setActive = function(state) {
  10521. if($scope.active != state) {
  10522. $scope.active = state;
  10523. if($scope.tableParams.page() == 1)
  10524. $scope.tableParams.reload();
  10525. else
  10526. $scope.tableParams.page(1);
  10527. }
  10528. };
  10529. var getService = function() {
  10530. return AddPartnerMyMessage;
  10531. };
  10532. $scope.tableParams = new ngTableParams({ // ng-Table参数
  10533. page : 1,
  10534. count : 5,
  10535. sorting: {
  10536. }
  10537. }, {
  10538. total : 0,
  10539. counts: [5, 10, 15, 25, 50],
  10540. getData : function($defer, params) { // 获取数据的方法
  10541. $scope.loading = true;
  10542. var pageParams = params.url();
  10543. pageParams.searchFilter = { // 筛选条件
  10544. keyword: $scope.keyword,
  10545. };
  10546. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10547. $scope.loading = false;
  10548. if(page) {
  10549. params.total(page.totalElement);
  10550. $defer.resolve(page.content);
  10551. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10552. }
  10553. }, function(response){
  10554. $scope.loading = false;
  10555. toaster.pop('error', '数据加载失败', response.data);
  10556. });
  10557. }
  10558. });
  10559. // 同意申请
  10560. $scope.agree = function(id) {
  10561. AddPartner.agreeRequest({id: id}, {}, function(data) {
  10562. toaster.pop('success', '提示', '操作成功');
  10563. }, function(response) {
  10564. toaster.pop('error', '提示', response.data);
  10565. });
  10566. }
  10567. // 拒绝申请
  10568. $scope.refuse = function(id, reason) {
  10569. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  10570. toaster.pop('success', '提示', '操作成功');
  10571. }, function(response) {
  10572. toaster.pop('error', '提示', response.data);
  10573. });
  10574. }
  10575. $scope.status = 'get';
  10576. }]);
  10577. /**
  10578. * 我的合作伙伴
  10579. */
  10580. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  10581. BaseService.scrollBackToTop();
  10582. // 默认显示合作伙伴
  10583. $scope.status = 'news';
  10584. // 获取所有的合作伙伴
  10585. GetProductInfo.getAllPartners({}, function(data) {
  10586. $scope.partners = data;
  10587. }, function(res) {
  10588. toaster.pop('error', '获取列表失败', res.data);
  10589. });
  10590. // 添加为客户
  10591. $scope.addCust = function(partner) {
  10592. GetProductInfo.addCust({}, partner, function(data) {
  10593. toaster.pop('success', '提示', '添加客户成功');
  10594. }, function(response) {
  10595. toaster.pop('error', '添加客户失败', response.data);
  10596. });
  10597. }
  10598. // 添加为供应商
  10599. $scope.addSupplier = function(partner) {
  10600. GetProductInfo.addSupplier({}, partner, function(data) {
  10601. toaster.pop('success', '提示', '添加供应商成功');
  10602. }, function(response) {
  10603. toaster.pop('error', '添加供应商失败', response.data);
  10604. });
  10605. }
  10606. }]);
  10607. /**
  10608. * 财务对账时,企业进行筛选操作
  10609. */
  10610. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  10611. var getData = function(){
  10612. $scope.loading = true;
  10613. FaApCheck.getAllCustomers(function(data) {
  10614. $scope.custs = data;
  10615. $scope.loading = false;
  10616. });
  10617. };
  10618. getData();
  10619. $scope.select = function(suuorname) {
  10620. $modalInstance.close(suuorname);
  10621. }
  10622. $scope.close = function() {
  10623. $modalInstance.close();
  10624. }
  10625. }]);
  10626. /**
  10627. * 跳转到企业圈
  10628. */
  10629. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  10630. GetProductInfo.businessGroups({}, function(data) {
  10631. window.open(data.url);
  10632. }, function(response) {
  10633. toaster.pop('error', '提示', response.data);
  10634. });
  10635. }]);
  10636. /**
  10637. * 购物车
  10638. */
  10639. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  10640. BaseService.scrollBackToTop();
  10641. $scope.active = 'all';
  10642. $scope.agreedText = '全部';
  10643. $scope.dateZoneText = '一个月内';
  10644. $scope.condition = {dateZone: 1};
  10645. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10646. $scope.changeAgreed = function(agreed) {
  10647. $scope.condition.agreed = agreed;
  10648. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  10649. $scope.condition.$agreedOpen = false;
  10650. };
  10651. $scope.changeDateZone = function(zone) {
  10652. $scope.condition.dateZone = zone;
  10653. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  10654. $scope.condition.$dateZoneOpen = false;
  10655. getDateCondition(zone, $scope.condition);
  10656. $scope.tableParams.reload();
  10657. };
  10658. $scope.setActive = function(state) {
  10659. if($scope.active != state) {
  10660. $scope.active = state;
  10661. if($scope.tableParams.page() == 1)
  10662. $scope.tableParams.reload();
  10663. else
  10664. $scope.tableParams.page(1);
  10665. }
  10666. };
  10667. var getService = function() {
  10668. return getCartList;
  10669. };
  10670. $scope.tableParams = new ngTableParams({
  10671. page : 1,
  10672. count : 5,
  10673. sorting: {
  10674. date: 'desc',
  10675. }
  10676. }, {
  10677. total : 0,
  10678. counts: [5, 10, 25, 50],
  10679. getData : function($defer, params) {
  10680. $scope.loading = true;
  10681. var pageParams = params.url();
  10682. pageParams.keyword = $scope.keyword;
  10683. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  10684. $scope.loading = false;
  10685. if(page) {
  10686. params.total(page.totalElements);
  10687. $defer.resolve(page.content);
  10688. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10689. }
  10690. }, function(response) {
  10691. $scope.loading = false;
  10692. toaster.pop('error', '数据加载失败', response.data);
  10693. });
  10694. }
  10695. });
  10696. $scope.getCartTotal = function(items) {
  10697. var sum = 0;
  10698. angular.forEach(items, function(item){
  10699. sum += item.qty * item.price;
  10700. });
  10701. return sum;
  10702. };
  10703. // 搜索框回车
  10704. $scope.onSearch = function() {
  10705. $scope.tableParams.page(1);
  10706. $scope.tableParams.reload();
  10707. };
  10708. // 提交
  10709. $scope.addtoOrder = function(id) {
  10710. cartOperation.addToOrder({id: id}, {}, function(data) {
  10711. if(data.success) {
  10712. toaster.pop('success', '提示', data.success);
  10713. $timeout(function() {
  10714. window.location.hash = '#/purc/order/'+data.id;
  10715. },500);
  10716. }
  10717. if(data.error) {
  10718. toaster.pop('error', '提示', data.error);
  10719. }
  10720. }, function(response) {
  10721. toaster.pop('erroer', '提示', response.data);
  10722. });
  10723. };
  10724. // 删除一条主记录
  10725. $scope.deleteCart = function(id) {
  10726. cartOperation.deleteCart({id: id}, {}, function(data) {
  10727. if(data.success) {
  10728. toaster.pop('success', '提示', data.success);
  10729. $timeout(function() {
  10730. window.location.reload();
  10731. },500);
  10732. }
  10733. if(data.error) {
  10734. toaster.pop('error', '提示', data.error);
  10735. }
  10736. }, function(response) {
  10737. toaster.pop('erroer', '提示', response.data);
  10738. });
  10739. };
  10740. // 删除一条明细
  10741. $scope.deleteDetail = function(id) {
  10742. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  10743. if(data.success) {
  10744. toaster.pop('success', '提示', data.success);
  10745. $timeout(function() {
  10746. window.location.reload();
  10747. },500);
  10748. }
  10749. if(data.error) {
  10750. toaster.pop('error', '提示', data.error);
  10751. }
  10752. }, function(response) {
  10753. toaster.pop('erroer', '提示', response.data);
  10754. });
  10755. };
  10756. // 清空购物车
  10757. $scope.clearCart = function() {
  10758. cartOperation.deleteCarts({}, function(data) {
  10759. if(data.success) {
  10760. toaster.pop('success', '提示', data.success);
  10761. $timeout(function() {
  10762. window.location.reload();
  10763. },500);
  10764. }
  10765. if(data.error) {
  10766. toaster.pop('error', '提示', data.error);
  10767. }
  10768. }, function(response) {
  10769. toaster.pop('erroer', '提示', response.data);
  10770. });
  10771. }
  10772. }]);
  10773. /**
  10774. * 购物车详情
  10775. */
  10776. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  10777. BaseService.scrollBackToTop();
  10778. var loadData = function() {
  10779. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  10780. if(data.code) {
  10781. $scope.cart = data;
  10782. var sum = 0;
  10783. angular.forEach($scope.cart.cartDetails, function(item) {
  10784. sum += item.qty * item.price;
  10785. });
  10786. $scope.cart.total = sum;
  10787. $scope.loading = false;
  10788. } else {
  10789. window.location.hash = '#/purc/cart';
  10790. }
  10791. });
  10792. };
  10793. loadData();
  10794. // 删除一条明细
  10795. $scope.deleteDetail = function(id) {
  10796. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  10797. if(data.success) {
  10798. toaster.pop('success', '提示', data.success);
  10799. $timeout(function() {
  10800. window.location.reload();
  10801. },500);
  10802. }
  10803. if(data.error) {
  10804. toaster.pop('error', '提示', data.error);
  10805. }
  10806. }, function(response) {
  10807. toaster.pop('erroer', '提示', response.data);
  10808. });
  10809. };
  10810. // 删除一条主记录
  10811. $scope.deleteCart = function(id) {
  10812. cartOperation.deleteCart({id: id}, {}, function(data) {
  10813. if(data.success) {
  10814. toaster.pop('success', '提示', data.success);
  10815. $timeout(function() {
  10816. window.location.reload();
  10817. },500);
  10818. }
  10819. if(data.error) {
  10820. toaster.pop('error', '提示', data.error);
  10821. }
  10822. }, function(response) {
  10823. toaster.pop('erroer', '提示', response.data);
  10824. });
  10825. };
  10826. // 提交
  10827. $scope.addtoOrder = function(id) {
  10828. cartOperation.addToOrder({id: id}, {}, function(data) {
  10829. if(data.success) {
  10830. toaster.pop('success', '提示', data.success);
  10831. $timeout(function() {
  10832. window.location.hash = '#/purc/order/'+data.id;
  10833. },500);
  10834. }
  10835. if(data.error) {
  10836. toaster.pop('error', '提示', data.error);
  10837. }
  10838. }, function(response) {
  10839. toaster.pop('erroer', '提示', response.data);
  10840. });
  10841. };
  10842. }]);
  10843. /**
  10844. * 审批流
  10845. */
  10846. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  10847. BaseService.scrollBackToTop();
  10848. $scope.vacation = false;
  10849. $scope.workovertime = false;
  10850. $scope.workdaily = false;
  10851. $scope.feeplease = false;
  10852. $scope.signapp = false;
  10853. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  10854. $scope.nodes = data;
  10855. angular.forEach($scope.nodes, function(node) {
  10856. if(node.appname = '请假单') {
  10857. $scope.vacation = true;
  10858. }
  10859. if(node.appname = '加班单') {
  10860. $scope.workovertime = true;
  10861. }
  10862. if(node.appname = '工作日报') {
  10863. $scope.workdaily = true;
  10864. }
  10865. if(node.appname = '出差单') {
  10866. $scope.feeplease = true;
  10867. }
  10868. if(node.appname = '申诉单') {
  10869. $scope.signapp = true;
  10870. }
  10871. });
  10872. }, function(response) {
  10873. });
  10874. $scope.NoteSet = function() {
  10875. var modalInstance = $modal.open({
  10876. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10877. controller: 'NoteStep1Ctrl',
  10878. size: 'lg',
  10879. resolve: {
  10880. AppName: function() {
  10881. return '请假单';
  10882. }
  10883. }
  10884. });
  10885. modalInstance.result.then(function(data) {
  10886. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10887. if(data.error) {
  10888. toaster.pop('error', '提示', data.error);
  10889. }
  10890. if(data.success) {
  10891. toaster.pop('success', '提示', data.success);
  10892. }
  10893. }, function(response) {
  10894. });
  10895. }, function(){
  10896. });
  10897. }
  10898. $scope.overTimeSet = function() {
  10899. var modalInstance = $modal.open({
  10900. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10901. controller: 'NoteStep1Ctrl',
  10902. size: 'lg',
  10903. resolve: {
  10904. AppName: function() {
  10905. return '加班单';
  10906. }
  10907. }
  10908. });
  10909. modalInstance.result.then(function(data) {
  10910. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10911. if(data.error) {
  10912. toaster.pop('error', '提示', data.error);
  10913. }
  10914. if(data.success) {
  10915. toaster.pop('success', '提示', data.success);
  10916. }
  10917. }, function(response) {
  10918. });
  10919. }, function(){
  10920. });
  10921. }
  10922. $scope.feePleaseSet = function() {
  10923. var modalInstance = $modal.open({
  10924. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10925. controller: 'NoteStep1Ctrl',
  10926. size: 'lg',
  10927. resolve: {
  10928. AppName: function() {
  10929. return '出差单';
  10930. }
  10931. }
  10932. });
  10933. modalInstance.result.then(function(data) {
  10934. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10935. if(data.error) {
  10936. toaster.pop('error', '提示', data.error);
  10937. }
  10938. if(data.success) {
  10939. toaster.pop('success', '提示', data.success);
  10940. }
  10941. }, function(response) {
  10942. });
  10943. }, function(){
  10944. });
  10945. }
  10946. $scope.workDailySet = function() {
  10947. var modalInstance = $modal.open({
  10948. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10949. controller: 'NoteStep1Ctrl',
  10950. size: 'lg',
  10951. resolve: {
  10952. AppName: function() {
  10953. return '工作日报';
  10954. }
  10955. }
  10956. });
  10957. modalInstance.result.then(function(data) {
  10958. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10959. if(data.error) {
  10960. toaster.pop('error', '提示', data.error);
  10961. }
  10962. if(data.success) {
  10963. toaster.pop('success', '提示', data.success);
  10964. }
  10965. }, function(response) {
  10966. });
  10967. }, function(){
  10968. });
  10969. }
  10970. $scope.signAppSet = function() {
  10971. var modalInstance = $modal.open({
  10972. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  10973. controller: 'NoteStep1Ctrl',
  10974. size: 'lg',
  10975. resolve: {
  10976. AppName: function() {
  10977. return '申诉单';
  10978. }
  10979. }
  10980. });
  10981. modalInstance.result.then(function(data) {
  10982. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  10983. if(data.error) {
  10984. toaster.pop('error', '提示', data.error);
  10985. }
  10986. if(data.success) {
  10987. toaster.pop('success', '提示', data.success);
  10988. }
  10989. }, function(response) {
  10990. });
  10991. }, function(){
  10992. });
  10993. }
  10994. }]);
  10995. /**
  10996. * 审核条件设置
  10997. */
  10998. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  10999. $scope.appName = AppName;// 标题名称
  11000. $scope.AppFlow = {appName: $scope.appName,
  11001. appNodes:{}};
  11002. $scope.AppFlow.appNodes = [];
  11003. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  11004. if(data.appNodes.length != 0) {
  11005. $scope.node = data;
  11006. $scope.AppFlow = data;
  11007. }
  11008. }, function() {
  11009. });
  11010. $scope.copy = function() {//复制
  11011. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  11012. toaster.pop('info', '提示', '复制成功');
  11013. $modalInstance.dismiss();
  11014. }
  11015. $scope.paste = function() {
  11016. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  11017. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  11018. }
  11019. $scope.clear = function() {// 清空
  11020. $scope.AppFlow = {appName: $scope.appName,
  11021. appNodes:{}};
  11022. $scope.AppFlow.appNodes = [];
  11023. }
  11024. appFlow.getPositions({}, function(data) {// 获取人员信息
  11025. $scope.users = data;
  11026. }, function(response) {
  11027. });
  11028. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  11029. $scope.roles = data;
  11030. },function(response) {
  11031. });
  11032. $scope.SelectUser = function(data) { // 添加人员
  11033. var item = {
  11034. useruu: null,
  11035. username: null,
  11036. level: null
  11037. };
  11038. item.useruu = data.useruu;
  11039. item.username = data.username;
  11040. // if($scope.AppFlow.appNodes.length != 0){
  11041. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  11042. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  11043. // toaster.pop('info', '提示', '不能重复添加');
  11044. // } else {
  11045. // $scope.AppFlow.appNodes.push(item);
  11046. // }
  11047. // }
  11048. // } else {
  11049. $scope.AppFlow.appNodes.push(item);
  11050. // }
  11051. }
  11052. $scope.SelectRole = function(data) {// 添加职位
  11053. var item = {
  11054. position: null,
  11055. level: null
  11056. };
  11057. item.position = data;
  11058. $scope.AppFlow.appNodes.push(item);
  11059. }
  11060. $scope.deleteNode = function(index) {// 删除节点
  11061. $scope.AppFlow.appNodes.splice(index, 1);
  11062. };
  11063. $scope.saveNode = function() { // 保存
  11064. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  11065. $scope.AppFlow.appNodes[key].level = key;
  11066. });
  11067. if($scope.AppFlow.appNodes.length == 0) {
  11068. toaster.pop('info', '提示', '您还未设置审批人');
  11069. } else {
  11070. $modalInstance.close($scope.AppFlow);
  11071. };
  11072. };
  11073. $scope.cancel = function() {// 取消
  11074. $modalInstance.dismiss();
  11075. }
  11076. }]);
  11077. /***
  11078. * 代采定单
  11079. */
  11080. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  11081. BaseService.scrollBackToTop();
  11082. $scope.active = 'all';
  11083. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11084. $scope.total = null;
  11085. $scope.setActive = function(state) {
  11086. if($scope.active != state) {
  11087. $scope.active = state;
  11088. if($scope.tableParams.page() == 1)
  11089. $scope.tableParams.reload();
  11090. else
  11091. $scope.tableParams.page(1);
  11092. }
  11093. };
  11094. $scope.tableParams = new ngTableParams({
  11095. page : 1,
  11096. count : 5,
  11097. sorting: {
  11098. }
  11099. }, {
  11100. total : 0,
  11101. counts: [5, 10, 25, 50],
  11102. getData : function($defer, params) {
  11103. $scope.loading = true;
  11104. var pageParams = params.url();
  11105. pageParams.keyword = $scope.keyword;
  11106. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  11107. $scope.loading = false;
  11108. if(page) {
  11109. params.total(page.totalElement);
  11110. $scope.total = page.totalElement;
  11111. $defer.resolve(page.content);
  11112. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11113. }
  11114. }, function(response) {
  11115. $scope.loading = false;
  11116. toaster.pop('error', '数据加载失败', response.data);
  11117. });
  11118. }
  11119. });
  11120. //打印
  11121. $scope.print = function(deputyOrder) {
  11122. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  11123. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  11124. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  11125. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  11126. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  11127. //TODO 目前只有信扬有代采业务,先写死之后再改
  11128. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  11129. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  11130. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  11131. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  11132. };
  11133. // 搜索框回车
  11134. $scope.onSearch = function() {
  11135. $scope.tableParams.page(1);
  11136. $scope.tableParams.reload();
  11137. };
  11138. }]);
  11139. /**
  11140. * 新增代采订单
  11141. */
  11142. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  11143. BaseService.scrollBackToTop();
  11144. $scope.deOrder = {
  11145. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  11146. entrydate: new Date(),
  11147. status: '在录入',
  11148. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  11149. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  11150. riskmethod: '甲方承担',
  11151. taxpaymentmethod: '甲方承担',
  11152. totalamount: 0,
  11153. totalpayament: 0,
  11154. orderamount: 0,
  11155. usdpayment: 0
  11156. };
  11157. $scope.deOrder.deputyOrderItems = [];
  11158. var item = {
  11159. prodname: null,
  11160. prodcode: null,
  11161. prodspec: null,
  11162. amount: null,
  11163. unitprice: null,
  11164. remark: null,
  11165. orderprice: null,
  11166. };
  11167. $scope.deOrder.deputyOrderItems.push(item);
  11168. // 代采企业列表
  11169. DeputyOrder.deputyEnterprise({}, function(data) {
  11170. $scope.deputyEnterprises = data;
  11171. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  11172. // 费率
  11173. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  11174. $scope.rate = data;
  11175. }, function(response){
  11176. });
  11177. });
  11178. // 更新代采企业时更新费率
  11179. $scope.change = function(deputyuu) {
  11180. // 费率
  11181. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  11182. $scope.rate = data;
  11183. }, function(response){
  11184. });
  11185. }
  11186. // 查找付款企业
  11187. $scope.dbfindPayCompany = function(deputyuu) {
  11188. var modalInstance = $modal.open({
  11189. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  11190. controller: 'DbfindDeputyPayCompanyCtrl',
  11191. resolve: {
  11192. deputyuu: function() {return deputyuu}
  11193. }
  11194. });
  11195. modalInstance.result.then(function(data) {
  11196. $scope.deOrder.paycomname = data.enname;
  11197. $scope.deOrder.paycomaddress = data.address;
  11198. })
  11199. }
  11200. // 查询上次的关键词记录
  11201. $scope.getHisKeyword = function(tervendor) {
  11202. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function(data) {
  11203. $scope.deOrder.vendtel = data.vendtel;
  11204. $scope.deOrder.venduser = data.venduser;
  11205. $scope.deOrder.otherdata = data.otherdata;
  11206. $scope.deOrder.companyname = data.companyname;
  11207. $scope.deOrder.bankaccount = data.bankaccount;
  11208. $scope.deOrder.bankaddress = data.bankaddress;
  11209. $scope.deOrder.bankcode = data.bankcode;
  11210. $scope.deOrder.bankname = data.bankname;
  11211. $scope.deOrder.legalrepresent = data.legalrepresent;
  11212. $scope.deOrder.tervendaddress = data.tervendaddress;
  11213. }, function(response) {
  11214. toaster.pop('error', '提示', response.data);
  11215. });
  11216. }
  11217. // 查询历史供应商
  11218. DeputyOrder.hisvendors({}, function(data) {
  11219. $scope.hisvendors = data;
  11220. }, function(response) {
  11221. toaster.pop('error', '提示', response.data);
  11222. });
  11223. //增加商品
  11224. $scope.add = function(index) {
  11225. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  11226. toaster.pop('info', '提示', '请先填写商品信息');
  11227. }else {
  11228. $scope.deOrder.deputyOrderItems.push(
  11229. { prodname: null,
  11230. prodcode: null,
  11231. prodspec: null,
  11232. prodbrand: null,
  11233. amount: null,
  11234. unitprice: null,
  11235. remark: null,
  11236. orderprice: null});
  11237. }
  11238. };
  11239. //删除商品
  11240. $scope.del = function(index) {
  11241. $scope.deOrder.deputyOrderItems.splice(index, 1);
  11242. };
  11243. // 导入商品信息
  11244. $scope.uplodaByBatch = function() {
  11245. var modalInstance = $modal.open({
  11246. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  11247. controller: 'DeputyOrderUploadCtrl',
  11248. size: 'lg',
  11249. resolve: {
  11250. }
  11251. });
  11252. modalInstance.result.then(function(data) {
  11253. angular.forEach(data, function(data) {
  11254. $scope.deOrder.deputyOrderItems.push(data);
  11255. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  11256. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  11257. $scope.deOrder.deputyOrderItems.splice(i, 1);
  11258. }
  11259. }
  11260. })
  11261. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11262. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11263. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11264. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11265. });
  11266. }, function(){
  11267. });
  11268. }
  11269. // 查找供应商
  11270. $scope.dbfindVendor = function(deputyuu) {
  11271. var modalInstance = $modal.open({
  11272. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  11273. controller: 'DbfindDeputyVendorInfoCtrl',
  11274. size: 'lg',
  11275. resolve: {
  11276. deputyuu: function() {return deputyuu}
  11277. }
  11278. });
  11279. modalInstance.result.then(function(data) {
  11280. $scope.deOrder.customer = data.vendorEnterprise.enName;
  11281. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  11282. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  11283. $scope.deOrder.usertel = data.vendorUser.userTel;
  11284. })
  11285. }
  11286. // 检验订单编号是否存在
  11287. $scope.checkOrder = function(salecode, deputyuu) {
  11288. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  11289. if(data.info) {
  11290. toaster.pop('error', '提示', data.info);
  11291. }
  11292. }, function(response) {
  11293. toaster.pop('error', '提示', response.data);
  11294. })
  11295. }
  11296. // 保存
  11297. $scope.save = function() {
  11298. $scope.deOrder.entrystatus = '保存';
  11299. $scope.deOrder.totalamount = 0;
  11300. $scope.deOrder.totalpayament = 0;
  11301. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11302. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11303. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11304. });
  11305. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  11306. toaster.pop('info', '提示', '您还未填写任何商品信息');
  11307. } else {
  11308. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11309. if(data.id) {
  11310. window.location.hash = "#/purc/deputy/"+data.id;
  11311. }
  11312. if(data.error) {
  11313. toaster.pop('error', '提示', '保存失败');
  11314. }
  11315. }, function(response) {
  11316. });
  11317. }
  11318. }
  11319. // 提交
  11320. $scope.submit = function() {
  11321. $scope.deOrder.entrystatus = '已提交';
  11322. $scope.deOrder.totalpayament = 0;
  11323. $scope.deOrder.totalamount = 0;
  11324. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11325. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11326. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11327. });
  11328. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  11329. toaster.pop('info', '提示', '您还未填写任何商品信息');
  11330. } else {
  11331. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11332. if(data.id) {
  11333. window.location.hash = "#/purc/deputy/"+data.id;
  11334. }
  11335. if(data.error) {
  11336. toaster.pop('error', '提示', '保存失败');
  11337. }
  11338. }, function(response) {
  11339. });
  11340. }
  11341. }
  11342. $scope.openDatePicker = function($event, deOrder, openParam) {
  11343. $event.preventDefault();
  11344. $event.stopPropagation();
  11345. deOrder[openParam] = !deOrder[openParam];
  11346. };
  11347. }]);
  11348. // 代采企业供应商
  11349. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  11350. $scope.prod = false;
  11351. BaseService.scrollBackToTop();
  11352. // 搜索框回车
  11353. $scope.onSearch = function(keyword) {
  11354. $scope.keyword = keyword;
  11355. $scope.customerParams.page(1);
  11356. $scope.customerParams.reload();
  11357. };
  11358. $scope.customerParams = new ngTableParams({
  11359. page : 1,
  11360. count : 10
  11361. }, {
  11362. total : 0,
  11363. counts: [5, 10, 25, 50],
  11364. getData : function($defer, params) {
  11365. $scope.loading = true;
  11366. var pageParams = params.url();
  11367. pageParams.keyword = $scope.keyword;
  11368. pageParams.enuu = deputyuu;
  11369. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function(page){
  11370. $scope.loading = false;
  11371. if(page) {
  11372. params.total(page.totalElements);
  11373. $defer.resolve(page.content);
  11374. }
  11375. $scope.totalCount = page.totalElements;
  11376. }, function(response){
  11377. $scope.loading = false;
  11378. toaster.pop('error', '数据加载失败', response.data);
  11379. });
  11380. }
  11381. });
  11382. $scope.cancel = function() {
  11383. $modalInstance.dismiss();
  11384. };
  11385. $scope.checkVendor = function(vendor) { // 直接选择
  11386. $modalInstance.close(vendor);
  11387. }
  11388. }]);
  11389. // 代采企业付款企业
  11390. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  11391. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function(data) {
  11392. $scope.paycompanies = data;
  11393. }, function(response) {
  11394. toaster.pop('error', '提示', response.data);
  11395. });
  11396. $scope.cancel = function() {
  11397. $modalInstance.dismiss();
  11398. };
  11399. $scope.select = function(company) { // 直接选择
  11400. $modalInstance.close(company);
  11401. }
  11402. }]);
  11403. /**
  11404. * 代采订单批量导入
  11405. */
  11406. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  11407. // 通过excel批量上传物料
  11408. $scope.result = null;
  11409. $scope.upload = function() {
  11410. var file = $scope.myFiles[0];
  11411. $upload.upload({
  11412. url: 'deputyOrder/release/excel',
  11413. file: file,
  11414. method: 'POST'
  11415. }).success(function(data) {
  11416. $scope.result = data;
  11417. $scope.success = $scope.result.success;
  11418. $scope.total = $scope.result.total;
  11419. $scope.alters = $scope.result.alters;
  11420. }).error(function(response) {
  11421. toaster.pop('error', response.data || response);
  11422. });
  11423. };
  11424. // 查看范例
  11425. $scope.showImg = function() {
  11426. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  11427. box.show();
  11428. box.find('img').attr('src', src);
  11429. box.find('a').click(function(){
  11430. box.hide();
  11431. });
  11432. box.dblclick(function(){
  11433. box.hide();
  11434. });
  11435. };
  11436. // 下载模板
  11437. $scope.download = function() {
  11438. window.location.href = 'deputyOrder/upload/template';
  11439. };
  11440. $scope.enSure = function() {
  11441. $modalInstance.close($scope.result.items);
  11442. }
  11443. $scope.cancel = function() {
  11444. $modalInstance.dismiss();
  11445. }
  11446. }]);
  11447. /**
  11448. * 代采详情
  11449. */
  11450. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal) {
  11451. BaseService.scrollBackToTop();
  11452. var loadData = function() {
  11453. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  11454. $scope.deOrder = data;
  11455. $scope.deOrder.$editing = false;
  11456. });
  11457. };
  11458. loadData();
  11459. // 查询历史供应商
  11460. DeputyOrder.hisvendors({}, function(data) {
  11461. $scope.hisvendors = data;
  11462. }, function(response) {
  11463. toaster.pop('error', '提示', response.data);
  11464. });
  11465. // 代采企业列表
  11466. DeputyOrder.deputyEnterprise({}, function(data) {
  11467. $scope.deputyEnterprises = data;
  11468. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  11469. // 费率
  11470. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  11471. $scope.rate = data;
  11472. }, function(response){
  11473. });
  11474. });
  11475. // 更新代采企业时更新费率
  11476. $scope.change = function(deputyuu) {
  11477. // 费率
  11478. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  11479. $scope.rate = data;
  11480. }, function(response){
  11481. });
  11482. }
  11483. // 查找付款企业
  11484. $scope.dbfindPayCompany = function(deputyuu) {
  11485. var modalInstance = $modal.open({
  11486. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  11487. controller: 'DbfindDeputyPayCompanyCtrl',
  11488. resolve: {
  11489. deputyuu: function() {return deputyuu}
  11490. }
  11491. });
  11492. modalInstance.result.then(function(data) {
  11493. $scope.deOrder.paycomname = data.enname;
  11494. $scope.deOrder.paycomaddress = data.address;
  11495. })
  11496. }
  11497. // 删除明细
  11498. $scope.del = function(index, id) {
  11499. DeputyOrder.deleteProdById({id: id}, {}, function(data) {
  11500. if(data.success) {
  11501. toaster.pop('success', '提示', data.success);
  11502. $scope.deOrder.deputyOrderItems.splice(index, 1)
  11503. }
  11504. if(data.error) {
  11505. toaster.pop('error', '提示', data.error);
  11506. }
  11507. $scope.deOrder.totalamount = 0;
  11508. $scope.deOrder.usdpayment = 0;
  11509. $scope.deOrder.orderamount = 0;
  11510. $scope.deOrder.totalpayament = 0;
  11511. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11512. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11513. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11514. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11515. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11516. });
  11517. }, function(response) {
  11518. toaster.pop('error', '提示', response.data);
  11519. });
  11520. }
  11521. //增加商品
  11522. $scope.add = function(index) {
  11523. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  11524. toaster.pop('info', '提示', '请先填写商品信息');
  11525. }else {
  11526. $scope.deOrder.deputyOrderItems.push(
  11527. { prodname: null,
  11528. prodcode: null,
  11529. prodspec: null,
  11530. prodbrand: null,
  11531. amount: null,
  11532. unitprice: null,
  11533. remark: null,
  11534. orderprice: null});
  11535. }
  11536. };
  11537. // 导入商品信息
  11538. $scope.uplodaByBatch = function() {
  11539. var modalInstance = $modal.open({
  11540. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  11541. controller: 'DeputyOrderUploadCtrl',
  11542. size: 'lg',
  11543. resolve: {
  11544. }
  11545. });
  11546. modalInstance.result.then(function(data) {
  11547. angular.forEach(data, function(data) {
  11548. $scope.deOrder.deputyOrderItems.push(data);
  11549. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  11550. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  11551. $scope.deOrder.deputyOrderItems.splice(i, 1);
  11552. }
  11553. }
  11554. })
  11555. $scope.deOrder.totalamount = 0;
  11556. $scope.deOrder.usdpayment = 0;
  11557. $scope.deOrder.orderamount = 0;
  11558. $scope.deOrder.totalpayament = 0;
  11559. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11560. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11561. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11562. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11563. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11564. });
  11565. }, function(){
  11566. });
  11567. }
  11568. //删除商品
  11569. $scope.delItem = function(index) {
  11570. $scope.deOrder.deputyOrderItems.splice(index, 1);
  11571. };
  11572. var getService = function() {
  11573. return DeputyOrder.getProdList;
  11574. };
  11575. $scope.update = function() {
  11576. $scope.deOrder.$editing = true;
  11577. }
  11578. $scope.cancel = function() {
  11579. $scope.deOrder.$editing = false;
  11580. }
  11581. // 检验订单编号是否存在
  11582. $scope.checkOrder = function(salecode, deputyuu) {
  11583. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  11584. if(data.info) {
  11585. toaster.pop('error', '提示', data.info);
  11586. }
  11587. }, function(response) {
  11588. toaster.pop('error', '提示', response.data);
  11589. })
  11590. }
  11591. // 保存
  11592. $scope.save = function() {
  11593. $scope.deOrder.entrystatus = '保存';
  11594. $scope.deOrder.totalamount = 0;
  11595. $scope.deOrder.usdpayment = 0;
  11596. $scope.deOrder.orderamount = 0;
  11597. $scope.deOrder.totalpayament = 0;
  11598. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11599. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11600. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11601. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11602. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11603. });
  11604. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  11605. toaster.pop('info', '提示', '您还未填写任何商品信息');
  11606. } else {
  11607. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11608. if(data.id) {
  11609. toaster.pop('success', '提示', '保存成功');
  11610. loadData();
  11611. }
  11612. if(data.error) {
  11613. toaster.pop('error', '提示', '保存失败');
  11614. }
  11615. }, function(response) {
  11616. });
  11617. }
  11618. }
  11619. // 提交
  11620. $scope.submit = function() {
  11621. $scope.deOrder.entrystatus = '已提交';
  11622. $scope.deOrder.totalamount = 0;
  11623. $scope.deOrder.usdpayment = 0;
  11624. $scope.deOrder.orderamount = 0;
  11625. $scope.deOrder.totalpayament = 0;
  11626. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  11627. $scope.deOrder.totalamount += item.amount * item.unitprice;
  11628. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  11629. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  11630. $scope.deOrder.orderamount += item.amount * item.unitprice * (1 + $scope.rate.rate/100);
  11631. });
  11632. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  11633. if(data.id) {
  11634. window.location.hash = "#/purc/deputy/"+data.id;
  11635. }
  11636. if(data.error) {
  11637. toaster.pop('error', '提示', '保存失败');
  11638. }
  11639. }, function(response) {
  11640. });
  11641. }
  11642. $scope.openDatePicker = function($event, deOrder, openParam) {
  11643. $event.preventDefault();
  11644. $event.stopPropagation();
  11645. deOrder[openParam] = !deOrder[openParam];
  11646. };
  11647. }]);
  11648. /**
  11649. * 代采错误日志
  11650. */
  11651. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  11652. BaseService.scrollBackToTop();
  11653. var getService = function() {
  11654. return DeputyOrder.getRepetitions;
  11655. };
  11656. $scope.tableParams = new ngTableParams({
  11657. page : 1,
  11658. count : 5,
  11659. sorting: {
  11660. }
  11661. }, {
  11662. total : 0,
  11663. counts: [5, 10, 25, 50],
  11664. getData : function($defer, params) {
  11665. $scope.loading = true;
  11666. var pageParams = params.url();
  11667. pageParams.keyword = $scope.keyword;
  11668. pageParams.searchFilter = $scope.searchFilter;
  11669. getService().call(null, BaseService.parseParams(pageParams), function(page){
  11670. $scope.loading = false;
  11671. if(page) {
  11672. params.total(page.totalElement);
  11673. $defer.resolve(page.content);
  11674. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11675. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  11676. }
  11677. }, function(response) {
  11678. $scope.loading = false;
  11679. toaster.pop('error', '数据加载失败', response.data);
  11680. });
  11681. }
  11682. });
  11683. // 搜索框回车
  11684. $scope.onSearch = function() {
  11685. $scope.tableParams.page(1);
  11686. $scope.tableParams.reload();
  11687. };
  11688. //删除
  11689. $scope.deleteById = function(id) {
  11690. GetProductInfo.deleteById({id: id}, function(data) {
  11691. if(data.error) {
  11692. toaster.pop("error", "提示", data.error);
  11693. } else {
  11694. toaster.pop("success", "提示", "删除成功");
  11695. $timeout(function() {
  11696. $scope.tableParams.reload();
  11697. }, 500);
  11698. }
  11699. }), function(response) {
  11700. toaster.pop("error", "删除失败", response.data);
  11701. };
  11702. }
  11703. }]);
  11704. /**
  11705. * 招标单
  11706. */
  11707. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  11708. BaseService.scrollBackToTop();
  11709. $scope.active = 'done';
  11710. if ($rootScope.tenderActive) {
  11711. $scope.active = $rootScope.tenderActive;
  11712. }
  11713. $scope.dateZoneText = '不限';
  11714. $scope.deliveryZoneText = '不限';
  11715. $scope.condition = {dateZone: -1, deliveryZone: -1};
  11716. $scope.changeDateZone = function(zone) {
  11717. $scope.condition.dateZone = zone;
  11718. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  11719. $scope.condition.$dateZoneOpen = false;
  11720. getDateCondition(zone, $scope.condition);
  11721. $scope.tableParams.reload();
  11722. };
  11723. $scope.changeDeliveryZone = function(zone) {
  11724. $scope.condition.deliveryZoneText = zone;
  11725. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  11726. $scope.condition.$delievryZoneOpen = false;
  11727. getDelveryCondition(zone, $scope.condition);
  11728. $scope.tableParams.reload();
  11729. };
  11730. $scope.setActive = function(state) {
  11731. if($scope.active != state) {
  11732. $scope.active = state;
  11733. if($scope.tableParams.page() == 1)
  11734. $scope.tableParams.reload();
  11735. else
  11736. $scope.tableParams.page(1);
  11737. }
  11738. };
  11739. var getTenderStatus = function(active) {
  11740. var fn = 'getMyAll';
  11741. switch(active) {
  11742. case 'done':
  11743. fn = 'getMyDone';break;
  11744. case 'todo':
  11745. fn = 'getMyTodo';break;
  11746. // case 'end':
  11747. // fn = 'getMyEnd';break;
  11748. case 'waiting':
  11749. fn = 'getMyWaiting';break;
  11750. }
  11751. return fn;
  11752. }
  11753. $scope.tableParams = new ngTableParams({
  11754. page : 1,
  11755. count : 5,
  11756. sorting: {
  11757. 'tender.endDate': 'desc',
  11758. 'tender.enterprise.enName': 'asc',
  11759. 'tender.code': 'asc'
  11760. }
  11761. }, {
  11762. total : 0,
  11763. counts: [5, 10, 25, 50],
  11764. getData : function($defer, params) {
  11765. $scope.loading = true;
  11766. var pageParams = params.url();
  11767. var realActive = {};
  11768. pageParams.searchFilter = { // 筛选条件
  11769. keyword: $scope.keyword,
  11770. fromDate: getDateTime($scope.condition.dateFrom),
  11771. endDate: getDateTime($scope.condition.dateTo)
  11772. };
  11773. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11774. $scope.loading = false;
  11775. if(page) {
  11776. params.total(page.totalElement);
  11777. $defer.resolve(page.content);
  11778. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  11779. }
  11780. }, function(response){
  11781. $scope.loading = false;
  11782. toaster.pop('error', '数据加载失败', response.data);
  11783. });
  11784. }
  11785. });
  11786. $scope.openDatePicker = function($event, item, openParam) {
  11787. $event.preventDefault();
  11788. $event.stopPropagation();
  11789. item[openParam] = !item[openParam];
  11790. };
  11791. $scope.parseDate = function(dateStr) {
  11792. if(dateStr)
  11793. return Date.parse(dateStr, 'yyyy-MM-dd');
  11794. return new Date();
  11795. };
  11796. // 选择查找日期
  11797. $scope.onDateCondition = function(){
  11798. $scope.tableParams.page(1);
  11799. $scope.tableParams.reload();
  11800. };
  11801. // 搜索框回车
  11802. $scope.onSearch = function() {
  11803. $scope.tableParams.page(1);
  11804. $scope.tableParams.reload();
  11805. };
  11806. }]);
  11807. /**
  11808. * 新增招标单
  11809. */
  11810. 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) {
  11811. // 录入人
  11812. AuthenticationService.getAuthentication().success(function(data) {
  11813. $scope.user = data;
  11814. });
  11815. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  11816. var getService = function() {
  11817. return GetProductInfo;
  11818. };
  11819. // 物料信息
  11820. $scope.tableParams = new ngTableParams({
  11821. page : 1,
  11822. count : 5,
  11823. sorting: {
  11824. }
  11825. }, {
  11826. total : 0,
  11827. counts: [5, 10, 25, 50],
  11828. getData : function($defer, params) {
  11829. $scope.loading = true;
  11830. var pageParams = params.url();
  11831. pageParams.keyword = $scope.keyword;
  11832. $scope.tip = $scope.keyword;
  11833. pageParams.searchFilter = $scope.searchFilter;
  11834. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11835. $scope.loading = false;
  11836. if(page) {
  11837. params.total(page.totalElement);
  11838. $scope.total = page.totalElement;
  11839. $defer.resolve(page.content);
  11840. }
  11841. }, function(response) {
  11842. $scope.loading = false;
  11843. toaster.pop('error', '数据加载失败', response.data);
  11844. });
  11845. }
  11846. });
  11847. // 搜索框回车
  11848. $scope.onSearch = function(keyword) {
  11849. $scope.tableParams.page(1);
  11850. $scope.tableParams.reload();
  11851. };
  11852. //在产品列表添加商品
  11853. $scope.check = function(product) {
  11854. $scope.tenderProd.push({
  11855. prodTitle: product.title,
  11856. prodCode: product.code,
  11857. brand: product.brand,
  11858. unit: product.unit,
  11859. qty: null
  11860. // 供应商企业信息
  11861. // enterpriseBaseInfo: [{}]
  11862. });
  11863. for(var i = 0; i < $scope.tenderProd.length; i++) {
  11864. if($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  11865. $scope.tenderProd.splice(i, 1);
  11866. }
  11867. }
  11868. };
  11869. $scope.loading = false;
  11870. // 获取收货地址列表
  11871. var loadShipAddress = function() {
  11872. ShipAddress.shipAddList({}, function(data) {
  11873. $scope.ships = data;
  11874. $scope.tender.shipadd = $scope.ships[0];
  11875. });
  11876. };
  11877. loadShipAddress();
  11878. // 获取地址信息
  11879. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  11880. }).then(function(response) {
  11881. $scope.provinces = response.data;
  11882. });
  11883. // 新增收货地址保存
  11884. $scope.saveShipAddress = function(ship) {
  11885. ship.address = ship.province + ship.city + ship.district;
  11886. ShipAddress.saveAddress( {}, ship, function(data) {
  11887. if(data.success) {
  11888. // 获取收货地址列表
  11889. loadShipAddress();
  11890. toaster.pop('success', '提示', data.success);
  11891. }
  11892. if(data.error) {
  11893. toaster.pop('error', '提示', data.error);
  11894. }
  11895. });
  11896. };
  11897. // 可选的证照要求
  11898. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  11899. // 处理证照要求
  11900. var parseCertificate = function(a) {
  11901. if (a) {
  11902. var arr = a.split(',');
  11903. angular.forEach(arr, function(app) {
  11904. var contained = false;
  11905. angular.forEach($scope.certificates, function($app) {
  11906. if($app.name == app) {
  11907. $app.checked = true;
  11908. contained = true;
  11909. }
  11910. });
  11911. if(!contained) {
  11912. $scope.certificates.push({name: app, checked: true});
  11913. }
  11914. });
  11915. }
  11916. };
  11917. // 联想词start
  11918. // 获取品牌联想词
  11919. $scope.getSimilarBrands = function(value) {
  11920. if (value) {
  11921. // 获取品牌联想词
  11922. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  11923. return data.map(function(item) {
  11924. return item;
  11925. });
  11926. });
  11927. }
  11928. };
  11929. // 获取产品型号联想词
  11930. $scope.getSimilarCodes = function(value) {
  11931. if (value) {
  11932. // 获取产品型号联想词
  11933. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  11934. return data.map(function (item) {
  11935. return item;
  11936. })
  11937. });
  11938. }
  11939. };
  11940. // // 获取产品类目联想词
  11941. // $scope.getSimilarKinds = function(value) {
  11942. // if (value) {
  11943. // // getSimilarLeafKinds 根据类目名获取末级联想词
  11944. // // 获取类目联想词
  11945. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  11946. // return data.map(function(item) {
  11947. // return item;
  11948. // })
  11949. // });
  11950. // }
  11951. // };
  11952. // // 点击联想词获取类目信息
  11953. // $scope.onAssociateKindClick = function(kind, submit) {
  11954. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  11955. // $scope.actives = data;
  11956. // console.log(data);
  11957. // var size = data.length;
  11958. // if (size > 0) {
  11959. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  11960. // submit.kiName = submit.gradeOneKiName;
  11961. // if (size > 1) {
  11962. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  11963. // submit.kiName = submit.gradeTwoKiName;
  11964. // if (kind.level < 3) {
  11965. // submit.gradeThreeKiName = null;
  11966. // } else if (size > 2) {
  11967. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  11968. // submit.kiName = submit.gradeThreeKiName;
  11969. // }
  11970. // }
  11971. // }
  11972. // console.log(submit);
  11973. // })
  11974. // };
  11975. // 选择类目
  11976. $scope.selectKind = function(prod) {
  11977. var submit = [];
  11978. $modal.open({
  11979. animation: true,
  11980. size: 'lg',
  11981. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  11982. controller: 'ProdKindChooseCtrl',
  11983. resolve: {
  11984. actives: function() {
  11985. return $scope.actives;
  11986. }
  11987. }
  11988. }).result.then(function(data){
  11989. $scope.actives = data.actives;
  11990. var size = data.actives.length;
  11991. submit.gradeOneKiName = '';
  11992. submit.gradeTwoKiName = '';
  11993. submit.gradeThreeKiName = '';
  11994. if (size > 0) {
  11995. submit.gradeOneKiName = $scope.actives[0].nameCn;
  11996. prod.prodTitle = submit.gradeOneKiName;
  11997. if (size > 1) {
  11998. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  11999. prod.prodTitle = submit.gradeTwoKiName;
  12000. if (size > 2) {
  12001. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  12002. prod.prodTitle = submit.gradeThreeKiName;
  12003. }
  12004. }
  12005. }
  12006. }, function(){
  12007. });
  12008. };
  12009. // // 验证分类信息
  12010. // $scope.checkKind = function() {
  12011. // setTimeout(function() {
  12012. // if($scope.activesString == null) {
  12013. // $scope.component.kindid = null;
  12014. // return;
  12015. // }
  12016. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  12017. // $scope.component.kind = kind;
  12018. // $scope.component.kindid = kind.id;
  12019. // $scope.activesString = $scope.component.kind.nameCn;
  12020. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  12021. // $scope.kindProperties = data;
  12022. // angular.forEach($scope.kindProperties, function(kp) {
  12023. // angular.forEach($scope.component.properties, function(pro) {
  12024. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  12025. // kp.value = pro.value;
  12026. // }
  12027. // });
  12028. // });
  12029. // }, function(response) {
  12030. // });
  12031. // }, function (response) {
  12032. // $scope.component.kindid = null;
  12033. // toaster.pop('error', response.data);
  12034. // });
  12035. // }, 500);
  12036. // };
  12037. // 点击联想词获取品牌信息
  12038. $scope.onAssociateBrandClick = function(brand, prod) {
  12039. if (brand instanceof String) {
  12040. prod.brand = brand;
  12041. } else if (brand instanceof Object) {
  12042. prod.brand = brand.brandCn;
  12043. }
  12044. };
  12045. // 打开品牌选择的模态框
  12046. $scope.selectBrand = function(prod){ //打开模态
  12047. var modalInstance = $modal.open({
  12048. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  12049. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  12050. });
  12051. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  12052. });
  12053. modalInstance.result.then(function(brand){
  12054. prod.brand = brand.nameCn;
  12055. }, function(reason){
  12056. });
  12057. };
  12058. // // 验证品牌是否正确
  12059. // $scope.checkBrand = function () {
  12060. // setTimeout(function () {
  12061. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  12062. // // $scope.component.brand = brand;
  12063. // // $scope.component.brandid = brand.id;
  12064. // }, function (response) {
  12065. // // $scope.component.brandid = null;
  12066. // toaster.pop('error', response.data);
  12067. // })
  12068. // } , 500);
  12069. // };
  12070. // 点击联想词获取器件信息 带入产品分类和品牌
  12071. $scope.onAssociateCmpClick = function(cmp, prod) {
  12072. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  12073. $scope.component = data;
  12074. prod.prodCode = data.code;
  12075. prod.prodTitle = data.kind.nameCn;
  12076. prod.brand = data.brand.nameCn;
  12077. }, function(res) {
  12078. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  12079. })
  12080. };
  12081. //联想词end
  12082. $scope.condition = {dateZone: 1};
  12083. $scope.tenderProd = [];
  12084. var prod = {
  12085. prodTitle: null,
  12086. prodCode: null,
  12087. brand: null,
  12088. unit: 'PCS',
  12089. qty: null
  12090. // 供应商企业信息
  12091. // enterpriseBaseInfo: [{}]
  12092. };
  12093. $scope.tender = {
  12094. date: new Date(),
  12095. unit: 'PCS',
  12096. currency: 'RMB',
  12097. ifOpen: 1,
  12098. ifTax: 1,
  12099. invoiceType: 2,
  12100. tenderAttachs:[{}]
  12101. };
  12102. //
  12103. $scope.tenderProd.push(prod);
  12104. //增加商品
  12105. $scope.add = function(index) {
  12106. $scope.tenderProd.push({
  12107. prodTitle: null,
  12108. prodCode: null,
  12109. brand: null,
  12110. unit: 'PCS',
  12111. qty: null
  12112. // 供应商企业信息
  12113. // enterpriseBaseInfo: [{}]
  12114. });
  12115. };
  12116. //删除商品
  12117. $scope.del = function(index) {
  12118. $scope.tenderProd.splice(index, 1);
  12119. };
  12120. // 批量导入
  12121. $scope.uplodaByBatch = function() {
  12122. var modalInstance = $modal.open({
  12123. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  12124. controller: 'PurcTenderUploadCtrl',
  12125. size: 'lg',
  12126. resolve: {
  12127. }
  12128. });
  12129. modalInstance.result.then(function(data) {
  12130. // 获取上传的产品明细,前台展示
  12131. angular.forEach(data, function(data) {
  12132. $scope.tenderProd.push(data);
  12133. for(var i = 0; i < $scope.tenderProd.length; i++) {
  12134. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  12135. $scope.tenderProd.splice(i, 1);
  12136. }
  12137. }
  12138. });
  12139. }, function(){
  12140. });
  12141. };
  12142. $scope.isSave = false;
  12143. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  12144. if( ! angular.isUndefined($stateParams.id)) {
  12145. $scope.isSave = true; // 用于判断是新增还是已保存
  12146. $scope.loading = true;
  12147. PurcTender.getOne({id: $stateParams.id}, function(data){
  12148. data.$editing = false;
  12149. $scope.tender = data;
  12150. $scope.tenderProd = data.purchaseTenderProds;
  12151. parseCertificate($scope.tender.certificate);
  12152. $scope.firstProd = data.purchaseTenderProds[0];
  12153. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  12154. // 获取供应商联系人
  12155. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function(data) {
  12156. item.saleTender.enterpriseBaseInfo.contacts = data;
  12157. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  12158. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function(contact) {
  12159. if (item.saleTender.userTel === contact.tel) {
  12160. item.saleTender.enterpriseBaseInfo.contact = contact;
  12161. }
  12162. });
  12163. });
  12164. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  12165. $scope.tenderProd.enterpriseBaseInfo = [{}];
  12166. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  12167. } else {
  12168. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  12169. }
  12170. });
  12171. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  12172. $scope.loading = false;
  12173. $scope.attaches = $scope.tender.tenderAttaches;
  12174. }, function(response){
  12175. $scope.loading = false;
  12176. toaster.pop('error', '数据加载失败', response.data);
  12177. });
  12178. }
  12179. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  12180. $rootScope.tenderVendor = [{}];
  12181. }
  12182. $scope.changeShipAddress = false;
  12183. $scope.changeAddress = function() {
  12184. if ($scope.changeShipAddress) {
  12185. $scope.changeShipAddress = false;
  12186. } else {
  12187. $scope.changeShipAddress = true;
  12188. }
  12189. };
  12190. $scope.changeContactInfo = function(en) {
  12191. if (en.changeContact) {
  12192. en.changeContact = false;
  12193. } else {
  12194. en.changeContact = true;
  12195. }
  12196. };
  12197. $scope.changeCurrency = function(tender) {
  12198. if (tender.currency !== 'RMB') {
  12199. $scope.notRMB = true;
  12200. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  12201. tender.invoiceType = 0;
  12202. } else {
  12203. $scope.notRMB = false;
  12204. }
  12205. };
  12206. // $scope.validateNumber = function (value) { // 采购数量 正整数
  12207. // var regex = /^\+?[1-9][0-9]*$/;
  12208. // if (!regex.test(value) || value === 0 || value === null) {
  12209. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  12210. // }
  12211. // };
  12212. // 查找供应商
  12213. $scope.dbfindVendor = function(){
  12214. var modalInstance = $modal.open({
  12215. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  12216. controller: 'DbfindVendorCtrl',
  12217. size: 'lg',
  12218. resolve: {
  12219. }
  12220. });
  12221. var ifPush = true;
  12222. modalInstance.result.then(function(data){
  12223. angular.forEach(data, function(vendor) {
  12224. // 获取供应商联系人
  12225. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function(data) {
  12226. vendor.vendorEnterprise.contacts = data;
  12227. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  12228. });
  12229. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  12230. $scope.tenderProd.enterpriseBaseInfo = [{}];
  12231. // 获取供应商联系人
  12232. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  12233. } else {
  12234. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  12235. ifPush = true;
  12236. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  12237. ifPush = false;
  12238. break; // 判定到已存在供应商,就终止循环。
  12239. }
  12240. }
  12241. if (ifPush) {
  12242. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  12243. }
  12244. }
  12245. });
  12246. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  12247. }, function(){
  12248. });
  12249. };
  12250. // 新增供应商联系人
  12251. $scope.addContact = function(en) {
  12252. var modalInstance = $modal.open({
  12253. animation: true,
  12254. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  12255. controller: 'AddContacCtrl',
  12256. resolve: {
  12257. }
  12258. });
  12259. modalInstance.result.then(function(data) {
  12260. en.contact = data;
  12261. en.contact.venduu = en.uu;
  12262. Vendor.saveContact({}, en.contact, function(data) {
  12263. Vendor.contacts({venduu: en.uu}, {}, function(data) {
  12264. en.contacts = data;
  12265. en.contact = data[0]; // 新增的作为联系人
  12266. });
  12267. toaster.pop('success', '提示', '联系人保存成功');
  12268. }, function(response) {
  12269. toaster.pop('error', '失败', response.data);
  12270. });
  12271. });
  12272. };
  12273. // 删除一个供应商
  12274. $scope.removeVendor = function(index) {
  12275. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  12276. };
  12277. // 删除供应商时,后台删除投标单
  12278. $scope.removeSaleTender = function (id, vendUU) {
  12279. var hasSaved = false;
  12280. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  12281. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  12282. hasSaved = true;
  12283. }
  12284. });
  12285. if (hasSaved) {
  12286. PurcTender.removeSaleTender ({id : id, vendUU : vendUU}, {}, function(data) {
  12287. }, function(response) {
  12288. toaster.pop('error', '提示', response.data);
  12289. });
  12290. }
  12291. };
  12292. // 删除产品明细时,后台删除产品明细
  12293. $scope.deleteProd = function (tenderProd) {
  12294. if (tenderProd.id) {
  12295. PurcTender.deleteProd ({tenderProdId : tenderProd.id}, {}, function(data) {
  12296. }, function(response) {
  12297. toaster.pop('error', '提示', response.data);
  12298. });
  12299. }
  12300. };
  12301. // // 查找客户物料
  12302. // $scope.dbfindCustProd = function(){
  12303. // if($scope.item.$editing) {
  12304. // if($scope.item.quotation.cust.uu) {
  12305. // var modalInstance = $modal.open({
  12306. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  12307. // controller: 'DbfindCustProdCtrl',
  12308. // size: 'lg',
  12309. // resolve: {
  12310. // custUU: function(){return $scope.item.quotation.cust.uu}
  12311. // }
  12312. // });
  12313. //
  12314. // modalInstance.result.then(function(data){
  12315. // $scope.item.product = data;
  12316. // }, function(){
  12317. //
  12318. // });
  12319. // } else {
  12320. // toaster.pop('error', '错误', '请先选择客户');
  12321. // }
  12322. // }
  12323. // };
  12324. if (!$scope.attaches) {
  12325. $scope.attaches = []; // 存放上传了的附件
  12326. }
  12327. $scope.upload = function(myFile) { // 上传附件
  12328. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  12329. $upload.upload({
  12330. url: 'tender/addTenderAttach',
  12331. file: file,
  12332. method: 'POST'
  12333. // data: {
  12334. // tender: $scope.tender
  12335. // }
  12336. }).success(function (attach) {
  12337. $scope.attaches.push(attach);
  12338. });
  12339. };
  12340. $scope.removeAttach = function(id, index) {
  12341. $scope.attaches.splice(index, 1);
  12342. // PurcTender.removeAttach({attachId:id}, function() {
  12343. //
  12344. // });
  12345. };
  12346. var sleep = function (d){
  12347. for(var t = Date.now();Date.now() - t <= d;);
  12348. };
  12349. // 保存和发布招标单
  12350. $scope.save = function(isPublish){
  12351. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  12352. toaster.pop('info','提示','请先指定供应商');
  12353. } else {
  12354. $scope.loading = true;
  12355. // --组装证照要求
  12356. var myCertificate = [];
  12357. angular.forEach($scope.certificates, function(certificate) {
  12358. if (certificate.checked) {
  12359. myCertificate.push(certificate.name);
  12360. }
  12361. });
  12362. $scope.tender.certificate = myCertificate.join(',');
  12363. if(!$scope.tender.code) { //新增,设单号
  12364. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  12365. }
  12366. if($scope.tender.date instanceof Date) {
  12367. $scope.tender.date = $scope.tender.date.getTime();
  12368. }
  12369. if($scope.tender.endDate instanceof Date) {
  12370. $scope.tender.endDate = $scope.tender.endDate.getTime();
  12371. }
  12372. if($scope.tender.publishDate instanceof Date) {
  12373. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  12374. }
  12375. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  12376. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  12377. $scope.tender.purchaseTenderProds[i].index = i + 1;
  12378. }
  12379. $scope.tender.tenderAttaches = $scope.attaches;
  12380. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  12381. var enInfos = [];
  12382. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  12383. var enInfo = {
  12384. uu: null,
  12385. contact: null,
  12386. contactTel: null
  12387. };
  12388. enInfo.uu = enterpriseBaseInfo.uu;
  12389. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  12390. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  12391. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  12392. }
  12393. enInfos.push(enInfo);
  12394. });
  12395. if (isPublish) { // 发布
  12396. toaster.pop('info', '提示', '正在发布,请稍候');
  12397. $scope.tender.isPublish = 1;
  12398. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  12399. // sleep(1500); //当前方法暂停1.5秒
  12400. $scope.loading = false;
  12401. toaster.pop('success', '成功', '发布成功');
  12402. window.location.hash = '#/purc/tender';
  12403. }, function(response){
  12404. $scope.loading = false;
  12405. toaster.pop('error', '发布失败', response.data);
  12406. });
  12407. } else { // 保存
  12408. toaster.pop('info', '提示', '正在保存,请稍候');
  12409. $scope.tender.isPublish = 0;
  12410. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  12411. $scope.loading = false;
  12412. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  12413. toaster.pop('success', '成功', '保存成功');
  12414. window.location.hash = '#/purc/tender';
  12415. }, function(response){
  12416. $scope.loading = false;
  12417. toaster.pop('error', '保存失败', response.data);
  12418. });
  12419. }
  12420. }
  12421. };
  12422. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  12423. $scope.removeChecked = function() {
  12424. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  12425. $scope.tenderProd.enterpriseBaseInfo = [];
  12426. }
  12427. };
  12428. // 删除(在录入状态)
  12429. $scope.deleteThis = function(id) {
  12430. PurcTender.deleteOne({id:id}, {}, function(data) {
  12431. toaster.pop('info', '提示', '删除成功');
  12432. window.location.hash = '#/purc/tender';
  12433. });
  12434. };
  12435. // 更新和发布(在录入状态)
  12436. $scope.updateSaved = function(isPublish){
  12437. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  12438. toaster.pop('info','提示','请先指定供应商');
  12439. } else {
  12440. $scope.loading = true;
  12441. // --组装证照要求
  12442. var myCertificate = [];
  12443. angular.forEach($scope.certificates, function(certificate) {
  12444. if (certificate.checked) {
  12445. myCertificate.push(certificate.name);
  12446. }
  12447. });
  12448. $scope.tender.certificate = myCertificate.join(',');
  12449. if($scope.tender.endDate instanceof Date) {
  12450. $scope.tender.endDate = $scope.tender.endDate.getTime();
  12451. }
  12452. if($scope.tender.publishDate instanceof Date) {
  12453. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  12454. }
  12455. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  12456. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  12457. $scope.tender.purchaseTenderProds[i].index = i + 1;
  12458. }
  12459. $scope.tender.tenderAttaches = $scope.attaches;
  12460. if ($scope.tender.shipadd) {
  12461. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  12462. }
  12463. angular.forEach($scope.tender.purchaseTenderProds, function(tenderProd){
  12464. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  12465. });
  12466. var enInfos = [];
  12467. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  12468. var enInfo = {
  12469. uu: null,
  12470. contact: null,
  12471. contactTel: null
  12472. };
  12473. enInfo.uu = enterpriseBaseInfo.uu;
  12474. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  12475. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  12476. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  12477. }
  12478. enInfos.push(enInfo);
  12479. });
  12480. if (isPublish) { // 发布
  12481. toaster.pop('info', '提示', '正在发布,请稍候');
  12482. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  12483. sleep(1500); //当前方法暂停1.5秒
  12484. // $scope.loading = false;
  12485. toaster.pop('success', '成功', '发布成功');
  12486. window.location.hash = '#/purc/tender';
  12487. }, function(response){
  12488. $scope.loading = false;
  12489. toaster.pop('error', '发布失败', response.data);
  12490. });
  12491. } else { // 保存
  12492. toaster.pop('info', '提示', '正在保存,请稍候');
  12493. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  12494. $scope.loading = false;
  12495. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  12496. toaster.pop('success', '成功', '保存成功');
  12497. window.location.reload();
  12498. }, function(response){
  12499. $scope.loading = false;
  12500. toaster.pop('error', '保存失败', response.data);
  12501. });
  12502. }
  12503. }
  12504. };
  12505. $scope.currentDay = function() {
  12506. return $filter('date')(new Date(), 'yyyy-MM-dd');
  12507. };
  12508. $scope.getMinDate = function() {
  12509. // var now = new Date();
  12510. // now = now.setDate(now.getDate()+1);
  12511. // var minDate = angular.copy($scope.tender.endDate);
  12512. // minDate = minDate.setDate(minDate.getDate() + 1);
  12513. if ($scope.tender.endDate instanceof Date) {
  12514. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  12515. }
  12516. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  12517. };
  12518. $scope.getMaxDate = function() {
  12519. // var maxDate = angular.copy($scope.tender.publishDate);
  12520. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  12521. if ($scope.tender.publishDate instanceof Date) {
  12522. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  12523. }
  12524. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  12525. };
  12526. $scope.openDatePicker = function($event, item, openParam) {
  12527. $event.preventDefault();
  12528. $event.stopPropagation();
  12529. item[openParam] = !item[openParam];
  12530. };
  12531. }]);
  12532. //类目选择模态框(招标产品明细)
  12533. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  12534. $scope.actives = actives;
  12535. $scope.kinds = [[], [], [], []];
  12536. // 获取子类目
  12537. var getChildren = function(pid, deep) {
  12538. KindAPI.getChildren({parentId: pid}, function(data) {
  12539. $scope.kinds[deep] = data;
  12540. }, function(response) {
  12541. toaster.pop('error', '获取子类目失败', response.data);
  12542. });
  12543. };
  12544. // 改变节点选中状态
  12545. var changeStatus = function(item, deep) {
  12546. var actives = [], level = 0;
  12547. angular.forEach($scope.kinds, function(ks, i) {
  12548. if(i > deep) {
  12549. $scope.kinds[i] = [];
  12550. } else {
  12551. angular.forEach(ks, function(k, j) {
  12552. if(i == deep) {
  12553. if(k.id == item.id) {
  12554. $scope.kinds[i][j].$active = true;
  12555. actives.push(k);
  12556. } else {
  12557. k.$active = null;
  12558. }
  12559. } else {
  12560. if(k.$active) {
  12561. actives.push(k);
  12562. }
  12563. }
  12564. });
  12565. }
  12566. });
  12567. // 选择的节点
  12568. $scope.actives = actives;
  12569. $scope.active = item;
  12570. // 当前可操作的层级
  12571. if(deep < 3) {
  12572. $scope.activeDeep = deep + 1;
  12573. }
  12574. };
  12575. // 节点点击后获取子类目,节点被选中
  12576. $scope.onItemClick = function(item, deep) {
  12577. changeStatus(item, deep);
  12578. if (!item.isLeaf) {
  12579. getChildren(item.id, deep + 1);
  12580. }
  12581. };
  12582. // 重新加载数据
  12583. function reload(deep) {
  12584. var pid;
  12585. if(deep) {
  12586. pid = $scope.actives[deep - 1].id;
  12587. } else {
  12588. pid = 0;
  12589. deep = 0;
  12590. }
  12591. getChildren(pid, deep);
  12592. }
  12593. // 初始加载数据,获取第一层的类目
  12594. if($scope.actives) {
  12595. angular.forEach($scope.actives, function(v, k) {
  12596. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  12597. $scope.kinds[k] = data;
  12598. angular.forEach($scope.kinds[k], function(kind, i){
  12599. if(kind.id == v.id) {
  12600. $scope.kinds[k][i].$active = true;
  12601. $scope.actives[k] = $scope.kinds[k][i];
  12602. }
  12603. })
  12604. }, function(response) {
  12605. toaster.pop('error', '获取子类目失败', response.data);
  12606. });
  12607. });
  12608. } else {
  12609. reload();
  12610. }
  12611. // 取消
  12612. $scope.cancel = function() {
  12613. $modalInstance.dismiss();
  12614. };
  12615. // 确认选择
  12616. $scope.check = function() {
  12617. var a = {
  12618. active: $scope.active,
  12619. actives: $scope.actives
  12620. };
  12621. $modalInstance.close(a);
  12622. };
  12623. }]);
  12624. //品牌选择模态框的controller
  12625. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  12626. $scope.filter = {};
  12627. $scope.brandsTableParams = new ngTableParams({
  12628. page : 1,
  12629. count : 6,
  12630. sorting : {
  12631. nameCn: 'asc'
  12632. }
  12633. }, {
  12634. total : 0,
  12635. counts : [],
  12636. getData : function($defer, params) {
  12637. var param = BaseService.parseParams(params.url());
  12638. param.keyword = $scope.filter.keyword;
  12639. var keyword = $scope.filter.keyword;
  12640. // param.keyword = $scope.filter.keyword;
  12641. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  12642. if (page) {
  12643. params.total(page.totalElements);
  12644. $defer.resolve(page.content);
  12645. }
  12646. }, function(){
  12647. });
  12648. }
  12649. });
  12650. // 搜索
  12651. $scope.search = function() {
  12652. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  12653. $scope.brandsTableParams.page(1);
  12654. $scope.brandsTableParams.reload();
  12655. };
  12656. // 选择
  12657. $scope.select = function(brand){
  12658. $modalInstance.close(brand);
  12659. };
  12660. // 关闭
  12661. $scope.cancel = function() {
  12662. $modalInstance.dismiss();
  12663. };
  12664. }]);
  12665. /**
  12666. * 招标单批量导入
  12667. */
  12668. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  12669. // 通过excel批量上传物料
  12670. $scope.result = null;
  12671. $scope.upload = function() {
  12672. var file = $scope.myFiles[0];
  12673. $upload.upload({
  12674. url: 'tender/release/excel',
  12675. file: file,
  12676. method: 'POST'
  12677. }).success(function(data) {
  12678. $scope.result = data;
  12679. $scope.success = $scope.result.success;
  12680. $scope.total = $scope.result.total;
  12681. $scope.alters = $scope.result.alters;
  12682. }).error(function(response) {
  12683. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  12684. });
  12685. };
  12686. // 查看范例
  12687. $scope.showImg = function() {
  12688. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  12689. box.show();
  12690. box.find('img').attr('src', src);
  12691. box.find('a').click(function(){
  12692. box.hide();
  12693. });
  12694. box.dblclick(function(){
  12695. box.hide();
  12696. });
  12697. };
  12698. // 下载模板
  12699. $scope.download = function() {
  12700. window.location.href = 'tender/upload/template';
  12701. };
  12702. $scope.enSure = function() {
  12703. $modalInstance.close($scope.result.items);
  12704. }
  12705. $scope.cancel = function() {
  12706. $modalInstance.dismiss();
  12707. }
  12708. }]);
  12709. /**
  12710. * 评标
  12711. */
  12712. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  12713. BaseService.scrollBackToTop();
  12714. $scope.tenderItems = [];
  12715. // 采购方获取评标单
  12716. var evaluation = function() {
  12717. $scope.loading = true;
  12718. PurcTender.getOne({id: $stateParams.id}, function(data){
  12719. data.$editing = false;
  12720. $scope.tender = data;
  12721. $scope.tableParams = new ngTableParams({}, { dataset: data});
  12722. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  12723. $scope.loading = false;
  12724. }, function(response){
  12725. $scope.loading = false;
  12726. toaster.pop('error', '数据加载失败', response.data);
  12727. });
  12728. };
  12729. evaluation();
  12730. $scope.orderType = '';
  12731. // $scope.dir = '-';
  12732. // 改变排序顺序
  12733. $scope.changeOrder = function(type){
  12734. $scope.orderType = type;
  12735. // if(!$scope.dir || $scope.dir === '') {
  12736. // $scope.dir = '-';
  12737. // }else {
  12738. // $scope.dir = '';
  12739. // }
  12740. };
  12741. $scope.submit = function(tender) {
  12742. var canSubmit = false;
  12743. var hasDecide = false;
  12744. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  12745. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12746. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  12747. hasDecide = true;
  12748. }
  12749. });
  12750. if (hasDecide) {
  12751. canSubmit = true;
  12752. }
  12753. });
  12754. if (!canSubmit) {
  12755. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  12756. } else {
  12757. PurcTender.decide(tender, function(){
  12758. toaster.pop('success', '确认成功');
  12759. window.location.hash = '#/purc/tender';
  12760. }, function(response){
  12761. toaster.pop('error', '确认失败', response.data);
  12762. });
  12763. }
  12764. }
  12765. }]);
  12766. /**
  12767. * 客户招标
  12768. *
  12769. */
  12770. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  12771. BaseService.scrollBackToTop();
  12772. $scope.active = 'todo';
  12773. /**
  12774. * 改变类型
  12775. */
  12776. var getTypeCondition = function(zone, condition) {
  12777. if(zone == -1) {
  12778. condition.ifOpen = null;
  12779. } else if(zone == 1) {
  12780. condition.ifOpen = 1;
  12781. } else {
  12782. condition.ifOpen = 0;
  12783. }
  12784. };
  12785. $scope.dateZoneText = '不限';
  12786. $scope.typeText = '全部';
  12787. $scope.deliveryZoneText = '不限';
  12788. $scope.condition = {dateZone: -1, deliveryZone: -1, type: -1};
  12789. $scope.changeDateZone = function(zone) {
  12790. $scope.condition.dateZone = zone;
  12791. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  12792. $scope.condition.$dateZoneOpen = false;
  12793. getDateCondition(zone, $scope.condition);
  12794. $scope.tableParams.reload();
  12795. };
  12796. $scope.changeDeliveryZone = function(zone) {
  12797. $scope.condition.deliveryZoneText = zone;
  12798. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  12799. $scope.condition.$delievryZoneOpen = false;
  12800. getDelveryCondition(zone, $scope.condition);
  12801. $scope.tableParams.reload();
  12802. };
  12803. $scope.changeType = function(type) {
  12804. $scope.condition.type = type;
  12805. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  12806. getTypeCondition(type, $scope.condition);
  12807. $scope.tableParams.reload();
  12808. };
  12809. $scope.setActive = function(state) {
  12810. if($scope.active != state) {
  12811. $scope.active = state;
  12812. if($scope.tableParams.page() == 1)
  12813. $scope.tableParams.reload();
  12814. else
  12815. $scope.tableParams.page(1);
  12816. }
  12817. };
  12818. $scope.tableParams = new ngTableParams({
  12819. page : 1,
  12820. count : 5,
  12821. sorting: {
  12822. 'tender.endDate': 'desc',
  12823. 'tender.enterprise.enName': 'asc',
  12824. 'tender.code': 'asc'
  12825. }
  12826. }, {
  12827. total : 0,
  12828. counts: [5, 10, 25, 50],
  12829. getData : function($defer, params) {
  12830. $scope.loading = true;
  12831. var pageParams = params.url();
  12832. var realActive = {};
  12833. pageParams.searchFilter = { // 筛选条件
  12834. keyword: $scope.keyword,
  12835. pt_ifopen: $scope.condition.ifOpen,
  12836. fromDate: getDateTime($scope.condition.dateFrom),
  12837. endDate: getDateTime($scope.condition.dateTo)
  12838. };
  12839. AccountEnterprise.get({}, function(data){
  12840. $scope.loading = false;
  12841. $scope.currentEn = data;
  12842. });
  12843. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  12844. $scope.loading = false;
  12845. if(page) {
  12846. params.total(page.totalElement);
  12847. $defer.resolve(page.content);
  12848. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  12849. angular.forEach(page.content, function(purcTender) {
  12850. purcTender.vendorHasBid = false;
  12851. angular.forEach(purcTender.purchaseTenderProds, function(tenderProd) {
  12852. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  12853. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  12854. tenderProd.currentItem = saleTenderItem;
  12855. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  12856. purcTender.vendorHasBid = true;
  12857. }
  12858. }
  12859. });
  12860. });
  12861. });
  12862. }
  12863. }, function(response){
  12864. $scope.loading = false;
  12865. toaster.pop('error', '数据加载失败', response.data);
  12866. });
  12867. }
  12868. });
  12869. $scope.openDatePicker = function($event, item, openParam) {
  12870. $event.preventDefault();
  12871. $event.stopPropagation();
  12872. item[openParam] = !item[openParam];
  12873. };
  12874. $scope.parseDate = function(dateStr) {
  12875. if(dateStr)
  12876. return Date.parse(dateStr, 'yyyy-MM-dd');
  12877. return new Date();
  12878. };
  12879. // 选择查找日期
  12880. $scope.onDateCondition = function(){
  12881. $scope.tableParams.page(1);
  12882. $scope.tableParams.reload();
  12883. };
  12884. // 搜索框回车
  12885. $scope.onSearch = function() {
  12886. $scope.tableParams.page(1);
  12887. $scope.tableParams.reload();
  12888. };
  12889. }]);
  12890. /**
  12891. * 平台公开招标
  12892. *
  12893. */
  12894. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  12895. BaseService.scrollBackToTop();
  12896. /**
  12897. * 改变单据日期范围
  12898. */
  12899. var getTenderDateCondition = function(zone, condition) {
  12900. var date = new Date();
  12901. if(zone == -1) {
  12902. condition.dateFrom = null;
  12903. condition.dateTo = null;
  12904. } else if(zone == 7) { // 一星期内
  12905. date.setDate(date.getDate() - 7);
  12906. condition.dateFrom = date;
  12907. condition.dateTo = new Date();
  12908. } else if(zone == 1) { // 一个月内
  12909. date.setMonth(date.getMonth() - 1);
  12910. condition.dateFrom = date;
  12911. condition.dateTo = new Date();
  12912. } else if(zone == 3) { // 三个月内
  12913. date.setMonth(date.getMonth() - 3);
  12914. condition.dateFrom = date;
  12915. condition.dateTo = new Date();
  12916. } else if (zone == 6) { // 半年内
  12917. date.setMonth(date.getMonth() - 6);
  12918. condition.dateFrom = date;
  12919. condition.dateTo = new Date();
  12920. } else { // 一年内
  12921. date.setYear(date.getYear() - 1);
  12922. condition.dateFrom = date;
  12923. condition.dateTo = new Date();
  12924. }
  12925. };
  12926. $scope.active = 'all';
  12927. $scope.dateZoneText = '不限';
  12928. $scope.deliveryZoneText = '不限';
  12929. $scope.condition = {dateZone: -1};
  12930. $scope.changeDateZone = function(zone) {
  12931. $scope.condition.dateZone = zone;
  12932. $scope.condition.$dateZoneOpen = false;
  12933. getTenderDateCondition(zone, $scope.condition);
  12934. $scope.tableParams.reload();
  12935. };
  12936. $scope.openDatePicker = function($event, item, openParam) {
  12937. $event.preventDefault();
  12938. $event.stopPropagation();
  12939. item[openParam] = !item[openParam];
  12940. };
  12941. $scope.parseDate = function(dateStr) {
  12942. if(dateStr)
  12943. return Date.parse(dateStr, 'yyyy-MM-dd');
  12944. return new Date();
  12945. };
  12946. // 选择查找日期
  12947. $scope.onDateCondition = function(){
  12948. $scope.tableParams.page(1);
  12949. $scope.tableParams.reload();
  12950. };
  12951. // $scope.setActive = function(state) {
  12952. // if($scope.active != state) {
  12953. // $scope.active = state;
  12954. // if($scope.tableParams.page() == 1)
  12955. // $scope.tableParams.reload();
  12956. // else
  12957. // $scope.tableParams.page(1);
  12958. // }
  12959. // };
  12960. var getOpenState = function(active) {
  12961. var fn = 'getOpenAll';
  12962. switch(active) {
  12963. case 'all':
  12964. fn = 'getOpenAll';break;
  12965. // case 'done':
  12966. // fn = 'getOpenDone';break;
  12967. case 'todo':
  12968. fn = 'getOpenTodo';break;
  12969. case 'end':
  12970. fn = 'getOpenEnd';break;
  12971. // case 'waiting':
  12972. // fn = 'getOpenWaiting';break;
  12973. }
  12974. return fn;
  12975. };
  12976. $scope.tableParams = new ngTableParams({
  12977. page : 1,
  12978. count : 20,
  12979. sorting: {
  12980. 'tender.endDate': 'desc',
  12981. 'tender.enterprise.enName': 'asc',
  12982. 'tender.code': 'asc'
  12983. }
  12984. }, {
  12985. total : 0,
  12986. counts: [],
  12987. getData : function($defer, params) {
  12988. $scope.loading = true;
  12989. var pageParams = params.url();
  12990. var realActive = {};
  12991. pageParams.searchFilter = { // 筛选条件
  12992. keyword: $scope.keyword,
  12993. fromDate: getDateTime($scope.condition.dateFrom),
  12994. endDate: getDateTime($scope.condition.dateTo)
  12995. };
  12996. AccountEnterprise.get({}, function(data){
  12997. $scope.loading = false;
  12998. $scope.currentEn = data;
  12999. });
  13000. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  13001. $scope.loading = false;
  13002. if(page) {
  13003. params.total(page.totalElement);
  13004. $defer.resolve(page.content);
  13005. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  13006. }
  13007. }, function(response){
  13008. $scope.loading = false;
  13009. toaster.pop('error', '数据加载失败', response.data);
  13010. });
  13011. }
  13012. });
  13013. $scope.toDetail = function(id) {
  13014. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  13015. };
  13016. // var stautsItem = [];
  13017. // $scope.getTenderStatus = function (tender) {
  13018. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  13019. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  13020. // stautsItem = thisItem;
  13021. // }
  13022. // });
  13023. // if (!stautsItem.price) {
  13024. // return "daitoubiao";
  13025. // } else if (!stautsItem.applystatus) {
  13026. // return "yitoubiao";
  13027. // } else if (stautsItem.applystatus == 1) {
  13028. // return "zhongbiao";
  13029. // } else if (stautsItem.applystatus == 0) {
  13030. // return "weizhongbiao";
  13031. // }
  13032. // };
  13033. // 搜索框回车
  13034. $scope.onSearch = function() {
  13035. $scope.tableParams.page(1);
  13036. $scope.tableParams.reload();
  13037. };
  13038. }]);
  13039. /**
  13040. * 采购方查看供应商投标单
  13041. */
  13042. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  13043. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  13044. // $scope.item = data; // 供应商查看
  13045. // $scope.loading = false;
  13046. // }, function(response){
  13047. // $scope.loading = false;
  13048. // toaster.pop('error', '数据加载失败', response.data);
  13049. // });
  13050. PurcTender.getOne({id: $stateParams.id}, function(data){
  13051. $scope.bid = data;
  13052. var vendUU = Number($stateParams.vendUU);
  13053. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  13054. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13055. if (saleTenderItem.saleTender.vendUU === vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  13056. tenderProd.currentItem = saleTenderItem;
  13057. $scope.saleTender = saleTenderItem.saleTender;
  13058. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  13059. }
  13060. });
  13061. });
  13062. }, function(response){
  13063. toaster.pop('error', '数据加载失败', response.data);
  13064. });
  13065. }]);
  13066. /**
  13067. * 查看投标单详情
  13068. */
  13069. 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) {
  13070. BaseService.scrollBackToTop();
  13071. if (!$scope.attaches) {
  13072. $scope.attaches = []; // 存放上传了的附件
  13073. }
  13074. // var staticItem = null;
  13075. // $scope.loading = true;
  13076. // PurcTender.getItem({id: $stateParams.id}, function(data){
  13077. // $scope.item = data; // 用于投标
  13078. // if ($scope.item.enterpriseBaseInfo != null) {
  13079. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  13080. // }
  13081. // staticItem = angular.copy(data);
  13082. // $scope.loading = false;
  13083. // }, function(response){
  13084. // $scope.loading = false;
  13085. // toaster.pop('error', '数据加载失败', response.data);
  13086. // });
  13087. var sleep = function (d){
  13088. for(var t = Date.now();Date.now() - t <= d;);
  13089. };
  13090. AccountEnterprise.get({}, function(data){
  13091. $scope.currentEn = data;
  13092. });
  13093. PurcTender.getOne({id: $stateParams.id}, function(data){
  13094. $scope.bid = data;
  13095. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  13096. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13097. if (!$scope.currentEn) {
  13098. AccountEnterprise.get({}, function(data){
  13099. $scope.currentEn = data;
  13100. });
  13101. }
  13102. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  13103. tenderProd.currentItem = saleTenderItem;
  13104. $scope.saleTender = saleTenderItem.saleTender;
  13105. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  13106. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  13107. }
  13108. });
  13109. });
  13110. }, function(response){
  13111. toaster.pop('error', '数据加载失败', response.data);
  13112. });
  13113. $scope.upload = function(myFile) { // 上传附件
  13114. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  13115. $upload.upload({
  13116. url: 'tender/addTenderItemAttach',
  13117. file: file,
  13118. method: 'POST'
  13119. }).success(function (attach) {
  13120. $scope.attaches.push(attach);
  13121. });
  13122. };
  13123. $scope.removeAttach = function(attachId, index) {
  13124. $scope.attaches.splice(index, 1);
  13125. // PurcTender.removeAttach({attachId : id}, {}, function() {
  13126. //
  13127. // });
  13128. };
  13129. var taxrateYes = false;
  13130. var cycleYes = false;
  13131. var priceYes = false;
  13132. $scope.canSave = false;
  13133. $scope.validateThis = function(value, type) {
  13134. switch(type) {
  13135. case 'taxrate':
  13136. var regex = /^\+?[0-9][0-9]{0,1}$/;
  13137. if (regex.test(value)) {
  13138. taxrateYes = true;
  13139. } else {
  13140. if (value) {
  13141. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  13142. }
  13143. }
  13144. break;
  13145. case 'cycle':
  13146. regex = /^\+?[1-9][0-9]*$/;
  13147. if (regex.test(value)) {
  13148. cycleYes = true;
  13149. } else {
  13150. if (value) {
  13151. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  13152. }
  13153. }
  13154. break;
  13155. case 'price':
  13156. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13157. if (regex.test(value) && value !== 0) {
  13158. priceYes = true;
  13159. } else {
  13160. if (value) {
  13161. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  13162. }
  13163. }
  13164. break;
  13165. }
  13166. };
  13167. $scope.emNumYes = true;
  13168. $scope.validEmNum = function (value) {
  13169. var regex = /^\+?[1-9][0-9]*$/;
  13170. if (!regex.test(value) || value === 0 || value !== null) {
  13171. $scope.emNumYes = false;
  13172. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  13173. }
  13174. };
  13175. $scope.validateProds = function(tenderProd) {
  13176. $scope.canSave = true;
  13177. if (tenderProd.currentItem.cycle || tenderProd.currentItem.taxrate || tenderProd.currentItem.price) {
  13178. var cycleRegex = /^\+?[1-9][0-9]*$/;
  13179. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  13180. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  13181. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13182. // 判断填写过的有为0或不符合正则式的,设置不能保存
  13183. if (!cycleRegex.test(tenderProd.currentItem.cycle) || !taxrateRegex.test(tenderProd.currentItem.taxrate) || !priceRegex.test(tenderProd.currentItem.price)) {
  13184. $scope.canSave = false;
  13185. } else {
  13186. $scope.canSave = true;
  13187. }
  13188. }
  13189. };
  13190. // 投标
  13191. $scope.bidIt = function(tender, currentEnBaseInfo){
  13192. $scope.loading = true;
  13193. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  13194. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  13195. }
  13196. var saleTenderItems = [];
  13197. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13198. if (tenderProd.currentItem) {
  13199. if ("" !== tenderProd.currentItem.price && "" !== tenderProd.currentItem.taxrate && "" !== tenderProd.currentItem.cycle) {
  13200. tenderProd.currentItem.saleTender = {};
  13201. saleTenderItems.push(tenderProd.currentItem);
  13202. }
  13203. }
  13204. });
  13205. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  13206. $scope.loading = false;
  13207. toaster.pop('info', '成功', '投标成功');
  13208. // $window.location.reload();
  13209. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  13210. // window.location.hash = '#/sale/opentender';
  13211. // } else {
  13212. window.location.hash = '#/sale/tender';
  13213. // }
  13214. }, function(response){
  13215. $scope.loading = false;
  13216. toaster.pop('error', '投标失败', '出现异常,投标失败');
  13217. });
  13218. };
  13219. $scope.condition = {
  13220. $fromOpened:false
  13221. };
  13222. $scope.getMaxDate = function() {
  13223. return $filter('date')(new Date(), 'yyyy-MM-dd');
  13224. };
  13225. $scope.openDatePicker = function($event, item, openParam) {
  13226. $event.preventDefault();
  13227. $event.stopPropagation();
  13228. item[openParam] = !item[openParam];
  13229. };
  13230. }]);
  13231. /**
  13232. * 公开招标转投标单
  13233. */
  13234. 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) {
  13235. BaseService.scrollBackToTop();
  13236. $scope.attaches = []; // 存放上传了的附件
  13237. var sleep = function (d){
  13238. for(var t = Date.now();Date.now() - t <= d;);
  13239. }
  13240. var getCurrentEn = function() {
  13241. AccountEnterprise.get({}, function(data){
  13242. $scope.currentEn = data;
  13243. });
  13244. }
  13245. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  13246. $scope.loading = true;
  13247. getCurrentEn();
  13248. PurcTender.getOne({id: $stateParams.id}, function(data){
  13249. data.$editing = false;
  13250. $scope.tender = data;
  13251. $scope.tenderProd = data.purchaseTenderProds;
  13252. // parseCertificate($scope.tender.certificate);
  13253. // $scope.firstProd = data.purchaseTenderProds[0];
  13254. $scope.currentHasBid = false; // 默认当前企业未转投标单
  13255. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  13256. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  13257. $scope.currentHasBid = true;
  13258. }
  13259. });
  13260. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  13261. // console.log($scope.tenderProd.enterpriseBaseInfo);
  13262. $scope.loading = false;
  13263. $scope.attaches = $scope.tender.tenderAttaches;
  13264. }, function(response){
  13265. $scope.loading = false;
  13266. toaster.pop('error', '数据加载失败', response.data);
  13267. });
  13268. }
  13269. $scope.hasClick = false;
  13270. $scope.iWantToBid = function(id) {
  13271. $scope.hasClick = true;
  13272. PurcTender.addItems({id: id}, {}, function(data){ // 添加明细
  13273. // $scope.tender = data;
  13274. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  13275. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  13276. // if (!$scope.currentEn) {
  13277. // AccountEnterprise.get({}, function(data){
  13278. // $scope.currentEn = data;
  13279. // });
  13280. // }
  13281. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  13282. // tenderProd.currentItem = saleTenderItem;
  13283. // $scope.saleTender = saleTenderItem.saleTender;
  13284. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  13285. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  13286. // }
  13287. // });
  13288. // });
  13289. toaster.pop('success', '成功', '转投标单成功');
  13290. window.location.hash = "#/sale/tender/" + id;
  13291. }, function(response){
  13292. toaster.pop('error', '操作失败', response.data);
  13293. });
  13294. // $scope.upload = function(myFile) { // 上传附件
  13295. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  13296. // $upload.upload({
  13297. // url: 'tender/addTenderItemAttach',
  13298. // file: file,
  13299. // method: 'POST'
  13300. // }).success(function (attach) {
  13301. // $scope.attaches.push(attach);
  13302. // });
  13303. // };
  13304. };
  13305. // $scope.removeAttach = function(id, index) {
  13306. // $scope.attaches.splice(index, 1);
  13307. // PurcTender.removeAttach({attachId:id}, function() {
  13308. //
  13309. // });
  13310. // };
  13311. // var taxrateYes = false;
  13312. // var cycleYes = false;
  13313. // var priceYes = false;
  13314. // $scope.canSave = false;
  13315. // $scope.validateThis = function(value, type) {
  13316. // switch(type) {
  13317. // case 'taxrate':
  13318. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  13319. // if (regex.test(value)) {
  13320. // taxrateYes = true;
  13321. // } else {
  13322. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  13323. // }
  13324. // break;
  13325. // case 'cycle':
  13326. // regex = /^\+?[1-9][0-9]*$/;
  13327. // if (regex.test(value)) {
  13328. // cycleYes = true;
  13329. // } else {
  13330. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  13331. // }
  13332. // break;
  13333. // case 'price':
  13334. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13335. // if (regex.test(value) && value !== 0) {
  13336. // priceYes = true;
  13337. // } else {
  13338. // if (!(value instanceof Number) || value) {
  13339. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  13340. // }
  13341. // }
  13342. // break;
  13343. // }
  13344. // };
  13345. //
  13346. // $scope.emNumYes = true;
  13347. //
  13348. // $scope.validEmNum = function (value) {
  13349. // var regex = /^\+?[1-9][0-9]*$/;
  13350. // if (!regex.test(value) || value == 0 || value !== null) {
  13351. // $scope.emNumYes = false;
  13352. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  13353. // }
  13354. // };
  13355. //
  13356. // $scope.validateProds = function(tenderProd) {
  13357. // // angular.forEach(tenderProds, function (tenderProd) {
  13358. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  13359. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  13360. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  13361. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  13362. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  13363. // console.log(tenderProd.currentItem.cycle);
  13364. // 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))) {
  13365. // $scope.canSave = false;
  13366. // } else {
  13367. // $scope.canSave = true;
  13368. // }
  13369. // // });
  13370. // };
  13371. //
  13372. // // 投标
  13373. // $scope.bidIt = function(tender, currentEnBaseInfo){
  13374. // $scope.loading = true;
  13375. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  13376. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  13377. // }
  13378. // var saleTenderItems = [];
  13379. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  13380. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13381. // if (tenderProd.currentItem) {
  13382. // tenderProd.currentItem.saleTender = {};
  13383. // saleTenderItems.push(tenderProd.currentItem);
  13384. // }
  13385. // });
  13386. // } else {
  13387. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  13388. // if (tenderProd.currentItem) {
  13389. // saleTenderItems.push(tenderProd.currentItem);
  13390. // }
  13391. // });
  13392. // }
  13393. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  13394. // $scope.loading = false;
  13395. // toaster.pop('info', '成功', '投标成功');
  13396. // // $window.location.reload();
  13397. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  13398. // // window.location.hash = '#/sale/opentender';
  13399. // // } else {
  13400. // window.location.hash = '#/sale/tender';
  13401. // // }
  13402. // }, function(response){
  13403. // $scope.loading = false;
  13404. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  13405. // });
  13406. //
  13407. // };
  13408. //
  13409. // $scope.condition = {
  13410. // $fromOpened:false
  13411. // };
  13412. //
  13413. // $scope.getMaxDate = function() {
  13414. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  13415. // };
  13416. //
  13417. // $scope.openDatePicker = function($event, item, openParam) {
  13418. // $event.preventDefault();
  13419. // $event.stopPropagation();
  13420. // item[openParam] = !item[openParam];
  13421. // };
  13422. }]);
  13423. // 基础资料客户详情
  13424. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', 'VendorInfo', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster, VendorInfo){
  13425. BaseService.scrollBackToTop();
  13426. $scope.status = 'customer';
  13427. $scope.userInfoResult = true;
  13428. AuthenticationService.getAuthentication().success(function(data) {
  13429. $scope.loading = false;
  13430. $scope.thisUser = data;
  13431. });
  13432. $scope.customerParams = new ngTableParams({
  13433. page : 1,
  13434. count : 10
  13435. }, {
  13436. total : 0,
  13437. counts: [],
  13438. getData : function($defer, params) {
  13439. $scope.loading = true;
  13440. var pageParams = params.url();
  13441. pageParams.keyword = $scope.keyword;
  13442. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function(page){
  13443. $scope.loading = false;
  13444. if(page) {
  13445. params.total(page.totalElement);
  13446. $scope.total = page.totalElement;
  13447. $defer.resolve(page.content);
  13448. }
  13449. $scope.totalCount = page.totalElements;
  13450. }, function(response){
  13451. $scope.loading = false;
  13452. toaster.pop('error', '数据加载失败', response.data);
  13453. });
  13454. }
  13455. });
  13456. // 搜索框回车
  13457. $scope.onSearch = function(keyword) {
  13458. $scope.customerParams.page(1);
  13459. $scope.customerParams.reload();
  13460. $scope.tip = keyword;
  13461. };
  13462. // 查看详情
  13463. $scope.viewDetail = function(id) {
  13464. window.location.hash = "#/sale/customer/" + id;
  13465. }
  13466. // 取消合作关系
  13467. $scope.disableCust = function(id) {
  13468. VendorInfo.disableCust({id: id}, {}, function(data) {
  13469. if(data.success) {
  13470. toaster.pop('success', '提示', data.success);
  13471. }
  13472. $scope.customerParams.page(1);
  13473. $scope.customerParams.reload();
  13474. }, function(response) {
  13475. toaster.pop('error', '提示', response.data);
  13476. });
  13477. }
  13478. // 解除禁用
  13479. $scope.activeCust = function(id) {
  13480. VendorInfo.activeCust({id: id}, {}, function(data) {
  13481. if(data.success) {
  13482. toaster.pop('success', '提示', data.success);
  13483. }
  13484. $scope.customerParams.page(1);
  13485. $scope.customerParams.reload();
  13486. }, function(response) {
  13487. toaster.pop('error', '提示', response.data);
  13488. });
  13489. }
  13490. }]);
  13491. // 基础资料供应商
  13492. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  13493. BaseService.scrollBackToTop();
  13494. $scope.status = 'vendor';
  13495. // 搜索框回车
  13496. $scope.onSearch = function(keyword) {
  13497. $scope.keyword = keyword;
  13498. $scope.customerParams.page(1);
  13499. $scope.customerParams.reload();
  13500. };
  13501. $scope.customerParams = new ngTableParams({
  13502. page : 1,
  13503. count : 10
  13504. }, {
  13505. total : 0,
  13506. counts: [],
  13507. getData : function($defer, params) {
  13508. $scope.loading = true;
  13509. var pageParams = params.url();
  13510. pageParams.keyword = $scope.keyword;
  13511. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  13512. $scope.loading = false;
  13513. if(page) {
  13514. params.total(page.totalElement);
  13515. $scope.total = page.totalElement;
  13516. $defer.resolve(page.content);
  13517. }
  13518. $scope.totalCount = page.totalElements;
  13519. }, function(response){
  13520. $scope.loading = false;
  13521. toaster.pop('error', '数据加载失败', response.data);
  13522. });
  13523. }
  13524. });
  13525. // 查看供应商详情
  13526. $scope.VendorDetail = function(id, uu) {
  13527. $rootScope.vendorId = id;
  13528. $rootScope.vendoruu = uu;
  13529. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  13530. }
  13531. // 向企业购买
  13532. $scope.purcByEn = function(businessCode) {
  13533. $rootScope.businessCode = businessCode;
  13534. window.location.hash = "#/purc/addOrder";
  13535. }
  13536. // 取消合作关系
  13537. $scope.relieve = function(id) {
  13538. VendorInfo.relieve({id: id}, {}, function(data) {
  13539. if(data.success) {
  13540. toaster.pop('success', '提示', data.success);
  13541. }
  13542. $scope.customerParams.page(1);
  13543. $scope.customerParams.reload();
  13544. }, function(response) {
  13545. toaster.pop('error', '提示', response.data);
  13546. });
  13547. }
  13548. // 建立合作关系
  13549. $scope.activeVend = function(id) {
  13550. VendorInfo.activeVend({id: id}, {}, function(data) {
  13551. if(data.success) {
  13552. toaster.pop('success', '提示', data.success);
  13553. }
  13554. $scope.customerParams.page(1);
  13555. $scope.customerParams.reload();
  13556. }, function(response) {
  13557. toaster.pop('error', '提示', response.data);
  13558. });
  13559. }
  13560. }]);
  13561. // 企业圈搜索界面
  13562. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  13563. $scope.onSearch = function(keyword) {
  13564. $rootScope.enterpriseKeyword = keyword;
  13565. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  13566. }
  13567. }]);
  13568. // 企业圈搜索结果
  13569. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  13570. $scope.status = 'add';
  13571. BaseService.scrollBackToTop();
  13572. $scope.active = 'all';
  13573. $scope.agreedText = '全部';
  13574. $scope.dateZoneText = '一个月内';
  13575. $scope.condition = {dateZone: 1};
  13576. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13577. $scope.changeAgreed = function(agreed) {
  13578. $scope.condition.agreed = agreed;
  13579. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13580. $scope.condition.$agreedOpen = false;
  13581. };
  13582. $scope.changeDateZone = function(zone) {
  13583. $scope.condition.dateZone = zone;
  13584. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13585. $scope.condition.$dateZoneOpen = false;
  13586. getDateCondition(zone, $scope.condition);
  13587. $scope.tableParams.reload();
  13588. };
  13589. $scope.setActive = function(state) {
  13590. if($scope.active != state) {
  13591. $scope.active = state;
  13592. if($scope.tableParams.page() == 1)
  13593. $scope.tableParams.reload();
  13594. else
  13595. $scope.tableParams.page(1);
  13596. }
  13597. };
  13598. var getService = function() {
  13599. return getAccountUserSpace;
  13600. };
  13601. $scope.tableParams = new ngTableParams({
  13602. page : 1,
  13603. count : 10,
  13604. sorting: {
  13605. }
  13606. }, {
  13607. total : 0,
  13608. counts: [],
  13609. getData : function($defer, params) {
  13610. $scope.loading = true;
  13611. var pageParams = params.url();
  13612. pageParams.keyword = $scope.keyword;
  13613. $scope.tip = $scope.keyword;
  13614. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  13615. $scope.loading = false;
  13616. if(page) {
  13617. params.total(page.totalElement);
  13618. $defer.resolve(page.content);
  13619. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13620. }
  13621. }, function(response) {
  13622. $scope.loading = false;
  13623. toaster.pop('error', '数据加载失败', response.data);
  13624. });
  13625. }
  13626. });
  13627. // 搜索框回车
  13628. $scope.onSearch = function(keyword) {
  13629. if($scope.keyword != null && $scope.keyword != '') {
  13630. $rootScope.searchKeyword = keyword;
  13631. $scope.keyword = keyword;
  13632. $scope.tableParams.page(1);
  13633. $scope.tableParams.reload();
  13634. }
  13635. };
  13636. // 添加合作关系
  13637. $scope.addPartner = function(name, businessCode) {
  13638. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  13639. if(data.success) {
  13640. toaster.pop("success", '添加成功', data.success);
  13641. }
  13642. if(data.error) {
  13643. toaster.pop("error", '添加失败', data.error);
  13644. }
  13645. }, function(response) {
  13646. toaster.pop('error','失败',response.data);
  13647. });
  13648. }
  13649. /**
  13650. * 邀请注册商务平台
  13651. */
  13652. $scope.invite = function(name) {
  13653. var modalInstance = $modal.open({
  13654. animation: true,
  13655. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  13656. controller: 'InviteCtrl',
  13657. resolve: {
  13658. enname: function(){return name}
  13659. }
  13660. });
  13661. modalInstance.result.then(function(data) {
  13662. InvitationRecord.invite({formStore: data}, {}, function(data) {
  13663. if(data.success) {
  13664. toaster.pop('success', '提示', data.success);
  13665. }
  13666. if(data.error) {
  13667. toaster.pop('error', '提示', data.error);
  13668. }
  13669. }, function(response) {
  13670. toaster.pop('error', '提示', response.data);
  13671. });
  13672. });
  13673. }
  13674. /**
  13675. * 立即查看
  13676. */
  13677. $scope.view = function(name) {
  13678. $rootScope.vendName = name;
  13679. window.location.hash = "#/baseInfo/myRquest";
  13680. }
  13681. }]);
  13682. // 平台新增的询价单(指定一个供应商)
  13683. 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) {
  13684. $scope.active = 'all';
  13685. // 供应商信息
  13686. var loadData = function() {
  13687. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function(data) {
  13688. $scope.vendor = data;
  13689. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  13690. $scope.vendorContacts = data;
  13691. });
  13692. // 物料信息
  13693. $scope.tableParams = new ngTableParams({
  13694. page : 1,
  13695. count : 10
  13696. }, {
  13697. total : 0,
  13698. counts: [5, 10, 25, 50],
  13699. getData : function($defer, params) {
  13700. $scope.loading = true;
  13701. var pageParams = params.url();
  13702. pageParams.keyword = $scope.keyword;
  13703. $scope.tip = $scope.keyword;
  13704. pageParams.custUU = $scope.vendor.uu;
  13705. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  13706. $scope.loading = false;
  13707. if(page) {
  13708. params.total(page.totalElement);
  13709. $scope.total = page.totalElement;
  13710. $defer.resolve(page.content);
  13711. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13712. }
  13713. }, function(response){
  13714. $scope.loading = false;
  13715. toaster.pop('error', '数据加载失败', response.data);
  13716. });
  13717. }
  13718. });
  13719. });
  13720. };
  13721. loadData();
  13722. $rootScope.tenderVendor = null;// 清除掉已选择的
  13723. var getService = function() {
  13724. return GetProductInfo;
  13725. };
  13726. $scope.inquiry = {
  13727. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  13728. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  13729. priceType: '采购',
  13730. isOpen: 1,
  13731. invoice: 0,
  13732. ifTax: 1,
  13733. currency: 'RMB'
  13734. };
  13735. $scope.changeCurrency = function(inquiry) {
  13736. if (inquiry.currency !== 'RMB') {
  13737. $scope.notRMB = true;
  13738. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  13739. inquiry.invoice = 0;
  13740. } else {
  13741. $scope.notRMB = false;
  13742. }
  13743. };
  13744. // 获取收货地址列表
  13745. var loadShipAddress = function() {
  13746. ShipAddress.shipAddList({}, function(data) {
  13747. $scope.ships = data;
  13748. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  13749. });
  13750. };
  13751. loadShipAddress();
  13752. // 获取地址信息
  13753. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  13754. }).then(function(response) {
  13755. $scope.provinces = response.data;
  13756. });
  13757. // 新增收货地址保存
  13758. $scope.saveShipAddress = function(ship) {
  13759. ship.address = ship.province + ship.city + ship.district;
  13760. ShipAddress.saveAddress( {}, ship, function(data) {
  13761. if(data.success) {
  13762. // 获取收货地址列表
  13763. loadShipAddress();
  13764. toaster.pop('success', '提示', data.success);
  13765. }
  13766. if(data.error) {
  13767. toaster.pop('error', '提示', data.error);
  13768. }
  13769. });
  13770. };
  13771. $scope.currentDay = function() {
  13772. return $filter('date')(new Date(), 'yyyy-MM-dd');
  13773. };
  13774. // 搜索框回车
  13775. $scope.onSearch = function(keyword) {
  13776. $scope.tableParams.page(1);
  13777. $scope.tableParams.reload();
  13778. };
  13779. $scope.inquiry.inquiryItems = [];
  13780. var prod = {
  13781. prodCode: null,
  13782. prodTitle: null,
  13783. inbrand: null,
  13784. currency: 'RMB',
  13785. toDate: null,
  13786. unit: 'PCS'
  13787. };
  13788. $scope.inquiry.inquiryItems.push(prod);
  13789. // 联想词start
  13790. // 获取品牌联想词
  13791. $scope.getSimilarBrands = function(value) {
  13792. if (value) {
  13793. // 获取品牌联想词
  13794. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  13795. return data.map(function(item) {
  13796. return item;
  13797. });
  13798. });
  13799. }
  13800. };
  13801. // 获取产品型号联想词
  13802. $scope.getSimilarCodes = function(value) {
  13803. if (value) {
  13804. // 获取产品型号联想词
  13805. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  13806. return data.map(function (item) {
  13807. return item;
  13808. })
  13809. });
  13810. }
  13811. };
  13812. $scope.selectKind = function(prod) {
  13813. var submit = [];
  13814. $modal.open({
  13815. animation: true,
  13816. size: 'lg',
  13817. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  13818. controller: 'ProdKindChooseCtrl',
  13819. resolve: {
  13820. actives: function() {
  13821. return $scope.actives;
  13822. }
  13823. }
  13824. }).result.then(function(data){
  13825. $scope.actives = data.actives;
  13826. var size = data.actives.length;
  13827. submit.gradeOneKiName = '';
  13828. submit.gradeTwoKiName = '';
  13829. submit.gradeThreeKiName = '';
  13830. if (size > 0) {
  13831. submit.gradeOneKiName = $scope.actives[0].nameCn;
  13832. prod.prodTitle = submit.gradeOneKiName;
  13833. if (size > 1) {
  13834. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  13835. prod.prodTitle = submit.gradeTwoKiName;
  13836. if (size > 2) {
  13837. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  13838. prod.prodTitle = submit.gradeThreeKiName;
  13839. }
  13840. }
  13841. }
  13842. }, function(){
  13843. });
  13844. };
  13845. // 点击联想词获取品牌信息
  13846. $scope.onAssociateBrandClick = function(brand, prod) {
  13847. if (brand instanceof String) {
  13848. prod.inbrand = brand;
  13849. } else if (brand instanceof Object) {
  13850. prod.inbrand = brand.brandCn;
  13851. }
  13852. };
  13853. // 打开品牌选择的模态框
  13854. $scope.selectBrand = function(prod){ //打开模态
  13855. var modalInstance = $modal.open({
  13856. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  13857. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  13858. });
  13859. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  13860. });
  13861. modalInstance.result.then(function(brand){
  13862. prod.inbrand = brand.nameCn;
  13863. }, function(reason){
  13864. });
  13865. };
  13866. // 点击联想词获取器件信息 带入产品分类和品牌
  13867. $scope.onAssociateCmpClick = function(cmp, prod) {
  13868. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  13869. $scope.component = data;
  13870. prod.prodCode = data.code;
  13871. prod.prodTitle = data.kind.nameCn;
  13872. prod.inbrand = data.brand.nameCn;
  13873. }, function(res) {
  13874. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  13875. })
  13876. };
  13877. //联想词end
  13878. // 导入商品信息
  13879. $scope.uplodaByBatch = function() {
  13880. var modalInstance = $modal.open({
  13881. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  13882. controller: 'PurcInquiryUploadCtrl',
  13883. size: 'lg',
  13884. resolve: {
  13885. }
  13886. });
  13887. modalInstance.result.then(function(data) {
  13888. angular.forEach(data, function(prod) {
  13889. console.log(prod);
  13890. $scope.inquiry.inquiryItems.push(prod);
  13891. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  13892. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  13893. $scope.inquiry.inquiryItems.splice(i, 1);
  13894. }
  13895. }
  13896. })
  13897. }, function(){
  13898. });
  13899. }
  13900. //增加商品
  13901. $scope.add = function() {
  13902. $scope.inquiry.inquiryItems.push(
  13903. { prodCode: null,
  13904. prodTitle: null,
  13905. unit: 'PCS',
  13906. ibrand: null,
  13907. currency: 'RMB',
  13908. toDate: null});
  13909. };
  13910. //删除商品
  13911. $scope.del = function(index) {
  13912. $scope.inquiry.inquiryItems.splice(index, 1);
  13913. };
  13914. // 搜索结果询价
  13915. if($rootScope.prodId) {
  13916. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  13917. prod.prodCode = data.code;
  13918. prod.prodTitle = data.title;
  13919. prod.spec = data.spec;
  13920. prod.unit = data.unit;
  13921. prod.productId = data.id;
  13922. prod.inbrand = data.brand;
  13923. $scope.inquiry.inquiryItems.push(prod);
  13924. $rootScope.prodId = null;// 清除掉prodId
  13925. }, function(response) {
  13926. });
  13927. }
  13928. $scope.check = function(product) {
  13929. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  13930. currency: null, toDate: null, productId: product.id, inbrand: product.brand});
  13931. }
  13932. $scope.getMinDate = function(item) {
  13933. return $filter('date')(new Date, 'yyyy-MM-dd');
  13934. };
  13935. $scope.openDatePicker = function($event, openParam, index) {
  13936. $event.preventDefault();
  13937. $event.stopPropagation();
  13938. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  13939. };
  13940. $scope.openEndDatePicker = function($event, item, openParam) {
  13941. $event.preventDefault();
  13942. $event.stopPropagation();
  13943. item[openParam] = !item[openParam];
  13944. };
  13945. // 保存并提交
  13946. $scope.submit = function() {
  13947. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  13948. $scope.vendors = [];
  13949. $scope.vendors.push({enName: $scope.vendor.enName, enuu: $scope.vendor.uu});
  13950. $upload.upload({
  13951. url: 'purc/inquiry/saveAndSubmit',
  13952. file: file,
  13953. method: 'POST',
  13954. data: {
  13955. inquiry: $scope.inquiry,
  13956. contacts: $scope.vendors
  13957. },
  13958. }).success(function(data) {
  13959. if(data.success) {
  13960. toaster.pop('success', '提示', data.success);
  13961. $timeout(function() {
  13962. window.location.hash = "#/purc/purchaseinquiry";
  13963. }, 500);
  13964. }
  13965. if(data.error) {
  13966. toaster.pop('error', '提示', data.error);
  13967. }
  13968. }).error(function(data) {
  13969. $scope.loadingShow = false;
  13970. toaster.pop('error', '操作失败', data.error);
  13971. });
  13972. }
  13973. }]);
  13974. // 企业圈查询收到待处理的数目
  13975. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', function($scope, AddPartnerMyRequest) {
  13976. AddPartnerMyRequest.requestAmount({}, function(data) {
  13977. $scope.requestTodo = data;
  13978. });
  13979. }]);
  13980. // 当前企业所有的物料信息
  13981. app.controller('ProductAllCtrl', ['$scope', 'Products', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, Products, ngTableParams, $filter, BaseService, toaster, $timeout) {
  13982. BaseService.scrollBackToTop();
  13983. $scope.active = 'all';
  13984. $scope.agreedText = '全部';
  13985. $scope.dateZoneText = '一个月内';
  13986. $scope.condition = {dateZone: 1};
  13987. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13988. $scope.changeAgreed = function(agreed) {
  13989. $scope.condition.agreed = agreed;
  13990. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13991. $scope.condition.$agreedOpen = false;
  13992. };
  13993. $scope.changeDateZone = function(zone) {
  13994. $scope.condition.dateZone = zone;
  13995. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13996. $scope.condition.$dateZoneOpen = false;
  13997. getDateCondition(zone, $scope.condition);
  13998. $scope.tableParams.reload();
  13999. };
  14000. $scope.setActive = function(state) {
  14001. if($scope.active != state) {
  14002. $scope.active = state;
  14003. if($scope.tableParams.page() == 1)
  14004. $scope.tableParams.reload();
  14005. else
  14006. $scope.tableParams.page(1);
  14007. }
  14008. };
  14009. var getService = function() {
  14010. return Products.info;
  14011. };
  14012. $scope.tableParams = new ngTableParams({
  14013. page : 1,
  14014. count : 5,
  14015. sorting: {
  14016. }
  14017. }, {
  14018. total : 0,
  14019. counts: [5, 10, 25, 50],
  14020. getData : function($defer, params) {
  14021. $scope.loading = true;
  14022. var pageParams = params.url();
  14023. pageParams.keyword = $scope.keyword;
  14024. pageParams.searchFilter = $scope.searchFilter;
  14025. getService().call(null, BaseService.parseParams(pageParams), function(page){
  14026. $scope.loading = false;
  14027. if(page) {
  14028. params.total(page.totalElement);
  14029. $defer.resolve(page.content);
  14030. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14031. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  14032. }
  14033. }, function(response) {
  14034. $scope.loading = false;
  14035. toaster.pop('error', '数据加载失败', response.data);
  14036. });
  14037. }
  14038. });
  14039. // 搜索框回车
  14040. $scope.onSearch = function() {
  14041. $scope.tableParams.page(1);
  14042. $scope.tableParams.reload();
  14043. };
  14044. // 开启销售
  14045. $scope.unlock = function(id) {
  14046. Products.unlock({id: id}, {}, function(data) {
  14047. toaster.pop('success', '提示', '操作成功');
  14048. $scope.tableParams.reload();
  14049. }, function(response) {
  14050. toaster.pop('error', '提示', response.data);
  14051. })
  14052. }
  14053. // 关闭销售
  14054. $scope.lock = function(id) {
  14055. Products.lock({id: id}, {}, function(data) {
  14056. toaster.pop('success', '提示', '操作成功');
  14057. $scope.tableParams.reload();
  14058. }, function(response) {
  14059. toaster.pop('error', '提示', response.data);
  14060. })
  14061. }
  14062. // 开启购买
  14063. $scope.unlockPurc = function(id) {
  14064. Products.unlockPurc({id: id}, {}, function(data) {
  14065. toaster.pop('success', '提示', '操作成功');
  14066. $scope.tableParams.reload();
  14067. }, function(response) {
  14068. toaster.pop('error', '提示', response.data);
  14069. })
  14070. }
  14071. // 关闭购买
  14072. $scope.lockPurc = function(id) {
  14073. Products.lockPurc({id: id}, {}, function(data) {
  14074. toaster.pop('success', '提示', '操作成功');
  14075. $scope.tableParams.reload();
  14076. }, function(response) {
  14077. toaster.pop('error', '提示', response.data);
  14078. })
  14079. }
  14080. }]);
  14081. /**
  14082. * 采购物料资料
  14083. */
  14084. app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout) {
  14085. BaseService.scrollBackToTop();
  14086. $scope.active = 'all';
  14087. $scope.agreedText = '全部';
  14088. $scope.dateZoneText = '一个月内';
  14089. $scope.condition = {dateZone: 1};
  14090. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14091. $scope.changeAgreed = function(agreed) {
  14092. $scope.condition.agreed = agreed;
  14093. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  14094. $scope.condition.$agreedOpen = false;
  14095. };
  14096. $scope.changeDateZone = function(zone) {
  14097. $scope.condition.dateZone = zone;
  14098. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  14099. $scope.condition.$dateZoneOpen = false;
  14100. getDateCondition(zone, $scope.condition);
  14101. $scope.tableParams.reload();
  14102. };
  14103. $scope.setActive = function(state) {
  14104. if($scope.active != state) {
  14105. $scope.active = state;
  14106. if($scope.tableParams.page() == 1)
  14107. $scope.tableParams.reload();
  14108. else
  14109. $scope.tableParams.page(1);
  14110. }
  14111. };
  14112. var getService = function() {
  14113. return PurcProduct;
  14114. };
  14115. $scope.tableParams = new ngTableParams({
  14116. page : 1,
  14117. count : 5,
  14118. sorting: {
  14119. }
  14120. }, {
  14121. total : 0,
  14122. counts: [5, 10, 25, 50],
  14123. getData : function($defer, params) {
  14124. $scope.loading = true;
  14125. var pageParams = params.url();
  14126. pageParams.keyword = $scope.keyword;
  14127. pageParams.searchFilter = $scope.searchFilter;
  14128. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  14129. $scope.loading = false;
  14130. if(page) {
  14131. params.total(page.totalElement);
  14132. $defer.resolve(page.content);
  14133. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14134. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  14135. }
  14136. }, function(response) {
  14137. $scope.loading = false;
  14138. toaster.pop('error', '数据加载失败', response.data);
  14139. });
  14140. }
  14141. });
  14142. // 搜索框回车
  14143. $scope.onSearch = function() {
  14144. $scope.tableParams.page(1);
  14145. $scope.tableParams.reload();
  14146. };
  14147. //删除
  14148. $scope.deleteById = function(id) {
  14149. GetProductInfo.deleteById({id: id}, function(data) {
  14150. if(data.error) {
  14151. toaster.pop("error", "提示", data.error);
  14152. } else {
  14153. toaster.pop("success", "提示", "删除成功");
  14154. $timeout(function() {
  14155. $scope.tableParams.reload();
  14156. }, 500);
  14157. }
  14158. }), function(response) {
  14159. toaster.pop("error", "删除失败", response.data);
  14160. };
  14161. }
  14162. }]);
  14163. /**
  14164. * 采购物料批量上传
  14165. */
  14166. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  14167. BaseService.scrollBackToTop();
  14168. // 通过excel批量上传物料
  14169. $scope.upload = function() {
  14170. if($scope.myFiles) {
  14171. var file = $scope.myFiles[0];
  14172. if(file.name) {
  14173. $upload.upload({
  14174. url: 'purcProduct/release/excel',
  14175. file: file,
  14176. method: 'POST'
  14177. }).success(function(data) {
  14178. $scope.result = data;
  14179. $scope.success = $scope.result.success;
  14180. $scope.total = $scope.result.total;
  14181. $scope.alters = $scope.result.alters;
  14182. $scope.infos = $scope.result.infos;
  14183. $scope.myFiles[0] = "";
  14184. }).error(function(response) {
  14185. toaster.pop('error', response.data || response);
  14186. });
  14187. } else {
  14188. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  14189. }
  14190. }
  14191. };
  14192. // 查看范例
  14193. $scope.showImg = function() {
  14194. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  14195. box.show();
  14196. box.find('img').attr('src', src);
  14197. box.find('a').click(function(){
  14198. box.hide();
  14199. });
  14200. box.dblclick(function(){
  14201. box.hide();
  14202. });
  14203. };
  14204. // 下载模板
  14205. $scope.download = function() {
  14206. window.location.href = 'product/baseInfo/upload/template';
  14207. };
  14208. }]);
  14209. /**
  14210. * 新增物料(采购)
  14211. */
  14212. 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) {
  14213. BaseService.scrollBackToTop();
  14214. // 录入人
  14215. AuthenticationService.getAuthentication().success(function(data) {
  14216. $scope.loading = false;
  14217. $scope.user = data;
  14218. });
  14219. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  14220. $scope.prodInfo = {};
  14221. // 选择类目
  14222. $scope.selectKind = function(uuids) {
  14223. $modal.open({
  14224. animation: true,
  14225. size: 'lg',
  14226. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  14227. controller: 'KindChooseCtrl',
  14228. }).result.then(function(data){
  14229. $scope.kindId = data;
  14230. var modalInstance = $modal.open({
  14231. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  14232. controller: 'FindComponentCtrl',
  14233. size: 'lg',
  14234. resolve: {
  14235. KindId: function() {
  14236. return $scope.kindId;
  14237. }
  14238. }
  14239. });
  14240. modalInstance.result.then(function(data) {
  14241. $scope.prodInfo.cmpUuId = data.uuid;
  14242. $scope.prodInfo.cmpCode = data.code;
  14243. $scope.prodInfo.brand = data.brand.nameEn;
  14244. }, function(){
  14245. });
  14246. }, function(){
  14247. });
  14248. };
  14249. // 删除
  14250. $scope.clearfile = function() {
  14251. $scope.myFiles = null;
  14252. $scope.previewShow = false;
  14253. }
  14254. //提交
  14255. $scope.submit = function(prodInfo){
  14256. $scope.prodInfo.isPurchase = 1;
  14257. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  14258. $upload.upload({
  14259. url: 'product/baseInfo/addNewProduct',
  14260. file: file,
  14261. method: 'POST',
  14262. data: {
  14263. prodInfo: prodInfo
  14264. },
  14265. }).success(function(data) {
  14266. if(data.success) {
  14267. toaster.pop('success', '提示', data.success);
  14268. $timeout(function() {
  14269. //提交后跳转到详情页面,防止重复提交
  14270. window.location.href="#/sale/prodList/"+data.id;
  14271. }, 500);
  14272. }
  14273. if(data.error) {
  14274. toaster.pop('error', '提示', data.error);
  14275. $timeout(function() {
  14276. //提交后跳转到详情页面,防止重复提交
  14277. window.location.href="#/sale/prodList/"+data.id;
  14278. }, 500);
  14279. }
  14280. }).error(function(data) {
  14281. $scope.loadingShow = false;
  14282. toaster.pop('error', '操作失败', data.error);
  14283. });
  14284. };
  14285. $scope.previewShow = false;
  14286. $scope.pdfShow = false;
  14287. $scope.noneFileShow = true;
  14288. $scope.$watch('myFiles', function(){
  14289. if($scope.myFiles) {
  14290. $scope.noneFileShow = false;
  14291. var file = $scope.myFiles[0];
  14292. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  14293. $scope.pdfShow = true;
  14294. $scope.previewShow = false;
  14295. $scope.imgPreviewName = file.name;
  14296. } else{
  14297. if (typeof(Worker) !== "undefined") {//支持HTML5
  14298. $scope.imgPreview = getObjectURL(file);
  14299. $scope.imgPreviewName = file.name;
  14300. } else{//不支持HTML5
  14301. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  14302. $scope.imgPreviewName = file.name;
  14303. }
  14304. $scope.previewShow = true;
  14305. $scope.pdfShow = false;
  14306. }
  14307. } else {
  14308. $scope.noneFileShow = true;
  14309. $scope.previewShow = false;
  14310. $scope.pdfShow = false;
  14311. }
  14312. });
  14313. //建立一个可存取到该file的url
  14314. var getObjectURL = function(file) {
  14315. var url = null ;
  14316. if (window.createObjectURL!=undefined) { // basic
  14317. url = window.createObjectURL(file) ;
  14318. } else if (window.URL!=undefined) { // mozilla(firefox)
  14319. url = window.URL.createObjectURL(file) ;
  14320. } else if (window.webkitURL!=undefined) { // webkit or chrome
  14321. url = window.webkitURL.createObjectURL(file) ;
  14322. }
  14323. return url ;
  14324. };
  14325. // 取消
  14326. $scope.cancel = function(){
  14327. $scope.prodInfo = angular.copy($scope.prodInfo);
  14328. };
  14329. }]);
  14330. /**
  14331. * 物料详情(采购)
  14332. */
  14333. app.controller('PurcProdDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService) {
  14334. BaseService.scrollBackToTop();
  14335. // 录入人
  14336. AuthenticationService.getAuthentication().success(function(data) {
  14337. $scope.loading = false;
  14338. $scope.user = data;
  14339. });
  14340. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  14341. var loadData = function() {
  14342. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  14343. if(data.attach) {
  14344. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  14345. // 查看范例
  14346. $scope.showImg = function() {
  14347. var src = data.url, box = $('#image-box');
  14348. box.show();
  14349. box.find('img').attr('src', src);
  14350. box.find('a').click(function(){
  14351. box.hide();
  14352. });
  14353. box.dblclick(function(){
  14354. box.hide();
  14355. });
  14356. };
  14357. })
  14358. }
  14359. $scope.prodInfo = data;
  14360. $scope.prodInfo.$editing = false;
  14361. $scope.loading = false;
  14362. });
  14363. };
  14364. loadData();
  14365. $scope.isShow = true;
  14366. // 更新
  14367. $scope.update = function() {
  14368. $scope.prodInfo.$editing = true;
  14369. $scope.isShow = true;
  14370. };
  14371. // 取消
  14372. $scope.cancel = function() {
  14373. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  14374. $scope.prodInfo = data;
  14375. $scope.prodInfo.$editing = false;
  14376. $scope.isShow = false;
  14377. $scope.loading = false;
  14378. });
  14379. };
  14380. // 删除
  14381. $scope.clearfile = function() {
  14382. $scope.myFiles = null;
  14383. $scope.previewShow = false;
  14384. }
  14385. $scope.submit = function(prodInfo) {
  14386. $scope.prodInfo.isPurchase = 1;
  14387. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  14388. $upload.upload({
  14389. url: 'product/baseInfo/updateProdInfo',
  14390. file: file,
  14391. method: 'POST',
  14392. data: {
  14393. prodInfo: $scope.prodInfo
  14394. },
  14395. }).success(function(data) {
  14396. if(data.success) {
  14397. toaster.pop('success', '提示', data.success);
  14398. window.location.reload();
  14399. }
  14400. if(data.error) {
  14401. toaster.pop('error', '提示', data.error);
  14402. }
  14403. }).error(function(data) {
  14404. $scope.loadingShow = false;
  14405. toaster.pop('error', '操作失败', data.error);
  14406. });
  14407. }
  14408. $scope.previewShow = false;
  14409. $scope.pdfShow = false;
  14410. $scope.noneFileShow = true;
  14411. $scope.$watch('myFiles', function(){
  14412. if($scope.myFiles) {
  14413. $scope.noneFileShow = false;
  14414. var file = $scope.myFiles[0];
  14415. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  14416. $scope.pdfShow = true;
  14417. $scope.previewShow = false;
  14418. $scope.imgPreviewName = file.name;
  14419. } else{
  14420. if (typeof(Worker) !== "undefined") {//支持HTML5
  14421. $scope.imgPreview = getObjectURL(file);
  14422. $scope.imgPreviewName = file.name;
  14423. } else{//不支持HTML5
  14424. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  14425. $scope.imgPreviewName = file.name;
  14426. }
  14427. $scope.previewShow = true;
  14428. $scope.pdfShow = false;
  14429. }
  14430. } else {
  14431. $scope.noneFileShow = true;
  14432. $scope.previewShow = false;
  14433. $scope.pdfShow = false;
  14434. }
  14435. });
  14436. //建立一个可存取到该file的url
  14437. var getObjectURL = function(file) {
  14438. var url = null ;
  14439. if (window.createObjectURL!=undefined) { // basic
  14440. url = window.createObjectURL(file) ;
  14441. } else if (window.URL!=undefined) { // mozilla(firefox)
  14442. url = window.URL.createObjectURL(file) ;
  14443. } else if (window.webkitURL!=undefined) { // webkit or chrome
  14444. url = window.webkitURL.createObjectURL(file) ;
  14445. }
  14446. return url ;
  14447. };
  14448. }]);
  14449. return app;
  14450. });