app.js 618 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product'], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config([ '$httpProvider', function($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function(response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url : "/index",
  26. views : {
  27. "left-view" : {
  28. templateUrl : "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view" : {
  32. templateUrl : "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url : "/",
  38. views : {
  39. "left-view" : {
  40. templateUrl : "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view" : {
  44. templateUrl : "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url : "/sale",
  50. views : {
  51. "left-view" : {
  52. templateUrl : "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view" : {
  56. templateUrl : "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url : "",
  65. templateUrl : "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url : "/",
  68. templateUrl : "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url : "/purc",
  71. views : {
  72. "left-view" : {
  73. templateUrl : "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view" : {
  77. templateUrl : "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url : "",
  86. templateUrl : "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url : "/",
  89. templateUrl : "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url : "/introduce",
  92. templateUrl : "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url : "/order",
  95. templateUrl : "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url : "/order/:id",
  99. templateUrl : "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url : "/addOrder",
  103. templateUrl : "static/tpl/index/purc/addOrder.html",
  104. controller : 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url : "/cart",
  107. templateUrl : "static/tpl/index/purc/cart.html",
  108. controller : 'CartController'
  109. }).state('purc.cartDetail', {
  110. url : "/cart/:id",
  111. templateUrl : "static/tpl/index/purc/cart_detail.html",
  112. controller : 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url : "/deputy",
  115. templateUrl : "static/tpl/index/purc/deputyOrder.html",
  116. controller : 'DeputyOrderCtrl'
  117. }).state('purc.deputylog', {
  118. url : "/deputylog",
  119. templateUrl : "static/tpl/index/purc/deputyorders_log.html",
  120. controller : 'DeputyOrderLogCtrl'
  121. }).state('purc.newdeputy', {
  122. url : "/deputy/add",
  123. templateUrl : "static/tpl/index/purc/deputyOrder_new.html",
  124. controller : 'NewDeputyOrderCtrl'
  125. }).state('purc.deputydetail', {
  126. url : "/deputy/:id",
  127. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  128. controller : 'DeputyOrderDetailCtrl'
  129. /* 招标列表 */
  130. }).state('purc.tenderlist', {
  131. url : "/tender",
  132. templateUrl : "static/tpl/index/purc/tenderlist.html",
  133. controller : 'PurcTenderCtrl'
  134. }).state('purc.waiting.tenderlist', {
  135. url : "/tender",
  136. templateUrl : "static/tpl/index/purc/tenderlist.html",
  137. controller : 'PurcTenderCtrl'
  138. }).state('purc.todo.tenderlist', {
  139. url : "/tender/todo",
  140. templateUrl : "static/tpl/index/purc/tenderlist.html",
  141. controller : 'PurcTenderCtrl'
  142. /* 招标 */
  143. }).state('purc.tender', {
  144. url : "/addTender",
  145. templateUrl : "static/tpl/index/purc/tender.html",
  146. controller : 'PurcNewTenderCtrl'
  147. }).state('purc.savedtender', {
  148. url : "/tender/:id",
  149. templateUrl : "static/tpl/index/purc/tender.html",
  150. controller : 'PurcNewTenderCtrl'
  151. /* 评标 */
  152. }).state('purc.evaluation', {
  153. url : "/evaluation/:id",
  154. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  155. controller : 'PurcEvaluationCtrl'
  156. /* 采购供应商资料 */
  157. }).state('purc.vendor', {
  158. url : "/vendor",
  159. templateUrl : "static/tpl/index/purc/vendor.html",
  160. controller : 'PurcVendorCtrl'
  161. /* 采购供应商资料 详情*/
  162. }).state('purc.vendordetail', {
  163. url : "/vendor/:id",
  164. templateUrl : "static/tpl/index/purc/vendor_detail.html",
  165. controller : 'PurcVendorDetailCtrl'
  166. /* 客户指定招标列表 */
  167. }).state('purc.makeoutorder', {
  168. url : "/makeoutorder",
  169. templateUrl : "static/tpl/index/make/outorder.html",
  170. controller: 'MakeOutOrderCtrl'
  171. }).state('purc.outorder_detail', {
  172. url : "/makeoutorder/:id",
  173. templateUrl : "static/tpl/index/make/outorder_detail.html",
  174. controller: 'MakeOutOrderDetailCtrl'
  175. /*平台新增询价单*/
  176. }).state('purc.inquiry_new', {
  177. url : "/purcinquiry",
  178. templateUrl : "static/tpl/index/purc/inquiry_new.html",
  179. controller: 'PurcInquiryCtrl'
  180. }).state('purc.purcinquiry_new', {
  181. url : "/purcinquiry/:bussinessCode",
  182. templateUrl : "static/tpl/index/purc/purcinquiry_new.html",
  183. controller: 'PurcInquiryNewCtrl'
  184. }).state('purc.inquiry', {
  185. url : "/purchaseinquiry",
  186. templateUrl : "static/tpl/index/purc/inquiry.html",
  187. controller: 'PurchaseInquiryCtrl'
  188. }).state('purc.inquiry_detail', {
  189. url : "/purcinquirydetail",
  190. templateUrl : "static/tpl/index/purc/inquiry_detail.html",
  191. controller: 'PurcInquiryDetailCtrl'
  192. }).state('purc.inquiryInfo_detail', {
  193. url : "/purcinquirydetail/:id",
  194. templateUrl : "static/tpl/index/purc/inquiryInfo_detail.html",
  195. controller: 'PurcInquiryInfoDetailCtrl'
  196. }).state('purc.inquiry_unapply', {
  197. url : "/inquiry_unapply",
  198. templateUrl : "static/tpl/index/purc/inquiry_unapply.html",
  199. controller: 'UnapplyInquiryCtrl'
  200. }).state('purc.product', {
  201. url : "/product",
  202. templateUrl : "static/tpl/index/purc/prodList.html",
  203. controller: 'PurcProductCtrl'
  204. }).state('purc.newProduct', {
  205. url : "/newProduct",
  206. templateUrl : "static/tpl/index/purc/newProdInfo.html",
  207. controller : 'PurcNewProdInfoCtrl'
  208. }).state('purc.productDetail', {
  209. url : "/prodList/:id",
  210. templateUrl : "static/tpl/index/purc/productDetail.html",
  211. controller : 'PurcProdDetailCtrl'
  212. }).state('purc.productmatches', {
  213. url : "/productmatches",
  214. templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
  215. controller: 'ProductmatchesForPurcCtrl'
  216. }).state('purc.uploadProduct', {
  217. url : "/uploadProduct",
  218. templateUrl : "static/tpl/index/purc/uploadByBatch.html",
  219. controller: 'UploadProductCtrl'
  220. }).state('sale.tenderlist', {
  221. url : "/tender",
  222. templateUrl : "static/tpl/index/sale/tenderlist.html",
  223. controller : 'SaleTenderCtrl'
  224. }).state('sale.todo.tenderlist', {
  225. url : "/tender",
  226. templateUrl : "static/tpl/index/sale/tenderlist.html",
  227. controller : 'SaleTenderCtrl'
  228. /* 平台公开招标列表 */
  229. }).state('baseInfo.openTenderList', {
  230. url : "/openTenderList",
  231. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  232. controller: 'SaleOpenTenderCtrl'
  233. /* 查看公开招标详情 */
  234. }).state('baseInfo.open_tender_detail', {
  235. url : "/openTenderDetail/:id",
  236. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  237. controller : 'OpenSaleTenderDetailCtrl'
  238. /* 投标 */
  239. }).state('sale.tender', {
  240. url : "/tender/:id",
  241. templateUrl : "static/tpl/index/sale/tender.html",
  242. controller : 'SaleTenderDetailCtrl'
  243. /* 采购方查看供应商投标 */
  244. }).state('sale.vendortender', {
  245. url : "/tender/:vendUU/:id",
  246. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  247. controller : 'SaleVendorTenderDetailCtrl'
  248. }).state('sale.todo', {
  249. url : "/todo",
  250. templateUrl : "static/tpl/index/sale/todo.html"
  251. }).state('sale.todo.inquiry', {
  252. url : "/inquiry",
  253. templateUrl : "static/tpl/index/sale/inquiry.html",
  254. controller: 'SaleInquiryCtrl'
  255. }).state('sale.todo.order', {
  256. url : "/order",
  257. templateUrl : "static/tpl/index/sale/order.html",
  258. controller: 'SaleOrderCtrl'
  259. }).state('sale.todo.change', {
  260. url : "/change",
  261. templateUrl : "static/tpl/index/sale/change.html",
  262. controller: 'SaleChangeCtrl'
  263. }).state('sale.todo.notice', {
  264. url : "/notice",
  265. templateUrl : "static/tpl/index/sale/notice.html",
  266. controller: 'SaleNoticeCtrl'
  267. }).state('sale.customer', {
  268. url : "/customer",
  269. templateUrl : "static/tpl/index/sale/customer.html",
  270. controller: 'CustomerCtrl'
  271. }).state('sale.customer_detail', {
  272. url : "/customer/:id",
  273. templateUrl : "static/tpl/index/sale/customer_detail.html",
  274. controller: 'CustomerDetailCtrl'
  275. }).state('sale.customerProduct', {
  276. url : "/customerProduct",
  277. templateUrl : "static/tpl/index/sale/customer.html",
  278. controller: 'CustomerCtrl'
  279. }).state('sale.inquiry', {
  280. url : "/inquiry",
  281. templateUrl : "static/tpl/index/sale/inquiry.html",
  282. controller: 'SaleInquiryCtrl'
  283. }).state('sale.inquirymould', {
  284. url : "/mould",
  285. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  286. controller: 'SaleInquiryMouldCtrl'
  287. }).state('sale.todo.inquirymould', {
  288. url : "/mould",
  289. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  290. controller: 'SaleInquiryMouldCtrl'
  291. }).state('sale.inquiry_mould_detail', {
  292. url : "/mould/:id",
  293. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  294. controller: 'SaleInquiryMouldDetailCtrl'
  295. }).state('sale.inquiry_detail', {
  296. url : "/inquiry/:id",
  297. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  298. controller: 'SaleInquiryDetailCtrl'
  299. }).state('sale.quotation', {
  300. url : "/quotation",
  301. templateUrl : "static/tpl/index/sale/quotation.html"
  302. }).state('sale.quotation.new', {
  303. url : "/new",
  304. templateUrl : "static/tpl/index/sale/quotation_new.html",
  305. controller: 'SaleQuotationNewCtrl'
  306. }).state('sale.quotation.list', {
  307. url : "/list",
  308. templateUrl : "static/tpl/index/sale/quotation_list.html",
  309. controller: 'SaleQuotationListCtrl'
  310. }).state('sale.quotation.item', {
  311. url : "/:id",
  312. templateUrl : "static/tpl/index/sale/quotation_new.html",
  313. controller: 'SaleQuotationNewCtrl'
  314. }).state('sale.order', {
  315. url : "/order",
  316. templateUrl : "static/tpl/index/sale/order.html",
  317. controller: 'SaleOrderCtrl'
  318. }).state('sale.order_detail', {
  319. url : "/order/:id",
  320. templateUrl : "static/tpl/index/sale/order_detail.html",
  321. controller: 'SaleOrderDetailCtrl'
  322. }).state('sale.change', {
  323. url : "/change",
  324. templateUrl : "static/tpl/index/sale/change.html",
  325. controller: 'SaleChangeCtrl'
  326. }).state('sale.change_detail', {
  327. url : "/change/:id",
  328. templateUrl : "static/tpl/index/sale/change_detail.html",
  329. controller: 'SaleChangeDetailCtrl'
  330. }).state('sale.notice', {
  331. url : "/notice",
  332. templateUrl : "static/tpl/index/sale/notice.html",
  333. controller: 'SaleNoticeCtrl'
  334. }).state('sale.send', {
  335. url : "/send",
  336. templateUrl : "static/tpl/index/sale/send.html",
  337. controller: 'SaleSendCtrl'
  338. }).state('sale.send_detail', {
  339. url : "/send/:id",
  340. templateUrl : "static/tpl/index/sale/send_detail.html",
  341. controller: 'SaleSendDetailCtrl'
  342. }).state('sale.forecast', {
  343. url : "/forecast",
  344. templateUrl : "static/tpl/index/sale/forecast.html",
  345. controller: 'SaleForecastCtrl'
  346. }).state('sale.accept', {
  347. url : "/accept",
  348. templateUrl : "static/tpl/index/sale/accept.html",
  349. controller: 'SaleAcceptCtrl'
  350. }).state('sale.accept_detail', {
  351. url : "/accept/:id",
  352. templateUrl : "static/tpl/index/sale/accept_detail.html",
  353. controller: 'SaleAcceptDetailCtrl'
  354. }).state('sale.returns', {
  355. url : "/returns",
  356. templateUrl : "static/tpl/index/sale/returns.html",
  357. controller: 'SaleReturnsCtrl'
  358. }).state('sale.return_detail', {
  359. url : "/return/:id",
  360. templateUrl : "static/tpl/index/sale/return_detail.html",
  361. controller: 'SaleReturnsDetailCtrl'
  362. }).state('sale.sample', {
  363. url : "/sample",
  364. templateUrl : "static/tpl/index/sale/sample.html",
  365. controller: 'SaleSampleCtrl'
  366. }).state('sale.sample_detail', {
  367. url : "/sample/:id",
  368. templateUrl : "static/tpl/index/sale/sample_detail.html",
  369. controller: 'SaleSampleDetailCtrl'
  370. }).state('sale.approval', {
  371. url : "/approval",
  372. templateUrl : "static/tpl/index/sale/approval.html",
  373. controller: 'SaleApprovalCtrl'
  374. }).state('sale.prodList', {
  375. url : "/prodList",
  376. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  377. controller : 'ProductListCtrl'
  378. }).state('sale.newProdInfo', {
  379. url : "/newProdInfo",
  380. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  381. controller : 'NewProdInfoCtrl'
  382. }).state('sale.uploadByBatch', {
  383. url : "/uploadByBatch",
  384. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  385. controller : 'UploadByBatchCtrl'
  386. }).state('sale.productDetail', {
  387. url : "/prodList/:id",
  388. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  389. controller : 'ProductDetailCtrl'
  390. }).state('sale.productmatches', {
  391. url : "/productmatches",
  392. templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
  393. controller: 'ProductmatchesForSaleCtrl'
  394. }).state('sale.maketodo', {
  395. url : "/maketodo",
  396. templateUrl : "static/tpl/index/make/todo.html"
  397. }).state('sale.maketodo.order', {
  398. url : "/makeorder",
  399. templateUrl : "static/tpl/index/make/order.html",
  400. controller: 'MakeOrderCtrl'
  401. }).state('sale.makeorder', {
  402. url : "/makeorder",
  403. templateUrl : "static/tpl/index/make/order.html",
  404. controller: 'MakeOrderCtrl'
  405. }).state('sale.makeorder_detail', {
  406. url : "/makeorder/:id",
  407. templateUrl : "static/tpl/index/make/order_detail.html",
  408. controller: 'MakeOrderDetailCtrl'
  409. }).state('sale.badOut', {
  410. url : "/badOut",
  411. templateUrl : "static/tpl/index/qc/badOut.html",
  412. controller: 'SaleBadOutCtrl'
  413. }).state('sale.MRB', {
  414. url : "/MRB",
  415. templateUrl : "static/tpl/index/qc/MRB.html",
  416. controller: 'SaleMRBCtrl'
  417. }).state('sale.badIn', {
  418. url : "/badIn",
  419. templateUrl : "static/tpl/index/qc/badIn.html",
  420. controller: 'SaleBadInCtrl'
  421. }).state('sale.makeaccept', {
  422. url : "/makeaccept",
  423. templateUrl : "static/tpl/index/make/accept.html",
  424. controller: 'MakeAcceptCtrl'
  425. }).state('sale.makereturns', {
  426. url : "/makereturns",
  427. templateUrl : "static/tpl/index/make/returns.html",
  428. controller: 'MakeReturnCtrl'
  429. }).state('sale.makechange', {
  430. url : "/makechange",
  431. templateUrl : "static/tpl/index/make/change.html",
  432. controller: 'MakeChangeCtrl'
  433. }).state('sale.makechange_detail', {
  434. url : "/makechange/:id",
  435. templateUrl : "static/tpl/index/make/change_detail.html",
  436. controller: 'MakeChangeDetailCtrl'
  437. }).state('account', {
  438. url : "/account",
  439. views : {
  440. "left-view" : {
  441. templateUrl : "static/tpl/index/account/left.html",
  442. controller: 'LeftCtrl'
  443. },
  444. "right-view" : {
  445. templateUrl : "static/tpl/index/account/right.html"
  446. }
  447. }
  448. }).state('account.index', {
  449. url : "",
  450. templateUrl : "static/tpl/index/account/index.html",
  451. controller: 'RightCtrl'
  452. }).state('account.home', {
  453. url : "/",
  454. templateUrl : "static/tpl/index/account/index.html",
  455. controller: 'RightCtrl'
  456. }).state('baseInfo', {//基础资料
  457. url : "/baseInfo",
  458. views : {
  459. "left-view" : {
  460. },
  461. "right-view" : {
  462. templateUrl : "static/tpl/index/baseInfo/right.html"
  463. }
  464. }
  465. }).state('baseInfo.index', {
  466. url : "/enterpriseList",
  467. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  468. controller: 'EnterpriseListCtrl'
  469. }).state('baseInfo.home', {
  470. url : "/enterpriseList",
  471. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  472. controller: 'EnterpriseListCtrl'
  473. }).state('baseInfo.enterpriseList', {
  474. url : "/enterpriseList",
  475. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  476. controller : 'EnterpriseListCtrl'
  477. }).state('baseInfo.myClient', {
  478. url : "/myClient",
  479. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  480. controller : 'MyClientCtrl'
  481. }).state('baseInfo.mySupplier', {
  482. url : "/mySupplier",
  483. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  484. controller : 'MySupplierCtrl'
  485. }).state('baseInfo.myRequest', {
  486. url : "/myRequest",
  487. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  488. controller : 'AddPartnerRequestCtrl'
  489. }).state('baseInfo.newPartner', {
  490. url : "/newPartner",
  491. templateUrl : "static/tpl/index/baseInfo/newPartner.html",
  492. controller : 'NewPartnerCtrl'
  493. }).state('baseInfo.myMessage', {
  494. url : "/myMessage",
  495. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  496. controller : 'AddPartnerMessageCtrl'
  497. }).state('baseInfo.myPartners', {
  498. url : '/myPartners',
  499. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  500. controller : 'MyPartnersCtrl'
  501. }).state('baseInfo.businessGroups', {
  502. url : '/businessGroups',
  503. controller : 'BusinessGroupsCtrl'
  504. }).state('baseInfo.inquiryList', {
  505. url : '/inquiryList',
  506. templateUrl : "static/tpl/index/baseInfo/inquiry_list.html",
  507. controller : 'PublicInquiryListCtrl'
  508. }).state('baseInfo.inquiryListDetail', {
  509. url : '/inquiryList/:id',
  510. templateUrl : "static/tpl/index/baseInfo/inquiryItem_detail.html",
  511. controller : 'PublicInquiryListDetailCtrl'
  512. }).state('baseInfo.vendorInfo', {
  513. url : '/enume/vendorInfo',
  514. templateUrl : "static/tpl/index/baseInfo/vendorsInfo.html",
  515. controller : 'VendorsInfoCtrl'
  516. }).state('baseInfo.customerInfo', {
  517. url : '/enume/customerInfo',
  518. templateUrl : "static/tpl/index/baseInfo/customersInfo.html",
  519. controller : 'CustomersInfoCtrl'
  520. }).state('baseInfo.enume', {
  521. url : '/enume',
  522. templateUrl : "static/tpl/index/baseInfo/vendorAndCustomer.html",
  523. }).state('baseInfo.partner', {
  524. url : '/partner',
  525. templateUrl : "static/tpl/index/baseInfo/addPartners.html",
  526. controller : 'AddPartnersCtrl'
  527. }).state('baseInfo.partner_searchresult', {
  528. url : '/search',
  529. templateUrl : "static/tpl/index/baseInfo/searchresult.html",
  530. controller : 'EnterpriseSearchCtrl'
  531. }).state('baseInfo.invitation', {
  532. url : '/invitation',
  533. templateUrl : "static/tpl/index/baseInfo/invitation.html",
  534. controller : 'InvitationCtrl'
  535. }).state('qc', {
  536. url : "/qc",
  537. views : {
  538. "left-view" : {
  539. templateUrl : "static/tpl/index/qc/left.html"
  540. },
  541. "right-view" : {
  542. templateUrl : "static/tpl/index/qc/right.html"
  543. }
  544. }
  545. }).state('qc.index', {
  546. url : "",
  547. templateUrl : "static/tpl/index/qc/index.html"
  548. }).state('qc.home', {
  549. url : "/",
  550. templateUrl : "static/tpl/index/qc/index.html"
  551. }).state('fa', {
  552. url : "/fa",
  553. views : {
  554. "left-view" : {
  555. templateUrl : "static/tpl/index/fa/left.html"
  556. },
  557. "right-view" : {
  558. templateUrl : "static/tpl/index/fa/right.html"
  559. }
  560. }
  561. }).state('fa.index', {
  562. url : "",
  563. templateUrl : "static/tpl/index/fa/index.html"
  564. }).state('fa.home', {
  565. url : "/",
  566. templateUrl : "static/tpl/index/fa/index.html"
  567. }).state('fa.apBill', {
  568. url : "/apBill",
  569. templateUrl : "static/tpl/index/fa/apBill.html",
  570. controller: 'SaleApBillCtrl'
  571. }).state('fa.apBill_detail', {
  572. url : "/apBill/:id",
  573. templateUrl : "static/tpl/index/fa/apBill_detail.html",
  574. controller: 'SaleApBillDetailCtrl'
  575. }).state('fa.arCheck', {
  576. url : "/arCheck",
  577. templateUrl : "static/tpl/index/fa/arCheck.html",
  578. controller: 'SaleArCheckCtrl'
  579. }).state('fa.arCheck_detail', {
  580. url : "/arCheck/:id",
  581. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  582. controller: 'SaleArCheckDetailCtrl'
  583. }).state('fa.apCheck', {
  584. url : "/apCheck",
  585. params:{
  586. 'id':null
  587. },
  588. templateUrl : "static/tpl/index/fa/apCheck.html",
  589. controller: 'PurchaseApCheckCtrl'
  590. }).state('fa.apCheck_detail', {
  591. url : "/apCheck/:id",
  592. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  593. controller: 'PurchaseApCheckDetailCtrl'
  594. }).state('fa.apCheckList', {
  595. url : "/apCheckList",
  596. templateUrl : "static/tpl/index/fa/apCheckList.html",
  597. controller: 'PurchaseApCheckListCtrl'
  598. }).state('fa.adjustList', {
  599. url : "/adjustList",
  600. templateUrl : "static/tpl/index/fa/adjustList.html",
  601. controller: 'PurchaseAdjustListCtrl'
  602. }).state('make', {
  603. url : "/make",
  604. views : {
  605. "left-view" : {
  606. templateUrl : "static/tpl/index/make/left.html"
  607. },
  608. "right-view" : {
  609. templateUrl : "static/tpl/index/make/right.html"
  610. }
  611. }
  612. }).state('make.index', {
  613. url : "",
  614. templateUrl : "static/tpl/index/make/index.html"
  615. }).state('make.home', {
  616. url : "/",
  617. templateUrl : "static/tpl/index/make/index.html"
  618. }).state('cs', {// 客户服务
  619. url : "/cs",
  620. views : {
  621. "left-view" : {
  622. templateUrl : "static/tpl/index/cs/left.html"
  623. },
  624. "right-view" : {
  625. templateUrl : "static/tpl/index/cs/right.html"
  626. }
  627. }
  628. }).state('cs.index', {
  629. url : "",
  630. templateUrl : "static/tpl/index/cs/index.html"
  631. }).state('cs.home', {
  632. url : "/",
  633. templateUrl : "static/tpl/index/cs/index.html"
  634. }).state('search', { //顶部搜索
  635. url: "/search?keyword=",
  636. views : {
  637. "left-view" : {
  638. templateUrl : "static/tpl/index/search/left.html"
  639. },
  640. "right-view" : {
  641. templateUrl: "static/tpl/index/search/search_result.html",
  642. controller: 'TopSearchCtrl'
  643. }
  644. }
  645. }).state('approvalflow', { //审批流
  646. url: "/approvalFlow",
  647. views : {
  648. "left-view" : {
  649. templateUrl : "static/tpl/index/approvalFlow/left.html"
  650. },
  651. "right-view" : {
  652. templateUrl: "static/tpl/index/approvalFlow/right.html",
  653. }
  654. }
  655. }).state('approvalflow.flow', {
  656. url : "/flow",
  657. templateUrl : "static/tpl/index/approvalFlow/home.html",
  658. controller: 'approvalFlowCtrl'
  659. }).state('approvalflow.enterprise', {
  660. url : "/enterprise",
  661. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  662. controller: 'EnterpriseCtrl'
  663. }).state('approvalflow.user', {
  664. url : "/user",
  665. templateUrl : "static/tpl/index/approvalFlow/user.html",
  666. controller: 'UserCtrl'
  667. }).state('approvalflow.log', {
  668. url : "/log",
  669. templateUrl : "static/tpl/index/approvalFlow/log.html",
  670. controller: 'LogCtrl'
  671. }).state('approvalflow.resource', {
  672. url : "/resource",
  673. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  674. controller: 'ResourceCtrl'
  675. }).state('approvalflow.role', {
  676. url : "/role",
  677. templateUrl : "static/tpl/index/approvalFlow/role.html",
  678. controller: 'RoleCtrl'
  679. }).state('approvalflow.product', {
  680. url : "/product",
  681. templateUrl : "static/tpl/index/approvalFlow/prodList.html",
  682. controller: 'ProductAllCtrl'
  683. }).state('approvalflow.productmatches', {
  684. url : "/productmatches",
  685. templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
  686. controller: 'ProductmatchesCtrl'
  687. });
  688. $urlRouterProvider.otherwise('/index');
  689. }]);
  690. /**
  691. * 表示符号
  692. */
  693. app.factory('Symbol', function(){
  694. return {
  695. currency: function(cur) {
  696. if(cur == 'RMB') return '¥';
  697. else if(cur == 'USD') return '$';
  698. else if(cur == 'EUR') return '€';
  699. else if(cur == null || cur == '') return '¥';
  700. else return cur;
  701. }
  702. };
  703. }).factory('Lodop',function(){
  704. return {
  705. getLodop:function(oOBJECT,oEMBED){
  706. var CreatedOKLodop7766=null;
  707. /**************************
  708. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  709. IE系列、IE内核系列的浏览器采用oOBJECT,
  710. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  711. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  712. 64位浏览器指向64位的安装程序install_lodop64.exe。
  713. **************************/
  714. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  715. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  716. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  717. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  718. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  719. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  720. var LODOP;
  721. try{
  722. //=====判断浏览器类型:===============
  723. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  724. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  725. //=====如果页面有Lodop就直接使用,没有则新建:==========
  726. if (oOBJECT!=undefined || oEMBED!=undefined) {
  727. if (isIE)
  728. LODOP=oOBJECT;
  729. else
  730. LODOP=oEMBED;
  731. } else {
  732. if (CreatedOKLodop7766==null){
  733. LODOP=document.createElement("object");
  734. LODOP.setAttribute("width",0);
  735. LODOP.setAttribute("height",0);
  736. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  737. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  738. else LODOP.setAttribute("type","application/x-print-lodop");
  739. document.documentElement.appendChild(LODOP);
  740. CreatedOKLodop7766=LODOP;
  741. } else
  742. LODOP=CreatedOKLodop7766;
  743. };
  744. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  745. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  746. if (navigator.userAgent.indexOf('Chrome')>=0)
  747. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  748. if (navigator.userAgent.indexOf('Firefox')>=0)
  749. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  750. if (is64IE) document.write(strHtm64_Install); else
  751. if (isIE) document.write(strHtmInstall); else
  752. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  753. return LODOP;
  754. } else
  755. if (LODOP.VERSION<"6.1.9.8") {
  756. if (is64IE) document.write(strHtm64_Update); else
  757. if (isIE) document.write(strHtmUpdate); else
  758. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  759. return LODOP;
  760. };
  761. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  762. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  763. //============================================================
  764. return LODOP;
  765. } catch(err) {
  766. if (is64IE)
  767. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  768. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  769. return LODOP;
  770. };
  771. }
  772. }
  773. });
  774. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', 'toaster', function($scope, $rootScope, $modal, toaster) {
  775. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  776. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  777. if (routeState.indexOf('/') > -1)
  778. routeState = routeState.substring(0, routeState.indexOf('/'));
  779. if (routeState.indexOf('.') > -1)
  780. routeState = routeState.substring(0, routeState.indexOf('.'));
  781. $scope.routeState = routeState || 'home';
  782. });
  783. $scope.search = function(keyword) {
  784. if(keyword != null && keyword != '') {
  785. $rootScope.searchKeyword = keyword;
  786. window.location.hash = '#/search?keyword=' + keyword;
  787. } else {
  788. $rootScope.searchKeyword = null;
  789. window.location.hash = '#/search';
  790. }
  791. };
  792. $scope.showMessage = function() {
  793. var $modalInstance = $modal.open({
  794. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  795. controller: 'PagingReleaseCtrl'
  796. });
  797. };
  798. // 连接到询价
  799. $scope.linktoInquiry = function(active) {
  800. $rootScope.active = active;
  801. window.location.href = "#/sale/inquiry";
  802. }
  803. // 连接到招标
  804. $scope.linktoSaleTender = function(active) {
  805. $rootScope.active = active;
  806. window.location.href = "#/sale/tender";
  807. }
  808. // 链接到打样申请
  809. $scope.linktoSample = function(active) {
  810. $rootScope.active = active;
  811. window.location.href = "#/sale/sample";
  812. }
  813. // 链接到采购招标
  814. $scope.linktoPurcTender = function(active) {
  815. $rootScope.tenderActive = active;
  816. window.location.href = "#/purc/tender";
  817. }
  818. $scope.linktoPurcInquiry = function(active) {
  819. $rootScope.active = active;
  820. window.location.href = "#/purc/purchaseinquiry";
  821. }
  822. }]);
  823. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  824. BaseService.scrollBackToTop();
  825. $scope.active = "todo";
  826. $scope.setActive = function(state) {
  827. if($scope.active != state) {
  828. $scope.active = state;
  829. if($scope.tableParams.page() == 1)
  830. $scope.tableParams.reload();
  831. else
  832. $scope.tableParams.page(1);
  833. }
  834. };
  835. $scope.tableParams = new ngTableParams({
  836. page : 1,
  837. count : 20,
  838. sorting: {
  839. 'releaseDetail.release.date': 'desc'
  840. }
  841. }, {
  842. total : 0,
  843. counts: [5, 10, 25, 50],
  844. getData : function($defer, params) {
  845. $scope.loading = true;
  846. var pageParams = params.url();
  847. var realActive = {};
  848. pageParams.searchFilter = { // 筛选条件
  849. keyword: $scope.keyword
  850. // fromDate: getDateTime($scope.condition.dateFrom),
  851. // endDate: getDateTime($scope.condition.dateTo)
  852. };
  853. // AccountEnterprise.get({}, function(data){
  854. // $scope.loading = false;
  855. // $scope.currentEn = data;
  856. // });
  857. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  858. $scope.loading = false;
  859. if(page) {
  860. params.total(page.totalElement);
  861. $defer.resolve(page.content);
  862. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  863. }
  864. }, function(response){
  865. $scope.loading = false;
  866. toaster.pop('error', '数据加载失败', response.data);
  867. });
  868. }
  869. });
  870. $scope.close = function() {
  871. $modalInstance.close();
  872. };
  873. $scope.checks = {
  874. checked : false
  875. };// 全选框
  876. $scope.checkAll = function() {
  877. angular.forEach($scope.tableParams.data, function(message) {
  878. message.checked = $scope.checks.checked;
  879. });
  880. };
  881. // 单选
  882. $scope.checkOne = function(vendor) {
  883. vendor.checked = true;
  884. var checked = true;
  885. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  886. if (!message.checked) {
  887. checked = false;
  888. }
  889. });
  890. $scope.checks.checked = checked;
  891. };
  892. // 单反选
  893. $scope.unCheckOne = function(vendor) {
  894. vendor.checked = false;
  895. $scope.checks.checked = false;
  896. };
  897. // 标为已读
  898. $scope.setRead = function() {
  899. var selectedMessages = [];
  900. angular.forEach($scope.tableParams.data, function(message) {
  901. if(message.checked) {
  902. selectedMessages.push(message);
  903. }
  904. });
  905. PagingRelease.setRead({}, selectedMessages , function(message) {
  906. $scope.tableParams.page(1);
  907. $scope.tableParams.reload();
  908. });
  909. };
  910. // 搜索框回车
  911. $scope.onSearch = function() {
  912. $scope.tableParams.page(1);
  913. $scope.tableParams.reload();
  914. };
  915. }]);
  916. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  917. var search = $rootScope.searchKeyword;
  918. return function(content, search) {
  919. content = encodeURI(content);
  920. search = encodeURI(search);
  921. var reg = new RegExp(search, 'gim');
  922. var result = content.replace(reg,'<font color="red">$&</font>');
  923. result = decodeURI(result);
  924. return $sce.trustAsHtml(result);
  925. };
  926. $rootScope.searchKeyword = null;// 清除缓存的关键字
  927. }]);
  928. /**
  929. * 顶部搜索
  930. */
  931. 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) {
  932. BaseService.scrollBackToTop();
  933. $scope.active = 'all';
  934. $scope.tip = $rootScope.searchKeyword;
  935. // 企业搜索
  936. var getService = function() {
  937. return getAccountUserSpace;
  938. };
  939. $scope.tableParams = new ngTableParams({
  940. page : 1,
  941. count : 20,
  942. sorting: {
  943. }
  944. }, {
  945. total : 0,
  946. counts: [5, 10, 25, 50],
  947. getData : function($defer, params) {
  948. $scope.loading = true;
  949. var pageParams = params.url();
  950. pageParams.keyword = $rootScope.searchKeyword;
  951. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  952. $scope.loading = false;
  953. if(page) {
  954. $scope.total = page.totalElement;
  955. params.total(page.totalElement);
  956. $defer.resolve(page.content);
  957. }
  958. }, function(response) {
  959. $scope.loading = false;
  960. toaster.pop('error', '数据加载失败', response.data);
  961. });
  962. }
  963. });
  964. // 添加合作关系
  965. $scope.addPartner = function(name, businessCode) {
  966. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  967. if(data.success) {
  968. toaster.pop("success", '添加成功', data.success);
  969. $scope.tableParams.reload();
  970. }
  971. if(data.error) {
  972. toaster.pop("error", '添加失败', data.error);
  973. }
  974. }, function(response) {
  975. toaster.pop('error','失败',response.data);
  976. });
  977. }
  978. // 物料搜索
  979. var getProdService = function() {
  980. return SearchProd;
  981. };
  982. $scope.prodTableParams = new ngTableParams({
  983. page : 1,
  984. count : 20,
  985. sorting: {
  986. }
  987. }, {
  988. total : 0,
  989. counts: [5, 10, 25, 50],
  990. getData : function($defer, params) {
  991. $scope.loading = true;
  992. var pageParams = params.url();
  993. pageParams.keyword = $rootScope.searchKeyword;
  994. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  995. $scope.loading = false;
  996. if(page) {
  997. $scope.prodtotal = page.totalElement;
  998. params.total(page.totalElement);
  999. $defer.resolve(page.content);
  1000. }
  1001. }, function(response) {
  1002. $scope.loading = false;
  1003. toaster.pop('error', '数据加载失败', response.data);
  1004. });
  1005. }
  1006. });
  1007. /**
  1008. * 向企业购买
  1009. */
  1010. $scope.PurcByEn = function(businessCode) {
  1011. $rootScope.businessCode = businessCode;
  1012. window.location.hash = "#/purc/addOrder";
  1013. }
  1014. /**
  1015. * 选中单个物料购买
  1016. * @param businessCode
  1017. * @param id
  1018. */
  1019. $scope.PurcByEnAndProd = function(businessCode, id) {
  1020. $rootScope.businessCode = businessCode;
  1021. $rootScope.prodId = id;
  1022. window.location.hash = "#/purc/addOrder";
  1023. }
  1024. /**
  1025. * 询价
  1026. */
  1027. $scope.PurcInquiry = function(businessCode, id){
  1028. $rootScope.prodId = id;
  1029. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1030. }
  1031. /**
  1032. * 邀请注册商务平台
  1033. */
  1034. $scope.invite = function(name) {
  1035. var modalInstance = $modal.open({
  1036. animation: true,
  1037. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1038. controller: 'InviteCtrl',
  1039. resolve: {
  1040. enname: function(){return name}
  1041. }
  1042. });
  1043. modalInstance.result.then(function(data) {
  1044. InvitationRecord.invite({formStore: data}, {}, function(data) {
  1045. if(data.success) {
  1046. toaster.pop('success', '提示', data.success);
  1047. }
  1048. if(data.error) {
  1049. toaster.pop('error', '提示', data.error);
  1050. }
  1051. }, function(response) {
  1052. toaster.pop('error', '提示', response.data);
  1053. });
  1054. });
  1055. }
  1056. /**
  1057. * 立即查看
  1058. */
  1059. $scope.view = function(name) {
  1060. $rootScope.vendName = name;
  1061. window.location.hash = "#/baseInfo/newPartner";
  1062. }
  1063. }]);
  1064. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  1065. $scope.enter = {
  1066. vendname: enname
  1067. };
  1068. $scope.save = function(enter) {
  1069. if(!enter.vendusertel && !enter.venduseremail) {
  1070. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1071. } else {
  1072. $modalInstance.close(enter);
  1073. }
  1074. }
  1075. $scope.cancel = function() {
  1076. $modalInstance.dismiss();
  1077. }
  1078. }]);
  1079. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function($scope, toaster, $modalInstance, id, InvitationRecord) {
  1080. var loadData = function (id) {
  1081. InvitationRecord.getRecordById({id: id}, {}, function(data) {
  1082. if (data.user !== null) {
  1083. data.user = {};
  1084. }
  1085. $scope.enter = data;
  1086. });
  1087. };
  1088. loadData(id);
  1089. $scope.save = function(enter) {
  1090. if(!enter.vendusertel && !enter.venduseremail) {
  1091. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1092. } else {
  1093. $modalInstance.close(enter);
  1094. }
  1095. };
  1096. $scope.cancel = function() {
  1097. $modalInstance.dismiss();
  1098. }
  1099. }]);
  1100. /**
  1101. * 邀请记录
  1102. */
  1103. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1104. BaseService.scrollBackToTop();
  1105. $scope.status = "invitation";
  1106. $scope.active = "invitation";
  1107. var getService = function() {
  1108. if ($scope.active === "invitation") {
  1109. return InvitationRecord.records;
  1110. } else if ($scope.active === "invitationTeam") {
  1111. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1112. }
  1113. };
  1114. $scope.setActive = function(state) {
  1115. if($scope.active !== state) {
  1116. $scope.active = state;
  1117. if($scope.tableParams.page() === 1)
  1118. $scope.tableParams.reload();
  1119. else
  1120. $scope.tableParams.page(1);
  1121. }
  1122. };
  1123. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1124. page : 1,
  1125. count : 20,
  1126. sorting: {
  1127. }
  1128. }, {
  1129. total : 0,
  1130. counts: [],
  1131. getData : function($defer, params) { // 获取数据的方法
  1132. $scope.loading = true;
  1133. var pageParams = params.url();
  1134. pageParams.keyword = $scope.keyword;
  1135. $scope.tip = $scope.keyword;
  1136. getService().call(null, BaseService.parseParams(pageParams), function(page){
  1137. $scope.loading = false;
  1138. if(page) {
  1139. params.total(page.totalElement);
  1140. $defer.resolve(page.content);
  1141. }
  1142. }, function(response){
  1143. $scope.loading = false;
  1144. toaster.pop('error', '数据加载失败', response.data);
  1145. });
  1146. }
  1147. });
  1148. $scope.onSearch = function(keyword){
  1149. $scope.tableParams.page(1);
  1150. $scope.tableParams.reload();
  1151. $scope.tip = keyword;
  1152. }
  1153. $scope.search = function(name) {
  1154. $modal.open({
  1155. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1156. controller: 'FuzzySearchCtrl',
  1157. resolve: {name: function() {return name}}
  1158. }).result.then(function(data){
  1159. });
  1160. };
  1161. // 再次邀请
  1162. $scope.reInvite = function(id) {
  1163. var modalInstance = $modal.open({
  1164. animation: true,
  1165. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1166. controller: 'ReInviteCtrl',
  1167. resolve: {
  1168. id: function(){return id}
  1169. }
  1170. });
  1171. modalInstance.result.then(function(data) {
  1172. InvitationRecord.invite({formStore: data}, {}, function(data) {
  1173. if(data.success) {
  1174. toaster.pop('success', '提示', data.success);
  1175. $scope.tableParams.reload();
  1176. }
  1177. if(data.error) {
  1178. toaster.pop('error', '提示', data.error);
  1179. }
  1180. }, function(response) {
  1181. toaster.pop('error', '提示', response.data);
  1182. });
  1183. });
  1184. }
  1185. }]);
  1186. /**
  1187. * 模糊查询相似的企业名称
  1188. */
  1189. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function($scope, name, InvitationRecord, toaster, BaseService) {
  1190. $scope.name = name;
  1191. if($scope.name != null) {
  1192. InvitationRecord.enterpriseList({name: $scope.name}, {}, function(data) {
  1193. $scope.enterprises = data;
  1194. }, function(response) {
  1195. toaster.pop('error', '提示', response.data);
  1196. });
  1197. }
  1198. }]);
  1199. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1200. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1201. //手机号码格式验证
  1202. // var checkTel = function(data){
  1203. // var userTel = data.userTel;
  1204. // $scope.checkResult = false;
  1205. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  1206. // if(!(telephone).test(userTel)){
  1207. // var modalInstance = $modal.open({
  1208. // animation: true,
  1209. // templateUrl: 'static/tpl/index/account/checkTel.html',
  1210. // controller: 'CheckTelCtrl',
  1211. // backdrop: 'static',
  1212. // keyboard: false,
  1213. // resolve: {
  1214. // user: function(){
  1215. // return data;
  1216. // },
  1217. // }
  1218. // });
  1219. // modalInstance.result.then(function(){
  1220. // }, function(){
  1221. //
  1222. // });
  1223. // } else {
  1224. // $scope.checkResult = true;
  1225. // }
  1226. // };
  1227. AuthenticationService.getAuthentication().success(function(data) {
  1228. if(data.enterprises) {
  1229. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1230. if(data.enterprises.length > 1) {
  1231. var enSelect = [];
  1232. angular.forEach(data.enterprises, function(e){
  1233. if(e.current)
  1234. data.enterprise = e;
  1235. else
  1236. enSelect.push(e);
  1237. });
  1238. data.enSelect = enSelect;
  1239. }
  1240. }
  1241. $scope.userInfo = data;
  1242. if (data == null || !data.userUU) {
  1243. $scope.isAuthed = false;
  1244. AuthenticationService.redirectSignin();
  1245. } else {
  1246. //跳转到手机号码验证
  1247. // checkTel($scope.userInfo);
  1248. }
  1249. });
  1250. $scope.logout = function() {
  1251. $modal.open({
  1252. templateUrl: 'static/tpl/index/account/logout.html',
  1253. controller: 'LogOutCtrl'
  1254. }).result.then(function(s){
  1255. if(s) {
  1256. AuthenticationService.logout();
  1257. }
  1258. });
  1259. };
  1260. $scope.switchto = function(enUU) {// 切换企业
  1261. AuthenticationService.reSignin(enUU).success(function(){
  1262. $window.location.reload();
  1263. });
  1264. };
  1265. $scope.addFavorite = function(){
  1266. var url = encodeURI(window.location.href);
  1267. try{
  1268. //ie浏览器收藏方式
  1269. window.external.addFavorite(url, "优软商务平台");
  1270. }catch(e) {
  1271. try{
  1272. //火狐浏览器收藏方式
  1273. window.sidebar.addPanel("优软商务平台", url);
  1274. }catch (e) {
  1275. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  1276. "或手动在浏览器里进行设置。");
  1277. }
  1278. }
  1279. };
  1280. }]);
  1281. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1282. $scope.close = function(confirm) {
  1283. $modalInstance.close(confirm);
  1284. };
  1285. }]);
  1286. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1287. $scope.image = {src: null};
  1288. // 图片上传成功之后
  1289. $scope.onUploadSuccess = function(data){
  1290. var path = data.path;
  1291. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1292. $scope.$apply(function(){
  1293. $scope.image.src = data.path;
  1294. $scope.image.thumb = path;
  1295. });
  1296. };
  1297. $scope.close = function() {
  1298. $modalInstance.dismiss();
  1299. };
  1300. $scope.confirm = function() {
  1301. $modalInstance.close($scope.image);
  1302. $scope.imageUrl = null;
  1303. };
  1304. }]);
  1305. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function($scope, SnapshotService, BaseService, $rootScope){
  1306. BaseService.scrollBackToTop();
  1307. SnapshotService.getTodo(function(data){
  1308. $scope.todo = data;
  1309. });
  1310. $scope.setTenderActive = function(active) {
  1311. $rootScope.tenderActive = active;
  1312. window.location.hash = '#/purc/tender';
  1313. }
  1314. }]);
  1315. // header
  1316. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1317. SnapshotService.getMessage(function(data){
  1318. $scope.message = data;
  1319. });
  1320. }]);
  1321. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1322. SaleTruck.query({}, function(data){
  1323. $rootScope.truck = data;
  1324. $scope.truckCount = data ? data.length : 0;
  1325. });
  1326. $scope.$watch(function(){
  1327. return $rootScope.truck;
  1328. }, function(data) {
  1329. $scope.truckCount = data ? data.length : 0;
  1330. }, true);
  1331. $scope.clearAll = function() {
  1332. SaleTruck.remove({}, function(){
  1333. $rootScope.truck = [];
  1334. });
  1335. };
  1336. $scope.openTrack = function() {
  1337. $modal.open({
  1338. templateUrl: 'static/tpl/index/sale/track.html',
  1339. controller: 'TruckModalCtrl',
  1340. size: 'lg'
  1341. }).result.then(function(s){
  1342. if(s) {
  1343. $scope.clearAll();
  1344. $rootScope.dataChanged = true;
  1345. }
  1346. });
  1347. };
  1348. }]);
  1349. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout){
  1350. $scope.saleSend = {sendItems: []};
  1351. SaleTruck.detail({}, function(data){
  1352. // 按物料编号排序
  1353. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1354. });
  1355. $scope.remove = function(index, notice) {
  1356. SaleTruck.remove({noticeId: notice.id}, function(data){
  1357. $rootScope.truck = data;
  1358. $scope.notices.splice(index, 1);
  1359. });
  1360. };
  1361. $scope.$watch(function(){
  1362. return $scope.notices;
  1363. }, function(data) {
  1364. var q = 0, t = 0;
  1365. if(data) {
  1366. angular.forEach(data,function(d){
  1367. q += d.thisSendQty;
  1368. t += d.thisSendQty * d.orderItem.price;
  1369. });
  1370. }
  1371. $scope.totalQty = q;
  1372. $scope.total = t;
  1373. }, true);
  1374. $scope.cancel = function() {
  1375. $modalInstance.close();
  1376. };
  1377. $scope.lockstatus = false;
  1378. // 锁定时间按钮5秒
  1379. $scope.lockClick = function() {
  1380. $scope.lockstatus = true;
  1381. $timeout(function() {
  1382. $scope.lockstatus = false;
  1383. }, 5000);
  1384. }
  1385. $scope.send = function() {// 发货
  1386. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1387. toaster.pop('error', '错误', '请输入送货单号');
  1388. return;
  1389. }
  1390. var currency = $scope.notices[0].orderItem.order.currency,
  1391. custUU = $scope.notices[0].enUU,
  1392. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1393. var num = 1;
  1394. for(var i in $scope.notices) {
  1395. var item = $scope.notices[i];
  1396. if(item.id) {
  1397. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1398. valid = false;
  1399. break;
  1400. }
  1401. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1402. }
  1403. }
  1404. if(!valid) {
  1405. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1406. } else {
  1407. var send = angular.extend(angular.copy($scope.saleSend), {
  1408. currency: currency,
  1409. custUU: custUU,
  1410. payments: payments,
  1411. sendItems: items
  1412. });
  1413. PurcNotice.sendByBatch({}, send, function(data){
  1414. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1415. $modalInstance.close(true);
  1416. $state.go('sale.send_detail', {id: data.id});
  1417. }, function(response){
  1418. toaster.pop('error', '错误', response.data);
  1419. });
  1420. }
  1421. };
  1422. }]);
  1423. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1424. SaleStat.cust({}, function(data){
  1425. var p = [], q = [];
  1426. angular.forEach(data.month, function(d){
  1427. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1428. });
  1429. angular.forEach(data.year, function(d){
  1430. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1431. });
  1432. $scope.custCharts = {
  1433. month : {
  1434. chartType : 'pie',
  1435. datas : {
  1436. data : p
  1437. },
  1438. config : {
  1439. labels : false,
  1440. title : "客户月采购量排行榜",
  1441. legend : {
  1442. display : true,
  1443. position : 'right'
  1444. },
  1445. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1446. click : function(d) {
  1447. },
  1448. mouseover : function(d) {
  1449. },
  1450. mouseout : function(d) {
  1451. },
  1452. innerRadius : 0,
  1453. lineLegend : 'lineEnd'
  1454. }
  1455. },
  1456. year : {
  1457. chartType : 'pie',
  1458. datas : {
  1459. data : q
  1460. },
  1461. config : {
  1462. labels : false,
  1463. title : "客户年采购量排行榜",
  1464. legend : {
  1465. display : true,
  1466. position : 'right'
  1467. },
  1468. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1469. click : function(d) {
  1470. },
  1471. mouseover : function(d) {
  1472. },
  1473. mouseout : function(d) {
  1474. },
  1475. innerRadius : 0,
  1476. lineLegend : 'lineEnd'
  1477. }
  1478. }
  1479. };
  1480. });
  1481. SaleStat.seller({}, function(data){
  1482. var p = [], q = [];
  1483. angular.forEach(data.month, function(d){
  1484. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1485. });
  1486. angular.forEach(data.year, function(d){
  1487. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1488. });
  1489. $scope.sellerCharts = {
  1490. month : {
  1491. chartType : 'pie',
  1492. datas : {
  1493. data : p
  1494. },
  1495. config : {
  1496. labels : false,
  1497. title : "业务员月销量排行榜",
  1498. legend : {
  1499. display : true,
  1500. position : 'right'
  1501. },
  1502. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1503. click : function(d) {
  1504. },
  1505. mouseover : function(d) {
  1506. },
  1507. mouseout : function(d) {
  1508. },
  1509. innerRadius : 0,
  1510. lineLegend : 'lineEnd'
  1511. }
  1512. },
  1513. year : {
  1514. chartType : 'pie',
  1515. datas : {
  1516. data : q
  1517. },
  1518. config : {
  1519. labels : false,
  1520. title : "业务员年销量排行榜",
  1521. legend : {
  1522. display : true,
  1523. position : 'right'
  1524. },
  1525. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1526. click : function(d) {
  1527. },
  1528. mouseover : function(d) {
  1529. },
  1530. mouseout : function(d) {
  1531. },
  1532. innerRadius : 0,
  1533. lineLegend : 'lineEnd'
  1534. }
  1535. }
  1536. };
  1537. });
  1538. }]);
  1539. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1540. SaleStat.get({}, function(data){
  1541. var p = [], q = [], r = [];
  1542. angular.forEach(data.day, function(d){
  1543. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1544. });
  1545. angular.forEach(data.month, function(d){
  1546. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1547. });
  1548. angular.forEach(data.year, function(d){
  1549. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1550. });
  1551. $scope.charts = {
  1552. day : {
  1553. chartType : "line",
  1554. datas: {
  1555. series: ['销售额'],
  1556. data: p
  1557. },
  1558. config : {
  1559. "labels": false,
  1560. "title": "销售额统计(近15日线)",
  1561. "legend": {
  1562. "display": true,
  1563. "position": "right"
  1564. },
  1565. colors : [ '#4D9934'],
  1566. "innerRadius": 0,
  1567. "lineLegend": "lineEnd"
  1568. }
  1569. },
  1570. month: {
  1571. chartType : "line",
  1572. datas: {
  1573. series: ['销售额'],
  1574. data: q
  1575. },
  1576. config : {
  1577. "labels": false,
  1578. "title": "销售额统计(近12月线)",
  1579. "legend": {
  1580. "display": true,
  1581. "position": "right"
  1582. },
  1583. colors : [ '#4D9934'],
  1584. "innerRadius": 0,
  1585. "lineLegend": "lineEnd"
  1586. }
  1587. },
  1588. year: {
  1589. chartType : "line",
  1590. datas: {
  1591. series: ['销售额'],
  1592. data: r
  1593. },
  1594. config : {
  1595. "labels": false,
  1596. "title": "销售额统计(近10年线)",
  1597. "legend": {
  1598. "display": true,
  1599. "position": "right"
  1600. },
  1601. colors : [ '#4D9934'],
  1602. "innerRadius": 0,
  1603. "lineLegend": "lineEnd"
  1604. }
  1605. }
  1606. };
  1607. });
  1608. }]);
  1609. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1610. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1611. $scope.notices = data;
  1612. });
  1613. $scope.dateTime = new Date();
  1614. }]);
  1615. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1616. // SnapshotService.getTender(250, function(data){
  1617. // $scope.tenders = data;
  1618. // console.log(data);
  1619. // var newDate = new Date();
  1620. // newDate = newDate.setDate(newDate.getDate() - 3);
  1621. // angular.forEach($scope.tenders, function(tender) {
  1622. // if (tender.date > newDate) {
  1623. // tender.isNew = true;
  1624. // } else {
  1625. // tender.isNew = false;
  1626. // }
  1627. // });
  1628. // });
  1629. SnapshotService.getOpenTender(5, function(data){
  1630. $scope.openTenders = data;
  1631. var newDate = new Date();
  1632. newDate = newDate.getTime() - 3*24*60*60*1000;
  1633. angular.forEach($scope.openTenders, function(tender) {
  1634. if (tender.date - newDate > 0) {
  1635. tender.isNew = true;
  1636. } else {
  1637. tender.isNew = false;
  1638. }
  1639. });
  1640. });
  1641. $scope.dateTime = new Date();
  1642. }]);
  1643. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1644. VendorService.getCount(function(date){
  1645. $scope.count = date;
  1646. });
  1647. }]);
  1648. // 客户
  1649. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1650. BaseService.scrollBackToTop();
  1651. $scope.userInfoResult = true;
  1652. AuthenticationService.getAuthentication().success(function(data) {
  1653. $scope.loading = false;
  1654. $scope.thisUser = data;
  1655. });
  1656. var getCustInfos = function(custuu) {
  1657. if(custuu) {
  1658. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1659. $scope.custInfos = data;
  1660. var getPage = function(page, size){
  1661. if($scope.custInfos) {
  1662. var result = {};
  1663. result.totalCount = $scope.custInfos.length;
  1664. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1665. if($scope.custInfos.length % size == 0) {
  1666. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1667. }else {
  1668. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1669. }
  1670. result.first = page == 1;
  1671. result.last = page == result.totalPage;
  1672. result.page = page;
  1673. result.next = page - 0 + 1;
  1674. result.pre = page - 1;
  1675. return result;
  1676. }
  1677. }
  1678. $scope.userdata = getPage(1,4);
  1679. $scope.first = function (){
  1680. $scope.userdata = getPage($scope.userdata.pre,4);
  1681. }
  1682. $scope.last = function (){
  1683. $scope.userdata = getPage($scope.userdata.next,4);
  1684. }
  1685. }, function(response){
  1686. $scope.loading = false;
  1687. toaster.pop('error', '数据加载失败', response.data);
  1688. });
  1689. }
  1690. }
  1691. $scope.addUserInfo = function(customer) {
  1692. //TODO
  1693. if ($scope.thisUser.sys) {
  1694. var modalInstance = $modal.open({
  1695. animation: true,
  1696. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1697. controller: 'AddUserInfoCtrl',
  1698. resolve: {
  1699. customer: function() {
  1700. return customer;
  1701. }
  1702. }
  1703. });
  1704. modalInstance.result.then(function(changed, checked){
  1705. if(changed) {
  1706. if(checked)
  1707. $scope.newUser.roles = checked;
  1708. else
  1709. loadUsers();
  1710. }
  1711. });
  1712. } else {
  1713. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1714. }
  1715. }
  1716. $scope.showUserInfo = function(customer,boo) {
  1717. $scope.custInfo = customer;
  1718. if(boo) {
  1719. getCustInfos(customer.myEnterprise.uu);
  1720. $scope.userInfoResult = true;
  1721. }
  1722. }
  1723. $scope.customerParams = new ngTableParams({
  1724. page : 1,
  1725. count : 20
  1726. }, {
  1727. total : 0,
  1728. counts: [5, 10, 25, 50],
  1729. getData : function($defer, params) {
  1730. $scope.loading = true;
  1731. var pageParams = params.url();
  1732. pageParams.keyword = $scope.keyword;
  1733. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1734. $scope.loading = false;
  1735. if(page) {
  1736. params.total(page.totalElement);
  1737. $defer.resolve(page.content);
  1738. }
  1739. $scope.totalCount = page.totalElement;
  1740. }, function(response){
  1741. $scope.loading = false;
  1742. toaster.pop('error', '数据加载失败', response.data);
  1743. });
  1744. }
  1745. });
  1746. // 搜索框回车
  1747. $scope.onSearch = function(keyword) {
  1748. $scope.customerParams.page(1);
  1749. $scope.customerParams.reload();
  1750. $scope.tip = keyword;
  1751. };
  1752. // 查看详情
  1753. $scope.viewDetail = function(id) {
  1754. window.location.hash = "#/sale/customer/" + id;
  1755. }
  1756. }]);
  1757. // 客户详情
  1758. 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) {
  1759. BaseService.scrollBackToTop();
  1760. $scope.userInfoResult = true;
  1761. AuthenticationService.getAuthentication().success(function(data) {
  1762. $scope.loading = false;
  1763. $scope.thisUser = data;
  1764. });
  1765. $scope.vendorContacts = [];
  1766. var loadData = function() {
  1767. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1768. $scope.customer = data.myEnterprise;
  1769. $scope.customerInfo = data;
  1770. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1771. $scope.Contacts = data;
  1772. });
  1773. // 查看已分配人员
  1774. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1775. $scope.custInfos = data;
  1776. var getPage = function(page, size){
  1777. if($scope.custInfos) {
  1778. var result = {};
  1779. result.totalCount = $scope.custInfos.length;
  1780. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1781. if($scope.custInfos.length % size == 0) {
  1782. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1783. }else {
  1784. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1785. }
  1786. result.first = page == 1;
  1787. result.last = page == result.totalPage;
  1788. result.page = page;
  1789. result.next = page - 0 + 1;
  1790. result.pre = page - 1;
  1791. return result;
  1792. }
  1793. }
  1794. $scope.userdata = getPage(1,4);
  1795. $scope.first = function (){
  1796. $scope.userdata = getPage($scope.userdata.pre,4);
  1797. }
  1798. $scope.last = function (){
  1799. $scope.userdata = getPage($scope.userdata.next,4);
  1800. }
  1801. }, function(response){
  1802. $scope.loading = false;
  1803. toaster.pop('error', '数据加载失败', response.data);
  1804. });
  1805. });
  1806. };
  1807. loadData();
  1808. // 新增客户联系人
  1809. $scope.addContact = function(uu) {
  1810. var modalInstance = $modal.open({
  1811. animation: true,
  1812. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1813. controller: 'AddContacCtrl',
  1814. resolve: {
  1815. }
  1816. });
  1817. modalInstance.result.then(function(data) {
  1818. $scope.contact = data;
  1819. $scope.contact.myenuu = uu;
  1820. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1821. toaster.pop('success', '提示', '联系人保存成功');
  1822. $scope.Contacts.push(data);
  1823. }, function(response) {
  1824. toaster.pop('error', '失败', response.data);
  1825. });
  1826. });
  1827. }
  1828. // 编辑客户联系人
  1829. $scope.edit = function(contact) {
  1830. var modalInstance = $modal.open({
  1831. animation: true,
  1832. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1833. controller: 'EditContacCtrl',
  1834. resolve: {
  1835. contact: function() {
  1836. return contact;
  1837. }
  1838. }
  1839. });
  1840. modalInstance.result.then(function(data) {
  1841. Vendor.saveContact({}, data, function(data) {
  1842. loadData();
  1843. toaster.pop('success', '提示', '联系人修改成功');
  1844. }, function(response) {
  1845. toaster.pop('error', '失败', response.data);
  1846. });
  1847. });
  1848. }
  1849. // 删除客户联系人
  1850. $scope.deleteById = function(id, index) {
  1851. $scope.Contacts.splice(index, 1);
  1852. Vendor.deleteContact({id: id}, {}, function(data) {
  1853. toaster.pop('success', '提示', '客户联系人删除成功');
  1854. loadData();
  1855. }, function(response) {
  1856. toaster.pop('error', '提示', response.data);
  1857. });
  1858. }
  1859. // 供应商物料信息
  1860. $scope.viewProdList = function(uu){
  1861. $scope.uu = uu;
  1862. $scope.tableParams.page(1);
  1863. $scope.tableParams.reload();
  1864. };
  1865. // 搜索框回车
  1866. $scope.onSearch = function(keyword) {
  1867. $scope.keyword = keyword;
  1868. $scope.tableParams.page(1);
  1869. $scope.tableParams.reload();
  1870. };
  1871. // 供应商物料信息
  1872. $scope.tableParams = new ngTableParams({
  1873. page : 1,
  1874. count : 20
  1875. }, {
  1876. total : 0,
  1877. counts: [5, 10, 25, 50],
  1878. getData : function($defer, params) {
  1879. $scope.loading = true;
  1880. var pageParams = params.url();
  1881. pageParams.custUU = $scope.uu;
  1882. pageParams.keyword = $scope.keyword;
  1883. $scope.tip = $scope.keyword;
  1884. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1885. $scope.loading = false;
  1886. if(page) {
  1887. params.total(page.totalElement);
  1888. $scope.total = page.totalElement;
  1889. $defer.resolve(page.content);
  1890. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1891. }
  1892. }, function(response){
  1893. $scope.loading = false;
  1894. toaster.pop('error', '数据加载失败', response.data);
  1895. });
  1896. }
  1897. });
  1898. $scope.addUserInfo = function() {
  1899. //TODO
  1900. if ($scope.thisUser.sys) {
  1901. var modalInstance = $modal.open({
  1902. animation: true,
  1903. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1904. controller: 'AddUserInfoCtrl',
  1905. resolve: {
  1906. customer: function() {
  1907. return $scope.customerInfo;
  1908. }
  1909. }
  1910. });
  1911. modalInstance.result.then(function(changed, checked){
  1912. loadData();
  1913. if(changed) {
  1914. if(checked) {
  1915. $scope.newUser.roles = checked;
  1916. } else {
  1917. loadUsers();
  1918. }
  1919. }
  1920. });
  1921. } else {
  1922. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1923. }
  1924. }
  1925. $scope.Quotation = function(uu, id) {
  1926. $rootScope.custuu = uu;
  1927. $rootScope.prodId = id;
  1928. window.location.hash = "#/sale/quotation/new";
  1929. }
  1930. }]);
  1931. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1932. $scope.isChanged = false;
  1933. $scope.checkboxes = {
  1934. checked : false
  1935. };
  1936. $scope.loading = true;
  1937. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1938. $scope.userinfos = data;
  1939. $scope.loading = false;
  1940. })
  1941. // 点击勾选全部的复选框
  1942. $scope.checkAll = function() {
  1943. angular.forEach($scope.userinfos, function(item) {
  1944. item.distribute = $scope.checkboxes.checked;
  1945. });
  1946. $scope.isChanged = true;
  1947. };
  1948. // 点击其中一个明细的复选框
  1949. $scope.checkOne = function(vendor){
  1950. var result = true;
  1951. angular.forEach($scope.userinfos, function(item) {
  1952. if(item.distribute != true){
  1953. result = false;
  1954. return;
  1955. }
  1956. });
  1957. $scope.checkboxes.checked = result;
  1958. $scope.isChanged = true;
  1959. };
  1960. $scope.close = function(save) {
  1961. var chooseResult = [];
  1962. if(save) {
  1963. if(customer.myEnterprise.uu) {
  1964. angular.forEach($scope.userinfos, function(item, i) {
  1965. chooseResult.push(item);
  1966. });
  1967. if(chooseResult.length > 0) {
  1968. $scope.loading = true;
  1969. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1970. $scope.loading = false;
  1971. toaster.pop('success', '提示', '保存成功');
  1972. $modalInstance.close(false);
  1973. }, function(response){
  1974. $scope.loading = false;
  1975. toaster.pop('error', '保存失败', response.data);
  1976. $modalInstance.close(false);
  1977. })
  1978. } else {
  1979. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1980. }
  1981. } else {
  1982. $modalInstance.close(true, $scope.checkboxes.checked);
  1983. }
  1984. } else {
  1985. $modalInstance.close(false);
  1986. }
  1987. };
  1988. }]);
  1989. /**
  1990. * 页面状态按钮过滤
  1991. */
  1992. var getState = function(active) {
  1993. var fn = 'get';
  1994. switch(active) {
  1995. case 'done':
  1996. fn = 'getDone';break;
  1997. case 'todo':
  1998. fn = 'getTodo';break;
  1999. case 'end':
  2000. fn = 'getEnd';break;
  2001. case 'waiting':
  2002. fn = 'getWaiting';break;
  2003. case 'received':
  2004. fn = 'getReceived';break;
  2005. case 'invalid':
  2006. fn = 'getInvalid';break;
  2007. // 已采纳
  2008. case 'agreed':
  2009. fn = 'getAgreed';break;
  2010. // 未采纳
  2011. case 'refused':
  2012. fn = 'getRefused';break;
  2013. // 个人
  2014. case 'personal':
  2015. fn = 'getPersonal';break;
  2016. // 集体
  2017. case 'teams':
  2018. fn = 'getTeams';break;
  2019. // 非标准
  2020. case 'nonstandard':
  2021. fn = 'getNonstandard';break;
  2022. // 标准
  2023. case 'standard':
  2024. fn = 'getStandard';break;
  2025. }
  2026. return fn;
  2027. };
  2028. /**
  2029. * 改变单据日期范围
  2030. */
  2031. var getDateCondition = function(zone, condition) {
  2032. var fromDate = new Date();
  2033. var toDate = new Date();
  2034. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  2035. fromDate.setHours(0,0,0,0);
  2036. toDate.setHours(23,59,59,999);
  2037. if(zone == -1) { // 自定义时间,什么都不做
  2038. } else if(zone == 1) {
  2039. fromDate.setMonth(fromDate.getMonth() - 1);
  2040. condition.dateFrom = fromDate;
  2041. condition.dateTo = toDate;
  2042. } else if(zone == 3) {
  2043. fromDate.setMonth(fromDate.getMonth() - 3);
  2044. condition.dateFrom = fromDate;
  2045. condition.dateTo = toDate;
  2046. } else if (zone == 6) {
  2047. fromDate.setMonth(fromDate.getMonth() - 6);
  2048. condition.dateFrom = fromDate;
  2049. condition.dateTo = toDate;
  2050. } else {
  2051. condition.dateFrom = null;
  2052. condition.dateTo = null;
  2053. }
  2054. };
  2055. /**
  2056. * 改变单据交货日期范围
  2057. */
  2058. var getDelveryCondition = function(zone, condition) {
  2059. var date = new Date();
  2060. if(zone == -1) {
  2061. condition.deliveryFrom = null;
  2062. condition.deliveryTo = null;
  2063. } else if(zone == 1) {
  2064. date.setMonth(date.getMonth() + 1);
  2065. condition.deliveryTo = date;
  2066. condition.deliveryFrom = new Date();
  2067. } else if (zone == 2) {
  2068. date.setMonth(date.getMonth() + 2);
  2069. condition.deliveryTo = date;
  2070. condition.deliveryFrom = new Date();
  2071. }
  2072. };
  2073. /**
  2074. * 将日期转化为整数日期
  2075. */
  2076. var getDateTime = function(date) {
  2077. if(angular.isDate(date)) {
  2078. return date.getTime();
  2079. } else {
  2080. return null;
  2081. }
  2082. };
  2083. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope',
  2084. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope){
  2085. BaseService.scrollBackToTop();
  2086. if ($rootScope.active) {
  2087. $scope.active = $rootScope.active;
  2088. $rootScope.active = null;
  2089. } else {
  2090. $scope.active = 'all';
  2091. }
  2092. $scope.dateZoneText = '不限';
  2093. $scope.deliveryZoneText = '不限';
  2094. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2095. /* 时间筛选初始化*/
  2096. var fromDate = new Date();
  2097. var toDate = new Date();
  2098. fromDate.setMonth(fromDate.getMonth() - 1);
  2099. fromDate.setHours(0,0,0,0);
  2100. toDate.setHours(23,59,59,999);
  2101. $scope.condition.dateFrom = fromDate;
  2102. $scope.condition.dateTo = toDate;
  2103. $scope.changeDateZone = function(zone) {
  2104. $scope.condition.dateZone = zone;
  2105. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2106. $scope.condition.$dateZoneOpen = false;
  2107. getDateCondition(zone, $scope.condition);
  2108. $scope.tableParams.page(1);
  2109. $scope.tableParams.reload();
  2110. };
  2111. $scope.changeDeliveryZone = function(zone) {
  2112. $scope.condition.deliveryZoneText = zone;
  2113. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2114. $scope.condition.$delievryZoneOpen = false;
  2115. getDelveryCondition(zone, $scope.condition);
  2116. $scope.tableParams.reload();
  2117. };
  2118. // 切换单据类型
  2119. $scope.setActive = function(state) {
  2120. if($scope.active != state) {
  2121. $scope.active = state;
  2122. if($scope.tableParams.page() == 1)
  2123. $scope.tableParams.reload();
  2124. else
  2125. $scope.tableParams.page(1);
  2126. }
  2127. };
  2128. var getPurcStatus = function(active) {
  2129. var fn = 'getPurcAll';
  2130. switch(active) {
  2131. case 'done':
  2132. fn = 'getPurcDone';break;
  2133. case 'todo':
  2134. fn = 'getPurcTodo';break;
  2135. case 'end':
  2136. fn = 'getPurcEnd';break;
  2137. case 'waiting':
  2138. fn = 'getPurcWaiting';break;
  2139. }
  2140. return fn;
  2141. };
  2142. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2143. page : 1,
  2144. count : 20,
  2145. sorting: {
  2146. display: 'desc',
  2147. date: 'desc'
  2148. }
  2149. }, {
  2150. total : 0,
  2151. counts: [5, 10, 15, 25, 50],
  2152. getData : function($defer, params) {// 获取数据的方法
  2153. $scope.loading = true;
  2154. var pageParams = params.url();
  2155. pageParams.searchFilter = { // 筛选条件
  2156. keyword: $scope.keyword,
  2157. fromDate: getDateTime($scope.condition.dateFrom),
  2158. endDate: getDateTime($scope.condition.dateTo)
  2159. };
  2160. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2161. $scope.loading = false;
  2162. if(page) {
  2163. $defer.resolve(page.content);
  2164. $scope.total = page.totalElement;
  2165. params.total(page.totalElement);
  2166. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2167. }
  2168. }, function(response){
  2169. $scope.loading = false;
  2170. toaster.pop('error', '数据加载失败', response.data);
  2171. });
  2172. }
  2173. });
  2174. $scope.getReply = function(item) {
  2175. if(!item.replies) {
  2176. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2177. item.replies = replies;
  2178. });
  2179. }
  2180. };
  2181. $scope.getOrderTotal = function(items) {
  2182. var sum = 0;
  2183. angular.forEach(items, function(item){
  2184. sum += item.qty * item.price;
  2185. });
  2186. return sum;
  2187. };
  2188. // 需方 打印 采购单
  2189. $scope.custPrint = function(order) {
  2190. PurcOrder.custPrintCount({id: order.id},{});//增加打印此次
  2191. ReportService.print(order.enUU, 'PURCLIST_CUST', "where purc$orders.pu_id=" + order.id);
  2192. };
  2193. $scope.openDatePicker = function($event, item, openParam) {
  2194. $event.preventDefault();
  2195. $event.stopPropagation();
  2196. item[openParam] = !item[openParam];
  2197. };
  2198. $scope.openFilterDatePicker = function($event, item, openParam) {
  2199. $event.preventDefault();
  2200. $event.stopPropagation();
  2201. item[openParam] = !item[openParam];
  2202. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  2203. $scope.tableParams.reload();
  2204. }
  2205. };
  2206. $scope.parseDate = function(dateStr) {
  2207. if(dateStr)
  2208. return Date.parse(dateStr, 'yyyy-MM-dd');
  2209. return new Date();
  2210. };
  2211. $scope.checkboxes = {
  2212. checked : false
  2213. };
  2214. // 点击勾选全部的复选框
  2215. $scope.checkAll = function(){
  2216. angular.forEach($scope.tableParams.data, function(item) {
  2217. item.$selected = $scope.checkboxes.checked;
  2218. });
  2219. };
  2220. // 点击其中一个明细的复选框
  2221. $scope.checkOne = function(order){
  2222. var result = true;
  2223. angular.forEach($scope.tableParams.data, function(item) {
  2224. if(item.$selected != true){
  2225. result = false;
  2226. return;
  2227. }
  2228. });
  2229. $scope.checkboxes.checked = result;
  2230. };
  2231. // 搜索框回车
  2232. $scope.onSearch = function(keyword) {
  2233. $scope.tableParams.page(1);
  2234. $scope.tableParams.reload();
  2235. $scope.tip = keyword;
  2236. };
  2237. // 选择查找日期
  2238. $scope.onDateCondition = function(){
  2239. $scope.tableParams.page(1);
  2240. $scope.tableParams.reload();
  2241. };
  2242. }]);
  2243. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2244. var loadData = function() {
  2245. PurcOrder.get({id: $stateParams.id}, function(data){
  2246. $scope.order = data;
  2247. var sum = 0;
  2248. angular.forEach($scope.order.orderItems, function(item){
  2249. sum += item.qty * item.price;
  2250. });
  2251. $scope.order.total = sum;
  2252. if($scope.order.display == 1) {//未查看的设为已查看
  2253. $scope.setDisplay('setRead', $scope.order.id);
  2254. }
  2255. $scope.loading = false;
  2256. });
  2257. };
  2258. loadData();
  2259. $scope.getReply = function(item) {
  2260. if(!item.replies) {
  2261. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2262. item.replies = replies;
  2263. });
  2264. }
  2265. };
  2266. $scope.openDatePicker = function($event, item, openParam) {
  2267. $event.preventDefault();
  2268. $event.stopPropagation();
  2269. item[openParam] = !item[openParam];
  2270. };
  2271. $scope.onReplyClick = function(item, inverse) {
  2272. if(item.reply) {
  2273. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2274. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2275. return;
  2276. }
  2277. var reply = angular.copy(item.reply);
  2278. if(reply.delivery) {
  2279. if(typeof reply.delivery == 'object')
  2280. reply.delivery = reply.delivery.getTime();
  2281. } else {
  2282. reply.delivery = item.delivery;
  2283. }
  2284. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2285. $scope.loading = true;
  2286. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2287. $scope.loading = false;
  2288. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2289. loadData();
  2290. }, function(response){
  2291. $scope.loading = false;
  2292. toaster.pop('error', '回复失败', response.data);
  2293. });
  2294. }
  2295. };
  2296. // // 采购单
  2297. // $scope.print = function(order) {
  2298. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  2299. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2300. // };
  2301. //设置为已查看
  2302. $scope.setDisplay = function(state, orderId) {
  2303. if(orderId) {//设置单个
  2304. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2305. // $scope.tableParams.reload();
  2306. }, function() {
  2307. toaster.pop('error', '错误', "设置失败");
  2308. });
  2309. } else {//设置已勾选的
  2310. var str = null;
  2311. angular.forEach($scope.tableParams.data, function(order) {
  2312. if(order.$selected == true) {
  2313. if(str != null && str != '') str += ',';
  2314. str += order.id;
  2315. }
  2316. });
  2317. if(str != null && str != '') {
  2318. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2319. $scope.tableParams.reload();
  2320. }, function() {
  2321. toaster.pop('error', '错误', "设置失败");
  2322. });
  2323. }
  2324. }
  2325. };
  2326. }]);
  2327. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  2328. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  2329. BaseService.scrollBackToTop();
  2330. $scope.active = 'todo';
  2331. $scope.dateZoneText = '不限';
  2332. $scope.deliveryZoneText = '不限';
  2333. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2334. /* 时间筛选初始化*/
  2335. var fromDate = new Date();
  2336. var toDate = new Date();
  2337. fromDate.setMonth(fromDate.getMonth() - 1);
  2338. fromDate.setHours(0,0,0,0);
  2339. toDate.setHours(23,59,59,999);
  2340. $scope.condition.dateFrom = fromDate;
  2341. $scope.condition.dateTo = toDate;
  2342. $scope.changeDateZone = function(zone) {
  2343. $scope.condition.dateZone = zone;
  2344. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2345. $scope.condition.$dateZoneOpen = false;
  2346. getDateCondition(zone, $scope.condition);
  2347. $scope.tableParams.page(1);
  2348. $scope.tableParams.reload();
  2349. };
  2350. $scope.changeDeliveryZone = function(zone) {
  2351. $scope.condition.deliveryZoneText = zone;
  2352. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2353. $scope.condition.$delievryZoneOpen = false;
  2354. getDelveryCondition(zone, $scope.condition);
  2355. $scope.tableParams.reload();
  2356. };
  2357. $scope.nowdate = new Date();
  2358. // 切换单据类型
  2359. $scope.setActive = function(state) {
  2360. if($scope.active != state) {
  2361. $scope.active = state;
  2362. if($scope.tableParams.page() == 1)
  2363. $scope.tableParams.reload();
  2364. else
  2365. $scope.tableParams.page(1);
  2366. }
  2367. };
  2368. // 切换数据来源(正常数据 or 历史数据)
  2369. var getService = function() {
  2370. return PurcOrderItem;
  2371. };
  2372. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2373. page : 1,
  2374. count : 20,
  2375. sorting: {
  2376. display: 'desc',
  2377. date: 'desc',
  2378. id: 'desc'
  2379. }
  2380. }, {
  2381. total : 0,
  2382. counts: [5, 10, 15, 25, 50],
  2383. getData : function($defer, params) { // 获取数据的方法
  2384. $scope.loading = true;
  2385. var pageParams = params.url();
  2386. pageParams.searchFilter = { // 筛选条件
  2387. keyword: $scope.keyword,
  2388. fromDate: getDateTime($scope.condition.dateFrom),
  2389. endDate: getDateTime($scope.condition.dateTo)
  2390. };
  2391. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2392. $scope.loading = false;
  2393. if(page) {
  2394. $defer.resolve(page.content);
  2395. params.total(page.totalElement);
  2396. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2397. }
  2398. }, function(response){
  2399. $scope.loading = false;
  2400. toaster.pop('error', '数据加载失败', response.data);
  2401. });
  2402. }
  2403. });
  2404. $scope.getOrderTotal = function(items) {
  2405. var sum = 0;
  2406. angular.forEach(items, function(item){
  2407. sum += item.qty * item.price;
  2408. });
  2409. return sum;
  2410. };
  2411. $scope.openDatePicker = function($event, item, openParam) {
  2412. $event.preventDefault();
  2413. $event.stopPropagation();
  2414. item[openParam] = !item[openParam];
  2415. };
  2416. $scope.openFilterDatePicker = function($event, item, openParam) {
  2417. $event.preventDefault();
  2418. $event.stopPropagation();
  2419. item[openParam] = !item[openParam];
  2420. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  2421. $scope.tableParams.reload();
  2422. }
  2423. };
  2424. $scope.parseDate = function(dateStr) {
  2425. if(dateStr)
  2426. return Date.parse(dateStr, 'yyyy-MM-dd');
  2427. return new Date();
  2428. };
  2429. $scope.onReplyClick = function(item, inverse) {
  2430. if(item.reply) {
  2431. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2432. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2433. return;
  2434. }
  2435. var reply = angular.copy(item.reply);
  2436. if(reply.delivery) {
  2437. if(typeof reply.delivery == 'object')
  2438. reply.delivery = reply.delivery.getTime();
  2439. } else {
  2440. reply.delivery = item.delivery;
  2441. }
  2442. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2443. $scope.loading = true;
  2444. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2445. $scope.loading = false;
  2446. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2447. $scope.tableParams.reload();
  2448. }, function(response){
  2449. $scope.loading = false;
  2450. toaster.pop('error', '回复失败', response.data);
  2451. });
  2452. }
  2453. };
  2454. //打印 采购单
  2455. $scope.print = function(order) {
  2456. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2457. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2458. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2459. $scope.tableParams.reload();
  2460. };
  2461. $scope.getReply = function(item) {
  2462. if(!item.replies) {
  2463. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2464. item.replies = replies;
  2465. });
  2466. }
  2467. };
  2468. $scope.checkboxes = {
  2469. checked : false
  2470. };
  2471. // 点击勾选全部的复选框
  2472. $scope.checkAll = function(){
  2473. angular.forEach($scope.tableParams.data, function(item) {
  2474. item.$selected = $scope.checkboxes.checked;
  2475. });
  2476. };
  2477. // 点击其中一个明细的复选框
  2478. $scope.checkOne = function(order){
  2479. var result = true;
  2480. angular.forEach($scope.tableParams.data, function(item) {
  2481. if(item.$selected != true){
  2482. result = false;
  2483. return;
  2484. }
  2485. });
  2486. $scope.checkboxes.checked = result;
  2487. };
  2488. //批量回复采购订单
  2489. $scope.replyByBatch = function() {
  2490. $scope.loading = true;
  2491. var str = '';
  2492. angular.forEach($scope.tableParams.data, function(order) {
  2493. if(order.$selected == true) {
  2494. angular.forEach(order.orderItems, function(item){
  2495. str += item.id;
  2496. str += ',';
  2497. });
  2498. }
  2499. });
  2500. if(!(str == '')) {
  2501. str = str.substr(0, str.length-1);
  2502. PurcOrderItem.replyByBatch(str, function(){
  2503. $scope.loading = false;
  2504. $scope.tableParams.reload();
  2505. toaster.pop('success', '提示', '批量回复成功');
  2506. }, function(data){
  2507. $scope.loading = false;
  2508. toaster.pop('error', '批量回复失败', data);
  2509. });
  2510. } else {//没有勾选其中的明细
  2511. $scope.loading = false;
  2512. }
  2513. };
  2514. // 搜索框回车
  2515. $scope.onSearch = function() {
  2516. $scope.tableParams.page(1);
  2517. $scope.tableParams.reload();
  2518. };
  2519. // 选择查找日期
  2520. $scope.onDateCondition = function(){
  2521. $scope.tableParams.page(1);
  2522. $scope.tableParams.reload();
  2523. };
  2524. //设置为已查看
  2525. $scope.setDisplay = function(state, orderId) {
  2526. if(orderId) {//设置单个
  2527. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2528. $scope.tableParams.reload();
  2529. }, function() {
  2530. toaster.pop('error', '错误', "设置失败");
  2531. });
  2532. } else {//设置已勾选的
  2533. var str = null;
  2534. angular.forEach($scope.tableParams.data, function(order) {
  2535. if(order.$selected == true) {
  2536. if(str != null && str != '') str += ',';
  2537. str += order.id;
  2538. }
  2539. });
  2540. if(str != null && str != '') {
  2541. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2542. $scope.tableParams.reload();
  2543. }, function() {
  2544. toaster.pop('error', '错误', "设置失败");
  2545. });
  2546. }
  2547. }
  2548. };
  2549. }]);
  2550. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2551. var loadData = function() {
  2552. PurcOrder.get({id: $stateParams.id}, function(data){
  2553. $scope.order = data;
  2554. var sum = 0;
  2555. angular.forEach($scope.order.orderItems, function(item){
  2556. sum += item.qty * item.price;
  2557. });
  2558. $scope.order.total = sum;
  2559. if($scope.order.display == 1) {//未查看的设为已查看
  2560. $scope.setDisplay('setRead', $scope.order.id);
  2561. }
  2562. $scope.loading = false;
  2563. });
  2564. };
  2565. loadData();
  2566. $scope.getReply = function(item) {
  2567. if(!item.replies) {
  2568. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2569. item.replies = replies;
  2570. });
  2571. }
  2572. };
  2573. $scope.openDatePicker = function($event, item, openParam) {
  2574. $event.preventDefault();
  2575. $event.stopPropagation();
  2576. item[openParam] = !item[openParam];
  2577. };
  2578. $scope.onReplyClick = function(item, inverse) {
  2579. if(item.reply) {
  2580. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2581. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2582. return;
  2583. }
  2584. var reply = angular.copy(item.reply);
  2585. if(reply.delivery) {
  2586. if(typeof reply.delivery == 'object')
  2587. reply.delivery = reply.delivery.getTime();
  2588. } else {
  2589. reply.delivery = item.delivery;
  2590. }
  2591. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2592. $scope.loading = true;
  2593. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2594. $scope.loading = false;
  2595. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2596. loadData();
  2597. }, function(response){
  2598. $scope.loading = false;
  2599. toaster.pop('error', '回复失败', response.data);
  2600. });
  2601. }
  2602. };
  2603. // 采购单
  2604. $scope.print = function(order) {
  2605. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2606. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2607. };
  2608. //设置为已查看
  2609. $scope.setDisplay = function(state, orderId) {
  2610. if(orderId) {//设置单个
  2611. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2612. $scope.tableParams.reload();
  2613. }, function() {
  2614. toaster.pop('error', '错误', "设置失败");
  2615. });
  2616. } else {//设置已勾选的
  2617. var str = null;
  2618. angular.forEach($scope.tableParams.data, function(order) {
  2619. if(order.$selected == true) {
  2620. if(str != null && str != '') str += ',';
  2621. str += order.id;
  2622. }
  2623. });
  2624. if(str != null && str != '') {
  2625. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2626. $scope.tableParams.reload();
  2627. }, function() {
  2628. toaster.pop('error', '错误', "设置失败");
  2629. });
  2630. }
  2631. }
  2632. };
  2633. }]);
  2634. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, PurcChangeHis){
  2635. BaseService.scrollBackToTop();
  2636. $scope.active = 'todo';
  2637. $scope.agreedText = '全部';
  2638. $scope.dateZoneText = '一个月内';
  2639. $scope.condition = {dateZone: 1};
  2640. /* 时间筛选初始化*/
  2641. var fromDate = new Date();
  2642. var toDate = new Date();
  2643. fromDate.setMonth(fromDate.getMonth() - 1);
  2644. fromDate.setHours(0,0,0,0);
  2645. toDate.setHours(23,59,59,999);
  2646. $scope.condition.dateFrom = fromDate;
  2647. $scope.condition.dateTo = toDate;
  2648. $scope.changeAgreed = function(agreed) {
  2649. $scope.condition.agreed = agreed;
  2650. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2651. $scope.condition.$agreedOpen = false;
  2652. };
  2653. $scope.changeDateZone = function(zone) {
  2654. $scope.condition.dateZone = zone;
  2655. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2656. $scope.condition.$dateZoneOpen = false;
  2657. getDateCondition(zone, $scope.condition);
  2658. $scope.tableParams.page(1);
  2659. $scope.tableParams.reload();
  2660. };
  2661. $scope.setActive = function(state) {
  2662. if($scope.active != state) {
  2663. $scope.active = state;
  2664. if($scope.tableParams.page() == 1)
  2665. $scope.tableParams.reload();
  2666. else
  2667. $scope.tableParams.page(1);
  2668. }
  2669. };
  2670. $scope.searchMethod = false;
  2671. var getService = function() {
  2672. if($scope.searchMethod) {
  2673. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2674. } else {
  2675. return PurcChanges;
  2676. }
  2677. };
  2678. $scope.tableParams = new ngTableParams({
  2679. page : 1,
  2680. count : 20,
  2681. sorting: {
  2682. date: 'desc'
  2683. }
  2684. }, {
  2685. total : 0,
  2686. counts: [5, 10, 25, 50],
  2687. getData : function($defer, params) {
  2688. $scope.loading = true;
  2689. var pageParams = params.url();
  2690. pageParams.searchFilter = {
  2691. keyword: $scope.keyword,
  2692. fromDate: getDateTime($scope.condition.dateFrom),
  2693. endDate: getDateTime($scope.condition.dateTo)
  2694. };
  2695. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2696. $scope.loading = false;
  2697. if(page) {
  2698. params.total(page.totalElement);
  2699. $defer.resolve(page.content);
  2700. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  2701. }
  2702. }, function(response){
  2703. $scope.loading = false;
  2704. toaster.pop('error', '数据加载失败', response.data);
  2705. });
  2706. }
  2707. });
  2708. $scope.openDatePicker = function($event, item, openParam) {
  2709. $event.preventDefault();
  2710. $event.stopPropagation();
  2711. item[openParam] = !item[openParam];
  2712. };
  2713. $scope.openFilterDatePicker = function($event, item, openParam) {
  2714. $event.preventDefault();
  2715. $event.stopPropagation();
  2716. item[openParam] = !item[openParam];
  2717. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  2718. $scope.tableParams.reload();
  2719. }
  2720. };
  2721. $scope.onReplyClick = function(change) {
  2722. if(change.$agreed) {
  2723. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2724. $scope.loading = true;
  2725. PurcChange.reply({changeId: change.id}, reply, function(){
  2726. $scope.loading = false;
  2727. toaster.pop('info', '提示', '回复成功');
  2728. $scope.tableParams.reload();
  2729. }, function(response){
  2730. $scope.loading = false;
  2731. toaster.pop('error', '回复失败', response.data);
  2732. });
  2733. }
  2734. };
  2735. // 搜索框回车
  2736. $scope.onSearch = function() {
  2737. $scope.searchMethod = true;
  2738. $scope.tableParams.page(1);
  2739. $scope.tableParams.reload();
  2740. };
  2741. }]);
  2742. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2743. var loadData = function() {
  2744. PurcChange.get({id: $stateParams.id}, function(data){
  2745. $scope.change = data;
  2746. });
  2747. };
  2748. loadData();
  2749. $scope.openDatePicker = function($event, item, openParam) {
  2750. $event.preventDefault();
  2751. $event.stopPropagation();
  2752. item[openParam] = !item[openParam];
  2753. };
  2754. $scope.onReplyClick = function(change) {
  2755. if(change.$agreed) {
  2756. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2757. PurcChange.reply({changeId: change.id}, reply, function(){
  2758. toaster.pop('info', '提示', '回复成功');
  2759. loadData();
  2760. }, function(response){
  2761. toaster.pop('error', '回复失败', response.data);
  2762. });
  2763. }
  2764. };
  2765. }]);
  2766. //采购询价
  2767. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', '$upload', '$rootScope', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis, $upload, $rootScope){
  2768. BaseService.scrollBackToTop();
  2769. if($rootScope.active) {
  2770. $scope.active = $rootScope.active;
  2771. $rootScope.active = null;
  2772. } else {
  2773. $scope.active = 'todo';
  2774. }
  2775. $scope.agreedText = '全部';
  2776. $scope.dateZoneText = '最近一个月';
  2777. $scope.condition = {dateZone: 1};
  2778. /* 时间筛选初始化*/
  2779. var fromDate = new Date();
  2780. var toDate = new Date();
  2781. fromDate.setMonth(fromDate.getMonth() - 1);
  2782. fromDate.setHours(0,0,0,0);
  2783. toDate.setHours(23,59,59,999);
  2784. $scope.condition.dateFrom = fromDate;
  2785. $scope.condition.dateTo = toDate;
  2786. $scope.changeAgreed = function(agreed) {
  2787. $scope.condition.agreed = agreed;
  2788. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2789. $scope.condition.$agreedOpen = false;
  2790. };
  2791. $scope.changeDateZone = function(zone) {
  2792. $scope.condition.dateZone = zone;
  2793. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  2794. $scope.condition.$dateZoneOpen = false;
  2795. getDateCondition(zone, $scope.condition);
  2796. $scope.tableParams.page(1);
  2797. $scope.tableParams.reload();
  2798. };
  2799. $scope.setActive = function(state) {
  2800. if($scope.active != state) {
  2801. $scope.active = state;
  2802. if($scope.tableParams.page() == 1)
  2803. $scope.tableParams.reload();
  2804. else
  2805. $scope.tableParams.page(1);
  2806. }
  2807. };
  2808. // 得到消息
  2809. PurcInquiry.getMessage({}, function(data){
  2810. $scope.message = data;
  2811. }, function(response) {
  2812. });
  2813. var getService = function() {
  2814. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2815. };
  2816. $scope.tableParams = new ngTableParams({
  2817. page : 1,
  2818. count : 20,
  2819. sorting: {
  2820. 'inquiry.date': 'desc',
  2821. 'inquiry.enterprise.enName': 'asc',
  2822. 'inquiry.code': 'asc'
  2823. }
  2824. }, {
  2825. total : 0,
  2826. counts: [5, 10, 25, 50],
  2827. getData : function($defer, params) {
  2828. $scope.loading = true;
  2829. var pageParams = params.url();
  2830. var realActive = {};
  2831. pageParams.searchFilter = { // 筛选条件
  2832. keyword: $scope.keyword,
  2833. fromDate: getDateTime($scope.condition.dateFrom),
  2834. endDate: getDateTime($scope.condition.dateTo)
  2835. };
  2836. if ($scope.active == 'overdue') {
  2837. $scope.active = 'end';
  2838. }
  2839. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2840. $scope.loading = false;
  2841. if(page) {
  2842. params.total(page.totalElement);
  2843. $defer.resolve(page.content);
  2844. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  2845. }
  2846. }, function(response){
  2847. $scope.loading = false;
  2848. toaster.pop('error', '数据加载失败', response.data);
  2849. });
  2850. }
  2851. });
  2852. $scope.getMinDate = function(item) {
  2853. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2854. };
  2855. $scope.replyPrices = [];
  2856. $scope.replylapQtys = [];
  2857. $scope.replyPrices.push(true);
  2858. $scope.replylapQtys.push(true);
  2859. $scope.addStep = function(inquiryItem) {
  2860. $scope.replyPrices.push(true);
  2861. if(inquiryItem.replies.length >= 10) {
  2862. toaster.pop('warning', '提示', '最多支持10个分段!');
  2863. } else {
  2864. inquiryItem.replies.push({});
  2865. if(inquiryItem.replies.length != 1) {
  2866. $scope.replyPrices.push(true);
  2867. $scope.replylapQtys.push(true);
  2868. }
  2869. }
  2870. };
  2871. $scope.removeStep = function(inquiryItem, stepIndex) {
  2872. inquiryItem.replies.splice(stepIndex, 1);
  2873. $scope.replyPrices.splice(stepIndex, 1);
  2874. $scope.replylapQtys.splice(stepIndex, 1);
  2875. };
  2876. $scope.openDatePicker = function($event, item, openParam) {
  2877. $event.preventDefault();
  2878. $event.stopPropagation();
  2879. item[openParam] = !item[openParam];
  2880. };
  2881. $scope.openFilterDatePicker = function($event, item, openParam) {
  2882. $event.preventDefault();
  2883. $event.stopPropagation();
  2884. item[openParam] = !item[openParam];
  2885. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  2886. $scope.tableParams.reload();
  2887. }
  2888. };
  2889. $scope.getHistory = function(item) {
  2890. if(!item.history) {
  2891. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2892. item.history = data;
  2893. });
  2894. }
  2895. };
  2896. $scope.isValid = function(item, withSteps) {
  2897. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2898. if(!withSteps || !bool)
  2899. return bool;
  2900. angular.forEach(item.replies, function(r, i){
  2901. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2902. });
  2903. return bool;
  2904. };
  2905. $scope.onReplyClick = function(item, withSteps) {
  2906. if(item.vendFromDate instanceof Date) {
  2907. item.vendFromDate = item.vendFromDate.getTime();
  2908. }
  2909. if(item.vendToDate instanceof Date) {
  2910. item.vendToDate = item.vendToDate.getTime();
  2911. }
  2912. if(item.vendFromDate > item.vendToDate) {
  2913. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2914. return;
  2915. }
  2916. var replies = [];
  2917. angular.forEach(item.replies, function(r, i){
  2918. if((i > 0 ? r.lapQty : 1) || r.price)
  2919. replies.push(r);
  2920. });
  2921. item.replies = replies;
  2922. $scope.loading = true;
  2923. if(withSteps) {
  2924. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  2925. $upload.upload({
  2926. url: 'sale/inquiry/addAttach',
  2927. file: file,
  2928. method: 'POST',
  2929. data: {
  2930. itemId:item.id
  2931. }
  2932. }).success(function (attach) {
  2933. console.log(attach);
  2934. });
  2935. PurcInquiry.reply({itemId: item.id}, item, function(){
  2936. $scope.loading = false;
  2937. toaster.pop('info', '提示', '报价成功');
  2938. $scope.tableParams.reload();
  2939. }, function(response){
  2940. $scope.loading = false;
  2941. toaster.pop('error', '询价失效', response.data);
  2942. });
  2943. } else {
  2944. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2945. $scope.loading = false;
  2946. toaster.pop('info', '提示', '保存成功');
  2947. $scope.tableParams.reload();
  2948. }, function(response){
  2949. $scope.loading = false;
  2950. toaster.pop('error', '保存失败', response.data);
  2951. });
  2952. }
  2953. };
  2954. $scope.verifylapQty = function(value,type) {
  2955. var regex = /^\d+(.\d{1,5})?$/;
  2956. $scope.replylapQtys[type] = regex.test(value);
  2957. }
  2958. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2959. $scope.verify = function(value,type) {
  2960. var regex = /^\d+(.\d{1,5})?$/;//
  2961. switch(type) {
  2962. case 'minOrderQty':
  2963. $scope.minOrderQtyVerify = regex.test(value);
  2964. break;
  2965. case 'minPackQty':
  2966. $scope.minPackQtyVerify = regex.test(value);
  2967. break;
  2968. case 'leadtime':
  2969. $scope.leadtimeVerify = regex.test(value);
  2970. break;
  2971. default:
  2972. $scope.replyPrices[type] = regex.test(value);
  2973. break;
  2974. }
  2975. }
  2976. // 搜索框回车
  2977. $scope.onSearch = function() {
  2978. $scope.tableParams.page(1);
  2979. $scope.tableParams.reload();
  2980. };
  2981. // 取消
  2982. $scope.cancel = function() {
  2983. $scope.tableParams.reload();
  2984. }
  2985. }]);
  2986. // 询价单明细
  2987. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', '$upload', function($scope, $stateParams, PurcInquiry,$filter, toaster, $upload){
  2988. var loadData = function() {
  2989. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2990. $scope.newinquiryItems = data;
  2991. var inquiry = data[0].inquiry;
  2992. //inquiry.inquiryItems = data;
  2993. angular.forEach(inquiry.attachs, function(attach){
  2994. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2995. });
  2996. $scope.inquiry = inquiry;
  2997. });
  2998. };
  2999. loadData();
  3000. $scope.getMinDate = function(item) {
  3001. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3002. };
  3003. $scope.addStep = function(inquiryItem) {
  3004. if(inquiryItem.replies.length >= 10) {
  3005. toaster.pop('warning', '提示', '最多支持10个分段!');
  3006. } else
  3007. inquiryItem.replies.push({});
  3008. };
  3009. $scope.removeStep = function(inquiryItem, stepIndex) {
  3010. inquiryItem.replies.splice(stepIndex, 1);
  3011. };
  3012. $scope.openDatePicker = function($event, item, openParam) {
  3013. $event.preventDefault();
  3014. $event.stopPropagation();
  3015. item[openParam] = !item[openParam];
  3016. };
  3017. $scope.getHistory = function(item) {
  3018. if(!item.history) {
  3019. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3020. item.history = data;
  3021. });
  3022. }
  3023. };
  3024. $scope.isValid = function(item, withSteps) {
  3025. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3026. if(!withSteps || !bool)
  3027. return bool;
  3028. angular.forEach(item.replies, function(r, i){
  3029. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3030. });
  3031. return bool;
  3032. };
  3033. $scope.onReplyClick = function(item, withSteps) {
  3034. if(item.vendFromDate instanceof Date) {
  3035. item.vendFromDate = item.vendFromDate.getTime();
  3036. }
  3037. if(item.vendToDate instanceof Date) {
  3038. item.vendToDate = item.vendToDate.getTime();
  3039. }
  3040. if(item.vendFromDate > item.vendToDate) {
  3041. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3042. return;
  3043. }
  3044. var replies = [];
  3045. angular.forEach(item.replies, function(r, i){
  3046. if((i > 0 ? r.lapQty : 1) || r.price)
  3047. replies.push(r);
  3048. });
  3049. item.replies = replies;
  3050. if(withSteps) {
  3051. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3052. $upload.upload({
  3053. url: 'sale/inquiry/addAttach',
  3054. file: file,
  3055. method: 'POST',
  3056. data: {
  3057. itemId:item.id
  3058. }
  3059. }).success(function (attach) {
  3060. console.log(attach);
  3061. });
  3062. PurcInquiry.reply({itemId: item.id}, item, function(){
  3063. toaster.pop('info', '提示', '报价成功');
  3064. loadData();
  3065. }, function(response){
  3066. toaster.pop('error', '报价失败', response.data);
  3067. });
  3068. } else {
  3069. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  3070. $scope.loading = false;
  3071. toaster.pop('info', '提示', '保存成功');
  3072. loadData();
  3073. }, function(response){
  3074. $scope.loading = false;
  3075. toaster.pop('error', '保存失败', response.data);
  3076. });
  3077. }
  3078. };
  3079. // 取消
  3080. $scope.cancel = function() {
  3081. $scope.tableParams.reload();
  3082. }
  3083. }]);
  3084. // 平台新增的询价单
  3085. 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) {
  3086. $scope.status = 'InquiryNew';
  3087. $scope.active = 'all';
  3088. $rootScope.tenderVendor = null;// 清除掉已选择的
  3089. var getService = function() {
  3090. return GetProductInfo;
  3091. };
  3092. $scope.inquiry = {
  3093. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  3094. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  3095. priceType: '采购',
  3096. isOpen: 1,
  3097. invoice: 0,
  3098. ifTax: 1,
  3099. currency: 'RMB',
  3100. inquirytype: '询价'
  3101. };
  3102. $scope.changeCurrency = function(inquiry) {
  3103. if (inquiry.currency !== 'RMB') {
  3104. $scope.notRMB = true;
  3105. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  3106. inquiry.invoice = 0;
  3107. } else {
  3108. $scope.notRMB = false;
  3109. }
  3110. };
  3111. // 获取收货地址列表
  3112. var loadShipAddress = function() {
  3113. ShipAddress.shipAddList({}, function(data) {
  3114. $scope.ships = data;
  3115. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  3116. });
  3117. };
  3118. loadShipAddress();
  3119. // 获取地址信息
  3120. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  3121. }).then(function(response) {
  3122. $scope.provinces = response.data;
  3123. });
  3124. // 新增收货地址保存
  3125. $scope.saveShipAddress = function(ship) {
  3126. ship.address = ship.province + ship.city + ship.district;
  3127. ShipAddress.saveAddress( {}, ship, function(data) {
  3128. if(data.success) {
  3129. // 获取收货地址列表
  3130. loadShipAddress();
  3131. toaster.pop('success', '提示', data.success);
  3132. }
  3133. if(data.error) {
  3134. toaster.pop('error', '提示', data.error);
  3135. }
  3136. });
  3137. };
  3138. $scope.currentDay = function() {
  3139. return $filter('date')(new Date(), 'yyyy-MM-dd');
  3140. };
  3141. $scope.vendors = [];
  3142. // 查找供应商
  3143. $scope.dbfindVendor = function(){
  3144. var modalInstance = $modal.open({
  3145. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  3146. controller: 'DbfindVendorCtrl',
  3147. size: 'lg',
  3148. resolve: {
  3149. }
  3150. });
  3151. modalInstance.result.then(function(data){
  3152. var ifPush = true;
  3153. modalInstance.result.then(function(data){
  3154. angular.forEach(data, function(vendor) {
  3155. if (!$scope.vendors) {// 不存在就先创建
  3156. $scope.vendors = [{}];
  3157. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  3158. } else {
  3159. for (var i = 0;i<$scope.vendors.length; i++) {
  3160. ifPush = true;
  3161. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  3162. ifPush = false;
  3163. break; // 判定到已存在供应商,就终止循环。
  3164. }
  3165. }
  3166. if (ifPush) {
  3167. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  3168. }
  3169. }
  3170. });
  3171. $rootScope.tenderVendor = $scope.vendors;
  3172. }, function(){
  3173. });
  3174. }, function(){
  3175. });
  3176. };
  3177. // 删除一个供应商
  3178. $scope.removeVendor = function(index) {
  3179. $scope.vendors.splice(index, 1);
  3180. };
  3181. $scope.removeChecked = function() {
  3182. console.log($scope.vendors);
  3183. if ( $scope.vendors.length > 0) {
  3184. $scope.vendors = [];
  3185. $rootScope.tenderVendor = '';
  3186. }
  3187. }
  3188. // 物料信息
  3189. $scope.tableParams = new ngTableParams({
  3190. page : 1,
  3191. count : 20,
  3192. sorting: {
  3193. }
  3194. }, {
  3195. total : 0,
  3196. counts: [5, 10, 25, 50],
  3197. getData : function($defer, params) {
  3198. $scope.loading = true;
  3199. var pageParams = params.url();
  3200. pageParams.keyword = $scope.keyword;
  3201. $scope.tip = $scope.keyword;
  3202. pageParams.searchFilter = $scope.searchFilter;
  3203. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3204. $scope.loading = false;
  3205. if(page) {
  3206. params.total(page.totalElement);
  3207. $scope.total = page.totalElement;
  3208. $defer.resolve(page.content);
  3209. }
  3210. }, function(response) {
  3211. $scope.loading = false;
  3212. toaster.pop('error', '数据加载失败', response.data);
  3213. });
  3214. }
  3215. });
  3216. // 搜索框回车
  3217. $scope.onSearch = function(keyword) {
  3218. $scope.tableParams.page(1);
  3219. $scope.tableParams.reload();
  3220. };
  3221. $scope.inquiry.inquiryItems = [];
  3222. var prod = {
  3223. prodCode: null,
  3224. prodTitle: null,
  3225. inbrand: null,
  3226. toDate: null,
  3227. unit: 'PCS',
  3228. needquantity: null
  3229. };
  3230. $scope.inquiry.inquiryItems.push(prod);
  3231. // 联想词start
  3232. // 获取品牌联想词
  3233. $scope.getSimilarBrands = function(value) {
  3234. if (value) {
  3235. // 获取品牌联想词
  3236. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  3237. return data.map(function(item) {
  3238. return item;
  3239. });
  3240. });
  3241. }
  3242. };
  3243. // 获取产品型号联想词
  3244. $scope.getSimilarCodes = function(value) {
  3245. if (value) {
  3246. // 获取产品型号联想词
  3247. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  3248. return data.map(function (item) {
  3249. return item;
  3250. })
  3251. });
  3252. }
  3253. };
  3254. $scope.selectKind = function(prod) {
  3255. var submit = [];
  3256. $modal.open({
  3257. animation: true,
  3258. size: 'lg',
  3259. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  3260. controller: 'ProdKindChooseCtrl',
  3261. resolve: {
  3262. actives: function() {
  3263. return $scope.actives;
  3264. }
  3265. }
  3266. }).result.then(function(data){
  3267. $scope.actives = data.actives;
  3268. var size = data.actives.length;
  3269. submit.gradeOneKiName = '';
  3270. submit.gradeTwoKiName = '';
  3271. submit.gradeThreeKiName = '';
  3272. if (size > 0) {
  3273. submit.gradeOneKiName = $scope.actives[0].nameCn;
  3274. prod.prodTitle = submit.gradeOneKiName;
  3275. if (size > 1) {
  3276. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  3277. prod.prodTitle = submit.gradeTwoKiName;
  3278. if (size > 2) {
  3279. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  3280. prod.prodTitle = submit.gradeThreeKiName;
  3281. }
  3282. }
  3283. }
  3284. }, function(){
  3285. });
  3286. };
  3287. // 点击联想词获取品牌信息
  3288. $scope.onAssociateBrandClick = function(brand, prod) {
  3289. if (brand instanceof String) {
  3290. prod.inbrand = brand;
  3291. } else if (brand instanceof Object) {
  3292. prod.inbrand = brand.brandCn;
  3293. }
  3294. };
  3295. // 打开品牌选择的模态框
  3296. $scope.selectBrand = function(prod){ //打开模态
  3297. var modalInstance = $modal.open({
  3298. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  3299. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  3300. });
  3301. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  3302. });
  3303. modalInstance.result.then(function(brand){
  3304. prod.inbrand = brand.nameCn;
  3305. }, function(reason){
  3306. });
  3307. };
  3308. // 点击联想词获取器件信息 带入产品分类和品牌
  3309. $scope.onAssociateCmpClick = function(cmp, prod) {
  3310. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  3311. $scope.component = data;
  3312. prod.prodCode = data.code;
  3313. prod.prodTitle = data.kind.nameCn;
  3314. prod.inbrand = data.brand.nameCn;
  3315. }, function(res) {
  3316. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  3317. })
  3318. };
  3319. //联想词end
  3320. // 导入商品信息
  3321. $scope.uplodaByBatch = function() {
  3322. var modalInstance = $modal.open({
  3323. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  3324. controller: 'PurcInquiryUploadCtrl',
  3325. size: 'lg',
  3326. resolve: {
  3327. }
  3328. });
  3329. modalInstance.result.then(function(data) {
  3330. angular.forEach(data, function(prod) {
  3331. console.log(prod);
  3332. $scope.inquiry.inquiryItems.push(prod);
  3333. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3334. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  3335. $scope.inquiry.inquiryItems.splice(i, 1);
  3336. }
  3337. }
  3338. })
  3339. }, function(){
  3340. });
  3341. }
  3342. //增加商品
  3343. $scope.add = function() {
  3344. $scope.inquiry.inquiryItems.push(
  3345. { prodCode: null,
  3346. prodTitle: null,
  3347. unit: 'PCS',
  3348. ibrand: null,
  3349. toDate: null,
  3350. needquantity: null});
  3351. };
  3352. //删除商品
  3353. $scope.del = function(index) {
  3354. $scope.inquiry.inquiryItems.splice(index, 1);
  3355. };
  3356. $scope.check = function(product) {
  3357. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3358. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  3359. $scope.inquiry.inquiryItems.splice(i, 1);
  3360. }
  3361. }
  3362. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  3363. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand});
  3364. }
  3365. $scope.getMinDate = function(item) {
  3366. return $filter('date')(new Date, 'yyyy-MM-dd');
  3367. };
  3368. $scope.openDatePicker = function($event, openParam, index) {
  3369. $event.preventDefault();
  3370. $event.stopPropagation();
  3371. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  3372. };
  3373. $scope.openEndDatePicker = function($event, item, openParam) {
  3374. $event.preventDefault();
  3375. $event.stopPropagation();
  3376. item[openParam] = !item[openParam];
  3377. };
  3378. $scope.ifrepeat = false;
  3379. // 保存
  3380. $scope.save = function() {
  3381. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3382. $scope.item = $scope.inquiry.inquiryItems[i];
  3383. for(var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  3384. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  3385. if(i != j) {
  3386. if($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  3387. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  3388. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  3389. $scope.ifrepeat = true;
  3390. }
  3391. }
  3392. }
  3393. }
  3394. if(!$scope.ifrepeat) {
  3395. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3396. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3397. if( $scope.vendors.length > 0) {
  3398. $upload.upload({
  3399. url: 'purc/inquiry/save',
  3400. file: file,
  3401. method: 'POST',
  3402. data: {
  3403. inquiry: $scope.inquiry,
  3404. contacts: $scope.vendors
  3405. },
  3406. }).success(function(data) {
  3407. if(data.success) {
  3408. toaster.pop('success', '提示', data.success);
  3409. $timeout(function() {
  3410. $rootScope.active = 'todo';
  3411. window.location.hash = "#/purc/inquiry_unapply";
  3412. }, 500);
  3413. }
  3414. if(data.error) {
  3415. toaster.pop('error', '提示', data.error);
  3416. }
  3417. }).error(function(data) {
  3418. $scope.loadingShow = false;
  3419. toaster.pop('error', '操作失败', data.error);
  3420. });
  3421. } else {
  3422. toaster.pop('info', '提示', '请先选择供应商');
  3423. }
  3424. } else {
  3425. $upload.upload({
  3426. url: 'purc/inquiry/saveWithoutVendor',
  3427. file: file,
  3428. method: 'POST',
  3429. data: {
  3430. inquiry: $scope.inquiry,
  3431. },
  3432. }).success(function(data) {
  3433. if(data.success) {
  3434. toaster.pop('success', '提示', data.success);
  3435. $timeout(function() {
  3436. $rootScope.active = 'done';
  3437. window.location.hash = "#/purc/inquiry_unapply";
  3438. }, 500);
  3439. }
  3440. if(data.error) {
  3441. toaster.pop('error', '提示', data.error);
  3442. }
  3443. }).error(function(data) {
  3444. $scope.loadingShow = false;
  3445. toaster.pop('error', '操作失败', data.error);
  3446. });
  3447. }
  3448. } else {
  3449. toaster.pop('error', '提示', '存在相同条件的物料信息');
  3450. }
  3451. }
  3452. // 保存并提交
  3453. $scope.submit = function() {
  3454. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  3455. $scope.item = $scope.inquiry.inquiryItems[i];
  3456. for(var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  3457. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  3458. if(i != j) {
  3459. if($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  3460. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  3461. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  3462. $scope.ifrepeat = true;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  3468. if(!$scope.ifrepeat) {
  3469. if( $scope.inquiry.isOpen == 0) { // 指定询价
  3470. if($scope.vendors.length > 0) {
  3471. $upload.upload({
  3472. url: 'purc/inquiry/saveAndSubmit',
  3473. file: file,
  3474. method: 'POST',
  3475. data: {
  3476. inquiry: $scope.inquiry,
  3477. contacts: $scope.vendors
  3478. },
  3479. }).success(function(data) {
  3480. if(data.success) {
  3481. toaster.pop('success', '提示', data.success);
  3482. $timeout(function() {
  3483. window.location.hash = "#/purc/purchaseinquiry";
  3484. }, 500);
  3485. }
  3486. if(data.error) {
  3487. toaster.pop('error', '提示', data.error);
  3488. }
  3489. }).error(function(data) {
  3490. $scope.loadingShow = false;
  3491. toaster.pop('error', '操作失败', data.error);
  3492. });
  3493. } else {
  3494. toaster.pop('info', '提示', '请先选择供应商');
  3495. }
  3496. } else {
  3497. $upload.upload({
  3498. url: 'purc/inquiry/saveAndSubmitWithoutVendor',
  3499. file: file,
  3500. method: 'POST',
  3501. data: {
  3502. inquiry: $scope.inquiry,
  3503. },
  3504. }).success(function(data) {
  3505. if(data.success) {
  3506. toaster.pop('success', '提示', data.success);
  3507. $timeout(function() {
  3508. window.location.hash = "#/purc/purchaseinquiry";
  3509. }, 500);
  3510. }
  3511. if(data.error) {
  3512. toaster.pop('error', '提示', data.error);
  3513. }
  3514. }).error(function(data) {
  3515. $scope.loadingShow = false;
  3516. toaster.pop('error', '操作失败', data.error);
  3517. });
  3518. }
  3519. } else {
  3520. toaster.pop('error', '提示', '存在相同条件的物料信息');
  3521. }
  3522. }
  3523. $scope.previewShow = false;
  3524. $scope.pdfShow = false;
  3525. $scope.noneFileShow = true;
  3526. $scope.$watch('myFiles', function(){
  3527. if($scope.myFiles) {
  3528. $scope.noneFileShow = false;
  3529. var file = $scope.myFiles[0];
  3530. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  3531. $scope.pdfShow = true;
  3532. $scope.previewShow = false;
  3533. $scope.imgPreviewName = file.name;
  3534. } else{
  3535. if (typeof(Worker) !== "undefined") {//支持HTML5
  3536. $scope.imgPreview = getObjectURL(file);
  3537. $scope.imgPreviewName = file.name;
  3538. } else{//不支持HTML5
  3539. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  3540. $scope.imgPreviewName = file.name;
  3541. }
  3542. $scope.previewShow = true;
  3543. $scope.pdfShow = false;
  3544. }
  3545. } else {
  3546. $scope.noneFileShow = true;
  3547. $scope.previewShow = false;
  3548. $scope.pdfShow = false;
  3549. }
  3550. });
  3551. //建立一个可存取到该file的url
  3552. var getObjectURL = function(file) {
  3553. var url = null ;
  3554. if (window.createObjectURL!=undefined) { // basic
  3555. url = window.createObjectURL(file) ;
  3556. } else if (window.URL!=undefined) { // mozilla(firefox)
  3557. url = window.URL.createObjectURL(file) ;
  3558. } else if (window.webkitURL!=undefined) { // webkit or chrome
  3559. url = window.webkitURL.createObjectURL(file) ;
  3560. }
  3561. return url ;
  3562. };
  3563. }]);
  3564. /**
  3565. * 代采订单批量导入
  3566. */
  3567. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  3568. // 通过excel批量上传物料
  3569. $scope.result = null;
  3570. $scope.upload = function() {
  3571. var file = $scope.myFiles[0];
  3572. $upload.upload({
  3573. url: 'purc/inquiry/release/excel',
  3574. file: file,
  3575. method: 'POST'
  3576. }).success(function(data) {
  3577. $scope.result = data;
  3578. $scope.success = $scope.result.success;
  3579. $scope.total = $scope.result.total;
  3580. $scope.alters = $scope.result.alters;
  3581. }).error(function(response) {
  3582. toaster.pop('error', response.data || response);
  3583. });
  3584. };
  3585. // 查看范例
  3586. $scope.showImg = function() {
  3587. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  3588. box.show();
  3589. box.find('img').attr('src', src);
  3590. box.find('a').click(function(){
  3591. box.hide();
  3592. });
  3593. box.dblclick(function(){
  3594. box.hide();
  3595. });
  3596. };
  3597. // 下载模板
  3598. $scope.download = function() {
  3599. window.location.href = 'purc/inquiry/upload/template';
  3600. };
  3601. $scope.enSure = function() {
  3602. $modalInstance.close($scope.result.items);
  3603. }
  3604. $scope.cancel = function() {
  3605. $modalInstance.dismiss();
  3606. }
  3607. }]);
  3608. // 平台询价单(已提交)
  3609. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope) {
  3610. $scope.status = 'InquirySubmit';
  3611. BaseService.scrollBackToTop();
  3612. if($rootScope.active) {
  3613. $scope.active = $rootScope.active;
  3614. $rootScope.active = null;
  3615. } else {
  3616. $scope.active = 'todo';
  3617. }
  3618. $scope.agreedText = '全部';
  3619. $scope.dateZoneText = '一个月内';
  3620. $scope.condition = {dateZone: 1};
  3621. /* 时间筛选初始化*/
  3622. var fromDate = new Date();
  3623. var toDate = new Date();
  3624. fromDate.setMonth(fromDate.getMonth() - 1);
  3625. fromDate.setHours(0,0,0,0);
  3626. toDate.setHours(23,59,59,999);
  3627. $scope.condition.dateFrom = fromDate;
  3628. $scope.condition.dateTo = toDate;
  3629. $scope.changeAgreed = function(agreed) {
  3630. $scope.condition.agreed = agreed;
  3631. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3632. $scope.condition.$agreedOpen = false;
  3633. };
  3634. $scope.changeDateZone = function(zone) {
  3635. $scope.condition.dateZone = zone;
  3636. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3637. $scope.condition.$dateZoneOpen = false;
  3638. getDateCondition(zone, $scope.condition);
  3639. $scope.tableParams.page(1);
  3640. $scope.tableParams.reload();
  3641. };
  3642. $scope.setActive = function(state) {
  3643. if($scope.active != state ) {
  3644. $scope.active = state;
  3645. if ($scope.tableParams.page() == 1) {
  3646. $scope.tableParams.reload();
  3647. } else {
  3648. $scope.tableParams.page(1);
  3649. }
  3650. }
  3651. }
  3652. var getService = function() {
  3653. return PurchaseInquiry;
  3654. };
  3655. $scope.tableParams = new ngTableParams({
  3656. page : 1,
  3657. count : 20,
  3658. sorting: {
  3659. 'inquiry.date': 'desc',
  3660. 'inquiry.enterprise.enName': 'asc',
  3661. 'inquiry.code': 'asc'
  3662. }
  3663. }, {
  3664. total : 0,
  3665. counts: [5, 10, 25, 50],
  3666. getData : function($defer, params) {
  3667. $scope.loading = true;
  3668. var pageParams = params.url();
  3669. var realActive = {};
  3670. pageParams.searchFilter = {
  3671. keyword: $scope.keyword,
  3672. fromDate: getDateTime($scope.condition.dateFrom),
  3673. endDate: getDateTime($scope.condition.dateTo)
  3674. };
  3675. if ($scope.active == 'overdue') {
  3676. $scope.active = 'end';
  3677. }
  3678. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3679. $scope.loading = false;
  3680. if(page) {
  3681. params.total(page.totalElement);
  3682. $defer.resolve(page.content);
  3683. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3684. }
  3685. }, function(response){
  3686. $scope.loading = false;
  3687. toaster.pop('error', '数据加载失败', response.data);
  3688. });
  3689. }
  3690. });
  3691. $scope.openDatePicker = function($event, item, openParam) {
  3692. $event.preventDefault();
  3693. $event.stopPropagation();
  3694. item[openParam] = !item[openParam];
  3695. };
  3696. $scope.openFilterDatePicker = function($event, item, openParam) {
  3697. $event.preventDefault();
  3698. $event.stopPropagation();
  3699. item[openParam] = !item[openParam];
  3700. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  3701. $scope.tableParams.reload();
  3702. }
  3703. };
  3704. // 搜索框回车
  3705. $scope.onSearch = function() {
  3706. $scope.tableParams.page(1);
  3707. $scope.tableParams.reload();
  3708. };
  3709. // 采纳
  3710. $scope.accept = function(id) {
  3711. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3712. if(data.success) {
  3713. toaster.pop('success', '提示', data.success);
  3714. $scope.tableParams.reload();
  3715. }
  3716. if(data.error) {
  3717. toaster.pop('error', '提示', data.error);
  3718. }
  3719. }, function(response) {
  3720. toaster.pop('error', '提示', response.data);
  3721. })
  3722. };
  3723. // 拒绝
  3724. $scope.refuse = function(id) {
  3725. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3726. if(data.success) {
  3727. toaster.pop('success', '提示', data.success);
  3728. $scope.tableParams.reload();
  3729. }
  3730. if(data.error) {
  3731. toaster.pop('error', '提示', data.error);
  3732. }
  3733. }, function(response) {
  3734. toaster.pop('error', '提示', response.data);
  3735. })
  3736. }
  3737. }]);
  3738. // 平台询价单(未提交)
  3739. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  3740. BaseService.scrollBackToTop();
  3741. if($rootScope.active = 'done') {
  3742. $scope.active = 'done';
  3743. $rootScope.active = '';
  3744. }
  3745. if($rootScope.active = 'todo') {
  3746. $scope.active = 'todo';
  3747. $rootScope.active = '';
  3748. }
  3749. var getService = function() {
  3750. if($scope.active == 'todo') {
  3751. return PurchaseInquiry.getUnapply;
  3752. }
  3753. if($scope.active == 'done') {
  3754. return PurchaseInquiry.getSubmit;
  3755. }
  3756. }
  3757. $scope.setActive = function(state) {
  3758. if($scope.active != state ) {
  3759. $scope.active = state;
  3760. if ($scope.tableParams.page() == 1) {
  3761. $scope.tableParams.reload();
  3762. } else {
  3763. $scope.tableParams.page(1);
  3764. }
  3765. }
  3766. }
  3767. $scope.tableParams = new ngTableParams({
  3768. page : 1,
  3769. count : 20,
  3770. sorting: {
  3771. 'date': 'desc',
  3772. 'enterprise.enName': 'asc',
  3773. 'code': 'asc'
  3774. }
  3775. }, {
  3776. total : 0,
  3777. counts: [5, 10, 25, 50],
  3778. getData : function($defer, params) {
  3779. $scope.loading = true;
  3780. var pageParams = params.url();
  3781. var realActive = {};
  3782. if ($scope.active == 'overdue') {
  3783. $scope.active = 'end';
  3784. }
  3785. getService().call(null, BaseService.parseParams(pageParams), function(page){
  3786. $scope.loading = false;
  3787. if(page) {
  3788. params.total(page.totalElements);
  3789. $defer.resolve(page.content);
  3790. }
  3791. }, function(response){
  3792. $scope.loading = false;
  3793. toaster.pop('error', '数据加载失败', response.data);
  3794. });
  3795. }
  3796. });
  3797. // 删除明细
  3798. $scope.deleteById = function(id) {
  3799. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  3800. toaster.pop('success', '提示', '删除成功');
  3801. $scope.tableParams.reload();
  3802. }, function(response) {
  3803. toaster.pop('error', '提示', response.data);
  3804. });
  3805. }
  3806. // 删除主表
  3807. $scope.clearOrder = function(id) {
  3808. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  3809. toaster.pop('success', '提示', '删除成功');
  3810. $scope.tableParams.reload();
  3811. }, function(response) {
  3812. toaster.pop('error', '提示', response.data);
  3813. });
  3814. }
  3815. // 提交
  3816. $scope.submit = function(id) {
  3817. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  3818. toaster.pop('success', '提示', '单据提交成功');
  3819. $scope.active = 'done';
  3820. $scope.tableParams.reload();
  3821. }, function(response) {
  3822. toaster.pop('error', '提示', response.data);
  3823. })
  3824. }
  3825. // 发布公共询价
  3826. $scope.publish = function(id) {
  3827. PurchaseInquiry.publishInquiry({id: id}, {}, function(data) {
  3828. toaster.pop('success', '提示', data.success);
  3829. $scope.active = 'done';
  3830. $scope.tableParams.reload();
  3831. }, function(response) {
  3832. toaster.pop('error', '提示', response.data);
  3833. })
  3834. }
  3835. }]);
  3836. // 公共询价列表
  3837. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams) {
  3838. BaseService.scrollBackToTop();
  3839. /**
  3840. * 改变单据日期范围
  3841. */
  3842. var getTenderDateCondition = function(zone, condition) {
  3843. var date = new Date();
  3844. if(zone == -1) {
  3845. condition.dateFrom = null;
  3846. condition.dateTo = null;
  3847. } else if(zone == 7) { // 一星期内
  3848. date.setDate(date.getDate() - 7);
  3849. condition.dateFrom = date;
  3850. condition.dateTo = new Date();
  3851. } else if(zone == 1) { // 一个月内
  3852. date.setMonth(date.getMonth() - 1);
  3853. condition.dateFrom = date;
  3854. condition.dateTo = new Date();
  3855. } else if(zone == 3) { // 三个月内
  3856. date.setMonth(date.getMonth() - 3);
  3857. condition.dateFrom = date;
  3858. condition.dateTo = new Date();
  3859. } else if (zone == 6) { // 半年内
  3860. date.setMonth(date.getMonth() - 6);
  3861. condition.dateFrom = date;
  3862. condition.dateTo = new Date();
  3863. } else { // 一年内
  3864. date.setYear(date.getYear() - 1);
  3865. condition.dateFrom = date;
  3866. condition.dateTo = new Date();
  3867. }
  3868. };
  3869. $scope.dateZoneText = '不限';
  3870. $scope.deliveryZoneText = '不限';
  3871. $scope.condition = {dateZone: -1};
  3872. $scope.changeDateZone = function(zone) {
  3873. $scope.condition.dateZone = zone;
  3874. $scope.condition.$dateZoneOpen = false;
  3875. getTenderDateCondition(zone, $scope.condition);
  3876. $scope.tableParams.page(1);
  3877. $scope.tableParams.reload();
  3878. };
  3879. $scope.openDatePicker = function($event, item, openParam) {
  3880. $event.preventDefault();
  3881. $event.stopPropagation();
  3882. item[openParam] = !item[openParam];
  3883. };
  3884. $scope.parseDate = function(dateStr) {
  3885. if(dateStr)
  3886. return Date.parse(dateStr, 'yyyy-MM-dd');
  3887. return new Date();
  3888. };
  3889. // 选择查找日期
  3890. $scope.onDateCondition = function(){
  3891. $scope.tableParams.page(1);
  3892. $scope.tableParams.reload();
  3893. };
  3894. // $scope.setActive = function(state) {
  3895. // if($scope.active != state) {
  3896. // $scope.active = state;
  3897. // if($scope.tableParams.page() == 1)
  3898. // $scope.tableParams.reload();
  3899. // else
  3900. // $scope.tableParams.page(1);
  3901. // }
  3902. // };
  3903. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  3904. console.log($scope.nowdate);
  3905. var getOpenState = function(active) {
  3906. var fn = 'getOpenAll';
  3907. switch(active) {
  3908. case 'all':
  3909. fn = 'getOpenAll';break;
  3910. case 'todo':
  3911. fn = 'getOpenTodo';break;
  3912. case 'end':
  3913. fn = 'getOpenEnd';break;
  3914. }
  3915. return fn;
  3916. };
  3917. $scope.tableParams = new ngTableParams({
  3918. page : 1,
  3919. count : 20,
  3920. sorting: {
  3921. // 'tender.endDate': 'desc',
  3922. // 'tender.enterprise.enName': 'asc',
  3923. // 'tender.code': 'asc'
  3924. }
  3925. }, {
  3926. total : 0,
  3927. counts: [10, 25, 50, 100],
  3928. getData : function($defer, params) {
  3929. $scope.loading = true;
  3930. var pageParams = params.url();
  3931. // var realActive = {};
  3932. pageParams.searchFilter = { // 筛选条件
  3933. keyword: $scope.keyword,
  3934. fromDate: getDateTime($scope.condition.dateFrom),
  3935. endDate: getDateTime($scope.condition.dateTo)
  3936. };
  3937. // AccountEnterprise.get({}, function(data){
  3938. // $scope.loading = false;
  3939. // $scope.currentEn = data;
  3940. // });
  3941. PurchaseInquiry.publicInquiryItem.call(null, BaseService.parseParams(pageParams), function(page){
  3942. $scope.loading = false;
  3943. if(page) {
  3944. params.total(page.totalElement);
  3945. $defer.resolve(page.content);
  3946. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  3947. }
  3948. }, function(response){
  3949. $scope.loading = false;
  3950. toaster.pop('error', '数据加载失败', response.data);
  3951. });
  3952. }
  3953. });
  3954. $scope.toDetail = function(id) {
  3955. window.location.hash = '#/baseInfo/inquiryList/' + id;
  3956. };
  3957. // 搜索框回车
  3958. $scope.onSearch = function() {
  3959. $scope.tableParams.page(1);
  3960. $scope.tableParams.reload();
  3961. };
  3962. }]);
  3963. /**
  3964. * 公共询价详情
  3965. */
  3966. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise) {
  3967. BaseService.scrollBackToTop();
  3968. $scope.currentHasBid = false;
  3969. var loadData = function() {
  3970. PurchaseInquiry.inquiryItemDetail({id: $stateParams.id}, function(data) {
  3971. $scope.inquiryItem = data.inquiryItem;
  3972. if(data.id) {
  3973. $scope.id = data.id;
  3974. console.log($scope.id);
  3975. $scope.currentHasBid = true;
  3976. }
  3977. }, function(response) {
  3978. toaster.pop('error', '提示', response.data);
  3979. });
  3980. }
  3981. loadData();
  3982. // 当前时间
  3983. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  3984. // 当前企业
  3985. AccountEnterprise.get({}, function(data){
  3986. $scope.loading = false;
  3987. $scope.enterprise = data;
  3988. });
  3989. // 转客户询价
  3990. $scope.transtoInquiry = function(id) {
  3991. PurchaseInquiry.transtoInquiry({id: id}, {}, function(data) {
  3992. if(data.success) {
  3993. toaster.pop('success', '提示', data.success);
  3994. window.location.hash = "sale/inquiry/" + data.id;
  3995. }
  3996. if(data.error) {
  3997. toaster.pop('error', '提示', data.error);
  3998. }
  3999. if(data.info) {
  4000. toaster.pop('info', '提示', data.info);
  4001. }
  4002. }, function(response) {
  4003. toaster.pop('error', '提示', response.data);
  4004. });
  4005. }
  4006. }]);
  4007. // 询价单明细
  4008. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  4009. var loadData = function() {
  4010. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  4011. $scope.newinquiryItems = data;
  4012. var inquiry = data[0].inquiry;
  4013. //inquiry.inquiryItems = data;
  4014. angular.forEach(inquiry.attachs, function(attach){
  4015. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  4016. });
  4017. $scope.inquiry = inquiry;
  4018. });
  4019. };
  4020. loadData();
  4021. $scope.getMinDate = function(item) {
  4022. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4023. };
  4024. $scope.addStep = function(inquiryItem) {
  4025. if(inquiryItem.replies.length >= 10) {
  4026. toaster.pop('warning', '提示', '最多支持10个分段!');
  4027. } else
  4028. inquiryItem.replies.push({});
  4029. };
  4030. $scope.removeStep = function(inquiryItem, stepIndex) {
  4031. inquiryItem.replies.splice(stepIndex, 1);
  4032. };
  4033. $scope.openDatePicker = function($event, item, openParam) {
  4034. $event.preventDefault();
  4035. $event.stopPropagation();
  4036. item[openParam] = !item[openParam];
  4037. };
  4038. $scope.getHistory = function(item) {
  4039. if(!item.history) {
  4040. PurcInquiry.getHistory({itemId: item.id}, function(data){
  4041. item.history = data;
  4042. });
  4043. }
  4044. };
  4045. $scope.isValid = function(item, withSteps) {
  4046. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4047. if(!withSteps || !bool)
  4048. return bool;
  4049. angular.forEach(item.replies, function(r, i){
  4050. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4051. });
  4052. return bool;
  4053. };
  4054. $scope.onReplyClick = function(item, withSteps) {
  4055. if(item.vendFromDate instanceof Date) {
  4056. item.vendFromDate = item.vendFromDate.getTime();
  4057. }
  4058. if(item.vendToDate instanceof Date) {
  4059. item.vendToDate = item.vendToDate.getTime();
  4060. }
  4061. if(item.vendFromDate > item.vendToDate) {
  4062. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4063. return;
  4064. }
  4065. var replies = [];
  4066. angular.forEach(item.replies, function(r, i){
  4067. if((i > 0 ? r.lapQty : 1) || r.price)
  4068. replies.push(r);
  4069. });
  4070. item.replies = replies;
  4071. if(withSteps) {
  4072. PurcInquiry.reply({itemId: item.id}, item, function(){
  4073. toaster.pop('info', '提示', '报价成功');
  4074. loadData();
  4075. }, function(response){
  4076. toaster.pop('error', '报价失败', response.data);
  4077. });
  4078. }
  4079. };
  4080. }]);
  4081. // 询价单明细(发出)
  4082. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', function($scope, $stateParams, PurchaseInquiry,$filter, toaster){
  4083. var loadData = function() {
  4084. PurchaseInquiry.detail({id: $stateParams.id}, function(data){
  4085. $scope.inquiry = data;
  4086. });
  4087. };
  4088. loadData();
  4089. $scope.getMinDate = function(item) {
  4090. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4091. };
  4092. $scope.addStep = function(inquiryItem) {
  4093. if(inquiryItem.replies.length >= 10) {
  4094. toaster.pop('warning', '提示', '最多支持10个分段!');
  4095. } else
  4096. inquiryItem.replies.push({});
  4097. };
  4098. $scope.removeStep = function(inquiryItem, stepIndex) {
  4099. inquiryItem.replies.splice(stepIndex, 1);
  4100. };
  4101. $scope.openDatePicker = function($event, item, openParam) {
  4102. $event.preventDefault();
  4103. $event.stopPropagation();
  4104. item[openParam] = !item[openParam];
  4105. };
  4106. $scope.getHistory = function(item) {
  4107. if(!item.history) {
  4108. PurcInquiry.getHistory({itemId: item.id}, function(data){
  4109. item.history = data;
  4110. });
  4111. }
  4112. };
  4113. $scope.isValid = function(item, withSteps) {
  4114. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4115. if(!withSteps || !bool)
  4116. return bool;
  4117. angular.forEach(item.replies, function(r, i){
  4118. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4119. });
  4120. return bool;
  4121. };
  4122. $scope.onReplyClick = function(item, withSteps) {
  4123. if(item.vendFromDate instanceof Date) {
  4124. item.vendFromDate = item.vendFromDate.getTime();
  4125. }
  4126. if(item.vendToDate instanceof Date) {
  4127. item.vendToDate = item.vendToDate.getTime();
  4128. }
  4129. if(item.vendFromDate > item.vendToDate) {
  4130. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4131. return;
  4132. }
  4133. var replies = [];
  4134. angular.forEach(item.replies, function(r, i){
  4135. if((i > 0 ? r.lapQty : 1) || r.price)
  4136. replies.push(r);
  4137. });
  4138. item.replies = replies;
  4139. if(withSteps) {
  4140. PurcInquiry.reply({itemId: item.id}, item, function(){
  4141. toaster.pop('info', '提示', '报价成功');
  4142. loadData();
  4143. }, function(response){
  4144. toaster.pop('error', '报价失败', response.data);
  4145. });
  4146. }
  4147. };
  4148. // 采纳
  4149. $scope.accept = function(id) {
  4150. PurchaseInquiry.accept({id: id}, {}, function(data) {
  4151. if(data.success) {
  4152. toaster.pop('success', '提示', data.success);
  4153. loadData();
  4154. }
  4155. if(data.error) {
  4156. toaster.pop('error', '提示', data.error);
  4157. }
  4158. }, function(response) {
  4159. toaster.pop('error', '提示', response.data);
  4160. })
  4161. };
  4162. // 拒绝
  4163. $scope.refuse = function(id) {
  4164. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  4165. if(data.success) {
  4166. toaster.pop('success', '提示', data.success);
  4167. loadData();
  4168. }
  4169. if(data.error) {
  4170. toaster.pop('error', '提示', data.error);
  4171. }
  4172. }, function(response) {
  4173. toaster.pop('error', '提示', response.data);
  4174. })
  4175. }
  4176. }]);
  4177. // 模具询价管理
  4178. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  4179. BaseService.scrollBackToTop();
  4180. $scope.active = 'todo';
  4181. $scope.agreedText = '全部';
  4182. $scope.dateZoneText = '不限';
  4183. $scope.condition = {dateZone: 1};
  4184. /* 时间筛选初始化*/
  4185. var fromDate = new Date();
  4186. var toDate = new Date();
  4187. fromDate.setMonth(fromDate.getMonth() - 1);
  4188. fromDate.setHours(0,0,0,0);
  4189. toDate.setHours(23,59,59,999);
  4190. $scope.condition.dateFrom = fromDate;
  4191. $scope.condition.dateTo = toDate;
  4192. var inquiryMould_copy = {};
  4193. $scope.changeAgreed = function(agreed) {
  4194. $scope.condition.agreed = agreed;
  4195. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4196. $scope.condition.$agreedOpen = false;
  4197. };
  4198. $scope.changeDateZone = function(zone) {
  4199. $scope.condition.dateZone = zone;
  4200. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4201. $scope.condition.$dateZoneOpen = false;
  4202. getDateCondition(zone, $scope.condition);
  4203. $scope.tableParams.page(1);
  4204. $scope.tableParams.reload();
  4205. };
  4206. $scope.setActive = function(state) {
  4207. if($scope.active != state ) {
  4208. $scope.active = state;
  4209. if ($scope.tableParams.page() == 1) {
  4210. $scope.tableParams.reload();
  4211. } else {
  4212. $scope.tableParams.page(1);
  4213. }
  4214. }
  4215. };
  4216. var getService = function() {
  4217. return PurcInquiryMould;
  4218. };
  4219. $scope.tableParams = new ngTableParams({
  4220. page: 1,
  4221. count: 5
  4222. },{
  4223. total: 0,
  4224. counts: [5, 10, 25, 50],
  4225. getData: function($defer, params) {
  4226. $scope.loading = true;
  4227. var pageParams = params.url();
  4228. var realActive = {};
  4229. pageParams.searchFilter = {
  4230. keyword: $scope.keyword,
  4231. fromDate: getDateTime($scope.condition.dateFrom),
  4232. endDate: getDateTime($scope.condition.dateTo)
  4233. };
  4234. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4235. $scope.loading = false;
  4236. // 用来验证价格修改
  4237. var mould = page.content;
  4238. inquiryMould_copy = angular.copy(mould);
  4239. if(page) {
  4240. params.total(page.totalElement);
  4241. $defer.resolve(page.content);
  4242. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4243. }
  4244. }, function(response){
  4245. $scope.loading = false;
  4246. toaster.pop('error', '数据加载失败', response.data);
  4247. });
  4248. }
  4249. })
  4250. $scope.getMinDate = function(item) {
  4251. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  4252. };
  4253. $scope.replyPrices = [];
  4254. $scope.replyPrices.push(true);
  4255. // 取消
  4256. $scope.reload = function() {
  4257. $scope.tableParams.reload();
  4258. $scope.canSave = false;
  4259. }
  4260. // 能否保存设置
  4261. $scope.canSave = false;
  4262. // items价格验证
  4263. $scope.verifyItems = function(price, reply) {
  4264. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  4265. if(regex.test(price) && price != 0) {
  4266. if (price != reply) {
  4267. $scope.canSave = true;
  4268. } else {
  4269. $scope.canSave = false;
  4270. }
  4271. } else {
  4272. $scope.canSave = false;
  4273. }
  4274. }
  4275. // prod下prods价格验证
  4276. $scope.verifyProds = function(price, reply) {
  4277. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4278. if(regex.test(price) && price != 0) {
  4279. if (price != reply) {
  4280. $scope.canSave = true;
  4281. } else {
  4282. $scope.canSave = false;
  4283. }
  4284. } else {
  4285. $scope.canSave = false;
  4286. }
  4287. }
  4288. //有价格为0或者不符合正则式,则不能报价
  4289. $scope.notZero = function (mould) {
  4290. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4291. angular.forEach(mould.inquiryMouldItems, function(item){
  4292. if (item.price == 0 || !regex.test(item.price)) {
  4293. $scope.canSave = false;
  4294. }
  4295. angular.forEach(item.inquiryMouldDetails, function(detail){
  4296. if (detail.price == 0 || !regex.test(detail.price)) {
  4297. $scope.canSave = false;
  4298. }
  4299. })
  4300. });
  4301. }
  4302. $scope.blurPrice = function (price) {
  4303. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4304. if (!regex.test(price)) {
  4305. toaster.pop('warning','格式错误','请输入有效价格');
  4306. }
  4307. }
  4308. // 获取历史报价
  4309. $scope.getHistory = function(mould) {
  4310. if(!mould.history) {
  4311. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  4312. mould.history = data;
  4313. });
  4314. }
  4315. };
  4316. $scope.uploadAttach = function(mould) {
  4317. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4318. var file = mould.attachs[0];
  4319. $scope.mould = mould;
  4320. $upload.upload({
  4321. url: 'sale/mould/' + mould.id + '/send',
  4322. method: 'POST',
  4323. file: file,
  4324. data: {
  4325. json: $scope.mould
  4326. }
  4327. }).success(function(res){
  4328. }).error(function(res){
  4329. });
  4330. }
  4331. // 保存并确认报价
  4332. $scope.onReplyClick = function(mould, withSteps) {
  4333. $scope.loading = true;
  4334. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4335. // var file = mould.attachs[0];
  4336. // $scope.mould = mould;
  4337. // $upload.upload({
  4338. // url: 'sale/mould/' + mould.id + '/send',
  4339. // method: 'POST',
  4340. // file: file,
  4341. // data: {
  4342. // json: $scope.mould
  4343. // }
  4344. // }).success(function(res){
  4345. // console.log("success");
  4346. // console.log(res);
  4347. // }).error(function(res){
  4348. // console.log("failure");
  4349. // });
  4350. if(withSteps) {
  4351. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4352. $scope.loading = false;
  4353. toaster.pop('info', '提示', '报价成功');
  4354. $scope.tableParams.reload();
  4355. $scope.canSave = false;
  4356. }, function(response){
  4357. $scope.loading = false;
  4358. toaster.pop('error', '报价失败', response.data);
  4359. });
  4360. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4361. }, function(response){
  4362. });
  4363. } else {
  4364. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4365. $scope.loading = false;
  4366. toaster.pop('info', '提示', '保存成功');
  4367. $scope.tableParams.reload();
  4368. }, function(response){
  4369. $scope.loading = false;
  4370. toaster.pop('error', '保存失败', response.data);
  4371. });
  4372. }
  4373. };
  4374. // 搜索框回车
  4375. $scope.onSearch = function() {
  4376. $scope.tableParams.page(1);
  4377. $scope.tableParams.reload();
  4378. };
  4379. $scope.openDatePicker = function($event, item, openParam) {
  4380. $event.preventDefault();
  4381. $event.stopPropagation();
  4382. item[openParam] = !item[openParam];
  4383. };
  4384. $scope.openFilterDatePicker = function($event, item, openParam) {
  4385. $event.preventDefault();
  4386. $event.stopPropagation();
  4387. item[openParam] = !item[openParam];
  4388. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  4389. $scope.tableParams.reload();
  4390. }
  4391. };
  4392. $scope.parseDate = function(dateStr) {
  4393. if(dateStr)
  4394. return Date.parse(dateStr, 'yyyy-MM-dd');
  4395. return new Date();
  4396. };
  4397. }]);
  4398. // 模具询价单明细
  4399. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  4400. var inquiryMould_copy = {};
  4401. var loadData = function() {
  4402. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  4403. // 用来验证价格修改
  4404. inquiryMould_copy = angular.copy(data);
  4405. $scope.inquiryMould_copy = inquiryMould_copy;
  4406. $scope.newinquirymould = data;
  4407. var mould = data;
  4408. angular.forEach(mould.attachs, function(attach){
  4409. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  4410. });
  4411. $scope.inquiryMould = mould;
  4412. });
  4413. };
  4414. loadData();
  4415. $scope.getMinDate = function(item) {
  4416. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4417. };
  4418. // 取消
  4419. $scope.reload = function() {
  4420. loadData();
  4421. $scope.canSave = false;
  4422. }
  4423. //有价格为0,则不能报价
  4424. $scope.notZero = function (mould) {
  4425. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4426. angular.forEach(mould.inquiryMouldItems, function(item){
  4427. if (item.price == 0 || !regex.test(item.price)) {
  4428. $scope.canSave = false;
  4429. }
  4430. angular.forEach(item.inquiryMouldDetails, function(detail){
  4431. if (detail.price == 0 || !regex.test(detail.price)) {
  4432. $scope.canSave = false;
  4433. }
  4434. })
  4435. });
  4436. }
  4437. $scope.blurPrice = function (price) {
  4438. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  4439. if (!regex.test(price)) {
  4440. toaster.pop('warning','格式错误','请输入有效价格');
  4441. }
  4442. }
  4443. // 获取历史报价
  4444. $scope.getHistory = function(mould) {
  4445. if(!mould.history) {
  4446. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  4447. mould.history = data;
  4448. });
  4449. }
  4450. };
  4451. $scope.canSave = false;
  4452. // items价格验证
  4453. $scope.verifyItems = function(price, index) {
  4454. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4455. if(regex.test(price) && price != 0) {
  4456. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  4457. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  4458. $scope.canSave = true;
  4459. } else {
  4460. $scope.canSave = false;
  4461. }
  4462. } else {
  4463. $scope.canSave = false;
  4464. }
  4465. }
  4466. // prod下prods价格验证
  4467. $scope.verifyProds = function(price, index, parentIndex) {
  4468. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  4469. if(regex.test(price) && price != 0) {
  4470. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  4471. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  4472. $scope.canSave = true;
  4473. } else {
  4474. $scope.canSave = false;
  4475. }
  4476. } else {
  4477. $scope.canSave = false;
  4478. }
  4479. }
  4480. // // 上传附件
  4481. // $scope.uploadAttach = function(mould) {
  4482. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  4483. // var file = mould.attachs[0];
  4484. // $scope.mould = mould;
  4485. // $upload.upload({
  4486. // url: 'sale/mould/' + mould.id + '/send',
  4487. // method: 'POST',
  4488. // file: file,
  4489. // data: {
  4490. // json: $scope.mould
  4491. // }
  4492. // }).success(function(res){
  4493. // console.log("success");
  4494. // console.log(res);
  4495. // }).error(function(res){
  4496. // console.log("failure");
  4497. // console.log(res);
  4498. // });
  4499. // }
  4500. $scope.onReplyClick = function(mould, withSteps) {
  4501. $scope.loading = true;
  4502. // var file = mould.attachs[0];
  4503. // $scope.mould = mould;
  4504. // $upload.upload({
  4505. // url: 'sale/mould/' + mould.id + '/send',
  4506. // method: 'POST',
  4507. // file: file,
  4508. // data: {
  4509. // json: $scope.mould
  4510. // }
  4511. // }).success(function(res){
  4512. //
  4513. // }).error(function(res){
  4514. // console.log(res);
  4515. // });
  4516. if(withSteps) {
  4517. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  4518. $scope.loading = false;
  4519. toaster.pop('info', '提示', '报价成功');
  4520. loadData();
  4521. $scope.canSave = false;
  4522. }, function(response){
  4523. $scope.loading = false;
  4524. toaster.pop('error', '报价失败', response.data);
  4525. });
  4526. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  4527. }, function(response){
  4528. });
  4529. } else {
  4530. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  4531. $scope.loading = false;
  4532. toaster.pop('info', '提示', '保存成功');
  4533. loadData();
  4534. }, function(response){
  4535. $scope.loading = false;
  4536. toaster.pop('error', '保存失败', response.data);
  4537. });
  4538. }
  4539. };
  4540. }]);
  4541. // 主动报价 - 列表
  4542. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope){
  4543. BaseService.scrollBackToTop();
  4544. $rootScope.enteryStatus = false;
  4545. $scope.active = 'todo';
  4546. $scope.agreedText = '全部';
  4547. $scope.dateZoneText = '一个月内';
  4548. $scope.condition = {dateZone: 1};
  4549. /* 时间筛选初始化*/
  4550. var fromDate = new Date();
  4551. var toDate = new Date();
  4552. fromDate.setMonth(fromDate.getMonth() - 1);
  4553. fromDate.setHours(0,0,0,0);
  4554. toDate.setHours(23,59,59,999);
  4555. $scope.condition.dateFrom = fromDate;
  4556. $scope.condition.dateTo = toDate;
  4557. $scope.changeDateZone = function(zone) {
  4558. $scope.condition.dateZone = zone;
  4559. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4560. $scope.condition.$dateZoneOpen = false;
  4561. getDateCondition(zone, $scope.condition);
  4562. $scope.tableParams.page(1);
  4563. $scope.tableParams.reload();
  4564. };
  4565. $scope.setActive = function(state) {
  4566. if($scope.active != state) {
  4567. $scope.active = state;
  4568. if($scope.tableParams.page() == 1)
  4569. $scope.tableParams.reload();
  4570. else
  4571. $scope.tableParams.page(1);
  4572. }
  4573. };
  4574. var getService = function() {
  4575. return Quotation;
  4576. };
  4577. $scope.tableParams = new ngTableParams({
  4578. page : 1,
  4579. count : 20,
  4580. sorting: {
  4581. 'quotation.date': 'desc'
  4582. }
  4583. }, {
  4584. total : 0,
  4585. counts: [5, 10, 25, 50],
  4586. getData : function($defer, params) {
  4587. $scope.loading = true;
  4588. var pageParams = params.url();
  4589. pageParams.searchFilter = {
  4590. keyword: $scope.keyword,
  4591. fromDate: getDateTime($scope.condition.dateFrom),
  4592. endDate: getDateTime($scope.condition.dateTo)
  4593. };
  4594. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4595. $scope.loading = false;
  4596. if(page) {
  4597. params.total(page.totalElement);
  4598. $defer.resolve(page.content);
  4599. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4600. }
  4601. }, function(response){
  4602. $scope.loading = false;
  4603. toaster.pop('error', '数据加载失败', response.data);
  4604. });
  4605. }
  4606. });
  4607. $scope.openDatePicker = function($event, item, openParam) {
  4608. $event.preventDefault();
  4609. $event.stopPropagation();
  4610. item[openParam] = !item[openParam];
  4611. };
  4612. $scope.openFilterDatePicker = function($event, item, openParam) {
  4613. $event.preventDefault();
  4614. $event.stopPropagation();
  4615. item[openParam] = !item[openParam];
  4616. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  4617. $scope.tableParams.reload();
  4618. }
  4619. };
  4620. $scope.getHistory = function(item) {
  4621. if(!item.history) {
  4622. PurcInquiry.getHistory({itemId: item.id}, function(data){
  4623. item.history = data;
  4624. });
  4625. }
  4626. };
  4627. $scope.isValid = function(item, withSteps) {
  4628. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4629. if(!withSteps || !bool)
  4630. return bool;
  4631. angular.forEach(item.replies, function(r, i){
  4632. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4633. });
  4634. return bool;
  4635. };
  4636. // 搜索框回车
  4637. $scope.onSearch = function() {
  4638. $scope.tableParams.page(1);
  4639. $scope.tableParams.reload();
  4640. };
  4641. }]);
  4642. // Controller 主动报价 - 新增
  4643. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope){
  4644. BaseService.scrollBackToTop();
  4645. var staticItem = null;
  4646. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  4647. $scope.loading = true;
  4648. $rootScope.enteryStatus = true;
  4649. Quotation.getItem({id: $stateParams.id}, function(data){
  4650. // data.$editing = false;
  4651. $scope.item = data;
  4652. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  4653. staticItem = angular.copy(data);
  4654. $scope.loading = false;
  4655. }, function(response){
  4656. $scope.loading = false;
  4657. toaster.pop('error', '数据加载失败', response.data);
  4658. });
  4659. } else {// 新增模式
  4660. $rootScope.enteryStatus = false;
  4661. $scope.item = {
  4662. quotation: {
  4663. currency: 'RMB',
  4664. taxrate: 17,
  4665. date: new Date()
  4666. },
  4667. product: {},
  4668. prices: [{lapQty: 0}],
  4669. minOrderQty: 1,
  4670. minPackQty: 1,
  4671. $endDateOpen: false,
  4672. $editing: true
  4673. };
  4674. }
  4675. $scope.getMinDate = function(item) {
  4676. return $filter('date')(new Date, 'yyyy-MM-dd');
  4677. };
  4678. //是否不能被点击
  4679. $scope.isDisabled = function () {
  4680. return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
  4681. }
  4682. $scope.openDatePicker = function($event, openParam) {
  4683. $event.preventDefault();
  4684. $event.stopPropagation();
  4685. $scope.item.$endDateOpen = !openParam;
  4686. };
  4687. // 增加一个分段
  4688. $scope.addPrice = function(){
  4689. if($scope.item.prices.length >= 10) {
  4690. toaster.pop('warning', '提示', '最多支持10个分段!');
  4691. } else
  4692. $scope.item.prices.push({});
  4693. };
  4694. // 删除一个分段
  4695. $scope.removePrice = function(index) {
  4696. $scope.item.prices.splice(index, 1);
  4697. };
  4698. // 查找客户
  4699. $scope.dbfindCust = function(){
  4700. if($scope.item.$editing) {
  4701. var modalInstance = $modal.open({
  4702. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  4703. controller: 'DbfindCustCtrl',
  4704. size: 'lg',
  4705. resolve: {
  4706. }
  4707. });
  4708. modalInstance.result.then(function(data){
  4709. $scope.item.quotation.cust = data.myEnterprise;
  4710. $scope.item.quotation.custUser = data.myUser;
  4711. $scope.item.product = null;
  4712. }, function(){
  4713. });
  4714. }
  4715. };
  4716. // 赋值客户信息
  4717. if($rootScope.custuu) {
  4718. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function(data) {
  4719. $scope.item.quotation.cust = data.myEnterprise;
  4720. $scope.item.quotation.custUser = data.myUser;
  4721. })
  4722. }
  4723. // 赋值物料信息
  4724. if($rootScope.prodId) {
  4725. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  4726. $scope.item.product.code = data.code;
  4727. $scope.item.product.title = data.title;
  4728. $scope.item.product.spec = data.spec;
  4729. $scope.item.product.unit = data.unit;
  4730. $scope.item.product.id = data.id;
  4731. }, function(response) {
  4732. });
  4733. }
  4734. // 查找客户物料
  4735. $scope.dbfindCustProd = function(){
  4736. if($scope.item.$editing) {
  4737. if($scope.item.quotation.cust.uu) {
  4738. var modalInstance = $modal.open({
  4739. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  4740. controller: 'DbfindCustProdCtrl',
  4741. size: 'lg',
  4742. resolve: {
  4743. custUU: function(){return $scope.item.quotation.cust.uu}
  4744. }
  4745. });
  4746. modalInstance.result.then(function(data){
  4747. $scope.item.product = data;
  4748. }, function(){
  4749. });
  4750. } else {
  4751. toaster.pop('error', '错误', '请先选择客户');
  4752. }
  4753. }
  4754. };
  4755. // 保存
  4756. $scope.save = function(){
  4757. $scope.loading = true;
  4758. if(!$scope.item.quotation.code) //新增,设单号
  4759. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  4760. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  4761. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  4762. $scope.item.productId = $scope.item.product.id;
  4763. $scope.item.quotation.status = 100;//在录入
  4764. if($scope.item.quotation.date instanceof Date) {
  4765. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  4766. }
  4767. if($scope.item.quotation.endDate instanceof Date) {
  4768. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  4769. }
  4770. Quotation.save({}, $scope.item, function(data){
  4771. $scope.loading = false;
  4772. toaster.pop('success', '成功', '保存成功');
  4773. if($stateParams.id)
  4774. window.location.reload();
  4775. else
  4776. // window.location.hash = '#/sale/quotation/' + data.id;
  4777. window.location.hash = '#/sale/quotation/list';
  4778. }, function(response){
  4779. $scope.loading = false;
  4780. toaster.pop('error', '保存失败', response.data);
  4781. });
  4782. };
  4783. // 更新
  4784. $scope.update = function(){
  4785. $scope.item.$editing = true;
  4786. };
  4787. // 取消
  4788. $scope.cancel = function(){
  4789. $scope.item.$editing = false;
  4790. $scope.item = angular.copy(staticItem);
  4791. };
  4792. // 提交
  4793. $scope.submit = function(){
  4794. $scope.loading = true;
  4795. $scope.item.quotation.status = 101;//已提交
  4796. Quotation.save({}, $scope.item, function(data){
  4797. $scope.loading = false;
  4798. toaster.pop('success', '成功', '提交成功');
  4799. window.location.hash = '#/sale/quotation/' + data.id;
  4800. }, function(response){
  4801. $scope.loading = false;
  4802. toaster.pop('error', '保存失败', response.data);
  4803. });
  4804. };
  4805. $scope.deleteById = function(id) {
  4806. Quotation.deleteById({id: id}, {}, function(data) {
  4807. window.location.href = "#/sale/quotation/list";
  4808. }, function(response) {
  4809. toaster.pop('error', '提示', response.data);
  4810. })
  4811. }
  4812. }]);
  4813. // 查找客户
  4814. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  4815. BaseService.scrollBackToTop();
  4816. $scope.tableParams = new ngTableParams({
  4817. page : 1,
  4818. count : 20
  4819. }, {
  4820. total : 0,
  4821. counts: [5, 10, 25, 50],
  4822. getData : function($defer, params) {
  4823. $scope.loading = true;
  4824. var pageParams = params.url();
  4825. pageParams.keyword = $scope.keyword;
  4826. Customer.get(BaseService.parseParams(pageParams), function(page){
  4827. $scope.loading = false;
  4828. if(page) {
  4829. params.total(page.totalElement);
  4830. $defer.resolve(page.content);
  4831. }
  4832. $scope.totalCount = page.totalElement;
  4833. }, function(response){
  4834. $scope.loading = false;
  4835. toaster.pop('error', '数据加载失败', response.data);
  4836. });
  4837. }
  4838. });
  4839. $scope.onSearch = function() {
  4840. $scope.tableParams.page(1);
  4841. $scope.tableParams.reload();
  4842. };
  4843. $scope.cancel = function() {
  4844. $modalInstance.dismiss();
  4845. };
  4846. $scope.check = function(cust){
  4847. $modalInstance.close(cust);
  4848. };
  4849. }]);
  4850. // 查找客户物料
  4851. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  4852. BaseService.scrollBackToTop();
  4853. $scope.tableParams = new ngTableParams({
  4854. page : 1,
  4855. count : 20
  4856. }, {
  4857. total : 0,
  4858. counts: [5, 10, 25, 50],
  4859. getData : function($defer, params) {
  4860. $scope.loading = true;
  4861. var pageParams = params.url();
  4862. pageParams.keyword = $scope.keyword;
  4863. pageParams.custUU = custUU;
  4864. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  4865. $scope.loading = false;
  4866. if(page) {
  4867. params.total(page.totalElement);
  4868. $defer.resolve(page.content);
  4869. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4870. }
  4871. }, function(response){
  4872. $scope.loading = false;
  4873. toaster.pop('error', '数据加载失败', response.data);
  4874. });
  4875. }
  4876. });
  4877. // 取消
  4878. $scope.cancel = function() {
  4879. $modalInstance.dismiss();
  4880. };
  4881. // 选择
  4882. $scope.check = function(cust){
  4883. $modalInstance.close(cust);
  4884. };
  4885. // 搜索框回车
  4886. $scope.onSearch = function() {
  4887. $scope.tableParams.page(1);
  4888. $scope.tableParams.reload();
  4889. };
  4890. }]);
  4891. // 查找供应商
  4892. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  4893. BaseService.scrollBackToTop();
  4894. // 搜索框回车
  4895. $scope.onSearch = function(keyword) {
  4896. $scope.keyword = keyword;
  4897. $scope.tableParams.page(1);
  4898. $scope.tableParams.reload();
  4899. };
  4900. $scope.tableParams = new ngTableParams({
  4901. page : 1,
  4902. count : 20
  4903. }, {
  4904. total : 0,
  4905. counts: [10, 25, 50, 100],
  4906. getData : function($defer, params) {
  4907. $scope.loading = true;
  4908. var pageParams = params.url();
  4909. pageParams.keyword = $scope.keyword;
  4910. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  4911. $scope.loading = false;
  4912. if(page) {
  4913. params.total(page.totalElement);
  4914. $defer.resolve(page.content);
  4915. // 添加供应商时,将已存在的选中
  4916. if ($rootScope.tenderVendor) {
  4917. angular.forEach(page.content, function(vendor) {
  4918. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  4919. vendor.checked = false;
  4920. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  4921. vendor.checked = true;
  4922. break;
  4923. }
  4924. }
  4925. });
  4926. }
  4927. }
  4928. $scope.totalCount = page.totalElement;
  4929. }, function(response){
  4930. $scope.loading = false;
  4931. toaster.pop('error', '数据加载失败', response.data);
  4932. });
  4933. }
  4934. });
  4935. $scope.cancel = function() {
  4936. $modalInstance.dismiss();
  4937. };
  4938. $scope.checks = {
  4939. checked : false
  4940. };// 全选框
  4941. $scope.checkAll = function() {
  4942. angular.forEach($scope.tableParams.data, function(vendor) {
  4943. vendor.checked = $scope.checks.checked;
  4944. });
  4945. };
  4946. // 单选
  4947. $scope.checkOne = function(vendor) {
  4948. vendor.checked = true;
  4949. var checked = true;
  4950. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  4951. if (!message.checked) {
  4952. checked = false;
  4953. }
  4954. });
  4955. $scope.checks.checked = checked;
  4956. };
  4957. // 单反选
  4958. $scope.unCheckOne = function(vendor) {
  4959. vendor.checked = false;
  4960. $scope.checks.checked = false;
  4961. };
  4962. $scope.close = function(){
  4963. var vendors = [];
  4964. angular.forEach($scope.tableParams.data, function(vendor) {
  4965. if(vendor.checked) {
  4966. vendors.push(vendor);
  4967. $modalInstance.close(vendors);
  4968. }
  4969. });
  4970. };
  4971. }]);
  4972. // 发货提醒
  4973. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', '$timeout', function($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state, $timeout){
  4974. BaseService.scrollBackToTop();
  4975. $scope.active = 'todo';
  4976. $scope.currency = Symbol.currency;
  4977. $scope.dateZoneText = '不限';
  4978. $scope.condition = {dateZone: 1};
  4979. /* 时间筛选初始化*/
  4980. var fromDate = new Date();
  4981. var toDate = new Date();
  4982. fromDate.setMonth(fromDate.getMonth() - 1);
  4983. fromDate.setHours(0,0,0,0);
  4984. toDate.setHours(23,59,59,999);
  4985. $scope.condition.dateFrom = fromDate;
  4986. $scope.condition.dateTo = toDate;
  4987. $scope.changeDateZone = function(zone) {
  4988. $scope.condition.dateZone = zone;
  4989. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4990. $scope.condition.$dateZoneOpen = false;
  4991. getDateCondition(zone, $scope.condition);
  4992. $scope.tableParams.page(1);
  4993. $scope.tableParams.reload();
  4994. };
  4995. $scope.setActive = function(state) {
  4996. if($scope.active != state) {
  4997. $scope.active = state;
  4998. if($scope.tableParams.page() == 1)
  4999. $scope.tableParams.reload();
  5000. else
  5001. $scope.tableParams.page(1);
  5002. }
  5003. };
  5004. var getService = function() {
  5005. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  5006. };
  5007. $scope.tableParams = new ngTableParams({
  5008. page : 1,
  5009. count : 20,
  5010. sorting: {
  5011. 'delivery': 'asc',
  5012. 'orderItemOrderCode': 'asc',
  5013. 'orderItemNumber': 'asc'
  5014. }
  5015. }, {
  5016. total : 0,
  5017. counts: [5, 10, 25, 50],
  5018. getData : function($defer, params) {
  5019. $scope.loading = true;
  5020. var pageParams = params.url();
  5021. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5022. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5023. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5024. $scope.loading = false;
  5025. if(page) {
  5026. params.total(page.totalElement);
  5027. $defer.resolve(page.content);
  5028. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5029. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5030. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5031. }
  5032. }, function(response){
  5033. $scope.loading = false;
  5034. toaster.pop('error', '数据加载失败', response.data);
  5035. });
  5036. }
  5037. });
  5038. $scope.openDatePicker = function($event, item, openParam) {
  5039. $event.preventDefault();
  5040. $event.stopPropagation();
  5041. item[openParam] = !item[openParam];
  5042. };
  5043. $scope.openFilterDatePicker = function($event, item, openParam) {
  5044. $event.preventDefault();
  5045. $event.stopPropagation();
  5046. item[openParam] = !item[openParam];
  5047. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  5048. $scope.tableParams.reload();
  5049. }
  5050. };
  5051. //生成随机单号
  5052. $scope.autoCode = function(notice){
  5053. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  5054. };
  5055. //可送货日期
  5056. $scope.sendDate = function(notice) {
  5057. var stock = notice.orderItem.product.ltinstock || 0;
  5058. var de = new Date(notice.delivery);
  5059. if(stock == -1) {
  5060. de.setMonth(de.getMonth() -1);
  5061. de.setDate(25);
  5062. } else if(stock >= 0) {
  5063. de.setDate(de.getDate() - stock -1);
  5064. }
  5065. return de;
  5066. };
  5067. $scope.lockstatus = false;
  5068. // 锁定时间按钮5秒
  5069. $scope.lockClick = function() {
  5070. $scope.lockstatus = true;
  5071. $timeout(function() {
  5072. $scope.lockstatus = false;
  5073. }, 5000);
  5074. };
  5075. $scope.onReplyClick = function(notice) {
  5076. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  5077. toaster.pop('warning', '警告', '数量填写错误!');
  5078. } else if(!notice.send.code) {
  5079. toaster.pop('warning', '警告', '请填写发货单号!');
  5080. } else {
  5081. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  5082. $scope.loading = true;
  5083. PurcNotice.save({id: notice.id}, send, function(data){
  5084. $scope.loading = false;
  5085. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  5086. $state.go('sale.send_detail', {id: data.id});
  5087. }, function(response){
  5088. $scope.loading = false;
  5089. toaster.pop('error', '发货失败', response.data);
  5090. });
  5091. }
  5092. };
  5093. $scope.checkboxes = {
  5094. checked : false
  5095. };
  5096. // 点击勾选全部的复选框
  5097. $scope.checkAll = function(){
  5098. angular.forEach($scope.tableParams.data, function(item) {
  5099. if(!item.waiting)
  5100. item.$selected = $scope.checkboxes.checked;
  5101. });
  5102. };
  5103. // 点击其中一个明细的复选框
  5104. $scope.checkOne = function(order){
  5105. var result = true;
  5106. angular.forEach($scope.tableParams.data, function(item) {
  5107. if(item.$selected != true){
  5108. result = false;
  5109. return;
  5110. }
  5111. });
  5112. $scope.checkboxes.checked = result;
  5113. };
  5114. $scope.sendByBatch = function(){
  5115. var modalInstance = $modal.open({
  5116. animation: true,
  5117. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  5118. controller: 'SaleNoticeSendByBatchCtrl',
  5119. size: 'lg',
  5120. resolve: {
  5121. selectedNotices: function(){return $scope.tableParams.data;}
  5122. }
  5123. });
  5124. modalInstance.result.then(function(){
  5125. $scope.tableParams.reload();
  5126. }, function(){
  5127. });
  5128. };
  5129. $scope.getSends = function(notice){
  5130. if( ! notice.sends && notice.endQty > 0){
  5131. notice.getSendsing = true;
  5132. notice.getSendsError = false;
  5133. PurcNotice.getSends({id: notice.id}, function(data){
  5134. notice.getSendsing = false;
  5135. notice.getSendsError = false;
  5136. notice.sends = data;
  5137. }, function(response){
  5138. notice.getSendsing = false;
  5139. notice.getSendsError = true;
  5140. });
  5141. }
  5142. };
  5143. // 搜索框回车
  5144. $scope.onSearch = function() {
  5145. $scope.tableParams.page(1);
  5146. $scope.tableParams.reload();
  5147. };
  5148. // 选择查找日期
  5149. $scope.onDateCondition = function(){
  5150. $scope.tableParams.page(1);
  5151. $scope.tableParams.reload();
  5152. };
  5153. //货车功能
  5154. var truck = $rootScope.truck;
  5155. if(!truck) {
  5156. SaleTruck.query({}, function(data){
  5157. $rootScope.truck = data;
  5158. });
  5159. }
  5160. $scope.isInTruck = function(noticeId) {
  5161. return truck.indexOf(noticeId) > -1;
  5162. };
  5163. $scope.addtoTruck = function(notice) {
  5164. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  5165. $rootScope.truck = data;
  5166. });
  5167. };
  5168. $scope.delFromTruck = function(notice) {
  5169. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  5170. $rootScope.truck = data;
  5171. });
  5172. };
  5173. $scope.$watch(function(){
  5174. return $rootScope.truck;
  5175. }, function(data) {
  5176. truck = $rootScope.truck;
  5177. }, true);
  5178. $scope.$watch(function(){
  5179. return $rootScope.dataChanged;
  5180. }, function(data) {
  5181. data && ($scope.tableParams.reload());
  5182. }, true);
  5183. }]);
  5184. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  5185. $scope.notices = angular.copy(selectedNotices);
  5186. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5187. $scope.saleSend = {
  5188. code: '',
  5189. payments: '',
  5190. currency: '',
  5191. custUU: null,
  5192. custUserUU: null,
  5193. remark: '批量发货',
  5194. sendItems: []
  5195. };
  5196. // 计算总数、总额
  5197. $scope.$watch(function(){
  5198. return $scope.notices;
  5199. }, function(data) {
  5200. var q = 0, t = 0;
  5201. if(data) {
  5202. angular.forEach(data,function(d){
  5203. q += (d.thisSendQty || 0);
  5204. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  5205. });
  5206. }
  5207. $scope.totalQty = q;
  5208. $scope.total = t;
  5209. }, true);
  5210. /**
  5211. * 删除一个已选中的送货提醒
  5212. */
  5213. $scope.removeOne = function(index) {
  5214. $scope.notices.splice(index, 1);
  5215. };
  5216. //确认送货
  5217. $scope.sendByBatch = function () {
  5218. $scope.saleSend.sendItems = [];
  5219. if($scope.saleSend.code == '') {//送货单号为空
  5220. toaster.pop('error', '错误', '请输入送货单号');
  5221. return;
  5222. }
  5223. var a = 0;
  5224. var num = 1;
  5225. var valid = true;
  5226. angular.forEach($scope.notices, function(item, key){
  5227. if(item.$selected) {
  5228. if(a == 0) {//第一次
  5229. $scope.saleSend.currency = item.orderItem.order.currency;
  5230. $scope.saleSend.custUU = item.enUU;
  5231. $scope.saleSend.payments = item.orderItem.order.payments;
  5232. a = 1;
  5233. } else {//其他
  5234. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  5235. if($scope.saleSend.custUU != item.enUU) valid = false;
  5236. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  5237. }
  5238. $scope.saleSend.sendItems.push({
  5239. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  5240. });
  5241. }
  5242. });
  5243. if(!valid) {
  5244. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  5245. } else {
  5246. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  5247. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  5248. $modalInstance.close('success');
  5249. $state.go('sale.send_detail', {id: data.id});
  5250. }, function(response){
  5251. toaster.pop('error', '错误', response.data);
  5252. });
  5253. }
  5254. };
  5255. $scope.cancel = function () {
  5256. $modalInstance.dismiss();
  5257. };
  5258. }]);
  5259. /**
  5260. * 发货单
  5261. */
  5262. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol' , 'ReportService', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService){
  5263. BaseService.scrollBackToTop();
  5264. $scope.active = 'all';
  5265. $scope.currency = Symbol.currency;
  5266. $scope.dateZoneText = '不限';
  5267. $scope.condition = {dateZone: 1};
  5268. /* 时间筛选初始化*/
  5269. var fromDate = new Date();
  5270. var toDate = new Date();
  5271. fromDate.setMonth(fromDate.getMonth() - 1);
  5272. fromDate.setHours(0,0,0,0);
  5273. toDate.setHours(23,59,59,999);
  5274. $scope.condition.dateFrom = fromDate;
  5275. $scope.condition.dateTo = toDate;
  5276. $scope.changeDateZone = function(zone) {
  5277. $scope.condition.dateZone = zone;
  5278. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5279. $scope.condition.$dateZoneOpen = false;
  5280. getDateCondition(zone, $scope.condition);
  5281. $scope.tableParams.page(1);
  5282. $scope.tableParams.reload();
  5283. };
  5284. $scope.setActive = function(state) {
  5285. if($scope.active != state) {
  5286. $scope.active = state;
  5287. if($scope.tableParams.page() == 1)
  5288. $scope.tableParams.reload();
  5289. else
  5290. $scope.tableParams.page(1);
  5291. }
  5292. };
  5293. var getService = function() {
  5294. return SaleSend;
  5295. };
  5296. $scope.tableParams = new ngTableParams({
  5297. page : 1,
  5298. count : 20,
  5299. sorting: {
  5300. date: 'desc'
  5301. }
  5302. }, {
  5303. total : 0,
  5304. counts: [5, 10, 25, 50],
  5305. getData : function($defer, params) {
  5306. $scope.loading = true;
  5307. var pageParams = params.url();
  5308. pageParams.keyword = $scope.keyword;
  5309. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5310. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5311. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5312. $scope.loading = false;
  5313. if(page) {
  5314. params.total(page.totalElement);
  5315. $defer.resolve(page.content);
  5316. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5317. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5318. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5319. }
  5320. }, function(response){
  5321. $scope.loading = false;
  5322. toaster.pop('error', '数据加载失败', response.data);
  5323. });
  5324. }
  5325. });
  5326. //打印 发货单
  5327. $scope.print = function(send) {
  5328. SaleSend.printCount({id: send.id},{}); //增加打印此次
  5329. $scope.tableParams.reload();
  5330. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id);
  5331. };
  5332. $scope.openDatePicker = function($event, item, openParam) {
  5333. $event.preventDefault();
  5334. $event.stopPropagation();
  5335. item[openParam] = !item[openParam];
  5336. };
  5337. $scope.openFilterDatePicker = function($event, item, openParam) {
  5338. $event.preventDefault();
  5339. $event.stopPropagation();
  5340. item[openParam] = !item[openParam];
  5341. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  5342. $scope.tableParams.reload();
  5343. }
  5344. };
  5345. // 搜索框回车
  5346. $scope.onSearch = function() {
  5347. $scope.tableParams.page(1);
  5348. $scope.tableParams.reload();
  5349. };
  5350. // 选择查找日期
  5351. $scope.onDateCondition = function(){
  5352. $scope.tableParams.page(1);
  5353. $scope.tableParams.reload();
  5354. };
  5355. }]);
  5356. /**
  5357. * 发货单(包括发货条码维护)
  5358. */
  5359. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  5360. var loading = true;
  5361. $scope.checkBarCode = [];
  5362. $scope.checkBoxCode = [];
  5363. var vm = $scope.vm = {};
  5364. $scope.getCheckedItems = {};
  5365. vm.editBar = false;
  5366. vm.showBarCode = [];
  5367. $scope.barCode = function() {
  5368. vm.editBar = !vm.editBar;
  5369. }
  5370. $scope.checkboxes = {
  5371. checked : false
  5372. };
  5373. $scope.checkbars = {
  5374. checked : false
  5375. };
  5376. // 点击勾选barCode全部的复选框
  5377. $scope.checkBarAll = function(){
  5378. angular.forEach($scope.checkBarCode, function(item,key) {
  5379. $scope.checkBarCode[key] = $scope.checkbars.checked;
  5380. });
  5381. };
  5382. //点击barCode单选
  5383. $scope.checkBarOne = function() {
  5384. var result = true;
  5385. angular.forEach($scope.checkBarCode, function(item,key) {
  5386. if(item != true){
  5387. result = false;
  5388. return;
  5389. }
  5390. });
  5391. $scope.checkbars.checked = result;
  5392. }
  5393. // 点击boxCode全部的复选框
  5394. $scope.checkBoxAll = function(){
  5395. angular.forEach($scope.checkBoxCode, function(item,key) {
  5396. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  5397. });
  5398. };
  5399. //点击boxCode单选
  5400. $scope.checkBoxOne = function() {
  5401. var result = true;
  5402. angular.forEach($scope.checkBoxCode, function(item) {
  5403. if(item != true){
  5404. result = false;
  5405. return;
  5406. }
  5407. });
  5408. $scope.checkboxes.checked = result;
  5409. }
  5410. /**
  5411. * 生成条码和箱号
  5412. */
  5413. $scope.generateBarCode = function(item) {
  5414. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  5415. $scope.getCheckedItems = [];
  5416. var warningdata = '';
  5417. angular.forEach($scope.checkBarCode, function(item,key) {
  5418. $scope.getCheckedItem = {};
  5419. if(item == true ){
  5420. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  5421. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  5422. $scope.getCheckedItems.push($scope.getCheckedItem);
  5423. //判断是否生成过条码
  5424. if($scope.order.sendItems[key].barSendNotify.length > 0){
  5425. warningdata += $scope.order.sendItems[key].number+","
  5426. }
  5427. }
  5428. });
  5429. if($scope.getCheckedItems.length == 0){
  5430. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  5431. return;
  5432. }
  5433. if(warningdata != ''){
  5434. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  5435. return ;
  5436. }
  5437. }
  5438. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  5439. toaster.pop('success', '提示','生成成功!');
  5440. loadData();
  5441. },function(response){
  5442. $scope.loading = false;
  5443. toaster.pop('error', '生成失败', response.data);
  5444. });
  5445. }
  5446. /**
  5447. * 打印条码和箱号
  5448. */
  5449. $scope.printCode = function(type) {
  5450. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  5451. //勾选需要打印的行
  5452. $scope.getCheckedItems = [];
  5453. var warningdata = ''
  5454. angular.forEach($scope.checkBarCode, function(item,key) {
  5455. $scope.getCheckedItem = {};
  5456. if(item == true ){
  5457. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  5458. $scope.getCheckedItems.push($scope.getCheckedItem);
  5459. //判断是否生成过条码
  5460. if($scope.order.sendItems[key].barSendNotify.length > 0){
  5461. warningdata += $scope.order.sendItems[key].number+","
  5462. }
  5463. }
  5464. });
  5465. if($scope.getCheckedItems.length == 0){
  5466. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  5467. return;
  5468. }
  5469. if(warningdata == ''){
  5470. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  5471. return;
  5472. }
  5473. //选择打印模板
  5474. var modalInstance = $modal.open({
  5475. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  5476. controller: 'BarPrintModalCtrl',
  5477. resolve: {
  5478. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  5479. }
  5480. });
  5481. modalInstance.result.then(function(s){
  5482. if(s) {
  5483. //获取打印数据
  5484. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  5485. if(s.type == 'print'){//判断选择是打印还是打印预览
  5486. lodopPrint(data.message,LODOP,type);
  5487. }else if(s.type == 'printPreview'){
  5488. lodopPrintPreview(data.message,LODOP,type);
  5489. }
  5490. },function(response){
  5491. toaster.pop('error', '获取打印数据失败', response.data);
  5492. });
  5493. }
  5494. });
  5495. };
  5496. //打印单个条码
  5497. $scope.printSingleCode = function(id){
  5498. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  5499. //选择打印模板
  5500. var modalInstance = $modal.open({
  5501. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  5502. controller: 'BarPrintModalCtrl',
  5503. resolve: {
  5504. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  5505. }
  5506. });
  5507. modalInstance.result.then(function(s){
  5508. if(s) {
  5509. //获取打印数据
  5510. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  5511. if(s.type == 'print'){//判断选择是打印还是打印预览
  5512. lodopSPrint(data.message,LODOP);
  5513. }else if(s.type == 'printPreview'){
  5514. lodopSPrintPreview(data.message,LODOP);
  5515. }
  5516. },function(response){
  5517. toaster.pop('error', '获取打印数据失败', response.data);
  5518. });
  5519. }
  5520. });
  5521. }
  5522. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  5523. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5524. if (selectOrNot != -1) {
  5525. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5526. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5527. var strs = pagesize.split("*"); //字符分割
  5528. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5529. angular.forEach(printStore, function(data, index) {
  5530. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5531. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5532. if (data['LP_VALUETYPE'] == 'barcode') {
  5533. 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']);
  5534. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5535. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5536. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5537. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5538. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5539. } else if (data['LP_VALUETYPE'] == 'text') {
  5540. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5541. }
  5542. });
  5543. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5544. LODOP.PRINT();
  5545. }
  5546. };
  5547. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  5548. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5549. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  5550. var strs = pagesize.split("*"); //字符分割
  5551. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5552. angular.forEach(printStore,function(data,index){
  5553. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5554. if(data['LP_VALUETYPE'] == 'barcode'){
  5555. 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']);
  5556. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5557. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5558. }else if(data['LP_VALUETYPE'] == 'text'){
  5559. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5560. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5561. }
  5562. });
  5563. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5564. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5565. LODOP.PREVIEW();//打印预览
  5566. };
  5567. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  5568. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  5569. if (selectOrNot != -1) {
  5570. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  5571. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  5572. var strs= new Array(); //定义一数组
  5573. strs = pagesize.split("*"); //字符分割
  5574. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5575. var ids = new Array();
  5576. angular.forEach(printStore, function(value,key) {
  5577. //LODOP.NewPage();
  5578. angular.forEach(value['data'], function(record,key) {
  5579. angular.forEach(record['store'], function(data, index) {
  5580. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  5581. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5582. if (data['LP_VALUETYPE'] == 'barcode') {
  5583. 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']);
  5584. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  5585. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  5586. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  5587. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  5588. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  5589. } else if (data['LP_VALUETYPE'] == 'text') {
  5590. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  5591. }
  5592. });
  5593. });
  5594. var o = new Object();
  5595. o['id'] = record['si_id']
  5596. ids.push(o);
  5597. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  5598. LODOP.PRINT();
  5599. });
  5600. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5601. if(type == 'Bar'){
  5602. //更新打印状态
  5603. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  5604. }
  5605. }
  5606. };
  5607. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  5608. var ids = new Array();
  5609. angular.forEach(printData, function(record, index){
  5610. angular.forEach(record['data'],function(value,index){
  5611. LODOP.NewPage();
  5612. angular.forEach(value['store'],function(data,index){
  5613. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  5614. if(data['LP_VALUETYPE'] == 'barcode'){
  5615. 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']);
  5616. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  5617. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  5618. }else if(data['LP_VALUETYPE'] == 'text'){
  5619. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  5620. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  5621. }
  5622. });
  5623. });
  5624. var o = new Object();
  5625. o['id'] = record['si_id']
  5626. ids.push(o);
  5627. });
  5628. var pagesize = printData[0]['pagesize'];//获取标签的大小
  5629. var strs= new Array(); //定义一数组
  5630. strs = pagesize.split("*"); //字符分割
  5631. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  5632. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  5633. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  5634. var times = LODOP.PREVIEW();//打印预览
  5635. if(times > 0){//点击了打印预览内的打印按钮
  5636. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  5637. if(type == 'Bar'){
  5638. //更新打印状态
  5639. SaleSend.updatePrintStatus({},ids,function(data){
  5640. loadData();
  5641. },function(res){});
  5642. }
  5643. }
  5644. };
  5645. /**
  5646. * 查看条码按钮
  5647. */
  5648. $scope.showBarCode = function(number) {
  5649. $scope.keys = number;
  5650. for(var i=0;i<vm.showBarCode.length;i++){
  5651. if(i!=number){
  5652. vm.showBarCode[i] = false;
  5653. }
  5654. }
  5655. vm.showBarCode[number] = !vm.showBarCode[number];
  5656. $scope.barcodes = [];
  5657. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  5658. var getPage = function(page, size){
  5659. if($scope.barcodes) {
  5660. var result = {};
  5661. result.totalCount = $scope.barcodes.length;
  5662. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  5663. if($scope.barcodes.length % size == 0) {
  5664. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  5665. }else {
  5666. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  5667. }
  5668. result.first = page == 1;
  5669. result.last = page == result.totalPage;
  5670. result.page = page;
  5671. result.next = page - 0 + 1;
  5672. result.pre = page - 1;
  5673. return result;
  5674. }
  5675. }
  5676. $scope.barData = getPage(1,5);
  5677. $scope.first = function (){
  5678. $scope.barData = getPage($scope.barData.pre,5);
  5679. }
  5680. $scope.last = function (){
  5681. $scope.barData = getPage($scope.barData.next,5);
  5682. }
  5683. };
  5684. /**
  5685. * 更新外箱号
  5686. */
  5687. $scope.updateOutBox = function(item,number) {
  5688. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  5689. }else {
  5690. if(item.outBoxQty > 0) {
  5691. if(!(item.outBoxQty % item.packageQty)) {
  5692. SaleSend.update({id:item.id},item,function(){
  5693. toaster.pop('success', '提示','保存成功!');
  5694. loadData();
  5695. }, function(response){
  5696. $scope.loading = false;
  5697. toaster.pop('error', '回复失败', response.data);
  5698. })
  5699. }else {
  5700. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  5701. }
  5702. }else {
  5703. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  5704. }
  5705. }
  5706. loadData();
  5707. };
  5708. /**
  5709. * 更新最小包数
  5710. */
  5711. $scope.updatePackage = function(item, number) {
  5712. if(item.packageQty == $scope.oldpackageQty[number]) {
  5713. }else {
  5714. if(item.orderItem.product.minPack != 0) {
  5715. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5716. if(!(item.packageQty % item.orderItem.product.minPack)) {
  5717. SaleSend.update({id:item.id},item,function(){
  5718. toaster.pop('success', '提示','保存成功!');
  5719. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5720. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5721. }
  5722. loadData();
  5723. }, function(response){
  5724. $scope.loading = false;
  5725. toaster.pop('error', '回复失败', response.data);
  5726. })
  5727. }else {
  5728. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  5729. }
  5730. }else {
  5731. toaster.pop('warning', '提示', '请填写有效的数量!');
  5732. }
  5733. }else {
  5734. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  5735. SaleSend.update({id:item.id},item,function(){
  5736. toaster.pop('success', '提示','保存成功!');
  5737. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  5738. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  5739. }
  5740. loadData();
  5741. }, function(response){
  5742. $scope.loading = false;
  5743. toaster.pop('error', '回复失败', response.data);
  5744. })
  5745. }else {
  5746. toaster.pop('warning', '提示', '请填写有效的数量!');
  5747. }
  5748. }
  5749. }
  5750. loadData();
  5751. };
  5752. var loadData = function() {
  5753. SaleSend.get({id: $stateParams.id}, function(data){
  5754. $scope.order = data;
  5755. var orderCount = $scope.order.sendItems.length;
  5756. $scope.oldpackageQty = [];
  5757. $scope.oldoutBoxQty = [];
  5758. var sum = 0;
  5759. vm.oldpackageQty = [];
  5760. angular.forEach(data.sendItems, function(value, key){
  5761. //给showBarCode数组赋初值
  5762. if (vm.showBarCode.length < orderCount){
  5763. vm.showBarCode.push(false);
  5764. }
  5765. if($scope.checkBarCode.length < orderCount) {
  5766. $scope.checkBarCode.push(false);
  5767. }
  5768. if($scope.checkBoxCode.length < orderCount) {
  5769. $scope.checkBoxCode.push(false);
  5770. }
  5771. //给个初值
  5772. if(!value.packageQty) {
  5773. value.packageQty = value.orderItem.product.minPack;
  5774. }
  5775. $scope.oldpackageQty.push(value.packageQty);
  5776. if(value.outBoxQty) {
  5777. $scope.oldoutBoxQty.push(value.outBoxQty);
  5778. }
  5779. sum += value.price * value.qty;
  5780. });
  5781. data.total = sum;
  5782. $scope.loading = false;
  5783. }, function(response){
  5784. loading = false;
  5785. toaster.pop('error', '获取数据失败', response.data);
  5786. });
  5787. };
  5788. loadData();
  5789. }]);
  5790. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  5791. $scope.typeItem = typeItem;
  5792. $scope.template = [];
  5793. $scope.choose = {};
  5794. //获取打印模板
  5795. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  5796. if(data.message){
  5797. $scope.template = data.message;
  5798. $scope.choose.tp_id = $scope.template[0].id;
  5799. }
  5800. },function(res){
  5801. toaster.pop('error', '获取模板错误', res.data);
  5802. });
  5803. $scope.print = function(){
  5804. $scope.choose.type = 'print';
  5805. $modalInstance.close($scope.choose);
  5806. };
  5807. $scope.printPreview = function(){
  5808. $scope.choose.type = 'printPreview';
  5809. $modalInstance.close($scope.choose);
  5810. }
  5811. $scope.cancel = function(){
  5812. $modalInstance.close();
  5813. }
  5814. }]);
  5815. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', function($scope, $stateParams, PurcSample, toaster, $modal, BaseService){
  5816. BaseService.scrollBackToTop();
  5817. var loading = true;
  5818. var loadData = function() {
  5819. PurcSample.get({id: $stateParams.id}, function(data){
  5820. $scope.sample = data;
  5821. if(!$scope.sample.sends){
  5822. $scope.sample.getSendInfo = '加载中...';
  5823. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  5824. if(sendData) {
  5825. $scope.sample.getSendInfo = null;
  5826. $scope.sample.sends = sendData;
  5827. } else {
  5828. $scope.sample.getSendInfo = '无送样信息';
  5829. $scope.sample.sends = '无送样信息';
  5830. }
  5831. }, function(response){
  5832. $scope.sample.getSendInfo = '加载失败!';
  5833. });
  5834. }
  5835. $scope.loading = false;
  5836. }, function(response){
  5837. loading = false;
  5838. toaster.pop('error', '获取数据失败', response.data);
  5839. });
  5840. };
  5841. loadData();
  5842. $scope.openSend = function(index, sample) {
  5843. var modalInstance = $modal.open({
  5844. animation: true,
  5845. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5846. controller: 'SampleSendCtrl',
  5847. resolve: {
  5848. sampleItem: function(){return sample;}
  5849. }
  5850. });
  5851. modalInstance.result.then(function(){
  5852. toaster.pop('info', '提示', '送样成功');
  5853. $scope.tableParams.reload();
  5854. }, function(){
  5855. });
  5856. };
  5857. }]);
  5858. /**
  5859. * 客户打样申请
  5860. */
  5861. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', '$rootScope', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol, $rootScope){
  5862. BaseService.scrollBackToTop();
  5863. if($rootScope.active) {
  5864. $scope.active = $rootScope.active;
  5865. $rootScope.active = null;
  5866. } else {
  5867. $scope.active = 'todo';
  5868. }
  5869. $scope.agreedText = '全部';
  5870. $scope.dateZoneText = '一个月内';
  5871. $scope.condition = {dateZone: 1};
  5872. /*初始化筛选时间*/
  5873. var fromDate = new Date();
  5874. var toDate = new Date();
  5875. fromDate.setMonth(fromDate.getMonth() - 1);
  5876. fromDate.setHours(0,0,0,0);
  5877. toDate.setHours(23,59,59,999);
  5878. $scope.condition.dateFrom = fromDate;
  5879. $scope.condition.dateTo = toDate;
  5880. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5881. $scope.changeAgreed = function(agreed) {
  5882. $scope.condition.agreed = agreed;
  5883. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5884. $scope.condition.$agreedOpen = false;
  5885. };
  5886. $scope.changeDateZone = function(zone) {
  5887. $scope.condition.dateZone = zone;
  5888. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5889. $scope.condition.$dateZoneOpen = false;
  5890. getDateCondition(zone, $scope.condition);
  5891. $scope.tableParams.page(1);
  5892. $scope.tableParams.reload();
  5893. };
  5894. $scope.setActive = function(state) {
  5895. if($scope.active != state) {
  5896. $scope.active = state;
  5897. if($scope.tableParams.page() == 1)
  5898. $scope.tableParams.reload();
  5899. else
  5900. $scope.tableParams.page(1);
  5901. }
  5902. };
  5903. var getService = function() {
  5904. return PurcSample;
  5905. };
  5906. $scope.tableParams = new ngTableParams({
  5907. page : 1,
  5908. count : 20,
  5909. sorting: {
  5910. proofingDate: 'desc'
  5911. }
  5912. }, {
  5913. total : 0,
  5914. counts: [5, 10, 25, 50],
  5915. getData : function($defer, params) {
  5916. $scope.loading = true;
  5917. var pageParams = params.url();
  5918. pageParams.searchFilter = {
  5919. keyword: $scope.keyword,
  5920. fromDate: getDateTime($scope.condition.dateFrom),
  5921. endDate: getDateTime($scope.condition.dateTo)
  5922. };
  5923. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5924. $scope.loading = false;
  5925. if(page) {
  5926. params.total(page.totalElement);
  5927. $defer.resolve(page.content);
  5928. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5929. // angular.forEach(page.content, function(proofing) { // 为了支持多次送样,读取列表的时候获取送样信息作为比较依据
  5930. // if( !proofing.send) {
  5931. // proofing.getSendInfo = '加载中...';
  5932. // PurcSample.getSend({id: proofing.id}, function(data){
  5933. // if(data) {
  5934. // proofing.getSendInfo = null;
  5935. // proofing.send = data;
  5936. // } else {
  5937. // proofing.getSendInfo = '无送样信息';
  5938. // proofing.send = '无送样信息';
  5939. // }
  5940. // }, function(response){
  5941. // proofing.getSendInfo = '加载失败!';
  5942. // });
  5943. // }
  5944. // });
  5945. }
  5946. }, function(response){
  5947. $scope.loading = false;
  5948. toaster.pop('error', '数据加载失败', response.data);
  5949. });
  5950. }
  5951. });
  5952. $scope.openDatePicker = function($event, item, openParam) {
  5953. $event.preventDefault();
  5954. $event.stopPropagation();
  5955. item[openParam] = !item[openParam];
  5956. };
  5957. $scope.openFilterDatePicker = function($event, item, openParam) {
  5958. $event.preventDefault();
  5959. $event.stopPropagation();
  5960. item[openParam] = !item[openParam];
  5961. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  5962. $scope.tableParams.reload();
  5963. }
  5964. };
  5965. $scope.openSend = function(index, sample) {
  5966. var modalInstance = $modal.open({
  5967. animation: true,
  5968. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5969. controller: 'SampleSendCtrl',
  5970. resolve: {
  5971. sampleItem: function(){return sample;}
  5972. }
  5973. });
  5974. modalInstance.result.then(function(){
  5975. toaster.pop('info', '提示', '送样成功');
  5976. $scope.tableParams.reload();
  5977. }, function(){
  5978. });
  5979. };
  5980. //打印 样品采购单
  5981. $scope.print = function(sample) {
  5982. PurcSample.printCount({id: sample.id},{});//增加打印此次
  5983. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  5984. };
  5985. $scope.getSend = function(proofing){
  5986. if( !proofing.sends) {
  5987. proofing.getSendInfo = '加载中...';
  5988. PurcSample.getSend({id: proofing.id}, function(data){
  5989. if(data) {
  5990. proofing.getSendInfo = null;
  5991. proofing.sends = data;
  5992. } else {
  5993. proofing.getSendInfo = '无送样信息';
  5994. proofing.sends = '无送样信息';
  5995. }
  5996. }, function(response){
  5997. proofing.getSendInfo = '加载失败!';
  5998. });
  5999. }
  6000. };
  6001. // 搜索框回车
  6002. $scope.onSearch = function() {
  6003. $scope.tableParams.page(1);
  6004. $scope.tableParams.reload();
  6005. };
  6006. }]);
  6007. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  6008. if( !sampleItem.sends) {
  6009. PurcSample.getSend({id: sampleItem.id}, function(data){
  6010. if(data) {
  6011. sampleItem.sends = data; // 获取送样信息
  6012. angular.forEach(data, function(send) {
  6013. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  6014. });
  6015. }
  6016. }, function(response){
  6017. });
  6018. }
  6019. $scope.sampleItem = sampleItem;
  6020. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  6021. //确认送样
  6022. $scope.ok = function (form) {
  6023. $scope.loading = true;
  6024. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  6025. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  6026. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  6027. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  6028. $upload.upload({
  6029. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  6030. method: 'POST',
  6031. file: file,
  6032. data: {
  6033. json: $scope.sampleItem.sampleSend
  6034. }
  6035. }).success(function(data){
  6036. $scope.loading = false;
  6037. $modalInstance.close('success');
  6038. }).error(function(data){
  6039. $scope.loading = false;
  6040. toaster.pop('danger', '错误', data);
  6041. });
  6042. };
  6043. $scope.cancel = function () {
  6044. $modalInstance.dismiss(sampleItem);
  6045. };
  6046. }]);
  6047. /**
  6048. * 客户认定单
  6049. */
  6050. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  6051. BaseService.scrollBackToTop();
  6052. $scope.active = 'all';
  6053. $scope.agreedText = '全部';
  6054. $scope.dateZoneText = '一个月内';
  6055. $scope.condition = {dateZone: 1};
  6056. /* 时间筛选初始化*/
  6057. var fromDate = new Date();
  6058. var toDate = new Date();
  6059. fromDate.setMonth(fromDate.getMonth() - 1);
  6060. fromDate.setHours(0,0,0,0);
  6061. toDate.setHours(23,59,59,999);
  6062. $scope.condition.dateFrom = fromDate;
  6063. $scope.condition.dateTo = toDate;
  6064. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6065. $scope.changeDateZone = function(zone) {
  6066. $scope.condition.dateZone = zone;
  6067. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6068. $scope.condition.$dateZoneOpen = false;
  6069. getDateCondition(zone, $scope.condition);
  6070. $scope.tableParams.page(1);
  6071. $scope.tableParams.reload();
  6072. };
  6073. $scope.setActive = function(state) {
  6074. if($scope.active != state) {
  6075. $scope.active = state;
  6076. if($scope.tableParams.page() == 1)
  6077. $scope.tableParams.reload();
  6078. else
  6079. $scope.tableParams.page(1);
  6080. }
  6081. };
  6082. var getService = function() {
  6083. return PurcApproval;
  6084. };
  6085. $scope.tableParams = new ngTableParams({
  6086. page : 1,
  6087. count : 20,
  6088. sorting: {
  6089. inDate: 'desc'
  6090. }
  6091. }, {
  6092. total : 0,
  6093. counts: [5, 10, 25, 50],
  6094. getData : function($defer, params) {
  6095. $scope.loading = true;
  6096. var pageParams = params.url();
  6097. pageParams.keyword = $scope.keyword;
  6098. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6099. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6100. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6101. $scope.loading = false;
  6102. if(page) {
  6103. params.total(page.totalElement);
  6104. $defer.resolve(page.content);
  6105. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6106. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6107. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6108. }
  6109. }, function(response){
  6110. $scope.loading = false;
  6111. toaster.pop('error', '数据加载失败', response.data);
  6112. });
  6113. }
  6114. });
  6115. $scope.openDatePicker = function($event, item, openParam) {
  6116. $event.preventDefault();
  6117. $event.stopPropagation();
  6118. item[openParam] = !item[openParam];
  6119. };
  6120. $scope.openFilterDatePicker = function($event, item, openParam) {
  6121. $event.preventDefault();
  6122. $event.stopPropagation();
  6123. item[openParam] = !item[openParam];
  6124. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6125. $scope.tableParams.reload();
  6126. }
  6127. };
  6128. $scope.parseDate = function(dateStr) {
  6129. if(dateStr)
  6130. return Date.parse(dateStr, 'yyyy-MM-dd');
  6131. return new Date();
  6132. };
  6133. // 搜索框回车
  6134. $scope.onSearch = function() {
  6135. $scope.tableParams.page(1);
  6136. $scope.tableParams.reload();
  6137. };
  6138. // 选择查找日期
  6139. $scope.onDateCondition = function(){
  6140. $scope.tableParams.page(1);
  6141. $scope.tableParams.reload();
  6142. };
  6143. }]);
  6144. /**
  6145. * 客户采购预测
  6146. */
  6147. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  6148. BaseService.scrollBackToTop();
  6149. $scope.active = 'all';
  6150. $scope.agreedText = '全部';
  6151. $scope.dateZoneText = '一个月内';
  6152. $scope.condition = {dateZone: 1};
  6153. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6154. $scope.changeAgreed = function(agreed) {
  6155. $scope.condition.agreed = agreed;
  6156. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6157. $scope.condition.$agreedOpen = false;
  6158. };
  6159. $scope.changeDateZone = function(zone) {
  6160. $scope.condition.dateZone = zone;
  6161. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  6162. $scope.condition.$dateZoneOpen = false;
  6163. };
  6164. $scope.setActive = function(state) {
  6165. if($scope.active != state) {
  6166. $scope.active = state;
  6167. if($scope.tableParams.page() == 1)
  6168. $scope.tableParams.reload();
  6169. else
  6170. $scope.tableParams.page(1);
  6171. }
  6172. };
  6173. var getService = function() {
  6174. return PurcForecast;
  6175. };
  6176. $scope.tableParams = new ngTableParams({
  6177. page : 1,
  6178. count : 20,
  6179. sorting: {
  6180. orderDate: 'desc'
  6181. }
  6182. }, {
  6183. total : 0,
  6184. counts: [5, 10, 25, 50],
  6185. getData : function($defer, params) {
  6186. $scope.loading = true;
  6187. var pageParams = params.url();
  6188. pageParams.keyword = $scope.keyword;
  6189. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6190. $scope.loading = false;
  6191. if(page) {
  6192. params.total(page.totalElement);
  6193. $defer.resolve(page.content);
  6194. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6195. }
  6196. }, function(response){
  6197. $scope.loading = false;
  6198. toaster.pop('error', '数据加载失败', response.data);
  6199. });
  6200. }
  6201. });
  6202. $scope.openDatePicker = function($event, item, openParam) {
  6203. $event.preventDefault();
  6204. $event.stopPropagation();
  6205. item[openParam] = !item[openParam];
  6206. };
  6207. // 搜索框回车
  6208. $scope.onSearch = function() {
  6209. $scope.tableParams.page(1);
  6210. $scope.tableParams.reload();
  6211. };
  6212. }]);
  6213. /**
  6214. * 客户采购验收
  6215. */
  6216. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  6217. BaseService.scrollBackToTop();
  6218. $scope.active = 'all';
  6219. $scope.dateZoneText = '不限';
  6220. $scope.deliveryZoneText = '不限';
  6221. $scope.condition = {dateZone: 1, deliveryZone: -1};
  6222. /* 时间筛选初始化*/
  6223. var fromDate = new Date();
  6224. var toDate = new Date();
  6225. fromDate.setMonth(fromDate.getMonth() - 1);
  6226. fromDate.setHours(0,0,0,0);
  6227. toDate.setHours(23,59,59,999);
  6228. $scope.condition.dateFrom = fromDate;
  6229. $scope.condition.dateTo = toDate;
  6230. $scope.changeDateZone = function(zone) {
  6231. $scope.condition.dateZone = zone;
  6232. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6233. $scope.condition.$dateZoneOpen = false;
  6234. getDateCondition(zone, $scope.condition);
  6235. $scope.tableParams.page(1);
  6236. $scope.tableParams.reload();
  6237. };
  6238. $scope.changeDeliveryZone = function(zone) {
  6239. $scope.condition.deliveryZoneText = zone;
  6240. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  6241. $scope.condition.$delievryZoneOpen = false;
  6242. getDelveryCondition(zone, $scope.condition);
  6243. $scope.tableParams.reload();
  6244. };
  6245. $scope.setActive = function(state) {
  6246. if($scope.active != state) {
  6247. $scope.active = state;
  6248. if($scope.tableParams.page() == 1)
  6249. $scope.tableParams.reload();
  6250. else
  6251. $scope.tableParams.page(1);
  6252. }
  6253. };
  6254. var getService = function() {
  6255. return PurcAccept;
  6256. };
  6257. $scope.tableParams = new ngTableParams({
  6258. page : 1,
  6259. count : 20,
  6260. sorting: {
  6261. date: 'desc'
  6262. }
  6263. }, {
  6264. total : 0,
  6265. counts: [5, 10, 25, 50],
  6266. getData : function($defer, params) {
  6267. $scope.loading = true;
  6268. var pageParams = params.url();
  6269. pageParams.searchFilter = { // 筛选条件
  6270. keyword: $scope.keyword,
  6271. fromDate: getDateTime($scope.condition.dateFrom),
  6272. endDate: getDateTime($scope.condition.dateTo)
  6273. };
  6274. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6275. $scope.loading = false;
  6276. if(page) {
  6277. params.total(page.totalElement);
  6278. $defer.resolve(page.content);
  6279. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6280. }
  6281. }, function(response){
  6282. $scope.loading = false;
  6283. toaster.pop('error', '数据加载失败', response.data);
  6284. });
  6285. }
  6286. });
  6287. $scope.openDatePicker = function($event, item, openParam) {
  6288. $event.preventDefault();
  6289. $event.stopPropagation();
  6290. item[openParam] = !item[openParam];
  6291. };
  6292. $scope.openFilterDatePicker = function($event, item, openParam) {
  6293. $event.preventDefault();
  6294. $event.stopPropagation();
  6295. item[openParam] = !item[openParam];
  6296. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6297. $scope.tableParams.reload();
  6298. }
  6299. };
  6300. $scope.parseDate = function(dateStr) {
  6301. if(dateStr)
  6302. return Date.parse(dateStr, 'yyyy-MM-dd');
  6303. return new Date();
  6304. };
  6305. // 选择查找日期
  6306. $scope.onDateCondition = function(){
  6307. $scope.tableParams.page(1);
  6308. $scope.tableParams.reload();
  6309. };
  6310. // 搜索框回车
  6311. $scope.onSearch = function() {
  6312. $scope.tableParams.page(1);
  6313. $scope.tableParams.reload();
  6314. };
  6315. }]);
  6316. /**
  6317. * 客户采购验收详情
  6318. */
  6319. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', function($scope, PurcAccept, toaster, BaseService, $stateParams){
  6320. BaseService.scrollBackToTop();
  6321. if($stateParams.id) {
  6322. PurcAccept.getDetail({id: $stateParams.id}, {}, function(data) {
  6323. $scope.accept= data;
  6324. if($scope.accept.acceptItems != null) {
  6325. var sum = 0;
  6326. angular.forEach($scope.accept.acceptItems, function(item) {
  6327. sum += item.orderPrice * item.qty;
  6328. });
  6329. $scope.totalPrice = sum;
  6330. }
  6331. }, function(response) {
  6332. toaster.pop('error', '提示', response.data);
  6333. });
  6334. }
  6335. }]);
  6336. /**
  6337. * 客户采购验退
  6338. */
  6339. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  6340. BaseService.scrollBackToTop();
  6341. $scope.active = 'all';
  6342. $scope.agreedText = '全部';
  6343. $scope.dateZoneText = '一个月内';
  6344. $scope.condition = {dateZone: 1};
  6345. /* 时间筛选初始化*/
  6346. var fromDate = new Date();
  6347. var toDate = new Date();
  6348. fromDate.setMonth(fromDate.getMonth() - 1);
  6349. fromDate.setHours(0,0,0,0);
  6350. toDate.setHours(23,59,59,999);
  6351. $scope.condition.dateFrom = fromDate;
  6352. $scope.condition.dateTo = toDate;
  6353. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6354. $scope.changeAgreed = function(agreed) {
  6355. $scope.condition.agreed = agreed;
  6356. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6357. $scope.condition.$agreedOpen = false;
  6358. };
  6359. $scope.changeDateZone = function(zone) {
  6360. $scope.condition.dateZone = zone;
  6361. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6362. $scope.condition.$dateZoneOpen = false;
  6363. getDateCondition(zone, $scope.condition);
  6364. $scope.tableParams.page(1);
  6365. $scope.tableParams.reload();
  6366. };
  6367. $scope.setActive = function(state) {
  6368. if($scope.active != state) {
  6369. $scope.active = state;
  6370. if($scope.tableParams.page() == 1)
  6371. $scope.tableParams.reload();
  6372. else
  6373. $scope.tableParams.page(1);
  6374. }
  6375. };
  6376. var getService = function() {
  6377. return PurcReturn;
  6378. };
  6379. $scope.tableParams = new ngTableParams({
  6380. page : 1,
  6381. count : 20,
  6382. sorting: {
  6383. date: 'desc'
  6384. }
  6385. }, {
  6386. total : 0,
  6387. counts: [5, 10, 25, 50],
  6388. getData : function($defer, params) {
  6389. $scope.loading = true;
  6390. var pageParams = params.url();
  6391. pageParams.searchFilter = {
  6392. keyword: $scope.keyword,
  6393. fromDate: getDateTime($scope.condition.dateFrom),
  6394. endDate: getDateTime($scope.condition.dateTo)
  6395. };
  6396. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6397. $scope.loading = false;
  6398. if(page) {
  6399. params.total(page.totalElement);
  6400. $defer.resolve(page.content);
  6401. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6402. angular.forEach(page.content, function(data) {
  6403. if (!data.returnItems[0].orderItem) {
  6404. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  6405. data.enName = enterprise.enName;
  6406. });
  6407. }
  6408. });
  6409. }
  6410. }, function(response){
  6411. $scope.loading = false;
  6412. toaster.pop('error', '数据加载失败', response.data);
  6413. });
  6414. }
  6415. });
  6416. $scope.openDatePicker = function($event, item, openParam) {
  6417. $event.preventDefault();
  6418. $event.stopPropagation();
  6419. item[openParam] = !item[openParam];
  6420. };
  6421. $scope.openFilterDatePicker = function($event, item, openParam) {
  6422. $event.preventDefault();
  6423. $event.stopPropagation();
  6424. item[openParam] = !item[openParam];
  6425. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6426. $scope.tableParams.reload();
  6427. }
  6428. };
  6429. // 搜索框回车
  6430. $scope.onSearch = function() {
  6431. $scope.tableParams.page(1);
  6432. $scope.tableParams.reload();
  6433. };
  6434. }]);
  6435. /**
  6436. * 客户采购验退详情
  6437. */
  6438. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', function($scope, PurcReturn, toaster, BaseService, $stateParams){
  6439. BaseService.scrollBackToTop();
  6440. if($stateParams.id != null) {
  6441. PurcReturn.getDetail({id: $stateParams.id}, {}, function(data) {
  6442. $scope.returns = data;
  6443. if($scope.returns.returnItems != null) {
  6444. var sum = 0;
  6445. angular.forEach($scope.returns.returnItems, function(item) {
  6446. sum += item.orderPrice * item.qty;
  6447. });
  6448. $scope.totalPrice = sum;
  6449. }
  6450. }, function(response) {
  6451. toaster.pop('error', '提示', response.data);
  6452. });
  6453. }
  6454. }]);
  6455. /**
  6456. * 客户不良品入库
  6457. */
  6458. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  6459. BaseService.scrollBackToTop();
  6460. $scope.active = 'all';
  6461. $scope.agreedText = '全部';
  6462. $scope.dateZoneText = '一个月内';
  6463. $scope.condition = {dateZone: 1};
  6464. /* 时间筛选初始化*/
  6465. var fromDate = new Date();
  6466. var toDate = new Date();
  6467. fromDate.setMonth(fromDate.getMonth() - 1);
  6468. fromDate.setHours(0,0,0,0);
  6469. toDate.setHours(23,59,59,999);
  6470. $scope.condition.dateFrom = fromDate;
  6471. $scope.condition.dateTo = toDate;
  6472. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6473. $scope.changeAgreed = function(agreed) {
  6474. $scope.condition.agreed = agreed;
  6475. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6476. $scope.condition.$agreedOpen = false;
  6477. };
  6478. $scope.changeDateZone = function(zone) {
  6479. $scope.condition.dateZone = zone;
  6480. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6481. $scope.condition.$dateZoneOpen = false;
  6482. getDateCondition(zone, $scope.condition);
  6483. $scope.tableParams.page(1);
  6484. $scope.tableParams.reload();
  6485. };
  6486. $scope.setActive = function(state) {
  6487. if($scope.active != state) {
  6488. $scope.active = state;
  6489. if($scope.tableParams.page() == 1)
  6490. $scope.tableParams.reload();
  6491. else
  6492. $scope.tableParams.page(1);
  6493. }
  6494. };
  6495. var getService = function() {
  6496. return PurcBadIn;
  6497. };
  6498. $scope.tableParams = new ngTableParams({
  6499. page : 1,
  6500. count : 20,
  6501. sorting: {
  6502. date: 'desc'
  6503. }
  6504. }, {
  6505. total : 0,
  6506. counts: [5, 10, 25, 50],
  6507. getData : function($defer, params) {
  6508. $scope.loading = true;
  6509. var pageParams = params.url();
  6510. pageParams.searchFilter = {
  6511. keyword: $scope.keyword,
  6512. fromDate: getDateTime($scope.condition.dateFrom),
  6513. endDate: getDateTime($scope.condition.dateTo)
  6514. };
  6515. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6516. $scope.loading = false;
  6517. if(page) {
  6518. params.total(page.totalElement);
  6519. $defer.resolve(page.content);
  6520. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6521. }
  6522. }, function(response){
  6523. $scope.loading = false;
  6524. toaster.pop('error', '数据加载失败', response.data);
  6525. });
  6526. }
  6527. });
  6528. $scope.openDatePicker = function($event, item, openParam) {
  6529. $event.preventDefault();
  6530. $event.stopPropagation();
  6531. item[openParam] = !item[openParam];
  6532. };
  6533. $scope.openFilterDatePicker = function($event, item, openParam) {
  6534. $event.preventDefault();
  6535. $event.stopPropagation();
  6536. item[openParam] = !item[openParam];
  6537. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6538. $scope.tableParams.reload();
  6539. }
  6540. };
  6541. // 搜索框回车
  6542. $scope.onSearch = function(keyword) {
  6543. $scope.keyword = keyword;
  6544. $scope.tableParams.page(1);
  6545. $scope.tableParams.reload();
  6546. };
  6547. }]);
  6548. /**
  6549. * 客户不良品出库
  6550. */
  6551. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  6552. BaseService.scrollBackToTop();
  6553. $scope.active = 'all';
  6554. $scope.agreedText = '全部';
  6555. $scope.dateZoneText = '一个月内';
  6556. $scope.condition = {dateZone: 1};
  6557. /* 时间筛选初始化*/
  6558. var fromDate = new Date();
  6559. var toDate = new Date();
  6560. fromDate.setMonth(fromDate.getMonth() - 1);
  6561. fromDate.setHours(0,0,0,0);
  6562. toDate.setHours(23,59,59,999);
  6563. $scope.condition.dateFrom = fromDate;
  6564. $scope.condition.dateTo = toDate;
  6565. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6566. $scope.changeAgreed = function(agreed) {
  6567. $scope.condition.agreed = agreed;
  6568. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6569. $scope.condition.$agreedOpen = false;
  6570. };
  6571. $scope.changeDateZone = function(zone) {
  6572. $scope.condition.dateZone = zone;
  6573. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6574. $scope.condition.$dateZoneOpen = false;
  6575. getDateCondition(zone, $scope.condition);
  6576. $scope.tableParams.page(1);
  6577. $scope.tableParams.reload();
  6578. };
  6579. $scope.setActive = function(state) {
  6580. if($scope.active != state) {
  6581. $scope.active = state;
  6582. if($scope.tableParams.page() == 1)
  6583. $scope.tableParams.reload();
  6584. else
  6585. $scope.tableParams.page(1);
  6586. }
  6587. };
  6588. var getService = function() {
  6589. return PurcBadOut;
  6590. };
  6591. $scope.tableParams = new ngTableParams({
  6592. page : 1,
  6593. count : 20,
  6594. sorting: {
  6595. date: 'desc'
  6596. }
  6597. }, {
  6598. total : 0,
  6599. counts: [5, 10, 25, 50],
  6600. getData : function($defer, params) {
  6601. $scope.loading = true;
  6602. var pageParams = params.url();
  6603. pageParams.searchFilter = {
  6604. keyword: $scope.keyword,
  6605. fromDate: getDateTime($scope.condition.dateFrom),
  6606. endDate: getDateTime($scope.condition.dateTo)
  6607. };
  6608. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6609. $scope.loading = false;
  6610. if(page) {
  6611. params.total(page.totalElement);
  6612. $defer.resolve(page.content);
  6613. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6614. }
  6615. }, function(response){
  6616. $scope.loading = false;
  6617. toaster.pop('error', '数据加载失败', response.data);
  6618. });
  6619. }
  6620. });
  6621. $scope.openDatePicker = function($event, item, openParam) {
  6622. $event.preventDefault();
  6623. $event.stopPropagation();
  6624. item[openParam] = !item[openParam];
  6625. };
  6626. $scope.openFilterDatePicker = function($event, item, openParam) {
  6627. $event.preventDefault();
  6628. $event.stopPropagation();
  6629. item[openParam] = !item[openParam];
  6630. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6631. $scope.tableParams.reload();
  6632. }
  6633. };
  6634. // 搜索框回车
  6635. $scope.onSearch = function() {
  6636. $scope.tableParams.page(1);
  6637. $scope.tableParams.reload();
  6638. };
  6639. }]);
  6640. /**
  6641. * 客户MRB
  6642. */
  6643. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  6644. BaseService.scrollBackToTop();
  6645. $scope.active = 'all';
  6646. $scope.agreedText = '全部';
  6647. $scope.dateZoneText = '一个月内';
  6648. $scope.condition = {dateZone: 1};
  6649. /* 时间筛选初始化*/
  6650. var fromDate = new Date();
  6651. var toDate = new Date();
  6652. fromDate.setMonth(fromDate.getMonth() - 1);
  6653. fromDate.setHours(0,0,0,0);
  6654. toDate.setHours(23,59,59,999);
  6655. $scope.condition.dateFrom = fromDate;
  6656. $scope.condition.dateTo = toDate;
  6657. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6658. $scope.changeAgreed = function(agreed) {
  6659. $scope.condition.agreed = agreed;
  6660. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  6661. $scope.condition.$agreedOpen = false;
  6662. };
  6663. $scope.changeDateZone = function(zone) {
  6664. $scope.condition.dateZone = zone;
  6665. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6666. $scope.condition.$dateZoneOpen = false;
  6667. getDateCondition(zone, $scope.condition);
  6668. $scope.tableParams.page(1);
  6669. $scope.tableParams.reload();
  6670. };
  6671. $scope.setActive = function(state) {
  6672. if($scope.active != state) {
  6673. $scope.active = state;
  6674. if($scope.tableParams.page() == 1)
  6675. $scope.tableParams.reload();
  6676. else
  6677. $scope.tableParams.page(1);
  6678. }
  6679. };
  6680. var getService = function() {
  6681. return PurcMRB;
  6682. };
  6683. $scope.tableParams = new ngTableParams({
  6684. page : 1,
  6685. count : 20,
  6686. sorting: {
  6687. date: 'desc'
  6688. }
  6689. }, {
  6690. total : 0,
  6691. counts: [5, 10, 25, 50],
  6692. getData : function($defer, params) {
  6693. $scope.loading = true;
  6694. var pageParams = params.url();
  6695. pageParams.searchFilter = {
  6696. keyword: $scope.keyword,
  6697. fromDate: getDateTime($scope.condition.dateFrom),
  6698. endDate: getDateTime($scope.condition.dateTo)
  6699. };
  6700. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6701. $scope.loading = false;
  6702. if(page) {
  6703. params.total(page.totalElement);
  6704. $defer.resolve(page.content);
  6705. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6706. }
  6707. }, function(response){
  6708. $scope.loading = false;
  6709. toaster.pop('error', '数据加载失败', response.data);
  6710. });
  6711. }
  6712. });
  6713. $scope.openDatePicker = function($event, item, openParam) {
  6714. $event.preventDefault();
  6715. $event.stopPropagation();
  6716. item[openParam] = !item[openParam];
  6717. };
  6718. $scope.openFilterDatePicker = function($event, item, openParam) {
  6719. $event.preventDefault();
  6720. $event.stopPropagation();
  6721. item[openParam] = !item[openParam];
  6722. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6723. $scope.tableParams.reload();
  6724. }
  6725. };
  6726. // 搜索框回车
  6727. $scope.onSearch = function() {
  6728. $scope.tableParams.page(1);
  6729. $scope.tableParams.reload();
  6730. };
  6731. }]);
  6732. /**
  6733. * 客户应付发票
  6734. */
  6735. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  6736. BaseService.scrollBackToTop();
  6737. $scope.active = 'all';
  6738. $scope.dateZoneText = '不限';
  6739. $scope.condition = {dateZone: 1};
  6740. /* 时间筛选初始化*/
  6741. var fromDate = new Date();
  6742. var toDate = new Date();
  6743. fromDate.setMonth(fromDate.getMonth() - 1);
  6744. fromDate.setHours(0,0,0,0);
  6745. toDate.setHours(23,59,59,999);
  6746. $scope.condition.dateFrom = fromDate;
  6747. $scope.condition.dateTo = toDate;
  6748. $scope.changeDateZone = function(zone) {
  6749. $scope.condition.dateZone = zone;
  6750. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6751. $scope.condition.$dateZoneOpen = false;
  6752. getDateCondition(zone, $scope.condition);
  6753. $scope.tableParams.page(1);
  6754. $scope.tableParams.reload();
  6755. };
  6756. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6757. $scope.setActive = function(state) {
  6758. if($scope.active != state) {
  6759. $scope.active = state;
  6760. if($scope.tableParams.page() == 1)
  6761. $scope.tableParams.reload();
  6762. else
  6763. $scope.tableParams.page(1);
  6764. }
  6765. };
  6766. var getService = function() {
  6767. return FaApBill;
  6768. };
  6769. $scope.tableParams = new ngTableParams({
  6770. page : 1,
  6771. count : 20,
  6772. sorting: {
  6773. date: 'desc'
  6774. }
  6775. }, {
  6776. total : 0,
  6777. counts: [5, 10, 25, 50],
  6778. getData : function($defer, params) {
  6779. $scope.loading = true;
  6780. var pageParams = params.url();
  6781. pageParams.searchFilter = { // 筛选条件
  6782. keyword: $scope.keyword,
  6783. fromDate: getDateTime($scope.condition.dateFrom),
  6784. endDate: getDateTime($scope.condition.dateTo)
  6785. };
  6786. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6787. $scope.loading = false;
  6788. if(page) {
  6789. params.total(page.totalElement);
  6790. $defer.resolve(page.content);
  6791. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  6792. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6793. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6794. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  6795. }
  6796. }, function(response){
  6797. $scope.loading = false;
  6798. toaster.pop('error', '数据加载失败', response.data);
  6799. });
  6800. }
  6801. });
  6802. $scope.openDatePicker = function($event, item, openParam) {
  6803. $event.preventDefault();
  6804. $event.stopPropagation();
  6805. item[openParam] = !item[openParam];
  6806. };
  6807. $scope.openFilterDatePicker = function($event, item, openParam) {
  6808. $event.preventDefault();
  6809. $event.stopPropagation();
  6810. item[openParam] = !item[openParam];
  6811. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6812. $scope.tableParams.reload();
  6813. }
  6814. };
  6815. $scope.parseDate = function(dateStr) {
  6816. if(dateStr)
  6817. return Date.parse(dateStr, 'yyyy-MM-dd');
  6818. return new Date();
  6819. };
  6820. // 搜索框回车
  6821. $scope.onSearch = function() {
  6822. $scope.tableParams.page(1);
  6823. $scope.tableParams.reload();
  6824. };
  6825. // 选择查找日期
  6826. $scope.onDateCondition = function(){
  6827. $scope.tableParams.page(1);
  6828. $scope.tableParams.reload();
  6829. };
  6830. }]);
  6831. /**
  6832. * 客户应付发票详情
  6833. */
  6834. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', function($scope, $filter, FaApBill, toaster, $stateParams, BaseService){
  6835. BaseService.scrollBackToTop();
  6836. var loadData = function() {
  6837. FaApBill.get({id: $stateParams.id}, function(data){
  6838. $scope.bill = data;
  6839. console.log(data);
  6840. $scope.loading = false;
  6841. });
  6842. };
  6843. loadData(); // 初始获取单据数据
  6844. }]);
  6845. /**
  6846. * 应付对账单
  6847. */
  6848. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  6849. BaseService.scrollBackToTop();
  6850. $scope.active = 'all';
  6851. $scope.dateZoneText = '不限';
  6852. $scope.condition = {dateZone:1};
  6853. /* 时间筛选初始化*/
  6854. var fromDate = new Date();
  6855. var toDate = new Date();
  6856. fromDate.setMonth(fromDate.getMonth() - 1);
  6857. fromDate.setHours(0,0,0,0);
  6858. toDate.setHours(23,59,59,999);
  6859. $scope.condition.dateFrom = fromDate;
  6860. $scope.condition.dateTo = toDate;
  6861. $scope.changeDateZone = function(zone) {
  6862. $scope.condition.dateZone = zone;
  6863. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6864. $scope.condition.$dateZoneOpen = false;
  6865. getDateCondition(zone, $scope.condition);
  6866. $scope.tableParams.page(1);
  6867. $scope.tableParams.reload();
  6868. };
  6869. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6870. $scope.setActive = function(state) {
  6871. if($scope.active != state) {
  6872. $scope.active = state;
  6873. if($scope.tableParams.page() == 1)
  6874. $scope.tableParams.reload();
  6875. else
  6876. $scope.tableParams.page(1);
  6877. }
  6878. };
  6879. var getService = function() {
  6880. return FaArCheck;
  6881. };
  6882. $scope.tableParams = new ngTableParams({
  6883. page : 1,
  6884. count : 20,
  6885. sorting: {
  6886. date: 'desc'
  6887. }
  6888. }, {
  6889. total : 0,
  6890. counts: [5, 10, 25, 50],
  6891. getData : function($defer, params) {
  6892. $scope.loading = true;
  6893. var pageParams = params.url();
  6894. pageParams.searchFilter = {};
  6895. pageParams.searchFilter.keyword = $scope.keyword;
  6896. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6897. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6898. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  6899. $scope.loading = false;
  6900. if(page) {
  6901. params.total(page.totalElement);
  6902. $defer.resolve(page.content);
  6903. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6904. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6905. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6906. }
  6907. }, function(response){
  6908. $scope.loading = false;
  6909. toaster.pop('error', '数据加载失败', response.data);
  6910. });
  6911. }
  6912. });
  6913. $scope.openDatePicker = function($event, item, openParam) {
  6914. $event.preventDefault();
  6915. $event.stopPropagation();
  6916. item[openParam] = !item[openParam];
  6917. };
  6918. $scope.openFilterDatePicker = function($event, item, openParam) {
  6919. $event.preventDefault();
  6920. $event.stopPropagation();
  6921. item[openParam] = !item[openParam];
  6922. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  6923. $scope.tableParams.reload();
  6924. }
  6925. };
  6926. // 计算单据的商品总数
  6927. $scope.getTotalProd = function(check) {
  6928. var total = 0;
  6929. if(check.items) {
  6930. angular.forEach(check.items, function(value) {
  6931. total += value.qty;
  6932. });
  6933. }
  6934. return total;
  6935. };
  6936. // 搜索框回车
  6937. $scope.onSearch = function() {
  6938. $scope.tableParams.page(1);
  6939. $scope.tableParams.reload();
  6940. };
  6941. // 选择查找日期
  6942. $scope.onDateCondition = function(){
  6943. $scope.tableParams.page(1);
  6944. $scope.tableParams.reload();
  6945. };
  6946. }]);
  6947. // 应付对账单详情页
  6948. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  6949. BaseService.scrollBackToTop();
  6950. var loadData = function() {
  6951. FaArCheck.get({id: $stateParams.id}, function(data){
  6952. $scope.order = data;
  6953. $scope.loading = false;
  6954. });
  6955. };
  6956. loadData(); // 初始获取单据数据
  6957. $scope.onReplyClick = function(item, isAgreed) {
  6958. if(isAgreed) {// 同意确认
  6959. FaArCheck.agree({itemId: item.id}, {}, function(data){
  6960. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  6961. }, function(response){
  6962. toaster.pop('danger', '确认失败', response.data);
  6963. });
  6964. } else {// 不同意回复
  6965. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  6966. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  6967. }, function(response) {
  6968. toaster.pop('danger', '确认失败', response.data);
  6969. });
  6970. }
  6971. };
  6972. // 获取明细的回复记录
  6973. $scope.getReplies = function(item) {
  6974. if(!item.replies) {
  6975. FaArCheck.getReplies({itemId: item.id}, function(data) {
  6976. item.replies = data;
  6977. }, function(response) {
  6978. toaster.pop('danger', '获取对账记录失败', response.data);
  6979. });
  6980. }
  6981. };
  6982. }]);
  6983. //应收对账单列表
  6984. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  6985. BaseService.scrollBackToTop();
  6986. $scope.dateZoneText = '不限';
  6987. $scope.condition = {dateZone: 1};
  6988. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6989. $scope.active = 'todo';
  6990. /* 时间筛选初始化*/
  6991. var fromDate = new Date();
  6992. var toDate = new Date();
  6993. fromDate.setMonth(fromDate.getMonth() - 1);
  6994. fromDate.setHours(0,0,0,0);
  6995. toDate.setHours(23,59,59,999);
  6996. $scope.condition.dateFrom = fromDate;
  6997. $scope.condition.dateTo = toDate;
  6998. //打印 对账单
  6999. $scope.print = function(check) {
  7000. FaApCheck.printCount({id: check.id},{});//增加打印此次
  7001. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  7002. };
  7003. //状态
  7004. $scope.setActive = function (state){
  7005. if($scope.active != state) {
  7006. $scope.active = state;
  7007. if($scope.tableParams.page() == 1)
  7008. $scope.tableParams.reload();
  7009. else
  7010. $scope.tableParams.page(1);
  7011. }
  7012. };
  7013. $scope.changeDateZone = function(zone) {
  7014. $scope.condition.dateZone = zone;
  7015. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7016. $scope.condition.$dateZoneOpen = false;
  7017. getDateCondition(zone, $scope.condition);
  7018. $scope.tableParams.page(1);
  7019. $scope.tableParams.reload();
  7020. };
  7021. //获取应收对账单全部
  7022. $scope.tableParams = new ngTableParams({
  7023. page : 1,
  7024. count : 20,
  7025. sorting: {
  7026. recordDate: 'desc'
  7027. }
  7028. }, {
  7029. total : 0,
  7030. counts: [5, 10, 25, 50],
  7031. getData : function($defer, params) {
  7032. $scope.loading = true;
  7033. var pageParams = params.url();
  7034. pageParams.searchFilter = { // 筛选条件
  7035. keyword: $scope.keyword,
  7036. fromDate: getDateTime($scope.condition.dateFrom),
  7037. endDate: getDateTime($scope.condition.dateTo)
  7038. };
  7039. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  7040. $scope.loading = false;
  7041. if(page) {
  7042. params.total(page.totalElement);
  7043. $scope.data = $defer.resolve(page.content);
  7044. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  7045. }
  7046. }, function(response){
  7047. $scope.loading = false;
  7048. toaster.pop('error', '数据加载失败', response.data);
  7049. });
  7050. }
  7051. });
  7052. $scope.openDatePicker = function($event, item, openParam) {
  7053. $event.preventDefault();
  7054. $event.stopPropagation();
  7055. item[openParam] = !item[openParam];
  7056. };
  7057. $scope.openFilterDatePicker = function($event, item, openParam) {
  7058. $event.preventDefault();
  7059. $event.stopPropagation();
  7060. item[openParam] = !item[openParam];
  7061. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  7062. $scope.tableParams.reload();
  7063. }
  7064. };
  7065. // 计算单据的商品总数
  7066. $scope.getTotalProd = function(check) {
  7067. var total = 0;
  7068. if(check.items) {
  7069. angular.forEach(check.items, function(value) {
  7070. total += value.checkQty;
  7071. });
  7072. }
  7073. return total;
  7074. };
  7075. // 搜索框回车
  7076. $scope.onSearch = function() {
  7077. $scope.tableParams.page(1);
  7078. $scope.tableParams.reload();
  7079. };
  7080. // 选择查找日期
  7081. $scope.onDateCondition = function(){
  7082. $scope.tableParams.page(1);
  7083. $scope.tableParams.reload();
  7084. };
  7085. }]);
  7086. //应收对账单详情
  7087. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  7088. BaseService.scrollBackToTop();
  7089. $scope.haveSelected = true;
  7090. $scope.data = {};
  7091. //控制提交和删除按钮的显示
  7092. $scope.ifShow = true;
  7093. var loadData = function(){
  7094. FaApCheck.get({id:$stateParams.id},function(data){
  7095. $scope.data = data;
  7096. if($scope.data.status){
  7097. }else{
  7098. $scope.ifShow = true;
  7099. }
  7100. })
  7101. };
  7102. if($stateParams.id){
  7103. loadData();
  7104. }
  7105. $scope.haveSource = false;
  7106. //提交应收对账单
  7107. $scope.submitApCheck = function(){
  7108. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  7109. if(data.result) {
  7110. toaster.pop('success', '提示', '提交成功');
  7111. $scope.haveSelected = false;
  7112. window.location.href = '#/fa/apCheck';
  7113. }else {
  7114. $scope.haveSource = true;
  7115. loadData();
  7116. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  7117. $scope.haveSelected = true;
  7118. }
  7119. },function(){
  7120. $scope.loading = false;
  7121. toaster.pop('error', '提示', '更新已转数失败');
  7122. });
  7123. }
  7124. //删除应收对账单的同时更新来源表已转数
  7125. var updateYCheckQty = function(){
  7126. var sourceInfos = [];
  7127. angular.forEach($scope.data.items, function(item){
  7128. $scope.sourceInfo = {
  7129. sourceId: '',
  7130. sourceTable: '',
  7131. newYCheckQty: ''
  7132. };
  7133. $scope.sourceInfo.sourceId = item.sourceId;
  7134. $scope.sourceInfo.sourceTable = item.sourceTable;
  7135. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  7136. sourceInfos.push($scope.sourceInfo);
  7137. });
  7138. FaApCheck.update({}, sourceInfos, function(){
  7139. },function(response){
  7140. $scope.loading = false;
  7141. toaster.pop('error', '更新已转数失败', response.data);
  7142. });
  7143. }
  7144. //删除应收对账单
  7145. $scope.deleteApCheck = function(){
  7146. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  7147. updateYCheckQty();
  7148. toaster.pop('success','提示','删除成功');
  7149. },function(){
  7150. toaster.pop('error','提示','删除失败');
  7151. });
  7152. $scope.haveSelected = false;
  7153. }
  7154. //作废应收对账单
  7155. $scope.cancelApCheck = function(check) {
  7156. FaApCheck.cancel({id:check.id},function(data){
  7157. $scope.checkResult = false;
  7158. if(data.result) {
  7159. $scope.checkResult = true;
  7160. toaster.pop('success', '提示', '作废成功');
  7161. $scope.tableParams.reload();
  7162. }else{
  7163. toaster.pop('error', '提示', '作废失败');
  7164. }
  7165. },function(){
  7166. $scope.loading = false;
  7167. toaster.pop('error', '提示', '作废失败');
  7168. });
  7169. }
  7170. }]);
  7171. //未对账单据列表
  7172. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  7173. $scope.data = [];// 列表数据
  7174. $scope.condition = {
  7175. $fromOpened: false
  7176. }
  7177. $scope.openDatePicker = function($event, item, openParam) {
  7178. $event.preventDefault();
  7179. $event.stopPropagation();
  7180. item[openParam] = !item[openParam];
  7181. }
  7182. //查找客户
  7183. $scope.searchCust = function(suuorname) {
  7184. var modalInstance = $modal.open({
  7185. animation: true,
  7186. templateUrl: 'static/tpl/index/fa/custInfo.html',
  7187. controller: 'SearchCustInfoCtrl',
  7188. resolve: {
  7189. suuorname: function() {
  7190. return suuorname;
  7191. }
  7192. }
  7193. });
  7194. modalInstance.result.then(function(suuorname){
  7195. $scope.suuorname = suuorname;
  7196. });
  7197. }
  7198. // 点击筛选根据条件选择数据
  7199. $scope.suuorname = '';
  7200. // 默认本月
  7201. $scope.sdateTo = new Date();
  7202. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  7203. $scope.vuuorname = '';
  7204. $scope.factory = '';
  7205. $scope.prodTitle = '';
  7206. $scope.prodSpec = '';
  7207. $scope.condition.uuorname = '';
  7208. $scope.condition.dateFrom = '';
  7209. $scope.condition.dateTo = '';
  7210. $scope.condition.venduuorname = '';
  7211. $scope.condition.factory = '';
  7212. $scope.condition.prodTitle = '';
  7213. $scope.condition.prodSpec = '';
  7214. $scope.searchOrder = function(check) {
  7215. $scope.data = [];
  7216. $scope.checkboxes.checked = false;
  7217. $scope.totalMoney = 0;
  7218. $scope.condition.uuorname = $scope.suuorname;
  7219. $scope.condition.factory = $scope.factory
  7220. $scope.condition.prodTitle = $scope.prodTitle;
  7221. $scope.condition.prodSpec = $scope.prodSpec;
  7222. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  7223. $scope.thisdatato = ($scope.sdateTo || 0);
  7224. if($scope.thisdatato != 0) {
  7225. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  7226. } else {
  7227. $scope.condition.dateTo = ($scope.sdateTo || 0);
  7228. }
  7229. $scope.condition.venduuorname = $scope.vuuorname;
  7230. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  7231. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7232. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7233. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  7234. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  7235. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  7236. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  7237. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  7238. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7239. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7240. if(!$scope.suuorname) {
  7241. toaster.pop('warning','提示', '请先选择客户');
  7242. document.getElementById('suuorname').focus();//光标默认在客户
  7243. } else {
  7244. $scope.loading = true;
  7245. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  7246. if(data.length > 0) {
  7247. angular.forEach(data, function(item) {
  7248. item.$selected = true;
  7249. });
  7250. $scope.data = data;
  7251. $scope.checkboxes.checked = true;
  7252. $scope.getTotalMoney();
  7253. } else {
  7254. toaster.pop('info', '提示', '当前没有需要对账记录');
  7255. }
  7256. $scope.loading = false;
  7257. }, function(response) {
  7258. $scope.loading = false;
  7259. toaster.pop('error', '提示', response.data);
  7260. });
  7261. }
  7262. }
  7263. }
  7264. /**
  7265. * 点击勾选框,选中要转应收对账单的订单
  7266. * */
  7267. $scope.totalMoney = 0;
  7268. $scope.checkboxes = {
  7269. checked : false
  7270. };
  7271. // 点击勾选全部的复选框
  7272. $scope.checkAll = function(){
  7273. $scope.totalMoney = 0;
  7274. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  7275. var uuorname = $scope.suuorname;
  7276. var venduuorname = $scope.venduuorname;
  7277. var dateFrom = $scope.condition.dateFrom;
  7278. var dateTo = $scope.condition.dateTo;
  7279. var prodTitle = $scope.condition.prodTitle;
  7280. var prodSpec = $scope.condition.prodSpec;
  7281. var factory = $scope.condition.factory;
  7282. angular.forEach($scope.filteredData, function(item) {
  7283. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  7284. item.$selected = $scope.checkboxes.checked;
  7285. }
  7286. });
  7287. $scope.getTotalMoney();
  7288. };
  7289. //获取已选单据总金额
  7290. var total = true;
  7291. $scope.getTotalMoney = function(){
  7292. $scope.totalMoney = 0;
  7293. angular.forEach($scope.data, function(check) {
  7294. if(check.$selected){
  7295. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  7296. }else{
  7297. $scope.totalMoney += 0;
  7298. }
  7299. });
  7300. }
  7301. // 点击其中一个明细的复选框
  7302. $scope.checkOne = function(check){
  7303. var result = true;
  7304. angular.forEach($scope.data, function(item) {
  7305. if(item.$selected != true){
  7306. result = false;
  7307. return;
  7308. }
  7309. });
  7310. $scope.checkboxes.checked = result;
  7311. };
  7312. $scope.haveSelected = false;
  7313. //生成应收对账单
  7314. $scope.createApCheck = function(){
  7315. //保存应收对账单主记录字段
  7316. $scope.apCheck = {
  7317. custUu: '',
  7318. custName: '',
  7319. enUu: '',
  7320. apDate: '',
  7321. beginDate: '',
  7322. endDate: '',
  7323. checkStatus: '未对账',
  7324. checkAmount: 0,
  7325. currency: '',
  7326. rate: '',
  7327. items: []
  7328. };
  7329. //保存来源单据相关信息
  7330. var sourceInfos = [];
  7331. //所允许的本次对账最大最小数量
  7332. $scope.data.maxThisCheckQty = 0;
  7333. $scope.data.minThisCheckQty = 0;
  7334. $scope.sameCust = true;
  7335. $scope.validQty = true;
  7336. $scope.loading = true;
  7337. angular.forEach($scope.data, function(check) {
  7338. //保存应收对账单明细行数据
  7339. $scope.item = {
  7340. inoutno: '',
  7341. inoutnodetno: '',
  7342. orderCode: '',
  7343. orderClass: '',
  7344. orderDetno: '',
  7345. price: '',
  7346. checkQty: '',
  7347. amount: '',
  7348. sourceId:'',
  7349. sourceTable:'',
  7350. oldYCheckQty:'',
  7351. status: 0,
  7352. receiveCode:'',
  7353. receiveName:'',
  7354. prodCode:'',
  7355. prodTitle:'',
  7356. prodSpec:'',
  7357. taxrate: '',
  7358. sendcode: '',
  7359. whname: '',
  7360. };
  7361. //应收对账单明细行来源表信息
  7362. $scope.sourceInfo = {
  7363. sourceId: '',
  7364. sourceTable: '',
  7365. newYCheckQty: ''
  7366. };
  7367. //此次对账后新的已转数
  7368. $scope.newYCheckQty = 0;
  7369. if(check.$selected == true) {
  7370. $scope.apCheck.custName = check.custName;
  7371. $scope.apCheck.enUu = check.enUu;
  7372. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  7373. $scope.apCheck.apDate = check.piDate;
  7374. $scope.apCheck.rate = check.rate;
  7375. //必须是同一家客户才能生成对账单,否则提示错误
  7376. if($scope.apCheck.custUu == ''){
  7377. $scope.apCheck.custUu = check.custUu;
  7378. }else if($scope.apCheck.custUu !== check.custUu){
  7379. $scope.sameCust = false;
  7380. $scope.loading = false;
  7381. toaster.pop('error', '请选择同一家客户');
  7382. }
  7383. //必须是相同币别才能生成对账单,否则提示错误
  7384. if($scope.apCheck.currency == ''){
  7385. $scope.apCheck.currency = check.currency;
  7386. }else if($scope.apCheck.currency !== check.currency){
  7387. $scope.sameCust = false;
  7388. $scope.loading = false;
  7389. toaster.pop('error', '请选择同一种币别');
  7390. }
  7391. //本次对账数量必须小于总对账数量
  7392. if(check.qty > 0){
  7393. $scope.data.maxThisCheckQty = check.qty;
  7394. $scope.data.minThisCheckQty = 0;
  7395. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  7396. $scope.validQty = false;
  7397. $scope.loading = false;
  7398. toaster.pop('error','本次对账数量,填写有误!');
  7399. }
  7400. }else if(check.qty < 0){
  7401. $scope.data.maxThisCheckQty = 0;
  7402. $scope.data.minThisCheckQty = check.qty;
  7403. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  7404. $scope.validQty = false;
  7405. $scope.loading = false;
  7406. toaster.pop('error','本次对账数量,填写有误!');
  7407. }
  7408. }
  7409. //获取最小时间作为对账区间的起始时间
  7410. if($scope.apCheck.beginDate == ''){
  7411. $scope.apCheck.beginDate = check.piDate;
  7412. }else{
  7413. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  7414. }
  7415. //获取最大时间作为对账区间的截止时间
  7416. if($scope.apCheck.endDate == ''){
  7417. $scope.apCheck.endDate = check.piDate;
  7418. }else{
  7419. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  7420. }
  7421. //应收对账单明细行数据
  7422. $scope.item.orderCode = check.orderCode;
  7423. $scope.item.orderClass = check.piClass;
  7424. $scope.item.orderDetno = check.orderDetno;
  7425. $scope.item.price = check.orderPrice;
  7426. $scope.item.checkQty = check.thisCheckQty;
  7427. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  7428. $scope.item.sourceId = check.sourceId;
  7429. $scope.item.sourceTable = check.sourceTable;
  7430. $scope.item.oldYCheckQty = check.yCheckQty;
  7431. $scope.item.prodCode = check.prodCode;
  7432. $scope.item.prodTitle = check.prodTitle;
  7433. $scope.item.prodSpec = check.prodSpec;
  7434. $scope.item.inoutno = check.inOutNo;
  7435. $scope.item.inoutnodetno = check.detno;
  7436. $scope.item.taxrate = check.taxrate;
  7437. $scope.item.receiveCode = check.receiveCode;
  7438. $scope.item.receiveName = check.receiveName;
  7439. $scope.item.sendcode = check.sendcode;
  7440. $scope.item.whname = check.whname;
  7441. //来源表相关信息
  7442. $scope.sourceInfo.sourceId = check.sourceId;
  7443. $scope.sourceInfo.sourceTable = check.sourceTable;
  7444. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  7445. sourceInfos.push($scope.sourceInfo);
  7446. $scope.apCheck.items.push($scope.item);
  7447. $scope.haveSelected = true;
  7448. }
  7449. });
  7450. //保存生成的应收对账单
  7451. $scope.saveApCheck = function(){
  7452. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  7453. $scope.loading = false;
  7454. toaster.pop('success', '成功', '生成应收对账成功');
  7455. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  7456. }, function(response){
  7457. toaster.pop('error', '生成对账单失败', response.data);
  7458. })
  7459. };
  7460. //如果是同一家客户,生成对账单的同时,关闭模态框
  7461. if($scope.sameCust && $scope.validQty) {
  7462. $scope.saveApCheck();
  7463. }
  7464. }
  7465. }]);
  7466. //货款调账
  7467. app.controller('PurchaseAdjustListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', 'ApbillAdjustment', function($scope, FaApCheck, toaster, $state, $filter, $modal, ApbillAdjustment){
  7468. $scope.data = [];// 列表数据
  7469. $scope.condition = {
  7470. $fromOpened: false
  7471. }
  7472. $scope.openDatePicker = function($event, item, openParam) {
  7473. $event.preventDefault();
  7474. $event.stopPropagation();
  7475. item[openParam] = !item[openParam];
  7476. }
  7477. //查找客户
  7478. $scope.searchCust = function(suuorname) {
  7479. var modalInstance = $modal.open({
  7480. animation: true,
  7481. templateUrl: 'static/tpl/index/fa/custInfo.html',
  7482. controller: 'SearchCustInfoCtrl',
  7483. resolve: {
  7484. suuorname: function() {
  7485. return suuorname;
  7486. }
  7487. }
  7488. });
  7489. modalInstance.result.then(function(suuorname){
  7490. $scope.suuorname = suuorname;
  7491. });
  7492. }
  7493. // 点击筛选根据条件选择数据
  7494. $scope.suuorname = '';
  7495. // 默认本月
  7496. $scope.sdateTo = new Date();
  7497. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  7498. $scope.vuuorname = '';
  7499. $scope.factory = '';
  7500. $scope.prodTitle = '';
  7501. $scope.prodSpec = '';
  7502. $scope.condition.uuorname = '';
  7503. $scope.condition.dateFrom = '';
  7504. $scope.condition.dateTo = '';
  7505. $scope.condition.venduuorname = '';
  7506. $scope.condition.factory = '';
  7507. $scope.condition.prodTitle = '';
  7508. $scope.condition.prodSpec = '';
  7509. $scope.searchOrder = function(check) {
  7510. $scope.data = [];
  7511. $scope.checkboxes.checked = false;
  7512. $scope.totalMoney = 0;
  7513. $scope.condition.uuorname = $scope.suuorname;
  7514. $scope.condition.factory = $scope.factory
  7515. $scope.condition.prodTitle = $scope.prodTitle;
  7516. $scope.condition.prodSpec = $scope.prodSpec;
  7517. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  7518. $scope.thisdatato = ($scope.sdateTo || 0);
  7519. if($scope.thisdatato != 0) {
  7520. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  7521. } else {
  7522. $scope.condition.dateTo = ($scope.sdateTo || 0);
  7523. }
  7524. $scope.condition.venduuorname = $scope.vuuorname;
  7525. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  7526. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7527. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7528. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  7529. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  7530. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  7531. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  7532. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  7533. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7534. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7535. if(!$scope.suuorname) {
  7536. toaster.pop('warning','提示', '请先选择客户');
  7537. document.getElementById('suuorname').focus();//光标默认在客户
  7538. } else {
  7539. $scope.loading = true;
  7540. ApbillAdjustment.adjustList({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  7541. if(data.length > 0) {
  7542. angular.forEach(data, function(item) {
  7543. item.$selected = true;
  7544. });
  7545. $scope.data = data;
  7546. $scope.checkboxes.checked = true;
  7547. $scope.getTotalMoney();
  7548. } else {
  7549. toaster.pop('info', '提示', '当前没有需要对账记录');
  7550. }
  7551. $scope.loading = false;
  7552. }, function(response) {
  7553. $scope.loading = false;
  7554. toaster.pop('error', '提示', response.data);
  7555. });
  7556. }
  7557. }
  7558. }
  7559. /**
  7560. * 点击勾选框,选中要转应收对账单的订单
  7561. * */
  7562. $scope.totalMoney = 0;
  7563. $scope.checkboxes = {
  7564. checked : false
  7565. };
  7566. // 点击勾选全部的复选框
  7567. $scope.checkAll = function(){
  7568. $scope.totalMoney = 0;
  7569. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  7570. var uuorname = $scope.suuorname;
  7571. var venduuorname = $scope.venduuorname;
  7572. var dateFrom = $scope.condition.dateFrom;
  7573. var dateTo = $scope.condition.dateTo;
  7574. var prodTitle = $scope.condition.prodTitle;
  7575. var prodSpec = $scope.condition.prodSpec;
  7576. var factory = $scope.condition.factory;
  7577. angular.forEach($scope.filteredData, function(item) {
  7578. if((item.orderdate >= dateFrom || dateFrom == '') && (item.orderdate < dateTo || dateTo == '')){
  7579. item.$selected = $scope.checkboxes.checked;
  7580. }
  7581. });
  7582. $scope.getTotalMoney();
  7583. };
  7584. //获取已选单据总金额
  7585. var total = true;
  7586. $scope.getTotalMoney = function(){
  7587. $scope.totalMoney = 0;
  7588. angular.forEach($scope.data, function(check) {
  7589. if(check.$selected){
  7590. $scope.totalMoney += (check.thischeckqty || 0)*(check.orderprice || 0);
  7591. }else{
  7592. $scope.totalMoney += 0;
  7593. }
  7594. });
  7595. }
  7596. // 点击其中一个明细的复选框
  7597. $scope.checkOne = function(check){
  7598. var result = true;
  7599. angular.forEach($scope.data, function(item) {
  7600. if(item.$selected != true){
  7601. result = false;
  7602. return;
  7603. }
  7604. });
  7605. $scope.checkboxes.checked = result;
  7606. };
  7607. $scope.haveSelected = false;
  7608. //生成应收对账单
  7609. $scope.createApCheck = function(){
  7610. //保存应收对账单主记录字段
  7611. $scope.apCheck = {
  7612. custUu: '',
  7613. custName: '',
  7614. enUu: '',
  7615. apDate: '',
  7616. beginDate: '',
  7617. endDate: '',
  7618. checkStatus: '未对账',
  7619. checkAmount: 0,
  7620. currency: '',
  7621. rate: '',
  7622. items: []
  7623. };
  7624. //保存来源单据相关信息
  7625. var sourceInfos = [];
  7626. //所允许的本次对账最大最小数量
  7627. $scope.data.maxThisCheckQty = 0;
  7628. $scope.data.minThisCheckQty = 0;
  7629. $scope.sameCust = true;
  7630. $scope.validQty = true;
  7631. $scope.loading = true;
  7632. angular.forEach($scope.data, function(check) {
  7633. //保存应收对账单明细行数据
  7634. $scope.item = {
  7635. inoutno: '',
  7636. inoutnodetno: '',
  7637. orderCode: '',
  7638. orderClass: '',
  7639. orderDetno: '',
  7640. price: '',
  7641. checkQty: '',
  7642. amount: '',
  7643. sourceId:'',
  7644. sourceTable:'',
  7645. oldYCheckQty:'',
  7646. status: 0,
  7647. receiveCode:'',
  7648. receiveName:'',
  7649. prodCode:'',
  7650. prodTitle:'',
  7651. prodSpec:'',
  7652. taxrate: '',
  7653. sendcode: '',
  7654. whname: '',
  7655. };
  7656. //应收对账单明细行来源表信息
  7657. $scope.sourceInfo = {
  7658. sourceId: '',
  7659. sourceTable: '',
  7660. newYCheckQty: ''
  7661. };
  7662. //此次对账后新的已转数
  7663. $scope.newYCheckQty = 0;
  7664. if(check.$selected == true) {
  7665. $scope.apCheck.custName = check.custname;
  7666. $scope.apCheck.enUu = check.enuu;
  7667. $scope.apCheck.checkAmount += (check.thischeckqty || 0)*(check.orderprice || 0);
  7668. $scope.apCheck.apDate = check.date;
  7669. $scope.apCheck.rate = check.rate;
  7670. //必须是同一家客户才能生成对账单,否则提示错误
  7671. if($scope.apCheck.custUu == ''){
  7672. $scope.apCheck.custUu = check.custuu;
  7673. }else if($scope.apCheck.custUu !== check.custuu){
  7674. $scope.sameCust = false;
  7675. $scope.loading = false;
  7676. toaster.pop('error', '请选择同一家客户');
  7677. }
  7678. //必须是相同币别才能生成对账单,否则提示错误
  7679. if($scope.apCheck.currency == ''){
  7680. $scope.apCheck.currency = check.currency;
  7681. }else if($scope.apCheck.currency !== check.currency){
  7682. $scope.sameCust = false;
  7683. $scope.loading = false;
  7684. toaster.pop('error', '请选择同一种币别');
  7685. }
  7686. //本次对账数量必须小于总对账数量
  7687. if(check.qty > 0){
  7688. $scope.data.maxThisCheckQty = check.qty;
  7689. $scope.data.minThisCheckQty = 0;
  7690. if(check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0){
  7691. $scope.validQty = false;
  7692. $scope.loading = false;
  7693. toaster.pop('error','本次对账数量,填写有误!');
  7694. }
  7695. }else if(check.qty < 0){
  7696. $scope.data.maxThisCheckQty = 0;
  7697. $scope.data.minThisCheckQty = check.qty;
  7698. if(((-check.qty)-(-check.ycheckQty) < (-check.thischeckQty)) || check.thischeckqty > 0 || check.thischeckqty == 0){
  7699. $scope.validQty = false;
  7700. $scope.loading = false;
  7701. toaster.pop('error','本次对账数量,填写有误!');
  7702. }
  7703. }
  7704. //获取最小时间作为对账区间的起始时间
  7705. if($scope.apCheck.beginDate == ''){
  7706. $scope.apCheck.beginDate = check.date;
  7707. }else{
  7708. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.orderdate : $scope.apCheck.beginDate;
  7709. }
  7710. //获取最大时间作为对账区间的截止时间
  7711. if($scope.apCheck.endDate == ''){
  7712. $scope.apCheck.endDate = check.date;
  7713. }else{
  7714. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.orderdate : $scope.apCheck.endDate;
  7715. }
  7716. //应收对账单明细行数据
  7717. $scope.item.orderCode = check.ordercode;
  7718. $scope.item.orderClass = check.piClass;
  7719. $scope.item.orderDetno = check.orderdetno;
  7720. $scope.item.price = check.orderprice;
  7721. $scope.item.checkQty = check.thischeckqty;
  7722. $scope.item.amount = (check.thischeckqty || 0)*(check.orderprice || 0);
  7723. $scope.item.sourceId = check.id;
  7724. $scope.item.sourceTable = 'purc$apbilladjustment';
  7725. $scope.item.orderClass = '货款调账';
  7726. $scope.item.oldYCheckQty = check.ycheckqty;
  7727. $scope.item.prodCode = check.prodcode;
  7728. $scope.item.prodTitle = check.prodtitle;
  7729. $scope.item.prodSpec = check.prodspec;
  7730. $scope.item.inoutno = check.inoutno;
  7731. $scope.item.inoutnodetno = check.detno;
  7732. $scope.item.taxrate = check.taxrate;
  7733. $scope.item.receiveCode = check.receivecode;
  7734. $scope.item.receiveName = check.receivename;
  7735. $scope.item.sendcode = check.sendcode;
  7736. $scope.item.whname = check.whname;
  7737. //来源表相关信息
  7738. $scope.sourceInfo.sourceId = check.id;
  7739. $scope.sourceInfo.sourceTable = 'purc$apbilladjustment';
  7740. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  7741. sourceInfos.push($scope.sourceInfo);
  7742. $scope.apCheck.items.push($scope.item);
  7743. $scope.haveSelected = true;
  7744. }
  7745. });
  7746. //保存生成的应收对账单
  7747. $scope.saveApCheck = function(){
  7748. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  7749. $scope.loading = false;
  7750. toaster.pop('success', '成功', '生成应收对账成功');
  7751. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  7752. }, function(response){
  7753. toaster.pop('error', '生成对账单失败', response.data);
  7754. })
  7755. };
  7756. //如果是同一家客户,生成对账单的同时,关闭模态框
  7757. if($scope.sameCust && $scope.validQty) {
  7758. $scope.saveApCheck();
  7759. }
  7760. }
  7761. }]);
  7762. // 企业信息设置
  7763. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder){
  7764. BaseService.scrollBackToTop();
  7765. $scope.loading = true;
  7766. AccountEnterprise.get({}, function(data){
  7767. $scope.loading = false;
  7768. $scope.enterprise = data;
  7769. // 获取付款企业信息
  7770. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7771. $scope.pays = data;
  7772. }, function(response) {
  7773. toaster.pop('error', '提示', response.data);
  7774. });
  7775. });
  7776. AccountEnterprise.growth({}, function(data){
  7777. if(data != null && data.length > 0) {
  7778. var growth = [], years = [];
  7779. angular.forEach(data, function(d){
  7780. var date = new Date(d.date), year = date.getFullYear();
  7781. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  7782. if(years.indexOf(year) == -1) {
  7783. years.push(year);
  7784. growth.push({year: year});
  7785. }
  7786. growth.push(d);
  7787. });
  7788. $scope.growth = growth;
  7789. }
  7790. });
  7791. // 更新企业信息
  7792. $scope.updateDetailInfo = function(){
  7793. $scope.loading = true;
  7794. AccountEnterprise.save($scope.enterprise, function(){
  7795. $scope.loading = false;
  7796. $scope.connectionEditing = false;
  7797. toaster.pop('success', '提示', '修改企业信息成功');
  7798. $state.reload();
  7799. }, function(response){
  7800. $scope.loading = false;
  7801. toaster.pop('error', '修改信息失败', response.data);
  7802. });
  7803. };
  7804. // 申请Saas
  7805. $scope.applySaas = function(){
  7806. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  7807. var modalInstance = $modal.open({
  7808. animation: true,
  7809. templateUrl: 'static/tpl/index/account/applySaas.html',
  7810. controller: 'ApplySaasCtrl',
  7811. resolve: {
  7812. enterprise: function(){return angular.copy($scope.enterprise);}
  7813. }
  7814. });
  7815. modalInstance.result.then(function(){
  7816. $state.reload();
  7817. }, function(){
  7818. });
  7819. } else {
  7820. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  7821. }
  7822. };
  7823. // 获取收货地址列表
  7824. ShipAddress.shipAddList({}, function(data) {
  7825. $scope.ships = data;
  7826. });
  7827. // 判断是否是代采企业
  7828. DeputyOrder.isDeputyEnterprise({}, function(data) {
  7829. $scope.deputyEnter = data;
  7830. });
  7831. // 获取地址信息
  7832. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7833. }).then(function(response) {
  7834. $scope.provinces = response.data;
  7835. });
  7836. // 新增收货地址保存
  7837. $scope.saveShipAddress = function(ship) {
  7838. ship.address = ship.province + ship.city + ship.district;
  7839. ShipAddress.saveAddress( {}, ship, function(data) {
  7840. if(data.success) {
  7841. ShipAddress.shipAddList({}, function(data) {
  7842. $scope.ships = data;
  7843. });
  7844. toaster.pop('success', '提示', data.success);
  7845. }
  7846. if(data.error) {
  7847. toaster.pop('error', '提示', data.error);
  7848. }
  7849. });
  7850. }
  7851. // 删除收货地址
  7852. $scope.removeShip = function(id, index) {
  7853. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  7854. $scope.ships.splice(index, 1);
  7855. toaster.pop('success', '提示', '收货地址删除成功');
  7856. }, function(response) {
  7857. toaster.pop('error', '提示', response.data);
  7858. });
  7859. };
  7860. // 编辑收货地址
  7861. $scope.editShip = function(ship){
  7862. var modalInstance = $modal.open({
  7863. animation: true,
  7864. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  7865. controller: 'ShipAddressCtrl',
  7866. resolve: {
  7867. ship: function(){return ship;}
  7868. }
  7869. });
  7870. modalInstance.result.then(function() {
  7871. ShipAddress.shipAddList({}, function(data) {
  7872. $scope.ships = data;
  7873. });
  7874. }, function(){
  7875. });
  7876. };
  7877. // 新增付款企业
  7878. $scope.addPayCompany = function() {
  7879. var modalInstance = $modal.open({
  7880. animation: true,
  7881. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7882. controller: 'PayCompanyCtrl',
  7883. resolve: {
  7884. pay: function(){return null;}
  7885. }
  7886. });
  7887. modalInstance.result.then(function() {
  7888. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7889. $scope.pays = data;
  7890. // 获取付款企业信息
  7891. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function(data) {
  7892. $scope.pays = data;
  7893. }, function(response) {
  7894. toaster.pop('error', '提示', response.data);
  7895. });
  7896. }, function(response) {
  7897. toaster.pop('error', '提示', response.data);
  7898. });
  7899. }, function(){
  7900. });
  7901. }
  7902. // 删除付款企业
  7903. $scope.removePay = function(id, index) {
  7904. DeputyOrder.removePayCompany({id: id}, {}, function(data) {
  7905. $scope.pays.splice(index, 1);
  7906. toaster.pop('success', '提示', '付款企业信息删除成功');
  7907. }, function(response) {
  7908. toaster.pop('error', '提示', response.data);
  7909. });
  7910. };
  7911. // 编辑付款企业
  7912. $scope.editPay = function(pay, uu) {
  7913. var modalInstance = $modal.open({
  7914. animation: true,
  7915. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  7916. controller: 'PayCompanyCtrl',
  7917. resolve: {
  7918. pay: function(){return pay;}
  7919. }
  7920. });
  7921. modalInstance.result.then(function() {
  7922. DeputyOrder.paycompanies({enuu: uu}, {}, function(data) {
  7923. $scope.pays = data;
  7924. }, function(response) {
  7925. toaster.pop('error', '提示', response.data);
  7926. });
  7927. }, function(){
  7928. });
  7929. };
  7930. // 设置logo
  7931. $scope.showImageDialog = function(modal) {
  7932. require([ 'jquery-uploadify' ], function() {
  7933. $modal.open({
  7934. templateUrl : 'static/tpl/index/home/insert.html',
  7935. controller : 'ImageInsertCtrl',
  7936. backdrop : 'static'
  7937. }).result.then(function(image){
  7938. $scope.imageUrl = image.thumb;
  7939. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  7940. $scope.user = data;
  7941. }, function(response) {
  7942. toaster.pop('error', '设置图像失败,' + response.data);
  7943. });
  7944. });
  7945. });
  7946. }
  7947. }]);
  7948. // 编辑收货地址
  7949. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  7950. $scope.ship = ship;
  7951. // 获取地址信息
  7952. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7953. }).then(function(response) {
  7954. $scope.provinces = response.data;
  7955. });
  7956. // 新增收货地址保存
  7957. $scope.saveShipAddress = function(ship) {
  7958. ship.address = ship.province + ship.city + ship.district;
  7959. ShipAddress.saveAddress( {}, ship, function(data) {
  7960. if(data.success) {
  7961. toaster.pop('success', '提示', data.success);
  7962. $modalInstance.close();
  7963. }
  7964. if(data.error) {
  7965. toaster.pop('error', '提示', data.error);
  7966. }
  7967. });
  7968. }
  7969. $scope.cancel = function() {
  7970. $modalInstance.dismiss();
  7971. }
  7972. }]);
  7973. // 编辑付款企业信息
  7974. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  7975. $scope.pay = pay;
  7976. // 获取地址信息
  7977. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  7978. }).then(function(response) {
  7979. $scope.provinces = response.data;
  7980. });
  7981. // 新增收货地址保存
  7982. $scope.savePayCompany = function(pay) {
  7983. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  7984. DeputyOrder.savePaycompany( {}, pay, function(data) {
  7985. toaster.pop('success', '提示', '保存成功');
  7986. $modalInstance.dismiss();
  7987. }, function(response) {
  7988. toaster.pop('error', '提示', response.data);
  7989. });
  7990. }
  7991. $scope.cancel = function() {
  7992. $modalInstance.dismiss();
  7993. }
  7994. }]);
  7995. // 申请Saas Controller
  7996. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  7997. $scope.enterprise = enterprise;
  7998. $scope.checking = false;
  7999. $scope.$watch('enterprise.enSaasUrl', function(){
  8000. if($scope.enterprise.enSaasUrl) {
  8001. $http.get('signup/saasUrlEnable', {
  8002. params: {
  8003. enSaasUrl: $scope.enterprise.enSaasUrl
  8004. }
  8005. }).success(function(data){
  8006. if(data && data == 'true') {
  8007. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  8008. } else {
  8009. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  8010. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  8011. }
  8012. }).error(function(){
  8013. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  8014. $scope.enSaasUrlErrorInfo = '验证出错';
  8015. });
  8016. } else {
  8017. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  8018. }
  8019. });
  8020. var setSaasUrl = function(url) {
  8021. var index = url.indexOf('www.');
  8022. if(index != -1) {//包含www.
  8023. var substr = url.substring(index+4, url.length);
  8024. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  8025. } else {
  8026. $scope.enterprise.enSaasUrl = getHost(url);
  8027. }
  8028. };
  8029. // 解析获取网址的一级域名
  8030. var getHost = function(host){
  8031. var newhost;
  8032. var domain;
  8033. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  8034. for(var k in ArrDomain){
  8035. var re = eval('/\\' + ArrDomain[k] + '$/g');
  8036. newhost = host.replace(re, '');
  8037. if(newhost != host){
  8038. domain = ArrDomain[k];
  8039. break;
  8040. }
  8041. }
  8042. var hostar = newhost.split('.');
  8043. var s = hostar[hostar.length-1];
  8044. return s;
  8045. };
  8046. // 设置优企云服域名为官网网址一级域名
  8047. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  8048. $scope.apply = function(){
  8049. $scope.loading = true;
  8050. AccountEnterprise.applySaas({
  8051. enUU: $scope.enterprise.uu,
  8052. enSaasUrl: $scope.enterprise.enSaasUrl,
  8053. enAdminPassword: $scope.enterprise.enAdminPassword
  8054. }, {}, function(){
  8055. $scope.loading = false;
  8056. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  8057. $modalInstance.close();
  8058. }, function(response){
  8059. $scope.loading = false;
  8060. toaster.pop('error', '申请失败', response.data);
  8061. });
  8062. };
  8063. $scope.cancel = function () {
  8064. $modalInstance.dismiss();
  8065. };
  8066. }]);
  8067. 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){
  8068. BaseService.scrollBackToTop();
  8069. $scope.editing = false;
  8070. $scope.loading = true;
  8071. $scope.enterprise = null;
  8072. AccountUser.findDistribute({},function(data) {
  8073. $scope.distributes = data;
  8074. },function(response) {
  8075. toaster.pop('error', '系统错误', response.data);
  8076. });
  8077. AuthenticationService.getAuthentication().success(function(data) {
  8078. $scope.loading = false;
  8079. $scope.user = data;
  8080. });
  8081. var users = [];
  8082. $scope.tableParams = new ngTableParams({
  8083. page : 1,
  8084. count : 20,
  8085. sorting: {
  8086. userName: 'asc'
  8087. }
  8088. }, {
  8089. total : 0,
  8090. counts: [15, 25, 50, 100],
  8091. getData : function($defer, params) {
  8092. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  8093. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  8094. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  8095. angular.forEach($scope.users,function(user){
  8096. AccountEnterprise.get({}, function(data){
  8097. $scope.loading = false;
  8098. $scope.enterprise = data;
  8099. });
  8100. });
  8101. params.total(orderedData.length);
  8102. $defer.resolve($scope.users);
  8103. }
  8104. });
  8105. var loadUsers = function() {
  8106. AccountUser.query({}, function(data){
  8107. users = data;
  8108. angular.forEach(users, function(user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  8109. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  8110. $scope.user.userIdcode = user.userIdcode;
  8111. }
  8112. });
  8113. $scope.tableParams.reload();
  8114. $scope.loading = false;
  8115. });
  8116. };
  8117. loadUsers();
  8118. $scope.saveUser = function(){
  8119. $scope.loading = true;
  8120. AccountUser.update({}, $scope.user, function(data){
  8121. $scope.loading = false;
  8122. toaster.pop('success', '提示', '修改用户信息成功');
  8123. AuthenticationService.getAuthentication().success(function(data) {
  8124. $scope.user = data;
  8125. });
  8126. loadUsers();
  8127. $scope.editing = false;
  8128. }, function(reponse){
  8129. $scope.loading = false;
  8130. toaster.pop('error', '失败', reponse.data);
  8131. });
  8132. };
  8133. $scope.updatePassword = function(){
  8134. var modalInstance = $modal.open({
  8135. animation: true,
  8136. templateUrl: 'updatePassword.html',
  8137. controller: 'PasswordCtrl',
  8138. resolve: {
  8139. user: function(){return $scope.user;}
  8140. }
  8141. });
  8142. modalInstance.result.then(function(){
  8143. }, function(){
  8144. });
  8145. };
  8146. $scope.newUser = {};
  8147. //弹出添加用户模态框
  8148. $scope.addExistUser = function(){
  8149. var modalInstance = $modal.open({
  8150. animation :true,
  8151. templateUrl : 'static/tpl/index/account/addExistUser.html',
  8152. controller : 'AddExistUserCtrl'
  8153. });
  8154. modalInstance.result.then(function(){
  8155. $scope.userTelSuccess = false;
  8156. $scope.userTelError = false;
  8157. loadUsers();
  8158. }, function(){
  8159. });
  8160. };
  8161. /**
  8162. * 添加未注册用户
  8163. */
  8164. $scope.addUser = function() {
  8165. $scope.adding = true;
  8166. AccountUser.save({}, $scope.newUser, function(){
  8167. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  8168. $scope.newUser = {userSex: 'M'};
  8169. loadUsers();
  8170. $scope.adding = false;
  8171. $scope.newUserForm.newUserTel.$setValidity('available', false);
  8172. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  8173. $scope.userTelSuccess = false;
  8174. $scope.userTelError = false;
  8175. $scope.userEmailSuccess = false;
  8176. $scope.userEmailError = false;
  8177. }, function(response){
  8178. toaster.pop('error', '错误', response.data);
  8179. });
  8180. };
  8181. /**
  8182. * 验证手机号是否可用
  8183. */
  8184. $scope.telValid = function(tel) {
  8185. if(tel) {
  8186. $http.get('account/user/telEnable', {
  8187. params: {
  8188. tel: tel
  8189. }
  8190. }).success(function(data){
  8191. data = eval(data);
  8192. if(data == true) {
  8193. $scope.newUserForm.newUserTel.$setValidity('available', true);
  8194. $scope.userTelSuccess = true;
  8195. $scope.userTelError = false;
  8196. }else{
  8197. $scope.newUserForm.newUserTel.$setValidity('available', false);
  8198. $scope.userTelError = true;
  8199. $scope.userTelSuccess = false;
  8200. if(tel.length == 11)
  8201. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  8202. }
  8203. }).error(function(){
  8204. $scope.userTelSuccess = false;
  8205. $scope.userTelError = true;
  8206. });
  8207. } else {
  8208. $scope.userTelSuccess = false;
  8209. $scope.userTelError = false;
  8210. }
  8211. };
  8212. /**
  8213. * 验证邮箱是否可用
  8214. */
  8215. $scope.emailValid = function(email) {
  8216. if(email) {
  8217. $http.get('account/user/emailEnable', {
  8218. params: {
  8219. email: email
  8220. }
  8221. }).success(function(data){
  8222. data = eval(data);
  8223. if(data == true) {
  8224. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  8225. $scope.userEmailSuccess = true;
  8226. $scope.userEmailError = false;
  8227. } else {
  8228. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  8229. $scope.userEmailError = true;
  8230. $scope.userEmailSuccess = false;
  8231. }
  8232. }).error(function(){
  8233. $scope.userEmailError = true;
  8234. $scope.userEmailSuccess = false;
  8235. });
  8236. } else {
  8237. $scope.userEmailError = false;
  8238. $scope.userEmailSuccess = false;
  8239. }
  8240. };
  8241. /**
  8242. * 删除用户
  8243. */
  8244. $scope.removeUser = function(user) {
  8245. new ngAlert({
  8246. title: '提示',
  8247. content: '确定删除用户(' + user.userName + ')吗?'
  8248. }, function(){
  8249. AccountUser.remove({uu: user.userUU}, function(){
  8250. toaster.pop('success', '提示', '用户删除成功。');
  8251. loadUsers();
  8252. }, function(response){
  8253. toaster.pop('error', '删除失败', response.data);
  8254. });
  8255. });
  8256. };
  8257. // 编辑用户的角色
  8258. $scope.editUserRole = function(user) {
  8259. var modalInstance = $modal.open({
  8260. animation: true,
  8261. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  8262. controller: 'UserRoleCtrl',
  8263. resolve: {
  8264. user: function() {
  8265. return user;
  8266. }
  8267. }
  8268. });
  8269. modalInstance.result.then(function(changed, checked){
  8270. if(changed) {
  8271. if(checked)
  8272. $scope.newUser.roles = checked;
  8273. else
  8274. loadUsers();
  8275. }
  8276. });
  8277. };
  8278. // 为用户分配角色(删除企业)
  8279. $scope.removeVendor = function(user) {
  8280. var resultRole = true;
  8281. angular.forEach(user.roles,function(role){
  8282. if(role.issys == 1) {
  8283. toaster.pop('error', '提示', '管理员无需分配客户');
  8284. resultRole = false;
  8285. return;
  8286. }
  8287. })
  8288. if(resultRole) {
  8289. var modalInstance = $modal.open({
  8290. animation: true,
  8291. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  8292. controller: 'RemoveVendorCtrl',
  8293. resolve: {
  8294. user: function() {
  8295. return user;
  8296. }
  8297. }
  8298. });
  8299. }
  8300. }
  8301. // 为用户分配角色(添加企业)
  8302. $scope.addVendor = function(user,isIssy) {
  8303. if(!isIssy) {
  8304. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  8305. return;
  8306. }
  8307. var resultRole = true;
  8308. angular.forEach(user.roles,function(role){
  8309. if(role.issys == 1) {
  8310. toaster.pop('error', '提示', '管理员无需分配客户');
  8311. resultRole = false;
  8312. return;
  8313. }
  8314. })
  8315. if(resultRole) {
  8316. var modalInstance = $modal.open({
  8317. animation: true,
  8318. templateUrl: 'static/tpl/index/account/add_vendor.html',
  8319. controller: 'AddVendorCtrl',
  8320. resolve: {
  8321. user: function() {
  8322. return user;
  8323. }
  8324. }
  8325. });
  8326. modalInstance.result.then(function(changed, checked){
  8327. if(changed) {
  8328. if(checked)
  8329. $scope.newUser.roles = checked;
  8330. else
  8331. loadUsers();
  8332. }
  8333. });
  8334. }
  8335. };
  8336. }]);
  8337. // 登录手机号码验证
  8338. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  8339. $scope.user = user;
  8340. $scope.cancel = function(){
  8341. $modalInstance.close();
  8342. }
  8343. /*$scope.loading = false;
  8344. $scope.btnState = false;
  8345. $scope.clicks = 0;
  8346. var storage = window.localStorage;
  8347. //手机验证码定时器
  8348. $scope.msgInfoError = false;
  8349. var setBtnTimeDown = function(value) {
  8350. if(value > 0) {
  8351. $scope.btnState = true;
  8352. $timeout(function() {
  8353. $scope.$apply(function(){
  8354. storage.setItem("btnTimes", $scope.btnTimes);
  8355. $scope.btnTimes --;
  8356. value --;
  8357. setBtnTimeDown (value);
  8358. });
  8359. }, 500);
  8360. }else{
  8361. $scope.btnState = false;
  8362. }
  8363. };
  8364. if(storage.btnTimes > 1){
  8365. $scope.btnTimes = storage.btnTimes;
  8366. setBtnTimeDown(storage.btnTimes)
  8367. }else{
  8368. storage.removeItem("btnTimes");
  8369. }
  8370. $scope.updateTel = function(phoneCode, userTel, uu){
  8371. $scope.loading = true;
  8372. $scope.msgInfoError = false;
  8373. $scope.result = false;
  8374. //更新联系方式
  8375. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  8376. $scope.loading = false;
  8377. $scope.msgInfoError2 = false;
  8378. $scope.result = true;
  8379. AuthenticationService.getAuthentication().success(function(data) {
  8380. $timeout(function(){
  8381. $modalInstance.dismiss();
  8382. window.location.reload();
  8383. }, 1000);
  8384. }).error(function(response) {
  8385. });
  8386. }, function(response){
  8387. $scope.loading = false;
  8388. $scope.msgInfoError2 = response;
  8389. });
  8390. };
  8391. //获取验证码
  8392. $scope.getPhoneCode = function(userTel){
  8393. var timeInfo = 10;
  8394. $scope.clicks ++;
  8395. $scope.timeInfo = timeInfo;
  8396. if($scope.clicks >= 5){
  8397. $scope.errorloading = true;
  8398. $scope.msgInfoSuccess = false;
  8399. $scope.msgInfoError = false;
  8400. }else{
  8401. $scope.loading = true;
  8402. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  8403. $scope.loading = false;
  8404. $scope.msgInfoSuccess = data.success;
  8405. $scope.sendMsg = data;
  8406. $scope.btnTimes = 60;
  8407. setBtnTimeDown($scope.btnTimes);
  8408. $scope.msgInfoError = false;
  8409. },function(response){
  8410. console.log(response);
  8411. $scope.loading = false;
  8412. $scope.msgInfoError = false;
  8413. $scope.sendCheckMsg = false;
  8414. $scope.msgInfoSuccess = true;
  8415. });
  8416. }
  8417. }; */
  8418. }]);
  8419. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  8420. $scope.checkboxes = {
  8421. checked : false
  8422. };
  8423. $scope.loading = true;
  8424. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  8425. $scope.enters = data;
  8426. $scope.loading = false;
  8427. angular.forEach($scope.enters, function(item) {
  8428. item:{
  8429. $selected:true;
  8430. }
  8431. });
  8432. })
  8433. // 点击勾选全部的复选框
  8434. $scope.checkAll = function() {
  8435. angular.forEach($scope.enters, function(item) {
  8436. item.$selected = $scope.checkboxes.checked;
  8437. });
  8438. };
  8439. // 点击其中一个明细的复选框
  8440. $scope.checkOne = function(vendor){
  8441. var result = true;
  8442. angular.forEach($scope.enters, function(item) {
  8443. if(item.$selected != true){
  8444. result = false;
  8445. return;
  8446. }
  8447. });
  8448. $scope.checkboxes.checked = result;
  8449. };
  8450. $scope.close = function(save) {
  8451. var chooseResult = [];
  8452. if(save) {
  8453. if(user.userUU) {
  8454. angular.forEach($scope.enters, function(item, i) {
  8455. if(item.$selected) {
  8456. chooseResult.push(item.id);
  8457. }
  8458. });
  8459. if(chooseResult.length > 0) {
  8460. $scope.loading = true;
  8461. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  8462. $scope.loading = false;
  8463. toaster.pop('success', '提示', '删除成功');
  8464. $modalInstance.close(false);
  8465. }, function(response){
  8466. $scope.loading = false;
  8467. toaster.pop('error', '删除失败', response.data);
  8468. $modalInstance.close(false);
  8469. })
  8470. } else {
  8471. toaster.pop('error', '删除失败', "您未勾选任何记录");
  8472. }
  8473. } else {
  8474. $modalInstance.close(true, $scope.checkboxes.checked);
  8475. }
  8476. } else {
  8477. $modalInstance.close(false);
  8478. }
  8479. };
  8480. }]);
  8481. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  8482. $scope.checkboxes = {
  8483. checked : false
  8484. };
  8485. $scope.loading = true;
  8486. AccountUser.findVendor({uu : user.userUU},function(data) {
  8487. $scope.enters = data;
  8488. $scope.loading = false;
  8489. // angular.forEach($scope.enters, function(item) {
  8490. // if(item.distribute) {
  8491. // item:{
  8492. // $selected:false;
  8493. // }
  8494. // } else {
  8495. // item:{
  8496. // $selected:true;
  8497. // }
  8498. // }
  8499. // });
  8500. })
  8501. // 点击勾选全部的复选框
  8502. $scope.checkAll = function() {
  8503. angular.forEach($scope.enters, function(item) {
  8504. item.distribute = $scope.checkboxes.checked;
  8505. });
  8506. };
  8507. // 点击其中一个明细的复选框
  8508. $scope.checkOne = function(vendor){
  8509. var result = true;
  8510. angular.forEach($scope.enters, function(item) {
  8511. if(item.distribute != true){
  8512. result = false;
  8513. return;
  8514. }
  8515. });
  8516. $scope.checkboxes.checked = result;
  8517. };
  8518. $scope.close = function(save) {
  8519. var chooseResult = [];
  8520. if(save) {
  8521. if(user.userUU) {
  8522. angular.forEach($scope.enters, function(item, i) {
  8523. // if(item.distribute) {
  8524. chooseResult.push(item);
  8525. // }
  8526. });
  8527. if(chooseResult.length > 0) {
  8528. $scope.loading = true;
  8529. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  8530. $scope.loading = false;
  8531. toaster.pop('success', '提示', '保存成功');
  8532. $modalInstance.close(false);
  8533. }, function(response){
  8534. $scope.loading = false;
  8535. toaster.pop('error', '保存失败', response.data);
  8536. $modalInstance.close(false);
  8537. })
  8538. } else {
  8539. toaster.pop('error', '保存失败', "您未勾选任何记录");
  8540. }
  8541. } else {
  8542. $modalInstance.close(true, $scope.checkboxes.checked);
  8543. }
  8544. } else {
  8545. $modalInstance.close(false);
  8546. }
  8547. };
  8548. }]);
  8549. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  8550. $scope.checked = [];
  8551. $scope.master = [];
  8552. AccountRole.query({}, function(data){
  8553. if(user && data) {
  8554. var rs = [], checked = [];
  8555. angular.forEach(user.roles, function(r){
  8556. rs.push(r.id);
  8557. });
  8558. angular.forEach(data, function(d){
  8559. if(rs.indexOf(d.id) > -1) {
  8560. d.$checked = true;
  8561. checked.push(d);
  8562. }
  8563. });
  8564. }
  8565. $scope.roles = data;
  8566. $scope.checked = checked;
  8567. $scope.master = angular.copy($scope.checked);
  8568. });
  8569. $scope.select = function(role) {
  8570. role.$checked = !role.$checked;
  8571. if(role.$checked) {
  8572. $scope.checked.push(role);
  8573. } else {
  8574. angular.forEach($scope.checked, function(c, i){
  8575. if(c.id == role.id)
  8576. $scope.checked.splice(i, 1);
  8577. });
  8578. }
  8579. };
  8580. $scope.isChanged = function() {
  8581. return !angular.equals($scope.master, $scope.checked);
  8582. };
  8583. $scope.close = function(save) {
  8584. if(save) {
  8585. if(user.userUU) {
  8586. user.roles = $scope.checked;
  8587. AccountUser.update({}, user, function(){
  8588. toaster.pop('success', '提示', '保存成功');
  8589. $modalInstance.close(true);
  8590. }, function(response){
  8591. toaster.pop('error', '保存失败', response.data);
  8592. });
  8593. } else {
  8594. $modalInstance.close(true, $scope.checked);
  8595. }
  8596. } else {
  8597. $modalInstance.close(false);
  8598. }
  8599. };
  8600. }]);
  8601. // 修改密码Controller
  8602. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  8603. $scope.user = user;
  8604. $scope.checking = false;
  8605. //输入原密码后验证原密码是否正确
  8606. $scope.checkPassword = function(password) {
  8607. $scope.checking = true;
  8608. $scope.checkSuccess = false;
  8609. $scope.checkFailed = false;
  8610. AccountUser.checkPassword({password: password}, function(data){
  8611. $scope.checkSuccess = true;
  8612. $scope.checking = false;
  8613. $scope.checkFailed = false;
  8614. }, function(response){
  8615. $scope.checkFailed = true;
  8616. $scope.checking = false;
  8617. $scope.checkSuccess = false;
  8618. });
  8619. };
  8620. //修改密码
  8621. $scope.ok = function () {
  8622. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  8623. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  8624. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  8625. toaster.pop('success', '成功', tip);
  8626. $scope.user.password = null;
  8627. $scope.user.newPassword = null;
  8628. $scope.user.newPassword1 = null;
  8629. $scope.checking = false;
  8630. $scope.checkSuccess = false;
  8631. $scope.checkFailed = false;
  8632. $modalInstance.close();
  8633. }, function(response){
  8634. toaster.pop('error', '错误', response.data);
  8635. });
  8636. } else {
  8637. toaster.pop('error', '错误', '重复密码不一致');
  8638. }
  8639. };
  8640. $scope.cancel = function () {
  8641. $modalInstance.dismiss();
  8642. };
  8643. }]);
  8644. /*
  8645. * 绑定用户到企业
  8646. */
  8647. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster){
  8648. $scope.searching = false;
  8649. //根据输入的内容查找用户
  8650. $scope.searchUser = function(keyWord) {
  8651. $scope.searching = true;
  8652. $scope.searchSuccess = false;
  8653. $scope.searchFailed = false;
  8654. $scope.illegalError = false;
  8655. $scope.reBindError = false;
  8656. $scope.okDisabled = false;
  8657. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  8658. $scope.searchSuccess = true;
  8659. $scope.searchFailed = false;
  8660. $scope.user = data; //查询到的用户
  8661. }, function(response){
  8662. $scope.searchSuccess = false;
  8663. $scope.searchFailed = true;
  8664. });
  8665. };
  8666. //确认绑定
  8667. $scope.ok = function (keyWord) {
  8668. AuthenticationService.getAuthentication().success(function(data) {
  8669. $scope.currentUser = data; //当前登录的用户(管理员)
  8670. //不可自己绑定自己
  8671. if($scope.currentUser.userUU == $scope.user.userUU){
  8672. $scope.illegalError = true;
  8673. $scope.okDisabled = true;
  8674. return false;
  8675. }
  8676. //用户未绑定到任何企业时
  8677. if(!$scope.user.enterprises){
  8678. //正常绑定
  8679. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  8680. $scope.okDisabled = true;
  8681. toaster.pop("success", "提示", "用户绑定成功");
  8682. $modalInstance.close(true);
  8683. }, function(response){
  8684. });
  8685. return true;
  8686. }
  8687. //用户已绑定到某些企业时
  8688. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  8689. if($scope.currentUser.enterprises[i].current){
  8690. for(var j = 0; j < $scope.user.enterprises.length; j++){
  8691. //该用户已绑定到当前企业,不可重复绑定
  8692. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  8693. $scope.reBindError = true;
  8694. $scope.okDisabled = true;
  8695. return false;
  8696. }
  8697. }
  8698. //该用户未绑定到当前企业,可以进行绑定
  8699. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  8700. $scope.okDisabled = true;
  8701. toaster.pop("success", "提示", "用户绑定成功");
  8702. $modalInstance.close(true);
  8703. }, function(response){
  8704. console.log("绑定失败!");
  8705. });
  8706. }
  8707. }
  8708. });
  8709. };
  8710. $scope.cancel = function () {
  8711. $modalInstance.dismiss();
  8712. };
  8713. }]);
  8714. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  8715. $scope.erpParams = new ngTableParams({
  8716. page : 1,
  8717. count : 20,
  8718. sorting: {
  8719. time: 'desc'
  8720. }
  8721. }, {
  8722. total : 0,
  8723. counts: [5, 10, 25, 50],
  8724. getData : function($defer, params) {
  8725. $scope.loading = true;
  8726. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  8727. $scope.loading = false;
  8728. if(page) {
  8729. params.total(page.totalElements);
  8730. $defer.resolve(page.content);
  8731. }
  8732. }, function(response){
  8733. $scope.loading = false;
  8734. toaster.pop('error', '数据加载失败', response.data);
  8735. });
  8736. }
  8737. });
  8738. $scope.usageParams = new ngTableParams({
  8739. page : 1,
  8740. count : 20,
  8741. sorting: {
  8742. time: 'desc'
  8743. }
  8744. }, {
  8745. total : 0,
  8746. counts: [5, 10, 25, 50],
  8747. getData : function($defer, params) {
  8748. $scope.loading = true;
  8749. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  8750. $scope.loading = false;
  8751. if(page) {
  8752. params.total(page.totalElements);
  8753. $defer.resolve(page.content);
  8754. }
  8755. }, function(response){
  8756. $scope.loading = false;
  8757. toaster.pop('error', '数据加载失败', response.data);
  8758. });
  8759. }
  8760. });
  8761. }]);
  8762. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  8763. AccountResource.query({}, function(data){
  8764. if(data && data.length > 0) {
  8765. data[0].$open = true;
  8766. }
  8767. $scope.resources = data;
  8768. });
  8769. }]);
  8770. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  8771. $scope.roles = {};
  8772. var getData = function() {
  8773. AccountRole.query({}, function(data){
  8774. var defaults = [], custom = [];
  8775. angular.forEach(data, function(d){
  8776. if(d.isdefault == 1)
  8777. defaults.push(d);
  8778. else
  8779. custom.push(d);
  8780. });
  8781. $scope.roles = {defaults: defaults, custom: custom};
  8782. });
  8783. };
  8784. getData();
  8785. $scope.editRole = function(role){
  8786. var modalInstance = $modal.open({
  8787. animation: true,
  8788. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  8789. controller: 'RoleEditCtrl',
  8790. resolve: {
  8791. role: function() {
  8792. return role;
  8793. }
  8794. }
  8795. });
  8796. modalInstance.result.then(function(added){
  8797. added && (getData());
  8798. });
  8799. };
  8800. }]);
  8801. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  8802. BaseService.scrollBackToTop();
  8803. $scope.role = role;
  8804. $scope.master = angular.copy($scope.role);
  8805. var isNew = role == null;
  8806. $scope.cancel = function() {
  8807. $modalInstance.close(false);
  8808. };
  8809. AccountResource.query({}, function(data){
  8810. if(data && data.length > 0) {
  8811. if(role && role.resourceItems) {
  8812. var rs = [];// 已分配的资源的id
  8813. angular.forEach(role.resourceItems, function(item){
  8814. rs.push(item.id);
  8815. });
  8816. angular.forEach(data, function(resource){
  8817. var c = 0;
  8818. angular.forEach(resource.items, function(item){
  8819. if(rs.indexOf(item.id) > -1) {
  8820. item.$checked = true;
  8821. c += 1;
  8822. }
  8823. });
  8824. resource.$checked = c == resource.items.length;
  8825. });
  8826. }
  8827. $scope.resourceItems = data[0].items;
  8828. data[0].$active = true;
  8829. }
  8830. $scope.resources = data;
  8831. $timeout(function(){
  8832. angular.forEach($scope.resources, function(resource){
  8833. var c = 0;
  8834. angular.forEach(resource.items, function(item){
  8835. item.$checked && (c+=1);
  8836. });
  8837. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8838. });
  8839. }, 100);
  8840. });
  8841. $scope.onItemClick = function(resource) {
  8842. $scope.resourceItems = resource.items;
  8843. angular.forEach($scope.resources, function(r){
  8844. r.$active = false;
  8845. });
  8846. resource.$active = true;
  8847. };
  8848. var getChecked = function() {
  8849. var items = [];
  8850. angular.forEach($scope.resources, function(resource){
  8851. angular.forEach(resource.items, function(item){
  8852. item.$checked && (items.push(item));
  8853. });
  8854. });
  8855. $scope.role.resourceItems = items;
  8856. };
  8857. $scope.onResourceChange = function(resource) {
  8858. angular.forEach(resource.items, function(item){
  8859. item.$checked = resource.$checked;
  8860. });
  8861. getChecked();
  8862. };
  8863. $scope.onItemChange = function() {
  8864. angular.forEach($scope.resources, function(resource){
  8865. if(resource.$active) {
  8866. var c = 0;
  8867. angular.forEach(resource.items, function(item){
  8868. item.$checked && (c+=1);
  8869. });
  8870. resource.$checked = (c == resource.items.length);
  8871. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  8872. }
  8873. });
  8874. getChecked();
  8875. };
  8876. $scope.isChanged = function(formData) {
  8877. if(!$scope.master)
  8878. return true;
  8879. return !angular.equals(formData, $scope.master);
  8880. };
  8881. $scope.save = function() {
  8882. $scope.master = angular.copy($scope.role);
  8883. AccountRole.save($scope.master, function(){
  8884. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  8885. $modalInstance.close(true);
  8886. }, function(response){
  8887. toaster.pop('error', '错误', response.data);
  8888. });
  8889. };
  8890. $scope.del = function() {
  8891. new ngAlert({
  8892. title: '提示',
  8893. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  8894. }, function(){
  8895. AccountRole.remove({id: role.id}, function(){
  8896. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  8897. $modalInstance.close(true);
  8898. }, function(response){
  8899. toaster.pop('error', '错误', response.data);
  8900. });
  8901. })
  8902. };
  8903. }]);
  8904. /**
  8905. * 委外订单
  8906. */
  8907. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  8908. function ($scope, $filter, MakeOrder, ngTableParams, toaster, ReportService, BaseService) {
  8909. BaseService.scrollBackToTop();
  8910. $scope.active = 'todo';
  8911. $scope.dateZoneText = '不限';
  8912. $scope.condition = {dateZone: 1};
  8913. /* 时间筛选初始化*/
  8914. var fromDate = new Date();
  8915. var toDate = new Date();
  8916. fromDate.setMonth(fromDate.getMonth() - 1);
  8917. fromDate.setHours(0, 0, 0, 0);
  8918. toDate.setHours(23, 59, 59, 999);
  8919. $scope.condition.dateFrom = fromDate;
  8920. $scope.condition.dateTo = toDate;
  8921. $scope.changeDateZone = function (zone) {
  8922. $scope.condition.dateZone = zone;
  8923. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8924. $scope.condition.$dateZoneOpen = false;
  8925. getDateCondition(zone, $scope.condition);
  8926. $scope.tableParams.page(1);
  8927. $scope.tableParams.reload();
  8928. };
  8929. $scope.setActive = function (state) {
  8930. if ($scope.active != state) {
  8931. $scope.active = state;
  8932. if ($scope.tableParams.page() == 1)
  8933. $scope.tableParams.reload();
  8934. else
  8935. $scope.tableParams.page(1);
  8936. }
  8937. };
  8938. var getService = function () {
  8939. return MakeOrder;
  8940. };
  8941. $scope.tableParams = new ngTableParams({
  8942. page: 1,
  8943. count: 20,
  8944. sorting: {
  8945. date: 'desc'
  8946. }
  8947. }, {
  8948. total: 0,
  8949. counts: [5, 10, 25, 50],
  8950. getData: function ($defer, params) {
  8951. $scope.loading = true;
  8952. var pageParams = params.url();
  8953. pageParams.searchFilter = {
  8954. keyword: $scope.keyword,
  8955. fromDate: getDateTime($scope.condition.dateFrom),
  8956. endDate: getDateTime($scope.condition.dateTo)
  8957. };
  8958. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8959. $scope.loading = false;
  8960. if (page) {
  8961. params.total(page.totalElement);
  8962. $defer.resolve(page.content);
  8963. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8964. }
  8965. }, function (response) {
  8966. $scope.loading = false;
  8967. toaster.pop('error', '数据加载失败', response.data);
  8968. });
  8969. }
  8970. });
  8971. $scope.getOrderTotal = function (items) {
  8972. var sum = 0;
  8973. angular.forEach(items, function (item) {
  8974. sum += item.qty * item.price;
  8975. });
  8976. return sum;
  8977. };
  8978. $scope.openDatePicker = function ($event, item, openParam) {
  8979. $event.preventDefault();
  8980. $event.stopPropagation();
  8981. item[openParam] = !item[openParam];
  8982. };
  8983. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8984. $event.preventDefault();
  8985. $event.stopPropagation();
  8986. item[openParam] = !item[openParam];
  8987. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8988. $scope.tableParams.reload();
  8989. }
  8990. };
  8991. $scope.parseDate = function (dateStr) {
  8992. if (dateStr)
  8993. return Date.parse(dateStr, 'yyyy-MM-dd');
  8994. return new Date();
  8995. };
  8996. // 打开回复
  8997. $scope.openReply = function (order) {
  8998. if (!order.reply) {
  8999. order.reply = {
  9000. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  9001. delivery: order.delivery
  9002. }
  9003. }
  9004. order.$editing = true;
  9005. };
  9006. // 关闭回复
  9007. $scope.closeReply = function (order) {
  9008. order.$editing = false;
  9009. }
  9010. // 搜索框回车
  9011. $scope.onSearch = function () {
  9012. $scope.tableParams.page(1);
  9013. $scope.tableParams.reload();
  9014. };
  9015. // 选择查找日期
  9016. $scope.onDateCondition = function () {
  9017. $scope.tableParams.page(1);
  9018. $scope.tableParams.reload();
  9019. };
  9020. // 点击回复
  9021. $scope.onReplyClick = function (order, inverse) {
  9022. if (order.reply) {
  9023. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  9024. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  9025. return;
  9026. }
  9027. var reply = angular.copy(order.reply);
  9028. if (reply.delivery) {
  9029. if (typeof reply.delivery == 'object')
  9030. reply.delivery = reply.delivery.getTime();
  9031. } else {
  9032. reply.delivery = order.delivery;
  9033. }
  9034. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  9035. $scope.loading = true;
  9036. MakeOrder.reply({orderId: order.id}, reply, function () {
  9037. $scope.loading = false;
  9038. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  9039. $scope.tableParams.reload();
  9040. }, function (response) {
  9041. $scope.loading = false;
  9042. toaster.pop('error', '回复失败', response.data);
  9043. });
  9044. }
  9045. };
  9046. //委外加工单
  9047. $scope.print = function (order) {
  9048. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  9049. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  9050. };
  9051. // 获取回复记录
  9052. $scope.getReply = function (order) {
  9053. if (!order.replies) {
  9054. MakeOrder.getReply({orderId: order.id}, function (replies) {
  9055. order.replies = replies;
  9056. });
  9057. }
  9058. };
  9059. }]);
  9060. /**
  9061. * 委外加工单详细
  9062. */
  9063. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  9064. BaseService.scrollBackToTop();
  9065. var loadData = function() {
  9066. MakeOrder.get({id: $stateParams.id}, function(data){
  9067. $scope.order = data;
  9068. var sum = $scope.order.qty * $scope.order.price;
  9069. $scope.order.total = sum;
  9070. $scope.loading = false;
  9071. });
  9072. };
  9073. loadData();
  9074. // 获取回复记录
  9075. $scope.getReply = function(item) {
  9076. if(!item.replies) {
  9077. MakeOrder.getReply({orderId: item.id}, function(replies){
  9078. item.replies = replies;
  9079. });
  9080. }
  9081. };
  9082. $scope.openDatePicker = function($event, item, openParam) {
  9083. $event.preventDefault();
  9084. $event.stopPropagation();
  9085. item[openParam] = !item[openParam];
  9086. };
  9087. // 点击回复
  9088. $scope.onReplyClick = function(order, inverse) {
  9089. if(order.reply) {
  9090. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  9091. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  9092. return;
  9093. }
  9094. var reply = angular.copy(order.reply);
  9095. if(reply.delivery) {
  9096. if(typeof reply.delivery == 'object')
  9097. reply.delivery = reply.delivery.getTime();
  9098. } else {
  9099. reply.delivery = order.delivery;
  9100. }
  9101. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  9102. $scope.loading = true;
  9103. MakeOrder.reply({orderId: order.id}, reply, function(){
  9104. $scope.loading = false;
  9105. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  9106. loadData();
  9107. }, function(response){
  9108. $scope.loading = false;
  9109. toaster.pop('error', '回复失败', response.data);
  9110. });
  9111. }
  9112. };
  9113. // 打开回复
  9114. $scope.openReply = function(order) {
  9115. if(!order.reply) {
  9116. order.reply = {
  9117. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  9118. delivery: order.delivery
  9119. }
  9120. }
  9121. order.$editing = true;
  9122. };
  9123. // 关闭回复
  9124. $scope.closeReply = function(order) {
  9125. order.$editing = false;
  9126. }
  9127. // 委外订单
  9128. $scope.print = function(order) {
  9129. MakeOrder.printCount({id: order.id},{});//增加打印此次
  9130. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  9131. };
  9132. }]);
  9133. /**
  9134. * 客户委外验收
  9135. */
  9136. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  9137. BaseService.scrollBackToTop();
  9138. $scope.active = 'all';
  9139. $scope.agreedText = '全部';
  9140. $scope.dateZoneText = '一个月内';
  9141. $scope.condition = {dateZone: 1};
  9142. /* 时间筛选初始化*/
  9143. var fromDate = new Date();
  9144. var toDate = new Date();
  9145. fromDate.setMonth(fromDate.getMonth() - 1);
  9146. fromDate.setHours(0,0,0,0);
  9147. toDate.setHours(23,59,59,999);
  9148. $scope.condition.dateFrom = fromDate;
  9149. $scope.condition.dateTo = toDate;
  9150. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9151. $scope.changeAgreed = function(agreed) {
  9152. $scope.condition.agreed = agreed;
  9153. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9154. $scope.condition.$agreedOpen = false;
  9155. };
  9156. $scope.changeDateZone = function(zone) {
  9157. $scope.condition.dateZone = zone;
  9158. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9159. $scope.condition.$dateZoneOpen = false;
  9160. getDateCondition(zone, $scope.condition);
  9161. $scope.tableParams.page(1);
  9162. $scope.tableParams.reload();
  9163. };
  9164. $scope.setActive = function(state) {
  9165. if($scope.active != state) {
  9166. $scope.active = state;
  9167. if($scope.tableParams.page() == 1)
  9168. $scope.tableParams.reload();
  9169. else
  9170. $scope.tableParams.page(1);
  9171. }
  9172. };
  9173. var getService = function() {
  9174. return MakeAccept;
  9175. };
  9176. $scope.tableParams = new ngTableParams({
  9177. page : 1,
  9178. count : 20,
  9179. sorting: {
  9180. date: 'desc'
  9181. }
  9182. }, {
  9183. total : 0,
  9184. counts: [5, 10, 25, 50],
  9185. getData : function($defer, params) {
  9186. $scope.loading = true;
  9187. var pageParams = params.url();
  9188. pageParams.searchFilter = {};
  9189. pageParams.searchFilter.keyword = $scope.keyword;
  9190. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9191. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9192. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9193. $scope.loading = false;
  9194. if(page) {
  9195. params.total(page.totalElement);
  9196. $defer.resolve(page.content);
  9197. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  9198. }
  9199. }, function(response){
  9200. $scope.loading = false;
  9201. toaster.pop('error', '数据加载失败', response.data);
  9202. });
  9203. }
  9204. });
  9205. $scope.openDatePicker = function($event, item, openParam) {
  9206. $event.preventDefault();
  9207. $event.stopPropagation();
  9208. item[openParam] = !item[openParam];
  9209. };
  9210. $scope.openFilterDatePicker = function($event, item, openParam) {
  9211. $event.preventDefault();
  9212. $event.stopPropagation();
  9213. item[openParam] = !item[openParam];
  9214. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  9215. $scope.tableParams.reload();
  9216. }
  9217. };
  9218. // 搜索框回车
  9219. $scope.onSearch = function() {
  9220. $scope.tableParams.page(1);
  9221. $scope.tableParams.reload();
  9222. };
  9223. // 选择查找日期
  9224. $scope.onDateCondition = function(){
  9225. $scope.tableParams.page(1);
  9226. $scope.tableParams.reload();
  9227. };
  9228. }]);
  9229. /**
  9230. * 客户委外验退
  9231. */
  9232. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  9233. BaseService.scrollBackToTop();
  9234. $scope.active = 'all';
  9235. $scope.agreedText = '全部';
  9236. $scope.dateZoneText = '一个月内';
  9237. $scope.condition = {dateZone: 1};
  9238. /* 时间筛选初始化*/
  9239. var fromDate = new Date();
  9240. var toDate = new Date();
  9241. fromDate.setMonth(fromDate.getMonth() - 1);
  9242. fromDate.setHours(0,0,0,0);
  9243. toDate.setHours(23,59,59,999);
  9244. $scope.condition.dateFrom = fromDate;
  9245. $scope.condition.dateTo = toDate;
  9246. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9247. $scope.changeAgreed = function(agreed) {
  9248. $scope.condition.agreed = agreed;
  9249. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9250. $scope.condition.$agreedOpen = false;
  9251. };
  9252. $scope.changeDateZone = function(zone) {
  9253. $scope.condition.dateZone = zone;
  9254. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9255. $scope.condition.$dateZoneOpen = false;
  9256. getDateCondition(zone, $scope.condition);
  9257. $scope.tableParams.page(1);
  9258. $scope.tableParams.reload();
  9259. };
  9260. $scope.setActive = function(state) {
  9261. if($scope.active != state) {
  9262. $scope.active = state;
  9263. if($scope.tableParams.page() == 1)
  9264. $scope.tableParams.reload();
  9265. else
  9266. $scope.tableParams.page(1);
  9267. }
  9268. };
  9269. var getService = function() {
  9270. return MakeReturn;
  9271. };
  9272. $scope.tableParams = new ngTableParams({
  9273. page : 1,
  9274. count : 20,
  9275. sorting: {
  9276. date: 'desc'
  9277. }
  9278. }, {
  9279. total : 0,
  9280. counts: [5, 10, 25, 50],
  9281. getData : function($defer, params) {
  9282. $scope.loading = true;
  9283. var pageParams = params.url();
  9284. pageParams.searchFilter = {};
  9285. pageParams.searchFilter.keyword = $scope.keyword;
  9286. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9287. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9288. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9289. $scope.loading = false;
  9290. if(page) {
  9291. params.total(page.totalElement);
  9292. $defer.resolve(page.content);
  9293. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  9294. }
  9295. }, function(response){
  9296. $scope.loading = false;
  9297. toaster.pop('error', '数据加载失败', response.data);
  9298. });
  9299. }
  9300. });
  9301. $scope.openDatePicker = function($event, item, openParam) {
  9302. $event.preventDefault();
  9303. $event.stopPropagation();
  9304. item[openParam] = !item[openParam];
  9305. };
  9306. $scope.openFilterDatePicker = function($event, item, openParam) {
  9307. $event.preventDefault();
  9308. $event.stopPropagation();
  9309. item[openParam] = !item[openParam];
  9310. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  9311. $scope.tableParams.reload();
  9312. }
  9313. };
  9314. // 搜索框回车
  9315. $scope.onSearch = function() {
  9316. $scope.tableParams.page(1);
  9317. $scope.tableParams.reload();
  9318. };
  9319. // 选择查找日期
  9320. $scope.onDateCondition = function(){
  9321. $scope.tableParams.page(1);
  9322. $scope.tableParams.reload();
  9323. };
  9324. }]);
  9325. /**
  9326. * 委外加工变更
  9327. */
  9328. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  9329. BaseService.scrollBackToTop();
  9330. $scope.active = 'all';
  9331. $scope.agreedText = '全部';
  9332. $scope.dateZoneText = '一个月内';
  9333. $scope.condition = {dateZone: 1};
  9334. /* 时间筛选初始化*/
  9335. var fromDate = new Date();
  9336. var toDate = new Date();
  9337. fromDate.setMonth(fromDate.getMonth() - 1);
  9338. fromDate.setHours(0,0,0,0);
  9339. toDate.setHours(23,59,59,999);
  9340. $scope.condition.dateFrom = fromDate;
  9341. $scope.condition.dateTo = toDate;
  9342. $scope.changeAgreed = function(agreed) {
  9343. $scope.condition.agreed = agreed;
  9344. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9345. $scope.condition.$agreedOpen = false;
  9346. };
  9347. $scope.changeDateZone = function(zone) {
  9348. $scope.condition.dateZone = zone;
  9349. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9350. $scope.condition.$dateZoneOpen = false;
  9351. getDateCondition(zone, $scope.condition);
  9352. $scope.tableParams.page(1);
  9353. $scope.tableParams.reload();
  9354. };
  9355. $scope.setActive = function(state) {
  9356. if($scope.active != state) {
  9357. $scope.active = state;
  9358. if($scope.tableParams.page() == 1)
  9359. $scope.tableParams.reload();
  9360. else
  9361. $scope.tableParams.page(1);
  9362. }
  9363. };
  9364. var getService = function() {
  9365. return MakeChange;
  9366. };
  9367. $scope.tableParams = new ngTableParams({
  9368. page : 1,
  9369. count : 20,
  9370. sorting: {
  9371. orderChangeDate: 'desc'
  9372. }
  9373. }, {
  9374. total : 0,
  9375. counts: [5, 10, 25, 50],
  9376. getData : function($defer, params) {
  9377. $scope.loading = true;
  9378. var pageParams = params.url();
  9379. pageParams.searchFilter = {
  9380. keyword: $scope.keyword,
  9381. fromDate: getDateTime($scope.condition.dateFrom),
  9382. endDate: getDateTime($scope.condition.dateTo)
  9383. };
  9384. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9385. $scope.loading = false;
  9386. if(page) {
  9387. params.total(page.totalElement);
  9388. $defer.resolve(page.content);
  9389. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  9390. }
  9391. }, function(response){
  9392. $scope.loading = false;
  9393. toaster.pop('error', '数据加载失败', response.data);
  9394. });
  9395. }
  9396. });
  9397. $scope.openDatePicker = function($event, item, openParam) {
  9398. $event.preventDefault();
  9399. $event.stopPropagation();
  9400. item[openParam] = !item[openParam];
  9401. };
  9402. $scope.openFilterDatePicker = function($event, item, openParam) {
  9403. $event.preventDefault();
  9404. $event.stopPropagation();
  9405. item[openParam] = !item[openParam];
  9406. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  9407. $scope.tableParams.reload();
  9408. }
  9409. };
  9410. // 打开回复
  9411. $scope.openReply = function(change) {
  9412. change.$editing = true;
  9413. };
  9414. // 关闭回复
  9415. $scope.closeReply = function(change) {
  9416. change.$editing = false;
  9417. }
  9418. // 确定回复
  9419. $scope.onReplyClick = function(change) {
  9420. if(change.$agreed) {
  9421. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  9422. $scope.loading = true;
  9423. MakeChange.reply({itemId: change.id}, reply, function(){
  9424. $scope.loading = false;
  9425. toaster.pop('info', '提示', '回复成功');
  9426. $scope.tableParams.reload();
  9427. }, function(response){
  9428. $scope.loading = false;
  9429. toaster.pop('error', '回复失败', response.data);
  9430. });
  9431. }
  9432. };
  9433. // 搜索框回车
  9434. $scope.onSearch = function() {
  9435. $scope.tableParams.page(1);
  9436. $scope.tableParams.reload();
  9437. };
  9438. // 选择查找日期
  9439. $scope.onDateCondition = function(){
  9440. $scope.tableParams.page(1);
  9441. $scope.tableParams.reload();
  9442. };
  9443. }]);
  9444. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  9445. BaseService.scrollBackToTop();
  9446. var loadData = function() {
  9447. MakeChange.get({id: $stateParams.id}, function(data){
  9448. $scope.change = data;
  9449. });
  9450. };
  9451. loadData();
  9452. $scope.openDatePicker = function($event, item, openParam) {
  9453. $event.preventDefault();
  9454. $event.stopPropagation();
  9455. item[openParam] = !item[openParam];
  9456. };
  9457. $scope.onReplyClick = function(change) {
  9458. if(change.$agreed) {
  9459. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  9460. MakeChange.reply({itemId: change.id}, reply, function(){
  9461. toaster.pop('info', '提示', '回复成功');
  9462. loadData();
  9463. }, function(response){
  9464. toaster.pop('error', '回复失败', response.data);
  9465. });
  9466. }
  9467. };
  9468. }]);
  9469. /**
  9470. * 委外加工
  9471. */
  9472. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService', function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  9473. BaseService.scrollBackToTop();
  9474. $scope.active = 'all';
  9475. $scope.agreedText = '全部';
  9476. $scope.dateZoneText = '一个月内';
  9477. $scope.condition = {dateZone: 1};
  9478. /* 时间筛选初始化*/
  9479. var fromDate = new Date();
  9480. var toDate = new Date();
  9481. fromDate.setMonth(fromDate.getMonth() - 1);
  9482. fromDate.setHours(0,0,0,0);
  9483. toDate.setHours(23,59,59,999);
  9484. $scope.condition.dateFrom = fromDate;
  9485. $scope.condition.dateTo = toDate;
  9486. $scope.changeAgreed = function(agreed) {
  9487. $scope.condition.agreed = agreed;
  9488. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9489. $scope.condition.$agreedOpen = false;
  9490. };
  9491. $scope.changeDateZone = function(zone) {
  9492. $scope.condition.dateZone = zone;
  9493. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9494. $scope.condition.$dateZoneOpen = false;
  9495. getDateCondition(zone, $scope.condition);
  9496. $scope.tableParams.page(1);
  9497. $scope.tableParams.reload();
  9498. };
  9499. $scope.setActive = function(state) {
  9500. if($scope.active != state) {
  9501. $scope.active = state;
  9502. if($scope.tableParams.page() == 1)
  9503. $scope.tableParams.reload();
  9504. else
  9505. $scope.tableParams.page(1);
  9506. }
  9507. };
  9508. var getService = function() {
  9509. return MakeOutOrder;
  9510. };
  9511. $scope.tableParams = new ngTableParams({
  9512. page : 1,
  9513. count : 20,
  9514. sorting: {
  9515. date: 'desc'
  9516. }
  9517. }, {
  9518. total : 0,
  9519. counts: [5, 10, 25, 50],
  9520. getData : function($defer, params) {
  9521. $scope.loading = true;
  9522. var pageParams = params.url();
  9523. pageParams.searchFilter = {};
  9524. pageParams.searchFilter.keyword = $scope.keyword;
  9525. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9526. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9527. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9528. $scope.loading = false;
  9529. if(page) {
  9530. params.total(page.totalElement);
  9531. $defer.resolve(page.content);
  9532. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  9533. }
  9534. }, function(response){
  9535. $scope.loading = false;
  9536. toaster.pop('error', '数据加载失败', response.data);
  9537. });
  9538. }
  9539. });
  9540. $scope.openDatePicker = function($event, item, openParam) {
  9541. $event.preventDefault();
  9542. $event.stopPropagation();
  9543. item[openParam] = !item[openParam];
  9544. };
  9545. $scope.openFilterDatePicker = function($event, item, openParam) {
  9546. $event.preventDefault();
  9547. $event.stopPropagation();
  9548. item[openParam] = !item[openParam];
  9549. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  9550. $scope.tableParams.reload();
  9551. }
  9552. };
  9553. // 打开回复
  9554. $scope.openReply = function(change) {
  9555. change.$editing = true;
  9556. };
  9557. // 关闭回复
  9558. $scope.closeReply = function(change) {
  9559. change.$editing = false;
  9560. }
  9561. // 确定回复
  9562. $scope.onReplyClick = function(change) {
  9563. if(change.$agreed) {
  9564. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  9565. $scope.loading = true;
  9566. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  9567. $scope.loading = false;
  9568. toaster.pop('info', '提示', '回复成功');
  9569. $scope.tableParams.reload();
  9570. }, function(response){
  9571. $scope.loading = false;
  9572. toaster.pop('error', '回复失败', response.data);
  9573. });
  9574. }
  9575. };
  9576. // 搜索框回车
  9577. $scope.onSearch = function() {
  9578. $scope.tableParams.page(1);
  9579. $scope.tableParams.reload();
  9580. };
  9581. // 选择查找日期
  9582. $scope.onDateCondition = function(){
  9583. $scope.tableParams.page(1);
  9584. $scope.tableParams.reload();
  9585. };
  9586. }]);
  9587. /**
  9588. * 委外加工详细
  9589. */
  9590. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  9591. BaseService.scrollBackToTop();
  9592. var loadData = function() {
  9593. MakeOutOrder.get({id: $stateParams.id}, function(data){
  9594. $scope.order = data;
  9595. var sum = $scope.order.qty * $scope.order.price;
  9596. $scope.order.total = sum;
  9597. $scope.loading = false;
  9598. });
  9599. };
  9600. loadData();
  9601. // 获取回复记录
  9602. $scope.getReply = function(item) {
  9603. if(!item.replies) {
  9604. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  9605. item.replies = replies;
  9606. });
  9607. }
  9608. };
  9609. $scope.openDatePicker = function($event, item, openParam) {
  9610. $event.preventDefault();
  9611. $event.stopPropagation();
  9612. item[openParam] = !item[openParam];
  9613. };
  9614. // 点击回复
  9615. $scope.onReplyClick = function(order, inverse) {
  9616. if(order.reply) {
  9617. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  9618. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  9619. return;
  9620. }
  9621. var reply = angular.copy(order.reply);
  9622. if(reply.delivery) {
  9623. if(typeof reply.delivery == 'object')
  9624. reply.delivery = reply.delivery.getTime();
  9625. } else {
  9626. reply.delivery = order.delivery;
  9627. }
  9628. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  9629. $scope.loading = true;
  9630. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  9631. $scope.loading = false;
  9632. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  9633. loadData();
  9634. }, function(response){
  9635. $scope.loading = false;
  9636. toaster.pop('error', '回复失败', response.data);
  9637. });
  9638. }
  9639. };
  9640. // 打开回复
  9641. $scope.openReply = function(order) {
  9642. if(!order.reply) {
  9643. order.reply = {
  9644. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  9645. delivery: order.delivery
  9646. }
  9647. }
  9648. order.$editing = true;
  9649. };
  9650. // 关闭回复
  9651. $scope.closeReply = function(order) {
  9652. order.$editing = false;
  9653. }
  9654. // 自己委外加工订单
  9655. $scope.print = function(order) {
  9656. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  9657. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  9658. };
  9659. }]);
  9660. /**
  9661. * 计算时间差
  9662. */
  9663. app.filter('timespan', function(){
  9664. return function(time) {
  9665. if(time == null)
  9666. return '9999年';
  9667. var now = new Date().getTime(), span = time - now,
  9668. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  9669. m = Math.ceil(span/60000);
  9670. if(span < 0)
  9671. return '1天';
  9672. if(d > 0)
  9673. return d+1 + '天';
  9674. if(h > 0)
  9675. return h + '小时';
  9676. if(m > 0)
  9677. return m + '分钟';
  9678. return '0天';
  9679. };
  9680. });
  9681. app.filter('firstchar', function(){
  9682. return function(str) {
  9683. if(str == null)
  9684. return null;
  9685. return str.substring(0, 1);
  9686. };
  9687. });
  9688. app.filter('summary', function(){
  9689. return function(data, field) {
  9690. var sum = 0;
  9691. if (data) {
  9692. angular.forEach(data, function(d){
  9693. sum += d[field];
  9694. });
  9695. }
  9696. return sum;
  9697. };
  9698. });
  9699. /**
  9700. * 搜索框,回车触发
  9701. */
  9702. app.directive('ngSearch', ['$parse', function($parse) {
  9703. return {
  9704. require : '?ngModel',
  9705. restrict : 'A',
  9706. link : function(scope, element, attrs, ngModel) {
  9707. var searchFn = $parse(attrs.ngSearch);
  9708. element.bind('keypress', function(event) {
  9709. if (event.keyCode == '13') {
  9710. event.preventDefault();
  9711. event.stopPropagation();
  9712. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  9713. }
  9714. });
  9715. }
  9716. };
  9717. }]);
  9718. /**
  9719. * 状态码 -> 描述
  9720. */
  9721. app.filter('status', function(){
  9722. return function(data) {
  9723. var statusConfig = {
  9724. '101': '已提交',
  9725. '102': '已审核',
  9726. '103': '未通过',
  9727. '200': '未回复',
  9728. '201': '已回复',
  9729. '313': '已激活',
  9730. '316': '已过账',
  9731. '311': '申请中',
  9732. '312': '未激活'
  9733. };
  9734. return statusConfig[data];
  9735. }
  9736. });
  9737. //弹出问题反馈模态框
  9738. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  9739. //获取当前用户
  9740. AuthenticationService.getAuthentication().success(function(data) {
  9741. $scope.user = data;
  9742. });
  9743. $scope.showModal = function(){
  9744. var modalInstance = $modal.open({
  9745. animation: true,
  9746. templateUrl: 'static/tpl/serve/feedback.html',
  9747. controller: 'FeedbackCtrl',
  9748. resolve: {
  9749. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  9750. }
  9751. });
  9752. modalInstance.result.then(function(){
  9753. }, function(){
  9754. })
  9755. }
  9756. }]);
  9757. /*
  9758. * 提交我的反馈
  9759. */
  9760. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  9761. $scope.isPublic = 1; //默认公开
  9762. $scope.classId = 1; //默认类别
  9763. $scope.user = user;
  9764. $scope.ok = function(){
  9765. if(!$scope.user){ //用户未登录
  9766. $scope.uu = null;
  9767. }else{ //用户已登录
  9768. $scope.uu = $scope.user.userUU;
  9769. }
  9770. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  9771. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  9772. function(data){
  9773. toaster.pop('success', '成功', '您的问题反馈成功!');
  9774. $scope.cancel();
  9775. }, function(response){
  9776. toaster.pop('error', '错误', response.data);
  9777. });
  9778. }
  9779. $scope.cancel = function () {
  9780. $modalInstance.dismiss();
  9781. };
  9782. }]);
  9783. //“我的问题反馈”跳转控制
  9784. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function($scope, AuthenticationService, toaster, $rootScope){
  9785. $scope.myFeedback = function(){
  9786. AuthenticationService.getAuthentication().success(function(data){
  9787. $scope.user = data;
  9788. if(!$scope.user){
  9789. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  9790. return false;
  9791. }else{
  9792. window.location.href = "./serve#/question/myFeedback";
  9793. }
  9794. });
  9795. };
  9796. $scope.setActive = function(active) {
  9797. $rootScope.active = active;
  9798. }
  9799. }]);
  9800. //客户服务
  9801. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  9802. Vendor.getServe(function(datas){
  9803. $scope.vendors = datas;
  9804. // 自动跳转
  9805. if(datas && datas.length == 1)
  9806. $scope.redirect(datas[0]);
  9807. });
  9808. $scope.redirect = function(vendor) {
  9809. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  9810. };
  9811. }]);
  9812. /**
  9813. * 物料资料
  9814. */
  9815. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$rootScope', '$modal', 'Products', 'GetProductInfoNewest', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout, $rootScope, $modal, Products, GetProductInfoNewest) {
  9816. BaseService.scrollBackToTop();
  9817. $scope.active = 'all';
  9818. $scope.agreedText = '全部';
  9819. $scope.dateZoneText = '一个月内';
  9820. $scope.condition = {dateZone: 1};
  9821. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9822. $scope.changeAgreed = function(agreed) {
  9823. $scope.condition.agreed = agreed;
  9824. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9825. $scope.condition.$agreedOpen = false;
  9826. };
  9827. $scope.changeDateZone = function(zone) {
  9828. $scope.condition.dateZone = zone;
  9829. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9830. $scope.condition.$dateZoneOpen = false;
  9831. getDateCondition(zone, $scope.condition);
  9832. $scope.tableParams.reload();
  9833. };
  9834. $scope.setActive = function(state) {
  9835. if($scope.active != state) {
  9836. $scope.active = state;
  9837. if($scope.tableParams.page() == 1)
  9838. $scope.tableParams.reload();
  9839. else
  9840. $scope.tableParams.page(1);
  9841. }
  9842. };
  9843. $scope.searchMethod = false;
  9844. var getService = function() {
  9845. if($scope.searchMethod) {
  9846. return GetProductInfo;
  9847. } else {
  9848. return GetProductInfoNewest;
  9849. }
  9850. };
  9851. $scope.tableParams = new ngTableParams({
  9852. page : 1,
  9853. count : 20,
  9854. sorting: {
  9855. }
  9856. }, {
  9857. total : 0,
  9858. counts: [5, 10, 25, 50],
  9859. getData : function($defer, params) {
  9860. $scope.loading = true;
  9861. var pageParams = params.url();
  9862. pageParams.keyword = $scope.keyword;
  9863. pageParams.searchFilter = $scope.searchFilter;
  9864. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9865. $scope.loading = false;
  9866. if(page) {
  9867. params.total(page.totalElement);
  9868. $defer.resolve(page.content);
  9869. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9870. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  9871. }
  9872. }, function(response) {
  9873. $scope.loading = false;
  9874. toaster.pop('error', '数据加载失败', response.data);
  9875. });
  9876. }
  9877. });
  9878. // 搜索框回车
  9879. $scope.onSearch = function() {
  9880. $scope.searchMethod = true;
  9881. $scope.tableParams.page(1);
  9882. $scope.tableParams.reload();
  9883. };
  9884. //删除
  9885. $scope.deleteById = function(id) {
  9886. GetProductInfo.deleteById({id: id}, function(data) {
  9887. if(data.error) {
  9888. toaster.pop("error", "提示", data.error);
  9889. } else {
  9890. toaster.pop("success", "提示", "删除成功");
  9891. $timeout(function() {
  9892. $scope.tableParams.reload();
  9893. }, 500);
  9894. }
  9895. }), function(response) {
  9896. toaster.pop("error", "删除失败", response.data);
  9897. };
  9898. };
  9899. $rootScope.isProductEdit = false;
  9900. // 编辑
  9901. $scope.isProductEdit = function () {
  9902. $rootScope.isProductEdit = true;
  9903. };
  9904. // 一键开启关闭
  9905. $scope.toggle = function(status) {
  9906. $scope.loading = true;
  9907. GetProductInfo.toggle({status: status}, {}, function(data) {
  9908. $scope.loading = false;
  9909. toaster.pop('success', '提示', '操作成功');
  9910. $scope.tableParams.reload();
  9911. }, function(response) {
  9912. $scope.loading = false;
  9913. toaster.pop('error', '提示', response.data);
  9914. })
  9915. }
  9916. var products = [];
  9917. $scope.checks = {
  9918. checked: false
  9919. };
  9920. // 全选框
  9921. $scope.checkAll = function() {
  9922. products = [];// 每次选择时先清空,防止重复
  9923. angular.forEach($scope.tableParams.data, function(product) {
  9924. if(product.cmpUuId == null) {
  9925. product.checked = $scope.checks.checked;
  9926. }
  9927. });
  9928. };
  9929. // 单选
  9930. $scope.checkOne = function(product) {
  9931. products = [];// 每次选择时先清空,防止重复
  9932. var result = true;
  9933. angular.forEach($scope.tableParams.data, function(item) {
  9934. if(item.$selected != true){
  9935. result = false;
  9936. return;
  9937. }
  9938. });
  9939. $scope.checks.checked = result;
  9940. var checked = true;
  9941. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  9942. if (!message.checked) {
  9943. checked = false;
  9944. }
  9945. });
  9946. $scope.checks.checked = checked;
  9947. };
  9948. $scope.updateByBatch = function(updatetype) {
  9949. var modalInstance = $modal.open({
  9950. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  9951. controller: 'UpdateByBatchCtrl',
  9952. size: 'md',
  9953. resolve: {
  9954. updatetype: function() {
  9955. return updatetype;
  9956. },
  9957. active: function() {
  9958. return $scope.active;
  9959. },
  9960. type: function() {
  9961. return 'sale';
  9962. }
  9963. }
  9964. });
  9965. modalInstance.result.then(function(data) {
  9966. toaster.pop('success', '提示', data.success);
  9967. $scope.tableParams.reload();
  9968. }, function(){
  9969. });
  9970. }
  9971. // 一键匹配
  9972. $scope.matchall = function() {
  9973. $scope.loading = true;
  9974. $scope.type = "sale";
  9975. Products.matchbytype({type: $scope.type}, {}, function(data) {
  9976. if(data.error) {
  9977. $scope.loading = false;
  9978. toaster.pop('error', '提示', data.error);
  9979. } else {
  9980. toaster.pop('info', '提示', '匹配成功'+data.size+'个标准器件');
  9981. window.location.href = "#/sale/productmatches";
  9982. }
  9983. }, function(response) {
  9984. toaster.pop('error', '提示', response.data);
  9985. });
  9986. }
  9987. }]);
  9988. /**
  9989. * 批量修改
  9990. */
  9991. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  9992. $scope.updatetype = updatetype;
  9993. $scope.changed = false;
  9994. $scope.parameter = {
  9995. updatetype: updatetype,
  9996. standard: active,
  9997. type: type,
  9998. oldvalue: null,
  9999. newvalue: null
  10000. };
  10001. $scope.cancel = function() {
  10002. $modalInstance.dismiss();
  10003. }
  10004. if(updatetype === '品牌')
  10005. var loadData = function() {
  10006. Products.getBrands({parameter: $scope.parameter}, {}, function(data) {
  10007. $scope.products = data;
  10008. }, function(response) {
  10009. toaster.pop('error', '提示', response.data);
  10010. })
  10011. }
  10012. if(updatetype === '名称(类目)')
  10013. var loadData = function() {
  10014. Products.getTitles({parameter: $scope.parameter}, {}, function(data) {
  10015. $scope.products = data;
  10016. }, function(response) {
  10017. toaster.pop('error', '提示', response.data);
  10018. })
  10019. }
  10020. loadData();
  10021. $scope.okay = function(newvalue) {
  10022. if(newvalue == '' || newvalue == null) {
  10023. toaster.pop('error', '提示', '修改的值不能为空');
  10024. } else {
  10025. Products.alterByBatch({parameter: $scope.parameter}, {}, function(data) {
  10026. $modalInstance.close(data);
  10027. }, function(response) {
  10028. toaster.pop('error', '提示', response.data);
  10029. });
  10030. }
  10031. }
  10032. }]);
  10033. /**
  10034. * 物料批量上传
  10035. */
  10036. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  10037. BaseService.scrollBackToTop();
  10038. $scope.$watch('myFiles', function(){
  10039. if($scope.myFiles) {
  10040. var file = $scope.myFiles[0];
  10041. $scope.fileName = file.name;
  10042. }
  10043. })
  10044. // 通过excel批量上传物料
  10045. $scope.upload = function() {
  10046. $scope.loading = true;
  10047. if($scope.myFiles) {
  10048. var file = $scope.myFiles[0];
  10049. if(file.name) {
  10050. $upload.upload({
  10051. url: 'product/baseInfo/release/excel',
  10052. file: file,
  10053. method: 'POST'
  10054. }).success(function(data) {
  10055. $scope.loading = false;
  10056. if(data.error) {
  10057. toaster.pop('error', '提示', data.error);
  10058. }
  10059. $scope.result = data;
  10060. $scope.products = $scope.result.products;
  10061. $scope.success = $scope.result.success;
  10062. $scope.total = $scope.result.total;
  10063. $scope.alters = $scope.result.alters;
  10064. $scope.infos = $scope.result.infos;
  10065. $scope.myFiles[0] = "";
  10066. $scope.fileName = "";
  10067. }).error(function(response) {
  10068. $scope.loading = false;
  10069. toaster.pop('error', response.data || response);
  10070. });
  10071. } else {
  10072. $scope.loading = false;
  10073. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  10074. }
  10075. } else {
  10076. $scope.loading = false;
  10077. }
  10078. };
  10079. // 查看范例
  10080. $scope.showImg = function() {
  10081. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  10082. box.show();
  10083. box.find('img').attr('src', src);
  10084. box.find('a').click(function(){
  10085. box.hide();
  10086. });
  10087. box.dblclick(function(){
  10088. box.hide();
  10089. });
  10090. };
  10091. // 下载模板
  10092. $scope.download = function() {
  10093. window.location.href = 'product/baseInfo/upload/template';
  10094. };
  10095. }]);
  10096. /**
  10097. * 物料详情
  10098. */
  10099. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$rootScope', '$modal', 'Products', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $rootScope, $modal, Products) {
  10100. BaseService.scrollBackToTop();
  10101. // 录入人
  10102. AuthenticationService.getAuthentication().success(function(data) {
  10103. $scope.loading = false;
  10104. $scope.user = data;
  10105. });
  10106. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  10107. var loadData = function() {
  10108. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  10109. if(data.attach) {
  10110. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  10111. // 查看范例
  10112. $scope.showImg = function() {
  10113. var src = data.url, box = $('#image-box');
  10114. box.show();
  10115. box.find('img').attr('src', src);
  10116. box.find('a').click(function(){
  10117. box.hide();
  10118. });
  10119. box.dblclick(function(){
  10120. box.hide();
  10121. });
  10122. };
  10123. })
  10124. }
  10125. $scope.prodInfo = data;
  10126. if($scope.prodInfo.standard != 1 ) {// 非标准的先进行匹配
  10127. Products.matchone({id: $scope.prodInfo.id}, {}, function(data) {
  10128. $scope.matchresults = data;
  10129. }, function(response) {
  10130. toaster.pop('error', '提示', response.data);
  10131. });
  10132. }
  10133. if ($rootScope.isProductEdit) { // 是否点击编辑
  10134. $scope.prodInfo.$editing = true;
  10135. } else {
  10136. $scope.prodInfo.$editing = false;
  10137. }
  10138. $rootScope.isProductEdit = false; // 第一次进入判断,后续不用
  10139. $scope.loading = false;
  10140. });
  10141. };
  10142. loadData();
  10143. //更新为标准器件
  10144. $scope.updateone = function(id) {
  10145. Products.updateone({id: id}, {}, function(data) {
  10146. if(data.success) {
  10147. toaster.pop('success', '提示', data.success);
  10148. }
  10149. }, function(response) {
  10150. toaster.pop('error', '提示', response.data);
  10151. });
  10152. }
  10153. // 选择类目
  10154. $scope.selectKind = function(cmpcode) {
  10155. if(cmpcode == null) {
  10156. $modal.open({
  10157. animation: true,
  10158. size: 'lg',
  10159. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  10160. controller: 'KindChooseCtrl',
  10161. }).result.then(function(data){
  10162. $scope.kindId = data;
  10163. var modalInstance = $modal.open({
  10164. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  10165. controller: 'FindComponentCtrl',
  10166. size: 'lg',
  10167. resolve: {
  10168. KindId: function() {
  10169. return $scope.kindId;
  10170. }
  10171. }
  10172. });
  10173. modalInstance.result.then(function(data) {
  10174. $scope.prodInfo.cmpUuId = data.uuid;
  10175. $scope.prodInfo.pcmpcode = data.code;
  10176. $scope.prodInfo.pbranden = data.brand.nameEn;
  10177. $scope.prodInfo.pbrand = data.brand.nameCn;
  10178. }, function(){
  10179. });
  10180. }, function(){
  10181. });
  10182. }
  10183. };
  10184. $scope.isShow = true;
  10185. // 更新
  10186. $scope.update = function() {
  10187. $scope.prodInfo.$editing = true;
  10188. $scope.isShow = true;
  10189. };
  10190. // 取消
  10191. $scope.cancel = function() {
  10192. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  10193. $scope.prodInfo = data;
  10194. $scope.prodInfo.$editing = false;
  10195. $scope.isShow = false;
  10196. $scope.loading = false;
  10197. });
  10198. };
  10199. // 删除
  10200. $scope.clearfile = function() {
  10201. $scope.myFiles = null;
  10202. $scope.previewShow = false;
  10203. }
  10204. //删除
  10205. $scope.deleteById = function(id) {
  10206. GetProductInfo.deleteById({id: id}, function(data) {
  10207. if(data.error) {
  10208. toaster.pop("error", "提示", data.error);
  10209. } else {
  10210. toaster.pop("success", "提示", "删除成功");
  10211. window.location.href = "#/sale/prodList";
  10212. }
  10213. }), function(response) {
  10214. toaster.pop("error", "删除失败", response.data);
  10215. };
  10216. };
  10217. $scope.submit = function(prodInfo) {
  10218. $scope.prodInfo.isSale = 1;
  10219. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  10220. $upload.upload({
  10221. url: 'product/baseInfo/updateProdInfo',
  10222. file: file,
  10223. method: 'POST',
  10224. data: {
  10225. prodInfo: $scope.prodInfo
  10226. },
  10227. }).success(function(data) {
  10228. if(data.success) {
  10229. toaster.pop('success', '提示', data.success);
  10230. $rootScope.isProductEdit = false;
  10231. // loadData();
  10232. window.location.href="#/sale/prodList";
  10233. }
  10234. if(data.error) {
  10235. toaster.pop('error', '提示', data.error);
  10236. }
  10237. }).error(function(data) {
  10238. $scope.loadingShow = false;
  10239. toaster.pop('error', '操作失败', data.error);
  10240. });
  10241. }
  10242. $scope.previewShow = false;
  10243. $scope.pdfShow = false;
  10244. $scope.noneFileShow = true;
  10245. $scope.$watch('myFiles', function(){
  10246. if($scope.myFiles) {
  10247. $scope.noneFileShow = false;
  10248. var file = $scope.myFiles[0];
  10249. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  10250. $scope.pdfShow = true;
  10251. $scope.previewShow = false;
  10252. $scope.imgPreviewName = file.name;
  10253. } else{
  10254. if (typeof(Worker) !== "undefined") {//支持HTML5
  10255. $scope.imgPreview = getObjectURL(file);
  10256. $scope.imgPreviewName = file.name;
  10257. } else{//不支持HTML5
  10258. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  10259. $scope.imgPreviewName = file.name;
  10260. }
  10261. $scope.previewShow = true;
  10262. $scope.pdfShow = false;
  10263. }
  10264. } else {
  10265. $scope.noneFileShow = true;
  10266. $scope.previewShow = false;
  10267. $scope.pdfShow = false;
  10268. }
  10269. });
  10270. //建立一个可存取到该file的url
  10271. var getObjectURL = function(file) {
  10272. var url = null ;
  10273. if (window.createObjectURL!=undefined) { // basic
  10274. url = window.createObjectURL(file) ;
  10275. } else if (window.URL!=undefined) { // mozilla(firefox)
  10276. url = window.URL.createObjectURL(file) ;
  10277. } else if (window.webkitURL!=undefined) { // webkit or chrome
  10278. url = window.webkitURL.createObjectURL(file) ;
  10279. }
  10280. return url ;
  10281. };
  10282. }]);
  10283. /**
  10284. * 新增物料(销售)
  10285. */
  10286. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', 'Products', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService, Products) {
  10287. BaseService.scrollBackToTop();
  10288. // 录入人
  10289. AuthenticationService.getAuthentication().success(function(data) {
  10290. $scope.loading = false;
  10291. $scope.user = data;
  10292. });
  10293. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  10294. $scope.prodInfo = {};
  10295. // 选择类目
  10296. $scope.selectKind = function() {
  10297. $modal.open({
  10298. animation: true,
  10299. size: 'lg',
  10300. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  10301. controller: 'KindChooseCtrl',
  10302. }).result.then(function(data){
  10303. $scope.kindId = data;
  10304. var modalInstance = $modal.open({
  10305. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  10306. controller: 'FindComponentCtrl',
  10307. size: 'lg',
  10308. resolve: {
  10309. KindId: function() {
  10310. return $scope.kindId;
  10311. }
  10312. }
  10313. });
  10314. modalInstance.result.then(function(data) {
  10315. $scope.prodInfo.cmpUuId = data.uuid;
  10316. $scope.prodInfo.pcmpcode = data.code;
  10317. $scope.prodInfo.pbranden = data.brand.nameEn;
  10318. $scope.prodInfo.pbrand = data.brand.nameCn;
  10319. }, function(){
  10320. });
  10321. }, function(){
  10322. });
  10323. };
  10324. // 联想词 start
  10325. // 获取类目
  10326. $scope.getSimilarKinds = function(value) {
  10327. if (value) {
  10328. return Products.getSimilarKind({keyword : value}).$promise.then(function(data) {
  10329. return data.map(function(item) {
  10330. return item;
  10331. });
  10332. });
  10333. }
  10334. };
  10335. $scope.onAssociateKindClick = function(kind, prodInfo) {
  10336. $scope.prodInfo.title = kind.kindCn;
  10337. }
  10338. $scope.getSimilarBrands = function(value) {
  10339. if(value) {
  10340. return Products.getSimilarBrand({keyword: value}).$promise.then(function(data) {
  10341. return data.map(function(item) {
  10342. return item;
  10343. });
  10344. });
  10345. }
  10346. }
  10347. $scope.onAssociateBrandClick = function(brand, prodInfo) {
  10348. $scope.prodInfo.brand = brand.brandEn;
  10349. }
  10350. $scope.getSimilarComponents = function(value) {
  10351. if(value) {
  10352. return Products.getSimilarComponent({keyword: value}).$promise.then(function(data) {
  10353. return data.map(function(item) {
  10354. return item;
  10355. });
  10356. });
  10357. }
  10358. }
  10359. $scope.onAssociateComponentClick = function(cmp, prodInfo) {
  10360. $scope.prodInfo.cmpCode = cmp.code;
  10361. }
  10362. // 联想词 end
  10363. // 删除
  10364. $scope.clearfile = function() {
  10365. $scope.myFiles = null;
  10366. $scope.previewShow = false;
  10367. }
  10368. //提交
  10369. $scope.submit = function(prodInfo){
  10370. $scope.prodInfo.isSale = 1;
  10371. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  10372. $upload.upload({
  10373. url: 'product/baseInfo/addNewProduct',
  10374. file: file,
  10375. method: 'POST',
  10376. data: {
  10377. prodInfo: prodInfo
  10378. },
  10379. }).success(function(data) {
  10380. if(data.success) {
  10381. toaster.pop('success', '提示', data.success);
  10382. $timeout(function() {
  10383. //提交后跳转到详情页面,防止重复提交
  10384. // window.location.href="#/sale/prodList/"+data.id;
  10385. window.location.href="#/sale/prodList";
  10386. }, 500);
  10387. }
  10388. if(data.error) {
  10389. toaster.pop('error', '提示', data.error);
  10390. $timeout(function() {
  10391. //提交后跳转到详情页面,防止重复提交
  10392. // window.location.href="#/sale/prodList/"+data.id;
  10393. window.location.href="#/sale/prodList";
  10394. }, 500);
  10395. }
  10396. }).error(function(data) {
  10397. $scope.loadingShow = false;
  10398. toaster.pop('error', '操作失败', data.error);
  10399. });
  10400. };
  10401. $scope.previewShow = false;
  10402. $scope.pdfShow = false;
  10403. $scope.noneFileShow = true;
  10404. $scope.$watch('myFiles', function(){
  10405. if($scope.myFiles) {
  10406. $scope.noneFileShow = false;
  10407. var file = $scope.myFiles[0];
  10408. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  10409. $scope.pdfShow = true;
  10410. $scope.previewShow = false;
  10411. $scope.imgPreviewName = file.name;
  10412. } else{
  10413. if (typeof(Worker) !== "undefined") {//支持HTML5
  10414. $scope.imgPreview = getObjectURL(file);
  10415. $scope.imgPreviewName = file.name;
  10416. } else{//不支持HTML5
  10417. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  10418. $scope.imgPreviewName = file.name;
  10419. }
  10420. $scope.previewShow = true;
  10421. $scope.pdfShow = false;
  10422. }
  10423. } else {
  10424. $scope.noneFileShow = true;
  10425. $scope.previewShow = false;
  10426. $scope.pdfShow = false;
  10427. }
  10428. });
  10429. //建立一个可存取到该file的url
  10430. var getObjectURL = function(file) {
  10431. var url = null ;
  10432. if (window.createObjectURL!=undefined) { // basic
  10433. url = window.createObjectURL(file) ;
  10434. } else if (window.URL!=undefined) { // mozilla(firefox)
  10435. url = window.URL.createObjectURL(file) ;
  10436. } else if (window.webkitURL!=undefined) { // webkit or chrome
  10437. url = window.webkitURL.createObjectURL(file) ;
  10438. }
  10439. return url ;
  10440. };
  10441. // 取消
  10442. $scope.cancel = function(){
  10443. $scope.prodInfo = angular.copy($scope.prodInfo);
  10444. };
  10445. }]);
  10446. /**
  10447. * 类目选择模态框
  10448. */
  10449. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  10450. $scope.kindId = null;
  10451. $scope.kinds = [[], [], [], []];
  10452. // 获取子类目
  10453. var getChildren = function(pid, deep) {
  10454. KindAPI.getChildren({parentId: pid}, function(data) {
  10455. $scope.kinds[deep] = data;
  10456. }, function(response) {
  10457. toaster.pop('error', '获取子类目失败', response.data);
  10458. });
  10459. };
  10460. // 改变节点选中状态
  10461. var changeStatus = function(item, deep) {
  10462. var kindId = null, level = 0;
  10463. angular.forEach($scope.kinds, function(ks, i) {
  10464. if(i > deep) {
  10465. $scope.kinds[i] = [];
  10466. } else {
  10467. angular.forEach(ks, function(k, j) {
  10468. if(i == deep) {
  10469. if(k.id == item.id) {
  10470. $scope.kinds[i][j].$active = true;
  10471. kindId = k.id;
  10472. } else {
  10473. k.$active = null;
  10474. }
  10475. }
  10476. });
  10477. }
  10478. });
  10479. // 选择的节点
  10480. $scope.kindId = kindId;
  10481. $scope.active = item;
  10482. // 当前可操作的层级
  10483. if(deep < 3) {
  10484. $scope.activeDeep = deep + 1;
  10485. }
  10486. };
  10487. // 节点点击后获取子类目,节点被选中
  10488. $scope.onItemClick = function(item, deep) {
  10489. changeStatus(item, deep);
  10490. if (!item.isLeaf) {
  10491. getChildren(item.id, deep + 1);
  10492. }
  10493. };
  10494. // 重新加载数据
  10495. function reload(deep) {
  10496. var pid;
  10497. if(deep) {
  10498. pid = $scope.actives[deep - 1].id;
  10499. } else {
  10500. pid = 0;
  10501. deep = 0;
  10502. }
  10503. getChildren(pid, deep);
  10504. }
  10505. // 初始加载数据,获取第一层的类目
  10506. if($scope.actives) {
  10507. angular.forEach($scope.actives, function(v, k) {
  10508. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  10509. $scope.kinds[k] = data;
  10510. angular.forEach($scope.kinds[k], function(kind, i){
  10511. if(kind.id == v.id) {
  10512. $scope.kinds[k][i].$active = true;
  10513. $scope.actives[k] = $scope.kinds[k][i];
  10514. }
  10515. })
  10516. }, function(response) {
  10517. toaster.pop('error', '获取子类目失败', response.data);
  10518. });
  10519. });
  10520. } else {
  10521. reload();
  10522. }
  10523. // 取消
  10524. $scope.cancel = function() {
  10525. $modalInstance.dismiss();
  10526. };
  10527. // 确认选择
  10528. $scope.check = function() {
  10529. $modalInstance.close($scope.kindId);
  10530. };
  10531. }]);
  10532. /**
  10533. * 器件筛选
  10534. */
  10535. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  10536. //状态
  10537. $scope.setActive = function (state){
  10538. if($scope.active != state) {
  10539. $scope.active = state;
  10540. if($scope.tableParams.page() == 1)
  10541. $scope.tableParams.reload();
  10542. else
  10543. $scope.tableParams.page(1);
  10544. }
  10545. };
  10546. $scope.tableParams = new ngTableParams({
  10547. page : 1,
  10548. count : 20
  10549. }, {
  10550. total : 0,
  10551. counts: [5, 10, 25, 50],
  10552. getData : function($defer, params) {
  10553. $scope.loading = true;
  10554. var pageParams = params.url();
  10555. pageParams.keyword = $scope.keyword;
  10556. pageParams.kindId = KindId;
  10557. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  10558. $scope.loading = false;
  10559. if(page) {
  10560. params.total(page.totalElement);
  10561. $defer.resolve(page.content);
  10562. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10563. }
  10564. }, function(response){
  10565. $scope.loading = false;
  10566. toaster.pop('error', '数据加载失败', response.data);
  10567. });
  10568. }
  10569. });
  10570. // 取消
  10571. $scope.cancel = function() {
  10572. $modalInstance.dismiss();
  10573. };
  10574. // 选择
  10575. $scope.check = function(data){
  10576. $modalInstance.close(data);
  10577. };
  10578. // 搜索框回车
  10579. $scope.onSearch = function() {
  10580. $scope.tableParams.page(1);
  10581. $scope.tableParams.reload();
  10582. };
  10583. }]);
  10584. /**
  10585. * 企业列表
  10586. */
  10587. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  10588. BaseService.scrollBackToTop();
  10589. $scope.active = 'all';
  10590. $scope.agreedText = '全部';
  10591. $scope.dateZoneText = '一个月内';
  10592. $scope.condition = {dateZone: 1};
  10593. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10594. $scope.changeAgreed = function(agreed) {
  10595. $scope.condition.agreed = agreed;
  10596. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  10597. $scope.condition.$agreedOpen = false;
  10598. };
  10599. $scope.changeDateZone = function(zone) {
  10600. $scope.condition.dateZone = zone;
  10601. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  10602. $scope.condition.$dateZoneOpen = false;
  10603. getDateCondition(zone, $scope.condition);
  10604. $scope.tableParams.reload();
  10605. };
  10606. $scope.setActive = function(state) {
  10607. if($scope.active != state) {
  10608. $scope.active = state;
  10609. if($scope.tableParams.page() == 1)
  10610. $scope.tableParams.reload();
  10611. else
  10612. $scope.tableParams.page(1);
  10613. }
  10614. };
  10615. var getService = function() {
  10616. return getAccountUserSpace;
  10617. };
  10618. $scope.tableParams = new ngTableParams({
  10619. page : 1,
  10620. count : 20,
  10621. sorting: {
  10622. }
  10623. }, {
  10624. total : 0,
  10625. counts: [5, 10, 25, 50],
  10626. getData : function($defer, params) {
  10627. $scope.loading = true;
  10628. var pageParams = params.url();
  10629. pageParams.keyword = $scope.keyword;
  10630. $scope.tip = $scope.keyword;
  10631. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  10632. $scope.loading = false;
  10633. if(page) {
  10634. params.total(page.totalElement);
  10635. $defer.resolve(page.content);
  10636. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10637. }
  10638. }, function(response) {
  10639. $scope.loading = false;
  10640. toaster.pop('error', '数据加载失败', response.data);
  10641. });
  10642. }
  10643. });
  10644. // 搜索框回车
  10645. $scope.onSearch = function() {
  10646. $scope.tableParams.page(1);
  10647. $scope.tableParams.reload();
  10648. };
  10649. // 添加合作关系
  10650. $scope.addPartner = function(name, businessCode) {
  10651. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  10652. if(data.success) {
  10653. toaster.pop("success", '添加成功', data.success);
  10654. $scope.tableParams.reload();
  10655. }
  10656. if(data.error) {
  10657. toaster.pop("error", '添加失败', data.error);
  10658. }
  10659. }, function(response) {
  10660. toaster.pop('error','失败',response.data);
  10661. });
  10662. }
  10663. $scope.status = 'enList';
  10664. }]);
  10665. /**
  10666. * 新增采购单
  10667. */
  10668. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window) {
  10669. BaseService.scrollBackToTop();
  10670. // 每次进入时先清除掉rootScope下的venuu
  10671. $rootScope.venduu = null;
  10672. // 获取收货地址列表
  10673. ShipAddress.shipAddList({}, function(data) {
  10674. $scope.ships = data;
  10675. $scope.order.shipadd = $scope.ships[0];
  10676. });
  10677. // 获取地址信息
  10678. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10679. }).then(function(response) {
  10680. $scope.provinces = response.data;
  10681. });
  10682. $scope.order = {
  10683. date : new Date(),
  10684. cust : {
  10685. uu : '',
  10686. },
  10687. custUser : {
  10688. },
  10689. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  10690. orderItems : {
  10691. product : {},
  10692. },
  10693. rate: 17
  10694. };
  10695. //商品信息
  10696. $scope.order.orderItems = [];
  10697. var item = {
  10698. code: null,
  10699. title: null,
  10700. spec: null,
  10701. unit: null,
  10702. qty: null,
  10703. price: null,
  10704. remark: null,
  10705. delivery: null,
  10706. id: null,
  10707. };
  10708. if($rootScope.businessCode) {
  10709. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  10710. $scope.id = data.id;
  10711. $scope.order.cust.enName = data.vendorEnterprise.enName;
  10712. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  10713. $scope.order.cust.uu = data.vendorEnterprise.uu;
  10714. $scope.order.paymethods = data.paymethod;
  10715. $rootScope.venduu = data.vendorEnterprise.uu;
  10716. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10717. $scope.contacts = data;
  10718. $scope.order.vendor = $scope.contacts[0];
  10719. });
  10720. }, function(response) {
  10721. });
  10722. };
  10723. // 查找供应商
  10724. $scope.dbfindCust = function(){
  10725. var modalInstance = $modal.open({
  10726. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  10727. controller: 'DbfindVendorInfoCtrl',
  10728. size: 'lg',
  10729. resolve: {
  10730. orderItems: function() {
  10731. return $scope.order.orderItems;
  10732. }
  10733. }
  10734. });
  10735. modalInstance.result.then(function(data) {
  10736. $rootScope.venduu = data.vendorEnterprise.uu;
  10737. $scope.id = data.id;
  10738. $scope.order.cust = data.vendorEnterprise;
  10739. $scope.order.custUser = data.vendorUser;
  10740. $scope.order.payments = data.paymethod;
  10741. $scope.order.orderItems = [];
  10742. var item = {
  10743. code: null,
  10744. title: null,
  10745. spec: null,
  10746. unit: null,
  10747. qty: null,
  10748. price: null,
  10749. remark: null,
  10750. delivery: null,
  10751. };
  10752. // $scope.order.orderItems.push(item);
  10753. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10754. $scope.contacts = data;
  10755. $scope.order.vendor = $scope.contacts[0];
  10756. });
  10757. }, function(){
  10758. });
  10759. };
  10760. // 联想词 start
  10761. // 获取供应商
  10762. $scope.getSimilarVendors = function(value) {
  10763. if (value) {
  10764. return Vendor.getSimilarVendors({keyword : value}).$promise.then(function(data) {
  10765. return data.map(function(item) {
  10766. return item;
  10767. });
  10768. });
  10769. }
  10770. };
  10771. $scope.onAssociateCmpClick = function(vendor, order) {
  10772. $scope.order.cust.uu = vendor.venduu;
  10773. $scope.id = vendor.id;
  10774. $scope.order.payments = vendor.paymethod;
  10775. $rootScope.venduu = $scope.order.cust.uu;
  10776. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10777. $scope.contacts = data;
  10778. $scope.order.vendor = $scope.contacts[0];
  10779. });
  10780. }
  10781. // 联想词 end
  10782. // $scope.order.orderItems.push(item);
  10783. if($rootScope.prodId) {
  10784. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  10785. item.code = data.code;
  10786. item.title = data.title;
  10787. item.spec = data.spec;
  10788. item.unit = data.unit;
  10789. item.id = data.id;
  10790. $scope.order.orderItems.push(item);
  10791. $rootScope.prodId = null;// 清除掉prodId
  10792. }, function(response) {
  10793. });
  10794. }
  10795. //增加商品
  10796. $scope.addProduct = function(index) {
  10797. if($scope.order.orderItems[index].code == null) {
  10798. toaster.pop('info', '提示', '请先选择商品');
  10799. } else {
  10800. $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});
  10801. }
  10802. };
  10803. //删除商品
  10804. $scope.deleteProduct = function(index) {
  10805. $scope.order.orderItems.splice(index, 1);
  10806. };
  10807. // 搜索框回车
  10808. $scope.onSearch = function(keyword) {
  10809. $scope.keyword = keyword;
  10810. $scope.tableParams.page(1);
  10811. $scope.tableParams.reload();
  10812. };
  10813. $scope.tableParams = new ngTableParams({
  10814. page : 1,
  10815. count : 20
  10816. }, {
  10817. total : 0,
  10818. counts: [5, 10, 25, 50],
  10819. getData : function($defer, params) {
  10820. $scope.loading = true;
  10821. var pageParams = params.url();
  10822. pageParams.keyword = $scope.keyword;
  10823. $scope.tip = $scope.keyword;
  10824. pageParams.custUU = $scope.order.cust.uu;
  10825. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  10826. $scope.loading = false;
  10827. if(page) {
  10828. params.total(page.totalElement);
  10829. $scope.total = page.totalElement;
  10830. $defer.resolve(page.content);
  10831. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  10832. }
  10833. }, function(response){
  10834. $scope.loading = false;
  10835. toaster.pop('error', '数据加载失败', response.data);
  10836. });
  10837. }
  10838. });
  10839. // 选择
  10840. $scope.check = function(data) {
  10841. $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});
  10842. };
  10843. // 导入商品信息
  10844. $scope.uplodaByBatch = function() {
  10845. var modalInstance = $modal.open({
  10846. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  10847. controller: 'PurcUploadByBatchCtrl',
  10848. size: 'lg',
  10849. resolve: {
  10850. }
  10851. });
  10852. modalInstance.result.then(function(data) {
  10853. angular.forEach(data, function(prod) {
  10854. $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});
  10855. // for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  10856. // 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) { // 如果没有填写就删除这行数据
  10857. // $scope.inquiry.inquiryItems.splice(i, 1);
  10858. // }
  10859. // }
  10860. })
  10861. }, function(){
  10862. });
  10863. }
  10864. // 监听custuu发生变化,重新加载物料信息
  10865. $scope.$watch('order.cust.uu', function(n, o) {
  10866. if(n==o) {
  10867. return;
  10868. } else {
  10869. $scope.tableParams.page(1);
  10870. $scope.tableParams.reload();
  10871. }
  10872. }, true);
  10873. // 查找客户物料
  10874. $scope.dbfindCustProd = function(index){
  10875. if($scope.order.cust.uu) {
  10876. var modalInstance = $modal.open({
  10877. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  10878. controller: 'DbfindCustProdCtrl',
  10879. size: 'lg',
  10880. resolve: {
  10881. custUU: function() {
  10882. return $scope.order.cust.uu
  10883. }
  10884. }
  10885. });
  10886. modalInstance.result.then(function(data) {
  10887. $scope.order.orderItems.push(data);
  10888. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  10889. if($scope.order.orderItems[i].code == null || i == index) {
  10890. $scope.order.orderItems.splice(i, 1);
  10891. }
  10892. }
  10893. }, function() {
  10894. });
  10895. } else {
  10896. toaster.pop('info', '提示', '请先选择供应商');
  10897. }
  10898. };
  10899. $scope.getMinDate = function(item) {
  10900. return $filter('date')(new Date, 'yyyy-MM-dd');
  10901. };
  10902. $scope.openDatePicker = function($event, openParam, index) {
  10903. $event.preventDefault();
  10904. $event.stopPropagation();
  10905. $scope.order.orderItems[index].$endDateOpen = !openParam;
  10906. };
  10907. // 添加到购物车
  10908. $scope.addToCart = function(order) {
  10909. $scope.loading = true;
  10910. $scope.order.vendusertel = order.vendor.tel;
  10911. $scope.order.venduser = order.vendor.venduser;
  10912. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  10913. $scope.order.custUU = $scope.order.cust.uu;
  10914. $scope.order.custUserUU = $scope.order.custUser.userUU;
  10915. if($scope.order.date instanceof Date) {
  10916. $scope.order.date = $scope.order.date.getTime();
  10917. }
  10918. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  10919. if($scope.order.orderItems[i].delivery instanceof Date) {
  10920. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  10921. }
  10922. if($scope.order.currency != 'RMB') {
  10923. $scope.order.orderItems[i].rate = 0;
  10924. }
  10925. }
  10926. addtoCart.save({}, $scope.order, function(data){
  10927. $scope.loading = false;
  10928. toaster.pop('success', '成功', '保存成功');
  10929. window.location.hash = '#/purc/cart/'+data.id;
  10930. $window.location.reload();
  10931. }, function(response){
  10932. $scope.loading = false;
  10933. toaster.pop('error', '保存失败', response.data);
  10934. });
  10935. };
  10936. // 立即购买
  10937. $scope.addToOrder = function(order) {
  10938. $scope.loading = true;
  10939. $scope.order.vendusertel = order.vendor.tel;
  10940. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  10941. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  10942. $scope.order.custUU = $scope.order.cust.uu;
  10943. $scope.order.custUserUU = $scope.order.custUser.userUU;
  10944. if($scope.order.date instanceof Date) {
  10945. $scope.order.date = $scope.order.date.getTime();
  10946. }
  10947. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  10948. if($scope.order.orderItems[i].delivery instanceof Date) {
  10949. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  10950. }
  10951. if($scope.order.currency != 'RMB') {
  10952. $scope.order.orderItems[i].rate = 0;
  10953. }
  10954. }
  10955. newPurcOrder.save({}, $scope.order, function(data){
  10956. $scope.loading = false;
  10957. toaster.pop('success', '成功', '保存成功');
  10958. window.location.hash = '#/purc/order/'+data.id;
  10959. }, function(response){
  10960. $scope.loading = false;
  10961. toaster.pop('error', '保存失败', response.data);
  10962. });
  10963. };
  10964. // 新增收货地址保存
  10965. $scope.saveShipAddress = function(ship) {
  10966. ship.address = ship.province + ship.city + ship.district;
  10967. ShipAddress.saveAddress( {}, ship, function(data) {
  10968. if(data.success) {
  10969. ShipAddress.shipAddList({}, function(data) {
  10970. $scope.ships = data;
  10971. $scope.order.shipadd = $scope.ships[0];
  10972. });
  10973. toaster.pop('success', '提示', data.success);
  10974. }
  10975. if(data.error) {
  10976. toaster.pop('error', '提示', data.error);
  10977. }
  10978. });
  10979. }
  10980. // 新增供应商联系人
  10981. $scope.addContact = function(uu) {
  10982. var modalInstance = $modal.open({
  10983. animation: true,
  10984. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  10985. controller: 'AddContacCtrl',
  10986. resolve: {
  10987. }
  10988. });
  10989. modalInstance.result.then(function(data) {
  10990. $scope.contact = data;
  10991. $scope.contact.venduu = uu;
  10992. Vendor.saveContact({}, $scope.contact, function(data) {
  10993. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  10994. $scope.contacts = data;
  10995. $scope.order.vendor = $scope.contacts[0];
  10996. });
  10997. toaster.pop('success', '提示', '联系人保存成功');
  10998. }, function(response) {
  10999. toaster.pop('error', '失败', response.data);
  11000. });
  11001. });
  11002. }
  11003. }]);
  11004. /**
  11005. * 采购批量导入
  11006. */
  11007. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  11008. // 通过excel批量上传物料
  11009. $scope.result = null;
  11010. $scope.upload = function() {
  11011. var file = $scope.myFiles[0];
  11012. $upload.upload({
  11013. url: 'purchase/release/excel',
  11014. file: file,
  11015. method: 'POST'
  11016. }).success(function(data) {
  11017. $scope.result = data;
  11018. $scope.success = $scope.result.success;
  11019. $scope.total = $scope.result.total;
  11020. $scope.alters = $scope.result.alters;
  11021. }).error(function(response) {
  11022. toaster.pop('error', response.data || response);
  11023. });
  11024. };
  11025. // 下载模板
  11026. $scope.download = function() {
  11027. window.location.href = 'purchase/upload/template';
  11028. };
  11029. $scope.enSure = function() {
  11030. $modalInstance.close($scope.result.products);
  11031. }
  11032. $scope.cancel = function() {
  11033. $modalInstance.dismiss();
  11034. }
  11035. }]);
  11036. // 查找供应商
  11037. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  11038. $scope.prod = false;
  11039. if(orderItems.length != 0) {
  11040. $scope.prod = true;
  11041. }
  11042. BaseService.scrollBackToTop();
  11043. if($rootScope.venduu != null) {
  11044. $scope.venduu = $rootScope.venduu;
  11045. }
  11046. // 搜索框回车
  11047. $scope.onSearch = function(keyword) {
  11048. $scope.keyword = keyword;
  11049. $scope.customerParams.page(1);
  11050. $scope.customerParams.reload();
  11051. };
  11052. $scope.customerParams = new ngTableParams({
  11053. page : 1,
  11054. count : 20
  11055. }, {
  11056. total : 0,
  11057. counts: [5, 10, 25, 50],
  11058. getData : function($defer, params) {
  11059. $scope.loading = true;
  11060. var pageParams = params.url();
  11061. pageParams.keyword = $scope.keyword;
  11062. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  11063. $scope.loading = false;
  11064. if(page) {
  11065. params.total(page.totalElement);
  11066. $defer.resolve(page.content);
  11067. }
  11068. $scope.totalCount = page.totalElement;
  11069. }, function(response){
  11070. $scope.loading = false;
  11071. toaster.pop('error', '数据加载失败', response.data);
  11072. });
  11073. }
  11074. });
  11075. $scope.cancel = function() {
  11076. $modalInstance.dismiss();
  11077. };
  11078. $scope.ensure = false;
  11079. $scope.check = function(vendor) { // 需要进行判断的选择
  11080. $scope.vendorInfo = vendor;
  11081. $scope.ensure = true;
  11082. };
  11083. $scope.checkVendor = function(vendor) { // 直接选择
  11084. $modalInstance.close(vendor);
  11085. }
  11086. }]);
  11087. /**
  11088. * 我的客户
  11089. */
  11090. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  11091. $scope.userInfoResult = true;
  11092. AuthenticationService.getAuthentication().success(function(data) {
  11093. $scope.loading = false;
  11094. $scope.thisUser = data;
  11095. });
  11096. var getCustInfos = function(custuu) {
  11097. if(custuu) {
  11098. VendorService.userInfo.query({uu:custuu},null,function(data) {
  11099. $scope.custInfos = data;
  11100. var getPage = function(page, size){
  11101. if($scope.custInfos) {
  11102. var result = {};
  11103. result.totalCount = $scope.custInfos.length;
  11104. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  11105. if($scope.custInfos.length % size == 0) {
  11106. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  11107. }else {
  11108. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  11109. }
  11110. result.first = page == 1;
  11111. result.last = page == result.totalPage;
  11112. result.page = page;
  11113. result.next = page - 0 + 1;
  11114. result.pre = page - 1;
  11115. return result;
  11116. }
  11117. }
  11118. $scope.userdata = getPage(1,4);
  11119. $scope.first = function (){
  11120. $scope.userdata = getPage($scope.userdata.pre,4);
  11121. }
  11122. $scope.last = function (){
  11123. $scope.userdata = getPage($scope.userdata.next,4);
  11124. }
  11125. }, function(response){
  11126. $scope.loading = false;
  11127. toaster.pop('error', '数据加载失败', response.data);
  11128. });
  11129. }
  11130. }
  11131. $scope.addUserInfo = function(customer) {
  11132. //TODO
  11133. if ($scope.thisUser.sys) {
  11134. var modalInstance = $modal.open({
  11135. animation: true,
  11136. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  11137. controller: 'AddUserInfoCtrl',
  11138. resolve: {
  11139. customer: function() {
  11140. return customer;
  11141. }
  11142. }
  11143. });
  11144. modalInstance.result.then(function(changed, checked){
  11145. if(changed) {
  11146. if(checked)
  11147. $scope.newUser.roles = checked;
  11148. else
  11149. loadUsers();
  11150. }
  11151. });
  11152. } else {
  11153. toaster.pop('error', '您不是管理员,无权限分配用户!');
  11154. }
  11155. }
  11156. $scope.showUserInfo = function(customer,boo) {
  11157. $scope.custInfo = customer;
  11158. if(boo) {
  11159. getCustInfos(customer.myEnterprise.uu);
  11160. $scope.userInfoResult = true;
  11161. }
  11162. }
  11163. $scope.customerParams = new ngTableParams({
  11164. page : 1,
  11165. count : 20
  11166. }, {
  11167. total : 0,
  11168. counts: [5, 10, 25, 50],
  11169. getData : function($defer, params) {
  11170. $scope.loading = true;
  11171. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  11172. $scope.loading = false;
  11173. if(page) {
  11174. params.total(page.totalElement);
  11175. $defer.resolve(page.content);
  11176. }
  11177. $scope.totalCount = page.totalElement;
  11178. }, function(response){
  11179. $scope.loading = false;
  11180. toaster.pop('error', '数据加载失败', response.data);
  11181. });
  11182. }
  11183. });
  11184. }]);
  11185. /**
  11186. * 我的供应商
  11187. */
  11188. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  11189. BaseService.scrollBackToTop();
  11190. // 搜索框回车
  11191. $scope.onSearch = function(keyword) {
  11192. $scope.keyword = keyword;
  11193. $scope.customerParams.page(1);
  11194. $scope.customerParams.reload();
  11195. };
  11196. $scope.customerParams = new ngTableParams({
  11197. page : 1,
  11198. count : 20
  11199. }, {
  11200. total : 0,
  11201. counts: [5, 10, 25, 50],
  11202. getData : function($defer, params) {
  11203. $scope.loading = true;
  11204. var pageParams = params.url();
  11205. pageParams.keyword = $scope.keyword;
  11206. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  11207. $scope.loading = false;
  11208. if(page) {
  11209. params.total(page.totalElement);
  11210. $scope.total = page.totalElement;
  11211. $defer.resolve(page.content);
  11212. }
  11213. $scope.totalCount = page.totalElement;
  11214. }, function(response){
  11215. $scope.loading = false;
  11216. toaster.pop('error', '数据加载失败', response.data);
  11217. });
  11218. }
  11219. });
  11220. // 查看供应商详情
  11221. $scope.VendorDetail = function(id, uu) {
  11222. $rootScope.vendorId = id;
  11223. $rootScope.vendoruu = uu;
  11224. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  11225. }
  11226. // 向企业购买
  11227. $scope.purcByEn = function(businessCode) {
  11228. $rootScope.businessCode = businessCode;
  11229. window.location.hash = "#/purc/addOrder";
  11230. }
  11231. }]);
  11232. /**
  11233. * 供应商详情
  11234. */
  11235. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  11236. BaseService.scrollBackToTop();
  11237. $scope.vendorContacts = [];
  11238. var loadData = function() {
  11239. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  11240. $scope.vendor = data.vendorEnterprise;
  11241. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  11242. $scope.vendorContacts = data;
  11243. });
  11244. });
  11245. };
  11246. loadData();
  11247. // 新增供应商联系人
  11248. $scope.addContact = function(uu) {
  11249. var modalInstance = $modal.open({
  11250. animation: true,
  11251. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  11252. controller: 'AddContacCtrl',
  11253. resolve: {
  11254. }
  11255. });
  11256. modalInstance.result.then(function(data) {
  11257. $scope.contact = data;
  11258. $scope.contact.venduu = uu;
  11259. Vendor.saveContact({}, $scope.contact, function(data) {
  11260. toaster.pop('success', '提示', '联系人保存成功');
  11261. $scope.vendorContacts.push(data);
  11262. }, function(response) {
  11263. toaster.pop('error', '失败', response.data);
  11264. });
  11265. });
  11266. };
  11267. // 编辑供应商联系人
  11268. $scope.edit = function(contact) {
  11269. var modalInstance = $modal.open({
  11270. animation: true,
  11271. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  11272. controller: 'EditContacCtrl',
  11273. resolve: {
  11274. contact: function() {
  11275. return contact;
  11276. }
  11277. }
  11278. });
  11279. modalInstance.result.then(function(data) {
  11280. Vendor.saveContact({}, data, function(data) {
  11281. loadData();
  11282. toaster.pop('success', '提示', '联系人修改成功');
  11283. }, function(response) {
  11284. toaster.pop('error', '失败', response.data);
  11285. });
  11286. });
  11287. }
  11288. // 删除供应商联系人
  11289. $scope.deleteById = function(id, index) {
  11290. $scope.vendorContacts.splice(index, 1);
  11291. Vendor.deleteContact({id: id}, {}, function(data) {
  11292. toaster.pop('success', '提示', '供应商联系人删除成功');
  11293. loadData();
  11294. }, function(response) {
  11295. toaster.pop('error', '提示', response.data);
  11296. });
  11297. }
  11298. // 供应商物料信息
  11299. $scope.viewProdList = function(uu){
  11300. $scope.uu = uu;
  11301. $scope.tableParams.page(1);
  11302. $scope.tableParams.reload();
  11303. };
  11304. // 搜索框回车
  11305. $scope.onSearch = function(keyword) {
  11306. $scope.keyword = keyword;
  11307. $scope.tableParams.page(1);
  11308. $scope.tableParams.reload();
  11309. };
  11310. // 供应商物料信息
  11311. $scope.tableParams = new ngTableParams({
  11312. page : 1,
  11313. count : 20
  11314. }, {
  11315. total : 0,
  11316. counts: [5, 10, 25, 50],
  11317. getData : function($defer, params) {
  11318. $scope.loading = true;
  11319. var pageParams = params.url();
  11320. pageParams.custUU = $scope.uu;
  11321. pageParams.keyword = $scope.keyword;
  11322. $scope.tip = $scope.keyword;
  11323. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  11324. $scope.loading = false;
  11325. if(page) {
  11326. params.total(page.totalElement);
  11327. $scope.total = page.totalElement;
  11328. $defer.resolve(page.content);
  11329. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  11330. }
  11331. }, function(response){
  11332. $scope.loading = false;
  11333. toaster.pop('error', '数据加载失败', response.data);
  11334. });
  11335. }
  11336. });
  11337. /**
  11338. * 选中单个物料购买
  11339. * @param businessCode
  11340. * @param id
  11341. */
  11342. $scope.PurcByEnAndProd = function(businessCode, id) {
  11343. $rootScope.businessCode = businessCode;
  11344. $rootScope.prodId = id;
  11345. window.location.hash = "#/purc/addOrder";
  11346. }
  11347. /**
  11348. * 询价
  11349. */
  11350. $scope.PurcInquiry = function(businessCode, id){
  11351. $rootScope.prodId = id;
  11352. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  11353. }
  11354. }]);
  11355. /**
  11356. * 编辑供应商联系人
  11357. */
  11358. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  11359. $scope.contact = angular.copy(contact);
  11360. $scope.save = function(contact) {
  11361. $modalInstance.close(contact);
  11362. };
  11363. $scope.cancel = function() {
  11364. $modalInstance.dismiss();
  11365. }
  11366. }]);
  11367. /**
  11368. * 新增供应商联系人
  11369. */
  11370. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  11371. $scope.save = function(contact) {
  11372. $modalInstance.close(contact);
  11373. };
  11374. $scope.cancel = function() {
  11375. $modalInstance.dismiss();
  11376. }
  11377. }]);
  11378. /**
  11379. * 建立合作关系申请 (我的合作伙伴)
  11380. */
  11381. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  11382. BaseService.scrollBackToTop();
  11383. $scope.status = "partner";
  11384. $scope.active = 'done';
  11385. var getRequestStatus = function(active) {
  11386. var fn = 'getAllRequest';
  11387. switch(active) {
  11388. case 'done':
  11389. fn = 'getRequestDone';break;
  11390. case 'todo':
  11391. fn = 'getRequestTodo';break;
  11392. case 'end':
  11393. fn = 'getRequestEnd';break;
  11394. }
  11395. return fn;
  11396. }
  11397. // 切换单据类型
  11398. $scope.setActive = function(state) {
  11399. if($scope.active != state) {
  11400. $scope.active = state;
  11401. if($scope.tableParams.page() == 1)
  11402. $scope.tableParams.reload();
  11403. else
  11404. $scope.tableParams.page(1);
  11405. }
  11406. };
  11407. // 切换数据来源(正常数据 or 历史数据)
  11408. var getService = function() {
  11409. return AddPartnerMyRequest;
  11410. };
  11411. $scope.tableParams = new ngTableParams({ // ng-Table参数
  11412. page : 1,
  11413. count : 20,
  11414. sorting: {
  11415. }
  11416. }, {
  11417. total : 0,
  11418. counts: [],
  11419. getData : function($defer, params) { // 获取数据的方法
  11420. $scope.loading = true;
  11421. var pageParams = params.url();
  11422. pageParams.keyword = $scope.keyword;
  11423. if($rootScope.vendName) {
  11424. pageParams.keyword = $rootScope.vendName;
  11425. $scope.keyword = $rootScope.vendName;
  11426. $rootScope.vendName = null;
  11427. }
  11428. $scope.tip = $scope.keyword;
  11429. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11430. $scope.loading = false;
  11431. if(page) {
  11432. params.total(page.totalElement);
  11433. $defer.resolve(page.content);
  11434. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11435. }
  11436. }, function(response){
  11437. $scope.loading = false;
  11438. toaster.pop('error', '数据加载失败', response.data);
  11439. });
  11440. }
  11441. });
  11442. // 再次申请
  11443. $scope.addAgain = function(name, businessCode) {
  11444. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  11445. if(data.success) {
  11446. toaster.pop("success", '添加成功', data.success);
  11447. $scope.tableParams.reload();
  11448. }
  11449. if(data.error) {
  11450. toaster.pop("error", '添加失败', data.error);
  11451. }
  11452. }, function(response) {
  11453. toaster.pop('error','失败',response.data);
  11454. });
  11455. }
  11456. // 添加为供应商
  11457. $scope.addSupplier = function(vendUID) {
  11458. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  11459. if(data.success) {
  11460. toaster.pop('success', '提示', data.success);
  11461. $scope.tableParams.reload();
  11462. }
  11463. if(data.error) {
  11464. toaster.pop('error','提示', data.error);
  11465. }
  11466. }, function(response) {
  11467. toaster.pop('error', '失败', response.data);
  11468. })
  11469. };
  11470. // 添加客户
  11471. $scope.addCust = function(vendUID) {
  11472. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  11473. if(data.success) {
  11474. toaster.pop('success', '提示', data.success);
  11475. $scope.tableParams.reload();
  11476. }
  11477. if(data.error) {
  11478. toaster.pop('error','提示', data.error);
  11479. }
  11480. }, function(response) {
  11481. toaster.pop('error', '失败', response.data);
  11482. })
  11483. };
  11484. // 搜索框回车
  11485. $scope.onSearch = function() {
  11486. $scope.tableParams.page(1);
  11487. $scope.tableParams.reload();
  11488. };
  11489. // 同意申请
  11490. $scope.agree = function(id) {
  11491. AddPartner.agreeRequest({id: id}, {}, function(data) {
  11492. toaster.pop('success', '提示', '操作成功');
  11493. $scope.tableParams.reload();
  11494. // $window.location.reload();
  11495. }, function(response) {
  11496. toaster.pop('error', '提示', response.data);
  11497. });
  11498. };
  11499. // 拒绝申请
  11500. $scope.refuse = function(id, reason) {
  11501. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  11502. toaster.pop('success', '提示', '操作成功');
  11503. $scope.tableParams.reload();
  11504. // $window.location.reload();
  11505. }, function(response) {
  11506. toaster.pop('error', '提示', response.data);
  11507. });
  11508. };
  11509. // 取消供应商关系
  11510. $scope.relieve = function(id) {
  11511. VendorInfo.relieve({id: id}, {}, function(data) {
  11512. if(data.success) {
  11513. toaster.pop('success', '提示', data.success);
  11514. }
  11515. $scope.tableParams.page(1);
  11516. $scope.tableParams.reload();
  11517. }, function(response) {
  11518. toaster.pop('error', '提示', response.data);
  11519. });
  11520. };
  11521. // 建立供应商关系
  11522. $scope.activeVend = function(id) {
  11523. VendorInfo.activeVend({id: id}, {}, function(data) {
  11524. if(data.success) {
  11525. toaster.pop('success', '提示', data.success);
  11526. }
  11527. $scope.tableParams.page(1);
  11528. $scope.tableParams.reload();
  11529. }, function(response) {
  11530. toaster.pop('error', '提示', response.data);
  11531. });
  11532. }
  11533. // 取消客户关系
  11534. $scope.disableCust = function(id) {
  11535. VendorInfo.disableCust({id: id}, {}, function(data) {
  11536. if(data.success) {
  11537. toaster.pop('success', '提示', data.success);
  11538. }
  11539. $scope.tableParams.page(1);
  11540. $scope.tableParams.reload();
  11541. }, function(response) {
  11542. toaster.pop('error', '提示', response.data);
  11543. });
  11544. }
  11545. // 激活客户关系
  11546. $scope.activeCust = function(id) {
  11547. VendorInfo.activeCust({id: id}, {}, function(data) {
  11548. if(data.success) {
  11549. toaster.pop('success', '提示', data.success);
  11550. }
  11551. $scope.tableParams.page(1);
  11552. $scope.tableParams.reload();
  11553. }, function(response) {
  11554. toaster.pop('error', '提示', response.data);
  11555. });
  11556. }
  11557. }]);
  11558. /**
  11559. * 建立合作关系申请 (新的合作伙伴)
  11560. */
  11561. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  11562. BaseService.scrollBackToTop();
  11563. $scope.status = "partner";
  11564. $scope.active = 'all'; // 所有申请记录
  11565. var getRequestStatus = function(active) {
  11566. var fn = 'getAllRequest';
  11567. switch(active) {
  11568. case 'done':
  11569. fn = 'getRequestDone';break;
  11570. case 'todo':
  11571. fn = 'getRequestTodo';break;
  11572. case 'end':
  11573. fn = 'getRequestEnd';break;
  11574. }
  11575. return fn;
  11576. }
  11577. // 切换单据类型
  11578. $scope.setActive = function(state) {
  11579. if($scope.active != state) {
  11580. $scope.active = state;
  11581. if($scope.tableParams.page() == 1)
  11582. $scope.tableParams.reload();
  11583. else
  11584. $scope.tableParams.page(1);
  11585. }
  11586. };
  11587. // 切换数据来源(正常数据 or 历史数据)
  11588. var getService = function() {
  11589. return AddPartnerMyRequest;
  11590. };
  11591. $scope.tableParams = new ngTableParams({ // ng-Table参数
  11592. page : 1,
  11593. count : 20,
  11594. sorting: {
  11595. }
  11596. }, {
  11597. total : 0,
  11598. counts: [],
  11599. getData : function($defer, params) { // 获取数据的方法
  11600. $scope.loading = true;
  11601. var pageParams = params.url();
  11602. pageParams.keyword = $scope.keyword;
  11603. if($rootScope.vendName) {
  11604. pageParams.keyword = $rootScope.vendName;
  11605. $scope.keyword = $rootScope.vendName;
  11606. $rootScope.vendName = null;
  11607. }
  11608. $scope.tip = $scope.keyword;
  11609. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11610. $scope.loading = false;
  11611. if(page) {
  11612. params.total(page.totalElement);
  11613. $defer.resolve(page.content);
  11614. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11615. }
  11616. }, function(response){
  11617. $scope.loading = false;
  11618. toaster.pop('error', '数据加载失败', response.data);
  11619. });
  11620. }
  11621. });
  11622. // 再次申请
  11623. $scope.addAgain = function(name, businessCode) {
  11624. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  11625. if(data.success) {
  11626. toaster.pop("success", '添加成功', data.success);
  11627. $scope.tableParams.reload();
  11628. }
  11629. if(data.error) {
  11630. toaster.pop("error", '添加失败', data.error);
  11631. }
  11632. }, function(response) {
  11633. toaster.pop('error','失败',response.data);
  11634. });
  11635. }
  11636. // 添加为供应商
  11637. $scope.addSupplier = function(vendUID) {
  11638. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  11639. if(data.success) {
  11640. toaster.pop('success', '提示', data.success);
  11641. $scope.tableParams.reload();
  11642. }
  11643. if(data.error) {
  11644. toaster.pop('error','提示', data.error);
  11645. }
  11646. }, function(response) {
  11647. toaster.pop('error', '失败', response.data);
  11648. })
  11649. };
  11650. // 添加客户
  11651. $scope.addCust = function(vendUID) {
  11652. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  11653. if(data.success) {
  11654. toaster.pop('success', '提示', data.success);
  11655. $scope.tableParams.reload();
  11656. }
  11657. if(data.error) {
  11658. toaster.pop('error','提示', data.error);
  11659. }
  11660. }, function(response) {
  11661. toaster.pop('error', '失败', response.data);
  11662. })
  11663. };
  11664. // 搜索框回车
  11665. $scope.onSearch = function() {
  11666. $scope.tableParams.page(1);
  11667. $scope.tableParams.reload();
  11668. };
  11669. // 同意申请
  11670. $scope.agree = function(id) {
  11671. AddPartner.agreeRequest({id: id}, {}, function(data) {
  11672. toaster.pop('success', '提示', '操作成功');
  11673. $scope.tableParams.reload();
  11674. // $window.location.reload();
  11675. }, function(response) {
  11676. toaster.pop('error', '提示', response.data);
  11677. });
  11678. };
  11679. AddPartnerMyRequest.requestAmount({}, function(data) {
  11680. $scope.requestTodo = data;
  11681. });
  11682. // 拒绝申请
  11683. $scope.refuse = function(id, reason) {
  11684. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  11685. toaster.pop('success', '提示', '操作成功');
  11686. $scope.tableParams.reload();
  11687. // $window.location.reload();
  11688. }, function(response) {
  11689. toaster.pop('error', '提示', response.data);
  11690. });
  11691. };
  11692. // 取消供应商关系
  11693. $scope.relieve = function(id) {
  11694. VendorInfo.relieve({id: id}, {}, function(data) {
  11695. if(data.success) {
  11696. toaster.pop('success', '提示', data.success);
  11697. }
  11698. // $scope.tableParams.page(1);
  11699. $scope.tableParams.reload();
  11700. }, function(response) {
  11701. toaster.pop('error', '提示', response.data);
  11702. });
  11703. }
  11704. // 建立供应商关系
  11705. $scope.activeVend = function(id) {
  11706. VendorInfo.activeVend({id: id}, {}, function(data) {
  11707. if(data.success) {
  11708. toaster.pop('success', '提示', data.success);
  11709. }
  11710. // $scope.tableParams.page(1);
  11711. $scope.tableParams.reload();
  11712. }, function(response) {
  11713. toaster.pop('error', '提示', response.data);
  11714. });
  11715. }
  11716. // 取消客户关系
  11717. $scope.disableCust = function(id) {
  11718. VendorInfo.disableCust({id: id}, {}, function(data) {
  11719. if(data.success) {
  11720. toaster.pop('success', '提示', data.success);
  11721. }
  11722. // $scope.tableParams.page(1);
  11723. $scope.tableParams.reload();
  11724. }, function(response) {
  11725. toaster.pop('error', '提示', response.data);
  11726. });
  11727. }
  11728. // 激活客户关系
  11729. $scope.activeCust = function(id) {
  11730. VendorInfo.activeCust({id: id}, {}, function(data) {
  11731. if(data.success) {
  11732. toaster.pop('success', '提示', data.success);
  11733. }
  11734. // $scope.tableParams.page(1);
  11735. $scope.tableParams.reload();
  11736. }, function(response) {
  11737. toaster.pop('error', '提示', response.data);
  11738. });
  11739. }
  11740. }]);
  11741. /**
  11742. * 建立合作关系处理申请
  11743. */
  11744. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', '$window', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest, $window) {
  11745. BaseService.scrollBackToTop();
  11746. $scope.active = 'todo';
  11747. var getMessagetStatus = function(active) {
  11748. var fn = 'getAllMessage';
  11749. switch(active) {
  11750. case 'done':
  11751. fn = 'getMessageDone';break;
  11752. case 'todo':
  11753. fn = 'getMessageTodo';break;
  11754. case 'end':
  11755. fn = 'getMessageEnd';break;
  11756. }
  11757. return fn;
  11758. }
  11759. // 切换单据类型
  11760. $scope.setActive = function(state) {
  11761. if($scope.active != state) {
  11762. $scope.active = state;
  11763. if($scope.tableParams.page() == 1)
  11764. $scope.tableParams.reload();
  11765. else
  11766. $scope.tableParams.page(1);
  11767. }
  11768. };
  11769. var getService = function() {
  11770. return AddPartnerMyMessage;
  11771. };
  11772. $scope.tableParams = new ngTableParams({ // ng-Table参数
  11773. page : 1,
  11774. count : 20,
  11775. sorting: {
  11776. }
  11777. }, {
  11778. total : 0,
  11779. counts: [5, 10, 15, 25, 50],
  11780. getData : function($defer, params) { // 获取数据的方法
  11781. $scope.loading = true;
  11782. var pageParams = params.url();
  11783. pageParams.searchFilter = { // 筛选条件
  11784. keyword: $scope.keyword,
  11785. };
  11786. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11787. $scope.loading = false;
  11788. if(page) {
  11789. params.total(page.totalElement);
  11790. $defer.resolve(page.content);
  11791. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11792. }
  11793. }, function(response){
  11794. $scope.loading = false;
  11795. toaster.pop('error', '数据加载失败', response.data);
  11796. });
  11797. }
  11798. });
  11799. // 同意申请
  11800. $scope.agree = function(id) {
  11801. AddPartner.agreeRequest({id: id}, {}, function(data) {
  11802. toaster.pop('success', '提示', '操作成功');
  11803. $scope.tableParams.reload();
  11804. // $window.location.reload();
  11805. }, function(response) {
  11806. toaster.pop('error', '提示', response.data);
  11807. });
  11808. };
  11809. // 拒绝申请
  11810. $scope.refuse = function(id, reason) {
  11811. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  11812. toaster.pop('success', '提示', '操作成功');
  11813. $scope.tableParams.reload();
  11814. // $window.location.reload();
  11815. }, function(response) {
  11816. toaster.pop('error', '提示', response.data);
  11817. });
  11818. };
  11819. $scope.status = 'get';
  11820. }]);
  11821. /**
  11822. * 我的合作伙伴
  11823. */
  11824. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  11825. BaseService.scrollBackToTop();
  11826. // 默认显示合作伙伴
  11827. $scope.status = 'news';
  11828. // 获取所有的合作伙伴
  11829. GetProductInfo.getAllPartners({}, function(data) {
  11830. $scope.partners = data;
  11831. }, function(res) {
  11832. toaster.pop('error', '获取列表失败', res.data);
  11833. });
  11834. // 添加为客户
  11835. $scope.addCust = function(partner) {
  11836. GetProductInfo.addCust({}, partner, function(data) {
  11837. toaster.pop('success', '提示', '添加客户成功');
  11838. $scope.tableParams.reload();
  11839. }, function(response) {
  11840. toaster.pop('error', '添加客户失败', response.data);
  11841. });
  11842. }
  11843. // 添加为供应商
  11844. $scope.addSupplier = function(partner) {
  11845. GetProductInfo.addSupplier({}, partner, function(data) {
  11846. toaster.pop('success', '提示', '添加供应商成功');
  11847. $scope.tableParams.reload();
  11848. }, function(response) {
  11849. toaster.pop('error', '添加供应商失败', response.data);
  11850. });
  11851. }
  11852. }]);
  11853. /**
  11854. * 财务对账时,企业进行筛选操作
  11855. */
  11856. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  11857. var getData = function(){
  11858. $scope.loading = true;
  11859. FaApCheck.getAllCustomers(function(data) {
  11860. $scope.custs = data;
  11861. $scope.loading = false;
  11862. });
  11863. };
  11864. getData();
  11865. $scope.select = function(suuorname) {
  11866. $modalInstance.close(suuorname);
  11867. }
  11868. $scope.close = function() {
  11869. $modalInstance.close();
  11870. }
  11871. }]);
  11872. /**
  11873. * 跳转到企业圈
  11874. */
  11875. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  11876. GetProductInfo.businessGroups({}, function(data) {
  11877. window.open(data.url);
  11878. }, function(response) {
  11879. toaster.pop('error', '提示', response.data);
  11880. });
  11881. }]);
  11882. /**
  11883. * 购物车
  11884. */
  11885. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', 'cartList', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout, cartList) {
  11886. BaseService.scrollBackToTop();
  11887. $scope.active = 'all';
  11888. $scope.agreedText = '全部';
  11889. $scope.dateZoneText = '一个月内';
  11890. $scope.condition = {dateZone: 1};
  11891. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11892. $scope.changeAgreed = function(agreed) {
  11893. $scope.condition.agreed = agreed;
  11894. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11895. $scope.condition.$agreedOpen = false;
  11896. };
  11897. $scope.changeDateZone = function(zone) {
  11898. $scope.condition.dateZone = zone;
  11899. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11900. $scope.condition.$dateZoneOpen = false;
  11901. getDateCondition(zone, $scope.condition);
  11902. $scope.tableParams.reload();
  11903. };
  11904. $scope.setActive = function(state) {
  11905. if($scope.active != state) {
  11906. $scope.active = state;
  11907. if($scope.tableParams.page() == 1)
  11908. $scope.tableParams.reload();
  11909. else
  11910. $scope.tableParams.page(1);
  11911. }
  11912. };
  11913. $scope.searchMethod = false;
  11914. var getService = function() {
  11915. if($scope.searchMethod) {
  11916. return cartList;
  11917. } else {
  11918. return getCartList;
  11919. }
  11920. };
  11921. var getTodoCartCount = function() {
  11922. cartOperation.getTodoCartCount({}, function(data) {
  11923. $scope.countTodo = data.cartTodo;
  11924. });
  11925. };
  11926. getTodoCartCount();
  11927. $scope.tableParams = new ngTableParams({
  11928. page : 1,
  11929. count : 20,
  11930. sorting: {
  11931. date: 'desc'
  11932. }
  11933. }, {
  11934. total : 0,
  11935. counts: [5, 10, 25, 50],
  11936. getData : function($defer, params) {
  11937. $scope.loading = true;
  11938. var pageParams = params.url();
  11939. pageParams.keyword = $scope.keyword;
  11940. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  11941. $scope.loading = false;
  11942. if(page) {
  11943. params.total(page.totalElement);
  11944. $defer.resolve(page.content);
  11945. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11946. }
  11947. }, function(response) {
  11948. $scope.loading = false;
  11949. toaster.pop('error', '数据加载失败', response.data);
  11950. });
  11951. }
  11952. });
  11953. $scope.getCartTotal = function(items) {
  11954. var sum = 0;
  11955. angular.forEach(items, function(item){
  11956. sum += item.qty * item.price;
  11957. });
  11958. return sum;
  11959. };
  11960. // 搜索框回车
  11961. $scope.onSearch = function() {
  11962. $scope.searchMethod = true;
  11963. $scope.tableParams.page(1);
  11964. $scope.tableParams.reload();
  11965. };
  11966. // 提交
  11967. $scope.addtoOrder = function(id) {
  11968. cartOperation.addToOrder({id: id}, {}, function(data) {
  11969. if(data.success) {
  11970. toaster.pop('success', '提示', data.success);
  11971. $timeout(function() {
  11972. window.location.hash = '#/purc/order/'+data.id;
  11973. window.location.reload();
  11974. },500);
  11975. }
  11976. if(data.error) {
  11977. toaster.pop('error', '提示', data.error);
  11978. }
  11979. }, function(response) {
  11980. toaster.pop('erroer', '提示', response.data);
  11981. });
  11982. };
  11983. // 删除一条主记录
  11984. $scope.deleteCart = function(id) {
  11985. cartOperation.deleteCart({id: id}, {}, function(data) {
  11986. if(data.success) {
  11987. toaster.pop('success', '提示', data.success);
  11988. getTodoCartCount();
  11989. $timeout(function() {
  11990. $scope.tableParams.page(1);
  11991. $scope.tableParams.reload();
  11992. },500);
  11993. }
  11994. if(data.error) {
  11995. toaster.pop('error', '提示', data.error);
  11996. }
  11997. }, function(response) {
  11998. toaster.pop('erroer', '提示', response.data);
  11999. });
  12000. };
  12001. // 删除一条明细
  12002. $scope.deleteDetail = function(id) {
  12003. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  12004. if(data.success) {
  12005. toaster.pop('success', '提示', data.success);
  12006. $timeout(function() {
  12007. window.location.reload();
  12008. },500);
  12009. }
  12010. if(data.error) {
  12011. toaster.pop('error', '提示', data.error);
  12012. }
  12013. }, function(response) {
  12014. toaster.pop('erroer', '提示', response.data);
  12015. });
  12016. };
  12017. // 清空购物车
  12018. $scope.clearCart = function() {
  12019. cartOperation.deleteCarts({}, function(data) {
  12020. if(data.success) {
  12021. toaster.pop('success', '提示', data.success);
  12022. $timeout(function() {
  12023. window.location.reload();
  12024. },500);
  12025. }
  12026. if(data.error) {
  12027. toaster.pop('error', '提示', data.error);
  12028. }
  12029. }, function(response) {
  12030. toaster.pop('erroer', '提示', response.data);
  12031. });
  12032. }
  12033. }]);
  12034. /**
  12035. * 购物车详情
  12036. */
  12037. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  12038. BaseService.scrollBackToTop();
  12039. var loadData = function() {
  12040. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  12041. if(data.code) {
  12042. $scope.cart = data;
  12043. var sum = 0;
  12044. angular.forEach($scope.cart.cartDetails, function(item) {
  12045. sum += item.qty * item.price;
  12046. });
  12047. $scope.cart.total = sum;
  12048. $scope.loading = false;
  12049. } else {
  12050. window.location.hash = '#/purc/cart';
  12051. }
  12052. });
  12053. };
  12054. loadData();
  12055. // 删除一条明细
  12056. $scope.deleteDetail = function(id) {
  12057. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  12058. if(data.success) {
  12059. toaster.pop('success', '提示', data.success);
  12060. $timeout(function() {
  12061. window.location.reload();
  12062. },500);
  12063. }
  12064. if(data.error) {
  12065. toaster.pop('error', '提示', data.error);
  12066. }
  12067. }, function(response) {
  12068. toaster.pop('erroer', '提示', response.data);
  12069. });
  12070. };
  12071. // 删除一条主记录
  12072. $scope.deleteCart = function(id) {
  12073. cartOperation.deleteCart({id: id}, {}, function(data) {
  12074. if(data.success) {
  12075. toaster.pop('success', '提示', data.success);
  12076. $timeout(function() {
  12077. window.location.reload();
  12078. },500);
  12079. }
  12080. if(data.error) {
  12081. toaster.pop('error', '提示', data.error);
  12082. }
  12083. }, function(response) {
  12084. toaster.pop('erroer', '提示', response.data);
  12085. });
  12086. };
  12087. // 提交
  12088. $scope.addtoOrder = function(id) {
  12089. cartOperation.addToOrder({id: id}, {}, function(data) {
  12090. if(data.success) {
  12091. toaster.pop('success', '提示', data.success);
  12092. $timeout(function() {
  12093. window.location.hash = '#/purc/order/'+data.id;
  12094. window.location.reload();
  12095. },500);
  12096. }
  12097. if(data.error) {
  12098. toaster.pop('error', '提示', data.error);
  12099. }
  12100. }, function(response) {
  12101. toaster.pop('erroer', '提示', response.data);
  12102. });
  12103. };
  12104. }]);
  12105. /**
  12106. * 审批流
  12107. */
  12108. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  12109. BaseService.scrollBackToTop();
  12110. $scope.vacation = false;
  12111. $scope.workovertime = false;
  12112. $scope.workdaily = false;
  12113. $scope.feeplease = false;
  12114. $scope.signapp = false;
  12115. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  12116. $scope.nodes = data;
  12117. angular.forEach($scope.nodes, function(node) {
  12118. if(node.appname = '请假单') {
  12119. $scope.vacation = true;
  12120. }
  12121. if(node.appname = '加班单') {
  12122. $scope.workovertime = true;
  12123. }
  12124. if(node.appname = '工作日报') {
  12125. $scope.workdaily = true;
  12126. }
  12127. if(node.appname = '出差单') {
  12128. $scope.feeplease = true;
  12129. }
  12130. if(node.appname = '申诉单') {
  12131. $scope.signapp = true;
  12132. }
  12133. });
  12134. }, function(response) {
  12135. });
  12136. $scope.NoteSet = function() {
  12137. var modalInstance = $modal.open({
  12138. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  12139. controller: 'NoteStep1Ctrl',
  12140. size: 'lg',
  12141. resolve: {
  12142. AppName: function() {
  12143. return '请假单';
  12144. }
  12145. }
  12146. });
  12147. modalInstance.result.then(function(data) {
  12148. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  12149. if(data.error) {
  12150. toaster.pop('error', '提示', data.error);
  12151. }
  12152. if(data.success) {
  12153. toaster.pop('success', '提示', data.success);
  12154. }
  12155. }, function(response) {
  12156. });
  12157. }, function(){
  12158. });
  12159. }
  12160. $scope.overTimeSet = function() {
  12161. var modalInstance = $modal.open({
  12162. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  12163. controller: 'NoteStep1Ctrl',
  12164. size: 'lg',
  12165. resolve: {
  12166. AppName: function() {
  12167. return '加班单';
  12168. }
  12169. }
  12170. });
  12171. modalInstance.result.then(function(data) {
  12172. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  12173. if(data.error) {
  12174. toaster.pop('error', '提示', data.error);
  12175. }
  12176. if(data.success) {
  12177. toaster.pop('success', '提示', data.success);
  12178. }
  12179. }, function(response) {
  12180. });
  12181. }, function(){
  12182. });
  12183. }
  12184. $scope.feePleaseSet = function() {
  12185. var modalInstance = $modal.open({
  12186. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  12187. controller: 'NoteStep1Ctrl',
  12188. size: 'lg',
  12189. resolve: {
  12190. AppName: function() {
  12191. return '出差单';
  12192. }
  12193. }
  12194. });
  12195. modalInstance.result.then(function(data) {
  12196. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  12197. if(data.error) {
  12198. toaster.pop('error', '提示', data.error);
  12199. }
  12200. if(data.success) {
  12201. toaster.pop('success', '提示', data.success);
  12202. }
  12203. }, function(response) {
  12204. });
  12205. }, function(){
  12206. });
  12207. }
  12208. $scope.workDailySet = function() {
  12209. var modalInstance = $modal.open({
  12210. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  12211. controller: 'NoteStep1Ctrl',
  12212. size: 'lg',
  12213. resolve: {
  12214. AppName: function() {
  12215. return '工作日报';
  12216. }
  12217. }
  12218. });
  12219. modalInstance.result.then(function(data) {
  12220. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  12221. if(data.error) {
  12222. toaster.pop('error', '提示', data.error);
  12223. }
  12224. if(data.success) {
  12225. toaster.pop('success', '提示', data.success);
  12226. }
  12227. }, function(response) {
  12228. });
  12229. }, function(){
  12230. });
  12231. }
  12232. $scope.signAppSet = function() {
  12233. var modalInstance = $modal.open({
  12234. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  12235. controller: 'NoteStep1Ctrl',
  12236. size: 'lg',
  12237. resolve: {
  12238. AppName: function() {
  12239. return '申诉单';
  12240. }
  12241. }
  12242. });
  12243. modalInstance.result.then(function(data) {
  12244. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  12245. if(data.error) {
  12246. toaster.pop('error', '提示', data.error);
  12247. }
  12248. if(data.success) {
  12249. toaster.pop('success', '提示', data.success);
  12250. }
  12251. }, function(response) {
  12252. });
  12253. }, function(){
  12254. });
  12255. }
  12256. }]);
  12257. /**
  12258. * 审核条件设置
  12259. */
  12260. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  12261. $scope.appName = AppName;// 标题名称
  12262. $scope.AppFlow = {appName: $scope.appName,
  12263. appNodes:{}};
  12264. $scope.AppFlow.appNodes = [];
  12265. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  12266. if(data.appNodes.length != 0) {
  12267. $scope.node = data;
  12268. $scope.AppFlow = data;
  12269. }
  12270. }, function() {
  12271. });
  12272. $scope.copy = function() {//复制
  12273. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  12274. toaster.pop('info', '提示', '复制成功');
  12275. $modalInstance.dismiss();
  12276. }
  12277. $scope.paste = function() {
  12278. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  12279. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  12280. }
  12281. $scope.clear = function() {// 清空
  12282. $scope.AppFlow = {appName: $scope.appName,
  12283. appNodes:{}};
  12284. $scope.AppFlow.appNodes = [];
  12285. }
  12286. appFlow.getPositions({}, function(data) {// 获取人员信息
  12287. $scope.users = data;
  12288. }, function(response) {
  12289. });
  12290. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  12291. $scope.roles = data;
  12292. },function(response) {
  12293. });
  12294. $scope.SelectUser = function(data) { // 添加人员
  12295. var item = {
  12296. useruu: null,
  12297. username: null,
  12298. level: null
  12299. };
  12300. item.useruu = data.useruu;
  12301. item.username = data.username;
  12302. // if($scope.AppFlow.appNodes.length != 0){
  12303. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  12304. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  12305. // toaster.pop('info', '提示', '不能重复添加');
  12306. // } else {
  12307. // $scope.AppFlow.appNodes.push(item);
  12308. // }
  12309. // }
  12310. // } else {
  12311. $scope.AppFlow.appNodes.push(item);
  12312. // }
  12313. }
  12314. $scope.SelectRole = function(data) {// 添加职位
  12315. var item = {
  12316. position: null,
  12317. level: null
  12318. };
  12319. item.position = data;
  12320. $scope.AppFlow.appNodes.push(item);
  12321. }
  12322. $scope.deleteNode = function(index) {// 删除节点
  12323. $scope.AppFlow.appNodes.splice(index, 1);
  12324. };
  12325. $scope.saveNode = function() { // 保存
  12326. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  12327. $scope.AppFlow.appNodes[key].level = key;
  12328. });
  12329. if($scope.AppFlow.appNodes.length == 0) {
  12330. toaster.pop('info', '提示', '您还未设置审批人');
  12331. } else {
  12332. $modalInstance.close($scope.AppFlow);
  12333. };
  12334. };
  12335. $scope.cancel = function() {// 取消
  12336. $modalInstance.dismiss();
  12337. }
  12338. }]);
  12339. /***
  12340. * 代采定单
  12341. */
  12342. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  12343. BaseService.scrollBackToTop();
  12344. $scope.active = 'all';
  12345. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12346. $scope.total = null;
  12347. $scope.setActive = function(state) {
  12348. if($scope.active != state) {
  12349. $scope.active = state;
  12350. if($scope.tableParams.page() == 1)
  12351. $scope.tableParams.reload();
  12352. else
  12353. $scope.tableParams.page(1);
  12354. }
  12355. };
  12356. $scope.agreedText = '全部';
  12357. $scope.dateZoneText = '不限';
  12358. $scope.condition = {dateZone: 1};
  12359. /* 时间筛选初始化*/
  12360. var fromDate = new Date();
  12361. var toDate = new Date();
  12362. fromDate.setMonth(fromDate.getMonth() - 1);
  12363. fromDate.setHours(0,0,0,0);
  12364. toDate.setHours(23,59,59,999);
  12365. $scope.condition.dateFrom = fromDate;
  12366. $scope.condition.dateTo = toDate;
  12367. $scope.changeDateZone = function(zone) {
  12368. $scope.condition.dateZone = zone;
  12369. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  12370. $scope.condition.$dateZoneOpen = false;
  12371. getDateCondition(zone, $scope.condition);
  12372. $scope.tableParams.page(1);
  12373. $scope.tableParams.reload();
  12374. };
  12375. $scope.openDatePicker = function($event, item, openParam) {
  12376. $event.preventDefault();
  12377. $event.stopPropagation();
  12378. item[openParam] = !item[openParam];
  12379. };
  12380. $scope.openFilterDatePicker = function($event, item, openParam) {
  12381. $event.preventDefault();
  12382. $event.stopPropagation();
  12383. item[openParam] = !item[openParam];
  12384. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  12385. $scope.tableParams.reload();
  12386. }
  12387. };
  12388. $scope.tableParams = new ngTableParams({
  12389. page : 1,
  12390. count : 20,
  12391. sorting: {
  12392. }
  12393. }, {
  12394. total : 0,
  12395. counts: [5, 10, 25, 50],
  12396. getData : function($defer, params) {
  12397. $scope.loading = true;
  12398. var pageParams = params.url();
  12399. pageParams.searchFilter = {
  12400. keyword: $scope.keyword,
  12401. fromDate: getDateTime($scope.condition.dateFrom),
  12402. endDate: getDateTime($scope.condition.dateTo)
  12403. };
  12404. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  12405. $scope.loading = false;
  12406. if(page) {
  12407. params.total(page.totalElement);
  12408. $scope.total = page.totalElement;
  12409. $defer.resolve(page.content);
  12410. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  12411. }
  12412. }, function(response) {
  12413. $scope.loading = false;
  12414. toaster.pop('error', '数据加载失败', response.data);
  12415. });
  12416. }
  12417. });
  12418. //打印
  12419. $scope.print = function(deputyOrder) {
  12420. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  12421. $scope.tableParams.reload();
  12422. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  12423. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  12424. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  12425. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  12426. //TODO 目前只有信扬有代采业务,先写死之后再改
  12427. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  12428. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  12429. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  12430. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  12431. };
  12432. // 搜索框回车
  12433. $scope.onSearch = function() {
  12434. $scope.tableParams.page(1);
  12435. $scope.tableParams.reload();
  12436. };
  12437. }]);
  12438. /**
  12439. * 新增代采订单
  12440. */
  12441. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  12442. BaseService.scrollBackToTop();
  12443. $scope.deOrder = {
  12444. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  12445. entrydate: new Date(),
  12446. status: '在录入',
  12447. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  12448. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  12449. riskmethod: '甲方承担',
  12450. taxpaymentmethod: '甲方承担',
  12451. totalamount: 0,
  12452. totalpayament: 0,
  12453. orderamount: 0,
  12454. usdpayment: 0
  12455. };
  12456. $scope.deOrder.deputyOrderItems = [];
  12457. var item = {
  12458. prodname: null,
  12459. prodcode: null,
  12460. prodspec: null,
  12461. amount: null,
  12462. unitprice: null,
  12463. purcprice: null,
  12464. remark: null,
  12465. orderprice: null,
  12466. };
  12467. $scope.deOrder.deputyOrderItems.push(item);
  12468. // 代采企业列表
  12469. DeputyOrder.deputyEnterprise({}, function(data) {
  12470. $scope.deputyEnterprises = data;
  12471. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  12472. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  12473. });
  12474. // 更新名称时后台更改uu号
  12475. $scope.change = function(deputyname) {
  12476. DeputyOrder.deputyEnterprise({}, function(data) {
  12477. $scope.deputyEn = data;
  12478. angular.forEach($scope.deputyEn, function(en) {
  12479. if(deputyname == en.deputyenname) {
  12480. $scope.deputyuu = en.deputyenuu;
  12481. }
  12482. });
  12483. });
  12484. }
  12485. // 查找付款企业
  12486. $scope.dbfindPayCompany = function(deputyuu) {
  12487. var modalInstance = $modal.open({
  12488. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  12489. controller: 'DbfindDeputyPayCompanyCtrl',
  12490. resolve: {
  12491. deputyuu: function() {return deputyuu}
  12492. }
  12493. });
  12494. modalInstance.result.then(function(data) {
  12495. $scope.deOrder.paycomname = data.enname;
  12496. $scope.deOrder.paycomaddress = data.address;
  12497. })
  12498. }
  12499. // 查询上次的关键词记录
  12500. $scope.getHisKeyword = function(tervendor) {
  12501. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function(data) {
  12502. $scope.deOrder.vendtel = data.vendtel;
  12503. $scope.deOrder.venduser = data.venduser;
  12504. $scope.deOrder.otherdata = data.otherdata;
  12505. $scope.deOrder.companyname = data.companyname;
  12506. $scope.deOrder.bankaccount = data.bankaccount;
  12507. $scope.deOrder.bankaddress = data.bankaddress;
  12508. $scope.deOrder.bankcode = data.bankcode;
  12509. $scope.deOrder.bankname = data.bankname;
  12510. $scope.deOrder.legalrepresent = data.legalrepresent;
  12511. $scope.deOrder.tervendaddress = data.tervendaddress;
  12512. $scope.deOrder.enfax = data.enfax;
  12513. $scope.deOrder.deliverymethod = data.deliverymethod;
  12514. }, function(response) {
  12515. toaster.pop('error', '提示', response.data);
  12516. });
  12517. }
  12518. // 查询历史供应商
  12519. DeputyOrder.hisvendors({}, function(data) {
  12520. $scope.hisvendors = data;
  12521. }, function(response) {
  12522. toaster.pop('error', '提示', response.data);
  12523. });
  12524. // 上次填写记录(不关联供应商)
  12525. DeputyOrder.lastKeywords({}, function(data) {
  12526. $scope.lastkeyowrds = data;
  12527. $scope.deOrder.madealdate = $scope.lastkeyowrds.madealdate;
  12528. $scope.deOrder.madealcode = $scope.lastkeyowrds.madealcode;
  12529. }, function(response) {
  12530. toaster.pop('error', '提示', response.data);
  12531. });
  12532. //增加商品
  12533. $scope.add = function(index) {
  12534. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  12535. toaster.pop('info', '提示', '请先填写商品信息');
  12536. }else {
  12537. $scope.deOrder.deputyOrderItems.push(
  12538. { prodname: null,
  12539. prodcode: null,
  12540. prodspec: null,
  12541. prodbrand: null,
  12542. amount: null,
  12543. unitprice: null,
  12544. purcprice: null,
  12545. remark: null,
  12546. orderprice: null});
  12547. }
  12548. };
  12549. //删除商品
  12550. $scope.del = function(index) {
  12551. $scope.deOrder.deputyOrderItems.splice(index, 1);
  12552. };
  12553. // 导入商品信息
  12554. $scope.uplodaByBatch = function() {
  12555. var modalInstance = $modal.open({
  12556. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  12557. controller: 'DeputyOrderUploadCtrl',
  12558. size: 'lg',
  12559. resolve: {
  12560. }
  12561. });
  12562. modalInstance.result.then(function(data) {
  12563. angular.forEach(data, function(data) {
  12564. $scope.deOrder.deputyOrderItems.push(data);
  12565. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  12566. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  12567. $scope.deOrder.deputyOrderItems.splice(i, 1);
  12568. }
  12569. }
  12570. })
  12571. $scope.deOrder.totalamount = 0;
  12572. $scope.deOrder.usdpayment = 0;
  12573. $scope.deOrder.orderamount = 0;
  12574. $scope.deOrder.totalpayament = 0;
  12575. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12576. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12577. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12578. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12579. $scope.deOrder.orderamount += item.amount * item.purcprice;
  12580. });
  12581. }, function(){
  12582. });
  12583. }
  12584. // 查找供应商
  12585. $scope.dbfindVendor = function(deputyuu) {
  12586. var modalInstance = $modal.open({
  12587. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  12588. controller: 'DbfindDeputyVendorInfoCtrl',
  12589. size: 'lg',
  12590. resolve: {
  12591. deputyuu: function() {return deputyuu}
  12592. }
  12593. });
  12594. modalInstance.result.then(function(data) {
  12595. $scope.deOrder.customer = data.vendorEnterprise.enName;
  12596. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  12597. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  12598. $scope.deOrder.usertel = data.vendorUser.userTel;
  12599. })
  12600. }
  12601. // 检验订单编号是否存在
  12602. $scope.checkOrder = function(salecode, deputyuu) {
  12603. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  12604. if(data.info) {
  12605. toaster.pop('error', '提示', data.info);
  12606. }
  12607. }, function(response) {
  12608. toaster.pop('error', '提示', response.data);
  12609. })
  12610. }
  12611. //计算采购单价
  12612. $scope.checkPrice = function(rate) {
  12613. $scope.deOrder.totalamount = 0;
  12614. $scope.deOrder.usdpayment = 0;
  12615. $scope.deOrder.orderamount = 0;
  12616. $scope.deOrder.totalpayament = 0;
  12617. if(rate == null) {
  12618. toaster.pop('info', '提示', '请先填入税率');
  12619. } else {
  12620. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12621. item.purcprice = item.unitprice * (1 + rate/100);
  12622. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12623. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12624. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12625. $scope.deOrder.orderamount += item.amount * item.purcprice;
  12626. });
  12627. }
  12628. }
  12629. $scope.checkresult = false;
  12630. var checkKeyword = function() {
  12631. if($scope.deOrder.madealdate == null) {
  12632. toaster.pop('info', '提示', '主协议签订日期未选择');
  12633. } else if($scope.deOrder.madealcode == null) {
  12634. toaster.pop('info', '提示', '主协议签订编号未填写');
  12635. } else if ($scope.deOrder.tervendor == null) {
  12636. toaster.pop('info', '提示', '终端供应商名称未填写');
  12637. } else if($scope.deOrder.vendtel == null) {
  12638. toaster.pop('info', '提示', '电话号码未填写');
  12639. } else if($scope.deOrder.venduser == null) {
  12640. toaster.pop('info', '提示', '联系人未填写');
  12641. } else if($scope.deOrder.shipdate == null) {
  12642. toaster.pop('info', '提示', '供应商发货时间未选择');
  12643. } else if($scope.deOrder.goodspacking == null) {
  12644. toaster.pop('info', '提示', '货物包装要求未填写');
  12645. } else if($scope.deOrder.deliverymethod == null) {
  12646. toaster.pop('info', '提示', '供应商交货方式未填写');
  12647. } else if($scope.deOrder.pickupmethod == null) {
  12648. toaster.pop('info', '提示', '我方提货方式未填写');
  12649. } else if($scope.deOrder.paymentmethod == null) {
  12650. toaster.pop('info', '提示', '我方付款方式未填写');
  12651. } else if($scope.deOrder.pickupdate == null) {
  12652. toaster.pop('info', '提示', '我方提货时间未选择');
  12653. } else if($scope.deOrder.currency == null) {
  12654. toaster.pop('info', '提示', '交易币别未选择');
  12655. } else if($scope.deOrder.deputyuu == null) {
  12656. toaster.pop('info', '提示', '代采企业未选择');
  12657. } else if($scope.deOrder.salecode == null) {
  12658. toaster.pop('info', '提示', '订单编号未填写');
  12659. } else if($scope.deOrder.paydeldate == null) {
  12660. toaster.pop('info', '提示', '我方付款提货时间未选择');
  12661. } else if($scope.deOrder.riskmethod == null) {
  12662. toaster.pop('info', '提示', '风险承担方式未填写');
  12663. } else if($scope.deOrder.taxpaymentmethod == null) {
  12664. toaster.pop('info', '提示', '运、税费承担方式');
  12665. } else if($scope.deOrder.tervendaddress == null) {
  12666. toaster.pop('info', '提示', '终端供应商地址未填写');
  12667. } else if($scope.deOrder.companyname == null) {
  12668. toaster.pop('info', '提示', '公司全称(英文)未填写');
  12669. } else if($scope.deOrder.requirepaydate == null) {
  12670. toaster.pop('info', '提示', '要求付汇日期未选择');
  12671. } else if($scope.deOrder.bankname == null) {
  12672. toaster.pop('info', '提示', '银行名称(英文)未填写');
  12673. } else if($scope.deOrder.bankaccount == null) {
  12674. toaster.pop('info', '提示', '银行账号未填写');
  12675. } else if($scope.deOrder.bankaddress == null) {
  12676. toaster.pop('info', '提示', '银行地址未填写');
  12677. } else if($scope.deOrder.bankcode == null) {
  12678. toaster.pop('info', '提示', '银行代码未填写');
  12679. } else if($scope.deOrder.salepocode == null) {
  12680. toaster.pop('info', '提示', '合同编号未填写');
  12681. } else if($scope.deOrder.legalrepresent == null) {
  12682. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  12683. } else if($scope.deOrder.paycomname == null) {
  12684. toaster.pop('info', '提示', '付款公司未填写');
  12685. } else if($scope.deOrder.paycomaddress == null) {
  12686. toaster.pop('info', '提示', '付款公司地址未填写');
  12687. } else if($scope.deOrder.enfax == null) {
  12688. toaster.pop('info', '提示', '供应商方法人电话未填写');
  12689. } else if($scope.deOrder.paydate == null) {
  12690. toaster.pop('info', '提示', '货款支付时间未选择');
  12691. } else if($scope.deOrder.paymethod == null) {
  12692. toaster.pop('info', '提示', '货款支付方式未填写');
  12693. } else if($scope.deOrder.deliverydate == null) {
  12694. toaster.pop('info', '提示', '交货时间未选择');
  12695. } else {
  12696. angular.forEach($scope.deOrder.deputyOrderItems, function(orderitem, index) {
  12697. console.log(orderitem);
  12698. if(orderitem.prodname == null) {
  12699. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品名称未填写');
  12700. } else if(orderitem.prodcode == null) {
  12701. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品编号未填写');
  12702. } else if(orderitem.prodspec == null) {
  12703. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品规格未填写');
  12704. } else if(orderitem.prodbrand == null) {
  12705. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品品牌未填写');
  12706. } else if(orderitem.amount == null) {
  12707. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行数量未填写');
  12708. } else if(orderitem.unitprice == null) {
  12709. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行单价未填写');
  12710. } else if(orderitem.purcprice == null) {
  12711. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行订单单价未填写');
  12712. } else {
  12713. $scope.checkresult = true;
  12714. }
  12715. });
  12716. }
  12717. }
  12718. // 保存
  12719. $scope.save = function() {
  12720. checkKeyword();
  12721. if($scope.checkresult) {
  12722. $scope.deOrder.entrystatus = '保存';
  12723. $scope.deOrder.totalamount = 0;
  12724. $scope.deOrder.usdpayment = 0;
  12725. $scope.deOrder.orderamount = 0;
  12726. $scope.deOrder.totalpayament = 0;
  12727. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12728. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12729. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12730. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12731. $scope.deOrder.orderamount += item.amount * item.purcprice;
  12732. });
  12733. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  12734. toaster.pop('info', '提示', '您还未填写任何商品信息');
  12735. } else {
  12736. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  12737. if(data.id) {
  12738. toaster.pop('success', '提示', '保存成功');
  12739. window.location.hash = "#/purc/deputy/"+data.id;
  12740. }
  12741. if(data.error) {
  12742. toaster.pop('error', '提示', '保存失败');
  12743. }
  12744. }, function(response) {
  12745. });
  12746. }
  12747. }
  12748. }
  12749. // 提交
  12750. $scope.submit = function() {
  12751. var result = checkKeyword();
  12752. if(result) {
  12753. $scope.deOrder.entrystatus = '已提交';
  12754. $scope.deOrder.totalamount = 0;
  12755. $scope.deOrder.usdpayment = 0;
  12756. $scope.deOrder.orderamount = 0;
  12757. $scope.deOrder.totalpayament = 0;
  12758. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12759. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12760. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12761. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12762. $scope.deOrder.orderamount += item.amount * item.purcprice;
  12763. });
  12764. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  12765. toaster.pop('info', '提示', '您还未填写任何商品信息');
  12766. } else {
  12767. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  12768. if(data.id) {
  12769. toaster.pop('success', '提示', '提交成功');
  12770. window.location.hash = "#/purc/deputy/"+data.id;
  12771. }
  12772. if(data.error) {
  12773. toaster.pop('error', '提示', '保存失败');
  12774. }
  12775. }, function(response) {
  12776. });
  12777. }
  12778. }
  12779. }
  12780. $scope.openDatePicker = function($event, deOrder, openParam) {
  12781. $event.preventDefault();
  12782. $event.stopPropagation();
  12783. deOrder[openParam] = !deOrder[openParam];
  12784. };
  12785. }]);
  12786. // 代采企业供应商
  12787. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  12788. $scope.prod = false;
  12789. BaseService.scrollBackToTop();
  12790. // 搜索框回车
  12791. $scope.onSearch = function(keyword) {
  12792. $scope.keyword = keyword;
  12793. $scope.customerParams.page(1);
  12794. $scope.customerParams.reload();
  12795. };
  12796. $scope.customerParams = new ngTableParams({
  12797. page : 1,
  12798. count : 20
  12799. }, {
  12800. total : 0,
  12801. counts: [5, 10, 25, 50],
  12802. getData : function($defer, params) {
  12803. $scope.loading = true;
  12804. var pageParams = params.url();
  12805. pageParams.keyword = $scope.keyword;
  12806. pageParams.enuu = deputyuu;
  12807. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function(page){
  12808. $scope.loading = false;
  12809. if(page) {
  12810. params.total(page.totalElement);
  12811. $defer.resolve(page.content);
  12812. }
  12813. $scope.totalCount = page.totalElement;
  12814. }, function(response){
  12815. $scope.loading = false;
  12816. toaster.pop('error', '数据加载失败', response.data);
  12817. });
  12818. }
  12819. });
  12820. $scope.cancel = function() {
  12821. $modalInstance.dismiss();
  12822. };
  12823. $scope.checkVendor = function(vendor) { // 直接选择
  12824. $modalInstance.close(vendor);
  12825. }
  12826. }]);
  12827. // 代采企业付款企业
  12828. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  12829. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function(data) {
  12830. $scope.paycompanies = data;
  12831. }, function(response) {
  12832. toaster.pop('error', '提示', response.data);
  12833. });
  12834. $scope.cancel = function() {
  12835. $modalInstance.dismiss();
  12836. };
  12837. $scope.select = function(company) { // 直接选择
  12838. $modalInstance.close(company);
  12839. }
  12840. }]);
  12841. /**
  12842. * 代采订单批量导入
  12843. */
  12844. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  12845. // 通过excel批量上传物料
  12846. $scope.result = null;
  12847. $scope.upload = function() {
  12848. var file = $scope.myFiles[0];
  12849. $upload.upload({
  12850. url: 'deputyOrder/release/excel',
  12851. file: file,
  12852. method: 'POST'
  12853. }).success(function(data) {
  12854. $scope.result = data;
  12855. $scope.success = $scope.result.success;
  12856. $scope.total = $scope.result.total;
  12857. $scope.alters = $scope.result.alters;
  12858. }).error(function(response) {
  12859. toaster.pop('error', response.data || response);
  12860. });
  12861. };
  12862. // 查看范例
  12863. $scope.showImg = function() {
  12864. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  12865. box.show();
  12866. box.find('img').attr('src', src);
  12867. box.find('a').click(function(){
  12868. box.hide();
  12869. });
  12870. box.dblclick(function(){
  12871. box.hide();
  12872. });
  12873. };
  12874. // 下载模板
  12875. $scope.download = function() {
  12876. window.location.href = 'deputyOrder/upload/template';
  12877. };
  12878. $scope.enSure = function() {
  12879. $modalInstance.close($scope.result.items);
  12880. }
  12881. $scope.cancel = function() {
  12882. $modalInstance.dismiss();
  12883. }
  12884. }]);
  12885. /**
  12886. * 代采详情
  12887. */
  12888. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal) {
  12889. BaseService.scrollBackToTop();
  12890. var loadData = function() {
  12891. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  12892. $scope.deOrder = data;
  12893. $scope.deOrder.$editing = false;
  12894. });
  12895. };
  12896. loadData();
  12897. // 查询历史供应商
  12898. DeputyOrder.hisvendors({}, function(data) {
  12899. $scope.hisvendors = data;
  12900. }, function(response) {
  12901. toaster.pop('error', '提示', response.data);
  12902. });
  12903. // 代采企业列表
  12904. DeputyOrder.deputyEnterprise({}, function(data) {
  12905. $scope.deputyEnterprises = data;
  12906. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  12907. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  12908. });
  12909. // 更新代采企业时更新费率
  12910. $scope.change = function(deputyname) {
  12911. DeputyOrder.deputyEnterprise({}, function(data) {
  12912. $scope.deputyEn = data;
  12913. angular.forEach($scope.deputyEn, function(en) {
  12914. if(deputyname == en.deputyenname) {
  12915. $scope.deputyuu = en.deputyenuu;
  12916. }
  12917. });
  12918. });
  12919. }
  12920. // 查找付款企业
  12921. $scope.dbfindPayCompany = function(deputyuu) {
  12922. var modalInstance = $modal.open({
  12923. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  12924. controller: 'DbfindDeputyPayCompanyCtrl',
  12925. resolve: {
  12926. deputyuu: function() {return deputyuu}
  12927. }
  12928. });
  12929. modalInstance.result.then(function(data) {
  12930. $scope.deOrder.paycomname = data.enname;
  12931. $scope.deOrder.paycomaddress = data.address;
  12932. })
  12933. }
  12934. // 删除明细
  12935. $scope.del = function(index, id) {
  12936. DeputyOrder.deleteProdById({id: id}, {}, function(data) {
  12937. if(data.success) {
  12938. toaster.pop('success', '提示', data.success);
  12939. $scope.deOrder.deputyOrderItems.splice(index, 1)
  12940. }
  12941. if(data.error) {
  12942. toaster.pop('error', '提示', data.error);
  12943. }
  12944. $scope.deOrder.totalamount = 0;
  12945. $scope.deOrder.usdpayment = 0;
  12946. $scope.deOrder.orderamount = 0;
  12947. $scope.deOrder.totalpayament = 0;
  12948. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12949. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12950. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12951. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  12952. $scope.deOrder.orderamount += item.amount * item.purcprice;
  12953. });
  12954. }, function(response) {
  12955. toaster.pop('error', '提示', response.data);
  12956. });
  12957. }
  12958. //增加商品
  12959. $scope.add = function(index) {
  12960. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  12961. toaster.pop('info', '提示', '请先填写商品信息');
  12962. }else {
  12963. $scope.deOrder.deputyOrderItems.push(
  12964. { prodname: null,
  12965. prodcode: null,
  12966. prodspec: null,
  12967. prodbrand: null,
  12968. amount: null,
  12969. unitprice: null,
  12970. remark: null,
  12971. orderprice: null});
  12972. }
  12973. };
  12974. // 导入商品信息
  12975. $scope.uplodaByBatch = function() {
  12976. var modalInstance = $modal.open({
  12977. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  12978. controller: 'DeputyOrderUploadCtrl',
  12979. size: 'lg',
  12980. resolve: {
  12981. }
  12982. });
  12983. modalInstance.result.then(function(data) {
  12984. angular.forEach(data, function(data) {
  12985. $scope.deOrder.deputyOrderItems.push(data);
  12986. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  12987. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  12988. $scope.deOrder.deputyOrderItems.splice(i, 1);
  12989. }
  12990. }
  12991. })
  12992. $scope.deOrder.totalamount = 0;
  12993. $scope.deOrder.usdpayment = 0;
  12994. $scope.deOrder.orderamount = 0;
  12995. $scope.deOrder.totalpayament = 0;
  12996. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  12997. $scope.deOrder.totalamount += item.amount * item.unitprice;
  12998. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  12999. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  13000. $scope.deOrder.orderamount += item.amount * item.purcprice;
  13001. });
  13002. }, function(){
  13003. });
  13004. }
  13005. //删除商品
  13006. $scope.delItem = function(index) {
  13007. $scope.deOrder.deputyOrderItems.splice(index, 1);
  13008. };
  13009. var getService = function() {
  13010. return DeputyOrder.getProdList;
  13011. };
  13012. $scope.update = function() {
  13013. $scope.deOrder.$editing = true;
  13014. }
  13015. $scope.cancel = function() {
  13016. $scope.deOrder.$editing = false;
  13017. }
  13018. // 检验订单编号是否存在
  13019. $scope.checkOrder = function(salecode, deputyuu) {
  13020. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function(data) {
  13021. if(data.info) {
  13022. toaster.pop('error', '提示', data.info);
  13023. }
  13024. }, function(response) {
  13025. toaster.pop('error', '提示', response.data);
  13026. })
  13027. }
  13028. //计算采购单价
  13029. $scope.checkPrice = function(rate) {
  13030. $scope.deOrder.totalamount = 0;
  13031. $scope.deOrder.usdpayment = 0;
  13032. $scope.deOrder.orderamount = 0;
  13033. $scope.deOrder.totalpayament = 0;
  13034. if(rate == null) {
  13035. toaster.pop('info', '提示', '请先填入税率');
  13036. } else {
  13037. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  13038. item.purcprice = item.unitprice * (1 + rate/100);
  13039. $scope.deOrder.totalamount += item.amount * item.unitprice;
  13040. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  13041. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  13042. $scope.deOrder.orderamount += item.amount * item.purcprice;
  13043. });
  13044. }
  13045. }
  13046. $scope.checkresult = false;
  13047. var checkKeyword = function() {
  13048. if($scope.deOrder.madealdate == null) {
  13049. toaster.pop('info', '提示', '主协议签订日期未选择');
  13050. } else if($scope.deOrder.madealcode == null) {
  13051. toaster.pop('info', '提示', '主协议签订编号未填写');
  13052. } else if ($scope.deOrder.tervendor == null) {
  13053. toaster.pop('info', '提示', '终端供应商名称未填写');
  13054. } else if($scope.deOrder.vendtel == null) {
  13055. toaster.pop('info', '提示', '电话号码未填写');
  13056. } else if($scope.deOrder.venduser == null) {
  13057. toaster.pop('info', '提示', '联系人未填写');
  13058. } else if($scope.deOrder.shipdate == null) {
  13059. toaster.pop('info', '提示', '供应商发货时间未选择');
  13060. } else if($scope.deOrder.goodspacking == null) {
  13061. toaster.pop('info', '提示', '货物包装要求未填写');
  13062. } else if($scope.deOrder.deliverymethod == null) {
  13063. toaster.pop('info', '提示', '供应商交货方式未填写');
  13064. } else if($scope.deOrder.pickupmethod == null) {
  13065. toaster.pop('info', '提示', '我方提货方式未填写');
  13066. } else if($scope.deOrder.paymentmethod == null) {
  13067. toaster.pop('info', '提示', '我方付款方式未填写');
  13068. } else if($scope.deOrder.pickupdate == null) {
  13069. toaster.pop('info', '提示', '我方提货时间未选择');
  13070. } else if($scope.deOrder.currency == null) {
  13071. toaster.pop('info', '提示', '交易币别未选择');
  13072. } else if($scope.deOrder.deputyuu == null) {
  13073. toaster.pop('info', '提示', '代采企业未选择');
  13074. } else if($scope.deOrder.salecode == null) {
  13075. toaster.pop('info', '提示', '订单编号未填写');
  13076. } else if($scope.deOrder.paydeldate == null) {
  13077. toaster.pop('info', '提示', '我方付款提货时间未选择');
  13078. } else if($scope.deOrder.riskmethod == null) {
  13079. toaster.pop('info', '提示', '风险承担方式未填写');
  13080. } else if($scope.deOrder.taxpaymentmethod == null) {
  13081. toaster.pop('info', '提示', '运、税费承担方式');
  13082. } else if($scope.deOrder.tervendaddress == null) {
  13083. toaster.pop('info', '提示', '终端供应商地址未填写');
  13084. } else if($scope.deOrder.companyname == null) {
  13085. toaster.pop('info', '提示', '公司全称(英文)未填写');
  13086. } else if($scope.deOrder.requirepaydate == null) {
  13087. toaster.pop('info', '提示', '要求付汇日期未选择');
  13088. } else if($scope.deOrder.bankname == null) {
  13089. toaster.pop('info', '提示', '银行名称(英文)未填写');
  13090. } else if($scope.deOrder.bankaccount == null) {
  13091. toaster.pop('info', '提示', '银行账号未填写');
  13092. } else if($scope.deOrder.bankaddress == null) {
  13093. toaster.pop('info', '提示', '银行地址未填写');
  13094. } else if($scope.deOrder.bankcode == null) {
  13095. toaster.pop('info', '提示', '银行代码未填写');
  13096. } else if($scope.deOrder.salepocode == null) {
  13097. toaster.pop('info', '提示', '合同编号未填写');
  13098. } else if($scope.deOrder.legalrepresent == null) {
  13099. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  13100. } else if($scope.deOrder.paycomname == null) {
  13101. toaster.pop('info', '提示', '付款公司未填写');
  13102. } else if($scope.deOrder.paycomaddress == null) {
  13103. toaster.pop('info', '提示', '付款公司地址未填写');
  13104. } else if($scope.deOrder.enfax == null) {
  13105. toaster.pop('info', '提示', '供应商方法人电话未填写');
  13106. } else if($scope.deOrder.paydate == null) {
  13107. toaster.pop('info', '提示', '货款支付时间未选择');
  13108. } else if($scope.deOrder.paymethod == null) {
  13109. toaster.pop('info', '提示', '货款支付方式未填写');
  13110. } else if($scope.deOrder.deliverydate == null) {
  13111. toaster.pop('info', '提示', '交货时间未选择');
  13112. } else {
  13113. angular.forEach($scope.deOrder.deputyOrderItems, function(orderitem, index) {
  13114. console.log(orderitem);
  13115. if(orderitem.prodname == null) {
  13116. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品名称未填写');
  13117. } else if(orderitem.prodcode == null) {
  13118. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品编号未填写');
  13119. } else if(orderitem.prodspec == null) {
  13120. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品规格未填写');
  13121. } else if(orderitem.prodbrand == null) {
  13122. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行产品品牌未填写');
  13123. } else if(orderitem.amount == null) {
  13124. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行数量未填写');
  13125. } else if(orderitem.unitprice == null) {
  13126. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行单价未填写');
  13127. } else if(orderitem.purcprice == null) {
  13128. toaster.pop('info', '提示', '订单明细第'+ (index+1) +'行订单单价未填写');
  13129. } else {
  13130. $scope.checkresult = true;
  13131. }
  13132. });
  13133. }
  13134. }
  13135. // 保存
  13136. $scope.save = function() {
  13137. checkKeyword();
  13138. if($scope.checkresult) {
  13139. $scope.deOrder.entrystatus = '保存';
  13140. $scope.deOrder.totalamount = 0;
  13141. $scope.deOrder.usdpayment = 0;
  13142. $scope.deOrder.orderamount = 0;
  13143. $scope.deOrder.totalpayament = 0;
  13144. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  13145. $scope.deOrder.totalamount += item.amount * item.unitprice;
  13146. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  13147. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  13148. $scope.deOrder.orderamount += item.amount * item.purcprice;
  13149. });
  13150. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  13151. toaster.pop('info', '提示', '您还未填写任何商品信息');
  13152. } else {
  13153. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  13154. if(data.id) {
  13155. toaster.pop('success', '提示', '保存成功');
  13156. loadData();
  13157. }
  13158. if(data.error) {
  13159. toaster.pop('error', '提示', '保存失败');
  13160. }
  13161. }, function(response) {
  13162. });
  13163. }
  13164. }
  13165. }
  13166. // 提交
  13167. $scope.submit = function() {
  13168. checkKeyword();
  13169. if($scope.checkresult) {
  13170. $scope.deOrder.entrystatus = '已提交';
  13171. $scope.deOrder.totalamount = 0;
  13172. $scope.deOrder.usdpayment = 0;
  13173. $scope.deOrder.orderamount = 0;
  13174. $scope.deOrder.totalpayament = 0;
  13175. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  13176. $scope.deOrder.totalamount += item.amount * item.unitprice;
  13177. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  13178. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  13179. $scope.deOrder.orderamount += item.amount * item.purcprice;
  13180. });
  13181. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  13182. if(data.id) {
  13183. toaster.pop('success', '提示', '提交成功');
  13184. window.location.hash = "#/purc/deputy/"+data.id;
  13185. }
  13186. if(data.error) {
  13187. toaster.pop('error', '提示', '保存失败');
  13188. }
  13189. }, function(response) {
  13190. });
  13191. }
  13192. }
  13193. $scope.openDatePicker = function($event, deOrder, openParam) {
  13194. $event.preventDefault();
  13195. $event.stopPropagation();
  13196. deOrder[openParam] = !deOrder[openParam];
  13197. };
  13198. }]);
  13199. /**
  13200. * 代采错误日志
  13201. */
  13202. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  13203. BaseService.scrollBackToTop();
  13204. var getService = function() {
  13205. return DeputyOrder.getRepetitions;
  13206. };
  13207. $scope.tableParams = new ngTableParams({
  13208. page : 1,
  13209. count : 20,
  13210. sorting: {
  13211. }
  13212. }, {
  13213. total : 0,
  13214. counts: [5, 10, 25, 50],
  13215. getData : function($defer, params) {
  13216. $scope.loading = true;
  13217. var pageParams = params.url();
  13218. pageParams.keyword = $scope.keyword;
  13219. pageParams.searchFilter = $scope.searchFilter;
  13220. getService().call(null, BaseService.parseParams(pageParams), function(page){
  13221. $scope.loading = false;
  13222. if(page) {
  13223. params.total(page.totalElement);
  13224. $defer.resolve(page.content);
  13225. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13226. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  13227. }
  13228. }, function(response) {
  13229. $scope.loading = false;
  13230. toaster.pop('error', '数据加载失败', response.data);
  13231. });
  13232. }
  13233. });
  13234. // 搜索框回车
  13235. $scope.onSearch = function() {
  13236. $scope.tableParams.page(1);
  13237. $scope.tableParams.reload();
  13238. };
  13239. //删除
  13240. $scope.deleteById = function(id) {
  13241. GetProductInfo.deleteById({id: id}, function(data) {
  13242. if(data.error) {
  13243. toaster.pop("error", "提示", data.error);
  13244. } else {
  13245. toaster.pop("success", "提示", "删除成功");
  13246. $timeout(function() {
  13247. $scope.tableParams.reload();
  13248. }, 500);
  13249. }
  13250. }), function(response) {
  13251. toaster.pop("error", "删除失败", response.data);
  13252. };
  13253. }
  13254. }]);
  13255. /**
  13256. * 招标单
  13257. */
  13258. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  13259. BaseService.scrollBackToTop();
  13260. if ($rootScope.tenderActive) {
  13261. $scope.active = $rootScope.tenderActive;
  13262. $rootScope.tenderActive = null;
  13263. } else {
  13264. $scope.active = 'done';
  13265. }
  13266. $scope.dateZoneText = '不限';
  13267. $scope.deliveryZoneText = '不限';
  13268. $scope.condition = {dateZone: 1, deliveryZone: -1};
  13269. /* 时间筛选初始化*/
  13270. var fromDate = new Date();
  13271. var toDate = new Date();
  13272. fromDate.setMonth(fromDate.getMonth() - 1);
  13273. fromDate.setHours(0,0,0,0);
  13274. toDate.setHours(23,59,59,999);
  13275. $scope.condition.dateFrom = fromDate;
  13276. $scope.condition.dateTo = toDate;
  13277. $scope.changeDateZone = function(zone) {
  13278. $scope.condition.dateZone = zone;
  13279. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  13280. $scope.condition.$dateZoneOpen = false;
  13281. getDateCondition(zone, $scope.condition);
  13282. $scope.tableParams.reload();
  13283. };
  13284. $scope.changeDeliveryZone = function(zone) {
  13285. $scope.condition.deliveryZoneText = zone;
  13286. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  13287. $scope.condition.$delievryZoneOpen = false;
  13288. getDelveryCondition(zone, $scope.condition);
  13289. $scope.tableParams.page(1);
  13290. $scope.tableParams.reload();
  13291. };
  13292. $scope.setActive = function(state) {
  13293. if($scope.active != state) {
  13294. $scope.active = state;
  13295. if($scope.tableParams.page() == 1)
  13296. $scope.tableParams.reload();
  13297. else
  13298. $scope.tableParams.page(1);
  13299. }
  13300. };
  13301. var getTenderStatus = function(active) {
  13302. var fn = 'getMyAll';
  13303. switch(active) {
  13304. case 'done':
  13305. fn = 'getMyDone';break;
  13306. case 'todo':
  13307. fn = 'getMyTodo';break;
  13308. // case 'end':
  13309. // fn = 'getMyEnd';break;
  13310. case 'waiting':
  13311. fn = 'getMyWaiting';break;
  13312. }
  13313. return fn;
  13314. }
  13315. $scope.tableParams = new ngTableParams({
  13316. page : 1,
  13317. count : 20,
  13318. sorting: {
  13319. 'tender.endDate': 'desc',
  13320. 'tender.enterprise.enName': 'asc',
  13321. 'tender.code': 'asc'
  13322. }
  13323. }, {
  13324. total : 0,
  13325. counts: [5, 10, 25, 50],
  13326. getData : function($defer, params) {
  13327. $scope.loading = true;
  13328. var pageParams = params.url();
  13329. var realActive = {};
  13330. pageParams.searchFilter = { // 筛选条件
  13331. keyword: $scope.keyword,
  13332. fromDate: getDateTime($scope.condition.dateFrom),
  13333. endDate: getDateTime($scope.condition.dateTo)
  13334. };
  13335. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  13336. $scope.loading = false;
  13337. if(page) {
  13338. params.total(page.totalElement);
  13339. $defer.resolve(page.content);
  13340. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  13341. }
  13342. }, function(response){
  13343. $scope.loading = false;
  13344. toaster.pop('error', '数据加载失败', response.data);
  13345. });
  13346. }
  13347. });
  13348. $scope.openDatePicker = function($event, item, openParam) {
  13349. $event.preventDefault();
  13350. $event.stopPropagation();
  13351. item[openParam] = !item[openParam];
  13352. };
  13353. $scope.openFilterDatePicker = function($event, item, openParam) {
  13354. $event.preventDefault();
  13355. $event.stopPropagation();
  13356. item[openParam] = !item[openParam];
  13357. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  13358. $scope.tableParams.reload();
  13359. }
  13360. };
  13361. $scope.parseDate = function(dateStr) {
  13362. if(dateStr)
  13363. return Date.parse(dateStr, 'yyyy-MM-dd');
  13364. return new Date();
  13365. };
  13366. // 选择查找日期
  13367. $scope.onDateCondition = function(){
  13368. $scope.tableParams.page(1);
  13369. $scope.tableParams.reload();
  13370. };
  13371. // 搜索框回车
  13372. $scope.onSearch = function() {
  13373. $scope.tableParams.page(1);
  13374. $scope.tableParams.reload();
  13375. };
  13376. }]);
  13377. /**
  13378. * 新增招标单
  13379. */
  13380. 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) {
  13381. // 录入人
  13382. AuthenticationService.getAuthentication().success(function(data) {
  13383. $scope.user = data;
  13384. });
  13385. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  13386. var getService = function() {
  13387. return GetProductInfo;
  13388. };
  13389. // 物料信息
  13390. $scope.tableParams = new ngTableParams({
  13391. page : 1,
  13392. count : 20,
  13393. sorting: {
  13394. }
  13395. }, {
  13396. total : 0,
  13397. counts: [5, 10, 25, 50],
  13398. getData : function($defer, params) {
  13399. $scope.loading = true;
  13400. var pageParams = params.url();
  13401. pageParams.keyword = $scope.keyword;
  13402. $scope.tip = $scope.keyword;
  13403. pageParams.searchFilter = $scope.searchFilter;
  13404. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  13405. $scope.loading = false;
  13406. if(page) {
  13407. params.total(page.totalElement);
  13408. $scope.total = page.totalElement;
  13409. $defer.resolve(page.content);
  13410. }
  13411. }, function(response) {
  13412. $scope.loading = false;
  13413. toaster.pop('error', '数据加载失败', response.data);
  13414. });
  13415. }
  13416. });
  13417. // 搜索框回车
  13418. $scope.onSearch = function(keyword) {
  13419. $scope.tableParams.page(1);
  13420. $scope.tableParams.reload();
  13421. };
  13422. //在产品列表添加商品
  13423. $scope.check = function(product) {
  13424. $scope.tenderProd.push({
  13425. prodTitle: product.title,
  13426. prodCode: product.code,
  13427. brand: product.brand,
  13428. unit: product.unit,
  13429. qty: null
  13430. // 供应商企业信息
  13431. // enterpriseBaseInfo: [{}]
  13432. });
  13433. for(var i = 0; i < $scope.tenderProd.length; i++) {
  13434. if($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  13435. $scope.tenderProd.splice(i, 1);
  13436. }
  13437. }
  13438. };
  13439. $scope.loading = false;
  13440. // 获取收货地址列表
  13441. var loadShipAddress = function() {
  13442. ShipAddress.shipAddList({}, function(data) {
  13443. $scope.ships = data;
  13444. $scope.tender.shipadd = $scope.ships[0];
  13445. });
  13446. };
  13447. loadShipAddress();
  13448. // 获取地址信息
  13449. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  13450. }).then(function(response) {
  13451. $scope.provinces = response.data;
  13452. });
  13453. // 新增收货地址保存
  13454. $scope.saveShipAddress = function(ship) {
  13455. ship.address = ship.province + ship.city + ship.district;
  13456. ShipAddress.saveAddress( {}, ship, function(data) {
  13457. if(data.success) {
  13458. // 获取收货地址列表
  13459. loadShipAddress();
  13460. toaster.pop('success', '提示', data.success);
  13461. }
  13462. if(data.error) {
  13463. toaster.pop('error', '提示', data.error);
  13464. }
  13465. });
  13466. };
  13467. // 可选的证照要求
  13468. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  13469. // 处理证照要求
  13470. var parseCertificate = function(a) {
  13471. if (a) {
  13472. var arr = a.split(',');
  13473. angular.forEach(arr, function(app) {
  13474. var contained = false;
  13475. angular.forEach($scope.certificates, function($app) {
  13476. if($app.name == app) {
  13477. $app.checked = true;
  13478. contained = true;
  13479. }
  13480. });
  13481. if(!contained) {
  13482. $scope.certificates.push({name: app, checked: true});
  13483. }
  13484. });
  13485. }
  13486. };
  13487. // 联想词start
  13488. // 获取品牌联想词
  13489. $scope.getSimilarBrands = function(value) {
  13490. if (value) {
  13491. // 获取品牌联想词
  13492. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  13493. return data.map(function(item) {
  13494. return item;
  13495. });
  13496. });
  13497. }
  13498. };
  13499. // 获取产品型号联想词
  13500. $scope.getSimilarCodes = function(value) {
  13501. if (value) {
  13502. // 获取产品型号联想词
  13503. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  13504. return data.map(function (item) {
  13505. return item;
  13506. })
  13507. });
  13508. }
  13509. };
  13510. // // 获取产品类目联想词
  13511. // $scope.getSimilarKinds = function(value) {
  13512. // if (value) {
  13513. // // getSimilarLeafKinds 根据类目名获取末级联想词
  13514. // // 获取类目联想词
  13515. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  13516. // return data.map(function(item) {
  13517. // return item;
  13518. // })
  13519. // });
  13520. // }
  13521. // };
  13522. // // 点击联想词获取类目信息
  13523. // $scope.onAssociateKindClick = function(kind, submit) {
  13524. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  13525. // $scope.actives = data;
  13526. // console.log(data);
  13527. // var size = data.length;
  13528. // if (size > 0) {
  13529. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  13530. // submit.kiName = submit.gradeOneKiName;
  13531. // if (size > 1) {
  13532. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  13533. // submit.kiName = submit.gradeTwoKiName;
  13534. // if (kind.level < 3) {
  13535. // submit.gradeThreeKiName = null;
  13536. // } else if (size > 2) {
  13537. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  13538. // submit.kiName = submit.gradeThreeKiName;
  13539. // }
  13540. // }
  13541. // }
  13542. // console.log(submit);
  13543. // })
  13544. // };
  13545. // 选择类目
  13546. $scope.selectKind = function(prod) {
  13547. var submit = [];
  13548. $modal.open({
  13549. animation: true,
  13550. size: 'lg',
  13551. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  13552. controller: 'ProdKindChooseCtrl',
  13553. resolve: {
  13554. actives: function() {
  13555. return $scope.actives;
  13556. }
  13557. }
  13558. }).result.then(function(data){
  13559. $scope.actives = data.actives;
  13560. var size = data.actives.length;
  13561. submit.gradeOneKiName = '';
  13562. submit.gradeTwoKiName = '';
  13563. submit.gradeThreeKiName = '';
  13564. if (size > 0) {
  13565. submit.gradeOneKiName = $scope.actives[0].nameCn;
  13566. prod.prodTitle = submit.gradeOneKiName;
  13567. if (size > 1) {
  13568. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  13569. prod.prodTitle = submit.gradeTwoKiName;
  13570. if (size > 2) {
  13571. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  13572. prod.prodTitle = submit.gradeThreeKiName;
  13573. }
  13574. }
  13575. }
  13576. }, function(){
  13577. });
  13578. };
  13579. // // 验证分类信息
  13580. // $scope.checkKind = function() {
  13581. // setTimeout(function() {
  13582. // if($scope.activesString == null) {
  13583. // $scope.component.kindid = null;
  13584. // return;
  13585. // }
  13586. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  13587. // $scope.component.kind = kind;
  13588. // $scope.component.kindid = kind.id;
  13589. // $scope.activesString = $scope.component.kind.nameCn;
  13590. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  13591. // $scope.kindProperties = data;
  13592. // angular.forEach($scope.kindProperties, function(kp) {
  13593. // angular.forEach($scope.component.properties, function(pro) {
  13594. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  13595. // kp.value = pro.value;
  13596. // }
  13597. // });
  13598. // });
  13599. // }, function(response) {
  13600. // });
  13601. // }, function (response) {
  13602. // $scope.component.kindid = null;
  13603. // toaster.pop('error', response.data);
  13604. // });
  13605. // }, 500);
  13606. // };
  13607. // 点击联想词获取品牌信息
  13608. $scope.onAssociateBrandClick = function(brand, prod) {
  13609. if (brand instanceof String) {
  13610. prod.brand = brand;
  13611. } else if (brand instanceof Object) {
  13612. prod.brand = brand.brandCn;
  13613. }
  13614. };
  13615. // 打开品牌选择的模态框
  13616. $scope.selectBrand = function(prod){ //打开模态
  13617. var modalInstance = $modal.open({
  13618. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  13619. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  13620. });
  13621. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  13622. });
  13623. modalInstance.result.then(function(brand){
  13624. prod.brand = brand.nameCn;
  13625. }, function(reason){
  13626. });
  13627. };
  13628. // // 验证品牌是否正确
  13629. // $scope.checkBrand = function () {
  13630. // setTimeout(function () {
  13631. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  13632. // // $scope.component.brand = brand;
  13633. // // $scope.component.brandid = brand.id;
  13634. // }, function (response) {
  13635. // // $scope.component.brandid = null;
  13636. // toaster.pop('error', response.data);
  13637. // })
  13638. // } , 500);
  13639. // };
  13640. // 点击联想词获取器件信息 带入产品分类和品牌
  13641. $scope.onAssociateCmpClick = function(cmp, prod) {
  13642. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  13643. $scope.component = data;
  13644. prod.prodCode = data.code;
  13645. prod.prodTitle = data.kind.nameCn;
  13646. prod.brand = data.brand.nameCn;
  13647. }, function(res) {
  13648. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  13649. })
  13650. };
  13651. //联想词end
  13652. $scope.condition = {dateZone: 1};
  13653. $scope.tenderProd = [];
  13654. var prod = {
  13655. prodTitle: null,
  13656. prodCode: null,
  13657. brand: null,
  13658. unit: 'PCS',
  13659. qty: null
  13660. // 供应商企业信息
  13661. // enterpriseBaseInfo: [{}]
  13662. };
  13663. $scope.tender = {
  13664. date: new Date(),
  13665. unit: 'PCS',
  13666. currency: 'RMB',
  13667. ifOpen: 1,
  13668. ifTax: 1,
  13669. invoiceType: 2,
  13670. tenderAttachs:[{}]
  13671. };
  13672. //
  13673. $scope.tenderProd.push(prod);
  13674. //增加商品
  13675. $scope.add = function(index) {
  13676. $scope.tenderProd.push({
  13677. prodTitle: null,
  13678. prodCode: null,
  13679. brand: null,
  13680. unit: 'PCS',
  13681. qty: null
  13682. // 供应商企业信息
  13683. // enterpriseBaseInfo: [{}]
  13684. });
  13685. };
  13686. //删除商品
  13687. $scope.del = function(index) {
  13688. $scope.tenderProd.splice(index, 1);
  13689. };
  13690. // 批量导入
  13691. $scope.uplodaByBatch = function() {
  13692. var modalInstance = $modal.open({
  13693. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  13694. controller: 'PurcTenderUploadCtrl',
  13695. size: 'lg',
  13696. resolve: {
  13697. }
  13698. });
  13699. modalInstance.result.then(function(data) {
  13700. // 获取上传的产品明细,前台展示
  13701. angular.forEach(data, function(data) {
  13702. $scope.tenderProd.push(data);
  13703. for(var i = 0; i < $scope.tenderProd.length; i++) {
  13704. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  13705. $scope.tenderProd.splice(i, 1);
  13706. }
  13707. }
  13708. });
  13709. }, function(){
  13710. });
  13711. };
  13712. $scope.isSave = false;
  13713. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  13714. if( ! angular.isUndefined($stateParams.id)) {
  13715. $scope.isSave = true; // 用于判断是新增还是已保存
  13716. $scope.loading = true;
  13717. PurcTender.getOne({id: $stateParams.id}, function(data){
  13718. data.$editing = false;
  13719. $scope.tender = data;
  13720. $scope.tenderProd = data.purchaseTenderProds;
  13721. parseCertificate($scope.tender.certificate);
  13722. $scope.firstProd = data.purchaseTenderProds[0];
  13723. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  13724. // 获取供应商联系人
  13725. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function(data) {
  13726. item.saleTender.enterpriseBaseInfo.contacts = data;
  13727. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  13728. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function(contact) {
  13729. if (item.saleTender.userTel === contact.tel) {
  13730. item.saleTender.enterpriseBaseInfo.contact = contact;
  13731. }
  13732. });
  13733. });
  13734. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  13735. $scope.tenderProd.enterpriseBaseInfo = [{}];
  13736. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  13737. } else {
  13738. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  13739. }
  13740. });
  13741. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  13742. $scope.loading = false;
  13743. $scope.attaches = $scope.tender.tenderAttaches;
  13744. }, function(response){
  13745. $scope.loading = false;
  13746. toaster.pop('error', '数据加载失败', response.data);
  13747. });
  13748. }
  13749. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  13750. $rootScope.tenderVendor = [{}];
  13751. }
  13752. $scope.changeShipAddress = false;
  13753. $scope.changeAddress = function() {
  13754. if ($scope.changeShipAddress) {
  13755. $scope.changeShipAddress = false;
  13756. } else {
  13757. $scope.changeShipAddress = true;
  13758. }
  13759. };
  13760. $scope.changeContactInfo = function(en) {
  13761. if (en.changeContact) {
  13762. en.changeContact = false;
  13763. } else {
  13764. en.changeContact = true;
  13765. }
  13766. };
  13767. $scope.changeCurrency = function(tender) {
  13768. if (tender.currency !== 'RMB') {
  13769. $scope.notRMB = true;
  13770. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  13771. tender.invoiceType = 0;
  13772. } else {
  13773. $scope.notRMB = false;
  13774. }
  13775. };
  13776. // $scope.validateNumber = function (value) { // 采购数量 正整数
  13777. // var regex = /^\+?[1-9][0-9]*$/;
  13778. // if (!regex.test(value) || value === 0 || value === null) {
  13779. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  13780. // }
  13781. // };
  13782. // 查找供应商
  13783. $scope.dbfindVendor = function(){
  13784. var modalInstance = $modal.open({
  13785. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  13786. controller: 'DbfindVendorCtrl',
  13787. size: 'lg',
  13788. resolve: {
  13789. }
  13790. });
  13791. var ifPush = true;
  13792. modalInstance.result.then(function(data){
  13793. angular.forEach(data, function(vendor) {
  13794. // 获取供应商联系人
  13795. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function(data) {
  13796. vendor.vendorEnterprise.contacts = data;
  13797. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  13798. });
  13799. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  13800. $scope.tenderProd.enterpriseBaseInfo = [{}];
  13801. // 获取供应商联系人
  13802. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  13803. } else {
  13804. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  13805. ifPush = true;
  13806. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  13807. ifPush = false;
  13808. break; // 判定到已存在供应商,就终止循环。
  13809. }
  13810. }
  13811. if (ifPush) {
  13812. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  13813. }
  13814. }
  13815. });
  13816. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  13817. }, function(){
  13818. });
  13819. };
  13820. // 新增供应商联系人
  13821. $scope.addContact = function(en) {
  13822. var modalInstance = $modal.open({
  13823. animation: true,
  13824. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13825. controller: 'AddContacCtrl',
  13826. resolve: {
  13827. }
  13828. });
  13829. modalInstance.result.then(function(data) {
  13830. en.contact = data;
  13831. en.contact.venduu = en.uu;
  13832. Vendor.saveContact({}, en.contact, function(data) {
  13833. Vendor.contacts({venduu: en.uu}, {}, function(data) {
  13834. en.contacts = data;
  13835. en.contact = data[0]; // 新增的作为联系人
  13836. });
  13837. toaster.pop('success', '提示', '联系人保存成功');
  13838. }, function(response) {
  13839. toaster.pop('error', '失败', response.data);
  13840. });
  13841. });
  13842. };
  13843. // 删除一个供应商
  13844. $scope.removeVendor = function(index) {
  13845. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  13846. };
  13847. // 删除供应商时,后台删除投标单
  13848. $scope.removeSaleTender = function (id, vendUU) {
  13849. var hasSaved = false;
  13850. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  13851. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  13852. hasSaved = true;
  13853. }
  13854. });
  13855. if (hasSaved) {
  13856. PurcTender.removeSaleTender ({id : id, vendUU : vendUU}, {}, function(data) {
  13857. }, function(response) {
  13858. toaster.pop('error', '提示', response.data);
  13859. });
  13860. }
  13861. };
  13862. // 删除产品明细时,后台删除产品明细
  13863. $scope.deleteProd = function (tenderProd) {
  13864. if (tenderProd.id) {
  13865. PurcTender.deleteProd ({tenderProdId : tenderProd.id}, {}, function(data) {
  13866. }, function(response) {
  13867. toaster.pop('error', '提示', response.data);
  13868. });
  13869. }
  13870. };
  13871. // // 查找客户物料
  13872. // $scope.dbfindCustProd = function(){
  13873. // if($scope.item.$editing) {
  13874. // if($scope.item.quotation.cust.uu) {
  13875. // var modalInstance = $modal.open({
  13876. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  13877. // controller: 'DbfindCustProdCtrl',
  13878. // size: 'lg',
  13879. // resolve: {
  13880. // custUU: function(){return $scope.item.quotation.cust.uu}
  13881. // }
  13882. // });
  13883. //
  13884. // modalInstance.result.then(function(data){
  13885. // $scope.item.product = data;
  13886. // }, function(){
  13887. //
  13888. // });
  13889. // } else {
  13890. // toaster.pop('error', '错误', '请先选择客户');
  13891. // }
  13892. // }
  13893. // };
  13894. if (!$scope.attaches) {
  13895. $scope.attaches = []; // 存放上传了的附件
  13896. }
  13897. $scope.upload = function(myFile) { // 上传附件
  13898. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  13899. $upload.upload({
  13900. url: 'tender/addTenderAttach',
  13901. file: file,
  13902. method: 'POST'
  13903. // data: {
  13904. // tender: $scope.tender
  13905. // }
  13906. }).success(function (attach) {
  13907. $scope.attaches.push(attach);
  13908. });
  13909. };
  13910. $scope.removeAttach = function(id, index) {
  13911. $scope.attaches.splice(index, 1);
  13912. // PurcTender.removeAttach({attachId:id}, function() {
  13913. //
  13914. // });
  13915. };
  13916. var sleep = function (d){
  13917. for(var t = Date.now();Date.now() - t <= d;);
  13918. };
  13919. // 保存和发布招标单
  13920. $scope.save = function(isPublish){
  13921. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  13922. toaster.pop('info','提示','请先指定供应商');
  13923. } else {
  13924. $scope.loading = true;
  13925. // --组装证照要求
  13926. var myCertificate = [];
  13927. angular.forEach($scope.certificates, function(certificate) {
  13928. if (certificate.checked) {
  13929. myCertificate.push(certificate.name);
  13930. }
  13931. });
  13932. $scope.tender.certificate = myCertificate.join(',');
  13933. if(!$scope.tender.code) { //新增,设单号
  13934. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  13935. }
  13936. if($scope.tender.date instanceof Date) {
  13937. $scope.tender.date = $scope.tender.date.getTime();
  13938. }
  13939. if($scope.tender.endDate instanceof Date) {
  13940. $scope.tender.endDate = $scope.tender.endDate.getTime();
  13941. }
  13942. if($scope.tender.publishDate instanceof Date) {
  13943. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  13944. }
  13945. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  13946. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  13947. $scope.tender.purchaseTenderProds[i].index = i + 1;
  13948. }
  13949. $scope.tender.tenderAttaches = $scope.attaches;
  13950. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  13951. var enInfos = [];
  13952. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  13953. var enInfo = {
  13954. uu: null,
  13955. contact: null,
  13956. contactTel: null
  13957. };
  13958. enInfo.uu = enterpriseBaseInfo.uu;
  13959. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  13960. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  13961. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  13962. }
  13963. enInfos.push(enInfo);
  13964. });
  13965. if (isPublish) { // 发布
  13966. toaster.pop('info', '提示', '正在发布,请稍候');
  13967. $scope.tender.isPublish = 1;
  13968. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  13969. // sleep(1500); //当前方法暂停1.5秒
  13970. $scope.loading = false;
  13971. toaster.pop('success', '成功', '发布成功');
  13972. window.location.hash = '#/purc/tender';
  13973. }, function(response){
  13974. $scope.loading = false;
  13975. toaster.pop('error', '发布失败', response.data);
  13976. });
  13977. } else { // 保存
  13978. toaster.pop('info', '提示', '正在保存,请稍候');
  13979. $scope.tender.isPublish = 0;
  13980. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  13981. $scope.loading = false;
  13982. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  13983. toaster.pop('success', '成功', '保存成功');
  13984. window.location.hash = '#/purc/tender';
  13985. }, function(response){
  13986. $scope.loading = false;
  13987. toaster.pop('error', '保存失败', response.data);
  13988. });
  13989. }
  13990. }
  13991. };
  13992. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  13993. $scope.removeChecked = function() {
  13994. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  13995. $scope.tenderProd.enterpriseBaseInfo = [];
  13996. }
  13997. };
  13998. // 删除(在录入状态)
  13999. $scope.deleteThis = function(id) {
  14000. PurcTender.deleteOne({id:id}, {}, function(data) {
  14001. toaster.pop('info', '提示', '删除成功');
  14002. window.location.hash = '#/purc/tender';
  14003. });
  14004. };
  14005. // 更新和发布(在录入状态)
  14006. $scope.updateSaved = function(isPublish){
  14007. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  14008. toaster.pop('info','提示','请先指定供应商');
  14009. } else {
  14010. $scope.loading = true;
  14011. // --组装证照要求
  14012. var myCertificate = [];
  14013. angular.forEach($scope.certificates, function(certificate) {
  14014. if (certificate.checked) {
  14015. myCertificate.push(certificate.name);
  14016. }
  14017. });
  14018. $scope.tender.certificate = myCertificate.join(',');
  14019. if($scope.tender.endDate instanceof Date) {
  14020. $scope.tender.endDate = $scope.tender.endDate.getTime();
  14021. }
  14022. if($scope.tender.publishDate instanceof Date) {
  14023. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  14024. }
  14025. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  14026. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  14027. $scope.tender.purchaseTenderProds[i].index = i + 1;
  14028. }
  14029. $scope.tender.tenderAttaches = $scope.attaches;
  14030. if ($scope.tender.shipadd) {
  14031. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  14032. }
  14033. angular.forEach($scope.tender.purchaseTenderProds, function(tenderProd){
  14034. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  14035. });
  14036. var enInfos = [];
  14037. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  14038. var enInfo = {
  14039. uu: null,
  14040. contact: null,
  14041. contactTel: null
  14042. };
  14043. enInfo.uu = enterpriseBaseInfo.uu;
  14044. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  14045. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  14046. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  14047. }
  14048. enInfos.push(enInfo);
  14049. });
  14050. if (isPublish) { // 发布
  14051. toaster.pop('info', '提示', '正在发布,请稍候');
  14052. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data){
  14053. sleep(1500); //当前方法暂停1.5秒
  14054. // $scope.loading = false;
  14055. toaster.pop('success', '成功', '发布成功');
  14056. window.location.hash = '#/purc/tender';
  14057. }, function(response){
  14058. $scope.loading = false;
  14059. toaster.pop('error', '发布失败', response.data);
  14060. });
  14061. } else { // 保存
  14062. toaster.pop('info', '提示', '正在保存,请稍候');
  14063. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function(data) {
  14064. $scope.loading = false;
  14065. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  14066. toaster.pop('success', '成功', '保存成功');
  14067. window.location.reload();
  14068. }, function(response){
  14069. $scope.loading = false;
  14070. toaster.pop('error', '保存失败', response.data);
  14071. });
  14072. }
  14073. }
  14074. };
  14075. $scope.currentDay = function() {
  14076. return $filter('date')(new Date(), 'yyyy-MM-dd');
  14077. };
  14078. $scope.getMinDate = function() {
  14079. // var now = new Date();
  14080. // now = now.setDate(now.getDate()+1);
  14081. // var minDate = angular.copy($scope.tender.endDate);
  14082. // minDate = minDate.setDate(minDate.getDate() + 1);
  14083. if ($scope.tender.endDate instanceof Date) {
  14084. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  14085. }
  14086. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  14087. };
  14088. $scope.getMaxDate = function() {
  14089. // var maxDate = angular.copy($scope.tender.publishDate);
  14090. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  14091. if ($scope.tender.publishDate instanceof Date) {
  14092. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  14093. }
  14094. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  14095. };
  14096. $scope.openDatePicker = function($event, item, openParam) {
  14097. $event.preventDefault();
  14098. $event.stopPropagation();
  14099. item[openParam] = !item[openParam];
  14100. };
  14101. }]);
  14102. //类目选择模态框(招标产品明细)
  14103. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  14104. $scope.actives = actives;
  14105. $scope.kinds = [[], [], [], []];
  14106. // 获取子类目
  14107. var getChildren = function(pid, deep) {
  14108. KindAPI.getChildren({parentId: pid}, function(data) {
  14109. $scope.kinds[deep] = data;
  14110. }, function(response) {
  14111. toaster.pop('error', '获取子类目失败', response.data);
  14112. });
  14113. };
  14114. // 改变节点选中状态
  14115. var changeStatus = function(item, deep) {
  14116. var actives = [], level = 0;
  14117. angular.forEach($scope.kinds, function(ks, i) {
  14118. if(i > deep) {
  14119. $scope.kinds[i] = [];
  14120. } else {
  14121. angular.forEach(ks, function(k, j) {
  14122. if(i == deep) {
  14123. if(k.id == item.id) {
  14124. $scope.kinds[i][j].$active = true;
  14125. actives.push(k);
  14126. } else {
  14127. k.$active = null;
  14128. }
  14129. } else {
  14130. if(k.$active) {
  14131. actives.push(k);
  14132. }
  14133. }
  14134. });
  14135. }
  14136. });
  14137. // 选择的节点
  14138. $scope.actives = actives;
  14139. $scope.active = item;
  14140. // 当前可操作的层级
  14141. if(deep < 3) {
  14142. $scope.activeDeep = deep + 1;
  14143. }
  14144. };
  14145. // 节点点击后获取子类目,节点被选中
  14146. $scope.onItemClick = function(item, deep) {
  14147. changeStatus(item, deep);
  14148. if (!item.isLeaf) {
  14149. getChildren(item.id, deep + 1);
  14150. }
  14151. };
  14152. // 重新加载数据
  14153. function reload(deep) {
  14154. var pid;
  14155. if(deep) {
  14156. pid = $scope.actives[deep - 1].id;
  14157. } else {
  14158. pid = 0;
  14159. deep = 0;
  14160. }
  14161. getChildren(pid, deep);
  14162. }
  14163. // 初始加载数据,获取第一层的类目
  14164. if($scope.actives) {
  14165. angular.forEach($scope.actives, function(v, k) {
  14166. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  14167. $scope.kinds[k] = data;
  14168. angular.forEach($scope.kinds[k], function(kind, i){
  14169. if(kind.id == v.id) {
  14170. $scope.kinds[k][i].$active = true;
  14171. $scope.actives[k] = $scope.kinds[k][i];
  14172. }
  14173. })
  14174. }, function(response) {
  14175. toaster.pop('error', '获取子类目失败', response.data);
  14176. });
  14177. });
  14178. } else {
  14179. reload();
  14180. }
  14181. // 取消
  14182. $scope.cancel = function() {
  14183. $modalInstance.dismiss();
  14184. };
  14185. // 确认选择
  14186. $scope.check = function() {
  14187. var a = {
  14188. active: $scope.active,
  14189. actives: $scope.actives
  14190. };
  14191. $modalInstance.close(a);
  14192. };
  14193. }]);
  14194. //品牌选择模态框的controller
  14195. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  14196. $scope.filter = {};
  14197. $scope.brandsTableParams = new ngTableParams({
  14198. page : 1,
  14199. count : 6,
  14200. sorting : {
  14201. nameCn: 'asc'
  14202. }
  14203. }, {
  14204. total : 0,
  14205. counts : [],
  14206. getData : function($defer, params) {
  14207. var param = BaseService.parseParams(params.url());
  14208. param.keyword = $scope.filter.keyword;
  14209. var keyword = $scope.filter.keyword;
  14210. // param.keyword = $scope.filter.keyword;
  14211. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  14212. if (page) {
  14213. params.total(page.totalElement);
  14214. $defer.resolve(page.content);
  14215. }
  14216. }, function(){
  14217. });
  14218. }
  14219. });
  14220. // 搜索
  14221. $scope.search = function() {
  14222. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  14223. $scope.brandsTableParams.page(1);
  14224. $scope.brandsTableParams.reload();
  14225. };
  14226. // 选择
  14227. $scope.select = function(brand){
  14228. $modalInstance.close(brand);
  14229. };
  14230. // 关闭
  14231. $scope.cancel = function() {
  14232. $modalInstance.dismiss();
  14233. };
  14234. }]);
  14235. /**
  14236. * 招标单批量导入
  14237. */
  14238. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  14239. // 通过excel批量上传物料
  14240. $scope.result = null;
  14241. $scope.upload = function() {
  14242. var file = $scope.myFiles[0];
  14243. $upload.upload({
  14244. url: 'tender/release/excel',
  14245. file: file,
  14246. method: 'POST'
  14247. }).success(function(data) {
  14248. $scope.result = data;
  14249. $scope.success = $scope.result.success;
  14250. $scope.total = $scope.result.total;
  14251. $scope.alters = $scope.result.alters;
  14252. }).error(function(response) {
  14253. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  14254. });
  14255. };
  14256. // 查看范例
  14257. $scope.showImg = function() {
  14258. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  14259. box.show();
  14260. box.find('img').attr('src', src);
  14261. box.find('a').click(function(){
  14262. box.hide();
  14263. });
  14264. box.dblclick(function(){
  14265. box.hide();
  14266. });
  14267. };
  14268. // 下载模板
  14269. $scope.download = function() {
  14270. window.location.href = 'tender/upload/template';
  14271. };
  14272. $scope.enSure = function() {
  14273. $modalInstance.close($scope.result.items);
  14274. }
  14275. $scope.cancel = function() {
  14276. $modalInstance.dismiss();
  14277. }
  14278. }]);
  14279. /**
  14280. * 评标
  14281. */
  14282. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  14283. BaseService.scrollBackToTop();
  14284. $scope.tenderItems = [];
  14285. // 采购方获取评标单
  14286. var evaluation = function() {
  14287. $scope.loading = true;
  14288. PurcTender.getOne({id: $stateParams.id}, function(data){
  14289. data.$editing = false;
  14290. $scope.tender = data;
  14291. $scope.tableParams = new ngTableParams({}, { dataset: data});
  14292. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  14293. $scope.loading = false;
  14294. }, function(response){
  14295. $scope.loading = false;
  14296. toaster.pop('error', '数据加载失败', response.data);
  14297. });
  14298. };
  14299. evaluation();
  14300. $scope.orderType = '';
  14301. // $scope.dir = '-';
  14302. // 改变排序顺序
  14303. $scope.changeOrder = function(type){
  14304. $scope.orderType = type;
  14305. // if(!$scope.dir || $scope.dir === '') {
  14306. // $scope.dir = '-';
  14307. // }else {
  14308. // $scope.dir = '';
  14309. // }
  14310. };
  14311. $scope.submit = function(tender) {
  14312. var canSubmit = false;
  14313. var hasDecide = false;
  14314. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  14315. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  14316. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  14317. hasDecide = true;
  14318. }
  14319. });
  14320. if (hasDecide) {
  14321. canSubmit = true;
  14322. }
  14323. });
  14324. if (!canSubmit) {
  14325. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  14326. } else {
  14327. PurcTender.decide(tender, function(){
  14328. toaster.pop('success', '确认成功');
  14329. window.location.hash = '#/purc/tender';
  14330. }, function(response){
  14331. toaster.pop('error', '确认失败', response.data);
  14332. });
  14333. }
  14334. }
  14335. }]);
  14336. /**
  14337. * 客户招标
  14338. *
  14339. */
  14340. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  14341. BaseService.scrollBackToTop();
  14342. if($rootScope.active) {
  14343. $scope.active = $rootScope.active;
  14344. $rootScope.active = null;
  14345. } else {
  14346. $scope.active = 'todo';
  14347. }
  14348. /**
  14349. * 改变类型
  14350. */
  14351. var getTypeCondition = function(zone, condition) {
  14352. if(zone == -1) {
  14353. condition.ifOpen = null;
  14354. } else if(zone == 1) {
  14355. condition.ifOpen = 1;
  14356. } else {
  14357. condition.ifOpen = 0;
  14358. }
  14359. };
  14360. $scope.dateZoneText = '不限';
  14361. $scope.typeText = '全部';
  14362. $scope.deliveryZoneText = '不限';
  14363. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  14364. /* 时间筛选初始化*/
  14365. var fromDate = new Date();
  14366. var toDate = new Date();
  14367. fromDate.setMonth(fromDate.getMonth() - 1);
  14368. fromDate.setHours(0,0,0,0);
  14369. toDate.setHours(23,59,59,999);
  14370. $scope.condition.dateFrom = fromDate;
  14371. $scope.condition.dateTo = toDate;
  14372. $scope.changeDateZone = function(zone) {
  14373. $scope.condition.dateZone = zone;
  14374. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14375. $scope.condition.$dateZoneOpen = false;
  14376. getDateCondition(zone, $scope.condition);
  14377. $scope.tableParams.reload();
  14378. };
  14379. $scope.changeDeliveryZone = function(zone) {
  14380. $scope.condition.deliveryZoneText = zone;
  14381. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  14382. $scope.condition.$delievryZoneOpen = false;
  14383. getDelveryCondition(zone, $scope.condition);
  14384. $scope.tableParams.page(1);
  14385. $scope.tableParams.reload();
  14386. };
  14387. $scope.changeType = function(type) {
  14388. $scope.condition.type = type;
  14389. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  14390. getTypeCondition(type, $scope.condition);
  14391. $scope.tableParams.reload();
  14392. };
  14393. $scope.setActive = function(state) {
  14394. if($scope.active != state) {
  14395. $scope.active = state;
  14396. if($scope.tableParams.page() == 1)
  14397. $scope.tableParams.reload();
  14398. else
  14399. $scope.tableParams.page(1);
  14400. }
  14401. };
  14402. $scope.tableParams = new ngTableParams({
  14403. page : 1,
  14404. count : 20,
  14405. sorting: {
  14406. 'tender.endDate': 'desc',
  14407. 'tender.enterprise.enName': 'asc',
  14408. 'tender.code': 'asc'
  14409. }
  14410. }, {
  14411. total : 0,
  14412. counts: [5, 10, 25, 50],
  14413. getData : function($defer, params) {
  14414. $scope.loading = true;
  14415. var pageParams = params.url();
  14416. var realActive = {};
  14417. pageParams.searchFilter = { // 筛选条件
  14418. keyword: $scope.keyword,
  14419. pt_ifopen: $scope.condition.ifOpen,
  14420. fromDate: getDateTime($scope.condition.dateFrom),
  14421. endDate: getDateTime($scope.condition.dateTo)
  14422. };
  14423. AccountEnterprise.get({}, function(data){
  14424. $scope.loading = false;
  14425. $scope.currentEn = data;
  14426. });
  14427. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  14428. $scope.loading = false;
  14429. if(page) {
  14430. params.total(page.totalElement);
  14431. $defer.resolve(page.content);
  14432. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  14433. angular.forEach(page.content, function(purcTender) {
  14434. purcTender.vendorHasBid = false;
  14435. angular.forEach(purcTender.purchaseTenderProds, function(tenderProd) {
  14436. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  14437. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  14438. tenderProd.currentItem = saleTenderItem;
  14439. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  14440. purcTender.vendorHasBid = true;
  14441. }
  14442. }
  14443. });
  14444. });
  14445. });
  14446. }
  14447. }, function(response){
  14448. $scope.loading = false;
  14449. toaster.pop('error', '数据加载失败', response.data);
  14450. });
  14451. }
  14452. });
  14453. $scope.openDatePicker = function($event, item, openParam) {
  14454. $event.preventDefault();
  14455. $event.stopPropagation();
  14456. item[openParam] = !item[openParam];
  14457. };
  14458. $scope.openFilterDatePicker = function($event, item, openParam) {
  14459. $event.preventDefault();
  14460. $event.stopPropagation();
  14461. item[openParam] = !item[openParam];
  14462. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  14463. $scope.tableParams.reload();
  14464. }
  14465. };
  14466. $scope.parseDate = function(dateStr) {
  14467. if(dateStr)
  14468. return Date.parse(dateStr, 'yyyy-MM-dd');
  14469. return new Date();
  14470. };
  14471. // 选择查找日期
  14472. $scope.onDateCondition = function(){
  14473. $scope.tableParams.page(1);
  14474. $scope.tableParams.reload();
  14475. };
  14476. // 搜索框回车
  14477. $scope.onSearch = function() {
  14478. $scope.tableParams.page(1);
  14479. $scope.tableParams.reload();
  14480. };
  14481. }]);
  14482. /**
  14483. * 平台公开招标
  14484. *
  14485. */
  14486. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  14487. BaseService.scrollBackToTop();
  14488. /**
  14489. * 改变单据日期范围
  14490. */
  14491. var getTenderDateCondition = function(zone, condition) {
  14492. var date = new Date();
  14493. if(zone == -1) {
  14494. condition.dateFrom = null;
  14495. condition.dateTo = null;
  14496. } else if(zone == 7) { // 一星期内
  14497. date.setDate(date.getDate() - 7);
  14498. condition.dateFrom = date;
  14499. condition.dateTo = new Date();
  14500. } else if(zone == 1) { // 一个月内
  14501. date.setMonth(date.getMonth() - 1);
  14502. condition.dateFrom = date;
  14503. condition.dateTo = new Date();
  14504. } else if(zone == 3) { // 三个月内
  14505. date.setMonth(date.getMonth() - 3);
  14506. condition.dateFrom = date;
  14507. condition.dateTo = new Date();
  14508. } else if (zone == 6) { // 半年内
  14509. date.setMonth(date.getMonth() - 6);
  14510. condition.dateFrom = date;
  14511. condition.dateTo = new Date();
  14512. } else { // 一年内
  14513. date.setYear(date.getYear() - 1);
  14514. condition.dateFrom = date;
  14515. condition.dateTo = new Date();
  14516. }
  14517. };
  14518. $scope.active = 'all';
  14519. $scope.dateZoneText = '不限';
  14520. $scope.deliveryZoneText = '不限';
  14521. $scope.condition = {dateZone: -1};
  14522. $scope.changeDateZone = function(zone) {
  14523. $scope.condition.dateZone = zone;
  14524. $scope.condition.$dateZoneOpen = false;
  14525. getTenderDateCondition(zone, $scope.condition);
  14526. $scope.tableParams.page(1);
  14527. $scope.tableParams.reload();
  14528. };
  14529. $scope.openDatePicker = function($event, item, openParam) {
  14530. $event.preventDefault();
  14531. $event.stopPropagation();
  14532. item[openParam] = !item[openParam];
  14533. };
  14534. $scope.parseDate = function(dateStr) {
  14535. if(dateStr)
  14536. return Date.parse(dateStr, 'yyyy-MM-dd');
  14537. return new Date();
  14538. };
  14539. // 选择查找日期
  14540. $scope.onDateCondition = function(){
  14541. $scope.tableParams.page(1);
  14542. $scope.tableParams.reload();
  14543. };
  14544. // $scope.setActive = function(state) {
  14545. // if($scope.active != state) {
  14546. // $scope.active = state;
  14547. // if($scope.tableParams.page() == 1)
  14548. // $scope.tableParams.reload();
  14549. // else
  14550. // $scope.tableParams.page(1);
  14551. // }
  14552. // };
  14553. var getOpenState = function(active) {
  14554. var fn = 'getOpenAll';
  14555. switch(active) {
  14556. case 'all':
  14557. fn = 'getOpenAll';break;
  14558. // case 'done':
  14559. // fn = 'getOpenDone';break;
  14560. case 'todo':
  14561. fn = 'getOpenTodo';break;
  14562. case 'end':
  14563. fn = 'getOpenEnd';break;
  14564. // case 'waiting':
  14565. // fn = 'getOpenWaiting';break;
  14566. }
  14567. return fn;
  14568. };
  14569. $scope.tableParams = new ngTableParams({
  14570. page : 1,
  14571. count : 20,
  14572. sorting: {
  14573. 'tender.endDate': 'desc',
  14574. 'tender.enterprise.enName': 'asc',
  14575. 'tender.code': 'asc'
  14576. }
  14577. }, {
  14578. total : 0,
  14579. counts: [],
  14580. getData : function($defer, params) {
  14581. $scope.loading = true;
  14582. var pageParams = params.url();
  14583. var realActive = {};
  14584. pageParams.searchFilter = { // 筛选条件
  14585. keyword: $scope.keyword,
  14586. fromDate: getDateTime($scope.condition.dateFrom),
  14587. endDate: getDateTime($scope.condition.dateTo)
  14588. };
  14589. AccountEnterprise.get({}, function(data){
  14590. $scope.loading = false;
  14591. $scope.currentEn = data;
  14592. });
  14593. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  14594. $scope.loading = false;
  14595. if(page) {
  14596. params.total(page.totalElement);
  14597. $defer.resolve(page.content);
  14598. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  14599. }
  14600. }, function(response){
  14601. $scope.loading = false;
  14602. toaster.pop('error', '数据加载失败', response.data);
  14603. });
  14604. }
  14605. });
  14606. $scope.toDetail = function(id) {
  14607. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  14608. };
  14609. // var stautsItem = [];
  14610. // $scope.getTenderStatus = function (tender) {
  14611. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  14612. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  14613. // stautsItem = thisItem;
  14614. // }
  14615. // });
  14616. // if (!stautsItem.price) {
  14617. // return "daitoubiao";
  14618. // } else if (!stautsItem.applystatus) {
  14619. // return "yitoubiao";
  14620. // } else if (stautsItem.applystatus == 1) {
  14621. // return "zhongbiao";
  14622. // } else if (stautsItem.applystatus == 0) {
  14623. // return "weizhongbiao";
  14624. // }
  14625. // };
  14626. // 搜索框回车
  14627. $scope.onSearch = function() {
  14628. $scope.tableParams.page(1);
  14629. $scope.tableParams.reload();
  14630. };
  14631. }]);
  14632. /**
  14633. * 采购方查看供应商投标单
  14634. */
  14635. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  14636. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  14637. // $scope.item = data; // 供应商查看
  14638. // $scope.loading = false;
  14639. // }, function(response){
  14640. // $scope.loading = false;
  14641. // toaster.pop('error', '数据加载失败', response.data);
  14642. // });
  14643. PurcTender.getOne({id: $stateParams.id}, function(data){
  14644. $scope.bid = data;
  14645. var vendUU = Number($stateParams.vendUU);
  14646. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  14647. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  14648. if (saleTenderItem.saleTender.vendUU === vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  14649. tenderProd.currentItem = saleTenderItem;
  14650. $scope.saleTender = saleTenderItem.saleTender;
  14651. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  14652. }
  14653. });
  14654. });
  14655. }, function(response){
  14656. toaster.pop('error', '数据加载失败', response.data);
  14657. });
  14658. }]);
  14659. /**
  14660. * 查看投标单详情
  14661. */
  14662. 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) {
  14663. BaseService.scrollBackToTop();
  14664. if (!$scope.attaches) {
  14665. $scope.attaches = []; // 存放上传了的附件
  14666. }
  14667. // var staticItem = null;
  14668. // $scope.loading = true;
  14669. // PurcTender.getItem({id: $stateParams.id}, function(data){
  14670. // $scope.item = data; // 用于投标
  14671. // if ($scope.item.enterpriseBaseInfo != null) {
  14672. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  14673. // }
  14674. // staticItem = angular.copy(data);
  14675. // $scope.loading = false;
  14676. // }, function(response){
  14677. // $scope.loading = false;
  14678. // toaster.pop('error', '数据加载失败', response.data);
  14679. // });
  14680. var sleep = function (d){
  14681. for(var t = Date.now();Date.now() - t <= d;);
  14682. };
  14683. AccountEnterprise.get({}, function(data){
  14684. $scope.currentEn = data;
  14685. });
  14686. PurcTender.getOne({id: $stateParams.id}, function(data){
  14687. $scope.bid = data;
  14688. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  14689. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  14690. if (!$scope.currentEn) {
  14691. AccountEnterprise.get({}, function(data){
  14692. $scope.currentEn = data;
  14693. });
  14694. }
  14695. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  14696. tenderProd.currentItem = saleTenderItem;
  14697. $scope.saleTender = saleTenderItem.saleTender;
  14698. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  14699. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  14700. }
  14701. });
  14702. });
  14703. }, function(response){
  14704. toaster.pop('error', '数据加载失败', response.data);
  14705. });
  14706. $scope.upload = function(myFile) { // 上传附件
  14707. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  14708. $upload.upload({
  14709. url: 'tender/addTenderItemAttach',
  14710. file: file,
  14711. method: 'POST'
  14712. }).success(function (attach) {
  14713. $scope.attaches.push(attach);
  14714. });
  14715. };
  14716. $scope.removeAttach = function(attachId, index) {
  14717. $scope.attaches.splice(index, 1);
  14718. // PurcTender.removeAttach({attachId : id}, {}, function() {
  14719. //
  14720. // });
  14721. };
  14722. var taxrateYes = false;
  14723. var cycleYes = false;
  14724. var priceYes = false;
  14725. $scope.canSave = false;
  14726. $scope.validateThis = function(value, type) {
  14727. switch(type) {
  14728. case 'taxrate':
  14729. var regex = /^\+?[0-9][0-9]{0,1}$/;
  14730. if (regex.test(value)) {
  14731. taxrateYes = true;
  14732. } else {
  14733. if (value) {
  14734. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  14735. }
  14736. }
  14737. break;
  14738. case 'cycle':
  14739. regex = /^\+?[1-9][0-9]*$/;
  14740. if (regex.test(value)) {
  14741. cycleYes = true;
  14742. } else {
  14743. if (value) {
  14744. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  14745. }
  14746. }
  14747. break;
  14748. case 'price':
  14749. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  14750. if (regex.test(value) && value !== 0) {
  14751. priceYes = true;
  14752. } else {
  14753. if (value) {
  14754. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  14755. }
  14756. }
  14757. break;
  14758. }
  14759. };
  14760. $scope.emNumYes = true;
  14761. $scope.validEmNum = function (value) {
  14762. var regex = /^\+?[1-9][0-9]*$/;
  14763. if (!regex.test(value) || value === 0 || value !== null) {
  14764. $scope.emNumYes = false;
  14765. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  14766. }
  14767. };
  14768. $scope.validateProds = function(tenderProd) {
  14769. $scope.canSave = true;
  14770. if (tenderProd.currentItem.cycle || tenderProd.currentItem.taxrate || tenderProd.currentItem.price) {
  14771. var cycleRegex = /^\+?[1-9][0-9]*$/;
  14772. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  14773. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  14774. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  14775. // 判断填写过的有为0或不符合正则式的,设置不能保存
  14776. if (!cycleRegex.test(tenderProd.currentItem.cycle) || !taxrateRegex.test(tenderProd.currentItem.taxrate) || !priceRegex.test(tenderProd.currentItem.price)) {
  14777. $scope.canSave = false;
  14778. } else {
  14779. $scope.canSave = true;
  14780. }
  14781. }
  14782. };
  14783. // 投标
  14784. $scope.bidIt = function(tender, currentEnBaseInfo){
  14785. $scope.loading = true;
  14786. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  14787. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  14788. }
  14789. var saleTenderItems = [];
  14790. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  14791. if (tenderProd.currentItem) {
  14792. if ("" !== tenderProd.currentItem.price && "" !== tenderProd.currentItem.taxrate && "" !== tenderProd.currentItem.cycle) {
  14793. tenderProd.currentItem.saleTender = {};
  14794. saleTenderItems.push(tenderProd.currentItem);
  14795. }
  14796. }
  14797. });
  14798. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  14799. $scope.loading = false;
  14800. toaster.pop('info', '成功', '投标成功');
  14801. // $window.location.reload();
  14802. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  14803. // window.location.hash = '#/sale/opentender';
  14804. // } else {
  14805. window.location.hash = '#/sale/tender';
  14806. // }
  14807. }, function(response){
  14808. $scope.loading = false;
  14809. toaster.pop('error', '投标失败', '出现异常,投标失败');
  14810. });
  14811. };
  14812. $scope.condition = {
  14813. $fromOpened:false
  14814. };
  14815. $scope.getMaxDate = function() {
  14816. return $filter('date')(new Date(), 'yyyy-MM-dd');
  14817. };
  14818. $scope.openDatePicker = function($event, item, openParam) {
  14819. $event.preventDefault();
  14820. $event.stopPropagation();
  14821. item[openParam] = !item[openParam];
  14822. };
  14823. }]);
  14824. /**
  14825. * 公开招标转投标单
  14826. */
  14827. 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) {
  14828. BaseService.scrollBackToTop();
  14829. $scope.attaches = []; // 存放上传了的附件
  14830. var sleep = function (d){
  14831. for(var t = Date.now();Date.now() - t <= d;);
  14832. }
  14833. var getCurrentEn = function() {
  14834. AccountEnterprise.get({}, function(data){
  14835. $scope.currentEn = data;
  14836. });
  14837. }
  14838. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  14839. $scope.loading = true;
  14840. getCurrentEn();
  14841. PurcTender.getOne({id: $stateParams.id}, function(data){
  14842. data.$editing = false;
  14843. $scope.tender = data;
  14844. $scope.tenderProd = data.purchaseTenderProds;
  14845. // parseCertificate($scope.tender.certificate);
  14846. // $scope.firstProd = data.purchaseTenderProds[0];
  14847. $scope.currentHasBid = false; // 默认当前企业未转投标单
  14848. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  14849. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  14850. $scope.currentHasBid = true;
  14851. }
  14852. });
  14853. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  14854. // console.log($scope.tenderProd.enterpriseBaseInfo);
  14855. $scope.loading = false;
  14856. $scope.attaches = $scope.tender.tenderAttaches;
  14857. }, function(response){
  14858. $scope.loading = false;
  14859. toaster.pop('error', '数据加载失败', response.data);
  14860. });
  14861. }
  14862. $scope.hasClick = false;
  14863. $scope.iWantToBid = function(id) {
  14864. $scope.hasClick = true;
  14865. PurcTender.addItems({id: id}, {}, function(data){ // 添加明细
  14866. // $scope.tender = data;
  14867. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  14868. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  14869. // if (!$scope.currentEn) {
  14870. // AccountEnterprise.get({}, function(data){
  14871. // $scope.currentEn = data;
  14872. // });
  14873. // }
  14874. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  14875. // tenderProd.currentItem = saleTenderItem;
  14876. // $scope.saleTender = saleTenderItem.saleTender;
  14877. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  14878. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  14879. // }
  14880. // });
  14881. // });
  14882. toaster.pop('success', '成功', '转投标单成功');
  14883. window.location.hash = "#/sale/tender/" + id;
  14884. }, function(response){
  14885. toaster.pop('error', '操作失败', response.data);
  14886. });
  14887. // $scope.upload = function(myFile) { // 上传附件
  14888. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  14889. // $upload.upload({
  14890. // url: 'tender/addTenderItemAttach',
  14891. // file: file,
  14892. // method: 'POST'
  14893. // }).success(function (attach) {
  14894. // $scope.attaches.push(attach);
  14895. // });
  14896. // };
  14897. };
  14898. // $scope.removeAttach = function(id, index) {
  14899. // $scope.attaches.splice(index, 1);
  14900. // PurcTender.removeAttach({attachId:id}, function() {
  14901. //
  14902. // });
  14903. // };
  14904. // var taxrateYes = false;
  14905. // var cycleYes = false;
  14906. // var priceYes = false;
  14907. // $scope.canSave = false;
  14908. // $scope.validateThis = function(value, type) {
  14909. // switch(type) {
  14910. // case 'taxrate':
  14911. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  14912. // if (regex.test(value)) {
  14913. // taxrateYes = true;
  14914. // } else {
  14915. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  14916. // }
  14917. // break;
  14918. // case 'cycle':
  14919. // regex = /^\+?[1-9][0-9]*$/;
  14920. // if (regex.test(value)) {
  14921. // cycleYes = true;
  14922. // } else {
  14923. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  14924. // }
  14925. // break;
  14926. // case 'price':
  14927. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  14928. // if (regex.test(value) && value !== 0) {
  14929. // priceYes = true;
  14930. // } else {
  14931. // if (!(value instanceof Number) || value) {
  14932. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  14933. // }
  14934. // }
  14935. // break;
  14936. // }
  14937. // };
  14938. //
  14939. // $scope.emNumYes = true;
  14940. //
  14941. // $scope.validEmNum = function (value) {
  14942. // var regex = /^\+?[1-9][0-9]*$/;
  14943. // if (!regex.test(value) || value == 0 || value !== null) {
  14944. // $scope.emNumYes = false;
  14945. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  14946. // }
  14947. // };
  14948. //
  14949. // $scope.validateProds = function(tenderProd) {
  14950. // // angular.forEach(tenderProds, function (tenderProd) {
  14951. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  14952. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  14953. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  14954. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  14955. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  14956. // console.log(tenderProd.currentItem.cycle);
  14957. // 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))) {
  14958. // $scope.canSave = false;
  14959. // } else {
  14960. // $scope.canSave = true;
  14961. // }
  14962. // // });
  14963. // };
  14964. //
  14965. // // 投标
  14966. // $scope.bidIt = function(tender, currentEnBaseInfo){
  14967. // $scope.loading = true;
  14968. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  14969. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  14970. // }
  14971. // var saleTenderItems = [];
  14972. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  14973. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  14974. // if (tenderProd.currentItem) {
  14975. // tenderProd.currentItem.saleTender = {};
  14976. // saleTenderItems.push(tenderProd.currentItem);
  14977. // }
  14978. // });
  14979. // } else {
  14980. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  14981. // if (tenderProd.currentItem) {
  14982. // saleTenderItems.push(tenderProd.currentItem);
  14983. // }
  14984. // });
  14985. // }
  14986. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  14987. // $scope.loading = false;
  14988. // toaster.pop('info', '成功', '投标成功');
  14989. // // $window.location.reload();
  14990. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  14991. // // window.location.hash = '#/sale/opentender';
  14992. // // } else {
  14993. // window.location.hash = '#/sale/tender';
  14994. // // }
  14995. // }, function(response){
  14996. // $scope.loading = false;
  14997. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  14998. // });
  14999. //
  15000. // };
  15001. //
  15002. // $scope.condition = {
  15003. // $fromOpened:false
  15004. // };
  15005. //
  15006. // $scope.getMaxDate = function() {
  15007. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  15008. // };
  15009. //
  15010. // $scope.openDatePicker = function($event, item, openParam) {
  15011. // $event.preventDefault();
  15012. // $event.stopPropagation();
  15013. // item[openParam] = !item[openParam];
  15014. // };
  15015. }]);
  15016. // 基础资料客户详情
  15017. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', 'VendorInfo', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster, VendorInfo){
  15018. BaseService.scrollBackToTop();
  15019. $scope.status = 'customer';
  15020. $scope.userInfoResult = true;
  15021. AuthenticationService.getAuthentication().success(function(data) {
  15022. $scope.loading = false;
  15023. $scope.thisUser = data;
  15024. });
  15025. $scope.customerParams = new ngTableParams({
  15026. page : 1,
  15027. count : 20
  15028. }, {
  15029. total : 0,
  15030. counts: [],
  15031. getData : function($defer, params) {
  15032. $scope.loading = true;
  15033. var pageParams = params.url();
  15034. pageParams.keyword = $scope.keyword;
  15035. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function(page){
  15036. $scope.loading = false;
  15037. if(page) {
  15038. params.total(page.totalElement);
  15039. $scope.total = page.totalElement;
  15040. $defer.resolve(page.content);
  15041. }
  15042. $scope.totalCount = page.totalElement;
  15043. }, function(response){
  15044. $scope.loading = false;
  15045. toaster.pop('error', '数据加载失败', response.data);
  15046. });
  15047. }
  15048. });
  15049. // 搜索框回车
  15050. $scope.onSearch = function(keyword) {
  15051. $scope.customerParams.page(1);
  15052. $scope.customerParams.reload();
  15053. $scope.tip = keyword;
  15054. };
  15055. // 查看详情
  15056. $scope.viewDetail = function(id) {
  15057. window.location.hash = "#/sale/customer/" + id;
  15058. }
  15059. // 取消合作关系
  15060. $scope.disableCust = function(id) {
  15061. VendorInfo.disableCust({id: id}, {}, function(data) {
  15062. if(data.success) {
  15063. toaster.pop('success', '提示', data.success);
  15064. }
  15065. // $scope.customerParams.page(1);
  15066. $scope.customerParams.reload();
  15067. }, function(response) {
  15068. toaster.pop('error', '提示', response.data);
  15069. });
  15070. }
  15071. // 解除禁用
  15072. $scope.activeCust = function(id) {
  15073. VendorInfo.activeCust({id: id}, {}, function(data) {
  15074. if(data.success) {
  15075. toaster.pop('success', '提示', data.success);
  15076. }
  15077. // $scope.customerParams.page(1);
  15078. $scope.customerParams.reload();
  15079. }, function(response) {
  15080. toaster.pop('error', '提示', response.data);
  15081. });
  15082. }
  15083. }]);
  15084. // 基础资料供应商
  15085. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  15086. BaseService.scrollBackToTop();
  15087. $scope.status = 'vendor';
  15088. // 搜索框回车
  15089. $scope.onSearch = function() {
  15090. $scope.customerParams.page(1);
  15091. $scope.customerParams.reload();
  15092. };
  15093. $scope.customerParams = new ngTableParams({
  15094. page : 1,
  15095. count : 20
  15096. }, {
  15097. total : 0,
  15098. counts: [],
  15099. getData : function($defer, params) {
  15100. $scope.loading = true;
  15101. var pageParams = params.url();
  15102. pageParams.keyword = $scope.keyword;
  15103. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  15104. $scope.loading = false;
  15105. if(page) {
  15106. params.total(page.totalElement);
  15107. $scope.total = page.totalElement;
  15108. $defer.resolve(page.content);
  15109. }
  15110. $scope.totalCount = page.totalElement;
  15111. }, function(response){
  15112. $scope.loading = false;
  15113. toaster.pop('error', '数据加载失败', response.data);
  15114. });
  15115. }
  15116. });
  15117. // 查看供应商详情
  15118. $scope.VendorDetail = function(id, uu) {
  15119. $rootScope.vendorId = id;
  15120. $rootScope.vendoruu = uu;
  15121. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  15122. }
  15123. // 向企业购买
  15124. $scope.purcByEn = function(businessCode) {
  15125. $rootScope.businessCode = businessCode;
  15126. window.location.hash = "#/purc/addOrder";
  15127. }
  15128. // 取消合作关系
  15129. $scope.relieve = function(id) {
  15130. VendorInfo.relieve({id: id}, {}, function(data) {
  15131. if(data.success) {
  15132. toaster.pop('success', '提示', data.success);
  15133. }
  15134. // $scope.customerParams.page(1);
  15135. $scope.customerParams.reload();
  15136. }, function(response) {
  15137. toaster.pop('error', '提示', response.data);
  15138. });
  15139. }
  15140. // 建立合作关系
  15141. $scope.activeVend = function(id) {
  15142. VendorInfo.activeVend({id: id}, {}, function(data) {
  15143. if(data.success) {
  15144. toaster.pop('success', '提示', data.success);
  15145. }
  15146. // $scope.customerParams.page(1);
  15147. $scope.customerParams.reload();
  15148. }, function(response) {
  15149. toaster.pop('error', '提示', response.data);
  15150. });
  15151. }
  15152. }]);
  15153. // 企业圈搜索界面
  15154. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  15155. $scope.onSearch = function(keyword) {
  15156. $rootScope.enterpriseKeyword = keyword;
  15157. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  15158. }
  15159. }]);
  15160. // 企业圈搜索结果
  15161. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  15162. $scope.status = 'add';
  15163. BaseService.scrollBackToTop();
  15164. $scope.active = 'all';
  15165. $scope.agreedText = '全部';
  15166. $scope.dateZoneText = '一个月内';
  15167. $scope.condition = {dateZone: 1};
  15168. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15169. $scope.changeAgreed = function(agreed) {
  15170. $scope.condition.agreed = agreed;
  15171. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15172. $scope.condition.$agreedOpen = false;
  15173. };
  15174. $scope.changeDateZone = function(zone) {
  15175. $scope.condition.dateZone = zone;
  15176. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15177. $scope.condition.$dateZoneOpen = false;
  15178. getDateCondition(zone, $scope.condition);
  15179. $scope.tableParams.reload();
  15180. };
  15181. $scope.setActive = function(state) {
  15182. if($scope.active != state) {
  15183. $scope.active = state;
  15184. if($scope.tableParams.page() == 1)
  15185. $scope.tableParams.reload();
  15186. else
  15187. $scope.tableParams.page(1);
  15188. }
  15189. };
  15190. var getService = function() {
  15191. return getAccountUserSpace;
  15192. };
  15193. $scope.tableParams = new ngTableParams({
  15194. page : 1,
  15195. count : 20,
  15196. sorting: {
  15197. }
  15198. }, {
  15199. total : 0,
  15200. counts: [],
  15201. getData : function($defer, params) {
  15202. $scope.loading = true;
  15203. var pageParams = params.url();
  15204. pageParams.keyword = $scope.keyword;
  15205. $scope.tip = $scope.keyword;
  15206. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  15207. $scope.loading = false;
  15208. if(page) {
  15209. params.total(page.totalElement);
  15210. $defer.resolve(page.content);
  15211. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15212. }
  15213. }, function(response) {
  15214. $scope.loading = false;
  15215. toaster.pop('error', '数据加载失败', response.data);
  15216. });
  15217. }
  15218. });
  15219. // 搜索框回车
  15220. $scope.onSearch = function(keyword) {
  15221. if(keyword === '') {
  15222. keyword = null;
  15223. $rootScope.searchKeyword = keyword;
  15224. $scope.keyword = keyword;
  15225. $scope.tableParams.page(1);
  15226. $scope.tableParams.reload();
  15227. } else {
  15228. $rootScope.searchKeyword = keyword;
  15229. $scope.keyword = keyword;
  15230. $scope.tableParams.page(1);
  15231. $scope.tableParams.reload();
  15232. }
  15233. };
  15234. // 添加合作关系
  15235. $scope.addPartner = function(name, businessCode) {
  15236. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  15237. if(data.success) {
  15238. toaster.pop("success", '添加成功', data.success);
  15239. $scope.tableParams.reload();
  15240. }
  15241. if(data.error) {
  15242. toaster.pop("error", '添加失败', data.error);
  15243. }
  15244. }, function(response) {
  15245. toaster.pop('error','失败',response.data);
  15246. });
  15247. }
  15248. /**
  15249. * 邀请注册商务平台
  15250. */
  15251. $scope.invite = function(name) {
  15252. var modalInstance = $modal.open({
  15253. animation: true,
  15254. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  15255. controller: 'InviteCtrl',
  15256. resolve: {
  15257. enname: function(){return name}
  15258. }
  15259. });
  15260. modalInstance.result.then(function(data) {
  15261. InvitationRecord.invite({formStore: data}, {}, function(data) {
  15262. if(data.success) {
  15263. toaster.pop('success', '提示', data.success);
  15264. $scope.tableParams.reload();
  15265. }
  15266. if(data.error) {
  15267. toaster.pop('error', '提示', data.error);
  15268. }
  15269. }, function(response) {
  15270. toaster.pop('error', '提示', response.data);
  15271. });
  15272. });
  15273. }
  15274. /**
  15275. * 立即查看
  15276. */
  15277. $scope.view = function(name) {
  15278. $rootScope.vendName = name;
  15279. window.location.hash = "#/baseInfo/newPartner";
  15280. }
  15281. }]);
  15282. // 平台新增的询价单(指定一个供应商)
  15283. 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) {
  15284. $scope.active = 'all';
  15285. // 供应商信息
  15286. var loadData = function() {
  15287. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function(data) {
  15288. $scope.vendor = data;
  15289. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  15290. $scope.vendorContacts = data;
  15291. });
  15292. // 物料信息
  15293. $scope.tableParams = new ngTableParams({
  15294. page : 1,
  15295. count : 20
  15296. }, {
  15297. total : 0,
  15298. counts: [5, 10, 25, 50],
  15299. getData : function($defer, params) {
  15300. $scope.loading = true;
  15301. var pageParams = params.url();
  15302. pageParams.keyword = $scope.keyword;
  15303. $scope.tip = $scope.keyword;
  15304. pageParams.custUU = $scope.vendor.uu;
  15305. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  15306. $scope.loading = false;
  15307. if(page) {
  15308. params.total(page.totalElement);
  15309. $scope.total = page.totalElement;
  15310. $defer.resolve(page.content);
  15311. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  15312. }
  15313. }, function(response){
  15314. $scope.loading = false;
  15315. toaster.pop('error', '数据加载失败', response.data);
  15316. });
  15317. }
  15318. });
  15319. });
  15320. };
  15321. loadData();
  15322. $rootScope.tenderVendor = null;// 清除掉已选择的
  15323. var getService = function() {
  15324. return GetProductInfo;
  15325. };
  15326. $scope.inquiry = {
  15327. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  15328. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  15329. priceType: '采购',
  15330. isOpen: 1,
  15331. invoice: 0,
  15332. ifTax: 1,
  15333. currency: 'RMB'
  15334. };
  15335. $scope.changeCurrency = function(inquiry) {
  15336. if (inquiry.currency !== 'RMB') {
  15337. $scope.notRMB = true;
  15338. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  15339. inquiry.invoice = 0;
  15340. } else {
  15341. $scope.notRMB = false;
  15342. }
  15343. };
  15344. // 获取收货地址列表
  15345. var loadShipAddress = function() {
  15346. ShipAddress.shipAddList({}, function(data) {
  15347. $scope.ships = data;
  15348. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  15349. });
  15350. };
  15351. loadShipAddress();
  15352. // 获取地址信息
  15353. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  15354. }).then(function(response) {
  15355. $scope.provinces = response.data;
  15356. });
  15357. // 新增收货地址保存
  15358. $scope.saveShipAddress = function(ship) {
  15359. ship.address = ship.province + ship.city + ship.district;
  15360. ShipAddress.saveAddress( {}, ship, function(data) {
  15361. if(data.success) {
  15362. // 获取收货地址列表
  15363. loadShipAddress();
  15364. toaster.pop('success', '提示', data.success);
  15365. }
  15366. if(data.error) {
  15367. toaster.pop('error', '提示', data.error);
  15368. }
  15369. });
  15370. };
  15371. $scope.currentDay = function() {
  15372. return $filter('date')(new Date(), 'yyyy-MM-dd');
  15373. };
  15374. // 搜索框回车
  15375. $scope.onSearch = function(keyword) {
  15376. $scope.tableParams.page(1);
  15377. $scope.tableParams.reload();
  15378. };
  15379. $scope.inquiry.inquiryItems = [];
  15380. var prod = {
  15381. prodCode: null,
  15382. prodTitle: null,
  15383. inbrand: null,
  15384. currency: 'RMB',
  15385. toDate: null,
  15386. unit: 'PCS'
  15387. };
  15388. $scope.inquiry.inquiryItems.push(prod);
  15389. // 联想词start
  15390. // 获取品牌联想词
  15391. $scope.getSimilarBrands = function(value) {
  15392. if (value) {
  15393. // 获取品牌联想词
  15394. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  15395. return data.map(function(item) {
  15396. return item;
  15397. });
  15398. });
  15399. }
  15400. };
  15401. // 获取产品型号联想词
  15402. $scope.getSimilarCodes = function(value) {
  15403. if (value) {
  15404. // 获取产品型号联想词
  15405. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  15406. return data.map(function (item) {
  15407. return item;
  15408. })
  15409. });
  15410. }
  15411. };
  15412. $scope.selectKind = function(prod) {
  15413. var submit = [];
  15414. $modal.open({
  15415. animation: true,
  15416. size: 'lg',
  15417. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  15418. controller: 'ProdKindChooseCtrl',
  15419. resolve: {
  15420. actives: function() {
  15421. return $scope.actives;
  15422. }
  15423. }
  15424. }).result.then(function(data){
  15425. $scope.actives = data.actives;
  15426. var size = data.actives.length;
  15427. submit.gradeOneKiName = '';
  15428. submit.gradeTwoKiName = '';
  15429. submit.gradeThreeKiName = '';
  15430. if (size > 0) {
  15431. submit.gradeOneKiName = $scope.actives[0].nameCn;
  15432. prod.prodTitle = submit.gradeOneKiName;
  15433. if (size > 1) {
  15434. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  15435. prod.prodTitle = submit.gradeTwoKiName;
  15436. if (size > 2) {
  15437. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  15438. prod.prodTitle = submit.gradeThreeKiName;
  15439. }
  15440. }
  15441. }
  15442. }, function(){
  15443. });
  15444. };
  15445. // 点击联想词获取品牌信息
  15446. $scope.onAssociateBrandClick = function(brand, prod) {
  15447. if (brand instanceof String) {
  15448. prod.inbrand = brand;
  15449. } else if (brand instanceof Object) {
  15450. prod.inbrand = brand.brandCn;
  15451. }
  15452. };
  15453. // 打开品牌选择的模态框
  15454. $scope.selectBrand = function(prod){ //打开模态
  15455. var modalInstance = $modal.open({
  15456. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  15457. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  15458. });
  15459. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  15460. });
  15461. modalInstance.result.then(function(brand){
  15462. prod.inbrand = brand.nameCn;
  15463. }, function(reason){
  15464. });
  15465. };
  15466. // 点击联想词获取器件信息 带入产品分类和品牌
  15467. $scope.onAssociateCmpClick = function(cmp, prod) {
  15468. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  15469. $scope.component = data;
  15470. prod.prodCode = data.code;
  15471. prod.prodTitle = data.kind.nameCn;
  15472. prod.inbrand = data.brand.nameCn;
  15473. }, function(res) {
  15474. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  15475. })
  15476. };
  15477. //联想词end
  15478. // 导入商品信息
  15479. $scope.uplodaByBatch = function() {
  15480. var modalInstance = $modal.open({
  15481. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15482. controller: 'PurcInquiryUploadCtrl',
  15483. size: 'lg',
  15484. resolve: {
  15485. }
  15486. });
  15487. modalInstance.result.then(function(data) {
  15488. angular.forEach(data, function(prod) {
  15489. console.log(prod);
  15490. $scope.inquiry.inquiryItems.push(prod);
  15491. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  15492. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  15493. $scope.inquiry.inquiryItems.splice(i, 1);
  15494. }
  15495. }
  15496. })
  15497. }, function(){
  15498. });
  15499. }
  15500. //增加商品
  15501. $scope.add = function() {
  15502. $scope.inquiry.inquiryItems.push(
  15503. { prodCode: null,
  15504. prodTitle: null,
  15505. unit: 'PCS',
  15506. ibrand: null,
  15507. currency: 'RMB',
  15508. toDate: null});
  15509. };
  15510. //删除商品
  15511. $scope.del = function(index) {
  15512. $scope.inquiry.inquiryItems.splice(index, 1);
  15513. };
  15514. // 搜索结果询价
  15515. if($rootScope.prodId) {
  15516. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  15517. prod.prodCode = data.code;
  15518. prod.prodTitle = data.title;
  15519. prod.spec = data.spec;
  15520. prod.unit = data.unit;
  15521. prod.productId = data.id;
  15522. prod.inbrand = data.brand;
  15523. $scope.inquiry.inquiryItems.push(prod);
  15524. $rootScope.prodId = null;// 清除掉prodId
  15525. }, function(response) {
  15526. });
  15527. }
  15528. $scope.check = function(product) {
  15529. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  15530. if($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  15531. $scope.inquiry.inquiryItems.splice(i, 1);
  15532. }
  15533. }
  15534. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  15535. currency: null, toDate: null, productId: product.id, inbrand: product.brand});
  15536. }
  15537. $scope.getMinDate = function(item) {
  15538. return $filter('date')(new Date, 'yyyy-MM-dd');
  15539. };
  15540. $scope.openDatePicker = function($event, openParam, index) {
  15541. $event.preventDefault();
  15542. $event.stopPropagation();
  15543. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  15544. };
  15545. $scope.openEndDatePicker = function($event, item, openParam) {
  15546. $event.preventDefault();
  15547. $event.stopPropagation();
  15548. item[openParam] = !item[openParam];
  15549. };
  15550. $scope.ifrepeat = false;
  15551. // 保存并提交
  15552. $scope.submit = function() {
  15553. for(var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  15554. $scope.item = $scope.inquiry.inquiryItems[i];
  15555. for(var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  15556. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  15557. if(i != j) {
  15558. if($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  15559. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  15560. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  15561. $scope.ifrepeat = true;
  15562. }
  15563. }
  15564. }
  15565. }
  15566. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  15567. $scope.vendors = [];
  15568. $scope.vendors.push({enName: $scope.vendor.enName, enuu: $scope.vendor.uu, currency: $scope.vendor.currency, rate: $scope.vendor.rate});
  15569. if(!$scope.ifrepeat) {
  15570. $upload.upload({
  15571. url: 'purc/inquiry/saveAndSubmit',
  15572. file: file,
  15573. method: 'POST',
  15574. data: {
  15575. inquiry: $scope.inquiry,
  15576. contacts: $scope.vendors
  15577. },
  15578. }).success(function(data) {
  15579. if(data.success) {
  15580. toaster.pop('success', '提示', data.success);
  15581. $timeout(function() {
  15582. window.location.hash = "#/purc/purchaseinquiry";
  15583. }, 500);
  15584. }
  15585. if(data.error) {
  15586. toaster.pop('error', '提示', data.error);
  15587. }
  15588. }).error(function(data) {
  15589. $scope.loadingShow = false;
  15590. toaster.pop('error', '操作失败', data.error);
  15591. });
  15592. } else {
  15593. toaster.pop('error', '提示', '存在条件相同的物料');
  15594. }
  15595. }
  15596. }]);
  15597. // 企业圈查询收到待处理的数目
  15598. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', function($scope, AddPartnerMyRequest) {
  15599. AddPartnerMyRequest.requestAmount({}, function(data) {
  15600. $scope.requestTodo = data;
  15601. });
  15602. }]);
  15603. // 当前企业所有的物料信息
  15604. app.controller('ProductAllCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', 'ProductAllNewest', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, ProductAllNewest) {
  15605. BaseService.scrollBackToTop();
  15606. $scope.active = 'all';
  15607. $scope.agreedText = '全部';
  15608. $scope.dateZoneText = '一个月内';
  15609. $scope.condition = {dateZone: 1};
  15610. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15611. $scope.changeAgreed = function(agreed) {
  15612. $scope.condition.agreed = agreed;
  15613. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15614. $scope.condition.$agreedOpen = false;
  15615. };
  15616. $scope.changeDateZone = function(zone) {
  15617. $scope.condition.dateZone = zone;
  15618. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15619. $scope.condition.$dateZoneOpen = false;
  15620. getDateCondition(zone, $scope.condition);
  15621. $scope.tableParams.reload();
  15622. };
  15623. $scope.setActive = function(state) {
  15624. if($scope.active != state) {
  15625. $scope.active = state;
  15626. if($scope.tableParams.page() == 1)
  15627. $scope.tableParams.reload();
  15628. else
  15629. $scope.tableParams.page(1);
  15630. }
  15631. };
  15632. $scope.searchMethod = false;
  15633. var getService = function() {
  15634. if($scope.searchMethod) {
  15635. return ProductAll;
  15636. } else {
  15637. return ProductAllNewest;
  15638. }
  15639. };
  15640. $scope.tableParams = new ngTableParams({
  15641. page : 1,
  15642. count : 20,
  15643. sorting: {
  15644. standard: 'desc',
  15645. id: 'desc',
  15646. }
  15647. }, {
  15648. total : 0,
  15649. counts: [5, 10, 25, 50],
  15650. getData : function($defer, params) {
  15651. $scope.loading = true;
  15652. var pageParams = params.url();
  15653. pageParams.keyword = $scope.keyword;
  15654. pageParams.searchFilter = $scope.searchFilter;
  15655. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  15656. $scope.loading = false;
  15657. if(page) {
  15658. params.total(page.totalElement);
  15659. $defer.resolve(page.content);
  15660. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15661. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15662. }
  15663. }, function(response) {
  15664. $scope.loading = false;
  15665. toaster.pop('error', '数据加载失败', response.data);
  15666. });
  15667. }
  15668. });
  15669. // 搜索框回车
  15670. $scope.onSearch = function() {
  15671. $scope.searchMethod = true;
  15672. $scope.tableParams.page(1);
  15673. $scope.tableParams.reload();
  15674. };
  15675. // 开启销售
  15676. $scope.unlock = function(id) {
  15677. Products.unlock({id: id}, {}, function(data) {
  15678. toaster.pop('success', '提示', '操作成功');
  15679. $scope.tableParams.reload();
  15680. }, function(response) {
  15681. toaster.pop('error', '提示', response.data);
  15682. })
  15683. }
  15684. // 关闭销售
  15685. $scope.lock = function(id) {
  15686. Products.lock({id: id}, {}, function(data) {
  15687. toaster.pop('success', '提示', '操作成功');
  15688. $scope.tableParams.reload();
  15689. }, function(response) {
  15690. toaster.pop('error', '提示', response.data);
  15691. })
  15692. }
  15693. // 开启购买
  15694. $scope.unlockPurc = function(id) {
  15695. Products.unlockPurc({id: id}, {}, function(data) {
  15696. toaster.pop('success', '提示', '操作成功');
  15697. $scope.tableParams.reload();
  15698. }, function(response) {
  15699. toaster.pop('error', '提示', response.data);
  15700. })
  15701. }
  15702. // 关闭购买
  15703. $scope.lockPurc = function(id) {
  15704. Products.lockPurc({id: id}, {}, function(data) {
  15705. toaster.pop('success', '提示', '操作成功');
  15706. $scope.tableParams.reload();
  15707. }, function(response) {
  15708. toaster.pop('error', '提示', response.data);
  15709. })
  15710. }
  15711. // 一键匹配
  15712. $scope.matchall = function() {
  15713. $scope.type = "all";
  15714. $scope.loading = true;
  15715. Products.matchbytype({type: $scope.type}, {}, function(data) {
  15716. if(data.error) {
  15717. $scope.loading = false;
  15718. toaster.pop('error', '提示', data.error);
  15719. } else {
  15720. toaster.pop('info', '提示', '匹配成功'+data.size+'个标准器件');
  15721. window.location.href = "#/approvalFlow/productmatches";
  15722. }
  15723. }, function(response) {
  15724. toaster.pop('error', '提示', response.data);
  15725. });
  15726. }
  15727. }]);
  15728. // 当前企业匹配的标准物料信息
  15729. app.controller('ProductmatchesCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  15730. BaseService.scrollBackToTop();
  15731. $scope.active = 'all';
  15732. $scope.agreedText = '全部';
  15733. $scope.dateZoneText = '一个月内';
  15734. $scope.condition = {dateZone: 1};
  15735. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15736. $scope.changeAgreed = function(agreed) {
  15737. $scope.condition.agreed = agreed;
  15738. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15739. $scope.condition.$agreedOpen = false;
  15740. };
  15741. $scope.changeDateZone = function(zone) {
  15742. $scope.condition.dateZone = zone;
  15743. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15744. $scope.condition.$dateZoneOpen = false;
  15745. getDateCondition(zone, $scope.condition);
  15746. $scope.tableParams.reload();
  15747. };
  15748. $scope.setActive = function(state) {
  15749. if($scope.active != state) {
  15750. $scope.active = state;
  15751. if($scope.tableParams.page() == 1)
  15752. $scope.tableParams.reload();
  15753. else
  15754. $scope.tableParams.page(1);
  15755. }
  15756. };
  15757. $scope.searchMethod = false;
  15758. var getService = function() {
  15759. if($rootScope.productMatchStatus === 'sale') {
  15760. if($scope.searchMethod) {
  15761. return Products.matchResultforSale;
  15762. } else {
  15763. return Products.newestMatchResultforSale;
  15764. }
  15765. } else if($rootScope.productMatchStatus === 'purc') {
  15766. if($scope.searchMethod) {
  15767. return Products.matchResultforPurc;
  15768. } else {
  15769. return Products.newestMatchResultforPurc;
  15770. }
  15771. } else {
  15772. if($scope.searchMethod) {
  15773. return Products.matchResult;
  15774. } else {
  15775. return Products.newestMatchResult;
  15776. }
  15777. }
  15778. };
  15779. $scope.tableParams = new ngTableParams({
  15780. page : 1,
  15781. count : 20,
  15782. sorting: {
  15783. matchsize: 'asc',
  15784. id: 'desc'
  15785. }
  15786. }, {
  15787. total : 0,
  15788. counts: [5, 10, 25, 50],
  15789. getData : function($defer, params) {
  15790. $scope.loading = true;
  15791. var pageParams = params.url();
  15792. pageParams.keyword = $scope.keyword;
  15793. pageParams.searchFilter = $scope.searchFilter;
  15794. getService().call(null, BaseService.parseParams(pageParams), function(page){
  15795. if(page) {
  15796. $scope.loading = false;
  15797. params.total(page.totalElement);
  15798. $defer.resolve(page.content);
  15799. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15800. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15801. angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
  15802. ids = [];
  15803. if(product.matchresults.length == 1) {
  15804. product.checked = $scope.checks.checked;
  15805. }
  15806. });
  15807. // $scope.total = page.totalElement;
  15808. // Products.matchsize({type: 'all'}, {}, function(data) {
  15809. // $scope.size = data.size;
  15810. // if($scope.total < $scope.size) {
  15811. // $timeout(function() {
  15812. // $scope.tableParams.reload();
  15813. // }, 500);
  15814. // } else {
  15815. // $scope.loading = false;
  15816. // }
  15817. // }, function(response) {
  15818. // toaster.pop('error', '提示', response.data);
  15819. // });
  15820. }
  15821. }, function(response) {
  15822. $scope.loading = false;
  15823. toaster.pop('error', '数据加载失败', response.data);
  15824. });
  15825. }
  15826. });
  15827. // 搜索框回车
  15828. $scope.onSearch = function() {
  15829. $scope.searchMethod = true;
  15830. $scope.tableParams.page(1);
  15831. $scope.tableParams.reload();
  15832. };
  15833. var ids = [];
  15834. $scope.checks = {
  15835. checked: false
  15836. };
  15837. // 全选框
  15838. $scope.checkAll = function() {
  15839. ids = [];// 每次选择时先清空,防止重复
  15840. angular.forEach($scope.tableParams.data, function(product) {
  15841. if(product.matchresults.length == 1) {
  15842. product.checked = $scope.checks.checked;
  15843. }
  15844. });
  15845. };
  15846. // 单选
  15847. $scope.checkOne = function(product) {
  15848. ids = [];// 每次选择时先清空,防止重复
  15849. product.checked = !product.checked;
  15850. var result = true;
  15851. angular.forEach($scope.tableParams.data, function(item) {
  15852. if(item.$selected != true){
  15853. result = false;
  15854. return;
  15855. }
  15856. });
  15857. $scope.checks.checked = result;
  15858. var checked = true;
  15859. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  15860. if (!message.checked) {
  15861. checked = false;
  15862. }
  15863. });
  15864. $scope.checks.checked = checked;
  15865. };
  15866. $scope.product = {
  15867. checked: false
  15868. };
  15869. var checkResults = function(result) {
  15870. angular.forEach($scope.tableParams.data, function(product) {
  15871. if (product.id == result.prid) {
  15872. product.checked = false;
  15873. angular.forEach(product.matchresults, function(item) {
  15874. if(result.id == item.id) {
  15875. if(item.checked) {
  15876. product.checked = true;
  15877. return;
  15878. }
  15879. } else {
  15880. item.checked = false;
  15881. }
  15882. });
  15883. }
  15884. });
  15885. // checkProductCheck();
  15886. };
  15887. var checkProductCheck = function () {
  15888. var checked = true;
  15889. angular.forEach($scope.tableParams.data, function(product) {
  15890. if(!product.checked) {
  15891. checked = false;
  15892. }
  15893. });
  15894. $scope.product.checked = checked;
  15895. }
  15896. // 单选明细
  15897. $scope.checkItem = function(result) {
  15898. ids = [];
  15899. result.checked = !result.checked;
  15900. checkResults(result);
  15901. }
  15902. // 一键更新
  15903. $scope.updateAll = function() {
  15904. $scope.loading = true;
  15905. angular.forEach($scope.tableParams.data, function(product) {
  15906. if(product.checked) {
  15907. if(product.matchresults.length == 1) {
  15908. ids.push(product.matchresults[0].id);
  15909. }
  15910. if (product.matchresults.length > 1) {
  15911. angular.forEach(product.matchresults, function(item) {
  15912. if(item.checked) {
  15913. ids.push(item.id);
  15914. }
  15915. });
  15916. }
  15917. }
  15918. });
  15919. Products.updateall( {status: $scope.checks.checked, type: 'all'}, ids, function(data) {
  15920. if(data.success) {
  15921. toaster.pop('success', '提示', data.success);
  15922. $timeout(function() {
  15923. $scope.tableParams.page(1);
  15924. $scope.tableParams.reload();
  15925. $scope.loading = false;
  15926. }, 500);
  15927. }
  15928. ids = []; // 清空ids,防止重复点击出现多余的数据
  15929. }, function(response) {
  15930. $scope.loading = false;
  15931. toaster.pop('error', '提示', response.data);
  15932. });
  15933. }
  15934. }]);
  15935. // 当前企业匹配的标准物料信息(销售)
  15936. app.controller('ProductmatchesForSaleCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  15937. BaseService.scrollBackToTop();
  15938. $scope.active = 'all';
  15939. $scope.agreedText = '全部';
  15940. $scope.dateZoneText = '一个月内';
  15941. $scope.condition = {dateZone: 1};
  15942. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15943. $scope.changeAgreed = function(agreed) {
  15944. $scope.condition.agreed = agreed;
  15945. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  15946. $scope.condition.$agreedOpen = false;
  15947. };
  15948. $scope.changeDateZone = function(zone) {
  15949. $scope.condition.dateZone = zone;
  15950. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  15951. $scope.condition.$dateZoneOpen = false;
  15952. getDateCondition(zone, $scope.condition);
  15953. $scope.tableParams.reload();
  15954. };
  15955. $scope.setActive = function(state) {
  15956. if($scope.active != state) {
  15957. $scope.active = state;
  15958. if($scope.tableParams.page() == 1)
  15959. $scope.tableParams.reload();
  15960. else
  15961. $scope.tableParams.page(1);
  15962. }
  15963. };
  15964. $scope.searchMethod = false;
  15965. var getService = function() {
  15966. if($scope.searchMethod) {
  15967. return Products.matchResultforSale;
  15968. } else {
  15969. return Products.newestMatchResultforSale;
  15970. }
  15971. };
  15972. $scope.tableParams = new ngTableParams({
  15973. page : 1,
  15974. count : 20,
  15975. sorting: {
  15976. matchsize: 'asc',
  15977. id: 'desc'
  15978. }
  15979. }, {
  15980. total : 0,
  15981. counts: [5, 10, 25, 50],
  15982. getData : function($defer, params) {
  15983. $scope.loading = true;
  15984. var pageParams = params.url();
  15985. pageParams.keyword = $scope.keyword;
  15986. pageParams.searchFilter = $scope.searchFilter;
  15987. getService().call(null, BaseService.parseParams(pageParams), function(page){
  15988. if(page) {
  15989. $scope.loading = false;
  15990. params.total(page.totalElement);
  15991. $defer.resolve(page.content);
  15992. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15993. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15994. angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
  15995. ids = [];
  15996. if(product.matchresults.length == 1) {
  15997. product.checked = $scope.checks.checked;
  15998. }
  15999. });
  16000. // $scope.total = page.totalElement;
  16001. // Products.matchsize({type: 'sale'}, {}, function(data) {
  16002. // $scope.size = data.size;
  16003. // if($scope.total < $scope.size) {
  16004. // $timeout(function() {
  16005. // $scope.tableParams.reload();
  16006. // }, 500);
  16007. // } else {
  16008. // $scope.loading = false;
  16009. // }
  16010. // }, function(response) {
  16011. // toaster.pop('error', '提示', response.data);
  16012. // });
  16013. }
  16014. }, function(response) {
  16015. $scope.loading = false;
  16016. toaster.pop('error', '数据加载失败', response.data);
  16017. });
  16018. }
  16019. });
  16020. // 搜索框回车
  16021. $scope.onSearch = function() {
  16022. $scope.searchMethod = true;
  16023. $scope.tableParams.page(1);
  16024. $scope.tableParams.reload();
  16025. };
  16026. var ids = [];
  16027. $scope.checks = {
  16028. checked: false
  16029. };
  16030. // 全选框
  16031. $scope.checkAll = function() {
  16032. ids = [];// 每次选择时先清空,防止重复
  16033. angular.forEach($scope.tableParams.data, function(product) {
  16034. if(product.matchresults.length == 1) {
  16035. product.checked = $scope.checks.checked;
  16036. }
  16037. });
  16038. };
  16039. // 单选
  16040. $scope.checkOne = function(product) {
  16041. ids = [];// 每次选择时先清空,防止重复
  16042. product.checked = !product.checked;
  16043. var result = true;
  16044. angular.forEach($scope.tableParams.data, function(item) {
  16045. if(item.$selected != true){
  16046. result = false;
  16047. return;
  16048. }
  16049. });
  16050. $scope.checks.checked = result;
  16051. var checked = true;
  16052. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  16053. if (!message.checked) {
  16054. checked = false;
  16055. }
  16056. });
  16057. $scope.checks.checked = checked;
  16058. };
  16059. $scope.product = {
  16060. checked: false
  16061. };
  16062. var checkResults = function(result) {
  16063. angular.forEach($scope.tableParams.data, function(product) {
  16064. if (product.id == result.prid) {
  16065. product.checked = false;
  16066. angular.forEach(product.matchresults, function(item) {
  16067. if(result.id == item.id) {
  16068. if(item.checked) {
  16069. product.checked = true;
  16070. return;
  16071. }
  16072. } else {
  16073. item.checked = false;
  16074. }
  16075. });
  16076. }
  16077. });
  16078. // checkProductCheck();
  16079. };
  16080. var checkProductCheck = function () {
  16081. var checked = true;
  16082. angular.forEach($scope.tableParams.data, function(product) {
  16083. if(!product.checked) {
  16084. checked = false;
  16085. }
  16086. });
  16087. $scope.product.checked = checked;
  16088. }
  16089. // 单选明细
  16090. $scope.checkItem = function(result) {
  16091. ids = [];
  16092. result.checked = !result.checked;
  16093. checkResults(result);
  16094. }
  16095. // 一键更新
  16096. $scope.updateAll = function() {
  16097. $scope.loading = true;
  16098. angular.forEach($scope.tableParams.data, function(product) {
  16099. if(product.checked) {
  16100. if(product.matchresults.length == 1) {
  16101. ids.push(product.matchresults[0].id);
  16102. }
  16103. if (product.matchresults.length > 1) {
  16104. angular.forEach(product.matchresults, function(item) {
  16105. if(item.checked) {
  16106. ids.push(item.id);
  16107. }
  16108. });
  16109. }
  16110. }
  16111. });
  16112. Products.updateall( {status: $scope.checks.checked, type: 'sale'}, ids, function(data) {
  16113. if(data.success) {
  16114. toaster.pop('success', '提示', data.success);
  16115. $timeout(function() {
  16116. $scope.tableParams.page(1);
  16117. $scope.tableParams.reload();
  16118. $scope.loading = false;
  16119. }, 500);
  16120. }
  16121. ids = []; // 清空ids,防止重复点击出现多余的数据
  16122. }, function(response) {
  16123. $scope.loading = true;
  16124. toaster.pop('error', '提示', response.data);
  16125. });
  16126. }
  16127. }]);
  16128. // 当前企业匹配的标准物料信息(采购)
  16129. app.controller('ProductmatchesForPurcCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  16130. BaseService.scrollBackToTop();
  16131. $scope.active = 'all';
  16132. $scope.agreedText = '全部';
  16133. $scope.dateZoneText = '一个月内';
  16134. $scope.condition = {dateZone: 1};
  16135. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  16136. $scope.changeAgreed = function(agreed) {
  16137. $scope.condition.agreed = agreed;
  16138. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  16139. $scope.condition.$agreedOpen = false;
  16140. };
  16141. $scope.changeDateZone = function(zone) {
  16142. $scope.condition.dateZone = zone;
  16143. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  16144. $scope.condition.$dateZoneOpen = false;
  16145. getDateCondition(zone, $scope.condition);
  16146. $scope.tableParams.reload();
  16147. };
  16148. $scope.setActive = function(state) {
  16149. if($scope.active != state) {
  16150. $scope.active = state;
  16151. if($scope.tableParams.page() == 1)
  16152. $scope.tableParams.reload();
  16153. else
  16154. $scope.tableParams.page(1);
  16155. }
  16156. };
  16157. $scope.searchMethod = false;
  16158. var getService = function() {
  16159. if($scope.searchMethod) {
  16160. return Products.matchResultforPurc;
  16161. } else {
  16162. return Products.newestMatchResultforPurc;
  16163. }
  16164. };
  16165. $scope.tableParams = new ngTableParams({
  16166. page : 1,
  16167. count : 20,
  16168. sorting: {
  16169. matchsize: 'asc',
  16170. id: 'desc'
  16171. }
  16172. }, {
  16173. total : 0,
  16174. counts: [5, 10, 25, 50],
  16175. getData : function($defer, params) {
  16176. $scope.loading = true;
  16177. var pageParams = params.url();
  16178. pageParams.keyword = $scope.keyword;
  16179. pageParams.searchFilter = $scope.searchFilter;
  16180. getService().call(null, BaseService.parseParams(pageParams), function(page){
  16181. if(page) {
  16182. $scope.loading = false;
  16183. params.total(page.totalElement);
  16184. $defer.resolve(page.content);
  16185. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  16186. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  16187. angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
  16188. ids = [];
  16189. if(product.matchresults.length == 1) {
  16190. product.checked = $scope.checks.checked;
  16191. }
  16192. });
  16193. $scope.total = page.totalElement;
  16194. // Products.matchsize({type: 'purc'}, {}, function(data) {
  16195. // $scope.size = data.size;
  16196. // if($scope.total < $scope.size) {
  16197. // $timeout(function() {
  16198. // $scope.tableParams.reload();
  16199. // }, 500);
  16200. // } else {
  16201. // $scope.loading = false;
  16202. // }
  16203. // }, function(response) {
  16204. // toaster.pop('error', '提示', response.data);
  16205. // });
  16206. }
  16207. }, function(response) {
  16208. $scope.loading = false;
  16209. toaster.pop('error', '数据加载失败', response.data);
  16210. });
  16211. }
  16212. });
  16213. // 搜索框回车
  16214. $scope.onSearch = function() {
  16215. $scope.searchMethod = true;
  16216. $scope.tableParams.page(1);
  16217. $scope.tableParams.reload();
  16218. };
  16219. var ids = [];
  16220. $scope.checks = {
  16221. checked: false
  16222. };
  16223. // 全选框
  16224. $scope.checkAll = function() {
  16225. ids = [];// 每次选择时先清空,防止重复
  16226. angular.forEach($scope.tableParams.data, function(product) {
  16227. if(product.matchresults.length == 1) {
  16228. product.checked = $scope.checks.checked;
  16229. }
  16230. });
  16231. };
  16232. // 单选
  16233. $scope.checkOne = function(product) {
  16234. ids = [];// 每次选择时先清空,防止重复
  16235. product.checked = !product.checked;
  16236. var result = true;
  16237. angular.forEach($scope.tableParams.data, function(item) {
  16238. if(item.$selected != true){
  16239. result = false;
  16240. return;
  16241. }
  16242. });
  16243. $scope.checks.checked = result;
  16244. var checked = true;
  16245. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  16246. if (!message.checked) {
  16247. checked = false;
  16248. }
  16249. });
  16250. $scope.checks.checked = checked;
  16251. };
  16252. $scope.product = {
  16253. checked: false
  16254. };
  16255. var checkResults = function(result) {
  16256. angular.forEach($scope.tableParams.data, function(product) {
  16257. if (product.id == result.prid) {
  16258. product.checked = false;
  16259. angular.forEach(product.matchresults, function(item) {
  16260. if(result.id == item.id) {
  16261. if(item.checked) {
  16262. product.checked = true;
  16263. return;
  16264. }
  16265. } else {
  16266. item.checked = false;
  16267. }
  16268. });
  16269. }
  16270. });
  16271. // checkProductCheck();
  16272. };
  16273. var checkProductCheck = function () {
  16274. var checked = true;
  16275. angular.forEach($scope.tableParams.data, function(product) {
  16276. if(!product.checked) {
  16277. checked = false;
  16278. }
  16279. });
  16280. $scope.product.checked = checked;
  16281. }
  16282. // 单选明细
  16283. $scope.checkItem = function(result) {
  16284. ids = [];
  16285. result.checked = !result.checked;
  16286. checkResults(result);
  16287. }
  16288. // 一键更新
  16289. $scope.updateAll = function() {
  16290. $scope.loading = true;
  16291. angular.forEach($scope.tableParams.data, function(product) {
  16292. if(product.checked) {
  16293. if(product.matchresults.length == 1) {
  16294. ids.push(product.matchresults[0].id);
  16295. }
  16296. if (product.matchresults.length > 1) {
  16297. angular.forEach(product.matchresults, function(item) {
  16298. if(item.checked) {
  16299. ids.push(item.id);
  16300. }
  16301. });
  16302. }
  16303. }
  16304. });
  16305. Products.updateall( {status: $scope.checks.checked, type: 'purc'}, ids, function(data) {
  16306. if(data.success) {
  16307. toaster.pop('success', '提示', data.success);
  16308. $timeout(function() {
  16309. $scope.tableParams.page(1);
  16310. $scope.tableParams.reload();
  16311. $scope.loading = false;
  16312. }, 500);
  16313. }
  16314. ids = []; // 清空ids,防止重复点击出现多余的数据
  16315. }, function(response) {
  16316. $scope.loading = false;
  16317. toaster.pop('error', '提示', response.data);
  16318. });
  16319. }
  16320. }]);
  16321. /**
  16322. * 采购物料资料
  16323. */
  16324. app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$modal', 'GetProductInfo', '$rootScope', 'PurcProductNewest', function($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $modal, GetProductInfo, $rootScope, PurcProductNewest) {
  16325. BaseService.scrollBackToTop();
  16326. $scope.active = 'all';
  16327. $scope.agreedText = '全部';
  16328. $scope.dateZoneText = '一个月内';
  16329. $scope.condition = {dateZone: 1};
  16330. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  16331. $scope.changeAgreed = function(agreed) {
  16332. $scope.condition.agreed = agreed;
  16333. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  16334. $scope.condition.$agreedOpen = false;
  16335. };
  16336. $scope.changeDateZone = function(zone) {
  16337. $scope.condition.dateZone = zone;
  16338. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  16339. $scope.condition.$dateZoneOpen = false;
  16340. getDateCondition(zone, $scope.condition);
  16341. $scope.tableParams.reload();
  16342. };
  16343. $scope.setActive = function(state) {
  16344. if($scope.active != state) {
  16345. $scope.active = state;
  16346. if($scope.tableParams.page() == 1)
  16347. $scope.tableParams.reload();
  16348. else
  16349. $scope.tableParams.page(1);
  16350. }
  16351. };
  16352. $scope.searchMethod = false;
  16353. var getService = function() {
  16354. if($scope.searchMethod) {
  16355. return PurcProduct;
  16356. } else {
  16357. return PurcProductNewest;
  16358. }
  16359. };
  16360. $scope.tableParams = new ngTableParams({
  16361. page : 1,
  16362. count : 20,
  16363. sorting: {
  16364. }
  16365. }, {
  16366. total : 0,
  16367. counts: [5, 10, 25, 50],
  16368. getData : function($defer, params) {
  16369. $scope.loading = true;
  16370. var pageParams = params.url();
  16371. pageParams.keyword = $scope.keyword;
  16372. pageParams.searchFilter = $scope.searchFilter;
  16373. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  16374. $scope.loading = false;
  16375. if(page) {
  16376. params.total(page.totalElement);
  16377. $defer.resolve(page.content);
  16378. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  16379. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  16380. }
  16381. }, function(response) {
  16382. $scope.loading = false;
  16383. toaster.pop('error', '数据加载失败', response.data);
  16384. });
  16385. }
  16386. });
  16387. // 搜索框回车
  16388. $scope.onSearch = function() {
  16389. $scope.searchMethod = true;
  16390. $scope.tableParams.page(1);
  16391. $scope.tableParams.reload();
  16392. };
  16393. //删除
  16394. $scope.deleteById = function(id) {
  16395. GetProductInfo.deleteById({id: id}, function(data) {
  16396. if(data.error) {
  16397. toaster.pop("error", "提示", data.error);
  16398. } else {
  16399. toaster.pop("success", "提示", "删除成功");
  16400. $timeout(function() {
  16401. $scope.tableParams.reload();
  16402. }, 500);
  16403. }
  16404. }), function(response) {
  16405. toaster.pop("error", "删除失败", response.data);
  16406. };
  16407. }
  16408. // 一键开启关闭
  16409. $scope.toggle = function(status) {
  16410. $scope.loading = true;
  16411. Products.toggle({status: status}, {}, function(data) {
  16412. $scope.loading = false;
  16413. toaster.pop('success', '提示', '操作成功');
  16414. $scope.tableParams.reload();
  16415. }, function(response) {
  16416. $scope.loading = false;
  16417. toaster.pop('error', '提示', response.data);
  16418. })
  16419. }
  16420. var products = [];
  16421. $scope.checks = {
  16422. checked: false
  16423. };
  16424. // 全选框
  16425. $scope.checkAll = function() {
  16426. products = [];// 每次选择时先清空,防止重复
  16427. angular.forEach($scope.tableParams.data, function(product) {
  16428. if(product.cmpUuId == null) {
  16429. product.checked = $scope.checks.checked;
  16430. }
  16431. });
  16432. };
  16433. // 单选
  16434. $scope.checkOne = function(product) {
  16435. products = [];// 每次选择时先清空,防止重复
  16436. var result = true;
  16437. angular.forEach($scope.tableParams.data, function(item) {
  16438. if(item.$selected != true){
  16439. result = false;
  16440. return;
  16441. }
  16442. });
  16443. $scope.checks.checked = result;
  16444. var checked = true;
  16445. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  16446. if (!message.checked) {
  16447. checked = false;
  16448. }
  16449. });
  16450. $scope.checks.checked = checked;
  16451. };
  16452. $scope.updateByBatch = function(updatetype) {
  16453. var modalInstance = $modal.open({
  16454. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  16455. controller: 'UpdateByBatchCtrl',
  16456. size: 'md',
  16457. resolve: {
  16458. updatetype: function() {
  16459. return updatetype;
  16460. },
  16461. active: function() {
  16462. return $scope.active;
  16463. },
  16464. type: function() {
  16465. return 'purchase';
  16466. }
  16467. }
  16468. });
  16469. modalInstance.result.then(function(data) {
  16470. toaster.pop('success', '提示', data.success);
  16471. $scope.tableParams.reload();
  16472. }, function(){
  16473. });
  16474. }
  16475. // 一键匹配
  16476. $scope.matchall = function() {
  16477. $scope.type = "purc";
  16478. $scope.loading = true;
  16479. Products.matchbytype({type: $scope.type}, {}, function(data) {
  16480. if(data.error) {
  16481. $scope.loading = false;
  16482. toaster.pop('error', '提示', data.error);
  16483. } else {
  16484. toaster.pop('info', '提示', '匹配成功'+data.size+'个标准器件');
  16485. window.location.href = "#/purc/productmatches";
  16486. }
  16487. }, function(response) {
  16488. toaster.pop('error', '提示', response.data);
  16489. });
  16490. }
  16491. }]);
  16492. /**
  16493. * 采购物料批量上传
  16494. */
  16495. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  16496. BaseService.scrollBackToTop();
  16497. $scope.$watch('myFiles', function(){
  16498. if($scope.myFiles) {
  16499. var file = $scope.myFiles[0];
  16500. $scope.fileName = file.name;
  16501. }
  16502. })
  16503. // 通过excel批量上传物料
  16504. $scope.upload = function() {
  16505. $scope.loading = true;
  16506. if($scope.myFiles) {
  16507. var file = $scope.myFiles[0];
  16508. if(file.name) {
  16509. $scope.loading = true;
  16510. $upload.upload({
  16511. url: 'purcProduct/release/excel',
  16512. file: file,
  16513. method: 'POST'
  16514. }).success(function(data) {
  16515. $scope.loading = false;
  16516. if(data.error) {
  16517. toaster.pop('error', '提示', data.error);
  16518. }
  16519. $scope.result = data;
  16520. $scope.products = $scope.result.products;
  16521. $scope.success = $scope.result.success;
  16522. $scope.total = $scope.result.total;
  16523. $scope.alters = $scope.result.alters;
  16524. $scope.infos = $scope.result.infos;
  16525. $scope.myFiles[0] = "";
  16526. $scope.fileName = "";
  16527. }).error(function(response) {
  16528. $scope.loading = false;
  16529. toaster.pop('error', response.data || response);
  16530. });
  16531. } else {
  16532. $scope.loading = false;
  16533. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  16534. }
  16535. } else {
  16536. $scope.loading = false;
  16537. }
  16538. };
  16539. // 查看范例
  16540. $scope.showImg = function() {
  16541. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  16542. box.show();
  16543. box.find('img').attr('src', src);
  16544. box.find('a').click(function(){
  16545. box.hide();
  16546. });
  16547. box.dblclick(function(){
  16548. box.hide();
  16549. });
  16550. };
  16551. // 下载模板
  16552. $scope.download = function() {
  16553. window.location.href = 'product/baseInfo/upload/template';
  16554. };
  16555. }]);
  16556. /**
  16557. * 新增物料(采购)
  16558. */
  16559. app.controller('PurcNewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', 'Products', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService, Products) {
  16560. BaseService.scrollBackToTop();
  16561. // 录入人
  16562. AuthenticationService.getAuthentication().success(function(data) {
  16563. $scope.loading = false;
  16564. $scope.user = data;
  16565. });
  16566. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16567. $scope.prodInfo = {};
  16568. // 选择类目
  16569. $scope.selectKind = function() {
  16570. $modal.open({
  16571. animation: true,
  16572. size: 'lg',
  16573. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  16574. controller: 'KindChooseCtrl',
  16575. }).result.then(function(data){
  16576. $scope.kindId = data;
  16577. var modalInstance = $modal.open({
  16578. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  16579. controller: 'FindComponentCtrl',
  16580. size: 'lg',
  16581. resolve: {
  16582. KindId: function() {
  16583. return $scope.kindId;
  16584. }
  16585. }
  16586. });
  16587. modalInstance.result.then(function(data) {
  16588. $scope.prodInfo.cmpUuId = data.uuid;
  16589. $scope.prodInfo.pcmpcode = data.code;
  16590. $scope.prodInfo.pbranden = data.brand.nameEn;
  16591. $scope.prodInfo.pbrand = data.brand.nameCn;
  16592. }, function(){
  16593. });
  16594. }, function(){
  16595. });
  16596. };
  16597. // 联想词 start
  16598. // 获取类目
  16599. $scope.getSimilarKinds = function(value) {
  16600. if (value) {
  16601. return Products.getSimilarKind({keyword : value}).$promise.then(function(data) {
  16602. return data.map(function(item) {
  16603. return item;
  16604. });
  16605. });
  16606. }
  16607. };
  16608. $scope.onAssociateKindClick = function(kind, prodInfo) {
  16609. $scope.prodInfo.title = kind.kindCn;
  16610. }
  16611. $scope.getSimilarBrands = function(value) {
  16612. if(value) {
  16613. return Products.getSimilarBrand({keyword: value}).$promise.then(function(data) {
  16614. return data.map(function(item) {
  16615. return item;
  16616. });
  16617. });
  16618. }
  16619. }
  16620. $scope.onAssociateBrandClick = function(brand, prodInfo) {
  16621. $scope.prodInfo.brand = brand.brandEn;
  16622. }
  16623. $scope.getSimilarComponents = function(value) {
  16624. if(value) {
  16625. return Products.getSimilarComponent({keyword: value}).$promise.then(function(data) {
  16626. return data.map(function(item) {
  16627. return item;
  16628. });
  16629. });
  16630. }
  16631. }
  16632. $scope.onAssociateComponentClick = function(cmp, prodInfo) {
  16633. $scope.prodInfo.cmpCode = cmp.code;
  16634. }
  16635. // 联想词 end
  16636. // 删除
  16637. $scope.clearfile = function() {
  16638. $scope.myFiles = null;
  16639. $scope.previewShow = false;
  16640. }
  16641. //提交
  16642. $scope.submit = function(prodInfo){
  16643. $scope.prodInfo.isPurchase = 1;
  16644. console.log(prodInfo);
  16645. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  16646. $upload.upload({
  16647. url: 'product/baseInfo/addNewProduct',
  16648. file: file,
  16649. method: 'POST',
  16650. data: {
  16651. prodInfo: prodInfo
  16652. },
  16653. }).success(function(data) {
  16654. if(data.success) {
  16655. toaster.pop('success', '提示', data.success);
  16656. $timeout(function() {
  16657. //提交后跳转到详情页面,防止重复提交
  16658. // window.location.href="#/sale/prodList/"+data.id;
  16659. window.location.href="#/sale/prodList";
  16660. }, 500);
  16661. }
  16662. if(data.error) {
  16663. toaster.pop('error', '提示', data.error);
  16664. $timeout(function() {
  16665. //提交后跳转到详情页面,防止重复提交
  16666. // window.location.href="#/sale/prodList/"+data.id;
  16667. window.location.href="#/sale/prodList";
  16668. }, 500);
  16669. }
  16670. }).error(function(data) {
  16671. $scope.loadingShow = false;
  16672. toaster.pop('error', '操作失败', data.error);
  16673. });
  16674. };
  16675. $scope.previewShow = false;
  16676. $scope.pdfShow = false;
  16677. $scope.noneFileShow = true;
  16678. $scope.$watch('myFiles', function(){
  16679. if($scope.myFiles) {
  16680. $scope.noneFileShow = false;
  16681. var file = $scope.myFiles[0];
  16682. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  16683. $scope.pdfShow = true;
  16684. $scope.previewShow = false;
  16685. $scope.imgPreviewName = file.name;
  16686. } else{
  16687. if (typeof(Worker) !== "undefined") {//支持HTML5
  16688. $scope.imgPreview = getObjectURL(file);
  16689. $scope.imgPreviewName = file.name;
  16690. } else{//不支持HTML5
  16691. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  16692. $scope.imgPreviewName = file.name;
  16693. }
  16694. $scope.previewShow = true;
  16695. $scope.pdfShow = false;
  16696. }
  16697. } else {
  16698. $scope.noneFileShow = true;
  16699. $scope.previewShow = false;
  16700. $scope.pdfShow = false;
  16701. }
  16702. });
  16703. //建立一个可存取到该file的url
  16704. var getObjectURL = function(file) {
  16705. var url = null ;
  16706. if (window.createObjectURL!=undefined) { // basic
  16707. url = window.createObjectURL(file) ;
  16708. } else if (window.URL!=undefined) { // mozilla(firefox)
  16709. url = window.URL.createObjectURL(file) ;
  16710. } else if (window.webkitURL!=undefined) { // webkit or chrome
  16711. url = window.webkitURL.createObjectURL(file) ;
  16712. }
  16713. return url ;
  16714. };
  16715. // 取消
  16716. $scope.cancel = function(){
  16717. $scope.prodInfo = angular.copy($scope.prodInfo);
  16718. };
  16719. }]);
  16720. /**
  16721. * 物料详情(采购)
  16722. */
  16723. app.controller('PurcProdDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$modal', 'Products', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $modal, Products) {
  16724. BaseService.scrollBackToTop();
  16725. // 录入人
  16726. AuthenticationService.getAuthentication().success(function(data) {
  16727. $scope.loading = false;
  16728. $scope.user = data;
  16729. });
  16730. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16731. var loadData = function() {
  16732. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  16733. if(data.attach) {
  16734. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  16735. // 查看范例
  16736. $scope.showImg = function() {
  16737. var src = data.url, box = $('#image-box');
  16738. box.show();
  16739. box.find('img').attr('src', src);
  16740. box.find('a').click(function(){
  16741. box.hide();
  16742. });
  16743. box.dblclick(function(){
  16744. box.hide();
  16745. });
  16746. };
  16747. })
  16748. }
  16749. $scope.prodInfo = data;
  16750. if($scope.prodInfo.standard != 1 ) {// 非标准的先进行匹配
  16751. Products.matchone({id: $scope.prodInfo.id}, {}, function(data) {
  16752. $scope.matchresults = data;
  16753. }, function(response) {
  16754. toaster.pop('error', '提示', response.data);
  16755. });
  16756. }
  16757. $scope.prodInfo.$editing = false;
  16758. $scope.loading = false;
  16759. });
  16760. };
  16761. loadData();
  16762. //更新为标准器件
  16763. $scope.updateone = function(id) {
  16764. Products.updateone({id: id}, {}, function(data) {
  16765. if(data.success) {
  16766. toaster.pop('success', '提示', data.success);
  16767. }
  16768. }, function(response) {
  16769. toaster.pop('error', '提示', response.data);
  16770. });
  16771. }
  16772. // 选择类目
  16773. $scope.selectKind = function(cmpcode) {
  16774. if(cmpcode == null) {
  16775. $modal.open({
  16776. animation: true,
  16777. size: 'lg',
  16778. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  16779. controller: 'KindChooseCtrl',
  16780. }).result.then(function(data){
  16781. $scope.kindId = data;
  16782. var modalInstance = $modal.open({
  16783. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  16784. controller: 'FindComponentCtrl',
  16785. size: 'lg',
  16786. resolve: {
  16787. KindId: function() {
  16788. return $scope.kindId;
  16789. }
  16790. }
  16791. });
  16792. modalInstance.result.then(function(data) {
  16793. $scope.prodInfo.cmpUuId = data.uuid;
  16794. $scope.prodInfo.pcmpcode = data.code;
  16795. $scope.prodInfo.pbranden = data.brand.nameEn;
  16796. $scope.prodInfo.pbrand = data.brand.nameCn;
  16797. }, function(){
  16798. });
  16799. }, function(){
  16800. });
  16801. }
  16802. };
  16803. $scope.isShow = true;
  16804. // 更新
  16805. $scope.update = function() {
  16806. $scope.prodInfo.$editing = true;
  16807. $scope.isShow = true;
  16808. };
  16809. // 取消
  16810. $scope.cancel = function() {
  16811. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  16812. $scope.prodInfo = data;
  16813. $scope.prodInfo.$editing = false;
  16814. $scope.isShow = false;
  16815. $scope.loading = false;
  16816. });
  16817. };
  16818. // 删除
  16819. $scope.clearfile = function() {
  16820. $scope.myFiles = null;
  16821. $scope.previewShow = false;
  16822. }
  16823. //删除
  16824. $scope.deleteById = function(id) {
  16825. GetProductInfo.deleteById({id: id}, function(data) {
  16826. if(data.error) {
  16827. toaster.pop("error", "提示", data.error);
  16828. } else {
  16829. toaster.pop("success", "提示", "删除成功");
  16830. window.location.href = "#/purc/prodList";
  16831. }
  16832. }), function(response) {
  16833. toaster.pop("error", "删除失败", response.data);
  16834. };
  16835. }
  16836. $scope.submit = function(prodInfo) {
  16837. $scope.prodInfo.isPurchase = 1;
  16838. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  16839. $upload.upload({
  16840. url: 'product/baseInfo/updateProdInfo',
  16841. file: file,
  16842. method: 'POST',
  16843. data: {
  16844. prodInfo: $scope.prodInfo
  16845. },
  16846. }).success(function(data) {
  16847. if(data.success) {
  16848. toaster.pop('success', '提示', data.success);
  16849. // loadData();
  16850. window.location.href="#/sale/prodList";
  16851. }
  16852. if(data.error) {
  16853. toaster.pop('error', '提示', data.error);
  16854. }
  16855. }).error(function(data) {
  16856. $scope.loadingShow = false;
  16857. toaster.pop('error', '操作失败', data.error);
  16858. });
  16859. }
  16860. $scope.previewShow = false;
  16861. $scope.pdfShow = false;
  16862. $scope.noneFileShow = true;
  16863. $scope.$watch('myFiles', function(){
  16864. if($scope.myFiles) {
  16865. $scope.noneFileShow = false;
  16866. var file = $scope.myFiles[0];
  16867. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  16868. $scope.pdfShow = true;
  16869. $scope.previewShow = false;
  16870. $scope.imgPreviewName = file.name;
  16871. } else{
  16872. if (typeof(Worker) !== "undefined") {//支持HTML5
  16873. $scope.imgPreview = getObjectURL(file);
  16874. $scope.imgPreviewName = file.name;
  16875. } else{//不支持HTML5
  16876. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  16877. $scope.imgPreviewName = file.name;
  16878. }
  16879. $scope.previewShow = true;
  16880. $scope.pdfShow = false;
  16881. }
  16882. } else {
  16883. $scope.noneFileShow = true;
  16884. $scope.previewShow = false;
  16885. $scope.pdfShow = false;
  16886. }
  16887. });
  16888. //建立一个可存取到该file的url
  16889. var getObjectURL = function(file) {
  16890. var url = null ;
  16891. if (window.createObjectURL!=undefined) { // basic
  16892. url = window.createObjectURL(file) ;
  16893. } else if (window.URL!=undefined) { // mozilla(firefox)
  16894. url = window.URL.createObjectURL(file) ;
  16895. } else if (window.webkitURL!=undefined) { // webkit or chrome
  16896. url = window.webkitURL.createObjectURL(file) ;
  16897. }
  16898. return url ;
  16899. };
  16900. }]);
  16901. return app;
  16902. });