app.js 448 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412
  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'], 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']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config([ '$httpProvider', function($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function(response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url : "/index",
  26. views : {
  27. "left-view" : {
  28. templateUrl : "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view" : {
  32. templateUrl : "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url : "/",
  38. views : {
  39. "left-view" : {
  40. templateUrl : "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view" : {
  44. templateUrl : "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url : "/sale",
  50. views : {
  51. "left-view" : {
  52. templateUrl : "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view" : {
  56. templateUrl : "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url : "",
  65. templateUrl : "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url : "/",
  68. templateUrl : "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url : "/purc",
  71. views : {
  72. "left-view" : {
  73. templateUrl : "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view" : {
  77. templateUrl : "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url : "",
  86. templateUrl : "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url : "/",
  89. templateUrl : "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url : "/introduce",
  92. templateUrl : "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url : "/order",
  95. templateUrl : "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url : "/order/:id",
  99. templateUrl : "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url : "/addOrder",
  103. templateUrl : "static/tpl/index/purc/addOrder.html",
  104. controller : 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url : "/cart",
  107. templateUrl : "static/tpl/index/purc/cart.html",
  108. controller : 'CartController'
  109. }).state('purc.cartDetail', {
  110. url : "/cart/:id",
  111. templateUrl : "static/tpl/index/purc/cart_detail.html",
  112. controller : 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url : "/deputy",
  115. templateUrl : "static/tpl/index/purc/deputyOrder.html",
  116. controller : 'DeputyOrderCtrl'
  117. }).state('purc.newdeputy', {
  118. url : "/deputy/add",
  119. templateUrl : "static/tpl/index/purc/deputyOrder_new.html",
  120. controller : 'NewDeputyOrderCtrl'
  121. }).state('purc.deputydetail', {
  122. url : "/deputy/:id",
  123. templateUrl : "static/tpl/index/purc/deputyOrder_detail.html",
  124. controller : 'DeputyOrderDetailCtrl'
  125. /* 招标列表 */
  126. }).state('purc.tenderlist', {
  127. url : "/tender",
  128. templateUrl : "static/tpl/index/purc/tenderlist.html",
  129. controller : 'PurcTenderCtrl'
  130. }).state('purc.waiting.tenderlist', {
  131. url : "/tender",
  132. templateUrl : "static/tpl/index/purc/tenderlist.html",
  133. controller : 'PurcTenderCtrl'
  134. }).state('purc.todo.tenderlist', {
  135. url : "/tender/todo",
  136. templateUrl : "static/tpl/index/purc/tenderlist.html",
  137. controller : 'PurcTenderCtrl'
  138. /* 招标 */
  139. }).state('purc.tender', {
  140. url : "/addTender",
  141. templateUrl : "static/tpl/index/purc/tender.html",
  142. controller : 'PurcNewTenderCtrl'
  143. }).state('purc.savedtender', {
  144. url : "/tender/:id",
  145. templateUrl : "static/tpl/index/purc/saved_tender.html",
  146. controller : 'PurcNewTenderCtrl'
  147. /* 评标 */
  148. }).state('purc.evaluation', {
  149. url : "/evaluation/:id",
  150. templateUrl : "static/tpl/index/purc/tender_evaluation.html",
  151. controller : 'PurcEvaluationCtrl'
  152. /* 采购供应商资料 */
  153. }).state('purc.vendor', {
  154. url : "/vendor",
  155. templateUrl : "static/tpl/index/purc/vendor.html",
  156. controller : 'PurcVendorCtrl'
  157. /* 采购供应商资料 详情*/
  158. }).state('purc.vendordetail', {
  159. url : "/vendor/:id",
  160. templateUrl : "static/tpl/index/purc/vendor_detail.html",
  161. controller : 'PurcVendorDetailCtrl'
  162. /* 客户指定招标列表 */
  163. }).state('purc.makeoutorder', {
  164. url : "/makeoutorder",
  165. templateUrl : "static/tpl/index/make/outorder.html",
  166. controller: 'MakeOutOrderCtrl'
  167. }).state('purc.outorder_detail', {
  168. url : "/makeoutorder/:id",
  169. templateUrl : "static/tpl/index/make/outorder_detail.html",
  170. controller: 'MakeOutOrderDetailCtrl'
  171. /*平台新增询价单*/
  172. }).state('purc.inquiry_new', {
  173. url : "/purcinquiry",
  174. templateUrl : "static/tpl/index/purc/inquiry_new.html",
  175. controller: 'PurcInquiryCtrl'
  176. }).state('purc.purcinquiry_new', {
  177. url : "/purcinquiry/:bussinessCode",
  178. templateUrl : "static/tpl/index/purc/purcinquiry_new.html",
  179. controller: 'PurcInquiryNewCtrl'
  180. }).state('purc.inquiry', {
  181. url : "/purchaseinquiry",
  182. templateUrl : "static/tpl/index/purc/inquiry.html",
  183. controller: 'PurchaseInquiryCtrl'
  184. }).state('purc.inquiry_detail', {
  185. url : "/purcinquirydetail",
  186. templateUrl : "static/tpl/index/purc/inquiry_detail.html",
  187. controller: 'PurcInquiryDetailCtrl'
  188. }).state('purc.inquiryInfo_detail', {
  189. url : "/purcinquirydetail/:id",
  190. templateUrl : "static/tpl/index/purc/inquiryInfo_detail.html",
  191. controller: 'PurcInquiryInfoDetailCtrl'
  192. }).state('purc.inquiry_unapply', {
  193. url : "/inquiry_unapply",
  194. templateUrl : "static/tpl/index/purc/inquiry_unapply.html",
  195. controller: 'UnapplyInquiryCtrl'
  196. }).state('sale.tenderlist', {
  197. url : "/tender",
  198. templateUrl : "static/tpl/index/sale/tenderlist.html",
  199. controller : 'SaleTenderCtrl'
  200. }).state('sale.todo.tenderlist', {
  201. url : "/tender",
  202. templateUrl : "static/tpl/index/sale/tenderlist.html",
  203. controller : 'SaleTenderCtrl'
  204. /* 平台公开招标列表 */
  205. }).state('baseInfo.openTenderList', {
  206. url : "/openTenderList",
  207. templateUrl : "static/tpl/index/sale/open_tender_list.html",
  208. controller: 'SaleOpenTenderCtrl'
  209. /* 查看公开招标详情 */
  210. }).state('baseInfo.open_tender_detail', {
  211. url : "/openTenderDetail/:id",
  212. templateUrl : "static/tpl/index/sale/open_tender_detail.html",
  213. controller : 'OpenSaleTenderDetailCtrl'
  214. /* 投标 */
  215. }).state('sale.tender', {
  216. url : "/tender/:id",
  217. templateUrl : "static/tpl/index/sale/tender.html",
  218. controller : 'SaleTenderDetailCtrl'
  219. /* 采购方查看供应商投标 */
  220. }).state('sale.vendortender', {
  221. url : "/tender/:vendUU/:id",
  222. templateUrl : "static/tpl/index/sale/vendor_tender.html",
  223. controller : 'SaleVendorTenderDetailCtrl'
  224. }).state('sale.todo', {
  225. url : "/todo",
  226. templateUrl : "static/tpl/index/sale/todo.html"
  227. }).state('sale.todo.inquiry', {
  228. url : "/inquiry",
  229. templateUrl : "static/tpl/index/sale/inquiry.html",
  230. controller: 'SaleInquiryCtrl'
  231. }).state('sale.todo.order', {
  232. url : "/order",
  233. templateUrl : "static/tpl/index/sale/order.html",
  234. controller: 'SaleOrderCtrl'
  235. }).state('sale.todo.change', {
  236. url : "/change",
  237. templateUrl : "static/tpl/index/sale/change.html",
  238. controller: 'SaleChangeCtrl'
  239. }).state('sale.todo.notice', {
  240. url : "/notice",
  241. templateUrl : "static/tpl/index/sale/notice.html",
  242. controller: 'SaleNoticeCtrl'
  243. }).state('sale.customer', {
  244. url : "/customer",
  245. templateUrl : "static/tpl/index/sale/customer.html",
  246. controller: 'CustomerCtrl'
  247. }).state('sale.customer_detail', {
  248. url : "/customer/:id",
  249. templateUrl : "static/tpl/index/sale/customer_detail.html",
  250. controller: 'CustomerDetailCtrl'
  251. }).state('sale.customerProduct', {
  252. url : "/customerProduct",
  253. templateUrl : "static/tpl/index/sale/customer.html",
  254. controller: 'CustomerCtrl'
  255. }).state('sale.inquiry', {
  256. url : "/inquiry",
  257. templateUrl : "static/tpl/index/sale/inquiry.html",
  258. controller: 'SaleInquiryCtrl'
  259. }).state('sale.inquirymould', {
  260. url : "/mould",
  261. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  262. controller: 'SaleInquiryMouldCtrl'
  263. }).state('sale.todo.inquirymould', {
  264. url : "/mould",
  265. templateUrl : "static/tpl/index/sale/inquiry_mould.html",
  266. controller: 'SaleInquiryMouldCtrl'
  267. }).state('sale.inquiry_mould_detail', {
  268. url : "/mould/:id",
  269. templateUrl : "static/tpl/index/sale/inquiry_mould_detail.html",
  270. controller: 'SaleInquiryMouldDetailCtrl'
  271. }).state('sale.inquiry_detail', {
  272. url : "/inquiry/:id",
  273. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  274. controller: 'SaleInquiryDetailCtrl'
  275. }).state('sale.quotation', {
  276. url : "/quotation",
  277. templateUrl : "static/tpl/index/sale/quotation.html"
  278. }).state('sale.quotation.new', {
  279. url : "/new",
  280. templateUrl : "static/tpl/index/sale/quotation_new.html",
  281. controller: 'SaleQuotationNewCtrl'
  282. }).state('sale.quotation.list', {
  283. url : "/list",
  284. templateUrl : "static/tpl/index/sale/quotation_list.html",
  285. controller: 'SaleQuotationListCtrl'
  286. }).state('sale.quotation.item', {
  287. url : "/:id",
  288. templateUrl : "static/tpl/index/sale/quotation_new.html",
  289. controller: 'SaleQuotationNewCtrl'
  290. }).state('sale.order', {
  291. url : "/order",
  292. templateUrl : "static/tpl/index/sale/order.html",
  293. controller: 'SaleOrderCtrl'
  294. }).state('sale.order_detail', {
  295. url : "/order/:id",
  296. templateUrl : "static/tpl/index/sale/order_detail.html",
  297. controller: 'SaleOrderDetailCtrl'
  298. }).state('sale.change', {
  299. url : "/change",
  300. templateUrl : "static/tpl/index/sale/change.html",
  301. controller: 'SaleChangeCtrl'
  302. }).state('sale.change_detail', {
  303. url : "/change/:id",
  304. templateUrl : "static/tpl/index/sale/change_detail.html",
  305. controller: 'SaleChangeDetailCtrl'
  306. }).state('sale.notice', {
  307. url : "/notice",
  308. templateUrl : "static/tpl/index/sale/notice.html",
  309. controller: 'SaleNoticeCtrl'
  310. }).state('sale.send', {
  311. url : "/send",
  312. templateUrl : "static/tpl/index/sale/send.html",
  313. controller: 'SaleSendCtrl'
  314. }).state('sale.send_detail', {
  315. url : "/send/:id",
  316. templateUrl : "static/tpl/index/sale/send_detail.html",
  317. controller: 'SaleSendDetailCtrl'
  318. }).state('sale.forecast', {
  319. url : "/forecast",
  320. templateUrl : "static/tpl/index/sale/forecast.html",
  321. controller: 'SaleForecastCtrl'
  322. }).state('sale.accept', {
  323. url : "/accept",
  324. templateUrl : "static/tpl/index/sale/accept.html",
  325. controller: 'SaleAcceptCtrl'
  326. }).state('sale.returns', {
  327. url : "/returns",
  328. templateUrl : "static/tpl/index/sale/returns.html",
  329. controller: 'SaleReturnsCtrl'
  330. }).state('sale.sample', {
  331. url : "/sample",
  332. templateUrl : "static/tpl/index/sale/sample.html",
  333. controller: 'SaleSampleCtrl'
  334. }).state('sale.sample_detail', {
  335. url : "/sample/:id",
  336. templateUrl : "static/tpl/index/sale/sample_detail.html",
  337. controller: 'SaleSampleDetailCtrl'
  338. }).state('sale.approval', {
  339. url : "/approval",
  340. templateUrl : "static/tpl/index/sale/approval.html",
  341. controller: 'SaleApprovalCtrl'
  342. }).state('sale.prodList', {
  343. url : "/prodList",
  344. templateUrl : "static/tpl/index/baseInfo/prodList.html",
  345. controller : 'ProductListCtrl'
  346. }).state('sale.newProdInfo', {
  347. url : "/newProdInfo",
  348. templateUrl : "static/tpl/index/baseInfo/newProdInfo.html",
  349. controller : 'NewProdInfoCtrl'
  350. }).state('sale.uploadByBatch', {
  351. url : "/uploadByBatch",
  352. templateUrl : "static/tpl/index/baseInfo/uploadByBatch.html",
  353. controller : 'UploadByBatchCtrl'
  354. }).state('sale.productDetail', {
  355. url : "/prodList/:id",
  356. templateUrl : "static/tpl/index/baseInfo/productDetail.html",
  357. controller : 'ProductDetailCtrl'
  358. }).state('sale.maketodo', {
  359. url : "/maketodo",
  360. templateUrl : "static/tpl/index/make/todo.html"
  361. }).state('sale.maketodo.order', {
  362. url : "/makeorder",
  363. templateUrl : "static/tpl/index/make/order.html",
  364. controller: 'MakeOrderCtrl'
  365. }).state('sale.makeorder', {
  366. url : "/makeorder",
  367. templateUrl : "static/tpl/index/make/order.html",
  368. controller: 'MakeOrderCtrl'
  369. }).state('sale.makeorder_detail', {
  370. url : "/makeorder/:id",
  371. templateUrl : "static/tpl/index/make/order_detail.html",
  372. controller: 'MakeOrderDetailCtrl'
  373. }).state('sale.badOut', {
  374. url : "/badOut",
  375. templateUrl : "static/tpl/index/qc/badOut.html",
  376. controller: 'SaleBadOutCtrl'
  377. }).state('sale.MRB', {
  378. url : "/MRB",
  379. templateUrl : "static/tpl/index/qc/MRB.html",
  380. controller: 'SaleMRBCtrl'
  381. }).state('sale.badIn', {
  382. url : "/badIn",
  383. templateUrl : "static/tpl/index/qc/badIn.html",
  384. controller: 'SaleBadInCtrl'
  385. }).state('sale.makeaccept', {
  386. url : "/makeaccept",
  387. templateUrl : "static/tpl/index/make/accept.html",
  388. controller: 'MakeAcceptCtrl'
  389. }).state('sale.makereturns', {
  390. url : "/makereturns",
  391. templateUrl : "static/tpl/index/make/returns.html",
  392. controller: 'MakeReturnCtrl'
  393. }).state('sale.makechange', {
  394. url : "/makechange",
  395. templateUrl : "static/tpl/index/make/change.html",
  396. controller: 'MakeChangeCtrl'
  397. }).state('sale.makechange_detail', {
  398. url : "/makechange/:id",
  399. templateUrl : "static/tpl/index/make/change_detail.html",
  400. controller: 'MakeChangeDetailCtrl'
  401. }).state('account', {
  402. url : "/account",
  403. views : {
  404. "left-view" : {
  405. templateUrl : "static/tpl/index/account/left.html",
  406. controller: 'LeftCtrl'
  407. },
  408. "right-view" : {
  409. templateUrl : "static/tpl/index/account/right.html"
  410. }
  411. }
  412. }).state('account.index', {
  413. url : "",
  414. templateUrl : "static/tpl/index/account/index.html",
  415. controller: 'RightCtrl'
  416. }).state('account.home', {
  417. url : "/",
  418. templateUrl : "static/tpl/index/account/index.html",
  419. controller: 'RightCtrl'
  420. }).state('baseInfo', {//基础资料
  421. url : "/baseInfo",
  422. views : {
  423. "left-view" : {
  424. },
  425. "right-view" : {
  426. templateUrl : "static/tpl/index/baseInfo/right.html"
  427. }
  428. }
  429. }).state('baseInfo.index', {
  430. url : "/enterpriseList",
  431. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  432. controller: 'EnterpriseListCtrl'
  433. }).state('baseInfo.home', {
  434. url : "/enterpriseList",
  435. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  436. controller: 'EnterpriseListCtrl'
  437. }).state('baseInfo.enterpriseList', {
  438. url : "/enterpriseList",
  439. templateUrl : "static/tpl/index/baseInfo/enterpriseList.html",
  440. controller : 'EnterpriseListCtrl'
  441. }).state('baseInfo.myClient', {
  442. url : "/myClient",
  443. templateUrl : "static/tpl/index/baseInfo/myClient.html",
  444. controller : 'MyClientCtrl'
  445. }).state('baseInfo.mySupplier', {
  446. url : "/mySupplier",
  447. templateUrl : "static/tpl/index/baseInfo/mySupplier.html",
  448. controller : 'MySupplierCtrl'
  449. }).state('baseInfo.myRequest', {
  450. url : "/myRquest",
  451. templateUrl : "static/tpl/index/baseInfo/myRequest.html",
  452. controller : 'AddPartnerRequestCtrl'
  453. }).state('baseInfo.myMessage', {
  454. url : "/myMessage",
  455. templateUrl : "static/tpl/index/baseInfo/myMessage.html",
  456. controller : 'AddPartnerMessageCtrl'
  457. }).state('baseInfo.myPartners', {
  458. url : '/myPartners',
  459. templateUrl : "static/tpl/index/baseInfo/myPartners.html",
  460. controller : 'MyPartnersCtrl'
  461. }).state('baseInfo.businessGroups', {
  462. url : '/businessGroups',
  463. controller : 'BusinessGroupsCtrl'
  464. }).state('baseInfo.inquiryList', {
  465. url : '/inquiryList',
  466. templateUrl : "static/tpl/index/baseInfo/inquiry_list.html",
  467. controller : 'PublicInquiryListCtrl'
  468. }).state('baseInfo.inquiryListDetail', {
  469. url : '/inquiryList/:id',
  470. templateUrl : "static/tpl/index/baseInfo/inquiryItem_detail.html",
  471. controller : 'PublicInquiryListDetailCtrl'
  472. }).state('baseInfo.vendorInfo', {
  473. url : '/enume/vendorInfo',
  474. templateUrl : "static/tpl/index/baseInfo/vendorsInfo.html",
  475. controller : 'VendorsInfoCtrl'
  476. }).state('baseInfo.customerInfo', {
  477. url : '/enume/customerInfo',
  478. templateUrl : "static/tpl/index/baseInfo/customersInfo.html",
  479. controller : 'CustomersInfoCtrl'
  480. }).state('baseInfo.enume', {
  481. url : '/enume',
  482. templateUrl : "static/tpl/index/baseInfo/vendorAndCustomer.html",
  483. }).state('baseInfo.partner', {
  484. url : '/partner',
  485. templateUrl : "static/tpl/index/baseInfo/addPartners.html",
  486. controller : 'AddPartnersCtrl'
  487. }).state('baseInfo.partner_searchresult', {
  488. url : '/search?keyword=',
  489. templateUrl : "static/tpl/index/baseInfo/searchresult.html",
  490. controller : 'EnterpriseSearchCtrl'
  491. }).state('qc', {
  492. url : "/qc",
  493. views : {
  494. "left-view" : {
  495. templateUrl : "static/tpl/index/qc/left.html"
  496. },
  497. "right-view" : {
  498. templateUrl : "static/tpl/index/qc/right.html"
  499. }
  500. }
  501. }).state('qc.index', {
  502. url : "",
  503. templateUrl : "static/tpl/index/qc/index.html"
  504. }).state('qc.home', {
  505. url : "/",
  506. templateUrl : "static/tpl/index/qc/index.html"
  507. }).state('fa', {
  508. url : "/fa",
  509. views : {
  510. "left-view" : {
  511. templateUrl : "static/tpl/index/fa/left.html"
  512. },
  513. "right-view" : {
  514. templateUrl : "static/tpl/index/fa/right.html"
  515. }
  516. }
  517. }).state('fa.index', {
  518. url : "",
  519. templateUrl : "static/tpl/index/fa/index.html"
  520. }).state('fa.home', {
  521. url : "/",
  522. templateUrl : "static/tpl/index/fa/index.html"
  523. }).state('fa.apBill', {
  524. url : "/apBill",
  525. templateUrl : "static/tpl/index/fa/apBill.html",
  526. controller: 'SaleApBillCtrl'
  527. }).state('fa.arCheck', {
  528. url : "/arCheck",
  529. templateUrl : "static/tpl/index/fa/arCheck.html",
  530. controller: 'SaleArCheckCtrl'
  531. }).state('fa.arCheck_detail', {
  532. url : "/arCheck/:id",
  533. templateUrl : "static/tpl/index/fa/arCheck_detail.html",
  534. controller: 'SaleArCheckDetailCtrl'
  535. }).state('fa.apCheck', {
  536. url : "/apCheck",
  537. params:{
  538. 'id':null
  539. },
  540. templateUrl : "static/tpl/index/fa/apCheck.html",
  541. controller: 'PurchaseApCheckCtrl'
  542. }).state('fa.apCheck_detail', {
  543. url : "/apCheck/:id",
  544. templateUrl : "static/tpl/index/fa/apCheck_detail.html",
  545. controller: 'PurchaseApCheckDetailCtrl'
  546. }).state('fa.apCheckList', {
  547. url : "/apCheckList",
  548. templateUrl : "static/tpl/index/fa/apCheckList.html",
  549. controller: 'PurchaseApCheckListCtrl'
  550. }).state('make', {
  551. url : "/make",
  552. views : {
  553. "left-view" : {
  554. templateUrl : "static/tpl/index/make/left.html"
  555. },
  556. "right-view" : {
  557. templateUrl : "static/tpl/index/make/right.html"
  558. }
  559. }
  560. }).state('make.index', {
  561. url : "",
  562. templateUrl : "static/tpl/index/make/index.html"
  563. }).state('make.home', {
  564. url : "/",
  565. templateUrl : "static/tpl/index/make/index.html"
  566. }).state('cs', {// 客户服务
  567. url : "/cs",
  568. views : {
  569. "left-view" : {
  570. templateUrl : "static/tpl/index/cs/left.html"
  571. },
  572. "right-view" : {
  573. templateUrl : "static/tpl/index/cs/right.html"
  574. }
  575. }
  576. }).state('cs.index', {
  577. url : "",
  578. templateUrl : "static/tpl/index/cs/index.html"
  579. }).state('cs.home', {
  580. url : "/",
  581. templateUrl : "static/tpl/index/cs/index.html"
  582. }).state('search', { //顶部搜索
  583. url: "/search?keyword=",
  584. views : {
  585. "left-view" : {
  586. templateUrl : "static/tpl/index/search/left.html"
  587. },
  588. "right-view" : {
  589. templateUrl: "static/tpl/index/search/search_result.html",
  590. controller: 'TopSearchCtrl'
  591. }
  592. }
  593. }).state('approvalflow', { //审批流
  594. url: "/approvalFlow",
  595. views : {
  596. "left-view" : {
  597. templateUrl : "static/tpl/index/approvalFlow/left.html"
  598. },
  599. "right-view" : {
  600. templateUrl: "static/tpl/index/approvalFlow/right.html",
  601. }
  602. }
  603. }).state('approvalflow.flow', {
  604. url : "/flow",
  605. templateUrl : "static/tpl/index/approvalFlow/home.html",
  606. controller: 'approvalFlowCtrl'
  607. }).state('approvalflow.enterprise', {
  608. url : "/enterprise",
  609. templateUrl : "static/tpl/index/approvalFlow/enterprise.html",
  610. controller: 'EnterpriseCtrl'
  611. }).state('approvalflow.user', {
  612. url : "/user",
  613. templateUrl : "static/tpl/index/approvalFlow/user.html",
  614. controller: 'UserCtrl'
  615. }).state('approvalflow.log', {
  616. url : "/log",
  617. templateUrl : "static/tpl/index/approvalFlow/log.html",
  618. controller: 'LogCtrl'
  619. }).state('approvalflow.resource', {
  620. url : "/resource",
  621. templateUrl : "static/tpl/index/approvalFlow/resource.html",
  622. controller: 'ResourceCtrl'
  623. }).state('approvalflow.role', {
  624. url : "/role",
  625. templateUrl : "static/tpl/index/approvalFlow/role.html",
  626. controller: 'RoleCtrl'
  627. });
  628. $urlRouterProvider.otherwise('/index');
  629. }]);
  630. /**
  631. * 表示符号
  632. */
  633. app.factory('Symbol', function(){
  634. return {
  635. currency: function(cur) {
  636. if(cur == 'RMB') return '¥';
  637. else if(cur == 'USD') return '$';
  638. else if(cur == 'EUR') return '€';
  639. else if(cur == null || cur == '') return '¥';
  640. else return cur;
  641. }
  642. };
  643. }).factory('Lodop',function(){
  644. return {
  645. getLodop:function(oOBJECT,oEMBED){
  646. var CreatedOKLodop7766=null;
  647. /**************************
  648. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  649. IE系列、IE内核系列的浏览器采用oOBJECT,
  650. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  651. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  652. 64位浏览器指向64位的安装程序install_lodop64.exe。
  653. **************************/
  654. var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  655. var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  656. var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  657. var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  658. var strHtmFireFox="<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  659. var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  660. var LODOP;
  661. try{
  662. //=====判断浏览器类型:===============
  663. var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
  664. var is64IE = isIE && (navigator.userAgent.indexOf('x64')>=0);
  665. //=====如果页面有Lodop就直接使用,没有则新建:==========
  666. if (oOBJECT!=undefined || oEMBED!=undefined) {
  667. if (isIE)
  668. LODOP=oOBJECT;
  669. else
  670. LODOP=oEMBED;
  671. } else {
  672. if (CreatedOKLodop7766==null){
  673. LODOP=document.createElement("object");
  674. LODOP.setAttribute("width",0);
  675. LODOP.setAttribute("height",0);
  676. LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  677. if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  678. else LODOP.setAttribute("type","application/x-print-lodop");
  679. document.documentElement.appendChild(LODOP);
  680. CreatedOKLodop7766=LODOP;
  681. } else
  682. LODOP=CreatedOKLodop7766;
  683. };
  684. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  685. if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
  686. if (navigator.userAgent.indexOf('Chrome')>=0)
  687. document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
  688. if (navigator.userAgent.indexOf('Firefox')>=0)
  689. document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
  690. if (is64IE) document.write(strHtm64_Install); else
  691. if (isIE) document.write(strHtmInstall); else
  692. document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
  693. return LODOP;
  694. } else
  695. if (LODOP.VERSION<"6.1.9.8") {
  696. if (is64IE) document.write(strHtm64_Update); else
  697. if (isIE) document.write(strHtmUpdate); else
  698. document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
  699. return LODOP;
  700. };
  701. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  702. LODOP.SET_LICENSES("深圳市优软科技有限公司","BBF53BD5AB0D522B3207D05CDE381F65","","");
  703. //============================================================
  704. return LODOP;
  705. } catch(err) {
  706. if (is64IE)
  707. document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
  708. document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
  709. return LODOP;
  710. };
  711. }
  712. }
  713. });
  714. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
  715. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  716. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  717. if (routeState.indexOf('/') > -1)
  718. routeState = routeState.substring(0, routeState.indexOf('/'));
  719. if (routeState.indexOf('.') > -1)
  720. routeState = routeState.substring(0, routeState.indexOf('.'));
  721. $scope.routeState = routeState || 'home';
  722. });
  723. $scope.search = function(keyword) {
  724. if(keyword != null ) {
  725. $rootScope.searchKeyword = keyword;
  726. window.location.hash = '#/search?keyword='+keyword;
  727. }
  728. };
  729. $scope.showMessage = function() {
  730. var $modalInstance = $modal.open({
  731. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  732. controller: 'PagingReleaseCtrl'
  733. });
  734. };
  735. }]);
  736. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance){
  737. BaseService.scrollBackToTop();
  738. $scope.active = "todo";
  739. $scope.setActive = function(state) {
  740. if($scope.active != state) {
  741. $scope.active = state;
  742. if($scope.tableParams.page() == 1)
  743. $scope.tableParams.reload();
  744. else
  745. $scope.tableParams.page(1);
  746. }
  747. };
  748. $scope.tableParams = new ngTableParams({
  749. page : 1,
  750. count : 5,
  751. sorting: {
  752. 'releaseDetail.release.date': 'desc'
  753. }
  754. }, {
  755. total : 0,
  756. counts: [5, 10, 25, 50],
  757. getData : function($defer, params) {
  758. $scope.loading = true;
  759. var pageParams = params.url();
  760. var realActive = {};
  761. pageParams.searchFilter = { // 筛选条件
  762. keyword: $scope.keyword
  763. // fromDate: getDateTime($scope.condition.dateFrom),
  764. // endDate: getDateTime($scope.condition.dateTo)
  765. };
  766. // AccountEnterprise.get({}, function(data){
  767. // $scope.loading = false;
  768. // $scope.currentEn = data;
  769. // });
  770. PagingRelease[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  771. $scope.loading = false;
  772. if(page) {
  773. params.total(page.totalElement);
  774. $defer.resolve(page.content);
  775. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  776. }
  777. }, function(response){
  778. $scope.loading = false;
  779. toaster.pop('error', '数据加载失败', response.data);
  780. });
  781. }
  782. });
  783. $scope.close = function() {
  784. $modalInstance.close();
  785. };
  786. $scope.checks = {
  787. checked : false
  788. };// 全选框
  789. $scope.checkAll = function() {
  790. angular.forEach($scope.tableParams.data, function(message) {
  791. message.checked = $scope.checks.checked;
  792. });
  793. };
  794. // 单选
  795. $scope.checkOne = function(vendor) {
  796. vendor.checked = true;
  797. var checked = true;
  798. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  799. if (!message.checked) {
  800. checked = false;
  801. }
  802. });
  803. $scope.checks.checked = checked;
  804. };
  805. // 单反选
  806. $scope.unCheckOne = function(vendor) {
  807. vendor.checked = false;
  808. $scope.checks.checked = false;
  809. };
  810. // 标为已读
  811. $scope.setRead = function() {
  812. var selectedMessages = [];
  813. angular.forEach($scope.tableParams.data, function(message) {
  814. if(message.checked) {
  815. selectedMessages.push(message);
  816. }
  817. });
  818. console.log(selectedMessages);
  819. PagingRelease.setRead({}, selectedMessages , function(message) {
  820. $scope.tableParams.page(1);
  821. $scope.tableParams.reload();
  822. });
  823. };
  824. // 搜索框回车
  825. $scope.onSearch = function() {
  826. $scope.tableParams.page(1);
  827. $scope.tableParams.reload();
  828. };
  829. }]);
  830. app.filter('getkey', ['$sce', '$rootScope', function($sce, $rootScope) {
  831. var search = $rootScope.searchKeyword;
  832. return function(content, search) {
  833. content = encodeURI(content);
  834. search = encodeURI(search);
  835. var reg = new RegExp(search, 'gim');
  836. var result = content.replace(reg,'<font color="red">$&</font>');
  837. result = decodeURI(result);
  838. return $sce.trustAsHtml(result);
  839. }
  840. }]);
  841. /**
  842. * 顶部搜索
  843. */
  844. 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) {
  845. BaseService.scrollBackToTop();
  846. $scope.active = 'all';
  847. $scope.tip = $rootScope.searchKeyword;
  848. // 企业搜索
  849. var getService = function() {
  850. return getAccountUserSpace;
  851. };
  852. $scope.tableParams = new ngTableParams({
  853. page : 1,
  854. count : 5,
  855. sorting: {
  856. }
  857. }, {
  858. total : 0,
  859. counts: [5, 10, 25, 50],
  860. getData : function($defer, params) {
  861. $scope.loading = true;
  862. var pageParams = params.url();
  863. pageParams.keyword = $rootScope.searchKeyword;
  864. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  865. $scope.loading = false;
  866. if(page) {
  867. $scope.total = page.totalElement;
  868. params.total(page.totalElement);
  869. $defer.resolve(page.content);
  870. }
  871. }, function(response) {
  872. $scope.loading = false;
  873. toaster.pop('error', '数据加载失败', response.data);
  874. });
  875. }
  876. });
  877. // 添加合作关系
  878. $scope.addPartner = function(name, businessCode) {
  879. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  880. if(data.success) {
  881. toaster.pop("success", '添加成功', data.success);
  882. }
  883. if(data.error) {
  884. toaster.pop("error", '添加失败', data.error);
  885. }
  886. }, function(response) {
  887. toaster.pop('error','失败',response.data);
  888. });
  889. }
  890. // 物料搜索
  891. var getProdService = function() {
  892. return SearchProd;
  893. };
  894. $scope.prodTableParams = new ngTableParams({
  895. page : 1,
  896. count : 5,
  897. sorting: {
  898. }
  899. }, {
  900. total : 0,
  901. counts: [5, 10, 25, 50],
  902. getData : function($defer, params) {
  903. $scope.loading = true;
  904. var pageParams = params.url();
  905. pageParams.keyword = $rootScope.searchKeyword;
  906. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  907. $scope.loading = false;
  908. if(page) {
  909. $scope.prodtotal = page.totalElement;
  910. params.total(page.totalElement);
  911. $defer.resolve(page.content);
  912. }
  913. }, function(response) {
  914. $scope.loading = false;
  915. toaster.pop('error', '数据加载失败', response.data);
  916. });
  917. }
  918. });
  919. /**
  920. * 向企业购买
  921. */
  922. $scope.PurcByEn = function(businessCode) {
  923. $rootScope.businessCode = businessCode;
  924. window.location.hash = "#/purc/addOrder";
  925. }
  926. /**
  927. * 选中单个物料购买
  928. * @param businessCode
  929. * @param id
  930. */
  931. $scope.PurcByEnAndProd = function(businessCode, id) {
  932. $rootScope.businessCode = businessCode;
  933. $rootScope.prodId = id;
  934. window.location.hash = "#/purc/addOrder";
  935. }
  936. /**
  937. * 邀请注册商务平台
  938. */
  939. $scope.invite = function(name) {
  940. var modalInstance = $modal.open({
  941. animation: true,
  942. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  943. controller: 'InviteCtrl',
  944. resolve: {
  945. enname: function(){return name}
  946. }
  947. });
  948. modalInstance.result.then(function(data) {
  949. InvitationRecord.invite({formStore: data}, {}, function(data) {
  950. if(data.success) {
  951. toaster.pop('success', '提示', data.success);
  952. }
  953. if(data.error) {
  954. toaster.pop('error', '提示', data.error);
  955. }
  956. }, function(response) {
  957. toaster.pop('error', '提示', response.data);
  958. });
  959. });
  960. }
  961. }]);
  962. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function($scope, toaster, $modalInstance, enname) {
  963. $scope.enter = {
  964. vendname: enname
  965. };
  966. $scope.save = function(enter) {
  967. if(!enter.vendusertel && !enter.venduseremail) {
  968. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  969. } else {
  970. $modalInstance.close(enter);
  971. }
  972. }
  973. $scope.cancel = function() {
  974. $modalInstance.dismiss();
  975. }
  976. }]);
  977. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  978. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  979. //手机号码格式验证
  980. // var checkTel = function(data){
  981. // var userTel = data.userTel;
  982. // $scope.checkResult = false;
  983. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  984. // if(!(telephone).test(userTel)){
  985. // var modalInstance = $modal.open({
  986. // animation: true,
  987. // templateUrl: 'static/tpl/index/account/checkTel.html',
  988. // controller: 'CheckTelCtrl',
  989. // backdrop: 'static',
  990. // keyboard: false,
  991. // resolve: {
  992. // user: function(){
  993. // return data;
  994. // },
  995. // }
  996. // });
  997. // modalInstance.result.then(function(){
  998. // }, function(){
  999. //
  1000. // });
  1001. // } else {
  1002. // $scope.checkResult = true;
  1003. // }
  1004. // };
  1005. AuthenticationService.getAuthentication().success(function(data) {
  1006. if(data.enterprises) {
  1007. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1008. if(data.enterprises.length > 1) {
  1009. var enSelect = [];
  1010. angular.forEach(data.enterprises, function(e){
  1011. if(e.current)
  1012. data.enterprise = e;
  1013. else
  1014. enSelect.push(e);
  1015. });
  1016. data.enSelect = enSelect;
  1017. }
  1018. }
  1019. $scope.userInfo = data;
  1020. if (data == null || !data.userUU) {
  1021. $scope.isAuthed = false;
  1022. AuthenticationService.redirectSignin();
  1023. } else {
  1024. //跳转到手机号码验证
  1025. // checkTel($scope.userInfo);
  1026. }
  1027. });
  1028. $scope.logout = function() {
  1029. AuthenticationService.logout();
  1030. };
  1031. $scope.switchto = function(enUU) {// 切换企业
  1032. AuthenticationService.reSignin(enUU).success(function(){
  1033. $window.location.reload();
  1034. });
  1035. };
  1036. $scope.addFavorite = function(){
  1037. var url = encodeURI(window.location.href);
  1038. try{
  1039. //ie浏览器收藏方式
  1040. window.external.addFavorite(url, "优软商务平台");
  1041. }catch(e) {
  1042. try{
  1043. //火狐浏览器收藏方式
  1044. window.sidebar.addPanel("优软商务平台", url);
  1045. }catch (e) {
  1046. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  1047. "或手动在浏览器里进行设置。");
  1048. }
  1049. }
  1050. };
  1051. }]);
  1052. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  1053. $scope.image = {src: null};
  1054. // 图片上传成功之后
  1055. $scope.onUploadSuccess = function(data){
  1056. var path = data.path;
  1057. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1058. $scope.$apply(function(){
  1059. $scope.image.src = data.path;
  1060. $scope.image.thumb = path;
  1061. });
  1062. };
  1063. $scope.close = function() {
  1064. $modalInstance.dismiss();
  1065. };
  1066. $scope.confirm = function() {
  1067. $modalInstance.close($scope.image);
  1068. $scope.imageUrl = null;
  1069. };
  1070. }]);
  1071. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function($scope, SnapshotService, BaseService, $rootScope){
  1072. BaseService.scrollBackToTop();
  1073. SnapshotService.getTodo(function(data){
  1074. $scope.todo = data;
  1075. });
  1076. $scope.setTenderActive = function(active) {
  1077. $rootScope.tenderActive = active;
  1078. window.location.hash = '#/purc/tender';
  1079. }
  1080. }]);
  1081. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  1082. SaleTruck.query({}, function(data){
  1083. $rootScope.truck = data;
  1084. $scope.truckCount = data ? data.length : 0;
  1085. });
  1086. $scope.$watch(function(){
  1087. return $rootScope.truck;
  1088. }, function(data) {
  1089. $scope.truckCount = data ? data.length : 0;
  1090. }, true);
  1091. $scope.clearAll = function() {
  1092. SaleTruck.remove({}, function(){
  1093. $rootScope.truck = [];
  1094. });
  1095. };
  1096. $scope.openTrack = function() {
  1097. $modal.open({
  1098. templateUrl: 'static/tpl/index/sale/track.html',
  1099. controller: 'TruckModalCtrl',
  1100. size: 'lg'
  1101. }).result.then(function(s){
  1102. if(s) {
  1103. $scope.clearAll();
  1104. $rootScope.dataChanged = true;
  1105. }
  1106. });
  1107. };
  1108. }]);
  1109. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter){
  1110. $scope.saleSend = {sendItems: []};
  1111. SaleTruck.detail({}, function(data){
  1112. // 按物料编号排序
  1113. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1114. });
  1115. $scope.remove = function(index, notice) {
  1116. SaleTruck.remove({noticeId: notice.id}, function(data){
  1117. $rootScope.truck = data;
  1118. $scope.notices.splice(index, 1);
  1119. });
  1120. };
  1121. $scope.$watch(function(){
  1122. return $scope.notices;
  1123. }, function(data) {
  1124. var q = 0, t = 0;
  1125. if(data) {
  1126. angular.forEach(data,function(d){
  1127. q += d.thisSendQty;
  1128. t += d.thisSendQty * d.orderItem.price;
  1129. });
  1130. }
  1131. $scope.totalQty = q;
  1132. $scope.total = t;
  1133. }, true);
  1134. $scope.cancel = function() {
  1135. $modalInstance.close();
  1136. };
  1137. $scope.send = function() {// 发货
  1138. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1139. toaster.pop('error', '错误', '请输入送货单号');
  1140. return;
  1141. }
  1142. var currency = $scope.notices[0].orderItem.order.currency,
  1143. custUU = $scope.notices[0].enUU,
  1144. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1145. var num = 1;
  1146. for(var i in $scope.notices) {
  1147. var item = $scope.notices[i];
  1148. if(item.id) {
  1149. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1150. valid = false;
  1151. break;
  1152. }
  1153. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++};
  1154. }
  1155. }
  1156. if(!valid) {
  1157. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1158. } else {
  1159. var send = angular.extend(angular.copy($scope.saleSend), {
  1160. currency: currency,
  1161. custUU: custUU,
  1162. payments: payments,
  1163. sendItems: items
  1164. });
  1165. PurcNotice.sendByBatch({}, send, function(data){
  1166. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1167. $modalInstance.close(true);
  1168. $state.go('sale.send_detail', {id: data.id});
  1169. }, function(response){
  1170. toaster.pop('error', '错误', response.data);
  1171. });
  1172. }
  1173. };
  1174. }]);
  1175. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  1176. SaleStat.cust({}, function(data){
  1177. var p = [], q = [];
  1178. angular.forEach(data.month, function(d){
  1179. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1180. });
  1181. angular.forEach(data.year, function(d){
  1182. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  1183. });
  1184. $scope.custCharts = {
  1185. month : {
  1186. chartType : 'pie',
  1187. datas : {
  1188. data : p
  1189. },
  1190. config : {
  1191. labels : false,
  1192. title : "客户月采购量排行榜",
  1193. legend : {
  1194. display : true,
  1195. position : 'right'
  1196. },
  1197. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1198. click : function(d) {
  1199. },
  1200. mouseover : function(d) {
  1201. },
  1202. mouseout : function(d) {
  1203. },
  1204. innerRadius : 0,
  1205. lineLegend : 'lineEnd'
  1206. }
  1207. },
  1208. year : {
  1209. chartType : 'pie',
  1210. datas : {
  1211. data : q
  1212. },
  1213. config : {
  1214. labels : false,
  1215. title : "客户年采购量排行榜",
  1216. legend : {
  1217. display : true,
  1218. position : 'right'
  1219. },
  1220. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1221. click : function(d) {
  1222. },
  1223. mouseover : function(d) {
  1224. },
  1225. mouseout : function(d) {
  1226. },
  1227. innerRadius : 0,
  1228. lineLegend : 'lineEnd'
  1229. }
  1230. }
  1231. };
  1232. });
  1233. SaleStat.seller({}, function(data){
  1234. var p = [], q = [];
  1235. angular.forEach(data.month, function(d){
  1236. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1237. });
  1238. angular.forEach(data.year, function(d){
  1239. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1240. });
  1241. $scope.sellerCharts = {
  1242. month : {
  1243. chartType : 'pie',
  1244. datas : {
  1245. data : p
  1246. },
  1247. config : {
  1248. labels : false,
  1249. title : "业务员月销量排行榜",
  1250. legend : {
  1251. display : true,
  1252. position : 'right'
  1253. },
  1254. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1255. click : function(d) {
  1256. },
  1257. mouseover : function(d) {
  1258. },
  1259. mouseout : function(d) {
  1260. },
  1261. innerRadius : 0,
  1262. lineLegend : 'lineEnd'
  1263. }
  1264. },
  1265. year : {
  1266. chartType : 'pie',
  1267. datas : {
  1268. data : q
  1269. },
  1270. config : {
  1271. labels : false,
  1272. title : "业务员年销量排行榜",
  1273. legend : {
  1274. display : true,
  1275. position : 'right'
  1276. },
  1277. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  1278. click : function(d) {
  1279. },
  1280. mouseover : function(d) {
  1281. },
  1282. mouseout : function(d) {
  1283. },
  1284. innerRadius : 0,
  1285. lineLegend : 'lineEnd'
  1286. }
  1287. }
  1288. };
  1289. });
  1290. }]);
  1291. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  1292. SaleStat.get({}, function(data){
  1293. var p = [], q = [], r = [];
  1294. angular.forEach(data.day, function(d){
  1295. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1296. });
  1297. angular.forEach(data.month, function(d){
  1298. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1299. });
  1300. angular.forEach(data.year, function(d){
  1301. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1302. });
  1303. $scope.charts = {
  1304. day : {
  1305. chartType : "line",
  1306. datas: {
  1307. series: ['销售额'],
  1308. data: p
  1309. },
  1310. config : {
  1311. "labels": false,
  1312. "title": "销售额统计(近15日线)",
  1313. "legend": {
  1314. "display": true,
  1315. "position": "right"
  1316. },
  1317. colors : [ '#4D9934'],
  1318. "innerRadius": 0,
  1319. "lineLegend": "lineEnd"
  1320. }
  1321. },
  1322. month: {
  1323. chartType : "line",
  1324. datas: {
  1325. series: ['销售额'],
  1326. data: q
  1327. },
  1328. config : {
  1329. "labels": false,
  1330. "title": "销售额统计(近12月线)",
  1331. "legend": {
  1332. "display": true,
  1333. "position": "right"
  1334. },
  1335. colors : [ '#4D9934'],
  1336. "innerRadius": 0,
  1337. "lineLegend": "lineEnd"
  1338. }
  1339. },
  1340. year: {
  1341. chartType : "line",
  1342. datas: {
  1343. series: ['销售额'],
  1344. data: r
  1345. },
  1346. config : {
  1347. "labels": false,
  1348. "title": "销售额统计(近10年线)",
  1349. "legend": {
  1350. "display": true,
  1351. "position": "right"
  1352. },
  1353. colors : [ '#4D9934'],
  1354. "innerRadius": 0,
  1355. "lineLegend": "lineEnd"
  1356. }
  1357. }
  1358. };
  1359. });
  1360. }]);
  1361. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1362. SnapshotService.getNotice(5, function(data){ //5表示首页显示的公告条数
  1363. $scope.notices = data;
  1364. });
  1365. $scope.dateTime = new Date();
  1366. }]);
  1367. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  1368. // SnapshotService.getTender(250, function(data){
  1369. // $scope.tenders = data;
  1370. // console.log(data);
  1371. // var newDate = new Date();
  1372. // newDate = newDate.setDate(newDate.getDate() - 3);
  1373. // angular.forEach($scope.tenders, function(tender) {
  1374. // if (tender.date > newDate) {
  1375. // tender.isNew = true;
  1376. // } else {
  1377. // tender.isNew = false;
  1378. // }
  1379. // });
  1380. // });
  1381. SnapshotService.getOpenTender(function(data){
  1382. $scope.openTenders = data;
  1383. var newDate = new Date();
  1384. console.log(data);
  1385. newDate = newDate.getTime() - 3*24*60*60*1000;
  1386. angular.forEach($scope.openTenders, function(tender) {
  1387. if (tender.date - newDate > 0) {
  1388. tender.isNew = true;
  1389. } else {
  1390. tender.isNew = false;
  1391. }
  1392. });
  1393. });
  1394. $scope.dateTime = new Date();
  1395. }]);
  1396. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  1397. VendorService.getCount(function(date){
  1398. $scope.count = date;
  1399. });
  1400. }]);
  1401. // 客户
  1402. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  1403. BaseService.scrollBackToTop();
  1404. $scope.userInfoResult = true;
  1405. AuthenticationService.getAuthentication().success(function(data) {
  1406. $scope.loading = false;
  1407. $scope.thisUser = data;
  1408. });
  1409. var getCustInfos = function(custuu) {
  1410. if(custuu) {
  1411. VendorService.userInfo.query({uu:custuu},null,function(data) {
  1412. $scope.custInfos = data;
  1413. var getPage = function(page, size){
  1414. if($scope.custInfos) {
  1415. var result = {};
  1416. result.totalCount = $scope.custInfos.length;
  1417. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1418. if($scope.custInfos.length % size == 0) {
  1419. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1420. }else {
  1421. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1422. }
  1423. result.first = page == 1;
  1424. result.last = page == result.totalPage;
  1425. result.page = page;
  1426. result.next = page - 0 + 1;
  1427. result.pre = page - 1;
  1428. return result;
  1429. }
  1430. }
  1431. $scope.userdata = getPage(1,4);
  1432. $scope.first = function (){
  1433. $scope.userdata = getPage($scope.userdata.pre,4);
  1434. }
  1435. $scope.last = function (){
  1436. $scope.userdata = getPage($scope.userdata.next,4);
  1437. }
  1438. }, function(response){
  1439. $scope.loading = false;
  1440. toaster.pop('error', '数据加载失败', response.data);
  1441. });
  1442. }
  1443. }
  1444. $scope.addUserInfo = function(customer) {
  1445. //TODO
  1446. if ($scope.thisUser.sys) {
  1447. var modalInstance = $modal.open({
  1448. animation: true,
  1449. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1450. controller: 'AddUserInfoCtrl',
  1451. resolve: {
  1452. customer: function() {
  1453. return customer;
  1454. }
  1455. }
  1456. });
  1457. modalInstance.result.then(function(changed, checked){
  1458. if(changed) {
  1459. if(checked)
  1460. $scope.newUser.roles = checked;
  1461. else
  1462. loadUsers();
  1463. }
  1464. });
  1465. } else {
  1466. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1467. }
  1468. }
  1469. $scope.showUserInfo = function(customer,boo) {
  1470. $scope.custInfo = customer;
  1471. if(boo) {
  1472. getCustInfos(customer.myEnterprise.uu);
  1473. $scope.userInfoResult = true;
  1474. }
  1475. }
  1476. $scope.customerParams = new ngTableParams({
  1477. page : 1,
  1478. count : 10
  1479. }, {
  1480. total : 0,
  1481. counts: [5, 10, 25, 50],
  1482. getData : function($defer, params) {
  1483. $scope.loading = true;
  1484. var pageParams = params.url();
  1485. pageParams.keyword = $scope.keyword;
  1486. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  1487. $scope.loading = false;
  1488. if(page) {
  1489. params.total(page.totalElement);
  1490. $defer.resolve(page.content);
  1491. }
  1492. $scope.totalCount = page.totalElement;
  1493. }, function(response){
  1494. $scope.loading = false;
  1495. toaster.pop('error', '数据加载失败', response.data);
  1496. });
  1497. }
  1498. });
  1499. // 搜索框回车
  1500. $scope.onSearch = function(keyword) {
  1501. $scope.customerParams.page(1);
  1502. $scope.customerParams.reload();
  1503. $scope.tip = keyword;
  1504. };
  1505. // 查看详情
  1506. $scope.viewDetail = function(id) {
  1507. console.log(id);
  1508. window.location.hash = "#/sale/customer/" + id;
  1509. }
  1510. }]);
  1511. // 客户详情
  1512. 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) {
  1513. BaseService.scrollBackToTop();
  1514. $scope.userInfoResult = true;
  1515. AuthenticationService.getAuthentication().success(function(data) {
  1516. $scope.loading = false;
  1517. $scope.thisUser = data;
  1518. });
  1519. $scope.vendorContacts = [];
  1520. var loadData = function() {
  1521. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  1522. $scope.customer = data.myEnterprise;
  1523. $scope.customerInfo = data;
  1524. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function(data) {
  1525. $scope.Contacts = data;
  1526. });
  1527. // 查看已分配人员
  1528. VendorService.userInfo.query({uu: $scope.customer.uu},null,function(data) {
  1529. $scope.custInfos = data;
  1530. var getPage = function(page, size){
  1531. if($scope.custInfos) {
  1532. var result = {};
  1533. result.totalCount = $scope.custInfos.length;
  1534. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  1535. if($scope.custInfos.length % size == 0) {
  1536. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1537. }else {
  1538. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1539. }
  1540. result.first = page == 1;
  1541. result.last = page == result.totalPage;
  1542. result.page = page;
  1543. result.next = page - 0 + 1;
  1544. result.pre = page - 1;
  1545. return result;
  1546. }
  1547. }
  1548. $scope.userdata = getPage(1,4);
  1549. $scope.first = function (){
  1550. $scope.userdata = getPage($scope.userdata.pre,4);
  1551. }
  1552. $scope.last = function (){
  1553. $scope.userdata = getPage($scope.userdata.next,4);
  1554. }
  1555. }, function(response){
  1556. $scope.loading = false;
  1557. toaster.pop('error', '数据加载失败', response.data);
  1558. });
  1559. });
  1560. };
  1561. loadData();
  1562. // 新增客户联系人
  1563. $scope.addContact = function(uu) {
  1564. var modalInstance = $modal.open({
  1565. animation: true,
  1566. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  1567. controller: 'AddContacCtrl',
  1568. resolve: {
  1569. }
  1570. });
  1571. modalInstance.result.then(function(data) {
  1572. $scope.contact = data;
  1573. $scope.contact.myenuu = uu;
  1574. Vendor.saveCustContact({}, $scope.contact, function(data) {
  1575. toaster.pop('success', '提示', '联系人保存成功');
  1576. $scope.Contacts.push(data);
  1577. }, function(response) {
  1578. toaster.pop('error', '失败', response.data);
  1579. });
  1580. });
  1581. }
  1582. // 编辑客户联系人
  1583. $scope.edit = function(contact) {
  1584. var modalInstance = $modal.open({
  1585. animation: true,
  1586. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  1587. controller: 'EditContacCtrl',
  1588. resolve: {
  1589. contact: function() {
  1590. return contact;
  1591. }
  1592. }
  1593. });
  1594. modalInstance.result.then(function(data) {
  1595. $scope.contact = data;
  1596. Vendor.saveContact({}, $scope.contact, function(data) {
  1597. toaster.pop('success', '提示', '联系人修改成功');
  1598. }, function(response) {
  1599. toaster.pop('error', '失败', response.data);
  1600. });
  1601. });
  1602. }
  1603. // 删除客户联系人
  1604. $scope.deleteById = function(id, index) {
  1605. $scope.Contacts.splice(index, 1);
  1606. Vendor.deleteContact({id: id}, {}, function(data) {
  1607. toaster.pop('success', '提示', '供应商联系人删除成功');
  1608. }, function(response) {
  1609. toaster.pop('error', '提示', response.data);
  1610. });
  1611. }
  1612. // 供应商物料信息
  1613. $scope.viewProdList = function(uu){
  1614. $scope.uu = uu;
  1615. $scope.tableParams.page(1);
  1616. $scope.tableParams.reload();
  1617. };
  1618. // 搜索框回车
  1619. $scope.onSearch = function(keyword) {
  1620. $scope.keyword = keyword;
  1621. $scope.tableParams.page(1);
  1622. $scope.tableParams.reload();
  1623. };
  1624. // 供应商物料信息
  1625. $scope.tableParams = new ngTableParams({
  1626. page : 1,
  1627. count : 10
  1628. }, {
  1629. total : 0,
  1630. counts: [5, 10, 25, 50],
  1631. getData : function($defer, params) {
  1632. $scope.loading = true;
  1633. var pageParams = params.url();
  1634. pageParams.custUU = $scope.uu;
  1635. pageParams.keyword = $scope.keyword;
  1636. $scope.tip = $scope.keyword;
  1637. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1638. $scope.loading = false;
  1639. if(page) {
  1640. params.total(page.totalElement);
  1641. $scope.total = page.totalElement;
  1642. $defer.resolve(page.content);
  1643. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1644. }
  1645. }, function(response){
  1646. $scope.loading = false;
  1647. toaster.pop('error', '数据加载失败', response.data);
  1648. });
  1649. }
  1650. });
  1651. $scope.addUserInfo = function() {
  1652. //TODO
  1653. if ($scope.thisUser.sys) {
  1654. var modalInstance = $modal.open({
  1655. animation: true,
  1656. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1657. controller: 'AddUserInfoCtrl',
  1658. resolve: {
  1659. customer: function() {
  1660. return $scope.customerInfo;
  1661. }
  1662. }
  1663. });
  1664. modalInstance.result.then(function(changed, checked){
  1665. if(changed) {
  1666. if(checked)
  1667. $scope.newUser.roles = checked;
  1668. else
  1669. loadUsers();
  1670. }
  1671. });
  1672. } else {
  1673. toaster.pop('error', '您不是管理员,无权限分配用户!');
  1674. }
  1675. }
  1676. $scope.Quotation = function(uu, id) {
  1677. $rootScope.custuu = uu;
  1678. $rootScope.prodId = id;
  1679. window.location.hash = "#/sale/quotation/new";
  1680. }
  1681. }]);
  1682. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function($scope, $modalInstance, customer, AccountUser, toaster){
  1683. $scope.checkboxes = {
  1684. checked : false
  1685. };
  1686. $scope.loading = true;
  1687. AccountUser.findUsers({uu:customer.myEnterprise.uu},null,function(data) {
  1688. $scope.userinfos = data;
  1689. $scope.loading = false;
  1690. })
  1691. // 点击勾选全部的复选框
  1692. $scope.checkAll = function() {
  1693. angular.forEach($scope.userinfos, function(item) {
  1694. item.distribute = $scope.checkboxes.checked;
  1695. });
  1696. };
  1697. // 点击其中一个明细的复选框
  1698. $scope.checkOne = function(vendor){
  1699. var result = true;
  1700. angular.forEach($scope.userinfos, function(item) {
  1701. if(item.distribute != true){
  1702. result = false;
  1703. return;
  1704. }
  1705. });
  1706. $scope.checkboxes.checked = result;
  1707. };
  1708. $scope.close = function(save) {
  1709. var chooseResult = [];
  1710. if(save) {
  1711. if(customer.myEnterprise.uu) {
  1712. angular.forEach($scope.userinfos, function(item, i) {
  1713. chooseResult.push(item);
  1714. });
  1715. if(chooseResult.length > 0) {
  1716. $scope.loading = true;
  1717. AccountUser.addUserToVendor({uu : customer.myEnterprise.uu }, chooseResult,function(data) {
  1718. $scope.loading = false;
  1719. toaster.pop('success', '提示', '保存成功');
  1720. $modalInstance.close(false);
  1721. }, function(response){
  1722. $scope.loading = false;
  1723. toaster.pop('error', '保存失败', response.data);
  1724. $modalInstance.close(false);
  1725. })
  1726. } else {
  1727. toaster.pop('error', '保存失败', "您未勾选任何记录");
  1728. }
  1729. } else {
  1730. $modalInstance.close(true, $scope.checkboxes.checked);
  1731. }
  1732. } else {
  1733. $modalInstance.close(false);
  1734. }
  1735. };
  1736. }]);
  1737. /**
  1738. * 页面状态按钮过滤
  1739. */
  1740. var getState = function(active) {
  1741. var fn = 'get';
  1742. switch(active) {
  1743. case 'done':
  1744. fn = 'getDone';break;
  1745. case 'todo':
  1746. fn = 'getTodo';break;
  1747. case 'end':
  1748. fn = 'getEnd';break;
  1749. case 'waiting':
  1750. fn = 'getWaiting';break;
  1751. case 'invalid':
  1752. fn = 'getInvalid';break;
  1753. }
  1754. return fn;
  1755. };
  1756. /**
  1757. * 改变单据日期范围
  1758. */
  1759. var getDateCondition = function(zone, condition) {
  1760. var date = new Date();
  1761. if(zone == -1) {
  1762. condition.dateFrom = null;
  1763. condition.dateTo = null;
  1764. } else if(zone == 1) {
  1765. date.setMonth(date.getMonth() - 1);
  1766. condition.dateFrom = date;
  1767. condition.dateTo = new Date();
  1768. } else if (zone == 6) {
  1769. date.setMonth(date.getMonth() - 6);
  1770. condition.dateFrom = date;
  1771. condition.dateTo = new Date();
  1772. } else {
  1773. date.setMonth(date.getMonth() - 6);
  1774. condition.dateFrom = null;
  1775. condition.dateTo = date;
  1776. }
  1777. };
  1778. /**
  1779. * 改变单据交货日期范围
  1780. */
  1781. var getDelveryCondition = function(zone, condition) {
  1782. var date = new Date();
  1783. if(zone == -1) {
  1784. condition.deliveryFrom = null;
  1785. condition.deliveryTo = null;
  1786. } else if(zone == 1) {
  1787. date.setMonth(date.getMonth() + 1);
  1788. condition.deliveryTo = date;
  1789. condition.deliveryFrom = new Date();
  1790. } else if (zone == 2) {
  1791. date.setMonth(date.getMonth() + 2);
  1792. condition.deliveryTo = date;
  1793. condition.deliveryFrom = new Date();
  1794. }
  1795. };
  1796. /**
  1797. * 将日期转化为整数日期
  1798. */
  1799. var getDateTime = function(date) {
  1800. if(angular.isDate(date)) {
  1801. return date.getTime();
  1802. } else {
  1803. return null;
  1804. }
  1805. };
  1806. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService',
  1807. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService){
  1808. BaseService.scrollBackToTop();
  1809. $scope.active = 'all';
  1810. $scope.dateZoneText = '不限';
  1811. $scope.deliveryZoneText = '不限';
  1812. $scope.condition = {dateZone: -1, deliveryZone: -1};
  1813. $scope.changeDateZone = function(zone) {
  1814. $scope.condition.dateZone = zone;
  1815. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  1816. $scope.condition.$dateZoneOpen = false;
  1817. getDateCondition(zone, $scope.condition);
  1818. $scope.tableParams.reload();
  1819. };
  1820. $scope.changeDeliveryZone = function(zone) {
  1821. $scope.condition.deliveryZoneText = zone;
  1822. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  1823. $scope.condition.$delievryZoneOpen = false;
  1824. getDelveryCondition(zone, $scope.condition);
  1825. $scope.tableParams.reload();
  1826. };
  1827. // 切换单据类型
  1828. $scope.setActive = function(state) {
  1829. if($scope.active != state) {
  1830. $scope.active = state;
  1831. if($scope.tableParams.page() == 1)
  1832. $scope.tableParams.reload();
  1833. else
  1834. $scope.tableParams.page(1);
  1835. }
  1836. };
  1837. var getPurcStatus = function(active) {
  1838. var fn = 'getPurcAll';
  1839. switch(active) {
  1840. case 'done':
  1841. fn = 'getPurcDone';break;
  1842. case 'todo':
  1843. fn = 'getPurcTodo';break;
  1844. case 'end':
  1845. fn = 'getPurcEnd';break;
  1846. case 'waiting':
  1847. fn = 'getPurcWaiting';break;
  1848. }
  1849. return fn;
  1850. };
  1851. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1852. page : 1,
  1853. count : 5,
  1854. sorting: {
  1855. display: 'desc',
  1856. date: 'desc'
  1857. }
  1858. }, {
  1859. total : 0,
  1860. counts: [5, 10, 15, 25, 50],
  1861. getData : function($defer, params) {// 获取数据的方法
  1862. $scope.loading = true;
  1863. var pageParams = params.url();
  1864. pageParams.searchFilter = { // 筛选条件
  1865. keyword: $scope.keyword,
  1866. fromDate: getDateTime($scope.condition.dateFrom),
  1867. endDate: getDateTime($scope.condition.dateTo)
  1868. };
  1869. PurcOrderItem[getPurcStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1870. $scope.loading = false;
  1871. if(page) {
  1872. $defer.resolve(page.content);
  1873. params.total(page.totalElement);
  1874. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  1875. }
  1876. }, function(response){
  1877. $scope.loading = false;
  1878. toaster.pop('error', '数据加载失败', response.data);
  1879. });
  1880. }
  1881. });
  1882. $scope.getReply = function(item) {
  1883. if(!item.replies) {
  1884. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1885. item.replies = replies;
  1886. });
  1887. }
  1888. };
  1889. $scope.getOrderTotal = function(items) {
  1890. var sum = 0;
  1891. angular.forEach(items, function(item){
  1892. sum += item.qty * item.price;
  1893. });
  1894. return sum;
  1895. };
  1896. $scope.openDatePicker = function($event, item, openParam) {
  1897. $event.preventDefault();
  1898. $event.stopPropagation();
  1899. item[openParam] = !item[openParam];
  1900. };
  1901. $scope.parseDate = function(dateStr) {
  1902. if(dateStr)
  1903. return Date.parse(dateStr, 'yyyy-MM-dd');
  1904. return new Date();
  1905. };
  1906. $scope.checkboxes = {
  1907. checked : false
  1908. };
  1909. // 点击勾选全部的复选框
  1910. $scope.checkAll = function(){
  1911. angular.forEach($scope.tableParams.data, function(item) {
  1912. item.$selected = $scope.checkboxes.checked;
  1913. });
  1914. };
  1915. // 点击其中一个明细的复选框
  1916. $scope.checkOne = function(order){
  1917. var result = true;
  1918. angular.forEach($scope.tableParams.data, function(item) {
  1919. if(item.$selected != true){
  1920. result = false;
  1921. return;
  1922. }
  1923. });
  1924. $scope.checkboxes.checked = result;
  1925. };
  1926. // 搜索框回车
  1927. $scope.onSearch = function(keyword) {
  1928. $scope.tableParams.page(1);
  1929. $scope.tableParams.reload();
  1930. $scope.tip = keyword;
  1931. };
  1932. // 选择查找日期
  1933. $scope.onDateCondition = function(){
  1934. $scope.tableParams.page(1);
  1935. $scope.tableParams.reload();
  1936. };
  1937. }]);
  1938. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  1939. var loadData = function() {
  1940. PurcOrder.get({id: $stateParams.id}, function(data){
  1941. $scope.order = data;
  1942. var sum = 0;
  1943. angular.forEach($scope.order.orderItems, function(item){
  1944. sum += item.qty * item.price;
  1945. });
  1946. $scope.order.total = sum;
  1947. if($scope.order.display == 1) {//未查看的设为已查看
  1948. $scope.setDisplay('setRead', $scope.order.id);
  1949. }
  1950. $scope.loading = false;
  1951. });
  1952. };
  1953. loadData();
  1954. $scope.getReply = function(item) {
  1955. if(!item.replies) {
  1956. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  1957. item.replies = replies;
  1958. });
  1959. }
  1960. };
  1961. $scope.openDatePicker = function($event, item, openParam) {
  1962. $event.preventDefault();
  1963. $event.stopPropagation();
  1964. item[openParam] = !item[openParam];
  1965. };
  1966. $scope.onReplyClick = function(item, inverse) {
  1967. if(item.reply) {
  1968. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  1969. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  1970. return;
  1971. }
  1972. var reply = angular.copy(item.reply);
  1973. if(reply.delivery) {
  1974. if(typeof reply.delivery == 'object')
  1975. reply.delivery = reply.delivery.getTime();
  1976. } else {
  1977. reply.delivery = item.delivery;
  1978. }
  1979. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  1980. $scope.loading = true;
  1981. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  1982. $scope.loading = false;
  1983. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  1984. loadData();
  1985. }, function(response){
  1986. $scope.loading = false;
  1987. toaster.pop('error', '回复失败', response.data);
  1988. });
  1989. }
  1990. };
  1991. // // 采购单
  1992. // $scope.print = function(order) {
  1993. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  1994. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  1995. // };
  1996. //设置为已查看
  1997. $scope.setDisplay = function(state, orderId) {
  1998. if(orderId) {//设置单个
  1999. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2000. // $scope.tableParams.reload();
  2001. }, function() {
  2002. toaster.pop('error', '错误', "设置失败");
  2003. });
  2004. } else {//设置已勾选的
  2005. var str = null;
  2006. angular.forEach($scope.tableParams.data, function(order) {
  2007. if(order.$selected == true) {
  2008. if(str != null && str != '') str += ',';
  2009. str += order.id;
  2010. }
  2011. });
  2012. if(str != null && str != '') {
  2013. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2014. $scope.tableParams.reload();
  2015. }, function() {
  2016. toaster.pop('error', '错误', "设置失败");
  2017. });
  2018. }
  2019. }
  2020. };
  2021. }]);
  2022. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  2023. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  2024. BaseService.scrollBackToTop();
  2025. $scope.active = 'todo';
  2026. $scope.dateZoneText = '不限';
  2027. $scope.deliveryZoneText = '不限';
  2028. $scope.condition = {dateZone: -1, deliveryZone: -1};
  2029. $scope.changeDateZone = function(zone) {
  2030. $scope.condition.dateZone = zone;
  2031. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  2032. $scope.condition.$dateZoneOpen = false;
  2033. getDateCondition(zone, $scope.condition);
  2034. $scope.tableParams.reload();
  2035. };
  2036. $scope.changeDeliveryZone = function(zone) {
  2037. $scope.condition.deliveryZoneText = zone;
  2038. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2039. $scope.condition.$delievryZoneOpen = false;
  2040. getDelveryCondition(zone, $scope.condition);
  2041. $scope.tableParams.reload();
  2042. };
  2043. // 切换单据类型
  2044. $scope.setActive = function(state) {
  2045. if($scope.active != state) {
  2046. $scope.active = state;
  2047. if($scope.tableParams.page() == 1)
  2048. $scope.tableParams.reload();
  2049. else
  2050. $scope.tableParams.page(1);
  2051. }
  2052. };
  2053. // 切换数据来源(正常数据 or 历史数据)
  2054. var getService = function() {
  2055. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  2056. };
  2057. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2058. page : 1,
  2059. count : 5,
  2060. sorting: {
  2061. display: 'desc',
  2062. date: 'desc',
  2063. id: 'desc'
  2064. }
  2065. }, {
  2066. total : 0,
  2067. counts: [5, 10, 15, 25, 50],
  2068. getData : function($defer, params) { // 获取数据的方法
  2069. $scope.loading = true;
  2070. var pageParams = params.url();
  2071. pageParams.searchFilter = { // 筛选条件
  2072. keyword: $scope.keyword,
  2073. fromDate: getDateTime($scope.condition.dateFrom),
  2074. endDate: getDateTime($scope.condition.dateTo)
  2075. };
  2076. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2077. $scope.loading = false;
  2078. if(page) {
  2079. $defer.resolve(page.content);
  2080. params.total(page.totalElement);
  2081. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2082. }
  2083. }, function(response){
  2084. $scope.loading = false;
  2085. toaster.pop('error', '数据加载失败', response.data);
  2086. });
  2087. }
  2088. });
  2089. $scope.getOrderTotal = function(items) {
  2090. var sum = 0;
  2091. angular.forEach(items, function(item){
  2092. sum += item.qty * item.price;
  2093. });
  2094. return sum;
  2095. };
  2096. $scope.openDatePicker = function($event, item, openParam) {
  2097. $event.preventDefault();
  2098. $event.stopPropagation();
  2099. item[openParam] = !item[openParam];
  2100. };
  2101. $scope.parseDate = function(dateStr) {
  2102. if(dateStr)
  2103. return Date.parse(dateStr, 'yyyy-MM-dd');
  2104. return new Date();
  2105. };
  2106. $scope.onReplyClick = function(item, inverse) {
  2107. if(item.reply) {
  2108. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2109. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2110. return;
  2111. }
  2112. var reply = angular.copy(item.reply);
  2113. if(reply.delivery) {
  2114. if(typeof reply.delivery == 'object')
  2115. reply.delivery = reply.delivery.getTime();
  2116. } else {
  2117. reply.delivery = item.delivery;
  2118. }
  2119. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2120. $scope.loading = true;
  2121. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2122. $scope.loading = false;
  2123. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2124. $scope.tableParams.reload();
  2125. }, function(response){
  2126. $scope.loading = false;
  2127. toaster.pop('error', '回复失败', response.data);
  2128. });
  2129. }
  2130. };
  2131. //打印 采购单
  2132. $scope.print = function(order) {
  2133. PurcOrder.printCount({id: order.id},{});//增加打印此次 // 在此方法内添加记录日志
  2134. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  2135. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2136. };
  2137. $scope.getReply = function(item) {
  2138. if(!item.replies) {
  2139. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2140. item.replies = replies;
  2141. });
  2142. }
  2143. };
  2144. $scope.checkboxes = {
  2145. checked : false
  2146. };
  2147. // 点击勾选全部的复选框
  2148. $scope.checkAll = function(){
  2149. angular.forEach($scope.tableParams.data, function(item) {
  2150. item.$selected = $scope.checkboxes.checked;
  2151. });
  2152. };
  2153. // 点击其中一个明细的复选框
  2154. $scope.checkOne = function(order){
  2155. var result = true;
  2156. angular.forEach($scope.tableParams.data, function(item) {
  2157. if(item.$selected != true){
  2158. result = false;
  2159. return;
  2160. }
  2161. });
  2162. $scope.checkboxes.checked = result;
  2163. };
  2164. //批量回复采购订单
  2165. $scope.replyByBatch = function() {
  2166. $scope.loading = true;
  2167. var str = '';
  2168. angular.forEach($scope.tableParams.data, function(order) {
  2169. if(order.$selected == true) {
  2170. angular.forEach(order.orderItems, function(item){
  2171. str += item.id;
  2172. str += ',';
  2173. });
  2174. }
  2175. });
  2176. if(!(str == '')) {
  2177. str = str.substr(0, str.length-1);
  2178. PurcOrderItem.replyByBatch(str, function(){
  2179. $scope.loading = false;
  2180. $scope.tableParams.reload();
  2181. toaster.pop('success', '提示', '批量回复成功');
  2182. }, function(data){
  2183. $scope.loading = false;
  2184. toaster.pop('error', '批量回复失败', data);
  2185. });
  2186. } else {//没有勾选其中的明细
  2187. $scope.loading = false;
  2188. }
  2189. };
  2190. // 搜索框回车
  2191. $scope.onSearch = function() {
  2192. $scope.tableParams.page(1);
  2193. $scope.tableParams.reload();
  2194. };
  2195. // 选择查找日期
  2196. $scope.onDateCondition = function(){
  2197. $scope.tableParams.page(1);
  2198. $scope.tableParams.reload();
  2199. };
  2200. //设置为已查看
  2201. $scope.setDisplay = function(state, orderId) {
  2202. if(orderId) {//设置单个
  2203. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2204. $scope.tableParams.reload();
  2205. }, function() {
  2206. toaster.pop('error', '错误', "设置失败");
  2207. });
  2208. } else {//设置已勾选的
  2209. var str = null;
  2210. angular.forEach($scope.tableParams.data, function(order) {
  2211. if(order.$selected == true) {
  2212. if(str != null && str != '') str += ',';
  2213. str += order.id;
  2214. }
  2215. });
  2216. if(str != null && str != '') {
  2217. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2218. $scope.tableParams.reload();
  2219. }, function() {
  2220. toaster.pop('error', '错误', "设置失败");
  2221. });
  2222. }
  2223. }
  2224. };
  2225. }]);
  2226. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  2227. var loadData = function() {
  2228. PurcOrder.get({id: $stateParams.id}, function(data){
  2229. $scope.order = data;
  2230. var sum = 0;
  2231. angular.forEach($scope.order.orderItems, function(item){
  2232. sum += item.qty * item.price;
  2233. });
  2234. $scope.order.total = sum;
  2235. if($scope.order.display == 1) {//未查看的设为已查看
  2236. $scope.setDisplay('setRead', $scope.order.id);
  2237. }
  2238. $scope.loading = false;
  2239. });
  2240. };
  2241. loadData();
  2242. $scope.getReply = function(item) {
  2243. if(!item.replies) {
  2244. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  2245. item.replies = replies;
  2246. });
  2247. }
  2248. };
  2249. $scope.openDatePicker = function($event, item, openParam) {
  2250. $event.preventDefault();
  2251. $event.stopPropagation();
  2252. item[openParam] = !item[openParam];
  2253. };
  2254. $scope.onReplyClick = function(item, inverse) {
  2255. if(item.reply) {
  2256. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2257. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2258. return;
  2259. }
  2260. var reply = angular.copy(item.reply);
  2261. if(reply.delivery) {
  2262. if(typeof reply.delivery == 'object')
  2263. reply.delivery = reply.delivery.getTime();
  2264. } else {
  2265. reply.delivery = item.delivery;
  2266. }
  2267. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2268. $scope.loading = true;
  2269. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  2270. $scope.loading = false;
  2271. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  2272. loadData();
  2273. }, function(response){
  2274. $scope.loading = false;
  2275. toaster.pop('error', '回复失败', response.data);
  2276. });
  2277. }
  2278. };
  2279. // 采购单
  2280. $scope.print = function(order) {
  2281. PurcOrder.printCount({id: order.id},{});//增加打印此次
  2282. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2283. };
  2284. //设置为已查看
  2285. $scope.setDisplay = function(state, orderId) {
  2286. if(orderId) {//设置单个
  2287. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  2288. $scope.tableParams.reload();
  2289. }, function() {
  2290. toaster.pop('error', '错误', "设置失败");
  2291. });
  2292. } else {//设置已勾选的
  2293. var str = null;
  2294. angular.forEach($scope.tableParams.data, function(order) {
  2295. if(order.$selected == true) {
  2296. if(str != null && str != '') str += ',';
  2297. str += order.id;
  2298. }
  2299. });
  2300. if(str != null && str != '') {
  2301. PurcOrder[state].call({}, {ids: '' + str}, function(){
  2302. $scope.tableParams.reload();
  2303. }, function() {
  2304. toaster.pop('error', '错误', "设置失败");
  2305. });
  2306. }
  2307. }
  2308. };
  2309. }]);
  2310. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  2311. BaseService.scrollBackToTop();
  2312. $scope.active = 'todo';
  2313. $scope.agreedText = '全部';
  2314. $scope.dateZoneText = '一个月内';
  2315. $scope.condition = {dateZone: 1};
  2316. $scope.changeAgreed = function(agreed) {
  2317. $scope.condition.agreed = agreed;
  2318. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2319. $scope.condition.$agreedOpen = false;
  2320. };
  2321. $scope.changeDateZone = function(zone) {
  2322. $scope.condition.dateZone = zone;
  2323. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2324. $scope.condition.$dateZoneOpen = false;
  2325. };
  2326. $scope.setActive = function(state) {
  2327. if($scope.active != state) {
  2328. $scope.active = state;
  2329. if($scope.tableParams.page() == 1)
  2330. $scope.tableParams.reload();
  2331. else
  2332. $scope.tableParams.page(1);
  2333. }
  2334. };
  2335. var getService = function() {
  2336. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  2337. };
  2338. $scope.tableParams = new ngTableParams({
  2339. page : 1,
  2340. count : 5,
  2341. sorting: {
  2342. date: 'desc'
  2343. }
  2344. }, {
  2345. total : 0,
  2346. counts: [5, 10, 25, 50],
  2347. getData : function($defer, params) {
  2348. $scope.loading = true;
  2349. var pageParams = params.url();
  2350. pageParams.keyword = $scope.keyword;
  2351. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2352. $scope.loading = false;
  2353. if(page) {
  2354. params.total(page.totalElement);
  2355. $defer.resolve(page.content);
  2356. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2357. }
  2358. }, function(response){
  2359. $scope.loading = false;
  2360. toaster.pop('error', '数据加载失败', response.data);
  2361. });
  2362. }
  2363. });
  2364. $scope.openDatePicker = function($event, item, openParam) {
  2365. $event.preventDefault();
  2366. $event.stopPropagation();
  2367. item[openParam] = !item[openParam];
  2368. };
  2369. $scope.onReplyClick = function(change) {
  2370. if(change.$agreed) {
  2371. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2372. $scope.loading = true;
  2373. PurcChange.reply({changeId: change.id}, reply, function(){
  2374. $scope.loading = false;
  2375. toaster.pop('info', '提示', '回复成功');
  2376. $scope.tableParams.reload();
  2377. }, function(response){
  2378. $scope.loading = false;
  2379. toaster.pop('error', '回复失败', response.data);
  2380. });
  2381. }
  2382. };
  2383. // 搜索框回车
  2384. $scope.onSearch = function() {
  2385. $scope.tableParams.page(1);
  2386. $scope.tableParams.reload();
  2387. };
  2388. }]);
  2389. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  2390. var loadData = function() {
  2391. PurcChange.get({id: $stateParams.id}, function(data){
  2392. $scope.change = data;
  2393. });
  2394. };
  2395. loadData();
  2396. $scope.openDatePicker = function($event, item, openParam) {
  2397. $event.preventDefault();
  2398. $event.stopPropagation();
  2399. item[openParam] = !item[openParam];
  2400. };
  2401. $scope.onReplyClick = function(change) {
  2402. if(change.$agreed) {
  2403. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  2404. PurcChange.reply({changeId: change.id}, reply, function(){
  2405. toaster.pop('info', '提示', '回复成功');
  2406. loadData();
  2407. }, function(response){
  2408. toaster.pop('error', '回复失败', response.data);
  2409. });
  2410. }
  2411. };
  2412. }]);
  2413. //采购询价
  2414. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  2415. BaseService.scrollBackToTop();
  2416. $scope.active = 'todo';
  2417. $scope.agreedText = '全部';
  2418. $scope.dateZoneText = '一个月内';
  2419. $scope.condition = {dateZone: 1};
  2420. $scope.changeAgreed = function(agreed) {
  2421. $scope.condition.agreed = agreed;
  2422. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2423. $scope.condition.$agreedOpen = false;
  2424. };
  2425. $scope.changeDateZone = function(zone) {
  2426. $scope.condition.dateZone = zone;
  2427. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2428. $scope.condition.$dateZoneOpen = false;
  2429. };
  2430. $scope.setActive = function(state) {
  2431. if($scope.active != state) {
  2432. $scope.active = state;
  2433. if($scope.tableParams.page() == 1)
  2434. $scope.tableParams.reload();
  2435. else
  2436. $scope.tableParams.page(1);
  2437. }
  2438. };
  2439. // 得到消息
  2440. PurcInquiry.getMessage({}, function(data){
  2441. console.log(data);
  2442. $scope.message = data;
  2443. }, function(response) {
  2444. });
  2445. var getService = function() {
  2446. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  2447. };
  2448. $scope.tableParams = new ngTableParams({
  2449. page : 1,
  2450. count : 5,
  2451. sorting: {
  2452. 'inquiry.date': 'desc',
  2453. 'inquiry.enterprise.enName': 'asc',
  2454. 'inquiry.code': 'asc'
  2455. }
  2456. }, {
  2457. total : 0,
  2458. counts: [5, 10, 25, 50],
  2459. getData : function($defer, params) {
  2460. $scope.loading = true;
  2461. var pageParams = params.url();
  2462. var realActive = {};
  2463. pageParams.keyword = $scope.keyword;
  2464. if ($scope.active == 'overdue') {
  2465. $scope.active = 'end';
  2466. }
  2467. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2468. $scope.loading = false;
  2469. if(page) {
  2470. params.total(page.totalElement);
  2471. $defer.resolve(page.content);
  2472. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2473. }
  2474. }, function(response){
  2475. $scope.loading = false;
  2476. toaster.pop('error', '数据加载失败', response.data);
  2477. });
  2478. }
  2479. });
  2480. $scope.getMinDate = function(item) {
  2481. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2482. };
  2483. $scope.replyPrices = [];
  2484. $scope.replylapQtys = [];
  2485. $scope.replyPrices.push(true);
  2486. $scope.replylapQtys.push(true);
  2487. $scope.addStep = function(inquiryItem) {
  2488. $scope.replyPrices.push(true);
  2489. if(inquiryItem.replies.length >= 10) {
  2490. toaster.pop('warning', '提示', '最多支持10个分段!');
  2491. } else {
  2492. inquiryItem.replies.push({});
  2493. if(inquiryItem.replies.length != 1) {
  2494. $scope.replyPrices.push(true);
  2495. $scope.replylapQtys.push(true);
  2496. }
  2497. }
  2498. };
  2499. $scope.removeStep = function(inquiryItem, stepIndex) {
  2500. inquiryItem.replies.splice(stepIndex, 1);
  2501. $scope.replyPrices.splice(stepIndex, 1);
  2502. $scope.replylapQtys.splice(stepIndex, 1);
  2503. };
  2504. $scope.openDatePicker = function($event, item, openParam) {
  2505. $event.preventDefault();
  2506. $event.stopPropagation();
  2507. item[openParam] = !item[openParam];
  2508. };
  2509. $scope.getHistory = function(item) {
  2510. if(!item.history) {
  2511. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2512. item.history = data;
  2513. });
  2514. }
  2515. };
  2516. $scope.isValid = function(item, withSteps) {
  2517. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2518. if(!withSteps || !bool)
  2519. return bool;
  2520. angular.forEach(item.replies, function(r, i){
  2521. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2522. });
  2523. return bool;
  2524. };
  2525. $scope.onReplyClick = function(item, withSteps) {
  2526. if(item.vendFromDate instanceof Date) {
  2527. item.vendFromDate = item.vendFromDate.getTime();
  2528. }
  2529. if(item.vendToDate instanceof Date) {
  2530. item.vendToDate = item.vendToDate.getTime();
  2531. }
  2532. if(item.vendFromDate > item.vendToDate) {
  2533. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2534. return;
  2535. }
  2536. var replies = [];
  2537. angular.forEach(item.replies, function(r, i){
  2538. if((i > 0 ? r.lapQty : 1) || r.price)
  2539. replies.push(r);
  2540. });
  2541. item.replies = replies;
  2542. $scope.loading = true;
  2543. if(withSteps) {
  2544. PurcInquiry.reply({itemId: item.id}, item, function(){
  2545. $scope.loading = false;
  2546. toaster.pop('info', '提示', '报价成功');
  2547. $scope.tableParams.reload();
  2548. }, function(response){
  2549. $scope.loading = false;
  2550. toaster.pop('error', '报价失败', response.data);
  2551. });
  2552. } else {
  2553. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  2554. $scope.loading = false;
  2555. toaster.pop('info', '提示', '保存成功');
  2556. $scope.tableParams.reload();
  2557. }, function(response){
  2558. $scope.loading = false;
  2559. toaster.pop('error', '保存失败', response.data);
  2560. });
  2561. }
  2562. };
  2563. $scope.verifylapQty = function(value,type) {
  2564. var regex = /^\d+(.\d{1,5})?$/;
  2565. $scope.replylapQtys[type] = regex.test(value);
  2566. }
  2567. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  2568. $scope.verify = function(value,type) {
  2569. var regex = /^\d+(.\d{1,5})?$/;//
  2570. switch(type) {
  2571. case 'minOrderQty':
  2572. $scope.minOrderQtyVerify = regex.test(value);
  2573. break;
  2574. case 'minPackQty':
  2575. $scope.minPackQtyVerify = regex.test(value);
  2576. break;
  2577. case 'leadtime':
  2578. $scope.leadtimeVerify = regex.test(value);
  2579. break;
  2580. default:
  2581. $scope.replyPrices[type] = regex.test(value);
  2582. break;
  2583. }
  2584. }
  2585. // 搜索框回车
  2586. $scope.onSearch = function() {
  2587. $scope.tableParams.page(1);
  2588. $scope.tableParams.reload();
  2589. };
  2590. }]);
  2591. // 询价单明细
  2592. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  2593. var loadData = function() {
  2594. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  2595. $scope.newinquiryItems = data;
  2596. var inquiry = data[0].inquiry;
  2597. //inquiry.inquiryItems = data;
  2598. angular.forEach(inquiry.attachs, function(attach){
  2599. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  2600. });
  2601. $scope.inquiry = inquiry;
  2602. });
  2603. };
  2604. loadData();
  2605. $scope.getMinDate = function(item) {
  2606. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  2607. };
  2608. $scope.addStep = function(inquiryItem) {
  2609. if(inquiryItem.replies.length >= 10) {
  2610. toaster.pop('warning', '提示', '最多支持10个分段!');
  2611. } else
  2612. inquiryItem.replies.push({});
  2613. };
  2614. $scope.removeStep = function(inquiryItem, stepIndex) {
  2615. inquiryItem.replies.splice(stepIndex, 1);
  2616. };
  2617. $scope.openDatePicker = function($event, item, openParam) {
  2618. $event.preventDefault();
  2619. $event.stopPropagation();
  2620. item[openParam] = !item[openParam];
  2621. };
  2622. $scope.getHistory = function(item) {
  2623. if(!item.history) {
  2624. PurcInquiry.getHistory({itemId: item.id}, function(data){
  2625. item.history = data;
  2626. });
  2627. }
  2628. };
  2629. $scope.isValid = function(item, withSteps) {
  2630. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  2631. if(!withSteps || !bool)
  2632. return bool;
  2633. angular.forEach(item.replies, function(r, i){
  2634. bool = (i > 0 ? r.lapQty : 1) && r.price;
  2635. });
  2636. return bool;
  2637. };
  2638. $scope.onReplyClick = function(item, withSteps) {
  2639. if(item.vendFromDate instanceof Date) {
  2640. item.vendFromDate = item.vendFromDate.getTime();
  2641. }
  2642. if(item.vendToDate instanceof Date) {
  2643. item.vendToDate = item.vendToDate.getTime();
  2644. }
  2645. if(item.vendFromDate > item.vendToDate) {
  2646. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  2647. return;
  2648. }
  2649. var replies = [];
  2650. angular.forEach(item.replies, function(r, i){
  2651. if((i > 0 ? r.lapQty : 1) || r.price)
  2652. replies.push(r);
  2653. });
  2654. item.replies = replies;
  2655. if(withSteps) {
  2656. PurcInquiry.reply({itemId: item.id}, item, function(){
  2657. toaster.pop('info', '提示', '报价成功');
  2658. loadData();
  2659. }, function(response){
  2660. toaster.pop('error', '报价失败', response.data);
  2661. });
  2662. }
  2663. };
  2664. }]);
  2665. // 平台新增的询价单
  2666. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', '$http', 'ShipAddress', function($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout, $http, ShipAddress) {
  2667. BaseService.scrollBackToTop();
  2668. $scope.status = 'InquiryNew';
  2669. $scope.active = 'all';
  2670. $rootScope.tenderVendor = null;// 清除掉已选择的
  2671. var getService = function() {
  2672. return GetProductInfo;
  2673. };
  2674. $scope.inquiry = {
  2675. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  2676. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  2677. priceType: '采购',
  2678. isOpen: 1,
  2679. invoice: 0
  2680. };
  2681. // 获取收货地址列表
  2682. var loadShipAddress = function() {
  2683. ShipAddress.shipAddList({}, function(data) {
  2684. $scope.ships = data;
  2685. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  2686. });
  2687. };
  2688. loadShipAddress();
  2689. // 获取地址信息
  2690. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  2691. }).then(function(response) {
  2692. $scope.provinces = response.data;
  2693. });
  2694. // 新增收货地址保存
  2695. $scope.saveShipAddress = function(ship) {
  2696. ship.address = ship.province + ship.city + ship.district;
  2697. ShipAddress.saveAddress( {}, ship, function(data) {
  2698. if(data.success) {
  2699. // 获取收货地址列表
  2700. loadShipAddress();
  2701. toaster.pop('success', '提示', data.success);
  2702. }
  2703. if(data.error) {
  2704. toaster.pop('error', '提示', data.error);
  2705. }
  2706. });
  2707. };
  2708. $scope.currentDay = function() {
  2709. return $filter('date')(new Date(), 'yyyy-MM-dd');
  2710. };
  2711. $scope.vendors = [];
  2712. // 查找供应商
  2713. $scope.dbfindVendor = function(){
  2714. var modalInstance = $modal.open({
  2715. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  2716. controller: 'DbfindVendorCtrl',
  2717. size: 'lg',
  2718. resolve: {
  2719. }
  2720. });
  2721. modalInstance.result.then(function(data){
  2722. var ifPush = true;
  2723. modalInstance.result.then(function(data){
  2724. angular.forEach(data, function(vendor) {
  2725. if (!$scope.vendors) {// 不存在就先创建
  2726. $scope.vendors = [{}];
  2727. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  2728. } else {
  2729. for (var i = 0;i<$scope.vendors.length; i++) {
  2730. ifPush = true;
  2731. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  2732. ifPush = false;
  2733. break; // 判定到已存在供应商,就终止循环。
  2734. }
  2735. }
  2736. if (ifPush) {
  2737. $scope.vendors.push({enName: vendor.vendorEnterprise.enName, enuu: vendor.vendorEnterprise.uu});
  2738. }
  2739. }
  2740. });
  2741. $rootScope.tenderVendor = $scope.vendors;
  2742. }, function(){
  2743. });
  2744. }, function(){
  2745. });
  2746. };
  2747. // 删除一个供应商
  2748. $scope.removeVendor = function(index) {
  2749. $scope.vendors.splice(index, 1);
  2750. };
  2751. // 物料信息
  2752. $scope.tableParams = new ngTableParams({
  2753. page : 1,
  2754. count : 5,
  2755. sorting: {
  2756. }
  2757. }, {
  2758. total : 0,
  2759. counts: [5, 10, 25, 50],
  2760. getData : function($defer, params) {
  2761. $scope.loading = true;
  2762. var pageParams = params.url();
  2763. pageParams.keyword = $scope.keyword;
  2764. $scope.tip = $scope.keyword;
  2765. pageParams.searchFilter = $scope.searchFilter;
  2766. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2767. $scope.loading = false;
  2768. if(page) {
  2769. params.total(page.totalElement);
  2770. $scope.total = page.totalElement;
  2771. $defer.resolve(page.content);
  2772. }
  2773. }, function(response) {
  2774. $scope.loading = false;
  2775. toaster.pop('error', '数据加载失败', response.data);
  2776. });
  2777. }
  2778. });
  2779. // 搜索框回车
  2780. $scope.onSearch = function(keyword) {
  2781. $scope.tableParams.page(1);
  2782. $scope.tableParams.reload();
  2783. };
  2784. $scope.inquiry.inquiryItems = [];
  2785. //删除商品
  2786. $scope.del = function(index) {
  2787. $scope.inquiry.inquiryItems.splice(index, 1);
  2788. };
  2789. $scope.check = function(product) {
  2790. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  2791. currency: null, toDate: null, productId: product.id});
  2792. }
  2793. $scope.getMinDate = function(item) {
  2794. return $filter('date')(new Date, 'yyyy-MM-dd');
  2795. };
  2796. $scope.openDatePicker = function($event, openParam, index) {
  2797. $event.preventDefault();
  2798. $event.stopPropagation();
  2799. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  2800. };
  2801. $scope.openEndDatePicker = function($event, item, openParam) {
  2802. $event.preventDefault();
  2803. $event.stopPropagation();
  2804. item[openParam] = !item[openParam];
  2805. };
  2806. // 保存
  2807. $scope.save = function() {
  2808. // var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  2809. // $upload.upload({
  2810. // url: 'product/baseInfo/updateProdInfo',
  2811. // file: file,
  2812. // method: 'POST',
  2813. // data: {
  2814. // prodInfo: $scope.prodInfo
  2815. // },
  2816. // }).success(function(data) {
  2817. // if(data.success) {
  2818. // toaster.pop('success', '提示', data.success);
  2819. // window.location.reload();
  2820. // }
  2821. // if(data.error) {
  2822. // toaster.pop('error', '提示', data.error);
  2823. // }
  2824. // }).error(function(data) {
  2825. // $scope.loadingShow = false;
  2826. // toaster.pop('error', '操作失败', data.error);
  2827. // });
  2828. if( $scope.inquiry.isOpen == 0) { // 指定询价
  2829. if( $scope.vendors.length > 0) {
  2830. PurchaseInquiry.save({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  2831. if(data.success) {
  2832. toaster.pop('success', '提示', data.success);
  2833. $timeout(function() {
  2834. window.location.hash = "#/purc/inquiry_unapply";
  2835. }, 500);
  2836. }
  2837. if(data.error) {
  2838. toaster.pop('error', '提示', data.error);
  2839. }
  2840. }, function(response) {
  2841. toaster.pop('error', '提示', response.data);
  2842. });
  2843. } else {
  2844. toaster.pop('info', '提示', '请先选择供应商');
  2845. }
  2846. } else {
  2847. PurchaseInquiry.saveWithoutVendor({inquiry: $scope.inquiry}, {}, function(data) {
  2848. if(data.success) {
  2849. toaster.pop('success', '提示', data.success);
  2850. $timeout(function() {
  2851. window.location.hash = "#/purc/inquiry_unapply";
  2852. }, 500);
  2853. }
  2854. if(data.error) {
  2855. toaster.pop('error', '提示', data.error);
  2856. }
  2857. }, function(response) {
  2858. toaster.pop('error', '提示', response.data);
  2859. });
  2860. }
  2861. }
  2862. // 保存并提交
  2863. $scope.submit = function() {
  2864. if( $scope.inquiry.isOpen == 0) { // 指定询价
  2865. if($scope.vendors.length > 0) {
  2866. PurchaseInquiry.submit({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  2867. if(data.success) {
  2868. toaster.pop('success', '提示', data.success);
  2869. $timeout(function() {
  2870. window.location.hash = "#/purc/purchaseinquiry";
  2871. }, 500);
  2872. }
  2873. if(data.error) {
  2874. toaster.pop('error', '提示', data.error);
  2875. }
  2876. }, function(response) {
  2877. toaster.pop('error', '提示', response.data);
  2878. });
  2879. } else {
  2880. toaster.pop('info', '提示', '请先选择供应商');
  2881. }
  2882. } else {
  2883. PurchaseInquiry.saveAndSubmitWithoutVendor({inquiry: $scope.inquiry}, {}, function(data) {
  2884. if(data.success) {
  2885. toaster.pop('success', '提示', data.success);
  2886. $timeout(function() {
  2887. window.location.hash = "#/purc/purchaseinquiry";
  2888. }, 500);
  2889. }
  2890. if(data.error) {
  2891. toaster.pop('error', '提示', data.error);
  2892. }
  2893. }, function(response) {
  2894. toaster.pop('error', '提示', response.data);
  2895. });
  2896. }
  2897. }
  2898. }]);
  2899. // 平台询价单(已提交)
  2900. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', function($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry) {
  2901. $scope.status = 'InquirySubmit';
  2902. BaseService.scrollBackToTop();
  2903. $scope.active = 'todo';
  2904. $scope.agreedText = '全部';
  2905. $scope.dateZoneText = '一个月内';
  2906. $scope.condition = {dateZone: 1};
  2907. $scope.changeAgreed = function(agreed) {
  2908. $scope.condition.agreed = agreed;
  2909. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  2910. $scope.condition.$agreedOpen = false;
  2911. };
  2912. $scope.changeDateZone = function(zone) {
  2913. $scope.condition.dateZone = zone;
  2914. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2915. $scope.condition.$dateZoneOpen = false;
  2916. };
  2917. $scope.setActive = function(state) {
  2918. if($scope.active != state ) {
  2919. $scope.active = state;
  2920. if ($scope.tableParams.page() == 1) {
  2921. $scope.tableParams.reload();
  2922. } else {
  2923. $scope.tableParams.page(1);
  2924. }
  2925. }
  2926. }
  2927. var getService = function() {
  2928. return PurchaseInquiry;
  2929. };
  2930. $scope.tableParams = new ngTableParams({
  2931. page : 1,
  2932. count : 5,
  2933. sorting: {
  2934. 'inquiry.date': 'desc',
  2935. 'inquiry.enterprise.enName': 'asc',
  2936. 'inquiry.code': 'asc'
  2937. }
  2938. }, {
  2939. total : 0,
  2940. counts: [5, 10, 25, 50],
  2941. getData : function($defer, params) {
  2942. $scope.loading = true;
  2943. var pageParams = params.url();
  2944. var realActive = {};
  2945. pageParams.keyword = $scope.keyword;
  2946. if ($scope.active == 'overdue') {
  2947. $scope.active = 'end';
  2948. }
  2949. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2950. $scope.loading = false;
  2951. if(page) {
  2952. params.total(page.totalElement);
  2953. $defer.resolve(page.content);
  2954. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2955. }
  2956. }, function(response){
  2957. $scope.loading = false;
  2958. toaster.pop('error', '数据加载失败', response.data);
  2959. });
  2960. }
  2961. });
  2962. $scope.openDatePicker = function($event, item, openParam) {
  2963. $event.preventDefault();
  2964. $event.stopPropagation();
  2965. item[openParam] = !item[openParam];
  2966. };
  2967. // 搜索框回车
  2968. $scope.onSearch = function() {
  2969. $scope.tableParams.page(1);
  2970. $scope.tableParams.reload();
  2971. };
  2972. // 采纳
  2973. $scope.accept = function(id) {
  2974. PurchaseInquiry.accept({id: id}, {}, function(data) {
  2975. if(data.success) {
  2976. toaster.pop('success', '提示', data.success);
  2977. $scope.tableParams.reload();
  2978. }
  2979. if(data.error) {
  2980. toaster.pop('error', '提示', data.error);
  2981. }
  2982. }, function(response) {
  2983. toaster.pop('error', '提示', response.data);
  2984. })
  2985. };
  2986. // 拒绝
  2987. $scope.refuse = function(id) {
  2988. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  2989. if(data.success) {
  2990. toaster.pop('success', '提示', data.success);
  2991. $scope.tableParams.reload();
  2992. }
  2993. if(data.error) {
  2994. toaster.pop('error', '提示', data.error);
  2995. }
  2996. }, function(response) {
  2997. toaster.pop('error', '提示', response.data);
  2998. })
  2999. }
  3000. }]);
  3001. // 平台询价单(未提交)
  3002. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', function($scope, PurchaseInquiry, ngTableParams, BaseService, toaster) {
  3003. BaseService.scrollBackToTop();
  3004. $scope.status = 'InquiryUnSubmit';
  3005. $scope.tableParams = new ngTableParams({
  3006. page : 1,
  3007. count : 5,
  3008. sorting: {
  3009. 'inquiry.date': 'desc',
  3010. 'inquiry.enterprise.enName': 'asc',
  3011. 'inquiry.code': 'asc'
  3012. }
  3013. }, {
  3014. total : 0,
  3015. counts: [5, 10, 25, 50],
  3016. getData : function($defer, params) {
  3017. $scope.loading = true;
  3018. var pageParams = params.url();
  3019. var realActive = {};
  3020. if ($scope.active == 'overdue') {
  3021. $scope.active = 'end';
  3022. }
  3023. PurchaseInquiry.getUnapply(null, BaseService.parseParams(pageParams), function(page){
  3024. $scope.loading = false;
  3025. if(page) {
  3026. params.total(page.totalElements);
  3027. $defer.resolve(page.content);
  3028. }
  3029. }, function(response){
  3030. $scope.loading = false;
  3031. toaster.pop('error', '数据加载失败', response.data);
  3032. });
  3033. }
  3034. });
  3035. // 删除明细
  3036. $scope.deleteById = function(id) {
  3037. PurchaseInquiry.deleteById({id: id}, {}, function(data) {
  3038. toaster.pop('success', '提示', '删除成功');
  3039. $scope.tableParams.reload();
  3040. }, function(response) {
  3041. toaster.pop('error', '提示', response.data);
  3042. });
  3043. }
  3044. // 删除主表
  3045. $scope.clearOrder = function(id) {
  3046. PurchaseInquiry.clearOrder({id: id}, {}, function(data) {
  3047. toaster.pop('success', '提示', '删除成功');
  3048. $scope.tableParams.reload();
  3049. }, function(response) {
  3050. toaster.pop('error', '提示', response.data);
  3051. });
  3052. }
  3053. // 提交
  3054. $scope.submit = function(id) {
  3055. PurchaseInquiry.submitUnapply({id: id}, {}, function(data) {
  3056. toaster.pop('success', '提示', '单据提交成功');
  3057. }, function(response) {
  3058. toaster.pop('error', '提示', response.data);
  3059. })
  3060. }
  3061. // 发布公共询价
  3062. $scope.publish = function(id) {
  3063. PurchaseInquiry.publishInquiry({id: id}, {}, function(data) {
  3064. toaster.pop('success', '提示', data.success);
  3065. }, function(response) {
  3066. toaster.pop('error', '提示', response.data);
  3067. })
  3068. }
  3069. }]);
  3070. // 公共询价列表
  3071. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams) {
  3072. BaseService.scrollBackToTop();
  3073. /**
  3074. * 改变单据日期范围
  3075. */
  3076. var getTenderDateCondition = function(zone, condition) {
  3077. var date = new Date();
  3078. if(zone == -1) {
  3079. condition.dateFrom = null;
  3080. condition.dateTo = null;
  3081. } else if(zone == 7) { // 一星期内
  3082. date.setDate(date.getDate() - 7);
  3083. condition.dateFrom = date;
  3084. condition.dateTo = new Date();
  3085. } else if(zone == 1) { // 一个月内
  3086. date.setMonth(date.getMonth() - 1);
  3087. condition.dateFrom = date;
  3088. condition.dateTo = new Date();
  3089. } else if(zone == 3) { // 三个月内
  3090. date.setMonth(date.getMonth() - 3);
  3091. condition.dateFrom = date;
  3092. condition.dateTo = new Date();
  3093. } else if (zone == 6) { // 半年内
  3094. date.setMonth(date.getMonth() - 6);
  3095. condition.dateFrom = date;
  3096. condition.dateTo = new Date();
  3097. } else { // 一年内
  3098. date.setYear(date.getYear() - 1);
  3099. condition.dateFrom = date;
  3100. condition.dateTo = new Date();
  3101. }
  3102. };
  3103. $scope.dateZoneText = '不限';
  3104. $scope.deliveryZoneText = '不限';
  3105. $scope.condition = {dateZone: -1};
  3106. $scope.changeDateZone = function(zone) {
  3107. $scope.condition.dateZone = zone;
  3108. $scope.condition.$dateZoneOpen = false;
  3109. getTenderDateCondition(zone, $scope.condition);
  3110. $scope.tableParams.reload();
  3111. };
  3112. $scope.openDatePicker = function($event, item, openParam) {
  3113. $event.preventDefault();
  3114. $event.stopPropagation();
  3115. item[openParam] = !item[openParam];
  3116. };
  3117. $scope.parseDate = function(dateStr) {
  3118. if(dateStr)
  3119. return Date.parse(dateStr, 'yyyy-MM-dd');
  3120. return new Date();
  3121. };
  3122. // 选择查找日期
  3123. $scope.onDateCondition = function(){
  3124. $scope.tableParams.page(1);
  3125. $scope.tableParams.reload();
  3126. };
  3127. // $scope.setActive = function(state) {
  3128. // if($scope.active != state) {
  3129. // $scope.active = state;
  3130. // if($scope.tableParams.page() == 1)
  3131. // $scope.tableParams.reload();
  3132. // else
  3133. // $scope.tableParams.page(1);
  3134. // }
  3135. // };
  3136. $scope.nowdate = new Date().getTime();
  3137. var getOpenState = function(active) {
  3138. var fn = 'getOpenAll';
  3139. switch(active) {
  3140. case 'all':
  3141. fn = 'getOpenAll';break;
  3142. case 'todo':
  3143. fn = 'getOpenTodo';break;
  3144. case 'end':
  3145. fn = 'getOpenEnd';break;
  3146. }
  3147. return fn;
  3148. };
  3149. $scope.tableParams = new ngTableParams({
  3150. page : 1,
  3151. count : 10,
  3152. sorting: {
  3153. // 'tender.endDate': 'desc',
  3154. // 'tender.enterprise.enName': 'asc',
  3155. // 'tender.code': 'asc'
  3156. }
  3157. }, {
  3158. total : 0,
  3159. counts: [10, 25, 50, 100],
  3160. getData : function($defer, params) {
  3161. $scope.loading = true;
  3162. var pageParams = params.url();
  3163. // var realActive = {};
  3164. pageParams.searchFilter = { // 筛选条件
  3165. keyword: $scope.keyword,
  3166. fromDate: getDateTime($scope.condition.dateFrom),
  3167. endDate: getDateTime($scope.condition.dateTo)
  3168. };
  3169. // AccountEnterprise.get({}, function(data){
  3170. // $scope.loading = false;
  3171. // $scope.currentEn = data;
  3172. // });
  3173. PurchaseInquiry.publicInquiryItem.call(null, BaseService.parseParams(pageParams), function(page){
  3174. $scope.loading = false;
  3175. if(page) {
  3176. params.total(page.totalElement);
  3177. $defer.resolve(page.content);
  3178. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  3179. }
  3180. }, function(response){
  3181. $scope.loading = false;
  3182. toaster.pop('error', '数据加载失败', response.data);
  3183. });
  3184. }
  3185. });
  3186. $scope.toDetail = function(id) {
  3187. window.location.hash = '#/baseInfo/inquiryList/' + id;
  3188. };
  3189. // 搜索框回车
  3190. $scope.onSearch = function() {
  3191. $scope.tableParams.page(1);
  3192. $scope.tableParams.reload();
  3193. };
  3194. }]);
  3195. /**
  3196. * 公共询价详情
  3197. */
  3198. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', function($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise) {
  3199. BaseService.scrollBackToTop();
  3200. var loadData = function() {
  3201. PurchaseInquiry.inquiryItemDetail({id: $stateParams.id}, function(data) {
  3202. $scope.inquiryItem = data;
  3203. }, function(response) {
  3204. toaster.pop('error', '提示', response.data);
  3205. });
  3206. }
  3207. loadData();
  3208. // 当前时间
  3209. $scope.nowdate = new Date().getTime();
  3210. // 当前企业
  3211. AccountEnterprise.get({}, function(data){
  3212. $scope.loading = false;
  3213. $scope.enterprise = data;
  3214. });
  3215. // 转客户询价
  3216. $scope.transtoInquiry = function(id) {
  3217. PurchaseInquiry.transtoInquiry({id: id}, {}, function(data) {
  3218. if(data.success) {
  3219. toaster.pop('success', '提示', data.success);
  3220. window.location.hash = "sale/inquiry/" + data.id;
  3221. }
  3222. if(data.error) {
  3223. toaster.pop('error', '提示', data.error);
  3224. }
  3225. if(data.info) {
  3226. toaster.pop('info', '提示', data.info);
  3227. }
  3228. }, function(response) {
  3229. toaster.pop('error', '提示', response.data);
  3230. });
  3231. }
  3232. }]);
  3233. // 询价单明细
  3234. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry','$filter', 'toaster', function($scope, $stateParams, PurcInquiry,$filter, toaster){
  3235. var loadData = function() {
  3236. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  3237. $scope.newinquiryItems = data;
  3238. var inquiry = data[0].inquiry;
  3239. //inquiry.inquiryItems = data;
  3240. angular.forEach(inquiry.attachs, function(attach){
  3241. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3242. });
  3243. $scope.inquiry = inquiry;
  3244. });
  3245. };
  3246. loadData();
  3247. $scope.getMinDate = function(item) {
  3248. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3249. };
  3250. $scope.addStep = function(inquiryItem) {
  3251. if(inquiryItem.replies.length >= 10) {
  3252. toaster.pop('warning', '提示', '最多支持10个分段!');
  3253. } else
  3254. inquiryItem.replies.push({});
  3255. };
  3256. $scope.removeStep = function(inquiryItem, stepIndex) {
  3257. inquiryItem.replies.splice(stepIndex, 1);
  3258. };
  3259. $scope.openDatePicker = function($event, item, openParam) {
  3260. $event.preventDefault();
  3261. $event.stopPropagation();
  3262. item[openParam] = !item[openParam];
  3263. };
  3264. $scope.getHistory = function(item) {
  3265. if(!item.history) {
  3266. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3267. item.history = data;
  3268. });
  3269. }
  3270. };
  3271. $scope.isValid = function(item, withSteps) {
  3272. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3273. if(!withSteps || !bool)
  3274. return bool;
  3275. angular.forEach(item.replies, function(r, i){
  3276. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3277. });
  3278. return bool;
  3279. };
  3280. $scope.onReplyClick = function(item, withSteps) {
  3281. if(item.vendFromDate instanceof Date) {
  3282. item.vendFromDate = item.vendFromDate.getTime();
  3283. }
  3284. if(item.vendToDate instanceof Date) {
  3285. item.vendToDate = item.vendToDate.getTime();
  3286. }
  3287. if(item.vendFromDate > item.vendToDate) {
  3288. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3289. return;
  3290. }
  3291. var replies = [];
  3292. angular.forEach(item.replies, function(r, i){
  3293. if((i > 0 ? r.lapQty : 1) || r.price)
  3294. replies.push(r);
  3295. });
  3296. item.replies = replies;
  3297. if(withSteps) {
  3298. PurcInquiry.reply({itemId: item.id}, item, function(){
  3299. toaster.pop('info', '提示', '报价成功');
  3300. loadData();
  3301. }, function(response){
  3302. toaster.pop('error', '报价失败', response.data);
  3303. });
  3304. }
  3305. };
  3306. }]);
  3307. // 询价单明细(发出)
  3308. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry','$filter', 'toaster', function($scope, $stateParams, PurchaseInquiry,$filter, toaster){
  3309. var loadData = function() {
  3310. PurchaseInquiry.detail({id: $stateParams.id}, function(data){
  3311. $scope.inquiry = data;
  3312. });
  3313. };
  3314. loadData();
  3315. $scope.getMinDate = function(item) {
  3316. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3317. };
  3318. $scope.addStep = function(inquiryItem) {
  3319. if(inquiryItem.replies.length >= 10) {
  3320. toaster.pop('warning', '提示', '最多支持10个分段!');
  3321. } else
  3322. inquiryItem.replies.push({});
  3323. };
  3324. $scope.removeStep = function(inquiryItem, stepIndex) {
  3325. inquiryItem.replies.splice(stepIndex, 1);
  3326. };
  3327. $scope.openDatePicker = function($event, item, openParam) {
  3328. $event.preventDefault();
  3329. $event.stopPropagation();
  3330. item[openParam] = !item[openParam];
  3331. };
  3332. $scope.getHistory = function(item) {
  3333. if(!item.history) {
  3334. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3335. item.history = data;
  3336. });
  3337. }
  3338. };
  3339. $scope.isValid = function(item, withSteps) {
  3340. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3341. if(!withSteps || !bool)
  3342. return bool;
  3343. angular.forEach(item.replies, function(r, i){
  3344. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3345. });
  3346. return bool;
  3347. };
  3348. $scope.onReplyClick = function(item, withSteps) {
  3349. if(item.vendFromDate instanceof Date) {
  3350. item.vendFromDate = item.vendFromDate.getTime();
  3351. }
  3352. if(item.vendToDate instanceof Date) {
  3353. item.vendToDate = item.vendToDate.getTime();
  3354. }
  3355. if(item.vendFromDate > item.vendToDate) {
  3356. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3357. return;
  3358. }
  3359. var replies = [];
  3360. angular.forEach(item.replies, function(r, i){
  3361. if((i > 0 ? r.lapQty : 1) || r.price)
  3362. replies.push(r);
  3363. });
  3364. item.replies = replies;
  3365. if(withSteps) {
  3366. PurcInquiry.reply({itemId: item.id}, item, function(){
  3367. toaster.pop('info', '提示', '报价成功');
  3368. loadData();
  3369. }, function(response){
  3370. toaster.pop('error', '报价失败', response.data);
  3371. });
  3372. }
  3373. };
  3374. // 采纳
  3375. $scope.accept = function(id) {
  3376. PurchaseInquiry.accept({id: id}, {}, function(data) {
  3377. if(data.success) {
  3378. toaster.pop('success', '提示', data.success);
  3379. $scope.tableParams.reload();
  3380. }
  3381. if(data.error) {
  3382. toaster.pop('error', '提示', data.error);
  3383. }
  3384. }, function(response) {
  3385. toaster.pop('error', '提示', response.data);
  3386. })
  3387. };
  3388. // 拒绝
  3389. $scope.refuse = function(id) {
  3390. PurchaseInquiry.refuse({id: id}, {}, function(data) {
  3391. if(data.success) {
  3392. toaster.pop('success', '提示', data.success);
  3393. $scope.tableParams.reload();
  3394. }
  3395. if(data.error) {
  3396. toaster.pop('error', '提示', data.error);
  3397. }
  3398. }, function(response) {
  3399. toaster.pop('error', '提示', response.data);
  3400. })
  3401. }
  3402. }]);
  3403. // 模具询价管理
  3404. app.controller('SaleInquiryMouldCtrl',['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', function($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload){
  3405. BaseService.scrollBackToTop();
  3406. $scope.active = 'todo';
  3407. $scope.agreedText = '全部';
  3408. $scope.dateZoneText = '一个月内';
  3409. $scope.condition = {dateZone: 1};
  3410. var inquiryMould_copy = {};
  3411. $scope.changeAgreed = function(agreed) {
  3412. $scope.condition.agreed = agreed;
  3413. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3414. $scope.condition.$agreedOpen = false;
  3415. };
  3416. $scope.changeDateZone = function(zone) {
  3417. $scope.condition.dateZone = zone;
  3418. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3419. $scope.condition.$dateZoneOpen = false;
  3420. };
  3421. $scope.setActive = function(state) {
  3422. if($scope.active != state ) {
  3423. $scope.active = state;
  3424. if ($scope.tableParams.page() == 1) {
  3425. $scope.tableParams.reload();
  3426. } else {
  3427. $scope.tableParams.page(1);
  3428. }
  3429. }
  3430. }
  3431. var getService = function() {
  3432. return PurcInquiryMould;
  3433. };
  3434. $scope.tableParams = new ngTableParams({
  3435. page: 1,
  3436. count: 5
  3437. },{
  3438. total: 0,
  3439. counts: [5, 10, 25, 50],
  3440. getData: function($defer, params) {
  3441. $scope.loading = true;
  3442. var pageParams = params.url();
  3443. var realActive = {};
  3444. pageParams.keyword = $scope.keyword;
  3445. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3446. $scope.loading = false;
  3447. // 用来验证价格修改
  3448. var mould = page.content;
  3449. inquiryMould_copy = angular.copy(mould);
  3450. if(page) {
  3451. params.total(page.totalElement);
  3452. $defer.resolve(page.content);
  3453. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3454. }
  3455. }, function(response){
  3456. $scope.loading = false;
  3457. toaster.pop('error', '数据加载失败', response.data);
  3458. });
  3459. }
  3460. })
  3461. $scope.getMinDate = function(item) {
  3462. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  3463. };
  3464. $scope.replyPrices = [];
  3465. $scope.replyPrices.push(true);
  3466. // 取消
  3467. $scope.reload = function() {
  3468. $scope.tableParams.reload();
  3469. $scope.canSave = false;
  3470. }
  3471. // 能否保存设置
  3472. $scope.canSave = false;
  3473. // items价格验证
  3474. $scope.verifyItems = function(price, reply) {
  3475. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  3476. if(regex.test(price) && price != 0) {
  3477. if (price != reply) {
  3478. $scope.canSave = true;
  3479. } else {
  3480. $scope.canSave = false;
  3481. }
  3482. } else {
  3483. $scope.canSave = false;
  3484. }
  3485. }
  3486. // prod下prods价格验证
  3487. $scope.verifyProds = function(price, reply) {
  3488. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3489. if(regex.test(price) && price != 0) {
  3490. if (price != reply) {
  3491. $scope.canSave = true;
  3492. } else {
  3493. $scope.canSave = false;
  3494. }
  3495. } else {
  3496. $scope.canSave = false;
  3497. }
  3498. }
  3499. //有价格为0或者不符合正则式,则不能报价
  3500. $scope.notZero = function (mould) {
  3501. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3502. angular.forEach(mould.inquiryMouldItems, function(item){
  3503. if (item.price == 0 || !regex.test(item.price)) {
  3504. $scope.canSave = false;
  3505. }
  3506. angular.forEach(item.inquiryMouldDetails, function(detail){
  3507. if (detail.price == 0 || !regex.test(detail.price)) {
  3508. $scope.canSave = false;
  3509. }
  3510. })
  3511. });
  3512. }
  3513. $scope.blurPrice = function (price) {
  3514. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3515. if (!regex.test(price)) {
  3516. toaster.pop('warning','格式错误','请输入有效价格');
  3517. }
  3518. }
  3519. // 获取历史报价
  3520. $scope.getHistory = function(mould) {
  3521. if(!mould.history) {
  3522. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3523. mould.history = data;
  3524. console.log(mould.history);
  3525. });
  3526. }
  3527. };
  3528. $scope.uploadAttach = function(mould) {
  3529. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3530. var file = mould.attachs[0];
  3531. $scope.mould = mould;
  3532. $upload.upload({
  3533. url: 'sale/mould/' + mould.id + '/send',
  3534. method: 'POST',
  3535. file: file,
  3536. data: {
  3537. json: $scope.mould
  3538. }
  3539. }).success(function(res){
  3540. console.log("success");
  3541. console.log(res);
  3542. }).error(function(res){
  3543. console.log("failure");
  3544. console.log(res);
  3545. });
  3546. }
  3547. // 保存并确认报价
  3548. $scope.onReplyClick = function(mould, withSteps) {
  3549. $scope.loading = true;
  3550. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3551. // var file = mould.attachs[0];
  3552. // $scope.mould = mould;
  3553. // $upload.upload({
  3554. // url: 'sale/mould/' + mould.id + '/send',
  3555. // method: 'POST',
  3556. // file: file,
  3557. // data: {
  3558. // json: $scope.mould
  3559. // }
  3560. // }).success(function(res){
  3561. // console.log("success");
  3562. // console.log(res);
  3563. // }).error(function(res){
  3564. // console.log("failure");
  3565. // });
  3566. if(withSteps) {
  3567. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3568. $scope.loading = false;
  3569. toaster.pop('info', '提示', '报价成功');
  3570. $scope.tableParams.reload();
  3571. $scope.canSave = false;
  3572. }, function(response){
  3573. $scope.loading = false;
  3574. toaster.pop('error', '报价失败', response.data);
  3575. });
  3576. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3577. }, function(response){
  3578. });
  3579. } else {
  3580. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3581. $scope.loading = false;
  3582. toaster.pop('info', '提示', '保存成功');
  3583. $scope.tableParams.reload();
  3584. }, function(response){
  3585. $scope.loading = false;
  3586. toaster.pop('error', '保存失败', response.data);
  3587. });
  3588. }
  3589. };
  3590. // 搜索框回车
  3591. $scope.onSearch = function() {
  3592. $scope.tableParams.page(1);
  3593. $scope.tableParams.reload();
  3594. };
  3595. }]);
  3596. // 模具询价单明细
  3597. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould','$filter', 'toaster','$upload', function($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload){
  3598. var inquiryMould_copy = {};
  3599. var loadData = function() {
  3600. PurcInquiryMould.getAll({id: $stateParams.id}, function(data){
  3601. // 用来验证价格修改
  3602. inquiryMould_copy = angular.copy(data);
  3603. $scope.inquiryMould_copy = inquiryMould_copy;
  3604. $scope.newinquirymould = data;
  3605. var mould = data;
  3606. angular.forEach(mould.attachs, function(attach){
  3607. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  3608. });
  3609. $scope.inquiryMould = mould;
  3610. });
  3611. };
  3612. loadData();
  3613. $scope.getMinDate = function(item) {
  3614. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3615. };
  3616. // 取消
  3617. $scope.reload = function() {
  3618. loadData();
  3619. $scope.canSave = false;
  3620. }
  3621. //有价格为0,则不能报价
  3622. $scope.notZero = function (mould) {
  3623. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3624. angular.forEach(mould.inquiryMouldItems, function(item){
  3625. if (item.price == 0 || !regex.test(item.price)) {
  3626. $scope.canSave = false;
  3627. }
  3628. angular.forEach(item.inquiryMouldDetails, function(detail){
  3629. if (detail.price == 0 || !regex.test(detail.price)) {
  3630. $scope.canSave = false;
  3631. }
  3632. })
  3633. });
  3634. }
  3635. $scope.blurPrice = function (price) {
  3636. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  3637. if (!regex.test(price)) {
  3638. toaster.pop('warning','格式错误','请输入有效价格');
  3639. }
  3640. }
  3641. // 获取历史报价
  3642. $scope.getHistory = function(mould) {
  3643. if(!mould.history) {
  3644. PurcInquiryMould.getHistory({id: mould.id}, function(data){
  3645. mould.history = data;
  3646. console.log(mould.history);
  3647. });
  3648. }
  3649. };
  3650. $scope.canSave = false;
  3651. // items价格验证
  3652. $scope.verifyItems = function(price, index) {
  3653. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3654. if(regex.test(price) && price != 0) {
  3655. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  3656. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  3657. $scope.canSave = true;
  3658. } else {
  3659. $scope.canSave = false;
  3660. }
  3661. } else {
  3662. $scope.canSave = false;
  3663. }
  3664. }
  3665. // prod下prods价格验证
  3666. $scope.verifyProds = function(price, index, parentIndex) {
  3667. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  3668. if(regex.test(price) && price != 0) {
  3669. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  3670. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  3671. $scope.canSave = true;
  3672. } else {
  3673. $scope.canSave = false;
  3674. }
  3675. } else {
  3676. $scope.canSave = false;
  3677. }
  3678. }
  3679. // // 上传附件
  3680. // $scope.uploadAttach = function(mould) {
  3681. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  3682. // var file = mould.attachs[0];
  3683. // $scope.mould = mould;
  3684. // $upload.upload({
  3685. // url: 'sale/mould/' + mould.id + '/send',
  3686. // method: 'POST',
  3687. // file: file,
  3688. // data: {
  3689. // json: $scope.mould
  3690. // }
  3691. // }).success(function(res){
  3692. // console.log("success");
  3693. // console.log(res);
  3694. // }).error(function(res){
  3695. // console.log("failure");
  3696. // console.log(res);
  3697. // });
  3698. // }
  3699. $scope.onReplyClick = function(mould, withSteps) {
  3700. $scope.loading = true;
  3701. // var file = mould.attachs[0];
  3702. // $scope.mould = mould;
  3703. // $upload.upload({
  3704. // url: 'sale/mould/' + mould.id + '/send',
  3705. // method: 'POST',
  3706. // file: file,
  3707. // data: {
  3708. // json: $scope.mould
  3709. // }
  3710. // }).success(function(res){
  3711. //
  3712. // }).error(function(res){
  3713. // console.log(res);
  3714. // });
  3715. if(withSteps) {
  3716. PurcInquiryMould.reply({id: mould.id}, mould, function(){
  3717. $scope.loading = false;
  3718. toaster.pop('info', '提示', '报价成功');
  3719. loadData();
  3720. $scope.canSave = false;
  3721. }, function(response){
  3722. $scope.loading = false;
  3723. toaster.pop('error', '报价失败', response.data);
  3724. });
  3725. PurcInquiryMould.saveHistory({id: mould.id}, mould, function(){
  3726. }, function(response){
  3727. });
  3728. } else {
  3729. PurcInquiryMould.saveItem({id: mould.id}, mould, function(){
  3730. $scope.loading = false;
  3731. toaster.pop('info', '提示', '保存成功');
  3732. loadData();
  3733. }, function(response){
  3734. $scope.loading = false;
  3735. toaster.pop('error', '保存失败', response.data);
  3736. });
  3737. }
  3738. };
  3739. }]);
  3740. // 主动报价 - 列表
  3741. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  3742. BaseService.scrollBackToTop();
  3743. $scope.active = 'todo';
  3744. $scope.agreedText = '全部';
  3745. $scope.dateZoneText = '一个月内';
  3746. $scope.condition = {dateZone: 1};
  3747. $scope.changeDateZone = function(zone) {
  3748. $scope.condition.dateZone = zone;
  3749. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3750. $scope.condition.$dateZoneOpen = false;
  3751. };
  3752. $scope.setActive = function(state) {
  3753. if($scope.active != state) {
  3754. $scope.active = state;
  3755. if($scope.tableParams.page() == 1)
  3756. $scope.tableParams.reload();
  3757. else
  3758. $scope.tableParams.page(1);
  3759. }
  3760. };
  3761. var getService = function() {
  3762. return Quotation;
  3763. };
  3764. $scope.tableParams = new ngTableParams({
  3765. page : 1,
  3766. count : 5,
  3767. sorting: {
  3768. 'quotation.date': 'desc'
  3769. }
  3770. }, {
  3771. total : 0,
  3772. counts: [5, 10, 25, 50],
  3773. getData : function($defer, params) {
  3774. $scope.loading = true;
  3775. var pageParams = params.url();
  3776. pageParams.keyword = $scope.keyword;
  3777. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3778. $scope.loading = false;
  3779. if(page) {
  3780. params.total(page.totalElement);
  3781. $defer.resolve(page.content);
  3782. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3783. }
  3784. }, function(response){
  3785. $scope.loading = false;
  3786. toaster.pop('error', '数据加载失败', response.data);
  3787. });
  3788. }
  3789. });
  3790. $scope.getHistory = function(item) {
  3791. if(!item.history) {
  3792. PurcInquiry.getHistory({itemId: item.id}, function(data){
  3793. item.history = data;
  3794. });
  3795. }
  3796. };
  3797. $scope.isValid = function(item, withSteps) {
  3798. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3799. if(!withSteps || !bool)
  3800. return bool;
  3801. angular.forEach(item.replies, function(r, i){
  3802. bool = (i > 0 ? r.lapQty : 1) && r.price;
  3803. });
  3804. return bool;
  3805. };
  3806. // 搜索框回车
  3807. $scope.onSearch = function() {
  3808. $scope.tableParams.page(1);
  3809. $scope.tableParams.reload();
  3810. };
  3811. }]);
  3812. // Controller 主动报价 - 新增
  3813. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope){
  3814. BaseService.scrollBackToTop();
  3815. var staticItem = null;
  3816. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  3817. $scope.loading = true;
  3818. Quotation.getItem({id: $stateParams.id}, function(data){
  3819. data.$editing = false;
  3820. $scope.item = data;
  3821. staticItem = angular.copy(data);
  3822. $scope.loading = false;
  3823. }, function(response){
  3824. $scope.loading = false;
  3825. toaster.pop('error', '数据加载失败', response.data);
  3826. });
  3827. } else {// 新增模式
  3828. $scope.item = {
  3829. quotation: {
  3830. currency: 'RMB',
  3831. taxrate: 17,
  3832. date: new Date()
  3833. },
  3834. product: {},
  3835. prices: [{lapQty: 0}],
  3836. minOrderQty: 1,
  3837. minPackQty: 1,
  3838. $endDateOpen: false,
  3839. $editing: true
  3840. };
  3841. }
  3842. $scope.getMinDate = function(item) {
  3843. return $filter('date')(new Date, 'yyyy-MM-dd');
  3844. };
  3845. $scope.openDatePicker = function($event, openParam) {
  3846. $event.preventDefault();
  3847. $event.stopPropagation();
  3848. $scope.item.$endDateOpen = !openParam;
  3849. };
  3850. // 增加一个分段
  3851. $scope.addPrice = function(){
  3852. if($scope.item.prices.length >= 10) {
  3853. toaster.pop('warning', '提示', '最多支持10个分段!');
  3854. } else
  3855. $scope.item.prices.push({});
  3856. };
  3857. // 删除一个分段
  3858. $scope.removePrice = function(index) {
  3859. $scope.item.prices.splice(index, 1);
  3860. };
  3861. // 查找客户
  3862. $scope.dbfindCust = function(){
  3863. if($scope.item.$editing) {
  3864. var modalInstance = $modal.open({
  3865. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  3866. controller: 'DbfindCustCtrl',
  3867. size: 'lg',
  3868. resolve: {
  3869. }
  3870. });
  3871. modalInstance.result.then(function(data){
  3872. $scope.item.quotation.cust = data.myEnterprise;
  3873. $scope.item.quotation.custUser = data.myUser;
  3874. $scope.item.product = null;
  3875. }, function(){
  3876. });
  3877. }
  3878. };
  3879. // 赋值客户信息
  3880. if($rootScope.custuu) {
  3881. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function(data) {
  3882. $scope.item.quotation.cust = data.myEnterprise;
  3883. $scope.item.quotation.custUser = data.myUser;
  3884. })
  3885. }
  3886. // 赋值物料信息
  3887. if($rootScope.prodId) {
  3888. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  3889. $scope.item.product.code = data.code;
  3890. $scope.item.product.title = data.title;
  3891. $scope.item.product.spec = data.spec;
  3892. $scope.item.product.unit = data.unit;
  3893. $scope.item.product.id = data.id;
  3894. }, function(response) {
  3895. });
  3896. }
  3897. // 查找客户物料
  3898. $scope.dbfindCustProd = function(){
  3899. if($scope.item.$editing) {
  3900. if($scope.item.quotation.cust.uu) {
  3901. var modalInstance = $modal.open({
  3902. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  3903. controller: 'DbfindCustProdCtrl',
  3904. size: 'lg',
  3905. resolve: {
  3906. custUU: function(){return $scope.item.quotation.cust.uu}
  3907. }
  3908. });
  3909. modalInstance.result.then(function(data){
  3910. $scope.item.product = data;
  3911. }, function(){
  3912. });
  3913. } else {
  3914. toaster.pop('error', '错误', '请先选择客户');
  3915. }
  3916. }
  3917. };
  3918. // 保存
  3919. $scope.save = function(){
  3920. $scope.loading = true;
  3921. if(!$scope.item.quotation.code) //新增,设单号
  3922. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  3923. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  3924. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  3925. $scope.item.productId = $scope.item.product.id;
  3926. $scope.item.quotation.status = 100;//在录入
  3927. if($scope.item.quotation.date instanceof Date) {
  3928. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  3929. }
  3930. if($scope.item.quotation.endDate instanceof Date) {
  3931. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  3932. }
  3933. Quotation.save({}, $scope.item, function(data){
  3934. $scope.loading = false;
  3935. toaster.pop('success', '成功', '保存成功');
  3936. if($stateParams.id)
  3937. window.location.reload();
  3938. else
  3939. window.location.hash = '#/sale/quotation/' + data.id;
  3940. }, function(response){
  3941. $scope.loading = false;
  3942. toaster.pop('error', '保存失败', response.data);
  3943. });
  3944. };
  3945. // 更新
  3946. $scope.update = function(){
  3947. $scope.item.$editing = true;
  3948. };
  3949. // 取消
  3950. $scope.cancel = function(){
  3951. $scope.item.$editing = false;
  3952. $scope.item = angular.copy(staticItem);
  3953. };
  3954. // 提交
  3955. $scope.submit = function(){
  3956. $scope.loading = true;
  3957. $scope.item.quotation.status = 101;//在录入
  3958. Quotation.save({}, $scope.item, function(data){
  3959. $scope.loading = false;
  3960. toaster.pop('success', '成功', '提交成功');
  3961. window.location.hash = '#/sale/quotation/' + data.id;
  3962. }, function(response){
  3963. $scope.loading = false;
  3964. toaster.pop('error', '保存失败', response.data);
  3965. });
  3966. };
  3967. }]);
  3968. // 查找客户
  3969. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  3970. BaseService.scrollBackToTop();
  3971. $scope.tableParams = new ngTableParams({
  3972. page : 1,
  3973. count : 10
  3974. }, {
  3975. total : 0,
  3976. counts: [5, 10, 25, 50],
  3977. getData : function($defer, params) {
  3978. $scope.loading = true;
  3979. var pageParams = params.url();
  3980. pageParams.keyword = $scope.keyword;
  3981. Customer.get(BaseService.parseParams(pageParams), function(page){
  3982. $scope.loading = false;
  3983. if(page) {
  3984. params.total(page.totalElements);
  3985. $defer.resolve(page.content);
  3986. }
  3987. $scope.totalCount = page.totalElements;
  3988. }, function(response){
  3989. $scope.loading = false;
  3990. toaster.pop('error', '数据加载失败', response.data);
  3991. });
  3992. }
  3993. });
  3994. $scope.onSearch = function() {
  3995. $scope.tableParams.page(1);
  3996. $scope.tableParams.reload();
  3997. };
  3998. $scope.cancel = function() {
  3999. $modalInstance.dismiss();
  4000. };
  4001. $scope.check = function(cust){
  4002. $modalInstance.close(cust);
  4003. };
  4004. }]);
  4005. // 查找客户物料
  4006. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  4007. BaseService.scrollBackToTop();
  4008. $scope.tableParams = new ngTableParams({
  4009. page : 1,
  4010. count : 10
  4011. }, {
  4012. total : 0,
  4013. counts: [5, 10, 25, 50],
  4014. getData : function($defer, params) {
  4015. $scope.loading = true;
  4016. var pageParams = params.url();
  4017. pageParams.keyword = $scope.keyword;
  4018. pageParams.custUU = custUU;
  4019. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  4020. $scope.loading = false;
  4021. if(page) {
  4022. params.total(page.totalElements);
  4023. $defer.resolve(page.content);
  4024. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4025. }
  4026. }, function(response){
  4027. $scope.loading = false;
  4028. toaster.pop('error', '数据加载失败', response.data);
  4029. });
  4030. }
  4031. });
  4032. // 取消
  4033. $scope.cancel = function() {
  4034. $modalInstance.dismiss();
  4035. };
  4036. // 选择
  4037. $scope.check = function(cust){
  4038. $modalInstance.close(cust);
  4039. };
  4040. // 搜索框回车
  4041. $scope.onSearch = function() {
  4042. $scope.tableParams.page(1);
  4043. $scope.tableParams.reload();
  4044. };
  4045. }]);
  4046. // 查找供应商
  4047. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance','$rootScope', function($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope){
  4048. BaseService.scrollBackToTop();
  4049. // 搜索框回车
  4050. $scope.onSearch = function(keyword) {
  4051. $scope.keyword = keyword;
  4052. $scope.tableParams.page(1);
  4053. $scope.tableParams.reload();
  4054. };
  4055. $scope.tableParams = new ngTableParams({
  4056. page : 1,
  4057. count : 10
  4058. }, {
  4059. total : 0,
  4060. counts: [10, 25, 50, 100],
  4061. getData : function($defer, params) {
  4062. $scope.loading = true;
  4063. var pageParams = params.url();
  4064. pageParams.keyword = $scope.keyword;
  4065. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  4066. $scope.loading = false;
  4067. if(page) {
  4068. params.total(page.totalElements);
  4069. $defer.resolve(page.content);
  4070. // 添加供应商时,将已存在的选中
  4071. if ($rootScope.tenderVendor) {
  4072. angular.forEach(page.content, function(vendor) {
  4073. for (var i = 0; i<$rootScope.tenderVendor.length; i++) {
  4074. vendor.checked = false;
  4075. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  4076. vendor.checked = true;
  4077. break;
  4078. }
  4079. }
  4080. });
  4081. }
  4082. }
  4083. $scope.totalCount = page.totalElements;
  4084. }, function(response){
  4085. $scope.loading = false;
  4086. toaster.pop('error', '数据加载失败', response.data);
  4087. });
  4088. }
  4089. });
  4090. $scope.cancel = function() {
  4091. $modalInstance.dismiss();
  4092. };
  4093. $scope.checks = {
  4094. checked : false
  4095. };// 全选框
  4096. $scope.checkAll = function() {
  4097. angular.forEach($scope.tableParams.data, function(vendor) {
  4098. vendor.checked = $scope.checks.checked;
  4099. });
  4100. };
  4101. // 单选
  4102. $scope.checkOne = function(vendor) {
  4103. vendor.checked = true;
  4104. var checked = true;
  4105. angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
  4106. if (!message.checked) {
  4107. checked = false;
  4108. }
  4109. });
  4110. $scope.checks.checked = checked;
  4111. };
  4112. // 单反选
  4113. $scope.unCheckOne = function(vendor) {
  4114. vendor.checked = false;
  4115. $scope.checks.checked = false;
  4116. };
  4117. $scope.close = function(){
  4118. var vendors = [];
  4119. angular.forEach($scope.tableParams.data, function(vendor) {
  4120. if(vendor.checked) {
  4121. vendors.push(vendor);
  4122. $modalInstance.close(vendors);
  4123. }
  4124. });
  4125. };
  4126. }]);
  4127. // 发货提醒
  4128. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', function($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state){
  4129. BaseService.scrollBackToTop();
  4130. $scope.active = 'todo';
  4131. $scope.currency = Symbol.currency;
  4132. $scope.dateZoneText = '不限';
  4133. $scope.condition = {dateZone: -1};
  4134. $scope.changeDateZone = function(zone) {
  4135. $scope.condition.dateZone = zone;
  4136. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4137. $scope.condition.$dateZoneOpen = false;
  4138. getDateCondition(zone, $scope.condition);
  4139. $scope.tableParams.reload();
  4140. };
  4141. $scope.setActive = function(state) {
  4142. if($scope.active != state) {
  4143. $scope.active = state;
  4144. if($scope.tableParams.page() == 1)
  4145. $scope.tableParams.reload();
  4146. else
  4147. $scope.tableParams.page(1);
  4148. }
  4149. };
  4150. var getService = function() {
  4151. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  4152. };
  4153. $scope.tableParams = new ngTableParams({
  4154. page : 1,
  4155. count : 5,
  4156. sorting: {
  4157. 'delivery': 'asc',
  4158. 'orderItemOrderCode': 'asc',
  4159. 'orderItemNumber': 'asc'
  4160. }
  4161. }, {
  4162. total : 0,
  4163. counts: [5, 10, 25, 50],
  4164. getData : function($defer, params) {
  4165. $scope.loading = true;
  4166. var pageParams = params.url();
  4167. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4168. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4169. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4170. $scope.loading = false;
  4171. if(page) {
  4172. params.total(page.totalElement);
  4173. $defer.resolve(page.content);
  4174. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4175. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4176. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4177. }
  4178. }, function(response){
  4179. $scope.loading = false;
  4180. toaster.pop('error', '数据加载失败', response.data);
  4181. });
  4182. }
  4183. });
  4184. $scope.openDatePicker = function($event, item, openParam) {
  4185. $event.preventDefault();
  4186. $event.stopPropagation();
  4187. item[openParam] = !item[openParam];
  4188. };
  4189. //生成随机单号
  4190. $scope.autoCode = function(notice){
  4191. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  4192. };
  4193. //可送货日期
  4194. $scope.sendDate = function(notice) {
  4195. var stock = notice.orderItem.product.ltinstock || 0;
  4196. var de = new Date(notice.delivery);
  4197. if(stock == -1) {
  4198. de.setMonth(de.getMonth() -1);
  4199. de.setDate(25);
  4200. } else if(stock >= 0) {
  4201. de.setDate(de.getDate() - stock -1);
  4202. }
  4203. return de;
  4204. };
  4205. $scope.onReplyClick = function(notice) {
  4206. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  4207. toaster.pop('warning', '警告', '数量填写错误!');
  4208. } else if(!notice.send.code) {
  4209. toaster.pop('warning', '警告', '请填写发货单号!');
  4210. } else {
  4211. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  4212. $scope.loading = true;
  4213. PurcNotice.save({id: notice.id}, send, function(data){
  4214. $scope.loading = false;
  4215. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  4216. $state.go('sale.send_detail', {id: data.id});
  4217. }, function(response){
  4218. $scope.loading = false;
  4219. toaster.pop('error', '发货失败', response.data);
  4220. });
  4221. }
  4222. };
  4223. $scope.checkboxes = {
  4224. checked : false
  4225. };
  4226. // 点击勾选全部的复选框
  4227. $scope.checkAll = function(){
  4228. angular.forEach($scope.tableParams.data, function(item) {
  4229. if(!item.waiting)
  4230. item.$selected = $scope.checkboxes.checked;
  4231. });
  4232. };
  4233. // 点击其中一个明细的复选框
  4234. $scope.checkOne = function(order){
  4235. var result = true;
  4236. angular.forEach($scope.tableParams.data, function(item) {
  4237. if(item.$selected != true){
  4238. result = false;
  4239. return;
  4240. }
  4241. });
  4242. $scope.checkboxes.checked = result;
  4243. };
  4244. $scope.sendByBatch = function(){
  4245. var modalInstance = $modal.open({
  4246. animation: true,
  4247. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  4248. controller: 'SaleNoticeSendByBatchCtrl',
  4249. size: 'lg',
  4250. resolve: {
  4251. selectedNotices: function(){return $scope.tableParams.data;}
  4252. }
  4253. });
  4254. modalInstance.result.then(function(){
  4255. $scope.tableParams.reload();
  4256. }, function(){
  4257. });
  4258. };
  4259. $scope.getSends = function(notice){
  4260. if( ! notice.sends && notice.endQty > 0){
  4261. notice.getSendsing = true;
  4262. notice.getSendsError = false;
  4263. PurcNotice.getSends({id: notice.id}, function(data){
  4264. notice.getSendsing = false;
  4265. notice.getSendsError = false;
  4266. notice.sends = data;
  4267. }, function(response){
  4268. notice.getSendsing = false;
  4269. notice.getSendsError = true;
  4270. });
  4271. }
  4272. };
  4273. // 搜索框回车
  4274. $scope.onSearch = function() {
  4275. $scope.tableParams.page(1);
  4276. $scope.tableParams.reload();
  4277. };
  4278. // 选择查找日期
  4279. $scope.onDateCondition = function(){
  4280. $scope.tableParams.page(1);
  4281. $scope.tableParams.reload();
  4282. };
  4283. //货车功能
  4284. var truck = $rootScope.truck;
  4285. if(!truck) {
  4286. SaleTruck.query({}, function(data){
  4287. $rootScope.truck = data;
  4288. });
  4289. }
  4290. $scope.isInTruck = function(noticeId) {
  4291. return truck.indexOf(noticeId) > -1;
  4292. };
  4293. $scope.addtoTruck = function(notice) {
  4294. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  4295. $rootScope.truck = data;
  4296. });
  4297. };
  4298. $scope.delFromTruck = function(notice) {
  4299. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  4300. $rootScope.truck = data;
  4301. });
  4302. };
  4303. $scope.$watch(function(){
  4304. return $rootScope.truck;
  4305. }, function(data) {
  4306. truck = $rootScope.truck;
  4307. }, true);
  4308. $scope.$watch(function(){
  4309. return $rootScope.dataChanged;
  4310. }, function(data) {
  4311. data && ($scope.tableParams.reload());
  4312. }, true);
  4313. }]);
  4314. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state){
  4315. $scope.notices = angular.copy(selectedNotices);
  4316. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4317. $scope.saleSend = {
  4318. code: '',
  4319. payments: '',
  4320. currency: '',
  4321. custUU: null,
  4322. custUserUU: null,
  4323. remark: '批量发货',
  4324. sendItems: []
  4325. };
  4326. // 计算总数、总额
  4327. $scope.$watch(function(){
  4328. return $scope.notices;
  4329. }, function(data) {
  4330. var q = 0, t = 0;
  4331. if(data) {
  4332. angular.forEach(data,function(d){
  4333. q += (d.thisSendQty || 0);
  4334. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  4335. });
  4336. }
  4337. $scope.totalQty = q;
  4338. $scope.total = t;
  4339. }, true);
  4340. /**
  4341. * 删除一个已选中的送货提醒
  4342. */
  4343. $scope.removeOne = function(index) {
  4344. $scope.notices.splice(index, 1);
  4345. };
  4346. //确认送货
  4347. $scope.sendByBatch = function () {
  4348. $scope.saleSend.sendItems = [];
  4349. if($scope.saleSend.code == '') {//送货单号为空
  4350. toaster.pop('error', '错误', '请输入送货单号');
  4351. return;
  4352. }
  4353. var a = 0;
  4354. var num = 1;
  4355. var valid = true;
  4356. angular.forEach($scope.notices, function(item, key){
  4357. if(item.$selected) {
  4358. if(a == 0) {//第一次
  4359. $scope.saleSend.currency = item.orderItem.order.currency;
  4360. $scope.saleSend.custUU = item.enUU;
  4361. $scope.saleSend.payments = item.orderItem.order.payments;
  4362. a = 1;
  4363. } else {//其他
  4364. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  4365. if($scope.saleSend.custUU != item.enUU) valid = false;
  4366. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  4367. }
  4368. $scope.saleSend.sendItems.push({
  4369. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num ++
  4370. });
  4371. }
  4372. });
  4373. if(!valid) {
  4374. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  4375. } else {
  4376. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  4377. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  4378. $modalInstance.close('success');
  4379. $state.go('sale.send_detail', {id: data.id});
  4380. }, function(response){
  4381. toaster.pop('error', '错误', response.data);
  4382. });
  4383. }
  4384. };
  4385. $scope.cancel = function () {
  4386. $modalInstance.dismiss();
  4387. };
  4388. }]);
  4389. /**
  4390. * 发货单
  4391. */
  4392. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  4393. BaseService.scrollBackToTop();
  4394. $scope.active = 'all';
  4395. $scope.currency = Symbol.currency;
  4396. $scope.dateZoneText = '不限';
  4397. $scope.condition = {dateZone: -1};
  4398. $scope.changeDateZone = function(zone) {
  4399. $scope.condition.dateZone = zone;
  4400. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  4401. $scope.condition.$dateZoneOpen = false;
  4402. getDateCondition(zone, $scope.condition);
  4403. $scope.tableParams.reload();
  4404. };
  4405. $scope.setActive = function(state) {
  4406. if($scope.active != state) {
  4407. $scope.active = state;
  4408. if($scope.tableParams.page() == 1)
  4409. $scope.tableParams.reload();
  4410. else
  4411. $scope.tableParams.page(1);
  4412. }
  4413. };
  4414. var getService = function() {
  4415. return SaleSend;
  4416. };
  4417. $scope.tableParams = new ngTableParams({
  4418. page : 1,
  4419. count : 5,
  4420. sorting: {
  4421. date: 'desc'
  4422. }
  4423. }, {
  4424. total : 0,
  4425. counts: [5, 10, 25, 50],
  4426. getData : function($defer, params) {
  4427. $scope.loading = true;
  4428. var pageParams = params.url();
  4429. pageParams.keyword = $scope.keyword;
  4430. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  4431. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  4432. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4433. $scope.loading = false;
  4434. if(page) {
  4435. params.total(page.totalElement);
  4436. $defer.resolve(page.content);
  4437. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  4438. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  4439. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  4440. }
  4441. }, function(response){
  4442. $scope.loading = false;
  4443. toaster.pop('error', '数据加载失败', response.data);
  4444. });
  4445. }
  4446. });
  4447. $scope.openDatePicker = function($event, item, openParam) {
  4448. $event.preventDefault();
  4449. $event.stopPropagation();
  4450. item[openParam] = !item[openParam];
  4451. };
  4452. // 搜索框回车
  4453. $scope.onSearch = function() {
  4454. $scope.tableParams.page(1);
  4455. $scope.tableParams.reload();
  4456. };
  4457. // 选择查找日期
  4458. $scope.onDateCondition = function(){
  4459. $scope.tableParams.page(1);
  4460. $scope.tableParams.reload();
  4461. };
  4462. }]);
  4463. /**
  4464. * 发货单(包括发货条码维护)
  4465. */
  4466. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService','ngTableParams','Lodop','$modal', function($scope, $stateParams, SaleSend, toaster, ReportService,ngTableParams,Lodop,$modal){
  4467. var loading = true;
  4468. $scope.checkBarCode = [];
  4469. $scope.checkBoxCode = [];
  4470. var vm = $scope.vm = {};
  4471. $scope.getCheckedItems = {};
  4472. vm.editBar = false;
  4473. vm.showBarCode = [];
  4474. $scope.barCode = function() {
  4475. vm.editBar = !vm.editBar;
  4476. }
  4477. $scope.checkboxes = {
  4478. checked : false
  4479. };
  4480. $scope.checkbars = {
  4481. checked : false
  4482. };
  4483. // 点击勾选barCode全部的复选框
  4484. $scope.checkBarAll = function(){
  4485. angular.forEach($scope.checkBarCode, function(item,key) {
  4486. $scope.checkBarCode[key] = $scope.checkbars.checked;
  4487. });
  4488. };
  4489. //点击barCode单选
  4490. $scope.checkBarOne = function() {
  4491. var result = true;
  4492. angular.forEach($scope.checkBarCode, function(item,key) {
  4493. if(item != true){
  4494. result = false;
  4495. return;
  4496. }
  4497. });
  4498. $scope.checkbars.checked = result;
  4499. }
  4500. // 点击boxCode全部的复选框
  4501. $scope.checkBoxAll = function(){
  4502. angular.forEach($scope.checkBoxCode, function(item,key) {
  4503. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  4504. });
  4505. };
  4506. //点击boxCode单选
  4507. $scope.checkBoxOne = function() {
  4508. var result = true;
  4509. angular.forEach($scope.checkBoxCode, function(item) {
  4510. if(item != true){
  4511. result = false;
  4512. return;
  4513. }
  4514. });
  4515. $scope.checkboxes.checked = result;
  4516. }
  4517. /**
  4518. * 生成条码和箱号
  4519. */
  4520. $scope.generateBarCode = function(item) {
  4521. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  4522. $scope.getCheckedItems = [];
  4523. var warningdata = '';
  4524. angular.forEach($scope.checkBarCode, function(item,key) {
  4525. $scope.getCheckedItem = {};
  4526. if(item == true ){
  4527. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4528. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  4529. $scope.getCheckedItems.push($scope.getCheckedItem);
  4530. //判断是否生成过条码
  4531. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4532. warningdata += $scope.order.sendItems[key].number+","
  4533. }
  4534. }
  4535. });
  4536. if($scope.getCheckedItems.length == 0){
  4537. toaster.pop('warning', '提示','请勾选需要生成条码的明细行!');
  4538. return;
  4539. }
  4540. if(warningdata != ''){
  4541. if(!confirm('明细行序号:'+warningdata+"已经生成了条码,继续生成将清空原有条码?")){
  4542. return ;
  4543. }
  4544. }
  4545. SaleSend.generateBarcodes({id:$scope.order.id}, angular.fromJson($scope.getCheckedItems),function(data){
  4546. toaster.pop('success', '提示','生成成功!');
  4547. loadData();
  4548. },function(response){
  4549. $scope.loading = false;
  4550. toaster.pop('error', '生成失败', response.data);
  4551. });
  4552. }
  4553. /**
  4554. * 打印条码和箱号
  4555. */
  4556. $scope.printCode = function(type) {
  4557. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4558. //勾选需要打印的行
  4559. $scope.getCheckedItems = [];
  4560. var warningdata = ''
  4561. angular.forEach($scope.checkBarCode, function(item,key) {
  4562. $scope.getCheckedItem = {};
  4563. if(item == true ){
  4564. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  4565. $scope.getCheckedItems.push($scope.getCheckedItem);
  4566. //判断是否生成过条码
  4567. if($scope.order.sendItems[key].barSendNotify.length > 0){
  4568. warningdata += $scope.order.sendItems[key].number+","
  4569. }
  4570. }
  4571. });
  4572. if($scope.getCheckedItems.length == 0){
  4573. toaster.pop('warning', '提示','请勾选需要打印的明细行!');
  4574. return;
  4575. }
  4576. if(warningdata == ''){
  4577. toaster.pop('warning', '提示','明细行序号:'+warningdata+'未生成条码无法打印');
  4578. return;
  4579. }
  4580. //选择打印模板
  4581. var modalInstance = $modal.open({
  4582. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4583. controller: 'BarPrintModalCtrl',
  4584. resolve: {
  4585. typeItem: function(){return {'type':type,'id':$scope.order.id};}
  4586. }
  4587. });
  4588. modalInstance.result.then(function(s){
  4589. if(s) {
  4590. //获取打印数据
  4591. SaleSend.getPrintBarcodes({lpsId:s.tp_id}, angular.fromJson($scope.getCheckedItems),function(data){
  4592. if(s.type == 'print'){//判断选择是打印还是打印预览
  4593. lodopPrint(data.message,LODOP,type);
  4594. }else if(s.type == 'printPreview'){
  4595. lodopPrintPreview(data.message,LODOP,type);
  4596. }
  4597. },function(response){
  4598. toaster.pop('error', '获取打印数据失败', response.data);
  4599. });
  4600. }
  4601. });
  4602. };
  4603. //打印单个条码
  4604. $scope.printSingleCode = function(id){
  4605. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
  4606. //选择打印模板
  4607. var modalInstance = $modal.open({
  4608. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  4609. controller: 'BarPrintModalCtrl',
  4610. resolve: {
  4611. typeItem: function(){return {'type':'Bar','id':$scope.order.id};}
  4612. }
  4613. });
  4614. modalInstance.result.then(function(s){
  4615. if(s) {
  4616. //获取打印数据
  4617. SaleSend.getSPrintBarcode({lpsId:s.tp_id,bsnId:id},function(data){
  4618. if(s.type == 'print'){//判断选择是打印还是打印预览
  4619. lodopSPrint(data.message,LODOP);
  4620. }else if(s.type == 'printPreview'){
  4621. lodopSPrintPreview(data.message,LODOP);
  4622. }
  4623. },function(response){
  4624. toaster.pop('error', '获取打印数据失败', response.data);
  4625. });
  4626. }
  4627. });
  4628. }
  4629. var lodopSPrint = function(printStore,LODOP){//单个条码打印
  4630. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4631. if (selectOrNot != -1) {
  4632. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4633. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4634. var strs = pagesize.split("*"); //字符分割
  4635. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4636. angular.forEach(printStore, function(data, index) {
  4637. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4638. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4639. if (data['LP_VALUETYPE'] == 'barcode') {
  4640. 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']);
  4641. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4642. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4643. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4644. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4645. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4646. } else if (data['LP_VALUETYPE'] == 'text') {
  4647. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4648. }
  4649. });
  4650. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4651. LODOP.PRINT();
  4652. }
  4653. };
  4654. var lodopSPrintPreview = function(printStore,LODOP){//单个条码打印预览
  4655. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4656. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  4657. var strs = pagesize.split("*"); //字符分割
  4658. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4659. angular.forEach(printStore,function(data,index){
  4660. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  4661. if(data['LP_VALUETYPE'] == 'barcode'){
  4662. 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']);
  4663. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  4664. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  4665. }else if(data['LP_VALUETYPE'] == 'text'){
  4666. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4667. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  4668. }
  4669. });
  4670. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  4671. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  4672. LODOP.PREVIEW();//打印预览
  4673. };
  4674. var lodopPrint = function(printStore,LODOP,type){//勾选发货单明细进行打印
  4675. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  4676. if (selectOrNot != -1) {
  4677. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  4678. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  4679. var strs= new Array(); //定义一数组
  4680. strs = pagesize.split("*"); //字符分割
  4681. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4682. var ids = new Array();
  4683. angular.forEach(printStore, function(value,key) {
  4684. //LODOP.NewPage();
  4685. angular.forEach(value['data'], function(record,key) {
  4686. angular.forEach(record['store'], function(data, index) {
  4687. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  4688. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4689. if (data['LP_VALUETYPE'] == 'barcode') {
  4690. 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']);
  4691. LODOP.SET_PRINT_STYLEA(0,"ShowBarText", data['LP_IFSHOWNOTE']);
  4692. LODOP.SET_PRINT_STYLEA(0,"AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  4693. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  4694. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  4695. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  4696. } else if (data['LP_VALUETYPE'] == 'text') {
  4697. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm", data['value']);
  4698. }
  4699. });
  4700. });
  4701. var o = new Object();
  4702. o['id'] = record['si_id']
  4703. ids.push(o);
  4704. LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);//设置打印的精度
  4705. LODOP.PRINT();
  4706. });
  4707. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  4708. if(type == 'Bar'){
  4709. //更新打印状态
  4710. SaleSend.updatePrintStatus({},ids,function(data){},function(res){});
  4711. }
  4712. }
  4713. };
  4714. var lodopPrintPreview = function(printData,LODOP,type){//打印预览
  4715. var ids = new Array();
  4716. angular.forEach(printData, function(record, index){
  4717. angular.forEach(record['data'],function(value,index){
  4718. LODOP.NewPage();
  4719. angular.forEach(value['store'],function(data,index){
  4720. LODOP.SET_PRINT_STYLE("FontSize",data['LP_SIZE']);
  4721. if(data['LP_VALUETYPE'] == 'barcode'){
  4722. 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']);
  4723. LODOP.SET_PRINT_STYLEA(0,"ShowBarText",data['LP_IFSHOWNOTE']);
  4724. LODOP.SET_PRINT_STYLEA(0,"AlignJustify",data['LP_NOTEALIGNJUSTIFY']);
  4725. }else if(data['LP_VALUETYPE'] == 'text'){
  4726. LODOP.SET_PRINT_STYLE("FontName",data['LP_FONT']);
  4727. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE']+"mm",data['LP_LEFTRATE']+"mm",data['LP_WIDTH']+"mm",data['LP_HEIGHT']+"mm",data['value']);
  4728. }
  4729. });
  4730. });
  4731. var o = new Object();
  4732. o['id'] = record['si_id']
  4733. ids.push(o);
  4734. });
  4735. var pagesize = printData[0]['pagesize'];//获取标签的大小
  4736. var strs= new Array(); //定义一数组
  4737. strs = pagesize.split("*"); //字符分割
  4738. LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");
  4739. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);
  4740. LODOP.SET_PRINT_PAGESIZE(1, strs[0]*10, strs[1]*10, "");
  4741. var times = LODOP.PREVIEW();//打印预览
  4742. if(times > 0){//点击了打印预览内的打印按钮
  4743. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  4744. if(type == 'Bar'){
  4745. //更新打印状态
  4746. SaleSend.updatePrintStatus({},ids,function(data){
  4747. loadData();
  4748. },function(res){});
  4749. }
  4750. }
  4751. };
  4752. /**
  4753. * 查看条码按钮
  4754. */
  4755. $scope.showBarCode = function(number) {
  4756. $scope.keys = number;
  4757. for(var i=0;i<vm.showBarCode.length;i++){
  4758. if(i!=number){
  4759. vm.showBarCode[i] = false;
  4760. }
  4761. }
  4762. vm.showBarCode[number] = !vm.showBarCode[number];
  4763. $scope.barcodes = [];
  4764. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  4765. var getPage = function(page, size){
  4766. if($scope.barcodes) {
  4767. var result = {};
  4768. result.totalCount = $scope.barcodes.length;
  4769. result.content = $scope.barcodes.slice((page - 1)*size, page * size);
  4770. if($scope.barcodes.length % size == 0) {
  4771. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  4772. }else {
  4773. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  4774. }
  4775. result.first = page == 1;
  4776. result.last = page == result.totalPage;
  4777. result.page = page;
  4778. result.next = page - 0 + 1;
  4779. result.pre = page - 1;
  4780. return result;
  4781. }
  4782. }
  4783. $scope.barData = getPage(1,5);
  4784. $scope.first = function (){
  4785. $scope.barData = getPage($scope.barData.pre,5);
  4786. }
  4787. $scope.last = function (){
  4788. $scope.barData = getPage($scope.barData.next,5);
  4789. }
  4790. };
  4791. /**
  4792. * 更新外箱号
  4793. */
  4794. $scope.updateOutBox = function(item,number) {
  4795. if($scope.oldoutBoxQty[number] == item.outBoxQty) {
  4796. }else {
  4797. if(item.outBoxQty > 0) {
  4798. if(!(item.outBoxQty % item.packageQty)) {
  4799. SaleSend.update({id:item.id},item,function(){
  4800. toaster.pop('success', '提示','保存成功!');
  4801. loadData();
  4802. }, function(response){
  4803. $scope.loading = false;
  4804. toaster.pop('error', '回复失败', response.data);
  4805. })
  4806. }else {
  4807. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  4808. }
  4809. }else {
  4810. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  4811. }
  4812. }
  4813. loadData();
  4814. };
  4815. /**
  4816. * 更新最小包数
  4817. */
  4818. $scope.updatePackage = function(item, number) {
  4819. if(item.packageQty == $scope.oldpackageQty[number]) {
  4820. }else {
  4821. if(item.orderItem.product.minPack != 0) {
  4822. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  4823. if(!(item.packageQty % item.orderItem.product.minPack)) {
  4824. SaleSend.update({id:item.id},item,function(){
  4825. toaster.pop('success', '提示','保存成功!');
  4826. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  4827. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  4828. }
  4829. loadData();
  4830. }, function(response){
  4831. $scope.loading = false;
  4832. toaster.pop('error', '回复失败', response.data);
  4833. })
  4834. }else {
  4835. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  4836. }
  4837. }else {
  4838. toaster.pop('warning', '提示', '请填写有效的数量!');
  4839. }
  4840. }else {
  4841. if(item.packageQty > 0 && item.packageQty <= item.qty) {
  4842. SaleSend.update({id:item.id},item,function(){
  4843. toaster.pop('success', '提示','保存成功!');
  4844. if(item.outBoxQty && item.outBoxQty%item.packageQty) {
  4845. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  4846. }
  4847. loadData();
  4848. }, function(response){
  4849. $scope.loading = false;
  4850. toaster.pop('error', '回复失败', response.data);
  4851. })
  4852. }else {
  4853. toaster.pop('warning', '提示', '请填写有效的数量!');
  4854. }
  4855. }
  4856. }
  4857. loadData();
  4858. };
  4859. var loadData = function() {
  4860. SaleSend.get({id: $stateParams.id}, function(data){
  4861. $scope.order = data;
  4862. var orderCount = $scope.order.sendItems.length;
  4863. $scope.oldpackageQty = [];
  4864. $scope.oldoutBoxQty = [];
  4865. var sum = 0;
  4866. vm.oldpackageQty = [];
  4867. angular.forEach(data.sendItems, function(value, key){
  4868. //给showBarCode数组赋初值
  4869. if (vm.showBarCode.length < orderCount){
  4870. vm.showBarCode.push(false);
  4871. }
  4872. if($scope.checkBarCode.length < orderCount) {
  4873. $scope.checkBarCode.push(false);
  4874. }
  4875. if($scope.checkBoxCode.length < orderCount) {
  4876. $scope.checkBoxCode.push(false);
  4877. }
  4878. //给个初值
  4879. if(!value.packageQty) {
  4880. value.packageQty = value.orderItem.product.minPack;
  4881. }
  4882. $scope.oldpackageQty.push(value.packageQty);
  4883. if(value.outBoxQty) {
  4884. $scope.oldoutBoxQty.push(value.outBoxQty);
  4885. }
  4886. sum += value.price * value.qty;
  4887. });
  4888. data.total = sum;
  4889. $scope.loading = false;
  4890. }, function(response){
  4891. loading = false;
  4892. toaster.pop('error', '获取数据失败', response.data);
  4893. });
  4894. };
  4895. loadData();
  4896. }]);
  4897. app.controller('BarPrintModalCtrl', ['$scope','typeItem', 'SaleSend','toaster','$modalInstance', function($scope, typeItem, SaleSend,toaster,$modalInstance){
  4898. $scope.typeItem = typeItem;
  4899. $scope.template = [];
  4900. $scope.choose = {};
  4901. //获取打印模板
  4902. SaleSend.getPrintTemplate({id:$scope.typeItem.id,type:$scope.typeItem.type},function(data){
  4903. if(data.message){
  4904. $scope.template = data.message;
  4905. $scope.choose.tp_id = $scope.template[0].id;
  4906. }
  4907. },function(res){
  4908. toaster.pop('error', '获取模板错误', res.data);
  4909. });
  4910. $scope.print = function(){
  4911. $scope.choose.type = 'print';
  4912. $modalInstance.close($scope.choose);
  4913. };
  4914. $scope.printPreview = function(){
  4915. $scope.choose.type = 'printPreview';
  4916. $modalInstance.close($scope.choose);
  4917. }
  4918. $scope.cancel = function(){
  4919. $modalInstance.close();
  4920. }
  4921. }]);
  4922. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
  4923. var loading = true;
  4924. var loadData = function() {
  4925. PurcSample.get({id: $stateParams.id}, function(data){
  4926. $scope.sample = data;
  4927. if(!$scope.sample.send){
  4928. $scope.sample.getSendInfo = '加载中...';
  4929. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  4930. if(sendData) {
  4931. $scope.sample.getSendInfo = null;
  4932. $scope.sample.send = sendData;
  4933. } else {
  4934. $scope.sample.getSendInfo = '无送样信息';
  4935. $scope.sample.send = '无送样信息';
  4936. }
  4937. }, function(response){
  4938. $scope.sample.getSendInfo = '加载失败!';
  4939. });
  4940. }
  4941. $scope.loading = false;
  4942. }, function(response){
  4943. loading = false;
  4944. toaster.pop('error', '获取数据失败', response.data);
  4945. });
  4946. };
  4947. loadData();
  4948. }]);
  4949. /**
  4950. * 客户打样申请
  4951. */
  4952. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService','ReportService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService,ReportService, Symbol){
  4953. BaseService.scrollBackToTop();
  4954. $scope.active = 'todo';
  4955. $scope.agreedText = '全部';
  4956. $scope.dateZoneText = '一个月内';
  4957. $scope.condition = {dateZone: 1};
  4958. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  4959. $scope.changeAgreed = function(agreed) {
  4960. $scope.condition.agreed = agreed;
  4961. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  4962. $scope.condition.$agreedOpen = false;
  4963. };
  4964. $scope.changeDateZone = function(zone) {
  4965. $scope.condition.dateZone = zone;
  4966. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  4967. $scope.condition.$dateZoneOpen = false;
  4968. };
  4969. $scope.setActive = function(state) {
  4970. if($scope.active != state) {
  4971. $scope.active = state;
  4972. if($scope.tableParams.page() == 1)
  4973. $scope.tableParams.reload();
  4974. else
  4975. $scope.tableParams.page(1);
  4976. }
  4977. };
  4978. var getService = function() {
  4979. return PurcSample;
  4980. };
  4981. $scope.tableParams = new ngTableParams({
  4982. page : 1,
  4983. count : 5,
  4984. sorting: {
  4985. proofingDate: 'desc'
  4986. }
  4987. }, {
  4988. total : 0,
  4989. counts: [5, 10, 25, 50],
  4990. getData : function($defer, params) {
  4991. $scope.loading = true;
  4992. var pageParams = params.url();
  4993. pageParams.keyword = $scope.keyword;
  4994. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  4995. $scope.loading = false;
  4996. if(page) {
  4997. params.total(page.totalElement);
  4998. $defer.resolve(page.content);
  4999. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5000. }
  5001. }, function(response){
  5002. $scope.loading = false;
  5003. toaster.pop('error', '数据加载失败', response.data);
  5004. });
  5005. }
  5006. });
  5007. $scope.openDatePicker = function($event, item, openParam) {
  5008. $event.preventDefault();
  5009. $event.stopPropagation();
  5010. item[openParam] = !item[openParam];
  5011. };
  5012. $scope.openSend = function(index, sample) {
  5013. var modalInstance = $modal.open({
  5014. animation: true,
  5015. templateUrl: 'static/tpl/index/sale/sample_send.html',
  5016. controller: 'SampleSendCtrl',
  5017. resolve: {
  5018. sampleItem: function(){return sample;}
  5019. }
  5020. });
  5021. modalInstance.result.then(function(){
  5022. toaster.pop('info', '提示', '送样成功');
  5023. $scope.tableParams.reload();
  5024. }, function(){
  5025. });
  5026. };
  5027. //打印 样品采购单
  5028. $scope.print = function(sample) {
  5029. console.log(sample);
  5030. PurcSample.printCount({id: sample.id},{});//增加打印此次
  5031. ReportService.print(sample.proofing.enUU, 'PURCPROOFING',"where purc$proofingitems.ppi_id =" + sample.id);
  5032. };
  5033. $scope.getSend = function(proofing){
  5034. if( !proofing.send) {
  5035. proofing.getSendInfo = '加载中...';
  5036. PurcSample.getSend({id: proofing.id}, function(data){
  5037. if(data) {
  5038. proofing.getSendInfo = null;
  5039. proofing.send = data;
  5040. } else {
  5041. proofing.getSendInfo = '无送样信息';
  5042. proofing.send = '无送样信息';
  5043. }
  5044. }, function(response){
  5045. proofing.getSendInfo = '加载失败!';
  5046. });
  5047. }
  5048. };
  5049. // 搜索框回车
  5050. $scope.onSearch = function() {
  5051. $scope.tableParams.page(1);
  5052. $scope.tableParams.reload();
  5053. };
  5054. }]);
  5055. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  5056. $scope.sampleItem = sampleItem;
  5057. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  5058. //确认送样
  5059. $scope.ok = function (form) {
  5060. $scope.loading = true;
  5061. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  5062. $upload.upload({
  5063. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  5064. method: 'POST',
  5065. file: file,
  5066. data: {
  5067. json: $scope.sampleItem.sampleSend
  5068. }
  5069. }).success(function(data){
  5070. $scope.loading = false;
  5071. $modalInstance.close('success');
  5072. }).error(function(data){
  5073. $scope.loading = false;
  5074. toaster.pop('danger', '错误', data);
  5075. });
  5076. };
  5077. $scope.cancel = function () {
  5078. $modalInstance.dismiss(sampleItem);
  5079. };
  5080. }]);
  5081. /**
  5082. * 客户认定单
  5083. */
  5084. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  5085. BaseService.scrollBackToTop();
  5086. $scope.active = 'all';
  5087. $scope.agreedText = '全部';
  5088. $scope.dateZoneText = '一个月内';
  5089. $scope.condition = {dateZone: 1};
  5090. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5091. $scope.changeDateZone = function(zone) {
  5092. $scope.condition.dateZone = zone;
  5093. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5094. $scope.condition.$dateZoneOpen = false;
  5095. getDateCondition(zone, $scope.condition);
  5096. $scope.tableParams.reload();
  5097. };
  5098. $scope.setActive = function(state) {
  5099. if($scope.active != state) {
  5100. $scope.active = state;
  5101. if($scope.tableParams.page() == 1)
  5102. $scope.tableParams.reload();
  5103. else
  5104. $scope.tableParams.page(1);
  5105. }
  5106. };
  5107. var getService = function() {
  5108. return PurcApproval;
  5109. };
  5110. $scope.tableParams = new ngTableParams({
  5111. page : 1,
  5112. count : 5,
  5113. sorting: {
  5114. inDate: 'desc'
  5115. }
  5116. }, {
  5117. total : 0,
  5118. counts: [5, 10, 25, 50],
  5119. getData : function($defer, params) {
  5120. $scope.loading = true;
  5121. var pageParams = params.url();
  5122. pageParams.keyword = $scope.keyword;
  5123. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5124. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5125. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5126. $scope.loading = false;
  5127. if(page) {
  5128. params.total(page.totalElement);
  5129. $defer.resolve(page.content);
  5130. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5131. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5132. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5133. }
  5134. }, function(response){
  5135. $scope.loading = false;
  5136. toaster.pop('error', '数据加载失败', response.data);
  5137. });
  5138. }
  5139. });
  5140. $scope.openDatePicker = function($event, item, openParam) {
  5141. $event.preventDefault();
  5142. $event.stopPropagation();
  5143. item[openParam] = !item[openParam];
  5144. };
  5145. $scope.parseDate = function(dateStr) {
  5146. if(dateStr)
  5147. return Date.parse(dateStr, 'yyyy-MM-dd');
  5148. return new Date();
  5149. };
  5150. // 搜索框回车
  5151. $scope.onSearch = function() {
  5152. $scope.tableParams.page(1);
  5153. $scope.tableParams.reload();
  5154. };
  5155. // 选择查找日期
  5156. $scope.onDateCondition = function(){
  5157. $scope.tableParams.page(1);
  5158. $scope.tableParams.reload();
  5159. };
  5160. }]);
  5161. /**
  5162. * 客户采购预测
  5163. */
  5164. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  5165. BaseService.scrollBackToTop();
  5166. $scope.active = 'all';
  5167. $scope.agreedText = '全部';
  5168. $scope.dateZoneText = '一个月内';
  5169. $scope.condition = {dateZone: 1};
  5170. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5171. $scope.changeAgreed = function(agreed) {
  5172. $scope.condition.agreed = agreed;
  5173. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5174. $scope.condition.$agreedOpen = false;
  5175. };
  5176. $scope.changeDateZone = function(zone) {
  5177. $scope.condition.dateZone = zone;
  5178. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5179. $scope.condition.$dateZoneOpen = false;
  5180. };
  5181. $scope.setActive = function(state) {
  5182. if($scope.active != state) {
  5183. $scope.active = state;
  5184. if($scope.tableParams.page() == 1)
  5185. $scope.tableParams.reload();
  5186. else
  5187. $scope.tableParams.page(1);
  5188. }
  5189. };
  5190. var getService = function() {
  5191. return PurcForecast;
  5192. };
  5193. $scope.tableParams = new ngTableParams({
  5194. page : 1,
  5195. count : 5,
  5196. sorting: {
  5197. orderDate: 'desc'
  5198. }
  5199. }, {
  5200. total : 0,
  5201. counts: [5, 10, 25, 50],
  5202. getData : function($defer, params) {
  5203. $scope.loading = true;
  5204. var pageParams = params.url();
  5205. pageParams.keyword = $scope.keyword;
  5206. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5207. $scope.loading = false;
  5208. if(page) {
  5209. console.log(page);
  5210. params.total(page.totalElement);
  5211. $defer.resolve(page.content);
  5212. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5213. }
  5214. }, function(response){
  5215. $scope.loading = false;
  5216. toaster.pop('error', '数据加载失败', response.data);
  5217. });
  5218. }
  5219. });
  5220. $scope.openDatePicker = function($event, item, openParam) {
  5221. $event.preventDefault();
  5222. $event.stopPropagation();
  5223. item[openParam] = !item[openParam];
  5224. };
  5225. // 搜索框回车
  5226. $scope.onSearch = function() {
  5227. $scope.tableParams.page(1);
  5228. $scope.tableParams.reload();
  5229. };
  5230. }]);
  5231. /**
  5232. * 客户采购验收
  5233. */
  5234. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  5235. BaseService.scrollBackToTop();
  5236. $scope.active = 'all';
  5237. $scope.dateZoneText = '不限';
  5238. $scope.deliveryZoneText = '不限';
  5239. $scope.condition = {dateZone: -1, deliveryZone: -1};
  5240. $scope.changeDateZone = function(zone) {
  5241. $scope.condition.dateZone = zone;
  5242. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5243. $scope.condition.$dateZoneOpen = false;
  5244. getDateCondition(zone, $scope.condition);
  5245. $scope.tableParams.reload();
  5246. };
  5247. $scope.changeDeliveryZone = function(zone) {
  5248. $scope.condition.deliveryZoneText = zone;
  5249. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  5250. $scope.condition.$delievryZoneOpen = false;
  5251. getDelveryCondition(zone, $scope.condition);
  5252. $scope.tableParams.reload();
  5253. };
  5254. $scope.setActive = function(state) {
  5255. if($scope.active != state) {
  5256. $scope.active = state;
  5257. if($scope.tableParams.page() == 1)
  5258. $scope.tableParams.reload();
  5259. else
  5260. $scope.tableParams.page(1);
  5261. }
  5262. };
  5263. var getService = function() {
  5264. return PurcAccept;
  5265. };
  5266. $scope.tableParams = new ngTableParams({
  5267. page : 1,
  5268. count : 5,
  5269. sorting: {
  5270. date: 'desc'
  5271. }
  5272. }, {
  5273. total : 0,
  5274. counts: [5, 10, 25, 50],
  5275. getData : function($defer, params) {
  5276. $scope.loading = true;
  5277. var pageParams = params.url();
  5278. pageParams.searchFilter = { // 筛选条件
  5279. keyword: $scope.keyword,
  5280. fromDate: getDateTime($scope.condition.dateFrom),
  5281. endDate: getDateTime($scope.condition.dateTo)
  5282. };
  5283. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5284. $scope.loading = false;
  5285. if(page) {
  5286. params.total(page.totalElement);
  5287. $defer.resolve(page.content);
  5288. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5289. }
  5290. }, function(response){
  5291. $scope.loading = false;
  5292. toaster.pop('error', '数据加载失败', response.data);
  5293. });
  5294. }
  5295. });
  5296. $scope.openDatePicker = function($event, item, openParam) {
  5297. $event.preventDefault();
  5298. $event.stopPropagation();
  5299. item[openParam] = !item[openParam];
  5300. };
  5301. $scope.parseDate = function(dateStr) {
  5302. if(dateStr)
  5303. return Date.parse(dateStr, 'yyyy-MM-dd');
  5304. return new Date();
  5305. };
  5306. // 选择查找日期
  5307. $scope.onDateCondition = function(){
  5308. $scope.tableParams.page(1);
  5309. $scope.tableParams.reload();
  5310. };
  5311. // 搜索框回车
  5312. $scope.onSearch = function() {
  5313. $scope.tableParams.page(1);
  5314. $scope.tableParams.reload();
  5315. };
  5316. }]);
  5317. /**
  5318. * 客户采购验退
  5319. */
  5320. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  5321. BaseService.scrollBackToTop();
  5322. $scope.active = 'all';
  5323. $scope.agreedText = '全部';
  5324. $scope.dateZoneText = '一个月内';
  5325. $scope.condition = {dateZone: 1};
  5326. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5327. $scope.changeAgreed = function(agreed) {
  5328. $scope.condition.agreed = agreed;
  5329. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5330. $scope.condition.$agreedOpen = false;
  5331. };
  5332. $scope.changeDateZone = function(zone) {
  5333. $scope.condition.dateZone = zone;
  5334. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5335. $scope.condition.$dateZoneOpen = false;
  5336. };
  5337. $scope.setActive = function(state) {
  5338. if($scope.active != state) {
  5339. $scope.active = state;
  5340. if($scope.tableParams.page() == 1)
  5341. $scope.tableParams.reload();
  5342. else
  5343. $scope.tableParams.page(1);
  5344. }
  5345. };
  5346. var getService = function() {
  5347. return PurcReturn;
  5348. };
  5349. $scope.tableParams = new ngTableParams({
  5350. page : 1,
  5351. count : 5,
  5352. sorting: {
  5353. date: 'desc'
  5354. }
  5355. }, {
  5356. total : 0,
  5357. counts: [5, 10, 25, 50],
  5358. getData : function($defer, params) {
  5359. $scope.loading = true;
  5360. var pageParams = params.url();
  5361. pageParams.keyword = $scope.keyword;
  5362. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5363. $scope.loading = false;
  5364. if(page) {
  5365. params.total(page.totalElement);
  5366. $defer.resolve(page.content);
  5367. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5368. angular.forEach(page.content, function(data) {
  5369. if (!data.returnItems[0].orderItem) {
  5370. PurcReturn.getEnterpriseName({id: data.id, enuu : data.enUU},function(enterprise) {
  5371. data.enName = enterprise.enName;
  5372. });
  5373. }
  5374. });
  5375. }
  5376. }, function(response){
  5377. $scope.loading = false;
  5378. toaster.pop('error', '数据加载失败', response.data);
  5379. });
  5380. }
  5381. });
  5382. $scope.openDatePicker = function($event, item, openParam) {
  5383. $event.preventDefault();
  5384. $event.stopPropagation();
  5385. item[openParam] = !item[openParam];
  5386. };
  5387. // 搜索框回车
  5388. $scope.onSearch = function() {
  5389. $scope.tableParams.page(1);
  5390. $scope.tableParams.reload();
  5391. };
  5392. }]);
  5393. /**
  5394. * 客户不良品入库
  5395. */
  5396. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  5397. BaseService.scrollBackToTop();
  5398. $scope.active = 'all';
  5399. $scope.agreedText = '全部';
  5400. $scope.dateZoneText = '一个月内';
  5401. $scope.condition = {dateZone: 1};
  5402. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5403. $scope.changeAgreed = function(agreed) {
  5404. $scope.condition.agreed = agreed;
  5405. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5406. $scope.condition.$agreedOpen = false;
  5407. };
  5408. $scope.changeDateZone = function(zone) {
  5409. $scope.condition.dateZone = zone;
  5410. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5411. $scope.condition.$dateZoneOpen = false;
  5412. };
  5413. $scope.setActive = function(state) {
  5414. if($scope.active != state) {
  5415. $scope.active = state;
  5416. if($scope.tableParams.page() == 1)
  5417. $scope.tableParams.reload();
  5418. else
  5419. $scope.tableParams.page(1);
  5420. }
  5421. };
  5422. var getService = function() {
  5423. return PurcBadIn;
  5424. };
  5425. $scope.tableParams = new ngTableParams({
  5426. page : 1,
  5427. count : 5,
  5428. sorting: {
  5429. date: 'desc'
  5430. }
  5431. }, {
  5432. total : 0,
  5433. counts: [5, 10, 25, 50],
  5434. getData : function($defer, params) {
  5435. $scope.loading = true;
  5436. var pageParams = params.url();
  5437. pageParams.keyword = $scope.keyword;
  5438. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5439. $scope.loading = false;
  5440. if(page) {
  5441. params.total(page.totalElement);
  5442. $defer.resolve(page.content);
  5443. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5444. }
  5445. }, function(response){
  5446. $scope.loading = false;
  5447. toaster.pop('error', '数据加载失败', response.data);
  5448. });
  5449. }
  5450. });
  5451. $scope.openDatePicker = function($event, item, openParam) {
  5452. $event.preventDefault();
  5453. $event.stopPropagation();
  5454. item[openParam] = !item[openParam];
  5455. };
  5456. // 搜索框回车
  5457. $scope.onSearch = function() {
  5458. $scope.tableParams.page(1);
  5459. $scope.tableParams.reload();
  5460. };
  5461. }]);
  5462. /**
  5463. * 客户不良品出库
  5464. */
  5465. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  5466. BaseService.scrollBackToTop();
  5467. $scope.active = 'all';
  5468. $scope.agreedText = '全部';
  5469. $scope.dateZoneText = '一个月内';
  5470. $scope.condition = {dateZone: 1};
  5471. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5472. $scope.changeAgreed = function(agreed) {
  5473. $scope.condition.agreed = agreed;
  5474. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5475. $scope.condition.$agreedOpen = false;
  5476. };
  5477. $scope.changeDateZone = function(zone) {
  5478. $scope.condition.dateZone = zone;
  5479. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5480. $scope.condition.$dateZoneOpen = false;
  5481. };
  5482. $scope.setActive = function(state) {
  5483. if($scope.active != state) {
  5484. $scope.active = state;
  5485. if($scope.tableParams.page() == 1)
  5486. $scope.tableParams.reload();
  5487. else
  5488. $scope.tableParams.page(1);
  5489. }
  5490. };
  5491. var getService = function() {
  5492. return PurcBadOut;
  5493. };
  5494. $scope.tableParams = new ngTableParams({
  5495. page : 1,
  5496. count : 5,
  5497. sorting: {
  5498. date: 'desc'
  5499. }
  5500. }, {
  5501. total : 0,
  5502. counts: [5, 10, 25, 50],
  5503. getData : function($defer, params) {
  5504. $scope.loading = true;
  5505. var pageParams = params.url();
  5506. pageParams.keyword = $scope.keyword;
  5507. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5508. $scope.loading = false;
  5509. if(page) {
  5510. params.total(page.totalElement);
  5511. $defer.resolve(page.content);
  5512. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5513. }
  5514. }, function(response){
  5515. $scope.loading = false;
  5516. toaster.pop('error', '数据加载失败', response.data);
  5517. });
  5518. }
  5519. });
  5520. $scope.openDatePicker = function($event, item, openParam) {
  5521. $event.preventDefault();
  5522. $event.stopPropagation();
  5523. item[openParam] = !item[openParam];
  5524. };
  5525. // 搜索框回车
  5526. $scope.onSearch = function() {
  5527. $scope.tableParams.page(1);
  5528. $scope.tableParams.reload();
  5529. };
  5530. }]);
  5531. /**
  5532. * 客户MRB
  5533. */
  5534. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  5535. BaseService.scrollBackToTop();
  5536. $scope.active = 'all';
  5537. $scope.agreedText = '全部';
  5538. $scope.dateZoneText = '一个月内';
  5539. $scope.condition = {dateZone: 1};
  5540. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5541. $scope.changeAgreed = function(agreed) {
  5542. $scope.condition.agreed = agreed;
  5543. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  5544. $scope.condition.$agreedOpen = false;
  5545. };
  5546. $scope.changeDateZone = function(zone) {
  5547. $scope.condition.dateZone = zone;
  5548. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  5549. $scope.condition.$dateZoneOpen = false;
  5550. };
  5551. $scope.setActive = function(state) {
  5552. if($scope.active != state) {
  5553. $scope.active = state;
  5554. if($scope.tableParams.page() == 1)
  5555. $scope.tableParams.reload();
  5556. else
  5557. $scope.tableParams.page(1);
  5558. }
  5559. };
  5560. var getService = function() {
  5561. return PurcMRB;
  5562. };
  5563. $scope.tableParams = new ngTableParams({
  5564. page : 1,
  5565. count : 5,
  5566. sorting: {
  5567. date: 'desc'
  5568. }
  5569. }, {
  5570. total : 0,
  5571. counts: [5, 10, 25, 50],
  5572. getData : function($defer, params) {
  5573. $scope.loading = true;
  5574. var pageParams = params.url();
  5575. pageParams.keyword = $scope.keyword;
  5576. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5577. $scope.loading = false;
  5578. if(page) {
  5579. params.total(page.totalElement);
  5580. $defer.resolve(page.content);
  5581. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5582. }
  5583. }, function(response){
  5584. $scope.loading = false;
  5585. toaster.pop('error', '数据加载失败', response.data);
  5586. });
  5587. }
  5588. });
  5589. $scope.openDatePicker = function($event, item, openParam) {
  5590. $event.preventDefault();
  5591. $event.stopPropagation();
  5592. item[openParam] = !item[openParam];
  5593. };
  5594. // 搜索框回车
  5595. $scope.onSearch = function() {
  5596. $scope.tableParams.page(1);
  5597. $scope.tableParams.reload();
  5598. };
  5599. }]);
  5600. /**
  5601. * 客户应付发票
  5602. */
  5603. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol){
  5604. BaseService.scrollBackToTop();
  5605. $scope.active = 'all';
  5606. $scope.dateZoneText = '不限';
  5607. $scope.condition = {dateZone: -1};
  5608. $scope.changeDateZone = function(zone) {
  5609. $scope.condition.dateZone = zone;
  5610. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5611. $scope.condition.$dateZoneOpen = false;
  5612. getDateCondition(zone, $scope.condition);
  5613. $scope.tableParams.reload();
  5614. };
  5615. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5616. $scope.setActive = function(state) {
  5617. if($scope.active != state) {
  5618. $scope.active = state;
  5619. if($scope.tableParams.page() == 1)
  5620. $scope.tableParams.reload();
  5621. else
  5622. $scope.tableParams.page(1);
  5623. }
  5624. };
  5625. var getService = function() {
  5626. return FaApBill;
  5627. };
  5628. $scope.tableParams = new ngTableParams({
  5629. page : 1,
  5630. count : 5,
  5631. sorting: {
  5632. date: 'desc'
  5633. }
  5634. }, {
  5635. total : 0,
  5636. counts: [5, 10, 25, 50],
  5637. getData : function($defer, params) {
  5638. $scope.loading = true;
  5639. var pageParams = params.url();
  5640. pageParams.searchFilter = { // 筛选条件
  5641. keyword: $scope.keyword,
  5642. fromDate: getDateTime($scope.condition.dateFrom),
  5643. endDate: getDateTime($scope.condition.dateTo)
  5644. };
  5645. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5646. $scope.loading = false;
  5647. if(page) {
  5648. params.total(page.totalElement);
  5649. $defer.resolve(page.content);
  5650. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  5651. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5652. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5653. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  5654. }
  5655. }, function(response){
  5656. $scope.loading = false;
  5657. toaster.pop('error', '数据加载失败', response.data);
  5658. });
  5659. }
  5660. });
  5661. $scope.openDatePicker = function($event, item, openParam) {
  5662. $event.preventDefault();
  5663. $event.stopPropagation();
  5664. item[openParam] = !item[openParam];
  5665. };
  5666. $scope.parseDate = function(dateStr) {
  5667. if(dateStr)
  5668. return Date.parse(dateStr, 'yyyy-MM-dd');
  5669. return new Date();
  5670. };
  5671. // 搜索框回车
  5672. $scope.onSearch = function() {
  5673. $scope.tableParams.page(1);
  5674. $scope.tableParams.reload();
  5675. };
  5676. // 选择查找日期
  5677. $scope.onDateCondition = function(){
  5678. $scope.tableParams.page(1);
  5679. $scope.tableParams.reload();
  5680. };
  5681. }]);
  5682. /**
  5683. * 应付对账单
  5684. */
  5685. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol){
  5686. BaseService.scrollBackToTop();
  5687. $scope.active = 'all';
  5688. $scope.dateZoneText = '不限';
  5689. $scope.condition = {dateZone: -1};
  5690. $scope.changeDateZone = function(zone) {
  5691. $scope.condition.dateZone = zone;
  5692. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5693. $scope.condition.$dateZoneOpen = false;
  5694. getDateCondition(zone, $scope.condition);
  5695. $scope.tableParams.reload();
  5696. };
  5697. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5698. $scope.setActive = function(state) {
  5699. if($scope.active != state) {
  5700. $scope.active = state;
  5701. if($scope.tableParams.page() == 1)
  5702. $scope.tableParams.reload();
  5703. else
  5704. $scope.tableParams.page(1);
  5705. }
  5706. };
  5707. var getService = function() {
  5708. return FaArCheck;
  5709. };
  5710. $scope.tableParams = new ngTableParams({
  5711. page : 1,
  5712. count : 5,
  5713. sorting: {
  5714. date: 'desc'
  5715. }
  5716. }, {
  5717. total : 0,
  5718. counts: [5, 10, 25, 50],
  5719. getData : function($defer, params) {
  5720. $scope.loading = true;
  5721. var pageParams = params.url();
  5722. pageParams.keyword = $scope.keyword;
  5723. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  5724. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  5725. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  5726. $scope.loading = false;
  5727. if(page) {
  5728. params.total(page.totalElement);
  5729. $defer.resolve(page.content);
  5730. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  5731. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  5732. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  5733. }
  5734. }, function(response){
  5735. $scope.loading = false;
  5736. toaster.pop('error', '数据加载失败', response.data);
  5737. });
  5738. }
  5739. });
  5740. $scope.openDatePicker = function($event, item, openParam) {
  5741. $event.preventDefault();
  5742. $event.stopPropagation();
  5743. item[openParam] = !item[openParam];
  5744. };
  5745. // 计算单据的商品总数
  5746. $scope.getTotalProd = function(check) {
  5747. var total = 0;
  5748. if(check.items) {
  5749. angular.forEach(check.items, function(value) {
  5750. total += value.qty;
  5751. });
  5752. }
  5753. return total;
  5754. };
  5755. // 搜索框回车
  5756. $scope.onSearch = function() {
  5757. $scope.tableParams.page(1);
  5758. $scope.tableParams.reload();
  5759. };
  5760. // 选择查找日期
  5761. $scope.onDateCondition = function(){
  5762. $scope.tableParams.page(1);
  5763. $scope.tableParams.reload();
  5764. };
  5765. }]);
  5766. // 应付对账单详情页
  5767. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function($scope, $stateParams, FaArCheck, toaster, $state, BaseService){
  5768. BaseService.scrollBackToTop();
  5769. var loadData = function() {
  5770. FaArCheck.get({id: $stateParams.id}, function(data){
  5771. $scope.order = data;
  5772. $scope.loading = false;
  5773. });
  5774. };
  5775. loadData(); // 初始获取单据数据
  5776. $scope.onReplyClick = function(item, isAgreed) {
  5777. if(isAgreed) {// 同意确认
  5778. FaArCheck.agree({itemId: item.id}, {}, function(data){
  5779. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  5780. }, function(response){
  5781. toaster.pop('danger', '确认失败', response.data);
  5782. });
  5783. } else {// 不同意回复
  5784. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  5785. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  5786. }, function(response) {
  5787. toaster.pop('danger', '确认失败', response.data);
  5788. });
  5789. }
  5790. };
  5791. // 获取明细的回复记录
  5792. $scope.getReplies = function(item) {
  5793. if(!item.replies) {
  5794. FaArCheck.getReplies({itemId: item.id}, function(data) {
  5795. item.replies = data;
  5796. }, function(response) {
  5797. toaster.pop('danger', '获取对账记录失败', response.data);
  5798. });
  5799. }
  5800. };
  5801. }]);
  5802. //应收对账单列表
  5803. app.controller('PurchaseApCheckCtrl',['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService , Symbol){
  5804. BaseService.scrollBackToTop();
  5805. $scope.dateZoneText = '不限';
  5806. $scope.condition = {dateZone: -1};
  5807. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  5808. $scope.active = 'todo';
  5809. //打印 对账单
  5810. $scope.print = function(check) {
  5811. FaApCheck.printCount({id: check.id},{});//增加打印此次
  5812. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id);
  5813. };
  5814. //状态
  5815. $scope.setActive = function (state){
  5816. if($scope.active != state) {
  5817. $scope.active = state;
  5818. if($scope.tableParams.page() == 1)
  5819. $scope.tableParams.reload();
  5820. else
  5821. $scope.tableParams.page(1);
  5822. }
  5823. };
  5824. $scope.changeDateZone = function(zone) {
  5825. $scope.condition.dateZone = zone;
  5826. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  5827. $scope.condition.$dateZoneOpen = false;
  5828. getDateCondition(zone, $scope.condition);
  5829. $scope.tableParams.reload();
  5830. };
  5831. //获取应收对账单全部
  5832. $scope.tableParams = new ngTableParams({
  5833. page : 1,
  5834. count : 5,
  5835. sorting: {
  5836. recordDate: 'desc'
  5837. }
  5838. }, {
  5839. total : 0,
  5840. counts: [5, 10, 25, 50],
  5841. getData : function($defer, params) {
  5842. $scope.loading = true;
  5843. var pageParams = params.url();
  5844. pageParams.searchFilter = { // 筛选条件
  5845. keyword: $scope.keyword,
  5846. fromDate: getDateTime($scope.condition.dateFrom),
  5847. endDate: getDateTime($scope.condition.dateTo)
  5848. };
  5849. FaApCheck[getState($scope.active )](BaseService.parseParams(pageParams), function(page){
  5850. $scope.loading = false;
  5851. if(page) {
  5852. params.total(page.totalElement);
  5853. $scope.data = $defer.resolve(page.content);
  5854. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  5855. }
  5856. }, function(response){
  5857. $scope.loading = false;
  5858. toaster.pop('error', '数据加载失败', response.data);
  5859. });
  5860. }
  5861. });
  5862. $scope.openDatePicker = function($event, item, openParam) {
  5863. $event.preventDefault();
  5864. $event.stopPropagation();
  5865. item[openParam] = !item[openParam];
  5866. };
  5867. // 计算单据的商品总数
  5868. $scope.getTotalProd = function(check) {
  5869. var total = 0;
  5870. if(check.items) {
  5871. angular.forEach(check.items, function(value) {
  5872. total += value.checkQty;
  5873. });
  5874. }
  5875. return total;
  5876. };
  5877. // 搜索框回车
  5878. $scope.onSearch = function() {
  5879. $scope.tableParams.page(1);
  5880. $scope.tableParams.reload();
  5881. };
  5882. // 选择查找日期
  5883. $scope.onDateCondition = function(){
  5884. $scope.tableParams.page(1);
  5885. $scope.tableParams.reload();
  5886. };
  5887. }]);
  5888. //应收对账单详情
  5889. app.controller('PurchaseApCheckDetailCtrl',['$scope','toaster','FaApCheck','$stateParams', 'BaseService', function($scope, toaster, FaApCheck, $stateParams, BaseService) {
  5890. BaseService.scrollBackToTop();
  5891. $scope.haveSelected = true;
  5892. $scope.data = {};
  5893. //控制提交和删除按钮的显示
  5894. $scope.ifShow = true;
  5895. var loadData = function(){
  5896. FaApCheck.get({id:$stateParams.id},function(data){
  5897. $scope.data = data;
  5898. if($scope.data.status){
  5899. }else{
  5900. $scope.ifShow = true;
  5901. }
  5902. })
  5903. };
  5904. if($stateParams.id){
  5905. loadData();
  5906. }
  5907. $scope.haveSource = false;
  5908. //提交应收对账单
  5909. $scope.submitApCheck = function(){
  5910. FaApCheck.updateStatus({id:$stateParams.id},function(data){
  5911. if(data.result) {
  5912. toaster.pop('success', '提示', '提交成功');
  5913. $scope.haveSelected = false;
  5914. window.location.href = '#/fa/apCheck';
  5915. }else {
  5916. $scope.haveSource = true;
  5917. loadData();
  5918. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  5919. $scope.haveSelected = true;
  5920. }
  5921. },function(){
  5922. $scope.loading = false;
  5923. toaster.pop('error', '提示', '更新已转数失败');
  5924. });
  5925. }
  5926. //删除应收对账单的同时更新来源表已转数
  5927. var updateYCheckQty = function(){
  5928. var sourceInfos = [];
  5929. angular.forEach($scope.data.items, function(item){
  5930. $scope.sourceInfo = {
  5931. sourceId: '',
  5932. sourceTable: '',
  5933. newYCheckQty: ''
  5934. };
  5935. $scope.sourceInfo.sourceId = item.sourceId;
  5936. $scope.sourceInfo.sourceTable = item.sourceTable;
  5937. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  5938. sourceInfos.push($scope.sourceInfo);
  5939. });
  5940. FaApCheck.update({}, sourceInfos, function(){
  5941. },function(response){
  5942. $scope.loading = false;
  5943. toaster.pop('error', '更新已转数失败', response.data);
  5944. });
  5945. }
  5946. //删除应收对账单
  5947. $scope.deleteApCheck = function(){
  5948. FaApCheck.deleteApCheck({id:$stateParams.id},function(data){
  5949. updateYCheckQty();
  5950. toaster.pop('success','提示','删除成功');
  5951. },function(){
  5952. toaster.pop('error','提示','删除失败');
  5953. });
  5954. $scope.haveSelected = false;
  5955. }
  5956. //作废应收对账单
  5957. $scope.cancelApCheck = function(check) {
  5958. FaApCheck.cancel({id:check.id},function(data){
  5959. $scope.checkResult = false;
  5960. if(data.result) {
  5961. $scope.checkResult = true;
  5962. toaster.pop('success', '提示', '作废成功');
  5963. $scope.tableParams.reload();
  5964. }else{
  5965. toaster.pop('error', '提示', '作废失败');
  5966. }
  5967. },function(){
  5968. $scope.loading = false;
  5969. toaster.pop('error', '提示', '作废失败');
  5970. });
  5971. }
  5972. }]);
  5973. //未对账单据列表
  5974. app.controller('PurchaseApCheckListCtrl',['$scope', 'FaApCheck', 'toaster', '$state','$filter', '$modal', function($scope, FaApCheck, toaster, $state, $filter, $modal){
  5975. $scope.data = [];// 列表数据
  5976. $scope.condition = {
  5977. $fromOpened: false
  5978. }
  5979. $scope.openDatePicker = function($event, item, openParam) {
  5980. $event.preventDefault();
  5981. $event.stopPropagation();
  5982. item[openParam] = !item[openParam];
  5983. }
  5984. //查找客户
  5985. $scope.searchCust = function(suuorname) {
  5986. var modalInstance = $modal.open({
  5987. animation: true,
  5988. templateUrl: 'static/tpl/index/fa/custInfo.html',
  5989. controller: 'SearchCustInfoCtrl',
  5990. resolve: {
  5991. suuorname: function() {
  5992. return suuorname;
  5993. }
  5994. }
  5995. });
  5996. modalInstance.result.then(function(suuorname){
  5997. $scope.suuorname = suuorname;
  5998. });
  5999. }
  6000. // 点击筛选根据条件选择数据
  6001. $scope.suuorname = '';
  6002. // 默认本月
  6003. $scope.sdateTo = new Date();
  6004. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  6005. $scope.vuuorname = '';
  6006. $scope.factory = '';
  6007. $scope.prodTitle = '';
  6008. $scope.prodSpec = '';
  6009. $scope.condition.uuorname = '';
  6010. $scope.condition.dateFrom = '';
  6011. $scope.condition.dateTo = '';
  6012. $scope.condition.venduuorname = '';
  6013. $scope.condition.factory = '';
  6014. $scope.condition.prodTitle = '';
  6015. $scope.condition.prodSpec = '';
  6016. $scope.searchOrder = function(check) {
  6017. $scope.data = [];
  6018. $scope.checkboxes.checked = false;
  6019. $scope.totalMoney = 0;
  6020. $scope.condition.uuorname = $scope.suuorname;
  6021. $scope.condition.factory = $scope.factory
  6022. $scope.condition.prodTitle = $scope.prodTitle;
  6023. $scope.condition.prodSpec = $scope.prodSpec;
  6024. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  6025. $scope.thisdatato = ($scope.sdateTo || 0);
  6026. if($scope.thisdatato != 0) {
  6027. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf() + 3600 * 12 * 1000) || 0);
  6028. } else {
  6029. $scope.condition.dateTo = ($scope.sdateTo || 0);
  6030. }
  6031. $scope.condition.venduuorname = $scope.vuuorname;
  6032. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  6033. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6034. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6035. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  6036. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  6037. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  6038. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  6039. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  6040. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6041. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6042. if(!$scope.suuorname) {
  6043. toaster.pop('warning','提示', '请先选择客户');
  6044. document.getElementById('suuorname').focus();//光标默认在客户
  6045. } else {
  6046. $scope.loading = true;
  6047. FaApCheck.getAllByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  6048. if(data.length > 0) {
  6049. angular.forEach(data, function(item) {
  6050. item.$selected = true;
  6051. });
  6052. $scope.data = data;
  6053. $scope.checkboxes.checked = true;
  6054. $scope.getTotalMoney();
  6055. } else {
  6056. toaster.pop('info', '提示', '当前没有需要对账记录');
  6057. }
  6058. $scope.loading = false;
  6059. }, function(response) {
  6060. $scope.loading = false;
  6061. toaster.pop('error', '提示', response.data);
  6062. });
  6063. }
  6064. }
  6065. }
  6066. /**
  6067. * 点击勾选框,选中要转应收对账单的订单
  6068. * */
  6069. $scope.totalMoney = 0;
  6070. $scope.checkboxes = {
  6071. checked : false
  6072. };
  6073. // 点击勾选全部的复选框
  6074. $scope.checkAll = function(){
  6075. $scope.totalMoney = 0;
  6076. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  6077. var uuorname = $scope.suuorname;
  6078. var venduuorname = $scope.venduuorname;
  6079. var dateFrom = $scope.condition.dateFrom;
  6080. var dateTo = $scope.condition.dateTo;
  6081. var prodTitle = $scope.condition.prodTitle;
  6082. var prodSpec = $scope.condition.prodSpec;
  6083. var factory = $scope.condition.factory;
  6084. angular.forEach($scope.filteredData, function(item) {
  6085. if((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')){
  6086. item.$selected = $scope.checkboxes.checked;
  6087. }
  6088. });
  6089. $scope.getTotalMoney();
  6090. };
  6091. //获取已选单据总金额
  6092. var total = true;
  6093. $scope.getTotalMoney = function(){
  6094. $scope.totalMoney = 0;
  6095. angular.forEach($scope.data, function(check) {
  6096. if(check.$selected){
  6097. $scope.totalMoney += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6098. }else{
  6099. $scope.totalMoney += 0;
  6100. }
  6101. });
  6102. }
  6103. // 点击其中一个明细的复选框
  6104. $scope.checkOne = function(check){
  6105. var result = true;
  6106. angular.forEach($scope.data, function(item) {
  6107. if(item.$selected != true){
  6108. result = false;
  6109. return;
  6110. }
  6111. });
  6112. $scope.checkboxes.checked = result;
  6113. };
  6114. $scope.haveSelected = false;
  6115. //生成应收对账单
  6116. $scope.createApCheck = function(){
  6117. //保存应收对账单主记录字段
  6118. $scope.apCheck = {
  6119. custUu: '',
  6120. custName: '',
  6121. enUu: '',
  6122. apDate: '',
  6123. beginDate: '',
  6124. endDate: '',
  6125. checkStatus: '未对账',
  6126. checkAmount: 0,
  6127. currency: '',
  6128. rate: '',
  6129. items: []
  6130. };
  6131. //保存来源单据相关信息
  6132. var sourceInfos = [];
  6133. //所允许的本次对账最大最小数量
  6134. $scope.data.maxThisCheckQty = 0;
  6135. $scope.data.minThisCheckQty = 0;
  6136. $scope.sameCust = true;
  6137. $scope.validQty = true;
  6138. $scope.loading = true;
  6139. angular.forEach($scope.data, function(check) {
  6140. //保存应收对账单明细行数据
  6141. $scope.item = {
  6142. inoutno: '',
  6143. inoutnodetno: '',
  6144. orderCode: '',
  6145. orderClass: '',
  6146. orderDetno: '',
  6147. price: '',
  6148. checkQty: '',
  6149. amount: '',
  6150. sourceId:'',
  6151. sourceTable:'',
  6152. oldYCheckQty:'',
  6153. status: 0,
  6154. receiveCode:'',
  6155. receiveName:'',
  6156. prodCode:'',
  6157. prodTitle:'',
  6158. prodSpec:'',
  6159. taxrate: '',
  6160. sendcode: '',
  6161. whname: '',
  6162. };
  6163. //应收对账单明细行来源表信息
  6164. $scope.sourceInfo = {
  6165. sourceId: '',
  6166. sourceTable: '',
  6167. newYCheckQty: ''
  6168. };
  6169. //此次对账后新的已转数
  6170. $scope.newYCheckQty = 0;
  6171. if(check.$selected == true) {
  6172. $scope.apCheck.custName = check.custName;
  6173. $scope.apCheck.enUu = check.enUu;
  6174. $scope.apCheck.checkAmount += (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6175. $scope.apCheck.apDate = check.piDate;
  6176. $scope.apCheck.rate = check.rate;
  6177. //必须是同一家客户才能生成对账单,否则提示错误
  6178. if($scope.apCheck.custUu == ''){
  6179. $scope.apCheck.custUu = check.custUu;
  6180. }else if($scope.apCheck.custUu !== check.custUu){
  6181. $scope.sameCust = false;
  6182. $scope.loading = false;
  6183. toaster.pop('error', '请选择同一家客户');
  6184. }
  6185. //必须是相同币别才能生成对账单,否则提示错误
  6186. if($scope.apCheck.currency == ''){
  6187. $scope.apCheck.currency = check.currency;
  6188. }else if($scope.apCheck.currency !== check.currency){
  6189. $scope.sameCust = false;
  6190. $scope.loading = false;
  6191. toaster.pop('error', '请选择同一种币别');
  6192. }
  6193. //本次对账数量必须小于总对账数量
  6194. if(check.qty > 0){
  6195. $scope.data.maxThisCheckQty = check.qty;
  6196. $scope.data.minThisCheckQty = 0;
  6197. if(check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0){
  6198. $scope.validQty = false;
  6199. $scope.loading = false;
  6200. toaster.pop('error','本次对账数量,填写有误!');
  6201. }
  6202. }else if(check.qty < 0){
  6203. $scope.data.maxThisCheckQty = 0;
  6204. $scope.data.minThisCheckQty = check.qty;
  6205. if(((-check.qty)-(-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0){
  6206. $scope.validQty = false;
  6207. $scope.loading = false;
  6208. toaster.pop('error','本次对账数量,填写有误!');
  6209. }
  6210. }
  6211. //获取最小时间作为对账区间的起始时间
  6212. if($scope.apCheck.beginDate == ''){
  6213. $scope.apCheck.beginDate = check.piDate;
  6214. }else{
  6215. $scope.apCheck.beginDate = $scope.apCheck.beginDate>check.piDate? check.piDate : $scope.apCheck.beginDate;
  6216. }
  6217. //获取最大时间作为对账区间的截止时间
  6218. if($scope.apCheck.endDate == ''){
  6219. $scope.apCheck.endDate = check.piDate;
  6220. }else{
  6221. $scope.apCheck.endDate = $scope.apCheck.endDate<check.piDate? check.piDate : $scope.apCheck.endDate;
  6222. }
  6223. //应收对账单明细行数据
  6224. $scope.item.orderCode = check.orderCode;
  6225. $scope.item.orderClass = check.piClass;
  6226. $scope.item.orderDetno = check.orderDetno;
  6227. $scope.item.price = check.orderPrice;
  6228. $scope.item.checkQty = check.thisCheckQty;
  6229. $scope.item.amount = (check.thisCheckQty || 0)*(check.orderPrice || 0);
  6230. $scope.item.sourceId = check.sourceId;
  6231. $scope.item.sourceTable = check.sourceTable;
  6232. $scope.item.oldYCheckQty = check.yCheckQty;
  6233. $scope.item.prodCode = check.prodCode;
  6234. $scope.item.prodTitle = check.prodTitle;
  6235. $scope.item.prodSpec = check.prodSpec;
  6236. $scope.item.inoutno = check.inOutNo;
  6237. $scope.item.inoutnodetno = check.detno;
  6238. $scope.item.taxrate = check.taxrate;
  6239. $scope.item.receiveCode = check.receiveCode;
  6240. $scope.item.receiveName = check.receiveName;
  6241. $scope.item.sendcode = check.sendcode;
  6242. $scope.item.whname = check.whname;
  6243. //来源表相关信息
  6244. $scope.sourceInfo.sourceId = check.sourceId;
  6245. $scope.sourceInfo.sourceTable = check.sourceTable;
  6246. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  6247. sourceInfos.push($scope.sourceInfo);
  6248. $scope.apCheck.items.push($scope.item);
  6249. $scope.haveSelected = true;
  6250. }
  6251. });
  6252. //保存生成的应收对账单
  6253. $scope.saveApCheck = function(){
  6254. FaApCheck.saveApCheck({}, $scope.apCheck, function(data){
  6255. $scope.loading = false;
  6256. toaster.pop('success', '成功', '生成应收对账成功');
  6257. $state.go('fa.apCheck_detail', {id: data.id}, {reload:true});
  6258. }, function(response){
  6259. toaster.pop('error', '生成对账单失败', response.data);
  6260. })
  6261. };
  6262. //如果是同一家客户,生成对账单的同时,关闭模态框
  6263. if($scope.sameCust && $scope.validQty) {
  6264. $scope.saveApCheck();
  6265. }
  6266. }
  6267. }]);
  6268. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', function($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http){
  6269. BaseService.scrollBackToTop();
  6270. $scope.loading = true;
  6271. AccountEnterprise.get({}, function(data){
  6272. $scope.loading = false;
  6273. $scope.enterprise = data;
  6274. });
  6275. AccountEnterprise.growth({}, function(data){
  6276. if(data != null && data.length > 0) {
  6277. var growth = [], years = [];
  6278. angular.forEach(data, function(d){
  6279. var date = new Date(d.date), year = date.getFullYear();
  6280. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  6281. if(years.indexOf(year) == -1) {
  6282. years.push(year);
  6283. growth.push({year: year});
  6284. }
  6285. growth.push(d);
  6286. });
  6287. $scope.growth = growth;
  6288. }
  6289. });
  6290. // 更新企业信息
  6291. $scope.updateDetailInfo = function(){
  6292. $scope.loading = true;
  6293. AccountEnterprise.save($scope.enterprise, function(){
  6294. $scope.loading = false;
  6295. $scope.connectionEditing = false;
  6296. toaster.pop('success', '提示', '修改企业信息成功');
  6297. $state.reload();
  6298. }, function(response){
  6299. $scope.loading = false;
  6300. toaster.pop('error', '修改信息失败', response.data);
  6301. });
  6302. };
  6303. // 申请Saas
  6304. $scope.applySaas = function(){
  6305. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  6306. var modalInstance = $modal.open({
  6307. animation: true,
  6308. templateUrl: 'static/tpl/index/account/applySaas.html',
  6309. controller: 'ApplySaasCtrl',
  6310. resolve: {
  6311. enterprise: function(){return angular.copy($scope.enterprise);}
  6312. }
  6313. });
  6314. modalInstance.result.then(function(){
  6315. $state.reload();
  6316. }, function(){
  6317. });
  6318. } else {
  6319. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  6320. }
  6321. };
  6322. // 获取收货地址列表
  6323. ShipAddress.shipAddList({}, function(data) {
  6324. $scope.ships = data;
  6325. });
  6326. // 获取地址信息
  6327. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  6328. }).then(function(response) {
  6329. $scope.provinces = response.data;
  6330. });
  6331. // 新增收货地址保存
  6332. $scope.saveShipAddress = function(ship) {
  6333. ship.address = ship.province + ship.city + ship.district;
  6334. ShipAddress.saveAddress( {}, ship, function(data) {
  6335. if(data.success) {
  6336. ShipAddress.shipAddList({}, function(data) {
  6337. $scope.ships = data;
  6338. });
  6339. toaster.pop('success', '提示', data.success);
  6340. }
  6341. if(data.error) {
  6342. toaster.pop('error', '提示', data.error);
  6343. }
  6344. });
  6345. }
  6346. // 删除收货地址
  6347. $scope.removeShip = function(id, index) {
  6348. ShipAddress.removeShipAddress({id: id}, {}, function(data) {
  6349. $scope.ships.splice(index, 1);
  6350. toaster.pop('success', '提示', '收货地址删除成功');
  6351. }, function(response) {
  6352. toaster.pop('error', '提示', response.data);
  6353. });
  6354. };
  6355. // 编辑收货地址
  6356. $scope.editShip = function(ship){
  6357. var modalInstance = $modal.open({
  6358. animation: true,
  6359. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  6360. controller: 'ShipAddressCtrl',
  6361. resolve: {
  6362. ship: function(){return ship;}
  6363. }
  6364. });
  6365. modalInstance.result.then(function() {
  6366. ShipAddress.shipAddList({}, function(data) {
  6367. $scope.ships = data;
  6368. });
  6369. }, function(){
  6370. });
  6371. };
  6372. // 设置logo
  6373. $scope.showImageDialog = function(modal) {
  6374. require([ 'jquery-uploadify' ], function() {
  6375. $modal.open({
  6376. templateUrl : 'static/tpl/index/home/insert.html',
  6377. controller : 'ImageInsertCtrl',
  6378. backdrop : 'static'
  6379. }).result.then(function(image){
  6380. $scope.imageUrl = image.thumb;
  6381. User.postImageUrl(null, angular.toJson($scope.imageUrl), function(data){
  6382. $scope.user = data;
  6383. }, function(response) {
  6384. toaster.pop('error', '设置图像失败,' + response.data);
  6385. });
  6386. });
  6387. });
  6388. }
  6389. }]);
  6390. // 编辑收货地址
  6391. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  6392. $scope.ship = ship;
  6393. // 获取地址信息
  6394. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  6395. }).then(function(response) {
  6396. $scope.provinces = response.data;
  6397. });
  6398. // 新增收货地址保存
  6399. $scope.saveShipAddress = function(ship) {
  6400. ship.address = ship.province + ship.city + ship.district;
  6401. ShipAddress.saveAddress( {}, ship, function(data) {
  6402. if(data.success) {
  6403. toaster.pop('success', '提示', data.success);
  6404. $modalInstance.close();
  6405. }
  6406. if(data.error) {
  6407. toaster.pop('error', '提示', data.error);
  6408. }
  6409. });
  6410. }
  6411. $scope.cancel = function() {
  6412. $modalInstance.dismiss();
  6413. }
  6414. }]);
  6415. // 申请Saas Controller
  6416. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  6417. $scope.enterprise = enterprise;
  6418. $scope.checking = false;
  6419. $scope.$watch('enterprise.enSaasUrl', function(){
  6420. if($scope.enterprise.enSaasUrl) {
  6421. $http.get('signup/saasUrlEnable', {
  6422. params: {
  6423. enSaasUrl: $scope.enterprise.enSaasUrl
  6424. }
  6425. }).success(function(data){
  6426. if(data && data == 'true') {
  6427. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  6428. } else {
  6429. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6430. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  6431. }
  6432. }).error(function(){
  6433. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6434. $scope.enSaasUrlErrorInfo = '验证出错';
  6435. });
  6436. } else {
  6437. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  6438. }
  6439. });
  6440. var setSaasUrl = function(url) {
  6441. var index = url.indexOf('www.');
  6442. if(index != -1) {//包含www.
  6443. var substr = url.substring(index+4, url.length);
  6444. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  6445. } else {
  6446. $scope.enterprise.enSaasUrl = getHost(url);
  6447. }
  6448. };
  6449. // 解析获取网址的一级域名
  6450. var getHost = function(host){
  6451. var newhost;
  6452. var domain;
  6453. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  6454. for(var k in ArrDomain){
  6455. var re = eval('/\\' + ArrDomain[k] + '$/g');
  6456. newhost = host.replace(re, '');
  6457. if(newhost != host){
  6458. domain = ArrDomain[k];
  6459. break;
  6460. }
  6461. }
  6462. var hostar = newhost.split('.');
  6463. var s = hostar[hostar.length-1];
  6464. return s;
  6465. };
  6466. // 设置优企云服域名为官网网址一级域名
  6467. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  6468. $scope.apply = function(){
  6469. $scope.loading = true;
  6470. AccountEnterprise.applySaas({
  6471. enUU: $scope.enterprise.uu,
  6472. enSaasUrl: $scope.enterprise.enSaasUrl,
  6473. enAdminPassword: $scope.enterprise.enAdminPassword
  6474. }, {}, function(){
  6475. $scope.loading = false;
  6476. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  6477. $modalInstance.close();
  6478. }, function(response){
  6479. $scope.loading = false;
  6480. toaster.pop('error', '申请失败', response.data);
  6481. });
  6482. };
  6483. $scope.cancel = function () {
  6484. $modalInstance.dismiss();
  6485. };
  6486. }]);
  6487. 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){
  6488. BaseService.scrollBackToTop();
  6489. $scope.editing = false;
  6490. $scope.loading = true;
  6491. $scope.enterprise = null;
  6492. AccountUser.findDistribute({},function(data) {
  6493. $scope.distributes = data;
  6494. },function(response) {
  6495. toaster.pop('error', '系统错误', response.data);
  6496. })
  6497. AuthenticationService.getAuthentication().success(function(data) {
  6498. $scope.loading = false;
  6499. $scope.user = data;
  6500. });
  6501. var users = [];
  6502. $scope.tableParams = new ngTableParams({
  6503. page : 1,
  6504. count : 5,
  6505. sorting: {
  6506. userName: 'asc'
  6507. }
  6508. }, {
  6509. total : 0,
  6510. counts: [15, 25, 50, 100],
  6511. getData : function($defer, params) {
  6512. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  6513. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  6514. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  6515. angular.forEach($scope.users,function(user){
  6516. AccountEnterprise.get({}, function(data){
  6517. $scope.loading = false;
  6518. $scope.enterprise = data;
  6519. });
  6520. });
  6521. params.total(orderedData.length);
  6522. $defer.resolve($scope.users);
  6523. }
  6524. });
  6525. var loadUsers = function() {
  6526. AccountUser.query({}, function(data){
  6527. users = data;
  6528. $scope.tableParams.reload();
  6529. $scope.loading = false;
  6530. });
  6531. };
  6532. loadUsers();
  6533. $scope.saveUser = function(){
  6534. $scope.loading = true;
  6535. AccountUser.update({}, $scope.user, function(data){
  6536. $scope.loading = false;
  6537. toaster.pop('success', '提示', '修改用户信息成功');
  6538. AuthenticationService.getAuthentication().success(function(data) {
  6539. $scope.user = data;
  6540. });
  6541. loadUsers();
  6542. $scope.editing = false;
  6543. }, function(reponse){
  6544. $scope.loading = false;
  6545. toaster.pop('error', '失败', reponse.data);
  6546. });
  6547. };
  6548. $scope.updatePassword = function(){
  6549. var modalInstance = $modal.open({
  6550. animation: true,
  6551. templateUrl: 'updatePassword.html',
  6552. controller: 'PasswordCtrl',
  6553. resolve: {
  6554. user: function(){return $scope.user;}
  6555. }
  6556. });
  6557. modalInstance.result.then(function(){
  6558. }, function(){
  6559. });
  6560. };
  6561. $scope.newUser = {};
  6562. //弹出添加用户模态框
  6563. $scope.addExistUser = function(){
  6564. var modalInstance = $modal.open({
  6565. animation :true,
  6566. templateUrl : 'static/tpl/index/account/addExistUser.html',
  6567. controller : 'AddExistUserCtrl'
  6568. });
  6569. modalInstance.result.then(function(){
  6570. $scope.userTelSuccess = false;
  6571. $scope.userTelError = false;
  6572. }, function(){
  6573. });
  6574. };
  6575. /**
  6576. * 添加未注册用户
  6577. */
  6578. $scope.addUser = function() {
  6579. $scope.adding = true;
  6580. AccountUser.save({}, $scope.newUser, function(){
  6581. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  6582. $scope.newUser = {userSex: 'M'};
  6583. loadUsers();
  6584. $scope.adding = false;
  6585. $scope.newUserForm.newUserTel.$setValidity('available', false);
  6586. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  6587. $scope.userTelSuccess = false;
  6588. $scope.userTelError = false;
  6589. $scope.userEmailSuccess = false;
  6590. $scope.userEmailError = false;
  6591. }, function(response){
  6592. toaster.pop('error', '错误', response.data);
  6593. });
  6594. };
  6595. /**
  6596. * 验证手机号是否可用
  6597. */
  6598. $scope.telValid = function(tel) {
  6599. if(tel) {
  6600. $http.get('account/user/telEnable', {
  6601. params: {
  6602. tel: tel
  6603. }
  6604. }).success(function(data){
  6605. data = eval(data);
  6606. if(data == true) {
  6607. $scope.newUserForm.newUserTel.$setValidity('available', true);
  6608. $scope.userTelSuccess = true;
  6609. $scope.userTelError = false;
  6610. }else{
  6611. $scope.newUserForm.newUserTel.$setValidity('available', false);
  6612. $scope.userTelError = true;
  6613. $scope.userTelSuccess = false;
  6614. if(tel.length == 11)
  6615. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  6616. }
  6617. }).error(function(){
  6618. $scope.userTelSuccess = false;
  6619. $scope.userTelError = true;
  6620. });
  6621. } else {
  6622. $scope.userTelSuccess = false;
  6623. $scope.userTelError = false;
  6624. }
  6625. };
  6626. /**
  6627. * 验证邮箱是否可用
  6628. */
  6629. $scope.emailValid = function(email) {
  6630. if(email) {
  6631. $http.get('account/user/emailEnable', {
  6632. params: {
  6633. email: email
  6634. }
  6635. }).success(function(data){
  6636. data = eval(data);
  6637. if(data == true) {
  6638. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  6639. $scope.userEmailSuccess = true;
  6640. $scope.userEmailError = false;
  6641. } else {
  6642. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  6643. $scope.userEmailError = true;
  6644. $scope.userEmailSuccess = false;
  6645. }
  6646. }).error(function(){
  6647. $scope.userEmailError = true;
  6648. $scope.userEmailSuccess = false;
  6649. });
  6650. } else {
  6651. $scope.userEmailError = false;
  6652. $scope.userEmailSuccess = false;
  6653. }
  6654. };
  6655. /**
  6656. * 删除用户
  6657. */
  6658. $scope.removeUser = function(user) {
  6659. new ngAlert({
  6660. title: '提示',
  6661. content: '确定删除用户(' + user.userName + ')吗?'
  6662. }, function(){
  6663. AccountUser.remove({uu: user.userUU}, function(){
  6664. toaster.pop('success', '提示', '用户删除成功。');
  6665. loadUsers();
  6666. }, function(response){
  6667. toaster.pop('error', '删除失败', response.data);
  6668. });
  6669. });
  6670. };
  6671. // 编辑用户的角色
  6672. $scope.editUserRole = function(user) {
  6673. var modalInstance = $modal.open({
  6674. animation: true,
  6675. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  6676. controller: 'UserRoleCtrl',
  6677. resolve: {
  6678. user: function() {
  6679. return user;
  6680. }
  6681. }
  6682. });
  6683. modalInstance.result.then(function(changed, checked){
  6684. if(changed) {
  6685. if(checked)
  6686. $scope.newUser.roles = checked;
  6687. else
  6688. loadUsers();
  6689. }
  6690. });
  6691. };
  6692. // 为用户分配角色(删除企业)
  6693. $scope.removeVendor = function(user) {
  6694. var resultRole = true;
  6695. angular.forEach(user.roles,function(role){
  6696. if(role.issys == 1) {
  6697. toaster.pop('error', '提示', '管理员无需分配客户');
  6698. resultRole = false;
  6699. return;
  6700. }
  6701. })
  6702. if(resultRole) {
  6703. var modalInstance = $modal.open({
  6704. animation: true,
  6705. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  6706. controller: 'RemoveVendorCtrl',
  6707. resolve: {
  6708. user: function() {
  6709. return user;
  6710. }
  6711. }
  6712. });
  6713. }
  6714. }
  6715. // 为用户分配角色(添加企业)
  6716. $scope.addVendor = function(user,isIssy) {
  6717. if(!isIssy) {
  6718. toaster.pop('error', '提示', '你不是管理员,无权限分配!请立即联系管理员');
  6719. return;
  6720. }
  6721. var resultRole = true;
  6722. angular.forEach(user.roles,function(role){
  6723. if(role.issys == 1) {
  6724. toaster.pop('error', '提示', '管理员无需分配客户');
  6725. resultRole = false;
  6726. return;
  6727. }
  6728. })
  6729. if(resultRole) {
  6730. var modalInstance = $modal.open({
  6731. animation: true,
  6732. templateUrl: 'static/tpl/index/account/add_vendor.html',
  6733. controller: 'AddVendorCtrl',
  6734. resolve: {
  6735. user: function() {
  6736. return user;
  6737. }
  6738. }
  6739. });
  6740. modalInstance.result.then(function(changed, checked){
  6741. if(changed) {
  6742. if(checked)
  6743. $scope.newUser.roles = checked;
  6744. else
  6745. loadUsers();
  6746. }
  6747. });
  6748. }
  6749. };
  6750. }]);
  6751. // 登录手机号码验证
  6752. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout){
  6753. $scope.user = user;
  6754. $scope.cancel = function(){
  6755. $modalInstance.close();
  6756. }
  6757. /*$scope.loading = false;
  6758. $scope.btnState = false;
  6759. $scope.clicks = 0;
  6760. var storage = window.localStorage;
  6761. //手机验证码定时器
  6762. $scope.msgInfoError = false;
  6763. var setBtnTimeDown = function(value) {
  6764. if(value > 0) {
  6765. $scope.btnState = true;
  6766. $timeout(function() {
  6767. $scope.$apply(function(){
  6768. storage.setItem("btnTimes", $scope.btnTimes);
  6769. $scope.btnTimes --;
  6770. value --;
  6771. setBtnTimeDown (value);
  6772. });
  6773. }, 500);
  6774. }else{
  6775. $scope.btnState = false;
  6776. }
  6777. };
  6778. if(storage.btnTimes > 1){
  6779. $scope.btnTimes = storage.btnTimes;
  6780. setBtnTimeDown(storage.btnTimes)
  6781. }else{
  6782. storage.removeItem("btnTimes");
  6783. }
  6784. $scope.updateTel = function(phoneCode, userTel, uu){
  6785. $scope.loading = true;
  6786. $scope.msgInfoError = false;
  6787. $scope.result = false;
  6788. //更新联系方式
  6789. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  6790. $scope.loading = false;
  6791. $scope.msgInfoError2 = false;
  6792. $scope.result = true;
  6793. AuthenticationService.getAuthentication().success(function(data) {
  6794. $timeout(function(){
  6795. $modalInstance.dismiss();
  6796. window.location.reload();
  6797. }, 1000);
  6798. }).error(function(response) {
  6799. });
  6800. }, function(response){
  6801. $scope.loading = false;
  6802. $scope.msgInfoError2 = response;
  6803. });
  6804. };
  6805. //获取验证码
  6806. $scope.getPhoneCode = function(userTel){
  6807. var timeInfo = 10;
  6808. $scope.clicks ++;
  6809. $scope.timeInfo = timeInfo;
  6810. if($scope.clicks >= 5){
  6811. $scope.errorloading = true;
  6812. $scope.msgInfoSuccess = false;
  6813. $scope.msgInfoError = false;
  6814. }else{
  6815. $scope.loading = true;
  6816. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  6817. $scope.loading = false;
  6818. $scope.msgInfoSuccess = data.success;
  6819. $scope.sendMsg = data;
  6820. $scope.btnTimes = 60;
  6821. setBtnTimeDown($scope.btnTimes);
  6822. $scope.msgInfoError = false;
  6823. },function(response){
  6824. console.log(response);
  6825. $scope.loading = false;
  6826. $scope.msgInfoError = false;
  6827. $scope.sendCheckMsg = false;
  6828. $scope.msgInfoSuccess = true;
  6829. });
  6830. }
  6831. }; */
  6832. }]);
  6833. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6834. $scope.checkboxes = {
  6835. checked : false
  6836. };
  6837. $scope.loading = true;
  6838. AccountUser.findChooseVendor({uu : user.userUU},function(data) {
  6839. $scope.enters = data;
  6840. $scope.loading = false;
  6841. angular.forEach($scope.enters, function(item) {
  6842. item:{
  6843. $selected:true;
  6844. }
  6845. });
  6846. })
  6847. // 点击勾选全部的复选框
  6848. $scope.checkAll = function() {
  6849. angular.forEach($scope.enters, function(item) {
  6850. item.$selected = $scope.checkboxes.checked;
  6851. });
  6852. };
  6853. // 点击其中一个明细的复选框
  6854. $scope.checkOne = function(vendor){
  6855. var result = true;
  6856. angular.forEach($scope.enters, function(item) {
  6857. if(item.$selected != true){
  6858. result = false;
  6859. return;
  6860. }
  6861. });
  6862. $scope.checkboxes.checked = result;
  6863. };
  6864. $scope.close = function(save) {
  6865. var chooseResult = [];
  6866. if(save) {
  6867. if(user.userUU) {
  6868. angular.forEach($scope.enters, function(item, i) {
  6869. if(item.$selected) {
  6870. chooseResult.push(item.id);
  6871. }
  6872. });
  6873. if(chooseResult.length > 0) {
  6874. $scope.loading = true;
  6875. AccountUser.removeChooseVendor({uu : user.userUU }, chooseResult,function(data) {
  6876. $scope.loading = false;
  6877. toaster.pop('success', '提示', '删除成功');
  6878. $modalInstance.close(false);
  6879. }, function(response){
  6880. $scope.loading = false;
  6881. toaster.pop('error', '删除失败', response.data);
  6882. $modalInstance.close(false);
  6883. })
  6884. } else {
  6885. toaster.pop('error', '删除失败', "您未勾选任何记录");
  6886. }
  6887. } else {
  6888. $modalInstance.close(true, $scope.checkboxes.checked);
  6889. }
  6890. } else {
  6891. $modalInstance.close(false);
  6892. }
  6893. };
  6894. }]);
  6895. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  6896. $scope.checkboxes = {
  6897. checked : false
  6898. };
  6899. $scope.loading = true;
  6900. AccountUser.findVendor({uu : user.userUU},function(data) {
  6901. $scope.enters = data;
  6902. $scope.loading = false;
  6903. // angular.forEach($scope.enters, function(item) {
  6904. // if(item.distribute) {
  6905. // item:{
  6906. // $selected:false;
  6907. // }
  6908. // } else {
  6909. // item:{
  6910. // $selected:true;
  6911. // }
  6912. // }
  6913. // });
  6914. })
  6915. // 点击勾选全部的复选框
  6916. $scope.checkAll = function() {
  6917. angular.forEach($scope.enters, function(item) {
  6918. item.distribute = $scope.checkboxes.checked;
  6919. });
  6920. };
  6921. // 点击其中一个明细的复选框
  6922. $scope.checkOne = function(vendor){
  6923. var result = true;
  6924. angular.forEach($scope.enters, function(item) {
  6925. if(item.distribute != true){
  6926. result = false;
  6927. return;
  6928. }
  6929. });
  6930. $scope.checkboxes.checked = result;
  6931. };
  6932. $scope.close = function(save) {
  6933. var chooseResult = [];
  6934. if(save) {
  6935. if(user.userUU) {
  6936. angular.forEach($scope.enters, function(item, i) {
  6937. // if(item.distribute) {
  6938. chooseResult.push(item);
  6939. // }
  6940. });
  6941. if(chooseResult.length > 0) {
  6942. $scope.loading = true;
  6943. AccountUser.addVendor({uu : user.userUU }, chooseResult,function(data) {
  6944. $scope.loading = false;
  6945. toaster.pop('success', '提示', '保存成功');
  6946. $modalInstance.close(false);
  6947. }, function(response){
  6948. $scope.loading = false;
  6949. toaster.pop('error', '保存失败', response.data);
  6950. $modalInstance.close(false);
  6951. })
  6952. } else {
  6953. toaster.pop('error', '保存失败', "您未勾选任何记录");
  6954. }
  6955. } else {
  6956. $modalInstance.close(true, $scope.checkboxes.checked);
  6957. }
  6958. } else {
  6959. $modalInstance.close(false);
  6960. }
  6961. };
  6962. }]);
  6963. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  6964. $scope.checked = [];
  6965. $scope.master = [];
  6966. AccountRole.query({}, function(data){
  6967. if(user && data) {
  6968. var rs = [], checked = [];
  6969. angular.forEach(user.roles, function(r){
  6970. rs.push(r.id);
  6971. });
  6972. angular.forEach(data, function(d){
  6973. if(rs.indexOf(d.id) > -1) {
  6974. d.$checked = true;
  6975. checked.push(d);
  6976. }
  6977. });
  6978. }
  6979. $scope.roles = data;
  6980. $scope.checked = checked;
  6981. $scope.master = angular.copy($scope.checked);
  6982. });
  6983. $scope.select = function(role) {
  6984. role.$checked = !role.$checked;
  6985. if(role.$checked) {
  6986. $scope.checked.push(role);
  6987. } else {
  6988. angular.forEach($scope.checked, function(c, i){
  6989. if(c.id == role.id)
  6990. $scope.checked.splice(i, 1);
  6991. });
  6992. }
  6993. };
  6994. $scope.isChanged = function() {
  6995. return !angular.equals($scope.master, $scope.checked);
  6996. };
  6997. $scope.close = function(save) {
  6998. if(save) {
  6999. if(user.userUU) {
  7000. user.roles = $scope.checked;
  7001. AccountUser.update({}, user, function(){
  7002. toaster.pop('success', '提示', '保存成功');
  7003. $modalInstance.close(true);
  7004. }, function(response){
  7005. toaster.pop('error', '保存失败', response.data);
  7006. });
  7007. } else {
  7008. $modalInstance.close(true, $scope.checked);
  7009. }
  7010. } else {
  7011. $modalInstance.close(false);
  7012. }
  7013. };
  7014. }]);
  7015. // 修改密码Controller
  7016. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  7017. $scope.user = user;
  7018. $scope.checking = false;
  7019. //输入原密码后验证原密码是否正确
  7020. $scope.checkPassword = function(password) {
  7021. $scope.checking = true;
  7022. $scope.checkSuccess = false;
  7023. $scope.checkFailed = false;
  7024. AccountUser.checkPassword({password: password}, function(data){
  7025. $scope.checkSuccess = true;
  7026. $scope.checking = false;
  7027. $scope.checkFailed = false;
  7028. }, function(response){
  7029. $scope.checkFailed = true;
  7030. $scope.checking = false;
  7031. $scope.checkSuccess = false;
  7032. });
  7033. };
  7034. //修改密码
  7035. $scope.ok = function () {
  7036. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  7037. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  7038. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  7039. $scope.user.password = null;
  7040. $scope.user.newPassword = null;
  7041. $scope.user.newPassword1 = null;
  7042. $scope.checking = false;
  7043. $scope.checkSuccess = false;
  7044. $scope.checkFailed = false;
  7045. }, function(response){
  7046. toaster.pop('error', '错误', response.data);
  7047. });
  7048. } else {
  7049. toaster.pop('error', '错误', '重复密码不一致');
  7050. }
  7051. };
  7052. $scope.cancel = function () {
  7053. $modalInstance.dismiss();
  7054. };
  7055. }]);
  7056. /*
  7057. * 绑定用户到企业
  7058. */
  7059. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', function($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout){
  7060. $scope.searching = false;
  7061. //根据输入的内容查找用户
  7062. $scope.searchUser = function(keyWord) {
  7063. $scope.searching = true;
  7064. $scope.searchSuccess = false;
  7065. $scope.searchFailed = false;
  7066. $scope.illegalError = false;
  7067. $scope.reBindError = false;
  7068. $scope.bindSuccess = false;
  7069. $scope.okDisabled = false;
  7070. FuzzySearch.searchUser({keyWord : keyWord}, function(data){
  7071. $scope.searchSuccess = true;
  7072. $scope.searchFailed = false;
  7073. $scope.user = data; //查询到的用户
  7074. }, function(response){
  7075. $scope.searchSuccess = false;
  7076. $scope.searchFailed = true;
  7077. });
  7078. };
  7079. //确认绑定
  7080. $scope.ok = function (keyWord) {
  7081. AuthenticationService.getAuthentication().success(function(data) {
  7082. $scope.currentUser = data; //当前登录的用户(管理员)
  7083. //不可自己绑定自己
  7084. if($scope.currentUser.userUU == $scope.user.userUU){
  7085. $scope.illegalError = true;
  7086. $scope.okDisabled = true;
  7087. return false;
  7088. }
  7089. //用户未绑定到任何企业时
  7090. if(!$scope.user.enterprises){
  7091. //正常绑定
  7092. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  7093. $scope.bindSuccess = true; //绑定成功
  7094. $scope.okDisabled = true;
  7095. }, function(response){
  7096. });
  7097. return true;
  7098. }
  7099. //用户已绑定到某些企业时
  7100. for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
  7101. if($scope.currentUser.enterprises[i].current){
  7102. for(var j = 0; j < $scope.user.enterprises.length; j++){
  7103. //该用户已绑定到当前企业,不可重复绑定
  7104. if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
  7105. $scope.reBindError = true;
  7106. $scope.okDisabled = true;
  7107. return false;
  7108. }
  7109. }
  7110. //该用户未绑定到当前企业,可以进行绑定
  7111. FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
  7112. $scope.bindSuccess = true; //绑定成功
  7113. $scope.okDisabled = true;
  7114. }, function(response){
  7115. console.log("绑定失败!");
  7116. });
  7117. }
  7118. }
  7119. });
  7120. $timeout(function() {
  7121. $modalInstance.close(true);
  7122. }, 500);
  7123. };
  7124. $scope.cancel = function () {
  7125. $modalInstance.dismiss();
  7126. };
  7127. }]);
  7128. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  7129. $scope.erpParams = new ngTableParams({
  7130. page : 1,
  7131. count : 5,
  7132. sorting: {
  7133. time: 'desc'
  7134. }
  7135. }, {
  7136. total : 0,
  7137. counts: [5, 10, 25, 50],
  7138. getData : function($defer, params) {
  7139. $scope.loading = true;
  7140. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  7141. $scope.loading = false;
  7142. if(page) {
  7143. params.total(page.totalElements);
  7144. $defer.resolve(page.content);
  7145. }
  7146. }, function(response){
  7147. $scope.loading = false;
  7148. toaster.pop('error', '数据加载失败', response.data);
  7149. });
  7150. }
  7151. });
  7152. $scope.usageParams = new ngTableParams({
  7153. page : 1,
  7154. count : 5,
  7155. sorting: {
  7156. time: 'desc'
  7157. }
  7158. }, {
  7159. total : 0,
  7160. counts: [5, 10, 25, 50],
  7161. getData : function($defer, params) {
  7162. $scope.loading = true;
  7163. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  7164. $scope.loading = false;
  7165. if(page) {
  7166. params.total(page.totalElements);
  7167. $defer.resolve(page.content);
  7168. }
  7169. }, function(response){
  7170. $scope.loading = false;
  7171. toaster.pop('error', '数据加载失败', response.data);
  7172. });
  7173. }
  7174. });
  7175. }]);
  7176. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  7177. AccountResource.query({}, function(data){
  7178. if(data && data.length > 0) {
  7179. data[0].$open = true;
  7180. }
  7181. $scope.resources = data;
  7182. });
  7183. }]);
  7184. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  7185. $scope.roles = {};
  7186. var getData = function() {
  7187. AccountRole.query({}, function(data){
  7188. var defaults = [], custom = [];
  7189. angular.forEach(data, function(d){
  7190. if(d.isdefault == 1)
  7191. defaults.push(d);
  7192. else
  7193. custom.push(d);
  7194. });
  7195. $scope.roles = {defaults: defaults, custom: custom};
  7196. });
  7197. };
  7198. getData();
  7199. $scope.editRole = function(role){
  7200. var modalInstance = $modal.open({
  7201. animation: true,
  7202. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  7203. controller: 'RoleEditCtrl',
  7204. resolve: {
  7205. role: function() {
  7206. return role;
  7207. }
  7208. }
  7209. });
  7210. modalInstance.result.then(function(added){
  7211. added && (getData());
  7212. });
  7213. };
  7214. }]);
  7215. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService){
  7216. BaseService.scrollBackToTop();
  7217. $scope.role = role;
  7218. $scope.master = angular.copy($scope.role);
  7219. var isNew = role == null;
  7220. $scope.cancel = function() {
  7221. $modalInstance.close(false);
  7222. };
  7223. AccountResource.query({}, function(data){
  7224. if(data && data.length > 0) {
  7225. if(role && role.resourceItems) {
  7226. var rs = [];// 已分配的资源的id
  7227. angular.forEach(role.resourceItems, function(item){
  7228. rs.push(item.id);
  7229. });
  7230. angular.forEach(data, function(resource){
  7231. var c = 0;
  7232. angular.forEach(resource.items, function(item){
  7233. if(rs.indexOf(item.id) > -1) {
  7234. item.$checked = true;
  7235. c += 1;
  7236. }
  7237. });
  7238. resource.$checked = c == resource.items.length;
  7239. });
  7240. }
  7241. $scope.resourceItems = data[0].items;
  7242. data[0].$active = true;
  7243. }
  7244. $scope.resources = data;
  7245. $timeout(function(){
  7246. angular.forEach($scope.resources, function(resource){
  7247. var c = 0;
  7248. angular.forEach(resource.items, function(item){
  7249. item.$checked && (c+=1);
  7250. });
  7251. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  7252. });
  7253. }, 100);
  7254. });
  7255. $scope.onItemClick = function(resource) {
  7256. $scope.resourceItems = resource.items;
  7257. angular.forEach($scope.resources, function(r){
  7258. r.$active = false;
  7259. });
  7260. resource.$active = true;
  7261. };
  7262. var getChecked = function() {
  7263. var items = [];
  7264. angular.forEach($scope.resources, function(resource){
  7265. angular.forEach(resource.items, function(item){
  7266. item.$checked && (items.push(item));
  7267. });
  7268. });
  7269. $scope.role.resourceItems = items;
  7270. };
  7271. $scope.onResourceChange = function(resource) {
  7272. angular.forEach(resource.items, function(item){
  7273. item.$checked = resource.$checked;
  7274. });
  7275. getChecked();
  7276. };
  7277. $scope.onItemChange = function() {
  7278. angular.forEach($scope.resources, function(resource){
  7279. if(resource.$active) {
  7280. var c = 0;
  7281. angular.forEach(resource.items, function(item){
  7282. item.$checked && (c+=1);
  7283. });
  7284. resource.$checked = (c == resource.items.length);
  7285. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  7286. }
  7287. });
  7288. getChecked();
  7289. };
  7290. $scope.isChanged = function(formData) {
  7291. if(!$scope.master)
  7292. return true;
  7293. return !angular.equals(formData, $scope.master);
  7294. };
  7295. $scope.save = function() {
  7296. $scope.master = angular.copy($scope.role);
  7297. AccountRole.save($scope.master, function(){
  7298. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  7299. $modalInstance.close(true);
  7300. }, function(response){
  7301. toaster.pop('error', '错误', response.data);
  7302. });
  7303. };
  7304. $scope.del = function() {
  7305. new ngAlert({
  7306. title: '提示',
  7307. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  7308. }, function(){
  7309. AccountRole.remove({id: role.id}, function(){
  7310. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  7311. $modalInstance.close(true);
  7312. }, function(response){
  7313. toaster.pop('error', '错误', response.data);
  7314. });
  7315. })
  7316. };
  7317. }]);
  7318. /**
  7319. * 委外订单
  7320. */
  7321. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  7322. function($scope, $filter, MakeOrder, ngTableParams, toaster,ReportService, BaseService){
  7323. BaseService.scrollBackToTop();
  7324. $scope.active = 'todo';
  7325. $scope.dateZoneText = '不限';
  7326. $scope.condition = {dateZone: -1};
  7327. $scope.changeDateZone = function(zone) {
  7328. $scope.condition.dateZone = zone;
  7329. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  7330. $scope.condition.$dateZoneOpen = false;
  7331. getDateCondition(zone, $scope.condition);
  7332. $scope.tableParams.reload();
  7333. };
  7334. $scope.setActive = function(state) {
  7335. if($scope.active != state) {
  7336. $scope.active = state;
  7337. if($scope.tableParams.page() == 1)
  7338. $scope.tableParams.reload();
  7339. else
  7340. $scope.tableParams.page(1);
  7341. }
  7342. };
  7343. var getService = function() {
  7344. return MakeOrder;
  7345. };
  7346. $scope.tableParams = new ngTableParams({
  7347. page : 1,
  7348. count : 5,
  7349. sorting: {
  7350. date: 'desc'
  7351. }
  7352. }, {
  7353. total : 0,
  7354. counts: [5, 10, 25, 50],
  7355. getData : function($defer, params) {
  7356. $scope.loading = true;
  7357. var pageParams = params.url();
  7358. pageParams.searchFilter = {};
  7359. pageParams.searchFilter.keyword = $scope.keyword;
  7360. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7361. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7362. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7363. $scope.loading = false;
  7364. if(page) {
  7365. params.total(page.totalElement);
  7366. $defer.resolve(page.content);
  7367. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7368. }
  7369. }, function(response){
  7370. $scope.loading = false;
  7371. toaster.pop('error', '数据加载失败', response.data);
  7372. });
  7373. }
  7374. });
  7375. $scope.getOrderTotal = function(items) {
  7376. var sum = 0;
  7377. angular.forEach(items, function(item){
  7378. sum += item.qty * item.price;
  7379. });
  7380. return sum;
  7381. };
  7382. $scope.openDatePicker = function($event, item, openParam) {
  7383. $event.preventDefault();
  7384. $event.stopPropagation();
  7385. item[openParam] = !item[openParam];
  7386. };
  7387. $scope.parseDate = function(dateStr) {
  7388. if(dateStr)
  7389. return Date.parse(dateStr, 'yyyy-MM-dd');
  7390. return new Date();
  7391. };
  7392. // 打开回复
  7393. $scope.openReply = function(order) {
  7394. if(!order.reply) {
  7395. order.reply = {
  7396. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7397. delivery: order.delivery
  7398. }
  7399. }
  7400. order.$editing = true;
  7401. };
  7402. // 关闭回复
  7403. $scope.closeReply = function(order) {
  7404. order.$editing = false;
  7405. }
  7406. // 搜索框回车
  7407. $scope.onSearch = function() {
  7408. $scope.tableParams.page(1);
  7409. $scope.tableParams.reload();
  7410. };
  7411. // 选择查找日期
  7412. $scope.onDateCondition = function(){
  7413. $scope.tableParams.page(1);
  7414. $scope.tableParams.reload();
  7415. };
  7416. // 点击回复
  7417. $scope.onReplyClick = function(order, inverse) {
  7418. if(order.reply) {
  7419. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7420. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7421. return;
  7422. }
  7423. var reply = angular.copy(order.reply);
  7424. if(reply.delivery) {
  7425. if(typeof reply.delivery == 'object')
  7426. reply.delivery = reply.delivery.getTime();
  7427. } else {
  7428. reply.delivery = order.delivery;
  7429. }
  7430. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7431. $scope.loading = true;
  7432. MakeOrder.reply({orderId: order.id}, reply, function(){
  7433. $scope.loading = false;
  7434. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7435. $scope.tableParams.reload();
  7436. }, function(response){
  7437. $scope.loading = false;
  7438. toaster.pop('error', '回复失败', response.data);
  7439. });
  7440. }
  7441. };
  7442. //委外加工单
  7443. $scope.print = function(order) {
  7444. MakeOrder.printCount({id: order.id},{});//增加打印此次
  7445. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  7446. };
  7447. // 获取回复记录
  7448. $scope.getReply = function(order) {
  7449. if(!order.replies) {
  7450. MakeOrder.getReply({orderId: order.id}, function(replies){
  7451. order.replies = replies;
  7452. });
  7453. }
  7454. };
  7455. }]);
  7456. /**
  7457. * 委外加工单详细
  7458. */
  7459. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService){
  7460. BaseService.scrollBackToTop();
  7461. var loadData = function() {
  7462. MakeOrder.get({id: $stateParams.id}, function(data){
  7463. $scope.order = data;
  7464. var sum = $scope.order.qty * $scope.order.price;
  7465. $scope.order.total = sum;
  7466. $scope.loading = false;
  7467. });
  7468. };
  7469. loadData();
  7470. // 获取回复记录
  7471. $scope.getReply = function(item) {
  7472. if(!item.replies) {
  7473. MakeOrder.getReply({orderId: item.id}, function(replies){
  7474. item.replies = replies;
  7475. });
  7476. }
  7477. };
  7478. $scope.openDatePicker = function($event, item, openParam) {
  7479. $event.preventDefault();
  7480. $event.stopPropagation();
  7481. item[openParam] = !item[openParam];
  7482. };
  7483. // 点击回复
  7484. $scope.onReplyClick = function(order, inverse) {
  7485. if(order.reply) {
  7486. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7487. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7488. return;
  7489. }
  7490. var reply = angular.copy(order.reply);
  7491. if(reply.delivery) {
  7492. if(typeof reply.delivery == 'object')
  7493. reply.delivery = reply.delivery.getTime();
  7494. } else {
  7495. reply.delivery = order.delivery;
  7496. }
  7497. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7498. $scope.loading = true;
  7499. MakeOrder.reply({orderId: order.id}, reply, function(){
  7500. $scope.loading = false;
  7501. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7502. loadData();
  7503. }, function(response){
  7504. $scope.loading = false;
  7505. toaster.pop('error', '回复失败', response.data);
  7506. });
  7507. }
  7508. };
  7509. // 打开回复
  7510. $scope.openReply = function(order) {
  7511. if(!order.reply) {
  7512. order.reply = {
  7513. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7514. delivery: order.delivery
  7515. }
  7516. }
  7517. order.$editing = true;
  7518. };
  7519. // 关闭回复
  7520. $scope.closeReply = function(order) {
  7521. order.$editing = false;
  7522. }
  7523. // 委外订单
  7524. $scope.print = function(order) {
  7525. MakeOrder.printCount({id: order.id},{});//增加打印此次
  7526. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  7527. };
  7528. }]);
  7529. /**
  7530. * 客户委外验收
  7531. */
  7532. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol){
  7533. BaseService.scrollBackToTop();
  7534. $scope.active = 'all';
  7535. $scope.agreedText = '全部';
  7536. $scope.dateZoneText = '一个月内';
  7537. $scope.condition = {dateZone: 1};
  7538. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7539. $scope.changeAgreed = function(agreed) {
  7540. $scope.condition.agreed = agreed;
  7541. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7542. $scope.condition.$agreedOpen = false;
  7543. };
  7544. $scope.changeDateZone = function(zone) {
  7545. $scope.condition.dateZone = zone;
  7546. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7547. $scope.condition.$dateZoneOpen = false;
  7548. getDateCondition(zone, $scope.condition);
  7549. $scope.tableParams.reload();
  7550. };
  7551. $scope.setActive = function(state) {
  7552. if($scope.active != state) {
  7553. $scope.active = state;
  7554. if($scope.tableParams.page() == 1)
  7555. $scope.tableParams.reload();
  7556. else
  7557. $scope.tableParams.page(1);
  7558. }
  7559. };
  7560. var getService = function() {
  7561. return MakeAccept;
  7562. };
  7563. $scope.tableParams = new ngTableParams({
  7564. page : 1,
  7565. count : 5,
  7566. sorting: {
  7567. date: 'desc'
  7568. }
  7569. }, {
  7570. total : 0,
  7571. counts: [5, 10, 25, 50],
  7572. getData : function($defer, params) {
  7573. $scope.loading = true;
  7574. var pageParams = params.url();
  7575. pageParams.searchFilter = {};
  7576. pageParams.searchFilter.keyword = $scope.keyword;
  7577. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7578. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7579. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7580. $scope.loading = false;
  7581. if(page) {
  7582. params.total(page.totalElement);
  7583. $defer.resolve(page.content);
  7584. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7585. }
  7586. }, function(response){
  7587. $scope.loading = false;
  7588. toaster.pop('error', '数据加载失败', response.data);
  7589. });
  7590. }
  7591. });
  7592. $scope.openDatePicker = function($event, item, openParam) {
  7593. $event.preventDefault();
  7594. $event.stopPropagation();
  7595. item[openParam] = !item[openParam];
  7596. };
  7597. // 搜索框回车
  7598. $scope.onSearch = function() {
  7599. $scope.tableParams.page(1);
  7600. $scope.tableParams.reload();
  7601. };
  7602. // 选择查找日期
  7603. $scope.onDateCondition = function(){
  7604. $scope.tableParams.page(1);
  7605. $scope.tableParams.reload();
  7606. };
  7607. }]);
  7608. /**
  7609. * 客户委外验退
  7610. */
  7611. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol){
  7612. BaseService.scrollBackToTop();
  7613. $scope.active = 'all';
  7614. $scope.agreedText = '全部';
  7615. $scope.dateZoneText = '一个月内';
  7616. $scope.condition = {dateZone: 1};
  7617. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7618. $scope.changeAgreed = function(agreed) {
  7619. $scope.condition.agreed = agreed;
  7620. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7621. $scope.condition.$agreedOpen = false;
  7622. };
  7623. $scope.changeDateZone = function(zone) {
  7624. $scope.condition.dateZone = zone;
  7625. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7626. $scope.condition.$dateZoneOpen = false;
  7627. getDateCondition(zone, $scope.condition);
  7628. $scope.tableParams.reload();
  7629. };
  7630. $scope.setActive = function(state) {
  7631. if($scope.active != state) {
  7632. $scope.active = state;
  7633. if($scope.tableParams.page() == 1)
  7634. $scope.tableParams.reload();
  7635. else
  7636. $scope.tableParams.page(1);
  7637. }
  7638. };
  7639. var getService = function() {
  7640. return MakeReturn;
  7641. };
  7642. $scope.tableParams = new ngTableParams({
  7643. page : 1,
  7644. count : 5,
  7645. sorting: {
  7646. date: 'desc'
  7647. }
  7648. }, {
  7649. total : 0,
  7650. counts: [5, 10, 25, 50],
  7651. getData : function($defer, params) {
  7652. $scope.loading = true;
  7653. var pageParams = params.url();
  7654. pageParams.searchFilter = {};
  7655. pageParams.searchFilter.keyword = $scope.keyword;
  7656. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7657. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7658. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7659. $scope.loading = false;
  7660. if(page) {
  7661. params.total(page.totalElement);
  7662. $defer.resolve(page.content);
  7663. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7664. }
  7665. }, function(response){
  7666. $scope.loading = false;
  7667. toaster.pop('error', '数据加载失败', response.data);
  7668. });
  7669. }
  7670. });
  7671. $scope.openDatePicker = function($event, item, openParam) {
  7672. $event.preventDefault();
  7673. $event.stopPropagation();
  7674. item[openParam] = !item[openParam];
  7675. };
  7676. // 搜索框回车
  7677. $scope.onSearch = function() {
  7678. $scope.tableParams.page(1);
  7679. $scope.tableParams.reload();
  7680. };
  7681. // 选择查找日期
  7682. $scope.onDateCondition = function(){
  7683. $scope.tableParams.page(1);
  7684. $scope.tableParams.reload();
  7685. };
  7686. }]);
  7687. /**
  7688. * 委外加工变更
  7689. */
  7690. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, MakeChange ,ngTableParams, toaster, BaseService){
  7691. BaseService.scrollBackToTop();
  7692. $scope.active = 'all';
  7693. $scope.agreedText = '全部';
  7694. $scope.dateZoneText = '一个月内';
  7695. $scope.condition = {dateZone: 1};
  7696. $scope.changeAgreed = function(agreed) {
  7697. $scope.condition.agreed = agreed;
  7698. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7699. $scope.condition.$agreedOpen = false;
  7700. };
  7701. $scope.changeDateZone = function(zone) {
  7702. $scope.condition.dateZone = zone;
  7703. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7704. $scope.condition.$dateZoneOpen = false;
  7705. getDateCondition(zone, $scope.condition);
  7706. $scope.tableParams.reload();
  7707. };
  7708. $scope.setActive = function(state) {
  7709. if($scope.active != state) {
  7710. $scope.active = state;
  7711. if($scope.tableParams.page() == 1)
  7712. $scope.tableParams.reload();
  7713. else
  7714. $scope.tableParams.page(1);
  7715. }
  7716. };
  7717. var getService = function() {
  7718. return MakeChange;
  7719. };
  7720. $scope.tableParams = new ngTableParams({
  7721. page : 1,
  7722. count : 5,
  7723. sorting: {
  7724. orderChangeDate: 'desc'
  7725. }
  7726. }, {
  7727. total : 0,
  7728. counts: [5, 10, 25, 50],
  7729. getData : function($defer, params) {
  7730. $scope.loading = true;
  7731. var pageParams = params.url();
  7732. pageParams.searchFilter = {};
  7733. pageParams.searchFilter.keyword = $scope.keyword;
  7734. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7735. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7736. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7737. $scope.loading = false;
  7738. if(page) {
  7739. params.total(page.totalElement);
  7740. $defer.resolve(page.content);
  7741. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7742. }
  7743. }, function(response){
  7744. $scope.loading = false;
  7745. toaster.pop('error', '数据加载失败', response.data);
  7746. });
  7747. }
  7748. });
  7749. $scope.openDatePicker = function($event, item, openParam) {
  7750. $event.preventDefault();
  7751. $event.stopPropagation();
  7752. item[openParam] = !item[openParam];
  7753. };
  7754. // 打开回复
  7755. $scope.openReply = function(change) {
  7756. change.$editing = true;
  7757. };
  7758. // 关闭回复
  7759. $scope.closeReply = function(change) {
  7760. change.$editing = false;
  7761. }
  7762. // 确定回复
  7763. $scope.onReplyClick = function(change) {
  7764. if(change.$agreed) {
  7765. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7766. $scope.loading = true;
  7767. MakeChange.reply({itemId: change.id}, reply, function(){
  7768. $scope.loading = false;
  7769. toaster.pop('info', '提示', '回复成功');
  7770. $scope.tableParams.reload();
  7771. }, function(response){
  7772. $scope.loading = false;
  7773. toaster.pop('error', '回复失败', response.data);
  7774. });
  7775. }
  7776. };
  7777. // 搜索框回车
  7778. $scope.onSearch = function() {
  7779. $scope.tableParams.page(1);
  7780. $scope.tableParams.reload();
  7781. };
  7782. // 选择查找日期
  7783. $scope.onDateCondition = function(){
  7784. $scope.tableParams.page(1);
  7785. $scope.tableParams.reload();
  7786. };
  7787. }]);
  7788. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', function($scope, $stateParams, MakeChange, toaster, BaseService){
  7789. BaseService.scrollBackToTop();
  7790. var loadData = function() {
  7791. MakeChange.get({id: $stateParams.id}, function(data){
  7792. $scope.change = data;
  7793. });
  7794. };
  7795. loadData();
  7796. $scope.openDatePicker = function($event, item, openParam) {
  7797. $event.preventDefault();
  7798. $event.stopPropagation();
  7799. item[openParam] = !item[openParam];
  7800. };
  7801. $scope.onReplyClick = function(change) {
  7802. if(change.$agreed) {
  7803. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7804. MakeChange.reply({itemId: change.id}, reply, function(){
  7805. toaster.pop('info', '提示', '回复成功');
  7806. loadData();
  7807. }, function(response){
  7808. toaster.pop('error', '回复失败', response.data);
  7809. });
  7810. }
  7811. };
  7812. }]);
  7813. /**
  7814. * 委外加工
  7815. */
  7816. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster','ReportService', 'BaseService',
  7817. function($scope, $filter, MakeOutOrder, ngTableParams, toaster,ReportService, BaseService) {
  7818. BaseService.scrollBackToTop();
  7819. $scope.active = 'all';
  7820. $scope.agreedText = '全部';
  7821. $scope.dateZoneText = '一个月内';
  7822. $scope.condition = {dateZone: 1};
  7823. $scope.changeAgreed = function(agreed) {
  7824. $scope.condition.agreed = agreed;
  7825. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7826. $scope.condition.$agreedOpen = false;
  7827. };
  7828. $scope.changeDateZone = function(zone) {
  7829. $scope.condition.dateZone = zone;
  7830. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7831. $scope.condition.$dateZoneOpen = false;
  7832. getDateCondition(zone, $scope.condition);
  7833. $scope.tableParams.reload();
  7834. };
  7835. $scope.setActive = function(state) {
  7836. if($scope.active != state) {
  7837. $scope.active = state;
  7838. if($scope.tableParams.page() == 1)
  7839. $scope.tableParams.reload();
  7840. else
  7841. $scope.tableParams.page(1);
  7842. }
  7843. };
  7844. var getService = function() {
  7845. return MakeOutOrder;
  7846. };
  7847. $scope.tableParams = new ngTableParams({
  7848. page : 1,
  7849. count : 5,
  7850. sorting: {
  7851. date: 'desc'
  7852. }
  7853. }, {
  7854. total : 0,
  7855. counts: [5, 10, 25, 50],
  7856. getData : function($defer, params) {
  7857. $scope.loading = true;
  7858. var pageParams = params.url();
  7859. pageParams.searchFilter = {};
  7860. pageParams.searchFilter.keyword = $scope.keyword;
  7861. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7862. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7863. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  7864. $scope.loading = false;
  7865. if(page) {
  7866. params.total(page.totalElement);
  7867. $defer.resolve(page.content);
  7868. $scope.keywordXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7869. }
  7870. }, function(response){
  7871. $scope.loading = false;
  7872. toaster.pop('error', '数据加载失败', response.data);
  7873. });
  7874. }
  7875. });
  7876. $scope.openDatePicker = function($event, item, openParam) {
  7877. $event.preventDefault();
  7878. $event.stopPropagation();
  7879. item[openParam] = !item[openParam];
  7880. };
  7881. // 打开回复
  7882. $scope.openReply = function(change) {
  7883. change.$editing = true;
  7884. };
  7885. // 关闭回复
  7886. $scope.closeReply = function(change) {
  7887. change.$editing = false;
  7888. }
  7889. // 确定回复
  7890. $scope.onReplyClick = function(change) {
  7891. if(change.$agreed) {
  7892. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  7893. $scope.loading = true;
  7894. MakeOutOrder.reply({itemId: change.id}, reply, function(){
  7895. $scope.loading = false;
  7896. toaster.pop('info', '提示', '回复成功');
  7897. $scope.tableParams.reload();
  7898. }, function(response){
  7899. $scope.loading = false;
  7900. toaster.pop('error', '回复失败', response.data);
  7901. });
  7902. }
  7903. };
  7904. // 搜索框回车
  7905. $scope.onSearch = function() {
  7906. $scope.tableParams.page(1);
  7907. $scope.tableParams.reload();
  7908. };
  7909. // 选择查找日期
  7910. $scope.onDateCondition = function(){
  7911. $scope.tableParams.page(1);
  7912. $scope.tableParams.reload();
  7913. };
  7914. }]);
  7915. /**
  7916. * 委外加工详细
  7917. */
  7918. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', function($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService) {
  7919. BaseService.scrollBackToTop();
  7920. var loadData = function() {
  7921. MakeOutOrder.get({id: $stateParams.id}, function(data){
  7922. $scope.order = data;
  7923. var sum = $scope.order.qty * $scope.order.price;
  7924. $scope.order.total = sum;
  7925. $scope.loading = false;
  7926. });
  7927. };
  7928. loadData();
  7929. // 获取回复记录
  7930. $scope.getReply = function(item) {
  7931. if(!item.replies) {
  7932. MakeOutOrder.getReply({orderId: item.id}, function(replies){
  7933. item.replies = replies;
  7934. });
  7935. }
  7936. };
  7937. $scope.openDatePicker = function($event, item, openParam) {
  7938. $event.preventDefault();
  7939. $event.stopPropagation();
  7940. item[openParam] = !item[openParam];
  7941. };
  7942. // 点击回复
  7943. $scope.onReplyClick = function(order, inverse) {
  7944. if(order.reply) {
  7945. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  7946. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7947. return;
  7948. }
  7949. var reply = angular.copy(order.reply);
  7950. if(reply.delivery) {
  7951. if(typeof reply.delivery == 'object')
  7952. reply.delivery = reply.delivery.getTime();
  7953. } else {
  7954. reply.delivery = order.delivery;
  7955. }
  7956. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  7957. $scope.loading = true;
  7958. MakeOutOrder.reply({orderId: order.id}, reply, function(){
  7959. $scope.loading = false;
  7960. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  7961. loadData();
  7962. }, function(response){
  7963. $scope.loading = false;
  7964. toaster.pop('error', '回复失败', response.data);
  7965. });
  7966. }
  7967. };
  7968. // 打开回复
  7969. $scope.openReply = function(order) {
  7970. if(!order.reply) {
  7971. order.reply = {
  7972. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  7973. delivery: order.delivery
  7974. }
  7975. }
  7976. order.$editing = true;
  7977. };
  7978. // 关闭回复
  7979. $scope.closeReply = function(order) {
  7980. order.$editing = false;
  7981. }
  7982. // 自己委外加工订单
  7983. $scope.print = function(order) {
  7984. MakeOutOrder.printCount({id: order.id},{});//增加打印此次
  7985. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  7986. };
  7987. }]);
  7988. /**
  7989. * 计算时间差
  7990. */
  7991. app.filter('timespan', function(){
  7992. return function(time) {
  7993. if(time == null)
  7994. return '9999年';
  7995. var now = new Date().getTime(), span = time - now,
  7996. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  7997. m = Math.ceil(span/60000);
  7998. if(span < 0)
  7999. return '0天';
  8000. if(d > 0)
  8001. return d + '天';
  8002. if(h > 0)
  8003. return h + '小时';
  8004. if(m > 0)
  8005. return m + '分钟';
  8006. return '0天';
  8007. };
  8008. });
  8009. app.filter('firstchar', function(){
  8010. return function(str) {
  8011. if(str == null)
  8012. return null;
  8013. return str.substring(0, 1);
  8014. };
  8015. });
  8016. app.filter('summary', function(){
  8017. return function(data, field) {
  8018. var sum = 0;
  8019. if (data) {
  8020. angular.forEach(data, function(d){
  8021. sum += d[field];
  8022. });
  8023. }
  8024. return sum;
  8025. };
  8026. });
  8027. /**
  8028. * 搜索框,回车触发
  8029. */
  8030. app.directive('ngSearch', ['$parse', function($parse) {
  8031. return {
  8032. require : '?ngModel',
  8033. restrict : 'A',
  8034. link : function(scope, element, attrs, ngModel) {
  8035. var searchFn = $parse(attrs.ngSearch);
  8036. element.bind('keypress', function(event) {
  8037. if (event.keyCode == '13') {
  8038. event.preventDefault();
  8039. event.stopPropagation();
  8040. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  8041. }
  8042. });
  8043. }
  8044. };
  8045. }]);
  8046. /**
  8047. * 状态码 -> 描述
  8048. */
  8049. app.filter('status', function(){
  8050. return function(data) {
  8051. var statusConfig = {
  8052. '101': '已提交',
  8053. '102': '已审核',
  8054. '103': '未通过',
  8055. '200': '未回复',
  8056. '201': '已回复',
  8057. '313': '已激活',
  8058. '316': '已过账',
  8059. '311': '申请中',
  8060. '312': '未激活'
  8061. };
  8062. return statusConfig[data];
  8063. }
  8064. });
  8065. //弹出问题反馈模态框
  8066. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
  8067. //获取当前用户
  8068. AuthenticationService.getAuthentication().success(function(data) {
  8069. $scope.user = data;
  8070. });
  8071. $scope.showModal = function(){
  8072. var modalInstance = $modal.open({
  8073. animation: true,
  8074. templateUrl: 'static/tpl/serve/feedback.html',
  8075. controller: 'FeedbackCtrl',
  8076. resolve: {
  8077. user: function(){return $scope.user;} //传递当前用户到模态框Controller
  8078. }
  8079. });
  8080. modalInstance.result.then(function(){
  8081. }, function(){
  8082. })
  8083. }
  8084. }]);
  8085. /*
  8086. * 提交我的反馈
  8087. */
  8088. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
  8089. $scope.isPublic = 1; //默认公开
  8090. $scope.classId = 1; //默认类别
  8091. $scope.user = user;
  8092. $scope.ok = function(){
  8093. if(!$scope.user){ //用户未登录
  8094. $scope.uu = null;
  8095. }else{ //用户已登录
  8096. $scope.uu = $scope.user.userUU;
  8097. }
  8098. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  8099. FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {},
  8100. function(data){
  8101. toaster.pop('success', '成功', '您的问题反馈成功!');
  8102. $scope.cancel();
  8103. }, function(response){
  8104. toaster.pop('error', '错误', response.data);
  8105. });
  8106. }
  8107. $scope.cancel = function () {
  8108. $modalInstance.dismiss();
  8109. };
  8110. }]);
  8111. //“我的问题反馈”跳转控制
  8112. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
  8113. $scope.myFeedback = function(){
  8114. AuthenticationService.getAuthentication().success(function(data){
  8115. $scope.user = data;
  8116. if(!$scope.user){
  8117. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  8118. return false;
  8119. }else{
  8120. window.location.href = "./serve#/question/myFeedback";
  8121. }
  8122. });
  8123. }
  8124. }]);
  8125. //客户服务
  8126. app.controller('CustServeCtrl', ['$scope', 'Vendor', function($scope, Vendor){
  8127. Vendor.getServe(function(datas){
  8128. $scope.vendors = datas;
  8129. console.log($scope.Vender);
  8130. // 自动跳转
  8131. if(datas && datas.length == 1)
  8132. $scope.redirect(datas[0]);
  8133. });
  8134. $scope.redirect = function(vendor) {
  8135. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  8136. };
  8137. }]);
  8138. /**
  8139. * 物料资料
  8140. */
  8141. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
  8142. BaseService.scrollBackToTop();
  8143. $scope.active = 'all';
  8144. $scope.agreedText = '全部';
  8145. $scope.dateZoneText = '一个月内';
  8146. $scope.condition = {dateZone: 1};
  8147. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8148. $scope.changeAgreed = function(agreed) {
  8149. $scope.condition.agreed = agreed;
  8150. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8151. $scope.condition.$agreedOpen = false;
  8152. };
  8153. $scope.changeDateZone = function(zone) {
  8154. $scope.condition.dateZone = zone;
  8155. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8156. $scope.condition.$dateZoneOpen = false;
  8157. getDateCondition(zone, $scope.condition);
  8158. $scope.tableParams.reload();
  8159. };
  8160. $scope.setActive = function(state) {
  8161. if($scope.active != state) {
  8162. $scope.active = state;
  8163. if($scope.tableParams.page() == 1)
  8164. $scope.tableParams.reload();
  8165. else
  8166. $scope.tableParams.page(1);
  8167. }
  8168. };
  8169. var getService = function() {
  8170. return GetProductInfo;
  8171. };
  8172. $scope.tableParams = new ngTableParams({
  8173. page : 1,
  8174. count : 5,
  8175. sorting: {
  8176. }
  8177. }, {
  8178. total : 0,
  8179. counts: [5, 10, 25, 50],
  8180. getData : function($defer, params) {
  8181. $scope.loading = true;
  8182. var pageParams = params.url();
  8183. pageParams.keyword = $scope.keyword;
  8184. pageParams.searchFilter = $scope.searchFilter;
  8185. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  8186. $scope.loading = false;
  8187. if(page) {
  8188. params.total(page.totalElement);
  8189. $defer.resolve(page.content);
  8190. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8191. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  8192. }
  8193. }, function(response) {
  8194. $scope.loading = false;
  8195. toaster.pop('error', '数据加载失败', response.data);
  8196. });
  8197. }
  8198. });
  8199. // 搜索框回车
  8200. $scope.onSearch = function() {
  8201. $scope.tableParams.page(1);
  8202. $scope.tableParams.reload();
  8203. };
  8204. //删除
  8205. $scope.deleteById = function(id) {
  8206. GetProductInfo.deleteById({id: id}, function(data) {
  8207. if(data.error) {
  8208. toaster.pop("error", "提示", data.error);
  8209. } else {
  8210. toaster.pop("success", "提示", "删除成功");
  8211. $timeout(function() {
  8212. $scope.tableParams.reload();
  8213. }, 500);
  8214. }
  8215. }), function(response) {
  8216. toaster.pop("error", "删除失败", response.data);
  8217. };
  8218. }
  8219. }]);
  8220. /**
  8221. * 物料批量上传
  8222. */
  8223. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function($scope, $upload, toaster, BaseService) {
  8224. BaseService.scrollBackToTop();
  8225. // 通过excel批量上传物料
  8226. $scope.upload = function() {
  8227. var file = $scope.myFiles[0];
  8228. $upload.upload({
  8229. url: 'product/baseInfo/release/excel',
  8230. file: file,
  8231. method: 'POST'
  8232. }).success(function(data) {
  8233. $scope.result = data;
  8234. $scope.success = $scope.result.success;
  8235. $scope.total = $scope.result.total;
  8236. $scope.alters = $scope.result.alters;
  8237. $scope.infos = $scope.result.infos;
  8238. }).error(function(response) {
  8239. toaster.pop('error', response.data || response);
  8240. });
  8241. };
  8242. // 查看范例
  8243. $scope.showImg = function() {
  8244. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  8245. box.show();
  8246. box.find('img').attr('src', src);
  8247. box.find('a').click(function(){
  8248. box.hide();
  8249. });
  8250. box.dblclick(function(){
  8251. box.hide();
  8252. });
  8253. };
  8254. // 下载模板
  8255. $scope.download = function() {
  8256. window.location.href = 'product/baseInfo/upload/template';
  8257. };
  8258. }]);
  8259. /**
  8260. * 物料详情
  8261. */
  8262. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService) {
  8263. BaseService.scrollBackToTop();
  8264. // 录入人
  8265. AuthenticationService.getAuthentication().success(function(data) {
  8266. $scope.loading = false;
  8267. $scope.user = data;
  8268. });
  8269. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  8270. var loadData = function() {
  8271. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  8272. if(data.attach) {
  8273. GetProductInfo.getAttach({id: data.attach.id}, function(data) {
  8274. // 查看范例
  8275. $scope.showImg = function() {
  8276. var src = data.url, box = $('#image-box');
  8277. box.show();
  8278. box.find('img').attr('src', src);
  8279. box.find('a').click(function(){
  8280. box.hide();
  8281. });
  8282. box.dblclick(function(){
  8283. box.hide();
  8284. });
  8285. };
  8286. })
  8287. }
  8288. $scope.prodInfo = data;
  8289. $scope.prodInfo.$editing = false;
  8290. $scope.loading = false;
  8291. });
  8292. };
  8293. loadData();
  8294. $scope.isShow = true;
  8295. // 更新
  8296. $scope.update = function() {
  8297. $scope.prodInfo.$editing = true;
  8298. $scope.isShow = true;
  8299. };
  8300. // 取消
  8301. $scope.cancel = function() {
  8302. GetProductInfo.getOne({id: $stateParams.id}, function(data) {
  8303. $scope.prodInfo = data;
  8304. $scope.prodInfo.$editing = false;
  8305. $scope.isShow = false;
  8306. $scope.loading = false;
  8307. });
  8308. };
  8309. $scope.submit = function(prodInfo) {
  8310. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  8311. $upload.upload({
  8312. url: 'product/baseInfo/updateProdInfo',
  8313. file: file,
  8314. method: 'POST',
  8315. data: {
  8316. prodInfo: $scope.prodInfo
  8317. },
  8318. }).success(function(data) {
  8319. if(data.success) {
  8320. toaster.pop('success', '提示', data.success);
  8321. window.location.reload();
  8322. }
  8323. if(data.error) {
  8324. toaster.pop('error', '提示', data.error);
  8325. }
  8326. }).error(function(data) {
  8327. $scope.loadingShow = false;
  8328. toaster.pop('error', '操作失败', data.error);
  8329. });
  8330. }
  8331. $scope.previewShow = false;
  8332. $scope.pdfShow = false;
  8333. $scope.noneFileShow = true;
  8334. $scope.$watch('myFiles', function(){
  8335. if($scope.myFiles) {
  8336. $scope.noneFileShow = false;
  8337. var file = $scope.myFiles[0];
  8338. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  8339. $scope.pdfShow = true;
  8340. $scope.previewShow = false;
  8341. $scope.imgPreviewName = file.name;
  8342. } else{
  8343. if (typeof(Worker) !== "undefined") {//支持HTML5
  8344. $scope.imgPreview = getObjectURL(file);
  8345. $scope.imgPreviewName = file.name;
  8346. } else{//不支持HTML5
  8347. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  8348. $scope.imgPreviewName = file.name;
  8349. }
  8350. $scope.previewShow = true;
  8351. $scope.pdfShow = false;
  8352. }
  8353. } else {
  8354. $scope.noneFileShow = true;
  8355. $scope.previewShow = false;
  8356. $scope.pdfShow = false;
  8357. }
  8358. });
  8359. //建立一个可存取到该file的url
  8360. var getObjectURL = function(file) {
  8361. var url = null ;
  8362. if (window.createObjectURL!=undefined) { // basic
  8363. url = window.createObjectURL(file) ;
  8364. } else if (window.URL!=undefined) { // mozilla(firefox)
  8365. url = window.URL.createObjectURL(file) ;
  8366. } else if (window.webkitURL!=undefined) { // webkit or chrome
  8367. url = window.webkitURL.createObjectURL(file) ;
  8368. }
  8369. return url ;
  8370. };
  8371. }]);
  8372. /**
  8373. * 新增物料
  8374. */
  8375. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService) {
  8376. BaseService.scrollBackToTop();
  8377. // 录入人
  8378. AuthenticationService.getAuthentication().success(function(data) {
  8379. $scope.loading = false;
  8380. $scope.user = data;
  8381. });
  8382. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  8383. $scope.prodInfo = {};
  8384. // 选择类目
  8385. $scope.selectKind = function(uuids) {
  8386. $modal.open({
  8387. animation: true,
  8388. size: 'lg',
  8389. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  8390. controller: 'KindChooseCtrl',
  8391. }).result.then(function(data){
  8392. $scope.kindId = data;
  8393. var modalInstance = $modal.open({
  8394. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  8395. controller: 'FindComponentCtrl',
  8396. size: 'lg',
  8397. resolve: {
  8398. KindId: function() {
  8399. return $scope.kindId;
  8400. }
  8401. }
  8402. });
  8403. modalInstance.result.then(function(data) {
  8404. $scope.prodInfo.cmpUuId = data.uuid;
  8405. $scope.prodInfo.cmpCode = data.code;
  8406. $scope.prodInfo.brand = data.brand.nameEn;
  8407. console.log($scope.prodInfo.brand);
  8408. }, function(){
  8409. });
  8410. }, function(){
  8411. });
  8412. };
  8413. //提交
  8414. $scope.submit = function(prodInfo){
  8415. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  8416. $upload.upload({
  8417. url: 'product/baseInfo/addNewProduct',
  8418. file: file,
  8419. method: 'POST',
  8420. data: {
  8421. prodInfo: $scope.prodInfo
  8422. },
  8423. }).success(function(data) {
  8424. if(data.success) {
  8425. toaster.pop('success', '提示', data.success);
  8426. $timeout(function() {
  8427. //提交后跳转到详情页面,防止重复提交
  8428. window.location.href="#/sale/prodList/"+data.id;
  8429. }, 500);
  8430. }
  8431. if(data.error) {
  8432. toaster.pop('error', '提示', data.error);
  8433. $timeout(function() {
  8434. //提交后跳转到详情页面,防止重复提交
  8435. window.location.href="#/sale/prodList/"+data.id;
  8436. }, 500);
  8437. }
  8438. }).error(function(data) {
  8439. $scope.loadingShow = false;
  8440. toaster.pop('error', '操作失败', data.error);
  8441. });
  8442. // GetProductInfo.addNewProd({}, prodInfo, function(data) {
  8443. // toaster.pop("success", "提示", "提交成功");
  8444. //
  8445. //
  8446. // }, function(res) {
  8447. // toaster.pop("error", "提示" + res);
  8448. // });
  8449. };
  8450. $scope.previewShow = false;
  8451. $scope.pdfShow = false;
  8452. $scope.noneFileShow = true;
  8453. $scope.$watch('myFiles', function(){
  8454. if($scope.myFiles) {
  8455. $scope.noneFileShow = false;
  8456. var file = $scope.myFiles[0];
  8457. if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  8458. $scope.pdfShow = true;
  8459. $scope.previewShow = false;
  8460. $scope.imgPreviewName = file.name;
  8461. } else{
  8462. if (typeof(Worker) !== "undefined") {//支持HTML5
  8463. $scope.imgPreview = getObjectURL(file);
  8464. $scope.imgPreviewName = file.name;
  8465. } else{//不支持HTML5
  8466. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  8467. $scope.imgPreviewName = file.name;
  8468. }
  8469. $scope.previewShow = true;
  8470. $scope.pdfShow = false;
  8471. }
  8472. } else {
  8473. $scope.noneFileShow = true;
  8474. $scope.previewShow = false;
  8475. $scope.pdfShow = false;
  8476. }
  8477. });
  8478. //建立一个可存取到该file的url
  8479. var getObjectURL = function(file) {
  8480. var url = null ;
  8481. if (window.createObjectURL!=undefined) { // basic
  8482. url = window.createObjectURL(file) ;
  8483. } else if (window.URL!=undefined) { // mozilla(firefox)
  8484. url = window.URL.createObjectURL(file) ;
  8485. } else if (window.webkitURL!=undefined) { // webkit or chrome
  8486. url = window.webkitURL.createObjectURL(file) ;
  8487. }
  8488. return url ;
  8489. };
  8490. // 取消
  8491. $scope.cancel = function(){
  8492. $scope.prodInfo = angular.copy($scope.prodInfo);
  8493. };
  8494. }]);
  8495. /**
  8496. * 类目选择模态框
  8497. */
  8498. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function($scope, KindAPI, toaster, $modalInstance, $modal) {
  8499. $scope.kindId = null;
  8500. $scope.kinds = [[], [], [], []];
  8501. // 获取子类目
  8502. var getChildren = function(pid, deep) {
  8503. KindAPI.getChildren({parentId: pid}, function(data) {
  8504. $scope.kinds[deep] = data;
  8505. }, function(response) {
  8506. toaster.pop('error', '获取子类目失败', response.data);
  8507. });
  8508. };
  8509. // 改变节点选中状态
  8510. var changeStatus = function(item, deep) {
  8511. var kindId = null, level = 0;
  8512. angular.forEach($scope.kinds, function(ks, i) {
  8513. if(i > deep) {
  8514. $scope.kinds[i] = [];
  8515. } else {
  8516. angular.forEach(ks, function(k, j) {
  8517. if(i == deep) {
  8518. if(k.id == item.id) {
  8519. $scope.kinds[i][j].$active = true;
  8520. kindId = k.id;
  8521. } else {
  8522. k.$active = null;
  8523. }
  8524. }
  8525. });
  8526. }
  8527. });
  8528. // 选择的节点
  8529. $scope.kindId = kindId;
  8530. $scope.active = item;
  8531. // 当前可操作的层级
  8532. if(deep < 3) {
  8533. $scope.activeDeep = deep + 1;
  8534. }
  8535. };
  8536. // 节点点击后获取子类目,节点被选中
  8537. $scope.onItemClick = function(item, deep) {
  8538. changeStatus(item, deep);
  8539. if (!item.isLeaf) {
  8540. getChildren(item.id, deep + 1);
  8541. }
  8542. };
  8543. // 重新加载数据
  8544. function reload(deep) {
  8545. var pid;
  8546. if(deep) {
  8547. pid = $scope.actives[deep - 1].id;
  8548. } else {
  8549. pid = 0;
  8550. deep = 0;
  8551. }
  8552. getChildren(pid, deep);
  8553. }
  8554. // 初始加载数据,获取第一层的类目
  8555. if($scope.actives) {
  8556. angular.forEach($scope.actives, function(v, k) {
  8557. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  8558. $scope.kinds[k] = data;
  8559. angular.forEach($scope.kinds[k], function(kind, i){
  8560. if(kind.id == v.id) {
  8561. $scope.kinds[k][i].$active = true;
  8562. $scope.actives[k] = $scope.kinds[k][i];
  8563. }
  8564. })
  8565. }, function(response) {
  8566. toaster.pop('error', '获取子类目失败', response.data);
  8567. });
  8568. });
  8569. } else {
  8570. reload();
  8571. }
  8572. // 取消
  8573. $scope.cancel = function() {
  8574. $modalInstance.dismiss();
  8575. };
  8576. // 确认选择
  8577. $scope.check = function() {
  8578. $modalInstance.close($scope.kindId);
  8579. };
  8580. }]);
  8581. /**
  8582. * 器件筛选
  8583. */
  8584. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  8585. //状态
  8586. $scope.setActive = function (state){
  8587. if($scope.active != state) {
  8588. $scope.active = state;
  8589. if($scope.tableParams.page() == 1)
  8590. $scope.tableParams.reload();
  8591. else
  8592. $scope.tableParams.page(1);
  8593. }
  8594. };
  8595. $scope.tableParams = new ngTableParams({
  8596. page : 1,
  8597. count : 10
  8598. }, {
  8599. total : 0,
  8600. counts: [5, 10, 25, 50],
  8601. getData : function($defer, params) {
  8602. $scope.loading = true;
  8603. var pageParams = params.url();
  8604. pageParams.keyword = $scope.keyword;
  8605. pageParams.kindId = KindId;
  8606. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function(page) {
  8607. console.log(page);
  8608. $scope.loading = false;
  8609. if(page) {
  8610. params.total(page.totalElement);
  8611. $defer.resolve(page.content);
  8612. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8613. }
  8614. }, function(response){
  8615. $scope.loading = false;
  8616. toaster.pop('error', '数据加载失败', response.data);
  8617. });
  8618. }
  8619. });
  8620. // 取消
  8621. $scope.cancel = function() {
  8622. $modalInstance.dismiss();
  8623. };
  8624. // 选择
  8625. $scope.check = function(data){
  8626. $modalInstance.close(data);
  8627. };
  8628. // 搜索框回车
  8629. $scope.onSearch = function() {
  8630. $scope.tableParams.page(1);
  8631. $scope.tableParams.reload();
  8632. };
  8633. }]);
  8634. /**
  8635. * 企业列表
  8636. */
  8637. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  8638. BaseService.scrollBackToTop();
  8639. $scope.active = 'all';
  8640. $scope.agreedText = '全部';
  8641. $scope.dateZoneText = '一个月内';
  8642. $scope.condition = {dateZone: 1};
  8643. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8644. $scope.changeAgreed = function(agreed) {
  8645. $scope.condition.agreed = agreed;
  8646. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8647. $scope.condition.$agreedOpen = false;
  8648. };
  8649. $scope.changeDateZone = function(zone) {
  8650. $scope.condition.dateZone = zone;
  8651. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8652. $scope.condition.$dateZoneOpen = false;
  8653. getDateCondition(zone, $scope.condition);
  8654. $scope.tableParams.reload();
  8655. };
  8656. $scope.setActive = function(state) {
  8657. if($scope.active != state) {
  8658. $scope.active = state;
  8659. if($scope.tableParams.page() == 1)
  8660. $scope.tableParams.reload();
  8661. else
  8662. $scope.tableParams.page(1);
  8663. }
  8664. };
  8665. var getService = function() {
  8666. return getAccountUserSpace;
  8667. };
  8668. $scope.tableParams = new ngTableParams({
  8669. page : 1,
  8670. count : 5,
  8671. sorting: {
  8672. }
  8673. }, {
  8674. total : 0,
  8675. counts: [5, 10, 25, 50],
  8676. getData : function($defer, params) {
  8677. $scope.loading = true;
  8678. var pageParams = params.url();
  8679. pageParams.keyword = $scope.keyword;
  8680. $scope.tip = $scope.keyword;
  8681. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  8682. $scope.loading = false;
  8683. if(page) {
  8684. params.total(page.totalElement);
  8685. $defer.resolve(page.content);
  8686. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  8687. }
  8688. }, function(response) {
  8689. $scope.loading = false;
  8690. toaster.pop('error', '数据加载失败', response.data);
  8691. });
  8692. }
  8693. });
  8694. // 搜索框回车
  8695. $scope.onSearch = function() {
  8696. $scope.tableParams.page(1);
  8697. $scope.tableParams.reload();
  8698. };
  8699. // 添加合作关系
  8700. $scope.addPartner = function(name, businessCode) {
  8701. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  8702. if(data.success) {
  8703. toaster.pop("success", '添加成功', data.success);
  8704. }
  8705. if(data.error) {
  8706. toaster.pop("error", '添加失败', data.error);
  8707. }
  8708. }, function(response) {
  8709. toaster.pop('error','失败',response.data);
  8710. });
  8711. }
  8712. $scope.status = 'enList';
  8713. }]);
  8714. /**
  8715. * 新增采购单
  8716. */
  8717. app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', function($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http) {
  8718. BaseService.scrollBackToTop();
  8719. // 每次进入时先清除掉rootScope下的venuu
  8720. $rootScope.venduu = null;
  8721. // 获取收货地址列表
  8722. ShipAddress.shipAddList({}, function(data) {
  8723. $scope.ships = data;
  8724. $scope.order.shipadd = $scope.ships[0];
  8725. });
  8726. // 获取地址信息
  8727. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  8728. }).then(function(response) {
  8729. $scope.provinces = response.data;
  8730. });
  8731. $scope.order = {
  8732. date : new Date(),
  8733. cust : {
  8734. uu : '',
  8735. },
  8736. custUser : {
  8737. },
  8738. code : $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  8739. orderItems : {
  8740. product : {},
  8741. },
  8742. };
  8743. //商品信息
  8744. $scope.order.orderItems = [];
  8745. var item = {
  8746. code: null,
  8747. title: null,
  8748. spec: null,
  8749. unit: null,
  8750. qty: null,
  8751. price: null,
  8752. remark: null,
  8753. delivery: null,
  8754. id: null,
  8755. };
  8756. if($rootScope.businessCode) {
  8757. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function(data) {
  8758. $scope.id = data.id;
  8759. $scope.order.cust.enName = data.vendorEnterprise.enName;
  8760. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  8761. $scope.order.cust.uu = data.vendorEnterprise.uu;
  8762. $rootScope.venduu = data.vendorEnterprise.uu;
  8763. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8764. $scope.contacts = data;
  8765. $scope.order.vendor = $scope.contacts[0];
  8766. });
  8767. }, function(response) {
  8768. });
  8769. };
  8770. // 查找供应商
  8771. $scope.dbfindCust = function(){
  8772. var modalInstance = $modal.open({
  8773. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  8774. controller: 'DbfindVendorInfoCtrl',
  8775. size: 'lg',
  8776. resolve: {
  8777. orderItems: function() {
  8778. return $scope.order.orderItems;
  8779. }
  8780. }
  8781. });
  8782. modalInstance.result.then(function(data) {
  8783. $rootScope.venduu = data.vendorEnterprise.uu;
  8784. $scope.id = data.id;
  8785. $scope.order.cust = data.vendorEnterprise;
  8786. $scope.order.custUser = data.vendorUser;
  8787. $scope.order.orderItems = [];
  8788. var item = {
  8789. code: null,
  8790. title: null,
  8791. spec: null,
  8792. unit: null,
  8793. qty: null,
  8794. price: null,
  8795. remark: null,
  8796. delivery: null,
  8797. };
  8798. // $scope.order.orderItems.push(item);
  8799. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  8800. $scope.contacts = data;
  8801. $scope.order.vendor = $scope.contacts[0];
  8802. });
  8803. }, function(){
  8804. });
  8805. };
  8806. // 联想词 start
  8807. // 获取供应商
  8808. $scope.getSimilarVendors = function(value) {
  8809. console.log(value);
  8810. if (value) {
  8811. return Vendor.getSimilarVendors({keyword : value}).$promise.then(function(data) {
  8812. return data.map(function(item) {
  8813. return item;
  8814. });
  8815. });
  8816. }
  8817. };
  8818. $scope.onAssociateCmpClick = function(vendor, order) {
  8819. $scope.order.cust.uu = vendor.venduu;
  8820. $rootScope.venduu = $scope.order.cust.uu;
  8821. }
  8822. // 联想词 end
  8823. // $scope.order.orderItems.push(item);
  8824. if($rootScope.prodId) {
  8825. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function(data) {
  8826. item.code = data.code;
  8827. item.title = data.title;
  8828. item.spec = data.spec;
  8829. item.unit = data.unit;
  8830. item.id = data.id;
  8831. $scope.order.orderItems.push(item);
  8832. }, function(response) {
  8833. });
  8834. }
  8835. //增加商品
  8836. $scope.addProduct = function(index) {
  8837. if($scope.order.orderItems[index].code == null) {
  8838. toaster.pop('info', '提示', '请先选择商品');
  8839. } else {
  8840. $scope.order.orderItems.push({code: null, title: null, spec: null, unit: null, qty: null, price: null, remark: null, delivery: null, $endDateOpen: false});
  8841. }
  8842. };
  8843. //删除商品
  8844. $scope.deleteProduct = function(index) {
  8845. $scope.order.orderItems.splice(index, 1);
  8846. };
  8847. // 搜索框回车
  8848. $scope.onSearch = function(keyword) {
  8849. $scope.keyword = keyword;
  8850. $scope.tableParams.page(1);
  8851. $scope.tableParams.reload();
  8852. };
  8853. $scope.tableParams = new ngTableParams({
  8854. page : 1,
  8855. count : 10
  8856. }, {
  8857. total : 0,
  8858. counts: [5, 10, 25, 50],
  8859. getData : function($defer, params) {
  8860. $scope.loading = true;
  8861. var pageParams = params.url();
  8862. pageParams.keyword = $scope.keyword;
  8863. $scope.tip = $scope.keyword;
  8864. pageParams.custUU = $scope.order.cust.uu;
  8865. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  8866. $scope.loading = false;
  8867. if(page) {
  8868. params.total(page.totalElement);
  8869. $scope.total = page.totalElement;
  8870. $defer.resolve(page.content);
  8871. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8872. }
  8873. }, function(response){
  8874. $scope.loading = false;
  8875. toaster.pop('error', '数据加载失败', response.data);
  8876. });
  8877. }
  8878. });
  8879. // 选择
  8880. $scope.check = function(data) {
  8881. $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});
  8882. };
  8883. // 监听custuu发生变化,重新加载物料信息
  8884. $scope.$watch('order.cust.uu', function(n, o) {
  8885. if(n==o) {
  8886. return;
  8887. } else {
  8888. $scope.tableParams.page(1);
  8889. $scope.tableParams.reload();
  8890. }
  8891. }, true);
  8892. // 查找客户物料
  8893. $scope.dbfindCustProd = function(index){
  8894. if($scope.order.cust.uu) {
  8895. var modalInstance = $modal.open({
  8896. templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
  8897. controller: 'DbfindCustProdCtrl',
  8898. size: 'lg',
  8899. resolve: {
  8900. custUU: function() {
  8901. return $scope.order.cust.uu
  8902. }
  8903. }
  8904. });
  8905. modalInstance.result.then(function(data) {
  8906. $scope.order.orderItems.push(data);
  8907. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8908. if($scope.order.orderItems[i].code == null || i == index) {
  8909. $scope.order.orderItems.splice(i, 1);
  8910. }
  8911. }
  8912. }, function() {
  8913. });
  8914. } else {
  8915. toaster.pop('info', '提示', '请先选择供应商');
  8916. }
  8917. };
  8918. $scope.getMinDate = function(item) {
  8919. return $filter('date')(new Date, 'yyyy-MM-dd');
  8920. };
  8921. $scope.openDatePicker = function($event, openParam, index) {
  8922. $event.preventDefault();
  8923. $event.stopPropagation();
  8924. $scope.order.orderItems[index].$endDateOpen = !openParam;
  8925. };
  8926. // 添加到购物车
  8927. $scope.addToCart = function(order) {
  8928. $scope.loading = true;
  8929. $scope.order.vendusertel = order.vendor.tel;
  8930. $scope.order.venduser = order.vendor.venduser;
  8931. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  8932. $scope.order.custUU = $scope.order.cust.uu;
  8933. $scope.order.custUserUU = $scope.order.custUser.userUU;
  8934. if($scope.order.date instanceof Date) {
  8935. $scope.order.date = $scope.order.date.getTime();
  8936. }
  8937. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8938. if($scope.order.orderItems[i].delivery instanceof Date) {
  8939. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  8940. }
  8941. if($scope.order.currency != 'RMB') {
  8942. $scope.order.orderItems[i].rate = 0;
  8943. }
  8944. }
  8945. addtoCart.save({}, $scope.order, function(data){
  8946. $scope.loading = false;
  8947. toaster.pop('success', '成功', '保存成功');
  8948. window.location.hash = '#/purc/cart/'+data.id;
  8949. }, function(response){
  8950. $scope.loading = false;
  8951. toaster.pop('error', '保存失败', response.data);
  8952. });
  8953. };
  8954. // 立即购买
  8955. $scope.addToOrder = function(order) {
  8956. $scope.loading = true;
  8957. $scope.order.vendusertel = order.vendor.tel;
  8958. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  8959. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  8960. $scope.order.custUU = $scope.order.cust.uu;
  8961. $scope.order.custUserUU = $scope.order.custUser.userUU;
  8962. if($scope.order.date instanceof Date) {
  8963. $scope.order.date = $scope.order.date.getTime();
  8964. }
  8965. for(var i = 0; i < $scope.order.orderItems.length; i++) {
  8966. if($scope.order.orderItems[i].delivery instanceof Date) {
  8967. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  8968. }
  8969. if($scope.order.currency != 'RMB') {
  8970. $scope.order.orderItems[i].rate = 0;
  8971. }
  8972. }
  8973. newPurcOrder.save({}, $scope.order, function(data){
  8974. $scope.loading = false;
  8975. toaster.pop('success', '成功', '保存成功');
  8976. window.location.hash = '#/purc/order/'+data.id;
  8977. }, function(response){
  8978. $scope.loading = false;
  8979. toaster.pop('error', '保存失败', response.data);
  8980. });
  8981. };
  8982. // 新增收货地址保存
  8983. $scope.saveShipAddress = function(ship) {
  8984. ship.address = ship.province + ship.city + ship.district;
  8985. ShipAddress.saveAddress( {}, ship, function(data) {
  8986. if(data.success) {
  8987. ShipAddress.shipAddList({}, function(data) {
  8988. $scope.ships = data;
  8989. $scope.order.shipadd = $scope.ships[0];
  8990. });
  8991. toaster.pop('success', '提示', data.success);
  8992. }
  8993. if(data.error) {
  8994. toaster.pop('error', '提示', data.error);
  8995. }
  8996. });
  8997. }
  8998. // 新增供应商联系人
  8999. $scope.addContact = function(uu) {
  9000. var modalInstance = $modal.open({
  9001. animation: true,
  9002. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  9003. controller: 'AddContacCtrl',
  9004. resolve: {
  9005. }
  9006. });
  9007. modalInstance.result.then(function(data) {
  9008. $scope.contact = data;
  9009. $scope.contact.venduu = uu;
  9010. Vendor.saveContact({}, $scope.contact, function(data) {
  9011. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function(data) {
  9012. $scope.contacts = data;
  9013. $scope.order.vendor = $scope.contacts[0];
  9014. });
  9015. toaster.pop('success', '提示', '联系人保存成功');
  9016. }, function(response) {
  9017. toaster.pop('error', '失败', response.data);
  9018. });
  9019. });
  9020. }
  9021. }]);
  9022. // 查找供应商
  9023. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems){
  9024. $scope.prod = false;
  9025. if(orderItems.length != 0) {
  9026. $scope.prod = true;
  9027. }
  9028. BaseService.scrollBackToTop();
  9029. if($rootScope.venduu != null) {
  9030. $scope.venduu = $rootScope.venduu;
  9031. }
  9032. // 搜索框回车
  9033. $scope.onSearch = function(keyword) {
  9034. $scope.keyword = keyword;
  9035. $scope.customerParams.page(1);
  9036. $scope.customerParams.reload();
  9037. };
  9038. $scope.customerParams = new ngTableParams({
  9039. page : 1,
  9040. count : 10
  9041. }, {
  9042. total : 0,
  9043. counts: [5, 10, 25, 50],
  9044. getData : function($defer, params) {
  9045. $scope.loading = true;
  9046. var pageParams = params.url();
  9047. pageParams.keyword = $scope.keyword;
  9048. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  9049. $scope.loading = false;
  9050. if(page) {
  9051. params.total(page.totalElements);
  9052. $defer.resolve(page.content);
  9053. }
  9054. $scope.totalCount = page.totalElements;
  9055. }, function(response){
  9056. $scope.loading = false;
  9057. toaster.pop('error', '数据加载失败', response.data);
  9058. });
  9059. }
  9060. });
  9061. $scope.cancel = function() {
  9062. $modalInstance.dismiss();
  9063. };
  9064. $scope.ensure = false;
  9065. $scope.check = function(vendor) { // 需要进行判断的选择
  9066. console.log(vendor);
  9067. $scope.vendorInfo = vendor;
  9068. $scope.ensure = true;
  9069. };
  9070. $scope.checkVendor = function(vendor) { // 直接选择
  9071. $modalInstance.close(vendor);
  9072. }
  9073. }]);
  9074. /**
  9075. * 我的客户
  9076. */
  9077. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster){
  9078. $scope.userInfoResult = true;
  9079. AuthenticationService.getAuthentication().success(function(data) {
  9080. $scope.loading = false;
  9081. $scope.thisUser = data;
  9082. });
  9083. var getCustInfos = function(custuu) {
  9084. if(custuu) {
  9085. VendorService.userInfo.query({uu:custuu},null,function(data) {
  9086. $scope.custInfos = data;
  9087. var getPage = function(page, size){
  9088. if($scope.custInfos) {
  9089. var result = {};
  9090. result.totalCount = $scope.custInfos.length;
  9091. result.content = $scope.custInfos.slice((page - 1)*size, page * size);
  9092. if($scope.custInfos.length % size == 0) {
  9093. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  9094. }else {
  9095. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  9096. }
  9097. result.first = page == 1;
  9098. result.last = page == result.totalPage;
  9099. result.page = page;
  9100. result.next = page - 0 + 1;
  9101. result.pre = page - 1;
  9102. return result;
  9103. }
  9104. }
  9105. $scope.userdata = getPage(1,4);
  9106. $scope.first = function (){
  9107. $scope.userdata = getPage($scope.userdata.pre,4);
  9108. }
  9109. $scope.last = function (){
  9110. $scope.userdata = getPage($scope.userdata.next,4);
  9111. }
  9112. }, function(response){
  9113. $scope.loading = false;
  9114. toaster.pop('error', '数据加载失败', response.data);
  9115. });
  9116. }
  9117. }
  9118. $scope.addUserInfo = function(customer) {
  9119. //TODO
  9120. if ($scope.thisUser.sys) {
  9121. var modalInstance = $modal.open({
  9122. animation: true,
  9123. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  9124. controller: 'AddUserInfoCtrl',
  9125. resolve: {
  9126. customer: function() {
  9127. return customer;
  9128. }
  9129. }
  9130. });
  9131. modalInstance.result.then(function(changed, checked){
  9132. if(changed) {
  9133. if(checked)
  9134. $scope.newUser.roles = checked;
  9135. else
  9136. loadUsers();
  9137. }
  9138. });
  9139. } else {
  9140. toaster.pop('error', '您不是管理员,无权限分配用户!');
  9141. }
  9142. }
  9143. $scope.showUserInfo = function(customer,boo) {
  9144. $scope.custInfo = customer;
  9145. if(boo) {
  9146. getCustInfos(customer.myEnterprise.uu);
  9147. $scope.userInfoResult = true;
  9148. }
  9149. }
  9150. $scope.customerParams = new ngTableParams({
  9151. page : 1,
  9152. count : 10
  9153. }, {
  9154. total : 0,
  9155. counts: [5, 10, 25, 50],
  9156. getData : function($defer, params) {
  9157. $scope.loading = true;
  9158. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  9159. $scope.loading = false;
  9160. if(page) {
  9161. params.total(page.totalElements);
  9162. $defer.resolve(page.content);
  9163. }
  9164. $scope.totalCount = page.totalElements;
  9165. }, function(response){
  9166. $scope.loading = false;
  9167. toaster.pop('error', '数据加载失败', response.data);
  9168. });
  9169. }
  9170. });
  9171. }]);
  9172. /**
  9173. * 我的供应商
  9174. */
  9175. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  9176. BaseService.scrollBackToTop();
  9177. // 搜索框回车
  9178. $scope.onSearch = function(keyword) {
  9179. $scope.keyword = keyword;
  9180. $scope.customerParams.page(1);
  9181. $scope.customerParams.reload();
  9182. };
  9183. $scope.customerParams = new ngTableParams({
  9184. page : 1,
  9185. count : 10
  9186. }, {
  9187. total : 0,
  9188. counts: [5, 10, 25, 50],
  9189. getData : function($defer, params) {
  9190. $scope.loading = true;
  9191. var pageParams = params.url();
  9192. pageParams.keyword = $scope.keyword;
  9193. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  9194. $scope.loading = false;
  9195. if(page) {
  9196. params.total(page.totalElements);
  9197. $scope.total = page.totalElement;
  9198. $defer.resolve(page.content);
  9199. }
  9200. $scope.totalCount = page.totalElements;
  9201. }, function(response){
  9202. $scope.loading = false;
  9203. toaster.pop('error', '数据加载失败', response.data);
  9204. });
  9205. }
  9206. });
  9207. // 查看供应商详情
  9208. $scope.VendorDetail = function(id, uu) {
  9209. $rootScope.vendorId = id;
  9210. $rootScope.vendoruu = uu;
  9211. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  9212. }
  9213. // 向企业购买
  9214. $scope.purcByEn = function(businessCode) {
  9215. $rootScope.businessCode = businessCode;
  9216. window.location.hash = "#/purc/addOrder";
  9217. }
  9218. }]);
  9219. /**
  9220. * 供应商详情
  9221. */
  9222. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  9223. BaseService.scrollBackToTop();
  9224. $scope.vendorContacts = [];
  9225. var loadData = function() {
  9226. Vendor.getVendorDetail({id: $stateParams.id}, {}, function(data) {
  9227. $scope.vendor = data.vendorEnterprise;
  9228. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  9229. $scope.vendorContacts = data;
  9230. });
  9231. });
  9232. };
  9233. loadData();
  9234. // 新增供应商联系人
  9235. $scope.addContact = function(uu) {
  9236. var modalInstance = $modal.open({
  9237. animation: true,
  9238. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  9239. controller: 'AddContacCtrl',
  9240. resolve: {
  9241. }
  9242. });
  9243. modalInstance.result.then(function(data) {
  9244. $scope.contact = data;
  9245. $scope.contact.venduu = uu;
  9246. Vendor.saveContact({}, $scope.contact, function(data) {
  9247. toaster.pop('success', '提示', '联系人保存成功');
  9248. $scope.vendorContacts.push(data);
  9249. }, function(response) {
  9250. toaster.pop('error', '失败', response.data);
  9251. });
  9252. });
  9253. }
  9254. // 编辑供应商联系人
  9255. $scope.edit = function(contact) {
  9256. var modalInstance = $modal.open({
  9257. animation: true,
  9258. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  9259. controller: 'EditContacCtrl',
  9260. resolve: {
  9261. contact: function() {
  9262. return contact;
  9263. }
  9264. }
  9265. });
  9266. modalInstance.result.then(function(data) {
  9267. $scope.contact = data;
  9268. Vendor.saveContact({}, $scope.contact, function(data) {
  9269. toaster.pop('success', '提示', '联系人修改成功');
  9270. }, function(response) {
  9271. toaster.pop('error', '失败', response.data);
  9272. });
  9273. });
  9274. }
  9275. // 删除供应商联系人
  9276. $scope.deleteById = function(id, index) {
  9277. $scope.vendorContacts.splice(index, 1);
  9278. Vendor.deleteContact({id: id}, {}, function(data) {
  9279. toaster.pop('success', '提示', '供应商联系人删除成功');
  9280. }, function(response) {
  9281. toaster.pop('error', '提示', response.data);
  9282. });
  9283. }
  9284. // 供应商物料信息
  9285. $scope.viewProdList = function(uu){
  9286. $scope.uu = uu;
  9287. $scope.tableParams.page(1);
  9288. $scope.tableParams.reload();
  9289. };
  9290. // 搜索框回车
  9291. $scope.onSearch = function(keyword) {
  9292. $scope.keyword = keyword;
  9293. $scope.tableParams.page(1);
  9294. $scope.tableParams.reload();
  9295. };
  9296. // 供应商物料信息
  9297. $scope.tableParams = new ngTableParams({
  9298. page : 1,
  9299. count : 10
  9300. }, {
  9301. total : 0,
  9302. counts: [5, 10, 25, 50],
  9303. getData : function($defer, params) {
  9304. $scope.loading = true;
  9305. var pageParams = params.url();
  9306. pageParams.custUU = $scope.uu;
  9307. pageParams.keyword = $scope.keyword;
  9308. $scope.tip = $scope.keyword;
  9309. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  9310. $scope.loading = false;
  9311. if(page) {
  9312. params.total(page.totalElement);
  9313. $scope.total = page.totalElement;
  9314. $defer.resolve(page.content);
  9315. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9316. }
  9317. }, function(response){
  9318. $scope.loading = false;
  9319. toaster.pop('error', '数据加载失败', response.data);
  9320. });
  9321. }
  9322. });
  9323. /**
  9324. * 选中单个物料购买
  9325. * @param businessCode
  9326. * @param id
  9327. */
  9328. $scope.PurcByEnAndProd = function(businessCode, id) {
  9329. $rootScope.businessCode = businessCode;
  9330. $rootScope.prodId = id;
  9331. window.location.hash = "#/purc/addOrder";
  9332. }
  9333. }]);
  9334. /**
  9335. * 编辑供应商联系人
  9336. */
  9337. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function($scope, toaster, $modalInstance, contact) {
  9338. $scope.contact = contact;
  9339. $scope.save = function(contact) {
  9340. $modalInstance.close(contact);
  9341. }
  9342. $scope.cancel = function() {
  9343. $modalInstance.dismiss();
  9344. }
  9345. }]);
  9346. /**
  9347. * 新增供应商联系人
  9348. */
  9349. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function($scope, toaster, $modalInstance) {
  9350. $scope.save = function(contact) {
  9351. $modalInstance.close(contact);
  9352. }
  9353. $scope.cancel = function() {
  9354. $modalInstance.dismiss();
  9355. }
  9356. }]);
  9357. /**
  9358. * 建立合作关系申请
  9359. */
  9360. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', function($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout) {
  9361. BaseService.scrollBackToTop();
  9362. $scope.active = 'todo';
  9363. var getRequestStatus = function(active) {
  9364. var fn = 'getAllRequest';
  9365. switch(active) {
  9366. case 'done':
  9367. fn = 'getRequestDone';break;
  9368. case 'todo':
  9369. fn = 'getRequestTodo';break;
  9370. case 'end':
  9371. fn = 'getRequestEnd';break;
  9372. }
  9373. return fn;
  9374. }
  9375. // 切换单据类型
  9376. $scope.setActive = function(state) {
  9377. if($scope.active != state) {
  9378. $scope.active = state;
  9379. if($scope.tableParams.page() == 1)
  9380. $scope.tableParams.reload();
  9381. else
  9382. $scope.tableParams.page(1);
  9383. }
  9384. };
  9385. // 切换数据来源(正常数据 or 历史数据)
  9386. var getService = function() {
  9387. return AddPartnerMyRequest;
  9388. };
  9389. $scope.tableParams = new ngTableParams({ // ng-Table参数
  9390. page : 1,
  9391. count : 5,
  9392. sorting: {
  9393. }
  9394. }, {
  9395. total : 0,
  9396. counts: [5, 10, 15, 25, 50],
  9397. getData : function($defer, params) { // 获取数据的方法
  9398. $scope.loading = true;
  9399. var pageParams = params.url();
  9400. pageParams.keyword = $scope.keyword;
  9401. $scope.tip = $scope.keyword;
  9402. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9403. $scope.loading = false;
  9404. if(page) {
  9405. params.total(page.totalElement);
  9406. $defer.resolve(page.content);
  9407. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9408. }
  9409. }, function(response){
  9410. $scope.loading = false;
  9411. toaster.pop('error', '数据加载失败', response.data);
  9412. });
  9413. }
  9414. });
  9415. // 再次申请
  9416. $scope.reapply = function(id) {
  9417. AddPartner.reapply({id: id}, {}, function(data) {
  9418. toaster.pop('success', '提示', '操作成功');
  9419. }, function(response) {
  9420. toaster.pop('error','失败',response.data);
  9421. });
  9422. }
  9423. // 添加为供应商
  9424. $scope.addSupplier = function(vendUID) {
  9425. AddPartner.addSupplier({businessCode: vendUID}, {}, function(data) {
  9426. if(data.success) {
  9427. toaster.pop('success', '提示', data.success);
  9428. }
  9429. if(data.error) {
  9430. toaster.pop('error','提示', data.error);
  9431. }
  9432. }, function(response) {
  9433. toaster.pop('error', '失败', response.data);
  9434. })
  9435. };
  9436. // 添加客户
  9437. $scope.addCust = function(vendUID) {
  9438. AddPartner.addCust({businessCode: vendUID}, {}, function(data) {
  9439. if(data.success) {
  9440. toaster.pop('success', '提示', data.success);
  9441. }
  9442. if(data.error) {
  9443. toaster.pop('error','提示', data.error);
  9444. }
  9445. }, function(response) {
  9446. toaster.pop('error', '失败', response.data);
  9447. })
  9448. };
  9449. // 搜索框回车
  9450. $scope.onSearch = function() {
  9451. $scope.tableParams.page(1);
  9452. $scope.tableParams.reload();
  9453. };
  9454. // 同意申请
  9455. $scope.agree = function(id) {
  9456. AddPartner.agreeRequest({id: id}, {}, function(data) {
  9457. toaster.pop('success', '提示', '操作成功');
  9458. $timeout(function() {
  9459. window.location.reload();
  9460. }, 500);
  9461. }, function(response) {
  9462. toaster.pop('error', '提示', response.data);
  9463. });
  9464. }
  9465. // 拒绝申请
  9466. $scope.refuse = function(id, reason) {
  9467. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  9468. toaster.pop('success', '提示', '操作成功');
  9469. $timeout(function() {
  9470. window.location.reload();
  9471. }, 500);
  9472. }, function(response) {
  9473. toaster.pop('error', '提示', response.data);
  9474. });
  9475. }
  9476. $scope.status = 'send';
  9477. }]);
  9478. /**
  9479. * 建立合作关系处理申请
  9480. */
  9481. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', function($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner) {
  9482. BaseService.scrollBackToTop();
  9483. $scope.active = 'todo';
  9484. var getMessagetStatus = function(active) {
  9485. var fn = 'getAllMessage';
  9486. switch(active) {
  9487. case 'done':
  9488. fn = 'getMessageDone';break;
  9489. case 'todo':
  9490. fn = 'getMessageTodo';break;
  9491. case 'end':
  9492. fn = 'getMessageEnd';break;
  9493. }
  9494. return fn;
  9495. }
  9496. // 切换单据类型
  9497. $scope.setActive = function(state) {
  9498. if($scope.active != state) {
  9499. $scope.active = state;
  9500. if($scope.tableParams.page() == 1)
  9501. $scope.tableParams.reload();
  9502. else
  9503. $scope.tableParams.page(1);
  9504. }
  9505. };
  9506. var getService = function() {
  9507. return AddPartnerMyMessage;
  9508. };
  9509. $scope.tableParams = new ngTableParams({ // ng-Table参数
  9510. page : 1,
  9511. count : 5,
  9512. sorting: {
  9513. }
  9514. }, {
  9515. total : 0,
  9516. counts: [5, 10, 15, 25, 50],
  9517. getData : function($defer, params) { // 获取数据的方法
  9518. $scope.loading = true;
  9519. var pageParams = params.url();
  9520. pageParams.searchFilter = { // 筛选条件
  9521. keyword: $scope.keyword,
  9522. };
  9523. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  9524. $scope.loading = false;
  9525. console.log(page);
  9526. if(page) {
  9527. params.total(page.totalElement);
  9528. $defer.resolve(page.content);
  9529. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9530. }
  9531. }, function(response){
  9532. $scope.loading = false;
  9533. toaster.pop('error', '数据加载失败', response.data);
  9534. });
  9535. }
  9536. });
  9537. // 同意申请
  9538. $scope.agree = function(id) {
  9539. AddPartner.agreeRequest({id: id}, {}, function(data) {
  9540. toaster.pop('success', '提示', '操作成功');
  9541. }, function(response) {
  9542. toaster.pop('error', '提示', response.data);
  9543. });
  9544. }
  9545. // 拒绝申请
  9546. $scope.refuse = function(id, reason) {
  9547. AddPartner.refuseRequest({id: id, reason: reason}, {}, function(data) {
  9548. toaster.pop('success', '提示', '操作成功');
  9549. }, function(response) {
  9550. toaster.pop('error', '提示', response.data);
  9551. });
  9552. }
  9553. $scope.status = 'get';
  9554. }]);
  9555. /**
  9556. * 我的合作伙伴
  9557. */
  9558. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function($scope, toaster, GetProductInfo, BaseService) {
  9559. BaseService.scrollBackToTop();
  9560. // 默认显示合作伙伴
  9561. $scope.status = 'news';
  9562. // 获取所有的合作伙伴
  9563. GetProductInfo.getAllPartners({}, function(data) {
  9564. console.log(data);
  9565. $scope.partners = data;
  9566. }, function(res) {
  9567. toaster.pop('error', '获取列表失败', res.data);
  9568. });
  9569. // 添加为客户
  9570. $scope.addCust = function(partner) {
  9571. GetProductInfo.addCust({}, partner, function(data) {
  9572. toaster.pop('success', '提示', '添加客户成功');
  9573. }, function(response) {
  9574. toaster.pop('error', '添加客户失败', response.data);
  9575. });
  9576. }
  9577. // 添加为供应商
  9578. $scope.addSupplier = function(partner) {
  9579. GetProductInfo.addSupplier({}, partner, function(data) {
  9580. toaster.pop('success', '提示', '添加供应商成功');
  9581. }, function(response) {
  9582. toaster.pop('error', '添加供应商失败', response.data);
  9583. });
  9584. }
  9585. }]);
  9586. /**
  9587. * 财务对账时,企业进行筛选操作
  9588. */
  9589. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', function($scope, $modalInstance, suuorname, FaApCheck) {
  9590. var getData = function(){
  9591. $scope.loading = true;
  9592. FaApCheck.getAllCustomers(function(data) {
  9593. $scope.custs = data;
  9594. $scope.loading = false;
  9595. });
  9596. };
  9597. getData();
  9598. $scope.select = function(suuorname) {
  9599. $modalInstance.close(suuorname);
  9600. }
  9601. $scope.close = function() {
  9602. $modalInstance.close();
  9603. }
  9604. }]);
  9605. /**
  9606. * 跳转到企业圈
  9607. */
  9608. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function($scope, GetProductInfo, toaster) {
  9609. GetProductInfo.businessGroups({}, function(data) {
  9610. window.open(data.url);
  9611. }, function(response) {
  9612. toaster.pop('error', '提示', response.data);
  9613. });
  9614. }]);
  9615. /**
  9616. * 购物车
  9617. */
  9618. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
  9619. BaseService.scrollBackToTop();
  9620. $scope.active = 'all';
  9621. $scope.agreedText = '全部';
  9622. $scope.dateZoneText = '一个月内';
  9623. $scope.condition = {dateZone: 1};
  9624. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9625. $scope.changeAgreed = function(agreed) {
  9626. $scope.condition.agreed = agreed;
  9627. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  9628. $scope.condition.$agreedOpen = false;
  9629. };
  9630. $scope.changeDateZone = function(zone) {
  9631. $scope.condition.dateZone = zone;
  9632. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  9633. $scope.condition.$dateZoneOpen = false;
  9634. getDateCondition(zone, $scope.condition);
  9635. $scope.tableParams.reload();
  9636. };
  9637. $scope.setActive = function(state) {
  9638. if($scope.active != state) {
  9639. $scope.active = state;
  9640. if($scope.tableParams.page() == 1)
  9641. $scope.tableParams.reload();
  9642. else
  9643. $scope.tableParams.page(1);
  9644. }
  9645. };
  9646. var getService = function() {
  9647. return getCartList;
  9648. };
  9649. $scope.tableParams = new ngTableParams({
  9650. page : 1,
  9651. count : 5,
  9652. sorting: {
  9653. date: 'desc',
  9654. }
  9655. }, {
  9656. total : 0,
  9657. counts: [5, 10, 25, 50],
  9658. getData : function($defer, params) {
  9659. $scope.loading = true;
  9660. var pageParams = params.url();
  9661. pageParams.keyword = $scope.keyword;
  9662. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  9663. $scope.loading = false;
  9664. if(page) {
  9665. params.total(page.totalElements);
  9666. $defer.resolve(page.content);
  9667. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  9668. }
  9669. }, function(response) {
  9670. $scope.loading = false;
  9671. toaster.pop('error', '数据加载失败', response.data);
  9672. });
  9673. }
  9674. });
  9675. $scope.getCartTotal = function(items) {
  9676. var sum = 0;
  9677. angular.forEach(items, function(item){
  9678. sum += item.qty * item.price;
  9679. });
  9680. return sum;
  9681. };
  9682. // 搜索框回车
  9683. $scope.onSearch = function() {
  9684. $scope.tableParams.page(1);
  9685. $scope.tableParams.reload();
  9686. };
  9687. // 提交
  9688. $scope.addtoOrder = function(id) {
  9689. console.log(id);
  9690. cartOperation.addToOrder({id: id}, {}, function(data) {
  9691. if(data.success) {
  9692. toaster.pop('success', '提示', data.success);
  9693. $timeout(function() {
  9694. window.location.hash = '#/purc/order/'+data.id;
  9695. },500);
  9696. }
  9697. if(data.error) {
  9698. toaster.pop('error', '提示', data.error);
  9699. }
  9700. }, function(response) {
  9701. toaster.pop('erroer', '提示', response.data);
  9702. });
  9703. };
  9704. // 删除一条主记录
  9705. $scope.deleteCart = function(id) {
  9706. cartOperation.deleteCart({id: id}, {}, function(data) {
  9707. if(data.success) {
  9708. toaster.pop('success', '提示', data.success);
  9709. $timeout(function() {
  9710. window.location.reload();
  9711. },500);
  9712. }
  9713. if(data.error) {
  9714. toaster.pop('error', '提示', data.error);
  9715. }
  9716. }, function(response) {
  9717. toaster.pop('erroer', '提示', response.data);
  9718. });
  9719. };
  9720. // 删除一条明细
  9721. $scope.deleteDetail = function(id) {
  9722. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  9723. if(data.success) {
  9724. toaster.pop('success', '提示', data.success);
  9725. $timeout(function() {
  9726. window.location.reload();
  9727. },500);
  9728. }
  9729. if(data.error) {
  9730. toaster.pop('error', '提示', data.error);
  9731. }
  9732. }, function(response) {
  9733. toaster.pop('erroer', '提示', response.data);
  9734. });
  9735. };
  9736. // 清空购物车
  9737. $scope.clearCart = function() {
  9738. cartOperation.deleteCarts({}, function(data) {
  9739. if(data.success) {
  9740. toaster.pop('success', '提示', data.success);
  9741. $timeout(function() {
  9742. window.location.reload();
  9743. },500);
  9744. }
  9745. if(data.error) {
  9746. toaster.pop('error', '提示', data.error);
  9747. }
  9748. }, function(response) {
  9749. toaster.pop('erroer', '提示', response.data);
  9750. });
  9751. }
  9752. }]);
  9753. /**
  9754. * 购物车详情
  9755. */
  9756. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', function($scope, cartOperation, $stateParams, toaster, $timeout, BaseService) {
  9757. BaseService.scrollBackToTop();
  9758. var loadData = function() {
  9759. cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
  9760. if(data.code) {
  9761. $scope.cart = data;
  9762. var sum = 0;
  9763. angular.forEach($scope.cart.cartDetails, function(item) {
  9764. sum += item.qty * item.price;
  9765. });
  9766. $scope.cart.total = sum;
  9767. $scope.loading = false;
  9768. } else {
  9769. window.location.hash = '#/purc/cart';
  9770. }
  9771. });
  9772. };
  9773. loadData();
  9774. // 删除一条明细
  9775. $scope.deleteDetail = function(id) {
  9776. cartOperation.deleteCartDetail({id: id}, {}, function(data) {
  9777. if(data.success) {
  9778. toaster.pop('success', '提示', data.success);
  9779. $timeout(function() {
  9780. window.location.reload();
  9781. },500);
  9782. }
  9783. if(data.error) {
  9784. toaster.pop('error', '提示', data.error);
  9785. }
  9786. }, function(response) {
  9787. toaster.pop('erroer', '提示', response.data);
  9788. });
  9789. };
  9790. // 删除一条主记录
  9791. $scope.deleteCart = function(id) {
  9792. cartOperation.deleteCart({id: id}, {}, function(data) {
  9793. if(data.success) {
  9794. toaster.pop('success', '提示', data.success);
  9795. $timeout(function() {
  9796. window.location.reload();
  9797. },500);
  9798. }
  9799. if(data.error) {
  9800. toaster.pop('error', '提示', data.error);
  9801. }
  9802. }, function(response) {
  9803. toaster.pop('erroer', '提示', response.data);
  9804. });
  9805. };
  9806. // 提交
  9807. $scope.addtoOrder = function(id) {
  9808. console.log(id);
  9809. cartOperation.addToOrder({id: id}, {}, function(data) {
  9810. if(data.success) {
  9811. toaster.pop('success', '提示', data.success);
  9812. $timeout(function() {
  9813. window.location.hash = '#/purc/order/'+data.id;
  9814. },500);
  9815. }
  9816. if(data.error) {
  9817. toaster.pop('error', '提示', data.error);
  9818. }
  9819. }, function(response) {
  9820. toaster.pop('erroer', '提示', response.data);
  9821. });
  9822. };
  9823. }]);
  9824. /**
  9825. * 审批流
  9826. */
  9827. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function($scope, toaster, $modal, appFlow, BaseService) {
  9828. BaseService.scrollBackToTop();
  9829. $scope.vacation = false;
  9830. $scope.workovertime = false;
  9831. $scope.workdaily = false;
  9832. $scope.feeplease = false;
  9833. $scope.signapp = false;
  9834. appFlow.viewAppFlow({}, function(data) {// 获取已设置的列表
  9835. $scope.nodes = data;
  9836. angular.forEach($scope.nodes, function(node) {
  9837. if(node.appname = '请假单') {
  9838. $scope.vacation = true;
  9839. }
  9840. if(node.appname = '加班单') {
  9841. $scope.workovertime = true;
  9842. }
  9843. if(node.appname = '工作日报') {
  9844. $scope.workdaily = true;
  9845. }
  9846. if(node.appname = '出差单') {
  9847. $scope.feeplease = true;
  9848. }
  9849. if(node.appname = '申诉单') {
  9850. $scope.signapp = true;
  9851. }
  9852. });
  9853. }, function(response) {
  9854. });
  9855. $scope.NoteSet = function() {
  9856. var modalInstance = $modal.open({
  9857. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9858. controller: 'NoteStep1Ctrl',
  9859. size: 'lg',
  9860. resolve: {
  9861. AppName: function() {
  9862. return '请假单';
  9863. }
  9864. }
  9865. });
  9866. modalInstance.result.then(function(data) {
  9867. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9868. if(data.error) {
  9869. toaster.pop('error', '提示', data.error);
  9870. }
  9871. if(data.success) {
  9872. toaster.pop('success', '提示', data.success);
  9873. }
  9874. }, function(response) {
  9875. });
  9876. }, function(){
  9877. });
  9878. }
  9879. $scope.overTimeSet = function() {
  9880. var modalInstance = $modal.open({
  9881. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9882. controller: 'NoteStep1Ctrl',
  9883. size: 'lg',
  9884. resolve: {
  9885. AppName: function() {
  9886. return '加班单';
  9887. }
  9888. }
  9889. });
  9890. modalInstance.result.then(function(data) {
  9891. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9892. if(data.error) {
  9893. toaster.pop('error', '提示', data.error);
  9894. }
  9895. if(data.success) {
  9896. toaster.pop('success', '提示', data.success);
  9897. }
  9898. }, function(response) {
  9899. });
  9900. }, function(){
  9901. });
  9902. }
  9903. $scope.feePleaseSet = function() {
  9904. var modalInstance = $modal.open({
  9905. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9906. controller: 'NoteStep1Ctrl',
  9907. size: 'lg',
  9908. resolve: {
  9909. AppName: function() {
  9910. return '出差单';
  9911. }
  9912. }
  9913. });
  9914. modalInstance.result.then(function(data) {
  9915. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9916. if(data.error) {
  9917. toaster.pop('error', '提示', data.error);
  9918. }
  9919. if(data.success) {
  9920. toaster.pop('success', '提示', data.success);
  9921. }
  9922. }, function(response) {
  9923. });
  9924. }, function(){
  9925. });
  9926. }
  9927. $scope.workDailySet = function() {
  9928. var modalInstance = $modal.open({
  9929. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9930. controller: 'NoteStep1Ctrl',
  9931. size: 'lg',
  9932. resolve: {
  9933. AppName: function() {
  9934. return '工作日报';
  9935. }
  9936. }
  9937. });
  9938. modalInstance.result.then(function(data) {
  9939. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9940. if(data.error) {
  9941. toaster.pop('error', '提示', data.error);
  9942. }
  9943. if(data.success) {
  9944. toaster.pop('success', '提示', data.success);
  9945. }
  9946. }, function(response) {
  9947. });
  9948. }, function(){
  9949. });
  9950. }
  9951. $scope.signAppSet = function() {
  9952. var modalInstance = $modal.open({
  9953. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  9954. controller: 'NoteStep1Ctrl',
  9955. size: 'lg',
  9956. resolve: {
  9957. AppName: function() {
  9958. return '申诉单';
  9959. }
  9960. }
  9961. });
  9962. modalInstance.result.then(function(data) {
  9963. appFlow.saveAppFlowSet({json: data}, {}, function(data) {
  9964. if(data.error) {
  9965. toaster.pop('error', '提示', data.error);
  9966. }
  9967. if(data.success) {
  9968. toaster.pop('success', '提示', data.success);
  9969. }
  9970. }, function(response) {
  9971. });
  9972. }, function(){
  9973. });
  9974. }
  9975. }]);
  9976. /**
  9977. * 审核条件设置
  9978. */
  9979. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  9980. $scope.appName = AppName;// 标题名称
  9981. $scope.AppFlow = {appName: $scope.appName,
  9982. appNodes:{}};
  9983. $scope.AppFlow.appNodes = [];
  9984. appFlow.getNodeByName({name: AppName}, {}, function(data) {// 通过单据名称查询单个审批流
  9985. if(data.appNodes.length != 0) {
  9986. $scope.node = data;
  9987. $scope.AppFlow = data;
  9988. }
  9989. }, function() {
  9990. });
  9991. $scope.copy = function() {//复制
  9992. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  9993. toaster.pop('info', '提示', '复制成功');
  9994. $modalInstance.dismiss();
  9995. }
  9996. $scope.paste = function() {
  9997. $scope.AppFlow = {appName: $scope.appName, appNodes:{}};
  9998. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  9999. }
  10000. $scope.clear = function() {// 清空
  10001. $scope.AppFlow = {appName: $scope.appName,
  10002. appNodes:{}};
  10003. $scope.AppFlow.appNodes = [];
  10004. }
  10005. appFlow.getPositions({}, function(data) {// 获取人员信息
  10006. $scope.users = data;
  10007. }, function(response) {
  10008. });
  10009. appFlow.getPositionInfo({}, function(data) { // 获取职位信息
  10010. $scope.roles = data;
  10011. },function(response) {
  10012. });
  10013. $scope.SelectUser = function(data) { // 添加人员
  10014. var item = {
  10015. useruu: null,
  10016. username: null,
  10017. level: null
  10018. };
  10019. item.useruu = data.useruu;
  10020. item.username = data.username;
  10021. // if($scope.AppFlow.appNodes.length != 0){
  10022. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  10023. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  10024. // toaster.pop('info', '提示', '不能重复添加');
  10025. // } else {
  10026. // $scope.AppFlow.appNodes.push(item);
  10027. // }
  10028. // }
  10029. // } else {
  10030. $scope.AppFlow.appNodes.push(item);
  10031. // }
  10032. }
  10033. $scope.SelectRole = function(data) {// 添加职位
  10034. var item = {
  10035. position: null,
  10036. level: null
  10037. };
  10038. item.position = data;
  10039. $scope.AppFlow.appNodes.push(item);
  10040. }
  10041. $scope.deleteNode = function(index) {// 删除节点
  10042. $scope.AppFlow.appNodes.splice(index, 1);
  10043. };
  10044. $scope.saveNode = function() { // 保存
  10045. angular.forEach($scope.AppFlow.appNodes, function(value, key) {
  10046. $scope.AppFlow.appNodes[key].level = key;
  10047. });
  10048. if($scope.AppFlow.appNodes.length == 0) {
  10049. toaster.pop('info', '提示', '您还未设置审批人');
  10050. } else {
  10051. $modalInstance.close($scope.AppFlow);
  10052. };
  10053. };
  10054. $scope.cancel = function() {// 取消
  10055. $modalInstance.dismiss();
  10056. }
  10057. }]);
  10058. /***
  10059. * 代采定单
  10060. */
  10061. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', function($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService) {
  10062. BaseService.scrollBackToTop();
  10063. $scope.active = 'all';
  10064. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10065. $scope.total = null;
  10066. $scope.setActive = function(state) {
  10067. if($scope.active != state) {
  10068. $scope.active = state;
  10069. if($scope.tableParams.page() == 1)
  10070. $scope.tableParams.reload();
  10071. else
  10072. $scope.tableParams.page(1);
  10073. }
  10074. };
  10075. $scope.tableParams = new ngTableParams({
  10076. page : 1,
  10077. count : 5,
  10078. sorting: {
  10079. }
  10080. }, {
  10081. total : 0,
  10082. counts: [5, 10, 25, 50],
  10083. getData : function($defer, params) {
  10084. $scope.loading = true;
  10085. var pageParams = params.url();
  10086. pageParams.keyword = $scope.keyword;
  10087. getDeOrder[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  10088. $scope.loading = false;
  10089. if(page) {
  10090. params.total(page.totalElement);
  10091. $scope.total = page.totalElement;
  10092. $defer.resolve(page.content);
  10093. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  10094. }
  10095. }, function(response) {
  10096. $scope.loading = false;
  10097. toaster.pop('error', '数据加载失败', response.data);
  10098. });
  10099. }
  10100. });
  10101. //打印
  10102. $scope.print = function(deputyOrder) {
  10103. DeputyOrder.printCount({id: deputyOrder.id},{});//增加打印此次
  10104. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  10105. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  10106. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  10107. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  10108. //TODO 目前只有信扬有代采业务,先写死之后再改
  10109. ReportService.print(10044118, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  10110. ReportService.print(10044118, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  10111. ReportService.print(10044118, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  10112. ReportService.print(10044118, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  10113. };
  10114. // 搜索框回车
  10115. $scope.onSearch = function() {
  10116. $scope.tableParams.page(1);
  10117. $scope.tableParams.reload();
  10118. };
  10119. }]);
  10120. /**
  10121. * 新增代采订单
  10122. */
  10123. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', function($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService) {
  10124. BaseService.scrollBackToTop();
  10125. $scope.deOrder = {
  10126. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  10127. entrydate: new Date(),
  10128. status: '在录入',
  10129. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  10130. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  10131. riskmethod: '甲方承担',
  10132. taxpaymentmethod: '甲方承担',
  10133. totalamount: 0,
  10134. totalpayament: 0,
  10135. orderamount: 0,
  10136. usdpayment: 0
  10137. };
  10138. $scope.deOrder.deputyOrderItems = [];
  10139. var item = {
  10140. prodname: null,
  10141. prodcode: null,
  10142. prodspec: null,
  10143. amount: null,
  10144. unitprice: null,
  10145. remark: null,
  10146. orderprice: null,
  10147. };
  10148. $scope.deOrder.deputyOrderItems.push(item);
  10149. // 代采企业列表
  10150. DeputyOrder.deputyEnterprise({}, function(data) {
  10151. $scope.deputyEnterprises = data;
  10152. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  10153. // 费率
  10154. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  10155. $scope.rate = data;
  10156. }, function(response){
  10157. });
  10158. });
  10159. // 更新代采企业时更新费率
  10160. $scope.change = function(deputyuu) {
  10161. // 费率
  10162. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  10163. $scope.rate = data;
  10164. }, function(response){
  10165. });
  10166. }
  10167. // 查找付款企业
  10168. $scope.dbfindPayCompany = function(deputyuu) {
  10169. var modalInstance = $modal.open({
  10170. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  10171. controller: 'DbfindDeputyPayCompanyCtrl',
  10172. size: 'lg',
  10173. resolve: {
  10174. deputyuu: function() {return deputyuu}
  10175. }
  10176. });
  10177. modalInstance.result.then(function(data) {
  10178. $scope.deOrder.paymentcomenname = data.enname;
  10179. $scope.deOrder.paycomaddress = data.address;
  10180. })
  10181. }
  10182. //增加商品
  10183. $scope.add = function(index) {
  10184. if($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  10185. toaster.pop('info', '提示', '请先填写商品信息');
  10186. }else {
  10187. $scope.deOrder.deputyOrderItems.push(
  10188. { prodname: null,
  10189. prodcode: null,
  10190. prodspec: null,
  10191. amount: null,
  10192. unitprice: null,
  10193. remark: null,
  10194. orderprice: null});
  10195. }
  10196. };
  10197. //删除商品
  10198. $scope.del = function(index) {
  10199. $scope.deOrder.deputyOrderItems.splice(index, 1);
  10200. };
  10201. $scope.uplodaByBatch = function() {
  10202. var modalInstance = $modal.open({
  10203. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  10204. controller: 'DeputyOrderUploadCtrl',
  10205. size: 'lg',
  10206. resolve: {
  10207. }
  10208. });
  10209. modalInstance.result.then(function(data) {
  10210. angular.forEach(data, function(data) {
  10211. $scope.deOrder.deputyOrderItems.push(data);
  10212. for(var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  10213. if($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  10214. $scope.deOrder.deputyOrderItems.splice(i, 1);
  10215. }
  10216. }
  10217. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  10218. $scope.deOrder.totalamount += item.amount * item.unitprice;
  10219. $scope.deOrder.usdpayment += item.amount * item.unitprice;
  10220. $scope.deOrder.orderamount += item.amount * item.purcprice;
  10221. });
  10222. })
  10223. }, function(){
  10224. });
  10225. }
  10226. // 查找供应商
  10227. $scope.dbfindVendor = function(deputyuu) {
  10228. var modalInstance = $modal.open({
  10229. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  10230. controller: 'DbfindDeputyVendorInfoCtrl',
  10231. size: 'lg',
  10232. resolve: {
  10233. deputyuu: function() {return deputyuu}
  10234. }
  10235. });
  10236. modalInstance.result.then(function(data) {
  10237. $scope.deOrder.customer = data.vendorEnterprise.enName;
  10238. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  10239. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  10240. $scope.deOrder.usertel = data.vendorUser.userTel;
  10241. })
  10242. }
  10243. $scope.save = function() {
  10244. $scope.deOrder.entrystatus = '保存';
  10245. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  10246. $scope.deOrder.totalamount += item.amount * item.unitprice;
  10247. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  10248. });
  10249. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  10250. toaster.pop('info', '提示', '您还未填写任何商品信息');
  10251. } else {
  10252. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  10253. if(data.id) {
  10254. window.location.hash = "#/purc/deputy/"+data.id;
  10255. }
  10256. if(data.error) {
  10257. toaster.pop('error', '提示', '保存失败');
  10258. }
  10259. }, function(response) {
  10260. });
  10261. }
  10262. }
  10263. $scope.submit = function() {
  10264. $scope.deOrder.entrystatus = '已提交';
  10265. angular.forEach($scope.deOrder.deputyOrderItems, function(item) {
  10266. $scope.deOrder.totalamount += item.amount * item.unitprice;
  10267. $scope.deOrder.totalpayament += item.amount * item.unitprice;
  10268. });
  10269. if($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  10270. toaster.pop('info', '提示', '您还未填写任何商品信息');
  10271. } else {
  10272. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  10273. if(data.id) {
  10274. window.location.hash = "#/purc/deputy/"+data.id;
  10275. }
  10276. if(data.error) {
  10277. toaster.pop('error', '提示', '保存失败');
  10278. }
  10279. }, function(response) {
  10280. });
  10281. }
  10282. }
  10283. $scope.openDatePicker = function($event, deOrder, openParam) {
  10284. $event.preventDefault();
  10285. $event.stopPropagation();
  10286. deOrder[openParam] = !deOrder[openParam];
  10287. };
  10288. }]);
  10289. // 代采企业供应商
  10290. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  10291. $scope.prod = false;
  10292. BaseService.scrollBackToTop();
  10293. // 搜索框回车
  10294. $scope.onSearch = function(keyword) {
  10295. $scope.keyword = keyword;
  10296. $scope.customerParams.page(1);
  10297. $scope.customerParams.reload();
  10298. };
  10299. $scope.customerParams = new ngTableParams({
  10300. page : 1,
  10301. count : 10
  10302. }, {
  10303. total : 0,
  10304. counts: [5, 10, 25, 50],
  10305. getData : function($defer, params) {
  10306. $scope.loading = true;
  10307. var pageParams = params.url();
  10308. pageParams.keyword = $scope.keyword;
  10309. pageParams.enuu = deputyuu;
  10310. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function(page){
  10311. $scope.loading = false;
  10312. if(page) {
  10313. params.total(page.totalElements);
  10314. $defer.resolve(page.content);
  10315. }
  10316. $scope.totalCount = page.totalElements;
  10317. }, function(response){
  10318. $scope.loading = false;
  10319. toaster.pop('error', '数据加载失败', response.data);
  10320. });
  10321. }
  10322. });
  10323. $scope.cancel = function() {
  10324. $modalInstance.dismiss();
  10325. };
  10326. $scope.checkVendor = function(vendor) { // 直接选择
  10327. $modalInstance.close(vendor);
  10328. }
  10329. }]);
  10330. // 代采企业付款企业
  10331. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  10332. $scope.prod = false;
  10333. BaseService.scrollBackToTop();
  10334. DeputyOrder.paycompanys({enuu: deputyuu}, {}, function(data) {
  10335. $scope.paycompanys = data;
  10336. }, function(response) {
  10337. toaster.pop('error', '提示', response.data);
  10338. });
  10339. $scope.cancel = function() {
  10340. $modalInstance.dismiss();
  10341. };
  10342. $scope.checkVendor = function(company) { // 直接选择
  10343. $modalInstance.close(company);
  10344. }
  10345. }]);
  10346. /**
  10347. * 代采订单批量导入
  10348. */
  10349. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  10350. // 通过excel批量上传物料
  10351. $scope.result = null;
  10352. $scope.upload = function() {
  10353. var file = $scope.myFiles[0];
  10354. $upload.upload({
  10355. url: 'deputyOrder/release/excel',
  10356. file: file,
  10357. method: 'POST'
  10358. }).success(function(data) {
  10359. $scope.result = data;
  10360. $scope.success = $scope.result.success;
  10361. $scope.total = $scope.result.total;
  10362. $scope.alters = $scope.result.alters;
  10363. }).error(function(response) {
  10364. toaster.pop('error', response.data || response);
  10365. });
  10366. };
  10367. // 查看范例
  10368. $scope.showImg = function() {
  10369. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  10370. box.show();
  10371. box.find('img').attr('src', src);
  10372. box.find('a').click(function(){
  10373. box.hide();
  10374. });
  10375. box.dblclick(function(){
  10376. box.hide();
  10377. });
  10378. };
  10379. // 下载模板
  10380. $scope.download = function() {
  10381. window.location.href = 'deputyOrder/upload/template';
  10382. };
  10383. $scope.enSure = function() {
  10384. $modalInstance.close($scope.result.items);
  10385. }
  10386. $scope.cancel = function() {
  10387. $modalInstance.dismiss();
  10388. }
  10389. }]);
  10390. /**
  10391. * 代采详情
  10392. */
  10393. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', function($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService) {
  10394. BaseService.scrollBackToTop();
  10395. var loadData = function() {
  10396. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function(data) {
  10397. $scope.deOrder = data;
  10398. $scope.deOrder.$editing = false;
  10399. });
  10400. };
  10401. loadData();
  10402. // 代采企业列表
  10403. DeputyOrder.deputyEnterprise({}, function(data) {
  10404. $scope.deputyEnterprises = data;
  10405. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyEnterprise.uu;
  10406. // 费率
  10407. DeputyOrder.vendorRate( {enuu: $scope.deOrder.deputyuu}, {}, function(data) {
  10408. $scope.rate = data;
  10409. }, function(response){
  10410. });
  10411. });
  10412. // 更新代采企业时更新费率
  10413. $scope.change = function(deputyuu) {
  10414. // 费率
  10415. DeputyOrder.vendorRate( {enuu: deputyuu}, {}, function(data) {
  10416. $scope.rate = data;
  10417. }, function(response){
  10418. });
  10419. }
  10420. // 查找付款企业
  10421. $scope.dbfindPayCompany = function(deputyuu) {
  10422. var modalInstance = $modal.open({
  10423. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  10424. controller: 'DbfindDeputyPayCompanyCtrl',
  10425. size: 'lg',
  10426. resolve: {
  10427. deputyuu: function() {return deputyuu}
  10428. }
  10429. });
  10430. modalInstance.result.then(function(data) {
  10431. $scope.deOrder.paymentcomenname = data.enname;
  10432. $scope.deOrder.paycomaddress = data.address;
  10433. })
  10434. }
  10435. var getService = function() {
  10436. return DeputyOrder.getProdList;
  10437. };
  10438. $scope.update = function() {
  10439. $scope.deOrder.$editing = true;
  10440. }
  10441. $scope.cancel = function() {
  10442. $scope.deOrder.$editing = false;
  10443. }
  10444. $scope.submit = function() {
  10445. $scope.deOrder.entrystatus = '已提交';
  10446. DeputyOrder.saveDeOrder({deOrder: $scope.deOrder}, {}, function(data) {
  10447. if(data.id) {
  10448. window.location.hash = "#/purc/deputy/"+data.id;
  10449. }
  10450. if(data.error) {
  10451. toaster.pop('error', '提示', '保存失败');
  10452. }
  10453. }, function(response) {
  10454. });
  10455. }
  10456. $scope.openDatePicker = function($event, deOrder, openParam) {
  10457. $event.preventDefault();
  10458. $event.stopPropagation();
  10459. deOrder[openParam] = !deOrder[openParam];
  10460. };
  10461. }]);
  10462. /**
  10463. * 招标单
  10464. */
  10465. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  10466. BaseService.scrollBackToTop();
  10467. $scope.active = 'done';
  10468. if ($rootScope.tenderActive) {
  10469. $scope.active = $rootScope.tenderActive;
  10470. }
  10471. $scope.dateZoneText = '不限';
  10472. $scope.deliveryZoneText = '不限';
  10473. $scope.condition = {dateZone: -1, deliveryZone: -1};
  10474. $scope.changeDateZone = function(zone) {
  10475. $scope.condition.dateZone = zone;
  10476. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  10477. $scope.condition.$dateZoneOpen = false;
  10478. getDateCondition(zone, $scope.condition);
  10479. $scope.tableParams.reload();
  10480. };
  10481. $scope.changeDeliveryZone = function(zone) {
  10482. $scope.condition.deliveryZoneText = zone;
  10483. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  10484. $scope.condition.$delievryZoneOpen = false;
  10485. getDelveryCondition(zone, $scope.condition);
  10486. $scope.tableParams.reload();
  10487. };
  10488. $scope.setActive = function(state) {
  10489. if($scope.active != state) {
  10490. $scope.active = state;
  10491. if($scope.tableParams.page() == 1)
  10492. $scope.tableParams.reload();
  10493. else
  10494. $scope.tableParams.page(1);
  10495. }
  10496. };
  10497. var getTenderStatus = function(active) {
  10498. var fn = 'getMyAll';
  10499. switch(active) {
  10500. case 'done':
  10501. fn = 'getMyDone';break;
  10502. case 'todo':
  10503. fn = 'getMyTodo';break;
  10504. // case 'end':
  10505. // fn = 'getMyEnd';break;
  10506. case 'waiting':
  10507. fn = 'getMyWaiting';break;
  10508. }
  10509. return fn;
  10510. }
  10511. $scope.tableParams = new ngTableParams({
  10512. page : 1,
  10513. count : 5,
  10514. sorting: {
  10515. 'tender.endDate': 'desc',
  10516. 'tender.enterprise.enName': 'asc',
  10517. 'tender.code': 'asc'
  10518. }
  10519. }, {
  10520. total : 0,
  10521. counts: [5, 10, 25, 50],
  10522. getData : function($defer, params) {
  10523. $scope.loading = true;
  10524. var pageParams = params.url();
  10525. var realActive = {};
  10526. pageParams.searchFilter = { // 筛选条件
  10527. keyword: $scope.keyword,
  10528. fromDate: getDateTime($scope.condition.dateFrom),
  10529. endDate: getDateTime($scope.condition.dateTo)
  10530. };
  10531. PurcTender[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  10532. $scope.loading = false;
  10533. if(page) {
  10534. params.total(page.totalElement);
  10535. $defer.resolve(page.content);
  10536. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  10537. }
  10538. }, function(response){
  10539. $scope.loading = false;
  10540. toaster.pop('error', '数据加载失败', response.data);
  10541. });
  10542. }
  10543. });
  10544. $scope.openDatePicker = function($event, item, openParam) {
  10545. $event.preventDefault();
  10546. $event.stopPropagation();
  10547. item[openParam] = !item[openParam];
  10548. };
  10549. $scope.parseDate = function(dateStr) {
  10550. if(dateStr)
  10551. return Date.parse(dateStr, 'yyyy-MM-dd');
  10552. return new Date();
  10553. };
  10554. // 选择查找日期
  10555. $scope.onDateCondition = function(){
  10556. $scope.tableParams.page(1);
  10557. $scope.tableParams.reload();
  10558. };
  10559. // 搜索框回车
  10560. $scope.onSearch = function() {
  10561. $scope.tableParams.page(1);
  10562. $scope.tableParams.reload();
  10563. };
  10564. }]);
  10565. /**
  10566. * 新增招标单
  10567. */
  10568. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'ShipAddress', '$http', 'AuthenticationService', 'KindAPI', 'BrandActiveAPI', 'Search', 'ComponentActiveAPI',function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, ShipAddress, $http, AuthenticationService, KindAPI, BrandActiveAPI, Search, ComponentActiveAPI) {
  10569. // 录入人
  10570. AuthenticationService.getAuthentication().success(function(data) {
  10571. $scope.user = data;
  10572. });
  10573. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  10574. $scope.loading = false;
  10575. // 获取收货地址列表
  10576. var loadShipAddress = function() {
  10577. ShipAddress.shipAddList({}, function(data) {
  10578. $scope.ships = data;
  10579. $scope.tender.shipadd = $scope.ships[0];
  10580. });
  10581. };
  10582. loadShipAddress();
  10583. // 获取地址信息
  10584. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  10585. }).then(function(response) {
  10586. $scope.provinces = response.data;
  10587. });
  10588. // 新增收货地址保存
  10589. $scope.saveShipAddress = function(ship) {
  10590. ship.address = ship.province + ship.city + ship.district;
  10591. ShipAddress.saveAddress( {}, ship, function(data) {
  10592. if(data.success) {
  10593. // 获取收货地址列表
  10594. loadShipAddress();
  10595. toaster.pop('success', '提示', data.success);
  10596. }
  10597. if(data.error) {
  10598. toaster.pop('error', '提示', data.error);
  10599. }
  10600. });
  10601. };
  10602. // 可选的证照要求
  10603. $scope.certificates = [{name:'三/五证合一'}, {name:'营业执照'}, {name:'组织机构代码证'}, {name:'一般纳税人证明材料'},{name:'统计登记证'},{name:'社会保险登记证'}];
  10604. // 处理证照要求
  10605. var parseCertificate = function(a) {
  10606. if (a) {
  10607. var arr = a.split(',');
  10608. angular.forEach(arr, function(app) {
  10609. var contained = false;
  10610. angular.forEach($scope.certificates, function($app) {
  10611. if($app.name == app) {
  10612. $app.checked = true;
  10613. contained = true;
  10614. }
  10615. });
  10616. if(!contained) {
  10617. $scope.certificates.push({name: app, checked: true});
  10618. }
  10619. });
  10620. }
  10621. };
  10622. // 联想词start
  10623. // 获取品牌联想词
  10624. $scope.getSimilarBrands = function(value) {
  10625. if (value) {
  10626. // 获取品牌联想词
  10627. return Search.getSimilarBrands({keyword : value}).$promise.then(function(data) {
  10628. return data.map(function(item) {
  10629. return item;
  10630. });
  10631. });
  10632. }
  10633. };
  10634. // 获取产品型号联想词
  10635. $scope.getSimilarCodes = function(value) {
  10636. if (value) {
  10637. // 获取产品型号联想词
  10638. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  10639. return data.map(function (item) {
  10640. return item;
  10641. })
  10642. });
  10643. }
  10644. };
  10645. // // 获取产品类目联想词
  10646. // $scope.getSimilarKinds = function(value) {
  10647. // if (value) {
  10648. // // getSimilarLeafKinds 根据类目名获取末级联想词
  10649. // // 获取类目联想词
  10650. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  10651. // return data.map(function(item) {
  10652. // return item;
  10653. // })
  10654. // });
  10655. // }
  10656. // };
  10657. // // 点击联想词获取类目信息
  10658. // $scope.onAssociateKindClick = function(kind, submit) {
  10659. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  10660. // $scope.actives = data;
  10661. // console.log(data);
  10662. // var size = data.length;
  10663. // if (size > 0) {
  10664. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  10665. // submit.kiName = submit.gradeOneKiName;
  10666. // if (size > 1) {
  10667. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  10668. // submit.kiName = submit.gradeTwoKiName;
  10669. // if (kind.level < 3) {
  10670. // submit.gradeThreeKiName = null;
  10671. // } else if (size > 2) {
  10672. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  10673. // submit.kiName = submit.gradeThreeKiName;
  10674. // }
  10675. // }
  10676. // }
  10677. // console.log(submit);
  10678. // })
  10679. // };
  10680. // 选择类目
  10681. $scope.selectKind = function(prod) {
  10682. var submit = [];
  10683. $modal.open({
  10684. animation: true,
  10685. size: 'lg',
  10686. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  10687. controller: 'ProdKindChooseCtrl',
  10688. resolve: {
  10689. actives: function() {
  10690. return $scope.actives;
  10691. }
  10692. }
  10693. }).result.then(function(data){
  10694. $scope.actives = data.actives;
  10695. var size = data.actives.length;
  10696. submit.gradeOneKiName = '';
  10697. submit.gradeTwoKiName = '';
  10698. submit.gradeThreeKiName = '';
  10699. if (size > 0) {
  10700. submit.gradeOneKiName = $scope.actives[0].nameCn;
  10701. prod.prodTitle = submit.gradeOneKiName;
  10702. if (size > 1) {
  10703. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  10704. prod.prodTitle = submit.gradeTwoKiName;
  10705. if (size > 2) {
  10706. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  10707. prod.prodTitle = submit.gradeThreeKiName;
  10708. }
  10709. }
  10710. }
  10711. }, function(){
  10712. });
  10713. };
  10714. // // 验证分类信息
  10715. // $scope.checkKind = function() {
  10716. // setTimeout(function() {
  10717. // if($scope.activesString == null) {
  10718. // $scope.component.kindid = null;
  10719. // return;
  10720. // }
  10721. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  10722. // $scope.component.kind = kind;
  10723. // $scope.component.kindid = kind.id;
  10724. // $scope.activesString = $scope.component.kind.nameCn;
  10725. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  10726. // $scope.kindProperties = data;
  10727. // angular.forEach($scope.kindProperties, function(kp) {
  10728. // angular.forEach($scope.component.properties, function(pro) {
  10729. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  10730. // kp.value = pro.value;
  10731. // }
  10732. // });
  10733. // });
  10734. // }, function(response) {
  10735. // });
  10736. // }, function (response) {
  10737. // $scope.component.kindid = null;
  10738. // toaster.pop('error', response.data);
  10739. // });
  10740. // }, 500);
  10741. // };
  10742. // 点击联想词获取品牌信息
  10743. $scope.onAssociateBrandClick = function(brand, prod) {
  10744. // $scope.component.brand = brand;
  10745. // $scope.component.brandid = brand.id;
  10746. prod.brand = brand;
  10747. };
  10748. // 打开品牌选择的模态框
  10749. $scope.selectBrand = function(prod){ //打开模态
  10750. var modalInstance = $modal.open({
  10751. templateUrl : 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  10752. controller : 'BrandModalInstanceCtrl' // 初始化模态范围
  10753. });
  10754. modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
  10755. });
  10756. modalInstance.result.then(function(brand){
  10757. console.log(brand);
  10758. prod.brand = brand.nameCn;
  10759. }, function(reason){
  10760. });
  10761. };
  10762. // // 验证品牌是否正确
  10763. // $scope.checkBrand = function () {
  10764. // setTimeout(function () {
  10765. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  10766. // // $scope.component.brand = brand;
  10767. // // $scope.component.brandid = brand.id;
  10768. // }, function (response) {
  10769. // // $scope.component.brandid = null;
  10770. // toaster.pop('error', response.data);
  10771. // })
  10772. // } , 500);
  10773. // };
  10774. // 点击联想词获取器件信息 带入产品分类和品牌
  10775. $scope.onAssociateCmpClick = function(cmp, prod) {
  10776. ComponentActiveAPI.get({uuid : cmp.uuid}, {}, function(data) {
  10777. $scope.component = data;
  10778. prod.prodCode = data.code;
  10779. prod.prodTitle = data.kind.nameCn;
  10780. prod.brand = data.brand.nameCn;
  10781. }, function(res) {
  10782. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  10783. })
  10784. };
  10785. //联想词end
  10786. $scope.condition = {dateZone: 1};
  10787. $scope.tenderProd = [];
  10788. var prod = {
  10789. prodTitle: null,
  10790. prodCode: null,
  10791. brand: null,
  10792. unit: 'PCS',
  10793. qty: null
  10794. // 供应商企业信息
  10795. // enterpriseBaseInfo: [{}]
  10796. };
  10797. $scope.tender = {
  10798. date: new Date(),
  10799. unit: 'PCS',
  10800. currency: 'RMB',
  10801. ifOpen: 0,
  10802. ifTax: 1,
  10803. invoiceType: 2,
  10804. tenderAttachs:[{}]
  10805. };
  10806. //
  10807. $scope.tenderProd.push(prod);
  10808. //增加商品
  10809. $scope.add = function(index) {
  10810. $scope.tenderProd.push({
  10811. prodTitle: null,
  10812. prodCode: null,
  10813. brand: null,
  10814. unit: 'PCS',
  10815. qty: null
  10816. // 供应商企业信息
  10817. // enterpriseBaseInfo: [{}]
  10818. });
  10819. };
  10820. //删除商品
  10821. $scope.del = function(index) {
  10822. $scope.tenderProd.splice(index, 1);
  10823. };
  10824. // 批量导入
  10825. $scope.uplodaByBatch = function() {
  10826. var modalInstance = $modal.open({
  10827. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  10828. controller: 'PurcTenderUploadCtrl',
  10829. size: 'lg',
  10830. resolve: {
  10831. }
  10832. });
  10833. modalInstance.result.then(function(data) {
  10834. // 获取上传的产品明细,前台展示
  10835. angular.forEach(data, function(data) {
  10836. $scope.tenderProd.push(data);
  10837. for(var i = 0; i < $scope.tenderProd.length; i++) {
  10838. if($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  10839. $scope.tenderProd.splice(i, 1);
  10840. console.log($scope.tenderProd);
  10841. }
  10842. }
  10843. });
  10844. }, function(){
  10845. });
  10846. };
  10847. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  10848. if( ! angular.isUndefined($stateParams.id)) {
  10849. $scope.loading = true;
  10850. PurcTender.getOne({id: $stateParams.id}, function(data){
  10851. data.$editing = false;
  10852. $scope.tender = data;
  10853. $scope.tenderProd = data.purchaseTenderProds;
  10854. parseCertificate($scope.tender.certificate);
  10855. $scope.firstProd = data.purchaseTenderProds[0];
  10856. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  10857. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  10858. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10859. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  10860. } else {
  10861. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  10862. }
  10863. });
  10864. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  10865. console.log($scope.tenderProd.enterpriseBaseInfo);
  10866. $scope.loading = false;
  10867. $scope.attaches = $scope.tender.tenderAttaches;
  10868. }, function(response){
  10869. $scope.loading = false;
  10870. toaster.pop('error', '数据加载失败', response.data);
  10871. });
  10872. }
  10873. if(angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  10874. $rootScope.tenderVendor = [{}];
  10875. }
  10876. $scope.changeShipAddress = false;
  10877. $scope.changeAddress = function() {
  10878. if ($scope.changeShipAddress) {
  10879. $scope.changeShipAddress = false;
  10880. } else {
  10881. $scope.changeShipAddress = true;
  10882. }
  10883. };
  10884. // $scope.validateNumber = function (value) { // 采购数量 正整数
  10885. // var regex = /^\+?[1-9][0-9]*$/;
  10886. // if (!regex.test(value) || value === 0 || value === null) {
  10887. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  10888. // }
  10889. // };
  10890. // 查找供应商
  10891. $scope.dbfindVendor = function(){
  10892. var modalInstance = $modal.open({
  10893. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  10894. controller: 'DbfindVendorCtrl',
  10895. size: 'lg',
  10896. resolve: {
  10897. }
  10898. });
  10899. var ifPush = true;
  10900. modalInstance.result.then(function(data){
  10901. angular.forEach(data, function(vendor) {
  10902. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  10903. $scope.tenderProd.enterpriseBaseInfo = [{}];
  10904. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  10905. } else {
  10906. for (var i = 0;i<$scope.tenderProd.enterpriseBaseInfo.length; i++) {
  10907. ifPush = true;
  10908. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  10909. ifPush = false;
  10910. break; // 判定到已存在供应商,就终止循环。
  10911. }
  10912. }
  10913. if (ifPush) {
  10914. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  10915. }
  10916. }
  10917. });
  10918. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  10919. }, function(){
  10920. });
  10921. };
  10922. // 删除一个供应商
  10923. $scope.removeVendor = function(index) {
  10924. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  10925. };
  10926. // 删除供应商时,后台删除投标单
  10927. $scope.removeSaleTender = function (id, vendUU) {
  10928. var hasSaved = false;
  10929. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function(saleTenderItem) {
  10930. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  10931. hasSaved = true;
  10932. }
  10933. });
  10934. if (hasSaved) {
  10935. PurcTender.removeSaleTender ({id : id, vendUU : vendUU}, {}, function(data) {
  10936. }, function(response) {
  10937. toaster.pop('error', '提示', response.data);
  10938. });
  10939. }
  10940. };
  10941. // 删除产品明细时,后台删除产品明细
  10942. $scope.deleteProd = function (tenderProd) {
  10943. if (tenderProd.id) {
  10944. PurcTender.deleteProd ({tenderProdId : tenderProd.id}, {}, function(data) {
  10945. }, function(response) {
  10946. toaster.pop('error', '提示', response.data);
  10947. });
  10948. }
  10949. };
  10950. // // 查找客户物料
  10951. // $scope.dbfindCustProd = function(){
  10952. // if($scope.item.$editing) {
  10953. // if($scope.item.quotation.cust.uu) {
  10954. // var modalInstance = $modal.open({
  10955. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  10956. // controller: 'DbfindCustProdCtrl',
  10957. // size: 'lg',
  10958. // resolve: {
  10959. // custUU: function(){return $scope.item.quotation.cust.uu}
  10960. // }
  10961. // });
  10962. //
  10963. // modalInstance.result.then(function(data){
  10964. // $scope.item.product = data;
  10965. // }, function(){
  10966. //
  10967. // });
  10968. // } else {
  10969. // toaster.pop('error', '错误', '请先选择客户');
  10970. // }
  10971. // }
  10972. // };
  10973. if (!$scope.attaches) {
  10974. $scope.attaches = []; // 存放上传了的附件
  10975. }
  10976. $scope.upload = function(myFile) { // 上传附件
  10977. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  10978. $upload.upload({
  10979. url: 'tender/addTenderAttach',
  10980. file: file,
  10981. method: 'POST'
  10982. // data: {
  10983. // tender: $scope.tender
  10984. // }
  10985. }).success(function (attach) {
  10986. $scope.attaches.push(attach);
  10987. });
  10988. };
  10989. $scope.removeAttach = function(id, index) {
  10990. $scope.attaches.splice(index, 1);
  10991. // PurcTender.removeAttach({attachId:id}, function() {
  10992. //
  10993. // });
  10994. };
  10995. var sleep = function (d){
  10996. for(var t = Date.now();Date.now() - t <= d;);
  10997. };
  10998. // 保存和发布招标单
  10999. $scope.save = function(isPublish){
  11000. if (!$scope.tender.ifOpen && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  11001. toaster.pop('info','提示','请先指定供应商');
  11002. } else {
  11003. $scope.loading = true;
  11004. // --组装证照要求
  11005. var myCertificate = [];
  11006. angular.forEach($scope.certificates, function(certificate) {
  11007. if (certificate.checked) {
  11008. myCertificate.push(certificate.name);
  11009. }
  11010. });
  11011. $scope.tender.certificate = myCertificate.join(',');
  11012. if(!$scope.tender.code) { //新增,设单号
  11013. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  11014. }
  11015. if($scope.tender.date instanceof Date) {
  11016. $scope.tender.date = $scope.tender.date.getTime();
  11017. }
  11018. if($scope.tender.endDate instanceof Date) {
  11019. $scope.tender.endDate = $scope.tender.endDate.getTime();
  11020. }
  11021. if($scope.tender.publishDate instanceof Date) {
  11022. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  11023. }
  11024. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  11025. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  11026. $scope.tender.purchaseTenderProds[i].index = i + 1;
  11027. }
  11028. $scope.tender.tenderAttaches = $scope.attaches;
  11029. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  11030. console.log($scope.tender.shipAddress);
  11031. var vendorUUs = [];
  11032. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){
  11033. vendorUUs.push(enterpriseBaseInfo.uu);
  11034. });
  11035. if (isPublish) { // 发布
  11036. toaster.pop('info', '提示', '正在发布,请稍候');
  11037. PurcTender.publish({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data){
  11038. sleep(1500); //当前方法暂停1.5秒
  11039. $scope.loading = false;
  11040. toaster.pop('success', '成功', '发布成功');
  11041. window.location.hash = '#/purc/tender';
  11042. }, function(response){
  11043. $scope.loading = false;
  11044. toaster.pop('error', '发布失败', response.data);
  11045. });
  11046. } else { // 保存
  11047. toaster.pop('info', '提示', '正在保存,请稍候');
  11048. PurcTender.save({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data) {
  11049. $scope.loading = false;
  11050. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  11051. toaster.pop('success', '成功', '保存成功');
  11052. window.location.hash = '#/purc/tender';
  11053. }, function(response){
  11054. $scope.loading = false;
  11055. toaster.pop('error', '保存失败', response.data);
  11056. });
  11057. }
  11058. }
  11059. };
  11060. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  11061. $scope.removeChecked = function() {
  11062. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  11063. $scope.tenderProd.enterpriseBaseInfo = [];
  11064. }
  11065. };
  11066. // 删除(在录入状态)
  11067. $scope.deleteThis = function(id) {
  11068. PurcTender.deleteOne({id:id}, {}, function(data) {
  11069. toaster.pop('info', '提示', '删除成功');
  11070. window.location.hash = '#/purc/tender';
  11071. });
  11072. };
  11073. // 更新和发布(在录入状态)
  11074. $scope.updateSaved = function(isPublish){
  11075. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  11076. toaster.pop('info','提示','请先指定供应商');
  11077. } else {
  11078. $scope.loading = true;
  11079. // --组装证照要求
  11080. var myCertificate = [];
  11081. angular.forEach($scope.certificates, function(certificate) {
  11082. if (certificate.checked) {
  11083. myCertificate.push(certificate.name);
  11084. }
  11085. });
  11086. $scope.tender.certificate = myCertificate.join(',');
  11087. if($scope.tender.endDate instanceof Date) {
  11088. $scope.tender.endDate = $scope.tender.endDate.getTime();
  11089. }
  11090. if($scope.tender.publishDate instanceof Date) {
  11091. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  11092. }
  11093. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  11094. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  11095. $scope.tender.purchaseTenderProds[i].index = i + 1;
  11096. }
  11097. $scope.tender.tenderAttaches = $scope.attaches;
  11098. if ($scope.tender.shipadd) {
  11099. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  11100. }
  11101. angular.forEach($scope.tender.purchaseTenderProds, function(tenderProd){
  11102. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  11103. });
  11104. var vendorUUs = [];
  11105. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function(enterpriseBaseInfo){ // 供应商uu号参数
  11106. vendorUUs.push(enterpriseBaseInfo.uu);
  11107. });
  11108. console.log($scope);
  11109. if (isPublish) { // 发布
  11110. toaster.pop('info', '提示', '正在发布,请稍候');
  11111. PurcTender.publishSaved({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data){
  11112. sleep(1500); //当前方法暂停1.5秒
  11113. $scope.loading = false;
  11114. toaster.pop('success', '成功', '发布成功');
  11115. window.location.hash = '#/purc/tender';
  11116. }, function(response){
  11117. $scope.loading = false;
  11118. toaster.pop('error', '发布失败', response.data);
  11119. });
  11120. } else { // 保存
  11121. toaster.pop('info', '提示', '正在保存,请稍候');
  11122. PurcTender.updateSaved({tender: $scope.tender, vendorUUs: vendorUUs}, {}, function(data) {
  11123. $scope.loading = false;
  11124. sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  11125. toaster.pop('success', '成功', '保存成功');
  11126. window.location.reload();
  11127. }, function(response){
  11128. $scope.loading = false;
  11129. toaster.pop('error', '保存失败', response.data);
  11130. });
  11131. }
  11132. }
  11133. };
  11134. $scope.currentDay = function() {
  11135. return $filter('date')(new Date(), 'yyyy-MM-dd');
  11136. };
  11137. $scope.getMinDate = function() {
  11138. // var now = new Date();
  11139. // now = now.setDate(now.getDate()+1);
  11140. // var minDate = angular.copy($scope.tender.endDate);
  11141. // minDate = minDate.setDate(minDate.getDate() + 1);
  11142. if ($scope.tender.endDate instanceof Date) {
  11143. var minDate = new Date($scope.tender.endDate.getTime() + 24*60*60*1000 + 1); // 不能选相同一天
  11144. }
  11145. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd'):$filter('date')(new Date(), 'yyyy-MM-dd');
  11146. };
  11147. $scope.getMaxDate = function() {
  11148. // var maxDate = angular.copy($scope.tender.publishDate);
  11149. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  11150. if ($scope.tender.publishDate instanceof Date) {
  11151. var maxDate = new Date($scope.tender.publishDate.getTime() - 1); // 不能选同一天
  11152. }
  11153. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd'):"";
  11154. };
  11155. $scope.openDatePicker = function($event, item, openParam) {
  11156. $event.preventDefault();
  11157. $event.stopPropagation();
  11158. item[openParam] = !item[openParam];
  11159. };
  11160. }]);
  11161. //类目选择模态框(招标产品明细)
  11162. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  11163. $scope.actives = actives;
  11164. $scope.kinds = [[], [], [], []];
  11165. // 获取子类目
  11166. var getChildren = function(pid, deep) {
  11167. KindAPI.getChildren({parentId: pid}, function(data) {
  11168. $scope.kinds[deep] = data;
  11169. }, function(response) {
  11170. toaster.pop('error', '获取子类目失败', response.data);
  11171. });
  11172. };
  11173. // 改变节点选中状态
  11174. var changeStatus = function(item, deep) {
  11175. var actives = [], level = 0;
  11176. angular.forEach($scope.kinds, function(ks, i) {
  11177. if(i > deep) {
  11178. $scope.kinds[i] = [];
  11179. } else {
  11180. angular.forEach(ks, function(k, j) {
  11181. if(i == deep) {
  11182. if(k.id == item.id) {
  11183. $scope.kinds[i][j].$active = true;
  11184. actives.push(k);
  11185. } else {
  11186. k.$active = null;
  11187. }
  11188. } else {
  11189. if(k.$active) {
  11190. actives.push(k);
  11191. }
  11192. }
  11193. });
  11194. }
  11195. });
  11196. // 选择的节点
  11197. $scope.actives = actives;
  11198. $scope.active = item;
  11199. // 当前可操作的层级
  11200. if(deep < 3) {
  11201. $scope.activeDeep = deep + 1;
  11202. }
  11203. };
  11204. // 节点点击后获取子类目,节点被选中
  11205. $scope.onItemClick = function(item, deep) {
  11206. changeStatus(item, deep);
  11207. if (!item.isLeaf) {
  11208. getChildren(item.id, deep + 1);
  11209. }
  11210. };
  11211. // 重新加载数据
  11212. function reload(deep) {
  11213. var pid;
  11214. if(deep) {
  11215. pid = $scope.actives[deep - 1].id;
  11216. } else {
  11217. pid = 0;
  11218. deep = 0;
  11219. }
  11220. getChildren(pid, deep);
  11221. }
  11222. // 初始加载数据,获取第一层的类目
  11223. if($scope.actives) {
  11224. angular.forEach($scope.actives, function(v, k) {
  11225. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  11226. $scope.kinds[k] = data;
  11227. angular.forEach($scope.kinds[k], function(kind, i){
  11228. if(kind.id == v.id) {
  11229. $scope.kinds[k][i].$active = true;
  11230. $scope.actives[k] = $scope.kinds[k][i];
  11231. }
  11232. })
  11233. }, function(response) {
  11234. toaster.pop('error', '获取子类目失败', response.data);
  11235. });
  11236. });
  11237. } else {
  11238. reload();
  11239. }
  11240. // 取消
  11241. $scope.cancel = function() {
  11242. $modalInstance.dismiss();
  11243. };
  11244. // 确认选择
  11245. $scope.check = function() {
  11246. var a = {
  11247. active: $scope.active,
  11248. actives: $scope.actives
  11249. };
  11250. $modalInstance.close(a);
  11251. };
  11252. }]);
  11253. //品牌选择模态框的controller
  11254. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  11255. $scope.filter = {};
  11256. $scope.brandsTableParams = new ngTableParams({
  11257. page : 1,
  11258. count : 6,
  11259. sorting : {
  11260. nameCn: 'asc'
  11261. }
  11262. }, {
  11263. total : 0,
  11264. counts : [],
  11265. getData : function($defer, params) {
  11266. var param = BaseService.parseParams(params.url());
  11267. param.keyword = $scope.filter.keyword;
  11268. var keyword = $scope.filter.keyword;
  11269. // param.keyword = $scope.filter.keyword;
  11270. BrandActiveAPI.getSimpleInfoPage(param, {}, function(page) {
  11271. if (page) {
  11272. params.total(page.totalElements);
  11273. $defer.resolve(page.content);
  11274. }
  11275. }, function(){
  11276. });
  11277. }
  11278. });
  11279. // 搜索
  11280. $scope.search = function() {
  11281. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  11282. $scope.brandsTableParams.page(1);
  11283. $scope.brandsTableParams.reload();
  11284. };
  11285. // 选择
  11286. $scope.select = function(brand){
  11287. $modalInstance.close(brand);
  11288. };
  11289. // 关闭
  11290. $scope.cancel = function() {
  11291. $modalInstance.dismiss();
  11292. };
  11293. }]);
  11294. /**
  11295. * 招标单批量导入
  11296. */
  11297. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function($scope, toaster, $upload, $modalInstance) {
  11298. // 通过excel批量上传物料
  11299. $scope.result = null;
  11300. $scope.upload = function() {
  11301. var file = $scope.myFiles[0];
  11302. $upload.upload({
  11303. url: 'tender/release/excel',
  11304. file: file,
  11305. method: 'POST'
  11306. }).success(function(data) {
  11307. console.log(data);
  11308. $scope.result = data;
  11309. $scope.success = $scope.result.success;
  11310. $scope.total = $scope.result.total;
  11311. $scope.alters = $scope.result.alters;
  11312. }).error(function(response) {
  11313. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  11314. });
  11315. };
  11316. // 查看范例
  11317. $scope.showImg = function() {
  11318. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  11319. box.show();
  11320. box.find('img').attr('src', src);
  11321. box.find('a').click(function(){
  11322. box.hide();
  11323. });
  11324. box.dblclick(function(){
  11325. box.hide();
  11326. });
  11327. };
  11328. // 下载模板
  11329. $scope.download = function() {
  11330. window.location.href = 'tender/upload/template';
  11331. };
  11332. $scope.enSure = function() {
  11333. $modalInstance.close($scope.result.items);
  11334. }
  11335. $scope.cancel = function() {
  11336. $modalInstance.dismiss();
  11337. }
  11338. }]);
  11339. /**
  11340. * 评标
  11341. */
  11342. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  11343. BaseService.scrollBackToTop();
  11344. $scope.tenderItems = [];
  11345. // 采购方获取评标单
  11346. var evaluation = function() {
  11347. $scope.loading = true;
  11348. PurcTender.getOne({id: $stateParams.id}, function(data){
  11349. data.$editing = false;
  11350. $scope.tender = data;
  11351. console.log(typeof data.purchaseTenderProds[0].saleTenderItems[0].cycle);
  11352. $scope.tableParams = new ngTableParams({}, { dataset: data});
  11353. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  11354. $scope.loading = false;
  11355. }, function(response){
  11356. $scope.loading = false;
  11357. toaster.pop('error', '数据加载失败', response.data);
  11358. });
  11359. };
  11360. evaluation();
  11361. $scope.orderType = 'price';
  11362. // $scope.dir = '-';
  11363. // 改变排序顺序
  11364. $scope.changeOrder = function(type){
  11365. $scope.orderType = type;
  11366. // if(!$scope.dir || $scope.dir === '') {
  11367. // $scope.dir = '-';
  11368. // }else {
  11369. // $scope.dir = '';
  11370. // }
  11371. };
  11372. $scope.submit = function(tender) {
  11373. var canSubmit = true;
  11374. var hasPrice = false;
  11375. var hasDecide = false;
  11376. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11377. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11378. if (saleTenderItem.price) { // 只要存在报价的行,就需要对其中一个定标
  11379. hasPrice = true;
  11380. }
  11381. });
  11382. if (hasPrice) {
  11383. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11384. if (saleTenderItem.applyStatus) { // 只要有一行定标,就可以投标
  11385. hasDecide = true;
  11386. }
  11387. });
  11388. }
  11389. if (!hasDecide) {
  11390. canSubmit = false;
  11391. }
  11392. });
  11393. if (!canSubmit) {
  11394. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  11395. } else {
  11396. PurcTender.decide(tender, function(){
  11397. toaster.pop('success', '确认成功');
  11398. window.location.hash = '#/purc/tender';
  11399. }, function(response){
  11400. toaster.pop('error', '确认失败', response.data);
  11401. });
  11402. }
  11403. }
  11404. }]);
  11405. /**
  11406. * 客户招标
  11407. *
  11408. */
  11409. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  11410. BaseService.scrollBackToTop();
  11411. $scope.active = 'todo';
  11412. /**
  11413. * 改变类型
  11414. */
  11415. var getTypeCondition = function(zone, condition) {
  11416. if(zone == -1) {
  11417. condition.ifOpen = null;
  11418. } else if(zone == 1) {
  11419. condition.ifOpen = 1;
  11420. } else {
  11421. condition.ifOpen = 0;
  11422. }
  11423. };
  11424. $scope.dateZoneText = '不限';
  11425. $scope.typeText = '全部';
  11426. $scope.deliveryZoneText = '不限';
  11427. $scope.condition = {dateZone: -1, deliveryZone: -1, type: -1};
  11428. $scope.changeDateZone = function(zone) {
  11429. $scope.condition.dateZone = zone;
  11430. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  11431. $scope.condition.$dateZoneOpen = false;
  11432. getDateCondition(zone, $scope.condition);
  11433. $scope.tableParams.reload();
  11434. };
  11435. $scope.changeDeliveryZone = function(zone) {
  11436. $scope.condition.deliveryZoneText = zone;
  11437. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  11438. $scope.condition.$delievryZoneOpen = false;
  11439. getDelveryCondition(zone, $scope.condition);
  11440. $scope.tableParams.reload();
  11441. };
  11442. $scope.changeType = function(type) {
  11443. $scope.condition.type = type;
  11444. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  11445. getTypeCondition(type, $scope.condition);
  11446. $scope.tableParams.reload();
  11447. };
  11448. $scope.setActive = function(state) {
  11449. if($scope.active != state) {
  11450. $scope.active = state;
  11451. if($scope.tableParams.page() == 1)
  11452. $scope.tableParams.reload();
  11453. else
  11454. $scope.tableParams.page(1);
  11455. }
  11456. };
  11457. $scope.tableParams = new ngTableParams({
  11458. page : 1,
  11459. count : 5,
  11460. sorting: {
  11461. 'tender.endDate': 'desc',
  11462. 'tender.enterprise.enName': 'asc',
  11463. 'tender.code': 'asc'
  11464. }
  11465. }, {
  11466. total : 0,
  11467. counts: [5, 10, 25, 50],
  11468. getData : function($defer, params) {
  11469. $scope.loading = true;
  11470. var pageParams = params.url();
  11471. var realActive = {};
  11472. pageParams.searchFilter = { // 筛选条件
  11473. keyword: $scope.keyword,
  11474. pt_ifopen: $scope.condition.ifOpen,
  11475. fromDate: getDateTime($scope.condition.dateFrom),
  11476. endDate: getDateTime($scope.condition.dateTo)
  11477. };
  11478. AccountEnterprise.get({}, function(data){
  11479. $scope.loading = false;
  11480. $scope.currentEn = data;
  11481. });
  11482. PurcTender[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11483. $scope.loading = false;
  11484. if(page) {
  11485. params.total(page.totalElement);
  11486. $defer.resolve(page.content);
  11487. console.log(page.content);
  11488. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  11489. angular.forEach(page.content, function(purcTender) {
  11490. purcTender.vendorHasBid = false;
  11491. angular.forEach(purcTender.purchaseTenderProds, function(tenderProd) {
  11492. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11493. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  11494. tenderProd.currentItem = saleTenderItem;
  11495. if (saleTenderItem.price) { //TODO 如果存在当前企业的投标明细已投标,即判断为已投标
  11496. purcTender.vendorHasBid = true;
  11497. }
  11498. }
  11499. });
  11500. });
  11501. });
  11502. }
  11503. }, function(response){
  11504. $scope.loading = false;
  11505. toaster.pop('error', '数据加载失败', response.data);
  11506. });
  11507. }
  11508. });
  11509. $scope.openDatePicker = function($event, item, openParam) {
  11510. $event.preventDefault();
  11511. $event.stopPropagation();
  11512. item[openParam] = !item[openParam];
  11513. };
  11514. $scope.parseDate = function(dateStr) {
  11515. if(dateStr)
  11516. return Date.parse(dateStr, 'yyyy-MM-dd');
  11517. return new Date();
  11518. };
  11519. // 选择查找日期
  11520. $scope.onDateCondition = function(){
  11521. $scope.tableParams.page(1);
  11522. $scope.tableParams.reload();
  11523. };
  11524. // 搜索框回车
  11525. $scope.onSearch = function() {
  11526. $scope.tableParams.page(1);
  11527. $scope.tableParams.reload();
  11528. };
  11529. }]);
  11530. /**
  11531. * 平台公开招标
  11532. *
  11533. */
  11534. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  11535. BaseService.scrollBackToTop();
  11536. /**
  11537. * 改变单据日期范围
  11538. */
  11539. var getTenderDateCondition = function(zone, condition) {
  11540. var date = new Date();
  11541. if(zone == -1) {
  11542. condition.dateFrom = null;
  11543. condition.dateTo = null;
  11544. } else if(zone == 7) { // 一星期内
  11545. date.setDate(date.getDate() - 7);
  11546. condition.dateFrom = date;
  11547. condition.dateTo = new Date();
  11548. } else if(zone == 1) { // 一个月内
  11549. date.setMonth(date.getMonth() - 1);
  11550. condition.dateFrom = date;
  11551. condition.dateTo = new Date();
  11552. } else if(zone == 3) { // 三个月内
  11553. date.setMonth(date.getMonth() - 3);
  11554. condition.dateFrom = date;
  11555. condition.dateTo = new Date();
  11556. } else if (zone == 6) { // 半年内
  11557. date.setMonth(date.getMonth() - 6);
  11558. condition.dateFrom = date;
  11559. condition.dateTo = new Date();
  11560. } else { // 一年内
  11561. date.setYear(date.getYear() - 1);
  11562. condition.dateFrom = date;
  11563. condition.dateTo = new Date();
  11564. }
  11565. };
  11566. $scope.active = 'all';
  11567. $scope.dateZoneText = '不限';
  11568. $scope.deliveryZoneText = '不限';
  11569. $scope.condition = {dateZone: -1};
  11570. $scope.changeDateZone = function(zone) {
  11571. $scope.condition.dateZone = zone;
  11572. $scope.condition.$dateZoneOpen = false;
  11573. getTenderDateCondition(zone, $scope.condition);
  11574. $scope.tableParams.reload();
  11575. };
  11576. $scope.openDatePicker = function($event, item, openParam) {
  11577. $event.preventDefault();
  11578. $event.stopPropagation();
  11579. item[openParam] = !item[openParam];
  11580. };
  11581. $scope.parseDate = function(dateStr) {
  11582. if(dateStr)
  11583. return Date.parse(dateStr, 'yyyy-MM-dd');
  11584. return new Date();
  11585. };
  11586. // 选择查找日期
  11587. $scope.onDateCondition = function(){
  11588. $scope.tableParams.page(1);
  11589. $scope.tableParams.reload();
  11590. };
  11591. // $scope.setActive = function(state) {
  11592. // if($scope.active != state) {
  11593. // $scope.active = state;
  11594. // if($scope.tableParams.page() == 1)
  11595. // $scope.tableParams.reload();
  11596. // else
  11597. // $scope.tableParams.page(1);
  11598. // }
  11599. // };
  11600. var getOpenState = function(active) {
  11601. var fn = 'getOpenAll';
  11602. switch(active) {
  11603. case 'all':
  11604. fn = 'getOpenAll';break;
  11605. // case 'done':
  11606. // fn = 'getOpenDone';break;
  11607. case 'todo':
  11608. fn = 'getOpenTodo';break;
  11609. case 'end':
  11610. fn = 'getOpenEnd';break;
  11611. // case 'waiting':
  11612. // fn = 'getOpenWaiting';break;
  11613. }
  11614. return fn;
  11615. };
  11616. $scope.tableParams = new ngTableParams({
  11617. page : 1,
  11618. count : 10,
  11619. sorting: {
  11620. 'tender.endDate': 'desc',
  11621. 'tender.enterprise.enName': 'asc',
  11622. 'tender.code': 'asc'
  11623. }
  11624. }, {
  11625. total : 0,
  11626. counts: [10, 25, 50, 100],
  11627. getData : function($defer, params) {
  11628. $scope.loading = true;
  11629. var pageParams = params.url();
  11630. var realActive = {};
  11631. pageParams.searchFilter = { // 筛选条件
  11632. keyword: $scope.keyword,
  11633. fromDate: getDateTime($scope.condition.dateFrom),
  11634. endDate: getDateTime($scope.condition.dateTo)
  11635. };
  11636. AccountEnterprise.get({}, function(data){
  11637. $scope.loading = false;
  11638. $scope.currentEn = data;
  11639. });
  11640. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  11641. $scope.loading = false;
  11642. if(page) {
  11643. params.total(page.totalElement);
  11644. $defer.resolve(page.content);
  11645. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  11646. }
  11647. }, function(response){
  11648. $scope.loading = false;
  11649. toaster.pop('error', '数据加载失败', response.data);
  11650. });
  11651. }
  11652. });
  11653. $scope.toDetail = function(id) {
  11654. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  11655. };
  11656. // var stautsItem = [];
  11657. // $scope.getTenderStatus = function (tender) {
  11658. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  11659. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  11660. // stautsItem = thisItem;
  11661. // }
  11662. // });
  11663. // if (!stautsItem.price) {
  11664. // return "daitoubiao";
  11665. // } else if (!stautsItem.applystatus) {
  11666. // return "yitoubiao";
  11667. // } else if (stautsItem.applystatus == 1) {
  11668. // return "zhongbiao";
  11669. // } else if (stautsItem.applystatus == 0) {
  11670. // return "weizhongbiao";
  11671. // }
  11672. // };
  11673. // 搜索框回车
  11674. $scope.onSearch = function() {
  11675. $scope.tableParams.page(1);
  11676. $scope.tableParams.reload();
  11677. };
  11678. }]);
  11679. /**
  11680. * 采购方查看供应商投标单
  11681. */
  11682. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  11683. // PurcTender.getVendorTenderItem({vendUU:$stateParams.vendUU, id: $stateParams.id}, function(data){
  11684. // $scope.item = data; // 供应商查看
  11685. // $scope.loading = false;
  11686. // }, function(response){
  11687. // $scope.loading = false;
  11688. // toaster.pop('error', '数据加载失败', response.data);
  11689. // });
  11690. console.log($stateParams);
  11691. PurcTender.getOne({id: $stateParams.id}, function(data){
  11692. $scope.bid = data;
  11693. var vendUU = Number($stateParams.vendUU);
  11694. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11695. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11696. if (saleTenderItem.saleTender.vendUU === vendUU) {// 与传出的参数venUU相等,即为查看企业对应的明细
  11697. tenderProd.currentItem = saleTenderItem;
  11698. $scope.saleTender = saleTenderItem.saleTender;
  11699. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11700. }
  11701. });
  11702. });
  11703. }, function(response){
  11704. toaster.pop('error', '数据加载失败', response.data);
  11705. });
  11706. }]);
  11707. /**
  11708. * 查看投标单详情
  11709. */
  11710. 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) {
  11711. BaseService.scrollBackToTop();
  11712. if (!$scope.attaches) {
  11713. $scope.attaches = []; // 存放上传了的附件
  11714. }
  11715. // var staticItem = null;
  11716. // $scope.loading = true;
  11717. // PurcTender.getItem({id: $stateParams.id}, function(data){
  11718. // $scope.item = data; // 用于投标
  11719. // if ($scope.item.enterpriseBaseInfo != null) {
  11720. // $scope.itemStatusTodo = $scope.item.enterpriseBaseInfo.uu + "待投标";
  11721. // }
  11722. // staticItem = angular.copy(data);
  11723. // $scope.loading = false;
  11724. // }, function(response){
  11725. // $scope.loading = false;
  11726. // toaster.pop('error', '数据加载失败', response.data);
  11727. // });
  11728. var sleep = function (d){
  11729. for(var t = Date.now();Date.now() - t <= d;);
  11730. };
  11731. AccountEnterprise.get({}, function(data){
  11732. $scope.currentEn = data;
  11733. });
  11734. PurcTender.getOne({id: $stateParams.id}, function(data){
  11735. $scope.bid = data;
  11736. angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11737. angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11738. if (!$scope.currentEn) {
  11739. AccountEnterprise.get({}, function(data){
  11740. $scope.currentEn = data;
  11741. });
  11742. }
  11743. if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  11744. tenderProd.currentItem = saleTenderItem;
  11745. $scope.saleTender = saleTenderItem.saleTender;
  11746. $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  11747. $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11748. }
  11749. });
  11750. });
  11751. }, function(response){
  11752. toaster.pop('error', '数据加载失败', response.data);
  11753. });
  11754. $scope.upload = function(myFile) { // 上传附件
  11755. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  11756. $upload.upload({
  11757. url: 'tender/addTenderItemAttach',
  11758. file: file,
  11759. method: 'POST'
  11760. }).success(function (attach) {
  11761. $scope.attaches.push(attach);
  11762. });
  11763. };
  11764. $scope.removeAttach = function(attachId, index) {
  11765. $scope.attaches.splice(index, 1);
  11766. // PurcTender.removeAttach({attachId : id}, {}, function() {
  11767. //
  11768. // });
  11769. };
  11770. var taxrateYes = false;
  11771. var cycleYes = false;
  11772. var priceYes = false;
  11773. $scope.canSave = false;
  11774. $scope.validateThis = function(value, type) {
  11775. switch(type) {
  11776. case 'taxrate':
  11777. var regex = /^\+?[0-9][0-9]{0,1}$/;
  11778. if (regex.test(value)) {
  11779. taxrateYes = true;
  11780. } else {
  11781. if (value) {
  11782. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  11783. }
  11784. }
  11785. break;
  11786. case 'cycle':
  11787. regex = /^\+?[1-9][0-9]*$/;
  11788. if (regex.test(value)) {
  11789. cycleYes = true;
  11790. } else {
  11791. if (value) {
  11792. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  11793. }
  11794. }
  11795. break;
  11796. case 'price':
  11797. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11798. if (regex.test(value) && value !== 0) {
  11799. priceYes = true;
  11800. } else {
  11801. if (value) {
  11802. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  11803. }
  11804. }
  11805. break;
  11806. }
  11807. };
  11808. $scope.emNumYes = true;
  11809. $scope.validEmNum = function (value) {
  11810. var regex = /^\+?[1-9][0-9]*$/;
  11811. if (!regex.test(value) || value === 0 || value !== null) {
  11812. $scope.emNumYes = false;
  11813. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  11814. }
  11815. };
  11816. $scope.validateProds = function(tenderProd) {
  11817. $scope.canSave = true;
  11818. if (tenderProd.currentItem.cycle || tenderProd.currentItem.taxrate || tenderProd.currentItem.price) {
  11819. var cycleRegex = /^\+?[1-9][0-9]*$/;
  11820. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  11821. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  11822. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11823. // 判断填写过的有为0或不符合正则式的,设置不能保存
  11824. if (!cycleRegex.test(tenderProd.currentItem.cycle) || !taxrateRegex.test(tenderProd.currentItem.taxrate) || !priceRegex.test(tenderProd.currentItem.price)) {
  11825. $scope.canSave = false;
  11826. } else {
  11827. $scope.canSave = true;
  11828. }
  11829. }
  11830. };
  11831. // 投标
  11832. $scope.bidIt = function(tender, currentEnBaseInfo){
  11833. $scope.loading = true;
  11834. if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  11835. currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  11836. }
  11837. var saleTenderItems = [];
  11838. angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  11839. if (tenderProd.currentItem) {
  11840. tenderProd.currentItem.saleTender = {};
  11841. saleTenderItems.push(tenderProd.currentItem);
  11842. }
  11843. });
  11844. PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  11845. $scope.loading = false;
  11846. toaster.pop('info', '成功', '投标成功');
  11847. // $window.location.reload();
  11848. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  11849. // window.location.hash = '#/sale/opentender';
  11850. // } else {
  11851. window.location.hash = '#/sale/tender';
  11852. // }
  11853. }, function(response){
  11854. $scope.loading = false;
  11855. toaster.pop('error', '投标失败', '出现异常,投标失败');
  11856. });
  11857. };
  11858. $scope.condition = {
  11859. $fromOpened:false
  11860. };
  11861. $scope.getMaxDate = function() {
  11862. return $filter('date')(new Date(), 'yyyy-MM-dd');
  11863. };
  11864. $scope.openDatePicker = function($event, item, openParam) {
  11865. $event.preventDefault();
  11866. $event.stopPropagation();
  11867. item[openParam] = !item[openParam];
  11868. };
  11869. }]);
  11870. /**
  11871. * 公开招标转投标单
  11872. */
  11873. 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) {
  11874. BaseService.scrollBackToTop();
  11875. $scope.attaches = []; // 存放上传了的附件
  11876. var sleep = function (d){
  11877. for(var t = Date.now();Date.now() - t <= d;);
  11878. }
  11879. var getCurrentEn = function() {
  11880. AccountEnterprise.get({}, function(data){
  11881. $scope.currentEn = data;
  11882. });
  11883. }
  11884. if( ! angular.isUndefined($stateParams.id)) { // 获取招标单详情
  11885. $scope.loading = true;
  11886. getCurrentEn();
  11887. PurcTender.getOne({id: $stateParams.id}, function(data){
  11888. data.$editing = false;
  11889. $scope.tender = data;
  11890. $scope.tenderProd = data.purchaseTenderProds;
  11891. // parseCertificate($scope.tender.certificate);
  11892. // $scope.firstProd = data.purchaseTenderProds[0];
  11893. $scope.currentHasBid = false; // 默认当前企业未转投标单
  11894. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function(item) {
  11895. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  11896. $scope.currentHasBid = true;
  11897. }
  11898. });
  11899. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  11900. // console.log($scope.tenderProd.enterpriseBaseInfo);
  11901. $scope.loading = false;
  11902. $scope.attaches = $scope.tender.tenderAttaches;
  11903. }, function(response){
  11904. $scope.loading = false;
  11905. toaster.pop('error', '数据加载失败', response.data);
  11906. });
  11907. }
  11908. $scope.hasClick = false;
  11909. $scope.iWantToBid = function(id) {
  11910. $scope.hasClick = true;
  11911. PurcTender.addItems({id: id}, {}, function(data){ // 添加明细
  11912. // $scope.tender = data;
  11913. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  11914. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  11915. // if (!$scope.currentEn) {
  11916. // AccountEnterprise.get({}, function(data){
  11917. // $scope.currentEn = data;
  11918. // });
  11919. // }
  11920. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  11921. // tenderProd.currentItem = saleTenderItem;
  11922. // $scope.saleTender = saleTenderItem.saleTender;
  11923. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  11924. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  11925. // }
  11926. // });
  11927. // });
  11928. toaster.pop('success', '成功', '转投标单成功');
  11929. window.location.hash = "#/sale/tender/" + id;
  11930. }, function(response){
  11931. toaster.pop('error', '操作失败', response.data);
  11932. });
  11933. // $scope.upload = function(myFile) { // 上传附件
  11934. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  11935. // $upload.upload({
  11936. // url: 'tender/addTenderItemAttach',
  11937. // file: file,
  11938. // method: 'POST'
  11939. // }).success(function (attach) {
  11940. // $scope.attaches.push(attach);
  11941. // });
  11942. // };
  11943. };
  11944. // $scope.removeAttach = function(id, index) {
  11945. // $scope.attaches.splice(index, 1);
  11946. // PurcTender.removeAttach({attachId:id}, function() {
  11947. //
  11948. // });
  11949. // };
  11950. // var taxrateYes = false;
  11951. // var cycleYes = false;
  11952. // var priceYes = false;
  11953. // $scope.canSave = false;
  11954. // $scope.validateThis = function(value, type) {
  11955. // switch(type) {
  11956. // case 'taxrate':
  11957. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  11958. // if (regex.test(value)) {
  11959. // taxrateYes = true;
  11960. // } else {
  11961. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  11962. // }
  11963. // break;
  11964. // case 'cycle':
  11965. // regex = /^\+?[1-9][0-9]*$/;
  11966. // if (regex.test(value)) {
  11967. // cycleYes = true;
  11968. // } else {
  11969. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  11970. // }
  11971. // break;
  11972. // case 'price':
  11973. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  11974. // if (regex.test(value) && value !== 0) {
  11975. // priceYes = true;
  11976. // } else {
  11977. // if (!(value instanceof Number) || value) {
  11978. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  11979. // }
  11980. // }
  11981. // break;
  11982. // }
  11983. // };
  11984. //
  11985. // $scope.emNumYes = true;
  11986. //
  11987. // $scope.validEmNum = function (value) {
  11988. // var regex = /^\+?[1-9][0-9]*$/;
  11989. // if (!regex.test(value) || value == 0 || value !== null) {
  11990. // $scope.emNumYes = false;
  11991. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  11992. // }
  11993. // };
  11994. //
  11995. // $scope.validateProds = function(tenderProd) {
  11996. // // angular.forEach(tenderProds, function (tenderProd) {
  11997. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  11998. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  11999. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  12000. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  12001. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  12002. // console.log(tenderProd.currentItem.cycle);
  12003. // 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))) {
  12004. // $scope.canSave = false;
  12005. // } else {
  12006. // $scope.canSave = true;
  12007. // }
  12008. // // });
  12009. // };
  12010. //
  12011. // // 投标
  12012. // $scope.bidIt = function(tender, currentEnBaseInfo){
  12013. // $scope.loading = true;
  12014. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  12015. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  12016. // }
  12017. // var saleTenderItems = [];
  12018. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  12019. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  12020. // if (tenderProd.currentItem) {
  12021. // tenderProd.currentItem.saleTender = {};
  12022. // saleTenderItems.push(tenderProd.currentItem);
  12023. // }
  12024. // });
  12025. // } else {
  12026. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  12027. // if (tenderProd.currentItem) {
  12028. // saleTenderItems.push(tenderProd.currentItem);
  12029. // }
  12030. // });
  12031. // }
  12032. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  12033. // $scope.loading = false;
  12034. // toaster.pop('info', '成功', '投标成功');
  12035. // // $window.location.reload();
  12036. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  12037. // // window.location.hash = '#/sale/opentender';
  12038. // // } else {
  12039. // window.location.hash = '#/sale/tender';
  12040. // // }
  12041. // }, function(response){
  12042. // $scope.loading = false;
  12043. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  12044. // });
  12045. //
  12046. // };
  12047. //
  12048. // $scope.condition = {
  12049. // $fromOpened:false
  12050. // };
  12051. //
  12052. // $scope.getMaxDate = function() {
  12053. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  12054. // };
  12055. //
  12056. // $scope.openDatePicker = function($event, item, openParam) {
  12057. // $event.preventDefault();
  12058. // $event.stopPropagation();
  12059. // item[openParam] = !item[openParam];
  12060. // };
  12061. }]);
  12062. // 基础资料客户详情
  12063. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', 'VendorInfo', function($scope, VendorService, BaseService, AuthenticationService,ngTableParams,$modal, toaster, VendorInfo){
  12064. BaseService.scrollBackToTop();
  12065. $scope.status = 'customer';
  12066. $scope.userInfoResult = true;
  12067. AuthenticationService.getAuthentication().success(function(data) {
  12068. $scope.loading = false;
  12069. $scope.thisUser = data;
  12070. });
  12071. $scope.customerParams = new ngTableParams({
  12072. page : 1,
  12073. count : 10
  12074. }, {
  12075. total : 0,
  12076. counts: [5, 10, 25, 50],
  12077. getData : function($defer, params) {
  12078. $scope.loading = true;
  12079. var pageParams = params.url();
  12080. pageParams.keyword = $scope.keyword;
  12081. VendorService.customer.get(BaseService.parseParams(pageParams), function(page){
  12082. $scope.loading = false;
  12083. if(page) {
  12084. params.total(page.totalElement);
  12085. $defer.resolve(page.content);
  12086. }
  12087. $scope.totalCount = page.totalElement;
  12088. }, function(response){
  12089. $scope.loading = false;
  12090. toaster.pop('error', '数据加载失败', response.data);
  12091. });
  12092. }
  12093. });
  12094. // 搜索框回车
  12095. $scope.onSearch = function(keyword) {
  12096. $scope.customerParams.page(1);
  12097. $scope.customerParams.reload();
  12098. $scope.tip = keyword;
  12099. };
  12100. // 查看详情
  12101. $scope.viewDetail = function(id) {
  12102. console.log(id);
  12103. window.location.hash = "#/sale/customer/" + id;
  12104. }
  12105. // 取消合作关系
  12106. $scope.disableCust = function(id) {
  12107. VendorInfo.disableCust({id: id}, {}, function(data) {
  12108. toaster.pop('success', '提示', '取消合作关系成功');
  12109. $scope.customerParams.page(1);
  12110. $scope.customerParams.reload();
  12111. }, function(response) {
  12112. toaster.pop('error', '提示', response.data);
  12113. });
  12114. }
  12115. // 解除禁用
  12116. $scope.activeCust = function(id) {
  12117. VendorInfo.disableCust({id: id}, {}, function(data) {
  12118. toaster.pop('success', '提示', '取消合作关系成功');
  12119. $scope.customerParams.page(1);
  12120. $scope.customerParams.reload();
  12121. }, function(response) {
  12122. toaster.pop('error', '提示', response.data);
  12123. });
  12124. }
  12125. }]);
  12126. // 基础资料供应商
  12127. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService','AuthenticationService', 'ngTableParams', '$modal','toaster', '$rootScope', 'VendorInfo', function($scope, Vendor, BaseService, AuthenticationService,ngTableParams,$modal, toaster, $rootScope, VendorInfo){
  12128. BaseService.scrollBackToTop();
  12129. $scope.status = 'vendor';
  12130. // 搜索框回车
  12131. $scope.onSearch = function(keyword) {
  12132. $scope.keyword = keyword;
  12133. $scope.customerParams.page(1);
  12134. $scope.customerParams.reload();
  12135. };
  12136. $scope.customerParams = new ngTableParams({
  12137. page : 1,
  12138. count : 10
  12139. }, {
  12140. total : 0,
  12141. counts: [5, 10, 25, 50],
  12142. getData : function($defer, params) {
  12143. $scope.loading = true;
  12144. var pageParams = params.url();
  12145. pageParams.keyword = $scope.keyword;
  12146. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function(page){
  12147. $scope.loading = false;
  12148. if(page) {
  12149. params.total(page.totalElements);
  12150. $scope.total = page.totalElement;
  12151. $defer.resolve(page.content);
  12152. }
  12153. $scope.totalCount = page.totalElements;
  12154. }, function(response){
  12155. $scope.loading = false;
  12156. toaster.pop('error', '数据加载失败', response.data);
  12157. });
  12158. }
  12159. });
  12160. // 查看供应商详情
  12161. $scope.VendorDetail = function(id, uu) {
  12162. $rootScope.vendorId = id;
  12163. $rootScope.vendoruu = uu;
  12164. window.location.hash = "#/purc/vendor/"+$rootScope.vendorId;
  12165. }
  12166. // 向企业购买
  12167. $scope.purcByEn = function(businessCode) {
  12168. $rootScope.businessCode = businessCode;
  12169. window.location.hash = "#/purc/addOrder";
  12170. }
  12171. // 取消合作关系
  12172. $scope.relieve = function(id) {
  12173. VendorInfo.relieve({id: id}, {}, function(data) {
  12174. toaster.pop('success', '提示', '取消合作关系成功');
  12175. $scope.customerParams.page(1);
  12176. $scope.customerParams.reload();
  12177. }, function(response) {
  12178. toaster.pop('error', '提示', response.data);
  12179. });
  12180. }
  12181. // 取消合作关系
  12182. $scope.activeVend = function(id) {
  12183. VendorInfo.activeVend({id: id}, {}, function(data) {
  12184. toaster.pop('success', '提示', '取消禁用成功');
  12185. $scope.customerParams.page(1);
  12186. $scope.customerParams.reload();
  12187. }, function(response) {
  12188. toaster.pop('error', '提示', response.data);
  12189. });
  12190. }
  12191. }]);
  12192. // 企业圈搜索界面
  12193. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  12194. $scope.onSearch = function(keyword) {
  12195. $rootScope.enterpriseKeyword = keyword;
  12196. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  12197. }
  12198. }]);
  12199. // 企业圈搜索结果
  12200. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  12201. BaseService.scrollBackToTop();
  12202. $scope.active = 'all';
  12203. $scope.agreedText = '全部';
  12204. $scope.dateZoneText = '一个月内';
  12205. $scope.condition = {dateZone: 1};
  12206. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12207. $scope.changeAgreed = function(agreed) {
  12208. $scope.condition.agreed = agreed;
  12209. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12210. $scope.condition.$agreedOpen = false;
  12211. };
  12212. $scope.changeDateZone = function(zone) {
  12213. $scope.condition.dateZone = zone;
  12214. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12215. $scope.condition.$dateZoneOpen = false;
  12216. getDateCondition(zone, $scope.condition);
  12217. $scope.tableParams.reload();
  12218. };
  12219. $scope.setActive = function(state) {
  12220. if($scope.active != state) {
  12221. $scope.active = state;
  12222. if($scope.tableParams.page() == 1)
  12223. $scope.tableParams.reload();
  12224. else
  12225. $scope.tableParams.page(1);
  12226. }
  12227. };
  12228. var getService = function() {
  12229. return getAccountUserSpace;
  12230. };
  12231. $scope.tableParams = new ngTableParams({
  12232. page : 1,
  12233. count : 5,
  12234. sorting: {
  12235. }
  12236. }, {
  12237. total : 0,
  12238. counts: [5, 10, 25, 50],
  12239. getData : function($defer, params) {
  12240. $scope.loading = true;
  12241. var pageParams = params.url();
  12242. pageParams.keyword = $rootScope.enterpriseKeyword;
  12243. $scope.tip = $rootScope.enterpriseKeyword;
  12244. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
  12245. $scope.loading = false;
  12246. if(page) {
  12247. params.total(page.totalElement);
  12248. $defer.resolve(page.content);
  12249. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12250. }
  12251. }, function(response) {
  12252. $scope.loading = false;
  12253. toaster.pop('error', '数据加载失败', response.data);
  12254. });
  12255. }
  12256. });
  12257. // 搜索框回车
  12258. $scope.onSearch = function() {
  12259. $scope.tableParams.page(1);
  12260. $scope.tableParams.reload();
  12261. };
  12262. // 添加合作关系
  12263. $scope.addPartner = function(name, businessCode) {
  12264. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function(data) {
  12265. if(data.success) {
  12266. toaster.pop("success", '添加成功', data.success);
  12267. }
  12268. if(data.error) {
  12269. toaster.pop("error", '添加失败', data.error);
  12270. }
  12271. }, function(response) {
  12272. toaster.pop('error','失败',response.data);
  12273. });
  12274. }
  12275. $scope.status = 'enList';
  12276. }]);
  12277. // 平台新增的询价单(指定一个供应商)
  12278. app.controller('PurcInquiryNewCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', '$http', 'ShipAddress', '$stateParams', 'Vendor', 'Product', function($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout, $http, ShipAddress, $stateParams, Vendor, Product) {
  12279. BaseService.scrollBackToTop();
  12280. $scope.active = 'all';
  12281. // 供应商信息
  12282. var loadData = function() {
  12283. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function(data) {
  12284. $scope.vendor = data;
  12285. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function(data) {
  12286. $scope.vendorContacts = data;
  12287. });
  12288. // 物料信息
  12289. $scope.tableParams = new ngTableParams({
  12290. page : 1,
  12291. count : 10
  12292. }, {
  12293. total : 0,
  12294. counts: [5, 10, 25, 50],
  12295. getData : function($defer, params) {
  12296. $scope.loading = true;
  12297. var pageParams = params.url();
  12298. pageParams.keyword = $scope.keyword;
  12299. $scope.tip = $scope.keyword;
  12300. pageParams.custUU = $scope.vendor.uu;
  12301. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  12302. $scope.loading = false;
  12303. if(page) {
  12304. params.total(page.totalElement);
  12305. $scope.total = page.totalElement;
  12306. $defer.resolve(page.content);
  12307. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  12308. }
  12309. }, function(response){
  12310. $scope.loading = false;
  12311. toaster.pop('error', '数据加载失败', response.data);
  12312. });
  12313. }
  12314. });
  12315. });
  12316. };
  12317. loadData();
  12318. $rootScope.tenderVendor = null;// 清除掉已选择的
  12319. var getService = function() {
  12320. return GetProductInfo;
  12321. };
  12322. $scope.inquiry = {
  12323. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  12324. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  12325. priceType: '采购',
  12326. isOpen: 1,
  12327. invoice: 0
  12328. };
  12329. // 获取收货地址列表
  12330. var loadShipAddress = function() {
  12331. ShipAddress.shipAddList({}, function(data) {
  12332. $scope.ships = data;
  12333. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  12334. });
  12335. };
  12336. loadShipAddress();
  12337. // 获取地址信息
  12338. $http.get('resources/citydata/city.json', {"Accept": "application/json;charset=utf-8", "Accept-Charset":"charset=utf-8"
  12339. }).then(function(response) {
  12340. $scope.provinces = response.data;
  12341. });
  12342. // 新增收货地址保存
  12343. $scope.saveShipAddress = function(ship) {
  12344. ship.address = ship.province + ship.city + ship.district;
  12345. ShipAddress.saveAddress( {}, ship, function(data) {
  12346. if(data.success) {
  12347. // 获取收货地址列表
  12348. loadShipAddress();
  12349. toaster.pop('success', '提示', data.success);
  12350. }
  12351. if(data.error) {
  12352. toaster.pop('error', '提示', data.error);
  12353. }
  12354. });
  12355. };
  12356. $scope.currentDay = function() {
  12357. return $filter('date')(new Date(), 'yyyy-MM-dd');
  12358. };
  12359. // 搜索框回车
  12360. $scope.onSearch = function(keyword) {
  12361. $scope.tableParams.page(1);
  12362. $scope.tableParams.reload();
  12363. };
  12364. $scope.inquiry.inquiryItems = [];
  12365. //删除商品
  12366. $scope.del = function(index) {
  12367. $scope.inquiry.inquiryItems.splice(index, 1);
  12368. };
  12369. $scope.check = function(product) {
  12370. $scope.inquiry.inquiryItems.push({prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  12371. currency: null, toDate: null, productId: product.id});
  12372. }
  12373. $scope.getMinDate = function(item) {
  12374. return $filter('date')(new Date, 'yyyy-MM-dd');
  12375. };
  12376. $scope.openDatePicker = function($event, openParam, index) {
  12377. $event.preventDefault();
  12378. $event.stopPropagation();
  12379. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  12380. };
  12381. $scope.openEndDatePicker = function($event, item, openParam) {
  12382. $event.preventDefault();
  12383. $event.stopPropagation();
  12384. item[openParam] = !item[openParam];
  12385. };
  12386. // 保存
  12387. $scope.save = function() {
  12388. // var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12389. // $upload.upload({
  12390. // url: 'product/baseInfo/updateProdInfo',
  12391. // file: file,
  12392. // method: 'POST',
  12393. // data: {
  12394. // prodInfo: $scope.prodInfo
  12395. // },
  12396. // }).success(function(data) {
  12397. // if(data.success) {
  12398. // toaster.pop('success', '提示', data.success);
  12399. // window.location.reload();
  12400. // }
  12401. // if(data.error) {
  12402. // toaster.pop('error', '提示', data.error);
  12403. // }
  12404. // }).error(function(data) {
  12405. // $scope.loadingShow = false;
  12406. // toaster.pop('error', '操作失败', data.error);
  12407. // });
  12408. if( $scope.inquiry.isOpen == 0) { // 指定询价
  12409. if( $scope.vendors.length > 0) {
  12410. PurchaseInquiry.save({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  12411. if(data.success) {
  12412. toaster.pop('success', '提示', data.success);
  12413. $timeout(function() {
  12414. window.location.hash = "#/purc/inquiry_unapply";
  12415. }, 500);
  12416. }
  12417. if(data.error) {
  12418. toaster.pop('error', '提示', data.error);
  12419. }
  12420. }, function(response) {
  12421. toaster.pop('error', '提示', response.data);
  12422. });
  12423. } else {
  12424. toaster.pop('info', '提示', '请先选择供应商');
  12425. }
  12426. } else {
  12427. PurchaseInquiry.saveWithoutVendor({inquiry: $scope.inquiry}, {}, function(data) {
  12428. if(data.success) {
  12429. toaster.pop('success', '提示', data.success);
  12430. $timeout(function() {
  12431. window.location.hash = "#/purc/inquiry_unapply";
  12432. }, 500);
  12433. }
  12434. if(data.error) {
  12435. toaster.pop('error', '提示', data.error);
  12436. }
  12437. }, function(response) {
  12438. toaster.pop('error', '提示', response.data);
  12439. });
  12440. }
  12441. }
  12442. // 保存并提交
  12443. $scope.submit = function() {
  12444. $scope.vendors = [];
  12445. $scope.vendors.push({enName: $scope.vendor.enName, enuu: $scope.vendor.uu});
  12446. PurchaseInquiry.submit({inquiry: $scope.inquiry}, $scope.vendors, function(data) {
  12447. if(data.success) {
  12448. toaster.pop('success', '提示', data.success);
  12449. $timeout(function() {
  12450. window.location.hash = "#/purc/purchaseinquiry";
  12451. }, 500);
  12452. }
  12453. if(data.error) {
  12454. toaster.pop('error', '提示', data.error);
  12455. }
  12456. }, function(response) {
  12457. toaster.pop('error', '提示', response.data);
  12458. });
  12459. }
  12460. }]);
  12461. return app;
  12462. });